2 * ion/mod_mgmtmode/mgmtmode.c
4 * Copyright (c) Tuomo Valkonen 2004-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.
17 #include <libtu/objp.h>
18 #include <ioncore/common.h>
19 #include <ioncore/global.h>
20 #include <ioncore/region.h>
21 #include <ioncore/rootwin.h>
22 #include <ioncore/binding.h>
23 #include <ioncore/grab.h>
28 static WMgmtMode *mgmt_mode=NULL;
31 static void cancel_mgmt(WRegion *reg);
37 static bool mgmtmode_init(WMgmtMode *mode, WRegion *reg)
39 watch_init(&(mode->selw));
40 watch_setup(&(mode->selw), (Obj*)reg, NULL);
45 static WMgmtMode *create_mgmtmode(WRegion *reg)
47 CREATEOBJ_IMPL(WMgmtMode, mgmtmode, (p, reg));
51 static void mgmtmode_deinit(WMgmtMode *mode)
56 watch_reset(&(mode->selw));
61 * Select management mode target.
64 void mgmtmode_select(WMgmtMode *mode, WRegion *reg)
66 watch_setup(&(mode->selw), (Obj*)reg, NULL);
71 * Return management mode target.
75 WRegion *mgmtmode_selected(WMgmtMode *mode)
77 return (WRegion*)(mode->selw.obj);
82 * End management mode.
85 void mgmtmode_finish(WMgmtMode *mode)
93 IMPLCLASS(WMgmtMode, Obj, mgmtmode_deinit, NULL);
102 static void draw_rubberbox(WRootWin *rw, const WRectangle *rect)
108 fpts[1].x=rect->x+rect->w;
110 fpts[2].x=rect->x+rect->w;
111 fpts[2].y=rect->y+rect->h;
113 fpts[3].y=rect->y+rect->h;
117 XDrawLines(ioncore_g.dpy, WROOTWIN_ROOT(rw), rw->xor_gc, fpts, 5,
122 static void mgmtmode_draw(WMgmtMode *mode)
124 WRegion *reg=mgmtmode_selected(mode);
127 WRootWin *rw=region_rootwin_of(reg);
128 WRectangle g=REGION_GEOM(reg);
131 region_rootpos(reg, &rx, &ry);
136 draw_rubberbox(rw, &g);
141 static void mgmtmode_erase(WMgmtMode *mode)
153 static bool mgmt_handler(WRegion *reg, XEvent *xev)
155 XKeyEvent *ev=&xev->xkey;
156 WBinding *binding=NULL;
159 if(ev->type==KeyRelease)
170 binding=bindmap_lookup_binding(mod_mgmtmode_bindmap,
172 ev->state, ev->keycode);
178 mgmtmode_erase(mode);
179 extl_call(binding->func, "o", NULL, mode);
181 mgmtmode_draw(mgmt_mode);
184 return (mgmt_mode==NULL);
188 static void cancel_mgmt(WRegion *reg)
191 mgmtmode_erase(mgmt_mode);
192 destroy_obj((Obj*)mgmt_mode);
194 ioncore_grab_remove(mgmt_handler);
199 * Begin management mode.
202 WMgmtMode *mod_mgmtmode_begin(WRegion *reg)
207 mgmt_mode=create_mgmtmode(reg);
212 ioncore_grab_establish((WRegion*)region_rootwin_of(reg),
214 (GrabKilledHandler*)cancel_mgmt, 0);
216 mgmtmode_draw(mgmt_mode);