Fixed problems in menu scrolling caused by the patch sent by Swivel.
[wmaker-crm.git] / src / event.c
blobf0aa940e97662540f4f7fee0d73232fe7bf4a18f
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 <nana.h>
35 #include <X11/Xlib.h>
36 #include <X11/Xutil.h>
37 #ifdef SHAPE
38 # include <X11/extensions/shape.h>
39 #endif
40 #ifdef XDND
41 #include "xdnd.h"
42 #endif
44 #ifdef KEEP_XKB_LOCK_STATUS
45 #include <X11/XKBlib.h>
46 #endif /* KEEP_XKB_LOCK_STATUS */
48 #include "WindowMaker.h"
49 #include "window.h"
50 #include "actions.h"
51 #include "client.h"
52 #include "funcs.h"
53 #include "keybind.h"
54 #include "application.h"
55 #include "stacking.h"
56 #include "defaults.h"
57 #include "workspace.h"
58 #include "dock.h"
59 #include "framewin.h"
60 #include "properties.h"
61 #include "balloon.h"
63 #ifdef GNOME_STUFF
64 # include "gnome.h"
65 #endif
66 #ifdef KWM_HINTS
67 # include "kwm.h"
68 #endif
70 /******** Global Variables **********/
71 extern XContext wWinContext;
73 extern Cursor wCursor[WCUR_LAST];
75 extern WShortKey wKeyBindings[WKBD_LAST];
76 extern int wScreenCount;
77 extern Time LastTimestamp;
78 extern Time LastFocusChange;
80 extern WPreferences wPreferences;
82 #define MOD_MASK wPreferences.modifier_mask
84 extern Atom _XA_WM_COLORMAP_NOTIFY;
86 extern Atom _XA_WM_CHANGE_STATE;
87 extern Atom _XA_WM_DELETE_WINDOW;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
90 extern Atom _XA_WINDOWMAKER_COMMAND;
92 #ifdef OFFIX_DND
93 extern Atom _XA_DND_PROTOCOL;
94 #endif
97 #ifdef SHAPE
98 extern Bool wShapeSupported;
99 extern int wShapeEventBase;
100 #endif
102 #ifdef KEEP_XKB_LOCK_STATUS
103 extern int wXkbEventBase;
104 #endif
106 /* special flags */
107 extern char WDelayedActionSet;
110 /************ Local stuff ***********/
113 static void saveTimestamp(XEvent *event);
114 static void handleColormapNotify();
115 static void handleMapNotify(), handleUnmapNotify();
116 static void handleButtonPress(), handleExpose();
117 static void handleDestroyNotify();
118 static void handleConfigureRequest();
119 static void handleMapRequest();
120 static void handlePropertyNotify();
121 static void handleEnterNotify();
122 static void handleLeaveNotify();
123 static void handleExtensions();
124 static void handleClientMessage();
125 static void handleKeyPress();
126 static void handleFocusIn();
127 static void handleMotionNotify();
128 static void handleVisibilityNotify();
131 #ifdef SHAPE
132 static void handleShapeNotify();
133 #endif
135 /* called from the signal handler */
136 void NotifyDeadProcess(pid_t pid, unsigned char status);
138 /* real dead process handler */
139 static void handleDeadProcess(void *foo);
142 typedef struct DeadProcesses {
143 pid_t pid;
144 unsigned char exit_status;
145 } DeadProcesses;
147 /* stack of dead processes */
148 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
149 static int deadProcessPtr=0;
152 typedef struct DeathHandler {
153 WDeathHandler *callback;
154 pid_t pid;
155 void *client_data;
156 } DeathHandler;
158 static WMBag *deathHandlers=NULL;
162 WMagicNumber
163 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
165 DeathHandler *handler;
167 handler = malloc(sizeof(DeathHandler));
168 if (!handler)
169 return 0;
171 handler->pid = pid;
172 handler->callback = callback;
173 handler->client_data = cdata;
175 if (!deathHandlers)
176 deathHandlers = WMCreateBag(8);
178 WMPutInBag(deathHandlers, handler);
180 return handler;
185 void
186 wDeleteDeathHandler(WMagicNumber id)
188 DeathHandler *handler=(DeathHandler*)id;
190 if (!handler || !deathHandlers)
191 return;
193 WMRemoveFromBag(deathHandlers, handler);
195 free(handler);
199 void
200 DispatchEvent(XEvent *event)
202 if (deathHandlers)
203 handleDeadProcess(NULL);
205 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
206 WCHANGE_STATE(WSTATE_EXITING);
207 /* received SIGTERM */
209 * WMHandleEvent() can't be called from anything
210 * executed inside here, or we can get in a infinite
211 * recursive loop.
213 Shutdown(WSExitMode);
215 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
216 WCHANGE_STATE(WSTATE_RESTARTING);
218 Shutdown(WSRestartPreparationMode);
219 /* received SIGHUP */
220 Restart(NULL, True);
223 /* for the case that all that is wanted to be dispatched is
224 * the stuff above */
225 if (!event)
226 return;
228 saveTimestamp(event);
229 switch (event->type) {
230 case MapRequest:
231 handleMapRequest(event);
232 break;
234 case KeyPress:
235 handleKeyPress(event);
236 break;
238 case MotionNotify:
239 handleMotionNotify(event);
240 break;
242 case ConfigureRequest:
243 handleConfigureRequest(event);
244 break;
246 case DestroyNotify:
247 handleDestroyNotify(event);
248 break;
250 case MapNotify:
251 handleMapNotify(event);
252 break;
254 case UnmapNotify:
255 handleUnmapNotify(event);
256 break;
258 case ButtonPress:
259 handleButtonPress(event);
260 break;
262 case Expose:
263 handleExpose(event);
264 break;
266 case PropertyNotify:
267 handlePropertyNotify(event);
268 break;
270 case EnterNotify:
271 handleEnterNotify(event);
272 break;
274 case LeaveNotify:
275 handleLeaveNotify(event);
276 break;
278 case ClientMessage:
279 handleClientMessage(event);
280 break;
282 case ColormapNotify:
283 handleColormapNotify(event);
284 break;
286 case MappingNotify:
287 if (event->xmapping.request == MappingKeyboard
288 || event->xmapping.request == MappingModifier)
289 XRefreshKeyboardMapping(&event->xmapping);
290 break;
292 case FocusIn:
293 handleFocusIn(event);
294 break;
296 case VisibilityNotify:
297 handleVisibilityNotify(event);
298 break;
299 default:
300 handleExtensions(event);
301 break;
307 *----------------------------------------------------------------------
308 * EventLoop-
309 * Processes X and internal events indefinitely.
311 * Returns:
312 * Never returns
314 * Side effects:
315 * The LastTimestamp global variable is updated.
316 *----------------------------------------------------------------------
318 void
319 EventLoop()
321 XEvent event;
323 for(;;) {
324 WMNextEvent(dpy, &event);
325 WMHandleEvent(&event);
331 Bool
332 IsDoubleClick(WScreen *scr, XEvent *event)
334 if ((scr->last_click_time>0) &&
335 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
336 && (event->xbutton.button == scr->last_click_button)
337 && (event->xbutton.window == scr->last_click_window)) {
339 scr->flags.next_click_is_not_double = 1;
340 scr->last_click_time = 0;
341 scr->last_click_window = event->xbutton.window;
343 return True;
345 return False;
349 void
350 NotifyDeadProcess(pid_t pid, unsigned char status)
352 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
353 wwarning("stack overflow: too many dead processes");
354 return;
356 /* stack the process to be handled later,
357 * as this is called from the signal handler */
358 deadProcesses[deadProcessPtr].pid = pid;
359 deadProcesses[deadProcessPtr].exit_status = status;
360 deadProcessPtr++;
364 static void
365 handleDeadProcess(void *foo)
367 DeathHandler *tmp;
368 int i;
370 for (i=0; i<deadProcessPtr; i++) {
371 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
374 if (!deathHandlers) {
375 deadProcessPtr=0;
376 return;
379 /* get the pids on the queue and call handlers */
380 while (deadProcessPtr>0) {
381 deadProcessPtr--;
383 for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) {
384 tmp = WMGetFromBag(deathHandlers, i);
385 if (!tmp)
386 continue;
388 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
389 (*tmp->callback)(tmp->pid,
390 deadProcesses[deadProcessPtr].exit_status,
391 tmp->client_data);
392 wDeleteDeathHandler(tmp);
399 static void
400 saveTimestamp(XEvent *event)
402 LastTimestamp = CurrentTime;
404 switch (event->type) {
405 case ButtonRelease:
406 case ButtonPress:
407 LastTimestamp = event->xbutton.time;
408 break;
409 case KeyPress:
410 case KeyRelease:
411 LastTimestamp = event->xkey.time;
412 break;
413 case MotionNotify:
414 LastTimestamp = event->xmotion.time;
415 break;
416 case PropertyNotify:
417 LastTimestamp = event->xproperty.time;
418 break;
419 case EnterNotify:
420 case LeaveNotify:
421 LastTimestamp = event->xcrossing.time;
422 break;
423 case SelectionClear:
424 LastTimestamp = event->xselectionclear.time;
425 break;
426 case SelectionRequest:
427 LastTimestamp = event->xselectionrequest.time;
428 break;
429 case SelectionNotify:
430 LastTimestamp = event->xselection.time;
431 #ifdef XDND
432 wXDNDProcessSelection(event);
433 #endif
434 break;
439 static void
440 handleExtensions(XEvent *event)
442 #ifdef KEEP_XKB_LOCK_STATUS
443 XkbEvent *xkbevent;
444 xkbevent = (XkbEvent *)event;
445 #endif /*KEEP_XKB_LOCK_STATUS*/
446 #ifdef SHAPE
447 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
448 handleShapeNotify(event);
450 #endif
451 #ifdef KEEP_XKB_LOCK_STATUS
452 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
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 L("got map request for %x\n", (unsigned)window);
468 #endif
469 if ((wwin = wWindowFor(window))) {
470 if (wwin->flags.shaded) {
471 wUnshadeWindow(wwin);
473 /* deiconify window */
474 if (wwin->flags.miniaturized) {
475 wDeiconifyWindow(wwin);
476 } else if (wwin->flags.hidden) {
477 WApplication *wapp = wApplicationOf(wwin->main_window);
478 /* go to the last workspace that the user worked on the app */
479 #ifndef REDUCE_APPICONS
480 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
481 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
483 if (wapp) {
484 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
486 #endif
487 wUnhideApplication(wapp, False, False);
489 return;
492 scr = wScreenForRootWindow(ev->xmaprequest.parent);
494 wwin = wManageWindow(scr, window);
497 * This is to let the Dock know that the application it launched
498 * has already been mapped (eg: it has finished launching).
499 * It is not necessary for normally docked apps, but is needed for
500 * apps that were forcedly docked (like with dockit).
502 if (scr->last_dock) {
503 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
504 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
505 else
506 wDockTrackWindowLaunch(scr->last_dock, window);
509 if (wwin) {
510 wClientSetState(wwin, NormalState, None);
511 if (wwin->flags.maximized) {
512 wMaximizeWindow(wwin, wwin->flags.maximized);
514 if (wwin->flags.shaded) {
515 wwin->flags.shaded = 0;
516 wwin->flags.skip_next_animation = 1;
517 wShadeWindow(wwin);
519 if (wwin->flags.miniaturized) {
520 wwin->flags.miniaturized = 0;
521 wwin->flags.skip_next_animation = 1;
522 wIconifyWindow(wwin);
524 if (wwin->flags.hidden) {
525 WApplication *wapp = wApplicationOf(wwin->main_window);
527 wwin->flags.hidden = 0;
528 wwin->flags.skip_next_animation = 1;
529 if (wapp) {
530 wHideApplication(wapp);
537 static void
538 handleDestroyNotify(XEvent *event)
540 WWindow *wwin;
541 WApplication *app;
542 Window window = event->xdestroywindow.window;
544 #ifdef DEBUG
545 L("got destroy notify");
546 #endif
547 wwin = wWindowFor(window);
548 if (wwin) {
549 wUnmanageWindow(wwin, False, True);
552 app = wApplicationOf(window);
553 if (app) {
554 if (window == app->main_window) {
555 app->refcount = 0;
556 wwin = app->main_window_desc->screen_ptr->focused_window;
557 while (wwin) {
558 if (wwin->main_window == window) {
559 wwin->main_window = None;
561 wwin = wwin->prev;
564 wApplicationDestroy(app);
567 #ifdef KWM_HINTS
568 wKWMCheckDestroy(&event->xdestroywindow);
569 #endif
574 static void
575 handleExpose(XEvent *event)
577 WObjDescriptor *desc;
578 XEvent ev;
580 #ifdef DEBUG
581 L("got expose");
582 #endif
583 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
585 if (XFindContext(dpy, event->xexpose.window, wWinContext,
586 (XPointer *)&desc)==XCNOENT) {
587 return;
590 if (desc->handle_expose) {
591 (*desc->handle_expose)(desc, event);
596 /* bindable */
597 static void
598 handleButtonPress(XEvent *event)
600 WObjDescriptor *desc;
601 WScreen *scr;
602 #ifdef DEBUG
603 L("got button press");
604 #endif
605 scr = wScreenForRootWindow(event->xbutton.root);
607 #ifdef BALLOON_TEXT
608 wBalloonHide(scr);
609 #endif
612 #ifndef LITE
613 if (event->xbutton.window==scr->root_win) {
615 if (event->xbutton.button==wPreferences.menu_button) {
616 OpenRootMenu(scr, event->xbutton.x_root,
617 event->xbutton.y_root, False);
618 /* ugly hack */
619 if (scr->root_menu) {
620 if (scr->root_menu->brother->flags.mapped)
621 event->xbutton.window = scr->root_menu->brother->frame->core->window;
622 else
623 event->xbutton.window = scr->root_menu->frame->core->window;
625 } else if (event->xbutton.button==wPreferences.windowl_button) {
626 OpenSwitchMenu(scr, event->xbutton.x_root,
627 event->xbutton.y_root, False);
628 if (scr->switch_menu) {
629 if (scr->switch_menu->brother->flags.mapped)
630 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
631 else
632 event->xbutton.window = scr->switch_menu->frame->core->window;
634 } else if (event->xbutton.button==wPreferences.select_button) {
635 wUnselectWindows(scr);
636 wSelectWindows(scr, event);
638 #ifdef MOUSE_WS_SWITCH
639 else if (event->xbutton.button==Button5) {
641 wWorkspaceRelativeChange(scr, -1);
643 } else if (event->xbutton.button==Button4) {
645 wWorkspaceRelativeChange(scr, 1);
648 #endif /* MOUSE_WS_SWITCH */
649 #ifdef GNOME_STUFF
650 else if (wGNOMEProxyizeButtonEvent(scr, event))
651 return;
652 #endif
654 #endif /* !LITE */
656 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
657 (XPointer *)&desc)==XCNOENT) {
658 if (XFindContext(dpy, event->xbutton.window, wWinContext,
659 (XPointer *)&desc)==XCNOENT) {
660 return;
664 if (desc->handle_mousedown!=NULL) {
665 (*desc->handle_mousedown)(desc, event);
668 if (desc->parent_type == WCLASS_WINDOW) {
669 XSync(dpy, 0);
671 if (event->xbutton.state & MOD_MASK) {
672 XAllowEvents(dpy, AsyncPointer, CurrentTime);
675 if (wPreferences.focus_mode == WKF_CLICK) {
676 if (wPreferences.ignore_focus_click) {
677 XAllowEvents(dpy, AsyncPointer, CurrentTime);
679 XAllowEvents(dpy, ReplayPointer, CurrentTime);
681 XSync(dpy, 0);
682 } else if (desc->parent_type == WCLASS_APPICON
683 || desc->parent_type == WCLASS_MINIWINDOW
684 || desc->parent_type == WCLASS_DOCK_ICON) {
685 if (event->xbutton.state & MOD_MASK) {
686 XSync(dpy, 0);
687 XAllowEvents(dpy, AsyncPointer, CurrentTime);
688 XSync(dpy, 0);
692 /* save double-click information */
693 if (scr->flags.next_click_is_not_double) {
694 scr->flags.next_click_is_not_double = 0;
695 } else {
696 scr->last_click_time = event->xbutton.time;
697 scr->last_click_button = event->xbutton.button;
698 scr->last_click_window = event->xbutton.window;
703 static void
704 handleMapNotify(XEvent *event)
706 WWindow *wwin;
707 #ifdef DEBUG
708 L("got map");
709 #endif
710 wwin = wWindowFor(event->xmap.event);
711 if (wwin && wwin->client_win == event->xmap.event) {
712 if (wwin->flags.miniaturized) {
713 wDeiconifyWindow(wwin);
714 } else {
715 XGrabServer(dpy);
716 wWindowMap(wwin);
717 wClientSetState(wwin, NormalState, None);
718 XUngrabServer(dpy);
724 static void
725 handleUnmapNotify(XEvent *event)
727 WWindow *wwin;
728 XEvent ev;
729 Bool withdraw = False;
730 #ifdef DEBUG
731 L("got unmap");
732 #endif
733 /* only process windows with StructureNotify selected
734 * (ignore SubstructureNotify) */
735 wwin = wWindowFor(event->xunmap.window);
736 if (!wwin)
737 return;
739 /* whether the event is a Withdrawal request */
740 if (event->xunmap.event == wwin->screen_ptr->root_win
741 && event->xunmap.send_event)
742 withdraw = True;
744 if (wwin->client_win != event->xunmap.event && !withdraw)
745 return;
747 if (!wwin->flags.mapped && !withdraw
748 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
749 && !wwin->flags.miniaturized && !wwin->flags.hidden)
750 return;
752 XGrabServer(dpy);
753 XUnmapWindow(dpy, wwin->frame->core->window);
754 wwin->flags.mapped = 0;
755 XSync(dpy, 0);
756 /* check if the window was destroyed */
757 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
758 DispatchEvent(&ev);
759 } else {
760 Bool reparented = False;
762 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
763 reparented = True;
765 /* withdraw window */
766 wwin->flags.mapped = 0;
767 if (!reparented)
768 wClientSetState(wwin, WithdrawnState, None);
770 /* if the window was reparented, do not reparent it back to the
771 * root window */
772 wUnmanageWindow(wwin, !reparented, False);
774 XUngrabServer(dpy);
778 static void
779 handleConfigureRequest(XEvent *event)
781 WWindow *wwin;
782 #ifdef DEBUG
783 L("got configure request");
784 #endif
785 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
787 * Configure request for unmapped window
789 wClientConfigure(NULL, &(event->xconfigurerequest));
790 } else {
791 wClientConfigure(wwin, &(event->xconfigurerequest));
796 static void
797 handlePropertyNotify(XEvent *event)
799 WWindow *wwin;
800 WApplication *wapp;
801 Window jr;
802 int ji;
803 unsigned int ju;
804 WScreen *scr;
805 #ifdef DEBUG
806 L("got property notify");
807 #endif
808 if ((wwin=wWindowFor(event->xproperty.window))) {
809 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
810 &ju, &ju, &ju, &ju)) {
811 return;
813 wClientCheckProperty(wwin, &event->xproperty);
815 wapp = wApplicationOf(event->xproperty.window);
816 if (wapp) {
817 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
820 scr = wScreenForWindow(event->xproperty.window);
821 if (scr && scr->root_win == event->xproperty.window) {
822 #ifdef KWM_HINTS
823 wKWMCheckRootHintChange(scr, &event->xproperty);
824 #endif
829 static void
830 handleClientMessage(XEvent *event)
832 WWindow *wwin;
833 WObjDescriptor *desc;
834 #ifdef DEBUG
835 L("got client message");
836 #endif
837 /* handle transition from Normal to Iconic state */
838 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
839 && event->xclient.format == 32
840 && event->xclient.data.l[0] == IconicState) {
842 wwin = wWindowFor(event->xclient.window);
843 if (!wwin) return;
844 if (!wwin->flags.miniaturized)
845 wIconifyWindow(wwin);
846 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
847 && event->xclient.format == 32) {
848 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
850 if (!scr)
851 return;
853 if (event->xclient.data.l[1] == 1) { /* starting */
854 wColormapAllowClientInstallation(scr, True);
855 } else { /* stopping */
856 wColormapAllowClientInstallation(scr, False);
858 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
860 wDefaultsCheckDomains("bla");
862 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
863 WApplication *wapp;
864 int done=0;
865 wapp = wApplicationOf(event->xclient.window);
866 if (wapp) {
867 switch (event->xclient.data.l[0]) {
868 case WMFHideOtherApplications:
869 wHideOtherApplications(wapp->main_window_desc);
870 done = 1;
871 break;
873 case WMFHideApplication:
874 wHideApplication(wapp);
875 done = 1;
876 break;
879 if (!done) {
880 wwin = wWindowFor(event->xclient.window);
881 if (wwin) {
882 switch (event->xclient.data.l[0]) {
883 case WMFHideOtherApplications:
884 wHideOtherApplications(wwin);
885 break;
887 case WMFHideApplication:
888 wHideApplication(wApplicationOf(wwin->main_window));
889 break;
893 #ifdef GNOME_STUFF
894 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
895 /* do nothing */
896 #endif /* GNOME_STUFF */
897 #ifdef KWM_HINTS
898 } else if (wKWMProcessClientMessage(&event->xclient)) {
899 /* do nothing */
900 #endif /* KWM_HINTS */
901 #ifdef XDND
902 } else if (wXDNDProcessClientMessage(&event->xclient)) {
903 /* do nothing */
904 #endif /* XDND */
905 #ifdef OFFIX_DND
906 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
907 WScreen *scr = wScreenForWindow(event->xclient.window);
908 if (scr && wDockReceiveDNDDrop(scr,event))
909 goto redirect_message;
910 #endif /* OFFIX_DND */
911 } else {
912 #ifdef OFFIX_DND
913 redirect_message:
914 #endif
916 * Non-standard thing, but needed by OffiX DND.
917 * For when the icon frame gets a ClientMessage
918 * that should have gone to the icon_window.
920 if (XFindContext(dpy, event->xbutton.window, wWinContext,
921 (XPointer *)&desc)!=XCNOENT) {
922 struct WIcon *icon=NULL;
924 if (desc->parent_type == WCLASS_MINIWINDOW) {
925 icon = (WIcon*)desc->parent;
926 } else if (desc->parent_type == WCLASS_DOCK_ICON
927 || desc->parent_type == WCLASS_APPICON) {
928 icon = ((WAppIcon*)desc->parent)->icon;
930 if (icon && (wwin=icon->owner)) {
931 if (wwin->client_win!=event->xclient.window) {
932 event->xclient.window = wwin->client_win;
933 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
934 event);
942 static void
943 raiseWindow(WScreen *scr)
945 WWindow *wwin;
947 scr->autoRaiseTimer = NULL;
949 wwin = wWindowFor(scr->autoRaiseWindow);
950 if (!wwin)
951 return;
953 if (!wwin->flags.destroyed && wwin->flags.focused) {
954 wRaiseFrame(wwin->frame->core);
955 /* this is needed or a race condition will occur */
956 XSync(dpy, False);
961 static void
962 handleEnterNotify(XEvent *event)
964 WMenu *menu;
965 WWindow *wwin;
966 WObjDescriptor *desc = NULL;
967 XEvent ev;
968 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
969 #ifdef DEBUG
970 L("got enter notify");
971 #endif
972 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
973 &ev)) {
974 /* already left the window... */
975 saveTimestamp(&ev);
976 if (ev.xcrossing.mode==event->xcrossing.mode
977 && ev.xcrossing.detail==event->xcrossing.detail) {
978 return;
982 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
983 (XPointer *)&desc)!=XCNOENT) {
984 if(desc->handle_enternotify)
985 (*desc->handle_enternotify)(desc, event);
988 /* enter to window */
989 wwin = wWindowFor(event->xcrossing.window);
990 if (!wwin) {
991 if (wPreferences.focus_mode==WKF_POINTER
992 && event->xcrossing.window==event->xcrossing.root) {
993 wSetFocusTo(scr, NULL);
995 if (wPreferences.colormap_mode==WKF_POINTER) {
996 wColormapInstallForWindow(scr, NULL);
998 if (scr->autoRaiseTimer
999 && event->xcrossing.root==event->xcrossing.window) {
1000 WMDeleteTimerHandler(scr->autoRaiseTimer);
1001 scr->autoRaiseTimer = NULL;
1003 } else {
1004 /* set auto raise timer even if in focus-follows-mouse mode
1005 * and the event is for the frame window, even if the window
1006 * has focus already. useful if you move the pointer from a focused
1007 * window to the root window and back pretty fast
1009 * set focus if in focus-follows-mouse mode and the event
1010 * is for the frame window and window doesn't have focus yet */
1011 if ((wPreferences.focus_mode==WKF_POINTER
1012 || wPreferences.focus_mode==WKF_SLOPPY)
1013 && wwin->frame->core->window==event->xcrossing.window
1014 && !scr->flags.doing_alt_tab) {
1016 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1017 wSetFocusTo(scr, wwin);
1019 if (scr->autoRaiseTimer)
1020 WMDeleteTimerHandler(scr->autoRaiseTimer);
1021 scr->autoRaiseTimer = NULL;
1023 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1024 scr->autoRaiseWindow = wwin->frame->core->window;
1025 scr->autoRaiseTimer
1026 = WMAddTimerHandler(wPreferences.raise_delay,
1027 (WMCallback*)raiseWindow, scr);
1030 /* Install colormap for window, if the colormap installation mode
1031 * is colormap_follows_mouse */
1032 if (wPreferences.colormap_mode==WKF_POINTER) {
1033 if (wwin->client_win==event->xcrossing.window)
1034 wColormapInstallForWindow(scr, wwin);
1035 else
1036 wColormapInstallForWindow(scr, NULL);
1040 /* a little kluge to hide the clip balloon */
1041 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1042 if (!desc) {
1043 XUnmapWindow(dpy, scr->clip_balloon);
1044 scr->flags.clip_balloon_mapped = 0;
1045 } else {
1046 if (desc->parent_type!=WCLASS_DOCK_ICON
1047 || scr->clip_icon != desc->parent) {
1048 XUnmapWindow(dpy, scr->clip_balloon);
1049 scr->flags.clip_balloon_mapped = 0;
1054 if (event->xcrossing.window == event->xcrossing.root
1055 && event->xcrossing.detail == NotifyNormal
1056 && event->xcrossing.detail != NotifyInferior
1057 && wPreferences.focus_mode != WKF_CLICK) {
1059 wSetFocusTo(scr, scr->focused_window);
1062 #ifdef BALLOON_TEXT
1063 wBalloonEnteredObject(scr, desc);
1064 #endif
1068 static void
1069 handleLeaveNotify(XEvent *event)
1071 WObjDescriptor *desc = NULL;
1073 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1074 (XPointer *)&desc)!=XCNOENT) {
1075 if(desc->handle_leavenotify)
1076 (*desc->handle_leavenotify)(desc, event);
1078 if (event->xcrossing.window == event->xcrossing.root
1079 && event->xcrossing.mode == NotifyNormal
1080 && event->xcrossing.detail != NotifyInferior
1081 && wPreferences.focus_mode != WKF_CLICK) {
1083 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1085 wSetFocusTo(scr, NULL);
1090 #ifdef SHAPE
1091 static void
1092 handleShapeNotify(XEvent *event)
1094 XShapeEvent *shev = (XShapeEvent*)event;
1095 WWindow *wwin;
1096 XEvent ev;
1097 #ifdef DEBUG
1098 L("got shape notify");
1099 #endif
1100 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1101 XShapeEvent *sev = (XShapeEvent*)&ev;
1103 if (sev->kind == ShapeBounding) {
1104 if (sev->shaped == shev->shaped) {
1105 *shev = *sev;
1106 } else {
1107 XPutBackEvent(dpy, &ev);
1108 break;
1113 wwin = wWindowFor(shev->window);
1114 if (!wwin || shev->kind != ShapeBounding)
1115 return;
1117 if (!shev->shaped && wwin->flags.shaped) {
1119 wwin->flags.shaped = 0;
1120 wWindowClearShape(wwin);
1122 } else if (shev->shaped) {
1124 wwin->flags.shaped = 1;
1125 wWindowSetShape(wwin);
1128 #endif /* SHAPE */
1130 #ifdef KEEP_XKB_LOCK_STATUS
1131 /* please help ]d if you know what to do */
1132 handleXkbIndicatorStateNotify(XEvent *event)
1134 WWindow *wwin;
1135 WScreen *scr;
1136 XkbStateRec staterec;
1137 int i;
1139 for (i=0; i<wScreenCount; i++) {
1140 scr = wScreenWithNumber(i);
1141 wwin = scr->focused_window;
1142 if (wwin && wwin->flags.focused) {
1143 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1144 if (wwin->frame->languagemode != staterec.group) {
1145 wwin->frame->last_languagemode = wwin->frame->languagemode;
1146 wwin->frame->languagemode = staterec.group;
1148 #ifdef XKB_BUTTON_HINT
1149 if (wwin->frame->titlebar) {
1150 wFrameWindowPaint(wwin->frame);
1152 #endif
1156 #endif /*KEEP_XKB_LOCK_STATUS*/
1158 static void
1159 handleColormapNotify(XEvent *event)
1161 WWindow *wwin;
1162 WScreen *scr;
1163 Bool reinstall = False;
1165 wwin = wWindowFor(event->xcolormap.window);
1166 if (!wwin)
1167 return;
1169 scr = wwin->screen_ptr;
1171 do {
1172 if (wwin) {
1173 if (event->xcolormap.new) {
1174 XWindowAttributes attr;
1176 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1178 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1179 scr->current_colormap = attr.colormap;
1181 reinstall = True;
1182 } else if (event->xcolormap.state == ColormapUninstalled &&
1183 scr->current_colormap == event->xcolormap.colormap) {
1185 /* some bastard app (like XV) removed our colormap */
1187 * can't enforce or things like xscreensaver wont work
1188 * reinstall = True;
1190 } else if (event->xcolormap.state == ColormapInstalled &&
1191 scr->current_colormap == event->xcolormap.colormap) {
1193 /* someone has put our colormap back */
1194 reinstall = False;
1197 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1198 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1200 if (reinstall && scr->current_colormap!=None) {
1201 if (!scr->flags.colormap_stuff_blocked)
1202 XInstallColormap(dpy, scr->current_colormap);
1208 static void
1209 handleFocusIn(XEvent *event)
1211 WWindow *wwin;
1214 * For applications that like stealing the focus.
1216 while (XCheckTypedEvent(dpy, FocusIn, event));
1217 saveTimestamp(event);
1218 if (event->xfocus.mode == NotifyUngrab
1219 || event->xfocus.mode == NotifyGrab
1220 || event->xfocus.detail > NotifyNonlinearVirtual) {
1221 return;
1224 wwin = wWindowFor(event->xfocus.window);
1225 if (wwin && !wwin->flags.focused) {
1226 if (wwin->flags.mapped)
1227 wSetFocusTo(wwin->screen_ptr, wwin);
1228 else
1229 wSetFocusTo(wwin->screen_ptr, NULL);
1230 } else if (!wwin) {
1231 WScreen *scr = wScreenForWindow(event->xfocus.window);
1232 if (scr)
1233 wSetFocusTo(scr, NULL);
1238 static WWindow*
1239 windowUnderPointer(WScreen *scr)
1241 unsigned int mask;
1242 int foo;
1243 Window bar, win;
1245 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1246 &mask))
1247 return wWindowFor(win);
1248 return NULL;
1252 #ifdef WEENDOZE_CYCLE
1254 static WWindow*
1255 nextToFocusAfter(WWindow *wwin)
1257 WWindow *tmp = wwin->prev;
1259 while (tmp) {
1260 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1262 return tmp;
1264 tmp = tmp->prev;
1267 tmp = wwin;
1268 /* start over from the beginning of the list */
1269 while (tmp->next)
1270 tmp = tmp->next;
1272 while (tmp && tmp != wwin) {
1273 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1275 return tmp;
1277 tmp = tmp->prev;
1280 return wwin;
1284 static WWindow*
1285 nextToFocusBefore(WWindow *wwin)
1287 WWindow *tmp = wwin->next;
1289 while (tmp) {
1290 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1292 return tmp;
1294 tmp = tmp->next;
1297 /* start over from the beginning of the list */
1298 tmp = wwin;
1299 while (tmp->prev)
1300 tmp = tmp->prev;
1302 while (tmp && tmp != wwin) {
1303 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1305 return tmp;
1307 tmp = tmp->next;
1310 return wwin;
1315 static void
1316 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1318 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1319 Bool done = False;
1320 Bool openedSwitchMenu = False;
1321 WWindow *newFocused;
1322 WWindow *oldFocused;
1323 int modifiers;
1324 XModifierKeymap *keymap;
1326 if (!wwin)
1327 return;
1329 keymap = XGetModifierMapping(dpy);
1332 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1333 CurrentTime);
1335 if (next) {
1336 newFocused = nextToFocusAfter(wwin);
1337 } else {
1338 newFocused = nextToFocusBefore(wwin);
1341 scr->flags.doing_alt_tab = 1;
1343 wWindowFocus(newFocused, scr->focused_window);
1344 oldFocused = newFocused;
1345 if (wPreferences.circ_raise)
1346 wRaiseFrame(newFocused->frame->core);
1348 if (wPreferences.popup_switchmenu &&
1349 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1351 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1352 openedSwitchMenu = True;
1355 while (!done) {
1356 XEvent ev;
1358 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1359 /* WMNextEvent(dpy, &ev);*/
1360 if (ev.type != KeyRelease && ev.type != KeyPress) {
1361 WMHandleEvent(&ev);
1362 continue;
1364 /* ignore CapsLock */
1365 modifiers = ev.xkey.state & ValidModMask;
1367 if (ev.type == KeyPress
1368 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1369 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1371 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1372 newFocused = nextToFocusAfter(newFocused);
1373 wWindowFocus(newFocused, oldFocused);
1374 oldFocused = newFocused;
1375 if (wPreferences.circ_raise)
1376 wRaiseFrame(newFocused->frame->core);
1377 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1379 } else if (ev.type == KeyPress
1380 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1381 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1383 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1384 newFocused = nextToFocusBefore(newFocused);
1385 wWindowFocus(newFocused, oldFocused);
1386 oldFocused = newFocused;
1387 if (wPreferences.circ_raise)
1388 wRaiseFrame(newFocused->frame->core);
1389 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1391 if (ev.type == KeyRelease) {
1392 int i;
1394 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1395 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1396 wKeyBindings[WKBD_FOCUSNEXT].modifier
1397 & 1<<(i/keymap->max_keypermod)) {
1398 done = True;
1399 break;
1404 XFree(keymap);
1406 XUngrabKeyboard(dpy, CurrentTime);
1407 wSetFocusTo(scr, newFocused);
1408 scr->flags.doing_alt_tab = 0;
1409 if (openedSwitchMenu)
1410 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1414 #endif /* WEENDOZE_CYCLE */
1419 static void
1420 handleKeyPress(XEvent *event)
1422 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1423 WWindow *wwin = scr->focused_window;
1424 int i;
1425 int modifiers;
1426 int command=-1, index;
1427 #ifdef KEEP_XKB_LOCK_STATUS
1428 XkbStateRec staterec;
1429 #endif /*KEEP_XKB_LOCK_STATUS*/
1431 /* ignore CapsLock */
1432 modifiers = event->xkey.state & ValidModMask;
1434 for (i=0; i<WKBD_LAST; i++) {
1435 if (wKeyBindings[i].keycode==0)
1436 continue;
1438 if (wKeyBindings[i].keycode==event->xkey.keycode
1439 && (/*wKeyBindings[i].modifier==0
1440 ||*/ wKeyBindings[i].modifier==modifiers)) {
1441 command = i;
1442 break;
1446 if (command < 0) {
1447 #ifdef LITE
1449 #if 0
1451 #endif
1452 #else
1453 if (!wRootMenuPerformShortcut(event)) {
1454 #endif
1455 static int dontLoop = 0;
1457 if (dontLoop > 10) {
1458 wwarning("problem with key event processing code");
1459 return;
1461 dontLoop++;
1462 /* if the focused window is an internal window, try redispatching
1463 * the event to the managed window, as it can be a WINGs window */
1464 if (wwin && wwin->flags.internal_window
1465 && wwin->client_leader!=None) {
1466 /* client_leader contains the WINGs toplevel */
1467 event->xany.window = wwin->client_leader;
1468 WMHandleEvent(event);
1470 dontLoop--;
1472 return;
1475 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1476 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1478 switch (command) {
1479 #ifndef LITE
1480 case WKBD_ROOTMENU:
1481 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1482 break;
1483 case WKBD_WINDOWLIST:
1484 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1485 break;
1486 #endif /* !LITE */
1487 case WKBD_WINDOWMENU:
1488 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1489 OpenWindowMenu(wwin, wwin->frame_x,
1490 wwin->frame_y+wwin->frame->top_width, True);
1491 break;
1492 case WKBD_MINIATURIZE:
1493 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1494 && !WFLAGP(wwin, no_miniaturizable)) {
1495 CloseWindowMenu(scr);
1497 if (wwin->protocols.MINIATURIZE_WINDOW)
1498 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1499 event->xbutton.time);
1500 else {
1501 wIconifyWindow(wwin);
1504 break;
1505 case WKBD_HIDE:
1506 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1507 WApplication *wapp = wApplicationOf(wwin->main_window);
1508 CloseWindowMenu(scr);
1510 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1511 wHideApplication(wapp);
1514 break;
1515 case WKBD_MAXIMIZE:
1516 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1517 CloseWindowMenu(scr);
1519 if (wwin->flags.maximized) {
1520 wUnmaximizeWindow(wwin);
1521 } else {
1522 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1525 break;
1526 case WKBD_VMAXIMIZE:
1527 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1528 CloseWindowMenu(scr);
1530 if (wwin->flags.maximized) {
1531 wUnmaximizeWindow(wwin);
1532 } else {
1533 wMaximizeWindow(wwin, MAX_VERTICAL);
1536 break;
1537 case WKBD_RAISE:
1538 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1539 CloseWindowMenu(scr);
1541 wRaiseFrame(wwin->frame->core);
1543 break;
1544 case WKBD_LOWER:
1545 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1546 CloseWindowMenu(scr);
1548 wLowerFrame(wwin->frame->core);
1550 break;
1551 case WKBD_RAISELOWER:
1552 /* raise or lower the window under the pointer, not the
1553 * focused one
1555 wwin = windowUnderPointer(scr);
1556 if (wwin)
1557 wRaiseLowerFrame(wwin->frame->core);
1558 break;
1559 case WKBD_SHADE:
1560 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1561 if (wwin->flags.shaded)
1562 wUnshadeWindow(wwin);
1563 else
1564 wShadeWindow(wwin);
1566 break;
1567 case WKBD_MOVERESIZE:
1568 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1569 CloseWindowMenu(scr);
1571 wKeyboardMoveResizeWindow(wwin);
1573 break;
1574 case WKBD_CLOSE:
1575 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1576 CloseWindowMenu(scr);
1577 if (wwin->protocols.DELETE_WINDOW)
1578 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1579 event->xkey.time);
1581 break;
1582 case WKBD_SELECT:
1583 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1584 wSelectWindow(wwin, !wwin->flags.selected);
1586 break;
1587 case WKBD_FOCUSNEXT:
1588 #ifdef WEENDOZE_CYCLE
1589 if (wPreferences.windoze_cycling) {
1590 doWindozeCycle(wwin, event, True);
1591 } else
1592 #endif /* WEENDOZE_CYCLE */
1594 wwin = NextFocusWindow(scr);
1595 if (wwin != NULL) {
1596 wSetFocusTo(scr, wwin);
1597 if (wPreferences.circ_raise)
1598 wRaiseFrame(wwin->frame->core);
1601 break;
1603 case WKBD_FOCUSPREV:
1604 #ifdef WEENDOZE_CYCLE
1605 if (wPreferences.windoze_cycling) {
1606 doWindozeCycle(wwin, event, False);
1607 } else
1608 #endif /* WEENDOZE_CYCLE */
1610 wwin = PrevFocusWindow(scr);
1611 if (wwin != NULL) {
1612 wSetFocusTo(scr, wwin);
1613 if (wPreferences.circ_raise)
1614 wRaiseFrame(wwin->frame->core);
1617 break;
1619 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1620 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1621 i = (scr->current_workspace/10)*10 + wk - 1;\
1622 if (wPreferences.ws_advance || i<scr->workspace_count)\
1623 wWorkspaceChange(scr, i);\
1624 break
1625 #else
1626 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1627 i = (scr->current_workspace/10)*10 + wk - 1;\
1628 if (wPreferences.ws_advance || i<scr->workspace_count)\
1629 wWorkspaceChange(scr, i);\
1630 break
1631 #endif
1632 GOTOWORKS(1);
1633 GOTOWORKS(2);
1634 GOTOWORKS(3);
1635 GOTOWORKS(4);
1636 GOTOWORKS(5);
1637 GOTOWORKS(6);
1638 GOTOWORKS(7);
1639 GOTOWORKS(8);
1640 GOTOWORKS(9);
1641 GOTOWORKS(10);
1642 #undef GOTOWORKS
1643 case WKBD_NEXTWORKSPACE:
1644 wWorkspaceRelativeChange(scr, 1);
1645 break;
1646 case WKBD_PREVWORKSPACE:
1647 wWorkspaceRelativeChange(scr, -1);
1648 break;
1649 case WKBD_WINDOW1:
1650 case WKBD_WINDOW2:
1651 case WKBD_WINDOW3:
1652 case WKBD_WINDOW4:
1653 #ifdef EXTEND_WINDOWSHORTCUT
1654 case WKBD_WINDOW5:
1655 case WKBD_WINDOW6:
1656 case WKBD_WINDOW7:
1657 case WKBD_WINDOW8:
1658 case WKBD_WINDOW9:
1659 case WKBD_WINDOW10:
1660 #endif
1662 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1664 index = command-WKBD_WINDOW1;
1666 if (scr->shortcutWindows[index]) {
1667 WMBag *list = scr->shortcutWindows[index];
1668 int cw;
1669 int i;
1670 int count = WMGetBagItemCount(list);
1671 WWindow *twin;
1673 wUnselectWindows(scr);
1674 cw = scr->current_workspace;
1676 for (i = count-1; i >= 0; i--) {
1677 WWindow *wwin = WMGetFromBag(list, i);
1679 if (count > 1)
1680 wWindowChangeWorkspace(wwin, cw);
1682 wMakeWindowVisible(wwin);
1684 if (count > 1)
1685 wSelectWindow(wwin, True);
1688 /* rotate the order of windows, to create a cycling effect */
1689 twin = WMGetFromBag(list, 0);
1690 WMDeleteFromBag(list, 0);
1691 WMPutInBag(list, twin);
1693 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1695 INITBAG(scr->shortcutWindows[index]);
1696 WMPutInBag(scr->shortcutWindows[index], wwin);
1698 if (wwin->flags.selected && scr->selected_windows) {
1699 WMBag *selwins = scr->selected_windows;
1700 int i;
1702 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1703 WWindow *tmp = WMGetFromBag(selwins, i);
1705 if (tmp != wwin)
1706 WMPutInBag(scr->shortcutWindows[index], tmp);
1709 wSelectWindow(wwin, !wwin->flags.selected);
1710 XFlush(dpy);
1711 wusleep(3000);
1712 wSelectWindow(wwin, !wwin->flags.selected);
1713 XFlush(dpy);
1715 } else if (WMGetBagItemCount(scr->selected_windows)) {
1717 if (wwin->flags.selected && scr->selected_windows) {
1718 WMBag *selwins = scr->selected_windows;
1719 int i;
1721 INITBAG(scr->shortcutWindows[index]);
1723 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1724 WWindow *tmp = WMGetFromBag(selwins, i);
1726 WMPutInBag(scr->shortcutWindows[index], tmp);
1730 #undef INITBAG
1732 break;
1733 case WKBD_NEXTWSLAYER:
1734 case WKBD_PREVWSLAYER:
1736 int row, column;
1738 row = scr->current_workspace/10;
1739 column = scr->current_workspace%10;
1741 if (command==WKBD_NEXTWSLAYER) {
1742 if ((row+1)*10 < scr->workspace_count)
1743 wWorkspaceChange(scr, column+(row+1)*10);
1744 } else {
1745 if (row > 0)
1746 wWorkspaceChange(scr, column+(row-1)*10);
1749 break;
1750 case WKBD_CLIPLOWER:
1751 if (!wPreferences.flags.noclip)
1752 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1753 break;
1754 case WKBD_CLIPRAISE:
1755 if (!wPreferences.flags.noclip)
1756 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1757 break;
1758 case WKBD_CLIPRAISELOWER:
1759 if (!wPreferences.flags.noclip)
1760 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1761 break;
1762 #ifdef KEEP_XKB_LOCK_STATUS
1763 case WKBD_TOGGLE:
1764 if(wPreferences.modelock) {
1765 /*toggle*/
1766 wwin = scr->focused_window;
1768 if (wwin && wwin->flags.mapped
1769 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1770 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1771 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1773 wwin->frame->languagemode = wwin->frame->last_languagemode;
1774 wwin->frame->last_languagemode = staterec.group;
1775 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1779 break;
1780 #endif /* KEEP_XKB_LOCK_STATUS */
1786 static void
1787 handleMotionNotify(XEvent *event)
1789 WMenu *menu;
1790 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1792 if (wPreferences.scrollable_menus) {
1793 if (scr->flags.jump_back_pending ||
1794 event->xmotion.x_root <= 1 ||
1795 event->xmotion.x_root >= (scr->scr_width - 2) ||
1796 event->xmotion.y_root <= 1 ||
1797 event->xmotion.y_root >= (scr->scr_height - 2)) {
1798 #ifdef DEBUG
1799 L("pointer at screen edge");
1800 #endif
1801 menu = wMenuUnderPointer(scr);
1802 if (menu!=NULL)
1803 wMenuScroll(menu, event);
1806 #if 0
1807 if (event->xmotion.subwindow == None)
1808 return;
1810 if (scr->scrolledFMaximize != None) {
1811 WWindow *twin;
1813 twin = wWindowFor(scr->scrolledFMaximize);
1814 if (twin && twin->frame_y ==) {
1818 scr->scrolledFMaximize = NULL;
1820 } else {
1822 /* scroll full maximized window */
1823 if (event->xmotion.y_root < 1
1824 || event->xmotion.y_root > scr->scr_height - 1) {
1826 wwin = wWindowFor(event->xmotion.subwindow);
1828 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1829 && WFLAGP(wwin, full_maximize)
1830 && event->xmotion.x_root >= wwin->frame_x
1831 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1833 if (!WFLAGP(wwin, no_titlebar)
1834 && wwin->frame_y <= - wwin->frame->top_width) {
1836 wWindowMove(wwin, wwin->frame_x, 0);
1837 wwin->flags.dragged_while_fmaximized = 0;
1839 } else if (!WFLAGP(wwin, no_resizebar)
1840 && wwin->frame_y + wwin->frame->core->height >=
1841 scr->scr_height + wwin->frame->bottom_width) {
1843 int y = scr->scr_height + wwin->frame->bottom_width;
1845 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1847 wWindowMove(wwin, wwin->frame_x, y);
1848 wwin->flags.dragged_while_fmaximized = 0;
1852 #endif
1856 static void
1857 handleVisibilityNotify(XEvent *event)
1859 WWindow *wwin;
1861 wwin = wWindowFor(event->xvisibility.window);
1862 if (!wwin)
1863 return;
1864 wwin->flags.obscured =
1865 (event->xvisibility.state == VisibilityFullyObscured);