estonian translation
[wmaker-crm.git] / src / event.c
blobe166b05ada41adefdd008de11cbd14facede105e
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 WMArray *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 = WMCreateArrayWithDestructor(8, wfree);
179 WMAddToArray(deathHandlers, handler);
181 return handler;
186 void
187 wDeleteDeathHandler(WMagicNumber id)
189 DeathHandler *handler=(DeathHandler*)id;
191 if (!handler || !deathHandlers)
192 return;
194 /* array destructor will call wfree(handler) */
195 WMRemoveFromArray(deathHandlers, handler);
199 void
200 DispatchEvent(XEvent *event)
202 if (deathHandlers)
203 handleDeadProcess(NULL);
205 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
206 WCHANGE_STATE(WSTATE_EXITING);
207 /* received SIGTERM */
209 * WMHandleEvent() can't be called from anything
210 * executed inside here, or we can get in a infinite
211 * recursive loop.
213 Shutdown(WSExitMode);
215 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
216 WCHANGE_STATE(WSTATE_RESTARTING);
218 Shutdown(WSRestartPreparationMode);
219 /* received SIGHUP */
220 Restart(NULL, True);
221 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
222 WCHANGE_STATE(WSTATE_NORMAL);
223 wDefaultsCheckDomains("bla");
226 /* for the case that all that is wanted to be dispatched is
227 * the stuff above */
228 if (!event)
229 return;
231 saveTimestamp(event);
232 switch (event->type) {
233 case MapRequest:
234 handleMapRequest(event);
235 break;
237 case KeyPress:
238 handleKeyPress(event);
239 break;
241 case MotionNotify:
242 handleMotionNotify(event);
243 break;
245 case ConfigureRequest:
246 handleConfigureRequest(event);
247 break;
249 case DestroyNotify:
250 handleDestroyNotify(event);
251 break;
253 case MapNotify:
254 handleMapNotify(event);
255 break;
257 case UnmapNotify:
258 handleUnmapNotify(event);
259 break;
261 case ButtonPress:
262 handleButtonPress(event);
263 break;
265 case Expose:
266 handleExpose(event);
267 break;
269 case PropertyNotify:
270 handlePropertyNotify(event);
271 break;
273 case EnterNotify:
274 handleEnterNotify(event);
275 break;
277 case LeaveNotify:
278 handleLeaveNotify(event);
279 break;
281 case ClientMessage:
282 handleClientMessage(event);
283 break;
285 case ColormapNotify:
286 handleColormapNotify(event);
287 break;
289 case MappingNotify:
290 if (event->xmapping.request == MappingKeyboard
291 || event->xmapping.request == MappingModifier)
292 XRefreshKeyboardMapping(&event->xmapping);
293 break;
295 case FocusIn:
296 handleFocusIn(event);
297 break;
299 case VisibilityNotify:
300 handleVisibilityNotify(event);
301 break;
302 default:
303 handleExtensions(event);
304 break;
310 *----------------------------------------------------------------------
311 * EventLoop-
312 * Processes X and internal events indefinitely.
314 * Returns:
315 * Never returns
317 * Side effects:
318 * The LastTimestamp global variable is updated.
319 *----------------------------------------------------------------------
321 void
322 EventLoop()
324 XEvent event;
326 for(;;) {
327 WMNextEvent(dpy, &event);
328 WMHandleEvent(&event);
334 Bool
335 IsDoubleClick(WScreen *scr, XEvent *event)
337 if ((scr->last_click_time>0) &&
338 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
339 && (event->xbutton.button == scr->last_click_button)
340 && (event->xbutton.window == scr->last_click_window)) {
342 scr->flags.next_click_is_not_double = 1;
343 scr->last_click_time = 0;
344 scr->last_click_window = event->xbutton.window;
346 return True;
348 return False;
352 void
353 NotifyDeadProcess(pid_t pid, unsigned char status)
355 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
356 wwarning("stack overflow: too many dead processes");
357 return;
359 /* stack the process to be handled later,
360 * as this is called from the signal handler */
361 deadProcesses[deadProcessPtr].pid = pid;
362 deadProcesses[deadProcessPtr].exit_status = status;
363 deadProcessPtr++;
367 static void
368 handleDeadProcess(void *foo)
370 DeathHandler *tmp;
371 int i;
373 for (i=0; i<deadProcessPtr; i++) {
374 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
377 if (!deathHandlers) {
378 deadProcessPtr=0;
379 return;
382 /* get the pids on the queue and call handlers */
383 while (deadProcessPtr>0) {
384 deadProcessPtr--;
386 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
387 tmp = WMGetFromArray(deathHandlers, i);
388 if (!tmp)
389 continue;
391 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
392 (*tmp->callback)(tmp->pid,
393 deadProcesses[deadProcessPtr].exit_status,
394 tmp->client_data);
395 wDeleteDeathHandler(tmp);
402 static void
403 saveTimestamp(XEvent *event)
405 LastTimestamp = CurrentTime;
407 switch (event->type) {
408 case ButtonRelease:
409 case ButtonPress:
410 LastTimestamp = event->xbutton.time;
411 break;
412 case KeyPress:
413 case KeyRelease:
414 LastTimestamp = event->xkey.time;
415 break;
416 case MotionNotify:
417 LastTimestamp = event->xmotion.time;
418 break;
419 case PropertyNotify:
420 LastTimestamp = event->xproperty.time;
421 break;
422 case EnterNotify:
423 case LeaveNotify:
424 LastTimestamp = event->xcrossing.time;
425 break;
426 case SelectionClear:
427 LastTimestamp = event->xselectionclear.time;
428 break;
429 case SelectionRequest:
430 LastTimestamp = event->xselectionrequest.time;
431 break;
432 case SelectionNotify:
433 LastTimestamp = event->xselection.time;
434 #ifdef XDND
435 wXDNDProcessSelection(event);
436 #endif
437 break;
442 static void
443 handleExtensions(XEvent *event)
445 #ifdef KEEP_XKB_LOCK_STATUS
446 XkbEvent *xkbevent;
447 xkbevent = (XkbEvent *)event;
448 #endif /*KEEP_XKB_LOCK_STATUS*/
449 #ifdef SHAPE
450 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
451 handleShapeNotify(event);
453 #endif
454 #ifdef KEEP_XKB_LOCK_STATUS
455 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
456 handleXkbIndicatorStateNotify(event);
458 #endif /*KEEP_XKB_LOCK_STATUS*/
462 static void
463 handleMapRequest(XEvent *ev)
465 WWindow *wwin;
466 WScreen *scr = NULL;
467 Window window = ev->xmaprequest.window;
469 #ifdef DEBUG
470 L("got map request for %x\n", (unsigned)window);
471 #endif
472 if ((wwin = wWindowFor(window))) {
473 if (wwin->flags.shaded) {
474 wUnshadeWindow(wwin);
476 /* deiconify window */
477 if (wwin->flags.miniaturized) {
478 wDeiconifyWindow(wwin);
479 } else if (wwin->flags.hidden) {
480 WApplication *wapp = wApplicationOf(wwin->main_window);
481 /* go to the last workspace that the user worked on the app */
482 if (wapp) {
483 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
485 wUnhideApplication(wapp, False, False);
487 return;
490 scr = wScreenForRootWindow(ev->xmaprequest.parent);
492 wwin = wManageWindow(scr, window);
495 * This is to let the Dock know that the application it launched
496 * has already been mapped (eg: it has finished launching).
497 * It is not necessary for normally docked apps, but is needed for
498 * apps that were forcedly docked (like with dockit).
500 if (scr->last_dock) {
501 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
502 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
503 else
504 wDockTrackWindowLaunch(scr->last_dock, window);
507 if (wwin) {
508 wClientSetState(wwin, NormalState, None);
509 if (wwin->flags.maximized) {
510 wMaximizeWindow(wwin, wwin->flags.maximized);
512 if (wwin->flags.shaded) {
513 wwin->flags.shaded = 0;
514 wwin->flags.skip_next_animation = 1;
515 wShadeWindow(wwin);
517 if (wwin->flags.miniaturized) {
518 wwin->flags.miniaturized = 0;
519 wwin->flags.skip_next_animation = 1;
520 wIconifyWindow(wwin);
522 if (wwin->flags.hidden) {
523 WApplication *wapp = wApplicationOf(wwin->main_window);
525 wwin->flags.hidden = 0;
526 wwin->flags.skip_next_animation = 1;
527 if (wapp) {
528 wHideApplication(wapp);
535 static void
536 handleDestroyNotify(XEvent *event)
538 WWindow *wwin;
539 WApplication *app;
540 Window window = event->xdestroywindow.window;
542 #ifdef DEBUG
543 L("got destroy notify");
544 #endif
545 wwin = wWindowFor(window);
546 if (wwin) {
547 wUnmanageWindow(wwin, False, True);
550 app = wApplicationOf(window);
551 if (app) {
552 if (window == app->main_window) {
553 app->refcount = 0;
554 wwin = app->main_window_desc->screen_ptr->focused_window;
555 while (wwin) {
556 if (wwin->main_window == window) {
557 wwin->main_window = None;
559 wwin = wwin->prev;
562 wApplicationDestroy(app);
565 #ifdef KWM_HINTS
566 wKWMCheckDestroy(&event->xdestroywindow);
567 #endif
572 static void
573 handleExpose(XEvent *event)
575 WObjDescriptor *desc;
576 XEvent ev;
578 #ifdef DEBUG
579 L("got expose");
580 #endif
581 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
583 if (XFindContext(dpy, event->xexpose.window, wWinContext,
584 (XPointer *)&desc)==XCNOENT) {
585 return;
588 if (desc->handle_expose) {
589 (*desc->handle_expose)(desc, event);
593 static void
594 executeButtonAction(WScreen *scr, XEvent *event, int action)
596 switch(action) {
597 case WA_SELECT_WINDOWS:
598 wUnselectWindows(scr);
599 wSelectWindows(scr, event);
600 break;
601 case WA_OPEN_APPMENU:
602 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
603 /* ugly hack */
604 if (scr->root_menu) {
605 if (scr->root_menu->brother->flags.mapped)
606 event->xbutton.window = scr->root_menu->brother->frame->core->window;
607 else
608 event->xbutton.window = scr->root_menu->frame->core->window;
610 break;
611 case WA_OPEN_WINLISTMENU:
612 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
613 if (scr->switch_menu) {
614 if (scr->switch_menu->brother->flags.mapped)
615 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
616 else
617 event->xbutton.window = scr->switch_menu->frame->core->window;
619 break;
620 default:
621 break;
626 /* bindable */
627 static void
628 handleButtonPress(XEvent *event)
630 WObjDescriptor *desc;
631 WScreen *scr;
633 #ifdef DEBUG
634 L("got button press");
635 #endif
636 scr = wScreenForRootWindow(event->xbutton.root);
638 #ifdef BALLOON_TEXT
639 wBalloonHide(scr);
640 #endif
643 #ifndef LITE
644 if (event->xbutton.window==scr->root_win) {
645 if (event->xbutton.button==Button1 &&
646 wPreferences.mouse_button1!=WA_NONE) {
647 executeButtonAction(scr, event, wPreferences.mouse_button1);
648 } else if (event->xbutton.button==Button2 &&
649 wPreferences.mouse_button2!=WA_NONE) {
650 executeButtonAction(scr, event, wPreferences.mouse_button2);
651 } else if (event->xbutton.button==Button3 &&
652 wPreferences.mouse_button3!=WA_NONE) {
653 executeButtonAction(scr, event, wPreferences.mouse_button3);
654 } else if (event->xbutton.button==Button4 &&
655 wPreferences.mouse_wheel!=WA_NONE) {
656 wWorkspaceRelativeChange(scr, 1);
657 } else if (event->xbutton.button==Button5 &&
658 wPreferences.mouse_wheel!=WA_NONE) {
659 wWorkspaceRelativeChange(scr, -1);
661 #ifdef GNOME_STUFF
662 else if (wGNOMEProxyizeButtonEvent(scr, event))
663 return;
664 #endif
666 #endif /* !LITE */
668 desc = NULL;
669 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
670 (XPointer *)&desc)==XCNOENT) {
671 if (XFindContext(dpy, event->xbutton.window, wWinContext,
672 (XPointer *)&desc)==XCNOENT) {
673 return;
677 if (desc->parent_type == WCLASS_WINDOW) {
678 XSync(dpy, 0);
680 if (event->xbutton.state & MOD_MASK) {
681 XAllowEvents(dpy, AsyncPointer, CurrentTime);
684 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
685 if (wPreferences.ignore_focus_click) {
686 XAllowEvents(dpy, AsyncPointer, CurrentTime);
688 XAllowEvents(dpy, ReplayPointer, CurrentTime);
689 /* }*/
690 XSync(dpy, 0);
691 } else if (desc->parent_type == WCLASS_APPICON
692 || desc->parent_type == WCLASS_MINIWINDOW
693 || desc->parent_type == WCLASS_DOCK_ICON) {
694 if (event->xbutton.state & MOD_MASK) {
695 XSync(dpy, 0);
696 XAllowEvents(dpy, AsyncPointer, CurrentTime);
697 XSync(dpy, 0);
701 if (desc->handle_mousedown!=NULL) {
702 (*desc->handle_mousedown)(desc, event);
705 /* save double-click information */
706 if (scr->flags.next_click_is_not_double) {
707 scr->flags.next_click_is_not_double = 0;
708 } else {
709 scr->last_click_time = event->xbutton.time;
710 scr->last_click_button = event->xbutton.button;
711 scr->last_click_window = event->xbutton.window;
716 static void
717 handleMapNotify(XEvent *event)
719 WWindow *wwin;
720 #ifdef DEBUG
721 L("got map");
722 #endif
723 wwin = wWindowFor(event->xmap.event);
724 if (wwin && wwin->client_win == event->xmap.event) {
725 if (wwin->flags.miniaturized) {
726 wDeiconifyWindow(wwin);
727 } else {
728 XGrabServer(dpy);
729 wWindowMap(wwin);
730 wClientSetState(wwin, NormalState, None);
731 XUngrabServer(dpy);
737 static void
738 handleUnmapNotify(XEvent *event)
740 WWindow *wwin;
741 XEvent ev;
742 Bool withdraw = False;
743 #ifdef DEBUG
744 L("got unmap");
745 #endif
746 /* only process windows with StructureNotify selected
747 * (ignore SubstructureNotify) */
748 wwin = wWindowFor(event->xunmap.window);
749 if (!wwin)
750 return;
752 /* whether the event is a Withdrawal request */
753 if (event->xunmap.event == wwin->screen_ptr->root_win
754 && event->xunmap.send_event)
755 withdraw = True;
757 if (wwin->client_win != event->xunmap.event && !withdraw)
758 return;
760 if (!wwin->flags.mapped && !withdraw
761 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
762 && !wwin->flags.miniaturized && !wwin->flags.hidden)
763 return;
765 XGrabServer(dpy);
766 XUnmapWindow(dpy, wwin->frame->core->window);
767 wwin->flags.mapped = 0;
768 XSync(dpy, 0);
769 /* check if the window was destroyed */
770 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
771 DispatchEvent(&ev);
772 } else {
773 Bool reparented = False;
775 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
776 reparented = True;
778 /* withdraw window */
779 wwin->flags.mapped = 0;
780 if (!reparented)
781 wClientSetState(wwin, WithdrawnState, None);
783 /* if the window was reparented, do not reparent it back to the
784 * root window */
785 wUnmanageWindow(wwin, !reparented, False);
787 XUngrabServer(dpy);
791 static void
792 handleConfigureRequest(XEvent *event)
794 WWindow *wwin;
795 #ifdef DEBUG
796 L("got configure request");
797 #endif
798 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
800 * Configure request for unmapped window
802 wClientConfigure(NULL, &(event->xconfigurerequest));
803 } else {
804 wClientConfigure(wwin, &(event->xconfigurerequest));
809 static void
810 handlePropertyNotify(XEvent *event)
812 WWindow *wwin;
813 WApplication *wapp;
814 Window jr;
815 int ji;
816 unsigned int ju;
817 WScreen *scr;
818 #ifdef DEBUG
819 L("got property notify");
820 #endif
821 if ((wwin=wWindowFor(event->xproperty.window))) {
822 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
823 &ju, &ju, &ju, &ju)) {
824 return;
826 wClientCheckProperty(wwin, &event->xproperty);
828 wapp = wApplicationOf(event->xproperty.window);
829 if (wapp) {
830 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
833 scr = wScreenForWindow(event->xproperty.window);
834 if (scr && scr->root_win == event->xproperty.window) {
835 #ifdef KWM_HINTS
836 wKWMCheckRootHintChange(scr, &event->xproperty);
837 #endif
842 static void
843 handleClientMessage(XEvent *event)
845 WWindow *wwin;
846 WObjDescriptor *desc;
847 #ifdef DEBUG
848 L("got client message");
849 #endif
850 /* handle transition from Normal to Iconic state */
851 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
852 && event->xclient.format == 32
853 && event->xclient.data.l[0] == IconicState) {
855 wwin = wWindowFor(event->xclient.window);
856 if (!wwin) return;
857 if (!wwin->flags.miniaturized)
858 wIconifyWindow(wwin);
859 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
860 && event->xclient.format == 32) {
861 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
863 if (!scr)
864 return;
866 if (event->xclient.data.l[1] == 1) { /* starting */
867 wColormapAllowClientInstallation(scr, True);
868 } else { /* stopping */
869 wColormapAllowClientInstallation(scr, False);
871 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
873 wDefaultsCheckDomains("bla");
875 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
876 WApplication *wapp;
877 int done=0;
878 wapp = wApplicationOf(event->xclient.window);
879 if (wapp) {
880 switch (event->xclient.data.l[0]) {
881 case WMFHideOtherApplications:
882 wHideOtherApplications(wapp->main_window_desc);
883 done = 1;
884 break;
886 case WMFHideApplication:
887 wHideApplication(wapp);
888 done = 1;
889 break;
892 if (!done) {
893 wwin = wWindowFor(event->xclient.window);
894 if (wwin) {
895 switch (event->xclient.data.l[0]) {
896 case WMFHideOtherApplications:
897 wHideOtherApplications(wwin);
898 break;
900 case WMFHideApplication:
901 wHideApplication(wApplicationOf(wwin->main_window));
902 break;
906 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
907 wwin = wWindowFor(event->xclient.window);
908 if (!wwin) return;
909 switch (event->xclient.data.l[0]) {
910 case GSWindowLevelAttr:
912 int level = (int)event->xclient.data.l[1];
914 if (WINDOW_LEVEL(wwin) != level) {
915 ChangeStackingLevel(wwin->frame->core, level);
918 break;
920 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
921 wwin = wWindowFor(event->xclient.window);
922 if (!wwin) return;
923 switch (event->xclient.data.l[0]) {
924 case WMTitleBarNormal:
925 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
926 break;
927 case WMTitleBarMain:
928 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
929 break;
930 case WMTitleBarKey:
931 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
932 break;
934 #ifdef GNOME_STUFF
935 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
936 /* do nothing */
937 #endif /* GNOME_STUFF */
938 #ifdef KWM_HINTS
939 } else if (wKWMProcessClientMessage(&event->xclient)) {
940 /* do nothing */
941 #endif /* KWM_HINTS */
942 #ifdef XDND
943 } else if (wXDNDProcessClientMessage(&event->xclient)) {
944 /* do nothing */
945 #endif /* XDND */
946 #ifdef OFFIX_DND
947 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
948 WScreen *scr = wScreenForWindow(event->xclient.window);
949 if (scr && wDockReceiveDNDDrop(scr,event))
950 goto redirect_message;
951 #endif /* OFFIX_DND */
952 } else {
953 #ifdef OFFIX_DND
954 redirect_message:
955 #endif
957 * Non-standard thing, but needed by OffiX DND.
958 * For when the icon frame gets a ClientMessage
959 * that should have gone to the icon_window.
961 if (XFindContext(dpy, event->xbutton.window, wWinContext,
962 (XPointer *)&desc)!=XCNOENT) {
963 struct WIcon *icon=NULL;
965 if (desc->parent_type == WCLASS_MINIWINDOW) {
966 icon = (WIcon*)desc->parent;
967 } else if (desc->parent_type == WCLASS_DOCK_ICON
968 || desc->parent_type == WCLASS_APPICON) {
969 icon = ((WAppIcon*)desc->parent)->icon;
971 if (icon && (wwin=icon->owner)) {
972 if (wwin->client_win!=event->xclient.window) {
973 event->xclient.window = wwin->client_win;
974 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
975 event);
983 static void
984 raiseWindow(WScreen *scr)
986 WWindow *wwin;
988 scr->autoRaiseTimer = NULL;
990 wwin = wWindowFor(scr->autoRaiseWindow);
991 if (!wwin)
992 return;
994 if (!wwin->flags.destroyed && wwin->flags.focused) {
995 wRaiseFrame(wwin->frame->core);
996 /* this is needed or a race condition will occur */
997 XSync(dpy, False);
1002 static void
1003 handleEnterNotify(XEvent *event)
1005 WWindow *wwin;
1006 WObjDescriptor *desc = NULL;
1007 XEvent ev;
1008 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1009 #ifdef DEBUG
1010 L("got enter notify");
1011 #endif
1013 #ifdef VIRTUAL_DESKTOP
1014 /* TODO: acceleration code */
1015 if (wPreferences.vedge_thickness) {
1016 int x,y;
1017 if (event->xcrossing.window == scr->virtual_edge_r) {
1018 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1019 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1020 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1021 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1022 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1023 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1024 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1025 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1026 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1027 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1028 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1029 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1030 printf("enter bottom\n");
1031 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1032 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1033 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1036 #endif
1038 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1039 &ev)) {
1040 /* already left the window... */
1041 saveTimestamp(&ev);
1042 if (ev.xcrossing.mode==event->xcrossing.mode
1043 && ev.xcrossing.detail==event->xcrossing.detail) {
1044 return;
1048 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1049 (XPointer *)&desc)!=XCNOENT) {
1050 if(desc->handle_enternotify)
1051 (*desc->handle_enternotify)(desc, event);
1054 /* enter to window */
1055 wwin = wWindowFor(event->xcrossing.window);
1056 if (!wwin) {
1057 if (wPreferences.colormap_mode==WCM_POINTER) {
1058 wColormapInstallForWindow(scr, NULL);
1060 if (scr->autoRaiseTimer
1061 && event->xcrossing.root==event->xcrossing.window) {
1062 WMDeleteTimerHandler(scr->autoRaiseTimer);
1063 scr->autoRaiseTimer = NULL;
1065 } else {
1066 /* set auto raise timer even if in focus-follows-mouse mode
1067 * and the event is for the frame window, even if the window
1068 * has focus already. useful if you move the pointer from a focused
1069 * window to the root window and back pretty fast
1071 * set focus if in focus-follows-mouse mode and the event
1072 * is for the frame window and window doesn't have focus yet */
1073 if (wPreferences.focus_mode==WKF_SLOPPY
1074 && wwin->frame->core->window==event->xcrossing.window
1075 && !scr->flags.doing_alt_tab) {
1077 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1078 wSetFocusTo(scr, wwin);
1080 if (scr->autoRaiseTimer)
1081 WMDeleteTimerHandler(scr->autoRaiseTimer);
1082 scr->autoRaiseTimer = NULL;
1084 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1085 scr->autoRaiseWindow = wwin->frame->core->window;
1086 scr->autoRaiseTimer
1087 = WMAddTimerHandler(wPreferences.raise_delay,
1088 (WMCallback*)raiseWindow, scr);
1091 /* Install colormap for window, if the colormap installation mode
1092 * is colormap_follows_mouse */
1093 if (wPreferences.colormap_mode==WCM_POINTER) {
1094 if (wwin->client_win==event->xcrossing.window)
1095 wColormapInstallForWindow(scr, wwin);
1096 else
1097 wColormapInstallForWindow(scr, NULL);
1101 /* a little kluge to hide the clip balloon */
1102 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1103 if (!desc) {
1104 XUnmapWindow(dpy, scr->clip_balloon);
1105 scr->flags.clip_balloon_mapped = 0;
1106 } else {
1107 if (desc->parent_type!=WCLASS_DOCK_ICON
1108 || scr->clip_icon != desc->parent) {
1109 XUnmapWindow(dpy, scr->clip_balloon);
1110 scr->flags.clip_balloon_mapped = 0;
1115 if (event->xcrossing.window == event->xcrossing.root
1116 && event->xcrossing.detail == NotifyNormal
1117 && event->xcrossing.detail != NotifyInferior
1118 && wPreferences.focus_mode != WKF_CLICK) {
1120 wSetFocusTo(scr, scr->focused_window);
1123 #ifdef BALLOON_TEXT
1124 wBalloonEnteredObject(scr, desc);
1125 #endif
1129 static void
1130 handleLeaveNotify(XEvent *event)
1132 WObjDescriptor *desc = NULL;
1134 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1135 (XPointer *)&desc)!=XCNOENT) {
1136 if(desc->handle_leavenotify)
1137 (*desc->handle_leavenotify)(desc, event);
1139 if (event->xcrossing.window == event->xcrossing.root
1140 && event->xcrossing.mode == NotifyNormal
1141 && event->xcrossing.detail != NotifyInferior
1142 && wPreferences.focus_mode != WKF_CLICK) {
1144 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1146 wSetFocusTo(scr, NULL);
1151 #ifdef SHAPE
1152 static void
1153 handleShapeNotify(XEvent *event)
1155 XShapeEvent *shev = (XShapeEvent*)event;
1156 WWindow *wwin;
1157 XEvent ev;
1158 #ifdef DEBUG
1159 L("got shape notify");
1160 #endif
1161 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1162 XShapeEvent *sev = (XShapeEvent*)&ev;
1164 if (sev->kind == ShapeBounding) {
1165 if (sev->shaped == shev->shaped) {
1166 *shev = *sev;
1167 } else {
1168 XPutBackEvent(dpy, &ev);
1169 break;
1174 wwin = wWindowFor(shev->window);
1175 if (!wwin || shev->kind != ShapeBounding)
1176 return;
1178 if (!shev->shaped && wwin->flags.shaped) {
1180 wwin->flags.shaped = 0;
1181 wWindowClearShape(wwin);
1183 } else if (shev->shaped) {
1185 wwin->flags.shaped = 1;
1186 wWindowSetShape(wwin);
1189 #endif /* SHAPE */
1191 #ifdef KEEP_XKB_LOCK_STATUS
1192 /* please help ]d if you know what to do */
1193 handleXkbIndicatorStateNotify(XEvent *event)
1195 WWindow *wwin;
1196 WScreen *scr;
1197 XkbStateRec staterec;
1198 int i;
1200 for (i=0; i<wScreenCount; i++) {
1201 scr = wScreenWithNumber(i);
1202 wwin = scr->focused_window;
1203 if (wwin && wwin->flags.focused) {
1204 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1205 if (wwin->frame->languagemode != staterec.group) {
1206 wwin->frame->last_languagemode = wwin->frame->languagemode;
1207 wwin->frame->languagemode = staterec.group;
1209 #ifdef XKB_BUTTON_HINT
1210 if (wwin->frame->titlebar) {
1211 wFrameWindowPaint(wwin->frame);
1213 #endif
1217 #endif /*KEEP_XKB_LOCK_STATUS*/
1219 static void
1220 handleColormapNotify(XEvent *event)
1222 WWindow *wwin;
1223 WScreen *scr;
1224 Bool reinstall = False;
1226 wwin = wWindowFor(event->xcolormap.window);
1227 if (!wwin)
1228 return;
1230 scr = wwin->screen_ptr;
1232 do {
1233 if (wwin) {
1234 if (event->xcolormap.new) {
1235 XWindowAttributes attr;
1237 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1239 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1240 scr->current_colormap = attr.colormap;
1242 reinstall = True;
1243 } else if (event->xcolormap.state == ColormapUninstalled &&
1244 scr->current_colormap == event->xcolormap.colormap) {
1246 /* some bastard app (like XV) removed our colormap */
1248 * can't enforce or things like xscreensaver wont work
1249 * reinstall = True;
1251 } else if (event->xcolormap.state == ColormapInstalled &&
1252 scr->current_colormap == event->xcolormap.colormap) {
1254 /* someone has put our colormap back */
1255 reinstall = False;
1258 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1259 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1261 if (reinstall && scr->current_colormap!=None) {
1262 if (!scr->flags.colormap_stuff_blocked)
1263 XInstallColormap(dpy, scr->current_colormap);
1269 static void
1270 handleFocusIn(XEvent *event)
1272 WWindow *wwin;
1275 * For applications that like stealing the focus.
1277 while (XCheckTypedEvent(dpy, FocusIn, event));
1278 saveTimestamp(event);
1279 if (event->xfocus.mode == NotifyUngrab
1280 || event->xfocus.mode == NotifyGrab
1281 || event->xfocus.detail > NotifyNonlinearVirtual) {
1282 return;
1285 wwin = wWindowFor(event->xfocus.window);
1286 if (wwin && !wwin->flags.focused) {
1287 if (wwin->flags.mapped)
1288 wSetFocusTo(wwin->screen_ptr, wwin);
1289 else
1290 wSetFocusTo(wwin->screen_ptr, NULL);
1291 } else if (!wwin) {
1292 WScreen *scr = wScreenForWindow(event->xfocus.window);
1293 if (scr)
1294 wSetFocusTo(scr, NULL);
1299 static WWindow*
1300 windowUnderPointer(WScreen *scr)
1302 unsigned int mask;
1303 int foo;
1304 Window bar, win;
1306 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1307 &mask))
1308 return wWindowFor(win);
1309 return NULL;
1315 static void
1316 handleKeyPress(XEvent *event)
1318 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1319 WWindow *wwin = scr->focused_window;
1320 int i;
1321 int modifiers;
1322 int command=-1, index;
1323 #ifdef KEEP_XKB_LOCK_STATUS
1324 XkbStateRec staterec;
1325 #endif /*KEEP_XKB_LOCK_STATUS*/
1327 /* ignore CapsLock */
1328 modifiers = event->xkey.state & ValidModMask;
1330 for (i=0; i<WKBD_LAST; i++) {
1331 if (wKeyBindings[i].keycode==0)
1332 continue;
1334 if (wKeyBindings[i].keycode==event->xkey.keycode
1335 && (/*wKeyBindings[i].modifier==0
1336 ||*/ wKeyBindings[i].modifier==modifiers)) {
1337 command = i;
1338 break;
1343 if (command < 0) {
1344 #ifdef LITE
1346 #if 0
1348 #endif
1349 #else
1350 if (!wRootMenuPerformShortcut(event)) {
1351 #endif
1352 static int dontLoop = 0;
1354 if (dontLoop > 10) {
1355 wwarning("problem with key event processing code");
1356 return;
1358 dontLoop++;
1359 /* if the focused window is an internal window, try redispatching
1360 * the event to the managed window, as it can be a WINGs window */
1361 if (wwin && wwin->flags.internal_window
1362 && wwin->client_leader!=None) {
1363 /* client_leader contains the WINGs toplevel */
1364 event->xany.window = wwin->client_leader;
1365 WMHandleEvent(event);
1367 dontLoop--;
1369 return;
1372 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1373 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1375 switch (command) {
1376 #ifndef LITE
1377 case WKBD_ROOTMENU:
1378 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1379 OpenRootMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1380 break;
1381 case WKBD_WINDOWLIST:
1382 /*OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1383 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1384 break;
1385 #endif /* !LITE */
1386 case WKBD_WINDOWMENU:
1387 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1388 OpenWindowMenu(wwin, wwin->frame_x,
1389 wwin->frame_y+wwin->frame->top_width, True);
1390 break;
1391 case WKBD_MINIATURIZE:
1392 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1393 && !WFLAGP(wwin, no_miniaturizable)) {
1394 CloseWindowMenu(scr);
1396 if (wwin->protocols.MINIATURIZE_WINDOW)
1397 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1398 event->xbutton.time);
1399 else {
1400 wIconifyWindow(wwin);
1403 break;
1404 case WKBD_HIDE:
1405 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1406 WApplication *wapp = wApplicationOf(wwin->main_window);
1407 CloseWindowMenu(scr);
1409 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1410 wHideApplication(wapp);
1413 break;
1414 case WKBD_MAXIMIZE:
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|MAX_HORIZONTAL);
1424 break;
1425 case WKBD_VMAXIMIZE:
1426 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1427 CloseWindowMenu(scr);
1429 if (wwin->flags.maximized) {
1430 wUnmaximizeWindow(wwin);
1431 } else {
1432 wMaximizeWindow(wwin, MAX_VERTICAL);
1435 break;
1436 case WKBD_HMAXIMIZE:
1437 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1438 CloseWindowMenu(scr);
1440 if (wwin->flags.maximized) {
1441 wUnmaximizeWindow(wwin);
1442 } else {
1443 wMaximizeWindow(wwin, MAX_HORIZONTAL);
1446 break;
1447 case WKBD_RAISE:
1448 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1449 CloseWindowMenu(scr);
1451 wRaiseFrame(wwin->frame->core);
1453 break;
1454 case WKBD_LOWER:
1455 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1456 CloseWindowMenu(scr);
1458 wLowerFrame(wwin->frame->core);
1460 break;
1461 case WKBD_RAISELOWER:
1462 /* raise or lower the window under the pointer, not the
1463 * focused one
1465 wwin = windowUnderPointer(scr);
1466 if (wwin)
1467 wRaiseLowerFrame(wwin->frame->core);
1468 break;
1469 case WKBD_SHADE:
1470 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1471 if (wwin->flags.shaded)
1472 wUnshadeWindow(wwin);
1473 else
1474 wShadeWindow(wwin);
1476 break;
1477 case WKBD_MOVERESIZE:
1478 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1479 CloseWindowMenu(scr);
1481 wKeyboardMoveResizeWindow(wwin);
1483 break;
1484 case WKBD_CLOSE:
1485 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1486 CloseWindowMenu(scr);
1487 if (wwin->protocols.DELETE_WINDOW)
1488 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1489 event->xkey.time);
1491 break;
1492 case WKBD_SELECT:
1493 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1494 wSelectWindow(wwin, !wwin->flags.selected);
1496 break;
1497 case WKBD_FOCUSNEXT:
1498 StartWindozeCycle(wwin, event, True);
1499 break;
1501 case WKBD_FOCUSPREV:
1502 StartWindozeCycle(wwin, event, False);
1503 break;
1505 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1506 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1507 i = (scr->current_workspace/10)*10 + wk - 1;\
1508 if (wPreferences.ws_advance || i<scr->workspace_count)\
1509 wWorkspaceChange(scr, i);\
1510 break
1511 #else
1512 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1513 i = (scr->current_workspace/10)*10 + wk - 1;\
1514 if (wPreferences.ws_advance || i<scr->workspace_count)\
1515 wWorkspaceChange(scr, i);\
1516 break
1517 #endif
1518 GOTOWORKS(1);
1519 GOTOWORKS(2);
1520 GOTOWORKS(3);
1521 GOTOWORKS(4);
1522 GOTOWORKS(5);
1523 GOTOWORKS(6);
1524 GOTOWORKS(7);
1525 GOTOWORKS(8);
1526 GOTOWORKS(9);
1527 GOTOWORKS(10);
1528 #undef GOTOWORKS
1529 case WKBD_NEXTWORKSPACE:
1530 wWorkspaceRelativeChange(scr, 1);
1531 break;
1532 case WKBD_PREVWORKSPACE:
1533 wWorkspaceRelativeChange(scr, -1);
1534 break;
1535 case WKBD_WINDOW1:
1536 case WKBD_WINDOW2:
1537 case WKBD_WINDOW3:
1538 case WKBD_WINDOW4:
1539 case WKBD_WINDOW5:
1540 case WKBD_WINDOW6:
1541 case WKBD_WINDOW7:
1542 case WKBD_WINDOW8:
1543 case WKBD_WINDOW9:
1544 case WKBD_WINDOW10:
1546 index = command-WKBD_WINDOW1;
1548 if (scr->shortcutWindows[index]) {
1549 WMArray *list = scr->shortcutWindows[index];
1550 int cw;
1551 int count = WMGetArrayItemCount(list);
1552 WWindow *twin;
1553 WMArrayIterator iter;
1554 WWindow *wwin;
1556 wUnselectWindows(scr);
1557 cw = scr->current_workspace;
1559 WM_ETARETI_ARRAY(list, wwin, iter) {
1560 if (count > 1)
1561 wWindowChangeWorkspace(wwin, cw);
1563 wMakeWindowVisible(wwin);
1565 if (count > 1)
1566 wSelectWindow(wwin, True);
1569 /* rotate the order of windows, to create a cycling effect */
1570 twin = WMGetFromArray(list, 0);
1571 WMDeleteFromArray(list, 0);
1572 WMAddToArray(list, twin);
1574 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1575 if (scr->shortcutWindows[index]) {
1576 WMFreeArray(scr->shortcutWindows[index]);
1577 scr->shortcutWindows[index] = NULL;
1580 if (wwin->flags.selected && scr->selected_windows) {
1581 scr->shortcutWindows[index] =
1582 WMDuplicateArray(scr->selected_windows);
1583 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1584 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1585 } else {
1586 scr->shortcutWindows[index] = WMCreateArray(4);
1587 WMAddToArray(scr->shortcutWindows[index], wwin);
1590 wSelectWindow(wwin, !wwin->flags.selected);
1591 XFlush(dpy);
1592 wusleep(3000);
1593 wSelectWindow(wwin, !wwin->flags.selected);
1594 XFlush(dpy);
1596 } else if (scr->selected_windows
1597 && WMGetArrayItemCount(scr->selected_windows)) {
1599 if (wwin->flags.selected && scr->selected_windows) {
1600 if (scr->shortcutWindows[index]) {
1601 WMFreeArray(scr->shortcutWindows[index]);
1603 scr->shortcutWindows[index] =
1604 WMDuplicateArray(scr->selected_windows);
1608 break;
1610 case WKBD_SWITCH_SCREEN:
1611 if (wScreenCount > 1) {
1612 WScreen *scr2;
1613 int i;
1615 /* find index of this screen */
1616 for (i = 0; i < wScreenCount; i++) {
1617 if (wScreenWithNumber(i) == scr)
1618 break;
1620 i++;
1621 if (i >= wScreenCount) {
1622 i = 0;
1624 scr2 = wScreenWithNumber(i);
1626 if (scr2) {
1627 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1628 scr2->scr_width/2, scr2->scr_height/2);
1631 break;
1633 case WKBD_NEXTWSLAYER:
1634 case WKBD_PREVWSLAYER:
1636 int row, column;
1638 row = scr->current_workspace/10;
1639 column = scr->current_workspace%10;
1641 if (command==WKBD_NEXTWSLAYER) {
1642 if ((row+1)*10 < scr->workspace_count)
1643 wWorkspaceChange(scr, column+(row+1)*10);
1644 } else {
1645 if (row > 0)
1646 wWorkspaceChange(scr, column+(row-1)*10);
1649 break;
1650 case WKBD_CLIPLOWER:
1651 if (!wPreferences.flags.noclip)
1652 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1653 break;
1654 case WKBD_CLIPRAISE:
1655 if (!wPreferences.flags.noclip)
1656 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1657 break;
1658 case WKBD_CLIPRAISELOWER:
1659 if (!wPreferences.flags.noclip)
1660 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1661 break;
1662 #ifdef KEEP_XKB_LOCK_STATUS
1663 case WKBD_TOGGLE:
1664 if(wPreferences.modelock) {
1665 /*toggle*/
1666 wwin = scr->focused_window;
1668 if (wwin && wwin->flags.mapped
1669 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1670 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1671 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1673 wwin->frame->languagemode = wwin->frame->last_languagemode;
1674 wwin->frame->last_languagemode = staterec.group;
1675 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1679 break;
1680 #endif /* KEEP_XKB_LOCK_STATUS */
1686 static void
1687 handleMotionNotify(XEvent *event)
1689 WMenu *menu;
1690 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1692 if (wPreferences.scrollable_menus) {
1693 if (scr->flags.jump_back_pending ||
1694 event->xmotion.x_root <= 1 ||
1695 event->xmotion.x_root >= (scr->scr_width - 2) ||
1696 event->xmotion.y_root <= 1 ||
1697 event->xmotion.y_root >= (scr->scr_height - 2)) {
1698 #ifdef DEBUG
1699 L("pointer at screen edge");
1700 #endif
1701 menu = wMenuUnderPointer(scr);
1702 if (menu!=NULL)
1703 wMenuScroll(menu, event);
1706 #if 0
1707 if (event->xmotion.subwindow == None)
1708 return;
1710 if (scr->scrolledFMaximize != None) {
1711 WWindow *twin;
1713 twin = wWindowFor(scr->scrolledFMaximize);
1714 if (twin && twin->frame_y ==) {
1718 scr->scrolledFMaximize = NULL;
1720 } else {
1722 /* scroll full maximized window */
1723 if (event->xmotion.y_root < 1
1724 || event->xmotion.y_root > scr->scr_height - 1) {
1726 wwin = wWindowFor(event->xmotion.subwindow);
1728 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1729 && WFLAGP(wwin, full_maximize)
1730 && event->xmotion.x_root >= wwin->frame_x
1731 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1733 if (!WFLAGP(wwin, no_titlebar)
1734 && wwin->frame_y <= - wwin->frame->top_width) {
1736 wWindowMove(wwin, wwin->frame_x, 0);
1737 wwin->flags.dragged_while_fmaximized = 0;
1739 } else if (!WFLAGP(wwin, no_resizebar)
1740 && wwin->frame_y + wwin->frame->core->height >=
1741 scr->scr_height + wwin->frame->bottom_width) {
1743 int y = scr->scr_height + wwin->frame->bottom_width;
1745 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1747 wWindowMove(wwin, wwin->frame_x, y);
1748 wwin->flags.dragged_while_fmaximized = 0;
1752 #endif
1756 static void
1757 handleVisibilityNotify(XEvent *event)
1759 WWindow *wwin;
1761 wwin = wWindowFor(event->xvisibility.window);
1762 if (!wwin)
1763 return;
1764 wwin->flags.obscured =
1765 (event->xvisibility.state == VisibilityFullyObscured);