Example #1
0
/****f* libAfterImage/tutorials/create_top_level_window()
 * NAME
 * create_top_level_window()
 * SYNOPSIS
 * Window create_top_level_window( ASVisual *asv, Window root,
 *                                 int x, int y,
 *                                 unsigned int width,
 *                                 unsigned int height,
 *                                 unsigned int border_width,
 *                                 unsigned long attr_mask,
 *                                 XSetWindowAttributes *attr,
 *                                 char *app_class );
 * INPUTS
 * asv           - pointer to valid preinitialized ASVisual structure.
 * root          - root window of the screen on which to create window.
 * x, y          - desired position of the window
 * width, height - desired window size.
 * border_width  - desired initial border width of the window (may not
 *                 have any effect due to Window Manager intervention.
 * attr_mask     - mask of the attributes that has to be set on the
 *                 window
 * attr          - values of the attributes to be set.
 * app_class     - title of the application to be used as its window
 *                 Title and resources class.
 * RETURN VALUE
 * ID of the created window.
 * DESCRIPTION
 * create_top_level_window() is autyomating process of creating top
 * level application window. It creates window for specified ASVisual,
 * and then sets up basic ICCCM hints for that window, such as WM_NAME,
 * WM_ICON_NAME, WM_CLASS and WM_PROTOCOLS.
 * SOURCE
 */
