Renamed se.po to sv.po
[wmaker-crm.git] / src / event.c
blob2ad6875ba38345f37b00ffbdc77500c23b42d0f1
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) {
640 wWorkspaceRelativeChange(scr, -1);
641 } else if (event->xbutton.button==Button4) {
642 wWorkspaceRelativeChange(scr, 1);
644 #endif /* MOUSE_WS_SWITCH */
645 #ifdef GNOME_STUFF
646 else if (wGNOMEProxyizeButtonEvent(scr, event))
647 return;
648 #endif
650 #endif /* !LITE */
652 desc = NULL;
653 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
654 (XPointer *)&desc)==XCNOENT) {
655 if (XFindContext(dpy, event->xbutton.window, wWinContext,
656 (XPointer *)&desc)==XCNOENT) {
657 return;
661 if (desc->parent_type == WCLASS_WINDOW) {
662 XSync(dpy, 0);
664 if (event->xbutton.state & MOD_MASK) {
665 XAllowEvents(dpy, AsyncPointer, CurrentTime);
668 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
669 if (wPreferences.ignore_focus_click) {
670 XAllowEvents(dpy, AsyncPointer, CurrentTime);
672 XAllowEvents(dpy, ReplayPointer, CurrentTime);
673 /* }*/
674 XSync(dpy, 0);
675 } else if (desc->parent_type == WCLASS_APPICON
676 || desc->parent_type == WCLASS_MINIWINDOW
677 || desc->parent_type == WCLASS_DOCK_ICON) {
678 if (event->xbutton.state & MOD_MASK) {
679 XSync(dpy, 0);
680 XAllowEvents(dpy, AsyncPointer, CurrentTime);
681 XSync(dpy, 0);
685 if (desc->handle_mousedown!=NULL) {
686 (*desc->handle_mousedown)(desc, event);
689 /* save double-click information */
690 if (scr->flags.next_click_is_not_double) {
691 scr->flags.next_click_is_not_double = 0;
692 } else {
693 scr->last_click_time = event->xbutton.time;
694 scr->last_click_button = event->xbutton.button;
695 scr->last_click_window = event->xbutton.window;
700 static void
701 handleMapNotify(XEvent *event)
703 WWindow *wwin;
704 #ifdef DEBUG
705 L("got map");
706 #endif
707 wwin = wWindowFor(event->xmap.event);
708 if (wwin && wwin->client_win == event->xmap.event) {
709 if (wwin->flags.miniaturized) {
710 wDeiconifyWindow(wwin);
711 } else {
712 XGrabServer(dpy);
713 wWindowMap(wwin);
714 wClientSetState(wwin, NormalState, None);
715 XUngrabServer(dpy);
721 static void
722 handleUnmapNotify(XEvent *event)
724 WWindow *wwin;
725 XEvent ev;
726 Bool withdraw = False;
727 #ifdef DEBUG
728 L("got unmap");
729 #endif
730 /* only process windows with StructureNotify selected
731 * (ignore SubstructureNotify) */
732 wwin = wWindowFor(event->xunmap.window);
733 if (!wwin)
734 return;
736 /* whether the event is a Withdrawal request */
737 if (event->xunmap.event == wwin->screen_ptr->root_win
738 && event->xunmap.send_event)
739 withdraw = True;
741 if (wwin->client_win != event->xunmap.event && !withdraw)
742 return;
744 if (!wwin->flags.mapped && !withdraw
745 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
746 && !wwin->flags.miniaturized && !wwin->flags.hidden)
747 return;
749 XGrabServer(dpy);
750 XUnmapWindow(dpy, wwin->frame->core->window);
751 wwin->flags.mapped = 0;
752 XSync(dpy, 0);
753 /* check if the window was destroyed */
754 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
755 DispatchEvent(&ev);
756 } else {
757 Bool reparented = False;
759 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
760 reparented = True;
762 /* withdraw window */
763 wwin->flags.mapped = 0;
764 if (!reparented)
765 wClientSetState(wwin, WithdrawnState, None);
767 /* if the window was reparented, do not reparent it back to the
768 * root window */
769 wUnmanageWindow(wwin, !reparented, False);
771 XUngrabServer(dpy);
775 static void
776 handleConfigureRequest(XEvent *event)
778 WWindow *wwin;
779 #ifdef DEBUG
780 L("got configure request");
781 #endif
782 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
784 * Configure request for unmapped window
786 wClientConfigure(NULL, &(event->xconfigurerequest));
787 } else {
788 wClientConfigure(wwin, &(event->xconfigurerequest));
793 static void
794 handlePropertyNotify(XEvent *event)
796 WWindow *wwin;
797 WApplication *wapp;
798 Window jr;
799 int ji;
800 unsigned int ju;
801 WScreen *scr;
802 #ifdef DEBUG
803 L("got property notify");
804 #endif
805 if ((wwin=wWindowFor(event->xproperty.window))) {
806 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
807 &ju, &ju, &ju, &ju)) {
808 return;
810 wClientCheckProperty(wwin, &event->xproperty);
812 wapp = wApplicationOf(event->xproperty.window);
813 if (wapp) {
814 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
817 scr = wScreenForWindow(event->xproperty.window);
818 if (scr && scr->root_win == event->xproperty.window) {
819 #ifdef KWM_HINTS
820 wKWMCheckRootHintChange(scr, &event->xproperty);
821 #endif
826 static void
827 handleClientMessage(XEvent *event)
829 WWindow *wwin;
830 WObjDescriptor *desc;
831 #ifdef DEBUG
832 L("got client message");
833 #endif
834 /* handle transition from Normal to Iconic state */
835 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
836 && event->xclient.format == 32
837 && event->xclient.data.l[0] == IconicState) {
839 wwin = wWindowFor(event->xclient.window);
840 if (!wwin) return;
841 if (!wwin->flags.miniaturized)
842 wIconifyWindow(wwin);
843 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
844 && event->xclient.format == 32) {
845 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
847 if (!scr)
848 return;
850 if (event->xclient.data.l[1] == 1) { /* starting */
851 wColormapAllowClientInstallation(scr, True);
852 } else { /* stopping */
853 wColormapAllowClientInstallation(scr, False);
855 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
857 wDefaultsCheckDomains("bla");
859 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
860 WApplication *wapp;
861 int done=0;
862 wapp = wApplicationOf(event->xclient.window);
863 if (wapp) {
864 switch (event->xclient.data.l[0]) {
865 case WMFHideOtherApplications:
866 wHideOtherApplications(wapp->main_window_desc);
867 done = 1;
868 break;
870 case WMFHideApplication:
871 wHideApplication(wapp);
872 done = 1;
873 break;
876 if (!done) {
877 wwin = wWindowFor(event->xclient.window);
878 if (wwin) {
879 switch (event->xclient.data.l[0]) {
880 case WMFHideOtherApplications:
881 wHideOtherApplications(wwin);
882 break;
884 case WMFHideApplication:
885 wHideApplication(wApplicationOf(wwin->main_window));
886 break;
890 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
891 wwin = wWindowFor(event->xclient.window);
892 if (!wwin) return;
893 switch (event->xclient.data.l[0]) {
894 case GSWindowLevelAttr:
896 int level = (int)event->xclient.data.l[1];
898 if (WINDOW_LEVEL(wwin) != level) {
899 ChangeStackingLevel(wwin->frame->core, level);
902 break;
904 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
905 wwin = wWindowFor(event->xclient.window);
906 if (!wwin) return;
907 switch (event->xclient.data.l[0]) {
908 case WMTitleBarNormal:
909 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
910 break;
911 case WMTitleBarMain:
912 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
913 break;
914 case WMTitleBarKey:
915 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
916 break;
918 #ifdef GNOME_STUFF
919 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
920 /* do nothing */
921 #endif /* GNOME_STUFF */
922 #ifdef KWM_HINTS
923 } else if (wKWMProcessClientMessage(&event->xclient)) {
924 /* do nothing */
925 #endif /* KWM_HINTS */
926 #ifdef XDND
927 } else if (wXDNDProcessClientMessage(&event->xclient)) {
928 /* do nothing */
929 #endif /* XDND */
930 #ifdef OFFIX_DND
931 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
932 WScreen *scr = wScreenForWindow(event->xclient.window);
933 if (scr && wDockReceiveDNDDrop(scr,event))
934 goto redirect_message;
935 #endif /* OFFIX_DND */
936 } else {
937 #ifdef OFFIX_DND
938 redirect_message:
939 #endif
941 * Non-standard thing, but needed by OffiX DND.
942 * For when the icon frame gets a ClientMessage
943 * that should have gone to the icon_window.
945 if (XFindContext(dpy, event->xbutton.window, wWinContext,
946 (XPointer *)&desc)!=XCNOENT) {
947 struct WIcon *icon=NULL;
949 if (desc->parent_type == WCLASS_MINIWINDOW) {
950 icon = (WIcon*)desc->parent;
951 } else if (desc->parent_type == WCLASS_DOCK_ICON
952 || desc->parent_type == WCLASS_APPICON) {
953 icon = ((WAppIcon*)desc->parent)->icon;
955 if (icon && (wwin=icon->owner)) {
956 if (wwin->client_win!=event->xclient.window) {
957 event->xclient.window = wwin->client_win;
958 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
959 event);
967 static void
968 raiseWindow(WScreen *scr)
970 WWindow *wwin;
972 scr->autoRaiseTimer = NULL;
974 wwin = wWindowFor(scr->autoRaiseWindow);
975 if (!wwin)
976 return;
978 if (!wwin->flags.destroyed && wwin->flags.focused) {
979 wRaiseFrame(wwin->frame->core);
980 /* this is needed or a race condition will occur */
981 XSync(dpy, False);
986 static void
987 handleEnterNotify(XEvent *event)
989 WWindow *wwin;
990 WObjDescriptor *desc = NULL;
991 XEvent ev;
992 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
993 #ifdef DEBUG
994 L("got enter notify");
995 #endif
997 #ifdef VIRTUAL_DESKTOP
998 /* TODO: acceleration code */
999 if (wPreferences.vedge_thickness) {
1000 int x,y;
1001 if (event->xcrossing.window == scr->virtual_edge_r) {
1002 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1003 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1004 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1005 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1006 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, 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_u) {
1010 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1011 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1012 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1013 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1014 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1015 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1016 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1019 #endif
1021 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1022 &ev)) {
1023 /* already left the window... */
1024 saveTimestamp(&ev);
1025 if (ev.xcrossing.mode==event->xcrossing.mode
1026 && ev.xcrossing.detail==event->xcrossing.detail) {
1027 return;
1031 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1032 (XPointer *)&desc)!=XCNOENT) {
1033 if(desc->handle_enternotify)
1034 (*desc->handle_enternotify)(desc, event);
1037 /* enter to window */
1038 wwin = wWindowFor(event->xcrossing.window);
1039 if (!wwin) {
1040 if (wPreferences.focus_mode==WKF_POINTER
1041 && event->xcrossing.window==event->xcrossing.root) {
1042 wSetFocusTo(scr, NULL);
1044 if (wPreferences.colormap_mode==WKF_POINTER) {
1045 wColormapInstallForWindow(scr, NULL);
1047 if (scr->autoRaiseTimer
1048 && event->xcrossing.root==event->xcrossing.window) {
1049 WMDeleteTimerHandler(scr->autoRaiseTimer);
1050 scr->autoRaiseTimer = NULL;
1052 } else {
1053 /* set auto raise timer even if in focus-follows-mouse mode
1054 * and the event is for the frame window, even if the window
1055 * has focus already. useful if you move the pointer from a focused
1056 * window to the root window and back pretty fast
1058 * set focus if in focus-follows-mouse mode and the event
1059 * is for the frame window and window doesn't have focus yet */
1060 if ((wPreferences.focus_mode==WKF_POINTER
1061 || wPreferences.focus_mode==WKF_SLOPPY)
1062 && wwin->frame->core->window==event->xcrossing.window
1063 && !scr->flags.doing_alt_tab) {
1065 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1066 wSetFocusTo(scr, wwin);
1068 if (scr->autoRaiseTimer)
1069 WMDeleteTimerHandler(scr->autoRaiseTimer);
1070 scr->autoRaiseTimer = NULL;
1072 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1073 scr->autoRaiseWindow = wwin->frame->core->window;
1074 scr->autoRaiseTimer
1075 = WMAddTimerHandler(wPreferences.raise_delay,
1076 (WMCallback*)raiseWindow, scr);
1079 /* Install colormap for window, if the colormap installation mode
1080 * is colormap_follows_mouse */
1081 if (wPreferences.colormap_mode==WKF_POINTER) {
1082 if (wwin->client_win==event->xcrossing.window)
1083 wColormapInstallForWindow(scr, wwin);
1084 else
1085 wColormapInstallForWindow(scr, NULL);
1089 /* a little kluge to hide the clip balloon */
1090 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1091 if (!desc) {
1092 XUnmapWindow(dpy, scr->clip_balloon);
1093 scr->flags.clip_balloon_mapped = 0;
1094 } else {
1095 if (desc->parent_type!=WCLASS_DOCK_ICON
1096 || scr->clip_icon != desc->parent) {
1097 XUnmapWindow(dpy, scr->clip_balloon);
1098 scr->flags.clip_balloon_mapped = 0;
1103 if (event->xcrossing.window == event->xcrossing.root
1104 && event->xcrossing.detail == NotifyNormal
1105 && event->xcrossing.detail != NotifyInferior
1106 && wPreferences.focus_mode != WKF_CLICK) {
1108 wSetFocusTo(scr, scr->focused_window);
1111 #ifdef BALLOON_TEXT
1112 wBalloonEnteredObject(scr, desc);
1113 #endif
1117 static void
1118 handleLeaveNotify(XEvent *event)
1120 WObjDescriptor *desc = NULL;
1122 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1123 (XPointer *)&desc)!=XCNOENT) {
1124 if(desc->handle_leavenotify)
1125 (*desc->handle_leavenotify)(desc, event);
1127 if (event->xcrossing.window == event->xcrossing.root
1128 && event->xcrossing.mode == NotifyNormal
1129 && event->xcrossing.detail != NotifyInferior
1130 && wPreferences.focus_mode != WKF_CLICK) {
1132 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1134 wSetFocusTo(scr, NULL);
1139 #ifdef SHAPE
1140 static void
1141 handleShapeNotify(XEvent *event)
1143 XShapeEvent *shev = (XShapeEvent*)event;
1144 WWindow *wwin;
1145 XEvent ev;
1146 #ifdef DEBUG
1147 L("got shape notify");
1148 #endif
1149 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1150 XShapeEvent *sev = (XShapeEvent*)&ev;
1152 if (sev->kind == ShapeBounding) {
1153 if (sev->shaped == shev->shaped) {
1154 *shev = *sev;
1155 } else {
1156 XPutBackEvent(dpy, &ev);
1157 break;
1162 wwin = wWindowFor(shev->window);
1163 if (!wwin || shev->kind != ShapeBounding)
1164 return;
1166 if (!shev->shaped && wwin->flags.shaped) {
1168 wwin->flags.shaped = 0;
1169 wWindowClearShape(wwin);
1171 } else if (shev->shaped) {
1173 wwin->flags.shaped = 1;
1174 wWindowSetShape(wwin);
1177 #endif /* SHAPE */
1179 #ifdef KEEP_XKB_LOCK_STATUS
1180 /* please help ]d if you know what to do */
1181 handleXkbIndicatorStateNotify(XEvent *event)
1183 WWindow *wwin;
1184 WScreen *scr;
1185 XkbStateRec staterec;
1186 int i;
1188 for (i=0; i<wScreenCount; i++) {
1189 scr = wScreenWithNumber(i);
1190 wwin = scr->focused_window;
1191 if (wwin && wwin->flags.focused) {
1192 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1193 if (wwin->frame->languagemode != staterec.group) {
1194 wwin->frame->last_languagemode = wwin->frame->languagemode;
1195 wwin->frame->languagemode = staterec.group;
1197 #ifdef XKB_BUTTON_HINT
1198 if (wwin->frame->titlebar) {
1199 wFrameWindowPaint(wwin->frame);
1201 #endif
1205 #endif /*KEEP_XKB_LOCK_STATUS*/
1207 static void
1208 handleColormapNotify(XEvent *event)
1210 WWindow *wwin;
1211 WScreen *scr;
1212 Bool reinstall = False;
1214 wwin = wWindowFor(event->xcolormap.window);
1215 if (!wwin)
1216 return;
1218 scr = wwin->screen_ptr;
1220 do {
1221 if (wwin) {
1222 if (event->xcolormap.new) {
1223 XWindowAttributes attr;
1225 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1227 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1228 scr->current_colormap = attr.colormap;
1230 reinstall = True;
1231 } else if (event->xcolormap.state == ColormapUninstalled &&
1232 scr->current_colormap == event->xcolormap.colormap) {
1234 /* some bastard app (like XV) removed our colormap */
1236 * can't enforce or things like xscreensaver wont work
1237 * reinstall = True;
1239 } else if (event->xcolormap.state == ColormapInstalled &&
1240 scr->current_colormap == event->xcolormap.colormap) {
1242 /* someone has put our colormap back */
1243 reinstall = False;
1246 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1247 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1249 if (reinstall && scr->current_colormap!=None) {
1250 if (!scr->flags.colormap_stuff_blocked)
1251 XInstallColormap(dpy, scr->current_colormap);
1257 static void
1258 handleFocusIn(XEvent *event)
1260 WWindow *wwin;
1263 * For applications that like stealing the focus.
1265 while (XCheckTypedEvent(dpy, FocusIn, event));
1266 saveTimestamp(event);
1267 if (event->xfocus.mode == NotifyUngrab
1268 || event->xfocus.mode == NotifyGrab
1269 || event->xfocus.detail > NotifyNonlinearVirtual) {
1270 return;
1273 wwin = wWindowFor(event->xfocus.window);
1274 if (wwin && !wwin->flags.focused) {
1275 if (wwin->flags.mapped)
1276 wSetFocusTo(wwin->screen_ptr, wwin);
1277 else
1278 wSetFocusTo(wwin->screen_ptr, NULL);
1279 } else if (!wwin) {
1280 WScreen *scr = wScreenForWindow(event->xfocus.window);
1281 if (scr)
1282 wSetFocusTo(scr, NULL);
1287 static WWindow*
1288 windowUnderPointer(WScreen *scr)
1290 unsigned int mask;
1291 int foo;
1292 Window bar, win;
1294 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1295 &mask))
1296 return wWindowFor(win);
1297 return NULL;
1303 static void
1304 handleKeyPress(XEvent *event)
1306 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1307 WWindow *wwin = scr->focused_window;
1308 int i;
1309 int modifiers;
1310 int command=-1, index;
1311 #ifdef KEEP_XKB_LOCK_STATUS
1312 XkbStateRec staterec;
1313 #endif /*KEEP_XKB_LOCK_STATUS*/
1315 /* ignore CapsLock */
1316 modifiers = event->xkey.state & ValidModMask;
1318 for (i=0; i<WKBD_LAST; i++) {
1319 if (wKeyBindings[i].keycode==0)
1320 continue;
1322 if (wKeyBindings[i].keycode==event->xkey.keycode
1323 && (/*wKeyBindings[i].modifier==0
1324 ||*/ wKeyBindings[i].modifier==modifiers)) {
1325 command = i;
1326 break;
1331 if (command < 0) {
1332 #ifdef LITE
1334 #if 0
1336 #endif
1337 #else
1338 if (!wRootMenuPerformShortcut(event)) {
1339 #endif
1340 static int dontLoop = 0;
1342 if (dontLoop > 10) {
1343 wwarning("problem with key event processing code");
1344 return;
1346 dontLoop++;
1347 /* if the focused window is an internal window, try redispatching
1348 * the event to the managed window, as it can be a WINGs window */
1349 if (wwin && wwin->flags.internal_window
1350 && wwin->client_leader!=None) {
1351 /* client_leader contains the WINGs toplevel */
1352 event->xany.window = wwin->client_leader;
1353 WMHandleEvent(event);
1355 dontLoop--;
1357 return;
1360 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1361 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1363 switch (command) {
1364 #ifndef LITE
1365 case WKBD_ROOTMENU:
1366 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1367 break;
1368 case WKBD_WINDOWLIST:
1369 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1370 break;
1371 #endif /* !LITE */
1372 case WKBD_WINDOWMENU:
1373 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1374 OpenWindowMenu(wwin, wwin->frame_x,
1375 wwin->frame_y+wwin->frame->top_width, True);
1376 break;
1377 case WKBD_MINIATURIZE:
1378 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1379 && !WFLAGP(wwin, no_miniaturizable)) {
1380 CloseWindowMenu(scr);
1382 if (wwin->protocols.MINIATURIZE_WINDOW)
1383 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1384 event->xbutton.time);
1385 else {
1386 wIconifyWindow(wwin);
1389 break;
1390 case WKBD_HIDE:
1391 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1392 WApplication *wapp = wApplicationOf(wwin->main_window);
1393 CloseWindowMenu(scr);
1395 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1396 wHideApplication(wapp);
1399 break;
1400 case WKBD_MAXIMIZE:
1401 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1402 CloseWindowMenu(scr);
1404 if (wwin->flags.maximized) {
1405 wUnmaximizeWindow(wwin);
1406 } else {
1407 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1410 break;
1411 case WKBD_VMAXIMIZE:
1412 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1413 CloseWindowMenu(scr);
1415 if (wwin->flags.maximized) {
1416 wUnmaximizeWindow(wwin);
1417 } else {
1418 wMaximizeWindow(wwin, MAX_VERTICAL);
1421 break;
1422 case WKBD_RAISE:
1423 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1424 CloseWindowMenu(scr);
1426 wRaiseFrame(wwin->frame->core);
1428 break;
1429 case WKBD_LOWER:
1430 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1431 CloseWindowMenu(scr);
1433 wLowerFrame(wwin->frame->core);
1435 break;
1436 case WKBD_RAISELOWER:
1437 /* raise or lower the window under the pointer, not the
1438 * focused one
1440 wwin = windowUnderPointer(scr);
1441 if (wwin)
1442 wRaiseLowerFrame(wwin->frame->core);
1443 break;
1444 case WKBD_SHADE:
1445 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1446 if (wwin->flags.shaded)
1447 wUnshadeWindow(wwin);
1448 else
1449 wShadeWindow(wwin);
1451 break;
1452 case WKBD_MOVERESIZE:
1453 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1454 CloseWindowMenu(scr);
1456 wKeyboardMoveResizeWindow(wwin);
1458 break;
1459 case WKBD_CLOSE:
1460 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1461 CloseWindowMenu(scr);
1462 if (wwin->protocols.DELETE_WINDOW)
1463 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1464 event->xkey.time);
1466 break;
1467 case WKBD_SELECT:
1468 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1469 wSelectWindow(wwin, !wwin->flags.selected);
1471 break;
1472 case WKBD_FOCUSNEXT:
1473 StartWindozeCycle(wwin, event, True);
1474 break;
1476 case WKBD_FOCUSPREV:
1477 StartWindozeCycle(wwin, event, False);
1478 break;
1480 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1481 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1482 i = (scr->current_workspace/10)*10 + wk - 1;\
1483 if (wPreferences.ws_advance || i<scr->workspace_count)\
1484 wWorkspaceChange(scr, i);\
1485 break
1486 #else
1487 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1488 i = (scr->current_workspace/10)*10 + wk - 1;\
1489 if (wPreferences.ws_advance || i<scr->workspace_count)\
1490 wWorkspaceChange(scr, i);\
1491 break
1492 #endif
1493 GOTOWORKS(1);
1494 GOTOWORKS(2);
1495 GOTOWORKS(3);
1496 GOTOWORKS(4);
1497 GOTOWORKS(5);
1498 GOTOWORKS(6);
1499 GOTOWORKS(7);
1500 GOTOWORKS(8);
1501 GOTOWORKS(9);
1502 GOTOWORKS(10);
1503 #undef GOTOWORKS
1504 case WKBD_NEXTWORKSPACE:
1505 wWorkspaceRelativeChange(scr, 1);
1506 break;
1507 case WKBD_PREVWORKSPACE:
1508 wWorkspaceRelativeChange(scr, -1);
1509 break;
1510 case WKBD_WINDOW1:
1511 case WKBD_WINDOW2:
1512 case WKBD_WINDOW3:
1513 case WKBD_WINDOW4:
1514 case WKBD_WINDOW5:
1515 case WKBD_WINDOW6:
1516 case WKBD_WINDOW7:
1517 case WKBD_WINDOW8:
1518 case WKBD_WINDOW9:
1519 case WKBD_WINDOW10:
1521 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1523 index = command-WKBD_WINDOW1;
1525 if (scr->shortcutWindows[index]) {
1526 WMBag *list = scr->shortcutWindows[index];
1527 int cw;
1528 int count = WMGetBagItemCount(list);
1529 WWindow *twin;
1530 WMBagIterator iter;
1531 WWindow *wwin;
1533 wUnselectWindows(scr);
1534 cw = scr->current_workspace;
1536 for (wwin = WMBagLast(list, &iter);
1537 iter != NULL;
1538 wwin = WMBagPrevious(list, &iter)) {
1540 if (count > 1)
1541 wWindowChangeWorkspace(wwin, cw);
1543 wMakeWindowVisible(wwin);
1545 if (count > 1)
1546 wSelectWindow(wwin, True);
1549 /* rotate the order of windows, to create a cycling effect */
1550 twin = WMBagFirst(list, &iter);
1551 WMRemoveFromBag(list, twin);
1552 WMPutInBag(list, twin);
1554 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1556 INITBAG(scr->shortcutWindows[index]);
1557 WMPutInBag(scr->shortcutWindows[index], wwin);
1559 if (wwin->flags.selected && scr->selected_windows) {
1560 WMBag *selwins = scr->selected_windows;
1561 int i;
1563 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1564 WWindow *tmp = WMGetFromBag(selwins, i);
1566 if (tmp != wwin)
1567 WMPutInBag(scr->shortcutWindows[index], tmp);
1570 wSelectWindow(wwin, !wwin->flags.selected);
1571 XFlush(dpy);
1572 wusleep(3000);
1573 wSelectWindow(wwin, !wwin->flags.selected);
1574 XFlush(dpy);
1576 } else if (scr->selected_windows
1577 && WMGetBagItemCount(scr->selected_windows)) {
1579 if (wwin->flags.selected && scr->selected_windows) {
1580 WMBag *selwins = scr->selected_windows;
1581 int i;
1583 INITBAG(scr->shortcutWindows[index]);
1585 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1586 WWindow *tmp = WMGetFromBag(selwins, i);
1588 WMPutInBag(scr->shortcutWindows[index], tmp);
1592 #undef INITBAG
1594 break;
1596 case WKBD_SWITCH_SCREEN:
1597 if (wScreenCount > 1) {
1598 WScreen *scr2;
1599 int i;
1601 /* find index of this screen */
1602 for (i = 0; i < wScreenCount; i++) {
1603 if (wScreenWithNumber(i) == scr)
1604 break;
1606 i++;
1607 if (i >= wScreenCount) {
1608 i = 0;
1610 scr2 = wScreenWithNumber(i);
1612 if (scr2) {
1613 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1614 scr2->scr_width/2, scr2->scr_height/2);
1617 break;
1619 case WKBD_NEXTWSLAYER:
1620 case WKBD_PREVWSLAYER:
1622 int row, column;
1624 row = scr->current_workspace/10;
1625 column = scr->current_workspace%10;
1627 if (command==WKBD_NEXTWSLAYER) {
1628 if ((row+1)*10 < scr->workspace_count)
1629 wWorkspaceChange(scr, column+(row+1)*10);
1630 } else {
1631 if (row > 0)
1632 wWorkspaceChange(scr, column+(row-1)*10);
1635 break;
1636 case WKBD_CLIPLOWER:
1637 if (!wPreferences.flags.noclip)
1638 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1639 break;
1640 case WKBD_CLIPRAISE:
1641 if (!wPreferences.flags.noclip)
1642 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1643 break;
1644 case WKBD_CLIPRAISELOWER:
1645 if (!wPreferences.flags.noclip)
1646 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1647 break;
1648 #ifdef KEEP_XKB_LOCK_STATUS
1649 case WKBD_TOGGLE:
1650 if(wPreferences.modelock) {
1651 /*toggle*/
1652 wwin = scr->focused_window;
1654 if (wwin && wwin->flags.mapped
1655 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1656 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1657 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1659 wwin->frame->languagemode = wwin->frame->last_languagemode;
1660 wwin->frame->last_languagemode = staterec.group;
1661 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1665 break;
1666 #endif /* KEEP_XKB_LOCK_STATUS */
1672 static void
1673 handleMotionNotify(XEvent *event)
1675 WMenu *menu;
1676 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1678 if (wPreferences.scrollable_menus) {
1679 if (scr->flags.jump_back_pending ||
1680 event->xmotion.x_root <= 1 ||
1681 event->xmotion.x_root >= (scr->scr_width - 2) ||
1682 event->xmotion.y_root <= 1 ||
1683 event->xmotion.y_root >= (scr->scr_height - 2)) {
1684 #ifdef DEBUG
1685 L("pointer at screen edge");
1686 #endif
1687 menu = wMenuUnderPointer(scr);
1688 if (menu!=NULL)
1689 wMenuScroll(menu, event);
1692 #if 0
1693 if (event->xmotion.subwindow == None)
1694 return;
1696 if (scr->scrolledFMaximize != None) {
1697 WWindow *twin;
1699 twin = wWindowFor(scr->scrolledFMaximize);
1700 if (twin && twin->frame_y ==) {
1704 scr->scrolledFMaximize = NULL;
1706 } else {
1708 /* scroll full maximized window */
1709 if (event->xmotion.y_root < 1
1710 || event->xmotion.y_root > scr->scr_height - 1) {
1712 wwin = wWindowFor(event->xmotion.subwindow);
1714 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1715 && WFLAGP(wwin, full_maximize)
1716 && event->xmotion.x_root >= wwin->frame_x
1717 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1719 if (!WFLAGP(wwin, no_titlebar)
1720 && wwin->frame_y <= - wwin->frame->top_width) {
1722 wWindowMove(wwin, wwin->frame_x, 0);
1723 wwin->flags.dragged_while_fmaximized = 0;
1725 } else if (!WFLAGP(wwin, no_resizebar)
1726 && wwin->frame_y + wwin->frame->core->height >=
1727 scr->scr_height + wwin->frame->bottom_width) {
1729 int y = scr->scr_height + wwin->frame->bottom_width;
1731 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1733 wWindowMove(wwin, wwin->frame_x, y);
1734 wwin->flags.dragged_while_fmaximized = 0;
1738 #endif
1742 static void
1743 handleVisibilityNotify(XEvent *event)
1745 WWindow *wwin;
1747 wwin = wWindowFor(event->xvisibility.window);
1748 if (!wwin)
1749 return;
1750 wwin->flags.obscured =
1751 (event->xvisibility.state == VisibilityFullyObscured);