No longer trap fatal signals
[notion/jeffpc.git] / ioncore / window.c
blob0bf53aec90bbc4d3a819e296d4269880b3291a7e
1 /*
2 * ion/ioncore/window.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <libtu/objp.h>
10 #include <libtu/minmax.h>
12 #include "names.h"
13 #include "common.h"
14 #include "global.h"
15 #include "window.h"
16 #include "focus.h"
17 #include "rootwin.h"
18 #include "region.h"
19 #include "xwindow.h"
20 #include "region-iter.h"
23 /*{{{ Dynfuns */
26 void window_draw(WWindow *wwin, bool complete)
28 CALL_DYN(window_draw, wwin, (wwin, complete));
32 void window_insstr(WWindow *wwin, const char *buf, size_t n)
34 CALL_DYN(window_insstr, wwin, (wwin, buf, n));
38 int window_press(WWindow *wwin, XButtonEvent *ev, WRegion **reg_ret)
40 int area=0;
41 CALL_DYN_RET(area, int, window_press, wwin, (wwin, ev, reg_ret));
42 return area;
46 void window_release(WWindow *wwin)
48 CALL_DYN(window_release, wwin, (wwin));
52 /*}}}*/
55 /*{{{ Init, create */
58 bool window_do_init(WWindow *wwin, WWindow *par,
59 const WFitParams *fp, Window win, const char *name)
61 if(win==None){
62 assert(par!=NULL);
63 win=create_xwindow(region_rootwin_of((WRegion*)par),
64 par->win, &(fp->g), name);
65 if(win==None)
66 return FALSE;
69 wwin->win=win;
70 wwin->xic=NULL;
71 wwin->event_mask=0;
72 wwin->stacking=NULL;
74 region_init(&(wwin->region), par, fp);
76 XSaveContext(ioncore_g.dpy, win, ioncore_g.win_context,
77 (XPointer)wwin);
79 return TRUE;
83 bool window_init(WWindow *wwin, WWindow *par, const WFitParams *fp, const char *name)
85 return window_do_init(wwin, par, fp, None, name);
89 void window_deinit(WWindow *wwin)
91 region_deinit((WRegion*)wwin);
93 region_pointer_focus_hack(&wwin->region);
95 if(wwin->xic!=NULL)
96 XDestroyIC(wwin->xic);
98 if(wwin->win!=None){
99 XDeleteContext(ioncore_g.dpy, wwin->win, ioncore_g.win_context);
100 /* Probably should not try destroy if root window... */
101 XDestroyWindow(ioncore_g.dpy, wwin->win);
104 /* There are no backlinks from WStacking to us, so it is not
105 * necessary to do any deinitialisation there.
110 /*}}}*/
113 /*{{{ Region dynfuns */
116 static void window_notify_subs_rootpos(WWindow *wwin, int x, int y)
118 WRegion *sub;
120 FOR_ALL_CHILDREN(wwin, sub){
121 region_notify_rootpos(sub,
122 x+REGION_GEOM(sub).x,
123 y+REGION_GEOM(sub).y);
128 void window_notify_subs_move(WWindow *wwin)
130 int x=0, y=0;
131 region_rootpos(&(wwin->region), &x, &y);
132 window_notify_subs_rootpos(wwin, x, y);
136 void window_do_fitrep(WWindow *wwin, WWindow *par, const WRectangle *geom)
138 bool move=(REGION_GEOM(wwin).x!=geom->x ||
139 REGION_GEOM(wwin).y!=geom->y);
140 int w=maxof(1, geom->w);
141 int h=maxof(1, geom->h);
143 if(par!=NULL){
144 region_unset_parent((WRegion*)wwin);
145 XReparentWindow(ioncore_g.dpy, wwin->win, par->win, geom->x, geom->y);
146 XResizeWindow(ioncore_g.dpy, wwin->win, w, h);
147 region_set_parent((WRegion*)wwin, par);
148 }else{
149 XMoveResizeWindow(ioncore_g.dpy, wwin->win, geom->x, geom->y, w, h);
152 REGION_GEOM(wwin)=*geom;
154 if(move)
155 window_notify_subs_move(wwin);
159 bool window_fitrep(WWindow *wwin, WWindow *par, const WFitParams *fp)
161 if(par!=NULL && !region_same_rootwin((WRegion*)wwin, (WRegion*)par))
162 return FALSE;
163 window_do_fitrep(wwin, par, &(fp->g));
164 return TRUE;
168 void window_map(WWindow *wwin)
170 XMapWindow(ioncore_g.dpy, wwin->win);
171 REGION_MARK_MAPPED(wwin);
175 void window_unmap(WWindow *wwin)
177 region_pointer_focus_hack(&wwin->region);
179 XUnmapWindow(ioncore_g.dpy, wwin->win);
180 REGION_MARK_UNMAPPED(wwin);
184 void window_do_set_focus(WWindow *wwin, bool warp)
186 region_finalise_focusing((WRegion*)wwin, wwin->win, warp, CurrentTime, TRUE);
190 void window_restack(WWindow *wwin, Window other, int mode)
192 xwindow_restack(wwin->win, other, mode);
196 Window window_xwindow(const WWindow *wwin)
198 return wwin->win;
202 /*}}}*/
205 /*{{{ Misc. */
208 /*EXTL_DOC
209 * Return the X window id for \var{wwin}.
211 EXTL_SAFE
212 EXTL_EXPORT_MEMBER
213 double window_xid(WWindow *wwin)
215 return wwin->win;
219 void window_select_input(WWindow *wwin, long event_mask)
221 XSelectInput(ioncore_g.dpy, wwin->win, event_mask);
222 wwin->event_mask=event_mask;
226 /*}}}*/
229 /*{{{ Dynamic function table and class implementation */
232 static DynFunTab window_dynfuntab[]={
233 {region_map, window_map},
234 {region_unmap, window_unmap},
235 {region_do_set_focus, window_do_set_focus},
236 {(DynFun*)region_fitrep, (DynFun*)window_fitrep},
237 {(DynFun*)region_xwindow, (DynFun*)window_xwindow},
238 {region_notify_rootpos, window_notify_subs_rootpos},
239 {region_restack, window_restack},
240 END_DYNFUNTAB
244 EXTL_EXPORT
245 IMPLCLASS(WWindow, WRegion, window_deinit, window_dynfuntab);
248 /*}}}*/