Window
create_top_level_window( ASVisual *asv, Window root, int x, int y,
                         unsigned int width, unsigned int height,
						 unsigned int border_width, 
						 unsigned long attr_mask,
						 XSetWindowAttributes *attr, 
						 const char *app_class, const char *app_name )
{
 	Window w = None;
#ifndef X_DISPLAY_MISSING
	char *tmp ;
	XTextProperty name;
	XClassHint class1;

	w = create_visual_window(asv, root, x, y, width, height, border_width, 
							 InputOutput, attr_mask, attr );

	tmp = (app_name==NULL)?(char*)get_application_name():(char*)app_name;
    XStringListToTextProperty (&tmp, 1, &name);

    class1.res_name = tmp;	/* for future use */
    class1.res_class = (char*)app_class;
    XSetWMProtocols (asv->dpy, w, &_XA_WM_DELETE_WINDOW, 1);
    XSetWMProperties (asv->dpy, w, &name, &name, NULL, 0, NULL, NULL, &class1);
    /* final cleanup */
    XFree ((char *) name.value);

#endif /* X_DISPLAY_MISSING */
	return w;
}
Example #2
0
File: calc.c Project: tommie/xppaut
static void make_calc(Calc *calc) {
  int width, height;
  static char *name[] = {"Answer"};
  Window base;
  XTextProperty winname;
  XSizeHints size_hints;

  calc->last_val = 0;
  width = 20 + 24 * DCURXs;
  height = 4 * DCURYs;
  base =
    make_plain_window(RootWindow(display, screen), 0, 0, width, height, 4);
  calc->base = base;
  size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  size_hints.x = 0;
  size_hints.y = 0;
  size_hints.width = width;
  size_hints.height = height;
  size_hints.min_width = width;
  size_hints.min_height = height;
  size_hints.max_width = width;
  size_hints.max_height = height;

  XStringListToTextProperty(name, 1, &winname);
  XSetWMProperties(display, base, &winname, &winname, NULL, 0, &size_hints,
                   NULL, NULL);
  XFree(winname.value);
  calc->answer = make_window(base, 10, DCURYs / 2, 24 * DCURXs, DCURYs, 0);
  width = (width - 4 * DCURXs) / 2;
  calc->quit =
    make_window(base, width, (int)(2.5 * DCURYs), 4 * DCURXs, DCURYs, 1);
  XSelectInput(display, calc->quit, MYMASK);
  x11_events_listen(g_x11_events, X11_EVENTS_ANY_WINDOW, MYMASK, calc_event, &g_calc);
  calc->use = 1;
}
Example #3
0
static void setup_window_hints_and_icon(Display* dpy, Window win, Window parent, const int maxsize) {
	XTextProperty	x_wname, x_iname;
	XSizeHints	hints;
	XWMHints	wmhints;
	char *w_name ="xjadeo";
	char *i_name ="xjadeo";

	/* default settings which allow arbitraray resizing of the window */
	hints.flags = PSize | PMaxSize | PMinSize;
	hints.min_width = 32;
	hints.min_height = 18;
	hints.max_width = maxsize;
	hints.max_height = maxsize;

	wmhints.input = True;
	XpmCreatePixmapFromData(dpy, parent, xjadeo8_xpm, &wmhints.icon_pixmap, &wmhints.icon_mask, NULL);
	wmhints.flags = InputHint | IconPixmapHint | IconMaskHint;

	if (XStringListToTextProperty (&w_name, 1, &x_wname) &&
			XStringListToTextProperty (&i_name, 1, &x_iname))
	{
		XSetWMProperties (dpy, win, &x_wname, &x_iname, NULL, 0, &hints, &wmhints, NULL);
		XFree (x_wname.value);
		XFree (x_iname.value);
	}
}
Example #4
0
int SetWindowManagerHints(Display * prDisplay, const char *psPrgClass,
                          Window nWnd, int nMinWidth, int nMinHeight,
			  const char *psTitle, const char *psIconTitle,
			  Pixmap nIconPixmap)
{
  XSizeHints rSizeHints;

  XWMHints rWMHints;
  XClassHint rClassHint;
  XTextProperty prWindowName, prIconName;

  if (!XStringListToTextProperty ((char**) &psTitle, 1, &prWindowName)
      || !XStringListToTextProperty ((char**) &psIconTitle, 1, &prIconName))
    return 1;			/* No memory! */

  rSizeHints.flags = PPosition | PSize | PMinSize;
  rSizeHints.min_width = nMinWidth;
  rSizeHints.min_height = nMinHeight;

  rWMHints.flags = StateHint | IconPixmapHint | InputHint;
  rWMHints.initial_state = NormalState;
  rWMHints.input = True;
  rWMHints.icon_pixmap = nIconPixmap;

  rClassHint.res_name = 0;
  rClassHint.res_class = (char*) psPrgClass;

  XSetWMProperties (prDisplay, nWnd, &prWindowName, &prIconName, 0, 0,
		    &rSizeHints, &rWMHints, &rClassHint);

  return 0;
}
Example #5
0
int
_xsetlabel(char *label)
{
	XTextProperty name;

	/*
	 * Label and other properties required by ICCCCM.
	 */
	memset(&name, 0, sizeof name);
	if(label == nil)
		label = "pjw-face-here";
	name.value = (uchar*)label;
	name.encoding = XA_STRING;
	name.format = 8;
	name.nitems = strlen((char*)name.value);

	XSetWMProperties(
		_x.display,	/* display */
		_x.drawable,	/* window */
		&name,		/* XA_WM_NAME property */
		&name,		/* XA_WM_ICON_NAME property */
		nil,		/* XA_WM_COMMAND */
		0,		/* argc */
		nil,		/* XA_WM_NORMAL_HINTS */
		nil,		/* XA_WM_HINTS */
		nil	/* XA_WM_CLASSHINTS */
	);
	XFlush(_x.display);
	return 0;
}
Example #6
0
void
Xutf8SetWMProperties (
    Display *dpy,
    Window w,
    _Xconst char *windowName,
    _Xconst char *iconName,
    char **argv,
    int argc,
    XSizeHints *sizeHints,
    XWMHints *wmHints,
    XClassHint *classHints)
{
    XTextProperty wname, iname;
    XTextProperty *wprop = NULL;
    XTextProperty *iprop = NULL;

    if (windowName &&
	Xutf8TextListToTextProperty(dpy, (char**)&windowName, 1,
				    XStdICCTextStyle, &wname) >= Success)
	wprop = &wname;
    if (iconName &&
	Xutf8TextListToTextProperty(dpy, (char**)&iconName, 1,
				    XStdICCTextStyle, &iname) >= Success)
	iprop = &iname;
    XSetWMProperties(dpy, w, wprop, iprop, argv, argc,
		     sizeHints, wmHints, classHints);
    if (wprop)
	Xfree((char *)wname.value);
    if (iprop)
	Xfree((char *)iname.value);

    /* Note: The WM_LOCALE_NAME property is set by XSetWMProperties. */
}
Example #7
0
set_window_title(Window win,char *string)
{
 XTextProperty wname,iname;
  XStringListToTextProperty(&string,1,&wname);
  XStringListToTextProperty(&string,1,&iname);
 XSetWMProperties(display,win,&wname,&iname,NULL,0,NULL,NULL,NULL);
}
/* Sets basic window manager hints for a window. */
void InputWindowXWin::setHints(Window window, char* window_name,
                               char* icon_name, char* class_name,
                               char* class_type)
{
    XTextProperty  w_name;
    XTextProperty  i_name;
    XSizeHints     sizehints;
    XWMHints       wmhints;
    XClassHint     classhints;
    int            status;

    /*
     * Generate window and icon names.
     */
   status = XStringListToTextProperty(&window_name, 1, &w_name);

   if (0 == status)
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << "Error allocating XString\n" << vprDEBUG_FLUSH;
   }

   status = XStringListToTextProperty(&icon_name, 1, &i_name);

   if (0 == status)
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << "Error allocating XString\n" << vprDEBUG_FLUSH;
   }

   sizehints.width       = mWidth;    /* -- Obsolete in R4 */
   sizehints.height      = mHeight;   /* -- Obsolete in R4 */
   sizehints.base_width  = mWidth;    /* -- New in R4 */
   sizehints.base_height = mHeight;   /* -- New in R4 */

   /* Set up flags for all the fields we've filled in. */
   sizehints.flags = USPosition | USSize | PBaseSize;

   /*   assume the window starts in "normal" (rather than
    *    iconic) state and wants keyboard input.
    */
   wmhints.initial_state = NormalState;
   wmhints.input         = True;
   wmhints.flags         = StateHint | InputHint;

   /* Fill in class name. */
   classhints.res_name  = class_name;
   classhints.res_class = class_type;

   XSetWMProperties(mXDisplay, window, &w_name, &i_name,
                    //argv, argc, /* Note reversed order. */
                    NULL, 0,
                    &sizehints, &wmhints, &classhints);

   XFree(w_name.value);
   XFree(i_name.value);
}
Example #9
0
static inline int up_x11createframe(void)
{
  XGCValues gcval;
  char *argv[2] = { "nuttx", NULL };
  char *winName = "NuttX";
  char *iconName = "NX";
  XTextProperty winprop;
  XTextProperty iconprop;
  XSizeHints hints;

  g_display = XOpenDisplay(NULL);
  if (g_display == NULL)
    {
      printf("Unable to open display.\n");
      return -1;
    }

  g_screen = DefaultScreen(g_display);
  g_window = XCreateSimpleWindow(g_display, DefaultRootWindow(g_display),
                                 0, 0, g_fbpixelwidth, g_fbpixelheight, 2,
                                 BlackPixel(g_display, g_screen),
                                 BlackPixel(g_display, g_screen));

  XStringListToTextProperty(&winName, 1, &winprop);
  XStringListToTextProperty(&iconName, 1, &iconprop);

  hints.flags = PSize | PMinSize | PMaxSize;
  hints.width = hints.min_width  = hints.max_width  = g_fbpixelwidth;
  hints.height= hints.min_height = hints.max_height = g_fbpixelheight;

  XSetWMProperties(g_display, g_window, &winprop, &iconprop, argv, 1,
                   &hints, NULL, NULL);

  XMapWindow(g_display, g_window);

  /* Select window input events */

  XSelectInput(g_display, g_window,
               ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask);

  /* Release queued events on the display */

#ifdef CONFIG_SIM_TOUCHSCREEN
  (void)XAllowEvents(g_display, AsyncBoth, CurrentTime);

  /* Grab mouse button 1, enabling mouse-related events */

  (void)XGrabButton(g_display, Button1, AnyModifier, g_window, 1,
                    ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
                    GrabModeAsync, GrabModeAsync, None, None);
#endif

  gcval.graphics_exposures = 0;
  g_gc = XCreateGC(g_display, g_window, GCGraphicsExposures, &gcval);

  return 0;
}
Example #10
0
static Window InitWindow(Display* dpy, int argc, char* argv[])
{
    static char* window_name = "Test Window Name";
    static char* icon_name = "XTest";
    XTextProperty windowName, iconName;
    int sn = DefaultScreen(dpy);
    unsigned dw = DisplayWidth(dpy, sn);
    unsigned dh = DisplayHeight(dpy, sn);
    XSizeHints size_hints = {0};
    XWMHints wm_hints = {0};
    XClassHint class_hints = {0};
    Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, sn)
            , 0, 0, dw / 2, dh / 2, 0
            //    , BlackPixel(dpy, screen_num)
            //    , WhitePixel(dpy, screen_num));
        , 0x000000, 0x88FF88);
    //To avoid sending Expose message the a part of window is covered
    //set the mode to backup the covered part of the window
    if(DoesBackingStore(DefaultScreenOfDisplay(dpy)) == Always)
    {
        XSetWindowAttributes attr;
        //CWBackingStore - Backup covered window image (not repaint)
        //CWBitGravity - repaint on size change
        attr.backing_store = Always;
        //only for top-right
        //    attr.bit_gravity = NorthWestGravity;
        //XChangeWindowAttributes keeps all other attr. unchanged
        XChangeWindowAttributes(dpy, win, CWBackingStore /*| CWBitGravity*/, &attr);
    }
    if(XStringListToTextProperty(&window_name, 1, &windowName) == 0)
    {
        perror("Structure allocation for windowName failed");
        return 0;
    }
    if(XStringListToTextProperty(&icon_name, 1, &iconName) == 0)
    {
        perror("Structure allocation for iconName failed");
        return 0;
    }
    size_hints.flags = PMinSize;
    size_hints.min_width = 200;
    size_hints.min_height = 100;

    wm_hints.flags = StateHint | InputHint;
    wm_hints.initial_state = NormalState;
    wm_hints.input = True;

    class_hints.res_name = argv[0];
    class_hints.res_class = "xtest";

    XSetWMProperties(dpy, win, &windowName, &iconName, argv, argc, &size_hints, &wm_hints, &class_hints);

    XFree(windowName.value);
    XFree(iconName.value);
    return win;
}
Example #11
0
static void Init_disp_prop(Display *d, Window win,
			   unsigned w, unsigned h, int x, int y,
			   int flags)
{
    XClassHint		xclh;
    XWMHints		xwmh;
    XSizeHints		xsh;

    xwmh.flags	   = InputHint|StateHint|IconPixmapHint;
    xwmh.input	   = True;
    xwmh.initial_state = NormalState;
    xwmh.icon_pixmap   = XCreateBitmapFromData(d, win,
					       (char *)icon_bits,
					       icon_width, icon_height);

    xsh.flags = (flags|PMinSize|PMaxSize|PBaseSize|PResizeInc);
    xsh.width = w;
    xsh.base_width =
    xsh.min_width = MIN_TOP_WIDTH;
    xsh.max_width = MAX_TOP_WIDTH;
    xsh.width_inc = 1;
    xsh.height = h;
    xsh.base_height =
    xsh.min_height = MIN_TOP_HEIGHT;
    xsh.max_height = MAX_TOP_HEIGHT;
    xsh.height_inc = 1;
    xsh.x = x;
    xsh.y = y;

    xclh.res_name = NULL;	/* NULL: Automatically uses Argv[0], */
    xclh.res_class = myClass; /* stripped of directory prefixes. */

    /*
     * Set the above properties.
     */
    XSetWMProperties(d, win, NULL, NULL, Argv, Argc,
		     &xsh, &xwmh, &xclh);

    /*
     * Now initialize icon and window title name.
     */
    XStoreName(d, win, TITLE);
    XSetIconName(d, win, TITLE);

    if (d != dpy)
	return;

    /*
     * Specify IO error handler and the WM_DELETE_WINDOW atom in
     * an attempt to catch 'nasty' quits.
     */
    ProtocolAtom = XInternAtom(d, "WM_PROTOCOLS", False);
    KillAtom = XInternAtom(d, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(d, win, &KillAtom, 1);
    XSetIOErrorHandler(FatalError);
}
Example #12
0
void set_window_title(Window win,char *string)
{
  XTextProperty wname,iname;
  XStringListToTextProperty(&string,1,&wname);
  XStringListToTextProperty(&string,1,&iname);
  
  XClassHint class_hints;
  class_hints.res_name="";
  class_hints.res_class="";
 
  XSetWMProperties(display,win,&wname,&iname,NULL,0,NULL,NULL,&class_hints);
}
Example #13
0
void
x_window_rep::set_hints (int min_w, int min_h, int max_w, int max_h) {
  XSizeHints* size_hints;
  XWMHints*   wm_hints;
  XClassHint* class_hints;
  ASSERT (size_hints= XAllocSizeHints (), "out of memory (X server)");
  ASSERT (wm_hints= XAllocWMHints (), "out of memory (X server)");
  ASSERT (class_hints= XAllocClassHint (), "out of memory (X server)");

  XTextProperty Window_Name;
  XTextProperty Icon_Name;
  ASSERT (XStringListToTextProperty (&name, 1, &Window_Name) != 0,
	  "out of memory (X server)");
  ASSERT (XStringListToTextProperty (&name, 1, &Icon_Name) != 0,
	  "out of memory (X server)");

  // time_t start_1= texmacs_time ();
  Pixmap pm= retrieve_pixmap (load_xpm ("TeXmacs.xpm"));
  // cout << "Getting pixmap required " << (texmacs_time ()-start_1) << " ms\n";

  // time_t start_2= texmacs_time ();
  size_hints->flags       = PPosition | PSize | PMinSize | PMaxSize;
  size_hints->min_width   = min_w;
  size_hints->min_height  = min_h;
  size_hints->max_width   = max_w;
  size_hints->max_height  = max_h;
  wm_hints->initial_state = NormalState;
  wm_hints->input         = true;
  wm_hints->icon_pixmap   = pm;
  wm_hints->flags         = StateHint | IconPixmapHint | InputHint;
  class_hints->res_name   = name;
  class_hints->res_class  = name;

  XSetWMProperties (
    dpy,
    win,
    &Window_Name,
    &Icon_Name,
    gui->argv,
    gui->argc,
    size_hints,
    wm_hints,
    class_hints
  );

  XFree(size_hints);
  XFree(wm_hints);
  XFree(class_hints);
  XFree(Window_Name.value);
  XFree(Icon_Name.value);
  // cout << "Setting hints required " << (texmacs_time ()-start_2) << " ms\n";
}
Example #14
0
/* CENTRY */
int GLUTAPIENTRY
glutCreateWindow(const char *title)
{
  static int firstWindow = 1;
  GLUTwindow *window;
#if !defined(_WIN32) && !defined(__OS2__)
  XWMHints *wmHints;
#endif
  Window win;
  XTextProperty textprop;

  if (__glutGameModeWindow) {
    __glutFatalError("cannot create windows in game mode.");
  }
  window = __glutCreateWindow(NULL,
    __glutSizeHints.x, __glutSizeHints.y,
    __glutInitWidth, __glutInitHeight,
    /* not game mode */ 0);
  win = window->win;
  /* Setup ICCCM properties. */
  textprop.value = (unsigned char *) title;
  textprop.encoding = XA_STRING;
  textprop.format = 8;
  textprop.nitems = strlen(title);
#if defined(__OS2__)
  WinSetWindowText(window->frame, (PCSZ)title);
  if (__glutIconic) {
    window->desiredMapState = IconicState;
  }
#elif defined(_WIN32)
  SetWindowText(win, title);
  if (__glutIconic) {
    window->desiredMapState = IconicState;
  }
#else
  wmHints = XAllocWMHints();
  wmHints->initial_state =
    __glutIconic ? IconicState : NormalState;
  wmHints->flags = StateHint;
  XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
  /* Only put WM_COMMAND property on first window. */
    firstWindow ? __glutArgv : NULL,
    firstWindow ? __glutArgc : 0,
    &__glutSizeHints, wmHints, NULL);
  XFree(wmHints);
  XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
#endif
  firstWindow = 0;
  return window->num + 1;
}
Example #15
0
static void make_sbox_windows(STRING_BOX *sb, int row, int col, char *title,
                              int maxchar) {
  int width, height;
  int i;
  int xpos, ypos, n = sb->n;
  int xstart, ystart;

  XTextProperty winname;
  XSizeHints size_hints;
  Window base;
  width = (maxchar + 4) * col * DCURX;
  height = (row + 4) * (DCURY + 16);
  base = make_plain_window(DefaultRootWindow(display), 0, 0, width, height, 4);
  size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  size_hints.x = 0;
  size_hints.y = 0;
  size_hints.width = width;
  size_hints.height = height;
  size_hints.min_width = width;
  size_hints.min_height = height;
  size_hints.max_width = width;
  size_hints.max_height = height;

  XClassHint class_hints;
  class_hints.res_name = "";
  class_hints.res_class = "";

  make_icon((char *)info_bits, info_width, info_height, base);
  XStringListToTextProperty(&title, 1, &winname);
  XSetWMProperties(display, base, &winname, NULL, NULL, 0, &size_hints, NULL,
                   &class_hints);
  XFree(winname.value);
  sb->base = base;
  sb->hgt = height;
  sb->wid = width;
  ystart = DCURY;
  xstart = DCURX;
  for (i = 0; i < n; i++) {
    xpos = xstart + (maxchar + 4) * DCURX * (i / row);
    ypos = ystart + (i % row) * (DCURY + 10);
    sb->win[i] = make_window(base, xpos, ypos, maxchar * DCURX, DCURY, 1);
  }

  ypos = height - 2 * DCURY;
  xpos = (width - 16 * DCURX) / 2;
  (sb->ok) = make_window(base, xpos, ypos, 8 * DCURX, DCURY, 1);
  (sb->cancel) =
      make_window(base, xpos + 8 * DCURX + 4, ypos, 8 * DCURX, DCURY, 1);
  XRaiseWindow(display, base);
}
Example #16
0
static void make_ebox_windows(EDIT_BOX *sb, const char *title) {
  int width, height;
  int i;
  int xpos, ypos, n = sb->n;
  int xstart, ystart;

  XTextProperty winname;
  XSizeHints size_hints;
  Window base;
  width = (MAX_LEN_EBOX + 4) * DCURX;
  height = (n + 4) * (DCURY + 16);
  base = make_plain_window(DefaultRootWindow(display), 0, 0, width, height, 4);
  size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  size_hints.x = 0;
  size_hints.y = 0;
  size_hints.width = width;
  size_hints.height = height;
  size_hints.min_width = width;
  size_hints.min_height = height;
  size_hints.max_width = width;
  size_hints.max_height = height;
  XStringListToTextProperty((char **)&title, 1, &winname);
  XSetWMProperties(display, base, &winname, NULL, NULL, 0, &size_hints, NULL,
                   NULL);
  XFree(winname.value);
  sb->base = base;

  ystart = DCURY;
  xstart = DCURX;
  for (i = 0; i < n; i++) {
    xpos = xstart;
    ypos = ystart + i * (DCURY + 10);
    sb->win[i] = make_window(base, xpos, ypos, MAX_LEN_EBOX * DCURX, DCURY, 1);
  }

  ypos = height - 2 * DCURY;
  xpos = (width - 19 * DCURX) / 2;
  sb->ok = make_window(base, xpos, ypos, 2 * DCURX, DCURY, 1);
  sb->cancel = make_window(base, xpos + 4 * DCURX, ypos, 6 * DCURX, DCURY, 1);
  sb->reset = make_window(base, xpos + 12 * DCURX, ypos, 5 * DCURX, DCURY, 1);

  XSelectInput(display, sb->cancel, BUT_MASK);
  XSelectInput(display, sb->ok, BUT_MASK);
  XSelectInput(display, sb->reset, BUT_MASK);
  x11_events_listen(g_x11_events, X11_EVENTS_ANY_WINDOW, BUT_MASK,
                    edit_box_event, sb);

  XRaiseWindow(display, base);
}
Example #17
0
void make_icon(const char *icon, int wid, int hgt, Window w) {
  Pixmap icon_map;
  XWMHints wm_hints;
  icon_map = XCreateBitmapFromData(display, w, icon, wid, hgt);
  wm_hints.initial_state = NormalState;
  wm_hints.input = True;
  wm_hints.icon_pixmap = icon_map;
  wm_hints.flags = StateHint | IconPixmapHint | InputHint;

  XClassHint class_hints;
  class_hints.res_name = "";
  class_hints.res_class = "";
  XSetWMProperties(display, w, NULL, NULL, NULL, 0, NULL, &wm_hints,
                   &class_hints);
}
Example #18
0
/* CENTRY */
int GLUTAPIENTRY
glutCreateWindow(const char *title)
{
    static int firstWindow = 1;
    GLUTwindow *window;
#if !defined(_WIN32)
    XWMHints *wmHints;
#endif
    Window win;
    XTextProperty textprop;
    const char **pvalue = (const char**) &textprop.value;  // See below for why...

    if (__glutGameModeWindow) {
        __glutFatalError("cannot create windows in game mode.");
    }
    window = __glutCreateWindow(NULL,
                                __glutSizeHints.x, __glutSizeHints.y,
                                __glutInitWidth, __glutInitHeight,
                                /* not game mode */ 0);
    win = window->win;
    /* Setup ICCCM properties. */
    *pvalue = title; /* We want to write "textprop.value = (unsigned char *) title;"
                      but gcc complains about discarding const-ness of pointer */
    assert(!strcmp((const char*)textprop.value, title));
    textprop.encoding = XA_STRING;
    textprop.format = 8;
    textprop.nitems = (unsigned long)strlen(title);
#if defined(_WIN32)
    SetWindowText(win, title);
    if (__glutIconic) {
        window->desiredMapState = IconicState;
    }
#else
    wmHints = XAllocWMHints();
    wmHints->initial_state =
        __glutIconic ? IconicState : NormalState;
    wmHints->flags = StateHint;
    XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
                     /* Only put WM_COMMAND property on first window. */
                     firstWindow ? __glutArgv : NULL,
                     firstWindow ? __glutArgc : 0,
                     &__glutSizeHints, wmHints, NULL);
    XFree(wmHints);
    XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
