*** empty log message ***
[wmaker-crm.git] / src / event.c
blob98f9a15cf8174bb18cda5b237c496c1e04ecd33f
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>
32 #include <nana.h>
35 #include <X11/Xlib.h>
36 #include <X11/Xutil.h>
37 #ifdef SHAPE
38 # include <X11/extensions/shape.h>
39 #endif
40 #ifdef XDND
41 #include "xdnd.h"
42 #endif
44 #ifdef KEEP_XKB_LOCK_STATUS
45 #include <X11/XKBlib.h>
46 #endif /* KEEP_XKB_LOCK_STATUS */
48 #include "WindowMaker.h"
49 #include "window.h"
50 #include "actions.h"
51 #include "client.h"
52 #include "funcs.h"
53 #include "keybind.h"
54 #include "application.h"
55 #include "stacking.h"
56 #include "defaults.h"
57 #include "workspace.h"
58 #include "dock.h"
59 #include "framewin.h"
60 #include "properties.h"
61 #include "balloon.h"
63 #ifdef GNOME_STUFF
64 # include "gnome.h"
65 #endif
66 #ifdef KWM_HINTS
67 # include "kwm.h"
68 #endif
70 /******** Global Variables **********/
71 extern XContext wWinContext;
73 extern Cursor wCursor[WCUR_LAST];
75 extern WShortKey wKeyBindings[WKBD_LAST];
76 extern int wScreenCount;
77 extern Time LastTimestamp;
78 extern Time LastFocusChange;
80 extern WPreferences wPreferences;
82 #define MOD_MASK wPreferences.modifier_mask
84 extern Atom _XA_WM_COLORMAP_NOTIFY;
86 extern Atom _XA_WM_CHANGE_STATE;
87 extern Atom _XA_WM_DELETE_WINDOW;
88 extern Atom _XA_GNUSTEP_WM_ATTR;
89 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
90 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
91 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
92 extern Atom _XA_WINDOWMAKER_COMMAND;
94 #ifdef OFFIX_DND
95 extern Atom _XA_DND_PROTOCOL;
96 #endif
99 #ifdef SHAPE
100 extern Bool wShapeSupported;
101 extern int wShapeEventBase;
102 #endif
104 #ifdef KEEP_XKB_LOCK_STATUS
105 extern int wXkbEventBase;
106 #endif
108 /* special flags */
109 extern char WDelayedActionSet;
112 /************ Local stuff ***********/
115 static void saveTimestamp(XEvent *event);
116 static void handleColormapNotify();
117 static void handleMapNotify(), handleUnmapNotify();
118 static void handleButtonPress(), handleExpose();
119 static void handleDestroyNotify();
120 static void handleConfigureRequest();
121 static void handleMapRequest();
122 static void handlePropertyNotify();
123 static void handleEnterNotify();
124 static void handleLeaveNotify();
125 static void handleExtensions();
126 static void handleClientMessage();
127 static void handleKeyPress();
128 static void handleFocusIn();
129 static void handleMotionNotify();
130 static void handleVisibilityNotify();
133 #ifdef SHAPE
134 static void handleShapeNotify();
135 #endif
137 /* called from the signal handler */
138 void NotifyDeadProcess(pid_t pid, unsigned char status);
140 /* real dead process handler */
141 static void handleDeadProcess(void *foo);
144 typedef struct DeadProcesses {
145 pid_t pid;
146 unsigned char exit_status;
147 } DeadProcesses;
149 /* stack of dead processes */
150 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
151 static int deadProcessPtr=0;
154 typedef struct DeathHandler {
155 WDeathHandler *callback;
156 pid_t pid;
157 void *client_data;
158 } DeathHandler;
160 static WMBag *deathHandlers=NULL;
164 WMagicNumber
165 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
167 DeathHandler *handler;
169 handler = malloc(sizeof(DeathHandler));
170 if (!handler)
171 return 0;
173 handler->pid = pid;
174 handler->callback = callback;
175 handler->client_data = cdata;
177 if (!deathHandlers)
178 deathHandlers = WMCreateBag(8);
180 WMPutInBag(deathHandlers, handler);
182 return handler;
187 void
188 wDeleteDeathHandler(WMagicNumber id)
190 DeathHandler *handler=(DeathHandler*)id;
192 if (!handler || !deathHandlers)
193 return;
195 WMRemoveFromBag(deathHandlers, handler);
197 free(handler);
201 void
202 DispatchEvent(XEvent *event)
204 if (deathHandlers)
205 handleDeadProcess(NULL);
207 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
208 WCHANGE_STATE(WSTATE_EXITING);
209 /* received SIGTERM */
211 * WMHandleEvent() can't be called from anything
212 * executed inside here, or we can get in a infinite
213 * recursive loop.
215 Shutdown(WSExitMode);
217 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
218 WCHANGE_STATE(WSTATE_RESTARTING);
220 Shutdown(WSRestartPreparationMode);
221 /* received SIGHUP */
222 Restart(NULL, True);
225 /* for the case that all that is wanted to be dispatched is
226 * the stuff above */
227 if (!event)
228 return;
230 saveTimestamp(event);
231 switch (event->type) {
232 case MapRequest:
233 handleMapRequest(event);
234 break;
236 case KeyPress:
237 handleKeyPress(event);
238 break;
240 case MotionNotify:
241 handleMotionNotify(event);
242 break;
244 case ConfigureRequest:
245 handleConfigureRequest(event);
246 break;
248 case DestroyNotify:
249 handleDestroyNotify(event);
250 break;
252 case MapNotify:
253 handleMapNotify(event);
254 break;
256 case UnmapNotify:
257 handleUnmapNotify(event);
258 break;
260 case ButtonPress:
261 handleButtonPress(event);
262 break;
264 case Expose:
265 handleExpose(event);
266 break;
268 case PropertyNotify:
269 handlePropertyNotify(event);
270 break;
272 case EnterNotify:
273 handleEnterNotify(event);
274 break;
276 case LeaveNotify:
277 handleLeaveNotify(event);
278 break;
280 case ClientMessage:
281 handleClientMessage(event);
282 break;
284 case ColormapNotify:
285 handleColormapNotify(event);
286 break;
288 case MappingNotify:
289 if (event->xmapping.request == MappingKeyboard
290 || event->xmapping.request == MappingModifier)
291 XRefreshKeyboardMapping(&event->xmapping);
292 break;
294 case FocusIn:
295 handleFocusIn(event);
296 break;
298 case VisibilityNotify:
299 handleVisibilityNotify(event);
300 break;
301 default:
302 handleExtensions(event);
303 break;
309 *----------------------------------------------------------------------
310 * EventLoop-
311 * Processes X and internal events indefinitely.
313 * Returns:
314 * Never returns
316 * Side effects:
317 * The LastTimestamp global variable is updated.
318 *----------------------------------------------------------------------
320 void
321 EventLoop()
323 XEvent event;
325 for(;;) {
326 WMNextEvent(dpy, &event);
327 WMHandleEvent(&event);
333 Bool
334 IsDoubleClick(WScreen *scr, XEvent *event)
336 if ((scr->last_click_time>0) &&
337 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
338 && (event->xbutton.button == scr->last_click_button)
339 && (event->xbutton.window == scr->last_click_window)) {
341 scr->flags.next_click_is_not_double = 1;
342 scr->last_click_time = 0;
343 scr->last_click_window = event->xbutton.window;
345 return True;
347 return False;
351 void
352 NotifyDeadProcess(pid_t pid, unsigned char status)
354 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
355 wwarning("stack overflow: too many dead processes");
356 return;
358 /* stack the process to be handled later,
359 * as this is called from the signal handler */
360 deadProcesses[deadProcessPtr].pid = pid;
361 deadProcesses[deadProcessPtr].exit_status = status;
362 deadProcessPtr++;
366 static void
367 handleDeadProcess(void *foo)
369 DeathHandler *tmp;
370 int i;
372 for (i=0; i<deadProcessPtr; i++) {
373 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
376 if (!deathHandlers) {
377 deadProcessPtr=0;
378 return;
381 /* get the pids on the queue and call handlers */
382 while (deadProcessPtr>0) {
383 deadProcessPtr--;
385 for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) {
386 tmp = WMGetFromBag(deathHandlers, i);
387 if (!tmp)
388 continue;
390 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
391 (*tmp->callback)(tmp->pid,
392 deadProcesses[deadProcessPtr].exit_status,
393 tmp->client_data);
394 wDeleteDeathHandler(tmp);
401 static void
402 saveTimestamp(XEvent *event)
404 LastTimestamp = CurrentTime;
406 switch (event->type) {
407 case ButtonRelease:
408 case ButtonPress:
409 LastTimestamp = event->xbutton.time;
410 break;
411 case KeyPress:
412 case KeyRelease:
413 LastTimestamp = event->xkey.time;
414 break;
415 case MotionNotify:
416 LastTimestamp = event->xmotion.time;
417 break;
418 case PropertyNotify:
419 LastTimestamp = event->xproperty.time;
420 break;
421 case EnterNotify:
422 case LeaveNotify:
423 LastTimestamp = event->xcrossing.time;
424 break;
425 case SelectionClear:
426 LastTimestamp = event->xselectionclear.time;
427 break;
428 case SelectionRequest:
429 LastTimestamp = event->xselectionrequest.time;
430 break;
431 case SelectionNotify:
432 LastTimestamp = event->xselection.time;
433 #ifdef XDND
434 wXDNDProcessSelection(event);
435 #endif
436 break;
441 static void
442 handleExtensions(XEvent *event)
444 #ifdef KEEP_XKB_LOCK_STATUS
445 XkbEvent *xkbevent;
446 xkbevent = (XkbEvent *)event;
447 #endif /*KEEP_XKB_LOCK_STATUS*/
448 #ifdef SHAPE
449 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
450 handleShapeNotify(event);
452 #endif
453 #ifdef KEEP_XKB_LOCK_STATUS
454 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
455 handleXkbIndicatorStateNotify(event);
457 #endif /*KEEP_XKB_LOCK_STATUS*/
461 static void
462 handleMapRequest(XEvent *ev)
464 WWindow *wwin;
465 WScreen *scr = NULL;
466 Window window = ev->xmaprequest.window;
468 #ifdef DEBUG
469 L("got map request for %x\n", (unsigned)window);
470 #endif
471 if ((wwin = wWindowFor(window))) {
472 if (wwin->flags.shaded) {
473 wUnshadeWindow(wwin);
475 /* deiconify window */
476 if (wwin->flags.miniaturized) {
477 wDeiconifyWindow(wwin);
478 } else if (wwin->flags.hidden) {
479 WApplication *wapp = wApplicationOf(wwin->main_window);
480 /* go to the last workspace that the user worked on the app */
481 #ifndef REDUCE_APPICONS
482 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
483 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
485 if (wapp) {
486 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
488 #endif
489 wUnhideApplication(wapp, False, False);
491 return;
494 scr = wScreenForRootWindow(ev->xmaprequest.parent);
496 wwin = wManageWindow(scr, window);
499 * This is to let the Dock know that the application it launched
500 * has already been mapped (eg: it has finished launching).
501 * It is not necessary for normally docked apps, but is needed for
502 * apps that were forcedly docked (like with dockit).
504 if (scr->last_dock) {
505 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
506 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
507 else
508 wDockTrackWindowLaunch(scr->last_dock, window);
511 if (wwin) {
512 wClientSetState(wwin, NormalState, None);
513 if (wwin->flags.maximized) {
514 wMaximizeWindow(wwin, wwin->flags.maximized);
516 if (wwin->flags.shaded) {
517 wwin->flags.shaded = 0;
518 wwin->flags.skip_next_animation = 1;
519 wShadeWindow(wwin);
521 if (wwin->flags.miniaturized) {
522 wwin->flags.miniaturized = 0;
523 wwin->flags.skip_next_animation = 1;
524 wIconifyWindow(wwin);
526 if (wwin->flags.hidden) {
527 WApplication *wapp = wApplicationOf(wwin->main_window);
529 wwin->flags.hidden = 0;
530 wwin->flags.skip_next_animation = 1;
531 if (wapp) {
532 wHideApplication(wapp);
539 static void
540 handleDestroyNotify(XEvent *event)
542 WWindow *wwin;
543 WApplication *app;
544 Window window = event->xdestroywindow.window;
546 #ifdef DEBUG
547 L("got destroy notify");
548 #endif
549 wwin = wWindowFor(window);
550 if (wwin) {
551 wUnmanageWindow(wwin, False, True);
554 app = wApplicationOf(window);
555 if (app) {
556 if (window == app->main_window) {
557 app->refcount = 0;
558 wwin = app->main_window_desc->screen_ptr->focused_window;
559 while (wwin) {
560 if (wwin->main_window == window) {
561 wwin->main_window = None;
563 wwin = wwin->prev;
566 wApplicationDestroy(app);
569 #ifdef KWM_HINTS
570 wKWMCheckDestroy(&event->xdestroywindow);
571 #endif
576 static void
577 handleExpose(XEvent *event)
579 WObjDescriptor *desc;
580 XEvent ev;
582 #ifdef DEBUG
583 L("got expose");
584 #endif
585 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
587 if (XFindContext(dpy, event->xexpose.window, wWinContext,
588 (XPointer *)&desc)==XCNOENT) {
589 return;
592 if (desc->handle_expose) {
593 (*desc->handle_expose)(desc, event);
597 /* bindable */
598 static void
599 handleButtonPress(XEvent *event)
601 WObjDescriptor *desc;
602 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 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
657 (XPointer *)&desc)==XCNOENT) {
658 if (XFindContext(dpy, event->xbutton.window, wWinContext,
659 (XPointer *)&desc)==XCNOENT) {
660 return;
664 if (desc->handle_mousedown!=NULL) {
665 (*desc->handle_mousedown)(desc, event);
668 if (desc->parent_type == WCLASS_WINDOW) {
669 XSync(dpy, 0);
671 if (event->xbutton.state & MOD_MASK) {
672 XAllowEvents(dpy, AsyncPointer, CurrentTime);
675 if (wPreferences.focus_mode == WKF_CLICK) {
676 if (wPreferences.ignore_focus_click) {
677 XAllowEvents(dpy, AsyncPointer, CurrentTime);
679 XAllowEvents(dpy, ReplayPointer, CurrentTime);
681 XSync(dpy, 0);
682 } else if (desc->parent_type == WCLASS_APPICON
683 || desc->parent_type == WCLASS_MINIWINDOW
684 || desc->parent_type == WCLASS_DOCK_ICON) {
685 if (event->xbutton.state & MOD_MASK) {
686 XSync(dpy, 0);
687 XAllowEvents(dpy, AsyncPointer, CurrentTime);
688 XSync(dpy, 0);
692 /* save double-click information */
693 if (scr->flags.next_click_is_not_double) {
694 scr->flags.next_click_is_not_double = 0;
695 } else {
696 scr->last_click_time = event->xbutton.time;
697 scr->last_click_button = event->xbutton.button;
698 scr->last_click_window = event->xbutton.window;
703 static void
704 handleMapNotify(XEvent *event)
706 WWindow *wwin;
707 #ifdef DEBUG
708 L("got map");
709 #endif
710 wwin = wWindowFor(event->xmap.event);
711 if (wwin && wwin->client_win == event->xmap.event) {
712 if (wwin->flags.miniaturized) {
713 wDeiconifyWindow(wwin);
714 } else {
715 XGrabServer(dpy);
716 wWindowMap(wwin);
717 wClientSetState(wwin, NormalState, None);
718 XUngrabServer(dpy);
724 static void
725 handleUnmapNotify(XEvent *event)
727 WWindow *wwin;
728 XEvent ev;
729 Bool withdraw = False;
730 #ifdef DEBUG
731 L("got unmap");
732 #endif
733 /* only process windows with StructureNotify selected
734 * (ignore SubstructureNotify) */
735 wwin = wWindowFor(event->xunmap.window);
736 if (!wwin)
737 return;
739 /* whether the event is a Withdrawal request */
740 if (event->xunmap.event == wwin->screen_ptr->root_win
741 && event->xunmap.send_event)
742 withdraw = True;
744 if (wwin->client_win != event->xunmap.event && !withdraw)
745 return;
747 if (!wwin->flags.mapped && !withdraw
748 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
749 && !wwin->flags.miniaturized && !wwin->flags.hidden)
750 return;
752 XGrabServer(dpy);
753 XUnmapWindow(dpy, wwin->frame->core->window);
754 wwin->flags.mapped = 0;
755 XSync(dpy, 0);
756 /* check if the window was destroyed */
757 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
758 DispatchEvent(&ev);
759 } else {
760 Bool reparented = False;
762 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
763 reparented = True;
765 /* withdraw window */
766 wwin->flags.mapped = 0;
767 if (!reparented)
768 wClientSetState(wwin, WithdrawnState, None);
770 /* if the window was reparented, do not reparent it back to the
771 * root window */
772 wUnmanageWindow(wwin, !reparented, False);
774 XUngrabServer(dpy);
778 static void
779 handleConfigureRequest(XEvent *event)
781 WWindow *wwin;
782 #ifdef DEBUG
783 L("got configure request");
784 #endif
785 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
787 * Configure request for unmapped window
789 wClientConfigure(NULL, &(event->xconfigurerequest));
790 } else {
791 wClientConfigure(wwin, &(event->xconfigurerequest));
796 static void
797 handlePropertyNotify(XEvent *event)
799 WWindow *wwin;
800 WApplication *wapp;
801 Window jr;
802 int ji;
803 unsigned int ju;
804 WScreen *scr;
805 #ifdef DEBUG
806 L("got property notify");
807 #endif
808 if ((wwin=wWindowFor(event->xproperty.window))) {
809 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
810 &ju, &ju, &ju, &ju)) {
811 return;
813 wClientCheckProperty(wwin, &event->xproperty);
815 wapp = wApplicationOf(event->xproperty.window);
816 if (wapp) {
817 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
820 scr = wScreenForWindow(event->xproperty.window);
821 if (scr && scr->root_win == event->xproperty.window) {
822 #ifdef KWM_HINTS
823 wKWMCheckRootHintChange(scr, &event->xproperty);
824 #endif
829 static void
830 handleClientMessage(XEvent *event)
832 WWindow *wwin;
833 WObjDescriptor *desc;
834 #ifdef DEBUG
835 L("got client message");
836 #endif
837 /* handle transition from Normal to Iconic state */
838 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
839 && event->xclient.format == 32
840 && event->xclient.data.l[0] == IconicState) {
842 wwin = wWindowFor(event->xclient.window);
843 if (!wwin) return;
844 if (!wwin->flags.miniaturized)
845 wIconifyWindow(wwin);
846 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
847 && event->xclient.format == 32) {
848 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
850 if (!scr)
851 return;
853 if (event->xclient.data.l[1] == 1) { /* starting */
854 wColormapAllowClientInstallation(scr, True);
855 } else { /* stopping */
856 wColormapAllowClientInstallation(scr, False);
858 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
860 wDefaultsCheckDomains("bla");
862 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
863 WApplication *wapp;
864 int done=0;
865 wapp = wApplicationOf(event->xclient.window);
866 if (wapp) {
867 switch (event->xclient.data.l[0]) {
868 case WMFHideOtherApplications:
869 wHideOtherApplications(wapp->main_window_desc);
870 done = 1;
871 break;
873 case WMFHideApplication:
874 wHideApplication(wapp);
875 done = 1;
876 break;
879 if (!done) {
880 wwin = wWindowFor(event->xclient.window);
881 if (wwin) {
882 switch (event->xclient.data.l[0]) {
883 case WMFHideOtherApplications:
884 wHideOtherApplications(wwin);
885 break;
887 case WMFHideApplication:
888 wHideApplication(wApplicationOf(wwin->main_window));
889 break;
893 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
894 wwin = wWindowFor(event->xclient.window);
895 if (!wwin) return;
896 switch (event->xclient.data.l[0]) {
897 case GSWindowLevelAttr:
899 int level = (int)event->xclient.data.l[1];
901 if (WINDOW_LEVEL(wwin) != level) {
902 ChangeStackingLevel(wwin->frame->core, level);
905 break;
907 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
908 wwin = wWindowFor(event->xclient.window);
909 if (!wwin) return;
910 switch (event->xclient.data.l[0]) {
911 case WMTitleBarNormal:
912 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
913 break;
914 case WMTitleBarMain:
915 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
916 break;
917 case WMTitleBarKey:
918 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
919 break;
921 #ifdef GNOME_STUFF
922 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
923 /* do nothing */
924 #endif /* GNOME_STUFF */
925 #ifdef KWM_HINTS
926 } else if (wKWMProcessClientMessage(&event->xclient)) {
927 /* do nothing */
928 #endif /* KWM_HINTS */
929 #ifdef XDND
930 } else if (wXDNDProcessClientMessage(&event->xclient)) {
931 /* do nothing */
932 #endif /* XDND */
933 #ifdef OFFIX_DND
934 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
935 WScreen *scr = wScreenForWindow(event->xclient.window);
936 if (scr && wDockReceiveDNDDrop(scr,event))
937 goto redirect_message;
938 #endif /* OFFIX_DND */
939 } else {
940 #ifdef OFFIX_DND
941 redirect_message:
942 #endif
944 * Non-standard thing, but needed by OffiX DND.
945 * For when the icon frame gets a ClientMessage
946 * that should have gone to the icon_window.
948 if (XFindContext(dpy, event->xbutton.window, wWinContext,
949 (XPointer *)&desc)!=XCNOENT) {
950 struct WIcon *icon=NULL;
952 if (desc->parent_type == WCLASS_MINIWINDOW) {
953 icon = (WIcon*)desc->parent;
954 } else if (desc->parent_type == WCLASS_DOCK_ICON
955 || desc->parent_type == WCLASS_APPICON) {
956 icon = ((WAppIcon*)desc->parent)->icon;
958 if (icon && (wwin=icon->owner)) {
959 if (wwin->client_win!=event->xclient.window) {
960 event->xclient.window = wwin->client_win;
961 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
962 event);
970 static void
971 raiseWindow(WScreen *scr)
973 WWindow *wwin;
975 scr->autoRaiseTimer = NULL;
977 wwin = wWindowFor(scr->autoRaiseWindow);
978 if (!wwin)
979 return;
981 if (!wwin->flags.destroyed && wwin->flags.focused) {
982 wRaiseFrame(wwin->frame->core);
983 /* this is needed or a race condition will occur */
984 XSync(dpy, False);
989 static void
990 handleEnterNotify(XEvent *event)
992 WWindow *wwin;
993 WObjDescriptor *desc = NULL;
994 XEvent ev;
995 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
996 #ifdef DEBUG
997 L("got enter notify");
998 #endif
1000 #ifdef VIRTUAL_DESKTOP
1001 if (wPreferences.vedge_thickness) {
1002 int x,y;
1003 if (event->xcrossing.window == scr->virtual_edge_r) {
1004 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1005 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1006 wWorkspaceSetViewPort(scr, scr->current_workspace, x+30, y);
1007 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1008 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1009 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1010 wWorkspaceSetViewPort(scr, scr->current_workspace, x-30, y);
1011 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1012 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1013 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1014 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y-30);
1015 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1016 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1017 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1018 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y+30);
1021 #endif
1023 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1024 &ev)) {
1025 /* already left the window... */
1026 saveTimestamp(&ev);
1027 if (ev.xcrossing.mode==event->xcrossing.mode
1028 && ev.xcrossing.detail==event->xcrossing.detail) {
1029 return;
1033 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1034 (XPointer *)&desc)!=XCNOENT) {
1035 if(desc->handle_enternotify)
1036 (*desc->handle_enternotify)(desc, event);
1039 /* enter to window */
1040 wwin = wWindowFor(event->xcrossing.window);
1041 if (!wwin) {
1042 if (wPreferences.focus_mode==WKF_POINTER
1043 && event->xcrossing.window==event->xcrossing.root) {
1044 wSetFocusTo(scr, NULL);
1046 if (wPreferences.colormap_mode==WKF_POINTER) {
1047 wColormapInstallForWindow(scr, NULL);
1049 if (scr->autoRaiseTimer
1050 && event->xcrossing.root==event->xcrossing.window) {
1051 WMDeleteTimerHandler(scr->autoRaiseTimer);
1052 scr->autoRaiseTimer = NULL;
1054 } else {
1055 /* set auto raise timer even if in focus-follows-mouse mode
1056 * and the event is for the frame window, even if the window
1057 * has focus already. useful if you move the pointer from a focused
1058 * window to the root window and back pretty fast
1060 * set focus if in focus-follows-mouse mode and the event
1061 * is for the frame window and window doesn't have focus yet */
1062 if ((wPreferences.focus_mode==WKF_POINTER
1063 || wPreferences.focus_mode==WKF_SLOPPY)
1064 && wwin->frame->core->window==event->xcrossing.window
1065 && !scr->flags.doing_alt_tab) {
1067 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1068 wSetFocusTo(scr, wwin);
1070 if (scr->autoRaiseTimer)
1071 WMDeleteTimerHandler(scr->autoRaiseTimer);
1072 scr->autoRaiseTimer = NULL;
1074 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1075 scr->autoRaiseWindow = wwin->frame->core->window;
1076 scr->autoRaiseTimer
1077 = WMAddTimerHandler(wPreferences.raise_delay,
1078 (WMCallback*)raiseWindow, scr);
1081 /* Install colormap for window, if the colormap installation mode
1082 * is colormap_follows_mouse */
1083 if (wPreferences.colormap_mode==WKF_POINTER) {
1084 if (wwin->client_win==event->xcrossing.window)
1085 wColormapInstallForWindow(scr, wwin);
1086 else
1087 wColormapInstallForWindow(scr, NULL);
1091 /* a little kluge to hide the clip balloon */
1092 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1093 if (!desc) {
1094 XUnmapWindow(dpy, scr->clip_balloon);
1095 scr->flags.clip_balloon_mapped = 0;
1096 } else {
1097 if (desc->parent_type!=WCLASS_DOCK_ICON
1098 || scr->clip_icon != desc->parent) {
1099 XUnmapWindow(dpy, scr->clip_balloon);
1100 scr->flags.clip_balloon_mapped = 0;
1105 if (event->xcrossing.window == event->xcrossing.root
1106 && event->xcrossing.detail == NotifyNormal
1107 && event->xcrossing.detail != NotifyInferior
1108 && wPreferences.focus_mode != WKF_CLICK) {
1110 wSetFocusTo(scr, scr->focused_window);
1113 #ifdef BALLOON_TEXT
1114 wBalloonEnteredObject(scr, desc);
1115 #endif
1119 static void
1120 handleLeaveNotify(XEvent *event)
1122 WObjDescriptor *desc = NULL;
1124 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1125 (XPointer *)&desc)!=XCNOENT) {
1126 if(desc->handle_leavenotify)
1127 (*desc->handle_leavenotify)(desc, event);
1129 if (event->xcrossing.window == event->xcrossing.root
1130 && event->xcrossing.mode == NotifyNormal
1131 && event->xcrossing.detail != NotifyInferior
1132 && wPreferences.focus_mode != WKF_CLICK) {
1134 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1136 wSetFocusTo(scr, NULL);
1141 #ifdef SHAPE
1142 static void
1143 handleShapeNotify(XEvent *event)
1145 XShapeEvent *shev = (XShapeEvent*)event;
1146 WWindow *wwin;
1147 XEvent ev;
1148 #ifdef DEBUG
1149 L("got shape notify");
1150 #endif
1151 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1152 XShapeEvent *sev = (XShapeEvent*)&ev;
1154 if (sev->kind == ShapeBounding) {
1155 if (sev->shaped == shev->shaped) {
1156 *shev = *sev;
1157 } else {
1158 XPutBackEvent(dpy, &ev);
1159 break;
1164 wwin = wWindowFor(shev->window);
1165 if (!wwin || shev->kind != ShapeBounding)
1166 return;
1168 if (!shev->shaped && wwin->flags.shaped) {
1170 wwin->flags.shaped = 0;
1171 wWindowClearShape(wwin);
1173 } else if (shev->shaped) {
1175 wwin->flags.shaped = 1;
1176 wWindowSetShape(wwin);
1179 #endif /* SHAPE */
1181 #ifdef KEEP_XKB_LOCK_STATUS
1182 /* please help ]d if you know what to do */
1183 handleXkbIndicatorStateNotify(XEvent *event)
1185 WWindow *wwin;
1186 WScreen *scr;
1187 XkbStateRec staterec;
1188 int i;
1190 for (i=0; i<wScreenCount; i++) {
1191 scr = wScreenWithNumber(i);
1192 wwin = scr->focused_window;
1193 if (wwin && wwin->flags.focused) {
1194 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1195 if (wwin->frame->languagemode != staterec.group) {
1196 wwin->frame->last_languagemode = wwin->frame->languagemode;
1197 wwin->frame->languagemode = staterec.group;
1199 #ifdef XKB_BUTTON_HINT
1200 if (wwin->frame->titlebar) {
1201 wFrameWindowPaint(wwin->frame);
1203 #endif
1207 #endif /*KEEP_XKB_LOCK_STATUS*/
1209 static void
1210 handleColormapNotify(XEvent *event)
1212 WWindow *wwin;
1213 WScreen *scr;
1214 Bool reinstall = False;
1216 wwin = wWindowFor(event->xcolormap.window);
1217 if (!wwin)
1218 return;
1220 scr = wwin->screen_ptr;
1222 do {
1223 if (wwin) {
1224 if (event->xcolormap.new) {
1225 XWindowAttributes attr;
1227 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1229 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1230 scr->current_colormap = attr.colormap;
1232 reinstall = True;
1233 } else if (event->xcolormap.state == ColormapUninstalled &&
1234 scr->current_colormap == event->xcolormap.colormap) {
1236 /* some bastard app (like XV) removed our colormap */
1238 * can't enforce or things like xscreensaver wont work
1239 * reinstall = True;
1241 } else if (event->xcolormap.state == ColormapInstalled &&
1242 scr->current_colormap == event->xcolormap.colormap) {
1244 /* someone has put our colormap back */
1245 reinstall = False;
1248 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1249 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1251 if (reinstall && scr->current_colormap!=None) {
1252 if (!scr->flags.colormap_stuff_blocked)
1253 XInstallColormap(dpy, scr->current_colormap);
1259 static void
1260 handleFocusIn(XEvent *event)
1262 WWindow *wwin;
1265 * For applications that like stealing the focus.
1267 while (XCheckTypedEvent(dpy, FocusIn, event));
1268 saveTimestamp(event);
1269 if (event->xfocus.mode == NotifyUngrab
1270 || event->xfocus.mode == NotifyGrab
1271 || event->xfocus.detail > NotifyNonlinearVirtual) {
1272 return;
1275 wwin = wWindowFor(event->xfocus.window);
1276 if (wwin && !wwin->flags.focused) {
1277 if (wwin->flags.mapped)
1278 wSetFocusTo(wwin->screen_ptr, wwin);
1279 else
1280 wSetFocusTo(wwin->screen_ptr, NULL);
1281 } else if (!wwin) {
1282 WScreen *scr = wScreenForWindow(event->xfocus.window);
1283 if (scr)
1284 wSetFocusTo(scr, NULL);
1289 static WWindow*
1290 windowUnderPointer(WScreen *scr)
1292 unsigned int mask;
1293 int foo;
1294 Window bar, win;
1296 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1297 &mask))
1298 return wWindowFor(win);
1299 return NULL;
1305 static void
1306 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1308 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1309 Bool done = False;
1310 Bool openedSwitchMenu = False;
1311 WWindow *newFocused;
1312 WWindow *oldFocused;
1313 int modifiers;
1314 XModifierKeymap *keymap;
1316 if (!wwin)
1317 return;
1319 keymap = XGetModifierMapping(dpy);
1322 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1323 CurrentTime);
1325 if (next) {
1326 newFocused = NextToFocusAfter(wwin);
1327 } else {
1328 newFocused = NextToFocusBefore(wwin);
1331 scr->flags.doing_alt_tab = 1;
1334 if (wPreferences.circ_raise)
1335 XRaiseWindow(dpy, newFocused->frame->core->window);
1336 wWindowFocus(newFocused, scr->focused_window);
1337 oldFocused = newFocused;
1339 #if 0
1340 if (wPreferences.popup_switchmenu &&
1341 (!scr->switch_menu || !scr->switch_menu->flags.mapped)) {
1343 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1344 openedSwitchMenu = True;
1346 #endif
1347 while (!done) {
1348 XEvent ev;
1350 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1352 if (ev.type != KeyRelease && ev.type != KeyPress) {
1353 WMHandleEvent(&ev);
1354 continue;
1356 /* ignore CapsLock */
1357 modifiers = ev.xkey.state & ValidModMask;
1359 if (ev.type == KeyPress) {
1360 if (wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1361 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1363 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1364 newFocused = NextToFocusAfter(newFocused);
1365 wWindowFocus(newFocused, oldFocused);
1366 oldFocused = newFocused;
1368 if (wPreferences.circ_raise) {
1369 /* restore order */
1370 CommitStacking(scr);
1371 XRaiseWindow(dpy, newFocused->frame->core->window);
1374 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1376 } else if (wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1377 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1379 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1380 newFocused = NextToFocusBefore(newFocused);
1381 wWindowFocus(newFocused, oldFocused);
1382 oldFocused = newFocused;
1384 if (wPreferences.circ_raise) {
1385 /* restore order */
1386 CommitStacking(scr);
1387 XRaiseWindow(dpy, newFocused->frame->core->window);
1389 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1391 } else if (wKeyBindings[WKBD_LOWER].keycode == ev.xkey.keycode
1392 && wKeyBindings[WKBD_LOWER].modifier == modifiers) {
1394 wLowerFrame(newFocused->frame->core);
1396 } else if (wKeyBindings[WKBD_RAISE].keycode == ev.xkey.keycode
1397 && wKeyBindings[WKBD_RAISE].modifier == modifiers) {
1399 wRaiseFrame(newFocused->frame->core);
1401 } else if (ev.type == KeyRelease) {
1402 int i;
1404 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1405 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1406 wKeyBindings[WKBD_FOCUSNEXT].modifier
1407 & 1<<(i/keymap->max_keypermod)) {
1408 done = True;
1409 break;
1414 XFree(keymap);
1416 XUngrabKeyboard(dpy, CurrentTime);
1417 wSetFocusTo(scr, newFocused);
1419 if (wPreferences.circ_raise) {
1420 wRaiseFrame(newFocused->frame->core);
1421 CommitStacking(scr);
1424 scr->flags.doing_alt_tab = 0;
1425 if (openedSwitchMenu)
1426 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1432 static void
1433 handleKeyPress(XEvent *event)
1435 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1436 WWindow *wwin = scr->focused_window;
1437 int i;
1438 int modifiers;
1439 int command=-1, index;
1440 #ifdef KEEP_XKB_LOCK_STATUS
1441 XkbStateRec staterec;
1442 #endif /*KEEP_XKB_LOCK_STATUS*/
1444 /* ignore CapsLock */
1445 modifiers = event->xkey.state & ValidModMask;
1447 for (i=0; i<WKBD_LAST; i++) {
1448 if (wKeyBindings[i].keycode==0)
1449 continue;
1451 if (wKeyBindings[i].keycode==event->xkey.keycode
1452 && (/*wKeyBindings[i].modifier==0
1453 ||*/ wKeyBindings[i].modifier==modifiers)) {
1454 command = i;
1455 break;
1460 if (command < 0) {
1461 #ifdef LITE
1463 #if 0
1465 #endif
1466 #else
1467 if (!wRootMenuPerformShortcut(event)) {
1468 #endif
1469 static int dontLoop = 0;
1471 if (dontLoop > 10) {
1472 wwarning("problem with key event processing code");
1473 return;
1475 dontLoop++;
1476 /* if the focused window is an internal window, try redispatching
1477 * the event to the managed window, as it can be a WINGs window */
1478 if (wwin && wwin->flags.internal_window
1479 && wwin->client_leader!=None) {
1480 /* client_leader contains the WINGs toplevel */
1481 event->xany.window = wwin->client_leader;
1482 WMHandleEvent(event);
1484 dontLoop--;
1486 return;
1489 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1490 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1492 switch (command) {
1493 #ifndef LITE
1494 case WKBD_ROOTMENU:
1495 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1496 break;
1497 case WKBD_WINDOWLIST:
1498 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1499 break;
1500 #endif /* !LITE */
1501 case WKBD_WINDOWMENU:
1502 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1503 OpenWindowMenu(wwin, wwin->frame_x,
1504 wwin->frame_y+wwin->frame->top_width, True);
1505 break;
1506 case WKBD_MINIATURIZE:
1507 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1508 && !WFLAGP(wwin, no_miniaturizable)) {
1509 CloseWindowMenu(scr);
1511 if (wwin->protocols.MINIATURIZE_WINDOW)
1512 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1513 event->xbutton.time);
1514 else {
1515 wIconifyWindow(wwin);
1518 break;
1519 case WKBD_HIDE:
1520 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1521 WApplication *wapp = wApplicationOf(wwin->main_window);
1522 CloseWindowMenu(scr);
1524 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1525 wHideApplication(wapp);
1528 break;
1529 case WKBD_MAXIMIZE:
1530 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1531 CloseWindowMenu(scr);
1533 if (wwin->flags.maximized) {
1534 wUnmaximizeWindow(wwin);
1535 } else {
1536 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1539 break;
1540 case WKBD_VMAXIMIZE:
1541 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1542 CloseWindowMenu(scr);
1544 if (wwin->flags.maximized) {
1545 wUnmaximizeWindow(wwin);
1546 } else {
1547 wMaximizeWindow(wwin, MAX_VERTICAL);
1550 break;
1551 case WKBD_RAISE:
1552 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1553 CloseWindowMenu(scr);
1555 wRaiseFrame(wwin->frame->core);
1557 break;
1558 case WKBD_LOWER:
1559 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1560 CloseWindowMenu(scr);
1562 wLowerFrame(wwin->frame->core);
1564 break;
1565 case WKBD_RAISELOWER:
1566 /* raise or lower the window under the pointer, not the
1567 * focused one
1569 wwin = windowUnderPointer(scr);
1570 if (wwin)
1571 wRaiseLowerFrame(wwin->frame->core);
1572 break;
1573 case WKBD_SHADE:
1574 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1575 if (wwin->flags.shaded)
1576 wUnshadeWindow(wwin);
1577 else
1578 wShadeWindow(wwin);
1580 break;
1581 case WKBD_MOVERESIZE:
1582 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1583 CloseWindowMenu(scr);
1585 wKeyboardMoveResizeWindow(wwin);
1587 break;
1588 case WKBD_CLOSE:
1589 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1590 CloseWindowMenu(scr);
1591 if (wwin->protocols.DELETE_WINDOW)
1592 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1593 event->xkey.time);
1595 break;
1596 case WKBD_SELECT:
1597 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1598 wSelectWindow(wwin, !wwin->flags.selected);
1600 break;
1601 case WKBD_FOCUSNEXT:
1602 doWindozeCycle(wwin, event, True);
1603 break;
1605 case WKBD_FOCUSPREV:
1606 doWindozeCycle(wwin, event, False);
1607 break;
1609 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1610 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1611 i = (scr->current_workspace/10)*10 + wk - 1;\
1612 if (wPreferences.ws_advance || i<scr->workspace_count)\
1613 wWorkspaceChange(scr, i);\
1614 break
1615 #else
1616 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1617 i = (scr->current_workspace/10)*10 + wk - 1;\
1618 if (wPreferences.ws_advance || i<scr->workspace_count)\
1619 wWorkspaceChange(scr, i);\
1620 break
1621 #endif
1622 GOTOWORKS(1);
1623 GOTOWORKS(2);
1624 GOTOWORKS(3);
1625 GOTOWORKS(4);
1626 GOTOWORKS(5);
1627 GOTOWORKS(6);
1628 GOTOWORKS(7);
1629 GOTOWORKS(8);
1630 GOTOWORKS(9);
1631 GOTOWORKS(10);
1632 #undef GOTOWORKS
1633 case WKBD_NEXTWORKSPACE:
1634 wWorkspaceRelativeChange(scr, 1);
1635 break;
1636 case WKBD_PREVWORKSPACE:
1637 wWorkspaceRelativeChange(scr, -1);
1638 break;
1639 case WKBD_WINDOW1:
1640 case WKBD_WINDOW2:
1641 case WKBD_WINDOW3:
1642 case WKBD_WINDOW4:
1643 #ifdef EXTEND_WINDOWSHORTCUT
1644 case WKBD_WINDOW5:
1645 case WKBD_WINDOW6:
1646 case WKBD_WINDOW7:
1647 case WKBD_WINDOW8:
1648 case WKBD_WINDOW9:
1649 case WKBD_WINDOW10:
1650 #endif
1652 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1654 index = command-WKBD_WINDOW1;
1656 if (scr->shortcutWindows[index]) {
1657 WMBag *list = scr->shortcutWindows[index];
1658 int cw;
1659 int i;
1660 int count = WMGetBagItemCount(list);
1661 WWindow *twin;
1663 wUnselectWindows(scr);
1664 cw = scr->current_workspace;
1666 for (i = count-1; i >= 0; i--) {
1667 WWindow *wwin = WMGetFromBag(list, i);
1669 if (count > 1)
1670 wWindowChangeWorkspace(wwin, cw);
1672 wMakeWindowVisible(wwin);
1674 if (count > 1)
1675 wSelectWindow(wwin, True);
1678 /* rotate the order of windows, to create a cycling effect */
1679 twin = WMGetFromBag(list, 0);
1680 WMDeleteFromBag(list, 0);
1681 WMPutInBag(list, twin);
1683 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1685 INITBAG(scr->shortcutWindows[index]);
1686 WMPutInBag(scr->shortcutWindows[index], wwin);
1688 if (wwin->flags.selected && scr->selected_windows) {
1689 WMBag *selwins = scr->selected_windows;
1690 int i;
1692 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1693 WWindow *tmp = WMGetFromBag(selwins, i);
1695 if (tmp != wwin)
1696 WMPutInBag(scr->shortcutWindows[index], tmp);
1699 wSelectWindow(wwin, !wwin->flags.selected);
1700 XFlush(dpy);
1701 wusleep(3000);
1702 wSelectWindow(wwin, !wwin->flags.selected);
1703 XFlush(dpy);
1705 } else if (scr->selected_windows
1706 && WMGetBagItemCount(scr->selected_windows)) {
1708 if (wwin->flags.selected && scr->selected_windows) {
1709 WMBag *selwins = scr->selected_windows;
1710 int i;
1712 INITBAG(scr->shortcutWindows[index]);
1714 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1715 WWindow *tmp = WMGetFromBag(selwins, i);
1717 WMPutInBag(scr->shortcutWindows[index], tmp);
1721 #undef INITBAG
1723 break;
1724 case WKBD_NEXTWSLAYER:
1725 case WKBD_PREVWSLAYER:
1727 int row, column;
1729 row = scr->current_workspace/10;
1730 column = scr->current_workspace%10;
1732 if (command==WKBD_NEXTWSLAYER) {
1733 if ((row+1)*10 < scr->workspace_count)
1734 wWorkspaceChange(scr, column+(row+1)*10);
1735 } else {
1736 if (row > 0)
1737 wWorkspaceChange(scr, column+(row-1)*10);
1740 break;
1741 case WKBD_CLIPLOWER:
1742 if (!wPreferences.flags.noclip)
1743 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1744 break;
1745 case WKBD_CLIPRAISE:
1746 if (!wPreferences.flags.noclip)
1747 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1748 break;
1749 case WKBD_CLIPRAISELOWER:
1750 if (!wPreferences.flags.noclip)
1751 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1752 break;
1753 #ifdef KEEP_XKB_LOCK_STATUS
1754 case WKBD_TOGGLE:
1755 if(wPreferences.modelock) {
1756 /*toggle*/
1757 wwin = scr->focused_window;
1759 if (wwin && wwin->flags.mapped
1760 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1761 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1762 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1764 wwin->frame->languagemode = wwin->frame->last_languagemode;
1765 wwin->frame->last_languagemode = staterec.group;
1766 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1770 break;
1771 #endif /* KEEP_XKB_LOCK_STATUS */
1777 static void
1778 handleMotionNotify(XEvent *event)
1780 WMenu *menu;
1781 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1783 if (wPreferences.scrollable_menus) {
1784 if (scr->flags.jump_back_pending ||
1785 event->xmotion.x_root <= 1 ||
1786 event->xmotion.x_root >= (scr->scr_width - 2) ||
1787 event->xmotion.y_root <= 1 ||
1788 event->xmotion.y_root >= (scr->scr_height - 2)) {
1789 #ifdef DEBUG
1790 L("pointer at screen edge");
1791 #endif
1792 menu = wMenuUnderPointer(scr);
1793 if (menu!=NULL)
1794 wMenuScroll(menu, event);
1797 #if 0
1798 if (event->xmotion.subwindow == None)
1799 return;
1801 if (scr->scrolledFMaximize != None) {
1802 WWindow *twin;
1804 twin = wWindowFor(scr->scrolledFMaximize);
1805 if (twin && twin->frame_y ==) {
1809 scr->scrolledFMaximize = NULL;
1811 } else {
1813 /* scroll full maximized window */
1814 if (event->xmotion.y_root < 1
1815 || event->xmotion.y_root > scr->scr_height - 1) {
1817 wwin = wWindowFor(event->xmotion.subwindow);
1819 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1820 && WFLAGP(wwin, full_maximize)
1821 && event->xmotion.x_root >= wwin->frame_x
1822 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1824 if (!WFLAGP(wwin, no_titlebar)
1825 && wwin->frame_y <= - wwin->frame->top_width) {
1827 wWindowMove(wwin, wwin->frame_x, 0);
1828 wwin->flags.dragged_while_fmaximized = 0;
1830 } else if (!WFLAGP(wwin, no_resizebar)
1831 && wwin->frame_y + wwin->frame->core->height >=
1832 scr->scr_height + wwin->frame->bottom_width) {
1834 int y = scr->scr_height + wwin->frame->bottom_width;
1836 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1838 wWindowMove(wwin, wwin->frame_x, y);
1839 wwin->flags.dragged_while_fmaximized = 0;
1843 #endif
1847 static void
1848 handleVisibilityNotify(XEvent *event)
1850 WWindow *wwin;
1852 wwin = wWindowFor(event->xvisibility.window);
1853 if (!wwin)
1854 return;
1855 wwin->flags.obscured =
1856 (event->xvisibility.state == VisibilityFullyObscured);