4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
9 #include <libtu/objp.h>
10 #include <libtu/minmax.h>
20 #include "region-iter.h"
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
)
41 CALL_DYN_RET(area
, int, window_press
, wwin
, (wwin
, ev
, reg_ret
));
46 void window_release(WWindow
*wwin
)
48 CALL_DYN(window_release
, wwin
, (wwin
));
58 bool window_do_init(WWindow
*wwin
, WWindow
*par
,
59 const WFitParams
*fp
, Window win
, const char *name
)
63 win
=create_xwindow(region_rootwin_of((WRegion
*)par
),
64 par
->win
, &(fp
->g
), name
);
74 region_init(&(wwin
->region
), par
, fp
);
76 XSaveContext(ioncore_g
.dpy
, win
, ioncore_g
.win_context
,
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
);
96 XDestroyIC(wwin
->xic
);
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.
113 /*{{{ Region dynfuns */
116 static void window_notify_subs_rootpos(WWindow
*wwin
, int x
, int y
)
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
)
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
);
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
);
149 XMoveResizeWindow(ioncore_g
.dpy
, wwin
->win
, geom
->x
, geom
->y
, w
, h
);
152 REGION_GEOM(wwin
)=*geom
;
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
))
163 window_do_fitrep(wwin
, par
, &(fp
->g
));
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
)
209 * Return the X window id for \var{wwin}.
213 double window_xid(WWindow
*wwin
)
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
;
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
},
245 IMPLCLASS(WWindow
, WRegion
, window_deinit
, window_dynfuntab
);