Keyboard shortcut to raise the dock
[wmaker-crm.git] / src / event.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* event.c- event loop and handling
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
56d85687 Rodney Padgett2008-08-09 11:39:24 +010023#include <sys/inotify.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000024#include "wconfig.h"
25
9d2e6ef9 scottc1998-09-29 22:36:29 +000026#include <stdio.h>
27#include <stdlib.h>
28#include <unistd.h>
29#include <string.h>
30
31#include <X11/Xlib.h>
32#include <X11/Xutil.h>
33#ifdef SHAPE
eb87c409 kojima1999-10-20 03:25:06 +000034# include <X11/extensions/shape.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000035#endif
d4025072 id1999-05-17 20:21:43 +000036#ifdef XDND
37#include "xdnd.h"
9af1c6c4 dan1998-10-21 14:43:47 +000038#endif
39
6830b057 dan2004-10-12 21:28:27 +000040#ifdef KEEP_XKB_LOCK_STATUS
41#include <X11/XKBlib.h>
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020042#endif /* KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +000043
44#include "WindowMaker.h"
45#include "window.h"
46#include "actions.h"
47#include "client.h"
48#include "funcs.h"
49#include "keybind.h"
50#include "application.h"
51#include "stacking.h"
52#include "defaults.h"
53#include "workspace.h"
54#include "dock.h"
55#include "framewin.h"
56#include "properties.h"
57#include "balloon.h"
a10214a5 kojima2002-11-28 22:04:07 +000058#include "xinerama.h"
15e37ff9 Carlos R. Mafra2009-10-12 00:08:21 +020059#include "wmspec.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000060
61/******** Global Variables **********/
62extern XContext wWinContext;
9aca0d5f dan2004-10-12 01:34:32 +000063extern XContext wVEdgeContext;
9d2e6ef9 scottc1998-09-29 22:36:29 +000064
65extern Cursor wCursor[WCUR_LAST];
66
67extern WShortKey wKeyBindings[WKBD_LAST];
68extern int wScreenCount;
69extern Time LastTimestamp;
70extern Time LastFocusChange;
71
72extern WPreferences wPreferences;
73
74#define MOD_MASK wPreferences.modifier_mask
75
59eb9475 dan1998-11-03 12:53:26 +000076extern Atom _XA_WM_COLORMAP_NOTIFY;
77
9d2e6ef9 scottc1998-09-29 22:36:29 +000078extern Atom _XA_WM_CHANGE_STATE;
79extern Atom _XA_WM_DELETE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +000080extern Atom _XA_GNUSTEP_WM_ATTR;
9af1c6c4 dan1998-10-21 14:43:47 +000081extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +000082extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
9d2e6ef9 scottc1998-09-29 22:36:29 +000083extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
9df0e167 kojima1999-04-03 03:51:17 +000084extern Atom _XA_WINDOWMAKER_COMMAND;
3f7110b1 Daniel Déchelotte2009-08-19 00:50:49 +020085extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
9d2e6ef9 scottc1998-09-29 22:36:29 +000086
9d2e6ef9 scottc1998-09-29 22:36:29 +000087#ifdef SHAPE
9af1c6c4 dan1998-10-21 14:43:47 +000088extern Bool wShapeSupported;
89extern int wShapeEventBase;
9d2e6ef9 scottc1998-09-29 22:36:29 +000090#endif
91
6830b057 dan2004-10-12 21:28:27 +000092#ifdef KEEP_XKB_LOCK_STATUS
2bce7940 id1999-05-23 19:33:19 +000093extern int wXkbEventBase;
94#endif
95
9d2e6ef9 scottc1998-09-29 22:36:29 +000096/* special flags */
56d85687 Rodney Padgett2008-08-09 11:39:24 +010097/*extern char WDelayedActionSet;*/
9d2e6ef9 scottc1998-09-29 22:36:29 +000098
9d2e6ef9 scottc1998-09-29 22:36:29 +000099/************ Local stuff ***********/
100
31f16389
CM
Carlos R. Mafra2009-08-23 15:15:29 +0200101static void saveTimestamp(XEvent *event);
102static void handleColormapNotify(XEvent *event);
103static void handleMapNotify(XEvent *event);
104static void handleUnmapNotify(XEvent *event);
105static void handleButtonPress(XEvent *event);
106static void handleExpose(XEvent *event);
107static void handleDestroyNotify(XEvent *event);
108static void handleConfigureRequest(XEvent *event);
109static void handleMapRequest(XEvent *event);
110static void handlePropertyNotify(XEvent *event);
111static void handleEnterNotify(XEvent *event);
112static void handleLeaveNotify(XEvent *event);
113static void handleExtensions(XEvent *event);
114static void handleClientMessage(XEvent *event);
115static void handleKeyPress(XEvent *event);
116static void handleFocusIn(XEvent *event);
117static void handleMotionNotify(XEvent *event);
118static void handleVisibilityNotify(XEvent *event);
59eb9475 dan1998-11-03 12:53:26 +0000119
9d2e6ef9 scottc1998-09-29 22:36:29 +0000120#ifdef SHAPE
31f16389 Carlos R. Mafra2009-08-23 15:15:29 +0200121static void handleShapeNotify(XEvent *event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000122#endif
123
124/* called from the signal handler */
125void NotifyDeadProcess(pid_t pid, unsigned char status);
126
127/* real dead process handler */
128static void handleDeadProcess(void *foo);
129
9d2e6ef9 scottc1998-09-29 22:36:29 +0000130typedef struct DeadProcesses {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200131 pid_t pid;
132 unsigned char exit_status;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000133} DeadProcesses;
134
135/* stack of dead processes */
136static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200137static int deadProcessPtr = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000138
139typedef struct DeathHandler {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200140 WDeathHandler *callback;
141 pid_t pid;
142 void *client_data;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000143} DeathHandler;
144
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200145static WMArray *deathHandlers = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000146
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200147WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000148{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200149 DeathHandler *handler;
6830b057 dan2004-10-12 21:28:27 +0000150
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200151 handler = malloc(sizeof(DeathHandler));
152 if (!handler)
153 return 0;
3c046182 kojima1999-09-16 02:58:56 +0000154
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200155 handler->pid = pid;
156 handler->callback = callback;
157 handler->client_data = cdata;
3c046182 kojima1999-09-16 02:58:56 +0000158
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200159 if (!deathHandlers)
160 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
3c046182 kojima1999-09-16 02:58:56 +0000161
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200162 WMAddToArray(deathHandlers, handler);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000163
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200164 return handler;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000165}
166
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200167void wDeleteDeathHandler(WMagicNumber id)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000168{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200169 DeathHandler *handler = (DeathHandler *) id;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000170
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200171 if (!handler || !deathHandlers)
172 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000173
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200174 /* array destructor will call wfree(handler) */
175 WMRemoveFromArray(deathHandlers, handler);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000176}
177
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200178void DispatchEvent(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000179{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200180 if (deathHandlers)
181 handleDeadProcess(NULL);
182
183 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
184 WCHANGE_STATE(WSTATE_EXITING);
185 /* received SIGTERM */
186 /*
187 * WMHandleEvent() can't be called from anything
188 * executed inside here, or we can get in a infinite
189 * recursive loop.
190 */
191 Shutdown(WSExitMode);
192
193 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
194 WCHANGE_STATE(WSTATE_RESTARTING);
195
196 Shutdown(WSRestartPreparationMode);
197 /* received SIGHUP */
198 Restart(NULL, True);
199 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
200 WCHANGE_STATE(WSTATE_NORMAL);
201 wDefaultsCheckDomains();
202 }
203
204 /* for the case that all that is wanted to be dispatched is
205 * the stuff above */
206 if (!event)
207 return;
208
209 saveTimestamp(event);
210 switch (event->type) {
211 case MapRequest:
212 handleMapRequest(event);
213 break;
214
215 case KeyPress:
216 handleKeyPress(event);
217 break;
218
219 case MotionNotify:
220 handleMotionNotify(event);
221 break;
222
223 case ConfigureRequest:
224 handleConfigureRequest(event);
225 break;
226
227 case DestroyNotify:
228 handleDestroyNotify(event);
229 break;
230
231 case MapNotify:
232 handleMapNotify(event);
233 break;
234
235 case UnmapNotify:
236 handleUnmapNotify(event);
237 break;
238
239 case ButtonPress:
240 handleButtonPress(event);
241 break;
242
243 case Expose:
244 handleExpose(event);
245 break;
246
247 case PropertyNotify:
248 handlePropertyNotify(event);
249 break;
250
251 case EnterNotify:
252 handleEnterNotify(event);
253 break;
254
255 case LeaveNotify:
256 handleLeaveNotify(event);
257 break;
258
259 case ClientMessage:
260 handleClientMessage(event);
261 break;
262
263 case ColormapNotify:
264 handleColormapNotify(event);
265 break;
266
267 case MappingNotify:
268 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
269 XRefreshKeyboardMapping(&event->xmapping);
270 break;
271
272 case FocusIn:
273 handleFocusIn(event);
274 break;
275
276 case VisibilityNotify:
277 handleVisibilityNotify(event);
278 break;
279 default:
280 handleExtensions(event);
281 break;
282 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000283}
284
56d85687
RP
Rodney Padgett2008-08-09 11:39:24 +0100285/*
286 *----------------------------------------------------------------------
287 * inotifyHandleEvents-
288 * Check for inotify events
289 *
290 * Returns:
291 * After reading events for the given file descriptor (fd) and
292 * watch descriptor (wd)
293 *
294 * Side effects:
295 * Calls wDefaultsCheckDomains if config database is updated
296 *----------------------------------------------------------------------
297 */
8efc4903
CM
Carlos R. Mafra2009-09-04 15:02:00 +0200298/* allow 5 simultaneous events, with path + filenames up to 64 chars */
299#define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200300void inotifyHandleEvents(int fd, int wd)
56d85687 Rodney Padgett2008-08-09 11:39:24 +0100301{
31f16389 Carlos R. Mafra2009-08-23 15:15:29 +0200302 extern void wDefaultsCheckDomains(void);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200303 ssize_t eventQLength, i = 0;
304 char buff[BUFF_SIZE] = { 0 };
305 /* Check config only once per read of the event queue */
306 int oneShotFlag = 0;
307
308 /*
309 * Read off the queued events
310 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
311 * not occur; the block is on Xevents, but a config file change will normally
312 * occur as a result of an Xevent - so the event queue should never have more than
313 * a few entries before a read().
314 */
315 eventQLength = read(fd, buff, BUFF_SIZE);
316
317 /* check what events occured */
318 /* Should really check wd here too, but for now we only have one watch! */
319 while (i < eventQLength) {
320 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
321
322 /*
323 * see inotify.h for event types.
324 */
325 if (pevent->mask & IN_DELETE_SELF) {
326 wwarning(_("the defaults database has been deleted!"
327 " Restart Window Maker to create the database" " with the default settings"));
328 close(fd);
329 }
330 if (pevent->mask & IN_UNMOUNT) {
331 wwarning(_("the unit containing the defaults database has"
332 " been unmounted. Setting --static mode." " Any changes will not be saved."));
333 close(fd);
334 wPreferences.flags.noupdates = 1;
335 }
336 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
337 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
338 wDefaultsCheckDomains();
339 }
340
341 /* move to next event in the buffer */
342 i += sizeof(struct inotify_event) + pevent->len;
343 }
f18567db Carlos R. Mafra2009-08-18 00:30:17 +0200344}
9d2e6ef9 scottc1998-09-29 22:36:29 +0000345
346/*
347 *----------------------------------------------------------------------
348 * EventLoop-
349 * Processes X and internal events indefinitely.
6830b057 dan2004-10-12 21:28:27 +0000350 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000351 * Returns:
352 * Never returns
6830b057 dan2004-10-12 21:28:27 +0000353 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000354 * Side effects:
355 * The LastTimestamp global variable is updated.
56d85687 Rodney Padgett2008-08-09 11:39:24 +0100356 * Calls inotifyGetEvents if defaults database changes.
6830b057 dan2004-10-12 21:28:27 +0000357 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000358 */
31f16389 Carlos R. Mafra2009-08-23 15:15:29 +0200359void EventLoop(void)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000360{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200361 XEvent event;
362 extern int inotifyFD;
363 extern int inotifyWD;
364 struct timeval time;
365 fd_set rfds;
366 int retVal = 0;
367
368 if (inotifyFD < 0 || inotifyWD < 0)
369 retVal = -1;
370
371 for (;;) {
372
373 WMNextEvent(dpy, &event); /* Blocks here */
374 WMHandleEvent(&event);
375
376 if (retVal != -1) {
377 time.tv_sec = 0;
378 time.tv_usec = 0;
379 FD_ZERO(&rfds);
380 FD_SET(inotifyFD, &rfds);
381
382 /* check for available read data from inotify - don't block! */
383 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
384
385 if (retVal < 0) { /* an error has occured */
386 wwarning(_("select failed. The inotify instance will be closed."
387 " Changes to the defaults database will require"
388 " a restart to take effect."));
389 close(inotifyFD);
390 continue;
391 }
392 if (FD_ISSET(inotifyFD, &rfds))
393 inotifyHandleEvents(inotifyFD, inotifyWD);
394 }
395 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000396}
397
9aca0d5f dan2004-10-12 01:34:32 +0000398/*
399 *----------------------------------------------------------------------
400 * ProcessPendingEvents --
401 * Processes the events that are currently pending (at the time
402 * this function is called) in the display's queue.
403 *
404 * Returns:
405 * After the pending events that were present at the function call
406 * are processed.
407 *
408 * Side effects:
6830b057 dan2004-10-12 21:28:27 +0000409 * Many -- whatever handling events may involve.
9aca0d5f dan2004-10-12 01:34:32 +0000410 *
411 *----------------------------------------------------------------------
412 */
31f16389 Carlos R. Mafra2009-08-23 15:15:29 +0200413void ProcessPendingEvents(void)
9aca0d5f dan2004-10-12 01:34:32 +0000414{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200415 XEvent event;
416 int count;
9aca0d5f dan2004-10-12 01:34:32 +0000417
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200418 XSync(dpy, False);
9aca0d5f dan2004-10-12 01:34:32 +0000419
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200420 /* Take a snapshot of the event count in the queue */
421 count = XPending(dpy);
9aca0d5f dan2004-10-12 01:34:32 +0000422
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200423 while (count > 0 && XPending(dpy)) {
424 WMNextEvent(dpy, &event);
425 WMHandleEvent(&event);
426 count--;
427 }
9aca0d5f dan2004-10-12 01:34:32 +0000428}
429
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200430Bool IsDoubleClick(WScreen * scr, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000431{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200432 if ((scr->last_click_time > 0) &&
433 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
434 && (event->xbutton.button == scr->last_click_button)
435 && (event->xbutton.window == scr->last_click_window)) {
436
437 scr->flags.next_click_is_not_double = 1;
438 scr->last_click_time = 0;
439 scr->last_click_window = event->xbutton.window;
440
441 return True;
442 }
443 return False;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000444}
445
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200446void NotifyDeadProcess(pid_t pid, unsigned char status)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000447{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200448 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
449 wwarning("stack overflow: too many dead processes");
450 return;
451 }
452 /* stack the process to be handled later,
453 * as this is called from the signal handler */
454 deadProcesses[deadProcessPtr].pid = pid;
455 deadProcesses[deadProcessPtr].exit_status = status;
456 deadProcessPtr++;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000457}
458
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200459static void handleDeadProcess(void *foo)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000460{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200461 DeathHandler *tmp;
462 int i;
463
464 for (i = 0; i < deadProcessPtr; i++) {
465 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
466 }
467
468 if (!deathHandlers) {
469 deadProcessPtr = 0;
470 return;
471 }
472
473 /* get the pids on the queue and call handlers */
474 while (deadProcessPtr > 0) {
475 deadProcessPtr--;
476
477 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
478 tmp = WMGetFromArray(deathHandlers, i);
479 if (!tmp)
480 continue;
481
482 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
483 (*tmp->callback) (tmp->pid,
484 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
485 wDeleteDeathHandler(tmp);
486 }
487 }
488 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000489}
490
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200491static void saveTimestamp(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000492{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200493 /*
494 * Never save CurrentTime as LastTimestamp because CurrentTime
495 * it's not a real timestamp (it's the 0L constant)
496 */
497
498 switch (event->type) {
499 case ButtonRelease:
500 case ButtonPress:
501 LastTimestamp = event->xbutton.time;
502 break;
503 case KeyPress:
504 case KeyRelease:
505 LastTimestamp = event->xkey.time;
506 break;
507 case MotionNotify:
508 LastTimestamp = event->xmotion.time;
509 break;
510 case PropertyNotify:
511 LastTimestamp = event->xproperty.time;
512 break;
513 case EnterNotify:
514 case LeaveNotify:
515 LastTimestamp = event->xcrossing.time;
516 break;
517 case SelectionClear:
518 LastTimestamp = event->xselectionclear.time;
519 break;
520 case SelectionRequest:
521 LastTimestamp = event->xselectionrequest.time;
522 break;
523 case SelectionNotify:
524 LastTimestamp = event->xselection.time;
d4025072 id1999-05-17 20:21:43 +0000525#ifdef XDND
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200526 wXDNDProcessSelection(event);
d4025072 id1999-05-17 20:21:43 +0000527#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200528 break;
529 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000530}
531
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200532static int matchWindow(void *item, void *cdata)
90c77b1a dan2001-12-17 14:46:31 +0000533{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200534 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
90c77b1a dan2001-12-17 14:46:31 +0000535}
536
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200537static void handleExtensions(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000538{
6830b057 dan2004-10-12 21:28:27 +0000539#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200540 XkbEvent *xkbevent;
541 xkbevent = (XkbEvent *) event;
542#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000543#ifdef SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200544 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
545 handleShapeNotify(event);
546 }
6830b057 dan2004-10-12 21:28:27 +0000547#endif
548#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200549 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
550 handleXkbIndicatorStateNotify(event);
551 }
552#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000553}
554
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200555static void handleMapRequest(XEvent * ev)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000556{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200557 WWindow *wwin;
558 WScreen *scr = NULL;
559 Window window = ev->xmaprequest.window;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000560
561#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200562 printf("got map request for %x\n", (unsigned)window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000563#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200564 if ((wwin = wWindowFor(window))) {
565 if (wwin->flags.shaded) {
566 wUnshadeWindow(wwin);
567 }
568 /* deiconify window */
569 if (wwin->flags.miniaturized) {
570 wDeiconifyWindow(wwin);
571 } else if (wwin->flags.hidden) {
572 WApplication *wapp = wApplicationOf(wwin->main_window);
573 /* go to the last workspace that the user worked on the app */
574 if (wapp) {
575 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
576 }
577 wUnhideApplication(wapp, False, False);
578 }
579 return;
580 }
581
582 scr = wScreenForRootWindow(ev->xmaprequest.parent);
583
584 wwin = wManageWindow(scr, window);
585
586 /*
587 * This is to let the Dock know that the application it launched
588 * has already been mapped (eg: it has finished launching).
589 * It is not necessary for normally docked apps, but is needed for
590 * apps that were forcedly docked (like with dockit).
591 */
592 if (scr->last_dock) {
593 if (wwin && wwin->main_window != None && wwin->main_window != window)
594 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
595 else
596 wDockTrackWindowLaunch(scr->last_dock, window);
597 }
598
599 if (wwin) {
600 wClientSetState(wwin, NormalState, None);
601 if (wwin->flags.maximized) {
602 wMaximizeWindow(wwin, wwin->flags.maximized);
603 }
604 if (wwin->flags.shaded) {
605 wwin->flags.shaded = 0;
606 wwin->flags.skip_next_animation = 1;
607 wShadeWindow(wwin);
608 }
609 if (wwin->flags.miniaturized) {
610 wwin->flags.miniaturized = 0;
611 wwin->flags.skip_next_animation = 1;
612 wIconifyWindow(wwin);
613 }
614 if (wwin->flags.fullscreen) {
615 wwin->flags.fullscreen = 0;
616 wFullscreenWindow(wwin);
617 }
618 if (wwin->flags.hidden) {
619 WApplication *wapp = wApplicationOf(wwin->main_window);
620
621 wwin->flags.hidden = 0;
622 wwin->flags.skip_next_animation = 1;
623 if (wapp) {
624 wHideApplication(wapp);
625 }
626 }
627 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000628}
629
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200630static void handleDestroyNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000631{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200632 WWindow *wwin;
633 WApplication *app;
634 Window window = event->xdestroywindow.window;
635 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
636 int widx;
0261c326 dan1999-01-06 15:22:33 +0000637
9d2e6ef9 scottc1998-09-29 22:36:29 +0000638#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200639 printf("got destroy notify\n");
eb87c409 kojima1999-10-20 03:25:06 +0000640#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200641 wwin = wWindowFor(window);
642 if (wwin) {
643 wUnmanageWindow(wwin, False, True);
644 }
645
646 if (scr != NULL) {
647 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
648 WFakeGroupLeader *fPtr;
649
650 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
651 if (fPtr->retainCount > 0) {
652 fPtr->retainCount--;
653 if (fPtr->retainCount == 0 && fPtr->leader != None) {
654 XDestroyWindow(dpy, fPtr->leader);
655 fPtr->leader = None;
656 XFlush(dpy);
657 }
658 }
659 fPtr->origLeader = None;
660 }
661 }
662
663 app = wApplicationOf(window);
664 if (app) {
665 if (window == app->main_window) {
666 app->refcount = 0;
667 wwin = app->main_window_desc->screen_ptr->focused_window;
668 while (wwin) {
669 if (wwin->main_window == window) {
670 wwin->main_window = None;
671 }
672 wwin = wwin->prev;
673 }
674 }
675 wApplicationDestroy(app);
676 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000677}
678
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200679static void handleExpose(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000680{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200681 WObjDescriptor *desc;
682 XEvent ev;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000683
eb87c409 kojima1999-10-20 03:25:06 +0000684#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200685 printf("got expose\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000686#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200687 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
e7495baf dan1999-02-17 11:06:40 +0000688
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200689 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
690 return;
691 }
6830b057 dan2004-10-12 21:28:27 +0000692
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200693 if (desc->handle_expose) {
694 (*desc->handle_expose) (desc, event);
695 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000696}
697
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200698static void executeButtonAction(WScreen * scr, XEvent * event, int action)
3bde6495 dan2001-04-27 23:41:17 +0000699{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200700 switch (action) {
701 case WA_SELECT_WINDOWS:
702 wUnselectWindows(scr);
703 wSelectWindows(scr, event);
704 break;
705 case WA_OPEN_APPMENU:
706 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
707 /* ugly hack */
708 if (scr->root_menu) {
709 if (scr->root_menu->brother->flags.mapped)
710 event->xbutton.window = scr->root_menu->brother->frame->core->window;
711 else
712 event->xbutton.window = scr->root_menu->frame->core->window;
713 }
714 break;
715 case WA_OPEN_WINLISTMENU:
716 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
717 if (scr->switch_menu) {
718 if (scr->switch_menu->brother->flags.mapped)
719 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
720 else
721 event->xbutton.window = scr->switch_menu->frame->core->window;
722 }
723 break;
724 default:
725 break;
726 }
3bde6495 dan2001-04-27 23:41:17 +0000727}
728
9d2e6ef9 scottc1998-09-29 22:36:29 +0000729/* bindable */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200730static void handleButtonPress(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000731{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200732 WObjDescriptor *desc;
733 WScreen *scr;
6830b057 dan2004-10-12 21:28:27 +0000734
eb87c409 kojima1999-10-20 03:25:06 +0000735#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200736 printf("got button press\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000737#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200738 scr = wScreenForRootWindow(event->xbutton.root);
6830b057 dan2004-10-12 21:28:27 +0000739
9d2e6ef9 scottc1998-09-29 22:36:29 +0000740#ifdef BALLOON_TEXT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200741 wBalloonHide(scr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000742#endif
743
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200744 if (event->xbutton.window == scr->root_win) {
745 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
746 executeButtonAction(scr, event, wPreferences.mouse_button1);
747 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
748 executeButtonAction(scr, event, wPreferences.mouse_button2);
749 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
750 executeButtonAction(scr, event, wPreferences.mouse_button3);
751 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
752 wWorkspaceRelativeChange(scr, 1);
753 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
754 wWorkspaceRelativeChange(scr, -1);
755 }
756 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200757
758 desc = NULL;
759 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
760 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
761 return;
762 }
763 }
764
765 if (desc->parent_type == WCLASS_WINDOW) {
766 XSync(dpy, 0);
767
768 if (event->xbutton.state & MOD_MASK) {
769 XAllowEvents(dpy, AsyncPointer, CurrentTime);
770 }
771
772 /* if (wPreferences.focus_mode == WKF_CLICK) { */
773 if (wPreferences.ignore_focus_click) {
774 XAllowEvents(dpy, AsyncPointer, CurrentTime);
775 }
776 XAllowEvents(dpy, ReplayPointer, CurrentTime);
777 /* } */
778 XSync(dpy, 0);
779 } else if (desc->parent_type == WCLASS_APPICON
780 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
781 if (event->xbutton.state & MOD_MASK) {
782 XSync(dpy, 0);
783 XAllowEvents(dpy, AsyncPointer, CurrentTime);
784 XSync(dpy, 0);
785 }
786 }
787
788 if (desc->handle_mousedown != NULL) {
789 (*desc->handle_mousedown) (desc, event);
790 }
791
792 /* save double-click information */
793 if (scr->flags.next_click_is_not_double) {
794 scr->flags.next_click_is_not_double = 0;
795 } else {
796 scr->last_click_time = event->xbutton.time;
797 scr->last_click_button = event->xbutton.button;
798 scr->last_click_window = event->xbutton.window;
799 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000800}
801
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200802static void handleMapNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000803{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200804 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000805#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200806 printf("got map\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000807#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200808 wwin = wWindowFor(event->xmap.event);
809 if (wwin && wwin->client_win == event->xmap.event) {
810 if (wwin->flags.miniaturized) {
811 wDeiconifyWindow(wwin);
812 } else {
813 XGrabServer(dpy);
814 wWindowMap(wwin);
815 wClientSetState(wwin, NormalState, None);
816 XUngrabServer(dpy);
817 }
818 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000819}
820
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200821static void handleUnmapNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000822{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200823 WWindow *wwin;
824 XEvent ev;
825 Bool withdraw = False;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000826#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200827 printf("got unmap\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000828#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200829 /* only process windows with StructureNotify selected
830 * (ignore SubstructureNotify) */
831 wwin = wWindowFor(event->xunmap.window);
832 if (!wwin)
833 return;
834
835 /* whether the event is a Withdrawal request */
836 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
837 withdraw = True;
838
839 if (wwin->client_win != event->xunmap.event && !withdraw)
840 return;
841
842 if (!wwin->flags.mapped && !withdraw
843 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
844 && !wwin->flags.miniaturized && !wwin->flags.hidden)
845 return;
846
847 XGrabServer(dpy);
848 XUnmapWindow(dpy, wwin->frame->core->window);
849 wwin->flags.mapped = 0;
850 XSync(dpy, 0);
851 /* check if the window was destroyed */
852 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
853 DispatchEvent(&ev);
854 } else {
855 Bool reparented = False;
856
857 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
858 reparented = True;
859
860 /* withdraw window */
861 wwin->flags.mapped = 0;
862 if (!reparented)
863 wClientSetState(wwin, WithdrawnState, None);
864
865 /* if the window was reparented, do not reparent it back to the
866 * root window */
867 wUnmanageWindow(wwin, !reparented, False);
868 }
869 XUngrabServer(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000870}
871
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200872static void handleConfigureRequest(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000873{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200874 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000875#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200876 printf("got configure request\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000877#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200878 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
879 /*
880 * Configure request for unmapped window
881 */
882 wClientConfigure(NULL, &(event->xconfigurerequest));
883 } else {
884 wClientConfigure(wwin, &(event->xconfigurerequest));
885 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000886}
887
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200888static void handlePropertyNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000889{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200890 WWindow *wwin;
891 WApplication *wapp;
892 Window jr;
893 int ji;
894 unsigned int ju;
895 WScreen *scr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000896#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200897 printf("got property notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000898#endif
6b08fc9e Carlos R. Mafra2009-08-08 23:37:27 +0200899
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200900 wwin = wWindowFor(event->xproperty.window);
901 if (wwin) {
902 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
903 return;
904 }
905 wClientCheckProperty(wwin, &event->xproperty);
906 }
907 wapp = wApplicationOf(event->xproperty.window);
908 if (wapp) {
909 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
910 }
911
912 scr = wScreenForWindow(event->xproperty.window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000913}
914
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200915static void handleClientMessage(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000916{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200917 WWindow *wwin;
918 WObjDescriptor *desc;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000919#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200920 printf("got client message\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000921#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200922 /* handle transition from Normal to Iconic state */
923 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
924 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
925
926 wwin = wWindowFor(event->xclient.window);
927 if (!wwin)
928 return;
929 if (!wwin->flags.miniaturized)
930 wIconifyWindow(wwin);
931 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
932 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
933
934 if (!scr)
935 return;
936
937 if (event->xclient.data.l[1] == 1) { /* starting */
938 wColormapAllowClientInstallation(scr, True);
939 } else { /* stopping */
940 wColormapAllowClientInstallation(scr, False);
941 }
942 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
943
944 wDefaultsCheckDomains();
945
946 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
947 WApplication *wapp;
948 int done = 0;
949 wapp = wApplicationOf(event->xclient.window);
950 if (wapp) {
951 switch (event->xclient.data.l[0]) {
952 case WMFHideOtherApplications:
953 wHideOtherApplications(wapp->main_window_desc);
954 done = 1;
955 break;
956
957 case WMFHideApplication:
958 wHideApplication(wapp);
959 done = 1;
960 break;
961 }
962 }
963 if (!done) {
964 wwin = wWindowFor(event->xclient.window);
965 if (wwin) {
966 switch (event->xclient.data.l[0]) {
967 case WMFHideOtherApplications:
968 wHideOtherApplications(wwin);
969 break;
970
971 case WMFHideApplication:
972 wHideApplication(wApplicationOf(wwin->main_window));
973 break;
974 }
975 }
976 }
977 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
978 wwin = wWindowFor(event->xclient.window);
979 if (!wwin)
980 return;
981 switch (event->xclient.data.l[0]) {
982 case GSWindowLevelAttr:
983 {
984 int level = (int)event->xclient.data.l[1];
985
986 if (WINDOW_LEVEL(wwin) != level) {
987 ChangeStackingLevel(wwin->frame->core, level);
988 }
989 }
990 break;
991 }
992 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
993 wwin = wWindowFor(event->xclient.window);
994 if (!wwin)
995 return;
996 switch (event->xclient.data.l[0]) {
997 case WMTitleBarNormal:
998 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
999 break;
1000 case WMTitleBarMain:
1001 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1002 break;
1003 case WMTitleBarKey:
1004 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1005 break;
1006 }
3f7110b1
DD
Daniel Déchelotte2009-08-19 00:50:49 +02001007 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1008 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1009 if (!scr)
1010 return;
1011 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001012 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1013 /* do nothing */
d4025072 id1999-05-17 20:21:43 +00001014#ifdef XDND
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001015 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1016 /* do nothing */
1017#endif /* XDND */
1018 } else {
1019 /*
1020 * Non-standard thing, but needed by OffiX DND.
1021 * For when the icon frame gets a ClientMessage
1022 * that should have gone to the icon_window.
1023 */
1024 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1025 struct WIcon *icon = NULL;
1026
1027 if (desc->parent_type == WCLASS_MINIWINDOW) {
1028 icon = (WIcon *) desc->parent;
1029 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1030 icon = ((WAppIcon *) desc->parent)->icon;
1031 }
1032 if (icon && (wwin = icon->owner)) {
1033 if (wwin->client_win != event->xclient.window) {
1034 event->xclient.window = wwin->client_win;
1035 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1036 }
1037 }
1038 }
1039 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001040}
1041
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001042static void raiseWindow(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001043{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001044 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001046 scr->autoRaiseTimer = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001047
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001048 wwin = wWindowFor(scr->autoRaiseWindow);
1049 if (!wwin)
1050 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001051
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001052 if (!wwin->flags.destroyed && wwin->flags.focused) {
1053 wRaiseFrame(wwin->frame->core);
1054 /* this is needed or a race condition will occur */
1055 XSync(dpy, False);
1056 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001057}
1058
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001059static void handleEnterNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001060{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001061 WWindow *wwin;
1062 WObjDescriptor *desc = NULL;
9aca0d5f dan2004-10-12 01:34:32 +00001063#ifdef VIRTUAL_DESKTOP
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001064 void (*vdHandler) (XEvent * event);
9aca0d5f dan2004-10-12 01:34:32 +00001065#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001066 XEvent ev;
1067 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001068#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001069 printf("got enter notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001070#endif
8eb0c79c id1999-12-18 11:52:49 +00001071
1072#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001073 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext, (XPointer *) & vdHandler) != XCNOENT) {
1074 (*vdHandler) (event);
1075 }
8eb0c79c id1999-12-18 11:52:49 +00001076#endif
1077
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001078 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1079 /* already left the window... */
1080 saveTimestamp(&ev);
1081 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1082 return;
1083 }
1084 }
1085
1086 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1087 if (desc->handle_enternotify)
1088 (*desc->handle_enternotify) (desc, event);
1089 }
1090
1091 /* enter to window */
1092 wwin = wWindowFor(event->xcrossing.window);
1093 if (!wwin) {
1094 if (wPreferences.colormap_mode == WCM_POINTER) {
1095 wColormapInstallForWindow(scr, NULL);
1096 }
1097 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1098 WMDeleteTimerHandler(scr->autoRaiseTimer);
1099 scr->autoRaiseTimer = NULL;
1100 }
1101 } else {
1102 /* set auto raise timer even if in focus-follows-mouse mode
1103 * and the event is for the frame window, even if the window
1104 * has focus already. useful if you move the pointer from a focused
1105 * window to the root window and back pretty fast
1106 *
1107 * set focus if in focus-follows-mouse mode and the event
1108 * is for the frame window and window doesn't have focus yet */
1109 if (wPreferences.focus_mode == WKF_SLOPPY
1110 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1111
1112 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1113 wSetFocusTo(scr, wwin);
1114
1115 if (scr->autoRaiseTimer)
1116 WMDeleteTimerHandler(scr->autoRaiseTimer);
1117 scr->autoRaiseTimer = NULL;
1118
1119 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1120 scr->autoRaiseWindow = wwin->frame->core->window;
1121 scr->autoRaiseTimer
1122 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1123 }
1124 }
1125 /* Install colormap for window, if the colormap installation mode
1126 * is colormap_follows_mouse */
1127 if (wPreferences.colormap_mode == WCM_POINTER) {
1128 if (wwin->client_win == event->xcrossing.window)
1129 wColormapInstallForWindow(scr, wwin);
1130 else
1131 wColormapInstallForWindow(scr, NULL);
1132 }
1133 }
1134
1135 /* a little kluge to hide the clip balloon */
1136 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1137 if (!desc) {
1138 XUnmapWindow(dpy, scr->clip_balloon);
1139 scr->flags.clip_balloon_mapped = 0;
1140 } else {
1141 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1142 XUnmapWindow(dpy, scr->clip_balloon);
1143 scr->flags.clip_balloon_mapped = 0;
1144 }
1145 }
1146 }
1147
1148 if (event->xcrossing.window == event->xcrossing.root
1149 && event->xcrossing.detail == NotifyNormal
1150 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1151
1152 wSetFocusTo(scr, scr->focused_window);
1153 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001154#ifdef BALLOON_TEXT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001155 wBalloonEnteredObject(scr, desc);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001156#endif
1157}
1158
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001159static void handleLeaveNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001160{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001161 WObjDescriptor *desc = NULL;
34cd5125 kojima2000-01-20 11:51:42 +00001162
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001163 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1164 if (desc->handle_leavenotify)
1165 (*desc->handle_leavenotify) (desc, event);
1166 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001167}
1168
9d2e6ef9 scottc1998-09-29 22:36:29 +00001169#ifdef SHAPE
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001170static void handleShapeNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001171{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001172 XShapeEvent *shev = (XShapeEvent *) event;
1173 WWindow *wwin;
1174 XEvent ev;
652caa1f dan1999-10-21 00:54:37 +00001175#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001176 printf("got shape notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001177#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001178 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1179 XShapeEvent *sev = (XShapeEvent *) & ev;
6830b057 dan2004-10-12 21:28:27 +00001180
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001181 if (sev->kind == ShapeBounding) {
1182 if (sev->shaped == shev->shaped) {
1183 *shev = *sev;
1184 } else {
1185 XPutBackEvent(dpy, &ev);
1186 break;
1187 }
1188 }
1189 }
9af1c6c4 dan1998-10-21 14:43:47 +00001190
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001191 wwin = wWindowFor(shev->window);
1192 if (!wwin || shev->kind != ShapeBounding)
1193 return;
9af1c6c4 dan1998-10-21 14:43:47 +00001194
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001195 if (!shev->shaped && wwin->flags.shaped) {
9af1c6c4 dan1998-10-21 14:43:47 +00001196
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001197 wwin->flags.shaped = 0;
1198 wWindowClearShape(wwin);
9af1c6c4 dan1998-10-21 14:43:47 +00001199
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001200 } else if (shev->shaped) {
9af1c6c4 dan1998-10-21 14:43:47 +00001201
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001202 wwin->flags.shaped = 1;
1203 wWindowSetShape(wwin);
1204 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001205}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001206#endif /* SHAPE */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001207
6830b057 dan2004-10-12 21:28:27 +00001208#ifdef KEEP_XKB_LOCK_STATUS
7f9f8894 kojima1999-03-15 23:41:22 +00001209/* please help ]d if you know what to do */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001210handleXkbIndicatorStateNotify(XEvent * event)
7f9f8894 kojima1999-03-15 23:41:22 +00001211{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001212 WWindow *wwin;
1213 WScreen *scr;
1214 XkbStateRec staterec;
1215 int i;
1216
1217 for (i = 0; i < wScreenCount; i++) {
1218 scr = wScreenWithNumber(i);
1219 wwin = scr->focused_window;
1220 if (wwin && wwin->flags.focused) {
1221 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1222 if (wwin->frame->languagemode != staterec.group) {
1223 wwin->frame->last_languagemode = wwin->frame->languagemode;
1224 wwin->frame->languagemode = staterec.group;
1225 }
c28f3b2c id1999-05-20 23:30:53 +00001226#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001227 if (wwin->frame->titlebar) {
1228 wFrameWindowPaint(wwin->frame);
1229 }
c28f3b2c id1999-05-20 23:30:53 +00001230#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001231 }
1232 }
7f9f8894 kojima1999-03-15 23:41:22 +00001233}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001234#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001235
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001236static void handleColormapNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001237{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001238 WWindow *wwin;
1239 WScreen *scr;
1240 Bool reinstall = False;
1241
1242 wwin = wWindowFor(event->xcolormap.window);
1243 if (!wwin)
1244 return;
1245
1246 scr = wwin->screen_ptr;
1247
1248 do {
1249 if (wwin) {
1250 if (event->xcolormap.new) {
1251 XWindowAttributes attr;
1252
1253 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1254
1255 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1256 scr->current_colormap = attr.colormap;
1257
1258 reinstall = True;
1259 } else if (event->xcolormap.state == ColormapUninstalled &&
1260 scr->current_colormap == event->xcolormap.colormap) {
1261
1262 /* some bastard app (like XV) removed our colormap */
1263 /*
1264 * can't enforce or things like xscreensaver wont work
1265 * reinstall = True;
1266 */
1267 } else if (event->xcolormap.state == ColormapInstalled &&
1268 scr->current_colormap == event->xcolormap.colormap) {
1269
1270 /* someone has put our colormap back */
1271 reinstall = False;
1272 }
1273 }
1274 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1275 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1276
1277 if (reinstall && scr->current_colormap != None) {
1278 if (!scr->flags.colormap_stuff_blocked)
1279 XInstallColormap(dpy, scr->current_colormap);
1280 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001281}
1282
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001283static void handleFocusIn(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001284{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001285 WWindow *wwin;
1286
1287 /*
1288 * For applications that like stealing the focus.
1289 */
1290 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1291 saveTimestamp(event);
1292 if (event->xfocus.mode == NotifyUngrab
1293 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1294 return;
1295 }
1296
1297 wwin = wWindowFor(event->xfocus.window);
1298 if (wwin && !wwin->flags.focused) {
1299 if (wwin->flags.mapped)
1300 wSetFocusTo(wwin->screen_ptr, wwin);
1301 else
1302 wSetFocusTo(wwin->screen_ptr, NULL);
1303 } else if (!wwin) {
1304 WScreen *scr = wScreenForWindow(event->xfocus.window);
1305 if (scr)
1306 wSetFocusTo(scr, NULL);
1307 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001308}
1309
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001310static WWindow *windowUnderPointer(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001311{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001312 unsigned int mask;
1313 int foo;
1314 Window bar, win;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001315
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001316 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1317 return wWindowFor(win);
1318 return NULL;
1319}
3c046182 kojima1999-09-16 02:58:56 +00001320
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001321static int CheckFullScreenWindowFocused(WScreen * scr)
30247c58 kojima2004-10-18 01:43:13 +00001322{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001323 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1324 return 1;
1325 else
1326 return 0;
30247c58 kojima2004-10-18 01:43:13 +00001327}
3c046182 kojima1999-09-16 02:58:56 +00001328
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001329static void handleKeyPress(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001330{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001331 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1332 WWindow *wwin = scr->focused_window;
1333 short i, widx;
1334 int modifiers;
1335 int command = -1;
6830b057 dan2004-10-12 21:28:27 +00001336#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001337 XkbStateRec staterec;
1338#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001339
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001340 /* ignore CapsLock */
1341 modifiers = event->xkey.state & ValidModMask;
6830b057 dan2004-10-12 21:28:27 +00001342
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001343 for (i = 0; i < WKBD_LAST; i++) {
1344 if (wKeyBindings[i].keycode == 0)
1345 continue;
9e615bcf dan2001-12-28 03:29:50 +00001346
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001347 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1348 || */ wKeyBindings[i].modifier ==
1349 modifiers)) {
1350 command = i;
1351 break;
1352 }
1353 }
9e615bcf dan2001-12-28 03:29:50 +00001354
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001355 if (command < 0) {
fe736e84 Carlos R. Mafra2009-08-23 18:25:59 +02001356
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001357 if (!wRootMenuPerformShortcut(event)) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001358 static int dontLoop = 0;
1359
1360 if (dontLoop > 10) {
1361 wwarning("problem with key event processing code");
1362 return;
1363 }
1364 dontLoop++;
1365 /* if the focused window is an internal window, try redispatching
1366 * the event to the managed window, as it can be a WINGs window */
1367 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1368 /* client_leader contains the WINGs toplevel */
1369 event->xany.window = wwin->client_leader;
1370 WMHandleEvent(event);
1371 }
1372 dontLoop--;
1373 }
1374 return;
1375 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001376#define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1377#define ISFOCUSED(w) ((w) && (w)->flags.focused)
1378
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001379 switch (command) {
fe736e84 Carlos R. Mafra2009-08-23 18:25:59 +02001380
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001381 case WKBD_ROOTMENU:
1382 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1383 if (!CheckFullScreenWindowFocused(scr)) {
1384 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1385 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1386 True);
1387 }
1388 break;
1389 case WKBD_WINDOWLIST:
1390 if (!CheckFullScreenWindowFocused(scr)) {
1391 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1392 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1393 True);
1394 }
1395 break;
fe736e84 Carlos R. Mafra2009-08-23 18:25:59 +02001396
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001397 case WKBD_WINDOWMENU:
1398 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1399 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1400 break;
1401 case WKBD_MINIATURIZE:
1402 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1403 && !WFLAGP(wwin, no_miniaturizable)) {
1404 CloseWindowMenu(scr);
1405
1406 if (wwin->protocols.MINIATURIZE_WINDOW)
1407 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1408 else {
1409 wIconifyWindow(wwin);
1410 }
1411 }
1412 break;
1413 case WKBD_HIDE:
1414 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1415 WApplication *wapp = wApplicationOf(wwin->main_window);
1416 CloseWindowMenu(scr);
1417
1418 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1419 wHideApplication(wapp);
1420 }
1421 }
1422 break;
1423 case WKBD_HIDE_OTHERS:
1424 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1425 CloseWindowMenu(scr);
1426
1427 wHideOtherApplications(wwin);
1428 }
1429 break;
1430 case WKBD_MAXIMIZE:
1431 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001432 CloseWindowMenu(scr);
1433
c04a2cae Carlos R. Mafra2009-09-01 03:22:57 +02001434 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_HORIZONTAL))
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001435 wUnmaximizeWindow(wwin);
c04a2cae
CM
Carlos R. Mafra2009-09-01 03:22:57 +02001436 else
1437 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001438 }
1439 break;
1440 case WKBD_VMAXIMIZE:
1441 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001442 CloseWindowMenu(scr);
1443
c04a2cae Carlos R. Mafra2009-09-01 03:22:57 +02001444 if (wwin->flags.maximized == MAX_VERTICAL)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001445 wUnmaximizeWindow(wwin);
c04a2cae
CM
Carlos R. Mafra2009-09-01 03:22:57 +02001446 else
1447 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_KEYBOARD);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001448 }
1449 break;
1450 case WKBD_HMAXIMIZE:
1451 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001452 CloseWindowMenu(scr);
1453
c04a2cae Carlos R. Mafra2009-09-01 03:22:57 +02001454 if (wwin->flags.maximized == MAX_HORIZONTAL)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001455 wUnmaximizeWindow(wwin);
c04a2cae
CM
Carlos R. Mafra2009-09-01 03:22:57 +02001456 else
1457 wMaximizeWindow(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001458 }
1459 break;
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +02001460 case WKBD_LHMAXIMIZE:
1461 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +02001462 CloseWindowMenu(scr);
1463
4bce3e38 Carlos R. Mafra2009-09-13 18:28:42 +02001464 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_LEFTHALF))
69244548 Johann Haarhoff2009-08-28 21:31:26 +02001465 wUnmaximizeWindow(wwin);
c04a2cae
CM
Carlos R. Mafra2009-09-01 03:22:57 +02001466 else
1467 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +02001468 }
1469 break;
1470 case WKBD_RHMAXIMIZE:
1471 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +02001472 CloseWindowMenu(scr);
1473
4bce3e38 Carlos R. Mafra2009-09-13 18:28:42 +02001474 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_RIGHTHALF))
69244548 Johann Haarhoff2009-08-28 21:31:26 +02001475 wUnmaximizeWindow(wwin);
c04a2cae
CM
Carlos R. Mafra2009-09-01 03:22:57 +02001476 else
1477 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +02001478 }
1479 break;
cf62d159
CM
Carlos R. Mafra2009-09-02 01:37:47 +02001480 case WKBD_MAXIMUS:
1481 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
cf62d159
CM
Carlos R. Mafra2009-09-02 01:37:47 +02001482 CloseWindowMenu(scr);
1483
c04a2cae Carlos R. Mafra2009-09-01 03:22:57 +02001484 if (wwin->flags.maximized == MAX_MAXIMUS)
cf62d159 Carlos R. Mafra2009-09-02 01:37:47 +02001485 wUnmaximizeWindow(wwin);
c04a2cae
CM
Carlos R. Mafra2009-09-01 03:22:57 +02001486 else
1487 wMaximizeWindow(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
cf62d159
CM
Carlos R. Mafra2009-09-02 01:37:47 +02001488 }
1489 break;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001490 case WKBD_RAISE:
1491 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1492 CloseWindowMenu(scr);
1493
1494 wRaiseFrame(wwin->frame->core);
1495 }
1496 break;
1497 case WKBD_LOWER:
1498 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1499 CloseWindowMenu(scr);
1500
1501 wLowerFrame(wwin->frame->core);
1502 }
1503 break;
1504 case WKBD_RAISELOWER:
1505 /* raise or lower the window under the pointer, not the
1506 * focused one
1507 */
1508 wwin = windowUnderPointer(scr);
1509 if (wwin)
1510 wRaiseLowerFrame(wwin->frame->core);
1511 break;
1512 case WKBD_SHADE:
1513 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1514 if (wwin->flags.shaded)
1515 wUnshadeWindow(wwin);
1516 else
1517 wShadeWindow(wwin);
1518 }
1519 break;
1520 case WKBD_MOVERESIZE:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1522 CloseWindowMenu(scr);
1523
1524 wKeyboardMoveResizeWindow(wwin);
1525 }
1526 break;
1527 case WKBD_CLOSE:
1528 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1529 CloseWindowMenu(scr);
1530 if (wwin->protocols.DELETE_WINDOW)
1531 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1532 }
1533 break;
1534 case WKBD_SELECT:
1535 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1536 wSelectWindow(wwin, !wwin->flags.selected);
1537 }
1538 break;
1539 case WKBD_FOCUSNEXT:
18408fff Iain Patterson2009-09-14 14:37:15 +01001540 StartWindozeCycle(wwin, event, True, False);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001541 break;
1542
1543 case WKBD_FOCUSPREV:
18408fff
IP
Iain Patterson2009-09-14 14:37:15 +01001544 StartWindozeCycle(wwin, event, False, False);
1545 break;
1546
1547 case WKBD_GROUPNEXT:
1548 StartWindozeCycle(wwin, event, True, True);
1549 break;
1550
1551 case WKBD_GROUPPREV:
1552 StartWindozeCycle(wwin, event, False, True);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001553 break;
1554
874b0fad Carlos R. Mafra2009-08-23 17:28:04 +02001555 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001556 widx = command - WKBD_WORKSPACE1;
1557 i = (scr->current_workspace / 10) * 10 + widx;
1558 if (wPreferences.ws_advance || i < scr->workspace_count)
1559 wWorkspaceChange(scr, i);
1560 break;
1561
1562 case WKBD_NEXTWORKSPACE:
1563 wWorkspaceRelativeChange(scr, 1);
1564 break;
1565 case WKBD_PREVWORKSPACE:
1566 wWorkspaceRelativeChange(scr, -1);
1567 break;
874b0fad Carlos R. Mafra2009-08-23 17:28:04 +02001568
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001569 case WKBD_WINDOW1:
1570 case WKBD_WINDOW2:
1571 case WKBD_WINDOW3:
1572 case WKBD_WINDOW4:
1573 case WKBD_WINDOW5:
1574 case WKBD_WINDOW6:
1575 case WKBD_WINDOW7:
1576 case WKBD_WINDOW8:
1577 case WKBD_WINDOW9:
1578 case WKBD_WINDOW10:
1579
1580 widx = command - WKBD_WINDOW1;
1581
1582 if (scr->shortcutWindows[widx]) {
1583 WMArray *list = scr->shortcutWindows[widx];
1584 int cw;
1585 int count = WMGetArrayItemCount(list);
1586 WWindow *twin;
1587 WMArrayIterator iter;
1588 WWindow *wwin;
1589
1590 wUnselectWindows(scr);
1591 cw = scr->current_workspace;
1592
1593 WM_ETARETI_ARRAY(list, wwin, iter) {
1594 if (count > 1)
1595 wWindowChangeWorkspace(wwin, cw);
1596
1597 wMakeWindowVisible(wwin);
1598
1599 if (count > 1)
1600 wSelectWindow(wwin, True);
1601 }
1602
1603 /* rotate the order of windows, to create a cycling effect */
1604 twin = WMGetFromArray(list, 0);
1605 WMDeleteFromArray(list, 0);
1606 WMAddToArray(list, twin);
1607
1608 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1609 if (scr->shortcutWindows[widx]) {
1610 WMFreeArray(scr->shortcutWindows[widx]);
1611 scr->shortcutWindows[widx] = NULL;
1612 }
1613
1614 if (wwin->flags.selected && scr->selected_windows) {
1615 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1616 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1617 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1618 } else {
1619 scr->shortcutWindows[widx] = WMCreateArray(4);
1620 WMAddToArray(scr->shortcutWindows[widx], wwin);
1621 }
1622
1623 wSelectWindow(wwin, !wwin->flags.selected);
1624 XFlush(dpy);
1625 wusleep(3000);
1626 wSelectWindow(wwin, !wwin->flags.selected);
1627 XFlush(dpy);
1628
1629 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1630
1631 if (wwin->flags.selected && scr->selected_windows) {
1632 if (scr->shortcutWindows[widx]) {
1633 WMFreeArray(scr->shortcutWindows[widx]);
1634 }
1635 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1636 }
1637 }
1638
1639 break;
1640
1641 case WKBD_SWITCH_SCREEN:
1642 if (wScreenCount > 1) {
1643 WScreen *scr2;
1644 int i;
1645
1646 /* find index of this screen */
1647 for (i = 0; i < wScreenCount; i++) {
1648 if (wScreenWithNumber(i) == scr)
1649 break;
1650 }
1651 i++;
1652 if (i >= wScreenCount) {
1653 i = 0;
1654 }
1655 scr2 = wScreenWithNumber(i);
1656
1657 if (scr2) {
1658 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1659 scr2->scr_width / 2, scr2->scr_height / 2);
1660 }
1661 }
1662 break;
1663
1664 case WKBD_NEXTWSLAYER:
1665 case WKBD_PREVWSLAYER:
1666 {
1667 int row, column;
1668
1669 row = scr->current_workspace / 10;
1670 column = scr->current_workspace % 10;
1671
1672 if (command == WKBD_NEXTWSLAYER) {
1673 if ((row + 1) * 10 < scr->workspace_count)
1674 wWorkspaceChange(scr, column + (row + 1) * 10);
1675 } else {
1676 if (row > 0)
1677 wWorkspaceChange(scr, column + (row - 1) * 10);
1678 }
1679 }
1680 break;
1681 case WKBD_CLIPLOWER:
1682 if (!wPreferences.flags.noclip)
1683 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1684 break;
1685 case WKBD_CLIPRAISE:
1686 if (!wPreferences.flags.noclip)
1687 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1688 break;
1689 case WKBD_CLIPRAISELOWER:
1690 if (!wPreferences.flags.noclip)
1691 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1692 break;
b6689a01
BJ
Brad Jorsch2010-01-06 12:50:36 -05001693 case WKBD_DOCKRAISELOWER:
1694 if (!wPreferences.flags.nodock)
1695 wDockRaiseLower(scr->dock);
1696 break;
59eb9475 dan1998-11-03 12:53:26 +00001697#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001698 case WKBD_TOGGLE:
1699 if (wPreferences.modelock) {
1700 /*toggle */
1701 wwin = scr->focused_window;
1702
1703 if (wwin && wwin->flags.mapped
1704 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1705 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1706 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1707
1708 wwin->frame->languagemode = wwin->frame->last_languagemode;
1709 wwin->frame->last_languagemode = staterec.group;
1710 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1711
1712 }
1713 }
1714 break;
1715#endif /* KEEP_XKB_LOCK_STATUS */
9aca0d5f dan2004-10-12 01:34:32 +00001716#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001717 case WKBD_VDESK_LEFT:
1718 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1719 break;
9aca0d5f dan2004-10-12 01:34:32 +00001720
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001721 case WKBD_VDESK_RIGHT:
1722 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1723 break;
9aca0d5f dan2004-10-12 01:34:32 +00001724
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001725 case WKBD_VDESK_UP:
1726 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1727 break;
9aca0d5f dan2004-10-12 01:34:32 +00001728
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001729 case WKBD_VDESK_DOWN:
1730 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1731 break;
9aca0d5f dan2004-10-12 01:34:32 +00001732#endif
59eb9475 dan1998-11-03 12:53:26 +00001733
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001734 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001735}
1736
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001737static void handleMotionNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001738{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001739 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1740
1741 if (wPreferences.scrollable_menus) {
1742 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1743 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1744
1745 if (scr->flags.jump_back_pending ||
1746 p.x <= (rect.pos.x + 1) ||
1747 p.x >= (rect.pos.x + rect.size.width - 2) ||
1748 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1749 WMenu *menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001750#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001751 printf("pointer at screen edge\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001752#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001753 menu = wMenuUnderPointer(scr);
1754 if (menu != NULL)
1755 wMenuScroll(menu, event);
1756 }
1757 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001758}
416e3a82 dan1999-01-25 19:06:50 +00001759
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001760static void handleVisibilityNotify(XEvent * event)
e7495baf dan1999-02-17 11:06:40 +00001761{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001762 WWindow *wwin;
e7495baf dan1999-02-17 11:06:40 +00001763
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001764 wwin = wWindowFor(event->xvisibility.window);
1765 if (!wwin)
1766 return;
1767 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);
e7495baf dan1999-02-17 11:06:40 +00001768}