Reverted the gnustep commented code. it seems better with the patch, but still buggy
[wmaker-crm.git] / src / window.c
blob202c262ea2e29c2ee3ef49ca5b1426a9d39125a8
1 /* window.c - client window managing stuffs
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #ifdef SHAPE
28 #include <X11/extensions/shape.h>
29 #endif
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
38 #include "WindowMaker.h"
39 #include "GNUstep.h"
40 #include "wcore.h"
41 #include "framewin.h"
42 #include "texture.h"
43 #include "window.h"
44 #include "winspector.h"
45 #include "icon.h"
46 #include "properties.h"
47 #include "actions.h"
48 #include "client.h"
49 #include "funcs.h"
50 #include "keybind.h"
51 #include "stacking.h"
52 #include "defaults.h"
53 #include "workspace.h"
56 #ifdef MWM_HINTS
57 # include "motif.h"
58 #endif
59 #ifdef KWM_HINTS
60 # include "kwm.h"
61 #endif
62 #ifdef GNOME_STUFF
63 # include "gnome.h"
64 #endif
65 #ifdef OLWM_HINTS
66 # include "openlook.h"
67 #endif
69 /****** Global Variables ******/
71 extern WShortKey wKeyBindings[WKBD_LAST];
73 #ifdef SHAPE
74 extern Bool wShapeSupported;
75 #endif
77 /* contexts */
78 extern XContext wWinContext;
80 /* cursors */
81 extern Cursor wCursor[WCUR_LAST];
83 /* protocol atoms */
84 extern Atom _XA_WM_DELETE_WINDOW;
85 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
87 extern Atom _XA_WINDOWMAKER_STATE;
89 extern WPreferences wPreferences;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern Time LastTimestamp;
95 /* superfluous... */
96 extern void DoWindowBirth(WWindow*);
99 /***** Local Stuff *****/
102 static WWindowState *windowState=NULL;
106 /* local functions */
107 static FocusMode getFocusMode(WWindow *wwin);
109 static int getSavedState(Window window, WSavedState **state);
111 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
113 /* event handlers */
116 /* frame window (during window grabs) */
117 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
119 /* close button */
120 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
121 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
123 /* iconify button */
124 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
126 #ifdef XKB_BUTTON_HINT
127 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
128 #endif
130 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
131 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
133 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
136 /****** Notification Observers ******/
138 static void
139 appearanceObserver(void *self, WMNotification *notif)
141 WWindow *wwin = (WWindow*)self;
142 int flags = (int)WMGetNotificationClientData(notif);
144 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
145 return;
147 if (flags & WFontSettings) {
148 wWindowConfigureBorders(wwin);
149 if(wwin->flags.shaded) {
150 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
151 wwin->frame->top_width - 1);
153 wwin->client.y = wwin->frame_y - wwin->client.height
154 + wwin->frame->top_width;
155 wWindowSynthConfigureNotify(wwin);
158 if (flags & WTextureSettings) {
159 wwin->frame->flags.need_texture_remake = 1;
161 if (flags & (WTextureSettings | WColorSettings)) {
162 if (wwin->frame->titlebar)
163 XClearWindow(dpy, wwin->frame->titlebar->window);
165 wFrameWindowPaint(wwin->frame);
169 /************************************/
171 WWindow*
172 wWindowFor(Window window)
174 WObjDescriptor *desc;
176 if (window==None)
177 return NULL;
179 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
180 return NULL;
182 if (desc->parent_type==WCLASS_WINDOW)
183 return desc->parent;
184 else if (desc->parent_type==WCLASS_FRAME) {
185 WFrameWindow *frame = (WFrameWindow*)desc->parent;
186 if (frame->flags.is_client_window_frame)
187 return frame->child;
190 return NULL;
194 WWindow*
195 wWindowCreate()
197 WWindow *wwin;
199 wwin = wmalloc(sizeof(WWindow));
200 wretain(wwin);
202 memset(wwin, 0, sizeof(WWindow));
204 wwin->client_descriptor.handle_mousedown = frameMouseDown;
205 wwin->client_descriptor.parent = wwin;
206 wwin->client_descriptor.self = wwin;
207 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
209 return wwin;
213 void
214 wWindowDestroy(WWindow *wwin)
216 int i;
218 if (wwin->screen_ptr->cmap_window == wwin) {
219 wwin->screen_ptr->cmap_window = NULL;
222 WMRemoveNotificationObserver(wwin);
224 wwin->flags.destroyed = 1;
226 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
227 if (!wwin->screen_ptr->shortcutWindows[i])
228 continue;
230 WMRemoveFromBag(wwin->screen_ptr->shortcutWindows[i], wwin);
232 if (!WMGetBagItemCount(wwin->screen_ptr->shortcutWindows[i])) {
233 WMFreeBag(wwin->screen_ptr->shortcutWindows[i]);
234 wwin->screen_ptr->shortcutWindows[i] = NULL;
238 if (wwin->normal_hints)
239 XFree(wwin->normal_hints);
241 if (wwin->wm_hints)
242 XFree(wwin->wm_hints);
244 if (wwin->wm_instance)
245 XFree(wwin->wm_instance);
247 if (wwin->wm_class)
248 XFree(wwin->wm_class);
250 if (wwin->wm_gnustep_attr)
251 wfree(wwin->wm_gnustep_attr);
253 if (wwin->cmap_windows)
254 XFree(wwin->cmap_windows);
256 XDeleteContext(dpy, wwin->client_win, wWinContext);
258 if (wwin->frame)
259 wFrameWindowDestroy(wwin->frame);
261 if (wwin->icon) {
262 RemoveFromStackList(wwin->icon->core);
263 wIconDestroy(wwin->icon);
264 if (wPreferences.auto_arrange_icons)
265 wArrangeIcons(wwin->screen_ptr, True);
267 wrelease(wwin);
273 static void
274 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
276 if (gs_hints->flags & GSWindowStyleAttr) {
277 if (gs_hints->window_style == WMBorderlessWindowMask) {
278 wwin->client_flags.no_border = 1;
279 wwin->client_flags.no_titlebar = 1;
280 wwin->client_flags.no_closable = 1;
281 wwin->client_flags.no_miniaturizable = 1;
282 wwin->client_flags.no_resizable = 1;
283 wwin->client_flags.no_close_button = 1;
284 wwin->client_flags.no_miniaturize_button = 1;
285 wwin->client_flags.no_resizebar = 1;
286 } else {
287 wwin->client_flags.no_close_button =
288 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
290 wwin->client_flags.no_closable =
291 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
293 wwin->client_flags.no_miniaturize_button =
294 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
296 wwin->client_flags.no_miniaturizable =
297 wwin->client_flags.no_miniaturize_button;
299 wwin->client_flags.no_resizebar =
300 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
302 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
304 /* these attributes supposedly imply in the existence
305 * of a titlebar */
306 if (gs_hints->window_style & (WMResizableWindowMask|
307 WMClosableWindowMask|
308 WMMiniaturizableWindowMask)) {
309 wwin->client_flags.no_titlebar = 0;
310 } else {
311 wwin->client_flags.no_titlebar =
312 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
316 } else {
317 /* setup the defaults */
318 wwin->client_flags.no_border = 0;
319 wwin->client_flags.no_titlebar = 0;
320 wwin->client_flags.no_closable = 0;
321 wwin->client_flags.no_miniaturizable = 0;
322 wwin->client_flags.no_resizable = 0;
323 wwin->client_flags.no_close_button = 0;
324 wwin->client_flags.no_miniaturize_button = 0;
325 wwin->client_flags.no_resizebar = 0;
327 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
328 wwin->client_flags.no_appicon = 1;
333 void
334 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
335 WWindowAttributes *mask)
337 if (wflags->no_appicon && mask->no_appicon)
338 wflags->emulate_appicon = 0;
340 if (wwin->main_window!=None) {
341 WApplication *wapp = wApplicationOf(wwin->main_window);
342 if (wapp && !wapp->flags.emulated)
343 wflags->emulate_appicon = 0;
346 if (wwin->transient_for!=None
347 && wwin->transient_for!=wwin->screen_ptr->root_win)
348 wflags->emulate_appicon = 0;
350 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
351 wflags->sunken = 0;
356 void
357 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
359 WScreen *scr = wwin->screen_ptr;
361 /* sets global default stuff */
362 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
363 &wwin->client_flags, NULL, True);
365 * Decoration setting is done in this precedence (lower to higher)
366 * - use global default in the resource database
367 * - guess some settings
368 * - use GNUstep/external window attributes
369 * - set hints specified for the app in the resource DB
372 WSETUFLAG(wwin, broken_close, 0);
374 if (wwin->protocols.DELETE_WINDOW)
375 WSETUFLAG(wwin, kill_close, 0);
376 else
377 WSETUFLAG(wwin, kill_close, 1);
379 /* transients can't be iconified or maximized */
380 if (wwin->transient_for) {
381 WSETUFLAG(wwin, no_miniaturizable, 1);
382 WSETUFLAG(wwin, no_miniaturize_button, 1);
385 /* if the window can't be resized, remove the resizebar */
386 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
387 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
388 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
389 WSETUFLAG(wwin, no_resizable, 1);
390 WSETUFLAG(wwin, no_resizebar, 1);
393 /* set GNUstep window attributes */
394 if (wwin->wm_gnustep_attr) {
395 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
397 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
399 switch (wwin->wm_gnustep_attr->window_level) {
400 case WMNormalWindowLevel:
401 *level = WMNormalLevel;
402 break;
403 case WMFloatingWindowLevel:
404 *level = WMFloatingLevel;
405 break;
406 case WMDockWindowLevel:
407 *level = WMDockLevel;
408 break;
409 case WMSubmenuWindowLevel:
410 *level = WMSubmenuLevel;
411 break;
412 case WMMainMenuWindowLevel:
413 *level = WMMainMenuLevel;
414 break;
415 default:
416 *level = WMNormalLevel;
417 break;
419 } else {
420 /* setup defaults */
421 *level = WMNormalLevel;
423 } else {
424 int tmp_workspace = -1;
425 int tmp_level = -1;
426 Bool check;
428 check = False;
430 #ifdef MWM_HINTS
431 wMWMCheckClientHints(wwin);
432 #endif /* MWM_HINTS */
434 #ifdef GNOME_STUFF
435 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
436 #endif /* GNOME_STUFF */
438 #ifdef KWM_HINTS
439 if (!check)
440 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
441 #endif /* KWM_HINTS */
443 #ifdef OLWM_HINTS
444 wOLWMCheckClientHints(wwin);
445 #endif /* OLWM_HINTS */
447 if (tmp_level < 0) {
448 if (WFLAGP(wwin, floating))
449 *level = WMFloatingLevel;
450 else if (WFLAGP(wwin, sunken))
451 *level = WMSunkenLevel;
452 else
453 *level = WMNormalLevel;
454 } else {
455 *level = tmp_level;
458 if (tmp_workspace >= 0) {
459 *workspace = tmp_workspace % scr->workspace_count;
464 * Set attributes specified only for that window/class.
465 * This might do duplicate work with the 1st wDefaultFillAttributes().
467 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
468 &wwin->user_flags, &wwin->defined_user_flags,
469 False);
471 * Sanity checks for attributes that depend on other attributes
473 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
474 wwin->user_flags.emulate_appicon = 0;
476 if (wwin->main_window!=None) {
477 WApplication *wapp = wApplicationOf(wwin->main_window);
478 if (wapp && !wapp->flags.emulated)
479 wwin->user_flags.emulate_appicon = 0;
482 if (wwin->transient_for!=None
483 && wwin->transient_for!=wwin->screen_ptr->root_win)
484 wwin->user_flags.emulate_appicon = 0;
486 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
487 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
488 wwin->user_flags.sunken = 0;
490 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
496 Bool
497 wWindowCanReceiveFocus(WWindow *wwin)
499 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
500 return False;
501 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
502 return False;
503 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
504 return False;
506 return True;
510 Bool
511 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
513 int w1, h1, w2, h2;
515 w1 = wwin->frame->core->width;
516 h1 = wwin->frame->core->height;
517 w2 = obscured->frame->core->width;
518 h2 = obscured->frame->core->height;
520 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
521 && wwin->frame->workspace != obscured->frame->workspace)
522 return False;
524 if (wwin->frame_x + w1 < obscured->frame_x
525 || wwin->frame_y + h1 < obscured->frame_y
526 || wwin->frame_x > obscured->frame_x + w2
527 || wwin->frame_y > obscured->frame_y + h2) {
528 return False;
531 return True;
536 *----------------------------------------------------------------
537 * wManageWindow--
538 * reparents the window and allocates a descriptor for it.
539 * Window manager hints and other hints are fetched to configure
540 * the window decoration attributes and others. User preferences
541 * for the window are used if available, to configure window
542 * decorations and some behaviour.
543 * If in startup, windows that are override redirect,
544 * unmapped and never were managed and are Withdrawn are not
545 * managed.
547 * Returns:
548 * the new window descriptor
550 * Side effects:
551 * The window is reparented and appropriate notification
552 * is done to the client. Input mask for the window is setup.
553 * The window descriptor is also associated with various window
554 * contexts and inserted in the head of the window list.
555 * Event handler contexts are associated for some objects
556 * (buttons, titlebar and resizebar)
558 *----------------------------------------------------------------
560 WWindow*
561 wManageWindow(WScreen *scr, Window window)
563 WWindow *wwin;
564 int x, y;
565 unsigned width, height;
566 XWindowAttributes wattribs;
567 XSetWindowAttributes attribs;
568 WWindowState *win_state;
569 WWindow *transientOwner = NULL;
570 int window_level;
571 int wm_state;
572 int foo;
573 int workspace = -1;
574 char *title;
575 Bool withdraw = False;
577 /* mutex. */
578 /* XGrabServer(dpy); */
579 XSync(dpy, False);
580 /* make sure the window is still there */
581 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
582 XUngrabServer(dpy);
583 return NULL;
586 /* if it's an override-redirect, ignore it */
587 if (wattribs.override_redirect) {
588 XUngrabServer(dpy);
589 return NULL;
592 wm_state = PropGetWindowState(window);
594 /* if it's startup and the window is unmapped, don't manage it */
595 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
596 XUngrabServer(dpy);
597 return NULL;
600 if (!wFetchName(dpy, window, &title)) {
601 title = NULL;
604 #ifdef KWM_HINTS
605 if (title && !wKWMManageableClient(scr, window, title)) {
606 XFree(title);
607 XUngrabServer(dpy);
608 return NULL;
610 #endif /* KWM_HINTS */
613 wwin = wWindowCreate();
615 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
617 #ifdef DEBUG
618 printf("managing window %x\n", (unsigned)window);
619 #endif
621 #ifdef SHAPE
622 if (wShapeSupported) {
623 int junk;
624 unsigned int ujunk;
625 int b_shaped;
627 XShapeSelectInput(dpy, window, ShapeNotifyMask);
628 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
629 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
630 wwin->flags.shaped = b_shaped;
632 #endif
635 *--------------------------------------------------
637 * Get hints and other information in properties
639 *--------------------------------------------------
641 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
643 /* setup descriptor */
644 wwin->client_win = window;
645 wwin->screen_ptr = scr;
647 wwin->old_border_width = wattribs.border_width;
649 wwin->event_mask = CLIENT_EVENTS;
650 attribs.event_mask = CLIENT_EVENTS;
651 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
652 attribs.save_under = False;
653 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
654 |CWSaveUnder, &attribs);
655 XSetWindowBorderWidth(dpy, window, 0);
657 /* get hints from GNUstep app */
658 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
659 wwin->flags.is_gnustep = 1;
661 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
662 wwin->wm_gnustep_attr = NULL;
665 wwin->client_leader = PropGetClientLeader(window);
666 if (wwin->client_leader!=None)
667 wwin->main_window = wwin->client_leader;
669 wwin->wm_hints = XGetWMHints(dpy, window);
671 if (wwin->wm_hints) {
672 if (wwin->wm_hints->flags & StateHint) {
674 if (wwin->wm_hints->initial_state == IconicState) {
676 wwin->flags.miniaturized = 1;
678 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
680 withdraw = True;
684 if (wwin->wm_hints->flags & WindowGroupHint) {
685 wwin->group_id = wwin->wm_hints->window_group;
686 /* window_group has priority over CLIENT_LEADER */
687 wwin->main_window = wwin->group_id;
688 } else {
689 wwin->group_id = None;
692 if (wwin->wm_hints->flags & UrgencyHint)
693 wwin->flags.urgent = 1;
694 } else {
695 wwin->group_id = None;
698 PropGetProtocols(window, &wwin->protocols);
700 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
701 wwin->transient_for = None;
702 } else {
703 if (wwin->transient_for==None || wwin->transient_for==window) {
704 wwin->transient_for = scr->root_win;
705 } else {
706 transientOwner = wWindowFor(wwin->transient_for);
707 if (transientOwner && transientOwner->main_window!=None) {
708 wwin->main_window = transientOwner->main_window;
709 } /*else {
710 wwin->main_window = None;
715 /* guess the focus mode */
716 wwin->focus_mode = getFocusMode(wwin);
718 /* get geometry stuff */
719 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
721 /* get colormap windows */
722 GetColormapWindows(wwin);
725 *--------------------------------------------------
727 * Setup the decoration/window attributes and
728 * geometry
730 *--------------------------------------------------
733 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
735 #ifdef OLWM_HINTS
736 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
737 && wwin->group_id != None && wwin->group_id != window) {
739 transientOwner = wWindowFor(wwin->group_id);
741 if (transientOwner) {
742 wwin->transient_for = wwin->group_id;
744 /* transients can't be iconified or maximized */
745 if (wwin->transient_for) {
746 WSETUFLAG(wwin, no_miniaturizable, 1);
747 WSETUFLAG(wwin, no_miniaturize_button, 1);
751 #endif /* OLWM_HINTS */
754 * Make broken apps behave as a nice app.
756 if (WFLAGP(wwin, emulate_appicon)) {
757 wwin->main_window = wwin->client_win;
761 *------------------------------------------------------------
763 * Setup the initial state of the window
765 *------------------------------------------------------------
768 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
769 wwin->flags.miniaturized = 1;
772 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
773 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
777 Bool bla;
779 bla = False;
780 #ifdef GNOME_STUFF
781 bla = wGNOMECheckInitialClientState(wwin);
782 #endif
783 #ifdef KWM_HINTS
784 if (!bla)
785 wKWMCheckClientInitialState(wwin);
786 #endif
789 /* apply previous state if it exists and we're in startup */
790 if (scr->flags.startup && wm_state >= 0) {
792 if (wm_state == IconicState) {
794 wwin->flags.miniaturized = 1;
796 } else if (wm_state == WithdrawnState) {
798 withdraw = True;
802 /* if there is a saved state (from file), restore it */
803 win_state = NULL;
804 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
805 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
806 } else {
807 win_state = (WWindowState*)wWindowGetSavedState(window);
809 if (win_state && !withdraw) {
811 if (win_state->state->hidden>0)
812 wwin->flags.hidden = win_state->state->hidden;
814 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
815 wwin->flags.shaded = win_state->state->shaded;
817 if (win_state->state->miniaturized>0 &&
818 !WFLAGP(wwin, no_miniaturizable)) {
819 wwin->flags.miniaturized = win_state->state->miniaturized;
822 if (!IS_OMNIPRESENT(wwin)) {
823 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
824 wwin->wm_class);
825 if (w < 0 || w >= scr->workspace_count) {
826 workspace = win_state->state->workspace;
827 if (workspace >= scr->workspace_count)
828 workspace = scr->current_workspace;
829 } else {
830 workspace = w;
832 } else {
833 workspace = scr->current_workspace;
837 /* if we're restarting, restore saved state (from hints).
838 * This will overwrite previous */
840 WSavedState *wstate;
842 if (getSavedState(window, &wstate)) {
843 wwin->flags.shaded = wstate->shaded;
844 wwin->flags.hidden = wstate->hidden;
845 wwin->flags.miniaturized = wstate->miniaturized;
846 wwin->flags.maximized = wstate->maximized;
847 if (wwin->flags.maximized) {
848 wwin->old_geometry.x = wstate->x;
849 wwin->old_geometry.y = wstate->y;
850 wwin->old_geometry.width = wstate->w;
851 wwin->old_geometry.height = wstate->h;
854 workspace = wstate->workspace;
855 } else {
856 wstate = NULL;
859 /* restore window shortcut */
860 if (wstate != NULL || win_state != NULL) {
861 unsigned mask = 0;
863 if (win_state != NULL)
864 mask = win_state->state->window_shortcuts;
866 if (wstate != NULL && mask == 0)
867 mask = wstate->window_shortcuts;
869 if (mask > 0) {
870 int i;
872 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
873 if (mask & (1<<i)) {
874 if (!scr->shortcutWindows[i])
875 scr->shortcutWindows[i] = WMCreateBag(4);
877 WMPutInBag(scr->shortcutWindows[i], wwin);
882 if (wstate != NULL) {
883 wfree(wstate);
887 /* don't let transients start miniaturized if their owners are not */
888 if (transientOwner && !transientOwner->flags.miniaturized
889 && wwin->flags.miniaturized && !withdraw) {
890 wwin->flags.miniaturized = 0;
891 if (wwin->wm_hints)
892 wwin->wm_hints->initial_state = NormalState;
895 /* set workspace on which the window starts */
896 if (workspace >= 0) {
897 if (workspace > scr->workspace_count-1) {
898 workspace = workspace % scr->workspace_count;
900 } else {
901 int w;
903 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
905 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
907 workspace = w;
909 } else {
910 if (wPreferences.open_transients_with_parent && transientOwner) {
912 workspace = transientOwner->frame->workspace;
914 } else {
916 workspace = scr->current_workspace;
921 /* setup window geometry */
922 if (win_state && win_state->state->w > 0) {
923 width = win_state->state->w;
924 height = win_state->state->h;
926 wWindowConstrainSize(wwin, &width, &height);
928 /* do not ask for window placement if the window is
929 * transient, during startup, if the initial workspace is another one
930 * or if the window wants to start iconic.
931 * If geometry was saved, restore it. */
933 Bool dontBring = False;
935 if (win_state && win_state->state->w > 0) {
936 x = win_state->state->x;
937 y = win_state->state->y;
938 } else if ((wwin->transient_for==None
939 || wPreferences.window_placement!=WPM_MANUAL)
940 && !scr->flags.startup
941 && workspace == scr->current_workspace
942 && !wwin->flags.miniaturized
943 && !wwin->flags.maximized
944 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
946 if (transientOwner && transientOwner->flags.mapped) {
947 int offs = WMAX(20, 2*transientOwner->frame->top_width);
949 x = transientOwner->frame_x +
950 abs((transientOwner->frame->core->width - width)/2) + offs;
951 y = transientOwner->frame_y +
952 abs((transientOwner->frame->core->height - height)/3) + offs;
954 if (x < 0)
955 x = 0;
956 else if (x + width > scr->scr_width)
957 x = scr->scr_width - width;
959 if (y < 0)
960 y = 0;
961 else if (y + height > scr->scr_height)
962 y = scr->scr_height - height;
963 } else {
964 PlaceWindow(wwin, &x, &y, width, height);
966 if (wPreferences.window_placement == WPM_MANUAL)
967 dontBring = True;
970 if (WFLAGP(wwin, dont_move_off) && dontBring)
971 wScreenBringInside(scr, &x, &y, width, height);
974 if (wwin->flags.urgent) {
975 if (!IS_OMNIPRESENT(wwin))
976 wwin->flags.omnipresent ^= 1;
980 *--------------------------------------------------
982 * Create frame, borders and do reparenting
984 *--------------------------------------------------
986 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
987 #ifdef XKB_BUTTON_HINT
988 if (wPreferences.modelock)
989 foo |= WFF_LANGUAGE_BUTTON;
990 #endif
991 if (!WFLAGP(wwin, no_titlebar))
992 foo |= WFF_TITLEBAR;
993 if (!WFLAGP(wwin, no_resizebar))
994 foo |= WFF_RESIZEBAR;
995 if (!WFLAGP(wwin, no_border))
996 foo |= WFF_BORDER;
998 wwin->frame = wFrameWindowCreate(scr, window_level,
999 x, y, width, height,
1000 &wPreferences.window_title_clearance, foo,
1001 scr->window_title_texture,
1002 scr->resizebar_texture,
1003 scr->window_title_pixel,
1004 &scr->window_title_gc,
1005 &scr->title_font);
1007 wwin->frame->flags.is_client_window_frame = 1;
1008 wwin->frame->flags.justification = wPreferences.title_justification;
1010 /* setup button images */
1011 wWindowUpdateButtonImages(wwin);
1013 /* hide unused buttons */
1014 foo = 0;
1015 if (WFLAGP(wwin, no_close_button))
1016 foo |= WFF_RIGHT_BUTTON;
1017 if (WFLAGP(wwin, no_miniaturize_button))
1018 foo |= WFF_LEFT_BUTTON;
1019 #ifdef XKB_BUTTON_HINT
1020 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1021 foo |= WFF_LANGUAGE_BUTTON;
1022 #endif
1023 if (foo!=0)
1024 wFrameWindowHideButton(wwin->frame, foo);
1026 wwin->frame->child = wwin;
1028 #ifdef OLWM_HINTS
1029 /* emulate olwm push pin. Make the button look as pushed-in for
1030 * the pinned-out state. When the button is clicked, it will
1031 * revert to the normal position, which means the pin is pinned-in.
1033 if (wwin->flags.olwm_push_pin_out)
1034 wFrameWindowUpdatePushButton(wwin->frame, True);
1035 #endif /* OLWM_HINTS */
1037 wFrameWindowChangeTitle(wwin->frame, title ? title : DEF_WINDOW_TITLE);
1038 if (title)
1039 XFree(title);
1041 wwin->frame->workspace = workspace;
1043 wwin->frame->on_click_left = windowIconifyClick;
1044 #ifdef XKB_BUTTON_HINT
1045 if (wPreferences.modelock)
1046 wwin->frame->on_click_language = windowLanguageClick;
1047 #endif
1049 wwin->frame->on_click_right = windowCloseClick;
1050 wwin->frame->on_dblclick_right = windowCloseDblClick;
1052 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1053 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1055 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1058 XSelectInput(dpy, wwin->client_win,
1059 wwin->event_mask & ~StructureNotifyMask);
1061 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1062 0, wwin->frame->top_width);
1064 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1068 int gx, gy;
1070 wClientGetGravityOffsets(wwin, &gx, &gy);
1072 /* if gravity is to the south, account for the border sizes */
1073 if (gy > 0)
1074 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1078 * wWindowConfigure() will init the client window's size
1079 * (wwin->client.{width,height}) and all other geometry
1080 * related variables (frame_x,frame_y)
1082 wWindowConfigure(wwin, x, y, width, height);
1084 /* to make sure the window receives it's new position after reparenting */
1085 wWindowSynthConfigureNotify(wwin);
1088 *--------------------------------------------------
1090 * Setup descriptors and save window to internal
1091 * lists
1093 *--------------------------------------------------
1096 if (wwin->main_window!=None) {
1097 WApplication *app;
1098 WWindow *leader;
1100 /* Leader windows do not necessary set themselves as leaders.
1101 * If this is the case, point the leader of this window to
1102 * itself */
1103 leader = wWindowFor(wwin->main_window);
1104 if (leader && leader->main_window==None) {
1105 leader->main_window = leader->client_win;
1107 app = wApplicationCreate(scr, wwin->main_window);
1108 if (app) {
1109 app->last_workspace = workspace;
1112 * Do application specific stuff, like setting application
1113 * wide attributes.
1116 if (wwin->flags.hidden) {
1117 /* if the window was set to hidden because it was hidden
1118 * in a previous incarnation and that state was restored */
1119 app->flags.hidden = 1;
1122 if (app->flags.hidden) {
1123 wwin->flags.hidden = 1;
1128 /* setup the frame descriptor */
1129 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1130 wwin->frame->core->descriptor.parent = wwin;
1131 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1133 /* don't let windows go away if we die */
1134 XAddToSaveSet(dpy, window);
1136 XLowerWindow(dpy, window);
1138 /* if window is in this workspace and should be mapped, then map it */
1139 if (!wwin->flags.miniaturized
1140 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1141 && !wwin->flags.hidden && !withdraw) {
1143 /* The following "if" is to avoid crashing of clients that expect
1144 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1145 * after the return from this function.
1147 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1148 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1149 } else {
1150 wClientSetState(wwin, NormalState, None);
1153 #if 0
1154 /* if not auto focus, then map the window under the currently
1155 * focused window */
1156 #define _WIDTH(w) (w)->frame->core->width
1157 #define _HEIGHT(w) (w)->frame->core->height
1158 if (!wPreferences.auto_focus && scr->focused_window
1159 && !scr->flags.startup && !transientOwner
1160 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1161 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1162 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1163 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1164 || wwin->flags.maximized)) {
1165 MoveInStackListUnder(scr->focused_window->frame->core,
1166 wwin->frame->core);
1168 #undef _WIDTH
1169 #undef _HEIGHT
1171 #endif
1173 if (wPreferences.superfluous && !wPreferences.no_animations
1174 && !scr->flags.startup && wwin->transient_for==None
1176 * The brain damaged idiotic non-click to focus modes will
1177 * have trouble with this because:
1179 * 1. window is created and mapped by the client
1180 * 2. window is mapped by wmaker in small size
1181 * 3. window is animated to grow to normal size
1182 * 4. this function returns to normal event loop
1183 * 5. eventually, the EnterNotify event that would trigger
1184 * the window focusing (if the mouse is over that window)
1185 * will be processed by wmaker.
1186 * But since this event will be rather delayed
1187 * (step 3 has a large delay) the time when the event ocurred
1188 * and when it is processed, the client that owns that window
1189 * will reject the XSetInputFocus() for it.
1191 && (wPreferences.focus_mode==WKF_CLICK
1192 || wPreferences.auto_focus)) {
1193 DoWindowBirth(wwin);
1196 wWindowMap(wwin);
1199 /* setup stacking descriptor */
1200 if (transientOwner) {
1201 /* && wPreferences.on_top_transients */
1202 if (transientOwner) {
1203 wwin->frame->core->stacking->child_of =
1204 transientOwner->frame->core;
1206 } else {
1207 wwin->frame->core->stacking->child_of = NULL;
1211 if (!scr->focused_window) {
1212 /* first window on the list */
1213 wwin->next = NULL;
1214 wwin->prev = NULL;
1215 scr->focused_window = wwin;
1216 } else {
1217 WWindow *tmp;
1219 /* add window at beginning of focus window list */
1220 tmp = scr->focused_window;
1221 while (tmp->prev)
1222 tmp = tmp->prev;
1223 tmp->prev = wwin;
1224 wwin->next = tmp;
1225 wwin->prev = NULL;
1228 #ifdef GNOME_STUFF
1229 wGNOMEUpdateClientStateHint(wwin, True);
1230 #endif
1231 #ifdef KWM_HINTS
1232 wKWMUpdateClientWorkspace(wwin);
1233 wKWMUpdateClientStateHint(wwin, KWMAllFlags);
1234 #endif
1236 XUngrabServer(dpy);
1239 *--------------------------------------------------
1241 * Final preparations before window is ready to go
1243 *--------------------------------------------------
1246 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1249 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1250 && !wwin->flags.hidden) {
1251 if (((transientOwner && transientOwner->flags.focused)
1252 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1253 wSetFocusTo(scr, wwin);
1255 wWindowResetMouseGrabs(wwin);
1257 if (!WFLAGP(wwin, no_bind_keys)) {
1258 wWindowSetKeyGrabs(wwin);
1260 #ifdef GNOME_STUFF
1261 wGNOMEUpdateClientListHint(scr);
1262 #endif
1263 #ifdef KWM_HINTS
1264 wwin->flags.kwm_managed = 1;
1266 wKWMSendEventMessage(wwin, WKWMAddWindow);
1267 #endif
1269 wColormapInstallForWindow(scr, scr->cmap_window);
1271 UpdateSwitchMenu(scr, wwin, ACTION_ADD);
1273 #ifdef OLWM_HINTS
1274 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1275 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1277 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1278 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1279 wwin->frame_y);
1281 #endif
1284 *------------------------------------------------------------
1285 * Setup Notification Observers
1286 *------------------------------------------------------------
1288 WMAddNotificationObserver(appearanceObserver, wwin,
1289 WNWindowAppearanceSettingsChanged, wwin);
1293 *--------------------------------------------------
1295 * Cleanup temporary stuff
1297 *--------------------------------------------------
1300 if (win_state)
1301 wWindowDeleteSavedState(win_state);
1303 /* If the window must be withdrawed, then do it now.
1304 * Must do some optimization, 'though */
1305 if (withdraw) {
1306 wwin->flags.mapped = 0;
1307 wClientSetState(wwin, WithdrawnState, None);
1308 wUnmanageWindow(wwin, True, False);
1309 wwin = NULL;
1312 return wwin;
1319 WWindow*
1320 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1321 char *title, int x, int y, int width, int height)
1323 WWindow *wwin;
1324 int foo;
1326 wwin = wWindowCreate();
1328 WMAddNotificationObserver(appearanceObserver, wwin,
1329 WNWindowAppearanceSettingsChanged, wwin);
1331 wwin->flags.internal_window = 1;
1333 WSETUFLAG(wwin, omnipresent, 1);
1334 WSETUFLAG(wwin, no_shadeable, 1);
1335 WSETUFLAG(wwin, no_resizable, 1);
1336 WSETUFLAG(wwin, no_miniaturizable, 1);
1338 wwin->focus_mode = WFM_PASSIVE;
1340 wwin->client_win = window;
1341 wwin->screen_ptr = scr;
1343 wwin->transient_for = owner;
1345 wwin->client.x = x;
1346 wwin->client.y = y;
1347 wwin->client.width = width;
1348 wwin->client.height = height;
1350 wwin->frame_x = wwin->client.x;
1351 wwin->frame_y = wwin->client.y;
1354 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1355 foo |= WFF_TITLEBAR;
1356 #ifdef XKB_BUTTON_HINT
1357 foo |= WFF_LANGUAGE_BUTTON;
1358 #endif
1360 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1361 wwin->frame_x, wwin->frame_y,
1362 width, height,
1363 &wPreferences.window_title_clearance, foo,
1364 scr->window_title_texture,
1365 scr->resizebar_texture,
1366 scr->window_title_pixel,
1367 &scr->window_title_gc,
1368 &scr->title_font);
1370 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1372 wwin->frame->flags.is_client_window_frame = 1;
1373 wwin->frame->flags.justification = wPreferences.title_justification;
1375 wFrameWindowChangeTitle(wwin->frame, title);
1377 /* setup button images */
1378 wWindowUpdateButtonImages(wwin);
1380 /* hide buttons */
1381 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1383 wwin->frame->child = wwin;
1385 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1387 #ifdef XKB_BUTTON_HINT
1388 if (wPreferences.modelock)
1389 wwin->frame->on_click_language = windowLanguageClick;
1390 #endif
1392 wwin->frame->on_click_right = windowCloseClick;
1394 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1395 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1397 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1399 wwin->client.y += wwin->frame->top_width;
1400 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1401 0, wwin->frame->top_width);
1403 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1404 wwin->client.width, wwin->client.height);
1406 /* setup the frame descriptor */
1407 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1408 wwin->frame->core->descriptor.parent = wwin;
1409 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1412 XLowerWindow(dpy, window);
1413 XMapSubwindows(dpy, wwin->frame->core->window);
1415 /* setup stacking descriptor */
1416 if (
1417 #ifdef removed
1418 wPreferences.on_top_transients &&
1419 #endif
1420 wwin->transient_for!=None
1421 && wwin->transient_for!=scr->root_win) {
1422 WWindow *tmp;
1423 tmp = wWindowFor(wwin->transient_for);
1424 if (tmp)
1425 wwin->frame->core->stacking->child_of = tmp->frame->core;
1426 } else {
1427 wwin->frame->core->stacking->child_of = NULL;
1431 if (!scr->focused_window) {
1432 /* first window on the list */
1433 wwin->next = NULL;
1434 wwin->prev = NULL;
1435 scr->focused_window = wwin;
1436 } else {
1437 WWindow *tmp;
1439 /* add window at beginning of focus window list */
1440 tmp = scr->focused_window;
1441 while (tmp->prev)
1442 tmp = tmp->prev;
1443 tmp->prev = wwin;
1444 wwin->next = tmp;
1445 wwin->prev = NULL;
1448 if (wwin->flags.is_gnustep == 0)
1449 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1451 /* if (wPreferences.auto_focus)*/
1452 wSetFocusTo(scr, wwin);
1454 wWindowResetMouseGrabs(wwin);
1456 wWindowSetKeyGrabs(wwin);
1458 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_ADD);
1460 return wwin;
1465 *----------------------------------------------------------------------
1466 * wUnmanageWindow--
1467 * Removes the frame window from a window and destroys all data
1468 * related to it. The window will be reparented back to the root window
1469 * if restore is True.
1471 * Side effects:
1472 * Everything related to the window is destroyed and the window
1473 * is removed from the window lists. Focus is set to the previous on the
1474 * window list.
1475 *----------------------------------------------------------------------
1477 void
1478 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1480 WCoreWindow *frame = wwin->frame->core;
1481 WWindow *owner = NULL;
1482 WWindow *newFocusedWindow = NULL;
1483 int wasFocused;
1484 WScreen *scr = wwin->screen_ptr;
1487 #ifdef KWM_HINTS
1488 wwin->frame->workspace = -1;
1490 wKWMUpdateClientWorkspace(wwin);
1491 #endif
1493 /* First close attribute editor window if open */
1494 if (wwin->flags.inspector_open) {
1495 wCloseInspectorForWindow(wwin);
1498 /* Close window menu if it's open for this window */
1499 if (wwin->flags.menu_open_for_me) {
1500 CloseWindowMenu(scr);
1503 if (!destroyed) {
1504 if (!wwin->flags.internal_window)
1505 XRemoveFromSaveSet(dpy, wwin->client_win);
1507 XSelectInput(dpy, wwin->client_win, NoEventMask);
1509 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1510 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1513 XUnmapWindow(dpy, frame->window);
1515 XUnmapWindow(dpy, wwin->client_win);
1517 /* deselect window */
1518 wSelectWindow(wwin, False);
1520 /* remove all pending events on window */
1521 /* I think this only matters for autoraise */
1522 if (wPreferences.raise_delay)
1523 WMDeleteTimerWithClientData(wwin->frame->core);
1525 XFlush(dpy);
1527 UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);
1529 /* reparent the window back to the root */
1530 if (restore)
1531 wClientRestore(wwin);
1533 if (wwin->transient_for!=scr->root_win) {
1534 owner = wWindowFor(wwin->transient_for);
1535 if (owner) {
1536 if (!owner->flags.semi_focused) {
1537 owner = NULL;
1538 } else {
1539 owner->flags.semi_focused = 0;
1544 wasFocused = wwin->flags.focused;
1546 /* remove from window focus list */
1547 if (!wwin->prev && !wwin->next) {
1548 /* was the only window */
1549 scr->focused_window = NULL;
1550 newFocusedWindow = NULL;
1551 } else {
1552 WWindow *tmp;
1554 if (wwin->prev)
1555 wwin->prev->next = wwin->next;
1556 if (wwin->next)
1557 wwin->next->prev = wwin->prev;
1558 else {
1559 scr->focused_window = wwin->prev;
1560 scr->focused_window->next = NULL;
1563 if (wPreferences.focus_mode==WKF_CLICK) {
1565 /* if in click to focus mode and the window
1566 * was a transient, focus the owner window
1568 tmp = NULL;
1569 if (wPreferences.focus_mode==WKF_CLICK) {
1570 tmp = wWindowFor(wwin->transient_for);
1571 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1572 tmp = NULL;
1575 /* otherwise, focus the next one in the focus list */
1576 if (!tmp) {
1577 tmp = scr->focused_window;
1578 while (tmp) { /* look for one in the window list first */
1579 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1580 && (tmp->flags.mapped || tmp->flags.shaded))
1581 break;
1582 tmp = tmp->prev;
1584 if (!tmp) { /* if unsuccessful, choose any focusable window */
1585 tmp = scr->focused_window;
1586 while (tmp) {
1587 if (!WFLAGP(tmp, no_focusable)
1588 && (tmp->flags.mapped || tmp->flags.shaded))
1589 break;
1590 tmp = tmp->prev;
1595 newFocusedWindow = tmp;
1597 } else if (wPreferences.focus_mode==WKF_SLOPPY
1598 || wPreferences.focus_mode==WKF_POINTER) {
1599 unsigned int mask;
1600 int foo;
1601 Window bar, win;
1603 /* This is to let the root window get the keyboard input
1604 * if Sloppy focus mode and no other window get focus.
1605 * This way keybindings will not freeze.
1607 tmp = NULL;
1608 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1609 &foo, &foo, &foo, &foo, &mask))
1610 tmp = wWindowFor(win);
1611 if (tmp == wwin)
1612 tmp = NULL;
1613 newFocusedWindow = tmp;
1614 } else {
1615 newFocusedWindow = NULL;
1619 if (!wwin->flags.internal_window) {
1620 #ifdef GNOME_STUFF
1621 wGNOMERemoveClient(wwin);
1622 #endif
1623 #ifdef KWM_HINTS
1624 wKWMSendEventMessage(wwin, WKWMRemoveWindow);
1625 #endif
1628 #ifdef DEBUG
1629 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1630 (unsigned)frame->window);
1631 #endif
1633 if (wasFocused) {
1634 if (newFocusedWindow != owner && owner) {
1635 if (wwin->flags.is_gnustep == 0)
1636 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1638 wSetFocusTo(scr, newFocusedWindow);
1640 wWindowDestroy(wwin);
1641 XFlush(dpy);
1645 void
1646 wWindowMap(WWindow *wwin)
1648 XMapWindow(dpy, wwin->frame->core->window);
1649 if (!wwin->flags.shaded) {
1650 /* window will be remapped when getting MapNotify */
1651 XSelectInput(dpy, wwin->client_win,
1652 wwin->event_mask & ~StructureNotifyMask);
1653 XMapWindow(dpy, wwin->client_win);
1654 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1656 wwin->flags.mapped = 1;
1661 void
1662 wWindowUnmap(WWindow *wwin)
1664 wwin->flags.mapped = 0;
1666 /* prevent window withdrawal when getting UnmapNotify */
1667 XSelectInput(dpy, wwin->client_win,
1668 wwin->event_mask & ~StructureNotifyMask);
1669 XUnmapWindow(dpy, wwin->client_win);
1670 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1672 XUnmapWindow(dpy, wwin->frame->core->window);
1677 void
1678 wWindowFocus(WWindow *wwin, WWindow *owin)
1680 WWindow *nowner;
1681 WWindow *oowner;
1683 #ifdef KEEP_XKB_LOCK_STATUS
1684 if (wPreferences.modelock) {
1685 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1687 #endif /* KEEP_XKB_LOCK_STATUS */
1689 wwin->flags.semi_focused = 0;
1691 if (wwin->flags.is_gnustep == 0)
1692 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1694 wwin->flags.focused = 1;
1696 wWindowResetMouseGrabs(wwin);
1698 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1700 if (owin == wwin || !owin)
1701 return;
1703 nowner = wWindowFor(wwin->transient_for);
1705 /* new window is a transient for the old window */
1706 if (nowner == owin) {
1707 owin->flags.semi_focused = 1;
1708 wWindowUnfocus(nowner);
1709 return;
1712 oowner = wWindowFor(owin->transient_for);
1714 /* new window is owner of old window */
1715 if (wwin == oowner) {
1716 wWindowUnfocus(owin);
1717 return;
1720 if (!nowner) {
1721 wWindowUnfocus(owin);
1722 return;
1725 /* new window has same owner of old window */
1726 if (oowner == nowner) {
1727 /* prevent unfocusing of owner */
1728 oowner->flags.semi_focused = 0;
1729 wWindowUnfocus(owin);
1730 oowner->flags.semi_focused = 1;
1732 return;
1735 /* nowner != NULL && oowner != nowner */
1736 nowner->flags.semi_focused = 1;
1737 wWindowUnfocus(nowner);
1738 wWindowUnfocus(owin);
1742 void
1743 wWindowUnfocus(WWindow *wwin)
1745 CloseWindowMenu(wwin->screen_ptr);
1747 if (wwin->flags.is_gnustep == 0)
1748 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1749 ? WS_PFOCUSED : WS_UNFOCUSED);
1751 if (wwin->transient_for!=None
1752 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1753 WWindow *owner;
1754 owner = wWindowFor(wwin->transient_for);
1755 if (owner && owner->flags.semi_focused) {
1756 owner->flags.semi_focused = 0;
1757 if (owner->flags.mapped || owner->flags.shaded) {
1758 wWindowUnfocus(owner);
1759 wFrameWindowPaint(owner->frame);
1763 wwin->flags.focused = 0;
1765 wWindowResetMouseGrabs(wwin);
1767 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1774 *----------------------------------------------------------------------
1776 * wWindowConstrainSize--
1777 * Constrains size for the client window, taking the maximal size,
1778 * window resize increments and other size hints into account.
1780 * Returns:
1781 * The closest size to what was given that the client window can
1782 * have.
1784 *----------------------------------------------------------------------
1786 void
1787 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1789 int width = *nwidth;
1790 int height = *nheight;
1791 int winc = 1;
1792 int hinc = 1;
1793 int minW = 1, minH = 1;
1794 int maxW = wwin->screen_ptr->scr_width*2;
1795 int maxH = wwin->screen_ptr->scr_height*2;
1796 int minAX = -1, minAY = -1;
1797 int maxAX = -1, maxAY = -1;
1798 int baseW = 0;
1799 int baseH = 0;
1801 if (wwin->normal_hints) {
1802 winc = wwin->normal_hints->width_inc;
1803 hinc = wwin->normal_hints->height_inc;
1804 minW = wwin->normal_hints->min_width;
1805 minH = wwin->normal_hints->min_height;
1806 maxW = wwin->normal_hints->max_width;
1807 maxH = wwin->normal_hints->max_height;
1808 if (wwin->normal_hints->flags & PAspect) {
1809 minAX = wwin->normal_hints->min_aspect.x;
1810 minAY = wwin->normal_hints->min_aspect.y;
1811 maxAX = wwin->normal_hints->max_aspect.x;
1812 maxAY = wwin->normal_hints->max_aspect.y;
1816 if (width < minW)
1817 width = minW;
1818 if (height < minH)
1819 height = minH;
1821 if (width > maxW)
1822 width = maxW;
1823 if (height > maxH)
1824 height = maxH;
1826 /* aspect ratio code borrowed from olwm */
1827 if (minAX > 0) {
1828 /* adjust max aspect ratio */
1829 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1830 if (maxAX > maxAY) {
1831 height = (width * maxAY) / maxAX;
1832 if (height > maxH) {
1833 height = maxH;
1834 width = (height * maxAX) / maxAY;
1836 } else {
1837 width = (height * maxAX) / maxAY;
1838 if (width > maxW) {
1839 width = maxW;
1840 height = (width * maxAY) / maxAX;
1845 /* adjust min aspect ratio */
1846 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1847 if (minAX > minAY) {
1848 height = (width * minAY) / minAX;
1849 if (height < minH) {
1850 height = minH;
1851 width = (height * minAX) / minAY;
1853 } else {
1854 width = (height * minAX) / minAY;
1855 if (width < minW) {
1856 width = minW;
1857 height = (width * minAY) / minAX;
1863 if (baseW != 0) {
1864 width = (((width - baseW) / winc) * winc) + baseW;
1865 } else {
1866 width = (((width - minW) / winc) * winc) + minW;
1869 if (baseW != 0) {
1870 height = (((height - baseH) / hinc) * hinc) + baseH;
1871 } else {
1872 height = (((height - minH) / hinc) * hinc) + minH;
1875 /* broken stupid apps may cause preposterous values for these.. */
1876 if (width > 0)
1877 *nwidth = width;
1878 if (height > 0)
1879 *nheight = height;
1883 void
1884 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1886 WScreen *scr = wwin->screen_ptr;
1887 WApplication *wapp;
1888 int unmap = 0;
1890 if (workspace >= scr->workspace_count || workspace < 0
1891 || workspace == wwin->frame->workspace)
1892 return;
1894 if (workspace != scr->current_workspace) {
1895 /* Sent to other workspace. Unmap window */
1896 if ((wwin->flags.mapped
1897 || wwin->flags.shaded
1898 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1899 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1901 wapp = wApplicationOf(wwin->main_window);
1902 if (wapp) {
1903 wapp->last_workspace = workspace;
1905 if (wwin->flags.miniaturized) {
1906 if (wwin->icon) {
1907 XUnmapWindow(dpy, wwin->icon->core->window);
1908 wwin->icon->mapped = 0;
1910 } else {
1911 unmap = 1;
1912 wSetFocusTo(scr, NULL);
1915 } else {
1916 /* brought to current workspace. Map window */
1917 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1918 if (wwin->icon) {
1919 XMapWindow(dpy, wwin->icon->core->window);
1920 wwin->icon->mapped = 1;
1922 } else if (!wwin->flags.mapped &&
1923 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1924 wWindowMap(wwin);
1927 if (!IS_OMNIPRESENT(wwin)) {
1928 wwin->frame->workspace = workspace;
1929 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1931 #ifdef GNOME_STUFF
1932 wGNOMEUpdateClientStateHint(wwin, True);
1933 #endif
1934 #ifdef KWM_HINTS
1935 wKWMUpdateClientWorkspace(wwin);
1936 wKWMSendEventMessage(wwin, WKWMChangedClient);
1937 #endif
1938 if (unmap) {
1939 wWindowUnmap(wwin);
1944 void
1945 wWindowSynthConfigureNotify(WWindow *wwin)
1947 XEvent sevent;
1949 sevent.type = ConfigureNotify;
1950 sevent.xconfigure.display = dpy;
1951 sevent.xconfigure.event = wwin->client_win;
1952 sevent.xconfigure.window = wwin->client_win;
1954 sevent.xconfigure.x = wwin->client.x;
1955 sevent.xconfigure.y = wwin->client.y;
1956 sevent.xconfigure.width = wwin->client.width;
1957 sevent.xconfigure.height = wwin->client.height;
1959 sevent.xconfigure.border_width = wwin->old_border_width;
1960 if (WFLAGP(wwin, no_titlebar))
1961 sevent.xconfigure.above = None;
1962 else
1963 sevent.xconfigure.above = wwin->frame->titlebar->window;
1965 sevent.xconfigure.override_redirect = False;
1966 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
1967 #ifdef KWM_HINTS
1968 wKWMSendEventMessage(wwin, WKWMChangedClient);
1969 #endif
1970 XFlush(dpy);
1975 *----------------------------------------------------------------------
1976 * wWindowConfigure--
1977 * Configures the frame, decorations and client window to the
1978 * specified geometry. The geometry is not checked for validity,
1979 * wWindowConstrainSize() must be used for that.
1980 * The size parameters are for the client window, but the position is
1981 * for the frame.
1982 * The client window receives a ConfigureNotify event, according
1983 * to what ICCCM says.
1985 * Returns:
1986 * None
1988 * Side effects:
1989 * Window size and position are changed and client window receives
1990 * a ConfigureNotify event.
1991 *----------------------------------------------------------------------
1993 void
1994 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
1995 WWindow *wwin;
1996 int req_x, req_y; /* new position of the frame */
1997 int req_width, req_height; /* new size of the client */
1999 int synth_notify = False;
2000 int resize;
2002 resize = (req_width!=wwin->client.width
2003 || req_height!=wwin->client.height);
2005 * if the window is being moved but not resized then
2006 * send a synthetic ConfigureNotify
2008 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2009 synth_notify = True;
2012 if (WFLAGP(wwin, dont_move_off))
2013 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2014 req_width, req_height);
2015 if (resize) {
2016 if (req_width < MIN_WINDOW_SIZE)
2017 req_width = MIN_WINDOW_SIZE;
2018 if (req_height < MIN_WINDOW_SIZE)
2019 req_height = MIN_WINDOW_SIZE;
2021 /* If growing, resize inner part before frame,
2022 * if shrinking, resize frame before.
2023 * This will prevent the frame (that can have a different color)
2024 * to be exposed, causing flicker */
2025 if (req_height > wwin->frame->core->height
2026 || req_width > wwin->frame->core->width)
2027 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2029 if (wwin->flags.shaded) {
2030 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2031 req_width, wwin->frame->core->height);
2032 wwin->old_geometry.height = req_height;
2033 } else {
2034 int h;
2036 h = req_height + wwin->frame->top_width
2037 + wwin->frame->bottom_width;
2039 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2042 if (!(req_height > wwin->frame->core->height
2043 || req_width > wwin->frame->core->width))
2044 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2046 wwin->client.x = req_x;
2047 wwin->client.y = req_y + wwin->frame->top_width;
2048 wwin->client.width = req_width;
2049 wwin->client.height = req_height;
2050 } else {
2051 wwin->client.x = req_x;
2052 wwin->client.y = req_y + wwin->frame->top_width;
2054 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2056 wwin->frame_x = req_x;
2057 wwin->frame_y = req_y;
2058 if (!WFLAGP(wwin, no_border)) {
2059 wwin->client.x += FRAME_BORDER_WIDTH;
2060 wwin->client.y += FRAME_BORDER_WIDTH;
2063 #ifdef SHAPE
2064 if (wShapeSupported && wwin->flags.shaped && resize) {
2065 wWindowSetShape(wwin);
2067 #endif
2069 if (synth_notify)
2070 wWindowSynthConfigureNotify(wwin);
2071 XFlush(dpy);
2075 void
2076 wWindowMove(wwin, req_x, req_y)
2077 WWindow *wwin;
2078 int req_x, req_y; /* new position of the frame */
2080 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2081 int synth_notify = False;
2083 /* Send a synthetic ConfigureNotify event for every window movement. */
2084 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2085 synth_notify = True;
2087 #else
2088 /* A single synthetic ConfigureNotify event is sent at the end of
2089 * a completed (opaque) movement in moveres.c */
2090 #endif
2092 if (WFLAGP(wwin, dont_move_off))
2093 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2094 wwin->frame->core->width, wwin->frame->core->height);
2096 wwin->client.x = req_x;
2097 wwin->client.y = req_y + wwin->frame->top_width;
2098 if (!WFLAGP(wwin, no_border)) {
2099 wwin->client.x += FRAME_BORDER_WIDTH;
2100 wwin->client.y += FRAME_BORDER_WIDTH;
2103 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2105 wwin->frame_x = req_x;
2106 wwin->frame_y = req_y;
2108 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2109 if (synth_notify)
2110 wWindowSynthConfigureNotify(wwin);
2111 #endif
2115 void
2116 wWindowUpdateButtonImages(WWindow *wwin)
2118 WScreen *scr = wwin->screen_ptr;
2119 Pixmap pixmap, mask;
2120 WFrameWindow *fwin = wwin->frame;
2122 if (WFLAGP(wwin, no_titlebar))
2123 return;
2125 /* miniaturize button */
2127 if (!WFLAGP(wwin, no_miniaturize_button)) {
2128 if (wwin->wm_gnustep_attr
2129 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2130 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2132 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2133 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2134 } else {
2135 mask = None;
2138 if (fwin->lbutton_image
2139 && (fwin->lbutton_image->image != pixmap
2140 || fwin->lbutton_image->mask != mask)) {
2141 wPixmapDestroy(fwin->lbutton_image);
2142 fwin->lbutton_image = NULL;
2145 if (!fwin->lbutton_image) {
2146 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2147 fwin->lbutton_image->client_owned = 1;
2148 fwin->lbutton_image->client_owned_mask = 1;
2150 } else {
2151 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2152 wPixmapDestroy(fwin->lbutton_image);
2154 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2158 #ifdef XKB_BUTTON_HINT
2159 if (!WFLAGP(wwin, no_language_button)) {
2160 if (fwin->languagebutton_image &&
2161 !fwin->languagebutton_image->shared) {
2162 wPixmapDestroy(fwin->languagebutton_image);
2164 fwin->languagebutton_image =
2165 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2167 #endif
2169 /* close button */
2171 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2172 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2174 if (!WFLAGP(wwin, no_close_button)) {
2175 if (wwin->wm_gnustep_attr
2176 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2177 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2179 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2180 mask = wwin->wm_gnustep_attr->close_mask;
2181 else
2182 mask = None;
2184 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2185 || fwin->rbutton_image->mask != mask)) {
2186 wPixmapDestroy(fwin->rbutton_image);
2187 fwin->rbutton_image = NULL;
2190 if (!fwin->rbutton_image) {
2191 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2192 fwin->rbutton_image->client_owned = 1;
2193 fwin->rbutton_image->client_owned_mask = 1;
2196 } else if (WFLAGP(wwin, kill_close)) {
2198 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2199 wPixmapDestroy(fwin->rbutton_image);
2201 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2203 } else if (MGFLAGP(wwin, broken_close)) {
2205 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2206 wPixmapDestroy(fwin->rbutton_image);
2208 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2210 } else {
2212 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2213 wPixmapDestroy(fwin->rbutton_image);
2215 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2219 /* force buttons to be redrawn */
2220 fwin->flags.need_texture_change = 1;
2221 wFrameWindowPaint(fwin);
2226 *---------------------------------------------------------------------------
2227 * wWindowConfigureBorders--
2228 * Update window border configuration according to attribute flags.
2230 *---------------------------------------------------------------------------
2232 void
2233 wWindowConfigureBorders(WWindow *wwin)
2235 if (wwin->frame) {
2236 int flags;
2237 int newy, oldh;
2239 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2240 #ifdef XKB_BUTTON_HINT
2241 flags |= WFF_LANGUAGE_BUTTON;
2242 #endif
2243 if (!WFLAGP(wwin, no_titlebar))
2244 flags |= WFF_TITLEBAR;
2245 if (!WFLAGP(wwin, no_resizebar))
2246 flags |= WFF_RESIZEBAR;
2247 if (!WFLAGP(wwin, no_border))
2248 flags |= WFF_BORDER;
2249 if (wwin->flags.shaded)
2250 flags |= WFF_IS_SHADED;
2252 oldh = wwin->frame->top_width;
2253 wFrameWindowUpdateBorders(wwin->frame, flags);
2254 if (oldh != wwin->frame->top_width) {
2255 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2257 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2258 wWindowConfigure(wwin, wwin->frame_x, newy,
2259 wwin->client.width, wwin->client.height);
2262 flags = 0;
2263 if (!WFLAGP(wwin, no_miniaturize_button)
2264 && wwin->frame->flags.hide_left_button)
2265 flags |= WFF_LEFT_BUTTON;
2267 #ifdef XKB_BUTTON_HINT
2268 if (!WFLAGP(wwin, no_language_button)
2269 && wwin->frame->flags.hide_language_button)
2270 flags |= WFF_LANGUAGE_BUTTON;
2271 #endif
2273 if (!WFLAGP(wwin, no_close_button)
2274 && wwin->frame->flags.hide_right_button)
2275 flags |= WFF_RIGHT_BUTTON;
2277 if (flags!=0) {
2278 wWindowUpdateButtonImages(wwin);
2279 wFrameWindowShowButton(wwin->frame, flags);
2282 flags = 0;
2283 if (WFLAGP(wwin, no_miniaturize_button)
2284 && !wwin->frame->flags.hide_left_button)
2285 flags |= WFF_LEFT_BUTTON;
2287 #ifdef XKB_BUTTON_HINT
2288 if (WFLAGP(wwin, no_language_button)
2289 && !wwin->frame->flags.hide_language_button)
2290 flags |= WFF_LANGUAGE_BUTTON;
2291 #endif
2293 if (WFLAGP(wwin, no_close_button)
2294 && !wwin->frame->flags.hide_right_button)
2295 flags |= WFF_RIGHT_BUTTON;
2297 if (flags!=0)
2298 wFrameWindowHideButton(wwin->frame, flags);
2300 #ifdef SHAPE
2301 if (wShapeSupported && wwin->flags.shaped) {
2302 wWindowSetShape(wwin);
2304 #endif
2309 void
2310 wWindowSaveState(WWindow *wwin)
2312 CARD32 data[10];
2313 int i;
2315 memset(data, 0, sizeof(CARD32)*10);
2316 data[0] = wwin->frame->workspace;
2317 data[1] = wwin->flags.miniaturized;
2318 data[2] = wwin->flags.shaded;
2319 data[3] = wwin->flags.hidden;
2320 data[4] = wwin->flags.maximized;
2321 if (wwin->flags.maximized == 0) {
2322 data[5] = wwin->frame_x;
2323 data[6] = wwin->frame_y;
2324 data[7] = wwin->frame->core->width;
2325 data[8] = wwin->frame->core->height;
2326 } else {
2327 data[5] = wwin->old_geometry.x;
2328 data[6] = wwin->old_geometry.y;
2329 data[7] = wwin->old_geometry.width;
2330 data[8] = wwin->old_geometry.height;
2333 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2334 if (wwin->screen_ptr->shortcutWindows[i] &&
2335 WMCountInBag(wwin->screen_ptr->shortcutWindows[i], wwin))
2336 data[9] |= 1<<i;
2338 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2339 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2340 (unsigned char *)data, 10);
2344 static int
2345 getSavedState(Window window, WSavedState **state)
2347 Atom type_ret;
2348 int fmt_ret;
2349 unsigned long nitems_ret;
2350 unsigned long bytes_after_ret;
2351 CARD32 *data;
2353 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2354 True, _XA_WINDOWMAKER_STATE,
2355 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2356 (unsigned char **)&data)!=Success || !data)
2357 return 0;
2359 *state = malloc(sizeof(WSavedState));
2361 if (*state) {
2362 (*state)->workspace = data[0];
2363 (*state)->miniaturized = data[1];
2364 (*state)->shaded = data[2];
2365 (*state)->hidden = data[3];
2366 (*state)->maximized = data[4];
2367 (*state)->x = data[5];
2368 (*state)->y = data[6];
2369 (*state)->w = data[7];
2370 (*state)->h = data[8];
2371 (*state)->window_shortcuts = data[9];
2373 XFree(data);
2375 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2376 return 1;
2377 else
2378 return 0;
2382 #ifdef SHAPE
2383 void
2384 wWindowClearShape(WWindow *wwin)
2386 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2387 0, wwin->frame->top_width, None, ShapeSet);
2388 XFlush(dpy);
2391 void
2392 wWindowSetShape(WWindow *wwin)
2394 XRectangle rect[2];
2395 int count;
2396 #ifdef OPTIMIZE_SHAPE
2397 XRectangle *rects;
2398 XRectangle *urec;
2399 int ordering;
2401 /* only shape is the client's */
2402 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2403 goto alt_code;
2406 /* Get array of rectangles describing the shape mask */
2407 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2408 &count, &ordering);
2409 if (!rects) {
2410 goto alt_code;
2413 urec = malloc(sizeof(XRectangle)*(count+2));
2414 if (!urec) {
2415 XFree(rects);
2416 goto alt_code;
2419 /* insert our decoration rectangles in the rect list */
2420 memcpy(urec, rects, sizeof(XRectangle)*count);
2421 XFree(rects);
2423 if (!WFLAGP(wwin, no_titlebar)) {
2424 urec[count].x = -1;
2425 urec[count].y = -1 - wwin->frame->top_width;
2426 urec[count].width = wwin->frame->core->width + 2;
2427 urec[count].height = wwin->frame->top_width + 1;
2428 count++;
2430 if (!WFLAGP(wwin, no_resizebar)) {
2431 urec[count].x = -1;
2432 urec[count].y = wwin->frame->core->height
2433 - wwin->frame->bottom_width - wwin->frame->top_width;
2434 urec[count].width = wwin->frame->core->width + 2;
2435 urec[count].height = wwin->frame->bottom_width + 1;
2436 count++;
2439 /* shape our frame window */
2440 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2441 0, wwin->frame->top_width, urec, count,
2442 ShapeSet, Unsorted);
2443 XFlush(dpy);
2444 wfree(urec);
2445 return;
2447 alt_code:
2448 #endif /* OPTIMIZE_SHAPE */
2449 count = 0;
2450 if (!WFLAGP(wwin, no_titlebar)) {
2451 rect[count].x = -1;
2452 rect[count].y = -1;
2453 rect[count].width = wwin->frame->core->width + 2;
2454 rect[count].height = wwin->frame->top_width + 1;
2455 count++;
2457 if (!WFLAGP(wwin, no_resizebar)) {
2458 rect[count].x = -1;
2459 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2460 rect[count].width = wwin->frame->core->width + 2;
2461 rect[count].height = wwin->frame->bottom_width + 1;
2462 count++;
2464 if (count > 0) {
2465 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2466 0, 0, rect, count, ShapeSet, Unsorted);
2468 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2469 0, wwin->frame->top_width, wwin->client_win,
2470 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2471 XFlush(dpy);
2473 #endif /* SHAPE */
2475 /* ====================================================================== */
2477 static FocusMode
2478 getFocusMode(WWindow *wwin)
2480 FocusMode mode;
2482 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2483 if (wwin->wm_hints->input == True) {
2484 if (wwin->protocols.TAKE_FOCUS)
2485 mode = WFM_LOCALLY_ACTIVE;
2486 else
2487 mode = WFM_PASSIVE;
2488 } else {
2489 if (wwin->protocols.TAKE_FOCUS)
2490 mode = WFM_GLOBALLY_ACTIVE;
2491 else
2492 mode = WFM_NO_INPUT;
2494 } else {
2495 mode = WFM_PASSIVE;
2497 return mode;
2501 void
2502 wWindowSetKeyGrabs(WWindow *wwin)
2504 int i;
2505 WShortKey *key;
2507 for (i=0; i<WKBD_LAST; i++) {
2508 key = &wKeyBindings[i];
2510 if (key->keycode==0)
2511 continue;
2512 if (key->modifier!=AnyModifier) {
2513 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2514 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2515 #ifdef NUMLOCK_HACK
2516 /* Also grab all modifier combinations possible that include,
2517 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2518 * work even if the NumLock/ScrollLock key is on.
2520 wHackedGrabKey(key->keycode, key->modifier,
2521 wwin->frame->core->window, True, GrabModeAsync,
2522 GrabModeAsync);
2523 #endif
2525 XGrabKey(dpy, key->keycode, key->modifier,
2526 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2529 #ifndef LITE
2530 wRootMenuBindShortcuts(wwin->frame->core->window);
2531 #endif
2536 void
2537 wWindowResetMouseGrabs(WWindow *wwin)
2539 /* Mouse grabs can't be done on the client window because of
2540 * ICCCM and because clients that try to do the same will crash.
2542 * But there is a problem wich makes tbar buttons of unfocused
2543 * windows not usable as the click goes to the frame window instead
2544 * of the button itself. Must figure a way to fix that.
2547 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2549 if (!WFLAGP(wwin, no_bind_mouse)) {
2550 /* grabs for Meta+drag */
2551 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2552 True, ButtonPressMask, GrabModeSync,
2553 GrabModeAsync, None, None);
2556 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2557 && !wwin->flags.is_gnustep) {
2558 /* the passive grabs to focus the window */
2559 /* if (wPreferences.focus_mode == WKF_CLICK) */
2560 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2561 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2562 None, None);
2564 XFlush(dpy);
2568 void
2569 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2571 if (attr->flags & GSExtraFlagsAttr) {
2572 if (MGFLAGP(wwin, broken_close) !=
2573 (attr->extra_flags & GSDocumentEditedFlag)) {
2574 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2575 wWindowUpdateButtonImages(wwin);
2581 WMagicNumber
2582 wWindowAddSavedState(char *instance, char *class, char *command,
2583 pid_t pid, WSavedState *state)
2585 WWindowState *wstate;
2587 wstate = malloc(sizeof(WWindowState));
2588 if (!wstate)
2589 return 0;
2591 memset(wstate, 0, sizeof(WWindowState));
2592 wstate->pid = pid;
2593 if (instance)
2594 wstate->instance = wstrdup(instance);
2595 if (class)
2596 wstate->class = wstrdup(class);
2597 if (command)
2598 wstate->command = wstrdup(command);
2599 wstate->state = state;
2601 wstate->next = windowState;
2602 windowState = wstate;
2604 #ifdef DEBUG
2605 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2606 class, command);
2607 #endif
2609 return wstate;
2613 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2616 WMagicNumber
2617 wWindowGetSavedState(Window win)
2619 char *instance, *class, *command=NULL;
2620 WWindowState *wstate = windowState;
2621 char **argv;
2622 int argc;
2624 if (!wstate)
2625 return NULL;
2627 if (XGetCommand(dpy, win, &argv, &argc)) {
2628 if (argc > 0)
2629 command = wtokenjoin(argv, argc);
2630 XFreeStringList(argv);
2632 if (!command)
2633 return NULL;
2635 if (PropGetWMClass(win, &class, &instance)) {
2636 while (wstate) {
2637 if (SAME(instance, wstate->instance) &&
2638 SAME(class, wstate->class) &&
2639 SAME(command, wstate->command)) {
2640 break;
2642 wstate = wstate->next;
2644 } else {
2645 wstate = NULL;
2648 #ifdef DEBUG
2649 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2650 class, command);
2651 #endif
2653 if (command) wfree(command);
2654 if (instance) XFree(instance);
2655 if (class) XFree(class);
2657 return wstate;
2661 void
2662 wWindowDeleteSavedState(WMagicNumber id)
2664 WWindowState *tmp, *wstate=(WWindowState*)id;
2666 if (!wstate || !windowState)
2667 return;
2669 tmp = windowState;
2670 if (tmp==wstate) {
2671 windowState = wstate->next;
2672 #ifdef DEBUG
2673 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2674 wstate, wstate->instance, wstate->class, wstate->command);
2675 #endif
2676 if (wstate->instance) wfree(wstate->instance);
2677 if (wstate->class) wfree(wstate->class);
2678 if (wstate->command) wfree(wstate->command);
2679 wfree(wstate->state);
2680 wfree(wstate);
2681 } else {
2682 while (tmp->next) {
2683 if (tmp->next==wstate) {
2684 tmp->next=wstate->next;
2685 #ifdef DEBUG
2686 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2687 wstate, wstate->instance, wstate->class, wstate->command);
2688 #endif
2689 if (wstate->instance) wfree(wstate->instance);
2690 if (wstate->class) wfree(wstate->class);
2691 if (wstate->command) wfree(wstate->command);
2692 wfree(wstate->state);
2693 wfree(wstate);
2694 break;
2696 tmp = tmp->next;
2702 void
2703 wWindowDeleteSavedStatesForPID(pid_t pid)
2705 WWindowState *tmp, *wstate;
2707 if (!windowState)
2708 return;
2710 tmp = windowState;
2711 if (tmp->pid == pid) {
2712 wstate = windowState;
2713 windowState = tmp->next;
2714 #ifdef DEBUG
2715 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2716 wstate, wstate->instance, wstate->class, wstate->command);
2717 #endif
2718 if (wstate->instance) wfree(wstate->instance);
2719 if (wstate->class) wfree(wstate->class);
2720 if (wstate->command) wfree(wstate->command);
2721 wfree(wstate->state);
2722 wfree(wstate);
2723 } else {
2724 while (tmp->next) {
2725 if (tmp->next->pid==pid) {
2726 wstate = tmp->next;
2727 tmp->next = wstate->next;
2728 #ifdef DEBUG
2729 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2730 wstate, wstate->instance, wstate->class, wstate->command);
2731 #endif
2732 if (wstate->instance) wfree(wstate->instance);
2733 if (wstate->class) wfree(wstate->class);
2734 if (wstate->command) wfree(wstate->command);
2735 wfree(wstate->state);
2736 wfree(wstate);
2737 break;
2739 tmp = tmp->next;
2745 /* ====================================================================== */
2747 static void
2748 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2750 WWindow *wwin = data;
2752 #ifndef NUMLOCK_HACK
2753 if ((event->xbutton.state & ValidModMask)
2754 != (event->xbutton.state & ~LockMask)) {
2755 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2756 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2758 #endif
2760 event->xbutton.state &= ValidModMask;
2762 CloseWindowMenu(wwin->screen_ptr);
2764 if (wPreferences.focus_mode==WKF_CLICK
2765 && !(event->xbutton.state&ControlMask)
2766 && !WFLAGP(wwin, no_focusable)) {
2767 wSetFocusTo(wwin->screen_ptr, wwin);
2770 if (event->xbutton.button == Button1)
2771 wRaiseFrame(wwin->frame->core);
2773 if (event->xbutton.window != wwin->frame->resizebar->window) {
2774 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2775 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2776 GrabModeAsync, GrabModeAsync, None,
2777 None, CurrentTime)!=GrabSuccess) {
2778 #ifdef DEBUG0
2779 wwarning("pointer grab failed for window move");
2780 #endif
2781 return;
2785 if (event->xbutton.state & MOD_MASK) {
2786 /* move the window */
2787 wMouseMoveWindow(wwin, event);
2788 XUngrabPointer(dpy, CurrentTime);
2789 } else {
2790 wMouseResizeWindow(wwin, event);
2791 XUngrabPointer(dpy, CurrentTime);
2797 static void
2798 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2800 WWindow *wwin = data;
2802 event->xbutton.state &= ValidModMask;
2804 if (event->xbutton.button==Button1) {
2805 if (event->xbutton.state == 0) {
2806 if (!WFLAGP(wwin, no_shadeable)) {
2807 /* shade window */
2808 if (wwin->flags.shaded)
2809 wUnshadeWindow(wwin);
2810 else
2811 wShadeWindow(wwin);
2813 } else {
2814 int dir = 0;
2816 if (event->xbutton.state & ControlMask)
2817 dir |= MAX_VERTICAL;
2819 if (event->xbutton.state & ShiftMask) {
2820 dir |= MAX_HORIZONTAL;
2821 if (!(event->xbutton.state & ControlMask))
2822 wSelectWindow(wwin, !wwin->flags.selected);
2825 /* maximize window */
2826 if (dir !=0 && !WFLAGP(wwin, no_resizable)) {
2827 int ndir = dir ^ wwin->flags.maximized;
2828 if (wwin->flags.maximized != 0)
2829 wUnmaximizeWindow(wwin);
2830 if (ndir != 0)
2831 wMaximizeWindow(wwin, ndir);
2834 } else if (event->xbutton.button==Button3) {
2835 if (event->xbutton.state & MOD_MASK) {
2836 wHideOtherApplications(wwin);
2838 } else if (event->xbutton.button==Button2) {
2839 wSelectWindow(wwin, !wwin->flags.selected);
2844 static void
2845 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2847 WWindow *wwin = desc->parent;
2849 event->xbutton.state &= ValidModMask;
2851 CloseWindowMenu(wwin->screen_ptr);
2853 if (/*wPreferences.focus_mode==WKF_CLICK
2854 &&*/ !(event->xbutton.state&ControlMask)
2855 && !WFLAGP(wwin, no_focusable)) {
2856 wSetFocusTo(wwin->screen_ptr, wwin);
2858 if (event->xbutton.button == Button1) {
2859 wRaiseFrame(wwin->frame->core);
2862 if (event->xbutton.state & MOD_MASK) {
2863 /* move the window */
2864 if (XGrabPointer(dpy, wwin->client_win, False,
2865 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2866 GrabModeAsync, GrabModeAsync, None,
2867 None, CurrentTime)!=GrabSuccess) {
2868 #ifdef DEBUG0
2869 wwarning("pointer grab failed for window move");
2870 #endif
2871 return;
2873 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2874 wMouseResizeWindow(wwin, event);
2875 else
2876 wMouseMoveWindow(wwin, event);
2877 XUngrabPointer(dpy, CurrentTime);
2882 static void
2883 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2885 WWindow *wwin = (WWindow*)data;
2887 #ifndef NUMLOCK_HACK
2888 if ((event->xbutton.state & ValidModMask)
2889 != (event->xbutton.state & ~LockMask)) {
2890 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2891 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2893 #endif
2894 event->xbutton.state &= ValidModMask;
2896 CloseWindowMenu(wwin->screen_ptr);
2898 if (wPreferences.focus_mode==WKF_CLICK
2899 && !(event->xbutton.state&ControlMask)
2900 && !WFLAGP(wwin, no_focusable)) {
2901 wSetFocusTo(wwin->screen_ptr, wwin);
2904 if (event->xbutton.button == Button1
2905 || event->xbutton.button == Button2) {
2907 if (event->xbutton.button == Button1) {
2908 if (event->xbutton.state & MOD_MASK) {
2909 wLowerFrame(wwin->frame->core);
2910 } else {
2911 wRaiseFrame(wwin->frame->core);
2914 if ((event->xbutton.state & ShiftMask)
2915 && !(event->xbutton.state & ControlMask)) {
2916 wSelectWindow(wwin, !wwin->flags.selected);
2917 return;
2919 if (event->xbutton.window != wwin->frame->titlebar->window
2920 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2921 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2922 GrabModeAsync, GrabModeAsync, None,
2923 None, CurrentTime)!=GrabSuccess) {
2924 #ifdef DEBUG0
2925 wwarning("pointer grab failed for window move");
2926 #endif
2927 return;
2930 /* move the window */
2931 wMouseMoveWindow(wwin, event);
2933 XUngrabPointer(dpy, CurrentTime);
2934 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2935 && !wwin->flags.internal_window
2936 && !WCHECK_STATE(WSTATE_MODAL)) {
2937 WObjDescriptor *desc;
2939 if (event->xbutton.window != wwin->frame->titlebar->window
2940 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2941 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2942 GrabModeAsync, GrabModeAsync, None,
2943 None, CurrentTime)!=GrabSuccess) {
2944 #ifdef DEBUG0
2945 wwarning("pointer grab failed for window move");
2946 #endif
2947 return;
2950 OpenWindowMenu(wwin, event->xbutton.x_root,
2951 wwin->frame_y+wwin->frame->top_width, False);
2953 /* allow drag select */
2954 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2955 event->xany.send_event = True;
2956 (*desc->handle_mousedown)(desc, event);
2958 XUngrabPointer(dpy, CurrentTime);
2964 static void
2965 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
2967 WWindow *wwin = data;
2969 event->xbutton.state &= ValidModMask;
2971 CloseWindowMenu(wwin->screen_ptr);
2973 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2974 return;
2976 /* if control-click, kill the client */
2977 if (event->xbutton.state & ControlMask) {
2978 wClientKill(wwin);
2979 } else {
2980 #ifdef OLWM_HINTS
2981 if (wwin->flags.olwm_push_pin_out) {
2983 wwin->flags.olwm_push_pin_out = 0;
2985 wOLWMChangePushpinState(wwin, True);
2987 wFrameWindowUpdatePushButton(wwin->frame, False);
2989 return;
2991 #endif
2992 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
2993 /* send delete message */
2994 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3000 static void
3001 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3003 WWindow *wwin = data;
3005 CloseWindowMenu(wwin->screen_ptr);
3007 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3008 return;
3010 /* send delete message */
3011 if (wwin->protocols.DELETE_WINDOW) {
3012 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3013 } else {
3014 wClientKill(wwin);
3019 #ifdef XKB_BUTTON_HINT
3020 static void
3021 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3023 WWindow *wwin = data;
3024 WFrameWindow *fwin = wwin->frame;
3025 WScreen *scr = fwin->screen_ptr;
3026 XkbStateRec staterec;
3027 int tl;
3029 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3030 return;
3031 tl = wwin->frame->languagemode;
3032 wwin->frame->languagemode = wwin->frame->last_languagemode;
3033 wwin->frame->last_languagemode = tl;
3034 wSetFocusTo(scr, wwin);
3035 wwin->frame->languagebutton_image =
3036 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3037 wwin->frame->languagemode];
3038 wFrameWindowUpdateLanguageButton(wwin->frame);
3039 if (event->xbutton.button == Button3)
3040 return;
3041 wRaiseFrame(fwin->core);
3043 #endif
3046 static void
3047 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3049 WWindow *wwin = data;
3051 event->xbutton.state &= ValidModMask;
3053 CloseWindowMenu(wwin->screen_ptr);
3055 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3056 return;
3058 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3059 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3060 LastTimestamp);
3061 } else {
3062 WApplication *wapp;
3063 if ((event->xbutton.state & ControlMask) ||
3064 (event->xbutton.button == Button3)) {
3066 wapp = wApplicationOf(wwin->main_window);
3067 if (wapp && !WFLAGP(wwin, no_appicon))
3068 wHideApplication(wapp);
3069 } else if (event->xbutton.state==0) {
3070 wIconifyWindow(wwin);