- Fixed problem with GNOME apps that have windows which need to stay on the
[wmaker-crm.git] / src / window.c
blob258c69ce360e226c896900f373dc1549e4b579f5
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 = INT_MIN; /* INT_MIN is never used by the window levels */
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 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
434 * have INT_MIN that means that no window level was requested. --Dan
436 if (tmp_level == INT_MIN) {
437 if (WFLAGP(wwin, floating))
438 *level = WMFloatingLevel;
439 else if (WFLAGP(wwin, sunken))
440 *level = WMSunkenLevel;
441 else
442 *level = WMNormalLevel;
443 } else {
444 *level = tmp_level;
447 if (tmp_workspace >= 0) {
448 *workspace = tmp_workspace % scr->workspace_count;
453 * Set attributes specified only for that window/class.
454 * This might do duplicate work with the 1st wDefaultFillAttributes().
456 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
457 &wwin->user_flags, &wwin->defined_user_flags,
458 False);
460 * Sanity checks for attributes that depend on other attributes
462 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
463 wwin->user_flags.emulate_appicon = 0;
465 if (wwin->main_window!=None) {
466 WApplication *wapp = wApplicationOf(wwin->main_window);
467 if (wapp && !wapp->flags.emulated)
468 wwin->user_flags.emulate_appicon = 0;
471 if (wwin->transient_for!=None
472 && wwin->transient_for!=wwin->screen_ptr->root_win)
473 wwin->user_flags.emulate_appicon = 0;
475 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
476 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
477 wwin->user_flags.sunken = 0;
479 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
485 Bool
486 wWindowCanReceiveFocus(WWindow *wwin)
488 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
489 return False;
490 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
491 return False;
492 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
493 return False;
495 return True;
499 Bool
500 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
502 int w1, h1, w2, h2;
504 w1 = wwin->frame->core->width;
505 h1 = wwin->frame->core->height;
506 w2 = obscured->frame->core->width;
507 h2 = obscured->frame->core->height;
509 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
510 && wwin->frame->workspace != obscured->frame->workspace)
511 return False;
513 if (wwin->frame_x + w1 < obscured->frame_x
514 || wwin->frame_y + h1 < obscured->frame_y
515 || wwin->frame_x > obscured->frame_x + w2
516 || wwin->frame_y > obscured->frame_y + h2) {
517 return False;
520 return True;
526 *----------------------------------------------------------------
527 * wManageWindow--
528 * reparents the window and allocates a descriptor for it.
529 * Window manager hints and other hints are fetched to configure
530 * the window decoration attributes and others. User preferences
531 * for the window are used if available, to configure window
532 * decorations and some behaviour.
533 * If in startup, windows that are override redirect,
534 * unmapped and never were managed and are Withdrawn are not
535 * managed.
537 * Returns:
538 * the new window descriptor
540 * Side effects:
541 * The window is reparented and appropriate notification
542 * is done to the client. Input mask for the window is setup.
543 * The window descriptor is also associated with various window
544 * contexts and inserted in the head of the window list.
545 * Event handler contexts are associated for some objects
546 * (buttons, titlebar and resizebar)
548 *----------------------------------------------------------------
550 WWindow*
551 wManageWindow(WScreen *scr, Window window)
553 WWindow *wwin;
554 int x, y;
555 unsigned width, height;
556 XWindowAttributes wattribs;
557 XSetWindowAttributes attribs;
558 WWindowState *win_state;
559 WWindow *transientOwner = NULL;
560 int window_level;
561 int wm_state;
562 int foo;
563 int workspace = -1;
564 char *title;
565 Bool withdraw = False;
567 /* mutex. */
568 /* XGrabServer(dpy); */
569 XSync(dpy, False);
570 /* make sure the window is still there */
571 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
572 XUngrabServer(dpy);
573 return NULL;
576 /* if it's an override-redirect, ignore it */
577 if (wattribs.override_redirect) {
578 XUngrabServer(dpy);
579 return NULL;
582 wm_state = PropGetWindowState(window);
584 /* if it's startup and the window is unmapped, don't manage it */
585 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
586 XUngrabServer(dpy);
587 return NULL;
590 if (!wFetchName(dpy, window, &title)) {
591 title = NULL;
594 #ifdef KWM_HINTS
595 if (title && !wKWMManageableClient(scr, window, title)) {
596 XFree(title);
597 XUngrabServer(dpy);
598 return NULL;
600 #endif /* KWM_HINTS */
603 wwin = wWindowCreate();
605 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
607 #ifdef DEBUG
608 printf("managing window %x\n", (unsigned)window);
609 #endif
611 #ifdef SHAPE
612 if (wShapeSupported) {
613 int junk;
614 unsigned int ujunk;
615 int b_shaped;
617 XShapeSelectInput(dpy, window, ShapeNotifyMask);
618 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
619 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
620 wwin->flags.shaped = b_shaped;
622 #endif
625 *--------------------------------------------------
627 * Get hints and other information in properties
629 *--------------------------------------------------
631 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
633 /* setup descriptor */
634 wwin->client_win = window;
635 wwin->screen_ptr = scr;
637 wwin->old_border_width = wattribs.border_width;
639 wwin->event_mask = CLIENT_EVENTS;
640 attribs.event_mask = CLIENT_EVENTS;
641 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
642 attribs.save_under = False;
643 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
644 |CWSaveUnder, &attribs);
645 XSetWindowBorderWidth(dpy, window, 0);
647 /* get hints from GNUstep app */
648 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
649 wwin->flags.is_gnustep = 1;
651 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
652 wwin->wm_gnustep_attr = NULL;
655 wwin->client_leader = PropGetClientLeader(window);
656 if (wwin->client_leader!=None)
657 wwin->main_window = wwin->client_leader;
659 wwin->wm_hints = XGetWMHints(dpy, window);
661 if (wwin->wm_hints) {
662 if (wwin->wm_hints->flags & StateHint) {
664 if (wwin->wm_hints->initial_state == IconicState) {
666 wwin->flags.miniaturized = 1;
668 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
670 withdraw = True;
674 if (wwin->wm_hints->flags & WindowGroupHint) {
675 wwin->group_id = wwin->wm_hints->window_group;
676 /* window_group has priority over CLIENT_LEADER */
677 wwin->main_window = wwin->group_id;
678 } else {
679 wwin->group_id = None;
682 if (wwin->wm_hints->flags & UrgencyHint)
683 wwin->flags.urgent = 1;
684 } else {
685 wwin->group_id = None;
688 PropGetProtocols(window, &wwin->protocols);
690 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
691 wwin->transient_for = None;
692 } else {
693 if (wwin->transient_for==None || wwin->transient_for==window) {
694 wwin->transient_for = scr->root_win;
695 } else {
696 transientOwner = wWindowFor(wwin->transient_for);
697 if (transientOwner && transientOwner->main_window!=None) {
698 wwin->main_window = transientOwner->main_window;
699 } /*else {
700 wwin->main_window = None;
705 /* guess the focus mode */
706 wwin->focus_mode = getFocusMode(wwin);
708 /* get geometry stuff */
709 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
711 /* get colormap windows */
712 GetColormapWindows(wwin);
715 *--------------------------------------------------
717 * Setup the decoration/window attributes and
718 * geometry
720 *--------------------------------------------------
723 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
725 #ifdef OLWM_HINTS
726 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
727 && wwin->group_id != None && wwin->group_id != window) {
729 transientOwner = wWindowFor(wwin->group_id);
731 if (transientOwner) {
732 wwin->transient_for = wwin->group_id;
734 /* transients can't be iconified or maximized */
735 if (wwin->transient_for) {
736 WSETUFLAG(wwin, no_miniaturizable, 1);
737 WSETUFLAG(wwin, no_miniaturize_button, 1);
741 #endif /* OLWM_HINTS */
744 * Make broken apps behave as a nice app.
746 if (WFLAGP(wwin, emulate_appicon)) {
747 wwin->main_window = wwin->client_win;
751 *------------------------------------------------------------
753 * Setup the initial state of the window
755 *------------------------------------------------------------
758 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
759 wwin->flags.miniaturized = 1;
762 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
763 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
767 Bool bla;
769 bla = False;
770 #ifdef GNOME_STUFF
771 bla = wGNOMECheckInitialClientState(wwin);
772 #endif
773 #ifdef KWM_HINTS
774 if (!bla)
775 wKWMCheckClientInitialState(wwin);
776 #endif
779 /* apply previous state if it exists and we're in startup */
780 if (scr->flags.startup && wm_state >= 0) {
782 if (wm_state == IconicState) {
784 wwin->flags.miniaturized = 1;
786 } else if (wm_state == WithdrawnState) {
788 withdraw = True;
792 /* if there is a saved state (from file), restore it */
793 win_state = NULL;
794 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
795 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
796 } else {
797 win_state = (WWindowState*)wWindowGetSavedState(window);
799 if (win_state && !withdraw) {
801 if (win_state->state->hidden>0)
802 wwin->flags.hidden = win_state->state->hidden;
804 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
805 wwin->flags.shaded = win_state->state->shaded;
807 if (win_state->state->miniaturized>0 &&
808 !WFLAGP(wwin, no_miniaturizable)) {
809 wwin->flags.miniaturized = win_state->state->miniaturized;
812 if (!IS_OMNIPRESENT(wwin)) {
813 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
814 wwin->wm_class);
815 if (w < 0 || w >= scr->workspace_count) {
816 workspace = win_state->state->workspace;
817 if (workspace >= scr->workspace_count)
818 workspace = scr->current_workspace;
819 } else {
820 workspace = w;
822 } else {
823 workspace = scr->current_workspace;
827 /* if we're restarting, restore saved state (from hints).
828 * This will overwrite previous */
830 WSavedState *wstate;
832 if (getSavedState(window, &wstate)) {
833 wwin->flags.shaded = wstate->shaded;
834 wwin->flags.hidden = wstate->hidden;
835 wwin->flags.miniaturized = wstate->miniaturized;
836 wwin->flags.maximized = wstate->maximized;
837 if (wwin->flags.maximized) {
838 wwin->old_geometry.x = wstate->x;
839 wwin->old_geometry.y = wstate->y;
840 wwin->old_geometry.width = wstate->w;
841 wwin->old_geometry.height = wstate->h;
844 workspace = wstate->workspace;
845 } else {
846 wstate = NULL;
849 /* restore window shortcut */
850 if (wstate != NULL || win_state != NULL) {
851 unsigned mask = 0;
853 if (win_state != NULL)
854 mask = win_state->state->window_shortcuts;
856 if (wstate != NULL && mask == 0)
857 mask = wstate->window_shortcuts;
859 if (mask > 0) {
860 int i;
862 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
863 if (mask & (1<<i)) {
864 if (!scr->shortcutWindows[i])
865 scr->shortcutWindows[i] = WMCreateBag(4);
867 WMPutInBag(scr->shortcutWindows[i], wwin);
872 if (wstate != NULL) {
873 wfree(wstate);
877 /* don't let transients start miniaturized if their owners are not */
878 if (transientOwner && !transientOwner->flags.miniaturized
879 && wwin->flags.miniaturized && !withdraw) {
880 wwin->flags.miniaturized = 0;
881 if (wwin->wm_hints)
882 wwin->wm_hints->initial_state = NormalState;
885 /* set workspace on which the window starts */
886 if (workspace >= 0) {
887 if (workspace > scr->workspace_count-1) {
888 workspace = workspace % scr->workspace_count;
890 } else {
891 int w;
893 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
895 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
897 workspace = w;
899 } else {
900 if (wPreferences.open_transients_with_parent && transientOwner) {
902 workspace = transientOwner->frame->workspace;
904 } else {
906 workspace = scr->current_workspace;
911 /* setup window geometry */
912 if (win_state && win_state->state->w > 0) {
913 width = win_state->state->w;
914 height = win_state->state->h;
916 wWindowConstrainSize(wwin, &width, &height);
918 /* do not ask for window placement if the window is
919 * transient, during startup, if the initial workspace is another one
920 * or if the window wants to start iconic.
921 * If geometry was saved, restore it. */
923 Bool dontBring = False;
925 if (win_state && win_state->state->w > 0) {
926 x = win_state->state->x;
927 y = win_state->state->y;
928 } else if ((wwin->transient_for==None
929 || wPreferences.window_placement!=WPM_MANUAL)
930 && !scr->flags.startup
931 && workspace == scr->current_workspace
932 && !wwin->flags.miniaturized
933 && !wwin->flags.maximized
934 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
936 if (transientOwner && transientOwner->flags.mapped) {
937 int offs = WMAX(20, 2*transientOwner->frame->top_width);
939 x = transientOwner->frame_x +
940 abs((transientOwner->frame->core->width - width)/2) + offs;
941 y = transientOwner->frame_y +
942 abs((transientOwner->frame->core->height - height)/3) + offs;
944 if (x < 0)
945 x = 0;
946 else if (x + width > scr->scr_width)
947 x = scr->scr_width - width;
949 if (y < 0)
950 y = 0;
951 else if (y + height > scr->scr_height)
952 y = scr->scr_height - height;
953 } else {
954 PlaceWindow(wwin, &x, &y, width, height);
956 if (wPreferences.window_placement == WPM_MANUAL)
957 dontBring = True;
960 if (WFLAGP(wwin, dont_move_off) && dontBring)
961 wScreenBringInside(scr, &x, &y, width, height);
964 if (wwin->flags.urgent) {
965 if (!IS_OMNIPRESENT(wwin))
966 wwin->flags.omnipresent ^= 1;
970 *--------------------------------------------------
972 * Create frame, borders and do reparenting
974 *--------------------------------------------------
976 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
977 #ifdef XKB_BUTTON_HINT
978 if (wPreferences.modelock)
979 foo |= WFF_LANGUAGE_BUTTON;
980 #endif
981 if (!WFLAGP(wwin, no_titlebar))
982 foo |= WFF_TITLEBAR;
983 if (!WFLAGP(wwin, no_resizebar))
984 foo |= WFF_RESIZEBAR;
985 if (!WFLAGP(wwin, no_border))
986 foo |= WFF_BORDER;
988 wwin->frame = wFrameWindowCreate(scr, window_level,
989 x, y, width, height,
990 &wPreferences.window_title_clearance, foo,
991 scr->window_title_texture,
992 scr->resizebar_texture,
993 scr->window_title_pixel,
994 &scr->window_title_gc,
995 &scr->title_font);
997 wwin->frame->flags.is_client_window_frame = 1;
998 wwin->frame->flags.justification = wPreferences.title_justification;
1000 /* setup button images */
1001 wWindowUpdateButtonImages(wwin);
1003 /* hide unused buttons */
1004 foo = 0;
1005 if (WFLAGP(wwin, no_close_button))
1006 foo |= WFF_RIGHT_BUTTON;
1007 if (WFLAGP(wwin, no_miniaturize_button))
1008 foo |= WFF_LEFT_BUTTON;
1009 #ifdef XKB_BUTTON_HINT
1010 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1011 foo |= WFF_LANGUAGE_BUTTON;
1012 #endif
1013 if (foo!=0)
1014 wFrameWindowHideButton(wwin->frame, foo);
1016 wwin->frame->child = wwin;
1018 #ifdef OLWM_HINTS
1019 /* emulate olwm push pin. Make the button look as pushed-in for
1020 * the pinned-out state. When the button is clicked, it will
1021 * revert to the normal position, which means the pin is pinned-in.
1023 if (wwin->flags.olwm_push_pin_out)
1024 wFrameWindowUpdatePushButton(wwin->frame, True);
1025 #endif /* OLWM_HINTS */
1028 wwin->frame->workspace = workspace;
1030 wwin->frame->on_click_left = windowIconifyClick;
1031 #ifdef XKB_BUTTON_HINT
1032 if (wPreferences.modelock)
1033 wwin->frame->on_click_language = windowLanguageClick;
1034 #endif
1036 wwin->frame->on_click_right = windowCloseClick;
1037 wwin->frame->on_dblclick_right = windowCloseDblClick;
1039 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1040 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1042 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1045 XSelectInput(dpy, wwin->client_win,
1046 wwin->event_mask & ~StructureNotifyMask);
1048 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1049 0, wwin->frame->top_width);
1051 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1055 int gx, gy;
1057 wClientGetGravityOffsets(wwin, &gx, &gy);
1059 /* if gravity is to the south, account for the border sizes */
1060 if (gy > 0)
1061 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1065 * wWindowConfigure() will init the client window's size
1066 * (wwin->client.{width,height}) and all other geometry
1067 * related variables (frame_x,frame_y)
1069 wWindowConfigure(wwin, x, y, width, height);
1071 /* to make sure the window receives it's new position after reparenting */
1072 wWindowSynthConfigureNotify(wwin);
1075 *--------------------------------------------------
1077 * Setup descriptors and save window to internal
1078 * lists
1080 *--------------------------------------------------
1083 if (wwin->main_window!=None) {
1084 WApplication *app;
1085 WWindow *leader;
1087 /* Leader windows do not necessary set themselves as leaders.
1088 * If this is the case, point the leader of this window to
1089 * itself */
1090 leader = wWindowFor(wwin->main_window);
1091 if (leader && leader->main_window==None) {
1092 leader->main_window = leader->client_win;
1094 app = wApplicationCreate(scr, wwin->main_window);
1095 if (app) {
1096 app->last_workspace = workspace;
1099 * Do application specific stuff, like setting application
1100 * wide attributes.
1103 if (wwin->flags.hidden) {
1104 /* if the window was set to hidden because it was hidden
1105 * in a previous incarnation and that state was restored */
1106 app->flags.hidden = 1;
1109 if (app->flags.hidden) {
1110 wwin->flags.hidden = 1;
1115 /* setup the frame descriptor */
1116 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1117 wwin->frame->core->descriptor.parent = wwin;
1118 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1120 /* don't let windows go away if we die */
1121 XAddToSaveSet(dpy, window);
1123 XLowerWindow(dpy, window);
1125 /* if window is in this workspace and should be mapped, then map it */
1126 if (!wwin->flags.miniaturized
1127 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1128 && !wwin->flags.hidden && !withdraw) {
1130 /* The following "if" is to avoid crashing of clients that expect
1131 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1132 * after the return from this function.
1134 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1135 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1136 } else {
1137 wClientSetState(wwin, NormalState, None);
1140 #if 0
1141 /* if not auto focus, then map the window under the currently
1142 * focused window */
1143 #define _WIDTH(w) (w)->frame->core->width
1144 #define _HEIGHT(w) (w)->frame->core->height
1145 if (!wPreferences.auto_focus && scr->focused_window
1146 && !scr->flags.startup && !transientOwner
1147 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1148 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1149 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1150 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1151 || wwin->flags.maximized)) {
1152 MoveInStackListUnder(scr->focused_window->frame->core,
1153 wwin->frame->core);
1155 #undef _WIDTH
1156 #undef _HEIGHT
1158 #endif
1160 if (wPreferences.superfluous && !wPreferences.no_animations
1161 && !scr->flags.startup && wwin->transient_for==None
1163 * The brain damaged idiotic non-click to focus modes will
1164 * have trouble with this because:
1166 * 1. window is created and mapped by the client
1167 * 2. window is mapped by wmaker in small size
1168 * 3. window is animated to grow to normal size
1169 * 4. this function returns to normal event loop
1170 * 5. eventually, the EnterNotify event that would trigger
1171 * the window focusing (if the mouse is over that window)
1172 * will be processed by wmaker.
1173 * But since this event will be rather delayed
1174 * (step 3 has a large delay) the time when the event ocurred
1175 * and when it is processed, the client that owns that window
1176 * will reject the XSetInputFocus() for it.
1178 && (wPreferences.focus_mode==WKF_CLICK
1179 || wPreferences.auto_focus)) {
1180 DoWindowBirth(wwin);
1183 wWindowMap(wwin);
1186 /* setup stacking descriptor */
1187 if (transientOwner) {
1188 /* && wPreferences.on_top_transients */
1189 if (transientOwner) {
1190 wwin->frame->core->stacking->child_of =
1191 transientOwner->frame->core;
1193 } else {
1194 wwin->frame->core->stacking->child_of = NULL;
1198 if (!scr->focused_window) {
1199 /* first window on the list */
1200 wwin->next = NULL;
1201 wwin->prev = NULL;
1202 scr->focused_window = wwin;
1203 } else {
1204 WWindow *tmp;
1206 /* add window at beginning of focus window list */
1207 tmp = scr->focused_window;
1208 while (tmp->prev)
1209 tmp = tmp->prev;
1210 tmp->prev = wwin;
1211 wwin->next = tmp;
1212 wwin->prev = NULL;
1215 /* Update name must come after WApplication stuff is done */
1216 wWindowUpdateName(wwin, title);
1217 if (title)
1218 XFree(title);
1221 #ifdef GNOME_STUFF
1222 wGNOMEUpdateClientStateHint(wwin, True);
1223 #endif
1224 #ifdef KWM_HINTS
1225 wKWMUpdateClientWorkspace(wwin);
1226 wKWMUpdateClientStateHint(wwin, KWMAllFlags);
1227 #endif
1229 XUngrabServer(dpy);
1232 *--------------------------------------------------
1234 * Final preparations before window is ready to go
1236 *--------------------------------------------------
1239 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1242 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1243 && !wwin->flags.hidden) {
1244 if (((transientOwner && transientOwner->flags.focused)
1245 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1246 wSetFocusTo(scr, wwin);
1248 wWindowResetMouseGrabs(wwin);
1250 if (!WFLAGP(wwin, no_bind_keys)) {
1251 wWindowSetKeyGrabs(wwin);
1253 #ifdef GNOME_STUFF
1254 wGNOMEUpdateClientListHint(scr);
1255 #endif
1256 #ifdef KWM_HINTS
1257 wwin->flags.kwm_managed = 1;
1259 wKWMSendEventMessage(wwin, WKWMAddWindow);
1260 #endif
1262 wColormapInstallForWindow(scr, scr->cmap_window);
1264 UpdateSwitchMenu(scr, wwin, ACTION_ADD);
1266 #ifdef OLWM_HINTS
1267 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1268 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1270 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1271 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1272 wwin->frame_y);
1274 #endif
1277 *------------------------------------------------------------
1278 * Setup Notification Observers
1279 *------------------------------------------------------------
1281 WMAddNotificationObserver(appearanceObserver, wwin,
1282 WNWindowAppearanceSettingsChanged, wwin);
1286 *--------------------------------------------------
1288 * Cleanup temporary stuff
1290 *--------------------------------------------------
1293 if (win_state)
1294 wWindowDeleteSavedState(win_state);
1296 /* If the window must be withdrawed, then do it now.
1297 * Must do some optimization, 'though */
1298 if (withdraw) {
1299 wwin->flags.mapped = 0;
1300 wClientSetState(wwin, WithdrawnState, None);
1301 wUnmanageWindow(wwin, True, False);
1302 wwin = NULL;
1305 return wwin;
1312 WWindow*
1313 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1314 char *title, int x, int y, int width, int height)
1316 WWindow *wwin;
1317 int foo;
1319 wwin = wWindowCreate();
1321 WMAddNotificationObserver(appearanceObserver, wwin,
1322 WNWindowAppearanceSettingsChanged, wwin);
1324 wwin->flags.internal_window = 1;
1326 WSETUFLAG(wwin, omnipresent, 1);
1327 WSETUFLAG(wwin, no_shadeable, 1);
1328 WSETUFLAG(wwin, no_resizable, 1);
1329 WSETUFLAG(wwin, no_miniaturizable, 1);
1331 wwin->focus_mode = WFM_PASSIVE;
1333 wwin->client_win = window;
1334 wwin->screen_ptr = scr;
1336 wwin->transient_for = owner;
1338 wwin->client.x = x;
1339 wwin->client.y = y;
1340 wwin->client.width = width;
1341 wwin->client.height = height;
1343 wwin->frame_x = wwin->client.x;
1344 wwin->frame_y = wwin->client.y;
1347 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1348 foo |= WFF_TITLEBAR;
1349 #ifdef XKB_BUTTON_HINT
1350 foo |= WFF_LANGUAGE_BUTTON;
1351 #endif
1353 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1354 wwin->frame_x, wwin->frame_y,
1355 width, height,
1356 &wPreferences.window_title_clearance, foo,
1357 scr->window_title_texture,
1358 scr->resizebar_texture,
1359 scr->window_title_pixel,
1360 &scr->window_title_gc,
1361 &scr->title_font);
1363 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1365 wwin->frame->flags.is_client_window_frame = 1;
1366 wwin->frame->flags.justification = wPreferences.title_justification;
1368 wFrameWindowChangeTitle(wwin->frame, title);
1370 /* setup button images */
1371 wWindowUpdateButtonImages(wwin);
1373 /* hide buttons */
1374 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1376 wwin->frame->child = wwin;
1378 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1380 #ifdef XKB_BUTTON_HINT
1381 if (wPreferences.modelock)
1382 wwin->frame->on_click_language = windowLanguageClick;
1383 #endif
1385 wwin->frame->on_click_right = windowCloseClick;
1387 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1388 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1390 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1392 wwin->client.y += wwin->frame->top_width;
1393 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1394 0, wwin->frame->top_width);
1396 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1397 wwin->client.width, wwin->client.height);
1399 /* setup the frame descriptor */
1400 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1401 wwin->frame->core->descriptor.parent = wwin;
1402 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1405 XLowerWindow(dpy, window);
1406 XMapSubwindows(dpy, wwin->frame->core->window);
1408 /* setup stacking descriptor */
1409 if (
1410 #ifdef removed
1411 wPreferences.on_top_transients &&
1412 #endif
1413 wwin->transient_for!=None
1414 && wwin->transient_for!=scr->root_win) {
1415 WWindow *tmp;
1416 tmp = wWindowFor(wwin->transient_for);
1417 if (tmp)
1418 wwin->frame->core->stacking->child_of = tmp->frame->core;
1419 } else {
1420 wwin->frame->core->stacking->child_of = NULL;
1424 if (!scr->focused_window) {
1425 /* first window on the list */
1426 wwin->next = NULL;
1427 wwin->prev = NULL;
1428 scr->focused_window = wwin;
1429 } else {
1430 WWindow *tmp;
1432 /* add window at beginning of focus window list */
1433 tmp = scr->focused_window;
1434 while (tmp->prev)
1435 tmp = tmp->prev;
1436 tmp->prev = wwin;
1437 wwin->next = tmp;
1438 wwin->prev = NULL;
1441 if (wwin->flags.is_gnustep == 0)
1442 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1444 /* if (wPreferences.auto_focus)*/
1445 wSetFocusTo(scr, wwin);
1447 wWindowResetMouseGrabs(wwin);
1449 wWindowSetKeyGrabs(wwin);
1451 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_ADD);
1453 return wwin;
1458 *----------------------------------------------------------------------
1459 * wUnmanageWindow--
1460 * Removes the frame window from a window and destroys all data
1461 * related to it. The window will be reparented back to the root window
1462 * if restore is True.
1464 * Side effects:
1465 * Everything related to the window is destroyed and the window
1466 * is removed from the window lists. Focus is set to the previous on the
1467 * window list.
1468 *----------------------------------------------------------------------
1470 void
1471 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1473 WCoreWindow *frame = wwin->frame->core;
1474 WWindow *owner = NULL;
1475 WWindow *newFocusedWindow = NULL;
1476 int wasFocused;
1477 WScreen *scr = wwin->screen_ptr;
1480 #ifdef KWM_HINTS
1481 wwin->frame->workspace = -1;
1483 wKWMUpdateClientWorkspace(wwin);
1484 #endif
1486 /* First close attribute editor window if open */
1487 if (wwin->flags.inspector_open) {
1488 wCloseInspectorForWindow(wwin);
1491 /* Close window menu if it's open for this window */
1492 if (wwin->flags.menu_open_for_me) {
1493 CloseWindowMenu(scr);
1496 if (!destroyed) {
1497 if (!wwin->flags.internal_window)
1498 XRemoveFromSaveSet(dpy, wwin->client_win);
1500 XSelectInput(dpy, wwin->client_win, NoEventMask);
1502 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1503 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1506 XUnmapWindow(dpy, frame->window);
1508 XUnmapWindow(dpy, wwin->client_win);
1510 /* deselect window */
1511 wSelectWindow(wwin, False);
1513 /* remove all pending events on window */
1514 /* I think this only matters for autoraise */
1515 if (wPreferences.raise_delay)
1516 WMDeleteTimerWithClientData(wwin->frame->core);
1518 XFlush(dpy);
1520 UpdateSwitchMenu(scr, wwin, ACTION_REMOVE);
1522 /* reparent the window back to the root */
1523 if (restore)
1524 wClientRestore(wwin);
1526 if (wwin->transient_for!=scr->root_win) {
1527 owner = wWindowFor(wwin->transient_for);
1528 if (owner) {
1529 if (!owner->flags.semi_focused) {
1530 owner = NULL;
1531 } else {
1532 owner->flags.semi_focused = 0;
1537 wasFocused = wwin->flags.focused;
1539 /* remove from window focus list */
1540 if (!wwin->prev && !wwin->next) {
1541 /* was the only window */
1542 scr->focused_window = NULL;
1543 newFocusedWindow = NULL;
1544 } else {
1545 WWindow *tmp;
1547 if (wwin->prev)
1548 wwin->prev->next = wwin->next;
1549 if (wwin->next)
1550 wwin->next->prev = wwin->prev;
1551 else {
1552 scr->focused_window = wwin->prev;
1553 scr->focused_window->next = NULL;
1556 if (wPreferences.focus_mode==WKF_CLICK) {
1558 /* if in click to focus mode and the window
1559 * was a transient, focus the owner window
1561 tmp = NULL;
1562 if (wPreferences.focus_mode==WKF_CLICK) {
1563 tmp = wWindowFor(wwin->transient_for);
1564 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1565 tmp = NULL;
1568 /* otherwise, focus the next one in the focus list */
1569 if (!tmp) {
1570 tmp = scr->focused_window;
1571 while (tmp) { /* look for one in the window list first */
1572 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1573 && (tmp->flags.mapped || tmp->flags.shaded))
1574 break;
1575 tmp = tmp->prev;
1577 if (!tmp) { /* if unsuccessful, choose any focusable window */
1578 tmp = scr->focused_window;
1579 while (tmp) {
1580 if (!WFLAGP(tmp, no_focusable)
1581 && (tmp->flags.mapped || tmp->flags.shaded))
1582 break;
1583 tmp = tmp->prev;
1588 newFocusedWindow = tmp;
1590 } else if (wPreferences.focus_mode==WKF_SLOPPY
1591 || wPreferences.focus_mode==WKF_POINTER) {
1592 unsigned int mask;
1593 int foo;
1594 Window bar, win;
1596 /* This is to let the root window get the keyboard input
1597 * if Sloppy focus mode and no other window get focus.
1598 * This way keybindings will not freeze.
1600 tmp = NULL;
1601 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1602 &foo, &foo, &foo, &foo, &mask))
1603 tmp = wWindowFor(win);
1604 if (tmp == wwin)
1605 tmp = NULL;
1606 newFocusedWindow = tmp;
1607 } else {
1608 newFocusedWindow = NULL;
1612 if (!wwin->flags.internal_window) {
1613 #ifdef GNOME_STUFF
1614 wGNOMERemoveClient(wwin);
1615 #endif
1616 #ifdef KWM_HINTS
1617 wKWMSendEventMessage(wwin, WKWMRemoveWindow);
1618 #endif
1621 #ifdef DEBUG
1622 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1623 (unsigned)frame->window);
1624 #endif
1626 if (wasFocused) {
1627 if (newFocusedWindow != owner && owner) {
1628 if (wwin->flags.is_gnustep == 0)
1629 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1631 wSetFocusTo(scr, newFocusedWindow);
1633 wWindowDestroy(wwin);
1634 XFlush(dpy);
1638 void
1639 wWindowMap(WWindow *wwin)
1641 XMapWindow(dpy, wwin->frame->core->window);
1642 if (!wwin->flags.shaded) {
1643 /* window will be remapped when getting MapNotify */
1644 XSelectInput(dpy, wwin->client_win,
1645 wwin->event_mask & ~StructureNotifyMask);
1646 XMapWindow(dpy, wwin->client_win);
1647 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1649 wwin->flags.mapped = 1;
1654 void
1655 wWindowUnmap(WWindow *wwin)
1657 wwin->flags.mapped = 0;
1659 /* prevent window withdrawal when getting UnmapNotify */
1660 XSelectInput(dpy, wwin->client_win,
1661 wwin->event_mask & ~StructureNotifyMask);
1662 XUnmapWindow(dpy, wwin->client_win);
1663 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1665 XUnmapWindow(dpy, wwin->frame->core->window);
1670 void
1671 wWindowFocus(WWindow *wwin, WWindow *owin)
1673 WWindow *nowner;
1674 WWindow *oowner;
1676 #ifdef KEEP_XKB_LOCK_STATUS
1677 if (wPreferences.modelock) {
1678 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1680 #endif /* KEEP_XKB_LOCK_STATUS */
1682 wwin->flags.semi_focused = 0;
1684 if (wwin->flags.is_gnustep == 0)
1685 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1687 wwin->flags.focused = 1;
1689 wWindowResetMouseGrabs(wwin);
1691 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1693 if (owin == wwin || !owin)
1694 return;
1696 nowner = wWindowFor(wwin->transient_for);
1698 /* new window is a transient for the old window */
1699 if (nowner == owin) {
1700 owin->flags.semi_focused = 1;
1701 wWindowUnfocus(nowner);
1702 return;
1705 oowner = wWindowFor(owin->transient_for);
1707 /* new window is owner of old window */
1708 if (wwin == oowner) {
1709 wWindowUnfocus(owin);
1710 return;
1713 if (!nowner) {
1714 wWindowUnfocus(owin);
1715 return;
1718 /* new window has same owner of old window */
1719 if (oowner == nowner) {
1720 /* prevent unfocusing of owner */
1721 oowner->flags.semi_focused = 0;
1722 wWindowUnfocus(owin);
1723 oowner->flags.semi_focused = 1;
1725 return;
1728 /* nowner != NULL && oowner != nowner */
1729 nowner->flags.semi_focused = 1;
1730 wWindowUnfocus(nowner);
1731 wWindowUnfocus(owin);
1735 void
1736 wWindowUnfocus(WWindow *wwin)
1738 CloseWindowMenu(wwin->screen_ptr);
1740 if (wwin->flags.is_gnustep == 0)
1741 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1742 ? WS_PFOCUSED : WS_UNFOCUSED);
1744 if (wwin->transient_for!=None
1745 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1746 WWindow *owner;
1747 owner = wWindowFor(wwin->transient_for);
1748 if (owner && owner->flags.semi_focused) {
1749 owner->flags.semi_focused = 0;
1750 if (owner->flags.mapped || owner->flags.shaded) {
1751 wWindowUnfocus(owner);
1752 wFrameWindowPaint(owner->frame);
1756 wwin->flags.focused = 0;
1758 wWindowResetMouseGrabs(wwin);
1760 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1765 void
1766 wWindowUpdateName(WWindow *wwin, char *newTitle)
1768 WApplication *app = wApplicationOf(wwin->main_window);
1769 int instIndex = 0;
1770 Bool res;
1771 char prefix[32] = "";
1772 char *tmp, *title;
1774 if (!wwin->frame)
1775 return;
1777 if (app)
1778 instIndex = wApplicationIndexOfGroup(app);
1781 wwin->flags.wm_name_changed = 1;
1783 if (!newTitle) {
1784 /* the hint was removed */
1785 title = DEF_WINDOW_TITLE;
1787 #ifdef KWM_HINTS
1788 wKWMSendEventMessage(wwin, WKWMChangedClient);
1789 #endif
1790 } else {
1791 title = newTitle;
1794 if (instIndex > 0) {
1795 sprintf(prefix, " [%i]", instIndex);
1797 title = wstrconcat(title, prefix);
1800 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1801 /* only update the menu if the title has actually changed */
1802 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE);
1803 #ifdef KWM_HINTS
1804 wKWMSendEventMessage(wwin, WKWMChangedClient);
1805 #endif
1807 if (instIndex > 0)
1808 wfree(title);
1814 *----------------------------------------------------------------------
1816 * wWindowConstrainSize--
1817 * Constrains size for the client window, taking the maximal size,
1818 * window resize increments and other size hints into account.
1820 * Returns:
1821 * The closest size to what was given that the client window can
1822 * have.
1824 *----------------------------------------------------------------------
1826 void
1827 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1829 int width = *nwidth;
1830 int height = *nheight;
1831 int winc = 1;
1832 int hinc = 1;
1833 int minW = 1, minH = 1;
1834 int maxW = wwin->screen_ptr->scr_width*2;
1835 int maxH = wwin->screen_ptr->scr_height*2;
1836 int minAX = -1, minAY = -1;
1837 int maxAX = -1, maxAY = -1;
1838 int baseW = 0;
1839 int baseH = 0;
1841 if (wwin->normal_hints) {
1842 winc = wwin->normal_hints->width_inc;
1843 hinc = wwin->normal_hints->height_inc;
1844 minW = wwin->normal_hints->min_width;
1845 minH = wwin->normal_hints->min_height;
1846 maxW = wwin->normal_hints->max_width;
1847 maxH = wwin->normal_hints->max_height;
1848 if (wwin->normal_hints->flags & PAspect) {
1849 minAX = wwin->normal_hints->min_aspect.x;
1850 minAY = wwin->normal_hints->min_aspect.y;
1851 maxAX = wwin->normal_hints->max_aspect.x;
1852 maxAY = wwin->normal_hints->max_aspect.y;
1856 if (width < minW)
1857 width = minW;
1858 if (height < minH)
1859 height = minH;
1861 if (width > maxW)
1862 width = maxW;
1863 if (height > maxH)
1864 height = maxH;
1866 /* aspect ratio code borrowed from olwm */
1867 if (minAX > 0) {
1868 /* adjust max aspect ratio */
1869 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1870 if (maxAX > maxAY) {
1871 height = (width * maxAY) / maxAX;
1872 if (height > maxH) {
1873 height = maxH;
1874 width = (height * maxAX) / maxAY;
1876 } else {
1877 width = (height * maxAX) / maxAY;
1878 if (width > maxW) {
1879 width = maxW;
1880 height = (width * maxAY) / maxAX;
1885 /* adjust min aspect ratio */
1886 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1887 if (minAX > minAY) {
1888 height = (width * minAY) / minAX;
1889 if (height < minH) {
1890 height = minH;
1891 width = (height * minAX) / minAY;
1893 } else {
1894 width = (height * minAX) / minAY;
1895 if (width < minW) {
1896 width = minW;
1897 height = (width * minAY) / minAX;
1903 if (baseW != 0) {
1904 width = (((width - baseW) / winc) * winc) + baseW;
1905 } else {
1906 width = (((width - minW) / winc) * winc) + minW;
1909 if (baseW != 0) {
1910 height = (((height - baseH) / hinc) * hinc) + baseH;
1911 } else {
1912 height = (((height - minH) / hinc) * hinc) + minH;
1915 /* broken stupid apps may cause preposterous values for these.. */
1916 if (width > 0)
1917 *nwidth = width;
1918 if (height > 0)
1919 *nheight = height;
1923 void
1924 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1926 WScreen *scr = wwin->screen_ptr;
1927 WApplication *wapp;
1928 int unmap = 0;
1930 if (workspace >= scr->workspace_count || workspace < 0
1931 || workspace == wwin->frame->workspace)
1932 return;
1934 if (workspace != scr->current_workspace) {
1935 /* Sent to other workspace. Unmap window */
1936 if ((wwin->flags.mapped
1937 || wwin->flags.shaded
1938 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1939 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1941 wapp = wApplicationOf(wwin->main_window);
1942 if (wapp) {
1943 wapp->last_workspace = workspace;
1945 if (wwin->flags.miniaturized) {
1946 if (wwin->icon) {
1947 XUnmapWindow(dpy, wwin->icon->core->window);
1948 wwin->icon->mapped = 0;
1950 } else {
1951 unmap = 1;
1952 wSetFocusTo(scr, NULL);
1955 } else {
1956 /* brought to current workspace. Map window */
1957 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1958 if (wwin->icon) {
1959 XMapWindow(dpy, wwin->icon->core->window);
1960 wwin->icon->mapped = 1;
1962 } else if (!wwin->flags.mapped &&
1963 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1964 wWindowMap(wwin);
1967 if (!IS_OMNIPRESENT(wwin)) {
1968 wwin->frame->workspace = workspace;
1969 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1971 #ifdef GNOME_STUFF
1972 wGNOMEUpdateClientStateHint(wwin, True);
1973 #endif
1974 #ifdef KWM_HINTS
1975 wKWMUpdateClientWorkspace(wwin);
1976 wKWMSendEventMessage(wwin, WKWMChangedClient);
1977 #endif
1978 if (unmap) {
1979 wWindowUnmap(wwin);
1984 void
1985 wWindowSynthConfigureNotify(WWindow *wwin)
1987 XEvent sevent;
1989 sevent.type = ConfigureNotify;
1990 sevent.xconfigure.display = dpy;
1991 sevent.xconfigure.event = wwin->client_win;
1992 sevent.xconfigure.window = wwin->client_win;
1994 sevent.xconfigure.x = wwin->client.x;
1995 sevent.xconfigure.y = wwin->client.y;
1996 sevent.xconfigure.width = wwin->client.width;
1997 sevent.xconfigure.height = wwin->client.height;
1999 sevent.xconfigure.border_width = wwin->old_border_width;
2000 if (WFLAGP(wwin, no_titlebar))
2001 sevent.xconfigure.above = None;
2002 else
2003 sevent.xconfigure.above = wwin->frame->titlebar->window;
2005 sevent.xconfigure.override_redirect = False;
2006 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2007 #ifdef KWM_HINTS
2008 wKWMSendEventMessage(wwin, WKWMChangedClient);
2009 #endif
2010 XFlush(dpy);
2015 *----------------------------------------------------------------------
2016 * wWindowConfigure--
2017 * Configures the frame, decorations and client window to the
2018 * specified geometry. The geometry is not checked for validity,
2019 * wWindowConstrainSize() must be used for that.
2020 * The size parameters are for the client window, but the position is
2021 * for the frame.
2022 * The client window receives a ConfigureNotify event, according
2023 * to what ICCCM says.
2025 * Returns:
2026 * None
2028 * Side effects:
2029 * Window size and position are changed and client window receives
2030 * a ConfigureNotify event.
2031 *----------------------------------------------------------------------
2033 void
2034 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2035 WWindow *wwin;
2036 int req_x, req_y; /* new position of the frame */
2037 int req_width, req_height; /* new size of the client */
2039 int synth_notify = False;
2040 int resize;
2042 resize = (req_width!=wwin->client.width
2043 || req_height!=wwin->client.height);
2045 * if the window is being moved but not resized then
2046 * send a synthetic ConfigureNotify
2048 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2049 synth_notify = True;
2052 if (WFLAGP(wwin, dont_move_off))
2053 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2054 req_width, req_height);
2055 if (resize) {
2056 if (req_width < MIN_WINDOW_SIZE)
2057 req_width = MIN_WINDOW_SIZE;
2058 if (req_height < MIN_WINDOW_SIZE)
2059 req_height = MIN_WINDOW_SIZE;
2061 /* If growing, resize inner part before frame,
2062 * if shrinking, resize frame before.
2063 * This will prevent the frame (that can have a different color)
2064 * to be exposed, causing flicker */
2065 if (req_height > wwin->frame->core->height
2066 || req_width > wwin->frame->core->width)
2067 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2069 if (wwin->flags.shaded) {
2070 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2071 req_width, wwin->frame->core->height);
2072 wwin->old_geometry.height = req_height;
2073 } else {
2074 int h;
2076 h = req_height + wwin->frame->top_width
2077 + wwin->frame->bottom_width;
2079 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2082 if (!(req_height > wwin->frame->core->height
2083 || req_width > wwin->frame->core->width))
2084 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2086 wwin->client.x = req_x;
2087 wwin->client.y = req_y + wwin->frame->top_width;
2088 wwin->client.width = req_width;
2089 wwin->client.height = req_height;
2090 } else {
2091 wwin->client.x = req_x;
2092 wwin->client.y = req_y + wwin->frame->top_width;
2094 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2096 wwin->frame_x = req_x;
2097 wwin->frame_y = req_y;
2098 if (!WFLAGP(wwin, no_border)) {
2099 wwin->client.x += FRAME_BORDER_WIDTH;
2100 wwin->client.y += FRAME_BORDER_WIDTH;
2103 #ifdef SHAPE
2104 if (wShapeSupported && wwin->flags.shaped && resize) {
2105 wWindowSetShape(wwin);
2107 #endif
2109 if (synth_notify)
2110 wWindowSynthConfigureNotify(wwin);
2111 XFlush(dpy);
2115 void
2116 wWindowMove(wwin, req_x, req_y)
2117 WWindow *wwin;
2118 int req_x, req_y; /* new position of the frame */
2120 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2121 int synth_notify = False;
2123 /* Send a synthetic ConfigureNotify event for every window movement. */
2124 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2125 synth_notify = True;
2127 #else
2128 /* A single synthetic ConfigureNotify event is sent at the end of
2129 * a completed (opaque) movement in moveres.c */
2130 #endif
2132 if (WFLAGP(wwin, dont_move_off))
2133 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2134 wwin->frame->core->width, wwin->frame->core->height);
2136 wwin->client.x = req_x;
2137 wwin->client.y = req_y + wwin->frame->top_width;
2138 if (!WFLAGP(wwin, no_border)) {
2139 wwin->client.x += FRAME_BORDER_WIDTH;
2140 wwin->client.y += FRAME_BORDER_WIDTH;
2143 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2145 wwin->frame_x = req_x;
2146 wwin->frame_y = req_y;
2148 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2149 if (synth_notify)
2150 wWindowSynthConfigureNotify(wwin);
2151 #endif
2155 void
2156 wWindowUpdateButtonImages(WWindow *wwin)
2158 WScreen *scr = wwin->screen_ptr;
2159 Pixmap pixmap, mask;
2160 WFrameWindow *fwin = wwin->frame;
2162 if (WFLAGP(wwin, no_titlebar))
2163 return;
2165 /* miniaturize button */
2167 if (!WFLAGP(wwin, no_miniaturize_button)) {
2168 if (wwin->wm_gnustep_attr
2169 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2170 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2172 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2173 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2174 } else {
2175 mask = None;
2178 if (fwin->lbutton_image
2179 && (fwin->lbutton_image->image != pixmap
2180 || fwin->lbutton_image->mask != mask)) {
2181 wPixmapDestroy(fwin->lbutton_image);
2182 fwin->lbutton_image = NULL;
2185 if (!fwin->lbutton_image) {
2186 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2187 fwin->lbutton_image->client_owned = 1;
2188 fwin->lbutton_image->client_owned_mask = 1;
2190 } else {
2191 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2192 wPixmapDestroy(fwin->lbutton_image);
2194 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2198 #ifdef XKB_BUTTON_HINT
2199 if (!WFLAGP(wwin, no_language_button)) {
2200 if (fwin->languagebutton_image &&
2201 !fwin->languagebutton_image->shared) {
2202 wPixmapDestroy(fwin->languagebutton_image);
2204 fwin->languagebutton_image =
2205 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2207 #endif
2209 /* close button */
2211 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2212 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2214 if (!WFLAGP(wwin, no_close_button)) {
2215 if (wwin->wm_gnustep_attr
2216 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2217 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2219 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2220 mask = wwin->wm_gnustep_attr->close_mask;
2221 else
2222 mask = None;
2224 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2225 || fwin->rbutton_image->mask != mask)) {
2226 wPixmapDestroy(fwin->rbutton_image);
2227 fwin->rbutton_image = NULL;
2230 if (!fwin->rbutton_image) {
2231 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2232 fwin->rbutton_image->client_owned = 1;
2233 fwin->rbutton_image->client_owned_mask = 1;
2236 } else if (WFLAGP(wwin, kill_close)) {
2238 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2239 wPixmapDestroy(fwin->rbutton_image);
2241 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2243 } else if (MGFLAGP(wwin, broken_close)) {
2245 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2246 wPixmapDestroy(fwin->rbutton_image);
2248 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2250 } else {
2252 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2253 wPixmapDestroy(fwin->rbutton_image);
2255 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2259 /* force buttons to be redrawn */
2260 fwin->flags.need_texture_change = 1;
2261 wFrameWindowPaint(fwin);
2266 *---------------------------------------------------------------------------
2267 * wWindowConfigureBorders--
2268 * Update window border configuration according to attribute flags.
2270 *---------------------------------------------------------------------------
2272 void
2273 wWindowConfigureBorders(WWindow *wwin)
2275 if (wwin->frame) {
2276 int flags;
2277 int newy, oldh;
2279 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2280 #ifdef XKB_BUTTON_HINT
2281 flags |= WFF_LANGUAGE_BUTTON;
2282 #endif
2283 if (!WFLAGP(wwin, no_titlebar))
2284 flags |= WFF_TITLEBAR;
2285 if (!WFLAGP(wwin, no_resizebar))
2286 flags |= WFF_RESIZEBAR;
2287 if (!WFLAGP(wwin, no_border))
2288 flags |= WFF_BORDER;
2289 if (wwin->flags.shaded)
2290 flags |= WFF_IS_SHADED;
2292 oldh = wwin->frame->top_width;
2293 wFrameWindowUpdateBorders(wwin->frame, flags);
2294 if (oldh != wwin->frame->top_width) {
2295 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2297 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2298 wWindowConfigure(wwin, wwin->frame_x, newy,
2299 wwin->client.width, wwin->client.height);
2302 flags = 0;
2303 if (!WFLAGP(wwin, no_miniaturize_button)
2304 && wwin->frame->flags.hide_left_button)
2305 flags |= WFF_LEFT_BUTTON;
2307 #ifdef XKB_BUTTON_HINT
2308 if (!WFLAGP(wwin, no_language_button)
2309 && wwin->frame->flags.hide_language_button)
2310 flags |= WFF_LANGUAGE_BUTTON;
2311 #endif
2313 if (!WFLAGP(wwin, no_close_button)
2314 && wwin->frame->flags.hide_right_button)
2315 flags |= WFF_RIGHT_BUTTON;
2317 if (flags!=0) {
2318 wWindowUpdateButtonImages(wwin);
2319 wFrameWindowShowButton(wwin->frame, flags);
2322 flags = 0;
2323 if (WFLAGP(wwin, no_miniaturize_button)
2324 && !wwin->frame->flags.hide_left_button)
2325 flags |= WFF_LEFT_BUTTON;
2327 #ifdef XKB_BUTTON_HINT
2328 if (WFLAGP(wwin, no_language_button)
2329 && !wwin->frame->flags.hide_language_button)
2330 flags |= WFF_LANGUAGE_BUTTON;
2331 #endif
2333 if (WFLAGP(wwin, no_close_button)
2334 && !wwin->frame->flags.hide_right_button)
2335 flags |= WFF_RIGHT_BUTTON;
2337 if (flags!=0)
2338 wFrameWindowHideButton(wwin->frame, flags);
2340 #ifdef SHAPE
2341 if (wShapeSupported && wwin->flags.shaped) {
2342 wWindowSetShape(wwin);
2344 #endif
2349 void
2350 wWindowSaveState(WWindow *wwin)
2352 CARD32 data[10];
2353 int i;
2355 memset(data, 0, sizeof(CARD32)*10);
2356 data[0] = wwin->frame->workspace;
2357 data[1] = wwin->flags.miniaturized;
2358 data[2] = wwin->flags.shaded;
2359 data[3] = wwin->flags.hidden;
2360 data[4] = wwin->flags.maximized;
2361 if (wwin->flags.maximized == 0) {
2362 data[5] = wwin->frame_x;
2363 data[6] = wwin->frame_y;
2364 data[7] = wwin->frame->core->width;
2365 data[8] = wwin->frame->core->height;
2366 } else {
2367 data[5] = wwin->old_geometry.x;
2368 data[6] = wwin->old_geometry.y;
2369 data[7] = wwin->old_geometry.width;
2370 data[8] = wwin->old_geometry.height;
2373 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2374 if (wwin->screen_ptr->shortcutWindows[i] &&
2375 WMCountInBag(wwin->screen_ptr->shortcutWindows[i], wwin))
2376 data[9] |= 1<<i;
2378 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2379 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2380 (unsigned char *)data, 10);
2384 static int
2385 getSavedState(Window window, WSavedState **state)
2387 Atom type_ret;
2388 int fmt_ret;
2389 unsigned long nitems_ret;
2390 unsigned long bytes_after_ret;
2391 CARD32 *data;
2393 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2394 True, _XA_WINDOWMAKER_STATE,
2395 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2396 (unsigned char **)&data)!=Success || !data)
2397 return 0;
2399 *state = malloc(sizeof(WSavedState));
2401 if (*state) {
2402 (*state)->workspace = data[0];
2403 (*state)->miniaturized = data[1];
2404 (*state)->shaded = data[2];
2405 (*state)->hidden = data[3];
2406 (*state)->maximized = data[4];
2407 (*state)->x = data[5];
2408 (*state)->y = data[6];
2409 (*state)->w = data[7];
2410 (*state)->h = data[8];
2411 (*state)->window_shortcuts = data[9];
2413 XFree(data);
2415 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2416 return 1;
2417 else
2418 return 0;
2422 #ifdef SHAPE
2423 void
2424 wWindowClearShape(WWindow *wwin)
2426 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2427 0, wwin->frame->top_width, None, ShapeSet);
2428 XFlush(dpy);
2431 void
2432 wWindowSetShape(WWindow *wwin)
2434 XRectangle rect[2];
2435 int count;
2436 #ifdef OPTIMIZE_SHAPE
2437 XRectangle *rects;
2438 XRectangle *urec;
2439 int ordering;
2441 /* only shape is the client's */
2442 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2443 goto alt_code;
2446 /* Get array of rectangles describing the shape mask */
2447 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2448 &count, &ordering);
2449 if (!rects) {
2450 goto alt_code;
2453 urec = malloc(sizeof(XRectangle)*(count+2));
2454 if (!urec) {
2455 XFree(rects);
2456 goto alt_code;
2459 /* insert our decoration rectangles in the rect list */
2460 memcpy(urec, rects, sizeof(XRectangle)*count);
2461 XFree(rects);
2463 if (!WFLAGP(wwin, no_titlebar)) {
2464 urec[count].x = -1;
2465 urec[count].y = -1 - wwin->frame->top_width;
2466 urec[count].width = wwin->frame->core->width + 2;
2467 urec[count].height = wwin->frame->top_width + 1;
2468 count++;
2470 if (!WFLAGP(wwin, no_resizebar)) {
2471 urec[count].x = -1;
2472 urec[count].y = wwin->frame->core->height
2473 - wwin->frame->bottom_width - wwin->frame->top_width;
2474 urec[count].width = wwin->frame->core->width + 2;
2475 urec[count].height = wwin->frame->bottom_width + 1;
2476 count++;
2479 /* shape our frame window */
2480 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2481 0, wwin->frame->top_width, urec, count,
2482 ShapeSet, Unsorted);
2483 XFlush(dpy);
2484 wfree(urec);
2485 return;
2487 alt_code:
2488 #endif /* OPTIMIZE_SHAPE */
2489 count = 0;
2490 if (!WFLAGP(wwin, no_titlebar)) {
2491 rect[count].x = -1;
2492 rect[count].y = -1;
2493 rect[count].width = wwin->frame->core->width + 2;
2494 rect[count].height = wwin->frame->top_width + 1;
2495 count++;
2497 if (!WFLAGP(wwin, no_resizebar)) {
2498 rect[count].x = -1;
2499 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2500 rect[count].width = wwin->frame->core->width + 2;
2501 rect[count].height = wwin->frame->bottom_width + 1;
2502 count++;
2504 if (count > 0) {
2505 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2506 0, 0, rect, count, ShapeSet, Unsorted);
2508 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2509 0, wwin->frame->top_width, wwin->client_win,
2510 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2511 XFlush(dpy);
2513 #endif /* SHAPE */
2515 /* ====================================================================== */
2517 static FocusMode
2518 getFocusMode(WWindow *wwin)
2520 FocusMode mode;
2522 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2523 if (wwin->wm_hints->input == True) {
2524 if (wwin->protocols.TAKE_FOCUS)
2525 mode = WFM_LOCALLY_ACTIVE;
2526 else
2527 mode = WFM_PASSIVE;
2528 } else {
2529 if (wwin->protocols.TAKE_FOCUS)
2530 mode = WFM_GLOBALLY_ACTIVE;
2531 else
2532 mode = WFM_NO_INPUT;
2534 } else {
2535 mode = WFM_PASSIVE;
2537 return mode;
2541 void
2542 wWindowSetKeyGrabs(WWindow *wwin)
2544 int i;
2545 WShortKey *key;
2547 for (i=0; i<WKBD_LAST; i++) {
2548 key = &wKeyBindings[i];
2550 if (key->keycode==0)
2551 continue;
2552 if (key->modifier!=AnyModifier) {
2553 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2554 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2555 #ifdef NUMLOCK_HACK
2556 /* Also grab all modifier combinations possible that include,
2557 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2558 * work even if the NumLock/ScrollLock key is on.
2560 wHackedGrabKey(key->keycode, key->modifier,
2561 wwin->frame->core->window, True, GrabModeAsync,
2562 GrabModeAsync);
2563 #endif
2565 XGrabKey(dpy, key->keycode, key->modifier,
2566 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2569 #ifndef LITE
2570 wRootMenuBindShortcuts(wwin->frame->core->window);
2571 #endif
2576 void
2577 wWindowResetMouseGrabs(WWindow *wwin)
2579 /* Mouse grabs can't be done on the client window because of
2580 * ICCCM and because clients that try to do the same will crash.
2582 * But there is a problem wich makes tbar buttons of unfocused
2583 * windows not usable as the click goes to the frame window instead
2584 * of the button itself. Must figure a way to fix that.
2587 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2589 if (!WFLAGP(wwin, no_bind_mouse)) {
2590 /* grabs for Meta+drag */
2591 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2592 True, ButtonPressMask, GrabModeSync,
2593 GrabModeAsync, None, None);
2596 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2597 && !wwin->flags.is_gnustep) {
2598 /* the passive grabs to focus the window */
2599 /* if (wPreferences.focus_mode == WKF_CLICK) */
2600 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2601 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2602 None, None);
2604 XFlush(dpy);
2608 void
2609 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2611 if (attr->flags & GSExtraFlagsAttr) {
2612 if (MGFLAGP(wwin, broken_close) !=
2613 (attr->extra_flags & GSDocumentEditedFlag)) {
2614 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2615 wWindowUpdateButtonImages(wwin);
2621 WMagicNumber
2622 wWindowAddSavedState(char *instance, char *class, char *command,
2623 pid_t pid, WSavedState *state)
2625 WWindowState *wstate;
2627 wstate = malloc(sizeof(WWindowState));
2628 if (!wstate)
2629 return 0;
2631 memset(wstate, 0, sizeof(WWindowState));
2632 wstate->pid = pid;
2633 if (instance)
2634 wstate->instance = wstrdup(instance);
2635 if (class)
2636 wstate->class = wstrdup(class);
2637 if (command)
2638 wstate->command = wstrdup(command);
2639 wstate->state = state;
2641 wstate->next = windowState;
2642 windowState = wstate;
2644 #ifdef DEBUG
2645 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2646 class, command);
2647 #endif
2649 return wstate;
2653 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2656 WMagicNumber
2657 wWindowGetSavedState(Window win)
2659 char *instance, *class, *command=NULL;
2660 WWindowState *wstate = windowState;
2661 char **argv;
2662 int argc;
2664 if (!wstate)
2665 return NULL;
2667 if (XGetCommand(dpy, win, &argv, &argc)) {
2668 if (argc > 0)
2669 command = wtokenjoin(argv, argc);
2670 XFreeStringList(argv);
2672 if (!command)
2673 return NULL;
2675 if (PropGetWMClass(win, &class, &instance)) {
2676 while (wstate) {
2677 if (SAME(instance, wstate->instance) &&
2678 SAME(class, wstate->class) &&
2679 SAME(command, wstate->command)) {
2680 break;
2682 wstate = wstate->next;
2684 } else {
2685 wstate = NULL;
2688 #ifdef DEBUG
2689 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2690 class, command);
2691 #endif
2693 if (command) wfree(command);
2694 if (instance) XFree(instance);
2695 if (class) XFree(class);
2697 return wstate;
2701 void
2702 wWindowDeleteSavedState(WMagicNumber id)
2704 WWindowState *tmp, *wstate=(WWindowState*)id;
2706 if (!wstate || !windowState)
2707 return;
2709 tmp = windowState;
2710 if (tmp==wstate) {
2711 windowState = wstate->next;
2712 #ifdef DEBUG
2713 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2714 wstate, wstate->instance, wstate->class, wstate->command);
2715 #endif
2716 if (wstate->instance) wfree(wstate->instance);
2717 if (wstate->class) wfree(wstate->class);
2718 if (wstate->command) wfree(wstate->command);
2719 wfree(wstate->state);
2720 wfree(wstate);
2721 } else {
2722 while (tmp->next) {
2723 if (tmp->next==wstate) {
2724 tmp->next=wstate->next;
2725 #ifdef DEBUG
2726 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2727 wstate, wstate->instance, wstate->class, wstate->command);
2728 #endif
2729 if (wstate->instance) wfree(wstate->instance);
2730 if (wstate->class) wfree(wstate->class);
2731 if (wstate->command) wfree(wstate->command);
2732 wfree(wstate->state);
2733 wfree(wstate);
2734 break;
2736 tmp = tmp->next;
2742 void
2743 wWindowDeleteSavedStatesForPID(pid_t pid)
2745 WWindowState *tmp, *wstate;
2747 if (!windowState)
2748 return;
2750 tmp = windowState;
2751 if (tmp->pid == pid) {
2752 wstate = windowState;
2753 windowState = tmp->next;
2754 #ifdef DEBUG
2755 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2756 wstate, wstate->instance, wstate->class, wstate->command);
2757 #endif
2758 if (wstate->instance) wfree(wstate->instance);
2759 if (wstate->class) wfree(wstate->class);
2760 if (wstate->command) wfree(wstate->command);
2761 wfree(wstate->state);
2762 wfree(wstate);
2763 } else {
2764 while (tmp->next) {
2765 if (tmp->next->pid==pid) {
2766 wstate = tmp->next;
2767 tmp->next = wstate->next;
2768 #ifdef DEBUG
2769 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2770 wstate, wstate->instance, wstate->class, wstate->command);
2771 #endif
2772 if (wstate->instance) wfree(wstate->instance);
2773 if (wstate->class) wfree(wstate->class);
2774 if (wstate->command) wfree(wstate->command);
2775 wfree(wstate->state);
2776 wfree(wstate);
2777 break;
2779 tmp = tmp->next;
2785 /* ====================================================================== */
2787 static void
2788 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2790 WWindow *wwin = data;
2792 #ifndef NUMLOCK_HACK
2793 if ((event->xbutton.state & ValidModMask)
2794 != (event->xbutton.state & ~LockMask)) {
2795 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2796 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2798 #endif
2800 event->xbutton.state &= ValidModMask;
2802 CloseWindowMenu(wwin->screen_ptr);
2804 if (wPreferences.focus_mode==WKF_CLICK
2805 && !(event->xbutton.state&ControlMask)
2806 && !WFLAGP(wwin, no_focusable)) {
2807 wSetFocusTo(wwin->screen_ptr, wwin);
2810 if (event->xbutton.button == Button1)
2811 wRaiseFrame(wwin->frame->core);
2813 if (event->xbutton.window != wwin->frame->resizebar->window) {
2814 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2815 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2816 GrabModeAsync, GrabModeAsync, None,
2817 None, CurrentTime)!=GrabSuccess) {
2818 #ifdef DEBUG0
2819 wwarning("pointer grab failed for window move");
2820 #endif
2821 return;
2825 if (event->xbutton.state & MOD_MASK) {
2826 /* move the window */
2827 wMouseMoveWindow(wwin, event);
2828 XUngrabPointer(dpy, CurrentTime);
2829 } else {
2830 wMouseResizeWindow(wwin, event);
2831 XUngrabPointer(dpy, CurrentTime);
2837 static void
2838 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2840 WWindow *wwin = data;
2842 event->xbutton.state &= ValidModMask;
2844 if (event->xbutton.button==Button1) {
2845 if (event->xbutton.state == 0) {
2846 if (!WFLAGP(wwin, no_shadeable)) {
2847 /* shade window */
2848 if (wwin->flags.shaded)
2849 wUnshadeWindow(wwin);
2850 else
2851 wShadeWindow(wwin);
2853 } else {
2854 int dir = 0;
2856 if (event->xbutton.state & ControlMask)
2857 dir |= MAX_VERTICAL;
2859 if (event->xbutton.state & ShiftMask) {
2860 dir |= MAX_HORIZONTAL;
2861 if (!(event->xbutton.state & ControlMask))
2862 wSelectWindow(wwin, !wwin->flags.selected);
2865 /* maximize window */
2866 if (dir !=0 && !WFLAGP(wwin, no_resizable)) {
2867 int ndir = dir ^ wwin->flags.maximized;
2868 if (wwin->flags.maximized != 0)
2869 wUnmaximizeWindow(wwin);
2870 if (ndir != 0)
2871 wMaximizeWindow(wwin, ndir);
2874 } else if (event->xbutton.button==Button3) {
2875 if (event->xbutton.state & MOD_MASK) {
2876 wHideOtherApplications(wwin);
2878 } else if (event->xbutton.button==Button2) {
2879 wSelectWindow(wwin, !wwin->flags.selected);
2884 static void
2885 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2887 WWindow *wwin = desc->parent;
2889 event->xbutton.state &= ValidModMask;
2891 CloseWindowMenu(wwin->screen_ptr);
2893 if (/*wPreferences.focus_mode==WKF_CLICK
2894 &&*/ !(event->xbutton.state&ControlMask)
2895 && !WFLAGP(wwin, no_focusable)) {
2896 wSetFocusTo(wwin->screen_ptr, wwin);
2898 if (event->xbutton.button == Button1) {
2899 wRaiseFrame(wwin->frame->core);
2902 if (event->xbutton.state & MOD_MASK) {
2903 /* move the window */
2904 if (XGrabPointer(dpy, wwin->client_win, False,
2905 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2906 GrabModeAsync, GrabModeAsync, None,
2907 None, CurrentTime)!=GrabSuccess) {
2908 #ifdef DEBUG0
2909 wwarning("pointer grab failed for window move");
2910 #endif
2911 return;
2913 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2914 wMouseResizeWindow(wwin, event);
2915 else
2916 wMouseMoveWindow(wwin, event);
2917 XUngrabPointer(dpy, CurrentTime);
2922 static void
2923 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2925 WWindow *wwin = (WWindow*)data;
2927 #ifndef NUMLOCK_HACK
2928 if ((event->xbutton.state & ValidModMask)
2929 != (event->xbutton.state & ~LockMask)) {
2930 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2931 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2933 #endif
2934 event->xbutton.state &= ValidModMask;
2936 CloseWindowMenu(wwin->screen_ptr);
2938 if (wPreferences.focus_mode==WKF_CLICK
2939 && !(event->xbutton.state&ControlMask)
2940 && !WFLAGP(wwin, no_focusable)) {
2941 wSetFocusTo(wwin->screen_ptr, wwin);
2944 if (event->xbutton.button == Button1
2945 || event->xbutton.button == Button2) {
2947 if (event->xbutton.button == Button1) {
2948 if (event->xbutton.state & MOD_MASK) {
2949 wLowerFrame(wwin->frame->core);
2950 } else {
2951 wRaiseFrame(wwin->frame->core);
2954 if ((event->xbutton.state & ShiftMask)
2955 && !(event->xbutton.state & ControlMask)) {
2956 wSelectWindow(wwin, !wwin->flags.selected);
2957 return;
2959 if (event->xbutton.window != wwin->frame->titlebar->window
2960 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2961 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2962 GrabModeAsync, GrabModeAsync, None,
2963 None, CurrentTime)!=GrabSuccess) {
2964 #ifdef DEBUG0
2965 wwarning("pointer grab failed for window move");
2966 #endif
2967 return;
2970 /* move the window */
2971 wMouseMoveWindow(wwin, event);
2973 XUngrabPointer(dpy, CurrentTime);
2974 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2975 && !wwin->flags.internal_window
2976 && !WCHECK_STATE(WSTATE_MODAL)) {
2977 WObjDescriptor *desc;
2979 if (event->xbutton.window != wwin->frame->titlebar->window
2980 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2981 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2982 GrabModeAsync, GrabModeAsync, None,
2983 None, CurrentTime)!=GrabSuccess) {
2984 #ifdef DEBUG0
2985 wwarning("pointer grab failed for window move");
2986 #endif
2987 return;
2990 OpenWindowMenu(wwin, event->xbutton.x_root,
2991 wwin->frame_y+wwin->frame->top_width, False);
2993 /* allow drag select */
2994 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2995 event->xany.send_event = True;
2996 (*desc->handle_mousedown)(desc, event);
2998 XUngrabPointer(dpy, CurrentTime);
3004 static void
3005 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3007 WWindow *wwin = data;
3009 event->xbutton.state &= ValidModMask;
3011 CloseWindowMenu(wwin->screen_ptr);
3013 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3014 return;
3016 /* if control-click, kill the client */
3017 if (event->xbutton.state & ControlMask) {
3018 wClientKill(wwin);
3019 } else {
3020 #ifdef OLWM_HINTS
3021 if (wwin->flags.olwm_push_pin_out) {
3023 wwin->flags.olwm_push_pin_out = 0;
3025 wOLWMChangePushpinState(wwin, True);
3027 wFrameWindowUpdatePushButton(wwin->frame, False);
3029 return;
3031 #endif
3032 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3033 /* send delete message */
3034 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3040 static void
3041 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3043 WWindow *wwin = data;
3045 CloseWindowMenu(wwin->screen_ptr);
3047 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3048 return;
3050 /* send delete message */
3051 if (wwin->protocols.DELETE_WINDOW) {
3052 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3053 } else {
3054 wClientKill(wwin);
3059 #ifdef XKB_BUTTON_HINT
3060 static void
3061 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3063 WWindow *wwin = data;
3064 WFrameWindow *fwin = wwin->frame;
3065 WScreen *scr = fwin->screen_ptr;
3066 XkbStateRec staterec;
3067 int tl;
3069 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3070 return;
3071 tl = wwin->frame->languagemode;
3072 wwin->frame->languagemode = wwin->frame->last_languagemode;
3073 wwin->frame->last_languagemode = tl;
3074 wSetFocusTo(scr, wwin);
3075 wwin->frame->languagebutton_image =
3076 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3077 wwin->frame->languagemode];
3078 wFrameWindowUpdateLanguageButton(wwin->frame);
3079 if (event->xbutton.button == Button3)
3080 return;
3081 wRaiseFrame(fwin->core);
3083 #endif
3086 static void
3087 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3089 WWindow *wwin = data;
3091 event->xbutton.state &= ValidModMask;
3093 CloseWindowMenu(wwin->screen_ptr);
3095 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3096 return;
3098 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3099 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3100 LastTimestamp);
3101 } else {
3102 WApplication *wapp;
3103 if ((event->xbutton.state & ControlMask) ||
3104 (event->xbutton.button == Button3)) {
3106 wapp = wApplicationOf(wwin->main_window);
3107 if (wapp && !WFLAGP(wwin, no_appicon))
3108 wHideApplication(wapp);
3109 } else if (event->xbutton.state==0) {
3110 wIconifyWindow(wwin);