new appicon grouping stuff
[wmaker-crm.git] / src / window.c
blob6c458875c7da863712b60cf09e5b013850a2fb0e
1 /* window.c - client window managing stuffs
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #ifdef SHAPE
28 #include <X11/extensions/shape.h>
29 #endif
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
38 #include "WindowMaker.h"
39 #include "GNUstep.h"
40 #include "wcore.h"
41 #include "framewin.h"
42 #include "texture.h"
43 #include "window.h"
44 #include "winspector.h"
45 #include "icon.h"
46 #include "properties.h"
47 #include "actions.h"
48 #include "client.h"
49 #include "funcs.h"
50 #include "keybind.h"
51 #include "stacking.h"
52 #include "defaults.h"
53 #include "workspace.h"
56 #ifdef MWM_HINTS
57 # include "motif.h"
58 #endif
59 #ifdef KWM_HINTS
60 # include "kwm.h"
61 #endif
62 #ifdef GNOME_STUFF
63 # include "gnome.h"
64 #endif
65 #ifdef OLWM_HINTS
66 # include "openlook.h"
67 #endif
69 /****** Global Variables ******/
71 extern WShortKey wKeyBindings[WKBD_LAST];
73 #ifdef SHAPE
74 extern Bool wShapeSupported;
75 #endif
77 /* contexts */
78 extern XContext wWinContext;
80 /* cursors */
81 extern Cursor wCursor[WCUR_LAST];
83 /* protocol atoms */
84 extern Atom _XA_WM_DELETE_WINDOW;
85 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
87 extern Atom _XA_WINDOWMAKER_STATE;
89 extern WPreferences wPreferences;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern Time LastTimestamp;
95 /* superfluous... */
96 extern void DoWindowBirth(WWindow*);
99 /***** Local Stuff *****/
102 static WWindowState *windowState=NULL;
106 /* local functions */
107 static FocusMode getFocusMode(WWindow *wwin);
109 static int getSavedState(Window window, WSavedState **state);
111 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
113 /* event handlers */
116 /* frame window (during window grabs) */
117 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
119 /* close button */
120 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
121 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
123 /* iconify button */
124 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
126 #ifdef XKB_BUTTON_HINT
127 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
128 #endif
130 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
131 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
133 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
136 /****** Notification Observers ******/
138 static void
139 appearanceObserver(void *self, WMNotification *notif)
141 WWindow *wwin = (WWindow*)self;
142 int flags = (int)WMGetNotificationClientData(notif);
144 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
145 return;
147 if (flags & WFontSettings) {
148 wWindowConfigureBorders(wwin);
149 if(wwin->flags.shaded) {
150 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
151 wwin->frame->top_width - 1);
153 wwin->client.y = wwin->frame_y - wwin->client.height
154 + wwin->frame->top_width;
155 wWindowSynthConfigureNotify(wwin);
158 if (flags & WTextureSettings) {
159 wwin->frame->flags.need_texture_remake = 1;
161 if (flags & (WTextureSettings | WColorSettings)) {
162 if (wwin->frame->titlebar)
163 XClearWindow(dpy, wwin->frame->titlebar->window);
165 wFrameWindowPaint(wwin->frame);
169 /************************************/
171 WWindow*
172 wWindowFor(Window window)
174 WObjDescriptor *desc;
176 if (window==None)
177 return NULL;
179 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
180 return NULL;
182 if (desc->parent_type==WCLASS_WINDOW)
183 return desc->parent;
184 else if (desc->parent_type==WCLASS_FRAME) {
185 WFrameWindow *frame = (WFrameWindow*)desc->parent;
186 if (frame->flags.is_client_window_frame)
187 return frame->child;
190 return NULL;
194 WWindow*
195 wWindowCreate()
197 WWindow *wwin;
199 wwin = wmalloc(sizeof(WWindow));
200 wretain(wwin);
202 memset(wwin, 0, sizeof(WWindow));
204 wwin->client_descriptor.handle_mousedown = frameMouseDown;
205 wwin->client_descriptor.parent = wwin;
206 wwin->client_descriptor.self = wwin;
207 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
209 return wwin;
213 void
214 wWindowDestroy(WWindow *wwin)
216 int i;
218 if (wwin->screen_ptr->cmap_window == wwin) {
219 wwin->screen_ptr->cmap_window = NULL;
222 WMRemoveNotificationObserver(wwin);
224 wwin->flags.destroyed = 1;
226 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
227 if (!wwin->screen_ptr->shortcutWindows[i])
228 continue;
230 WMRemoveFromBag(wwin->screen_ptr->shortcutWindows[i], wwin);
232 if (!WMGetBagItemCount(wwin->screen_ptr->shortcutWindows[i])) {
233 WMFreeBag(wwin->screen_ptr->shortcutWindows[i]);
234 wwin->screen_ptr->shortcutWindows[i] = NULL;
238 if (wwin->normal_hints)
239 XFree(wwin->normal_hints);
241 if (wwin->wm_hints)
242 XFree(wwin->wm_hints);
244 if (wwin->wm_instance)
245 XFree(wwin->wm_instance);
247 if (wwin->wm_class)
248 XFree(wwin->wm_class);
250 if (wwin->wm_gnustep_attr)
251 wfree(wwin->wm_gnustep_attr);
253 if (wwin->cmap_windows)
254 XFree(wwin->cmap_windows);
256 XDeleteContext(dpy, wwin->client_win, wWinContext);
258 if (wwin->frame)
259 wFrameWindowDestroy(wwin->frame);
261 if (wwin->icon) {
262 RemoveFromStackList(wwin->icon->core);
263 wIconDestroy(wwin->icon);
264 if (wPreferences.auto_arrange_icons)
265 wArrangeIcons(wwin->screen_ptr, True);
267 wrelease(wwin);
273 static void
274 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
276 if (gs_hints->flags & GSWindowStyleAttr) {
277 if (gs_hints->window_style == WMBorderlessWindowMask) {
278 wwin->client_flags.no_border = 1;
279 wwin->client_flags.no_titlebar = 1;
280 wwin->client_flags.no_closable = 1;
281 wwin->client_flags.no_miniaturizable = 1;
282 wwin->client_flags.no_resizable = 1;
283 wwin->client_flags.no_close_button = 1;
284 wwin->client_flags.no_miniaturize_button = 1;
285 wwin->client_flags.no_resizebar = 1;
286 } else {
287 wwin->client_flags.no_close_button =
288 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
290 wwin->client_flags.no_closable =
291 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
293 wwin->client_flags.no_miniaturize_button =
294 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
296 wwin->client_flags.no_miniaturizable =
297 wwin->client_flags.no_miniaturize_button;
299 wwin->client_flags.no_resizebar =
300 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
302 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
304 /* these attributes supposedly imply in the existence
305 * of a titlebar */
306 if (gs_hints->window_style & (WMResizableWindowMask|
307 WMClosableWindowMask|
308 WMMiniaturizableWindowMask)) {
309 wwin->client_flags.no_titlebar = 0;
310 } else {
311 wwin->client_flags.no_titlebar =
312 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
316 } else {
317 /* setup the defaults */
318 wwin->client_flags.no_border = 0;
319 wwin->client_flags.no_titlebar = 0;
320 wwin->client_flags.no_closable = 0;
321 wwin->client_flags.no_miniaturizable = 0;
322 wwin->client_flags.no_resizable = 0;
323 wwin->client_flags.no_close_button = 0;
324 wwin->client_flags.no_miniaturize_button = 0;
325 wwin->client_flags.no_resizebar = 0;
327 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
328 wwin->client_flags.no_appicon = 1;
333 void
334 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
335 WWindowAttributes *mask)
337 if (wflags->no_appicon && mask->no_appicon)
338 wflags->emulate_appicon = 0;
340 if (wwin->main_window!=None) {
341 WApplication *wapp = wApplicationOf(wwin->main_window);
342 if (wapp && !wapp->flags.emulated)
343 wflags->emulate_appicon = 0;
346 if (wwin->transient_for!=None
347 && wwin->transient_for!=wwin->screen_ptr->root_win)
348 wflags->emulate_appicon = 0;
350 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
351 wflags->sunken = 0;
356 void
357 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
359 WScreen *scr = wwin->screen_ptr;
361 /* sets global default stuff */
362 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
363 &wwin->client_flags, NULL, True);
365 * Decoration setting is done in this precedence (lower to higher)
366 * - use global default in the resource database
367 * - guess some settings
368 * - use GNUstep/external window attributes
369 * - set hints specified for the app in the resource DB
372 WSETUFLAG(wwin, broken_close, 0);
374 if (wwin->protocols.DELETE_WINDOW)
375 WSETUFLAG(wwin, kill_close, 0);
376 else
377 WSETUFLAG(wwin, kill_close, 1);
379 /* transients can't be iconified or maximized */
380 if (wwin->transient_for) {
381 WSETUFLAG(wwin, no_miniaturizable, 1);
382 WSETUFLAG(wwin, no_miniaturize_button, 1);
385 /* if the window can't be resized, remove the resizebar */
386 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
387 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
388 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
389 WSETUFLAG(wwin, no_resizable, 1);
390 WSETUFLAG(wwin, no_resizebar, 1);
393 /* set GNUstep window attributes */
394 if (wwin->wm_gnustep_attr) {
395 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
397 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
399 *level = wwin->wm_gnustep_attr->window_level;
401 * INT_MIN is the only illegal window level.
403 if (*level == INT_MIN)
404 *level = INT_MIN + 1;
405 } else {
406 /* setup defaults */
407 *level = WMNormalLevel;
409 } else {
410 int tmp_workspace = -1;
411 int tmp_level = -1;
412 Bool check;
414 check = False;
416 #ifdef MWM_HINTS
417 wMWMCheckClientHints(wwin);
418 #endif /* MWM_HINTS */
420 #ifdef GNOME_STUFF
421 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
422 #endif /* GNOME_STUFF */
424 #ifdef KWM_HINTS
425 if (!check)
426 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
427 #endif /* KWM_HINTS */
429 #ifdef OLWM_HINTS
430 wOLWMCheckClientHints(wwin);
431 #endif /* OLWM_HINTS */
433 if (tmp_level < 0) {
434 if (WFLAGP(wwin, floating))
435 *level = WMFloatingLevel;
436 else if (WFLAGP(wwin, sunken))
437 *level = WMSunkenLevel;
438 else
439 *level = WMNormalLevel;
440 } else {
441 *level = tmp_level;
444 if (tmp_workspace >= 0) {
445 *workspace = tmp_workspace % scr->workspace_count;
450 * Set attributes specified only for that window/class.
451 * This might do duplicate work with the 1st wDefaultFillAttributes().
453 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
454 &wwin->user_flags, &wwin->defined_user_flags,
455 False);
457 * Sanity checks for attributes that depend on other attributes
459 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
460 wwin->user_flags.emulate_appicon = 0;
462 if (wwin->main_window!=None) {
463 WApplication *wapp = wApplicationOf(wwin->main_window);
464 if (wapp && !wapp->flags.emulated)
465 wwin->user_flags.emulate_appicon = 0;
468 if (wwin->transient_for!=None
469 && wwin->transient_for!=wwin->screen_ptr->root_win)
470 wwin->user_flags.emulate_appicon = 0;
472 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
473 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
474 wwin->user_flags.sunken = 0;
476 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
482 Bool
483 wWindowCanReceiveFocus(WWindow *wwin)
485 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
486 return False;
487 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
488 return False;
489 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
490 return False;
492 return True;
496 Bool
497 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
499 int w1, h1, w2, h2;
501 w1 = wwin->frame->core->width;
502 h1 = wwin->frame->core->height;
503 w2 = obscured->frame->core->width;
504 h2 = obscured->frame->core->height;
506 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
507 && wwin->frame->workspace != obscured->frame->workspace)
508 return False;
510 if (wwin->frame_x + w1 < obscured->frame_x
511 || wwin->frame_y + h1 < obscured->frame_y
512 || wwin->frame_x > obscured->frame_x + w2
513 || wwin->frame_y > obscured->frame_y + h2) {
514 return False;
517 return True;
523 *----------------------------------------------------------------
524 * wManageWindow--
525 * reparents the window and allocates a descriptor for it.
526 * Window manager hints and other hints are fetched to configure
527 * the window decoration attributes and others. User preferences
528 * for the window are used if available, to configure window
529 * decorations and some behaviour.
530 * If in startup, windows that are override redirect,
531 * unmapped and never were managed and are Withdrawn are not
532 * managed.
534 * Returns:
535 * the new window descriptor
537 * Side effects:
538 * The window is reparented and appropriate notification
539 * is done to the client. Input mask for the window is setup.
540 * The window descriptor is also associated with various window
541 * contexts and inserted in the head of the window list.
542 * Event handler contexts are associated for some objects
543 * (buttons, titlebar and resizebar)
545 *----------------------------------------------------------------
547 WWindow*
548 wManageWindow(WScreen *scr, Window window)
550 WWindow *wwin;
551 int x, y;
552 unsigned width, height;
553 XWindowAttributes wattribs;
554 XSetWindowAttributes attribs;
555 WWindowState *win_state;
556 WWindow *transientOwner = NULL;
557 int window_level;
558 int wm_state;
559 int foo;
560 int workspace = -1;
561 char *title;
562 Bool withdraw = False;
564 /* mutex. */
565 /* XGrabServer(dpy); */
566 XSync(dpy, False);
567 /* make sure the window is still there */
568 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
569 XUngrabServer(dpy);
570 return NULL;
573 /* if it's an override-redirect, ignore it */
574 if (wattribs.override_redirect) {
575 XUngrabServer(dpy);
576 return NULL;
579 wm_state = PropGetWindowState(window);
581 /* if it's startup and the window is unmapped, don't manage it */
582 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
583 XUngrabServer(dpy);
584 return NULL;
587 if (!wFetchName(dpy, window, &title)) {
588 title = NULL;
591 #ifdef KWM_HINTS
592 if (title && !wKWMManageableClient(scr, window, title)) {
593 XFree(title);
594 XUngrabServer(dpy);
595 return NULL;
597 #endif /* KWM_HINTS */
600 wwin = wWindowCreate();
602 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
604 #ifdef DEBUG
605 printf("managing window %x\n", (unsigned)window);
606 #endif
608 #ifdef SHAPE
609 if (wShapeSupported) {
610 int junk;
611 unsigned int ujunk;
612 int b_shaped;
614 XShapeSelectInput(dpy, window, ShapeNotifyMask);
615 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
616 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
617 wwin->flags.shaped = b_shaped;
619 #endif
622 *--------------------------------------------------
624 * Get hints and other information in properties
626 *--------------------------------------------------
628 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
630 /* setup descriptor */
631 wwin->client_win = window;
632 wwin->screen_ptr = scr;
634 wwin->old_border_width = wattribs.border_width;
636 wwin->event_mask = CLIENT_EVENTS;
637 attribs.event_mask = CLIENT_EVENTS;
638 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
639 attribs.save_under = False;
640 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
641 |CWSaveUnder, &attribs);
642 XSetWindowBorderWidth(dpy, window, 0);
644 /* get hints from GNUstep app */
645 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
646 wwin->flags.is_gnustep = 1;
648 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
649 wwin->wm_gnustep_attr = NULL;
652 wwin->client_leader = PropGetClientLeader(window);
653 if (wwin->client_leader!=None)
654 wwin->main_window = wwin->client_leader;
656 wwin->wm_hints = XGetWMHints(dpy, window);
658 if (wwin->wm_hints) {
659 if (wwin->wm_hints->flags & StateHint) {
661 if (wwin->wm_hints->initial_state == IconicState) {
663 wwin->flags.miniaturized = 1;
665 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
667 withdraw = True;
671 if (wwin->wm_hints->flags & WindowGroupHint) {
672 wwin->group_id = wwin->wm_hints->window_group;
673 /* window_group has priority over CLIENT_LEADER */
674 wwin->main_window = wwin->group_id;
675 } else {
676 wwin->group_id = None;
679 if (wwin->wm_hints->flags & UrgencyHint)
680 wwin->flags.urgent = 1;
681 } else {
682 wwin->group_id = None;
685 PropGetProtocols(window, &wwin->protocols);
687 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
688 wwin->transient_for = None;
689 } else {
690 if (wwin->transient_for==None || wwin->transient_for==window) {
691 wwin->transient_for = scr->root_win;
692 } else {
693 transientOwner = wWindowFor(wwin->transient_for);
694 if (transientOwner && transientOwner->main_window!=None) {
695 wwin->main_window = transientOwner->main_window;
696 } /*else {
697 wwin->main_window = None;
702 /* guess the focus mode */
703 wwin->focus_mode = getFocusMode(wwin);
705 /* get geometry stuff */
706 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
708 /* get colormap windows */
709 GetColormapWindows(wwin);
712 *--------------------------------------------------
714 * Setup the decoration/window attributes and
715 * geometry
717 *--------------------------------------------------
720 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
722 #ifdef OLWM_HINTS
723 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
724 && wwin->group_id != None && wwin->group_id != window) {
726 transientOwner = wWindowFor(wwin->group_id);
728 if (transientOwner) {
729 wwin->transient_for = wwin->group_id;
731 /* transients can't be iconified or maximized */
732 if (wwin->transient_for) {
733 WSETUFLAG(wwin, no_miniaturizable, 1);
734 WSETUFLAG(wwin, no_miniaturize_button, 1);
738 #endif /* OLWM_HINTS */
741 * Make broken apps behave as a nice app.
743 if (WFLAGP(wwin, emulate_appicon)) {
744 wwin->main_window = wwin->client_win;
748 *------------------------------------------------------------
750 * Setup the initial state of the window
752 *------------------------------------------------------------
755 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
756 wwin->flags.miniaturized = 1;
759 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
760 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
764 Bool bla;
766 bla = False;
767 #ifdef GNOME_STUFF
768 bla = wGNOMECheckInitialClientState(wwin);
769 #endif
770 #ifdef KWM_HINTS
771 if (!bla)
772 wKWMCheckClientInitialState(wwin);
773 #endif
776 /* apply previous state if it exists and we're in startup */
777 if (scr->flags.startup && wm_state >= 0) {
779 if (wm_state == IconicState) {
781 wwin->flags.miniaturized = 1;
783 } else if (wm_state == WithdrawnState) {
785 withdraw = True;
789 /* if there is a saved state (from file), restore it */
790 win_state = NULL;
791 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
792 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
793 } else {
794 win_state = (WWindowState*)wWindowGetSavedState(window);
796 if (win_state && !withdraw) {
798 if (win_state->state->hidden>0)
799 wwin->flags.hidden = win_state->state->hidden;
801 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
802 wwin->flags.shaded = win_state->state->shaded;
804 if (win_state->state->miniaturized>0 &&
805 !WFLAGP(wwin, no_miniaturizable)) {
806 wwin->flags.miniaturized = win_state->state->miniaturized;
809 if (!IS_OMNIPRESENT(wwin)) {
810 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
811 wwin->wm_class);
812 if (w < 0 || w >= scr->workspace_count) {
813 workspace = win_state->state->workspace;
814 if (workspace >= scr->workspace_count)
815 workspace = scr->current_workspace;
816 } else {
817 workspace = w;
819 } else {
820 workspace = scr->current_workspace;
824 /* if we're restarting, restore saved state (from hints).
825 * This will overwrite previous */
827 WSavedState *wstate;
829 if (getSavedState(window, &wstate)) {
830 wwin->flags.shaded = wstate->shaded;
831 wwin->flags.hidden = wstate->hidden;
832 wwin->flags.miniaturized = wstate->miniaturized;
833 wwin->flags.maximized = wstate->maximized;
834 if (wwin->flags.maximized) {
835 wwin->old_geometry.x = wstate->x;
836 wwin->old_geometry.y = wstate->y;
837 wwin->old_geometry.width = wstate->w;
838 wwin->old_geometry.height = wstate->h;
841 workspace = wstate->workspace;
842 } else {
843 wstate = NULL;
846 /* restore window shortcut */
847 if (wstate != NULL || win_state != NULL) {
848 unsigned mask = 0;
850 if (win_state != NULL)
851 mask = win_state->state->window_shortcuts;
853 if (wstate != NULL && mask == 0)
854 mask = wstate->window_shortcuts;
856 if (mask > 0) {
857 int i;
859 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
860 if (mask & (1<<i)) {
861 if (!scr->shortcutWindows[i])
862 scr->shortcutWindows[i] = WMCreateBag(4);
864 WMPutInBag(scr->shortcutWindows[i], wwin);
869 if (wstate != NULL) {
870 wfree(wstate);
874 /* don't let transients start miniaturized if their owners are not */
875 if (transientOwner && !transientOwner->flags.miniaturized
876 && wwin->flags.miniaturized && !withdraw) {
877 wwin->flags.miniaturized = 0;
878 if (wwin->wm_hints)
879 wwin->wm_hints->initial_state = NormalState;
882 /* set workspace on which the window starts */
883 if (workspace >= 0) {
884 if (workspace > scr->workspace_count-1) {
885 workspace = workspace % scr->workspace_count;
887 } else {
888 int w;
890 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
892 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
894 workspace = w;
896 } else {
897 if (wPreferences.open_transients_with_parent && transientOwner) {
899 workspace = transientOwner->frame->workspace;
901 } else {
903 workspace = scr->current_workspace;
908 /* setup window geometry */
909 if (win_state && win_state->state->w > 0) {
910 width = win_state->state->w;
911 height = win_state->state->h;
913 wWindowConstrainSize(wwin, &width, &height);
915 /* do not ask for window placement if the window is
916 * transient, during startup, if the initial workspace is another one
917 * or if the window wants to start iconic.
918 * If geometry was saved, restore it. */
920 Bool dontBring = False;
922 if (win_state && win_state->state->w > 0) {
923 x = win_state->state->x;
924 y = win_state->state->y;
925 } else if ((wwin->transient_for==None
926 || wPreferences.window_placement!=WPM_MANUAL)
927 && !scr->flags.startup
928 && workspace == scr->current_workspace
929 && !wwin->flags.miniaturized
930 && !wwin->flags.maximized
931 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
933 if (transientOwner && transientOwner->flags.mapped) {
934 int offs = WMAX(20, 2*transientOwner->frame->top_width);
936 x = transientOwner->frame_x +
937 abs((transientOwner->frame->core->width - width)/2) + offs;
938 y = transientOwner->frame_y +
939 abs((transientOwner->frame->core->height - height)/3) + offs;
941 if (x < 0)
942 x = 0;
943 else if (x + width > scr->scr_width)
944 x = scr->scr_width - width;
946 if (y < 0)
947 y = 0;
948 else if (y + height > scr->scr_height)
949 y = scr->scr_height - height;
950 } else {
951 PlaceWindow(wwin, &x, &y, width, height);
953 if (wPreferences.window_placement == WPM_MANUAL)
954 dontBring = True;
957 if (WFLAGP(wwin, dont_move_off) && dontBring)
958 wScreenBringInside(scr, &x, &y, width, height);
961 if (wwin->flags.urgent) {
962 if (!IS_OMNIPRESENT(wwin))
963 wwin->flags.omnipresent ^= 1;
967 *--------------------------------------------------
969 * Create frame, borders and do reparenting
971 *--------------------------------------------------
973 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
974 #ifdef XKB_BUTTON_HINT
975 if (wPreferences.modelock)
976 foo |= WFF_LANGUAGE_BUTTON;
977 #endif
978 if (!WFLAGP(wwin, no_titlebar))
979 foo |= WFF_TITLEBAR;
980 if (!WFLAGP(wwin, no_resizebar))
981 foo |= WFF_RESIZEBAR;
982 if (!WFLAGP(wwin, no_border))
983 foo |= WFF_BORDER;
985 wwin->frame = wFrameWindowCreate(scr, window_level,
986 x, y, width, height,
987 &wPreferences.window_title_clearance, foo,
988 scr->window_title_texture,
989 scr->resizebar_texture,
990 scr->window_title_pixel,
991 &scr->window_title_gc,
992 &scr->title_font);
994 wwin->frame->flags.is_client_window_frame = 1;
995 wwin->frame->flags.justification = wPreferences.title_justification;
997 /* setup button images */
998 wWindowUpdateButtonImages(wwin);
1000 /* hide unused buttons */
1001 foo = 0;
1002 if (WFLAGP(wwin, no_close_button))
1003 foo |= WFF_RIGHT_BUTTON;
1004 if (WFLAGP(wwin, no_miniaturize_button))
1005 foo |= WFF_LEFT_BUTTON;
1006 #ifdef XKB_BUTTON_HINT
1007 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1008 foo |= WFF_LANGUAGE_BUTTON;
1009 #endif
1010 if (foo!=0)
1011 wFrameWindowHideButton(wwin->frame, foo);
1013 wwin->frame->child = wwin;
1015 #ifdef OLWM_HINTS
1016 /* emulate olwm push pin. Make the button look as pushed-in for
1017 * the pinned-out state. When the button is clicked, it will
1018 * revert to the normal position, which means the pin is pinned-in.
1020 if (wwin->flags.olwm_push_pin_out)
1021 wFrameWindowUpdatePushButton(wwin->frame, True);
1022 #endif /* OLWM_HINTS */
1025 wwin->frame->workspace = workspace;
1027 wwin->frame->on_click_left = windowIconifyClick;
1028 #ifdef XKB_BUTTON_HINT
1029 if (wPreferences.modelock)
1030 wwin->frame->on_click_language = windowLanguageClick;
1031 #endif
1033 wwin->frame->on_click_right = windowCloseClick;
1034 wwin->frame->on_dblclick_right = windowCloseDblClick;
1036 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1037 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1039 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1042 XSelectInput(dpy, wwin->client_win,
1043 wwin->event_mask & ~StructureNotifyMask);
1045 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1046 0, wwin->frame->top_width);
1048 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1052 int gx, gy;
1054 wClientGetGravityOffsets(wwin, &gx, &gy);
1056 /* if gravity is to the south, account for the border sizes */
1057 if (gy > 0)
1058 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1062 * wWindowConfigure() will init the client window's size
1063 * (wwin->client.{width,height}) and all other geometry
1064 * related variables (frame_x,frame_y)
1066 wWindowConfigure(wwin, x, y, width, height);
1068 /* to make sure the window receives it's new position after reparenting */
1069 wWindowSynthConfigureNotify(wwin);
1072 *--------------------------------------------------
1074 * Setup descriptors and save window to internal
1075 * lists
1077 *--------------------------------------------------
1080 if (wwin->main_window!=None) {
1081 WApplication *app;
1082 WWindow *leader;
1084 /* Leader windows do not necessary set themselves as leaders.
1085 * If this is the case, point the leader of this window to
1086 * itself */
1087 leader = wWindowFor(wwin->main_window);
1088 if (leader && leader->main_window==None) {
1089 leader->main_window = leader->client_win;
1091 app = wApplicationCreate(scr, wwin->main_window);
1092 if (app) {
1093 app->last_workspace = workspace;
1096 * Do application specific stuff, like setting application
1097 * wide attributes.
1100 if (wwin->flags.hidden) {
1101 /* if the window was set to hidden because it was hidden
1102 * in a previous incarnation and that state was restored */
1103 app->flags.hidden = 1;
1106 if (app->flags.hidden) {
1107 wwin->flags.hidden = 1;
1112 /* setup the frame descriptor */
1113 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1114 wwin->frame->core->descriptor.parent = wwin;
1115 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1117 /* don't let windows go away if we die */
1118 XAddToSaveSet(dpy, window);
1120 XLowerWindow(dpy, window);
1122 /* if window is in this workspace and should be mapped, then map it */
1123 if (!wwin->flags.miniaturized
1124 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1125 && !wwin->flags.hidden && !withdraw) {
1127 /* The following "if" is to avoid crashing of clients that expect
1128 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1129 * after the return from this function.
1131 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1132 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1133 } else {
1134 wClientSetState(wwin, NormalState, None);
1137 #if 0
1138 /* if not auto focus, then map the window under the currently
1139 * focused window */
1140 #define _WIDTH(w) (w)->frame->core->width
1141 #define _HEIGHT(w) (w)->frame->core->height
1142 if (!wPreferences.auto_focus && scr->focused_window
1143 && !scr->flags.startup && !transientOwner
1144 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1145 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1146 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1147 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1148 || wwin->flags.maximized)) {
1149 MoveInStackListUnder(scr->focused_window->frame->core,
1150 wwin->frame->core);
1152 #undef _WIDTH
1153 #undef _HEIGHT
1155 #endif
1157 if (wPreferences.superfluous && !wPreferences.no_animations
1158 && !scr->flags.startup && wwin->transient_for==None
1160 * The brain damaged idiotic non-click to focus modes will
1161 * have trouble with this because:
1163 * 1. window is created and mapped by the client
1164 * 2. window is mapped by wmaker in small size
1165 * 3. window is animated to grow to normal size
1166 * 4. this function returns to normal event loop
1167 * 5. eventually, the EnterNotify event that would trigger
1168 * the window focusing (if the mouse is over that window)
1169 * will be processed by wmaker.
1170 * But since this event will be rather delayed
1171 * (step 3 has a large delay) the time when the event ocurred
1172 * and when it is processed, the client that owns that window
1173 * will reject the XSetInputFocus() for it.
1175 && (wPreferences.focus_mode==WKF_CLICK
1176 || wPreferences.auto_focus)) {
1177 DoWindowBirth(wwin);
1180 wWindowMap(wwin);
1183 /* setup stacking descriptor */
1184 if (transientOwner) {
1185 /* && wPreferences.on_top_transients */
1186 if (transientOwner) {
1187 wwin->frame->core->stacking->child_of =
1188 transientOwner->frame->core;
1190 } else {
1191 wwin->frame->core->stacking->child_of = NULL;
1195 if (!scr->focused_window) {
1196 /* first window on the list */
1197 wwin->next = NULL;
1198 wwin->prev = NULL;
1199 scr->focused_window = wwin;
1200 } else {
1201 WWindow *tmp;
1203 /* add window at beginning of focus window list */
1204 tmp = scr->focused_window;
1205 while (tmp->prev)
1206 tmp = tmp->prev;
1207 tmp->prev = wwin;
1208 wwin->next = tmp;
1209 wwin->prev = NULL;
1212 /* Update name must come after WApplication stuff is done */
1213 wWindowUpdateName(wwin, title);
1214 if (title)
1215 XFree(title);
1218 #ifdef GNOME_STUFF
1219 wGNOMEUpdateClientStateHint(wwin, True);
1220 #endif
1221 #ifdef KWM_HINTS
1222 wKWMUpdateClientWorkspace(wwin);
1223 wKWMUpdateClientStateHint(wwin, KWMAllFlags);
1224 #endif
1226 XUngrabServer(dpy);
1229 *--------------------------------------------------
1231 * Final preparations before window is ready to go
1233 *--------------------------------------------------
1236 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1239 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1240 && !wwin->flags.hidden) {
1241 if (((transientOwner && transientOwner->flags.focused)
1242 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1243 wSetFocusTo(scr, wwin);
1245 wWindowResetMouseGrabs(wwin);
1247 if (!WFLAGP(wwin, no_bind_keys)) {
1248 wWindowSetKeyGrabs(wwin);
1250 #ifdef GNOME_STUFF
1251 wGNOMEUpdateClientListHint(scr);
1252 #endif
1253 #ifdef KWM_HINTS
1254 wwin->flags.kwm_managed = 1;
1256 wKWMSendEventMessage(wwin, WKWMAddWindow);
1257 #endif
1259 wColormapInstallForWindow(scr, scr->cmap_window);
1261 UpdateSwitchMenu(scr, wwin, ACTION_ADD);
1263 #ifdef OLWM_HINTS
1264 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1265 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1267 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1268 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1269 wwin->frame_y);
1271 #endif
1274 *------------------------------------------------------------
1275 * Setup Notification Observers
1276 *------------------------------------------------------------
1278 WMAddNotificationObserver(appearanceObserver, wwin,
1279 WNWindowAppearanceSettingsChanged, wwin);
1283 *--------------------------------------------------
1285 * Cleanup temporary stuff
1287 *--------------------------------------------------
1290 if (win_state)
1291 wWindowDeleteSavedState(win_state);
1293 /* If the window must be withdrawed, then do it now.
1294 * Must do some optimization, 'though */
1295 if (withdraw) {
1296 wwin->flags.mapped = 0;
1297 wClientSetState(wwin, WithdrawnState, None);
1298 wUnmanageWindow(wwin, True, False);
1299 wwin = NULL;
1302 return wwin;
1309 WWindow*
1310 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1311 char *title, int x, int y, int width, int height)
1313 WWindow *wwin;
1314 int foo;
1316 wwin = wWindowCreate();
1318 WMAddNotificationObserver(appearanceObserver, wwin,
1319 WNWindowAppearanceSettingsChanged, wwin);
1321 wwin->flags.internal_window = 1;
1323 WSETUFLAG(wwin, omnipresent, 1);
1324 WSETUFLAG(wwin, no_shadeable, 1);
1325 WSETUFLAG(wwin, no_resizable, 1);
1326 WSETUFLAG(wwin, no_miniaturizable, 1);
1328 wwin->focus_mode = WFM_PASSIVE;
1330 wwin->client_win = window;
1331 wwin->screen_ptr = scr;
1333 wwin->transient_for = owner;
1335 wwin->client.x = x;
1336 wwin->client.y = y;
1337 wwin->client.width = width;
1338 wwin->client.height = height;
1340 wwin->frame_x = wwin->client.x;
1341 wwin->frame_y = wwin->client.y;
1344 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1345 foo |= WFF_TITLEBAR;
1346 #ifdef XKB_BUTTON_HINT
1347 foo |= WFF_LANGUAGE_BUTTON;
1348 #endif
1350 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1351 wwin->frame_x, wwin->frame_y,
1352 width, height,
1353 &wPreferences.window_title_clearance, foo,
1354 scr->window_title_texture,
1355 scr->resizebar_texture,
1356 scr->window_title_pixel,
1357 &scr->window_title_gc,
1358 &scr->title_font);
1360 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1362 wwin->frame->flags.is_client_window_frame = 1;
1363 wwin->frame->flags.justification = wPreferences.title_justification;
1365 wFrameWindowChangeTitle(wwin->frame, title);
1367 /* setup button images */
1368 wWindowUpdateButtonImages(wwin);
1370 /* hide buttons */
1371 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1373 wwin->frame->child = wwin;
1375 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1377 #ifdef XKB_BUTTON_HINT
1378 if (wPreferences.modelock)
1379 wwin->frame->on_click_language = windowLanguageClick;
1380 #endif
1382 wwin->frame->on_click_right = windowCloseClick;
1384 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1385 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1387 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1389 wwin->client.y += wwin->frame->top_width;
1390 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1391 0, wwin->frame->top_width);
1393 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1394 wwin->client.width, wwin->client.height);
1396 /* setup the frame descriptor */
1397 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1398 wwin->frame->core->descriptor.parent = wwin;
1399 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1402 XLowerWindow(dpy, window);
1403 XMapSubwindows(dpy, wwin->frame->core->window);
1405 /* setup stacking descriptor */
1406 if (
1407 #ifdef removed
1408 wPreferences.on_top_transients &&
1409 #endif
1410 wwin->transient_for!=None
1411 && wwin->transient_for!=scr->root_win) {
1412 WWindow *tmp;
1413 tmp = wWindowFor(wwin->transient_for);
1414 if (tmp)
1415 wwin->frame->core->stacking->child_of = tmp->frame->core;
1416 } else {
1417 wwin->frame->core->stacking->child_of = NULL;
1421 if (!scr->focused_window) {
1422 /* first window on the list */
1423 wwin->next = NULL;
1424 wwin->prev = NULL;
1425 scr->focused_window = wwin;
1426 } else {
1427 WWindow *tmp;
1429 /* add window at beginning of focus window list */
1430 tmp = scr->focused_window;
1431 while (tmp->prev)
1432 tmp = tmp->prev;
1433 tmp->prev = wwin;
1434 wwin->next = tmp;
1435 wwin->prev = NULL;
1438 if (wwin->flags.is_gnustep == 0)
1439 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1441 /* if (wPreferences.auto_focus)*/
1442 wSetFocusTo(scr, wwin);
1444 wWindowResetMouseGrabs(wwin);
1446 wWindowSetKeyGrabs(wwin);
1448 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_ADD);
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 #ifdef KWM_HINTS
1478 wwin->frame->workspace = -1;
1480 wKWMUpdateClientWorkspace(wwin);
1481 #endif
1483 /* First close attribute editor window if open */
1484 if (wwin->flags.inspector_open) {
1485 wCloseInspectorForWindow(wwin);
1488 /* Close window menu if it's open for this window */
1489 if (wwin->flags.menu_open_for_me) {
1490 CloseWindowMenu(scr);
1493 if (!destroyed) {
1494 if (!wwin->flags.internal_window)
1495 XRemoveFromSaveSet(dpy, wwin->client_win);
1497 XSelectInput(dpy, wwin->client_win, NoEventMask);
1499 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1500 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1503 XUnmapWindow(dpy, frame->window);
1505 XUnmapWindow(dpy, wwin->client_win);
1507 /* deselect window */
1508 wSelectWindow(wwin, False);
1510 /* remove all pending events on window */
1511 /* I think this only matters for autoraise */
1512 if (wPreferences.raise_delay)
1513 WMDeleteTimerWithClientData(wwin->frame->core);
1515 XFlush(dpy);
1517 UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);
1519 /* reparent the window back to the root */
1520 if (restore)
1521 wClientRestore(wwin);
1523 if (wwin->transient_for!=scr->root_win) {
1524 owner = wWindowFor(wwin->transient_for);
1525 if (owner) {
1526 if (!owner->flags.semi_focused) {
1527 owner = NULL;
1528 } else {
1529 owner->flags.semi_focused = 0;
1534 wasFocused = wwin->flags.focused;
1536 /* remove from window focus list */
1537 if (!wwin->prev && !wwin->next) {
1538 /* was the only window */
1539 scr->focused_window = NULL;
1540 newFocusedWindow = NULL;
1541 } else {
1542 WWindow *tmp;
1544 if (wwin->prev)
1545 wwin->prev->next = wwin->next;
1546 if (wwin->next)
1547 wwin->next->prev = wwin->prev;
1548 else {
1549 scr->focused_window = wwin->prev;
1550 scr->focused_window->next = NULL;
1553 if (wPreferences.focus_mode==WKF_CLICK) {
1555 /* if in click to focus mode and the window
1556 * was a transient, focus the owner window
1558 tmp = NULL;
1559 if (wPreferences.focus_mode==WKF_CLICK) {
1560 tmp = wWindowFor(wwin->transient_for);
1561 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1562 tmp = NULL;
1565 /* otherwise, focus the next one in the focus list */
1566 if (!tmp) {
1567 tmp = scr->focused_window;
1568 while (tmp) { /* look for one in the window list first */
1569 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1570 && (tmp->flags.mapped || tmp->flags.shaded))
1571 break;
1572 tmp = tmp->prev;
1574 if (!tmp) { /* if unsuccessful, choose any focusable window */
1575 tmp = scr->focused_window;
1576 while (tmp) {
1577 if (!WFLAGP(tmp, no_focusable)
1578 && (tmp->flags.mapped || tmp->flags.shaded))
1579 break;
1580 tmp = tmp->prev;
1585 newFocusedWindow = tmp;
1587 } else if (wPreferences.focus_mode==WKF_SLOPPY
1588 || wPreferences.focus_mode==WKF_POINTER) {
1589 unsigned int mask;
1590 int foo;
1591 Window bar, win;
1593 /* This is to let the root window get the keyboard input
1594 * if Sloppy focus mode and no other window get focus.
1595 * This way keybindings will not freeze.
1597 tmp = NULL;
1598 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1599 &foo, &foo, &foo, &foo, &mask))
1600 tmp = wWindowFor(win);
1601 if (tmp == wwin)
1602 tmp = NULL;
1603 newFocusedWindow = tmp;
1604 } else {
1605 newFocusedWindow = NULL;
1609 if (!wwin->flags.internal_window) {
1610 #ifdef GNOME_STUFF
1611 wGNOMERemoveClient(wwin);
1612 #endif
1613 #ifdef KWM_HINTS
1614 wKWMSendEventMessage(wwin, WKWMRemoveWindow);
1615 #endif
1618 #ifdef DEBUG
1619 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1620 (unsigned)frame->window);
1621 #endif
1623 if (wasFocused) {
1624 if (newFocusedWindow != owner && owner) {
1625 if (wwin->flags.is_gnustep == 0)
1626 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1628 wSetFocusTo(scr, newFocusedWindow);
1630 wWindowDestroy(wwin);
1631 XFlush(dpy);
1635 void
1636 wWindowMap(WWindow *wwin)
1638 XMapWindow(dpy, wwin->frame->core->window);
1639 if (!wwin->flags.shaded) {
1640 /* window will be remapped when getting MapNotify */
1641 XSelectInput(dpy, wwin->client_win,
1642 wwin->event_mask & ~StructureNotifyMask);
1643 XMapWindow(dpy, wwin->client_win);
1644 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1646 wwin->flags.mapped = 1;
1651 void
1652 wWindowUnmap(WWindow *wwin)
1654 wwin->flags.mapped = 0;
1656 /* prevent window withdrawal when getting UnmapNotify */
1657 XSelectInput(dpy, wwin->client_win,
1658 wwin->event_mask & ~StructureNotifyMask);
1659 XUnmapWindow(dpy, wwin->client_win);
1660 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1662 XUnmapWindow(dpy, wwin->frame->core->window);
1667 void
1668 wWindowFocus(WWindow *wwin, WWindow *owin)
1670 WWindow *nowner;
1671 WWindow *oowner;
1673 #ifdef KEEP_XKB_LOCK_STATUS
1674 if (wPreferences.modelock) {
1675 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1677 #endif /* KEEP_XKB_LOCK_STATUS */
1679 wwin->flags.semi_focused = 0;
1681 if (wwin->flags.is_gnustep == 0)
1682 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1684 wwin->flags.focused = 1;
1686 wWindowResetMouseGrabs(wwin);
1688 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1690 if (owin == wwin || !owin)
1691 return;
1693 nowner = wWindowFor(wwin->transient_for);
1695 /* new window is a transient for the old window */
1696 if (nowner == owin) {
1697 owin->flags.semi_focused = 1;
1698 wWindowUnfocus(nowner);
1699 return;
1702 oowner = wWindowFor(owin->transient_for);
1704 /* new window is owner of old window */
1705 if (wwin == oowner) {
1706 wWindowUnfocus(owin);
1707 return;
1710 if (!nowner) {
1711 wWindowUnfocus(owin);
1712 return;
1715 /* new window has same owner of old window */
1716 if (oowner == nowner) {
1717 /* prevent unfocusing of owner */
1718 oowner->flags.semi_focused = 0;
1719 wWindowUnfocus(owin);
1720 oowner->flags.semi_focused = 1;
1722 return;
1725 /* nowner != NULL && oowner != nowner */
1726 nowner->flags.semi_focused = 1;
1727 wWindowUnfocus(nowner);
1728 wWindowUnfocus(owin);
1732 void
1733 wWindowUnfocus(WWindow *wwin)
1735 CloseWindowMenu(wwin->screen_ptr);
1737 if (wwin->flags.is_gnustep == 0)
1738 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1739 ? WS_PFOCUSED : WS_UNFOCUSED);
1741 if (wwin->transient_for!=None
1742 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1743 WWindow *owner;
1744 owner = wWindowFor(wwin->transient_for);
1745 if (owner && owner->flags.semi_focused) {
1746 owner->flags.semi_focused = 0;
1747 if (owner->flags.mapped || owner->flags.shaded) {
1748 wWindowUnfocus(owner);
1749 wFrameWindowPaint(owner->frame);
1753 wwin->flags.focused = 0;
1755 wWindowResetMouseGrabs(wwin);
1757 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1762 void
1763 wWindowUpdateName(WWindow *wwin, char *newTitle)
1765 WApplication *app = wApplicationOf(wwin->main_window);
1766 int instIndex = 0;
1767 Bool res;
1768 char prefix[32] = "";
1769 char *tmp, *title;
1771 if (!wwin->frame)
1772 return;
1774 if (app)
1775 instIndex = wApplicationIndexOfInstance(app);
1778 wwin->flags.wm_name_changed = 1;
1780 if (!newTitle) {
1781 /* the hint was removed */
1782 title = DEF_WINDOW_TITLE;
1784 #ifdef KWM_HINTS
1785 wKWMSendEventMessage(wwin, WKWMChangedClient);
1786 #endif
1787 } else {
1788 title = newTitle;
1791 if (instIndex > 0) {
1792 sprintf(prefix, " [%i]", instIndex);
1794 title = wstrconcat(title, prefix);
1797 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1798 /* only update the menu if the title has actually changed */
1799 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE);
1800 #ifdef KWM_HINTS
1801 wKWMSendEventMessage(wwin, WKWMChangedClient);
1802 #endif
1804 if (instIndex > 0)
1805 wfree(title);
1811 *----------------------------------------------------------------------
1813 * wWindowConstrainSize--
1814 * Constrains size for the client window, taking the maximal size,
1815 * window resize increments and other size hints into account.
1817 * Returns:
1818 * The closest size to what was given that the client window can
1819 * have.
1821 *----------------------------------------------------------------------
1823 void
1824 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1826 int width = *nwidth;
1827 int height = *nheight;
1828 int winc = 1;
1829 int hinc = 1;
1830 int minW = 1, minH = 1;
1831 int maxW = wwin->screen_ptr->scr_width*2;
1832 int maxH = wwin->screen_ptr->scr_height*2;
1833 int minAX = -1, minAY = -1;
1834 int maxAX = -1, maxAY = -1;
1835 int baseW = 0;
1836 int baseH = 0;
1838 if (wwin->normal_hints) {
1839 winc = wwin->normal_hints->width_inc;
1840 hinc = wwin->normal_hints->height_inc;
1841 minW = wwin->normal_hints->min_width;
1842 minH = wwin->normal_hints->min_height;
1843 maxW = wwin->normal_hints->max_width;
1844 maxH = wwin->normal_hints->max_height;
1845 if (wwin->normal_hints->flags & PAspect) {
1846 minAX = wwin->normal_hints->min_aspect.x;
1847 minAY = wwin->normal_hints->min_aspect.y;
1848 maxAX = wwin->normal_hints->max_aspect.x;
1849 maxAY = wwin->normal_hints->max_aspect.y;
1853 if (width < minW)
1854 width = minW;
1855 if (height < minH)
1856 height = minH;
1858 if (width > maxW)
1859 width = maxW;
1860 if (height > maxH)
1861 height = maxH;
1863 /* aspect ratio code borrowed from olwm */
1864 if (minAX > 0) {
1865 /* adjust max aspect ratio */
1866 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1867 if (maxAX > maxAY) {
1868 height = (width * maxAY) / maxAX;
1869 if (height > maxH) {
1870 height = maxH;
1871 width = (height * maxAX) / maxAY;
1873 } else {
1874 width = (height * maxAX) / maxAY;
1875 if (width > maxW) {
1876 width = maxW;
1877 height = (width * maxAY) / maxAX;
1882 /* adjust min aspect ratio */
1883 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1884 if (minAX > minAY) {
1885 height = (width * minAY) / minAX;
1886 if (height < minH) {
1887 height = minH;
1888 width = (height * minAX) / minAY;
1890 } else {
1891 width = (height * minAX) / minAY;
1892 if (width < minW) {
1893 width = minW;
1894 height = (width * minAY) / minAX;
1900 if (baseW != 0) {
1901 width = (((width - baseW) / winc) * winc) + baseW;
1902 } else {
1903 width = (((width - minW) / winc) * winc) + minW;
1906 if (baseW != 0) {
1907 height = (((height - baseH) / hinc) * hinc) + baseH;
1908 } else {
1909 height = (((height - minH) / hinc) * hinc) + minH;
1912 /* broken stupid apps may cause preposterous values for these.. */
1913 if (width > 0)
1914 *nwidth = width;
1915 if (height > 0)
1916 *nheight = height;
1920 void
1921 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1923 WScreen *scr = wwin->screen_ptr;
1924 WApplication *wapp;
1925 int unmap = 0;
1927 if (workspace >= scr->workspace_count || workspace < 0
1928 || workspace == wwin->frame->workspace)
1929 return;
1931 if (workspace != scr->current_workspace) {
1932 /* Sent to other workspace. Unmap window */
1933 if ((wwin->flags.mapped
1934 || wwin->flags.shaded
1935 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1936 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1938 wapp = wApplicationOf(wwin->main_window);
1939 if (wapp) {
1940 wapp->last_workspace = workspace;
1942 if (wwin->flags.miniaturized) {
1943 if (wwin->icon) {
1944 XUnmapWindow(dpy, wwin->icon->core->window);
1945 wwin->icon->mapped = 0;
1947 } else {
1948 unmap = 1;
1949 wSetFocusTo(scr, NULL);
1952 } else {
1953 /* brought to current workspace. Map window */
1954 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1955 if (wwin->icon) {
1956 XMapWindow(dpy, wwin->icon->core->window);
1957 wwin->icon->mapped = 1;
1959 } else if (!wwin->flags.mapped &&
1960 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1961 wWindowMap(wwin);
1964 if (!IS_OMNIPRESENT(wwin)) {
1965 wwin->frame->workspace = workspace;
1966 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1968 #ifdef GNOME_STUFF
1969 wGNOMEUpdateClientStateHint(wwin, True);
1970 #endif
1971 #ifdef KWM_HINTS
1972 wKWMUpdateClientWorkspace(wwin);
1973 wKWMSendEventMessage(wwin, WKWMChangedClient);
1974 #endif
1975 if (unmap) {
1976 wWindowUnmap(wwin);
1981 void
1982 wWindowSynthConfigureNotify(WWindow *wwin)
1984 XEvent sevent;
1986 sevent.type = ConfigureNotify;
1987 sevent.xconfigure.display = dpy;
1988 sevent.xconfigure.event = wwin->client_win;
1989 sevent.xconfigure.window = wwin->client_win;
1991 sevent.xconfigure.x = wwin->client.x;
1992 sevent.xconfigure.y = wwin->client.y;
1993 sevent.xconfigure.width = wwin->client.width;
1994 sevent.xconfigure.height = wwin->client.height;
1996 sevent.xconfigure.border_width = wwin->old_border_width;
1997 if (WFLAGP(wwin, no_titlebar))
1998 sevent.xconfigure.above = None;
1999 else
2000 sevent.xconfigure.above = wwin->frame->titlebar->window;
2002 sevent.xconfigure.override_redirect = False;
2003 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2004 #ifdef KWM_HINTS
2005 wKWMSendEventMessage(wwin, WKWMChangedClient);
2006 #endif
2007 XFlush(dpy);
2012 *----------------------------------------------------------------------
2013 * wWindowConfigure--
2014 * Configures the frame, decorations and client window to the
2015 * specified geometry. The geometry is not checked for validity,
2016 * wWindowConstrainSize() must be used for that.
2017 * The size parameters are for the client window, but the position is
2018 * for the frame.
2019 * The client window receives a ConfigureNotify event, according
2020 * to what ICCCM says.
2022 * Returns:
2023 * None
2025 * Side effects:
2026 * Window size and position are changed and client window receives
2027 * a ConfigureNotify event.
2028 *----------------------------------------------------------------------
2030 void
2031 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2032 WWindow *wwin;
2033 int req_x, req_y; /* new position of the frame */
2034 int req_width, req_height; /* new size of the client */
2036 int synth_notify = False;
2037 int resize;
2039 resize = (req_width!=wwin->client.width
2040 || req_height!=wwin->client.height);
2042 * if the window is being moved but not resized then
2043 * send a synthetic ConfigureNotify
2045 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2046 synth_notify = True;
2049 if (WFLAGP(wwin, dont_move_off))
2050 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2051 req_width, req_height);
2052 if (resize) {
2053 if (req_width < MIN_WINDOW_SIZE)
2054 req_width = MIN_WINDOW_SIZE;
2055 if (req_height < MIN_WINDOW_SIZE)
2056 req_height = MIN_WINDOW_SIZE;
2058 /* If growing, resize inner part before frame,
2059 * if shrinking, resize frame before.
2060 * This will prevent the frame (that can have a different color)
2061 * to be exposed, causing flicker */
2062 if (req_height > wwin->frame->core->height
2063 || req_width > wwin->frame->core->width)
2064 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2066 if (wwin->flags.shaded) {
2067 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2068 req_width, wwin->frame->core->height);
2069 wwin->old_geometry.height = req_height;
2070 } else {
2071 int h;
2073 h = req_height + wwin->frame->top_width
2074 + wwin->frame->bottom_width;
2076 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2079 if (!(req_height > wwin->frame->core->height
2080 || req_width > wwin->frame->core->width))
2081 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2083 wwin->client.x = req_x;
2084 wwin->client.y = req_y + wwin->frame->top_width;
2085 wwin->client.width = req_width;
2086 wwin->client.height = req_height;
2087 } else {
2088 wwin->client.x = req_x;
2089 wwin->client.y = req_y + wwin->frame->top_width;
2091 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2093 wwin->frame_x = req_x;
2094 wwin->frame_y = req_y;
2095 if (!WFLAGP(wwin, no_border)) {
2096 wwin->client.x += FRAME_BORDER_WIDTH;
2097 wwin->client.y += FRAME_BORDER_WIDTH;
2100 #ifdef SHAPE
2101 if (wShapeSupported && wwin->flags.shaped && resize) {
2102 wWindowSetShape(wwin);
2104 #endif
2106 if (synth_notify)
2107 wWindowSynthConfigureNotify(wwin);
2108 XFlush(dpy);
2112 void
2113 wWindowMove(wwin, req_x, req_y)
2114 WWindow *wwin;
2115 int req_x, req_y; /* new position of the frame */
2117 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2118 int synth_notify = False;
2120 /* Send a synthetic ConfigureNotify event for every window movement. */
2121 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2122 synth_notify = True;
2124 #else
2125 /* A single synthetic ConfigureNotify event is sent at the end of
2126 * a completed (opaque) movement in moveres.c */
2127 #endif
2129 if (WFLAGP(wwin, dont_move_off))
2130 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2131 wwin->frame->core->width, wwin->frame->core->height);
2133 wwin->client.x = req_x;
2134 wwin->client.y = req_y + wwin->frame->top_width;
2135 if (!WFLAGP(wwin, no_border)) {
2136 wwin->client.x += FRAME_BORDER_WIDTH;
2137 wwin->client.y += FRAME_BORDER_WIDTH;
2140 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2142 wwin->frame_x = req_x;
2143 wwin->frame_y = req_y;
2145 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2146 if (synth_notify)
2147 wWindowSynthConfigureNotify(wwin);
2148 #endif
2152 void
2153 wWindowUpdateButtonImages(WWindow *wwin)
2155 WScreen *scr = wwin->screen_ptr;
2156 Pixmap pixmap, mask;
2157 WFrameWindow *fwin = wwin->frame;
2159 if (WFLAGP(wwin, no_titlebar))
2160 return;
2162 /* miniaturize button */
2164 if (!WFLAGP(wwin, no_miniaturize_button)) {
2165 if (wwin->wm_gnustep_attr
2166 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2167 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2169 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2170 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2171 } else {
2172 mask = None;
2175 if (fwin->lbutton_image
2176 && (fwin->lbutton_image->image != pixmap
2177 || fwin->lbutton_image->mask != mask)) {
2178 wPixmapDestroy(fwin->lbutton_image);
2179 fwin->lbutton_image = NULL;
2182 if (!fwin->lbutton_image) {
2183 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2184 fwin->lbutton_image->client_owned = 1;
2185 fwin->lbutton_image->client_owned_mask = 1;
2187 } else {
2188 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2189 wPixmapDestroy(fwin->lbutton_image);
2191 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2195 #ifdef XKB_BUTTON_HINT
2196 if (!WFLAGP(wwin, no_language_button)) {
2197 if (fwin->languagebutton_image &&
2198 !fwin->languagebutton_image->shared) {
2199 wPixmapDestroy(fwin->languagebutton_image);
2201 fwin->languagebutton_image =
2202 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2204 #endif
2206 /* close button */
2208 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2209 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2211 if (!WFLAGP(wwin, no_close_button)) {
2212 if (wwin->wm_gnustep_attr
2213 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2214 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2216 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2217 mask = wwin->wm_gnustep_attr->close_mask;
2218 else
2219 mask = None;
2221 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2222 || fwin->rbutton_image->mask != mask)) {
2223 wPixmapDestroy(fwin->rbutton_image);
2224 fwin->rbutton_image = NULL;
2227 if (!fwin->rbutton_image) {
2228 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2229 fwin->rbutton_image->client_owned = 1;
2230 fwin->rbutton_image->client_owned_mask = 1;
2233 } else if (WFLAGP(wwin, kill_close)) {
2235 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2236 wPixmapDestroy(fwin->rbutton_image);
2238 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2240 } else if (MGFLAGP(wwin, broken_close)) {
2242 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2243 wPixmapDestroy(fwin->rbutton_image);
2245 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2247 } else {
2249 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2250 wPixmapDestroy(fwin->rbutton_image);
2252 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2256 /* force buttons to be redrawn */
2257 fwin->flags.need_texture_change = 1;
2258 wFrameWindowPaint(fwin);
2263 *---------------------------------------------------------------------------
2264 * wWindowConfigureBorders--
2265 * Update window border configuration according to attribute flags.
2267 *---------------------------------------------------------------------------
2269 void
2270 wWindowConfigureBorders(WWindow *wwin)
2272 if (wwin->frame) {
2273 int flags;
2274 int newy, oldh;
2276 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2277 #ifdef XKB_BUTTON_HINT
2278 flags |= WFF_LANGUAGE_BUTTON;
2279 #endif
2280 if (!WFLAGP(wwin, no_titlebar))
2281 flags |= WFF_TITLEBAR;
2282 if (!WFLAGP(wwin, no_resizebar))
2283 flags |= WFF_RESIZEBAR;
2284 if (!WFLAGP(wwin, no_border))
2285 flags |= WFF_BORDER;
2286 if (wwin->flags.shaded)
2287 flags |= WFF_IS_SHADED;
2289 oldh = wwin->frame->top_width;
2290 wFrameWindowUpdateBorders(wwin->frame, flags);
2291 if (oldh != wwin->frame->top_width) {
2292 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2294 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2295 wWindowConfigure(wwin, wwin->frame_x, newy,
2296 wwin->client.width, wwin->client.height);
2299 flags = 0;
2300 if (!WFLAGP(wwin, no_miniaturize_button)
2301 && wwin->frame->flags.hide_left_button)
2302 flags |= WFF_LEFT_BUTTON;
2304 #ifdef XKB_BUTTON_HINT
2305 if (!WFLAGP(wwin, no_language_button)
2306 && wwin->frame->flags.hide_language_button)
2307 flags |= WFF_LANGUAGE_BUTTON;
2308 #endif
2310 if (!WFLAGP(wwin, no_close_button)
2311 && wwin->frame->flags.hide_right_button)
2312 flags |= WFF_RIGHT_BUTTON;
2314 if (flags!=0) {
2315 wWindowUpdateButtonImages(wwin);
2316 wFrameWindowShowButton(wwin->frame, flags);
2319 flags = 0;
2320 if (WFLAGP(wwin, no_miniaturize_button)
2321 && !wwin->frame->flags.hide_left_button)
2322 flags |= WFF_LEFT_BUTTON;
2324 #ifdef XKB_BUTTON_HINT
2325 if (WFLAGP(wwin, no_language_button)
2326 && !wwin->frame->flags.hide_language_button)
2327 flags |= WFF_LANGUAGE_BUTTON;
2328 #endif
2330 if (WFLAGP(wwin, no_close_button)
2331 && !wwin->frame->flags.hide_right_button)
2332 flags |= WFF_RIGHT_BUTTON;
2334 if (flags!=0)
2335 wFrameWindowHideButton(wwin->frame, flags);
2337 #ifdef SHAPE
2338 if (wShapeSupported && wwin->flags.shaped) {
2339 wWindowSetShape(wwin);
2341 #endif
2346 void
2347 wWindowSaveState(WWindow *wwin)
2349 CARD32 data[10];
2350 int i;
2352 memset(data, 0, sizeof(CARD32)*10);
2353 data[0] = wwin->frame->workspace;
2354 data[1] = wwin->flags.miniaturized;
2355 data[2] = wwin->flags.shaded;
2356 data[3] = wwin->flags.hidden;
2357 data[4] = wwin->flags.maximized;
2358 if (wwin->flags.maximized == 0) {
2359 data[5] = wwin->frame_x;
2360 data[6] = wwin->frame_y;
2361 data[7] = wwin->frame->core->width;
2362 data[8] = wwin->frame->core->height;
2363 } else {
2364 data[5] = wwin->old_geometry.x;
2365 data[6] = wwin->old_geometry.y;
2366 data[7] = wwin->old_geometry.width;
2367 data[8] = wwin->old_geometry.height;
2370 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2371 if (wwin->screen_ptr->shortcutWindows[i] &&
2372 WMCountInBag(wwin->screen_ptr->shortcutWindows[i], wwin))
2373 data[9] |= 1<<i;
2375 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2376 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2377 (unsigned char *)data, 10);
2381 static int
2382 getSavedState(Window window, WSavedState **state)
2384 Atom type_ret;
2385 int fmt_ret;
2386 unsigned long nitems_ret;
2387 unsigned long bytes_after_ret;
2388 CARD32 *data;
2390 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2391 True, _XA_WINDOWMAKER_STATE,
2392 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2393 (unsigned char **)&data)!=Success || !data)
2394 return 0;
2396 *state = malloc(sizeof(WSavedState));
2398 if (*state) {
2399 (*state)->workspace = data[0];
2400 (*state)->miniaturized = data[1];
2401 (*state)->shaded = data[2];
2402 (*state)->hidden = data[3];
2403 (*state)->maximized = data[4];
2404 (*state)->x = data[5];
2405 (*state)->y = data[6];
2406 (*state)->w = data[7];
2407 (*state)->h = data[8];
2408 (*state)->window_shortcuts = data[9];
2410 XFree(data);
2412 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2413 return 1;
2414 else
2415 return 0;
2419 #ifdef SHAPE
2420 void
2421 wWindowClearShape(WWindow *wwin)
2423 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2424 0, wwin->frame->top_width, None, ShapeSet);
2425 XFlush(dpy);
2428 void
2429 wWindowSetShape(WWindow *wwin)
2431 XRectangle rect[2];
2432 int count;
2433 #ifdef OPTIMIZE_SHAPE
2434 XRectangle *rects;
2435 XRectangle *urec;
2436 int ordering;
2438 /* only shape is the client's */
2439 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2440 goto alt_code;
2443 /* Get array of rectangles describing the shape mask */
2444 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2445 &count, &ordering);
2446 if (!rects) {
2447 goto alt_code;
2450 urec = malloc(sizeof(XRectangle)*(count+2));
2451 if (!urec) {
2452 XFree(rects);
2453 goto alt_code;
2456 /* insert our decoration rectangles in the rect list */
2457 memcpy(urec, rects, sizeof(XRectangle)*count);
2458 XFree(rects);
2460 if (!WFLAGP(wwin, no_titlebar)) {
2461 urec[count].x = -1;
2462 urec[count].y = -1 - wwin->frame->top_width;
2463 urec[count].width = wwin->frame->core->width + 2;
2464 urec[count].height = wwin->frame->top_width + 1;
2465 count++;
2467 if (!WFLAGP(wwin, no_resizebar)) {
2468 urec[count].x = -1;
2469 urec[count].y = wwin->frame->core->height
2470 - wwin->frame->bottom_width - wwin->frame->top_width;
2471 urec[count].width = wwin->frame->core->width + 2;
2472 urec[count].height = wwin->frame->bottom_width + 1;
2473 count++;
2476 /* shape our frame window */
2477 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2478 0, wwin->frame->top_width, urec, count,
2479 ShapeSet, Unsorted);
2480 XFlush(dpy);
2481 wfree(urec);
2482 return;
2484 alt_code:
2485 #endif /* OPTIMIZE_SHAPE */
2486 count = 0;
2487 if (!WFLAGP(wwin, no_titlebar)) {
2488 rect[count].x = -1;
2489 rect[count].y = -1;
2490 rect[count].width = wwin->frame->core->width + 2;
2491 rect[count].height = wwin->frame->top_width + 1;
2492 count++;
2494 if (!WFLAGP(wwin, no_resizebar)) {
2495 rect[count].x = -1;
2496 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2497 rect[count].width = wwin->frame->core->width + 2;
2498 rect[count].height = wwin->frame->bottom_width + 1;
2499 count++;
2501 if (count > 0) {
2502 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2503 0, 0, rect, count, ShapeSet, Unsorted);
2505 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2506 0, wwin->frame->top_width, wwin->client_win,
2507 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2508 XFlush(dpy);
2510 #endif /* SHAPE */
2512 /* ====================================================================== */
2514 static FocusMode
2515 getFocusMode(WWindow *wwin)
2517 FocusMode mode;
2519 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2520 if (wwin->wm_hints->input == True) {
2521 if (wwin->protocols.TAKE_FOCUS)
2522 mode = WFM_LOCALLY_ACTIVE;
2523 else
2524 mode = WFM_PASSIVE;
2525 } else {
2526 if (wwin->protocols.TAKE_FOCUS)
2527 mode = WFM_GLOBALLY_ACTIVE;
2528 else
2529 mode = WFM_NO_INPUT;
2531 } else {
2532 mode = WFM_PASSIVE;
2534 return mode;
2538 void
2539 wWindowSetKeyGrabs(WWindow *wwin)
2541 int i;
2542 WShortKey *key;
2544 for (i=0; i<WKBD_LAST; i++) {
2545 key = &wKeyBindings[i];
2547 if (key->keycode==0)
2548 continue;
2549 if (key->modifier!=AnyModifier) {
2550 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2551 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2552 #ifdef NUMLOCK_HACK
2553 /* Also grab all modifier combinations possible that include,
2554 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2555 * work even if the NumLock/ScrollLock key is on.
2557 wHackedGrabKey(key->keycode, key->modifier,
2558 wwin->frame->core->window, True, GrabModeAsync,
2559 GrabModeAsync);
2560 #endif
2562 XGrabKey(dpy, key->keycode, key->modifier,
2563 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2566 #ifndef LITE
2567 wRootMenuBindShortcuts(wwin->frame->core->window);
2568 #endif
2573 void
2574 wWindowResetMouseGrabs(WWindow *wwin)
2576 /* Mouse grabs can't be done on the client window because of
2577 * ICCCM and because clients that try to do the same will crash.
2579 * But there is a problem wich makes tbar buttons of unfocused
2580 * windows not usable as the click goes to the frame window instead
2581 * of the button itself. Must figure a way to fix that.
2584 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2586 if (!WFLAGP(wwin, no_bind_mouse)) {
2587 /* grabs for Meta+drag */
2588 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2589 True, ButtonPressMask, GrabModeSync,
2590 GrabModeAsync, None, None);
2593 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2594 && !wwin->flags.is_gnustep) {
2595 /* the passive grabs to focus the window */
2596 /* if (wPreferences.focus_mode == WKF_CLICK) */
2597 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2598 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2599 None, None);
2601 XFlush(dpy);
2605 void
2606 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2608 if (attr->flags & GSExtraFlagsAttr) {
2609 if (MGFLAGP(wwin, broken_close) !=
2610 (attr->extra_flags & GSDocumentEditedFlag)) {
2611 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2612 wWindowUpdateButtonImages(wwin);
2618 WMagicNumber
2619 wWindowAddSavedState(char *instance, char *class, char *command,
2620 pid_t pid, WSavedState *state)
2622 WWindowState *wstate;
2624 wstate = malloc(sizeof(WWindowState));
2625 if (!wstate)
2626 return 0;
2628 memset(wstate, 0, sizeof(WWindowState));
2629 wstate->pid = pid;
2630 if (instance)
2631 wstate->instance = wstrdup(instance);
2632 if (class)
2633 wstate->class = wstrdup(class);
2634 if (command)
2635 wstate->command = wstrdup(command);
2636 wstate->state = state;
2638 wstate->next = windowState;
2639 windowState = wstate;
2641 #ifdef DEBUG
2642 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2643 class, command);
2644 #endif
2646 return wstate;
2650 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2653 WMagicNumber
2654 wWindowGetSavedState(Window win)
2656 char *instance, *class, *command=NULL;
2657 WWindowState *wstate = windowState;
2658 char **argv;
2659 int argc;
2661 if (!wstate)
2662 return NULL;
2664 if (XGetCommand(dpy, win, &argv, &argc)) {
2665 if (argc > 0)
2666 command = wtokenjoin(argv, argc);
2667 XFreeStringList(argv);
2669 if (!command)
2670 return NULL;
2672 if (PropGetWMClass(win, &class, &instance)) {
2673 while (wstate) {
2674 if (SAME(instance, wstate->instance) &&
2675 SAME(class, wstate->class) &&
2676 SAME(command, wstate->command)) {
2677 break;
2679 wstate = wstate->next;
2681 } else {
2682 wstate = NULL;
2685 #ifdef DEBUG
2686 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2687 class, command);
2688 #endif
2690 if (command) wfree(command);
2691 if (instance) XFree(instance);
2692 if (class) XFree(class);
2694 return wstate;
2698 void
2699 wWindowDeleteSavedState(WMagicNumber id)
2701 WWindowState *tmp, *wstate=(WWindowState*)id;
2703 if (!wstate || !windowState)
2704 return;
2706 tmp = windowState;
2707 if (tmp==wstate) {
2708 windowState = wstate->next;
2709 #ifdef DEBUG
2710 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2711 wstate, wstate->instance, wstate->class, wstate->command);
2712 #endif
2713 if (wstate->instance) wfree(wstate->instance);
2714 if (wstate->class) wfree(wstate->class);
2715 if (wstate->command) wfree(wstate->command);
2716 wfree(wstate->state);
2717 wfree(wstate);
2718 } else {
2719 while (tmp->next) {
2720 if (tmp->next==wstate) {
2721 tmp->next=wstate->next;
2722 #ifdef DEBUG
2723 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2724 wstate, wstate->instance, wstate->class, wstate->command);
2725 #endif
2726 if (wstate->instance) wfree(wstate->instance);
2727 if (wstate->class) wfree(wstate->class);
2728 if (wstate->command) wfree(wstate->command);
2729 wfree(wstate->state);
2730 wfree(wstate);
2731 break;
2733 tmp = tmp->next;
2739 void
2740 wWindowDeleteSavedStatesForPID(pid_t pid)
2742 WWindowState *tmp, *wstate;
2744 if (!windowState)
2745 return;
2747 tmp = windowState;
2748 if (tmp->pid == pid) {
2749 wstate = windowState;
2750 windowState = tmp->next;
2751 #ifdef DEBUG
2752 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2753 wstate, wstate->instance, wstate->class, wstate->command);
2754 #endif
2755 if (wstate->instance) wfree(wstate->instance);
2756 if (wstate->class) wfree(wstate->class);
2757 if (wstate->command) wfree(wstate->command);
2758 wfree(wstate->state);
2759 wfree(wstate);
2760 } else {
2761 while (tmp->next) {
2762 if (tmp->next->pid==pid) {
2763 wstate = tmp->next;
2764 tmp->next = wstate->next;
2765 #ifdef DEBUG
2766 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2767 wstate, wstate->instance, wstate->class, wstate->command);
2768 #endif
2769 if (wstate->instance) wfree(wstate->instance);
2770 if (wstate->class) wfree(wstate->class);
2771 if (wstate->command) wfree(wstate->command);
2772 wfree(wstate->state);
2773 wfree(wstate);
2774 break;
2776 tmp = tmp->next;
2782 /* ====================================================================== */
2784 static void
2785 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2787 WWindow *wwin = data;
2789 #ifndef NUMLOCK_HACK
2790 if ((event->xbutton.state & ValidModMask)
2791 != (event->xbutton.state & ~LockMask)) {
2792 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2793 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2795 #endif
2797 event->xbutton.state &= ValidModMask;
2799 CloseWindowMenu(wwin->screen_ptr);
2801 if (wPreferences.focus_mode==WKF_CLICK
2802 && !(event->xbutton.state&ControlMask)
2803 && !WFLAGP(wwin, no_focusable)) {
2804 wSetFocusTo(wwin->screen_ptr, wwin);
2807 if (event->xbutton.button == Button1)
2808 wRaiseFrame(wwin->frame->core);
2810 if (event->xbutton.window != wwin->frame->resizebar->window) {
2811 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2812 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2813 GrabModeAsync, GrabModeAsync, None,
2814 None, CurrentTime)!=GrabSuccess) {
2815 #ifdef DEBUG0
2816 wwarning("pointer grab failed for window move");
2817 #endif
2818 return;
2822 if (event->xbutton.state & MOD_MASK) {
2823 /* move the window */
2824 wMouseMoveWindow(wwin, event);
2825 XUngrabPointer(dpy, CurrentTime);
2826 } else {
2827 wMouseResizeWindow(wwin, event);
2828 XUngrabPointer(dpy, CurrentTime);
2834 static void
2835 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2837 WWindow *wwin = data;
2839 event->xbutton.state &= ValidModMask;
2841 if (event->xbutton.button==Button1) {
2842 if (event->xbutton.state == 0) {
2843 if (!WFLAGP(wwin, no_shadeable)) {
2844 /* shade window */
2845 if (wwin->flags.shaded)
2846 wUnshadeWindow(wwin);
2847 else
2848 wShadeWindow(wwin);
2850 } else {
2851 int dir = 0;
2853 if (event->xbutton.state & ControlMask)
2854 dir |= MAX_VERTICAL;
2856 if (event->xbutton.state & ShiftMask) {
2857 dir |= MAX_HORIZONTAL;
2858 if (!(event->xbutton.state & ControlMask))
2859 wSelectWindow(wwin, !wwin->flags.selected);
2862 /* maximize window */
2863 if (dir !=0 && !WFLAGP(wwin, no_resizable)) {
2864 int ndir = dir ^ wwin->flags.maximized;
2865 if (wwin->flags.maximized != 0)
2866 wUnmaximizeWindow(wwin);
2867 if (ndir != 0)
2868 wMaximizeWindow(wwin, ndir);
2871 } else if (event->xbutton.button==Button3) {
2872 if (event->xbutton.state & MOD_MASK) {
2873 wHideOtherApplications(wwin);
2875 } else if (event->xbutton.button==Button2) {
2876 wSelectWindow(wwin, !wwin->flags.selected);
2881 static void
2882 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2884 WWindow *wwin = desc->parent;
2886 event->xbutton.state &= ValidModMask;
2888 CloseWindowMenu(wwin->screen_ptr);
2890 if (/*wPreferences.focus_mode==WKF_CLICK
2891 &&*/ !(event->xbutton.state&ControlMask)
2892 && !WFLAGP(wwin, no_focusable)) {
2893 wSetFocusTo(wwin->screen_ptr, wwin);
2895 if (event->xbutton.button == Button1) {
2896 wRaiseFrame(wwin->frame->core);
2899 if (event->xbutton.state & MOD_MASK) {
2900 /* move the window */
2901 if (XGrabPointer(dpy, wwin->client_win, False,
2902 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2903 GrabModeAsync, GrabModeAsync, None,
2904 None, CurrentTime)!=GrabSuccess) {
2905 #ifdef DEBUG0
2906 wwarning("pointer grab failed for window move");
2907 #endif
2908 return;
2910 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2911 wMouseResizeWindow(wwin, event);
2912 else
2913 wMouseMoveWindow(wwin, event);
2914 XUngrabPointer(dpy, CurrentTime);
2919 static void
2920 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2922 WWindow *wwin = (WWindow*)data;
2924 #ifndef NUMLOCK_HACK
2925 if ((event->xbutton.state & ValidModMask)
2926 != (event->xbutton.state & ~LockMask)) {
2927 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2928 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2930 #endif
2931 event->xbutton.state &= ValidModMask;
2933 CloseWindowMenu(wwin->screen_ptr);
2935 if (wPreferences.focus_mode==WKF_CLICK
2936 && !(event->xbutton.state&ControlMask)
2937 && !WFLAGP(wwin, no_focusable)) {
2938 wSetFocusTo(wwin->screen_ptr, wwin);
2941 if (event->xbutton.button == Button1
2942 || event->xbutton.button == Button2) {
2944 if (event->xbutton.button == Button1) {
2945 if (event->xbutton.state & MOD_MASK) {
2946 wLowerFrame(wwin->frame->core);
2947 } else {
2948 wRaiseFrame(wwin->frame->core);
2951 if ((event->xbutton.state & ShiftMask)
2952 && !(event->xbutton.state & ControlMask)) {
2953 wSelectWindow(wwin, !wwin->flags.selected);
2954 return;
2956 if (event->xbutton.window != wwin->frame->titlebar->window
2957 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2958 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2959 GrabModeAsync, GrabModeAsync, None,
2960 None, CurrentTime)!=GrabSuccess) {
2961 #ifdef DEBUG0
2962 wwarning("pointer grab failed for window move");
2963 #endif
2964 return;
2967 /* move the window */
2968 wMouseMoveWindow(wwin, event);
2970 XUngrabPointer(dpy, CurrentTime);
2971 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2972 && !wwin->flags.internal_window
2973 && !WCHECK_STATE(WSTATE_MODAL)) {
2974 WObjDescriptor *desc;
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 OpenWindowMenu(wwin, event->xbutton.x_root,
2988 wwin->frame_y+wwin->frame->top_width, False);
2990 /* allow drag select */
2991 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2992 event->xany.send_event = True;
2993 (*desc->handle_mousedown)(desc, event);
2995 XUngrabPointer(dpy, CurrentTime);
3001 static void
3002 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3004 WWindow *wwin = data;
3006 event->xbutton.state &= ValidModMask;
3008 CloseWindowMenu(wwin->screen_ptr);
3010 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3011 return;
3013 /* if control-click, kill the client */
3014 if (event->xbutton.state & ControlMask) {
3015 wClientKill(wwin);
3016 } else {
3017 #ifdef OLWM_HINTS
3018 if (wwin->flags.olwm_push_pin_out) {
3020 wwin->flags.olwm_push_pin_out = 0;
3022 wOLWMChangePushpinState(wwin, True);
3024 wFrameWindowUpdatePushButton(wwin->frame, False);
3026 return;
3028 #endif
3029 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3030 /* send delete message */
3031 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3037 static void
3038 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3040 WWindow *wwin = data;
3042 CloseWindowMenu(wwin->screen_ptr);
3044 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3045 return;
3047 /* send delete message */
3048 if (wwin->protocols.DELETE_WINDOW) {
3049 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3050 } else {
3051 wClientKill(wwin);
3056 #ifdef XKB_BUTTON_HINT
3057 static void
3058 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3060 WWindow *wwin = data;
3061 WFrameWindow *fwin = wwin->frame;
3062 WScreen *scr = fwin->screen_ptr;
3063 XkbStateRec staterec;
3064 int tl;
3066 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3067 return;
3068 tl = wwin->frame->languagemode;
3069 wwin->frame->languagemode = wwin->frame->last_languagemode;
3070 wwin->frame->last_languagemode = tl;
3071 wSetFocusTo(scr, wwin);
3072 wwin->frame->languagebutton_image =
3073 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3074 wwin->frame->languagemode];
3075 wFrameWindowUpdateLanguageButton(wwin->frame);
3076 if (event->xbutton.button == Button3)
3077 return;
3078 wRaiseFrame(fwin->core);
3080 #endif
3083 static void
3084 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3086 WWindow *wwin = data;
3088 event->xbutton.state &= ValidModMask;
3090 CloseWindowMenu(wwin->screen_ptr);
3092 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3093 return;
3095 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3096 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3097 LastTimestamp);
3098 } else {
3099 WApplication *wapp;
3100 if ((event->xbutton.state & ControlMask) ||
3101 (event->xbutton.button == Button3)) {
3103 wapp = wApplicationOf(wwin->main_window);
3104 if (wapp && !WFLAGP(wwin, no_appicon))
3105 wHideApplication(wapp);
3106 } else if (event->xbutton.state==0) {
3107 wIconifyWindow(wwin);