#endif
    firstWindow = 0;
    return window->num + 1;
}
Example #19
0
/*
 ****************************************************************
 *	Cria a janela uma única vez				*
 ****************************************************************
 */
Window
create_window (Display *dpy)
{
	Window		win;

	/*
	 *	Cria a janela onde será mostrada a imagem.
	 */
        win =	XCreateSimpleWindow
                (	dpy, RootWindow (dpy, screen),
			0, 0, 100, 100, 1, 0, 0
		);

	if (!win)
		msg ("$Não consegui criar a janela");

	/*
	 *	Prepara a máscara de eventos e as dicas para o "fvwm".
	 */
	XSelectInput (dpy, win, ExposureMask|KeyPressMask|ButtonPressMask);

	classhint.res_name  = (char *)pgname;
	classhint.res_class = "XPaint";

	wmhint.input		= True;
	wmhint.initial_state	= NormalState;
	wmhint.flags		= InputHint | StateHint;

	XSetWMProperties
	(	dpy, win, NULL, NULL, (char **)save_argv, save_argc,
		NULL, &wmhint, &classhint
	);

	/*
	 *	Mapeia a janela.
	 */
	XMapWindow (dpy, win);

	return (win);

}	/* end create_window */
Example #20
0
void
XmbSetWMProperties(Display *dpy, Window w, _Xconst char *windowName,
	_Xconst char *iconName, char **argv, int argc, XSizeHints * sizeHints,
	XWMHints * wmHints, XClassHint * classHints)
{
	XTextProperty wname, iname;
	XTextProperty *wprop = NULL;
	XTextProperty *iprop = NULL;

	/* fake up XTextProperty struct members for XSetWMName*/
	if (windowName) {
		wname.value = (unsigned char *)windowName;
		wprop = &wname;
	}
	if (iconName) {
		iname.value = (unsigned char *)iconName;
		iprop = &iname;
	}
	XSetWMProperties(dpy, w, wprop, iprop, argv, argc, sizeHints, wmHints,
		classHints);
}
Example #21
0
void VID_SetWindowTitle( Window win, char *pszName )
{
	XTextProperty	textprop;
	XWMHints		*wmHints;

    // Setup ICCCM properties
    textprop.value = (unsigned char *)pszName;
    textprop.encoding = XA_STRING;
    textprop.format = 8;
    textprop.nitems = strlen(pszName);
    wmHints = XAllocWMHints();
    wmHints->initial_state = NormalState;
    wmHints->flags = StateHint;
    XSetWMProperties( x_disp, win, &textprop, &textprop,
					  // Only put WM_COMMAND property on first window.
					  com_argv, com_argc, NULL, NULL, NULL );
    XFree( wmHints );

    aWMDelete = XInternAtom( x_disp, "WM_DELETE_WINDOW", False );
    XSetWMProtocols( x_disp, win, &aWMDelete, 1 );
}
Example #22
0
/* CENTRY */
int APIENTRY
glutCreateWindow(const char *title)
{
  static int firstWindow = 1;
  GLUTwindow *window;
#if !defined(WIN32)
  XWMHints *wmHints;
#endif
  Window win;
  XTextProperty textprop;

  window = __glutCreateWindow(NULL,
    __glutSizeHints.x, __glutSizeHints.y,
    __glutInitWidth, __glutInitHeight);
  win = window->win;
  /* Setup ICCCM properties. */
  textprop.value = (unsigned char *) title;
  textprop.encoding = XA_STRING;
  textprop.format = 8;
  textprop.nitems = strlen(title);
#if defined(WIN32)
  SetWindowText(win, title);
  if (__glutIconic)
    ShowWindow(win, SW_MINIMIZE);
#else
  wmHints = XAllocWMHints();
  wmHints->initial_state =
    __glutIconic ? IconicState : NormalState;
  wmHints->flags = StateHint;
  XSetWMProperties(__glutDisplay, win, &textprop, &textprop,
  /* Only put WM_COMMAND property on first window. */
    firstWindow ? __glutArgv : NULL,
    firstWindow ? __glutArgc : 0,
    &__glutSizeHints, wmHints, NULL);
  XFree(wmHints);
  XSetWMProtocols(__glutDisplay, win, &__glutWMDeleteWindow, 1);
#endif
  firstWindow = 0;
  return window->num + 1;
}
Example #23
0
static inline void
set_wm_pid (ClutterStageX11 *stage_x11)
{
  ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11);
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend);
  long pid;

  if (stage_x11->xwin == None || stage_x11->is_foreign_xwin)
    return;

  /* this will take care of WM_CLIENT_MACHINE and WM_LOCALE_NAME */
  XSetWMProperties (backend_x11->xdpy, stage_x11->xwin,
                    NULL,
                    NULL,
                    NULL, 0,
                    NULL, NULL, NULL);

  pid = getpid ();
  XChangeProperty (backend_x11->xdpy,
                   stage_x11->xwin,
                   backend_x11->atom_NET_WM_PID, XA_CARDINAL, 32,
                   PropModeReplace,
                   (guchar *) &pid, 1);
}
Example #24
0
void setWindowHints(Window win, char **argv, int argc, char *window_name,
                    char *icon_name, char *res_name, char *res_class)
{
  XSizeHints *size_hints;
  XWMHints *wm_hints;
  XClassHint *class_hints;
  XTextProperty windowName, iconName;

  XSelectInput(Spw_Dpy, win,
               ButtonPressMask | ButtonReleaseMask
               | KeyPressMask | KeyReleaseMask
               | ExposureMask 
               );

  /*
   * Allocate and set the the Size hints in a friendly way
   */

  if ( !(size_hints = XAllocSizeHints()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }
  /*
   *  What things we will be setting.  Position and size refer to
   *  if the user set the values (via a resource file for example)
   *  or if the program set the values.
   */
  size_hints->flags = 
                      PPosition   | /* Program specified position      */
                      PSize       | /* Program specified size          */
                      PBaseSize   | /* Program specified base size     */
                      0;

  /*
   *  Now set the values.
   */
  size_hints->base_width = Spw_WindowWidth;
  size_hints->base_height = Spw_WindowHeight;
   
  /*
   * Allocate and set the the Window Manager hints in a friendly way.
   * This is probably the most critical to set correctly as some
   * WMs (olwm) are REALLY picky about setting them correctly and
   * hose you if you don't.  Like, for example, not sending you any
   * keypresses.
   */
  if ( !(wm_hints = XAllocWMHints()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }

  /*
   *  What hints we will be setting
   */
  wm_hints->flags = InputHint        | /* Setting if we expect input  */
                    StateHint        | /* What initial state to be in */
                    IconPixmapHint   | /* Set the Icon pixmap         */
                    IconMaskHint     | /* Set the Icon Shape Mask     */
                    0;

  wm_hints->input = TRUE;                /* InputHint */
  wm_hints->initial_state = NormalState  /* or IconicState */; /* StateHint */

  wm_hints->icon_pixmap = XCreateBitmapFromData(Spw_Dpy,
                                                Spw_mainWindow,
                                                (char *)sbXcityfly_icon_bits,
                                                sbXcityfly_icon_width,
                                                sbXcityfly_icon_height);
  wm_hints->icon_mask = XCreateBitmapFromData(Spw_Dpy,
                                              Spw_mainWindow,
                                              (char *)sbXcityfly_iconMask_bits,
                                              sbXcityfly_iconMask_width,
                                              sbXcityfly_iconMask_height);
  /*
   * Allocate and set the the Class hints in a friendly way
   */
  if ( !(class_hints = XAllocClassHint()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }
   /*
    *  Not much to say this is about it for class hints....
    */
  class_hints->res_name = res_name;
  class_hints->res_class = res_class;
  
  /*
   * Convert names into X strings
   */

  if ( XStringListToTextProperty( &window_name, 1, &windowName) == 0 )
     {
     fprintf(stderr,"Couldn't create string\n");
     exit(-1);
     }
  if ( XStringListToTextProperty( &icon_name, 1, &iconName) == 0 )
     {
     fprintf(stderr,"Couldn't create string\n");
     exit(-1);
     }

  /*
   * Finally we can set the properities.
   * This is supposedly the "correct" call.  Most of the
   * others like SetWMHints are obsolete.
   */

  XSetWMProperties(Spw_Dpy, win, &windowName, &iconName,
                   argv, argc, size_hints, wm_hints, class_hints);

}
Example #25
0
Memimage*
_xattach(char *label, char *winsize)
{
	char *argv[2], *disp;
	int i, havemin, height, mask, n, width, x, xrootid, y;
	Rectangle r;
	XClassHint classhint;
	XDrawable pmid;
	XPixmapFormatValues *pfmt;
	XScreen *xscreen;
	XSetWindowAttributes attr;
	XSizeHints normalhint;
	XTextProperty name;
	XVisualInfo xvi;
	XWindow xrootwin;
	XWindowAttributes wattr;
	XWMHints hint;
	Atom atoms[2];

	/*
	if(XInitThreads() == 0){
		fprint(2, "XInitThreads failed\n");
		abort();
	}
	*/

	/*
	 * Connect to X server.
	 */
	_x.display = XOpenDisplay(NULL);
	if(_x.display == nil){
		disp = getenv("DISPLAY");
		werrstr("XOpenDisplay %s: %r", disp ? disp : ":0");
		free(disp);
		return nil;
	}
	_x.fd = ConnectionNumber(_x.display);
	XSetErrorHandler(xerror);
	XSetIOErrorHandler(xioerror);
	xrootid = DefaultScreen(_x.display);
	xrootwin = DefaultRootWindow(_x.display);

	/* 
	 * Figure out underlying screen format.
	 */
	if(XMatchVisualInfo(_x.display, xrootid, 24, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 24, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 24;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 16, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 16, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 16;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 15, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 15, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 15;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 8, PseudoColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 8, StaticColor, &xvi)){
		if(_x.depth > 8){
			werrstr("can't deal with colormapped depth %d screens",
				_x.depth);
			goto err0;
		}
		_x.vis = xvi.visual;
		_x.depth = 8;
	}
	else{
		_x.depth = DefaultDepth(_x.display, xrootid);
		if(_x.depth != 8){
			werrstr("can't understand depth %d screen", _x.depth);
			goto err0;
		}
		_x.vis = DefaultVisual(_x.display, xrootid);
	}

	if(DefaultDepth(_x.display, xrootid) == _x.depth)
		_x.usetable = 1;

	/*
	 * _x.depth is only the number of significant pixel bits,
	 * not the total number of pixel bits.  We need to walk the
	 * display list to find how many actual bits are used
	 * per pixel.
	 */
	_x.chan = 0;
	pfmt = XListPixmapFormats(_x.display, &n);
	for(i=0; i<n; i++){
		if(pfmt[i].depth == _x.depth){
			switch(pfmt[i].bits_per_pixel){
			case 1:	/* untested */
				_x.chan = GREY1;
				break;
			case 2:	/* untested */
				_x.chan = GREY2;
				break;
			case 4:	/* untested */
				_x.chan = GREY4;
				break;
			case 8:
				_x.chan = CMAP8;
				break;
			case 15:
				_x.chan = RGB15;
				break;
			case 16: /* how to tell RGB15? */
				_x.chan = RGB16;
				break;
			case 24: /* untested (impossible?) */
				_x.chan = RGB24;
				break;
			case 32:
				_x.chan = XRGB32;
				break;
			}
		}
	}
	if(_x.chan == 0){
		werrstr("could not determine screen pixel format");
		goto err0;
	}

	/*
	 * Set up color map if necessary.
	 */
	xscreen = DefaultScreenOfDisplay(_x.display);
	_x.cmap = DefaultColormapOfScreen(xscreen);
	if(_x.vis->class != StaticColor){
		plan9cmap();
		setupcmap(xrootwin);
	}

	/*
	 * We get to choose the initial rectangle size.
	 * This is arbitrary.  In theory we should read the
	 * command line and allow the traditional X options.
	 */
	mask = 0;
	x = 0;
	y = 0;
	if(winsize && winsize[0]){
		if(parsewinsize(winsize, &r, &havemin) < 0)
			sysfatal("%r");
	}else{
		/*
		 * Parse the various X resources.  Thanks to Peter Canning.
		 */
		char *screen_resources, *display_resources, *geom, 
			*geomrestype, *home, *file;
		XrmDatabase database;
		XrmValue geomres;

		database = XrmGetDatabase(_x.display);
		screen_resources = XScreenResourceString(xscreen);
		if(screen_resources != nil){
			XrmCombineDatabase(XrmGetStringDatabase(screen_resources), &database, False);
			XFree(screen_resources);
		}

		display_resources = XResourceManagerString(_x.display);
		if(display_resources == nil){
			home = getenv("HOME");
			if(home!=nil && (file=smprint("%s/.Xdefaults", home)) != nil){
				XrmCombineFileDatabase(file, &database, False);
				free(file);
			}
			free(home);
		}else
			XrmCombineDatabase(XrmGetStringDatabase(display_resources), &database, False);

		geom = smprint("%s.geometry", label);
		if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres))
			mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height);
		free(geom);

		if((mask & WidthValue) && (mask & HeightValue)){
			r = Rect(0, 0, width, height);
		}else{
			r = Rect(0, 0, WidthOfScreen(xscreen)*3/4,
					HeightOfScreen(xscreen)*3/4);
			if(Dx(r) > Dy(r)*3/2)
				r.max.x = r.min.x + Dy(r)*3/2;
			if(Dy(r) > Dx(r)*3/2)
				r.max.y = r.min.y + Dx(r)*3/2;
		}
		if(mask & XNegative){
			x += WidthOfScreen(xscreen);
		}
		if(mask & YNegative){
			y += HeightOfScreen(xscreen);
		}
		havemin = 0;
	}
	screenrect = Rect(0, 0, WidthOfScreen(xscreen), HeightOfScreen(xscreen));
	windowrect = r;

	memset(&attr, 0, sizeof attr);
	attr.colormap = _x.cmap;
	attr.background_pixel = ~0;
	attr.border_pixel = 0;
	_x.drawable = XCreateWindow(
		_x.display,	/* display */
		xrootwin,	/* parent */
		x,		/* x */
		y,		/* y */
		Dx(r),		/* width */
	 	Dy(r),		/* height */
		0,		/* border width */
		_x.depth,	/* depth */
		InputOutput,	/* class */
		_x.vis,		/* visual */
				/* valuemask */
		CWBackPixel|CWBorderPixel|CWColormap,
		&attr		/* attributes (the above aren't?!) */
	);

	/*
	 * Label and other properties required by ICCCCM.
	 */
	memset(&name, 0, sizeof name);
	if(label == nil)
		label = "pjw-face-here";
	name.value = (uchar*)label;
	name.encoding = XA_STRING;
	name.format = 8;
	name.nitems = strlen((char*)name.value);

	memset(&normalhint, 0, sizeof normalhint);
	normalhint.flags = PSize|PMaxSize;
	if(winsize && winsize[0]){
		normalhint.flags &= ~PSize;
		normalhint.flags |= USSize;
		normalhint.width = Dx(r);
		normalhint.height = Dy(r);
	}else{
		if((mask & WidthValue) && (mask & HeightValue)){
			normalhint.flags &= ~PSize;
			normalhint.flags |= USSize;
			normalhint.width = width;
			normalhint.height = height;
		}
		if((mask & WidthValue) && (mask & HeightValue)){
			normalhint.flags |= USPosition;
			normalhint.x = x;
			normalhint.y = y;
		}
	}

	normalhint.max_width = WidthOfScreen(xscreen);
	normalhint.max_height = HeightOfScreen(xscreen);

	memset(&hint, 0, sizeof hint);
	hint.flags = InputHint|StateHint;
	hint.input = 1;
	hint.initial_state = NormalState;

	memset(&classhint, 0, sizeof classhint);
	classhint.res_name = label;
	classhint.res_class = label;

	argv[0] = label;
	argv[1] = nil;

	XSetWMProperties(
		_x.display,	/* display */
		_x.drawable,	/* window */
		&name,		/* XA_WM_NAME property */
		&name,		/* XA_WM_ICON_NAME property */
		argv,		/* XA_WM_COMMAND */
		1,		/* argc */
		&normalhint,	/* XA_WM_NORMAL_HINTS */
		&hint,		/* XA_WM_HINTS */
		&classhint	/* XA_WM_CLASSHINTS */
	);
	XFlush(_x.display);

	if(havemin){
		XWindowChanges ch;

		memset(&ch, 0, sizeof ch);
		ch.x = r.min.x;
		ch.y = r.min.y;
		XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch);
		/*
		 * Must pretend origin is 0,0 for X.
		 */
		r = Rect(0,0,Dx(r),Dy(r));
	}
	/*
	 * Look up clipboard atom.
	 */
	_x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
	_x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
	_x.targets = XInternAtom(_x.display, "TARGETS", False);
	_x.text = XInternAtom(_x.display, "TEXT", False);
	_x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
	_x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
	_x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
	_x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);

	atoms[0] = _x.takefocus;
	atoms[1] = _x.losefocus;
	XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
		PropModeReplace, (uchar*)atoms, 2);

	/*
	 * Put the window on the screen, check to see what size we actually got.
	 */
	XMapWindow(_x.display, _x.drawable);
	XSync(_x.display, False);

	if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
		fprint(2, "XGetWindowAttributes failed\n");
	else if(wattr.width && wattr.height){
		if(wattr.width != Dx(r) || wattr.height != Dy(r)){
			r.max.x = wattr.width;
			r.max.y = wattr.height;
		}
	}else
		fprint(2, "XGetWindowAttributes: bad attrs\n");

	/*
	 * Allocate our local backing store.
	 */
	_x.screenr = r;
	_x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
	_x.nextscreenpm = _x.screenpm;
	_x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm);

	/*
	 * Allocate some useful graphics contexts for the future.
	 */
	_x.gcfill	= xgc(_x.screenpm, FillSolid, -1);
	_x.gccopy	= xgc(_x.screenpm, -1, -1);
	_x.gcsimplesrc 	= xgc(_x.screenpm, FillStippled, -1);
	_x.gczero	= xgc(_x.screenpm, -1, -1);
	_x.gcreplsrc	= xgc(_x.screenpm, FillTiled, -1);

	pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1);
	_x.gcfill0	= xgc(pmid, FillSolid, 0);
	_x.gccopy0	= xgc(pmid, -1, -1);
	_x.gcsimplesrc0	= xgc(pmid, FillStippled, -1);
	_x.gczero0	= xgc(pmid, -1, -1);
	_x.gcreplsrc0	= xgc(pmid, FillTiled, -1);
	XFreePixmap(_x.display, pmid);

	return _x.screenimage;

