Remove unused argument from wDefaultFillAttributes()
[wmaker-crm.git] / src / window.c
blob50962f70a3e72dc5e5bce2c5a765c7b4ccaa9fd2
1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #ifdef SHAPE
27 #include <X11/extensions/shape.h>
28 #endif
29 #ifdef KEEP_XKB_LOCK_STATUS
30 #include <X11/XKBlib.h>
31 #endif /* KEEP_XKB_LOCK_STATUS */
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdint.h>
36 #include <math.h>
38 /* For getting mouse wheel mappings from WINGs */
39 #include <WINGs/WINGsP.h>
41 #include "WindowMaker.h"
42 #include "GNUstep.h"
43 #include "wcore.h"
44 #include "framewin.h"
45 #include "texture.h"
46 #include "window.h"
47 #include "winspector.h"
48 #include "icon.h"
49 #include "properties.h"
50 #include "actions.h"
51 #include "client.h"
52 #include "funcs.h"
53 #include "colormap.h"
54 #include "keybind.h"
55 #include "stacking.h"
56 #include "defaults.h"
57 #include "workspace.h"
58 #include "xinerama.h"
59 #include "appmenu.h"
60 #include "appicon.h"
61 #include "superfluous.h"
62 #include "rootmenu.h"
64 #ifdef MWM_HINTS
65 # include "motif.h"
66 #endif
67 #include "wmspec.h"
69 #define MOD_MASK wPreferences.modifier_mask
71 /****** Global Variables ******/
72 extern WShortKey wKeyBindings[WKBD_LAST];
74 #ifdef SHAPE
75 extern Bool wShapeSupported;
76 #endif
78 /* contexts */
79 extern XContext wWinContext;
81 /* protocol atoms */
82 extern Atom _XA_WM_DELETE_WINDOW;
83 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
84 extern Atom _XA_WINDOWMAKER_STATE;
85 extern WPreferences wPreferences;
86 extern Time LastTimestamp;
88 /***** Local Stuff *****/
89 static WWindowState *windowState = NULL;
90 static FocusMode getFocusMode(WWindow *wwin);
91 static int getSavedState(Window window, WSavedState **state);
92 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
94 /* frame window (during window grabs) */
95 static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
97 /* close button */
98 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
99 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
101 /* iconify button */
102 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
104 #ifdef XKB_BUTTON_HINT
105 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
106 #endif
108 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
109 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
110 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
112 /****** Notification Observers ******/
114 static void appearanceObserver(void *self, WMNotification * notif)
116 WWindow *wwin = (WWindow *) self;
117 uintptr_t flags = (uintptr_t)WMGetNotificationClientData(notif);
119 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
120 return;
122 if (flags & WFontSettings) {
123 wWindowConfigureBorders(wwin);
124 if (wwin->flags.shaded) {
125 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
126 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
127 wWindowSynthConfigureNotify(wwin);
130 if (flags & WTextureSettings)
131 wwin->frame->flags.need_texture_remake = 1;
133 if (flags & (WTextureSettings | WColorSettings)) {
134 if (wwin->frame->titlebar)
135 XClearWindow(dpy, wwin->frame->titlebar->window);
137 wFrameWindowPaint(wwin->frame);
142 WWindow *wWindowFor(Window window)
144 WObjDescriptor *desc;
146 if (window == None)
147 return NULL;
149 if (XFindContext(dpy, window, wWinContext, (XPointer *) & desc) == XCNOENT)
150 return NULL;
152 if (desc->parent_type == WCLASS_WINDOW)
153 return desc->parent;
154 else if (desc->parent_type == WCLASS_FRAME) {
155 WFrameWindow *frame = (WFrameWindow *) desc->parent;
156 if (frame->flags.is_client_window_frame)
157 return frame->child;
160 return NULL;
163 WWindow *wWindowCreate(void)
165 WWindow *wwin;
167 wwin = wmalloc(sizeof(WWindow));
168 wretain(wwin);
170 wwin->client_descriptor.handle_mousedown = frameMouseDown;
171 wwin->client_descriptor.parent = wwin;
172 wwin->client_descriptor.self = wwin;
173 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
175 return wwin;
178 void wWindowDestroy(WWindow *wwin)
180 int i;
182 if (wwin->screen_ptr->cmap_window == wwin)
183 wwin->screen_ptr->cmap_window = NULL;
185 WMRemoveNotificationObserver(wwin);
187 wwin->flags.destroyed = 1;
189 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
190 if (!wwin->screen_ptr->shortcutWindows[i])
191 continue;
193 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
195 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
196 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
197 wwin->screen_ptr->shortcutWindows[i] = NULL;
201 if (wwin->fake_group && wwin->fake_group->retainCount > 0) {
202 wwin->fake_group->retainCount--;
203 if (wwin->fake_group->retainCount == 0 && wwin->fake_group->leader != None) {
204 XDestroyWindow(dpy, wwin->fake_group->leader);
205 wwin->fake_group->leader = None;
206 wwin->fake_group->origLeader = None;
207 XFlush(dpy);
211 if (wwin->normal_hints)
212 XFree(wwin->normal_hints);
214 if (wwin->wm_hints)
215 XFree(wwin->wm_hints);
217 if (wwin->wm_instance)
218 XFree(wwin->wm_instance);
220 if (wwin->wm_class)
221 XFree(wwin->wm_class);
223 if (wwin->wm_gnustep_attr)
224 wfree(wwin->wm_gnustep_attr);
226 if (wwin->cmap_windows)
227 XFree(wwin->cmap_windows);
229 XDeleteContext(dpy, wwin->client_win, wWinContext);
231 if (wwin->frame)
232 wFrameWindowDestroy(wwin->frame);
234 if (wwin->icon) {
235 RemoveFromStackList(wwin->icon->core);
236 wIconDestroy(wwin->icon);
237 if (wPreferences.auto_arrange_icons)
238 wArrangeIcons(wwin->screen_ptr, True);
240 if (wwin->net_icon_image)
241 RReleaseImage(wwin->net_icon_image);
243 wrelease(wwin);
246 static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
248 if (gs_hints->flags & GSWindowStyleAttr) {
249 if (gs_hints->window_style == WMBorderlessWindowMask) {
250 wwin->client_flags.no_border = 1;
251 wwin->client_flags.no_titlebar = 1;
252 wwin->client_flags.no_closable = 1;
253 wwin->client_flags.no_miniaturizable = 1;
254 wwin->client_flags.no_resizable = 1;
255 wwin->client_flags.no_close_button = 1;
256 wwin->client_flags.no_miniaturize_button = 1;
257 wwin->client_flags.no_resizebar = 1;
258 } else {
259 wwin->client_flags.no_close_button =
260 ((gs_hints->window_style & WMClosableWindowMask) ? 0 : 1);
262 wwin->client_flags.no_closable = ((gs_hints->window_style & WMClosableWindowMask) ? 0 : 1);
264 wwin->client_flags.no_miniaturize_button =
265 ((gs_hints->window_style & WMMiniaturizableWindowMask) ? 0 : 1);
267 wwin->client_flags.no_miniaturizable = wwin->client_flags.no_miniaturize_button;
269 wwin->client_flags.no_resizebar =
270 ((gs_hints->window_style & WMResizableWindowMask) ? 0 : 1);
272 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
274 /* these attributes supposedly imply in the existence
275 * of a titlebar */
276 if (gs_hints->window_style & (WMResizableWindowMask |
277 WMClosableWindowMask | WMMiniaturizableWindowMask)) {
278 wwin->client_flags.no_titlebar = 0;
279 } else {
280 wwin->client_flags.no_titlebar =
281 ((gs_hints->window_style & WMTitledWindowMask) ? 0 : 1);
285 } else {
286 /* setup the defaults */
287 wwin->client_flags.no_border = 0;
288 wwin->client_flags.no_titlebar = 0;
289 wwin->client_flags.no_closable = 0;
290 wwin->client_flags.no_miniaturizable = 0;
291 wwin->client_flags.no_resizable = 0;
292 wwin->client_flags.no_close_button = 0;
293 wwin->client_flags.no_miniaturize_button = 0;
294 wwin->client_flags.no_resizebar = 0;
296 if (gs_hints->extra_flags & GSNoApplicationIconFlag)
297 wwin->client_flags.no_appicon = 1;
300 void wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
302 WScreen *scr = wwin->screen_ptr;
304 /* sets global default stuff */
305 wDefaultFillAttributes(wwin->wm_instance, wwin->wm_class, &wwin->client_flags, NULL, True);
307 * Decoration setting is done in this precedence (lower to higher)
308 * - use global default in the resource database
309 * - guess some settings
310 * - use GNUstep/external window attributes
311 * - set hints specified for the app in the resource DB
314 WSETUFLAG(wwin, broken_close, 0);
316 if (wwin->protocols.DELETE_WINDOW)
317 WSETUFLAG(wwin, kill_close, 0);
318 else
319 WSETUFLAG(wwin, kill_close, 1);
321 /* transients can't be iconified or maximized */
322 if (wwin->transient_for != None && wwin->transient_for != scr->root_win) {
323 WSETUFLAG(wwin, no_miniaturizable, 1);
324 WSETUFLAG(wwin, no_miniaturize_button, 1);
327 /* if the window can't be resized, remove the resizebar */
328 if (wwin->normal_hints->flags & (PMinSize | PMaxSize)
329 && (wwin->normal_hints->min_width == wwin->normal_hints->max_width)
330 && (wwin->normal_hints->min_height == wwin->normal_hints->max_height)) {
331 WSETUFLAG(wwin, no_resizable, 1);
332 WSETUFLAG(wwin, no_resizebar, 1);
335 /* set GNUstep window attributes */
336 if (wwin->wm_gnustep_attr) {
337 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
339 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
341 *level = wwin->wm_gnustep_attr->window_level;
343 * INT_MIN is the only illegal window level.
345 if (*level == INT_MIN)
346 *level = INT_MIN + 1;
347 } else {
348 /* setup defaults */
349 *level = WMNormalLevel;
351 } else {
352 int tmp_workspace = -1;
353 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
354 Bool check;
356 check = False;
358 #ifdef MWM_HINTS
359 wMWMCheckClientHints(wwin);
360 #endif /* MWM_HINTS */
362 if (!check)
363 check = wNETWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
365 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
366 * have INT_MIN that means that no window level was requested. -Dan
368 if (tmp_level == INT_MIN) {
369 if (WFLAGP(wwin, floating))
370 *level = WMFloatingLevel;
371 else if (WFLAGP(wwin, sunken))
372 *level = WMSunkenLevel;
373 else
374 *level = WMNormalLevel;
375 } else {
376 *level = tmp_level;
379 if (wwin->transient_for != None && wwin->transient_for != scr->root_win) {
380 WWindow *transientOwner = wWindowFor(wwin->transient_for);
381 if (transientOwner) {
382 int ownerLevel = transientOwner->frame->core->stacking->window_level;
383 if (ownerLevel > *level)
384 *level = ownerLevel;
388 if (tmp_workspace >= 0)
389 *workspace = tmp_workspace % scr->workspace_count;
393 * Set attributes specified only for that window/class.
394 * This might do duplicate work with the 1st wDefaultFillAttributes().
396 wDefaultFillAttributes(wwin->wm_instance, wwin->wm_class, &wwin->user_flags,
397 &wwin->defined_user_flags, False);
399 * Sanity checks for attributes that depend on other attributes
401 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
402 wwin->user_flags.emulate_appicon = 0;
404 if (wwin->main_window != None) {
405 WApplication *wapp = wApplicationOf(wwin->main_window);
406 if (wapp && !wapp->flags.emulated)
407 wwin->user_flags.emulate_appicon = 0;
410 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win)
411 wwin->user_flags.emulate_appicon = 0;
413 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
414 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
415 wwin->user_flags.sunken = 0;
417 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
419 /* windows that have takefocus=False shouldn't take focus at all */
420 if (wwin->focus_mode == WFM_NO_INPUT)
421 wwin->client_flags.no_focusable = 1;
424 Bool wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
426 int w1, h1, w2, h2;
428 w1 = wwin->frame->core->width;
429 h1 = wwin->frame->core->height;
430 w2 = obscured->frame->core->width;
431 h2 = obscured->frame->core->height;
433 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
434 && wwin->frame->workspace != obscured->frame->workspace)
435 return False;
437 if (wwin->frame_x + w1 < obscured->frame_x
438 || wwin->frame_y + h1 < obscured->frame_y
439 || wwin->frame_x > obscured->frame_x + w2 || wwin->frame_y > obscured->frame_y + h2)
440 return False;
442 return True;
445 static void fixLeaderProperties(WWindow *wwin)
447 XClassHint *classHint;
448 XWMHints *hints, *clientHints;
449 XWindowAttributes attr;
450 Window leaders[2], window;
451 char **argv, *command;
452 int argc, i, pid;
453 Bool haveCommand;
455 classHint = XAllocClassHint();
456 clientHints = XGetWMHints(dpy, wwin->client_win);
457 pid = wNETWMGetPidForWindow(wwin->client_win);
458 if (pid > 0)
459 haveCommand = GetCommandForPid(pid, &argv, &argc);
460 else
461 haveCommand = False;
463 leaders[0] = wwin->client_leader;
464 leaders[1] = wwin->group_id;
466 if (haveCommand) {
467 command = GetCommandForWindow(wwin->client_win);
468 if (command)
469 wfree(command); /* command already set. nothing to do. */
470 else
471 XSetCommand(dpy, wwin->client_win, argv, argc);
474 for (i = 0; i < 2; i++) {
475 window = leaders[i];
476 if (window) {
477 if (XGetClassHint(dpy, window, classHint) == 0) {
478 classHint->res_name = wwin->wm_instance;
479 classHint->res_class = wwin->wm_class;
480 XSetClassHint(dpy, window, classHint);
482 hints = XGetWMHints(dpy, window);
483 if (hints) {
484 XFree(hints);
485 } else if (clientHints) {
486 /* set window group leader to self */
487 clientHints->window_group = window;
488 clientHints->flags |= WindowGroupHint;
489 XSetWMHints(dpy, window, clientHints);
492 if (haveCommand) {
493 command = GetCommandForWindow(window);
494 if (command)
495 wfree(command); /* command already set. nothing to do. */
496 else
497 XSetCommand(dpy, window, argv, argc);
500 /* Make sure we get notification when this window is destroyed */
501 if (XGetWindowAttributes(dpy, window, &attr))
502 XSelectInput(dpy, window, attr.your_event_mask | StructureNotifyMask | PropertyChangeMask);
506 XFree(classHint);
507 if (clientHints)
508 XFree(clientHints);
509 if (haveCommand)
510 wfree(argv);
513 static Window createFakeWindowGroupLeader(WScreen *scr, Window win, char *instance, char *class)
515 XClassHint *classHint;
516 XWMHints *hints;
517 Window leader;
518 int argc;
519 char **argv;
521 leader = XCreateSimpleWindow(dpy, scr->root_win, 10, 10, 10, 10, 0, 0, 0);
522 /* set class hint */
523 classHint = XAllocClassHint();
524 classHint->res_name = instance;
525 classHint->res_class = class;
526 XSetClassHint(dpy, leader, classHint);
527 XFree(classHint);
529 /* inherit these from the original leader if available */
530 hints = XGetWMHints(dpy, win);
531 if (!hints) {
532 hints = XAllocWMHints();
533 hints->flags = 0;
535 /* set window group leader to self */
536 hints->window_group = leader;
537 hints->flags |= WindowGroupHint;
538 XSetWMHints(dpy, leader, hints);
539 XFree(hints);
541 if (XGetCommand(dpy, win, &argv, &argc) != 0 && argc > 0) {
542 XSetCommand(dpy, leader, argv, argc);
543 XFreeStringList(argv);
546 return leader;
549 static int matchIdentifier(const void *item, const void *cdata)
551 return (strcmp(((WFakeGroupLeader *) item)->identifier, (char *)cdata) == 0);
555 *----------------------------------------------------------------
556 * wManageWindow--
557 * reparents the window and allocates a descriptor for it.
558 * Window manager hints and other hints are fetched to configure
559 * the window decoration attributes and others. User preferences
560 * for the window are used if available, to configure window
561 * decorations and some behaviour.
562 * If in startup, windows that are override redirect,
563 * unmapped and never were managed and are Withdrawn are not
564 * managed.
566 * Returns:
567 * the new window descriptor
569 * Side effects:
570 * The window is reparented and appropriate notification
571 * is done to the client. Input mask for the window is setup.
572 * The window descriptor is also associated with various window
573 * contexts and inserted in the head of the window list.
574 * Event handler contexts are associated for some objects
575 * (buttons, titlebar and resizebar)
577 *----------------------------------------------------------------
579 WWindow *wManageWindow(WScreen *scr, Window window)
581 WWindow *wwin;
582 int x, y;
583 unsigned width, height;
584 XWindowAttributes wattribs;
585 XSetWindowAttributes attribs;
586 WWindowState *win_state;
587 WWindow *transientOwner = NULL;
588 int window_level;
589 int wm_state;
590 int foo;
591 int workspace = -1;
592 char *title;
593 Bool withdraw = False;
594 Bool raise = False;
596 /* mutex. */
597 XGrabServer(dpy);
598 XSync(dpy, False);
599 /* make sure the window is still there */
600 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
601 XUngrabServer(dpy);
602 return NULL;
605 /* if it's an override-redirect, ignore it */
606 if (wattribs.override_redirect) {
607 XUngrabServer(dpy);
608 return NULL;
611 wm_state = PropGetWindowState(window);
613 /* if it's startup and the window is unmapped, don't manage it */
614 if (scr->flags.startup && wm_state < 0 && wattribs.map_state == IsUnmapped) {
615 XUngrabServer(dpy);
616 return NULL;
619 wwin = wWindowCreate();
621 title = wNETWMGetWindowName(window);
622 if (title)
623 wwin->flags.net_has_title = 1;
624 if (!title && !wFetchName(dpy, window, &title))
625 title = NULL;
627 XSaveContext(dpy, window, wWinContext, (XPointer) & wwin->client_descriptor);
629 #ifdef SHAPE
630 if (wShapeSupported) {
631 int junk;
632 unsigned int ujunk;
633 int b_shaped;
635 XShapeSelectInput(dpy, window, ShapeNotifyMask);
636 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
637 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
638 wwin->flags.shaped = b_shaped;
640 #endif
643 * Get hints and other information in properties
645 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
647 /* setup descriptor */
648 wwin->client_win = window;
649 wwin->screen_ptr = scr;
650 wwin->old_border_width = wattribs.border_width;
651 wwin->event_mask = CLIENT_EVENTS;
652 attribs.event_mask = CLIENT_EVENTS;
653 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
654 attribs.save_under = False;
656 XChangeWindowAttributes(dpy, window, CWEventMask | CWDontPropagate | CWSaveUnder, &attribs);
657 XSetWindowBorderWidth(dpy, window, 0);
659 /* get hints from GNUstep app */
660 if (wwin->wm_class != NULL && strcmp(wwin->wm_class, "GNUstep") == 0)
661 wwin->flags.is_gnustep = 1;
663 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr))
664 wwin->wm_gnustep_attr = NULL;
666 if (wwin->wm_class != NULL && strcmp(wwin->wm_class, "DockApp") == 0) {
667 wwin->flags.is_dockapp = 1;
668 withdraw = True;
671 wwin->client_leader = PropGetClientLeader(window);
672 if (wwin->client_leader != None)
673 wwin->main_window = wwin->client_leader;
675 wwin->wm_hints = XGetWMHints(dpy, window);
677 if (wwin->wm_hints) {
678 if (wwin->wm_hints->flags & StateHint) {
680 if (wwin->wm_hints->initial_state == IconicState) {
681 wwin->flags.miniaturized = 1;
682 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
683 wwin->flags.is_dockapp = 1;
684 withdraw = True;
688 if (wwin->wm_hints->flags & WindowGroupHint) {
689 wwin->group_id = wwin->wm_hints->window_group;
690 /* window_group has priority over CLIENT_LEADER */
691 wwin->main_window = wwin->group_id;
692 } else {
693 wwin->group_id = None;
696 if (wwin->wm_hints->flags & UrgencyHint) {
697 wwin->flags.urgent = 1;
698 wAppBounceWhileUrgent(wApplicationOf(wwin->main_window));
700 } else {
701 wwin->group_id = None;
704 PropGetProtocols(window, &wwin->protocols);
706 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
707 wwin->transient_for = None;
708 } else {
709 if (wwin->transient_for == None || wwin->transient_for == window) {
710 wwin->transient_for = scr->root_win;
711 } else {
712 transientOwner = wWindowFor(wwin->transient_for);
713 if (transientOwner && transientOwner->main_window != None)
714 wwin->main_window = transientOwner->main_window;
718 /* guess the focus mode */
719 wwin->focus_mode = getFocusMode(wwin);
721 /* get geometry stuff */
722 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
724 /* get colormap windows */
725 GetColormapWindows(wwin);
728 * Setup the decoration/window attributes and
729 * geometry
731 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
733 /* Make broken apps behave as a nice app. */
734 if (WFLAGP(wwin, emulate_appicon))
735 wwin->main_window = wwin->client_win;
737 fixLeaderProperties(wwin);
739 wwin->orig_main_window = wwin->main_window;
741 if (wwin->flags.is_gnustep)
742 WSETUFLAG(wwin, shared_appicon, 0);
744 if (wwin->main_window) {
745 extern Atom _XA_WINDOWMAKER_MENU;
746 XTextProperty text_prop;
748 if (XGetTextProperty(dpy, wwin->main_window, &text_prop, _XA_WINDOWMAKER_MENU))
749 WSETUFLAG(wwin, shared_appicon, 0);
752 if (wwin->flags.is_dockapp)
753 WSETUFLAG(wwin, shared_appicon, 0);
755 if (wwin->main_window) {
756 WApplication *app = wApplicationOf(wwin->main_window);
757 if (app && app->app_icon)
758 WSETUFLAG(wwin, shared_appicon, 0);
761 if (!withdraw && wwin->main_window && WFLAGP(wwin, shared_appicon)) {
762 char *buffer, *instance, *class;
763 WFakeGroupLeader *fPtr;
764 int index;
766 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
768 /* // only enter here if PropGetWMClass() succeds */
769 PropGetWMClass(wwin->main_window, &class, &instance);
770 buffer = StrConcatDot(instance, class);
772 index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void *)buffer);
773 if (index != WANotFound) {
774 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
775 if (fPtr->retainCount == 0)
776 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
777 instance, class);
779 fPtr->retainCount++;
780 if (fPtr->origLeader == None) {
781 if (ADEQUATE(wwin->main_window)) {
782 fPtr->retainCount++;
783 fPtr->origLeader = wwin->main_window;
786 wwin->fake_group = fPtr;
787 /*wwin->group_id = fPtr->leader; */
788 wwin->main_window = fPtr->leader;
789 wfree(buffer);
790 } else {
791 fPtr = (WFakeGroupLeader *) wmalloc(sizeof(WFakeGroupLeader));
793 fPtr->identifier = buffer;
794 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window, instance, class);
795 fPtr->origLeader = None;
796 fPtr->retainCount = 1;
798 WMAddToArray(scr->fakeGroupLeaders, fPtr);
800 if (ADEQUATE(wwin->main_window)) {
801 fPtr->retainCount++;
802 fPtr->origLeader = wwin->main_window;
804 wwin->fake_group = fPtr;
805 /*wwin->group_id = fPtr->leader; */
806 wwin->main_window = fPtr->leader;
808 if (instance)
809 free(instance);
810 if (class)
811 free(class);
812 #undef ADEQUATE
816 * Setup the initial state of the window
818 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable))
819 wwin->flags.miniaturized = 1;
821 if (WFLAGP(wwin, start_maximized) && IS_RESIZABLE(wwin))
822 wwin->flags.maximized = MAX_VERTICAL | MAX_HORIZONTAL;
824 wNETWMCheckInitialClientState(wwin);
826 /* apply previous state if it exists and we're in startup */
827 if (scr->flags.startup && wm_state >= 0) {
828 if (wm_state == IconicState) {
829 wwin->flags.miniaturized = 1;
830 } else if (wm_state == WithdrawnState) {
831 withdraw = True;
835 /* if there is a saved state (from file), restore it */
836 win_state = NULL;
837 if (wwin->main_window != None)
838 win_state = (WWindowState *) wWindowGetSavedState(wwin->main_window);
839 else
840 win_state = (WWindowState *) wWindowGetSavedState(window);
842 if (win_state && !withdraw) {
843 if (win_state->state->hidden > 0)
844 wwin->flags.hidden = win_state->state->hidden;
846 if (win_state->state->shaded > 0 && !WFLAGP(wwin, no_shadeable))
847 wwin->flags.shaded = win_state->state->shaded;
849 if (win_state->state->miniaturized > 0 && !WFLAGP(wwin, no_miniaturizable))
850 wwin->flags.miniaturized = win_state->state->miniaturized;
852 if (!IS_OMNIPRESENT(wwin)) {
853 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
854 wwin->wm_class);
855 if (w < 0 || w >= scr->workspace_count) {
856 workspace = win_state->state->workspace;
857 if (workspace >= scr->workspace_count)
858 workspace = scr->current_workspace;
859 } else {
860 workspace = w;
862 } else {
863 workspace = scr->current_workspace;
867 /* if we're restarting, restore saved state (from hints).
868 * This will overwrite previous */
870 WSavedState *wstate;
872 if (getSavedState(window, &wstate)) {
873 wwin->flags.shaded = wstate->shaded;
874 wwin->flags.hidden = wstate->hidden;
875 wwin->flags.miniaturized = wstate->miniaturized;
876 wwin->flags.maximized = wstate->maximized;
877 if (wwin->flags.maximized) {
878 wwin->old_geometry.x = wstate->x;
879 wwin->old_geometry.y = wstate->y;
880 wwin->old_geometry.width = wstate->w;
881 wwin->old_geometry.height = wstate->h;
884 workspace = wstate->workspace;
885 } else {
886 wstate = NULL;
889 /* restore window shortcut */
890 if (wstate != NULL || win_state != NULL) {
891 unsigned mask = 0;
893 if (win_state != NULL)
894 mask = win_state->state->window_shortcuts;
896 if (wstate != NULL && mask == 0)
897 mask = wstate->window_shortcuts;
899 if (mask > 0) {
900 int i;
902 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
903 if (mask & (1 << i)) {
904 if (!scr->shortcutWindows[i])
905 scr->shortcutWindows[i] = WMCreateArray(4);
907 WMAddToArray(scr->shortcutWindows[i], wwin);
912 if (wstate != NULL)
913 wfree(wstate);
916 /* don't let transients start miniaturized if their owners are not */
917 if (transientOwner && !transientOwner->flags.miniaturized && wwin->flags.miniaturized && !withdraw) {
918 wwin->flags.miniaturized = 0;
919 if (wwin->wm_hints)
920 wwin->wm_hints->initial_state = NormalState;
923 /* set workspace on which the window starts */
924 if (workspace >= 0) {
925 if (workspace > scr->workspace_count - 1)
926 workspace = workspace % scr->workspace_count;
927 } else {
928 int w;
930 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
932 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
933 workspace = w;
934 } else {
935 if (wPreferences.open_transients_with_parent && transientOwner)
936 workspace = transientOwner->frame->workspace;
937 else
938 workspace = scr->current_workspace;
942 /* setup window geometry */
943 if (win_state && win_state->state->w > 0) {
944 width = win_state->state->w;
945 height = win_state->state->h;
947 wWindowConstrainSize(wwin, &width, &height);
949 /* do not ask for window placement if the window is
950 * transient, during startup, if the initial workspace is another one
951 * or if the window wants to start iconic.
952 * If geometry was saved, restore it. */
954 Bool dontBring = False;
956 if (win_state && win_state->state->w > 0) {
957 x = win_state->state->x;
958 y = win_state->state->y;
959 } else if ((wwin->transient_for == None || wPreferences.window_placement != WPM_MANUAL)
960 && !scr->flags.startup
961 && workspace == scr->current_workspace
962 && !wwin->flags.miniaturized
963 && !wwin->flags.maximized && !(wwin->normal_hints->flags & (USPosition | PPosition))) {
965 if (transientOwner && transientOwner->flags.mapped) {
966 int offs = WMAX(20, 2 * transientOwner->frame->top_width);
967 WMRect rect;
968 int head;
970 x = transientOwner->frame_x +
971 abs((transientOwner->frame->core->width - width) / 2) + offs;
972 y = transientOwner->frame_y +
973 abs((transientOwner->frame->core->height - height) / 3) + offs;
976 * limit transient windows to be inside their parent's head
978 rect.pos.x = transientOwner->frame_x;
979 rect.pos.y = transientOwner->frame_y;
980 rect.size.width = transientOwner->frame->core->width;
981 rect.size.height = transientOwner->frame->core->height;
983 head = wGetHeadForRect(scr, rect);
984 rect = wGetRectForHead(scr, head);
986 if (x < rect.pos.x)
987 x = rect.pos.x;
988 else if (x + width > rect.pos.x + rect.size.width)
989 x = rect.pos.x + rect.size.width - width;
991 if (y < rect.pos.y)
992 y = rect.pos.y;
993 else if (y + height > rect.pos.y + rect.size.height)
994 y = rect.pos.y + rect.size.height - height;
996 } else {
997 PlaceWindow(wwin, &x, &y, width, height);
999 if (wPreferences.window_placement == WPM_MANUAL) {
1000 dontBring = True;
1002 } else if (scr->xine_info.count && (wwin->normal_hints->flags & PPosition)) {
1003 int head, flags;
1004 WMRect rect;
1005 int reposition = 0;
1008 * Make spash screens come out in the center of a head
1009 * trouble is that most splashies never get here
1010 * they are managed trough atoms but god knows where.
1011 * Dan, do you know ? -peter
1013 * Most of them are not managed, they have set
1014 * OverrideRedirect, which means we can't do anything about
1015 * them. -alfredo
1019 * xinerama checks for: across head and dead space
1021 rect.pos.x = x;
1022 rect.pos.y = y;
1023 rect.size.width = width;
1024 rect.size.height = height;
1026 head = wGetRectPlacementInfo(scr, rect, &flags);
1028 if (flags & XFLAG_DEAD)
1029 reposition = 1;
1031 if (flags & XFLAG_MULTIPLE)
1032 reposition = 2;
1035 switch (reposition) {
1036 case 1:
1037 head = wGetHeadForPointerLocation(scr);
1038 rect = wGetRectForHead(scr, head);
1040 x = rect.pos.x + (x * rect.size.width) / scr->scr_width;
1041 y = rect.pos.y + (y * rect.size.height) / scr->scr_height;
1042 break;
1044 case 2:
1045 rect = wGetRectForHead(scr, head);
1047 if (x < rect.pos.x)
1048 x = rect.pos.x;
1049 else if (x + width > rect.pos.x + rect.size.width)
1050 x = rect.pos.x + rect.size.width - width;
1052 if (y < rect.pos.y)
1053 y = rect.pos.y;
1054 else if (y + height > rect.pos.y + rect.size.height)
1055 y = rect.pos.y + rect.size.height - height;
1057 break;
1059 default:
1060 break;
1064 if (WFLAGP(wwin, dont_move_off) && dontBring)
1065 wScreenBringInside(scr, &x, &y, width, height);
1068 wNETWMPositionSplash(wwin, &x, &y, width, height);
1070 if (wwin->flags.urgent) {
1071 if (!IS_OMNIPRESENT(wwin))
1072 wwin->flags.omnipresent ^= 1;
1076 * Create frame, borders and do reparenting
1078 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
1079 #ifdef XKB_BUTTON_HINT
1080 if (wPreferences.modelock)
1081 foo |= WFF_LANGUAGE_BUTTON;
1082 #endif
1083 if (HAS_TITLEBAR(wwin))
1084 foo |= WFF_TITLEBAR;
1085 if (HAS_RESIZEBAR(wwin))
1086 foo |= WFF_RESIZEBAR;
1087 if (HAS_BORDER(wwin))
1088 foo |= WFF_BORDER;
1090 wwin->frame = wFrameWindowCreate(scr, window_level,
1091 x, y, width, height,
1092 &wPreferences.window_title_clearance,
1093 &wPreferences.window_title_min_height,
1094 &wPreferences.window_title_max_height,
1095 foo,
1096 scr->window_title_texture,
1097 scr->resizebar_texture, scr->window_title_color, &scr->title_font);
1099 wwin->frame->flags.is_client_window_frame = 1;
1100 wwin->frame->flags.justification = wPreferences.title_justification;
1102 /* setup button images */
1103 wWindowUpdateButtonImages(wwin);
1105 /* hide unused buttons */
1106 foo = 0;
1107 if (WFLAGP(wwin, no_close_button))
1108 foo |= WFF_RIGHT_BUTTON;
1109 if (WFLAGP(wwin, no_miniaturize_button))
1110 foo |= WFF_LEFT_BUTTON;
1111 #ifdef XKB_BUTTON_HINT
1112 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1113 foo |= WFF_LANGUAGE_BUTTON;
1114 #endif
1115 if (foo != 0)
1116 wFrameWindowHideButton(wwin->frame, foo);
1118 wwin->frame->child = wwin;
1119 wwin->frame->workspace = workspace;
1120 wwin->frame->on_click_left = windowIconifyClick;
1122 #ifdef XKB_BUTTON_HINT
1123 if (wPreferences.modelock)
1124 wwin->frame->on_click_language = windowLanguageClick;
1125 #endif
1127 wwin->frame->on_click_right = windowCloseClick;
1128 wwin->frame->on_dblclick_right = windowCloseDblClick;
1129 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1130 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1131 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1133 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
1134 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window, 0, wwin->frame->top_width);
1135 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1138 int gx, gy;
1140 wClientGetGravityOffsets(wwin, &gx, &gy);
1142 /* if gravity is to the south, account for the border sizes */
1143 if (gy > 0)
1144 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1148 * wWindowConfigure() will init the client window's size
1149 * (wwin->client.{width,height}) and all other geometry
1150 * related variables (frame_x,frame_y)
1152 wWindowConfigure(wwin, x, y, width, height);
1154 /* to make sure the window receives it's new position after reparenting */
1155 wWindowSynthConfigureNotify(wwin);
1158 * Setup descriptors and save window to internal
1159 * lists
1161 if (wwin->main_window != None) {
1162 WApplication *app;
1163 WWindow *leader;
1165 /* Leader windows do not necessary set themselves as leaders.
1166 * If this is the case, point the leader of this window to
1167 * itself */
1168 leader = wWindowFor(wwin->main_window);
1169 if (leader && leader->main_window == None)
1170 leader->main_window = leader->client_win;
1172 app = wApplicationCreate(wwin);
1173 if (app) {
1174 app->last_workspace = workspace;
1177 * Do application specific stuff, like setting application
1178 * wide attributes.
1181 if (wwin->flags.hidden) {
1182 /* if the window was set to hidden because it was hidden
1183 * in a previous incarnation and that state was restored */
1184 app->flags.hidden = 1;
1185 } else if (app->flags.hidden) {
1186 if (WFLAGP(app->main_window_desc, start_hidden)) {
1187 wwin->flags.hidden = 1;
1188 } else {
1189 wUnhideApplication(app, False, False);
1190 raise = True;
1193 wAppBounce(app);
1197 /* setup the frame descriptor */
1198 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1199 wwin->frame->core->descriptor.parent = wwin;
1200 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1202 /* don't let windows go away if we die */
1203 XAddToSaveSet(dpy, window);
1205 XLowerWindow(dpy, window);
1207 /* if window is in this workspace and should be mapped, then map it */
1208 if (!wwin->flags.miniaturized && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1209 && !wwin->flags.hidden && !withdraw) {
1211 /* The following "if" is to avoid crashing of clients that expect
1212 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1213 * after the return from this function.
1215 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint))
1216 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1217 else
1218 wClientSetState(wwin, NormalState, None);
1220 if (wPreferences.superfluous && !wPreferences.no_animations && !scr->flags.startup &&
1221 (wwin->transient_for == None || wwin->transient_for == scr->root_win) &&
1223 * The brain damaged idiotic non-click to focus modes will
1224 * have trouble with this because:
1226 * 1. window is created and mapped by the client
1227 * 2. window is mapped by wmaker in small size
1228 * 3. window is animated to grow to normal size
1229 * 4. this function returns to normal event loop
1230 * 5. eventually, the EnterNotify event that would trigger
1231 * the window focusing (if the mouse is over that window)
1232 * will be processed by wmaker.
1233 * But since this event will be rather delayed
1234 * (step 3 has a large delay) the time when the event ocurred
1235 * and when it is processed, the client that owns that window
1236 * will reject the XSetInputFocus() for it.
1238 (wPreferences.focus_mode == WKF_CLICK || wPreferences.auto_focus))
1239 DoWindowBirth(wwin);
1241 wWindowMap(wwin);
1244 /* setup stacking descriptor */
1245 if (transientOwner)
1246 wwin->frame->core->stacking->child_of = transientOwner->frame->core;
1247 else
1248 wwin->frame->core->stacking->child_of = NULL;
1250 if (!scr->focused_window) {
1251 /* first window on the list */
1252 wwin->next = NULL;
1253 wwin->prev = NULL;
1254 scr->focused_window = wwin;
1255 } else {
1256 WWindow *tmp;
1258 /* add window at beginning of focus window list */
1259 tmp = scr->focused_window;
1260 while (tmp->prev)
1261 tmp = tmp->prev;
1262 tmp->prev = wwin;
1263 wwin->next = tmp;
1264 wwin->prev = NULL;
1267 /* raise is set to true if we un-hid the app when this window was born.
1268 * we raise, else old windows of this app will be above this new one. */
1269 if (raise)
1270 wRaiseFrame(wwin->frame->core);
1272 /* Update name must come after WApplication stuff is done */
1273 wWindowUpdateName(wwin, title);
1274 if (title)
1275 XFree(title);
1277 XUngrabServer(dpy);
1280 * Final preparations before window is ready to go
1282 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1284 if (!wwin->flags.miniaturized && workspace == scr->current_workspace && !wwin->flags.hidden) {
1285 if (((transientOwner && transientOwner->flags.focused)
1286 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable)) {
1288 /* only auto_focus if on same screen as mouse
1289 * (and same head for xinerama mode)
1290 * TODO: make it an option */
1292 /*TODO add checking the head of the window, is it available? */
1293 short same_screen = 0, same_head = 1;
1295 int foo;
1296 unsigned int bar;
1297 Window dummy;
1299 if (XQueryPointer(dpy, scr->root_win, &dummy, &dummy,
1300 &foo, &foo, &foo, &foo, &bar) != False)
1301 same_screen = 1;
1303 if (same_screen == 1 && same_head == 1)
1304 wSetFocusTo(scr, wwin);
1307 wWindowResetMouseGrabs(wwin);
1309 if (!WFLAGP(wwin, no_bind_keys))
1310 wWindowSetKeyGrabs(wwin);
1312 WMPostNotificationName(WMNManaged, wwin, NULL);
1313 wColormapInstallForWindow(scr, scr->cmap_window);
1315 /* Setup Notification Observers */
1316 WMAddNotificationObserver(appearanceObserver, wwin, WNWindowAppearanceSettingsChanged, wwin);
1318 /* Cleanup temporary stuff */
1319 if (win_state)
1320 wWindowDeleteSavedState(win_state);
1322 /* If the window must be withdrawed, then do it now.
1323 * Must do some optimization, 'though */
1324 if (withdraw) {
1325 wwin->flags.mapped = 0;
1326 wClientSetState(wwin, WithdrawnState, None);
1327 wUnmanageWindow(wwin, True, False);
1328 wwin = NULL;
1331 return wwin;
1334 WWindow *wManageInternalWindow(WScreen *scr, Window window, Window owner,
1335 char *title, int x, int y, int width, int height)
1337 WWindow *wwin;
1338 int foo;
1340 wwin = wWindowCreate();
1342 WMAddNotificationObserver(appearanceObserver, wwin, WNWindowAppearanceSettingsChanged, wwin);
1344 wwin->flags.internal_window = 1;
1346 WSETUFLAG(wwin, omnipresent, 1);
1347 WSETUFLAG(wwin, no_shadeable, 1);
1348 WSETUFLAG(wwin, no_resizable, 1);
1349 WSETUFLAG(wwin, no_miniaturizable, 1);
1351 wwin->focus_mode = WFM_PASSIVE;
1352 wwin->client_win = window;
1353 wwin->screen_ptr = scr;
1354 wwin->transient_for = owner;
1355 wwin->client.x = x;
1356 wwin->client.y = y;
1357 wwin->client.width = width;
1358 wwin->client.height = height;
1359 wwin->frame_x = wwin->client.x;
1360 wwin->frame_y = wwin->client.y;
1362 foo = WFF_RIGHT_BUTTON | WFF_BORDER;
1363 foo |= WFF_TITLEBAR;
1364 #ifdef XKB_BUTTON_HINT
1365 foo |= WFF_LANGUAGE_BUTTON;
1366 #endif
1368 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1369 wwin->frame_x, wwin->frame_y,
1370 width, height,
1371 &wPreferences.window_title_clearance,
1372 &wPreferences.window_title_min_height,
1373 &wPreferences.window_title_max_height,
1374 foo,
1375 scr->window_title_texture,
1376 scr->resizebar_texture, scr->window_title_color, &scr->title_font);
1378 XSaveContext(dpy, window, wWinContext, (XPointer) & wwin->client_descriptor);
1380 wwin->frame->flags.is_client_window_frame = 1;
1381 wwin->frame->flags.justification = wPreferences.title_justification;
1383 wFrameWindowChangeTitle(wwin->frame, title);
1385 /* setup button images */
1386 wWindowUpdateButtonImages(wwin);
1388 /* hide buttons */
1389 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
1391 wwin->frame->child = wwin;
1392 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
1394 #ifdef XKB_BUTTON_HINT
1395 if (wPreferences.modelock)
1396 wwin->frame->on_click_language = windowLanguageClick;
1397 #endif
1399 wwin->frame->on_click_right = windowCloseClick;
1400 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1401 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
1402 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1403 wwin->client.y += wwin->frame->top_width;
1405 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window, 0, wwin->frame->top_width);
1406 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, wwin->client.width, wwin->client.height);
1408 /* setup the frame descriptor */
1409 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1410 wwin->frame->core->descriptor.parent = wwin;
1411 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1413 XLowerWindow(dpy, window);
1414 XMapSubwindows(dpy, wwin->frame->core->window);
1416 /* setup stacking descriptor */
1417 if (wwin->transient_for != None && wwin->transient_for != scr->root_win) {
1418 WWindow *tmp;
1419 tmp = wWindowFor(wwin->transient_for);
1420 if (tmp)
1421 wwin->frame->core->stacking->child_of = tmp->frame->core;
1422 } else {
1423 wwin->frame->core->stacking->child_of = NULL;
1426 if (!scr->focused_window) {
1427 /* first window on the list */
1428 wwin->next = NULL;
1429 wwin->prev = NULL;
1430 scr->focused_window = wwin;
1431 } else {
1432 WWindow *tmp;
1434 /* add window at beginning of focus window list */
1435 tmp = scr->focused_window;
1436 while (tmp->prev)
1437 tmp = tmp->prev;
1438 tmp->prev = wwin;
1439 wwin->next = tmp;
1440 wwin->prev = NULL;
1443 if (wwin->flags.is_gnustep == 0)
1444 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1446 /* if (wPreferences.auto_focus) */
1447 wSetFocusTo(scr, wwin);
1448 wWindowResetMouseGrabs(wwin);
1449 wWindowSetKeyGrabs(wwin);
1451 return wwin;
1455 *----------------------------------------------------------------------
1456 * wUnmanageWindow--
1457 * Removes the frame window from a window and destroys all data
1458 * related to it. The window will be reparented back to the root window
1459 * if restore is True.
1461 * Side effects:
1462 * Everything related to the window is destroyed and the window
1463 * is removed from the window lists. Focus is set to the previous on the
1464 * window list.
1465 *----------------------------------------------------------------------
1467 void 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;
1475 /* First close attribute editor window if open */
1476 if (wwin->flags.inspector_open)
1477 wCloseInspectorForWindow(wwin);
1479 /* Close window menu if it's open for this window */
1480 if (wwin->flags.menu_open_for_me)
1481 CloseWindowMenu(scr);
1483 if (!destroyed) {
1484 if (!wwin->flags.internal_window)
1485 XRemoveFromSaveSet(dpy, wwin->client_win);
1487 /* If this is a leader window, we still need to listen for
1488 * DestroyNotify and PropertyNotify. */
1489 if (wApplicationOf(wwin->client_win))
1490 XSelectInput(dpy, wwin->client_win, StructureNotifyMask | PropertyChangeMask);
1491 else
1492 XSelectInput(dpy, wwin->client_win, NoEventMask);
1494 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1495 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1498 XUnmapWindow(dpy, frame->window);
1500 XUnmapWindow(dpy, wwin->client_win);
1502 /* deselect window */
1503 wSelectWindow(wwin, False);
1505 /* remove all pending events on window */
1506 /* I think this only matters for autoraise */
1507 if (wPreferences.raise_delay)
1508 WMDeleteTimerWithClientData(wwin->frame->core);
1510 XFlush(dpy);
1512 /* reparent the window back to the root */
1513 if (restore)
1514 wClientRestore(wwin);
1516 if (wwin->transient_for != scr->root_win) {
1517 owner = wWindowFor(wwin->transient_for);
1518 if (owner) {
1519 if (!owner->flags.semi_focused)
1520 owner = NULL;
1521 else
1522 owner->flags.semi_focused = 0;
1526 wasFocused = wwin->flags.focused;
1528 /* remove from window focus list */
1529 if (!wwin->prev && !wwin->next) {
1530 /* was the only window */
1531 scr->focused_window = NULL;
1532 newFocusedWindow = NULL;
1533 } else {
1534 WWindow *tmp;
1536 if (wwin->prev)
1537 wwin->prev->next = wwin->next;
1539 if (wwin->next)
1540 wwin->next->prev = wwin->prev;
1541 else {
1542 scr->focused_window = wwin->prev;
1543 scr->focused_window->next = NULL;
1546 if (wPreferences.focus_mode == WKF_CLICK) {
1548 /* if in click to focus mode and the window
1549 * was a transient, focus the owner window
1551 tmp = NULL;
1552 if (wPreferences.focus_mode == WKF_CLICK) {
1553 tmp = wWindowFor(wwin->transient_for);
1554 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1555 tmp = NULL;
1558 /* otherwise, focus the next one in the focus list */
1559 if (!tmp) {
1560 tmp = scr->focused_window;
1561 while (tmp) { /* look for one in the window list first */
1562 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1563 && (tmp->flags.mapped || tmp->flags.shaded))
1564 break;
1565 tmp = tmp->prev;
1567 if (!tmp) { /* if unsuccessful, choose any focusable window */
1568 tmp = scr->focused_window;
1569 while (tmp) {
1570 if (!WFLAGP(tmp, no_focusable)
1571 && (tmp->flags.mapped || tmp->flags.shaded))
1572 break;
1573 tmp = tmp->prev;
1578 newFocusedWindow = tmp;
1580 } else if (wPreferences.focus_mode == WKF_SLOPPY) {
1581 unsigned int mask;
1582 int foo;
1583 Window bar, win;
1585 /* This is to let the root window get the keyboard input
1586 * if Sloppy focus mode and no other window get focus.
1587 * This way keybindings will not freeze.
1589 tmp = NULL;
1590 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1591 tmp = wWindowFor(win);
1592 if (tmp == wwin)
1593 tmp = NULL;
1594 newFocusedWindow = tmp;
1595 } else {
1596 newFocusedWindow = NULL;
1600 if (!wwin->flags.internal_window)
1601 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
1602 if (wasFocused) {
1603 if (newFocusedWindow != owner && owner) {
1604 if (wwin->flags.is_gnustep == 0)
1605 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1607 wSetFocusTo(scr, newFocusedWindow);
1610 /* Close menu and unhighlight */
1611 WApplication *oapp = wApplicationOf(wwin->main_window);
1612 WApplication *napp = scr->focused_window ? wApplicationOf(scr->focused_window->main_window) : NULL;
1613 if (oapp && oapp != napp) {
1614 wAppMenuUnmap(oapp->menu);
1615 wApplicationDeactivate(oapp);
1618 wWindowDestroy(wwin);
1619 XFlush(dpy);
1622 void wWindowMap(WWindow *wwin)
1624 XMapWindow(dpy, wwin->frame->core->window);
1625 if (!wwin->flags.shaded) {
1626 /* window will be remapped when getting MapNotify */
1627 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
1628 XMapWindow(dpy, wwin->client_win);
1629 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1631 wwin->flags.mapped = 1;
1635 void wWindowUnmap(WWindow *wwin)
1637 wwin->flags.mapped = 0;
1639 /* prevent window withdrawal when getting UnmapNotify */
1640 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
1641 XUnmapWindow(dpy, wwin->client_win);
1642 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1644 XUnmapWindow(dpy, wwin->frame->core->window);
1647 void wWindowFocus(WWindow *wwin, WWindow *owin)
1649 WWindow *nowner;
1650 WWindow *oowner;
1652 #ifdef KEEP_XKB_LOCK_STATUS
1653 if (wPreferences.modelock)
1654 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1655 #endif /* KEEP_XKB_LOCK_STATUS */
1657 wwin->flags.semi_focused = 0;
1659 if (wwin->flags.is_gnustep == 0)
1660 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1662 wwin->flags.focused = 1;
1664 wWindowResetMouseGrabs(wwin);
1666 WMPostNotificationName(WMNChangedFocus, wwin, (void *)True);
1668 if (owin == wwin || !owin)
1669 return;
1671 nowner = wWindowFor(wwin->transient_for);
1673 /* new window is a transient for the old window */
1674 if (nowner == owin) {
1675 owin->flags.semi_focused = 1;
1676 wWindowUnfocus(nowner);
1677 return;
1680 oowner = wWindowFor(owin->transient_for);
1682 /* new window is owner of old window */
1683 if (wwin == oowner) {
1684 wWindowUnfocus(owin);
1685 return;
1688 if (!nowner) {
1689 wWindowUnfocus(owin);
1690 return;
1693 /* new window has same owner of old window */
1694 if (oowner == nowner) {
1695 /* prevent unfocusing of owner */
1696 oowner->flags.semi_focused = 0;
1697 wWindowUnfocus(owin);
1698 oowner->flags.semi_focused = 1;
1700 return;
1703 /* nowner != NULL && oowner != nowner */
1704 nowner->flags.semi_focused = 1;
1705 wWindowUnfocus(nowner);
1706 wWindowUnfocus(owin);
1709 void wWindowUnfocus(WWindow *wwin)
1711 CloseWindowMenu(wwin->screen_ptr);
1713 if (wwin->flags.is_gnustep == 0)
1714 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused ? WS_PFOCUSED : WS_UNFOCUSED);
1716 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1717 WWindow *owner;
1718 owner = wWindowFor(wwin->transient_for);
1719 if (owner && owner->flags.semi_focused) {
1720 owner->flags.semi_focused = 0;
1721 if (owner->flags.mapped || owner->flags.shaded) {
1722 wWindowUnfocus(owner);
1723 wFrameWindowPaint(owner->frame);
1727 wwin->flags.focused = 0;
1728 wWindowResetMouseGrabs(wwin);
1729 WMPostNotificationName(WMNChangedFocus, wwin, (void *)False);
1732 void wWindowUpdateName(WWindow *wwin, char *newTitle)
1734 char *title;
1736 if (!wwin->frame)
1737 return;
1739 if (!newTitle)
1740 title = DEF_WINDOW_TITLE; /* the hint was removed */
1741 else
1742 title = newTitle;
1744 if (wFrameWindowChangeTitle(wwin->frame, title))
1745 WMPostNotificationName(WMNChangedName, wwin, NULL);
1749 *----------------------------------------------------------------------
1751 * wWindowConstrainSize--
1752 * Constrains size for the client window, taking the maximal size,
1753 * window resize increments and other size hints into account.
1755 * Returns:
1756 * The closest size to what was given that the client window can
1757 * have.
1759 *----------------------------------------------------------------------
1761 void wWindowConstrainSize(WWindow *wwin, unsigned int *nwidth, unsigned int *nheight)
1763 int width = (int)*nwidth;
1764 int height = (int)*nheight;
1765 int winc = 1;
1766 int hinc = 1;
1767 int minW = 1, minH = 1;
1768 int maxW = wwin->screen_ptr->scr_width * 2;
1769 int maxH = wwin->screen_ptr->scr_height * 2;
1770 int minAX = -1, minAY = -1;
1771 int maxAX = -1, maxAY = -1;
1772 int baseW = 0;
1773 int baseH = 0;
1775 if (wwin->normal_hints) {
1776 winc = wwin->normal_hints->width_inc;
1777 hinc = wwin->normal_hints->height_inc;
1778 minW = wwin->normal_hints->min_width;
1779 minH = wwin->normal_hints->min_height;
1780 maxW = wwin->normal_hints->max_width;
1781 maxH = wwin->normal_hints->max_height;
1782 if (wwin->normal_hints->flags & PAspect) {
1783 minAX = wwin->normal_hints->min_aspect.x;
1784 minAY = wwin->normal_hints->min_aspect.y;
1785 maxAX = wwin->normal_hints->max_aspect.x;
1786 maxAY = wwin->normal_hints->max_aspect.y;
1789 baseW = wwin->normal_hints->base_width;
1790 baseH = wwin->normal_hints->base_height;
1793 if (width < minW)
1794 width = minW;
1795 if (height < minH)
1796 height = minH;
1798 if (width > maxW)
1799 width = maxW;
1800 if (height > maxH)
1801 height = maxH;
1803 /* aspect ratio code borrowed from olwm */
1804 if (minAX > 0) {
1805 /* adjust max aspect ratio */
1806 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1807 if (maxAX > maxAY) {
1808 height = (width * maxAY) / maxAX;
1809 if (height > maxH) {
1810 height = maxH;
1811 width = (height * maxAX) / maxAY;
1813 } else {
1814 width = (height * maxAX) / maxAY;
1815 if (width > maxW) {
1816 width = maxW;
1817 height = (width * maxAY) / maxAX;
1822 /* adjust min aspect ratio */
1823 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1824 if (minAX > minAY) {
1825 height = (width * minAY) / minAX;
1826 if (height < minH) {
1827 height = minH;
1828 width = (height * minAX) / minAY;
1830 } else {
1831 width = (height * minAX) / minAY;
1832 if (width < minW) {
1833 width = minW;
1834 height = (width * minAY) / minAX;
1840 if (baseW != 0)
1841 width = (((width - baseW) / winc) * winc) + baseW;
1842 else
1843 width = (((width - minW) / winc) * winc) + minW;
1845 if (baseH != 0)
1846 height = (((height - baseH) / hinc) * hinc) + baseH;
1847 else
1848 height = (((height - minH) / hinc) * hinc) + minH;
1850 /* broken stupid apps may cause preposterous values for these.. */
1851 if (width > 0)
1852 *nwidth = width;
1853 if (height > 0)
1854 *nheight = height;
1857 void wWindowCropSize(WWindow *wwin, unsigned int maxW, unsigned int maxH,
1858 unsigned int *width, unsigned int *height)
1860 int baseW = 0, baseH = 0;
1861 int winc = 1, hinc = 1;
1863 if (wwin->normal_hints) {
1864 baseW = wwin->normal_hints->base_width;
1865 baseH = wwin->normal_hints->base_height;
1867 winc = wwin->normal_hints->width_inc;
1868 hinc = wwin->normal_hints->height_inc;
1871 if (*width > maxW)
1872 *width = maxW - (maxW - baseW) % winc;
1874 if (*height > maxH)
1875 *height = maxH - (maxH - baseH) % hinc;
1878 void wWindowChangeWorkspace(WWindow *wwin, int workspace)
1880 WScreen *scr = wwin->screen_ptr;
1881 WApplication *wapp;
1882 int unmap = 0;
1884 if (workspace >= scr->workspace_count || workspace < 0 || workspace == wwin->frame->workspace)
1885 return;
1887 if (workspace != scr->current_workspace) {
1888 /* Sent to other workspace. Unmap window */
1889 if ((wwin->flags.mapped
1890 || wwin->flags.shaded || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1891 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1893 wapp = wApplicationOf(wwin->main_window);
1894 if (wapp)
1895 wapp->last_workspace = workspace;
1897 if (wwin->flags.miniaturized) {
1898 if (wwin->icon) {
1899 XUnmapWindow(dpy, wwin->icon->core->window);
1900 wwin->icon->mapped = 0;
1902 } else {
1903 unmap = 1;
1904 wSetFocusTo(scr, NULL);
1907 } else {
1908 /* brought to current workspace. Map window */
1909 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1910 if (wwin->icon) {
1911 XMapWindow(dpy, wwin->icon->core->window);
1912 wwin->icon->mapped = 1;
1914 } else if (!wwin->flags.mapped && !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1915 wWindowMap(wwin);
1918 if (!IS_OMNIPRESENT(wwin)) {
1919 int oldWorkspace = wwin->frame->workspace;
1920 wwin->frame->workspace = workspace;
1921 WMPostNotificationName(WMNChangedWorkspace, wwin, (void *)(uintptr_t) oldWorkspace);
1924 if (unmap)
1925 wWindowUnmap(wwin);
1928 void wWindowSynthConfigureNotify(WWindow *wwin)
1930 XEvent sevent;
1932 sevent.type = ConfigureNotify;
1933 sevent.xconfigure.display = dpy;
1934 sevent.xconfigure.event = wwin->client_win;
1935 sevent.xconfigure.window = wwin->client_win;
1937 sevent.xconfigure.x = wwin->client.x;
1938 sevent.xconfigure.y = wwin->client.y;
1939 sevent.xconfigure.width = wwin->client.width;
1940 sevent.xconfigure.height = wwin->client.height;
1942 sevent.xconfigure.border_width = wwin->old_border_width;
1943 if (HAS_TITLEBAR(wwin) && wwin->frame->titlebar)
1944 sevent.xconfigure.above = wwin->frame->titlebar->window;
1945 else
1946 sevent.xconfigure.above = None;
1948 sevent.xconfigure.override_redirect = False;
1949 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
1950 XFlush(dpy);
1954 *----------------------------------------------------------------------
1955 * wWindowConfigure()
1957 * req_x, req_y: new requested positions for the frame
1958 * req_width, req_height: new requested sizes for the client
1960 * Configures the frame, decorations and client window to the specified
1961 * geometry, whose validity is not checked -- wWindowConstrainSize()
1962 * must be used for that.
1963 * The size parameters are for the client window, but the position is
1964 * for the frame.
1965 * The client window receives a ConfigureNotify event, according
1966 * to what ICCCM says.
1968 * Returns:
1969 * None
1971 * Side effects:
1972 * Window size and position are changed and client window receives
1973 * a ConfigureNotify event.
1974 *----------------------------------------------------------------------
1976 void wWindowConfigure(WWindow *wwin, int req_x, int req_y, int req_width, int req_height)
1978 int synth_notify = False;
1979 int resize;
1981 resize = (req_width != wwin->client.width || req_height != wwin->client.height);
1983 * if the window is being moved but not resized then
1984 * send a synthetic ConfigureNotify
1986 if ((req_x != wwin->frame_x || req_y != wwin->frame_y) && !resize)
1987 synth_notify = True;
1989 if (WFLAGP(wwin, dont_move_off))
1990 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y, req_width, req_height);
1992 if (resize) {
1993 if (req_width < MIN_WINDOW_SIZE)
1994 req_width = MIN_WINDOW_SIZE;
1995 if (req_height < MIN_WINDOW_SIZE)
1996 req_height = MIN_WINDOW_SIZE;
1998 /* If growing, resize inner part before frame,
1999 * if shrinking, resize frame before.
2000 * This will prevent the frame (that can have a different color)
2001 * to be exposed, causing flicker */
2002 if (req_height > wwin->frame->core->height || req_width > wwin->frame->core->width)
2003 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2005 if (wwin->flags.shaded) {
2006 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, wwin->frame->core->height);
2007 wwin->old_geometry.height = req_height;
2008 } else {
2009 int h;
2011 h = req_height + wwin->frame->top_width + wwin->frame->bottom_width;
2013 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2016 if (!(req_height > wwin->frame->core->height || req_width > wwin->frame->core->width))
2017 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2019 wwin->client.x = req_x;
2020 wwin->client.y = req_y + wwin->frame->top_width;
2021 wwin->client.width = req_width;
2022 wwin->client.height = req_height;
2023 } else {
2024 wwin->client.x = req_x;
2025 wwin->client.y = req_y + wwin->frame->top_width;
2027 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2029 wwin->frame_x = req_x;
2030 wwin->frame_y = req_y;
2031 if (HAS_BORDER(wwin)) {
2032 wwin->client.x += FRAME_BORDER_WIDTH;
2033 wwin->client.y += FRAME_BORDER_WIDTH;
2035 #ifdef SHAPE
2036 if (wShapeSupported && wwin->flags.shaped && resize)
2037 wWindowSetShape(wwin);
2038 #endif
2040 if (synth_notify)
2041 wWindowSynthConfigureNotify(wwin);
2043 wNETFrameExtents(wwin);
2045 XFlush(dpy);
2048 /* req_x, req_y: new position of the frame */
2049 void wWindowMove(WWindow *wwin, int req_x, int req_y)
2051 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2052 int synth_notify = False;
2054 /* Send a synthetic ConfigureNotify event for every window movement. */
2055 if ((req_x != wwin->frame_x || req_y != wwin->frame_y))
2056 synth_notify = True;
2057 #else
2058 /* A single synthetic ConfigureNotify event is sent at the end of
2059 * a completed (opaque) movement in moveres.c */
2060 #endif
2062 if (WFLAGP(wwin, dont_move_off))
2063 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2064 wwin->frame->core->width, wwin->frame->core->height);
2066 wwin->client.x = req_x;
2067 wwin->client.y = req_y + wwin->frame->top_width;
2068 if (HAS_BORDER(wwin)) {
2069 wwin->client.x += FRAME_BORDER_WIDTH;
2070 wwin->client.y += FRAME_BORDER_WIDTH;
2073 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2075 wwin->frame_x = req_x;
2076 wwin->frame_y = req_y;
2078 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2079 if (synth_notify)
2080 wWindowSynthConfigureNotify(wwin);
2081 #endif
2084 void wWindowUpdateButtonImages(WWindow *wwin)
2086 WScreen *scr = wwin->screen_ptr;
2087 Pixmap pixmap, mask;
2088 WFrameWindow *fwin = wwin->frame;
2090 if (!HAS_TITLEBAR(wwin))
2091 return;
2093 /* miniaturize button */
2094 if (!WFLAGP(wwin, no_miniaturize_button)) {
2095 if (wwin->wm_gnustep_attr && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2096 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2098 if (wwin->wm_gnustep_attr->flags & GSMiniaturizeMaskAttr)
2099 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2100 else
2101 mask = None;
2103 if (fwin->lbutton_image
2104 && (fwin->lbutton_image->image != pixmap || fwin->lbutton_image->mask != mask)) {
2105 wPixmapDestroy(fwin->lbutton_image);
2106 fwin->lbutton_image = NULL;
2109 if (!fwin->lbutton_image) {
2110 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2111 fwin->lbutton_image->client_owned = 1;
2112 fwin->lbutton_image->client_owned_mask = 1;
2114 } else {
2115 if (fwin->lbutton_image && !fwin->lbutton_image->shared)
2116 wPixmapDestroy(fwin->lbutton_image);
2118 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2121 #ifdef XKB_BUTTON_HINT
2122 if (!WFLAGP(wwin, no_language_button)) {
2123 if (fwin->languagebutton_image && !fwin->languagebutton_image->shared)
2124 wPixmapDestroy(fwin->languagebutton_image);
2126 fwin->languagebutton_image = scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2128 #endif
2130 /* close button */
2132 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2133 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2135 if (!WFLAGP(wwin, no_close_button)) {
2136 if (wwin->wm_gnustep_attr && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2137 pixmap = wwin->wm_gnustep_attr->close_pixmap;
2139 if (wwin->wm_gnustep_attr->flags & GSCloseMaskAttr)
2140 mask = wwin->wm_gnustep_attr->close_mask;
2141 else
2142 mask = None;
2144 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2145 || fwin->rbutton_image->mask != mask)) {
2146 wPixmapDestroy(fwin->rbutton_image);
2147 fwin->rbutton_image = NULL;
2150 if (!fwin->rbutton_image) {
2151 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2152 fwin->rbutton_image->client_owned = 1;
2153 fwin->rbutton_image->client_owned_mask = 1;
2156 } else if (WFLAGP(wwin, kill_close)) {
2157 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2158 wPixmapDestroy(fwin->rbutton_image);
2160 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
2162 } else if (MGFLAGP(wwin, broken_close)) {
2163 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2164 wPixmapDestroy(fwin->rbutton_image);
2166 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
2168 } else {
2169 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2170 wPixmapDestroy(fwin->rbutton_image);
2172 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2176 /* force buttons to be redrawn */
2177 fwin->flags.need_texture_change = 1;
2178 wFrameWindowPaint(fwin);
2182 *---------------------------------------------------------------------------
2183 * wWindowConfigureBorders--
2184 * Update window border configuration according to attribute flags.
2186 *---------------------------------------------------------------------------
2188 void wWindowConfigureBorders(WWindow *wwin)
2190 if (wwin->frame) {
2191 int flags;
2192 int newy, oldh;
2194 flags = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
2196 #ifdef XKB_BUTTON_HINT
2197 if (wPreferences.modelock)
2198 flags |= WFF_LANGUAGE_BUTTON;
2199 #endif
2201 if (HAS_TITLEBAR(wwin))
2202 flags |= WFF_TITLEBAR;
2203 if (HAS_RESIZEBAR(wwin) && IS_RESIZABLE(wwin))
2204 flags |= WFF_RESIZEBAR;
2205 if (HAS_BORDER(wwin))
2206 flags |= WFF_BORDER;
2207 if (wwin->flags.shaded)
2208 flags |= WFF_IS_SHADED;
2210 oldh = wwin->frame->top_width;
2211 wFrameWindowUpdateBorders(wwin->frame, flags);
2212 if (oldh != wwin->frame->top_width) {
2213 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2215 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2216 wWindowConfigure(wwin, wwin->frame_x, newy, wwin->client.width, wwin->client.height);
2219 flags = 0;
2220 if (!WFLAGP(wwin, no_miniaturize_button)
2221 && wwin->frame->flags.hide_left_button)
2222 flags |= WFF_LEFT_BUTTON;
2224 #ifdef XKB_BUTTON_HINT
2225 if (!WFLAGP(wwin, no_language_button)
2226 && wwin->frame->flags.hide_language_button)
2227 flags |= WFF_LANGUAGE_BUTTON;
2228 #endif
2230 if (!WFLAGP(wwin, no_close_button)
2231 && wwin->frame->flags.hide_right_button)
2232 flags |= WFF_RIGHT_BUTTON;
2234 if (flags != 0) {
2235 wWindowUpdateButtonImages(wwin);
2236 wFrameWindowShowButton(wwin->frame, flags);
2239 flags = 0;
2240 if (WFLAGP(wwin, no_miniaturize_button)
2241 && !wwin->frame->flags.hide_left_button)
2242 flags |= WFF_LEFT_BUTTON;
2244 #ifdef XKB_BUTTON_HINT
2245 if (WFLAGP(wwin, no_language_button)
2246 && !wwin->frame->flags.hide_language_button)
2247 flags |= WFF_LANGUAGE_BUTTON;
2248 #endif
2250 if (WFLAGP(wwin, no_close_button)
2251 && !wwin->frame->flags.hide_right_button)
2252 flags |= WFF_RIGHT_BUTTON;
2254 if (flags != 0)
2255 wFrameWindowHideButton(wwin->frame, flags);
2257 #ifdef SHAPE
2258 if (wShapeSupported && wwin->flags.shaped)
2259 wWindowSetShape(wwin);
2260 #endif
2264 void wWindowSaveState(WWindow * wwin)
2266 long data[10];
2267 int i;
2269 memset(data, 0, sizeof(long) * 10);
2270 data[0] = wwin->frame->workspace;
2271 data[1] = wwin->flags.miniaturized;
2272 data[2] = wwin->flags.shaded;
2273 data[3] = wwin->flags.hidden;
2274 data[4] = wwin->flags.maximized;
2275 if (wwin->flags.maximized == 0) {
2276 data[5] = wwin->frame_x;
2277 data[6] = wwin->frame_y;
2278 data[7] = wwin->frame->core->width;
2279 data[8] = wwin->frame->core->height;
2280 } else {
2281 data[5] = wwin->old_geometry.x;
2282 data[6] = wwin->old_geometry.y;
2283 data[7] = wwin->old_geometry.width;
2284 data[8] = wwin->old_geometry.height;
2287 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2288 if (wwin->screen_ptr->shortcutWindows[i] &&
2289 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2290 data[9] |= 1 << i;
2292 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2293 _XA_WINDOWMAKER_STATE, 32, PropModeReplace, (unsigned char *)data, 10);
2296 static int getSavedState(Window window, WSavedState ** state)
2298 Atom type_ret;
2299 int fmt_ret;
2300 unsigned long nitems_ret;
2301 unsigned long bytes_after_ret;
2302 long *data;
2304 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2305 True, _XA_WINDOWMAKER_STATE,
2306 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
2307 (unsigned char **)&data) != Success || !data || nitems_ret < 10)
2308 return 0;
2310 *state = wmalloc(sizeof(WSavedState));
2312 (*state)->workspace = data[0];
2313 (*state)->miniaturized = data[1];
2314 (*state)->shaded = data[2];
2315 (*state)->hidden = data[3];
2316 (*state)->maximized = data[4];
2317 (*state)->x = data[5];
2318 (*state)->y = data[6];
2319 (*state)->w = data[7];
2320 (*state)->h = data[8];
2321 (*state)->window_shortcuts = data[9];
2323 XFree(data);
2325 if (*state && type_ret == _XA_WINDOWMAKER_STATE)
2326 return 1;
2327 else
2328 return 0;
2331 #ifdef SHAPE
2332 void wWindowClearShape(WWindow * wwin)
2334 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2335 0, wwin->frame->top_width, None, ShapeSet);
2336 XFlush(dpy);
2339 void wWindowSetShape(WWindow * wwin)
2341 XRectangle rect[2];
2342 int count;
2343 #ifdef OPTIMIZE_SHAPE
2344 XRectangle *rects;
2345 XRectangle *urec;
2346 int ordering;
2348 /* only shape is the client's */
2349 if (!HAS_TITLEBAR(wwin) && !HAS_RESIZEBAR(wwin))
2350 goto alt_code;
2352 /* Get array of rectangles describing the shape mask */
2353 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding, &count, &ordering);
2354 if (!rects)
2355 goto alt_code;
2357 urec = malloc(sizeof(XRectangle) * (count + 2));
2358 if (!urec) {
2359 XFree(rects);
2360 goto alt_code;
2363 /* insert our decoration rectangles in the rect list */
2364 memcpy(urec, rects, sizeof(XRectangle) * count);
2365 XFree(rects);
2367 if (HAS_TITLEBAR(wwin)) {
2368 urec[count].x = -1;
2369 urec[count].y = -1 - wwin->frame->top_width;
2370 urec[count].width = wwin->frame->core->width + 2;
2371 urec[count].height = wwin->frame->top_width + 1;
2372 count++;
2374 if (HAS_RESIZEBAR(wwin)) {
2375 urec[count].x = -1;
2376 urec[count].y = wwin->frame->core->height - wwin->frame->bottom_width - wwin->frame->top_width;
2377 urec[count].width = wwin->frame->core->width + 2;
2378 urec[count].height = wwin->frame->bottom_width + 1;
2379 count++;
2382 /* shape our frame window */
2383 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2384 0, wwin->frame->top_width, urec, count, ShapeSet, Unsorted);
2385 XFlush(dpy);
2386 wfree(urec);
2387 return;
2389 alt_code:
2390 #endif /* OPTIMIZE_SHAPE */
2391 count = 0;
2392 if (HAS_TITLEBAR(wwin)) {
2393 rect[count].x = -1;
2394 rect[count].y = -1;
2395 rect[count].width = wwin->frame->core->width + 2;
2396 rect[count].height = wwin->frame->top_width + 1;
2397 count++;
2399 if (HAS_RESIZEBAR(wwin)) {
2400 rect[count].x = -1;
2401 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2402 rect[count].width = wwin->frame->core->width + 2;
2403 rect[count].height = wwin->frame->bottom_width + 1;
2404 count++;
2406 if (count > 0) {
2407 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2408 0, 0, rect, count, ShapeSet, Unsorted);
2410 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2411 0, wwin->frame->top_width, wwin->client_win,
2412 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2413 XFlush(dpy);
2415 #endif /* SHAPE */
2417 /* ====================================================================== */
2419 static FocusMode getFocusMode(WWindow * wwin)
2421 FocusMode mode;
2423 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2424 if (wwin->wm_hints->input == True) {
2425 if (wwin->protocols.TAKE_FOCUS)
2426 mode = WFM_LOCALLY_ACTIVE;
2427 else
2428 mode = WFM_PASSIVE;
2429 } else {
2430 if (wwin->protocols.TAKE_FOCUS)
2431 mode = WFM_GLOBALLY_ACTIVE;
2432 else
2433 mode = WFM_NO_INPUT;
2435 } else {
2436 mode = WFM_PASSIVE;
2438 return mode;
2441 void wWindowSetKeyGrabs(WWindow * wwin)
2443 int i;
2444 WShortKey *key;
2446 for (i = 0; i < WKBD_LAST; i++) {
2447 key = &wKeyBindings[i];
2449 if (key->keycode == 0)
2450 continue;
2451 if (key->modifier != AnyModifier) {
2452 XGrabKey(dpy, key->keycode, key->modifier | LockMask,
2453 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2454 #ifdef NUMLOCK_HACK
2455 /* Also grab all modifier combinations possible that include,
2456 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2457 * work even if the NumLock/ScrollLock key is on.
2459 wHackedGrabKey(key->keycode, key->modifier,
2460 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2461 #endif
2463 XGrabKey(dpy, key->keycode, key->modifier,
2464 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2467 wRootMenuBindShortcuts(wwin->frame->core->window);
2470 void wWindowResetMouseGrabs(WWindow * wwin)
2472 /* Mouse grabs can't be done on the client window because of
2473 * ICCCM and because clients that try to do the same will crash.
2475 * But there is a problem wich makes tbar buttons of unfocused
2476 * windows not usable as the click goes to the frame window instead
2477 * of the button itself. Must figure a way to fix that.
2480 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2482 if (!WFLAGP(wwin, no_bind_mouse)) {
2483 /* grabs for Meta+drag */
2484 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2485 True, ButtonPressMask | ButtonReleaseMask,
2486 GrabModeSync, GrabModeAsync, None, None);
2488 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2489 * but we only grab it for Button4 and Button 5 since a lot of apps
2490 * use CTRL+Button1-3 for app related functionality
2492 if (wPreferences.resize_increment > 0) {
2493 wHackedGrabButton(Button4, ControlMask, wwin->client_win,
2494 True, ButtonPressMask | ButtonReleaseMask,
2495 GrabModeSync, GrabModeAsync, None, None);
2496 wHackedGrabButton(Button5, ControlMask, wwin->client_win,
2497 True, ButtonPressMask | ButtonReleaseMask,
2498 GrabModeSync, GrabModeAsync, None, None);
2500 wHackedGrabButton(Button4, MOD_MASK | ControlMask, wwin->client_win,
2501 True, ButtonPressMask | ButtonReleaseMask,
2502 GrabModeSync, GrabModeAsync, None, None);
2503 wHackedGrabButton(Button5, MOD_MASK | ControlMask, wwin->client_win,
2504 True, ButtonPressMask | ButtonReleaseMask,
2505 GrabModeSync, GrabModeAsync, None, None);
2509 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2510 && !wwin->flags.is_gnustep) {
2511 /* the passive grabs to focus the window */
2512 /* if (wPreferences.focus_mode == WKF_CLICK) */
2513 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2514 True, ButtonPressMask | ButtonReleaseMask, GrabModeSync, GrabModeAsync, None, None);
2516 XFlush(dpy);
2519 void wWindowUpdateGNUstepAttr(WWindow * wwin, GNUstepWMAttributes * attr)
2521 if (attr->flags & GSExtraFlagsAttr) {
2522 if (MGFLAGP(wwin, broken_close) != (attr->extra_flags & GSDocumentEditedFlag)) {
2523 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2524 wWindowUpdateButtonImages(wwin);
2529 WMagicNumber wWindowAddSavedState(char *instance, char *class, char *command, pid_t pid, WSavedState * state)
2531 WWindowState *wstate;
2533 wstate = malloc(sizeof(WWindowState));
2534 if (!wstate)
2535 return NULL;
2537 memset(wstate, 0, sizeof(WWindowState));
2538 wstate->pid = pid;
2539 if (instance)
2540 wstate->instance = wstrdup(instance);
2541 if (class)
2542 wstate->class = wstrdup(class);
2543 if (command)
2544 wstate->command = wstrdup(command);
2545 wstate->state = state;
2547 wstate->next = windowState;
2548 windowState = wstate;
2550 return wstate;
2553 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2555 WMagicNumber wWindowGetSavedState(Window win)
2557 char *instance, *class, *command = NULL;
2558 WWindowState *wstate = windowState;
2560 if (!wstate)
2561 return NULL;
2563 command = GetCommandForWindow(win);
2564 if (!command)
2565 return NULL;
2567 if (PropGetWMClass(win, &class, &instance)) {
2568 while (wstate) {
2569 if (SAME(instance, wstate->instance) &&
2570 SAME(class, wstate->class) && SAME(command, wstate->command)) {
2571 break;
2573 wstate = wstate->next;
2575 } else {
2576 wstate = NULL;
2579 if (command)
2580 wfree(command);
2581 if (instance)
2582 free(instance);
2583 if (class)
2584 free(class);
2586 return wstate;
2589 void wWindowDeleteSavedState(WMagicNumber id)
2591 WWindowState *tmp, *wstate = (WWindowState *) id;
2593 if (!wstate || !windowState)
2594 return;
2596 tmp = windowState;
2597 if (tmp == wstate) {
2598 windowState = wstate->next;
2599 if (wstate->instance)
2600 wfree(wstate->instance);
2601 if (wstate->class)
2602 wfree(wstate->class);
2603 if (wstate->command)
2604 wfree(wstate->command);
2605 wfree(wstate->state);
2606 wfree(wstate);
2607 } else {
2608 while (tmp->next) {
2609 if (tmp->next == wstate) {
2610 tmp->next = wstate->next;
2611 if (wstate->instance)
2612 wfree(wstate->instance);
2613 if (wstate->class)
2614 wfree(wstate->class);
2615 if (wstate->command)
2616 wfree(wstate->command);
2617 wfree(wstate->state);
2618 wfree(wstate);
2619 break;
2621 tmp = tmp->next;
2626 void wWindowDeleteSavedStatesForPID(pid_t pid)
2628 WWindowState *tmp, *wstate;
2630 if (!windowState)
2631 return;
2633 tmp = windowState;
2634 if (tmp->pid == pid) {
2635 wstate = windowState;
2636 windowState = tmp->next;
2637 if (wstate->instance)
2638 wfree(wstate->instance);
2639 if (wstate->class)
2640 wfree(wstate->class);
2641 if (wstate->command)
2642 wfree(wstate->command);
2643 wfree(wstate->state);
2644 wfree(wstate);
2645 } else {
2646 while (tmp->next) {
2647 if (tmp->next->pid == pid) {
2648 wstate = tmp->next;
2649 tmp->next = wstate->next;
2650 if (wstate->instance)
2651 wfree(wstate->instance);
2652 if (wstate->class)
2653 wfree(wstate->class);
2654 if (wstate->command)
2655 wfree(wstate->command);
2656 wfree(wstate->state);
2657 wfree(wstate);
2658 break;
2660 tmp = tmp->next;
2665 void wWindowSetOmnipresent(WWindow *wwin, Bool flag)
2667 if (wwin->flags.omnipresent == flag)
2668 return;
2670 wwin->flags.omnipresent = flag;
2671 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
2674 static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2676 WWindow *wwin = data;
2678 #ifndef NUMLOCK_HACK
2679 if ((event->xbutton.state & ValidModMask)
2680 != (event->xbutton.state & ~LockMask)) {
2681 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2682 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2684 #endif
2686 event->xbutton.state &= ValidModMask;
2688 CloseWindowMenu(wwin->screen_ptr);
2690 if (wPreferences.focus_mode == WKF_CLICK && !(event->xbutton.state & ControlMask)
2691 && !WFLAGP(wwin, no_focusable)) {
2692 wSetFocusTo(wwin->screen_ptr, wwin);
2695 if (event->xbutton.button == Button1)
2696 wRaiseFrame(wwin->frame->core);
2698 if (event->xbutton.window != wwin->frame->resizebar->window) {
2699 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2700 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2701 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
2702 return;
2706 if (event->xbutton.state & MOD_MASK) {
2707 /* move the window */
2708 wMouseMoveWindow(wwin, event);
2709 XUngrabPointer(dpy, CurrentTime);
2710 } else {
2711 wMouseResizeWindow(wwin, event);
2712 XUngrabPointer(dpy, CurrentTime);
2716 static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
2718 WWindow *wwin = data;
2720 event->xbutton.state &= ValidModMask;
2722 if (event->xbutton.button == Button1) {
2723 if (event->xbutton.state == 0) {
2724 if (!WFLAGP(wwin, no_shadeable)) {
2725 /* shade window */
2726 if (wwin->flags.shaded)
2727 wUnshadeWindow(wwin);
2728 else
2729 wShadeWindow(wwin);
2731 } else {
2732 int dir = 0;
2734 if (event->xbutton.state & ControlMask)
2735 dir |= MAX_VERTICAL;
2737 if (event->xbutton.state & ShiftMask) {
2738 dir |= MAX_HORIZONTAL;
2739 if (!(event->xbutton.state & ControlMask))
2740 wSelectWindow(wwin, !wwin->flags.selected);
2743 /* maximize window */
2744 if (dir != 0 && IS_RESIZABLE(wwin)) {
2745 int ndir = dir ^ wwin->flags.maximized;
2747 if (ndir != 0)
2748 wMaximizeWindow(wwin, ndir);
2749 else
2750 wUnmaximizeWindow(wwin);
2753 } else if (event->xbutton.button == Button3) {
2754 if (event->xbutton.state & MOD_MASK)
2755 wHideOtherApplications(wwin);
2756 } else if (event->xbutton.button == Button2) {
2757 wSelectWindow(wwin, !wwin->flags.selected);
2758 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2759 wShadeWindow(wwin);
2760 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2761 wUnshadeWindow(wwin);
2765 static void frameMouseDown(WObjDescriptor *desc, XEvent *event)
2767 WWindow *wwin = desc->parent;
2768 unsigned int new_width, w_scale;
2769 unsigned int new_height, h_scale;
2770 unsigned int resize_width_increment = 0;
2771 unsigned int resize_height_increment = 0;
2773 if (wwin->normal_hints) {
2774 w_scale = (wPreferences.resize_increment + wwin->normal_hints->width_inc - 1) / wwin->normal_hints->width_inc;
2775 h_scale = (wPreferences.resize_increment + wwin->normal_hints->height_inc - 1) / wwin->normal_hints->height_inc;
2776 resize_width_increment = wwin->normal_hints->width_inc * w_scale;
2777 resize_height_increment = wwin->normal_hints->height_inc * h_scale;
2779 if (resize_width_increment <= 1 && resize_height_increment <= 1) {
2780 resize_width_increment = wPreferences.resize_increment;
2781 resize_height_increment = wPreferences.resize_increment;
2784 event->xbutton.state &= ValidModMask;
2786 CloseWindowMenu(wwin->screen_ptr);
2788 if (!(event->xbutton.state & ControlMask) && !WFLAGP(wwin, no_focusable))
2789 wSetFocusTo(wwin->screen_ptr, wwin);
2791 if (event->xbutton.button == Button1)
2792 wRaiseFrame(wwin->frame->core);
2794 if (event->xbutton.state & ControlMask) {
2795 if (event->xbutton.button == Button4) {
2796 new_width = wwin->client.width - resize_width_increment;
2797 wWindowConstrainSize(wwin, &new_width, &wwin->client.height);
2798 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, new_width, wwin->client.height);
2800 if (event->xbutton.button == Button5) {
2801 new_width = wwin->client.width + resize_width_increment;
2802 wWindowConstrainSize(wwin, &new_width, &wwin->client.height);
2803 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, new_width, wwin->client.height);
2807 if (event->xbutton.state & MOD_MASK) {
2808 /* move the window */
2809 if (XGrabPointer(dpy, wwin->client_win, False,
2810 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2811 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
2812 return;
2814 if (event->xbutton.button == Button3) {
2815 wMouseResizeWindow(wwin, event);
2816 } else if (event->xbutton.button == Button4) {
2817 new_height = wwin->client.height - resize_height_increment;
2818 wWindowConstrainSize(wwin, &wwin->client.width, &new_height);
2819 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, wwin->client.width, new_height);
2820 } else if (event->xbutton.button == Button5) {
2821 new_height = wwin->client.height + resize_height_increment;
2822 wWindowConstrainSize(wwin, &wwin->client.width, &new_height);
2823 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, wwin->client.width, new_height);
2824 } else if (event->xbutton.button == Button1 || event->xbutton.button == Button2) {
2825 wMouseMoveWindow(wwin, event);
2827 XUngrabPointer(dpy, CurrentTime);
2831 static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
2833 WWindow *wwin = (WWindow *) data;
2835 #ifndef NUMLOCK_HACK
2836 if ((event->xbutton.state & ValidModMask) != (event->xbutton.state & ~LockMask))
2837 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2838 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2839 #endif
2840 event->xbutton.state &= ValidModMask;
2842 CloseWindowMenu(wwin->screen_ptr);
2844 if (wPreferences.focus_mode == WKF_CLICK && !(event->xbutton.state & ControlMask)
2845 && !WFLAGP(wwin, no_focusable))
2846 wSetFocusTo(wwin->screen_ptr, wwin);
2848 if (event->xbutton.button == Button1 || event->xbutton.button == Button2) {
2850 if (event->xbutton.button == Button1) {
2851 if (event->xbutton.state & MOD_MASK)
2852 wLowerFrame(wwin->frame->core);
2853 else
2854 wRaiseFrame(wwin->frame->core);
2856 if ((event->xbutton.state & ShiftMask)
2857 && !(event->xbutton.state & ControlMask)) {
2858 wSelectWindow(wwin, !wwin->flags.selected);
2859 return;
2861 if (event->xbutton.window != wwin->frame->titlebar->window
2862 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2863 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2864 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
2865 return;
2868 /* move the window */
2869 wMouseMoveWindow(wwin, event);
2871 XUngrabPointer(dpy, CurrentTime);
2872 } else if (event->xbutton.button == Button3 && event->xbutton.state == 0
2873 && !wwin->flags.internal_window && !WCHECK_STATE(WSTATE_MODAL)) {
2874 WObjDescriptor *desc;
2876 if (event->xbutton.window != wwin->frame->titlebar->window
2877 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2878 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2879 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
2880 return;
2883 OpenWindowMenu(wwin, event->xbutton.x_root, wwin->frame_y + wwin->frame->top_width, False);
2885 /* allow drag select */
2886 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2887 event->xany.send_event = True;
2888 (*desc->handle_mousedown) (desc, event);
2890 XUngrabPointer(dpy, CurrentTime);
2894 static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
2896 WWindow *wwin = data;
2898 event->xbutton.state &= ValidModMask;
2900 CloseWindowMenu(wwin->screen_ptr);
2902 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2903 return;
2905 /* if control-click, kill the client */
2906 if (event->xbutton.state & ControlMask) {
2907 wClientKill(wwin);
2908 } else {
2909 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state == 0) {
2910 /* send delete message */
2911 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
2916 static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
2918 WWindow *wwin = data;
2920 CloseWindowMenu(wwin->screen_ptr);
2922 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2923 return;
2925 /* send delete message */
2926 if (wwin->protocols.DELETE_WINDOW)
2927 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
2928 else
2929 wClientKill(wwin);
2932 #ifdef XKB_BUTTON_HINT
2933 static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
2935 WWindow *wwin = data;
2936 WFrameWindow *fwin = wwin->frame;
2937 WScreen *scr = fwin->screen_ptr;
2938 int tl;
2940 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
2941 return;
2942 tl = wwin->frame->languagemode;
2943 wwin->frame->languagemode = wwin->frame->last_languagemode;
2944 wwin->frame->last_languagemode = tl;
2945 wSetFocusTo(scr, wwin);
2946 wwin->frame->languagebutton_image =
2947 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 + wwin->frame->languagemode];
2948 wFrameWindowUpdateLanguageButton(wwin->frame);
2949 if (event->xbutton.button == Button3)
2950 return;
2951 wRaiseFrame(fwin->core);
2953 #endif
2955 static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
2957 WWindow *wwin = data;
2959 event->xbutton.state &= ValidModMask;
2961 CloseWindowMenu(wwin->screen_ptr);
2963 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2964 return;
2966 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state == 0) {
2967 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, LastTimestamp);
2968 } else {
2969 WApplication *wapp;
2970 if ((event->xbutton.state & ControlMask) || (event->xbutton.button == Button3)) {
2972 wapp = wApplicationOf(wwin->main_window);
2973 if (wapp && !WFLAGP(wwin, no_appicon))
2974 wHideApplication(wapp);
2975 } else if (event->xbutton.state == 0) {
2976 wIconifyWindow(wwin);