fixed cosmetic bug in geom. dpy window for 8bpp
[wmaker-crm.git] / src / event.c
blob80dd12b327374281e99ab40c37c7154c8bf17d66
1 /* event.c- event loop and handling
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * 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.
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.
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
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "wconfig.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
32 #include <X11/Xlib.h>
33 #include <X11/Xutil.h>
34 #ifdef SHAPE
35 #include <X11/extensions/shape.h>
36 #endif
37 #ifdef XDND
38 #include "xdnd.h"
39 #endif
41 #ifdef KEEP_XKB_LOCK_STATUS
42 #include <X11/XKBlib.h>
43 #endif /* KEEP_XKB_LOCK_STATUS */
45 #include "WindowMaker.h"
46 #include "window.h"
47 #include "actions.h"
48 #include "client.h"
49 #include "funcs.h"
50 #include "keybind.h"
51 #include "application.h"
52 #include "stacking.h"
53 #include "defaults.h"
54 #include "workspace.h"
55 #include "dock.h"
56 #include "framewin.h"
57 #include "properties.h"
58 #include "balloon.h"
59 #include "list.h"
60 #ifdef GNOME_STUFF
61 # include "gnome.h"
62 #endif
63 #ifdef KWM_HINTS
64 # include "kwm.h"
65 #endif
67 /******** Global Variables **********/
68 extern XContext wWinContext;
70 extern Cursor wCursor[WCUR_LAST];
72 extern WShortKey wKeyBindings[WKBD_LAST];
73 extern int wScreenCount;
74 extern Time LastTimestamp;
75 extern Time LastFocusChange;
77 extern WPreferences wPreferences;
79 #define MOD_MASK wPreferences.modifier_mask
81 extern Atom _XA_WM_COLORMAP_NOTIFY;
83 extern Atom _XA_WM_CHANGE_STATE;
84 extern Atom _XA_WM_DELETE_WINDOW;
85 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
86 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
87 extern Atom _XA_WINDOWMAKER_COMMAND;
89 #ifdef OFFIX_DND
90 extern Atom _XA_DND_PROTOCOL;
91 #endif
94 #ifdef SHAPE
95 extern Bool wShapeSupported;
96 extern int wShapeEventBase;
97 #endif
99 #ifdef KEEP_XKB_LOCK_STATUS
100 extern int wXkbEventBase;
101 #endif
103 /* special flags */
104 extern char WDelayedActionSet;
107 /************ Local stuff ***********/
110 static void saveTimestamp(XEvent *event);
111 static void handleColormapNotify();
112 static void handleMapNotify(), handleUnmapNotify();
113 static void handleButtonPress(), handleExpose();
114 static void handleDestroyNotify();
115 static void handleConfigureRequest();
116 static void handleMapRequest();
117 static void handlePropertyNotify();
118 static void handleEnterNotify();
119 static void handleLeaveNotify();
120 static void handleExtensions();
121 static void handleClientMessage();
122 static void handleKeyPress();
123 static void handleFocusIn();
124 static void handleMotionNotify();
125 static void handleVisibilityNotify();
128 #ifdef SHAPE
129 static void handleShapeNotify();
130 #endif
132 /* called from the signal handler */
133 void NotifyDeadProcess(pid_t pid, unsigned char status);
135 /* real dead process handler */
136 static void handleDeadProcess(void *foo);
139 typedef struct DeadProcesses {
140 pid_t pid;
141 unsigned char exit_status;
142 } DeadProcesses;
144 /* stack of dead processes */
145 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
146 static int deadProcessPtr=0;
149 typedef struct DeathHandler {
150 WDeathHandler *callback;
151 pid_t pid;
152 struct DeathHandler *next;
153 void *client_data;
154 } DeathHandler;
156 static DeathHandler *deathHandler=NULL;
160 WMagicNumber
161 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
163 DeathHandler *handler;
165 handler = malloc(sizeof(DeathHandler));
166 if (!handler)
167 return 0;
169 handler->pid = pid;
170 handler->callback = callback;
171 handler->client_data = cdata;
173 handler->next = deathHandler;
175 deathHandler = handler;
177 return handler;
182 void
183 wDeleteDeathHandler(WMagicNumber id)
185 DeathHandler *tmp, *handler=(DeathHandler*)id;
187 if (!handler || !deathHandler)
188 return;
190 tmp = deathHandler;
191 if (tmp==handler) {
192 deathHandler = handler->next;
193 free(handler);
194 } else {
195 while (tmp->next) {
196 if (tmp->next==handler) {
197 tmp->next=handler->next;
198 free(handler);
199 break;
201 tmp = tmp->next;
207 void
208 DispatchEvent(XEvent *event)
210 if (deathHandler)
211 handleDeadProcess(NULL);
213 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
214 WCHANGE_STATE(WSTATE_EXITING);
215 /* received SIGTERM */
217 * WMHandleEvent() can't be called from anything
218 * executed inside here, or we can get in a infinite
219 * recursive loop.
221 Shutdown(WSExitMode);
223 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
224 WCHANGE_STATE(WSTATE_RESTARTING);
226 Shutdown(WSRestartPreparationMode);
227 /* received SIGHUP */
228 Restart(NULL, True);
231 /* for the case that all that is wanted to be dispatched is
232 * the stuff above */
233 if (!event)
234 return;
236 saveTimestamp(event);
237 switch (event->type) {
238 case MapRequest:
239 handleMapRequest(event);
240 break;
242 case KeyPress:
243 handleKeyPress(event);
244 break;
246 case MotionNotify:
247 handleMotionNotify(event);
248 break;
250 case ConfigureRequest:
251 handleConfigureRequest(event);
252 break;
254 case DestroyNotify:
255 handleDestroyNotify(event);
256 break;
258 case MapNotify:
259 handleMapNotify(event);
260 break;
262 case UnmapNotify:
263 handleUnmapNotify(event);
264 break;
266 case ButtonPress:
267 handleButtonPress(event);
268 break;
270 case Expose:
271 handleExpose(event);
272 break;
274 case PropertyNotify:
275 handlePropertyNotify(event);
276 break;
278 case EnterNotify:
279 handleEnterNotify(event);
280 break;
282 case LeaveNotify:
283 handleLeaveNotify(event);
284 break;
286 case ClientMessage:
287 handleClientMessage(event);
288 break;
290 case ColormapNotify:
291 handleColormapNotify(event);
292 break;
294 case MappingNotify:
295 if (event->xmapping.request == MappingKeyboard
296 || event->xmapping.request == MappingModifier)
297 XRefreshKeyboardMapping(&event->xmapping);
298 break;
300 case FocusIn:
301 handleFocusIn(event);
302 break;
304 case VisibilityNotify:
305 handleVisibilityNotify(event);
306 break;
307 default:
308 handleExtensions(event);
309 break;
315 *----------------------------------------------------------------------
316 * EventLoop-
317 * Processes X and internal events indefinitely.
319 * Returns:
320 * Never returns
322 * Side effects:
323 * The LastTimestamp global variable is updated.
324 *----------------------------------------------------------------------
326 void
327 EventLoop()
329 XEvent event;
331 for(;;) {
332 WMNextEvent(dpy, &event);
333 WMHandleEvent(&event);
339 Bool
340 IsDoubleClick(WScreen *scr, XEvent *event)
342 if ((scr->last_click_time>0) &&
343 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
344 && (event->xbutton.button == scr->last_click_button)
345 && (event->xbutton.window == scr->last_click_window)) {
347 scr->flags.next_click_is_not_double = 1;
348 scr->last_click_time = 0;
349 scr->last_click_window = event->xbutton.window;
351 return True;
353 return False;
357 void
358 NotifyDeadProcess(pid_t pid, unsigned char status)
360 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
361 wwarning("stack overflow: too many dead processes");
362 return;
364 /* stack the process to be handled later,
365 * as this is called from the signal handler */
366 deadProcesses[deadProcessPtr].pid = pid;
367 deadProcesses[deadProcessPtr].exit_status = status;
368 deadProcessPtr++;
372 static void
373 handleDeadProcess(void *foo)
375 DeathHandler *tmp;
376 int i;
378 for (i=0; i<deadProcessPtr; i++) {
379 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
382 if (!deathHandler) {
383 deadProcessPtr=0;
384 return;
387 /* get the pids on the queue and call handlers */
388 while (deadProcessPtr>0) {
389 deadProcessPtr--;
391 tmp = deathHandler;
392 while (tmp) {
393 DeathHandler *t;
395 t = tmp->next;
397 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
398 (*tmp->callback)(tmp->pid,
399 deadProcesses[deadProcessPtr].exit_status,
400 tmp->client_data);
401 wDeleteDeathHandler(tmp);
403 tmp = t;
409 static void
410 saveTimestamp(XEvent *event)
412 LastTimestamp = CurrentTime;
414 switch (event->type) {
415 case ButtonRelease:
416 case ButtonPress:
417 LastTimestamp = event->xbutton.time;
418 break;
419 case KeyPress:
420 case KeyRelease:
421 LastTimestamp = event->xkey.time;
422 break;
423 case MotionNotify:
424 LastTimestamp = event->xmotion.time;
425 break;
426 case PropertyNotify:
427 LastTimestamp = event->xproperty.time;
428 break;
429 case EnterNotify:
430 case LeaveNotify:
431 LastTimestamp = event->xcrossing.time;
432 break;
433 case SelectionClear:
434 LastTimestamp = event->xselectionclear.time;
435 break;
436 case SelectionRequest:
437 LastTimestamp = event->xselectionrequest.time;
438 break;
439 case SelectionNotify:
440 LastTimestamp = event->xselection.time;
441 #ifdef XDND
442 wXDNDProcessSelection(event);
443 #endif
444 break;
449 static void
450 handleExtensions(XEvent *event)
452 #ifdef KEEP_XKB_LOCK_STATUS
453 XkbEvent *xkbevent;
454 xkbevent = (XkbEvent *)event;
455 #endif /*KEEP_XKB_LOCK_STATUS*/
456 #ifdef SHAPE
457 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
458 handleShapeNotify(event);
460 #endif
461 #ifdef KEEP_XKB_LOCK_STATUS
462 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
463 handleXkbIndicatorStateNotify(event);
465 #endif /*KEEP_XKB_LOCK_STATUS*/
469 static void
470 handleMapRequest(XEvent *ev)
472 WWindow *wwin;
473 WScreen *scr = NULL;
474 Window window = ev->xmaprequest.window;
476 #ifdef DEBUG
477 printf("got map request for %x\n", (unsigned)window);
478 #endif
480 if ((wwin = wWindowFor(window))) {
481 if (wwin->flags.shaded) {
482 wUnshadeWindow(wwin);
484 /* deiconify window */
485 if (wwin->flags.miniaturized) {
486 wDeiconifyWindow(wwin);
487 } else if (wwin->flags.hidden) {
488 WApplication *wapp = wApplicationOf(wwin->main_window);
489 /* go to the last workspace that the user worked on the app */
490 #ifndef REDUCE_APPICONS
491 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
492 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
494 if (wapp) {
495 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
497 #endif
498 wUnhideApplication(wapp, False, False);
500 return;
503 scr = wScreenForRootWindow(ev->xmaprequest.parent);
505 wwin = wManageWindow(scr, window);
508 * This is to let the Dock know that the application it launched
509 * has already been mapped (eg: it has finished launching).
510 * It is not necessary for normally docked apps, but is needed for
511 * apps that were forcedly docked (like with dockit).
513 if (scr->last_dock) {
514 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
515 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
516 else
517 wDockTrackWindowLaunch(scr->last_dock, window);
520 if (wwin) {
521 wClientSetState(wwin, NormalState, None);
522 if (wwin->flags.maximized) {
523 wMaximizeWindow(wwin, wwin->flags.maximized);
525 if (wwin->flags.shaded) {
526 wwin->flags.shaded = 0;
527 wwin->flags.skip_next_animation = 1;
528 wShadeWindow(wwin);
530 if (wwin->flags.miniaturized) {
531 wwin->flags.miniaturized = 0;
532 wwin->flags.skip_next_animation = 1;
533 wIconifyWindow(wwin);
535 if (wwin->flags.hidden) {
536 WApplication *wapp = wApplicationOf(wwin->main_window);
538 wwin->flags.hidden = 0;
539 wwin->flags.skip_next_animation = 1;
540 if (wapp) {
541 wHideApplication(wapp);
548 static void
549 handleDestroyNotify(XEvent *event)
551 WWindow *wwin;
552 WApplication *app;
553 Window window = event->xdestroywindow.window;
555 #ifdef DEBUG
556 puts("got destroy notify");
557 #endif
559 wwin = wWindowFor(window);
560 if (wwin) {
561 wUnmanageWindow(wwin, False, True);
564 app = wApplicationOf(window);
565 if (app) {
566 if (window == app->main_window) {
567 app->refcount = 0;
568 wwin = app->main_window_desc->screen_ptr->focused_window;
569 while (wwin) {
570 if (wwin->main_window == window) {
571 wwin->main_window = None;
573 wwin = wwin->prev;
576 wApplicationDestroy(app);
579 #ifdef KWM_HINTS
580 wKWMCheckDestroy(&event->xdestroywindow);
581 #endif
586 static void
587 handleExpose(XEvent *event)
589 WObjDescriptor *desc;
590 XEvent ev;
592 #ifdef DEBUG
593 puts("got expose");
594 #endif
596 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
598 if (XFindContext(dpy, event->xexpose.window, wWinContext,
599 (XPointer *)&desc)==XCNOENT) {
600 return;
603 if (desc->handle_expose) {
604 (*desc->handle_expose)(desc, event);
609 /* bindable */
610 static void
611 handleButtonPress(XEvent *event)
613 WObjDescriptor *desc;
614 WScreen *scr;
616 #ifdef DEBUG
617 puts("got button press");
618 #endif
620 scr = wScreenForRootWindow(event->xbutton.root);
622 #ifdef BALLOON_TEXT
623 wBalloonHide(scr);
624 #endif
627 #ifndef LITE
628 if (event->xbutton.window==scr->root_win) {
630 if (event->xbutton.button==wPreferences.menu_button) {
631 OpenRootMenu(scr, event->xbutton.x_root,
632 event->xbutton.y_root, False);
633 /* ugly hack */
634 if (scr->root_menu) {
635 if (scr->root_menu->brother->flags.mapped)
636 event->xbutton.window = scr->root_menu->brother->frame->core->window;
637 else
638 event->xbutton.window = scr->root_menu->frame->core->window;
640 } else if (event->xbutton.button==wPreferences.windowl_button) {
641 OpenSwitchMenu(scr, event->xbutton.x_root,
642 event->xbutton.y_root, False);
643 if (scr->switch_menu) {
644 if (scr->switch_menu->brother->flags.mapped)
645 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
646 else
647 event->xbutton.window = scr->switch_menu->frame->core->window;
649 } else if (event->xbutton.button==wPreferences.select_button) {
650 wUnselectWindows(scr);
651 wSelectWindows(scr, event);
653 #ifdef MOUSE_WS_SWITCH
654 else if (event->xbutton.button==Button5) {
656 wWorkspaceRelativeChange(scr, -1);
658 } else if (event->xbutton.button==Button4) {
660 wWorkspaceRelativeChange(scr, 1);
663 #endif /* MOUSE_WS_SWITCH */
664 #ifdef GNOME_STUFF
665 else if (wGNOMEProxyizeButtonEvent(scr, event))
666 return;
667 #endif
669 #endif /* !LITE */
671 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
672 (XPointer *)&desc)==XCNOENT) {
673 if (XFindContext(dpy, event->xbutton.window, wWinContext,
674 (XPointer *)&desc)==XCNOENT) {
675 return;
679 if (desc->handle_mousedown!=NULL) {
680 (*desc->handle_mousedown)(desc, event);
683 if (desc->parent_type == WCLASS_WINDOW) {
684 XSync(dpy, 0);
686 if (event->xbutton.state & MOD_MASK) {
687 XAllowEvents(dpy, AsyncPointer, CurrentTime);
690 if (wPreferences.focus_mode == WKF_CLICK) {
691 if (wPreferences.ignore_focus_click) {
692 XAllowEvents(dpy, AsyncPointer, CurrentTime);
694 XAllowEvents(dpy, ReplayPointer, CurrentTime);
696 XSync(dpy, 0);
697 } else if (desc->parent_type == WCLASS_APPICON
698 || desc->parent_type == WCLASS_MINIWINDOW
699 || desc->parent_type == WCLASS_DOCK_ICON) {
700 if (event->xbutton.state & MOD_MASK) {
701 XSync(dpy, 0);
702 XAllowEvents(dpy, AsyncPointer, CurrentTime);
703 XSync(dpy, 0);
707 /* save double-click information */
708 if (scr->flags.next_click_is_not_double) {
709 scr->flags.next_click_is_not_double = 0;
710 } else {
711 scr->last_click_time = event->xbutton.time;
712 scr->last_click_button = event->xbutton.button;
713 scr->last_click_window = event->xbutton.window;
718 static void
719 handleMapNotify(XEvent *event)
721 WWindow *wwin;
723 #ifdef DEBUG
724 puts("got map");
725 #endif
727 wwin = wWindowFor(event->xmap.event);
728 if (wwin && wwin->client_win == event->xmap.event) {
729 if (wwin->flags.miniaturized) {
730 wDeiconifyWindow(wwin);
731 } else {
732 XGrabServer(dpy);
733 wWindowMap(wwin);
734 wClientSetState(wwin, NormalState, None);
735 XUngrabServer(dpy);
741 static void
742 handleUnmapNotify(XEvent *event)
744 WWindow *wwin;
745 XEvent ev;
746 Bool withdraw = False;
748 #ifdef DEBUG
749 puts("got unmap");
750 #endif
752 /* only process windows with StructureNotify selected
753 * (ignore SubstructureNotify) */
754 wwin = wWindowFor(event->xunmap.window);
755 if (!wwin)
756 return;
758 /* whether the event is a Withdrawal request */
759 if (event->xunmap.event == wwin->screen_ptr->root_win
760 && event->xunmap.send_event)
761 withdraw = True;
763 if (wwin->client_win != event->xunmap.event && !withdraw)
764 return;
766 if (!wwin->flags.mapped && !withdraw
767 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
768 && !wwin->flags.miniaturized && !wwin->flags.hidden)
769 return;
771 XGrabServer(dpy);
772 XUnmapWindow(dpy, wwin->frame->core->window);
773 wwin->flags.mapped = 0;
774 XSync(dpy, 0);
775 /* check if the window was destroyed */
776 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
777 DispatchEvent(&ev);
778 } else {
779 Bool reparented = False;
781 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
782 reparented = True;
784 /* withdraw window */
785 wwin->flags.mapped = 0;
786 if (!reparented)
787 wClientSetState(wwin, WithdrawnState, None);
789 /* if the window was reparented, do not reparent it back to the
790 * root window */
791 wUnmanageWindow(wwin, !reparented, False);
793 XUngrabServer(dpy);
797 static void
798 handleConfigureRequest(XEvent *event)
800 WWindow *wwin;
802 #ifdef DEBUG
803 puts("got configure request");
804 #endif
805 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
807 * Configure request for unmapped window
809 wClientConfigure(NULL, &(event->xconfigurerequest));
810 } else {
811 wClientConfigure(wwin, &(event->xconfigurerequest));
816 static void
817 handlePropertyNotify(XEvent *event)
819 WWindow *wwin;
820 WApplication *wapp;
821 Window jr;
822 int ji;
823 unsigned int ju;
824 WScreen *scr;
826 #ifdef DEBUG
827 puts("got property notify");
828 #endif
829 if ((wwin=wWindowFor(event->xproperty.window))) {
830 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
831 &ju, &ju, &ju, &ju)) {
832 return;
834 wClientCheckProperty(wwin, &event->xproperty);
836 wapp = wApplicationOf(event->xproperty.window);
837 if (wapp) {
838 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
841 scr = wScreenForWindow(event->xproperty.window);
842 if (scr && scr->root_win == event->xproperty.window) {
843 #ifdef KWM_HINTS
844 wKWMCheckRootHintChange(scr, &event->xproperty);
845 #endif
850 static void
851 handleClientMessage(XEvent *event)
853 WWindow *wwin;
854 WObjDescriptor *desc;
856 #ifdef DEBUG
857 puts("got client message");
858 #endif
859 /* handle transition from Normal to Iconic state */
860 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
861 && event->xclient.format == 32
862 && event->xclient.data.l[0] == IconicState) {
864 wwin = wWindowFor(event->xclient.window);
865 if (!wwin) return;
866 if (!wwin->flags.miniaturized)
867 wIconifyWindow(wwin);
868 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
869 && event->xclient.format == 32) {
870 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
872 if (!scr)
873 return;
875 if (event->xclient.data.l[1] == 1) { /* starting */
876 wColormapAllowClientInstallation(scr, True);
877 } else { /* stopping */
878 wColormapAllowClientInstallation(scr, False);
880 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
882 wDefaultsCheckDomains("bla");
884 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
885 WApplication *wapp;
886 int done=0;
887 wapp = wApplicationOf(event->xclient.window);
888 if (wapp) {
889 switch (event->xclient.data.l[0]) {
890 case WMFHideOtherApplications:
891 wHideOtherApplications(wapp->main_window_desc);
892 done = 1;
893 break;
895 case WMFHideApplication:
896 wHideApplication(wapp);
897 done = 1;
898 break;
901 if (!done) {
902 wwin = wWindowFor(event->xclient.window);
903 if (wwin) {
904 switch (event->xclient.data.l[0]) {
905 case WMFHideOtherApplications:
906 wHideOtherApplications(wwin);
907 break;
909 case WMFHideApplication:
910 wHideApplication(wApplicationOf(wwin->main_window));
911 break;
915 #ifdef GNOME_STUFF
916 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
917 /* do nothing */
918 #endif /* GNOME_STUFF */
919 #ifdef KWM_HINTS
920 } else if (wKWMProcessClientMessage(&event->xclient)) {
921 /* do nothing */
922 #endif /* KWM_HINTS */
923 #ifdef XDND
924 } else if (wXDNDProcessClientMessage(&event->xclient)) {
925 /* do nothing */
926 #endif /* XDND */
927 #ifdef OFFIX_DND
928 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
929 WScreen *scr = wScreenForWindow(event->xclient.window);
930 if (scr && wDockReceiveDNDDrop(scr,event))
931 goto redirect_message;
932 #endif /* OFFIX_DND */
933 } else {
934 #ifdef OFFIX_DND
935 redirect_message:
936 #endif
938 * Non-standard thing, but needed by OffiX DND.
939 * For when the icon frame gets a ClientMessage
940 * that should have gone to the icon_window.
942 if (XFindContext(dpy, event->xbutton.window, wWinContext,
943 (XPointer *)&desc)!=XCNOENT) {
944 struct WIcon *icon=NULL;
946 if (desc->parent_type == WCLASS_MINIWINDOW) {
947 icon = (WIcon*)desc->parent;
948 } else if (desc->parent_type == WCLASS_DOCK_ICON
949 || desc->parent_type == WCLASS_APPICON) {
950 icon = ((WAppIcon*)desc->parent)->icon;
952 if (icon && (wwin=icon->owner)) {
953 if (wwin->client_win!=event->xclient.window) {
954 event->xclient.window = wwin->client_win;
955 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
956 event);
964 static void
965 raiseWindow(WScreen *scr)
967 WWindow *wwin;
969 scr->autoRaiseTimer = NULL;
971 wwin = wWindowFor(scr->autoRaiseWindow);
972 if (!wwin)
973 return;
975 if (!wwin->flags.destroyed && wwin->flags.focused) {
976 wRaiseFrame(wwin->frame->core);
977 /* this is needed or a race condition will occur */
978 XSync(dpy, False);
983 static void
984 handleEnterNotify(XEvent *event)
986 WWindow *wwin;
987 WObjDescriptor *desc = NULL;
988 XEvent ev;
989 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
992 #ifdef DEBUG
993 puts("got enter notify");
994 #endif
996 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
997 &ev)) {
998 /* already left the window... */
999 saveTimestamp(&ev);
1000 if (ev.xcrossing.mode==event->xcrossing.mode
1001 && ev.xcrossing.detail==event->xcrossing.detail) {
1002 return;
1006 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1007 (XPointer *)&desc)!=XCNOENT) {
1008 if(desc->handle_enternotify)
1009 (*desc->handle_enternotify)(desc, event);
1012 /* enter to window */
1013 wwin = wWindowFor(event->xcrossing.window);
1014 if (!wwin) {
1015 if (wPreferences.focus_mode==WKF_POINTER
1016 && event->xcrossing.window==event->xcrossing.root) {
1017 wSetFocusTo(scr, NULL);
1019 if (wPreferences.colormap_mode==WKF_POINTER) {
1020 wColormapInstallForWindow(scr, NULL);
1022 if (scr->autoRaiseTimer
1023 && event->xcrossing.root==event->xcrossing.window) {
1024 WMDeleteTimerHandler(scr->autoRaiseTimer);
1025 scr->autoRaiseTimer = NULL;
1027 } else {
1028 /* set auto raise timer even if in focus-follows-mouse mode
1029 * and the event is for the frame window, even if the window
1030 * has focus already. useful if you move the pointer from a focused
1031 * window to the root window and back pretty fast
1033 * set focus if in focus-follows-mouse mode and the event
1034 * is for the frame window and window doesn't have focus yet */
1035 if ((wPreferences.focus_mode==WKF_POINTER
1036 || wPreferences.focus_mode==WKF_SLOPPY)
1037 && wwin->frame->core->window==event->xcrossing.window
1038 && !scr->flags.doing_alt_tab) {
1040 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1041 wSetFocusTo(scr, wwin);
1043 if (scr->autoRaiseTimer)
1044 WMDeleteTimerHandler(scr->autoRaiseTimer);
1045 scr->autoRaiseTimer = NULL;
1047 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1048 scr->autoRaiseWindow = wwin->frame->core->window;
1049 scr->autoRaiseTimer
1050 = WMAddTimerHandler(wPreferences.raise_delay,
1051 (WMCallback*)raiseWindow, scr);
1054 /* Install colormap for window, if the colormap installation mode
1055 * is colormap_follows_mouse */
1056 if (wPreferences.colormap_mode==WKF_POINTER) {
1057 if (wwin->client_win==event->xcrossing.window)
1058 wColormapInstallForWindow(scr, wwin);
1059 else
1060 wColormapInstallForWindow(scr, NULL);
1064 /* a little kluge to hide the clip balloon */
1065 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1066 if (!desc) {
1067 XUnmapWindow(dpy, scr->clip_balloon);
1068 scr->flags.clip_balloon_mapped = 0;
1069 } else {
1070 if (desc->parent_type!=WCLASS_DOCK_ICON
1071 || scr->clip_icon != desc->parent) {
1072 XUnmapWindow(dpy, scr->clip_balloon);
1073 scr->flags.clip_balloon_mapped = 0;
1078 if (event->xcrossing.window == event->xcrossing.root
1079 && event->xcrossing.detail == NotifyNormal
1080 && event->xcrossing.detail != NotifyInferior
1081 && wPreferences.focus_mode != WKF_CLICK) {
1083 wSetFocusTo(scr, scr->focused_window);
1086 #ifdef BALLOON_TEXT
1087 wBalloonEnteredObject(scr, desc);
1088 #endif
1092 static void
1093 handleLeaveNotify(XEvent *event)
1095 WObjDescriptor *desc = NULL;
1097 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1098 (XPointer *)&desc)!=XCNOENT) {
1099 if(desc->handle_leavenotify)
1100 (*desc->handle_leavenotify)(desc, event);
1102 if (event->xcrossing.window == event->xcrossing.root
1103 && event->xcrossing.mode == NotifyNormal
1104 && event->xcrossing.detail != NotifyInferior
1105 && wPreferences.focus_mode != WKF_CLICK) {
1107 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1109 wSetFocusTo(scr, NULL);
1114 #ifdef SHAPE
1115 static void
1116 handleShapeNotify(XEvent *event)
1118 XShapeEvent *shev = (XShapeEvent*)event;
1119 WWindow *wwin;
1120 XEvent ev;
1122 #ifdef DEBUG
1123 puts("got shape notify");
1124 #endif
1126 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1127 XShapeEvent *sev = (XShapeEvent*)&ev;
1129 if (sev->kind == ShapeBounding) {
1130 if (sev->shaped == shev->shaped) {
1131 *shev = *sev;
1132 } else {
1133 XPutBackEvent(dpy, &ev);
1134 break;
1139 wwin = wWindowFor(shev->window);
1140 if (!wwin || shev->kind != ShapeBounding)
1141 return;
1143 if (!shev->shaped && wwin->flags.shaped) {
1145 wwin->flags.shaped = 0;
1146 wWindowClearShape(wwin);
1148 } else if (shev->shaped) {
1150 wwin->flags.shaped = 1;
1151 wWindowSetShape(wwin);
1154 #endif /* SHAPE */
1156 #ifdef KEEP_XKB_LOCK_STATUS
1157 /* please help ]d if you know what to do */
1158 handleXkbIndicatorStateNotify(XEvent *event)
1160 WWindow *wwin;
1161 WScreen *scr;
1162 XkbStateRec staterec;
1163 int i;
1165 for (i=0; i<wScreenCount; i++) {
1166 scr = wScreenWithNumber(i);
1167 wwin = scr->focused_window;
1168 if (wwin && wwin->flags.focused) {
1169 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1170 if (wwin->frame->languagemode != staterec.group) {
1171 wwin->frame->last_languagemode = wwin->frame->languagemode;
1172 wwin->frame->languagemode = staterec.group;
1174 #ifdef XKB_BUTTON_HINT
1175 if (wwin->frame->titlebar) {
1176 wFrameWindowPaint(wwin->frame);
1178 #endif
1182 #endif /*KEEP_XKB_LOCK_STATUS*/
1184 static void
1185 handleColormapNotify(XEvent *event)
1187 WWindow *wwin;
1188 WScreen *scr;
1189 Bool reinstall = False;
1191 wwin = wWindowFor(event->xcolormap.window);
1192 if (!wwin)
1193 return;
1195 scr = wwin->screen_ptr;
1197 do {
1198 if (wwin) {
1199 if (event->xcolormap.new) {
1200 XWindowAttributes attr;
1202 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1204 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1205 scr->current_colormap = attr.colormap;
1207 reinstall = True;
1208 } else if (event->xcolormap.state == ColormapUninstalled &&
1209 scr->current_colormap == event->xcolormap.colormap) {
1211 /* some bastard app (like XV) removed our colormap */
1213 * can't enforce or things like xscreensaver wont work
1214 * reinstall = True;
1216 } else if (event->xcolormap.state == ColormapInstalled &&
1217 scr->current_colormap == event->xcolormap.colormap) {
1219 /* someone has put our colormap back */
1220 reinstall = False;
1223 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1224 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1226 if (reinstall && scr->current_colormap!=None) {
1227 if (!scr->flags.colormap_stuff_blocked)
1228 XInstallColormap(dpy, scr->current_colormap);
1234 static void
1235 handleFocusIn(XEvent *event)
1237 WWindow *wwin;
1240 * For applications that like stealing the focus.
1242 while (XCheckTypedEvent(dpy, FocusIn, event));
1243 saveTimestamp(event);
1244 if (event->xfocus.mode == NotifyUngrab
1245 || event->xfocus.mode == NotifyGrab
1246 || event->xfocus.detail > NotifyNonlinearVirtual) {
1247 return;
1250 wwin = wWindowFor(event->xfocus.window);
1251 if (wwin && !wwin->flags.focused) {
1252 if (wwin->flags.mapped)
1253 wSetFocusTo(wwin->screen_ptr, wwin);
1254 else
1255 wSetFocusTo(wwin->screen_ptr, NULL);
1256 } else if (!wwin) {
1257 WScreen *scr = wScreenForWindow(event->xfocus.window);
1258 if (scr)
1259 wSetFocusTo(scr, NULL);
1264 static WWindow*
1265 windowUnderPointer(WScreen *scr)
1267 unsigned int mask;
1268 int foo;
1269 Window bar, win;
1271 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1272 &mask))
1273 return wWindowFor(win);
1274 return NULL;
1277 #ifdef WEENDOZE_CYCLE
1279 static WWindow*
1280 nextToFocusAfter(WWindow *wwin)
1282 WWindow *tmp = wwin->prev;
1284 while (tmp) {
1285 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1287 return tmp;
1289 tmp = tmp->prev;
1292 tmp = wwin;
1293 /* start over from the beginning of the list */
1294 while (tmp->next)
1295 tmp = tmp->next;
1297 while (tmp && tmp != wwin) {
1298 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1300 return tmp;
1302 tmp = tmp->prev;
1305 return wwin;
1309 static WWindow*
1310 nextToFocusBefore(WWindow *wwin)
1312 WWindow *tmp = wwin->next;
1314 while (tmp) {
1315 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1317 return tmp;
1319 tmp = tmp->next;
1322 /* start over from the beginning of the list */
1323 tmp = wwin;
1324 while (tmp->prev)
1325 tmp = tmp->prev;
1327 while (tmp && tmp != wwin) {
1328 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1330 return tmp;
1332 tmp = tmp->next;
1335 return wwin;
1338 static void
1339 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1341 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1342 Bool done = False;
1343 Bool openedSwitchMenu = False;
1344 WWindow *newFocused;
1345 WWindow *oldFocused;
1346 int modifiers;
1347 XModifierKeymap *keymap;
1349 if (!wwin)
1350 return;
1352 /* puts("IN");*/
1353 keymap = XGetModifierMapping(dpy);
1356 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1357 CurrentTime);
1359 if (next) {
1360 newFocused = nextToFocusAfter(wwin);
1361 } else {
1362 newFocused = nextToFocusBefore(wwin);
1365 scr->flags.doing_alt_tab = 1;
1367 wWindowFocus(newFocused, scr->focused_window);
1368 oldFocused = newFocused;
1369 if (wPreferences.circ_raise)
1370 wRaiseFrame(newFocused->frame->core);
1372 if (wPreferences.popup_switchmenu &&
1373 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1375 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1376 openedSwitchMenu = True;
1379 while (!done) {
1380 XEvent ev;
1382 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1383 /* WMNextEvent(dpy, &ev);*/
1384 if (ev.type != KeyRelease && ev.type != KeyPress) {
1385 WMHandleEvent(&ev);
1386 continue;
1388 /*puts("EV");*/
1389 /* ignore CapsLock */
1390 modifiers = ev.xkey.state & ValidModMask;
1392 if (ev.type == KeyPress
1393 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1394 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1396 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1397 newFocused = nextToFocusAfter(newFocused);
1398 wWindowFocus(newFocused, oldFocused);
1399 oldFocused = newFocused;
1400 if (wPreferences.circ_raise)
1401 wRaiseFrame(newFocused->frame->core);
1402 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1404 } else if (ev.type == KeyPress
1405 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1406 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1408 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1409 newFocused = nextToFocusBefore(newFocused);
1410 wWindowFocus(newFocused, oldFocused);
1411 oldFocused = newFocused;
1412 if (wPreferences.circ_raise)
1413 wRaiseFrame(newFocused->frame->core);
1414 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1416 if (ev.type == KeyRelease) {
1417 int i;
1419 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1420 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1421 wKeyBindings[WKBD_FOCUSNEXT].modifier
1422 & 1<<(i/keymap->max_keypermod)) {
1423 done = True;
1424 break;
1429 /*puts("OUT");*/
1430 XFree(keymap);
1432 XUngrabKeyboard(dpy, CurrentTime);
1433 wSetFocusTo(scr, newFocused);
1434 scr->flags.doing_alt_tab = 0;
1435 if (openedSwitchMenu)
1436 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1440 #endif /* WEENDOZE_CYCLE */
1445 static void
1446 handleKeyPress(XEvent *event)
1448 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1449 WWindow *wwin = scr->focused_window;
1450 int i;
1451 int modifiers;
1452 int command=-1;
1453 #ifdef KEEP_XKB_LOCK_STATUS
1454 XkbStateRec staterec;
1455 #endif /*KEEP_XKB_LOCK_STATUS*/
1457 /* ignore CapsLock */
1458 modifiers = event->xkey.state & ValidModMask;
1460 for (i=0; i<WKBD_LAST; i++) {
1461 if (wKeyBindings[i].keycode==0)
1462 continue;
1464 if (wKeyBindings[i].keycode==event->xkey.keycode
1465 && (/*wKeyBindings[i].modifier==0
1466 ||*/ wKeyBindings[i].modifier==modifiers)) {
1467 command = i;
1468 break;
1472 if (command < 0) {
1473 #ifdef LITE
1475 #if 0
1477 #endif
1478 #else
1479 if (!wRootMenuPerformShortcut(event)) {
1480 #endif
1481 static int dontLoop = 0;
1483 if (dontLoop > 10) {
1484 wwarning("problem with key event processing code");
1485 return;
1487 dontLoop++;
1488 /* if the focused window is an internal window, try redispatching
1489 * the event to the managed window, as it can be a WINGs window */
1490 if (wwin && wwin->flags.internal_window
1491 && wwin->client_leader!=None) {
1492 /* client_leader contains the WINGs toplevel */
1493 event->xany.window = wwin->client_leader;
1494 WMHandleEvent(event);
1496 dontLoop--;
1498 return;
1501 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1502 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1504 switch (command) {
1505 #ifndef LITE
1506 case WKBD_ROOTMENU:
1507 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1508 break;
1509 case WKBD_WINDOWLIST:
1510 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1511 break;
1512 #endif /* !LITE */
1513 case WKBD_WINDOWMENU:
1514 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1515 OpenWindowMenu(wwin, wwin->frame_x,
1516 wwin->frame_y+wwin->frame->top_width, True);
1517 break;
1518 case WKBD_MINIATURIZE:
1519 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1520 && !WFLAGP(wwin, no_miniaturizable)) {
1521 CloseWindowMenu(scr);
1523 if (wwin->protocols.MINIATURIZE_WINDOW)
1524 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1525 event->xbutton.time);
1526 else {
1527 wIconifyWindow(wwin);
1530 break;
1531 case WKBD_HIDE:
1532 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1533 WApplication *wapp = wApplicationOf(wwin->main_window);
1534 CloseWindowMenu(scr);
1536 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1537 wHideApplication(wapp);
1540 break;
1541 case WKBD_MAXIMIZE:
1542 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1543 CloseWindowMenu(scr);
1545 if (wwin->flags.maximized) {
1546 wUnmaximizeWindow(wwin);
1547 } else {
1548 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1551 break;
1552 case WKBD_VMAXIMIZE:
1553 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1554 CloseWindowMenu(scr);
1556 if (wwin->flags.maximized) {
1557 wUnmaximizeWindow(wwin);
1558 } else {
1559 wMaximizeWindow(wwin, MAX_VERTICAL);
1562 break;
1563 case WKBD_RAISE:
1564 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1565 CloseWindowMenu(scr);
1567 wRaiseFrame(wwin->frame->core);
1569 break;
1570 case WKBD_LOWER:
1571 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1572 CloseWindowMenu(scr);
1574 wLowerFrame(wwin->frame->core);
1576 break;
1577 case WKBD_RAISELOWER:
1578 /* raise or lower the window under the pointer, not the
1579 * focused one
1581 wwin = windowUnderPointer(scr);
1582 if (wwin)
1583 wRaiseLowerFrame(wwin->frame->core);
1584 break;
1585 case WKBD_SHADE:
1586 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1587 if (wwin->flags.shaded)
1588 wUnshadeWindow(wwin);
1589 else
1590 wShadeWindow(wwin);
1592 break;
1593 case WKBD_MOVERESIZE:
1594 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1595 CloseWindowMenu(scr);
1597 wKeyboardMoveResizeWindow(wwin);
1599 break;
1600 case WKBD_CLOSE:
1601 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1602 CloseWindowMenu(scr);
1603 if (wwin->protocols.DELETE_WINDOW)
1604 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1605 event->xkey.time);
1607 break;
1608 case WKBD_SELECT:
1609 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1610 wSelectWindow(wwin, !wwin->flags.selected);
1612 break;
1613 case WKBD_FOCUSNEXT:
1614 #ifdef WEENDOZE_CYCLE
1615 if (wPreferences.windoze_cycling) {
1616 doWindozeCycle(wwin, event, True);
1617 } else
1618 #endif /* WEENDOZE_CYCLE */
1620 wwin = NextFocusWindow(scr);
1621 if (wwin != NULL) {
1622 wSetFocusTo(scr, wwin);
1623 if (wPreferences.circ_raise)
1624 wRaiseFrame(wwin->frame->core);
1627 break;
1629 case WKBD_FOCUSPREV:
1630 #ifdef WEENDOZE_CYCLE
1631 if (wPreferences.windoze_cycling) {
1632 doWindozeCycle(wwin, event, False);
1633 } else
1634 #endif /* WEENDOZE_CYCLE */
1636 wwin = PrevFocusWindow(scr);
1637 if (wwin != NULL) {
1638 wSetFocusTo(scr, wwin);
1639 if (wPreferences.circ_raise)
1640 wRaiseFrame(wwin->frame->core);
1643 break;
1645 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1646 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1647 i = (scr->current_workspace/10)*10 + wk - 1;\
1648 if (wPreferences.ws_advance || i<scr->workspace_count)\
1649 wWorkspaceChange(scr, i);\
1650 break
1651 #else
1652 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1653 i = (scr->current_workspace/10)*10 + wk - 1;\
1654 if (wPreferences.ws_advance || i<scr->workspace_count)\
1655 wWorkspaceChange(scr, i);\
1656 break
1657 #endif
1658 GOTOWORKS(1);
1659 GOTOWORKS(2);
1660 GOTOWORKS(3);
1661 GOTOWORKS(4);
1662 GOTOWORKS(5);
1663 GOTOWORKS(6);
1664 GOTOWORKS(7);
1665 GOTOWORKS(8);
1666 GOTOWORKS(9);
1667 GOTOWORKS(10);
1668 #undef GOTOWORKS
1669 case WKBD_NEXTWORKSPACE:
1670 wWorkspaceRelativeChange(scr, 1);
1671 break;
1672 case WKBD_PREVWORKSPACE:
1673 wWorkspaceRelativeChange(scr, -1);
1674 break;
1675 case WKBD_WINDOW1:
1676 case WKBD_WINDOW2:
1677 case WKBD_WINDOW3:
1678 case WKBD_WINDOW4:
1679 #ifdef EXTEND_WINDOWSHORTCUT
1680 case WKBD_WINDOW5:
1681 case WKBD_WINDOW6:
1682 case WKBD_WINDOW7:
1683 case WKBD_WINDOW8:
1684 case WKBD_WINDOW9:
1685 case WKBD_WINDOW10:
1686 #endif
1687 if ( scr->shortcutSelectedWindows[command-WKBD_WINDOW1]) {
1688 LinkedList *list = scr->shortcutSelectedWindows[command-WKBD_WINDOW1];
1689 int cw;
1691 wUnselectWindows(scr);
1692 if (scr->shortcutWindow[command-WKBD_WINDOW1])
1693 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1694 cw = scr->current_workspace;
1695 while (list) {
1696 wWindowChangeWorkspace(list->head, cw);
1697 wMakeWindowVisible(list->head);
1698 wSelectWindow(list->head, True);
1699 list = list->tail;
1701 } else if (scr->shortcutWindow[command-WKBD_WINDOW1]){
1703 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1705 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1707 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1708 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1709 LinkedList *sl;
1711 sl = scr->selected_windows;
1712 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1714 while (sl) {
1715 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1716 sl = sl->tail;
1719 wSelectWindow(wwin, !wwin->flags.selected);
1720 XFlush(dpy);
1721 wusleep(3000);
1722 wSelectWindow(wwin, !wwin->flags.selected);
1723 XFlush(dpy);
1725 } else if (scr->selected_windows) {
1727 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1728 LinkedList *sl;
1730 sl = scr->selected_windows;
1731 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1733 while (sl) {
1734 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1735 sl = sl->tail;
1740 break;
1741 case WKBD_NEXTWSLAYER:
1742 case WKBD_PREVWSLAYER:
1744 int row, column;
1746 row = scr->current_workspace/10;
1747 column = scr->current_workspace%10;
1749 if (command==WKBD_NEXTWSLAYER) {
1750 if ((row+1)*10 < scr->workspace_count)
1751 wWorkspaceChange(scr, column+(row+1)*10);
1752 } else {
1753 if (row > 0)
1754 wWorkspaceChange(scr, column+(row-1)*10);
1757 break;
1758 case WKBD_CLIPLOWER:
1759 if (!wPreferences.flags.noclip)
1760 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1761 break;
1762 case WKBD_CLIPRAISE:
1763 if (!wPreferences.flags.noclip)
1764 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1765 break;
1766 case WKBD_CLIPRAISELOWER:
1767 if (!wPreferences.flags.noclip)
1768 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1769 break;
1770 #ifdef KEEP_XKB_LOCK_STATUS
1771 case WKBD_TOGGLE:
1772 if(wPreferences.modelock) {
1773 /*toggle*/
1774 wwin = scr->focused_window;
1776 if (wwin && wwin->flags.mapped
1777 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1778 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1779 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1781 wwin->frame->languagemode = wwin->frame->last_languagemode;
1782 wwin->frame->last_languagemode = staterec.group;
1783 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1787 break;
1788 #endif /* KEEP_XKB_LOCK_STATUS */
1794 static void
1795 handleMotionNotify(XEvent *event)
1797 WMenu *menu;
1798 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1800 if (wPreferences.scrollable_menus) {
1801 if (scr->flags.jump_back_pending ||
1802 event->xmotion.x_root <= 1 ||
1803 event->xmotion.x_root >= (scr->scr_width - 2) ||
1804 event->xmotion.y_root <= 1 ||
1805 event->xmotion.y_root >= (scr->scr_height - 2)) {
1807 #ifdef DEBUG
1808 puts("pointer at screen edge");
1809 #endif
1811 menu = wMenuUnderPointer(scr);
1812 if (menu!=NULL)
1813 wMenuScroll(menu, event);
1816 #if 0
1817 if (event->xmotion.subwindow == None)
1818 return;
1820 if (scr->scrolledFMaximize != None) {
1821 WWindow *twin;
1823 twin = wWindowFor(scr->scrolledFMaximize);
1824 if (twin && twin->frame_y ==) {
1828 scr->scrolledFMaximize = NULL;
1830 } else {
1832 /* scroll full maximized window */
1833 if (event->xmotion.y_root < 1
1834 || event->xmotion.y_root > scr->scr_height - 1) {
1836 wwin = wWindowFor(event->xmotion.subwindow);
1838 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1839 && WFLAGP(wwin, full_maximize)
1840 && event->xmotion.x_root >= wwin->frame_x
1841 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1843 if (!WFLAGP(wwin, no_titlebar)
1844 && wwin->frame_y <= - wwin->frame->top_width) {
1846 wWindowMove(wwin, wwin->frame_x, 0);
1847 wwin->flags.dragged_while_fmaximized = 0;
1849 } else if (!WFLAGP(wwin, no_resizebar)
1850 && wwin->frame_y + wwin->frame->core->height >=
1851 scr->scr_height + wwin->frame->bottom_width) {
1853 int y = scr->scr_height + wwin->frame->bottom_width;
1855 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1857 wWindowMove(wwin, wwin->frame_x, y);
1858 wwin->flags.dragged_while_fmaximized = 0;
1862 #endif
1866 static void
1867 handleVisibilityNotify(XEvent *event)
1869 WWindow *wwin;
1871 wwin = wWindowFor(event->xvisibility.window);
1872 if (!wwin)
1873 return;
1874 wwin->flags.obscured =
1875 (event->xvisibility.state == VisibilityFullyObscured);