# include "Ximage.h"

/************** CheckGeometry *************/
void CheckGeometry (int *argc, char **argv, Graphic *graphic) {

  int status, x, y, N;
  unsigned int dx, dy;
  int X, Y, dX, dY;
  char *temp_name;
  
  temp_name = XGetDefault (graphic[0].display, argv[0], "geometry");
  if ((N = get_argument (*argc, argv, "-geom"))) {
    if (N + 1 < *argc) {
      temp_name = argv[N+1];
    }
    else {
      fprintf (stderr, "error: usage is -geom DisplayName\n");
      exit (0);
    }
  }
  X = 10;
  Y = 10;
  dX = 512 + 2*PAD1 + PAD1 + ZOOM_X;
  dY = 512 + 2*PAD1 + PAD2 + COLORPAD;
  if (temp_name != (char *)NULL) {  
    status = XParseGeometry (temp_name, &x, &y, &dx, &dy);
    if (status & XValue)
      X = x;
    if (status & YValue)
      Y = y;
    if (status & WidthValue) {
      dX = dx + 2*PAD1 + PAD1 + ZOOM_X;
      dX = MAX (dX, MIN_WIDTH);
    }
    if (status & HeightValue) {
      dY = dy + 2*PAD1 + PAD2 + COLORPAD + 42;
      dY = MAX (dY, MIN_HEIGHT);
    }
    if (status & XNegative)
      X  = DisplayWidth  (graphic[0].display, graphic[0].screen) - dX + X;
    if (status & YNegative)
      Y  = DisplayHeight (graphic[0].display, graphic[0].screen) - dY + Y;
  }

  graphic[0].x = X;
  graphic[0].y = Y;
  graphic[0].dx = dX;
  graphic[0].dy = dY; 
  
}
