- Mapping a new window that belongs to a running application that is hidden,
[wmaker-crm.git] / src / window.c
blob5628480b1af3244c89bd3df72e6fe0d2547e0621
1 /* window.c - client window managing stuffs
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #ifdef SHAPE
28 #include <X11/extensions/shape.h>
29 #endif
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
37 /* For getting mouse wheel mappings from WINGs */
38 #include <WINGs/WINGsP.h>
40 #include "WindowMaker.h"
41 #include "GNUstep.h"
42 #include "wcore.h"
43 #include "framewin.h"
44 #include "texture.h"
45 #include "window.h"
46 #include "winspector.h"
47 #include "icon.h"
48 #include "properties.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "stacking.h"
54 #include "defaults.h"
55 #include "workspace.h"
58 #ifdef MWM_HINTS
59 # include "motif.h"
60 #endif
61 #ifdef KWM_HINTS
62 # include "kwm.h"
63 #endif
64 #ifdef GNOME_STUFF
65 # include "gnome.h"
66 #endif
67 #ifdef OLWM_HINTS
68 # include "openlook.h"
69 #endif
71 /****** Global Variables ******/
73 extern WShortKey wKeyBindings[WKBD_LAST];
75 #ifdef SHAPE
76 extern Bool wShapeSupported;
77 #endif
79 /* contexts */
80 extern XContext wWinContext;
82 /* cursors */
83 extern Cursor wCursor[WCUR_LAST];
85 /* protocol atoms */
86 extern Atom _XA_WM_DELETE_WINDOW;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_WINDOWMAKER_STATE;
91 extern WPreferences wPreferences;
93 #define MOD_MASK wPreferences.modifier_mask
95 extern Time LastTimestamp;
97 /* superfluous... */
98 extern void DoWindowBirth(WWindow*);
102 /***** Local Stuff *****/
105 static WWindowState *windowState=NULL;
109 /* local functions */
110 static FocusMode getFocusMode(WWindow *wwin);
112 static int getSavedState(Window window, WSavedState **state);
114 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
116 /* event handlers */
119 /* frame window (during window grabs) */
120 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
122 /* close button */
123 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
124 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
126 /* iconify button */
127 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
129 #ifdef XKB_BUTTON_HINT
130 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
131 #endif
133 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
134 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
136 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
139 /****** Notification Observers ******/
141 static void
142 appearanceObserver(void *self, WMNotification *notif)
144 WWindow *wwin = (WWindow*)self;
145 int flags = (int)WMGetNotificationClientData(notif);
147 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
148 return;
150 if (flags & WFontSettings) {
151 wWindowConfigureBorders(wwin);
152 if(wwin->flags.shaded) {
153 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
154 wwin->frame->top_width - 1);
156 wwin->client.y = wwin->frame_y - wwin->client.height
157 + wwin->frame->top_width;
158 wWindowSynthConfigureNotify(wwin);
161 if (flags & WTextureSettings) {
162 wwin->frame->flags.need_texture_remake = 1;
164 if (flags & (WTextureSettings | WColorSettings)) {
165 if (wwin->frame->titlebar)
166 XClearWindow(dpy, wwin->frame->titlebar->window);
168 wFrameWindowPaint(wwin->frame);
172 /************************************/
174 WWindow*
175 wWindowFor(Window window)
177 WObjDescriptor *desc;
179 if (window==None)
180 return NULL;
182 if (XFindContext(dpy, window, wWinContext, (XPointer*)&desc)==XCNOENT)
183 return NULL;
185 if (desc->parent_type==WCLASS_WINDOW)
186 return desc->parent;
187 else if (desc->parent_type==WCLASS_FRAME) {
188 WFrameWindow *frame = (WFrameWindow*)desc->parent;
189 if (frame->flags.is_client_window_frame)
190 return frame->child;
193 return NULL;
197 WWindow*
198 wWindowCreate()
200 WWindow *wwin;
202 wwin = wmalloc(sizeof(WWindow));
203 wretain(wwin);
205 memset(wwin, 0, sizeof(WWindow));
207 wwin->client_descriptor.handle_mousedown = frameMouseDown;
208 wwin->client_descriptor.parent = wwin;
209 wwin->client_descriptor.self = wwin;
210 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
212 return wwin;
216 void
217 wWindowDestroy(WWindow *wwin)
219 int i;
221 if (wwin->screen_ptr->cmap_window == wwin) {
222 wwin->screen_ptr->cmap_window = NULL;
225 WMRemoveNotificationObserver(wwin);
227 wwin->flags.destroyed = 1;
229 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
230 if (!wwin->screen_ptr->shortcutWindows[i])
231 continue;
233 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
235 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
236 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
237 wwin->screen_ptr->shortcutWindows[i] = NULL;
241 if (wwin->normal_hints)
242 XFree(wwin->normal_hints);
244 if (wwin->wm_hints)
245 XFree(wwin->wm_hints);
247 if (wwin->wm_instance)
248 XFree(wwin->wm_instance);
250 if (wwin->wm_class)
251 XFree(wwin->wm_class);
253 if (wwin->wm_gnustep_attr)
254 wfree(wwin->wm_gnustep_attr);
256 if (wwin->cmap_windows)
257 XFree(wwin->cmap_windows);
259 XDeleteContext(dpy, wwin->client_win, wWinContext);
261 if (wwin->frame)
262 wFrameWindowDestroy(wwin->frame);
264 if (wwin->icon) {
265 RemoveFromStackList(wwin->icon->core);
266 wIconDestroy(wwin->icon);
267 if (wPreferences.auto_arrange_icons)
268 wArrangeIcons(wwin->screen_ptr, True);
270 wrelease(wwin);
276 static void
277 setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
279 if (gs_hints->flags & GSWindowStyleAttr) {
280 if (gs_hints->window_style == WMBorderlessWindowMask) {
281 wwin->client_flags.no_border = 1;
282 wwin->client_flags.no_titlebar = 1;
283 wwin->client_flags.no_closable = 1;
284 wwin->client_flags.no_miniaturizable = 1;
285 wwin->client_flags.no_resizable = 1;
286 wwin->client_flags.no_close_button = 1;
287 wwin->client_flags.no_miniaturize_button = 1;
288 wwin->client_flags.no_resizebar = 1;
289 } else {
290 wwin->client_flags.no_close_button =
291 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
293 wwin->client_flags.no_closable =
294 ((gs_hints->window_style & WMClosableWindowMask)?0:1);
296 wwin->client_flags.no_miniaturize_button =
297 ((gs_hints->window_style & WMMiniaturizableWindowMask)?0:1);
299 wwin->client_flags.no_miniaturizable =
300 wwin->client_flags.no_miniaturize_button;
302 wwin->client_flags.no_resizebar =
303 ((gs_hints->window_style & WMResizableWindowMask)?0:1);
305 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
307 /* these attributes supposedly imply in the existence
308 * of a titlebar */
309 if (gs_hints->window_style & (WMResizableWindowMask|
310 WMClosableWindowMask|
311 WMMiniaturizableWindowMask)) {
312 wwin->client_flags.no_titlebar = 0;
313 } else {
314 wwin->client_flags.no_titlebar =
315 ((gs_hints->window_style & WMTitledWindowMask)?0:1);
319 } else {
320 /* setup the defaults */
321 wwin->client_flags.no_border = 0;
322 wwin->client_flags.no_titlebar = 0;
323 wwin->client_flags.no_closable = 0;
324 wwin->client_flags.no_miniaturizable = 0;
325 wwin->client_flags.no_resizable = 0;
326 wwin->client_flags.no_close_button = 0;
327 wwin->client_flags.no_miniaturize_button = 0;
328 wwin->client_flags.no_resizebar = 0;
330 if (gs_hints->extra_flags & GSNoApplicationIconFlag) {
331 wwin->client_flags.no_appicon = 1;
336 void
337 wWindowCheckAttributeSanity(WWindow *wwin, WWindowAttributes *wflags,
338 WWindowAttributes *mask)
340 if (wflags->no_appicon && mask->no_appicon)
341 wflags->emulate_appicon = 0;
343 if (wwin->main_window!=None) {
344 WApplication *wapp = wApplicationOf(wwin->main_window);
345 if (wapp && !wapp->flags.emulated)
346 wflags->emulate_appicon = 0;
349 if (wwin->transient_for!=None
350 && wwin->transient_for!=wwin->screen_ptr->root_win)
351 wflags->emulate_appicon = 0;
353 if (wflags->sunken && mask->sunken && wflags->floating && mask->floating)
354 wflags->sunken = 0;
359 void
360 wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
362 WScreen *scr = wwin->screen_ptr;
364 /* sets global default stuff */
365 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
366 &wwin->client_flags, NULL, True);
368 * Decoration setting is done in this precedence (lower to higher)
369 * - use global default in the resource database
370 * - guess some settings
371 * - use GNUstep/external window attributes
372 * - set hints specified for the app in the resource DB
375 WSETUFLAG(wwin, broken_close, 0);
377 if (wwin->protocols.DELETE_WINDOW)
378 WSETUFLAG(wwin, kill_close, 0);
379 else
380 WSETUFLAG(wwin, kill_close, 1);
382 /* transients can't be iconified or maximized */
383 if (wwin->transient_for) {
384 WSETUFLAG(wwin, no_miniaturizable, 1);
385 WSETUFLAG(wwin, no_miniaturize_button, 1);
388 /* if the window can't be resized, remove the resizebar */
389 if (wwin->normal_hints->flags & (PMinSize|PMaxSize)
390 && (wwin->normal_hints->min_width==wwin->normal_hints->max_width)
391 && (wwin->normal_hints->min_height==wwin->normal_hints->max_height)) {
392 WSETUFLAG(wwin, no_resizable, 1);
393 WSETUFLAG(wwin, no_resizebar, 1);
396 /* set GNUstep window attributes */
397 if (wwin->wm_gnustep_attr) {
398 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
400 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
402 *level = wwin->wm_gnustep_attr->window_level;
404 * INT_MIN is the only illegal window level.
406 if (*level == INT_MIN)
407 *level = INT_MIN + 1;
408 } else {
409 /* setup defaults */
410 *level = WMNormalLevel;
412 } else {
413 int tmp_workspace = -1;
414 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
415 Bool check;
417 check = False;
419 #ifdef MWM_HINTS
420 wMWMCheckClientHints(wwin);
421 #endif /* MWM_HINTS */
423 #ifdef GNOME_STUFF
424 check = wGNOMECheckClientHints(wwin, &tmp_level, &tmp_workspace);
425 #endif /* GNOME_STUFF */
427 #ifdef KWM_HINTS
428 if (!check)
429 wKWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
430 #endif /* KWM_HINTS */
432 #ifdef OLWM_HINTS
433 wOLWMCheckClientHints(wwin);
434 #endif /* OLWM_HINTS */
436 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
437 * have INT_MIN that means that no window level was requested. -Dan
439 if (tmp_level == INT_MIN) {
440 if (WFLAGP(wwin, floating))
441 *level = WMFloatingLevel;
442 else if (WFLAGP(wwin, sunken))
443 *level = WMSunkenLevel;
444 else
445 *level = WMNormalLevel;
446 } else {
447 *level = tmp_level;
450 if (tmp_workspace >= 0) {
451 *workspace = tmp_workspace % scr->workspace_count;
456 * Set attributes specified only for that window/class.
457 * This might do duplicate work with the 1st wDefaultFillAttributes().
459 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
460 &wwin->user_flags, &wwin->defined_user_flags,
461 False);
463 * Sanity checks for attributes that depend on other attributes
465 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
466 wwin->user_flags.emulate_appicon = 0;
468 if (wwin->main_window!=None) {
469 WApplication *wapp = wApplicationOf(wwin->main_window);
470 if (wapp && !wapp->flags.emulated)
471 wwin->user_flags.emulate_appicon = 0;
474 if (wwin->transient_for!=None
475 && wwin->transient_for!=wwin->screen_ptr->root_win)
476 wwin->user_flags.emulate_appicon = 0;
478 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
479 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
480 wwin->user_flags.sunken = 0;
482 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
488 Bool
489 wWindowCanReceiveFocus(WWindow *wwin)
491 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
492 return False;
493 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
494 return False;
495 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
496 return False;
498 return True;
502 Bool
503 wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
505 int w1, h1, w2, h2;
507 w1 = wwin->frame->core->width;
508 h1 = wwin->frame->core->height;
509 w2 = obscured->frame->core->width;
510 h2 = obscured->frame->core->height;
512 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
513 && wwin->frame->workspace != obscured->frame->workspace)
514 return False;
516 if (wwin->frame_x + w1 < obscured->frame_x
517 || wwin->frame_y + h1 < obscured->frame_y
518 || wwin->frame_x > obscured->frame_x + w2
519 || wwin->frame_y > obscured->frame_y + h2) {
520 return False;
523 return True;
529 *----------------------------------------------------------------
530 * wManageWindow--
531 * reparents the window and allocates a descriptor for it.
532 * Window manager hints and other hints are fetched to configure
533 * the window decoration attributes and others. User preferences
534 * for the window are used if available, to configure window
535 * decorations and some behaviour.
536 * If in startup, windows that are override redirect,
537 * unmapped and never were managed and are Withdrawn are not
538 * managed.
540 * Returns:
541 * the new window descriptor
543 * Side effects:
544 * The window is reparented and appropriate notification
545 * is done to the client. Input mask for the window is setup.
546 * The window descriptor is also associated with various window
547 * contexts and inserted in the head of the window list.
548 * Event handler contexts are associated for some objects
549 * (buttons, titlebar and resizebar)
551 *----------------------------------------------------------------
553 WWindow*
554 wManageWindow(WScreen *scr, Window window)
556 WWindow *wwin;
557 int x, y;
558 unsigned width, height;
559 XWindowAttributes wattribs;
560 XSetWindowAttributes attribs;
561 WWindowState *win_state;
562 WWindow *transientOwner = NULL;
563 int window_level;
564 int wm_state;
565 int foo;
566 int workspace = -1;
567 char *title;
568 Bool withdraw = False;
569 Bool raise = False;
571 /* mutex. */
572 /* XGrabServer(dpy); */
573 XSync(dpy, False);
574 /* make sure the window is still there */
575 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
576 XUngrabServer(dpy);
577 return NULL;
580 /* if it's an override-redirect, ignore it */
581 if (wattribs.override_redirect) {
582 XUngrabServer(dpy);
583 return NULL;
586 wm_state = PropGetWindowState(window);
588 /* if it's startup and the window is unmapped, don't manage it */
589 if (scr->flags.startup && wm_state < 0 && wattribs.map_state==IsUnmapped) {
590 XUngrabServer(dpy);
591 return NULL;
594 if (!wFetchName(dpy, window, &title)) {
595 title = NULL;
598 #ifdef KWM_HINTS
599 if (title && !wKWMManageableClient(scr, window, title)) {
600 XFree(title);
601 XUngrabServer(dpy);
602 return NULL;
604 #endif /* KWM_HINTS */
607 wwin = wWindowCreate();
609 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
611 #ifdef DEBUG
612 printf("managing window %x\n", (unsigned)window);
613 #endif
615 #ifdef SHAPE
616 if (wShapeSupported) {
617 int junk;
618 unsigned int ujunk;
619 int b_shaped;
621 XShapeSelectInput(dpy, window, ShapeNotifyMask);
622 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
623 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
624 wwin->flags.shaped = b_shaped;
626 #endif
629 *--------------------------------------------------
631 * Get hints and other information in properties
633 *--------------------------------------------------
635 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
637 /* setup descriptor */
638 wwin->client_win = window;
639 wwin->screen_ptr = scr;
641 wwin->old_border_width = wattribs.border_width;
643 wwin->event_mask = CLIENT_EVENTS;
644 attribs.event_mask = CLIENT_EVENTS;
645 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
646 attribs.save_under = False;
647 XChangeWindowAttributes(dpy, window, CWEventMask|CWDontPropagate
648 |CWSaveUnder, &attribs);
649 XSetWindowBorderWidth(dpy, window, 0);
651 /* get hints from GNUstep app */
652 if (wwin->wm_class != 0 && strcmp(wwin->wm_class, "GNUstep") == 0) {
653 wwin->flags.is_gnustep = 1;
655 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
656 wwin->wm_gnustep_attr = NULL;
659 wwin->client_leader = PropGetClientLeader(window);
660 if (wwin->client_leader!=None)
661 wwin->main_window = wwin->client_leader;
663 wwin->wm_hints = XGetWMHints(dpy, window);
665 if (wwin->wm_hints) {
666 if (wwin->wm_hints->flags & StateHint) {
668 if (wwin->wm_hints->initial_state == IconicState) {
670 wwin->flags.miniaturized = 1;
672 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
674 withdraw = True;
678 if (wwin->wm_hints->flags & WindowGroupHint) {
679 wwin->group_id = wwin->wm_hints->window_group;
680 /* window_group has priority over CLIENT_LEADER */
681 wwin->main_window = wwin->group_id;
682 } else {
683 wwin->group_id = None;
686 if (wwin->wm_hints->flags & UrgencyHint)
687 wwin->flags.urgent = 1;
688 } else {
689 wwin->group_id = None;
692 PropGetProtocols(window, &wwin->protocols);
694 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
695 wwin->transient_for = None;
696 } else {
697 if (wwin->transient_for==None || wwin->transient_for==window) {
698 wwin->transient_for = scr->root_win;
699 } else {
700 transientOwner = wWindowFor(wwin->transient_for);
701 if (transientOwner && transientOwner->main_window!=None) {
702 wwin->main_window = transientOwner->main_window;
703 } /*else {
704 wwin->main_window = None;
709 /* guess the focus mode */
710 wwin->focus_mode = getFocusMode(wwin);
712 /* get geometry stuff */
713 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
715 /* get colormap windows */
716 GetColormapWindows(wwin);
719 *--------------------------------------------------
721 * Setup the decoration/window attributes and
722 * geometry
724 *--------------------------------------------------
727 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
729 #ifdef OLWM_HINTS
730 if (wwin->client_flags.olwm_transient && wwin->transient_for==None
731 && wwin->group_id != None && wwin->group_id != window) {
733 transientOwner = wWindowFor(wwin->group_id);
735 if (transientOwner) {
736 wwin->transient_for = wwin->group_id;
738 /* transients can't be iconified or maximized */
739 if (wwin->transient_for) {
740 WSETUFLAG(wwin, no_miniaturizable, 1);
741 WSETUFLAG(wwin, no_miniaturize_button, 1);
745 #endif /* OLWM_HINTS */
748 * Make broken apps behave as a nice app.
750 if (WFLAGP(wwin, emulate_appicon)) {
751 wwin->main_window = wwin->client_win;
755 *------------------------------------------------------------
757 * Setup the initial state of the window
759 *------------------------------------------------------------
762 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable)) {
763 wwin->flags.miniaturized = 1;
766 if (WFLAGP(wwin, start_maximized) && !WFLAGP(wwin, no_resizable)) {
767 wwin->flags.maximized = MAX_VERTICAL|MAX_HORIZONTAL;
771 Bool bla;
773 bla = False;
774 #ifdef GNOME_STUFF
775 bla = wGNOMECheckInitialClientState(wwin);
776 #endif
777 #ifdef KWM_HINTS
778 if (!bla)
779 wKWMCheckClientInitialState(wwin);
780 #endif
783 /* apply previous state if it exists and we're in startup */
784 if (scr->flags.startup && wm_state >= 0) {
786 if (wm_state == IconicState) {
788 wwin->flags.miniaturized = 1;
790 } else if (wm_state == WithdrawnState) {
792 withdraw = True;
796 /* if there is a saved state (from file), restore it */
797 win_state = NULL;
798 if (wwin->main_window!=None/* && wwin->main_window!=window*/) {
799 win_state = (WWindowState*)wWindowGetSavedState(wwin->main_window);
800 } else {
801 win_state = (WWindowState*)wWindowGetSavedState(window);
803 if (win_state && !withdraw) {
805 if (win_state->state->hidden>0)
806 wwin->flags.hidden = win_state->state->hidden;
808 if (win_state->state->shaded>0 && !WFLAGP(wwin, no_shadeable))
809 wwin->flags.shaded = win_state->state->shaded;
811 if (win_state->state->miniaturized>0 &&
812 !WFLAGP(wwin, no_miniaturizable)) {
813 wwin->flags.miniaturized = win_state->state->miniaturized;
816 if (!IS_OMNIPRESENT(wwin)) {
817 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
818 wwin->wm_class);
819 if (w < 0 || w >= scr->workspace_count) {
820 workspace = win_state->state->workspace;
821 if (workspace >= scr->workspace_count)
822 workspace = scr->current_workspace;
823 } else {
824 workspace = w;
826 } else {
827 workspace = scr->current_workspace;
831 /* if we're restarting, restore saved state (from hints).
832 * This will overwrite previous */
834 WSavedState *wstate;
836 if (getSavedState(window, &wstate)) {
837 wwin->flags.shaded = wstate->shaded;
838 wwin->flags.hidden = wstate->hidden;
839 wwin->flags.miniaturized = wstate->miniaturized;
840 wwin->flags.maximized = wstate->maximized;
841 if (wwin->flags.maximized) {
842 wwin->old_geometry.x = wstate->x;
843 wwin->old_geometry.y = wstate->y;
844 wwin->old_geometry.width = wstate->w;
845 wwin->old_geometry.height = wstate->h;
848 workspace = wstate->workspace;
849 } else {
850 wstate = NULL;
853 /* restore window shortcut */
854 if (wstate != NULL || win_state != NULL) {
855 unsigned mask = 0;
857 if (win_state != NULL)
858 mask = win_state->state->window_shortcuts;
860 if (wstate != NULL && mask == 0)
861 mask = wstate->window_shortcuts;
863 if (mask > 0) {
864 int i;
866 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
867 if (mask & (1<<i)) {
868 if (!scr->shortcutWindows[i])
869 scr->shortcutWindows[i] = WMCreateArray(4);
871 WMAddToArray(scr->shortcutWindows[i], wwin);
876 if (wstate != NULL) {
877 wfree(wstate);
881 /* don't let transients start miniaturized if their owners are not */
882 if (transientOwner && !transientOwner->flags.miniaturized
883 && wwin->flags.miniaturized && !withdraw) {
884 wwin->flags.miniaturized = 0;
885 if (wwin->wm_hints)
886 wwin->wm_hints->initial_state = NormalState;
889 /* set workspace on which the window starts */
890 if (workspace >= 0) {
891 if (workspace > scr->workspace_count-1) {
892 workspace = workspace % scr->workspace_count;
894 } else {
895 int w;
897 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
899 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
901 workspace = w;
903 } else {
904 if (wPreferences.open_transients_with_parent && transientOwner) {
906 workspace = transientOwner->frame->workspace;
908 } else {
910 workspace = scr->current_workspace;
915 /* setup window geometry */
916 if (win_state && win_state->state->w > 0) {
917 width = win_state->state->w;
918 height = win_state->state->h;
920 wWindowConstrainSize(wwin, &width, &height);
922 /* do not ask for window placement if the window is
923 * transient, during startup, if the initial workspace is another one
924 * or if the window wants to start iconic.
925 * If geometry was saved, restore it. */
927 Bool dontBring = False;
929 if (win_state && win_state->state->w > 0) {
930 x = win_state->state->x;
931 y = win_state->state->y;
932 } else if ((wwin->transient_for==None
933 || wPreferences.window_placement!=WPM_MANUAL)
934 && !scr->flags.startup
935 && workspace == scr->current_workspace
936 && !wwin->flags.miniaturized
937 && !wwin->flags.maximized
938 && !(wwin->normal_hints->flags & (USPosition|PPosition))) {
940 if (transientOwner && transientOwner->flags.mapped) {
941 int offs = WMAX(20, 2*transientOwner->frame->top_width);
943 x = transientOwner->frame_x +
944 abs((transientOwner->frame->core->width - width)/2) + offs;
945 y = transientOwner->frame_y +
946 abs((transientOwner->frame->core->height - height)/3) + offs;
948 if (x < 0)
949 x = 0;
950 else if (x + width > scr->scr_width)
951 x = scr->scr_width - width;
953 if (y < 0)
954 y = 0;
955 else if (y + height > scr->scr_height)
956 y = scr->scr_height - height;
957 } else {
958 PlaceWindow(wwin, &x, &y, width, height);
960 if (wPreferences.window_placement == WPM_MANUAL)
961 dontBring = True;
964 if (WFLAGP(wwin, dont_move_off) && dontBring)
965 wScreenBringInside(scr, &x, &y, width, height);
968 if (wwin->flags.urgent) {
969 if (!IS_OMNIPRESENT(wwin))
970 wwin->flags.omnipresent ^= 1;
974 *--------------------------------------------------
976 * Create frame, borders and do reparenting
978 *--------------------------------------------------
980 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
981 #ifdef XKB_BUTTON_HINT
982 if (wPreferences.modelock)
983 foo |= WFF_LANGUAGE_BUTTON;
984 #endif
985 if (!WFLAGP(wwin, no_titlebar))
986 foo |= WFF_TITLEBAR;
987 if (!WFLAGP(wwin, no_resizebar))
988 foo |= WFF_RESIZEBAR;
989 if (!WFLAGP(wwin, no_border))
990 foo |= WFF_BORDER;
992 wwin->frame = wFrameWindowCreate(scr, window_level,
993 x, y, width, height,
994 &wPreferences.window_title_clearance, foo,
995 scr->window_title_texture,
996 scr->resizebar_texture,
997 scr->window_title_pixel,
998 &scr->window_title_gc,
999 &scr->title_font);
1001 wwin->frame->flags.is_client_window_frame = 1;
1002 wwin->frame->flags.justification = wPreferences.title_justification;
1004 /* setup button images */
1005 wWindowUpdateButtonImages(wwin);
1007 /* hide unused buttons */
1008 foo = 0;
1009 if (WFLAGP(wwin, no_close_button))
1010 foo |= WFF_RIGHT_BUTTON;
1011 if (WFLAGP(wwin, no_miniaturize_button))
1012 foo |= WFF_LEFT_BUTTON;
1013 #ifdef XKB_BUTTON_HINT
1014 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1015 foo |= WFF_LANGUAGE_BUTTON;
1016 #endif
1017 if (foo!=0)
1018 wFrameWindowHideButton(wwin->frame, foo);
1020 wwin->frame->child = wwin;
1022 #ifdef OLWM_HINTS
1023 /* emulate olwm push pin. Make the button look as pushed-in for
1024 * the pinned-out state. When the button is clicked, it will
1025 * revert to the normal position, which means the pin is pinned-in.
1027 if (wwin->flags.olwm_push_pin_out)
1028 wFrameWindowUpdatePushButton(wwin->frame, True);
1029 #endif /* OLWM_HINTS */
1032 wwin->frame->workspace = workspace;
1034 wwin->frame->on_click_left = windowIconifyClick;
1035 #ifdef XKB_BUTTON_HINT
1036 if (wPreferences.modelock)
1037 wwin->frame->on_click_language = windowLanguageClick;
1038 #endif
1040 wwin->frame->on_click_right = windowCloseClick;
1041 wwin->frame->on_dblclick_right = windowCloseDblClick;
1043 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1044 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1046 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1049 XSelectInput(dpy, wwin->client_win,
1050 wwin->event_mask & ~StructureNotifyMask);
1052 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1053 0, wwin->frame->top_width);
1055 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1059 int gx, gy;
1061 wClientGetGravityOffsets(wwin, &gx, &gy);
1063 /* if gravity is to the south, account for the border sizes */
1064 if (gy > 0)
1065 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1069 * wWindowConfigure() will init the client window's size
1070 * (wwin->client.{width,height}) and all other geometry
1071 * related variables (frame_x,frame_y)
1073 wWindowConfigure(wwin, x, y, width, height);
1075 /* to make sure the window receives it's new position after reparenting */
1076 wWindowSynthConfigureNotify(wwin);
1079 *--------------------------------------------------
1081 * Setup descriptors and save window to internal
1082 * lists
1084 *--------------------------------------------------
1087 if (wwin->main_window!=None) {
1088 WApplication *app;
1089 WWindow *leader;
1091 /* Leader windows do not necessary set themselves as leaders.
1092 * If this is the case, point the leader of this window to
1093 * itself */
1094 leader = wWindowFor(wwin->main_window);
1095 if (leader && leader->main_window==None) {
1096 leader->main_window = leader->client_win;
1098 app = wApplicationCreate(scr, wwin->main_window);
1099 if (app) {
1100 app->last_workspace = workspace;
1103 * Do application specific stuff, like setting application
1104 * wide attributes.
1107 if (wwin->flags.hidden) {
1108 /* if the window was set to hidden because it was hidden
1109 * in a previous incarnation and that state was restored */
1110 app->flags.hidden = 1;
1113 if (app->flags.hidden) {
1114 /*wwin->flags.hidden = 1;*/
1115 wUnhideApplication(app, False, False);
1116 raise = True;
1121 /* setup the frame descriptor */
1122 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1123 wwin->frame->core->descriptor.parent = wwin;
1124 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1126 /* don't let windows go away if we die */
1127 XAddToSaveSet(dpy, window);
1129 XLowerWindow(dpy, window);
1131 /* if window is in this workspace and should be mapped, then map it */
1132 if (!wwin->flags.miniaturized
1133 && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1134 && !wwin->flags.hidden && !withdraw) {
1136 /* The following "if" is to avoid crashing of clients that expect
1137 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1138 * after the return from this function.
1140 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1141 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1142 } else {
1143 wClientSetState(wwin, NormalState, None);
1146 #if 0
1147 /* if not auto focus, then map the window under the currently
1148 * focused window */
1149 #define _WIDTH(w) (w)->frame->core->width
1150 #define _HEIGHT(w) (w)->frame->core->height
1151 if (!wPreferences.auto_focus && scr->focused_window
1152 && !scr->flags.startup && !transientOwner
1153 && ((wWindowObscuresWindow(wwin, scr->focused_window)
1154 && (_WIDTH(wwin) > (_WIDTH(scr->focused_window)*5)/3
1155 || _HEIGHT(wwin) > (_HEIGHT(scr->focused_window)*5)/3)
1156 && WINDOW_LEVEL(scr->focused_window) == WINDOW_LEVEL(wwin))
1157 || wwin->flags.maximized)) {
1158 MoveInStackListUnder(scr->focused_window->frame->core,
1159 wwin->frame->core);
1161 #undef _WIDTH
1162 #undef _HEIGHT
1164 #endif
1166 if (wPreferences.superfluous && !wPreferences.no_animations
1167 && !scr->flags.startup && wwin->transient_for==None
1169 * The brain damaged idiotic non-click to focus modes will
1170 * have trouble with this because:
1172 * 1. window is created and mapped by the client
1173 * 2. window is mapped by wmaker in small size
1174 * 3. window is animated to grow to normal size
1175 * 4. this function returns to normal event loop
1176 * 5. eventually, the EnterNotify event that would trigger
1177 * the window focusing (if the mouse is over that window)
1178 * will be processed by wmaker.
1179 * But since this event will be rather delayed
1180 * (step 3 has a large delay) the time when the event ocurred
1181 * and when it is processed, the client that owns that window
1182 * will reject the XSetInputFocus() for it.
1184 && (wPreferences.focus_mode==WKF_CLICK
1185 || wPreferences.auto_focus)) {
1186 DoWindowBirth(wwin);
1189 wWindowMap(wwin);
1192 /* setup stacking descriptor */
1193 if (transientOwner) {
1194 /* && wPreferences.on_top_transients */
1195 if (transientOwner) {
1196 wwin->frame->core->stacking->child_of =
1197 transientOwner->frame->core;
1199 } else {
1200 wwin->frame->core->stacking->child_of = NULL;
1204 if (!scr->focused_window) {
1205 /* first window on the list */
1206 wwin->next = NULL;
1207 wwin->prev = NULL;
1208 scr->focused_window = wwin;
1209 } else {
1210 WWindow *tmp;
1212 /* add window at beginning of focus window list */
1213 tmp = scr->focused_window;
1214 while (tmp->prev)
1215 tmp = tmp->prev;
1216 tmp->prev = wwin;
1217 wwin->next = tmp;
1218 wwin->prev = NULL;
1221 /* raise is set to true if we un-hid the app when this window was born.
1222 * we raise, else old windows of this app will be above this new one. */
1223 if (raise) {
1224 wRaiseFrame(wwin->frame->core);
1227 /* Update name must come after WApplication stuff is done */
1228 wWindowUpdateName(wwin, title);
1229 if (title)
1230 XFree(title);
1232 XUngrabServer(dpy);
1235 *--------------------------------------------------
1237 * Final preparations before window is ready to go
1239 *--------------------------------------------------
1242 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1245 if (!wwin->flags.miniaturized && workspace == scr->current_workspace
1246 && !wwin->flags.hidden) {
1247 if (((transientOwner && transientOwner->flags.focused)
1248 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable))
1249 wSetFocusTo(scr, wwin);
1251 wWindowResetMouseGrabs(wwin);
1253 if (!WFLAGP(wwin, no_bind_keys)) {
1254 wWindowSetKeyGrabs(wwin);
1258 WMPostNotificationName(WMNManaged, wwin, NULL);
1261 wColormapInstallForWindow(scr, scr->cmap_window);
1264 #ifdef OLWM_HINTS
1265 if (wwin->client_flags.olwm_warp_to_pin && wwin->frame->titlebar != NULL
1266 && !WFLAGP(wwin, no_close_button) && !withdraw) {
1268 XWarpPointer(dpy, None, None, 0, 0, 0, 0,
1269 wwin->frame_x + width - wwin->frame->titlebar->height * 2,
1270 wwin->frame_y);
1272 #endif
1275 *------------------------------------------------------------
1276 * Setup Notification Observers
1277 *------------------------------------------------------------
1279 WMAddNotificationObserver(appearanceObserver, wwin,
1280 WNWindowAppearanceSettingsChanged, wwin);
1284 *--------------------------------------------------
1286 * Cleanup temporary stuff
1288 *--------------------------------------------------
1291 if (win_state)
1292 wWindowDeleteSavedState(win_state);
1294 /* If the window must be withdrawed, then do it now.
1295 * Must do some optimization, 'though */
1296 if (withdraw) {
1297 wwin->flags.mapped = 0;
1298 wClientSetState(wwin, WithdrawnState, None);
1299 wUnmanageWindow(wwin, True, False);
1300 wwin = NULL;
1303 return wwin;
1310 WWindow*
1311 wManageInternalWindow(WScreen *scr, Window window, Window owner,
1312 char *title, int x, int y, int width, int height)
1314 WWindow *wwin;
1315 int foo;
1317 wwin = wWindowCreate();
1319 WMAddNotificationObserver(appearanceObserver, wwin,
1320 WNWindowAppearanceSettingsChanged, wwin);
1322 wwin->flags.internal_window = 1;
1324 WSETUFLAG(wwin, omnipresent, 1);
1325 WSETUFLAG(wwin, no_shadeable, 1);
1326 WSETUFLAG(wwin, no_resizable, 1);
1327 WSETUFLAG(wwin, no_miniaturizable, 1);
1329 wwin->focus_mode = WFM_PASSIVE;
1331 wwin->client_win = window;
1332 wwin->screen_ptr = scr;
1334 wwin->transient_for = owner;
1336 wwin->client.x = x;
1337 wwin->client.y = y;
1338 wwin->client.width = width;
1339 wwin->client.height = height;
1341 wwin->frame_x = wwin->client.x;
1342 wwin->frame_y = wwin->client.y;
1345 foo = WFF_RIGHT_BUTTON|WFF_BORDER;
1346 foo |= WFF_TITLEBAR;
1347 #ifdef XKB_BUTTON_HINT
1348 foo |= WFF_LANGUAGE_BUTTON;
1349 #endif
1351 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1352 wwin->frame_x, wwin->frame_y,
1353 width, height,
1354 &wPreferences.window_title_clearance, foo,
1355 scr->window_title_texture,
1356 scr->resizebar_texture,
1357 scr->window_title_pixel,
1358 &scr->window_title_gc,
1359 &scr->title_font);
1361 XSaveContext(dpy, window, wWinContext, (XPointer)&wwin->client_descriptor);
1363 wwin->frame->flags.is_client_window_frame = 1;
1364 wwin->frame->flags.justification = wPreferences.title_justification;
1366 wFrameWindowChangeTitle(wwin->frame, title);
1368 /* setup button images */
1369 wWindowUpdateButtonImages(wwin);
1371 /* hide buttons */
1372 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1374 wwin->frame->child = wwin;
1376 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1378 #ifdef XKB_BUTTON_HINT
1379 if (wPreferences.modelock)
1380 wwin->frame->on_click_language = windowLanguageClick;
1381 #endif
1383 wwin->frame->on_click_right = windowCloseClick;
1385 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1386 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1388 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1390 wwin->client.y += wwin->frame->top_width;
1391 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window,
1392 0, wwin->frame->top_width);
1394 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y,
1395 wwin->client.width, wwin->client.height);
1397 /* setup the frame descriptor */
1398 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1399 wwin->frame->core->descriptor.parent = wwin;
1400 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1403 XLowerWindow(dpy, window);
1404 XMapSubwindows(dpy, wwin->frame->core->window);
1406 /* setup stacking descriptor */
1407 if (
1408 #ifdef removed
1409 wPreferences.on_top_transients &&
1410 #endif
1411 wwin->transient_for!=None
1412 && wwin->transient_for!=scr->root_win) {
1413 WWindow *tmp;
1414 tmp = wWindowFor(wwin->transient_for);
1415 if (tmp)
1416 wwin->frame->core->stacking->child_of = tmp->frame->core;
1417 } else {
1418 wwin->frame->core->stacking->child_of = NULL;
1422 if (!scr->focused_window) {
1423 /* first window on the list */
1424 wwin->next = NULL;
1425 wwin->prev = NULL;
1426 scr->focused_window = wwin;
1427 } else {
1428 WWindow *tmp;
1430 /* add window at beginning of focus window list */
1431 tmp = scr->focused_window;
1432 while (tmp->prev)
1433 tmp = tmp->prev;
1434 tmp->prev = wwin;
1435 wwin->next = tmp;
1436 wwin->prev = NULL;
1439 if (wwin->flags.is_gnustep == 0)
1440 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1442 /* if (wPreferences.auto_focus)*/
1443 wSetFocusTo(scr, wwin);
1445 wWindowResetMouseGrabs(wwin);
1447 wWindowSetKeyGrabs(wwin);
1449 return wwin;
1454 *----------------------------------------------------------------------
1455 * wUnmanageWindow--
1456 * Removes the frame window from a window and destroys all data
1457 * related to it. The window will be reparented back to the root window
1458 * if restore is True.
1460 * Side effects:
1461 * Everything related to the window is destroyed and the window
1462 * is removed from the window lists. Focus is set to the previous on the
1463 * window list.
1464 *----------------------------------------------------------------------
1466 void
1467 wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
1469 WCoreWindow *frame = wwin->frame->core;
1470 WWindow *owner = NULL;
1471 WWindow *newFocusedWindow = NULL;
1472 int wasFocused;
1473 WScreen *scr = wwin->screen_ptr;
1476 /* First close attribute editor window if open */
1477 if (wwin->flags.inspector_open) {
1478 wCloseInspectorForWindow(wwin);
1481 /* Close window menu if it's open for this window */
1482 if (wwin->flags.menu_open_for_me) {
1483 CloseWindowMenu(scr);
1486 if (!destroyed) {
1487 if (!wwin->flags.internal_window)
1488 XRemoveFromSaveSet(dpy, wwin->client_win);
1490 XSelectInput(dpy, wwin->client_win, NoEventMask);
1492 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1493 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1496 XUnmapWindow(dpy, frame->window);
1498 XUnmapWindow(dpy, wwin->client_win);
1500 /* deselect window */
1501 wSelectWindow(wwin, False);
1503 /* remove all pending events on window */
1504 /* I think this only matters for autoraise */
1505 if (wPreferences.raise_delay)
1506 WMDeleteTimerWithClientData(wwin->frame->core);
1508 XFlush(dpy);
1510 /* reparent the window back to the root */
1511 if (restore)
1512 wClientRestore(wwin);
1514 if (wwin->transient_for!=scr->root_win) {
1515 owner = wWindowFor(wwin->transient_for);
1516 if (owner) {
1517 if (!owner->flags.semi_focused) {
1518 owner = NULL;
1519 } else {
1520 owner->flags.semi_focused = 0;
1525 wasFocused = wwin->flags.focused;
1527 /* remove from window focus list */
1528 if (!wwin->prev && !wwin->next) {
1529 /* was the only window */
1530 scr->focused_window = NULL;
1531 newFocusedWindow = NULL;
1532 } else {
1533 WWindow *tmp;
1535 if (wwin->prev)
1536 wwin->prev->next = wwin->next;
1537 if (wwin->next)
1538 wwin->next->prev = wwin->prev;
1539 else {
1540 scr->focused_window = wwin->prev;
1541 scr->focused_window->next = NULL;
1544 if (wPreferences.focus_mode==WKF_CLICK) {
1546 /* if in click to focus mode and the window
1547 * was a transient, focus the owner window
1549 tmp = NULL;
1550 if (wPreferences.focus_mode==WKF_CLICK) {
1551 tmp = wWindowFor(wwin->transient_for);
1552 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1553 tmp = NULL;
1556 /* otherwise, focus the next one in the focus list */
1557 if (!tmp) {
1558 tmp = scr->focused_window;
1559 while (tmp) { /* look for one in the window list first */
1560 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1561 && (tmp->flags.mapped || tmp->flags.shaded))
1562 break;
1563 tmp = tmp->prev;
1565 if (!tmp) { /* if unsuccessful, choose any focusable window */
1566 tmp = scr->focused_window;
1567 while (tmp) {
1568 if (!WFLAGP(tmp, no_focusable)
1569 && (tmp->flags.mapped || tmp->flags.shaded))
1570 break;
1571 tmp = tmp->prev;
1576 newFocusedWindow = tmp;
1578 } else if (wPreferences.focus_mode==WKF_SLOPPY) {
1579 unsigned int mask;
1580 int foo;
1581 Window bar, win;
1583 /* This is to let the root window get the keyboard input
1584 * if Sloppy focus mode and no other window get focus.
1585 * This way keybindings will not freeze.
1587 tmp = NULL;
1588 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
1589 &foo, &foo, &foo, &foo, &mask))
1590 tmp = wWindowFor(win);
1591 if (tmp == wwin)
1592 tmp = NULL;
1593 newFocusedWindow = tmp;
1594 } else {
1595 newFocusedWindow = NULL;
1599 if (!wwin->flags.internal_window) {
1600 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1603 #ifdef DEBUG
1604 printf("destroying window %x frame %x\n", (unsigned)wwin->client_win,
1605 (unsigned)frame->window);
1606 #endif
1608 if (wasFocused) {
1609 if (newFocusedWindow != owner && owner) {
1610 if (wwin->flags.is_gnustep == 0)
1611 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1613 wSetFocusTo(scr, newFocusedWindow);
1615 wWindowDestroy(wwin);
1616 XFlush(dpy);
1620 void
1621 wWindowMap(WWindow *wwin)
1623 XMapWindow(dpy, wwin->frame->core->window);
1624 if (!wwin->flags.shaded) {
1625 /* window will be remapped when getting MapNotify */
1626 XSelectInput(dpy, wwin->client_win,
1627 wwin->event_mask & ~StructureNotifyMask);
1628 XMapWindow(dpy, wwin->client_win);
1629 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1631 wwin->flags.mapped = 1;
1636 void
1637 wWindowUnmap(WWindow *wwin)
1639 wwin->flags.mapped = 0;
1641 /* prevent window withdrawal when getting UnmapNotify */
1642 XSelectInput(dpy, wwin->client_win,
1643 wwin->event_mask & ~StructureNotifyMask);
1644 XUnmapWindow(dpy, wwin->client_win);
1645 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1647 XUnmapWindow(dpy, wwin->frame->core->window);
1652 void
1653 wWindowFocus(WWindow *wwin, WWindow *owin)
1655 WWindow *nowner;
1656 WWindow *oowner;
1658 #ifdef KEEP_XKB_LOCK_STATUS
1659 if (wPreferences.modelock) {
1660 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1662 #endif /* KEEP_XKB_LOCK_STATUS */
1664 wwin->flags.semi_focused = 0;
1666 if (wwin->flags.is_gnustep == 0)
1667 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1669 wwin->flags.focused = 1;
1671 wWindowResetMouseGrabs(wwin);
1673 WMPostNotificationName(WMNChangedFocus, wwin, (void*)True);
1675 if (owin == wwin || !owin)
1676 return;
1678 nowner = wWindowFor(wwin->transient_for);
1680 /* new window is a transient for the old window */
1681 if (nowner == owin) {
1682 owin->flags.semi_focused = 1;
1683 wWindowUnfocus(nowner);
1684 return;
1687 oowner = wWindowFor(owin->transient_for);
1689 /* new window is owner of old window */
1690 if (wwin == oowner) {
1691 wWindowUnfocus(owin);
1692 return;
1695 if (!nowner) {
1696 wWindowUnfocus(owin);
1697 return;
1700 /* new window has same owner of old window */
1701 if (oowner == nowner) {
1702 /* prevent unfocusing of owner */
1703 oowner->flags.semi_focused = 0;
1704 wWindowUnfocus(owin);
1705 oowner->flags.semi_focused = 1;
1707 return;
1710 /* nowner != NULL && oowner != nowner */
1711 nowner->flags.semi_focused = 1;
1712 wWindowUnfocus(nowner);
1713 wWindowUnfocus(owin);
1717 void
1718 wWindowUnfocus(WWindow *wwin)
1720 CloseWindowMenu(wwin->screen_ptr);
1722 if (wwin->flags.is_gnustep == 0)
1723 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused
1724 ? WS_PFOCUSED : WS_UNFOCUSED);
1726 if (wwin->transient_for!=None
1727 && wwin->transient_for!=wwin->screen_ptr->root_win) {
1728 WWindow *owner;
1729 owner = wWindowFor(wwin->transient_for);
1730 if (owner && owner->flags.semi_focused) {
1731 owner->flags.semi_focused = 0;
1732 if (owner->flags.mapped || owner->flags.shaded) {
1733 wWindowUnfocus(owner);
1734 wFrameWindowPaint(owner->frame);
1738 wwin->flags.focused = 0;
1740 wWindowResetMouseGrabs(wwin);
1742 WMPostNotificationName(WMNChangedFocus, wwin, (void*)False);
1746 void
1747 wWindowUpdateName(WWindow *wwin, char *newTitle)
1749 WApplication *app = wApplicationOf(wwin->main_window);
1750 int instIndex = 0;
1751 char prefix[32] = "";
1752 char *title;
1754 if (!wwin->frame)
1755 return;
1757 if (app)
1758 instIndex = wApplicationIndexOfGroup(app);
1761 wwin->flags.wm_name_changed = 1;
1763 if (!newTitle) {
1764 /* the hint was removed */
1765 title = DEF_WINDOW_TITLE;
1767 WMPostNotificationName(WMNChangedName, wwin, NULL);
1768 } else {
1769 title = newTitle;
1772 #ifndef NO_WINDOW_ENUMERATOR
1773 if (instIndex > 0) {
1774 snprintf(prefix, sizeof(prefix), " [%i]", instIndex);
1776 title = wstrconcat(title, prefix);
1778 #endif
1780 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1782 WMPostNotificationName(WMNChangedName, wwin, NULL);
1785 #ifndef NO_WINDOW_ENUMERATOR
1786 if (instIndex > 0)
1787 wfree(title);
1788 #endif
1795 *----------------------------------------------------------------------
1797 * wWindowConstrainSize--
1798 * Constrains size for the client window, taking the maximal size,
1799 * window resize increments and other size hints into account.
1801 * Returns:
1802 * The closest size to what was given that the client window can
1803 * have.
1805 *----------------------------------------------------------------------
1807 void
1808 wWindowConstrainSize(WWindow *wwin, int *nwidth, int *nheight)
1810 int width = *nwidth;
1811 int height = *nheight;
1812 int winc = 1;
1813 int hinc = 1;
1814 int minW = 1, minH = 1;
1815 int maxW = wwin->screen_ptr->scr_width*2;
1816 int maxH = wwin->screen_ptr->scr_height*2;
1817 int minAX = -1, minAY = -1;
1818 int maxAX = -1, maxAY = -1;
1819 int baseW = 0;
1820 int baseH = 0;
1822 if (wwin->normal_hints) {
1823 winc = wwin->normal_hints->width_inc;
1824 hinc = wwin->normal_hints->height_inc;
1825 minW = wwin->normal_hints->min_width;
1826 minH = wwin->normal_hints->min_height;
1827 maxW = wwin->normal_hints->max_width;
1828 maxH = wwin->normal_hints->max_height;
1829 if (wwin->normal_hints->flags & PAspect) {
1830 minAX = wwin->normal_hints->min_aspect.x;
1831 minAY = wwin->normal_hints->min_aspect.y;
1832 maxAX = wwin->normal_hints->max_aspect.x;
1833 maxAY = wwin->normal_hints->max_aspect.y;
1836 baseW = wwin->normal_hints->base_width;
1837 baseH = wwin->normal_hints->base_height;
1840 if (width < minW)
1841 width = minW;
1842 if (height < minH)
1843 height = minH;
1845 if (width > maxW)
1846 width = maxW;
1847 if (height > maxH)
1848 height = maxH;
1850 /* aspect ratio code borrowed from olwm */
1851 if (minAX > 0) {
1852 /* adjust max aspect ratio */
1853 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1854 if (maxAX > maxAY) {
1855 height = (width * maxAY) / maxAX;
1856 if (height > maxH) {
1857 height = maxH;
1858 width = (height * maxAX) / maxAY;
1860 } else {
1861 width = (height * maxAX) / maxAY;
1862 if (width > maxW) {
1863 width = maxW;
1864 height = (width * maxAY) / maxAX;
1869 /* adjust min aspect ratio */
1870 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1871 if (minAX > minAY) {
1872 height = (width * minAY) / minAX;
1873 if (height < minH) {
1874 height = minH;
1875 width = (height * minAX) / minAY;
1877 } else {
1878 width = (height * minAX) / minAY;
1879 if (width < minW) {
1880 width = minW;
1881 height = (width * minAY) / minAX;
1887 if (baseW != 0) {
1888 width = (((width - baseW) / winc) * winc) + baseW;
1889 } else {
1890 width = (((width - minW) / winc) * winc) + minW;
1893 if (baseH != 0) {
1894 height = (((height - baseH) / hinc) * hinc) + baseH;
1895 } else {
1896 height = (((height - minH) / hinc) * hinc) + minH;
1899 /* broken stupid apps may cause preposterous values for these.. */
1900 if (width > 0)
1901 *nwidth = width;
1902 if (height > 0)
1903 *nheight = height;
1907 void
1908 wWindowCropSize(WWindow *wwin, int maxW, int maxH,
1909 int *width, int *height)
1911 int baseW = 0, baseH = 0;
1912 int winc = 1, hinc = 1;
1914 if (wwin->normal_hints) {
1915 baseW = wwin->normal_hints->base_width;
1916 baseH = wwin->normal_hints->base_height;
1918 winc = wwin->normal_hints->width_inc;
1919 hinc = wwin->normal_hints->height_inc;
1922 if (*width > maxW)
1923 *width = maxW - (maxW - baseW) % winc;
1925 if (*height > maxH)
1926 *height = maxH - (maxH - baseH) % hinc;
1930 void
1931 wWindowChangeWorkspace(WWindow *wwin, int workspace)
1933 WScreen *scr = wwin->screen_ptr;
1934 WApplication *wapp;
1935 int unmap = 0;
1937 if (workspace >= scr->workspace_count || workspace < 0
1938 || workspace == wwin->frame->workspace)
1939 return;
1941 if (workspace != scr->current_workspace) {
1942 /* Sent to other workspace. Unmap window */
1943 if ((wwin->flags.mapped
1944 || wwin->flags.shaded
1945 || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1946 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1948 wapp = wApplicationOf(wwin->main_window);
1949 if (wapp) {
1950 wapp->last_workspace = workspace;
1952 if (wwin->flags.miniaturized) {
1953 if (wwin->icon) {
1954 XUnmapWindow(dpy, wwin->icon->core->window);
1955 wwin->icon->mapped = 0;
1957 } else {
1958 unmap = 1;
1959 wSetFocusTo(scr, NULL);
1962 } else {
1963 /* brought to current workspace. Map window */
1964 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1965 if (wwin->icon) {
1966 XMapWindow(dpy, wwin->icon->core->window);
1967 wwin->icon->mapped = 1;
1969 } else if (!wwin->flags.mapped &&
1970 !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1971 wWindowMap(wwin);
1974 if (!IS_OMNIPRESENT(wwin)) {
1975 int oldWorkspace = wwin->frame->workspace;
1977 wwin->frame->workspace = workspace;
1979 WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
1982 if (unmap) {
1983 wWindowUnmap(wwin);
1988 void
1989 wWindowSynthConfigureNotify(WWindow *wwin)
1991 XEvent sevent;
1993 sevent.type = ConfigureNotify;
1994 sevent.xconfigure.display = dpy;
1995 sevent.xconfigure.event = wwin->client_win;
1996 sevent.xconfigure.window = wwin->client_win;
1998 sevent.xconfigure.x = wwin->client.x;
1999 sevent.xconfigure.y = wwin->client.y;
2000 sevent.xconfigure.width = wwin->client.width;
2001 sevent.xconfigure.height = wwin->client.height;
2003 sevent.xconfigure.border_width = wwin->old_border_width;
2004 if (WFLAGP(wwin, no_titlebar))
2005 sevent.xconfigure.above = None;
2006 else
2007 sevent.xconfigure.above = wwin->frame->titlebar->window;
2009 sevent.xconfigure.override_redirect = False;
2010 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
2011 #ifdef KWM_HINTS
2012 wKWMSendEventMessage(wwin, WKWMChangedClient);
2013 #endif
2014 XFlush(dpy);
2019 *----------------------------------------------------------------------
2020 * wWindowConfigure--
2021 * Configures the frame, decorations and client window to the
2022 * specified geometry. The geometry is not checked for validity,
2023 * wWindowConstrainSize() must be used for that.
2024 * The size parameters are for the client window, but the position is
2025 * for the frame.
2026 * The client window receives a ConfigureNotify event, according
2027 * to what ICCCM says.
2029 * Returns:
2030 * None
2032 * Side effects:
2033 * Window size and position are changed and client window receives
2034 * a ConfigureNotify event.
2035 *----------------------------------------------------------------------
2037 void
2038 wWindowConfigure(wwin, req_x, req_y, req_width, req_height)
2039 WWindow *wwin;
2040 int req_x, req_y; /* new position of the frame */
2041 int req_width, req_height; /* new size of the client */
2043 int synth_notify = False;
2044 int resize;
2046 resize = (req_width!=wwin->client.width
2047 || req_height!=wwin->client.height);
2049 * if the window is being moved but not resized then
2050 * send a synthetic ConfigureNotify
2052 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y) && !resize) {
2053 synth_notify = True;
2056 if (WFLAGP(wwin, dont_move_off))
2057 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2058 req_width, req_height);
2059 if (resize) {
2060 if (req_width < MIN_WINDOW_SIZE)
2061 req_width = MIN_WINDOW_SIZE;
2062 if (req_height < MIN_WINDOW_SIZE)
2063 req_height = MIN_WINDOW_SIZE;
2065 /* If growing, resize inner part before frame,
2066 * if shrinking, resize frame before.
2067 * This will prevent the frame (that can have a different color)
2068 * to be exposed, causing flicker */
2069 if (req_height > wwin->frame->core->height
2070 || req_width > wwin->frame->core->width)
2071 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2073 if (wwin->flags.shaded) {
2074 wFrameWindowConfigure(wwin->frame, req_x, req_y,
2075 req_width, wwin->frame->core->height);
2076 wwin->old_geometry.height = req_height;
2077 } else {
2078 int h;
2080 h = req_height + wwin->frame->top_width
2081 + wwin->frame->bottom_width;
2083 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2086 if (!(req_height > wwin->frame->core->height
2087 || req_width > wwin->frame->core->width))
2088 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2090 wwin->client.x = req_x;
2091 wwin->client.y = req_y + wwin->frame->top_width;
2092 wwin->client.width = req_width;
2093 wwin->client.height = req_height;
2094 } else {
2095 wwin->client.x = req_x;
2096 wwin->client.y = req_y + wwin->frame->top_width;
2098 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2100 wwin->frame_x = req_x;
2101 wwin->frame_y = req_y;
2102 if (!WFLAGP(wwin, no_border)) {
2103 wwin->client.x += FRAME_BORDER_WIDTH;
2104 wwin->client.y += FRAME_BORDER_WIDTH;
2107 #ifdef SHAPE
2108 if (wShapeSupported && wwin->flags.shaped && resize) {
2109 wWindowSetShape(wwin);
2111 #endif
2113 if (synth_notify)
2114 wWindowSynthConfigureNotify(wwin);
2115 XFlush(dpy);
2119 void
2120 wWindowMove(wwin, req_x, req_y)
2121 WWindow *wwin;
2122 int req_x, req_y; /* new position of the frame */
2124 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2125 int synth_notify = False;
2127 /* Send a synthetic ConfigureNotify event for every window movement. */
2128 if ((req_x!=wwin->frame_x || req_y!=wwin->frame_y)) {
2129 synth_notify = True;
2131 #else
2132 /* A single synthetic ConfigureNotify event is sent at the end of
2133 * a completed (opaque) movement in moveres.c */
2134 #endif
2136 if (WFLAGP(wwin, dont_move_off))
2137 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2138 wwin->frame->core->width, wwin->frame->core->height);
2140 wwin->client.x = req_x;
2141 wwin->client.y = req_y + wwin->frame->top_width;
2142 if (!WFLAGP(wwin, no_border)) {
2143 wwin->client.x += FRAME_BORDER_WIDTH;
2144 wwin->client.y += FRAME_BORDER_WIDTH;
2147 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2149 wwin->frame_x = req_x;
2150 wwin->frame_y = req_y;
2152 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2153 if (synth_notify)
2154 wWindowSynthConfigureNotify(wwin);
2155 #endif
2159 void
2160 wWindowUpdateButtonImages(WWindow *wwin)
2162 WScreen *scr = wwin->screen_ptr;
2163 Pixmap pixmap, mask;
2164 WFrameWindow *fwin = wwin->frame;
2166 if (WFLAGP(wwin, no_titlebar))
2167 return;
2169 /* miniaturize button */
2171 if (!WFLAGP(wwin, no_miniaturize_button)) {
2172 if (wwin->wm_gnustep_attr
2173 && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2174 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2176 if (wwin->wm_gnustep_attr->flags&GSMiniaturizeMaskAttr) {
2177 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2178 } else {
2179 mask = None;
2182 if (fwin->lbutton_image
2183 && (fwin->lbutton_image->image != pixmap
2184 || fwin->lbutton_image->mask != mask)) {
2185 wPixmapDestroy(fwin->lbutton_image);
2186 fwin->lbutton_image = NULL;
2189 if (!fwin->lbutton_image) {
2190 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2191 fwin->lbutton_image->client_owned = 1;
2192 fwin->lbutton_image->client_owned_mask = 1;
2194 } else {
2195 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2196 wPixmapDestroy(fwin->lbutton_image);
2198 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2202 #ifdef XKB_BUTTON_HINT
2203 if (!WFLAGP(wwin, no_language_button)) {
2204 if (fwin->languagebutton_image &&
2205 !fwin->languagebutton_image->shared) {
2206 wPixmapDestroy(fwin->languagebutton_image);
2208 fwin->languagebutton_image =
2209 scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2211 #endif
2213 /* close button */
2215 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2216 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2218 if (!WFLAGP(wwin, no_close_button)) {
2219 if (wwin->wm_gnustep_attr
2220 && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2221 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2223 if (wwin->wm_gnustep_attr->flags&GSCloseMaskAttr)
2224 mask = wwin->wm_gnustep_attr->close_mask;
2225 else
2226 mask = None;
2228 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2229 || fwin->rbutton_image->mask != mask)) {
2230 wPixmapDestroy(fwin->rbutton_image);
2231 fwin->rbutton_image = NULL;
2234 if (!fwin->rbutton_image) {
2235 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2236 fwin->rbutton_image->client_owned = 1;
2237 fwin->rbutton_image->client_owned_mask = 1;
2240 } else if (WFLAGP(wwin, kill_close)) {
2242 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2243 wPixmapDestroy(fwin->rbutton_image);
2245 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2247 } else if (MGFLAGP(wwin, broken_close)) {
2249 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2250 wPixmapDestroy(fwin->rbutton_image);
2252 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2254 } else {
2256 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2257 wPixmapDestroy(fwin->rbutton_image);
2259 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2263 /* force buttons to be redrawn */
2264 fwin->flags.need_texture_change = 1;
2265 wFrameWindowPaint(fwin);
2270 *---------------------------------------------------------------------------
2271 * wWindowConfigureBorders--
2272 * Update window border configuration according to attribute flags.
2274 *---------------------------------------------------------------------------
2276 void
2277 wWindowConfigureBorders(WWindow *wwin)
2279 if (wwin->frame) {
2280 int flags;
2281 int newy, oldh;
2283 flags = WFF_LEFT_BUTTON|WFF_RIGHT_BUTTON;
2284 #ifdef XKB_BUTTON_HINT
2285 flags |= WFF_LANGUAGE_BUTTON;
2286 #endif
2287 if (!WFLAGP(wwin, no_titlebar))
2288 flags |= WFF_TITLEBAR;
2289 if (!WFLAGP(wwin, no_resizebar))
2290 flags |= WFF_RESIZEBAR;
2291 if (!WFLAGP(wwin, no_border))
2292 flags |= WFF_BORDER;
2293 if (wwin->flags.shaded)
2294 flags |= WFF_IS_SHADED;
2296 oldh = wwin->frame->top_width;
2297 wFrameWindowUpdateBorders(wwin->frame, flags);
2298 if (oldh != wwin->frame->top_width) {
2299 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2301 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2302 wWindowConfigure(wwin, wwin->frame_x, newy,
2303 wwin->client.width, wwin->client.height);
2306 flags = 0;
2307 if (!WFLAGP(wwin, no_miniaturize_button)
2308 && wwin->frame->flags.hide_left_button)
2309 flags |= WFF_LEFT_BUTTON;
2311 #ifdef XKB_BUTTON_HINT
2312 if (!WFLAGP(wwin, no_language_button)
2313 && wwin->frame->flags.hide_language_button)
2314 flags |= WFF_LANGUAGE_BUTTON;
2315 #endif
2317 if (!WFLAGP(wwin, no_close_button)
2318 && wwin->frame->flags.hide_right_button)
2319 flags |= WFF_RIGHT_BUTTON;
2321 if (flags!=0) {
2322 wWindowUpdateButtonImages(wwin);
2323 wFrameWindowShowButton(wwin->frame, flags);
2326 flags = 0;
2327 if (WFLAGP(wwin, no_miniaturize_button)
2328 && !wwin->frame->flags.hide_left_button)
2329 flags |= WFF_LEFT_BUTTON;
2331 #ifdef XKB_BUTTON_HINT
2332 if (WFLAGP(wwin, no_language_button)
2333 && !wwin->frame->flags.hide_language_button)
2334 flags |= WFF_LANGUAGE_BUTTON;
2335 #endif
2337 if (WFLAGP(wwin, no_close_button)
2338 && !wwin->frame->flags.hide_right_button)
2339 flags |= WFF_RIGHT_BUTTON;
2341 if (flags!=0)
2342 wFrameWindowHideButton(wwin->frame, flags);
2344 #ifdef SHAPE
2345 if (wShapeSupported && wwin->flags.shaped) {
2346 wWindowSetShape(wwin);
2348 #endif
2353 void
2354 wWindowSaveState(WWindow *wwin)
2356 CARD32 data[10];
2357 int i;
2359 memset(data, 0, sizeof(CARD32)*10);
2360 data[0] = wwin->frame->workspace;
2361 data[1] = wwin->flags.miniaturized;
2362 data[2] = wwin->flags.shaded;
2363 data[3] = wwin->flags.hidden;
2364 data[4] = wwin->flags.maximized;
2365 if (wwin->flags.maximized == 0) {
2366 data[5] = wwin->frame_x;
2367 data[6] = wwin->frame_y;
2368 data[7] = wwin->frame->core->width;
2369 data[8] = wwin->frame->core->height;
2370 } else {
2371 data[5] = wwin->old_geometry.x;
2372 data[6] = wwin->old_geometry.y;
2373 data[7] = wwin->old_geometry.width;
2374 data[8] = wwin->old_geometry.height;
2377 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2378 if (wwin->screen_ptr->shortcutWindows[i] &&
2379 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2380 data[9] |= 1<<i;
2382 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2383 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
2384 (unsigned char *)data, 10);
2388 static int
2389 getSavedState(Window window, WSavedState **state)
2391 Atom type_ret;
2392 int fmt_ret;
2393 unsigned long nitems_ret;
2394 unsigned long bytes_after_ret;
2395 CARD32 *data;
2397 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2398 True, _XA_WINDOWMAKER_STATE,
2399 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2400 (unsigned char **)&data)!=Success || !data)
2401 return 0;
2403 *state = wmalloc(sizeof(WSavedState));
2405 (*state)->workspace = data[0];
2406 (*state)->miniaturized = data[1];
2407 (*state)->shaded = data[2];
2408 (*state)->hidden = data[3];
2409 (*state)->maximized = data[4];
2410 (*state)->x = data[5];
2411 (*state)->y = data[6];
2412 (*state)->w = data[7];
2413 (*state)->h = data[8];
2414 (*state)->window_shortcuts = data[9];
2416 XFree(data);
2418 if (*state && type_ret==_XA_WINDOWMAKER_STATE)
2419 return 1;
2420 else
2421 return 0;
2425 #ifdef SHAPE
2426 void
2427 wWindowClearShape(WWindow *wwin)
2429 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2430 0, wwin->frame->top_width, None, ShapeSet);
2431 XFlush(dpy);
2434 void
2435 wWindowSetShape(WWindow *wwin)
2437 XRectangle rect[2];
2438 int count;
2439 #ifdef OPTIMIZE_SHAPE
2440 XRectangle *rects;
2441 XRectangle *urec;
2442 int ordering;
2444 /* only shape is the client's */
2445 if (WFLAGP(wwin, no_titlebar) && WFLAGP(wwin, no_resizebar)) {
2446 goto alt_code;
2449 /* Get array of rectangles describing the shape mask */
2450 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding,
2451 &count, &ordering);
2452 if (!rects) {
2453 goto alt_code;
2456 urec = malloc(sizeof(XRectangle)*(count+2));
2457 if (!urec) {
2458 XFree(rects);
2459 goto alt_code;
2462 /* insert our decoration rectangles in the rect list */
2463 memcpy(urec, rects, sizeof(XRectangle)*count);
2464 XFree(rects);
2466 if (!WFLAGP(wwin, no_titlebar)) {
2467 urec[count].x = -1;
2468 urec[count].y = -1 - wwin->frame->top_width;
2469 urec[count].width = wwin->frame->core->width + 2;
2470 urec[count].height = wwin->frame->top_width + 1;
2471 count++;
2473 if (!WFLAGP(wwin, no_resizebar)) {
2474 urec[count].x = -1;
2475 urec[count].y = wwin->frame->core->height
2476 - wwin->frame->bottom_width - wwin->frame->top_width;
2477 urec[count].width = wwin->frame->core->width + 2;
2478 urec[count].height = wwin->frame->bottom_width + 1;
2479 count++;
2482 /* shape our frame window */
2483 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2484 0, wwin->frame->top_width, urec, count,
2485 ShapeSet, Unsorted);
2486 XFlush(dpy);
2487 wfree(urec);
2488 return;
2490 alt_code:
2491 #endif /* OPTIMIZE_SHAPE */
2492 count = 0;
2493 if (!WFLAGP(wwin, no_titlebar)) {
2494 rect[count].x = -1;
2495 rect[count].y = -1;
2496 rect[count].width = wwin->frame->core->width + 2;
2497 rect[count].height = wwin->frame->top_width + 1;
2498 count++;
2500 if (!WFLAGP(wwin, no_resizebar)) {
2501 rect[count].x = -1;
2502 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2503 rect[count].width = wwin->frame->core->width + 2;
2504 rect[count].height = wwin->frame->bottom_width + 1;
2505 count++;
2507 if (count > 0) {
2508 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2509 0, 0, rect, count, ShapeSet, Unsorted);
2511 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2512 0, wwin->frame->top_width, wwin->client_win,
2513 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2514 XFlush(dpy);
2516 #endif /* SHAPE */
2518 /* ====================================================================== */
2520 static FocusMode
2521 getFocusMode(WWindow *wwin)
2523 FocusMode mode;
2525 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2526 if (wwin->wm_hints->input == True) {
2527 if (wwin->protocols.TAKE_FOCUS)
2528 mode = WFM_LOCALLY_ACTIVE;
2529 else
2530 mode = WFM_PASSIVE;
2531 } else {
2532 if (wwin->protocols.TAKE_FOCUS)
2533 mode = WFM_GLOBALLY_ACTIVE;
2534 else
2535 mode = WFM_NO_INPUT;
2537 } else {
2538 mode = WFM_PASSIVE;
2540 return mode;
2544 void
2545 wWindowSetKeyGrabs(WWindow *wwin)
2547 int i;
2548 WShortKey *key;
2550 for (i=0; i<WKBD_LAST; i++) {
2551 key = &wKeyBindings[i];
2553 if (key->keycode==0)
2554 continue;
2555 if (key->modifier!=AnyModifier) {
2556 XGrabKey(dpy, key->keycode, key->modifier|LockMask,
2557 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2558 #ifdef NUMLOCK_HACK
2559 /* Also grab all modifier combinations possible that include,
2560 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2561 * work even if the NumLock/ScrollLock key is on.
2563 wHackedGrabKey(key->keycode, key->modifier,
2564 wwin->frame->core->window, True, GrabModeAsync,
2565 GrabModeAsync);
2566 #endif
2568 XGrabKey(dpy, key->keycode, key->modifier,
2569 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2572 #ifndef LITE
2573 wRootMenuBindShortcuts(wwin->frame->core->window);
2574 #endif
2579 void
2580 wWindowResetMouseGrabs(WWindow *wwin)
2582 /* Mouse grabs can't be done on the client window because of
2583 * ICCCM and because clients that try to do the same will crash.
2585 * But there is a problem wich makes tbar buttons of unfocused
2586 * windows not usable as the click goes to the frame window instead
2587 * of the button itself. Must figure a way to fix that.
2590 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2592 if (!WFLAGP(wwin, no_bind_mouse)) {
2593 /* grabs for Meta+drag */
2594 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2595 True, ButtonPressMask, GrabModeSync,
2596 GrabModeAsync, None, None);
2599 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2600 && !wwin->flags.is_gnustep) {
2601 /* the passive grabs to focus the window */
2602 /* if (wPreferences.focus_mode == WKF_CLICK) */
2603 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2604 True, ButtonPressMask, GrabModeSync, GrabModeAsync,
2605 None, None);
2607 XFlush(dpy);
2611 void
2612 wWindowUpdateGNUstepAttr(WWindow *wwin, GNUstepWMAttributes *attr)
2614 if (attr->flags & GSExtraFlagsAttr) {
2615 if (MGFLAGP(wwin, broken_close) !=
2616 (attr->extra_flags & GSDocumentEditedFlag)) {
2617 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2618 wWindowUpdateButtonImages(wwin);
2624 WMagicNumber
2625 wWindowAddSavedState(char *instance, char *class, char *command,
2626 pid_t pid, WSavedState *state)
2628 WWindowState *wstate;
2630 wstate = malloc(sizeof(WWindowState));
2631 if (!wstate)
2632 return 0;
2634 memset(wstate, 0, sizeof(WWindowState));
2635 wstate->pid = pid;
2636 if (instance)
2637 wstate->instance = wstrdup(instance);
2638 if (class)
2639 wstate->class = wstrdup(class);
2640 if (command)
2641 wstate->command = wstrdup(command);
2642 wstate->state = state;
2644 wstate->next = windowState;
2645 windowState = wstate;
2647 #ifdef DEBUG
2648 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2649 class, command);
2650 #endif
2652 return wstate;
2656 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2659 WMagicNumber
2660 wWindowGetSavedState(Window win)
2662 char *instance, *class, *command=NULL;
2663 WWindowState *wstate = windowState;
2664 char **argv;
2665 int argc;
2667 if (!wstate)
2668 return NULL;
2670 if (XGetCommand(dpy, win, &argv, &argc)) {
2671 if (argc > 0)
2672 command = wtokenjoin(argv, argc);
2673 XFreeStringList(argv);
2675 if (!command)
2676 return NULL;
2678 if (PropGetWMClass(win, &class, &instance)) {
2679 while (wstate) {
2680 if (SAME(instance, wstate->instance) &&
2681 SAME(class, wstate->class) &&
2682 SAME(command, wstate->command)) {
2683 break;
2685 wstate = wstate->next;
2687 } else {
2688 wstate = NULL;
2691 #ifdef DEBUG
2692 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate, instance,
2693 class, command);
2694 #endif
2696 if (command) wfree(command);
2697 if (instance) XFree(instance);
2698 if (class) XFree(class);
2700 return wstate;
2704 void
2705 wWindowDeleteSavedState(WMagicNumber id)
2707 WWindowState *tmp, *wstate=(WWindowState*)id;
2709 if (!wstate || !windowState)
2710 return;
2712 tmp = windowState;
2713 if (tmp==wstate) {
2714 windowState = wstate->next;
2715 #ifdef DEBUG
2716 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2717 wstate, wstate->instance, wstate->class, wstate->command);
2718 #endif
2719 if (wstate->instance) wfree(wstate->instance);
2720 if (wstate->class) wfree(wstate->class);
2721 if (wstate->command) wfree(wstate->command);
2722 wfree(wstate->state);
2723 wfree(wstate);
2724 } else {
2725 while (tmp->next) {
2726 if (tmp->next==wstate) {
2727 tmp->next=wstate->next;
2728 #ifdef DEBUG
2729 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2730 wstate, wstate->instance, wstate->class, wstate->command);
2731 #endif
2732 if (wstate->instance) wfree(wstate->instance);
2733 if (wstate->class) wfree(wstate->class);
2734 if (wstate->command) wfree(wstate->command);
2735 wfree(wstate->state);
2736 wfree(wstate);
2737 break;
2739 tmp = tmp->next;
2745 void
2746 wWindowDeleteSavedStatesForPID(pid_t pid)
2748 WWindowState *tmp, *wstate;
2750 if (!windowState)
2751 return;
2753 tmp = windowState;
2754 if (tmp->pid == pid) {
2755 wstate = windowState;
2756 windowState = tmp->next;
2757 #ifdef DEBUG
2758 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2759 wstate, wstate->instance, wstate->class, wstate->command);
2760 #endif
2761 if (wstate->instance) wfree(wstate->instance);
2762 if (wstate->class) wfree(wstate->class);
2763 if (wstate->command) wfree(wstate->command);
2764 wfree(wstate->state);
2765 wfree(wstate);
2766 } else {
2767 while (tmp->next) {
2768 if (tmp->next->pid==pid) {
2769 wstate = tmp->next;
2770 tmp->next = wstate->next;
2771 #ifdef DEBUG
2772 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2773 wstate, wstate->instance, wstate->class, wstate->command);
2774 #endif
2775 if (wstate->instance) wfree(wstate->instance);
2776 if (wstate->class) wfree(wstate->class);
2777 if (wstate->command) wfree(wstate->command);
2778 wfree(wstate->state);
2779 wfree(wstate);
2780 break;
2782 tmp = tmp->next;
2788 void
2789 wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2791 wwin->flags.omnipresent = flag;
2793 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2797 /* ====================================================================== */
2799 static void
2800 resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2802 WWindow *wwin = data;
2804 #ifndef NUMLOCK_HACK
2805 if ((event->xbutton.state & ValidModMask)
2806 != (event->xbutton.state & ~LockMask)) {
2807 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2808 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2810 #endif
2812 event->xbutton.state &= ValidModMask;
2814 CloseWindowMenu(wwin->screen_ptr);
2816 if (wPreferences.focus_mode==WKF_CLICK
2817 && !(event->xbutton.state&ControlMask)
2818 && !WFLAGP(wwin, no_focusable)) {
2819 wSetFocusTo(wwin->screen_ptr, wwin);
2822 if (event->xbutton.button == Button1)
2823 wRaiseFrame(wwin->frame->core);
2825 if (event->xbutton.window != wwin->frame->resizebar->window) {
2826 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2827 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2828 GrabModeAsync, GrabModeAsync, None,
2829 None, CurrentTime)!=GrabSuccess) {
2830 #ifdef DEBUG0
2831 wwarning("pointer grab failed for window move");
2832 #endif
2833 return;
2837 if (event->xbutton.state & MOD_MASK) {
2838 /* move the window */
2839 wMouseMoveWindow(wwin, event);
2840 XUngrabPointer(dpy, CurrentTime);
2841 } else {
2842 wMouseResizeWindow(wwin, event);
2843 XUngrabPointer(dpy, CurrentTime);
2849 static void
2850 titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2852 WWindow *wwin = data;
2854 event->xbutton.state &= ValidModMask;
2856 if (event->xbutton.button==Button1) {
2857 if (event->xbutton.state == 0) {
2858 if (!WFLAGP(wwin, no_shadeable)) {
2859 /* shade window */
2860 if (wwin->flags.shaded)
2861 wUnshadeWindow(wwin);
2862 else
2863 wShadeWindow(wwin);
2865 } else {
2866 int dir = 0;
2868 if (event->xbutton.state & ControlMask)
2869 dir |= MAX_VERTICAL;
2871 if (event->xbutton.state & ShiftMask) {
2872 dir |= MAX_HORIZONTAL;
2873 if (!(event->xbutton.state & ControlMask))
2874 wSelectWindow(wwin, !wwin->flags.selected);
2877 /* maximize window */
2878 if (dir!=0 && !WFLAGP(wwin, no_resizable)) {
2879 int ndir = dir ^ wwin->flags.maximized;
2880 if (wwin->flags.maximized != 0)
2881 wUnmaximizeWindow(wwin);
2882 if (ndir != 0)
2883 wMaximizeWindow(wwin, ndir);
2886 } else if (event->xbutton.button==Button3) {
2887 if (event->xbutton.state & MOD_MASK) {
2888 wHideOtherApplications(wwin);
2890 } else if (event->xbutton.button==Button2) {
2891 wSelectWindow(wwin, !wwin->flags.selected);
2892 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2893 wShadeWindow(wwin);
2894 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2895 wUnshadeWindow(wwin);
2900 static void
2901 frameMouseDown(WObjDescriptor *desc, XEvent *event)
2903 WWindow *wwin = desc->parent;
2905 event->xbutton.state &= ValidModMask;
2907 CloseWindowMenu(wwin->screen_ptr);
2909 if (/*wPreferences.focus_mode==WKF_CLICK
2910 &&*/ !(event->xbutton.state&ControlMask)
2911 && !WFLAGP(wwin, no_focusable)) {
2912 wSetFocusTo(wwin->screen_ptr, wwin);
2914 if (event->xbutton.button == Button1) {
2915 wRaiseFrame(wwin->frame->core);
2918 if (event->xbutton.state & MOD_MASK) {
2919 /* move the window */
2920 if (XGrabPointer(dpy, wwin->client_win, False,
2921 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2922 GrabModeAsync, GrabModeAsync, None,
2923 None, CurrentTime)!=GrabSuccess) {
2924 #ifdef DEBUG0
2925 wwarning("pointer grab failed for window move");
2926 #endif
2927 return;
2929 if (event->xbutton.button == Button3 && !WFLAGP(wwin, no_resizable))
2930 wMouseResizeWindow(wwin, event);
2931 else
2932 wMouseMoveWindow(wwin, event);
2933 XUngrabPointer(dpy, CurrentTime);
2938 static void
2939 titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2941 WWindow *wwin = (WWindow*)data;
2943 #ifndef NUMLOCK_HACK
2944 if ((event->xbutton.state & ValidModMask)
2945 != (event->xbutton.state & ~LockMask)) {
2946 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2947 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2949 #endif
2950 event->xbutton.state &= ValidModMask;
2952 CloseWindowMenu(wwin->screen_ptr);
2954 if (wPreferences.focus_mode==WKF_CLICK
2955 && !(event->xbutton.state&ControlMask)
2956 && !WFLAGP(wwin, no_focusable)) {
2957 wSetFocusTo(wwin->screen_ptr, wwin);
2960 if (event->xbutton.button == Button1
2961 || event->xbutton.button == Button2) {
2963 if (event->xbutton.button == Button1) {
2964 if (event->xbutton.state & MOD_MASK) {
2965 wLowerFrame(wwin->frame->core);
2966 } else {
2967 wRaiseFrame(wwin->frame->core);
2970 if ((event->xbutton.state & ShiftMask)
2971 && !(event->xbutton.state & ControlMask)) {
2972 wSelectWindow(wwin, !wwin->flags.selected);
2973 return;
2975 if (event->xbutton.window != wwin->frame->titlebar->window
2976 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2977 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2978 GrabModeAsync, GrabModeAsync, None,
2979 None, CurrentTime)!=GrabSuccess) {
2980 #ifdef DEBUG0
2981 wwarning("pointer grab failed for window move");
2982 #endif
2983 return;
2986 /* move the window */
2987 wMouseMoveWindow(wwin, event);
2989 XUngrabPointer(dpy, CurrentTime);
2990 } else if (event->xbutton.button == Button3 && event->xbutton.state==0
2991 && !wwin->flags.internal_window
2992 && !WCHECK_STATE(WSTATE_MODAL)) {
2993 WObjDescriptor *desc;
2995 if (event->xbutton.window != wwin->frame->titlebar->window
2996 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2997 ButtonMotionMask|ButtonReleaseMask|ButtonPressMask,
2998 GrabModeAsync, GrabModeAsync, None,
2999 None, CurrentTime)!=GrabSuccess) {
3000 #ifdef DEBUG0
3001 wwarning("pointer grab failed for window move");
3002 #endif
3003 return;
3006 OpenWindowMenu(wwin, event->xbutton.x_root,
3007 wwin->frame_y+wwin->frame->top_width, False);
3009 /* allow drag select */
3010 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
3011 event->xany.send_event = True;
3012 (*desc->handle_mousedown)(desc, event);
3014 XUngrabPointer(dpy, CurrentTime);
3020 static void
3021 windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
3023 WWindow *wwin = data;
3025 event->xbutton.state &= ValidModMask;
3027 CloseWindowMenu(wwin->screen_ptr);
3029 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3030 return;
3032 /* if control-click, kill the client */
3033 if (event->xbutton.state & ControlMask) {
3034 wClientKill(wwin);
3035 } else {
3036 #ifdef OLWM_HINTS
3037 if (wwin->flags.olwm_push_pin_out) {
3039 wwin->flags.olwm_push_pin_out = 0;
3041 wOLWMChangePushpinState(wwin, True);
3043 wFrameWindowUpdatePushButton(wwin->frame, False);
3045 return;
3047 #endif
3048 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state==0) {
3049 /* send delete message */
3050 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3056 static void
3057 windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
3059 WWindow *wwin = data;
3061 CloseWindowMenu(wwin->screen_ptr);
3063 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3064 return;
3066 /* send delete message */
3067 if (wwin->protocols.DELETE_WINDOW) {
3068 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
3069 } else {
3070 wClientKill(wwin);
3075 #ifdef XKB_BUTTON_HINT
3076 static void
3077 windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
3079 WWindow *wwin = data;
3080 WFrameWindow *fwin = wwin->frame;
3081 WScreen *scr = fwin->screen_ptr;
3082 XkbStateRec staterec;
3083 int tl;
3085 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
3086 return;
3087 tl = wwin->frame->languagemode;
3088 wwin->frame->languagemode = wwin->frame->last_languagemode;
3089 wwin->frame->last_languagemode = tl;
3090 wSetFocusTo(scr, wwin);
3091 wwin->frame->languagebutton_image =
3092 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 +
3093 wwin->frame->languagemode];
3094 wFrameWindowUpdateLanguageButton(wwin->frame);
3095 if (event->xbutton.button == Button3)
3096 return;
3097 wRaiseFrame(fwin->core);
3099 #endif
3102 static void
3103 windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
3105 WWindow *wwin = data;
3107 event->xbutton.state &= ValidModMask;
3109 CloseWindowMenu(wwin->screen_ptr);
3111 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3112 return;
3114 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state==0) {
3115 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
3116 LastTimestamp);
3117 } else {
3118 WApplication *wapp;
3119 if ((event->xbutton.state & ControlMask) ||
3120 (event->xbutton.button == Button3)) {
3122 wapp = wApplicationOf(wwin->main_window);
3123 if (wapp && !WFLAGP(wwin, no_appicon))
3124 wHideApplication(wapp);
3125 } else if (event->xbutton.state==0) {
3126 wIconifyWindow(wwin);