GNOME mouseclickproxy thing fix
[wmaker-crm.git] / src / event.c
blob79dd800416971601fa9540a83a79b32afc65eb6f
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 XDE_DND
38 #include "xde.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 #ifdef GNOME_STUFF
60 # include "gnome.h"
61 #endif
62 #ifdef KWM_HINTS
63 # include "kwm.h"
64 #endif
66 /******** Global Variables **********/
67 extern XContext wWinContext;
69 extern Cursor wCursor[WCUR_LAST];
71 extern WShortKey wKeyBindings[WKBD_LAST];
72 extern int wScreenCount;
73 extern Time LastTimestamp;
74 extern Time LastFocusChange;
76 extern WPreferences wPreferences;
78 #define MOD_MASK wPreferences.modifier_mask
80 extern Atom _XA_WM_COLORMAP_NOTIFY;
82 extern Atom _XA_WM_CHANGE_STATE;
83 extern Atom _XA_WM_DELETE_WINDOW;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
85 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
86 extern Atom _XA_WINDOWMAKER_COMMAND;
88 #ifdef OFFIX_DND
89 extern Atom _XA_DND_PROTOCOL;
90 #endif
93 #ifdef SHAPE
94 extern Bool wShapeSupported;
95 extern int wShapeEventBase;
96 #endif
98 /* special flags */
99 extern char WDelayedActionSet;
102 /************ Local stuff ***********/
105 static void saveTimestamp(XEvent *event);
106 static void handleColormapNotify();
107 static void handleMapNotify(), handleUnmapNotify();
108 static void handleButtonPress(), handleExpose();
109 static void handleDestroyNotify();
110 static void handleConfigureRequest();
111 static void handleMapRequest();
112 static void handlePropertyNotify();
113 static void handleEnterNotify();
114 static void handleLeaveNotify();
115 static void handleExtensions();
116 static void handleClientMessage();
117 static void handleKeyPress();
118 static void handleFocusIn();
119 static void handleMotionNotify();
120 static void handleVisibilityNotify();
123 #ifdef SHAPE
124 static void handleShapeNotify();
125 #endif
127 /* called from the signal handler */
128 void NotifyDeadProcess(pid_t pid, unsigned char status);
130 /* real dead process handler */
131 static void handleDeadProcess(void *foo);
134 typedef struct DeadProcesses {
135 pid_t pid;
136 unsigned char exit_status;
137 } DeadProcesses;
139 /* stack of dead processes */
140 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
141 static int deadProcessPtr=0;
144 typedef struct DeathHandler {
145 WDeathHandler *callback;
146 pid_t pid;
147 struct DeathHandler *next;
148 void *client_data;
149 } DeathHandler;
151 static DeathHandler *deathHandler=NULL;
155 WMagicNumber
156 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
158 DeathHandler *handler;
160 handler = malloc(sizeof(DeathHandler));
161 if (!handler)
162 return 0;
164 handler->pid = pid;
165 handler->callback = callback;
166 handler->client_data = cdata;
168 handler->next = deathHandler;
170 deathHandler = handler;
172 return handler;
177 void
178 wDeleteDeathHandler(WMagicNumber id)
180 DeathHandler *tmp, *handler=(DeathHandler*)id;
182 if (!handler || !deathHandler)
183 return;
185 tmp = deathHandler;
186 if (tmp==handler) {
187 deathHandler = handler->next;
188 free(handler);
189 } else {
190 while (tmp->next) {
191 if (tmp->next==handler) {
192 tmp->next=handler->next;
193 free(handler);
194 break;
196 tmp = tmp->next;
202 void
203 DispatchEvent(XEvent *event)
205 if (deathHandler)
206 handleDeadProcess(NULL);
208 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
209 WCHANGE_STATE(WSTATE_EXITING);
210 /* received SIGTERM */
212 * WMHandleEvent() can't be called from anything
213 * executed inside here, or we can get in a infinite
214 * recursive loop.
216 Shutdown(WSExitMode);
218 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
219 WCHANGE_STATE(WSTATE_RESTARTING);
221 Shutdown(WSRestartPreparationMode);
222 /* received SIGHUP */
223 Restart(NULL, True);
226 /* for the case that all that is wanted to be dispatched is
227 * the stuff above */
228 if (!event)
229 return;
231 saveTimestamp(event);
232 switch (event->type) {
233 case MapRequest:
234 handleMapRequest(event);
235 break;
237 case KeyPress:
238 handleKeyPress(event);
239 break;
241 case MotionNotify:
242 handleMotionNotify(event);
243 break;
245 case ConfigureRequest:
246 handleConfigureRequest(event);
247 break;
249 case DestroyNotify:
250 handleDestroyNotify(event);
251 break;
253 case MapNotify:
254 handleMapNotify(event);
255 break;
257 case UnmapNotify:
258 handleUnmapNotify(event);
259 break;
261 case ButtonPress:
262 handleButtonPress(event);
263 break;
265 case Expose:
266 handleExpose(event);
267 break;
269 case PropertyNotify:
270 handlePropertyNotify(event);
271 break;
273 case EnterNotify:
274 handleEnterNotify(event);
275 break;
277 case LeaveNotify:
278 handleLeaveNotify(event);
279 break;
281 case ClientMessage:
282 handleClientMessage(event);
283 break;
285 case ColormapNotify:
286 handleColormapNotify(event);
287 break;
289 case MappingNotify:
290 if (event->xmapping.request == MappingKeyboard
291 || event->xmapping.request == MappingModifier)
292 XRefreshKeyboardMapping(&event->xmapping);
293 break;
295 case FocusIn:
296 handleFocusIn(event);
297 break;
299 case VisibilityNotify:
300 handleVisibilityNotify(event);
301 break;
302 default:
303 handleExtensions(event);
304 break;
310 *----------------------------------------------------------------------
311 * EventLoop-
312 * Processes X and internal events indefinitely.
314 * Returns:
315 * Never returns
317 * Side effects:
318 * The LastTimestamp global variable is updated.
319 *----------------------------------------------------------------------
321 void
322 EventLoop()
324 XEvent event;
326 for(;;) {
327 WMNextEvent(dpy, &event);
328 WMHandleEvent(&event);
334 Bool
335 IsDoubleClick(WScreen *scr, XEvent *event)
337 if ((scr->last_click_time>0) &&
338 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
339 && (event->xbutton.button == scr->last_click_button)
340 && (event->xbutton.window == scr->last_click_window)) {
342 scr->flags.next_click_is_not_double = 1;
343 scr->last_click_time = 0;
344 scr->last_click_window = event->xbutton.window;
346 return True;
348 return False;
352 void
353 NotifyDeadProcess(pid_t pid, unsigned char status)
355 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
356 wwarning("stack overflow: too many dead processes");
357 return;
359 /* stack the process to be handled later,
360 * as this is called from the signal handler */
361 deadProcesses[deadProcessPtr].pid = pid;
362 deadProcesses[deadProcessPtr].exit_status = status;
363 deadProcessPtr++;
367 static void
368 handleDeadProcess(void *foo)
370 DeathHandler *tmp;
371 int i;
373 for (i=0; i<deadProcessPtr; i++) {
374 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
377 if (!deathHandler) {
378 deadProcessPtr=0;
379 return;
382 /* get the pids on the queue and call handlers */
383 while (deadProcessPtr>0) {
384 deadProcessPtr--;
386 tmp = deathHandler;
387 while (tmp) {
388 DeathHandler *t;
390 t = tmp->next;
392 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
393 (*tmp->callback)(tmp->pid,
394 deadProcesses[deadProcessPtr].exit_status,
395 tmp->client_data);
396 wDeleteDeathHandler(tmp);
398 tmp = t;
404 static void
405 saveTimestamp(XEvent *event)
407 LastTimestamp = CurrentTime;
409 switch (event->type) {
410 case ButtonRelease:
411 case ButtonPress:
412 LastTimestamp = event->xbutton.time;
413 break;
414 case KeyPress:
415 case KeyRelease:
416 LastTimestamp = event->xkey.time;
417 break;
418 case MotionNotify:
419 LastTimestamp = event->xmotion.time;
420 break;
421 case PropertyNotify:
422 LastTimestamp = event->xproperty.time;
423 break;
424 case EnterNotify:
425 case LeaveNotify:
426 LastTimestamp = event->xcrossing.time;
427 break;
428 case SelectionClear:
429 LastTimestamp = event->xselectionclear.time;
430 break;
431 case SelectionRequest:
432 LastTimestamp = event->xselectionrequest.time;
433 break;
434 case SelectionNotify:
435 LastTimestamp = event->xselection.time;
436 break;
441 static void
442 handleExtensions(XEvent *event)
444 #ifdef SHAPE
445 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
446 handleShapeNotify(event);
448 #endif
449 #ifdef KEEP_XKB_LOCK_STATUS
450 if (wPreferences.modelock && event->type == (0x50|XkbIndicatorStateNotify)){
451 /* if someone know how to call this 0x50
452 * or how to clean code this please tell ]d */
453 handleXkbIndicatorStateNotify(event);
455 #endif /*KEEP_XKB_LOCK_STATUS*/
459 static void
460 handleMapRequest(XEvent *ev)
462 WWindow *wwin;
463 WScreen *scr = NULL;
464 Window window = ev->xmaprequest.window;
466 #ifdef DEBUG
467 printf("got map request for %x\n", (unsigned)window);
468 #endif
470 if ((wwin = wWindowFor(window))) {
471 if (wwin->flags.shaded) {
472 wUnshadeWindow(wwin);
474 /* deiconify window */
475 if (wwin->flags.miniaturized) {
476 wDeiconifyWindow(wwin);
477 } else if (wwin->flags.hidden) {
478 WApplication *wapp = wApplicationOf(wwin->main_window);
479 /* go to the last workspace that the user worked on the app */
480 #ifndef REDUCE_APPICONS
481 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
482 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
484 if (wapp) {
485 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
487 #endif
488 wUnhideApplication(wapp, False, False);
490 return;
493 scr = wScreenForRootWindow(ev->xmaprequest.parent);
495 wwin = wManageWindow(scr, window);
498 * This is to let the Dock know that the application it launched
499 * has already been mapped (eg: it has finished launching).
500 * It is not necessary for normally docked apps, but is needed for
501 * apps that were forcedly docked (like with dockit).
503 if (scr->last_dock) {
504 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
505 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
506 else
507 wDockTrackWindowLaunch(scr->last_dock, window);
510 if (wwin) {
511 wClientSetState(wwin, NormalState, None);
512 if (wwin->flags.maximized) {
513 wMaximizeWindow(wwin, wwin->flags.maximized);
515 if (wwin->flags.shaded) {
516 wwin->flags.shaded = 0;
517 wwin->flags.skip_next_animation = 1;
518 wShadeWindow(wwin);
520 if (wwin->flags.miniaturized) {
521 wwin->flags.miniaturized = 0;
522 wwin->flags.skip_next_animation = 1;
523 wIconifyWindow(wwin);
525 if (wwin->flags.hidden) {
526 WApplication *wapp = wApplicationOf(wwin->main_window);
528 wwin->flags.hidden = 0;
529 wwin->flags.skip_next_animation = 1;
530 if (wapp) {
531 wHideApplication(wapp);
538 static void
539 handleDestroyNotify(XEvent *event)
541 WWindow *wwin;
542 WApplication *app;
543 Window window = event->xdestroywindow.window;
545 #ifdef DEBUG
546 puts("got destroy notify");
547 #endif
549 wwin = wWindowFor(window);
550 if (wwin) {
551 wUnmanageWindow(wwin, False, True);
554 app = wApplicationOf(window);
555 if (app) {
556 if (window == app->main_window) {
557 app->refcount = 0;
558 wwin = app->main_window_desc->screen_ptr->focused_window;
559 while (wwin) {
560 if (wwin->main_window == window) {
561 wwin->main_window = None;
563 wwin = wwin->prev;
566 wApplicationDestroy(app);
569 #ifdef KWM_HINTS
570 wKWMCheckDestroy(&event->xdestroywindow);
571 #endif
576 static void
577 handleExpose(XEvent *event)
579 WObjDescriptor *desc;
580 XEvent ev;
582 #ifdef DEBUG
583 puts("got expose");
584 #endif
586 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
588 if (XFindContext(dpy, event->xexpose.window, wWinContext,
589 (XPointer *)&desc)==XCNOENT) {
590 return;
593 if (desc->handle_expose) {
594 (*desc->handle_expose)(desc, event);
599 /* bindable */
600 static void
601 handleButtonPress(XEvent *event)
603 WObjDescriptor *desc;
604 WScreen *scr;
606 #ifdef DEBUG
607 puts("got button press");
608 #endif
610 scr = wScreenForRootWindow(event->xbutton.root);
612 #ifdef BALLOON_TEXT
613 wBalloonHide(scr);
614 #endif
617 #ifndef LITE
618 if (event->xbutton.window==scr->root_win) {
620 if (event->xbutton.button==wPreferences.menu_button) {
621 OpenRootMenu(scr, event->xbutton.x_root,
622 event->xbutton.y_root, False);
623 /* ugly hack */
624 if (scr->root_menu) {
625 if (scr->root_menu->brother->flags.mapped)
626 event->xbutton.window = scr->root_menu->brother->frame->core->window;
627 else
628 event->xbutton.window = scr->root_menu->frame->core->window;
630 } else if (event->xbutton.button==wPreferences.windowl_button) {
631 OpenSwitchMenu(scr, event->xbutton.x_root,
632 event->xbutton.y_root, False);
633 if (scr->switch_menu) {
634 if (scr->switch_menu->brother->flags.mapped)
635 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
636 else
637 event->xbutton.window = scr->switch_menu->frame->core->window;
639 } else if (event->xbutton.button==wPreferences.select_button) {
640 wUnselectWindows(scr);
641 wSelectWindows(scr, event);
643 #ifdef MOUSE_WS_SWITCH
644 else if (event->xbutton.button==Button5) {
646 wWorkspaceRelativeChange(scr, -1);
648 } else if (event->xbutton.button==Button4) {
650 wWorkspaceRelativeChange(scr, 1);
653 #endif /* MOUSE_WS_SWITCH */
654 #ifdef GNOME_STUFF
655 else if (wGNOMEProxyizeButtonEvent(scr, event))
656 return;
657 #endif
659 #endif /* !LITE */
661 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
662 (XPointer *)&desc)==XCNOENT) {
663 if (XFindContext(dpy, event->xbutton.window, wWinContext,
664 (XPointer *)&desc)==XCNOENT) {
665 return;
669 if (desc->handle_mousedown!=NULL) {
670 (*desc->handle_mousedown)(desc, event);
673 if (desc->parent_type == WCLASS_WINDOW) {
674 XSync(dpy, 0);
676 if (event->xbutton.state & MOD_MASK) {
677 XAllowEvents(dpy, AsyncPointer, CurrentTime);
680 if (wPreferences.focus_mode == WKF_CLICK) {
681 if (wPreferences.ignore_focus_click) {
682 XAllowEvents(dpy, AsyncPointer, CurrentTime);
684 XAllowEvents(dpy, ReplayPointer, CurrentTime);
686 XSync(dpy, 0);
687 } else if (desc->parent_type == WCLASS_APPICON
688 || desc->parent_type == WCLASS_MINIWINDOW
689 || desc->parent_type == WCLASS_DOCK_ICON) {
690 if (event->xbutton.state & MOD_MASK) {
691 XSync(dpy, 0);
692 XAllowEvents(dpy, AsyncPointer, CurrentTime);
693 XSync(dpy, 0);
697 /* save double-click information */
698 if (scr->flags.next_click_is_not_double) {
699 scr->flags.next_click_is_not_double = 0;
700 } else {
701 scr->last_click_time = event->xbutton.time;
702 scr->last_click_button = event->xbutton.button;
703 scr->last_click_window = event->xbutton.window;
708 static void
709 handleMapNotify(XEvent *event)
711 WWindow *wwin;
713 #ifdef DEBUG
714 puts("got map");
715 #endif
717 wwin = wWindowFor(event->xmap.event);
718 if (wwin && wwin->client_win == event->xmap.event) {
719 if (wwin->flags.miniaturized) {
720 wDeiconifyWindow(wwin);
721 } else {
722 XGrabServer(dpy);
723 wWindowMap(wwin);
724 wClientSetState(wwin, NormalState, None);
725 XUngrabServer(dpy);
731 static void
732 handleUnmapNotify(XEvent *event)
734 WWindow *wwin;
735 XEvent ev;
736 Bool withdraw = False;
738 #ifdef DEBUG
739 puts("got unmap");
740 #endif
742 /* only process windows with StructureNotify selected
743 * (ignore SubstructureNotify) */
744 wwin = wWindowFor(event->xunmap.window);
745 if (!wwin)
746 return;
748 /* whether the event is a Withdrawal request */
749 if (event->xunmap.event == wwin->screen_ptr->root_win
750 && event->xunmap.send_event)
751 withdraw = True;
753 if (wwin->client_win != event->xunmap.event && !withdraw)
754 return;
756 if (!wwin->flags.mapped && !withdraw
757 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
758 && !wwin->flags.miniaturized && !wwin->flags.hidden)
759 return;
761 XGrabServer(dpy);
762 XUnmapWindow(dpy, wwin->frame->core->window);
763 wwin->flags.mapped = 0;
764 XSync(dpy, 0);
765 /* check if the window was destroyed */
766 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
767 DispatchEvent(&ev);
768 } else {
769 Bool reparented = False;
771 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
772 reparented = True;
774 /* withdraw window */
775 wwin->flags.mapped = 0;
776 if (!reparented)
777 wClientSetState(wwin, WithdrawnState, None);
779 /* if the window was reparented, do not reparent it back to the
780 * root window */
781 wUnmanageWindow(wwin, !reparented, False);
783 XUngrabServer(dpy);
787 static void
788 handleConfigureRequest(XEvent *event)
790 WWindow *wwin;
792 #ifdef DEBUG
793 puts("got configure request");
794 #endif
795 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
797 * Configure request for unmapped window
799 wClientConfigure(NULL, &(event->xconfigurerequest));
800 } else {
801 wClientConfigure(wwin, &(event->xconfigurerequest));
806 static void
807 handlePropertyNotify(XEvent *event)
809 WWindow *wwin;
810 WApplication *wapp;
811 Window jr;
812 int ji;
813 unsigned int ju;
814 WScreen *scr;
816 #ifdef DEBUG
817 puts("got property notify");
818 #endif
819 if ((wwin=wWindowFor(event->xproperty.window))) {
820 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
821 &ju, &ju, &ju, &ju)) {
822 return;
824 wClientCheckProperty(wwin, &event->xproperty);
826 wapp = wApplicationOf(event->xproperty.window);
827 if (wapp) {
828 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
831 scr = wScreenForWindow(event->xproperty.window);
832 if (scr && scr->root_win == event->xproperty.window) {
833 #ifdef KWM_HINTS
834 wKWMCheckRootHintChange(scr, &event->xproperty);
835 #endif
840 static void
841 handleClientMessage(XEvent *event)
843 WWindow *wwin;
844 WObjDescriptor *desc;
846 #ifdef DEBUG
847 puts("got client message");
848 #endif
849 /* handle transition from Normal to Iconic state */
850 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
851 && event->xclient.format == 32
852 && event->xclient.data.l[0] == IconicState) {
854 wwin = wWindowFor(event->xclient.window);
855 if (!wwin) return;
856 if (!wwin->flags.miniaturized)
857 wIconifyWindow(wwin);
858 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
859 && event->xclient.format == 32) {
860 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
862 if (!scr)
863 return;
865 if (event->xclient.data.l[1] == 1) { /* starting */
866 wColormapAllowClientInstallation(scr, True);
867 } else { /* stopping */
868 wColormapAllowClientInstallation(scr, False);
870 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
872 wDefaultsCheckDomains("bla");
874 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
875 WApplication *wapp;
876 int done=0;
877 wapp = wApplicationOf(event->xclient.window);
878 if (wapp) {
879 switch (event->xclient.data.l[0]) {
880 case WMFHideOtherApplications:
881 wHideOtherApplications(wapp->main_window_desc);
882 done = 1;
883 break;
885 case WMFHideApplication:
886 wHideApplication(wapp);
887 done = 1;
888 break;
891 if (!done) {
892 wwin = wWindowFor(event->xclient.window);
893 if (wwin) {
894 switch (event->xclient.data.l[0]) {
895 case WMFHideOtherApplications:
896 wHideOtherApplications(wwin);
897 break;
899 case WMFHideApplication:
900 wHideApplication(wApplicationOf(wwin->main_window));
901 break;
905 #ifdef GNOME_STUFF
906 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
907 /* do nothing */
908 #endif /* GNOME_STUFF */
909 #ifdef KWM_HINTS
910 } else if (wKWMProcessClientMessage(&event->xclient)) {
911 /* do nothing */
912 #endif /* KWM_HINTS */
913 #ifdef XDE_DND
914 } else if (wXDEProcessClientMessage(&event->xclient)) {
915 /* do nothing */
916 #endif /* XDE_DND */
917 #ifdef OFFIX_DND
918 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
919 WScreen *scr = wScreenForWindow(event->xclient.window);
920 if (scr && wDockReceiveDNDDrop(scr,event))
921 goto redirect_message;
922 #endif /* OFFIX_DND */
923 } else {
924 #ifdef OFFIX_DND
925 redirect_message:
926 #endif
928 * Non-standard thing, but needed by OffiX DND.
929 * For when the icon frame gets a ClientMessage
930 * that should have gone to the icon_window.
932 if (XFindContext(dpy, event->xbutton.window, wWinContext,
933 (XPointer *)&desc)!=XCNOENT) {
934 struct WIcon *icon=NULL;
936 if (desc->parent_type == WCLASS_MINIWINDOW) {
937 icon = (WIcon*)desc->parent;
938 } else if (desc->parent_type == WCLASS_DOCK_ICON
939 || desc->parent_type == WCLASS_APPICON) {
940 icon = ((WAppIcon*)desc->parent)->icon;
942 if (icon && (wwin=icon->owner)) {
943 if (wwin->client_win!=event->xclient.window) {
944 event->xclient.window = wwin->client_win;
945 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
946 event);
954 static void
955 raiseWindow(WScreen *scr)
957 WWindow *wwin;
959 scr->autoRaiseTimer = NULL;
961 wwin = wWindowFor(scr->autoRaiseWindow);
962 if (!wwin)
963 return;
965 if (!wwin->flags.destroyed) {
966 wRaiseFrame(wwin->frame->core);
967 /* this is needed or a race condition will occur */
968 XSync(dpy, False);
973 static void
974 handleEnterNotify(XEvent *event)
976 WWindow *wwin;
977 WObjDescriptor *desc = NULL;
978 XEvent ev;
979 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
982 #ifdef DEBUG
983 puts("got enter notify");
984 #endif
986 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
987 &ev)) {
988 /* already left the window... */
989 saveTimestamp(&ev);
990 if (ev.xcrossing.mode==event->xcrossing.mode
991 && ev.xcrossing.detail==event->xcrossing.detail) {
992 return;
996 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
997 (XPointer *)&desc)!=XCNOENT) {
998 if(desc->handle_enternotify)
999 (*desc->handle_enternotify)(desc, event);
1002 /* enter to window */
1003 wwin = wWindowFor(event->xcrossing.window);
1004 if (!wwin) {
1005 if (wPreferences.focus_mode==WKF_POINTER
1006 && event->xcrossing.window==event->xcrossing.root) {
1007 wSetFocusTo(scr, NULL);
1009 if (wPreferences.colormap_mode==WKF_POINTER) {
1010 wColormapInstallForWindow(scr, NULL);
1012 if (scr->autoRaiseTimer
1013 && event->xcrossing.root==event->xcrossing.window) {
1014 WMDeleteTimerHandler(scr->autoRaiseTimer);
1015 scr->autoRaiseTimer = NULL;
1017 } else {
1018 /* set auto raise timer even if in focus-follows-mouse mode
1019 * and the event is for the frame window, even if the window
1020 * has focus already. useful if you move the pointer from a focused
1021 * window to the root window and back pretty fast
1023 * set focus if in focus-follows-mouse mode and the event
1024 * is for the frame window and window doesn't have focus yet */
1025 if ((wPreferences.focus_mode==WKF_POINTER
1026 || wPreferences.focus_mode==WKF_SLOPPY)
1027 && wwin->frame->core->window==event->xcrossing.window
1028 && !scr->flags.doing_alt_tab) {
1030 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1031 wSetFocusTo(scr, wwin);
1033 if (scr->autoRaiseTimer)
1034 WMDeleteTimerHandler(scr->autoRaiseTimer);
1035 scr->autoRaiseTimer = NULL;
1037 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1038 scr->autoRaiseWindow = wwin->frame->core->window;
1039 scr->autoRaiseTimer
1040 = WMAddTimerHandler(wPreferences.raise_delay,
1041 (WMCallback*)raiseWindow, scr);
1044 /* Install colormap for window, if the colormap installation mode
1045 * is colormap_follows_mouse */
1046 if (wPreferences.colormap_mode==WKF_POINTER) {
1047 if (wwin->client_win==event->xcrossing.window)
1048 wColormapInstallForWindow(scr, wwin);
1049 else
1050 wColormapInstallForWindow(scr, NULL);
1054 /* a little kluge to hide the clip balloon */
1055 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1056 if (!desc) {
1057 XUnmapWindow(dpy, scr->clip_balloon);
1058 scr->flags.clip_balloon_mapped = 0;
1059 } else {
1060 if (desc->parent_type!=WCLASS_DOCK_ICON
1061 || scr->clip_icon != desc->parent) {
1062 XUnmapWindow(dpy, scr->clip_balloon);
1063 scr->flags.clip_balloon_mapped = 0;
1068 if (event->xcrossing.window == event->xcrossing.root
1069 && event->xcrossing.detail == NotifyNormal
1070 && event->xcrossing.detail != NotifyInferior
1071 && wPreferences.focus_mode != WKF_CLICK) {
1073 wSetFocusTo(scr, scr->focused_window);
1076 #ifdef BALLOON_TEXT
1077 wBalloonEnteredObject(scr, desc);
1078 #endif
1082 static void
1083 handleLeaveNotify(XEvent *event)
1085 WObjDescriptor *desc = NULL;
1087 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1088 (XPointer *)&desc)!=XCNOENT) {
1089 if(desc->handle_leavenotify)
1090 (*desc->handle_leavenotify)(desc, event);
1092 if (event->xcrossing.window == event->xcrossing.root
1093 && event->xcrossing.mode == NotifyNormal
1094 && event->xcrossing.detail != NotifyInferior
1095 && wPreferences.focus_mode != WKF_CLICK) {
1097 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1099 wSetFocusTo(scr, NULL);
1104 #ifdef SHAPE
1105 static void
1106 handleShapeNotify(XEvent *event)
1108 XShapeEvent *shev = (XShapeEvent*)event;
1109 WWindow *wwin;
1110 XEvent ev;
1112 #ifdef DEBUG
1113 puts("got shape notify");
1114 #endif
1116 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1117 XShapeEvent *sev = (XShapeEvent*)&ev;
1119 if (sev->kind == ShapeBounding) {
1120 if (sev->shaped == shev->shaped) {
1121 *shev = *sev;
1122 } else {
1123 XPutBackEvent(dpy, &ev);
1124 break;
1129 wwin = wWindowFor(shev->window);
1130 if (!wwin || shev->kind != ShapeBounding)
1131 return;
1133 if (!shev->shaped && wwin->flags.shaped) {
1135 wwin->flags.shaped = 0;
1136 wWindowClearShape(wwin);
1138 } else if (shev->shaped) {
1140 wwin->flags.shaped = 1;
1141 wWindowSetShape(wwin);
1144 #endif /* SHAPE */
1146 #ifdef KEEP_XKB_LOCK_STATUS
1147 /* please help ]d if you know what to do */
1148 handleXkbIndicatorStateNotify(XEvent *event)
1150 WWindow *wwin;
1151 WScreen *scr;
1152 XkbStateRec staterec;
1153 int i;
1155 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1156 for (i=0; i<wScreenCount; i++) {
1157 scr = wScreenWithNumber(i);
1158 wwin = scr->focused_window;
1159 if (wwin->flags.focused) {
1160 wwin->frame->languagemode=staterec.compat_state&32?1:0;
1161 #ifdef XKB_TITLE_HINT
1162 if (wwin->frame->titlebar) {
1163 XClearWindow(dpy, wwin->frame->titlebar->window);
1164 wFrameWindowPaint(wwin->frame);
1166 #endif /* XKB_TITLE_HINT */
1170 #endif /*KEEP_XKB_LOCK_STATUS*/
1172 static void
1173 handleColormapNotify(XEvent *event)
1175 WWindow *wwin;
1176 WScreen *scr;
1177 Bool reinstall = False;
1179 wwin = wWindowFor(event->xcolormap.window);
1180 if (!wwin)
1181 return;
1183 scr = wwin->screen_ptr;
1185 do {
1186 if (wwin) {
1187 if (event->xcolormap.new) {
1188 XWindowAttributes attr;
1190 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1192 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1193 scr->current_colormap = attr.colormap;
1195 reinstall = True;
1196 } else if (event->xcolormap.state == ColormapUninstalled &&
1197 scr->current_colormap == event->xcolormap.colormap) {
1199 /* some bastard app (like XV) removed our colormap */
1201 * can't enforce or things like xscreensaver wont work
1202 * reinstall = True;
1204 } else if (event->xcolormap.state == ColormapInstalled &&
1205 scr->current_colormap == event->xcolormap.colormap) {
1207 /* someone has put our colormap back */
1208 reinstall = False;
1211 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1212 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1214 if (reinstall && scr->current_colormap!=None) {
1215 if (!scr->flags.colormap_stuff_blocked)
1216 XInstallColormap(dpy, scr->current_colormap);
1222 static void
1223 handleFocusIn(XEvent *event)
1225 WWindow *wwin;
1228 * For applications that like stealing the focus.
1230 while (XCheckTypedEvent(dpy, FocusIn, event));
1231 saveTimestamp(event);
1232 if (event->xfocus.mode == NotifyUngrab
1233 || event->xfocus.mode == NotifyGrab
1234 || event->xfocus.detail > NotifyNonlinearVirtual) {
1235 return;
1238 wwin = wWindowFor(event->xfocus.window);
1239 if (wwin && !wwin->flags.focused) {
1240 if (wwin->flags.mapped)
1241 wSetFocusTo(wwin->screen_ptr, wwin);
1242 else
1243 wSetFocusTo(wwin->screen_ptr, NULL);
1244 } else if (!wwin) {
1245 WScreen *scr = wScreenForWindow(event->xfocus.window);
1246 if (scr)
1247 wSetFocusTo(scr, NULL);
1252 static WWindow*
1253 windowUnderPointer(WScreen *scr)
1255 unsigned int mask;
1256 int foo;
1257 Window bar, win;
1259 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1260 &mask))
1261 return wWindowFor(win);
1262 return NULL;
1265 #ifdef WEENDOZE_CYCLE
1267 static WWindow*
1268 nextToFocusAfter(WWindow *wwin)
1270 WWindow *tmp = wwin->prev;
1272 while (tmp) {
1273 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1275 return tmp;
1277 tmp = tmp->prev;
1280 tmp = wwin;
1281 /* start over from the beginning of the list */
1282 while (tmp->next)
1283 tmp = tmp->next;
1285 while (tmp && tmp != wwin) {
1286 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1288 return tmp;
1290 tmp = tmp->prev;
1293 return wwin;
1297 static WWindow*
1298 nextToFocusBefore(WWindow *wwin)
1300 WWindow *tmp = wwin->next;
1302 while (tmp) {
1303 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1305 return tmp;
1307 tmp = tmp->next;
1310 /* start over from the beginning of the list */
1311 tmp = wwin;
1312 while (tmp->prev)
1313 tmp = tmp->prev;
1315 while (tmp && tmp != wwin) {
1316 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1318 return tmp;
1320 tmp = tmp->next;
1323 return wwin;
1326 static void
1327 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1329 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1330 Bool done = False;
1331 Bool openedSwitchMenu = False;
1332 WWindow *newFocused;
1333 WWindow *oldFocused;
1334 int modifiers;
1335 XModifierKeymap *keymap;
1337 if (!wwin)
1338 return;
1340 /* puts("IN");*/
1341 keymap = XGetModifierMapping(dpy);
1344 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1345 CurrentTime);
1347 if (next) {
1348 newFocused = nextToFocusAfter(wwin);
1349 } else {
1350 newFocused = nextToFocusBefore(wwin);
1353 scr->flags.doing_alt_tab = 1;
1355 wWindowFocus(newFocused, scr->focused_window);
1356 oldFocused = newFocused;
1357 if (wPreferences.circ_raise)
1358 wRaiseFrame(newFocused->frame->core);
1360 if (wPreferences.popup_switchmenu &&
1361 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1363 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1364 openedSwitchMenu = True;
1367 while (!done) {
1368 XEvent ev;
1370 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1371 /* WMNextEvent(dpy, &ev);*/
1372 if (ev.type != KeyRelease && ev.type != KeyPress) {
1373 WMHandleEvent(&ev);
1374 continue;
1376 /*puts("EV");*/
1377 /* ignore CapsLock */
1378 modifiers = ev.xkey.state & ValidModMask;
1380 if (ev.type == KeyPress
1381 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1382 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1384 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1385 newFocused = nextToFocusAfter(newFocused);
1386 wWindowFocus(newFocused, oldFocused);
1387 oldFocused = newFocused;
1388 if (wPreferences.circ_raise)
1389 wRaiseFrame(newFocused->frame->core);
1390 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1392 } else if (ev.type == KeyPress
1393 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1394 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1396 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1397 newFocused = nextToFocusBefore(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 if (ev.type == KeyRelease) {
1405 int i;
1407 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1408 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1409 wKeyBindings[WKBD_FOCUSNEXT].modifier
1410 & 1<<(i/keymap->max_keypermod)) {
1411 done = True;
1412 break;
1417 /*puts("OUT");*/
1418 XFree(keymap);
1420 XUngrabKeyboard(dpy, CurrentTime);
1421 wSetFocusTo(scr, newFocused);
1422 scr->flags.doing_alt_tab = 0;
1423 if (openedSwitchMenu)
1424 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1428 #endif /* WEENDOZE_CYCLE */
1433 static void
1434 handleKeyPress(XEvent *event)
1436 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1437 WWindow *wwin = scr->focused_window;
1438 int i;
1439 int modifiers;
1440 int command=-1;
1441 #ifdef KEEP_XKB_LOCK_STATUS
1442 XkbStateRec staterec;
1443 #endif /*KEEP_XKB_LOCK_STATUS*/
1445 /* ignore CapsLock */
1446 modifiers = event->xkey.state & ValidModMask;
1448 for (i=0; i<WKBD_LAST; i++) {
1449 if (wKeyBindings[i].keycode==0)
1450 continue;
1452 if (wKeyBindings[i].keycode==event->xkey.keycode
1453 && (/*wKeyBindings[i].modifier==0
1454 ||*/ wKeyBindings[i].modifier==modifiers)) {
1455 command = i;
1456 break;
1460 if (command < 0) {
1461 #ifdef LITE
1463 #if 0
1465 #endif
1466 #else
1467 if (!wRootMenuPerformShortcut(event)) {
1468 #endif
1469 static int dontLoop = 0;
1471 if (dontLoop > 10) {
1472 wwarning("problem with key event processing code");
1473 return;
1475 dontLoop++;
1476 /* if the focused window is an internal window, try redispatching
1477 * the event to the managed window, as it can be a WINGs window */
1478 if (wwin && wwin->flags.internal_window
1479 && wwin->client_leader!=None) {
1480 /* client_leader contains the WINGs toplevel */
1481 event->xany.window = wwin->client_leader;
1482 WMHandleEvent(event);
1484 dontLoop--;
1486 return;
1489 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1490 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1492 switch (command) {
1493 #ifndef LITE
1494 case WKBD_ROOTMENU:
1495 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1496 break;
1497 case WKBD_WINDOWLIST:
1498 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1499 break;
1500 #endif /* !LITE */
1501 case WKBD_WINDOWMENU:
1502 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1503 OpenWindowMenu(wwin, wwin->frame_x,
1504 wwin->frame_y+wwin->frame->top_width, True);
1505 break;
1506 case WKBD_MINIATURIZE:
1507 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1508 && !WFLAGP(wwin, no_miniaturizable)) {
1509 CloseWindowMenu(scr);
1511 if (wwin->protocols.MINIATURIZE_WINDOW)
1512 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1513 event->xbutton.time);
1514 else {
1515 wIconifyWindow(wwin);
1518 break;
1519 case WKBD_HIDE:
1520 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1521 WApplication *wapp = wApplicationOf(wwin->main_window);
1522 CloseWindowMenu(scr);
1524 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1525 wHideApplication(wapp);
1528 break;
1529 case WKBD_MAXIMIZE:
1530 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1531 CloseWindowMenu(scr);
1533 if (wwin->flags.maximized) {
1534 wUnmaximizeWindow(wwin);
1535 } else {
1536 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1539 break;
1540 case WKBD_VMAXIMIZE:
1541 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1542 CloseWindowMenu(scr);
1544 if (wwin->flags.maximized) {
1545 wUnmaximizeWindow(wwin);
1546 } else {
1547 wMaximizeWindow(wwin, MAX_VERTICAL);
1550 break;
1551 case WKBD_RAISE:
1552 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1553 CloseWindowMenu(scr);
1555 wRaiseFrame(wwin->frame->core);
1557 break;
1558 case WKBD_LOWER:
1559 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1560 CloseWindowMenu(scr);
1562 wLowerFrame(wwin->frame->core);
1564 break;
1565 case WKBD_RAISELOWER:
1566 /* raise or lower the window under the pointer, not the
1567 * focused one
1569 wwin = windowUnderPointer(scr);
1570 if (wwin)
1571 wRaiseLowerFrame(wwin->frame->core);
1572 break;
1573 case WKBD_SHADE:
1574 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1575 if (wwin->flags.shaded)
1576 wUnshadeWindow(wwin);
1577 else
1578 wShadeWindow(wwin);
1580 break;
1581 case WKBD_MOVERESIZE:
1582 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1583 CloseWindowMenu(scr);
1585 wKeyboardMoveResizeWindow(wwin);
1587 break;
1588 case WKBD_CLOSE:
1589 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1590 CloseWindowMenu(scr);
1591 if (wwin->protocols.DELETE_WINDOW)
1592 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1593 event->xkey.time);
1595 break;
1596 case WKBD_SELECT:
1597 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1598 wSelectWindow(wwin, !wwin->flags.selected);
1600 break;
1601 case WKBD_FOCUSNEXT:
1602 #ifdef WEENDOZE_CYCLE
1603 if (wPreferences.windoze_cycling) {
1604 doWindozeCycle(wwin, event, True);
1605 } else
1606 #endif /* WEENDOZE_CYCLE */
1608 wwin = NextFocusWindow(scr);
1609 if (wwin != NULL) {
1610 wSetFocusTo(scr, wwin);
1611 if (wPreferences.circ_raise)
1612 wRaiseFrame(wwin->frame->core);
1615 break;
1617 case WKBD_FOCUSPREV:
1618 #ifdef WEENDOZE_CYCLE
1619 if (wPreferences.windoze_cycling) {
1620 doWindozeCycle(wwin, event, False);
1621 } else
1622 #endif /* WEENDOZE_CYCLE */
1624 wwin = PrevFocusWindow(scr);
1625 if (wwin != NULL) {
1626 wSetFocusTo(scr, wwin);
1627 if (wPreferences.circ_raise)
1628 wRaiseFrame(wwin->frame->core);
1631 break;
1633 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1634 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1635 i = (scr->current_workspace/10)*10 + wk - 1;\
1636 if (wPreferences.ws_advance || i<scr->workspace_count)\
1637 wWorkspaceChange(scr, i);\
1638 break
1639 #else
1640 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1641 i = (scr->current_workspace/10)*10 + wk - 1;\
1642 if (wPreferences.ws_advance || i<scr->workspace_count)\
1643 wWorkspaceChange(scr, i);\
1644 break
1645 #endif
1646 GOTOWORKS(1);
1647 GOTOWORKS(2);
1648 GOTOWORKS(3);
1649 GOTOWORKS(4);
1650 GOTOWORKS(5);
1651 GOTOWORKS(6);
1652 GOTOWORKS(7);
1653 GOTOWORKS(8);
1654 GOTOWORKS(9);
1655 GOTOWORKS(10);
1656 #undef GOTOWORKS
1657 case WKBD_NEXTWORKSPACE:
1658 wWorkspaceRelativeChange(scr, 1);
1659 break;
1660 case WKBD_PREVWORKSPACE:
1661 wWorkspaceRelativeChange(scr, -1);
1662 break;
1663 case WKBD_WINDOW1:
1664 case WKBD_WINDOW2:
1665 case WKBD_WINDOW3:
1666 case WKBD_WINDOW4:
1667 #ifdef EXTEND_WINDOWSHORTCUT
1668 case WKBD_WINDOW5:
1669 case WKBD_WINDOW6:
1670 case WKBD_WINDOW7:
1671 case WKBD_WINDOW8:
1672 case WKBD_WINDOW9:
1673 case WKBD_WINDOW10:
1674 #endif
1675 if (scr->shortcutWindow[command-WKBD_WINDOW1]) {
1676 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1677 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1678 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1679 wSelectWindow(wwin, !wwin->flags.selected);
1680 XFlush(dpy);
1681 wusleep(3000);
1682 wSelectWindow(wwin, !wwin->flags.selected);
1683 XFlush(dpy);
1685 break;
1686 case WKBD_NEXTWSLAYER:
1687 case WKBD_PREVWSLAYER:
1689 int row, column;
1691 row = scr->current_workspace/10;
1692 column = scr->current_workspace%10;
1694 if (command==WKBD_NEXTWSLAYER) {
1695 if ((row+1)*10 < scr->workspace_count)
1696 wWorkspaceChange(scr, column+(row+1)*10);
1697 } else {
1698 if (row > 0)
1699 wWorkspaceChange(scr, column+(row-1)*10);
1702 break;
1703 case WKBD_CLIPLOWER:
1704 if (!wPreferences.flags.noclip)
1705 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1706 break;
1707 case WKBD_CLIPRAISE:
1708 if (!wPreferences.flags.noclip)
1709 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1710 break;
1711 case WKBD_CLIPRAISELOWER:
1712 if (!wPreferences.flags.noclip)
1713 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1714 break;
1715 #ifdef KEEP_XKB_LOCK_STATUS
1716 case WKBD_TOGGLE:
1717 if(wPreferences.modelock) {
1718 /*toggle*/
1719 wwin = scr->focused_window;
1721 if (wwin && wwin->flags.mapped
1722 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1723 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1724 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1726 wwin->frame->languagemode = staterec.compat_state&32
1727 ? 0 : 1;
1728 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1732 break;
1733 #endif /* KEEP_XKB_LOCK_STATUS */
1739 static void
1740 handleMotionNotify(XEvent *event)
1742 WMenu *menu;
1743 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1745 if (wPreferences.scrollable_menus) {
1746 if (scr->flags.jump_back_pending ||
1747 event->xmotion.x_root <= 1 ||
1748 event->xmotion.x_root >= (scr->scr_width - 2) ||
1749 event->xmotion.y_root <= 1 ||
1750 event->xmotion.y_root >= (scr->scr_height - 2)) {
1752 #ifdef DEBUG
1753 puts("pointer at screen edge");
1754 #endif
1756 menu = wMenuUnderPointer(scr);
1757 if (menu!=NULL)
1758 wMenuScroll(menu, event);
1761 #if 0
1762 if (event->xmotion.subwindow == None)
1763 return;
1765 if (scr->scrolledFMaximize != None) {
1766 WWindow *twin;
1768 twin = wWindowFor(scr->scrolledFMaximize);
1769 if (twin && twin->frame_y ==) {
1773 scr->scrolledFMaximize = NULL;
1775 } else {
1777 /* scroll full maximized window */
1778 if (event->xmotion.y_root < 1
1779 || event->xmotion.y_root > scr->scr_height - 1) {
1781 wwin = wWindowFor(event->xmotion.subwindow);
1783 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1784 && WFLAGP(wwin, full_maximize)
1785 && event->xmotion.x_root >= wwin->frame_x
1786 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1788 if (!WFLAGP(wwin, no_titlebar)
1789 && wwin->frame_y <= - wwin->frame->top_width) {
1791 wWindowMove(wwin, wwin->frame_x, 0);
1792 wwin->flags.dragged_while_fmaximized = 0;
1794 } else if (!WFLAGP(wwin, no_resizebar)
1795 && wwin->frame_y + wwin->frame->core->height >=
1796 scr->scr_height + wwin->frame->bottom_width) {
1798 int y = scr->scr_height + wwin->frame->bottom_width;
1800 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1802 wWindowMove(wwin, wwin->frame_x, y);
1803 wwin->flags.dragged_while_fmaximized = 0;
1807 #endif
1811 static void
1812 handleVisibilityNotify(XEvent *event)
1814 WWindow *wwin;
1816 wwin = wWindowFor(event->xvisibility.window);
1817 if (!wwin)
1818 return;
1819 wwin->flags.obscured =
1820 (event->xvisibility.state == VisibilityFullyObscured);