Update contrib
[notion/jeffpc.git] / ioncore / xwindow.c
blob821a9eb475916671cb49c9092553a04d3a1a8c4a
1 /*
2 * ion/ioncore/xwindow.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <string.h>
11 #include <libtu/minmax.h>
13 #include <ioncore/property.h>
15 #include "common.h"
16 #include "global.h"
17 #include "xwindow.h"
18 #include "cursor.h"
19 #include "sizehint.h"
22 /*{{{ X window->region mapping */
25 WRegion *xwindow_region_of(Window win)
27 WRegion *reg;
29 if(XFindContext(ioncore_g.dpy, win, ioncore_g.win_context,
30 (XPointer*)&reg)!=0)
31 return NULL;
33 return reg;
37 WRegion *xwindow_region_of_t(Window win, const ClassDescr *descr)
39 WRegion *reg=xwindow_region_of(win);
41 if(reg==NULL)
42 return NULL;
44 if(!obj_is((Obj*)reg, descr))
45 return NULL;
47 return reg;
51 /*}}}*/
54 /*{{{ Create */
57 Window create_xwindow(WRootWin *rw, Window par, const WRectangle *geom, const char *name)
59 int w=maxof(1, geom->w);
60 int h=maxof(1, geom->h);
61 const char *p[1];
62 Window window;
64 window = XCreateSimpleWindow(ioncore_g.dpy, par, geom->x, geom->y, w, h,
65 0, 0, BlackPixel(ioncore_g.dpy, rw->xscr));
66 p[0] = name;
67 xwindow_set_text_property(window, XA_WM_NAME, p, 1);
69 return window;
73 /*}}}*/
76 /*{{{ Restack */
79 void xwindow_restack(Window win, Window other, int stack_mode)
81 XWindowChanges wc;
82 int wcmask;
84 wcmask=CWStackMode;
85 wc.stack_mode=stack_mode;
86 if(other!=None){
87 wc.sibling=other;
88 wcmask|=CWSibling;
91 XConfigureWindow(ioncore_g.dpy, win, wcmask, &wc);
95 /*}}}*/
98 /*{{{ Focus */
101 void xwindow_do_set_focus(Window win)
103 XSetInputFocus(ioncore_g.dpy, win, RevertToParent, CurrentTime);
107 /*}}}*/
110 /*{{{ Pointer and cursors */
112 void xwindow_set_cursor(Window win, int cursor)
114 XDefineCursor(ioncore_g.dpy, win, ioncore_xcursor(cursor));
118 bool xwindow_pointer_pos(Window rel, int *px, int *py)
120 Window win=None, realroot=None;
121 int rx=0, ry=0;
122 uint mask=0;
123 return XQueryPointer(ioncore_g.dpy, rel, &realroot, &win,
124 &rx, &ry, px, py, &mask);
127 /*}}}*/
130 /*{{{ Size hints */
133 void xwindow_get_sizehints(Window win, XSizeHints *hints)
135 int minh, minw;
136 long supplied=0;
138 memset(hints, 0, sizeof(*hints));
139 XGetWMNormalHints(ioncore_g.dpy, win, hints, &supplied);
141 xsizehints_sanity_adjust(hints);
145 /*}}}*/