]> git.decadent.org.uk Git - ion3.git/blob - ioncore/xwindow.c
9d4cea79e1ceec6ce446abc77350088acd96b079
[ion3.git] / ioncore / xwindow.c
1 /*
2  * ion/ioncore/xwindow.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <string.h>
13
14 #include <libtu/minmax.h>
15 #include "common.h"
16 #include "global.h"
17 #include "xwindow.h"
18 #include "cursor.h"
19 #include "sizehint.h"
20
21
22 /*{{{ X window->region mapping */
23
24
25 WRegion *xwindow_region_of(Window win)
26 {
27     WRegion *reg;
28     
29     if(XFindContext(ioncore_g.dpy, win, ioncore_g.win_context,
30                     (XPointer*)&reg)!=0)
31         return NULL;
32     
33     return reg;
34 }
35
36
37 WRegion *xwindow_region_of_t(Window win, const ClassDescr *descr)
38 {
39     WRegion *reg=xwindow_region_of(win);
40     
41     if(reg==NULL)
42         return NULL;
43     
44     if(!obj_is((Obj*)reg, descr))
45         return NULL;
46     
47     return reg;
48 }
49
50
51 /*}}}*/
52
53
54 /*{{{ Create */
55
56
57 Window create_xwindow(WRootWin *rw, Window par, const WRectangle *geom)
58 {
59     int w=maxof(1, geom->w);
60     int h=maxof(1, geom->h);
61     
62     return XCreateSimpleWindow(ioncore_g.dpy, par, geom->x, geom->y, w, h,
63                                0, 0, BlackPixel(ioncore_g.dpy, rw->xscr));
64 }
65
66
67 /*}}}*/
68
69
70 /*{{{ Restack */
71
72
73 void xwindow_restack(Window win, Window other, int stack_mode)
74 {
75     XWindowChanges wc;
76     int wcmask;
77     
78     wcmask=CWStackMode;
79     wc.stack_mode=stack_mode;
80     if(other!=None){
81         wc.sibling=other;
82         wcmask|=CWSibling;
83     }
84
85     XConfigureWindow(ioncore_g.dpy, win, wcmask, &wc);
86 }
87
88
89 /*}}}*/
90
91
92 /*{{{ Focus */
93
94
95 void xwindow_do_set_focus(Window win)
96 {
97     XSetInputFocus(ioncore_g.dpy, win, RevertToParent, CurrentTime);
98 }
99
100
101 /*}}}*/
102
103
104 /*{{{ Pointer and cursors */
105
106 void xwindow_set_cursor(Window win, int cursor)
107 {
108     XDefineCursor(ioncore_g.dpy, win, ioncore_xcursor(cursor));
109 }
110
111
112 bool xwindow_pointer_pos(Window rel, int *px, int *py)
113 {
114     Window win=None, realroot=None;
115     int rx=0, ry=0;
116     uint mask=0;
117     return XQueryPointer(ioncore_g.dpy, rel, &realroot, &win,
118                          &rx, &ry, px, py, &mask);
119 }
120
121 /*}}}*/
122
123
124 /*{{{ Size hints */
125
126
127 void xwindow_get_sizehints(Window win, XSizeHints *hints)
128 {
129     int minh, minw;
130     long supplied=0;
131     
132     memset(hints, 0, sizeof(*hints));
133     XGetWMNormalHints(ioncore_g.dpy, win, hints, &supplied);
134     
135     xsizehints_sanity_adjust(hints);
136 }
137
138
139 /*}}}*/
140