new appicon grouping stuff
[wmaker-crm.git] / src / event.c
blob04a8621eeddc3e381976ca2e641b486f38a6cb92
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 #ifdef MOUSE_WS_SWITCH
637 else if (event->xbutton.button==Button5) {
638 wWorkspaceRelativeChange(scr, -1);
639 } else if (event->xbutton.button==Button4) {
640 wWorkspaceRelativeChange(scr, 1);
642 #endif /* MOUSE_WS_SWITCH */
643 #ifdef GNOME_STUFF
644 else if (wGNOMEProxyizeButtonEvent(scr, event))
645 return;
646 #endif
648 #endif /* !LITE */
650 desc = NULL;
651 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
652 (XPointer *)&desc)==XCNOENT) {
653 if (XFindContext(dpy, event->xbutton.window, wWinContext,
654 (XPointer *)&desc)==XCNOENT) {
655 return;
659 if (desc->parent_type == WCLASS_WINDOW) {
660 XSync(dpy, 0);
662 if (event->xbutton.state & MOD_MASK) {
663 XAllowEvents(dpy, AsyncPointer, CurrentTime);
666 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
667 if (wPreferences.ignore_focus_click) {
668 XAllowEvents(dpy, AsyncPointer, CurrentTime);
670 XAllowEvents(dpy, ReplayPointer, CurrentTime);
671 /* }*/
672 XSync(dpy, 0);
673 } else if (desc->parent_type == WCLASS_APPICON
674 || desc->parent_type == WCLASS_MINIWINDOW
675 || desc->parent_type == WCLASS_DOCK_ICON) {
676 if (event->xbutton.state & MOD_MASK) {
677 XSync(dpy, 0);
678 XAllowEvents(dpy, AsyncPointer, CurrentTime);
679 XSync(dpy, 0);
683 if (desc->handle_mousedown!=NULL) {
684 (*desc->handle_mousedown)(desc, event);
687 /* save double-click information */
688 if (scr->flags.next_click_is_not_double) {
689 scr->flags.next_click_is_not_double = 0;
690 } else {
691 scr->last_click_time = event->xbutton.time;
692 scr->last_click_button = event->xbutton.button;
693 scr->last_click_window = event->xbutton.window;
698 static void
699 handleMapNotify(XEvent *event)
701 WWindow *wwin;
702 #ifdef DEBUG
703 L("got map");
704 #endif
705 wwin = wWindowFor(event->xmap.event);
706 if (wwin && wwin->client_win == event->xmap.event) {
707 if (wwin->flags.miniaturized) {
708 wDeiconifyWindow(wwin);
709 } else {
710 XGrabServer(dpy);
711 wWindowMap(wwin);
712 wClientSetState(wwin, NormalState, None);
713 XUngrabServer(dpy);
719 static void
720 handleUnmapNotify(XEvent *event)
722 WWindow *wwin;
723 XEvent ev;
724 Bool withdraw = False;
725 #ifdef DEBUG
726 L("got unmap");
727 #endif
728 /* only process windows with StructureNotify selected
729 * (ignore SubstructureNotify) */
730 wwin = wWindowFor(event->xunmap.window);
731 if (!wwin)
732 return;
734 /* whether the event is a Withdrawal request */
735 if (event->xunmap.event == wwin->screen_ptr->root_win
736 && event->xunmap.send_event)
737 withdraw = True;
739 if (wwin->client_win != event->xunmap.event && !withdraw)
740 return;
742 if (!wwin->flags.mapped && !withdraw
743 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
744 && !wwin->flags.miniaturized && !wwin->flags.hidden)
745 return;
747 XGrabServer(dpy);
748 XUnmapWindow(dpy, wwin->frame->core->window);
749 wwin->flags.mapped = 0;
750 XSync(dpy, 0);
751 /* check if the window was destroyed */
752 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
753 DispatchEvent(&ev);
754 } else {
755 Bool reparented = False;
757 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
758 reparented = True;
760 /* withdraw window */
761 wwin->flags.mapped = 0;
762 if (!reparented)
763 wClientSetState(wwin, WithdrawnState, None);
765 /* if the window was reparented, do not reparent it back to the
766 * root window */
767 wUnmanageWindow(wwin, !reparented, False);
769 XUngrabServer(dpy);
773 static void
774 handleConfigureRequest(XEvent *event)
776 WWindow *wwin;
777 #ifdef DEBUG
778 L("got configure request");
779 #endif
780 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
782 * Configure request for unmapped window
784 wClientConfigure(NULL, &(event->xconfigurerequest));
785 } else {
786 wClientConfigure(wwin, &(event->xconfigurerequest));
791 static void
792 handlePropertyNotify(XEvent *event)
794 WWindow *wwin;
795 WApplication *wapp;
796 Window jr;
797 int ji;
798 unsigned int ju;
799 WScreen *scr;
800 #ifdef DEBUG
801 L("got property notify");
802 #endif
803 if ((wwin=wWindowFor(event->xproperty.window))) {
804 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
805 &ju, &ju, &ju, &ju)) {
806 return;
808 wClientCheckProperty(wwin, &event->xproperty);
810 wapp = wApplicationOf(event->xproperty.window);
811 if (wapp) {
812 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
815 scr = wScreenForWindow(event->xproperty.window);
816 if (scr && scr->root_win == event->xproperty.window) {
817 #ifdef KWM_HINTS
818 wKWMCheckRootHintChange(scr, &event->xproperty);
819 #endif
824 static void
825 handleClientMessage(XEvent *event)
827 WWindow *wwin;
828 WObjDescriptor *desc;
829 #ifdef DEBUG
830 L("got client message");
831 #endif
832 /* handle transition from Normal to Iconic state */
833 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
834 && event->xclient.format == 32
835 && event->xclient.data.l[0] == IconicState) {
837 wwin = wWindowFor(event->xclient.window);
838 if (!wwin) return;
839 if (!wwin->flags.miniaturized)
840 wIconifyWindow(wwin);
841 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
842 && event->xclient.format == 32) {
843 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
845 if (!scr)
846 return;
848 if (event->xclient.data.l[1] == 1) { /* starting */
849 wColormapAllowClientInstallation(scr, True);
850 } else { /* stopping */
851 wColormapAllowClientInstallation(scr, False);
853 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
855 wDefaultsCheckDomains("bla");
857 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
858 WApplication *wapp;
859 int done=0;
860 wapp = wApplicationOf(event->xclient.window);
861 if (wapp) {
862 switch (event->xclient.data.l[0]) {
863 case WMFHideOtherApplications:
864 wHideOtherApplications(wapp->main_window_desc);
865 done = 1;
866 break;
868 case WMFHideApplication:
869 wHideApplication(wapp);
870 done = 1;
871 break;
874 if (!done) {
875 wwin = wWindowFor(event->xclient.window);
876 if (wwin) {
877 switch (event->xclient.data.l[0]) {
878 case WMFHideOtherApplications:
879 wHideOtherApplications(wwin);
880 break;
882 case WMFHideApplication:
883 wHideApplication(wApplicationOf(wwin->main_window));
884 break;
888 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
889 wwin = wWindowFor(event->xclient.window);
890 if (!wwin) return;
891 switch (event->xclient.data.l[0]) {
892 case GSWindowLevelAttr:
894 int level = (int)event->xclient.data.l[1];
896 if (WINDOW_LEVEL(wwin) != level) {
897 ChangeStackingLevel(wwin->frame->core, level);
900 break;
902 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
903 wwin = wWindowFor(event->xclient.window);
904 if (!wwin) return;
905 switch (event->xclient.data.l[0]) {
906 case WMTitleBarNormal:
907 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
908 break;
909 case WMTitleBarMain:
910 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
911 break;
912 case WMTitleBarKey:
913 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
914 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 && wwin->flags.focused) {
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);
991 #ifdef DEBUG
992 L("got enter notify");
993 #endif
995 #ifdef VIRTUAL_DESKTOP
996 /* TODO: acceleration code */
997 if (wPreferences.vedge_thickness) {
998 int x,y;
999 if (event->xcrossing.window == scr->virtual_edge_r) {
1000 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1001 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1002 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1003 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1004 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1005 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1006 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1007 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1008 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1009 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1010 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1011 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1012 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1013 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1014 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1017 #endif
1019 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1020 &ev)) {
1021 /* already left the window... */
1022 saveTimestamp(&ev);
1023 if (ev.xcrossing.mode==event->xcrossing.mode
1024 && ev.xcrossing.detail==event->xcrossing.detail) {
1025 return;
1029 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1030 (XPointer *)&desc)!=XCNOENT) {
1031 if(desc->handle_enternotify)
1032 (*desc->handle_enternotify)(desc, event);
1035 /* enter to window */
1036 wwin = wWindowFor(event->xcrossing.window);
1037 if (!wwin) {
1038 if (wPreferences.focus_mode==WKF_POINTER
1039 && event->xcrossing.window==event->xcrossing.root) {
1040 wSetFocusTo(scr, NULL);
1042 if (wPreferences.colormap_mode==WKF_POINTER) {
1043 wColormapInstallForWindow(scr, NULL);
1045 if (scr->autoRaiseTimer
1046 && event->xcrossing.root==event->xcrossing.window) {
1047 WMDeleteTimerHandler(scr->autoRaiseTimer);
1048 scr->autoRaiseTimer = NULL;
1050 } else {
1051 /* set auto raise timer even if in focus-follows-mouse mode
1052 * and the event is for the frame window, even if the window
1053 * has focus already. useful if you move the pointer from a focused
1054 * window to the root window and back pretty fast
1056 * set focus if in focus-follows-mouse mode and the event
1057 * is for the frame window and window doesn't have focus yet */
1058 if ((wPreferences.focus_mode==WKF_POINTER
1059 || wPreferences.focus_mode==WKF_SLOPPY)
1060 && wwin->frame->core->window==event->xcrossing.window
1061 && !scr->flags.doing_alt_tab) {
1063 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1064 wSetFocusTo(scr, wwin);
1066 if (scr->autoRaiseTimer)
1067 WMDeleteTimerHandler(scr->autoRaiseTimer);
1068 scr->autoRaiseTimer = NULL;
1070 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1071 scr->autoRaiseWindow = wwin->frame->core->window;
1072 scr->autoRaiseTimer
1073 = WMAddTimerHandler(wPreferences.raise_delay,
1074 (WMCallback*)raiseWindow, scr);
1077 /* Install colormap for window, if the colormap installation mode
1078 * is colormap_follows_mouse */
1079 if (wPreferences.colormap_mode==WKF_POINTER) {
1080 if (wwin->client_win==event->xcrossing.window)
1081 wColormapInstallForWindow(scr, wwin);
1082 else
1083 wColormapInstallForWindow(scr, NULL);
1087 /* a little kluge to hide the clip balloon */
1088 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1089 if (!desc) {
1090 XUnmapWindow(dpy, scr->clip_balloon);
1091 scr->flags.clip_balloon_mapped = 0;
1092 } else {
1093 if (desc->parent_type!=WCLASS_DOCK_ICON
1094 || scr->clip_icon != desc->parent) {
1095 XUnmapWindow(dpy, scr->clip_balloon);
1096 scr->flags.clip_balloon_mapped = 0;
1101 if (event->xcrossing.window == event->xcrossing.root
1102 && event->xcrossing.detail == NotifyNormal
1103 && event->xcrossing.detail != NotifyInferior
1104 && wPreferences.focus_mode != WKF_CLICK) {
1106 wSetFocusTo(scr, scr->focused_window);
1109 #ifdef BALLOON_TEXT
1110 wBalloonEnteredObject(scr, desc);
1111 #endif
1115 static void
1116 handleLeaveNotify(XEvent *event)
1118 WObjDescriptor *desc = NULL;
1120 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1121 (XPointer *)&desc)!=XCNOENT) {
1122 if(desc->handle_leavenotify)
1123 (*desc->handle_leavenotify)(desc, event);
1125 if (event->xcrossing.window == event->xcrossing.root
1126 && event->xcrossing.mode == NotifyNormal
1127 && event->xcrossing.detail != NotifyInferior
1128 && wPreferences.focus_mode != WKF_CLICK) {
1130 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1132 wSetFocusTo(scr, NULL);
1137 #ifdef SHAPE
1138 static void
1139 handleShapeNotify(XEvent *event)
1141 XShapeEvent *shev = (XShapeEvent*)event;
1142 WWindow *wwin;
1143 XEvent ev;
1144 #ifdef DEBUG
1145 L("got shape notify");
1146 #endif
1147 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1148 XShapeEvent *sev = (XShapeEvent*)&ev;
1150 if (sev->kind == ShapeBounding) {
1151 if (sev->shaped == shev->shaped) {
1152 *shev = *sev;
1153 } else {
1154 XPutBackEvent(dpy, &ev);
1155 break;
1160 wwin = wWindowFor(shev->window);
1161 if (!wwin || shev->kind != ShapeBounding)
1162 return;
1164 if (!shev->shaped && wwin->flags.shaped) {
1166 wwin->flags.shaped = 0;
1167 wWindowClearShape(wwin);
1169 } else if (shev->shaped) {
1171 wwin->flags.shaped = 1;
1172 wWindowSetShape(wwin);
1175 #endif /* SHAPE */
1177 #ifdef KEEP_XKB_LOCK_STATUS
1178 /* please help ]d if you know what to do */
1179 handleXkbIndicatorStateNotify(XEvent *event)
1181 WWindow *wwin;
1182 WScreen *scr;
1183 XkbStateRec staterec;
1184 int i;
1186 for (i=0; i<wScreenCount; i++) {
1187 scr = wScreenWithNumber(i);
1188 wwin = scr->focused_window;
1189 if (wwin && wwin->flags.focused) {
1190 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1191 if (wwin->frame->languagemode != staterec.group) {
1192 wwin->frame->last_languagemode = wwin->frame->languagemode;
1193 wwin->frame->languagemode = staterec.group;
1195 #ifdef XKB_BUTTON_HINT
1196 if (wwin->frame->titlebar) {
1197 wFrameWindowPaint(wwin->frame);
1199 #endif
1203 #endif /*KEEP_XKB_LOCK_STATUS*/
1205 static void
1206 handleColormapNotify(XEvent *event)
1208 WWindow *wwin;
1209 WScreen *scr;
1210 Bool reinstall = False;
1212 wwin = wWindowFor(event->xcolormap.window);
1213 if (!wwin)
1214 return;
1216 scr = wwin->screen_ptr;
1218 do {
1219 if (wwin) {
1220 if (event->xcolormap.new) {
1221 XWindowAttributes attr;
1223 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1225 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1226 scr->current_colormap = attr.colormap;
1228 reinstall = True;
1229 } else if (event->xcolormap.state == ColormapUninstalled &&
1230 scr->current_colormap == event->xcolormap.colormap) {
1232 /* some bastard app (like XV) removed our colormap */
1234 * can't enforce or things like xscreensaver wont work
1235 * reinstall = True;
1237 } else if (event->xcolormap.state == ColormapInstalled &&
1238 scr->current_colormap == event->xcolormap.colormap) {
1240 /* someone has put our colormap back */
1241 reinstall = False;
1244 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1245 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1247 if (reinstall && scr->current_colormap!=None) {
1248 if (!scr->flags.colormap_stuff_blocked)
1249 XInstallColormap(dpy, scr->current_colormap);
1255 static void
1256 handleFocusIn(XEvent *event)
1258 WWindow *wwin;
1261 * For applications that like stealing the focus.
1263 while (XCheckTypedEvent(dpy, FocusIn, event));
1264 saveTimestamp(event);
1265 if (event->xfocus.mode == NotifyUngrab
1266 || event->xfocus.mode == NotifyGrab
1267 || event->xfocus.detail > NotifyNonlinearVirtual) {
1268 return;
1271 wwin = wWindowFor(event->xfocus.window);
1272 if (wwin && !wwin->flags.focused) {
1273 if (wwin->flags.mapped)
1274 wSetFocusTo(wwin->screen_ptr, wwin);
1275 else
1276 wSetFocusTo(wwin->screen_ptr, NULL);
1277 } else if (!wwin) {
1278 WScreen *scr = wScreenForWindow(event->xfocus.window);
1279 if (scr)
1280 wSetFocusTo(scr, NULL);
1285 static WWindow*
1286 windowUnderPointer(WScreen *scr)
1288 unsigned int mask;
1289 int foo;
1290 Window bar, win;
1292 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1293 &mask))
1294 return wWindowFor(win);
1295 return NULL;
1301 static void
1302 handleKeyPress(XEvent *event)
1304 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1305 WWindow *wwin = scr->focused_window;
1306 int i;
1307 int modifiers;
1308 int command=-1, index;
1309 #ifdef KEEP_XKB_LOCK_STATUS
1310 XkbStateRec staterec;
1311 #endif /*KEEP_XKB_LOCK_STATUS*/
1313 /* ignore CapsLock */
1314 modifiers = event->xkey.state & ValidModMask;
1316 for (i=0; i<WKBD_LAST; i++) {
1317 if (wKeyBindings[i].keycode==0)
1318 continue;
1320 if (wKeyBindings[i].keycode==event->xkey.keycode
1321 && (/*wKeyBindings[i].modifier==0
1322 ||*/ wKeyBindings[i].modifier==modifiers)) {
1323 command = i;
1324 break;
1329 if (command < 0) {
1330 #ifdef LITE
1332 #if 0
1334 #endif
1335 #else
1336 if (!wRootMenuPerformShortcut(event)) {
1337 #endif
1338 static int dontLoop = 0;
1340 if (dontLoop > 10) {
1341 wwarning("problem with key event processing code");
1342 return;
1344 dontLoop++;
1345 /* if the focused window is an internal window, try redispatching
1346 * the event to the managed window, as it can be a WINGs window */
1347 if (wwin && wwin->flags.internal_window
1348 && wwin->client_leader!=None) {
1349 /* client_leader contains the WINGs toplevel */
1350 event->xany.window = wwin->client_leader;
1351 WMHandleEvent(event);
1353 dontLoop--;
1355 return;
1358 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1359 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1361 switch (command) {
1362 #ifndef LITE
1363 case WKBD_ROOTMENU:
1364 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1365 break;
1366 case WKBD_WINDOWLIST:
1367 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1368 break;
1369 #endif /* !LITE */
1370 case WKBD_WINDOWMENU:
1371 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1372 OpenWindowMenu(wwin, wwin->frame_x,
1373 wwin->frame_y+wwin->frame->top_width, True);
1374 break;
1375 case WKBD_MINIATURIZE:
1376 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1377 && !WFLAGP(wwin, no_miniaturizable)) {
1378 CloseWindowMenu(scr);
1380 if (wwin->protocols.MINIATURIZE_WINDOW)
1381 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1382 event->xbutton.time);
1383 else {
1384 wIconifyWindow(wwin);
1387 break;
1388 case WKBD_HIDE:
1389 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1390 WApplication *wapp = wApplicationOf(wwin->main_window);
1391 CloseWindowMenu(scr);
1393 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1394 wHideApplication(wapp);
1397 break;
1398 case WKBD_MAXIMIZE:
1399 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1400 CloseWindowMenu(scr);
1402 if (wwin->flags.maximized) {
1403 wUnmaximizeWindow(wwin);
1404 } else {
1405 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1408 break;
1409 case WKBD_VMAXIMIZE:
1410 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1411 CloseWindowMenu(scr);
1413 if (wwin->flags.maximized) {
1414 wUnmaximizeWindow(wwin);
1415 } else {
1416 wMaximizeWindow(wwin, MAX_VERTICAL);
1419 break;
1420 case WKBD_RAISE:
1421 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1422 CloseWindowMenu(scr);
1424 wRaiseFrame(wwin->frame->core);
1426 break;
1427 case WKBD_LOWER:
1428 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1429 CloseWindowMenu(scr);
1431 wLowerFrame(wwin->frame->core);
1433 break;
1434 case WKBD_RAISELOWER:
1435 /* raise or lower the window under the pointer, not the
1436 * focused one
1438 wwin = windowUnderPointer(scr);
1439 if (wwin)
1440 wRaiseLowerFrame(wwin->frame->core);
1441 break;
1442 case WKBD_SHADE:
1443 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1444 if (wwin->flags.shaded)
1445 wUnshadeWindow(wwin);
1446 else
1447 wShadeWindow(wwin);
1449 break;
1450 case WKBD_MOVERESIZE:
1451 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1452 CloseWindowMenu(scr);
1454 wKeyboardMoveResizeWindow(wwin);
1456 break;
1457 case WKBD_CLOSE:
1458 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1459 CloseWindowMenu(scr);
1460 if (wwin->protocols.DELETE_WINDOW)
1461 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1462 event->xkey.time);
1464 break;
1465 case WKBD_SELECT:
1466 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1467 wSelectWindow(wwin, !wwin->flags.selected);
1469 break;
1470 case WKBD_FOCUSNEXT:
1471 StartWindozeCycle(wwin, event, True);
1472 break;
1474 case WKBD_FOCUSPREV:
1475 StartWindozeCycle(wwin, event, False);
1476 break;
1478 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1479 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1480 i = (scr->current_workspace/10)*10 + wk - 1;\
1481 if (wPreferences.ws_advance || i<scr->workspace_count)\
1482 wWorkspaceChange(scr, i);\
1483 break
1484 #else
1485 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1486 i = (scr->current_workspace/10)*10 + wk - 1;\
1487 if (wPreferences.ws_advance || i<scr->workspace_count)\
1488 wWorkspaceChange(scr, i);\
1489 break
1490 #endif
1491 GOTOWORKS(1);
1492 GOTOWORKS(2);
1493 GOTOWORKS(3);
1494 GOTOWORKS(4);
1495 GOTOWORKS(5);
1496 GOTOWORKS(6);
1497 GOTOWORKS(7);
1498 GOTOWORKS(8);
1499 GOTOWORKS(9);
1500 GOTOWORKS(10);
1501 #undef GOTOWORKS
1502 case WKBD_NEXTWORKSPACE:
1503 wWorkspaceRelativeChange(scr, 1);
1504 break;
1505 case WKBD_PREVWORKSPACE:
1506 wWorkspaceRelativeChange(scr, -1);
1507 break;
1508 case WKBD_WINDOW1:
1509 case WKBD_WINDOW2:
1510 case WKBD_WINDOW3:
1511 case WKBD_WINDOW4:
1512 case WKBD_WINDOW5:
1513 case WKBD_WINDOW6:
1514 case WKBD_WINDOW7:
1515 case WKBD_WINDOW8:
1516 case WKBD_WINDOW9:
1517 case WKBD_WINDOW10:
1519 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1521 index = command-WKBD_WINDOW1;
1523 if (scr->shortcutWindows[index]) {
1524 WMBag *list = scr->shortcutWindows[index];
1525 int cw;
1526 int count = WMGetBagItemCount(list);
1527 WWindow *twin;
1528 WMBagIterator iter;
1529 WWindow *wwin;
1531 wUnselectWindows(scr);
1532 cw = scr->current_workspace;
1534 for (wwin = WMBagLast(list, &iter);
1535 iter != NULL;
1536 wwin = WMBagPrevious(list, &iter)) {
1538 if (count > 1)
1539 wWindowChangeWorkspace(wwin, cw);
1541 wMakeWindowVisible(wwin);
1543 if (count > 1)
1544 wSelectWindow(wwin, True);
1547 /* rotate the order of windows, to create a cycling effect */
1548 twin = WMBagFirst(list, &iter);
1549 WMRemoveFromBag(list, twin);
1550 WMPutInBag(list, twin);
1552 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1554 INITBAG(scr->shortcutWindows[index]);
1555 WMPutInBag(scr->shortcutWindows[index], wwin);
1557 if (wwin->flags.selected && scr->selected_windows) {
1558 WMBag *selwins = scr->selected_windows;
1559 int i;
1561 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1562 WWindow *tmp = WMGetFromBag(selwins, i);
1564 if (tmp != wwin)
1565 WMPutInBag(scr->shortcutWindows[index], tmp);
1568 wSelectWindow(wwin, !wwin->flags.selected);
1569 XFlush(dpy);
1570 wusleep(3000);
1571 wSelectWindow(wwin, !wwin->flags.selected);
1572 XFlush(dpy);
1574 } else if (scr->selected_windows
1575 && WMGetBagItemCount(scr->selected_windows)) {
1577 if (wwin->flags.selected && scr->selected_windows) {
1578 WMBag *selwins = scr->selected_windows;
1579 int i;
1581 INITBAG(scr->shortcutWindows[index]);
1583 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1584 WWindow *tmp = WMGetFromBag(selwins, i);
1586 WMPutInBag(scr->shortcutWindows[index], tmp);
1590 #undef INITBAG
1592 break;
1594 case WKBD_SWITCH_SCREEN:
1595 if (wScreenCount > 1) {
1596 WScreen *scr2;
1597 int i;
1599 /* find index of this screen */
1600 for (i = 0; i < wScreenCount; i++) {
1601 if (wScreenWithNumber(i) == scr)
1602 break;
1604 i++;
1605 if (i >= wScreenCount) {
1606 i = 0;
1608 scr2 = wScreenWithNumber(i);
1610 if (scr2) {
1611 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1612 scr2->scr_width/2, scr2->scr_height/2);
1615 break;
1617 case WKBD_NEXTWSLAYER:
1618 case WKBD_PREVWSLAYER:
1620 int row, column;
1622 row = scr->current_workspace/10;
1623 column = scr->current_workspace%10;
1625 if (command==WKBD_NEXTWSLAYER) {
1626 if ((row+1)*10 < scr->workspace_count)
1627 wWorkspaceChange(scr, column+(row+1)*10);
1628 } else {
1629 if (row > 0)
1630 wWorkspaceChange(scr, column+(row-1)*10);
1633 break;
1634 case WKBD_CLIPLOWER:
1635 if (!wPreferences.flags.noclip)
1636 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1637 break;
1638 case WKBD_CLIPRAISE:
1639 if (!wPreferences.flags.noclip)
1640 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1641 break;
1642 case WKBD_CLIPRAISELOWER:
1643 if (!wPreferences.flags.noclip)
1644 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1645 break;
1646 #ifdef KEEP_XKB_LOCK_STATUS
1647 case WKBD_TOGGLE:
1648 if(wPreferences.modelock) {
1649 /*toggle*/
1650 wwin = scr->focused_window;
1652 if (wwin && wwin->flags.mapped
1653 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1654 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1655 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1657 wwin->frame->languagemode = wwin->frame->last_languagemode;
1658 wwin->frame->last_languagemode = staterec.group;
1659 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1663 break;
1664 #endif /* KEEP_XKB_LOCK_STATUS */
1670 static void
1671 handleMotionNotify(XEvent *event)
1673 WMenu *menu;
1674 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1676 if (wPreferences.scrollable_menus) {
1677 if (scr->flags.jump_back_pending ||
1678 event->xmotion.x_root <= 1 ||
1679 event->xmotion.x_root >= (scr->scr_width - 2) ||
1680 event->xmotion.y_root <= 1 ||
1681 event->xmotion.y_root >= (scr->scr_height - 2)) {
1682 #ifdef DEBUG
1683 L("pointer at screen edge");
1684 #endif
1685 menu = wMenuUnderPointer(scr);
1686 if (menu!=NULL)
1687 wMenuScroll(menu, event);
1690 #if 0
1691 if (event->xmotion.subwindow == None)
1692 return;
1694 if (scr->scrolledFMaximize != None) {
1695 WWindow *twin;
1697 twin = wWindowFor(scr->scrolledFMaximize);
1698 if (twin && twin->frame_y ==) {
1702 scr->scrolledFMaximize = NULL;
1704 } else {
1706 /* scroll full maximized window */
1707 if (event->xmotion.y_root < 1
1708 || event->xmotion.y_root > scr->scr_height - 1) {
1710 wwin = wWindowFor(event->xmotion.subwindow);
1712 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1713 && WFLAGP(wwin, full_maximize)
1714 && event->xmotion.x_root >= wwin->frame_x
1715 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1717 if (!WFLAGP(wwin, no_titlebar)
1718 && wwin->frame_y <= - wwin->frame->top_width) {
1720 wWindowMove(wwin, wwin->frame_x, 0);
1721 wwin->flags.dragged_while_fmaximized = 0;
1723 } else if (!WFLAGP(wwin, no_resizebar)
1724 && wwin->frame_y + wwin->frame->core->height >=
1725 scr->scr_height + wwin->frame->bottom_width) {
1727 int y = scr->scr_height + wwin->frame->bottom_width;
1729 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1731 wWindowMove(wwin, wwin->frame_x, y);
1732 wwin->flags.dragged_while_fmaximized = 0;
1736 #endif
1740 static void
1741 handleVisibilityNotify(XEvent *event)
1743 WWindow *wwin;
1745 wwin = wWindowFor(event->xvisibility.window);
1746 if (!wwin)
1747 return;
1748 wwin->flags.obscured =
1749 (event->xvisibility.state == VisibilityFullyObscured);