CTWM
Loading...
Searching...
No Matches
/usr/src/RPM/BUILD/ctwm-4.1.0/animate.c
Go to the documentation of this file.
1/*
2 * Animation routines
3 */
4
5
6#include "ctwm.h"
7
8#include <sys/time.h>
9#include <assert.h>
10#include <stdio.h>
11#include <string.h>
12
13#include <X11/extensions/shape.h>
14
15#include "ctwm_atoms.h"
16#include "events.h"
17#include "icons.h"
18#include "image.h"
19#include "screen.h"
20#include "util.h"
21#include "vscreen.h"
22#include "win_utils.h"
23
24#include "animate.h"
25
26
27#define MAXANIMATIONSPEED 20
28
29
30int Animating = 0;
32bool AnimationActive = false;
33bool MaybeAnimate = true;
35
36
37static void Animate(void);
38static void AnimateButton(TBWindow *tbw);
39static void AnimateHighlight(TwmWindow *t);
40static void AnimateIcons(ScreenInfo *scr, Icon *icon);
41static bool AnimateRoot(void);
42
43
44/*
45 * XXX We're directly looking at this for hopefully hysterical raisins.
46 * Rexamine the whole tracefile subsystem at some point when we look at
47 * debugging.
48 *
49 * Currently get it via pollution from events.h anyway.
50 *
51 * extern FILE *tracefile;
52 */
53
54void
56{
57 struct timeval tp;
58 static unsigned long lastsec;
59 static long lastusec;
60 unsigned long gap;
61
62 if(Animating > 1) {
63 return; /* rate limiting */
64 }
65
67 gap = ((tp.tv_sec - lastsec) * 1000000) + (tp.tv_usec - lastusec);
68 if(tracefile) {
69 fprintf(tracefile, "Time = %lu, %ld, %ld, %ld, %lu\n", lastsec,
70 lastusec, (long)tp.tv_sec, (long)tp.tv_usec, gap);
72 }
74 if(gap < 1000000) {
75 return;
76 }
77 if(tracefile) {
78 fprintf(tracefile, "Animate\n");
80 }
81 Animate();
82 lastsec = tp.tv_sec;
83 lastusec = tp.tv_usec;
84}
85
86
87
88void
90{
91
94 }
95 if(AnimationSpeed <= 0) {
97 }
98 if(AnimationActive) {
99 return;
100 }
101 switch(AnimationSpeed) {
102 case 0 :
103 return;
104 case 1 :
105 AnimateTimeout.tv_sec = 1;
106 AnimateTimeout.tv_usec = 0;
107 break;
108 default :
109 AnimateTimeout.tv_sec = 0;
110 AnimateTimeout.tv_usec = 1000000 / AnimationSpeed;
111 }
112 AnimationActive = true;
113}
114
115
116void
118{
119 AnimationActive = false;
120}
121
122
123void
131
132
133void
135{
136 if((AnimationSpeed + incr) < 0) {
137 return;
138 }
139 if((AnimationSpeed + incr) == 0) {
140 if(AnimationActive) {
142 }
143 AnimationSpeed = 0;
144 return;
145 }
149 }
150
151 if(AnimationSpeed == 1) {
152 AnimateTimeout.tv_sec = 1;
153 AnimateTimeout.tv_usec = 0;
154 }
155 else {
156 AnimateTimeout.tv_sec = 0;
157 AnimateTimeout.tv_usec = 1000000 / AnimationSpeed;
158 }
159 AnimationActive = true;
160}
161
162
163
164/*
165 * Only called from TryToAnimate
166 */
167static void
169{
170 TwmWindow *t;
171 int scrnum;
172 ScreenInfo *scr;
173 int i;
174 TBWindow *tbw;
175 int nb;
176
177 if(AnimationSpeed == 0) {
178 return;
179 }
180 if(Animating > 1) {
181 return; /* rate limiting */
182 }
183
184 /* Impossible? */
185 if(NumScreens < 1) {
186 return;
187 }
188
189 MaybeAnimate = false;
190 scr = NULL;
191 for(scrnum = 0; scrnum < NumScreens; scrnum++) {
192 if((scr = ScreenList [scrnum]) == NULL) {
193 continue;
194 }
195
196 for(t = scr->FirstWindow; t != NULL; t = t->next) {
197 if(! visible(t)) {
198 continue;
199 }
200 if(t->icon_on && t->icon && t->icon->bm_w && t->icon->image &&
201 t->icon->image->next) {
202 AnimateIcons(scr, t->icon);
203 MaybeAnimate = true;
204 }
205 else if(t->mapped && t->titlebuttons) {
206 nb = scr->TBInfo.nleft + scr->TBInfo.nright;
207 for(i = 0, tbw = t->titlebuttons; i < nb; i++, tbw++) {
208 if(tbw->image && tbw->image->next) {
210 MaybeAnimate = true;
211 }
212 }
213 }
214 }
215 if(scr->Focus) {
216 t = scr->Focus;
217 if(t->mapped && t->titlehighlight && t->title_height &&
218 t->HiliteImage && t->HiliteImage->next) {
220 MaybeAnimate = true;
221 }
222 }
223 }
225 if(MaybeAnimate) {
226 // Impossible: scr==NULL means we had no valid screens, which
227 // means we'd'a bomed out WAY earlier than trying to animate
228 // something...
229 assert(scr != NULL);
230 Animating++;
232 EventTime);
233 }
234 XFlush(dpy);
235 return;
236}
237
238
239/* Originally in add_window.c */
240static void
242{
243 Image *image;
245
246 image = tbw->image;
247 attr.background_pixmap = image->pixmap;
249 XClearWindow(dpy, tbw->window);
250 tbw->image = image->next;
251}
252
253/* Originally in add_window.c */
254static void
256{
257 Image *image;
259
260 image = t->HiliteImage;
261 attr.background_pixmap = image->pixmap;
262 if(t->hilite_wl) {
263 XChangeWindowAttributes(dpy, t->hilite_wl, CWBackPixmap, &attr);
264 XClearWindow(dpy, t->hilite_wl);
265 }
266 if(t->hilite_wr) {
267 XChangeWindowAttributes(dpy, t->hilite_wr, CWBackPixmap, &attr);
268 XClearWindow(dpy, t->hilite_wr);
269 }
270 t->HiliteImage = image->next;
271}
272
273
274/* Originally in icons.c */
275static void
277{
278 Image *image;
281 int x;
282
283 image = icon->image;
284 attr.background_pixmap = image->pixmap;
286
287 if(image->mask != None) {
288 x = GetIconOffset(icon);
289 XShapeCombineMask(dpy, icon->bm_w, ShapeBounding, 0, 0, image->mask, ShapeSet);
290 if(icon->has_title) {
291 rect.x = 0;
292 rect.y = icon->height;
293 rect.width = icon->w_width;
294 rect.height = scr->IconFont.height + 6;
295
299 ShapeUnion, 0);
302 }
303 else
304 XShapeCombineShape(dpy, icon->w, ShapeBounding, x, 0, icon->bm_w,
306 }
307 XClearWindow(dpy, icon->bm_w);
308 icon->image = image->next;
309 return;
310}
311
312
313/* Original in workmgr.c */
314static bool
316{
317 VirtualScreen *vs;
318 ScreenInfo *scr;
319 int scrnum;
320 Image *image;
321 WorkSpace *ws;
322 bool maybeanimate;
323
324 maybeanimate = false;
325 for(scrnum = 0; scrnum < NumScreens; scrnum++) {
326 if((scr = ScreenList [scrnum]) == NULL) {
327 continue;
328 }
329 if(! scr->workSpaceManagerActive) {
330 continue;
331 }
332
333 for(vs = scr->vScreenList; vs != NULL; vs = vs->next) {
334 if(! vs->wsw->currentwspc) {
335 continue;
336 }
337 image = vs->wsw->currentwspc->image;
338 if((image == NULL) || (image->next == NULL)) {
339 continue;
340 }
341 if(scr->DontPaintRootWindow) {
342 continue;
343 }
344
346 XClearWindow(dpy, scr->Root);
347 vs->wsw->currentwspc->image = image->next;
348 maybeanimate = true;
349 }
350 }
351 for(scrnum = 0; scrnum < NumScreens; scrnum++) {
352 if((scr = ScreenList [scrnum]) == NULL) {
353 continue;
354 }
355
356 for(vs = scr->vScreenList; vs != NULL; vs = vs->next) {
357 if(vs->wsw->state == WMS_buttons) {
358 continue;
359 }
360 for(ws = scr->workSpaceMgr.workSpaceList; ws != NULL; ws = ws->next) {
361 image = ws->image;
362
363 if((image == NULL) || (image->next == NULL)) {
364 continue;
365 }
366 if(ws == vs->wsw->currentwspc) {
367 continue;
368 }
369 XSetWindowBackgroundPixmap(dpy, vs->wsw->mswl [ws->number]->w, image->pixmap);
370 XClearWindow(dpy, vs->wsw->mswl [ws->number]->w);
371 ws->image = image->next;
372 maybeanimate = true;
373 }
374 }
375 }
376 return maybeanimate;
377}
static int PlaceX
Definition add_window.c:82
static void Animate(void)
Definition animate.c:168
static bool AnimateRoot(void)
Definition animate.c:315
static void AnimateButton(TBWindow *tbw)
Definition animate.c:241
int AnimationSpeed
Definition animate.c:31
int Animating
Definition animate.c:30
#define MAXANIMATIONSPEED
Definition animate.c:27
void StartAnimation(void)
Definition animate.c:89
void StopAnimation(void)
Definition animate.c:117
bool MaybeAnimate
Definition animate.c:33
void TryToAnimate(void)
Definition animate.c:55
static void AnimateHighlight(TwmWindow *t)
Definition animate.c:255
static void AnimateIcons(ScreenInfo *scr, Icon *icon)
Definition animate.c:276
void SetAnimationSpeed(int speed)
Definition animate.c:124
bool AnimationActive
Definition animate.c:32
void ModifyAnimationSpeed(int incr)
Definition animate.c:134
struct timeval AnimateTimeout
Definition animate.c:34
Display * dpy
Definition ctwm_main.c:84
int NumScreens
How many Screens are on our display.
Definition ctwm_main.c:89
ScreenInfo ** ScreenList
List of ScreenInfo structs for each Screen.
Definition ctwm_main.c:92
Time EventTime
Definition event_core.c:79
MyFont IconFont
IconFont config var.
Definition screen.h:720
Window ShapeWindow
Utility window for animated icons.
Definition screen.h:253
Window Root
Root window for the current vscreen.
Definition screen.h:194
VirtualScreen * vScreenList
Linked list of per-VS info.
Definition screen.h:513
VirtualScreen * currentvs
Currently active VS.
Definition screen.h:514
int GetIconOffset(Icon *icon)
Definition icons.c:1128
int x
Definition menus.c:69
Definition icons.h:26
bool has_title
Definition icons.h:44
int w_width
Definition icons.h:36
int height
Definition icons.h:39
Image * image
Definition icons.h:31
Window w
Definition icons.h:28
Window bm_w
Definition icons.h:30
Definition image.h:9
Pixmap mask
Definition image.h:11
Pixmap pixmap
Definition image.h:10
Image * next
Definition image.h:14
int height
Definition ctwm.h:132
int nleft
numbers of buttons on left side
Definition screen.h:345
int nright
numbers of buttons on right side
Definition screen.h:346
Info and control for each X Screen we control.
Definition screen.h:96
TwmWindow * Focus
The twm window that has focus.
Definition screen.h:769
bool DontPaintRootWindow
DontPaintRootWindow config var.
Definition screen.h:843
WorkSpaceMgr workSpaceMgr
Info about the WorkSpaceManager (and Occupy window) for the screen.
Definition screen.h:508
bool workSpaceManagerActive
Whether the WSM is being shown.
Definition screen.h:509
struct ScreenInfo::_TBInfo TBInfo
Various titlebar buttons that will be put in the window decorations for the screen....
TwmWindow * FirstWindow
The head of the screen's twm window list.
Definition screen.h:151
Info and control for every X Window we take over.
struct VirtualScreen * next
Definition vscreen.h:12
struct WorkSpaceWindow * wsw
Definition vscreen.h:11
Window window
Definition vscreen.h:9
struct WorkSpace * workSpaceList
WorkSpace * currentwspc
MapSubwindow ** mswl
FILE * tracefile
Definition util.c:59
void send_clientmessage(Window w, Atom a, Time timestamp)
Definition win_utils.c:996
bool visible(const TwmWindow *tmp_win)
Definition win_utils.c:341
@ WMS_buttons