Example #1
0
static void
open_window(Window w)
{
    int x = 0, y = 0;
    /*int border_width = 2;*/
    unsigned int width = 1;
    unsigned int height = 1;
    unsigned int fwidth = 0, fheight = 0;
    unsigned int xadder = 0, yadder = 0;
    char *str_type[50];
    XrmValue value;

    char userdefaults[50], progdefaults[50];

    strcpy(progdefaults, "=700x450+0+0");
    if (XrmGetResource(rDB, "FriCAS.hyperdoc.Geometry",
        "FriCAS.hyperdoc.Geometry", str_type, &value) == True)
    {
        strncpy(userdefaults, value.addr, (int) value.size);
    }
    else
        strcpy(userdefaults, progdefaults);

    XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
              0, fwidth, fheight, xadder, yadder,
              &x, &y, ( int *)&width,( int *) &height);

    gWindow->border_width = get_border_properties();

    gWindow->fMainWindow = XCreateSimpleWindow(gXDisplay, RootWindow(gXDisplay, gXScreenNumber),
                                    x, y, width, height, gWindow->border_width,
                                    gBorderColor,
                                    WhitePixel(gXDisplay, gXScreenNumber));

    gWindow->fScrollWindow = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
                                         1, 1, 1, 1, 0,
                                         gBorderColor,
                                         WhitePixel(gXDisplay, gXScreenNumber));


    makeScrollBarWindows();
    makeTitleBarWindows();

    /* Now set all the little properties for the top level window */

    set_name_and_icon();
    set_size_hints(w);
    XSelectInput(gXDisplay, gWindow->fScrollWindow, PointerMotionMask);
    XSelectInput(gXDisplay, gWindow->fMainWindow, StructureNotifyMask | PointerMotionMask);
    XDefineCursor(gXDisplay, gWindow->fMainWindow, gNormalCursor);
}
Example #2
0
void QSetGeometry( char *s )

{
	int x,y;
	int width,height;	/* unsigned deleted 21.03.94 */
	int flag;

	flag = XGeometry( MyDisplay , MyScreen , s , NULL ,
				MyBorder , 1 , 1 , 0 , 0 ,
				&x , &y , &width , &height );

	flag_useless = flag;

	XMinPix = x;
	YMinPix = y;
	XMaxPix = x+width-1;
	YMaxPix = y+height-1;
}
Example #3
0
static void
set_size_hints(Window w)
{
    int x, y;
    unsigned int width, height;
    char userdefaults[50];
    char progdefaults[50];
    char *str_type[50];
    unsigned int fwidth = 0, fheight = 0;
    unsigned int xadder = 0, yadder = 0;
    int geo = 0;                /* return flag from XGetGeometry */
    unsigned int depth, bw=0;
    Window root;
    XSizeHints size_hints;
    XPoint xp;
    XrmValue value;

    size_hints.flags = 0;

    strcpy(progdefaults, "=600x450+0+0");

    if (w) {
        /*
         * The window should be queried for it's size and position. Then the
         * new window should be given almost the same locations
         */

        if (XGetGeometry(gXDisplay, w, &root, &x, &y, &width, &height, &bw, &depth))
        {
            xp = getWindowPositionXY(gXDisplay, w);
            x = xp.x + 40;
            y = xp.y + 40;
            if (x < 0)
                x = 0;
            if (y < 0)
                y = 0;
            size_hints.flags |= (USSize | USPosition);
        }
        else {
            fprintf(stderr, "(HyperDoc) Error Querying window configuration: %ld.\n", w);
            x = y = 0;
            width = 600;
            height = 450;
            size_hints.flags |= (PSize | PPosition);
        }
    }
    else {
        /* this is the first window, so lets try to find a nice spot for it */

        if (XrmGetResource(rDB, "FriCAS.hyperdoc.Geometry",
                           "FriCAS.hyperdoc.Geometry", str_type,
                           &value) == True) {
            strncpy(userdefaults, value.addr, (int) value.size);
            geo = XParseGeometry(userdefaults, &x, &y, &width, &height);
        } else {
            strcpy(userdefaults, progdefaults);
        }

        size_hints.flags |= (geo & (WidthValue | HeightValue)) ? USSize : PSize;
        size_hints.flags |= (geo & (XValue | YValue)) ? USPosition : PPosition;

        geo = XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
                        bw, fwidth, fheight, xadder, yadder,
                        &x, &y, (int *)&width, (int *)&height);
    }

    size_hints.x = x;
    size_hints.y = y;
    size_hints.width = width;
    size_hints.height = height;

    getTitleBarMinimumSize(&(size_hints.min_width), &(size_hints.min_height));
