Improve dockapp recognition
[wmaker-crm.git] / src / window.c
Commit [+]AuthorDateLineData
e7495baf dan1999-02-17 11:06:40 +00001/* window.c - client window managing stuffs
9aca0d5f dan2004-10-12 01:34:32 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
9aca0d5f dan2004-10-12 01:34:32 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1997-2003 Alfredo K. Kojima
9aca0d5f dan2004-10-12 01:34:32 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
11 *
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.
16 *
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
9aca0d5f dan2004-10-12 01:34:32 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
23#include "wconfig.h"
24
25#include <X11/Xlib.h>
26#include <X11/Xutil.h>
27#ifdef SHAPE
28#include <X11/extensions/shape.h>
29#endif
9aca0d5f dan2004-10-12 01:34:32 +000030#ifdef KEEP_XKB_LOCK_STATUS
31#include <X11/XKBlib.h>
347e804b Carlos R. Mafra2009-10-11 23:30:41 +020032#endif /* KEEP_XKB_LOCK_STATUS */
9d2e6ef9 scottc1998-09-29 22:36:29 +000033#include <stdlib.h>
34#include <stdio.h>
35#include <string.h>
06f59b99 Carlos R. Mafra2008-11-06 01:37:44 +010036#include <stdint.h>
1f1eb393 Johann Haarhoff2009-10-12 21:48:45 +020037#include <math.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000038
75f79016 dan2001-10-09 03:35:45 +000039/* For getting mouse wheel mappings from WINGs */
40#include <WINGs/WINGsP.h>
59eb9475 dan1998-11-03 12:53:26 +000041
9d2e6ef9 scottc1998-09-29 22:36:29 +000042#include "WindowMaker.h"
43#include "GNUstep.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000044#include "wcore.h"
45#include "framewin.h"
46#include "texture.h"
47#include "window.h"
48#include "winspector.h"
49#include "icon.h"
50#include "properties.h"
51#include "actions.h"
52#include "client.h"
53#include "funcs.h"
54#include "keybind.h"
55#include "stacking.h"
56#include "defaults.h"
57#include "workspace.h"
a10214a5 kojima2002-11-28 22:04:07 +000058#include "xinerama.h"
3c046182 kojima1999-09-16 02:58:56 +000059
0261c326 dan1999-01-06 15:22:33 +000060#ifdef MWM_HINTS
61# include "motif.h"
62#endif
15e37ff9 Carlos R. Mafra2009-10-12 00:08:21 +020063#include "wmspec.h"
0261c326 dan1999-01-06 15:22:33 +000064
347e804b Carlos R. Mafra2009-10-11 23:30:41 +020065#define MOD_MASK wPreferences.modifier_mask
9d2e6ef9 scottc1998-09-29 22:36:29 +000066
347e804b Carlos R. Mafra2009-10-11 23:30:41 +020067/****** Global Variables ******/
9d2e6ef9 scottc1998-09-29 22:36:29 +000068extern WShortKey wKeyBindings[WKBD_LAST];
69
9af1c6c4 dan1998-10-21 14:43:47 +000070#ifdef SHAPE
71extern Bool wShapeSupported;
72#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +000073
74/* contexts */
75extern XContext wWinContext;
76
9d2e6ef9 scottc1998-09-29 22:36:29 +000077/* protocol atoms */
78extern Atom _XA_WM_DELETE_WINDOW;
9af1c6c4 dan1998-10-21 14:43:47 +000079extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
9d2e6ef9 scottc1998-09-29 22:36:29 +000080extern Atom _XA_WINDOWMAKER_STATE;
9d2e6ef9 scottc1998-09-29 22:36:29 +000081extern WPreferences wPreferences;
9d2e6ef9 scottc1998-09-29 22:36:29 +000082extern Time LastTimestamp;
83
84/* superfluous... */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +020085extern void DoWindowBirth(WWindow *wwin);
5ef342d9 kojima2001-09-06 21:42:28 +000086
9d2e6ef9 scottc1998-09-29 22:36:29 +000087/***** Local Stuff *****/
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020088static WWindowState *windowState = NULL;
347e804b
CM
Carlos R. Mafra2009-10-11 23:30:41 +020089static FocusMode getFocusMode(WWindow *wwin);
90static int getSavedState(Window window, WSavedState **state);
91static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints);
9d2e6ef9 scottc1998-09-29 22:36:29 +000092
9d2e6ef9 scottc1998-09-29 22:36:29 +000093/* frame window (during window grabs) */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +020094static void frameMouseDown(WObjDescriptor *desc, XEvent *event);
9d2e6ef9 scottc1998-09-29 22:36:29 +000095
96/* close button */
347e804b
CM
Carlos R. Mafra2009-10-11 23:30:41 +020097static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event);
98static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event);
9d2e6ef9 scottc1998-09-29 22:36:29 +000099
100/* iconify button */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200101static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000102
c28f3b2c id1999-05-20 23:30:53 +0000103#ifdef XKB_BUTTON_HINT
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200104static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event);
c28f3b2c id1999-05-20 23:30:53 +0000105#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000106
347e804b
CM
Carlos R. Mafra2009-10-11 23:30:41 +0200107static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
108static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event);
109static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000110
9df0e167 kojima1999-04-03 03:51:17 +0000111/****** Notification Observers ******/
9af1c6c4 dan1998-10-21 14:43:47 +0000112
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200113static void appearanceObserver(void *self, WMNotification * notif)
9df0e167 kojima1999-04-03 03:51:17 +0000114{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200115 WWindow *wwin = (WWindow *) self;
513a5090 Carlos R. Mafra2009-09-14 15:57:52 +0200116 uintptr_t flags = (uintptr_t)WMGetNotificationClientData(notif);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200117
118 if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
119 return;
120
121 if (flags & WFontSettings) {
122 wWindowConfigureBorders(wwin);
123 if (wwin->flags.shaded) {
124 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
125
126 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
127 wWindowSynthConfigureNotify(wwin);
128 }
129 }
130 if (flags & WTextureSettings) {
131 wwin->frame->flags.need_texture_remake = 1;
132 }
133 if (flags & (WTextureSettings | WColorSettings)) {
134 if (wwin->frame->titlebar)
135 XClearWindow(dpy, wwin->frame->titlebar->window);
136
137 wFrameWindowPaint(wwin->frame);
138 }
9df0e167 kojima1999-04-03 03:51:17 +0000139}
140
9af1c6c4 dan1998-10-21 14:43:47 +0000141
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200142WWindow *wWindowFor(Window window)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000143{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200144 WObjDescriptor *desc;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000145
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200146 if (window == None)
147 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000148
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200149 if (XFindContext(dpy, window, wWinContext, (XPointer *) & desc) == XCNOENT)
150 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000151
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200152 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;
158 }
9df0e167 kojima1999-04-03 03:51:17 +0000159
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200160 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000161}
162
4041278f Carlos R. Mafra2010-04-12 23:31:59 +0200163WWindow *wWindowCreate(void)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000164{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200165 WWindow *wwin;
9aca0d5f dan2004-10-12 01:34:32 +0000166
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200167 wwin = wmalloc(sizeof(WWindow));
168 wretain(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000169
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200170 memset(wwin, 0, sizeof(WWindow));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000171
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200172 wwin->client_descriptor.handle_mousedown = frameMouseDown;
173 wwin->client_descriptor.parent = wwin;
174 wwin->client_descriptor.self = wwin;
175 wwin->client_descriptor.parent_type = WCLASS_WINDOW;
9df0e167 kojima1999-04-03 03:51:17 +0000176
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200177 return wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000178}
179
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200180void wWindowDestroy(WWindow *wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000181{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200182 int i;
59eb9475 dan1998-11-03 12:53:26 +0000183
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200184 if (wwin->screen_ptr->cmap_window == wwin)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200185 wwin->screen_ptr->cmap_window = NULL;
9aca0d5f dan2004-10-12 01:34:32 +0000186
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200187 WMRemoveNotificationObserver(wwin);
9aca0d5f dan2004-10-12 01:34:32 +0000188
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200189 wwin->flags.destroyed = 1;
59eb9475 dan1998-11-03 12:53:26 +0000190
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200191 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
192 if (!wwin->screen_ptr->shortcutWindows[i])
193 continue;
3c046182 kojima1999-09-16 02:58:56 +0000194
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200195 WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
5c881364 kojima1999-09-18 21:17:03 +0000196
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200197 if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
198 WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
199 wwin->screen_ptr->shortcutWindows[i] = NULL;
200 }
201 }
59eb9475 dan1998-11-03 12:53:26 +0000202
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200203 if (wwin->fake_group && wwin->fake_group->retainCount > 0) {
204 wwin->fake_group->retainCount--;
205 if (wwin->fake_group->retainCount == 0 && wwin->fake_group->leader != None) {
206 XDestroyWindow(dpy, wwin->fake_group->leader);
207 wwin->fake_group->leader = None;
208 wwin->fake_group->origLeader = None;
209 XFlush(dpy);
210 }
211 }
672c42cc dan2001-12-17 04:02:33 +0000212
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200213 if (wwin->normal_hints)
214 XFree(wwin->normal_hints);
672c42cc dan2001-12-17 04:02:33 +0000215
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200216 if (wwin->wm_hints)
217 XFree(wwin->wm_hints);
672c42cc dan2001-12-17 04:02:33 +0000218
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200219 if (wwin->wm_instance)
220 XFree(wwin->wm_instance);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000221
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200222 if (wwin->wm_class)
223 XFree(wwin->wm_class);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000224
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200225 if (wwin->wm_gnustep_attr)
226 wfree(wwin->wm_gnustep_attr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000227
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200228 if (wwin->cmap_windows)
229 XFree(wwin->cmap_windows);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000230
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200231 XDeleteContext(dpy, wwin->client_win, wWinContext);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000232
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200233 if (wwin->frame)
234 wFrameWindowDestroy(wwin->frame);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000235
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200236 if (wwin->icon) {
237 RemoveFromStackList(wwin->icon->core);
238 wIconDestroy(wwin->icon);
239 if (wPreferences.auto_arrange_icons)
240 wArrangeIcons(wwin->screen_ptr, True);
241 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200242 if (wwin->net_icon_image)
243 RReleaseImage(wwin->net_icon_image);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000244
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200245 wrelease(wwin);
9aca0d5f dan2004-10-12 01:34:32 +0000246}
9d2e6ef9 scottc1998-09-29 22:36:29 +0000247
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200248static void setupGNUstepHints(WWindow *wwin, GNUstepWMAttributes *gs_hints)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000249{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200250 if (gs_hints->flags & GSWindowStyleAttr) {
251 if (gs_hints->window_style == WMBorderlessWindowMask) {
252 wwin->client_flags.no_border = 1;
253 wwin->client_flags.no_titlebar = 1;
254 wwin->client_flags.no_closable = 1;
255 wwin->client_flags.no_miniaturizable = 1;
256 wwin->client_flags.no_resizable = 1;
257 wwin->client_flags.no_close_button = 1;
258 wwin->client_flags.no_miniaturize_button = 1;
259 wwin->client_flags.no_resizebar = 1;
260 } else {
261 wwin->client_flags.no_close_button =
262 ((gs_hints->window_style & WMClosableWindowMask) ? 0 : 1);
263
264 wwin->client_flags.no_closable = ((gs_hints->window_style & WMClosableWindowMask) ? 0 : 1);
265
266 wwin->client_flags.no_miniaturize_button =
267 ((gs_hints->window_style & WMMiniaturizableWindowMask) ? 0 : 1);
268
269 wwin->client_flags.no_miniaturizable = wwin->client_flags.no_miniaturize_button;
270
271 wwin->client_flags.no_resizebar =
272 ((gs_hints->window_style & WMResizableWindowMask) ? 0 : 1);
273
274 wwin->client_flags.no_resizable = wwin->client_flags.no_resizebar;
275
276 /* these attributes supposedly imply in the existence
277 * of a titlebar */
278 if (gs_hints->window_style & (WMResizableWindowMask |
279 WMClosableWindowMask | WMMiniaturizableWindowMask)) {
280 wwin->client_flags.no_titlebar = 0;
281 } else {
282 wwin->client_flags.no_titlebar =
283 ((gs_hints->window_style & WMTitledWindowMask) ? 0 : 1);
284 }
285
286 }
287 } else {
288 /* setup the defaults */
289 wwin->client_flags.no_border = 0;
290 wwin->client_flags.no_titlebar = 0;
291 wwin->client_flags.no_closable = 0;
292 wwin->client_flags.no_miniaturizable = 0;
293 wwin->client_flags.no_resizable = 0;
294 wwin->client_flags.no_close_button = 0;
295 wwin->client_flags.no_miniaturize_button = 0;
296 wwin->client_flags.no_resizebar = 0;
297 }
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200298 if (gs_hints->extra_flags & GSNoApplicationIconFlag)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200299 wwin->client_flags.no_appicon = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000300}
301
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200302void wWindowSetupInitialAttributes(WWindow *wwin, int *level, int *workspace)
0261c326 dan1999-01-06 15:22:33 +0000303{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200304 WScreen *scr = wwin->screen_ptr;
305
306 /* sets global default stuff */
307 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class, &wwin->client_flags, NULL, True);
308 /*
309 * Decoration setting is done in this precedence (lower to higher)
310 * - use global default in the resource database
311 * - guess some settings
312 * - use GNUstep/external window attributes
313 * - set hints specified for the app in the resource DB
314 *
315 */
316 WSETUFLAG(wwin, broken_close, 0);
317
318 if (wwin->protocols.DELETE_WINDOW)
319 WSETUFLAG(wwin, kill_close, 0);
320 else
321 WSETUFLAG(wwin, kill_close, 1);
322
323 /* transients can't be iconified or maximized */
324 if (wwin->transient_for != None && wwin->transient_for != scr->root_win) {
325 WSETUFLAG(wwin, no_miniaturizable, 1);
326 WSETUFLAG(wwin, no_miniaturize_button, 1);
327 }
328
329 /* if the window can't be resized, remove the resizebar */
330 if (wwin->normal_hints->flags & (PMinSize | PMaxSize)
331 && (wwin->normal_hints->min_width == wwin->normal_hints->max_width)
332 && (wwin->normal_hints->min_height == wwin->normal_hints->max_height)) {
333 WSETUFLAG(wwin, no_resizable, 1);
334 WSETUFLAG(wwin, no_resizebar, 1);
335 }
336
337 /* set GNUstep window attributes */
338 if (wwin->wm_gnustep_attr) {
339 setupGNUstepHints(wwin, wwin->wm_gnustep_attr);
340
341 if (wwin->wm_gnustep_attr->flags & GSWindowLevelAttr) {
342
343 *level = wwin->wm_gnustep_attr->window_level;
344 /*
345 * INT_MIN is the only illegal window level.
346 */
347 if (*level == INT_MIN)
348 *level = INT_MIN + 1;
349 } else {
350 /* setup defaults */
351 *level = WMNormalLevel;
352 }
353 } else {
354 int tmp_workspace = -1;
355 int tmp_level = INT_MIN; /* INT_MIN is never used by the window levels */
356 Bool check;
357
358 check = False;
9aca0d5f dan2004-10-12 01:34:32 +0000359
0261c326 dan1999-01-06 15:22:33 +0000360#ifdef MWM_HINTS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200361 wMWMCheckClientHints(wwin);
362#endif /* MWM_HINTS */
0261c326 dan1999-01-06 15:22:33 +0000363
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200364 if (!check)
365 check = wNETWMCheckClientHints(wwin, &tmp_level, &tmp_workspace);
9aca0d5f dan2004-10-12 01:34:32 +0000366
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200367 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
368 * have INT_MIN that means that no window level was requested. -Dan
369 */
370 if (tmp_level == INT_MIN) {
371 if (WFLAGP(wwin, floating))
372 *level = WMFloatingLevel;
373 else if (WFLAGP(wwin, sunken))
374 *level = WMSunkenLevel;
375 else
376 *level = WMNormalLevel;
377 } else {
378 *level = tmp_level;
379 }
380
381 if (wwin->transient_for != None && wwin->transient_for != scr->root_win) {
382 WWindow *transientOwner = wWindowFor(wwin->transient_for);
383 if (transientOwner) {
384 int ownerLevel = transientOwner->frame->core->stacking->window_level;
385 if (ownerLevel > *level)
386 *level = ownerLevel;
387 }
388 }
389
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200390 if (tmp_workspace >= 0)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200391 *workspace = tmp_workspace % scr->workspace_count;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200392 }
393
394 /*
395 * Set attributes specified only for that window/class.
396 * This might do duplicate work with the 1st wDefaultFillAttributes().
397 */
398 wDefaultFillAttributes(scr, wwin->wm_instance, wwin->wm_class,
399 &wwin->user_flags, &wwin->defined_user_flags, False);
400 /*
401 * Sanity checks for attributes that depend on other attributes
402 */
403 if (wwin->user_flags.no_appicon && wwin->defined_user_flags.no_appicon)
404 wwin->user_flags.emulate_appicon = 0;
405
406 if (wwin->main_window != None) {
407 WApplication *wapp = wApplicationOf(wwin->main_window);
408 if (wapp && !wapp->flags.emulated)
409 wwin->user_flags.emulate_appicon = 0;
410 }
411
412 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win)
413 wwin->user_flags.emulate_appicon = 0;
414
415 if (wwin->user_flags.sunken && wwin->defined_user_flags.sunken
416 && wwin->user_flags.floating && wwin->defined_user_flags.floating)
417 wwin->user_flags.sunken = 0;
418
419 WSETUFLAG(wwin, no_shadeable, WFLAGP(wwin, no_titlebar));
420
421 /* windows that have takefocus=False shouldn't take focus at all */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200422 if (wwin->focus_mode == WFM_NO_INPUT)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200423 wwin->client_flags.no_focusable = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000424}
425
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200426Bool wWindowCanReceiveFocus(WWindow *wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000427{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200428 if (!wwin->flags.mapped && (!wwin->flags.shaded || wwin->flags.hidden))
429 return False;
430 if (WFLAGP(wwin, no_focusable) || wwin->flags.miniaturized)
431 return False;
432 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
433 return False;
434
435 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000436}
437
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200438Bool wWindowObscuresWindow(WWindow *wwin, WWindow *obscured)
0261c326 dan1999-01-06 15:22:33 +0000439{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200440 int w1, h1, w2, h2;
416e3a82 dan1999-01-25 19:06:50 +0000441
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200442 w1 = wwin->frame->core->width;
443 h1 = wwin->frame->core->height;
444 w2 = obscured->frame->core->width;
445 h2 = obscured->frame->core->height;
416e3a82 dan1999-01-25 19:06:50 +0000446
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200447 if (!IS_OMNIPRESENT(wwin) && !IS_OMNIPRESENT(obscured)
448 && wwin->frame->workspace != obscured->frame->workspace)
449 return False;
0261c326 dan1999-01-06 15:22:33 +0000450
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200451 if (wwin->frame_x + w1 < obscured->frame_x
452 || wwin->frame_y + h1 < obscured->frame_y
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200453 || wwin->frame_x > obscured->frame_x + w2 || wwin->frame_y > obscured->frame_y + h2)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200454 return False;
0261c326 dan1999-01-06 15:22:33 +0000455
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200456 return True;
0261c326 dan1999-01-06 15:22:33 +0000457}
416e3a82 dan1999-01-25 19:06:50 +0000458
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200459static void fixLeaderProperties(WWindow *wwin)
9aca0d5f dan2004-10-12 01:34:32 +0000460{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200461 XClassHint *classHint;
462 XWMHints *hints, *clientHints;
463 Window leaders[2], window;
464 char **argv, *command;
465 int argc, i, pid;
466 Bool haveCommand;
467
468 classHint = XAllocClassHint();
469 clientHints = XGetWMHints(dpy, wwin->client_win);
470 pid = wNETWMGetPidForWindow(wwin->client_win);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200471 if (pid > 0)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200472 haveCommand = GetCommandForPid(pid, &argv, &argc);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200473 else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200474 haveCommand = False;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200475
476 leaders[0] = wwin->client_leader;
477 leaders[1] = wwin->group_id;
478
479 if (haveCommand) {
480 command = GetCommandForWindow(wwin->client_win);
481 if (command) {
482 /* command already set. nothing to do. */
483 wfree(command);
484 } else {
485 XSetCommand(dpy, wwin->client_win, argv, argc);
486 }
487 }
488
489 for (i = 0; i < 2; i++) {
490 window = leaders[i];
491 if (window) {
492 if (XGetClassHint(dpy, window, classHint) == 0) {
493 classHint->res_name = wwin->wm_instance;
494 classHint->res_class = wwin->wm_class;
495 XSetClassHint(dpy, window, classHint);
496 }
497 hints = XGetWMHints(dpy, window);
498 if (hints) {
499 XFree(hints);
500 } else if (clientHints) {
501 /* set window group leader to self */
502 clientHints->window_group = window;
503 clientHints->flags |= WindowGroupHint;
504 XSetWMHints(dpy, window, clientHints);
505 }
506
507 if (haveCommand) {
508 command = GetCommandForWindow(window);
509 if (command) {
510 /* command already set. nothing to do. */
511 wfree(command);
512 } else {
513 XSetCommand(dpy, window, argv, argc);
514 }
515 }
516 }
517 }
518
519 XFree(classHint);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200520 if (clientHints)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200521 XFree(clientHints);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200522 if (haveCommand)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200523 wfree(argv);
9aca0d5f dan2004-10-12 01:34:32 +0000524}
525
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200526static Window createFakeWindowGroupLeader(WScreen *scr, Window win, char *instance, char *class)
672c42cc dan2001-12-17 04:02:33 +0000527{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200528 XClassHint *classHint;
529 XWMHints *hints;
530 Window leader;
531 int argc;
532 char **argv;
533
534 leader = XCreateSimpleWindow(dpy, scr->root_win, 10, 10, 10, 10, 0, 0, 0);
535 /* set class hint */
536 classHint = XAllocClassHint();
537 classHint->res_name = instance;
538 classHint->res_class = class;
539 XSetClassHint(dpy, leader, classHint);
540 XFree(classHint);
541
542 /* inherit these from the original leader if available */
543 hints = XGetWMHints(dpy, win);
544 if (!hints) {
545 hints = XAllocWMHints();
546 hints->flags = 0;
547 }
548 /* set window group leader to self */
549 hints->window_group = leader;
550 hints->flags |= WindowGroupHint;
551 XSetWMHints(dpy, leader, hints);
552 XFree(hints);
553
554 if (XGetCommand(dpy, win, &argv, &argc) != 0 && argc > 0) {
555 XSetCommand(dpy, leader, argv, argc);
556 XFreeStringList(argv);
557 }
558
559 return leader;
672c42cc dan2001-12-17 04:02:33 +0000560}
561
8018da81 Carlos R. Mafra2010-03-16 19:01:01 +0100562static int matchIdentifier(const void *item, const void *cdata)
672c42cc dan2001-12-17 04:02:33 +0000563{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200564 return (strcmp(((WFakeGroupLeader *) item)->identifier, (char *)cdata) == 0);
672c42cc dan2001-12-17 04:02:33 +0000565}
566
9d2e6ef9 scottc1998-09-29 22:36:29 +0000567/*
568 *----------------------------------------------------------------
569 * wManageWindow--
570 * reparents the window and allocates a descriptor for it.
571 * Window manager hints and other hints are fetched to configure
572 * the window decoration attributes and others. User preferences
9aca0d5f dan2004-10-12 01:34:32 +0000573 * for the window are used if available, to configure window
9d2e6ef9 scottc1998-09-29 22:36:29 +0000574 * decorations and some behaviour.
088c0ac2 dan1999-03-09 14:58:01 +0000575 * If in startup, windows that are override redirect,
576 * unmapped and never were managed and are Withdrawn are not
577 * managed.
9aca0d5f dan2004-10-12 01:34:32 +0000578 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000579 * Returns:
580 * the new window descriptor
9aca0d5f dan2004-10-12 01:34:32 +0000581 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000582 * Side effects:
583 * The window is reparented and appropriate notification
584 * is done to the client. Input mask for the window is setup.
9aca0d5f dan2004-10-12 01:34:32 +0000585 * The window descriptor is also associated with various window
9d2e6ef9 scottc1998-09-29 22:36:29 +0000586 * contexts and inserted in the head of the window list.
9aca0d5f dan2004-10-12 01:34:32 +0000587 * Event handler contexts are associated for some objects
9d2e6ef9 scottc1998-09-29 22:36:29 +0000588 * (buttons, titlebar and resizebar)
9aca0d5f dan2004-10-12 01:34:32 +0000589 *
590 *----------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000591 */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200592WWindow *wManageWindow(WScreen *scr, Window window)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000593{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200594 WWindow *wwin;
595 int x, y;
596 unsigned width, height;
597 XWindowAttributes wattribs;
598 XSetWindowAttributes attribs;
599 WWindowState *win_state;
600 WWindow *transientOwner = NULL;
601 int window_level;
602 int wm_state;
603 int foo;
604 int workspace = -1;
605 char *title;
606 Bool withdraw = False;
607 Bool raise = False;
608
609 /* mutex. */
6c6e832c Ralf Hoffmann2009-12-04 14:51:31 +0100610 XGrabServer(dpy);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200611 XSync(dpy, False);
612 /* make sure the window is still there */
613 if (!XGetWindowAttributes(dpy, window, &wattribs)) {
614 XUngrabServer(dpy);
615 return NULL;
616 }
617
618 /* if it's an override-redirect, ignore it */
619 if (wattribs.override_redirect) {
620 XUngrabServer(dpy);
621 return NULL;
622 }
623
624 wm_state = PropGetWindowState(window);
625
626 /* if it's startup and the window is unmapped, don't manage it */
627 if (scr->flags.startup && wm_state < 0 && wattribs.map_state == IsUnmapped) {
628 XUngrabServer(dpy);
629 return NULL;
630 }
631
632 wwin = wWindowCreate();
633
634 title = wNETWMGetWindowName(window);
635 if (title)
636 wwin->flags.net_has_title = 1;
637 if (!title && !wFetchName(dpy, window, &title))
638 title = NULL;
639
640 XSaveContext(dpy, window, wWinContext, (XPointer) & wwin->client_descriptor);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000641
9d2e6ef9 scottc1998-09-29 22:36:29 +0000642#ifdef SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200643 if (wShapeSupported) {
644 int junk;
645 unsigned int ujunk;
646 int b_shaped;
647
648 XShapeSelectInput(dpy, window, ShapeNotifyMask);
649 XShapeQueryExtents(dpy, window, &b_shaped, &junk, &junk, &ujunk,
650 &ujunk, &junk, &junk, &junk, &ujunk, &ujunk);
651 wwin->flags.shaped = b_shaped;
652 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000653#endif
9aca0d5f dan2004-10-12 01:34:32 +0000654
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200655 /*
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200656 * Get hints and other information in properties
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200657 */
658 PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
659
660 /* setup descriptor */
661 wwin->client_win = window;
662 wwin->screen_ptr = scr;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200663 wwin->old_border_width = wattribs.border_width;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200664 wwin->event_mask = CLIENT_EVENTS;
665 attribs.event_mask = CLIENT_EVENTS;
666 attribs.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask;
667 attribs.save_under = False;
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200668
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200669 XChangeWindowAttributes(dpy, window, CWEventMask | CWDontPropagate | CWSaveUnder, &attribs);
670 XSetWindowBorderWidth(dpy, window, 0);
671
672 /* get hints from GNUstep app */
4041278f Carlos R. Mafra2010-04-12 23:31:59 +0200673 if (wwin->wm_class != NULL && strcmp(wwin->wm_class, "GNUstep") == 0) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200674 wwin->flags.is_gnustep = 1;
675 }
676 if (!PropGetGNUstepWMAttr(window, &wwin->wm_gnustep_attr)) {
677 wwin->wm_gnustep_attr = NULL;
678 }
679
9318a7f4
BJ
Brad Jorsch2010-09-15 12:59:00 -0400680 if (wwin->wm_class != NULL && strcmp(wwin->wm_class, "DockApp") == 0) {
681 wwin->flags.is_dockapp = 1;
682 withdraw = True;
683 }
684
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200685 wwin->client_leader = PropGetClientLeader(window);
686 if (wwin->client_leader != None)
687 wwin->main_window = wwin->client_leader;
688
689 wwin->wm_hints = XGetWMHints(dpy, window);
690
691 if (wwin->wm_hints) {
692 if (wwin->wm_hints->flags & StateHint) {
693
694 if (wwin->wm_hints->initial_state == IconicState) {
695
696 wwin->flags.miniaturized = 1;
697
698 } else if (wwin->wm_hints->initial_state == WithdrawnState) {
699
9318a7f4 Brad Jorsch2010-09-15 12:59:00 -0400700 wwin->flags.is_dockapp = 1;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200701 withdraw = True;
702 }
703 }
704
705 if (wwin->wm_hints->flags & WindowGroupHint) {
706 wwin->group_id = wwin->wm_hints->window_group;
707 /* window_group has priority over CLIENT_LEADER */
708 wwin->main_window = wwin->group_id;
709 } else {
710 wwin->group_id = None;
711 }
712
713 if (wwin->wm_hints->flags & UrgencyHint)
714 wwin->flags.urgent = 1;
715 } else {
716 wwin->group_id = None;
717 }
718
719 PropGetProtocols(window, &wwin->protocols);
720
721 if (!XGetTransientForHint(dpy, window, &wwin->transient_for)) {
722 wwin->transient_for = None;
723 } else {
724 if (wwin->transient_for == None || wwin->transient_for == window) {
725 wwin->transient_for = scr->root_win;
726 } else {
727 transientOwner = wWindowFor(wwin->transient_for);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200728 if (transientOwner && transientOwner->main_window != None)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200729 wwin->main_window = transientOwner->main_window;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200730 }
731 }
732
733 /* guess the focus mode */
734 wwin->focus_mode = getFocusMode(wwin);
735
736 /* get geometry stuff */
737 wClientGetNormalHints(wwin, &wattribs, True, &x, &y, &width, &height);
738
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200739 /* get colormap windows */
740 GetColormapWindows(wwin);
741
742 /*
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200743 * Setup the decoration/window attributes and
744 * geometry
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200745 */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200746 wWindowSetupInitialAttributes(wwin, &window_level, &workspace);
747
748 /* Make broken apps behave as a nice app. */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200749 if (WFLAGP(wwin, emulate_appicon))
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200750 wwin->main_window = wwin->client_win;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200751
752 fixLeaderProperties(wwin);
753
754 wwin->orig_main_window = wwin->main_window;
755
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200756 if (wwin->flags.is_gnustep)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200757 WSETUFLAG(wwin, shared_appicon, 0);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200758
759 if (wwin->main_window) {
760 extern Atom _XA_WINDOWMAKER_MENU;
761 XTextProperty text_prop;
762
763 if (XGetTextProperty(dpy, wwin->main_window, &text_prop, _XA_WINDOWMAKER_MENU)) {
764 WSETUFLAG(wwin, shared_appicon, 0);
765 }
766 }
767
9318a7f4
BJ
Brad Jorsch2010-09-15 12:59:00 -0400768 if (wwin->flags.is_dockapp)
769 WSETUFLAG(wwin, shared_appicon, 0);
770
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200771 if (!withdraw && wwin->main_window && WFLAGP(wwin, shared_appicon)) {
772 char *buffer, *instance, *class;
773 WFakeGroupLeader *fPtr;
774 int index;
672c42cc dan2001-12-17 04:02:33 +0000775
c8b3933c dan2001-12-18 05:18:35 +0000776#define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
777
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200778 /* // only enter here if PropGetWMClass() succeds */
779 PropGetWMClass(wwin->main_window, &class, &instance);
780 buffer = StrConcatDot(instance, class);
781
782 index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void *)buffer);
783 if (index != WANotFound) {
784 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
785 if (fPtr->retainCount == 0) {
786 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window,
787 instance, class);
788 }
789 fPtr->retainCount++;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200790 if (fPtr->origLeader == None) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200791 if (ADEQUATE(wwin->main_window)) {
792 fPtr->retainCount++;
793 fPtr->origLeader = wwin->main_window;
794 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200795 }
796 wwin->fake_group = fPtr;
797 /*wwin->group_id = fPtr->leader; */
798 wwin->main_window = fPtr->leader;
799 wfree(buffer);
800 } else {
801 fPtr = (WFakeGroupLeader *) wmalloc(sizeof(WFakeGroupLeader));
802
803 fPtr->identifier = buffer;
804 fPtr->leader = createFakeWindowGroupLeader(scr, wwin->main_window, instance, class);
805 fPtr->origLeader = None;
806 fPtr->retainCount = 1;
807
808 WMAddToArray(scr->fakeGroupLeaders, fPtr);
672c42cc dan2001-12-17 04:02:33 +0000809
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200810 if (ADEQUATE(wwin->main_window)) {
811 fPtr->retainCount++;
812 fPtr->origLeader = wwin->main_window;
813 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200814 wwin->fake_group = fPtr;
815 /*wwin->group_id = fPtr->leader; */
816 wwin->main_window = fPtr->leader;
817 }
818 if (instance)
819 XFree(instance);
820 if (class)
821 XFree(class);
c8b3933c dan2001-12-18 05:18:35 +0000822#undef ADEQUATE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200823 }
824
825 /*
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200826 * Setup the initial state of the window
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200827 */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200828 if (WFLAGP(wwin, start_miniaturized) && !WFLAGP(wwin, no_miniaturizable))
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200829 wwin->flags.miniaturized = 1;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200830
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200831 if (WFLAGP(wwin, start_maximized) && IS_RESIZABLE(wwin))
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200832 wwin->flags.maximized = MAX_VERTICAL | MAX_HORIZONTAL;
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200833
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200834 wNETWMCheckInitialClientState(wwin);
0261c326 dan1999-01-06 15:22:33 +0000835
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200836 /* apply previous state if it exists and we're in startup */
837 if (scr->flags.startup && wm_state >= 0) {
838
839 if (wm_state == IconicState) {
840
841 wwin->flags.miniaturized = 1;
842
843 } else if (wm_state == WithdrawnState) {
844
845 withdraw = True;
846 }
847 }
848
849 /* if there is a saved state (from file), restore it */
850 win_state = NULL;
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200851 if (wwin->main_window != None)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200852 win_state = (WWindowState *) wWindowGetSavedState(wwin->main_window);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200853 else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200854 win_state = (WWindowState *) wWindowGetSavedState(window);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200855
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200856 if (win_state && !withdraw) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200857 if (win_state->state->hidden > 0)
858 wwin->flags.hidden = win_state->state->hidden;
859
860 if (win_state->state->shaded > 0 && !WFLAGP(wwin, no_shadeable))
861 wwin->flags.shaded = win_state->state->shaded;
862
863 if (win_state->state->miniaturized > 0 && !WFLAGP(wwin, no_miniaturizable)) {
864 wwin->flags.miniaturized = win_state->state->miniaturized;
865 }
866
867 if (!IS_OMNIPRESENT(wwin)) {
868 int w = wDefaultGetStartWorkspace(scr, wwin->wm_instance,
869 wwin->wm_class);
870 if (w < 0 || w >= scr->workspace_count) {
871 workspace = win_state->state->workspace;
872 if (workspace >= scr->workspace_count)
873 workspace = scr->current_workspace;
874 } else {
875 workspace = w;
876 }
877 } else {
878 workspace = scr->current_workspace;
879 }
880 }
881
882 /* if we're restarting, restore saved state (from hints).
883 * This will overwrite previous */
884 {
885 WSavedState *wstate;
886
887 if (getSavedState(window, &wstate)) {
888 wwin->flags.shaded = wstate->shaded;
889 wwin->flags.hidden = wstate->hidden;
890 wwin->flags.miniaturized = wstate->miniaturized;
891 wwin->flags.maximized = wstate->maximized;
892 if (wwin->flags.maximized) {
893 wwin->old_geometry.x = wstate->x;
894 wwin->old_geometry.y = wstate->y;
895 wwin->old_geometry.width = wstate->w;
896 wwin->old_geometry.height = wstate->h;
897 }
898
899 workspace = wstate->workspace;
900 } else {
901 wstate = NULL;
902 }
903
904 /* restore window shortcut */
905 if (wstate != NULL || win_state != NULL) {
906 unsigned mask = 0;
907
908 if (win_state != NULL)
909 mask = win_state->state->window_shortcuts;
910
911 if (wstate != NULL && mask == 0)
912 mask = wstate->window_shortcuts;
913
914 if (mask > 0) {
915 int i;
916
917 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
918 if (mask & (1 << i)) {
919 if (!scr->shortcutWindows[i])
920 scr->shortcutWindows[i] = WMCreateArray(4);
921
922 WMAddToArray(scr->shortcutWindows[i], wwin);
923 }
924 }
925 }
926 }
347e804b Carlos R. Mafra2009-10-11 23:30:41 +0200927 if (wstate != NULL)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200928 wfree(wstate);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200929 }
930
931 /* don't let transients start miniaturized if their owners are not */
932 if (transientOwner && !transientOwner->flags.miniaturized && wwin->flags.miniaturized && !withdraw) {
933 wwin->flags.miniaturized = 0;
934 if (wwin->wm_hints)
935 wwin->wm_hints->initial_state = NormalState;
936 }
937
938 /* set workspace on which the window starts */
939 if (workspace >= 0) {
940 if (workspace > scr->workspace_count - 1) {
941 workspace = workspace % scr->workspace_count;
942 }
943 } else {
944 int w;
945
946 w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, wwin->wm_class);
947
948 if (w >= 0 && w < scr->workspace_count && !(IS_OMNIPRESENT(wwin))) {
949
950 workspace = w;
951
952 } else {
953 if (wPreferences.open_transients_with_parent && transientOwner) {
954
955 workspace = transientOwner->frame->workspace;
956
957 } else {
958
959 workspace = scr->current_workspace;
960 }
961 }
962 }
963
964 /* setup window geometry */
965 if (win_state && win_state->state->w > 0) {
966 width = win_state->state->w;
967 height = win_state->state->h;
968 }
969 wWindowConstrainSize(wwin, &width, &height);
970
971 /* do not ask for window placement if the window is
972 * transient, during startup, if the initial workspace is another one
973 * or if the window wants to start iconic.
974 * If geometry was saved, restore it. */
975 {
976 Bool dontBring = False;
977
978 if (win_state && win_state->state->w > 0) {
979 x = win_state->state->x;
980 y = win_state->state->y;
981 } else if ((wwin->transient_for == None || wPreferences.window_placement != WPM_MANUAL)
982 && !scr->flags.startup
983 && workspace == scr->current_workspace
984 && !wwin->flags.miniaturized
985 && !wwin->flags.maximized && !(wwin->normal_hints->flags & (USPosition | PPosition))) {
986
987 if (transientOwner && transientOwner->flags.mapped) {
988 int offs = WMAX(20, 2 * transientOwner->frame->top_width);
989 WMRect rect;
990 int head;
991
992 x = transientOwner->frame_x +
993 abs((transientOwner->frame->core->width - width) / 2) + offs;
994 y = transientOwner->frame_y +
995 abs((transientOwner->frame->core->height - height) / 3) + offs;
996
997 /*
998 * limit transient windows to be inside their parent's head
999 */
1000 rect.pos.x = transientOwner->frame_x;
1001 rect.pos.y = transientOwner->frame_y;
1002 rect.size.width = transientOwner->frame->core->width;
1003 rect.size.height = transientOwner->frame->core->height;
1004
1005 head = wGetHeadForRect(scr, rect);
1006 rect = wGetRectForHead(scr, head);
1007
1008 if (x < rect.pos.x)
1009 x = rect.pos.x;
1010 else if (x + width > rect.pos.x + rect.size.width)
1011 x = rect.pos.x + rect.size.width - width;
1012
1013 if (y < rect.pos.y)
1014 y = rect.pos.y;
1015 else if (y + height > rect.pos.y + rect.size.height)
1016 y = rect.pos.y + rect.size.height - height;
1017
1018 } else {
1019 PlaceWindow(wwin, &x, &y, width, height);
1020 }
1021 if (wPreferences.window_placement == WPM_MANUAL) {
1022 dontBring = True;
1023 }
1024 } else if (scr->xine_info.count && (wwin->normal_hints->flags & PPosition)) {
1025 int head, flags;
1026 WMRect rect;
1027 int reposition = 0;
1028
1029 /*
1030 * Make spash screens come out in the center of a head
1031 * trouble is that most splashies never get here
1032 * they are managed trough atoms but god knows where.
1033 * Dan, do you know ? -peter
1034 *
1035 * Most of them are not managed, they have set
1036 * OverrideRedirect, which means we can't do anything about
1037 * them. -alfredo
1038 */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001039 {
1040 /*
1041 * xinerama checks for: across head and dead space
1042 */
1043 rect.pos.x = x;
1044 rect.pos.y = y;
1045 rect.size.width = width;
1046 rect.size.height = height;
6830b057 dan2004-10-12 21:28:27 +00001047
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001048 head = wGetRectPlacementInfo(scr, rect, &flags);
6830b057 dan2004-10-12 21:28:27 +00001049
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001050 if (flags & XFLAG_DEAD)
1051 reposition = 1;
6830b057 dan2004-10-12 21:28:27 +00001052
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001053 if (flags & XFLAG_MULTIPLE)
1054 reposition = 2;
1055 }
9aca0d5f dan2004-10-12 01:34:32 +00001056
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001057 switch (reposition) {
1058 case 1:
1059 head = wGetHeadForPointerLocation(scr);
1060 rect = wGetRectForHead(scr, head);
9aca0d5f dan2004-10-12 01:34:32 +00001061
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001062 x = rect.pos.x + (x * rect.size.width) / scr->scr_width;
1063 y = rect.pos.y + (y * rect.size.height) / scr->scr_height;
1064 break;
9aca0d5f dan2004-10-12 01:34:32 +00001065
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001066 case 2:
1067 rect = wGetRectForHead(scr, head);
9aca0d5f dan2004-10-12 01:34:32 +00001068
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001069 if (x < rect.pos.x)
1070 x = rect.pos.x;
1071 else if (x + width > rect.pos.x + rect.size.width)
1072 x = rect.pos.x + rect.size.width - width;
9aca0d5f dan2004-10-12 01:34:32 +00001073
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001074 if (y < rect.pos.y)
1075 y = rect.pos.y;
1076 else if (y + height > rect.pos.y + rect.size.height)
1077 y = rect.pos.y + rect.size.height - height;
9aca0d5f dan2004-10-12 01:34:32 +00001078
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001079 break;
9aca0d5f dan2004-10-12 01:34:32 +00001080
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001081 default:
1082 break;
1083 }
1084 }
345d980b dan1998-11-27 12:26:46 +00001085
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001086 if (WFLAGP(wwin, dont_move_off) && dontBring)
1087 wScreenBringInside(scr, &x, &y, width, height);
1088 }
088c0ac2 dan1999-03-09 14:58:01 +00001089
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001090 wNETWMPositionSplash(wwin, &x, &y, width, height);
9aca0d5f dan2004-10-12 01:34:32 +00001091
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001092 if (wwin->flags.urgent) {
1093 if (!IS_OMNIPRESENT(wwin))
1094 wwin->flags.omnipresent ^= 1;
1095 }
1096
1097 /*
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001098 * Create frame, borders and do reparenting
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001099 */
1100 foo = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
c28f3b2c id1999-05-20 23:30:53 +00001101#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001102 if (wPreferences.modelock)
1103 foo |= WFF_LANGUAGE_BUTTON;
c28f3b2c id1999-05-20 23:30:53 +00001104#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001105 if (HAS_TITLEBAR(wwin))
1106 foo |= WFF_TITLEBAR;
1107 if (HAS_RESIZEBAR(wwin))
1108 foo |= WFF_RESIZEBAR;
1109 if (HAS_BORDER(wwin))
1110 foo |= WFF_BORDER;
1111
1112 wwin->frame = wFrameWindowCreate(scr, window_level,
1113 x, y, width, height,
1114 &wPreferences.window_title_clearance, foo,
1115 scr->window_title_texture,
1116 scr->resizebar_texture, scr->window_title_color, &scr->title_font);
1117
1118 wwin->frame->flags.is_client_window_frame = 1;
1119 wwin->frame->flags.justification = wPreferences.title_justification;
1120
1121 /* setup button images */
1122 wWindowUpdateButtonImages(wwin);
1123
1124 /* hide unused buttons */
1125 foo = 0;
1126 if (WFLAGP(wwin, no_close_button))
1127 foo |= WFF_RIGHT_BUTTON;
1128 if (WFLAGP(wwin, no_miniaturize_button))
1129 foo |= WFF_LEFT_BUTTON;
daaccf6f id1999-05-23 23:48:08 +00001130#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001131 if (WFLAGP(wwin, no_language_button) || WFLAGP(wwin, no_focusable))
1132 foo |= WFF_LANGUAGE_BUTTON;
daaccf6f id1999-05-23 23:48:08 +00001133#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001134 if (foo != 0)
1135 wFrameWindowHideButton(wwin->frame, foo);
416e3a82 dan1999-01-25 19:06:50 +00001136
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001137 wwin->frame->child = wwin;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001138 wwin->frame->workspace = workspace;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001139 wwin->frame->on_click_left = windowIconifyClick;
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001140
c28f3b2c id1999-05-20 23:30:53 +00001141#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001142 if (wPreferences.modelock)
1143 wwin->frame->on_click_language = windowLanguageClick;
c28f3b2c id1999-05-20 23:30:53 +00001144#endif
0261c326 dan1999-01-06 15:22:33 +00001145
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001146 wwin->frame->on_click_right = windowCloseClick;
1147 wwin->frame->on_dblclick_right = windowCloseDblClick;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001148 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1149 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001150 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
1151
1152 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001153 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window, 0, wwin->frame->top_width);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001154 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1155
1156 {
1157 int gx, gy;
1158
1159 wClientGetGravityOffsets(wwin, &gx, &gy);
1160
1161 /* if gravity is to the south, account for the border sizes */
1162 if (gy > 0)
1163 y -= wwin->frame->top_width + wwin->frame->bottom_width;
1164 }
1165
1166 /*
1167 * wWindowConfigure() will init the client window's size
1168 * (wwin->client.{width,height}) and all other geometry
1169 * related variables (frame_x,frame_y)
1170 */
1171 wWindowConfigure(wwin, x, y, width, height);
1172
1173 /* to make sure the window receives it's new position after reparenting */
1174 wWindowSynthConfigureNotify(wwin);
1175
1176 /*
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001177 * Setup descriptors and save window to internal
1178 * lists
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001179 */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001180 if (wwin->main_window != None) {
1181 WApplication *app;
1182 WWindow *leader;
1183
1184 /* Leader windows do not necessary set themselves as leaders.
1185 * If this is the case, point the leader of this window to
1186 * itself */
1187 leader = wWindowFor(wwin->main_window);
1188 if (leader && leader->main_window == None) {
1189 leader->main_window = leader->client_win;
1190 }
1191 app = wApplicationCreate(wwin);
1192 if (app) {
1193 app->last_workspace = workspace;
1194
1195 /*
1196 * Do application specific stuff, like setting application
1197 * wide attributes.
1198 */
1199
1200 if (wwin->flags.hidden) {
1201 /* if the window was set to hidden because it was hidden
1202 * in a previous incarnation and that state was restored */
1203 app->flags.hidden = 1;
1204 } else if (app->flags.hidden) {
1205 if (WFLAGP(app->main_window_desc, start_hidden)) {
1206 wwin->flags.hidden = 1;
1207 } else {
1208 wUnhideApplication(app, False, False);
1209 raise = True;
1210 }
1211 }
a257e165 Alexey I. Froloff2010-09-10 20:51:03 +04001212 wAppBounce(app);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001213 }
1214 }
1215
1216 /* setup the frame descriptor */
1217 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1218 wwin->frame->core->descriptor.parent = wwin;
1219 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
1220
1221 /* don't let windows go away if we die */
1222 XAddToSaveSet(dpy, window);
1223
1224 XLowerWindow(dpy, window);
1225
1226 /* if window is in this workspace and should be mapped, then map it */
1227 if (!wwin->flags.miniaturized && (workspace == scr->current_workspace || IS_OMNIPRESENT(wwin))
1228 && !wwin->flags.hidden && !withdraw) {
1229
1230 /* The following "if" is to avoid crashing of clients that expect
1231 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1232 * after the return from this function.
1233 */
1234 if (wwin->wm_hints && (wwin->wm_hints->flags & StateHint)) {
1235 wClientSetState(wwin, wwin->wm_hints->initial_state, None);
1236 } else {
1237 wClientSetState(wwin, NormalState, None);
1238 }
0261c326 dan1999-01-06 15:22:33 +00001239
9acdde00 kojima1999-03-20 02:42:48 +00001240#if 0
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001241 /* if not auto focus, then map the window under the currently
1242 * focused window */
416e3a82 dan1999-01-25 19:06:50 +00001243#define _WIDTH(w) (w)->frame->core->width
1244#define _HEIGHT(w) (w)->frame->core->height
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001245 if (!wPreferences.auto_focus && scr->focused_window
1246 && !scr->flags.startup && !transientOwner && ((wWindowObscuresWindow(wwin, scr->focused_window)
1247 && (_WIDTH(wwin) >
1248 (_WIDTH(scr->focused_window) * 5) / 3
1249 || _HEIGHT(wwin) >
1250 (_HEIGHT(scr->focused_window) * 5) / 3)
1251 && WINDOW_LEVEL(scr->focused_window) ==
1252 WINDOW_LEVEL(wwin))
1253 || wwin->flags.maximized)) {
1254 MoveInStackListUnder(scr->focused_window->frame->core, wwin->frame->core);
1255 }
416e3a82 dan1999-01-25 19:06:50 +00001256#undef _WIDTH
1257#undef _HEIGHT
1258
9acdde00 kojima1999-03-20 02:42:48 +00001259#endif
1260
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001261 if (wPreferences.superfluous && !wPreferences.no_animations
1262 && !scr->flags.startup && (wwin->transient_for == None || wwin->transient_for == scr->root_win)
1263 /*
1264 * The brain damaged idiotic non-click to focus modes will
1265 * have trouble with this because:
1266 *
1267 * 1. window is created and mapped by the client
1268 * 2. window is mapped by wmaker in small size
1269 * 3. window is animated to grow to normal size
1270 * 4. this function returns to normal event loop
1271 * 5. eventually, the EnterNotify event that would trigger
1272 * the window focusing (if the mouse is over that window)
1273 * will be processed by wmaker.
1274 * But since this event will be rather delayed
1275 * (step 3 has a large delay) the time when the event ocurred
1276 * and when it is processed, the client that owns that window
1277 * will reject the XSetInputFocus() for it.
1278 */
1279 && (wPreferences.focus_mode == WKF_CLICK || wPreferences.auto_focus)) {
1280 DoWindowBirth(wwin);
1281 }
1282
1283 wWindowMap(wwin);
1284 }
1285
1286 /* setup stacking descriptor */
1287 if (transientOwner) {
1288 wwin->frame->core->stacking->child_of = transientOwner->frame->core;
1289 } else {
1290 wwin->frame->core->stacking->child_of = NULL;
1291 }
1292
1293 if (!scr->focused_window) {
1294 /* first window on the list */
1295 wwin->next = NULL;
1296 wwin->prev = NULL;
1297 scr->focused_window = wwin;
1298 } else {
1299 WWindow *tmp;
1300
1301 /* add window at beginning of focus window list */
1302 tmp = scr->focused_window;
1303 while (tmp->prev)
1304 tmp = tmp->prev;
1305 tmp->prev = wwin;
1306 wwin->next = tmp;
1307 wwin->prev = NULL;
1308 }
1309
1310 /* raise is set to true if we un-hid the app when this window was born.
1311 * we raise, else old windows of this app will be above this new one. */
1312 if (raise) {
1313 wRaiseFrame(wwin->frame->core);
1314 }
1315
1316 /* Update name must come after WApplication stuff is done */
1317 wWindowUpdateName(wwin, title);
1318 if (title)
1319 XFree(title);
1320
1321 XUngrabServer(dpy);
1322
1323 /*
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001324 * Final preparations before window is ready to go
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001325 */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001326 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1327
1328 if (!wwin->flags.miniaturized && workspace == scr->current_workspace && !wwin->flags.hidden) {
1329 if (((transientOwner && transientOwner->flags.focused)
d74a90d1
RH
Ralf Hoffmann2009-12-04 15:01:14 +01001330 || wPreferences.auto_focus) && !WFLAGP(wwin, no_focusable)) {
1331
1332 /* only auto_focus if on same screen as mouse
1333 * (and same head for xinerama mode)
1334 * TODO: make it an option */
1335
1336 /*TODO add checking the head of the window, is it available? */
1337 short same_screen = 0, same_head = 1;
1338
1339 int foo;
1340 unsigned int bar;
1341 Window dummy;
1342
1343 if (XQueryPointer(dpy, scr->root_win, &dummy, &dummy,
1344 &foo, &foo, &foo, &foo, &bar) != False) {
1345 same_screen = 1;
1346 }
1347
1348 if (same_screen == 1 && same_head == 1) {
1349 wSetFocusTo(scr, wwin);
1350 }
1351 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001352 }
1353 wWindowResetMouseGrabs(wwin);
1354
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001355 if (!WFLAGP(wwin, no_bind_keys))
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001356 wWindowSetKeyGrabs(wwin);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001357
1358 WMPostNotificationName(WMNManaged, wwin, NULL);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001359 wColormapInstallForWindow(scr, scr->cmap_window);
1360
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001361 /* Setup Notification Observers */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001362 WMAddNotificationObserver(appearanceObserver, wwin, WNWindowAppearanceSettingsChanged, wwin);
1363
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001364 /* Cleanup temporary stuff */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001365 if (win_state)
1366 wWindowDeleteSavedState(win_state);
1367
1368 /* If the window must be withdrawed, then do it now.
1369 * Must do some optimization, 'though */
1370 if (withdraw) {
1371 wwin->flags.mapped = 0;
1372 wClientSetState(wwin, WithdrawnState, None);
1373 wUnmanageWindow(wwin, True, False);
1374 wwin = NULL;
1375 }
1376
1377 return wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001378}
1379
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001380WWindow *wManageInternalWindow(WScreen *scr, Window window, Window owner,
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001381 char *title, int x, int y, int width, int height)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001382{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001383 WWindow *wwin;
1384 int foo;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001385
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001386 wwin = wWindowCreate();
9df0e167 kojima1999-04-03 03:51:17 +00001387
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001388 WMAddNotificationObserver(appearanceObserver, wwin, WNWindowAppearanceSettingsChanged, wwin);
0261c326 dan1999-01-06 15:22:33 +00001389
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001390 wwin->flags.internal_window = 1;
0261c326 dan1999-01-06 15:22:33 +00001391
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001392 WSETUFLAG(wwin, omnipresent, 1);
1393 WSETUFLAG(wwin, no_shadeable, 1);
1394 WSETUFLAG(wwin, no_resizable, 1);
1395 WSETUFLAG(wwin, no_miniaturizable, 1);
9aca0d5f dan2004-10-12 01:34:32 +00001396
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001397 wwin->focus_mode = WFM_PASSIVE;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001398 wwin->client_win = window;
1399 wwin->screen_ptr = scr;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001400 wwin->transient_for = owner;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001401 wwin->client.x = x;
1402 wwin->client.y = y;
1403 wwin->client.width = width;
1404 wwin->client.height = height;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001405 wwin->frame_x = wwin->client.x;
1406 wwin->frame_y = wwin->client.y;
9aca0d5f dan2004-10-12 01:34:32 +00001407
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001408 foo = WFF_RIGHT_BUTTON | WFF_BORDER;
1409 foo |= WFF_TITLEBAR;
c28f3b2c id1999-05-20 23:30:53 +00001410#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001411 foo |= WFF_LANGUAGE_BUTTON;
c28f3b2c id1999-05-20 23:30:53 +00001412#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +00001413
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001414 wwin->frame = wFrameWindowCreate(scr, WMFloatingLevel,
1415 wwin->frame_x, wwin->frame_y,
1416 width, height,
1417 &wPreferences.window_title_clearance, foo,
1418 scr->window_title_texture,
1419 scr->resizebar_texture, scr->window_title_color, &scr->title_font);
9aca0d5f dan2004-10-12 01:34:32 +00001420
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001421 XSaveContext(dpy, window, wWinContext, (XPointer) & wwin->client_descriptor);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001422
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001423 wwin->frame->flags.is_client_window_frame = 1;
1424 wwin->frame->flags.justification = wPreferences.title_justification;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001425
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001426 wFrameWindowChangeTitle(wwin->frame, title);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001427
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001428 /* setup button images */
1429 wWindowUpdateButtonImages(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001430
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001431 /* hide buttons */
1432 wFrameWindowHideButton(wwin->frame, WFF_RIGHT_BUTTON);
9aca0d5f dan2004-10-12 01:34:32 +00001433
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001434 wwin->frame->child = wwin;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001435 wwin->frame->workspace = wwin->screen_ptr->current_workspace;
9aca0d5f dan2004-10-12 01:34:32 +00001436
b3112e2b id1999-05-22 21:30:35 +00001437#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001438 if (wPreferences.modelock)
1439 wwin->frame->on_click_language = windowLanguageClick;
c28f3b2c id1999-05-20 23:30:53 +00001440#endif
9aca0d5f dan2004-10-12 01:34:32 +00001441
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001442 wwin->frame->on_click_right = windowCloseClick;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001443 wwin->frame->on_mousedown_titlebar = titlebarMouseDown;
1444 wwin->frame->on_dblclick_titlebar = titlebarDblClick;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001445 wwin->frame->on_mousedown_resizebar = resizebarMouseDown;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001446 wwin->client.y += wwin->frame->top_width;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001447
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001448 XReparentWindow(dpy, wwin->client_win, wwin->frame->core->window, 0, wwin->frame->top_width);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001449 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, wwin->client.width, wwin->client.height);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001450
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001451 /* setup the frame descriptor */
1452 wwin->frame->core->descriptor.handle_mousedown = frameMouseDown;
1453 wwin->frame->core->descriptor.parent = wwin;
1454 wwin->frame->core->descriptor.parent_type = WCLASS_WINDOW;
9aca0d5f dan2004-10-12 01:34:32 +00001455
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001456 XLowerWindow(dpy, window);
1457 XMapSubwindows(dpy, wwin->frame->core->window);
9aca0d5f dan2004-10-12 01:34:32 +00001458
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001459 /* setup stacking descriptor */
1460 if (wwin->transient_for != None && wwin->transient_for != scr->root_win) {
1461 WWindow *tmp;
1462 tmp = wWindowFor(wwin->transient_for);
1463 if (tmp)
1464 wwin->frame->core->stacking->child_of = tmp->frame->core;
1465 } else {
1466 wwin->frame->core->stacking->child_of = NULL;
1467 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001468
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001469 if (!scr->focused_window) {
1470 /* first window on the list */
1471 wwin->next = NULL;
1472 wwin->prev = NULL;
1473 scr->focused_window = wwin;
1474 } else {
1475 WWindow *tmp;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001476
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001477 /* add window at beginning of focus window list */
1478 tmp = scr->focused_window;
1479 while (tmp->prev)
1480 tmp = tmp->prev;
1481 tmp->prev = wwin;
1482 wwin->next = tmp;
1483 wwin->prev = NULL;
1484 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001485
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001486 if (wwin->flags.is_gnustep == 0)
1487 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001488
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001489 /* if (wPreferences.auto_focus) */
1490 wSetFocusTo(scr, wwin);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001491 wWindowResetMouseGrabs(wwin);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001492 wWindowSetKeyGrabs(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001493
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001494 return wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001495}
1496
9d2e6ef9 scottc1998-09-29 22:36:29 +00001497/*
9aca0d5f dan2004-10-12 01:34:32 +00001498 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +00001499 * wUnmanageWindow--
1500 * Removes the frame window from a window and destroys all data
1501 * related to it. The window will be reparented back to the root window
1502 * if restore is True.
9aca0d5f dan2004-10-12 01:34:32 +00001503 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00001504 * Side effects:
1505 * Everything related to the window is destroyed and the window
1506 * is removed from the window lists. Focus is set to the previous on the
1507 * window list.
9aca0d5f dan2004-10-12 01:34:32 +00001508 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +00001509 */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001510void wUnmanageWindow(WWindow *wwin, Bool restore, Bool destroyed)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001511{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001512 WCoreWindow *frame = wwin->frame->core;
1513 WWindow *owner = NULL;
1514 WWindow *newFocusedWindow = NULL;
1515 int wasFocused;
1516 WScreen *scr = wwin->screen_ptr;
1517
1518 /* First close attribute editor window if open */
1519 if (wwin->flags.inspector_open) {
1520 wCloseInspectorForWindow(wwin);
1521 }
1522
1523 /* Close window menu if it's open for this window */
1524 if (wwin->flags.menu_open_for_me) {
1525 CloseWindowMenu(scr);
1526 }
1527
1528 if (!destroyed) {
1529 if (!wwin->flags.internal_window)
1530 XRemoveFromSaveSet(dpy, wwin->client_win);
1531
1532 XSelectInput(dpy, wwin->client_win, NoEventMask);
1533
1534 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
1535 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->client_win);
1536 }
1537
1538 XUnmapWindow(dpy, frame->window);
1539
1540 XUnmapWindow(dpy, wwin->client_win);
1541
1542 /* deselect window */
1543 wSelectWindow(wwin, False);
1544
1545 /* remove all pending events on window */
1546 /* I think this only matters for autoraise */
1547 if (wPreferences.raise_delay)
1548 WMDeleteTimerWithClientData(wwin->frame->core);
1549
1550 XFlush(dpy);
1551
1552 /* reparent the window back to the root */
1553 if (restore)
1554 wClientRestore(wwin);
1555
1556 if (wwin->transient_for != scr->root_win) {
1557 owner = wWindowFor(wwin->transient_for);
1558 if (owner) {
1559 if (!owner->flags.semi_focused) {
1560 owner = NULL;
1561 } else {
1562 owner->flags.semi_focused = 0;
1563 }
1564 }
1565 }
1566
1567 wasFocused = wwin->flags.focused;
1568
1569 /* remove from window focus list */
1570 if (!wwin->prev && !wwin->next) {
1571 /* was the only window */
1572 scr->focused_window = NULL;
1573 newFocusedWindow = NULL;
1574 } else {
1575 WWindow *tmp;
1576
1577 if (wwin->prev)
1578 wwin->prev->next = wwin->next;
1579 if (wwin->next)
1580 wwin->next->prev = wwin->prev;
1581 else {
1582 scr->focused_window = wwin->prev;
1583 scr->focused_window->next = NULL;
1584 }
1585
1586 if (wPreferences.focus_mode == WKF_CLICK) {
1587
1588 /* if in click to focus mode and the window
1589 * was a transient, focus the owner window
1590 */
1591 tmp = NULL;
1592 if (wPreferences.focus_mode == WKF_CLICK) {
1593 tmp = wWindowFor(wwin->transient_for);
1594 if (tmp && (!tmp->flags.mapped || WFLAGP(tmp, no_focusable))) {
1595 tmp = NULL;
1596 }
1597 }
1598 /* otherwise, focus the next one in the focus list */
1599 if (!tmp) {
1600 tmp = scr->focused_window;
1601 while (tmp) { /* look for one in the window list first */
1602 if (!WFLAGP(tmp, no_focusable) && !WFLAGP(tmp, skip_window_list)
1603 && (tmp->flags.mapped || tmp->flags.shaded))
1604 break;
1605 tmp = tmp->prev;
1606 }
1607 if (!tmp) { /* if unsuccessful, choose any focusable window */
1608 tmp = scr->focused_window;
1609 while (tmp) {
1610 if (!WFLAGP(tmp, no_focusable)
1611 && (tmp->flags.mapped || tmp->flags.shaded))
1612 break;
1613 tmp = tmp->prev;
1614 }
1615 }
1616 }
1617
1618 newFocusedWindow = tmp;
1619
1620 } else if (wPreferences.focus_mode == WKF_SLOPPY) {
1621 unsigned int mask;
1622 int foo;
1623 Window bar, win;
1624
1625 /* This is to let the root window get the keyboard input
1626 * if Sloppy focus mode and no other window get focus.
1627 * This way keybindings will not freeze.
1628 */
1629 tmp = NULL;
1630 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1631 tmp = wWindowFor(win);
1632 if (tmp == wwin)
1633 tmp = NULL;
1634 newFocusedWindow = tmp;
1635 } else {
1636 newFocusedWindow = NULL;
1637 }
1638 }
1639
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001640 if (!wwin->flags.internal_window)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001641 WMPostNotificationName(WMNUnmanaged, wwin, NULL);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001642 if (wasFocused) {
1643 if (newFocusedWindow != owner && owner) {
1644 if (wwin->flags.is_gnustep == 0)
1645 wFrameWindowChangeState(owner->frame, WS_UNFOCUSED);
1646 }
1647 wSetFocusTo(scr, newFocusedWindow);
1648 }
1649 wWindowDestroy(wwin);
1650 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001651}
1652
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001653void wWindowMap(WWindow *wwin)
e7495baf dan1999-02-17 11:06:40 +00001654{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001655 XMapWindow(dpy, wwin->frame->core->window);
1656 if (!wwin->flags.shaded) {
1657 /* window will be remapped when getting MapNotify */
1658 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
1659 XMapWindow(dpy, wwin->client_win);
1660 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
1661
1662 wwin->flags.mapped = 1;
1663 }
e7495baf dan1999-02-17 11:06:40 +00001664}
1665
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001666void wWindowUnmap(WWindow *wwin)
e7495baf dan1999-02-17 11:06:40 +00001667{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001668 wwin->flags.mapped = 0;
e7495baf dan1999-02-17 11:06:40 +00001669
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001670 /* prevent window withdrawal when getting UnmapNotify */
1671 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
1672 XUnmapWindow(dpy, wwin->client_win);
1673 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
e7495baf dan1999-02-17 11:06:40 +00001674
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001675 XUnmapWindow(dpy, wwin->frame->core->window);
e7495baf dan1999-02-17 11:06:40 +00001676}
1677
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001678void wWindowFocus(WWindow *wwin, WWindow *owin)
59eb9475 dan1998-11-03 12:53:26 +00001679{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001680 WWindow *nowner;
1681 WWindow *oowner;
e7495baf dan1999-02-17 11:06:40 +00001682
59eb9475 dan1998-11-03 12:53:26 +00001683#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001684 if (wPreferences.modelock) {
1685 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1686 }
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001687#endif /* KEEP_XKB_LOCK_STATUS */
59eb9475 dan1998-11-03 12:53:26 +00001688
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001689 wwin->flags.semi_focused = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001690
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001691 if (wwin->flags.is_gnustep == 0)
1692 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001693
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001694 wwin->flags.focused = 1;
e7495baf dan1999-02-17 11:06:40 +00001695
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001696 wWindowResetMouseGrabs(wwin);
7f018497 kojima1999-04-24 20:08:20 +00001697
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001698 WMPostNotificationName(WMNChangedFocus, wwin, (void *)True);
0261c326 dan1999-01-06 15:22:33 +00001699
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001700 if (owin == wwin || !owin)
1701 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001702
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001703 nowner = wWindowFor(wwin->transient_for);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001704
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001705 /* new window is a transient for the old window */
1706 if (nowner == owin) {
1707 owin->flags.semi_focused = 1;
1708 wWindowUnfocus(nowner);
1709 return;
1710 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001711
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001712 oowner = wWindowFor(owin->transient_for);
9eb4f894 kojima1999-04-17 23:11:34 +00001713
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001714 /* new window is owner of old window */
1715 if (wwin == oowner) {
1716 wWindowUnfocus(owin);
1717 return;
1718 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001719
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001720 if (!nowner) {
1721 wWindowUnfocus(owin);
1722 return;
1723 }
416e3a82 dan1999-01-25 19:06:50 +00001724
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001725 /* new window has same owner of old window */
1726 if (oowner == nowner) {
1727 /* prevent unfocusing of owner */
1728 oowner->flags.semi_focused = 0;
1729 wWindowUnfocus(owin);
1730 oowner->flags.semi_focused = 1;
416e3a82 dan1999-01-25 19:06:50 +00001731
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001732 return;
1733 }
416e3a82 dan1999-01-25 19:06:50 +00001734
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001735 /* nowner != NULL && oowner != nowner */
1736 nowner->flags.semi_focused = 1;
1737 wWindowUnfocus(nowner);
1738 wWindowUnfocus(owin);
416e3a82 dan1999-01-25 19:06:50 +00001739}
1740
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001741void wWindowUnfocus(WWindow *wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001742{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001743 CloseWindowMenu(wwin->screen_ptr);
1744
1745 if (wwin->flags.is_gnustep == 0)
1746 wFrameWindowChangeState(wwin->frame, wwin->flags.semi_focused ? WS_PFOCUSED : WS_UNFOCUSED);
1747
1748 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1749 WWindow *owner;
1750 owner = wWindowFor(wwin->transient_for);
1751 if (owner && owner->flags.semi_focused) {
1752 owner->flags.semi_focused = 0;
1753 if (owner->flags.mapped || owner->flags.shaded) {
1754 wWindowUnfocus(owner);
1755 wFrameWindowPaint(owner->frame);
1756 }
1757 }
1758 }
1759 wwin->flags.focused = 0;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001760 wWindowResetMouseGrabs(wwin);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001761 WMPostNotificationName(WMNChangedFocus, wwin, (void *)False);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001762}
1763
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001764void wWindowUpdateName(WWindow *wwin, char *newTitle)
7a491db6 kojima2001-02-11 02:18:26 +00001765{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001766 char *title;
9aca0d5f dan2004-10-12 01:34:32 +00001767
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001768 if (!wwin->frame)
1769 return;
9aca0d5f dan2004-10-12 01:34:32 +00001770
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001771 wwin->flags.wm_name_changed = 1;
9aca0d5f dan2004-10-12 01:34:32 +00001772
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001773 if (!newTitle) {
1774 /* the hint was removed */
1775 title = DEF_WINDOW_TITLE;
1776 } else {
1777 title = newTitle;
1778 }
5ef342d9 kojima2001-09-06 21:42:28 +00001779
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001780 if (wFrameWindowChangeTitle(wwin->frame, title)) {
1781 WMPostNotificationName(WMNChangedName, wwin, NULL);
1782 }
7a491db6 kojima2001-02-11 02:18:26 +00001783}
1784
9d2e6ef9 scottc1998-09-29 22:36:29 +00001785/*
1786 *----------------------------------------------------------------------
9aca0d5f dan2004-10-12 01:34:32 +00001787 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00001788 * wWindowConstrainSize--
1789 * Constrains size for the client window, taking the maximal size,
1790 * window resize increments and other size hints into account.
9aca0d5f dan2004-10-12 01:34:32 +00001791 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00001792 * Returns:
9aca0d5f dan2004-10-12 01:34:32 +00001793 * The closest size to what was given that the client window can
9d2e6ef9 scottc1998-09-29 22:36:29 +00001794 * have.
9aca0d5f dan2004-10-12 01:34:32 +00001795 *
1796 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +00001797 */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001798void wWindowConstrainSize(WWindow *wwin, unsigned int *nwidth, unsigned int *nheight)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001799{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001800 int width = (int)*nwidth;
1801 int height = (int)*nheight;
1802 int winc = 1;
1803 int hinc = 1;
1804 int minW = 1, minH = 1;
1805 int maxW = wwin->screen_ptr->scr_width * 2;
1806 int maxH = wwin->screen_ptr->scr_height * 2;
1807 int minAX = -1, minAY = -1;
1808 int maxAX = -1, maxAY = -1;
1809 int baseW = 0;
1810 int baseH = 0;
1811
1812 if (wwin->normal_hints) {
1813 winc = wwin->normal_hints->width_inc;
1814 hinc = wwin->normal_hints->height_inc;
1815 minW = wwin->normal_hints->min_width;
1816 minH = wwin->normal_hints->min_height;
1817 maxW = wwin->normal_hints->max_width;
1818 maxH = wwin->normal_hints->max_height;
1819 if (wwin->normal_hints->flags & PAspect) {
1820 minAX = wwin->normal_hints->min_aspect.x;
1821 minAY = wwin->normal_hints->min_aspect.y;
1822 maxAX = wwin->normal_hints->max_aspect.x;
1823 maxAY = wwin->normal_hints->max_aspect.y;
1824 }
1825
1826 baseW = wwin->normal_hints->base_width;
1827 baseH = wwin->normal_hints->base_height;
1828 }
1829
1830 if (width < minW)
1831 width = minW;
1832 if (height < minH)
1833 height = minH;
1834
1835 if (width > maxW)
1836 width = maxW;
1837 if (height > maxH)
1838 height = maxH;
1839
1840 /* aspect ratio code borrowed from olwm */
1841 if (minAX > 0) {
1842 /* adjust max aspect ratio */
1843 if (!(maxAX == 1 && maxAY == 1) && width * maxAY > height * maxAX) {
1844 if (maxAX > maxAY) {
1845 height = (width * maxAY) / maxAX;
1846 if (height > maxH) {
1847 height = maxH;
1848 width = (height * maxAX) / maxAY;
1849 }
1850 } else {
1851 width = (height * maxAX) / maxAY;
1852 if (width > maxW) {
1853 width = maxW;
1854 height = (width * maxAY) / maxAX;
1855 }
1856 }
1857 }
1858
1859 /* adjust min aspect ratio */
1860 if (!(minAX == 1 && minAY == 1) && width * minAY < height * minAX) {
1861 if (minAX > minAY) {
1862 height = (width * minAY) / minAX;
1863 if (height < minH) {
1864 height = minH;
1865 width = (height * minAX) / minAY;
1866 }
1867 } else {
1868 width = (height * minAX) / minAY;
1869 if (width < minW) {
1870 width = minW;
1871 height = (width * minAY) / minAX;
1872 }
1873 }
1874 }
1875 }
1876
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001877 if (baseW != 0)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001878 width = (((width - baseW) / winc) * winc) + baseW;
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001879 else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001880 width = (((width - minW) / winc) * winc) + minW;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001881
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001882 if (baseH != 0)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001883 height = (((height - baseH) / hinc) * hinc) + baseH;
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001884 else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001885 height = (((height - minH) / hinc) * hinc) + minH;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001886
1887 /* broken stupid apps may cause preposterous values for these.. */
1888 if (width > 0)
1889 *nwidth = width;
1890 if (height > 0)
1891 *nheight = height;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001892}
1893
347e804b
CM
Carlos R. Mafra2009-10-11 23:30:41 +02001894void wWindowCropSize(WWindow *wwin, unsigned int maxW, unsigned int maxH,
1895 unsigned int *width, unsigned int *height)
7e1f0e1e kojima2001-06-06 18:20:23 +00001896{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001897 int baseW = 0, baseH = 0;
1898 int winc = 1, hinc = 1;
7e1f0e1e kojima2001-06-06 18:20:23 +00001899
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001900 if (wwin->normal_hints) {
1901 baseW = wwin->normal_hints->base_width;
1902 baseH = wwin->normal_hints->base_height;
9aca0d5f dan2004-10-12 01:34:32 +00001903
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001904 winc = wwin->normal_hints->width_inc;
1905 hinc = wwin->normal_hints->height_inc;
1906 }
7e1f0e1e kojima2001-06-06 18:20:23 +00001907
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001908 if (*width > maxW)
1909 *width = maxW - (maxW - baseW) % winc;
7e1f0e1e kojima2001-06-06 18:20:23 +00001910
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001911 if (*height > maxH)
1912 *height = maxH - (maxH - baseH) % hinc;
7e1f0e1e kojima2001-06-06 18:20:23 +00001913}
1914
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001915void wWindowChangeWorkspace(WWindow *wwin, int workspace)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001916{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001917 WScreen *scr = wwin->screen_ptr;
1918 WApplication *wapp;
1919 int unmap = 0;
1920
1921 if (workspace >= scr->workspace_count || workspace < 0 || workspace == wwin->frame->workspace)
1922 return;
1923
1924 if (workspace != scr->current_workspace) {
1925 /* Sent to other workspace. Unmap window */
1926 if ((wwin->flags.mapped
1927 || wwin->flags.shaded || (wwin->flags.miniaturized && !wPreferences.sticky_icons))
1928 && !IS_OMNIPRESENT(wwin) && !wwin->flags.changing_workspace) {
1929
1930 wapp = wApplicationOf(wwin->main_window);
1931 if (wapp) {
1932 wapp->last_workspace = workspace;
1933 }
1934 if (wwin->flags.miniaturized) {
1935 if (wwin->icon) {
1936 XUnmapWindow(dpy, wwin->icon->core->window);
1937 wwin->icon->mapped = 0;
1938 }
1939 } else {
1940 unmap = 1;
1941 wSetFocusTo(scr, NULL);
1942 }
1943 }
1944 } else {
1945 /* brought to current workspace. Map window */
1946 if (wwin->flags.miniaturized && !wPreferences.sticky_icons) {
1947 if (wwin->icon) {
1948 XMapWindow(dpy, wwin->icon->core->window);
1949 wwin->icon->mapped = 1;
1950 }
1951 } else if (!wwin->flags.mapped && !(wwin->flags.miniaturized || wwin->flags.hidden)) {
1952 wWindowMap(wwin);
1953 }
1954 }
1955 if (!IS_OMNIPRESENT(wwin)) {
1956 int oldWorkspace = wwin->frame->workspace;
1957
1958 wwin->frame->workspace = workspace;
1959
1960 WMPostNotificationName(WMNChangedWorkspace, wwin, (void *)(uintptr_t) oldWorkspace);
1961 }
1962
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001963 if (unmap)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001964 wWindowUnmap(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001965}
1966
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02001967void wWindowSynthConfigureNotify(WWindow *wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001968{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001969 XEvent sevent;
1970
1971 sevent.type = ConfigureNotify;
1972 sevent.xconfigure.display = dpy;
1973 sevent.xconfigure.event = wwin->client_win;
1974 sevent.xconfigure.window = wwin->client_win;
1975
1976 sevent.xconfigure.x = wwin->client.x;
1977 sevent.xconfigure.y = wwin->client.y;
1978 sevent.xconfigure.width = wwin->client.width;
1979 sevent.xconfigure.height = wwin->client.height;
1980
1981 sevent.xconfigure.border_width = wwin->old_border_width;
1982 if (HAS_TITLEBAR(wwin) && wwin->frame->titlebar)
1983 sevent.xconfigure.above = wwin->frame->titlebar->window;
1984 else
1985 sevent.xconfigure.above = None;
1986
1987 sevent.xconfigure.override_redirect = False;
1988 XSendEvent(dpy, wwin->client_win, False, StructureNotifyMask, &sevent);
1989 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001990}
1991
9d2e6ef9 scottc1998-09-29 22:36:29 +00001992/*
1993 *----------------------------------------------------------------------
cbd13dd9
CM
Carlos R. Mafra2009-09-13 16:05:55 +02001994 * wWindowConfigure()
1995 *
1996 * req_x, req_y: new requested positions for the frame
1997 * req_width, req_height: new requested sizes for the client
1998 *
1999 * Configures the frame, decorations and client window to the specified
2000 * geometry, whose validity is not checked -- wWindowConstrainSize()
2001 * must be used for that.
9d2e6ef9 scottc1998-09-29 22:36:29 +00002002 * The size parameters are for the client window, but the position is
2003 * for the frame.
2004 * The client window receives a ConfigureNotify event, according
2005 * to what ICCCM says.
9aca0d5f dan2004-10-12 01:34:32 +00002006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00002007 * Returns:
2008 * None
9aca0d5f dan2004-10-12 01:34:32 +00002009 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00002010 * Side effects:
2011 * Window size and position are changed and client window receives
2012 * a ConfigureNotify event.
9aca0d5f dan2004-10-12 01:34:32 +00002013 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +00002014 */
cbd13dd9 Carlos R. Mafra2009-09-13 16:05:55 +02002015void wWindowConfigure(WWindow *wwin, int req_x, int req_y, int req_width, int req_height)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002016{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002017 int synth_notify = False;
2018 int resize;
2019
2020 resize = (req_width != wwin->client.width || req_height != wwin->client.height);
2021 /*
2022 * if the window is being moved but not resized then
2023 * send a synthetic ConfigureNotify
2024 */
2025 if ((req_x != wwin->frame_x || req_y != wwin->frame_y) && !resize) {
2026 synth_notify = True;
2027 }
2028
2029 if (WFLAGP(wwin, dont_move_off))
2030 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y, req_width, req_height);
2031 if (resize) {
2032 if (req_width < MIN_WINDOW_SIZE)
2033 req_width = MIN_WINDOW_SIZE;
2034 if (req_height < MIN_WINDOW_SIZE)
2035 req_height = MIN_WINDOW_SIZE;
2036
2037 /* If growing, resize inner part before frame,
2038 * if shrinking, resize frame before.
2039 * This will prevent the frame (that can have a different color)
2040 * to be exposed, causing flicker */
2041 if (req_height > wwin->frame->core->height || req_width > wwin->frame->core->width)
2042 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2043
2044 if (wwin->flags.shaded) {
2045 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, wwin->frame->core->height);
2046 wwin->old_geometry.height = req_height;
2047 } else {
2048 int h;
2049
2050 h = req_height + wwin->frame->top_width + wwin->frame->bottom_width;
2051
2052 wFrameWindowConfigure(wwin->frame, req_x, req_y, req_width, h);
2053 }
2054
2055 if (!(req_height > wwin->frame->core->height || req_width > wwin->frame->core->width))
2056 XResizeWindow(dpy, wwin->client_win, req_width, req_height);
2057
2058 wwin->client.x = req_x;
2059 wwin->client.y = req_y + wwin->frame->top_width;
2060 wwin->client.width = req_width;
2061 wwin->client.height = req_height;
2062 } else {
2063 wwin->client.x = req_x;
2064 wwin->client.y = req_y + wwin->frame->top_width;
2065
2066 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
2067 }
2068 wwin->frame_x = req_x;
2069 wwin->frame_y = req_y;
2070 if (HAS_BORDER(wwin)) {
2071 wwin->client.x += FRAME_BORDER_WIDTH;
2072 wwin->client.y += FRAME_BORDER_WIDTH;
2073 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002074#ifdef SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002075 if (wShapeSupported && wwin->flags.shaped && resize) {
2076 wWindowSetShape(wwin);
2077 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002078#endif
9af1c6c4 dan1998-10-21 14:43:47 +00002079
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002080 if (synth_notify)
2081 wWindowSynthConfigureNotify(wwin);
2082 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002083}
2084
347e804b
CM
Carlos R. Mafra2009-10-11 23:30:41 +02002085/* req_x, req_y: new position of the frame */
2086void wWindowMove(WWindow *wwin, int req_x, int req_y)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002087{
2088#ifdef CONFIGURE_WINDOW_WHILE_MOVING
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002089 int synth_notify = False;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002090
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002091 /* Send a synthetic ConfigureNotify event for every window movement. */
2092 if ((req_x != wwin->frame_x || req_y != wwin->frame_y)) {
2093 synth_notify = True;
2094 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002095#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002096 /* A single synthetic ConfigureNotify event is sent at the end of
2097 * a completed (opaque) movement in moveres.c */
9d2e6ef9 scottc1998-09-29 22:36:29 +00002098#endif
2099
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002100 if (WFLAGP(wwin, dont_move_off))
2101 wScreenBringInside(wwin->screen_ptr, &req_x, &req_y,
2102 wwin->frame->core->width, wwin->frame->core->height);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002103
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002104 wwin->client.x = req_x;
2105 wwin->client.y = req_y + wwin->frame->top_width;
2106 if (HAS_BORDER(wwin)) {
2107 wwin->client.x += FRAME_BORDER_WIDTH;
2108 wwin->client.y += FRAME_BORDER_WIDTH;
2109 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002110
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002111 XMoveWindow(dpy, wwin->frame->core->window, req_x, req_y);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002112
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002113 wwin->frame_x = req_x;
2114 wwin->frame_y = req_y;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002115
2116#ifdef CONFIGURE_WINDOW_WHILE_MOVING
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002117 if (synth_notify)
2118 wWindowSynthConfigureNotify(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002119#endif
2120}
2121
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002122void wWindowUpdateButtonImages(WWindow *wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002123{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002124 WScreen *scr = wwin->screen_ptr;
2125 Pixmap pixmap, mask;
2126 WFrameWindow *fwin = wwin->frame;
2127
2128 if (!HAS_TITLEBAR(wwin))
2129 return;
2130
2131 /* miniaturize button */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002132 if (!WFLAGP(wwin, no_miniaturize_button)) {
2133 if (wwin->wm_gnustep_attr && wwin->wm_gnustep_attr->flags & GSMiniaturizePixmapAttr) {
2134 pixmap = wwin->wm_gnustep_attr->miniaturize_pixmap;
2135
2136 if (wwin->wm_gnustep_attr->flags & GSMiniaturizeMaskAttr) {
2137 mask = wwin->wm_gnustep_attr->miniaturize_mask;
2138 } else {
2139 mask = None;
2140 }
2141
2142 if (fwin->lbutton_image
2143 && (fwin->lbutton_image->image != pixmap || fwin->lbutton_image->mask != mask)) {
2144 wPixmapDestroy(fwin->lbutton_image);
2145 fwin->lbutton_image = NULL;
2146 }
2147
2148 if (!fwin->lbutton_image) {
2149 fwin->lbutton_image = wPixmapCreate(scr, pixmap, mask);
2150 fwin->lbutton_image->client_owned = 1;
2151 fwin->lbutton_image->client_owned_mask = 1;
2152 }
2153 } else {
2154 if (fwin->lbutton_image && !fwin->lbutton_image->shared) {
2155 wPixmapDestroy(fwin->lbutton_image);
2156 }
2157 fwin->lbutton_image = scr->b_pixmaps[WBUT_ICONIFY];
2158 }
2159 }
c28f3b2c id1999-05-20 23:30:53 +00002160#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002161 if (!WFLAGP(wwin, no_language_button)) {
2162 if (fwin->languagebutton_image && !fwin->languagebutton_image->shared) {
2163 wPixmapDestroy(fwin->languagebutton_image);
2164 }
2165 fwin->languagebutton_image = scr->b_pixmaps[WBUT_XKBGROUP1 + fwin->languagemode];
2166 }
c28f3b2c id1999-05-20 23:30:53 +00002167#endif
3c046182 kojima1999-09-16 02:58:56 +00002168
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002169 /* close button */
9d2e6ef9 scottc1998-09-29 22:36:29 +00002170
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002171 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
3c046182 kojima1999-09-16 02:58:56 +00002172#define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2173
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002174 if (!WFLAGP(wwin, no_close_button)) {
2175 if (wwin->wm_gnustep_attr && wwin->wm_gnustep_attr->flags & GSClosePixmapAttr) {
2176 pixmap = wwin->wm_gnustep_attr->close_pixmap;
9aca0d5f dan2004-10-12 01:34:32 +00002177
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002178 if (wwin->wm_gnustep_attr->flags & GSCloseMaskAttr)
2179 mask = wwin->wm_gnustep_attr->close_mask;
2180 else
2181 mask = None;
3c046182 kojima1999-09-16 02:58:56 +00002182
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002183 if (fwin->rbutton_image && (fwin->rbutton_image->image != pixmap
2184 || fwin->rbutton_image->mask != mask)) {
2185 wPixmapDestroy(fwin->rbutton_image);
2186 fwin->rbutton_image = NULL;
2187 }
9aca0d5f dan2004-10-12 01:34:32 +00002188
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002189 if (!fwin->rbutton_image) {
2190 fwin->rbutton_image = wPixmapCreate(scr, pixmap, mask);
2191 fwin->rbutton_image->client_owned = 1;
2192 fwin->rbutton_image->client_owned_mask = 1;
2193 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002194
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002195 } else if (WFLAGP(wwin, kill_close)) {
3c046182 kojima1999-09-16 02:58:56 +00002196
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002197 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2198 wPixmapDestroy(fwin->rbutton_image);
3c046182 kojima1999-09-16 02:58:56 +00002199
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002200 fwin->rbutton_image = scr->b_pixmaps[WBUT_KILL];
9aca0d5f dan2004-10-12 01:34:32 +00002201
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002202 } else if (MGFLAGP(wwin, broken_close)) {
3c046182 kojima1999-09-16 02:58:56 +00002203
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002204 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2205 wPixmapDestroy(fwin->rbutton_image);
3c046182 kojima1999-09-16 02:58:56 +00002206
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002207 fwin->rbutton_image = scr->b_pixmaps[WBUT_BROKENCLOSE];
3c046182 kojima1999-09-16 02:58:56 +00002208
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002209 } else {
3c046182 kojima1999-09-16 02:58:56 +00002210
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002211 if (fwin->rbutton_image && !fwin->rbutton_image->shared)
2212 wPixmapDestroy(fwin->rbutton_image);
3c046182 kojima1999-09-16 02:58:56 +00002213
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002214 fwin->rbutton_image = scr->b_pixmaps[WBUT_CLOSE];
2215 }
2216 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002217
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002218 /* force buttons to be redrawn */
2219 fwin->flags.need_texture_change = 1;
2220 wFrameWindowPaint(fwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002221}
2222
9d2e6ef9 scottc1998-09-29 22:36:29 +00002223/*
2224 *---------------------------------------------------------------------------
2225 * wWindowConfigureBorders--
0261c326 dan1999-01-06 15:22:33 +00002226 * Update window border configuration according to attribute flags.
9aca0d5f dan2004-10-12 01:34:32 +00002227 *
2228 *---------------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +00002229 */
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002230void wWindowConfigureBorders(WWindow *wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002231{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002232 if (wwin->frame) {
2233 int flags;
2234 int newy, oldh;
e7495baf dan1999-02-17 11:06:40 +00002235
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002236 flags = WFF_LEFT_BUTTON | WFF_RIGHT_BUTTON;
9aca0d5f dan2004-10-12 01:34:32 +00002237
a43f369e id1999-05-29 15:45:19 +00002238#ifdef XKB_BUTTON_HINT
2203b229 Nicolas Bonifas2009-11-17 01:01:54 +01002239 if (wPreferences.modelock)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002240 flags |= WFF_LANGUAGE_BUTTON;
a43f369e id1999-05-29 15:45:19 +00002241#endif
9aca0d5f dan2004-10-12 01:34:32 +00002242
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002243 if (HAS_TITLEBAR(wwin))
2244 flags |= WFF_TITLEBAR;
2245 if (HAS_RESIZEBAR(wwin) && IS_RESIZABLE(wwin))
2246 flags |= WFF_RESIZEBAR;
2247 if (HAS_BORDER(wwin))
2248 flags |= WFF_BORDER;
2249 if (wwin->flags.shaded)
2250 flags |= WFF_IS_SHADED;
2251
2252 oldh = wwin->frame->top_width;
2253 wFrameWindowUpdateBorders(wwin->frame, flags);
2254 if (oldh != wwin->frame->top_width) {
2255 newy = wwin->frame_y + oldh - wwin->frame->top_width;
2256
2257 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2258 wWindowConfigure(wwin, wwin->frame_x, newy, wwin->client.width, wwin->client.height);
2259 }
2260
2261 flags = 0;
2262 if (!WFLAGP(wwin, no_miniaturize_button)
2263 && wwin->frame->flags.hide_left_button)
2264 flags |= WFF_LEFT_BUTTON;
9af1c6c4 dan1998-10-21 14:43:47 +00002265
a43f369e id1999-05-29 15:45:19 +00002266#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002267 if (!WFLAGP(wwin, no_language_button)
2268 && wwin->frame->flags.hide_language_button) {
2269 flags |= WFF_LANGUAGE_BUTTON;
2270 }
a43f369e id1999-05-29 15:45:19 +00002271#endif
2272
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002273 if (!WFLAGP(wwin, no_close_button)
2274 && wwin->frame->flags.hide_right_button)
2275 flags |= WFF_RIGHT_BUTTON;
9af1c6c4 dan1998-10-21 14:43:47 +00002276
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002277 if (flags != 0) {
2278 wWindowUpdateButtonImages(wwin);
2279 wFrameWindowShowButton(wwin->frame, flags);
2280 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002281
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002282 flags = 0;
2283 if (WFLAGP(wwin, no_miniaturize_button)
2284 && !wwin->frame->flags.hide_left_button)
2285 flags |= WFF_LEFT_BUTTON;
9af1c6c4 dan1998-10-21 14:43:47 +00002286
a43f369e id1999-05-29 15:45:19 +00002287#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002288 if (WFLAGP(wwin, no_language_button)
2289 && !wwin->frame->flags.hide_language_button)
2290 flags |= WFF_LANGUAGE_BUTTON;
a43f369e id1999-05-29 15:45:19 +00002291#endif
2292
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002293 if (WFLAGP(wwin, no_close_button)
2294 && !wwin->frame->flags.hide_right_button)
2295 flags |= WFF_RIGHT_BUTTON;
9af1c6c4 dan1998-10-21 14:43:47 +00002296
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002297 if (flags != 0)
2298 wFrameWindowHideButton(wwin->frame, flags);
9af1c6c4 dan1998-10-21 14:43:47 +00002299
2300#ifdef SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002301 if (wShapeSupported && wwin->flags.shaped) {
2302 wWindowSetShape(wwin);
2303 }
9af1c6c4 dan1998-10-21 14:43:47 +00002304#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002305 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002306}
2307
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002308void wWindowSaveState(WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002309{
0c2d2c69 Carlos R. Mafra2010-03-29 00:00:07 +02002310 long data[10];
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002311 int i;
2312
0c2d2c69 Carlos R. Mafra2010-03-29 00:00:07 +02002313 memset(data, 0, sizeof(long) * 10);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002314 data[0] = wwin->frame->workspace;
2315 data[1] = wwin->flags.miniaturized;
2316 data[2] = wwin->flags.shaded;
2317 data[3] = wwin->flags.hidden;
2318 data[4] = wwin->flags.maximized;
2319 if (wwin->flags.maximized == 0) {
2320 data[5] = wwin->frame_x;
2321 data[6] = wwin->frame_y;
2322 data[7] = wwin->frame->core->width;
2323 data[8] = wwin->frame->core->height;
2324 } else {
2325 data[5] = wwin->old_geometry.x;
2326 data[6] = wwin->old_geometry.y;
2327 data[7] = wwin->old_geometry.width;
2328 data[8] = wwin->old_geometry.height;
2329 }
2330
2331 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
2332 if (wwin->screen_ptr->shortcutWindows[i] &&
2333 WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
2334 data[9] |= 1 << i;
2335 }
2336 XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,
2337 _XA_WINDOWMAKER_STATE, 32, PropModeReplace, (unsigned char *)data, 10);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002338}
2339
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002340static int getSavedState(Window window, WSavedState ** state)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002341{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002342 Atom type_ret;
2343 int fmt_ret;
2344 unsigned long nitems_ret;
2345 unsigned long bytes_after_ret;
37829a7c Brad Jorsch2010-04-09 15:49:06 -04002346 long *data;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002347
2348 if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
2349 True, _XA_WINDOWMAKER_STATE,
2350 &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
37829a7c Brad Jorsch2010-04-09 15:49:06 -04002351 (unsigned char **)&data) != Success || !data || nitems_ret < 10)
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002352 return 0;
2353
2354 *state = wmalloc(sizeof(WSavedState));
2355
2356 (*state)->workspace = data[0];
2357 (*state)->miniaturized = data[1];
2358 (*state)->shaded = data[2];
2359 (*state)->hidden = data[3];
2360 (*state)->maximized = data[4];
2361 (*state)->x = data[5];
2362 (*state)->y = data[6];
2363 (*state)->w = data[7];
2364 (*state)->h = data[8];
2365 (*state)->window_shortcuts = data[9];
2366
2367 XFree(data);
2368
2369 if (*state && type_ret == _XA_WINDOWMAKER_STATE)
2370 return 1;
2371 else
2372 return 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002373}
2374
9d2e6ef9 scottc1998-09-29 22:36:29 +00002375#ifdef SHAPE
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002376void wWindowClearShape(WWindow * wwin)
9af1c6c4 dan1998-10-21 14:43:47 +00002377{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002378 XShapeCombineMask(dpy, wwin->frame->core->window, ShapeBounding,
2379 0, wwin->frame->top_width, None, ShapeSet);
2380 XFlush(dpy);
9af1c6c4 dan1998-10-21 14:43:47 +00002381}
2382
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002383void wWindowSetShape(WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002384{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002385 XRectangle rect[2];
2386 int count;
9af1c6c4 dan1998-10-21 14:43:47 +00002387#ifdef OPTIMIZE_SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002388 XRectangle *rects;
2389 XRectangle *urec;
2390 int ordering;
2391
2392 /* only shape is the client's */
2393 if (!HAS_TITLEBAR(wwin) && !HAS_RESIZEBAR(wwin)) {
2394 goto alt_code;
2395 }
2396
2397 /* Get array of rectangles describing the shape mask */
2398 rects = XShapeGetRectangles(dpy, wwin->client_win, ShapeBounding, &count, &ordering);
2399 if (!rects) {
2400 goto alt_code;
2401 }
2402
2403 urec = malloc(sizeof(XRectangle) * (count + 2));
2404 if (!urec) {
2405 XFree(rects);
2406 goto alt_code;
2407 }
2408
2409 /* insert our decoration rectangles in the rect list */
2410 memcpy(urec, rects, sizeof(XRectangle) * count);
2411 XFree(rects);
2412
2413 if (HAS_TITLEBAR(wwin)) {
2414 urec[count].x = -1;
2415 urec[count].y = -1 - wwin->frame->top_width;
2416 urec[count].width = wwin->frame->core->width + 2;
2417 urec[count].height = wwin->frame->top_width + 1;
2418 count++;
2419 }
2420 if (HAS_RESIZEBAR(wwin)) {
2421 urec[count].x = -1;
2422 urec[count].y = wwin->frame->core->height - wwin->frame->bottom_width - wwin->frame->top_width;
2423 urec[count].width = wwin->frame->core->width + 2;
2424 urec[count].height = wwin->frame->bottom_width + 1;
2425 count++;
2426 }
2427
2428 /* shape our frame window */
2429 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2430 0, wwin->frame->top_width, urec, count, ShapeSet, Unsorted);
2431 XFlush(dpy);
2432 wfree(urec);
2433 return;
2434
2435 alt_code:
2436#endif /* OPTIMIZE_SHAPE */
2437 count = 0;
2438 if (HAS_TITLEBAR(wwin)) {
2439 rect[count].x = -1;
2440 rect[count].y = -1;
2441 rect[count].width = wwin->frame->core->width + 2;
2442 rect[count].height = wwin->frame->top_width + 1;
2443 count++;
2444 }
2445 if (HAS_RESIZEBAR(wwin)) {
2446 rect[count].x = -1;
2447 rect[count].y = wwin->frame->core->height - wwin->frame->bottom_width;
2448 rect[count].width = wwin->frame->core->width + 2;
2449 rect[count].height = wwin->frame->bottom_width + 1;
2450 count++;
2451 }
2452 if (count > 0) {
2453 XShapeCombineRectangles(dpy, wwin->frame->core->window, ShapeBounding,
2454 0, 0, rect, count, ShapeSet, Unsorted);
2455 }
2456 XShapeCombineShape(dpy, wwin->frame->core->window, ShapeBounding,
2457 0, wwin->frame->top_width, wwin->client_win,
2458 ShapeBounding, (count > 0 ? ShapeUnion : ShapeSet));
2459 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002460}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002461#endif /* SHAPE */
9d2e6ef9 scottc1998-09-29 22:36:29 +00002462
2463/* ====================================================================== */
2464
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002465static FocusMode getFocusMode(WWindow * wwin)
9af1c6c4 dan1998-10-21 14:43:47 +00002466{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002467 FocusMode mode;
2468
2469 if ((wwin->wm_hints) && (wwin->wm_hints->flags & InputHint)) {
2470 if (wwin->wm_hints->input == True) {
2471 if (wwin->protocols.TAKE_FOCUS)
2472 mode = WFM_LOCALLY_ACTIVE;
2473 else
2474 mode = WFM_PASSIVE;
2475 } else {
2476 if (wwin->protocols.TAKE_FOCUS)
2477 mode = WFM_GLOBALLY_ACTIVE;
2478 else
2479 mode = WFM_NO_INPUT;
2480 }
2481 } else {
2482 mode = WFM_PASSIVE;
2483 }
2484 return mode;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002485}
2486
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002487void wWindowSetKeyGrabs(WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002488{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002489 int i;
2490 WShortKey *key;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002491
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002492 for (i = 0; i < WKBD_LAST; i++) {
2493 key = &wKeyBindings[i];
9af1c6c4 dan1998-10-21 14:43:47 +00002494
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002495 if (key->keycode == 0)
2496 continue;
2497 if (key->modifier != AnyModifier) {
2498 XGrabKey(dpy, key->keycode, key->modifier | LockMask,
2499 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002500#ifdef NUMLOCK_HACK
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002501 /* Also grab all modifier combinations possible that include,
2502 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2503 * work even if the NumLock/ScrollLock key is on.
2504 */
2505 wHackedGrabKey(key->keycode, key->modifier,
2506 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002507#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002508 }
2509 XGrabKey(dpy, key->keycode, key->modifier,
2510 wwin->frame->core->window, True, GrabModeAsync, GrabModeAsync);
2511 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002512
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002513 wRootMenuBindShortcuts(wwin->frame->core->window);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002514}
2515
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002516void wWindowResetMouseGrabs(WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002517{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002518 /* Mouse grabs can't be done on the client window because of
2519 * ICCCM and because clients that try to do the same will crash.
2520 *
2521 * But there is a problem wich makes tbar buttons of unfocused
2522 * windows not usable as the click goes to the frame window instead
2523 * of the button itself. Must figure a way to fix that.
2524 */
2525
2526 XUngrabButton(dpy, AnyButton, AnyModifier, wwin->client_win);
2527
2528 if (!WFLAGP(wwin, no_bind_mouse)) {
2529 /* grabs for Meta+drag */
2530 wHackedGrabButton(AnyButton, MOD_MASK, wwin->client_win,
2531 True, ButtonPressMask | ButtonReleaseMask,
2532 GrabModeSync, GrabModeAsync, None, None);
0db4d788
JH
Johann Haarhoff2010-03-14 22:19:13 +02002533
2534 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2535 * but we only grab it for Button4 and Button 5 since a lot of apps
2536 * use CTRL+Button1-3 for app related functionality
2537 */
4ddc2a5a
BJ
Brad Jorsch2010-04-26 13:56:37 -04002538 if (wPreferences.resize_increment > 0) {
2539 wHackedGrabButton(Button4, ControlMask, wwin->client_win,
2540 True, ButtonPressMask | ButtonReleaseMask,
2541 GrabModeSync, GrabModeAsync, None, None);
2542 wHackedGrabButton(Button5, ControlMask, wwin->client_win,
2543 True, ButtonPressMask | ButtonReleaseMask,
2544 GrabModeSync, GrabModeAsync, None, None);
2545
2546 wHackedGrabButton(Button4, MOD_MASK | ControlMask, wwin->client_win,
2547 True, ButtonPressMask | ButtonReleaseMask,
2548 GrabModeSync, GrabModeAsync, None, None);
2549 wHackedGrabButton(Button5, MOD_MASK | ControlMask, wwin->client_win,
2550 True, ButtonPressMask | ButtonReleaseMask,
2551 GrabModeSync, GrabModeAsync, None, None);
2552 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002553 }
2554
2555 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable)
2556 && !wwin->flags.is_gnustep) {
2557 /* the passive grabs to focus the window */
2558 /* if (wPreferences.focus_mode == WKF_CLICK) */
2559 XGrabButton(dpy, AnyButton, AnyModifier, wwin->client_win,
2560 True, ButtonPressMask | ButtonReleaseMask, GrabModeSync, GrabModeAsync, None, None);
2561 }
2562 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002563}
2564
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002565void wWindowUpdateGNUstepAttr(WWindow * wwin, GNUstepWMAttributes * attr)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002566{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002567 if (attr->flags & GSExtraFlagsAttr) {
2568 if (MGFLAGP(wwin, broken_close) != (attr->extra_flags & GSDocumentEditedFlag)) {
2569 wwin->client_flags.broken_close = !MGFLAGP(wwin, broken_close);
2570 wWindowUpdateButtonImages(wwin);
2571 }
2572 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002573}
2574
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002575WMagicNumber wWindowAddSavedState(char *instance, char *class, char *command, pid_t pid, WSavedState * state)
9af1c6c4 dan1998-10-21 14:43:47 +00002576{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002577 WWindowState *wstate;
9af1c6c4 dan1998-10-21 14:43:47 +00002578
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002579 wstate = malloc(sizeof(WWindowState));
2580 if (!wstate)
4041278f Carlos R. Mafra2010-04-12 23:31:59 +02002581 return NULL;
9af1c6c4 dan1998-10-21 14:43:47 +00002582
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002583 memset(wstate, 0, sizeof(WWindowState));
2584 wstate->pid = pid;
2585 if (instance)
2586 wstate->instance = wstrdup(instance);
2587 if (class)
2588 wstate->class = wstrdup(class);
2589 if (command)
2590 wstate->command = wstrdup(command);
2591 wstate->state = state;
9af1c6c4 dan1998-10-21 14:43:47 +00002592
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002593 wstate->next = windowState;
2594 windowState = wstate;
9af1c6c4 dan1998-10-21 14:43:47 +00002595
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002596 return wstate;
9af1c6c4 dan1998-10-21 14:43:47 +00002597}
2598
9af1c6c4 dan1998-10-21 14:43:47 +00002599#define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2600
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002601WMagicNumber wWindowGetSavedState(Window win)
9af1c6c4 dan1998-10-21 14:43:47 +00002602{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002603 char *instance, *class, *command = NULL;
2604 WWindowState *wstate = windowState;
2605
2606 if (!wstate)
2607 return NULL;
2608
2609 command = GetCommandForWindow(win);
2610 if (!command)
2611 return NULL;
2612
2613 if (PropGetWMClass(win, &class, &instance)) {
2614 while (wstate) {
2615 if (SAME(instance, wstate->instance) &&
2616 SAME(class, wstate->class) && SAME(command, wstate->command)) {
2617 break;
2618 }
2619 wstate = wstate->next;
2620 }
2621 } else {
2622 wstate = NULL;
2623 }
9af1c6c4 dan1998-10-21 14:43:47 +00002624
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002625 if (command)
2626 wfree(command);
2627 if (instance)
2628 XFree(instance);
2629 if (class)
2630 XFree(class);
9af1c6c4 dan1998-10-21 14:43:47 +00002631
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002632 return wstate;
9af1c6c4 dan1998-10-21 14:43:47 +00002633}
2634
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002635void wWindowDeleteSavedState(WMagicNumber id)
9af1c6c4 dan1998-10-21 14:43:47 +00002636{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002637 WWindowState *tmp, *wstate = (WWindowState *) id;
9af1c6c4 dan1998-10-21 14:43:47 +00002638
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002639 if (!wstate || !windowState)
2640 return;
9af1c6c4 dan1998-10-21 14:43:47 +00002641
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002642 tmp = windowState;
2643 if (tmp == wstate) {
2644 windowState = wstate->next;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002645 if (wstate->instance)
2646 wfree(wstate->instance);
2647 if (wstate->class)
2648 wfree(wstate->class);
2649 if (wstate->command)
2650 wfree(wstate->command);
2651 wfree(wstate->state);
2652 wfree(wstate);
2653 } else {
2654 while (tmp->next) {
2655 if (tmp->next == wstate) {
2656 tmp->next = wstate->next;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002657 if (wstate->instance)
2658 wfree(wstate->instance);
2659 if (wstate->class)
2660 wfree(wstate->class);
2661 if (wstate->command)
2662 wfree(wstate->command);
2663 wfree(wstate->state);
2664 wfree(wstate);
2665 break;
2666 }
2667 tmp = tmp->next;
2668 }
2669 }
9af1c6c4 dan1998-10-21 14:43:47 +00002670}
2671
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002672void wWindowDeleteSavedStatesForPID(pid_t pid)
9af1c6c4 dan1998-10-21 14:43:47 +00002673{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002674 WWindowState *tmp, *wstate;
9af1c6c4 dan1998-10-21 14:43:47 +00002675
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002676 if (!windowState)
2677 return;
9af1c6c4 dan1998-10-21 14:43:47 +00002678
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002679 tmp = windowState;
2680 if (tmp->pid == pid) {
2681 wstate = windowState;
2682 windowState = tmp->next;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002683 if (wstate->instance)
2684 wfree(wstate->instance);
2685 if (wstate->class)
2686 wfree(wstate->class);
2687 if (wstate->command)
2688 wfree(wstate->command);
2689 wfree(wstate->state);
2690 wfree(wstate);
2691 } else {
2692 while (tmp->next) {
2693 if (tmp->next->pid == pid) {
2694 wstate = tmp->next;
2695 tmp->next = wstate->next;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002696 if (wstate->instance)
2697 wfree(wstate->instance);
2698 if (wstate->class)
2699 wfree(wstate->class);
2700 if (wstate->command)
2701 wfree(wstate->command);
2702 wfree(wstate->state);
2703 wfree(wstate);
2704 break;
2705 }
2706 tmp = tmp->next;
2707 }
2708 }
9af1c6c4 dan1998-10-21 14:43:47 +00002709}
9d2e6ef9 scottc1998-09-29 22:36:29 +00002710
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002711void wWindowSetOmnipresent(WWindow *wwin, Bool flag)
5ef342d9 kojima2001-09-06 21:42:28 +00002712{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002713 if (wwin->flags.omnipresent == flag)
2714 return;
27a396d7 dan2003-06-06 04:11:00 +00002715
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002716 wwin->flags.omnipresent = flag;
2717 WMPostNotificationName(WMNChangedState, wwin, "omnipresent");
5ef342d9 kojima2001-09-06 21:42:28 +00002718}
2719
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002720static void resizebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002721{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002722 WWindow *wwin = data;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002723
2724#ifndef NUMLOCK_HACK
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002725 if ((event->xbutton.state & ValidModMask)
2726 != (event->xbutton.state & ~LockMask)) {
2727 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2728 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2729 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002730#endif
9aca0d5f dan2004-10-12 01:34:32 +00002731
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002732 event->xbutton.state &= ValidModMask;
9aca0d5f dan2004-10-12 01:34:32 +00002733
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002734 CloseWindowMenu(wwin->screen_ptr);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002735
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002736 if (wPreferences.focus_mode == WKF_CLICK && !(event->xbutton.state & ControlMask)
2737 && !WFLAGP(wwin, no_focusable)) {
2738 wSetFocusTo(wwin->screen_ptr, wwin);
2739 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002740
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002741 if (event->xbutton.button == Button1)
2742 wRaiseFrame(wwin->frame->core);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002743
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002744 if (event->xbutton.window != wwin->frame->resizebar->window) {
2745 if (XGrabPointer(dpy, wwin->frame->resizebar->window, True,
2746 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2747 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002748 return;
2749 }
2750 }
2751
2752 if (event->xbutton.state & MOD_MASK) {
2753 /* move the window */
2754 wMouseMoveWindow(wwin, event);
2755 XUngrabPointer(dpy, CurrentTime);
2756 } else {
2757 wMouseResizeWindow(wwin, event);
2758 XUngrabPointer(dpy, CurrentTime);
2759 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002760}
2761
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002762static void titlebarDblClick(WCoreWindow *sender, void *data, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002763{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002764 WWindow *wwin = data;
2765
2766 event->xbutton.state &= ValidModMask;
2767
2768 if (event->xbutton.button == Button1) {
2769 if (event->xbutton.state == 0) {
2770 if (!WFLAGP(wwin, no_shadeable)) {
2771 /* shade window */
2772 if (wwin->flags.shaded)
2773 wUnshadeWindow(wwin);
2774 else
2775 wShadeWindow(wwin);
2776 }
2777 } else {
2778 int dir = 0;
2779
2780 if (event->xbutton.state & ControlMask)
2781 dir |= MAX_VERTICAL;
2782
2783 if (event->xbutton.state & ShiftMask) {
2784 dir |= MAX_HORIZONTAL;
2785 if (!(event->xbutton.state & ControlMask))
2786 wSelectWindow(wwin, !wwin->flags.selected);
2787 }
2788
2789 /* maximize window */
2790 if (dir != 0 && IS_RESIZABLE(wwin)) {
2791 int ndir = dir ^ wwin->flags.maximized;
2792
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002793 if (ndir != 0)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002794 wMaximizeWindow(wwin, ndir);
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002795 else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002796 wUnmaximizeWindow(wwin);
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002797 }
2798 }
2799 } else if (event->xbutton.button == Button3) {
2800 if (event->xbutton.state & MOD_MASK) {
2801 wHideOtherApplications(wwin);
2802 }
2803 } else if (event->xbutton.button == Button2) {
2804 wSelectWindow(wwin, !wwin->flags.selected);
2805 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
2806 wShadeWindow(wwin);
2807 } else if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
2808 wUnshadeWindow(wwin);
2809 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002810}
2811
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002812static void frameMouseDown(WObjDescriptor *desc, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002813{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002814 WWindow *wwin = desc->parent;
1f1eb393
JH
Johann Haarhoff2009-10-12 21:48:45 +02002815 unsigned int new_width, w_scale;
2816 unsigned int new_height, h_scale;
bf88570a
IP
Iain Patterson2009-10-12 10:24:55 +01002817 unsigned int resize_width_increment = 0;
2818 unsigned int resize_height_increment = 0;
a0633381 Johann Haarhoff2009-10-11 21:36:46 +02002819
bf88570a Iain Patterson2009-10-12 10:24:55 +01002820 if (wwin->normal_hints) {
68bd644b
BJ
Brad Jorsch2010-04-26 13:56:38 -04002821 w_scale = (wPreferences.resize_increment + wwin->normal_hints->width_inc - 1) / wwin->normal_hints->width_inc;
2822 h_scale = (wPreferences.resize_increment + wwin->normal_hints->height_inc - 1) / wwin->normal_hints->height_inc;
1f1eb393
JH
Johann Haarhoff2009-10-12 21:48:45 +02002823 resize_width_increment = wwin->normal_hints->width_inc * w_scale;
2824 resize_height_increment = wwin->normal_hints->height_inc * h_scale;
bf88570a
IP
Iain Patterson2009-10-12 10:24:55 +01002825 }
2826 if (resize_width_increment <= 1 && resize_height_increment <= 1) {
2827 resize_width_increment = wPreferences.resize_increment;
2828 resize_height_increment = wPreferences.resize_increment;
2829 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002830
2831 event->xbutton.state &= ValidModMask;
2832
2833 CloseWindowMenu(wwin->screen_ptr);
2834
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002835 if (!(event->xbutton.state & ControlMask) && !WFLAGP(wwin, no_focusable))
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002836 wSetFocusTo(wwin->screen_ptr, wwin);
347e804b
CM
Carlos R. Mafra2009-10-11 23:30:41 +02002837
2838 if (event->xbutton.button == Button1)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002839 wRaiseFrame(wwin->frame->core);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002840
744ccb85 Johann Haarhoff2010-03-14 10:49:14 +02002841 if (event->xbutton.state & ControlMask) {
744ccb85
JH
Johann Haarhoff2010-03-14 10:49:14 +02002842 if (event->xbutton.button == Button4) {
2843 new_width = wwin->client.width - resize_width_increment;
2844 wWindowConstrainSize(wwin, &new_width, &wwin->client.height);
2845 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, new_width, wwin->client.height);
2846 }
2847 if (event->xbutton.button == Button5) {
2848 new_width = wwin->client.width + resize_width_increment;
2849 wWindowConstrainSize(wwin, &new_width, &wwin->client.height);
2850 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, new_width, wwin->client.height);
2851 }
2852 }
2853
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002854 if (event->xbutton.state & MOD_MASK) {
2855 /* move the window */
2856 if (XGrabPointer(dpy, wwin->client_win, False,
2857 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2858 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002859 return;
2860 }
a0633381 Johann Haarhoff2009-10-11 21:36:46 +02002861 if (event->xbutton.button == Button3) {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002862 wMouseResizeWindow(wwin, event);
a0633381 Johann Haarhoff2009-10-11 21:36:46 +02002863 } else if (event->xbutton.button == Button4) {
bf88570a Iain Patterson2009-10-12 10:24:55 +01002864 new_height = wwin->client.height - resize_height_increment;
744ccb85
JH
Johann Haarhoff2010-03-14 10:49:14 +02002865 wWindowConstrainSize(wwin, &wwin->client.width, &new_height);
2866 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, wwin->client.width, new_height);
a0633381 Johann Haarhoff2009-10-11 21:36:46 +02002867 } else if (event->xbutton.button == Button5) {
bf88570a Iain Patterson2009-10-12 10:24:55 +01002868 new_height = wwin->client.height + resize_height_increment;
744ccb85
JH
Johann Haarhoff2010-03-14 10:49:14 +02002869 wWindowConstrainSize(wwin, &wwin->client.width, &new_height);
2870 wWindowConfigure(wwin, wwin->frame_x, wwin->frame_y, wwin->client.width, new_height);
a0633381 Johann Haarhoff2009-10-11 21:36:46 +02002871 } else if (event->xbutton.button == Button1 || event->xbutton.button == Button2) {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002872 wMouseMoveWindow(wwin, event);
a0633381 Johann Haarhoff2009-10-11 21:36:46 +02002873 }
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002874 XUngrabPointer(dpy, CurrentTime);
2875 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002876}
2877
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002878static void titlebarMouseDown(WCoreWindow *sender, void *data, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002879{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002880 WWindow *wwin = (WWindow *) data;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002881
2882#ifndef NUMLOCK_HACK
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002883 if ((event->xbutton.state & ValidModMask)
2884 != (event->xbutton.state & ~LockMask)) {
2885 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2886 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2887 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002888#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002889 event->xbutton.state &= ValidModMask;
2890
2891 CloseWindowMenu(wwin->screen_ptr);
2892
2893 if (wPreferences.focus_mode == WKF_CLICK && !(event->xbutton.state & ControlMask)
2894 && !WFLAGP(wwin, no_focusable)) {
2895 wSetFocusTo(wwin->screen_ptr, wwin);
2896 }
2897
2898 if (event->xbutton.button == Button1 || event->xbutton.button == Button2) {
2899
2900 if (event->xbutton.button == Button1) {
2901 if (event->xbutton.state & MOD_MASK) {
2902 wLowerFrame(wwin->frame->core);
2903 } else {
2904 wRaiseFrame(wwin->frame->core);
2905 }
2906 }
2907 if ((event->xbutton.state & ShiftMask)
2908 && !(event->xbutton.state & ControlMask)) {
2909 wSelectWindow(wwin, !wwin->flags.selected);
2910 return;
2911 }
2912 if (event->xbutton.window != wwin->frame->titlebar->window
2913 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2914 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2915 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002916 return;
2917 }
2918
2919 /* move the window */
2920 wMouseMoveWindow(wwin, event);
2921
2922 XUngrabPointer(dpy, CurrentTime);
2923 } else if (event->xbutton.button == Button3 && event->xbutton.state == 0
2924 && !wwin->flags.internal_window && !WCHECK_STATE(WSTATE_MODAL)) {
2925 WObjDescriptor *desc;
2926
2927 if (event->xbutton.window != wwin->frame->titlebar->window
2928 && XGrabPointer(dpy, wwin->frame->titlebar->window, False,
2929 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
2930 GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002931 return;
2932 }
9007a657 dan1998-11-23 11:32:19 +00002933
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002934 OpenWindowMenu(wwin, event->xbutton.x_root, wwin->frame_y + wwin->frame->top_width, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002935
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002936 /* allow drag select */
2937 desc = &wwin->screen_ptr->window_menu->menu->descriptor;
2938 event->xany.send_event = True;
2939 (*desc->handle_mousedown) (desc, event);
9aca0d5f dan2004-10-12 01:34:32 +00002940
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002941 XUngrabPointer(dpy, CurrentTime);
2942 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002943}
2944
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002945static void windowCloseClick(WCoreWindow *sender, void *data, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002946{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002947 WWindow *wwin = data;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002948
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002949 event->xbutton.state &= ValidModMask;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002950
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002951 CloseWindowMenu(wwin->screen_ptr);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002952
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002953 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2954 return;
416e3a82 dan1999-01-25 19:06:50 +00002955
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002956 /* if control-click, kill the client */
2957 if (event->xbutton.state & ControlMask) {
2958 wClientKill(wwin);
2959 } else {
2960 if (wwin->protocols.DELETE_WINDOW && event->xbutton.state == 0) {
2961 /* send delete message */
2962 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
2963 }
2964 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002965}
2966
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002967static void windowCloseDblClick(WCoreWindow *sender, void *data, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00002968{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002969 WWindow *wwin = data;
9d2e6ef9 scottc1998-09-29 22:36:29 +00002970
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002971 CloseWindowMenu(wwin->screen_ptr);
9d2e6ef9 scottc1998-09-29 22:36:29 +00002972
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002973 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
2974 return;
416e3a82 dan1999-01-25 19:06:50 +00002975
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002976 /* send delete message */
2977 if (wwin->protocols.DELETE_WINDOW) {
2978 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
2979 } else {
2980 wClientKill(wwin);
2981 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00002982}
2983
c28f3b2c id1999-05-20 23:30:53 +00002984#ifdef XKB_BUTTON_HINT
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02002985static void windowLanguageClick(WCoreWindow *sender, void *data, XEvent *event)
c28f3b2c id1999-05-20 23:30:53 +00002986{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002987 WWindow *wwin = data;
2988 WFrameWindow *fwin = wwin->frame;
2989 WScreen *scr = fwin->screen_ptr;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002990 int tl;
2991
2992 if (event->xbutton.button != Button1 && event->xbutton.button != Button3)
2993 return;
2994 tl = wwin->frame->languagemode;
2995 wwin->frame->languagemode = wwin->frame->last_languagemode;
2996 wwin->frame->last_languagemode = tl;
2997 wSetFocusTo(scr, wwin);
2998 wwin->frame->languagebutton_image =
2999 wwin->frame->screen_ptr->b_pixmaps[WBUT_XKBGROUP1 + wwin->frame->languagemode];
3000 wFrameWindowUpdateLanguageButton(wwin->frame);
3001 if (event->xbutton.button == Button3)
3002 return;
3003 wRaiseFrame(fwin->core);
c28f3b2c id1999-05-20 23:30:53 +00003004}
3005#endif
3006
347e804b Carlos R. Mafra2009-10-11 23:30:41 +02003007static void windowIconifyClick(WCoreWindow *sender, void *data, XEvent *event)
9d2e6ef9 scottc1998-09-29 22:36:29 +00003008{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02003009 WWindow *wwin = data;
3010
3011 event->xbutton.state &= ValidModMask;
3012
3013 CloseWindowMenu(wwin->screen_ptr);
6830b057 dan2004-10-12 21:28:27 +00003014
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02003015 if (event->xbutton.button < Button1 || event->xbutton.button > Button3)
3016 return;
3017
3018 if (wwin->protocols.MINIATURIZE_WINDOW && event->xbutton.state == 0) {
3019 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, LastTimestamp);
3020 } else {
3021 WApplication *wapp;
3022 if ((event->xbutton.state & ControlMask) || (event->xbutton.button == Button3)) {
3023
3024 wapp = wApplicationOf(wwin->main_window);
3025 if (wapp && !WFLAGP(wwin, no_appicon))
3026 wHideApplication(wapp);
3027 } else if (event->xbutton.state == 0) {
3028 wIconifyWindow(wwin);
3029 }
3030 }
3031}