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>
21 #include "region-iter.h"
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
)
42 CALL_DYN_RET(area
, int, window_press
, wwin
, (wwin
, ev
, reg_ret
));
47 void window_release(WWindow
*wwin
)
49 CALL_DYN(window_release
, wwin
, (wwin
));
59 bool window_do_init(WWindow
*wwin
, WWindow
*par
, Window win
,
64 region_init(&(wwin
->region
), par
, fp
);
66 XSaveContext(ioncore_g
.dpy
, win
, ioncore_g
.win_context
,
74 bool window_init(WWindow
*wwin
, WWindow
*par
, const WFitParams
*fp
)
78 win
=create_xwindow(region_rootwin_of((WRegion
*)par
),
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
);
92 XDestroyIC(wwin
->xic
);
95 XDeleteContext(ioncore_g
.dpy
, wwin
->win
, ioncore_g
.win_context
);
96 XDestroyWindow(ioncore_g
.dpy
, wwin
->win
);
104 /*{{{ Region dynfuns */
107 static void window_notify_subs_rootpos(WWindow
*wwin
, int x
, int y
)
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
)
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
);
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
);
140 XMoveResizeWindow(ioncore_g
.dpy
, wwin
->win
, geom
->x
, geom
->y
, w
, h
);
143 REGION_GEOM(wwin
)=*geom
;
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
))
154 window_do_fitrep(wwin
, par
, &(fp
->g
));
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
)
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
)
196 * Return the X window id for \var{wwin}.
199 double window_xid(WWindow
*wwin
)
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
},
223 IMPLCLASS(WWindow
, WRegion
, window_deinit
, window_dynfuntab
);