Remove DEBUG statements, #if 0 etc
[wmaker-crm.git] / src / event.c
blobd29cafc45a640cb9671de5ebfafa32702ca346dd
1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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.
23 #include <sys/inotify.h>
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33 #ifdef SHAPE
34 # include <X11/extensions/shape.h>
35 #endif
36 #ifdef XDND
37 #include "xdnd.h"
38 #endif
40 #ifdef KEEP_XKB_LOCK_STATUS
41 #include <X11/XKBlib.h>
42 #endif /* KEEP_XKB_LOCK_STATUS */
44 #include "WindowMaker.h"
45 #include "window.h"
46 #include "actions.h"
47 #include "client.h"
48 #include "funcs.h"
49 #include "keybind.h"
50 #include "application.h"
51 #include "stacking.h"
52 #include "defaults.h"
53 #include "workspace.h"
54 #include "dock.h"
55 #include "framewin.h"
56 #include "properties.h"
57 #include "balloon.h"
58 #include "xinerama.h"
59 #include "wmspec.h"
61 /******** Global Variables **********/
62 extern XContext wWinContext;
63 extern XContext wVEdgeContext;
65 extern Cursor wCursor[WCUR_LAST];
67 extern WShortKey wKeyBindings[WKBD_LAST];
68 extern int wScreenCount;
69 extern Time LastTimestamp;
70 extern Time LastFocusChange;
72 extern WPreferences wPreferences;
74 #define MOD_MASK wPreferences.modifier_mask
76 extern Atom _XA_WM_COLORMAP_NOTIFY;
78 extern Atom _XA_WM_CHANGE_STATE;
79 extern Atom _XA_WM_DELETE_WINDOW;
80 extern Atom _XA_GNUSTEP_WM_ATTR;
81 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
82 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
83 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
84 extern Atom _XA_WINDOWMAKER_COMMAND;
85 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
87 #ifdef SHAPE
88 extern Bool wShapeSupported;
89 extern int wShapeEventBase;
90 #endif
92 #ifdef KEEP_XKB_LOCK_STATUS
93 extern int wXkbEventBase;
94 #endif
96 /* special flags */
97 /*extern char WDelayedActionSet;*/
99 /************ Local stuff ***********/
101 static void saveTimestamp(XEvent *event);
102 static void handleColormapNotify(XEvent *event);
103 static void handleMapNotify(XEvent *event);
104 static void handleUnmapNotify(XEvent *event);
105 static void handleButtonPress(XEvent *event);
106 static void handleExpose(XEvent *event);
107 static void handleDestroyNotify(XEvent *event);
108 static void handleConfigureRequest(XEvent *event);
109 static void handleMapRequest(XEvent *event);
110 static void handlePropertyNotify(XEvent *event);
111 static void handleEnterNotify(XEvent *event);
112 static void handleLeaveNotify(XEvent *event);
113 static void handleExtensions(XEvent *event);
114 static void handleClientMessage(XEvent *event);
115 static void handleKeyPress(XEvent *event);
116 static void handleFocusIn(XEvent *event);
117 static void handleMotionNotify(XEvent *event);
118 static void handleVisibilityNotify(XEvent *event);
120 #ifdef SHAPE
121 static void handleShapeNotify(XEvent *event);
122 #endif
124 /* called from the signal handler */
125 void NotifyDeadProcess(pid_t pid, unsigned char status);
127 /* real dead process handler */
128 static void handleDeadProcess(void *foo);
130 typedef struct DeadProcesses {
131 pid_t pid;
132 unsigned char exit_status;
133 } DeadProcesses;
135 /* stack of dead processes */
136 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
137 static int deadProcessPtr = 0;
139 typedef struct DeathHandler {
140 WDeathHandler *callback;
141 pid_t pid;
142 void *client_data;
143 } DeathHandler;
145 static WMArray *deathHandlers = NULL;
147 WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
149 DeathHandler *handler;
151 handler = malloc(sizeof(DeathHandler));
152 if (!handler)
153 return 0;
155 handler->pid = pid;
156 handler->callback = callback;
157 handler->client_data = cdata;
159 if (!deathHandlers)
160 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
162 WMAddToArray(deathHandlers, handler);
164 return handler;
167 void wDeleteDeathHandler(WMagicNumber id)
169 DeathHandler *handler = (DeathHandler *) id;
171 if (!handler || !deathHandlers)
172 return;
174 /* array destructor will call wfree(handler) */
175 WMRemoveFromArray(deathHandlers, handler);
178 void DispatchEvent(XEvent * event)
180 if (deathHandlers)
181 handleDeadProcess(NULL);
183 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
184 WCHANGE_STATE(WSTATE_EXITING);
185 /* received SIGTERM */
187 * WMHandleEvent() can't be called from anything
188 * executed inside here, or we can get in a infinite
189 * recursive loop.
191 Shutdown(WSExitMode);
193 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
194 WCHANGE_STATE(WSTATE_RESTARTING);
196 Shutdown(WSRestartPreparationMode);
197 /* received SIGHUP */
198 Restart(NULL, True);
199 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
200 WCHANGE_STATE(WSTATE_NORMAL);
201 wDefaultsCheckDomains();
204 /* for the case that all that is wanted to be dispatched is
205 * the stuff above */
206 if (!event)
207 return;
209 saveTimestamp(event);
210 switch (event->type) {
211 case MapRequest:
212 handleMapRequest(event);
213 break;
215 case KeyPress:
216 handleKeyPress(event);
217 break;
219 case MotionNotify:
220 handleMotionNotify(event);
221 break;
223 case ConfigureRequest:
224 handleConfigureRequest(event);
225 break;
227 case DestroyNotify:
228 handleDestroyNotify(event);
229 break;
231 case MapNotify:
232 handleMapNotify(event);
233 break;
235 case UnmapNotify:
236 handleUnmapNotify(event);
237 break;
239 case ButtonPress:
240 handleButtonPress(event);
241 break;
243 case Expose:
244 handleExpose(event);
245 break;
247 case PropertyNotify:
248 handlePropertyNotify(event);
249 break;
251 case EnterNotify:
252 handleEnterNotify(event);
253 break;
255 case LeaveNotify:
256 handleLeaveNotify(event);
257 break;
259 case ClientMessage:
260 handleClientMessage(event);
261 break;
263 case ColormapNotify:
264 handleColormapNotify(event);
265 break;
267 case MappingNotify:
268 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
269 XRefreshKeyboardMapping(&event->xmapping);
270 break;
272 case FocusIn:
273 handleFocusIn(event);
274 break;
276 case VisibilityNotify:
277 handleVisibilityNotify(event);
278 break;
279 default:
280 handleExtensions(event);
281 break;
286 *----------------------------------------------------------------------
287 * inotifyHandleEvents-
288 * Check for inotify events
290 * Returns:
291 * After reading events for the given file descriptor (fd) and
292 * watch descriptor (wd)
294 * Side effects:
295 * Calls wDefaultsCheckDomains if config database is updated
296 *----------------------------------------------------------------------
298 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
299 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
300 void inotifyHandleEvents(int fd, int wd)
302 extern void wDefaultsCheckDomains(void);
303 ssize_t eventQLength, i = 0;
304 char buff[BUFF_SIZE] = { 0 };
305 /* Check config only once per read of the event queue */
306 int oneShotFlag = 0;
309 * Read off the queued events
310 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
311 * not occur; the block is on Xevents, but a config file change will normally
312 * occur as a result of an Xevent - so the event queue should never have more than
313 * a few entries before a read().
315 eventQLength = read(fd, buff, BUFF_SIZE);
317 /* check what events occured */
318 /* Should really check wd here too, but for now we only have one watch! */
319 while (i < eventQLength) {
320 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
323 * see inotify.h for event types.
325 if (pevent->mask & IN_DELETE_SELF) {
326 wwarning(_("the defaults database has been deleted!"
327 " Restart Window Maker to create the database" " with the default settings"));
328 close(fd);
330 if (pevent->mask & IN_UNMOUNT) {
331 wwarning(_("the unit containing the defaults database has"
332 " been unmounted. Setting --static mode." " Any changes will not be saved."));
333 close(fd);
334 wPreferences.flags.noupdates = 1;
336 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
337 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
338 wDefaultsCheckDomains();
341 /* move to next event in the buffer */
342 i += sizeof(struct inotify_event) + pevent->len;
347 *----------------------------------------------------------------------
348 * EventLoop-
349 * Processes X and internal events indefinitely.
351 * Returns:
352 * Never returns
354 * Side effects:
355 * The LastTimestamp global variable is updated.
356 * Calls inotifyGetEvents if defaults database changes.
357 *----------------------------------------------------------------------
359 void EventLoop(void)
361 XEvent event;
362 extern int inotifyFD;
363 extern int inotifyWD;
364 struct timeval time;
365 fd_set rfds;
366 int retVal = 0;
368 if (inotifyFD < 0 || inotifyWD < 0)
369 retVal = -1;
371 for (;;) {
373 WMNextEvent(dpy, &event); /* Blocks here */
374 WMHandleEvent(&event);
376 if (retVal != -1) {
377 time.tv_sec = 0;
378 time.tv_usec = 0;
379 FD_ZERO(&rfds);
380 FD_SET(inotifyFD, &rfds);
382 /* check for available read data from inotify - don't block! */
383 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
385 if (retVal < 0) { /* an error has occured */
386 wwarning(_("select failed. The inotify instance will be closed."
387 " Changes to the defaults database will require"
388 " a restart to take effect."));
389 close(inotifyFD);
390 continue;
392 if (FD_ISSET(inotifyFD, &rfds))
393 inotifyHandleEvents(inotifyFD, inotifyWD);
399 *----------------------------------------------------------------------
400 * ProcessPendingEvents --
401 * Processes the events that are currently pending (at the time
402 * this function is called) in the display's queue.
404 * Returns:
405 * After the pending events that were present at the function call
406 * are processed.
408 * Side effects:
409 * Many -- whatever handling events may involve.
411 *----------------------------------------------------------------------
413 void ProcessPendingEvents(void)
415 XEvent event;
416 int count;
418 XSync(dpy, False);
420 /* Take a snapshot of the event count in the queue */
421 count = XPending(dpy);
423 while (count > 0 && XPending(dpy)) {
424 WMNextEvent(dpy, &event);
425 WMHandleEvent(&event);
426 count--;
430 Bool IsDoubleClick(WScreen * scr, XEvent * event)
432 if ((scr->last_click_time > 0) &&
433 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
434 && (event->xbutton.button == scr->last_click_button)
435 && (event->xbutton.window == scr->last_click_window)) {
437 scr->flags.next_click_is_not_double = 1;
438 scr->last_click_time = 0;
439 scr->last_click_window = event->xbutton.window;
441 return True;
443 return False;
446 void NotifyDeadProcess(pid_t pid, unsigned char status)
448 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
449 wwarning("stack overflow: too many dead processes");
450 return;
452 /* stack the process to be handled later,
453 * as this is called from the signal handler */
454 deadProcesses[deadProcessPtr].pid = pid;
455 deadProcesses[deadProcessPtr].exit_status = status;
456 deadProcessPtr++;
459 static void handleDeadProcess(void *foo)
461 DeathHandler *tmp;
462 int i;
464 for (i = 0; i < deadProcessPtr; i++) {
465 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
468 if (!deathHandlers) {
469 deadProcessPtr = 0;
470 return;
473 /* get the pids on the queue and call handlers */
474 while (deadProcessPtr > 0) {
475 deadProcessPtr--;
477 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
478 tmp = WMGetFromArray(deathHandlers, i);
479 if (!tmp)
480 continue;
482 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
483 (*tmp->callback) (tmp->pid,
484 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
485 wDeleteDeathHandler(tmp);
491 static void saveTimestamp(XEvent * event)
494 * Never save CurrentTime as LastTimestamp because CurrentTime
495 * it's not a real timestamp (it's the 0L constant)
498 switch (event->type) {
499 case ButtonRelease:
500 case ButtonPress:
501 LastTimestamp = event->xbutton.time;
502 break;
503 case KeyPress:
504 case KeyRelease:
505 LastTimestamp = event->xkey.time;
506 break;
507 case MotionNotify:
508 LastTimestamp = event->xmotion.time;
509 break;
510 case PropertyNotify:
511 LastTimestamp = event->xproperty.time;
512 break;
513 case EnterNotify:
514 case LeaveNotify:
515 LastTimestamp = event->xcrossing.time;
516 break;
517 case SelectionClear:
518 LastTimestamp = event->xselectionclear.time;
519 break;
520 case SelectionRequest:
521 LastTimestamp = event->xselectionrequest.time;
522 break;
523 case SelectionNotify:
524 LastTimestamp = event->xselection.time;
525 #ifdef XDND
526 wXDNDProcessSelection(event);
527 #endif
528 break;
532 static int matchWindow(const void *item, const void *cdata)
534 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
537 static void handleExtensions(XEvent * event)
539 #ifdef KEEP_XKB_LOCK_STATUS
540 XkbEvent *xkbevent;
541 xkbevent = (XkbEvent *) event;
542 #endif /*KEEP_XKB_LOCK_STATUS */
543 #ifdef SHAPE
544 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
545 handleShapeNotify(event);
547 #endif
548 #ifdef KEEP_XKB_LOCK_STATUS
549 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
550 handleXkbIndicatorStateNotify(event);
552 #endif /*KEEP_XKB_LOCK_STATUS */
555 static void handleMapRequest(XEvent * ev)
557 WWindow *wwin;
558 WScreen *scr = NULL;
559 Window window = ev->xmaprequest.window;
561 if ((wwin = wWindowFor(window))) {
562 if (wwin->flags.shaded) {
563 wUnshadeWindow(wwin);
565 /* deiconify window */
566 if (wwin->flags.miniaturized) {
567 wDeiconifyWindow(wwin);
568 } else if (wwin->flags.hidden) {
569 WApplication *wapp = wApplicationOf(wwin->main_window);
570 /* go to the last workspace that the user worked on the app */
571 if (wapp) {
572 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
574 wUnhideApplication(wapp, False, False);
576 return;
579 scr = wScreenForRootWindow(ev->xmaprequest.parent);
581 wwin = wManageWindow(scr, window);
584 * This is to let the Dock know that the application it launched
585 * has already been mapped (eg: it has finished launching).
586 * It is not necessary for normally docked apps, but is needed for
587 * apps that were forcedly docked (like with dockit).
589 if (scr->last_dock) {
590 if (wwin && wwin->main_window != None && wwin->main_window != window)
591 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
592 else
593 wDockTrackWindowLaunch(scr->last_dock, window);
596 if (wwin) {
597 wClientSetState(wwin, NormalState, None);
598 if (wwin->flags.maximized) {
599 wMaximizeWindow(wwin, wwin->flags.maximized);
601 if (wwin->flags.shaded) {
602 wwin->flags.shaded = 0;
603 wwin->flags.skip_next_animation = 1;
604 wShadeWindow(wwin);
606 if (wwin->flags.miniaturized) {
607 wwin->flags.miniaturized = 0;
608 wwin->flags.skip_next_animation = 1;
609 wIconifyWindow(wwin);
611 if (wwin->flags.fullscreen) {
612 wwin->flags.fullscreen = 0;
613 wFullscreenWindow(wwin);
615 if (wwin->flags.hidden) {
616 WApplication *wapp = wApplicationOf(wwin->main_window);
618 wwin->flags.hidden = 0;
619 wwin->flags.skip_next_animation = 1;
620 if (wapp) {
621 wHideApplication(wapp);
627 static void handleDestroyNotify(XEvent * event)
629 WWindow *wwin;
630 WApplication *app;
631 Window window = event->xdestroywindow.window;
632 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
633 int widx;
635 wwin = wWindowFor(window);
636 if (wwin) {
637 wUnmanageWindow(wwin, False, True);
640 if (scr != NULL) {
641 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
642 WFakeGroupLeader *fPtr;
644 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
645 if (fPtr->retainCount > 0) {
646 fPtr->retainCount--;
647 if (fPtr->retainCount == 0 && fPtr->leader != None) {
648 XDestroyWindow(dpy, fPtr->leader);
649 fPtr->leader = None;
650 XFlush(dpy);
653 fPtr->origLeader = None;
657 app = wApplicationOf(window);
658 if (app) {
659 if (window == app->main_window) {
660 app->refcount = 0;
661 wwin = app->main_window_desc->screen_ptr->focused_window;
662 while (wwin) {
663 if (wwin->main_window == window) {
664 wwin->main_window = None;
666 wwin = wwin->prev;
669 wApplicationDestroy(app);
673 static void handleExpose(XEvent * event)
675 WObjDescriptor *desc;
676 XEvent ev;
678 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
680 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
681 return;
684 if (desc->handle_expose) {
685 (*desc->handle_expose) (desc, event);
689 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
691 switch (action) {
692 case WA_SELECT_WINDOWS:
693 wUnselectWindows(scr);
694 wSelectWindows(scr, event);
695 break;
696 case WA_OPEN_APPMENU:
697 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
698 /* ugly hack */
699 if (scr->root_menu) {
700 if (scr->root_menu->brother->flags.mapped)
701 event->xbutton.window = scr->root_menu->brother->frame->core->window;
702 else
703 event->xbutton.window = scr->root_menu->frame->core->window;
705 break;
706 case WA_OPEN_WINLISTMENU:
707 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
708 if (scr->switch_menu) {
709 if (scr->switch_menu->brother->flags.mapped)
710 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
711 else
712 event->xbutton.window = scr->switch_menu->frame->core->window;
714 break;
715 default:
716 break;
720 /* bindable */
721 static void handleButtonPress(XEvent * event)
723 WObjDescriptor *desc;
724 WScreen *scr;
726 scr = wScreenForRootWindow(event->xbutton.root);
728 #ifdef BALLOON_TEXT
729 wBalloonHide(scr);
730 #endif
732 if (event->xbutton.window == scr->root_win) {
733 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
734 executeButtonAction(scr, event, wPreferences.mouse_button1);
735 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
736 executeButtonAction(scr, event, wPreferences.mouse_button2);
737 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
738 executeButtonAction(scr, event, wPreferences.mouse_button3);
739 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
740 wWorkspaceRelativeChange(scr, 1);
741 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
742 wWorkspaceRelativeChange(scr, -1);
746 desc = NULL;
747 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
748 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
749 return;
753 if (desc->parent_type == WCLASS_WINDOW) {
754 XSync(dpy, 0);
756 if (event->xbutton.state & ( MOD_MASK | ControlMask )) {
757 XAllowEvents(dpy, AsyncPointer, CurrentTime);
760 /* if (wPreferences.focus_mode == WKF_CLICK) { */
761 if (wPreferences.ignore_focus_click) {
762 XAllowEvents(dpy, AsyncPointer, CurrentTime);
764 XAllowEvents(dpy, ReplayPointer, CurrentTime);
765 /* } */
766 XSync(dpy, 0);
767 } else if (desc->parent_type == WCLASS_APPICON
768 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
769 if (event->xbutton.state & MOD_MASK) {
770 XSync(dpy, 0);
771 XAllowEvents(dpy, AsyncPointer, CurrentTime);
772 XSync(dpy, 0);
776 if (desc->handle_mousedown != NULL) {
777 (*desc->handle_mousedown) (desc, event);
780 /* save double-click information */
781 if (scr->flags.next_click_is_not_double) {
782 scr->flags.next_click_is_not_double = 0;
783 } else {
784 scr->last_click_time = event->xbutton.time;
785 scr->last_click_button = event->xbutton.button;
786 scr->last_click_window = event->xbutton.window;
790 static void handleMapNotify(XEvent * event)
792 WWindow *wwin;
794 wwin = wWindowFor(event->xmap.event);
795 if (wwin && wwin->client_win == event->xmap.event) {
796 if (wwin->flags.miniaturized) {
797 wDeiconifyWindow(wwin);
798 } else {
799 XGrabServer(dpy);
800 wWindowMap(wwin);
801 wClientSetState(wwin, NormalState, None);
802 XUngrabServer(dpy);
807 static void handleUnmapNotify(XEvent * event)
809 WWindow *wwin;
810 XEvent ev;
811 Bool withdraw = False;
813 /* only process windows with StructureNotify selected
814 * (ignore SubstructureNotify) */
815 wwin = wWindowFor(event->xunmap.window);
816 if (!wwin)
817 return;
819 /* whether the event is a Withdrawal request */
820 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
821 withdraw = True;
823 if (wwin->client_win != event->xunmap.event && !withdraw)
824 return;
826 if (!wwin->flags.mapped && !withdraw
827 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
828 && !wwin->flags.miniaturized && !wwin->flags.hidden)
829 return;
831 XGrabServer(dpy);
832 XUnmapWindow(dpy, wwin->frame->core->window);
833 wwin->flags.mapped = 0;
834 XSync(dpy, 0);
835 /* check if the window was destroyed */
836 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
837 DispatchEvent(&ev);
838 } else {
839 Bool reparented = False;
841 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
842 reparented = True;
844 /* withdraw window */
845 wwin->flags.mapped = 0;
846 if (!reparented)
847 wClientSetState(wwin, WithdrawnState, None);
849 /* if the window was reparented, do not reparent it back to the
850 * root window */
851 wUnmanageWindow(wwin, !reparented, False);
853 XUngrabServer(dpy);
856 static void handleConfigureRequest(XEvent * event)
858 WWindow *wwin;
860 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
862 * Configure request for unmapped window
864 wClientConfigure(NULL, &(event->xconfigurerequest));
865 } else {
866 wClientConfigure(wwin, &(event->xconfigurerequest));
870 static void handlePropertyNotify(XEvent * event)
872 WWindow *wwin;
873 WApplication *wapp;
874 Window jr;
875 int ji;
876 unsigned int ju;
877 WScreen *scr;
879 wwin = wWindowFor(event->xproperty.window);
880 if (wwin) {
881 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
882 return;
884 wClientCheckProperty(wwin, &event->xproperty);
886 wapp = wApplicationOf(event->xproperty.window);
887 if (wapp) {
888 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
891 scr = wScreenForWindow(event->xproperty.window);
894 static void handleClientMessage(XEvent * event)
896 WWindow *wwin;
897 WObjDescriptor *desc;
899 /* handle transition from Normal to Iconic state */
900 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
901 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
903 wwin = wWindowFor(event->xclient.window);
904 if (!wwin)
905 return;
906 if (!wwin->flags.miniaturized)
907 wIconifyWindow(wwin);
908 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
909 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
911 if (!scr)
912 return;
914 if (event->xclient.data.l[1] == 1) { /* starting */
915 wColormapAllowClientInstallation(scr, True);
916 } else { /* stopping */
917 wColormapAllowClientInstallation(scr, False);
919 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
921 wDefaultsCheckDomains();
923 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
924 WApplication *wapp;
925 int done = 0;
926 wapp = wApplicationOf(event->xclient.window);
927 if (wapp) {
928 switch (event->xclient.data.l[0]) {
929 case WMFHideOtherApplications:
930 wHideOtherApplications(wapp->main_window_desc);
931 done = 1;
932 break;
934 case WMFHideApplication:
935 wHideApplication(wapp);
936 done = 1;
937 break;
940 if (!done) {
941 wwin = wWindowFor(event->xclient.window);
942 if (wwin) {
943 switch (event->xclient.data.l[0]) {
944 case WMFHideOtherApplications:
945 wHideOtherApplications(wwin);
946 break;
948 case WMFHideApplication:
949 wHideApplication(wApplicationOf(wwin->main_window));
950 break;
954 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
955 wwin = wWindowFor(event->xclient.window);
956 if (!wwin)
957 return;
958 switch (event->xclient.data.l[0]) {
959 case GSWindowLevelAttr:
961 int level = (int)event->xclient.data.l[1];
963 if (WINDOW_LEVEL(wwin) != level) {
964 ChangeStackingLevel(wwin->frame->core, level);
967 break;
969 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
970 wwin = wWindowFor(event->xclient.window);
971 if (!wwin)
972 return;
973 switch (event->xclient.data.l[0]) {
974 case WMTitleBarNormal:
975 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
976 break;
977 case WMTitleBarMain:
978 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
979 break;
980 case WMTitleBarKey:
981 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
982 break;
984 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
985 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
986 if (!scr)
987 return;
988 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
989 } else if (wNETWMProcessClientMessage(&event->xclient)) {
990 /* do nothing */
991 #ifdef XDND
992 } else if (wXDNDProcessClientMessage(&event->xclient)) {
993 /* do nothing */
994 #endif /* XDND */
995 } else {
997 * Non-standard thing, but needed by OffiX DND.
998 * For when the icon frame gets a ClientMessage
999 * that should have gone to the icon_window.
1001 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1002 struct WIcon *icon = NULL;
1004 if (desc->parent_type == WCLASS_MINIWINDOW) {
1005 icon = (WIcon *) desc->parent;
1006 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1007 icon = ((WAppIcon *) desc->parent)->icon;
1009 if (icon && (wwin = icon->owner)) {
1010 if (wwin->client_win != event->xclient.window) {
1011 event->xclient.window = wwin->client_win;
1012 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1019 static void raiseWindow(WScreen * scr)
1021 WWindow *wwin;
1023 scr->autoRaiseTimer = NULL;
1025 wwin = wWindowFor(scr->autoRaiseWindow);
1026 if (!wwin)
1027 return;
1029 if (!wwin->flags.destroyed && wwin->flags.focused) {
1030 wRaiseFrame(wwin->frame->core);
1031 /* this is needed or a race condition will occur */
1032 XSync(dpy, False);
1036 static void handleEnterNotify(XEvent * event)
1038 WWindow *wwin;
1039 WObjDescriptor *desc = NULL;
1040 XEvent ev;
1041 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1043 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1044 /* already left the window... */
1045 saveTimestamp(&ev);
1046 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1047 return;
1051 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1052 if (desc->handle_enternotify)
1053 (*desc->handle_enternotify) (desc, event);
1056 /* enter to window */
1057 wwin = wWindowFor(event->xcrossing.window);
1058 if (!wwin) {
1059 if (wPreferences.colormap_mode == WCM_POINTER) {
1060 wColormapInstallForWindow(scr, NULL);
1062 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1063 WMDeleteTimerHandler(scr->autoRaiseTimer);
1064 scr->autoRaiseTimer = NULL;
1066 } else {
1067 /* set auto raise timer even if in focus-follows-mouse mode
1068 * and the event is for the frame window, even if the window
1069 * has focus already. useful if you move the pointer from a focused
1070 * window to the root window and back pretty fast
1072 * set focus if in focus-follows-mouse mode and the event
1073 * is for the frame window and window doesn't have focus yet */
1074 if (wPreferences.focus_mode == WKF_SLOPPY
1075 && wwin->frame->core->window == event->xcrossing.window && !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, (WMCallback *) raiseWindow, scr);
1090 /* Install colormap for window, if the colormap installation mode
1091 * is colormap_follows_mouse */
1092 if (wPreferences.colormap_mode == WCM_POINTER) {
1093 if (wwin->client_win == event->xcrossing.window)
1094 wColormapInstallForWindow(scr, wwin);
1095 else
1096 wColormapInstallForWindow(scr, NULL);
1100 /* a little kluge to hide the clip balloon */
1101 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1102 if (!desc) {
1103 XUnmapWindow(dpy, scr->clip_balloon);
1104 scr->flags.clip_balloon_mapped = 0;
1105 } else {
1106 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1107 XUnmapWindow(dpy, scr->clip_balloon);
1108 scr->flags.clip_balloon_mapped = 0;
1113 if (event->xcrossing.window == event->xcrossing.root
1114 && event->xcrossing.detail == NotifyNormal
1115 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1117 wSetFocusTo(scr, scr->focused_window);
1119 #ifdef BALLOON_TEXT
1120 wBalloonEnteredObject(scr, desc);
1121 #endif
1124 static void handleLeaveNotify(XEvent * event)
1126 WObjDescriptor *desc = NULL;
1128 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1129 if (desc->handle_leavenotify)
1130 (*desc->handle_leavenotify) (desc, event);
1134 #ifdef SHAPE
1135 static void handleShapeNotify(XEvent * event)
1137 XShapeEvent *shev = (XShapeEvent *) event;
1138 WWindow *wwin;
1139 XEvent ev;
1141 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1142 XShapeEvent *sev = (XShapeEvent *) & ev;
1144 if (sev->kind == ShapeBounding) {
1145 if (sev->shaped == shev->shaped) {
1146 *shev = *sev;
1147 } else {
1148 XPutBackEvent(dpy, &ev);
1149 break;
1154 wwin = wWindowFor(shev->window);
1155 if (!wwin || shev->kind != ShapeBounding)
1156 return;
1158 if (!shev->shaped && wwin->flags.shaped) {
1160 wwin->flags.shaped = 0;
1161 wWindowClearShape(wwin);
1163 } else if (shev->shaped) {
1165 wwin->flags.shaped = 1;
1166 wWindowSetShape(wwin);
1169 #endif /* SHAPE */
1171 #ifdef KEEP_XKB_LOCK_STATUS
1172 /* please help ]d if you know what to do */
1173 handleXkbIndicatorStateNotify(XEvent * event)
1175 WWindow *wwin;
1176 WScreen *scr;
1177 XkbStateRec staterec;
1178 int i;
1180 for (i = 0; i < wScreenCount; i++) {
1181 scr = wScreenWithNumber(i);
1182 wwin = scr->focused_window;
1183 if (wwin && wwin->flags.focused) {
1184 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1185 if (wwin->frame->languagemode != staterec.group) {
1186 wwin->frame->last_languagemode = wwin->frame->languagemode;
1187 wwin->frame->languagemode = staterec.group;
1189 #ifdef XKB_BUTTON_HINT
1190 if (wwin->frame->titlebar) {
1191 wFrameWindowPaint(wwin->frame);
1193 #endif
1197 #endif /*KEEP_XKB_LOCK_STATUS */
1199 static void handleColormapNotify(XEvent * event)
1201 WWindow *wwin;
1202 WScreen *scr;
1203 Bool reinstall = False;
1205 wwin = wWindowFor(event->xcolormap.window);
1206 if (!wwin)
1207 return;
1209 scr = wwin->screen_ptr;
1211 do {
1212 if (wwin) {
1213 if (event->xcolormap.new) {
1214 XWindowAttributes attr;
1216 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1218 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1219 scr->current_colormap = attr.colormap;
1221 reinstall = True;
1222 } else if (event->xcolormap.state == ColormapUninstalled &&
1223 scr->current_colormap == event->xcolormap.colormap) {
1225 /* some bastard app (like XV) removed our colormap */
1227 * can't enforce or things like xscreensaver wont work
1228 * reinstall = True;
1230 } else if (event->xcolormap.state == ColormapInstalled &&
1231 scr->current_colormap == event->xcolormap.colormap) {
1233 /* someone has put our colormap back */
1234 reinstall = False;
1237 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1238 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1240 if (reinstall && scr->current_colormap != None) {
1241 if (!scr->flags.colormap_stuff_blocked)
1242 XInstallColormap(dpy, scr->current_colormap);
1246 static void handleFocusIn(XEvent * event)
1248 WWindow *wwin;
1251 * For applications that like stealing the focus.
1253 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1254 saveTimestamp(event);
1255 if (event->xfocus.mode == NotifyUngrab
1256 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1257 return;
1260 wwin = wWindowFor(event->xfocus.window);
1261 if (wwin && !wwin->flags.focused) {
1262 if (wwin->flags.mapped)
1263 wSetFocusTo(wwin->screen_ptr, wwin);
1264 else
1265 wSetFocusTo(wwin->screen_ptr, NULL);
1266 } else if (!wwin) {
1267 WScreen *scr = wScreenForWindow(event->xfocus.window);
1268 if (scr)
1269 wSetFocusTo(scr, NULL);
1273 static WWindow *windowUnderPointer(WScreen * scr)
1275 unsigned int mask;
1276 int foo;
1277 Window bar, win;
1279 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1280 return wWindowFor(win);
1281 return NULL;
1284 static int CheckFullScreenWindowFocused(WScreen * scr)
1286 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1287 return 1;
1288 else
1289 return 0;
1292 static void handleKeyPress(XEvent * event)
1294 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1295 WWindow *wwin = scr->focused_window;
1296 short i, widx;
1297 int modifiers;
1298 int command = -1;
1299 #ifdef KEEP_XKB_LOCK_STATUS
1300 XkbStateRec staterec;
1301 #endif /*KEEP_XKB_LOCK_STATUS */
1303 /* ignore CapsLock */
1304 modifiers = event->xkey.state & ValidModMask;
1306 for (i = 0; i < WKBD_LAST; i++) {
1307 if (wKeyBindings[i].keycode == 0)
1308 continue;
1310 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1311 || */ wKeyBindings[i].modifier ==
1312 modifiers)) {
1313 command = i;
1314 break;
1318 if (command < 0) {
1320 if (!wRootMenuPerformShortcut(event)) {
1321 static int dontLoop = 0;
1323 if (dontLoop > 10) {
1324 wwarning("problem with key event processing code");
1325 return;
1327 dontLoop++;
1328 /* if the focused window is an internal window, try redispatching
1329 * the event to the managed window, as it can be a WINGs window */
1330 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1331 /* client_leader contains the WINGs toplevel */
1332 event->xany.window = wwin->client_leader;
1333 WMHandleEvent(event);
1335 dontLoop--;
1337 return;
1339 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1340 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1342 switch (command) {
1344 case WKBD_ROOTMENU:
1345 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1346 if (!CheckFullScreenWindowFocused(scr)) {
1347 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1348 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1349 True);
1351 break;
1352 case WKBD_WINDOWLIST:
1353 if (!CheckFullScreenWindowFocused(scr)) {
1354 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1355 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1356 True);
1358 break;
1360 case WKBD_WINDOWMENU:
1361 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1362 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1363 break;
1364 case WKBD_MINIATURIZE:
1365 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1366 && !WFLAGP(wwin, no_miniaturizable)) {
1367 CloseWindowMenu(scr);
1369 if (wwin->protocols.MINIATURIZE_WINDOW)
1370 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1371 else {
1372 wIconifyWindow(wwin);
1375 break;
1376 case WKBD_HIDE:
1377 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1378 WApplication *wapp = wApplicationOf(wwin->main_window);
1379 CloseWindowMenu(scr);
1381 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1382 wHideApplication(wapp);
1385 break;
1386 case WKBD_HIDE_OTHERS:
1387 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1388 CloseWindowMenu(scr);
1390 wHideOtherApplications(wwin);
1392 break;
1393 case WKBD_MAXIMIZE:
1394 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1395 CloseWindowMenu(scr);
1397 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_HORIZONTAL))
1398 wUnmaximizeWindow(wwin);
1399 else
1400 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
1402 break;
1403 case WKBD_VMAXIMIZE:
1404 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1405 CloseWindowMenu(scr);
1407 if (wwin->flags.maximized == MAX_VERTICAL)
1408 wUnmaximizeWindow(wwin);
1409 else
1410 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_KEYBOARD);
1412 break;
1413 case WKBD_HMAXIMIZE:
1414 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1415 CloseWindowMenu(scr);
1417 if (wwin->flags.maximized == MAX_HORIZONTAL)
1418 wUnmaximizeWindow(wwin);
1419 else
1420 wMaximizeWindow(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
1422 break;
1423 case WKBD_LHMAXIMIZE:
1424 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1425 CloseWindowMenu(scr);
1427 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_LEFTHALF))
1428 wUnmaximizeWindow(wwin);
1429 else
1430 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
1432 break;
1433 case WKBD_RHMAXIMIZE:
1434 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1435 CloseWindowMenu(scr);
1437 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_RIGHTHALF))
1438 wUnmaximizeWindow(wwin);
1439 else
1440 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
1442 break;
1443 case WKBD_MAXIMUS:
1444 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1445 CloseWindowMenu(scr);
1447 if (wwin->flags.maximized == MAX_MAXIMUS)
1448 wUnmaximizeWindow(wwin);
1449 else
1450 wMaximizeWindow(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
1452 break;
1453 case WKBD_RAISE:
1454 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1455 CloseWindowMenu(scr);
1457 wRaiseFrame(wwin->frame->core);
1459 break;
1460 case WKBD_LOWER:
1461 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1462 CloseWindowMenu(scr);
1464 wLowerFrame(wwin->frame->core);
1466 break;
1467 case WKBD_RAISELOWER:
1468 /* raise or lower the window under the pointer, not the
1469 * focused one
1471 wwin = windowUnderPointer(scr);
1472 if (wwin)
1473 wRaiseLowerFrame(wwin->frame->core);
1474 break;
1475 case WKBD_SHADE:
1476 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1477 if (wwin->flags.shaded)
1478 wUnshadeWindow(wwin);
1479 else
1480 wShadeWindow(wwin);
1482 break;
1483 case WKBD_MOVERESIZE:
1484 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1485 CloseWindowMenu(scr);
1487 wKeyboardMoveResizeWindow(wwin);
1489 break;
1490 case WKBD_CLOSE:
1491 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1492 CloseWindowMenu(scr);
1493 if (wwin->protocols.DELETE_WINDOW)
1494 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1496 break;
1497 case WKBD_SELECT:
1498 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1499 wSelectWindow(wwin, !wwin->flags.selected);
1501 break;
1502 case WKBD_FOCUSNEXT:
1503 StartWindozeCycle(wwin, event, True, False);
1504 break;
1506 case WKBD_FOCUSPREV:
1507 StartWindozeCycle(wwin, event, False, False);
1508 break;
1510 case WKBD_GROUPNEXT:
1511 StartWindozeCycle(wwin, event, True, True);
1512 break;
1514 case WKBD_GROUPPREV:
1515 StartWindozeCycle(wwin, event, False, True);
1516 break;
1518 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
1519 widx = command - WKBD_WORKSPACE1;
1520 i = (scr->current_workspace / 10) * 10 + widx;
1521 if (wPreferences.ws_advance || i < scr->workspace_count)
1522 wWorkspaceChange(scr, i);
1523 break;
1525 case WKBD_NEXTWORKSPACE:
1526 wWorkspaceRelativeChange(scr, 1);
1527 break;
1528 case WKBD_PREVWORKSPACE:
1529 wWorkspaceRelativeChange(scr, -1);
1530 break;
1532 case WKBD_WINDOW1:
1533 case WKBD_WINDOW2:
1534 case WKBD_WINDOW3:
1535 case WKBD_WINDOW4:
1536 case WKBD_WINDOW5:
1537 case WKBD_WINDOW6:
1538 case WKBD_WINDOW7:
1539 case WKBD_WINDOW8:
1540 case WKBD_WINDOW9:
1541 case WKBD_WINDOW10:
1543 widx = command - WKBD_WINDOW1;
1545 if (scr->shortcutWindows[widx]) {
1546 WMArray *list = scr->shortcutWindows[widx];
1547 int cw;
1548 int count = WMGetArrayItemCount(list);
1549 WWindow *twin;
1550 WMArrayIterator iter;
1551 WWindow *wwin;
1553 wUnselectWindows(scr);
1554 cw = scr->current_workspace;
1556 WM_ETARETI_ARRAY(list, wwin, iter) {
1557 if (count > 1)
1558 wWindowChangeWorkspace(wwin, cw);
1560 wMakeWindowVisible(wwin);
1562 if (count > 1)
1563 wSelectWindow(wwin, True);
1566 /* rotate the order of windows, to create a cycling effect */
1567 twin = WMGetFromArray(list, 0);
1568 WMDeleteFromArray(list, 0);
1569 WMAddToArray(list, twin);
1571 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1572 if (scr->shortcutWindows[widx]) {
1573 WMFreeArray(scr->shortcutWindows[widx]);
1574 scr->shortcutWindows[widx] = NULL;
1577 if (wwin->flags.selected && scr->selected_windows) {
1578 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1579 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1580 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1581 } else {
1582 scr->shortcutWindows[widx] = WMCreateArray(4);
1583 WMAddToArray(scr->shortcutWindows[widx], wwin);
1586 wSelectWindow(wwin, !wwin->flags.selected);
1587 XFlush(dpy);
1588 wusleep(3000);
1589 wSelectWindow(wwin, !wwin->flags.selected);
1590 XFlush(dpy);
1592 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1594 if (wwin->flags.selected && scr->selected_windows) {
1595 if (scr->shortcutWindows[widx]) {
1596 WMFreeArray(scr->shortcutWindows[widx]);
1598 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1602 break;
1604 case WKBD_SWITCH_SCREEN:
1605 if (wScreenCount > 1) {
1606 WScreen *scr2;
1607 int i;
1609 /* find index of this screen */
1610 for (i = 0; i < wScreenCount; i++) {
1611 if (wScreenWithNumber(i) == scr)
1612 break;
1614 i++;
1615 if (i >= wScreenCount) {
1616 i = 0;
1618 scr2 = wScreenWithNumber(i);
1620 if (scr2) {
1621 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1622 scr2->scr_width / 2, scr2->scr_height / 2);
1625 break;
1627 case WKBD_NEXTWSLAYER:
1628 case WKBD_PREVWSLAYER:
1630 int row, column;
1632 row = scr->current_workspace / 10;
1633 column = scr->current_workspace % 10;
1635 if (command == WKBD_NEXTWSLAYER) {
1636 if ((row + 1) * 10 < scr->workspace_count)
1637 wWorkspaceChange(scr, column + (row + 1) * 10);
1638 } else {
1639 if (row > 0)
1640 wWorkspaceChange(scr, column + (row - 1) * 10);
1643 break;
1644 case WKBD_CLIPRAISELOWER:
1645 if (!wPreferences.flags.noclip)
1646 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1647 break;
1648 case WKBD_DOCKRAISELOWER:
1649 if (!wPreferences.flags.nodock)
1650 wDockRaiseLower(scr->dock);
1651 break;
1652 #ifdef KEEP_XKB_LOCK_STATUS
1653 case WKBD_TOGGLE:
1654 if (wPreferences.modelock) {
1655 /*toggle */
1656 wwin = scr->focused_window;
1658 if (wwin && wwin->flags.mapped
1659 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1660 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1661 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1663 wwin->frame->languagemode = wwin->frame->last_languagemode;
1664 wwin->frame->last_languagemode = staterec.group;
1665 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1669 break;
1670 #endif /* KEEP_XKB_LOCK_STATUS */
1674 static void handleMotionNotify(XEvent * event)
1676 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1678 if (wPreferences.scrollable_menus) {
1679 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1680 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1682 if (scr->flags.jump_back_pending ||
1683 p.x <= (rect.pos.x + 1) ||
1684 p.x >= (rect.pos.x + rect.size.width - 2) ||
1685 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1686 WMenu *menu;
1688 menu = wMenuUnderPointer(scr);
1689 if (menu != NULL)
1690 wMenuScroll(menu, event);
1695 static void handleVisibilityNotify(XEvent * event)
1697 WWindow *wwin;
1699 wwin = wWindowFor(event->xvisibility.window);
1700 if (!wwin)
1701 return;
1702 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);