Hmmm. Please check the thing compiles before commiting changes.
[wmaker-crm.git] / src / event.c
blob99b4a4de83a651db76c1823f11c68372eeadd218
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 #ifdef KEEP_XKB_LOCK_STATUS
100 extern int wXkbEventBase;
101 #endif
103 /* special flags */
104 extern char WDelayedActionSet;
107 /************ Local stuff ***********/
110 static void saveTimestamp(XEvent *event);
111 static void handleColormapNotify();
112 static void handleMapNotify(), handleUnmapNotify();
113 static void handleButtonPress(), handleExpose();
114 static void handleDestroyNotify();
115 static void handleConfigureRequest();
116 static void handleMapRequest();
117 static void handlePropertyNotify();
118 static void handleEnterNotify();
119 static void handleLeaveNotify();
120 static void handleExtensions();
121 static void handleClientMessage();
122 static void handleKeyPress();
123 static void handleFocusIn();
124 static void handleMotionNotify();
125 static void handleVisibilityNotify();
128 #ifdef SHAPE
129 static void handleShapeNotify();
130 #endif
132 /* called from the signal handler */
133 void NotifyDeadProcess(pid_t pid, unsigned char status);
135 /* real dead process handler */
136 static void handleDeadProcess(void *foo);
139 typedef struct DeadProcesses {
140 pid_t pid;
141 unsigned char exit_status;
142 } DeadProcesses;
144 /* stack of dead processes */
145 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
146 static int deadProcessPtr=0;
149 typedef struct DeathHandler {
150 WDeathHandler *callback;
151 pid_t pid;
152 struct DeathHandler *next;
153 void *client_data;
154 } DeathHandler;
156 static DeathHandler *deathHandler=NULL;
160 WMagicNumber
161 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
163 DeathHandler *handler;
165 handler = malloc(sizeof(DeathHandler));
166 if (!handler)
167 return 0;
169 handler->pid = pid;
170 handler->callback = callback;
171 handler->client_data = cdata;
173 handler->next = deathHandler;
175 deathHandler = handler;
177 return handler;
182 void
183 wDeleteDeathHandler(WMagicNumber id)
185 DeathHandler *tmp, *handler=(DeathHandler*)id;
187 if (!handler || !deathHandler)
188 return;
190 tmp = deathHandler;
191 if (tmp==handler) {
192 deathHandler = handler->next;
193 free(handler);
194 } else {
195 while (tmp->next) {
196 if (tmp->next==handler) {
197 tmp->next=handler->next;
198 free(handler);
199 break;
201 tmp = tmp->next;
207 void
208 DispatchEvent(XEvent *event)
210 if (deathHandler)
211 handleDeadProcess(NULL);
213 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
214 WCHANGE_STATE(WSTATE_EXITING);
215 /* received SIGTERM */
217 * WMHandleEvent() can't be called from anything
218 * executed inside here, or we can get in a infinite
219 * recursive loop.
221 Shutdown(WSExitMode);
223 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
224 WCHANGE_STATE(WSTATE_RESTARTING);
226 Shutdown(WSRestartPreparationMode);
227 /* received SIGHUP */
228 Restart(NULL, True);
231 /* for the case that all that is wanted to be dispatched is
232 * the stuff above */
233 if (!event)
234 return;
236 saveTimestamp(event);
237 switch (event->type) {
238 case MapRequest:
239 handleMapRequest(event);
240 break;
242 case KeyPress:
243 handleKeyPress(event);
244 break;
246 case MotionNotify:
247 handleMotionNotify(event);
248 break;
250 case ConfigureRequest:
251 handleConfigureRequest(event);
252 break;
254 case DestroyNotify:
255 handleDestroyNotify(event);
256 break;
258 case MapNotify:
259 handleMapNotify(event);
260 break;
262 case UnmapNotify:
263 handleUnmapNotify(event);
264 break;
266 case ButtonPress:
267 handleButtonPress(event);
268 break;
270 case Expose:
271 handleExpose(event);
272 break;
274 case PropertyNotify:
275 handlePropertyNotify(event);
276 break;
278 case EnterNotify:
279 handleEnterNotify(event);
280 break;
282 case LeaveNotify:
283 handleLeaveNotify(event);
284 break;
286 case ClientMessage:
287 handleClientMessage(event);
288 break;
290 case ColormapNotify:
291 handleColormapNotify(event);
292 break;
294 case MappingNotify:
295 if (event->xmapping.request == MappingKeyboard
296 || event->xmapping.request == MappingModifier)
297 XRefreshKeyboardMapping(&event->xmapping);
298 break;
300 case FocusIn:
301 handleFocusIn(event);
302 break;
304 case VisibilityNotify:
305 handleVisibilityNotify(event);
306 break;
307 default:
308 handleExtensions(event);
309 break;
315 *----------------------------------------------------------------------
316 * EventLoop-
317 * Processes X and internal events indefinitely.
319 * Returns:
320 * Never returns
322 * Side effects:
323 * The LastTimestamp global variable is updated.
324 *----------------------------------------------------------------------
326 void
327 EventLoop()
329 XEvent event;
331 for(;;) {
332 WMNextEvent(dpy, &event);
333 WMHandleEvent(&event);
339 Bool
340 IsDoubleClick(WScreen *scr, XEvent *event)
342 if ((scr->last_click_time>0) &&
343 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
344 && (event->xbutton.button == scr->last_click_button)
345 && (event->xbutton.window == scr->last_click_window)) {
347 scr->flags.next_click_is_not_double = 1;
348 scr->last_click_time = 0;
349 scr->last_click_window = event->xbutton.window;
351 return True;
353 return False;
357 void
358 NotifyDeadProcess(pid_t pid, unsigned char status)
360 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
361 wwarning("stack overflow: too many dead processes");
362 return;
364 /* stack the process to be handled later,
365 * as this is called from the signal handler */
366 deadProcesses[deadProcessPtr].pid = pid;
367 deadProcesses[deadProcessPtr].exit_status = status;
368 deadProcessPtr++;
372 static void
373 handleDeadProcess(void *foo)
375 DeathHandler *tmp;
376 int i;
378 for (i=0; i<deadProcessPtr; i++) {
379 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
382 if (!deathHandler) {
383 deadProcessPtr=0;
384 return;
387 /* get the pids on the queue and call handlers */
388 while (deadProcessPtr>0) {
389 deadProcessPtr--;
391 tmp = deathHandler;
392 while (tmp) {
393 DeathHandler *t;
395 t = tmp->next;
397 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
398 (*tmp->callback)(tmp->pid,
399 deadProcesses[deadProcessPtr].exit_status,
400 tmp->client_data);
401 wDeleteDeathHandler(tmp);
403 tmp = t;
409 static void
410 saveTimestamp(XEvent *event)
412 WScreen *scr = wScreenForWindow(event->xany.window);
413 LastTimestamp = CurrentTime;
415 switch (event->type) {
416 case ButtonRelease:
417 case ButtonPress:
418 LastTimestamp = event->xbutton.time;
419 break;
420 case KeyPress:
421 case KeyRelease:
422 LastTimestamp = event->xkey.time;
423 break;
424 case MotionNotify:
425 LastTimestamp = event->xmotion.time;
426 break;
427 case PropertyNotify:
428 LastTimestamp = event->xproperty.time;
429 break;
430 case EnterNotify:
431 case LeaveNotify:
432 LastTimestamp = event->xcrossing.time;
433 break;
434 case SelectionClear:
435 LastTimestamp = event->xselectionclear.time;
436 break;
437 case SelectionRequest:
438 LastTimestamp = event->xselectionrequest.time;
439 break;
440 case SelectionNotify:
441 LastTimestamp = event->xselection.time;
442 #ifdef XDND
443 wXDNDProcessSelection(event);
444 #endif
445 break;
450 static void
451 handleExtensions(XEvent *event)
453 #ifdef KEEP_XKB_LOCK_STATUS
454 XkbEvent *xkbevent;
455 xkbevent = (XkbEvent *)event;
456 #endif /*KEEP_XKB_LOCK_STATUS*/
457 #ifdef SHAPE
458 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
459 handleShapeNotify(event);
461 #endif
462 #ifdef KEEP_XKB_LOCK_STATUS
463 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
464 handleXkbIndicatorStateNotify(event);
466 #endif /*KEEP_XKB_LOCK_STATUS*/
470 static void
471 handleMapRequest(XEvent *ev)
473 WWindow *wwin;
474 WScreen *scr = NULL;
475 Window window = ev->xmaprequest.window;
477 #ifdef DEBUG
478 printf("got map request for %x\n", (unsigned)window);
479 #endif
481 if ((wwin = wWindowFor(window))) {
482 if (wwin->flags.shaded) {
483 wUnshadeWindow(wwin);
485 /* deiconify window */
486 if (wwin->flags.miniaturized) {
487 wDeiconifyWindow(wwin);
488 } else if (wwin->flags.hidden) {
489 WApplication *wapp = wApplicationOf(wwin->main_window);
490 /* go to the last workspace that the user worked on the app */
491 #ifndef REDUCE_APPICONS
492 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
493 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
495 if (wapp) {
496 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
498 #endif
499 wUnhideApplication(wapp, False, False);
501 return;
504 scr = wScreenForRootWindow(ev->xmaprequest.parent);
506 wwin = wManageWindow(scr, window);
509 * This is to let the Dock know that the application it launched
510 * has already been mapped (eg: it has finished launching).
511 * It is not necessary for normally docked apps, but is needed for
512 * apps that were forcedly docked (like with dockit).
514 if (scr->last_dock) {
515 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
516 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
517 else
518 wDockTrackWindowLaunch(scr->last_dock, window);
521 if (wwin) {
522 wClientSetState(wwin, NormalState, None);
523 if (wwin->flags.maximized) {
524 wMaximizeWindow(wwin, wwin->flags.maximized);
526 if (wwin->flags.shaded) {
527 wwin->flags.shaded = 0;
528 wwin->flags.skip_next_animation = 1;
529 wShadeWindow(wwin);
531 if (wwin->flags.miniaturized) {
532 wwin->flags.miniaturized = 0;
533 wwin->flags.skip_next_animation = 1;
534 wIconifyWindow(wwin);
536 if (wwin->flags.hidden) {
537 WApplication *wapp = wApplicationOf(wwin->main_window);
539 wwin->flags.hidden = 0;
540 wwin->flags.skip_next_animation = 1;
541 if (wapp) {
542 wHideApplication(wapp);
549 static void
550 handleDestroyNotify(XEvent *event)
552 WWindow *wwin;
553 WApplication *app;
554 Window window = event->xdestroywindow.window;
556 #ifdef DEBUG
557 puts("got destroy notify");
558 #endif
560 wwin = wWindowFor(window);
561 if (wwin) {
562 wUnmanageWindow(wwin, False, True);
565 app = wApplicationOf(window);
566 if (app) {
567 if (window == app->main_window) {
568 app->refcount = 0;
569 wwin = app->main_window_desc->screen_ptr->focused_window;
570 while (wwin) {
571 if (wwin->main_window == window) {
572 wwin->main_window = None;
574 wwin = wwin->prev;
577 wApplicationDestroy(app);
580 #ifdef KWM_HINTS
581 wKWMCheckDestroy(&event->xdestroywindow);
582 #endif
587 static void
588 handleExpose(XEvent *event)
590 WObjDescriptor *desc;
591 XEvent ev;
593 #ifdef DEBUG
594 puts("got expose");
595 #endif
597 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
599 if (XFindContext(dpy, event->xexpose.window, wWinContext,
600 (XPointer *)&desc)==XCNOENT) {
601 return;
604 if (desc->handle_expose) {
605 (*desc->handle_expose)(desc, event);
610 /* bindable */
611 static void
612 handleButtonPress(XEvent *event)
614 WObjDescriptor *desc;
615 WScreen *scr;
617 #ifdef DEBUG
618 puts("got button press");
619 #endif
621 scr = wScreenForRootWindow(event->xbutton.root);
623 #ifdef BALLOON_TEXT
624 wBalloonHide(scr);
625 #endif
628 #ifndef LITE
629 if (event->xbutton.window==scr->root_win) {
631 if (event->xbutton.button==wPreferences.menu_button) {
632 OpenRootMenu(scr, event->xbutton.x_root,
633 event->xbutton.y_root, False);
634 /* ugly hack */
635 if (scr->root_menu) {
636 if (scr->root_menu->brother->flags.mapped)
637 event->xbutton.window = scr->root_menu->brother->frame->core->window;
638 else
639 event->xbutton.window = scr->root_menu->frame->core->window;
641 } else if (event->xbutton.button==wPreferences.windowl_button) {
642 OpenSwitchMenu(scr, event->xbutton.x_root,
643 event->xbutton.y_root, False);
644 if (scr->switch_menu) {
645 if (scr->switch_menu->brother->flags.mapped)
646 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
647 else
648 event->xbutton.window = scr->switch_menu->frame->core->window;
650 } else if (event->xbutton.button==wPreferences.select_button) {
651 wUnselectWindows(scr);
652 wSelectWindows(scr, event);
654 #ifdef MOUSE_WS_SWITCH
655 else if (event->xbutton.button==Button5) {
657 wWorkspaceRelativeChange(scr, -1);
659 } else if (event->xbutton.button==Button4) {
661 wWorkspaceRelativeChange(scr, 1);
664 #endif /* MOUSE_WS_SWITCH */
665 #ifdef GNOME_STUFF
666 else if (wGNOMEProxyizeButtonEvent(scr, event))
667 return;
668 #endif
670 #endif /* !LITE */
672 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
673 (XPointer *)&desc)==XCNOENT) {
674 if (XFindContext(dpy, event->xbutton.window, wWinContext,
675 (XPointer *)&desc)==XCNOENT) {
676 return;
680 if (desc->handle_mousedown!=NULL) {
681 (*desc->handle_mousedown)(desc, event);
684 if (desc->parent_type == WCLASS_WINDOW) {
685 XSync(dpy, 0);
687 if (event->xbutton.state & MOD_MASK) {
688 XAllowEvents(dpy, AsyncPointer, CurrentTime);
691 if (wPreferences.focus_mode == WKF_CLICK) {
692 if (wPreferences.ignore_focus_click) {
693 XAllowEvents(dpy, AsyncPointer, CurrentTime);
695 XAllowEvents(dpy, ReplayPointer, CurrentTime);
697 XSync(dpy, 0);
698 } else if (desc->parent_type == WCLASS_APPICON
699 || desc->parent_type == WCLASS_MINIWINDOW
700 || desc->parent_type == WCLASS_DOCK_ICON) {
701 if (event->xbutton.state & MOD_MASK) {
702 XSync(dpy, 0);
703 XAllowEvents(dpy, AsyncPointer, CurrentTime);
704 XSync(dpy, 0);
708 /* save double-click information */
709 if (scr->flags.next_click_is_not_double) {
710 scr->flags.next_click_is_not_double = 0;
711 } else {
712 scr->last_click_time = event->xbutton.time;
713 scr->last_click_button = event->xbutton.button;
714 scr->last_click_window = event->xbutton.window;
719 static void
720 handleMapNotify(XEvent *event)
722 WWindow *wwin;
724 #ifdef DEBUG
725 puts("got map");
726 #endif
728 wwin = wWindowFor(event->xmap.event);
729 if (wwin && wwin->client_win == event->xmap.event) {
730 if (wwin->flags.miniaturized) {
731 wDeiconifyWindow(wwin);
732 } else {
733 XGrabServer(dpy);
734 wWindowMap(wwin);
735 wClientSetState(wwin, NormalState, None);
736 XUngrabServer(dpy);
742 static void
743 handleUnmapNotify(XEvent *event)
745 WWindow *wwin;
746 XEvent ev;
747 Bool withdraw = False;
749 #ifdef DEBUG
750 puts("got unmap");
751 #endif
753 /* only process windows with StructureNotify selected
754 * (ignore SubstructureNotify) */
755 wwin = wWindowFor(event->xunmap.window);
756 if (!wwin)
757 return;
759 /* whether the event is a Withdrawal request */
760 if (event->xunmap.event == wwin->screen_ptr->root_win
761 && event->xunmap.send_event)
762 withdraw = True;
764 if (wwin->client_win != event->xunmap.event && !withdraw)
765 return;
767 if (!wwin->flags.mapped && !withdraw
768 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
769 && !wwin->flags.miniaturized && !wwin->flags.hidden)
770 return;
772 XGrabServer(dpy);
773 XUnmapWindow(dpy, wwin->frame->core->window);
774 wwin->flags.mapped = 0;
775 XSync(dpy, 0);
776 /* check if the window was destroyed */
777 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
778 DispatchEvent(&ev);
779 } else {
780 Bool reparented = False;
782 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
783 reparented = True;
785 /* withdraw window */
786 wwin->flags.mapped = 0;
787 if (!reparented)
788 wClientSetState(wwin, WithdrawnState, None);
790 /* if the window was reparented, do not reparent it back to the
791 * root window */
792 wUnmanageWindow(wwin, !reparented, False);
794 XUngrabServer(dpy);
798 static void
799 handleConfigureRequest(XEvent *event)
801 WWindow *wwin;
803 #ifdef DEBUG
804 puts("got configure request");
805 #endif
806 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
808 * Configure request for unmapped window
810 wClientConfigure(NULL, &(event->xconfigurerequest));
811 } else {
812 wClientConfigure(wwin, &(event->xconfigurerequest));
817 static void
818 handlePropertyNotify(XEvent *event)
820 WWindow *wwin;
821 WApplication *wapp;
822 Window jr;
823 int ji;
824 unsigned int ju;
825 WScreen *scr;
827 #ifdef DEBUG
828 puts("got property notify");
829 #endif
830 if ((wwin=wWindowFor(event->xproperty.window))) {
831 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
832 &ju, &ju, &ju, &ju)) {
833 return;
835 wClientCheckProperty(wwin, &event->xproperty);
837 wapp = wApplicationOf(event->xproperty.window);
838 if (wapp) {
839 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
842 scr = wScreenForWindow(event->xproperty.window);
843 if (scr && scr->root_win == event->xproperty.window) {
844 #ifdef KWM_HINTS
845 wKWMCheckRootHintChange(scr, &event->xproperty);
846 #endif
851 static void
852 handleClientMessage(XEvent *event)
854 WWindow *wwin;
855 WObjDescriptor *desc;
857 #ifdef DEBUG
858 puts("got client message");
859 #endif
860 /* handle transition from Normal to Iconic state */
861 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
862 && event->xclient.format == 32
863 && event->xclient.data.l[0] == IconicState) {
865 wwin = wWindowFor(event->xclient.window);
866 if (!wwin) return;
867 if (!wwin->flags.miniaturized)
868 wIconifyWindow(wwin);
869 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
870 && event->xclient.format == 32) {
871 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
873 if (!scr)
874 return;
876 if (event->xclient.data.l[1] == 1) { /* starting */
877 wColormapAllowClientInstallation(scr, True);
878 } else { /* stopping */
879 wColormapAllowClientInstallation(scr, False);
881 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
883 wDefaultsCheckDomains("bla");
885 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
886 WApplication *wapp;
887 int done=0;
888 wapp = wApplicationOf(event->xclient.window);
889 if (wapp) {
890 switch (event->xclient.data.l[0]) {
891 case WMFHideOtherApplications:
892 wHideOtherApplications(wapp->main_window_desc);
893 done = 1;
894 break;
896 case WMFHideApplication:
897 wHideApplication(wapp);
898 done = 1;
899 break;
902 if (!done) {
903 wwin = wWindowFor(event->xclient.window);
904 if (wwin) {
905 switch (event->xclient.data.l[0]) {
906 case WMFHideOtherApplications:
907 wHideOtherApplications(wwin);
908 break;
910 case WMFHideApplication:
911 wHideApplication(wApplicationOf(wwin->main_window));
912 break;
916 #ifdef GNOME_STUFF
917 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
918 /* do nothing */
919 #endif /* GNOME_STUFF */
920 #ifdef KWM_HINTS
921 } else if (wKWMProcessClientMessage(&event->xclient)) {
922 /* do nothing */
923 #endif /* KWM_HINTS */
924 #ifdef XDND
925 } else if (wXDNDProcessClientMessage(&event->xclient)) {
926 /* do nothing */
927 #endif /* XDND */
928 #ifdef OFFIX_DND
929 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
930 WScreen *scr = wScreenForWindow(event->xclient.window);
931 if (scr && wDockReceiveDNDDrop(scr,event))
932 goto redirect_message;
933 #endif /* OFFIX_DND */
934 } else {
935 #ifdef OFFIX_DND
936 redirect_message:
937 #endif
939 * Non-standard thing, but needed by OffiX DND.
940 * For when the icon frame gets a ClientMessage
941 * that should have gone to the icon_window.
943 if (XFindContext(dpy, event->xbutton.window, wWinContext,
944 (XPointer *)&desc)!=XCNOENT) {
945 struct WIcon *icon=NULL;
947 if (desc->parent_type == WCLASS_MINIWINDOW) {
948 icon = (WIcon*)desc->parent;
949 } else if (desc->parent_type == WCLASS_DOCK_ICON
950 || desc->parent_type == WCLASS_APPICON) {
951 icon = ((WAppIcon*)desc->parent)->icon;
953 if (icon && (wwin=icon->owner)) {
954 if (wwin->client_win!=event->xclient.window) {
955 event->xclient.window = wwin->client_win;
956 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
957 event);
965 static void
966 raiseWindow(WScreen *scr)
968 WWindow *wwin;
970 scr->autoRaiseTimer = NULL;
972 wwin = wWindowFor(scr->autoRaiseWindow);
973 if (!wwin)
974 return;
976 if (!wwin->flags.destroyed) {
977 wRaiseFrame(wwin->frame->core);
978 /* this is needed or a race condition will occur */
979 XSync(dpy, False);
984 static void
985 handleEnterNotify(XEvent *event)
987 WWindow *wwin;
988 WObjDescriptor *desc = NULL;
989 XEvent ev;
990 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
993 #ifdef DEBUG
994 puts("got enter notify");
995 #endif
997 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
998 &ev)) {
999 /* already left the window... */
1000 saveTimestamp(&ev);
1001 if (ev.xcrossing.mode==event->xcrossing.mode
1002 && ev.xcrossing.detail==event->xcrossing.detail) {
1003 return;
1007 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1008 (XPointer *)&desc)!=XCNOENT) {
1009 if(desc->handle_enternotify)
1010 (*desc->handle_enternotify)(desc, event);
1013 /* enter to window */
1014 wwin = wWindowFor(event->xcrossing.window);
1015 if (!wwin) {
1016 if (wPreferences.focus_mode==WKF_POINTER
1017 && event->xcrossing.window==event->xcrossing.root) {
1018 wSetFocusTo(scr, NULL);
1020 if (wPreferences.colormap_mode==WKF_POINTER) {
1021 wColormapInstallForWindow(scr, NULL);
1023 if (scr->autoRaiseTimer
1024 && event->xcrossing.root==event->xcrossing.window) {
1025 WMDeleteTimerHandler(scr->autoRaiseTimer);
1026 scr->autoRaiseTimer = NULL;
1028 } else {
1029 /* set auto raise timer even if in focus-follows-mouse mode
1030 * and the event is for the frame window, even if the window
1031 * has focus already. useful if you move the pointer from a focused
1032 * window to the root window and back pretty fast
1034 * set focus if in focus-follows-mouse mode and the event
1035 * is for the frame window and window doesn't have focus yet */
1036 if ((wPreferences.focus_mode==WKF_POINTER
1037 || wPreferences.focus_mode==WKF_SLOPPY)
1038 && wwin->frame->core->window==event->xcrossing.window
1039 && !scr->flags.doing_alt_tab) {
1041 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1042 wSetFocusTo(scr, wwin);
1044 if (scr->autoRaiseTimer)
1045 WMDeleteTimerHandler(scr->autoRaiseTimer);
1046 scr->autoRaiseTimer = NULL;
1048 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1049 scr->autoRaiseWindow = wwin->frame->core->window;
1050 scr->autoRaiseTimer
1051 = WMAddTimerHandler(wPreferences.raise_delay,
1052 (WMCallback*)raiseWindow, scr);
1055 /* Install colormap for window, if the colormap installation mode
1056 * is colormap_follows_mouse */
1057 if (wPreferences.colormap_mode==WKF_POINTER) {
1058 if (wwin->client_win==event->xcrossing.window)
1059 wColormapInstallForWindow(scr, wwin);
1060 else
1061 wColormapInstallForWindow(scr, NULL);
1065 /* a little kluge to hide the clip balloon */
1066 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1067 if (!desc) {
1068 XUnmapWindow(dpy, scr->clip_balloon);
1069 scr->flags.clip_balloon_mapped = 0;
1070 } else {
1071 if (desc->parent_type!=WCLASS_DOCK_ICON
1072 || scr->clip_icon != desc->parent) {
1073 XUnmapWindow(dpy, scr->clip_balloon);
1074 scr->flags.clip_balloon_mapped = 0;
1079 if (event->xcrossing.window == event->xcrossing.root
1080 && event->xcrossing.detail == NotifyNormal
1081 && event->xcrossing.detail != NotifyInferior
1082 && wPreferences.focus_mode != WKF_CLICK) {
1084 wSetFocusTo(scr, scr->focused_window);
1087 #ifdef BALLOON_TEXT
1088 wBalloonEnteredObject(scr, desc);
1089 #endif
1093 static void
1094 handleLeaveNotify(XEvent *event)
1096 WObjDescriptor *desc = NULL;
1098 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1099 (XPointer *)&desc)!=XCNOENT) {
1100 if(desc->handle_leavenotify)
1101 (*desc->handle_leavenotify)(desc, event);
1103 if (event->xcrossing.window == event->xcrossing.root
1104 && event->xcrossing.mode == NotifyNormal
1105 && event->xcrossing.detail != NotifyInferior
1106 && wPreferences.focus_mode != WKF_CLICK) {
1108 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1110 wSetFocusTo(scr, NULL);
1115 #ifdef SHAPE
1116 static void
1117 handleShapeNotify(XEvent *event)
1119 XShapeEvent *shev = (XShapeEvent*)event;
1120 WWindow *wwin;
1121 XEvent ev;
1123 #ifdef DEBUG
1124 puts("got shape notify");
1125 #endif
1127 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1128 XShapeEvent *sev = (XShapeEvent*)&ev;
1130 if (sev->kind == ShapeBounding) {
1131 if (sev->shaped == shev->shaped) {
1132 *shev = *sev;
1133 } else {
1134 XPutBackEvent(dpy, &ev);
1135 break;
1140 wwin = wWindowFor(shev->window);
1141 if (!wwin || shev->kind != ShapeBounding)
1142 return;
1144 if (!shev->shaped && wwin->flags.shaped) {
1146 wwin->flags.shaped = 0;
1147 wWindowClearShape(wwin);
1149 } else if (shev->shaped) {
1151 wwin->flags.shaped = 1;
1152 wWindowSetShape(wwin);
1155 #endif /* SHAPE */
1157 #ifdef KEEP_XKB_LOCK_STATUS
1158 /* please help ]d if you know what to do */
1159 handleXkbIndicatorStateNotify(XEvent *event)
1161 WWindow *wwin;
1162 WScreen *scr;
1163 XkbStateRec staterec;
1164 int i;
1166 for (i=0; i<wScreenCount; i++) {
1167 scr = wScreenWithNumber(i);
1168 wwin = scr->focused_window;
1169 if (wwin && wwin->flags.focused) {
1170 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1171 if (wwin->frame->languagemode != staterec.group) {
1172 wwin->frame->last_languagemode = wwin->frame->languagemode;
1173 wwin->frame->languagemode = staterec.group;
1175 #ifdef XKB_BUTTON_HINT
1176 if (wwin->frame->titlebar) {
1177 wFrameWindowPaint(wwin->frame);
1179 #endif
1183 #endif /*KEEP_XKB_LOCK_STATUS*/
1185 static void
1186 handleColormapNotify(XEvent *event)
1188 WWindow *wwin;
1189 WScreen *scr;
1190 Bool reinstall = False;
1192 wwin = wWindowFor(event->xcolormap.window);
1193 if (!wwin)
1194 return;
1196 scr = wwin->screen_ptr;
1198 do {
1199 if (wwin) {
1200 if (event->xcolormap.new) {
1201 XWindowAttributes attr;
1203 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1205 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1206 scr->current_colormap = attr.colormap;
1208 reinstall = True;
1209 } else if (event->xcolormap.state == ColormapUninstalled &&
1210 scr->current_colormap == event->xcolormap.colormap) {
1212 /* some bastard app (like XV) removed our colormap */
1214 * can't enforce or things like xscreensaver wont work
1215 * reinstall = True;
1217 } else if (event->xcolormap.state == ColormapInstalled &&
1218 scr->current_colormap == event->xcolormap.colormap) {
1220 /* someone has put our colormap back */
1221 reinstall = False;
1224 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1225 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1227 if (reinstall && scr->current_colormap!=None) {
1228 if (!scr->flags.colormap_stuff_blocked)
1229 XInstallColormap(dpy, scr->current_colormap);
1235 static void
1236 handleFocusIn(XEvent *event)
1238 WWindow *wwin;
1241 * For applications that like stealing the focus.
1243 while (XCheckTypedEvent(dpy, FocusIn, event));
1244 saveTimestamp(event);
1245 if (event->xfocus.mode == NotifyUngrab
1246 || event->xfocus.mode == NotifyGrab
1247 || event->xfocus.detail > NotifyNonlinearVirtual) {
1248 return;
1251 wwin = wWindowFor(event->xfocus.window);
1252 if (wwin && !wwin->flags.focused) {
1253 if (wwin->flags.mapped)
1254 wSetFocusTo(wwin->screen_ptr, wwin);
1255 else
1256 wSetFocusTo(wwin->screen_ptr, NULL);
1257 } else if (!wwin) {
1258 WScreen *scr = wScreenForWindow(event->xfocus.window);
1259 if (scr)
1260 wSetFocusTo(scr, NULL);
1265 static WWindow*
1266 windowUnderPointer(WScreen *scr)
1268 unsigned int mask;
1269 int foo;
1270 Window bar, win;
1272 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1273 &mask))
1274 return wWindowFor(win);
1275 return NULL;
1278 #ifdef WEENDOZE_CYCLE
1280 static WWindow*
1281 nextToFocusAfter(WWindow *wwin)
1283 WWindow *tmp = wwin->prev;
1285 while (tmp) {
1286 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1288 return tmp;
1290 tmp = tmp->prev;
1293 tmp = wwin;
1294 /* start over from the beginning of the list */
1295 while (tmp->next)
1296 tmp = tmp->next;
1298 while (tmp && tmp != wwin) {
1299 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1301 return tmp;
1303 tmp = tmp->prev;
1306 return wwin;
1310 static WWindow*
1311 nextToFocusBefore(WWindow *wwin)
1313 WWindow *tmp = wwin->next;
1315 while (tmp) {
1316 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1318 return tmp;
1320 tmp = tmp->next;
1323 /* start over from the beginning of the list */
1324 tmp = wwin;
1325 while (tmp->prev)
1326 tmp = tmp->prev;
1328 while (tmp && tmp != wwin) {
1329 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1331 return tmp;
1333 tmp = tmp->next;
1336 return wwin;
1339 static void
1340 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1342 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1343 Bool done = False;
1344 Bool openedSwitchMenu = False;
1345 WWindow *newFocused;
1346 WWindow *oldFocused;
1347 int modifiers;
1348 XModifierKeymap *keymap;
1350 if (!wwin)
1351 return;
1353 /* puts("IN");*/
1354 keymap = XGetModifierMapping(dpy);
1357 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1358 CurrentTime);
1360 if (next) {
1361 newFocused = nextToFocusAfter(wwin);
1362 } else {
1363 newFocused = nextToFocusBefore(wwin);
1366 scr->flags.doing_alt_tab = 1;
1368 wWindowFocus(newFocused, scr->focused_window);
1369 oldFocused = newFocused;
1370 if (wPreferences.circ_raise)
1371 wRaiseFrame(newFocused->frame->core);
1373 if (wPreferences.popup_switchmenu &&
1374 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1376 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1377 openedSwitchMenu = True;
1380 while (!done) {
1381 XEvent ev;
1383 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1384 /* WMNextEvent(dpy, &ev);*/
1385 if (ev.type != KeyRelease && ev.type != KeyPress) {
1386 WMHandleEvent(&ev);
1387 continue;
1389 /*puts("EV");*/
1390 /* ignore CapsLock */
1391 modifiers = ev.xkey.state & ValidModMask;
1393 if (ev.type == KeyPress
1394 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1395 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1397 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1398 newFocused = nextToFocusAfter(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 } else if (ev.type == KeyPress
1406 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1407 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1409 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1410 newFocused = nextToFocusBefore(newFocused);
1411 wWindowFocus(newFocused, oldFocused);
1412 oldFocused = newFocused;
1413 if (wPreferences.circ_raise)
1414 wRaiseFrame(newFocused->frame->core);
1415 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1417 if (ev.type == KeyRelease) {
1418 int i;
1420 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1421 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1422 wKeyBindings[WKBD_FOCUSNEXT].modifier
1423 & 1<<(i/keymap->max_keypermod)) {
1424 done = True;
1425 break;
1430 /*puts("OUT");*/
1431 XFree(keymap);
1433 XUngrabKeyboard(dpy, CurrentTime);
1434 wSetFocusTo(scr, newFocused);
1435 scr->flags.doing_alt_tab = 0;
1436 if (openedSwitchMenu)
1437 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1441 #endif /* WEENDOZE_CYCLE */
1446 static void
1447 handleKeyPress(XEvent *event)
1449 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1450 WWindow *wwin = scr->focused_window;
1451 int i;
1452 int modifiers;
1453 int command=-1;
1454 #ifdef KEEP_XKB_LOCK_STATUS
1455 XkbStateRec staterec;
1456 #endif /*KEEP_XKB_LOCK_STATUS*/
1458 /* ignore CapsLock */
1459 modifiers = event->xkey.state & ValidModMask;
1461 for (i=0; i<WKBD_LAST; i++) {
1462 if (wKeyBindings[i].keycode==0)
1463 continue;
1465 if (wKeyBindings[i].keycode==event->xkey.keycode
1466 && (/*wKeyBindings[i].modifier==0
1467 ||*/ wKeyBindings[i].modifier==modifiers)) {
1468 command = i;
1469 break;
1473 if (command < 0) {
1474 #ifdef LITE
1476 #if 0
1478 #endif
1479 #else
1480 if (!wRootMenuPerformShortcut(event)) {
1481 #endif
1482 static int dontLoop = 0;
1484 if (dontLoop > 10) {
1485 wwarning("problem with key event processing code");
1486 return;
1488 dontLoop++;
1489 /* if the focused window is an internal window, try redispatching
1490 * the event to the managed window, as it can be a WINGs window */
1491 if (wwin && wwin->flags.internal_window
1492 && wwin->client_leader!=None) {
1493 /* client_leader contains the WINGs toplevel */
1494 event->xany.window = wwin->client_leader;
1495 WMHandleEvent(event);
1497 dontLoop--;
1499 return;
1502 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1503 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1505 switch (command) {
1506 #ifndef LITE
1507 case WKBD_ROOTMENU:
1508 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1509 break;
1510 case WKBD_WINDOWLIST:
1511 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1512 break;
1513 #endif /* !LITE */
1514 case WKBD_WINDOWMENU:
1515 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1516 OpenWindowMenu(wwin, wwin->frame_x,
1517 wwin->frame_y+wwin->frame->top_width, True);
1518 break;
1519 case WKBD_MINIATURIZE:
1520 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1521 && !WFLAGP(wwin, no_miniaturizable)) {
1522 CloseWindowMenu(scr);
1524 if (wwin->protocols.MINIATURIZE_WINDOW)
1525 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1526 event->xbutton.time);
1527 else {
1528 wIconifyWindow(wwin);
1531 break;
1532 case WKBD_HIDE:
1533 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1534 WApplication *wapp = wApplicationOf(wwin->main_window);
1535 CloseWindowMenu(scr);
1537 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1538 wHideApplication(wapp);
1541 break;
1542 case WKBD_MAXIMIZE:
1543 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1544 CloseWindowMenu(scr);
1546 if (wwin->flags.maximized) {
1547 wUnmaximizeWindow(wwin);
1548 } else {
1549 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1552 break;
1553 case WKBD_VMAXIMIZE:
1554 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1555 CloseWindowMenu(scr);
1557 if (wwin->flags.maximized) {
1558 wUnmaximizeWindow(wwin);
1559 } else {
1560 wMaximizeWindow(wwin, MAX_VERTICAL);
1563 break;
1564 case WKBD_RAISE:
1565 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1566 CloseWindowMenu(scr);
1568 wRaiseFrame(wwin->frame->core);
1570 break;
1571 case WKBD_LOWER:
1572 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1573 CloseWindowMenu(scr);
1575 wLowerFrame(wwin->frame->core);
1577 break;
1578 case WKBD_RAISELOWER:
1579 /* raise or lower the window under the pointer, not the
1580 * focused one
1582 wwin = windowUnderPointer(scr);
1583 if (wwin)
1584 wRaiseLowerFrame(wwin->frame->core);
1585 break;
1586 case WKBD_SHADE:
1587 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1588 if (wwin->flags.shaded)
1589 wUnshadeWindow(wwin);
1590 else
1591 wShadeWindow(wwin);
1593 break;
1594 case WKBD_MOVERESIZE:
1595 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1596 CloseWindowMenu(scr);
1598 wKeyboardMoveResizeWindow(wwin);
1600 break;
1601 case WKBD_CLOSE:
1602 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1603 CloseWindowMenu(scr);
1604 if (wwin->protocols.DELETE_WINDOW)
1605 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1606 event->xkey.time);
1608 break;
1609 case WKBD_SELECT:
1610 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1611 wSelectWindow(wwin, !wwin->flags.selected);
1613 break;
1614 case WKBD_FOCUSNEXT:
1615 #ifdef WEENDOZE_CYCLE
1616 if (wPreferences.windoze_cycling) {
1617 doWindozeCycle(wwin, event, True);
1618 } else
1619 #endif /* WEENDOZE_CYCLE */
1621 wwin = NextFocusWindow(scr);
1622 if (wwin != NULL) {
1623 wSetFocusTo(scr, wwin);
1624 if (wPreferences.circ_raise)
1625 wRaiseFrame(wwin->frame->core);
1628 break;
1630 case WKBD_FOCUSPREV:
1631 #ifdef WEENDOZE_CYCLE
1632 if (wPreferences.windoze_cycling) {
1633 doWindozeCycle(wwin, event, False);
1634 } else
1635 #endif /* WEENDOZE_CYCLE */
1637 wwin = PrevFocusWindow(scr);
1638 if (wwin != NULL) {
1639 wSetFocusTo(scr, wwin);
1640 if (wPreferences.circ_raise)
1641 wRaiseFrame(wwin->frame->core);
1644 break;
1646 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1647 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1648 i = (scr->current_workspace/10)*10 + wk - 1;\
1649 if (wPreferences.ws_advance || i<scr->workspace_count)\
1650 wWorkspaceChange(scr, i);\
1651 break
1652 #else
1653 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1654 i = (scr->current_workspace/10)*10 + wk - 1;\
1655 if (wPreferences.ws_advance || i<scr->workspace_count)\
1656 wWorkspaceChange(scr, i);\
1657 break
1658 #endif
1659 GOTOWORKS(1);
1660 GOTOWORKS(2);
1661 GOTOWORKS(3);
1662 GOTOWORKS(4);
1663 GOTOWORKS(5);
1664 GOTOWORKS(6);
1665 GOTOWORKS(7);
1666 GOTOWORKS(8);
1667 GOTOWORKS(9);
1668 GOTOWORKS(10);
1669 #undef GOTOWORKS
1670 case WKBD_NEXTWORKSPACE:
1671 wWorkspaceRelativeChange(scr, 1);
1672 break;
1673 case WKBD_PREVWORKSPACE:
1674 wWorkspaceRelativeChange(scr, -1);
1675 break;
1676 case WKBD_WINDOW1:
1677 case WKBD_WINDOW2:
1678 case WKBD_WINDOW3:
1679 case WKBD_WINDOW4:
1680 #ifdef EXTEND_WINDOWSHORTCUT
1681 case WKBD_WINDOW5:
1682 case WKBD_WINDOW6:
1683 case WKBD_WINDOW7:
1684 case WKBD_WINDOW8:
1685 case WKBD_WINDOW9:
1686 case WKBD_WINDOW10:
1687 #endif
1688 if ( scr->shortcutSelectedWindows[command-WKBD_WINDOW1]) {
1689 LinkedList *list = scr->shortcutSelectedWindows[command-WKBD_WINDOW1];
1690 int cw;
1692 wUnselectWindows(scr);
1693 if (scr->shortcutWindow[command-WKBD_WINDOW1])
1694 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1695 cw = scr->current_workspace;
1696 while (list) {
1697 wWindowChangeWorkspace(list->head, cw);
1698 wMakeWindowVisible(list->head);
1699 wSelectWindow(list->head, True);
1700 list = list->tail;
1702 } else if (scr->shortcutWindow[command-WKBD_WINDOW1]){
1704 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1706 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1708 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1709 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1710 LinkedList *sl;
1712 sl = scr->selected_windows;
1713 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1715 while (sl) {
1716 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1717 sl = sl->tail;
1720 wSelectWindow(wwin, !wwin->flags.selected);
1721 XFlush(dpy);
1722 wusleep(3000);
1723 wSelectWindow(wwin, !wwin->flags.selected);
1724 XFlush(dpy);
1726 } else if (scr->selected_windows) {
1728 if (wwin->flags.selected /* && scr->selected_windows */ ) {
1729 LinkedList *sl;
1731 sl = scr->selected_windows;
1732 list_free(scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1734 while (sl) {
1735 scr->shortcutSelectedWindows[command-WKBD_WINDOW1] = list_cons(sl->head,scr->shortcutSelectedWindows[command-WKBD_WINDOW1]);
1736 sl = sl->tail;
1741 break;
1742 case WKBD_NEXTWSLAYER:
1743 case WKBD_PREVWSLAYER:
1745 int row, column;
1747 row = scr->current_workspace/10;
1748 column = scr->current_workspace%10;
1750 if (command==WKBD_NEXTWSLAYER) {
1751 if ((row+1)*10 < scr->workspace_count)
1752 wWorkspaceChange(scr, column+(row+1)*10);
1753 } else {
1754 if (row > 0)
1755 wWorkspaceChange(scr, column+(row-1)*10);
1758 break;
1759 case WKBD_CLIPLOWER:
1760 if (!wPreferences.flags.noclip)
1761 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1762 break;
1763 case WKBD_CLIPRAISE:
1764 if (!wPreferences.flags.noclip)
1765 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1766 break;
1767 case WKBD_CLIPRAISELOWER:
1768 if (!wPreferences.flags.noclip)
1769 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1770 break;
1771 #ifdef KEEP_XKB_LOCK_STATUS
1772 case WKBD_TOGGLE:
1773 if(wPreferences.modelock) {
1774 /*toggle*/
1775 wwin = scr->focused_window;
1777 if (wwin && wwin->flags.mapped
1778 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1779 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1780 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1782 wwin->frame->languagemode = wwin->frame->last_languagemode;
1783 wwin->frame->last_languagemode = staterec.group;
1784 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1788 break;
1789 #endif /* KEEP_XKB_LOCK_STATUS */
1795 static void
1796 handleMotionNotify(XEvent *event)
1798 WMenu *menu;
1799 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1801 if (wPreferences.scrollable_menus) {
1802 if (scr->flags.jump_back_pending ||
1803 event->xmotion.x_root <= 1 ||
1804 event->xmotion.x_root >= (scr->scr_width - 2) ||
1805 event->xmotion.y_root <= 1 ||
1806 event->xmotion.y_root >= (scr->scr_height - 2)) {
1808 #ifdef DEBUG
1809 puts("pointer at screen edge");
1810 #endif
1812 menu = wMenuUnderPointer(scr);
1813 if (menu!=NULL)
1814 wMenuScroll(menu, event);
1817 #if 0
1818 if (event->xmotion.subwindow == None)
1819 return;
1821 if (scr->scrolledFMaximize != None) {
1822 WWindow *twin;
1824 twin = wWindowFor(scr->scrolledFMaximize);
1825 if (twin && twin->frame_y ==) {
1829 scr->scrolledFMaximize = NULL;
1831 } else {
1833 /* scroll full maximized window */
1834 if (event->xmotion.y_root < 1
1835 || event->xmotion.y_root > scr->scr_height - 1) {
1837 wwin = wWindowFor(event->xmotion.subwindow);
1839 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1840 && WFLAGP(wwin, full_maximize)
1841 && event->xmotion.x_root >= wwin->frame_x
1842 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1844 if (!WFLAGP(wwin, no_titlebar)
1845 && wwin->frame_y <= - wwin->frame->top_width) {
1847 wWindowMove(wwin, wwin->frame_x, 0);
1848 wwin->flags.dragged_while_fmaximized = 0;
1850 } else if (!WFLAGP(wwin, no_resizebar)
1851 && wwin->frame_y + wwin->frame->core->height >=
1852 scr->scr_height + wwin->frame->bottom_width) {
1854 int y = scr->scr_height + wwin->frame->bottom_width;
1856 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1858 wWindowMove(wwin, wwin->frame_x, y);
1859 wwin->flags.dragged_while_fmaximized = 0;
1863 #endif
1867 static void
1868 handleVisibilityNotify(XEvent *event)
1870 WWindow *wwin;
1872 wwin = wWindowFor(event->xvisibility.window);
1873 if (!wwin)
1874 return;
1875 wwin->flags.obscured =
1876 (event->xvisibility.state == VisibilityFullyObscured);