fixed [joeyh@debian.org: Bug#99311: full screen maximization cuts off bottom 6 pixels]
[wmaker-crm.git] / src / window.c
blobe3019c65bc8250cbd076d13097f0275ea0fa34ed
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 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
232 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
233 WMFreeArray(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] = WMCreateArray(4);
867 WMAddToArray(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 unsigned int mask;
1592 int foo;
1593 Window bar, win;
1595 /* This is to let the root window get the keyboard input
1596 * if Sloppy focus mode and no other window get focus.
1597 * This way keybindings will not freeze.
1599 tmp = NULL;
1600 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1601 &foo, &foo, &foo, &foo, &mask))
1602 tmp = wWindowFor(win);
1603 if (tmp == wwin)
1604 tmp = NULL;
1605 newFocusedWindow = tmp;
1606 } else {
1607 newFocusedWindow = NULL;
1611 if (!wwin->flags.internal_window) {
1612 #ifdef GNOME_STUFF
1613 wGNOMERemoveClient(wwin);
1614 #endif
1615 #ifdef KWM_HINTS
1616 wKWMSendEventMessage(wwin, WKWMRemoveWindow);
1617 #endif
1620 #ifdef DEBUG
1621 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1622 (unsigned)frame->window);
1623 #endif
1625 if (wasFocused) {
1626 if (newFocusedWindow != owner && owner) {
1627 if (wwin->flags.is_gnustep == 0)
1628 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1630 wSetFocusTo(scr, newFocusedWindow);
1632 wWindowDestroy(wwin);
1633 XFlush(dpy);
1637 void
1638 wWindowMap(WWindow *wwin)
1640 XMapWindow(dpy, wwin->frame->core->window);
1641 if (!wwin->flags.shaded) {
1642 /* window will be remapped when getting MapNotify */
1643 XSelectInput(dpy, wwin->client_win,
1644 wwin->event_mask & ~StructureNotifyMask);
1645 XMapWindow(dpy, wwin->client_win);
1646 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1648 wwin->flags.mapped = 1;
1653 void
1654 wWindowUnmap(WWindow *wwin)
1656 wwin->flags.mapped = 0;
1658 /* prevent window withdrawal when getting UnmapNotify */
1659 XSelectInput(dpy, wwin->client_win,
1660 wwin->event_mask & ~StructureNotifyMask);
1661 XUnmapWindow(dpy, wwin->client_win);
1662 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1664 XUnmapWindow(dpy, wwin->frame->core->window);
1669 void
1670 wWindowFocus(WWindow *wwin, WWindow *owin)
1672 WWindow *nowner;
1673 WWindow *oowner;
1675 #ifdef KEEP_XKB_LOCK_STATUS
1676 if (wPreferences.modelock) {
1677 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1679 #endif /* KEEP_XKB_LOCK_STATUS */
1681 wwin->flags.semi_focused = 0;
1683 if (wwin->flags.is_gnustep == 0)
1684 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1686 wwin->flags.focused = 1;
1688 wWindowResetMouseGrabs(wwin);
1690 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1692 if (owin == wwin || !owin)
1693 return;
1695 nowner = wWindowFor(wwin->transient_for);
1697 /* new window is a transient for the old window */
1698 if (nowner == owin) {
1699 owin->flags.semi_focused = 1;
1700 wWindowUnfocus(nowner);
1701 return;
1704 oowner = wWindowFor(owin->transient_for);
1706 /* new window is owner of old window */
1707 if (wwin == oowner) {
1708 wWindowUnfocus(owin);
1709 return;
1712 if (!nowner) {
1713 wWindowUnfocus(owin);
1714 return;
1717 /* new window has same owner of old window */
1718 if (oowner == nowner) {
1719 /* prevent unfocusing of owner */
1720 oowner->flags.semi_focused = 0;
1721 wWindowUnfocus(owin);
1722 oowner->flags.semi_focused = 1;
1724 return;
1727 /* nowner != NULL && oowner != nowner */
1728 nowner->flags.semi_focused = 1;
1729 wWindowUnfocus(nowner);
1730 wWindowUnfocus(owin);
1734 void
1735 wWindowUnfocus(WWindow *wwin)
1737 CloseWindowMenu(wwin->screen_ptr);
1739 if (wwin->flags.is_gnustep == 0)
1740 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1741 ? WS_PFOCUSED : WS_UNFOCUSED);
1743 if (wwin->transient_for!=None
1744 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1745 WWindow *owner;
1746 owner = wWindowFor(wwin->transient_for);
1747 if (owner && owner->flags.semi_focused) {
1748 owner->flags.semi_focused = 0;
1749 if (owner->flags.mapped || owner->flags.shaded) {
1750 wWindowUnfocus(owner);
1751 wFrameWindowPaint(owner->frame);
1755 wwin->flags.focused = 0;
1757 wWindowResetMouseGrabs(wwin);
1759 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1764 void
1765 wWindowUpdateName(WWindow *wwin, char *newTitle)
1767 WApplication *app = wApplicationOf(wwin->main_window);
1768 int instIndex = 0;
1769 Bool res;
1770 char prefix[32] = "";
1771 char *tmp, *title;
1773 if (!wwin->frame)
1774 return;
1776 if (app)
1777 instIndex = wApplicationIndexOfGroup(app);
1780 wwin->flags.wm_name_changed = 1;
1782 if (!newTitle) {
1783 /* the hint was removed */
1784 title = DEF_WINDOW_TITLE;
1786 #ifdef KWM_HINTS
1787 wKWMSendEventMessage(wwin, WKWMChangedClient);
1788 #endif
1789 } else {
1790 title = newTitle;
1793 if (instIndex > 0) {
1794 sprintf(prefix, " [%i]", instIndex);
1796 title = wstrconcat(title, prefix);
1799 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1800 /* only update the menu if the title has actually changed */
1801 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE);
1802 #ifdef KWM_HINTS
1803 wKWMSendEventMessage(wwin, WKWMChangedClient);
1804 #endif
1806 if (instIndex > 0)
1807 wfree(title);
1813 *----------------------------------------------------------------------
1815 * wWindowConstrainSize--
1816 * Constrains size for the client window, taking the maximal size,
1817 * window resize increments and other size hints into account.
1819 * Returns:
1820 * The closest size to what was given that the client window can
1821 * have.
1823 *----------------------------------------------------------------------
1825 void
1826 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1828 int width = *nwidth;
1829 int height = *nheight;
1830 int winc = 1;
1831 int hinc = 1;
1832 int minW = 1, minH = 1;
1833 int maxW = wwin->screen_ptr->scr_width*2;
1834 int maxH = wwin->screen_ptr->scr_height*2;
1835 int minAX = -1, minAY = -1;
1836 int maxAX = -1, maxAY = -1;
1837 int baseW = 0;
1838 int baseH = 0;
1840 if (wwin->normal_hints) {
1841 winc = wwin->normal_hints->width_inc;
1842 hinc = wwin->normal_hints->height_inc;
1843 minW = wwin->normal_hints->min_width;
1844 minH = wwin->normal_hints->min_height;
1845 maxW = wwin->normal_hints->max_width;
1846 maxH = wwin->normal_hints->max_height;
1847 if (wwin->normal_hints->flags & PAspect) {
1848 minAX = wwin->normal_hints->min_aspect.x;
1849 minAY = wwin->normal_hints->min_aspect.y;
1850 maxAX = wwin->normal_hints->max_aspect.x;
1851 maxAY = wwin->normal_hints->max_aspect.y;
1854 baseW = wwin->normal_hints->base_width;
1855 baseH = wwin->normal_hints->base_height;
1858 if (width < minW)
1859 width = minW;
1860 if (height < minH)
1861 height = minH;
1863 if (width > maxW)
1864 width = maxW;
1865 if (height > maxH)
1866 height = maxH;
1868 /* aspect ratio code borrowed from olwm */
1869 if (minAX > 0) {
1870 /* adjust max aspect ratio */
1871 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1872 if (maxAX > maxAY) {
1873 height = (width * maxAY) / maxAX;
1874 if (height > maxH) {
1875 height = maxH;
1876 width = (height * maxAX) / maxAY;
1878 } else {
1879 width = (height * maxAX) / maxAY;
1880 if (width > maxW) {
1881 width = maxW;
1882 height = (width * maxAY) / maxAX;
1887 /* adjust min aspect ratio */
1888 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1889 if (minAX > minAY) {
1890 height = (width * minAY) / minAX;
1891 if (height < minH) {
1892 height = minH;
1893 width = (height * minAX) / minAY;
1895 } else {
1896 width = (height * minAX) / minAY;
1897 if (width < minW) {
1898 width = minW;
1899 height = (width * minAY) / minAX;
1905 if (baseW != 0) {
1906 width = (((width - baseW) / winc) * winc) + baseW;
1907 } else {
1908 width = (((width - minW) / winc) * winc) + minW;
1911 if (baseH != 0) {
1912 height = (((height - baseH) / hinc) * hinc) + baseH;
1913 } else {
1914 height = (((height - minH) / hinc) * hinc) + minH;
1917 /* broken stupid apps may cause preposterous values for these.. */
1918 if (width > 0)
1919 *nwidth = width;
1920 if (height > 0)
1921 *nheight = height;
1925 void
1926 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1927 int *width, int *height)
1929 int baseW = 0, baseH = 0;
1930 int winc = 1, hinc = 1;
1932 if (wwin->normal_hints) {
1933 baseW = wwin->normal_hints->base_width;
1934 baseH = wwin->normal_hints->base_height;
1936 winc = wwin->normal_hints->width_inc;
1937 hinc = wwin->normal_hints->height_inc;
1940 if (*width > maxW)
1941 *width = maxW - (maxW - baseW) % winc;
1943 if (*height > maxH)
1944 *height = maxH - (maxH - baseH) % hinc;
1948 void
1949 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1951 WScreen *scr = wwin->screen_ptr;
1952 WApplication *wapp;
1953 int unmap = 0;
1955 if (workspace >= scr->workspace_count || workspace < 0
1956 || workspace == wwin->frame->workspace)
1957 return;
1959 if (workspace != scr->current_workspace) {
1960 /* Sent to other workspace. Unmap window */
1961 if ((wwin->flags.mapped
1962 || wwin->flags.shaded
1963 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1964 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1966 wapp = wApplicationOf(wwin->main_window);
1967 if (wapp) {
1968 wapp->last_workspace = workspace;
1970 if (wwin->flags.miniaturized) {
1971 if (wwin->icon) {
1972 XUnmapWindow(dpy, wwin->icon->core->window);
1973 wwin->icon->mapped = 0;
1975 } else {
1976 unmap = 1;
1977 wSetFocusTo(scr, NULL);
1980 } else {
1981 /* brought to current workspace. Map window */
1982 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1983 if (wwin->icon) {
1984 XMapWindow(dpy, wwin->icon->core->window);
1985 wwin->icon->mapped = 1;
1987 } else if (!wwin->flags.mapped &&
1988 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1989 wWindowMap(wwin);
1992 if (!IS_OMNIPRESENT(wwin)) {
1993 wwin->frame->workspace = workspace;
1994 UpdateSwitchMenu(scr, wwin, ACTION_CHANGE_WORKSPACE);
1996 #ifdef GNOME_STUFF
1997 wGNOMEUpdateClientStateHint(wwin, True);
1998 #endif
1999 #ifdef KWM_HINTS
2000 wKWMUpdateClientWorkspace(wwin);
2001 wKWMSendEventMessage(wwin, WKWMChangedClient);
2002 #endif
2003 if (unmap) {
2004 wWindowUnmap(wwin);
2009 void
2010 wWindowSynthConfigureNotify(WWindow *wwin)
2012 XEvent sevent;
2014 sevent.type = ConfigureNotify;
2015 sevent.xconfigure.display = dpy;
2016 sevent.xconfigure.event = wwin->client_win;
2017 sevent.xconfigure.window = wwin->client_win;
2019 sevent.xconfigure.x = wwin->client.x;
2020 sevent.xconfigure.y = wwin->client.y;
2021 sevent.xconfigure.width = wwin->client.width;
2022 sevent.xconfigure.height = wwin->client.height;
2024 sevent.xconfigure.border_width = wwin->old_border_width;
2025 if (WFLAGP(wwin, no_titlebar))
2026 sevent.xconfigure.above = None;
2027 else
2028 sevent.xconfigure.above = wwin->frame->titlebar->window;
2030 sevent.xconfigure.override_redirect = False;
2031 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2032 #ifdef KWM_HINTS
2033 wKWMSendEventMessage(wwin, WKWMChangedClient);
2034 #endif
2035 XFlush(dpy);
2040 *----------------------------------------------------------------------
2041 * wWindowConfigure--
2042 * Configures the frame, decorations and client window to the
2043 * specified geometry. The geometry is not checked for validity,
2044 * wWindowConstrainSize() must be used for that.
2045 * The size parameters are for the client window, but the position is
2046 * for the frame.
2047 * The client window receives a ConfigureNotify event, according
2048 * to what ICCCM says.
2050 * Returns:
2051 * None
2053 * Side effects:
2054 * Window size and position are changed and client window receives
2055 * a ConfigureNotify event.
2056 *----------------------------------------------------------------------
2058 void
2059 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2060 WWindow *wwin;
2061 int req_x, req_y; /* new position of the frame */
2062 int req_width, req_height; /* new size of the client */
2064 int synth_notify = False;
2065 int resize;
2067 resize = (req_width!=wwin->client.width
2068 || req_height!=wwin->client.height);
2070 * if the window is being moved but not resized then
2071 * send a synthetic ConfigureNotify
2073 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2074 synth_notify = True;
2077 if (WFLAGP(wwin, dont_move_off))
2078 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2079 req_width, req_height);
2080 if (resize) {
2081 if (req_width < MIN_WINDOW_SIZE)
2082 req_width = MIN_WINDOW_SIZE;
2083 if (req_height < MIN_WINDOW_SIZE)
2084 req_height = MIN_WINDOW_SIZE;
2086 /* If growing, resize inner part before frame,
2087 * if shrinking, resize frame before.
2088 * This will prevent the frame (that can have a different color)
2089 * to be exposed, causing flicker */
2090 if (req_height > wwin->frame->core->height
2091 || req_width > wwin->frame->core->width)
2092 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2094 if (wwin->flags.shaded) {
2095 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2096 req_width, wwin->frame->core->height);
2097 wwin->old_geometry.height = req_height;
2098 } else {
2099 int h;
2101 h = req_height + wwin->frame->top_width
2102 + wwin->frame->bottom_width;
2104 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2107 if (!(req_height > wwin->frame->core->height
2108 || req_width > wwin->frame->core->width))
2109 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2111 wwin->client.x = req_x;
2112 wwin->client.y = req_y + wwin->frame->top_width;
2113 wwin->client.width = req_width;
2114 wwin->client.height = req_height;
2115 } else {
2116 wwin->client.x = req_x;
2117 wwin->client.y = req_y + wwin->frame->top_width;
2119 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2121 wwin->frame_x = req_x;
2122 wwin->frame_y = req_y;
2123 if (!WFLAGP(wwin, no_border)) {
2124 wwin->client.x += FRAME_BORDER_WIDTH;
2125 wwin->client.y += FRAME_BORDER_WIDTH;
2128 #ifdef SHAPE
2129 if (wShapeSupported && wwin->flags.shaped && resize) {
2130 wWindowSetShape(wwin);
2132 #endif
2134 if (synth_notify)
2135 wWindowSynthConfigureNotify(wwin);
2136 XFlush(dpy);
2140 void
2141 wWindowMove(wwin, req_x, req_y)
2142 WWindow *wwin;
2143 int req_x, req_y; /* new position of the frame */
2145 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2146 int synth_notify = False;
2148 /* Send a synthetic ConfigureNotify event for every window movement. */
2149 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2150 synth_notify = True;
2152 #else
2153 /* A single synthetic ConfigureNotify event is sent at the end of
2154 * a completed (opaque) movement in moveres.c */
2155 #endif
2157 if (WFLAGP(wwin, dont_move_off))
2158 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2159 wwin->frame->core->width, wwin->frame->core->height);
2161 wwin->client.x = req_x;
2162 wwin->client.y = req_y + wwin->frame->top_width;
2163 if (!WFLAGP(wwin, no_border)) {
2164 wwin->client.x += FRAME_BORDER_WIDTH;
2165 wwin->client.y += FRAME_BORDER_WIDTH;
2168 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2170 wwin->frame_x = req_x;
2171 wwin->frame_y = req_y;
2173 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2174 if (synth_notify)
2175 wWindowSynthConfigureNotify(wwin);
2176 #endif
2180 void
2181 wWindowUpdateButtonImages(WWindow *wwin)
2183 WScreen *scr = wwin->screen_ptr;
2184 Pixmap pixmap, mask;
2185 WFrameWindow *fwin = wwin->frame;
2187 if (WFLAGP(wwin, no_titlebar))
2188 return;
2190 /* miniaturize button */
2192 if (!WFLAGP(wwin, no_miniaturize_button)) {
2193 if (wwin->wm_gnustep_attr
2194 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2195 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2197 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2198 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2199 } else {
2200 mask = None;
2203 if (fwin->lbutton_image
2204 && (fwin->lbutton_image->image != pixmap
2205 || fwin->lbutton_image->mask != mask)) {
2206 wPixmapDestroy(fwin->lbutton_image);
2207 fwin->lbutton_image = NULL;
2210 if (!fwin->lbutton_image) {
2211 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2212 fwin->lbutton_image->client_owned = 1;
2213 fwin->lbutton_image->client_owned_mask = 1;
2215 } else {
2216 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2217 wPixmapDestroy(fwin->lbutton_image);
2219 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2223 #ifdef XKB_BUTTON_HINT
2224 if (!WFLAGP(wwin, no_language_button)) {
2225 if (fwin->languagebutton_image &&
2226 !fwin->languagebutton_image->shared) {
2227 wPixmapDestroy(fwin->languagebutton_image);
2229 fwin->languagebutton_image =
2230 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2232 #endif
2234 /* close button */
2236 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2237 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2239 if (!WFLAGP(wwin, no_close_button)) {
2240 if (wwin->wm_gnustep_attr
2241 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2242 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2244 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2245 mask = wwin->wm_gnustep_attr->close_mask;
2246 else
2247 mask = None;
2249 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2250 || fwin->rbutton_image->mask != mask)) {
2251 wPixmapDestroy(fwin->rbutton_image);
2252 fwin->rbutton_image = NULL;
2255 if (!fwin->rbutton_image) {
2256 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2257 fwin->rbutton_image->client_owned = 1;
2258 fwin->rbutton_image->client_owned_mask = 1;
2261 } else if (WFLAGP(wwin, kill_close)) {
2263 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2264 wPixmapDestroy(fwin->rbutton_image);
2266 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2268 } else if (MGFLAGP(wwin, broken_close)) {
2270 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2271 wPixmapDestroy(fwin->rbutton_image);
2273 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2275 } else {
2277 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2278 wPixmapDestroy(fwin->rbutton_image);
2280 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2284 /* force buttons to be redrawn */
2285 fwin->flags.need_texture_change = 1;
2286 wFrameWindowPaint(fwin);
2291 *---------------------------------------------------------------------------
2292 * wWindowConfigureBorders--
2293 * Update window border configuration according to attribute flags.
2295 *---------------------------------------------------------------------------
2297 void
2298 wWindowConfigureBorders(WWindow *wwin)
2300 if (wwin->frame) {
2301 int flags;
2302 int newy, oldh;
2304 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2305 #ifdef XKB_BUTTON_HINT
2306 flags |= WFF_LANGUAGE_BUTTON;
2307 #endif
2308 if (!WFLAGP(wwin, no_titlebar))
2309 flags |= WFF_TITLEBAR;
2310 if (!WFLAGP(wwin, no_resizebar))
2311 flags |= WFF_RESIZEBAR;
2312 if (!WFLAGP(wwin, no_border))
2313 flags |= WFF_BORDER;
2314 if (wwin->flags.shaded)
2315 flags |= WFF_IS_SHADED;
2317 oldh = wwin->frame->top_width;
2318 wFrameWindowUpdateBorders(wwin->frame, flags);
2319 if (oldh != wwin->frame->top_width) {
2320 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2322 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2323 wWindowConfigure(wwin, wwin->frame_x, newy,
2324 wwin->client.width, wwin->client.height);
2327 flags = 0;
2328 if (!WFLAGP(wwin, no_miniaturize_button)
2329 && wwin->frame->flags.hide_left_button)
2330 flags |= WFF_LEFT_BUTTON;
2332 #ifdef XKB_BUTTON_HINT
2333 if (!WFLAGP(wwin, no_language_button)
2334 && wwin->frame->flags.hide_language_button)
2335 flags |= WFF_LANGUAGE_BUTTON;
2336 #endif
2338 if (!WFLAGP(wwin, no_close_button)
2339 && wwin->frame->flags.hide_right_button)
2340 flags |= WFF_RIGHT_BUTTON;
2342 if (flags!=0) {
2343 wWindowUpdateButtonImages(wwin);
2344 wFrameWindowShowButton(wwin->frame, flags);
2347 flags = 0;
2348 if (WFLAGP(wwin, no_miniaturize_button)
2349 && !wwin->frame->flags.hide_left_button)
2350 flags |= WFF_LEFT_BUTTON;
2352 #ifdef XKB_BUTTON_HINT
2353 if (WFLAGP(wwin, no_language_button)
2354 && !wwin->frame->flags.hide_language_button)
2355 flags |= WFF_LANGUAGE_BUTTON;
2356 #endif
2358 if (WFLAGP(wwin, no_close_button)
2359 && !wwin->frame->flags.hide_right_button)
2360 flags |= WFF_RIGHT_BUTTON;
2362 if (flags!=0)
2363 wFrameWindowHideButton(wwin->frame, flags);
2365 #ifdef SHAPE
2366 if (wShapeSupported && wwin->flags.shaped) {
2367 wWindowSetShape(wwin);
2369 #endif
2374 void
2375 wWindowSaveState(WWindow *wwin)
2377 CARD32 data[10];
2378 int i;
2380 memset(data, 0, sizeof(CARD32)*10);
2381 data[0] = wwin->frame->workspace;
2382 data[1] = wwin->flags.miniaturized;
2383 data[2] = wwin->flags.shaded;
2384 data[3] = wwin->flags.hidden;
2385 data[4] = wwin->flags.maximized;
2386 if (wwin->flags.maximized == 0) {
2387 data[5] = wwin->frame_x;
2388 data[6] = wwin->frame_y;
2389 data[7] = wwin->frame->core->width;
2390 data[8] = wwin->frame->core->height;
2391 } else {
2392 data[5] = wwin->old_geometry.x;
2393 data[6] = wwin->old_geometry.y;
2394 data[7] = wwin->old_geometry.width;
2395 data[8] = wwin->old_geometry.height;
2398 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2399 if (wwin->screen_ptr->shortcutWindows[i] &&
2400 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2401 data[9] |= 1<<i;
2403 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2404 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2405 (unsigned char *)data, 10);
2409 static int
2410 getSavedState(Window window, WSavedState **state)
2412 Atom type_ret;
2413 int fmt_ret;
2414 unsigned long nitems_ret;
2415 unsigned long bytes_after_ret;
2416 CARD32 *data;
2418 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2419 True, _XA_WINDOWMAKER_STATE,
2420 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2421 (unsigned char **)&data)!=Success || !data)
2422 return 0;
2424 *state = wmalloc(sizeof(WSavedState));
2426 (*state)->workspace = data[0];
2427 (*state)->miniaturized = data[1];
2428 (*state)->shaded = data[2];
2429 (*state)->hidden = data[3];
2430 (*state)->maximized = data[4];
2431 (*state)->x = data[5];
2432 (*state)->y = data[6];
2433 (*state)->w = data[7];
2434 (*state)->h = data[8];
2435 (*state)->window_shortcuts = data[9];
2437 XFree(data);
2439 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2440 return 1;
2441 else
2442 return 0;
2446 #ifdef SHAPE
2447 void
2448 wWindowClearShape(WWindow *wwin)
2450 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2451 0, wwin->frame->top_width, None, ShapeSet);
2452 XFlush(dpy);
2455 void
2456 wWindowSetShape(WWindow *wwin)
2458 XRectangle rect[2];
2459 int count;
2460 #ifdef OPTIMIZE_SHAPE
2461 XRectangle *rects;
2462 XRectangle *urec;
2463 int ordering;
2465 /* only shape is the client's */
2466 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2467 goto alt_code;
2470 /* Get array of rectangles describing the shape mask */
2471 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2472 &count, &ordering);
2473 if (!rects) {
2474 goto alt_code;
2477 urec = malloc(sizeof(XRectangle)*(count+2));
2478 if (!urec) {
2479 XFree(rects);
2480 goto alt_code;
2483 /* insert our decoration rectangles in the rect list */
2484 memcpy(urec, rects, sizeof(XRectangle)*count);
2485 XFree(rects);
2487 if (!WFLAGP(wwin, no_titlebar)) {
2488 urec[count].x = -1;
2489 urec[count].y = -1 - wwin->frame->top_width;
2490 urec[count].width = wwin->frame->core->width + 2;
2491 urec[count].height = wwin->frame->top_width + 1;
2492 count++;
2494 if (!WFLAGP(wwin, no_resizebar)) {
2495 urec[count].x = -1;
2496 urec[count].y = wwin->frame->core->height
2497 - wwin->frame->bottom_width - wwin->frame->top_width;
2498 urec[count].width = wwin->frame->core->width + 2;
2499 urec[count].height = wwin->frame->bottom_width + 1;
2500 count++;
2503 /* shape our frame window */
2504 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2505 0, wwin->frame->top_width, urec, count,
2506 ShapeSet, Unsorted);
2507 XFlush(dpy);
2508 wfree(urec);
2509 return;
2511 alt_code:
2512 #endif /* OPTIMIZE_SHAPE */
2513 count = 0;
2514 if (!WFLAGP(wwin, no_titlebar)) {
2515 rect[count].x = -1;
2516 rect[count].y = -1;
2517 rect[count].width = wwin->frame->core->width + 2;
2518 rect[count].height = wwin->frame->top_width + 1;
2519 count++;
2521 if (!WFLAGP(wwin, no_resizebar)) {
2522 rect[count].x = -1;
2523 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2524 rect[count].width = wwin->frame->core->width + 2;
2525 rect[count].height = wwin->frame->bottom_width + 1;
2526 count++;
2528 if (count > 0) {
2529 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2530 0, 0, rect, count, ShapeSet, Unsorted);
2532 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2533 0, wwin->frame->top_width, wwin->client_win,
2534 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2535 XFlush(dpy);
2537 #endif /* SHAPE */
2539 /* ====================================================================== */
2541 static FocusMode
2542 getFocusMode(WWindow *wwin)
2544 FocusMode mode;
2546 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2547 if (wwin->wm_hints->input == True) {
2548 if (wwin->protocols.TAKE_FOCUS)
2549 mode = WFM_LOCALLY_ACTIVE;
2550 else
2551 mode = WFM_PASSIVE;
2552 } else {
2553 if (wwin->protocols.TAKE_FOCUS)
2554 mode = WFM_GLOBALLY_ACTIVE;
2555 else
2556 mode = WFM_NO_INPUT;
2558 } else {
2559 mode = WFM_PASSIVE;
2561 return mode;
2565 void
2566 wWindowSetKeyGrabs(WWindow *wwin)
2568 int i;
2569 WShortKey *key;
2571 for (i=0; i<WKBD_LAST; i++) {
2572 key = &wKeyBindings[i];
2574 if (key->keycode==0)
2575 continue;
2576 if (key->modifier!=AnyModifier) {
2577 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2578 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2579 #ifdef NUMLOCK_HACK
2580 /* Also grab all modifier combinations possible that include,
2581 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2582 * work even if the NumLock/ScrollLock key is on.
2584 wHackedGrabKey(key->keycode, key->modifier,
2585 wwin->frame->core->window, True, GrabModeAsync,
2586 GrabModeAsync);
2587 #endif
2589 XGrabKey(dpy, key->keycode, key->modifier,
2590 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2593 #ifndef LITE
2594 wRootMenuBindShortcuts(wwin->frame->core->window);
2595 #endif
2600 void
2601 wWindowResetMouseGrabs(WWindow *wwin)
2603 /* Mouse grabs can't be done on the client window because of
2604 * ICCCM and because clients that try to do the same will crash.
2606 * But there is a problem wich makes tbar buttons of unfocused
2607 * windows not usable as the click goes to the frame window instead
2608 * of the button itself. Must figure a way to fix that.
2611 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2613 if (!WFLAGP(wwin, no_bind_mouse)) {
2614 /* grabs for Meta+drag */
2615 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2616 True, ButtonPressMask, GrabModeSync,
2617 GrabModeAsync, None, None);
2620 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2621 && !wwin->flags.is_gnustep) {
2622 /* the passive grabs to focus the window */
2623 /* if (wPreferences.focus_mode == WKF_CLICK) */
2624 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2625 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2626 None, None);
2628 XFlush(dpy);
2632 void
2633 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2635 if (attr->flags & GSExtraFlagsAttr) {
2636 if (MGFLAGP(wwin, broken_close) !=
2637 (attr->extra_flags & GSDocumentEditedFlag)) {
2638 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2639 wWindowUpdateButtonImages(wwin);
2645 WMagicNumber
2646 wWindowAddSavedState(char *instance, char *class, char *command,
2647 pid_t pid, WSavedState *state)
2649 WWindowState *wstate;
2651 wstate = malloc(sizeof(WWindowState));
2652 if (!wstate)
2653 return 0;
2655 memset(wstate, 0, sizeof(WWindowState));
2656 wstate->pid = pid;
2657 if (instance)
2658 wstate->instance = wstrdup(instance);
2659 if (class)
2660 wstate->class = wstrdup(class);
2661 if (command)
2662 wstate->command = wstrdup(command);
2663 wstate->state = state;
2665 wstate->next = windowState;
2666 windowState = wstate;
2668 #ifdef DEBUG
2669 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2670 class, command);
2671 #endif
2673 return wstate;
2677 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2680 WMagicNumber
2681 wWindowGetSavedState(Window win)
2683 char *instance, *class, *command=NULL;
2684 WWindowState *wstate = windowState;
2685 char **argv;
2686 int argc;
2688 if (!wstate)
2689 return NULL;
2691 if (XGetCommand(dpy, win, &argv, &argc)) {
2692 if (argc > 0)
2693 command = wtokenjoin(argv, argc);
2694 XFreeStringList(argv);
2696 if (!command)
2697 return NULL;
2699 if (PropGetWMClass(win, &class, &instance)) {
2700 while (wstate) {
2701 if (SAME(instance, wstate->instance) &&
2702 SAME(class, wstate->class) &&
2703 SAME(command, wstate->command)) {
2704 break;
2706 wstate = wstate->next;
2708 } else {
2709 wstate = NULL;
2712 #ifdef DEBUG
2713 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2714 class, command);
2715 #endif
2717 if (command) wfree(command);
2718 if (instance) XFree(instance);
2719 if (class) XFree(class);
2721 return wstate;
2725 void
2726 wWindowDeleteSavedState(WMagicNumber id)
2728 WWindowState *tmp, *wstate=(WWindowState*)id;
2730 if (!wstate || !windowState)
2731 return;
2733 tmp = windowState;
2734 if (tmp==wstate) {
2735 windowState = wstate->next;
2736 #ifdef DEBUG
2737 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2738 wstate, wstate->instance, wstate->class, wstate->command);
2739 #endif
2740 if (wstate->instance) wfree(wstate->instance);
2741 if (wstate->class) wfree(wstate->class);
2742 if (wstate->command) wfree(wstate->command);
2743 wfree(wstate->state);
2744 wfree(wstate);
2745 } else {
2746 while (tmp->next) {
2747 if (tmp->next==wstate) {
2748 tmp->next=wstate->next;
2749 #ifdef DEBUG
2750 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2751 wstate, wstate->instance, wstate->class, wstate->command);
2752 #endif
2753 if (wstate->instance) wfree(wstate->instance);
2754 if (wstate->class) wfree(wstate->class);
2755 if (wstate->command) wfree(wstate->command);
2756 wfree(wstate->state);
2757 wfree(wstate);
2758 break;
2760 tmp = tmp->next;
2766 void
2767 wWindowDeleteSavedStatesForPID(pid_t pid)
2769 WWindowState *tmp, *wstate;
2771 if (!windowState)
2772 return;
2774 tmp = windowState;
2775 if (tmp->pid == pid) {
2776 wstate = windowState;
2777 windowState = tmp->next;
2778 #ifdef DEBUG
2779 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2780 wstate, wstate->instance, wstate->class, wstate->command);
2781 #endif
2782 if (wstate->instance) wfree(wstate->instance);
2783 if (wstate->class) wfree(wstate->class);
2784 if (wstate->command) wfree(wstate->command);
2785 wfree(wstate->state);
2786 wfree(wstate);
2787 } else {
2788 while (tmp->next) {
2789 if (tmp->next->pid==pid) {
2790 wstate = tmp->next;
2791 tmp->next = wstate->next;
2792 #ifdef DEBUG
2793 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2794 wstate, wstate->instance, wstate->class, wstate->command);
2795 #endif
2796 if (wstate->instance) wfree(wstate->instance);
2797 if (wstate->class) wfree(wstate->class);
2798 if (wstate->command) wfree(wstate->command);
2799 wfree(wstate->state);
2800 wfree(wstate);
2801 break;
2803 tmp = tmp->next;
2809 /* ====================================================================== */
2811 static void
2812 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2814 WWindow *wwin = data;
2816 #ifndef NUMLOCK_HACK
2817 if ((event->xbutton.state & ValidModMask)
2818 != (event->xbutton.state & ~LockMask)) {
2819 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2820 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2822 #endif
2824 event->xbutton.state &= ValidModMask;
2826 CloseWindowMenu(wwin->screen_ptr);
2828 if (wPreferences.focus_mode==WKF_CLICK
2829 && !(event->xbutton.state&ControlMask)
2830 && !WFLAGP(wwin, no_focusable)) {
2831 wSetFocusTo(wwin->screen_ptr, wwin);
2834 if (event->xbutton.button == Button1)
2835 wRaiseFrame(wwin->frame->core);
2837 if (event->xbutton.window != wwin->frame->resizebar->window) {
2838 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2839 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2840 GrabModeAsync, GrabModeAsync, None,
2841 None, CurrentTime)!=GrabSuccess) {
2842 #ifdef DEBUG0
2843 wwarning("pointer grab failed for window move");
2844 #endif
2845 return;
2849 if (event->xbutton.state & MOD_MASK) {
2850 /* move the window */
2851 wMouseMoveWindow(wwin, event);
2852 XUngrabPointer(dpy, CurrentTime);
2853 } else {
2854 wMouseResizeWindow(wwin, event);
2855 XUngrabPointer(dpy, CurrentTime);
2861 static void
2862 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2864 WWindow *wwin = data;
2866 event->xbutton.state &= ValidModMask;
2868 if (event->xbutton.button==Button1) {
2869 if (event->xbutton.state == 0) {
2870 if (!WFLAGP(wwin, no_shadeable)) {
2871 /* shade window */
2872 if (wwin->flags.shaded)
2873 wUnshadeWindow(wwin);
2874 else
2875 wShadeWindow(wwin);
2877 } else {
2878 int dir = 0;
2880 if (event->xbutton.state & ControlMask)
2881 dir |= MAX_VERTICAL;
2883 if (event->xbutton.state & ShiftMask) {
2884 dir |= MAX_HORIZONTAL;
2885 if (!(event->xbutton.state & ControlMask))
2886 wSelectWindow(wwin, !wwin->flags.selected);
2889 /* maximize window */
2890 if (dir !=0 && !WFLAGP(wwin, no_resizable)) {
2891 int ndir = dir ^ wwin->flags.maximized;
2892 if (wwin->flags.maximized != 0)
2893 wUnmaximizeWindow(wwin);
2894 if (ndir != 0)
2895 wMaximizeWindow(wwin, ndir);
2898 } else if (event->xbutton.button==Button3) {
2899 if (event->xbutton.state & MOD_MASK) {
2900 wHideOtherApplications(wwin);
2902 } else if (event->xbutton.button==Button2) {
2903 wSelectWindow(wwin, !wwin->flags.selected);
2908 static void
2909 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2911 WWindow *wwin = desc->parent;
2913 event->xbutton.state &= ValidModMask;
2915 CloseWindowMenu(wwin->screen_ptr);
2917 if (/*wPreferences.focus_mode==WKF_CLICK
2918 &&*/ !(event->xbutton.state&ControlMask)
2919 && !WFLAGP(wwin, no_focusable)) {
2920 wSetFocusTo(wwin->screen_ptr, wwin);
2922 if (event->xbutton.button == Button1) {
2923 wRaiseFrame(wwin->frame->core);
2926 if (event->xbutton.state & MOD_MASK) {
2927 /* move the window */
2928 if (XGrabPointer(dpy, wwin->client_win, False,
2929 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2930 GrabModeAsync, GrabModeAsync, None,
2931 None, CurrentTime)!=GrabSuccess) {
2932 #ifdef DEBUG0
2933 wwarning("pointer grab failed for window move");
2934 #endif
2935 return;
2937 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2938 wMouseResizeWindow(wwin, event);
2939 else
2940 wMouseMoveWindow(wwin, event);
2941 XUngrabPointer(dpy, CurrentTime);
2946 static void
2947 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2949 WWindow *wwin = (WWindow*)data;
2951 #ifndef NUMLOCK_HACK
2952 if ((event->xbutton.state & ValidModMask)
2953 != (event->xbutton.state & ~LockMask)) {
2954 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2955 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2957 #endif
2958 event->xbutton.state &= ValidModMask;
2960 CloseWindowMenu(wwin->screen_ptr);
2962 if (wPreferences.focus_mode==WKF_CLICK
2963 && !(event->xbutton.state&ControlMask)
2964 && !WFLAGP(wwin, no_focusable)) {
2965 wSetFocusTo(wwin->screen_ptr, wwin);
2968 if (event->xbutton.button == Button1
2969 || event->xbutton.button == Button2) {
2971 if (event->xbutton.button == Button1) {
2972 if (event->xbutton.state & MOD_MASK) {
2973 wLowerFrame(wwin->frame->core);
2974 } else {
2975 wRaiseFrame(wwin->frame->core);
2978 if ((event->xbutton.state & ShiftMask)
2979 && !(event->xbutton.state & ControlMask)) {
2980 wSelectWindow(wwin, !wwin->flags.selected);
2981 return;
2983 if (event->xbutton.window != wwin->frame->titlebar->window
2984 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2985 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2986 GrabModeAsync, GrabModeAsync, None,
2987 None, CurrentTime)!=GrabSuccess) {
2988 #ifdef DEBUG0
2989 wwarning("pointer grab failed for window move");
2990 #endif
2991 return;
2994 /* move the window */
2995 wMouseMoveWindow(wwin, event);
2997 XUngrabPointer(dpy, CurrentTime);
2998 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2999 && !wwin->flags.internal_window
3000 && !WCHECK_STATE(WSTATE_MODAL)) {
3001 WObjDescriptor *desc;
3003 if (event->xbutton.window != wwin->frame->titlebar->window
3004 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
3005 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
3006 GrabModeAsync, GrabModeAsync, None,
3007 None, CurrentTime)!=GrabSuccess) {
3008 #ifdef DEBUG0
3009 wwarning("pointer grab failed for window move");
3010 #endif
3011 return;
3014 OpenWindowMenu(wwin, event->xbutton.x_root,
3015 wwin->frame_y+wwin->frame->top_width, False);
3017 /* allow drag select */
3018 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3019 event->xany.send_event = True;
3020 (*desc->handle_mousedown)(desc, event);
3022 XUngrabPointer(dpy, CurrentTime);
3028 static void
3029 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3031 WWindow *wwin = data;
3033 event->xbutton.state &= ValidModMask;
3035 CloseWindowMenu(wwin->screen_ptr);
3037 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3038 return;
3040 /* if control-click, kill the client */
3041 if (event->xbutton.state & ControlMask) {
3042 wClientKill(wwin);
3043 } else {
3044 #ifdef OLWM_HINTS
3045 if (wwin->flags.olwm_push_pin_out) {
3047 wwin->flags.olwm_push_pin_out = 0;
3049 wOLWMChangePushpinState(wwin, True);
3051 wFrameWindowUpdatePushButton(wwin->frame, False);
3053 return;
3055 #endif
3056 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3057 /* send delete message */
3058 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3064 static void
3065 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3067 WWindow *wwin = data;
3069 CloseWindowMenu(wwin->screen_ptr);
3071 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3072 return;
3074 /* send delete message */
3075 if (wwin->protocols.DELETE_WINDOW) {
3076 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3077 } else {
3078 wClientKill(wwin);
3083 #ifdef XKB_BUTTON_HINT
3084 static void
3085 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3087 WWindow *wwin = data;
3088 WFrameWindow *fwin = wwin->frame;
3089 WScreen *scr = fwin->screen_ptr;
3090 XkbStateRec staterec;
3091 int tl;
3093 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3094 return;
3095 tl = wwin->frame->languagemode;
3096 wwin->frame->languagemode = wwin->frame->last_languagemode;
3097 wwin->frame->last_languagemode = tl;
3098 wSetFocusTo(scr, wwin);
3099 wwin->frame->languagebutton_image =
3100 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3101 wwin->frame->languagemode];
3102 wFrameWindowUpdateLanguageButton(wwin->frame);
3103 if (event->xbutton.button == Button3)
3104 return;
3105 wRaiseFrame(fwin->core);
3107 #endif
3110 static void
3111 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3113 WWindow *wwin = data;
3115 event->xbutton.state &= ValidModMask;
3117 CloseWindowMenu(wwin->screen_ptr);
3119 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3120 return;
3122 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3123 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3124 LastTimestamp);
3125 } else {
3126 WApplication *wapp;
3127 if ((event->xbutton.state & ControlMask) ||
3128 (event->xbutton.button == Button3)) {
3130 wapp = wApplicationOf(wwin->main_window);
3131 if (wapp && !WFLAGP(wwin, no_appicon))
3132 wHideApplication(wapp);
3133 } else if (event->xbutton.state==0) {
3134 wIconifyWindow(wwin);