2
* Window de/iconification handling
9
#include <X11/extensions/shape.h>
11
#include "add_window.h"
13
#include "functions.h"
20
#include "win_iconify.h"
21
#include "workspace_manager.h"
25
static void MosaicFade(TwmWindow *tmp_win, Window blanket);
26
static void ZoomInWindow(TwmWindow *tmp_win, Window blanket);
27
static void ZoomOutWindow(TwmWindow *tmp_win, Window blanket);
28
static void FadeWindow(TwmWindow *tmp_win, Window blanket);
29
static void SweepWindow(TwmWindow *tmp_win, Window blanket);
31
/* De/iconify utils */
32
static void ReMapOne(TwmWindow *t, TwmWindow *leader);
33
static void waitamoment(float timeout);
38
* The main routines for iconifying...
41
Iconify(TwmWindow *tmp_win, int def_x, int def_y)
47
Window leader = (Window) - 1;
48
Window blanket = (Window) - 1;
50
iconify = (!tmp_win->iconify_by_unmapping);
52
if(tmp_win->istransient) {
53
leader = tmp_win->transientfor;
54
t = GetTwmWindow(leader);
56
else if((leader = tmp_win->group) != 0 && leader != tmp_win->w) {
57
t = GetTwmWindow(leader);
63
if(!tmp_win->icon || !tmp_win->icon->w) {
64
CreateIconWindow(tmp_win, def_x, def_y);
69
if(visible(tmp_win)) {
71
OtpRaise(tmp_win, IconWin);
72
XMapWindow(dpy, tmp_win->icon->w);
75
OtpRaise(tmp_win, IconWin);
76
XMapWindow(dpy, tmp_win->icon->w);
80
if(tmp_win->iconmanagerlist) {
81
for(wl = tmp_win->iconmanagerlist; wl != NULL; wl = wl->nextv) {
82
XMapWindow(dpy, wl->icon);
86
/* Don't mask anything yet, just get the current for various uses */
87
eventMask = mask_out_event(tmp_win->w, 0);
89
/* iconify transients and window group first */
90
UnmapTransients(tmp_win, iconify, eventMask);
93
Zoom(tmp_win->frame, tmp_win->icon->w);
97
* Prevent the receipt of an UnmapNotify, since that would
98
* cause a transition to the Withdrawn state.
100
tmp_win->mapped = false;
102
if((Scr->IconifyStyle != ICONIFY_NORMAL) && !Scr->WindowMask) {
103
XWindowAttributes winattrs;
104
XSetWindowAttributes attr;
106
XGetWindowAttributes(dpy, tmp_win->frame, &winattrs);
107
attr.backing_store = NotUseful;
108
attr.save_under = False;
109
blanket = XCreateWindow(dpy, Scr->Root, winattrs.x, winattrs.y,
110
winattrs.width, winattrs.height, 0,
111
CopyFromParent, CopyFromParent,
112
CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
113
XMapWindow(dpy, blanket);
116
mask_out_event_mask(tmp_win->w, StructureNotifyMask, eventMask);
117
XUnmapWindow(dpy, tmp_win->w);
118
XUnmapWindow(dpy, tmp_win->frame);
119
restore_mask(tmp_win->w, eventMask);
121
SetMapStateProp(tmp_win, IconicState);
123
if((Scr->IconifyStyle != ICONIFY_NORMAL) && !Scr->WindowMask) {
124
switch(Scr->IconifyStyle) {
126
MosaicFade(tmp_win, blanket);
129
ZoomInWindow(tmp_win, blanket);
131
case ICONIFY_ZOOMOUT:
132
ZoomOutWindow(tmp_win, blanket);
135
FadeWindow(tmp_win, blanket);
138
SweepWindow(tmp_win, blanket);
141
/* Placate insufficiently smart clang warning */
144
XDestroyWindow(dpy, blanket);
146
if(tmp_win == Scr->Focus) {
147
SetFocus(NULL, LastTimestamp());
148
if(! Scr->ClickToFocus) {
149
Scr->FocusRoot = true;
152
tmp_win->isicon = true;
153
tmp_win->icon_on = iconify;
154
WMapIconify(tmp_win);
155
if(! Scr->WindowMask && Scr->IconifyFunction.func != 0) {
159
action = Scr->IconifyFunction.item ? Scr->IconifyFunction.item->action : NULL;
160
ExecuteFunction(Scr->IconifyFunction.func, action,
161
(Window) 0, tmp_win, &event, C_ROOT, false);
168
* ... and its complement
171
DeIconify(TwmWindow *tmp_win)
173
TwmWindow *t = tmp_win;
176
/* de-iconify the main window */
177
if(Scr->WindowMask) {
178
XRaiseWindow(dpy, Scr->WindowMask);
180
if(tmp_win->isicon) {
182
if(tmp_win->icon_on && tmp_win->icon && tmp_win->icon->w) {
183
Zoom(tmp_win->icon->w, tmp_win->frame);
185
else if(tmp_win->group != (Window) 0) {
186
t = GetTwmWindow(tmp_win->group);
187
if(t && t->icon_on && t->icon && t->icon->w) {
188
Zoom(t->icon->w, tmp_win->frame);
193
ReMapOne(tmp_win, t);
197
LookInList(Scr->WarpCursorL, tmp_win->full_name, &tmp_win->class))) {
198
WarpToWindow(tmp_win, false);
201
/* now de-iconify any window group transients */
202
ReMapTransients(tmp_win);
204
if(! Scr->WindowMask && Scr->DeIconifyFunction.func != 0) {
208
action = Scr->DeIconifyFunction.item ?
209
Scr->DeIconifyFunction.item->action : NULL;
210
ExecuteFunction(Scr->DeIconifyFunction.func, action,
211
(Window) 0, tmp_win, &event, C_ROOT, false);
219
* Animations for popping windows around.
222
MosaicFade(TwmWindow *tmp_win, Window blanket)
229
XRectangle *rectangles;
230
int width = tmp_win->frame_width;
231
int height = tmp_win->frame_height;
233
srect = (width < height) ? (width / 20) : (height / 20);
234
mask = XCreatePixmap(dpy, blanket, width, height, 1);
237
gc = XCreateGC(dpy, mask, GCForeground, &gcv);
238
XFillRectangle(dpy, mask, gc, 0, 0, width, height);
239
gcv.function = GXclear;
240
XChangeGC(dpy, gc, GCFunction, &gcv);
242
nrects = ((width * height) / (srect * srect)) / 10;
243
rectangles = calloc(nrects, sizeof(XRectangle));
244
for(j = 0; j < nrects; j++) {
245
rectangles [j].width = srect;
246
rectangles [j].height = srect;
248
for(i = 0; i < 10; i++) {
249
for(j = 0; j < nrects; j++) {
250
rectangles [j].x = ((lrand48() % width) / srect) * srect;
251
rectangles [j].y = ((lrand48() % height) / srect) * srect;
253
XFillRectangles(dpy, mask, gc, rectangles, nrects);
254
XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
258
XFreePixmap(dpy, mask);
265
ZoomInWindow(TwmWindow *tmp_win, Window blanket)
272
int w = tmp_win->frame_width;
273
int h = tmp_win->frame_height;
274
int step = (MAX(w, h)) / (2.0 * nsteps);
276
mask = XCreatePixmap(dpy, blanket, w, h, 1);
278
gc = XCreateGC(dpy, mask, GCForeground, &gcv);
279
gcv.function = GXclear;
280
gcn = XCreateGC(dpy, mask, GCForeground | GCFunction, &gcv);
282
for(i = 0; i < nsteps; i++) {
283
XFillRectangle(dpy, mask, gcn, 0, 0, w, h);
284
XFillArc(dpy, mask, gc, (w / 2) - ((nsteps - i) * step),
285
(h / 2) - ((nsteps - i) * step),
286
2 * (nsteps - i) * step,
287
2 * (nsteps - i) * step,
289
XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
297
ZoomOutWindow(TwmWindow *tmp_win, Window blanket)
304
int w = tmp_win->frame_width;
305
int h = tmp_win->frame_height;
306
int step = (MAX(w, h)) / (2.0 * nsteps);
308
mask = XCreatePixmap(dpy, blanket, w, h, 1);
310
gc = XCreateGC(dpy, mask, GCForeground, &gcv);
311
XFillRectangle(dpy, mask, gc, 0, 0, w, h);
312
gcv.function = GXclear;
313
XChangeGC(dpy, gc, GCFunction, &gcv);
315
for(i = 0; i < nsteps; i++) {
316
XFillArc(dpy, mask, gc, (w / 2) - (i * step),
317
(h / 2) - (i * step),
321
XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
329
FadeWindow(TwmWindow *tmp_win, Window blanket)
331
Pixmap mask, stipple;
334
static unsigned char stipple_bits[] = { 0x0F, 0x0F,
343
int w = tmp_win->frame_width;
344
int h = tmp_win->frame_height;
346
stipple = XCreateBitmapFromData(dpy, blanket, (char *)stipple_bits, 8, 8);
347
mask = XCreatePixmap(dpy, blanket, w, h, 1);
350
gcv.stipple = stipple;
351
gcv.fill_style = FillOpaqueStippled;
352
gc = XCreateGC(dpy, mask, GCBackground | GCForeground | GCFillStyle | GCStipple,
354
XFillRectangle(dpy, mask, gc, 0, 0, w, h);
356
XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
359
XFreePixmap(dpy, stipple);
365
SweepWindow(TwmWindow *tmp_win, Window blanket)
369
int dir = 0, dist = tmp_win->frame_x, dist1;
371
dist1 = tmp_win->frame_y;
376
dist1 = tmp_win->vs->w - (tmp_win->frame_x + tmp_win->frame_width);
381
dist1 = tmp_win->vs->h - (tmp_win->frame_y + tmp_win->frame_height);
389
step = tmp_win->frame_x + tmp_win->frame_width;
392
step = tmp_win->frame_y + tmp_win->frame_height;
395
step = tmp_win->vs->w - tmp_win->frame_x;
398
step = tmp_win->vs->h - tmp_win->frame_y;
401
step /= (float) nsteps;
402
step /= (float) nsteps;
403
for(i = 0; i < 20; i++) {
404
int x = tmp_win->frame_x;
405
int y = tmp_win->frame_y;
420
XMoveWindow(dpy, blanket, x, y);
429
* Utils used by various bits above
432
ReMapOne(TwmWindow *t, TwmWindow *leader)
435
Zoom(t->icon->w, t->frame);
437
else if(leader->icon) {
438
Zoom(leader->icon->w, t->frame);
442
XMapWindow(dpy, t->w);
445
if(False && Scr->Root != Scr->CaptiveRoot) { /* XXX dubious test */
446
ReparentWindow(dpy, t, WinWin, Scr->Root, t->frame_x, t->frame_y);
448
if(!Scr->NoRaiseDeicon) {
451
XMapWindow(dpy, t->frame);
452
SetMapStateProp(t, NormalState);
454
if(t->icon && t->icon->w) {
455
XUnmapWindow(dpy, t->icon->w);
457
if(Scr->ShrinkIconTitles) {
458
t->icon->title_shrunk = true;
461
if(t->iconmanagerlist) {
464
for(wl = t->iconmanagerlist; wl != NULL; wl = wl->nextv) {
465
XUnmapWindow(dpy, wl->icon);
475
* Mostly internal util of iconification, but squeezing code needs it
479
ReMapTransients(TwmWindow *tmp_win)
483
/* find t such that it is a transient or group member window */
484
for(t = Scr->FirstWindow; t != NULL; t = t->next) {
486
((t->istransient && t->transientfor == tmp_win->w) ||
487
(t->group == tmp_win->w && t->isicon))) {
488
ReMapOne(t, tmp_win);
495
* Ditto previous note about squeezing.
498
UnmapTransients(TwmWindow *tmp_win, bool iconify, long eventMask)
502
for(t = Scr->FirstWindow; t != NULL; t = t->next) {
504
((t->istransient && t->transientfor == tmp_win->w) ||
505
t->group == tmp_win->w)) {
508
Zoom(t->icon->w, tmp_win->icon->w);
510
else if(tmp_win->icon) {
511
Zoom(t->frame, tmp_win->icon->w);
516
* Prevent the receipt of an UnmapNotify, since that would
517
* cause a transition to the Withdrawn state.
522
* Note that here, we're setting masks relative to what we
523
* were passed, which is that of the window these are
524
* transient for, rather than relative to these windows'
525
* current masks. I believe in practice it's the same thing,
526
* and it saves getting attributes on each for masking.
527
* Still, a little odd...
529
mask_out_event_mask(t->w, StructureNotifyMask, eventMask);
530
XUnmapWindow(dpy, t->w);
531
XUnmapWindow(dpy, t->frame);
532
restore_mask(t->w, eventMask);
534
if(t->icon && t->icon->w) {
535
XUnmapWindow(dpy, t->icon->w);
537
SetMapStateProp(t, IconicState);
538
if(t == Scr->Focus) {
539
SetFocus(NULL, LastTimestamp());
540
if(! Scr->ClickToFocus) {
541
Scr->FocusRoot = true;
544
if(t->iconmanagerlist) {
545
XMapWindow(dpy, t->iconmanagerlist->icon);
556
waitamoment(float timeout)
558
struct timeval timeoutstruct;
559
int usec = timeout * 1000000;
560
timeoutstruct.tv_usec = usec % (unsigned long) 1000000;
561
timeoutstruct.tv_sec = usec / (unsigned long) 1000000;
562
select(0, NULL, NULL, NULL, &timeoutstruct);