1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*
* ion/mod_mgmtmode/mgmtmode.c
*
* Copyright (c) Tuomo Valkonen 2004-2007.
*
* See the included file LICENSE for details.
*/
#include <math.h>
#include <sys/time.h>
#include <time.h>
#include <limits.h>
#include <libtu/objp.h>
#include <ioncore/common.h>
#include <ioncore/global.h>
#include <ioncore/region.h>
#include <ioncore/rootwin.h>
#include <ioncore/binding.h>
#include <ioncore/grab.h>
#include "mgmtmode.h"
#include "main.h"
static WMgmtMode *mgmt_mode=NULL;
static void cancel_mgmt(WRegion *reg);
/*{{{ WMgmtMode */
static bool mgmtmode_init(WMgmtMode *mode, WRegion *reg)
{
watch_init(&(mode->selw));
watch_setup(&(mode->selw), (Obj*)reg, NULL);
return TRUE;
}
static WMgmtMode *create_mgmtmode(WRegion *reg)
{
CREATEOBJ_IMPL(WMgmtMode, mgmtmode, (p, reg));
}
static void mgmtmode_deinit(WMgmtMode *mode)
{
if(mgmt_mode==mode)
mgmt_mode=NULL;
watch_reset(&(mode->selw));
}
/*EXTL_DOC
* Select management mode target.
*/
EXTL_EXPORT_MEMBER
void mgmtmode_select(WMgmtMode *mode, WRegion *reg)
{
watch_setup(&(mode->selw), (Obj*)reg, NULL);
}
/*EXTL_DOC
* Return management mode target.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
WRegion *mgmtmode_selected(WMgmtMode *mode)
{
return (WRegion*)(mode->selw.obj);
}
/*EXTL_DOC
* End management mode.
*/
EXTL_EXPORT_MEMBER
void mgmtmode_finish(WMgmtMode *mode)
{
if(mgmt_mode==mode)
cancel_mgmt(NULL);
}
EXTL_EXPORT
IMPLCLASS(WMgmtMode, Obj, mgmtmode_deinit, NULL);
/*}}}*/
/*{{{ Rubberband */
static void draw_rubberbox(WRootWin *rw, const WRectangle *rect)
{
XPoint fpts[5];
fpts[0].x=rect->x;
fpts[0].y=rect->y;
fpts[1].x=rect->x+rect->w;
fpts[1].y=rect->y;
fpts[2].x=rect->x+rect->w;
fpts[2].y=rect->y+rect->h;
fpts[3].x=rect->x;
fpts[3].y=rect->y+rect->h;
fpts[4].x=rect->x;
fpts[4].y=rect->y;
XDrawLines(ioncore_g.dpy, WROOTWIN_ROOT(rw), rw->xor_gc, fpts, 5,
CoordModeOrigin);
}
static void mgmtmode_draw(WMgmtMode *mode)
{
WRegion *reg=mgmtmode_selected(mode);
if(reg!=NULL){
WRootWin *rw=region_rootwin_of(reg);
WRectangle g=REGION_GEOM(reg);
int rx=0, ry=0;
region_rootpos(reg, &rx, &ry);
g.x=rx;
g.y=ry;
draw_rubberbox(rw, &g);
}
}
static void mgmtmode_erase(WMgmtMode *mode)
{
mgmtmode_draw(mode);
}
/*}}}*/
/*{{{ The mode */
static bool mgmt_handler(WRegion *reg, XEvent *xev)
{
XKeyEvent *ev=&xev->xkey;
WBinding *binding=NULL;
WMgmtMode *mode;
if(ev->type==KeyRelease)
return FALSE;
if(reg==NULL)
return FALSE;
mode=mgmt_mode;
if(mode==NULL)
return FALSE;
binding=bindmap_lookup_binding(mod_mgmtmode_bindmap,
BINDING_KEYPRESS,
ev->state, ev->keycode);
if(!binding)
return FALSE;
if(binding!=NULL){
mgmtmode_erase(mode);
extl_call(binding->func, "o", NULL, mode);
if(mgmt_mode!=NULL)
mgmtmode_draw(mgmt_mode);
}
return (mgmt_mode==NULL);
}
static void cancel_mgmt(WRegion *reg)
{
if(mgmt_mode!=NULL){
mgmtmode_erase(mgmt_mode);
destroy_obj((Obj*)mgmt_mode);
}
ioncore_grab_remove(mgmt_handler);
}
/*EXTL_DOC
* Begin management mode.
*/
EXTL_EXPORT
WMgmtMode *mod_mgmtmode_begin(WRegion *reg)
{
if(mgmt_mode!=NULL)
return NULL;
mgmt_mode=create_mgmtmode(reg);
if(mgmt_mode==NULL)
return NULL;
ioncore_grab_establish((WRegion*)region_rootwin_of(reg),
mgmt_handler,
(GrabKilledHandler*)cancel_mgmt, 0,
GRAB_DEFAULT_FLAGS);
mgmtmode_draw(mgmt_mode);
return mgmt_mode;
}
/*}}}*/
|