bug fixes
[wmaker-crm.git] / src / event.c
blob6d26a4fb6ff693283e1cc5fac578b80db897f171
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 #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 LastTimestamp = CurrentTime;
410 switch (event->type) {
411 case ButtonRelease:
412 case ButtonPress:
413 LastTimestamp = event->xbutton.time;
414 break;
415 case KeyPress:
416 case KeyRelease:
417 LastTimestamp = event->xkey.time;
418 break;
419 case MotionNotify:
420 LastTimestamp = event->xmotion.time;
421 break;
422 case PropertyNotify:
423 LastTimestamp = event->xproperty.time;
424 break;
425 case EnterNotify:
426 case LeaveNotify:
427 LastTimestamp = event->xcrossing.time;
428 break;
429 case SelectionClear:
430 LastTimestamp = event->xselectionclear.time;
431 break;
432 case SelectionRequest:
433 LastTimestamp = event->xselectionrequest.time;
434 break;
435 case SelectionNotify:
436 LastTimestamp = event->xselection.time;
437 break;
442 static void
443 handleExtensions(XEvent *event)
445 #ifdef SHAPE
446 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
447 handleShapeNotify(event);
449 #endif
450 #ifdef KEEP_XKB_LOCK_STATUS
451 if (wPreferences.modelock && event->type == (0x50|XkbIndicatorStateNotify)){
452 /* if someone know how to call this 0x50
453 * or how to clean code this please tell ]d */
454 handleXkbIndicatorStateNotify(event);
456 #endif /*KEEP_XKB_LOCK_STATUS*/
460 static void
461 handleMapRequest(XEvent *ev)
463 WWindow *wwin;
464 WScreen *scr = NULL;
465 Window window = ev->xmaprequest.window;
467 #ifdef DEBUG
468 printf("got map request for %x\n", (unsigned)window);
469 #endif
471 if ((wwin = wWindowFor(window))) {
472 if (wwin->flags.shaded) {
473 wUnshadeWindow(wwin);
475 /* deiconify window */
476 if (wwin->flags.miniaturized) {
477 wDeiconifyWindow(wwin);
478 } else if (wwin->flags.hidden) {
479 WApplication *wapp = wApplicationOf(wwin->main_window);
480 /* go to the last workspace that the user worked on the app */
481 #ifndef REDUCE_APPICONS
482 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
483 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
485 if (wapp) {
486 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
488 #endif
489 wUnhideApplication(wapp, False, False);
491 return;
494 scr = wScreenForRootWindow(ev->xmaprequest.parent);
496 wwin = wManageWindow(scr, window);
499 * This is to let the Dock know that the application it launched
500 * has already been mapped (eg: it has finished launching).
501 * It is not necessary for normally docked apps, but is needed for
502 * apps that were forcedly docked (like with dockit).
504 if (scr->last_dock) {
505 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
506 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
507 else
508 wDockTrackWindowLaunch(scr->last_dock, window);
511 if (wwin) {
512 wClientSetState(wwin, NormalState, None);
513 if (wwin->flags.maximized) {
514 wMaximizeWindow(wwin, wwin->flags.maximized);
516 if (wwin->flags.shaded) {
517 wwin->flags.shaded = 0;
518 wwin->flags.skip_next_animation = 1;
519 wShadeWindow(wwin);
521 if (wwin->flags.miniaturized) {
522 wwin->flags.miniaturized = 0;
523 wwin->flags.skip_next_animation = 1;
524 wIconifyWindow(wwin);
526 if (wwin->flags.hidden) {
527 WApplication *wapp = wApplicationOf(wwin->main_window);
529 wwin->flags.hidden = 0;
530 wwin->flags.skip_next_animation = 1;
531 if (wapp) {
532 wHideApplication(wapp);
539 static void
540 handleDestroyNotify(XEvent *event)
542 WWindow *wwin;
543 WApplication *app;
544 Window window = event->xdestroywindow.window;
546 #ifdef DEBUG
547 puts("got destroy notify");
548 #endif
550 wwin = wWindowFor(window);
551 if (wwin) {
552 wUnmanageWindow(wwin, False, True);
555 app = wApplicationOf(window);
556 if (app) {
557 if (window == app->main_window) {
558 app->refcount = 0;
559 wwin = app->main_window_desc->screen_ptr->focused_window;
560 while (wwin) {
561 if (wwin->main_window == window) {
562 wwin->main_window = None;
564 wwin = wwin->prev;
567 wApplicationDestroy(app);
570 #ifdef KWM_HINTS
571 wKWMCheckDestroy(&event->xdestroywindow);
572 #endif
577 static void
578 handleExpose(XEvent *event)
580 WObjDescriptor *desc;
581 XEvent ev;
583 #ifdef DEBUG
584 puts("got expose");
585 #endif
587 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
589 if (XFindContext(dpy, event->xexpose.window, wWinContext,
590 (XPointer *)&desc)==XCNOENT) {
591 return;
594 if (desc->handle_expose) {
595 (*desc->handle_expose)(desc, event);
600 /* bindable */
601 static void
602 handleButtonPress(XEvent *event)
604 WObjDescriptor *desc;
605 WScreen *scr;
607 #ifdef DEBUG
608 puts("got button press");
609 #endif
611 scr = wScreenForRootWindow(event->xbutton.root);
613 #ifdef BALLOON_TEXT
614 wBalloonHide(scr);
615 #endif
618 #ifndef LITE
619 if (event->xbutton.window==scr->root_win) {
621 if (event->xbutton.button==wPreferences.menu_button) {
622 OpenRootMenu(scr, event->xbutton.x_root,
623 event->xbutton.y_root, False);
624 /* ugly hack */
625 if (scr->root_menu) {
626 if (scr->root_menu->brother->flags.mapped)
627 event->xbutton.window = scr->root_menu->brother->frame->core->window;
628 else
629 event->xbutton.window = scr->root_menu->frame->core->window;
631 } else if (event->xbutton.button==wPreferences.windowl_button) {
632 OpenSwitchMenu(scr, event->xbutton.x_root,
633 event->xbutton.y_root, False);
634 if (scr->switch_menu) {
635 if (scr->switch_menu->brother->flags.mapped)
636 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
637 else
638 event->xbutton.window = scr->switch_menu->frame->core->window;
640 } else if (event->xbutton.button==wPreferences.select_button) {
641 wUnselectWindows(scr);
642 wSelectWindows(scr, event);
644 #ifdef MOUSE_WS_SWITCH
645 else if (event->xbutton.button==Button5) {
647 wWorkspaceRelativeChange(scr, -1);
649 } else if (event->xbutton.button==Button4) {
651 wWorkspaceRelativeChange(scr, 1);
654 #endif /* MOUSE_WS_SWITCH */
655 #ifdef GNOME_STUFF
656 else if (wGNOMEProxyizeButtonEvent(scr, event))
657 return;
658 #endif
660 #endif /* !LITE */
662 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
663 (XPointer *)&desc)==XCNOENT) {
664 if (XFindContext(dpy, event->xbutton.window, wWinContext,
665 (XPointer *)&desc)==XCNOENT) {
666 return;
670 if (desc->handle_mousedown!=NULL) {
671 (*desc->handle_mousedown)(desc, event);
674 if (desc->parent_type == WCLASS_WINDOW) {
675 XSync(dpy, 0);
677 if (event->xbutton.state & MOD_MASK) {
678 XAllowEvents(dpy, AsyncPointer, CurrentTime);
681 if (wPreferences.focus_mode == WKF_CLICK) {
682 if (wPreferences.ignore_focus_click) {
683 XAllowEvents(dpy, AsyncPointer, CurrentTime);
685 XAllowEvents(dpy, ReplayPointer, CurrentTime);
687 XSync(dpy, 0);
688 } else if (desc->parent_type == WCLASS_APPICON
689 || desc->parent_type == WCLASS_MINIWINDOW
690 || desc->parent_type == WCLASS_DOCK_ICON) {
691 if (event->xbutton.state & MOD_MASK) {
692 XSync(dpy, 0);
693 XAllowEvents(dpy, AsyncPointer, CurrentTime);
694 XSync(dpy, 0);
698 /* save double-click information */
699 if (scr->flags.next_click_is_not_double) {
700 scr->flags.next_click_is_not_double = 0;
701 } else {
702 scr->last_click_time = event->xbutton.time;
703 scr->last_click_button = event->xbutton.button;
704 scr->last_click_window = event->xbutton.window;
709 static void
710 handleMapNotify(XEvent *event)
712 WWindow *wwin;
714 #ifdef DEBUG
715 puts("got map");
716 #endif
718 wwin = wWindowFor(event->xmap.event);
719 if (wwin && wwin->client_win == event->xmap.event) {
720 if (wwin->flags.miniaturized) {
721 wDeiconifyWindow(wwin);
722 } else {
723 XGrabServer(dpy);
724 wWindowMap(wwin);
725 wClientSetState(wwin, NormalState, None);
726 XUngrabServer(dpy);
732 static void
733 handleUnmapNotify(XEvent *event)
735 WWindow *wwin;
736 XEvent ev;
737 Bool withdraw = False;
739 #ifdef DEBUG
740 puts("got unmap");
741 #endif
743 /* only process windows with StructureNotify selected
744 * (ignore SubstructureNotify) */
745 wwin = wWindowFor(event->xunmap.window);
746 if (!wwin)
747 return;
749 /* whether the event is a Withdrawal request */
750 if (event->xunmap.event == wwin->screen_ptr->root_win
751 && event->xunmap.send_event)
752 withdraw = True;
754 if (wwin->client_win != event->xunmap.event && !withdraw)
755 return;
757 if (!wwin->flags.mapped && !withdraw
758 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
759 && !wwin->flags.miniaturized && !wwin->flags.hidden)
760 return;
762 XGrabServer(dpy);
763 XUnmapWindow(dpy, wwin->frame->core->window);
764 wwin->flags.mapped = 0;
765 XSync(dpy, 0);
766 /* check if the window was destroyed */
767 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
768 DispatchEvent(&ev);
769 } else {
770 Bool reparented = False;
772 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
773 reparented = True;
775 /* withdraw window */
776 wwin->flags.mapped = 0;
777 if (!reparented)
778 wClientSetState(wwin, WithdrawnState, None);
780 /* if the window was reparented, do not reparent it back to the
781 * root window */
782 wUnmanageWindow(wwin, !reparented, False);
784 XUngrabServer(dpy);
788 static void
789 handleConfigureRequest(XEvent *event)
791 WWindow *wwin;
793 #ifdef DEBUG
794 puts("got configure request");
795 #endif
796 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
798 * Configure request for unmapped window
800 wClientConfigure(NULL, &(event->xconfigurerequest));
801 } else {
802 wClientConfigure(wwin, &(event->xconfigurerequest));
807 static void
808 handlePropertyNotify(XEvent *event)
810 WWindow *wwin;
811 WApplication *wapp;
812 Window jr;
813 int ji;
814 unsigned int ju;
815 WScreen *scr;
817 #ifdef DEBUG
818 puts("got property notify");
819 #endif
820 if ((wwin=wWindowFor(event->xproperty.window))) {
821 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
822 &ju, &ju, &ju, &ju)) {
823 return;
825 wClientCheckProperty(wwin, &event->xproperty);
827 wapp = wApplicationOf(event->xproperty.window);
828 if (wapp) {
829 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
832 scr = wScreenForWindow(event->xproperty.window);
833 if (scr && scr->root_win == event->xproperty.window) {
834 #ifdef KWM_HINTS
835 wKWMCheckRootHintChange(scr, &event->xproperty);
836 #endif
841 static void
842 handleClientMessage(XEvent *event)
844 WWindow *wwin;
845 WObjDescriptor *desc;
847 #ifdef DEBUG
848 puts("got client message");
849 #endif
850 /* handle transition from Normal to Iconic state */
851 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
852 && event->xclient.format == 32
853 && event->xclient.data.l[0] == IconicState) {
855 wwin = wWindowFor(event->xclient.window);
856 if (!wwin) return;
857 if (!wwin->flags.miniaturized)
858 wIconifyWindow(wwin);
859 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
860 && event->xclient.format == 32) {
861 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
863 if (!scr)
864 return;
866 if (event->xclient.data.l[1] == 1) { /* starting */
867 wColormapAllowClientInstallation(scr, True);
868 } else { /* stopping */
869 wColormapAllowClientInstallation(scr, False);
871 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
873 wDefaultsCheckDomains("bla");
875 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
876 WApplication *wapp;
877 int done=0;
878 wapp = wApplicationOf(event->xclient.window);
879 if (wapp) {
880 switch (event->xclient.data.l[0]) {
881 case WMFHideOtherApplications:
882 wHideOtherApplications(wapp->main_window_desc);
883 done = 1;
884 break;
886 case WMFHideApplication:
887 wHideApplication(wapp);
888 done = 1;
889 break;
892 if (!done) {
893 wwin = wWindowFor(event->xclient.window);
894 if (wwin) {
895 switch (event->xclient.data.l[0]) {
896 case WMFHideOtherApplications:
897 wHideOtherApplications(wwin);
898 break;
900 case WMFHideApplication:
901 wHideApplication(wApplicationOf(wwin->main_window));
902 break;
906 #ifdef GNOME_STUFF
907 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
908 /* do nothing */
909 #endif /* GNOME_STUFF */
910 #ifdef KWM_HINTS
911 } else if (wKWMProcessClientMessage(&event->xclient)) {
912 /* do nothing */
913 #endif /* KWM_HINTS */
914 #ifdef XDE_DND
915 } else if (wXDEProcessClientMessage(&event->xclient)) {
916 /* do nothing */
917 #endif /* XDE_DND */
918 #ifdef OFFIX_DND
919 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
920 WScreen *scr = wScreenForWindow(event->xclient.window);
921 if (scr && wDockReceiveDNDDrop(scr,event))
922 goto redirect_message;
923 #endif /* OFFIX_DND */
924 } else {
925 #ifdef OFFIX_DND
926 redirect_message:
927 #endif
929 * Non-standard thing, but needed by OffiX DND.
930 * For when the icon frame gets a ClientMessage
931 * that should have gone to the icon_window.
933 if (XFindContext(dpy, event->xbutton.window, wWinContext,
934 (XPointer *)&desc)!=XCNOENT) {
935 struct WIcon *icon=NULL;
937 if (desc->parent_type == WCLASS_MINIWINDOW) {
938 icon = (WIcon*)desc->parent;
939 } else if (desc->parent_type == WCLASS_DOCK_ICON
940 || desc->parent_type == WCLASS_APPICON) {
941 icon = ((WAppIcon*)desc->parent)->icon;
943 if (icon && (wwin=icon->owner)) {
944 if (wwin->client_win!=event->xclient.window) {
945 event->xclient.window = wwin->client_win;
946 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
947 event);
955 static void
956 raiseWindow(WScreen *scr)
958 WWindow *wwin;
960 scr->autoRaiseTimer = NULL;
962 wwin = wWindowFor(scr->autoRaiseWindow);
963 if (!wwin)
964 return;
966 if (!wwin->flags.destroyed) {
967 wRaiseFrame(wwin->frame->core);
968 /* this is needed or a race condition will occur */
969 XSync(dpy, False);
974 static void
975 handleEnterNotify(XEvent *event)
977 WWindow *wwin;
978 WObjDescriptor *desc = NULL;
979 XEvent ev;
980 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
983 #ifdef DEBUG
984 puts("got enter notify");
985 #endif
987 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
988 &ev)) {
989 /* already left the window... */
990 saveTimestamp(&ev);
991 if (ev.xcrossing.mode==event->xcrossing.mode
992 && ev.xcrossing.detail==event->xcrossing.detail) {
993 return;
997 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
998 (XPointer *)&desc)!=XCNOENT) {
999 if(desc->handle_enternotify)
1000 (*desc->handle_enternotify)(desc, event);
1003 /* enter to window */
1004 wwin = wWindowFor(event->xcrossing.window);
1005 if (!wwin) {
1006 if (wPreferences.focus_mode==WKF_POINTER
1007 && event->xcrossing.window==event->xcrossing.root) {
1008 wSetFocusTo(scr, NULL);
1010 if (wPreferences.colormap_mode==WKF_POINTER) {
1011 wColormapInstallForWindow(scr, NULL);
1013 if (scr->autoRaiseTimer
1014 && event->xcrossing.root==event->xcrossing.window) {
1015 WMDeleteTimerHandler(scr->autoRaiseTimer);
1016 scr->autoRaiseTimer = NULL;
1018 } else {
1019 /* set auto raise timer even if in focus-follows-mouse mode
1020 * and the event is for the frame window, even if the window
1021 * has focus already. useful if you move the pointer from a focused
1022 * window to the root window and back pretty fast
1024 * set focus if in focus-follows-mouse mode and the event
1025 * is for the frame window and window doesn't have focus yet */
1026 if ((wPreferences.focus_mode==WKF_POINTER
1027 || wPreferences.focus_mode==WKF_SLOPPY)
1028 && wwin->frame->core->window==event->xcrossing.window
1029 && !scr->flags.doing_alt_tab) {
1031 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1032 wSetFocusTo(scr, wwin);
1034 if (scr->autoRaiseTimer)
1035 WMDeleteTimerHandler(scr->autoRaiseTimer);
1036 scr->autoRaiseTimer = NULL;
1038 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1039 scr->autoRaiseWindow = wwin->frame->core->window;
1040 scr->autoRaiseTimer
1041 = WMAddTimerHandler(wPreferences.raise_delay,
1042 (WMCallback*)raiseWindow, scr);
1045 /* Install colormap for window, if the colormap installation mode
1046 * is colormap_follows_mouse */
1047 if (wPreferences.colormap_mode==WKF_POINTER) {
1048 if (wwin->client_win==event->xcrossing.window)
1049 wColormapInstallForWindow(scr, wwin);
1050 else
1051 wColormapInstallForWindow(scr, NULL);
1055 /* a little kluge to hide the clip balloon */
1056 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1057 if (!desc) {
1058 XUnmapWindow(dpy, scr->clip_balloon);
1059 scr->flags.clip_balloon_mapped = 0;
1060 } else {
1061 if (desc->parent_type!=WCLASS_DOCK_ICON
1062 || scr->clip_icon != desc->parent) {
1063 XUnmapWindow(dpy, scr->clip_balloon);
1064 scr->flags.clip_balloon_mapped = 0;
1069 if (event->xcrossing.window == event->xcrossing.root
1070 && event->xcrossing.detail == NotifyNormal
1071 && event->xcrossing.detail != NotifyInferior
1072 && wPreferences.focus_mode != WKF_CLICK) {
1074 wSetFocusTo(scr, scr->focused_window);
1077 #ifdef BALLOON_TEXT
1078 wBalloonEnteredObject(scr, desc);
1079 #endif
1083 static void
1084 handleLeaveNotify(XEvent *event)
1086 WObjDescriptor *desc = NULL;
1088 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1089 (XPointer *)&desc)!=XCNOENT) {
1090 if(desc->handle_leavenotify)
1091 (*desc->handle_leavenotify)(desc, event);
1093 if (event->xcrossing.window == event->xcrossing.root
1094 && event->xcrossing.mode == NotifyNormal
1095 && event->xcrossing.detail != NotifyInferior
1096 && wPreferences.focus_mode != WKF_CLICK) {
1098 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1100 wSetFocusTo(scr, NULL);
1105 #ifdef SHAPE
1106 static void
1107 handleShapeNotify(XEvent *event)
1109 XShapeEvent *shev = (XShapeEvent*)event;
1110 WWindow *wwin;
1111 XEvent ev;
1113 #ifdef DEBUG
1114 puts("got shape notify");
1115 #endif
1117 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1118 XShapeEvent *sev = (XShapeEvent*)&ev;
1120 if (sev->kind == ShapeBounding) {
1121 if (sev->shaped == shev->shaped) {
1122 *shev = *sev;
1123 } else {
1124 XPutBackEvent(dpy, &ev);
1125 break;
1130 wwin = wWindowFor(shev->window);
1131 if (!wwin || shev->kind != ShapeBounding)
1132 return;
1134 if (!shev->shaped && wwin->flags.shaped) {
1136 wwin->flags.shaped = 0;
1137 wWindowClearShape(wwin);
1139 } else if (shev->shaped) {
1141 wwin->flags.shaped = 1;
1142 wWindowSetShape(wwin);
1145 #endif /* SHAPE */
1147 #ifdef KEEP_XKB_LOCK_STATUS
1148 /* please help ]d if you know what to do */
1149 handleXkbIndicatorStateNotify(XEvent *event)
1151 WWindow *wwin;
1152 WScreen *scr;
1153 XkbStateRec staterec;
1154 int i;
1156 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1157 for (i=0; i<wScreenCount; i++) {
1158 scr = wScreenWithNumber(i);
1159 wwin = scr->focused_window;
1160 if (wwin->flags.focused) {
1161 wwin->frame->languagemode=staterec.compat_state&32?1:0;
1162 #ifdef XKB_TITLE_HINT
1163 if (wwin->frame->titlebar) {
1164 XClearWindow(dpy, wwin->frame->titlebar->window);
1165 wFrameWindowPaint(wwin->frame);
1167 #endif /* XKB_TITLE_HINT */
1171 #endif /*KEEP_XKB_LOCK_STATUS*/
1173 static void
1174 handleColormapNotify(XEvent *event)
1176 WWindow *wwin;
1177 WScreen *scr;
1178 Bool reinstall = False;
1180 wwin = wWindowFor(event->xcolormap.window);
1181 if (!wwin)
1182 return;
1184 scr = wwin->screen_ptr;
1186 do {
1187 if (wwin) {
1188 if (event->xcolormap.new) {
1189 XWindowAttributes attr;
1191 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1193 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1194 scr->current_colormap = attr.colormap;
1196 reinstall = True;
1197 } else if (event->xcolormap.state == ColormapUninstalled &&
1198 scr->current_colormap == event->xcolormap.colormap) {
1200 /* some bastard app (like XV) removed our colormap */
1202 * can't enforce or things like xscreensaver wont work
1203 * reinstall = True;
1205 } else if (event->xcolormap.state == ColormapInstalled &&
1206 scr->current_colormap == event->xcolormap.colormap) {
1208 /* someone has put our colormap back */
1209 reinstall = False;
1212 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1213 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1215 if (reinstall && scr->current_colormap!=None) {
1216 if (!scr->flags.colormap_stuff_blocked)
1217 XInstallColormap(dpy, scr->current_colormap);
1223 static void
1224 handleFocusIn(XEvent *event)
1226 WWindow *wwin;
1229 * For applications that like stealing the focus.
1231 while (XCheckTypedEvent(dpy, FocusIn, event));
1232 saveTimestamp(event);
1233 if (event->xfocus.mode == NotifyUngrab
1234 || event->xfocus.mode == NotifyGrab
1235 || event->xfocus.detail > NotifyNonlinearVirtual) {
1236 return;
1239 wwin = wWindowFor(event->xfocus.window);
1240 if (wwin && !wwin->flags.focused) {
1241 if (wwin->flags.mapped)
1242 wSetFocusTo(wwin->screen_ptr, wwin);
1243 else
1244 wSetFocusTo(wwin->screen_ptr, NULL);
1245 } else if (!wwin) {
1246 WScreen *scr = wScreenForWindow(event->xfocus.window);
1247 if (scr)
1248 wSetFocusTo(scr, NULL);
1253 static WWindow*
1254 windowUnderPointer(WScreen *scr)
1256 unsigned int mask;
1257 int foo;
1258 Window bar, win;
1260 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1261 &mask))
1262 return wWindowFor(win);
1263 return NULL;
1266 #ifdef WEENDOZE_CYCLE
1268 static WWindow*
1269 nextToFocusAfter(WWindow *wwin)
1271 WWindow *tmp = wwin->prev;
1273 while (tmp) {
1274 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1276 return tmp;
1278 tmp = tmp->prev;
1281 tmp = wwin;
1282 /* start over from the beginning of the list */
1283 while (tmp->next)
1284 tmp = tmp->next;
1286 while (tmp && tmp != wwin) {
1287 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1289 return tmp;
1291 tmp = tmp->prev;
1294 return wwin;
1298 static WWindow*
1299 nextToFocusBefore(WWindow *wwin)
1301 WWindow *tmp = wwin->next;
1303 while (tmp) {
1304 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1306 return tmp;
1308 tmp = tmp->next;
1311 /* start over from the beginning of the list */
1312 tmp = wwin;
1313 while (tmp->prev)
1314 tmp = tmp->prev;
1316 while (tmp && tmp != wwin) {
1317 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1319 return tmp;
1321 tmp = tmp->next;
1324 return wwin;
1327 static void
1328 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1330 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1331 Bool done = False;
1332 Bool openedSwitchMenu = False;
1333 WWindow *newFocused;
1334 WWindow *oldFocused;
1335 int modifiers;
1336 XModifierKeymap *keymap;
1338 if (!wwin)
1339 return;
1341 /* puts("IN");*/
1342 keymap = XGetModifierMapping(dpy);
1345 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1346 CurrentTime);
1348 if (next) {
1349 newFocused = nextToFocusAfter(wwin);
1350 } else {
1351 newFocused = nextToFocusBefore(wwin);
1354 scr->flags.doing_alt_tab = 1;
1356 wWindowFocus(newFocused, scr->focused_window);
1357 oldFocused = newFocused;
1358 if (wPreferences.circ_raise)
1359 wRaiseFrame(newFocused->frame->core);
1361 if (wPreferences.popup_switchmenu &&
1362 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1364 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1365 openedSwitchMenu = True;
1368 while (!done) {
1369 XEvent ev;
1371 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1372 /* WMNextEvent(dpy, &ev);*/
1373 if (ev.type != KeyRelease && ev.type != KeyPress) {
1374 WMHandleEvent(&ev);
1375 continue;
1377 /*puts("EV");*/
1378 /* ignore CapsLock */
1379 modifiers = ev.xkey.state & ValidModMask;
1381 if (ev.type == KeyPress
1382 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1383 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1385 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1386 newFocused = nextToFocusAfter(newFocused);
1387 wWindowFocus(newFocused, oldFocused);
1388 oldFocused = newFocused;
1389 if (wPreferences.circ_raise)
1390 wRaiseFrame(newFocused->frame->core);
1391 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1393 } else if (ev.type == KeyPress
1394 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1395 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1397 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1398 newFocused = nextToFocusBefore(newFocused);
1399 wWindowFocus(newFocused, oldFocused);
1400 oldFocused = newFocused;
1401 if (wPreferences.circ_raise)
1402 wRaiseFrame(newFocused->frame->core);
1403 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1405 if (ev.type == KeyRelease) {
1406 int i;
1408 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1409 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1410 wKeyBindings[WKBD_FOCUSNEXT].modifier
1411 & 1<<(i/keymap->max_keypermod)) {
1412 done = True;
1413 break;
1418 /*puts("OUT");*/
1419 XFree(keymap);
1421 XUngrabKeyboard(dpy, CurrentTime);
1422 wSetFocusTo(scr, newFocused);
1423 scr->flags.doing_alt_tab = 0;
1424 if (openedSwitchMenu)
1425 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1429 #endif /* WEENDOZE_CYCLE */
1434 static void
1435 handleKeyPress(XEvent *event)
1437 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1438 WWindow *wwin = scr->focused_window;
1439 int i;
1440 int modifiers;
1441 int command=-1;
1442 #ifdef KEEP_XKB_LOCK_STATUS
1443 XkbStateRec staterec;
1444 #endif /*KEEP_XKB_LOCK_STATUS*/
1446 /* ignore CapsLock */
1447 modifiers = event->xkey.state & ValidModMask;
1449 for (i=0; i<WKBD_LAST; i++) {
1450 if (wKeyBindings[i].keycode==0)
1451 continue;
1453 if (wKeyBindings[i].keycode==event->xkey.keycode
1454 && (/*wKeyBindings[i].modifier==0
1455 ||*/ wKeyBindings[i].modifier==modifiers)) {
1456 command = i;
1457 break;
1461 if (command < 0) {
1462 #ifdef LITE
1464 #if 0
1466 #endif
1467 #else
1468 if (!wRootMenuPerformShortcut(event)) {
1469 #endif
1470 static int dontLoop = 0;
1472 if (dontLoop > 10) {
1473 wwarning("problem with key event processing code");
1474 return;
1476 dontLoop++;
1477 /* if the focused window is an internal window, try redispatching
1478 * the event to the managed window, as it can be a WINGs window */
1479 if (wwin && wwin->flags.internal_window
1480 && wwin->client_leader!=None) {
1481 /* client_leader contains the WINGs toplevel */
1482 event->xany.window = wwin->client_leader;
1483 WMHandleEvent(event);
1485 dontLoop--;
1487 return;
1490 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1491 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1493 switch (command) {
1494 #ifndef LITE
1495 case WKBD_ROOTMENU:
1496 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1497 break;
1498 case WKBD_WINDOWLIST:
1499 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1500 break;
1501 #endif /* !LITE */
1502 case WKBD_WINDOWMENU:
1503 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1504 OpenWindowMenu(wwin, wwin->frame_x,
1505 wwin->frame_y+wwin->frame->top_width, True);
1506 break;
1507 case WKBD_MINIATURIZE:
1508 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1509 && !WFLAGP(wwin, no_miniaturizable)) {
1510 CloseWindowMenu(scr);
1512 if (wwin->protocols.MINIATURIZE_WINDOW)
1513 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1514 event->xbutton.time);
1515 else {
1516 wIconifyWindow(wwin);
1519 break;
1520 case WKBD_HIDE:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1522 WApplication *wapp = wApplicationOf(wwin->main_window);
1523 CloseWindowMenu(scr);
1525 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1526 wHideApplication(wapp);
1529 break;
1530 case WKBD_MAXIMIZE:
1531 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1532 CloseWindowMenu(scr);
1534 if (wwin->flags.maximized) {
1535 wUnmaximizeWindow(wwin);
1536 } else {
1537 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1540 break;
1541 case WKBD_VMAXIMIZE:
1542 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1543 CloseWindowMenu(scr);
1545 if (wwin->flags.maximized) {
1546 wUnmaximizeWindow(wwin);
1547 } else {
1548 wMaximizeWindow(wwin, MAX_VERTICAL);
1551 break;
1552 case WKBD_RAISE:
1553 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1554 CloseWindowMenu(scr);
1556 wRaiseFrame(wwin->frame->core);
1558 break;
1559 case WKBD_LOWER:
1560 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1561 CloseWindowMenu(scr);
1563 wLowerFrame(wwin->frame->core);
1565 break;
1566 case WKBD_RAISELOWER:
1567 /* raise or lower the window under the pointer, not the
1568 * focused one
1570 wwin = windowUnderPointer(scr);
1571 if (wwin)
1572 wRaiseLowerFrame(wwin->frame->core);
1573 break;
1574 case WKBD_SHADE:
1575 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1576 if (wwin->flags.shaded)
1577 wUnshadeWindow(wwin);
1578 else
1579 wShadeWindow(wwin);
1581 break;
1582 case WKBD_MOVERESIZE:
1583 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1584 CloseWindowMenu(scr);
1586 wKeyboardMoveResizeWindow(wwin);
1588 break;
1589 case WKBD_CLOSE:
1590 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1591 CloseWindowMenu(scr);
1592 if (wwin->protocols.DELETE_WINDOW)
1593 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1594 event->xkey.time);
1596 break;
1597 case WKBD_SELECT:
1598 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1599 wSelectWindow(wwin, !wwin->flags.selected);
1601 break;
1602 case WKBD_FOCUSNEXT:
1603 #ifdef WEENDOZE_CYCLE
1604 if (wPreferences.windoze_cycling) {
1605 doWindozeCycle(wwin, event, True);
1606 } else
1607 #endif /* WEENDOZE_CYCLE */
1609 wwin = NextFocusWindow(scr);
1610 if (wwin != NULL) {
1611 wSetFocusTo(scr, wwin);
1612 if (wPreferences.circ_raise)
1613 wRaiseFrame(wwin->frame->core);
1616 break;
1618 case WKBD_FOCUSPREV:
1619 #ifdef WEENDOZE_CYCLE
1620 if (wPreferences.windoze_cycling) {
1621 doWindozeCycle(wwin, event, False);
1622 } else
1623 #endif /* WEENDOZE_CYCLE */
1625 wwin = PrevFocusWindow(scr);
1626 if (wwin != NULL) {
1627 wSetFocusTo(scr, wwin);
1628 if (wPreferences.circ_raise)
1629 wRaiseFrame(wwin->frame->core);
1632 break;
1634 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1635 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1636 i = (scr->current_workspace/10)*10 + wk - 1;\
1637 if (wPreferences.ws_advance || i<scr->workspace_count)\
1638 wWorkspaceChange(scr, i);\
1639 break
1640 #else
1641 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1642 i = (scr->current_workspace/10)*10 + wk - 1;\
1643 if (wPreferences.ws_advance || i<scr->workspace_count)\
1644 wWorkspaceChange(scr, i);\
1645 break
1646 #endif
1647 GOTOWORKS(1);
1648 GOTOWORKS(2);
1649 GOTOWORKS(3);
1650 GOTOWORKS(4);
1651 GOTOWORKS(5);
1652 GOTOWORKS(6);
1653 GOTOWORKS(7);
1654 GOTOWORKS(8);
1655 GOTOWORKS(9);
1656 GOTOWORKS(10);
1657 #undef GOTOWORKS
1658 case WKBD_NEXTWORKSPACE:
1659 wWorkspaceRelativeChange(scr, 1);
1660 break;
1661 case WKBD_PREVWORKSPACE:
1662 wWorkspaceRelativeChange(scr, -1);
1663 break;
1664 case WKBD_WINDOW1:
1665 case WKBD_WINDOW2:
1666 case WKBD_WINDOW3:
1667 case WKBD_WINDOW4:
1668 #ifdef EXTEND_WINDOWSHORTCUT
1669 case WKBD_WINDOW5:
1670 case WKBD_WINDOW6:
1671 case WKBD_WINDOW7:
1672 case WKBD_WINDOW8:
1673 case WKBD_WINDOW9:
1674 case WKBD_WINDOW10:
1675 #endif
1676 if ( scr->shortcutSelectedWindows[command-WKBD_WINDOW1]) {
1677 LinkedList *list = scr->shortcutSelectedWindows[command-WKBD_WINDOW1];
1678 int cw;
1680 wUnselectWindows(scr);
1681 if (scr->shortcutWindow[command-WKBD_WINDOW1])
1682 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1683 cw = scr->current_workspace;
1684 while (list) {
1685 wWindowChangeWorkspace(list->head, cw);
1686 wMakeWindowVisible(list->head);
1687 wSelectWindow(list->head, True);
1688 list = list->tail;
1690 } else if (scr->shortcutWindow[command-WKBD_WINDOW1]){
1692 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1694 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1696 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1697 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1698 LinkedList *sl;
1700 sl = scr->selected_windows;
1701 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1703 while (sl) {
1704 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1705 sl = sl->tail;
1708 wSelectWindow(wwin, !wwin->flags.selected);
1709 XFlush(dpy);
1710 wusleep(3000);
1711 wSelectWindow(wwin, !wwin->flags.selected);
1712 XFlush(dpy);
1714 } else if (scr->selected_windows) {
1716 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1717 LinkedList *sl;
1719 sl = scr->selected_windows;
1720 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1722 while (sl) {
1723 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1724 sl = sl->tail;
1729 break;
1730 case WKBD_NEXTWSLAYER:
1731 case WKBD_PREVWSLAYER:
1733 int row, column;
1735 row = scr->current_workspace/10;
1736 column = scr->current_workspace%10;
1738 if (command==WKBD_NEXTWSLAYER) {
1739 if ((row+1)*10 < scr->workspace_count)
1740 wWorkspaceChange(scr, column+(row+1)*10);
1741 } else {
1742 if (row > 0)
1743 wWorkspaceChange(scr, column+(row-1)*10);
1746 break;
1747 case WKBD_CLIPLOWER:
1748 if (!wPreferences.flags.noclip)
1749 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1750 break;
1751 case WKBD_CLIPRAISE:
1752 if (!wPreferences.flags.noclip)
1753 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1754 break;
1755 case WKBD_CLIPRAISELOWER:
1756 if (!wPreferences.flags.noclip)
1757 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1758 break;
1759 #ifdef KEEP_XKB_LOCK_STATUS
1760 case WKBD_TOGGLE:
1761 if(wPreferences.modelock) {
1762 /*toggle*/
1763 wwin = scr->focused_window;
1765 if (wwin && wwin->flags.mapped
1766 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1767 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1768 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1770 wwin->frame->languagemode = staterec.compat_state&32
1771 ? 0 : 1;
1772 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1776 break;
1777 #endif /* KEEP_XKB_LOCK_STATUS */
1783 static void
1784 handleMotionNotify(XEvent *event)
1786 WMenu *menu;
1787 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1789 if (wPreferences.scrollable_menus) {
1790 if (scr->flags.jump_back_pending ||
1791 event->xmotion.x_root <= 1 ||
1792 event->xmotion.x_root >= (scr->scr_width - 2) ||
1793 event->xmotion.y_root <= 1 ||
1794 event->xmotion.y_root >= (scr->scr_height - 2)) {
1796 #ifdef DEBUG
1797 puts("pointer at screen edge");
1798 #endif
1800 menu = wMenuUnderPointer(scr);
1801 if (menu!=NULL)
1802 wMenuScroll(menu, event);
1805 #if 0
1806 if (event->xmotion.subwindow == None)
1807 return;
1809 if (scr->scrolledFMaximize != None) {
1810 WWindow *twin;
1812 twin = wWindowFor(scr->scrolledFMaximize);
1813 if (twin && twin->frame_y ==) {
1817 scr->scrolledFMaximize = NULL;
1819 } else {
1821 /* scroll full maximized window */
1822 if (event->xmotion.y_root < 1
1823 || event->xmotion.y_root > scr->scr_height - 1) {
1825 wwin = wWindowFor(event->xmotion.subwindow);
1827 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1828 && WFLAGP(wwin, full_maximize)
1829 && event->xmotion.x_root >= wwin->frame_x
1830 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1832 if (!WFLAGP(wwin, no_titlebar)
1833 && wwin->frame_y <= - wwin->frame->top_width) {
1835 wWindowMove(wwin, wwin->frame_x, 0);
1836 wwin->flags.dragged_while_fmaximized = 0;
1838 } else if (!WFLAGP(wwin, no_resizebar)
1839 && wwin->frame_y + wwin->frame->core->height >=
1840 scr->scr_height + wwin->frame->bottom_width) {
1842 int y = scr->scr_height + wwin->frame->bottom_width;
1844 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1846 wWindowMove(wwin, wwin->frame_x, y);
1847 wwin->flags.dragged_while_fmaximized = 0;
1851 #endif
1855 static void
1856 handleVisibilityNotify(XEvent *event)
1858 WWindow *wwin;
1860 wwin = wWindowFor(event->xvisibility.window);
1861 if (!wwin)
1862 return;
1863 wwin->flags.obscured =
1864 (event->xvisibility.state == VisibilityFullyObscured);