1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/*
* MATE panel x stuff
*
* Copyright (C) 2000, 2001 Eazel, Inc.
* 2002 Sun Microsystems Inc.
*
* Authors: George Lebl <jirka@5z.com>
* Mark McLoughlin <mark@skynet.ie>
*
* Contains code from the Window Maker window manager
*
* Copyright (c) 1997-2002 Alfredo K. Kojima
*/
#include <config.h>
#include <unistd.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include "xstuff.h"
/* Zoom animation */
#define MINIATURIZE_ANIMATION_FRAMES_Z 1
#define MINIATURIZE_ANIMATION_STEPS_Z 6
/* the delay per draw */
#define MINIATURIZE_ANIMATION_DELAY_Z 10
static void
draw_zoom_animation (GdkScreen *gscreen,
int x, int y, int w, int h,
int fx, int fy, int fw, int fh,
int steps)
{
#define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
int cxi[FRAMES], cyi[FRAMES], cwi[FRAMES], chi[FRAMES];
float xstep, ystep, wstep, hstep;
int i, j;
GC frame_gc;
XGCValues gcv;
GdkColor color = { 65535, 65535, 65535 };
Display *dpy;
Window root_win;
int screen;
int depth;
dpy = gdk_x11_display_get_xdisplay (gdk_screen_get_display (gscreen));
root_win = GDK_WINDOW_XID (gdk_screen_get_root_window (gscreen));
screen = gdk_x11_screen_get_screen_number (gscreen);
depth = DefaultDepth(dpy,screen);
/* frame GC */
gcv.function = GXxor;
/* this will raise the probability of the XORed color being different
* of the original color in PseudoColor when not all color cells are
* initialized */
if (DefaultVisual(dpy, screen)->class==PseudoColor)
gcv.plane_mask = (1<<(depth-1))|1;
else
gcv.plane_mask = AllPlanes;
gcv.foreground = color.pixel;
if (gcv.foreground == 0)
gcv.foreground = 1;
gcv.line_width = 1;
gcv.subwindow_mode = IncludeInferiors;
gcv.graphics_exposures = False;
frame_gc = XCreateGC(dpy, root_win, GCForeground|GCGraphicsExposures
|GCFunction|GCSubwindowMode|GCLineWidth
|GCPlaneMask, &gcv);
xstep = (float)(fx-x)/steps;
ystep = (float)(fy-y)/steps;
wstep = (float)(fw-w)/steps;
hstep = (float)(fh-h)/steps;
for (j=0; j<FRAMES; j++) {
cx[j] = (float)x;
cy[j] = (float)y;
cw[j] = (float)w;
ch[j] = (float)h;
cxi[j] = (int)cx[j];
cyi[j] = (int)cy[j];
cwi[j] = (int)cw[j];
chi[j] = (int)ch[j];
}
XGrabServer(dpy);
for (i=0; i<steps; i++) {
for (j=0; j<FRAMES; j++) {
XDrawRectangle(dpy, root_win, frame_gc, cxi[j], cyi[j], cwi[j], chi[j]);
}
XFlush(dpy);
#if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
usleep(MINIATURIZE_ANIMATION_DELAY_Z);
#else
usleep(10);
#endif
for (j=0; j<FRAMES; j++) {
XDrawRectangle(dpy, root_win, frame_gc,
cxi[j], cyi[j], cwi[j], chi[j]);
if (j<FRAMES-1) {
cx[j]=cx[j+1];
cy[j]=cy[j+1];
cw[j]=cw[j+1];
ch[j]=ch[j+1];
cxi[j]=cxi[j+1];
cyi[j]=cyi[j+1];
cwi[j]=cwi[j+1];
chi[j]=chi[j+1];
} else {
cx[j]+=xstep;
cy[j]+=ystep;
cw[j]+=wstep;
ch[j]+=hstep;
cxi[j] = (int)cx[j];
cyi[j] = (int)cy[j];
cwi[j] = (int)cw[j];
chi[j] = (int)ch[j];
}
}
}
for (j=0; j<FRAMES; j++) {
XDrawRectangle(dpy, root_win, frame_gc,
cxi[j], cyi[j], cwi[j], chi[j]);
}
XFlush(dpy);
#if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
usleep(MINIATURIZE_ANIMATION_DELAY_Z);
#else
usleep(10);
#endif
for (j=0; j<FRAMES; j++) {
XDrawRectangle(dpy, root_win, frame_gc,
cxi[j], cyi[j], cwi[j], chi[j]);
}
XUngrabServer(dpy);
XFreeGC (dpy, frame_gc);
}
#undef FRAMES
void
xstuff_zoom_animate (GtkWidget *widget, GdkRectangle *opt_rect)
{
GdkScreen *gscreen;
GdkRectangle rect, dest;
GtkAllocation allocation;
GdkMonitor *monitor;
if (opt_rect)
rect = *opt_rect;
else {
gdk_window_get_origin (gtk_widget_get_window (widget), &rect.x, &rect.y);
gtk_widget_get_allocation (widget, &allocation);
if (!gtk_widget_get_has_window (widget)) {
rect.x += allocation.x;
rect.y += allocation.y;
}
rect.height = allocation.height;
rect.width = allocation.width;
}
gscreen = gtk_widget_get_screen (widget);
monitor = gdk_display_get_monitor_at_window (gdk_screen_get_display (gscreen),
gtk_widget_get_window (widget));
gdk_monitor_get_geometry (monitor, &dest);
draw_zoom_animation (gscreen,
rect.x, rect.y, rect.width, rect.height,
dest.x, dest.y, dest.width, dest.height,
MINIATURIZE_ANIMATION_STEPS_Z);
}
|