fixed some bugs
[wmaker-crm.git] / src / event.c
blob82432272258842daf343c9ede9ae6d1f0db594d1
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);
224 /* for the case that all that is wanted to be dispatched is
225 * the stuff above */
226 if (!event)
227 return;
229 saveTimestamp(event);
230 switch (event->type) {
231 case MapRequest:
232 handleMapRequest(event);
233 break;
235 case KeyPress:
236 handleKeyPress(event);
237 break;
239 case MotionNotify:
240 handleMotionNotify(event);
241 break;
243 case ConfigureRequest:
244 handleConfigureRequest(event);
245 break;
247 case DestroyNotify:
248 handleDestroyNotify(event);
249 break;
251 case MapNotify:
252 handleMapNotify(event);
253 break;
255 case UnmapNotify:
256 handleUnmapNotify(event);
257 break;
259 case ButtonPress:
260 handleButtonPress(event);
261 break;
263 case Expose:
264 handleExpose(event);
265 break;
267 case PropertyNotify:
268 handlePropertyNotify(event);
269 break;
271 case EnterNotify:
272 handleEnterNotify(event);
273 break;
275 case LeaveNotify:
276 handleLeaveNotify(event);
277 break;
279 case ClientMessage:
280 handleClientMessage(event);
281 break;
283 case ColormapNotify:
284 handleColormapNotify(event);
285 break;
287 case MappingNotify:
288 if (event->xmapping.request == MappingKeyboard
289 || event->xmapping.request == MappingModifier)
290 XRefreshKeyboardMapping(&event->xmapping);
291 break;
293 case FocusIn:
294 handleFocusIn(event);
295 break;
297 case VisibilityNotify:
298 handleVisibilityNotify(event);
299 break;
300 default:
301 handleExtensions(event);
302 break;
308 *----------------------------------------------------------------------
309 * EventLoop-
310 * Processes X and internal events indefinitely.
312 * Returns:
313 * Never returns
315 * Side effects:
316 * The LastTimestamp global variable is updated.
317 *----------------------------------------------------------------------
319 void
320 EventLoop()
322 XEvent event;
324 for(;;) {
325 WMNextEvent(dpy, &event);
326 WMHandleEvent(&event);
332 Bool
333 IsDoubleClick(WScreen *scr, XEvent *event)
335 if ((scr->last_click_time>0) &&
336 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
337 && (event->xbutton.button == scr->last_click_button)
338 && (event->xbutton.window == scr->last_click_window)) {
340 scr->flags.next_click_is_not_double = 1;
341 scr->last_click_time = 0;
342 scr->last_click_window = event->xbutton.window;
344 return True;
346 return False;
350 void
351 NotifyDeadProcess(pid_t pid, unsigned char status)
353 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
354 wwarning("stack overflow: too many dead processes");
355 return;
357 /* stack the process to be handled later,
358 * as this is called from the signal handler */
359 deadProcesses[deadProcessPtr].pid = pid;
360 deadProcesses[deadProcessPtr].exit_status = status;
361 deadProcessPtr++;
365 static void
366 handleDeadProcess(void *foo)
368 DeathHandler *tmp;
369 int i;
371 for (i=0; i<deadProcessPtr; i++) {
372 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
375 if (!deathHandlers) {
376 deadProcessPtr=0;
377 return;
380 /* get the pids on the queue and call handlers */
381 while (deadProcessPtr>0) {
382 deadProcessPtr--;
384 for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) {
385 tmp = WMGetFromBag(deathHandlers, i);
386 if (!tmp)
387 continue;
389 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
390 (*tmp->callback)(tmp->pid,
391 deadProcesses[deadProcessPtr].exit_status,
392 tmp->client_data);
393 wDeleteDeathHandler(tmp);
400 static void
401 saveTimestamp(XEvent *event)
403 LastTimestamp = CurrentTime;
405 switch (event->type) {
406 case ButtonRelease:
407 case ButtonPress:
408 LastTimestamp = event->xbutton.time;
409 break;
410 case KeyPress:
411 case KeyRelease:
412 LastTimestamp = event->xkey.time;
413 break;
414 case MotionNotify:
415 LastTimestamp = event->xmotion.time;
416 break;
417 case PropertyNotify:
418 LastTimestamp = event->xproperty.time;
419 break;
420 case EnterNotify:
421 case LeaveNotify:
422 LastTimestamp = event->xcrossing.time;
423 break;
424 case SelectionClear:
425 LastTimestamp = event->xselectionclear.time;
426 break;
427 case SelectionRequest:
428 LastTimestamp = event->xselectionrequest.time;
429 break;
430 case SelectionNotify:
431 LastTimestamp = event->xselection.time;
432 #ifdef XDND
433 wXDNDProcessSelection(event);
434 #endif
435 break;
440 static void
441 handleExtensions(XEvent *event)
443 #ifdef KEEP_XKB_LOCK_STATUS
444 XkbEvent *xkbevent;
445 xkbevent = (XkbEvent *)event;
446 #endif /*KEEP_XKB_LOCK_STATUS*/
447 #ifdef SHAPE
448 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
449 handleShapeNotify(event);
451 #endif
452 #ifdef KEEP_XKB_LOCK_STATUS
453 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
454 handleXkbIndicatorStateNotify(event);
456 #endif /*KEEP_XKB_LOCK_STATUS*/
460 static void
461 handleMapRequest(XEvent *ev)
463 WWindow *wwin;
464 WScreen *scr = NULL;
465 Window window = ev->xmaprequest.window;
467 #ifdef DEBUG
468 L("got map request for %x\n", (unsigned)window);
469 #endif
470 if ((wwin = wWindowFor(window))) {
471 if (wwin->flags.shaded) {
472 wUnshadeWindow(wwin);
474 /* deiconify window */
475 if (wwin->flags.miniaturized) {
476 wDeiconifyWindow(wwin);
477 } else if (wwin->flags.hidden) {
478 WApplication *wapp = wApplicationOf(wwin->main_window);
479 /* go to the last workspace that the user worked on the app */
480 #ifndef REDUCE_APPICONS
481 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
482 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
484 if (wapp) {
485 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
487 #endif
488 wUnhideApplication(wapp, False, False);
490 return;
493 scr = wScreenForRootWindow(ev->xmaprequest.parent);
495 wwin = wManageWindow(scr, window);
498 * This is to let the Dock know that the application it launched
499 * has already been mapped (eg: it has finished launching).
500 * It is not necessary for normally docked apps, but is needed for
501 * apps that were forcedly docked (like with dockit).
503 if (scr->last_dock) {
504 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
505 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
506 else
507 wDockTrackWindowLaunch(scr->last_dock, window);
510 if (wwin) {
511 wClientSetState(wwin, NormalState, None);
512 if (wwin->flags.maximized) {
513 wMaximizeWindow(wwin, wwin->flags.maximized);
515 if (wwin->flags.shaded) {
516 wwin->flags.shaded = 0;
517 wwin->flags.skip_next_animation = 1;
518 wShadeWindow(wwin);
520 if (wwin->flags.miniaturized) {
521 wwin->flags.miniaturized = 0;
522 wwin->flags.skip_next_animation = 1;
523 wIconifyWindow(wwin);
525 if (wwin->flags.hidden) {
526 WApplication *wapp = wApplicationOf(wwin->main_window);
528 wwin->flags.hidden = 0;
529 wwin->flags.skip_next_animation = 1;
530 if (wapp) {
531 wHideApplication(wapp);
538 static void
539 handleDestroyNotify(XEvent *event)
541 WWindow *wwin;
542 WApplication *app;
543 Window window = event->xdestroywindow.window;
545 #ifdef DEBUG
546 L("got destroy notify");
547 #endif
548 wwin = wWindowFor(window);
549 if (wwin) {
550 wUnmanageWindow(wwin, False, True);
553 app = wApplicationOf(window);
554 if (app) {
555 if (window == app->main_window) {
556 app->refcount = 0;
557 wwin = app->main_window_desc->screen_ptr->focused_window;
558 while (wwin) {
559 if (wwin->main_window == window) {
560 wwin->main_window = None;
562 wwin = wwin->prev;
565 wApplicationDestroy(app);
568 #ifdef KWM_HINTS
569 wKWMCheckDestroy(&event->xdestroywindow);
570 #endif
575 static void
576 handleExpose(XEvent *event)
578 WObjDescriptor *desc;
579 XEvent ev;
581 #ifdef DEBUG
582 L("got expose");
583 #endif
584 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
586 if (XFindContext(dpy, event->xexpose.window, wWinContext,
587 (XPointer *)&desc)==XCNOENT) {
588 return;
591 if (desc->handle_expose) {
592 (*desc->handle_expose)(desc, event);
596 /* bindable */
597 static void
598 handleButtonPress(XEvent *event)
600 WObjDescriptor *desc;
601 WScreen *scr;
603 #ifdef DEBUG
604 L("got button press");
605 #endif
606 scr = wScreenForRootWindow(event->xbutton.root);
608 #ifdef BALLOON_TEXT
609 wBalloonHide(scr);
610 #endif
613 #ifndef LITE
614 if (event->xbutton.window==scr->root_win) {
615 if (event->xbutton.button==wPreferences.menu_button) {
616 OpenRootMenu(scr, event->xbutton.x_root,
617 event->xbutton.y_root, False);
618 /* ugly hack */
619 if (scr->root_menu) {
620 if (scr->root_menu->brother->flags.mapped)
621 event->xbutton.window = scr->root_menu->brother->frame->core->window;
622 else
623 event->xbutton.window = scr->root_menu->frame->core->window;
625 } else if (event->xbutton.button==wPreferences.windowl_button) {
626 OpenSwitchMenu(scr, event->xbutton.x_root,
627 event->xbutton.y_root, False);
628 if (scr->switch_menu) {
629 if (scr->switch_menu->brother->flags.mapped)
630 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
631 else
632 event->xbutton.window = scr->switch_menu->frame->core->window;
634 } else if (event->xbutton.button==wPreferences.select_button) {
635 wUnselectWindows(scr);
636 wSelectWindows(scr, event);
638 #ifdef MOUSE_WS_SWITCH
639 else if (event->xbutton.button==Button5) {
641 wWorkspaceRelativeChange(scr, -1);
643 } else if (event->xbutton.button==Button4) {
645 wWorkspaceRelativeChange(scr, 1);
648 #endif /* MOUSE_WS_SWITCH */
649 #ifdef GNOME_STUFF
650 else if (wGNOMEProxyizeButtonEvent(scr, event))
651 return;
652 #endif
654 #endif /* !LITE */
656 desc = NULL;
657 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
658 (XPointer *)&desc)==XCNOENT) {
659 if (XFindContext(dpy, event->xbutton.window, wWinContext,
660 (XPointer *)&desc)==XCNOENT) {
661 return;
665 if (desc->parent_type == WCLASS_WINDOW) {
666 XSync(dpy, 0);
668 if (event->xbutton.state & MOD_MASK) {
669 XAllowEvents(dpy, AsyncPointer, CurrentTime);
672 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
673 if (wPreferences.ignore_focus_click) {
674 XAllowEvents(dpy, AsyncPointer, CurrentTime);
676 XAllowEvents(dpy, ReplayPointer, CurrentTime);
677 /* }*/
678 XSync(dpy, 0);
679 } else if (desc->parent_type == WCLASS_APPICON
680 || desc->parent_type == WCLASS_MINIWINDOW
681 || desc->parent_type == WCLASS_DOCK_ICON) {
682 if (event->xbutton.state & MOD_MASK) {
683 XSync(dpy, 0);
684 XAllowEvents(dpy, AsyncPointer, CurrentTime);
685 XSync(dpy, 0);
689 if (desc->handle_mousedown!=NULL) {
690 (*desc->handle_mousedown)(desc, event);
693 /* save double-click information */
694 if (scr->flags.next_click_is_not_double) {
695 scr->flags.next_click_is_not_double = 0;
696 } else {
697 scr->last_click_time = event->xbutton.time;
698 scr->last_click_button = event->xbutton.button;
699 scr->last_click_window = event->xbutton.window;
704 static void
705 handleMapNotify(XEvent *event)
707 WWindow *wwin;
708 #ifdef DEBUG
709 L("got map");
710 #endif
711 wwin = wWindowFor(event->xmap.event);
712 if (wwin && wwin->client_win == event->xmap.event) {
713 if (wwin->flags.miniaturized) {
714 wDeiconifyWindow(wwin);
715 } else {
716 XGrabServer(dpy);
717 wWindowMap(wwin);
718 wClientSetState(wwin, NormalState, None);
719 XUngrabServer(dpy);
725 static void
726 handleUnmapNotify(XEvent *event)
728 WWindow *wwin;
729 XEvent ev;
730 Bool withdraw = False;
731 #ifdef DEBUG
732 L("got unmap");
733 #endif
734 /* only process windows with StructureNotify selected
735 * (ignore SubstructureNotify) */
736 wwin = wWindowFor(event->xunmap.window);
737 if (!wwin)
738 return;
740 /* whether the event is a Withdrawal request */
741 if (event->xunmap.event == wwin->screen_ptr->root_win
742 && event->xunmap.send_event)
743 withdraw = True;
745 if (wwin->client_win != event->xunmap.event && !withdraw)
746 return;
748 if (!wwin->flags.mapped && !withdraw
749 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
750 && !wwin->flags.miniaturized && !wwin->flags.hidden)
751 return;
753 XGrabServer(dpy);
754 XUnmapWindow(dpy, wwin->frame->core->window);
755 wwin->flags.mapped = 0;
756 XSync(dpy, 0);
757 /* check if the window was destroyed */
758 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
759 DispatchEvent(&ev);
760 } else {
761 Bool reparented = False;
763 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
764 reparented = True;
766 /* withdraw window */
767 wwin->flags.mapped = 0;
768 if (!reparented)
769 wClientSetState(wwin, WithdrawnState, None);
771 /* if the window was reparented, do not reparent it back to the
772 * root window */
773 wUnmanageWindow(wwin, !reparented, False);
775 XUngrabServer(dpy);
779 static void
780 handleConfigureRequest(XEvent *event)
782 WWindow *wwin;
783 #ifdef DEBUG
784 L("got configure request");
785 #endif
786 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
788 * Configure request for unmapped window
790 wClientConfigure(NULL, &(event->xconfigurerequest));
791 } else {
792 wClientConfigure(wwin, &(event->xconfigurerequest));
797 static void
798 handlePropertyNotify(XEvent *event)
800 WWindow *wwin;
801 WApplication *wapp;
802 Window jr;
803 int ji;
804 unsigned int ju;
805 WScreen *scr;
806 #ifdef DEBUG
807 L("got property notify");
808 #endif
809 if ((wwin=wWindowFor(event->xproperty.window))) {
810 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
811 &ju, &ju, &ju, &ju)) {
812 return;
814 wClientCheckProperty(wwin, &event->xproperty);
816 wapp = wApplicationOf(event->xproperty.window);
817 if (wapp) {
818 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
821 scr = wScreenForWindow(event->xproperty.window);
822 if (scr && scr->root_win == event->xproperty.window) {
823 #ifdef KWM_HINTS
824 wKWMCheckRootHintChange(scr, &event->xproperty);
825 #endif
830 static void
831 handleClientMessage(XEvent *event)
833 WWindow *wwin;
834 WObjDescriptor *desc;
835 #ifdef DEBUG
836 L("got client message");
837 #endif
838 /* handle transition from Normal to Iconic state */
839 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
840 && event->xclient.format == 32
841 && event->xclient.data.l[0] == IconicState) {
843 wwin = wWindowFor(event->xclient.window);
844 if (!wwin) return;
845 if (!wwin->flags.miniaturized)
846 wIconifyWindow(wwin);
847 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
848 && event->xclient.format == 32) {
849 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
851 if (!scr)
852 return;
854 if (event->xclient.data.l[1] == 1) { /* starting */
855 wColormapAllowClientInstallation(scr, True);
856 } else { /* stopping */
857 wColormapAllowClientInstallation(scr, False);
859 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
861 wDefaultsCheckDomains("bla");
863 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
864 WApplication *wapp;
865 int done=0;
866 wapp = wApplicationOf(event->xclient.window);
867 if (wapp) {
868 switch (event->xclient.data.l[0]) {
869 case WMFHideOtherApplications:
870 wHideOtherApplications(wapp->main_window_desc);
871 done = 1;
872 break;
874 case WMFHideApplication:
875 wHideApplication(wapp);
876 done = 1;
877 break;
880 if (!done) {
881 wwin = wWindowFor(event->xclient.window);
882 if (wwin) {
883 switch (event->xclient.data.l[0]) {
884 case WMFHideOtherApplications:
885 wHideOtherApplications(wwin);
886 break;
888 case WMFHideApplication:
889 wHideApplication(wApplicationOf(wwin->main_window));
890 break;
894 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
895 wwin = wWindowFor(event->xclient.window);
896 if (!wwin) return;
897 switch (event->xclient.data.l[0]) {
898 case GSWindowLevelAttr:
900 int level = (int)event->xclient.data.l[1];
902 if (WINDOW_LEVEL(wwin) != level) {
903 ChangeStackingLevel(wwin->frame->core, level);
906 break;
908 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
909 wwin = wWindowFor(event->xclient.window);
910 if (!wwin) return;
911 switch (event->xclient.data.l[0]) {
912 case WMTitleBarNormal:
913 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
914 break;
915 case WMTitleBarMain:
916 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
917 break;
918 case WMTitleBarKey:
919 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
920 break;
922 #ifdef GNOME_STUFF
923 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
924 /* do nothing */
925 #endif /* GNOME_STUFF */
926 #ifdef KWM_HINTS
927 } else if (wKWMProcessClientMessage(&event->xclient)) {
928 /* do nothing */
929 #endif /* KWM_HINTS */
930 #ifdef XDND
931 } else if (wXDNDProcessClientMessage(&event->xclient)) {
932 /* do nothing */
933 #endif /* XDND */
934 #ifdef OFFIX_DND
935 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
936 WScreen *scr = wScreenForWindow(event->xclient.window);
937 if (scr && wDockReceiveDNDDrop(scr,event))
938 goto redirect_message;
939 #endif /* OFFIX_DND */
940 } else {
941 #ifdef OFFIX_DND
942 redirect_message:
943 #endif
945 * Non-standard thing, but needed by OffiX DND.
946 * For when the icon frame gets a ClientMessage
947 * that should have gone to the icon_window.
949 if (XFindContext(dpy, event->xbutton.window, wWinContext,
950 (XPointer *)&desc)!=XCNOENT) {
951 struct WIcon *icon=NULL;
953 if (desc->parent_type == WCLASS_MINIWINDOW) {
954 icon = (WIcon*)desc->parent;
955 } else if (desc->parent_type == WCLASS_DOCK_ICON
956 || desc->parent_type == WCLASS_APPICON) {
957 icon = ((WAppIcon*)desc->parent)->icon;
959 if (icon && (wwin=icon->owner)) {
960 if (wwin->client_win!=event->xclient.window) {
961 event->xclient.window = wwin->client_win;
962 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
963 event);
971 static void
972 raiseWindow(WScreen *scr)
974 WWindow *wwin;
976 scr->autoRaiseTimer = NULL;
978 wwin = wWindowFor(scr->autoRaiseWindow);
979 if (!wwin)
980 return;
982 if (!wwin->flags.destroyed && wwin->flags.focused) {
983 wRaiseFrame(wwin->frame->core);
984 /* this is needed or a race condition will occur */
985 XSync(dpy, False);
990 static void
991 handleEnterNotify(XEvent *event)
993 WWindow *wwin;
994 WObjDescriptor *desc = NULL;
995 XEvent ev;
996 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
997 #ifdef DEBUG
998 L("got enter notify");
999 #endif
1001 #ifdef VIRTUAL_DESKTOP
1002 /* TODO: acceleration code */
1003 if (wPreferences.vedge_thickness) {
1004 int x,y;
1005 if (event->xcrossing.window == scr->virtual_edge_r) {
1006 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1007 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1008 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1009 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1010 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1011 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1012 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1013 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1014 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1015 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1016 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1017 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1018 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1019 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1020 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1023 #endif
1025 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1026 &ev)) {
1027 /* already left the window... */
1028 saveTimestamp(&ev);
1029 if (ev.xcrossing.mode==event->xcrossing.mode
1030 && ev.xcrossing.detail==event->xcrossing.detail) {
1031 return;
1035 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1036 (XPointer *)&desc)!=XCNOENT) {
1037 if(desc->handle_enternotify)
1038 (*desc->handle_enternotify)(desc, event);
1041 /* enter to window */
1042 wwin = wWindowFor(event->xcrossing.window);
1043 if (!wwin) {
1044 if (wPreferences.focus_mode==WKF_POINTER
1045 && event->xcrossing.window==event->xcrossing.root) {
1046 wSetFocusTo(scr, NULL);
1048 if (wPreferences.colormap_mode==WKF_POINTER) {
1049 wColormapInstallForWindow(scr, NULL);
1051 if (scr->autoRaiseTimer
1052 && event->xcrossing.root==event->xcrossing.window) {
1053 WMDeleteTimerHandler(scr->autoRaiseTimer);
1054 scr->autoRaiseTimer = NULL;
1056 } else {
1057 /* set auto raise timer even if in focus-follows-mouse mode
1058 * and the event is for the frame window, even if the window
1059 * has focus already. useful if you move the pointer from a focused
1060 * window to the root window and back pretty fast
1062 * set focus if in focus-follows-mouse mode and the event
1063 * is for the frame window and window doesn't have focus yet */
1064 if ((wPreferences.focus_mode==WKF_POINTER
1065 || wPreferences.focus_mode==WKF_SLOPPY)
1066 && wwin->frame->core->window==event->xcrossing.window
1067 && !scr->flags.doing_alt_tab) {
1069 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1070 wSetFocusTo(scr, wwin);
1072 if (scr->autoRaiseTimer)
1073 WMDeleteTimerHandler(scr->autoRaiseTimer);
1074 scr->autoRaiseTimer = NULL;
1076 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1077 scr->autoRaiseWindow = wwin->frame->core->window;
1078 scr->autoRaiseTimer
1079 = WMAddTimerHandler(wPreferences.raise_delay,
1080 (WMCallback*)raiseWindow, scr);
1083 /* Install colormap for window, if the colormap installation mode
1084 * is colormap_follows_mouse */
1085 if (wPreferences.colormap_mode==WKF_POINTER) {
1086 if (wwin->client_win==event->xcrossing.window)
1087 wColormapInstallForWindow(scr, wwin);
1088 else
1089 wColormapInstallForWindow(scr, NULL);
1093 /* a little kluge to hide the clip balloon */
1094 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1095 if (!desc) {
1096 XUnmapWindow(dpy, scr->clip_balloon);
1097 scr->flags.clip_balloon_mapped = 0;
1098 } else {
1099 if (desc->parent_type!=WCLASS_DOCK_ICON
1100 || scr->clip_icon != desc->parent) {
1101 XUnmapWindow(dpy, scr->clip_balloon);
1102 scr->flags.clip_balloon_mapped = 0;
1107 if (event->xcrossing.window == event->xcrossing.root
1108 && event->xcrossing.detail == NotifyNormal
1109 && event->xcrossing.detail != NotifyInferior
1110 && wPreferences.focus_mode != WKF_CLICK) {
1112 wSetFocusTo(scr, scr->focused_window);
1115 #ifdef BALLOON_TEXT
1116 wBalloonEnteredObject(scr, desc);
1117 #endif
1121 static void
1122 handleLeaveNotify(XEvent *event)
1124 WObjDescriptor *desc = NULL;
1126 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1127 (XPointer *)&desc)!=XCNOENT) {
1128 if(desc->handle_leavenotify)
1129 (*desc->handle_leavenotify)(desc, event);
1131 if (event->xcrossing.window == event->xcrossing.root
1132 && event->xcrossing.mode == NotifyNormal
1133 && event->xcrossing.detail != NotifyInferior
1134 && wPreferences.focus_mode != WKF_CLICK) {
1136 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1138 wSetFocusTo(scr, NULL);
1143 #ifdef SHAPE
1144 static void
1145 handleShapeNotify(XEvent *event)
1147 XShapeEvent *shev = (XShapeEvent*)event;
1148 WWindow *wwin;
1149 XEvent ev;
1150 #ifdef DEBUG
1151 L("got shape notify");
1152 #endif
1153 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1154 XShapeEvent *sev = (XShapeEvent*)&ev;
1156 if (sev->kind == ShapeBounding) {
1157 if (sev->shaped == shev->shaped) {
1158 *shev = *sev;
1159 } else {
1160 XPutBackEvent(dpy, &ev);
1161 break;
1166 wwin = wWindowFor(shev->window);
1167 if (!wwin || shev->kind != ShapeBounding)
1168 return;
1170 if (!shev->shaped && wwin->flags.shaped) {
1172 wwin->flags.shaped = 0;
1173 wWindowClearShape(wwin);
1175 } else if (shev->shaped) {
1177 wwin->flags.shaped = 1;
1178 wWindowSetShape(wwin);
1181 #endif /* SHAPE */
1183 #ifdef KEEP_XKB_LOCK_STATUS
1184 /* please help ]d if you know what to do */
1185 handleXkbIndicatorStateNotify(XEvent *event)
1187 WWindow *wwin;
1188 WScreen *scr;
1189 XkbStateRec staterec;
1190 int i;
1192 for (i=0; i<wScreenCount; i++) {
1193 scr = wScreenWithNumber(i);
1194 wwin = scr->focused_window;
1195 if (wwin && wwin->flags.focused) {
1196 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1197 if (wwin->frame->languagemode != staterec.group) {
1198 wwin->frame->last_languagemode = wwin->frame->languagemode;
1199 wwin->frame->languagemode = staterec.group;
1201 #ifdef XKB_BUTTON_HINT
1202 if (wwin->frame->titlebar) {
1203 wFrameWindowPaint(wwin->frame);
1205 #endif
1209 #endif /*KEEP_XKB_LOCK_STATUS*/
1211 static void
1212 handleColormapNotify(XEvent *event)
1214 WWindow *wwin;
1215 WScreen *scr;
1216 Bool reinstall = False;
1218 wwin = wWindowFor(event->xcolormap.window);
1219 if (!wwin)
1220 return;
1222 scr = wwin->screen_ptr;
1224 do {
1225 if (wwin) {
1226 if (event->xcolormap.new) {
1227 XWindowAttributes attr;
1229 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1231 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1232 scr->current_colormap = attr.colormap;
1234 reinstall = True;
1235 } else if (event->xcolormap.state == ColormapUninstalled &&
1236 scr->current_colormap == event->xcolormap.colormap) {
1238 /* some bastard app (like XV) removed our colormap */
1240 * can't enforce or things like xscreensaver wont work
1241 * reinstall = True;
1243 } else if (event->xcolormap.state == ColormapInstalled &&
1244 scr->current_colormap == event->xcolormap.colormap) {
1246 /* someone has put our colormap back */
1247 reinstall = False;
1250 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1251 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1253 if (reinstall && scr->current_colormap!=None) {
1254 if (!scr->flags.colormap_stuff_blocked)
1255 XInstallColormap(dpy, scr->current_colormap);
1261 static void
1262 handleFocusIn(XEvent *event)
1264 WWindow *wwin;
1267 * For applications that like stealing the focus.
1269 while (XCheckTypedEvent(dpy, FocusIn, event));
1270 saveTimestamp(event);
1271 if (event->xfocus.mode == NotifyUngrab
1272 || event->xfocus.mode == NotifyGrab
1273 || event->xfocus.detail > NotifyNonlinearVirtual) {
1274 return;
1277 wwin = wWindowFor(event->xfocus.window);
1278 if (wwin && !wwin->flags.focused) {
1279 if (wwin->flags.mapped)
1280 wSetFocusTo(wwin->screen_ptr, wwin);
1281 else
1282 wSetFocusTo(wwin->screen_ptr, NULL);
1283 } else if (!wwin) {
1284 WScreen *scr = wScreenForWindow(event->xfocus.window);
1285 if (scr)
1286 wSetFocusTo(scr, NULL);
1291 static WWindow*
1292 windowUnderPointer(WScreen *scr)
1294 unsigned int mask;
1295 int foo;
1296 Window bar, win;
1298 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1299 &mask))
1300 return wWindowFor(win);
1301 return NULL;
1307 static void
1308 handleKeyPress(XEvent *event)
1310 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1311 WWindow *wwin = scr->focused_window;
1312 int i;
1313 int modifiers;
1314 int command=-1, index;
1315 #ifdef KEEP_XKB_LOCK_STATUS
1316 XkbStateRec staterec;
1317 #endif /*KEEP_XKB_LOCK_STATUS*/
1319 /* ignore CapsLock */
1320 modifiers = event->xkey.state & ValidModMask;
1322 for (i=0; i<WKBD_LAST; i++) {
1323 if (wKeyBindings[i].keycode==0)
1324 continue;
1326 if (wKeyBindings[i].keycode==event->xkey.keycode
1327 && (/*wKeyBindings[i].modifier==0
1328 ||*/ wKeyBindings[i].modifier==modifiers)) {
1329 command = i;
1330 break;
1335 if (command < 0) {
1336 #ifdef LITE
1338 #if 0
1340 #endif
1341 #else
1342 if (!wRootMenuPerformShortcut(event)) {
1343 #endif
1344 static int dontLoop = 0;
1346 if (dontLoop > 10) {
1347 wwarning("problem with key event processing code");
1348 return;
1350 dontLoop++;
1351 /* if the focused window is an internal window, try redispatching
1352 * the event to the managed window, as it can be a WINGs window */
1353 if (wwin && wwin->flags.internal_window
1354 && wwin->client_leader!=None) {
1355 /* client_leader contains the WINGs toplevel */
1356 event->xany.window = wwin->client_leader;
1357 WMHandleEvent(event);
1359 dontLoop--;
1361 return;
1364 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1365 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1367 switch (command) {
1368 #ifndef LITE
1369 case WKBD_ROOTMENU:
1370 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1371 break;
1372 case WKBD_WINDOWLIST:
1373 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1374 break;
1375 #endif /* !LITE */
1376 case WKBD_WINDOWMENU:
1377 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1378 OpenWindowMenu(wwin, wwin->frame_x,
1379 wwin->frame_y+wwin->frame->top_width, True);
1380 break;
1381 case WKBD_MINIATURIZE:
1382 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1383 && !WFLAGP(wwin, no_miniaturizable)) {
1384 CloseWindowMenu(scr);
1386 if (wwin->protocols.MINIATURIZE_WINDOW)
1387 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1388 event->xbutton.time);
1389 else {
1390 wIconifyWindow(wwin);
1393 break;
1394 case WKBD_HIDE:
1395 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1396 WApplication *wapp = wApplicationOf(wwin->main_window);
1397 CloseWindowMenu(scr);
1399 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1400 wHideApplication(wapp);
1403 break;
1404 case WKBD_MAXIMIZE:
1405 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1406 CloseWindowMenu(scr);
1408 if (wwin->flags.maximized) {
1409 wUnmaximizeWindow(wwin);
1410 } else {
1411 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1414 break;
1415 case WKBD_VMAXIMIZE:
1416 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1417 CloseWindowMenu(scr);
1419 if (wwin->flags.maximized) {
1420 wUnmaximizeWindow(wwin);
1421 } else {
1422 wMaximizeWindow(wwin, MAX_VERTICAL);
1425 break;
1426 case WKBD_RAISE:
1427 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1428 CloseWindowMenu(scr);
1430 wRaiseFrame(wwin->frame->core);
1432 break;
1433 case WKBD_LOWER:
1434 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1435 CloseWindowMenu(scr);
1437 wLowerFrame(wwin->frame->core);
1439 break;
1440 case WKBD_RAISELOWER:
1441 /* raise or lower the window under the pointer, not the
1442 * focused one
1444 wwin = windowUnderPointer(scr);
1445 if (wwin)
1446 wRaiseLowerFrame(wwin->frame->core);
1447 break;
1448 case WKBD_SHADE:
1449 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1450 if (wwin->flags.shaded)
1451 wUnshadeWindow(wwin);
1452 else
1453 wShadeWindow(wwin);
1455 break;
1456 case WKBD_MOVERESIZE:
1457 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1458 CloseWindowMenu(scr);
1460 wKeyboardMoveResizeWindow(wwin);
1462 break;
1463 case WKBD_CLOSE:
1464 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1465 CloseWindowMenu(scr);
1466 if (wwin->protocols.DELETE_WINDOW)
1467 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1468 event->xkey.time);
1470 break;
1471 case WKBD_SELECT:
1472 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1473 wSelectWindow(wwin, !wwin->flags.selected);
1475 break;
1476 case WKBD_FOCUSNEXT:
1477 if (wKeyBindings[WKBD_FOCUSNEXT].modifier != 0
1478 && wPreferences.windows_cycling)
1479 StartWindozeCycle(wwin, event, True);
1480 else
1481 CycleWindow(scr, True);
1482 break;
1484 case WKBD_FOCUSPREV:
1485 if (wKeyBindings[WKBD_FOCUSPREV].modifier != 0
1486 && wPreferences.windows_cycling)
1487 StartWindozeCycle(wwin, event, False);
1488 else
1489 CycleWindow(scr, False);
1490 break;
1492 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1493 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1494 i = (scr->current_workspace/10)*10 + wk - 1;\
1495 if (wPreferences.ws_advance || i<scr->workspace_count)\
1496 wWorkspaceChange(scr, i);\
1497 break
1498 #else
1499 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1500 i = (scr->current_workspace/10)*10 + wk - 1;\
1501 if (wPreferences.ws_advance || i<scr->workspace_count)\
1502 wWorkspaceChange(scr, i);\
1503 break
1504 #endif
1505 GOTOWORKS(1);
1506 GOTOWORKS(2);
1507 GOTOWORKS(3);
1508 GOTOWORKS(4);
1509 GOTOWORKS(5);
1510 GOTOWORKS(6);
1511 GOTOWORKS(7);
1512 GOTOWORKS(8);
1513 GOTOWORKS(9);
1514 GOTOWORKS(10);
1515 #undef GOTOWORKS
1516 case WKBD_NEXTWORKSPACE:
1517 wWorkspaceRelativeChange(scr, 1);
1518 break;
1519 case WKBD_PREVWORKSPACE:
1520 wWorkspaceRelativeChange(scr, -1);
1521 break;
1522 case WKBD_WINDOW1:
1523 case WKBD_WINDOW2:
1524 case WKBD_WINDOW3:
1525 case WKBD_WINDOW4:
1526 case WKBD_WINDOW5:
1527 case WKBD_WINDOW6:
1528 case WKBD_WINDOW7:
1529 case WKBD_WINDOW8:
1530 case WKBD_WINDOW9:
1531 case WKBD_WINDOW10:
1533 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1535 index = command-WKBD_WINDOW1;
1537 if (scr->shortcutWindows[index]) {
1538 WMBag *list = scr->shortcutWindows[index];
1539 int cw;
1540 int count = WMGetBagItemCount(list);
1541 WWindow *twin;
1542 WMBagIterator iter;
1543 WWindow *wwin;
1545 wUnselectWindows(scr);
1546 cw = scr->current_workspace;
1548 for (wwin = WMBagLast(list, &iter);
1549 iter != NULL;
1550 wwin = WMBagPrevious(list, &iter)) {
1552 if (count > 1)
1553 wWindowChangeWorkspace(wwin, cw);
1555 wMakeWindowVisible(wwin);
1557 if (count > 1)
1558 wSelectWindow(wwin, True);
1561 /* rotate the order of windows, to create a cycling effect */
1562 twin = WMBagFirst(list, &iter);
1563 WMRemoveFromBag(list, twin);
1564 WMPutInBag(list, twin);
1566 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1568 INITBAG(scr->shortcutWindows[index]);
1569 WMPutInBag(scr->shortcutWindows[index], wwin);
1571 if (wwin->flags.selected && scr->selected_windows) {
1572 WMBag *selwins = scr->selected_windows;
1573 int i;
1575 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1576 WWindow *tmp = WMGetFromBag(selwins, i);
1578 if (tmp != wwin)
1579 WMPutInBag(scr->shortcutWindows[index], tmp);
1582 wSelectWindow(wwin, !wwin->flags.selected);
1583 XFlush(dpy);
1584 wusleep(3000);
1585 wSelectWindow(wwin, !wwin->flags.selected);
1586 XFlush(dpy);
1588 } else if (scr->selected_windows
1589 && WMGetBagItemCount(scr->selected_windows)) {
1591 if (wwin->flags.selected && scr->selected_windows) {
1592 WMBag *selwins = scr->selected_windows;
1593 int i;
1595 INITBAG(scr->shortcutWindows[index]);
1597 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1598 WWindow *tmp = WMGetFromBag(selwins, i);
1600 WMPutInBag(scr->shortcutWindows[index], tmp);
1604 #undef INITBAG
1606 break;
1608 case WKBD_SWITCH_SCREEN:
1609 if (wScreenCount > 1) {
1610 WScreen *scr2;
1611 int i;
1613 /* find index of this screen */
1614 for (i = 0; i < wScreenCount; i++) {
1615 if (wScreenWithNumber(i) == scr)
1616 break;
1618 i++;
1619 if (i >= wScreenCount) {
1620 i = 0;
1622 scr2 = wScreenWithNumber(i);
1624 if (scr2) {
1625 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1626 scr2->scr_width/2, scr2->scr_height/2);
1629 break;
1631 case WKBD_NEXTWSLAYER:
1632 case WKBD_PREVWSLAYER:
1634 int row, column;
1636 row = scr->current_workspace/10;
1637 column = scr->current_workspace%10;
1639 if (command==WKBD_NEXTWSLAYER) {
1640 if ((row+1)*10 < scr->workspace_count)
1641 wWorkspaceChange(scr, column+(row+1)*10);
1642 } else {
1643 if (row > 0)
1644 wWorkspaceChange(scr, column+(row-1)*10);
1647 break;
1648 case WKBD_CLIPLOWER:
1649 if (!wPreferences.flags.noclip)
1650 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1651 break;
1652 case WKBD_CLIPRAISE:
1653 if (!wPreferences.flags.noclip)
1654 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1655 break;
1656 case WKBD_CLIPRAISELOWER:
1657 if (!wPreferences.flags.noclip)
1658 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1659 break;
1660 #ifdef KEEP_XKB_LOCK_STATUS
1661 case WKBD_TOGGLE:
1662 if(wPreferences.modelock) {
1663 /*toggle*/
1664 wwin = scr->focused_window;
1666 if (wwin && wwin->flags.mapped
1667 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1668 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1669 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1671 wwin->frame->languagemode = wwin->frame->last_languagemode;
1672 wwin->frame->last_languagemode = staterec.group;
1673 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1677 break;
1678 #endif /* KEEP_XKB_LOCK_STATUS */
1684 static void
1685 handleMotionNotify(XEvent *event)
1687 WMenu *menu;
1688 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1690 if (wPreferences.scrollable_menus) {
1691 if (scr->flags.jump_back_pending ||
1692 event->xmotion.x_root <= 1 ||
1693 event->xmotion.x_root >= (scr->scr_width - 2) ||
1694 event->xmotion.y_root <= 1 ||
1695 event->xmotion.y_root >= (scr->scr_height - 2)) {
1696 #ifdef DEBUG
1697 L("pointer at screen edge");
1698 #endif
1699 menu = wMenuUnderPointer(scr);
1700 if (menu!=NULL)
1701 wMenuScroll(menu, event);
1704 #if 0
1705 if (event->xmotion.subwindow == None)
1706 return;
1708 if (scr->scrolledFMaximize != None) {
1709 WWindow *twin;
1711 twin = wWindowFor(scr->scrolledFMaximize);
1712 if (twin && twin->frame_y ==) {
1716 scr->scrolledFMaximize = NULL;
1718 } else {
1720 /* scroll full maximized window */
1721 if (event->xmotion.y_root < 1
1722 || event->xmotion.y_root > scr->scr_height - 1) {
1724 wwin = wWindowFor(event->xmotion.subwindow);
1726 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1727 && WFLAGP(wwin, full_maximize)
1728 && event->xmotion.x_root >= wwin->frame_x
1729 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1731 if (!WFLAGP(wwin, no_titlebar)
1732 && wwin->frame_y <= - wwin->frame->top_width) {
1734 wWindowMove(wwin, wwin->frame_x, 0);
1735 wwin->flags.dragged_while_fmaximized = 0;
1737 } else if (!WFLAGP(wwin, no_resizebar)
1738 && wwin->frame_y + wwin->frame->core->height >=
1739 scr->scr_height + wwin->frame->bottom_width) {
1741 int y = scr->scr_height + wwin->frame->bottom_width;
1743 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1745 wWindowMove(wwin, wwin->frame_x, y);
1746 wwin->flags.dragged_while_fmaximized = 0;
1750 #endif
1754 static void
1755 handleVisibilityNotify(XEvent *event)
1757 WWindow *wwin;
1759 wwin = wWindowFor(event->xvisibility.window);
1760 if (!wwin)
1761 return;
1762 wwin->flags.obscured =
1763 (event->xvisibility.state == VisibilityFullyObscured);