#if 0
    size_hints.min_width  = MIN_WINDOW_SIZE;
    size_hints.min_height = MIN_WINDOW_SIZE;
#endif
    size_hints.flags |= PMinSize;

    XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints);
    /* just in case a hint isn't enough ... */
    XFlush(gXDisplay);
/*  XMoveResizeWindow(gXDisplay, gWindow->fMainWindow, x, y, width, height); */
}
Example #4
0
static void
open_form_window(void)
{
    int x, y, width, height;
    unsigned int fwidth = 0, fheight = 0;
    unsigned int xadder = 0, yadder = 0;
    /*char *window_name = "HyperDoc";*/
    /*char *icon_name = "HT";*/
    XrmValue value;
    char *str_type[50];
    XSizeHints size_hints;
    int userSpecified = 0;

    char userdefaults[50], progdefaults[50];

    strcpy(progdefaults, "=950x450+0+0");
    if (XrmGetResource(rDB, "FriCAS.hyperdoc.FormGeometry",
        "FriCAS.hyperdoc.FormGeometry", str_type, &value) == True)
    {
        strncpy(userdefaults, value.addr, (int) value.size);
        userSpecified = 1;
    }
    else
        strcpy(userdefaults, progdefaults);

    XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
              0, fwidth, fheight, xadder, yadder,
              &x, &y, &width, &height);

    gWindow->border_width = get_border_properties();

    gWindow->width = 1;
    gWindow->height = 1;

    gWindow->fMainWindow = XCreateSimpleWindow(gXDisplay, RootWindow(gXDisplay, gXScreenNumber),
                                    x, y, width, height, gWindow->border_width,
                                    gBorderColor,
                                    WhitePixel(gXDisplay, gXScreenNumber));
    gWindow->fScrollWindow = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
                                         1, 1, 1, 1, 0,
                                         BlackPixel(gXDisplay, gXScreenNumber),
                                         WhitePixel(gXDisplay, gXScreenNumber));
    makeScrollBarWindows();
    makeTitleBarWindows();

    set_name_and_icon();

    XSelectInput(gXDisplay, gWindow->fScrollWindow, PointerMotionMask);
    XSelectInput(gXDisplay, gWindow->fMainWindow, StructureNotifyMask | PointerMotionMask);
    XDefineCursor(gXDisplay, gWindow->fMainWindow, gNormalCursor);

    /* now give the window manager some hints */

    size_hints.flags = 0;

    size_hints.min_width  = width;
    size_hints.min_height = height;
    size_hints.flags |= PMinSize;

    size_hints.width  = width;
    size_hints.height = height;
    size_hints.flags |= (userSpecified ? USSize : PSize);

    size_hints.x = x;
    size_hints.y = y;
    size_hints.flags |= (userSpecified ? USPosition : PPosition);

    XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints);
    XFlush(gXDisplay);
}
Example #5
0
void init_window(int argc, char *argv[])
{
   unsigned long get_color_pix(char *color_name);

   screen = DefaultScreen(display);

#if defined(HAVE_BZERO) && !defined(HAVE_MEMSET)
   bzero(&xsh, sizeof(xsh));
#else
   memset(&xsh, 0, sizeof(xsh));
#endif

   if (geometry) {
      int bitmask;

      bitmask = XGeometry(display, screen, geometry, NULL,
                          bwidth, 1, 1, 1, 1,
                          &(xsh.x), &(xsh.y), &(xsh.width), &(xsh.height));
      if (bitmask & (XValue | YValue)) {
         xsh.flags |= USPosition;
      }
      if (bitmask & (WidthValue | HeightValue)) {
         xsh.flags |= USSize;
      }
   } else {
      xsh.flags = USPosition | PSize;
      if (!landscape) {
         xsh.width = XLENG / shrink;
         xsh.height = YLENG / shrink;
         xsh.x = X0;
         xsh.y = Y0;
      } else {
         xsh.width = YLENG / shrink;
         xsh.height = XLENG / shrink;
         xsh.x = X0_LAND;
         xsh.y = Y0;
      }
   }

   /**  Color  **/
#ifdef COLOR_BUG
   reverse = 1;
#endif
   if (DisplayPlanes(display, screen) >= 3) {
      c_flg = 1;
      if (!reverse) {
         forepix = get_color_pix(fore_color);
         backpix = get_color_pix(back_color);
         highpix = get_color_pix(high_color);
         brdrpix = get_color_pix(brdr_color);
         mouspix = get_color_pix(mous_color);
      } else {
         forepix = get_color_pix(back_color);
         backpix = get_color_pix(fore_color);
         highpix = get_color_pix(high_color);
         brdrpix = get_color_pix(brdr_color);
         mouspix = get_color_pix(mous_color);
      }
   } else {
      if (!reverse) {
         forepix = BlackPixel(display, screen);
         highpix = BlackPixel(display, screen);
         backpix = WhitePixel(display, screen);
         brdrpix = BlackPixel(display, screen);
         mouspix = BlackPixel(display, screen);
      } else {
         forepix = WhitePixel(display, screen);
         highpix = WhitePixel(display, screen);
         backpix = BlackPixel(display, screen);
         brdrpix = WhitePixel(display, screen);
         mouspix = WhitePixel(display, screen);
      }
   }


   /**  Generate Window  **/
   main_window = XCreateSimpleWindow(display, DefaultRootWindow(display),
                                     xsh.x, xsh.y, xsh.width, xsh.height,
                                     bwidth, brdrpix, backpix);

   XSetStandardProperties(display, main_window, windowtitle, windowtitle,
                          None, argv, argc, &xsh);

   /* winatt.bit_gravity = SouthWestGravity; */
   XChangeWindowAttributes(display, main_window, CWBitGravity, &winatt);

   /**  Map Window  **/
   XSelectInput(display, main_window, StructureNotifyMask);
   XMapWindow(display, main_window);
   for (;;) {
      XNextEvent(display, &ev);
      if (ev.type == MapNotify)
         break;
   }
   XSelectInput(display, main_window,
                ButtonPressMask | PointerMotionMask | KeyPressMask |
                ExposureMask);
   /*  KeyReleaseMask|ExposureMask|StructureNotifyMask);
    */
   /**  Cursor  **/
   watch_cur = XCreateFontCursor(display, XC_watch);
   XDefineCursor(display, main_window, watch_cur);

   /**  GC  **/
   gcval.line_width = 1;
   gc = XCreateGC(display, main_window, GCLineWidth, &gcval);

   XSetFunction(display, gc, GXcopy);
   XSetGraphicsExposures(display, gc, False);
   XSetForeground(display, gc, forepix);
   XSetBackground(display, gc, backpix);

   font = XLoadFont(display, f_name[fno]);
   XSetFont(display, gc, font);
}
Example #6
0
static void WindowInitialize()
{
  Window root;
  XEvent event;
  int screennum;
  Cursor newcursor;

  screennum = DefaultScreen(m_display);
  root = DefaultRootWindow(m_display);
  
  if (BlackAndWhite) {
    WinAttr.background_pixel = BlackPixel(m_display, DefaultScreen(m_display));
    WinAttr.border_pixel = WhitePixel(m_display, DefaultScreen(m_display));
  } else {
    WinAttr.background_pixel = m_colors[0][m_black].pixel;
    WinAttr.border_pixel = m_colors[0][m_black].pixel;
  }
#if 0   /* simple cleanup ***mdg*** */
  WinAttr.background_pixel = m_colors[0][m_black].pixel;
  WinAttr.border_pixel = m_colors[m_black]->pixel;
#endif
  WinAttr.event_mask = WindowEventMask;
  WinAttr.cursor = XCreateFontCursor(m_display, XC_tcross);
  XRecolorCursor(m_display, WinAttr.cursor, &m_colors[0][15], 
		                            &m_colors[0][m_black]);
  WinSizeHints.max_width = XDisplayWidth(m_display, screennum);
  WinSizeHints.max_height = XDisplayHeight(m_display, screennum);

  /* This next section allows entries in .Xdefaults to set initial
     size and position of the newcrt window. 
     Jim Clark 7/13/92 */

  usrgeo = XGetDefault (m_display, "newcrt", "geometry");
   
  if (usrgeo == NULL)
    WinSizeHints.flags |= PPosition;
  else
    WinSizeHints.flags |= USPosition;

  x_pad = 0;
  y_pad = 0;


  XGeometry(m_display,screennum, usrgeo, defgeo, WinBorder, nc_fontwidth,
	    nc_fontheight, x_pad, y_pad, &jc_winX, &jc_winY,
	    &jc_winW, &jc_winH);

  nc_window = XCreateWindow(m_display, root, jc_winX, jc_winY,
			    jc_winW, jc_winH, WinBorder,
			    CopyFromParent, InputOutput, 
			    DefaultVisual(m_display, screennum),
			    WinAttrMask, &WinAttr);
 
  /* End of revised section. */

  XStoreName(m_display, nc_window, "newcrt");
  XSetIconName(m_display, nc_window, "newcrt");
  XSetCommand(m_display, nc_window, &progname, 1);
  XSetWMHints(m_display, nc_window, &WinWMHints);
  XSetNormalHints(m_display, nc_window, &WinSizeHints);

  XMapWindow(m_display, nc_window);

/*  nc_gc = XCreateGC(m_display, nc_window, 0, NULL);  */

  XWindowEvent(m_display, nc_window, ExposureMask, &event);
}
Example #7
0
int
mf_x11_initscreen()
{
    char *geometry;
    int geometry_found = 0;
    char default_geometry[100];
    XSizeHints sizehints;
    XGCValues gcvalues;

    /* We want the default display. (section 2.1 Opening the display)  */
    my_display = XOpenDisplay(NULL);
    if (my_display == NULL) return 0;
    
    /* Given a display, we can get the screen and the ``black'' and
       ``white'' pixels.  (section 2.2.1 Display macros)  */
    my_screen = DefaultScreen(my_display);     
    white = WhitePixel(my_display, my_screen);
    black = BlackPixel(my_display, my_screen);
    
    
    sizehints.x = DEFAULT_X_POSITION;
    sizehints.y = DEFAULT_Y_POSITION;
    sizehints.width = screenwidth;
    sizehints.height = screendepth;
    sizehints.flags = PPosition|PSize;

    sprintf (default_geometry, "%ux%u+%u+%u", screenwidth, screendepth,
                               DEFAULT_X_POSITION, DEFAULT_Y_POSITION);

    /* Look up the geometry for this window. (Section 10.2 Obtaining X
       environment defaults)  */
    geometry = XGetDefault(my_display, PROGRAM_NAME, ARG_GEOMETRY);
    
    if (geometry != NULL) {
       /* (section 10.3 Parsing window geometry) */
       int bitmask = XGeometry(my_display, my_screen,
			       geometry, default_geometry,
                               BORDER_WIDTH,
                               1, 1, /* ``Font'' width and height. */
                               0, 0, /* Interior padding. */
                               &(sizehints.x), &(sizehints.y),
                               &(sizehints.width), &(sizehints.height));
       
       /* (section 9.1.6 Setting and getting window sizing hints)  */
       if (bitmask & (XValue|YValue)) {
          sizehints.flags |= USPosition;
          geometry_found = 1;
       }
       
       if (bitmask & (WidthValue|HeightValue)) {
          sizehints.flags |= USSize;
          if (sizehints.width > screenwidth) sizehints.width = screenwidth;
          if (sizehints.height > screendepth) sizehints.height = screendepth;
          geometry_found = 1;
       }
    }
    
    
    /* Our window is pretty simple. (section 3.3 Creating windows)  */
    my_window = XCreateSimpleWindow(my_display,
                          DefaultRootWindow(my_display), /* parent */
                          sizehints.x, sizehints.y, /* upper left */
                          sizehints.width, sizehints.height,
                          BORDER_WIDTH,
			  black, /* border color */
                          white); /* background color */
    
    /* (section 9.1.1 Setting standard properties)  */
    XSetStandardProperties(my_display, my_window, 
                           PROGRAM_NAME,  /* window name */
                           PROGRAM_NAME,  /* icon name */
			   None,  /* pixmap for icon */
                           0, 0,  /* argv and argc for restarting */
                           &sizehints);
    XSetWMHints(my_display, my_window, &wm_hints);
    
    
    /* We need a graphics context if we're going to draw anything.
       (section 5.3 Manipulating graphics context/state)  */
    gcvalues.foreground = black;
    gcvalues.background = white;
    /* A ``thin'' line.  This is much faster than a line of length 1,
       although the manual cautions that the results might be less
       consistent across screens.  */
    gcvalues.line_width = 0;
    
    my_gc = XCreateGC(my_display, my_window,
		      GCForeground|GCBackground|GCLineWidth,
		      &gcvalues);
    
    /* (section 3.5 Mapping windows)  This is the confusing part of the
    program, at least to me. If no geometry spec was found, then the
    window manager puts up the blinking rectangle, and the user clicks,
    all before the following call returns. But if a geometry spec was
    found, then we want to do a whole mess of other things, because the
    window manager is going to send us an expose event so that we can
    bring our window up -- and this is one expose event we have to
    handle.  */
    XMapWindow(my_display, my_window);

    if (geometry_found) {
       /* The window manager sends us an Expose event. Yuck.
       */
       XEvent my_event;
       /* We certainly don't want to handle anything else.
          (section 8.5 Selecting events)
       */
       XSelectInput(my_display, my_window, ExposureMask);

       /* We also want to do this right now. This is the confusion. From
          stepping through the program under the debugger, it appears
          that it is this call to XSync (given the previous call to
          XSelectInput) that actually brings the window up -- and yet
          without the remaining code, the thing doesn't work right. Very
          strange. (section 8.6 Handling the output buffer)  
       */
       XSync(my_display, 0);

       /* Now get the event. (section 8.8.1 Returning the next event)
       */
       XNextEvent(my_display, &my_event);
       
       /* Ignore all but the last of the Expose events.
          (section 8.4.5.1 Expose event processing)
       */
       if (my_event.type == Expose && my_event.xexpose.count == 0) {
          /* Apparently the network might STILL have my_events coming in.
             Let's throw away Expose my_events again. (section 8.8.3
             Selecting my_events using a window or my_event mask)
          */
          while (XCheckTypedEvent(my_display, Expose, &my_event)) ;

          /* Finally, let's draw the blank screen.
          */
          XClearWindow(my_display, my_window);
       }
   }
    
    /* That's it.  */
    return 1;
}