4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
9 #include <libtu/objp.h>
10 #include <libtu/minmax.h>
19 #include "region-iter.h"
25 void window_draw(WWindow *wwin, bool complete)
27 CALL_DYN(window_draw, wwin, (wwin, complete));
31 void window_insstr(WWindow *wwin, const char *buf, size_t n)
33 CALL_DYN(window_insstr, wwin, (wwin, buf, n));
37 int window_press(WWindow *wwin, XButtonEvent *ev, WRegion **reg_ret)
40 CALL_DYN_RET(area, int, window_press, wwin, (wwin, ev, reg_ret));
45 void window_release(WWindow *wwin)
47 CALL_DYN(window_release, wwin, (wwin));
57 bool window_do_init(WWindow *wwin, WWindow *par,
58 const WFitParams *fp, Window win)
62 win=create_xwindow(region_rootwin_of((WRegion*)par),
73 region_init(&(wwin->region), par, fp);
75 XSaveContext(ioncore_g.dpy, win, ioncore_g.win_context,
82 bool window_init(WWindow *wwin, WWindow *par, const WFitParams *fp)
84 return window_do_init(wwin, par, fp, None);
88 void window_deinit(WWindow *wwin)
90 region_deinit((WRegion*)wwin);
92 region_pointer_focus_hack(&wwin->region);
95 XDestroyIC(wwin->xic);
98 XDeleteContext(ioncore_g.dpy, wwin->win, ioncore_g.win_context);
99 /* Probably should not try destroy if root window... */
100 XDestroyWindow(ioncore_g.dpy, wwin->win);
103 /* There are no backlinks from WStacking to us, so it is not
104 * necessary to do any deinitialisation there.
112 /*{{{ Region dynfuns */
115 static void window_notify_subs_rootpos(WWindow *wwin, int x, int y)
119 FOR_ALL_CHILDREN(wwin, sub){
120 region_notify_rootpos(sub,
121 x+REGION_GEOM(sub).x,
122 y+REGION_GEOM(sub).y);
127 void window_notify_subs_move(WWindow *wwin)
130 region_rootpos(&(wwin->region), &x, &y);
131 window_notify_subs_rootpos(wwin, x, y);
135 void window_do_fitrep(WWindow *wwin, WWindow *par, const WRectangle *geom)
137 bool move=(REGION_GEOM(wwin).x!=geom->x ||
138 REGION_GEOM(wwin).y!=geom->y);
139 int w=maxof(1, geom->w);
140 int h=maxof(1, geom->h);
143 region_unset_parent((WRegion*)wwin);
144 XReparentWindow(ioncore_g.dpy, wwin->win, par->win, geom->x, geom->y);
145 XResizeWindow(ioncore_g.dpy, wwin->win, w, h);
146 region_set_parent((WRegion*)wwin, par);
148 XMoveResizeWindow(ioncore_g.dpy, wwin->win, geom->x, geom->y, w, h);
151 REGION_GEOM(wwin)=*geom;
154 window_notify_subs_move(wwin);
158 bool window_fitrep(WWindow *wwin, WWindow *par, const WFitParams *fp)
160 if(par!=NULL && !region_same_rootwin((WRegion*)wwin, (WRegion*)par))
162 window_do_fitrep(wwin, par, &(fp->g));
167 void window_map(WWindow *wwin)
169 XMapWindow(ioncore_g.dpy, wwin->win);
170 REGION_MARK_MAPPED(wwin);
174 void window_unmap(WWindow *wwin)
176 region_pointer_focus_hack(&wwin->region);
178 XUnmapWindow(ioncore_g.dpy, wwin->win);
179 REGION_MARK_UNMAPPED(wwin);
183 void window_do_set_focus(WWindow *wwin, bool warp)
185 region_finalise_focusing((WRegion*)wwin, wwin->win, warp);
189 void window_restack(WWindow *wwin, Window other, int mode)
191 xwindow_restack(wwin->win, other, mode);
195 Window window_xwindow(const WWindow *wwin)
208 * Return the X window id for \var{wwin}.
212 double window_xid(WWindow *wwin)
218 void window_select_input(WWindow *wwin, long event_mask)
220 XSelectInput(ioncore_g.dpy, wwin->win, event_mask);
221 wwin->event_mask=event_mask;
228 /*{{{ Dynamic function table and class implementation */
231 static DynFunTab window_dynfuntab[]={
232 {region_map, window_map},
233 {region_unmap, window_unmap},
234 {region_do_set_focus, window_do_set_focus},
235 {(DynFun*)region_fitrep, (DynFun*)window_fitrep},
236 {(DynFun*)region_xwindow, (DynFun*)window_xwindow},
237 {region_notify_rootpos, window_notify_subs_rootpos},
238 {region_restack, window_restack},
244 IMPLCLASS(WWindow, WRegion, window_deinit, window_dynfuntab);