XShapeEvent strict aliasing violation
[wmaker-crm.git] / src / event.c
blob46e2ea9a14fcae96a54b3cab200edaf02d2245b6
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 "wconfig.h"
25 #ifdef HAVE_INOTIFY
26 #include <sys/inotify.h>
27 #endif
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #ifdef SHAPE
37 # include <X11/extensions/shape.h>
38 #endif
39 #ifdef XDND
40 #include "xdnd.h"
41 #endif
43 #ifdef KEEP_XKB_LOCK_STATUS
44 #include <X11/XKBlib.h>
45 #endif /* KEEP_XKB_LOCK_STATUS */
47 #include "WindowMaker.h"
48 #include "window.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "application.h"
54 #include "stacking.h"
55 #include "defaults.h"
56 #include "workspace.h"
57 #include "dock.h"
58 #include "framewin.h"
59 #include "properties.h"
60 #include "balloon.h"
61 #include "xinerama.h"
62 #include "wmspec.h"
64 /******** Global Variables **********/
65 extern XContext wWinContext;
66 extern XContext wVEdgeContext;
68 extern Cursor wCursor[WCUR_LAST];
70 extern WShortKey wKeyBindings[WKBD_LAST];
71 extern int wScreenCount;
72 extern Time LastTimestamp;
73 extern Time LastFocusChange;
75 extern WPreferences wPreferences;
77 #define MOD_MASK wPreferences.modifier_mask
79 extern Atom _XA_WM_COLORMAP_NOTIFY;
81 extern Atom _XA_WM_CHANGE_STATE;
82 extern Atom _XA_WM_DELETE_WINDOW;
83 extern Atom _XA_GNUSTEP_WM_ATTR;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
85 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
86 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
87 extern Atom _XA_WINDOWMAKER_COMMAND;
88 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
90 #ifdef SHAPE
91 extern Bool wShapeSupported;
92 extern int wShapeEventBase;
93 #endif
95 #ifdef KEEP_XKB_LOCK_STATUS
96 extern int wXkbEventBase;
97 #endif
99 /* special flags */
100 /*extern char WDelayedActionSet;*/
102 /************ Local stuff ***********/
104 static void saveTimestamp(XEvent *event);
105 static void handleColormapNotify(XEvent *event);
106 static void handleMapNotify(XEvent *event);
107 static void handleUnmapNotify(XEvent *event);
108 static void handleButtonPress(XEvent *event);
109 static void handleExpose(XEvent *event);
110 static void handleDestroyNotify(XEvent *event);
111 static void handleConfigureRequest(XEvent *event);
112 static void handleMapRequest(XEvent *event);
113 static void handlePropertyNotify(XEvent *event);
114 static void handleEnterNotify(XEvent *event);
115 static void handleLeaveNotify(XEvent *event);
116 static void handleExtensions(XEvent *event);
117 static void handleClientMessage(XEvent *event);
118 static void handleKeyPress(XEvent *event);
119 static void handleFocusIn(XEvent *event);
120 static void handleMotionNotify(XEvent *event);
121 static void handleVisibilityNotify(XEvent *event);
123 #ifdef SHAPE
124 static void handleShapeNotify(XEvent *event);
125 #endif
127 /* called from the signal handler */
128 void NotifyDeadProcess(pid_t pid, unsigned char status);
130 /* real dead process handler */
131 static void handleDeadProcess(void *foo);
133 typedef struct DeadProcesses {
134 pid_t pid;
135 unsigned char exit_status;
136 } DeadProcesses;
138 /* stack of dead processes */
139 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
140 static int deadProcessPtr = 0;
142 typedef struct DeathHandler {
143 WDeathHandler *callback;
144 pid_t pid;
145 void *client_data;
146 } DeathHandler;
148 static WMArray *deathHandlers = NULL;
150 WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
152 DeathHandler *handler;
154 handler = malloc(sizeof(DeathHandler));
155 if (!handler)
156 return 0;
158 handler->pid = pid;
159 handler->callback = callback;
160 handler->client_data = cdata;
162 if (!deathHandlers)
163 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
165 WMAddToArray(deathHandlers, handler);
167 return handler;
170 void wDeleteDeathHandler(WMagicNumber id)
172 DeathHandler *handler = (DeathHandler *) id;
174 if (!handler || !deathHandlers)
175 return;
177 /* array destructor will call wfree(handler) */
178 WMRemoveFromArray(deathHandlers, handler);
181 void DispatchEvent(XEvent * event)
183 if (deathHandlers)
184 handleDeadProcess(NULL);
186 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
187 WCHANGE_STATE(WSTATE_EXITING);
188 /* received SIGTERM */
190 * WMHandleEvent() can't be called from anything
191 * executed inside here, or we can get in a infinite
192 * recursive loop.
194 Shutdown(WSExitMode);
196 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
197 WCHANGE_STATE(WSTATE_RESTARTING);
199 Shutdown(WSRestartPreparationMode);
200 /* received SIGHUP */
201 Restart(NULL, True);
202 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
203 WCHANGE_STATE(WSTATE_NORMAL);
204 wDefaultsCheckDomains(NULL);
207 /* for the case that all that is wanted to be dispatched is
208 * the stuff above */
209 if (!event)
210 return;
212 saveTimestamp(event);
213 switch (event->type) {
214 case MapRequest:
215 handleMapRequest(event);
216 break;
218 case KeyPress:
219 handleKeyPress(event);
220 break;
222 case MotionNotify:
223 handleMotionNotify(event);
224 break;
226 case ConfigureRequest:
227 handleConfigureRequest(event);
228 break;
230 case DestroyNotify:
231 handleDestroyNotify(event);
232 break;
234 case MapNotify:
235 handleMapNotify(event);
236 break;
238 case UnmapNotify:
239 handleUnmapNotify(event);
240 break;
242 case ButtonPress:
243 handleButtonPress(event);
244 break;
246 case Expose:
247 handleExpose(event);
248 break;
250 case PropertyNotify:
251 handlePropertyNotify(event);
252 break;
254 case EnterNotify:
255 handleEnterNotify(event);
256 break;
258 case LeaveNotify:
259 handleLeaveNotify(event);
260 break;
262 case ClientMessage:
263 handleClientMessage(event);
264 break;
266 case ColormapNotify:
267 handleColormapNotify(event);
268 break;
270 case MappingNotify:
271 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
272 XRefreshKeyboardMapping(&event->xmapping);
273 break;
275 case FocusIn:
276 handleFocusIn(event);
277 break;
279 case VisibilityNotify:
280 handleVisibilityNotify(event);
281 break;
282 default:
283 handleExtensions(event);
284 break;
288 #ifdef HAVE_INOTIFY
290 *----------------------------------------------------------------------
291 * inotifyHandleEvents-
292 * Check for inotify events
294 * Returns:
295 * After reading events for the given file descriptor (fd) and
296 * watch descriptor (wd)
298 * Side effects:
299 * Calls wDefaultsCheckDomains if config database is updated
300 *----------------------------------------------------------------------
302 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
303 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
304 void inotifyHandleEvents(int fd, int wd)
306 extern void wDefaultsCheckDomains(void *);
307 ssize_t eventQLength, i = 0;
308 char buff[BUFF_SIZE] = { 0 };
309 /* Check config only once per read of the event queue */
310 int oneShotFlag = 0;
313 * Read off the queued events
314 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
315 * not occur; the block is on Xevents, but a config file change will normally
316 * occur as a result of an Xevent - so the event queue should never have more than
317 * a few entries before a read().
319 eventQLength = read(fd, buff, BUFF_SIZE);
321 /* check what events occured */
322 /* Should really check wd here too, but for now we only have one watch! */
323 while (i < eventQLength) {
324 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
327 * see inotify.h for event types.
329 if (pevent->mask & IN_DELETE_SELF) {
330 wwarning(_("the defaults database has been deleted!"
331 " Restart Window Maker to create the database" " with the default settings"));
332 close(fd);
334 if (pevent->mask & IN_UNMOUNT) {
335 wwarning(_("the unit containing the defaults database has"
336 " been unmounted. Setting --static mode." " Any changes will not be saved."));
337 close(fd);
338 wPreferences.flags.noupdates = 1;
340 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
341 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
342 wDefaultsCheckDomains(NULL);
345 /* move to next event in the buffer */
346 i += sizeof(struct inotify_event) + pevent->len;
349 #endif /* HAVE_INOTIFY */
352 *----------------------------------------------------------------------
353 * EventLoop-
354 * Processes X and internal events indefinitely.
356 * Returns:
357 * Never returns
359 * Side effects:
360 * The LastTimestamp global variable is updated.
361 * Calls inotifyGetEvents if defaults database changes.
362 *----------------------------------------------------------------------
364 void EventLoop(void)
366 XEvent event;
367 #ifdef HAVE_INOTIFY
368 extern int inotifyFD;
369 extern int inotifyWD;
370 struct timeval time;
371 fd_set rfds;
372 int retVal = 0;
374 if (inotifyFD < 0 || inotifyWD < 0)
375 retVal = -1;
376 #endif
378 for (;;) {
380 WMNextEvent(dpy, &event); /* Blocks here */
381 WMHandleEvent(&event);
382 #ifdef HAVE_INOTIFY
383 if (retVal != -1) {
384 time.tv_sec = 0;
385 time.tv_usec = 0;
386 FD_ZERO(&rfds);
387 FD_SET(inotifyFD, &rfds);
389 /* check for available read data from inotify - don't block! */
390 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
392 if (retVal < 0) { /* an error has occured */
393 wwarning(_("select failed. The inotify instance will be closed."
394 " Changes to the defaults database will require"
395 " a restart to take effect."));
396 close(inotifyFD);
397 continue;
399 if (FD_ISSET(inotifyFD, &rfds))
400 inotifyHandleEvents(inotifyFD, inotifyWD);
402 #endif
407 *----------------------------------------------------------------------
408 * ProcessPendingEvents --
409 * Processes the events that are currently pending (at the time
410 * this function is called) in the display's queue.
412 * Returns:
413 * After the pending events that were present at the function call
414 * are processed.
416 * Side effects:
417 * Many -- whatever handling events may involve.
419 *----------------------------------------------------------------------
421 void ProcessPendingEvents(void)
423 XEvent event;
424 int count;
426 XSync(dpy, False);
428 /* Take a snapshot of the event count in the queue */
429 count = XPending(dpy);
431 while (count > 0 && XPending(dpy)) {
432 WMNextEvent(dpy, &event);
433 WMHandleEvent(&event);
434 count--;
438 Bool IsDoubleClick(WScreen * scr, XEvent * event)
440 if ((scr->last_click_time > 0) &&
441 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
442 && (event->xbutton.button == scr->last_click_button)
443 && (event->xbutton.window == scr->last_click_window)) {
445 scr->flags.next_click_is_not_double = 1;
446 scr->last_click_time = 0;
447 scr->last_click_window = event->xbutton.window;
449 return True;
451 return False;
454 void NotifyDeadProcess(pid_t pid, unsigned char status)
456 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
457 wwarning("stack overflow: too many dead processes");
458 return;
460 /* stack the process to be handled later,
461 * as this is called from the signal handler */
462 deadProcesses[deadProcessPtr].pid = pid;
463 deadProcesses[deadProcessPtr].exit_status = status;
464 deadProcessPtr++;
467 static void handleDeadProcess(void *foo)
469 DeathHandler *tmp;
470 int i;
472 for (i = 0; i < deadProcessPtr; i++) {
473 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
476 if (!deathHandlers) {
477 deadProcessPtr = 0;
478 return;
481 /* get the pids on the queue and call handlers */
482 while (deadProcessPtr > 0) {
483 deadProcessPtr--;
485 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
486 tmp = WMGetFromArray(deathHandlers, i);
487 if (!tmp)
488 continue;
490 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
491 (*tmp->callback) (tmp->pid,
492 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
493 wDeleteDeathHandler(tmp);
499 static void saveTimestamp(XEvent * event)
502 * Never save CurrentTime as LastTimestamp because CurrentTime
503 * it's not a real timestamp (it's the 0L constant)
506 switch (event->type) {
507 case ButtonRelease:
508 case ButtonPress:
509 LastTimestamp = event->xbutton.time;
510 break;
511 case KeyPress:
512 case KeyRelease:
513 LastTimestamp = event->xkey.time;
514 break;
515 case MotionNotify:
516 LastTimestamp = event->xmotion.time;
517 break;
518 case PropertyNotify:
519 LastTimestamp = event->xproperty.time;
520 break;
521 case EnterNotify:
522 case LeaveNotify:
523 LastTimestamp = event->xcrossing.time;
524 break;
525 case SelectionClear:
526 LastTimestamp = event->xselectionclear.time;
527 break;
528 case SelectionRequest:
529 LastTimestamp = event->xselectionrequest.time;
530 break;
531 case SelectionNotify:
532 LastTimestamp = event->xselection.time;
533 #ifdef XDND
534 wXDNDProcessSelection(event);
535 #endif
536 break;
540 static int matchWindow(const void *item, const void *cdata)
542 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
545 static void handleExtensions(XEvent * event)
547 #ifdef KEEP_XKB_LOCK_STATUS
548 XkbEvent *xkbevent;
549 xkbevent = (XkbEvent *) event;
550 #endif /*KEEP_XKB_LOCK_STATUS */
551 #ifdef SHAPE
552 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
553 handleShapeNotify(event);
555 #endif
556 #ifdef KEEP_XKB_LOCK_STATUS
557 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
558 handleXkbIndicatorStateNotify(event);
560 #endif /*KEEP_XKB_LOCK_STATUS */
563 static void handleMapRequest(XEvent * ev)
565 WWindow *wwin;
566 WScreen *scr = NULL;
567 Window window = ev->xmaprequest.window;
569 if ((wwin = wWindowFor(window))) {
570 if (wwin->flags.shaded) {
571 wUnshadeWindow(wwin);
573 /* deiconify window */
574 if (wwin->flags.miniaturized) {
575 wDeiconifyWindow(wwin);
576 } else if (wwin->flags.hidden) {
577 WApplication *wapp = wApplicationOf(wwin->main_window);
578 /* go to the last workspace that the user worked on the app */
579 if (wapp) {
580 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
582 wUnhideApplication(wapp, False, False);
584 return;
587 scr = wScreenForRootWindow(ev->xmaprequest.parent);
589 wwin = wManageWindow(scr, window);
592 * This is to let the Dock know that the application it launched
593 * has already been mapped (eg: it has finished launching).
594 * It is not necessary for normally docked apps, but is needed for
595 * apps that were forcedly docked (like with dockit).
597 if (scr->last_dock) {
598 if (wwin && wwin->main_window != None && wwin->main_window != window)
599 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
600 else
601 wDockTrackWindowLaunch(scr->last_dock, window);
604 if (wwin) {
605 wClientSetState(wwin, NormalState, None);
606 if (wwin->flags.maximized) {
607 wMaximizeWindow(wwin, wwin->flags.maximized);
609 if (wwin->flags.shaded) {
610 wwin->flags.shaded = 0;
611 wwin->flags.skip_next_animation = 1;
612 wShadeWindow(wwin);
614 if (wwin->flags.miniaturized) {
615 wwin->flags.miniaturized = 0;
616 wwin->flags.skip_next_animation = 1;
617 wIconifyWindow(wwin);
619 if (wwin->flags.fullscreen) {
620 wwin->flags.fullscreen = 0;
621 wFullscreenWindow(wwin);
623 if (wwin->flags.hidden) {
624 WApplication *wapp = wApplicationOf(wwin->main_window);
626 wwin->flags.hidden = 0;
627 wwin->flags.skip_next_animation = 1;
628 if (wapp) {
629 wHideApplication(wapp);
635 static void handleDestroyNotify(XEvent * event)
637 WWindow *wwin;
638 WApplication *app;
639 Window window = event->xdestroywindow.window;
640 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
641 int widx;
643 wwin = wWindowFor(window);
644 if (wwin) {
645 wUnmanageWindow(wwin, False, True);
648 if (scr != NULL) {
649 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
650 WFakeGroupLeader *fPtr;
652 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
653 if (fPtr->retainCount > 0) {
654 fPtr->retainCount--;
655 if (fPtr->retainCount == 0 && fPtr->leader != None) {
656 XDestroyWindow(dpy, fPtr->leader);
657 fPtr->leader = None;
658 XFlush(dpy);
661 fPtr->origLeader = None;
665 app = wApplicationOf(window);
666 if (app) {
667 if (window == app->main_window) {
668 app->refcount = 0;
669 wwin = app->main_window_desc->screen_ptr->focused_window;
670 while (wwin) {
671 if (wwin->main_window == window) {
672 wwin->main_window = None;
674 wwin = wwin->prev;
677 wApplicationDestroy(app);
681 static void handleExpose(XEvent * event)
683 WObjDescriptor *desc;
684 XEvent ev;
686 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
688 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
689 return;
692 if (desc->handle_expose) {
693 (*desc->handle_expose) (desc, event);
697 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
699 switch (action) {
700 case WA_SELECT_WINDOWS:
701 wUnselectWindows(scr);
702 wSelectWindows(scr, event);
703 break;
704 case WA_OPEN_APPMENU:
705 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
706 /* ugly hack */
707 if (scr->root_menu) {
708 if (scr->root_menu->brother->flags.mapped)
709 event->xbutton.window = scr->root_menu->brother->frame->core->window;
710 else
711 event->xbutton.window = scr->root_menu->frame->core->window;
713 break;
714 case WA_OPEN_WINLISTMENU:
715 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
716 if (scr->switch_menu) {
717 if (scr->switch_menu->brother->flags.mapped)
718 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
719 else
720 event->xbutton.window = scr->switch_menu->frame->core->window;
722 break;
723 default:
724 break;
728 /* bindable */
729 static void handleButtonPress(XEvent * event)
731 WObjDescriptor *desc;
732 WScreen *scr;
734 scr = wScreenForRootWindow(event->xbutton.root);
736 #ifdef BALLOON_TEXT
737 wBalloonHide(scr);
738 #endif
740 if (event->xbutton.window == scr->root_win) {
741 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
742 executeButtonAction(scr, event, wPreferences.mouse_button1);
743 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
744 executeButtonAction(scr, event, wPreferences.mouse_button2);
745 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
746 executeButtonAction(scr, event, wPreferences.mouse_button3);
747 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
748 wWorkspaceRelativeChange(scr, 1);
749 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
750 wWorkspaceRelativeChange(scr, -1);
754 desc = NULL;
755 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
756 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
757 return;
761 if (desc->parent_type == WCLASS_WINDOW) {
762 XSync(dpy, 0);
764 if (event->xbutton.state & ( MOD_MASK | ControlMask )) {
765 XAllowEvents(dpy, AsyncPointer, CurrentTime);
768 /* if (wPreferences.focus_mode == WKF_CLICK) { */
769 if (wPreferences.ignore_focus_click) {
770 XAllowEvents(dpy, AsyncPointer, CurrentTime);
772 XAllowEvents(dpy, ReplayPointer, CurrentTime);
773 /* } */
774 XSync(dpy, 0);
775 } else if (desc->parent_type == WCLASS_APPICON
776 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
777 if (event->xbutton.state & MOD_MASK) {
778 XSync(dpy, 0);
779 XAllowEvents(dpy, AsyncPointer, CurrentTime);
780 XSync(dpy, 0);
784 if (desc->handle_mousedown != NULL) {
785 (*desc->handle_mousedown) (desc, event);
788 /* save double-click information */
789 if (scr->flags.next_click_is_not_double) {
790 scr->flags.next_click_is_not_double = 0;
791 } else {
792 scr->last_click_time = event->xbutton.time;
793 scr->last_click_button = event->xbutton.button;
794 scr->last_click_window = event->xbutton.window;
798 static void handleMapNotify(XEvent * event)
800 WWindow *wwin;
802 wwin = wWindowFor(event->xmap.event);
803 if (wwin && wwin->client_win == event->xmap.event) {
804 if (wwin->flags.miniaturized) {
805 wDeiconifyWindow(wwin);
806 } else {
807 XGrabServer(dpy);
808 wWindowMap(wwin);
809 wClientSetState(wwin, NormalState, None);
810 XUngrabServer(dpy);
815 static void handleUnmapNotify(XEvent * event)
817 WWindow *wwin;
818 XEvent ev;
819 Bool withdraw = False;
821 /* only process windows with StructureNotify selected
822 * (ignore SubstructureNotify) */
823 wwin = wWindowFor(event->xunmap.window);
824 if (!wwin)
825 return;
827 /* whether the event is a Withdrawal request */
828 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
829 withdraw = True;
831 if (wwin->client_win != event->xunmap.event && !withdraw)
832 return;
834 if (!wwin->flags.mapped && !withdraw
835 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
836 && !wwin->flags.miniaturized && !wwin->flags.hidden)
837 return;
839 XGrabServer(dpy);
840 XUnmapWindow(dpy, wwin->frame->core->window);
841 wwin->flags.mapped = 0;
842 XSync(dpy, 0);
843 /* check if the window was destroyed */
844 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
845 DispatchEvent(&ev);
846 } else {
847 Bool reparented = False;
849 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
850 reparented = True;
852 /* withdraw window */
853 wwin->flags.mapped = 0;
854 if (!reparented)
855 wClientSetState(wwin, WithdrawnState, None);
857 /* if the window was reparented, do not reparent it back to the
858 * root window */
859 wUnmanageWindow(wwin, !reparented, False);
861 XUngrabServer(dpy);
864 static void handleConfigureRequest(XEvent * event)
866 WWindow *wwin;
868 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
870 * Configure request for unmapped window
872 wClientConfigure(NULL, &(event->xconfigurerequest));
873 } else {
874 wClientConfigure(wwin, &(event->xconfigurerequest));
878 static void handlePropertyNotify(XEvent * event)
880 WWindow *wwin;
881 WApplication *wapp;
882 Window jr;
883 int ji;
884 unsigned int ju;
885 WScreen *scr;
887 wwin = wWindowFor(event->xproperty.window);
888 if (wwin) {
889 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
890 return;
892 wClientCheckProperty(wwin, &event->xproperty);
894 wapp = wApplicationOf(event->xproperty.window);
895 if (wapp) {
896 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
899 scr = wScreenForWindow(event->xproperty.window);
902 static void handleClientMessage(XEvent * event)
904 WWindow *wwin;
905 WObjDescriptor *desc;
907 /* handle transition from Normal to Iconic state */
908 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
909 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
911 wwin = wWindowFor(event->xclient.window);
912 if (!wwin)
913 return;
914 if (!wwin->flags.miniaturized)
915 wIconifyWindow(wwin);
916 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
917 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
919 if (!scr)
920 return;
922 if (event->xclient.data.l[1] == 1) { /* starting */
923 wColormapAllowClientInstallation(scr, True);
924 } else { /* stopping */
925 wColormapAllowClientInstallation(scr, False);
927 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
929 char *command;
930 size_t len;
932 len = sizeof(event->xclient.data.b) + 1;
933 command = wmalloc(len);
934 memset(command, 0, len);
935 strncpy(command, event->xclient.data.b, sizeof(event->xclient.data.b));
937 if (strncmp(command, "Reconfigure", sizeof("Reconfigure")) == 0) {
938 wwarning(_("Got Reconfigure command"));
939 wDefaultsCheckDomains(NULL);
940 } else {
941 wwarning(_("Got unknown command %s"), command);
944 wfree(command);
946 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
947 WApplication *wapp;
948 int done = 0;
949 wapp = wApplicationOf(event->xclient.window);
950 if (wapp) {
951 switch (event->xclient.data.l[0]) {
952 case WMFHideOtherApplications:
953 wHideOtherApplications(wapp->main_window_desc);
954 done = 1;
955 break;
957 case WMFHideApplication:
958 wHideApplication(wapp);
959 done = 1;
960 break;
963 if (!done) {
964 wwin = wWindowFor(event->xclient.window);
965 if (wwin) {
966 switch (event->xclient.data.l[0]) {
967 case WMFHideOtherApplications:
968 wHideOtherApplications(wwin);
969 break;
971 case WMFHideApplication:
972 wHideApplication(wApplicationOf(wwin->main_window));
973 break;
977 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
978 wwin = wWindowFor(event->xclient.window);
979 if (!wwin)
980 return;
981 switch (event->xclient.data.l[0]) {
982 case GSWindowLevelAttr:
984 int level = (int)event->xclient.data.l[1];
986 if (WINDOW_LEVEL(wwin) != level) {
987 ChangeStackingLevel(wwin->frame->core, level);
990 break;
992 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
993 wwin = wWindowFor(event->xclient.window);
994 if (!wwin)
995 return;
996 switch (event->xclient.data.l[0]) {
997 case WMTitleBarNormal:
998 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
999 break;
1000 case WMTitleBarMain:
1001 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1002 break;
1003 case WMTitleBarKey:
1004 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1005 break;
1007 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1008 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1009 if (!scr)
1010 return;
1011 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
1012 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1013 /* do nothing */
1014 #ifdef XDND
1015 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1016 /* do nothing */
1017 #endif /* XDND */
1018 } else {
1020 * Non-standard thing, but needed by OffiX DND.
1021 * For when the icon frame gets a ClientMessage
1022 * that should have gone to the icon_window.
1024 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1025 struct WIcon *icon = NULL;
1027 if (desc->parent_type == WCLASS_MINIWINDOW) {
1028 icon = (WIcon *) desc->parent;
1029 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1030 icon = ((WAppIcon *) desc->parent)->icon;
1032 if (icon && (wwin = icon->owner)) {
1033 if (wwin->client_win != event->xclient.window) {
1034 event->xclient.window = wwin->client_win;
1035 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1042 static void raiseWindow(WScreen * scr)
1044 WWindow *wwin;
1046 scr->autoRaiseTimer = NULL;
1048 wwin = wWindowFor(scr->autoRaiseWindow);
1049 if (!wwin)
1050 return;
1052 if (!wwin->flags.destroyed && wwin->flags.focused) {
1053 wRaiseFrame(wwin->frame->core);
1054 /* this is needed or a race condition will occur */
1055 XSync(dpy, False);
1059 static void handleEnterNotify(XEvent * event)
1061 WWindow *wwin;
1062 WObjDescriptor *desc = NULL;
1063 XEvent ev;
1064 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1066 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1067 /* already left the window... */
1068 saveTimestamp(&ev);
1069 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1070 return;
1074 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1075 if (desc->handle_enternotify)
1076 (*desc->handle_enternotify) (desc, event);
1079 /* enter to window */
1080 wwin = wWindowFor(event->xcrossing.window);
1081 if (!wwin) {
1082 if (wPreferences.colormap_mode == WCM_POINTER) {
1083 wColormapInstallForWindow(scr, NULL);
1085 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1086 WMDeleteTimerHandler(scr->autoRaiseTimer);
1087 scr->autoRaiseTimer = NULL;
1089 } else {
1090 /* set auto raise timer even if in focus-follows-mouse mode
1091 * and the event is for the frame window, even if the window
1092 * has focus already. useful if you move the pointer from a focused
1093 * window to the root window and back pretty fast
1095 * set focus if in focus-follows-mouse mode and the event
1096 * is for the frame window and window doesn't have focus yet */
1097 if (wPreferences.focus_mode == WKF_SLOPPY
1098 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1100 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1101 wSetFocusTo(scr, wwin);
1103 if (scr->autoRaiseTimer)
1104 WMDeleteTimerHandler(scr->autoRaiseTimer);
1105 scr->autoRaiseTimer = NULL;
1107 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1108 scr->autoRaiseWindow = wwin->frame->core->window;
1109 scr->autoRaiseTimer
1110 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1113 /* Install colormap for window, if the colormap installation mode
1114 * is colormap_follows_mouse */
1115 if (wPreferences.colormap_mode == WCM_POINTER) {
1116 if (wwin->client_win == event->xcrossing.window)
1117 wColormapInstallForWindow(scr, wwin);
1118 else
1119 wColormapInstallForWindow(scr, NULL);
1123 /* a little kluge to hide the clip balloon */
1124 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1125 if (!desc) {
1126 XUnmapWindow(dpy, scr->clip_balloon);
1127 scr->flags.clip_balloon_mapped = 0;
1128 } else {
1129 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1130 XUnmapWindow(dpy, scr->clip_balloon);
1131 scr->flags.clip_balloon_mapped = 0;
1136 if (event->xcrossing.window == event->xcrossing.root
1137 && event->xcrossing.detail == NotifyNormal
1138 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1140 wSetFocusTo(scr, scr->focused_window);
1142 #ifdef BALLOON_TEXT
1143 wBalloonEnteredObject(scr, desc);
1144 #endif
1147 static void handleLeaveNotify(XEvent * event)
1149 WObjDescriptor *desc = NULL;
1151 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1152 if (desc->handle_leavenotify)
1153 (*desc->handle_leavenotify) (desc, event);
1157 #ifdef SHAPE
1158 static void handleShapeNotify(XEvent * event)
1160 XShapeEvent *shev = (XShapeEvent *) event;
1161 WWindow *wwin;
1162 union {
1163 XEvent xevent;
1164 XShapeEvent xshape;
1165 } ev;
1167 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev.xevent)) {
1168 if (ev.xshape.kind == ShapeBounding) {
1169 if (ev.xshape.shaped == shev->shaped) {
1170 *shev = ev.xshape;
1171 } else {
1172 XPutBackEvent(dpy, &ev.xevent);
1173 break;
1178 wwin = wWindowFor(shev->window);
1179 if (!wwin || shev->kind != ShapeBounding)
1180 return;
1182 if (!shev->shaped && wwin->flags.shaped) {
1184 wwin->flags.shaped = 0;
1185 wWindowClearShape(wwin);
1187 } else if (shev->shaped) {
1189 wwin->flags.shaped = 1;
1190 wWindowSetShape(wwin);
1193 #endif /* SHAPE */
1195 #ifdef KEEP_XKB_LOCK_STATUS
1196 /* please help ]d if you know what to do */
1197 handleXkbIndicatorStateNotify(XEvent * event)
1199 WWindow *wwin;
1200 WScreen *scr;
1201 XkbStateRec staterec;
1202 int i;
1204 for (i = 0; i < wScreenCount; i++) {
1205 scr = wScreenWithNumber(i);
1206 wwin = scr->focused_window;
1207 if (wwin && wwin->flags.focused) {
1208 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1209 if (wwin->frame->languagemode != staterec.group) {
1210 wwin->frame->last_languagemode = wwin->frame->languagemode;
1211 wwin->frame->languagemode = staterec.group;
1213 #ifdef XKB_BUTTON_HINT
1214 if (wwin->frame->titlebar) {
1215 wFrameWindowPaint(wwin->frame);
1217 #endif
1221 #endif /*KEEP_XKB_LOCK_STATUS */
1223 static void handleColormapNotify(XEvent * event)
1225 WWindow *wwin;
1226 WScreen *scr;
1227 Bool reinstall = False;
1229 wwin = wWindowFor(event->xcolormap.window);
1230 if (!wwin)
1231 return;
1233 scr = wwin->screen_ptr;
1235 do {
1236 if (wwin) {
1237 if (event->xcolormap.new) {
1238 XWindowAttributes attr;
1240 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1242 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1243 scr->current_colormap = attr.colormap;
1245 reinstall = True;
1246 } else if (event->xcolormap.state == ColormapUninstalled &&
1247 scr->current_colormap == event->xcolormap.colormap) {
1249 /* some bastard app (like XV) removed our colormap */
1251 * can't enforce or things like xscreensaver wont work
1252 * reinstall = True;
1254 } else if (event->xcolormap.state == ColormapInstalled &&
1255 scr->current_colormap == event->xcolormap.colormap) {
1257 /* someone has put our colormap back */
1258 reinstall = False;
1261 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1262 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1264 if (reinstall && scr->current_colormap != None) {
1265 if (!scr->flags.colormap_stuff_blocked)
1266 XInstallColormap(dpy, scr->current_colormap);
1270 static void handleFocusIn(XEvent * event)
1272 WWindow *wwin;
1275 * For applications that like stealing the focus.
1277 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1278 saveTimestamp(event);
1279 if (event->xfocus.mode == NotifyUngrab
1280 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1281 return;
1284 wwin = wWindowFor(event->xfocus.window);
1285 if (wwin && !wwin->flags.focused) {
1286 if (wwin->flags.mapped)
1287 wSetFocusTo(wwin->screen_ptr, wwin);
1288 else
1289 wSetFocusTo(wwin->screen_ptr, NULL);
1290 } else if (!wwin) {
1291 WScreen *scr = wScreenForWindow(event->xfocus.window);
1292 if (scr)
1293 wSetFocusTo(scr, NULL);
1297 static WWindow *windowUnderPointer(WScreen * scr)
1299 unsigned int mask;
1300 int foo;
1301 Window bar, win;
1303 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1304 return wWindowFor(win);
1305 return NULL;
1308 static int CheckFullScreenWindowFocused(WScreen * scr)
1310 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1311 return 1;
1312 else
1313 return 0;
1316 static void handleKeyPress(XEvent * event)
1318 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1319 WWindow *wwin = scr->focused_window;
1320 short i, widx;
1321 int modifiers;
1322 int command = -1;
1323 #ifdef KEEP_XKB_LOCK_STATUS
1324 XkbStateRec staterec;
1325 #endif /*KEEP_XKB_LOCK_STATUS */
1327 /* ignore CapsLock */
1328 modifiers = event->xkey.state & ValidModMask;
1330 for (i = 0; i < WKBD_LAST; i++) {
1331 if (wKeyBindings[i].keycode == 0)
1332 continue;
1334 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1335 || */ wKeyBindings[i].modifier ==
1336 modifiers)) {
1337 command = i;
1338 break;
1342 if (command < 0) {
1344 if (!wRootMenuPerformShortcut(event)) {
1345 static int dontLoop = 0;
1347 if (dontLoop > 10) {
1348 wwarning("problem with key event processing code");
1349 return;
1351 dontLoop++;
1352 /* if the focused window is an internal window, try redispatching
1353 * the event to the managed window, as it can be a WINGs window */
1354 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1355 /* client_leader contains the WINGs toplevel */
1356 event->xany.window = wwin->client_leader;
1357 WMHandleEvent(event);
1359 dontLoop--;
1361 return;
1363 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1364 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1366 switch (command) {
1368 case WKBD_ROOTMENU:
1369 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1370 if (!CheckFullScreenWindowFocused(scr)) {
1371 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1372 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1373 True);
1375 break;
1376 case WKBD_WINDOWLIST:
1377 if (!CheckFullScreenWindowFocused(scr)) {
1378 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1379 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1380 True);
1382 break;
1384 case WKBD_WINDOWMENU:
1385 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1386 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1387 break;
1388 case WKBD_MINIATURIZE:
1389 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1390 && !WFLAGP(wwin, no_miniaturizable)) {
1391 CloseWindowMenu(scr);
1393 if (wwin->protocols.MINIATURIZE_WINDOW)
1394 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1395 else {
1396 wIconifyWindow(wwin);
1399 break;
1400 case WKBD_HIDE:
1401 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1402 WApplication *wapp = wApplicationOf(wwin->main_window);
1403 CloseWindowMenu(scr);
1405 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1406 wHideApplication(wapp);
1409 break;
1410 case WKBD_HIDE_OTHERS:
1411 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1412 CloseWindowMenu(scr);
1414 wHideOtherApplications(wwin);
1416 break;
1417 case WKBD_MAXIMIZE:
1418 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1419 CloseWindowMenu(scr);
1421 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_HORIZONTAL))
1422 wUnmaximizeWindow(wwin);
1423 else
1424 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
1426 break;
1427 case WKBD_VMAXIMIZE:
1428 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1429 CloseWindowMenu(scr);
1431 if (wwin->flags.maximized == MAX_VERTICAL)
1432 wUnmaximizeWindow(wwin);
1433 else
1434 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_KEYBOARD);
1436 break;
1437 case WKBD_HMAXIMIZE:
1438 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1439 CloseWindowMenu(scr);
1441 if (wwin->flags.maximized == MAX_HORIZONTAL)
1442 wUnmaximizeWindow(wwin);
1443 else
1444 wMaximizeWindow(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
1446 break;
1447 case WKBD_LHMAXIMIZE:
1448 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1449 CloseWindowMenu(scr);
1451 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_LEFTHALF))
1452 wUnmaximizeWindow(wwin);
1453 else
1454 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
1456 break;
1457 case WKBD_RHMAXIMIZE:
1458 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1459 CloseWindowMenu(scr);
1461 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_RIGHTHALF))
1462 wUnmaximizeWindow(wwin);
1463 else
1464 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
1466 break;
1467 case WKBD_MAXIMUS:
1468 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1469 CloseWindowMenu(scr);
1471 if (wwin->flags.maximized == MAX_MAXIMUS)
1472 wUnmaximizeWindow(wwin);
1473 else
1474 wMaximizeWindow(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
1476 break;
1477 case WKBD_RAISE:
1478 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1479 CloseWindowMenu(scr);
1481 wRaiseFrame(wwin->frame->core);
1483 break;
1484 case WKBD_LOWER:
1485 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1486 CloseWindowMenu(scr);
1488 wLowerFrame(wwin->frame->core);
1490 break;
1491 case WKBD_RAISELOWER:
1492 /* raise or lower the window under the pointer, not the
1493 * focused one
1495 wwin = windowUnderPointer(scr);
1496 if (wwin)
1497 wRaiseLowerFrame(wwin->frame->core);
1498 break;
1499 case WKBD_SHADE:
1500 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1501 if (wwin->flags.shaded)
1502 wUnshadeWindow(wwin);
1503 else
1504 wShadeWindow(wwin);
1506 break;
1507 case WKBD_MOVERESIZE:
1508 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1509 CloseWindowMenu(scr);
1511 wKeyboardMoveResizeWindow(wwin);
1513 break;
1514 case WKBD_CLOSE:
1515 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1516 CloseWindowMenu(scr);
1517 if (wwin->protocols.DELETE_WINDOW)
1518 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1520 break;
1521 case WKBD_SELECT:
1522 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1523 wSelectWindow(wwin, !wwin->flags.selected);
1525 break;
1526 case WKBD_FOCUSNEXT:
1527 StartWindozeCycle(wwin, event, True, False);
1528 break;
1530 case WKBD_FOCUSPREV:
1531 StartWindozeCycle(wwin, event, False, False);
1532 break;
1534 case WKBD_GROUPNEXT:
1535 StartWindozeCycle(wwin, event, True, True);
1536 break;
1538 case WKBD_GROUPPREV:
1539 StartWindozeCycle(wwin, event, False, True);
1540 break;
1542 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
1543 widx = command - WKBD_WORKSPACE1;
1544 i = (scr->current_workspace / 10) * 10 + widx;
1545 if (wPreferences.ws_advance || i < scr->workspace_count)
1546 wWorkspaceChange(scr, i);
1547 break;
1549 case WKBD_NEXTWORKSPACE:
1550 wWorkspaceRelativeChange(scr, 1);
1551 break;
1552 case WKBD_PREVWORKSPACE:
1553 wWorkspaceRelativeChange(scr, -1);
1554 break;
1556 case WKBD_WINDOW1:
1557 case WKBD_WINDOW2:
1558 case WKBD_WINDOW3:
1559 case WKBD_WINDOW4:
1560 case WKBD_WINDOW5:
1561 case WKBD_WINDOW6:
1562 case WKBD_WINDOW7:
1563 case WKBD_WINDOW8:
1564 case WKBD_WINDOW9:
1565 case WKBD_WINDOW10:
1567 widx = command - WKBD_WINDOW1;
1569 if (scr->shortcutWindows[widx]) {
1570 WMArray *list = scr->shortcutWindows[widx];
1571 int cw;
1572 int count = WMGetArrayItemCount(list);
1573 WWindow *twin;
1574 WMArrayIterator iter;
1575 WWindow *wwin;
1577 wUnselectWindows(scr);
1578 cw = scr->current_workspace;
1580 WM_ETARETI_ARRAY(list, wwin, iter) {
1581 if (count > 1)
1582 wWindowChangeWorkspace(wwin, cw);
1584 wMakeWindowVisible(wwin);
1586 if (count > 1)
1587 wSelectWindow(wwin, True);
1590 /* rotate the order of windows, to create a cycling effect */
1591 twin = WMGetFromArray(list, 0);
1592 WMDeleteFromArray(list, 0);
1593 WMAddToArray(list, twin);
1595 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1596 if (scr->shortcutWindows[widx]) {
1597 WMFreeArray(scr->shortcutWindows[widx]);
1598 scr->shortcutWindows[widx] = NULL;
1601 if (wwin->flags.selected && scr->selected_windows) {
1602 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1603 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1604 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1605 } else {
1606 scr->shortcutWindows[widx] = WMCreateArray(4);
1607 WMAddToArray(scr->shortcutWindows[widx], wwin);
1610 wSelectWindow(wwin, !wwin->flags.selected);
1611 XFlush(dpy);
1612 wusleep(3000);
1613 wSelectWindow(wwin, !wwin->flags.selected);
1614 XFlush(dpy);
1616 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1618 if (wwin->flags.selected && scr->selected_windows) {
1619 if (scr->shortcutWindows[widx]) {
1620 WMFreeArray(scr->shortcutWindows[widx]);
1622 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1626 break;
1628 case WKBD_SWITCH_SCREEN:
1629 if (wScreenCount > 1) {
1630 WScreen *scr2;
1631 int i;
1633 /* find index of this screen */
1634 for (i = 0; i < wScreenCount; i++) {
1635 if (wScreenWithNumber(i) == scr)
1636 break;
1638 i++;
1639 if (i >= wScreenCount) {
1640 i = 0;
1642 scr2 = wScreenWithNumber(i);
1644 if (scr2) {
1645 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1646 scr2->scr_width / 2, scr2->scr_height / 2);
1649 break;
1651 case WKBD_NEXTWSLAYER:
1652 case WKBD_PREVWSLAYER:
1654 int row, column;
1656 row = scr->current_workspace / 10;
1657 column = scr->current_workspace % 10;
1659 if (command == WKBD_NEXTWSLAYER) {
1660 if ((row + 1) * 10 < scr->workspace_count)
1661 wWorkspaceChange(scr, column + (row + 1) * 10);
1662 } else {
1663 if (row > 0)
1664 wWorkspaceChange(scr, column + (row - 1) * 10);
1667 break;
1668 case WKBD_CLIPRAISELOWER:
1669 if (!wPreferences.flags.noclip)
1670 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1671 break;
1672 case WKBD_DOCKRAISELOWER:
1673 if (!wPreferences.flags.nodock)
1674 wDockRaiseLower(scr->dock);
1675 break;
1676 #ifdef KEEP_XKB_LOCK_STATUS
1677 case WKBD_TOGGLE:
1678 if (wPreferences.modelock) {
1679 /*toggle */
1680 wwin = scr->focused_window;
1682 if (wwin && wwin->flags.mapped
1683 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1684 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1685 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1687 wwin->frame->languagemode = wwin->frame->last_languagemode;
1688 wwin->frame->last_languagemode = staterec.group;
1689 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1693 break;
1694 #endif /* KEEP_XKB_LOCK_STATUS */
1698 static void handleMotionNotify(XEvent * event)
1700 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1702 if (wPreferences.scrollable_menus) {
1703 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1704 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1706 if (scr->flags.jump_back_pending ||
1707 p.x <= (rect.pos.x + 1) ||
1708 p.x >= (rect.pos.x + rect.size.width - 2) ||
1709 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1710 WMenu *menu;
1712 menu = wMenuUnderPointer(scr);
1713 if (menu != NULL)
1714 wMenuScroll(menu, event);
1719 static void handleVisibilityNotify(XEvent * event)
1721 WWindow *wwin;
1723 wwin = wWindowFor(event->xvisibility.window);
1724 if (!wwin)
1725 return;
1726 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);