Fix periodic focus bug
[wmaker-crm.git] / src / actions.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* action.c- misc. window commands (miniaturize, hide etc.)
84576113 dan2003-07-16 20:58:49 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
84576113 dan2003-07-16 20:58:49 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
84576113 dan2003-07-16 20:58:49 +00007 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
84576113 dan2003-07-16 20:58:49 +000020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000021 * USA.
22 */
0261c326 dan1999-01-06 15:22:33 +000023
9d2e6ef9 scottc1998-09-29 22:36:29 +000024#include "wconfig.h"
25
0261c326 dan1999-01-06 15:22:33 +000026
9d2e6ef9 scottc1998-09-29 22:36:29 +000027#include <X11/Xlib.h>
28#include <X11/Xutil.h>
29#include <stdlib.h>
30#include <stdio.h>
31#include <unistd.h>
32#include <math.h>
9af1c6c4 dan1998-10-21 14:43:47 +000033#include <time.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000034
35#include "WindowMaker.h"
36#include "wcore.h"
37#include "framewin.h"
38#include "window.h"
39#include "client.h"
40#include "icon.h"
41#include "funcs.h"
42#include "application.h"
43#include "actions.h"
44#include "stacking.h"
45#include "appicon.h"
46#include "dock.h"
47#include "appmenu.h"
48#include "winspector.h"
59eb9475 dan1998-11-03 12:53:26 +000049#include "workspace.h"
430c12e2 dan2001-05-13 00:28:55 +000050#include "wsound.h"
5873385d kojima2002-02-15 21:30:42 +000051#include "xinerama.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000052
9d2e6ef9 scottc1998-09-29 22:36:29 +000053
54/****** Global Variables ******/
55extern Time LastTimestamp;
56extern Time LastFocusChange;
57
58extern Cursor wCursor[WCUR_LAST];
59
60extern WPreferences wPreferences;
61
62extern Atom _XA_WM_TAKE_FOCUS;
63
9aca0d5f dan2004-10-12 01:34:32 +000064extern void ProcessPendingEvents();
65
e7495baf dan1999-02-17 11:06:40 +000066
9d2e6ef9 scottc1998-09-29 22:36:29 +000067/******* Local Variables *******/
68static struct {
69 int steps;
70 int delay;
71} shadePars[5] = {
72 {SHADE_STEPS_UF, SHADE_DELAY_UF},
73 {SHADE_STEPS_F, SHADE_DELAY_F},
74 {SHADE_STEPS_M, SHADE_DELAY_M},
75 {SHADE_STEPS_S, SHADE_DELAY_S},
f4ef34b8 dan2001-12-17 21:21:59 +000076 {SHADE_STEPS_US, SHADE_DELAY_US}};
9d2e6ef9 scottc1998-09-29 22:36:29 +000077
9af1c6c4 dan1998-10-21 14:43:47 +000078#define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79#define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
9d2e6ef9 scottc1998-09-29 22:36:29 +000080
c91bb1ba
PG
Pedro Gimeno2008-05-19 17:52:00 -030081static int
82compareTimes(Time t1, Time t2)
83{
84 Time diff;
85 if (t1 == t2)
86 return 0;
87 diff = t1 - t2;
88 return (diff < 60000) ? 1 : -1;
89}
9d2e6ef9 scottc1998-09-29 22:36:29 +000090
9d2e6ef9 scottc1998-09-29 22:36:29 +000091/*
84576113 dan2003-07-16 20:58:49 +000092 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +000093 * wSetFocusTo--
94 * Changes the window focus to the one passed as argument.
95 * If the window to focus is not already focused, it will be brought
96 * to the head of the list of windows. Previously focused window is
84576113 dan2003-07-16 20:58:49 +000097 * unfocused.
98 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000099 * Side effects:
100 * Window list may be reordered and the window focus is changed.
84576113 dan2003-07-16 20:58:49 +0000101 *
102 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000103 */
104void
105wSetFocusTo(WScreen *scr, WWindow *wwin)
106{
dbdb44a4 kojima1999-10-02 20:24:41 +0000107 static WScreen *old_scr=NULL;
108
109 WWindow *old_focused;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000110 WWindow *focused=scr->focused_window;
c91bb1ba Pedro Gimeno2008-05-19 17:52:00 -0300111 Time timestamp=LastTimestamp;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000112 WApplication *oapp=NULL, *napp=NULL;
113 int wasfocused;
6830b057 dan2004-10-12 21:28:27 +0000114
c91bb1ba Pedro Gimeno2008-05-19 17:52:00 -0300115 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
9aca0d5f dan2004-10-12 01:34:32 +0000116 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000117
dbdb44a4 kojima1999-10-02 20:24:41 +0000118 if (!old_scr)
84576113 dan2003-07-16 20:58:49 +0000119 old_scr=scr;
dbdb44a4 kojima1999-10-02 20:24:41 +0000120 old_focused=old_scr->focused_window;
121
9d2e6ef9 scottc1998-09-29 22:36:29 +0000122 LastFocusChange = timestamp;
0261c326 dan1999-01-06 15:22:33 +0000123
dbdb44a4 kojima1999-10-02 20:24:41 +0000124 if (old_focused)
84576113 dan2003-07-16 20:58:49 +0000125 oapp = wApplicationOf(old_focused->main_window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000126
e7495baf dan1999-02-17 11:06:40 +0000127 if (wwin == NULL) {
9aca0d5f dan2004-10-12 01:34:32 +0000128 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
84576113 dan2003-07-16 20:58:49 +0000129 if (old_focused) {
130 wWindowUnfocus(old_focused);
131 }
132 if (oapp) {
133 wAppMenuUnmap(oapp->menu);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000134#ifdef NEWAPPICON
84576113 dan2003-07-16 20:58:49 +0000135 wApplicationDeactivate(oapp);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000136#endif
84576113 dan2003-07-16 20:58:49 +0000137 }
138
139 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
140 return;
0bbbdcb9 richard2001-01-21 10:44:13 +0000141 } else if (old_scr != scr && old_focused) {
dbdb44a4 kojima1999-10-02 20:24:41 +0000142 wWindowUnfocus(old_focused);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000143 }
dbdb44a4 kojima1999-10-02 20:24:41 +0000144
9d2e6ef9 scottc1998-09-29 22:36:29 +0000145 wasfocused = wwin->flags.focused;
146 napp = wApplicationOf(wwin->main_window);
147
148 /* remember last workspace where the app has been */
501c3f48 dan2002-01-05 01:35:30 +0000149 if (napp) {
150 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
151 napp->last_workspace = wwin->frame->workspace;
152 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000153
7e07b7b5 kojima1999-04-10 19:32:34 +0000154 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
84576113 dan2003-07-16 20:58:49 +0000155 /* install colormap if colormap mode is lock mode */
156 if (wPreferences.colormap_mode==WCM_CLICK)
157 wColormapInstallForWindow(scr, wwin);
158
159 /* set input focus */
160 switch (wwin->focus_mode) {
161 case WFM_NO_INPUT:
9aca0d5f dan2004-10-12 01:34:32 +0000162 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
84576113 dan2003-07-16 20:58:49 +0000163 break;
164
165 case WFM_PASSIVE:
166 case WFM_LOCALLY_ACTIVE:
9aca0d5f dan2004-10-12 01:34:32 +0000167 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
84576113 dan2003-07-16 20:58:49 +0000168 break;
169
170 case WFM_GLOBALLY_ACTIVE:
171 break;
172 }
173 XFlush(dpy);
174 if (wwin->protocols.TAKE_FOCUS) {
175 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
176 }
177 XSync(dpy, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000178 } else {
9aca0d5f dan2004-10-12 01:34:32 +0000179 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000180 }
7e07b7b5 kojima1999-04-10 19:32:34 +0000181 if (WFLAGP(wwin, no_focusable))
84576113 dan2003-07-16 20:58:49 +0000182 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000183
184 /* if this is not the focused window focus it */
185 if (focused!=wwin) {
84576113 dan2003-07-16 20:58:49 +0000186 /* change the focus window list order */
187 if (wwin->prev)
188 wwin->prev->next = wwin->next;
e7495baf dan1999-02-17 11:06:40 +0000189
84576113 dan2003-07-16 20:58:49 +0000190 if (wwin->next)
191 wwin->next->prev = wwin->prev;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000192
84576113 dan2003-07-16 20:58:49 +0000193 wwin->prev = focused;
194 focused->next = wwin;
195 wwin->next = NULL;
196 scr->focused_window = wwin;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000197
84576113 dan2003-07-16 20:58:49 +0000198 if (oapp && oapp != napp) {
199 wAppMenuUnmap(oapp->menu);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000200#ifdef NEWAPPICON
84576113 dan2003-07-16 20:58:49 +0000201 wApplicationDeactivate(oapp);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000202#endif
84576113 dan2003-07-16 20:58:49 +0000203 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000204 }
e7495baf dan1999-02-17 11:06:40 +0000205
0bbbdcb9 richard2001-01-21 10:44:13 +0000206 wWindowFocus(wwin, focused);
e7495baf dan1999-02-17 11:06:40 +0000207
9d2e6ef9 scottc1998-09-29 22:36:29 +0000208 if (napp && !wasfocused) {
7e07b7b5 kojima1999-04-10 19:32:34 +0000209#ifdef USER_MENU
84576113 dan2003-07-16 20:58:49 +0000210 wUserMenuRefreshInstances(napp->menu, wwin);
7e07b7b5 kojima1999-04-10 19:32:34 +0000211#endif /* USER_MENU */
212
84576113 dan2003-07-16 20:58:49 +0000213 if (wwin->flags.mapped)
214 wAppMenuMap(napp->menu, wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000215#ifdef NEWAPPICON
84576113 dan2003-07-16 20:58:49 +0000216 wApplicationActivate(napp);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000217#endif
218 }
84576113 dan2003-07-16 20:58:49 +0000219
9d2e6ef9 scottc1998-09-29 22:36:29 +0000220 XFlush(dpy);
dbdb44a4 kojima1999-10-02 20:24:41 +0000221 old_scr=scr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000222}
223
224
225void
226wShadeWindow(WWindow *wwin)
227{
0c4dc1c2 dan2001-11-20 13:48:23 +0000228 time_t time0;
9af1c6c4 dan1998-10-21 14:43:47 +0000229#ifdef ANIMATIONS
9d2e6ef9 scottc1998-09-29 22:36:29 +0000230 int y, s, w, h;
231#endif
9af1c6c4 dan1998-10-21 14:43:47 +0000232
9d2e6ef9 scottc1998-09-29 22:36:29 +0000233 if (wwin->flags.shaded)
84576113 dan2003-07-16 20:58:49 +0000234 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000235
0c4dc1c2 dan2001-11-20 13:48:23 +0000236 time0 = time(NULL);
237
84576113 dan2003-07-16 20:58:49 +0000238 XLowerWindow(dpy, wwin->client_win);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000239
1b587b01 dan2001-01-18 01:33:44 +0000240 wSoundPlay(WSOUND_SHADE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000241
242#ifdef ANIMATIONS
243 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
84576113 dan2003-07-16 20:58:49 +0000244 && !wPreferences.no_animations) {
245 /* do the shading animation */
246 h = wwin->frame->core->height;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000247 s = h/SHADE_STEPS;
248 if (s < 1) s=1;
84576113 dan2003-07-16 20:58:49 +0000249 w = wwin->frame->core->width;
250 y = wwin->frame->top_width;
251 while (h>wwin->frame->top_width+1) {
252 XMoveWindow(dpy, wwin->client_win, 0, y);
253 XResizeWindow(dpy, wwin->frame->core->window, w, h);
254 XFlush(dpy);
59eb9475 dan1998-11-03 12:53:26 +0000255
84576113 dan2003-07-16 20:58:49 +0000256 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
257 break;
59eb9475 dan1998-11-03 12:53:26 +0000258
f4ef34b8 dan2001-12-17 21:21:59 +0000259 if (SHADE_DELAY > 0) {
9d2e6ef9 scottc1998-09-29 22:36:29 +0000260 wusleep(SHADE_DELAY*1000L);
f4ef34b8 dan2001-12-17 21:21:59 +0000261 } else {
262 wusleep(10);
263 }
84576113 dan2003-07-16 20:58:49 +0000264 h-=s;
265 y-=s;
266 }
267 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000268 }
269#endif /* ANIMATIONS */
270
9d2e6ef9 scottc1998-09-29 22:36:29 +0000271 wwin->flags.skip_next_animation = 0;
416e3a82 dan1999-01-25 19:06:50 +0000272 wwin->flags.shaded = 1;
e7495baf dan1999-02-17 11:06:40 +0000273 wwin->flags.mapped = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000274 /* prevent window withdrawal when getting UnmapNotify */
84576113 dan2003-07-16 20:58:49 +0000275 XSelectInput(dpy, wwin->client_win,
e7495baf dan1999-02-17 11:06:40 +0000276 wwin->event_mask & ~StructureNotifyMask);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000277 XUnmapWindow(dpy, wwin->client_win);
e7495baf dan1999-02-17 11:06:40 +0000278 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
416e3a82 dan1999-01-25 19:06:50 +0000279
9d2e6ef9 scottc1998-09-29 22:36:29 +0000280 /* for the client it's just like iconification */
281 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
84576113 dan2003-07-16 20:58:49 +0000282 wwin->frame->top_width - 1);
283
284 wwin->client.y = wwin->frame_y - wwin->client.height
285 + wwin->frame->top_width;
0261c326 dan1999-01-06 15:22:33 +0000286 wWindowSynthConfigureNotify(wwin);
287
59eb9475 dan1998-11-03 12:53:26 +0000288 /*
84576113 dan2003-07-16 20:58:49 +0000289 wClientSetState(wwin, IconicState, None);
59eb9475 dan1998-11-03 12:53:26 +0000290 */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000291
5ef342d9 kojima2001-09-06 21:42:28 +0000292 WMPostNotificationName(WMNChangedState, wwin, "shade");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000293
294#ifdef ANIMATIONS
295 if (!wwin->screen_ptr->flags.startup) {
9aca0d5f dan2004-10-12 01:34:32 +0000296 /* Catch up with events not processed while animation was running */
297 ProcessPendingEvents();
9d2e6ef9 scottc1998-09-29 22:36:29 +0000298 }
299#endif
300}
301
302
303void
304wUnshadeWindow(WWindow *wwin)
305{
0c4dc1c2 dan2001-11-20 13:48:23 +0000306 time_t time0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000307#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +0000308 int y, s, w, h;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000309#endif /* ANIMATIONS */
310
311
312 if (!wwin->flags.shaded)
84576113 dan2003-07-16 20:58:49 +0000313 return;
0c4dc1c2 dan2001-11-20 13:48:23 +0000314
315 time0 = time(NULL);
316
416e3a82 dan1999-01-25 19:06:50 +0000317 wwin->flags.shaded = 0;
318 wwin->flags.mapped = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000319 XMapWindow(dpy, wwin->client_win);
320
1b587b01 dan2001-01-18 01:33:44 +0000321 wSoundPlay(WSOUND_UNSHADE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000322
323#ifdef ANIMATIONS
324 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
84576113 dan2003-07-16 20:58:49 +0000325 /* do the shading animation */
326 h = wwin->frame->top_width + wwin->frame->bottom_width;
327 y = wwin->frame->top_width - wwin->client.height;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000328 s = abs(y)/SHADE_STEPS;
329 if (s<1) s=1;
84576113 dan2003-07-16 20:58:49 +0000330 w = wwin->frame->core->width;
331 XMoveWindow(dpy, wwin->client_win, 0, y);
332 if (s>0) {
333 while (h < wwin->client.height + wwin->frame->top_width
334 + wwin->frame->bottom_width) {
335 XResizeWindow(dpy, wwin->frame->core->window, w, h);
336 XMoveWindow(dpy, wwin->client_win, 0, y);
337 XFlush(dpy);
f4ef34b8 dan2001-12-17 21:21:59 +0000338 if (SHADE_DELAY > 0) {
9d2e6ef9 scottc1998-09-29 22:36:29 +0000339 wusleep(SHADE_DELAY*2000L/3);
f4ef34b8 dan2001-12-17 21:21:59 +0000340 } else {
341 wusleep(10);
342 }
84576113 dan2003-07-16 20:58:49 +0000343 h+=s;
344 y+=s;
345
346 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
347 break;
348 }
349 }
350 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000351 }
352#endif /* ANIMATIONS */
353
9d2e6ef9 scottc1998-09-29 22:36:29 +0000354 wwin->flags.skip_next_animation = 0;
84576113 dan2003-07-16 20:58:49 +0000355 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
356 wwin->frame->top_width + wwin->client.height
357 + wwin->frame->bottom_width);
0261c326 dan1999-01-06 15:22:33 +0000358
359 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
360 wWindowSynthConfigureNotify(wwin);
84576113 dan2003-07-16 20:58:49 +0000361
59eb9475 dan1998-11-03 12:53:26 +0000362 /*
84576113 dan2003-07-16 20:58:49 +0000363 wClientSetState(wwin, NormalState, None);
59eb9475 dan1998-11-03 12:53:26 +0000364 */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000365 /* if the window is focused, set the focus again as it was disabled during
366 * shading */
367 if (wwin->flags.focused)
84576113 dan2003-07-16 20:58:49 +0000368 wSetFocusTo(wwin->screen_ptr, wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000369
5ef342d9 kojima2001-09-06 21:42:28 +0000370 WMPostNotificationName(WMNChangedState, wwin, "shade");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000371}
372
373
374void
375wMaximizeWindow(WWindow *wwin, int directions)
376{
c0317dda dan2005-08-22 23:58:19 +0000377 int new_x, new_y;
378 unsigned int new_width, new_height;
bd7943d9 dan2003-07-05 02:39:37 +0000379 int changed_h, changed_v, shrink_h, shrink_v;
27a396d7 dan2003-06-06 04:11:00 +0000380 WArea usableArea, totalArea;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000381
9aca0d5f dan2004-10-12 01:34:32 +0000382 if (!IS_RESIZABLE(wwin))
84576113 dan2003-07-16 20:58:49 +0000383 return;
384
385 totalArea.x1 = 0;
386 totalArea.y1 = 0;
387 totalArea.x2 = wwin->screen_ptr->scr_width;
388 totalArea.y2 = wwin->screen_ptr->scr_height;
389 usableArea = totalArea;
b4851afb kojima2001-01-16 16:08:40 +0000390
27a396d7 dan2003-06-06 04:11:00 +0000391 if (!(directions & MAX_IGNORE_XINERAMA)) {
84576113 dan2003-07-16 20:58:49 +0000392 WScreen *scr = wwin->screen_ptr;
393 int head;
a10214a5 kojima2002-11-28 22:04:07 +0000394
84576113 dan2003-07-16 20:58:49 +0000395 if (directions & MAX_KEYBOARD)
396 head = wGetHeadForWindow(wwin);
397 else
398 head = wGetHeadForPointerLocation(scr);
5873385d kojima2002-02-15 21:30:42 +0000399
84576113 dan2003-07-16 20:58:49 +0000400 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
b4851afb kojima2001-01-16 16:08:40 +0000401 }
b4851afb kojima2001-01-16 16:08:40 +0000402
088c0ac2 dan1999-03-09 14:58:01 +0000403 if (WFLAGP(wwin, full_maximize)) {
84576113 dan2003-07-16 20:58:49 +0000404 usableArea = totalArea;
088c0ac2 dan1999-03-09 14:58:01 +0000405 }
406
9d2e6ef9 scottc1998-09-29 22:36:29 +0000407 if (wwin->flags.shaded) {
84576113 dan2003-07-16 20:58:49 +0000408 wwin->flags.skip_next_animation = 1;
409 wUnshadeWindow(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000410 }
bd7943d9 dan2003-07-05 02:39:37 +0000411 /* Only save directions, not kbd or xinerama hints */
412 directions &= (MAX_HORIZONTAL|MAX_VERTICAL);
413
414 changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
415 changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
416 shrink_h = (changed_h && (directions & MAX_HORIZONTAL)==0);
417 shrink_v = (changed_v && (directions & MAX_VERTICAL)==0);
418
419 if (wwin->flags.maximized) {
420 /* if already maximized in some direction, we only update the
421 * appropriate old x, old y coordinates. This is necessary to
422 * allow succesive maximizations in different directions without
423 * the need to first do an un-maximize (to avoid flicker).
424 */
425 if (!(wwin->flags.maximized & MAX_HORIZONTAL)) {
426 wwin->old_geometry.x = wwin->frame_x;
427 }
428 if (!(wwin->flags.maximized & MAX_VERTICAL)) {
429 wwin->old_geometry.y = wwin->frame_y;
430 }
431 } else {
432 wwin->old_geometry.width = wwin->client.width;
433 wwin->old_geometry.height = wwin->client.height;
434 wwin->old_geometry.x = wwin->frame_x;
435 wwin->old_geometry.y = wwin->frame_y;
436 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000437 wwin->flags.maximized = directions;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000438
0261c326 dan1999-01-06 15:22:33 +0000439 if (directions & MAX_HORIZONTAL) {
84576113 dan2003-07-16 20:58:49 +0000440 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
441 new_x = usableArea.x1;
bd7943d9 dan2003-07-05 02:39:37 +0000442 } else if (shrink_h) {
84576113 dan2003-07-16 20:58:49 +0000443 new_x = wwin->old_geometry.x;
444 new_width = wwin->old_geometry.width;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000445 } else {
84576113 dan2003-07-16 20:58:49 +0000446 new_x = wwin->frame_x;
447 new_width = wwin->frame->core->width;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000448 }
449
450 if (directions & MAX_VERTICAL) {
84576113 dan2003-07-16 20:58:49 +0000451 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
452 new_y = usableArea.y1;
453 if (WFLAGP(wwin, full_maximize)) {
454 new_y -= wwin->frame->top_width;
455 new_height += wwin->frame->bottom_width - 1;
456 }
bd7943d9 dan2003-07-05 02:39:37 +0000457 } else if (shrink_v) {
84576113 dan2003-07-16 20:58:49 +0000458 new_y = wwin->old_geometry.y;
459 new_height = wwin->old_geometry.height;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000460 } else {
84576113 dan2003-07-16 20:58:49 +0000461 new_y = wwin->frame_y;
462 new_height = wwin->frame->core->height;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000463 }
088c0ac2 dan1999-03-09 14:58:01 +0000464
465 if (!WFLAGP(wwin, full_maximize)) {
84576113 dan2003-07-16 20:58:49 +0000466 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
088c0ac2 dan1999-03-09 14:58:01 +0000467 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000468
469 wWindowConstrainSize(wwin, &new_width, &new_height);
84576113 dan2003-07-16 20:58:49 +0000470
471 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
472 usableArea.y2-usableArea.y1,
473 &new_width, &new_height);
474
9d2e6ef9 scottc1998-09-29 22:36:29 +0000475 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
476
5ef342d9 kojima2001-09-06 21:42:28 +0000477
478 WMPostNotificationName(WMNChangedState, wwin, "maximize");
0261c326 dan1999-01-06 15:22:33 +0000479
1b587b01 dan2001-01-18 01:33:44 +0000480 wSoundPlay(WSOUND_MAXIMIZE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000481}
482
483
484void
485wUnmaximizeWindow(WWindow *wwin)
486{
69730273 dan2005-05-15 16:45:02 +0000487 int x, y, w, h;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000488
0261c326 dan1999-01-06 15:22:33 +0000489 if (!wwin->flags.maximized)
84576113 dan2003-07-16 20:58:49 +0000490 return;
491
9d2e6ef9 scottc1998-09-29 22:36:29 +0000492 if (wwin->flags.shaded) {
84576113 dan2003-07-16 20:58:49 +0000493 wwin->flags.skip_next_animation = 1;
494 wUnshadeWindow(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000495 }
69730273 dan2005-05-15 16:45:02 +0000496 x = ((wwin->flags.maximized & MAX_HORIZONTAL) && wwin->old_geometry.x) ?
9d2e6ef9 scottc1998-09-29 22:36:29 +0000497 wwin->old_geometry.x : wwin->frame_x;
69730273 dan2005-05-15 16:45:02 +0000498 y = ((wwin->flags.maximized & MAX_VERTICAL) && wwin->old_geometry.y) ?
9d2e6ef9 scottc1998-09-29 22:36:29 +0000499 wwin->old_geometry.y : wwin->frame_y;
69730273 dan2005-05-15 16:45:02 +0000500 w = wwin->old_geometry.width ?
501 wwin->old_geometry.width : wwin->client.width;
502 h = wwin->old_geometry.height ?
503 wwin->old_geometry.height : wwin->client.height;
504
9d2e6ef9 scottc1998-09-29 22:36:29 +0000505 wwin->flags.maximized = 0;
69730273 dan2005-05-15 16:45:02 +0000506 wWindowConfigure(wwin, x, y, w, h);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000507
5ef342d9 kojima2001-09-06 21:42:28 +0000508 WMPostNotificationName(WMNChangedState, wwin, "maximize");
0261c326 dan1999-01-06 15:22:33 +0000509
1b587b01 dan2001-01-18 01:33:44 +0000510 wSoundPlay(WSOUND_UNMAXIMIZE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000511}
512
9aca0d5f dan2004-10-12 01:34:32 +0000513
514void
515wFullscreenWindow(WWindow *wwin)
516{
517 int head;
518 WMRect rect;
519
520 if (wwin->flags.fullscreen)
521 return;
522
523 wwin->flags.fullscreen = True;
524
525 wWindowConfigureBorders(wwin);
526
527 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
528
529 wwin->bfs_geometry.x = wwin->frame_x;
530 wwin->bfs_geometry.y = wwin->frame_y;
531 wwin->bfs_geometry.width = wwin->frame->core->width;
532 wwin->bfs_geometry.height = wwin->frame->core->height;
533
534 head = wGetHeadForWindow(wwin);
535 rect = wGetRectForHead(wwin->screen_ptr, head);
536 wWindowConfigure(wwin, rect.pos.x, rect.pos.y,
537 rect.size.width, rect.size.height);
538
539 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
540}
541
542
543void
544wUnfullscreenWindow(WWindow *wwin)
545{
546 if (!wwin->flags.fullscreen)
547 return;
548
549 wwin->flags.fullscreen = False;
550
551 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
552 if (WFLAGP(wwin, sunken)) {
6830b057 dan2004-10-12 21:28:27 +0000553 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
9aca0d5f dan2004-10-12 01:34:32 +0000554 } else if (WFLAGP(wwin, floating)) {
6830b057 dan2004-10-12 21:28:27 +0000555 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
9aca0d5f dan2004-10-12 01:34:32 +0000556 } else {
557 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
558 }
559 }
560
561 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
562 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
563
564 wWindowConfigureBorders(wwin);
620a280d kojima2004-10-22 23:39:11 +0000565 /*
9aca0d5f dan2004-10-12 01:34:32 +0000566 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
567 wFrameWindowPaint(wwin->frame);
620a280d kojima2004-10-22 23:39:11 +0000568 */
9aca0d5f dan2004-10-12 01:34:32 +0000569
570 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
571}
572
573
9d2e6ef9 scottc1998-09-29 22:36:29 +0000574#ifdef ANIMATIONS
575static void
576animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
577 int fx, int fy, int fw, int fh, int steps)
578{
579#define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
580 float cx, cy, cw, ch;
581 float xstep, ystep, wstep, hstep;
84576113 dan2003-07-16 20:58:49 +0000582 XPoint points[5];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000583 float dx, dch, midy;
584 float angle, final_angle, delta;
585
586 xstep = (float)(fx-x)/steps;
587 ystep = (float)(fy-y)/steps;
588 wstep = (float)(fw-w)/steps;
589 hstep = (float)(fh-h)/steps;
84576113 dan2003-07-16 20:58:49 +0000590
9d2e6ef9 scottc1998-09-29 22:36:29 +0000591 cx = (float)x;
592 cy = (float)y;
593 cw = (float)w;
594 ch = (float)h;
595
596 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
597 delta = (float)(final_angle/FRAMES);
598 for (angle=0;; angle+=delta) {
599 if (angle > final_angle)
600 angle = final_angle;
601
602 dx = (cw/10) - ((cw/5) * sin(angle));
603 dch = (ch/2) * cos(angle);
604 midy = cy + (ch/2);
605
606 points[0].x = cx + dx; points[0].y = midy - dch;
607 points[1].x = cx + cw - dx; points[1].y = points[0].y;
608 points[2].x = cx + cw + dx; points[2].y = midy + dch;
609 points[3].x = cx - dx; points[3].y = points[2].y;
610 points[4].x = points[0].x; points[4].y = points[0].y;
611
612 XGrabServer(dpy);
613 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
84576113 dan2003-07-16 20:58:49 +0000614 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000615#if (MINIATURIZE_ANIMATION_DELAY_F > 0)
616 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
f4ef34b8 dan2001-12-17 21:21:59 +0000617#else
618 wusleep(10);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000619#endif
620
84576113 dan2003-07-16 20:58:49 +0000621 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
622 XUngrabServer(dpy);
623 cx+=xstep;
624 cy+=ystep;
625 cw+=wstep;
626 ch+=hstep;
627 if (angle >= final_angle)
628 break;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000629
630 }
631 XFlush(dpy);
632}
633#undef FRAMES
634
635
84576113 dan2003-07-16 20:58:49 +0000636static void
9d2e6ef9 scottc1998-09-29 22:36:29 +0000637animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
638 int fx, int fy, int fw, int fh, int steps)
639{
640#define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
641 float cx, cy, cw, ch;
642 float xstep, ystep, wstep, hstep;
84576113 dan2003-07-16 20:58:49 +0000643 XPoint points[5];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000644 float angle, final_angle, a, d, delta;
645
646 x += w/2;
647 y += h/2;
648 fx += fw/2;
649 fy += fh/2;
650
651 xstep = (float)(fx-x)/steps;
652 ystep = (float)(fy-y)/steps;
653 wstep = (float)(fw-w)/steps;
654 hstep = (float)(fh-h)/steps;
84576113 dan2003-07-16 20:58:49 +0000655
9d2e6ef9 scottc1998-09-29 22:36:29 +0000656 cx = (float)x;
657 cy = (float)y;
658 cw = (float)w;
659 ch = (float)h;
660
661 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
662 delta = (float)(final_angle/FRAMES);
663 for (angle=0;; angle+=delta) {
664 if (angle > final_angle)
665 angle = final_angle;
666
667 a = atan(ch/cw);
668 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
669
670 points[0].x = cx+cos(angle-a)*d;
671 points[0].y = cy+sin(angle-a)*d;
672 points[1].x = cx+cos(angle+a)*d;
673 points[1].y = cy+sin(angle+a)*d;
674 points[2].x = cx+cos(angle-a+WM_PI)*d;
675 points[2].y = cy+sin(angle-a+WM_PI)*d;
676 points[3].x = cx+cos(angle+a+WM_PI)*d;
677 points[3].y = cy+sin(angle+a+WM_PI)*d;
678 points[4].x = cx+cos(angle-a)*d;
679 points[4].y = cy+sin(angle-a)*d;
680 XGrabServer(dpy);
681 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
84576113 dan2003-07-16 20:58:49 +0000682 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000683#if (MINIATURIZE_ANIMATION_DELAY_T > 0)
684 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
f4ef34b8 dan2001-12-17 21:21:59 +0000685#else
686 wusleep(10);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000687#endif
688
689 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
84576113 dan2003-07-16 20:58:49 +0000690 XUngrabServer(dpy);
691 cx+=xstep;
692 cy+=ystep;
693 cw+=wstep;
694 ch+=hstep;
695 if (angle >= final_angle)
696 break;
697
9d2e6ef9 scottc1998-09-29 22:36:29 +0000698 }
699 XFlush(dpy);
700}
701#undef FRAMES
702
703
84576113 dan2003-07-16 20:58:49 +0000704static void
9d2e6ef9 scottc1998-09-29 22:36:29 +0000705animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
706 int fx, int fy, int fw, int fh, int steps)
707{
708#define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
709 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
710 float xstep, ystep, wstep, hstep;
711 int i, j;
712
713 xstep = (float)(fx-x)/steps;
714 ystep = (float)(fy-y)/steps;
715 wstep = (float)(fw-w)/steps;
716 hstep = (float)(fh-h)/steps;
84576113 dan2003-07-16 20:58:49 +0000717
9d2e6ef9 scottc1998-09-29 22:36:29 +0000718 for (j=0; j<FRAMES; j++) {
84576113 dan2003-07-16 20:58:49 +0000719 cx[j] = (float)x;
720 cy[j] = (float)y;
721 cw[j] = (float)w;
722 ch[j] = (float)h;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000723 }
724 XGrabServer(dpy);
725 for (i=0; i<steps; i++) {
84576113 dan2003-07-16 20:58:49 +0000726 for (j=0; j<FRAMES; j++) {
727 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
728 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
729 }
730 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000731#if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
732 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
f4ef34b8 dan2001-12-17 21:21:59 +0000733#else
734 wusleep(10);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000735#endif
84576113 dan2003-07-16 20:58:49 +0000736 for (j=0; j<FRAMES; j++) {
737 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
738 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
739 if (j<FRAMES-1) {
740 cx[j]=cx[j+1];
741 cy[j]=cy[j+1];
742 cw[j]=cw[j+1];
743 ch[j]=ch[j+1];
744 } else {
745 cx[j]+=xstep;
746 cy[j]+=ystep;
747 cw[j]+=wstep;
748 ch[j]+=hstep;
749 }
750 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000751 }
752
753 for (j=0; j<FRAMES; j++) {
84576113 dan2003-07-16 20:58:49 +0000754 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
755 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000756 }
757 XFlush(dpy);
758#if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
759 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
f4ef34b8 dan2001-12-17 21:21:59 +0000760#else
761 wusleep(10);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000762#endif
763 for (j=0; j<FRAMES; j++) {
84576113 dan2003-07-16 20:58:49 +0000764 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
765 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000766 }
84576113 dan2003-07-16 20:58:49 +0000767
9d2e6ef9 scottc1998-09-29 22:36:29 +0000768 XUngrabServer(dpy);
769}
770#undef FRAMES
771
772
fa994f62 kojima2001-08-20 18:11:40 +0000773void
84576113 dan2003-07-16 20:58:49 +0000774animateResize(WScreen *scr, int x, int y, int w, int h,
775 int fx, int fy, int fw, int fh, int hiding)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000776{
777 int style = wPreferences.iconification_style; /* Catch the value */
778 int steps, k;
779
780 if (style == WIS_NONE)
781 return;
782
345d980b dan1998-11-27 12:26:46 +0000783 if (style == WIS_RANDOM) {
84576113 dan2003-07-16 20:58:49 +0000784 style = rand()%3;
345d980b dan1998-11-27 12:26:46 +0000785 }
786
9d2e6ef9 scottc1998-09-29 22:36:29 +0000787 k = (hiding ? 2 : 3);
2ea40ff2 dan2005-05-08 00:51:56 +0000788
9d2e6ef9 scottc1998-09-29 22:36:29 +0000789 switch(style) {
790 case WIS_TWIST:
791 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
792 if (steps>0)
793 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
794 break;
795 case WIS_FLIP:
796 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
797 if (steps>0)
798 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
799 break;
800 case WIS_ZOOM:
801 default:
802 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
803 if (steps>0)
804 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
805 break;
806 }
807}
808#endif /* ANIMATIONS */
809
810
9d2e6ef9 scottc1998-09-29 22:36:29 +0000811static void
812flushExpose()
813{
814 XEvent tmpev;
84576113 dan2003-07-16 20:58:49 +0000815
9d2e6ef9 scottc1998-09-29 22:36:29 +0000816 while (XCheckTypedEvent(dpy, Expose, &tmpev))
84576113 dan2003-07-16 20:58:49 +0000817 WMHandleEvent(&tmpev);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000818 XSync(dpy, 0);
819}
820
821static void
822unmapTransientsFor(WWindow *wwin)
823{
824 WWindow *tmp;
84576113 dan2003-07-16 20:58:49 +0000825
9d2e6ef9 scottc1998-09-29 22:36:29 +0000826
827 tmp = wwin->screen_ptr->focused_window;
828 while (tmp) {
84576113 dan2003-07-16 20:58:49 +0000829 /* unmap the transients for this transient */
830 if (tmp!=wwin && tmp->transient_for == wwin->client_win
831 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
832 || tmp->flags.shaded)) {
833 unmapTransientsFor(tmp);
834 tmp->flags.miniaturized = 1;
835 if (!tmp->flags.shaded) {
836 wWindowUnmap(tmp);
837 } else {
838 XUnmapWindow(dpy, tmp->frame->core->window);
839 }
840 /*
841 if (!tmp->flags.shaded)
842 */
843 wClientSetState(tmp, IconicState, None);
844
845 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
846 }
847 tmp = tmp->prev;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000848 }
849}
850
851
852static void
853mapTransientsFor(WWindow *wwin)
854{
855 WWindow *tmp;
856
857 tmp = wwin->screen_ptr->focused_window;
858 while (tmp) {
84576113 dan2003-07-16 20:58:49 +0000859 /* recursively map the transients for this transient */
860 if (tmp!=wwin && tmp->transient_for == wwin->client_win
861 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
862 && tmp->icon==NULL) {
863 mapTransientsFor(tmp);
864 tmp->flags.miniaturized = 0;
865 if (!tmp->flags.shaded) {
866 wWindowMap(tmp);
867 } else {
868 XMapWindow(dpy, tmp->frame->core->window);
869 }
870 tmp->flags.semi_focused = 0;
871 /*
872 if (!tmp->flags.shaded)
873 */
874 wClientSetState(tmp, NormalState, None);
875
876 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
877 }
878 tmp = tmp->prev;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000879 }
880}
881
e7495baf dan1999-02-17 11:06:40 +0000882#if 0
9d2e6ef9 scottc1998-09-29 22:36:29 +0000883static void
884setupIconGrabs(WIcon *icon)
885{
886 /* setup passive grabs on the icon */
887 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
84576113 dan2003-07-16 20:58:49 +0000888 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000889 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
84576113 dan2003-07-16 20:58:49 +0000890 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000891 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
84576113 dan2003-07-16 20:58:49 +0000892 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000893 XSync(dpy, 0);
894}
e7495baf dan1999-02-17 11:06:40 +0000895#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000896
897static WWindow*
898recursiveTransientFor(WWindow *wwin)
899{
9af1c6c4 dan1998-10-21 14:43:47 +0000900 int i;
901
9d2e6ef9 scottc1998-09-29 22:36:29 +0000902 if (!wwin)
84576113 dan2003-07-16 20:58:49 +0000903 return None;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000904
84576113 dan2003-07-16 20:58:49 +0000905 /* hackish way to detect transient_for cycle */
9af1c6c4 dan1998-10-21 14:43:47 +0000906 i = wwin->screen_ptr->window_count+1;
907
908 while (wwin && wwin->transient_for != None && i>0) {
84576113 dan2003-07-16 20:58:49 +0000909 wwin = wWindowFor(wwin->transient_for);
910 i--;
9af1c6c4 dan1998-10-21 14:43:47 +0000911 }
912 if (i==0 && wwin) {
84576113 dan2003-07-16 20:58:49 +0000913 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
914 wwin->frame->title);
915 return NULL;
9af1c6c4 dan1998-10-21 14:43:47 +0000916 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000917
918 return wwin;
919}
920
e7495baf dan1999-02-17 11:06:40 +0000921#if 0
9d2e6ef9 scottc1998-09-29 22:36:29 +0000922static void
923removeIconGrabs(WIcon *icon)
924{
925 /* remove passive grabs on the icon */
926 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
927 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
84576113 dan2003-07-16 20:58:49 +0000928 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000929 XSync(dpy, 0);
930}
e7495baf dan1999-02-17 11:06:40 +0000931#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000932
7f9f8894 kojima1999-03-15 23:41:22 +0000933
9d2e6ef9 scottc1998-09-29 22:36:29 +0000934void
935wIconifyWindow(WWindow *wwin)
936{
937 XWindowAttributes attribs;
938 int present;
939
940
941 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
84576113 dan2003-07-16 20:58:49 +0000942 /* the window doesn't exist anymore */
943 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000944 }
945
416e3a82 dan1999-01-25 19:06:50 +0000946 if (wwin->flags.miniaturized) {
84576113 dan2003-07-16 20:58:49 +0000947 return;
416e3a82 dan1999-01-25 19:06:50 +0000948 }
949
a8c73756 dan2002-01-04 00:30:11 +0000950 if (wwin->transient_for!=None &&
951 wwin->transient_for!=wwin->screen_ptr->root_win) {
84576113 dan2003-07-16 20:58:49 +0000952 WWindow *owner = wWindowFor(wwin->transient_for);
953
954 if (owner && owner->flags.miniaturized)
955 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000956 }
84576113 dan2003-07-16 20:58:49 +0000957
9d2e6ef9 scottc1998-09-29 22:36:29 +0000958 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
84576113 dan2003-07-16 20:58:49 +0000959
9d2e6ef9 scottc1998-09-29 22:36:29 +0000960 /* if the window is in another workspace, simplify process */
961 if (present) {
84576113 dan2003-07-16 20:58:49 +0000962 /* icon creation may take a while */
963 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
964 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
965 GrabModeAsync, None, None, CurrentTime);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000966 }
ea55bc5e kojima1999-03-18 01:11:18 +0000967
6830b057 dan2004-10-12 21:28:27 +0000968 if (!wPreferences.disable_miniwindows
9aca0d5f dan2004-10-12 01:34:32 +0000969#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +0000970 && !wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +0000971#endif
6830b057 dan2004-10-12 21:28:27 +0000972 ) {
84576113 dan2003-07-16 20:58:49 +0000973 if (!wwin->flags.icon_moved) {
974 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
975 }
976 wwin->icon = wIconCreate(wwin);
2a19d455 kojima1999-04-21 00:16:13 +0000977
84576113 dan2003-07-16 20:58:49 +0000978 wwin->icon->mapped = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000979 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000980
e7495baf dan1999-02-17 11:06:40 +0000981 wwin->flags.miniaturized = 1;
982 wwin->flags.mapped = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000983
984 /* unmap transients */
84576113 dan2003-07-16 20:58:49 +0000985
9d2e6ef9 scottc1998-09-29 22:36:29 +0000986 unmapTransientsFor(wwin);
987
988 if (present) {
84576113 dan2003-07-16 20:58:49 +0000989 wSoundPlay(WSOUND_ICONIFY);
9af1c6c4 dan1998-10-21 14:43:47 +0000990
84576113 dan2003-07-16 20:58:49 +0000991 XUngrabPointer(dpy, CurrentTime);
992 wWindowUnmap(wwin);
993 /* let all Expose events arrive so that we can repaint
994 * something before the animation starts (and the server is grabbed) */
995 XSync(dpy, 0);
ea55bc5e kojima1999-03-18 01:11:18 +0000996
6830b057 dan2004-10-12 21:28:27 +0000997 if (wPreferences.disable_miniwindows
9aca0d5f dan2004-10-12 01:34:32 +0000998#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +0000999 || wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001000#endif
6830b057 dan2004-10-12 21:28:27 +00001001 )
84576113 dan2003-07-16 20:58:49 +00001002 wClientSetState(wwin, IconicState, None);
1003 else
1004 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
ea55bc5e kojima1999-03-18 01:11:18 +00001005
84576113 dan2003-07-16 20:58:49 +00001006 flushExpose();
9d2e6ef9 scottc1998-09-29 22:36:29 +00001007#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +00001008 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1009 && !wPreferences.no_animations) {
1010 int ix, iy, iw, ih;
1011
6830b057 dan2004-10-12 21:28:27 +00001012 if (!wPreferences.disable_miniwindows
9aca0d5f dan2004-10-12 01:34:32 +00001013#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +00001014 && !wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001015#endif
6830b057 dan2004-10-12 21:28:27 +00001016 ) {
84576113 dan2003-07-16 20:58:49 +00001017 ix = wwin->icon_x;
1018 iy = wwin->icon_y;
1019 iw = wwin->icon->core->width;
1020 ih = wwin->icon->core->height;
1021 } else {
9aca0d5f dan2004-10-12 01:34:32 +00001022#ifdef NETWM_HINTS
0c09179f dan2004-10-14 23:05:20 +00001023 if (wwin->flags.net_handle_icon) {
1024 ix = wwin->icon_x;
1025 iy = wwin->icon_y;
1026 iw = wwin->icon_w;
1027 ih = wwin->icon_h;
1028 } else
9aca0d5f dan2004-10-12 01:34:32 +00001029#endif
0c09179f dan2004-10-14 23:05:20 +00001030 {
1031 ix = 0;
1032 iy = 0;
1033 iw = wwin->screen_ptr->scr_width;
1034 ih = wwin->screen_ptr->scr_height;
1035 }
84576113 dan2003-07-16 20:58:49 +00001036 }
1037 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1038 wwin->frame->core->width, wwin->frame->core->height,
1039 ix, iy, iw, ih, False);
1040 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001041#endif
1042 }
84576113 dan2003-07-16 20:58:49 +00001043
9d2e6ef9 scottc1998-09-29 22:36:29 +00001044 wwin->flags.skip_next_animation = 0;
0261c326 dan1999-01-06 15:22:33 +00001045
9aca0d5f dan2004-10-12 01:34:32 +00001046 if (!wPreferences.disable_miniwindows
1047#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +00001048 && !wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001049#endif
6830b057 dan2004-10-12 21:28:27 +00001050 ) {
ea55bc5e kojima1999-03-18 01:11:18 +00001051
84576113 dan2003-07-16 20:58:49 +00001052 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1053 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
9007a657 dan1998-11-23 11:32:19 +00001054
84576113 dan2003-07-16 20:58:49 +00001055 XMapWindow(dpy, wwin->icon->core->window);
ea55bc5e kojima1999-03-18 01:11:18 +00001056
84576113 dan2003-07-16 20:58:49 +00001057 AddToStackList(wwin->icon->core);
ea55bc5e kojima1999-03-18 01:11:18 +00001058
84576113 dan2003-07-16 20:58:49 +00001059 wLowerFrame(wwin->icon->core);
ea55bc5e kojima1999-03-18 01:11:18 +00001060 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001061
1062 if (present) {
84576113 dan2003-07-16 20:58:49 +00001063 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
416e3a82 dan1999-01-25 19:06:50 +00001064
84576113 dan2003-07-16 20:58:49 +00001065 /*
1066 * It doesn't seem to be working and causes button event hangup
1067 * when deiconifying a transient window.
1068 setupIconGrabs(wwin->icon);
1069 */
1070 if ((wwin->flags.focused
1071 || (owner && wwin->client_win == owner->client_win))
1072 && wPreferences.focus_mode==WKF_CLICK) {
1073 WWindow *tmp;
1074
1075 tmp = wwin->prev;
1076 while (tmp) {
1077 if (!WFLAGP(tmp, no_focusable)
1078 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1079 && (wwin->frame->workspace == tmp->frame->workspace))
1080 break;
1081 tmp = tmp->prev;
1082 }
1083 wSetFocusTo(wwin->screen_ptr, tmp);
1084 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1085 wSetFocusTo(wwin->screen_ptr, NULL);
1086 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001087
1088#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +00001089 if (!wwin->screen_ptr->flags.startup) {
9aca0d5f dan2004-10-12 01:34:32 +00001090 /* Catch up with events not processed while animation was running */
84576113 dan2003-07-16 20:58:49 +00001091 Window clientwin = wwin->client_win;
1092
9aca0d5f dan2004-10-12 01:34:32 +00001093 ProcessPendingEvents();
84576113 dan2003-07-16 20:58:49 +00001094
9aca0d5f dan2004-10-12 01:34:32 +00001095 /* the window can disappear while ProcessPendingEvents() runs */
1096 if (!wWindowFor(clientwin)) {
84576113 dan2003-07-16 20:58:49 +00001097 return;
9aca0d5f dan2004-10-12 01:34:32 +00001098 }
84576113 dan2003-07-16 20:58:49 +00001099 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001100#endif
1101 }
1102
6830b057 dan2004-10-12 21:28:27 +00001103 /* maybe we want to do this regardless of net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001104 * it seems to me we might break behaviour this way.
1105 */
1106 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1107#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +00001108 && !wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001109#endif
6830b057 dan2004-10-12 21:28:27 +00001110 )
9d2e6ef9 scottc1998-09-29 22:36:29 +00001111 wIconSelect(wwin->icon);
1112
5ef342d9 kojima2001-09-06 21:42:28 +00001113 WMPostNotificationName(WMNChangedState, wwin, "iconify");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001114}
1115
1116
ea55bc5e kojima1999-03-18 01:11:18 +00001117
1118
9d2e6ef9 scottc1998-09-29 22:36:29 +00001119void
1120wDeiconifyWindow(WWindow *wwin)
1121{
9aca0d5f dan2004-10-12 01:34:32 +00001122#ifdef NETWM_HINTS
1123 /* we're hiding for show_desktop */
1124 int netwm_hidden = wwin->flags.net_show_desktop &&
6830b057 dan2004-10-12 21:28:27 +00001125 wwin->frame->workspace!=wwin->screen_ptr->current_workspace;
9aca0d5f dan2004-10-12 01:34:32 +00001126#else
1127 int netwm_hidden = False;
1128#endif
1129
1130 if (!netwm_hidden)
6830b057 dan2004-10-12 21:28:27 +00001131 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001132
1133 if (!wwin->flags.miniaturized)
84576113 dan2003-07-16 20:58:49 +00001134 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001135
84576113 dan2003-07-16 20:58:49 +00001136 if (wwin->transient_for != None
1137 && wwin->transient_for != wwin->screen_ptr->root_win) {
1138 WWindow *owner = recursiveTransientFor(wwin);
416e3a82 dan1999-01-25 19:06:50 +00001139
84576113 dan2003-07-16 20:58:49 +00001140 if (owner && owner->flags.miniaturized) {
1141 wDeiconifyWindow(owner);
1142 wSetFocusTo(wwin->screen_ptr, wwin);
1143 wRaiseFrame(wwin->frame->core);
1144 return;
1145 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001146 }
1147
416e3a82 dan1999-01-25 19:06:50 +00001148 wwin->flags.miniaturized = 0;
9aca0d5f dan2004-10-12 01:34:32 +00001149
1150 if (!netwm_hidden && !wwin->flags.shaded) {
84576113 dan2003-07-16 20:58:49 +00001151 wwin->flags.mapped = 1;
9aca0d5f dan2004-10-12 01:34:32 +00001152 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001153
9aca0d5f dan2004-10-12 01:34:32 +00001154 if (!netwm_hidden || wPreferences.sticky_icons) {
6830b057 dan2004-10-12 21:28:27 +00001155 /* maybe we want to do this regardless of net_handle_icon
1156 * it seems to me we might break behaviour this way.
1157 */
1158 if (!wPreferences.disable_miniwindows
9aca0d5f dan2004-10-12 01:34:32 +00001159#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +00001160 && !wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001161#endif
6830b057 dan2004-10-12 21:28:27 +00001162 && wwin->icon != NULL) {
1163 if (wwin->icon->selected)
1164 wIconSelect(wwin->icon);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001165
6830b057 dan2004-10-12 21:28:27 +00001166 XUnmapWindow(dpy, wwin->icon->core->window);
1167 }
ea55bc5e kojima1999-03-18 01:11:18 +00001168 }
9af1c6c4 dan1998-10-21 14:43:47 +00001169
9aca0d5f dan2004-10-12 01:34:32 +00001170 if (!netwm_hidden)
6830b057 dan2004-10-12 21:28:27 +00001171 wSoundPlay(WSOUND_DEICONIFY);
9af1c6c4 dan1998-10-21 14:43:47 +00001172
9d2e6ef9 scottc1998-09-29 22:36:29 +00001173 /* if the window is in another workspace, do it silently */
9aca0d5f dan2004-10-12 01:34:32 +00001174 if (!netwm_hidden) {
9d2e6ef9 scottc1998-09-29 22:36:29 +00001175#ifdef ANIMATIONS
6830b057 dan2004-10-12 21:28:27 +00001176 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1177 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1178 int ix, iy, iw, ih;
9aca0d5f dan2004-10-12 01:34:32 +00001179
6830b057 dan2004-10-12 21:28:27 +00001180 if (!wPreferences.disable_miniwindows
9aca0d5f dan2004-10-12 01:34:32 +00001181#ifdef NETWM_HINTS
6830b057 dan2004-10-12 21:28:27 +00001182 && !wwin->flags.net_handle_icon
9aca0d5f dan2004-10-12 01:34:32 +00001183#endif
6830b057 dan2004-10-12 21:28:27 +00001184 ) {
1185 ix = wwin->icon_x;
1186 iy = wwin->icon_y;
1187 iw = wwin->icon->core->width;
1188 ih = wwin->icon->core->height;
1189 } else {
9aca0d5f dan2004-10-12 01:34:32 +00001190#ifdef NETWM_HINTS
0c09179f dan2004-10-14 23:05:20 +00001191 if (wwin->flags.net_handle_icon) {
1192 ix = wwin->icon_x;
1193 iy = wwin->icon_y;
1194 iw = wwin->icon_w;
1195 ih = wwin->icon_h;
1196 } else
9aca0d5f dan2004-10-12 01:34:32 +00001197#endif
0c09179f dan2004-10-14 23:05:20 +00001198 {
1199 ix = 0;
1200 iy = 0;
1201 iw = wwin->screen_ptr->scr_width;
1202 ih = wwin->screen_ptr->scr_height;
1203 }
6830b057 dan2004-10-12 21:28:27 +00001204 }
1205 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1206 wwin->frame_x, wwin->frame_y,
1207 wwin->frame->core->width, wwin->frame->core->height,
1208 False);
1209 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001210#endif /* ANIMATIONS */
6830b057 dan2004-10-12 21:28:27 +00001211 wwin->flags.skip_next_animation = 0;
1212 XGrabServer(dpy);
1213 if (!wwin->flags.shaded) {
1214 XMapWindow(dpy, wwin->client_win);
1215 }
1216 XMapWindow(dpy, wwin->frame->core->window);
1217 wRaiseFrame(wwin->frame->core);
1218 if (!wwin->flags.shaded) {
1219 wClientSetState(wwin, NormalState, None);
1220 }
1221 mapTransientsFor(wwin);
9aca0d5f dan2004-10-12 01:34:32 +00001222 }
1223
1224 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1225#ifdef NETWM_HINTS
1226 && !wwin->flags.net_handle_icon
1227#endif
6830b057 dan2004-10-12 21:28:27 +00001228 ) {
84576113 dan2003-07-16 20:58:49 +00001229 RemoveFromStackList(wwin->icon->core);
1230 /* removeIconGrabs(wwin->icon);*/
1231 wIconDestroy(wwin->icon);
1232 wwin->icon = NULL;
ea55bc5e kojima1999-03-18 01:11:18 +00001233 }
7f018497 kojima1999-04-24 20:08:20 +00001234
9aca0d5f dan2004-10-12 01:34:32 +00001235 if (!netwm_hidden) {
6830b057 dan2004-10-12 21:28:27 +00001236 XUngrabServer(dpy);
9aca0d5f dan2004-10-12 01:34:32 +00001237
6830b057 dan2004-10-12 21:28:27 +00001238 wSetFocusTo(wwin->screen_ptr, wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001239
9d2e6ef9 scottc1998-09-29 22:36:29 +00001240#ifdef ANIMATIONS
6830b057 dan2004-10-12 21:28:27 +00001241 if (!wwin->screen_ptr->flags.startup) {
9aca0d5f dan2004-10-12 01:34:32 +00001242 /* Catch up with events not processed while animation was running */
6830b057 dan2004-10-12 21:28:27 +00001243 Window clientwin = wwin->client_win;
84576113 dan2003-07-16 20:58:49 +00001244
6830b057 dan2004-10-12 21:28:27 +00001245 ProcessPendingEvents();
84576113 dan2003-07-16 20:58:49 +00001246
9aca0d5f dan2004-10-12 01:34:32 +00001247 /* the window can disappear while ProcessPendingEvents() runs */
1248 if (!wWindowFor(clientwin)) {
1249 return;
1250 }
6830b057 dan2004-10-12 21:28:27 +00001251 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001252#endif
9aca0d5f dan2004-10-12 01:34:32 +00001253 }
84576113 dan2003-07-16 20:58:49 +00001254
9d2e6ef9 scottc1998-09-29 22:36:29 +00001255 if (wPreferences.auto_arrange_icons) {
1256 wArrangeIcons(wwin->screen_ptr, True);
1257 }
1258
5ef342d9 kojima2001-09-06 21:42:28 +00001259 WMPostNotificationName(WMNChangedState, wwin, "iconify");
0c4dc1c2 dan2001-11-20 13:48:23 +00001260
1261 /* In case we were shaded and iconified, also unshade */
9aca0d5f dan2004-10-12 01:34:32 +00001262 if (!netwm_hidden)
6830b057 dan2004-10-12 21:28:27 +00001263 wUnshadeWindow(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001264}
1265
1266
1267
1268static void
1269hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1270{
9d2e6ef9 scottc1998-09-29 22:36:29 +00001271 if (wwin->flags.miniaturized) {
84576113 dan2003-07-16 20:58:49 +00001272 if (wwin->icon) {
1273 XUnmapWindow(dpy, wwin->icon->core->window);
1274 wwin->icon->mapped = 0;
1275 }
1276 wwin->flags.hidden = 1;
1277
1278 WMPostNotificationName(WMNChangedState, wwin, "hide");
1279 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001280 }
1281
1282 if (wwin->flags.inspector_open) {
84576113 dan2003-07-16 20:58:49 +00001283 wHideInspectorForWindow(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001284 }
1285
9d2e6ef9 scottc1998-09-29 22:36:29 +00001286 wwin->flags.hidden = 1;
416e3a82 dan1999-01-25 19:06:50 +00001287 wWindowUnmap(wwin);
e7495baf dan1999-02-17 11:06:40 +00001288
9d2e6ef9 scottc1998-09-29 22:36:29 +00001289 wClientSetState(wwin, IconicState, icon->icon_win);
1290 flushExpose();
1b587b01 dan2001-01-18 01:33:44 +00001291 wSoundPlay(WSOUND_HIDE);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001292#ifdef ANIMATIONS
1293 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
84576113 dan2003-07-16 20:58:49 +00001294 !wwin->flags.skip_next_animation && animate) {
1295 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1296 wwin->frame->core->width, wwin->frame->core->height,
1297 icon_x, icon_y, icon->core->width, icon->core->height,
1298 True);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001299 }
1300#endif
1301 wwin->flags.skip_next_animation = 0;
1302
5ef342d9 kojima2001-09-06 21:42:28 +00001303 WMPostNotificationName(WMNChangedState, wwin, "hide");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001304}
1305
1306
1307
1308void
1309wHideOtherApplications(WWindow *awin)
1310{
1311 WWindow *wwin;
1312 WApplication *tapp;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001313
1314 if (!awin)
84576113 dan2003-07-16 20:58:49 +00001315 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001316 wwin = awin->screen_ptr->focused_window;
1317
9d2e6ef9 scottc1998-09-29 22:36:29 +00001318
1319 while (wwin) {
84576113 dan2003-07-16 20:58:49 +00001320 if (wwin!=awin
1321 && wwin->frame->workspace == awin->screen_ptr->current_workspace
9d2e6ef9 scottc1998-09-29 22:36:29 +00001322 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1323 && !wwin->flags.internal_window
84576113 dan2003-07-16 20:58:49 +00001324 && wGetWindowOfInspectorForWindow(wwin) != awin
1325 && !WFLAGP(wwin, no_hide_others)) {
1326
1327 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1328 if (!WFLAGP(wwin, no_miniaturizable)) {
1329 wwin->flags.skip_next_animation = 1;
1330 wIconifyWindow(wwin);
1331 }
1332 } else if (wwin->main_window!=None
1333 && awin->main_window != wwin->main_window) {
1334 tapp = wApplicationOf(wwin->main_window);
1335 if (tapp) {
1336 tapp->flags.skip_next_animation = 1;
1337 wHideApplication(tapp);
1338 } else {
1339 if (!WFLAGP(wwin, no_miniaturizable)) {
1340 wwin->flags.skip_next_animation = 1;
1341 wIconifyWindow(wwin);
1342 }
1343 }
1344 }
1345 }
1346 wwin = wwin->prev;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001347 }
1348 /*
84576113 dan2003-07-16 20:58:49 +00001349 wSetFocusTo(awin->screen_ptr, awin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001350 */
1351}
1352
1353
1354
1355void
1356wHideApplication(WApplication *wapp)
1357{
9d2e6ef9 scottc1998-09-29 22:36:29 +00001358 WScreen *scr;
1359 WWindow *wlist;
1360 int hadfocus;
2ea40ff2 dan2005-05-08 00:51:56 +00001361 int animate;
84576113 dan2003-07-16 20:58:49 +00001362
9d2e6ef9 scottc1998-09-29 22:36:29 +00001363 if (!wapp) {
84576113 dan2003-07-16 20:58:49 +00001364 wwarning("trying to hide a non grouped window");
1365 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001366 }
1367 if (!wapp->main_window_desc) {
84576113 dan2003-07-16 20:58:49 +00001368 wwarning("group leader not found for window group");
1369 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001370 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001371 scr = wapp->main_window_desc->screen_ptr;
1372 hadfocus = 0;
1373 wlist = scr->focused_window;
1374 if (!wlist)
84576113 dan2003-07-16 20:58:49 +00001375 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001376
1377 if (wlist->main_window == wapp->main_window)
84576113 dan2003-07-16 20:58:49 +00001378 wapp->last_focused = wlist;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001379 else
84576113 dan2003-07-16 20:58:49 +00001380 wapp->last_focused = NULL;
2ea40ff2 dan2005-05-08 00:51:56 +00001381
1382 animate = !wapp->flags.skip_next_animation;
1383
9d2e6ef9 scottc1998-09-29 22:36:29 +00001384 while (wlist) {
84576113 dan2003-07-16 20:58:49 +00001385 if (wlist->main_window == wapp->main_window) {
1386 if (wlist->flags.focused) {
1387 hadfocus = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001388 }
2ea40ff2 dan2005-05-08 00:51:56 +00001389 if (wapp->app_icon) {
9d2e6ef9 scottc1998-09-29 22:36:29 +00001390 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
2ea40ff2 dan2005-05-08 00:51:56 +00001391 wapp->app_icon->y_pos, wlist, animate);
1392 animate = False;
1393 }
84576113 dan2003-07-16 20:58:49 +00001394 }
1395 wlist = wlist->prev;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001396 }
84576113 dan2003-07-16 20:58:49 +00001397
1398 wapp->flags.skip_next_animation = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001399
1400 if (hadfocus) {
84576113 dan2003-07-16 20:58:49 +00001401 if (wPreferences.focus_mode==WKF_CLICK) {
1402 wlist = scr->focused_window;
1403 while (wlist) {
1404 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1405 && (wlist->flags.mapped || wlist->flags.shaded))
1406 break;
1407 wlist = wlist->prev;
1408 }
1409 wSetFocusTo(scr, wlist);
1410 } else {
1411 wSetFocusTo(scr, NULL);
1412 }
1413 }
1414
9d2e6ef9 scottc1998-09-29 22:36:29 +00001415 wapp->flags.hidden = 1;
84576113 dan2003-07-16 20:58:49 +00001416
9007a657 dan1998-11-23 11:32:19 +00001417 if(wPreferences.auto_arrange_icons) {
84576113 dan2003-07-16 20:58:49 +00001418 wArrangeIcons(scr, True);
9007a657 dan1998-11-23 11:32:19 +00001419 }
7f9f8894 kojima1999-03-15 23:41:22 +00001420#ifdef HIDDENDOT
4a473b8a kojima1999-04-10 18:27:21 +00001421 if (wapp->app_icon)
84576113 dan2003-07-16 20:58:49 +00001422 wAppIconPaint(wapp->app_icon);
7f9f8894 kojima1999-03-15 23:41:22 +00001423#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +00001424}
1425
1426
1427
1428
1429static void
1430unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
84576113 dan2003-07-16 20:58:49 +00001431 int bringToCurrentWS)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001432{
1433 if (bringToCurrentWS)
84576113 dan2003-07-16 20:58:49 +00001434 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001435
1436 wwin->flags.hidden=0;
6f28d987 dan2001-12-18 16:10:07 +00001437
1b587b01 dan2001-01-18 01:33:44 +00001438 wSoundPlay(WSOUND_UNHIDE);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001439#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +00001440 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1441 && animate) {
1442 animateResize(wwin->screen_ptr, icon_x, icon_y,
1443 icon->core->width, icon->core->height,
1444 wwin->frame_x, wwin->frame_y,
1445 wwin->frame->core->width, wwin->frame->core->height,
9d2e6ef9 scottc1998-09-29 22:36:29 +00001446 True);
1447 }
1448#endif
1449 wwin->flags.skip_next_animation = 0;
6f28d987 dan2001-12-18 16:10:07 +00001450 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1451 XMapWindow(dpy, wwin->client_win);
1452 XMapWindow(dpy, wwin->frame->core->window);
1453 wClientSetState(wwin, NormalState, None);
1454 wwin->flags.mapped=1;
1455 wRaiseFrame(wwin->frame->core);
1456 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001457 if (wwin->flags.inspector_open) {
6f28d987 dan2001-12-18 16:10:07 +00001458 wUnhideInspectorForWindow(wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001459 }
1460
5ef342d9 kojima2001-09-06 21:42:28 +00001461 WMPostNotificationName(WMNChangedState, wwin, "hide");
9d2e6ef9 scottc1998-09-29 22:36:29 +00001462}
1463
1464
1465void
1466wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1467{
1468 WScreen *scr;
1469 WWindow *wlist, *next;
1470 WWindow *focused=NULL;
2ea40ff2 dan2005-05-08 00:51:56 +00001471 int animate;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001472
b3816743 dan2003-02-11 00:32:17 +00001473 if (!wapp)
84576113 dan2003-07-16 20:58:49 +00001474 return;
b3816743 dan2003-02-11 00:32:17 +00001475
9d2e6ef9 scottc1998-09-29 22:36:29 +00001476 scr = wapp->main_window_desc->screen_ptr;
1477 wlist = scr->focused_window;
b3816743 dan2003-02-11 00:32:17 +00001478 if (!wlist)
1479 return;
1480
9d2e6ef9 scottc1998-09-29 22:36:29 +00001481 /* goto beginning of list */
1482 while (wlist->prev)
84576113 dan2003-07-16 20:58:49 +00001483 wlist = wlist->prev;
b3816743 dan2003-02-11 00:32:17 +00001484
2ea40ff2 dan2005-05-08 00:51:56 +00001485 animate = !wapp->flags.skip_next_animation;
1486
9d2e6ef9 scottc1998-09-29 22:36:29 +00001487 while (wlist) {
84576113 dan2003-07-16 20:58:49 +00001488 next = wlist->next;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001489
84576113 dan2003-07-16 20:58:49 +00001490 if (wlist->main_window == wapp->main_window) {
1491 if (wlist->flags.focused)
b3816743 dan2003-02-11 00:32:17 +00001492 focused = wlist;
84576113 dan2003-07-16 20:58:49 +00001493 else if (!focused || !focused->flags.focused)
b3816743 dan2003-02-11 00:32:17 +00001494 focused = wlist;
1495
84576113 dan2003-07-16 20:58:49 +00001496 if (wlist->flags.miniaturized) {
4e8423d1 dan2006-04-27 19:16:58 +00001497 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1498 wlist->frame->workspace == scr->current_workspace) &&
1499 wlist->icon) {
1500 if (!wlist->icon->mapped) {
ad0ae488 dan2005-07-03 17:37:03 +00001501 int x, y;
1502
1503 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1504 if (wlist->icon_x!=x || wlist->icon_y!=y) {
1505 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1506 }
1507 wlist->icon_x = x;
1508 wlist->icon_y = y;
b3816743 dan2003-02-11 00:32:17 +00001509 XMapWindow(dpy, wlist->icon->core->window);
1510 wlist->icon->mapped = 1;
1511 }
ad0ae488 dan2005-07-03 17:37:03 +00001512 wRaiseFrame(wlist->icon->core);
b3816743 dan2003-02-11 00:32:17 +00001513 }
1514 if (bringToCurrentWS)
1515 wWindowChangeWorkspace(wlist, scr->current_workspace);
1516 wlist->flags.hidden = 0;
1517 if (miniwindows &&
1518 wlist->frame->workspace == scr->current_workspace) {
1519 wDeiconifyWindow(wlist);
1520 }
1521 WMPostNotificationName(WMNChangedState, wlist, "hide");
1522 } else if (wlist->flags.shaded) {
1523 if (bringToCurrentWS)
1524 wWindowChangeWorkspace(wlist, scr->current_workspace);
1525 wlist->flags.hidden = 0;
fe4cd695 dan2003-02-24 04:06:20 +00001526 if (wlist->frame->workspace == scr->current_workspace) {
1527 XMapWindow(dpy, wlist->frame->core->window);
1528 if (miniwindows) {
1529 wUnshadeWindow(wlist);
1530 wRaiseFrame(wlist->frame->core);
1531 }
b3816743 dan2003-02-11 00:32:17 +00001532 }
1533 WMPostNotificationName(WMNChangedState, wlist, "hide");
84576113 dan2003-07-16 20:58:49 +00001534 } else if (wlist->flags.hidden) {
1535 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
2ea40ff2 dan2005-05-08 00:51:56 +00001536 wapp->app_icon->y_pos, wlist, animate,
84576113 dan2003-07-16 20:58:49 +00001537 bringToCurrentWS);
2ea40ff2 dan2005-05-08 00:51:56 +00001538 animate = False;
84576113 dan2003-07-16 20:58:49 +00001539 } else {
1540 if (bringToCurrentWS
1541 && wlist->frame->workspace != scr->current_workspace) {
1542 wWindowChangeWorkspace(wlist, scr->current_workspace);
1543 }
1544 wRaiseFrame(wlist->frame->core);
1545 }
1546 }
1547 wlist = next;
1548 }
1549
9d2e6ef9 scottc1998-09-29 22:36:29 +00001550 wapp->flags.skip_next_animation = 0;
1551 wapp->flags.hidden = 0;
84576113 dan2003-07-16 20:58:49 +00001552
b3816743 dan2003-02-11 00:32:17 +00001553 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1554 wRaiseFrame(wapp->last_focused->frame->core);
1555 wSetFocusTo(scr, wapp->last_focused);
1556 } else if (focused) {
1557 wSetFocusTo(scr, focused);
1558 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001559 wapp->last_focused = NULL;
ad0ae488 dan2005-07-03 17:37:03 +00001560 if (wPreferences.auto_arrange_icons) {
9d2e6ef9 scottc1998-09-29 22:36:29 +00001561 wArrangeIcons(scr, True);
1562 }
7f9f8894 kojima1999-03-15 23:41:22 +00001563#ifdef HIDDENDOT
1564 wAppIconPaint(wapp->app_icon);
84576113 dan2003-07-16 20:58:49 +00001565#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +00001566}
1567
1568
9d2e6ef9 scottc1998-09-29 22:36:29 +00001569void
1570wShowAllWindows(WScreen *scr)
1571{
1572 WWindow *wwin, *old_foc;
1573 WApplication *wapp;
1574
1575 old_foc = wwin = scr->focused_window;
1576 while (wwin) {
1577 if (!wwin->flags.internal_window &&
1578 (scr->current_workspace == wwin->frame->workspace
84576113 dan2003-07-16 20:58:49 +00001579 || IS_OMNIPRESENT(wwin))) {
1580 if (wwin->flags.miniaturized) {
1581 wwin->flags.skip_next_animation = 1;
1582 wDeiconifyWindow(wwin);
1583 } else if (wwin->flags.hidden) {
1584 wapp = wApplicationOf(wwin->main_window);
1585 if (wapp) {
1586 wUnhideApplication(wapp, False, False);
1587 } else {
1588 wwin->flags.skip_next_animation = 1;
1589 wDeiconifyWindow(wwin);
1590 }
1591 }
1592 }
1593 wwin = wwin->prev;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001594 }
1595 wSetFocusTo(scr, old_foc);
1596 /*wRaiseFrame(old_foc->frame->core);*/
1597}
1598
1599
1600void
1601wRefreshDesktop(WScreen *scr)
1602{
1603 Window win;
1604 XSetWindowAttributes attr;
1605
1606 attr.backing_store = NotUseful;
1607 attr.save_under = False;
84576113 dan2003-07-16 20:58:49 +00001608 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1609 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1610 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1611 &attr);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001612 XMapRaised(dpy, win);
1613 XDestroyWindow(dpy, win);
1614 XFlush(dpy);
1615}
1616
1617
1618void
1619wArrangeIcons(WScreen *scr, Bool arrangeAll)
1620{
1621 WWindow *wwin;
1622 WAppIcon *aicon;
27a396d7 dan2003-06-06 04:11:00 +00001623
1624 int head;
1625 const int heads = wXineramaHeads(scr);
1626
84576113 dan2003-07-16 20:58:49 +00001627 struct HeadVars {
1628 int pf; /* primary axis */
1629 int sf; /* secondary axis */
1630 int fullW;
1631 int fullH;
1632 int pi, si;
1633 int sx1, sx2, sy1, sy2; /* screen boundary */
1634 int sw, sh;
1635 int xo, yo;
1636 int xs, ys;
1637 } *vars;
27a396d7 dan2003-06-06 04:11:00 +00001638
1639 int isize = wPreferences.icon_size;
1640
84576113 dan2003-07-16 20:58:49 +00001641 vars = (struct HeadVars*)wmalloc(sizeof(struct HeadVars)*heads);
1642
27a396d7 dan2003-06-06 04:11:00 +00001643 for (head = 0; head < heads; ++head) {
1644#if 0
84576113 dan2003-07-16 20:58:49 +00001645 WMRect rect = wGetRectForHead(scr, head);
27a396d7 dan2003-06-06 04:11:00 +00001646#else
84576113 dan2003-07-16 20:58:49 +00001647 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1648 WMRect rect = wmkrect(area.x1, area.y1, area.x2-area.x1, area.y2-area.y1);
27a396d7 dan2003-06-06 04:11:00 +00001649#endif
1650
84576113 dan2003-07-16 20:58:49 +00001651 vars[head].pi = vars[head].si = 0;
1652 vars[head].sx1 = rect.pos.x;
1653 vars[head].sy1 = rect.pos.y;
1654 vars[head].sw = rect.size.width;
1655 vars[head].sh = rect.size.height;
1656 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1657 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
27a396d7 dan2003-06-06 04:11:00 +00001658
1659#if 0
84576113 dan2003-07-16 20:58:49 +00001660 if (scr->dock) {
1661 if (scr->dock->on_right_side)
1662 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1663 else
1664 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1665 }
27a396d7 dan2003-06-06 04:11:00 +00001666#endif
1667
84576113 dan2003-07-16 20:58:49 +00001668 vars[head].sw = isize * (vars[head].sw/isize);
1669 vars[head].sh = isize * (vars[head].sh/isize);
1670 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1671 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1672
1673 /* icon yard boundaries */
1674 if (wPreferences.icon_yard & IY_VERT) {
1675 vars[head].pf = vars[head].fullH;
1676 vars[head].sf = vars[head].fullW;
1677 } else {
1678 vars[head].pf = vars[head].fullW;
1679 vars[head].sf = vars[head].fullH;
1680 }
1681 if (wPreferences.icon_yard & IY_RIGHT) {
1682 vars[head].xo = vars[head].sx2 - isize;
1683 vars[head].xs = -1;
1684 } else {
1685 vars[head].xo = vars[head].sx1;
1686 vars[head].xs = 1;
1687 }
1688 if (wPreferences.icon_yard & IY_TOP) {
1689 vars[head].yo = vars[head].sy1;
1690 vars[head].ys = 1;
1691 } else {
1692 vars[head].yo = vars[head].sy2 - isize;
1693 vars[head].ys = -1;
1694 }
27a396d7 dan2003-06-06 04:11:00 +00001695 }
1696
1697#define X ((wPreferences.icon_yard & IY_VERT) \
84576113 dan2003-07-16 20:58:49 +00001698 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1699 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
27a396d7 dan2003-06-06 04:11:00 +00001700
1701#define Y ((wPreferences.icon_yard & IY_VERT) \
84576113 dan2003-07-16 20:58:49 +00001702 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1703 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
27a396d7 dan2003-06-06 04:11:00 +00001704
1705
1706 /* arrange application icons */
1707 aicon = scr->app_icon_list;
1708 /* reverse them to avoid unnecessarily sliding of icons */
1709 while (aicon && aicon->next)
84576113 dan2003-07-16 20:58:49 +00001710 aicon = aicon->next;
27a396d7 dan2003-06-06 04:11:00 +00001711
1712 while (aicon) {
84576113 dan2003-07-16 20:58:49 +00001713 if (!aicon->docked) {
9aca0d5f dan2004-10-12 01:34:32 +00001714 /* CHECK: can icon be NULL here ? */
1715 /* The intention here is to place the AppIcon on the head that
1716 * contains most of the applications _main_ window. */
84576113 dan2003-07-16 20:58:49 +00001717 head = wGetHeadForWindow(aicon->icon->owner);
27a396d7 dan2003-06-06 04:11:00 +00001718
84576113 dan2003-07-16 20:58:49 +00001719 if (aicon->x_pos != X || aicon->y_pos != Y) {
27a396d7 dan2003-06-06 04:11:00 +00001720#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +00001721 if (!wPreferences.no_animations) {
1722 SlideWindow(aicon->icon->core->window,
1723 aicon->x_pos, aicon->y_pos, X, Y);
1724 }
27a396d7 dan2003-06-06 04:11:00 +00001725#endif /* ANIMATIONS */
84576113 dan2003-07-16 20:58:49 +00001726 }
1727 wAppIconMove(aicon, X, Y);
1728 vars[head].pi++;
1729 if (vars[head].pi >= vars[head].pf) {
1730 vars[head].pi = 0;
1731 vars[head].si++;
1732 }
1733 }
1734 aicon = aicon->prev;
27a396d7 dan2003-06-06 04:11:00 +00001735 }
1736
1737 /* arrange miniwindows */
1738 wwin = scr->focused_window;
1739 /* reverse them to avoid unnecessarily shuffling */
1740 while (wwin && wwin->prev)
84576113 dan2003-07-16 20:58:49 +00001741 wwin = wwin->prev;
27a396d7 dan2003-06-06 04:11:00 +00001742
1743 while (wwin) {
1744 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1745 (wwin->frame->workspace==scr->current_workspace ||
1746 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1747
84576113 dan2003-07-16 20:58:49 +00001748 head = wGetHeadForWindow(wwin);
1749
1750 if (arrangeAll || !wwin->flags.icon_moved) {
1751 if (wwin->icon_x != X || wwin->icon_y != Y) {
27a396d7 dan2003-06-06 04:11:00 +00001752#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +00001753 if (wPreferences.no_animations) {
1754 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1755 } else {
1756 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1757 wwin->icon_y, X, Y);
1758 }
27a396d7 dan2003-06-06 04:11:00 +00001759#else
84576113 dan2003-07-16 20:58:49 +00001760 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
27a396d7 dan2003-06-06 04:11:00 +00001761#endif /* ANIMATIONS */
84576113 dan2003-07-16 20:58:49 +00001762 }
1763 wwin->icon_x = X;
1764 wwin->icon_y = Y;
1765
1766 vars[head].pi++;
1767 if (vars[head].pi >= vars[head].pf) {
1768 vars[head].pi = 0;
1769 vars[head].si++;
1770 }
1771 }
1772 }
1773 if (arrangeAll) {
1774 wwin->flags.icon_moved = 0;
1775 }
27a396d7 dan2003-06-06 04:11:00 +00001776 /* we reversed the order, so we use next */
1777 wwin = wwin->next;
1778 }
84576113 dan2003-07-16 20:58:49 +00001779
1780 wfree(vars);
27a396d7 dan2003-06-06 04:11:00 +00001781}
1782
1783#if 0
1784void
1785wArrangeIcons(WScreen *scr, Bool arrangeAll)
1786{
1787 WWindow *wwin;
1788 WAppIcon *aicon;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001789 int pf; /* primary axis */
1790 int sf; /* secondary axis */
1791 int fullW;
1792 int fullH;
1793 int pi, si;
1794 int sx1, sx2, sy1, sy2; /* screen boundary */
1795 int sw, sh;
1796 int xo, yo;
1797 int xs, ys;
1798 int isize = wPreferences.icon_size;
1799
1800 /*
1801 * Find out screen boundaries.
1802 */
a10214a5 kojima2002-11-28 22:04:07 +00001803
1804 /*
1805 * Allows each head to have miniwindows
1806 */
1807 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1808
1809 sx1 = rect.pos.x;
1810 sy1 = rect.pos.y;
1811 sw = rect.size.width;
1812 sh = rect.size.height;
1813 sx2 = sx1 + sw;
1814 sy2 = sy1 + sh;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001815 if (scr->dock) {
84576113 dan2003-07-16 20:58:49 +00001816 if (scr->dock->on_right_side)
1817 sx2 -= isize + DOCK_EXTRA_SPACE;
1818 else
1819 sx1 += isize + DOCK_EXTRA_SPACE;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001820 }
1821
a10214a5 kojima2002-11-28 22:04:07 +00001822#if 0
9d2e6ef9 scottc1998-09-29 22:36:29 +00001823 sw = isize * (scr->scr_width/isize);
1824 sh = isize * (scr->scr_height/isize);
a10214a5 kojima2002-11-28 22:04:07 +00001825#else
1826 sw = isize * (sw/isize);
1827 sh = isize * (sh/isize);
1828#endif
1829 fullW = (sx2-sx1)/isize;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001830 fullH = (sy2-sy1)/isize;
1831
84576113 dan2003-07-16 20:58:49 +00001832 /* icon yard boundaries */
9d2e6ef9 scottc1998-09-29 22:36:29 +00001833 if (wPreferences.icon_yard & IY_VERT) {
84576113 dan2003-07-16 20:58:49 +00001834 pf = fullH;
1835 sf = fullW;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001836 } else {
84576113 dan2003-07-16 20:58:49 +00001837 pf = fullW;
1838 sf = fullH;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001839 }
1840 if (wPreferences.icon_yard & IY_RIGHT) {
84576113 dan2003-07-16 20:58:49 +00001841 xo = sx2 - isize;
1842 xs = -1;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001843 } else {
84576113 dan2003-07-16 20:58:49 +00001844 xo = sx1;
1845 xs = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001846 }
1847 if (wPreferences.icon_yard & IY_TOP) {
84576113 dan2003-07-16 20:58:49 +00001848 yo = sy1;
1849 ys = 1;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001850 } else {
84576113 dan2003-07-16 20:58:49 +00001851 yo = sy2 - isize;
1852 ys = -1;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001853 }
1854
1855 /* arrange icons putting the most recently focused window
1856 * as the last icon */
1857#define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
84576113 dan2003-07-16 20:58:49 +00001858 : xo + xs*(pi*isize))
9d2e6ef9 scottc1998-09-29 22:36:29 +00001859#define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
84576113 dan2003-07-16 20:58:49 +00001860 : yo + ys*(si*isize))
9d2e6ef9 scottc1998-09-29 22:36:29 +00001861
1862 /* arrange application icons */
1863 aicon = scr->app_icon_list;
1864 /* reverse them to avoid unnecessarily sliding of icons */
1865 while (aicon && aicon->next)
1866 aicon = aicon->next;
1867
1868 pi = 0;
1869 si = 0;
84576113 dan2003-07-16 20:58:49 +00001870 while (aicon) {
672c42cc dan2001-12-17 04:02:33 +00001871 if (!aicon->docked) {
9d2e6ef9 scottc1998-09-29 22:36:29 +00001872 if (aicon->x_pos != X || aicon->y_pos != Y) {
1873#ifdef ANIMATIONS
1874 if (!wPreferences.no_animations) {
1875 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1876 X, Y);
1877 }
1878#endif /* ANIMATIONS */
84576113 dan2003-07-16 20:58:49 +00001879 }
1880 wAppIconMove(aicon, X, Y);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001881 pi++;
1882 }
1883 /* we reversed the order so we use prev */
1884 aicon = aicon->prev;
1885 if (pi >= pf) {
1886 pi=0;
1887 si++;
1888 }
1889 }
84576113 dan2003-07-16 20:58:49 +00001890
9d2e6ef9 scottc1998-09-29 22:36:29 +00001891 /* arrange miniwindows */
1892
1893 wwin = scr->focused_window;
1894 /* reverse them to avoid unnecessarily shuffling */
1895 while (wwin && wwin->prev)
1896 wwin = wwin->prev;
1897
7f36af4f kojima1999-05-31 20:34:00 +00001898 while (wwin) {
1899 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
9d2e6ef9 scottc1998-09-29 22:36:29 +00001900 (wwin->frame->workspace==scr->current_workspace ||
0261c326 dan1999-01-06 15:22:33 +00001901 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
84576113 dan2003-07-16 20:58:49 +00001902
1903 if (arrangeAll || !wwin->flags.icon_moved) {
1904 if (wwin->icon_x != X || wwin->icon_y != Y) {
9d2e6ef9 scottc1998-09-29 22:36:29 +00001905#ifdef ANIMATIONS
84576113 dan2003-07-16 20:58:49 +00001906 if (wPreferences.no_animations) {
1907 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1908 } else {
1909 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1910 wwin->icon_y, X, Y);
1911 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001912#else
84576113 dan2003-07-16 20:58:49 +00001913 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001914#endif /* ANIMATIONS */
84576113 dan2003-07-16 20:58:49 +00001915 }
1916 wwin->icon_x = X;
1917 wwin->icon_y = Y;
1918 pi++;
1919 }
1920 }
1921 if (arrangeAll) {
1922 wwin->flags.icon_moved = 0;
1923 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001924 /* we reversed the order, so we use next */
1925 wwin = wwin->next;
84576113 dan2003-07-16 20:58:49 +00001926 if (pi >= pf) {
1927 pi=0;
1928 si++;
1929 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001930 }
1931}
27a396d7 dan2003-06-06 04:11:00 +00001932#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +00001933
59eb9475 dan1998-11-03 12:53:26 +00001934void
1935wSelectWindow(WWindow *wwin, Bool flag)
1936{
1937 WScreen *scr = wwin->screen_ptr;
84576113 dan2003-07-16 20:58:49 +00001938
59eb9475 dan1998-11-03 12:53:26 +00001939 if (flag) {
84576113 dan2003-07-16 20:58:49 +00001940 wwin->flags.selected = 1;
1941 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1942
6830b057 dan2004-10-12 21:28:27 +00001943 if (!HAS_BORDER(wwin)) {
84576113 dan2003-07-16 20:58:49 +00001944 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1945 FRAME_BORDER_WIDTH);
1946 }
1947
1948 if (!scr->selected_windows)
1949 scr->selected_windows = WMCreateArray(4);
1950 WMAddToArray(scr->selected_windows, wwin);
59eb9475 dan1998-11-03 12:53:26 +00001951 } else {
84576113 dan2003-07-16 20:58:49 +00001952 wwin->flags.selected = 0;
1953 XSetWindowBorder(dpy, wwin->frame->core->window,
1954 scr->frame_border_pixel);
f2de1c9d kojima2000-01-14 16:30:56 +00001955
6830b057 dan2004-10-12 21:28:27 +00001956 if (!HAS_BORDER(wwin)) {
84576113 dan2003-07-16 20:58:49 +00001957 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1958 }
f2de1c9d kojima2000-01-14 16:30:56 +00001959
84576113 dan2003-07-16 20:58:49 +00001960 if (scr->selected_windows) {
1961 WMRemoveFromArray(scr->selected_windows, wwin);
1962 }
59eb9475 dan1998-11-03 12:53:26 +00001963 }
1964}
1965
1966
1967void
1968wMakeWindowVisible(WWindow *wwin)
1969{
afcbe063 kojima1999-04-17 19:44:58 +00001970 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
84576113 dan2003-07-16 20:58:49 +00001971 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
59eb9475 dan1998-11-03 12:53:26 +00001972
1973 if (wwin->flags.shaded) {
fe4cd695 dan2003-02-24 04:06:20 +00001974 wUnshadeWindow(wwin);
59eb9475 dan1998-11-03 12:53:26 +00001975 }
1976 if (wwin->flags.hidden) {
84576113 dan2003-07-16 20:58:49 +00001977 WApplication *app;
e7495baf dan1999-02-17 11:06:40 +00001978
84576113 dan2003-07-16 20:58:49 +00001979 app = wApplicationOf(wwin->main_window);
b3816743 dan2003-02-11 00:32:17 +00001980 if (app) {
1981 /* trick to get focus to this window */
1982 app->last_focused = wwin;
1983 wUnhideApplication(app, False, False);
1984 }
fe4cd695 dan2003-02-24 04:06:20 +00001985 }
1986 if (wwin->flags.miniaturized) {
84576113 dan2003-07-16 20:58:49 +00001987 wDeiconifyWindow(wwin);
59eb9475 dan1998-11-03 12:53:26 +00001988 } else {
84576113 dan2003-07-16 20:58:49 +00001989 if (!WFLAGP(wwin, no_focusable))
1990 wSetFocusTo(wwin->screen_ptr, wwin);
1991 wRaiseFrame(wwin->frame->core);
59eb9475 dan1998-11-03 12:53:26 +00001992 }
1993}