err0:
	/*
	 * Should do a better job of cleaning up here.
	 */
	XCloseDisplay(_x.display);
	return nil;
}
Example #26
0
void I_InitGraphics(void)
{
  const char*	displayname = NULL;
  int		n;
  int		pnum;
  int		x=0;
  int		y=0;
  
  {  
    static int		firsttime=1;
    
    if (!firsttime) {
      return;
    }
    firsttime = 0;
  }

  { // Check for screen enlargement
    char str[3] = { '-', 0, 0 };

    for (n=1; n<4; n++) {
      str[1] = n + '0';
      if (M_CheckParm(str)) multiply = n;
    }
  }
  
  X_width = SCREENWIDTH * multiply;
  X_height = SCREENHEIGHT * multiply;
  
  // check for command-line geometry
  if ( (pnum=M_CheckParm("-geom")) ? 1 : (pnum=M_CheckParm("-geometry"))) 
   if (pnum+1 < myargc) { // check parm given
    // warning: char format, different type arg
    char	xsign=' ';
    char	ysign=' ';
    const char* pg = myargv[pnum+1];
    
    pg += strcspn(pg, "+-");
    
    // warning: char format, different type arg 3,5
    n = sscanf(pg, "%c%d%c%d", &xsign, &x, &ysign, &y);
    
    if (n==2)
      x = y = 0;
    else if (n==4) {
      if (xsign == '-')
	x = -x;
      if (ysign == '-')
	y = -y;
    } else
      fprintf(stderr, "I_InitGraphics: bad -geom offsets \"%s\"\n", pg);
  }
  
  // check for command-line display name
  if ( (pnum=M_CheckParm("-disp")) ) // suggest parentheses around assignment
    displayname = myargv[pnum+1];
  // CPhipps - support more standard -display param
  if ( (pnum=M_CheckParm("-display")) ) // ditto
    displayname = myargv[pnum+1];
  // CPhipps - and -displayname as for xterm
  if ( (pnum=M_CheckParm("-displayname")) ) // ditto
    displayname = myargv[pnum+1];

  // open the display
  if (!(X_display = XOpenDisplay(displayname))) {
    if (displayname)
      I_Error("Could not open display [%s]", displayname);
    else
      I_Error("Could not open display (DISPLAY=[%s])", getenv("DISPLAY"));
  }

  // use the default visual 
  X_screen = DefaultScreen(X_display);

  X_deletewin = XInternAtom(X_display, "WM_DELETE_WINDOW", False);

  // check for the MITSHM extension
  // even if it's available, make sure it's a local connection
  lprintf(LO_INFO,"I_InitGraphics:");

#ifdef HAVE_LIBXXF86DGA
  if ((doDga = (M_CheckParm("-dga") && XF86DGAQueryExtension(X_display, &n, &n)) )) {
    lprintf(LO_INFO,"I_InitGraphics: found DGA extension\n");
    if (M_CheckParm("-noaccel") || (X_opt & 1)) doDga = false;
    else lprintf(LO_INFO, "(using DGA)");
  }
  else 
#endif
#ifdef HAVE_LIBXEXT
  if ((doShm = XShmQueryExtension(X_display))) {

    if (!displayname) displayname = getenv("DISPLAY");
    
    if (displayname) {
      // CPhipps - don't modify the original string, please.
      //         - oops my code here was totally wrong
      // I have no idea exactly what should go here.

      if (M_CheckParm("-noaccel") || (X_opt & 1)) doShm = false;
      else lprintf(LO_INFO, "(using MITShm)");
    }
  }
  else 
#endif 
    if (devparm) 
      fprintf(stderr, "No MITShm extension in server");

  if (devparm)
    fputc('\n', stderr);

  if ((X_visual = I_FindMode(X_screen)) == NULL) 
    I_Error("Unsupported visual");
  
  // create the colormap
  X_cmap = XCreateColormap(X_display, RootWindow(X_display, X_screen), 
			   X_visual, true_color ? AllocNone : AllocAll);

#ifdef HAVE_LIBXXF86DGA
  /* setup for DGA */
  if(doDga) {
     char *fb;
     X_mainWindow=RootWindow(X_display, X_screen);
     XF86DGAGetViewPortSize(X_display, X_screen, &DGA_width, &DGA_height);
     XF86DGAGetVideo(X_display, X_screen, &fb,
		     &DGA_real_width, &DGA_pagelen, &DGA_memlen);

     fprintf(stderr,
	     "I_InitGraphics: DGA reports %dx%d scan=%d page=%d mem=%d\n",
	     DGA_width,DGA_height,DGA_real_width,DGA_pagelen,DGA_memlen);

     out_buffer=(void*)fb;

     XF86DGADirectVideo(X_display, X_screen, XF86DGADirectGraphics);
     XF86DGASetVidPage(X_display, X_screen, 0);
     XF86DGAForkApp(X_screen);
     XSelectInput(X_display, X_mainWindow, KeyPressMask | KeyReleaseMask);
     fprintf(stderr,"DGA framebuffer @%p\n",fb);
     memset(fb,0,102400);
  }
#endif

#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif

  { // setup attributes for main window
    unsigned long	attribmask;
    XSetWindowAttributes attribs;

    attribmask = CWEventMask | CWColormap | CWBorderPixel;
    attribs.event_mask = KeyPressMask | KeyReleaseMask
#ifdef MONITOR_VISIBILITY
      | VisibilityChangeMask
#endif
      | ExposureMask;
    
    attribs.colormap = X_cmap;
    attribs.border_pixel = 0;
    
    // create the main window
    X_mainWindow = XCreateWindow( X_display,
				  RootWindow(X_display, X_screen),
				  x, y,
				  X_width, X_height,
				  0, // borderwidth
				  X_bpp, // depth
				  InputOutput, X_visual,
				  attribmask, &attribs );
  }
  
#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif

  {
    XClassHint c_hint;
    XTextProperty x_name;
    XSizeHints s_hint;
    XWMHints wm_hint;
    char lcase_buf[10], ucase_buf[10];
    char* str;

    strcpy(str = lcase_buf, lcase_lxdoom);
    XStringListToTextProperty(&str, 1, &x_name);

    s_hint.flags = PSize | PMinSize | PMaxSize;
    s_hint.min_width = s_hint.max_width = s_hint.base_width = X_width;
    s_hint.min_height = s_hint.max_height = s_hint.base_height = X_height;

    wm_hint.input = True;
    wm_hint.window_group = X_mainWindow;
    wm_hint.flags = InputHint | WindowGroupHint;

    strcpy(c_hint.res_name = lcase_buf, lcase_lxdoom);
    strcpy(c_hint.res_class = ucase_buf, ucase_lxdoom);
    
    XSetWMProtocols(X_display, X_mainWindow, &X_deletewin, 1);
    
    XSetWMProperties(X_display, X_mainWindow, &x_name, &x_name, 
		     (char**)myargv, myargc, &s_hint, &wm_hint, &c_hint);

    XFlush(X_display);
  }

#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif
  // Hide pointer while over this window
  XDefineCursor(X_display, X_mainWindow,
		I_XCreateNullCursor( X_display, X_mainWindow ) );
  
  { // create the GC
    XGCValues		xgcvalues;
    int		valuemask;
    
    valuemask = GCGraphicsExposures;
    xgcvalues.graphics_exposures = False;
    X_gc = XCreateGC(X_display, X_mainWindow, valuemask, &xgcvalues);
  }
  
#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif
  {
     // name the window
     XStoreName(X_display, X_mainWindow, "lxdoom");
  
     // map the window
     XMapWindow(X_display, X_mainWindow);
  }  

  // wait until it is OK to draw
#ifdef HAVE_LIBXXF86DGA
  if(!doDga)
#endif
  do {
    XNextEvent(X_display, &X_event);
  } while (!(X_event.type == Expose && !X_event.xexpose.count));

#ifdef HAVE_LIBXXF86DGA
  if(doDga) {}
  else
#endif

#ifdef HAVE_LIBXEXT
  if (doShm) {
    
    X_shmeventtype = XShmGetEventBase(X_display) + ShmCompletion;
    
    // create the image
    image = XShmCreateImage( X_display, X_visual,
			     X_bpp, ZPixmap,
			     0, &X_shminfo,
			     X_width, X_height );
    
    I_XShmGrabSharedMemory(image->bytes_per_line * image->height);
    
    if (!(out_buffer = (pval*)image->data)) {
      perror("");
      I_Error("shmat() failed in I_InitGraphics()");
    }
    
    // get the X server to attach to it
    if (!XShmAttach(X_display, &X_shminfo))
      I_Error("XShmAttach() failed in InitGraphics()");
    
    if (!expand_buffer) {
      // Render directly into MitSHM memory
      Z_Free(screens[0]);
      screens[0] = (unsigned char *) (image->data); 
    }
  } else
#endif 
  {
    if (!expand_buffer) {
      // Very efficient, render directly into image
      out_buffer = (pval*)screens[0];
    } else {
      // Will have to enlarge from rendering buffer
      //  into image buffer
      out_buffer = (pval*)malloc (X_width * X_height * BYTESPP);
    }

	{ 
/* hack to enable 15 bpp usage */
		int bpp=X_bpp;
		if(bpp==15)bpp=16;

    	image=XCreateImage( X_display, X_visual,
				X_bpp, ZPixmap,
				0, (char*)out_buffer,
				X_width, X_height,
				bpp, 0);
#ifdef NOT_NOW
    image=XCreateImage( X_display, X_visual,
			X_bpp, ZPixmap,
			0, (char*)out_buffer,
			X_width, X_height,
			X_bpp, 0);
#endif

	}
    if (!image) 
      I_Error("XCreateImage: failed to create image %dx%d %d bpp", 
	      X_width, X_height, X_bpp);
  }
  
  atexit(I_ShutdownGraphics);

  I_XInitInputs();
}
Example #27
0
Window Xvars::create_toplevel_window(int argc,char** argv,
                                     int dpyNum,const Size& size,
                                     const char* title,
                                     long eventMask) {
  // Creates with 0 border width.
  Window toplevel = 
    XCreateSimpleWindow(dpy[dpyNum],root[dpyNum],0,0,
                        size.width,size.height,
                        0,windowBorder[dpyNum],
                        windowBg[dpyNum]);

  XSizeHints size_hints;
  size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  size_hints.min_width = size.width;
  size_hints.min_height = size.height;
  size_hints.max_width = size.width;
  size_hints.max_height = size.height;

  XTextProperty windowName, iconName;
  // Should be safe to cast away const, XStringListToTextProperty doesn't 
  // mutate the string list argument.
  char *window_name = (char*)title;    // Will appear on window.
  char *icon_name = (char*)title;
  Status stat = XStringListToTextProperty(&window_name,1,&windowName);
  assert(stat);
  stat = XStringListToTextProperty(&icon_name,1,&iconName);
  assert(stat);
  
  // Hints to window manager.
  XWMHints wm_hints;
  wm_hints.initial_state = NormalState;
  wm_hints.input = True;
  wm_hints.flags = StateHint | InputHint;
  
  // Only set IconPixmap and IconMask hints if the pixmaps loaded 
  // correctly.
  if (iconPixmap[dpyNum]) {
    wm_hints.icon_pixmap = iconPixmap[dpyNum];
    wm_hints.flags |= IconPixmapHint;
    if (iconMask[dpyNum]) {
      wm_hints.icon_mask = iconMask[dpyNum];
      wm_hints.flags |= IconMaskHint;
    }
  }

  XClassHint class_hints;
  class_hints.res_name = argv[0];
  class_hints.res_class = "XEvil";

  XSetWMProperties(dpy[dpyNum],toplevel,
                   &windowName,&iconName,argv,argc,
                   &size_hints,&wm_hints,&class_hints);

  XSelectInput(dpy[dpyNum],toplevel,eventMask);

  // Add WM_DELETE_WINDOW protocol
  XChangeProperty(dpy[dpyNum],toplevel,
                  wmProtocols[dpyNum],XA_ATOM,
                  32,PropModePrepend,
                  (unsigned char *)&wmDeleteWindow[dpyNum],
                  1);

  return toplevel;
}
Example #28
0
slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
    m_x = std::min( sx, ex );
    m_y = std::min( sy, ey );
    m_width = std::max( sx, ex ) - m_x;
    m_height = std::max( sy, ey ) - m_y;
    m_r = r;
    m_g = g;
    m_b = b;
    m_a = a;
    m_border = border;
    m_window = None;
    m_highlight = highlight;
    m_glassPixels = 64;
    m_glassx = xengine->m_mousex;
    m_glassy = xengine->m_mousey;
    m_realglassx = xengine->m_mousex;
    m_realglassy = xengine->m_mousey;
    m_glassSize = 4;
    m_glassBorder = 1;
    m_monitors = xengine->getCRTCS();
    m_themed = false;
    m_shader = "simple";
    m_time = 0;

    // If we don't have a border, we don't exist, so just die.
    if ( m_border == 0 ) {
        return;
    }

    if ( m_highlight ) {
        m_border = 0;
    }

    static int visdata[] = {
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        GLX_DOUBLEBUFFER, True,
        GLX_RED_SIZE, 8,
        GLX_GREEN_SIZE, 8,
        GLX_BLUE_SIZE, 8,
        GLX_ALPHA_SIZE, 8,
        GLX_DEPTH_SIZE, 16,
        None
    };

    int numfbconfigs = 0;
    GLXFBConfig* fbconfigs = glXChooseFBConfig( xengine->m_display,  DefaultScreen( xengine->m_display ), visdata, &numfbconfigs );
    m_fbconfig = 0;
    for ( int i=0; i<numfbconfigs; i++ ) {
        m_visual = (XVisualInfo*)glXGetVisualFromFBConfig( xengine->m_display, fbconfigs[i] );
        if ( !m_visual ) {
            continue;
        }
        m_pictFormat = XRenderFindVisualFormat( xengine->m_display, m_visual->visual );
        if ( !m_pictFormat ) {
            continue;
        }
        m_fbconfig = fbconfigs[i];
        if ( m_pictFormat->direct.alphaMask > 0 ) {
            break;
        }
    }

    if ( !m_fbconfig ) {
        fprintf( stderr, "Couldn't find a matching FB config for a transparent OpenGL window!\n");
    }

    m_cmap = XCreateColormap( xengine->m_display, xengine->m_root, m_visual->visual, AllocNone );

    XSetWindowAttributes attributes;
    attributes.colormap = m_cmap;
    attributes.background_pixmap = None;
    attributes.border_pixmap = None;
    attributes.border_pixel = 0;
    // Disable window decorations.
    attributes.override_redirect = True;
    // Make sure we know when we've been successfully destroyed later!
    attributes.event_mask = StructureNotifyMask;
    unsigned long valueMask = CWOverrideRedirect | CWEventMask | CWBackPixmap | CWColormap | CWBorderPixel;


    // Create the window
    m_window = XCreateWindow( xengine->m_display, xengine->m_root, 0, 0, xengine->getWidth(), xengine->getHeight(),
                              0, m_visual->depth, InputOutput,
                              m_visual->visual, valueMask, &attributes );

    if ( !m_window ) {
        fprintf( stderr, "Couldn't create a GL window!\n");
    }

    m_glxWindow = m_window;

    static char title[] = "OpenGL Slop";
    XWMHints* startup_state = XAllocWMHints();
    startup_state->initial_state = NormalState;
    startup_state->flags = StateHint;
    XTextProperty textprop;
    textprop.value = (unsigned char*)title;
    textprop.encoding = XA_STRING;
    textprop.format = 8;
    textprop.nitems = strlen( title );
    XSizeHints sizehints;
    sizehints.x = 0;
    sizehints.y = 0;
    sizehints.width = xengine->getWidth();
    sizehints.height = xengine->getHeight();
    sizehints.flags = USPosition | USSize;
    XClassHint classhints;
    char name[] = "slop";
    classhints.res_name = name;
    classhints.res_class = name;
    XSetClassHint( xengine->m_display, m_window, &classhints );
    XSetWMProperties( xengine->m_display, m_window, &textprop, &textprop, NULL, 0, &sizehints, startup_state, NULL );
    XFree( startup_state );

    // Make it so all input falls through
    XRectangle rect;
    rect.x = rect.y = rect.width = rect.height = 0;
    XShapeCombineRectangles( xengine->m_display, m_window, ShapeInput, 0, 0, &rect, 1, ShapeSet, 0);

    XMapWindow( xengine->m_display, m_window );

    int dummy;
    if ( !glXQueryExtension( xengine->m_display, &dummy, &dummy ) ) {
        fprintf( stderr, "OpenGL is not supported!\n" );
    }
    m_renderContext = glXCreateNewContext( xengine->m_display, m_fbconfig, GLX_RGBA_TYPE, 0, True );
    if ( !m_renderContext ) {
        fprintf( stderr, "Failed to create a GL context.\n" );
    }
    if ( !glXMakeContextCurrent( xengine->m_display, m_glxWindow, m_glxWindow, m_renderContext ) ) {
        fprintf( stderr, "Failed to attach GL context to window!\n" );
    }
    GLenum err = glewInit();
    if ( GLEW_OK != err ) {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }

    // Get an image of the entire desktop for use in shaders.
    XImage* image = XGetImage( xengine->m_display, xengine->m_root, 0, 0, xengine->getWidth(), xengine->getHeight(), 0xffffffff, ZPixmap );
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &m_desktop);
    glBindTexture(GL_TEXTURE_2D, m_desktop);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, xengine->getWidth(), xengine->getHeight(), 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(image->data[0])));
    XDestroyImage( image );

    glDisable(GL_TEXTURE_2D);
    m_framebuffer = new slop::Framebuffer( xengine->getWidth(), xengine->getHeight(), slop::Framebuffer::color, m_shader );
    m_framebuffer->bind();
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glClearColor( 0, 0, 0, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glXSwapBuffers( xengine->m_display, m_glxWindow );
    m_framebuffer->unbind();
}
Example #29
0
BasicWin BWCreateNewWindow(Display *display, int argc, char **argv)
{
	BasicWin this_window;
	unsigned int newwin_width, newwin_height;	/* window size */
	int newwin_x, newwin_y;				/* window position */
	unsigned int newwin_border_width = 4;
	char *newwin_window_name = "Output";
	char *newwin_icon_name = "Output";
	Pixmap icon_pixmap;
	XSizeHints newwin_size_hints;
	XIconSize *size_list;
	int screen_num;
	XEvent win_report;
	Window win;
	XFontStruct *win_font_info;
	GC win_gc;
	char *progname;

	/* The name of the executable */
	progname=argv[0];
	
	/* get screen size from display structure macro */
	screen_num = DefaultScreen(display);

	/* At the moment, the position of the window is not
	settable from the command line */
	newwin_x = 255;
	newwin_y = 255;

	/* size window */
	newwin_width = 255, newwin_height = 255;

	/* create opaque window */
	win = XCreateSimpleWindow(display, RootWindow(display,screen_num), 
			newwin_x, newwin_y, newwin_width, newwin_height, newwin_border_width, 
			BlackPixel(display,screen_num), 
			WhitePixel(display,screen_num));

	/* Create bitmap for the icon */
	icon_pixmap = XCreateBitmapFromData(display, win, icon_bits, 
			icon_width, icon_height);

	/* Set size hints for window manager. */

#ifdef X11R3
	newwin_size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
	newwin_size_hints.x = newwin_x;
	newwin_size_hints.y = newwin_y;
	newwin_size_hints.width = newwin_width;
	newwin_size_hints.height = newwin_height;
	newwin_size_hints.min_width = 255;
	newwin_size_hints.min_height = 255;

#else /* X11R4 or later */

	newwin_size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
	newwin_size_hints.min_width = 255;
	newwin_size_hints.min_height = 255;
#endif

#ifdef X11R3
	/* set Properties for window manager (always before mapping) */
	XSetStandardProperties(display, win, window_name, newwin_icon_name, 
			icon_pixmap, argv, argc, &newwin_size_hints);

#else /* X11R4 or later */
	{
	XWMHints wm_hints;
	XClassHint class_hints;

	/* format of the window name and icon name 
	 * arguments has changed in R4 */
	XTextProperty windowName, iconName;

	/* These calls store window_name and icon_name into
	 * XTextProperty structures and set their other 
	 * fields properly. */
	if (XStringListToTextProperty(&newwin_window_name, 1, &windowName) == 0) {
		(void) fprintf( stderr, "%s: structure allocation for windowName failed.\n",progname);
		exit(-1);
	}
		
	if (XStringListToTextProperty(&newwin_icon_name, 1, &iconName) == 0) {
		(void) fprintf( stderr, "%s: structure allocation for iconName 
failed.\n",progname);
		exit(-1);
	}

	wm_hints.initial_state = NormalState;
	wm_hints.input = True;
	wm_hints.icon_pixmap = icon_pixmap;
	wm_hints.flags = StateHint | IconPixmapHint | InputHint;

	class_hints.res_name = "basicwin";
	class_hints.res_class = "Graphical";

	XSetWMProperties(display, win, &windowName, &iconName, 
			argv, argc, &newwin_size_hints, &wm_hints, 
			&class_hints);
	}
Example #30
0
File: x11.c Project: cbdevnet/xecho
bool x11_init(XRESOURCES* res, CFG* config){
	Window root;
	XSetWindowAttributes window_attributes;
	unsigned width, height;
	Atom wm_state_fullscreen;
	int xdbe_major, xdbe_minor;
	XTextProperty window_name;
	pid_t pid = getpid();

	//allocate some structures
	XSizeHints* size_hints = XAllocSizeHints();
	XWMHints* wm_hints = XAllocWMHints();
	XClassHint* class_hints = XAllocClassHint();

	if(!size_hints || !wm_hints || !class_hints){
		fprintf(stderr, "Failed to allocate X data structures\n");
		return false;
	}

	//x data initialization
	res->display = XOpenDisplay(NULL);

	if(!(res->display)){
		fprintf(stderr, "Failed to open display\n");
		XFree(size_hints);
		XFree(wm_hints);
		XFree(class_hints);
		return false;
	}

	if(config->double_buffer){
		config->double_buffer = (XdbeQueryExtension(res->display, &xdbe_major, &xdbe_minor) != 0);
	}
	else{
		config->double_buffer = false;
	}
	errlog(config, LOG_INFO, "Double buffering %s\n", config->double_buffer ? "enabled":"disabled");

	res->screen = DefaultScreen(res->display);
	root = RootWindow(res->display, res->screen);

	//start xft
	if(!XftInit(NULL)){
		fprintf(stderr, "Failed to initialize Xft\n");
		XFree(size_hints);
		XFree(wm_hints);
		XFree(class_hints);
		return false;
	}

	//set up colors
	res->text_color = colorspec_parse(config->text_color, res->display, res->screen);
	res->bg_color = colorspec_parse(config->bg_color, res->display, res->screen);
	res->debug_color = colorspec_parse(config->debug_color, res->display, res->screen);

	//set up window params
	window_attributes.background_pixel = res->bg_color.pixel;
	window_attributes.cursor = None;
	window_attributes.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask;
	width = DisplayWidth(res->display, res->screen);
	height = DisplayHeight(res->display, res->screen);

	//create window
	res->main = XCreateWindow(res->display,
				root,
				0,
				0,
				width,
				height,
				0,
				CopyFromParent,
				InputOutput,
				CopyFromParent,
				CWBackPixel | CWCursor | CWEventMask,
				&window_attributes);

	//set window properties
	if(XStringListToTextProperty(&(config->window_name), 1, &window_name) == 0){
		fprintf(stderr, "Failed to create string list, aborting\n");
		return false;
	}

	wm_hints->flags = 0;
	class_hints->res_name = "xecho";
	class_hints->res_class = "xecho";

	XSetWMProperties(res->display, res->main, &window_name, NULL, NULL, 0, NULL, wm_hints, class_hints);

	XFree(window_name.value);
	XFree(size_hints);
	XFree(wm_hints);
	XFree(class_hints);

	//set fullscreen mode
	if(!config->windowed){
		wm_state_fullscreen = XInternAtom(res->display, "_NET_WM_STATE_FULLSCREEN", False);
		XChangeProperty(res->display, res->main, XInternAtom(res->display, "_NET_WM_STATE", False), XA_ATOM, 32, PropModeReplace, (unsigned char*) &wm_state_fullscreen, 1);
	}

	XChangeProperty(res->display, res->main, XInternAtom(res->display, "_NET_WM_PID", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&pid, 1);

	//allocate back drawing buffer
	if(config->double_buffer){
		res->back_buffer = XdbeAllocateBackBufferName(res->display, res->main, XdbeBackground);
	}

	//make xft drawable from window
	res->drawable = XftDrawCreate(res->display, (config->double_buffer?res->back_buffer:res->main), DefaultVisual(res->display, res->screen), DefaultColormap(res->display, res->screen));

	if(!res->drawable){
		fprintf(stderr, "Failed to allocate drawable\n");
		return false;
	}

	//register for WM_DELETE_WINDOW messages
	res->wm_delete = XInternAtom(res->display, "WM_DELETE_WINDOW", False);
	XSetWMProtocols(res->display, res->main, &(res->wm_delete), 1);

	//map window
	XMapRaised(res->display, res->main);

	//get x socket fds
	if(!xfd_add(&(res->xfds), XConnectionNumber(res->display))){
		fprintf(stderr, "Failed to allocate xfd memory\n");
		return false;
	}
	if(XAddConnectionWatch(res->display, xconn_watch, (void*)(&(res->xfds))) == 0){
		fprintf(stderr, "Failed to register connection watch procedure\n");
		return false;
	}

	return true;
}