Change to the linux kernel coding style
[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"
3c046182 kojima1999-09-16 02:58:56 +000059
9aca0d5f dan2004-10-12 01:34:32 +000060#ifdef NETWM_HINTS
61# include "wmspec.h"
62#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +000063
64/******** Global Variables **********/
65extern XContext wWinContext;
9aca0d5f dan2004-10-12 01:34:32 +000066extern XContext wVEdgeContext;
9d2e6ef9 scottc1998-09-29 22:36:29 +000067
68extern Cursor wCursor[WCUR_LAST];
69
70extern WShortKey wKeyBindings[WKBD_LAST];
71extern int wScreenCount;
72extern Time LastTimestamp;
73extern Time LastFocusChange;
74
75extern WPreferences wPreferences;
76
77#define MOD_MASK wPreferences.modifier_mask
78
59eb9475 dan1998-11-03 12:53:26 +000079extern Atom _XA_WM_COLORMAP_NOTIFY;
80
9d2e6ef9 scottc1998-09-29 22:36:29 +000081extern Atom _XA_WM_CHANGE_STATE;
82extern Atom _XA_WM_DELETE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +000083extern Atom _XA_GNUSTEP_WM_ATTR;
9af1c6c4 dan1998-10-21 14:43:47 +000084extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +000085extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
9d2e6ef9 scottc1998-09-29 22:36:29 +000086extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
9df0e167 kojima1999-04-03 03:51:17 +000087extern Atom _XA_WINDOWMAKER_COMMAND;
9d2e6ef9 scottc1998-09-29 22:36:29 +000088
9d2e6ef9 scottc1998-09-29 22:36:29 +000089#ifdef SHAPE
9af1c6c4 dan1998-10-21 14:43:47 +000090extern Bool wShapeSupported;
91extern int wShapeEventBase;
9d2e6ef9 scottc1998-09-29 22:36:29 +000092#endif
93
6830b057 dan2004-10-12 21:28:27 +000094#ifdef KEEP_XKB_LOCK_STATUS
2bce7940 id1999-05-23 19:33:19 +000095extern int wXkbEventBase;
96#endif
97
9d2e6ef9 scottc1998-09-29 22:36:29 +000098/* special flags */
56d85687 Rodney Padgett2008-08-09 11:39:24 +010099/*extern char WDelayedActionSet;*/
9d2e6ef9 scottc1998-09-29 22:36:29 +0000100
9d2e6ef9 scottc1998-09-29 22:36:29 +0000101/************ Local stuff ***********/
102
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200103static void saveTimestamp(XEvent * event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000104static void handleColormapNotify();
6830b057 dan2004-10-12 21:28:27 +0000105static void handleMapNotify();
106static void handleUnmapNotify();
107static void handleButtonPress();
108static void handleExpose();
9d2e6ef9 scottc1998-09-29 22:36:29 +0000109static void handleDestroyNotify();
110static void handleConfigureRequest();
111static void handleMapRequest();
112static void handlePropertyNotify();
113static void handleEnterNotify();
114static void handleLeaveNotify();
115static void handleExtensions();
116static void handleClientMessage();
117static void handleKeyPress();
118static void handleFocusIn();
119static void handleMotionNotify();
e7495baf dan1999-02-17 11:06:40 +0000120static void handleVisibilityNotify();
59eb9475 dan1998-11-03 12:53:26 +0000121
9d2e6ef9 scottc1998-09-29 22:36:29 +0000122#ifdef SHAPE
123static void handleShapeNotify();
124#endif
125
126/* called from the signal handler */
127void NotifyDeadProcess(pid_t pid, unsigned char status);
128
129/* real dead process handler */
130static void handleDeadProcess(void *foo);
131
9d2e6ef9 scottc1998-09-29 22:36:29 +0000132typedef struct DeadProcesses {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200133 pid_t pid;
134 unsigned char exit_status;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000135} DeadProcesses;
136
137/* stack of dead processes */
138static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200139static int deadProcessPtr = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000140
141typedef struct DeathHandler {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200142 WDeathHandler *callback;
143 pid_t pid;
144 void *client_data;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000145} DeathHandler;
146
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200147static WMArray *deathHandlers = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000148
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200149WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000150{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200151 DeathHandler *handler;
6830b057 dan2004-10-12 21:28:27 +0000152
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200153 handler = malloc(sizeof(DeathHandler));
154 if (!handler)
155 return 0;
3c046182 kojima1999-09-16 02:58:56 +0000156
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200157 handler->pid = pid;
158 handler->callback = callback;
159 handler->client_data = cdata;
3c046182 kojima1999-09-16 02:58:56 +0000160
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200161 if (!deathHandlers)
162 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
3c046182 kojima1999-09-16 02:58:56 +0000163
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200164 WMAddToArray(deathHandlers, handler);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000165
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200166 return handler;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000167}
168
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200169void wDeleteDeathHandler(WMagicNumber id)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000170{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200171 DeathHandler *handler = (DeathHandler *) id;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000172
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200173 if (!handler || !deathHandlers)
174 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000175
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200176 /* array destructor will call wfree(handler) */
177 WMRemoveFromArray(deathHandlers, handler);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000178}
179
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200180void DispatchEvent(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000181{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200182 if (deathHandlers)
183 handleDeadProcess(NULL);
184
185 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
186 WCHANGE_STATE(WSTATE_EXITING);
187 /* received SIGTERM */
188 /*
189 * WMHandleEvent() can't be called from anything
190 * executed inside here, or we can get in a infinite
191 * recursive loop.
192 */
193 Shutdown(WSExitMode);
194
195 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
196 WCHANGE_STATE(WSTATE_RESTARTING);
197
198 Shutdown(WSRestartPreparationMode);
199 /* received SIGHUP */
200 Restart(NULL, True);
201 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
202 WCHANGE_STATE(WSTATE_NORMAL);
203 wDefaultsCheckDomains();
204 }
205
206 /* for the case that all that is wanted to be dispatched is
207 * the stuff above */
208 if (!event)
209 return;
210
211 saveTimestamp(event);
212 switch (event->type) {
213 case MapRequest:
214 handleMapRequest(event);
215 break;
216
217 case KeyPress:
218 handleKeyPress(event);
219 break;
220
221 case MotionNotify:
222 handleMotionNotify(event);
223 break;
224
225 case ConfigureRequest:
226 handleConfigureRequest(event);
227 break;
228
229 case DestroyNotify:
230 handleDestroyNotify(event);
231 break;
232
233 case MapNotify:
234 handleMapNotify(event);
235 break;
236
237 case UnmapNotify:
238 handleUnmapNotify(event);
239 break;
240
241 case ButtonPress:
242 handleButtonPress(event);
243 break;
244
245 case Expose:
246 handleExpose(event);
247 break;
248
249 case PropertyNotify:
250 handlePropertyNotify(event);
251 break;
252
253 case EnterNotify:
254 handleEnterNotify(event);
255 break;
256
257 case LeaveNotify:
258 handleLeaveNotify(event);
259 break;
260
261 case ClientMessage:
262 handleClientMessage(event);
263 break;
264
265 case ColormapNotify:
266 handleColormapNotify(event);
267 break;
268
269 case MappingNotify:
270 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
271 XRefreshKeyboardMapping(&event->xmapping);
272 break;
273
274 case FocusIn:
275 handleFocusIn(event);
276 break;
277
278 case VisibilityNotify:
279 handleVisibilityNotify(event);
280 break;
281 default:
282 handleExtensions(event);
283 break;
284 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000285}
286
56d85687
RP
Rodney Padgett2008-08-09 11:39:24 +0100287/*
288 *----------------------------------------------------------------------
289 * inotifyHandleEvents-
290 * Check for inotify events
291 *
292 * Returns:
293 * After reading events for the given file descriptor (fd) and
294 * watch descriptor (wd)
295 *
296 * Side effects:
297 * Calls wDefaultsCheckDomains if config database is updated
298 *----------------------------------------------------------------------
299 */
300
f18567db Carlos R. Mafra2009-08-18 00:30:17 +0200301#define BUFF_SIZE ((sizeof(struct inotify_event) + 16)*512)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200302void inotifyHandleEvents(int fd, int wd)
56d85687 Rodney Padgett2008-08-09 11:39:24 +0100303{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200304 extern void wDefaultsCheckDomains();
305 ssize_t eventQLength, i = 0;
306 char buff[BUFF_SIZE] = { 0 };
307 /* Check config only once per read of the event queue */
308 int oneShotFlag = 0;
309
310 /*
311 * Read off the queued events
312 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
313 * not occur; the block is on Xevents, but a config file change will normally
314 * occur as a result of an Xevent - so the event queue should never have more than
315 * a few entries before a read().
316 */
317 eventQLength = read(fd, buff, BUFF_SIZE);
318
319 /* check what events occured */
320 /* Should really check wd here too, but for now we only have one watch! */
321 while (i < eventQLength) {
322 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
323
324 /*
325 * see inotify.h for event types.
326 */
327 if (pevent->mask & IN_DELETE_SELF) {
328 wwarning(_("the defaults database has been deleted!"
329 " Restart Window Maker to create the database" " with the default settings"));
330 close(fd);
331 }
332 if (pevent->mask & IN_UNMOUNT) {
333 wwarning(_("the unit containing the defaults database has"
334 " been unmounted. Setting --static mode." " Any changes will not be saved."));
335 close(fd);
336 wPreferences.flags.noupdates = 1;
337 }
338 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
339 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
340 wDefaultsCheckDomains();
341 }
342
343 /* move to next event in the buffer */
344 i += sizeof(struct inotify_event) + pevent->len;
345 }
f18567db Carlos R. Mafra2009-08-18 00:30:17 +0200346}
9d2e6ef9 scottc1998-09-29 22:36:29 +0000347
348/*
349 *----------------------------------------------------------------------
350 * EventLoop-
351 * Processes X and internal events indefinitely.
6830b057 dan2004-10-12 21:28:27 +0000352 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000353 * Returns:
354 * Never returns
6830b057 dan2004-10-12 21:28:27 +0000355 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000356 * Side effects:
357 * The LastTimestamp global variable is updated.
56d85687 Rodney Padgett2008-08-09 11:39:24 +0100358 * Calls inotifyGetEvents if defaults database changes.
6830b057 dan2004-10-12 21:28:27 +0000359 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000360 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200361void EventLoop()
9d2e6ef9 scottc1998-09-29 22:36:29 +0000362{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200363 XEvent event;
364 extern int inotifyFD;
365 extern int inotifyWD;
366 struct timeval time;
367 fd_set rfds;
368 int retVal = 0;
369
370 if (inotifyFD < 0 || inotifyWD < 0)
371 retVal = -1;
372
373 for (;;) {
374
375 WMNextEvent(dpy, &event); /* Blocks here */
376 WMHandleEvent(&event);
377
378 if (retVal != -1) {
379 time.tv_sec = 0;
380 time.tv_usec = 0;
381 FD_ZERO(&rfds);
382 FD_SET(inotifyFD, &rfds);
383
384 /* check for available read data from inotify - don't block! */
385 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
386
387 if (retVal < 0) { /* an error has occured */
388 wwarning(_("select failed. The inotify instance will be closed."
389 " Changes to the defaults database will require"
390 " a restart to take effect."));
391 close(inotifyFD);
392 continue;
393 }
394 if (FD_ISSET(inotifyFD, &rfds))
395 inotifyHandleEvents(inotifyFD, inotifyWD);
396 }
397 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000398}
399
9aca0d5f dan2004-10-12 01:34:32 +0000400/*
401 *----------------------------------------------------------------------
402 * ProcessPendingEvents --
403 * Processes the events that are currently pending (at the time
404 * this function is called) in the display's queue.
405 *
406 * Returns:
407 * After the pending events that were present at the function call
408 * are processed.
409 *
410 * Side effects:
6830b057 dan2004-10-12 21:28:27 +0000411 * Many -- whatever handling events may involve.
9aca0d5f dan2004-10-12 01:34:32 +0000412 *
413 *----------------------------------------------------------------------
414 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200415void ProcessPendingEvents()
9aca0d5f dan2004-10-12 01:34:32 +0000416{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200417 XEvent event;
418 int count;
9aca0d5f dan2004-10-12 01:34:32 +0000419
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200420 XSync(dpy, False);
9aca0d5f dan2004-10-12 01:34:32 +0000421
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200422 /* Take a snapshot of the event count in the queue */
423 count = XPending(dpy);
9aca0d5f dan2004-10-12 01:34:32 +0000424
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200425 while (count > 0 && XPending(dpy)) {
426 WMNextEvent(dpy, &event);
427 WMHandleEvent(&event);
428 count--;
429 }
9aca0d5f dan2004-10-12 01:34:32 +0000430}
431
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200432Bool IsDoubleClick(WScreen * scr, XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000433{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200434 if ((scr->last_click_time > 0) &&
435 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
436 && (event->xbutton.button == scr->last_click_button)
437 && (event->xbutton.window == scr->last_click_window)) {
438
439 scr->flags.next_click_is_not_double = 1;
440 scr->last_click_time = 0;
441 scr->last_click_window = event->xbutton.window;
442
443 return True;
444 }
445 return False;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000446}
447
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200448void NotifyDeadProcess(pid_t pid, unsigned char status)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000449{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200450 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
451 wwarning("stack overflow: too many dead processes");
452 return;
453 }
454 /* stack the process to be handled later,
455 * as this is called from the signal handler */
456 deadProcesses[deadProcessPtr].pid = pid;
457 deadProcesses[deadProcessPtr].exit_status = status;
458 deadProcessPtr++;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000459}
460
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200461static void handleDeadProcess(void *foo)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000462{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200463 DeathHandler *tmp;
464 int i;
465
466 for (i = 0; i < deadProcessPtr; i++) {
467 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
468 }
469
470 if (!deathHandlers) {
471 deadProcessPtr = 0;
472 return;
473 }
474
475 /* get the pids on the queue and call handlers */
476 while (deadProcessPtr > 0) {
477 deadProcessPtr--;
478
479 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
480 tmp = WMGetFromArray(deathHandlers, i);
481 if (!tmp)
482 continue;
483
484 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
485 (*tmp->callback) (tmp->pid,
486 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
487 wDeleteDeathHandler(tmp);
488 }
489 }
490 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000491}
492
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200493static void saveTimestamp(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000494{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200495 /*
496 * Never save CurrentTime as LastTimestamp because CurrentTime
497 * it's not a real timestamp (it's the 0L constant)
498 */
499
500 switch (event->type) {
501 case ButtonRelease:
502 case ButtonPress:
503 LastTimestamp = event->xbutton.time;
504 break;
505 case KeyPress:
506 case KeyRelease:
507 LastTimestamp = event->xkey.time;
508 break;
509 case MotionNotify:
510 LastTimestamp = event->xmotion.time;
511 break;
512 case PropertyNotify:
513 LastTimestamp = event->xproperty.time;
514 break;
515 case EnterNotify:
516 case LeaveNotify:
517 LastTimestamp = event->xcrossing.time;
518 break;
519 case SelectionClear:
520 LastTimestamp = event->xselectionclear.time;
521 break;
522 case SelectionRequest:
523 LastTimestamp = event->xselectionrequest.time;
524 break;
525 case SelectionNotify:
526 LastTimestamp = event->xselection.time;
d4025072 id1999-05-17 20:21:43 +0000527#ifdef XDND
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200528 wXDNDProcessSelection(event);
d4025072 id1999-05-17 20:21:43 +0000529#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200530 break;
531 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000532}
533
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200534static int matchWindow(void *item, void *cdata)
90c77b1a dan2001-12-17 14:46:31 +0000535{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200536 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
90c77b1a dan2001-12-17 14:46:31 +0000537}
538
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200539static void handleExtensions(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000540{
6830b057 dan2004-10-12 21:28:27 +0000541#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200542 XkbEvent *xkbevent;
543 xkbevent = (XkbEvent *) event;
544#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000545#ifdef SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200546 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
547 handleShapeNotify(event);
548 }
6830b057 dan2004-10-12 21:28:27 +0000549#endif
550#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200551 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
552 handleXkbIndicatorStateNotify(event);
553 }
554#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000555}
556
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200557static void handleMapRequest(XEvent * ev)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000558{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200559 WWindow *wwin;
560 WScreen *scr = NULL;
561 Window window = ev->xmaprequest.window;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000562
563#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200564 printf("got map request for %x\n", (unsigned)window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000565#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200566 if ((wwin = wWindowFor(window))) {
567 if (wwin->flags.shaded) {
568 wUnshadeWindow(wwin);
569 }
570 /* deiconify window */
571 if (wwin->flags.miniaturized) {
572 wDeiconifyWindow(wwin);
573 } else if (wwin->flags.hidden) {
574 WApplication *wapp = wApplicationOf(wwin->main_window);
575 /* go to the last workspace that the user worked on the app */
576 if (wapp) {
577 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
578 }
579 wUnhideApplication(wapp, False, False);
580 }
581 return;
582 }
583
584 scr = wScreenForRootWindow(ev->xmaprequest.parent);
585
586 wwin = wManageWindow(scr, window);
587
588 /*
589 * This is to let the Dock know that the application it launched
590 * has already been mapped (eg: it has finished launching).
591 * It is not necessary for normally docked apps, but is needed for
592 * apps that were forcedly docked (like with dockit).
593 */
594 if (scr->last_dock) {
595 if (wwin && wwin->main_window != None && wwin->main_window != window)
596 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
597 else
598 wDockTrackWindowLaunch(scr->last_dock, window);
599 }
600
601 if (wwin) {
602 wClientSetState(wwin, NormalState, None);
603 if (wwin->flags.maximized) {
604 wMaximizeWindow(wwin, wwin->flags.maximized);
605 }
606 if (wwin->flags.shaded) {
607 wwin->flags.shaded = 0;
608 wwin->flags.skip_next_animation = 1;
609 wShadeWindow(wwin);
610 }
611 if (wwin->flags.miniaturized) {
612 wwin->flags.miniaturized = 0;
613 wwin->flags.skip_next_animation = 1;
614 wIconifyWindow(wwin);
615 }
616 if (wwin->flags.fullscreen) {
617 wwin->flags.fullscreen = 0;
618 wFullscreenWindow(wwin);
619 }
620 if (wwin->flags.hidden) {
621 WApplication *wapp = wApplicationOf(wwin->main_window);
622
623 wwin->flags.hidden = 0;
624 wwin->flags.skip_next_animation = 1;
625 if (wapp) {
626 wHideApplication(wapp);
627 }
628 }
629 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000630}
631
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200632static void handleDestroyNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000633{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200634 WWindow *wwin;
635 WApplication *app;
636 Window window = event->xdestroywindow.window;
637 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
638 int widx;
0261c326 dan1999-01-06 15:22:33 +0000639
9d2e6ef9 scottc1998-09-29 22:36:29 +0000640#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200641 printf("got destroy notify\n");
eb87c409 kojima1999-10-20 03:25:06 +0000642#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200643 wwin = wWindowFor(window);
644 if (wwin) {
645 wUnmanageWindow(wwin, False, True);
646 }
647
648 if (scr != NULL) {
649 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
650 WFakeGroupLeader *fPtr;
651
652 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
653 if (fPtr->retainCount > 0) {
654 fPtr->retainCount--;
655 if (fPtr->retainCount == 0 && fPtr->leader != None) {
656 XDestroyWindow(dpy, fPtr->leader);
657 fPtr->leader = None;
658 XFlush(dpy);
659 }
660 }
661 fPtr->origLeader = None;
662 }
663 }
664
665 app = wApplicationOf(window);
666 if (app) {
667 if (window == app->main_window) {
668 app->refcount = 0;
669 wwin = app->main_window_desc->screen_ptr->focused_window;
670 while (wwin) {
671 if (wwin->main_window == window) {
672 wwin->main_window = None;
673 }
674 wwin = wwin->prev;
675 }
676 }
677 wApplicationDestroy(app);
678 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000679}
680
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200681static void handleExpose(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000682{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200683 WObjDescriptor *desc;
684 XEvent ev;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000685
eb87c409 kojima1999-10-20 03:25:06 +0000686#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200687 printf("got expose\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000688#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200689 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
e7495baf dan1999-02-17 11:06:40 +0000690
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200691 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
692 return;
693 }
6830b057 dan2004-10-12 21:28:27 +0000694
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200695 if (desc->handle_expose) {
696 (*desc->handle_expose) (desc, event);
697 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000698}
699
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200700static void executeButtonAction(WScreen * scr, XEvent * event, int action)
3bde6495 dan2001-04-27 23:41:17 +0000701{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200702 switch (action) {
703 case WA_SELECT_WINDOWS:
704 wUnselectWindows(scr);
705 wSelectWindows(scr, event);
706 break;
707 case WA_OPEN_APPMENU:
708 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
709 /* ugly hack */
710 if (scr->root_menu) {
711 if (scr->root_menu->brother->flags.mapped)
712 event->xbutton.window = scr->root_menu->brother->frame->core->window;
713 else
714 event->xbutton.window = scr->root_menu->frame->core->window;
715 }
716 break;
717 case WA_OPEN_WINLISTMENU:
718 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
719 if (scr->switch_menu) {
720 if (scr->switch_menu->brother->flags.mapped)
721 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
722 else
723 event->xbutton.window = scr->switch_menu->frame->core->window;
724 }
725 break;
726 default:
727 break;
728 }
3bde6495 dan2001-04-27 23:41:17 +0000729}
730
9d2e6ef9 scottc1998-09-29 22:36:29 +0000731/* bindable */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200732static void handleButtonPress(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000733{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200734 WObjDescriptor *desc;
735 WScreen *scr;
6830b057 dan2004-10-12 21:28:27 +0000736
eb87c409 kojima1999-10-20 03:25:06 +0000737#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200738 printf("got button press\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000739#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200740 scr = wScreenForRootWindow(event->xbutton.root);
6830b057 dan2004-10-12 21:28:27 +0000741
9d2e6ef9 scottc1998-09-29 22:36:29 +0000742#ifdef BALLOON_TEXT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200743 wBalloonHide(scr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000744#endif
745
0261c326 dan1999-01-06 15:22:33 +0000746#ifndef LITE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200747 if (event->xbutton.window == scr->root_win) {
748 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
749 executeButtonAction(scr, event, wPreferences.mouse_button1);
750 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
751 executeButtonAction(scr, event, wPreferences.mouse_button2);
752 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
753 executeButtonAction(scr, event, wPreferences.mouse_button3);
754 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
755 wWorkspaceRelativeChange(scr, 1);
756 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
757 wWorkspaceRelativeChange(scr, -1);
758 }
759 }
760#endif /* !LITE */
761
762 desc = NULL;
763 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
764 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
765 return;
766 }
767 }
768
769 if (desc->parent_type == WCLASS_WINDOW) {
770 XSync(dpy, 0);
771
772 if (event->xbutton.state & MOD_MASK) {
773 XAllowEvents(dpy, AsyncPointer, CurrentTime);
774 }
775
776 /* if (wPreferences.focus_mode == WKF_CLICK) { */
777 if (wPreferences.ignore_focus_click) {
778 XAllowEvents(dpy, AsyncPointer, CurrentTime);
779 }
780 XAllowEvents(dpy, ReplayPointer, CurrentTime);
781 /* } */
782 XSync(dpy, 0);
783 } else if (desc->parent_type == WCLASS_APPICON
784 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
785 if (event->xbutton.state & MOD_MASK) {
786 XSync(dpy, 0);
787 XAllowEvents(dpy, AsyncPointer, CurrentTime);
788 XSync(dpy, 0);
789 }
790 }
791
792 if (desc->handle_mousedown != NULL) {
793 (*desc->handle_mousedown) (desc, event);
794 }
795
796 /* save double-click information */
797 if (scr->flags.next_click_is_not_double) {
798 scr->flags.next_click_is_not_double = 0;
799 } else {
800 scr->last_click_time = event->xbutton.time;
801 scr->last_click_button = event->xbutton.button;
802 scr->last_click_window = event->xbutton.window;
803 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000804}
805
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200806static void handleMapNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000807{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200808 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000809#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200810 printf("got map\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000811#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200812 wwin = wWindowFor(event->xmap.event);
813 if (wwin && wwin->client_win == event->xmap.event) {
814 if (wwin->flags.miniaturized) {
815 wDeiconifyWindow(wwin);
816 } else {
817 XGrabServer(dpy);
818 wWindowMap(wwin);
819 wClientSetState(wwin, NormalState, None);
820 XUngrabServer(dpy);
821 }
822 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000823}
824
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200825static void handleUnmapNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000826{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200827 WWindow *wwin;
828 XEvent ev;
829 Bool withdraw = False;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000830#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200831 printf("got unmap\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000832#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200833 /* only process windows with StructureNotify selected
834 * (ignore SubstructureNotify) */
835 wwin = wWindowFor(event->xunmap.window);
836 if (!wwin)
837 return;
838
839 /* whether the event is a Withdrawal request */
840 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
841 withdraw = True;
842
843 if (wwin->client_win != event->xunmap.event && !withdraw)
844 return;
845
846 if (!wwin->flags.mapped && !withdraw
847 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
848 && !wwin->flags.miniaturized && !wwin->flags.hidden)
849 return;
850
851 XGrabServer(dpy);
852 XUnmapWindow(dpy, wwin->frame->core->window);
853 wwin->flags.mapped = 0;
854 XSync(dpy, 0);
855 /* check if the window was destroyed */
856 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
857 DispatchEvent(&ev);
858 } else {
859 Bool reparented = False;
860
861 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
862 reparented = True;
863
864 /* withdraw window */
865 wwin->flags.mapped = 0;
866 if (!reparented)
867 wClientSetState(wwin, WithdrawnState, None);
868
869 /* if the window was reparented, do not reparent it back to the
870 * root window */
871 wUnmanageWindow(wwin, !reparented, False);
872 }
873 XUngrabServer(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000874}
875
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200876static void handleConfigureRequest(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000877{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200878 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000879#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200880 printf("got configure request\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000881#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200882 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
883 /*
884 * Configure request for unmapped window
885 */
886 wClientConfigure(NULL, &(event->xconfigurerequest));
887 } else {
888 wClientConfigure(wwin, &(event->xconfigurerequest));
889 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000890}
891
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200892static void handlePropertyNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000893{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200894 WWindow *wwin;
895 WApplication *wapp;
896 Window jr;
897 int ji;
898 unsigned int ju;
899 WScreen *scr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000900#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200901 printf("got property notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000902#endif
6b08fc9e Carlos R. Mafra2009-08-08 23:37:27 +0200903
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200904 wwin = wWindowFor(event->xproperty.window);
905 if (wwin) {
906 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
907 return;
908 }
909 wClientCheckProperty(wwin, &event->xproperty);
910 }
911 wapp = wApplicationOf(event->xproperty.window);
912 if (wapp) {
913 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
914 }
915
916 scr = wScreenForWindow(event->xproperty.window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000917}
918
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200919static void handleClientMessage(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000920{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200921 WWindow *wwin;
922 WObjDescriptor *desc;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000923#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200924 printf("got client message\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000925#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200926 /* handle transition from Normal to Iconic state */
927 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
928 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
929
930 wwin = wWindowFor(event->xclient.window);
931 if (!wwin)
932 return;
933 if (!wwin->flags.miniaturized)
934 wIconifyWindow(wwin);
935 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
936 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
937
938 if (!scr)
939 return;
940
941 if (event->xclient.data.l[1] == 1) { /* starting */
942 wColormapAllowClientInstallation(scr, True);
943 } else { /* stopping */
944 wColormapAllowClientInstallation(scr, False);
945 }
946 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
947
948 wDefaultsCheckDomains();
949
950 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
951 WApplication *wapp;
952 int done = 0;
953 wapp = wApplicationOf(event->xclient.window);
954 if (wapp) {
955 switch (event->xclient.data.l[0]) {
956 case WMFHideOtherApplications:
957 wHideOtherApplications(wapp->main_window_desc);
958 done = 1;
959 break;
960
961 case WMFHideApplication:
962 wHideApplication(wapp);
963 done = 1;
964 break;
965 }
966 }
967 if (!done) {
968 wwin = wWindowFor(event->xclient.window);
969 if (wwin) {
970 switch (event->xclient.data.l[0]) {
971 case WMFHideOtherApplications:
972 wHideOtherApplications(wwin);
973 break;
974
975 case WMFHideApplication:
976 wHideApplication(wApplicationOf(wwin->main_window));
977 break;
978 }
979 }
980 }
981 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
982 wwin = wWindowFor(event->xclient.window);
983 if (!wwin)
984 return;
985 switch (event->xclient.data.l[0]) {
986 case GSWindowLevelAttr:
987 {
988 int level = (int)event->xclient.data.l[1];
989
990 if (WINDOW_LEVEL(wwin) != level) {
991 ChangeStackingLevel(wwin->frame->core, level);
992 }
993 }
994 break;
995 }
996 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
997 wwin = wWindowFor(event->xclient.window);
998 if (!wwin)
999 return;
1000 switch (event->xclient.data.l[0]) {
1001 case WMTitleBarNormal:
1002 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1003 break;
1004 case WMTitleBarMain:
1005 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1006 break;
1007 case WMTitleBarKey:
1008 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1009 break;
1010 }
9aca0d5f dan2004-10-12 01:34:32 +00001011#ifdef NETWM_HINTS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001012 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1013 /* do nothing */
9aca0d5f dan2004-10-12 01:34:32 +00001014#endif
d4025072 id1999-05-17 20:21:43 +00001015#ifdef XDND
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001016 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1017 /* do nothing */
1018#endif /* XDND */
1019 } else {
1020 /*
1021 * Non-standard thing, but needed by OffiX DND.
1022 * For when the icon frame gets a ClientMessage
1023 * that should have gone to the icon_window.
1024 */
1025 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1026 struct WIcon *icon = NULL;
1027
1028 if (desc->parent_type == WCLASS_MINIWINDOW) {
1029 icon = (WIcon *) desc->parent;
1030 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1031 icon = ((WAppIcon *) desc->parent)->icon;
1032 }
1033 if (icon && (wwin = icon->owner)) {
1034 if (wwin->client_win != event->xclient.window) {
1035 event->xclient.window = wwin->client_win;
1036 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1037 }
1038 }
1039 }
1040 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001041}
1042
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001043static void raiseWindow(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001044{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001045 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001046
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001047 scr->autoRaiseTimer = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001049 wwin = wWindowFor(scr->autoRaiseWindow);
1050 if (!wwin)
1051 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001052
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001053 if (!wwin->flags.destroyed && wwin->flags.focused) {
1054 wRaiseFrame(wwin->frame->core);
1055 /* this is needed or a race condition will occur */
1056 XSync(dpy, False);
1057 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001058}
1059
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001060static void handleEnterNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001061{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001062 WWindow *wwin;
1063 WObjDescriptor *desc = NULL;
9aca0d5f dan2004-10-12 01:34:32 +00001064#ifdef VIRTUAL_DESKTOP
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001065 void (*vdHandler) (XEvent * event);
9aca0d5f dan2004-10-12 01:34:32 +00001066#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001067 XEvent ev;
1068 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001069#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001070 printf("got enter notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001071#endif
8eb0c79c id1999-12-18 11:52:49 +00001072
1073#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001074 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext, (XPointer *) & vdHandler) != XCNOENT) {
1075 (*vdHandler) (event);
1076 }
8eb0c79c id1999-12-18 11:52:49 +00001077#endif
1078
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001079 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1080 /* already left the window... */
1081 saveTimestamp(&ev);
1082 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1083 return;
1084 }
1085 }
1086
1087 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1088 if (desc->handle_enternotify)
1089 (*desc->handle_enternotify) (desc, event);
1090 }
1091
1092 /* enter to window */
1093 wwin = wWindowFor(event->xcrossing.window);
1094 if (!wwin) {
1095 if (wPreferences.colormap_mode == WCM_POINTER) {
1096 wColormapInstallForWindow(scr, NULL);
1097 }
1098 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1099 WMDeleteTimerHandler(scr->autoRaiseTimer);
1100 scr->autoRaiseTimer = NULL;
1101 }
1102 } else {
1103 /* set auto raise timer even if in focus-follows-mouse mode
1104 * and the event is for the frame window, even if the window
1105 * has focus already. useful if you move the pointer from a focused
1106 * window to the root window and back pretty fast
1107 *
1108 * set focus if in focus-follows-mouse mode and the event
1109 * is for the frame window and window doesn't have focus yet */
1110 if (wPreferences.focus_mode == WKF_SLOPPY
1111 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1112
1113 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1114 wSetFocusTo(scr, wwin);
1115
1116 if (scr->autoRaiseTimer)
1117 WMDeleteTimerHandler(scr->autoRaiseTimer);
1118 scr->autoRaiseTimer = NULL;
1119
1120 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1121 scr->autoRaiseWindow = wwin->frame->core->window;
1122 scr->autoRaiseTimer
1123 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1124 }
1125 }
1126 /* Install colormap for window, if the colormap installation mode
1127 * is colormap_follows_mouse */
1128 if (wPreferences.colormap_mode == WCM_POINTER) {
1129 if (wwin->client_win == event->xcrossing.window)
1130 wColormapInstallForWindow(scr, wwin);
1131 else
1132 wColormapInstallForWindow(scr, NULL);
1133 }
1134 }
1135
1136 /* a little kluge to hide the clip balloon */
1137 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1138 if (!desc) {
1139 XUnmapWindow(dpy, scr->clip_balloon);
1140 scr->flags.clip_balloon_mapped = 0;
1141 } else {
1142 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1143 XUnmapWindow(dpy, scr->clip_balloon);
1144 scr->flags.clip_balloon_mapped = 0;
1145 }
1146 }
1147 }
1148
1149 if (event->xcrossing.window == event->xcrossing.root
1150 && event->xcrossing.detail == NotifyNormal
1151 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1152
1153 wSetFocusTo(scr, scr->focused_window);
1154 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001155#ifdef BALLOON_TEXT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001156 wBalloonEnteredObject(scr, desc);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001157#endif
1158}
1159
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001160static void handleLeaveNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001161{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001162 WObjDescriptor *desc = NULL;
34cd5125 kojima2000-01-20 11:51:42 +00001163
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001164 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1165 if (desc->handle_leavenotify)
1166 (*desc->handle_leavenotify) (desc, event);
1167 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001168}
1169
9d2e6ef9 scottc1998-09-29 22:36:29 +00001170#ifdef SHAPE
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001171static void handleShapeNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001172{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001173 XShapeEvent *shev = (XShapeEvent *) event;
1174 WWindow *wwin;
1175 XEvent ev;
652caa1f dan1999-10-21 00:54:37 +00001176#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001177 printf("got shape notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001178#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001179 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1180 XShapeEvent *sev = (XShapeEvent *) & ev;
6830b057 dan2004-10-12 21:28:27 +00001181
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001182 if (sev->kind == ShapeBounding) {
1183 if (sev->shaped == shev->shaped) {
1184 *shev = *sev;
1185 } else {
1186 XPutBackEvent(dpy, &ev);
1187 break;
1188 }
1189 }
1190 }
9af1c6c4 dan1998-10-21 14:43:47 +00001191
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001192 wwin = wWindowFor(shev->window);
1193 if (!wwin || shev->kind != ShapeBounding)
1194 return;
9af1c6c4 dan1998-10-21 14:43:47 +00001195
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001196 if (!shev->shaped && wwin->flags.shaped) {
9af1c6c4 dan1998-10-21 14:43:47 +00001197
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001198 wwin->flags.shaped = 0;
1199 wWindowClearShape(wwin);
9af1c6c4 dan1998-10-21 14:43:47 +00001200
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001201 } else if (shev->shaped) {
9af1c6c4 dan1998-10-21 14:43:47 +00001202
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001203 wwin->flags.shaped = 1;
1204 wWindowSetShape(wwin);
1205 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001206}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001207#endif /* SHAPE */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001208
6830b057 dan2004-10-12 21:28:27 +00001209#ifdef KEEP_XKB_LOCK_STATUS
7f9f8894 kojima1999-03-15 23:41:22 +00001210/* please help ]d if you know what to do */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001211handleXkbIndicatorStateNotify(XEvent * event)
7f9f8894 kojima1999-03-15 23:41:22 +00001212{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001213 WWindow *wwin;
1214 WScreen *scr;
1215 XkbStateRec staterec;
1216 int i;
1217
1218 for (i = 0; i < wScreenCount; i++) {
1219 scr = wScreenWithNumber(i);
1220 wwin = scr->focused_window;
1221 if (wwin && wwin->flags.focused) {
1222 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1223 if (wwin->frame->languagemode != staterec.group) {
1224 wwin->frame->last_languagemode = wwin->frame->languagemode;
1225 wwin->frame->languagemode = staterec.group;
1226 }
c28f3b2c id1999-05-20 23:30:53 +00001227#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001228 if (wwin->frame->titlebar) {
1229 wFrameWindowPaint(wwin->frame);
1230 }
c28f3b2c id1999-05-20 23:30:53 +00001231#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001232 }
1233 }
7f9f8894 kojima1999-03-15 23:41:22 +00001234}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001235#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001236
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001237static void handleColormapNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001238{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001239 WWindow *wwin;
1240 WScreen *scr;
1241 Bool reinstall = False;
1242
1243 wwin = wWindowFor(event->xcolormap.window);
1244 if (!wwin)
1245 return;
1246
1247 scr = wwin->screen_ptr;
1248
1249 do {
1250 if (wwin) {
1251 if (event->xcolormap.new) {
1252 XWindowAttributes attr;
1253
1254 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1255
1256 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1257 scr->current_colormap = attr.colormap;
1258
1259 reinstall = True;
1260 } else if (event->xcolormap.state == ColormapUninstalled &&
1261 scr->current_colormap == event->xcolormap.colormap) {
1262
1263 /* some bastard app (like XV) removed our colormap */
1264 /*
1265 * can't enforce or things like xscreensaver wont work
1266 * reinstall = True;
1267 */
1268 } else if (event->xcolormap.state == ColormapInstalled &&
1269 scr->current_colormap == event->xcolormap.colormap) {
1270
1271 /* someone has put our colormap back */
1272 reinstall = False;
1273 }
1274 }
1275 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1276 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1277
1278 if (reinstall && scr->current_colormap != None) {
1279 if (!scr->flags.colormap_stuff_blocked)
1280 XInstallColormap(dpy, scr->current_colormap);
1281 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001282}
1283
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001284static void handleFocusIn(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001285{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001286 WWindow *wwin;
1287
1288 /*
1289 * For applications that like stealing the focus.
1290 */
1291 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1292 saveTimestamp(event);
1293 if (event->xfocus.mode == NotifyUngrab
1294 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1295 return;
1296 }
1297
1298 wwin = wWindowFor(event->xfocus.window);
1299 if (wwin && !wwin->flags.focused) {
1300 if (wwin->flags.mapped)
1301 wSetFocusTo(wwin->screen_ptr, wwin);
1302 else
1303 wSetFocusTo(wwin->screen_ptr, NULL);
1304 } else if (!wwin) {
1305 WScreen *scr = wScreenForWindow(event->xfocus.window);
1306 if (scr)
1307 wSetFocusTo(scr, NULL);
1308 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001309}
1310
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001311static WWindow *windowUnderPointer(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001312{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001313 unsigned int mask;
1314 int foo;
1315 Window bar, win;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001316
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001317 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1318 return wWindowFor(win);
1319 return NULL;
1320}
3c046182 kojima1999-09-16 02:58:56 +00001321
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001322static int CheckFullScreenWindowFocused(WScreen * scr)
30247c58 kojima2004-10-18 01:43:13 +00001323{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001324 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1325 return 1;
1326 else
1327 return 0;
30247c58 kojima2004-10-18 01:43:13 +00001328}
3c046182 kojima1999-09-16 02:58:56 +00001329
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001330static void handleKeyPress(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001331{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001332 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1333 WWindow *wwin = scr->focused_window;
1334 short i, widx;
1335 int modifiers;
1336 int command = -1;
6830b057 dan2004-10-12 21:28:27 +00001337#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001338 XkbStateRec staterec;
1339#endif /*KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001340
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001341 /* ignore CapsLock */
1342 modifiers = event->xkey.state & ValidModMask;
6830b057 dan2004-10-12 21:28:27 +00001343
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001344 for (i = 0; i < WKBD_LAST; i++) {
1345 if (wKeyBindings[i].keycode == 0)
1346 continue;
9e615bcf dan2001-12-28 03:29:50 +00001347
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001348 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1349 || */ wKeyBindings[i].modifier ==
1350 modifiers)) {
1351 command = i;
1352 break;
1353 }
1354 }
9e615bcf dan2001-12-28 03:29:50 +00001355
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001356 if (command < 0) {
0261c326 dan1999-01-06 15:22:33 +00001357#ifdef LITE
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001358 {
0261c326 dan1999-01-06 15:22:33 +00001359#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001360 }
0261c326 dan1999-01-06 15:22:33 +00001361#endif
1362#else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001363 if (!wRootMenuPerformShortcut(event)) {
0261c326 dan1999-01-06 15:22:33 +00001364#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001365 static int dontLoop = 0;
1366
1367 if (dontLoop > 10) {
1368 wwarning("problem with key event processing code");
1369 return;
1370 }
1371 dontLoop++;
1372 /* if the focused window is an internal window, try redispatching
1373 * the event to the managed window, as it can be a WINGs window */
1374 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1375 /* client_leader contains the WINGs toplevel */
1376 event->xany.window = wwin->client_leader;
1377 WMHandleEvent(event);
1378 }
1379 dontLoop--;
1380 }
1381 return;
1382 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001383#define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1384#define ISFOCUSED(w) ((w) && (w)->flags.focused)
1385
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001386 switch (command) {
0261c326 dan1999-01-06 15:22:33 +00001387#ifndef LITE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001388 case WKBD_ROOTMENU:
1389 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1390 if (!CheckFullScreenWindowFocused(scr)) {
1391 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1392 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1393 True);
1394 }
1395 break;
1396 case WKBD_WINDOWLIST:
1397 if (!CheckFullScreenWindowFocused(scr)) {
1398 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1399 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1400 True);
1401 }
1402 break;
1403#endif /* !LITE */
1404 case WKBD_WINDOWMENU:
1405 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1406 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1407 break;
1408 case WKBD_MINIATURIZE:
1409 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1410 && !WFLAGP(wwin, no_miniaturizable)) {
1411 CloseWindowMenu(scr);
1412
1413 if (wwin->protocols.MINIATURIZE_WINDOW)
1414 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1415 else {
1416 wIconifyWindow(wwin);
1417 }
1418 }
1419 break;
1420 case WKBD_HIDE:
1421 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1422 WApplication *wapp = wApplicationOf(wwin->main_window);
1423 CloseWindowMenu(scr);
1424
1425 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1426 wHideApplication(wapp);
1427 }
1428 }
1429 break;
1430 case WKBD_HIDE_OTHERS:
1431 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1432 CloseWindowMenu(scr);
1433
1434 wHideOtherApplications(wwin);
1435 }
1436 break;
1437 case WKBD_MAXIMIZE:
1438 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1439 int newdir = (MAX_VERTICAL | MAX_HORIZONTAL);
1440
1441 CloseWindowMenu(scr);
1442
1443 if (wwin->flags.maximized == newdir) {
1444 wUnmaximizeWindow(wwin);
1445 } else {
1446 wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
1447 }
1448 }
1449 break;
1450 case WKBD_VMAXIMIZE:
1451 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1452 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1453
1454 CloseWindowMenu(scr);
1455
1456 if (newdir) {
1457 wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
1458 } else {
1459 wUnmaximizeWindow(wwin);
1460 }
1461 }
1462 break;
1463 case WKBD_HMAXIMIZE:
1464 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1465 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1466
1467 CloseWindowMenu(scr);
1468
1469 if (newdir) {
1470 wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
1471 } else {
1472 wUnmaximizeWindow(wwin);
1473 }
1474 }
1475 break;
1476 case WKBD_RAISE:
1477 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1478 CloseWindowMenu(scr);
1479
1480 wRaiseFrame(wwin->frame->core);
1481 }
1482 break;
1483 case WKBD_LOWER:
1484 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1485 CloseWindowMenu(scr);
1486
1487 wLowerFrame(wwin->frame->core);
1488 }
1489 break;
1490 case WKBD_RAISELOWER:
1491 /* raise or lower the window under the pointer, not the
1492 * focused one
1493 */
1494 wwin = windowUnderPointer(scr);
1495 if (wwin)
1496 wRaiseLowerFrame(wwin->frame->core);
1497 break;
1498 case WKBD_SHADE:
1499 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1500 if (wwin->flags.shaded)
1501 wUnshadeWindow(wwin);
1502 else
1503 wShadeWindow(wwin);
1504 }
1505 break;
1506 case WKBD_MOVERESIZE:
1507 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1508 CloseWindowMenu(scr);
1509
1510 wKeyboardMoveResizeWindow(wwin);
1511 }
1512 break;
1513 case WKBD_CLOSE:
1514 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1515 CloseWindowMenu(scr);
1516 if (wwin->protocols.DELETE_WINDOW)
1517 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1518 }
1519 break;
1520 case WKBD_SELECT:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1522 wSelectWindow(wwin, !wwin->flags.selected);
1523 }
1524 break;
1525 case WKBD_FOCUSNEXT:
1526 StartWindozeCycle(wwin, event, True);
1527 break;
1528
1529 case WKBD_FOCUSPREV:
1530 StartWindozeCycle(wwin, event, False);
1531 break;
1532
1533 case WKBD_WORKSPACE1...WKBD_WORKSPACE10:
1534 widx = command - WKBD_WORKSPACE1;
1535 i = (scr->current_workspace / 10) * 10 + widx;
1536 if (wPreferences.ws_advance || i < scr->workspace_count)
1537 wWorkspaceChange(scr, i);
1538 break;
1539
1540 case WKBD_NEXTWORKSPACE:
1541 wWorkspaceRelativeChange(scr, 1);
1542 break;
1543 case WKBD_PREVWORKSPACE:
1544 wWorkspaceRelativeChange(scr, -1);
1545 break;
1546 case WKBD_WINDOW1:
1547 case WKBD_WINDOW2:
1548 case WKBD_WINDOW3:
1549 case WKBD_WINDOW4:
1550 case WKBD_WINDOW5:
1551 case WKBD_WINDOW6:
1552 case WKBD_WINDOW7:
1553 case WKBD_WINDOW8:
1554 case WKBD_WINDOW9:
1555 case WKBD_WINDOW10:
1556
1557 widx = command - WKBD_WINDOW1;
1558
1559 if (scr->shortcutWindows[widx]) {
1560 WMArray *list = scr->shortcutWindows[widx];
1561 int cw;
1562 int count = WMGetArrayItemCount(list);
1563 WWindow *twin;
1564 WMArrayIterator iter;
1565 WWindow *wwin;
1566
1567 wUnselectWindows(scr);
1568 cw = scr->current_workspace;
1569
1570 WM_ETARETI_ARRAY(list, wwin, iter) {
1571 if (count > 1)
1572 wWindowChangeWorkspace(wwin, cw);
1573
1574 wMakeWindowVisible(wwin);
1575
1576 if (count > 1)
1577 wSelectWindow(wwin, True);
1578 }
1579
1580 /* rotate the order of windows, to create a cycling effect */
1581 twin = WMGetFromArray(list, 0);
1582 WMDeleteFromArray(list, 0);
1583 WMAddToArray(list, twin);
1584
1585 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1586 if (scr->shortcutWindows[widx]) {
1587 WMFreeArray(scr->shortcutWindows[widx]);
1588 scr->shortcutWindows[widx] = NULL;
1589 }
1590
1591 if (wwin->flags.selected && scr->selected_windows) {
1592 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1593 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1594 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1595 } else {
1596 scr->shortcutWindows[widx] = WMCreateArray(4);
1597 WMAddToArray(scr->shortcutWindows[widx], wwin);
1598 }
1599
1600 wSelectWindow(wwin, !wwin->flags.selected);
1601 XFlush(dpy);
1602 wusleep(3000);
1603 wSelectWindow(wwin, !wwin->flags.selected);
1604 XFlush(dpy);
1605
1606 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1607
1608 if (wwin->flags.selected && scr->selected_windows) {
1609 if (scr->shortcutWindows[widx]) {
1610 WMFreeArray(scr->shortcutWindows[widx]);
1611 }
1612 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1613 }
1614 }
1615
1616 break;
1617
1618 case WKBD_SWITCH_SCREEN:
1619 if (wScreenCount > 1) {
1620 WScreen *scr2;
1621 int i;
1622
1623 /* find index of this screen */
1624 for (i = 0; i < wScreenCount; i++) {
1625 if (wScreenWithNumber(i) == scr)
1626 break;
1627 }
1628 i++;
1629 if (i >= wScreenCount) {
1630 i = 0;
1631 }
1632 scr2 = wScreenWithNumber(i);
1633
1634 if (scr2) {
1635 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1636 scr2->scr_width / 2, scr2->scr_height / 2);
1637 }
1638 }
1639 break;
1640
1641 case WKBD_NEXTWSLAYER:
1642 case WKBD_PREVWSLAYER:
1643 {
1644 int row, column;
1645
1646 row = scr->current_workspace / 10;
1647 column = scr->current_workspace % 10;
1648
1649 if (command == WKBD_NEXTWSLAYER) {
1650 if ((row + 1) * 10 < scr->workspace_count)
1651 wWorkspaceChange(scr, column + (row + 1) * 10);
1652 } else {
1653 if (row > 0)
1654 wWorkspaceChange(scr, column + (row - 1) * 10);
1655 }
1656 }
1657 break;
1658 case WKBD_CLIPLOWER:
1659 if (!wPreferences.flags.noclip)
1660 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1661 break;
1662 case WKBD_CLIPRAISE:
1663 if (!wPreferences.flags.noclip)
1664 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1665 break;
1666 case WKBD_CLIPRAISELOWER:
1667 if (!wPreferences.flags.noclip)
1668 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1669 break;
59eb9475 dan1998-11-03 12:53:26 +00001670#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001671 case WKBD_TOGGLE:
1672 if (wPreferences.modelock) {
1673 /*toggle */
1674 wwin = scr->focused_window;
1675
1676 if (wwin && wwin->flags.mapped
1677 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1678 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1679 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1680
1681 wwin->frame->languagemode = wwin->frame->last_languagemode;
1682 wwin->frame->last_languagemode = staterec.group;
1683 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1684
1685 }
1686 }
1687 break;
1688#endif /* KEEP_XKB_LOCK_STATUS */
9aca0d5f dan2004-10-12 01:34:32 +00001689#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001690 case WKBD_VDESK_LEFT:
1691 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1692 break;
9aca0d5f dan2004-10-12 01:34:32 +00001693
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001694 case WKBD_VDESK_RIGHT:
1695 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1696 break;
9aca0d5f dan2004-10-12 01:34:32 +00001697
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001698 case WKBD_VDESK_UP:
1699 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1700 break;
9aca0d5f dan2004-10-12 01:34:32 +00001701
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001702 case WKBD_VDESK_DOWN:
1703 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1704 break;
9aca0d5f dan2004-10-12 01:34:32 +00001705#endif
59eb9475 dan1998-11-03 12:53:26 +00001706
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001707 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001708}
1709
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001710static void handleMotionNotify(XEvent * event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001711{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001712 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1713
1714 if (wPreferences.scrollable_menus) {
1715 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1716 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1717
1718 if (scr->flags.jump_back_pending ||
1719 p.x <= (rect.pos.x + 1) ||
1720 p.x >= (rect.pos.x + rect.size.width - 2) ||
1721 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1722 WMenu *menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001723#ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001724 printf("pointer at screen edge\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001725#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001726 menu = wMenuUnderPointer(scr);
1727 if (menu != NULL)
1728 wMenuScroll(menu, event);
1729 }
1730 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001731}
416e3a82 dan1999-01-25 19:06:50 +00001732
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001733static void handleVisibilityNotify(XEvent * event)
e7495baf dan1999-02-17 11:06:40 +00001734{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001735 WWindow *wwin;
e7495baf dan1999-02-17 11:06:40 +00001736
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001737 wwin = wWindowFor(event->xvisibility.window);
1738 if (!wwin)
1739 return;
1740 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);
e7495baf dan1999-02-17 11:06:40 +00001741}