- Finished moving to the new proplist handling code in WINGs.
[wmaker-crm.git] / src / window.c
blobd551d2dace5429e7716bb2040f9881bde3c94f19
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*);
100 /***** Local Stuff *****/
103 static WWindowState *windowState=NULL;
107 /* local functions */
108 static FocusMode getFocusMode(WWindow *wwin);
110 static int getSavedState(Window window, WSavedState **state);
112 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
114 /* event handlers */
117 /* frame window (during window grabs) */
118 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
120 /* close button */
121 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
122 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
124 /* iconify button */
125 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
127 #ifdef XKB_BUTTON_HINT
128 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
129 #endif
131 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
132 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
134 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
137 /****** Notification Observers ******/
139 static void
140 appearanceObserver(void *self, WMNotification *notif)
142 WWindow *wwin = (WWindow*)self;
143 int flags = (int)WMGetNotificationClientData(notif);
145 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
146 return;
148 if (flags & WFontSettings) {
149 wWindowConfigureBorders(wwin);
150 if(wwin->flags.shaded) {
151 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
152 wwin->frame->top_width - 1);
154 wwin->client.y = wwin->frame_y - wwin->client.height
155 + wwin->frame->top_width;
156 wWindowSynthConfigureNotify(wwin);
159 if (flags & WTextureSettings) {
160 wwin->frame->flags.need_texture_remake = 1;
162 if (flags & (WTextureSettings | WColorSettings)) {
163 if (wwin->frame->titlebar)
164 XClearWindow(dpy, wwin->frame->titlebar->window);
166 wFrameWindowPaint(wwin->frame);
170 /************************************/
172 WWindow*
173 wWindowFor(Window window)
175 WObjDescriptor *desc;
177 if (window==None)
178 return NULL;
180 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
181 return NULL;
183 if (desc->parent_type==WCLASS_WINDOW)
184 return desc->parent;
185 else if (desc->parent_type==WCLASS_FRAME) {
186 WFrameWindow *frame = (WFrameWindow*)desc->parent;
187 if (frame->flags.is_client_window_frame)
188 return frame->child;
191 return NULL;
195 WWindow*
196 wWindowCreate()
198 WWindow *wwin;
200 wwin = wmalloc(sizeof(WWindow));
201 wretain(wwin);
203 memset(wwin, 0, sizeof(WWindow));
205 wwin->client_descriptor.handle_mousedown = frameMouseDown;
206 wwin->client_descriptor.parent = wwin;
207 wwin->client_descriptor.self = wwin;
208 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
210 return wwin;
214 void
215 wWindowDestroy(WWindow *wwin)
217 int i;
219 if (wwin->screen_ptr->cmap_window == wwin) {
220 wwin->screen_ptr->cmap_window = NULL;
223 WMRemoveNotificationObserver(wwin);
225 wwin->flags.destroyed = 1;
227 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
228 if (!wwin->screen_ptr->shortcutWindows[i])
229 continue;
231 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
233 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
234 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
235 wwin->screen_ptr->shortcutWindows[i] = NULL;
239 if (wwin->normal_hints)
240 XFree(wwin->normal_hints);
242 if (wwin->wm_hints)
243 XFree(wwin->wm_hints);
245 if (wwin->wm_instance)
246 XFree(wwin->wm_instance);
248 if (wwin->wm_class)
249 XFree(wwin->wm_class);
251 if (wwin->wm_gnustep_attr)
252 wfree(wwin->wm_gnustep_attr);
254 if (wwin->cmap_windows)
255 XFree(wwin->cmap_windows);
257 XDeleteContext(dpy, wwin->client_win, wWinContext);
259 if (wwin->frame)
260 wFrameWindowDestroy(wwin->frame);
262 if (wwin->icon) {
263 RemoveFromStackList(wwin->icon->core);
264 wIconDestroy(wwin->icon);
265 if (wPreferences.auto_arrange_icons)
266 wArrangeIcons(wwin->screen_ptr, True);
268 wrelease(wwin);
274 static void
275 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
277 if (gs_hints->flags & GSWindowStyleAttr) {
278 if (gs_hints->window_style == WMBorderlessWindowMask) {
279 wwin->client_flags.no_border = 1;
280 wwin->client_flags.no_titlebar = 1;
281 wwin->client_flags.no_closable = 1;
282 wwin->client_flags.no_miniaturizable = 1;
283 wwin->client_flags.no_resizable = 1;
284 wwin->client_flags.no_close_button = 1;
285 wwin->client_flags.no_miniaturize_button = 1;
286 wwin->client_flags.no_resizebar = 1;
287 } else {
288 wwin->client_flags.no_close_button =
289 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
291 wwin->client_flags.no_closable =
292 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
294 wwin->client_flags.no_miniaturize_button =
295 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
297 wwin->client_flags.no_miniaturizable =
298 wwin->client_flags.no_miniaturize_button;
300 wwin->client_flags.no_resizebar =
301 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
303 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
305 /* these attributes supposedly imply in the existence
306 * of a titlebar */
307 if (gs_hints->window_style & (WMResizableWindowMask|
308 WMClosableWindowMask|
309 WMMiniaturizableWindowMask)) {
310 wwin->client_flags.no_titlebar = 0;
311 } else {
312 wwin->client_flags.no_titlebar =
313 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
317 } else {
318 /* setup the defaults */
319 wwin->client_flags.no_border = 0;
320 wwin->client_flags.no_titlebar = 0;
321 wwin->client_flags.no_closable = 0;
322 wwin->client_flags.no_miniaturizable = 0;
323 wwin->client_flags.no_resizable = 0;
324 wwin->client_flags.no_close_button = 0;
325 wwin->client_flags.no_miniaturize_button = 0;
326 wwin->client_flags.no_resizebar = 0;
328 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
329 wwin->client_flags.no_appicon = 1;
334 void
335 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
336 WWindowAttributes *mask)
338 if (wflags->no_appicon && mask->no_appicon)
339 wflags->emulate_appicon = 0;
341 if (wwin->main_window!=None) {
342 WApplication *wapp = wApplicationOf(wwin->main_window);
343 if (wapp && !wapp->flags.emulated)
344 wflags->emulate_appicon = 0;
347 if (wwin->transient_for!=None
348 && wwin->transient_for!=wwin->screen_ptr->root_win)
349 wflags->emulate_appicon = 0;
351 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
352 wflags->sunken = 0;
357 void
358 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
360 WScreen *scr = wwin->screen_ptr;
362 /* sets global default stuff */
363 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
364 &wwin->client_flags, NULL, True);
366 * Decoration setting is done in this precedence (lower to higher)
367 * - use global default in the resource database
368 * - guess some settings
369 * - use GNUstep/external window attributes
370 * - set hints specified for the app in the resource DB
373 WSETUFLAG(wwin, broken_close, 0);
375 if (wwin->protocols.DELETE_WINDOW)
376 WSETUFLAG(wwin, kill_close, 0);
377 else
378 WSETUFLAG(wwin, kill_close, 1);
380 /* transients can't be iconified or maximized */
381 if (wwin->transient_for) {
382 WSETUFLAG(wwin, no_miniaturizable, 1);
383 WSETUFLAG(wwin, no_miniaturize_button, 1);
386 /* if the window can't be resized, remove the resizebar */
387 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
388 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
389 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
390 WSETUFLAG(wwin, no_resizable, 1);
391 WSETUFLAG(wwin, no_resizebar, 1);
394 /* set GNUstep window attributes */
395 if (wwin->wm_gnustep_attr) {
396 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
398 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
400 *level = wwin->wm_gnustep_attr->window_level;
402 * INT_MIN is the only illegal window level.
404 if (*level == INT_MIN)
405 *level = INT_MIN + 1;
406 } else {
407 /* setup defaults */
408 *level = WMNormalLevel;
410 } else {
411 int tmp_workspace = -1;
412 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
413 Bool check;
415 check = False;
417 #ifdef MWM_HINTS
418 wMWMCheckClientHints(wwin);
419 #endif /* MWM_HINTS */
421 #ifdef GNOME_STUFF
422 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
423 #endif /* GNOME_STUFF */
425 #ifdef KWM_HINTS
426 if (!check)
427 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
428 #endif /* KWM_HINTS */
430 #ifdef OLWM_HINTS
431 wOLWMCheckClientHints(wwin);
432 #endif /* OLWM_HINTS */
434 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
435 * have INT_MIN that means that no window level was requested. -Dan
437 if (tmp_level == INT_MIN) {
438 if (WFLAGP(wwin, floating))
439 *level = WMFloatingLevel;
440 else if (WFLAGP(wwin, sunken))
441 *level = WMSunkenLevel;
442 else
443 *level = WMNormalLevel;
444 } else {
445 *level = tmp_level;
448 if (tmp_workspace >= 0) {
449 *workspace = tmp_workspace % scr->workspace_count;
454 * Set attributes specified only for that window/class.
455 * This might do duplicate work with the 1st wDefaultFillAttributes().
457 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
458 &wwin->user_flags, &wwin->defined_user_flags,
459 False);
461 * Sanity checks for attributes that depend on other attributes
463 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
464 wwin->user_flags.emulate_appicon = 0;
466 if (wwin->main_window!=None) {
467 WApplication *wapp = wApplicationOf(wwin->main_window);
468 if (wapp && !wapp->flags.emulated)
469 wwin->user_flags.emulate_appicon = 0;
472 if (wwin->transient_for!=None
473 && wwin->transient_for!=wwin->screen_ptr->root_win)
474 wwin->user_flags.emulate_appicon = 0;
476 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
477 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
478 wwin->user_flags.sunken = 0;
480 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
486 Bool
487 wWindowCanReceiveFocus(WWindow *wwin)
489 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
490 return False;
491 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
492 return False;
493 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
494 return False;
496 return True;
500 Bool
501 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
503 int w1, h1, w2, h2;
505 w1 = wwin->frame->core->width;
506 h1 = wwin->frame->core->height;
507 w2 = obscured->frame->core->width;
508 h2 = obscured->frame->core->height;
510 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
511 && wwin->frame->workspace != obscured->frame->workspace)
512 return False;
514 if (wwin->frame_x + w1 < obscured->frame_x
515 || wwin->frame_y + h1 < obscured->frame_y
516 || wwin->frame_x > obscured->frame_x + w2
517 || wwin->frame_y > obscured->frame_y + h2) {
518 return False;
521 return True;
527 *----------------------------------------------------------------
528 * wManageWindow--
529 * reparents the window and allocates a descriptor for it.
530 * Window manager hints and other hints are fetched to configure
531 * the window decoration attributes and others. User preferences
532 * for the window are used if available, to configure window
533 * decorations and some behaviour.
534 * If in startup, windows that are override redirect,
535 * unmapped and never were managed and are Withdrawn are not
536 * managed.
538 * Returns:
539 * the new window descriptor
541 * Side effects:
542 * The window is reparented and appropriate notification
543 * is done to the client. Input mask for the window is setup.
544 * The window descriptor is also associated with various window
545 * contexts and inserted in the head of the window list.
546 * Event handler contexts are associated for some objects
547 * (buttons, titlebar and resizebar)
549 *----------------------------------------------------------------
551 WWindow*
552 wManageWindow(WScreen *scr, Window window)
554 WWindow *wwin;
555 int x, y;
556 unsigned width, height;
557 XWindowAttributes wattribs;
558 XSetWindowAttributes attribs;
559 WWindowState *win_state;
560 WWindow *transientOwner = NULL;
561 int window_level;
562 int wm_state;
563 int foo;
564 int workspace = -1;
565 char *title;
566 Bool withdraw = False;
568 /* mutex. */
569 /* XGrabServer(dpy); */
570 XSync(dpy, False);
571 /* make sure the window is still there */
572 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
573 XUngrabServer(dpy);
574 return NULL;
577 /* if it's an override-redirect, ignore it */
578 if (wattribs.override_redirect) {
579 XUngrabServer(dpy);
580 return NULL;
583 wm_state = PropGetWindowState(window);
585 /* if it's startup and the window is unmapped, don't manage it */
586 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
587 XUngrabServer(dpy);
588 return NULL;
591 if (!wFetchName(dpy, window, &title)) {
592 title = NULL;
595 #ifdef KWM_HINTS
596 if (title && !wKWMManageableClient(scr, window, title)) {
597 XFree(title);
598 XUngrabServer(dpy);
599 return NULL;
601 #endif /* KWM_HINTS */
604 wwin = wWindowCreate();
606 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
608 #ifdef DEBUG
609 printf("managing window %x\n", (unsigned)window);
610 #endif
612 #ifdef SHAPE
613 if (wShapeSupported) {
614 int junk;
615 unsigned int ujunk;
616 int b_shaped;
618 XShapeSelectInput(dpy, window, ShapeNotifyMask);
619 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
620 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
621 wwin->flags.shaped = b_shaped;
623 #endif
626 *--------------------------------------------------
628 * Get hints and other information in properties
630 *--------------------------------------------------
632 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
634 /* setup descriptor */
635 wwin->client_win = window;
636 wwin->screen_ptr = scr;
638 wwin->old_border_width = wattribs.border_width;
640 wwin->event_mask = CLIENT_EVENTS;
641 attribs.event_mask = CLIENT_EVENTS;
642 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
643 attribs.save_under = False;
644 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
645 |CWSaveUnder, &attribs);
646 XSetWindowBorderWidth(dpy, window, 0);
648 /* get hints from GNUstep app */
649 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
650 wwin->flags.is_gnustep = 1;
652 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
653 wwin->wm_gnustep_attr = NULL;
656 wwin->client_leader = PropGetClientLeader(window);
657 if (wwin->client_leader!=None)
658 wwin->main_window = wwin->client_leader;
660 wwin->wm_hints = XGetWMHints(dpy, window);
662 if (wwin->wm_hints) {
663 if (wwin->wm_hints->flags & StateHint) {
665 if (wwin->wm_hints->initial_state == IconicState) {
667 wwin->flags.miniaturized = 1;
669 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
671 withdraw = True;
675 if (wwin->wm_hints->flags & WindowGroupHint) {
676 wwin->group_id = wwin->wm_hints->window_group;
677 /* window_group has priority over CLIENT_LEADER */
678 wwin->main_window = wwin->group_id;
679 } else {
680 wwin->group_id = None;
683 if (wwin->wm_hints->flags & UrgencyHint)
684 wwin->flags.urgent = 1;
685 } else {
686 wwin->group_id = None;
689 PropGetProtocols(window, &wwin->protocols);
691 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
692 wwin->transient_for = None;
693 } else {
694 if (wwin->transient_for==None || wwin->transient_for==window) {
695 wwin->transient_for = scr->root_win;
696 } else {
697 transientOwner = wWindowFor(wwin->transient_for);
698 if (transientOwner && transientOwner->main_window!=None) {
699 wwin->main_window = transientOwner->main_window;
700 } /*else {
701 wwin->main_window = None;
706 /* guess the focus mode */
707 wwin->focus_mode = getFocusMode(wwin);
709 /* get geometry stuff */
710 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
712 /* get colormap windows */
713 GetColormapWindows(wwin);
716 *--------------------------------------------------
718 * Setup the decoration/window attributes and
719 * geometry
721 *--------------------------------------------------
724 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
726 #ifdef OLWM_HINTS
727 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
728 && wwin->group_id != None && wwin->group_id != window) {
730 transientOwner = wWindowFor(wwin->group_id);
732 if (transientOwner) {
733 wwin->transient_for = wwin->group_id;
735 /* transients can't be iconified or maximized */
736 if (wwin->transient_for) {
737 WSETUFLAG(wwin, no_miniaturizable, 1);
738 WSETUFLAG(wwin, no_miniaturize_button, 1);
742 #endif /* OLWM_HINTS */
745 * Make broken apps behave as a nice app.
747 if (WFLAGP(wwin, emulate_appicon)) {
748 wwin->main_window = wwin->client_win;
752 *------------------------------------------------------------
754 * Setup the initial state of the window
756 *------------------------------------------------------------
759 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
760 wwin->flags.miniaturized = 1;
763 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
764 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
768 Bool bla;
770 bla = False;
771 #ifdef GNOME_STUFF
772 bla = wGNOMECheckInitialClientState(wwin);
773 #endif
774 #ifdef KWM_HINTS
775 if (!bla)
776 wKWMCheckClientInitialState(wwin);
777 #endif
780 /* apply previous state if it exists and we're in startup */
781 if (scr->flags.startup && wm_state >= 0) {
783 if (wm_state == IconicState) {
785 wwin->flags.miniaturized = 1;
787 } else if (wm_state == WithdrawnState) {
789 withdraw = True;
793 /* if there is a saved state (from file), restore it */
794 win_state = NULL;
795 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
796 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
797 } else {
798 win_state = (WWindowState*)wWindowGetSavedState(window);
800 if (win_state && !withdraw) {
802 if (win_state->state->hidden>0)
803 wwin->flags.hidden = win_state->state->hidden;
805 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
806 wwin->flags.shaded = win_state->state->shaded;
808 if (win_state->state->miniaturized>0 &&
809 !WFLAGP(wwin, no_miniaturizable)) {
810 wwin->flags.miniaturized = win_state->state->miniaturized;
813 if (!IS_OMNIPRESENT(wwin)) {
814 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
815 wwin->wm_class);
816 if (w < 0 || w >= scr->workspace_count) {
817 workspace = win_state->state->workspace;
818 if (workspace >= scr->workspace_count)
819 workspace = scr->current_workspace;
820 } else {
821 workspace = w;
823 } else {
824 workspace = scr->current_workspace;
828 /* if we're restarting, restore saved state (from hints).
829 * This will overwrite previous */
831 WSavedState *wstate;
833 if (getSavedState(window, &wstate)) {
834 wwin->flags.shaded = wstate->shaded;
835 wwin->flags.hidden = wstate->hidden;
836 wwin->flags.miniaturized = wstate->miniaturized;
837 wwin->flags.maximized = wstate->maximized;
838 if (wwin->flags.maximized) {
839 wwin->old_geometry.x = wstate->x;
840 wwin->old_geometry.y = wstate->y;
841 wwin->old_geometry.width = wstate->w;
842 wwin->old_geometry.height = wstate->h;
845 workspace = wstate->workspace;
846 } else {
847 wstate = NULL;
850 /* restore window shortcut */
851 if (wstate != NULL || win_state != NULL) {
852 unsigned mask = 0;
854 if (win_state != NULL)
855 mask = win_state->state->window_shortcuts;
857 if (wstate != NULL && mask == 0)
858 mask = wstate->window_shortcuts;
860 if (mask > 0) {
861 int i;
863 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
864 if (mask & (1<<i)) {
865 if (!scr->shortcutWindows[i])
866 scr->shortcutWindows[i] = WMCreateArray(4);
868 WMAddToArray(scr->shortcutWindows[i], wwin);
873 if (wstate != NULL) {
874 wfree(wstate);
878 /* don't let transients start miniaturized if their owners are not */
879 if (transientOwner && !transientOwner->flags.miniaturized
880 && wwin->flags.miniaturized && !withdraw) {
881 wwin->flags.miniaturized = 0;
882 if (wwin->wm_hints)
883 wwin->wm_hints->initial_state = NormalState;
886 /* set workspace on which the window starts */
887 if (workspace >= 0) {
888 if (workspace > scr->workspace_count-1) {
889 workspace = workspace % scr->workspace_count;
891 } else {
892 int w;
894 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
896 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
898 workspace = w;
900 } else {
901 if (wPreferences.open_transients_with_parent && transientOwner) {
903 workspace = transientOwner->frame->workspace;
905 } else {
907 workspace = scr->current_workspace;
912 /* setup window geometry */
913 if (win_state && win_state->state->w > 0) {
914 width = win_state->state->w;
915 height = win_state->state->h;
917 wWindowConstrainSize(wwin, &width, &height);
919 /* do not ask for window placement if the window is
920 * transient, during startup, if the initial workspace is another one
921 * or if the window wants to start iconic.
922 * If geometry was saved, restore it. */
924 Bool dontBring = False;
926 if (win_state && win_state->state->w > 0) {
927 x = win_state->state->x;
928 y = win_state->state->y;
929 } else if ((wwin->transient_for==None
930 || wPreferences.window_placement!=WPM_MANUAL)
931 && !scr->flags.startup
932 && workspace == scr->current_workspace
933 && !wwin->flags.miniaturized
934 && !wwin->flags.maximized
935 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
937 if (transientOwner && transientOwner->flags.mapped) {
938 int offs = WMAX(20, 2*transientOwner->frame->top_width);
940 x = transientOwner->frame_x +
941 abs((transientOwner->frame->core->width - width)/2) + offs;
942 y = transientOwner->frame_y +
943 abs((transientOwner->frame->core->height - height)/3) + offs;
945 if (x < 0)
946 x = 0;
947 else if (x + width > scr->scr_width)
948 x = scr->scr_width - width;
950 if (y < 0)
951 y = 0;
952 else if (y + height > scr->scr_height)
953 y = scr->scr_height - height;
954 } else {
955 PlaceWindow(wwin, &x, &y, width, height);
957 if (wPreferences.window_placement == WPM_MANUAL)
958 dontBring = True;
961 if (WFLAGP(wwin, dont_move_off) && dontBring)
962 wScreenBringInside(scr, &x, &y, width, height);
965 if (wwin->flags.urgent) {
966 if (!IS_OMNIPRESENT(wwin))
967 wwin->flags.omnipresent ^= 1;
971 *--------------------------------------------------
973 * Create frame, borders and do reparenting
975 *--------------------------------------------------
977 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
978 #ifdef XKB_BUTTON_HINT
979 if (wPreferences.modelock)
980 foo |= WFF_LANGUAGE_BUTTON;
981 #endif
982 if (!WFLAGP(wwin, no_titlebar))
983 foo |= WFF_TITLEBAR;
984 if (!WFLAGP(wwin, no_resizebar))
985 foo |= WFF_RESIZEBAR;
986 if (!WFLAGP(wwin, no_border))
987 foo |= WFF_BORDER;
989 wwin->frame = wFrameWindowCreate(scr, window_level,
990 x, y, width, height,
991 &wPreferences.window_title_clearance, foo,
992 scr->window_title_texture,
993 scr->resizebar_texture,
994 scr->window_title_pixel,
995 &scr->window_title_gc,
996 &scr->title_font);
998 wwin->frame->flags.is_client_window_frame = 1;
999 wwin->frame->flags.justification = wPreferences.title_justification;
1001 /* setup button images */
1002 wWindowUpdateButtonImages(wwin);
1004 /* hide unused buttons */
1005 foo = 0;
1006 if (WFLAGP(wwin, no_close_button))
1007 foo |= WFF_RIGHT_BUTTON;
1008 if (WFLAGP(wwin, no_miniaturize_button))
1009 foo |= WFF_LEFT_BUTTON;
1010 #ifdef XKB_BUTTON_HINT
1011 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1012 foo |= WFF_LANGUAGE_BUTTON;
1013 #endif
1014 if (foo!=0)
1015 wFrameWindowHideButton(wwin->frame, foo);
1017 wwin->frame->child = wwin;
1019 #ifdef OLWM_HINTS
1020 /* emulate olwm push pin. Make the button look as pushed-in for
1021 * the pinned-out state. When the button is clicked, it will
1022 * revert to the normal position, which means the pin is pinned-in.
1024 if (wwin->flags.olwm_push_pin_out)
1025 wFrameWindowUpdatePushButton(wwin->frame, True);
1026 #endif /* OLWM_HINTS */
1029 wwin->frame->workspace = workspace;
1031 wwin->frame->on_click_left = windowIconifyClick;
1032 #ifdef XKB_BUTTON_HINT
1033 if (wPreferences.modelock)
1034 wwin->frame->on_click_language = windowLanguageClick;
1035 #endif
1037 wwin->frame->on_click_right = windowCloseClick;
1038 wwin->frame->on_dblclick_right = windowCloseDblClick;
1040 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1041 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1043 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1046 XSelectInput(dpy, wwin->client_win,
1047 wwin->event_mask & ~StructureNotifyMask);
1049 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1050 0, wwin->frame->top_width);
1052 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1056 int gx, gy;
1058 wClientGetGravityOffsets(wwin, &gx, &gy);
1060 /* if gravity is to the south, account for the border sizes */
1061 if (gy > 0)
1062 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1066 * wWindowConfigure() will init the client window's size
1067 * (wwin->client.{width,height}) and all other geometry
1068 * related variables (frame_x,frame_y)
1070 wWindowConfigure(wwin, x, y, width, height);
1072 /* to make sure the window receives it's new position after reparenting */
1073 wWindowSynthConfigureNotify(wwin);
1076 *--------------------------------------------------
1078 * Setup descriptors and save window to internal
1079 * lists
1081 *--------------------------------------------------
1084 if (wwin->main_window!=None) {
1085 WApplication *app;
1086 WWindow *leader;
1088 /* Leader windows do not necessary set themselves as leaders.
1089 * If this is the case, point the leader of this window to
1090 * itself */
1091 leader = wWindowFor(wwin->main_window);
1092 if (leader && leader->main_window==None) {
1093 leader->main_window = leader->client_win;
1095 app = wApplicationCreate(scr, wwin->main_window);
1096 if (app) {
1097 app->last_workspace = workspace;
1100 * Do application specific stuff, like setting application
1101 * wide attributes.
1104 if (wwin->flags.hidden) {
1105 /* if the window was set to hidden because it was hidden
1106 * in a previous incarnation and that state was restored */
1107 app->flags.hidden = 1;
1110 if (app->flags.hidden) {
1111 wwin->flags.hidden = 1;
1116 /* setup the frame descriptor */
1117 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1118 wwin->frame->core->descriptor.parent = wwin;
1119 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1121 /* don't let windows go away if we die */
1122 XAddToSaveSet(dpy, window);
1124 XLowerWindow(dpy, window);
1126 /* if window is in this workspace and should be mapped, then map it */
1127 if (!wwin->flags.miniaturized
1128 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1129 && !wwin->flags.hidden && !withdraw) {
1131 /* The following "if" is to avoid crashing of clients that expect
1132 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1133 * after the return from this function.
1135 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1136 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1137 } else {
1138 wClientSetState(wwin, NormalState, None);
1141 #if 0
1142 /* if not auto focus, then map the window under the currently
1143 * focused window */
1144 #define _WIDTH(w) (w)->frame->core->width
1145 #define _HEIGHT(w) (w)->frame->core->height
1146 if (!wPreferences.auto_focus && scr->focused_window
1147 && !scr->flags.startup && !transientOwner
1148 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1149 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1150 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1151 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1152 || wwin->flags.maximized)) {
1153 MoveInStackListUnder(scr->focused_window->frame->core,
1154 wwin->frame->core);
1156 #undef _WIDTH
1157 #undef _HEIGHT
1159 #endif
1161 if (wPreferences.superfluous && !wPreferences.no_animations
1162 && !scr->flags.startup && wwin->transient_for==None
1164 * The brain damaged idiotic non-click to focus modes will
1165 * have trouble with this because:
1167 * 1. window is created and mapped by the client
1168 * 2. window is mapped by wmaker in small size
1169 * 3. window is animated to grow to normal size
1170 * 4. this function returns to normal event loop
1171 * 5. eventually, the EnterNotify event that would trigger
1172 * the window focusing (if the mouse is over that window)
1173 * will be processed by wmaker.
1174 * But since this event will be rather delayed
1175 * (step 3 has a large delay) the time when the event ocurred
1176 * and when it is processed, the client that owns that window
1177 * will reject the XSetInputFocus() for it.
1179 && (wPreferences.focus_mode==WKF_CLICK
1180 || wPreferences.auto_focus)) {
1181 DoWindowBirth(wwin);
1184 wWindowMap(wwin);
1187 /* setup stacking descriptor */
1188 if (transientOwner) {
1189 /* && wPreferences.on_top_transients */
1190 if (transientOwner) {
1191 wwin->frame->core->stacking->child_of =
1192 transientOwner->frame->core;
1194 } else {
1195 wwin->frame->core->stacking->child_of = NULL;
1199 if (!scr->focused_window) {
1200 /* first window on the list */
1201 wwin->next = NULL;
1202 wwin->prev = NULL;
1203 scr->focused_window = wwin;
1204 } else {
1205 WWindow *tmp;
1207 /* add window at beginning of focus window list */
1208 tmp = scr->focused_window;
1209 while (tmp->prev)
1210 tmp = tmp->prev;
1211 tmp->prev = wwin;
1212 wwin->next = tmp;
1213 wwin->prev = NULL;
1216 /* Update name must come after WApplication stuff is done */
1217 wWindowUpdateName(wwin, title);
1218 if (title)
1219 XFree(title);
1221 XUngrabServer(dpy);
1224 *--------------------------------------------------
1226 * Final preparations before window is ready to go
1228 *--------------------------------------------------
1231 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1234 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1235 && !wwin->flags.hidden) {
1236 if (((transientOwner && transientOwner->flags.focused)
1237 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1238 wSetFocusTo(scr, wwin);
1240 wWindowResetMouseGrabs(wwin);
1242 if (!WFLAGP(wwin, no_bind_keys)) {
1243 wWindowSetKeyGrabs(wwin);
1247 WMPostNotificationName(WMNManaged, wwin, NULL);
1250 wColormapInstallForWindow(scr, scr->cmap_window);
1253 #ifdef OLWM_HINTS
1254 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1255 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1257 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1258 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1259 wwin->frame_y);
1261 #endif
1264 *------------------------------------------------------------
1265 * Setup Notification Observers
1266 *------------------------------------------------------------
1268 WMAddNotificationObserver(appearanceObserver, wwin,
1269 WNWindowAppearanceSettingsChanged, wwin);
1273 *--------------------------------------------------
1275 * Cleanup temporary stuff
1277 *--------------------------------------------------
1280 if (win_state)
1281 wWindowDeleteSavedState(win_state);
1283 /* If the window must be withdrawed, then do it now.
1284 * Must do some optimization, 'though */
1285 if (withdraw) {
1286 wwin->flags.mapped = 0;
1287 wClientSetState(wwin, WithdrawnState, None);
1288 wUnmanageWindow(wwin, True, False);
1289 wwin = NULL;
1292 return wwin;
1299 WWindow*
1300 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1301 char *title, int x, int y, int width, int height)
1303 WWindow *wwin;
1304 int foo;
1306 wwin = wWindowCreate();
1308 WMAddNotificationObserver(appearanceObserver, wwin,
1309 WNWindowAppearanceSettingsChanged, wwin);
1311 wwin->flags.internal_window = 1;
1313 WSETUFLAG(wwin, omnipresent, 1);
1314 WSETUFLAG(wwin, no_shadeable, 1);
1315 WSETUFLAG(wwin, no_resizable, 1);
1316 WSETUFLAG(wwin, no_miniaturizable, 1);
1318 wwin->focus_mode = WFM_PASSIVE;
1320 wwin->client_win = window;
1321 wwin->screen_ptr = scr;
1323 wwin->transient_for = owner;
1325 wwin->client.x = x;
1326 wwin->client.y = y;
1327 wwin->client.width = width;
1328 wwin->client.height = height;
1330 wwin->frame_x = wwin->client.x;
1331 wwin->frame_y = wwin->client.y;
1334 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1335 foo |= WFF_TITLEBAR;
1336 #ifdef XKB_BUTTON_HINT
1337 foo |= WFF_LANGUAGE_BUTTON;
1338 #endif
1340 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1341 wwin->frame_x, wwin->frame_y,
1342 width, height,
1343 &wPreferences.window_title_clearance, foo,
1344 scr->window_title_texture,
1345 scr->resizebar_texture,
1346 scr->window_title_pixel,
1347 &scr->window_title_gc,
1348 &scr->title_font);
1350 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1352 wwin->frame->flags.is_client_window_frame = 1;
1353 wwin->frame->flags.justification = wPreferences.title_justification;
1355 wFrameWindowChangeTitle(wwin->frame, title);
1357 /* setup button images */
1358 wWindowUpdateButtonImages(wwin);
1360 /* hide buttons */
1361 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1363 wwin->frame->child = wwin;
1365 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1367 #ifdef XKB_BUTTON_HINT
1368 if (wPreferences.modelock)
1369 wwin->frame->on_click_language = windowLanguageClick;
1370 #endif
1372 wwin->frame->on_click_right = windowCloseClick;
1374 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1375 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1377 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1379 wwin->client.y += wwin->frame->top_width;
1380 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1381 0, wwin->frame->top_width);
1383 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1384 wwin->client.width, wwin->client.height);
1386 /* setup the frame descriptor */
1387 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1388 wwin->frame->core->descriptor.parent = wwin;
1389 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1392 XLowerWindow(dpy, window);
1393 XMapSubwindows(dpy, wwin->frame->core->window);
1395 /* setup stacking descriptor */
1396 if (
1397 #ifdef removed
1398 wPreferences.on_top_transients &&
1399 #endif
1400 wwin->transient_for!=None
1401 && wwin->transient_for!=scr->root_win) {
1402 WWindow *tmp;
1403 tmp = wWindowFor(wwin->transient_for);
1404 if (tmp)
1405 wwin->frame->core->stacking->child_of = tmp->frame->core;
1406 } else {
1407 wwin->frame->core->stacking->child_of = NULL;
1411 if (!scr->focused_window) {
1412 /* first window on the list */
1413 wwin->next = NULL;
1414 wwin->prev = NULL;
1415 scr->focused_window = wwin;
1416 } else {
1417 WWindow *tmp;
1419 /* add window at beginning of focus window list */
1420 tmp = scr->focused_window;
1421 while (tmp->prev)
1422 tmp = tmp->prev;
1423 tmp->prev = wwin;
1424 wwin->next = tmp;
1425 wwin->prev = NULL;
1428 if (wwin->flags.is_gnustep == 0)
1429 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1431 /* if (wPreferences.auto_focus)*/
1432 wSetFocusTo(scr, wwin);
1434 wWindowResetMouseGrabs(wwin);
1436 wWindowSetKeyGrabs(wwin);
1438 return wwin;
1443 *----------------------------------------------------------------------
1444 * wUnmanageWindow--
1445 * Removes the frame window from a window and destroys all data
1446 * related to it. The window will be reparented back to the root window
1447 * if restore is True.
1449 * Side effects:
1450 * Everything related to the window is destroyed and the window
1451 * is removed from the window lists. Focus is set to the previous on the
1452 * window list.
1453 *----------------------------------------------------------------------
1455 void
1456 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1458 WCoreWindow *frame = wwin->frame->core;
1459 WWindow *owner = NULL;
1460 WWindow *newFocusedWindow = NULL;
1461 int wasFocused;
1462 WScreen *scr = wwin->screen_ptr;
1465 /* First close attribute editor window if open */
1466 if (wwin->flags.inspector_open) {
1467 wCloseInspectorForWindow(wwin);
1470 /* Close window menu if it's open for this window */
1471 if (wwin->flags.menu_open_for_me) {
1472 CloseWindowMenu(scr);
1475 if (!destroyed) {
1476 if (!wwin->flags.internal_window)
1477 XRemoveFromSaveSet(dpy, wwin->client_win);
1479 XSelectInput(dpy, wwin->client_win, NoEventMask);
1481 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1482 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1485 XUnmapWindow(dpy, frame->window);
1487 XUnmapWindow(dpy, wwin->client_win);
1489 /* deselect window */
1490 wSelectWindow(wwin, False);
1492 /* remove all pending events on window */
1493 /* I think this only matters for autoraise */
1494 if (wPreferences.raise_delay)
1495 WMDeleteTimerWithClientData(wwin->frame->core);
1497 XFlush(dpy);
1499 /* reparent the window back to the root */
1500 if (restore)
1501 wClientRestore(wwin);
1503 if (wwin->transient_for!=scr->root_win) {
1504 owner = wWindowFor(wwin->transient_for);
1505 if (owner) {
1506 if (!owner->flags.semi_focused) {
1507 owner = NULL;
1508 } else {
1509 owner->flags.semi_focused = 0;
1514 wasFocused = wwin->flags.focused;
1516 /* remove from window focus list */
1517 if (!wwin->prev && !wwin->next) {
1518 /* was the only window */
1519 scr->focused_window = NULL;
1520 newFocusedWindow = NULL;
1521 } else {
1522 WWindow *tmp;
1524 if (wwin->prev)
1525 wwin->prev->next = wwin->next;
1526 if (wwin->next)
1527 wwin->next->prev = wwin->prev;
1528 else {
1529 scr->focused_window = wwin->prev;
1530 scr->focused_window->next = NULL;
1533 if (wPreferences.focus_mode==WKF_CLICK) {
1535 /* if in click to focus mode and the window
1536 * was a transient, focus the owner window
1538 tmp = NULL;
1539 if (wPreferences.focus_mode==WKF_CLICK) {
1540 tmp = wWindowFor(wwin->transient_for);
1541 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1542 tmp = NULL;
1545 /* otherwise, focus the next one in the focus list */
1546 if (!tmp) {
1547 tmp = scr->focused_window;
1548 while (tmp) { /* look for one in the window list first */
1549 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1550 && (tmp->flags.mapped || tmp->flags.shaded))
1551 break;
1552 tmp = tmp->prev;
1554 if (!tmp) { /* if unsuccessful, choose any focusable window */
1555 tmp = scr->focused_window;
1556 while (tmp) {
1557 if (!WFLAGP(tmp, no_focusable)
1558 && (tmp->flags.mapped || tmp->flags.shaded))
1559 break;
1560 tmp = tmp->prev;
1565 newFocusedWindow = tmp;
1567 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1568 unsigned int mask;
1569 int foo;
1570 Window bar, win;
1572 /* This is to let the root window get the keyboard input
1573 * if Sloppy focus mode and no other window get focus.
1574 * This way keybindings will not freeze.
1576 tmp = NULL;
1577 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1578 &foo, &foo, &foo, &foo, &mask))
1579 tmp = wWindowFor(win);
1580 if (tmp == wwin)
1581 tmp = NULL;
1582 newFocusedWindow = tmp;
1583 } else {
1584 newFocusedWindow = NULL;
1588 if (!wwin->flags.internal_window) {
1589 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1592 #ifdef DEBUG
1593 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1594 (unsigned)frame->window);
1595 #endif
1597 if (wasFocused) {
1598 if (newFocusedWindow != owner && owner) {
1599 if (wwin->flags.is_gnustep == 0)
1600 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1602 wSetFocusTo(scr, newFocusedWindow);
1604 wWindowDestroy(wwin);
1605 XFlush(dpy);
1609 void
1610 wWindowMap(WWindow *wwin)
1612 XMapWindow(dpy, wwin->frame->core->window);
1613 if (!wwin->flags.shaded) {
1614 /* window will be remapped when getting MapNotify */
1615 XSelectInput(dpy, wwin->client_win,
1616 wwin->event_mask & ~StructureNotifyMask);
1617 XMapWindow(dpy, wwin->client_win);
1618 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1620 wwin->flags.mapped = 1;
1625 void
1626 wWindowUnmap(WWindow *wwin)
1628 wwin->flags.mapped = 0;
1630 /* prevent window withdrawal when getting UnmapNotify */
1631 XSelectInput(dpy, wwin->client_win,
1632 wwin->event_mask & ~StructureNotifyMask);
1633 XUnmapWindow(dpy, wwin->client_win);
1634 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1636 XUnmapWindow(dpy, wwin->frame->core->window);
1641 void
1642 wWindowFocus(WWindow *wwin, WWindow *owin)
1644 WWindow *nowner;
1645 WWindow *oowner;
1647 #ifdef KEEP_XKB_LOCK_STATUS
1648 if (wPreferences.modelock) {
1649 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1651 #endif /* KEEP_XKB_LOCK_STATUS */
1653 wwin->flags.semi_focused = 0;
1655 if (wwin->flags.is_gnustep == 0)
1656 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1658 wwin->flags.focused = 1;
1660 wWindowResetMouseGrabs(wwin);
1662 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1664 if (owin == wwin || !owin)
1665 return;
1667 nowner = wWindowFor(wwin->transient_for);
1669 /* new window is a transient for the old window */
1670 if (nowner == owin) {
1671 owin->flags.semi_focused = 1;
1672 wWindowUnfocus(nowner);
1673 return;
1676 oowner = wWindowFor(owin->transient_for);
1678 /* new window is owner of old window */
1679 if (wwin == oowner) {
1680 wWindowUnfocus(owin);
1681 return;
1684 if (!nowner) {
1685 wWindowUnfocus(owin);
1686 return;
1689 /* new window has same owner of old window */
1690 if (oowner == nowner) {
1691 /* prevent unfocusing of owner */
1692 oowner->flags.semi_focused = 0;
1693 wWindowUnfocus(owin);
1694 oowner->flags.semi_focused = 1;
1696 return;
1699 /* nowner != NULL && oowner != nowner */
1700 nowner->flags.semi_focused = 1;
1701 wWindowUnfocus(nowner);
1702 wWindowUnfocus(owin);
1706 void
1707 wWindowUnfocus(WWindow *wwin)
1709 CloseWindowMenu(wwin->screen_ptr);
1711 if (wwin->flags.is_gnustep == 0)
1712 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1713 ? WS_PFOCUSED : WS_UNFOCUSED);
1715 if (wwin->transient_for!=None
1716 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1717 WWindow *owner;
1718 owner = wWindowFor(wwin->transient_for);
1719 if (owner && owner->flags.semi_focused) {
1720 owner->flags.semi_focused = 0;
1721 if (owner->flags.mapped || owner->flags.shaded) {
1722 wWindowUnfocus(owner);
1723 wFrameWindowPaint(owner->frame);
1727 wwin->flags.focused = 0;
1729 wWindowResetMouseGrabs(wwin);
1731 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1735 void
1736 wWindowUpdateName(WWindow *wwin, char *newTitle)
1738 WApplication *app = wApplicationOf(wwin->main_window);
1739 int instIndex = 0;
1740 char prefix[32] = "";
1741 char *title;
1743 if (!wwin->frame)
1744 return;
1746 if (app)
1747 instIndex = wApplicationIndexOfGroup(app);
1750 wwin->flags.wm_name_changed = 1;
1752 if (!newTitle) {
1753 /* the hint was removed */
1754 title = DEF_WINDOW_TITLE;
1756 WMPostNotificationName(WMNChangedName, wwin, NULL);
1757 } else {
1758 title = newTitle;
1761 #ifndef NO_WINDOW_ENUMERATOR
1762 if (instIndex > 0) {
1763 snprintf(prefix, sizeof(prefix), " [%i]", instIndex);
1765 title = wstrconcat(title, prefix);
1767 #endif
1769 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1771 WMPostNotificationName(WMNChangedName, wwin, NULL);
1774 #ifndef NO_WINDOW_ENUMERATOR
1775 if (instIndex > 0)
1776 wfree(title);
1777 #endif
1784 *----------------------------------------------------------------------
1786 * wWindowConstrainSize--
1787 * Constrains size for the client window, taking the maximal size,
1788 * window resize increments and other size hints into account.
1790 * Returns:
1791 * The closest size to what was given that the client window can
1792 * have.
1794 *----------------------------------------------------------------------
1796 void
1797 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1799 int width = *nwidth;
1800 int height = *nheight;
1801 int winc = 1;
1802 int hinc = 1;
1803 int minW = 1, minH = 1;
1804 int maxW = wwin->screen_ptr->scr_width*2;
1805 int maxH = wwin->screen_ptr->scr_height*2;
1806 int minAX = -1, minAY = -1;
1807 int maxAX = -1, maxAY = -1;
1808 int baseW = 0;
1809 int baseH = 0;
1811 if (wwin->normal_hints) {
1812 winc = wwin->normal_hints->width_inc;
1813 hinc = wwin->normal_hints->height_inc;
1814 minW = wwin->normal_hints->min_width;
1815 minH = wwin->normal_hints->min_height;
1816 maxW = wwin->normal_hints->max_width;
1817 maxH = wwin->normal_hints->max_height;
1818 if (wwin->normal_hints->flags & PAspect) {
1819 minAX = wwin->normal_hints->min_aspect.x;
1820 minAY = wwin->normal_hints->min_aspect.y;
1821 maxAX = wwin->normal_hints->max_aspect.x;
1822 maxAY = wwin->normal_hints->max_aspect.y;
1825 baseW = wwin->normal_hints->base_width;
1826 baseH = wwin->normal_hints->base_height;
1829 if (width < minW)
1830 width = minW;
1831 if (height < minH)
1832 height = minH;
1834 if (width > maxW)
1835 width = maxW;
1836 if (height > maxH)
1837 height = maxH;
1839 /* aspect ratio code borrowed from olwm */
1840 if (minAX > 0) {
1841 /* adjust max aspect ratio */
1842 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1843 if (maxAX > maxAY) {
1844 height = (width * maxAY) / maxAX;
1845 if (height > maxH) {
1846 height = maxH;
1847 width = (height * maxAX) / maxAY;
1849 } else {
1850 width = (height * maxAX) / maxAY;
1851 if (width > maxW) {
1852 width = maxW;
1853 height = (width * maxAY) / maxAX;
1858 /* adjust min aspect ratio */
1859 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1860 if (minAX > minAY) {
1861 height = (width * minAY) / minAX;
1862 if (height < minH) {
1863 height = minH;
1864 width = (height * minAX) / minAY;
1866 } else {
1867 width = (height * minAX) / minAY;
1868 if (width < minW) {
1869 width = minW;
1870 height = (width * minAY) / minAX;
1876 if (baseW != 0) {
1877 width = (((width - baseW) / winc) * winc) + baseW;
1878 } else {
1879 width = (((width - minW) / winc) * winc) + minW;
1882 if (baseH != 0) {
1883 height = (((height - baseH) / hinc) * hinc) + baseH;
1884 } else {
1885 height = (((height - minH) / hinc) * hinc) + minH;
1888 /* broken stupid apps may cause preposterous values for these.. */
1889 if (width > 0)
1890 *nwidth = width;
1891 if (height > 0)
1892 *nheight = height;
1896 void
1897 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1898 int *width, int *height)
1900 int baseW = 0, baseH = 0;
1901 int winc = 1, hinc = 1;
1903 if (wwin->normal_hints) {
1904 baseW = wwin->normal_hints->base_width;
1905 baseH = wwin->normal_hints->base_height;
1907 winc = wwin->normal_hints->width_inc;
1908 hinc = wwin->normal_hints->height_inc;
1911 if (*width > maxW)
1912 *width = maxW - (maxW - baseW) % winc;
1914 if (*height > maxH)
1915 *height = maxH - (maxH - baseH) % hinc;
1919 void
1920 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1922 WScreen *scr = wwin->screen_ptr;
1923 WApplication *wapp;
1924 int unmap = 0;
1926 if (workspace >= scr->workspace_count || workspace < 0
1927 || workspace == wwin->frame->workspace)
1928 return;
1930 if (workspace != scr->current_workspace) {
1931 /* Sent to other workspace. Unmap window */
1932 if ((wwin->flags.mapped
1933 || wwin->flags.shaded
1934 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1935 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1937 wapp = wApplicationOf(wwin->main_window);
1938 if (wapp) {
1939 wapp->last_workspace = workspace;
1941 if (wwin->flags.miniaturized) {
1942 if (wwin->icon) {
1943 XUnmapWindow(dpy, wwin->icon->core->window);
1944 wwin->icon->mapped = 0;
1946 } else {
1947 unmap = 1;
1948 wSetFocusTo(scr, NULL);
1951 } else {
1952 /* brought to current workspace. Map window */
1953 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1954 if (wwin->icon) {
1955 XMapWindow(dpy, wwin->icon->core->window);
1956 wwin->icon->mapped = 1;
1958 } else if (!wwin->flags.mapped &&
1959 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1960 wWindowMap(wwin);
1963 if (!IS_OMNIPRESENT(wwin)) {
1964 int oldWorkspace = wwin->frame->workspace;
1966 wwin->frame->workspace = workspace;
1968 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
1971 if (unmap) {
1972 wWindowUnmap(wwin);
1977 void
1978 wWindowSynthConfigureNotify(WWindow *wwin)
1980 XEvent sevent;
1982 sevent.type = ConfigureNotify;
1983 sevent.xconfigure.display = dpy;
1984 sevent.xconfigure.event = wwin->client_win;
1985 sevent.xconfigure.window = wwin->client_win;
1987 sevent.xconfigure.x = wwin->client.x;
1988 sevent.xconfigure.y = wwin->client.y;
1989 sevent.xconfigure.width = wwin->client.width;
1990 sevent.xconfigure.height = wwin->client.height;
1992 sevent.xconfigure.border_width = wwin->old_border_width;
1993 if (WFLAGP(wwin, no_titlebar))
1994 sevent.xconfigure.above = None;
1995 else
1996 sevent.xconfigure.above = wwin->frame->titlebar->window;
1998 sevent.xconfigure.override_redirect = False;
1999 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2000 #ifdef KWM_HINTS
2001 wKWMSendEventMessage(wwin, WKWMChangedClient);
2002 #endif
2003 XFlush(dpy);
2008 *----------------------------------------------------------------------
2009 * wWindowConfigure--
2010 * Configures the frame, decorations and client window to the
2011 * specified geometry. The geometry is not checked for validity,
2012 * wWindowConstrainSize() must be used for that.
2013 * The size parameters are for the client window, but the position is
2014 * for the frame.
2015 * The client window receives a ConfigureNotify event, according
2016 * to what ICCCM says.
2018 * Returns:
2019 * None
2021 * Side effects:
2022 * Window size and position are changed and client window receives
2023 * a ConfigureNotify event.
2024 *----------------------------------------------------------------------
2026 void
2027 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2028 WWindow *wwin;
2029 int req_x, req_y; /* new position of the frame */
2030 int req_width, req_height; /* new size of the client */
2032 int synth_notify = False;
2033 int resize;
2035 resize = (req_width!=wwin->client.width
2036 || req_height!=wwin->client.height);
2038 * if the window is being moved but not resized then
2039 * send a synthetic ConfigureNotify
2041 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2042 synth_notify = True;
2045 if (WFLAGP(wwin, dont_move_off))
2046 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2047 req_width, req_height);
2048 if (resize) {
2049 if (req_width < MIN_WINDOW_SIZE)
2050 req_width = MIN_WINDOW_SIZE;
2051 if (req_height < MIN_WINDOW_SIZE)
2052 req_height = MIN_WINDOW_SIZE;
2054 /* If growing, resize inner part before frame,
2055 * if shrinking, resize frame before.
2056 * This will prevent the frame (that can have a different color)
2057 * to be exposed, causing flicker */
2058 if (req_height > wwin->frame->core->height
2059 || req_width > wwin->frame->core->width)
2060 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2062 if (wwin->flags.shaded) {
2063 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2064 req_width, wwin->frame->core->height);
2065 wwin->old_geometry.height = req_height;
2066 } else {
2067 int h;
2069 h = req_height + wwin->frame->top_width
2070 + wwin->frame->bottom_width;
2072 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2075 if (!(req_height > wwin->frame->core->height
2076 || req_width > wwin->frame->core->width))
2077 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2079 wwin->client.x = req_x;
2080 wwin->client.y = req_y + wwin->frame->top_width;
2081 wwin->client.width = req_width;
2082 wwin->client.height = req_height;
2083 } else {
2084 wwin->client.x = req_x;
2085 wwin->client.y = req_y + wwin->frame->top_width;
2087 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2089 wwin->frame_x = req_x;
2090 wwin->frame_y = req_y;
2091 if (!WFLAGP(wwin, no_border)) {
2092 wwin->client.x += FRAME_BORDER_WIDTH;
2093 wwin->client.y += FRAME_BORDER_WIDTH;
2096 #ifdef SHAPE
2097 if (wShapeSupported && wwin->flags.shaped && resize) {
2098 wWindowSetShape(wwin);
2100 #endif
2102 if (synth_notify)
2103 wWindowSynthConfigureNotify(wwin);
2104 XFlush(dpy);
2108 void
2109 wWindowMove(wwin, req_x, req_y)
2110 WWindow *wwin;
2111 int req_x, req_y; /* new position of the frame */
2113 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2114 int synth_notify = False;
2116 /* Send a synthetic ConfigureNotify event for every window movement. */
2117 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2118 synth_notify = True;
2120 #else
2121 /* A single synthetic ConfigureNotify event is sent at the end of
2122 * a completed (opaque) movement in moveres.c */
2123 #endif
2125 if (WFLAGP(wwin, dont_move_off))
2126 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2127 wwin->frame->core->width, wwin->frame->core->height);
2129 wwin->client.x = req_x;
2130 wwin->client.y = req_y + wwin->frame->top_width;
2131 if (!WFLAGP(wwin, no_border)) {
2132 wwin->client.x += FRAME_BORDER_WIDTH;
2133 wwin->client.y += FRAME_BORDER_WIDTH;
2136 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2138 wwin->frame_x = req_x;
2139 wwin->frame_y = req_y;
2141 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2142 if (synth_notify)
2143 wWindowSynthConfigureNotify(wwin);
2144 #endif
2148 void
2149 wWindowUpdateButtonImages(WWindow *wwin)
2151 WScreen *scr = wwin->screen_ptr;
2152 Pixmap pixmap, mask;
2153 WFrameWindow *fwin = wwin->frame;
2155 if (WFLAGP(wwin, no_titlebar))
2156 return;
2158 /* miniaturize button */
2160 if (!WFLAGP(wwin, no_miniaturize_button)) {
2161 if (wwin->wm_gnustep_attr
2162 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2163 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2165 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2166 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2167 } else {
2168 mask = None;
2171 if (fwin->lbutton_image
2172 && (fwin->lbutton_image->image != pixmap
2173 || fwin->lbutton_image->mask != mask)) {
2174 wPixmapDestroy(fwin->lbutton_image);
2175 fwin->lbutton_image = NULL;
2178 if (!fwin->lbutton_image) {
2179 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2180 fwin->lbutton_image->client_owned = 1;
2181 fwin->lbutton_image->client_owned_mask = 1;
2183 } else {
2184 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2185 wPixmapDestroy(fwin->lbutton_image);
2187 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2191 #ifdef XKB_BUTTON_HINT
2192 if (!WFLAGP(wwin, no_language_button)) {
2193 if (fwin->languagebutton_image &&
2194 !fwin->languagebutton_image->shared) {
2195 wPixmapDestroy(fwin->languagebutton_image);
2197 fwin->languagebutton_image =
2198 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2200 #endif
2202 /* close button */
2204 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2205 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2207 if (!WFLAGP(wwin, no_close_button)) {
2208 if (wwin->wm_gnustep_attr
2209 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2210 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2212 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2213 mask = wwin->wm_gnustep_attr->close_mask;
2214 else
2215 mask = None;
2217 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2218 || fwin->rbutton_image->mask != mask)) {
2219 wPixmapDestroy(fwin->rbutton_image);
2220 fwin->rbutton_image = NULL;
2223 if (!fwin->rbutton_image) {
2224 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2225 fwin->rbutton_image->client_owned = 1;
2226 fwin->rbutton_image->client_owned_mask = 1;
2229 } else if (WFLAGP(wwin, kill_close)) {
2231 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2232 wPixmapDestroy(fwin->rbutton_image);
2234 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2236 } else if (MGFLAGP(wwin, broken_close)) {
2238 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2239 wPixmapDestroy(fwin->rbutton_image);
2241 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2243 } else {
2245 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2246 wPixmapDestroy(fwin->rbutton_image);
2248 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2252 /* force buttons to be redrawn */
2253 fwin->flags.need_texture_change = 1;
2254 wFrameWindowPaint(fwin);
2259 *---------------------------------------------------------------------------
2260 * wWindowConfigureBorders--
2261 * Update window border configuration according to attribute flags.
2263 *---------------------------------------------------------------------------
2265 void
2266 wWindowConfigureBorders(WWindow *wwin)
2268 if (wwin->frame) {
2269 int flags;
2270 int newy, oldh;
2272 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2273 #ifdef XKB_BUTTON_HINT
2274 flags |= WFF_LANGUAGE_BUTTON;
2275 #endif
2276 if (!WFLAGP(wwin, no_titlebar))
2277 flags |= WFF_TITLEBAR;
2278 if (!WFLAGP(wwin, no_resizebar))
2279 flags |= WFF_RESIZEBAR;
2280 if (!WFLAGP(wwin, no_border))
2281 flags |= WFF_BORDER;
2282 if (wwin->flags.shaded)
2283 flags |= WFF_IS_SHADED;
2285 oldh = wwin->frame->top_width;
2286 wFrameWindowUpdateBorders(wwin->frame, flags);
2287 if (oldh != wwin->frame->top_width) {
2288 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2290 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2291 wWindowConfigure(wwin, wwin->frame_x, newy,
2292 wwin->client.width, wwin->client.height);
2295 flags = 0;
2296 if (!WFLAGP(wwin, no_miniaturize_button)
2297 && wwin->frame->flags.hide_left_button)
2298 flags |= WFF_LEFT_BUTTON;
2300 #ifdef XKB_BUTTON_HINT
2301 if (!WFLAGP(wwin, no_language_button)
2302 && wwin->frame->flags.hide_language_button)
2303 flags |= WFF_LANGUAGE_BUTTON;
2304 #endif
2306 if (!WFLAGP(wwin, no_close_button)
2307 && wwin->frame->flags.hide_right_button)
2308 flags |= WFF_RIGHT_BUTTON;
2310 if (flags!=0) {
2311 wWindowUpdateButtonImages(wwin);
2312 wFrameWindowShowButton(wwin->frame, flags);
2315 flags = 0;
2316 if (WFLAGP(wwin, no_miniaturize_button)
2317 && !wwin->frame->flags.hide_left_button)
2318 flags |= WFF_LEFT_BUTTON;
2320 #ifdef XKB_BUTTON_HINT
2321 if (WFLAGP(wwin, no_language_button)
2322 && !wwin->frame->flags.hide_language_button)
2323 flags |= WFF_LANGUAGE_BUTTON;
2324 #endif
2326 if (WFLAGP(wwin, no_close_button)
2327 && !wwin->frame->flags.hide_right_button)
2328 flags |= WFF_RIGHT_BUTTON;
2330 if (flags!=0)
2331 wFrameWindowHideButton(wwin->frame, flags);
2333 #ifdef SHAPE
2334 if (wShapeSupported && wwin->flags.shaped) {
2335 wWindowSetShape(wwin);
2337 #endif
2342 void
2343 wWindowSaveState(WWindow *wwin)
2345 CARD32 data[10];
2346 int i;
2348 memset(data, 0, sizeof(CARD32)*10);
2349 data[0] = wwin->frame->workspace;
2350 data[1] = wwin->flags.miniaturized;
2351 data[2] = wwin->flags.shaded;
2352 data[3] = wwin->flags.hidden;
2353 data[4] = wwin->flags.maximized;
2354 if (wwin->flags.maximized == 0) {
2355 data[5] = wwin->frame_x;
2356 data[6] = wwin->frame_y;
2357 data[7] = wwin->frame->core->width;
2358 data[8] = wwin->frame->core->height;
2359 } else {
2360 data[5] = wwin->old_geometry.x;
2361 data[6] = wwin->old_geometry.y;
2362 data[7] = wwin->old_geometry.width;
2363 data[8] = wwin->old_geometry.height;
2366 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2367 if (wwin->screen_ptr->shortcutWindows[i] &&
2368 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2369 data[9] |= 1<<i;
2371 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2372 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2373 (unsigned char *)data, 10);
2377 static int
2378 getSavedState(Window window, WSavedState **state)
2380 Atom type_ret;
2381 int fmt_ret;
2382 unsigned long nitems_ret;
2383 unsigned long bytes_after_ret;
2384 CARD32 *data;
2386 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2387 True, _XA_WINDOWMAKER_STATE,
2388 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2389 (unsigned char **)&data)!=Success || !data)
2390 return 0;
2392 *state = wmalloc(sizeof(WSavedState));
2394 (*state)->workspace = data[0];
2395 (*state)->miniaturized = data[1];
2396 (*state)->shaded = data[2];
2397 (*state)->hidden = data[3];
2398 (*state)->maximized = data[4];
2399 (*state)->x = data[5];
2400 (*state)->y = data[6];
2401 (*state)->w = data[7];
2402 (*state)->h = data[8];
2403 (*state)->window_shortcuts = data[9];
2405 XFree(data);
2407 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2408 return 1;
2409 else
2410 return 0;
2414 #ifdef SHAPE
2415 void
2416 wWindowClearShape(WWindow *wwin)
2418 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2419 0, wwin->frame->top_width, None, ShapeSet);
2420 XFlush(dpy);
2423 void
2424 wWindowSetShape(WWindow *wwin)
2426 XRectangle rect[2];
2427 int count;
2428 #ifdef OPTIMIZE_SHAPE
2429 XRectangle *rects;
2430 XRectangle *urec;
2431 int ordering;
2433 /* only shape is the client's */
2434 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2435 goto alt_code;
2438 /* Get array of rectangles describing the shape mask */
2439 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2440 &count, &ordering);
2441 if (!rects) {
2442 goto alt_code;
2445 urec = malloc(sizeof(XRectangle)*(count+2));
2446 if (!urec) {
2447 XFree(rects);
2448 goto alt_code;
2451 /* insert our decoration rectangles in the rect list */
2452 memcpy(urec, rects, sizeof(XRectangle)*count);
2453 XFree(rects);
2455 if (!WFLAGP(wwin, no_titlebar)) {
2456 urec[count].x = -1;
2457 urec[count].y = -1 - wwin->frame->top_width;
2458 urec[count].width = wwin->frame->core->width + 2;
2459 urec[count].height = wwin->frame->top_width + 1;
2460 count++;
2462 if (!WFLAGP(wwin, no_resizebar)) {
2463 urec[count].x = -1;
2464 urec[count].y = wwin->frame->core->height
2465 - wwin->frame->bottom_width - wwin->frame->top_width;
2466 urec[count].width = wwin->frame->core->width + 2;
2467 urec[count].height = wwin->frame->bottom_width + 1;
2468 count++;
2471 /* shape our frame window */
2472 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2473 0, wwin->frame->top_width, urec, count,
2474 ShapeSet, Unsorted);
2475 XFlush(dpy);
2476 wfree(urec);
2477 return;
2479 alt_code:
2480 #endif /* OPTIMIZE_SHAPE */
2481 count = 0;
2482 if (!WFLAGP(wwin, no_titlebar)) {
2483 rect[count].x = -1;
2484 rect[count].y = -1;
2485 rect[count].width = wwin->frame->core->width + 2;
2486 rect[count].height = wwin->frame->top_width + 1;
2487 count++;
2489 if (!WFLAGP(wwin, no_resizebar)) {
2490 rect[count].x = -1;
2491 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2492 rect[count].width = wwin->frame->core->width + 2;
2493 rect[count].height = wwin->frame->bottom_width + 1;
2494 count++;
2496 if (count > 0) {
2497 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2498 0, 0, rect, count, ShapeSet, Unsorted);
2500 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2501 0, wwin->frame->top_width, wwin->client_win,
2502 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2503 XFlush(dpy);
2505 #endif /* SHAPE */
2507 /* ====================================================================== */
2509 static FocusMode
2510 getFocusMode(WWindow *wwin)
2512 FocusMode mode;
2514 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2515 if (wwin->wm_hints->input == True) {
2516 if (wwin->protocols.TAKE_FOCUS)
2517 mode = WFM_LOCALLY_ACTIVE;
2518 else
2519 mode = WFM_PASSIVE;
2520 } else {
2521 if (wwin->protocols.TAKE_FOCUS)
2522 mode = WFM_GLOBALLY_ACTIVE;
2523 else
2524 mode = WFM_NO_INPUT;
2526 } else {
2527 mode = WFM_PASSIVE;
2529 return mode;
2533 void
2534 wWindowSetKeyGrabs(WWindow *wwin)
2536 int i;
2537 WShortKey *key;
2539 for (i=0; i<WKBD_LAST; i++) {
2540 key = &wKeyBindings[i];
2542 if (key->keycode==0)
2543 continue;
2544 if (key->modifier!=AnyModifier) {
2545 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2546 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2547 #ifdef NUMLOCK_HACK
2548 /* Also grab all modifier combinations possible that include,
2549 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2550 * work even if the NumLock/ScrollLock key is on.
2552 wHackedGrabKey(key->keycode, key->modifier,
2553 wwin->frame->core->window, True, GrabModeAsync,
2554 GrabModeAsync);
2555 #endif
2557 XGrabKey(dpy, key->keycode, key->modifier,
2558 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2561 #ifndef LITE
2562 wRootMenuBindShortcuts(wwin->frame->core->window);
2563 #endif
2568 void
2569 wWindowResetMouseGrabs(WWindow *wwin)
2571 /* Mouse grabs can't be done on the client window because of
2572 * ICCCM and because clients that try to do the same will crash.
2574 * But there is a problem wich makes tbar buttons of unfocused
2575 * windows not usable as the click goes to the frame window instead
2576 * of the button itself. Must figure a way to fix that.
2579 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2581 if (!WFLAGP(wwin, no_bind_mouse)) {
2582 /* grabs for Meta+drag */
2583 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2584 True, ButtonPressMask, GrabModeSync,
2585 GrabModeAsync, None, None);
2588 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2589 && !wwin->flags.is_gnustep) {
2590 /* the passive grabs to focus the window */
2591 /* if (wPreferences.focus_mode == WKF_CLICK) */
2592 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2593 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2594 None, None);
2596 XFlush(dpy);
2600 void
2601 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2603 if (attr->flags & GSExtraFlagsAttr) {
2604 if (MGFLAGP(wwin, broken_close) !=
2605 (attr->extra_flags & GSDocumentEditedFlag)) {
2606 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2607 wWindowUpdateButtonImages(wwin);
2613 WMagicNumber
2614 wWindowAddSavedState(char *instance, char *class, char *command,
2615 pid_t pid, WSavedState *state)
2617 WWindowState *wstate;
2619 wstate = malloc(sizeof(WWindowState));
2620 if (!wstate)
2621 return 0;
2623 memset(wstate, 0, sizeof(WWindowState));
2624 wstate->pid = pid;
2625 if (instance)
2626 wstate->instance = wstrdup(instance);
2627 if (class)
2628 wstate->class = wstrdup(class);
2629 if (command)
2630 wstate->command = wstrdup(command);
2631 wstate->state = state;
2633 wstate->next = windowState;
2634 windowState = wstate;
2636 #ifdef DEBUG
2637 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2638 class, command);
2639 #endif
2641 return wstate;
2645 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2648 WMagicNumber
2649 wWindowGetSavedState(Window win)
2651 char *instance, *class, *command=NULL;
2652 WWindowState *wstate = windowState;
2653 char **argv;
2654 int argc;
2656 if (!wstate)
2657 return NULL;
2659 if (XGetCommand(dpy, win, &argv, &argc)) {
2660 if (argc > 0)
2661 command = wtokenjoin(argv, argc);
2662 XFreeStringList(argv);
2664 if (!command)
2665 return NULL;
2667 if (PropGetWMClass(win, &class, &instance)) {
2668 while (wstate) {
2669 if (SAME(instance, wstate->instance) &&
2670 SAME(class, wstate->class) &&
2671 SAME(command, wstate->command)) {
2672 break;
2674 wstate = wstate->next;
2676 } else {
2677 wstate = NULL;
2680 #ifdef DEBUG
2681 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2682 class, command);
2683 #endif
2685 if (command) wfree(command);
2686 if (instance) XFree(instance);
2687 if (class) XFree(class);
2689 return wstate;
2693 void
2694 wWindowDeleteSavedState(WMagicNumber id)
2696 WWindowState *tmp, *wstate=(WWindowState*)id;
2698 if (!wstate || !windowState)
2699 return;
2701 tmp = windowState;
2702 if (tmp==wstate) {
2703 windowState = wstate->next;
2704 #ifdef DEBUG
2705 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2706 wstate, wstate->instance, wstate->class, wstate->command);
2707 #endif
2708 if (wstate->instance) wfree(wstate->instance);
2709 if (wstate->class) wfree(wstate->class);
2710 if (wstate->command) wfree(wstate->command);
2711 wfree(wstate->state);
2712 wfree(wstate);
2713 } else {
2714 while (tmp->next) {
2715 if (tmp->next==wstate) {
2716 tmp->next=wstate->next;
2717 #ifdef DEBUG
2718 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2719 wstate, wstate->instance, wstate->class, wstate->command);
2720 #endif
2721 if (wstate->instance) wfree(wstate->instance);
2722 if (wstate->class) wfree(wstate->class);
2723 if (wstate->command) wfree(wstate->command);
2724 wfree(wstate->state);
2725 wfree(wstate);
2726 break;
2728 tmp = tmp->next;
2734 void
2735 wWindowDeleteSavedStatesForPID(pid_t pid)
2737 WWindowState *tmp, *wstate;
2739 if (!windowState)
2740 return;
2742 tmp = windowState;
2743 if (tmp->pid == pid) {
2744 wstate = windowState;
2745 windowState = tmp->next;
2746 #ifdef DEBUG
2747 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2748 wstate, wstate->instance, wstate->class, wstate->command);
2749 #endif
2750 if (wstate->instance) wfree(wstate->instance);
2751 if (wstate->class) wfree(wstate->class);
2752 if (wstate->command) wfree(wstate->command);
2753 wfree(wstate->state);
2754 wfree(wstate);
2755 } else {
2756 while (tmp->next) {
2757 if (tmp->next->pid==pid) {
2758 wstate = tmp->next;
2759 tmp->next = wstate->next;
2760 #ifdef DEBUG
2761 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2762 wstate, wstate->instance, wstate->class, wstate->command);
2763 #endif
2764 if (wstate->instance) wfree(wstate->instance);
2765 if (wstate->class) wfree(wstate->class);
2766 if (wstate->command) wfree(wstate->command);
2767 wfree(wstate->state);
2768 wfree(wstate);
2769 break;
2771 tmp = tmp->next;
2777 void
2778 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2780 wwin->flags.omnipresent = flag;
2782 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2786 /* ====================================================================== */
2788 static void
2789 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2791 WWindow *wwin = data;
2793 #ifndef NUMLOCK_HACK
2794 if ((event->xbutton.state & ValidModMask)
2795 != (event->xbutton.state & ~LockMask)) {
2796 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2797 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2799 #endif
2801 event->xbutton.state &= ValidModMask;
2803 CloseWindowMenu(wwin->screen_ptr);
2805 if (wPreferences.focus_mode==WKF_CLICK
2806 && !(event->xbutton.state&ControlMask)
2807 && !WFLAGP(wwin, no_focusable)) {
2808 wSetFocusTo(wwin->screen_ptr, wwin);
2811 if (event->xbutton.button == Button1)
2812 wRaiseFrame(wwin->frame->core);
2814 if (event->xbutton.window != wwin->frame->resizebar->window) {
2815 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2816 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2817 GrabModeAsync, GrabModeAsync, None,
2818 None, CurrentTime)!=GrabSuccess) {
2819 #ifdef DEBUG0
2820 wwarning("pointer grab failed for window move");
2821 #endif
2822 return;
2826 if (event->xbutton.state & MOD_MASK) {
2827 /* move the window */
2828 wMouseMoveWindow(wwin, event);
2829 XUngrabPointer(dpy, CurrentTime);
2830 } else {
2831 wMouseResizeWindow(wwin, event);
2832 XUngrabPointer(dpy, CurrentTime);
2838 static void
2839 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2841 WWindow *wwin = data;
2843 event->xbutton.state &= ValidModMask;
2845 if (event->xbutton.button==Button1) {
2846 if (event->xbutton.state == 0) {
2847 if (!WFLAGP(wwin, no_shadeable)) {
2848 /* shade window */
2849 if (wwin->flags.shaded)
2850 wUnshadeWindow(wwin);
2851 else
2852 wShadeWindow(wwin);
2854 } else {
2855 int dir = 0;
2857 if (event->xbutton.state & ControlMask)
2858 dir |= MAX_VERTICAL;
2860 if (event->xbutton.state & ShiftMask) {
2861 dir |= MAX_HORIZONTAL;
2862 if (!(event->xbutton.state & ControlMask))
2863 wSelectWindow(wwin, !wwin->flags.selected);
2866 /* maximize window */
2867 if (dir !=0 && !WFLAGP(wwin, no_resizable)) {
2868 int ndir = dir ^ wwin->flags.maximized;
2869 if (wwin->flags.maximized != 0)
2870 wUnmaximizeWindow(wwin);
2871 if (ndir != 0)
2872 wMaximizeWindow(wwin, ndir);
2875 } else if (event->xbutton.button==Button3) {
2876 if (event->xbutton.state & MOD_MASK) {
2877 wHideOtherApplications(wwin);
2879 } else if (event->xbutton.button==Button2) {
2880 wSelectWindow(wwin, !wwin->flags.selected);
2885 static void
2886 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2888 WWindow *wwin = desc->parent;
2890 event->xbutton.state &= ValidModMask;
2892 CloseWindowMenu(wwin->screen_ptr);
2894 if (/*wPreferences.focus_mode==WKF_CLICK
2895 &&*/ !(event->xbutton.state&ControlMask)
2896 && !WFLAGP(wwin, no_focusable)) {
2897 wSetFocusTo(wwin->screen_ptr, wwin);
2899 if (event->xbutton.button == Button1) {
2900 wRaiseFrame(wwin->frame->core);
2903 if (event->xbutton.state & MOD_MASK) {
2904 /* move the window */
2905 if (XGrabPointer(dpy, wwin->client_win, False,
2906 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2907 GrabModeAsync, GrabModeAsync, None,
2908 None, CurrentTime)!=GrabSuccess) {
2909 #ifdef DEBUG0
2910 wwarning("pointer grab failed for window move");
2911 #endif
2912 return;
2914 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2915 wMouseResizeWindow(wwin, event);
2916 else
2917 wMouseMoveWindow(wwin, event);
2918 XUngrabPointer(dpy, CurrentTime);
2923 static void
2924 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2926 WWindow *wwin = (WWindow*)data;
2928 #ifndef NUMLOCK_HACK
2929 if ((event->xbutton.state & ValidModMask)
2930 != (event->xbutton.state & ~LockMask)) {
2931 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2932 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2934 #endif
2935 event->xbutton.state &= ValidModMask;
2937 CloseWindowMenu(wwin->screen_ptr);
2939 if (wPreferences.focus_mode==WKF_CLICK
2940 && !(event->xbutton.state&ControlMask)
2941 && !WFLAGP(wwin, no_focusable)) {
2942 wSetFocusTo(wwin->screen_ptr, wwin);
2945 if (event->xbutton.button == Button1
2946 || event->xbutton.button == Button2) {
2948 if (event->xbutton.button == Button1) {
2949 if (event->xbutton.state & MOD_MASK) {
2950 wLowerFrame(wwin->frame->core);
2951 } else {
2952 wRaiseFrame(wwin->frame->core);
2955 if ((event->xbutton.state & ShiftMask)
2956 && !(event->xbutton.state & ControlMask)) {
2957 wSelectWindow(wwin, !wwin->flags.selected);
2958 return;
2960 if (event->xbutton.window != wwin->frame->titlebar->window
2961 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2962 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2963 GrabModeAsync, GrabModeAsync, None,
2964 None, CurrentTime)!=GrabSuccess) {
2965 #ifdef DEBUG0
2966 wwarning("pointer grab failed for window move");
2967 #endif
2968 return;
2971 /* move the window */
2972 wMouseMoveWindow(wwin, event);
2974 XUngrabPointer(dpy, CurrentTime);
2975 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2976 && !wwin->flags.internal_window
2977 && !WCHECK_STATE(WSTATE_MODAL)) {
2978 WObjDescriptor *desc;
2980 if (event->xbutton.window != wwin->frame->titlebar->window
2981 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2982 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2983 GrabModeAsync, GrabModeAsync, None,
2984 None, CurrentTime)!=GrabSuccess) {
2985 #ifdef DEBUG0
2986 wwarning("pointer grab failed for window move");
2987 #endif
2988 return;
2991 OpenWindowMenu(wwin, event->xbutton.x_root,
2992 wwin->frame_y+wwin->frame->top_width, False);
2994 /* allow drag select */
2995 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2996 event->xany.send_event = True;
2997 (*desc->handle_mousedown)(desc, event);
2999 XUngrabPointer(dpy, CurrentTime);
3005 static void
3006 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3008 WWindow *wwin = data;
3010 event->xbutton.state &= ValidModMask;
3012 CloseWindowMenu(wwin->screen_ptr);
3014 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3015 return;
3017 /* if control-click, kill the client */
3018 if (event->xbutton.state & ControlMask) {
3019 wClientKill(wwin);
3020 } else {
3021 #ifdef OLWM_HINTS
3022 if (wwin->flags.olwm_push_pin_out) {
3024 wwin->flags.olwm_push_pin_out = 0;
3026 wOLWMChangePushpinState(wwin, True);
3028 wFrameWindowUpdatePushButton(wwin->frame, False);
3030 return;
3032 #endif
3033 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3034 /* send delete message */
3035 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3041 static void
3042 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3044 WWindow *wwin = data;
3046 CloseWindowMenu(wwin->screen_ptr);
3048 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3049 return;
3051 /* send delete message */
3052 if (wwin->protocols.DELETE_WINDOW) {
3053 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3054 } else {
3055 wClientKill(wwin);
3060 #ifdef XKB_BUTTON_HINT
3061 static void
3062 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3064 WWindow *wwin = data;
3065 WFrameWindow *fwin = wwin->frame;
3066 WScreen *scr = fwin->screen_ptr;
3067 XkbStateRec staterec;
3068 int tl;
3070 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3071 return;
3072 tl = wwin->frame->languagemode;
3073 wwin->frame->languagemode = wwin->frame->last_languagemode;
3074 wwin->frame->last_languagemode = tl;
3075 wSetFocusTo(scr, wwin);
3076 wwin->frame->languagebutton_image =
3077 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3078 wwin->frame->languagemode];
3079 wFrameWindowUpdateLanguageButton(wwin->frame);
3080 if (event->xbutton.button == Button3)
3081 return;
3082 wRaiseFrame(fwin->core);
3084 #endif
3087 static void
3088 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3090 WWindow *wwin = data;
3092 event->xbutton.state &= ValidModMask;
3094 CloseWindowMenu(wwin->screen_ptr);
3096 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3097 return;
3099 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3100 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3101 LastTimestamp);
3102 } else {
3103 WApplication *wapp;
3104 if ((event->xbutton.state & ControlMask) ||
3105 (event->xbutton.button == Button3)) {
3107 wapp = wApplicationOf(wwin->main_window);
3108 if (wapp && !WFLAGP(wwin, no_appicon))
3109 wHideApplication(wapp);
3110 } else if (event->xbutton.state==0) {
3111 wIconifyWindow(wwin);