fixed a bug introduced by the previous commit
[wmaker-crm.git] / src / window.c
blobbc880b3d591778a7c102948fa05a81713225a99f
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;
569 Bool raise = False;
571 /* mutex. */
572 /* XGrabServer(dpy); */
573 XSync(dpy, False);
574 /* make sure the window is still there */
575 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
576 XUngrabServer(dpy);
577 return NULL;
580 /* if it's an override-redirect, ignore it */
581 if (wattribs.override_redirect) {
582 XUngrabServer(dpy);
583 return NULL;
586 wm_state = PropGetWindowState(window);
588 /* if it's startup and the window is unmapped, don't manage it */
589 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
590 XUngrabServer(dpy);
591 return NULL;
594 if (!wFetchName(dpy, window, &title)) {
595 title = NULL;
598 #ifdef KWM_HINTS
599 if (title && !wKWMManageableClient(scr, window, title)) {
600 XFree(title);
601 XUngrabServer(dpy);
602 return NULL;
604 #endif /* KWM_HINTS */
607 wwin = wWindowCreate();
609 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
611 #ifdef DEBUG
612 printf("managing window %x\n", (unsigned)window);
613 #endif
615 #ifdef SHAPE
616 if (wShapeSupported) {
617 int junk;
618 unsigned int ujunk;
619 int b_shaped;
621 XShapeSelectInput(dpy, window, ShapeNotifyMask);
622 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
623 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
624 wwin->flags.shaped = b_shaped;
626 #endif
629 *--------------------------------------------------
631 * Get hints and other information in properties
633 *--------------------------------------------------
635 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
637 /* setup descriptor */
638 wwin->client_win = window;
639 wwin->screen_ptr = scr;
641 wwin->old_border_width = wattribs.border_width;
643 wwin->event_mask = CLIENT_EVENTS;
644 attribs.event_mask = CLIENT_EVENTS;
645 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
646 attribs.save_under = False;
647 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
648 |CWSaveUnder, &attribs);
649 XSetWindowBorderWidth(dpy, window, 0);
651 /* get hints from GNUstep app */
652 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
653 wwin->flags.is_gnustep = 1;
655 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
656 wwin->wm_gnustep_attr = NULL;
659 wwin->client_leader = PropGetClientLeader(window);
660 if (wwin->client_leader!=None)
661 wwin->main_window = wwin->client_leader;
663 wwin->wm_hints = XGetWMHints(dpy, window);
665 if (wwin->wm_hints) {
666 if (wwin->wm_hints->flags & StateHint) {
668 if (wwin->wm_hints->initial_state == IconicState) {
670 wwin->flags.miniaturized = 1;
672 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
674 withdraw = True;
678 if (wwin->wm_hints->flags & WindowGroupHint) {
679 wwin->group_id = wwin->wm_hints->window_group;
680 /* window_group has priority over CLIENT_LEADER */
681 wwin->main_window = wwin->group_id;
682 } else {
683 wwin->group_id = None;
686 if (wwin->wm_hints->flags & UrgencyHint)
687 wwin->flags.urgent = 1;
688 } else {
689 wwin->group_id = None;
692 PropGetProtocols(window, &wwin->protocols);
694 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
695 wwin->transient_for = None;
696 } else {
697 if (wwin->transient_for==None || wwin->transient_for==window) {
698 wwin->transient_for = scr->root_win;
699 } else {
700 transientOwner = wWindowFor(wwin->transient_for);
701 if (transientOwner && transientOwner->main_window!=None) {
702 wwin->main_window = transientOwner->main_window;
703 } /*else {
704 wwin->main_window = None;
709 /* guess the focus mode */
710 wwin->focus_mode = getFocusMode(wwin);
712 /* get geometry stuff */
713 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
715 /* get colormap windows */
716 GetColormapWindows(wwin);
719 *--------------------------------------------------
721 * Setup the decoration/window attributes and
722 * geometry
724 *--------------------------------------------------
727 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
729 #ifdef OLWM_HINTS
730 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
731 && wwin->group_id != None && wwin->group_id != window) {
733 transientOwner = wWindowFor(wwin->group_id);
735 if (transientOwner) {
736 wwin->transient_for = wwin->group_id;
738 /* transients can't be iconified or maximized */
739 if (wwin->transient_for) {
740 WSETUFLAG(wwin, no_miniaturizable, 1);
741 WSETUFLAG(wwin, no_miniaturize_button, 1);
745 #endif /* OLWM_HINTS */
748 * Make broken apps behave as a nice app.
750 if (WFLAGP(wwin, emulate_appicon)) {
751 wwin->main_window = wwin->client_win;
755 *------------------------------------------------------------
757 * Setup the initial state of the window
759 *------------------------------------------------------------
762 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
763 wwin->flags.miniaturized = 1;
766 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
767 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
771 Bool bla;
773 bla = False;
774 #ifdef GNOME_STUFF
775 bla = wGNOMECheckInitialClientState(wwin);
776 #endif
777 #ifdef KWM_HINTS
778 if (!bla)
779 wKWMCheckClientInitialState(wwin);
780 #endif
783 /* apply previous state if it exists and we're in startup */
784 if (scr->flags.startup && wm_state >= 0) {
786 if (wm_state == IconicState) {
788 wwin->flags.miniaturized = 1;
790 } else if (wm_state == WithdrawnState) {
792 withdraw = True;
796 /* if there is a saved state (from file), restore it */
797 win_state = NULL;
798 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
799 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
800 } else {
801 win_state = (WWindowState*)wWindowGetSavedState(window);
803 if (win_state && !withdraw) {
805 if (win_state->state->hidden>0)
806 wwin->flags.hidden = win_state->state->hidden;
808 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
809 wwin->flags.shaded = win_state->state->shaded;
811 if (win_state->state->miniaturized>0 &&
812 !WFLAGP(wwin, no_miniaturizable)) {
813 wwin->flags.miniaturized = win_state->state->miniaturized;
816 if (!IS_OMNIPRESENT(wwin)) {
817 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
818 wwin->wm_class);
819 if (w < 0 || w >= scr->workspace_count) {
820 workspace = win_state->state->workspace;
821 if (workspace >= scr->workspace_count)
822 workspace = scr->current_workspace;
823 } else {
824 workspace = w;
826 } else {
827 workspace = scr->current_workspace;
831 /* if we're restarting, restore saved state (from hints).
832 * This will overwrite previous */
834 WSavedState *wstate;
836 if (getSavedState(window, &wstate)) {
837 wwin->flags.shaded = wstate->shaded;
838 wwin->flags.hidden = wstate->hidden;
839 wwin->flags.miniaturized = wstate->miniaturized;
840 wwin->flags.maximized = wstate->maximized;
841 if (wwin->flags.maximized) {
842 wwin->old_geometry.x = wstate->x;
843 wwin->old_geometry.y = wstate->y;
844 wwin->old_geometry.width = wstate->w;
845 wwin->old_geometry.height = wstate->h;
848 workspace = wstate->workspace;
849 } else {
850 wstate = NULL;
853 /* restore window shortcut */
854 if (wstate != NULL || win_state != NULL) {
855 unsigned mask = 0;
857 if (win_state != NULL)
858 mask = win_state->state->window_shortcuts;
860 if (wstate != NULL && mask == 0)
861 mask = wstate->window_shortcuts;
863 if (mask > 0) {
864 int i;
866 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
867 if (mask & (1<<i)) {
868 if (!scr->shortcutWindows[i])
869 scr->shortcutWindows[i] = WMCreateArray(4);
871 WMAddToArray(scr->shortcutWindows[i], wwin);
876 if (wstate != NULL) {
877 wfree(wstate);
881 /* don't let transients start miniaturized if their owners are not */
882 if (transientOwner && !transientOwner->flags.miniaturized
883 && wwin->flags.miniaturized && !withdraw) {
884 wwin->flags.miniaturized = 0;
885 if (wwin->wm_hints)
886 wwin->wm_hints->initial_state = NormalState;
889 /* set workspace on which the window starts */
890 if (workspace >= 0) {
891 if (workspace > scr->workspace_count-1) {
892 workspace = workspace % scr->workspace_count;
894 } else {
895 int w;
897 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
899 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
901 workspace = w;
903 } else {
904 if (wPreferences.open_transients_with_parent && transientOwner) {
906 workspace = transientOwner->frame->workspace;
908 } else {
910 workspace = scr->current_workspace;
915 /* setup window geometry */
916 if (win_state && win_state->state->w > 0) {
917 width = win_state->state->w;
918 height = win_state->state->h;
920 wWindowConstrainSize(wwin, &width, &height);
922 /* do not ask for window placement if the window is
923 * transient, during startup, if the initial workspace is another one
924 * or if the window wants to start iconic.
925 * If geometry was saved, restore it. */
927 Bool dontBring = False;
929 if (win_state && win_state->state->w > 0) {
930 x = win_state->state->x;
931 y = win_state->state->y;
932 } else if ((wwin->transient_for==None
933 || wPreferences.window_placement!=WPM_MANUAL)
934 && !scr->flags.startup
935 && workspace == scr->current_workspace
936 && !wwin->flags.miniaturized
937 && !wwin->flags.maximized
938 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
940 if (transientOwner && transientOwner->flags.mapped) {
941 int offs = WMAX(20, 2*transientOwner->frame->top_width);
943 x = transientOwner->frame_x +
944 abs((transientOwner->frame->core->width - width)/2) + offs;
945 y = transientOwner->frame_y +
946 abs((transientOwner->frame->core->height - height)/3) + offs;
948 if (x < 0)
949 x = 0;
950 else if (x + width > scr->scr_width)
951 x = scr->scr_width - width;
953 if (y < 0)
954 y = 0;
955 else if (y + height > scr->scr_height)
956 y = scr->scr_height - height;
957 } else {
958 PlaceWindow(wwin, &x, &y, width, height);
960 if (wPreferences.window_placement == WPM_MANUAL)
961 dontBring = True;
964 if (WFLAGP(wwin, dont_move_off) && dontBring)
965 wScreenBringInside(scr, &x, &y, width, height);
968 if (wwin->flags.urgent) {
969 if (!IS_OMNIPRESENT(wwin))
970 wwin->flags.omnipresent ^= 1;
974 *--------------------------------------------------
976 * Create frame, borders and do reparenting
978 *--------------------------------------------------
980 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
981 #ifdef XKB_BUTTON_HINT
982 if (wPreferences.modelock)
983 foo |= WFF_LANGUAGE_BUTTON;
984 #endif
985 if (!WFLAGP(wwin, no_titlebar))
986 foo |= WFF_TITLEBAR;
987 if (!WFLAGP(wwin, no_resizebar))
988 foo |= WFF_RESIZEBAR;
989 if (!WFLAGP(wwin, no_border))
990 foo |= WFF_BORDER;
992 wwin->frame = wFrameWindowCreate(scr, window_level,
993 x, y, width, height,
994 &wPreferences.window_title_clearance, foo,
995 scr->window_title_texture,
996 scr->resizebar_texture,
997 scr->window_title_pixel,
998 &scr->window_title_gc,
999 &scr->title_font);
1001 wwin->frame->flags.is_client_window_frame = 1;
1002 wwin->frame->flags.justification = wPreferences.title_justification;
1004 /* setup button images */
1005 wWindowUpdateButtonImages(wwin);
1007 /* hide unused buttons */
1008 foo = 0;
1009 if (WFLAGP(wwin, no_close_button))
1010 foo |= WFF_RIGHT_BUTTON;
1011 if (WFLAGP(wwin, no_miniaturize_button))
1012 foo |= WFF_LEFT_BUTTON;
1013 #ifdef XKB_BUTTON_HINT
1014 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1015 foo |= WFF_LANGUAGE_BUTTON;
1016 #endif
1017 if (foo!=0)
1018 wFrameWindowHideButton(wwin->frame, foo);
1020 wwin->frame->child = wwin;
1022 #ifdef OLWM_HINTS
1023 /* emulate olwm push pin. Make the button look as pushed-in for
1024 * the pinned-out state. When the button is clicked, it will
1025 * revert to the normal position, which means the pin is pinned-in.
1027 if (wwin->flags.olwm_push_pin_out)
1028 wFrameWindowUpdatePushButton(wwin->frame, True);
1029 #endif /* OLWM_HINTS */
1032 wwin->frame->workspace = workspace;
1034 wwin->frame->on_click_left = windowIconifyClick;
1035 #ifdef XKB_BUTTON_HINT
1036 if (wPreferences.modelock)
1037 wwin->frame->on_click_language = windowLanguageClick;
1038 #endif
1040 wwin->frame->on_click_right = windowCloseClick;
1041 wwin->frame->on_dblclick_right = windowCloseDblClick;
1043 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1044 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1046 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1049 XSelectInput(dpy, wwin->client_win,
1050 wwin->event_mask & ~StructureNotifyMask);
1052 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1053 0, wwin->frame->top_width);
1055 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1059 int gx, gy;
1061 wClientGetGravityOffsets(wwin, &gx, &gy);
1063 /* if gravity is to the south, account for the border sizes */
1064 if (gy > 0)
1065 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1069 * wWindowConfigure() will init the client window's size
1070 * (wwin->client.{width,height}) and all other geometry
1071 * related variables (frame_x,frame_y)
1073 wWindowConfigure(wwin, x, y, width, height);
1075 /* to make sure the window receives it's new position after reparenting */
1076 wWindowSynthConfigureNotify(wwin);
1079 *--------------------------------------------------
1081 * Setup descriptors and save window to internal
1082 * lists
1084 *--------------------------------------------------
1087 if (wwin->main_window!=None) {
1088 WApplication *app;
1089 WWindow *leader;
1091 /* Leader windows do not necessary set themselves as leaders.
1092 * If this is the case, point the leader of this window to
1093 * itself */
1094 leader = wWindowFor(wwin->main_window);
1095 if (leader && leader->main_window==None) {
1096 leader->main_window = leader->client_win;
1098 app = wApplicationCreate(scr, wwin->main_window);
1099 if (app) {
1100 app->last_workspace = workspace;
1103 * Do application specific stuff, like setting application
1104 * wide attributes.
1107 if (wwin->flags.hidden) {
1108 /* if the window was set to hidden because it was hidden
1109 * in a previous incarnation and that state was restored */
1110 app->flags.hidden = 1;
1111 } else if (app->flags.hidden) {
1112 if (WFLAGP(app->main_window_desc, start_hidden)) {
1113 wwin->flags.hidden = 1;
1114 } else {
1115 wUnhideApplication(app, False, False);
1116 raise = True;
1122 /* setup the frame descriptor */
1123 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1124 wwin->frame->core->descriptor.parent = wwin;
1125 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1127 /* don't let windows go away if we die */
1128 XAddToSaveSet(dpy, window);
1130 XLowerWindow(dpy, window);
1132 /* if window is in this workspace and should be mapped, then map it */
1133 if (!wwin->flags.miniaturized
1134 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1135 && !wwin->flags.hidden && !withdraw) {
1137 /* The following "if" is to avoid crashing of clients that expect
1138 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1139 * after the return from this function.
1141 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1142 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1143 } else {
1144 wClientSetState(wwin, NormalState, None);
1147 #if 0
1148 /* if not auto focus, then map the window under the currently
1149 * focused window */
1150 #define _WIDTH(w) (w)->frame->core->width
1151 #define _HEIGHT(w) (w)->frame->core->height
1152 if (!wPreferences.auto_focus && scr->focused_window
1153 && !scr->flags.startup && !transientOwner
1154 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1155 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1156 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1157 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1158 || wwin->flags.maximized)) {
1159 MoveInStackListUnder(scr->focused_window->frame->core,
1160 wwin->frame->core);
1162 #undef _WIDTH
1163 #undef _HEIGHT
1165 #endif
1167 if (wPreferences.superfluous && !wPreferences.no_animations
1168 && !scr->flags.startup && wwin->transient_for==None
1170 * The brain damaged idiotic non-click to focus modes will
1171 * have trouble with this because:
1173 * 1. window is created and mapped by the client
1174 * 2. window is mapped by wmaker in small size
1175 * 3. window is animated to grow to normal size
1176 * 4. this function returns to normal event loop
1177 * 5. eventually, the EnterNotify event that would trigger
1178 * the window focusing (if the mouse is over that window)
1179 * will be processed by wmaker.
1180 * But since this event will be rather delayed
1181 * (step 3 has a large delay) the time when the event ocurred
1182 * and when it is processed, the client that owns that window
1183 * will reject the XSetInputFocus() for it.
1185 && (wPreferences.focus_mode==WKF_CLICK
1186 || wPreferences.auto_focus)) {
1187 DoWindowBirth(wwin);
1190 wWindowMap(wwin);
1193 /* setup stacking descriptor */
1194 if (transientOwner) {
1195 /* && wPreferences.on_top_transients */
1196 if (transientOwner) {
1197 wwin->frame->core->stacking->child_of =
1198 transientOwner->frame->core;
1200 } else {
1201 wwin->frame->core->stacking->child_of = NULL;
1205 if (!scr->focused_window) {
1206 /* first window on the list */
1207 wwin->next = NULL;
1208 wwin->prev = NULL;
1209 scr->focused_window = wwin;
1210 } else {
1211 WWindow *tmp;
1213 /* add window at beginning of focus window list */
1214 tmp = scr->focused_window;
1215 while (tmp->prev)
1216 tmp = tmp->prev;
1217 tmp->prev = wwin;
1218 wwin->next = tmp;
1219 wwin->prev = NULL;
1222 /* raise is set to true if we un-hid the app when this window was born.
1223 * we raise, else old windows of this app will be above this new one. */
1224 if (raise) {
1225 wRaiseFrame(wwin->frame->core);
1228 /* Update name must come after WApplication stuff is done */
1229 wWindowUpdateName(wwin, title);
1230 if (title)
1231 XFree(title);
1233 XUngrabServer(dpy);
1236 *--------------------------------------------------
1238 * Final preparations before window is ready to go
1240 *--------------------------------------------------
1243 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1246 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1247 && !wwin->flags.hidden) {
1248 if (((transientOwner && transientOwner->flags.focused)
1249 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1250 wSetFocusTo(scr, wwin);
1252 wWindowResetMouseGrabs(wwin);
1254 if (!WFLAGP(wwin, no_bind_keys)) {
1255 wWindowSetKeyGrabs(wwin);
1259 WMPostNotificationName(WMNManaged, wwin, NULL);
1262 wColormapInstallForWindow(scr, scr->cmap_window);
1265 #ifdef OLWM_HINTS
1266 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1267 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1269 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1270 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1271 wwin->frame_y);
1273 #endif
1276 *------------------------------------------------------------
1277 * Setup Notification Observers
1278 *------------------------------------------------------------
1280 WMAddNotificationObserver(appearanceObserver, wwin,
1281 WNWindowAppearanceSettingsChanged, wwin);
1285 *--------------------------------------------------
1287 * Cleanup temporary stuff
1289 *--------------------------------------------------
1292 if (win_state)
1293 wWindowDeleteSavedState(win_state);
1295 /* If the window must be withdrawed, then do it now.
1296 * Must do some optimization, 'though */
1297 if (withdraw) {
1298 wwin->flags.mapped = 0;
1299 wClientSetState(wwin, WithdrawnState, None);
1300 wUnmanageWindow(wwin, True, False);
1301 wwin = NULL;
1304 return wwin;
1311 WWindow*
1312 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1313 char *title, int x, int y, int width, int height)
1315 WWindow *wwin;
1316 int foo;
1318 wwin = wWindowCreate();
1320 WMAddNotificationObserver(appearanceObserver, wwin,
1321 WNWindowAppearanceSettingsChanged, wwin);
1323 wwin->flags.internal_window = 1;
1325 WSETUFLAG(wwin, omnipresent, 1);
1326 WSETUFLAG(wwin, no_shadeable, 1);
1327 WSETUFLAG(wwin, no_resizable, 1);
1328 WSETUFLAG(wwin, no_miniaturizable, 1);
1330 wwin->focus_mode = WFM_PASSIVE;
1332 wwin->client_win = window;
1333 wwin->screen_ptr = scr;
1335 wwin->transient_for = owner;
1337 wwin->client.x = x;
1338 wwin->client.y = y;
1339 wwin->client.width = width;
1340 wwin->client.height = height;
1342 wwin->frame_x = wwin->client.x;
1343 wwin->frame_y = wwin->client.y;
1346 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1347 foo |= WFF_TITLEBAR;
1348 #ifdef XKB_BUTTON_HINT
1349 foo |= WFF_LANGUAGE_BUTTON;
1350 #endif
1352 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1353 wwin->frame_x, wwin->frame_y,
1354 width, height,
1355 &wPreferences.window_title_clearance, foo,
1356 scr->window_title_texture,
1357 scr->resizebar_texture,
1358 scr->window_title_pixel,
1359 &scr->window_title_gc,
1360 &scr->title_font);
1362 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1364 wwin->frame->flags.is_client_window_frame = 1;
1365 wwin->frame->flags.justification = wPreferences.title_justification;
1367 wFrameWindowChangeTitle(wwin->frame, title);
1369 /* setup button images */
1370 wWindowUpdateButtonImages(wwin);
1372 /* hide buttons */
1373 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1375 wwin->frame->child = wwin;
1377 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1379 #ifdef XKB_BUTTON_HINT
1380 if (wPreferences.modelock)
1381 wwin->frame->on_click_language = windowLanguageClick;
1382 #endif
1384 wwin->frame->on_click_right = windowCloseClick;
1386 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1387 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1389 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1391 wwin->client.y += wwin->frame->top_width;
1392 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1393 0, wwin->frame->top_width);
1395 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1396 wwin->client.width, wwin->client.height);
1398 /* setup the frame descriptor */
1399 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1400 wwin->frame->core->descriptor.parent = wwin;
1401 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1404 XLowerWindow(dpy, window);
1405 XMapSubwindows(dpy, wwin->frame->core->window);
1407 /* setup stacking descriptor */
1408 if (
1409 #ifdef removed
1410 wPreferences.on_top_transients &&
1411 #endif
1412 wwin->transient_for!=None
1413 && wwin->transient_for!=scr->root_win) {
1414 WWindow *tmp;
1415 tmp = wWindowFor(wwin->transient_for);
1416 if (tmp)
1417 wwin->frame->core->stacking->child_of = tmp->frame->core;
1418 } else {
1419 wwin->frame->core->stacking->child_of = NULL;
1423 if (!scr->focused_window) {
1424 /* first window on the list */
1425 wwin->next = NULL;
1426 wwin->prev = NULL;
1427 scr->focused_window = wwin;
1428 } else {
1429 WWindow *tmp;
1431 /* add window at beginning of focus window list */
1432 tmp = scr->focused_window;
1433 while (tmp->prev)
1434 tmp = tmp->prev;
1435 tmp->prev = wwin;
1436 wwin->next = tmp;
1437 wwin->prev = NULL;
1440 if (wwin->flags.is_gnustep == 0)
1441 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1443 /* if (wPreferences.auto_focus)*/
1444 wSetFocusTo(scr, wwin);
1446 wWindowResetMouseGrabs(wwin);
1448 wWindowSetKeyGrabs(wwin);
1450 return wwin;
1455 *----------------------------------------------------------------------
1456 * wUnmanageWindow--
1457 * Removes the frame window from a window and destroys all data
1458 * related to it. The window will be reparented back to the root window
1459 * if restore is True.
1461 * Side effects:
1462 * Everything related to the window is destroyed and the window
1463 * is removed from the window lists. Focus is set to the previous on the
1464 * window list.
1465 *----------------------------------------------------------------------
1467 void
1468 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1470 WCoreWindow *frame = wwin->frame->core;
1471 WWindow *owner = NULL;
1472 WWindow *newFocusedWindow = NULL;
1473 int wasFocused;
1474 WScreen *scr = wwin->screen_ptr;
1477 /* First close attribute editor window if open */
1478 if (wwin->flags.inspector_open) {
1479 wCloseInspectorForWindow(wwin);
1482 /* Close window menu if it's open for this window */
1483 if (wwin->flags.menu_open_for_me) {
1484 CloseWindowMenu(scr);
1487 if (!destroyed) {
1488 if (!wwin->flags.internal_window)
1489 XRemoveFromSaveSet(dpy, wwin->client_win);
1491 XSelectInput(dpy, wwin->client_win, NoEventMask);
1493 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1494 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1497 XUnmapWindow(dpy, frame->window);
1499 XUnmapWindow(dpy, wwin->client_win);
1501 /* deselect window */
1502 wSelectWindow(wwin, False);
1504 /* remove all pending events on window */
1505 /* I think this only matters for autoraise */
1506 if (wPreferences.raise_delay)
1507 WMDeleteTimerWithClientData(wwin->frame->core);
1509 XFlush(dpy);
1511 /* reparent the window back to the root */
1512 if (restore)
1513 wClientRestore(wwin);
1515 if (wwin->transient_for!=scr->root_win) {
1516 owner = wWindowFor(wwin->transient_for);
1517 if (owner) {
1518 if (!owner->flags.semi_focused) {
1519 owner = NULL;
1520 } else {
1521 owner->flags.semi_focused = 0;
1526 wasFocused = wwin->flags.focused;
1528 /* remove from window focus list */
1529 if (!wwin->prev && !wwin->next) {
1530 /* was the only window */
1531 scr->focused_window = NULL;
1532 newFocusedWindow = NULL;
1533 } else {
1534 WWindow *tmp;
1536 if (wwin->prev)
1537 wwin->prev->next = wwin->next;
1538 if (wwin->next)
1539 wwin->next->prev = wwin->prev;
1540 else {
1541 scr->focused_window = wwin->prev;
1542 scr->focused_window->next = NULL;
1545 if (wPreferences.focus_mode==WKF_CLICK) {
1547 /* if in click to focus mode and the window
1548 * was a transient, focus the owner window
1550 tmp = NULL;
1551 if (wPreferences.focus_mode==WKF_CLICK) {
1552 tmp = wWindowFor(wwin->transient_for);
1553 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1554 tmp = NULL;
1557 /* otherwise, focus the next one in the focus list */
1558 if (!tmp) {
1559 tmp = scr->focused_window;
1560 while (tmp) { /* look for one in the window list first */
1561 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1562 && (tmp->flags.mapped || tmp->flags.shaded))
1563 break;
1564 tmp = tmp->prev;
1566 if (!tmp) { /* if unsuccessful, choose any focusable window */
1567 tmp = scr->focused_window;
1568 while (tmp) {
1569 if (!WFLAGP(tmp, no_focusable)
1570 && (tmp->flags.mapped || tmp->flags.shaded))
1571 break;
1572 tmp = tmp->prev;
1577 newFocusedWindow = tmp;
1579 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1580 unsigned int mask;
1581 int foo;
1582 Window bar, win;
1584 /* This is to let the root window get the keyboard input
1585 * if Sloppy focus mode and no other window get focus.
1586 * This way keybindings will not freeze.
1588 tmp = NULL;
1589 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1590 &foo, &foo, &foo, &foo, &mask))
1591 tmp = wWindowFor(win);
1592 if (tmp == wwin)
1593 tmp = NULL;
1594 newFocusedWindow = tmp;
1595 } else {
1596 newFocusedWindow = NULL;
1600 if (!wwin->flags.internal_window) {
1601 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1604 #ifdef DEBUG
1605 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1606 (unsigned)frame->window);
1607 #endif
1609 if (wasFocused) {
1610 if (newFocusedWindow != owner && owner) {
1611 if (wwin->flags.is_gnustep == 0)
1612 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1614 wSetFocusTo(scr, newFocusedWindow);
1616 wWindowDestroy(wwin);
1617 XFlush(dpy);
1621 void
1622 wWindowMap(WWindow *wwin)
1624 XMapWindow(dpy, wwin->frame->core->window);
1625 if (!wwin->flags.shaded) {
1626 /* window will be remapped when getting MapNotify */
1627 XSelectInput(dpy, wwin->client_win,
1628 wwin->event_mask & ~StructureNotifyMask);
1629 XMapWindow(dpy, wwin->client_win);
1630 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1632 wwin->flags.mapped = 1;
1637 void
1638 wWindowUnmap(WWindow *wwin)
1640 wwin->flags.mapped = 0;
1642 /* prevent window withdrawal when getting UnmapNotify */
1643 XSelectInput(dpy, wwin->client_win,
1644 wwin->event_mask & ~StructureNotifyMask);
1645 XUnmapWindow(dpy, wwin->client_win);
1646 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1648 XUnmapWindow(dpy, wwin->frame->core->window);
1653 void
1654 wWindowFocus(WWindow *wwin, WWindow *owin)
1656 WWindow *nowner;
1657 WWindow *oowner;
1659 #ifdef KEEP_XKB_LOCK_STATUS
1660 if (wPreferences.modelock) {
1661 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1663 #endif /* KEEP_XKB_LOCK_STATUS */
1665 wwin->flags.semi_focused = 0;
1667 if (wwin->flags.is_gnustep == 0)
1668 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1670 wwin->flags.focused = 1;
1672 wWindowResetMouseGrabs(wwin);
1674 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1676 if (owin == wwin || !owin)
1677 return;
1679 nowner = wWindowFor(wwin->transient_for);
1681 /* new window is a transient for the old window */
1682 if (nowner == owin) {
1683 owin->flags.semi_focused = 1;
1684 wWindowUnfocus(nowner);
1685 return;
1688 oowner = wWindowFor(owin->transient_for);
1690 /* new window is owner of old window */
1691 if (wwin == oowner) {
1692 wWindowUnfocus(owin);
1693 return;
1696 if (!nowner) {
1697 wWindowUnfocus(owin);
1698 return;
1701 /* new window has same owner of old window */
1702 if (oowner == nowner) {
1703 /* prevent unfocusing of owner */
1704 oowner->flags.semi_focused = 0;
1705 wWindowUnfocus(owin);
1706 oowner->flags.semi_focused = 1;
1708 return;
1711 /* nowner != NULL && oowner != nowner */
1712 nowner->flags.semi_focused = 1;
1713 wWindowUnfocus(nowner);
1714 wWindowUnfocus(owin);
1718 void
1719 wWindowUnfocus(WWindow *wwin)
1721 CloseWindowMenu(wwin->screen_ptr);
1723 if (wwin->flags.is_gnustep == 0)
1724 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1725 ? WS_PFOCUSED : WS_UNFOCUSED);
1727 if (wwin->transient_for!=None
1728 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1729 WWindow *owner;
1730 owner = wWindowFor(wwin->transient_for);
1731 if (owner && owner->flags.semi_focused) {
1732 owner->flags.semi_focused = 0;
1733 if (owner->flags.mapped || owner->flags.shaded) {
1734 wWindowUnfocus(owner);
1735 wFrameWindowPaint(owner->frame);
1739 wwin->flags.focused = 0;
1741 wWindowResetMouseGrabs(wwin);
1743 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1747 void
1748 wWindowUpdateName(WWindow *wwin, char *newTitle)
1750 WApplication *app = wApplicationOf(wwin->main_window);
1751 int instIndex = 0;
1752 char prefix[32] = "";
1753 char *title;
1755 if (!wwin->frame)
1756 return;
1758 if (app)
1759 instIndex = wApplicationIndexOfGroup(app);
1762 wwin->flags.wm_name_changed = 1;
1764 if (!newTitle) {
1765 /* the hint was removed */
1766 title = DEF_WINDOW_TITLE;
1768 WMPostNotificationName(WMNChangedName, wwin, NULL);
1769 } else {
1770 title = newTitle;
1773 #ifndef NO_WINDOW_ENUMERATOR
1774 if (instIndex > 0) {
1775 snprintf(prefix, sizeof(prefix), " [%i]", instIndex);
1777 title = wstrconcat(title, prefix);
1779 #endif
1781 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1783 WMPostNotificationName(WMNChangedName, wwin, NULL);
1786 #ifndef NO_WINDOW_ENUMERATOR
1787 if (instIndex > 0)
1788 wfree(title);
1789 #endif
1796 *----------------------------------------------------------------------
1798 * wWindowConstrainSize--
1799 * Constrains size for the client window, taking the maximal size,
1800 * window resize increments and other size hints into account.
1802 * Returns:
1803 * The closest size to what was given that the client window can
1804 * have.
1806 *----------------------------------------------------------------------
1808 void
1809 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1811 int width = *nwidth;
1812 int height = *nheight;
1813 int winc = 1;
1814 int hinc = 1;
1815 int minW = 1, minH = 1;
1816 int maxW = wwin->screen_ptr->scr_width*2;
1817 int maxH = wwin->screen_ptr->scr_height*2;
1818 int minAX = -1, minAY = -1;
1819 int maxAX = -1, maxAY = -1;
1820 int baseW = 0;
1821 int baseH = 0;
1823 if (wwin->normal_hints) {
1824 winc = wwin->normal_hints->width_inc;
1825 hinc = wwin->normal_hints->height_inc;
1826 minW = wwin->normal_hints->min_width;
1827 minH = wwin->normal_hints->min_height;
1828 maxW = wwin->normal_hints->max_width;
1829 maxH = wwin->normal_hints->max_height;
1830 if (wwin->normal_hints->flags & PAspect) {
1831 minAX = wwin->normal_hints->min_aspect.x;
1832 minAY = wwin->normal_hints->min_aspect.y;
1833 maxAX = wwin->normal_hints->max_aspect.x;
1834 maxAY = wwin->normal_hints->max_aspect.y;
1837 baseW = wwin->normal_hints->base_width;
1838 baseH = wwin->normal_hints->base_height;
1841 if (width < minW)
1842 width = minW;
1843 if (height < minH)
1844 height = minH;
1846 if (width > maxW)
1847 width = maxW;
1848 if (height > maxH)
1849 height = maxH;
1851 /* aspect ratio code borrowed from olwm */
1852 if (minAX > 0) {
1853 /* adjust max aspect ratio */
1854 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1855 if (maxAX > maxAY) {
1856 height = (width * maxAY) / maxAX;
1857 if (height > maxH) {
1858 height = maxH;
1859 width = (height * maxAX) / maxAY;
1861 } else {
1862 width = (height * maxAX) / maxAY;
1863 if (width > maxW) {
1864 width = maxW;
1865 height = (width * maxAY) / maxAX;
1870 /* adjust min aspect ratio */
1871 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1872 if (minAX > minAY) {
1873 height = (width * minAY) / minAX;
1874 if (height < minH) {
1875 height = minH;
1876 width = (height * minAX) / minAY;
1878 } else {
1879 width = (height * minAX) / minAY;
1880 if (width < minW) {
1881 width = minW;
1882 height = (width * minAY) / minAX;
1888 if (baseW != 0) {
1889 width = (((width - baseW) / winc) * winc) + baseW;
1890 } else {
1891 width = (((width - minW) / winc) * winc) + minW;
1894 if (baseH != 0) {
1895 height = (((height - baseH) / hinc) * hinc) + baseH;
1896 } else {
1897 height = (((height - minH) / hinc) * hinc) + minH;
1900 /* broken stupid apps may cause preposterous values for these.. */
1901 if (width > 0)
1902 *nwidth = width;
1903 if (height > 0)
1904 *nheight = height;
1908 void
1909 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1910 int *width, int *height)
1912 int baseW = 0, baseH = 0;
1913 int winc = 1, hinc = 1;
1915 if (wwin->normal_hints) {
1916 baseW = wwin->normal_hints->base_width;
1917 baseH = wwin->normal_hints->base_height;
1919 winc = wwin->normal_hints->width_inc;
1920 hinc = wwin->normal_hints->height_inc;
1923 if (*width > maxW)
1924 *width = maxW - (maxW - baseW) % winc;
1926 if (*height > maxH)
1927 *height = maxH - (maxH - baseH) % hinc;
1931 void
1932 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1934 WScreen *scr = wwin->screen_ptr;
1935 WApplication *wapp;
1936 int unmap = 0;
1938 if (workspace >= scr->workspace_count || workspace < 0
1939 || workspace == wwin->frame->workspace)
1940 return;
1942 if (workspace != scr->current_workspace) {
1943 /* Sent to other workspace. Unmap window */
1944 if ((wwin->flags.mapped
1945 || wwin->flags.shaded
1946 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1947 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1949 wapp = wApplicationOf(wwin->main_window);
1950 if (wapp) {
1951 wapp->last_workspace = workspace;
1953 if (wwin->flags.miniaturized) {
1954 if (wwin->icon) {
1955 XUnmapWindow(dpy, wwin->icon->core->window);
1956 wwin->icon->mapped = 0;
1958 } else {
1959 unmap = 1;
1960 wSetFocusTo(scr, NULL);
1963 } else {
1964 /* brought to current workspace. Map window */
1965 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1966 if (wwin->icon) {
1967 XMapWindow(dpy, wwin->icon->core->window);
1968 wwin->icon->mapped = 1;
1970 } else if (!wwin->flags.mapped &&
1971 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1972 wWindowMap(wwin);
1975 if (!IS_OMNIPRESENT(wwin)) {
1976 int oldWorkspace = wwin->frame->workspace;
1978 wwin->frame->workspace = workspace;
1980 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
1983 if (unmap) {
1984 wWindowUnmap(wwin);
1989 void
1990 wWindowSynthConfigureNotify(WWindow *wwin)
1992 XEvent sevent;
1994 sevent.type = ConfigureNotify;
1995 sevent.xconfigure.display = dpy;
1996 sevent.xconfigure.event = wwin->client_win;
1997 sevent.xconfigure.window = wwin->client_win;
1999 sevent.xconfigure.x = wwin->client.x;
2000 sevent.xconfigure.y = wwin->client.y;
2001 sevent.xconfigure.width = wwin->client.width;
2002 sevent.xconfigure.height = wwin->client.height;
2004 sevent.xconfigure.border_width = wwin->old_border_width;
2005 if (WFLAGP(wwin, no_titlebar))
2006 sevent.xconfigure.above = None;
2007 else
2008 sevent.xconfigure.above = wwin->frame->titlebar->window;
2010 sevent.xconfigure.override_redirect = False;
2011 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2012 #ifdef KWM_HINTS
2013 wKWMSendEventMessage(wwin, WKWMChangedClient);
2014 #endif
2015 XFlush(dpy);
2020 *----------------------------------------------------------------------
2021 * wWindowConfigure--
2022 * Configures the frame, decorations and client window to the
2023 * specified geometry. The geometry is not checked for validity,
2024 * wWindowConstrainSize() must be used for that.
2025 * The size parameters are for the client window, but the position is
2026 * for the frame.
2027 * The client window receives a ConfigureNotify event, according
2028 * to what ICCCM says.
2030 * Returns:
2031 * None
2033 * Side effects:
2034 * Window size and position are changed and client window receives
2035 * a ConfigureNotify event.
2036 *----------------------------------------------------------------------
2038 void
2039 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2040 WWindow *wwin;
2041 int req_x, req_y; /* new position of the frame */
2042 int req_width, req_height; /* new size of the client */
2044 int synth_notify = False;
2045 int resize;
2047 resize = (req_width!=wwin->client.width
2048 || req_height!=wwin->client.height);
2050 * if the window is being moved but not resized then
2051 * send a synthetic ConfigureNotify
2053 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2054 synth_notify = True;
2057 if (WFLAGP(wwin, dont_move_off))
2058 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2059 req_width, req_height);
2060 if (resize) {
2061 if (req_width < MIN_WINDOW_SIZE)
2062 req_width = MIN_WINDOW_SIZE;
2063 if (req_height < MIN_WINDOW_SIZE)
2064 req_height = MIN_WINDOW_SIZE;
2066 /* If growing, resize inner part before frame,
2067 * if shrinking, resize frame before.
2068 * This will prevent the frame (that can have a different color)
2069 * to be exposed, causing flicker */
2070 if (req_height > wwin->frame->core->height
2071 || req_width > wwin->frame->core->width)
2072 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2074 if (wwin->flags.shaded) {
2075 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2076 req_width, wwin->frame->core->height);
2077 wwin->old_geometry.height = req_height;
2078 } else {
2079 int h;
2081 h = req_height + wwin->frame->top_width
2082 + wwin->frame->bottom_width;
2084 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2087 if (!(req_height > wwin->frame->core->height
2088 || req_width > wwin->frame->core->width))
2089 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2091 wwin->client.x = req_x;
2092 wwin->client.y = req_y + wwin->frame->top_width;
2093 wwin->client.width = req_width;
2094 wwin->client.height = req_height;
2095 } else {
2096 wwin->client.x = req_x;
2097 wwin->client.y = req_y + wwin->frame->top_width;
2099 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2101 wwin->frame_x = req_x;
2102 wwin->frame_y = req_y;
2103 if (!WFLAGP(wwin, no_border)) {
2104 wwin->client.x += FRAME_BORDER_WIDTH;
2105 wwin->client.y += FRAME_BORDER_WIDTH;
2108 #ifdef SHAPE
2109 if (wShapeSupported && wwin->flags.shaped && resize) {
2110 wWindowSetShape(wwin);
2112 #endif
2114 if (synth_notify)
2115 wWindowSynthConfigureNotify(wwin);
2116 XFlush(dpy);
2120 void
2121 wWindowMove(wwin, req_x, req_y)
2122 WWindow *wwin;
2123 int req_x, req_y; /* new position of the frame */
2125 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2126 int synth_notify = False;
2128 /* Send a synthetic ConfigureNotify event for every window movement. */
2129 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2130 synth_notify = True;
2132 #else
2133 /* A single synthetic ConfigureNotify event is sent at the end of
2134 * a completed (opaque) movement in moveres.c */
2135 #endif
2137 if (WFLAGP(wwin, dont_move_off))
2138 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2139 wwin->frame->core->width, wwin->frame->core->height);
2141 wwin->client.x = req_x;
2142 wwin->client.y = req_y + wwin->frame->top_width;
2143 if (!WFLAGP(wwin, no_border)) {
2144 wwin->client.x += FRAME_BORDER_WIDTH;
2145 wwin->client.y += FRAME_BORDER_WIDTH;
2148 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2150 wwin->frame_x = req_x;
2151 wwin->frame_y = req_y;
2153 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2154 if (synth_notify)
2155 wWindowSynthConfigureNotify(wwin);
2156 #endif
2160 void
2161 wWindowUpdateButtonImages(WWindow *wwin)
2163 WScreen *scr = wwin->screen_ptr;
2164 Pixmap pixmap, mask;
2165 WFrameWindow *fwin = wwin->frame;
2167 if (WFLAGP(wwin, no_titlebar))
2168 return;
2170 /* miniaturize button */
2172 if (!WFLAGP(wwin, no_miniaturize_button)) {
2173 if (wwin->wm_gnustep_attr
2174 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2175 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2177 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2178 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2179 } else {
2180 mask = None;
2183 if (fwin->lbutton_image
2184 && (fwin->lbutton_image->image != pixmap
2185 || fwin->lbutton_image->mask != mask)) {
2186 wPixmapDestroy(fwin->lbutton_image);
2187 fwin->lbutton_image = NULL;
2190 if (!fwin->lbutton_image) {
2191 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2192 fwin->lbutton_image->client_owned = 1;
2193 fwin->lbutton_image->client_owned_mask = 1;
2195 } else {
2196 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2197 wPixmapDestroy(fwin->lbutton_image);
2199 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2203 #ifdef XKB_BUTTON_HINT
2204 if (!WFLAGP(wwin, no_language_button)) {
2205 if (fwin->languagebutton_image &&
2206 !fwin->languagebutton_image->shared) {
2207 wPixmapDestroy(fwin->languagebutton_image);
2209 fwin->languagebutton_image =
2210 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2212 #endif
2214 /* close button */
2216 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2217 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2219 if (!WFLAGP(wwin, no_close_button)) {
2220 if (wwin->wm_gnustep_attr
2221 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2222 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2224 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2225 mask = wwin->wm_gnustep_attr->close_mask;
2226 else
2227 mask = None;
2229 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2230 || fwin->rbutton_image->mask != mask)) {
2231 wPixmapDestroy(fwin->rbutton_image);
2232 fwin->rbutton_image = NULL;
2235 if (!fwin->rbutton_image) {
2236 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2237 fwin->rbutton_image->client_owned = 1;
2238 fwin->rbutton_image->client_owned_mask = 1;
2241 } else if (WFLAGP(wwin, kill_close)) {
2243 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2244 wPixmapDestroy(fwin->rbutton_image);
2246 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2248 } else if (MGFLAGP(wwin, broken_close)) {
2250 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2251 wPixmapDestroy(fwin->rbutton_image);
2253 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2255 } else {
2257 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2258 wPixmapDestroy(fwin->rbutton_image);
2260 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2264 /* force buttons to be redrawn */
2265 fwin->flags.need_texture_change = 1;
2266 wFrameWindowPaint(fwin);
2271 *---------------------------------------------------------------------------
2272 * wWindowConfigureBorders--
2273 * Update window border configuration according to attribute flags.
2275 *---------------------------------------------------------------------------
2277 void
2278 wWindowConfigureBorders(WWindow *wwin)
2280 if (wwin->frame) {
2281 int flags;
2282 int newy, oldh;
2284 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2285 #ifdef XKB_BUTTON_HINT
2286 flags |= WFF_LANGUAGE_BUTTON;
2287 #endif
2288 if (!WFLAGP(wwin, no_titlebar))
2289 flags |= WFF_TITLEBAR;
2290 if (!WFLAGP(wwin, no_resizebar))
2291 flags |= WFF_RESIZEBAR;
2292 if (!WFLAGP(wwin, no_border))
2293 flags |= WFF_BORDER;
2294 if (wwin->flags.shaded)
2295 flags |= WFF_IS_SHADED;
2297 oldh = wwin->frame->top_width;
2298 wFrameWindowUpdateBorders(wwin->frame, flags);
2299 if (oldh != wwin->frame->top_width) {
2300 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2302 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2303 wWindowConfigure(wwin, wwin->frame_x, newy,
2304 wwin->client.width, wwin->client.height);
2307 flags = 0;
2308 if (!WFLAGP(wwin, no_miniaturize_button)
2309 && wwin->frame->flags.hide_left_button)
2310 flags |= WFF_LEFT_BUTTON;
2312 #ifdef XKB_BUTTON_HINT
2313 if (!WFLAGP(wwin, no_language_button)
2314 && wwin->frame->flags.hide_language_button)
2315 flags |= WFF_LANGUAGE_BUTTON;
2316 #endif
2318 if (!WFLAGP(wwin, no_close_button)
2319 && wwin->frame->flags.hide_right_button)
2320 flags |= WFF_RIGHT_BUTTON;
2322 if (flags!=0) {
2323 wWindowUpdateButtonImages(wwin);
2324 wFrameWindowShowButton(wwin->frame, flags);
2327 flags = 0;
2328 if (WFLAGP(wwin, no_miniaturize_button)
2329 && !wwin->frame->flags.hide_left_button)
2330 flags |= WFF_LEFT_BUTTON;
2332 #ifdef XKB_BUTTON_HINT
2333 if (WFLAGP(wwin, no_language_button)
2334 && !wwin->frame->flags.hide_language_button)
2335 flags |= WFF_LANGUAGE_BUTTON;
2336 #endif
2338 if (WFLAGP(wwin, no_close_button)
2339 && !wwin->frame->flags.hide_right_button)
2340 flags |= WFF_RIGHT_BUTTON;
2342 if (flags!=0)
2343 wFrameWindowHideButton(wwin->frame, flags);
2345 #ifdef SHAPE
2346 if (wShapeSupported && wwin->flags.shaped) {
2347 wWindowSetShape(wwin);
2349 #endif
2354 void
2355 wWindowSaveState(WWindow *wwin)
2357 CARD32 data[10];
2358 int i;
2360 memset(data, 0, sizeof(CARD32)*10);
2361 data[0] = wwin->frame->workspace;
2362 data[1] = wwin->flags.miniaturized;
2363 data[2] = wwin->flags.shaded;
2364 data[3] = wwin->flags.hidden;
2365 data[4] = wwin->flags.maximized;
2366 if (wwin->flags.maximized == 0) {
2367 data[5] = wwin->frame_x;
2368 data[6] = wwin->frame_y;
2369 data[7] = wwin->frame->core->width;
2370 data[8] = wwin->frame->core->height;
2371 } else {
2372 data[5] = wwin->old_geometry.x;
2373 data[6] = wwin->old_geometry.y;
2374 data[7] = wwin->old_geometry.width;
2375 data[8] = wwin->old_geometry.height;
2378 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2379 if (wwin->screen_ptr->shortcutWindows[i] &&
2380 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2381 data[9] |= 1<<i;
2383 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2384 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2385 (unsigned char *)data, 10);
2389 static int
2390 getSavedState(Window window, WSavedState **state)
2392 Atom type_ret;
2393 int fmt_ret;
2394 unsigned long nitems_ret;
2395 unsigned long bytes_after_ret;
2396 CARD32 *data;
2398 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2399 True, _XA_WINDOWMAKER_STATE,
2400 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2401 (unsigned char **)&data)!=Success || !data)
2402 return 0;
2404 *state = wmalloc(sizeof(WSavedState));
2406 (*state)->workspace = data[0];
2407 (*state)->miniaturized = data[1];
2408 (*state)->shaded = data[2];
2409 (*state)->hidden = data[3];
2410 (*state)->maximized = data[4];
2411 (*state)->x = data[5];
2412 (*state)->y = data[6];
2413 (*state)->w = data[7];
2414 (*state)->h = data[8];
2415 (*state)->window_shortcuts = data[9];
2417 XFree(data);
2419 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2420 return 1;
2421 else
2422 return 0;
2426 #ifdef SHAPE
2427 void
2428 wWindowClearShape(WWindow *wwin)
2430 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2431 0, wwin->frame->top_width, None, ShapeSet);
2432 XFlush(dpy);
2435 void
2436 wWindowSetShape(WWindow *wwin)
2438 XRectangle rect[2];
2439 int count;
2440 #ifdef OPTIMIZE_SHAPE
2441 XRectangle *rects;
2442 XRectangle *urec;
2443 int ordering;
2445 /* only shape is the client's */
2446 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2447 goto alt_code;
2450 /* Get array of rectangles describing the shape mask */
2451 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2452 &count, &ordering);
2453 if (!rects) {
2454 goto alt_code;
2457 urec = malloc(sizeof(XRectangle)*(count+2));
2458 if (!urec) {
2459 XFree(rects);
2460 goto alt_code;
2463 /* insert our decoration rectangles in the rect list */
2464 memcpy(urec, rects, sizeof(XRectangle)*count);
2465 XFree(rects);
2467 if (!WFLAGP(wwin, no_titlebar)) {
2468 urec[count].x = -1;
2469 urec[count].y = -1 - wwin->frame->top_width;
2470 urec[count].width = wwin->frame->core->width + 2;
2471 urec[count].height = wwin->frame->top_width + 1;
2472 count++;
2474 if (!WFLAGP(wwin, no_resizebar)) {
2475 urec[count].x = -1;
2476 urec[count].y = wwin->frame->core->height
2477 - wwin->frame->bottom_width - wwin->frame->top_width;
2478 urec[count].width = wwin->frame->core->width + 2;
2479 urec[count].height = wwin->frame->bottom_width + 1;
2480 count++;
2483 /* shape our frame window */
2484 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2485 0, wwin->frame->top_width, urec, count,
2486 ShapeSet, Unsorted);
2487 XFlush(dpy);
2488 wfree(urec);
2489 return;
2491 alt_code:
2492 #endif /* OPTIMIZE_SHAPE */
2493 count = 0;
2494 if (!WFLAGP(wwin, no_titlebar)) {
2495 rect[count].x = -1;
2496 rect[count].y = -1;
2497 rect[count].width = wwin->frame->core->width + 2;
2498 rect[count].height = wwin->frame->top_width + 1;
2499 count++;
2501 if (!WFLAGP(wwin, no_resizebar)) {
2502 rect[count].x = -1;
2503 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2504 rect[count].width = wwin->frame->core->width + 2;
2505 rect[count].height = wwin->frame->bottom_width + 1;
2506 count++;
2508 if (count > 0) {
2509 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2510 0, 0, rect, count, ShapeSet, Unsorted);
2512 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2513 0, wwin->frame->top_width, wwin->client_win,
2514 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2515 XFlush(dpy);
2517 #endif /* SHAPE */
2519 /* ====================================================================== */
2521 static FocusMode
2522 getFocusMode(WWindow *wwin)
2524 FocusMode mode;
2526 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2527 if (wwin->wm_hints->input == True) {
2528 if (wwin->protocols.TAKE_FOCUS)
2529 mode = WFM_LOCALLY_ACTIVE;
2530 else
2531 mode = WFM_PASSIVE;
2532 } else {
2533 if (wwin->protocols.TAKE_FOCUS)
2534 mode = WFM_GLOBALLY_ACTIVE;
2535 else
2536 mode = WFM_NO_INPUT;
2538 } else {
2539 mode = WFM_PASSIVE;
2541 return mode;
2545 void
2546 wWindowSetKeyGrabs(WWindow *wwin)
2548 int i;
2549 WShortKey *key;
2551 for (i=0; i<WKBD_LAST; i++) {
2552 key = &wKeyBindings[i];
2554 if (key->keycode==0)
2555 continue;
2556 if (key->modifier!=AnyModifier) {
2557 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2558 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2559 #ifdef NUMLOCK_HACK
2560 /* Also grab all modifier combinations possible that include,
2561 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2562 * work even if the NumLock/ScrollLock key is on.
2564 wHackedGrabKey(key->keycode, key->modifier,
2565 wwin->frame->core->window, True, GrabModeAsync,
2566 GrabModeAsync);
2567 #endif
2569 XGrabKey(dpy, key->keycode, key->modifier,
2570 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2573 #ifndef LITE
2574 wRootMenuBindShortcuts(wwin->frame->core->window);
2575 #endif
2580 void
2581 wWindowResetMouseGrabs(WWindow *wwin)
2583 /* Mouse grabs can't be done on the client window because of
2584 * ICCCM and because clients that try to do the same will crash.
2586 * But there is a problem wich makes tbar buttons of unfocused
2587 * windows not usable as the click goes to the frame window instead
2588 * of the button itself. Must figure a way to fix that.
2591 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2593 if (!WFLAGP(wwin, no_bind_mouse)) {
2594 /* grabs for Meta+drag */
2595 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2596 True, ButtonPressMask, GrabModeSync,
2597 GrabModeAsync, None, None);
2600 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2601 && !wwin->flags.is_gnustep) {
2602 /* the passive grabs to focus the window */
2603 /* if (wPreferences.focus_mode == WKF_CLICK) */
2604 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2605 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2606 None, None);
2608 XFlush(dpy);
2612 void
2613 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2615 if (attr->flags & GSExtraFlagsAttr) {
2616 if (MGFLAGP(wwin, broken_close) !=
2617 (attr->extra_flags & GSDocumentEditedFlag)) {
2618 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2619 wWindowUpdateButtonImages(wwin);
2625 WMagicNumber
2626 wWindowAddSavedState(char *instance, char *class, char *command,
2627 pid_t pid, WSavedState *state)
2629 WWindowState *wstate;
2631 wstate = malloc(sizeof(WWindowState));
2632 if (!wstate)
2633 return 0;
2635 memset(wstate, 0, sizeof(WWindowState));
2636 wstate->pid = pid;
2637 if (instance)
2638 wstate->instance = wstrdup(instance);
2639 if (class)
2640 wstate->class = wstrdup(class);
2641 if (command)
2642 wstate->command = wstrdup(command);
2643 wstate->state = state;
2645 wstate->next = windowState;
2646 windowState = wstate;
2648 #ifdef DEBUG
2649 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2650 class, command);
2651 #endif
2653 return wstate;
2657 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2660 WMagicNumber
2661 wWindowGetSavedState(Window win)
2663 char *instance, *class, *command=NULL;
2664 WWindowState *wstate = windowState;
2665 char **argv;
2666 int argc;
2668 if (!wstate)
2669 return NULL;
2671 if (XGetCommand(dpy, win, &argv, &argc)) {
2672 if (argc > 0)
2673 command = wtokenjoin(argv, argc);
2674 XFreeStringList(argv);
2676 if (!command)
2677 return NULL;
2679 if (PropGetWMClass(win, &class, &instance)) {
2680 while (wstate) {
2681 if (SAME(instance, wstate->instance) &&
2682 SAME(class, wstate->class) &&
2683 SAME(command, wstate->command)) {
2684 break;
2686 wstate = wstate->next;
2688 } else {
2689 wstate = NULL;
2692 #ifdef DEBUG
2693 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2694 class, command);
2695 #endif
2697 if (command) wfree(command);
2698 if (instance) XFree(instance);
2699 if (class) XFree(class);
2701 return wstate;
2705 void
2706 wWindowDeleteSavedState(WMagicNumber id)
2708 WWindowState *tmp, *wstate=(WWindowState*)id;
2710 if (!wstate || !windowState)
2711 return;
2713 tmp = windowState;
2714 if (tmp==wstate) {
2715 windowState = wstate->next;
2716 #ifdef DEBUG
2717 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2718 wstate, wstate->instance, wstate->class, wstate->command);
2719 #endif
2720 if (wstate->instance) wfree(wstate->instance);
2721 if (wstate->class) wfree(wstate->class);
2722 if (wstate->command) wfree(wstate->command);
2723 wfree(wstate->state);
2724 wfree(wstate);
2725 } else {
2726 while (tmp->next) {
2727 if (tmp->next==wstate) {
2728 tmp->next=wstate->next;
2729 #ifdef DEBUG
2730 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2731 wstate, wstate->instance, wstate->class, wstate->command);
2732 #endif
2733 if (wstate->instance) wfree(wstate->instance);
2734 if (wstate->class) wfree(wstate->class);
2735 if (wstate->command) wfree(wstate->command);
2736 wfree(wstate->state);
2737 wfree(wstate);
2738 break;
2740 tmp = tmp->next;
2746 void
2747 wWindowDeleteSavedStatesForPID(pid_t pid)
2749 WWindowState *tmp, *wstate;
2751 if (!windowState)
2752 return;
2754 tmp = windowState;
2755 if (tmp->pid == pid) {
2756 wstate = windowState;
2757 windowState = tmp->next;
2758 #ifdef DEBUG
2759 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2760 wstate, wstate->instance, wstate->class, wstate->command);
2761 #endif
2762 if (wstate->instance) wfree(wstate->instance);
2763 if (wstate->class) wfree(wstate->class);
2764 if (wstate->command) wfree(wstate->command);
2765 wfree(wstate->state);
2766 wfree(wstate);
2767 } else {
2768 while (tmp->next) {
2769 if (tmp->next->pid==pid) {
2770 wstate = tmp->next;
2771 tmp->next = wstate->next;
2772 #ifdef DEBUG
2773 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2774 wstate, wstate->instance, wstate->class, wstate->command);
2775 #endif
2776 if (wstate->instance) wfree(wstate->instance);
2777 if (wstate->class) wfree(wstate->class);
2778 if (wstate->command) wfree(wstate->command);
2779 wfree(wstate->state);
2780 wfree(wstate);
2781 break;
2783 tmp = tmp->next;
2789 void
2790 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2792 wwin->flags.omnipresent = flag;
2794 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2798 /* ====================================================================== */
2800 static void
2801 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2803 WWindow *wwin = data;
2805 #ifndef NUMLOCK_HACK
2806 if ((event->xbutton.state & ValidModMask)
2807 != (event->xbutton.state & ~LockMask)) {
2808 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2809 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2811 #endif
2813 event->xbutton.state &= ValidModMask;
2815 CloseWindowMenu(wwin->screen_ptr);
2817 if (wPreferences.focus_mode==WKF_CLICK
2818 && !(event->xbutton.state&ControlMask)
2819 && !WFLAGP(wwin, no_focusable)) {
2820 wSetFocusTo(wwin->screen_ptr, wwin);
2823 if (event->xbutton.button == Button1)
2824 wRaiseFrame(wwin->frame->core);
2826 if (event->xbutton.window != wwin->frame->resizebar->window) {
2827 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2828 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2829 GrabModeAsync, GrabModeAsync, None,
2830 None, CurrentTime)!=GrabSuccess) {
2831 #ifdef DEBUG0
2832 wwarning("pointer grab failed for window move");
2833 #endif
2834 return;
2838 if (event->xbutton.state & MOD_MASK) {
2839 /* move the window */
2840 wMouseMoveWindow(wwin, event);
2841 XUngrabPointer(dpy, CurrentTime);
2842 } else {
2843 wMouseResizeWindow(wwin, event);
2844 XUngrabPointer(dpy, CurrentTime);
2850 static void
2851 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2853 WWindow *wwin = data;
2855 event->xbutton.state &= ValidModMask;
2857 if (event->xbutton.button==Button1) {
2858 if (event->xbutton.state == 0) {
2859 if (!WFLAGP(wwin, no_shadeable)) {
2860 /* shade window */
2861 if (wwin->flags.shaded)
2862 wUnshadeWindow(wwin);
2863 else
2864 wShadeWindow(wwin);
2866 } else {
2867 int dir = 0;
2869 if (event->xbutton.state & ControlMask)
2870 dir |= MAX_VERTICAL;
2872 if (event->xbutton.state & ShiftMask) {
2873 dir |= MAX_HORIZONTAL;
2874 if (!(event->xbutton.state & ControlMask))
2875 wSelectWindow(wwin, !wwin->flags.selected);
2878 /* maximize window */
2879 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
2880 int ndir = dir ^ wwin->flags.maximized;
2881 if (wwin->flags.maximized != 0)
2882 wUnmaximizeWindow(wwin);
2883 if (ndir != 0)
2884 wMaximizeWindow(wwin, ndir);
2887 } else if (event->xbutton.button==Button3) {
2888 if (event->xbutton.state & MOD_MASK) {
2889 wHideOtherApplications(wwin);
2891 } else if (event->xbutton.button==Button2) {
2892 wSelectWindow(wwin, !wwin->flags.selected);
2893 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2894 wShadeWindow(wwin);
2895 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2896 wUnshadeWindow(wwin);
2901 static void
2902 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2904 WWindow *wwin = desc->parent;
2906 event->xbutton.state &= ValidModMask;
2908 CloseWindowMenu(wwin->screen_ptr);
2910 if (/*wPreferences.focus_mode==WKF_CLICK
2911 &&*/ !(event->xbutton.state&ControlMask)
2912 && !WFLAGP(wwin, no_focusable)) {
2913 wSetFocusTo(wwin->screen_ptr, wwin);
2915 if (event->xbutton.button == Button1) {
2916 wRaiseFrame(wwin->frame->core);
2919 if (event->xbutton.state & MOD_MASK) {
2920 /* move the window */
2921 if (XGrabPointer(dpy, wwin->client_win, False,
2922 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2923 GrabModeAsync, GrabModeAsync, None,
2924 None, CurrentTime)!=GrabSuccess) {
2925 #ifdef DEBUG0
2926 wwarning("pointer grab failed for window move");
2927 #endif
2928 return;
2930 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2931 wMouseResizeWindow(wwin, event);
2932 else
2933 wMouseMoveWindow(wwin, event);
2934 XUngrabPointer(dpy, CurrentTime);
2939 static void
2940 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2942 WWindow *wwin = (WWindow*)data;
2944 #ifndef NUMLOCK_HACK
2945 if ((event->xbutton.state & ValidModMask)
2946 != (event->xbutton.state & ~LockMask)) {
2947 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2948 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2950 #endif
2951 event->xbutton.state &= ValidModMask;
2953 CloseWindowMenu(wwin->screen_ptr);
2955 if (wPreferences.focus_mode==WKF_CLICK
2956 && !(event->xbutton.state&ControlMask)
2957 && !WFLAGP(wwin, no_focusable)) {
2958 wSetFocusTo(wwin->screen_ptr, wwin);
2961 if (event->xbutton.button == Button1
2962 || event->xbutton.button == Button2) {
2964 if (event->xbutton.button == Button1) {
2965 if (event->xbutton.state & MOD_MASK) {
2966 wLowerFrame(wwin->frame->core);
2967 } else {
2968 wRaiseFrame(wwin->frame->core);
2971 if ((event->xbutton.state & ShiftMask)
2972 && !(event->xbutton.state & ControlMask)) {
2973 wSelectWindow(wwin, !wwin->flags.selected);
2974 return;
2976 if (event->xbutton.window != wwin->frame->titlebar->window
2977 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2978 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2979 GrabModeAsync, GrabModeAsync, None,
2980 None, CurrentTime)!=GrabSuccess) {
2981 #ifdef DEBUG0
2982 wwarning("pointer grab failed for window move");
2983 #endif
2984 return;
2987 /* move the window */
2988 wMouseMoveWindow(wwin, event);
2990 XUngrabPointer(dpy, CurrentTime);
2991 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2992 && !wwin->flags.internal_window
2993 && !WCHECK_STATE(WSTATE_MODAL)) {
2994 WObjDescriptor *desc;
2996 if (event->xbutton.window != wwin->frame->titlebar->window
2997 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2998 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2999 GrabModeAsync, GrabModeAsync, None,
3000 None, CurrentTime)!=GrabSuccess) {
3001 #ifdef DEBUG0
3002 wwarning("pointer grab failed for window move");
3003 #endif
3004 return;
3007 OpenWindowMenu(wwin, event->xbutton.x_root,
3008 wwin->frame_y+wwin->frame->top_width, False);
3010 /* allow drag select */
3011 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3012 event->xany.send_event = True;
3013 (*desc->handle_mousedown)(desc, event);
3015 XUngrabPointer(dpy, CurrentTime);
3021 static void
3022 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3024 WWindow *wwin = data;
3026 event->xbutton.state &= ValidModMask;
3028 CloseWindowMenu(wwin->screen_ptr);
3030 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3031 return;
3033 /* if control-click, kill the client */
3034 if (event->xbutton.state & ControlMask) {
3035 wClientKill(wwin);
3036 } else {
3037 #ifdef OLWM_HINTS
3038 if (wwin->flags.olwm_push_pin_out) {
3040 wwin->flags.olwm_push_pin_out = 0;
3042 wOLWMChangePushpinState(wwin, True);
3044 wFrameWindowUpdatePushButton(wwin->frame, False);
3046 return;
3048 #endif
3049 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3050 /* send delete message */
3051 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3057 static void
3058 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3060 WWindow *wwin = data;
3062 CloseWindowMenu(wwin->screen_ptr);
3064 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3065 return;
3067 /* send delete message */
3068 if (wwin->protocols.DELETE_WINDOW) {
3069 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3070 } else {
3071 wClientKill(wwin);
3076 #ifdef XKB_BUTTON_HINT
3077 static void
3078 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3080 WWindow *wwin = data;
3081 WFrameWindow *fwin = wwin->frame;
3082 WScreen *scr = fwin->screen_ptr;
3083 XkbStateRec staterec;
3084 int tl;
3086 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3087 return;
3088 tl = wwin->frame->languagemode;
3089 wwin->frame->languagemode = wwin->frame->last_languagemode;
3090 wwin->frame->last_languagemode = tl;
3091 wSetFocusTo(scr, wwin);
3092 wwin->frame->languagebutton_image =
3093 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3094 wwin->frame->languagemode];
3095 wFrameWindowUpdateLanguageButton(wwin->frame);
3096 if (event->xbutton.button == Button3)
3097 return;
3098 wRaiseFrame(fwin->core);
3100 #endif
3103 static void
3104 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3106 WWindow *wwin = data;
3108 event->xbutton.state &= ValidModMask;
3110 CloseWindowMenu(wwin->screen_ptr);
3112 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3113 return;
3115 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3116 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3117 LastTimestamp);
3118 } else {
3119 WApplication *wapp;
3120 if ((event->xbutton.state & ControlMask) ||
3121 (event->xbutton.button == Button3)) {
3123 wapp = wApplicationOf(wwin->main_window);
3124 if (wapp && !WFLAGP(wwin, no_appicon))
3125 wHideApplication(wapp);
3126 } else if (event->xbutton.state==0) {
3127 wIconifyWindow(wwin);