trunk: changeset 1925
[notion/jeffpc.git] / ioncore / window.c
blob2a969d3033565257b1f9f63ebc3165e2520e46cd
1 /*
2 * ion/ioncore/window.c
4 * Copyright (c) Tuomo Valkonen 1999-2005.
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>
14 #include "common.h"
15 #include "global.h"
16 #include "window.h"
17 #include "focus.h"
18 #include "rootwin.h"
19 #include "region.h"
20 #include "xwindow.h"
21 #include "region-iter.h"
24 /*{{{ Dynfuns */
27 void window_draw(WWindow *wwin, bool complete)
29 CALL_DYN(window_draw, wwin, (wwin, complete));
33 void window_insstr(WWindow *wwin, const char *buf, size_t n)
35 CALL_DYN(window_insstr, wwin, (wwin, buf, n));
39 int window_press(WWindow *wwin, XButtonEvent *ev, WRegion **reg_ret)
41 int area=0;
42 CALL_DYN_RET(area, int, window_press, wwin, (wwin, ev, reg_ret));
43 return area;
47 void window_release(WWindow *wwin)
49 CALL_DYN(window_release, wwin, (wwin));
53 /*}}}*/
56 /*{{{ Init, create */
59 bool window_do_init(WWindow *wwin, WWindow *par, Window win,
60 const WFitParams *fp)
62 wwin->win=win;
63 wwin->xic=NULL;
64 region_init(&(wwin->region), par, fp);
65 if(win!=None){
66 XSaveContext(ioncore_g.dpy, win, ioncore_g.win_context,
67 (XPointer)wwin);
70 return TRUE;
74 bool window_init(WWindow *wwin, WWindow *par, const WFitParams *fp)
76 Window win;
78 win=create_xwindow(region_rootwin_of((WRegion*)par),
79 par->win, &(fp->g));
80 if(win==None)
81 return FALSE;
82 /* window_init does not fail */
83 return window_do_init(wwin, par, win, fp);
87 void window_deinit(WWindow *wwin)
89 region_deinit((WRegion*)wwin);
91 if(wwin->xic!=NULL)
92 XDestroyIC(wwin->xic);
94 if(wwin->win!=None){
95 XDeleteContext(ioncore_g.dpy, wwin->win, ioncore_g.win_context);
96 XDestroyWindow(ioncore_g.dpy, wwin->win);
101 /*}}}*/
104 /*{{{ Region dynfuns */
107 static void window_notify_subs_rootpos(WWindow *wwin, int x, int y)
109 WRegion *sub;
111 FOR_ALL_CHILDREN(wwin, sub){
112 region_notify_rootpos(sub,
113 x+REGION_GEOM(sub).x,
114 y+REGION_GEOM(sub).y);
119 void window_notify_subs_move(WWindow *wwin)
121 int x=0, y=0;
122 region_rootpos(&(wwin->region), &x, &y);
123 window_notify_subs_rootpos(wwin, x, y);
127 void window_do_fitrep(WWindow *wwin, WWindow *par, const WRectangle *geom)
129 bool move=(REGION_GEOM(wwin).x!=geom->x ||
130 REGION_GEOM(wwin).y!=geom->y);
131 int w=maxof(1, geom->w);
132 int h=maxof(1, geom->h);
134 if(par!=NULL){
135 region_unset_parent((WRegion*)wwin);
136 XReparentWindow(ioncore_g.dpy, wwin->win, par->win, geom->x, geom->y);
137 XResizeWindow(ioncore_g.dpy, wwin->win, w, h);
138 region_set_parent((WRegion*)wwin, par);
139 }else{
140 XMoveResizeWindow(ioncore_g.dpy, wwin->win, geom->x, geom->y, w, h);
143 REGION_GEOM(wwin)=*geom;
145 if(move)
146 window_notify_subs_move(wwin);
150 bool window_fitrep(WWindow *wwin, WWindow *par, const WFitParams *fp)
152 if(par!=NULL && !region_same_rootwin((WRegion*)wwin, (WRegion*)par))
153 return FALSE;
154 window_do_fitrep(wwin, par, &(fp->g));
155 return TRUE;
159 void window_map(WWindow *wwin)
161 XMapWindow(ioncore_g.dpy, wwin->win);
162 REGION_MARK_MAPPED(wwin);
166 void window_unmap(WWindow *wwin)
168 XUnmapWindow(ioncore_g.dpy, wwin->win);
169 REGION_MARK_UNMAPPED(wwin);
173 void window_do_set_focus(WWindow *wwin, bool warp)
175 if(warp)
176 region_do_warp((WRegion*)wwin);
178 region_set_await_focus((WRegion*)wwin);
179 xwindow_do_set_focus(wwin->win);
183 void window_restack(WWindow *wwin, Window other, int mode)
185 xwindow_restack(wwin->win, other, mode);
189 Window window_xwindow(const WWindow *wwin)
191 return wwin->win;
195 /*EXTL_DOC
196 * Return the X window id for \var{wwin}.
198 EXTL_EXPORT_MEMBER
199 double window_xid(WWindow *wwin)
201 return wwin->win;
205 /*}}}*/
208 /*{{{ Dynamic function table and class implementation */
211 static DynFunTab window_dynfuntab[]={
212 {region_map, window_map},
213 {region_unmap, window_unmap},
214 {region_do_set_focus, window_do_set_focus},
215 {(DynFun*)region_fitrep, (DynFun*)window_fitrep},
216 {(DynFun*)region_xwindow, (DynFun*)window_xwindow},
217 {region_notify_rootpos, window_notify_subs_rootpos},
218 {region_restack, window_restack},
219 END_DYNFUNTAB
223 IMPLCLASS(WWindow, WRegion, window_deinit, window_dynfuntab);
226 /*}}}*/