2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "menus.h" /* FIXME - Should not be here */
32 static EObj *w1 = NULL, *w2 = NULL, *w3 = NULL, *w4 = NULL;
33 static Timer *edge_timer = NULL;
36 EdgeTimeout(void *data)
39 int ax, ay, aw, ah, dx, dy, dax, day;
44 if (Conf.desks.edge_flip_mode == EDGE_FLIP_OFF)
47 /* Quit if pointer has left screen */
48 if (!EQueryPointer(NULL, NULL, NULL, NULL, NULL))
51 /* Quit if in fullscreen window */
52 ewin = GetEwinPointerInClient();
53 if (ewin && ewin->state.fullscreen)
56 DeskCurrentGetArea(&ax, &ay);
57 DesksGetAreaSize(&aw, &ah);
66 if (ax == 0 && !Conf.desks.areas_wraparound)
68 dx = WinGetW(VROOT) - 2;
72 if (ax == (aw - 1) && !Conf.desks.areas_wraparound)
74 dx = -(WinGetW(VROOT) - 2);
78 if (ay == 0 && !Conf.desks.areas_wraparound)
80 dy = WinGetH(VROOT) - 2;
84 if (ay == (ah - 1) && !Conf.desks.areas_wraparound)
86 dy = -(WinGetH(VROOT) - 2);
96 Mode.events.px = Mode.events.mx;
97 Mode.events.py = Mode.events.my;
98 Mode.events.mx = Mode.events.cx += dx;
99 Mode.events.my = Mode.events.cy += dy;
100 EXWarpPointer(WinGetXwin(VROOT), Mode.events.mx, Mode.events.my);
101 DeskCurrentMoveAreaBy(dax, day);
102 Mode.events.px = Mode.events.mx;
103 Mode.events.py = Mode.events.my;
113 static int lastdir = -1;
116 Eprintf("EdgeEvent %d -> %d\n", lastdir, dir);
118 if (lastdir == dir || Conf.desks.edge_flip_mode == EDGE_FLIP_OFF)
121 if (Conf.desks.edge_flip_mode == EDGE_FLIP_MOVE && Mode.mode != MODE_MOVE)
124 TIMER_DEL(edge_timer);
127 if (Conf.desks.edge_flip_resistance <= 0)
128 Conf.desks.edge_flip_resistance = 1;
129 TIMER_ADD(edge_timer, ((double)Conf.desks.edge_flip_resistance) / 100.0,
130 EdgeTimeout, INT2PTR(dir));
136 EdgeHandleEvents(Win win __UNUSED__, XEvent * ev, void *prm)
158 EdgeCheckMotion(int x, int y)
164 else if (x == WinGetW(VROOT) - 1)
168 else if (y == WinGetH(VROOT) - 1)
176 EdgeWindowShow(int which, int on)
193 x = WinGetW(VROOT) - 1;
202 y = WinGetH(VROOT) - 1;
209 EobjMoveResize(eo, x, y, w, h);
219 EdgeWindowsShow(void)
223 if (Conf.desks.edge_flip_mode == EDGE_FLIP_OFF)
231 w1 = EobjWindowCreate(EOBJ_TYPE_EVENT,
232 0, 0, 1, WinGetH(VROOT), 0, "Edge-L");
233 w2 = EobjWindowCreate(EOBJ_TYPE_EVENT,
234 WinGetW(VROOT) - 1, 0, 1, WinGetH(VROOT),
236 w3 = EobjWindowCreate(EOBJ_TYPE_EVENT,
237 0, 0, WinGetW(VROOT), 1, 0, "Edge-T");
238 w4 = EobjWindowCreate(EOBJ_TYPE_EVENT,
239 0, WinGetH(VROOT) - 1, WinGetW(VROOT), 1,
241 ESelectInput(EobjGetWin(w1), EnterWindowMask | LeaveWindowMask);
242 ESelectInput(EobjGetWin(w2), EnterWindowMask | LeaveWindowMask);
243 ESelectInput(EobjGetWin(w3), EnterWindowMask | LeaveWindowMask);
244 ESelectInput(EobjGetWin(w4), EnterWindowMask | LeaveWindowMask);
245 EventCallbackRegister(EobjGetWin(w1), 0, EdgeHandleEvents, (void *)0);
246 EventCallbackRegister(EobjGetWin(w2), 0, EdgeHandleEvents, (void *)1);
247 EventCallbackRegister(EobjGetWin(w3), 0, EdgeHandleEvents, (void *)2);
248 EventCallbackRegister(EobjGetWin(w4), 0, EdgeHandleEvents, (void *)3);
250 DeskCurrentGetArea(&cx, &cy);
251 DesksGetAreaSize(&ax, &ay);
253 EdgeWindowShow(1, cx != 0 || Conf.desks.areas_wraparound);
254 EdgeWindowShow(2, cx != (ax - 1) || Conf.desks.areas_wraparound);
255 EdgeWindowShow(3, cy != 0 || Conf.desks.areas_wraparound);
256 EdgeWindowShow(4, cy != (ay - 1) || Conf.desks.areas_wraparound);
260 EdgeWindowsHide(void)