- Added Jim Knoble's 'no polling' patch.
[wmaker-crm.git] / src / event.c
blob68344fd2ddd46d641dfebbb993df1bac2489bcda
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 #ifndef REDUCE_APPICONS
484 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
485 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
487 if (wapp) {
488 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
490 #endif
491 wUnhideApplication(wapp, False, False);
493 return;
496 scr = wScreenForRootWindow(ev->xmaprequest.parent);
498 wwin = wManageWindow(scr, window);
501 * This is to let the Dock know that the application it launched
502 * has already been mapped (eg: it has finished launching).
503 * It is not necessary for normally docked apps, but is needed for
504 * apps that were forcedly docked (like with dockit).
506 if (scr->last_dock) {
507 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
508 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
509 else
510 wDockTrackWindowLaunch(scr->last_dock, window);
513 if (wwin) {
514 wClientSetState(wwin, NormalState, None);
515 if (wwin->flags.maximized) {
516 wMaximizeWindow(wwin, wwin->flags.maximized);
518 if (wwin->flags.shaded) {
519 wwin->flags.shaded = 0;
520 wwin->flags.skip_next_animation = 1;
521 wShadeWindow(wwin);
523 if (wwin->flags.miniaturized) {
524 wwin->flags.miniaturized = 0;
525 wwin->flags.skip_next_animation = 1;
526 wIconifyWindow(wwin);
528 if (wwin->flags.hidden) {
529 WApplication *wapp = wApplicationOf(wwin->main_window);
531 wwin->flags.hidden = 0;
532 wwin->flags.skip_next_animation = 1;
533 if (wapp) {
534 wHideApplication(wapp);
541 static void
542 handleDestroyNotify(XEvent *event)
544 WWindow *wwin;
545 WApplication *app;
546 Window window = event->xdestroywindow.window;
548 #ifdef DEBUG
549 L("got destroy notify");
550 #endif
551 wwin = wWindowFor(window);
552 if (wwin) {
553 wUnmanageWindow(wwin, False, True);
556 app = wApplicationOf(window);
557 if (app) {
558 if (window == app->main_window) {
559 app->refcount = 0;
560 wwin = app->main_window_desc->screen_ptr->focused_window;
561 while (wwin) {
562 if (wwin->main_window == window) {
563 wwin->main_window = None;
565 wwin = wwin->prev;
568 wApplicationDestroy(app);
571 #ifdef KWM_HINTS
572 wKWMCheckDestroy(&event->xdestroywindow);
573 #endif
578 static void
579 handleExpose(XEvent *event)
581 WObjDescriptor *desc;
582 XEvent ev;
584 #ifdef DEBUG
585 L("got expose");
586 #endif
587 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
589 if (XFindContext(dpy, event->xexpose.window, wWinContext,
590 (XPointer *)&desc)==XCNOENT) {
591 return;
594 if (desc->handle_expose) {
595 (*desc->handle_expose)(desc, event);
599 /* bindable */
600 static void
601 handleButtonPress(XEvent *event)
603 WObjDescriptor *desc;
604 WScreen *scr;
606 #ifdef DEBUG
607 L("got button press");
608 #endif
609 scr = wScreenForRootWindow(event->xbutton.root);
611 #ifdef BALLOON_TEXT
612 wBalloonHide(scr);
613 #endif
616 #ifndef LITE
617 if (event->xbutton.window==scr->root_win) {
618 if (event->xbutton.button==wPreferences.menu_button) {
619 OpenRootMenu(scr, event->xbutton.x_root,
620 event->xbutton.y_root, False);
621 /* ugly hack */
622 if (scr->root_menu) {
623 if (scr->root_menu->brother->flags.mapped)
624 event->xbutton.window = scr->root_menu->brother->frame->core->window;
625 else
626 event->xbutton.window = scr->root_menu->frame->core->window;
628 } else if (event->xbutton.button==wPreferences.windowl_button) {
629 OpenSwitchMenu(scr, event->xbutton.x_root,
630 event->xbutton.y_root, False);
631 if (scr->switch_menu) {
632 if (scr->switch_menu->brother->flags.mapped)
633 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
634 else
635 event->xbutton.window = scr->switch_menu->frame->core->window;
637 } else if (event->xbutton.button==wPreferences.select_button) {
638 wUnselectWindows(scr);
639 wSelectWindows(scr, event);
641 #ifdef MOUSE_WS_SWITCH
642 else if (event->xbutton.button==Button5) {
643 wWorkspaceRelativeChange(scr, -1);
644 } else if (event->xbutton.button==Button4) {
645 wWorkspaceRelativeChange(scr, 1);
647 #endif /* MOUSE_WS_SWITCH */
648 #ifdef GNOME_STUFF
649 else if (wGNOMEProxyizeButtonEvent(scr, event))
650 return;
651 #endif
653 #endif /* !LITE */
655 desc = NULL;
656 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
657 (XPointer *)&desc)==XCNOENT) {
658 if (XFindContext(dpy, event->xbutton.window, wWinContext,
659 (XPointer *)&desc)==XCNOENT) {
660 return;
664 if (desc->parent_type == WCLASS_WINDOW) {
665 XSync(dpy, 0);
667 if (event->xbutton.state & MOD_MASK) {
668 XAllowEvents(dpy, AsyncPointer, CurrentTime);
671 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
672 if (wPreferences.ignore_focus_click) {
673 XAllowEvents(dpy, AsyncPointer, CurrentTime);
675 XAllowEvents(dpy, ReplayPointer, CurrentTime);
676 /* }*/
677 XSync(dpy, 0);
678 } else if (desc->parent_type == WCLASS_APPICON
679 || desc->parent_type == WCLASS_MINIWINDOW
680 || desc->parent_type == WCLASS_DOCK_ICON) {
681 if (event->xbutton.state & MOD_MASK) {
682 XSync(dpy, 0);
683 XAllowEvents(dpy, AsyncPointer, CurrentTime);
684 XSync(dpy, 0);
688 if (desc->handle_mousedown!=NULL) {
689 (*desc->handle_mousedown)(desc, event);
692 /* save double-click information */
693 if (scr->flags.next_click_is_not_double) {
694 scr->flags.next_click_is_not_double = 0;
695 } else {
696 scr->last_click_time = event->xbutton.time;
697 scr->last_click_button = event->xbutton.button;
698 scr->last_click_window = event->xbutton.window;
703 static void
704 handleMapNotify(XEvent *event)
706 WWindow *wwin;
707 #ifdef DEBUG
708 L("got map");
709 #endif
710 wwin = wWindowFor(event->xmap.event);
711 if (wwin && wwin->client_win == event->xmap.event) {
712 if (wwin->flags.miniaturized) {
713 wDeiconifyWindow(wwin);
714 } else {
715 XGrabServer(dpy);
716 wWindowMap(wwin);
717 wClientSetState(wwin, NormalState, None);
718 XUngrabServer(dpy);
724 static void
725 handleUnmapNotify(XEvent *event)
727 WWindow *wwin;
728 XEvent ev;
729 Bool withdraw = False;
730 #ifdef DEBUG
731 L("got unmap");
732 #endif
733 /* only process windows with StructureNotify selected
734 * (ignore SubstructureNotify) */
735 wwin = wWindowFor(event->xunmap.window);
736 if (!wwin)
737 return;
739 /* whether the event is a Withdrawal request */
740 if (event->xunmap.event == wwin->screen_ptr->root_win
741 && event->xunmap.send_event)
742 withdraw = True;
744 if (wwin->client_win != event->xunmap.event && !withdraw)
745 return;
747 if (!wwin->flags.mapped && !withdraw
748 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
749 && !wwin->flags.miniaturized && !wwin->flags.hidden)
750 return;
752 XGrabServer(dpy);
753 XUnmapWindow(dpy, wwin->frame->core->window);
754 wwin->flags.mapped = 0;
755 XSync(dpy, 0);
756 /* check if the window was destroyed */
757 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
758 DispatchEvent(&ev);
759 } else {
760 Bool reparented = False;
762 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
763 reparented = True;
765 /* withdraw window */
766 wwin->flags.mapped = 0;
767 if (!reparented)
768 wClientSetState(wwin, WithdrawnState, None);
770 /* if the window was reparented, do not reparent it back to the
771 * root window */
772 wUnmanageWindow(wwin, !reparented, False);
774 XUngrabServer(dpy);
778 static void
779 handleConfigureRequest(XEvent *event)
781 WWindow *wwin;
782 #ifdef DEBUG
783 L("got configure request");
784 #endif
785 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
787 * Configure request for unmapped window
789 wClientConfigure(NULL, &(event->xconfigurerequest));
790 } else {
791 wClientConfigure(wwin, &(event->xconfigurerequest));
796 static void
797 handlePropertyNotify(XEvent *event)
799 WWindow *wwin;
800 WApplication *wapp;
801 Window jr;
802 int ji;
803 unsigned int ju;
804 WScreen *scr;
805 #ifdef DEBUG
806 L("got property notify");
807 #endif
808 if ((wwin=wWindowFor(event->xproperty.window))) {
809 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
810 &ju, &ju, &ju, &ju)) {
811 return;
813 wClientCheckProperty(wwin, &event->xproperty);
815 wapp = wApplicationOf(event->xproperty.window);
816 if (wapp) {
817 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
820 scr = wScreenForWindow(event->xproperty.window);
821 if (scr && scr->root_win == event->xproperty.window) {
822 #ifdef KWM_HINTS
823 wKWMCheckRootHintChange(scr, &event->xproperty);
824 #endif
829 static void
830 handleClientMessage(XEvent *event)
832 WWindow *wwin;
833 WObjDescriptor *desc;
834 #ifdef DEBUG
835 L("got client message");
836 #endif
837 /* handle transition from Normal to Iconic state */
838 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
839 && event->xclient.format == 32
840 && event->xclient.data.l[0] == IconicState) {
842 wwin = wWindowFor(event->xclient.window);
843 if (!wwin) return;
844 if (!wwin->flags.miniaturized)
845 wIconifyWindow(wwin);
846 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
847 && event->xclient.format == 32) {
848 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
850 if (!scr)
851 return;
853 if (event->xclient.data.l[1] == 1) { /* starting */
854 wColormapAllowClientInstallation(scr, True);
855 } else { /* stopping */
856 wColormapAllowClientInstallation(scr, False);
858 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
860 wDefaultsCheckDomains("bla");
862 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
863 WApplication *wapp;
864 int done=0;
865 wapp = wApplicationOf(event->xclient.window);
866 if (wapp) {
867 switch (event->xclient.data.l[0]) {
868 case WMFHideOtherApplications:
869 wHideOtherApplications(wapp->main_window_desc);
870 done = 1;
871 break;
873 case WMFHideApplication:
874 wHideApplication(wapp);
875 done = 1;
876 break;
879 if (!done) {
880 wwin = wWindowFor(event->xclient.window);
881 if (wwin) {
882 switch (event->xclient.data.l[0]) {
883 case WMFHideOtherApplications:
884 wHideOtherApplications(wwin);
885 break;
887 case WMFHideApplication:
888 wHideApplication(wApplicationOf(wwin->main_window));
889 break;
893 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
894 wwin = wWindowFor(event->xclient.window);
895 if (!wwin) return;
896 switch (event->xclient.data.l[0]) {
897 case GSWindowLevelAttr:
899 int level = (int)event->xclient.data.l[1];
901 if (WINDOW_LEVEL(wwin) != level) {
902 ChangeStackingLevel(wwin->frame->core, level);
905 break;
907 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
908 wwin = wWindowFor(event->xclient.window);
909 if (!wwin) return;
910 switch (event->xclient.data.l[0]) {
911 case WMTitleBarNormal:
912 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
913 break;
914 case WMTitleBarMain:
915 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
916 break;
917 case WMTitleBarKey:
918 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
919 break;
921 #ifdef GNOME_STUFF
922 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
923 /* do nothing */
924 #endif /* GNOME_STUFF */
925 #ifdef KWM_HINTS
926 } else if (wKWMProcessClientMessage(&event->xclient)) {
927 /* do nothing */
928 #endif /* KWM_HINTS */
929 #ifdef XDND
930 } else if (wXDNDProcessClientMessage(&event->xclient)) {
931 /* do nothing */
932 #endif /* XDND */
933 #ifdef OFFIX_DND
934 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
935 WScreen *scr = wScreenForWindow(event->xclient.window);
936 if (scr && wDockReceiveDNDDrop(scr,event))
937 goto redirect_message;
938 #endif /* OFFIX_DND */
939 } else {
940 #ifdef OFFIX_DND
941 redirect_message:
942 #endif
944 * Non-standard thing, but needed by OffiX DND.
945 * For when the icon frame gets a ClientMessage
946 * that should have gone to the icon_window.
948 if (XFindContext(dpy, event->xbutton.window, wWinContext,
949 (XPointer *)&desc)!=XCNOENT) {
950 struct WIcon *icon=NULL;
952 if (desc->parent_type == WCLASS_MINIWINDOW) {
953 icon = (WIcon*)desc->parent;
954 } else if (desc->parent_type == WCLASS_DOCK_ICON
955 || desc->parent_type == WCLASS_APPICON) {
956 icon = ((WAppIcon*)desc->parent)->icon;
958 if (icon && (wwin=icon->owner)) {
959 if (wwin->client_win!=event->xclient.window) {
960 event->xclient.window = wwin->client_win;
961 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
962 event);
970 static void
971 raiseWindow(WScreen *scr)
973 WWindow *wwin;
975 scr->autoRaiseTimer = NULL;
977 wwin = wWindowFor(scr->autoRaiseWindow);
978 if (!wwin)
979 return;
981 if (!wwin->flags.destroyed && wwin->flags.focused) {
982 wRaiseFrame(wwin->frame->core);
983 /* this is needed or a race condition will occur */
984 XSync(dpy, False);
989 static void
990 handleEnterNotify(XEvent *event)
992 WWindow *wwin;
993 WObjDescriptor *desc = NULL;
994 XEvent ev;
995 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
996 #ifdef DEBUG
997 L("got enter notify");
998 #endif
1000 #ifdef VIRTUAL_DESKTOP
1001 /* TODO: acceleration code */
1002 if (wPreferences.vedge_thickness) {
1003 int x,y;
1004 if (event->xcrossing.window == scr->virtual_edge_r) {
1005 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1006 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1007 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1008 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1009 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1010 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1011 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1012 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1013 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1014 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1015 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1016 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1017 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1018 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1019 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1022 #endif
1024 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1025 &ev)) {
1026 /* already left the window... */
1027 saveTimestamp(&ev);
1028 if (ev.xcrossing.mode==event->xcrossing.mode
1029 && ev.xcrossing.detail==event->xcrossing.detail) {
1030 return;
1034 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1035 (XPointer *)&desc)!=XCNOENT) {
1036 if(desc->handle_enternotify)
1037 (*desc->handle_enternotify)(desc, event);
1040 /* enter to window */
1041 wwin = wWindowFor(event->xcrossing.window);
1042 if (!wwin) {
1043 if (wPreferences.focus_mode==WKF_POINTER
1044 && event->xcrossing.window==event->xcrossing.root) {
1045 wSetFocusTo(scr, NULL);
1047 if (wPreferences.colormap_mode==WKF_POINTER) {
1048 wColormapInstallForWindow(scr, NULL);
1050 if (scr->autoRaiseTimer
1051 && event->xcrossing.root==event->xcrossing.window) {
1052 WMDeleteTimerHandler(scr->autoRaiseTimer);
1053 scr->autoRaiseTimer = NULL;
1055 } else {
1056 /* set auto raise timer even if in focus-follows-mouse mode
1057 * and the event is for the frame window, even if the window
1058 * has focus already. useful if you move the pointer from a focused
1059 * window to the root window and back pretty fast
1061 * set focus if in focus-follows-mouse mode and the event
1062 * is for the frame window and window doesn't have focus yet */
1063 if ((wPreferences.focus_mode==WKF_POINTER
1064 || wPreferences.focus_mode==WKF_SLOPPY)
1065 && wwin->frame->core->window==event->xcrossing.window
1066 && !scr->flags.doing_alt_tab) {
1068 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1069 wSetFocusTo(scr, wwin);
1071 if (scr->autoRaiseTimer)
1072 WMDeleteTimerHandler(scr->autoRaiseTimer);
1073 scr->autoRaiseTimer = NULL;
1075 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1076 scr->autoRaiseWindow = wwin->frame->core->window;
1077 scr->autoRaiseTimer
1078 = WMAddTimerHandler(wPreferences.raise_delay,
1079 (WMCallback*)raiseWindow, scr);
1082 /* Install colormap for window, if the colormap installation mode
1083 * is colormap_follows_mouse */
1084 if (wPreferences.colormap_mode==WKF_POINTER) {
1085 if (wwin->client_win==event->xcrossing.window)
1086 wColormapInstallForWindow(scr, wwin);
1087 else
1088 wColormapInstallForWindow(scr, NULL);
1092 /* a little kluge to hide the clip balloon */
1093 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1094 if (!desc) {
1095 XUnmapWindow(dpy, scr->clip_balloon);
1096 scr->flags.clip_balloon_mapped = 0;
1097 } else {
1098 if (desc->parent_type!=WCLASS_DOCK_ICON
1099 || scr->clip_icon != desc->parent) {
1100 XUnmapWindow(dpy, scr->clip_balloon);
1101 scr->flags.clip_balloon_mapped = 0;
1106 if (event->xcrossing.window == event->xcrossing.root
1107 && event->xcrossing.detail == NotifyNormal
1108 && event->xcrossing.detail != NotifyInferior
1109 && wPreferences.focus_mode != WKF_CLICK) {
1111 wSetFocusTo(scr, scr->focused_window);
1114 #ifdef BALLOON_TEXT
1115 wBalloonEnteredObject(scr, desc);
1116 #endif
1120 static void
1121 handleLeaveNotify(XEvent *event)
1123 WObjDescriptor *desc = NULL;
1125 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1126 (XPointer *)&desc)!=XCNOENT) {
1127 if(desc->handle_leavenotify)
1128 (*desc->handle_leavenotify)(desc, event);
1130 if (event->xcrossing.window == event->xcrossing.root
1131 && event->xcrossing.mode == NotifyNormal
1132 && event->xcrossing.detail != NotifyInferior
1133 && wPreferences.focus_mode != WKF_CLICK) {
1135 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1137 wSetFocusTo(scr, NULL);
1142 #ifdef SHAPE
1143 static void
1144 handleShapeNotify(XEvent *event)
1146 XShapeEvent *shev = (XShapeEvent*)event;
1147 WWindow *wwin;
1148 XEvent ev;
1149 #ifdef DEBUG
1150 L("got shape notify");
1151 #endif
1152 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1153 XShapeEvent *sev = (XShapeEvent*)&ev;
1155 if (sev->kind == ShapeBounding) {
1156 if (sev->shaped == shev->shaped) {
1157 *shev = *sev;
1158 } else {
1159 XPutBackEvent(dpy, &ev);
1160 break;
1165 wwin = wWindowFor(shev->window);
1166 if (!wwin || shev->kind != ShapeBounding)
1167 return;
1169 if (!shev->shaped && wwin->flags.shaped) {
1171 wwin->flags.shaped = 0;
1172 wWindowClearShape(wwin);
1174 } else if (shev->shaped) {
1176 wwin->flags.shaped = 1;
1177 wWindowSetShape(wwin);
1180 #endif /* SHAPE */
1182 #ifdef KEEP_XKB_LOCK_STATUS
1183 /* please help ]d if you know what to do */
1184 handleXkbIndicatorStateNotify(XEvent *event)
1186 WWindow *wwin;
1187 WScreen *scr;
1188 XkbStateRec staterec;
1189 int i;
1191 for (i=0; i<wScreenCount; i++) {
1192 scr = wScreenWithNumber(i);
1193 wwin = scr->focused_window;
1194 if (wwin && wwin->flags.focused) {
1195 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1196 if (wwin->frame->languagemode != staterec.group) {
1197 wwin->frame->last_languagemode = wwin->frame->languagemode;
1198 wwin->frame->languagemode = staterec.group;
1200 #ifdef XKB_BUTTON_HINT
1201 if (wwin->frame->titlebar) {
1202 wFrameWindowPaint(wwin->frame);
1204 #endif
1208 #endif /*KEEP_XKB_LOCK_STATUS*/
1210 static void
1211 handleColormapNotify(XEvent *event)
1213 WWindow *wwin;
1214 WScreen *scr;
1215 Bool reinstall = False;
1217 wwin = wWindowFor(event->xcolormap.window);
1218 if (!wwin)
1219 return;
1221 scr = wwin->screen_ptr;
1223 do {
1224 if (wwin) {
1225 if (event->xcolormap.new) {
1226 XWindowAttributes attr;
1228 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1230 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1231 scr->current_colormap = attr.colormap;
1233 reinstall = True;
1234 } else if (event->xcolormap.state == ColormapUninstalled &&
1235 scr->current_colormap == event->xcolormap.colormap) {
1237 /* some bastard app (like XV) removed our colormap */
1239 * can't enforce or things like xscreensaver wont work
1240 * reinstall = True;
1242 } else if (event->xcolormap.state == ColormapInstalled &&
1243 scr->current_colormap == event->xcolormap.colormap) {
1245 /* someone has put our colormap back */
1246 reinstall = False;
1249 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1250 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1252 if (reinstall && scr->current_colormap!=None) {
1253 if (!scr->flags.colormap_stuff_blocked)
1254 XInstallColormap(dpy, scr->current_colormap);
1260 static void
1261 handleFocusIn(XEvent *event)
1263 WWindow *wwin;
1266 * For applications that like stealing the focus.
1268 while (XCheckTypedEvent(dpy, FocusIn, event));
1269 saveTimestamp(event);
1270 if (event->xfocus.mode == NotifyUngrab
1271 || event->xfocus.mode == NotifyGrab
1272 || event->xfocus.detail > NotifyNonlinearVirtual) {
1273 return;
1276 wwin = wWindowFor(event->xfocus.window);
1277 if (wwin && !wwin->flags.focused) {
1278 if (wwin->flags.mapped)
1279 wSetFocusTo(wwin->screen_ptr, wwin);
1280 else
1281 wSetFocusTo(wwin->screen_ptr, NULL);
1282 } else if (!wwin) {
1283 WScreen *scr = wScreenForWindow(event->xfocus.window);
1284 if (scr)
1285 wSetFocusTo(scr, NULL);
1290 static WWindow*
1291 windowUnderPointer(WScreen *scr)
1293 unsigned int mask;
1294 int foo;
1295 Window bar, win;
1297 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1298 &mask))
1299 return wWindowFor(win);
1300 return NULL;
1306 static void
1307 handleKeyPress(XEvent *event)
1309 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1310 WWindow *wwin = scr->focused_window;
1311 int i;
1312 int modifiers;
1313 int command=-1, index;
1314 #ifdef KEEP_XKB_LOCK_STATUS
1315 XkbStateRec staterec;
1316 #endif /*KEEP_XKB_LOCK_STATUS*/
1318 /* ignore CapsLock */
1319 modifiers = event->xkey.state & ValidModMask;
1321 for (i=0; i<WKBD_LAST; i++) {
1322 if (wKeyBindings[i].keycode==0)
1323 continue;
1325 if (wKeyBindings[i].keycode==event->xkey.keycode
1326 && (/*wKeyBindings[i].modifier==0
1327 ||*/ wKeyBindings[i].modifier==modifiers)) {
1328 command = i;
1329 break;
1334 if (command < 0) {
1335 #ifdef LITE
1337 #if 0
1339 #endif
1340 #else
1341 if (!wRootMenuPerformShortcut(event)) {
1342 #endif
1343 static int dontLoop = 0;
1345 if (dontLoop > 10) {
1346 wwarning("problem with key event processing code");
1347 return;
1349 dontLoop++;
1350 /* if the focused window is an internal window, try redispatching
1351 * the event to the managed window, as it can be a WINGs window */
1352 if (wwin && wwin->flags.internal_window
1353 && wwin->client_leader!=None) {
1354 /* client_leader contains the WINGs toplevel */
1355 event->xany.window = wwin->client_leader;
1356 WMHandleEvent(event);
1358 dontLoop--;
1360 return;
1363 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1364 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1366 switch (command) {
1367 #ifndef LITE
1368 case WKBD_ROOTMENU:
1369 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1370 break;
1371 case WKBD_WINDOWLIST:
1372 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1373 break;
1374 #endif /* !LITE */
1375 case WKBD_WINDOWMENU:
1376 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1377 OpenWindowMenu(wwin, wwin->frame_x,
1378 wwin->frame_y+wwin->frame->top_width, True);
1379 break;
1380 case WKBD_MINIATURIZE:
1381 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1382 && !WFLAGP(wwin, no_miniaturizable)) {
1383 CloseWindowMenu(scr);
1385 if (wwin->protocols.MINIATURIZE_WINDOW)
1386 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1387 event->xbutton.time);
1388 else {
1389 wIconifyWindow(wwin);
1392 break;
1393 case WKBD_HIDE:
1394 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1395 WApplication *wapp = wApplicationOf(wwin->main_window);
1396 CloseWindowMenu(scr);
1398 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1399 wHideApplication(wapp);
1402 break;
1403 case WKBD_MAXIMIZE:
1404 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1405 CloseWindowMenu(scr);
1407 if (wwin->flags.maximized) {
1408 wUnmaximizeWindow(wwin);
1409 } else {
1410 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1413 break;
1414 case WKBD_VMAXIMIZE:
1415 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1416 CloseWindowMenu(scr);
1418 if (wwin->flags.maximized) {
1419 wUnmaximizeWindow(wwin);
1420 } else {
1421 wMaximizeWindow(wwin, MAX_VERTICAL);
1424 break;
1425 case WKBD_RAISE:
1426 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1427 CloseWindowMenu(scr);
1429 wRaiseFrame(wwin->frame->core);
1431 break;
1432 case WKBD_LOWER:
1433 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1434 CloseWindowMenu(scr);
1436 wLowerFrame(wwin->frame->core);
1438 break;
1439 case WKBD_RAISELOWER:
1440 /* raise or lower the window under the pointer, not the
1441 * focused one
1443 wwin = windowUnderPointer(scr);
1444 if (wwin)
1445 wRaiseLowerFrame(wwin->frame->core);
1446 break;
1447 case WKBD_SHADE:
1448 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1449 if (wwin->flags.shaded)
1450 wUnshadeWindow(wwin);
1451 else
1452 wShadeWindow(wwin);
1454 break;
1455 case WKBD_MOVERESIZE:
1456 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1457 CloseWindowMenu(scr);
1459 wKeyboardMoveResizeWindow(wwin);
1461 break;
1462 case WKBD_CLOSE:
1463 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1464 CloseWindowMenu(scr);
1465 if (wwin->protocols.DELETE_WINDOW)
1466 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1467 event->xkey.time);
1469 break;
1470 case WKBD_SELECT:
1471 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1472 wSelectWindow(wwin, !wwin->flags.selected);
1474 break;
1475 case WKBD_FOCUSNEXT:
1476 StartWindozeCycle(wwin, event, True);
1477 break;
1479 case WKBD_FOCUSPREV:
1480 StartWindozeCycle(wwin, event, False);
1481 break;
1483 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1484 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1485 i = (scr->current_workspace/10)*10 + wk - 1;\
1486 if (wPreferences.ws_advance || i<scr->workspace_count)\
1487 wWorkspaceChange(scr, i);\
1488 break
1489 #else
1490 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1491 i = (scr->current_workspace/10)*10 + wk - 1;\
1492 if (wPreferences.ws_advance || i<scr->workspace_count)\
1493 wWorkspaceChange(scr, i);\
1494 break
1495 #endif
1496 GOTOWORKS(1);
1497 GOTOWORKS(2);
1498 GOTOWORKS(3);
1499 GOTOWORKS(4);
1500 GOTOWORKS(5);
1501 GOTOWORKS(6);
1502 GOTOWORKS(7);
1503 GOTOWORKS(8);
1504 GOTOWORKS(9);
1505 GOTOWORKS(10);
1506 #undef GOTOWORKS
1507 case WKBD_NEXTWORKSPACE:
1508 wWorkspaceRelativeChange(scr, 1);
1509 break;
1510 case WKBD_PREVWORKSPACE:
1511 wWorkspaceRelativeChange(scr, -1);
1512 break;
1513 case WKBD_WINDOW1:
1514 case WKBD_WINDOW2:
1515 case WKBD_WINDOW3:
1516 case WKBD_WINDOW4:
1517 case WKBD_WINDOW5:
1518 case WKBD_WINDOW6:
1519 case WKBD_WINDOW7:
1520 case WKBD_WINDOW8:
1521 case WKBD_WINDOW9:
1522 case WKBD_WINDOW10:
1524 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1526 index = command-WKBD_WINDOW1;
1528 if (scr->shortcutWindows[index]) {
1529 WMBag *list = scr->shortcutWindows[index];
1530 int cw;
1531 int count = WMGetBagItemCount(list);
1532 WWindow *twin;
1533 WMBagIterator iter;
1534 WWindow *wwin;
1536 wUnselectWindows(scr);
1537 cw = scr->current_workspace;
1539 for (wwin = WMBagLast(list, &iter);
1540 iter != NULL;
1541 wwin = WMBagPrevious(list, &iter)) {
1543 if (count > 1)
1544 wWindowChangeWorkspace(wwin, cw);
1546 wMakeWindowVisible(wwin);
1548 if (count > 1)
1549 wSelectWindow(wwin, True);
1552 /* rotate the order of windows, to create a cycling effect */
1553 twin = WMBagFirst(list, &iter);
1554 WMRemoveFromBag(list, twin);
1555 WMPutInBag(list, twin);
1557 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1559 INITBAG(scr->shortcutWindows[index]);
1560 WMPutInBag(scr->shortcutWindows[index], wwin);
1562 if (wwin->flags.selected && scr->selected_windows) {
1563 WMBag *selwins = scr->selected_windows;
1564 int i;
1566 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1567 WWindow *tmp = WMGetFromBag(selwins, i);
1569 if (tmp != wwin)
1570 WMPutInBag(scr->shortcutWindows[index], tmp);
1573 wSelectWindow(wwin, !wwin->flags.selected);
1574 XFlush(dpy);
1575 wusleep(3000);
1576 wSelectWindow(wwin, !wwin->flags.selected);
1577 XFlush(dpy);
1579 } else if (scr->selected_windows
1580 && WMGetBagItemCount(scr->selected_windows)) {
1582 if (wwin->flags.selected && scr->selected_windows) {
1583 WMBag *selwins = scr->selected_windows;
1584 int i;
1586 INITBAG(scr->shortcutWindows[index]);
1588 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1589 WWindow *tmp = WMGetFromBag(selwins, i);
1591 WMPutInBag(scr->shortcutWindows[index], tmp);
1595 #undef INITBAG
1597 break;
1599 case WKBD_SWITCH_SCREEN:
1600 if (wScreenCount > 1) {
1601 WScreen *scr2;
1602 int i;
1604 /* find index of this screen */
1605 for (i = 0; i < wScreenCount; i++) {
1606 if (wScreenWithNumber(i) == scr)
1607 break;
1609 i++;
1610 if (i >= wScreenCount) {
1611 i = 0;
1613 scr2 = wScreenWithNumber(i);
1615 if (scr2) {
1616 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1617 scr2->scr_width/2, scr2->scr_height/2);
1620 break;
1622 case WKBD_NEXTWSLAYER:
1623 case WKBD_PREVWSLAYER:
1625 int row, column;
1627 row = scr->current_workspace/10;
1628 column = scr->current_workspace%10;
1630 if (command==WKBD_NEXTWSLAYER) {
1631 if ((row+1)*10 < scr->workspace_count)
1632 wWorkspaceChange(scr, column+(row+1)*10);
1633 } else {
1634 if (row > 0)
1635 wWorkspaceChange(scr, column+(row-1)*10);
1638 break;
1639 case WKBD_CLIPLOWER:
1640 if (!wPreferences.flags.noclip)
1641 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1642 break;
1643 case WKBD_CLIPRAISE:
1644 if (!wPreferences.flags.noclip)
1645 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1646 break;
1647 case WKBD_CLIPRAISELOWER:
1648 if (!wPreferences.flags.noclip)
1649 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1650 break;
1651 #ifdef KEEP_XKB_LOCK_STATUS
1652 case WKBD_TOGGLE:
1653 if(wPreferences.modelock) {
1654 /*toggle*/
1655 wwin = scr->focused_window;
1657 if (wwin && wwin->flags.mapped
1658 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1659 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1660 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1662 wwin->frame->languagemode = wwin->frame->last_languagemode;
1663 wwin->frame->last_languagemode = staterec.group;
1664 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1668 break;
1669 #endif /* KEEP_XKB_LOCK_STATUS */
1675 static void
1676 handleMotionNotify(XEvent *event)
1678 WMenu *menu;
1679 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1681 if (wPreferences.scrollable_menus) {
1682 if (scr->flags.jump_back_pending ||
1683 event->xmotion.x_root <= 1 ||
1684 event->xmotion.x_root >= (scr->scr_width - 2) ||
1685 event->xmotion.y_root <= 1 ||
1686 event->xmotion.y_root >= (scr->scr_height - 2)) {
1687 #ifdef DEBUG
1688 L("pointer at screen edge");
1689 #endif
1690 menu = wMenuUnderPointer(scr);
1691 if (menu!=NULL)
1692 wMenuScroll(menu, event);
1695 #if 0
1696 if (event->xmotion.subwindow == None)
1697 return;
1699 if (scr->scrolledFMaximize != None) {
1700 WWindow *twin;
1702 twin = wWindowFor(scr->scrolledFMaximize);
1703 if (twin && twin->frame_y ==) {
1707 scr->scrolledFMaximize = NULL;
1709 } else {
1711 /* scroll full maximized window */
1712 if (event->xmotion.y_root < 1
1713 || event->xmotion.y_root > scr->scr_height - 1) {
1715 wwin = wWindowFor(event->xmotion.subwindow);
1717 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1718 && WFLAGP(wwin, full_maximize)
1719 && event->xmotion.x_root >= wwin->frame_x
1720 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1722 if (!WFLAGP(wwin, no_titlebar)
1723 && wwin->frame_y <= - wwin->frame->top_width) {
1725 wWindowMove(wwin, wwin->frame_x, 0);
1726 wwin->flags.dragged_while_fmaximized = 0;
1728 } else if (!WFLAGP(wwin, no_resizebar)
1729 && wwin->frame_y + wwin->frame->core->height >=
1730 scr->scr_height + wwin->frame->bottom_width) {
1732 int y = scr->scr_height + wwin->frame->bottom_width;
1734 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1736 wWindowMove(wwin, wwin->frame_x, y);
1737 wwin->flags.dragged_while_fmaximized = 0;
1741 #endif
1745 static void
1746 handleVisibilityNotify(XEvent *event)
1748 WWindow *wwin;
1750 wwin = wWindowFor(event->xvisibility.window);
1751 if (!wwin)
1752 return;
1753 wwin->flags.obscured =
1754 (event->xvisibility.state == VisibilityFullyObscured);