Renamed package to ion1, and made it conflict with package 'ion'.
[ion1.git] / src / window.c
blobf80cb2db475f10916a1337aef9bfb402a7db5421
1 /*
2 * ion/window.c
4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
6 */
8 #include "common.h"
9 #include "global.h"
10 #include "window.h"
11 #include "focus.h"
12 #include "thingp.h"
15 static WThingFuntab window_funtab={
16 deinit_window,
17 NULL
20 IMPLOBJ(WWindow, WThing, &window_funtab)
23 /*{{{ Init, create */
26 bool init_window(WWindow *p, Window win, WRectangle geom)
28 p->flags=0;
29 p->win=win;
30 p->geom=geom;
31 p->xic=NULL;
32 p->split=NULL;
33 p->bindmap=NULL;
35 XSaveContext(wglobal.dpy, win, wglobal.win_context, (XPointer)p);
37 return TRUE;
41 void deinit_window(WWindow *wwin)
43 if(wwin->xic!=NULL)
44 XDestroyIC(wwin->xic);
46 if(wglobal.current_wswindow==wwin)
47 wglobal.current_wswindow=NULL;
49 XDeleteContext(wglobal.dpy, wwin->win, wglobal.win_context);
50 XDestroyWindow(wglobal.dpy, wwin->win);
54 /*}}}*/
57 /*{{{ Find, X Window -> thing */
60 WThing *find_window(Window win)
62 WThing *thing;
64 if(XFindContext(wglobal.dpy, win, wglobal.win_context,
65 (XPointer*)&thing)!=0)
66 return NULL;
68 return thing;
72 WThing *find_window_t(Window win, const WObjDescr *descr)
74 WThing *thing=find_window(win);
76 if(thing==NULL)
77 return NULL;
79 if(!wobj_is((WObj*)thing, descr))
80 return NULL;
82 return thing;
86 WFrame *find_frame_of(Window win)
88 WWindow *window=find_window_of(win);
90 if(window==NULL || !WTHING_IS(window, WFrame))
91 return NULL;
93 return (WFrame*)window;
97 WWindow *find_window_of(Window win)
99 WThing *thing=FIND_WINDOW_T(win, WThing);
101 if(thing==NULL)
102 return NULL;
104 return window_of(thing);
108 WWindow *window_of(WThing *thing)
110 while(1){
111 if(thing->t_parent==NULL)
112 return NULL;
114 if(WTHING_IS(thing->t_parent, WWorkspace))
115 break;
117 thing=thing->t_parent;
120 if(WTHING_IS(thing, WWindow))
121 return (WWindow*)thing;
123 return NULL;
127 /*}}}*/
130 /*{{{ Mapping */
133 void do_map_window(WWindow *wwin)
135 XMapWindow(wglobal.dpy, wwin->win);
137 wwin->flags|=WWINDOW_MAPPED;
141 void do_unmap_window(WWindow *wwin)
143 WFrame *frame;
145 if(!(wwin->flags&WWINDOW_MAPPED))
146 return;
148 XUnmapWindow(wglobal.dpy, wwin->win);
150 wwin->flags&=~WWINDOW_MAPPED;
152 /*if(wglobal.current_wswindow==wwin)
153 wglobal.current_wswindow=NULL;*/
157 void map_window(WWindow *wwin)
159 if(wwin->flags&WWINDOW_UNMAPPABLE)
160 return;
162 do_map_window(wwin);
166 void unmap_window(WWindow *wwin)
168 do_unmap_window(wwin);
172 /*}}}*/
175 /*{{{ Misc */
178 void focus_window(WWindow *wwin)
180 set_input_focus(wwin->win);
184 /*}}}*/