4 * Copyright (c) Tuomo Valkonen 1999-2007.
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.
12 #include <libtu/objp.h>
13 #include <libtu/minmax.h>
22 #include "region-iter.h"
28 void window_draw(WWindow *wwin, bool complete)
30 CALL_DYN(window_draw, wwin, (wwin, complete));
34 void window_insstr(WWindow *wwin, const char *buf, size_t n)
36 CALL_DYN(window_insstr, wwin, (wwin, buf, n));
40 int window_press(WWindow *wwin, XButtonEvent *ev, WRegion **reg_ret)
43 CALL_DYN_RET(area, int, window_press, wwin, (wwin, ev, reg_ret));
48 void window_release(WWindow *wwin)
50 CALL_DYN(window_release, wwin, (wwin));
60 bool window_do_init(WWindow *wwin, WWindow *par,
61 const WFitParams *fp, Window win)
65 win=create_xwindow(region_rootwin_of((WRegion*)par),
76 region_init(&(wwin->region), par, fp);
78 XSaveContext(ioncore_g.dpy, win, ioncore_g.win_context,
85 bool window_init(WWindow *wwin, WWindow *par, const WFitParams *fp)
87 return window_do_init(wwin, par, fp, None);
91 void window_deinit(WWindow *wwin)
93 region_deinit((WRegion*)wwin);
95 region_pointer_focus_hack(&wwin->region);
98 XDestroyIC(wwin->xic);
101 XDeleteContext(ioncore_g.dpy, wwin->win, ioncore_g.win_context);
102 /* Probably should not try destroy if root window... */
103 XDestroyWindow(ioncore_g.dpy, wwin->win);
106 /* There are no backlinks from WStacking to us, so it is not
107 * necessary to do any deinitialisation there.
115 /*{{{ Region dynfuns */
118 static void window_notify_subs_rootpos(WWindow *wwin, int x, int y)
122 FOR_ALL_CHILDREN(wwin, sub){
123 region_notify_rootpos(sub,
124 x+REGION_GEOM(sub).x,
125 y+REGION_GEOM(sub).y);
130 void window_notify_subs_move(WWindow *wwin)
133 region_rootpos(&(wwin->region), &x, &y);
134 window_notify_subs_rootpos(wwin, x, y);
138 void window_do_fitrep(WWindow *wwin, WWindow *par, const WRectangle *geom)
140 bool move=(REGION_GEOM(wwin).x!=geom->x ||
141 REGION_GEOM(wwin).y!=geom->y);
142 int w=maxof(1, geom->w);
143 int h=maxof(1, geom->h);
146 region_unset_parent((WRegion*)wwin);
147 XReparentWindow(ioncore_g.dpy, wwin->win, par->win, geom->x, geom->y);
148 XResizeWindow(ioncore_g.dpy, wwin->win, w, h);
149 region_set_parent((WRegion*)wwin, par);
151 XMoveResizeWindow(ioncore_g.dpy, wwin->win, geom->x, geom->y, w, h);
154 REGION_GEOM(wwin)=*geom;
157 window_notify_subs_move(wwin);
161 bool window_fitrep(WWindow *wwin, WWindow *par, const WFitParams *fp)
163 if(par!=NULL && !region_same_rootwin((WRegion*)wwin, (WRegion*)par))
165 window_do_fitrep(wwin, par, &(fp->g));
170 void window_map(WWindow *wwin)
172 XMapWindow(ioncore_g.dpy, wwin->win);
173 REGION_MARK_MAPPED(wwin);
177 void window_unmap(WWindow *wwin)
179 region_pointer_focus_hack(&wwin->region);
181 XUnmapWindow(ioncore_g.dpy, wwin->win);
182 REGION_MARK_UNMAPPED(wwin);
186 void window_do_set_focus(WWindow *wwin, bool warp)
188 region_finalise_focusing((WRegion*)wwin, wwin->win, warp);
192 void window_restack(WWindow *wwin, Window other, int mode)
194 xwindow_restack(wwin->win, other, mode);
198 Window window_xwindow(const WWindow *wwin)
211 * Return the X window id for \var{wwin}.
215 double window_xid(WWindow *wwin)
221 void window_select_input(WWindow *wwin, long event_mask)
223 XSelectInput(ioncore_g.dpy, wwin->win, event_mask);
224 wwin->event_mask=event_mask;
231 /*{{{ Dynamic function table and class implementation */
234 static DynFunTab window_dynfuntab[]={
235 {region_map, window_map},
236 {region_unmap, window_unmap},
237 {region_do_set_focus, window_do_set_focus},
238 {(DynFun*)region_fitrep, (DynFun*)window_fitrep},
239 {(DynFun*)region_xwindow, (DynFun*)window_xwindow},
240 {region_notify_rootpos, window_notify_subs_rootpos},
241 {region_restack, window_restack},
247 IMPLCLASS(WWindow, WRegion, window_deinit, window_dynfuntab);