Lots of cleanups to fvwm-menu-desktop
[fvwm.git] / fvwm / events.c
blob4b06c3275126c33f98f3342aac6ea73130a0e4b9
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 /* This module is based on Twm, but has been siginificantly modified
17 * by Rob Nation
20 * Copyright 1988 by Evans & Sutherland Computer Corporation,
21 * Salt Lake City, Utah
22 * Portions Copyright 1989 by the Massachusetts Institute of Technology
23 * Cambridge, Massachusetts
25 * All Rights Reserved
27 * Permission to use, copy, modify, and distribute this software and
28 * its documentation for any purpose and without fee is hereby
29 * granted, provided that the above copyright notice appear in all
30 * copies and that both that copyright notice and this permis-
31 * sion notice appear in supporting documentation, and that the
32 * names of Evans & Sutherland and M.I.T. not be used in advertising
33 * in publicity pertaining to distribution of the software without
34 * specific, written prior permission.
36 * EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD
37 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
38 * ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND OR
39 * M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM-
40 * AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
41 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
42 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
43 * OR PERFORMANCE OF THIS SOFTWARE.
46 /* ---------------------------- included header files ---------------------- */
48 #include "config.h"
50 #if HAVE_SYS_BSDTYPES_H
51 #include <sys/bsdtypes.h>
52 #endif
54 #include <stdio.h>
55 #include <unistd.h>
56 #include <X11/Xatom.h>
58 #include "libs/ftime.h"
59 #include "libs/fvwmlib.h"
60 #include "libs/System.h"
61 #include "libs/Grab.h"
62 #include "libs/Parse.h"
63 #include "libs/ColorUtils.h"
64 #include "libs/FShape.h"
65 #include "libs/PictureBase.h"
66 #include "libs/Colorset.h"
67 #include "libs/charmap.h"
68 #include "libs/wcontext.h"
69 #include "fvwm.h"
70 #include "externs.h"
71 #include "cursor.h"
72 #include "functions.h"
73 #include "commands.h"
74 #include "bindings.h"
75 #include "misc.h"
76 #include "screen.h"
77 #include "events.h"
78 #include "eventhandler.h"
79 #include "eventmask.h"
80 #include "libs/fvwmsignal.h"
81 #include "module_list.h"
82 #include "module_interface.h"
83 #include "session.h"
84 #include "borders.h"
85 #include "frame.h"
86 #include "add_window.h"
87 #include "icccm2.h"
88 #include "icons.h"
89 #include "gnome.h"
90 #include "ewmh.h"
91 #include "update.h"
92 #include "style.h"
93 #include "stack.h"
94 #include "geometry.h"
95 #include "focus.h"
96 #include "virtual.h"
97 #include "decorations.h"
98 #include "schedule.h"
99 #include "menus.h"
100 #include "colormaps.h"
101 #include "colorset.h"
102 #ifdef HAVE_STROKE
103 #include "stroke.h"
104 #endif /* HAVE_STROKE */
106 /* ---------------------------- local definitions -------------------------- */
108 #ifndef XUrgencyHint
109 #define XUrgencyHint (1L << 8)
110 #endif
112 #define CR_MOVERESIZE_MASK (CWX | CWY | CWWidth | CWHeight | CWBorderWidth)
114 /* ---------------------------- local macros ------------------------------- */
116 /* ---------------------------- imports ------------------------------------ */
118 extern void StartupStuff(void);
120 /* ---------------------------- included code files ------------------------ */
122 /* ---------------------------- local types -------------------------------- */
124 typedef void (*PFEH)(const evh_args_t *ea);
126 typedef struct
128 Window w;
129 Bool do_return_true;
130 Bool do_return_true_cr;
131 unsigned long cr_value_mask;
132 Bool ret_does_match;
133 unsigned long ret_type;
134 } check_if_event_args;
136 typedef struct
138 unsigned do_forbid_function : 1;
139 unsigned do_focus : 1;
140 unsigned do_swallow_click : 1;
141 unsigned do_raise : 1;
142 } hfrc_ret_t;
144 typedef struct event_group
146 int base;
147 int count;
148 PFEH *jump_table;
149 struct event_group *next;
150 } event_group_t;
152 /* ---------------------------- forward declarations ----------------------- */
154 /* ---------------------------- local variables ---------------------------- */
156 static int Button = 0;
157 static const FvwmWindow *xcrossing_last_grab_window = NULL;
158 STROKE_CODE(static int send_motion);
159 STROKE_CODE(static char sequence[STROKE_MAX_SEQUENCE + 1]);
160 static event_group_t *base_event_group = NULL;
162 /* ---------------------------- exported variables (globals) --------------- */
164 int last_event_type = 0;
165 Window PressedW = None;
167 /* ---------------------------- local functions ---------------------------- */
169 static void fake_map_unmap_notify(const FvwmWindow *fw, int event_type)
171 XEvent client_event;
172 XWindowAttributes winattrs = {0};
174 if (!XGetWindowAttributes(dpy, FW_W(fw), &winattrs))
176 return;
178 XSelectInput(
179 dpy, FW_W(fw),
180 winattrs.your_event_mask & ~StructureNotifyMask);
181 client_event.type = event_type;
182 client_event.xmap.display = dpy;
183 client_event.xmap.event = FW_W(fw);
184 client_event.xmap.window = FW_W(fw);
185 switch (event_type)
187 case MapNotify:
188 client_event.xmap.override_redirect = False;
189 break;
190 case UnmapNotify:
191 client_event.xunmap.from_configure = False;
192 break;
193 default:
194 /* not possible if called correctly */
195 break;
197 FSendEvent(
198 dpy, FW_W(fw), False, StructureNotifyMask, &client_event);
199 XSelectInput(dpy, FW_W(fw), winattrs.your_event_mask);
200 XFlush(dpy);
202 return;
205 static Bool test_map_request(
206 Display *display, XEvent *event, XPointer arg)
208 check_if_event_args *cie_args;
209 Bool rc;
211 cie_args = (check_if_event_args *)arg;
212 cie_args->ret_does_match = False;
213 if (event->type == MapRequest &&
214 event->xmaprequest.window == cie_args->w)
216 cie_args->ret_type = MapRequest;
217 cie_args->ret_does_match = True;
218 rc = cie_args->do_return_true;
220 else
222 cie_args->ret_type = 0;
223 rc = False;
226 /* Yes, it is correct that this function always returns False. */
227 return rc;
230 /* Test for ICCCM2 withdraw requests by syntetic events on the root window */
231 static Bool test_withdraw_request(
232 Display *display, XEvent *event, XPointer arg)
234 check_if_event_args *cie_args;
235 Bool rc;
237 cie_args = (check_if_event_args *)arg;
238 cie_args->ret_does_match = False;
239 if (event->type == UnmapNotify &&
240 event->xunmap.window == cie_args->w &&
241 event->xany.send_event == True &&
242 event->xunmap.event == FW_W(&Scr.FvwmRoot))
244 cie_args->ret_type = UnmapNotify;
245 cie_args->ret_does_match = True;
246 rc = cie_args->do_return_true;
248 else
250 cie_args->ret_type = 0;
251 rc = False;
254 return rc;
257 Bool test_button_event(
258 Display *display, XEvent *event, XPointer arg)
260 if (event->type == ButtonPress || event->type == ButtonRelease)
262 return True;
265 return False;
268 Bool test_typed_window_event(
269 Display *display, XEvent *event, XPointer arg)
271 test_typed_window_event_args *ta = (test_typed_window_event_args *)arg;
273 if (event->xany.window == ta->w &&
274 event->xany.type == ta->event_type &&
275 event->xproperty.atom == ta->atom)
277 return True;
280 return False;
283 static Bool test_resizing_event(
284 Display *display, XEvent *event, XPointer arg)
286 check_if_event_args *cie_args;
287 Bool rc;
289 cie_args = (check_if_event_args *)arg;
290 cie_args->ret_does_match = False;
291 if (event->xany.window != cie_args->w)
293 return False;
295 rc = False;
296 switch (event->type)
298 case ConfigureRequest:
299 if ((event->xconfigurerequest.value_mask &
300 cie_args->cr_value_mask) != 0)
302 cie_args->ret_type = ConfigureRequest;
303 cie_args->ret_does_match = True;
304 rc = cie_args->do_return_true_cr;
306 break;
307 case PropertyNotify:
308 if (event->xproperty.atom == XA_WM_NORMAL_HINTS)
310 cie_args->ret_type = PropertyNotify;
311 cie_args->ret_does_match = True;
312 rc = cie_args->do_return_true;
314 default:
315 break;
318 /* Yes, it is correct that this function may always returns False. */
319 return rc;
322 static inline void __handle_cr_on_unmanaged(XConfigureRequestEvent *cre)
324 XWindowChanges xwc;
325 unsigned long xwcm;
327 xwcm = (cre->value_mask & CR_MOVERESIZE_MASK);
328 xwc.x = cre->x;
329 xwc.y = cre->y;
330 xwc.width = cre->width;
331 xwc.height = cre->height;
332 xwc.border_width = cre->border_width;
333 XConfigureWindow(dpy, cre->window, xwcm, &xwc);
335 return;
338 static inline void __handle_cr_on_icon(
339 XConfigureRequestEvent *cre, FvwmWindow *fw)
341 XWindowChanges xwc;
342 unsigned long xwcm;
344 xwcm = (cre->value_mask & CR_MOVERESIZE_MASK);
345 xwc.x = cre->x;
346 xwc.y = cre->y;
347 xwc.width = cre->width;
348 xwc.height = cre->height;
349 xwc.border_width = cre->border_width;
350 if (FW_W_ICON_PIXMAP(fw) == cre->window)
352 int bw;
354 if (cre->value_mask & CWBorderWidth)
356 fw->icon_border_width = cre->border_width;
358 bw = fw->icon_border_width;
359 if ((cre->value_mask & (CWWidth | CWHeight)) ==
360 (CWWidth | CWHeight))
362 set_icon_picture_size(
363 fw, cre->width + 2 * bw, cre->height + 2 * bw);
366 set_icon_position(fw, cre->x, cre->y);
367 broadcast_icon_geometry(fw, False);
368 XConfigureWindow(dpy, cre->window, xwcm, &xwc);
369 if (cre->window != FW_W_ICON_PIXMAP(fw) &&
370 FW_W_ICON_PIXMAP(fw) != None)
372 rectangle g;
374 get_icon_picture_geometry(fw, &g);
375 xwc.x = g.x;
376 xwc.y = g.y;
377 xwcm = cre->value_mask & (CWX | CWY);
378 XConfigureWindow(
379 dpy, FW_W_ICON_PIXMAP(fw), xwcm, &xwc);
381 if (FW_W_ICON_TITLE(fw) != None)
383 rectangle g;
385 get_icon_title_geometry(fw, &g);
386 xwc.x = g.x;
387 xwc.y = g.y;
388 xwcm = cre->value_mask & (CWX | CWY);
389 XConfigureWindow(
390 dpy, FW_W_ICON_TITLE(fw), xwcm, &xwc);
393 return;
396 static inline void __handle_cr_on_shaped(FvwmWindow *fw)
398 /* suppress compiler warnings w/o shape extension */
399 int i = 0;
400 unsigned int u = 0;
401 Bool b = False;
402 int boundingShaped;
404 if (FShapeQueryExtents(
405 dpy, FW_W(fw), &boundingShaped, &i, &i, &u, &u, &b,
406 &i, &i, &u, &u))
408 fw->wShaped = boundingShaped;
410 else
412 fw->wShaped = 0;
415 return;
418 static inline void __handle_cr_restack(
419 int *ret_do_send_event, XConfigureRequestEvent *cre, FvwmWindow *fw)
421 XWindowChanges xwc;
422 unsigned long xwcm;
423 FvwmWindow *fw2 = NULL;
425 if (cre->value_mask & CWSibling)
427 if (XFindContext(
428 dpy, cre->above, FvwmContext,
429 (caddr_t *)&fw2) == XCNOENT)
431 fw2 = NULL;
433 if (fw2 == fw)
435 fw2 = NULL;
438 if (cre->detail != Above && cre->detail != Below)
440 HandleUnusualStackmodes(
441 cre->detail, fw, cre->window, fw2, cre->above);
443 /* only allow clients to restack windows within their layer */
444 else if (fw2 == NULL || compare_window_layers(fw2, fw) != 0)
446 switch (cre->detail)
448 case Above:
449 RaiseWindow(fw, True);
450 break;
451 case Below:
452 LowerWindow(fw, True);
453 break;
456 else
458 xwc.sibling = FW_W_FRAME(fw2);
459 xwc.stack_mode = cre->detail;
460 xwcm = CWSibling | CWStackMode;
461 XConfigureWindow(dpy, FW_W_FRAME(fw), xwcm, &xwc);
463 /* Maintain the condition that icon windows are stacked
464 * immediately below their frame
465 * 1. for fw */
466 xwc.sibling = FW_W_FRAME(fw);
467 xwc.stack_mode = Below;
468 xwcm = CWSibling | CWStackMode;
469 if (FW_W_ICON_TITLE(fw) != None)
471 XConfigureWindow(
472 dpy, FW_W_ICON_TITLE(fw), xwcm, &xwc);
474 if (FW_W_ICON_PIXMAP(fw) != None)
476 XConfigureWindow(
477 dpy, FW_W_ICON_PIXMAP(fw), xwcm, &xwc);
479 /* 2. for fw2 */
480 if (cre->detail == Below)
482 xwc.sibling = FW_W_FRAME(fw2);
483 xwc.stack_mode = Below;
484 xwcm = CWSibling | CWStackMode;
485 if (FW_W_ICON_TITLE(fw2) != None)
487 XConfigureWindow(
488 dpy, FW_W_ICON_TITLE(fw2), xwcm, &xwc);
490 if (FW_W_ICON_PIXMAP(fw2) != None)
492 XConfigureWindow(
493 dpy, FW_W_ICON_PIXMAP(fw2), xwcm,
494 &xwc);
497 /* Maintain the stacking order ring */
498 if (cre->detail == Above)
500 remove_window_from_stack_ring(fw);
501 add_window_to_stack_ring_after(
502 fw, get_prev_window_in_stack_ring(fw2));
504 else /* cre->detail == Below */
506 remove_window_from_stack_ring(fw);
507 add_window_to_stack_ring_after(fw, fw2);
509 BroadcastRestackThisWindow(fw);
511 /* srt (28-Apr-2001): Tk needs a ConfigureNotify event after a
512 * raise, otherwise it would hang for two seconds */
513 *ret_do_send_event = 1;
515 return;
518 static inline void __cr_get_static_position(
519 rectangle *ret_g, FvwmWindow *fw, XConfigureRequestEvent *cre,
520 size_borders *b)
522 if (cre->value_mask & CWX)
524 ret_g->x = cre->x - b->top_left.width;
526 else
528 ret_g->x = fw->g.frame.x;
530 if (cre->value_mask & CWY)
532 ret_g->y = cre->y - b->top_left.height;
534 else
536 ret_g->y = fw->g.frame.y;
539 return;
542 static inline void __cr_get_grav_position(
543 rectangle *ret_g, FvwmWindow *fw, XConfigureRequestEvent *cre,
544 size_borders *b)
546 int grav_x;
547 int grav_y;
549 gravity_get_offsets(fw->hints.win_gravity, &grav_x, &grav_y);
550 if (cre->value_mask & CWX)
552 ret_g->x = cre->x - ((grav_x + 1) * b->total_size.width) / 2;
554 else
556 ret_g->x = fw->g.frame.x;
558 if (cre->value_mask & CWY)
560 ret_g->y = cre->y - ((grav_y + 1) * b->total_size.height) / 2;
562 else
564 ret_g->y = fw->g.frame.y;
567 return;
570 /* Try to detect whether the application uses the ICCCM way of moving its
571 * window or the traditional way, always assuming StaticGravity. */
572 static inline void __cr_detect_icccm_move(
573 FvwmWindow *fw, XConfigureRequestEvent *cre, size_borders *b)
575 rectangle grav_g;
576 rectangle static_g;
577 rectangle dg_g;
578 rectangle ds_g;
579 int mx;
580 int my;
581 int m;
582 int w;
583 int h;
584 int has_x;
585 int has_y;
587 if (CR_MOTION_METHOD(fw) != CR_MOTION_METHOD_AUTO)
589 if (Scr.bo.do_debug_cr_motion_method == 1)
591 fprintf(
592 stderr,
593 "_cdim: --- already detected (pid %d) %p"
594 " '%s'\n", HAS_EWMH_WM_PID(fw), fw,
595 fw->visible_name);
597 return;
599 if (HAS_EWMH_WM_PID(fw))
601 if (Scr.bo.do_debug_cr_motion_method == 1)
603 fprintf(
604 stderr,"_cdim: +++ has ewmh_wm_pid: icccm"
605 " %p '%s'\n", fw, fw->visible_name);
607 SET_CR_MOTION_METHOD(fw, CR_MOTION_METHOD_USE_GRAV);
608 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
609 return;
611 if (fw->ewmh_window_type != EWMH_WINDOW_TYPE_NONE_ID)
613 if (Scr.bo.do_debug_cr_motion_method == 1)
615 fprintf(
616 stderr, "_cdim: +++ has ewmh_window_type:"
617 " icccm %p '%s'\n", fw,
618 fw->visible_name);
620 SET_CR_MOTION_METHOD(fw, CR_MOTION_METHOD_USE_GRAV);
621 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
622 return;
624 if (FShapesSupported && fw->wShaped)
626 if (Scr.bo.do_debug_cr_motion_method == 1)
628 fprintf(
629 stderr, "_cdim: --- shaped window %p "
630 "'%s'\n", fw, fw->visible_name);
632 /* no detection for shaped windows */
633 return;
635 if (fw->hints.win_gravity == StaticGravity)
637 if (Scr.bo.do_debug_cr_motion_method == 1)
639 fprintf(
640 stderr, "_cdim: --- using StaticGravity"
641 " %p '%s'\n", fw, fw->visible_name);
643 return;
645 has_x = (cre->value_mask & CWX);
646 has_y = (cre->value_mask & CWY);
647 if (!has_x && !has_y)
649 if (Scr.bo.do_debug_cr_motion_method == 1)
651 fprintf(
652 stderr, "_cdim: --- not moved %p '%s'\n",
653 fw, fw->visible_name);
655 return;
657 __cr_get_grav_position(&grav_g, fw, cre, b);
658 __cr_get_static_position(&static_g, fw, cre, b);
659 if (static_g.x == grav_g.x)
661 /* both methods have the same result; ignore */
662 has_x = 0;
664 if (static_g.y == grav_g.y)
666 /* both methods have the same result; ignore */
667 has_y = 0;
669 if (!has_x && !has_y)
671 if (Scr.bo.do_debug_cr_motion_method == 1)
673 fprintf(
674 stderr, "_cdim: --- not moved %p '%s'\n",
675 fw, fw->visible_name);
677 return;
679 dg_g.x = grav_g.x - fw->g.frame.x;
680 dg_g.y = grav_g.y - fw->g.frame.y;
681 ds_g.x = static_g.x - fw->g.frame.x;
682 ds_g.y = static_g.y - fw->g.frame.y;
683 if (Scr.bo.do_debug_cr_motion_method == 1)
685 fprintf(
686 stderr, "s %3d/%3d %2d/%2d, g %3d/%3d %2d/%2d: ",
687 static_g.x, static_g.y, ds_g.x, ds_g.y, grav_g.x,
688 grav_g.y, dg_g.x, dg_g.y);
690 /* check full screen */
691 if ((cre->value_mask & (CWX | CWY)) == (CWX | CWY) &&
692 (has_x || has_y) &&
693 cre->width == Scr.MyDisplayWidth &&
694 cre->height == Scr.MyDisplayHeight)
696 if (grav_g.x == -b->top_left.width &&
697 grav_g.y == -b->top_left.height)
699 /* Window is fullscreen using the ICCCM way. */
700 SET_CR_MOTION_METHOD(fw, CR_MOTION_METHOD_USE_GRAV);
701 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
702 if (Scr.bo.do_debug_cr_motion_method == 1)
704 fprintf(
705 stderr, "+++ fullscreen icccm %p"
706 " '%s'\n", fw, fw->visible_name);
708 return;
710 else if (static_g.x == -b->top_left.width &&
711 static_g.y == -b->top_left.height)
713 /* Window is fullscreen using the traditional way. */
714 SET_CR_MOTION_METHOD(fw, CR_MOTION_METHOD_STATIC_GRAV);
715 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
716 if (Scr.bo.do_debug_cr_motion_method == 1)
718 fprintf(
719 stderr, "+++ fullscreen traditional"
720 " %p '%s'\n", fw,
721 fw->visible_name);
723 return;
726 /* check travelling across the screen */
727 if (has_x && dg_g.x == 0 && ds_g.x != 0 &&
728 has_y && dg_g.y == 0 && ds_g.y != 0)
730 /* The traditional way causes a shift by the border width or
731 * height. Use ICCCM way. */
732 SET_CR_MOTION_METHOD(fw, CR_MOTION_METHOD_USE_GRAV);
733 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
734 if (Scr.bo.do_debug_cr_motion_method == 1)
736 fprintf(
737 stderr, "+++ travelling icccm %p '%s'\n",
738 fw, fw->visible_name);
740 return;
742 if (has_x && dg_g.x != 0 && ds_g.x == 0 &&
743 has_y && dg_g.y != 0 && ds_g.y == 0)
745 /* The ICCCM way causes a shift by the border width or height.
746 * Use traditional way. */
747 SET_CR_MOTION_METHOD(fw, CR_MOTION_METHOD_STATIC_GRAV);
748 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
749 if (Scr.bo.do_debug_cr_motion_method == 1)
751 fprintf(
752 stderr, "+++ travelling traditional %p"
753 " '%s'\n", fw, fw->visible_name);
755 return;
757 /* check placement near border */
758 w = (cre->value_mask & CWWidth) ?
759 cre->width + b->total_size.width : fw->g.frame.width;
760 h = (cre->value_mask & CWHeight) ?
761 cre->height + b->total_size.height : fw->g.frame.height;
762 if (!has_x)
764 mx = CR_MOTION_METHOD_AUTO;
766 else if (static_g.x == 0 || static_g.x + w == Scr.MyDisplayWidth)
768 mx = CR_MOTION_METHOD_STATIC_GRAV;
770 else if (grav_g.x == 0 || grav_g.x + w == Scr.MyDisplayWidth)
772 mx = CR_MOTION_METHOD_USE_GRAV;
774 else
776 mx = CR_MOTION_METHOD_AUTO;
778 if (!has_y)
780 my = CR_MOTION_METHOD_AUTO;
782 else if (static_g.y == 0 || static_g.y + h == Scr.MyDisplayHeight)
784 my = CR_MOTION_METHOD_STATIC_GRAV;
786 else if (grav_g.y == 0 || grav_g.y + h == Scr.MyDisplayHeight)
788 my = CR_MOTION_METHOD_USE_GRAV;
790 else
792 my = CR_MOTION_METHOD_AUTO;
794 m = (mx != CR_MOTION_METHOD_AUTO) ? mx : my;
795 if (m != CR_MOTION_METHOD_AUTO)
797 /* Window was placed next to the display border. */
798 if (m == my || my == CR_MOTION_METHOD_AUTO)
800 SET_CR_MOTION_METHOD(fw, m);
801 SET_CR_MOTION_METHOD_DETECTED(fw, 1);
802 if (Scr.bo.do_debug_cr_motion_method == 1)
804 fprintf(
805 stderr, "+++ near border %s %p "
806 "'%s'\n", (m ==
807 CR_MOTION_METHOD_USE_GRAV)
808 ? "icccm" : "traditional", fw,
809 fw->visible_name);
811 return;
814 if (Scr.bo.do_debug_cr_motion_method == 1)
816 fprintf(
817 stderr, "--- not detected %p '%s'\n", fw,
818 fw->visible_name);
821 return;
824 #define EXPERIMENTAL_ANTI_RACE_CONDITION_CODE
825 /* This is not a good idea because this interferes with changes in the size
826 * hints of the window. However, it is impossible to be completely safe here.
827 * For example, if the client changes the size inc, then resizes the size of
828 * its window and then changes the size inc again - all in one batch - then
829 * the WM will read the *second* size inc upon the *first* event and use the
830 * wrong one in the ConfigureRequest calculations. */
831 /* dv (31 Mar 2002): The code now handles these situations, so enable it
832 * again. */
833 #ifdef EXPERIMENTAL_ANTI_RACE_CONDITION_CODE
834 static inline int __merge_cr_moveresize(
835 const evh_args_t *ea, XConfigureRequestEvent *cre, FvwmWindow *fw,
836 size_borders *b)
838 int cn_count = 0;
839 XEvent e;
840 XConfigureRequestEvent *ecre;
841 check_if_event_args args;
843 args.w = cre->window;
844 args.do_return_true = False;
845 args.do_return_true_cr = True;
846 args.cr_value_mask = CR_MOVERESIZE_MASK;
847 args.ret_does_match = False;
848 args.ret_type = 0;
850 for (cn_count = 0; 1; )
852 unsigned long vma;
853 unsigned long vmo;
854 unsigned long xm;
855 unsigned long ym;
856 evh_args_t ea2;
857 exec_context_changes_t ecc;
859 FCheckPeekIfEvent(
860 dpy, &e, test_resizing_event, (XPointer)&args);
861 ecre = &e.xconfigurerequest;
862 if (args.ret_does_match == False)
864 break;
866 else if (args.ret_type == PropertyNotify)
868 /* Can't merge events with a PropertyNotify in
869 * between. The event is still on the queue. */
870 break;
872 else if (args.ret_type != ConfigureRequest)
874 /* not good. unselected event type! */
875 continue;
877 /* Event was not yet removed from the queue but stored in e. */
878 xm = CWX | CWWidth;
879 ym = CWY | CWHeight;
880 vma = cre->value_mask & ecre->value_mask;
881 vmo = cre->value_mask | ecre->value_mask;
882 if (((vma & xm) == 0 && (vmo & xm) == xm) ||
883 ((vma & ym) == 0 && (vmo & ym) == ym))
885 /* can't merge events since location of window might
886 * get screwed up. */
887 break;
889 /* Finally remove the event from the queue */
890 FCheckIfEvent(dpy, &e, test_resizing_event, (XPointer)&args);
891 /* partially handle the event */
892 ecre->value_mask &= ~args.cr_value_mask;
893 ea2.exc = exc_clone_context(ea->exc, &ecc, ECC_ETRIGGER);
894 HandleConfigureRequest(&ea2);
895 exc_destroy_context(ea2.exc);
896 /* collect the size/position changes */
897 if (ecre->value_mask & CWX)
899 cre->x = ecre->x;
901 if (ecre->value_mask & CWY)
903 cre->y = ecre->y;
905 if (ecre->value_mask & CWWidth)
907 cre->width = ecre->width;
909 if (ecre->value_mask & CWHeight)
911 cre->height = ecre->height;
913 if (ecre->value_mask & CWBorderWidth)
915 cre->border_width = ecre->border_width;
917 cre->value_mask |= (ecre->value_mask & CR_MOVERESIZE_MASK);
918 cn_count++;
921 return cn_count;
923 #endif
925 static inline int __handle_cr_on_client(
926 int *ret_do_send_event, XConfigureRequestEvent cre,
927 const evh_args_t *ea, FvwmWindow *fw, Bool force, int force_gravity)
929 rectangle current_g;
930 rectangle new_g;
931 rectangle d_g;
932 size_rect constr_dim;
933 size_rect oldnew_dim;
934 size_borders b;
935 int cn_count = 0;
936 int gravity;
938 if (ea)
940 cre = ea->exc->x.etrigger->xconfigurerequest;
942 if ((cre.value_mask & (CWWidth | CWHeight | CWX | CWY)) == 0)
944 return 0;
947 get_window_borders(fw, &b);
948 #ifdef EXPERIMENTAL_ANTI_RACE_CONDITION_CODE
949 /* Merge all pending ConfigureRequests for the window into a single
950 * event. However, we can not do this if the window uses the motion
951 * method autodetection because the merged event might confuse the
952 * detection code. */
953 if (ea && CR_MOTION_METHOD(fw) != CR_MOTION_METHOD_AUTO)
955 cn_count = __merge_cr_moveresize(ea, &cre, fw, &b);
957 #endif
958 #if 0
959 fprintf(stderr,
960 "cre: %d(%d) %d(%d) %d(%d)x%d(%d) fw 0x%08x w 0x%08x "
961 "ew 0x%08x '%s'\n",
962 cre.x, (int)(cre.value_mask & CWX),
963 cre.y, (int)(cre.value_mask & CWY),
964 cre.width, (int)(cre.value_mask & CWWidth),
965 cre.height, (int)(cre.value_mask & CWHeight),
966 (int)FW_W_FRAME(fw), (int)FW_W(fw), (int)cre.window,
967 (fw->name.name) ? fw->name.name : "");
968 #endif
969 /* Don't modify frame_g fields before calling SetupWindow! */
970 memset(&d_g, 0, sizeof(d_g));
972 if (HAS_NEW_WM_NORMAL_HINTS(fw))
974 /* get the latest size hints */
975 XSync(dpy, 0);
976 GetWindowSizeHints(fw);
977 SET_HAS_NEW_WM_NORMAL_HINTS(fw, 0);
979 if (!HAS_OVERRIDE_SIZE_HINTS(fw) && (fw->hints.flags & PMaxSize))
981 /* Java workaround */
982 if (cre.height > fw->hints.max_height &&
983 fw->hints.max_height <= BROKEN_MAXSIZE_LIMIT)
985 fw->hints.max_height = DEFAULT_MAX_MAX_WINDOW_HEIGHT;
986 cre.value_mask |= CWHeight;
988 if (cre.width > fw->hints.max_width &&
989 fw->hints.max_width <= BROKEN_MAXSIZE_LIMIT)
991 fw->hints.max_width = DEFAULT_MAX_MAX_WINDOW_WIDTH;
992 cre.value_mask |= CWWidth;
995 if (!HAS_OVERRIDE_SIZE_HINTS(fw) && (fw->hints.flags & PMinSize))
997 if (cre.width < fw->hints.min_width &&
998 fw->hints.min_width >= BROKEN_MINSIZE_LIMIT)
1000 fw->hints.min_width = 1;
1001 cre.value_mask |= CWWidth;
1003 if (cre.height < fw->hints.min_height &&
1004 fw->hints.min_height >= BROKEN_MINSIZE_LIMIT)
1006 fw->hints.min_height = 1;
1007 cre.value_mask |= CWHeight;
1010 if (IS_SHADED(fw) ||
1011 !is_function_allowed(F_MOVE, NULL, fw, RQORIG_PROGRAM, False))
1013 /* forbid shaded applications to move their windows */
1014 cre.value_mask &= ~(CWX | CWY);
1015 /* resend the old geometry */
1016 *ret_do_send_event = 1;
1018 if (IS_MAXIMIZED(fw))
1020 /* dont allow clients to resize maximized windows */
1021 cre.value_mask &= ~(CWWidth | CWHeight);
1022 /* resend the old geometry */
1023 *ret_do_send_event = 1;
1024 d_g.width = 0;
1025 d_g.height = 0;
1027 else if (
1028 !is_function_allowed(
1029 F_RESIZE, NULL, fw, RQORIG_PROGRAM, False))
1031 cre.value_mask &= ~(CWWidth | CWHeight);
1032 *ret_do_send_event = 1;
1035 if (cre.value_mask & CWBorderWidth)
1037 /* for restoring */
1038 fw->attr_backup.border_width = cre.border_width;
1040 if (!force && CR_MOTION_METHOD(fw) == CR_MOTION_METHOD_AUTO)
1042 __cr_detect_icccm_move(fw, &cre, &b);
1044 if (force_gravity > ForgetGravity && force_gravity <= StaticGravity)
1046 gravity = force_gravity;
1048 else
1050 gravity = fw->hints.win_gravity;
1052 if (IS_SHADED(fw))
1054 direction_t gravity_dir;
1056 get_unshaded_geometry(fw, &current_g);
1057 /* the shade direction overrides the window's gravity */
1058 gravity_dir = gravity_grav_to_dir(gravity);
1059 gravity_dir = gravity_override_dir(
1060 gravity_dir, SHADED_DIR(fw));
1061 gravity = gravity_dir_to_grav(gravity_dir);
1063 else
1065 current_g = fw->g.frame;
1067 if (!(cre.value_mask & (CWX | CWY)))
1069 /* nothing */
1071 else if ((force ||
1072 CR_MOTION_METHOD(fw) == CR_MOTION_METHOD_USE_GRAV) &&
1073 gravity != StaticGravity)
1075 int ref_x;
1076 int ref_y;
1077 int grav_x;
1078 int grav_y;
1080 gravity_get_offsets(gravity, &grav_x, &grav_y);
1081 if (cre.value_mask & CWX)
1083 ref_x = cre.x -
1084 ((grav_x + 1) * b.total_size.width) / 2;
1085 d_g.x = ref_x - current_g.x;
1087 if (cre.value_mask & CWY)
1089 ref_y = cre.y -
1090 ((grav_y + 1) * b.total_size.height) / 2;
1091 d_g.y = ref_y - current_g.y;
1094 else /* ..._USE_GRAV or ..._AUTO */
1096 /* default: traditional cr handling */
1097 if (cre.value_mask & CWX)
1099 d_g.x = cre.x - current_g.x - b.top_left.width;
1101 if (cre.value_mask & CWY)
1103 d_g.y = cre.y - current_g.y - b.top_left.height;
1107 if (cre.value_mask & CWHeight)
1109 if (cre.height <
1110 (WINDOW_FREAKED_OUT_SIZE - b.total_size.height))
1112 d_g.height = cre.height -
1113 (current_g.height - b.total_size.height);
1115 else
1117 /* Ignore height changes to astronomically large
1118 * windows (needed for XEmacs 20.4); don't care if the
1119 * window is shaded here - we won't use 'height' in
1120 * this case anyway.
1121 * Inform the buggy app about the size that *we* want
1123 d_g.height = 0;
1124 *ret_do_send_event = 1;
1127 if (cre.value_mask & CWWidth)
1129 if (cre.width < (WINDOW_FREAKED_OUT_SIZE - b.total_size.width))
1131 d_g.width = cre.width -
1132 (current_g.width - b.total_size.width);
1134 else
1136 d_g.width = 0;
1137 *ret_do_send_event = 1;
1141 /* SetupWindow (x,y) are the location of the upper-left outer corner
1142 * and are passed directly to XMoveResizeWindow (frame). The
1143 * (width,height) are the inner size of the frame. The inner width is
1144 * the same as the requested client window width; the inner height is
1145 * the same as the requested client window height plus any title bar
1146 * slop. */
1147 new_g = current_g;
1148 oldnew_dim.width = new_g.width + d_g.width;
1149 oldnew_dim.height = new_g.height + d_g.height;
1150 constr_dim.width = oldnew_dim.width;
1151 constr_dim.height = oldnew_dim.height;
1152 constrain_size(
1153 fw, NULL, &constr_dim.width, &constr_dim.height, 0, 0,
1154 CS_UPDATE_MAX_DEFECT);
1155 d_g.width += (constr_dim.width - oldnew_dim.width);
1156 d_g.height += (constr_dim.height - oldnew_dim.height);
1157 if ((cre.value_mask & CWX) && d_g.width)
1159 new_g.x = current_g.x + d_g.x;
1160 new_g.width = current_g.width + d_g.width;
1162 else if ((cre.value_mask & CWX) && !d_g.width)
1164 new_g.x = current_g.x + d_g.x;
1166 else if (!(cre.value_mask & CWX) && d_g.width)
1168 gravity_resize(gravity, &new_g, d_g.width, 0);
1170 if ((cre.value_mask & CWY) && d_g.height)
1172 new_g.y = current_g.y + d_g.y;
1173 new_g.height = current_g.height + d_g.height;
1175 else if ((cre.value_mask & CWY) && !d_g.height)
1177 new_g.y = current_g.y + d_g.y;
1179 else if (!(cre.value_mask & CWY) && d_g.height)
1181 gravity_resize(gravity, &new_g, 0, d_g.height);
1184 if (new_g.x == current_g.x && new_g.y == current_g.y &&
1185 new_g.width == current_g.width &&
1186 new_g.height == current_g.height)
1188 /* Window will not be moved or resized; send a synthetic
1189 * ConfigureNotify. */
1190 *ret_do_send_event = 1;
1192 else if ((cre.value_mask & CWX) || (cre.value_mask & CWY) ||
1193 d_g.width || d_g.height)
1195 if (IS_SHADED(fw))
1197 fw->g.normal = new_g;
1198 get_shaded_geometry(fw, &new_g, &new_g);
1200 frame_setup_window_app_request(
1201 fw, new_g.x, new_g.y, new_g.width, new_g.height,
1202 False);
1203 /* make sure the window structure has the new position */
1204 update_absolute_geometry(fw);
1205 maximize_adjust_offset(fw);
1206 GNOME_SetWinArea(fw);
1208 else if (DO_FORCE_NEXT_CR(fw))
1210 *ret_do_send_event = 1;
1212 SET_FORCE_NEXT_CR(fw, 0);
1213 SET_FORCE_NEXT_PN(fw, 0);
1215 return cn_count;
1218 void __handle_configure_request(
1219 XConfigureRequestEvent cre, const evh_args_t *ea, FvwmWindow *fw,
1220 Bool force, int force_gravity)
1222 int do_send_event = 0;
1223 int cn_count = 0;
1225 /* According to the July 27, 1988 ICCCM draft, we should ignore size
1226 * and position fields in the WM_NORMAL_HINTS property when we map a
1227 * window. Instead, we'll read the current geometry. Therefore, we
1228 * should respond to configuration requests for windows which have
1229 * never been mapped. */
1230 if (fw == NULL)
1232 __handle_cr_on_unmanaged(&cre);
1233 return;
1235 if (cre.window == FW_W_ICON_TITLE(fw) ||
1236 cre.window == FW_W_ICON_PIXMAP(fw))
1238 __handle_cr_on_icon(&cre, fw);
1240 if (FShapesSupported)
1242 __handle_cr_on_shaped(fw);
1244 if (fw != NULL && cre.window == FW_W(fw))
1246 cn_count = __handle_cr_on_client(
1247 &do_send_event, cre, ea, fw, force, force_gravity);
1249 /* Stacking order change requested. Handle this *after* geometry
1250 * changes, since we need the new geometry in occlusion calculations */
1251 if ((cre.value_mask & CWStackMode) &&
1252 (!DO_IGNORE_RESTACK(fw) || force))
1254 __handle_cr_restack(&do_send_event, &cre, fw);
1256 #if 1
1257 /* This causes some ddd windows not to be drawn properly. Reverted back
1258 * to the old method in frame_setup_window. */
1259 /* domivogt (15-Oct-1999): enabled this to work around buggy apps that
1260 * ask for a nonsense height and expect that they really get it. */
1261 if (cn_count == 0 && do_send_event)
1263 cn_count = 1;
1265 else if (cn_count > 0)
1267 do_send_event = 1;
1269 for ( ; cn_count > 0; cn_count--)
1271 SendConfigureNotify(
1272 fw, fw->g.frame.x, fw->g.frame.y, fw->g.frame.width,
1273 fw->g.frame.height, 0, True);
1275 if (do_send_event)
1277 XFlush(dpy);
1279 #endif
1281 return;
1284 static Bool __predicate_button_click(
1285 Display *display, XEvent *event, XPointer arg)
1287 if (event->type == ButtonPress || event->type == ButtonRelease)
1289 return True;
1292 return False;
1295 /* Helper function for __handle_focus_raise_click(). */
1296 static Bool __test_for_motion(int x0, int y0)
1298 int x;
1299 int y;
1300 unsigned int mask;
1301 XEvent e;
1303 /* Query the pointer to do this. We can't check for events here since
1304 * the events are still needed if the pointer moves. */
1306 /* However, some special mouse (e.g., a touchpad with the
1307 * synaptic driver) may handle a double click in a special way
1308 * (for dragging through short touching and holding down the
1309 * finger on the touchpad). Bascially, when you execute a
1310 * double click the first button release is queued after the
1311 * second _physical_ mouse release happen. It seems that
1312 * FQueryPointer may not work as expected: it does not see
1313 * that the button is released on a double click. So, we need
1314 * to check for a button press in the future to avoid a fvwm
1315 * lockup! (olicha 2004-01-31) */
1317 for (x = x0, y = y0; FQueryPointer(
1318 dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY,
1319 &x, &y, &mask) == True; usleep(20000))
1321 if ((mask & DEFAULT_ALL_BUTTONS_MASK) == 0)
1323 /* all buttons are released */
1324 return False;
1326 else if (abs(x - x0) >= Scr.MoveThreshold ||
1327 abs(y - y0) >= Scr.MoveThreshold)
1329 /* the pointer has moved */
1330 return True;
1332 if (FCheckPeekIfEvent(dpy, &e, __predicate_button_click, NULL))
1334 /* click in the future */
1335 return False;
1337 else
1339 /* The predicate procedure finds no match, no event
1340 * has been removed from the queue and XFlush was
1341 * called. Nothing to do */
1345 /* pointer has moved off screen */
1346 return True;
1349 /* Helper function for __handle_focus_raise_click(). */
1350 static void __check_click_to_focus_or_raise(
1351 hfrc_ret_t *ret_args, const exec_context_t *exc)
1353 FvwmWindow * const fw = exc->w.fw;
1354 const XEvent *te = exc->x.etrigger;
1355 struct
1357 unsigned is_client_click : 1;
1358 unsigned is_focused : 1;
1359 } f;
1361 f.is_focused = !!focus_is_focused(fw);
1362 f.is_client_click = (exc->w.wcontext == C_WINDOW ||
1363 exc->w.wcontext == C_EWMH_DESKTOP);
1364 /* check if we need to raise and/or focus the window */
1365 ret_args->do_focus = focus_query_click_to_focus(fw, exc->w.wcontext);
1366 if (f.is_client_click && !ret_args->do_focus &&
1367 !f.is_focused && FP_DO_FOCUS_BY_PROGRAM(FW_FOCUS_POLICY(fw)) &&
1368 !fpol_query_allow_user_focus(&FW_FOCUS_POLICY(fw)))
1370 /* Give the window a chance to to take focus itself */
1371 ret_args->do_focus = 1;
1373 if (ret_args->do_focus && focus_is_focused(fw))
1375 ret_args->do_focus = 0;
1377 ret_args->do_raise =
1378 focus_query_click_to_raise(fw, f.is_focused, exc->w.wcontext);
1379 #define EXPERIMENTAL_ROU_HANDLING_V2
1380 #ifdef EXPERIMENTAL_ROU_HANDLING_V2
1381 /* RBW -- Dang! This works without the one in HandleEnterNotify! */
1382 if (ret_args->do_raise && is_on_top_of_layer_and_above_unmanaged(fw))
1383 #else
1384 if (ret_args->do_raise && is_on_top_of_layer(fw))
1385 #endif
1387 ret_args->do_raise = 0;
1389 if ((ret_args->do_focus &&
1390 FP_DO_IGNORE_FOCUS_CLICK_MOTION(FW_FOCUS_POLICY(fw))) ||
1391 (ret_args->do_raise &&
1392 FP_DO_IGNORE_RAISE_CLICK_MOTION(FW_FOCUS_POLICY(fw))))
1394 /* Pass further events to the application and check if a button
1395 * release or motion event occurs next. If we don't do this
1396 * here, the pointer will seem to be frozen in
1397 * __test_for_motion(). */
1398 XAllowEvents(dpy, ReplayPointer, CurrentTime);
1399 if (__test_for_motion(te->xbutton.x_root, te->xbutton.y_root))
1401 /* the pointer was moved, process event normally */
1402 ret_args->do_focus = 0;
1403 ret_args->do_raise = 0;
1406 if (ret_args->do_focus || ret_args->do_raise)
1408 if (!((ret_args->do_focus &&
1409 FP_DO_ALLOW_FUNC_FOCUS_CLICK(FW_FOCUS_POLICY(fw))) ||
1410 (ret_args->do_raise &&
1411 FP_DO_ALLOW_FUNC_RAISE_CLICK(FW_FOCUS_POLICY(fw)))))
1413 ret_args->do_forbid_function = 1;
1415 if (!((ret_args->do_focus &&
1416 FP_DO_PASS_FOCUS_CLICK(FW_FOCUS_POLICY(fw))) ||
1417 (ret_args->do_raise &&
1418 FP_DO_PASS_RAISE_CLICK(FW_FOCUS_POLICY(fw)))))
1420 ret_args->do_swallow_click = 1;
1424 return;
1427 /* Finds out if the click on a window must be used to focus or raise it. */
1428 static void __handle_focus_raise_click(
1429 hfrc_ret_t *ret_args, const exec_context_t *exc)
1431 memset(ret_args, 0, sizeof(*ret_args));
1432 if (exc->w.fw == NULL)
1434 return;
1436 /* check for proper click button and modifiers*/
1437 if (FP_USE_MOUSE_BUTTONS(FW_FOCUS_POLICY(exc->w.fw)) != 0 &&
1438 !(FP_USE_MOUSE_BUTTONS(FW_FOCUS_POLICY(exc->w.fw)) &
1439 (1 << (exc->x.etrigger->xbutton.button - 1))))
1441 /* wrong button, handle click normally */
1442 return;
1444 else if (FP_USE_MODIFIERS(FW_FOCUS_POLICY(exc->w.fw)) !=
1445 FPOL_ANY_MODIFIER &&
1446 MaskUsedModifiers(
1447 FP_USE_MODIFIERS(FW_FOCUS_POLICY(exc->w.fw))) !=
1448 MaskUsedModifiers(exc->x.etrigger->xbutton.state))
1450 /* right button but wrong modifiers, handle click normally */
1451 return;
1453 else
1455 __check_click_to_focus_or_raise(ret_args, exc);
1458 return;
1461 /* Helper function for HandleButtonPress */
1462 static Bool __is_bpress_window_handled(const exec_context_t *exc)
1464 Window eventw;
1465 const XEvent *te = exc->x.etrigger;
1467 if (exc->w.fw == NULL)
1469 if ((te->xbutton.window != Scr.Root ||
1470 te->xbutton.subwindow != None) &&
1471 !is_pan_frame(te->xbutton.window))
1473 /* Ignore events in unmanaged windows or subwindows of
1474 * a client */
1475 return False;
1477 else
1479 return True;
1482 eventw = (te->xbutton.subwindow != None &&
1483 te->xany.window != FW_W(exc->w.fw)) ?
1484 te->xbutton.subwindow : te->xany.window;
1485 if (is_frame_hide_window(eventw) || eventw == FW_W_FRAME(exc->w.fw))
1487 return False;
1489 if (!XGetGeometry(
1490 dpy, eventw, &JunkRoot, &JunkX, &JunkY,
1491 (unsigned int*)&JunkWidth, (unsigned int*)&JunkHeight,
1492 (unsigned int*)&JunkBW, (unsigned int*)&JunkDepth))
1494 /* The window has already died. */
1495 return False;
1498 return True;
1501 /* Helper function for __handle_bpress_on_managed */
1502 static Bool __handle_click_to_focus(const exec_context_t *exc)
1504 fpol_set_focus_by_t set_by;
1506 switch (exc->w.wcontext)
1508 case C_WINDOW:
1509 case C_EWMH_DESKTOP:
1510 set_by = FOCUS_SET_BY_CLICK_CLIENT;
1511 break;
1512 case C_ICON:
1513 set_by = FOCUS_SET_BY_CLICK_ICON;
1514 break;
1515 default:
1516 set_by = FOCUS_SET_BY_CLICK_DECOR;
1517 break;
1519 SetFocusWindow(exc->w.fw, True, set_by);
1520 focus_grab_buttons(exc->w.fw);
1521 if (focus_is_focused(exc->w.fw) && !IS_ICONIFIED(exc->w.fw))
1523 border_draw_decorations(
1524 exc->w.fw, PART_ALL, True, True, CLEAR_ALL, NULL,
1525 NULL);
1528 return focus_is_focused(exc->w.fw);
1531 /* Helper function for __handle_bpress_on_managed */
1532 static Bool __handle_click_to_raise(const exec_context_t *exc)
1534 Bool rc = False;
1535 int is_focused;
1537 is_focused = focus_is_focused(exc->w.fw);
1538 if (focus_query_click_to_raise(exc->w.fw, is_focused, True))
1540 rc = True;
1543 return rc;
1546 /* Helper function for HandleButtonPress */
1547 static void __handle_bpress_stroke(void)
1549 STROKE_CODE(stroke_init());
1550 STROKE_CODE(send_motion = True);
1552 return;
1555 /* Helper function for __handle_bpress_on_managed */
1556 static Bool __handle_bpress_action(
1557 const exec_context_t *exc, char *action)
1559 window_parts part;
1560 Bool do_force;
1561 Bool rc = False;
1563 if (!action || *action == 0)
1565 PressedW = None;
1566 return False;
1568 /* draw pressed in decorations */
1569 part = border_context_to_parts(exc->w.wcontext);
1570 do_force = (part & PART_TITLEBAR) ? True : False;
1571 border_draw_decorations(
1572 exc->w.fw, part, (Scr.Hilite == exc->w.fw), do_force,
1573 CLEAR_ALL, NULL, NULL);
1574 /* execute the action */
1575 if (IS_ICONIFIED(exc->w.fw))
1577 /* release the pointer since it can't do harm over an icon */
1578 XAllowEvents(dpy, AsyncPointer, CurrentTime);
1580 execute_function(NULL, exc, action, 0);
1581 if (exc->w.wcontext != C_WINDOW && exc->w.wcontext != C_NO_CONTEXT)
1583 WaitForButtonsUp(True);
1584 rc = True;
1586 /* redraw decorations */
1587 PressedW = None;
1588 if (check_if_fvwm_window_exists(exc->w.fw))
1590 part = border_context_to_parts(exc->w.wcontext);
1591 do_force = (part & PART_TITLEBAR) ? True : False;
1592 border_draw_decorations(
1593 exc->w.fw, part, (Scr.Hilite == exc->w.fw), do_force,
1594 CLEAR_ALL, NULL, NULL);
1597 return rc;
1600 /* Handles button presses on the root window. */
1601 static void __handle_bpress_on_root(const exec_context_t *exc)
1603 char *action;
1605 PressedW = None;
1606 __handle_bpress_stroke();
1607 /* search for an appropriate mouse binding */
1608 action = CheckBinding(
1609 Scr.AllBindings, STROKE_ARG(0) exc->x.etrigger->xbutton.button,
1610 exc->x.etrigger->xbutton.state, GetUnusedModifiers(), C_ROOT,
1611 BIND_BUTTONPRESS, NULL, NULL);
1612 if (action && *action)
1614 const exec_context_t *exc2;
1615 exec_context_changes_t ecc;
1617 ecc.w.wcontext = C_ROOT;
1618 exc2 = exc_clone_context(exc, &ecc, ECC_WCONTEXT);
1619 execute_function(NULL, exc2, action, 0);
1620 exc_destroy_context(exc2);
1621 WaitForButtonsUp(True);
1623 else
1625 /* do gnome buttonpress forwarding if win == root */
1626 GNOME_ProxyButtonEvent(exc->x.etrigger);
1629 return;
1632 /* Handles button presses on unmanaged windows */
1633 static void __handle_bpress_on_unmanaged(const exec_context_t *exc)
1635 /* Pass the event to the application. */
1636 XAllowEvents(dpy, ReplayPointer, CurrentTime);
1637 XFlush(dpy);
1639 return;
1642 /* Handles button presses on managed windows */
1643 static void __handle_bpress_on_managed(const exec_context_t *exc)
1645 char *action;
1646 hfrc_ret_t f;
1647 FvwmWindow * const fw = exc->w.fw;
1648 XEvent *e;
1650 e = exc->x.etrigger;
1651 /* Now handle click to focus and click to raise. */
1652 __handle_focus_raise_click(&f, exc);
1653 PressedW = (f.do_forbid_function) ? None : exc->w.w;
1654 if (f.do_focus)
1656 if (!__handle_click_to_focus(exc))
1658 /* Window didn't accept the focus; pass the click to
1659 * the application. */
1660 f.do_swallow_click = 0;
1663 if (f.do_raise)
1665 if (__handle_click_to_raise(exc) == True)
1667 /* We can't raise the window immediately because the
1668 * action bound to the click might be "Lower" or
1669 * "RaiseLower". So mark the window as scheduled to be
1670 * raised after the binding is executed. Functions that
1671 * modify the stacking order will reset this flag. */
1672 SET_SCHEDULED_FOR_RAISE(fw, 1);
1675 /* handle bindings */
1676 if (!f.do_forbid_function)
1678 /* stroke bindings */
1679 __handle_bpress_stroke();
1680 /* mouse bindings */
1681 action = CheckBinding(
1682 Scr.AllBindings, STROKE_ARG(0) e->xbutton.button,
1683 e->xbutton.state, GetUnusedModifiers(),
1684 exc->w.wcontext, BIND_BUTTONPRESS, &fw->class,
1685 fw->name.name);
1686 if (__handle_bpress_action(exc, action))
1688 f.do_swallow_click = 1;
1691 /* raise the window */
1692 if (IS_SCHEDULED_FOR_RAISE(fw))
1694 /* Now that we know the action did not restack the window we
1695 * can raise it.
1696 * dv (10-Aug-2002): We can safely raise the window after
1697 * redrawing it since all the decorations are drawn in the
1698 * window background and no Expose event is generated. */
1699 RaiseWindow(fw, False);
1700 SET_SCHEDULED_FOR_RAISE(fw, 0);
1702 /* clean up */
1703 if (!f.do_swallow_click)
1705 /* pass the click to the application */
1706 XAllowEvents(dpy, ReplayPointer, CurrentTime);
1707 XFlush(dpy);
1709 else if (f.do_focus || f.do_raise)
1711 WaitForButtonsUp(True);
1714 return;
1717 /* restore focus stolen by unmanaged */
1718 static void __refocus_stolen_focus_win(const evh_args_t *ea)
1720 FOCUS_SET(Scr.StolenFocusWin);
1721 ea->exc->x.etrigger->xfocus.window = Scr.StolenFocusWin;
1722 ea->exc->x.etrigger->type = FocusIn;
1723 Scr.UnknownWinFocused = None;
1724 Scr.StolenFocusWin = None;
1725 dispatch_event(ea->exc->x.etrigger);
1727 return;
1730 /* ---------------------------- event handlers ----------------------------- */
1732 void HandleButtonPress(const evh_args_t *ea)
1734 DBUG("HandleButtonPress", "Routine Entered");
1736 GrabEm(CRS_NONE, GRAB_PASSIVE);
1737 if (__is_bpress_window_handled(ea->exc) == False)
1739 __handle_bpress_on_unmanaged(ea->exc);
1741 else if (ea->exc->w.fw != NULL)
1743 __handle_bpress_on_managed(ea->exc);
1745 else
1747 __handle_bpress_on_root(ea->exc);
1749 UngrabEm(GRAB_PASSIVE);
1751 return;
1754 #ifdef HAVE_STROKE
1755 void HandleButtonRelease(const evh_args_t *ea)
1757 char *action;
1758 char *name;
1759 int real_modifier;
1760 const XEvent *te = ea->exc->x.etrigger;
1761 XClassHint *class;
1763 DBUG("HandleButtonRelease", "Routine Entered");
1764 send_motion = False;
1765 stroke_trans (sequence);
1766 DBUG("HandleButtonRelease",sequence);
1767 /* Allows modifier to work (Only R context works here). */
1768 real_modifier = te->xbutton.state - (1 << (7 + te->xbutton.button));
1769 if (ea->exc->w.fw == NULL)
1771 class = NULL;
1772 name = NULL;
1774 else
1776 class = &ea->exc->w.fw->class;
1777 name = ea->exc->w.fw->name.name;
1779 /* need to search for an appropriate stroke binding */
1780 action = CheckBinding(
1781 Scr.AllBindings, sequence, te->xbutton.button, real_modifier,
1782 GetUnusedModifiers(), ea->exc->w.wcontext, BIND_STROKE,
1783 class, name);
1784 /* got a match, now process it */
1785 if (action != NULL && (action[0] != 0))
1787 execute_function(NULL, ea->exc, action, 0);
1788 WaitForButtonsUp(True);
1790 else
1793 * do gnome buttonpress forwarding if win == root
1795 if (Scr.Root == te->xany.window)
1797 GNOME_ProxyButtonEvent(te);
1801 return;
1803 #endif /* HAVE_STROKE */
1805 void HandleClientMessage(const evh_args_t *ea)
1807 const XEvent *te = ea->exc->x.etrigger;
1808 FvwmWindow * const fw = ea->exc->w.fw;
1810 DBUG("HandleClientMessage", "Routine Entered");
1812 /* Process GNOME and EWMH Messages */
1813 if (GNOME_ProcessClientMessage(ea->exc))
1815 return;
1817 else if (EWMH_ProcessClientMessage(ea->exc))
1819 return;
1822 /* handle deletion of tear out menus */
1823 if (fw && IS_TEAR_OFF_MENU(fw) && te->xclient.format == 32 &&
1824 te->xclient.data.l[0] == _XA_WM_DELETE_WINDOW)
1826 menu_close_tear_off_menu(fw);
1827 return;
1830 if (te->xclient.message_type == _XA_WM_CHANGE_STATE &&
1831 fw && te->xclient.data.l[0] == IconicState && !IS_ICONIFIED(fw))
1833 const exec_context_t *exc;
1834 exec_context_changes_t ecc;
1836 ecc.w.wcontext = C_WINDOW;
1837 exc = exc_clone_context(ea->exc, &ecc, ECC_WCONTEXT);
1838 execute_function(NULL, exc, "Iconify", 0);
1839 exc_destroy_context(exc);
1840 return;
1843 /* FIXME: Is this safe enough ? I guess if clients behave
1844 * according to ICCCM and send these messages only if they
1845 * grabbed the pointer, it is OK */
1847 extern Atom _XA_WM_COLORMAP_NOTIFY;
1848 if (te->xclient.message_type == _XA_WM_COLORMAP_NOTIFY)
1850 set_client_controls_colormaps(te->xclient.data.l[1]);
1851 return;
1855 /* CKH - if we get here, it was an unknown client message, so send
1856 * it to the client if it was in a window we know about. I'm not so
1857 * sure this should be done or not, since every other window manager
1858 * I've looked at doesn't. But it might be handy for a free drag and
1859 * drop setup being developed for Linux. */
1860 /* TA: 20091231 - But this confuses QT Drag and Drop since it handles
1861 * processing XSendEvents in an odd order. For now, workaround this
1862 * by using a BugOpts option.
1864 if (fw)
1866 if ((!Scr.bo.do_enable_qt_drag_n_drop_workaround) &&
1867 (te->xclient.window != FW_W(fw)))
1869 XEvent e;
1871 e = *te;
1872 e.xclient.window = FW_W(fw);
1873 FSendEvent(dpy, FW_W(fw), False, NoEventMask, &e);
1878 void HandleColormapNotify(const evh_args_t *ea)
1880 colormap_handle_colormap_notify(ea);
1882 return;
1885 void HandleConfigureRequest(const evh_args_t *ea)
1887 const XEvent *te = ea->exc->x.etrigger;
1888 XConfigureRequestEvent cre;
1889 FvwmWindow *fw = ea->exc->w.fw;
1891 DBUG("HandleConfigureRequest", "Routine Entered");
1893 cre = te->xconfigurerequest;
1894 /* te->xany.window is te->.xconfigurerequest.parent, so the context
1895 * window may be wrong. */
1896 if (XFindContext(dpy, cre.window, FvwmContext, (caddr_t *)&fw) ==
1897 XCNOENT)
1899 fw = NULL;
1901 __handle_configure_request(cre, ea, fw, False, ForgetGravity);
1903 return;
1906 void HandleDestroyNotify(const evh_args_t *ea)
1908 DBUG("HandleDestroyNotify", "Routine Entered");
1910 destroy_window(ea->exc->w.fw);
1911 EWMH_ManageKdeSysTray(
1912 ea->exc->x.etrigger->xdestroywindow.window,
1913 ea->exc->x.etrigger->type);
1914 EWMH_WindowDestroyed();
1915 GNOME_SetClientList();
1917 return;
1920 #define DEBUG_ENTERNOTIFY 0
1921 #if DEBUG_ENTERNOTIFY
1922 static int ecount=0;
1923 #define ENTER_DBG(x) fprintf x;
1924 #else
1925 #define ENTER_DBG(x)
1926 #endif
1927 void HandleEnterNotify(const evh_args_t *ea)
1929 const XEnterWindowEvent *ewp;
1930 XEvent d;
1931 FvwmWindow *sf;
1932 static Bool is_initial_ungrab_pending = True;
1933 Bool is_tear_off_menu;
1934 const XEvent *te = ea->exc->x.etrigger;
1935 FvwmWindow * const fw = ea->exc->w.fw;
1937 DBUG("HandleEnterNotify", "Routine Entered");
1938 ewp = &te->xcrossing;
1939 ENTER_DBG((stderr, "++++++++ en (%d): fw 0x%08x w 0x%08x sw 0x%08xmode 0x%x detail 0x%x '%s'\n", ++ecount, (int)fw, (int)ewp->window, (int)ewp->subwindow, ewp->mode, ewp->detail, fw?fw->visible_name:"(none)"));
1941 if (
1942 ewp->window == Scr.Root &&
1943 ewp->detail == NotifyInferior && ewp->mode == NotifyNormal)
1945 /* pointer left subwindow */
1946 BroadcastPacket(
1947 MX_ENTER_WINDOW, 3, (long)Scr.Root, (long)NULL,
1948 (long)NULL);
1950 else if (
1951 ewp->window == Scr.Root &&
1952 ewp->detail == NotifyNonlinearVirtual)
1954 /* pointer entered screen */
1955 BroadcastPacket(
1956 MX_ENTER_WINDOW, 3, (long)Scr.Root, (long)NULL,
1957 (long)NULL);
1959 if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE)
1961 if (fw && !IS_ICONIFIED(fw) && ewp->window == FW_W(fw))
1963 InstallWindowColormaps(fw);
1965 else
1967 /* make sure its for one of our windows */
1968 /* handle a subwindow cmap */
1969 InstallWindowColormaps(NULL);
1972 else if (!fw)
1974 EnterSubWindowColormap(ewp->window);
1976 if (Scr.flags.is_wire_frame_displayed)
1978 ENTER_DBG((stderr, "en: exit: iwfd\n"));
1979 /* Ignore EnterNotify events while a window is resized or moved
1980 * as a wire frame; otherwise the window list may be screwed
1981 * up. */
1982 return;
1984 if (fw)
1986 if (ewp->window != FW_W_FRAME(fw) &&
1987 ewp->window != FW_W_PARENT(fw) &&
1988 ewp->window != FW_W(fw) &&
1989 ewp->window != FW_W_ICON_TITLE(fw) &&
1990 ewp->window != FW_W_ICON_PIXMAP(fw))
1992 /* Ignore EnterNotify that received by any of the sub
1993 * windows that don't handle this event. unclutter
1994 * triggers these events sometimes, re focusing an
1995 * unfocused window under the pointer */
1996 ENTER_DBG((stderr, "en: exit: funny window\n"));
1997 return;
2000 if (Scr.focus_in_pending_window != NULL)
2002 ENTER_DBG((stderr, "en: exit: fipw\n"));
2003 /* Ignore EnterNotify event while we are waiting for a window to
2004 * receive focus via Focus or FlipFocus commands. */
2005 focus_grab_buttons(fw);
2006 return;
2008 if (ewp->mode == NotifyGrab)
2010 ENTER_DBG((stderr, "en: exit: NotifyGrab\n"));
2011 return;
2013 else if (ewp->mode == NotifyNormal)
2015 ENTER_DBG((stderr, "en: NotifyNormal\n"));
2016 if (ewp->detail == NotifyNonlinearVirtual &&
2017 ewp->focus == False && ewp->subwindow != None)
2019 /* This takes care of some buggy apps that forget that
2020 * one of their dialog subwindows has the focus after
2021 * popping up a selection list several times (ddd,
2022 * netscape). I'm not convinced that this does not
2023 * break something else. */
2024 ENTER_DBG((stderr, "en: NN: refreshing focus\n"));
2025 refresh_focus(fw);
2028 else if (ewp->mode == NotifyUngrab)
2030 ENTER_DBG((stderr, "en: NotifyUngrab\n"));
2031 /* Ignore events generated by grabbing or ungrabbing the
2032 * pointer. However, there is no way to prevent the client
2033 * application from handling this event and, for example,
2034 * grabbing the focus. This will interfere with functions that
2035 * transferred the focus to a different window. */
2036 if (is_initial_ungrab_pending)
2038 ENTER_DBG((stderr, "en: NU: initial ungrab pending (lgw = NULL)\n"));
2039 is_initial_ungrab_pending = False;
2040 xcrossing_last_grab_window = NULL;
2042 else
2044 if (ewp->detail == NotifyNonlinearVirtual &&
2045 ewp->focus == False && ewp->subwindow != None)
2047 /* see comment above */
2048 ENTER_DBG((stderr, "en: NU: refreshing focus\n"));
2049 refresh_focus(fw);
2051 if (fw && fw == xcrossing_last_grab_window)
2053 ENTER_DBG((stderr, "en: exit: NU: is last grab window\n"));
2054 if (ewp->window == FW_W_FRAME(fw) ||
2055 ewp->window == FW_W_ICON_TITLE(fw) ||
2056 ewp->window == FW_W_ICON_PIXMAP(fw))
2058 ENTER_DBG((stderr, "en: exit: NU: last grab window = NULL\n"));
2059 xcrossing_last_grab_window = NULL;
2061 focus_grab_buttons(fw);
2063 return;
2065 else if (fw)
2067 if (ewp->window != FW_W_FRAME(fw) &&
2068 ewp->window != FW_W_ICON_TITLE(fw) &&
2069 ewp->window != FW_W_ICON_PIXMAP(fw))
2071 ENTER_DBG((stderr, "en: exit: NU: not frame window\n"));
2072 focus_grab_buttons(fw);
2073 return;
2078 if (fw)
2080 is_initial_ungrab_pending = False;
2083 /* look for a matching leaveNotify which would nullify this EnterNotify
2086 * RBW - if we're in startup, this is a coerced focus, so we don't
2087 * want to save the event time, or exit prematurely.
2089 * Ignore LeaveNotify events for tear out menus - handled by menu code
2091 is_tear_off_menu =
2092 (fw && IS_TEAR_OFF_MENU(fw) && ewp->window == FW_W(fw));
2093 if (!fFvwmInStartup && !is_tear_off_menu &&
2094 FCheckTypedWindowEvent(dpy, ewp->window, LeaveNotify, &d))
2096 if (d.xcrossing.mode == NotifyNormal &&
2097 d.xcrossing.detail != NotifyInferior)
2099 ENTER_DBG((stderr, "en: exit: found LeaveNotify\n"));
2100 return;
2104 if (ewp->window == Scr.Root)
2106 FvwmWindow *lf = get_last_screen_focus_window();
2108 if (!Scr.flags.is_pointer_on_this_screen)
2110 Scr.flags.is_pointer_on_this_screen = 1;
2111 if (lf && lf != &Scr.FvwmRoot &&
2112 !FP_DO_UNFOCUS_LEAVE(FW_FOCUS_POLICY(lf)))
2114 SetFocusWindow(lf, True, FOCUS_SET_FORCE);
2116 else if (lf != &Scr.FvwmRoot)
2118 ForceDeleteFocus();
2120 else
2122 /* This was the first EnterNotify event for the
2123 * root window - ignore */
2125 set_last_screen_focus_window(NULL);
2127 else if (!(sf = get_focus_window()) ||
2128 FP_DO_UNFOCUS_LEAVE(FW_FOCUS_POLICY(sf)))
2130 DeleteFocus(True);
2132 else if (
2133 Scr.UnknownWinFocused != None && sf != NULL &&
2134 FW_W(sf) == Scr.StolenFocusWin)
2136 __refocus_stolen_focus_win(ea);
2138 if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE)
2140 InstallWindowColormaps(NULL);
2142 focus_grab_buttons(lf);
2143 return;
2145 else
2147 Scr.flags.is_pointer_on_this_screen = 1;
2150 /* An EnterEvent in one of the PanFrameWindows activates the Paging or
2151 an EdgeCommand. */
2152 if (is_pan_frame(ewp->window))
2154 char *edge_command = NULL;
2156 if (
2157 Scr.UnknownWinFocused != None &&
2158 (sf = get_focus_window()) != NULL &&
2159 FW_W(sf) == Scr.StolenFocusWin)
2161 __refocus_stolen_focus_win(ea);
2163 /* check for edge commands */
2164 if (ewp->window == Scr.PanFrameTop.win)
2166 edge_command = Scr.PanFrameTop.command;
2168 else if (ewp->window == Scr.PanFrameBottom.win)
2170 edge_command = Scr.PanFrameBottom.command;
2172 else if (ewp->window == Scr.PanFrameLeft.win)
2174 edge_command = Scr.PanFrameLeft.command;
2176 else if (ewp->window == Scr.PanFrameRight.win)
2178 edge_command = Scr.PanFrameRight.command;
2180 if (edge_command && ewp->mode == NotifyUngrab &&
2181 ewp->detail == NotifyAncestor)
2183 /* nothing */
2185 else if (edge_command)
2187 execute_function(NULL, ea->exc, edge_command, 0);
2189 else
2191 /* no edge command for this pan frame - so we do
2192 * HandlePaging */
2193 int delta_x = 0;
2194 int delta_y = 0;
2195 XEvent e;
2197 /* this was in the HandleMotionNotify before, HEDU */
2198 Scr.flags.is_pointer_on_this_screen = 1;
2199 e = *te;
2200 HandlePaging(
2201 &e, Scr.EdgeScrollX, Scr.EdgeScrollY, &JunkX,
2202 &JunkY, &delta_x, &delta_y, True, True, False,
2203 Scr.ScrollDelay);
2204 return;
2207 if (!fw)
2209 return;
2211 if (IS_EWMH_DESKTOP(FW_W(fw)))
2213 BroadcastPacket(
2214 MX_ENTER_WINDOW, 3, (long)Scr.Root, (long)NULL,
2215 (long)NULL);
2216 return;
2218 if (ewp->window == FW_W_FRAME(fw) ||
2219 ewp->window == FW_W_ICON_TITLE(fw) ||
2220 ewp->window == FW_W_ICON_PIXMAP(fw))
2222 BroadcastPacket(
2223 MX_ENTER_WINDOW, 3, (long)FW_W(fw),
2224 (long)FW_W_FRAME(fw), (unsigned long)fw);
2226 sf = get_focus_window();
2227 if (sf && fw != sf && FP_DO_UNFOCUS_LEAVE(FW_FOCUS_POLICY(sf)))
2229 ENTER_DBG((stderr, "en: delete focus\n"));
2230 DeleteFocus(True);
2232 focus_grab_buttons(fw);
2233 if (FP_DO_FOCUS_ENTER(FW_FOCUS_POLICY(fw)))
2235 ENTER_DBG((stderr, "en: set mousey focus\n"));
2236 if (ewp->window == FW_W(fw))
2238 /* Event is for the client window...*/
2239 #ifndef EXPERIMENTAL_ROU_HANDLING_V2
2240 /* RBW -- This may still be needed at times, I'm not
2241 *sure yet. */
2242 SetFocusWindowClientEntered(
2243 fw, True, FOCUS_SET_BY_ENTER);
2244 #else
2245 SetFocusWindow(fw, True, FOCUS_SET_BY_ENTER);
2246 #endif
2248 else
2250 /* Event is for the frame...*/
2251 SetFocusWindow(fw, True, FOCUS_SET_BY_ENTER);
2254 else if (focus_is_focused(fw) && focus_does_accept_input_focus(fw))
2256 /* We have to refresh the focus window here in case we left the
2257 * focused fvwm window. Motif apps may lose the input focus
2258 * otherwise. But do not try to refresh the focus of
2259 * applications that want to handle it themselves. */
2260 focus_force_refresh_focus(fw);
2262 else if (sf != fw)
2264 /* Give the window a chance to grab the buttons needed for
2265 * raise-on-click */
2266 focus_grab_buttons(sf);
2268 if (
2269 Scr.UnknownWinFocused != None && sf != NULL &&
2270 FW_W(sf) == Scr.StolenFocusWin)
2272 __refocus_stolen_focus_win(ea);
2274 /* We get an EnterNotify with mode == UnGrab when fvwm releases the
2275 * grab held during iconification. We have to ignore this, or icon
2276 * title will be initially raised. */
2277 if (IS_ICONIFIED(fw) && (ewp->mode == NotifyNormal) &&
2278 (ewp->window == FW_W_ICON_PIXMAP(fw) ||
2279 ewp->window == FW_W_ICON_TITLE(fw)) &&
2280 FW_W_ICON_PIXMAP(fw) != None)
2282 SET_ICON_ENTERED(fw, 1);
2283 DrawIconWindow(fw, True, False, False, False, NULL);
2285 /* Check for tear off menus */
2286 if (is_tear_off_menu)
2288 menu_enter_tear_off_menu(ea->exc);
2291 return;
2294 void HandleExpose(const evh_args_t *ea)
2296 XEvent e;
2297 FvwmWindow * const fw = ea->exc->w.fw;
2299 e = *ea->exc->x.etrigger;
2300 #if 0
2301 /* This doesn't work well. Sometimes, the expose count is zero although
2302 * dozens of expose events are pending. This happens all the time
2303 * during a shading animation. Simply flush expose events
2304 * unconditionally. */
2305 if (e.xexpose.count != 0)
2307 flush_accumulate_expose(e.xexpose.window, &e);
2309 #else
2310 flush_accumulate_expose(e.xexpose.window, &e);
2311 #endif
2312 if (fw == NULL)
2314 return;
2316 if (e.xany.window == FW_W_ICON_TITLE(fw) ||
2317 e.xany.window == FW_W_ICON_PIXMAP(fw))
2319 DrawIconWindow(fw, True, True, False, False, &e);
2320 return;
2322 else if (IS_TEAR_OFF_MENU(fw) && e.xany.window == FW_W(fw))
2324 /* refresh the contents of the torn out menu */
2325 menu_expose(&e, NULL);
2328 return;
2331 void HandleFocusIn(const evh_args_t *ea)
2333 XEvent d;
2334 Window w = None;
2335 Window focus_w = None;
2336 Window focus_fw = None;
2337 Pixel fc = 0;
2338 Pixel bc = 0;
2339 FvwmWindow *ffw_old = get_focus_window();
2340 FvwmWindow *sf;
2341 Bool do_force_broadcast = False;
2342 Bool is_unmanaged_focused = False;
2343 static Window last_focus_w = None;
2344 static Window last_focus_fw = None;
2345 static Bool was_nothing_ever_focused = True;
2346 FvwmWindow *fw = ea->exc->w.fw;
2348 DBUG("HandleFocusIn", "Routine Entered");
2350 Scr.focus_in_pending_window = NULL;
2351 /* This is a hack to make the PointerKey command work */
2352 if (ea->exc->x.etrigger->xfocus.detail != NotifyPointer)
2354 /**/
2355 w = ea->exc->x.etrigger->xany.window;
2357 while (FCheckTypedEvent(dpy, FocusIn, &d))
2359 /* dito */
2360 if (d.xfocus.detail != NotifyPointer)
2362 /**/
2363 w = d.xany.window;
2366 /* dito */
2367 if (w == None)
2369 return;
2371 /**/
2372 if (XFindContext(dpy, w, FvwmContext, (caddr_t *) &fw) == XCNOENT)
2374 fw = NULL;
2377 Scr.UnknownWinFocused = None;
2378 if (!fw)
2380 if (w != Scr.NoFocusWin)
2382 Scr.UnknownWinFocused = w;
2383 Scr.StolenFocusWin =
2384 (ffw_old != NULL) ? FW_W(ffw_old) : None;
2385 focus_w = w;
2386 is_unmanaged_focused = True;
2388 /* Only show a non-focused window as focused,
2389 * if the focus is on unmanaged and flickering qt dialogs
2390 * workaround is on. */
2391 if (!Scr.bo.do_enable_flickering_qt_dialogs_workaround ||
2392 !is_unmanaged_focused)
2394 border_draw_decorations(
2395 Scr.Hilite, PART_ALL, False, True, CLEAR_ALL,
2396 NULL, NULL);
2397 if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS)
2399 if ((Scr.Hilite)&&(!IS_ICONIFIED(Scr.Hilite)))
2401 InstallWindowColormaps(Scr.Hilite);
2403 else
2405 InstallWindowColormaps(NULL);
2409 /* Not very useful if no window that fvwm and its modules know
2410 * about has the focus. */
2411 fc = GetColor(DEFAULT_FORE_COLOR);
2412 bc = GetColor(DEFAULT_BACK_COLOR);
2414 else if (fw != Scr.Hilite ||
2415 /* domivogt (16-May-2000): This check is necessary to force
2416 * sending a M_FOCUS_CHANGE packet after an unmanaged window
2417 * was focused. Otherwise fvwm would believe that Scr.Hilite
2418 * was still focused and not send any info to the modules. */
2419 last_focus_fw == None ||
2420 IS_FOCUS_CHANGE_BROADCAST_PENDING(fw))
2422 do_force_broadcast = IS_FOCUS_CHANGE_BROADCAST_PENDING(fw);
2423 SET_FOCUS_CHANGE_BROADCAST_PENDING(fw, 0);
2424 if (fw != Scr.Hilite)
2426 border_draw_decorations(
2427 fw, PART_ALL, True, True, CLEAR_ALL, NULL,
2428 NULL);
2430 focus_w = FW_W(fw);
2431 focus_fw = FW_W_FRAME(fw);
2432 fc = fw->hicolors.fore;
2433 bc = fw->hicolors.back;
2434 set_focus_window(fw);
2435 if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS)
2437 if ((Scr.Hilite)&&(!IS_ICONIFIED(Scr.Hilite)))
2439 InstallWindowColormaps(Scr.Hilite);
2441 else
2443 InstallWindowColormaps(NULL);
2447 else
2449 return;
2451 if (was_nothing_ever_focused || last_focus_fw == None ||
2452 focus_w != last_focus_w || focus_fw != last_focus_fw ||
2453 do_force_broadcast)
2455 if (!Scr.bo.do_enable_flickering_qt_dialogs_workaround ||
2456 !is_unmanaged_focused)
2458 BroadcastPacket(
2459 M_FOCUS_CHANGE, 5, (long)focus_w,
2460 (long)focus_fw,
2461 (unsigned long)IsLastFocusSetByMouse(),
2462 (long)fc, (long)bc);
2463 EWMH_SetActiveWindow(focus_w);
2465 last_focus_w = focus_w;
2466 last_focus_fw = focus_fw;
2467 was_nothing_ever_focused = False;
2469 if ((sf = get_focus_window()) != ffw_old)
2471 focus_grab_buttons(sf);
2472 focus_grab_buttons(ffw_old);
2475 return;
2478 void HandleFocusOut(const evh_args_t *ea)
2480 if (Scr.UnknownWinFocused != None && Scr.StolenFocusWin != None &&
2481 ea->exc->x.etrigger->xfocus.window == Scr.UnknownWinFocused)
2483 __refocus_stolen_focus_win(ea);
2486 return;
2489 void __handle_key(const evh_args_t *ea, Bool is_press)
2491 char *action;
2492 FvwmWindow *sf;
2493 KeyCode kc;
2494 int kcontext;
2495 const XEvent *te = ea->exc->x.etrigger;
2496 const FvwmWindow * const fw = ea->exc->w.fw;
2497 Bool is_second_binding;
2498 const XClassHint *winClass1, *winClass2;
2499 XClassHint tmp;
2500 char *name1, *name2;
2501 const exec_context_t *exc;
2502 exec_context_changes_t ecc;
2504 PressedW = None;
2506 /* Here's a real hack - some systems have two keys with the
2507 * same keysym and different keycodes. This converts all
2508 * the cases to one keycode. */
2509 kc = XKeysymToKeycode(dpy, XKeycodeToKeysym(dpy, te->xkey.keycode, 0));
2511 /* Check if there is something bound to the key */
2513 sf = get_focus_window();
2514 if (sf == NULL)
2516 tmp.res_name = tmp.res_class = name1 = "root";
2517 winClass1 = &tmp;
2518 kcontext = C_ROOT;
2520 else
2522 winClass1 = &sf->class;
2523 name1 = sf->name.name;
2524 kcontext = (sf == fw ? ea->exc->w.wcontext : C_WINDOW);
2527 if (fw == NULL)
2529 tmp.res_name = tmp.res_class = name2 = "root";
2530 winClass2 = &tmp;
2532 else
2534 winClass2 = &fw->class;
2535 name2 = fw->name.name;
2537 /* Searching the binding list with a different 'type' value
2538 * (ie. BIND_KEYPRESS vs BIND_PKEYPRESS) doesn't make a difference.
2539 * The different context value does though. */
2540 action = CheckTwoBindings(
2541 &is_second_binding, Scr.AllBindings, STROKE_ARG(0) kc,
2542 te->xkey.state, GetUnusedModifiers(), kcontext, BIND_KEYPRESS,
2543 winClass1, name1, ea->exc->w.wcontext, BIND_PKEYPRESS,
2544 winClass2, name2);
2546 if (action != NULL)
2548 if (!is_press)
2550 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
2551 return;
2553 exc = ea->exc;
2554 if (is_second_binding == False)
2556 ecc.w.fw = sf;
2557 ecc.w.wcontext = kcontext;
2558 exc = exc_clone_context(
2559 ea->exc, &ecc, ECC_FW | ECC_WCONTEXT);
2561 execute_function(NULL, exc, action, 0);
2562 if (is_second_binding == False)
2564 exc_destroy_context(exc);
2566 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
2567 return;
2570 /* if we get here, no function key was bound to the key. Send it
2571 * to the client if it was in a window we know about. */
2572 sf = get_focus_window();
2573 if (sf && te->xkey.window != FW_W(sf))
2575 XEvent e;
2577 e = *te;
2578 e.xkey.window = FW_W(sf);
2579 FSendEvent(
2580 dpy, e.xkey.window, False,
2581 (is_press)? KeyPressMask:KeyReleaseMask, &e);
2583 else if (fw && te->xkey.window != FW_W(fw))
2585 XEvent e;
2587 e = *te;
2588 e.xkey.window = FW_W(fw);
2589 FSendEvent(
2590 dpy, e.xkey.window, False,
2591 (is_press)? KeyPressMask:KeyReleaseMask, &e);
2593 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
2595 return;
2598 void HandleKeyPress(const evh_args_t *ea)
2600 __handle_key(ea, True);
2603 void HandleKeyRelease(const evh_args_t *ea)
2605 __handle_key(ea, False);
2608 void HandleLeaveNotify(const evh_args_t *ea)
2610 const XLeaveWindowEvent *lwp;
2611 const XEvent *te = ea->exc->x.etrigger;
2612 FvwmWindow * const fw = ea->exc->w.fw;
2614 DBUG("HandleLeaveNotify", "Routine Entered");
2616 ENTER_DBG((stderr, "-------- ln (%d): fw 0x%08x w 0x%08x sw 0x%08x mode 0x%x detail 0x%x '%s'\n", ++ecount, (int)fw, (int)te->xcrossing.window, (int)te->xcrossing.subwindow, te->xcrossing.mode, te->xcrossing.detail, fw?fw->visible_name:"(none)"));
2617 lwp = &te->xcrossing;
2618 if (
2619 lwp->window == Scr.Root &&
2620 lwp->detail == NotifyInferior && lwp->mode == NotifyNormal)
2622 /* pointer entered subwindow */
2623 BroadcastPacket(
2624 MX_LEAVE_WINDOW, 3, (long)Scr.Root, (long)NULL,
2625 (long)NULL);
2627 else if (
2628 lwp->window == Scr.Root &&
2629 lwp->detail == NotifyNonlinearVirtual)
2631 /* pointer left screen */
2632 BroadcastPacket(
2633 MX_LEAVE_WINDOW, 3, (long)Scr.Root, (long)NULL,
2634 (long)NULL);
2636 /* Ignore LeaveNotify events while a window is resized or moved as a
2637 * wire frame; otherwise the window list may be screwed up. */
2638 if (Scr.flags.is_wire_frame_displayed)
2640 return;
2642 if (lwp->mode != NotifyNormal)
2644 /* Ignore events generated by grabbing or ungrabbing the
2645 * pointer. However, there is no way to prevent the client
2646 * application from handling this event and, for example,
2647 * grabbing the focus. This will interfere with functions that
2648 * transferred the focus to a different window. It is
2649 * necessary to check for LeaveNotify events on the client
2650 * window too in case buttons are not grabbed on it. */
2651 if (lwp->mode == NotifyGrab && fw &&
2652 (lwp->window == FW_W_FRAME(fw) ||
2653 lwp->window == FW_W(fw) ||
2654 lwp->window == FW_W_ICON_TITLE(fw) ||
2655 lwp->window == FW_W_ICON_PIXMAP(fw)))
2657 ENTER_DBG((stderr, "ln: *** lgw = 0x%08x\n", (int)fw));
2658 xcrossing_last_grab_window = fw;
2660 #ifdef FOCUS_EXPANDS_TITLE
2661 if (fw && IS_ICONIFIED(fw))
2663 SET_ICON_ENTERED(fw, 0);
2664 DrawIconWindow(
2665 fw, True, False, False, False, NULL);
2667 #endif
2668 return;
2670 /* CDE-like behaviour of raising the icon title if the icon
2671 gets the focus (in particular if the cursor is over the icon) */
2672 if (fw && IS_ICONIFIED(fw))
2674 SET_ICON_ENTERED(fw,0);
2675 DrawIconWindow(fw, True, False, False, False, NULL);
2678 /* An LeaveEvent in one of the PanFrameWindows activates
2679 an EdgeLeaveCommand. */
2680 if (is_pan_frame(lwp->window))
2682 char *edge_command_leave = NULL;
2684 /* check for edge commands */
2685 if (lwp->window == Scr.PanFrameTop.win)
2687 edge_command_leave = Scr.PanFrameTop.command_leave;
2689 else if (lwp->window == Scr.PanFrameBottom.win)
2691 edge_command_leave = Scr.PanFrameBottom.command_leave;
2693 else if (lwp->window == Scr.PanFrameLeft.win)
2695 edge_command_leave = Scr.PanFrameLeft.command_leave;
2697 else if (lwp->window == Scr.PanFrameRight.win)
2699 edge_command_leave = Scr.PanFrameRight.command_leave;
2701 if (edge_command_leave && lwp->mode == NotifyUngrab &&
2702 lwp->detail == NotifyAncestor)
2704 /* nothing */
2706 else if (edge_command_leave)
2708 execute_function(NULL, ea->exc, edge_command_leave, 0);
2713 /* If we leave the root window, then we're really moving
2714 * another screen on a multiple screen display, and we
2715 * need to de-focus and unhighlight to make sure that we
2716 * don't end up with more than one highlighted window at a time */
2717 if (lwp->window == Scr.Root &&
2718 /* domivogt (16-May-2000): added this test because somehow fvwm
2719 * sometimes gets a LeaveNotify on the root window although it is
2720 * single screen. */
2721 Scr.NumberOfScreens > 1)
2723 if (lwp->mode == NotifyNormal)
2725 if (lwp->detail != NotifyInferior)
2727 FvwmWindow *sf = get_focus_window();
2729 Scr.flags.is_pointer_on_this_screen = 0;
2730 set_last_screen_focus_window(sf);
2731 if (sf != NULL)
2733 DeleteFocus(True);
2735 if (Scr.Hilite != NULL)
2737 border_draw_decorations(
2738 Scr.Hilite, PART_ALL, False,
2739 True, CLEAR_ALL, NULL, NULL);
2744 else
2746 /* handle a subwindow cmap */
2747 LeaveSubWindowColormap(te->xany.window);
2749 if (fw != NULL &&
2750 (lwp->window == FW_W_FRAME(fw) ||
2751 lwp->window == FW_W_ICON_TITLE(fw) ||
2752 lwp->window == FW_W_ICON_PIXMAP(fw)))
2754 BroadcastPacket(
2755 MX_LEAVE_WINDOW, 3, (long)FW_W(fw),
2756 (long)FW_W_FRAME(fw), (unsigned long)fw);
2759 return;
2762 void HandleMapNotify(const evh_args_t *ea)
2764 Bool is_on_this_page = False;
2765 const XEvent *te = ea->exc->x.etrigger;
2766 FvwmWindow * const fw = ea->exc->w.fw;
2768 DBUG("HandleMapNotify", "Routine Entered");
2770 if (!fw)
2772 if (te->xmap.override_redirect == True &&
2773 te->xmap.window != Scr.NoFocusWin)
2775 XSelectInput(dpy, te->xmap.window, XEVMASK_ORW);
2776 XFlush(dpy);
2777 Scr.UnknownWinFocused = te->xmap.window;
2779 return;
2781 if (te->xmap.window == FW_W_FRAME(fw))
2783 /* Now that we know the frame is mapped after capturing the
2784 * window we do not need StructureNotifyMask events anymore. */
2785 XSelectInput(dpy, FW_W_FRAME(fw), XEVMASK_FRAMEW);
2786 XFlush(dpy);
2788 /* Except for identifying over-ride redirect window mappings, we
2789 * don't need or want windows associated with the
2790 * SubstructureNotifyMask */
2791 if (te->xmap.event != te->xmap.window)
2793 return;
2795 SET_MAP_PENDING(fw, 0);
2796 /* don't map if the event was caused by a de-iconify */
2797 if (IS_ICONIFY_PENDING(fw))
2799 return;
2802 /* Make sure at least part of window is on this page before giving it
2803 * focus... */
2804 is_on_this_page = IsRectangleOnThisPage(&(fw->g.frame), fw->Desk);
2807 * Need to do the grab to avoid race condition of having server send
2808 * MapNotify to client before the frame gets mapped; this is bad because
2809 * the client would think that the window has a chance of being viewable
2810 * when it really isn't.
2812 MyXGrabServer (dpy);
2813 if (FW_W_ICON_TITLE(fw))
2815 XUnmapWindow(dpy, FW_W_ICON_TITLE(fw));
2817 if (FW_W_ICON_PIXMAP(fw) != None)
2819 XUnmapWindow(dpy, FW_W_ICON_PIXMAP(fw));
2821 XMapSubwindows(dpy, FW_W_FRAME(fw));
2822 if (fw->Desk == Scr.CurrentDesk)
2824 XMapWindow(dpy, FW_W_FRAME(fw));
2826 if (IS_ICONIFIED(fw))
2828 BroadcastPacket(
2829 M_DEICONIFY, 3, (long)FW_W(fw), (long)FW_W_FRAME(fw),
2830 (unsigned long)fw);
2832 else
2834 BroadcastPacket(
2835 M_MAP, 3, (long)FW_W(fw), (long)FW_W_FRAME(fw),
2836 (unsigned long)fw);
2839 if (is_on_this_page &&
2840 focus_query_open_grab_focus(fw, get_focus_window()) == True)
2842 SetFocusWindow(fw, True, FOCUS_SET_FORCE);
2844 border_draw_decorations(
2845 fw, PART_ALL, (fw == get_focus_window()) ? True : False, True,
2846 CLEAR_ALL, NULL, NULL);
2847 MyXUngrabServer (dpy);
2848 SET_MAPPED(fw, 1);
2849 SET_ICONIFIED(fw, 0);
2850 SET_ICON_UNMAPPED(fw, 0);
2851 if (DO_ICONIFY_AFTER_MAP(fw))
2853 initial_window_options_t win_opts;
2855 /* finally, if iconification was requested before the window
2856 * was mapped, request it now. */
2857 memset(&win_opts, 0, sizeof(win_opts));
2858 Iconify(fw, &win_opts);
2859 SET_ICONIFY_AFTER_MAP(fw, 0);
2861 focus_grab_buttons_on_layer(fw->layer);
2863 return;
2866 void HandleMappingNotify(const evh_args_t *ea)
2868 XRefreshKeyboardMapping(&ea->exc->x.etrigger->xmapping);
2870 return;
2873 void HandleMapRequest(const evh_args_t *ea)
2875 DBUG("HandleMapRequest", "Routine Entered");
2877 if (fFvwmInStartup)
2879 /* Just map the damn thing, decorations are added later
2880 * in CaptureAllWindows. */
2881 XMapWindow(dpy, ea->exc->x.etrigger->xmaprequest.window);
2882 return;
2884 HandleMapRequestKeepRaised(ea, None, NULL, NULL);
2886 return;
2889 void HandleMapRequestKeepRaised(
2890 const evh_args_t *ea, Window KeepRaised, FvwmWindow *ReuseWin,
2891 initial_window_options_t *win_opts)
2893 Bool is_on_this_page = False;
2894 Bool is_new_window = False;
2895 FvwmWindow *tmp;
2896 FvwmWindow *sf;
2897 initial_window_options_t win_opts_bak;
2898 Window ew;
2899 FvwmWindow *fw;
2900 extern Bool Restarting;
2901 const char *initial_map_command;
2903 initial_map_command = NULL;
2904 if (win_opts == NULL)
2906 memset(&win_opts_bak, 0, sizeof(win_opts_bak));
2907 win_opts = &win_opts_bak;
2909 ew = ea->exc->w.w;
2910 if (ReuseWin == NULL)
2912 Window pw;
2914 pw = ea->exc->x.etrigger->xmaprequest.parent;
2915 if (XFindContext(dpy, ew, FvwmContext, (caddr_t *)&fw) ==
2916 XCNOENT)
2918 fw = NULL;
2920 if (fw != NULL && IS_MAP_PENDING(fw))
2922 /* The window is already going to be mapped, no need to
2923 * do that twice */
2924 return;
2927 else
2929 fw = ReuseWin;
2932 if (fw == NULL && EWMH_IsKdeSysTrayWindow(ew))
2934 /* This means that the window is swallowed by kicker and that
2935 * kicker restart or exit. As we should assume that kicker
2936 * restart we should return here, if not we go into trouble
2937 * ... */
2938 return;
2940 if (!win_opts->flags.do_override_ppos)
2942 XFlush(dpy);
2945 /* If the window has never been mapped before ... */
2946 if (!fw || (fw && DO_REUSE_DESTROYED(fw)))
2948 check_if_event_args args;
2949 XEvent dummy;
2951 args.w = ew;
2952 args.do_return_true = True;
2953 args.do_return_true_cr = False;
2954 if (
2955 FCheckIfEvent(
2956 dpy, &dummy, test_withdraw_request,
2957 (XPointer)&args)) {
2958 /* The window is moved back to the WithdrawnState
2959 * immideately. Don't map it.
2961 * However, send make sure that a WM_STATE
2962 * PropertyNotify event is sent to the window.
2963 * QT needs this.
2965 Atom atype;
2966 int aformat;
2967 unsigned long nitems, bytes_remain;
2968 unsigned char *prop;
2970 if (
2971 XGetWindowProperty(
2972 dpy, ew, _XA_WM_STATE, 0L, 3L, False,
2973 _XA_WM_STATE, &atype, &aformat,
2974 &nitems,&bytes_remain,&prop)
2975 == Success)
2977 if (prop != NULL)
2979 XFree(prop);
2980 XDeleteProperty(dpy, ew, _XA_WM_STATE);
2982 else
2984 XPropertyEvent ev;
2985 ev.type = PropertyNotify;
2986 ev.display = dpy;
2987 ev.window = ew;
2988 ev.atom = _XA_WM_STATE;
2989 ev.time = fev_get_evtime();
2990 ev.state = PropertyDelete;
2991 FSendEvent(
2992 dpy, ew, True,
2993 PropertyChangeMask,
2994 (XEvent*)&ev);
2998 return;
3001 /* Add decorations. */
3002 fw = AddWindow(
3003 &initial_map_command, ea->exc, ReuseWin, win_opts);
3004 if (fw == AW_NO_WINDOW)
3006 return;
3008 else if (fw == AW_UNMANAGED)
3010 XMapWindow(dpy, ew);
3011 return;
3013 is_new_window = True;
3016 * Make sure at least part of window is on this page
3017 * before giving it focus...
3019 is_on_this_page = IsRectangleOnThisPage(&(fw->g.frame), fw->Desk);
3020 if (KeepRaised != None)
3022 XRaiseWindow(dpy, KeepRaised);
3024 /* If it's not merely iconified, and we have hints, use them. */
3026 if (IS_ICONIFIED(fw))
3028 /* If no hints, or currently an icon, just "deiconify" */
3029 DeIconify(fw);
3031 else if (IS_MAPPED(fw))
3033 /* the window is already mapped - fake a MapNotify event */
3034 fake_map_unmap_notify(fw, MapNotify);
3036 else
3038 int state;
3040 if (fw->wmhints && (fw->wmhints->flags & StateHint))
3042 state = fw->wmhints->initial_state;
3044 else
3046 state = NormalState;
3048 if (win_opts->initial_state != DontCareState)
3050 state = win_opts->initial_state;
3053 switch (state)
3055 case DontCareState:
3056 case NormalState:
3057 case InactiveState:
3058 default:
3059 MyXGrabServer(dpy);
3060 if (fw->Desk == Scr.CurrentDesk)
3062 Bool do_grab_focus;
3064 SET_MAP_PENDING(fw, 1);
3065 XMapWindow(dpy, FW_W_FRAME(fw));
3066 XMapWindow(dpy, FW_W(fw));
3067 SetMapStateProp(fw, NormalState);
3068 if (Scr.flags.is_map_desk_in_progress)
3070 do_grab_focus = False;
3072 else if (!is_on_this_page)
3074 do_grab_focus = False;
3076 else if (focus_query_open_grab_focus(
3077 fw, get_focus_window()) ==
3078 True)
3080 do_grab_focus = True;
3082 else
3084 do_grab_focus = False;
3086 if (do_grab_focus)
3088 SetFocusWindow(
3089 fw, True, FOCUS_SET_FORCE);
3091 else
3093 /* make sure the old focused window
3094 * still has grabbed all necessary
3095 * buttons. */
3096 focus_grab_buttons(
3097 get_focus_window());
3100 else
3102 #ifndef ICCCM2_UNMAP_WINDOW_PATCH
3103 /* nope, this is forbidden by the ICCCM2 */
3104 XMapWindow(dpy, FW_W(fw));
3105 SetMapStateProp(fw, NormalState);
3106 #else
3107 /* Since we will not get a MapNotify, set the
3108 * IS_MAPPED flag manually. */
3109 SET_MAPPED(fw, 1);
3110 SetMapStateProp(fw, IconicState);
3111 /* fake that the window was mapped to allow
3112 * modules to swallow it */
3113 BroadcastPacket(
3114 M_MAP, 3, (long)FW_W(fw),
3115 (long)FW_W_FRAME(fw),
3116 (unsigned long)fw);
3117 #endif
3119 /* TA: 20090125: We *have* to handle
3120 * InitialMapCommand here and not in AddWindow() to
3121 * allow for correct timings when the window is truly
3122 * mapped. (c.f. things like Iconify.)
3125 /* TA: 20091212: But only do this when we're *not*
3126 * restarting -- the window is still mapped, but gets
3127 * recaptured -- we don't want to trigger this event
3128 * again. Otherwise we end up toggling the state of
3129 * the window in situations where the
3130 * InitialMapCommand is Iconify or Maximize, for
3131 * instance.
3133 if ((initial_map_command != NULL) &&
3134 (!Restarting && Scr.flags.are_windows_captured))
3136 execute_function_override_window(
3137 NULL, ea->exc,
3138 (char *)initial_map_command, 0, fw);
3140 MyXUngrabServer(dpy);
3141 break;
3143 case IconicState:
3144 if (is_new_window)
3146 /* the window will not be mapped - fake a
3147 * MapNotify and an UnmapNotify event. Can't
3148 * remember exactly why this is necessary, but
3149 * probably something w/ (de)iconify state
3150 * confusion. */
3151 fake_map_unmap_notify(fw, MapNotify);
3152 fake_map_unmap_notify(fw, UnmapNotify);
3154 if (win_opts->flags.is_iconified_by_parent ||
3155 ((tmp = get_transientfor_fvwmwindow(fw)) &&
3156 IS_ICONIFIED(tmp)))
3158 win_opts->flags.is_iconified_by_parent = 0;
3159 SET_ICONIFIED_BY_PARENT(fw, 1);
3161 if (USE_ICON_POSITION_HINT(fw) && fw->wmhints &&
3162 (fw->wmhints->flags & IconPositionHint))
3164 win_opts->default_icon_x = fw->wmhints->icon_x;
3165 win_opts->default_icon_y = fw->wmhints->icon_y;
3167 Iconify(fw, win_opts);
3168 break;
3171 if (IS_SHADED(fw))
3173 BroadcastPacket(
3174 M_WINDOWSHADE, 3, (long)FW_W(fw), (long)FW_W_FRAME(fw),
3175 (unsigned long)fw);
3177 /* If the newly mapped window overlaps the focused window, make sure
3178 * ClickToFocusRaises and MouseFocusClickRaises work again. */
3179 sf = get_focus_window();
3180 if (sf != NULL)
3182 focus_grab_buttons(sf);
3184 if (win_opts->flags.is_menu)
3186 SET_MAPPED(fw, 1);
3187 SET_MAP_PENDING(fw, 0);
3189 EWMH_SetClientList();
3190 EWMH_SetClientListStacking();
3191 GNOME_SetClientList();
3193 return;
3196 #ifdef HAVE_STROKE
3197 void HandleMotionNotify(const evh_args_t *ea)
3199 DBUG("HandleMotionNotify", "Routine Entered");
3201 if (send_motion == True)
3203 stroke_record(
3204 ea->exc->x.etrigger->xmotion.x,
3205 ea->exc->x.etrigger->xmotion.y);
3208 return;
3210 #endif /* HAVE_STROKE */
3212 void HandlePropertyNotify(const evh_args_t *ea)
3214 Bool OnThisPage = False;
3215 Bool has_icon_changed = False;
3216 Bool has_icon_pixmap_hint_changed = False;
3217 Bool has_icon_window_hint_changed = False;
3218 FlocaleNameString new_name = { NoName, NULL };
3219 int old_wmhints_flags;
3220 const XEvent *te = ea->exc->x.etrigger;
3221 char *urgency_action = NULL;
3222 FvwmWindow * const fw = ea->exc->w.fw;
3224 DBUG("HandlePropertyNotify", "Routine Entered");
3226 if (te->xproperty.window == Scr.Root &&
3227 te->xproperty.state == PropertyNewValue &&
3228 (te->xproperty.atom == _XA_XSETROOT_ID ||
3229 te->xproperty.atom == _XA_XROOTPMAP_ID))
3231 /* background change */
3232 /* _XA_XSETROOT_ID is used by fvwm-root, xli and more (xv sends
3233 * no property notify?). _XA_XROOTPMAP_ID is used by Esetroot
3234 * compatible program: the problem here is that with some
3235 * Esetroot compatible program we get the message _before_ the
3236 * background change. This is fixed with Esetroot 9.2 (not yet
3237 * released, 2002-01-14) */
3239 /* update icon window with some alpha and tear-off menu */
3240 FvwmWindow *t;
3242 for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
3244 int cs;
3245 int t_cs = -1;
3246 int b_cs = t->icon_background_cs;
3247 Bool draw_picture = False;
3248 Bool draw_title = False;
3250 /* redraw ParentRelative tear-off menu */
3251 menu_redraw_transparent_tear_off_menu(t, True);
3253 if (!IS_ICONIFIED(t) || IS_ICON_SUPPRESSED(t))
3255 continue;
3257 if (Scr.Hilite == t)
3259 if (t->icon_title_cs_hi >= 0)
3261 t_cs = cs = t->icon_title_cs_hi;
3263 else
3265 cs = t->cs_hi;
3268 else
3270 if (t->icon_title_cs >= 0)
3272 t_cs = cs = t->icon_title_cs;
3274 else
3276 cs = t->cs;
3279 if (t->icon_alphaPixmap != None ||
3280 (cs >= 0 &&
3281 Colorset[cs].icon_alpha_percent < 100) ||
3282 CSET_IS_TRANSPARENT_PR(b_cs) ||
3283 (!IS_ICON_SHAPED(t) &&
3284 t->icon_background_padding > 0))
3286 draw_picture = True;
3288 if (CSET_IS_TRANSPARENT_PR(t_cs))
3290 draw_title = True;
3292 if (draw_title || draw_picture)
3294 DrawIconWindow(
3295 t, draw_title, draw_picture, False,
3296 draw_picture, NULL);
3299 if (te->xproperty.atom == _XA_XROOTPMAP_ID)
3301 update_root_transparent_colorset(te->xproperty.atom);
3303 BroadcastPropertyChange(
3304 MX_PROPERTY_CHANGE_BACKGROUND, 0, 0, "");
3305 return;
3308 if (!fw)
3310 return;
3312 if (XGetGeometry(
3313 dpy, FW_W(fw), &JunkRoot, &JunkX, &JunkY,
3314 (unsigned int*)&JunkWidth, (unsigned int*)&JunkHeight,
3315 (unsigned int*)&JunkBW, (unsigned int*)&JunkDepth) == 0)
3317 return;
3321 * Make sure at least part of window is on this page
3322 * before giving it focus...
3324 OnThisPage = IsRectangleOnThisPage(&(fw->g.frame), fw->Desk);
3326 switch (te->xproperty.atom)
3328 case XA_WM_TRANSIENT_FOR:
3329 flush_property_notify(XA_WM_TRANSIENT_FOR, FW_W(fw));
3330 if (setup_transientfor(fw) == True)
3332 RaiseWindow(fw, False);
3334 break;
3336 case XA_WM_NAME:
3337 flush_property_notify(XA_WM_NAME, FW_W(fw));
3338 if (HAS_EWMH_WM_NAME(fw))
3340 return;
3342 FlocaleGetNameProperty(XGetWMName, dpy, FW_W(fw), &new_name);
3343 if (new_name.name == NULL)
3345 FlocaleFreeNameProperty(&new_name);
3346 return;
3348 if (strlen(new_name.name) > MAX_WINDOW_NAME_LEN)
3350 /* limit to prevent hanging X server */
3351 (new_name.name)[MAX_WINDOW_NAME_LEN] = 0;
3353 if (fw->name.name && strcmp(new_name.name, fw->name.name) == 0)
3355 /* migo: some apps update their names every second */
3356 /* griph: make sure we don't free the property if it
3357 is THE same name */
3358 if (new_name.name != fw->name.name)
3360 FlocaleFreeNameProperty(&new_name);
3362 return;
3365 free_window_names(fw, True, False);
3366 fw->name = new_name;
3367 SET_NAME_CHANGED(fw, 1);
3368 if (fw->name.name == NULL)
3370 fw->name.name = NoName; /* must not happen */
3372 setup_visible_name(fw, False);
3373 BroadcastWindowIconNames(fw, True, False);
3375 /* fix the name in the title bar */
3376 if (!IS_ICONIFIED(fw))
3378 border_draw_decorations(
3379 fw, PART_TITLE, (Scr.Hilite == fw), True,
3380 CLEAR_ALL, NULL, NULL);
3382 EWMH_SetVisibleName(fw, False);
3384 * if the icon name is NoName, set the name of the icon to be
3385 * the same as the window
3387 if (!WAS_ICON_NAME_PROVIDED(fw))
3389 fw->icon_name = fw->name;
3390 setup_visible_name(fw, True);
3391 BroadcastWindowIconNames(fw, False, True);
3392 RedoIconName(fw);
3394 break;
3396 case XA_WM_ICON_NAME:
3397 flush_property_notify(XA_WM_ICON_NAME, FW_W(fw));
3398 if (HAS_EWMH_WM_ICON_NAME(fw))
3400 return;
3402 FlocaleGetNameProperty(
3403 XGetWMIconName, dpy, FW_W(fw), &new_name);
3404 if (new_name.name == NULL)
3406 FlocaleFreeNameProperty(&new_name);
3407 return;
3409 if (new_name.name && strlen(new_name.name) > MAX_ICON_NAME_LEN)
3411 /* limit to prevent hanging X server */
3412 (new_name.name)[MAX_ICON_NAME_LEN] = 0;
3414 if (fw->icon_name.name &&
3415 strcmp(new_name.name, fw->icon_name.name) == 0)
3417 /* migo: some apps update their names every second */
3418 /* griph: make sure we don't free the property if it
3419 is THE same name */
3420 if (new_name.name != fw->icon_name.name)
3422 FlocaleFreeNameProperty(&new_name);
3424 return;
3427 free_window_names(fw, False, True);
3428 fw->icon_name = new_name;
3429 SET_WAS_ICON_NAME_PROVIDED(fw, 1);
3430 if (fw->icon_name.name == NULL)
3432 /* currently never happens */
3433 fw->icon_name.name = fw->name.name;
3434 SET_WAS_ICON_NAME_PROVIDED(fw, 0);
3436 setup_visible_name(fw, True);
3437 BroadcastWindowIconNames(fw, False, True);
3438 RedoIconName(fw);
3439 EWMH_SetVisibleName(fw, True);
3440 break;
3442 case XA_WM_HINTS:
3443 flush_property_notify(XA_WM_HINTS, FW_W(fw));
3444 /* clasen@mathematik.uni-freiburg.de - 02/01/1998 - new -
3445 * the urgency flag is an ICCCM 2.0 addition to the WM_HINTS.
3447 old_wmhints_flags = 0;
3448 if (fw->wmhints)
3450 old_wmhints_flags = fw->wmhints->flags;
3451 XFree ((char *) fw->wmhints);
3453 setup_wm_hints(fw);
3454 if (fw->wmhints == NULL)
3456 return;
3460 * rebuild icon if the client either provides an icon
3461 * pixmap or window or has reset the hints to `no icon'.
3463 if ((fw->wmhints->flags & IconPixmapHint) ||
3464 (old_wmhints_flags & IconPixmapHint))
3466 ICON_DBG((stderr, "hpn: iph changed (%d) '%s'\n", !!(int)(fw->wmhints->flags & IconPixmapHint), fw->name));
3467 has_icon_pixmap_hint_changed = True;
3469 if ((fw->wmhints->flags & IconWindowHint) ||
3470 (old_wmhints_flags & IconWindowHint))
3472 ICON_DBG((stderr, "hpn: iwh changed (%d) '%s'\n", !!(int)(fw->wmhints->flags & IconWindowHint), fw->name));
3473 has_icon_window_hint_changed = True;
3474 SET_USE_EWMH_ICON(fw, False);
3476 increase_icon_hint_count(fw);
3477 if (has_icon_window_hint_changed ||
3478 has_icon_pixmap_hint_changed)
3480 if (ICON_OVERRIDE_MODE(fw) == ICON_OVERRIDE)
3482 ICON_DBG((stderr, "hpn: icon override '%s'\n", fw->name));
3483 has_icon_changed = False;
3485 else if (ICON_OVERRIDE_MODE(fw) ==
3486 NO_ACTIVE_ICON_OVERRIDE)
3488 if (has_icon_pixmap_hint_changed)
3490 if (WAS_ICON_HINT_PROVIDED(fw) ==
3491 ICON_HINT_MULTIPLE)
3493 ICON_DBG((stderr, "hpn: using further iph '%s'\n", fw->name));
3494 has_icon_changed = True;
3496 else if (fw->icon_bitmap_file ==
3497 NULL ||
3498 fw->icon_bitmap_file ==
3499 Scr.DefaultIcon)
3501 ICON_DBG((stderr, "hpn: using first iph '%s'\n", fw->name));
3502 has_icon_changed = True;
3504 else
3506 /* ignore the first icon pixmap
3507 * hint if the application did
3508 * not provide it from the
3509 * start */
3510 ICON_DBG((stderr, "hpn: first iph ignored '%s'\n", fw->name));
3511 has_icon_changed = False;
3514 else if (has_icon_window_hint_changed)
3516 ICON_DBG((stderr, "hpn: using iwh '%s'\n", fw->name));
3517 has_icon_changed = True;
3519 else
3521 ICON_DBG((stderr, "hpn: iwh not changed, hint ignored '%s'\n", fw->name));
3522 has_icon_changed = False;
3525 else /* NO_ICON_OVERRIDE */
3527 ICON_DBG((stderr, "hpn: using hint '%s'\n", fw->name));
3528 has_icon_changed = True;
3531 if (USE_EWMH_ICON(fw))
3533 has_icon_changed = False;
3536 if (has_icon_changed)
3538 ICON_DBG((stderr, "hpn: icon changed '%s'\n", fw->name));
3539 /* Okay, the icon hint has changed and style
3540 * options tell us to honour this change. Now
3541 * let's see if we have to use the application
3542 * provided pixmap or window (if any), the icon
3543 * file provided by the window's style or the
3544 * default style's icon. */
3545 if (fw->icon_bitmap_file == Scr.DefaultIcon)
3547 fw->icon_bitmap_file = NULL;
3549 if (!fw->icon_bitmap_file &&
3550 !(fw->wmhints->flags &
3551 (IconPixmapHint|IconWindowHint)))
3553 fw->icon_bitmap_file =
3554 (Scr.DefaultIcon) ?
3555 Scr.DefaultIcon : NULL;
3557 fw->iconPixmap = (Window)NULL;
3558 ChangeIconPixmap(fw);
3562 /* clasen@mathematik.uni-freiburg.de - 02/01/1998 - new -
3563 * the urgency flag is an ICCCM 2.0 addition to the WM_HINTS.
3564 * Treat urgency changes by calling user-settable functions.
3565 * These could e.g. deiconify and raise the window or
3566 * temporarily change the decor. */
3567 if (!(old_wmhints_flags & XUrgencyHint) &&
3568 (fw->wmhints->flags & XUrgencyHint))
3570 urgency_action = "Function UrgencyFunc";
3572 if ((old_wmhints_flags & XUrgencyHint) &&
3573 !(fw->wmhints->flags & XUrgencyHint))
3575 urgency_action = "Function UrgencyDoneFunc";
3577 if (urgency_action)
3579 const exec_context_t *exc;
3580 exec_context_changes_t ecc;
3582 ecc.w.fw = fw;
3583 ecc.w.wcontext = C_WINDOW;
3584 exc = exc_clone_context(
3585 ea->exc, &ecc, ECC_FW | ECC_WCONTEXT);
3586 execute_function(NULL, exc, urgency_action, 0);
3587 exc_destroy_context(exc);
3589 break;
3590 case XA_WM_NORMAL_HINTS:
3591 /* just mark wm normal hints as changed and look them up when
3592 * the next ConfigureRequest w/ x, y, width or height set
3593 * arrives. */
3594 SET_HAS_NEW_WM_NORMAL_HINTS(fw, 1);
3595 break;
3596 default:
3597 if (te->xproperty.atom == _XA_WM_PROTOCOLS)
3599 FetchWmProtocols (fw);
3601 else if (te->xproperty.atom == _XA_WM_COLORMAP_WINDOWS)
3603 FetchWmColormapWindows (fw); /* frees old data */
3604 ReInstallActiveColormap();
3606 else if (te->xproperty.atom == _XA_WM_STATE)
3608 if (fw && OnThisPage && focus_is_focused(fw) &&
3609 FP_DO_FOCUS_ENTER(FW_FOCUS_POLICY(fw)))
3611 /* refresh the focus - why? */
3612 focus_force_refresh_focus(fw);
3615 else
3617 EWMH_ProcessPropertyNotify(ea->exc);
3619 break;
3623 void HandleReparentNotify(const evh_args_t *ea)
3625 const XEvent *te = ea->exc->x.etrigger;
3626 FvwmWindow * const fw = ea->exc->w.fw;
3628 if (!fw)
3630 return;
3632 if (te->xreparent.parent == Scr.Root)
3634 /* Ignore reparenting to the root window. In some cases these
3635 * events are selected although the window is no longer
3636 * managed. */
3637 return;
3639 if (te->xreparent.parent != FW_W_FRAME(fw))
3641 /* window was reparented by someone else, destroy the frame */
3642 SetMapStateProp(fw, WithdrawnState);
3643 EWMH_RestoreInitialStates(fw, te->type);
3644 if (!IS_TEAR_OFF_MENU(fw))
3646 XRemoveFromSaveSet(dpy, te->xreparent.window);
3647 XSelectInput(dpy, te->xreparent.window, NoEventMask);
3649 else
3651 XSelectInput(dpy, te->xreparent.window, XEVMASK_MENUW);
3653 discard_events(XEVMASK_FRAMEW);
3654 destroy_window(fw);
3655 EWMH_ManageKdeSysTray(te->xreparent.window, te->type);
3656 EWMH_WindowDestroyed();
3659 return;
3662 void HandleSelectionRequest(const evh_args_t *ea)
3664 icccm2_handle_selection_request(ea->exc->x.etrigger);
3666 return;
3669 void HandleSelectionClear(const evh_args_t *ea)
3671 icccm2_handle_selection_clear();
3673 return;
3676 void HandleShapeNotify(const evh_args_t *ea)
3678 FvwmWindow * const fw = ea->exc->w.fw;
3680 DBUG("HandleShapeNotify", "Routine Entered");
3682 if (FShapesSupported)
3684 const FShapeEvent *sev =
3685 (const FShapeEvent *)(ea->exc->x.etrigger);
3687 if (!fw)
3689 return;
3691 if (sev->kind != FShapeBounding)
3693 return;
3695 frame_setup_shape(
3696 fw, fw->g.frame.width, fw->g.frame.height, sev->shaped);
3697 GNOME_SetWinArea(fw);
3698 EWMH_SetFrameStrut(fw);
3699 if (!IS_ICONIFIED(fw))
3701 border_redraw_decorations(fw);
3705 return;
3708 void HandleUnmapNotify(const evh_args_t *ea)
3710 int dstx, dsty;
3711 Window dumwin;
3712 XEvent dummy;
3713 XEvent map_event;
3714 const XEvent *te = ea->exc->x.etrigger;
3715 int weMustUnmap;
3716 Bool focus_grabbed;
3717 Bool must_return = False;
3718 Bool do_map = False;
3719 FvwmWindow * const fw = ea->exc->w.fw;
3720 Window pw;
3721 Window cw;
3723 DBUG("HandleUnmapNotify", "Routine Entered");
3725 /* Don't ignore events as described below. */
3726 if (te->xunmap.event != te->xunmap.window &&
3727 (te->xunmap.event != Scr.Root || !te->xunmap.send_event))
3729 must_return = True;
3733 * The July 27, 1988 ICCCM spec states that a client wishing to switch
3734 * to WithdrawnState should send a synthetic UnmapNotify with the
3735 * event field set to (pseudo-)root, in case the window is already
3736 * unmapped (which is the case for fvwm for IconicState).
3737 * Unfortunately, we looked for the FvwmContext using that field, so
3738 * try the window field also. */
3739 weMustUnmap = 0;
3740 if (!fw)
3742 weMustUnmap = 1;
3743 if (XFindContext(
3744 dpy, te->xunmap.window, FvwmContext,
3745 (caddr_t *)&fw) == XCNOENT)
3747 return;
3750 cw = FW_W(fw);
3751 pw = FW_W_PARENT(fw);
3752 if (te->xunmap.window == FW_W_FRAME(fw))
3754 SET_ICONIFY_PENDING(fw , 0);
3755 return;
3757 if (must_return)
3759 return;
3762 if (weMustUnmap)
3764 Bool is_map_request_pending;
3765 check_if_event_args args;
3767 args.w = te->xunmap.window;
3768 args.do_return_true = False;
3769 args.do_return_true_cr = False;
3770 /* Using FCheckTypedWindowEvent() does not work here. I don't
3771 * have the slightest idea why, but using FCheckIfEvent() with
3772 * the appropriate predicate procedure works fine. */
3773 FCheckIfEvent(dpy, &dummy, test_map_request, (XPointer)&args);
3774 /* Unfortunately, there is no procedure in X that simply tests
3775 * if an event of a certain type in on the queue without
3776 * waiting and without removing it from the queue.
3777 * XCheck...Event() does not wait but removes the event while
3778 * XPeek...() does not remove the event but waits. To solve
3779 * this, the predicate procedure sets a flag in the passed in
3780 * structure and returns False unconditionally. */
3781 is_map_request_pending = (args.ret_does_match == True);
3782 if (!is_map_request_pending)
3784 XUnmapWindow(dpy, te->xunmap.window);
3787 if (fw == Scr.Hilite)
3789 Scr.Hilite = NULL;
3791 focus_grabbed = focus_query_close_release_focus(fw);
3792 restore_focus_after_unmap(fw, False);
3793 if (!IS_MAPPED(fw) && !IS_ICONIFIED(fw))
3795 return;
3799 * The program may have unmapped the client window, from either
3800 * NormalState or IconicState. Handle the transition to WithdrawnState.
3802 * We need to reparent the window back to the root (so that fvwm exiting
3803 * won't cause it to get mapped) and then throw away all state (pretend
3804 * that we've received a DestroyNotify).
3806 if (!FCheckTypedWindowEvent(
3807 dpy, te->xunmap.window, DestroyNotify, &dummy) &&
3808 XTranslateCoordinates(
3809 dpy, te->xunmap.window, Scr.Root, 0, 0, &dstx, &dsty,
3810 &dumwin))
3812 MyXGrabServer(dpy);
3813 SetMapStateProp(fw, WithdrawnState);
3814 EWMH_RestoreInitialStates(fw, te->type);
3815 if (FCheckTypedWindowEvent(
3816 dpy, te->xunmap.window, ReparentNotify, &dummy))
3818 if (fw->attr_backup.border_width)
3820 XSetWindowBorderWidth(
3821 dpy, te->xunmap.window,
3822 fw->attr_backup.border_width);
3824 if ((!IS_ICON_SUPPRESSED(fw))&&
3825 (fw->wmhints &&
3826 (fw->wmhints->flags & IconWindowHint)))
3828 XUnmapWindow(dpy, fw->wmhints->icon_window);
3831 else
3833 RestoreWithdrawnLocation(fw, False, Scr.Root);
3835 if (!IS_TEAR_OFF_MENU(fw))
3837 XRemoveFromSaveSet(dpy, te->xunmap.window);
3838 XSelectInput(dpy, te->xunmap.window, NoEventMask);
3840 XSync(dpy, 0);
3841 MyXUngrabServer(dpy);
3842 if (FCheckTypedWindowEvent(dpy, pw, MapRequest, &map_event))
3844 /* the client tried to map the window again while it
3845 * was still inside the decoration windows */
3846 do_map = True;
3849 destroy_window(fw);
3850 if (focus_grabbed == True)
3852 CoerceEnterNotifyOnCurrentWindow();
3854 EWMH_ManageKdeSysTray(te->xunmap.window, te->type);
3855 EWMH_WindowDestroyed();
3856 GNOME_SetClientList();
3857 if (do_map == True)
3859 map_event.xmaprequest.window = cw;
3860 map_event.xmaprequest.parent = Scr.Root;
3861 dispatch_event(&map_event);
3862 /* note: we really should handle all map and unmap notify
3863 * events for that window in a loop here */
3866 return;
3869 void HandleVisibilityNotify(const evh_args_t *ea)
3871 FvwmWindow * const fw = ea->exc->w.fw;
3873 DBUG("HandleVisibilityNotify", "Routine Entered");
3875 if (fw && ea->exc->x.etrigger->xvisibility.window == FW_W_FRAME(fw))
3877 switch (ea->exc->x.etrigger->xvisibility.state)
3879 case VisibilityUnobscured:
3880 SET_FULLY_VISIBLE(fw, 1);
3881 SET_PARTIALLY_VISIBLE(fw, 1);
3882 break;
3883 case VisibilityPartiallyObscured:
3884 SET_FULLY_VISIBLE(fw, 0);
3885 SET_PARTIALLY_VISIBLE(fw, 1);
3886 break;
3887 default:
3888 SET_FULLY_VISIBLE(fw, 0);
3889 SET_PARTIALLY_VISIBLE(fw, 0);
3890 break;
3892 /* Make sure the button grabs are up to date */
3893 focus_grab_buttons(fw);
3896 return;
3899 /* ---------------------------- interface functions ------------------------ */
3901 /* Inform a client window of its geometry.
3903 * The input (frame) geometry will be translated to client geometry
3904 * before sending. */
3905 void SendConfigureNotify(
3906 FvwmWindow *fw, int x, int y, int w, int h, int bw,
3907 Bool send_for_frame_too)
3909 XEvent client_event;
3910 size_borders b;
3912 if (!fw || IS_SHADED(fw))
3914 return;
3916 client_event.type = ConfigureNotify;
3917 client_event.xconfigure.display = dpy;
3918 client_event.xconfigure.event = FW_W(fw);
3919 client_event.xconfigure.window = FW_W(fw);
3920 get_window_borders(fw, &b);
3921 client_event.xconfigure.x = x + b.top_left.width;
3922 client_event.xconfigure.y = y + b.top_left.height;
3923 client_event.xconfigure.width = w - b.total_size.width;
3924 client_event.xconfigure.height = h - b.total_size.height;
3925 client_event.xconfigure.border_width = bw;
3926 client_event.xconfigure.above = FW_W_FRAME(fw);
3927 client_event.xconfigure.override_redirect = False;
3928 #if 0
3929 fprintf(stderr,
3930 "send cn: %d %d %dx%d fw 0x%08x w 0x%08x ew 0x%08x '%s'\n",
3931 client_event.xconfigure.x, client_event.xconfigure.y,
3932 client_event.xconfigure.width, client_event.xconfigure.height,
3933 (int)FW_W_FRAME(fw), (int)FW_W(fw),
3934 (int)client_event.xconfigure.window,
3935 (fw->name.name) ? fw->name.name : "");
3936 #endif
3937 FSendEvent(
3938 dpy, FW_W(fw), False, StructureNotifyMask, &client_event);
3939 if (send_for_frame_too)
3941 /* This is for buggy tk, which waits for the real
3942 * ConfigureNotify on frame instead of the synthetic one on w.
3943 * The geometry data in the event will not be correct for the
3944 * frame, but tk doesn't look at that data anyway. */
3945 client_event.xconfigure.event = FW_W_FRAME(fw);
3946 client_event.xconfigure.window = FW_W_FRAME(fw);
3947 FSendEvent(
3948 dpy, FW_W_FRAME(fw), False, StructureNotifyMask,
3949 &client_event);
3952 return;
3955 /* Add an event group to the event handler */
3956 int register_event_group(int event_base, int event_count, PFEH *jump_table)
3958 /* insert into the list */
3959 event_group_t *group;
3960 event_group_t *position = base_event_group;
3961 event_group_t *prev_position = NULL;
3963 while (
3964 position != NULL &&
3965 position->base + position->count < event_base)
3967 prev_position = position;
3968 position = position->next;
3970 if ((position != NULL && position->base < event_base + event_count))
3972 /* there is already an event group registered at the specified
3973 * event range, or the base is before the base X events */
3975 return 1;
3977 /* create the group structure (these are not freed until fvwm exits) */
3978 group = (event_group_t*)safemalloc(sizeof(event_group_t));
3979 group->base = event_base;
3980 group->count = event_count;
3981 group->jump_table = jump_table;
3982 group->next = position;
3983 if (prev_position != NULL)
3985 prev_position->next = group;
3987 else
3989 base_event_group = group;
3992 return 0;
3996 ** Procedure:
3997 ** InitEventHandlerJumpTable
3999 void InitEventHandlerJumpTable(void)
4001 static PFEH EventHandlerJumpTable[LASTEvent];
4002 int i;
4004 for (i=0; i<LASTEvent; i++)
4006 EventHandlerJumpTable[i] = NULL;
4008 EventHandlerJumpTable[Expose] = HandleExpose;
4009 EventHandlerJumpTable[DestroyNotify] = HandleDestroyNotify;
4010 EventHandlerJumpTable[MapRequest] = HandleMapRequest;
4011 EventHandlerJumpTable[MapNotify] = HandleMapNotify;
4012 EventHandlerJumpTable[UnmapNotify] = HandleUnmapNotify;
4013 EventHandlerJumpTable[ButtonPress] = HandleButtonPress;
4014 EventHandlerJumpTable[EnterNotify] = HandleEnterNotify;
4015 EventHandlerJumpTable[LeaveNotify] = HandleLeaveNotify;
4016 EventHandlerJumpTable[FocusIn] = HandleFocusIn;
4017 EventHandlerJumpTable[FocusOut] = HandleFocusOut;
4018 EventHandlerJumpTable[ConfigureRequest] = HandleConfigureRequest;
4019 EventHandlerJumpTable[ClientMessage] = HandleClientMessage;
4020 EventHandlerJumpTable[PropertyNotify] = HandlePropertyNotify;
4021 EventHandlerJumpTable[KeyPress] = HandleKeyPress;
4022 EventHandlerJumpTable[KeyRelease] = HandleKeyRelease;
4023 EventHandlerJumpTable[VisibilityNotify] = HandleVisibilityNotify;
4024 EventHandlerJumpTable[ColormapNotify] = HandleColormapNotify;
4025 EventHandlerJumpTable[SelectionClear] = HandleSelectionClear;
4026 EventHandlerJumpTable[SelectionRequest] = HandleSelectionRequest;
4027 EventHandlerJumpTable[ReparentNotify] = HandleReparentNotify;
4028 EventHandlerJumpTable[MappingNotify] = HandleMappingNotify;
4029 STROKE_CODE(EventHandlerJumpTable[ButtonRelease] = HandleButtonRelease);
4030 STROKE_CODE(EventHandlerJumpTable[MotionNotify] = HandleMotionNotify);
4031 #ifdef MOUSE_DROPPINGS
4032 STROKE_CODE(stroke_init(dpy,DefaultRootWindow(dpy)));
4033 #else /* no MOUSE_DROPPINGS */
4034 STROKE_CODE(stroke_init());
4035 #endif /* MOUSE_DROPPINGS */
4036 if (register_event_group(0, LASTEvent, EventHandlerJumpTable))
4038 /* should never happen */
4039 fvwm_msg(ERR, "InitEventHandlerJumpTable",
4040 "Faild to initialize event handlers");
4041 exit(1);
4043 if (FShapesSupported)
4045 static PFEH shape_jump_table[FShapeNumberEvents];
4047 for (i = 0; i < FShapeNumberEvents; i++)
4049 shape_jump_table[i] = NULL;
4051 shape_jump_table[FShapeNotify] = HandleShapeNotify;
4052 if (
4053 register_event_group(
4054 FShapeEventBase, FShapeNumberEvents,
4055 shape_jump_table))
4057 fvwm_msg(ERR, "InitEventHandlerJumpTable",
4058 "Faild to init Shape event handler");
4063 return;
4066 /* handle a single X event */
4067 void dispatch_event(XEvent *e)
4069 Window w = e->xany.window;
4070 FvwmWindow *fw;
4071 event_group_t *event_group;
4073 DBUG("dispatch_event", "Routine Entered");
4075 XFlush(dpy);
4076 if (w == Scr.Root)
4078 switch (e->type)
4080 case ButtonPress:
4081 case ButtonRelease:
4082 if (e->xbutton.subwindow != None)
4084 w = e->xbutton.subwindow;
4086 case MapRequest:
4087 w = e->xmaprequest.window;
4088 break;
4089 default:
4090 break;
4093 if (w == Scr.Root ||
4094 XFindContext(dpy, w, FvwmContext, (caddr_t *)&fw) == XCNOENT)
4096 fw = NULL;
4098 last_event_type = e->type;
4099 event_group = base_event_group;
4100 while (
4101 event_group != NULL &&
4102 event_group->base + event_group->count < e->type)
4104 event_group = event_group->next;
4107 if (
4108 event_group != NULL &&
4109 e->type - event_group->base < event_group->count &&
4110 event_group->jump_table[e->type - event_group->base] != NULL)
4112 evh_args_t ea;
4113 exec_context_changes_t ecc;
4114 Window dummyw;
4116 ecc.type = EXCT_EVENT;
4117 ecc.x.etrigger = e;
4118 ecc.w.wcontext = GetContext(&fw, fw, e, &dummyw);
4119 ecc.w.w = w;
4120 ecc.w.fw = fw;
4121 ea.exc = exc_create_context(
4122 &ecc, ECC_TYPE | ECC_ETRIGGER | ECC_FW | ECC_W |
4123 ECC_WCONTEXT);
4124 (*event_group->jump_table[e->type - event_group->base])(&ea);
4125 exc_destroy_context(ea.exc);
4128 #ifdef C_ALLOCA
4129 /* If we're using the C version of alloca, see if anything needs to be
4130 * freed up.
4132 alloca(0);
4133 #endif
4134 DBUG("dispatch_event", "Leaving Routine");
4136 return;
4139 /* ewmh configure request */
4140 void events_handle_configure_request(
4141 XConfigureRequestEvent cre, FvwmWindow *fw, Bool force,
4142 int force_gravity)
4144 __handle_configure_request(cre, NULL, fw, force, force_gravity);
4146 return;
4149 void HandleEvents(void)
4151 XEvent ev;
4153 DBUG("HandleEvents", "Routine Entered");
4154 STROKE_CODE(send_motion = False);
4155 while (!isTerminated)
4157 last_event_type = 0;
4158 if (Scr.flags.is_window_scheduled_for_destroy)
4160 destroy_scheduled_windows();
4162 if (Scr.flags.do_need_window_update)
4164 flush_window_updates();
4166 if (My_XNextEvent(dpy, &ev))
4168 dispatch_event(&ev);
4170 if (Scr.flags.do_need_style_list_update)
4172 simplify_style_list();
4176 return;
4181 * Waits for next X or module event, fires off startup routines when startup
4182 * modules have finished or after a timeout if the user has specified a
4183 * command line module that doesn't quit or gets stuck.
4186 int My_XNextEvent(Display *dpy, XEvent *event)
4188 fd_set in_fdset, out_fdset;
4189 int num_fd;
4190 fmodule_list_itr moditr;
4191 fmodule *module;
4192 fmodule_input *input;
4193 static struct timeval timeout;
4194 static struct timeval *timeoutP = &timeout;
4196 DBUG("My_XNextEvent", "Routine Entered");
4198 /* check for any X events already queued up.
4199 * Side effect: this does an XFlush if no events are queued
4200 * Make sure nothing between here and the select causes further
4201 * X requests to be sent or the select may block even though
4202 * there are events in the queue */
4203 if (FPending(dpy))
4205 DBUG(
4206 "My_XNextEvent", "taking care of queued up events"
4207 " & returning (1)");
4208 FNextEvent(dpy, event);
4209 return 1;
4212 /* check for termination of all startup modules */
4213 if (fFvwmInStartup)
4215 module_list_itr_init(&moditr);
4216 module = module_list_itr_next(&moditr);
4217 for (; module != NULL; module = module_list_itr_next(&moditr))
4219 if (MOD_IS_CMDLINE(module) == 1)
4221 break;
4224 module_cleanup();
4225 if (module == NULL)
4227 /* last module */
4228 DBUG(
4229 "My_XNextEvent",
4230 "Starting up after command lines modules");
4231 /* set an infinite timeout to stop ticking */
4232 timeoutP = NULL;
4233 /* This may cause X requests to be sent */
4234 StartupStuff();
4236 return 0; /* so return without select()ing */
4240 /* Some signals can interrupt us while we wait for any action
4241 * on our descriptors. While some of these signals may be asking
4242 * fvwm to die, some might be harmless. Harmless interruptions
4243 * mean we have to start waiting all over again ... */
4246 int ms;
4247 Bool is_waiting_for_scheduled_command = False;
4248 static struct timeval *old_timeoutP = NULL;
4250 /* The timeouts become undefined whenever the select returns,
4251 * and so we have to reinitialise them */
4252 ms = squeue_get_next_ms();
4253 if (ms == 0)
4255 /* run scheduled commands */
4256 squeue_execute();
4257 ms = squeue_get_next_ms();
4258 /* should not happen anyway.
4259 * get_next_schedule_queue_ms() can't return 0 after a
4260 * call to execute_schedule_queue(). */
4261 if (ms == 0)
4263 ms = 1;
4266 if (ms < 0)
4268 timeout.tv_sec = 42;
4269 timeout.tv_usec = 0;
4271 else
4273 /* scheduled commands are pending - don't wait too
4274 * long */
4275 timeout.tv_sec = ms / 1000;
4276 timeout.tv_usec = 1000 * (ms % 1000);
4277 old_timeoutP = timeoutP;
4278 timeoutP = &timeout;
4279 is_waiting_for_scheduled_command = True;
4282 FD_ZERO(&in_fdset);
4283 FD_ZERO(&out_fdset);
4284 FD_SET(x_fd, &in_fdset);
4286 /* nothing is done here if fvwm was compiled without session
4287 * support */
4288 if (sm_fd >= 0)
4290 FD_SET(sm_fd, &in_fdset);
4293 module_list_itr_init(&moditr);
4294 while ( (module = module_list_itr_next(&moditr)) != NULL)
4296 FD_SET(MOD_READFD(module), &in_fdset);
4298 if (!FQUEUE_IS_EMPTY(&MOD_PIPEQUEUE(module)))
4300 FD_SET(MOD_WRITEFD(module), &out_fdset);
4304 DBUG("My_XNextEvent", "waiting for module input/output");
4305 num_fd = fvwmSelect(
4306 fvwmlib_max_fd, &in_fdset, &out_fdset, 0, timeoutP);
4307 if (is_waiting_for_scheduled_command)
4309 timeoutP = old_timeoutP;
4312 /* Express route out of fvwm ... */
4313 if (isTerminated)
4315 return 0;
4317 } while (num_fd < 0);
4319 if (num_fd > 0)
4321 /* Check for module input. */
4322 module_list_itr_init(&moditr);
4323 while ( (module = module_list_itr_next(&moditr)) != NULL)
4325 if (FD_ISSET(MOD_READFD(module), &in_fdset))
4327 input = module_receive(module);
4328 /* enqueue the received command */
4329 module_input_enqueue(input);
4331 if (
4332 MOD_WRITEFD(module) >= 0 &&
4333 FD_ISSET(MOD_WRITEFD(module), &out_fdset))
4335 DBUG("My_XNextEvent",
4336 "calling FlushMessageQueue");
4337 FlushMessageQueue(module);
4341 /* execute any commands queued up */
4342 DBUG("My_XNextEvent", "executing module comand queue");
4343 ExecuteCommandQueue();
4345 /* cleanup dead modules */
4346 module_cleanup();
4348 /* nothing is done here if fvwm was compiled without session
4349 * support */
4350 if ((sm_fd >= 0) && (FD_ISSET(sm_fd, &in_fdset)))
4352 ProcessICEMsgs();
4356 else
4358 /* select has timed out, things must have calmed down so let's
4359 * decorate */
4360 if (fFvwmInStartup)
4362 fvwm_msg(ERR, "My_XNextEvent",
4363 "Some command line modules have not quit, "
4364 "Starting up after timeout.\n");
4365 StartupStuff();
4366 timeoutP = NULL; /* set an infinite timeout to stop
4367 * ticking */
4368 reset_style_changes();
4369 Scr.flags.do_need_window_update = 0;
4371 /* run scheduled commands if necessary */
4372 squeue_execute();
4375 /* check for X events again, rather than return 0 and get called again
4377 if (FPending(dpy))
4379 DBUG("My_XNextEvent",
4380 "taking care of queued up events & returning (2)");
4381 FNextEvent(dpy,event);
4382 return 1;
4385 DBUG("My_XNextEvent", "leaving My_XNextEvent");
4386 return 0;
4391 * Procedure:
4392 * Find the Fvwm context for the event.
4395 int GetContext(FvwmWindow **ret_fw, FvwmWindow *t, const XEvent *e, Window *w)
4397 int context;
4398 Window win;
4399 Window subw = None;
4400 int x = 0;
4401 int y = 0;
4402 Bool is_key_event = False;
4404 win = e->xany.window;
4405 context = C_NO_CONTEXT;
4406 switch (e->type)
4408 case KeyPress:
4409 case KeyRelease:
4410 x = e->xkey.x;
4411 y = e->xkey.y;
4412 subw = e->xkey.subwindow;
4413 if (win == Scr.Root && subw != None)
4415 /* Translate root coordinates into subwindow
4416 * coordinates. Necessary for key bindings that work
4417 * over unfocused windows. */
4418 win = subw;
4419 XTranslateCoordinates(
4420 dpy, Scr.Root, subw, x, y, &x, &y, &subw);
4421 XFindContext(dpy, win, FvwmContext, (caddr_t *) &t);
4423 is_key_event = True;
4424 /* fall through */
4425 case ButtonPress:
4426 case ButtonRelease:
4427 if (!is_key_event)
4429 x = e->xbutton.x;
4430 y = e->xbutton.y;
4431 subw = e->xbutton.subwindow;
4433 if (t && win == FW_W_FRAME(t) && subw != None)
4435 /* Translate frame coordinates into subwindow
4436 * coordinates. */
4437 win = subw;
4438 XTranslateCoordinates(
4439 dpy, FW_W_FRAME(t), subw, x, y, &x, &y, &subw);
4440 if (win == FW_W_PARENT(t))
4442 win = subw;
4443 XTranslateCoordinates(
4444 dpy, FW_W_PARENT(t), subw, x, y, &x,
4445 &y, &subw);
4448 break;
4449 default:
4450 XFindContext(dpy, win, FvwmContext, (caddr_t *)&t);
4451 break;
4453 if (ret_fw != NULL)
4455 *ret_fw = t;
4457 if (!t)
4459 return C_ROOT;
4461 *w = win;
4462 if (*w == Scr.NoFocusWin)
4464 return C_ROOT;
4466 if (subw != None)
4468 if (win == FW_W_PARENT(t))
4470 *w = subw;
4473 if (*w == Scr.Root)
4475 return C_ROOT;
4477 context = frame_window_id_to_context(t, *w, &Button);
4479 return context;
4484 * Removes expose events for a specific window from the queue
4487 int flush_expose(Window w)
4489 XEvent dummy;
4490 int i=0;
4492 while (FCheckTypedWindowEvent(dpy, w, Expose, &dummy))
4494 i++;
4497 return i;
4500 /* same as above, but merges the expose rectangles into a single big one */
4501 int flush_accumulate_expose(Window w, XEvent *e)
4503 XEvent dummy;
4504 int i = 0;
4505 int x1 = e->xexpose.x;
4506 int y1 = e->xexpose.y;
4507 int x2 = x1 + e->xexpose.width;
4508 int y2 = y1 + e->xexpose.height;
4510 while (FCheckTypedWindowEvent(dpy, w, Expose, &dummy))
4512 x1 = min(x1, dummy.xexpose.x);
4513 y1 = min(y1, dummy.xexpose.y);
4514 x2 = max(x2, dummy.xexpose.x + dummy.xexpose.width);
4515 y2 = max(y2, dummy.xexpose.y + dummy.xexpose.height);
4516 i++;
4518 e->xexpose.x = x1;
4519 e->xexpose.y = y1;
4520 e->xexpose.width = x2 - x1;
4521 e->xexpose.height = y2 - y1;
4523 return i;
4528 * Removes all expose events from the queue and does the necessary redraws
4531 void handle_all_expose(void)
4533 void *saved_event;
4534 XEvent evdummy;
4536 saved_event = fev_save_event();
4537 FPending(dpy);
4538 while (FCheckMaskEvent(dpy, ExposureMask, &evdummy))
4540 dispatch_event(&evdummy);
4542 fev_restore_event(saved_event);
4544 return;
4547 /* CoerceEnterNotifyOnCurrentWindow()
4548 * Pretends to get a HandleEnterNotify on the window that the pointer
4549 * currently is in so that the focus gets set correctly from the beginning.
4550 * Note that this presently only works if the current window is not
4551 * click_to_focus; I think that that behaviour is correct and desirable.
4552 * --11/08/97 gjb */
4553 void CoerceEnterNotifyOnCurrentWindow(void)
4555 Window child;
4556 Window root;
4557 Bool f;
4558 evh_args_t ea;
4559 exec_context_changes_t ecc;
4560 XEvent e;
4561 FvwmWindow *fw;
4563 f = FQueryPointer(
4564 dpy, Scr.Root, &root, &child, &e.xcrossing.x_root,
4565 &e.xcrossing.y_root, &e.xcrossing.x, &e.xcrossing.y,
4566 &JunkMask);
4567 if (f == False || child == None)
4569 return;
4571 e.xcrossing.type = EnterNotify;
4572 e.xcrossing.window = child;
4573 e.xcrossing.subwindow = None;
4574 e.xcrossing.mode = NotifyNormal;
4575 e.xcrossing.detail = NotifyAncestor;
4576 e.xcrossing.same_screen = True;
4577 if (XFindContext(dpy, child, FvwmContext, (caddr_t *)&fw) == XCNOENT)
4579 fw = NULL;
4581 else
4583 XTranslateCoordinates(
4584 dpy, Scr.Root, child, e.xcrossing.x_root,
4585 e.xcrossing.y_root, &JunkX, &JunkY, &child);
4586 if (child == FW_W_PARENT(fw))
4588 child = FW_W(fw);
4590 if (child != None)
4592 e.xany.window = child;
4595 e.xcrossing.focus = (fw == get_focus_window()) ? True : False;
4596 ecc.type = EXCT_NULL;
4597 ecc.x.etrigger = &e;
4598 ea.exc = exc_create_context(&ecc, ECC_TYPE | ECC_ETRIGGER);
4599 HandleEnterNotify(&ea);
4600 exc_destroy_context(ea.exc);
4602 return;
4605 /* This function discards all queued up ButtonPress, ButtonRelease and
4606 * ButtonMotion events. */
4607 int discard_events(long event_mask)
4609 XEvent e;
4610 int count;
4612 XSync(dpy, 0);
4613 for (count = 0; FCheckMaskEvent(dpy, event_mask, &e); count++)
4615 /* nothing */
4618 return count;
4621 /* This function discards all queued up ButtonPress, ButtonRelease and
4622 * ButtonMotion events. */
4623 int discard_window_events(Window w, long event_mask)
4625 XEvent e;
4626 int count;
4628 XSync(dpy, 0);
4629 for (count = 0; FCheckWindowEvent(dpy, w, event_mask, &e); count++)
4631 /* nothing */
4634 return count;
4637 /* Similar function for certain types of PropertyNotify. */
4638 int flush_property_notify(Atom atom, Window w)
4640 XEvent e;
4641 int count;
4642 test_typed_window_event_args args;
4644 count = 0;
4645 XSync(dpy, 0);
4646 args.w = w;
4647 args.atom = atom;
4648 args.event_type = PropertyNotify;
4650 /* Get rid of the events. */
4651 while (FCheckIfEvent(dpy, &e, test_typed_window_event, (XPointer)&args))
4652 count++;
4654 return count;
4657 /* Wait for all mouse buttons to be released
4658 * This can ease some confusion on the part of the user sometimes
4660 * Discard superflous button events during this wait period. */
4661 void WaitForButtonsUp(Bool do_handle_expose)
4663 unsigned int mask;
4664 unsigned int bmask;
4665 long evmask = ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|
4666 KeyPressMask|KeyReleaseMask;
4667 int count;
4668 int use_wait_cursor;
4669 XEvent e;
4671 if (FQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY,
4672 &JunkX, &JunkY, &mask) == False)
4674 /* pointer is on a different screen - that's okay here */
4676 mask &= DEFAULT_ALL_BUTTONS_MASK;
4677 if (mask == 0)
4679 return;
4681 if (do_handle_expose)
4683 evmask |= ExposureMask;
4685 GrabEm(None, GRAB_NORMAL);
4686 for (count = 0, use_wait_cursor = 0; mask != 0; count++)
4688 /* handle expose events */
4689 XAllowEvents(dpy, SyncPointer, CurrentTime);
4690 if (FCheckMaskEvent(dpy, evmask, &e))
4692 switch (e.type)
4694 case ButtonRelease:
4695 if (e.xbutton.button <=
4696 NUMBER_OF_MOUSE_BUTTONS)
4698 bmask = (Button1Mask <<
4699 (e.xbutton.button - 1));
4700 mask = e.xbutton.state & ~bmask;
4702 break;
4703 case Expose:
4704 dispatch_event(&e);
4705 break;
4706 default:
4707 break;
4710 else
4712 if (FQueryPointer(
4713 dpy, Scr.Root, &JunkRoot, &JunkChild,
4714 &JunkX, &JunkY, &JunkX, &JunkY, &mask) ==
4715 False)
4717 /* pointer is on a different screen - that's
4718 * okay here */
4720 mask &= DEFAULT_ALL_BUTTONS_MASK;
4721 usleep(1);
4723 if (use_wait_cursor == 0 && count == 20)
4725 GrabEm(CRS_WAIT, GRAB_NORMAL);
4726 use_wait_cursor = 1;
4729 UngrabEm(GRAB_NORMAL);
4730 if (use_wait_cursor)
4732 UngrabEm(GRAB_NORMAL);
4733 XFlush(dpy);
4736 return;
4739 void sync_server(int toggle)
4741 static Bool synced = False;
4743 if (toggle == -1)
4745 toggle = (synced == False);
4747 if (toggle == 1)
4749 synced = True;
4751 else
4753 synced = False;
4755 XSynchronize(dpy, synced);
4756 XFlush(dpy);
4758 return;
4761 Bool is_resizing_event_pending(
4762 FvwmWindow *fw)
4764 XEvent e;
4765 check_if_event_args args;
4767 args.w = FW_W(fw);
4768 args.do_return_true = False;
4769 args.do_return_true_cr = False;
4770 args.cr_value_mask = 0;
4771 args.ret_does_match = False;
4772 args.ret_type = 0;
4773 FCheckIfEvent(dpy, &e, test_resizing_event, (XPointer)&args);
4775 return args.ret_does_match;
4778 /* ---------------------------- builtin commands --------------------------- */
4780 void CMD_XSynchronize(F_CMD_ARGS)
4782 int toggle;
4784 toggle = ParseToggleArgument(action, NULL, -1, 0);
4785 sync_server(toggle);
4787 return;
4790 void CMD_XSync(F_CMD_ARGS)
4792 XSync(dpy, 0);
4794 return;