Changes relate to modelock.
[wmaker-crm.git] / src / event.c
blob79c315608a9cf351ab31ee7003fd457277d400c4
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 /* special flags */
100 extern char WDelayedActionSet;
103 /************ Local stuff ***********/
106 static void saveTimestamp(XEvent *event);
107 static void handleColormapNotify();
108 static void handleMapNotify(), handleUnmapNotify();
109 static void handleButtonPress(), handleExpose();
110 static void handleDestroyNotify();
111 static void handleConfigureRequest();
112 static void handleMapRequest();
113 static void handlePropertyNotify();
114 static void handleEnterNotify();
115 static void handleLeaveNotify();
116 static void handleExtensions();
117 static void handleClientMessage();
118 static void handleKeyPress();
119 static void handleFocusIn();
120 static void handleMotionNotify();
121 static void handleVisibilityNotify();
124 #ifdef SHAPE
125 static void handleShapeNotify();
126 #endif
128 /* called from the signal handler */
129 void NotifyDeadProcess(pid_t pid, unsigned char status);
131 /* real dead process handler */
132 static void handleDeadProcess(void *foo);
135 typedef struct DeadProcesses {
136 pid_t pid;
137 unsigned char exit_status;
138 } DeadProcesses;
140 /* stack of dead processes */
141 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
142 static int deadProcessPtr=0;
145 typedef struct DeathHandler {
146 WDeathHandler *callback;
147 pid_t pid;
148 struct DeathHandler *next;
149 void *client_data;
150 } DeathHandler;
152 static DeathHandler *deathHandler=NULL;
156 WMagicNumber
157 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
159 DeathHandler *handler;
161 handler = malloc(sizeof(DeathHandler));
162 if (!handler)
163 return 0;
165 handler->pid = pid;
166 handler->callback = callback;
167 handler->client_data = cdata;
169 handler->next = deathHandler;
171 deathHandler = handler;
173 return handler;
178 void
179 wDeleteDeathHandler(WMagicNumber id)
181 DeathHandler *tmp, *handler=(DeathHandler*)id;
183 if (!handler || !deathHandler)
184 return;
186 tmp = deathHandler;
187 if (tmp==handler) {
188 deathHandler = handler->next;
189 free(handler);
190 } else {
191 while (tmp->next) {
192 if (tmp->next==handler) {
193 tmp->next=handler->next;
194 free(handler);
195 break;
197 tmp = tmp->next;
203 void
204 DispatchEvent(XEvent *event)
206 if (deathHandler)
207 handleDeadProcess(NULL);
209 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
210 WCHANGE_STATE(WSTATE_EXITING);
211 /* received SIGTERM */
213 * WMHandleEvent() can't be called from anything
214 * executed inside here, or we can get in a infinite
215 * recursive loop.
217 Shutdown(WSExitMode);
219 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
220 WCHANGE_STATE(WSTATE_RESTARTING);
222 Shutdown(WSRestartPreparationMode);
223 /* received SIGHUP */
224 Restart(NULL, True);
227 /* for the case that all that is wanted to be dispatched is
228 * the stuff above */
229 if (!event)
230 return;
232 saveTimestamp(event);
233 switch (event->type) {
234 case MapRequest:
235 handleMapRequest(event);
236 break;
238 case KeyPress:
239 handleKeyPress(event);
240 break;
242 case MotionNotify:
243 handleMotionNotify(event);
244 break;
246 case ConfigureRequest:
247 handleConfigureRequest(event);
248 break;
250 case DestroyNotify:
251 handleDestroyNotify(event);
252 break;
254 case MapNotify:
255 handleMapNotify(event);
256 break;
258 case UnmapNotify:
259 handleUnmapNotify(event);
260 break;
262 case ButtonPress:
263 handleButtonPress(event);
264 break;
266 case Expose:
267 handleExpose(event);
268 break;
270 case PropertyNotify:
271 handlePropertyNotify(event);
272 break;
274 case EnterNotify:
275 handleEnterNotify(event);
276 break;
278 case LeaveNotify:
279 handleLeaveNotify(event);
280 break;
282 case ClientMessage:
283 handleClientMessage(event);
284 break;
286 case ColormapNotify:
287 handleColormapNotify(event);
288 break;
290 case MappingNotify:
291 if (event->xmapping.request == MappingKeyboard
292 || event->xmapping.request == MappingModifier)
293 XRefreshKeyboardMapping(&event->xmapping);
294 break;
296 case FocusIn:
297 handleFocusIn(event);
298 break;
300 case VisibilityNotify:
301 handleVisibilityNotify(event);
302 break;
303 default:
304 handleExtensions(event);
305 break;
311 *----------------------------------------------------------------------
312 * EventLoop-
313 * Processes X and internal events indefinitely.
315 * Returns:
316 * Never returns
318 * Side effects:
319 * The LastTimestamp global variable is updated.
320 *----------------------------------------------------------------------
322 void
323 EventLoop()
325 XEvent event;
327 for(;;) {
328 WMNextEvent(dpy, &event);
329 WMHandleEvent(&event);
335 Bool
336 IsDoubleClick(WScreen *scr, XEvent *event)
338 if ((scr->last_click_time>0) &&
339 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
340 && (event->xbutton.button == scr->last_click_button)
341 && (event->xbutton.window == scr->last_click_window)) {
343 scr->flags.next_click_is_not_double = 1;
344 scr->last_click_time = 0;
345 scr->last_click_window = event->xbutton.window;
347 return True;
349 return False;
353 void
354 NotifyDeadProcess(pid_t pid, unsigned char status)
356 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
357 wwarning("stack overflow: too many dead processes");
358 return;
360 /* stack the process to be handled later,
361 * as this is called from the signal handler */
362 deadProcesses[deadProcessPtr].pid = pid;
363 deadProcesses[deadProcessPtr].exit_status = status;
364 deadProcessPtr++;
368 static void
369 handleDeadProcess(void *foo)
371 DeathHandler *tmp;
372 int i;
374 for (i=0; i<deadProcessPtr; i++) {
375 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
378 if (!deathHandler) {
379 deadProcessPtr=0;
380 return;
383 /* get the pids on the queue and call handlers */
384 while (deadProcessPtr>0) {
385 deadProcessPtr--;
387 tmp = deathHandler;
388 while (tmp) {
389 DeathHandler *t;
391 t = tmp->next;
393 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
394 (*tmp->callback)(tmp->pid,
395 deadProcesses[deadProcessPtr].exit_status,
396 tmp->client_data);
397 wDeleteDeathHandler(tmp);
399 tmp = t;
405 static void
406 saveTimestamp(XEvent *event)
408 WScreen *scr = wScreenForWindow(event->xany.window);
409 LastTimestamp = CurrentTime;
411 switch (event->type) {
412 case ButtonRelease:
413 case ButtonPress:
414 LastTimestamp = event->xbutton.time;
415 break;
416 case KeyPress:
417 case KeyRelease:
418 LastTimestamp = event->xkey.time;
419 break;
420 case MotionNotify:
421 LastTimestamp = event->xmotion.time;
422 break;
423 case PropertyNotify:
424 LastTimestamp = event->xproperty.time;
425 break;
426 case EnterNotify:
427 case LeaveNotify:
428 LastTimestamp = event->xcrossing.time;
429 break;
430 case SelectionClear:
431 LastTimestamp = event->xselectionclear.time;
432 break;
433 case SelectionRequest:
434 LastTimestamp = event->xselectionrequest.time;
435 break;
436 case SelectionNotify:
437 LastTimestamp = event->xselection.time;
438 #ifdef XDND
439 wXDNDProcessSelection(event);
440 #endif
441 break;
446 static void
447 handleExtensions(XEvent *event)
449 #ifdef SHAPE
450 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
451 handleShapeNotify(event);
453 #endif
454 #ifdef KEEP_XKB_LOCK_STATUS
455 if (wPreferences.modelock && event->type == (0x50|XkbIndicatorStateNotify)){
456 /* if someone know how to call this 0x50
457 * or how to clean code this please tell ]d */
458 handleXkbIndicatorStateNotify(event);
460 #endif /*KEEP_XKB_LOCK_STATUS*/
464 static void
465 handleMapRequest(XEvent *ev)
467 WWindow *wwin;
468 WScreen *scr = NULL;
469 Window window = ev->xmaprequest.window;
471 #ifdef DEBUG
472 printf("got map request for %x\n", (unsigned)window);
473 #endif
475 if ((wwin = wWindowFor(window))) {
476 if (wwin->flags.shaded) {
477 wUnshadeWindow(wwin);
479 /* deiconify window */
480 if (wwin->flags.miniaturized) {
481 wDeiconifyWindow(wwin);
482 } else if (wwin->flags.hidden) {
483 WApplication *wapp = wApplicationOf(wwin->main_window);
484 /* go to the last workspace that the user worked on the app */
485 #ifndef REDUCE_APPICONS
486 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
487 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
489 if (wapp) {
490 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
492 #endif
493 wUnhideApplication(wapp, False, False);
495 return;
498 scr = wScreenForRootWindow(ev->xmaprequest.parent);
500 wwin = wManageWindow(scr, window);
503 * This is to let the Dock know that the application it launched
504 * has already been mapped (eg: it has finished launching).
505 * It is not necessary for normally docked apps, but is needed for
506 * apps that were forcedly docked (like with dockit).
508 if (scr->last_dock) {
509 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
510 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
511 else
512 wDockTrackWindowLaunch(scr->last_dock, window);
515 if (wwin) {
516 wClientSetState(wwin, NormalState, None);
517 if (wwin->flags.maximized) {
518 wMaximizeWindow(wwin, wwin->flags.maximized);
520 if (wwin->flags.shaded) {
521 wwin->flags.shaded = 0;
522 wwin->flags.skip_next_animation = 1;
523 wShadeWindow(wwin);
525 if (wwin->flags.miniaturized) {
526 wwin->flags.miniaturized = 0;
527 wwin->flags.skip_next_animation = 1;
528 wIconifyWindow(wwin);
530 if (wwin->flags.hidden) {
531 WApplication *wapp = wApplicationOf(wwin->main_window);
533 wwin->flags.hidden = 0;
534 wwin->flags.skip_next_animation = 1;
535 if (wapp) {
536 wHideApplication(wapp);
543 static void
544 handleDestroyNotify(XEvent *event)
546 WWindow *wwin;
547 WApplication *app;
548 Window window = event->xdestroywindow.window;
550 #ifdef DEBUG
551 puts("got destroy notify");
552 #endif
554 wwin = wWindowFor(window);
555 if (wwin) {
556 wUnmanageWindow(wwin, False, True);
559 app = wApplicationOf(window);
560 if (app) {
561 if (window == app->main_window) {
562 app->refcount = 0;
563 wwin = app->main_window_desc->screen_ptr->focused_window;
564 while (wwin) {
565 if (wwin->main_window == window) {
566 wwin->main_window = None;
568 wwin = wwin->prev;
571 wApplicationDestroy(app);
574 #ifdef KWM_HINTS
575 wKWMCheckDestroy(&event->xdestroywindow);
576 #endif
581 static void
582 handleExpose(XEvent *event)
584 WObjDescriptor *desc;
585 XEvent ev;
587 #ifdef DEBUG
588 puts("got expose");
589 #endif
591 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
593 if (XFindContext(dpy, event->xexpose.window, wWinContext,
594 (XPointer *)&desc)==XCNOENT) {
595 return;
598 if (desc->handle_expose) {
599 (*desc->handle_expose)(desc, event);
604 /* bindable */
605 static void
606 handleButtonPress(XEvent *event)
608 WObjDescriptor *desc;
609 WScreen *scr;
611 #ifdef DEBUG
612 puts("got button press");
613 #endif
615 scr = wScreenForRootWindow(event->xbutton.root);
617 #ifdef BALLOON_TEXT
618 wBalloonHide(scr);
619 #endif
622 #ifndef LITE
623 if (event->xbutton.window==scr->root_win) {
625 if (event->xbutton.button==wPreferences.menu_button) {
626 OpenRootMenu(scr, event->xbutton.x_root,
627 event->xbutton.y_root, False);
628 /* ugly hack */
629 if (scr->root_menu) {
630 if (scr->root_menu->brother->flags.mapped)
631 event->xbutton.window = scr->root_menu->brother->frame->core->window;
632 else
633 event->xbutton.window = scr->root_menu->frame->core->window;
635 } else if (event->xbutton.button==wPreferences.windowl_button) {
636 OpenSwitchMenu(scr, event->xbutton.x_root,
637 event->xbutton.y_root, False);
638 if (scr->switch_menu) {
639 if (scr->switch_menu->brother->flags.mapped)
640 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
641 else
642 event->xbutton.window = scr->switch_menu->frame->core->window;
644 } else if (event->xbutton.button==wPreferences.select_button) {
645 wUnselectWindows(scr);
646 wSelectWindows(scr, event);
648 #ifdef MOUSE_WS_SWITCH
649 else if (event->xbutton.button==Button5) {
651 wWorkspaceRelativeChange(scr, -1);
653 } else if (event->xbutton.button==Button4) {
655 wWorkspaceRelativeChange(scr, 1);
658 #endif /* MOUSE_WS_SWITCH */
659 #ifdef GNOME_STUFF
660 else if (wGNOMEProxyizeButtonEvent(scr, event))
661 return;
662 #endif
664 #endif /* !LITE */
666 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
667 (XPointer *)&desc)==XCNOENT) {
668 if (XFindContext(dpy, event->xbutton.window, wWinContext,
669 (XPointer *)&desc)==XCNOENT) {
670 return;
674 if (desc->handle_mousedown!=NULL) {
675 (*desc->handle_mousedown)(desc, event);
678 if (desc->parent_type == WCLASS_WINDOW) {
679 XSync(dpy, 0);
681 if (event->xbutton.state & MOD_MASK) {
682 XAllowEvents(dpy, AsyncPointer, CurrentTime);
685 if (wPreferences.focus_mode == WKF_CLICK) {
686 if (wPreferences.ignore_focus_click) {
687 XAllowEvents(dpy, AsyncPointer, CurrentTime);
689 XAllowEvents(dpy, ReplayPointer, CurrentTime);
691 XSync(dpy, 0);
692 } else if (desc->parent_type == WCLASS_APPICON
693 || desc->parent_type == WCLASS_MINIWINDOW
694 || desc->parent_type == WCLASS_DOCK_ICON) {
695 if (event->xbutton.state & MOD_MASK) {
696 XSync(dpy, 0);
697 XAllowEvents(dpy, AsyncPointer, CurrentTime);
698 XSync(dpy, 0);
702 /* save double-click information */
703 if (scr->flags.next_click_is_not_double) {
704 scr->flags.next_click_is_not_double = 0;
705 } else {
706 scr->last_click_time = event->xbutton.time;
707 scr->last_click_button = event->xbutton.button;
708 scr->last_click_window = event->xbutton.window;
713 static void
714 handleMapNotify(XEvent *event)
716 WWindow *wwin;
718 #ifdef DEBUG
719 puts("got map");
720 #endif
722 wwin = wWindowFor(event->xmap.event);
723 if (wwin && wwin->client_win == event->xmap.event) {
724 if (wwin->flags.miniaturized) {
725 wDeiconifyWindow(wwin);
726 } else {
727 XGrabServer(dpy);
728 wWindowMap(wwin);
729 wClientSetState(wwin, NormalState, None);
730 XUngrabServer(dpy);
736 static void
737 handleUnmapNotify(XEvent *event)
739 WWindow *wwin;
740 XEvent ev;
741 Bool withdraw = False;
743 #ifdef DEBUG
744 puts("got unmap");
745 #endif
747 /* only process windows with StructureNotify selected
748 * (ignore SubstructureNotify) */
749 wwin = wWindowFor(event->xunmap.window);
750 if (!wwin)
751 return;
753 /* whether the event is a Withdrawal request */
754 if (event->xunmap.event == wwin->screen_ptr->root_win
755 && event->xunmap.send_event)
756 withdraw = True;
758 if (wwin->client_win != event->xunmap.event && !withdraw)
759 return;
761 if (!wwin->flags.mapped && !withdraw
762 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
763 && !wwin->flags.miniaturized && !wwin->flags.hidden)
764 return;
766 XGrabServer(dpy);
767 XUnmapWindow(dpy, wwin->frame->core->window);
768 wwin->flags.mapped = 0;
769 XSync(dpy, 0);
770 /* check if the window was destroyed */
771 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
772 DispatchEvent(&ev);
773 } else {
774 Bool reparented = False;
776 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
777 reparented = True;
779 /* withdraw window */
780 wwin->flags.mapped = 0;
781 if (!reparented)
782 wClientSetState(wwin, WithdrawnState, None);
784 /* if the window was reparented, do not reparent it back to the
785 * root window */
786 wUnmanageWindow(wwin, !reparented, False);
788 XUngrabServer(dpy);
792 static void
793 handleConfigureRequest(XEvent *event)
795 WWindow *wwin;
797 #ifdef DEBUG
798 puts("got configure request");
799 #endif
800 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
802 * Configure request for unmapped window
804 wClientConfigure(NULL, &(event->xconfigurerequest));
805 } else {
806 wClientConfigure(wwin, &(event->xconfigurerequest));
811 static void
812 handlePropertyNotify(XEvent *event)
814 WWindow *wwin;
815 WApplication *wapp;
816 Window jr;
817 int ji;
818 unsigned int ju;
819 WScreen *scr;
821 #ifdef DEBUG
822 puts("got property notify");
823 #endif
824 if ((wwin=wWindowFor(event->xproperty.window))) {
825 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
826 &ju, &ju, &ju, &ju)) {
827 return;
829 wClientCheckProperty(wwin, &event->xproperty);
831 wapp = wApplicationOf(event->xproperty.window);
832 if (wapp) {
833 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
836 scr = wScreenForWindow(event->xproperty.window);
837 if (scr && scr->root_win == event->xproperty.window) {
838 #ifdef KWM_HINTS
839 wKWMCheckRootHintChange(scr, &event->xproperty);
840 #endif
845 static void
846 handleClientMessage(XEvent *event)
848 WWindow *wwin;
849 WObjDescriptor *desc;
851 #ifdef DEBUG
852 puts("got client message");
853 #endif
854 /* handle transition from Normal to Iconic state */
855 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
856 && event->xclient.format == 32
857 && event->xclient.data.l[0] == IconicState) {
859 wwin = wWindowFor(event->xclient.window);
860 if (!wwin) return;
861 if (!wwin->flags.miniaturized)
862 wIconifyWindow(wwin);
863 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
864 && event->xclient.format == 32) {
865 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
867 if (!scr)
868 return;
870 if (event->xclient.data.l[1] == 1) { /* starting */
871 wColormapAllowClientInstallation(scr, True);
872 } else { /* stopping */
873 wColormapAllowClientInstallation(scr, False);
875 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
877 wDefaultsCheckDomains("bla");
879 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
880 WApplication *wapp;
881 int done=0;
882 wapp = wApplicationOf(event->xclient.window);
883 if (wapp) {
884 switch (event->xclient.data.l[0]) {
885 case WMFHideOtherApplications:
886 wHideOtherApplications(wapp->main_window_desc);
887 done = 1;
888 break;
890 case WMFHideApplication:
891 wHideApplication(wapp);
892 done = 1;
893 break;
896 if (!done) {
897 wwin = wWindowFor(event->xclient.window);
898 if (wwin) {
899 switch (event->xclient.data.l[0]) {
900 case WMFHideOtherApplications:
901 wHideOtherApplications(wwin);
902 break;
904 case WMFHideApplication:
905 wHideApplication(wApplicationOf(wwin->main_window));
906 break;
910 #ifdef GNOME_STUFF
911 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
912 /* do nothing */
913 #endif /* GNOME_STUFF */
914 #ifdef KWM_HINTS
915 } else if (wKWMProcessClientMessage(&event->xclient)) {
916 /* do nothing */
917 #endif /* KWM_HINTS */
918 #ifdef XDND
919 } else if (wXDNDProcessClientMessage(&event->xclient)) {
920 /* do nothing */
921 #endif /* XDND */
922 #ifdef OFFIX_DND
923 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
924 WScreen *scr = wScreenForWindow(event->xclient.window);
925 if (scr && wDockReceiveDNDDrop(scr,event))
926 goto redirect_message;
927 #endif /* OFFIX_DND */
928 } else {
929 #ifdef OFFIX_DND
930 redirect_message:
931 #endif
933 * Non-standard thing, but needed by OffiX DND.
934 * For when the icon frame gets a ClientMessage
935 * that should have gone to the icon_window.
937 if (XFindContext(dpy, event->xbutton.window, wWinContext,
938 (XPointer *)&desc)!=XCNOENT) {
939 struct WIcon *icon=NULL;
941 if (desc->parent_type == WCLASS_MINIWINDOW) {
942 icon = (WIcon*)desc->parent;
943 } else if (desc->parent_type == WCLASS_DOCK_ICON
944 || desc->parent_type == WCLASS_APPICON) {
945 icon = ((WAppIcon*)desc->parent)->icon;
947 if (icon && (wwin=icon->owner)) {
948 if (wwin->client_win!=event->xclient.window) {
949 event->xclient.window = wwin->client_win;
950 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
951 event);
959 static void
960 raiseWindow(WScreen *scr)
962 WWindow *wwin;
964 scr->autoRaiseTimer = NULL;
966 wwin = wWindowFor(scr->autoRaiseWindow);
967 if (!wwin)
968 return;
970 if (!wwin->flags.destroyed) {
971 wRaiseFrame(wwin->frame->core);
972 /* this is needed or a race condition will occur */
973 XSync(dpy, False);
978 static void
979 handleEnterNotify(XEvent *event)
981 WWindow *wwin;
982 WObjDescriptor *desc = NULL;
983 XEvent ev;
984 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
987 #ifdef DEBUG
988 puts("got enter notify");
989 #endif
991 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
992 &ev)) {
993 /* already left the window... */
994 saveTimestamp(&ev);
995 if (ev.xcrossing.mode==event->xcrossing.mode
996 && ev.xcrossing.detail==event->xcrossing.detail) {
997 return;
1001 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1002 (XPointer *)&desc)!=XCNOENT) {
1003 if(desc->handle_enternotify)
1004 (*desc->handle_enternotify)(desc, event);
1007 /* enter to window */
1008 wwin = wWindowFor(event->xcrossing.window);
1009 if (!wwin) {
1010 if (wPreferences.focus_mode==WKF_POINTER
1011 && event->xcrossing.window==event->xcrossing.root) {
1012 wSetFocusTo(scr, NULL);
1014 if (wPreferences.colormap_mode==WKF_POINTER) {
1015 wColormapInstallForWindow(scr, NULL);
1017 if (scr->autoRaiseTimer
1018 && event->xcrossing.root==event->xcrossing.window) {
1019 WMDeleteTimerHandler(scr->autoRaiseTimer);
1020 scr->autoRaiseTimer = NULL;
1022 } else {
1023 /* set auto raise timer even if in focus-follows-mouse mode
1024 * and the event is for the frame window, even if the window
1025 * has focus already. useful if you move the pointer from a focused
1026 * window to the root window and back pretty fast
1028 * set focus if in focus-follows-mouse mode and the event
1029 * is for the frame window and window doesn't have focus yet */
1030 if ((wPreferences.focus_mode==WKF_POINTER
1031 || wPreferences.focus_mode==WKF_SLOPPY)
1032 && wwin->frame->core->window==event->xcrossing.window
1033 && !scr->flags.doing_alt_tab) {
1035 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1036 wSetFocusTo(scr, wwin);
1038 if (scr->autoRaiseTimer)
1039 WMDeleteTimerHandler(scr->autoRaiseTimer);
1040 scr->autoRaiseTimer = NULL;
1042 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1043 scr->autoRaiseWindow = wwin->frame->core->window;
1044 scr->autoRaiseTimer
1045 = WMAddTimerHandler(wPreferences.raise_delay,
1046 (WMCallback*)raiseWindow, scr);
1049 /* Install colormap for window, if the colormap installation mode
1050 * is colormap_follows_mouse */
1051 if (wPreferences.colormap_mode==WKF_POINTER) {
1052 if (wwin->client_win==event->xcrossing.window)
1053 wColormapInstallForWindow(scr, wwin);
1054 else
1055 wColormapInstallForWindow(scr, NULL);
1059 /* a little kluge to hide the clip balloon */
1060 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1061 if (!desc) {
1062 XUnmapWindow(dpy, scr->clip_balloon);
1063 scr->flags.clip_balloon_mapped = 0;
1064 } else {
1065 if (desc->parent_type!=WCLASS_DOCK_ICON
1066 || scr->clip_icon != desc->parent) {
1067 XUnmapWindow(dpy, scr->clip_balloon);
1068 scr->flags.clip_balloon_mapped = 0;
1073 if (event->xcrossing.window == event->xcrossing.root
1074 && event->xcrossing.detail == NotifyNormal
1075 && event->xcrossing.detail != NotifyInferior
1076 && wPreferences.focus_mode != WKF_CLICK) {
1078 wSetFocusTo(scr, scr->focused_window);
1081 #ifdef BALLOON_TEXT
1082 wBalloonEnteredObject(scr, desc);
1083 #endif
1087 static void
1088 handleLeaveNotify(XEvent *event)
1090 WObjDescriptor *desc = NULL;
1092 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1093 (XPointer *)&desc)!=XCNOENT) {
1094 if(desc->handle_leavenotify)
1095 (*desc->handle_leavenotify)(desc, event);
1097 if (event->xcrossing.window == event->xcrossing.root
1098 && event->xcrossing.mode == NotifyNormal
1099 && event->xcrossing.detail != NotifyInferior
1100 && wPreferences.focus_mode != WKF_CLICK) {
1102 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1104 wSetFocusTo(scr, NULL);
1109 #ifdef SHAPE
1110 static void
1111 handleShapeNotify(XEvent *event)
1113 XShapeEvent *shev = (XShapeEvent*)event;
1114 WWindow *wwin;
1115 XEvent ev;
1117 #ifdef DEBUG
1118 puts("got shape notify");
1119 #endif
1121 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1122 XShapeEvent *sev = (XShapeEvent*)&ev;
1124 if (sev->kind == ShapeBounding) {
1125 if (sev->shaped == shev->shaped) {
1126 *shev = *sev;
1127 } else {
1128 XPutBackEvent(dpy, &ev);
1129 break;
1134 wwin = wWindowFor(shev->window);
1135 if (!wwin || shev->kind != ShapeBounding)
1136 return;
1138 if (!shev->shaped && wwin->flags.shaped) {
1140 wwin->flags.shaped = 0;
1141 wWindowClearShape(wwin);
1143 } else if (shev->shaped) {
1145 wwin->flags.shaped = 1;
1146 wWindowSetShape(wwin);
1149 #endif /* SHAPE */
1151 #ifdef KEEP_XKB_LOCK_STATUS
1152 /* please help ]d if you know what to do */
1153 handleXkbIndicatorStateNotify(XEvent *event)
1155 WWindow *wwin;
1156 WScreen *scr;
1157 XkbStateRec staterec;
1158 int i;
1160 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1161 for (i=0; i<wScreenCount; i++) {
1162 scr = wScreenWithNumber(i);
1163 wwin = scr->focused_window;
1164 if (wwin->flags.focused) {
1165 wwin->frame->languagemode=staterec.compat_state&32?1:0;
1166 #ifdef XKB_BUTTON_HINT
1167 if (wwin->frame->titlebar) {
1168 wFrameWindowPaint(wwin->frame);
1170 #endif
1171 #ifdef XKB_TITLE_HINT
1172 if (wwin->frame->titlebar) {
1173 XClearWindow(dpy, wwin->frame->titlebar->window);
1174 wFrameWindowPaint(wwin->frame);
1176 #endif /* XKB_TITLE_HINT */
1180 #endif /*KEEP_XKB_LOCK_STATUS*/
1182 static void
1183 handleColormapNotify(XEvent *event)
1185 WWindow *wwin;
1186 WScreen *scr;
1187 Bool reinstall = False;
1189 wwin = wWindowFor(event->xcolormap.window);
1190 if (!wwin)
1191 return;
1193 scr = wwin->screen_ptr;
1195 do {
1196 if (wwin) {
1197 if (event->xcolormap.new) {
1198 XWindowAttributes attr;
1200 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1202 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1203 scr->current_colormap = attr.colormap;
1205 reinstall = True;
1206 } else if (event->xcolormap.state == ColormapUninstalled &&
1207 scr->current_colormap == event->xcolormap.colormap) {
1209 /* some bastard app (like XV) removed our colormap */
1211 * can't enforce or things like xscreensaver wont work
1212 * reinstall = True;
1214 } else if (event->xcolormap.state == ColormapInstalled &&
1215 scr->current_colormap == event->xcolormap.colormap) {
1217 /* someone has put our colormap back */
1218 reinstall = False;
1221 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1222 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1224 if (reinstall && scr->current_colormap!=None) {
1225 if (!scr->flags.colormap_stuff_blocked)
1226 XInstallColormap(dpy, scr->current_colormap);
1232 static void
1233 handleFocusIn(XEvent *event)
1235 WWindow *wwin;
1238 * For applications that like stealing the focus.
1240 while (XCheckTypedEvent(dpy, FocusIn, event));
1241 saveTimestamp(event);
1242 if (event->xfocus.mode == NotifyUngrab
1243 || event->xfocus.mode == NotifyGrab
1244 || event->xfocus.detail > NotifyNonlinearVirtual) {
1245 return;
1248 wwin = wWindowFor(event->xfocus.window);
1249 if (wwin && !wwin->flags.focused) {
1250 if (wwin->flags.mapped)
1251 wSetFocusTo(wwin->screen_ptr, wwin);
1252 else
1253 wSetFocusTo(wwin->screen_ptr, NULL);
1254 } else if (!wwin) {
1255 WScreen *scr = wScreenForWindow(event->xfocus.window);
1256 if (scr)
1257 wSetFocusTo(scr, NULL);
1262 static WWindow*
1263 windowUnderPointer(WScreen *scr)
1265 unsigned int mask;
1266 int foo;
1267 Window bar, win;
1269 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1270 &mask))
1271 return wWindowFor(win);
1272 return NULL;
1275 #ifdef WEENDOZE_CYCLE
1277 static WWindow*
1278 nextToFocusAfter(WWindow *wwin)
1280 WWindow *tmp = wwin->prev;
1282 while (tmp) {
1283 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1285 return tmp;
1287 tmp = tmp->prev;
1290 tmp = wwin;
1291 /* start over from the beginning of the list */
1292 while (tmp->next)
1293 tmp = tmp->next;
1295 while (tmp && tmp != wwin) {
1296 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1298 return tmp;
1300 tmp = tmp->prev;
1303 return wwin;
1307 static WWindow*
1308 nextToFocusBefore(WWindow *wwin)
1310 WWindow *tmp = wwin->next;
1312 while (tmp) {
1313 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1315 return tmp;
1317 tmp = tmp->next;
1320 /* start over from the beginning of the list */
1321 tmp = wwin;
1322 while (tmp->prev)
1323 tmp = tmp->prev;
1325 while (tmp && tmp != wwin) {
1326 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1328 return tmp;
1330 tmp = tmp->next;
1333 return wwin;
1336 static void
1337 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1339 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1340 Bool done = False;
1341 Bool openedSwitchMenu = False;
1342 WWindow *newFocused;
1343 WWindow *oldFocused;
1344 int modifiers;
1345 XModifierKeymap *keymap;
1347 if (!wwin)
1348 return;
1350 /* puts("IN");*/
1351 keymap = XGetModifierMapping(dpy);
1354 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1355 CurrentTime);
1357 if (next) {
1358 newFocused = nextToFocusAfter(wwin);
1359 } else {
1360 newFocused = nextToFocusBefore(wwin);
1363 scr->flags.doing_alt_tab = 1;
1365 wWindowFocus(newFocused, scr->focused_window);
1366 oldFocused = newFocused;
1367 if (wPreferences.circ_raise)
1368 wRaiseFrame(newFocused->frame->core);
1370 if (wPreferences.popup_switchmenu &&
1371 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1373 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1374 openedSwitchMenu = True;
1377 while (!done) {
1378 XEvent ev;
1380 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1381 /* WMNextEvent(dpy, &ev);*/
1382 if (ev.type != KeyRelease && ev.type != KeyPress) {
1383 WMHandleEvent(&ev);
1384 continue;
1386 /*puts("EV");*/
1387 /* ignore CapsLock */
1388 modifiers = ev.xkey.state & ValidModMask;
1390 if (ev.type == KeyPress
1391 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1392 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1394 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1395 newFocused = nextToFocusAfter(newFocused);
1396 wWindowFocus(newFocused, oldFocused);
1397 oldFocused = newFocused;
1398 if (wPreferences.circ_raise)
1399 wRaiseFrame(newFocused->frame->core);
1400 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1402 } else if (ev.type == KeyPress
1403 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1404 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1406 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1407 newFocused = nextToFocusBefore(newFocused);
1408 wWindowFocus(newFocused, oldFocused);
1409 oldFocused = newFocused;
1410 if (wPreferences.circ_raise)
1411 wRaiseFrame(newFocused->frame->core);
1412 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1414 if (ev.type == KeyRelease) {
1415 int i;
1417 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1418 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1419 wKeyBindings[WKBD_FOCUSNEXT].modifier
1420 & 1<<(i/keymap->max_keypermod)) {
1421 done = True;
1422 break;
1427 /*puts("OUT");*/
1428 XFree(keymap);
1430 XUngrabKeyboard(dpy, CurrentTime);
1431 wSetFocusTo(scr, newFocused);
1432 scr->flags.doing_alt_tab = 0;
1433 if (openedSwitchMenu)
1434 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1438 #endif /* WEENDOZE_CYCLE */
1443 static void
1444 handleKeyPress(XEvent *event)
1446 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1447 WWindow *wwin = scr->focused_window;
1448 int i;
1449 int modifiers;
1450 int command=-1;
1451 #ifdef KEEP_XKB_LOCK_STATUS
1452 XkbStateRec staterec;
1453 #endif /*KEEP_XKB_LOCK_STATUS*/
1455 /* ignore CapsLock */
1456 modifiers = event->xkey.state & ValidModMask;
1458 for (i=0; i<WKBD_LAST; i++) {
1459 if (wKeyBindings[i].keycode==0)
1460 continue;
1462 if (wKeyBindings[i].keycode==event->xkey.keycode
1463 && (/*wKeyBindings[i].modifier==0
1464 ||*/ wKeyBindings[i].modifier==modifiers)) {
1465 command = i;
1466 break;
1470 if (command < 0) {
1471 #ifdef LITE
1473 #if 0
1475 #endif
1476 #else
1477 if (!wRootMenuPerformShortcut(event)) {
1478 #endif
1479 static int dontLoop = 0;
1481 if (dontLoop > 10) {
1482 wwarning("problem with key event processing code");
1483 return;
1485 dontLoop++;
1486 /* if the focused window is an internal window, try redispatching
1487 * the event to the managed window, as it can be a WINGs window */
1488 if (wwin && wwin->flags.internal_window
1489 && wwin->client_leader!=None) {
1490 /* client_leader contains the WINGs toplevel */
1491 event->xany.window = wwin->client_leader;
1492 WMHandleEvent(event);
1494 dontLoop--;
1496 return;
1499 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1500 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1502 switch (command) {
1503 #ifndef LITE
1504 case WKBD_ROOTMENU:
1505 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1506 break;
1507 case WKBD_WINDOWLIST:
1508 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1509 break;
1510 #endif /* !LITE */
1511 case WKBD_WINDOWMENU:
1512 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1513 OpenWindowMenu(wwin, wwin->frame_x,
1514 wwin->frame_y+wwin->frame->top_width, True);
1515 break;
1516 case WKBD_MINIATURIZE:
1517 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1518 && !WFLAGP(wwin, no_miniaturizable)) {
1519 CloseWindowMenu(scr);
1521 if (wwin->protocols.MINIATURIZE_WINDOW)
1522 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1523 event->xbutton.time);
1524 else {
1525 wIconifyWindow(wwin);
1528 break;
1529 case WKBD_HIDE:
1530 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1531 WApplication *wapp = wApplicationOf(wwin->main_window);
1532 CloseWindowMenu(scr);
1534 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1535 wHideApplication(wapp);
1538 break;
1539 case WKBD_MAXIMIZE:
1540 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1541 CloseWindowMenu(scr);
1543 if (wwin->flags.maximized) {
1544 wUnmaximizeWindow(wwin);
1545 } else {
1546 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1549 break;
1550 case WKBD_VMAXIMIZE:
1551 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1552 CloseWindowMenu(scr);
1554 if (wwin->flags.maximized) {
1555 wUnmaximizeWindow(wwin);
1556 } else {
1557 wMaximizeWindow(wwin, MAX_VERTICAL);
1560 break;
1561 case WKBD_RAISE:
1562 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1563 CloseWindowMenu(scr);
1565 wRaiseFrame(wwin->frame->core);
1567 break;
1568 case WKBD_LOWER:
1569 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1570 CloseWindowMenu(scr);
1572 wLowerFrame(wwin->frame->core);
1574 break;
1575 case WKBD_RAISELOWER:
1576 /* raise or lower the window under the pointer, not the
1577 * focused one
1579 wwin = windowUnderPointer(scr);
1580 if (wwin)
1581 wRaiseLowerFrame(wwin->frame->core);
1582 break;
1583 case WKBD_SHADE:
1584 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1585 if (wwin->flags.shaded)
1586 wUnshadeWindow(wwin);
1587 else
1588 wShadeWindow(wwin);
1590 break;
1591 case WKBD_MOVERESIZE:
1592 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1593 CloseWindowMenu(scr);
1595 wKeyboardMoveResizeWindow(wwin);
1597 break;
1598 case WKBD_CLOSE:
1599 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1600 CloseWindowMenu(scr);
1601 if (wwin->protocols.DELETE_WINDOW)
1602 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1603 event->xkey.time);
1605 break;
1606 case WKBD_SELECT:
1607 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1608 wSelectWindow(wwin, !wwin->flags.selected);
1610 break;
1611 case WKBD_FOCUSNEXT:
1612 #ifdef WEENDOZE_CYCLE
1613 if (wPreferences.windoze_cycling) {
1614 doWindozeCycle(wwin, event, True);
1615 } else
1616 #endif /* WEENDOZE_CYCLE */
1618 wwin = NextFocusWindow(scr);
1619 if (wwin != NULL) {
1620 wSetFocusTo(scr, wwin);
1621 if (wPreferences.circ_raise)
1622 wRaiseFrame(wwin->frame->core);
1625 break;
1627 case WKBD_FOCUSPREV:
1628 #ifdef WEENDOZE_CYCLE
1629 if (wPreferences.windoze_cycling) {
1630 doWindozeCycle(wwin, event, False);
1631 } else
1632 #endif /* WEENDOZE_CYCLE */
1634 wwin = PrevFocusWindow(scr);
1635 if (wwin != NULL) {
1636 wSetFocusTo(scr, wwin);
1637 if (wPreferences.circ_raise)
1638 wRaiseFrame(wwin->frame->core);
1641 break;
1643 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1644 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1645 i = (scr->current_workspace/10)*10 + wk - 1;\
1646 if (wPreferences.ws_advance || i<scr->workspace_count)\
1647 wWorkspaceChange(scr, i);\
1648 break
1649 #else
1650 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1651 i = (scr->current_workspace/10)*10 + wk - 1;\
1652 if (wPreferences.ws_advance || i<scr->workspace_count)\
1653 wWorkspaceChange(scr, i);\
1654 break
1655 #endif
1656 GOTOWORKS(1);
1657 GOTOWORKS(2);
1658 GOTOWORKS(3);
1659 GOTOWORKS(4);
1660 GOTOWORKS(5);
1661 GOTOWORKS(6);
1662 GOTOWORKS(7);
1663 GOTOWORKS(8);
1664 GOTOWORKS(9);
1665 GOTOWORKS(10);
1666 #undef GOTOWORKS
1667 case WKBD_NEXTWORKSPACE:
1668 wWorkspaceRelativeChange(scr, 1);
1669 break;
1670 case WKBD_PREVWORKSPACE:
1671 wWorkspaceRelativeChange(scr, -1);
1672 break;
1673 case WKBD_WINDOW1:
1674 case WKBD_WINDOW2:
1675 case WKBD_WINDOW3:
1676 case WKBD_WINDOW4:
1677 #ifdef EXTEND_WINDOWSHORTCUT
1678 case WKBD_WINDOW5:
1679 case WKBD_WINDOW6:
1680 case WKBD_WINDOW7:
1681 case WKBD_WINDOW8:
1682 case WKBD_WINDOW9:
1683 case WKBD_WINDOW10:
1684 #endif
1685 if ( scr->shortcutSelectedWindows[command-WKBD_WINDOW1]) {
1686 LinkedList *list = scr->shortcutSelectedWindows[command-WKBD_WINDOW1];
1687 int cw;
1689 wUnselectWindows(scr);
1690 if (scr->shortcutWindow[command-WKBD_WINDOW1])
1691 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1692 cw = scr->current_workspace;
1693 while (list) {
1694 wWindowChangeWorkspace(list->head, cw);
1695 wMakeWindowVisible(list->head);
1696 wSelectWindow(list->head, True);
1697 list = list->tail;
1699 } else if (scr->shortcutWindow[command-WKBD_WINDOW1]){
1701 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1703 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1705 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1706 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1707 LinkedList *sl;
1709 sl = scr->selected_windows;
1710 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1712 while (sl) {
1713 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1714 sl = sl->tail;
1717 wSelectWindow(wwin, !wwin->flags.selected);
1718 XFlush(dpy);
1719 wusleep(3000);
1720 wSelectWindow(wwin, !wwin->flags.selected);
1721 XFlush(dpy);
1723 } else if (scr->selected_windows) {
1725 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1726 LinkedList *sl;
1728 sl = scr->selected_windows;
1729 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1731 while (sl) {
1732 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1733 sl = sl->tail;
1738 break;
1739 case WKBD_NEXTWSLAYER:
1740 case WKBD_PREVWSLAYER:
1742 int row, column;
1744 row = scr->current_workspace/10;
1745 column = scr->current_workspace%10;
1747 if (command==WKBD_NEXTWSLAYER) {
1748 if ((row+1)*10 < scr->workspace_count)
1749 wWorkspaceChange(scr, column+(row+1)*10);
1750 } else {
1751 if (row > 0)
1752 wWorkspaceChange(scr, column+(row-1)*10);
1755 break;
1756 case WKBD_CLIPLOWER:
1757 if (!wPreferences.flags.noclip)
1758 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1759 break;
1760 case WKBD_CLIPRAISE:
1761 if (!wPreferences.flags.noclip)
1762 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1763 break;
1764 case WKBD_CLIPRAISELOWER:
1765 if (!wPreferences.flags.noclip)
1766 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1767 break;
1768 #ifdef KEEP_XKB_LOCK_STATUS
1769 case WKBD_TOGGLE:
1770 if(wPreferences.modelock) {
1771 /*toggle*/
1772 wwin = scr->focused_window;
1774 if (wwin && wwin->flags.mapped
1775 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1776 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1777 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1779 wwin->frame->languagemode = staterec.compat_state&32
1780 ? 0 : 1;
1781 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1785 break;
1786 #endif /* KEEP_XKB_LOCK_STATUS */
1792 static void
1793 handleMotionNotify(XEvent *event)
1795 WMenu *menu;
1796 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1798 if (wPreferences.scrollable_menus) {
1799 if (scr->flags.jump_back_pending ||
1800 event->xmotion.x_root <= 1 ||
1801 event->xmotion.x_root >= (scr->scr_width - 2) ||
1802 event->xmotion.y_root <= 1 ||
1803 event->xmotion.y_root >= (scr->scr_height - 2)) {
1805 #ifdef DEBUG
1806 puts("pointer at screen edge");
1807 #endif
1809 menu = wMenuUnderPointer(scr);
1810 if (menu!=NULL)
1811 wMenuScroll(menu, event);
1814 #if 0
1815 if (event->xmotion.subwindow == None)
1816 return;
1818 if (scr->scrolledFMaximize != None) {
1819 WWindow *twin;
1821 twin = wWindowFor(scr->scrolledFMaximize);
1822 if (twin && twin->frame_y ==) {
1826 scr->scrolledFMaximize = NULL;
1828 } else {
1830 /* scroll full maximized window */
1831 if (event->xmotion.y_root < 1
1832 || event->xmotion.y_root > scr->scr_height - 1) {
1834 wwin = wWindowFor(event->xmotion.subwindow);
1836 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1837 && WFLAGP(wwin, full_maximize)
1838 && event->xmotion.x_root >= wwin->frame_x
1839 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1841 if (!WFLAGP(wwin, no_titlebar)
1842 && wwin->frame_y <= - wwin->frame->top_width) {
1844 wWindowMove(wwin, wwin->frame_x, 0);
1845 wwin->flags.dragged_while_fmaximized = 0;
1847 } else if (!WFLAGP(wwin, no_resizebar)
1848 && wwin->frame_y + wwin->frame->core->height >=
1849 scr->scr_height + wwin->frame->bottom_width) {
1851 int y = scr->scr_height + wwin->frame->bottom_width;
1853 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1855 wWindowMove(wwin, wwin->frame_x, y);
1856 wwin->flags.dragged_while_fmaximized = 0;
1860 #endif
1864 static void
1865 handleVisibilityNotify(XEvent *event)
1867 WWindow *wwin;
1869 wwin = wWindowFor(event->xvisibility.window);
1870 if (!wwin)
1871 return;
1872 wwin->flags.obscured =
1873 (event->xvisibility.state == VisibilityFullyObscured);