Added option to 'configure' to control debug information for compilation
[wmaker-crm.git] / src / event.c
blob53d5acf59f1e2ea354ce55c7cdb1fa831867c23c
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #ifdef HAVE_INOTIFY
25 #include <sys/select.h>
26 #include <sys/inotify.h>
27 #endif
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <time.h>
36 #include <X11/Xlib.h>
37 #include <X11/Xutil.h>
38 #ifdef SHAPE
39 # include <X11/extensions/shape.h>
40 #endif
41 #ifdef XDND
42 #include "xdnd.h"
43 #endif
45 #ifdef HAVE_XRANDR
46 #include <X11/extensions/Xrandr.h>
47 #endif
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
54 #include "window.h"
55 #include "actions.h"
56 #include "client.h"
57 #include "main.h"
58 #include "keybind.h"
59 #include "application.h"
60 #include "stacking.h"
61 #include "defaults.h"
62 #include "workspace.h"
63 #include "dock.h"
64 #include "framewin.h"
65 #include "properties.h"
66 #include "balloon.h"
67 #include "xinerama.h"
68 #include "wmspec.h"
69 #include "rootmenu.h"
70 #include "colormap.h"
72 /******** Global Variables **********/
73 extern XContext wWinContext;
74 extern XContext wVEdgeContext;
76 extern Cursor wCursor[WCUR_LAST];
78 extern WShortKey wKeyBindings[WKBD_LAST];
79 extern int wScreenCount;
80 extern Time LastTimestamp;
81 extern Time LastFocusChange;
83 extern WPreferences wPreferences;
85 #define MOD_MASK wPreferences.modifier_mask
87 extern Atom _XA_WM_COLORMAP_NOTIFY;
89 extern Atom _XA_WM_CHANGE_STATE;
90 extern Atom _XA_WM_DELETE_WINDOW;
91 extern Atom _XA_GNUSTEP_WM_ATTR;
92 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
93 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
94 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
95 extern Atom _XA_WINDOWMAKER_COMMAND;
96 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
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 #ifdef HAVE_XRANDR
108 extern Bool has_randr;
109 extern int randr_event_base;
110 #endif
112 /* special flags */
113 /*extern char WDelayedActionSet;*/
115 /************ Local stuff ***********/
117 static void saveTimestamp(XEvent *event);
118 static void handleColormapNotify(XEvent *event);
119 static void handleMapNotify(XEvent *event);
120 static void handleUnmapNotify(XEvent *event);
121 static void handleButtonPress(XEvent *event);
122 static void handleExpose(XEvent *event);
123 static void handleDestroyNotify(XEvent *event);
124 static void handleConfigureRequest(XEvent *event);
125 static void handleMapRequest(XEvent *event);
126 static void handlePropertyNotify(XEvent *event);
127 static void handleEnterNotify(XEvent *event);
128 static void handleLeaveNotify(XEvent *event);
129 static void handleExtensions(XEvent *event);
130 static void handleClientMessage(XEvent *event);
131 static void handleKeyPress(XEvent *event);
132 static void handleFocusIn(XEvent *event);
133 static void handleMotionNotify(XEvent *event);
134 static void handleVisibilityNotify(XEvent *event);
135 static void handle_inotify_events(int fd, int wd);
136 static void wdelete_death_handler(WMagicNumber id);
139 #ifdef SHAPE
140 static void handleShapeNotify(XEvent *event);
141 #endif
143 #ifdef KEEP_XKB_LOCK_STATUS
144 static void handleXkbIndicatorStateNotify(XEvent *event);
145 #endif
147 /* called from the signal handler */
148 void NotifyDeadProcess(pid_t pid, unsigned char status);
150 /* real dead process handler */
151 static void handleDeadProcess(void *foo);
153 typedef struct DeadProcesses {
154 pid_t pid;
155 unsigned char exit_status;
156 } DeadProcesses;
158 /* stack of dead processes */
159 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
160 static int deadProcessPtr = 0;
162 typedef struct DeathHandler {
163 WDeathHandler *callback;
164 pid_t pid;
165 void *client_data;
166 } DeathHandler;
168 static WMArray *deathHandlers = NULL;
170 WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
172 DeathHandler *handler;
174 handler = malloc(sizeof(DeathHandler));
175 if (!handler)
176 return 0;
178 handler->pid = pid;
179 handler->callback = callback;
180 handler->client_data = cdata;
182 if (!deathHandlers)
183 deathHandlers = WMCreateArrayWithDestructor(8, free);
185 WMAddToArray(deathHandlers, handler);
187 return handler;
190 static void wdelete_death_handler(WMagicNumber id)
192 DeathHandler *handler = (DeathHandler *) id;
194 if (!handler || !deathHandlers)
195 return;
197 /* array destructor will call free(handler) */
198 WMRemoveFromArray(deathHandlers, handler);
201 void DispatchEvent(XEvent * event)
203 if (deathHandlers)
204 handleDeadProcess(NULL);
206 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
207 WCHANGE_STATE(WSTATE_EXITING);
208 /* received SIGTERM */
210 * WMHandleEvent() can't be called from anything
211 * executed inside here, or we can get in a infinite
212 * recursive loop.
214 Shutdown(WSExitMode);
216 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
217 WCHANGE_STATE(WSTATE_RESTARTING);
219 Shutdown(WSRestartPreparationMode);
220 /* received SIGHUP */
221 Restart(NULL, True);
222 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
223 WCHANGE_STATE(WSTATE_NORMAL);
224 wDefaultsCheckDomains(NULL);
227 /* for the case that all that is wanted to be dispatched is
228 * the stuff above */
229 if (!event)
230 return;
232 saveTimestamp(event);
233 switch (event->type) {
234 case MapRequest:
235 handleMapRequest(event);
236 break;
238 case KeyPress:
239 handleKeyPress(event);
240 break;
242 case MotionNotify:
243 handleMotionNotify(event);
244 break;
246 case ConfigureRequest:
247 handleConfigureRequest(event);
248 break;
250 case DestroyNotify:
251 handleDestroyNotify(event);
252 break;
254 case MapNotify:
255 handleMapNotify(event);
256 break;
258 case UnmapNotify:
259 handleUnmapNotify(event);
260 break;
262 case ButtonPress:
263 handleButtonPress(event);
264 break;
266 case Expose:
267 handleExpose(event);
268 break;
270 case PropertyNotify:
271 handlePropertyNotify(event);
272 break;
274 case EnterNotify:
275 handleEnterNotify(event);
276 break;
278 case LeaveNotify:
279 handleLeaveNotify(event);
280 break;
282 case ClientMessage:
283 handleClientMessage(event);
284 break;
286 case ColormapNotify:
287 handleColormapNotify(event);
288 break;
290 case MappingNotify:
291 if (event->xmapping.request == MappingKeyboard || 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;
303 case ConfigureNotify:
304 if (event->xconfigure.window == DefaultRootWindow(dpy)) {
305 #ifdef HAVE_XRANDR
306 XRRUpdateConfiguration(event);
307 #endif
309 break;
311 default:
312 handleExtensions(event);
313 break;
317 #ifdef HAVE_INOTIFY
319 *----------------------------------------------------------------------
320 * handle_inotify_events-
321 * Check for inotify events
323 * Returns:
324 * After reading events for the given file descriptor (fd) and
325 * watch descriptor (wd)
327 * Side effects:
328 * Calls wDefaultsCheckDomains if config database is updated
329 *----------------------------------------------------------------------
331 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
332 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
333 static void handle_inotify_events(int fd, int wd)
335 extern void wDefaultsCheckDomains(void *);
336 ssize_t eventQLength, i = 0;
337 char buff[BUFF_SIZE] = { 0 };
338 /* Check config only once per read of the event queue */
339 int oneShotFlag = 0;
342 * Read off the queued events
343 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
344 * not occur; the block is on Xevents, but a config file change will normally
345 * occur as a result of an Xevent - so the event queue should never have more than
346 * a few entries before a read().
348 eventQLength = read(fd, buff, BUFF_SIZE);
350 /* check what events occured */
351 /* Should really check wd here too, but for now we only have one watch! */
352 while (i < eventQLength) {
353 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
356 * see inotify.h for event types.
358 if (pevent->mask & IN_DELETE_SELF) {
359 wwarning(_("the defaults database has been deleted!"
360 " Restart Window Maker to create the database" " with the default settings"));
361 close(fd);
363 if (pevent->mask & IN_UNMOUNT) {
364 wwarning(_("the unit containing the defaults database has"
365 " been unmounted. Setting --static mode." " Any changes will not be saved."));
366 close(fd);
367 wPreferences.flags.noupdates = 1;
369 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
370 wwarning(_("Inotify: Reading config files in defaults database."));
371 wDefaultsCheckDomains(NULL);
374 /* move to next event in the buffer */
375 i += sizeof(struct inotify_event) + pevent->len;
378 #endif /* HAVE_INOTIFY */
381 *----------------------------------------------------------------------
382 * EventLoop-
383 * Processes X and internal events indefinitely.
385 * Returns:
386 * Never returns
388 * Side effects:
389 * The LastTimestamp global variable is updated.
390 * Calls inotifyGetEvents if defaults database changes.
391 *----------------------------------------------------------------------
393 void EventLoop(void)
395 XEvent event;
396 #ifdef HAVE_INOTIFY
397 extern int inotifyFD;
398 extern int inotifyWD;
399 struct timeval time;
400 fd_set rfds;
401 int retVal = 0;
403 if (inotifyFD < 0 || inotifyWD < 0)
404 retVal = -1;
405 #endif
407 for (;;) {
409 WMNextEvent(dpy, &event); /* Blocks here */
410 WMHandleEvent(&event);
411 #ifdef HAVE_INOTIFY
412 if (retVal != -1) {
413 time.tv_sec = 0;
414 time.tv_usec = 0;
415 FD_ZERO(&rfds);
416 FD_SET(inotifyFD, &rfds);
418 /* check for available read data from inotify - don't block! */
419 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
421 if (retVal < 0) { /* an error has occured */
422 wwarning(_("select failed. The inotify instance will be closed."
423 " Changes to the defaults database will require"
424 " a restart to take effect."));
425 close(inotifyFD);
426 continue;
428 if (FD_ISSET(inotifyFD, &rfds))
429 handle_inotify_events(inotifyFD, inotifyWD);
431 #endif
436 *----------------------------------------------------------------------
437 * ProcessPendingEvents --
438 * Processes the events that are currently pending (at the time
439 * this function is called) in the display's queue.
441 * Returns:
442 * After the pending events that were present at the function call
443 * are processed.
445 * Side effects:
446 * Many -- whatever handling events may involve.
448 *----------------------------------------------------------------------
450 void ProcessPendingEvents(void)
452 XEvent event;
453 int count;
455 XSync(dpy, False);
457 /* Take a snapshot of the event count in the queue */
458 count = XPending(dpy);
460 while (count > 0 && XPending(dpy)) {
461 WMNextEvent(dpy, &event);
462 WMHandleEvent(&event);
463 count--;
467 Bool IsDoubleClick(WScreen * scr, XEvent * event)
469 if ((scr->last_click_time > 0) &&
470 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
471 && (event->xbutton.button == scr->last_click_button)
472 && (event->xbutton.window == scr->last_click_window)) {
474 scr->flags.next_click_is_not_double = 1;
475 scr->last_click_time = 0;
476 scr->last_click_window = event->xbutton.window;
478 return True;
480 return False;
483 void NotifyDeadProcess(pid_t pid, unsigned char status)
485 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
486 wwarning("stack overflow: too many dead processes");
487 return;
489 /* stack the process to be handled later,
490 * as this is called from the signal handler */
491 deadProcesses[deadProcessPtr].pid = pid;
492 deadProcesses[deadProcessPtr].exit_status = status;
493 deadProcessPtr++;
496 static void handleDeadProcess(void *foo)
498 DeathHandler *tmp;
499 int i;
501 for (i = 0; i < deadProcessPtr; i++) {
502 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
505 if (!deathHandlers) {
506 deadProcessPtr = 0;
507 return;
510 /* get the pids on the queue and call handlers */
511 while (deadProcessPtr > 0) {
512 deadProcessPtr--;
514 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
515 tmp = WMGetFromArray(deathHandlers, i);
516 if (!tmp)
517 continue;
519 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
520 (*tmp->callback) (tmp->pid,
521 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
522 wdelete_death_handler(tmp);
528 static void saveTimestamp(XEvent * event)
531 * Never save CurrentTime as LastTimestamp because CurrentTime
532 * it's not a real timestamp (it's the 0L constant)
535 switch (event->type) {
536 case ButtonRelease:
537 case ButtonPress:
538 LastTimestamp = event->xbutton.time;
539 break;
540 case KeyPress:
541 case KeyRelease:
542 LastTimestamp = event->xkey.time;
543 break;
544 case MotionNotify:
545 LastTimestamp = event->xmotion.time;
546 break;
547 case PropertyNotify:
548 LastTimestamp = event->xproperty.time;
549 break;
550 case EnterNotify:
551 case LeaveNotify:
552 LastTimestamp = event->xcrossing.time;
553 break;
554 case SelectionClear:
555 LastTimestamp = event->xselectionclear.time;
556 break;
557 case SelectionRequest:
558 LastTimestamp = event->xselectionrequest.time;
559 break;
560 case SelectionNotify:
561 LastTimestamp = event->xselection.time;
562 #ifdef XDND
563 wXDNDProcessSelection(event);
564 #endif
565 break;
569 static int matchWindow(const void *item, const void *cdata)
571 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
574 static void handleExtensions(XEvent * event)
576 #ifdef KEEP_XKB_LOCK_STATUS
577 XkbEvent *xkbevent;
578 xkbevent = (XkbEvent *) event;
579 #endif /*KEEP_XKB_LOCK_STATUS */
580 #ifdef SHAPE
581 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
582 handleShapeNotify(event);
584 #endif
585 #ifdef KEEP_XKB_LOCK_STATUS
586 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
587 handleXkbIndicatorStateNotify(event);
589 #endif /*KEEP_XKB_LOCK_STATUS */
590 #ifdef HAVE_XRANDR
591 if (has_randr && event->type == (randr_event_base + RRScreenChangeNotify)) {
592 /* From xrandr man page: "Clients must call back into Xlib using
593 * XRRUpdateConfiguration when screen configuration change notify
594 * events are generated */
595 XRRUpdateConfiguration(event);
596 WCHANGE_STATE(WSTATE_RESTARTING);
597 Shutdown(WSRestartPreparationMode);
598 Restart(NULL,True);
600 #endif
603 static void handleMapRequest(XEvent * ev)
605 WWindow *wwin;
606 WScreen *scr = NULL;
607 Window window = ev->xmaprequest.window;
609 if ((wwin = wWindowFor(window))) {
610 if (wwin->flags.shaded) {
611 wUnshadeWindow(wwin);
613 /* deiconify window */
614 if (wwin->flags.miniaturized) {
615 wDeiconifyWindow(wwin);
616 } else if (wwin->flags.hidden) {
617 WApplication *wapp = wApplicationOf(wwin->main_window);
618 /* go to the last workspace that the user worked on the app */
619 if (wapp) {
620 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
622 wUnhideApplication(wapp, False, False);
624 return;
627 scr = wScreenForRootWindow(ev->xmaprequest.parent);
629 wwin = wManageWindow(scr, window);
632 * This is to let the Dock know that the application it launched
633 * has already been mapped (eg: it has finished launching).
634 * It is not necessary for normally docked apps, but is needed for
635 * apps that were forcedly docked (like with dockit).
637 if (scr->last_dock) {
638 if (wwin && wwin->main_window != None && wwin->main_window != window)
639 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
640 else
641 wDockTrackWindowLaunch(scr->last_dock, window);
644 if (wwin) {
645 wClientSetState(wwin, NormalState, None);
646 if (wwin->flags.maximized) {
647 wMaximizeWindow(wwin, wwin->flags.maximized);
649 if (wwin->flags.shaded) {
650 wwin->flags.shaded = 0;
651 wwin->flags.skip_next_animation = 1;
652 wShadeWindow(wwin);
654 if (wwin->flags.miniaturized) {
655 wwin->flags.miniaturized = 0;
656 wwin->flags.skip_next_animation = 1;
657 wIconifyWindow(wwin);
659 if (wwin->flags.fullscreen) {
660 wwin->flags.fullscreen = 0;
661 wFullscreenWindow(wwin);
663 if (wwin->flags.hidden) {
664 WApplication *wapp = wApplicationOf(wwin->main_window);
666 wwin->flags.hidden = 0;
667 wwin->flags.skip_next_animation = 1;
668 if (wapp) {
669 wHideApplication(wapp);
675 static void handleDestroyNotify(XEvent * event)
677 WWindow *wwin;
678 WApplication *app;
679 Window window = event->xdestroywindow.window;
680 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
681 int widx;
683 wwin = wWindowFor(window);
684 if (wwin) {
685 wUnmanageWindow(wwin, False, True);
688 if (scr != NULL) {
689 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
690 WFakeGroupLeader *fPtr;
692 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
693 if (fPtr->retainCount > 0) {
694 fPtr->retainCount--;
695 if (fPtr->retainCount == 0 && fPtr->leader != None) {
696 XDestroyWindow(dpy, fPtr->leader);
697 fPtr->leader = None;
698 XFlush(dpy);
701 fPtr->origLeader = None;
705 app = wApplicationOf(window);
706 if (app) {
707 if (window == app->main_window) {
708 app->refcount = 0;
709 wwin = app->main_window_desc->screen_ptr->focused_window;
710 while (wwin) {
711 if (wwin->main_window == window) {
712 wwin->main_window = None;
714 wwin = wwin->prev;
717 wApplicationDestroy(app);
721 static void handleExpose(XEvent * event)
723 WObjDescriptor *desc;
724 XEvent ev;
726 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
728 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
729 return;
732 if (desc->handle_expose) {
733 (*desc->handle_expose) (desc, event);
737 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
739 switch (action) {
740 case WA_SELECT_WINDOWS:
741 wUnselectWindows(scr);
742 wSelectWindows(scr, event);
743 break;
744 case WA_OPEN_APPMENU:
745 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
746 /* ugly hack */
747 if (scr->root_menu) {
748 if (scr->root_menu->brother->flags.mapped)
749 event->xbutton.window = scr->root_menu->brother->frame->core->window;
750 else
751 event->xbutton.window = scr->root_menu->frame->core->window;
753 break;
754 case WA_OPEN_WINLISTMENU:
755 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
756 if (scr->switch_menu) {
757 if (scr->switch_menu->brother->flags.mapped)
758 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
759 else
760 event->xbutton.window = scr->switch_menu->frame->core->window;
762 break;
763 default:
764 break;
768 /* bindable */
769 static void handleButtonPress(XEvent * event)
771 WObjDescriptor *desc;
772 WScreen *scr;
774 scr = wScreenForRootWindow(event->xbutton.root);
776 #ifdef BALLOON_TEXT
777 wBalloonHide(scr);
778 #endif
780 if (event->xbutton.window == scr->root_win) {
781 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
782 executeButtonAction(scr, event, wPreferences.mouse_button1);
783 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
784 executeButtonAction(scr, event, wPreferences.mouse_button2);
785 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
786 executeButtonAction(scr, event, wPreferences.mouse_button3);
787 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
788 wWorkspaceRelativeChange(scr, 1);
789 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
790 wWorkspaceRelativeChange(scr, -1);
794 desc = NULL;
795 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
796 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
797 return;
801 if (desc->parent_type == WCLASS_WINDOW) {
802 XSync(dpy, 0);
804 if (event->xbutton.state & ( MOD_MASK | ControlMask )) {
805 XAllowEvents(dpy, AsyncPointer, CurrentTime);
806 } else {
807 /* if (wPreferences.focus_mode == WKF_CLICK) { */
808 if (wPreferences.ignore_focus_click) {
809 XAllowEvents(dpy, AsyncPointer, CurrentTime);
811 XAllowEvents(dpy, ReplayPointer, CurrentTime);
812 /* } */
814 XSync(dpy, 0);
815 } else if (desc->parent_type == WCLASS_APPICON
816 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
817 if (event->xbutton.state & MOD_MASK) {
818 XSync(dpy, 0);
819 XAllowEvents(dpy, AsyncPointer, CurrentTime);
820 XSync(dpy, 0);
824 if (desc->handle_mousedown != NULL) {
825 (*desc->handle_mousedown) (desc, event);
828 /* save double-click information */
829 if (scr->flags.next_click_is_not_double) {
830 scr->flags.next_click_is_not_double = 0;
831 } else {
832 scr->last_click_time = event->xbutton.time;
833 scr->last_click_button = event->xbutton.button;
834 scr->last_click_window = event->xbutton.window;
838 static void handleMapNotify(XEvent * event)
840 WWindow *wwin;
842 wwin = wWindowFor(event->xmap.event);
843 if (wwin && wwin->client_win == event->xmap.event) {
844 if (wwin->flags.miniaturized) {
845 wDeiconifyWindow(wwin);
846 } else {
847 XGrabServer(dpy);
848 wWindowMap(wwin);
849 wClientSetState(wwin, NormalState, None);
850 XUngrabServer(dpy);
855 static void handleUnmapNotify(XEvent * event)
857 WWindow *wwin;
858 XEvent ev;
859 Bool withdraw = False;
861 /* only process windows with StructureNotify selected
862 * (ignore SubstructureNotify) */
863 wwin = wWindowFor(event->xunmap.window);
864 if (!wwin)
865 return;
867 /* whether the event is a Withdrawal request */
868 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
869 withdraw = True;
871 if (wwin->client_win != event->xunmap.event && !withdraw)
872 return;
874 if (!wwin->flags.mapped && !withdraw
875 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
876 && !wwin->flags.miniaturized && !wwin->flags.hidden)
877 return;
879 XGrabServer(dpy);
880 XUnmapWindow(dpy, wwin->frame->core->window);
881 wwin->flags.mapped = 0;
882 XSync(dpy, 0);
883 /* check if the window was destroyed */
884 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
885 DispatchEvent(&ev);
886 } else {
887 Bool reparented = False;
889 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
890 reparented = True;
892 /* withdraw window */
893 wwin->flags.mapped = 0;
894 if (!reparented)
895 wClientSetState(wwin, WithdrawnState, None);
897 /* if the window was reparented, do not reparent it back to the
898 * root window */
899 wUnmanageWindow(wwin, !reparented, False);
901 XUngrabServer(dpy);
904 static void handleConfigureRequest(XEvent * event)
906 WWindow *wwin;
908 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
910 * Configure request for unmapped window
912 wClientConfigure(NULL, &(event->xconfigurerequest));
913 } else {
914 wClientConfigure(wwin, &(event->xconfigurerequest));
918 static void handlePropertyNotify(XEvent * event)
920 WWindow *wwin;
921 WApplication *wapp;
922 Window jr;
923 int ji;
924 unsigned int ju;
926 wwin = wWindowFor(event->xproperty.window);
927 if (wwin) {
928 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
929 return;
931 wClientCheckProperty(wwin, &event->xproperty);
933 wapp = wApplicationOf(event->xproperty.window);
934 if (wapp) {
935 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
939 static void handleClientMessage(XEvent * event)
941 WWindow *wwin;
942 WObjDescriptor *desc;
944 /* handle transition from Normal to Iconic state */
945 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
946 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
948 wwin = wWindowFor(event->xclient.window);
949 if (!wwin)
950 return;
951 if (!wwin->flags.miniaturized)
952 wIconifyWindow(wwin);
953 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
954 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
956 if (!scr)
957 return;
959 if (event->xclient.data.l[1] == 1) { /* starting */
960 wColormapAllowClientInstallation(scr, True);
961 } else { /* stopping */
962 wColormapAllowClientInstallation(scr, False);
964 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
966 char *command;
967 size_t len;
969 len = sizeof(event->xclient.data.b) + 1;
970 command = wmalloc(len);
971 strncpy(command, event->xclient.data.b, sizeof(event->xclient.data.b));
973 if (strncmp(command, "Reconfigure", sizeof("Reconfigure")) == 0) {
974 wwarning(_("Got Reconfigure command"));
975 wDefaultsCheckDomains(NULL);
976 } else {
977 wwarning(_("Got unknown command %s"), command);
980 wfree(command);
982 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
983 WApplication *wapp;
984 int done = 0;
985 wapp = wApplicationOf(event->xclient.window);
986 if (wapp) {
987 switch (event->xclient.data.l[0]) {
988 case WMFHideOtherApplications:
989 wHideOtherApplications(wapp->main_window_desc);
990 done = 1;
991 break;
993 case WMFHideApplication:
994 wHideApplication(wapp);
995 done = 1;
996 break;
999 if (!done) {
1000 wwin = wWindowFor(event->xclient.window);
1001 if (wwin) {
1002 switch (event->xclient.data.l[0]) {
1003 case WMFHideOtherApplications:
1004 wHideOtherApplications(wwin);
1005 break;
1007 case WMFHideApplication:
1008 wHideApplication(wApplicationOf(wwin->main_window));
1009 break;
1013 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
1014 wwin = wWindowFor(event->xclient.window);
1015 if (!wwin)
1016 return;
1017 switch (event->xclient.data.l[0]) {
1018 case GSWindowLevelAttr:
1020 int level = (int)event->xclient.data.l[1];
1022 if (WINDOW_LEVEL(wwin) != level) {
1023 ChangeStackingLevel(wwin->frame->core, level);
1026 break;
1028 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
1029 wwin = wWindowFor(event->xclient.window);
1030 if (!wwin)
1031 return;
1032 switch (event->xclient.data.l[0]) {
1033 case WMTitleBarNormal:
1034 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1035 break;
1036 case WMTitleBarMain:
1037 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1038 break;
1039 case WMTitleBarKey:
1040 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1041 break;
1043 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1044 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1045 if (!scr)
1046 return;
1047 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
1048 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1049 /* do nothing */
1050 #ifdef XDND
1051 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1052 /* do nothing */
1053 #endif /* XDND */
1054 } else {
1056 * Non-standard thing, but needed by OffiX DND.
1057 * For when the icon frame gets a ClientMessage
1058 * that should have gone to the icon_window.
1060 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1061 struct WIcon *icon = NULL;
1063 if (desc->parent_type == WCLASS_MINIWINDOW) {
1064 icon = (WIcon *) desc->parent;
1065 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1066 icon = ((WAppIcon *) desc->parent)->icon;
1068 if (icon && (wwin = icon->owner)) {
1069 if (wwin->client_win != event->xclient.window) {
1070 event->xclient.window = wwin->client_win;
1071 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1078 static void raiseWindow(WScreen * scr)
1080 WWindow *wwin;
1082 scr->autoRaiseTimer = NULL;
1084 wwin = wWindowFor(scr->autoRaiseWindow);
1085 if (!wwin)
1086 return;
1088 if (!wwin->flags.destroyed && wwin->flags.focused) {
1089 wRaiseFrame(wwin->frame->core);
1090 /* this is needed or a race condition will occur */
1091 XSync(dpy, False);
1095 static void handleEnterNotify(XEvent * event)
1097 WWindow *wwin;
1098 WObjDescriptor *desc = NULL;
1099 XEvent ev;
1100 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1102 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1103 /* already left the window... */
1104 saveTimestamp(&ev);
1105 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1106 return;
1110 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1111 if (desc->handle_enternotify)
1112 (*desc->handle_enternotify) (desc, event);
1115 /* enter to window */
1116 wwin = wWindowFor(event->xcrossing.window);
1117 if (!wwin) {
1118 if (wPreferences.colormap_mode == WCM_POINTER) {
1119 wColormapInstallForWindow(scr, NULL);
1121 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1122 WMDeleteTimerHandler(scr->autoRaiseTimer);
1123 scr->autoRaiseTimer = NULL;
1125 } else {
1126 /* set auto raise timer even if in focus-follows-mouse mode
1127 * and the event is for the frame window, even if the window
1128 * has focus already. useful if you move the pointer from a focused
1129 * window to the root window and back pretty fast
1131 * set focus if in focus-follows-mouse mode and the event
1132 * is for the frame window and window doesn't have focus yet */
1133 if (wPreferences.focus_mode == WKF_SLOPPY
1134 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1136 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1137 wSetFocusTo(scr, wwin);
1139 if (scr->autoRaiseTimer)
1140 WMDeleteTimerHandler(scr->autoRaiseTimer);
1141 scr->autoRaiseTimer = NULL;
1143 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1144 scr->autoRaiseWindow = wwin->frame->core->window;
1145 scr->autoRaiseTimer
1146 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1149 /* Install colormap for window, if the colormap installation mode
1150 * is colormap_follows_mouse */
1151 if (wPreferences.colormap_mode == WCM_POINTER) {
1152 if (wwin->client_win == event->xcrossing.window)
1153 wColormapInstallForWindow(scr, wwin);
1154 else
1155 wColormapInstallForWindow(scr, NULL);
1159 if (event->xcrossing.window == event->xcrossing.root
1160 && event->xcrossing.detail == NotifyNormal
1161 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1163 wSetFocusTo(scr, scr->focused_window);
1165 #ifdef BALLOON_TEXT
1166 wBalloonEnteredObject(scr, desc);
1167 #endif
1170 static void handleLeaveNotify(XEvent * event)
1172 WObjDescriptor *desc = NULL;
1174 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1175 if (desc->handle_leavenotify)
1176 (*desc->handle_leavenotify) (desc, event);
1180 #ifdef SHAPE
1181 static void handleShapeNotify(XEvent * event)
1183 XShapeEvent *shev = (XShapeEvent *) event;
1184 WWindow *wwin;
1185 union {
1186 XEvent xevent;
1187 XShapeEvent xshape;
1188 } ev;
1190 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev.xevent)) {
1191 if (ev.xshape.kind == ShapeBounding) {
1192 if (ev.xshape.shaped == shev->shaped) {
1193 *shev = ev.xshape;
1194 } else {
1195 XPutBackEvent(dpy, &ev.xevent);
1196 break;
1201 wwin = wWindowFor(shev->window);
1202 if (!wwin || shev->kind != ShapeBounding)
1203 return;
1205 if (!shev->shaped && wwin->flags.shaped) {
1207 wwin->flags.shaped = 0;
1208 wWindowClearShape(wwin);
1210 } else if (shev->shaped) {
1212 wwin->flags.shaped = 1;
1213 wWindowSetShape(wwin);
1216 #endif /* SHAPE */
1218 #ifdef KEEP_XKB_LOCK_STATUS
1219 /* please help ]d if you know what to do */
1220 static void handleXkbIndicatorStateNotify(XEvent *event)
1222 WWindow *wwin;
1223 WScreen *scr;
1224 XkbStateRec staterec;
1225 int i;
1227 for (i = 0; i < wScreenCount; i++) {
1228 scr = wScreenWithNumber(i);
1229 wwin = scr->focused_window;
1230 if (wwin && wwin->flags.focused) {
1231 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1232 if (wwin->frame->languagemode != staterec.group) {
1233 wwin->frame->last_languagemode = wwin->frame->languagemode;
1234 wwin->frame->languagemode = staterec.group;
1236 #ifdef XKB_BUTTON_HINT
1237 if (wwin->frame->titlebar) {
1238 wFrameWindowPaint(wwin->frame);
1240 #endif
1244 #endif /*KEEP_XKB_LOCK_STATUS */
1246 static void handleColormapNotify(XEvent * event)
1248 WWindow *wwin;
1249 WScreen *scr;
1250 Bool reinstall = False;
1252 wwin = wWindowFor(event->xcolormap.window);
1253 if (!wwin)
1254 return;
1256 scr = wwin->screen_ptr;
1258 do {
1259 if (wwin) {
1260 if (event->xcolormap.new) {
1261 XWindowAttributes attr;
1263 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1265 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1266 scr->current_colormap = attr.colormap;
1268 reinstall = True;
1269 } else if (event->xcolormap.state == ColormapUninstalled &&
1270 scr->current_colormap == event->xcolormap.colormap) {
1272 /* some bastard app (like XV) removed our colormap */
1274 * can't enforce or things like xscreensaver wont work
1275 * reinstall = True;
1277 } else if (event->xcolormap.state == ColormapInstalled &&
1278 scr->current_colormap == event->xcolormap.colormap) {
1280 /* someone has put our colormap back */
1281 reinstall = False;
1284 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1285 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1287 if (reinstall && scr->current_colormap != None) {
1288 if (!scr->flags.colormap_stuff_blocked)
1289 XInstallColormap(dpy, scr->current_colormap);
1293 static void handleFocusIn(XEvent * event)
1295 WWindow *wwin;
1298 * For applications that like stealing the focus.
1300 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1301 saveTimestamp(event);
1302 if (event->xfocus.mode == NotifyUngrab
1303 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1304 return;
1307 wwin = wWindowFor(event->xfocus.window);
1308 if (wwin && !wwin->flags.focused) {
1309 if (wwin->flags.mapped)
1310 wSetFocusTo(wwin->screen_ptr, wwin);
1311 else
1312 wSetFocusTo(wwin->screen_ptr, NULL);
1313 } else if (!wwin) {
1314 WScreen *scr = wScreenForWindow(event->xfocus.window);
1315 if (scr)
1316 wSetFocusTo(scr, NULL);
1320 static WWindow *windowUnderPointer(WScreen * scr)
1322 unsigned int mask;
1323 int foo;
1324 Window bar, win;
1326 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1327 return wWindowFor(win);
1328 return NULL;
1331 static int CheckFullScreenWindowFocused(WScreen * scr)
1333 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1334 return 1;
1335 else
1336 return 0;
1339 static void handleKeyPress(XEvent * event)
1341 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1342 WWindow *wwin = scr->focused_window;
1343 short i, widx;
1344 int modifiers;
1345 int command = -1;
1346 #ifdef KEEP_XKB_LOCK_STATUS
1347 XkbStateRec staterec;
1348 #endif /*KEEP_XKB_LOCK_STATUS */
1350 /* ignore CapsLock */
1351 modifiers = event->xkey.state & ValidModMask;
1353 for (i = 0; i < WKBD_LAST; i++) {
1354 if (wKeyBindings[i].keycode == 0)
1355 continue;
1357 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1358 || */ wKeyBindings[i].modifier ==
1359 modifiers)) {
1360 command = i;
1361 break;
1365 if (command < 0) {
1367 if (!wRootMenuPerformShortcut(event)) {
1368 static int dontLoop = 0;
1370 if (dontLoop > 10) {
1371 wwarning("problem with key event processing code");
1372 return;
1374 dontLoop++;
1375 /* if the focused window is an internal window, try redispatching
1376 * the event to the managed window, as it can be a WINGs window */
1377 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1378 /* client_leader contains the WINGs toplevel */
1379 event->xany.window = wwin->client_leader;
1380 WMHandleEvent(event);
1382 dontLoop--;
1384 return;
1386 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1387 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1389 switch (command) {
1391 case WKBD_ROOTMENU:
1392 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1393 if (!CheckFullScreenWindowFocused(scr)) {
1394 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1395 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1396 True);
1398 break;
1399 case WKBD_WINDOWLIST:
1400 if (!CheckFullScreenWindowFocused(scr)) {
1401 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1402 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1403 True);
1405 break;
1407 case WKBD_WINDOWMENU:
1408 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1409 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1410 break;
1411 case WKBD_MINIMIZEALL:
1412 CloseWindowMenu(scr);
1413 wHideAll(scr);
1414 break;
1415 case WKBD_MINIATURIZE:
1416 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1417 && !WFLAGP(wwin, no_miniaturizable)) {
1418 CloseWindowMenu(scr);
1420 if (wwin->protocols.MINIATURIZE_WINDOW)
1421 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1422 else {
1423 wIconifyWindow(wwin);
1426 break;
1427 case WKBD_HIDE:
1428 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1429 WApplication *wapp = wApplicationOf(wwin->main_window);
1430 CloseWindowMenu(scr);
1432 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1433 wHideApplication(wapp);
1436 break;
1437 case WKBD_HIDE_OTHERS:
1438 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1439 CloseWindowMenu(scr);
1441 wHideOtherApplications(wwin);
1443 break;
1444 case WKBD_MAXIMIZE:
1445 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1446 CloseWindowMenu(scr);
1448 handleMaximize(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
1450 break;
1451 case WKBD_VMAXIMIZE:
1452 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1453 CloseWindowMenu(scr);
1455 handleMaximize(wwin, MAX_VERTICAL | MAX_KEYBOARD);
1457 break;
1458 case WKBD_HMAXIMIZE:
1459 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1460 CloseWindowMenu(scr);
1462 handleMaximize(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
1464 break;
1465 case WKBD_LHMAXIMIZE:
1466 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1467 CloseWindowMenu(scr);
1469 handleMaximize(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
1471 break;
1472 case WKBD_RHMAXIMIZE:
1473 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1474 CloseWindowMenu(scr);
1476 handleMaximize(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
1478 break;
1479 case WKBD_MAXIMUS:
1480 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1481 CloseWindowMenu(scr);
1483 handleMaximize(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
1485 break;
1486 case WKBD_RAISE:
1487 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1488 CloseWindowMenu(scr);
1490 wRaiseFrame(wwin->frame->core);
1492 break;
1493 case WKBD_LOWER:
1494 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1495 CloseWindowMenu(scr);
1497 wLowerFrame(wwin->frame->core);
1499 break;
1500 case WKBD_RAISELOWER:
1501 /* raise or lower the window under the pointer, not the
1502 * focused one
1504 wwin = windowUnderPointer(scr);
1505 if (wwin)
1506 wRaiseLowerFrame(wwin->frame->core);
1507 break;
1508 case WKBD_SHADE:
1509 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1510 if (wwin->flags.shaded)
1511 wUnshadeWindow(wwin);
1512 else
1513 wShadeWindow(wwin);
1515 break;
1516 case WKBD_MOVERESIZE:
1517 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1518 CloseWindowMenu(scr);
1520 wKeyboardMoveResizeWindow(wwin);
1522 break;
1523 case WKBD_CLOSE:
1524 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1525 CloseWindowMenu(scr);
1526 if (wwin->protocols.DELETE_WINDOW)
1527 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1529 break;
1530 case WKBD_SELECT:
1531 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1532 wSelectWindow(wwin, !wwin->flags.selected);
1534 break;
1535 case WKBD_FOCUSNEXT:
1536 StartWindozeCycle(wwin, event, True, False);
1537 break;
1539 case WKBD_FOCUSPREV:
1540 StartWindozeCycle(wwin, event, False, False);
1541 break;
1543 case WKBD_GROUPNEXT:
1544 StartWindozeCycle(wwin, event, True, True);
1545 break;
1547 case WKBD_GROUPPREV:
1548 StartWindozeCycle(wwin, event, False, True);
1549 break;
1551 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
1552 widx = command - WKBD_WORKSPACE1;
1553 i = (scr->current_workspace / 10) * 10 + widx;
1554 if (wPreferences.ws_advance || i < scr->workspace_count)
1555 wWorkspaceChange(scr, i);
1556 break;
1558 case WKBD_NEXTWORKSPACE:
1559 wWorkspaceRelativeChange(scr, 1);
1560 break;
1561 case WKBD_PREVWORKSPACE:
1562 wWorkspaceRelativeChange(scr, -1);
1563 break;
1565 case WKBD_WINDOW1:
1566 case WKBD_WINDOW2:
1567 case WKBD_WINDOW3:
1568 case WKBD_WINDOW4:
1569 case WKBD_WINDOW5:
1570 case WKBD_WINDOW6:
1571 case WKBD_WINDOW7:
1572 case WKBD_WINDOW8:
1573 case WKBD_WINDOW9:
1574 case WKBD_WINDOW10:
1576 widx = command - WKBD_WINDOW1;
1578 if (scr->shortcutWindows[widx]) {
1579 WMArray *list = scr->shortcutWindows[widx];
1580 int cw;
1581 int count = WMGetArrayItemCount(list);
1582 WWindow *twin;
1583 WMArrayIterator iter;
1584 WWindow *wwin;
1586 wUnselectWindows(scr);
1587 cw = scr->current_workspace;
1589 WM_ETARETI_ARRAY(list, wwin, iter) {
1590 if (count > 1)
1591 wWindowChangeWorkspace(wwin, cw);
1593 wMakeWindowVisible(wwin);
1595 if (count > 1)
1596 wSelectWindow(wwin, True);
1599 /* rotate the order of windows, to create a cycling effect */
1600 twin = WMGetFromArray(list, 0);
1601 WMDeleteFromArray(list, 0);
1602 WMAddToArray(list, twin);
1604 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1605 if (scr->shortcutWindows[widx]) {
1606 WMFreeArray(scr->shortcutWindows[widx]);
1607 scr->shortcutWindows[widx] = NULL;
1610 if (wwin->flags.selected && scr->selected_windows) {
1611 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1612 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1613 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1614 } else {
1615 scr->shortcutWindows[widx] = WMCreateArray(4);
1616 WMAddToArray(scr->shortcutWindows[widx], wwin);
1619 wSelectWindow(wwin, !wwin->flags.selected);
1620 XFlush(dpy);
1621 wusleep(3000);
1622 wSelectWindow(wwin, !wwin->flags.selected);
1623 XFlush(dpy);
1625 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1627 if (wwin->flags.selected && scr->selected_windows) {
1628 if (scr->shortcutWindows[widx]) {
1629 WMFreeArray(scr->shortcutWindows[widx]);
1631 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1635 break;
1637 case WKBD_RELAUNCH:
1638 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1639 (void) RelaunchWindow(wwin);
1641 break;
1643 case WKBD_SWITCH_SCREEN:
1644 if (wScreenCount > 1) {
1645 WScreen *scr2;
1646 int i;
1648 /* find index of this screen */
1649 for (i = 0; i < wScreenCount; i++) {
1650 if (wScreenWithNumber(i) == scr)
1651 break;
1653 i++;
1654 if (i >= wScreenCount) {
1655 i = 0;
1657 scr2 = wScreenWithNumber(i);
1659 if (scr2) {
1660 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1661 scr2->scr_width / 2, scr2->scr_height / 2);
1664 break;
1666 case WKBD_NEXTWSLAYER:
1667 case WKBD_PREVWSLAYER:
1669 int row, column;
1671 row = scr->current_workspace / 10;
1672 column = scr->current_workspace % 10;
1674 if (command == WKBD_NEXTWSLAYER) {
1675 if ((row + 1) * 10 < scr->workspace_count)
1676 wWorkspaceChange(scr, column + (row + 1) * 10);
1677 } else {
1678 if (row > 0)
1679 wWorkspaceChange(scr, column + (row - 1) * 10);
1682 break;
1683 case WKBD_CLIPRAISELOWER:
1684 if (!wPreferences.flags.noclip)
1685 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1686 break;
1687 case WKBD_DOCKRAISELOWER:
1688 if (!wPreferences.flags.nodock)
1689 wDockRaiseLower(scr->dock);
1690 break;
1691 #ifdef KEEP_XKB_LOCK_STATUS
1692 case WKBD_TOGGLE:
1693 if (wPreferences.modelock) {
1694 /*toggle */
1695 wwin = scr->focused_window;
1697 if (wwin && wwin->flags.mapped
1698 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1699 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1700 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1702 wwin->frame->languagemode = wwin->frame->last_languagemode;
1703 wwin->frame->last_languagemode = staterec.group;
1704 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1708 break;
1709 #endif /* KEEP_XKB_LOCK_STATUS */
1713 static void handleMotionNotify(XEvent * event)
1715 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1717 if (wPreferences.scrollable_menus) {
1718 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1719 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1721 if (scr->flags.jump_back_pending ||
1722 p.x <= (rect.pos.x + 1) ||
1723 p.x >= (rect.pos.x + rect.size.width - 2) ||
1724 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1725 WMenu *menu;
1727 menu = wMenuUnderPointer(scr);
1728 if (menu != NULL)
1729 wMenuScroll(menu, event);
1734 static void handleVisibilityNotify(XEvent * event)
1736 WWindow *wwin;
1738 wwin = wWindowFor(event->xvisibility.window);
1739 if (!wwin)
1740 return;
1741 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);