removed MOUSE_WS_bla
[wmaker-crm.git] / src / event.c
blob1db7cbc46d716aa437f12851769e3bf63e9d9f7f
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>
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #ifdef SHAPE
37 # include <X11/extensions/shape.h>
38 #endif
39 #ifdef XDND
40 #include "xdnd.h"
41 #endif
43 #ifdef KEEP_XKB_LOCK_STATUS
44 #include <X11/XKBlib.h>
45 #endif /* KEEP_XKB_LOCK_STATUS */
47 #include "WindowMaker.h"
48 #include "window.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "application.h"
54 #include "stacking.h"
55 #include "defaults.h"
56 #include "workspace.h"
57 #include "dock.h"
58 #include "framewin.h"
59 #include "properties.h"
60 #include "balloon.h"
62 #ifdef GNOME_STUFF
63 # include "gnome.h"
64 #endif
65 #ifdef KWM_HINTS
66 # include "kwm.h"
67 #endif
69 /******** Global Variables **********/
70 extern XContext wWinContext;
72 extern Cursor wCursor[WCUR_LAST];
74 extern WShortKey wKeyBindings[WKBD_LAST];
75 extern int wScreenCount;
76 extern Time LastTimestamp;
77 extern Time LastFocusChange;
79 extern WPreferences wPreferences;
81 #define MOD_MASK wPreferences.modifier_mask
83 extern Atom _XA_WM_COLORMAP_NOTIFY;
85 extern Atom _XA_WM_CHANGE_STATE;
86 extern Atom _XA_WM_DELETE_WINDOW;
87 extern Atom _XA_GNUSTEP_WM_ATTR;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
90 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
91 extern Atom _XA_WINDOWMAKER_COMMAND;
93 #ifdef OFFIX_DND
94 extern Atom _XA_DND_PROTOCOL;
95 #endif
98 #ifdef SHAPE
99 extern Bool wShapeSupported;
100 extern int wShapeEventBase;
101 #endif
103 #ifdef KEEP_XKB_LOCK_STATUS
104 extern int wXkbEventBase;
105 #endif
107 /* special flags */
108 extern char WDelayedActionSet;
111 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent *event);
115 static void handleColormapNotify();
116 static void handleMapNotify(), handleUnmapNotify();
117 static void handleButtonPress(), handleExpose();
118 static void handleDestroyNotify();
119 static void handleConfigureRequest();
120 static void handleMapRequest();
121 static void handlePropertyNotify();
122 static void handleEnterNotify();
123 static void handleLeaveNotify();
124 static void handleExtensions();
125 static void handleClientMessage();
126 static void handleKeyPress();
127 static void handleFocusIn();
128 static void handleMotionNotify();
129 static void handleVisibilityNotify();
132 #ifdef SHAPE
133 static void handleShapeNotify();
134 #endif
136 /* called from the signal handler */
137 void NotifyDeadProcess(pid_t pid, unsigned char status);
139 /* real dead process handler */
140 static void handleDeadProcess(void *foo);
143 typedef struct DeadProcesses {
144 pid_t pid;
145 unsigned char exit_status;
146 } DeadProcesses;
148 /* stack of dead processes */
149 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
150 static int deadProcessPtr=0;
153 typedef struct DeathHandler {
154 WDeathHandler *callback;
155 pid_t pid;
156 void *client_data;
157 } DeathHandler;
159 static WMBag *deathHandlers=NULL;
163 WMagicNumber
164 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
166 DeathHandler *handler;
168 handler = malloc(sizeof(DeathHandler));
169 if (!handler)
170 return 0;
172 handler->pid = pid;
173 handler->callback = callback;
174 handler->client_data = cdata;
176 if (!deathHandlers)
177 deathHandlers = WMCreateBag(8);
179 WMPutInBag(deathHandlers, handler);
181 return handler;
186 void
187 wDeleteDeathHandler(WMagicNumber id)
189 DeathHandler *handler=(DeathHandler*)id;
191 if (!handler || !deathHandlers)
192 return;
194 WMRemoveFromBag(deathHandlers, handler);
196 wfree(handler);
200 void
201 DispatchEvent(XEvent *event)
203 if (deathHandlers)
204 handleDeadProcess(NULL);
206 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
207 WCHANGE_STATE(WSTATE_EXITING);
208 /* received SIGTERM */
210 * WMHandleEvent() can't be called from anything
211 * executed inside here, or we can get in a infinite
212 * recursive loop.
214 Shutdown(WSExitMode);
216 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
217 WCHANGE_STATE(WSTATE_RESTARTING);
219 Shutdown(WSRestartPreparationMode);
220 /* received SIGHUP */
221 Restart(NULL, True);
222 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
223 WCHANGE_STATE(WSTATE_NORMAL);
224 wDefaultsCheckDomains("bla");
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 (!deathHandlers) {
379 deadProcessPtr=0;
380 return;
383 /* get the pids on the queue and call handlers */
384 while (deadProcessPtr>0) {
385 deadProcessPtr--;
387 for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) {
388 tmp = WMGetFromBag(deathHandlers, i);
389 if (!tmp)
390 continue;
392 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
393 (*tmp->callback)(tmp->pid,
394 deadProcesses[deadProcessPtr].exit_status,
395 tmp->client_data);
396 wDeleteDeathHandler(tmp);
403 static void
404 saveTimestamp(XEvent *event)
406 LastTimestamp = CurrentTime;
408 switch (event->type) {
409 case ButtonRelease:
410 case ButtonPress:
411 LastTimestamp = event->xbutton.time;
412 break;
413 case KeyPress:
414 case KeyRelease:
415 LastTimestamp = event->xkey.time;
416 break;
417 case MotionNotify:
418 LastTimestamp = event->xmotion.time;
419 break;
420 case PropertyNotify:
421 LastTimestamp = event->xproperty.time;
422 break;
423 case EnterNotify:
424 case LeaveNotify:
425 LastTimestamp = event->xcrossing.time;
426 break;
427 case SelectionClear:
428 LastTimestamp = event->xselectionclear.time;
429 break;
430 case SelectionRequest:
431 LastTimestamp = event->xselectionrequest.time;
432 break;
433 case SelectionNotify:
434 LastTimestamp = event->xselection.time;
435 #ifdef XDND
436 wXDNDProcessSelection(event);
437 #endif
438 break;
443 static void
444 handleExtensions(XEvent *event)
446 #ifdef KEEP_XKB_LOCK_STATUS
447 XkbEvent *xkbevent;
448 xkbevent = (XkbEvent *)event;
449 #endif /*KEEP_XKB_LOCK_STATUS*/
450 #ifdef SHAPE
451 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
452 handleShapeNotify(event);
454 #endif
455 #ifdef KEEP_XKB_LOCK_STATUS
456 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
457 handleXkbIndicatorStateNotify(event);
459 #endif /*KEEP_XKB_LOCK_STATUS*/
463 static void
464 handleMapRequest(XEvent *ev)
466 WWindow *wwin;
467 WScreen *scr = NULL;
468 Window window = ev->xmaprequest.window;
470 #ifdef DEBUG
471 L("got map request for %x\n", (unsigned)window);
472 #endif
473 if ((wwin = wWindowFor(window))) {
474 if (wwin->flags.shaded) {
475 wUnshadeWindow(wwin);
477 /* deiconify window */
478 if (wwin->flags.miniaturized) {
479 wDeiconifyWindow(wwin);
480 } else if (wwin->flags.hidden) {
481 WApplication *wapp = wApplicationOf(wwin->main_window);
482 /* go to the last workspace that the user worked on the app */
483 if (wapp) {
484 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
486 wUnhideApplication(wapp, False, False);
488 return;
491 scr = wScreenForRootWindow(ev->xmaprequest.parent);
493 wwin = wManageWindow(scr, window);
496 * This is to let the Dock know that the application it launched
497 * has already been mapped (eg: it has finished launching).
498 * It is not necessary for normally docked apps, but is needed for
499 * apps that were forcedly docked (like with dockit).
501 if (scr->last_dock) {
502 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
503 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
504 else
505 wDockTrackWindowLaunch(scr->last_dock, window);
508 if (wwin) {
509 wClientSetState(wwin, NormalState, None);
510 if (wwin->flags.maximized) {
511 wMaximizeWindow(wwin, wwin->flags.maximized);
513 if (wwin->flags.shaded) {
514 wwin->flags.shaded = 0;
515 wwin->flags.skip_next_animation = 1;
516 wShadeWindow(wwin);
518 if (wwin->flags.miniaturized) {
519 wwin->flags.miniaturized = 0;
520 wwin->flags.skip_next_animation = 1;
521 wIconifyWindow(wwin);
523 if (wwin->flags.hidden) {
524 WApplication *wapp = wApplicationOf(wwin->main_window);
526 wwin->flags.hidden = 0;
527 wwin->flags.skip_next_animation = 1;
528 if (wapp) {
529 wHideApplication(wapp);
536 static void
537 handleDestroyNotify(XEvent *event)
539 WWindow *wwin;
540 WApplication *app;
541 Window window = event->xdestroywindow.window;
543 #ifdef DEBUG
544 L("got destroy notify");
545 #endif
546 wwin = wWindowFor(window);
547 if (wwin) {
548 wUnmanageWindow(wwin, False, True);
551 app = wApplicationOf(window);
552 if (app) {
553 if (window == app->main_window) {
554 app->refcount = 0;
555 wwin = app->main_window_desc->screen_ptr->focused_window;
556 while (wwin) {
557 if (wwin->main_window == window) {
558 wwin->main_window = None;
560 wwin = wwin->prev;
563 wApplicationDestroy(app);
566 #ifdef KWM_HINTS
567 wKWMCheckDestroy(&event->xdestroywindow);
568 #endif
573 static void
574 handleExpose(XEvent *event)
576 WObjDescriptor *desc;
577 XEvent ev;
579 #ifdef DEBUG
580 L("got expose");
581 #endif
582 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
584 if (XFindContext(dpy, event->xexpose.window, wWinContext,
585 (XPointer *)&desc)==XCNOENT) {
586 return;
589 if (desc->handle_expose) {
590 (*desc->handle_expose)(desc, event);
594 /* bindable */
595 static void
596 handleButtonPress(XEvent *event)
598 WObjDescriptor *desc;
599 WScreen *scr;
601 #ifdef DEBUG
602 L("got button press");
603 #endif
604 scr = wScreenForRootWindow(event->xbutton.root);
606 #ifdef BALLOON_TEXT
607 wBalloonHide(scr);
608 #endif
611 #ifndef LITE
612 if (event->xbutton.window==scr->root_win) {
613 if (event->xbutton.button==wPreferences.menu_button) {
614 OpenRootMenu(scr, event->xbutton.x_root,
615 event->xbutton.y_root, False);
616 /* ugly hack */
617 if (scr->root_menu) {
618 if (scr->root_menu->brother->flags.mapped)
619 event->xbutton.window = scr->root_menu->brother->frame->core->window;
620 else
621 event->xbutton.window = scr->root_menu->frame->core->window;
623 } else if (event->xbutton.button==wPreferences.windowl_button) {
624 OpenSwitchMenu(scr, event->xbutton.x_root,
625 event->xbutton.y_root, False);
626 if (scr->switch_menu) {
627 if (scr->switch_menu->brother->flags.mapped)
628 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
629 else
630 event->xbutton.window = scr->switch_menu->frame->core->window;
632 } else if (event->xbutton.button==wPreferences.select_button) {
633 wUnselectWindows(scr);
634 wSelectWindows(scr, event);
636 else if (event->xbutton.button==Button5) {
637 wWorkspaceRelativeChange(scr, -1);
638 } else if (event->xbutton.button==Button4) {
639 wWorkspaceRelativeChange(scr, 1);
641 #ifdef GNOME_STUFF
642 else if (wGNOMEProxyizeButtonEvent(scr, event))
643 return;
644 #endif
646 #endif /* !LITE */
648 desc = NULL;
649 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
650 (XPointer *)&desc)==XCNOENT) {
651 if (XFindContext(dpy, event->xbutton.window, wWinContext,
652 (XPointer *)&desc)==XCNOENT) {
653 return;
657 if (desc->parent_type == WCLASS_WINDOW) {
658 XSync(dpy, 0);
660 if (event->xbutton.state & MOD_MASK) {
661 XAllowEvents(dpy, AsyncPointer, CurrentTime);
664 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
665 if (wPreferences.ignore_focus_click) {
666 XAllowEvents(dpy, AsyncPointer, CurrentTime);
668 XAllowEvents(dpy, ReplayPointer, CurrentTime);
669 /* }*/
670 XSync(dpy, 0);
671 } else if (desc->parent_type == WCLASS_APPICON
672 || desc->parent_type == WCLASS_MINIWINDOW
673 || desc->parent_type == WCLASS_DOCK_ICON) {
674 if (event->xbutton.state & MOD_MASK) {
675 XSync(dpy, 0);
676 XAllowEvents(dpy, AsyncPointer, CurrentTime);
677 XSync(dpy, 0);
681 if (desc->handle_mousedown!=NULL) {
682 (*desc->handle_mousedown)(desc, event);
685 /* save double-click information */
686 if (scr->flags.next_click_is_not_double) {
687 scr->flags.next_click_is_not_double = 0;
688 } else {
689 scr->last_click_time = event->xbutton.time;
690 scr->last_click_button = event->xbutton.button;
691 scr->last_click_window = event->xbutton.window;
696 static void
697 handleMapNotify(XEvent *event)
699 WWindow *wwin;
700 #ifdef DEBUG
701 L("got map");
702 #endif
703 wwin = wWindowFor(event->xmap.event);
704 if (wwin && wwin->client_win == event->xmap.event) {
705 if (wwin->flags.miniaturized) {
706 wDeiconifyWindow(wwin);
707 } else {
708 XGrabServer(dpy);
709 wWindowMap(wwin);
710 wClientSetState(wwin, NormalState, None);
711 XUngrabServer(dpy);
717 static void
718 handleUnmapNotify(XEvent *event)
720 WWindow *wwin;
721 XEvent ev;
722 Bool withdraw = False;
723 #ifdef DEBUG
724 L("got unmap");
725 #endif
726 /* only process windows with StructureNotify selected
727 * (ignore SubstructureNotify) */
728 wwin = wWindowFor(event->xunmap.window);
729 if (!wwin)
730 return;
732 /* whether the event is a Withdrawal request */
733 if (event->xunmap.event == wwin->screen_ptr->root_win
734 && event->xunmap.send_event)
735 withdraw = True;
737 if (wwin->client_win != event->xunmap.event && !withdraw)
738 return;
740 if (!wwin->flags.mapped && !withdraw
741 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
742 && !wwin->flags.miniaturized && !wwin->flags.hidden)
743 return;
745 XGrabServer(dpy);
746 XUnmapWindow(dpy, wwin->frame->core->window);
747 wwin->flags.mapped = 0;
748 XSync(dpy, 0);
749 /* check if the window was destroyed */
750 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
751 DispatchEvent(&ev);
752 } else {
753 Bool reparented = False;
755 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
756 reparented = True;
758 /* withdraw window */
759 wwin->flags.mapped = 0;
760 if (!reparented)
761 wClientSetState(wwin, WithdrawnState, None);
763 /* if the window was reparented, do not reparent it back to the
764 * root window */
765 wUnmanageWindow(wwin, !reparented, False);
767 XUngrabServer(dpy);
771 static void
772 handleConfigureRequest(XEvent *event)
774 WWindow *wwin;
775 #ifdef DEBUG
776 L("got configure request");
777 #endif
778 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
780 * Configure request for unmapped window
782 wClientConfigure(NULL, &(event->xconfigurerequest));
783 } else {
784 wClientConfigure(wwin, &(event->xconfigurerequest));
789 static void
790 handlePropertyNotify(XEvent *event)
792 WWindow *wwin;
793 WApplication *wapp;
794 Window jr;
795 int ji;
796 unsigned int ju;
797 WScreen *scr;
798 #ifdef DEBUG
799 L("got property notify");
800 #endif
801 if ((wwin=wWindowFor(event->xproperty.window))) {
802 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
803 &ju, &ju, &ju, &ju)) {
804 return;
806 wClientCheckProperty(wwin, &event->xproperty);
808 wapp = wApplicationOf(event->xproperty.window);
809 if (wapp) {
810 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
813 scr = wScreenForWindow(event->xproperty.window);
814 if (scr && scr->root_win == event->xproperty.window) {
815 #ifdef KWM_HINTS
816 wKWMCheckRootHintChange(scr, &event->xproperty);
817 #endif
822 static void
823 handleClientMessage(XEvent *event)
825 WWindow *wwin;
826 WObjDescriptor *desc;
827 #ifdef DEBUG
828 L("got client message");
829 #endif
830 /* handle transition from Normal to Iconic state */
831 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
832 && event->xclient.format == 32
833 && event->xclient.data.l[0] == IconicState) {
835 wwin = wWindowFor(event->xclient.window);
836 if (!wwin) return;
837 if (!wwin->flags.miniaturized)
838 wIconifyWindow(wwin);
839 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
840 && event->xclient.format == 32) {
841 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
843 if (!scr)
844 return;
846 if (event->xclient.data.l[1] == 1) { /* starting */
847 wColormapAllowClientInstallation(scr, True);
848 } else { /* stopping */
849 wColormapAllowClientInstallation(scr, False);
851 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
853 wDefaultsCheckDomains("bla");
855 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
856 WApplication *wapp;
857 int done=0;
858 wapp = wApplicationOf(event->xclient.window);
859 if (wapp) {
860 switch (event->xclient.data.l[0]) {
861 case WMFHideOtherApplications:
862 wHideOtherApplications(wapp->main_window_desc);
863 done = 1;
864 break;
866 case WMFHideApplication:
867 wHideApplication(wapp);
868 done = 1;
869 break;
872 if (!done) {
873 wwin = wWindowFor(event->xclient.window);
874 if (wwin) {
875 switch (event->xclient.data.l[0]) {
876 case WMFHideOtherApplications:
877 wHideOtherApplications(wwin);
878 break;
880 case WMFHideApplication:
881 wHideApplication(wApplicationOf(wwin->main_window));
882 break;
886 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
887 wwin = wWindowFor(event->xclient.window);
888 if (!wwin) return;
889 switch (event->xclient.data.l[0]) {
890 case GSWindowLevelAttr:
892 int level = (int)event->xclient.data.l[1];
894 if (WINDOW_LEVEL(wwin) != level) {
895 ChangeStackingLevel(wwin->frame->core, level);
898 break;
900 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
901 wwin = wWindowFor(event->xclient.window);
902 if (!wwin) return;
903 switch (event->xclient.data.l[0]) {
904 case WMTitleBarNormal:
905 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
906 break;
907 case WMTitleBarMain:
908 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
909 break;
910 case WMTitleBarKey:
911 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
912 break;
914 #ifdef GNOME_STUFF
915 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
916 /* do nothing */
917 #endif /* GNOME_STUFF */
918 #ifdef KWM_HINTS
919 } else if (wKWMProcessClientMessage(&event->xclient)) {
920 /* do nothing */
921 #endif /* KWM_HINTS */
922 #ifdef XDND
923 } else if (wXDNDProcessClientMessage(&event->xclient)) {
924 /* do nothing */
925 #endif /* XDND */
926 #ifdef OFFIX_DND
927 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
928 WScreen *scr = wScreenForWindow(event->xclient.window);
929 if (scr && wDockReceiveDNDDrop(scr,event))
930 goto redirect_message;
931 #endif /* OFFIX_DND */
932 } else {
933 #ifdef OFFIX_DND
934 redirect_message:
935 #endif
937 * Non-standard thing, but needed by OffiX DND.
938 * For when the icon frame gets a ClientMessage
939 * that should have gone to the icon_window.
941 if (XFindContext(dpy, event->xbutton.window, wWinContext,
942 (XPointer *)&desc)!=XCNOENT) {
943 struct WIcon *icon=NULL;
945 if (desc->parent_type == WCLASS_MINIWINDOW) {
946 icon = (WIcon*)desc->parent;
947 } else if (desc->parent_type == WCLASS_DOCK_ICON
948 || desc->parent_type == WCLASS_APPICON) {
949 icon = ((WAppIcon*)desc->parent)->icon;
951 if (icon && (wwin=icon->owner)) {
952 if (wwin->client_win!=event->xclient.window) {
953 event->xclient.window = wwin->client_win;
954 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
955 event);
963 static void
964 raiseWindow(WScreen *scr)
966 WWindow *wwin;
968 scr->autoRaiseTimer = NULL;
970 wwin = wWindowFor(scr->autoRaiseWindow);
971 if (!wwin)
972 return;
974 if (!wwin->flags.destroyed && wwin->flags.focused) {
975 wRaiseFrame(wwin->frame->core);
976 /* this is needed or a race condition will occur */
977 XSync(dpy, False);
982 static void
983 handleEnterNotify(XEvent *event)
985 WWindow *wwin;
986 WObjDescriptor *desc = NULL;
987 XEvent ev;
988 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
989 #ifdef DEBUG
990 L("got enter notify");
991 #endif
993 #ifdef VIRTUAL_DESKTOP
994 /* TODO: acceleration code */
995 if (wPreferences.vedge_thickness) {
996 int x,y;
997 if (event->xcrossing.window == scr->virtual_edge_r) {
998 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
999 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1000 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1001 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1002 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1003 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1004 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1005 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1006 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1007 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1008 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1009 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1010 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1011 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1012 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1015 #endif
1017 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1018 &ev)) {
1019 /* already left the window... */
1020 saveTimestamp(&ev);
1021 if (ev.xcrossing.mode==event->xcrossing.mode
1022 && ev.xcrossing.detail==event->xcrossing.detail) {
1023 return;
1027 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1028 (XPointer *)&desc)!=XCNOENT) {
1029 if(desc->handle_enternotify)
1030 (*desc->handle_enternotify)(desc, event);
1033 /* enter to window */
1034 wwin = wWindowFor(event->xcrossing.window);
1035 if (!wwin) {
1036 if (wPreferences.focus_mode==WKF_POINTER
1037 && event->xcrossing.window==event->xcrossing.root) {
1038 wSetFocusTo(scr, NULL);
1040 if (wPreferences.colormap_mode==WKF_POINTER) {
1041 wColormapInstallForWindow(scr, NULL);
1043 if (scr->autoRaiseTimer
1044 && event->xcrossing.root==event->xcrossing.window) {
1045 WMDeleteTimerHandler(scr->autoRaiseTimer);
1046 scr->autoRaiseTimer = NULL;
1048 } else {
1049 /* set auto raise timer even if in focus-follows-mouse mode
1050 * and the event is for the frame window, even if the window
1051 * has focus already. useful if you move the pointer from a focused
1052 * window to the root window and back pretty fast
1054 * set focus if in focus-follows-mouse mode and the event
1055 * is for the frame window and window doesn't have focus yet */
1056 if ((wPreferences.focus_mode==WKF_POINTER
1057 || wPreferences.focus_mode==WKF_SLOPPY)
1058 && wwin->frame->core->window==event->xcrossing.window
1059 && !scr->flags.doing_alt_tab) {
1061 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1062 wSetFocusTo(scr, wwin);
1064 if (scr->autoRaiseTimer)
1065 WMDeleteTimerHandler(scr->autoRaiseTimer);
1066 scr->autoRaiseTimer = NULL;
1068 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1069 scr->autoRaiseWindow = wwin->frame->core->window;
1070 scr->autoRaiseTimer
1071 = WMAddTimerHandler(wPreferences.raise_delay,
1072 (WMCallback*)raiseWindow, scr);
1075 /* Install colormap for window, if the colormap installation mode
1076 * is colormap_follows_mouse */
1077 if (wPreferences.colormap_mode==WKF_POINTER) {
1078 if (wwin->client_win==event->xcrossing.window)
1079 wColormapInstallForWindow(scr, wwin);
1080 else
1081 wColormapInstallForWindow(scr, NULL);
1085 /* a little kluge to hide the clip balloon */
1086 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1087 if (!desc) {
1088 XUnmapWindow(dpy, scr->clip_balloon);
1089 scr->flags.clip_balloon_mapped = 0;
1090 } else {
1091 if (desc->parent_type!=WCLASS_DOCK_ICON
1092 || scr->clip_icon != desc->parent) {
1093 XUnmapWindow(dpy, scr->clip_balloon);
1094 scr->flags.clip_balloon_mapped = 0;
1099 if (event->xcrossing.window == event->xcrossing.root
1100 && event->xcrossing.detail == NotifyNormal
1101 && event->xcrossing.detail != NotifyInferior
1102 && wPreferences.focus_mode != WKF_CLICK) {
1104 wSetFocusTo(scr, scr->focused_window);
1107 #ifdef BALLOON_TEXT
1108 wBalloonEnteredObject(scr, desc);
1109 #endif
1113 static void
1114 handleLeaveNotify(XEvent *event)
1116 WObjDescriptor *desc = NULL;
1118 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1119 (XPointer *)&desc)!=XCNOENT) {
1120 if(desc->handle_leavenotify)
1121 (*desc->handle_leavenotify)(desc, event);
1123 if (event->xcrossing.window == event->xcrossing.root
1124 && event->xcrossing.mode == NotifyNormal
1125 && event->xcrossing.detail != NotifyInferior
1126 && wPreferences.focus_mode != WKF_CLICK) {
1128 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1130 wSetFocusTo(scr, NULL);
1135 #ifdef SHAPE
1136 static void
1137 handleShapeNotify(XEvent *event)
1139 XShapeEvent *shev = (XShapeEvent*)event;
1140 WWindow *wwin;
1141 XEvent ev;
1142 #ifdef DEBUG
1143 L("got shape notify");
1144 #endif
1145 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1146 XShapeEvent *sev = (XShapeEvent*)&ev;
1148 if (sev->kind == ShapeBounding) {
1149 if (sev->shaped == shev->shaped) {
1150 *shev = *sev;
1151 } else {
1152 XPutBackEvent(dpy, &ev);
1153 break;
1158 wwin = wWindowFor(shev->window);
1159 if (!wwin || shev->kind != ShapeBounding)
1160 return;
1162 if (!shev->shaped && wwin->flags.shaped) {
1164 wwin->flags.shaped = 0;
1165 wWindowClearShape(wwin);
1167 } else if (shev->shaped) {
1169 wwin->flags.shaped = 1;
1170 wWindowSetShape(wwin);
1173 #endif /* SHAPE */
1175 #ifdef KEEP_XKB_LOCK_STATUS
1176 /* please help ]d if you know what to do */
1177 handleXkbIndicatorStateNotify(XEvent *event)
1179 WWindow *wwin;
1180 WScreen *scr;
1181 XkbStateRec staterec;
1182 int i;
1184 for (i=0; i<wScreenCount; i++) {
1185 scr = wScreenWithNumber(i);
1186 wwin = scr->focused_window;
1187 if (wwin && wwin->flags.focused) {
1188 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1189 if (wwin->frame->languagemode != staterec.group) {
1190 wwin->frame->last_languagemode = wwin->frame->languagemode;
1191 wwin->frame->languagemode = staterec.group;
1193 #ifdef XKB_BUTTON_HINT
1194 if (wwin->frame->titlebar) {
1195 wFrameWindowPaint(wwin->frame);
1197 #endif
1201 #endif /*KEEP_XKB_LOCK_STATUS*/
1203 static void
1204 handleColormapNotify(XEvent *event)
1206 WWindow *wwin;
1207 WScreen *scr;
1208 Bool reinstall = False;
1210 wwin = wWindowFor(event->xcolormap.window);
1211 if (!wwin)
1212 return;
1214 scr = wwin->screen_ptr;
1216 do {
1217 if (wwin) {
1218 if (event->xcolormap.new) {
1219 XWindowAttributes attr;
1221 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1223 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1224 scr->current_colormap = attr.colormap;
1226 reinstall = True;
1227 } else if (event->xcolormap.state == ColormapUninstalled &&
1228 scr->current_colormap == event->xcolormap.colormap) {
1230 /* some bastard app (like XV) removed our colormap */
1232 * can't enforce or things like xscreensaver wont work
1233 * reinstall = True;
1235 } else if (event->xcolormap.state == ColormapInstalled &&
1236 scr->current_colormap == event->xcolormap.colormap) {
1238 /* someone has put our colormap back */
1239 reinstall = False;
1242 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1243 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1245 if (reinstall && scr->current_colormap!=None) {
1246 if (!scr->flags.colormap_stuff_blocked)
1247 XInstallColormap(dpy, scr->current_colormap);
1253 static void
1254 handleFocusIn(XEvent *event)
1256 WWindow *wwin;
1259 * For applications that like stealing the focus.
1261 while (XCheckTypedEvent(dpy, FocusIn, event));
1262 saveTimestamp(event);
1263 if (event->xfocus.mode == NotifyUngrab
1264 || event->xfocus.mode == NotifyGrab
1265 || event->xfocus.detail > NotifyNonlinearVirtual) {
1266 return;
1269 wwin = wWindowFor(event->xfocus.window);
1270 if (wwin && !wwin->flags.focused) {
1271 if (wwin->flags.mapped)
1272 wSetFocusTo(wwin->screen_ptr, wwin);
1273 else
1274 wSetFocusTo(wwin->screen_ptr, NULL);
1275 } else if (!wwin) {
1276 WScreen *scr = wScreenForWindow(event->xfocus.window);
1277 if (scr)
1278 wSetFocusTo(scr, NULL);
1283 static WWindow*
1284 windowUnderPointer(WScreen *scr)
1286 unsigned int mask;
1287 int foo;
1288 Window bar, win;
1290 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1291 &mask))
1292 return wWindowFor(win);
1293 return NULL;
1299 static void
1300 handleKeyPress(XEvent *event)
1302 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1303 WWindow *wwin = scr->focused_window;
1304 int i;
1305 int modifiers;
1306 int command=-1, index;
1307 #ifdef KEEP_XKB_LOCK_STATUS
1308 XkbStateRec staterec;
1309 #endif /*KEEP_XKB_LOCK_STATUS*/
1311 /* ignore CapsLock */
1312 modifiers = event->xkey.state & ValidModMask;
1314 for (i=0; i<WKBD_LAST; i++) {
1315 if (wKeyBindings[i].keycode==0)
1316 continue;
1318 if (wKeyBindings[i].keycode==event->xkey.keycode
1319 && (/*wKeyBindings[i].modifier==0
1320 ||*/ wKeyBindings[i].modifier==modifiers)) {
1321 command = i;
1322 break;
1327 if (command < 0) {
1328 #ifdef LITE
1330 #if 0
1332 #endif
1333 #else
1334 if (!wRootMenuPerformShortcut(event)) {
1335 #endif
1336 static int dontLoop = 0;
1338 if (dontLoop > 10) {
1339 wwarning("problem with key event processing code");
1340 return;
1342 dontLoop++;
1343 /* if the focused window is an internal window, try redispatching
1344 * the event to the managed window, as it can be a WINGs window */
1345 if (wwin && wwin->flags.internal_window
1346 && wwin->client_leader!=None) {
1347 /* client_leader contains the WINGs toplevel */
1348 event->xany.window = wwin->client_leader;
1349 WMHandleEvent(event);
1351 dontLoop--;
1353 return;
1356 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1357 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1359 switch (command) {
1360 #ifndef LITE
1361 case WKBD_ROOTMENU:
1362 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1363 break;
1364 case WKBD_WINDOWLIST:
1365 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1366 break;
1367 #endif /* !LITE */
1368 case WKBD_WINDOWMENU:
1369 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1370 OpenWindowMenu(wwin, wwin->frame_x,
1371 wwin->frame_y+wwin->frame->top_width, True);
1372 break;
1373 case WKBD_MINIATURIZE:
1374 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1375 && !WFLAGP(wwin, no_miniaturizable)) {
1376 CloseWindowMenu(scr);
1378 if (wwin->protocols.MINIATURIZE_WINDOW)
1379 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1380 event->xbutton.time);
1381 else {
1382 wIconifyWindow(wwin);
1385 break;
1386 case WKBD_HIDE:
1387 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1388 WApplication *wapp = wApplicationOf(wwin->main_window);
1389 CloseWindowMenu(scr);
1391 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1392 wHideApplication(wapp);
1395 break;
1396 case WKBD_MAXIMIZE:
1397 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1398 CloseWindowMenu(scr);
1400 if (wwin->flags.maximized) {
1401 wUnmaximizeWindow(wwin);
1402 } else {
1403 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1406 break;
1407 case WKBD_VMAXIMIZE:
1408 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1409 CloseWindowMenu(scr);
1411 if (wwin->flags.maximized) {
1412 wUnmaximizeWindow(wwin);
1413 } else {
1414 wMaximizeWindow(wwin, MAX_VERTICAL);
1417 break;
1418 case WKBD_RAISE:
1419 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1420 CloseWindowMenu(scr);
1422 wRaiseFrame(wwin->frame->core);
1424 break;
1425 case WKBD_LOWER:
1426 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1427 CloseWindowMenu(scr);
1429 wLowerFrame(wwin->frame->core);
1431 break;
1432 case WKBD_RAISELOWER:
1433 /* raise or lower the window under the pointer, not the
1434 * focused one
1436 wwin = windowUnderPointer(scr);
1437 if (wwin)
1438 wRaiseLowerFrame(wwin->frame->core);
1439 break;
1440 case WKBD_SHADE:
1441 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1442 if (wwin->flags.shaded)
1443 wUnshadeWindow(wwin);
1444 else
1445 wShadeWindow(wwin);
1447 break;
1448 case WKBD_MOVERESIZE:
1449 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1450 CloseWindowMenu(scr);
1452 wKeyboardMoveResizeWindow(wwin);
1454 break;
1455 case WKBD_CLOSE:
1456 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1457 CloseWindowMenu(scr);
1458 if (wwin->protocols.DELETE_WINDOW)
1459 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1460 event->xkey.time);
1462 break;
1463 case WKBD_SELECT:
1464 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1465 wSelectWindow(wwin, !wwin->flags.selected);
1467 break;
1468 case WKBD_FOCUSNEXT:
1469 StartWindozeCycle(wwin, event, True);
1470 break;
1472 case WKBD_FOCUSPREV:
1473 StartWindozeCycle(wwin, event, False);
1474 break;
1476 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1477 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1478 i = (scr->current_workspace/10)*10 + wk - 1;\
1479 if (wPreferences.ws_advance || i<scr->workspace_count)\
1480 wWorkspaceChange(scr, i);\
1481 break
1482 #else
1483 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1484 i = (scr->current_workspace/10)*10 + wk - 1;\
1485 if (wPreferences.ws_advance || i<scr->workspace_count)\
1486 wWorkspaceChange(scr, i);\
1487 break
1488 #endif
1489 GOTOWORKS(1);
1490 GOTOWORKS(2);
1491 GOTOWORKS(3);
1492 GOTOWORKS(4);
1493 GOTOWORKS(5);
1494 GOTOWORKS(6);
1495 GOTOWORKS(7);
1496 GOTOWORKS(8);
1497 GOTOWORKS(9);
1498 GOTOWORKS(10);
1499 #undef GOTOWORKS
1500 case WKBD_NEXTWORKSPACE:
1501 wWorkspaceRelativeChange(scr, 1);
1502 break;
1503 case WKBD_PREVWORKSPACE:
1504 wWorkspaceRelativeChange(scr, -1);
1505 break;
1506 case WKBD_WINDOW1:
1507 case WKBD_WINDOW2:
1508 case WKBD_WINDOW3:
1509 case WKBD_WINDOW4:
1510 case WKBD_WINDOW5:
1511 case WKBD_WINDOW6:
1512 case WKBD_WINDOW7:
1513 case WKBD_WINDOW8:
1514 case WKBD_WINDOW9:
1515 case WKBD_WINDOW10:
1517 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1519 index = command-WKBD_WINDOW1;
1521 if (scr->shortcutWindows[index]) {
1522 WMBag *list = scr->shortcutWindows[index];
1523 int cw;
1524 int count = WMGetBagItemCount(list);
1525 WWindow *twin;
1526 WMBagIterator iter;
1527 WWindow *wwin;
1529 wUnselectWindows(scr);
1530 cw = scr->current_workspace;
1532 for (wwin = WMBagLast(list, &iter);
1533 iter != NULL;
1534 wwin = WMBagPrevious(list, &iter)) {
1536 if (count > 1)
1537 wWindowChangeWorkspace(wwin, cw);
1539 wMakeWindowVisible(wwin);
1541 if (count > 1)
1542 wSelectWindow(wwin, True);
1545 /* rotate the order of windows, to create a cycling effect */
1546 twin = WMBagFirst(list, &iter);
1547 WMRemoveFromBag(list, twin);
1548 WMPutInBag(list, twin);
1550 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1552 INITBAG(scr->shortcutWindows[index]);
1553 WMPutInBag(scr->shortcutWindows[index], wwin);
1555 if (wwin->flags.selected && scr->selected_windows) {
1556 WMBag *selwins = scr->selected_windows;
1557 int i;
1559 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1560 WWindow *tmp = WMGetFromBag(selwins, i);
1562 if (tmp != wwin)
1563 WMPutInBag(scr->shortcutWindows[index], tmp);
1566 wSelectWindow(wwin, !wwin->flags.selected);
1567 XFlush(dpy);
1568 wusleep(3000);
1569 wSelectWindow(wwin, !wwin->flags.selected);
1570 XFlush(dpy);
1572 } else if (scr->selected_windows
1573 && WMGetBagItemCount(scr->selected_windows)) {
1575 if (wwin->flags.selected && scr->selected_windows) {
1576 WMBag *selwins = scr->selected_windows;
1577 int i;
1579 INITBAG(scr->shortcutWindows[index]);
1581 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1582 WWindow *tmp = WMGetFromBag(selwins, i);
1584 WMPutInBag(scr->shortcutWindows[index], tmp);
1588 #undef INITBAG
1590 break;
1592 case WKBD_SWITCH_SCREEN:
1593 if (wScreenCount > 1) {
1594 WScreen *scr2;
1595 int i;
1597 /* find index of this screen */
1598 for (i = 0; i < wScreenCount; i++) {
1599 if (wScreenWithNumber(i) == scr)
1600 break;
1602 i++;
1603 if (i >= wScreenCount) {
1604 i = 0;
1606 scr2 = wScreenWithNumber(i);
1608 if (scr2) {
1609 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1610 scr2->scr_width/2, scr2->scr_height/2);
1613 break;
1615 case WKBD_NEXTWSLAYER:
1616 case WKBD_PREVWSLAYER:
1618 int row, column;
1620 row = scr->current_workspace/10;
1621 column = scr->current_workspace%10;
1623 if (command==WKBD_NEXTWSLAYER) {
1624 if ((row+1)*10 < scr->workspace_count)
1625 wWorkspaceChange(scr, column+(row+1)*10);
1626 } else {
1627 if (row > 0)
1628 wWorkspaceChange(scr, column+(row-1)*10);
1631 break;
1632 case WKBD_CLIPLOWER:
1633 if (!wPreferences.flags.noclip)
1634 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1635 break;
1636 case WKBD_CLIPRAISE:
1637 if (!wPreferences.flags.noclip)
1638 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1639 break;
1640 case WKBD_CLIPRAISELOWER:
1641 if (!wPreferences.flags.noclip)
1642 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1643 break;
1644 #ifdef KEEP_XKB_LOCK_STATUS
1645 case WKBD_TOGGLE:
1646 if(wPreferences.modelock) {
1647 /*toggle*/
1648 wwin = scr->focused_window;
1650 if (wwin && wwin->flags.mapped
1651 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1652 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1653 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1655 wwin->frame->languagemode = wwin->frame->last_languagemode;
1656 wwin->frame->last_languagemode = staterec.group;
1657 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1661 break;
1662 #endif /* KEEP_XKB_LOCK_STATUS */
1668 static void
1669 handleMotionNotify(XEvent *event)
1671 WMenu *menu;
1672 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1674 if (wPreferences.scrollable_menus) {
1675 if (scr->flags.jump_back_pending ||
1676 event->xmotion.x_root <= 1 ||
1677 event->xmotion.x_root >= (scr->scr_width - 2) ||
1678 event->xmotion.y_root <= 1 ||
1679 event->xmotion.y_root >= (scr->scr_height - 2)) {
1680 #ifdef DEBUG
1681 L("pointer at screen edge");
1682 #endif
1683 menu = wMenuUnderPointer(scr);
1684 if (menu!=NULL)
1685 wMenuScroll(menu, event);
1688 #if 0
1689 if (event->xmotion.subwindow == None)
1690 return;
1692 if (scr->scrolledFMaximize != None) {
1693 WWindow *twin;
1695 twin = wWindowFor(scr->scrolledFMaximize);
1696 if (twin && twin->frame_y ==) {
1700 scr->scrolledFMaximize = NULL;
1702 } else {
1704 /* scroll full maximized window */
1705 if (event->xmotion.y_root < 1
1706 || event->xmotion.y_root > scr->scr_height - 1) {
1708 wwin = wWindowFor(event->xmotion.subwindow);
1710 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1711 && WFLAGP(wwin, full_maximize)
1712 && event->xmotion.x_root >= wwin->frame_x
1713 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1715 if (!WFLAGP(wwin, no_titlebar)
1716 && wwin->frame_y <= - wwin->frame->top_width) {
1718 wWindowMove(wwin, wwin->frame_x, 0);
1719 wwin->flags.dragged_while_fmaximized = 0;
1721 } else if (!WFLAGP(wwin, no_resizebar)
1722 && wwin->frame_y + wwin->frame->core->height >=
1723 scr->scr_height + wwin->frame->bottom_width) {
1725 int y = scr->scr_height + wwin->frame->bottom_width;
1727 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1729 wWindowMove(wwin, wwin->frame_x, y);
1730 wwin->flags.dragged_while_fmaximized = 0;
1734 #endif
1738 static void
1739 handleVisibilityNotify(XEvent *event)
1741 WWindow *wwin;
1743 wwin = wWindowFor(event->xvisibility.window);
1744 if (!wwin)
1745 return;
1746 wwin->flags.obscured =
1747 (event->xvisibility.state == VisibilityFullyObscured);