misc fixes
[wmaker-crm.git] / src / window.c
blob7f4bd8fd70ef9c1d69cfbc350744668f8b829765
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>
37 /* For getting mouse wheel mappings from WINGs */
38 #include <WINGs/WINGsP.h>
40 #include "WindowMaker.h"
41 #include "GNUstep.h"
42 #include "wcore.h"
43 #include "framewin.h"
44 #include "texture.h"
45 #include "window.h"
46 #include "winspector.h"
47 #include "icon.h"
48 #include "properties.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "stacking.h"
54 #include "defaults.h"
55 #include "workspace.h"
58 #ifdef MWM_HINTS
59 # include "motif.h"
60 #endif
61 #ifdef KWM_HINTS
62 # include "kwm.h"
63 #endif
64 #ifdef GNOME_STUFF
65 # include "gnome.h"
66 #endif
67 #ifdef OLWM_HINTS
68 # include "openlook.h"
69 #endif
71 /****** Global Variables ******/
73 extern WShortKey wKeyBindings[WKBD_LAST];
75 #ifdef SHAPE
76 extern Bool wShapeSupported;
77 #endif
79 /* contexts */
80 extern XContext wWinContext;
82 /* cursors */
83 extern Cursor wCursor[WCUR_LAST];
85 /* protocol atoms */
86 extern Atom _XA_WM_DELETE_WINDOW;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_WINDOWMAKER_STATE;
91 extern WPreferences wPreferences;
93 #define MOD_MASK wPreferences.modifier_mask
95 extern Time LastTimestamp;
97 /* superfluous... */
98 extern void DoWindowBirth(WWindow*);
102 /***** Local Stuff *****/
105 static WWindowState *windowState=NULL;
109 /* local functions */
110 static FocusMode getFocusMode(WWindow *wwin);
112 static int getSavedState(Window window, WSavedState **state);
114 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
116 /* event handlers */
119 /* frame window (during window grabs) */
120 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
122 /* close button */
123 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
124 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
126 /* iconify button */
127 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
129 #ifdef XKB_BUTTON_HINT
130 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
131 #endif
133 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
134 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
136 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
139 /****** Notification Observers ******/
141 static void
142 appearanceObserver(void *self, WMNotification *notif)
144 WWindow *wwin = (WWindow*)self;
145 int flags = (int)WMGetNotificationClientData(notif);
147 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
148 return;
150 if (flags & WFontSettings) {
151 wWindowConfigureBorders(wwin);
152 if(wwin->flags.shaded) {
153 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
154 wwin->frame->top_width - 1);
156 wwin->client.y = wwin->frame_y - wwin->client.height
157 + wwin->frame->top_width;
158 wWindowSynthConfigureNotify(wwin);
161 if (flags & WTextureSettings) {
162 wwin->frame->flags.need_texture_remake = 1;
164 if (flags & (WTextureSettings | WColorSettings)) {
165 if (wwin->frame->titlebar)
166 XClearWindow(dpy, wwin->frame->titlebar->window);
168 wFrameWindowPaint(wwin->frame);
172 /************************************/
174 WWindow*
175 wWindowFor(Window window)
177 WObjDescriptor *desc;
179 if (window==None)
180 return NULL;
182 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
183 return NULL;
185 if (desc->parent_type==WCLASS_WINDOW)
186 return desc->parent;
187 else if (desc->parent_type==WCLASS_FRAME) {
188 WFrameWindow *frame = (WFrameWindow*)desc->parent;
189 if (frame->flags.is_client_window_frame)
190 return frame->child;
193 return NULL;
197 WWindow*
198 wWindowCreate()
200 WWindow *wwin;
202 wwin = wmalloc(sizeof(WWindow));
203 wretain(wwin);
205 memset(wwin, 0, sizeof(WWindow));
207 wwin->client_descriptor.handle_mousedown = frameMouseDown;
208 wwin->client_descriptor.parent = wwin;
209 wwin->client_descriptor.self = wwin;
210 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
212 return wwin;
216 void
217 wWindowDestroy(WWindow *wwin)
219 int i;
221 if (wwin->screen_ptr->cmap_window == wwin) {
222 wwin->screen_ptr->cmap_window = NULL;
225 WMRemoveNotificationObserver(wwin);
227 wwin->flags.destroyed = 1;
229 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
230 if (!wwin->screen_ptr->shortcutWindows[i])
231 continue;
233 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
235 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
236 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
237 wwin->screen_ptr->shortcutWindows[i] = NULL;
241 if (wwin->normal_hints)
242 XFree(wwin->normal_hints);
244 if (wwin->wm_hints)
245 XFree(wwin->wm_hints);
247 if (wwin->wm_instance)
248 XFree(wwin->wm_instance);
250 if (wwin->wm_class)
251 XFree(wwin->wm_class);
253 if (wwin->wm_gnustep_attr)
254 wfree(wwin->wm_gnustep_attr);
256 if (wwin->cmap_windows)
257 XFree(wwin->cmap_windows);
259 XDeleteContext(dpy, wwin->client_win, wWinContext);
261 if (wwin->frame)
262 wFrameWindowDestroy(wwin->frame);
264 if (wwin->icon) {
265 RemoveFromStackList(wwin->icon->core);
266 wIconDestroy(wwin->icon);
267 if (wPreferences.auto_arrange_icons)
268 wArrangeIcons(wwin->screen_ptr, True);
270 wrelease(wwin);
276 static void
277 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
279 if (gs_hints->flags & GSWindowStyleAttr) {
280 if (gs_hints->window_style == WMBorderlessWindowMask) {
281 wwin->client_flags.no_border = 1;
282 wwin->client_flags.no_titlebar = 1;
283 wwin->client_flags.no_closable = 1;
284 wwin->client_flags.no_miniaturizable = 1;
285 wwin->client_flags.no_resizable = 1;
286 wwin->client_flags.no_close_button = 1;
287 wwin->client_flags.no_miniaturize_button = 1;
288 wwin->client_flags.no_resizebar = 1;
289 } else {
290 wwin->client_flags.no_close_button =
291 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
293 wwin->client_flags.no_closable =
294 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
296 wwin->client_flags.no_miniaturize_button =
297 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
299 wwin->client_flags.no_miniaturizable =
300 wwin->client_flags.no_miniaturize_button;
302 wwin->client_flags.no_resizebar =
303 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
305 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
307 /* these attributes supposedly imply in the existence
308 * of a titlebar */
309 if (gs_hints->window_style & (WMResizableWindowMask|
310 WMClosableWindowMask|
311 WMMiniaturizableWindowMask)) {
312 wwin->client_flags.no_titlebar = 0;
313 } else {
314 wwin->client_flags.no_titlebar =
315 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
319 } else {
320 /* setup the defaults */
321 wwin->client_flags.no_border = 0;
322 wwin->client_flags.no_titlebar = 0;
323 wwin->client_flags.no_closable = 0;
324 wwin->client_flags.no_miniaturizable = 0;
325 wwin->client_flags.no_resizable = 0;
326 wwin->client_flags.no_close_button = 0;
327 wwin->client_flags.no_miniaturize_button = 0;
328 wwin->client_flags.no_resizebar = 0;
330 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
331 wwin->client_flags.no_appicon = 1;
336 void
337 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
338 WWindowAttributes *mask)
340 if (wflags->no_appicon && mask->no_appicon)
341 wflags->emulate_appicon = 0;
343 if (wwin->main_window!=None) {
344 WApplication *wapp = wApplicationOf(wwin->main_window);
345 if (wapp && !wapp->flags.emulated)
346 wflags->emulate_appicon = 0;
349 if (wwin->transient_for!=None
350 && wwin->transient_for!=wwin->screen_ptr->root_win)
351 wflags->emulate_appicon = 0;
353 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
354 wflags->sunken = 0;
359 void
360 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
362 WScreen *scr = wwin->screen_ptr;
364 /* sets global default stuff */
365 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
366 &wwin->client_flags, NULL, True);
368 * Decoration setting is done in this precedence (lower to higher)
369 * - use global default in the resource database
370 * - guess some settings
371 * - use GNUstep/external window attributes
372 * - set hints specified for the app in the resource DB
375 WSETUFLAG(wwin, broken_close, 0);
377 if (wwin->protocols.DELETE_WINDOW)
378 WSETUFLAG(wwin, kill_close, 0);
379 else
380 WSETUFLAG(wwin, kill_close, 1);
382 /* transients can't be iconified or maximized */
383 if (wwin->transient_for) {
384 WSETUFLAG(wwin, no_miniaturizable, 1);
385 WSETUFLAG(wwin, no_miniaturize_button, 1);
388 /* if the window can't be resized, remove the resizebar */
389 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
390 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
391 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
392 WSETUFLAG(wwin, no_resizable, 1);
393 WSETUFLAG(wwin, no_resizebar, 1);
396 /* set GNUstep window attributes */
397 if (wwin->wm_gnustep_attr) {
398 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
400 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
402 *level = wwin->wm_gnustep_attr->window_level;
404 * INT_MIN is the only illegal window level.
406 if (*level == INT_MIN)
407 *level = INT_MIN + 1;
408 } else {
409 /* setup defaults */
410 *level = WMNormalLevel;
412 } else {
413 int tmp_workspace = -1;
414 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
415 Bool check;
417 check = False;
419 #ifdef MWM_HINTS
420 wMWMCheckClientHints(wwin);
421 #endif /* MWM_HINTS */
423 #ifdef GNOME_STUFF
424 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
425 #endif /* GNOME_STUFF */
427 #ifdef KWM_HINTS
428 if (!check)
429 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
430 #endif /* KWM_HINTS */
432 #ifdef OLWM_HINTS
433 wOLWMCheckClientHints(wwin);
434 #endif /* OLWM_HINTS */
436 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
437 * have INT_MIN that means that no window level was requested. -Dan
439 if (tmp_level == INT_MIN) {
440 if (WFLAGP(wwin, floating))
441 *level = WMFloatingLevel;
442 else if (WFLAGP(wwin, sunken))
443 *level = WMSunkenLevel;
444 else
445 *level = WMNormalLevel;
446 } else {
447 *level = tmp_level;
450 if (tmp_workspace >= 0) {
451 *workspace = tmp_workspace % scr->workspace_count;
456 * Set attributes specified only for that window/class.
457 * This might do duplicate work with the 1st wDefaultFillAttributes().
459 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
460 &wwin->user_flags, &wwin->defined_user_flags,
461 False);
463 * Sanity checks for attributes that depend on other attributes
465 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
466 wwin->user_flags.emulate_appicon = 0;
468 if (wwin->main_window!=None) {
469 WApplication *wapp = wApplicationOf(wwin->main_window);
470 if (wapp && !wapp->flags.emulated)
471 wwin->user_flags.emulate_appicon = 0;
474 if (wwin->transient_for!=None
475 && wwin->transient_for!=wwin->screen_ptr->root_win)
476 wwin->user_flags.emulate_appicon = 0;
478 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
479 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
480 wwin->user_flags.sunken = 0;
482 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
488 Bool
489 wWindowCanReceiveFocus(WWindow *wwin)
491 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
492 return False;
493 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
494 return False;
495 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
496 return False;
498 return True;
502 Bool
503 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
505 int w1, h1, w2, h2;
507 w1 = wwin->frame->core->width;
508 h1 = wwin->frame->core->height;
509 w2 = obscured->frame->core->width;
510 h2 = obscured->frame->core->height;
512 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
513 && wwin->frame->workspace != obscured->frame->workspace)
514 return False;
516 if (wwin->frame_x + w1 < obscured->frame_x
517 || wwin->frame_y + h1 < obscured->frame_y
518 || wwin->frame_x > obscured->frame_x + w2
519 || wwin->frame_y > obscured->frame_y + h2) {
520 return False;
523 return True;
529 *----------------------------------------------------------------
530 * wManageWindow--
531 * reparents the window and allocates a descriptor for it.
532 * Window manager hints and other hints are fetched to configure
533 * the window decoration attributes and others. User preferences
534 * for the window are used if available, to configure window
535 * decorations and some behaviour.
536 * If in startup, windows that are override redirect,
537 * unmapped and never were managed and are Withdrawn are not
538 * managed.
540 * Returns:
541 * the new window descriptor
543 * Side effects:
544 * The window is reparented and appropriate notification
545 * is done to the client. Input mask for the window is setup.
546 * The window descriptor is also associated with various window
547 * contexts and inserted in the head of the window list.
548 * Event handler contexts are associated for some objects
549 * (buttons, titlebar and resizebar)
551 *----------------------------------------------------------------
553 WWindow*
554 wManageWindow(WScreen *scr, Window window)
556 WWindow *wwin;
557 int x, y;
558 unsigned width, height;
559 XWindowAttributes wattribs;
560 XSetWindowAttributes attribs;
561 WWindowState *win_state;
562 WWindow *transientOwner = NULL;
563 int window_level;
564 int wm_state;
565 int foo;
566 int workspace = -1;
567 char *title;
568 Bool withdraw = False;
570 /* mutex. */
571 /* XGrabServer(dpy); */
572 XSync(dpy, False);
573 /* make sure the window is still there */
574 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
575 XUngrabServer(dpy);
576 return NULL;
579 /* if it's an override-redirect, ignore it */
580 if (wattribs.override_redirect) {
581 XUngrabServer(dpy);
582 return NULL;
585 wm_state = PropGetWindowState(window);
587 /* if it's startup and the window is unmapped, don't manage it */
588 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
589 XUngrabServer(dpy);
590 return NULL;
593 if (!wFetchName(dpy, window, &title)) {
594 title = NULL;
597 #ifdef KWM_HINTS
598 if (title && !wKWMManageableClient(scr, window, title)) {
599 XFree(title);
600 XUngrabServer(dpy);
601 return NULL;
603 #endif /* KWM_HINTS */
606 wwin = wWindowCreate();
608 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
610 #ifdef DEBUG
611 printf("managing window %x\n", (unsigned)window);
612 #endif
614 #ifdef SHAPE
615 if (wShapeSupported) {
616 int junk;
617 unsigned int ujunk;
618 int b_shaped;
620 XShapeSelectInput(dpy, window, ShapeNotifyMask);
621 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
622 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
623 wwin->flags.shaped = b_shaped;
625 #endif
628 *--------------------------------------------------
630 * Get hints and other information in properties
632 *--------------------------------------------------
634 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
636 /* setup descriptor */
637 wwin->client_win = window;
638 wwin->screen_ptr = scr;
640 wwin->old_border_width = wattribs.border_width;
642 wwin->event_mask = CLIENT_EVENTS;
643 attribs.event_mask = CLIENT_EVENTS;
644 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
645 attribs.save_under = False;
646 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
647 |CWSaveUnder, &attribs);
648 XSetWindowBorderWidth(dpy, window, 0);
650 /* get hints from GNUstep app */
651 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
652 wwin->flags.is_gnustep = 1;
654 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
655 wwin->wm_gnustep_attr = NULL;
658 wwin->client_leader = PropGetClientLeader(window);
659 if (wwin->client_leader!=None)
660 wwin->main_window = wwin->client_leader;
662 wwin->wm_hints = XGetWMHints(dpy, window);
664 if (wwin->wm_hints) {
665 if (wwin->wm_hints->flags & StateHint) {
667 if (wwin->wm_hints->initial_state == IconicState) {
669 wwin->flags.miniaturized = 1;
671 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
673 withdraw = True;
677 if (wwin->wm_hints->flags & WindowGroupHint) {
678 wwin->group_id = wwin->wm_hints->window_group;
679 /* window_group has priority over CLIENT_LEADER */
680 wwin->main_window = wwin->group_id;
681 } else {
682 wwin->group_id = None;
685 if (wwin->wm_hints->flags & UrgencyHint)
686 wwin->flags.urgent = 1;
687 } else {
688 wwin->group_id = None;
691 PropGetProtocols(window, &wwin->protocols);
693 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
694 wwin->transient_for = None;
695 } else {
696 if (wwin->transient_for==None || wwin->transient_for==window) {
697 wwin->transient_for = scr->root_win;
698 } else {
699 transientOwner = wWindowFor(wwin->transient_for);
700 if (transientOwner && transientOwner->main_window!=None) {
701 wwin->main_window = transientOwner->main_window;
702 } /*else {
703 wwin->main_window = None;
708 /* guess the focus mode */
709 wwin->focus_mode = getFocusMode(wwin);
711 /* get geometry stuff */
712 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
714 /* get colormap windows */
715 GetColormapWindows(wwin);
718 *--------------------------------------------------
720 * Setup the decoration/window attributes and
721 * geometry
723 *--------------------------------------------------
726 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
728 #ifdef OLWM_HINTS
729 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
730 && wwin->group_id != None && wwin->group_id != window) {
732 transientOwner = wWindowFor(wwin->group_id);
734 if (transientOwner) {
735 wwin->transient_for = wwin->group_id;
737 /* transients can't be iconified or maximized */
738 if (wwin->transient_for) {
739 WSETUFLAG(wwin, no_miniaturizable, 1);
740 WSETUFLAG(wwin, no_miniaturize_button, 1);
744 #endif /* OLWM_HINTS */
747 * Make broken apps behave as a nice app.
749 if (WFLAGP(wwin, emulate_appicon)) {
750 wwin->main_window = wwin->client_win;
754 *------------------------------------------------------------
756 * Setup the initial state of the window
758 *------------------------------------------------------------
761 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
762 wwin->flags.miniaturized = 1;
765 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
766 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
770 Bool bla;
772 bla = False;
773 #ifdef GNOME_STUFF
774 bla = wGNOMECheckInitialClientState(wwin);
775 #endif
776 #ifdef KWM_HINTS
777 if (!bla)
778 wKWMCheckClientInitialState(wwin);
779 #endif
782 /* apply previous state if it exists and we're in startup */
783 if (scr->flags.startup && wm_state >= 0) {
785 if (wm_state == IconicState) {
787 wwin->flags.miniaturized = 1;
789 } else if (wm_state == WithdrawnState) {
791 withdraw = True;
795 /* if there is a saved state (from file), restore it */
796 win_state = NULL;
797 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
798 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
799 } else {
800 win_state = (WWindowState*)wWindowGetSavedState(window);
802 if (win_state && !withdraw) {
804 if (win_state->state->hidden>0)
805 wwin->flags.hidden = win_state->state->hidden;
807 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
808 wwin->flags.shaded = win_state->state->shaded;
810 if (win_state->state->miniaturized>0 &&
811 !WFLAGP(wwin, no_miniaturizable)) {
812 wwin->flags.miniaturized = win_state->state->miniaturized;
815 if (!IS_OMNIPRESENT(wwin)) {
816 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
817 wwin->wm_class);
818 if (w < 0 || w >= scr->workspace_count) {
819 workspace = win_state->state->workspace;
820 if (workspace >= scr->workspace_count)
821 workspace = scr->current_workspace;
822 } else {
823 workspace = w;
825 } else {
826 workspace = scr->current_workspace;
830 /* if we're restarting, restore saved state (from hints).
831 * This will overwrite previous */
833 WSavedState *wstate;
835 if (getSavedState(window, &wstate)) {
836 wwin->flags.shaded = wstate->shaded;
837 wwin->flags.hidden = wstate->hidden;
838 wwin->flags.miniaturized = wstate->miniaturized;
839 wwin->flags.maximized = wstate->maximized;
840 if (wwin->flags.maximized) {
841 wwin->old_geometry.x = wstate->x;
842 wwin->old_geometry.y = wstate->y;
843 wwin->old_geometry.width = wstate->w;
844 wwin->old_geometry.height = wstate->h;
847 workspace = wstate->workspace;
848 } else {
849 wstate = NULL;
852 /* restore window shortcut */
853 if (wstate != NULL || win_state != NULL) {
854 unsigned mask = 0;
856 if (win_state != NULL)
857 mask = win_state->state->window_shortcuts;
859 if (wstate != NULL && mask == 0)
860 mask = wstate->window_shortcuts;
862 if (mask > 0) {
863 int i;
865 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
866 if (mask & (1<<i)) {
867 if (!scr->shortcutWindows[i])
868 scr->shortcutWindows[i] = WMCreateArray(4);
870 WMAddToArray(scr->shortcutWindows[i], wwin);
875 if (wstate != NULL) {
876 wfree(wstate);
880 /* don't let transients start miniaturized if their owners are not */
881 if (transientOwner && !transientOwner->flags.miniaturized
882 && wwin->flags.miniaturized && !withdraw) {
883 wwin->flags.miniaturized = 0;
884 if (wwin->wm_hints)
885 wwin->wm_hints->initial_state = NormalState;
888 /* set workspace on which the window starts */
889 if (workspace >= 0) {
890 if (workspace > scr->workspace_count-1) {
891 workspace = workspace % scr->workspace_count;
893 } else {
894 int w;
896 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
898 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
900 workspace = w;
902 } else {
903 if (wPreferences.open_transients_with_parent && transientOwner) {
905 workspace = transientOwner->frame->workspace;
907 } else {
909 workspace = scr->current_workspace;
914 /* setup window geometry */
915 if (win_state && win_state->state->w > 0) {
916 width = win_state->state->w;
917 height = win_state->state->h;
919 wWindowConstrainSize(wwin, &width, &height);
921 /* do not ask for window placement if the window is
922 * transient, during startup, if the initial workspace is another one
923 * or if the window wants to start iconic.
924 * If geometry was saved, restore it. */
926 Bool dontBring = False;
928 if (win_state && win_state->state->w > 0) {
929 x = win_state->state->x;
930 y = win_state->state->y;
931 } else if ((wwin->transient_for==None
932 || wPreferences.window_placement!=WPM_MANUAL)
933 && !scr->flags.startup
934 && workspace == scr->current_workspace
935 && !wwin->flags.miniaturized
936 && !wwin->flags.maximized
937 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
939 if (transientOwner && transientOwner->flags.mapped) {
940 int offs = WMAX(20, 2*transientOwner->frame->top_width);
942 x = transientOwner->frame_x +
943 abs((transientOwner->frame->core->width - width)/2) + offs;
944 y = transientOwner->frame_y +
945 abs((transientOwner->frame->core->height - height)/3) + offs;
947 if (x < 0)
948 x = 0;
949 else if (x + width > scr->scr_width)
950 x = scr->scr_width - width;
952 if (y < 0)
953 y = 0;
954 else if (y + height > scr->scr_height)
955 y = scr->scr_height - height;
956 } else {
957 PlaceWindow(wwin, &x, &y, width, height);
959 if (wPreferences.window_placement == WPM_MANUAL)
960 dontBring = True;
963 if (WFLAGP(wwin, dont_move_off) && dontBring)
964 wScreenBringInside(scr, &x, &y, width, height);
967 if (wwin->flags.urgent) {
968 if (!IS_OMNIPRESENT(wwin))
969 wwin->flags.omnipresent ^= 1;
973 *--------------------------------------------------
975 * Create frame, borders and do reparenting
977 *--------------------------------------------------
979 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
980 #ifdef XKB_BUTTON_HINT
981 if (wPreferences.modelock)
982 foo |= WFF_LANGUAGE_BUTTON;
983 #endif
984 if (!WFLAGP(wwin, no_titlebar))
985 foo |= WFF_TITLEBAR;
986 if (!WFLAGP(wwin, no_resizebar))
987 foo |= WFF_RESIZEBAR;
988 if (!WFLAGP(wwin, no_border))
989 foo |= WFF_BORDER;
991 wwin->frame = wFrameWindowCreate(scr, window_level,
992 x, y, width, height,
993 &wPreferences.window_title_clearance, foo,
994 scr->window_title_texture,
995 scr->resizebar_texture,
996 scr->window_title_pixel,
997 &scr->window_title_gc,
998 &scr->title_font);
1000 wwin->frame->flags.is_client_window_frame = 1;
1001 wwin->frame->flags.justification = wPreferences.title_justification;
1003 /* setup button images */
1004 wWindowUpdateButtonImages(wwin);
1006 /* hide unused buttons */
1007 foo = 0;
1008 if (WFLAGP(wwin, no_close_button))
1009 foo |= WFF_RIGHT_BUTTON;
1010 if (WFLAGP(wwin, no_miniaturize_button))
1011 foo |= WFF_LEFT_BUTTON;
1012 #ifdef XKB_BUTTON_HINT
1013 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1014 foo |= WFF_LANGUAGE_BUTTON;
1015 #endif
1016 if (foo!=0)
1017 wFrameWindowHideButton(wwin->frame, foo);
1019 wwin->frame->child = wwin;
1021 #ifdef OLWM_HINTS
1022 /* emulate olwm push pin. Make the button look as pushed-in for
1023 * the pinned-out state. When the button is clicked, it will
1024 * revert to the normal position, which means the pin is pinned-in.
1026 if (wwin->flags.olwm_push_pin_out)
1027 wFrameWindowUpdatePushButton(wwin->frame, True);
1028 #endif /* OLWM_HINTS */
1031 wwin->frame->workspace = workspace;
1033 wwin->frame->on_click_left = windowIconifyClick;
1034 #ifdef XKB_BUTTON_HINT
1035 if (wPreferences.modelock)
1036 wwin->frame->on_click_language = windowLanguageClick;
1037 #endif
1039 wwin->frame->on_click_right = windowCloseClick;
1040 wwin->frame->on_dblclick_right = windowCloseDblClick;
1042 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1043 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1045 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1048 XSelectInput(dpy, wwin->client_win,
1049 wwin->event_mask & ~StructureNotifyMask);
1051 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1052 0, wwin->frame->top_width);
1054 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1058 int gx, gy;
1060 wClientGetGravityOffsets(wwin, &gx, &gy);
1062 /* if gravity is to the south, account for the border sizes */
1063 if (gy > 0)
1064 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1068 * wWindowConfigure() will init the client window's size
1069 * (wwin->client.{width,height}) and all other geometry
1070 * related variables (frame_x,frame_y)
1072 wWindowConfigure(wwin, x, y, width, height);
1074 /* to make sure the window receives it's new position after reparenting */
1075 wWindowSynthConfigureNotify(wwin);
1078 *--------------------------------------------------
1080 * Setup descriptors and save window to internal
1081 * lists
1083 *--------------------------------------------------
1086 if (wwin->main_window!=None) {
1087 WApplication *app;
1088 WWindow *leader;
1090 /* Leader windows do not necessary set themselves as leaders.
1091 * If this is the case, point the leader of this window to
1092 * itself */
1093 leader = wWindowFor(wwin->main_window);
1094 if (leader && leader->main_window==None) {
1095 leader->main_window = leader->client_win;
1097 app = wApplicationCreate(scr, wwin->main_window);
1098 if (app) {
1099 app->last_workspace = workspace;
1102 * Do application specific stuff, like setting application
1103 * wide attributes.
1106 if (wwin->flags.hidden) {
1107 /* if the window was set to hidden because it was hidden
1108 * in a previous incarnation and that state was restored */
1109 app->flags.hidden = 1;
1112 if (app->flags.hidden) {
1113 wwin->flags.hidden = 1;
1118 /* setup the frame descriptor */
1119 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1120 wwin->frame->core->descriptor.parent = wwin;
1121 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1123 /* don't let windows go away if we die */
1124 XAddToSaveSet(dpy, window);
1126 XLowerWindow(dpy, window);
1128 /* if window is in this workspace and should be mapped, then map it */
1129 if (!wwin->flags.miniaturized
1130 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1131 && !wwin->flags.hidden && !withdraw) {
1133 /* The following "if" is to avoid crashing of clients that expect
1134 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1135 * after the return from this function.
1137 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1138 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1139 } else {
1140 wClientSetState(wwin, NormalState, None);
1143 #if 0
1144 /* if not auto focus, then map the window under the currently
1145 * focused window */
1146 #define _WIDTH(w) (w)->frame->core->width
1147 #define _HEIGHT(w) (w)->frame->core->height
1148 if (!wPreferences.auto_focus && scr->focused_window
1149 && !scr->flags.startup && !transientOwner
1150 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1151 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1152 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1153 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1154 || wwin->flags.maximized)) {
1155 MoveInStackListUnder(scr->focused_window->frame->core,
1156 wwin->frame->core);
1158 #undef _WIDTH
1159 #undef _HEIGHT
1161 #endif
1163 if (wPreferences.superfluous && !wPreferences.no_animations
1164 && !scr->flags.startup && wwin->transient_for==None
1166 * The brain damaged idiotic non-click to focus modes will
1167 * have trouble with this because:
1169 * 1. window is created and mapped by the client
1170 * 2. window is mapped by wmaker in small size
1171 * 3. window is animated to grow to normal size
1172 * 4. this function returns to normal event loop
1173 * 5. eventually, the EnterNotify event that would trigger
1174 * the window focusing (if the mouse is over that window)
1175 * will be processed by wmaker.
1176 * But since this event will be rather delayed
1177 * (step 3 has a large delay) the time when the event ocurred
1178 * and when it is processed, the client that owns that window
1179 * will reject the XSetInputFocus() for it.
1181 && (wPreferences.focus_mode==WKF_CLICK
1182 || wPreferences.auto_focus)) {
1183 DoWindowBirth(wwin);
1186 wWindowMap(wwin);
1189 /* setup stacking descriptor */
1190 if (transientOwner) {
1191 /* && wPreferences.on_top_transients */
1192 if (transientOwner) {
1193 wwin->frame->core->stacking->child_of =
1194 transientOwner->frame->core;
1196 } else {
1197 wwin->frame->core->stacking->child_of = NULL;
1201 if (!scr->focused_window) {
1202 /* first window on the list */
1203 wwin->next = NULL;
1204 wwin->prev = NULL;
1205 scr->focused_window = wwin;
1206 } else {
1207 WWindow *tmp;
1209 /* add window at beginning of focus window list */
1210 tmp = scr->focused_window;
1211 while (tmp->prev)
1212 tmp = tmp->prev;
1213 tmp->prev = wwin;
1214 wwin->next = tmp;
1215 wwin->prev = NULL;
1218 /* Update name must come after WApplication stuff is done */
1219 wWindowUpdateName(wwin, title);
1220 if (title)
1221 XFree(title);
1223 XUngrabServer(dpy);
1226 *--------------------------------------------------
1228 * Final preparations before window is ready to go
1230 *--------------------------------------------------
1233 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1236 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1237 && !wwin->flags.hidden) {
1238 if (((transientOwner && transientOwner->flags.focused)
1239 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1240 wSetFocusTo(scr, wwin);
1242 wWindowResetMouseGrabs(wwin);
1244 if (!WFLAGP(wwin, no_bind_keys)) {
1245 wWindowSetKeyGrabs(wwin);
1249 WMPostNotificationName(WMNManaged, wwin, NULL);
1252 wColormapInstallForWindow(scr, scr->cmap_window);
1255 #ifdef OLWM_HINTS
1256 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1257 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1259 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1260 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1261 wwin->frame_y);
1263 #endif
1266 *------------------------------------------------------------
1267 * Setup Notification Observers
1268 *------------------------------------------------------------
1270 WMAddNotificationObserver(appearanceObserver, wwin,
1271 WNWindowAppearanceSettingsChanged, wwin);
1275 *--------------------------------------------------
1277 * Cleanup temporary stuff
1279 *--------------------------------------------------
1282 if (win_state)
1283 wWindowDeleteSavedState(win_state);
1285 /* If the window must be withdrawed, then do it now.
1286 * Must do some optimization, 'though */
1287 if (withdraw) {
1288 wwin->flags.mapped = 0;
1289 wClientSetState(wwin, WithdrawnState, None);
1290 wUnmanageWindow(wwin, True, False);
1291 wwin = NULL;
1294 return wwin;
1301 WWindow*
1302 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1303 char *title, int x, int y, int width, int height)
1305 WWindow *wwin;
1306 int foo;
1308 wwin = wWindowCreate();
1310 WMAddNotificationObserver(appearanceObserver, wwin,
1311 WNWindowAppearanceSettingsChanged, wwin);
1313 wwin->flags.internal_window = 1;
1315 WSETUFLAG(wwin, omnipresent, 1);
1316 WSETUFLAG(wwin, no_shadeable, 1);
1317 WSETUFLAG(wwin, no_resizable, 1);
1318 WSETUFLAG(wwin, no_miniaturizable, 1);
1320 wwin->focus_mode = WFM_PASSIVE;
1322 wwin->client_win = window;
1323 wwin->screen_ptr = scr;
1325 wwin->transient_for = owner;
1327 wwin->client.x = x;
1328 wwin->client.y = y;
1329 wwin->client.width = width;
1330 wwin->client.height = height;
1332 wwin->frame_x = wwin->client.x;
1333 wwin->frame_y = wwin->client.y;
1336 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1337 foo |= WFF_TITLEBAR;
1338 #ifdef XKB_BUTTON_HINT
1339 foo |= WFF_LANGUAGE_BUTTON;
1340 #endif
1342 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1343 wwin->frame_x, wwin->frame_y,
1344 width, height,
1345 &wPreferences.window_title_clearance, foo,
1346 scr->window_title_texture,
1347 scr->resizebar_texture,
1348 scr->window_title_pixel,
1349 &scr->window_title_gc,
1350 &scr->title_font);
1352 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1354 wwin->frame->flags.is_client_window_frame = 1;
1355 wwin->frame->flags.justification = wPreferences.title_justification;
1357 wFrameWindowChangeTitle(wwin->frame, title);
1359 /* setup button images */
1360 wWindowUpdateButtonImages(wwin);
1362 /* hide buttons */
1363 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1365 wwin->frame->child = wwin;
1367 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1369 #ifdef XKB_BUTTON_HINT
1370 if (wPreferences.modelock)
1371 wwin->frame->on_click_language = windowLanguageClick;
1372 #endif
1374 wwin->frame->on_click_right = windowCloseClick;
1376 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1377 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1379 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1381 wwin->client.y += wwin->frame->top_width;
1382 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1383 0, wwin->frame->top_width);
1385 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1386 wwin->client.width, wwin->client.height);
1388 /* setup the frame descriptor */
1389 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1390 wwin->frame->core->descriptor.parent = wwin;
1391 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1394 XLowerWindow(dpy, window);
1395 XMapSubwindows(dpy, wwin->frame->core->window);
1397 /* setup stacking descriptor */
1398 if (
1399 #ifdef removed
1400 wPreferences.on_top_transients &&
1401 #endif
1402 wwin->transient_for!=None
1403 && wwin->transient_for!=scr->root_win) {
1404 WWindow *tmp;
1405 tmp = wWindowFor(wwin->transient_for);
1406 if (tmp)
1407 wwin->frame->core->stacking->child_of = tmp->frame->core;
1408 } else {
1409 wwin->frame->core->stacking->child_of = NULL;
1413 if (!scr->focused_window) {
1414 /* first window on the list */
1415 wwin->next = NULL;
1416 wwin->prev = NULL;
1417 scr->focused_window = wwin;
1418 } else {
1419 WWindow *tmp;
1421 /* add window at beginning of focus window list */
1422 tmp = scr->focused_window;
1423 while (tmp->prev)
1424 tmp = tmp->prev;
1425 tmp->prev = wwin;
1426 wwin->next = tmp;
1427 wwin->prev = NULL;
1430 if (wwin->flags.is_gnustep == 0)
1431 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1433 /* if (wPreferences.auto_focus)*/
1434 wSetFocusTo(scr, wwin);
1436 wWindowResetMouseGrabs(wwin);
1438 wWindowSetKeyGrabs(wwin);
1440 return wwin;
1445 *----------------------------------------------------------------------
1446 * wUnmanageWindow--
1447 * Removes the frame window from a window and destroys all data
1448 * related to it. The window will be reparented back to the root window
1449 * if restore is True.
1451 * Side effects:
1452 * Everything related to the window is destroyed and the window
1453 * is removed from the window lists. Focus is set to the previous on the
1454 * window list.
1455 *----------------------------------------------------------------------
1457 void
1458 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1460 WCoreWindow *frame = wwin->frame->core;
1461 WWindow *owner = NULL;
1462 WWindow *newFocusedWindow = NULL;
1463 int wasFocused;
1464 WScreen *scr = wwin->screen_ptr;
1467 /* First close attribute editor window if open */
1468 if (wwin->flags.inspector_open) {
1469 wCloseInspectorForWindow(wwin);
1472 /* Close window menu if it's open for this window */
1473 if (wwin->flags.menu_open_for_me) {
1474 CloseWindowMenu(scr);
1477 if (!destroyed) {
1478 if (!wwin->flags.internal_window)
1479 XRemoveFromSaveSet(dpy, wwin->client_win);
1481 XSelectInput(dpy, wwin->client_win, NoEventMask);
1483 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1484 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1487 XUnmapWindow(dpy, frame->window);
1489 XUnmapWindow(dpy, wwin->client_win);
1491 /* deselect window */
1492 wSelectWindow(wwin, False);
1494 /* remove all pending events on window */
1495 /* I think this only matters for autoraise */
1496 if (wPreferences.raise_delay)
1497 WMDeleteTimerWithClientData(wwin->frame->core);
1499 XFlush(dpy);
1501 /* reparent the window back to the root */
1502 if (restore)
1503 wClientRestore(wwin);
1505 if (wwin->transient_for!=scr->root_win) {
1506 owner = wWindowFor(wwin->transient_for);
1507 if (owner) {
1508 if (!owner->flags.semi_focused) {
1509 owner = NULL;
1510 } else {
1511 owner->flags.semi_focused = 0;
1516 wasFocused = wwin->flags.focused;
1518 /* remove from window focus list */
1519 if (!wwin->prev && !wwin->next) {
1520 /* was the only window */
1521 scr->focused_window = NULL;
1522 newFocusedWindow = NULL;
1523 } else {
1524 WWindow *tmp;
1526 if (wwin->prev)
1527 wwin->prev->next = wwin->next;
1528 if (wwin->next)
1529 wwin->next->prev = wwin->prev;
1530 else {
1531 scr->focused_window = wwin->prev;
1532 scr->focused_window->next = NULL;
1535 if (wPreferences.focus_mode==WKF_CLICK) {
1537 /* if in click to focus mode and the window
1538 * was a transient, focus the owner window
1540 tmp = NULL;
1541 if (wPreferences.focus_mode==WKF_CLICK) {
1542 tmp = wWindowFor(wwin->transient_for);
1543 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1544 tmp = NULL;
1547 /* otherwise, focus the next one in the focus list */
1548 if (!tmp) {
1549 tmp = scr->focused_window;
1550 while (tmp) { /* look for one in the window list first */
1551 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1552 && (tmp->flags.mapped || tmp->flags.shaded))
1553 break;
1554 tmp = tmp->prev;
1556 if (!tmp) { /* if unsuccessful, choose any focusable window */
1557 tmp = scr->focused_window;
1558 while (tmp) {
1559 if (!WFLAGP(tmp, no_focusable)
1560 && (tmp->flags.mapped || tmp->flags.shaded))
1561 break;
1562 tmp = tmp->prev;
1567 newFocusedWindow = tmp;
1569 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1570 unsigned int mask;
1571 int foo;
1572 Window bar, win;
1574 /* This is to let the root window get the keyboard input
1575 * if Sloppy focus mode and no other window get focus.
1576 * This way keybindings will not freeze.
1578 tmp = NULL;
1579 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1580 &foo, &foo, &foo, &foo, &mask))
1581 tmp = wWindowFor(win);
1582 if (tmp == wwin)
1583 tmp = NULL;
1584 newFocusedWindow = tmp;
1585 } else {
1586 newFocusedWindow = NULL;
1590 if (!wwin->flags.internal_window) {
1591 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1594 #ifdef DEBUG
1595 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1596 (unsigned)frame->window);
1597 #endif
1599 if (wasFocused) {
1600 if (newFocusedWindow != owner && owner) {
1601 if (wwin->flags.is_gnustep == 0)
1602 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1604 wSetFocusTo(scr, newFocusedWindow);
1606 wWindowDestroy(wwin);
1607 XFlush(dpy);
1611 void
1612 wWindowMap(WWindow *wwin)
1614 XMapWindow(dpy, wwin->frame->core->window);
1615 if (!wwin->flags.shaded) {
1616 /* window will be remapped when getting MapNotify */
1617 XSelectInput(dpy, wwin->client_win,
1618 wwin->event_mask & ~StructureNotifyMask);
1619 XMapWindow(dpy, wwin->client_win);
1620 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1622 wwin->flags.mapped = 1;
1627 void
1628 wWindowUnmap(WWindow *wwin)
1630 wwin->flags.mapped = 0;
1632 /* prevent window withdrawal when getting UnmapNotify */
1633 XSelectInput(dpy, wwin->client_win,
1634 wwin->event_mask & ~StructureNotifyMask);
1635 XUnmapWindow(dpy, wwin->client_win);
1636 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1638 XUnmapWindow(dpy, wwin->frame->core->window);
1643 void
1644 wWindowFocus(WWindow *wwin, WWindow *owin)
1646 WWindow *nowner;
1647 WWindow *oowner;
1649 #ifdef KEEP_XKB_LOCK_STATUS
1650 if (wPreferences.modelock) {
1651 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1653 #endif /* KEEP_XKB_LOCK_STATUS */
1655 wwin->flags.semi_focused = 0;
1657 if (wwin->flags.is_gnustep == 0)
1658 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1660 wwin->flags.focused = 1;
1662 wWindowResetMouseGrabs(wwin);
1664 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1666 if (owin == wwin || !owin)
1667 return;
1669 nowner = wWindowFor(wwin->transient_for);
1671 /* new window is a transient for the old window */
1672 if (nowner == owin) {
1673 owin->flags.semi_focused = 1;
1674 wWindowUnfocus(nowner);
1675 return;
1678 oowner = wWindowFor(owin->transient_for);
1680 /* new window is owner of old window */
1681 if (wwin == oowner) {
1682 wWindowUnfocus(owin);
1683 return;
1686 if (!nowner) {
1687 wWindowUnfocus(owin);
1688 return;
1691 /* new window has same owner of old window */
1692 if (oowner == nowner) {
1693 /* prevent unfocusing of owner */
1694 oowner->flags.semi_focused = 0;
1695 wWindowUnfocus(owin);
1696 oowner->flags.semi_focused = 1;
1698 return;
1701 /* nowner != NULL && oowner != nowner */
1702 nowner->flags.semi_focused = 1;
1703 wWindowUnfocus(nowner);
1704 wWindowUnfocus(owin);
1708 void
1709 wWindowUnfocus(WWindow *wwin)
1711 CloseWindowMenu(wwin->screen_ptr);
1713 if (wwin->flags.is_gnustep == 0)
1714 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1715 ? WS_PFOCUSED : WS_UNFOCUSED);
1717 if (wwin->transient_for!=None
1718 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1719 WWindow *owner;
1720 owner = wWindowFor(wwin->transient_for);
1721 if (owner && owner->flags.semi_focused) {
1722 owner->flags.semi_focused = 0;
1723 if (owner->flags.mapped || owner->flags.shaded) {
1724 wWindowUnfocus(owner);
1725 wFrameWindowPaint(owner->frame);
1729 wwin->flags.focused = 0;
1731 wWindowResetMouseGrabs(wwin);
1733 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1737 void
1738 wWindowUpdateName(WWindow *wwin, char *newTitle)
1740 WApplication *app = wApplicationOf(wwin->main_window);
1741 int instIndex = 0;
1742 char prefix[32] = "";
1743 char *title;
1745 if (!wwin->frame)
1746 return;
1748 if (app)
1749 instIndex = wApplicationIndexOfGroup(app);
1752 wwin->flags.wm_name_changed = 1;
1754 if (!newTitle) {
1755 /* the hint was removed */
1756 title = DEF_WINDOW_TITLE;
1758 WMPostNotificationName(WMNChangedName, wwin, NULL);
1759 } else {
1760 title = newTitle;
1763 #ifndef NO_WINDOW_ENUMERATOR
1764 if (instIndex > 0) {
1765 snprintf(prefix, sizeof(prefix), " [%i]", instIndex);
1767 title = wstrconcat(title, prefix);
1769 #endif
1771 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1773 WMPostNotificationName(WMNChangedName, wwin, NULL);
1776 #ifndef NO_WINDOW_ENUMERATOR
1777 if (instIndex > 0)
1778 wfree(title);
1779 #endif
1786 *----------------------------------------------------------------------
1788 * wWindowConstrainSize--
1789 * Constrains size for the client window, taking the maximal size,
1790 * window resize increments and other size hints into account.
1792 * Returns:
1793 * The closest size to what was given that the client window can
1794 * have.
1796 *----------------------------------------------------------------------
1798 void
1799 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1801 int width = *nwidth;
1802 int height = *nheight;
1803 int winc = 1;
1804 int hinc = 1;
1805 int minW = 1, minH = 1;
1806 int maxW = wwin->screen_ptr->scr_width*2;
1807 int maxH = wwin->screen_ptr->scr_height*2;
1808 int minAX = -1, minAY = -1;
1809 int maxAX = -1, maxAY = -1;
1810 int baseW = 0;
1811 int baseH = 0;
1813 if (wwin->normal_hints) {
1814 winc = wwin->normal_hints->width_inc;
1815 hinc = wwin->normal_hints->height_inc;
1816 minW = wwin->normal_hints->min_width;
1817 minH = wwin->normal_hints->min_height;
1818 maxW = wwin->normal_hints->max_width;
1819 maxH = wwin->normal_hints->max_height;
1820 if (wwin->normal_hints->flags & PAspect) {
1821 minAX = wwin->normal_hints->min_aspect.x;
1822 minAY = wwin->normal_hints->min_aspect.y;
1823 maxAX = wwin->normal_hints->max_aspect.x;
1824 maxAY = wwin->normal_hints->max_aspect.y;
1827 baseW = wwin->normal_hints->base_width;
1828 baseH = wwin->normal_hints->base_height;
1831 if (width < minW)
1832 width = minW;
1833 if (height < minH)
1834 height = minH;
1836 if (width > maxW)
1837 width = maxW;
1838 if (height > maxH)
1839 height = maxH;
1841 /* aspect ratio code borrowed from olwm */
1842 if (minAX > 0) {
1843 /* adjust max aspect ratio */
1844 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1845 if (maxAX > maxAY) {
1846 height = (width * maxAY) / maxAX;
1847 if (height > maxH) {
1848 height = maxH;
1849 width = (height * maxAX) / maxAY;
1851 } else {
1852 width = (height * maxAX) / maxAY;
1853 if (width > maxW) {
1854 width = maxW;
1855 height = (width * maxAY) / maxAX;
1860 /* adjust min aspect ratio */
1861 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1862 if (minAX > minAY) {
1863 height = (width * minAY) / minAX;
1864 if (height < minH) {
1865 height = minH;
1866 width = (height * minAX) / minAY;
1868 } else {
1869 width = (height * minAX) / minAY;
1870 if (width < minW) {
1871 width = minW;
1872 height = (width * minAY) / minAX;
1878 if (baseW != 0) {
1879 width = (((width - baseW) / winc) * winc) + baseW;
1880 } else {
1881 width = (((width - minW) / winc) * winc) + minW;
1884 if (baseH != 0) {
1885 height = (((height - baseH) / hinc) * hinc) + baseH;
1886 } else {
1887 height = (((height - minH) / hinc) * hinc) + minH;
1890 /* broken stupid apps may cause preposterous values for these.. */
1891 if (width > 0)
1892 *nwidth = width;
1893 if (height > 0)
1894 *nheight = height;
1898 void
1899 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1900 int *width, int *height)
1902 int baseW = 0, baseH = 0;
1903 int winc = 1, hinc = 1;
1905 if (wwin->normal_hints) {
1906 baseW = wwin->normal_hints->base_width;
1907 baseH = wwin->normal_hints->base_height;
1909 winc = wwin->normal_hints->width_inc;
1910 hinc = wwin->normal_hints->height_inc;
1913 if (*width > maxW)
1914 *width = maxW - (maxW - baseW) % winc;
1916 if (*height > maxH)
1917 *height = maxH - (maxH - baseH) % hinc;
1921 void
1922 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1924 WScreen *scr = wwin->screen_ptr;
1925 WApplication *wapp;
1926 int unmap = 0;
1928 if (workspace >= scr->workspace_count || workspace < 0
1929 || workspace == wwin->frame->workspace)
1930 return;
1932 if (workspace != scr->current_workspace) {
1933 /* Sent to other workspace. Unmap window */
1934 if ((wwin->flags.mapped
1935 || wwin->flags.shaded
1936 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1937 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1939 wapp = wApplicationOf(wwin->main_window);
1940 if (wapp) {
1941 wapp->last_workspace = workspace;
1943 if (wwin->flags.miniaturized) {
1944 if (wwin->icon) {
1945 XUnmapWindow(dpy, wwin->icon->core->window);
1946 wwin->icon->mapped = 0;
1948 } else {
1949 unmap = 1;
1950 wSetFocusTo(scr, NULL);
1953 } else {
1954 /* brought to current workspace. Map window */
1955 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1956 if (wwin->icon) {
1957 XMapWindow(dpy, wwin->icon->core->window);
1958 wwin->icon->mapped = 1;
1960 } else if (!wwin->flags.mapped &&
1961 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1962 wWindowMap(wwin);
1965 if (!IS_OMNIPRESENT(wwin)) {
1966 int oldWorkspace = wwin->frame->workspace;
1968 wwin->frame->workspace = workspace;
1970 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
1973 if (unmap) {
1974 wWindowUnmap(wwin);
1979 void
1980 wWindowSynthConfigureNotify(WWindow *wwin)
1982 XEvent sevent;
1984 sevent.type = ConfigureNotify;
1985 sevent.xconfigure.display = dpy;
1986 sevent.xconfigure.event = wwin->client_win;
1987 sevent.xconfigure.window = wwin->client_win;
1989 sevent.xconfigure.x = wwin->client.x;
1990 sevent.xconfigure.y = wwin->client.y;
1991 sevent.xconfigure.width = wwin->client.width;
1992 sevent.xconfigure.height = wwin->client.height;
1994 sevent.xconfigure.border_width = wwin->old_border_width;
1995 if (WFLAGP(wwin, no_titlebar))
1996 sevent.xconfigure.above = None;
1997 else
1998 sevent.xconfigure.above = wwin->frame->titlebar->window;
2000 sevent.xconfigure.override_redirect = False;
2001 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2002 #ifdef KWM_HINTS
2003 wKWMSendEventMessage(wwin, WKWMChangedClient);
2004 #endif
2005 XFlush(dpy);
2010 *----------------------------------------------------------------------
2011 * wWindowConfigure--
2012 * Configures the frame, decorations and client window to the
2013 * specified geometry. The geometry is not checked for validity,
2014 * wWindowConstrainSize() must be used for that.
2015 * The size parameters are for the client window, but the position is
2016 * for the frame.
2017 * The client window receives a ConfigureNotify event, according
2018 * to what ICCCM says.
2020 * Returns:
2021 * None
2023 * Side effects:
2024 * Window size and position are changed and client window receives
2025 * a ConfigureNotify event.
2026 *----------------------------------------------------------------------
2028 void
2029 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2030 WWindow *wwin;
2031 int req_x, req_y; /* new position of the frame */
2032 int req_width, req_height; /* new size of the client */
2034 int synth_notify = False;
2035 int resize;
2037 resize = (req_width!=wwin->client.width
2038 || req_height!=wwin->client.height);
2040 * if the window is being moved but not resized then
2041 * send a synthetic ConfigureNotify
2043 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2044 synth_notify = True;
2047 if (WFLAGP(wwin, dont_move_off))
2048 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2049 req_width, req_height);
2050 if (resize) {
2051 if (req_width < MIN_WINDOW_SIZE)
2052 req_width = MIN_WINDOW_SIZE;
2053 if (req_height < MIN_WINDOW_SIZE)
2054 req_height = MIN_WINDOW_SIZE;
2056 /* If growing, resize inner part before frame,
2057 * if shrinking, resize frame before.
2058 * This will prevent the frame (that can have a different color)
2059 * to be exposed, causing flicker */
2060 if (req_height > wwin->frame->core->height
2061 || req_width > wwin->frame->core->width)
2062 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2064 if (wwin->flags.shaded) {
2065 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2066 req_width, wwin->frame->core->height);
2067 wwin->old_geometry.height = req_height;
2068 } else {
2069 int h;
2071 h = req_height + wwin->frame->top_width
2072 + wwin->frame->bottom_width;
2074 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2077 if (!(req_height > wwin->frame->core->height
2078 || req_width > wwin->frame->core->width))
2079 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2081 wwin->client.x = req_x;
2082 wwin->client.y = req_y + wwin->frame->top_width;
2083 wwin->client.width = req_width;
2084 wwin->client.height = req_height;
2085 } else {
2086 wwin->client.x = req_x;
2087 wwin->client.y = req_y + wwin->frame->top_width;
2089 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2091 wwin->frame_x = req_x;
2092 wwin->frame_y = req_y;
2093 if (!WFLAGP(wwin, no_border)) {
2094 wwin->client.x += FRAME_BORDER_WIDTH;
2095 wwin->client.y += FRAME_BORDER_WIDTH;
2098 #ifdef SHAPE
2099 if (wShapeSupported && wwin->flags.shaped && resize) {
2100 wWindowSetShape(wwin);
2102 #endif
2104 if (synth_notify)
2105 wWindowSynthConfigureNotify(wwin);
2106 XFlush(dpy);
2110 void
2111 wWindowMove(wwin, req_x, req_y)
2112 WWindow *wwin;
2113 int req_x, req_y; /* new position of the frame */
2115 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2116 int synth_notify = False;
2118 /* Send a synthetic ConfigureNotify event for every window movement. */
2119 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2120 synth_notify = True;
2122 #else
2123 /* A single synthetic ConfigureNotify event is sent at the end of
2124 * a completed (opaque) movement in moveres.c */
2125 #endif
2127 if (WFLAGP(wwin, dont_move_off))
2128 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2129 wwin->frame->core->width, wwin->frame->core->height);
2131 wwin->client.x = req_x;
2132 wwin->client.y = req_y + wwin->frame->top_width;
2133 if (!WFLAGP(wwin, no_border)) {
2134 wwin->client.x += FRAME_BORDER_WIDTH;
2135 wwin->client.y += FRAME_BORDER_WIDTH;
2138 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2140 wwin->frame_x = req_x;
2141 wwin->frame_y = req_y;
2143 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2144 if (synth_notify)
2145 wWindowSynthConfigureNotify(wwin);
2146 #endif
2150 void
2151 wWindowUpdateButtonImages(WWindow *wwin)
2153 WScreen *scr = wwin->screen_ptr;
2154 Pixmap pixmap, mask;
2155 WFrameWindow *fwin = wwin->frame;
2157 if (WFLAGP(wwin, no_titlebar))
2158 return;
2160 /* miniaturize button */
2162 if (!WFLAGP(wwin, no_miniaturize_button)) {
2163 if (wwin->wm_gnustep_attr
2164 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2165 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2167 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2168 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2169 } else {
2170 mask = None;
2173 if (fwin->lbutton_image
2174 && (fwin->lbutton_image->image != pixmap
2175 || fwin->lbutton_image->mask != mask)) {
2176 wPixmapDestroy(fwin->lbutton_image);
2177 fwin->lbutton_image = NULL;
2180 if (!fwin->lbutton_image) {
2181 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2182 fwin->lbutton_image->client_owned = 1;
2183 fwin->lbutton_image->client_owned_mask = 1;
2185 } else {
2186 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2187 wPixmapDestroy(fwin->lbutton_image);
2189 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2193 #ifdef XKB_BUTTON_HINT
2194 if (!WFLAGP(wwin, no_language_button)) {
2195 if (fwin->languagebutton_image &&
2196 !fwin->languagebutton_image->shared) {
2197 wPixmapDestroy(fwin->languagebutton_image);
2199 fwin->languagebutton_image =
2200 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2202 #endif
2204 /* close button */
2206 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2207 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2209 if (!WFLAGP(wwin, no_close_button)) {
2210 if (wwin->wm_gnustep_attr
2211 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2212 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2214 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2215 mask = wwin->wm_gnustep_attr->close_mask;
2216 else
2217 mask = None;
2219 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2220 || fwin->rbutton_image->mask != mask)) {
2221 wPixmapDestroy(fwin->rbutton_image);
2222 fwin->rbutton_image = NULL;
2225 if (!fwin->rbutton_image) {
2226 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2227 fwin->rbutton_image->client_owned = 1;
2228 fwin->rbutton_image->client_owned_mask = 1;
2231 } else if (WFLAGP(wwin, kill_close)) {
2233 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2234 wPixmapDestroy(fwin->rbutton_image);
2236 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2238 } else if (MGFLAGP(wwin, broken_close)) {
2240 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2241 wPixmapDestroy(fwin->rbutton_image);
2243 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2245 } else {
2247 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2248 wPixmapDestroy(fwin->rbutton_image);
2250 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2254 /* force buttons to be redrawn */
2255 fwin->flags.need_texture_change = 1;
2256 wFrameWindowPaint(fwin);
2261 *---------------------------------------------------------------------------
2262 * wWindowConfigureBorders--
2263 * Update window border configuration according to attribute flags.
2265 *---------------------------------------------------------------------------
2267 void
2268 wWindowConfigureBorders(WWindow *wwin)
2270 if (wwin->frame) {
2271 int flags;
2272 int newy, oldh;
2274 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2275 #ifdef XKB_BUTTON_HINT
2276 flags |= WFF_LANGUAGE_BUTTON;
2277 #endif
2278 if (!WFLAGP(wwin, no_titlebar))
2279 flags |= WFF_TITLEBAR;
2280 if (!WFLAGP(wwin, no_resizebar))
2281 flags |= WFF_RESIZEBAR;
2282 if (!WFLAGP(wwin, no_border))
2283 flags |= WFF_BORDER;
2284 if (wwin->flags.shaded)
2285 flags |= WFF_IS_SHADED;
2287 oldh = wwin->frame->top_width;
2288 wFrameWindowUpdateBorders(wwin->frame, flags);
2289 if (oldh != wwin->frame->top_width) {
2290 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2292 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2293 wWindowConfigure(wwin, wwin->frame_x, newy,
2294 wwin->client.width, wwin->client.height);
2297 flags = 0;
2298 if (!WFLAGP(wwin, no_miniaturize_button)
2299 && wwin->frame->flags.hide_left_button)
2300 flags |= WFF_LEFT_BUTTON;
2302 #ifdef XKB_BUTTON_HINT
2303 if (!WFLAGP(wwin, no_language_button)
2304 && wwin->frame->flags.hide_language_button)
2305 flags |= WFF_LANGUAGE_BUTTON;
2306 #endif
2308 if (!WFLAGP(wwin, no_close_button)
2309 && wwin->frame->flags.hide_right_button)
2310 flags |= WFF_RIGHT_BUTTON;
2312 if (flags!=0) {
2313 wWindowUpdateButtonImages(wwin);
2314 wFrameWindowShowButton(wwin->frame, flags);
2317 flags = 0;
2318 if (WFLAGP(wwin, no_miniaturize_button)
2319 && !wwin->frame->flags.hide_left_button)
2320 flags |= WFF_LEFT_BUTTON;
2322 #ifdef XKB_BUTTON_HINT
2323 if (WFLAGP(wwin, no_language_button)
2324 && !wwin->frame->flags.hide_language_button)
2325 flags |= WFF_LANGUAGE_BUTTON;
2326 #endif
2328 if (WFLAGP(wwin, no_close_button)
2329 && !wwin->frame->flags.hide_right_button)
2330 flags |= WFF_RIGHT_BUTTON;
2332 if (flags!=0)
2333 wFrameWindowHideButton(wwin->frame, flags);
2335 #ifdef SHAPE
2336 if (wShapeSupported && wwin->flags.shaped) {
2337 wWindowSetShape(wwin);
2339 #endif
2344 void
2345 wWindowSaveState(WWindow *wwin)
2347 CARD32 data[10];
2348 int i;
2350 memset(data, 0, sizeof(CARD32)*10);
2351 data[0] = wwin->frame->workspace;
2352 data[1] = wwin->flags.miniaturized;
2353 data[2] = wwin->flags.shaded;
2354 data[3] = wwin->flags.hidden;
2355 data[4] = wwin->flags.maximized;
2356 if (wwin->flags.maximized == 0) {
2357 data[5] = wwin->frame_x;
2358 data[6] = wwin->frame_y;
2359 data[7] = wwin->frame->core->width;
2360 data[8] = wwin->frame->core->height;
2361 } else {
2362 data[5] = wwin->old_geometry.x;
2363 data[6] = wwin->old_geometry.y;
2364 data[7] = wwin->old_geometry.width;
2365 data[8] = wwin->old_geometry.height;
2368 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2369 if (wwin->screen_ptr->shortcutWindows[i] &&
2370 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2371 data[9] |= 1<<i;
2373 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2374 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2375 (unsigned char *)data, 10);
2379 static int
2380 getSavedState(Window window, WSavedState **state)
2382 Atom type_ret;
2383 int fmt_ret;
2384 unsigned long nitems_ret;
2385 unsigned long bytes_after_ret;
2386 CARD32 *data;
2388 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2389 True, _XA_WINDOWMAKER_STATE,
2390 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2391 (unsigned char **)&data)!=Success || !data)
2392 return 0;
2394 *state = wmalloc(sizeof(WSavedState));
2396 (*state)->workspace = data[0];
2397 (*state)->miniaturized = data[1];
2398 (*state)->shaded = data[2];
2399 (*state)->hidden = data[3];
2400 (*state)->maximized = data[4];
2401 (*state)->x = data[5];
2402 (*state)->y = data[6];
2403 (*state)->w = data[7];
2404 (*state)->h = data[8];
2405 (*state)->window_shortcuts = data[9];
2407 XFree(data);
2409 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2410 return 1;
2411 else
2412 return 0;
2416 #ifdef SHAPE
2417 void
2418 wWindowClearShape(WWindow *wwin)
2420 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2421 0, wwin->frame->top_width, None, ShapeSet);
2422 XFlush(dpy);
2425 void
2426 wWindowSetShape(WWindow *wwin)
2428 XRectangle rect[2];
2429 int count;
2430 #ifdef OPTIMIZE_SHAPE
2431 XRectangle *rects;
2432 XRectangle *urec;
2433 int ordering;
2435 /* only shape is the client's */
2436 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2437 goto alt_code;
2440 /* Get array of rectangles describing the shape mask */
2441 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2442 &count, &ordering);
2443 if (!rects) {
2444 goto alt_code;
2447 urec = malloc(sizeof(XRectangle)*(count+2));
2448 if (!urec) {
2449 XFree(rects);
2450 goto alt_code;
2453 /* insert our decoration rectangles in the rect list */
2454 memcpy(urec, rects, sizeof(XRectangle)*count);
2455 XFree(rects);
2457 if (!WFLAGP(wwin, no_titlebar)) {
2458 urec[count].x = -1;
2459 urec[count].y = -1 - wwin->frame->top_width;
2460 urec[count].width = wwin->frame->core->width + 2;
2461 urec[count].height = wwin->frame->top_width + 1;
2462 count++;
2464 if (!WFLAGP(wwin, no_resizebar)) {
2465 urec[count].x = -1;
2466 urec[count].y = wwin->frame->core->height
2467 - wwin->frame->bottom_width - wwin->frame->top_width;
2468 urec[count].width = wwin->frame->core->width + 2;
2469 urec[count].height = wwin->frame->bottom_width + 1;
2470 count++;
2473 /* shape our frame window */
2474 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2475 0, wwin->frame->top_width, urec, count,
2476 ShapeSet, Unsorted);
2477 XFlush(dpy);
2478 wfree(urec);
2479 return;
2481 alt_code:
2482 #endif /* OPTIMIZE_SHAPE */
2483 count = 0;
2484 if (!WFLAGP(wwin, no_titlebar)) {
2485 rect[count].x = -1;
2486 rect[count].y = -1;
2487 rect[count].width = wwin->frame->core->width + 2;
2488 rect[count].height = wwin->frame->top_width + 1;
2489 count++;
2491 if (!WFLAGP(wwin, no_resizebar)) {
2492 rect[count].x = -1;
2493 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2494 rect[count].width = wwin->frame->core->width + 2;
2495 rect[count].height = wwin->frame->bottom_width + 1;
2496 count++;
2498 if (count > 0) {
2499 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2500 0, 0, rect, count, ShapeSet, Unsorted);
2502 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2503 0, wwin->frame->top_width, wwin->client_win,
2504 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2505 XFlush(dpy);
2507 #endif /* SHAPE */
2509 /* ====================================================================== */
2511 static FocusMode
2512 getFocusMode(WWindow *wwin)
2514 FocusMode mode;
2516 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2517 if (wwin->wm_hints->input == True) {
2518 if (wwin->protocols.TAKE_FOCUS)
2519 mode = WFM_LOCALLY_ACTIVE;
2520 else
2521 mode = WFM_PASSIVE;
2522 } else {
2523 if (wwin->protocols.TAKE_FOCUS)
2524 mode = WFM_GLOBALLY_ACTIVE;
2525 else
2526 mode = WFM_NO_INPUT;
2528 } else {
2529 mode = WFM_PASSIVE;
2531 return mode;
2535 void
2536 wWindowSetKeyGrabs(WWindow *wwin)
2538 int i;
2539 WShortKey *key;
2541 for (i=0; i<WKBD_LAST; i++) {
2542 key = &wKeyBindings[i];
2544 if (key->keycode==0)
2545 continue;
2546 if (key->modifier!=AnyModifier) {
2547 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2548 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2549 #ifdef NUMLOCK_HACK
2550 /* Also grab all modifier combinations possible that include,
2551 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2552 * work even if the NumLock/ScrollLock key is on.
2554 wHackedGrabKey(key->keycode, key->modifier,
2555 wwin->frame->core->window, True, GrabModeAsync,
2556 GrabModeAsync);
2557 #endif
2559 XGrabKey(dpy, key->keycode, key->modifier,
2560 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2563 #ifndef LITE
2564 wRootMenuBindShortcuts(wwin->frame->core->window);
2565 #endif
2570 void
2571 wWindowResetMouseGrabs(WWindow *wwin)
2573 /* Mouse grabs can't be done on the client window because of
2574 * ICCCM and because clients that try to do the same will crash.
2576 * But there is a problem wich makes tbar buttons of unfocused
2577 * windows not usable as the click goes to the frame window instead
2578 * of the button itself. Must figure a way to fix that.
2581 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2583 if (!WFLAGP(wwin, no_bind_mouse)) {
2584 /* grabs for Meta+drag */
2585 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2586 True, ButtonPressMask, GrabModeSync,
2587 GrabModeAsync, None, None);
2590 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2591 && !wwin->flags.is_gnustep) {
2592 /* the passive grabs to focus the window */
2593 /* if (wPreferences.focus_mode == WKF_CLICK) */
2594 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2595 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2596 None, None);
2598 XFlush(dpy);
2602 void
2603 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2605 if (attr->flags & GSExtraFlagsAttr) {
2606 if (MGFLAGP(wwin, broken_close) !=
2607 (attr->extra_flags & GSDocumentEditedFlag)) {
2608 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2609 wWindowUpdateButtonImages(wwin);
2615 WMagicNumber
2616 wWindowAddSavedState(char *instance, char *class, char *command,
2617 pid_t pid, WSavedState *state)
2619 WWindowState *wstate;
2621 wstate = malloc(sizeof(WWindowState));
2622 if (!wstate)
2623 return 0;
2625 memset(wstate, 0, sizeof(WWindowState));
2626 wstate->pid = pid;
2627 if (instance)
2628 wstate->instance = wstrdup(instance);
2629 if (class)
2630 wstate->class = wstrdup(class);
2631 if (command)
2632 wstate->command = wstrdup(command);
2633 wstate->state = state;
2635 wstate->next = windowState;
2636 windowState = wstate;
2638 #ifdef DEBUG
2639 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2640 class, command);
2641 #endif
2643 return wstate;
2647 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2650 WMagicNumber
2651 wWindowGetSavedState(Window win)
2653 char *instance, *class, *command=NULL;
2654 WWindowState *wstate = windowState;
2655 char **argv;
2656 int argc;
2658 if (!wstate)
2659 return NULL;
2661 if (XGetCommand(dpy, win, &argv, &argc)) {
2662 if (argc > 0)
2663 command = wtokenjoin(argv, argc);
2664 XFreeStringList(argv);
2666 if (!command)
2667 return NULL;
2669 if (PropGetWMClass(win, &class, &instance)) {
2670 while (wstate) {
2671 if (SAME(instance, wstate->instance) &&
2672 SAME(class, wstate->class) &&
2673 SAME(command, wstate->command)) {
2674 break;
2676 wstate = wstate->next;
2678 } else {
2679 wstate = NULL;
2682 #ifdef DEBUG
2683 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2684 class, command);
2685 #endif
2687 if (command) wfree(command);
2688 if (instance) XFree(instance);
2689 if (class) XFree(class);
2691 return wstate;
2695 void
2696 wWindowDeleteSavedState(WMagicNumber id)
2698 WWindowState *tmp, *wstate=(WWindowState*)id;
2700 if (!wstate || !windowState)
2701 return;
2703 tmp = windowState;
2704 if (tmp==wstate) {
2705 windowState = wstate->next;
2706 #ifdef DEBUG
2707 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2708 wstate, wstate->instance, wstate->class, wstate->command);
2709 #endif
2710 if (wstate->instance) wfree(wstate->instance);
2711 if (wstate->class) wfree(wstate->class);
2712 if (wstate->command) wfree(wstate->command);
2713 wfree(wstate->state);
2714 wfree(wstate);
2715 } else {
2716 while (tmp->next) {
2717 if (tmp->next==wstate) {
2718 tmp->next=wstate->next;
2719 #ifdef DEBUG
2720 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2721 wstate, wstate->instance, wstate->class, wstate->command);
2722 #endif
2723 if (wstate->instance) wfree(wstate->instance);
2724 if (wstate->class) wfree(wstate->class);
2725 if (wstate->command) wfree(wstate->command);
2726 wfree(wstate->state);
2727 wfree(wstate);
2728 break;
2730 tmp = tmp->next;
2736 void
2737 wWindowDeleteSavedStatesForPID(pid_t pid)
2739 WWindowState *tmp, *wstate;
2741 if (!windowState)
2742 return;
2744 tmp = windowState;
2745 if (tmp->pid == pid) {
2746 wstate = windowState;
2747 windowState = tmp->next;
2748 #ifdef DEBUG
2749 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2750 wstate, wstate->instance, wstate->class, wstate->command);
2751 #endif
2752 if (wstate->instance) wfree(wstate->instance);
2753 if (wstate->class) wfree(wstate->class);
2754 if (wstate->command) wfree(wstate->command);
2755 wfree(wstate->state);
2756 wfree(wstate);
2757 } else {
2758 while (tmp->next) {
2759 if (tmp->next->pid==pid) {
2760 wstate = tmp->next;
2761 tmp->next = wstate->next;
2762 #ifdef DEBUG
2763 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2764 wstate, wstate->instance, wstate->class, wstate->command);
2765 #endif
2766 if (wstate->instance) wfree(wstate->instance);
2767 if (wstate->class) wfree(wstate->class);
2768 if (wstate->command) wfree(wstate->command);
2769 wfree(wstate->state);
2770 wfree(wstate);
2771 break;
2773 tmp = tmp->next;
2779 void
2780 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2782 wwin->flags.omnipresent = flag;
2784 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2788 /* ====================================================================== */
2790 static void
2791 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2793 WWindow *wwin = data;
2795 #ifndef NUMLOCK_HACK
2796 if ((event->xbutton.state & ValidModMask)
2797 != (event->xbutton.state & ~LockMask)) {
2798 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2799 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2801 #endif
2803 event->xbutton.state &= ValidModMask;
2805 CloseWindowMenu(wwin->screen_ptr);
2807 if (wPreferences.focus_mode==WKF_CLICK
2808 && !(event->xbutton.state&ControlMask)
2809 && !WFLAGP(wwin, no_focusable)) {
2810 wSetFocusTo(wwin->screen_ptr, wwin);
2813 if (event->xbutton.button == Button1)
2814 wRaiseFrame(wwin->frame->core);
2816 if (event->xbutton.window != wwin->frame->resizebar->window) {
2817 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2818 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2819 GrabModeAsync, GrabModeAsync, None,
2820 None, CurrentTime)!=GrabSuccess) {
2821 #ifdef DEBUG0
2822 wwarning("pointer grab failed for window move");
2823 #endif
2824 return;
2828 if (event->xbutton.state & MOD_MASK) {
2829 /* move the window */
2830 wMouseMoveWindow(wwin, event);
2831 XUngrabPointer(dpy, CurrentTime);
2832 } else {
2833 wMouseResizeWindow(wwin, event);
2834 XUngrabPointer(dpy, CurrentTime);
2840 static void
2841 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2843 WWindow *wwin = data;
2845 event->xbutton.state &= ValidModMask;
2847 if (event->xbutton.button==Button1) {
2848 if (event->xbutton.state == 0) {
2849 if (!WFLAGP(wwin, no_shadeable)) {
2850 /* shade window */
2851 if (wwin->flags.shaded)
2852 wUnshadeWindow(wwin);
2853 else
2854 wShadeWindow(wwin);
2856 } else {
2857 int dir = 0;
2859 if (event->xbutton.state & ControlMask)
2860 dir |= MAX_VERTICAL;
2862 if (event->xbutton.state & ShiftMask) {
2863 dir |= MAX_HORIZONTAL;
2864 if (!(event->xbutton.state & ControlMask))
2865 wSelectWindow(wwin, !wwin->flags.selected);
2868 /* maximize window */
2869 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
2870 int ndir = dir ^ wwin->flags.maximized;
2871 if (wwin->flags.maximized != 0)
2872 wUnmaximizeWindow(wwin);
2873 if (ndir != 0)
2874 wMaximizeWindow(wwin, ndir);
2877 } else if (event->xbutton.button==Button3) {
2878 if (event->xbutton.state & MOD_MASK) {
2879 wHideOtherApplications(wwin);
2881 } else if (event->xbutton.button==Button2) {
2882 wSelectWindow(wwin, !wwin->flags.selected);
2883 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2884 wShadeWindow(wwin);
2885 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2886 wUnshadeWindow(wwin);
2891 static void
2892 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2894 WWindow *wwin = desc->parent;
2896 event->xbutton.state &= ValidModMask;
2898 CloseWindowMenu(wwin->screen_ptr);
2900 if (/*wPreferences.focus_mode==WKF_CLICK
2901 &&*/ !(event->xbutton.state&ControlMask)
2902 && !WFLAGP(wwin, no_focusable)) {
2903 wSetFocusTo(wwin->screen_ptr, wwin);
2905 if (event->xbutton.button == Button1) {
2906 wRaiseFrame(wwin->frame->core);
2909 if (event->xbutton.state & MOD_MASK) {
2910 /* move the window */
2911 if (XGrabPointer(dpy, wwin->client_win, False,
2912 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2913 GrabModeAsync, GrabModeAsync, None,
2914 None, CurrentTime)!=GrabSuccess) {
2915 #ifdef DEBUG0
2916 wwarning("pointer grab failed for window move");
2917 #endif
2918 return;
2920 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2921 wMouseResizeWindow(wwin, event);
2922 else
2923 wMouseMoveWindow(wwin, event);
2924 XUngrabPointer(dpy, CurrentTime);
2929 static void
2930 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2932 WWindow *wwin = (WWindow*)data;
2934 #ifndef NUMLOCK_HACK
2935 if ((event->xbutton.state & ValidModMask)
2936 != (event->xbutton.state & ~LockMask)) {
2937 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2938 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2940 #endif
2941 event->xbutton.state &= ValidModMask;
2943 CloseWindowMenu(wwin->screen_ptr);
2945 if (wPreferences.focus_mode==WKF_CLICK
2946 && !(event->xbutton.state&ControlMask)
2947 && !WFLAGP(wwin, no_focusable)) {
2948 wSetFocusTo(wwin->screen_ptr, wwin);
2951 if (event->xbutton.button == Button1
2952 || event->xbutton.button == Button2) {
2954 if (event->xbutton.button == Button1) {
2955 if (event->xbutton.state & MOD_MASK) {
2956 wLowerFrame(wwin->frame->core);
2957 } else {
2958 wRaiseFrame(wwin->frame->core);
2961 if ((event->xbutton.state & ShiftMask)
2962 && !(event->xbutton.state & ControlMask)) {
2963 wSelectWindow(wwin, !wwin->flags.selected);
2964 return;
2966 if (event->xbutton.window != wwin->frame->titlebar->window
2967 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2968 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2969 GrabModeAsync, GrabModeAsync, None,
2970 None, CurrentTime)!=GrabSuccess) {
2971 #ifdef DEBUG0
2972 wwarning("pointer grab failed for window move");
2973 #endif
2974 return;
2977 /* move the window */
2978 wMouseMoveWindow(wwin, event);
2980 XUngrabPointer(dpy, CurrentTime);
2981 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2982 && !wwin->flags.internal_window
2983 && !WCHECK_STATE(WSTATE_MODAL)) {
2984 WObjDescriptor *desc;
2986 if (event->xbutton.window != wwin->frame->titlebar->window
2987 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2988 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2989 GrabModeAsync, GrabModeAsync, None,
2990 None, CurrentTime)!=GrabSuccess) {
2991 #ifdef DEBUG0
2992 wwarning("pointer grab failed for window move");
2993 #endif
2994 return;
2997 OpenWindowMenu(wwin, event->xbutton.x_root,
2998 wwin->frame_y+wwin->frame->top_width, False);
3000 /* allow drag select */
3001 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3002 event->xany.send_event = True;
3003 (*desc->handle_mousedown)(desc, event);
3005 XUngrabPointer(dpy, CurrentTime);
3011 static void
3012 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3014 WWindow *wwin = data;
3016 event->xbutton.state &= ValidModMask;
3018 CloseWindowMenu(wwin->screen_ptr);
3020 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3021 return;
3023 /* if control-click, kill the client */
3024 if (event->xbutton.state & ControlMask) {
3025 wClientKill(wwin);
3026 } else {
3027 #ifdef OLWM_HINTS
3028 if (wwin->flags.olwm_push_pin_out) {
3030 wwin->flags.olwm_push_pin_out = 0;
3032 wOLWMChangePushpinState(wwin, True);
3034 wFrameWindowUpdatePushButton(wwin->frame, False);
3036 return;
3038 #endif
3039 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3040 /* send delete message */
3041 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3047 static void
3048 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3050 WWindow *wwin = data;
3052 CloseWindowMenu(wwin->screen_ptr);
3054 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3055 return;
3057 /* send delete message */
3058 if (wwin->protocols.DELETE_WINDOW) {
3059 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3060 } else {
3061 wClientKill(wwin);
3066 #ifdef XKB_BUTTON_HINT
3067 static void
3068 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3070 WWindow *wwin = data;
3071 WFrameWindow *fwin = wwin->frame;
3072 WScreen *scr = fwin->screen_ptr;
3073 XkbStateRec staterec;
3074 int tl;
3076 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3077 return;
3078 tl = wwin->frame->languagemode;
3079 wwin->frame->languagemode = wwin->frame->last_languagemode;
3080 wwin->frame->last_languagemode = tl;
3081 wSetFocusTo(scr, wwin);
3082 wwin->frame->languagebutton_image =
3083 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3084 wwin->frame->languagemode];
3085 wFrameWindowUpdateLanguageButton(wwin->frame);
3086 if (event->xbutton.button == Button3)
3087 return;
3088 wRaiseFrame(fwin->core);
3090 #endif
3093 static void
3094 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3096 WWindow *wwin = data;
3098 event->xbutton.state &= ValidModMask;
3100 CloseWindowMenu(wwin->screen_ptr);
3102 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3103 return;
3105 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3106 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3107 LastTimestamp);
3108 } else {
3109 WApplication *wapp;
3110 if ((event->xbutton.state & ControlMask) ||
3111 (event->xbutton.button == Button3)) {
3113 wapp = wApplicationOf(wwin->main_window);
3114 if (wapp && !WFLAGP(wwin, no_appicon))
3115 wHideApplication(wapp);
3116 } else if (event->xbutton.state==0) {
3117 wIconifyWindow(wwin);