Use inotify to check for changes to the defaults database. Workaround for
[wmaker-crm.git] / src / event.c
blob7adaba95273daf63536db3e7ad5bf26e06717798
1 /* event.c- event loop and handling
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
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.
16 *
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.
21 */
23 #include <sys/inotify.h>
24 #include "wconfig.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #ifdef SHAPE
37 # include <X11/extensions/shape.h>
38 #endif
39 #ifdef XDND
40 #include "xdnd.h"
41 #endif
43 #ifdef KEEP_XKB_LOCK_STATUS
44 #include <X11/XKBlib.h>
45 #endif /* KEEP_XKB_LOCK_STATUS */
47 #include "WindowMaker.h"
48 #include "window.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "application.h"
54 #include "stacking.h"
55 #include "defaults.h"
56 #include "workspace.h"
57 #include "dock.h"
58 #include "framewin.h"
59 #include "properties.h"
60 #include "balloon.h"
61 #include "xinerama.h"
63 #ifdef NETWM_HINTS
64 # include "wmspec.h"
65 #endif
67 /******** Global Variables **********/
68 extern XContext wWinContext;
69 extern XContext wVEdgeContext;
71 extern Cursor wCursor[WCUR_LAST];
73 extern WShortKey wKeyBindings[WKBD_LAST];
74 extern int wScreenCount;
75 extern Time LastTimestamp;
76 extern Time LastFocusChange;
78 extern WPreferences wPreferences;
80 #define MOD_MASK wPreferences.modifier_mask
82 extern Atom _XA_WM_COLORMAP_NOTIFY;
84 extern Atom _XA_WM_CHANGE_STATE;
85 extern Atom _XA_WM_DELETE_WINDOW;
86 extern Atom _XA_GNUSTEP_WM_ATTR;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
88 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
89 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
90 extern Atom _XA_WINDOWMAKER_COMMAND;
93 #ifdef SHAPE
94 extern Bool wShapeSupported;
95 extern int wShapeEventBase;
96 #endif
98 #ifdef KEEP_XKB_LOCK_STATUS
99 extern int wXkbEventBase;
100 #endif
102 /* special flags */
103 /*extern char WDelayedActionSet;*/
106 /************ Local stuff ***********/
108 static void saveTimestamp(XEvent *event);
109 static void handleColormapNotify();
110 static void handleMapNotify();
111 static void handleUnmapNotify();
112 static void handleButtonPress();
113 static void handleExpose();
114 static void handleDestroyNotify();
115 static void handleConfigureRequest();
116 static void handleMapRequest();
117 static void handlePropertyNotify();
118 static void handleEnterNotify();
119 static void handleLeaveNotify();
120 static void handleExtensions();
121 static void handleClientMessage();
122 static void handleKeyPress();
123 static void handleFocusIn();
124 static void handleMotionNotify();
125 static void handleVisibilityNotify();
128 #ifdef SHAPE
129 static void handleShapeNotify();
130 #endif
132 /* called from the signal handler */
133 void NotifyDeadProcess(pid_t pid, unsigned char status);
135 /* real dead process handler */
136 static void handleDeadProcess(void *foo);
139 typedef struct DeadProcesses {
140 pid_t pid;
141 unsigned char exit_status;
142 } DeadProcesses;
144 /* stack of dead processes */
145 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
146 static int deadProcessPtr=0;
149 typedef struct DeathHandler {
150 WDeathHandler *callback;
151 pid_t pid;
152 void *client_data;
153 } DeathHandler;
155 static WMArray *deathHandlers=NULL;
159 WMagicNumber
160 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
162 DeathHandler *handler;
164 handler = malloc(sizeof(DeathHandler));
165 if (!handler)
166 return 0;
168 handler->pid = pid;
169 handler->callback = callback;
170 handler->client_data = cdata;
172 if (!deathHandlers)
173 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
175 WMAddToArray(deathHandlers, handler);
177 return handler;
182 void
183 wDeleteDeathHandler(WMagicNumber id)
185 DeathHandler *handler=(DeathHandler*)id;
187 if (!handler || !deathHandlers)
188 return;
190 /* array destructor will call wfree(handler) */
191 WMRemoveFromArray(deathHandlers, handler);
195 void
196 DispatchEvent(XEvent *event)
198 if (deathHandlers)
199 handleDeadProcess(NULL);
201 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
202 WCHANGE_STATE(WSTATE_EXITING);
203 /* received SIGTERM */
204 /*
205 * WMHandleEvent() can't be called from anything
206 * executed inside here, or we can get in a infinite
207 * recursive loop.
208 */
209 Shutdown(WSExitMode);
211 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
212 WCHANGE_STATE(WSTATE_RESTARTING);
214 Shutdown(WSRestartPreparationMode);
215 /* received SIGHUP */
216 Restart(NULL, True);
217 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
218 WCHANGE_STATE(WSTATE_NORMAL);
219 wDefaultsCheckDomains("bla");
222 /* for the case that all that is wanted to be dispatched is
223 * the stuff above */
224 if (!event)
225 return;
227 saveTimestamp(event);
228 switch (event->type) {
229 case MapRequest:
230 handleMapRequest(event);
231 break;
233 case KeyPress:
234 handleKeyPress(event);
235 break;
237 case MotionNotify:
238 handleMotionNotify(event);
239 break;
241 case ConfigureRequest:
242 handleConfigureRequest(event);
243 break;
245 case DestroyNotify:
246 handleDestroyNotify(event);
247 break;
249 case MapNotify:
250 handleMapNotify(event);
251 break;
253 case UnmapNotify:
254 handleUnmapNotify(event);
255 break;
257 case ButtonPress:
258 handleButtonPress(event);
259 break;
261 case Expose:
262 handleExpose(event);
263 break;
265 case PropertyNotify:
266 handlePropertyNotify(event);
267 break;
269 case EnterNotify:
270 handleEnterNotify(event);
271 break;
273 case LeaveNotify:
274 handleLeaveNotify(event);
275 break;
277 case ClientMessage:
278 handleClientMessage(event);
279 break;
281 case ColormapNotify:
282 handleColormapNotify(event);
283 break;
285 case MappingNotify:
286 if (event->xmapping.request == MappingKeyboard
287 || event->xmapping.request == MappingModifier)
288 XRefreshKeyboardMapping(&event->xmapping);
289 break;
291 case FocusIn:
292 handleFocusIn(event);
293 break;
295 case VisibilityNotify:
296 handleVisibilityNotify(event);
297 break;
298 default:
299 handleExtensions(event);
300 break;
304 /*
305 *----------------------------------------------------------------------
306 * inotifyHandleEvents-
307 * Check for inotify events
309 * Returns:
310 * After reading events for the given file descriptor (fd) and
311 * watch descriptor (wd)
313 * Side effects:
314 * Calls wDefaultsCheckDomains if config database is updated
315 *----------------------------------------------------------------------
316 */
318 /* Allow for 1024 simultanious events */
319 #define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
320 void inotifyHandleEvents (int fd, int wd)
322 ssize_t eventQLength, i = 0;
323 char buff[BUFF_SIZE] = {0};
324 extern void wDefaultsCheckDomains();
325 int oneShotFlag=0; /* Only check config once per read of the event queue */
327 /* Read off the queued events
328 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
329 * not occur; the block is on Xevents, but a config file change will normally
330 * occur as a result of an Xevent - so the event queue should never have more than
331 * a few entries before a read().
332 */
333 eventQLength = read (fd, buff, BUFF_SIZE);
335 /* check what events occured */
336 /* Should really check wd here too, but for now we only have one watch! */
337 while (i < eventQLength) {
338 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
340 /*
341 * see inotify.h for event types.
342 */
343 if (pevent->mask & IN_DELETE_SELF) {
344 wwarning(_("the defaults database has been deleted!"
345 " Restart Window Maker to create the database"
346 " with the default settings"));
347 close(fd);
349 if (pevent->mask & IN_UNMOUNT) {
350 wwarning(_("the unit containing the defaults database has"
351 " been unmounted. Setting --static mode."
352 " Any changes will not be saved."));
353 close(fd);
354 wPreferences.flags.noupdates=1;
356 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
357 fprintf(stdout,"wmaker: reading config files in defaults database.\n");
358 wDefaultsCheckDomains(NULL);
360 /* Check for filename (length of name (len) > 0) */
361 /* if (pevent->len) printf ("name=%s\n", pevent->name); */
363 i += sizeof(struct inotify_event) + pevent->len; /* move to next event in the buffer */
366 } /* inotifyHandleEvents */
368 /*
369 *----------------------------------------------------------------------
370 * EventLoop-
371 * Processes X and internal events indefinitely.
373 * Returns:
374 * Never returns
376 * Side effects:
377 * The LastTimestamp global variable is updated.
378 * Calls inotifyGetEvents if defaults database changes.
379 *----------------------------------------------------------------------
380 */
381 void
382 EventLoop()
384 XEvent event;
385 extern int inotifyFD;
386 extern int inotifyWD;
387 struct timeval time;
388 fd_set rfds;
389 int retVal=0;
391 if (inotifyFD < 0 || inotifyWD < 0)
392 retVal = -1;
394 for(;;) {
396 WMNextEvent(dpy, &event); /* Blocks here */
397 WMHandleEvent(&event);
399 if (retVal != -1 ) {
400 time.tv_sec = 0;
401 time.tv_usec = 0;
402 FD_ZERO (&rfds);
403 FD_SET (inotifyFD, &rfds);
405 /* check for available read data from inotify - don't block! */
406 retVal = select (inotifyFD + 1, &rfds, NULL, NULL, &time);
408 if (retVal < 0) { /* an error has occured */
409 wwarning(_("select failed. The inotify instance will be closed."
410 " Changes to the defaults database will require"
411 " a restart to take effect."));
412 close(inotifyFD);
413 continue;
415 if (FD_ISSET (inotifyFD, &rfds))
416 inotifyHandleEvents(inotifyFD,inotifyWD);
421 /*
422 *----------------------------------------------------------------------
423 * ProcessPendingEvents --
424 * Processes the events that are currently pending (at the time
425 * this function is called) in the display's queue.
427 * Returns:
428 * After the pending events that were present at the function call
429 * are processed.
431 * Side effects:
432 * Many -- whatever handling events may involve.
434 *----------------------------------------------------------------------
435 */
436 void
437 ProcessPendingEvents()
439 XEvent event;
440 int count;
442 XSync(dpy, False);
444 /* Take a snapshot of the event count in the queue */
445 count = XPending(dpy);
447 while (count>0 && XPending(dpy)) {
448 WMNextEvent(dpy, &event);
449 WMHandleEvent(&event);
450 count--;
455 Bool
456 IsDoubleClick(WScreen *scr, XEvent *event)
458 if ((scr->last_click_time>0) &&
459 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
460 && (event->xbutton.button == scr->last_click_button)
461 && (event->xbutton.window == scr->last_click_window)) {
463 scr->flags.next_click_is_not_double = 1;
464 scr->last_click_time = 0;
465 scr->last_click_window = event->xbutton.window;
467 return True;
469 return False;
473 void
474 NotifyDeadProcess(pid_t pid, unsigned char status)
476 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
477 wwarning("stack overflow: too many dead processes");
478 return;
480 /* stack the process to be handled later,
481 * as this is called from the signal handler */
482 deadProcesses[deadProcessPtr].pid = pid;
483 deadProcesses[deadProcessPtr].exit_status = status;
484 deadProcessPtr++;
488 static void
489 handleDeadProcess(void *foo)
491 DeathHandler *tmp;
492 int i;
494 for (i=0; i<deadProcessPtr; i++) {
495 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
498 if (!deathHandlers) {
499 deadProcessPtr=0;
500 return;
503 /* get the pids on the queue and call handlers */
504 while (deadProcessPtr>0) {
505 deadProcessPtr--;
507 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
508 tmp = WMGetFromArray(deathHandlers, i);
509 if (!tmp)
510 continue;
512 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
513 (*tmp->callback)(tmp->pid,
514 deadProcesses[deadProcessPtr].exit_status,
515 tmp->client_data);
516 wDeleteDeathHandler(tmp);
523 static void
524 saveTimestamp(XEvent *event)
526 /*
527 * Never save CurrentTime as LastTimestamp because CurrentTime
528 * it's not a real timestamp (it's the 0L constant)
529 */
531 switch (event->type) {
532 case ButtonRelease:
533 case ButtonPress:
534 LastTimestamp = event->xbutton.time;
535 break;
536 case KeyPress:
537 case KeyRelease:
538 LastTimestamp = event->xkey.time;
539 break;
540 case MotionNotify:
541 LastTimestamp = event->xmotion.time;
542 break;
543 case PropertyNotify:
544 LastTimestamp = event->xproperty.time;
545 break;
546 case EnterNotify:
547 case LeaveNotify:
548 LastTimestamp = event->xcrossing.time;
549 break;
550 case SelectionClear:
551 LastTimestamp = event->xselectionclear.time;
552 break;
553 case SelectionRequest:
554 LastTimestamp = event->xselectionrequest.time;
555 break;
556 case SelectionNotify:
557 LastTimestamp = event->xselection.time;
558 #ifdef XDND
559 wXDNDProcessSelection(event);
560 #endif
561 break;
566 static int
567 matchWindow(void *item, void *cdata)
569 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
573 static void
574 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*/
593 static void
594 handleMapRequest(XEvent *ev)
596 WWindow *wwin;
597 WScreen *scr = NULL;
598 Window window = ev->xmaprequest.window;
600 #ifdef DEBUG
601 printf("got map request for %x\n", (unsigned)window);
602 #endif
603 if ((wwin = wWindowFor(window))) {
604 if (wwin->flags.shaded) {
605 wUnshadeWindow(wwin);
607 /* deiconify window */
608 if (wwin->flags.miniaturized) {
609 wDeiconifyWindow(wwin);
610 } else if (wwin->flags.hidden) {
611 WApplication *wapp = wApplicationOf(wwin->main_window);
612 /* go to the last workspace that the user worked on the app */
613 if (wapp) {
614 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
616 wUnhideApplication(wapp, False, False);
618 return;
621 scr = wScreenForRootWindow(ev->xmaprequest.parent);
623 wwin = wManageWindow(scr, window);
625 /*
626 * This is to let the Dock know that the application it launched
627 * has already been mapped (eg: it has finished launching).
628 * It is not necessary for normally docked apps, but is needed for
629 * apps that were forcedly docked (like with dockit).
630 */
631 if (scr->last_dock) {
632 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
633 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
634 else
635 wDockTrackWindowLaunch(scr->last_dock, window);
638 if (wwin) {
639 wClientSetState(wwin, NormalState, None);
640 if (wwin->flags.maximized) {
641 wMaximizeWindow(wwin, wwin->flags.maximized);
643 if (wwin->flags.shaded) {
644 wwin->flags.shaded = 0;
645 wwin->flags.skip_next_animation = 1;
646 wShadeWindow(wwin);
648 if (wwin->flags.miniaturized) {
649 wwin->flags.miniaturized = 0;
650 wwin->flags.skip_next_animation = 1;
651 wIconifyWindow(wwin);
653 if (wwin->flags.fullscreen) {
654 wwin->flags.fullscreen = 0;
655 wFullscreenWindow(wwin);
657 if (wwin->flags.hidden) {
658 WApplication *wapp = wApplicationOf(wwin->main_window);
660 wwin->flags.hidden = 0;
661 wwin->flags.skip_next_animation = 1;
662 if (wapp) {
663 wHideApplication(wapp);
670 static void
671 handleDestroyNotify(XEvent *event)
673 WWindow *wwin;
674 WApplication *app;
675 Window window = event->xdestroywindow.window;
676 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
677 int index;
679 #ifdef DEBUG
680 printf("got destroy notify\n");
681 #endif
682 wwin = wWindowFor(window);
683 if (wwin) {
684 wUnmanageWindow(wwin, False, True);
687 if (scr != NULL) {
688 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
689 (void*)window)) != WANotFound) {
690 WFakeGroupLeader *fPtr;
692 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
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);
723 static void
724 handleExpose(XEvent *event)
726 WObjDescriptor *desc;
727 XEvent ev;
729 #ifdef DEBUG
730 printf("got expose\n");
731 #endif
732 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
734 if (XFindContext(dpy, event->xexpose.window, wWinContext,
735 (XPointer *)&desc)==XCNOENT) {
736 return;
739 if (desc->handle_expose) {
740 (*desc->handle_expose)(desc, event);
744 static void
745 executeButtonAction(WScreen *scr, XEvent *event, int action)
747 switch(action) {
748 case WA_SELECT_WINDOWS:
749 wUnselectWindows(scr);
750 wSelectWindows(scr, event);
751 break;
752 case WA_OPEN_APPMENU:
753 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
754 /* ugly hack */
755 if (scr->root_menu) {
756 if (scr->root_menu->brother->flags.mapped)
757 event->xbutton.window = scr->root_menu->brother->frame->core->window;
758 else
759 event->xbutton.window = scr->root_menu->frame->core->window;
761 break;
762 case WA_OPEN_WINLISTMENU:
763 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
764 if (scr->switch_menu) {
765 if (scr->switch_menu->brother->flags.mapped)
766 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
767 else
768 event->xbutton.window = scr->switch_menu->frame->core->window;
770 break;
771 default:
772 break;
777 /* bindable */
778 static void
779 handleButtonPress(XEvent *event)
781 WObjDescriptor *desc;
782 WScreen *scr;
784 #ifdef DEBUG
785 printf("got button press\n");
786 #endif
787 scr = wScreenForRootWindow(event->xbutton.root);
789 #ifdef BALLOON_TEXT
790 wBalloonHide(scr);
791 #endif
794 #ifndef LITE
795 if (event->xbutton.window==scr->root_win) {
796 if (event->xbutton.button==Button1 &&
797 wPreferences.mouse_button1!=WA_NONE) {
798 executeButtonAction(scr, event, wPreferences.mouse_button1);
799 } else if (event->xbutton.button==Button2 &&
800 wPreferences.mouse_button2!=WA_NONE) {
801 executeButtonAction(scr, event, wPreferences.mouse_button2);
802 } else if (event->xbutton.button==Button3 &&
803 wPreferences.mouse_button3!=WA_NONE) {
804 executeButtonAction(scr, event, wPreferences.mouse_button3);
805 } else if (event->xbutton.button==Button4 &&
806 wPreferences.mouse_wheel!=WA_NONE) {
807 wWorkspaceRelativeChange(scr, 1);
808 } else if (event->xbutton.button==Button5 &&
809 wPreferences.mouse_wheel!=WA_NONE) {
810 wWorkspaceRelativeChange(scr, -1);
813 #endif /* !LITE */
815 desc = NULL;
816 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
817 (XPointer *)&desc)==XCNOENT) {
818 if (XFindContext(dpy, event->xbutton.window, wWinContext,
819 (XPointer *)&desc)==XCNOENT) {
820 return;
824 if (desc->parent_type == WCLASS_WINDOW) {
825 XSync(dpy, 0);
827 if (event->xbutton.state & MOD_MASK) {
828 XAllowEvents(dpy, AsyncPointer, CurrentTime);
831 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
832 if (wPreferences.ignore_focus_click) {
833 XAllowEvents(dpy, AsyncPointer, CurrentTime);
835 XAllowEvents(dpy, ReplayPointer, CurrentTime);
836 /* }*/
837 XSync(dpy, 0);
838 } else if (desc->parent_type == WCLASS_APPICON
839 || desc->parent_type == WCLASS_MINIWINDOW
840 || desc->parent_type == WCLASS_DOCK_ICON) {
841 if (event->xbutton.state & MOD_MASK) {
842 XSync(dpy, 0);
843 XAllowEvents(dpy, AsyncPointer, CurrentTime);
844 XSync(dpy, 0);
848 if (desc->handle_mousedown!=NULL) {
849 (*desc->handle_mousedown)(desc, event);
852 /* save double-click information */
853 if (scr->flags.next_click_is_not_double) {
854 scr->flags.next_click_is_not_double = 0;
855 } else {
856 scr->last_click_time = event->xbutton.time;
857 scr->last_click_button = event->xbutton.button;
858 scr->last_click_window = event->xbutton.window;
863 static void
864 handleMapNotify(XEvent *event)
866 WWindow *wwin;
867 #ifdef DEBUG
868 printf("got map\n");
869 #endif
870 wwin = wWindowFor(event->xmap.event);
871 if (wwin && wwin->client_win == event->xmap.event) {
872 if (wwin->flags.miniaturized) {
873 wDeiconifyWindow(wwin);
874 } else {
875 XGrabServer(dpy);
876 wWindowMap(wwin);
877 wClientSetState(wwin, NormalState, None);
878 XUngrabServer(dpy);
884 static void
885 handleUnmapNotify(XEvent *event)
887 WWindow *wwin;
888 XEvent ev;
889 Bool withdraw = False;
890 #ifdef DEBUG
891 printf("got unmap\n");
892 #endif
893 /* only process windows with StructureNotify selected
894 * (ignore SubstructureNotify) */
895 wwin = wWindowFor(event->xunmap.window);
896 if (!wwin)
897 return;
899 /* whether the event is a Withdrawal request */
900 if (event->xunmap.event == wwin->screen_ptr->root_win
901 && event->xunmap.send_event)
902 withdraw = True;
904 if (wwin->client_win != event->xunmap.event && !withdraw)
905 return;
907 if (!wwin->flags.mapped && !withdraw
908 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
909 && !wwin->flags.miniaturized && !wwin->flags.hidden)
910 return;
912 XGrabServer(dpy);
913 XUnmapWindow(dpy, wwin->frame->core->window);
914 wwin->flags.mapped = 0;
915 XSync(dpy, 0);
916 /* check if the window was destroyed */
917 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
918 DispatchEvent(&ev);
919 } else {
920 Bool reparented = False;
922 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
923 reparented = True;
925 /* withdraw window */
926 wwin->flags.mapped = 0;
927 if (!reparented)
928 wClientSetState(wwin, WithdrawnState, None);
930 /* if the window was reparented, do not reparent it back to the
931 * root window */
932 wUnmanageWindow(wwin, !reparented, False);
934 XUngrabServer(dpy);
938 static void
939 handleConfigureRequest(XEvent *event)
941 WWindow *wwin;
942 #ifdef DEBUG
943 printf("got configure request\n");
944 #endif
945 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
946 /*
947 * Configure request for unmapped window
948 */
949 wClientConfigure(NULL, &(event->xconfigurerequest));
950 } else {
951 wClientConfigure(wwin, &(event->xconfigurerequest));
956 static void
957 handlePropertyNotify(XEvent *event)
959 WWindow *wwin;
960 WApplication *wapp;
961 Window jr;
962 int ji;
963 unsigned int ju;
964 WScreen *scr;
965 #ifdef DEBUG
966 printf("got property notify\n");
967 #endif
968 if ((wwin=wWindowFor(event->xproperty.window))) {
969 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
970 &ju, &ju, &ju, &ju)) {
971 return;
973 wClientCheckProperty(wwin, &event->xproperty);
975 wapp = wApplicationOf(event->xproperty.window);
976 if (wapp) {
977 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
980 scr = wScreenForWindow(event->xproperty.window);
984 static void
985 handleClientMessage(XEvent *event)
987 WWindow *wwin;
988 WObjDescriptor *desc;
989 #ifdef DEBUG
990 printf("got client message\n");
991 #endif
992 /* handle transition from Normal to Iconic state */
993 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
994 && event->xclient.format == 32
995 && event->xclient.data.l[0] == IconicState) {
997 wwin = wWindowFor(event->xclient.window);
998 if (!wwin) return;
999 if (!wwin->flags.miniaturized)
1000 wIconifyWindow(wwin);
1001 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
1002 && event->xclient.format == 32) {
1003 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1005 if (!scr)
1006 return;
1008 if (event->xclient.data.l[1] == 1) { /* starting */
1009 wColormapAllowClientInstallation(scr, True);
1010 } else { /* stopping */
1011 wColormapAllowClientInstallation(scr, False);
1013 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
1015 wDefaultsCheckDomains("bla");
1017 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
1018 WApplication *wapp;
1019 int done=0;
1020 wapp = wApplicationOf(event->xclient.window);
1021 if (wapp) {
1022 switch (event->xclient.data.l[0]) {
1023 case WMFHideOtherApplications:
1024 wHideOtherApplications(wapp->main_window_desc);
1025 done = 1;
1026 break;
1028 case WMFHideApplication:
1029 wHideApplication(wapp);
1030 done = 1;
1031 break;
1034 if (!done) {
1035 wwin = wWindowFor(event->xclient.window);
1036 if (wwin) {
1037 switch (event->xclient.data.l[0]) {
1038 case WMFHideOtherApplications:
1039 wHideOtherApplications(wwin);
1040 break;
1042 case WMFHideApplication:
1043 wHideApplication(wApplicationOf(wwin->main_window));
1044 break;
1048 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
1049 wwin = wWindowFor(event->xclient.window);
1050 if (!wwin) return;
1051 switch (event->xclient.data.l[0]) {
1052 case GSWindowLevelAttr:
1054 int level = (int)event->xclient.data.l[1];
1056 if (WINDOW_LEVEL(wwin) != level) {
1057 ChangeStackingLevel(wwin->frame->core, level);
1060 break;
1062 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
1063 wwin = wWindowFor(event->xclient.window);
1064 if (!wwin) return;
1065 switch (event->xclient.data.l[0]) {
1066 case WMTitleBarNormal:
1067 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1068 break;
1069 case WMTitleBarMain:
1070 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1071 break;
1072 case WMTitleBarKey:
1073 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1074 break;
1076 #ifdef NETWM_HINTS
1077 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1078 /* do nothing */
1079 #endif
1080 #ifdef XDND
1081 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1082 /* do nothing */
1083 #endif /* XDND */
1084 } else {
1085 /*
1086 * Non-standard thing, but needed by OffiX DND.
1087 * For when the icon frame gets a ClientMessage
1088 * that should have gone to the icon_window.
1089 */
1090 if (XFindContext(dpy, event->xbutton.window, wWinContext,
1091 (XPointer *)&desc)!=XCNOENT) {
1092 struct WIcon *icon=NULL;
1094 if (desc->parent_type == WCLASS_MINIWINDOW) {
1095 icon = (WIcon*)desc->parent;
1096 } else if (desc->parent_type == WCLASS_DOCK_ICON
1097 || desc->parent_type == WCLASS_APPICON) {
1098 icon = ((WAppIcon*)desc->parent)->icon;
1100 if (icon && (wwin=icon->owner)) {
1101 if (wwin->client_win!=event->xclient.window) {
1102 event->xclient.window = wwin->client_win;
1103 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1104 event);
1112 static void
1113 raiseWindow(WScreen *scr)
1115 WWindow *wwin;
1117 scr->autoRaiseTimer = NULL;
1119 wwin = wWindowFor(scr->autoRaiseWindow);
1120 if (!wwin)
1121 return;
1123 if (!wwin->flags.destroyed && wwin->flags.focused) {
1124 wRaiseFrame(wwin->frame->core);
1125 /* this is needed or a race condition will occur */
1126 XSync(dpy, False);
1131 static void
1132 handleEnterNotify(XEvent *event)
1134 WWindow *wwin;
1135 WObjDescriptor *desc = NULL;
1136 #ifdef VIRTUAL_DESKTOP
1137 void (*vdHandler)(XEvent * event);
1138 #endif
1139 XEvent ev;
1140 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1141 #ifdef DEBUG
1142 printf("got enter notify\n");
1143 #endif
1145 #ifdef VIRTUAL_DESKTOP
1146 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext,
1147 (XPointer *)&vdHandler)!=XCNOENT) {
1148 (*vdHandler)(event);
1150 #endif
1152 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1153 &ev)) {
1154 /* already left the window... */
1155 saveTimestamp(&ev);
1156 if (ev.xcrossing.mode==event->xcrossing.mode
1157 && ev.xcrossing.detail==event->xcrossing.detail) {
1158 return;
1162 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1163 (XPointer *)&desc)!=XCNOENT) {
1164 if(desc->handle_enternotify)
1165 (*desc->handle_enternotify)(desc, event);
1168 /* enter to window */
1169 wwin = wWindowFor(event->xcrossing.window);
1170 if (!wwin) {
1171 if (wPreferences.colormap_mode==WCM_POINTER) {
1172 wColormapInstallForWindow(scr, NULL);
1174 if (scr->autoRaiseTimer
1175 && event->xcrossing.root==event->xcrossing.window) {
1176 WMDeleteTimerHandler(scr->autoRaiseTimer);
1177 scr->autoRaiseTimer = NULL;
1179 } else {
1180 /* set auto raise timer even if in focus-follows-mouse mode
1181 * and the event is for the frame window, even if the window
1182 * has focus already. useful if you move the pointer from a focused
1183 * window to the root window and back pretty fast
1185 * set focus if in focus-follows-mouse mode and the event
1186 * is for the frame window and window doesn't have focus yet */
1187 if (wPreferences.focus_mode==WKF_SLOPPY
1188 && wwin->frame->core->window==event->xcrossing.window
1189 && !scr->flags.doing_alt_tab) {
1191 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1192 wSetFocusTo(scr, wwin);
1194 if (scr->autoRaiseTimer)
1195 WMDeleteTimerHandler(scr->autoRaiseTimer);
1196 scr->autoRaiseTimer = NULL;
1198 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1199 scr->autoRaiseWindow = wwin->frame->core->window;
1200 scr->autoRaiseTimer
1201 = WMAddTimerHandler(wPreferences.raise_delay,
1202 (WMCallback*)raiseWindow, scr);
1205 /* Install colormap for window, if the colormap installation mode
1206 * is colormap_follows_mouse */
1207 if (wPreferences.colormap_mode==WCM_POINTER) {
1208 if (wwin->client_win==event->xcrossing.window)
1209 wColormapInstallForWindow(scr, wwin);
1210 else
1211 wColormapInstallForWindow(scr, NULL);
1215 /* a little kluge to hide the clip balloon */
1216 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1217 if (!desc) {
1218 XUnmapWindow(dpy, scr->clip_balloon);
1219 scr->flags.clip_balloon_mapped = 0;
1220 } else {
1221 if (desc->parent_type!=WCLASS_DOCK_ICON
1222 || scr->clip_icon != desc->parent) {
1223 XUnmapWindow(dpy, scr->clip_balloon);
1224 scr->flags.clip_balloon_mapped = 0;
1229 if (event->xcrossing.window == event->xcrossing.root
1230 && event->xcrossing.detail == NotifyNormal
1231 && event->xcrossing.detail != NotifyInferior
1232 && wPreferences.focus_mode != WKF_CLICK) {
1234 wSetFocusTo(scr, scr->focused_window);
1237 #ifdef BALLOON_TEXT
1238 wBalloonEnteredObject(scr, desc);
1239 #endif
1243 static void
1244 handleLeaveNotify(XEvent *event)
1246 WObjDescriptor *desc = NULL;
1248 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1249 (XPointer *)&desc)!=XCNOENT) {
1250 if(desc->handle_leavenotify)
1251 (*desc->handle_leavenotify)(desc, event);
1256 #ifdef SHAPE
1257 static void
1258 handleShapeNotify(XEvent *event)
1260 XShapeEvent *shev = (XShapeEvent*)event;
1261 WWindow *wwin;
1262 XEvent ev;
1263 #ifdef DEBUG
1264 printf("got shape notify\n");
1265 #endif
1266 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1267 XShapeEvent *sev = (XShapeEvent*)&ev;
1269 if (sev->kind == ShapeBounding) {
1270 if (sev->shaped == shev->shaped) {
1271 *shev = *sev;
1272 } else {
1273 XPutBackEvent(dpy, &ev);
1274 break;
1279 wwin = wWindowFor(shev->window);
1280 if (!wwin || shev->kind != ShapeBounding)
1281 return;
1283 if (!shev->shaped && wwin->flags.shaped) {
1285 wwin->flags.shaped = 0;
1286 wWindowClearShape(wwin);
1288 } else if (shev->shaped) {
1290 wwin->flags.shaped = 1;
1291 wWindowSetShape(wwin);
1294 #endif /* SHAPE */
1296 #ifdef KEEP_XKB_LOCK_STATUS
1297 /* please help ]d if you know what to do */
1298 handleXkbIndicatorStateNotify(XEvent *event)
1300 WWindow *wwin;
1301 WScreen *scr;
1302 XkbStateRec staterec;
1303 int i;
1305 for (i=0; i<wScreenCount; i++) {
1306 scr = wScreenWithNumber(i);
1307 wwin = scr->focused_window;
1308 if (wwin && wwin->flags.focused) {
1309 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1310 if (wwin->frame->languagemode != staterec.group) {
1311 wwin->frame->last_languagemode = wwin->frame->languagemode;
1312 wwin->frame->languagemode = staterec.group;
1314 #ifdef XKB_BUTTON_HINT
1315 if (wwin->frame->titlebar) {
1316 wFrameWindowPaint(wwin->frame);
1318 #endif
1322 #endif /*KEEP_XKB_LOCK_STATUS*/
1324 static void
1325 handleColormapNotify(XEvent *event)
1327 WWindow *wwin;
1328 WScreen *scr;
1329 Bool reinstall = False;
1331 wwin = wWindowFor(event->xcolormap.window);
1332 if (!wwin)
1333 return;
1335 scr = wwin->screen_ptr;
1337 do {
1338 if (wwin) {
1339 if (event->xcolormap.new) {
1340 XWindowAttributes attr;
1342 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1344 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1345 scr->current_colormap = attr.colormap;
1347 reinstall = True;
1348 } else if (event->xcolormap.state == ColormapUninstalled &&
1349 scr->current_colormap == event->xcolormap.colormap) {
1351 /* some bastard app (like XV) removed our colormap */
1352 /*
1353 * can't enforce or things like xscreensaver wont work
1354 * reinstall = True;
1355 */
1356 } else if (event->xcolormap.state == ColormapInstalled &&
1357 scr->current_colormap == event->xcolormap.colormap) {
1359 /* someone has put our colormap back */
1360 reinstall = False;
1363 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1364 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1366 if (reinstall && scr->current_colormap!=None) {
1367 if (!scr->flags.colormap_stuff_blocked)
1368 XInstallColormap(dpy, scr->current_colormap);
1374 static void
1375 handleFocusIn(XEvent *event)
1377 WWindow *wwin;
1379 /*
1380 * For applications that like stealing the focus.
1381 */
1382 while (XCheckTypedEvent(dpy, FocusIn, event));
1383 saveTimestamp(event);
1384 if (event->xfocus.mode == NotifyUngrab
1385 || event->xfocus.mode == NotifyGrab
1386 || event->xfocus.detail > NotifyNonlinearVirtual) {
1387 return;
1390 wwin = wWindowFor(event->xfocus.window);
1391 if (wwin && !wwin->flags.focused) {
1392 if (wwin->flags.mapped)
1393 wSetFocusTo(wwin->screen_ptr, wwin);
1394 else
1395 wSetFocusTo(wwin->screen_ptr, NULL);
1396 } else if (!wwin) {
1397 WScreen *scr = wScreenForWindow(event->xfocus.window);
1398 if (scr)
1399 wSetFocusTo(scr, NULL);
1404 static WWindow*
1405 windowUnderPointer(WScreen *scr)
1407 unsigned int mask;
1408 int foo;
1409 Window bar, win;
1411 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1412 &mask))
1413 return wWindowFor(win);
1414 return NULL;
1418 static int CheckFullScreenWindowFocused(WScreen *scr)
1420 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1421 return 1;
1422 else
1423 return 0;
1427 static void
1428 handleKeyPress(XEvent *event)
1430 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1431 WWindow *wwin = scr->focused_window;
1432 int i;
1433 int modifiers;
1434 int command=-1, index;
1435 #ifdef KEEP_XKB_LOCK_STATUS
1436 XkbStateRec staterec;
1437 #endif /*KEEP_XKB_LOCK_STATUS*/
1439 /* ignore CapsLock */
1440 modifiers = event->xkey.state & ValidModMask;
1442 for (i=0; i<WKBD_LAST; i++) {
1443 if (wKeyBindings[i].keycode==0)
1444 continue;
1446 if (wKeyBindings[i].keycode==event->xkey.keycode
1447 && (/*wKeyBindings[i].modifier==0
1448 ||*/ wKeyBindings[i].modifier==modifiers)) {
1449 command = i;
1450 break;
1455 if (command < 0) {
1456 #ifdef LITE
1458 #if 0
1460 #endif
1461 #else
1462 if (!wRootMenuPerformShortcut(event)) {
1463 #endif
1464 static int dontLoop = 0;
1466 if (dontLoop > 10) {
1467 wwarning("problem with key event processing code");
1468 return;
1470 dontLoop++;
1471 /* if the focused window is an internal window, try redispatching
1472 * the event to the managed window, as it can be a WINGs window */
1473 if (wwin && wwin->flags.internal_window
1474 && wwin->client_leader!=None) {
1475 /* client_leader contains the WINGs toplevel */
1476 event->xany.window = wwin->client_leader;
1477 WMHandleEvent(event);
1479 dontLoop--;
1481 return;
1484 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1485 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1487 switch (command) {
1488 #ifndef LITE
1489 case WKBD_ROOTMENU:
1490 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1491 if (!CheckFullScreenWindowFocused(scr)) {
1492 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1493 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1495 break;
1496 case WKBD_WINDOWLIST:
1497 if (!CheckFullScreenWindowFocused(scr)) {
1498 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1499 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1501 break;
1502 #endif /* !LITE */
1503 case WKBD_WINDOWMENU:
1504 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1505 OpenWindowMenu(wwin, wwin->frame_x,
1506 wwin->frame_y+wwin->frame->top_width, True);
1507 break;
1508 case WKBD_MINIATURIZE:
1509 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1510 && !WFLAGP(wwin, no_miniaturizable)) {
1511 CloseWindowMenu(scr);
1513 if (wwin->protocols.MINIATURIZE_WINDOW)
1514 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1515 event->xbutton.time);
1516 else {
1517 wIconifyWindow(wwin);
1520 break;
1521 case WKBD_HIDE:
1522 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1523 WApplication *wapp = wApplicationOf(wwin->main_window);
1524 CloseWindowMenu(scr);
1526 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1527 wHideApplication(wapp);
1530 break;
1531 case WKBD_HIDE_OTHERS:
1532 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1533 CloseWindowMenu(scr);
1535 wHideOtherApplications(wwin);
1537 break;
1538 case WKBD_MAXIMIZE:
1539 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1540 int newdir = (MAX_VERTICAL|MAX_HORIZONTAL);
1542 CloseWindowMenu(scr);
1544 if (wwin->flags.maximized == newdir) {
1545 wUnmaximizeWindow(wwin);
1546 } else {
1547 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1550 break;
1551 case WKBD_VMAXIMIZE:
1552 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1553 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1555 CloseWindowMenu(scr);
1557 if (newdir) {
1558 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1559 } else {
1560 wUnmaximizeWindow(wwin);
1563 break;
1564 case WKBD_HMAXIMIZE:
1565 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1566 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1568 CloseWindowMenu(scr);
1570 if (newdir) {
1571 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1572 } else {
1573 wUnmaximizeWindow(wwin);
1576 break;
1577 case WKBD_RAISE:
1578 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1579 CloseWindowMenu(scr);
1581 wRaiseFrame(wwin->frame->core);
1583 break;
1584 case WKBD_LOWER:
1585 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1586 CloseWindowMenu(scr);
1588 wLowerFrame(wwin->frame->core);
1590 break;
1591 case WKBD_RAISELOWER:
1592 /* raise or lower the window under the pointer, not the
1593 * focused one
1594 */
1595 wwin = windowUnderPointer(scr);
1596 if (wwin)
1597 wRaiseLowerFrame(wwin->frame->core);
1598 break;
1599 case WKBD_SHADE:
1600 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1601 if (wwin->flags.shaded)
1602 wUnshadeWindow(wwin);
1603 else
1604 wShadeWindow(wwin);
1606 break;
1607 case WKBD_MOVERESIZE:
1608 if (ISMAPPED(wwin) && ISFOCUSED(wwin) &&
1609 (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1610 CloseWindowMenu(scr);
1612 wKeyboardMoveResizeWindow(wwin);
1614 break;
1615 case WKBD_CLOSE:
1616 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1617 CloseWindowMenu(scr);
1618 if (wwin->protocols.DELETE_WINDOW)
1619 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1620 event->xkey.time);
1622 break;
1623 case WKBD_SELECT:
1624 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1625 wSelectWindow(wwin, !wwin->flags.selected);
1627 break;
1628 case WKBD_FOCUSNEXT:
1629 StartWindozeCycle(wwin, event, True);
1630 break;
1632 case WKBD_FOCUSPREV:
1633 StartWindozeCycle(wwin, event, False);
1634 break;
1636 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1637 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1638 i = (scr->current_workspace/10)*10 + wk - 1;\
1639 if (wPreferences.ws_advance || i<scr->workspace_count)\
1640 wWorkspaceChange(scr, i);\
1641 break
1642 #else
1643 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1644 i = (scr->current_workspace/10)*10 + wk - 1;\
1645 if (wPreferences.ws_advance || i<scr->workspace_count)\
1646 wWorkspaceChange(scr, i);\
1647 break
1648 #endif
1649 GOTOWORKS(1);
1650 GOTOWORKS(2);
1651 GOTOWORKS(3);
1652 GOTOWORKS(4);
1653 GOTOWORKS(5);
1654 GOTOWORKS(6);
1655 GOTOWORKS(7);
1656 GOTOWORKS(8);
1657 GOTOWORKS(9);
1658 GOTOWORKS(10);
1659 #undef GOTOWORKS
1660 case WKBD_NEXTWORKSPACE:
1661 wWorkspaceRelativeChange(scr, 1);
1662 break;
1663 case WKBD_PREVWORKSPACE:
1664 wWorkspaceRelativeChange(scr, -1);
1665 break;
1666 case WKBD_WINDOW1:
1667 case WKBD_WINDOW2:
1668 case WKBD_WINDOW3:
1669 case WKBD_WINDOW4:
1670 case WKBD_WINDOW5:
1671 case WKBD_WINDOW6:
1672 case WKBD_WINDOW7:
1673 case WKBD_WINDOW8:
1674 case WKBD_WINDOW9:
1675 case WKBD_WINDOW10:
1677 index = command-WKBD_WINDOW1;
1679 if (scr->shortcutWindows[index]) {
1680 WMArray *list = scr->shortcutWindows[index];
1681 int cw;
1682 int count = WMGetArrayItemCount(list);
1683 WWindow *twin;
1684 WMArrayIterator iter;
1685 WWindow *wwin;
1687 wUnselectWindows(scr);
1688 cw = scr->current_workspace;
1690 WM_ETARETI_ARRAY(list, wwin, iter) {
1691 if (count > 1)
1692 wWindowChangeWorkspace(wwin, cw);
1694 wMakeWindowVisible(wwin);
1696 if (count > 1)
1697 wSelectWindow(wwin, True);
1700 /* rotate the order of windows, to create a cycling effect */
1701 twin = WMGetFromArray(list, 0);
1702 WMDeleteFromArray(list, 0);
1703 WMAddToArray(list, twin);
1705 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1706 if (scr->shortcutWindows[index]) {
1707 WMFreeArray(scr->shortcutWindows[index]);
1708 scr->shortcutWindows[index] = NULL;
1711 if (wwin->flags.selected && scr->selected_windows) {
1712 scr->shortcutWindows[index] =
1713 WMDuplicateArray(scr->selected_windows);
1714 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1715 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1716 } else {
1717 scr->shortcutWindows[index] = WMCreateArray(4);
1718 WMAddToArray(scr->shortcutWindows[index], wwin);
1721 wSelectWindow(wwin, !wwin->flags.selected);
1722 XFlush(dpy);
1723 wusleep(3000);
1724 wSelectWindow(wwin, !wwin->flags.selected);
1725 XFlush(dpy);
1727 } else if (scr->selected_windows
1728 && WMGetArrayItemCount(scr->selected_windows)) {
1730 if (wwin->flags.selected && scr->selected_windows) {
1731 if (scr->shortcutWindows[index]) {
1732 WMFreeArray(scr->shortcutWindows[index]);
1734 scr->shortcutWindows[index] =
1735 WMDuplicateArray(scr->selected_windows);
1739 break;
1741 case WKBD_SWITCH_SCREEN:
1742 if (wScreenCount > 1) {
1743 WScreen *scr2;
1744 int i;
1746 /* find index of this screen */
1747 for (i = 0; i < wScreenCount; i++) {
1748 if (wScreenWithNumber(i) == scr)
1749 break;
1751 i++;
1752 if (i >= wScreenCount) {
1753 i = 0;
1755 scr2 = wScreenWithNumber(i);
1757 if (scr2) {
1758 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1759 scr2->scr_width/2, scr2->scr_height/2);
1762 break;
1764 case WKBD_NEXTWSLAYER:
1765 case WKBD_PREVWSLAYER:
1767 int row, column;
1769 row = scr->current_workspace/10;
1770 column = scr->current_workspace%10;
1772 if (command==WKBD_NEXTWSLAYER) {
1773 if ((row+1)*10 < scr->workspace_count)
1774 wWorkspaceChange(scr, column+(row+1)*10);
1775 } else {
1776 if (row > 0)
1777 wWorkspaceChange(scr, column+(row-1)*10);
1780 break;
1781 case WKBD_CLIPLOWER:
1782 if (!wPreferences.flags.noclip)
1783 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1784 break;
1785 case WKBD_CLIPRAISE:
1786 if (!wPreferences.flags.noclip)
1787 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1788 break;
1789 case WKBD_CLIPRAISELOWER:
1790 if (!wPreferences.flags.noclip)
1791 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1792 break;
1793 #ifdef KEEP_XKB_LOCK_STATUS
1794 case WKBD_TOGGLE:
1795 if(wPreferences.modelock) {
1796 /*toggle*/
1797 wwin = scr->focused_window;
1799 if (wwin && wwin->flags.mapped
1800 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1801 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1802 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1804 wwin->frame->languagemode = wwin->frame->last_languagemode;
1805 wwin->frame->last_languagemode = staterec.group;
1806 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1810 break;
1811 #endif /* KEEP_XKB_LOCK_STATUS */
1812 #ifdef VIRTUAL_DESKTOP
1813 case WKBD_VDESK_LEFT:
1814 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1815 break;
1817 case WKBD_VDESK_RIGHT:
1818 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1819 break;
1821 case WKBD_VDESK_UP:
1822 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1823 break;
1825 case WKBD_VDESK_DOWN:
1826 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1827 break;
1828 #endif
1834 static void
1835 handleMotionNotify(XEvent *event)
1837 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1839 if (wPreferences.scrollable_menus) {
1840 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1841 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1843 if (scr->flags.jump_back_pending ||
1844 p.x <= (rect.pos.x + 1) ||
1845 p.x >= (rect.pos.x + rect.size.width - 2) ||
1846 p.y <= (rect.pos.y + 1) ||
1847 p.y >= (rect.pos.y + rect.size.height - 2)) {
1848 WMenu *menu;
1849 #ifdef DEBUG
1850 printf("pointer at screen edge\n");
1851 #endif
1852 menu = wMenuUnderPointer(scr);
1853 if (menu!=NULL)
1854 wMenuScroll(menu, event);
1860 static void
1861 handleVisibilityNotify(XEvent *event)
1863 WWindow *wwin;
1865 wwin = wWindowFor(event->xvisibility.window);
1866 if (!wwin)
1867 return;
1868 wwin->flags.obscured =
1869 (event->xvisibility.state == VisibilityFullyObscured);