Use inotify to check for changes to the defaults database. Workaround for
[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
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <unistd.h>
30#include <string.h>
31
eb87c409 kojima1999-10-20 03:25:06 +000032
33
9d2e6ef9 scottc1998-09-29 22:36:29 +000034#include <X11/Xlib.h>
35#include <X11/Xutil.h>
36#ifdef SHAPE
eb87c409 kojima1999-10-20 03:25:06 +000037# include <X11/extensions/shape.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000038#endif
d4025072 id1999-05-17 20:21:43 +000039#ifdef XDND
40#include "xdnd.h"
9af1c6c4 dan1998-10-21 14:43:47 +000041#endif
42
6830b057 dan2004-10-12 21:28:27 +000043#ifdef KEEP_XKB_LOCK_STATUS
44#include <X11/XKBlib.h>
59eb9475 dan1998-11-03 12:53:26 +000045#endif /* KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +000046
47#include "WindowMaker.h"
48#include "window.h"
49#include "actions.h"
50#include "client.h"
51#include "funcs.h"
52#include "keybind.h"
53#include "application.h"
54#include "stacking.h"
55#include "defaults.h"
56#include "workspace.h"
57#include "dock.h"
58#include "framewin.h"
59#include "properties.h"
60#include "balloon.h"
a10214a5 kojima2002-11-28 22:04:07 +000061#include "xinerama.h"
3c046182 kojima1999-09-16 02:58:56 +000062
9aca0d5f dan2004-10-12 01:34:32 +000063#ifdef NETWM_HINTS
64# include "wmspec.h"
65#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +000066
67/******** Global Variables **********/
68extern XContext wWinContext;
9aca0d5f dan2004-10-12 01:34:32 +000069extern XContext wVEdgeContext;
9d2e6ef9 scottc1998-09-29 22:36:29 +000070
71extern Cursor wCursor[WCUR_LAST];
72
73extern WShortKey wKeyBindings[WKBD_LAST];
74extern int wScreenCount;
75extern Time LastTimestamp;
76extern Time LastFocusChange;
77
78extern WPreferences wPreferences;
79
80#define MOD_MASK wPreferences.modifier_mask
81
59eb9475 dan1998-11-03 12:53:26 +000082extern Atom _XA_WM_COLORMAP_NOTIFY;
83
9d2e6ef9 scottc1998-09-29 22:36:29 +000084extern Atom _XA_WM_CHANGE_STATE;
85extern Atom _XA_WM_DELETE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +000086extern Atom _XA_GNUSTEP_WM_ATTR;
9af1c6c4 dan1998-10-21 14:43:47 +000087extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +000088extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
9d2e6ef9 scottc1998-09-29 22:36:29 +000089extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
9df0e167 kojima1999-04-03 03:51:17 +000090extern Atom _XA_WINDOWMAKER_COMMAND;
9d2e6ef9 scottc1998-09-29 22:36:29 +000091
9d2e6ef9 scottc1998-09-29 22:36:29 +000092
93#ifdef SHAPE
9af1c6c4 dan1998-10-21 14:43:47 +000094extern Bool wShapeSupported;
95extern int wShapeEventBase;
9d2e6ef9 scottc1998-09-29 22:36:29 +000096#endif
97
6830b057 dan2004-10-12 21:28:27 +000098#ifdef KEEP_XKB_LOCK_STATUS
2bce7940 id1999-05-23 19:33:19 +000099extern int wXkbEventBase;
100#endif
101
9d2e6ef9 scottc1998-09-29 22:36:29 +0000102/* special flags */
56d85687 Rodney Padgett2008-08-09 11:39:24 +0100103/*extern char WDelayedActionSet;*/
9d2e6ef9 scottc1998-09-29 22:36:29 +0000104
105
106/************ Local stuff ***********/
107
9d2e6ef9 scottc1998-09-29 22:36:29 +0000108static void saveTimestamp(XEvent *event);
109static void handleColormapNotify();
6830b057 dan2004-10-12 21:28:27 +0000110static void handleMapNotify();
111static void handleUnmapNotify();
112static void handleButtonPress();
113static void handleExpose();
9d2e6ef9 scottc1998-09-29 22:36:29 +0000114static void handleDestroyNotify();
115static void handleConfigureRequest();
116static void handleMapRequest();
117static void handlePropertyNotify();
118static void handleEnterNotify();
119static void handleLeaveNotify();
120static void handleExtensions();
121static void handleClientMessage();
122static void handleKeyPress();
123static void handleFocusIn();
124static void handleMotionNotify();
e7495baf dan1999-02-17 11:06:40 +0000125static void handleVisibilityNotify();
59eb9475 dan1998-11-03 12:53:26 +0000126
416e3a82 dan1999-01-25 19:06:50 +0000127
9d2e6ef9 scottc1998-09-29 22:36:29 +0000128#ifdef SHAPE
129static void handleShapeNotify();
130#endif
131
132/* called from the signal handler */
133void NotifyDeadProcess(pid_t pid, unsigned char status);
134
135/* real dead process handler */
136static void handleDeadProcess(void *foo);
137
138
139typedef struct DeadProcesses {
140 pid_t pid;
141 unsigned char exit_status;
142} DeadProcesses;
143
144/* stack of dead processes */
145static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
146static int deadProcessPtr=0;
147
148
149typedef struct DeathHandler {
150 WDeathHandler *callback;
151 pid_t pid;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000152 void *client_data;
153} DeathHandler;
154
046403db dan2001-04-15 01:22:56 +0000155static WMArray *deathHandlers=NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000156
9d2e6ef9 scottc1998-09-29 22:36:29 +0000157
158
59eb9475 dan1998-11-03 12:53:26 +0000159WMagicNumber
9d2e6ef9 scottc1998-09-29 22:36:29 +0000160wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
161{
162 DeathHandler *handler;
6830b057 dan2004-10-12 21:28:27 +0000163
9d2e6ef9 scottc1998-09-29 22:36:29 +0000164 handler = malloc(sizeof(DeathHandler));
165 if (!handler)
6830b057 dan2004-10-12 21:28:27 +0000166 return 0;
3c046182 kojima1999-09-16 02:58:56 +0000167
9d2e6ef9 scottc1998-09-29 22:36:29 +0000168 handler->pid = pid;
169 handler->callback = callback;
170 handler->client_data = cdata;
3c046182 kojima1999-09-16 02:58:56 +0000171
172 if (!deathHandlers)
6830b057 dan2004-10-12 21:28:27 +0000173 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
3c046182 kojima1999-09-16 02:58:56 +0000174
046403db dan2001-04-15 01:22:56 +0000175 WMAddToArray(deathHandlers, handler);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000176
177 return handler;
178}
179
180
181
6830b057 dan2004-10-12 21:28:27 +0000182void
59eb9475 dan1998-11-03 12:53:26 +0000183wDeleteDeathHandler(WMagicNumber id)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000184{
3c046182 kojima1999-09-16 02:58:56 +0000185 DeathHandler *handler=(DeathHandler*)id;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000186
3c046182 kojima1999-09-16 02:58:56 +0000187 if (!handler || !deathHandlers)
6830b057 dan2004-10-12 21:28:27 +0000188 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000189
046403db dan2001-04-15 01:22:56 +0000190 /* array destructor will call wfree(handler) */
191 WMRemoveFromArray(deathHandlers, handler);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000192}
193
194
195void
196DispatchEvent(XEvent *event)
197{
3c046182 kojima1999-09-16 02:58:56 +0000198 if (deathHandlers)
6830b057 dan2004-10-12 21:28:27 +0000199 handleDeadProcess(NULL);
3c046182 kojima1999-09-16 02:58:56 +0000200
088c0ac2 dan1999-03-09 14:58:01 +0000201 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
6830b057 dan2004-10-12 21:28:27 +0000202 WCHANGE_STATE(WSTATE_EXITING);
203 /* received SIGTERM */
204 /*
205 * WMHandleEvent() can't be called from anything
206 * executed inside here, or we can get in a infinite
207 * recursive loop.
208 */
209 Shutdown(WSExitMode);
0261c326 dan1999-01-06 15:22:33 +0000210
088c0ac2 dan1999-03-09 14:58:01 +0000211 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
6830b057 dan2004-10-12 21:28:27 +0000212 WCHANGE_STATE(WSTATE_RESTARTING);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000213
6830b057 dan2004-10-12 21:28:27 +0000214 Shutdown(WSRestartPreparationMode);
215 /* received SIGHUP */
216 Restart(NULL, True);
4637c09d dan2001-01-30 03:04:02 +0000217 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
218 WCHANGE_STATE(WSTATE_NORMAL);
219 wDefaultsCheckDomains("bla");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000220 }
221
222 /* for the case that all that is wanted to be dispatched is
223 * the stuff above */
224 if (!event)
6830b057 dan2004-10-12 21:28:27 +0000225 return;
3c046182 kojima1999-09-16 02:58:56 +0000226
227 saveTimestamp(event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000228 switch (event->type) {
6830b057 dan2004-10-12 21:28:27 +0000229 case MapRequest:
230 handleMapRequest(event);
231 break;
232
233 case KeyPress:
234 handleKeyPress(event);
235 break;
236
237 case MotionNotify:
238 handleMotionNotify(event);
239 break;
240
241 case ConfigureRequest:
242 handleConfigureRequest(event);
243 break;
244
245 case DestroyNotify:
246 handleDestroyNotify(event);
247 break;
248
249 case MapNotify:
250 handleMapNotify(event);
251 break;
252
253 case UnmapNotify:
254 handleUnmapNotify(event);
255 break;
256
257 case ButtonPress:
258 handleButtonPress(event);
259 break;
260
261 case Expose:
262 handleExpose(event);
263 break;
264
265 case PropertyNotify:
266 handlePropertyNotify(event);
267 break;
268
269 case EnterNotify:
270 handleEnterNotify(event);
271 break;
272
273 case LeaveNotify:
9d2e6ef9 scottc1998-09-29 22:36:29 +0000274 handleLeaveNotify(event);
6830b057 dan2004-10-12 21:28:27 +0000275 break;
276
277 case ClientMessage:
278 handleClientMessage(event);
279 break;
280
281 case ColormapNotify:
282 handleColormapNotify(event);
283 break;
284
285 case MappingNotify:
286 if (event->xmapping.request == MappingKeyboard
287 || event->xmapping.request == MappingModifier)
288 XRefreshKeyboardMapping(&event->xmapping);
289 break;
290
291 case FocusIn:
292 handleFocusIn(event);
293 break;
294
295 case VisibilityNotify:
296 handleVisibilityNotify(event);
297 break;
298 default:
299 handleExtensions(event);
300 break;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000301 }
302}
303
56d85687
RP
Rodney Padgett2008-08-09 11:39:24 +0100304/*
305 *----------------------------------------------------------------------
306 * inotifyHandleEvents-
307 * Check for inotify events
308 *
309 * Returns:
310 * After reading events for the given file descriptor (fd) and
311 * watch descriptor (wd)
312 *
313 * Side effects:
314 * Calls wDefaultsCheckDomains if config database is updated
315 *----------------------------------------------------------------------
316 */
317
318/* Allow for 1024 simultanious events */
319#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
320void inotifyHandleEvents (int fd, int wd)
321{
322 ssize_t eventQLength, i = 0;
323 char buff[BUFF_SIZE] = {0};
324 extern void wDefaultsCheckDomains();
325 int oneShotFlag=0; /* Only check config once per read of the event queue */
326
327 /* Read off the queued events
328 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
329 * not occur; the block is on Xevents, but a config file change will normally
330 * occur as a result of an Xevent - so the event queue should never have more than
331 * a few entries before a read().
332 */
333 eventQLength = read (fd, buff, BUFF_SIZE);
334
335 /* check what events occured */
336 /* Should really check wd here too, but for now we only have one watch! */
337 while (i < eventQLength) {
338 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
339
340 /*
341 * see inotify.h for event types.
342 */
343 if (pevent->mask & IN_DELETE_SELF) {
344 wwarning(_("the defaults database has been deleted!"
345 " Restart Window Maker to create the database"
346 " with the default settings"));
347 close(fd);
348 }
349 if (pevent->mask & IN_UNMOUNT) {
350 wwarning(_("the unit containing the defaults database has"
351 " been unmounted. Setting --static mode."
352 " Any changes will not be saved."));
353 close(fd);
354 wPreferences.flags.noupdates=1;
355 }
356 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
357 fprintf(stdout,"wmaker: reading config files in defaults database.\n");
358 wDefaultsCheckDomains(NULL);
359 }
360 /* Check for filename (length of name (len) > 0) */
361 /* if (pevent->len) printf ("name=%s\n", pevent->name); */
362
363 i += sizeof(struct inotify_event) + pevent->len; /* move to next event in the buffer */
364 }
365
366} /* inotifyHandleEvents */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000367
368/*
369 *----------------------------------------------------------------------
370 * EventLoop-
371 * Processes X and internal events indefinitely.
6830b057 dan2004-10-12 21:28:27 +0000372 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000373 * Returns:
374 * Never returns
6830b057 dan2004-10-12 21:28:27 +0000375 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000376 * Side effects:
377 * The LastTimestamp global variable is updated.
56d85687 Rodney Padgett2008-08-09 11:39:24 +0100378 * Calls inotifyGetEvents if defaults database changes.
6830b057 dan2004-10-12 21:28:27 +0000379 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000380 */
381void
382EventLoop()
383{
384 XEvent event;
56d85687
RP
Rodney Padgett2008-08-09 11:39:24 +0100385 extern int inotifyFD;
386 extern int inotifyWD;
387 struct timeval time;
388 fd_set rfds;
389 int retVal=0;
390
391 if (inotifyFD < 0 || inotifyWD < 0)
392 retVal = -1;
9aca0d5f dan2004-10-12 01:34:32 +0000393
9d2e6ef9 scottc1998-09-29 22:36:29 +0000394 for(;;) {
722c82c8 Carlos R. Mafra2008-05-02 20:01:50 -0300395
56d85687
RP
Rodney Padgett2008-08-09 11:39:24 +0100396 WMNextEvent(dpy, &event); /* Blocks here */
397 WMHandleEvent(&event);
398
399 if (retVal != -1 ) {
400 time.tv_sec = 0;
401 time.tv_usec = 0;
402 FD_ZERO (&rfds);
403 FD_SET (inotifyFD, &rfds);
404
405 /* check for available read data from inotify - don't block! */
406 retVal = select (inotifyFD + 1, &rfds, NULL, NULL, &time);
407
408 if (retVal < 0) { /* an error has occured */
409 wwarning(_("select failed. The inotify instance will be closed."
410 " Changes to the defaults database will require"
411 " a restart to take effect."));
412 close(inotifyFD);
413 continue;
414 }
415 if (FD_ISSET (inotifyFD, &rfds))
416 inotifyHandleEvents(inotifyFD,inotifyWD);
417 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000418 }
419}
420
9aca0d5f dan2004-10-12 01:34:32 +0000421/*
422 *----------------------------------------------------------------------
423 * ProcessPendingEvents --
424 * Processes the events that are currently pending (at the time
425 * this function is called) in the display's queue.
426 *
427 * Returns:
428 * After the pending events that were present at the function call
429 * are processed.
430 *
431 * Side effects:
6830b057 dan2004-10-12 21:28:27 +0000432 * Many -- whatever handling events may involve.
9aca0d5f dan2004-10-12 01:34:32 +0000433 *
434 *----------------------------------------------------------------------
435 */
436void
437ProcessPendingEvents()
438{
439 XEvent event;
440 int count;
441
442 XSync(dpy, False);
443
444 /* Take a snapshot of the event count in the queue */
445 count = XPending(dpy);
446
447 while (count>0 && XPending(dpy)) {
448 WMNextEvent(dpy, &event);
449 WMHandleEvent(&event);
450 count--;
451 }
452}
453
9d2e6ef9 scottc1998-09-29 22:36:29 +0000454
6830b057 dan2004-10-12 21:28:27 +0000455Bool
9d2e6ef9 scottc1998-09-29 22:36:29 +0000456IsDoubleClick(WScreen *scr, XEvent *event)
457{
6830b057 dan2004-10-12 21:28:27 +0000458 if ((scr->last_click_time>0) &&
459 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
460 && (event->xbutton.button == scr->last_click_button)
461 && (event->xbutton.window == scr->last_click_window)) {
9d2e6ef9 scottc1998-09-29 22:36:29 +0000462
6830b057 dan2004-10-12 21:28:27 +0000463 scr->flags.next_click_is_not_double = 1;
464 scr->last_click_time = 0;
465 scr->last_click_window = event->xbutton.window;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000466
6830b057 dan2004-10-12 21:28:27 +0000467 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000468 }
469 return False;
470}
471
472
473void
474NotifyDeadProcess(pid_t pid, unsigned char status)
475{
476 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
6830b057 dan2004-10-12 21:28:27 +0000477 wwarning("stack overflow: too many dead processes");
478 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000479 }
480 /* stack the process to be handled later,
481 * as this is called from the signal handler */
482 deadProcesses[deadProcessPtr].pid = pid;
483 deadProcesses[deadProcessPtr].exit_status = status;
484 deadProcessPtr++;
485}
486
487
488static void
489handleDeadProcess(void *foo)
490{
491 DeathHandler *tmp;
9af1c6c4 dan1998-10-21 14:43:47 +0000492 int i;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000493
9af1c6c4 dan1998-10-21 14:43:47 +0000494 for (i=0; i<deadProcessPtr; i++) {
6830b057 dan2004-10-12 21:28:27 +0000495 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000496 }
497
3c046182 kojima1999-09-16 02:58:56 +0000498 if (!deathHandlers) {
6830b057 dan2004-10-12 21:28:27 +0000499 deadProcessPtr=0;
500 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000501 }
6830b057 dan2004-10-12 21:28:27 +0000502
9d2e6ef9 scottc1998-09-29 22:36:29 +0000503 /* get the pids on the queue and call handlers */
504 while (deadProcessPtr>0) {
6830b057 dan2004-10-12 21:28:27 +0000505 deadProcessPtr--;
506
507 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
508 tmp = WMGetFromArray(deathHandlers, i);
509 if (!tmp)
510 continue;
511
512 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
513 (*tmp->callback)(tmp->pid,
514 deadProcesses[deadProcessPtr].exit_status,
515 tmp->client_data);
516 wDeleteDeathHandler(tmp);
517 }
518 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000519 }
520}
521
522
523static void
524saveTimestamp(XEvent *event)
525{
7efcf57c dan2003-08-03 00:00:11 +0000526 /*
527 * Never save CurrentTime as LastTimestamp because CurrentTime
528 * it's not a real timestamp (it's the 0L constant)
529 */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000530
531 switch (event->type) {
6830b057 dan2004-10-12 21:28:27 +0000532 case ButtonRelease:
533 case ButtonPress:
534 LastTimestamp = event->xbutton.time;
535 break;
536 case KeyPress:
537 case KeyRelease:
538 LastTimestamp = event->xkey.time;
539 break;
540 case MotionNotify:
541 LastTimestamp = event->xmotion.time;
542 break;
543 case PropertyNotify:
544 LastTimestamp = event->xproperty.time;
545 break;
546 case EnterNotify:
547 case LeaveNotify:
548 LastTimestamp = event->xcrossing.time;
549 break;
550 case SelectionClear:
551 LastTimestamp = event->xselectionclear.time;
552 break;
553 case SelectionRequest:
554 LastTimestamp = event->xselectionrequest.time;
555 break;
556 case SelectionNotify:
557 LastTimestamp = event->xselection.time;
d4025072 id1999-05-17 20:21:43 +0000558#ifdef XDND
7efcf57c dan2003-08-03 00:00:11 +0000559 wXDNDProcessSelection(event);
d4025072 id1999-05-17 20:21:43 +0000560#endif
6830b057 dan2004-10-12 21:28:27 +0000561 break;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000562 }
563}
564
565
90c77b1a dan2001-12-17 14:46:31 +0000566static int
567matchWindow(void *item, void *cdata)
568{
569 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
570}
571
572
9d2e6ef9 scottc1998-09-29 22:36:29 +0000573static void
574handleExtensions(XEvent *event)
575{
6830b057 dan2004-10-12 21:28:27 +0000576#ifdef KEEP_XKB_LOCK_STATUS
b3112e2b id1999-05-22 21:30:35 +0000577 XkbEvent *xkbevent;
2bce7940 id1999-05-23 19:33:19 +0000578 xkbevent = (XkbEvent *)event;
9ca84c07 dan1999-05-24 20:04:41 +0000579#endif /*KEEP_XKB_LOCK_STATUS*/
9d2e6ef9 scottc1998-09-29 22:36:29 +0000580#ifdef SHAPE
9af1c6c4 dan1998-10-21 14:43:47 +0000581 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
6830b057 dan2004-10-12 21:28:27 +0000582 handleShapeNotify(event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000583 }
6830b057 dan2004-10-12 21:28:27 +0000584#endif
585#ifdef KEEP_XKB_LOCK_STATUS
2bce7940 id1999-05-23 19:33:19 +0000586 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
587 handleXkbIndicatorStateNotify(event);
7f9f8894 kojima1999-03-15 23:41:22 +0000588 }
589#endif /*KEEP_XKB_LOCK_STATUS*/
9d2e6ef9 scottc1998-09-29 22:36:29 +0000590}
591
0261c326 dan1999-01-06 15:22:33 +0000592
6830b057 dan2004-10-12 21:28:27 +0000593static void
9d2e6ef9 scottc1998-09-29 22:36:29 +0000594handleMapRequest(XEvent *ev)
595{
596 WWindow *wwin;
597 WScreen *scr = NULL;
598 Window window = ev->xmaprequest.window;
599
600#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000601 printf("got map request for %x\n", (unsigned)window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000602#endif
e7495baf dan1999-02-17 11:06:40 +0000603 if ((wwin = wWindowFor(window))) {
6830b057 dan2004-10-12 21:28:27 +0000604 if (wwin->flags.shaded) {
605 wUnshadeWindow(wwin);
606 }
607 /* deiconify window */
608 if (wwin->flags.miniaturized) {
609 wDeiconifyWindow(wwin);
610 } else if (wwin->flags.hidden) {
9d2e6ef9 scottc1998-09-29 22:36:29 +0000611 WApplication *wapp = wApplicationOf(wwin->main_window);
612 /* go to the last workspace that the user worked on the app */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000613 if (wapp) {
614 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
615 }
6830b057 dan2004-10-12 21:28:27 +0000616 wUnhideApplication(wapp, False, False);
617 }
618 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000619 }
620
621 scr = wScreenForRootWindow(ev->xmaprequest.parent);
622
623 wwin = wManageWindow(scr, window);
624
6830b057 dan2004-10-12 21:28:27 +0000625 /*
9d2e6ef9 scottc1998-09-29 22:36:29 +0000626 * This is to let the Dock know that the application it launched
6830b057 dan2004-10-12 21:28:27 +0000627 * has already been mapped (eg: it has finished launching).
9d2e6ef9 scottc1998-09-29 22:36:29 +0000628 * It is not necessary for normally docked apps, but is needed for
629 * apps that were forcedly docked (like with dockit).
630 */
631 if (scr->last_dock) {
6830b057 dan2004-10-12 21:28:27 +0000632 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
633 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
634 else
635 wDockTrackWindowLaunch(scr->last_dock, window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000636 }
637
638 if (wwin) {
6830b057 dan2004-10-12 21:28:27 +0000639 wClientSetState(wwin, NormalState, None);
640 if (wwin->flags.maximized) {
641 wMaximizeWindow(wwin, wwin->flags.maximized);
642 }
643 if (wwin->flags.shaded) {
644 wwin->flags.shaded = 0;
645 wwin->flags.skip_next_animation = 1;
646 wShadeWindow(wwin);
647 }
648 if (wwin->flags.miniaturized) {
649 wwin->flags.miniaturized = 0;
650 wwin->flags.skip_next_animation = 1;
651 wIconifyWindow(wwin);
652 }
c0317dda dan2005-08-22 23:58:19 +0000653 if (wwin->flags.fullscreen) {
654 wwin->flags.fullscreen = 0;
655 wFullscreenWindow(wwin);
656 }
6830b057 dan2004-10-12 21:28:27 +0000657 if (wwin->flags.hidden) {
658 WApplication *wapp = wApplicationOf(wwin->main_window);
659
660 wwin->flags.hidden = 0;
661 wwin->flags.skip_next_animation = 1;
662 if (wapp) {
663 wHideApplication(wapp);
664 }
665 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000666 }
667}
668
669
670static void
0261c326 dan1999-01-06 15:22:33 +0000671handleDestroyNotify(XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000672{
673 WWindow *wwin;
674 WApplication *app;
0261c326 dan1999-01-06 15:22:33 +0000675 Window window = event->xdestroywindow.window;
90c77b1a dan2001-12-17 14:46:31 +0000676 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
677 int index;
0261c326 dan1999-01-06 15:22:33 +0000678
9d2e6ef9 scottc1998-09-29 22:36:29 +0000679#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000680 printf("got destroy notify\n");
eb87c409 kojima1999-10-20 03:25:06 +0000681#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000682 wwin = wWindowFor(window);
683 if (wwin) {
6830b057 dan2004-10-12 21:28:27 +0000684 wUnmanageWindow(wwin, False, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000685 }
686
9e615bcf dan2001-12-28 03:29:50 +0000687 if (scr != NULL) {
688 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
689 (void*)window)) != WANotFound) {
690 WFakeGroupLeader *fPtr;
691
692 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
693 if (fPtr->retainCount > 0) {
694 fPtr->retainCount--;
695 if (fPtr->retainCount==0 && fPtr->leader!=None) {
696 XDestroyWindow(dpy, fPtr->leader);
697 fPtr->leader = None;
698 XFlush(dpy);
699 }
90c77b1a dan2001-12-17 14:46:31 +0000700 }
9e615bcf dan2001-12-28 03:29:50 +0000701 fPtr->origLeader = None;
90c77b1a dan2001-12-17 14:46:31 +0000702 }
90c77b1a dan2001-12-17 14:46:31 +0000703 }
704
9d2e6ef9 scottc1998-09-29 22:36:29 +0000705 app = wApplicationOf(window);
706 if (app) {
6830b057 dan2004-10-12 21:28:27 +0000707 if (window == app->main_window) {
708 app->refcount = 0;
709 wwin = app->main_window_desc->screen_ptr->focused_window;
710 while (wwin) {
711 if (wwin->main_window == window) {
712 wwin->main_window = None;
713 }
714 wwin = wwin->prev;
715 }
716 }
717 wApplicationDestroy(app);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000718 }
719}
720
721
722
6830b057 dan2004-10-12 21:28:27 +0000723static void
9d2e6ef9 scottc1998-09-29 22:36:29 +0000724handleExpose(XEvent *event)
725{
726 WObjDescriptor *desc;
e7495baf dan1999-02-17 11:06:40 +0000727 XEvent ev;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000728
eb87c409 kojima1999-10-20 03:25:06 +0000729#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000730 printf("got expose\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000731#endif
e7495baf dan1999-02-17 11:06:40 +0000732 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
733
6830b057 dan2004-10-12 21:28:27 +0000734 if (XFindContext(dpy, event->xexpose.window, wWinContext,
735 (XPointer *)&desc)==XCNOENT) {
736 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000737 }
6830b057 dan2004-10-12 21:28:27 +0000738
9d2e6ef9 scottc1998-09-29 22:36:29 +0000739 if (desc->handle_expose) {
6830b057 dan2004-10-12 21:28:27 +0000740 (*desc->handle_expose)(desc, event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000741 }
742}
743
3bde6495 dan2001-04-27 23:41:17 +0000744static void
745executeButtonAction(WScreen *scr, XEvent *event, int action)
746{
747 switch(action) {
6830b057 dan2004-10-12 21:28:27 +0000748 case WA_SELECT_WINDOWS:
3bde6495 dan2001-04-27 23:41:17 +0000749 wUnselectWindows(scr);
750 wSelectWindows(scr, event);
751 break;
6830b057 dan2004-10-12 21:28:27 +0000752 case WA_OPEN_APPMENU:
3bde6495 dan2001-04-27 23:41:17 +0000753 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
754 /* ugly hack */
755 if (scr->root_menu) {
756 if (scr->root_menu->brother->flags.mapped)
757 event->xbutton.window = scr->root_menu->brother->frame->core->window;
758 else
759 event->xbutton.window = scr->root_menu->frame->core->window;
760 }
761 break;
6830b057 dan2004-10-12 21:28:27 +0000762 case WA_OPEN_WINLISTMENU:
3bde6495 dan2001-04-27 23:41:17 +0000763 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
764 if (scr->switch_menu) {
765 if (scr->switch_menu->brother->flags.mapped)
766 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
767 else
768 event->xbutton.window = scr->switch_menu->frame->core->window;
769 }
770 break;
771 default:
772 break;
773 }
774}
775
776
9d2e6ef9 scottc1998-09-29 22:36:29 +0000777/* bindable */
778static void
779handleButtonPress(XEvent *event)
780{
781 WObjDescriptor *desc;
782 WScreen *scr;
6830b057 dan2004-10-12 21:28:27 +0000783
eb87c409 kojima1999-10-20 03:25:06 +0000784#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000785 printf("got button press\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000786#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000787 scr = wScreenForRootWindow(event->xbutton.root);
6830b057 dan2004-10-12 21:28:27 +0000788
9d2e6ef9 scottc1998-09-29 22:36:29 +0000789#ifdef BALLOON_TEXT
790 wBalloonHide(scr);
791#endif
792
6830b057 dan2004-10-12 21:28:27 +0000793
0261c326 dan1999-01-06 15:22:33 +0000794#ifndef LITE
6830b057 dan2004-10-12 21:28:27 +0000795 if (event->xbutton.window==scr->root_win) {
3bde6495 dan2001-04-27 23:41:17 +0000796 if (event->xbutton.button==Button1 &&
797 wPreferences.mouse_button1!=WA_NONE) {
798 executeButtonAction(scr, event, wPreferences.mouse_button1);
799 } else if (event->xbutton.button==Button2 &&
800 wPreferences.mouse_button2!=WA_NONE) {
801 executeButtonAction(scr, event, wPreferences.mouse_button2);
802 } else if (event->xbutton.button==Button3 &&
803 wPreferences.mouse_button3!=WA_NONE) {
804 executeButtonAction(scr, event, wPreferences.mouse_button3);
805 } else if (event->xbutton.button==Button4 &&
806 wPreferences.mouse_wheel!=WA_NONE) {
6830b057 dan2004-10-12 21:28:27 +0000807 wWorkspaceRelativeChange(scr, 1);
3bde6495 dan2001-04-27 23:41:17 +0000808 } else if (event->xbutton.button==Button5 &&
809 wPreferences.mouse_wheel!=WA_NONE) {
810 wWorkspaceRelativeChange(scr, -1);
811 }
9007a657 dan1998-11-23 11:32:19 +0000812 }
0261c326 dan1999-01-06 15:22:33 +0000813#endif /* !LITE */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000814
3d7cb106 kojima2000-03-29 03:58:25 +0000815 desc = NULL;
9007a657 dan1998-11-23 11:32:19 +0000816 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
6830b057 dan2004-10-12 21:28:27 +0000817 (XPointer *)&desc)==XCNOENT) {
818 if (XFindContext(dpy, event->xbutton.window, wWinContext,
819 (XPointer *)&desc)==XCNOENT) {
820 return;
821 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000822 }
823
824 if (desc->parent_type == WCLASS_WINDOW) {
6830b057 dan2004-10-12 21:28:27 +0000825 XSync(dpy, 0);
826
827 if (event->xbutton.state & MOD_MASK) {
828 XAllowEvents(dpy, AsyncPointer, CurrentTime);
829 }
830
831 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
832 if (wPreferences.ignore_focus_click) {
833 XAllowEvents(dpy, AsyncPointer, CurrentTime);
834 }
835 XAllowEvents(dpy, ReplayPointer, CurrentTime);
836 /* }*/
837 XSync(dpy, 0);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000838 } else if (desc->parent_type == WCLASS_APPICON
6830b057 dan2004-10-12 21:28:27 +0000839 || desc->parent_type == WCLASS_MINIWINDOW
840 || desc->parent_type == WCLASS_DOCK_ICON) {
841 if (event->xbutton.state & MOD_MASK) {
842 XSync(dpy, 0);
843 XAllowEvents(dpy, AsyncPointer, CurrentTime);
844 XSync(dpy, 0);
845 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000846 }
847
3d7cb106 kojima2000-03-29 03:58:25 +0000848 if (desc->handle_mousedown!=NULL) {
6830b057 dan2004-10-12 21:28:27 +0000849 (*desc->handle_mousedown)(desc, event);
3d7cb106 kojima2000-03-29 03:58:25 +0000850 }
851
9d2e6ef9 scottc1998-09-29 22:36:29 +0000852 /* save double-click information */
853 if (scr->flags.next_click_is_not_double) {
6830b057 dan2004-10-12 21:28:27 +0000854 scr->flags.next_click_is_not_double = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000855 } else {
6830b057 dan2004-10-12 21:28:27 +0000856 scr->last_click_time = event->xbutton.time;
857 scr->last_click_button = event->xbutton.button;
858 scr->last_click_window = event->xbutton.window;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000859 }
860}
861
862
863static void
e7495baf dan1999-02-17 11:06:40 +0000864handleMapNotify(XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000865{
866 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000867#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000868 printf("got map\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000869#endif
e7495baf dan1999-02-17 11:06:40 +0000870 wwin = wWindowFor(event->xmap.event);
871 if (wwin && wwin->client_win == event->xmap.event) {
6830b057 dan2004-10-12 21:28:27 +0000872 if (wwin->flags.miniaturized) {
873 wDeiconifyWindow(wwin);
874 } else {
875 XGrabServer(dpy);
876 wWindowMap(wwin);
877 wClientSetState(wwin, NormalState, None);
878 XUngrabServer(dpy);
879 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000880 }
881}
882
883
884static void
885handleUnmapNotify(XEvent *event)
886{
887 WWindow *wwin;
888 XEvent ev;
e7495baf dan1999-02-17 11:06:40 +0000889 Bool withdraw = False;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000890#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000891 printf("got unmap\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000892#endif
6830b057 dan2004-10-12 21:28:27 +0000893 /* only process windows with StructureNotify selected
e7495baf dan1999-02-17 11:06:40 +0000894 * (ignore SubstructureNotify) */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000895 wwin = wWindowFor(event->xunmap.window);
e7495baf dan1999-02-17 11:06:40 +0000896 if (!wwin)
6830b057 dan2004-10-12 21:28:27 +0000897 return;
e7495baf dan1999-02-17 11:06:40 +0000898
899 /* whether the event is a Withdrawal request */
900 if (event->xunmap.event == wwin->screen_ptr->root_win
6830b057 dan2004-10-12 21:28:27 +0000901 && event->xunmap.send_event)
902 withdraw = True;
e7495baf dan1999-02-17 11:06:40 +0000903
904 if (wwin->client_win != event->xunmap.event && !withdraw)
6830b057 dan2004-10-12 21:28:27 +0000905 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000906
e7495baf dan1999-02-17 11:06:40 +0000907 if (!wwin->flags.mapped && !withdraw
6830b057 dan2004-10-12 21:28:27 +0000908 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
909 && !wwin->flags.miniaturized && !wwin->flags.hidden)
910 return;
e7495baf dan1999-02-17 11:06:40 +0000911
9d2e6ef9 scottc1998-09-29 22:36:29 +0000912 XGrabServer(dpy);
913 XUnmapWindow(dpy, wwin->frame->core->window);
914 wwin->flags.mapped = 0;
915 XSync(dpy, 0);
916 /* check if the window was destroyed */
917 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
6830b057 dan2004-10-12 21:28:27 +0000918 DispatchEvent(&ev);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000919 } else {
6830b057 dan2004-10-12 21:28:27 +0000920 Bool reparented = False;
921
922 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
923 reparented = True;
924
925 /* withdraw window */
926 wwin->flags.mapped = 0;
927 if (!reparented)
928 wClientSetState(wwin, WithdrawnState, None);
929
930 /* if the window was reparented, do not reparent it back to the
931 * root window */
932 wUnmanageWindow(wwin, !reparented, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000933 }
934 XUngrabServer(dpy);
935}
936
937
938static void
939handleConfigureRequest(XEvent *event)
940{
941 WWindow *wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000942#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000943 printf("got configure request\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000944#endif
945 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
6830b057 dan2004-10-12 21:28:27 +0000946 /*
947 * Configure request for unmapped window
948 */
949 wClientConfigure(NULL, &(event->xconfigurerequest));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000950 } else {
6830b057 dan2004-10-12 21:28:27 +0000951 wClientConfigure(wwin, &(event->xconfigurerequest));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000952 }
953}
954
955
956static void
957handlePropertyNotify(XEvent *event)
958{
959 WWindow *wwin;
960 WApplication *wapp;
961 Window jr;
962 int ji;
963 unsigned int ju;
0261c326 dan1999-01-06 15:22:33 +0000964 WScreen *scr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000965#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000966 printf("got property notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000967#endif
968 if ((wwin=wWindowFor(event->xproperty.window))) {
6830b057 dan2004-10-12 21:28:27 +0000969 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
970 &ju, &ju, &ju, &ju)) {
971 return;
972 }
973 wClientCheckProperty(wwin, &event->xproperty);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000974 }
975 wapp = wApplicationOf(event->xproperty.window);
976 if (wapp) {
6830b057 dan2004-10-12 21:28:27 +0000977 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000978 }
6830b057 dan2004-10-12 21:28:27 +0000979
416e3a82 dan1999-01-25 19:06:50 +0000980 scr = wScreenForWindow(event->xproperty.window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000981}
982
983
984static void
985handleClientMessage(XEvent *event)
986{
987 WWindow *wwin;
988 WObjDescriptor *desc;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000989#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +0000990 printf("got client message\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000991#endif
992 /* handle transition from Normal to Iconic state */
993 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
6830b057 dan2004-10-12 21:28:27 +0000994 && event->xclient.format == 32
995 && event->xclient.data.l[0] == IconicState) {
996
997 wwin = wWindowFor(event->xclient.window);
998 if (!wwin) return;
999 if (!wwin->flags.miniaturized)
1000 wIconifyWindow(wwin);
59eb9475 dan1998-11-03 12:53:26 +00001001 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
6830b057 dan2004-10-12 21:28:27 +00001002 && event->xclient.format == 32) {
1003 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
59eb9475 dan1998-11-03 12:53:26 +00001004
6830b057 dan2004-10-12 21:28:27 +00001005 if (!scr)
1006 return;
59eb9475 dan1998-11-03 12:53:26 +00001007
6830b057 dan2004-10-12 21:28:27 +00001008 if (event->xclient.data.l[1] == 1) { /* starting */
1009 wColormapAllowClientInstallation(scr, True);
1010 } else { /* stopping */
1011 wColormapAllowClientInstallation(scr, False);
1012 }
9df0e167 kojima1999-04-03 03:51:17 +00001013 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
1014
6830b057 dan2004-10-12 21:28:27 +00001015 wDefaultsCheckDomains("bla");
9df0e167 kojima1999-04-03 03:51:17 +00001016
9d2e6ef9 scottc1998-09-29 22:36:29 +00001017 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
6830b057 dan2004-10-12 21:28:27 +00001018 WApplication *wapp;
1019 int done=0;
1020 wapp = wApplicationOf(event->xclient.window);
1021 if (wapp) {
1022 switch (event->xclient.data.l[0]) {
1023 case WMFHideOtherApplications:
1024 wHideOtherApplications(wapp->main_window_desc);
1025 done = 1;
1026 break;
1027
1028 case WMFHideApplication:
1029 wHideApplication(wapp);
1030 done = 1;
1031 break;
1032 }
1033 }
1034 if (!done) {
1035 wwin = wWindowFor(event->xclient.window);
1036 if (wwin) {
1037 switch (event->xclient.data.l[0]) {
1038 case WMFHideOtherApplications:
1039 wHideOtherApplications(wwin);
1040 break;
1041
1042 case WMFHideApplication:
1043 wHideApplication(wApplicationOf(wwin->main_window));
1044 break;
1045 }
1046 }
1047 }
0af24483 richard2000-03-02 07:36:02 +00001048 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
6830b057 dan2004-10-12 21:28:27 +00001049 wwin = wWindowFor(event->xclient.window);
1050 if (!wwin) return;
1051 switch (event->xclient.data.l[0]) {
1052 case GSWindowLevelAttr:
1053 {
1054 int level = (int)event->xclient.data.l[1];
1055
1056 if (WINDOW_LEVEL(wwin) != level) {
1057 ChangeStackingLevel(wwin->frame->core, level);
1058 }
1059 }
1060 break;
1061 }
0af24483 richard2000-03-02 07:36:02 +00001062 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
6830b057 dan2004-10-12 21:28:27 +00001063 wwin = wWindowFor(event->xclient.window);
1064 if (!wwin) return;
1065 switch (event->xclient.data.l[0]) {
1066 case WMTitleBarNormal:
1067 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1068 break;
1069 case WMTitleBarMain:
1070 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1071 break;
1072 case WMTitleBarKey:
1073 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1074 break;
1075 }
9aca0d5f dan2004-10-12 01:34:32 +00001076#ifdef NETWM_HINTS
1077 } else if (wNETWMProcessClientMessage(&event->xclient)) {
6830b057 dan2004-10-12 21:28:27 +00001078 /* do nothing */
9aca0d5f dan2004-10-12 01:34:32 +00001079#endif
d4025072 id1999-05-17 20:21:43 +00001080#ifdef XDND
1081 } else if (wXDNDProcessClientMessage(&event->xclient)) {
6830b057 dan2004-10-12 21:28:27 +00001082 /* do nothing */
d4025072 id1999-05-17 20:21:43 +00001083#endif /* XDND */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001084 } else {
6830b057 dan2004-10-12 21:28:27 +00001085 /*
1086 * Non-standard thing, but needed by OffiX DND.
1087 * For when the icon frame gets a ClientMessage
1088 * that should have gone to the icon_window.
1089 */
1090 if (XFindContext(dpy, event->xbutton.window, wWinContext,
1091 (XPointer *)&desc)!=XCNOENT) {
1092 struct WIcon *icon=NULL;
1093
1094 if (desc->parent_type == WCLASS_MINIWINDOW) {
1095 icon = (WIcon*)desc->parent;
1096 } else if (desc->parent_type == WCLASS_DOCK_ICON
1097 || desc->parent_type == WCLASS_APPICON) {
1098 icon = ((WAppIcon*)desc->parent)->icon;
1099 }
1100 if (icon && (wwin=icon->owner)) {
1101 if (wwin->client_win!=event->xclient.window) {
1102 event->xclient.window = wwin->client_win;
1103 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1104 event);
1105 }
1106 }
1107 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001108 }
1109}
1110
1111
1112static void
1113raiseWindow(WScreen *scr)
1114{
1115 WWindow *wwin;
1116
1117 scr->autoRaiseTimer = NULL;
1118
6830b057 dan2004-10-12 21:28:27 +00001119 wwin = wWindowFor(scr->autoRaiseWindow);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001120 if (!wwin)
6830b057 dan2004-10-12 21:28:27 +00001121 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001122
3d5f435b kojima1999-05-30 05:02:55 +00001123 if (!wwin->flags.destroyed && wwin->flags.focused) {
6830b057 dan2004-10-12 21:28:27 +00001124 wRaiseFrame(wwin->frame->core);
1125 /* this is needed or a race condition will occur */
1126 XSync(dpy, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001127 }
1128}
1129
1130
6830b057 dan2004-10-12 21:28:27 +00001131static void
9d2e6ef9 scottc1998-09-29 22:36:29 +00001132handleEnterNotify(XEvent *event)
1133{
1134 WWindow *wwin;
1135 WObjDescriptor *desc = NULL;
9aca0d5f dan2004-10-12 01:34:32 +00001136#ifdef VIRTUAL_DESKTOP
1137 void (*vdHandler)(XEvent * event);
1138#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +00001139 XEvent ev;
1140 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001141#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +00001142 printf("got enter notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001143#endif
8eb0c79c id1999-12-18 11:52:49 +00001144
1145#ifdef VIRTUAL_DESKTOP
9aca0d5f dan2004-10-12 01:34:32 +00001146 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext,
1147 (XPointer *)&vdHandler)!=XCNOENT) {
897e75d5 dan2004-10-24 20:24:23 +00001148 (*vdHandler)(event);
8eb0c79c id1999-12-18 11:52:49 +00001149 }
1150#endif
1151
9d2e6ef9 scottc1998-09-29 22:36:29 +00001152 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
6830b057 dan2004-10-12 21:28:27 +00001153 &ev)) {
1154 /* already left the window... */
1155 saveTimestamp(&ev);
1156 if (ev.xcrossing.mode==event->xcrossing.mode
1157 && ev.xcrossing.detail==event->xcrossing.detail) {
1158 return;
1159 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001160 }
1161
1162 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1163 (XPointer *)&desc)!=XCNOENT) {
1164 if(desc->handle_enternotify)
1165 (*desc->handle_enternotify)(desc, event);
1166 }
1167
1168 /* enter to window */
1169 wwin = wWindowFor(event->xcrossing.window);
1170 if (!wwin) {
6830b057 dan2004-10-12 21:28:27 +00001171 if (wPreferences.colormap_mode==WCM_POINTER) {
1172 wColormapInstallForWindow(scr, NULL);
1173 }
1174 if (scr->autoRaiseTimer
1175 && event->xcrossing.root==event->xcrossing.window) {
1176 WMDeleteTimerHandler(scr->autoRaiseTimer);
1177 scr->autoRaiseTimer = NULL;
1178 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001179 } else {
6830b057 dan2004-10-12 21:28:27 +00001180 /* set auto raise timer even if in focus-follows-mouse mode
1181 * and the event is for the frame window, even if the window
1182 * has focus already. useful if you move the pointer from a focused
1183 * window to the root window and back pretty fast
1184 *
1185 * set focus if in focus-follows-mouse mode and the event
1186 * is for the frame window and window doesn't have focus yet */
1187 if (wPreferences.focus_mode==WKF_SLOPPY
1188 && wwin->frame->core->window==event->xcrossing.window
1189 && !scr->flags.doing_alt_tab) {
1190
1191 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1192 wSetFocusTo(scr, wwin);
1193
1194 if (scr->autoRaiseTimer)
1195 WMDeleteTimerHandler(scr->autoRaiseTimer);
1196 scr->autoRaiseTimer = NULL;
1197
1198 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1199 scr->autoRaiseWindow = wwin->frame->core->window;
1200 scr->autoRaiseTimer
1201 = WMAddTimerHandler(wPreferences.raise_delay,
1202 (WMCallback*)raiseWindow, scr);
1203 }
1204 }
1205 /* Install colormap for window, if the colormap installation mode
1206 * is colormap_follows_mouse */
1207 if (wPreferences.colormap_mode==WCM_POINTER) {
1208 if (wwin->client_win==event->xcrossing.window)
1209 wColormapInstallForWindow(scr, wwin);
1210 else
1211 wColormapInstallForWindow(scr, NULL);
1212 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001213 }
6830b057 dan2004-10-12 21:28:27 +00001214
9d2e6ef9 scottc1998-09-29 22:36:29 +00001215 /* a little kluge to hide the clip balloon */
1216 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
6830b057 dan2004-10-12 21:28:27 +00001217 if (!desc) {
1218 XUnmapWindow(dpy, scr->clip_balloon);
1219 scr->flags.clip_balloon_mapped = 0;
1220 } else {
1221 if (desc->parent_type!=WCLASS_DOCK_ICON
1222 || scr->clip_icon != desc->parent) {
1223 XUnmapWindow(dpy, scr->clip_balloon);
1224 scr->flags.clip_balloon_mapped = 0;
1225 }
1226 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001227 }
1228
1229 if (event->xcrossing.window == event->xcrossing.root
6830b057 dan2004-10-12 21:28:27 +00001230 && event->xcrossing.detail == NotifyNormal
1231 && event->xcrossing.detail != NotifyInferior
1232 && wPreferences.focus_mode != WKF_CLICK) {
1233
1234 wSetFocusTo(scr, scr->focused_window);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001235 }
1236
1237#ifdef BALLOON_TEXT
1238 wBalloonEnteredObject(scr, desc);
1239#endif
1240}
1241
1242
1243static void
1244handleLeaveNotify(XEvent *event)
1245{
1246 WObjDescriptor *desc = NULL;
34cd5125 kojima2000-01-20 11:51:42 +00001247
6830b057 dan2004-10-12 21:28:27 +00001248 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1249 (XPointer *)&desc)!=XCNOENT) {
9d2e6ef9 scottc1998-09-29 22:36:29 +00001250 if(desc->handle_leavenotify)
6830b057 dan2004-10-12 21:28:27 +00001251 (*desc->handle_leavenotify)(desc, event);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001252 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001253}
1254
1255
1256#ifdef SHAPE
1257static void
1258handleShapeNotify(XEvent *event)
1259{
1260 XShapeEvent *shev = (XShapeEvent*)event;
1261 WWindow *wwin;
9af1c6c4 dan1998-10-21 14:43:47 +00001262 XEvent ev;
652caa1f dan1999-10-21 00:54:37 +00001263#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +00001264 printf("got shape notify\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001265#endif
9af1c6c4 dan1998-10-21 14:43:47 +00001266 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
6830b057 dan2004-10-12 21:28:27 +00001267 XShapeEvent *sev = (XShapeEvent*)&ev;
1268
1269 if (sev->kind == ShapeBounding) {
1270 if (sev->shaped == shev->shaped) {
1271 *shev = *sev;
1272 } else {
1273 XPutBackEvent(dpy, &ev);
1274 break;
1275 }
1276 }
9af1c6c4 dan1998-10-21 14:43:47 +00001277 }
1278
1279 wwin = wWindowFor(shev->window);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001280 if (!wwin || shev->kind != ShapeBounding)
6830b057 dan2004-10-12 21:28:27 +00001281 return;
9af1c6c4 dan1998-10-21 14:43:47 +00001282
1283 if (!shev->shaped && wwin->flags.shaped) {
1284
6830b057 dan2004-10-12 21:28:27 +00001285 wwin->flags.shaped = 0;
1286 wWindowClearShape(wwin);
9af1c6c4 dan1998-10-21 14:43:47 +00001287
1288 } else if (shev->shaped) {
1289
6830b057 dan2004-10-12 21:28:27 +00001290 wwin->flags.shaped = 1;
1291 wWindowSetShape(wwin);
9af1c6c4 dan1998-10-21 14:43:47 +00001292 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001293}
1294#endif /* SHAPE */
1295
6830b057 dan2004-10-12 21:28:27 +00001296#ifdef KEEP_XKB_LOCK_STATUS
7f9f8894 kojima1999-03-15 23:41:22 +00001297/* please help ]d if you know what to do */
1298handleXkbIndicatorStateNotify(XEvent *event)
1299{
1300 WWindow *wwin;
1301 WScreen *scr;
1302 XkbStateRec staterec;
1303 int i;
1304
7f9f8894 kojima1999-03-15 23:41:22 +00001305 for (i=0; i<wScreenCount; i++) {
1306 scr = wScreenWithNumber(i);
6830b057 dan2004-10-12 21:28:27 +00001307 wwin = scr->focused_window;
1308 if (wwin && wwin->flags.focused) {
1309 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1310 if (wwin->frame->languagemode != staterec.group) {
1311 wwin->frame->last_languagemode = wwin->frame->languagemode;
1312 wwin->frame->languagemode = staterec.group;
1313 }
c28f3b2c id1999-05-20 23:30:53 +00001314#ifdef XKB_BUTTON_HINT
6830b057 dan2004-10-12 21:28:27 +00001315 if (wwin->frame->titlebar) {
1316 wFrameWindowPaint(wwin->frame);
1317 }
c28f3b2c id1999-05-20 23:30:53 +00001318#endif
6830b057 dan2004-10-12 21:28:27 +00001319 }
7f9f8894 kojima1999-03-15 23:41:22 +00001320 }
1321}
1322#endif /*KEEP_XKB_LOCK_STATUS*/
9d2e6ef9 scottc1998-09-29 22:36:29 +00001323
6830b057 dan2004-10-12 21:28:27 +00001324static void
9d2e6ef9 scottc1998-09-29 22:36:29 +00001325handleColormapNotify(XEvent *event)
1326{
1327 WWindow *wwin;
1328 WScreen *scr;
1329 Bool reinstall = False;
6830b057 dan2004-10-12 21:28:27 +00001330
9d2e6ef9 scottc1998-09-29 22:36:29 +00001331 wwin = wWindowFor(event->xcolormap.window);
1332 if (!wwin)
6830b057 dan2004-10-12 21:28:27 +00001333 return;
1334
9d2e6ef9 scottc1998-09-29 22:36:29 +00001335 scr = wwin->screen_ptr;
1336
1337 do {
6830b057 dan2004-10-12 21:28:27 +00001338 if (wwin) {
1339 if (event->xcolormap.new) {
1340 XWindowAttributes attr;
1341
1342 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1343
1344 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1345 scr->current_colormap = attr.colormap;
1346
1347 reinstall = True;
1348 } else if (event->xcolormap.state == ColormapUninstalled &&
1349 scr->current_colormap == event->xcolormap.colormap) {
1350
1351 /* some bastard app (like XV) removed our colormap */
1352 /*
1353 * can't enforce or things like xscreensaver wont work
1354 * reinstall = True;
1355 */
1356 } else if (event->xcolormap.state == ColormapInstalled &&
1357 scr->current_colormap == event->xcolormap.colormap) {
1358
1359 /* someone has put our colormap back */
1360 reinstall = False;
1361 }
1362 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001363 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
6830b057 dan2004-10-12 21:28:27 +00001364 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
9d2e6ef9 scottc1998-09-29 22:36:29 +00001365
1366 if (reinstall && scr->current_colormap!=None) {
6830b057 dan2004-10-12 21:28:27 +00001367 if (!scr->flags.colormap_stuff_blocked)
1368 XInstallColormap(dpy, scr->current_colormap);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001369 }
1370}
1371
1372
1373
1374static void
1375handleFocusIn(XEvent *event)
1376{
1377 WWindow *wwin;
1378
9d2e6ef9 scottc1998-09-29 22:36:29 +00001379 /*
1380 * For applications that like stealing the focus.
1381 */
6830b057 dan2004-10-12 21:28:27 +00001382 while (XCheckTypedEvent(dpy, FocusIn, event));
9d2e6ef9 scottc1998-09-29 22:36:29 +00001383 saveTimestamp(event);
9af1c6c4 dan1998-10-21 14:43:47 +00001384 if (event->xfocus.mode == NotifyUngrab
6830b057 dan2004-10-12 21:28:27 +00001385 || event->xfocus.mode == NotifyGrab
1386 || event->xfocus.detail > NotifyNonlinearVirtual) {
1387 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001388 }
1389
1390 wwin = wWindowFor(event->xfocus.window);
1391 if (wwin && !wwin->flags.focused) {
6830b057 dan2004-10-12 21:28:27 +00001392 if (wwin->flags.mapped)
1393 wSetFocusTo(wwin->screen_ptr, wwin);
1394 else
1395 wSetFocusTo(wwin->screen_ptr, NULL);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001396 } else if (!wwin) {
6830b057 dan2004-10-12 21:28:27 +00001397 WScreen *scr = wScreenForWindow(event->xfocus.window);
1398 if (scr)
1399 wSetFocusTo(scr, NULL);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001400 }
1401}
1402
1403
1404static WWindow*
1405windowUnderPointer(WScreen *scr)
1406{
1407 unsigned int mask;
1408 int foo;
1409 Window bar, win;
6830b057 dan2004-10-12 21:28:27 +00001410
9d2e6ef9 scottc1998-09-29 22:36:29 +00001411 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
6830b057 dan2004-10-12 21:28:27 +00001412 &mask))
1413 return wWindowFor(win);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001414 return NULL;
1415}
1416
3c046182 kojima1999-09-16 02:58:56 +00001417
30247c58 kojima2004-10-18 01:43:13 +00001418static int CheckFullScreenWindowFocused(WScreen *scr)
1419{
1420 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1421 return 1;
1422 else
1423 return 0;
1424}
3c046182 kojima1999-09-16 02:58:56 +00001425
1426
e7495baf dan1999-02-17 11:06:40 +00001427static void
9d2e6ef9 scottc1998-09-29 22:36:29 +00001428handleKeyPress(XEvent *event)
1429{
1430 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1431 WWindow *wwin = scr->focused_window;
1432 int i;
1433 int modifiers;
3c046182 kojima1999-09-16 02:58:56 +00001434 int command=-1, index;
6830b057 dan2004-10-12 21:28:27 +00001435#ifdef KEEP_XKB_LOCK_STATUS
1436 XkbStateRec staterec;
59eb9475 dan1998-11-03 12:53:26 +00001437#endif /*KEEP_XKB_LOCK_STATUS*/
9d2e6ef9 scottc1998-09-29 22:36:29 +00001438
1439 /* ignore CapsLock */
1440 modifiers = event->xkey.state & ValidModMask;
1441
1442 for (i=0; i<WKBD_LAST; i++) {
6830b057 dan2004-10-12 21:28:27 +00001443 if (wKeyBindings[i].keycode==0)
1444 continue;
1445
1446 if (wKeyBindings[i].keycode==event->xkey.keycode
1447 && (/*wKeyBindings[i].modifier==0
1448 ||*/ wKeyBindings[i].modifier==modifiers)) {
1449 command = i;
1450 break;
1451 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001452 }
9e615bcf dan2001-12-28 03:29:50 +00001453
1454
9d2e6ef9 scottc1998-09-29 22:36:29 +00001455 if (command < 0) {
0261c326 dan1999-01-06 15:22:33 +00001456#ifdef LITE
6830b057 dan2004-10-12 21:28:27 +00001457 {
0261c326 dan1999-01-06 15:22:33 +00001458#if 0
6830b057 dan2004-10-12 21:28:27 +00001459 }
0261c326 dan1999-01-06 15:22:33 +00001460#endif
1461#else
6830b057 dan2004-10-12 21:28:27 +00001462 if (!wRootMenuPerformShortcut(event)) {
0261c326 dan1999-01-06 15:22:33 +00001463#endif
6830b057 dan2004-10-12 21:28:27 +00001464 static int dontLoop = 0;
1465
1466 if (dontLoop > 10) {
1467 wwarning("problem with key event processing code");
1468 return;
1469 }
1470 dontLoop++;
1471 /* if the focused window is an internal window, try redispatching
1472 * the event to the managed window, as it can be a WINGs window */
1473 if (wwin && wwin->flags.internal_window
1474 && wwin->client_leader!=None) {
1475 /* client_leader contains the WINGs toplevel */
1476 event->xany.window = wwin->client_leader;
1477 WMHandleEvent(event);
1478 }
1479 dontLoop--;
1480 }
1481 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001482 }
1483
1484#define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1485#define ISFOCUSED(w) ((w) && (w)->flags.focused)
1486
1487 switch (command) {
0261c326 dan1999-01-06 15:22:33 +00001488#ifndef LITE
6830b057 dan2004-10-12 21:28:27 +00001489 case WKBD_ROOTMENU:
1490 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
30247c58 kojima2004-10-18 01:43:13 +00001491 if (!CheckFullScreenWindowFocused(scr)) {
6830b057 dan2004-10-12 21:28:27 +00001492 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
a10214a5 kojima2002-11-28 22:04:07 +00001493 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
6830b057 dan2004-10-12 21:28:27 +00001494 }
eb11184e dan2001-04-20 01:22:41 +00001495 break;
6830b057 dan2004-10-12 21:28:27 +00001496 case WKBD_WINDOWLIST:
30247c58 kojima2004-10-18 01:43:13 +00001497 if (!CheckFullScreenWindowFocused(scr)) {
6830b057 dan2004-10-12 21:28:27 +00001498 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
a10214a5 kojima2002-11-28 22:04:07 +00001499 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
6830b057 dan2004-10-12 21:28:27 +00001500 }
eb11184e dan2001-04-20 01:22:41 +00001501 break;
0261c326 dan1999-01-06 15:22:33 +00001502#endif /* !LITE */
6830b057 dan2004-10-12 21:28:27 +00001503 case WKBD_WINDOWMENU:
1504 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1505 OpenWindowMenu(wwin, wwin->frame_x,
1506 wwin->frame_y+wwin->frame->top_width, True);
1507 break;
1508 case WKBD_MINIATURIZE:
1509 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1510 && !WFLAGP(wwin, no_miniaturizable)) {
1511 CloseWindowMenu(scr);
1512
1513 if (wwin->protocols.MINIATURIZE_WINDOW)
1514 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1515 event->xbutton.time);
1516 else {
1517 wIconifyWindow(wwin);
1518 }
1519 }
1520 break;
1521 case WKBD_HIDE:
1522 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1523 WApplication *wapp = wApplicationOf(wwin->main_window);
1524 CloseWindowMenu(scr);
1525
1526 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1527 wHideApplication(wapp);
1528 }
1529 }
1530 break;
1531 case WKBD_HIDE_OTHERS:
1532 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1533 CloseWindowMenu(scr);
1534
96f8ab16 dan2002-01-04 05:44:20 +00001535 wHideOtherApplications(wwin);
6830b057 dan2004-10-12 21:28:27 +00001536 }
1537 break;
1538 case WKBD_MAXIMIZE:
1539 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
bd7943d9 dan2003-07-05 02:39:37 +00001540 int newdir = (MAX_VERTICAL|MAX_HORIZONTAL);
1541
1542 CloseWindowMenu(scr);
1543
6830b057 dan2004-10-12 21:28:27 +00001544 if (wwin->flags.maximized == newdir) {
1545 wUnmaximizeWindow(wwin);
bd7943d9 dan2003-07-05 02:39:37 +00001546 } else {
6830b057 dan2004-10-12 21:28:27 +00001547 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1548 }
1549 }
1550 break;
1551 case WKBD_VMAXIMIZE:
1552 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
bd7943d9 dan2003-07-05 02:39:37 +00001553 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1554
6830b057 dan2004-10-12 21:28:27 +00001555 CloseWindowMenu(scr);
bd7943d9 dan2003-07-05 02:39:37 +00001556
1557 if (newdir) {
6830b057 dan2004-10-12 21:28:27 +00001558 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1559 } else {
1560 wUnmaximizeWindow(wwin);
bd7943d9 dan2003-07-05 02:39:37 +00001561 }
6830b057 dan2004-10-12 21:28:27 +00001562 }
1563 break;
1564 case WKBD_HMAXIMIZE:
1565 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
bd7943d9 dan2003-07-05 02:39:37 +00001566 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1567
6830b057 dan2004-10-12 21:28:27 +00001568 CloseWindowMenu(scr);
bd7943d9 dan2003-07-05 02:39:37 +00001569
1570 if (newdir) {
6830b057 dan2004-10-12 21:28:27 +00001571 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1572 } else {
1573 wUnmaximizeWindow(wwin);
bd7943d9 dan2003-07-05 02:39:37 +00001574 }
6830b057 dan2004-10-12 21:28:27 +00001575 }
1576 break;
1577 case WKBD_RAISE:
1578 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1579 CloseWindowMenu(scr);
1580
1581 wRaiseFrame(wwin->frame->core);
1582 }
1583 break;
1584 case WKBD_LOWER:
1585 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1586 CloseWindowMenu(scr);
1587
1588 wLowerFrame(wwin->frame->core);
1589 }
1590 break;
1591 case WKBD_RAISELOWER:
1592 /* raise or lower the window under the pointer, not the
1593 * focused one
1594 */
1595 wwin = windowUnderPointer(scr);
1596 if (wwin)
1597 wRaiseLowerFrame(wwin->frame->core);
1598 break;
1599 case WKBD_SHADE:
1600 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1601 if (wwin->flags.shaded)
1602 wUnshadeWindow(wwin);
1603 else
1604 wShadeWindow(wwin);
1605 }
1606 break;
1607 case WKBD_MOVERESIZE:
1608 if (ISMAPPED(wwin) && ISFOCUSED(wwin) &&
1609 (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1610 CloseWindowMenu(scr);
1611
1612 wKeyboardMoveResizeWindow(wwin);
1613 }
1614 break;
1615 case WKBD_CLOSE:
1616 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1617 CloseWindowMenu(scr);
1618 if (wwin->protocols.DELETE_WINDOW)
1619 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1620 event->xkey.time);
1621 }
1622 break;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001623 case WKBD_SELECT:
6830b057 dan2004-10-12 21:28:27 +00001624 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1625 wSelectWindow(wwin, !wwin->flags.selected);
1626 }
1627 break;
1628 case WKBD_FOCUSNEXT:
1629 StartWindozeCycle(wwin, event, True);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001630 break;
e7495baf dan1999-02-17 11:06:40 +00001631
6830b057 dan2004-10-12 21:28:27 +00001632 case WKBD_FOCUSPREV:
1633 StartWindozeCycle(wwin, event, False);
1634 break;
e7495baf dan1999-02-17 11:06:40 +00001635
9af1c6c4 dan1998-10-21 14:43:47 +00001636#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1637#define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
6830b057 dan2004-10-12 21:28:27 +00001638 i = (scr->current_workspace/10)*10 + wk - 1;\
1639 if (wPreferences.ws_advance || i<scr->workspace_count)\
1640 wWorkspaceChange(scr, i);\
1641 break
9af1c6c4 dan1998-10-21 14:43:47 +00001642#else
1643#define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
6830b057 dan2004-10-12 21:28:27 +00001644 i = (scr->current_workspace/10)*10 + wk - 1;\
1645 if (wPreferences.ws_advance || i<scr->workspace_count)\
1646 wWorkspaceChange(scr, i);\
1647 break
9af1c6c4 dan1998-10-21 14:43:47 +00001648#endif
6830b057 dan2004-10-12 21:28:27 +00001649 GOTOWORKS(1);
1650 GOTOWORKS(2);
1651 GOTOWORKS(3);
1652 GOTOWORKS(4);
1653 GOTOWORKS(5);
1654 GOTOWORKS(6);
1655 GOTOWORKS(7);
1656 GOTOWORKS(8);
1657 GOTOWORKS(9);
1658 GOTOWORKS(10);
9af1c6c4 dan1998-10-21 14:43:47 +00001659#undef GOTOWORKS
6830b057 dan2004-10-12 21:28:27 +00001660 case WKBD_NEXTWORKSPACE:
1661 wWorkspaceRelativeChange(scr, 1);
1662 break;
1663 case WKBD_PREVWORKSPACE:
1664 wWorkspaceRelativeChange(scr, -1);
1665 break;
1666 case WKBD_WINDOW1:
1667 case WKBD_WINDOW2:
1668 case WKBD_WINDOW3:
1669 case WKBD_WINDOW4:
1670 case WKBD_WINDOW5:
1671 case WKBD_WINDOW6:
1672 case WKBD_WINDOW7:
1673 case WKBD_WINDOW8:
1674 case WKBD_WINDOW9:
1675 case WKBD_WINDOW10:
1676
1677 index = command-WKBD_WINDOW1;
1678
5c881364 kojima1999-09-18 21:17:03 +00001679 if (scr->shortcutWindows[index]) {
046403db dan2001-04-15 01:22:56 +00001680 WMArray *list = scr->shortcutWindows[index];
f8918e85 id1999-05-04 21:03:11 +00001681 int cw;
6830b057 dan2004-10-12 21:28:27 +00001682 int count = WMGetArrayItemCount(list);
1683 WWindow *twin;
1684 WMArrayIterator iter;
1685 WWindow *wwin;
f8918e85 id1999-05-04 21:03:11 +00001686
1687 wUnselectWindows(scr);
f8918e85 id1999-05-04 21:03:11 +00001688 cw = scr->current_workspace;
5c881364 kojima1999-09-18 21:17:03 +00001689
046403db dan2001-04-15 01:22:56 +00001690 WM_ETARETI_ARRAY(list, wwin, iter) {
6830b057 dan2004-10-12 21:28:27 +00001691 if (count > 1)
1692 wWindowChangeWorkspace(wwin, cw);
5c881364 kojima1999-09-18 21:17:03 +00001693
3c046182 kojima1999-09-16 02:58:56 +00001694 wMakeWindowVisible(wwin);
39513b9f kojima1999-05-14 04:30:01 +00001695
6830b057 dan2004-10-12 21:28:27 +00001696 if (count > 1)
1697 wSelectWindow(wwin, True);
5c881364 kojima1999-09-18 21:17:03 +00001698 }
6830b057 dan2004-10-12 21:28:27 +00001699
1700 /* rotate the order of windows, to create a cycling effect */
1701 twin = WMGetFromArray(list, 0);
1702 WMDeleteFromArray(list, 0);
1703 WMAddToArray(list, twin);
39513b9f kojima1999-05-14 04:30:01 +00001704
59eb9475 dan1998-11-03 12:53:26 +00001705 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
046403db dan2001-04-15 01:22:56 +00001706 if (scr->shortcutWindows[index]) {
1707 WMFreeArray(scr->shortcutWindows[index]);
1708 scr->shortcutWindows[index] = NULL;
1709 }
5c881364 kojima1999-09-18 21:17:03 +00001710
3c046182 kojima1999-09-16 02:58:56 +00001711 if (wwin->flags.selected && scr->selected_windows) {
046403db dan2001-04-15 01:22:56 +00001712 scr->shortcutWindows[index] =
1713 WMDuplicateArray(scr->selected_windows);
1714 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
6830b057 dan2004-10-12 21:28:27 +00001715 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
046403db dan2001-04-15 01:22:56 +00001716 } else {
1717 scr->shortcutWindows[index] = WMCreateArray(4);
1718 WMAddToArray(scr->shortcutWindows[index], wwin);
f8918e85 id1999-05-04 21:03:11 +00001719 }
046403db dan2001-04-15 01:22:56 +00001720
f8918e85 id1999-05-04 21:03:11 +00001721 wSelectWindow(wwin, !wwin->flags.selected);
1722 XFlush(dpy);
1723 wusleep(3000);
1724 wSelectWindow(wwin, !wwin->flags.selected);
1725 XFlush(dpy);
39513b9f kojima1999-05-14 04:30:01 +00001726
6830b057 dan2004-10-12 21:28:27 +00001727 } else if (scr->selected_windows
1728 && WMGetArrayItemCount(scr->selected_windows)) {
3c046182 kojima1999-09-16 02:58:56 +00001729
1730 if (wwin->flags.selected && scr->selected_windows) {
046403db dan2001-04-15 01:22:56 +00001731 if (scr->shortcutWindows[index]) {
1732 WMFreeArray(scr->shortcutWindows[index]);
f8918e85 id1999-05-04 21:03:11 +00001733 }
046403db dan2001-04-15 01:22:56 +00001734 scr->shortcutWindows[index] =
1735 WMDuplicateArray(scr->selected_windows);
f8918e85 id1999-05-04 21:03:11 +00001736 }
59eb9475 dan1998-11-03 12:53:26 +00001737 }
f8918e85 id1999-05-04 21:03:11 +00001738
59eb9475 dan1998-11-03 12:53:26 +00001739 break;
6830b057 dan2004-10-12 21:28:27 +00001740
1741 case WKBD_SWITCH_SCREEN:
1742 if (wScreenCount > 1) {
1743 WScreen *scr2;
1744 int i;
1745
1746 /* find index of this screen */
1747 for (i = 0; i < wScreenCount; i++) {
1748 if (wScreenWithNumber(i) == scr)
1749 break;
1750 }
1751 i++;
1752 if (i >= wScreenCount) {
1753 i = 0;
1754 }
1755 scr2 = wScreenWithNumber(i);
1756
1757 if (scr2) {
1758 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1759 scr2->scr_width/2, scr2->scr_height/2);
1760 }
1761 }
1762 break;
1763
1764 case WKBD_NEXTWSLAYER:
1765 case WKBD_PREVWSLAYER:
1766 {
1767 int row, column;
1768
1769 row = scr->current_workspace/10;
1770 column = scr->current_workspace%10;
1771
1772 if (command==WKBD_NEXTWSLAYER) {
1773 if ((row+1)*10 < scr->workspace_count)
1774 wWorkspaceChange(scr, column+(row+1)*10);
1775 } else {
1776 if (row > 0)
1777 wWorkspaceChange(scr, column+(row-1)*10);
1778 }
1779 }
1780 break;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001781 case WKBD_CLIPLOWER:
1782 if (!wPreferences.flags.noclip)
1783 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1784 break;
6830b057 dan2004-10-12 21:28:27 +00001785 case WKBD_CLIPRAISE:
9d2e6ef9 scottc1998-09-29 22:36:29 +00001786 if (!wPreferences.flags.noclip)
1787 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1788 break;
6830b057 dan2004-10-12 21:28:27 +00001789 case WKBD_CLIPRAISELOWER:
9d2e6ef9 scottc1998-09-29 22:36:29 +00001790 if (!wPreferences.flags.noclip)
1791 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1792 break;
59eb9475 dan1998-11-03 12:53:26 +00001793#ifdef KEEP_XKB_LOCK_STATUS
6830b057 dan2004-10-12 21:28:27 +00001794 case WKBD_TOGGLE:
4a473b8a kojima1999-04-10 18:27:21 +00001795 if(wPreferences.modelock) {
1796 /*toggle*/
1797 wwin = scr->focused_window;
1798
1799 if (wwin && wwin->flags.mapped
1800 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1801 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
b3112e2b id1999-05-22 21:30:35 +00001802 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
4a473b8a kojima1999-04-10 18:27:21 +00001803
b3112e2b id1999-05-22 21:30:35 +00001804 wwin->frame->languagemode = wwin->frame->last_languagemode;
1805 wwin->frame->last_languagemode = staterec.group;
1806 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
6830b057 dan2004-10-12 21:28:27 +00001807
4a473b8a kojima1999-04-10 18:27:21 +00001808 }
59eb9475 dan1998-11-03 12:53:26 +00001809 }
1810 break;
1811#endif /* KEEP_XKB_LOCK_STATUS */
9aca0d5f dan2004-10-12 01:34:32 +00001812#ifdef VIRTUAL_DESKTOP
6830b057 dan2004-10-12 21:28:27 +00001813 case WKBD_VDESK_LEFT:
1814 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1815 break;
9aca0d5f dan2004-10-12 01:34:32 +00001816
6830b057 dan2004-10-12 21:28:27 +00001817 case WKBD_VDESK_RIGHT:
1818 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1819 break;
9aca0d5f dan2004-10-12 01:34:32 +00001820
6830b057 dan2004-10-12 21:28:27 +00001821 case WKBD_VDESK_UP:
1822 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1823 break;
9aca0d5f dan2004-10-12 01:34:32 +00001824
6830b057 dan2004-10-12 21:28:27 +00001825 case WKBD_VDESK_DOWN:
1826 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1827 break;
9aca0d5f dan2004-10-12 01:34:32 +00001828#endif
59eb9475 dan1998-11-03 12:53:26 +00001829
9d2e6ef9 scottc1998-09-29 22:36:29 +00001830 }
1831}
1832
1833
6830b057 dan2004-10-12 21:28:27 +00001834static void
9d2e6ef9 scottc1998-09-29 22:36:29 +00001835handleMotionNotify(XEvent *event)
1836{
9d2e6ef9 scottc1998-09-29 22:36:29 +00001837 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1838
1839 if (wPreferences.scrollable_menus) {
84576113 dan2003-07-16 20:58:49 +00001840 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1841 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
a10214a5 kojima2002-11-28 22:04:07 +00001842
6830b057 dan2004-10-12 21:28:27 +00001843 if (scr->flags.jump_back_pending ||
1844 p.x <= (rect.pos.x + 1) ||
1845 p.x >= (rect.pos.x + rect.size.width - 2) ||
1846 p.y <= (rect.pos.y + 1) ||
1847 p.y >= (rect.pos.y + rect.size.height - 2)) {
1848 WMenu *menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001849#ifdef DEBUG
9aca0d5f dan2004-10-12 01:34:32 +00001850 printf("pointer at screen edge\n");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001851#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +00001852 menu = wMenuUnderPointer(scr);
1853 if (menu!=NULL)
1854 wMenuScroll(menu, event);
1855 }
1856 }
1857}
416e3a82 dan1999-01-25 19:06:50 +00001858
1859
e7495baf dan1999-02-17 11:06:40 +00001860static void
1861handleVisibilityNotify(XEvent *event)
1862{
1863 WWindow *wwin;
1864
1865 wwin = wWindowFor(event->xvisibility.window);
1866 if (!wwin)
6830b057 dan2004-10-12 21:28:27 +00001867 return;
1868 wwin->flags.obscured =
1869 (event->xvisibility.state == VisibilityFullyObscured);
e7495baf dan1999-02-17 11:06:40 +00001870}
6830b057 dan2004-10-12 21:28:27 +00001871
1872