Fixes relate to modelock.
[wmaker-crm.git] / src / event.c
blobeb1fa064ffa4548637624df05427ab5dcfe3a136
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 XkbEvent *xkbevent;
450 xkbevent = event;
451 #ifdef SHAPE
452 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
453 handleShapeNotify(event);
455 #endif
456 #ifdef KEEP_XKB_LOCK_STATUS
457 if (wPreferences.modelock &&
458 (event->type == 0x54)){
459 /* if someone know how to call this 0x50
460 * or how to clean code this please tell ]d */
461 handleXkbIndicatorStateNotify(event);
463 #endif /*KEEP_XKB_LOCK_STATUS*/
467 static void
468 handleMapRequest(XEvent *ev)
470 WWindow *wwin;
471 WScreen *scr = NULL;
472 Window window = ev->xmaprequest.window;
474 #ifdef DEBUG
475 printf("got map request for %x\n", (unsigned)window);
476 #endif
478 if ((wwin = wWindowFor(window))) {
479 if (wwin->flags.shaded) {
480 wUnshadeWindow(wwin);
482 /* deiconify window */
483 if (wwin->flags.miniaturized) {
484 wDeiconifyWindow(wwin);
485 } else if (wwin->flags.hidden) {
486 WApplication *wapp = wApplicationOf(wwin->main_window);
487 /* go to the last workspace that the user worked on the app */
488 #ifndef REDUCE_APPICONS
489 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
490 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
492 if (wapp) {
493 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
495 #endif
496 wUnhideApplication(wapp, False, False);
498 return;
501 scr = wScreenForRootWindow(ev->xmaprequest.parent);
503 wwin = wManageWindow(scr, window);
506 * This is to let the Dock know that the application it launched
507 * has already been mapped (eg: it has finished launching).
508 * It is not necessary for normally docked apps, but is needed for
509 * apps that were forcedly docked (like with dockit).
511 if (scr->last_dock) {
512 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
513 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
514 else
515 wDockTrackWindowLaunch(scr->last_dock, window);
518 if (wwin) {
519 wClientSetState(wwin, NormalState, None);
520 if (wwin->flags.maximized) {
521 wMaximizeWindow(wwin, wwin->flags.maximized);
523 if (wwin->flags.shaded) {
524 wwin->flags.shaded = 0;
525 wwin->flags.skip_next_animation = 1;
526 wShadeWindow(wwin);
528 if (wwin->flags.miniaturized) {
529 wwin->flags.miniaturized = 0;
530 wwin->flags.skip_next_animation = 1;
531 wIconifyWindow(wwin);
533 if (wwin->flags.hidden) {
534 WApplication *wapp = wApplicationOf(wwin->main_window);
536 wwin->flags.hidden = 0;
537 wwin->flags.skip_next_animation = 1;
538 if (wapp) {
539 wHideApplication(wapp);
546 static void
547 handleDestroyNotify(XEvent *event)
549 WWindow *wwin;
550 WApplication *app;
551 Window window = event->xdestroywindow.window;
553 #ifdef DEBUG
554 puts("got destroy notify");
555 #endif
557 wwin = wWindowFor(window);
558 if (wwin) {
559 wUnmanageWindow(wwin, False, True);
562 app = wApplicationOf(window);
563 if (app) {
564 if (window == app->main_window) {
565 app->refcount = 0;
566 wwin = app->main_window_desc->screen_ptr->focused_window;
567 while (wwin) {
568 if (wwin->main_window == window) {
569 wwin->main_window = None;
571 wwin = wwin->prev;
574 wApplicationDestroy(app);
577 #ifdef KWM_HINTS
578 wKWMCheckDestroy(&event->xdestroywindow);
579 #endif
584 static void
585 handleExpose(XEvent *event)
587 WObjDescriptor *desc;
588 XEvent ev;
590 #ifdef DEBUG
591 puts("got expose");
592 #endif
594 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
596 if (XFindContext(dpy, event->xexpose.window, wWinContext,
597 (XPointer *)&desc)==XCNOENT) {
598 return;
601 if (desc->handle_expose) {
602 (*desc->handle_expose)(desc, event);
607 /* bindable */
608 static void
609 handleButtonPress(XEvent *event)
611 WObjDescriptor *desc;
612 WScreen *scr;
614 #ifdef DEBUG
615 puts("got button press");
616 #endif
618 scr = wScreenForRootWindow(event->xbutton.root);
620 #ifdef BALLOON_TEXT
621 wBalloonHide(scr);
622 #endif
625 #ifndef LITE
626 if (event->xbutton.window==scr->root_win) {
628 if (event->xbutton.button==wPreferences.menu_button) {
629 OpenRootMenu(scr, event->xbutton.x_root,
630 event->xbutton.y_root, False);
631 /* ugly hack */
632 if (scr->root_menu) {
633 if (scr->root_menu->brother->flags.mapped)
634 event->xbutton.window = scr->root_menu->brother->frame->core->window;
635 else
636 event->xbutton.window = scr->root_menu->frame->core->window;
638 } else if (event->xbutton.button==wPreferences.windowl_button) {
639 OpenSwitchMenu(scr, event->xbutton.x_root,
640 event->xbutton.y_root, False);
641 if (scr->switch_menu) {
642 if (scr->switch_menu->brother->flags.mapped)
643 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
644 else
645 event->xbutton.window = scr->switch_menu->frame->core->window;
647 } else if (event->xbutton.button==wPreferences.select_button) {
648 wUnselectWindows(scr);
649 wSelectWindows(scr, event);
651 #ifdef MOUSE_WS_SWITCH
652 else if (event->xbutton.button==Button5) {
654 wWorkspaceRelativeChange(scr, -1);
656 } else if (event->xbutton.button==Button4) {
658 wWorkspaceRelativeChange(scr, 1);
661 #endif /* MOUSE_WS_SWITCH */
662 #ifdef GNOME_STUFF
663 else if (wGNOMEProxyizeButtonEvent(scr, event))
664 return;
665 #endif
667 #endif /* !LITE */
669 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
670 (XPointer *)&desc)==XCNOENT) {
671 if (XFindContext(dpy, event->xbutton.window, wWinContext,
672 (XPointer *)&desc)==XCNOENT) {
673 return;
677 if (desc->handle_mousedown!=NULL) {
678 (*desc->handle_mousedown)(desc, event);
681 if (desc->parent_type == WCLASS_WINDOW) {
682 XSync(dpy, 0);
684 if (event->xbutton.state & MOD_MASK) {
685 XAllowEvents(dpy, AsyncPointer, CurrentTime);
688 if (wPreferences.focus_mode == WKF_CLICK) {
689 if (wPreferences.ignore_focus_click) {
690 XAllowEvents(dpy, AsyncPointer, CurrentTime);
692 XAllowEvents(dpy, ReplayPointer, CurrentTime);
694 XSync(dpy, 0);
695 } else if (desc->parent_type == WCLASS_APPICON
696 || desc->parent_type == WCLASS_MINIWINDOW
697 || desc->parent_type == WCLASS_DOCK_ICON) {
698 if (event->xbutton.state & MOD_MASK) {
699 XSync(dpy, 0);
700 XAllowEvents(dpy, AsyncPointer, CurrentTime);
701 XSync(dpy, 0);
705 /* save double-click information */
706 if (scr->flags.next_click_is_not_double) {
707 scr->flags.next_click_is_not_double = 0;
708 } else {
709 scr->last_click_time = event->xbutton.time;
710 scr->last_click_button = event->xbutton.button;
711 scr->last_click_window = event->xbutton.window;
716 static void
717 handleMapNotify(XEvent *event)
719 WWindow *wwin;
721 #ifdef DEBUG
722 puts("got map");
723 #endif
725 wwin = wWindowFor(event->xmap.event);
726 if (wwin && wwin->client_win == event->xmap.event) {
727 if (wwin->flags.miniaturized) {
728 wDeiconifyWindow(wwin);
729 } else {
730 XGrabServer(dpy);
731 wWindowMap(wwin);
732 wClientSetState(wwin, NormalState, None);
733 XUngrabServer(dpy);
739 static void
740 handleUnmapNotify(XEvent *event)
742 WWindow *wwin;
743 XEvent ev;
744 Bool withdraw = False;
746 #ifdef DEBUG
747 puts("got unmap");
748 #endif
750 /* only process windows with StructureNotify selected
751 * (ignore SubstructureNotify) */
752 wwin = wWindowFor(event->xunmap.window);
753 if (!wwin)
754 return;
756 /* whether the event is a Withdrawal request */
757 if (event->xunmap.event == wwin->screen_ptr->root_win
758 && event->xunmap.send_event)
759 withdraw = True;
761 if (wwin->client_win != event->xunmap.event && !withdraw)
762 return;
764 if (!wwin->flags.mapped && !withdraw
765 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
766 && !wwin->flags.miniaturized && !wwin->flags.hidden)
767 return;
769 XGrabServer(dpy);
770 XUnmapWindow(dpy, wwin->frame->core->window);
771 wwin->flags.mapped = 0;
772 XSync(dpy, 0);
773 /* check if the window was destroyed */
774 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
775 DispatchEvent(&ev);
776 } else {
777 Bool reparented = False;
779 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
780 reparented = True;
782 /* withdraw window */
783 wwin->flags.mapped = 0;
784 if (!reparented)
785 wClientSetState(wwin, WithdrawnState, None);
787 /* if the window was reparented, do not reparent it back to the
788 * root window */
789 wUnmanageWindow(wwin, !reparented, False);
791 XUngrabServer(dpy);
795 static void
796 handleConfigureRequest(XEvent *event)
798 WWindow *wwin;
800 #ifdef DEBUG
801 puts("got configure request");
802 #endif
803 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
805 * Configure request for unmapped window
807 wClientConfigure(NULL, &(event->xconfigurerequest));
808 } else {
809 wClientConfigure(wwin, &(event->xconfigurerequest));
814 static void
815 handlePropertyNotify(XEvent *event)
817 WWindow *wwin;
818 WApplication *wapp;
819 Window jr;
820 int ji;
821 unsigned int ju;
822 WScreen *scr;
824 #ifdef DEBUG
825 puts("got property notify");
826 #endif
827 if ((wwin=wWindowFor(event->xproperty.window))) {
828 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
829 &ju, &ju, &ju, &ju)) {
830 return;
832 wClientCheckProperty(wwin, &event->xproperty);
834 wapp = wApplicationOf(event->xproperty.window);
835 if (wapp) {
836 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
839 scr = wScreenForWindow(event->xproperty.window);
840 if (scr && scr->root_win == event->xproperty.window) {
841 #ifdef KWM_HINTS
842 wKWMCheckRootHintChange(scr, &event->xproperty);
843 #endif
848 static void
849 handleClientMessage(XEvent *event)
851 WWindow *wwin;
852 WObjDescriptor *desc;
854 #ifdef DEBUG
855 puts("got client message");
856 #endif
857 /* handle transition from Normal to Iconic state */
858 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
859 && event->xclient.format == 32
860 && event->xclient.data.l[0] == IconicState) {
862 wwin = wWindowFor(event->xclient.window);
863 if (!wwin) return;
864 if (!wwin->flags.miniaturized)
865 wIconifyWindow(wwin);
866 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
867 && event->xclient.format == 32) {
868 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
870 if (!scr)
871 return;
873 if (event->xclient.data.l[1] == 1) { /* starting */
874 wColormapAllowClientInstallation(scr, True);
875 } else { /* stopping */
876 wColormapAllowClientInstallation(scr, False);
878 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
880 wDefaultsCheckDomains("bla");
882 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
883 WApplication *wapp;
884 int done=0;
885 wapp = wApplicationOf(event->xclient.window);
886 if (wapp) {
887 switch (event->xclient.data.l[0]) {
888 case WMFHideOtherApplications:
889 wHideOtherApplications(wapp->main_window_desc);
890 done = 1;
891 break;
893 case WMFHideApplication:
894 wHideApplication(wapp);
895 done = 1;
896 break;
899 if (!done) {
900 wwin = wWindowFor(event->xclient.window);
901 if (wwin) {
902 switch (event->xclient.data.l[0]) {
903 case WMFHideOtherApplications:
904 wHideOtherApplications(wwin);
905 break;
907 case WMFHideApplication:
908 wHideApplication(wApplicationOf(wwin->main_window));
909 break;
913 #ifdef GNOME_STUFF
914 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
915 /* do nothing */
916 #endif /* GNOME_STUFF */
917 #ifdef KWM_HINTS
918 } else if (wKWMProcessClientMessage(&event->xclient)) {
919 /* do nothing */
920 #endif /* KWM_HINTS */
921 #ifdef XDND
922 } else if (wXDNDProcessClientMessage(&event->xclient)) {
923 /* do nothing */
924 #endif /* XDND */
925 #ifdef OFFIX_DND
926 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
927 WScreen *scr = wScreenForWindow(event->xclient.window);
928 if (scr && wDockReceiveDNDDrop(scr,event))
929 goto redirect_message;
930 #endif /* OFFIX_DND */
931 } else {
932 #ifdef OFFIX_DND
933 redirect_message:
934 #endif
936 * Non-standard thing, but needed by OffiX DND.
937 * For when the icon frame gets a ClientMessage
938 * that should have gone to the icon_window.
940 if (XFindContext(dpy, event->xbutton.window, wWinContext,
941 (XPointer *)&desc)!=XCNOENT) {
942 struct WIcon *icon=NULL;
944 if (desc->parent_type == WCLASS_MINIWINDOW) {
945 icon = (WIcon*)desc->parent;
946 } else if (desc->parent_type == WCLASS_DOCK_ICON
947 || desc->parent_type == WCLASS_APPICON) {
948 icon = ((WAppIcon*)desc->parent)->icon;
950 if (icon && (wwin=icon->owner)) {
951 if (wwin->client_win!=event->xclient.window) {
952 event->xclient.window = wwin->client_win;
953 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
954 event);
962 static void
963 raiseWindow(WScreen *scr)
965 WWindow *wwin;
967 scr->autoRaiseTimer = NULL;
969 wwin = wWindowFor(scr->autoRaiseWindow);
970 if (!wwin)
971 return;
973 if (!wwin->flags.destroyed) {
974 wRaiseFrame(wwin->frame->core);
975 /* this is needed or a race condition will occur */
976 XSync(dpy, False);
981 static void
982 handleEnterNotify(XEvent *event)
984 WWindow *wwin;
985 WObjDescriptor *desc = NULL;
986 XEvent ev;
987 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
990 #ifdef DEBUG
991 puts("got enter notify");
992 #endif
994 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
995 &ev)) {
996 /* already left the window... */
997 saveTimestamp(&ev);
998 if (ev.xcrossing.mode==event->xcrossing.mode
999 && ev.xcrossing.detail==event->xcrossing.detail) {
1000 return;
1004 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1005 (XPointer *)&desc)!=XCNOENT) {
1006 if(desc->handle_enternotify)
1007 (*desc->handle_enternotify)(desc, event);
1010 /* enter to window */
1011 wwin = wWindowFor(event->xcrossing.window);
1012 if (!wwin) {
1013 if (wPreferences.focus_mode==WKF_POINTER
1014 && event->xcrossing.window==event->xcrossing.root) {
1015 wSetFocusTo(scr, NULL);
1017 if (wPreferences.colormap_mode==WKF_POINTER) {
1018 wColormapInstallForWindow(scr, NULL);
1020 if (scr->autoRaiseTimer
1021 && event->xcrossing.root==event->xcrossing.window) {
1022 WMDeleteTimerHandler(scr->autoRaiseTimer);
1023 scr->autoRaiseTimer = NULL;
1025 } else {
1026 /* set auto raise timer even if in focus-follows-mouse mode
1027 * and the event is for the frame window, even if the window
1028 * has focus already. useful if you move the pointer from a focused
1029 * window to the root window and back pretty fast
1031 * set focus if in focus-follows-mouse mode and the event
1032 * is for the frame window and window doesn't have focus yet */
1033 if ((wPreferences.focus_mode==WKF_POINTER
1034 || wPreferences.focus_mode==WKF_SLOPPY)
1035 && wwin->frame->core->window==event->xcrossing.window
1036 && !scr->flags.doing_alt_tab) {
1038 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1039 wSetFocusTo(scr, wwin);
1041 if (scr->autoRaiseTimer)
1042 WMDeleteTimerHandler(scr->autoRaiseTimer);
1043 scr->autoRaiseTimer = NULL;
1045 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1046 scr->autoRaiseWindow = wwin->frame->core->window;
1047 scr->autoRaiseTimer
1048 = WMAddTimerHandler(wPreferences.raise_delay,
1049 (WMCallback*)raiseWindow, scr);
1052 /* Install colormap for window, if the colormap installation mode
1053 * is colormap_follows_mouse */
1054 if (wPreferences.colormap_mode==WKF_POINTER) {
1055 if (wwin->client_win==event->xcrossing.window)
1056 wColormapInstallForWindow(scr, wwin);
1057 else
1058 wColormapInstallForWindow(scr, NULL);
1062 /* a little kluge to hide the clip balloon */
1063 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1064 if (!desc) {
1065 XUnmapWindow(dpy, scr->clip_balloon);
1066 scr->flags.clip_balloon_mapped = 0;
1067 } else {
1068 if (desc->parent_type!=WCLASS_DOCK_ICON
1069 || scr->clip_icon != desc->parent) {
1070 XUnmapWindow(dpy, scr->clip_balloon);
1071 scr->flags.clip_balloon_mapped = 0;
1076 if (event->xcrossing.window == event->xcrossing.root
1077 && event->xcrossing.detail == NotifyNormal
1078 && event->xcrossing.detail != NotifyInferior
1079 && wPreferences.focus_mode != WKF_CLICK) {
1081 wSetFocusTo(scr, scr->focused_window);
1084 #ifdef BALLOON_TEXT
1085 wBalloonEnteredObject(scr, desc);
1086 #endif
1090 static void
1091 handleLeaveNotify(XEvent *event)
1093 WObjDescriptor *desc = NULL;
1095 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1096 (XPointer *)&desc)!=XCNOENT) {
1097 if(desc->handle_leavenotify)
1098 (*desc->handle_leavenotify)(desc, event);
1100 if (event->xcrossing.window == event->xcrossing.root
1101 && event->xcrossing.mode == NotifyNormal
1102 && event->xcrossing.detail != NotifyInferior
1103 && wPreferences.focus_mode != WKF_CLICK) {
1105 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1107 wSetFocusTo(scr, NULL);
1112 #ifdef SHAPE
1113 static void
1114 handleShapeNotify(XEvent *event)
1116 XShapeEvent *shev = (XShapeEvent*)event;
1117 WWindow *wwin;
1118 XEvent ev;
1120 #ifdef DEBUG
1121 puts("got shape notify");
1122 #endif
1124 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1125 XShapeEvent *sev = (XShapeEvent*)&ev;
1127 if (sev->kind == ShapeBounding) {
1128 if (sev->shaped == shev->shaped) {
1129 *shev = *sev;
1130 } else {
1131 XPutBackEvent(dpy, &ev);
1132 break;
1137 wwin = wWindowFor(shev->window);
1138 if (!wwin || shev->kind != ShapeBounding)
1139 return;
1141 if (!shev->shaped && wwin->flags.shaped) {
1143 wwin->flags.shaped = 0;
1144 wWindowClearShape(wwin);
1146 } else if (shev->shaped) {
1148 wwin->flags.shaped = 1;
1149 wWindowSetShape(wwin);
1152 #endif /* SHAPE */
1154 #ifdef KEEP_XKB_LOCK_STATUS
1155 /* please help ]d if you know what to do */
1156 handleXkbIndicatorStateNotify(XEvent *event)
1158 WWindow *wwin;
1159 WScreen *scr;
1160 XkbStateRec staterec;
1161 int i;
1163 for (i=0; i<wScreenCount; i++) {
1164 scr = wScreenWithNumber(i);
1165 wwin = scr->focused_window;
1166 if (wwin->flags.focused) {
1167 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1168 if (wwin->frame->languagemode != staterec.group) {
1169 wwin->frame->last_languagemode = wwin->frame->languagemode;
1170 wwin->frame->languagemode = staterec.group;
1172 #ifdef XKB_BUTTON_HINT
1173 if (wwin->frame->titlebar) {
1174 wFrameWindowPaint(wwin->frame);
1176 #endif
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 = wwin->frame->last_languagemode;
1780 wwin->frame->last_languagemode = staterec.group;
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);