fixed bugs in configure.in, removed
[wmaker-crm.git] / src / window.c
blob1c066da8bdf716df7ce42ce35d97a52233635187
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 #ifdef DRAWSTRING_PLUGIN
1005 W_STRING_FTITLE,
1006 #endif
1007 &scr->window_title_gc,
1008 &scr->title_font);
1010 wwin->frame->flags.is_client_window_frame = 1;
1011 wwin->frame->flags.justification = wPreferences.title_justification;
1013 /* setup button images */
1014 wWindowUpdateButtonImages(wwin);
1016 /* hide unused buttons */
1017 foo = 0;
1018 if (WFLAGP(wwin, no_close_button))
1019 foo |= WFF_RIGHT_BUTTON;
1020 if (WFLAGP(wwin, no_miniaturize_button))
1021 foo |= WFF_LEFT_BUTTON;
1022 #ifdef XKB_BUTTON_HINT
1023 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1024 foo |= WFF_LANGUAGE_BUTTON;
1025 #endif
1026 if (foo!=0)
1027 wFrameWindowHideButton(wwin->frame, foo);
1029 wwin->frame->child = wwin;
1031 #ifdef OLWM_HINTS
1032 /* emulate olwm push pin. Make the button look as pushed-in for
1033 * the pinned-out state. When the button is clicked, it will
1034 * revert to the normal position, which means the pin is pinned-in.
1036 if (wwin->flags.olwm_push_pin_out)
1037 wFrameWindowUpdatePushButton(wwin->frame, True);
1038 #endif /* OLWM_HINTS */
1040 wFrameWindowChangeTitle(wwin->frame, title ? title : DEF_WINDOW_TITLE);
1041 if (title)
1042 XFree(title);
1044 wwin->frame->workspace = workspace;
1046 wwin->frame->on_click_left = windowIconifyClick;
1047 #ifdef XKB_BUTTON_HINT
1048 if (wPreferences.modelock)
1049 wwin->frame->on_click_language = windowLanguageClick;
1050 #endif
1052 wwin->frame->on_click_right = windowCloseClick;
1053 wwin->frame->on_dblclick_right = windowCloseDblClick;
1055 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1056 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1058 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1061 XSelectInput(dpy, wwin->client_win,
1062 wwin->event_mask & ~StructureNotifyMask);
1064 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1065 0, wwin->frame->top_width);
1067 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1071 int gx, gy;
1073 wClientGetGravityOffsets(wwin, &gx, &gy);
1075 /* if gravity is to the south, account for the border sizes */
1076 if (gy > 0)
1077 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1081 * wWindowConfigure() will init the client window's size
1082 * (wwin->client.{width,height}) and all other geometry
1083 * related variables (frame_x,frame_y)
1085 wWindowConfigure(wwin, x, y, width, height);
1087 /* to make sure the window receives it's new position after reparenting */
1088 wWindowSynthConfigureNotify(wwin);
1091 *--------------------------------------------------
1093 * Setup descriptors and save window to internal
1094 * lists
1096 *--------------------------------------------------
1099 if (wwin->main_window!=None) {
1100 WApplication *app;
1101 WWindow *leader;
1103 /* Leader windows do not necessary set themselves as leaders.
1104 * If this is the case, point the leader of this window to
1105 * itself */
1106 leader = wWindowFor(wwin->main_window);
1107 if (leader && leader->main_window==None) {
1108 leader->main_window = leader->client_win;
1110 app = wApplicationCreate(scr, wwin->main_window);
1111 if (app) {
1112 app->last_workspace = workspace;
1115 * Do application specific stuff, like setting application
1116 * wide attributes.
1119 if (wwin->flags.hidden) {
1120 /* if the window was set to hidden because it was hidden
1121 * in a previous incarnation and that state was restored */
1122 app->flags.hidden = 1;
1125 if (app->flags.hidden) {
1126 wwin->flags.hidden = 1;
1131 /* setup the frame descriptor */
1132 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1133 wwin->frame->core->descriptor.parent = wwin;
1134 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1136 /* don't let windows go away if we die */
1137 XAddToSaveSet(dpy, window);
1139 XLowerWindow(dpy, window);
1141 /* if window is in this workspace and should be mapped, then map it */
1142 if (!wwin->flags.miniaturized
1143 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1144 && !wwin->flags.hidden && !withdraw) {
1146 /* The following "if" is to avoid crashing of clients that expect
1147 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1148 * after the return from this function.
1150 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1151 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1152 } else {
1153 wClientSetState(wwin, NormalState, None);
1156 #if 0
1157 /* if not auto focus, then map the window under the currently
1158 * focused window */
1159 #define _WIDTH(w) (w)->frame->core->width
1160 #define _HEIGHT(w) (w)->frame->core->height
1161 if (!wPreferences.auto_focus && scr->focused_window
1162 && !scr->flags.startup && !transientOwner
1163 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1164 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1165 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1166 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1167 || wwin->flags.maximized)) {
1168 MoveInStackListUnder(scr->focused_window->frame->core,
1169 wwin->frame->core);
1171 #undef _WIDTH
1172 #undef _HEIGHT
1174 #endif
1176 if (wPreferences.superfluous && !wPreferences.no_animations
1177 && !scr->flags.startup && wwin->transient_for==None
1179 * The brain damaged idiotic non-click to focus modes will
1180 * have trouble with this because:
1182 * 1. window is created and mapped by the client
1183 * 2. window is mapped by wmaker in small size
1184 * 3. window is animated to grow to normal size
1185 * 4. this function returns to normal event loop
1186 * 5. eventually, the EnterNotify event that would trigger
1187 * the window focusing (if the mouse is over that window)
1188 * will be processed by wmaker.
1189 * But since this event will be rather delayed
1190 * (step 3 has a large delay) the time when the event ocurred
1191 * and when it is processed, the client that owns that window
1192 * will reject the XSetInputFocus() for it.
1194 && (wPreferences.focus_mode==WKF_CLICK
1195 || wPreferences.auto_focus)) {
1196 DoWindowBirth(wwin);
1199 wWindowMap(wwin);
1202 /* setup stacking descriptor */
1203 if (transientOwner) {
1204 /* && wPreferences.on_top_transients */
1205 if (transientOwner) {
1206 wwin->frame->core->stacking->child_of =
1207 transientOwner->frame->core;
1209 } else {
1210 wwin->frame->core->stacking->child_of = NULL;
1214 if (!scr->focused_window) {
1215 /* first window on the list */
1216 wwin->next = NULL;
1217 wwin->prev = NULL;
1218 scr->focused_window = wwin;
1219 } else {
1220 WWindow *tmp;
1222 /* add window at beginning of focus window list */
1223 tmp = scr->focused_window;
1224 while (tmp->prev)
1225 tmp = tmp->prev;
1226 tmp->prev = wwin;
1227 wwin->next = tmp;
1228 wwin->prev = NULL;
1231 #ifdef GNOME_STUFF
1232 wGNOMEUpdateClientStateHint(wwin, True);
1233 #endif
1234 #ifdef KWM_HINTS
1235 wKWMUpdateClientWorkspace(wwin);
1236 wKWMUpdateClientStateHint(wwin, KWMAllFlags);
1237 #endif
1239 XUngrabServer(dpy);
1242 *--------------------------------------------------
1244 * Final preparations before window is ready to go
1246 *--------------------------------------------------
1249 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1252 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1253 && !wwin->flags.hidden) {
1254 if (((transientOwner && transientOwner->flags.focused)
1255 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1256 wSetFocusTo(scr, wwin);
1258 wWindowResetMouseGrabs(wwin);
1260 if (!WFLAGP(wwin, no_bind_keys)) {
1261 wWindowSetKeyGrabs(wwin);
1263 #ifdef GNOME_STUFF
1264 wGNOMEUpdateClientListHint(scr);
1265 #endif
1266 #ifdef KWM_HINTS
1267 wwin->flags.kwm_managed = 1;
1269 wKWMSendEventMessage(wwin, WKWMAddWindow);
1270 #endif
1272 wColormapInstallForWindow(scr, scr->cmap_window);
1274 UpdateSwitchMenu(scr, wwin, ACTION_ADD);
1276 #ifdef OLWM_HINTS
1277 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1278 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1280 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1281 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1282 wwin->frame_y);
1284 #endif
1287 *------------------------------------------------------------
1288 * Setup Notification Observers
1289 *------------------------------------------------------------
1291 WMAddNotificationObserver(appearanceObserver, wwin,
1292 WNWindowAppearanceSettingsChanged, wwin);
1296 *--------------------------------------------------
1298 * Cleanup temporary stuff
1300 *--------------------------------------------------
1303 if (win_state)
1304 wWindowDeleteSavedState(win_state);
1306 /* If the window must be withdrawed, then do it now.
1307 * Must do some optimization, 'though */
1308 if (withdraw) {
1309 wwin->flags.mapped = 0;
1310 wClientSetState(wwin, WithdrawnState, None);
1311 wUnmanageWindow(wwin, True, False);
1312 wwin = NULL;
1315 return wwin;
1322 WWindow*
1323 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1324 char *title, int x, int y, int width, int height)
1326 WWindow *wwin;
1327 int foo;
1329 wwin = wWindowCreate();
1331 WMAddNotificationObserver(appearanceObserver, wwin,
1332 WNWindowAppearanceSettingsChanged, wwin);
1334 wwin->flags.internal_window = 1;
1336 WSETUFLAG(wwin, omnipresent, 1);
1337 WSETUFLAG(wwin, no_shadeable, 1);
1338 WSETUFLAG(wwin, no_resizable, 1);
1339 WSETUFLAG(wwin, no_miniaturizable, 1);
1341 wwin->focus_mode = WFM_PASSIVE;
1343 wwin->client_win = window;
1344 wwin->screen_ptr = scr;
1346 wwin->transient_for = owner;
1348 wwin->client.x = x;
1349 wwin->client.y = y;
1350 wwin->client.width = width;
1351 wwin->client.height = height;
1353 wwin->frame_x = wwin->client.x;
1354 wwin->frame_y = wwin->client.y;
1357 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1358 foo |= WFF_TITLEBAR;
1359 #ifdef XKB_BUTTON_HINT
1360 foo |= WFF_LANGUAGE_BUTTON;
1361 #endif
1363 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1364 wwin->frame_x, wwin->frame_y,
1365 width, height,
1366 &wPreferences.window_title_clearance, foo,
1367 scr->window_title_texture,
1368 scr->resizebar_texture,
1369 scr->window_title_pixel,
1370 #ifdef DRAWSTRING_PLUGIN
1371 W_STRING_FTITLE,
1372 #endif
1373 &scr->window_title_gc,
1374 &scr->title_font);
1376 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1378 wwin->frame->flags.is_client_window_frame = 1;
1379 wwin->frame->flags.justification = wPreferences.title_justification;
1381 wFrameWindowChangeTitle(wwin->frame, title);
1383 /* setup button images */
1384 wWindowUpdateButtonImages(wwin);
1386 /* hide buttons */
1387 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1389 wwin->frame->child = wwin;
1391 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1393 #ifdef XKB_BUTTON_HINT
1394 if (wPreferences.modelock)
1395 wwin->frame->on_click_language = windowLanguageClick;
1396 #endif
1398 wwin->frame->on_click_right = windowCloseClick;
1400 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1401 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1403 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1405 wwin->client.y += wwin->frame->top_width;
1406 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1407 0, wwin->frame->top_width);
1409 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1410 wwin->client.width, wwin->client.height);
1412 /* setup the frame descriptor */
1413 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1414 wwin->frame->core->descriptor.parent = wwin;
1415 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1418 XLowerWindow(dpy, window);
1419 XMapSubwindows(dpy, wwin->frame->core->window);
1421 /* setup stacking descriptor */
1422 if (
1423 #ifdef removed
1424 wPreferences.on_top_transients &&
1425 #endif
1426 wwin->transient_for!=None
1427 && wwin->transient_for!=scr->root_win) {
1428 WWindow *tmp;
1429 tmp = wWindowFor(wwin->transient_for);
1430 if (tmp)
1431 wwin->frame->core->stacking->child_of = tmp->frame->core;
1432 } else {
1433 wwin->frame->core->stacking->child_of = NULL;
1437 if (!scr->focused_window) {
1438 /* first window on the list */
1439 wwin->next = NULL;
1440 wwin->prev = NULL;
1441 scr->focused_window = wwin;
1442 } else {
1443 WWindow *tmp;
1445 /* add window at beginning of focus window list */
1446 tmp = scr->focused_window;
1447 while (tmp->prev)
1448 tmp = tmp->prev;
1449 tmp->prev = wwin;
1450 wwin->next = tmp;
1451 wwin->prev = NULL;
1454 if (wwin->flags.is_gnustep == 0)
1455 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1457 /* if (wPreferences.auto_focus)*/
1458 wSetFocusTo(scr, wwin);
1460 wWindowResetMouseGrabs(wwin);
1462 wWindowSetKeyGrabs(wwin);
1464 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_ADD);
1466 return wwin;
1471 *----------------------------------------------------------------------
1472 * wUnmanageWindow--
1473 * Removes the frame window from a window and destroys all data
1474 * related to it. The window will be reparented back to the root window
1475 * if restore is True.
1477 * Side effects:
1478 * Everything related to the window is destroyed and the window
1479 * is removed from the window lists. Focus is set to the previous on the
1480 * window list.
1481 *----------------------------------------------------------------------
1483 void
1484 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1486 WCoreWindow *frame = wwin->frame->core;
1487 WWindow *owner = NULL;
1488 WWindow *newFocusedWindow = NULL;
1489 int wasFocused;
1490 WScreen *scr = wwin->screen_ptr;
1493 #ifdef KWM_HINTS
1494 wwin->frame->workspace = -1;
1496 wKWMUpdateClientWorkspace(wwin);
1497 #endif
1499 /* First close attribute editor window if open */
1500 if (wwin->flags.inspector_open) {
1501 wCloseInspectorForWindow(wwin);
1504 /* Close window menu if it's open for this window */
1505 if (wwin->flags.menu_open_for_me) {
1506 CloseWindowMenu(scr);
1509 if (!destroyed) {
1510 if (!wwin->flags.internal_window)
1511 XRemoveFromSaveSet(dpy, wwin->client_win);
1513 XSelectInput(dpy, wwin->client_win, NoEventMask);
1515 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1516 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1519 XUnmapWindow(dpy, frame->window);
1521 XUnmapWindow(dpy, wwin->client_win);
1523 /* deselect window */
1524 wSelectWindow(wwin, False);
1526 /* remove all pending events on window */
1527 /* I think this only matters for autoraise */
1528 if (wPreferences.raise_delay)
1529 WMDeleteTimerWithClientData(wwin->frame->core);
1531 XFlush(dpy);
1533 UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);
1535 /* reparent the window back to the root */
1536 if (restore)
1537 wClientRestore(wwin);
1539 if (wwin->transient_for!=scr->root_win) {
1540 owner = wWindowFor(wwin->transient_for);
1541 if (owner) {
1542 if (!owner->flags.semi_focused) {
1543 owner = NULL;
1544 } else {
1545 owner->flags.semi_focused = 0;
1550 wasFocused = wwin->flags.focused;
1552 /* remove from window focus list */
1553 if (!wwin->prev && !wwin->next) {
1554 /* was the only window */
1555 scr->focused_window = NULL;
1556 newFocusedWindow = NULL;
1557 } else {
1558 WWindow *tmp;
1560 if (wwin->prev)
1561 wwin->prev->next = wwin->next;
1562 if (wwin->next)
1563 wwin->next->prev = wwin->prev;
1564 else {
1565 scr->focused_window = wwin->prev;
1566 scr->focused_window->next = NULL;
1569 if (wPreferences.focus_mode==WKF_CLICK) {
1571 /* if in click to focus mode and the window
1572 * was a transient, focus the owner window
1574 tmp = NULL;
1575 if (wPreferences.focus_mode==WKF_CLICK) {
1576 tmp = wWindowFor(wwin->transient_for);
1577 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1578 tmp = NULL;
1581 /* otherwise, focus the next one in the focus list */
1582 if (!tmp) {
1583 tmp = scr->focused_window;
1584 while (tmp) { /* look for one in the window list first */
1585 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1586 && (tmp->flags.mapped || tmp->flags.shaded))
1587 break;
1588 tmp = tmp->prev;
1590 if (!tmp) { /* if unsuccessful, choose any focusable window */
1591 tmp = scr->focused_window;
1592 while (tmp) {
1593 if (!WFLAGP(tmp, no_focusable)
1594 && (tmp->flags.mapped || tmp->flags.shaded))
1595 break;
1596 tmp = tmp->prev;
1601 newFocusedWindow = tmp;
1603 } else if (wPreferences.focus_mode==WKF_SLOPPY
1604 || wPreferences.focus_mode==WKF_POINTER) {
1605 unsigned int mask;
1606 int foo;
1607 Window bar, win;
1609 /* This is to let the root window get the keyboard input
1610 * if Sloppy focus mode and no other window get focus.
1611 * This way keybindings will not freeze.
1613 tmp = NULL;
1614 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1615 &foo, &foo, &foo, &foo, &mask))
1616 tmp = wWindowFor(win);
1617 if (tmp == wwin)
1618 tmp = NULL;
1619 newFocusedWindow = tmp;
1620 } else {
1621 newFocusedWindow = NULL;
1625 if (!wwin->flags.internal_window) {
1626 #ifdef GNOME_STUFF
1627 wGNOMERemoveClient(wwin);
1628 #endif
1629 #ifdef KWM_HINTS
1630 wKWMSendEventMessage(wwin, WKWMRemoveWindow);
1631 #endif
1634 #ifdef DEBUG
1635 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1636 (unsigned)frame->window);
1637 #endif
1639 if (wasFocused) {
1640 if (newFocusedWindow != owner && owner) {
1641 if (wwin->flags.is_gnustep == 0)
1642 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1644 wSetFocusTo(scr, newFocusedWindow);
1646 wWindowDestroy(wwin);
1647 XFlush(dpy);
1651 void
1652 wWindowMap(WWindow *wwin)
1654 XMapWindow(dpy, wwin->frame->core->window);
1655 if (!wwin->flags.shaded) {
1656 /* window will be remapped when getting MapNotify */
1657 XSelectInput(dpy, wwin->client_win,
1658 wwin->event_mask & ~StructureNotifyMask);
1659 XMapWindow(dpy, wwin->client_win);
1660 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1662 wwin->flags.mapped = 1;
1667 void
1668 wWindowUnmap(WWindow *wwin)
1670 wwin->flags.mapped = 0;
1672 /* prevent window withdrawal when getting UnmapNotify */
1673 XSelectInput(dpy, wwin->client_win,
1674 wwin->event_mask & ~StructureNotifyMask);
1675 XUnmapWindow(dpy, wwin->client_win);
1676 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1678 XUnmapWindow(dpy, wwin->frame->core->window);
1683 void
1684 wWindowFocus(WWindow *wwin, WWindow *owin)
1686 WWindow *nowner;
1687 WWindow *oowner;
1689 #ifdef KEEP_XKB_LOCK_STATUS
1690 if (wPreferences.modelock) {
1691 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1693 #endif /* KEEP_XKB_LOCK_STATUS */
1695 wwin->flags.semi_focused = 0;
1697 if (wwin->flags.is_gnustep == 0)
1698 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1700 wwin->flags.focused = 1;
1702 wWindowResetMouseGrabs(wwin);
1704 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1706 if (owin == wwin || !owin)
1707 return;
1709 nowner = wWindowFor(wwin->transient_for);
1711 /* new window is a transient for the old window */
1712 if (nowner == owin) {
1713 owin->flags.semi_focused = 1;
1714 wWindowUnfocus(nowner);
1715 return;
1718 oowner = wWindowFor(owin->transient_for);
1720 /* new window is owner of old window */
1721 if (wwin == oowner) {
1722 wWindowUnfocus(owin);
1723 return;
1726 if (!nowner) {
1727 wWindowUnfocus(owin);
1728 return;
1731 /* new window has same owner of old window */
1732 if (oowner == nowner) {
1733 /* prevent unfocusing of owner */
1734 oowner->flags.semi_focused = 0;
1735 wWindowUnfocus(owin);
1736 oowner->flags.semi_focused = 1;
1738 return;
1741 /* nowner != NULL && oowner != nowner */
1742 nowner->flags.semi_focused = 1;
1743 wWindowUnfocus(nowner);
1744 wWindowUnfocus(owin);
1748 void
1749 wWindowUnfocus(WWindow *wwin)
1751 CloseWindowMenu(wwin->screen_ptr);
1753 if (wwin->flags.is_gnustep == 0)
1754 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1755 ? WS_PFOCUSED : WS_UNFOCUSED);
1757 if (wwin->transient_for!=None
1758 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1759 WWindow *owner;
1760 owner = wWindowFor(wwin->transient_for);
1761 if (owner && owner->flags.semi_focused) {
1762 owner->flags.semi_focused = 0;
1763 if (owner->flags.mapped || owner->flags.shaded) {
1764 wWindowUnfocus(owner);
1765 wFrameWindowPaint(owner->frame);
1769 wwin->flags.focused = 0;
1771 wWindowResetMouseGrabs(wwin);
1773 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1780 *----------------------------------------------------------------------
1782 * wWindowConstrainSize--
1783 * Constrains size for the client window, taking the maximal size,
1784 * window resize increments and other size hints into account.
1786 * Returns:
1787 * The closest size to what was given that the client window can
1788 * have.
1790 *----------------------------------------------------------------------
1792 void
1793 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1795 int width = *nwidth;
1796 int height = *nheight;
1797 int winc = 1;
1798 int hinc = 1;
1799 int minW = 1, minH = 1;
1800 int maxW = wwin->screen_ptr->scr_width*2;
1801 int maxH = wwin->screen_ptr->scr_height*2;
1802 int minAX = -1, minAY = -1;
1803 int maxAX = -1, maxAY = -1;
1804 int baseW = 0;
1805 int baseH = 0;
1807 if (wwin->normal_hints) {
1808 winc = wwin->normal_hints->width_inc;
1809 hinc = wwin->normal_hints->height_inc;
1810 minW = wwin->normal_hints->min_width;
1811 minH = wwin->normal_hints->min_height;
1812 maxW = wwin->normal_hints->max_width;
1813 maxH = wwin->normal_hints->max_height;
1814 if (wwin->normal_hints->flags & PAspect) {
1815 minAX = wwin->normal_hints->min_aspect.x;
1816 minAY = wwin->normal_hints->min_aspect.y;
1817 maxAX = wwin->normal_hints->max_aspect.x;
1818 maxAY = wwin->normal_hints->max_aspect.y;
1822 if (width < minW)
1823 width = minW;
1824 if (height < minH)
1825 height = minH;
1827 if (width > maxW)
1828 width = maxW;
1829 if (height > maxH)
1830 height = maxH;
1832 /* aspect ratio code borrowed from olwm */
1833 if (minAX > 0) {
1834 /* adjust max aspect ratio */
1835 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1836 if (maxAX > maxAY) {
1837 height = (width * maxAY) / maxAX;
1838 if (height > maxH) {
1839 height = maxH;
1840 width = (height * maxAX) / maxAY;
1842 } else {
1843 width = (height * maxAX) / maxAY;
1844 if (width > maxW) {
1845 width = maxW;
1846 height = (width * maxAY) / maxAX;
1851 /* adjust min aspect ratio */
1852 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1853 if (minAX > minAY) {
1854 height = (width * minAY) / minAX;
1855 if (height < minH) {
1856 height = minH;
1857 width = (height * minAX) / minAY;
1859 } else {
1860 width = (height * minAX) / minAY;
1861 if (width < minW) {
1862 width = minW;
1863 height = (width * minAY) / minAX;
1869 if (baseW != 0) {
1870 width = (((width - baseW) / winc) * winc) + baseW;
1871 } else {
1872 width = (((width - minW) / winc) * winc) + minW;
1875 if (baseW != 0) {
1876 height = (((height - baseH) / hinc) * hinc) + baseH;
1877 } else {
1878 height = (((height - minH) / hinc) * hinc) + minH;
1881 /* broken stupid apps may cause preposterous values for these.. */
1882 if (width > 0)
1883 *nwidth = width;
1884 if (height > 0)
1885 *nheight = height;
1889 void
1890 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1892 WScreen *scr = wwin->screen_ptr;
1893 WApplication *wapp;
1894 int unmap = 0;
1896 if (workspace >= scr->workspace_count || workspace < 0
1897 || workspace == wwin->frame->workspace)
1898 return;
1900 if (workspace != scr->current_workspace) {
1901 /* Sent to other workspace. Unmap window */
1902 if ((wwin->flags.mapped
1903 || wwin->flags.shaded
1904 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1905 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1907 wapp = wApplicationOf(wwin->main_window);
1908 if (wapp) {
1909 wapp->last_workspace = workspace;
1911 if (wwin->flags.miniaturized) {
1912 if (wwin->icon) {
1913 XUnmapWindow(dpy, wwin->icon->core->window);
1914 wwin->icon->mapped = 0;
1916 } else {
1917 unmap = 1;
1918 wSetFocusTo(scr, NULL);
1921 } else {
1922 /* brought to current workspace. Map window */
1923 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1924 if (wwin->icon) {
1925 XMapWindow(dpy, wwin->icon->core->window);
1926 wwin->icon->mapped = 1;
1928 } else if (!wwin->flags.mapped &&
1929 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1930 wWindowMap(wwin);
1933 if (!IS_OMNIPRESENT(wwin)) {
1934 wwin->frame->workspace = workspace;
1935 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1937 #ifdef GNOME_STUFF
1938 wGNOMEUpdateClientStateHint(wwin, True);
1939 #endif
1940 #ifdef KWM_HINTS
1941 wKWMUpdateClientWorkspace(wwin);
1942 wKWMSendEventMessage(wwin, WKWMChangedClient);
1943 #endif
1944 if (unmap) {
1945 wWindowUnmap(wwin);
1950 void
1951 wWindowSynthConfigureNotify(WWindow *wwin)
1953 XEvent sevent;
1955 sevent.type = ConfigureNotify;
1956 sevent.xconfigure.display = dpy;
1957 sevent.xconfigure.event = wwin->client_win;
1958 sevent.xconfigure.window = wwin->client_win;
1960 sevent.xconfigure.x = wwin->client.x;
1961 sevent.xconfigure.y = wwin->client.y;
1962 sevent.xconfigure.width = wwin->client.width;
1963 sevent.xconfigure.height = wwin->client.height;
1965 sevent.xconfigure.border_width = wwin->old_border_width;
1966 if (WFLAGP(wwin, no_titlebar))
1967 sevent.xconfigure.above = None;
1968 else
1969 sevent.xconfigure.above = wwin->frame->titlebar->window;
1971 sevent.xconfigure.override_redirect = False;
1972 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
1973 #ifdef KWM_HINTS
1974 wKWMSendEventMessage(wwin, WKWMChangedClient);
1975 #endif
1976 XFlush(dpy);
1981 *----------------------------------------------------------------------
1982 * wWindowConfigure--
1983 * Configures the frame, decorations and client window to the
1984 * specified geometry. The geometry is not checked for validity,
1985 * wWindowConstrainSize() must be used for that.
1986 * The size parameters are for the client window, but the position is
1987 * for the frame.
1988 * The client window receives a ConfigureNotify event, according
1989 * to what ICCCM says.
1991 * Returns:
1992 * None
1994 * Side effects:
1995 * Window size and position are changed and client window receives
1996 * a ConfigureNotify event.
1997 *----------------------------------------------------------------------
1999 void
2000 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2001 WWindow *wwin;
2002 int req_x, req_y; /* new position of the frame */
2003 int req_width, req_height; /* new size of the client */
2005 int synth_notify = False;
2006 int resize;
2008 resize = (req_width!=wwin->client.width
2009 || req_height!=wwin->client.height);
2011 * if the window is being moved but not resized then
2012 * send a synthetic ConfigureNotify
2014 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2015 synth_notify = True;
2018 if (WFLAGP(wwin, dont_move_off))
2019 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2020 req_width, req_height);
2021 if (resize) {
2022 if (req_width < MIN_WINDOW_SIZE)
2023 req_width = MIN_WINDOW_SIZE;
2024 if (req_height < MIN_WINDOW_SIZE)
2025 req_height = MIN_WINDOW_SIZE;
2027 /* If growing, resize inner part before frame,
2028 * if shrinking, resize frame before.
2029 * This will prevent the frame (that can have a different color)
2030 * to be exposed, causing flicker */
2031 if (req_height > wwin->frame->core->height
2032 || req_width > wwin->frame->core->width)
2033 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2035 if (wwin->flags.shaded) {
2036 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2037 req_width, wwin->frame->core->height);
2038 wwin->old_geometry.height = req_height;
2039 } else {
2040 int h;
2042 h = req_height + wwin->frame->top_width
2043 + wwin->frame->bottom_width;
2045 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2048 if (!(req_height > wwin->frame->core->height
2049 || req_width > wwin->frame->core->width))
2050 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2052 wwin->client.x = req_x;
2053 wwin->client.y = req_y + wwin->frame->top_width;
2054 wwin->client.width = req_width;
2055 wwin->client.height = req_height;
2056 } else {
2057 wwin->client.x = req_x;
2058 wwin->client.y = req_y + wwin->frame->top_width;
2060 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2062 wwin->frame_x = req_x;
2063 wwin->frame_y = req_y;
2064 if (!WFLAGP(wwin, no_border)) {
2065 wwin->client.x += FRAME_BORDER_WIDTH;
2066 wwin->client.y += FRAME_BORDER_WIDTH;
2069 #ifdef SHAPE
2070 if (wShapeSupported && wwin->flags.shaped && resize) {
2071 wWindowSetShape(wwin);
2073 #endif
2075 if (synth_notify)
2076 wWindowSynthConfigureNotify(wwin);
2077 XFlush(dpy);
2081 void
2082 wWindowMove(wwin, req_x, req_y)
2083 WWindow *wwin;
2084 int req_x, req_y; /* new position of the frame */
2086 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2087 int synth_notify = False;
2089 /* Send a synthetic ConfigureNotify event for every window movement. */
2090 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2091 synth_notify = True;
2093 #else
2094 /* A single synthetic ConfigureNotify event is sent at the end of
2095 * a completed (opaque) movement in moveres.c */
2096 #endif
2098 if (WFLAGP(wwin, dont_move_off))
2099 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2100 wwin->frame->core->width, wwin->frame->core->height);
2102 wwin->client.x = req_x;
2103 wwin->client.y = req_y + wwin->frame->top_width;
2104 if (!WFLAGP(wwin, no_border)) {
2105 wwin->client.x += FRAME_BORDER_WIDTH;
2106 wwin->client.y += FRAME_BORDER_WIDTH;
2109 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2111 wwin->frame_x = req_x;
2112 wwin->frame_y = req_y;
2114 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2115 if (synth_notify)
2116 wWindowSynthConfigureNotify(wwin);
2117 #endif
2121 void
2122 wWindowUpdateButtonImages(WWindow *wwin)
2124 WScreen *scr = wwin->screen_ptr;
2125 Pixmap pixmap, mask;
2126 WFrameWindow *fwin = wwin->frame;
2128 if (WFLAGP(wwin, no_titlebar))
2129 return;
2131 /* miniaturize button */
2133 if (!WFLAGP(wwin, no_miniaturize_button)) {
2134 if (wwin->wm_gnustep_attr
2135 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2136 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2138 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2139 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2140 } else {
2141 mask = None;
2144 if (fwin->lbutton_image
2145 && (fwin->lbutton_image->image != pixmap
2146 || fwin->lbutton_image->mask != mask)) {
2147 wPixmapDestroy(fwin->lbutton_image);
2148 fwin->lbutton_image = NULL;
2151 if (!fwin->lbutton_image) {
2152 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2153 fwin->lbutton_image->client_owned = 1;
2154 fwin->lbutton_image->client_owned_mask = 1;
2156 } else {
2157 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2158 wPixmapDestroy(fwin->lbutton_image);
2160 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2164 #ifdef XKB_BUTTON_HINT
2165 if (!WFLAGP(wwin, no_language_button)) {
2166 if (fwin->languagebutton_image &&
2167 !fwin->languagebutton_image->shared) {
2168 wPixmapDestroy(fwin->languagebutton_image);
2170 fwin->languagebutton_image =
2171 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2173 #endif
2175 /* close button */
2177 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2178 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2180 if (!WFLAGP(wwin, no_close_button)) {
2181 if (wwin->wm_gnustep_attr
2182 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2183 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2185 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2186 mask = wwin->wm_gnustep_attr->close_mask;
2187 else
2188 mask = None;
2190 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2191 || fwin->rbutton_image->mask != mask)) {
2192 wPixmapDestroy(fwin->rbutton_image);
2193 fwin->rbutton_image = NULL;
2196 if (!fwin->rbutton_image) {
2197 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2198 fwin->rbutton_image->client_owned = 1;
2199 fwin->rbutton_image->client_owned_mask = 1;
2202 } else if (WFLAGP(wwin, kill_close)) {
2204 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2205 wPixmapDestroy(fwin->rbutton_image);
2207 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2209 } else if (MGFLAGP(wwin, broken_close)) {
2211 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2212 wPixmapDestroy(fwin->rbutton_image);
2214 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2216 } else {
2218 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2219 wPixmapDestroy(fwin->rbutton_image);
2221 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2225 /* force buttons to be redrawn */
2226 fwin->flags.need_texture_change = 1;
2227 wFrameWindowPaint(fwin);
2232 *---------------------------------------------------------------------------
2233 * wWindowConfigureBorders--
2234 * Update window border configuration according to attribute flags.
2236 *---------------------------------------------------------------------------
2238 void
2239 wWindowConfigureBorders(WWindow *wwin)
2241 if (wwin->frame) {
2242 int flags;
2243 int newy, oldh;
2245 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2246 #ifdef XKB_BUTTON_HINT
2247 flags |= WFF_LANGUAGE_BUTTON;
2248 #endif
2249 if (!WFLAGP(wwin, no_titlebar))
2250 flags |= WFF_TITLEBAR;
2251 if (!WFLAGP(wwin, no_resizebar))
2252 flags |= WFF_RESIZEBAR;
2253 if (!WFLAGP(wwin, no_border))
2254 flags |= WFF_BORDER;
2255 if (wwin->flags.shaded)
2256 flags |= WFF_IS_SHADED;
2258 oldh = wwin->frame->top_width;
2259 wFrameWindowUpdateBorders(wwin->frame, flags);
2260 if (oldh != wwin->frame->top_width) {
2261 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2263 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2264 wWindowConfigure(wwin, wwin->frame_x, newy,
2265 wwin->client.width, wwin->client.height);
2268 flags = 0;
2269 if (!WFLAGP(wwin, no_miniaturize_button)
2270 && wwin->frame->flags.hide_left_button)
2271 flags |= WFF_LEFT_BUTTON;
2273 #ifdef XKB_BUTTON_HINT
2274 if (!WFLAGP(wwin, no_language_button)
2275 && wwin->frame->flags.hide_language_button)
2276 flags |= WFF_LANGUAGE_BUTTON;
2277 #endif
2279 if (!WFLAGP(wwin, no_close_button)
2280 && wwin->frame->flags.hide_right_button)
2281 flags |= WFF_RIGHT_BUTTON;
2283 if (flags!=0) {
2284 wWindowUpdateButtonImages(wwin);
2285 wFrameWindowShowButton(wwin->frame, flags);
2288 flags = 0;
2289 if (WFLAGP(wwin, no_miniaturize_button)
2290 && !wwin->frame->flags.hide_left_button)
2291 flags |= WFF_LEFT_BUTTON;
2293 #ifdef XKB_BUTTON_HINT
2294 if (WFLAGP(wwin, no_language_button)
2295 && !wwin->frame->flags.hide_language_button)
2296 flags |= WFF_LANGUAGE_BUTTON;
2297 #endif
2299 if (WFLAGP(wwin, no_close_button)
2300 && !wwin->frame->flags.hide_right_button)
2301 flags |= WFF_RIGHT_BUTTON;
2303 if (flags!=0)
2304 wFrameWindowHideButton(wwin->frame, flags);
2306 #ifdef SHAPE
2307 if (wShapeSupported && wwin->flags.shaped) {
2308 wWindowSetShape(wwin);
2310 #endif
2315 void
2316 wWindowSaveState(WWindow *wwin)
2318 CARD32 data[10];
2319 int i;
2321 memset(data, 0, sizeof(CARD32)*10);
2322 data[0] = wwin->frame->workspace;
2323 data[1] = wwin->flags.miniaturized;
2324 data[2] = wwin->flags.shaded;
2325 data[3] = wwin->flags.hidden;
2326 data[4] = wwin->flags.maximized;
2327 if (wwin->flags.maximized == 0) {
2328 data[5] = wwin->frame_x;
2329 data[6] = wwin->frame_y;
2330 data[7] = wwin->frame->core->width;
2331 data[8] = wwin->frame->core->height;
2332 } else {
2333 data[5] = wwin->old_geometry.x;
2334 data[6] = wwin->old_geometry.y;
2335 data[7] = wwin->old_geometry.width;
2336 data[8] = wwin->old_geometry.height;
2339 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2340 if (wwin->screen_ptr->shortcutWindows[i] &&
2341 WMCountInBag(wwin->screen_ptr->shortcutWindows[i], wwin))
2342 data[9] |= 1<<i;
2344 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2345 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2346 (unsigned char *)data, 10);
2350 static int
2351 getSavedState(Window window, WSavedState **state)
2353 Atom type_ret;
2354 int fmt_ret;
2355 unsigned long nitems_ret;
2356 unsigned long bytes_after_ret;
2357 CARD32 *data;
2359 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2360 True, _XA_WINDOWMAKER_STATE,
2361 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2362 (unsigned char **)&data)!=Success || !data)
2363 return 0;
2365 *state = malloc(sizeof(WSavedState));
2367 if (*state) {
2368 (*state)->workspace = data[0];
2369 (*state)->miniaturized = data[1];
2370 (*state)->shaded = data[2];
2371 (*state)->hidden = data[3];
2372 (*state)->maximized = data[4];
2373 (*state)->x = data[5];
2374 (*state)->y = data[6];
2375 (*state)->w = data[7];
2376 (*state)->h = data[8];
2377 (*state)->window_shortcuts = data[9];
2379 XFree(data);
2381 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2382 return 1;
2383 else
2384 return 0;
2388 #ifdef SHAPE
2389 void
2390 wWindowClearShape(WWindow *wwin)
2392 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2393 0, wwin->frame->top_width, None, ShapeSet);
2394 XFlush(dpy);
2397 void
2398 wWindowSetShape(WWindow *wwin)
2400 XRectangle rect[2];
2401 int count;
2402 #ifdef OPTIMIZE_SHAPE
2403 XRectangle *rects;
2404 XRectangle *urec;
2405 int ordering;
2407 /* only shape is the client's */
2408 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2409 goto alt_code;
2412 /* Get array of rectangles describing the shape mask */
2413 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2414 &count, &ordering);
2415 if (!rects) {
2416 goto alt_code;
2419 urec = malloc(sizeof(XRectangle)*(count+2));
2420 if (!urec) {
2421 XFree(rects);
2422 goto alt_code;
2425 /* insert our decoration rectangles in the rect list */
2426 memcpy(urec, rects, sizeof(XRectangle)*count);
2427 XFree(rects);
2429 if (!WFLAGP(wwin, no_titlebar)) {
2430 urec[count].x = -1;
2431 urec[count].y = -1 - wwin->frame->top_width;
2432 urec[count].width = wwin->frame->core->width + 2;
2433 urec[count].height = wwin->frame->top_width + 1;
2434 count++;
2436 if (!WFLAGP(wwin, no_resizebar)) {
2437 urec[count].x = -1;
2438 urec[count].y = wwin->frame->core->height
2439 - wwin->frame->bottom_width - wwin->frame->top_width;
2440 urec[count].width = wwin->frame->core->width + 2;
2441 urec[count].height = wwin->frame->bottom_width + 1;
2442 count++;
2445 /* shape our frame window */
2446 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2447 0, wwin->frame->top_width, urec, count,
2448 ShapeSet, Unsorted);
2449 XFlush(dpy);
2450 wfree(urec);
2451 return;
2453 alt_code:
2454 #endif /* OPTIMIZE_SHAPE */
2455 count = 0;
2456 if (!WFLAGP(wwin, no_titlebar)) {
2457 rect[count].x = -1;
2458 rect[count].y = -1;
2459 rect[count].width = wwin->frame->core->width + 2;
2460 rect[count].height = wwin->frame->top_width + 1;
2461 count++;
2463 if (!WFLAGP(wwin, no_resizebar)) {
2464 rect[count].x = -1;
2465 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2466 rect[count].width = wwin->frame->core->width + 2;
2467 rect[count].height = wwin->frame->bottom_width + 1;
2468 count++;
2470 if (count > 0) {
2471 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2472 0, 0, rect, count, ShapeSet, Unsorted);
2474 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2475 0, wwin->frame->top_width, wwin->client_win,
2476 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2477 XFlush(dpy);
2479 #endif /* SHAPE */
2481 /* ====================================================================== */
2483 static FocusMode
2484 getFocusMode(WWindow *wwin)
2486 FocusMode mode;
2488 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2489 if (wwin->wm_hints->input == True) {
2490 if (wwin->protocols.TAKE_FOCUS)
2491 mode = WFM_LOCALLY_ACTIVE;
2492 else
2493 mode = WFM_PASSIVE;
2494 } else {
2495 if (wwin->protocols.TAKE_FOCUS)
2496 mode = WFM_GLOBALLY_ACTIVE;
2497 else
2498 mode = WFM_NO_INPUT;
2500 } else {
2501 mode = WFM_PASSIVE;
2503 return mode;
2507 void
2508 wWindowSetKeyGrabs(WWindow *wwin)
2510 int i;
2511 WShortKey *key;
2513 for (i=0; i<WKBD_LAST; i++) {
2514 key = &wKeyBindings[i];
2516 if (key->keycode==0)
2517 continue;
2518 if (key->modifier!=AnyModifier) {
2519 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2520 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2521 #ifdef NUMLOCK_HACK
2522 /* Also grab all modifier combinations possible that include,
2523 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2524 * work even if the NumLock/ScrollLock key is on.
2526 wHackedGrabKey(key->keycode, key->modifier,
2527 wwin->frame->core->window, True, GrabModeAsync,
2528 GrabModeAsync);
2529 #endif
2531 XGrabKey(dpy, key->keycode, key->modifier,
2532 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2535 #ifndef LITE
2536 wRootMenuBindShortcuts(wwin->frame->core->window);
2537 #endif
2542 void
2543 wWindowResetMouseGrabs(WWindow *wwin)
2545 /* Mouse grabs can't be done on the client window because of
2546 * ICCCM and because clients that try to do the same will crash.
2548 * But there is a problem wich makes tbar buttons of unfocused
2549 * windows not usable as the click goes to the frame window instead
2550 * of the button itself. Must figure a way to fix that.
2553 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2555 if (!WFLAGP(wwin, no_bind_mouse)) {
2556 /* grabs for Meta+drag */
2557 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2558 True, ButtonPressMask, GrabModeSync,
2559 GrabModeAsync, None, None);
2562 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2563 && !wwin->flags.is_gnustep) {
2564 /* the passive grabs to focus the window */
2565 /* if (wPreferences.focus_mode == WKF_CLICK) */
2566 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2567 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2568 None, None);
2570 XFlush(dpy);
2574 void
2575 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2577 if (attr->flags & GSExtraFlagsAttr) {
2578 if (MGFLAGP(wwin, broken_close) !=
2579 (attr->extra_flags & GSDocumentEditedFlag)) {
2580 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2581 wWindowUpdateButtonImages(wwin);
2587 WMagicNumber
2588 wWindowAddSavedState(char *instance, char *class, char *command,
2589 pid_t pid, WSavedState *state)
2591 WWindowState *wstate;
2593 wstate = malloc(sizeof(WWindowState));
2594 if (!wstate)
2595 return 0;
2597 memset(wstate, 0, sizeof(WWindowState));
2598 wstate->pid = pid;
2599 if (instance)
2600 wstate->instance = wstrdup(instance);
2601 if (class)
2602 wstate->class = wstrdup(class);
2603 if (command)
2604 wstate->command = wstrdup(command);
2605 wstate->state = state;
2607 wstate->next = windowState;
2608 windowState = wstate;
2610 #ifdef DEBUG
2611 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2612 class, command);
2613 #endif
2615 return wstate;
2619 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2622 WMagicNumber
2623 wWindowGetSavedState(Window win)
2625 char *instance, *class, *command=NULL;
2626 WWindowState *wstate = windowState;
2627 char **argv;
2628 int argc;
2630 if (!wstate)
2631 return NULL;
2633 if (XGetCommand(dpy, win, &argv, &argc)) {
2634 if (argc > 0)
2635 command = wtokenjoin(argv, argc);
2636 XFreeStringList(argv);
2638 if (!command)
2639 return NULL;
2641 if (PropGetWMClass(win, &class, &instance)) {
2642 while (wstate) {
2643 if (SAME(instance, wstate->instance) &&
2644 SAME(class, wstate->class) &&
2645 SAME(command, wstate->command)) {
2646 break;
2648 wstate = wstate->next;
2650 } else {
2651 wstate = NULL;
2654 #ifdef DEBUG
2655 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2656 class, command);
2657 #endif
2659 if (command) wfree(command);
2660 if (instance) XFree(instance);
2661 if (class) XFree(class);
2663 return wstate;
2667 void
2668 wWindowDeleteSavedState(WMagicNumber id)
2670 WWindowState *tmp, *wstate=(WWindowState*)id;
2672 if (!wstate || !windowState)
2673 return;
2675 tmp = windowState;
2676 if (tmp==wstate) {
2677 windowState = wstate->next;
2678 #ifdef DEBUG
2679 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2680 wstate, wstate->instance, wstate->class, wstate->command);
2681 #endif
2682 if (wstate->instance) wfree(wstate->instance);
2683 if (wstate->class) wfree(wstate->class);
2684 if (wstate->command) wfree(wstate->command);
2685 wfree(wstate->state);
2686 wfree(wstate);
2687 } else {
2688 while (tmp->next) {
2689 if (tmp->next==wstate) {
2690 tmp->next=wstate->next;
2691 #ifdef DEBUG
2692 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2693 wstate, wstate->instance, wstate->class, wstate->command);
2694 #endif
2695 if (wstate->instance) wfree(wstate->instance);
2696 if (wstate->class) wfree(wstate->class);
2697 if (wstate->command) wfree(wstate->command);
2698 wfree(wstate->state);
2699 wfree(wstate);
2700 break;
2702 tmp = tmp->next;
2708 void
2709 wWindowDeleteSavedStatesForPID(pid_t pid)
2711 WWindowState *tmp, *wstate;
2713 if (!windowState)
2714 return;
2716 tmp = windowState;
2717 if (tmp->pid == pid) {
2718 wstate = windowState;
2719 windowState = tmp->next;
2720 #ifdef DEBUG
2721 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2722 wstate, wstate->instance, wstate->class, wstate->command);
2723 #endif
2724 if (wstate->instance) wfree(wstate->instance);
2725 if (wstate->class) wfree(wstate->class);
2726 if (wstate->command) wfree(wstate->command);
2727 wfree(wstate->state);
2728 wfree(wstate);
2729 } else {
2730 while (tmp->next) {
2731 if (tmp->next->pid==pid) {
2732 wstate = tmp->next;
2733 tmp->next = wstate->next;
2734 #ifdef DEBUG
2735 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2736 wstate, wstate->instance, wstate->class, wstate->command);
2737 #endif
2738 if (wstate->instance) wfree(wstate->instance);
2739 if (wstate->class) wfree(wstate->class);
2740 if (wstate->command) wfree(wstate->command);
2741 wfree(wstate->state);
2742 wfree(wstate);
2743 break;
2745 tmp = tmp->next;
2751 /* ====================================================================== */
2753 static void
2754 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2756 WWindow *wwin = data;
2758 #ifndef NUMLOCK_HACK
2759 if ((event->xbutton.state & ValidModMask)
2760 != (event->xbutton.state & ~LockMask)) {
2761 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2762 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2764 #endif
2766 event->xbutton.state &= ValidModMask;
2768 CloseWindowMenu(wwin->screen_ptr);
2770 if (wPreferences.focus_mode==WKF_CLICK
2771 && !(event->xbutton.state&ControlMask)
2772 && !WFLAGP(wwin, no_focusable)) {
2773 wSetFocusTo(wwin->screen_ptr, wwin);
2776 if (event->xbutton.button == Button1)
2777 wRaiseFrame(wwin->frame->core);
2779 if (event->xbutton.window != wwin->frame->resizebar->window) {
2780 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2781 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2782 GrabModeAsync, GrabModeAsync, None,
2783 None, CurrentTime)!=GrabSuccess) {
2784 #ifdef DEBUG0
2785 wwarning("pointer grab failed for window move");
2786 #endif
2787 return;
2791 if (event->xbutton.state & MOD_MASK) {
2792 /* move the window */
2793 wMouseMoveWindow(wwin, event);
2794 XUngrabPointer(dpy, CurrentTime);
2795 } else {
2796 wMouseResizeWindow(wwin, event);
2797 XUngrabPointer(dpy, CurrentTime);
2803 static void
2804 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2806 WWindow *wwin = data;
2808 event->xbutton.state &= ValidModMask;
2810 if (event->xbutton.button==Button1) {
2811 if (event->xbutton.state == 0) {
2812 if (!WFLAGP(wwin, no_shadeable)) {
2813 /* shade window */
2814 if (wwin->flags.shaded)
2815 wUnshadeWindow(wwin);
2816 else
2817 wShadeWindow(wwin);
2819 } else {
2820 int dir = 0;
2822 if (event->xbutton.state & ControlMask)
2823 dir |= MAX_VERTICAL;
2825 if (event->xbutton.state & ShiftMask) {
2826 dir |= MAX_HORIZONTAL;
2827 if (!(event->xbutton.state & ControlMask))
2828 wSelectWindow(wwin, !wwin->flags.selected);
2831 /* maximize window */
2832 if (dir !=0 && !WFLAGP(wwin, no_resizable)) {
2833 int ndir = dir ^ wwin->flags.maximized;
2834 if (wwin->flags.maximized != 0)
2835 wUnmaximizeWindow(wwin);
2836 if (ndir != 0)
2837 wMaximizeWindow(wwin, ndir);
2840 } else if (event->xbutton.button==Button3) {
2841 if (event->xbutton.state & MOD_MASK) {
2842 wHideOtherApplications(wwin);
2844 } else if (event->xbutton.button==Button2) {
2845 wSelectWindow(wwin, !wwin->flags.selected);
2850 static void
2851 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2853 WWindow *wwin = desc->parent;
2855 event->xbutton.state &= ValidModMask;
2857 CloseWindowMenu(wwin->screen_ptr);
2859 if (/*wPreferences.focus_mode==WKF_CLICK
2860 &&*/ !(event->xbutton.state&ControlMask)
2861 && !WFLAGP(wwin, no_focusable)) {
2862 wSetFocusTo(wwin->screen_ptr, wwin);
2864 if (event->xbutton.button == Button1) {
2865 wRaiseFrame(wwin->frame->core);
2868 if (event->xbutton.state & MOD_MASK) {
2869 /* move the window */
2870 if (XGrabPointer(dpy, wwin->client_win, False,
2871 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2872 GrabModeAsync, GrabModeAsync, None,
2873 None, CurrentTime)!=GrabSuccess) {
2874 #ifdef DEBUG0
2875 wwarning("pointer grab failed for window move");
2876 #endif
2877 return;
2879 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2880 wMouseResizeWindow(wwin, event);
2881 else
2882 wMouseMoveWindow(wwin, event);
2883 XUngrabPointer(dpy, CurrentTime);
2888 static void
2889 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2891 WWindow *wwin = (WWindow*)data;
2893 #ifndef NUMLOCK_HACK
2894 if ((event->xbutton.state & ValidModMask)
2895 != (event->xbutton.state & ~LockMask)) {
2896 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2897 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2899 #endif
2900 event->xbutton.state &= ValidModMask;
2902 CloseWindowMenu(wwin->screen_ptr);
2904 if (wPreferences.focus_mode==WKF_CLICK
2905 && !(event->xbutton.state&ControlMask)
2906 && !WFLAGP(wwin, no_focusable)) {
2907 wSetFocusTo(wwin->screen_ptr, wwin);
2910 if (event->xbutton.button == Button1
2911 || event->xbutton.button == Button2) {
2913 if (event->xbutton.button == Button1) {
2914 if (event->xbutton.state & MOD_MASK) {
2915 wLowerFrame(wwin->frame->core);
2916 } else {
2917 wRaiseFrame(wwin->frame->core);
2920 if ((event->xbutton.state & ShiftMask)
2921 && !(event->xbutton.state & ControlMask)) {
2922 wSelectWindow(wwin, !wwin->flags.selected);
2923 return;
2925 if (event->xbutton.window != wwin->frame->titlebar->window
2926 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2927 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2928 GrabModeAsync, GrabModeAsync, None,
2929 None, CurrentTime)!=GrabSuccess) {
2930 #ifdef DEBUG0
2931 wwarning("pointer grab failed for window move");
2932 #endif
2933 return;
2936 /* move the window */
2937 wMouseMoveWindow(wwin, event);
2939 XUngrabPointer(dpy, CurrentTime);
2940 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2941 && !wwin->flags.internal_window
2942 && !WCHECK_STATE(WSTATE_MODAL)) {
2943 WObjDescriptor *desc;
2945 if (event->xbutton.window != wwin->frame->titlebar->window
2946 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2947 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2948 GrabModeAsync, GrabModeAsync, None,
2949 None, CurrentTime)!=GrabSuccess) {
2950 #ifdef DEBUG0
2951 wwarning("pointer grab failed for window move");
2952 #endif
2953 return;
2956 OpenWindowMenu(wwin, event->xbutton.x_root,
2957 wwin->frame_y+wwin->frame->top_width, False);
2959 /* allow drag select */
2960 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2961 event->xany.send_event = True;
2962 (*desc->handle_mousedown)(desc, event);
2964 XUngrabPointer(dpy, CurrentTime);
2970 static void
2971 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
2973 WWindow *wwin = data;
2975 event->xbutton.state &= ValidModMask;
2977 CloseWindowMenu(wwin->screen_ptr);
2979 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2980 return;
2982 /* if control-click, kill the client */
2983 if (event->xbutton.state & ControlMask) {
2984 wClientKill(wwin);
2985 } else {
2986 #ifdef OLWM_HINTS
2987 if (wwin->flags.olwm_push_pin_out) {
2989 wwin->flags.olwm_push_pin_out = 0;
2991 wOLWMChangePushpinState(wwin, True);
2993 wFrameWindowUpdatePushButton(wwin->frame, False);
2995 return;
2997 #endif
2998 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
2999 /* send delete message */
3000 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3006 static void
3007 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3009 WWindow *wwin = data;
3011 CloseWindowMenu(wwin->screen_ptr);
3013 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3014 return;
3016 /* send delete message */
3017 if (wwin->protocols.DELETE_WINDOW) {
3018 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3019 } else {
3020 wClientKill(wwin);
3025 #ifdef XKB_BUTTON_HINT
3026 static void
3027 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3029 WWindow *wwin = data;
3030 WFrameWindow *fwin = wwin->frame;
3031 WScreen *scr = fwin->screen_ptr;
3032 XkbStateRec staterec;
3033 int tl;
3035 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3036 return;
3037 tl = wwin->frame->languagemode;
3038 wwin->frame->languagemode = wwin->frame->last_languagemode;
3039 wwin->frame->last_languagemode = tl;
3040 wSetFocusTo(scr, wwin);
3041 wwin->frame->languagebutton_image =
3042 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3043 wwin->frame->languagemode];
3044 wFrameWindowUpdateLanguageButton(wwin->frame);
3045 if (event->xbutton.button == Button3)
3046 return;
3047 wRaiseFrame(fwin->core);
3049 #endif
3052 static void
3053 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3055 WWindow *wwin = data;
3057 event->xbutton.state &= ValidModMask;
3059 CloseWindowMenu(wwin->screen_ptr);
3061 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3062 return;
3064 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3065 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3066 LastTimestamp);
3067 } else {
3068 WApplication *wapp;
3069 if ((event->xbutton.state & ControlMask) ||
3070 (event->xbutton.button == Button3)) {
3072 wapp = wApplicationOf(wwin->main_window);
3073 if (wapp && !WFLAGP(wwin, no_appicon))
3074 wHideApplication(wapp);
3075 } else if (event->xbutton.state==0) {
3076 wIconifyWindow(wwin);