Skip to content

Commit da13a00

Browse files
committed
xwrits: Adapt to new Gif_XNextImage interface.
Requires some data structure refactoring; appears to work.
1 parent 86b4f2b commit da13a00

File tree

4 files changed

+64
-87
lines changed

4 files changed

+64
-87
lines changed

clock.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ static void
4747
draw_1_clock(Hand *hand, int seconds)
4848
{
4949
Port *port = hand->port;
50-
Picture *p;
50+
PictureList *pl;
5151
int x, y;
5252
int hour, min;
5353

5454
if (!hand->slideshow)
5555
return;
5656

57-
p = (Picture *)(hand->slideshow->images[hand->slide]->user_data);
58-
x = p->clock_x_off;
59-
y = p->clock_y_off;
57+
pl = (PictureList *)(hand->slideshow->images[hand->slide]->user_data);
58+
x = pl->clock_x_off;
59+
y = pl->clock_y_off;
6060

6161
XFillArc(port->display, hand->w, port->white_gc,
6262
x, y, ClockWidth, ClockHeight, 0, 23040);
@@ -122,18 +122,19 @@ void
122122
erase_clock(Hand *hand)
123123
{
124124
Port *port = hand->port;
125-
Picture *p;
125+
PictureList *pl;
126126

127127
if (!hand->slideshow)
128128
return;
129129

130-
p = (Picture *)(hand->slideshow->images[hand->slide]->user_data);
130+
pl = (PictureList *)(hand->slideshow->images[hand->slide]->user_data);
131131

132-
XCopyArea(port->display, p->pix[port->port_number], hand->w,
132+
XCopyArea(port->display, pl->frames[port->port_number][hand->slide].pixmap,
133+
hand->w,
133134
port->clock_fore_gc,
134-
p->clock_x_off - 2, p->clock_y_off - 2,
135+
pl->clock_x_off - 2, pl->clock_y_off - 2,
135136
ClockWidth + 4, ClockHeight + 4,
136-
p->clock_x_off - 2, p->clock_y_off - 2);
137+
pl->clock_x_off - 2, pl->clock_y_off - 2);
137138
hand->clock = 0;
138139
}
139140

hands.c

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ new_hand(Port *slave_port, int x, int y)
288288
nh_icon->port = port;
289289
nh_icon->icon = nh;
290290
nh_icon->root_child = nh->w;
291+
nh_icon->width = nh_icon->height = 0;
291292
nh_icon->is_icon = 1;
292293
nh_icon->mapped = 0;
293294
nh_icon->withdrawn = 0;
@@ -461,59 +462,27 @@ window_to_hand(Port *port, Window w, int allow_icons)
461462

462463
/* draw a picture on a hand */
463464

464-
static void
465-
ensure_picture(Port *port, Gif_Stream *gfs, int n)
466-
{
467-
Gif_Image *gfi = gfs->images[n];
468-
Picture *p, *last_p, *last_last_p;
469-
int i;
470-
int picn = port->port_number;
471-
472-
for (i = 0; i < n; i++) {
473-
p = (Picture *)gfs->images[i]->user_data;
474-
if (!p->pix[picn]) /* no picture cached for earlier image */
475-
ensure_picture(port, gfs, i);
476-
}
477-
478-
p = (Picture *)gfi->user_data;
479-
last_p = (n > 0 ? (Picture *)gfs->images[n-1]->user_data : 0);
480-
last_last_p = (n > 1 ? (Picture *)gfs->images[n-2]->user_data : 0);
481-
482-
/* reuse pixmaps from other streams */
483-
if (p->canonical && gfi->transparent < 0 && gfi->left == 0 && gfi->top == 0
484-
&& gfi->width == gfs->screen_width && gfi->height == gfs->screen_height
485-
&& ((Picture *)p->canonical->user_data)->pix[picn]) {
486-
p->pix[picn] = ((Picture *)p->canonical->user_data)->pix[picn];
487-
return;
488-
} else if (p->canonical)
489-
p->canonical = 0;
490-
491-
p->pix[picn] = Gif_XNextImage
492-
(port->gfx, (last_last_p ? last_last_p->pix[picn] : None),
493-
(last_p ? last_p->pix[picn] : None),
494-
gfs, n);
495-
}
496-
497465
void
498466
draw_slide(Hand *h)
499467
{
500468
Gif_Stream *gfs;
501469
Gif_Image *gfi;
502470
Port *port;
503-
Picture *p;
471+
PictureList *pl;
504472

505473
if (!h || !h->slideshow)
506474
return;
507475

508476
gfs = h->slideshow;
509477
gfi = gfs->images[h->slide];
510-
p = (Picture *)gfi->user_data;
478+
pl = (PictureList *)gfi->user_data;
511479
port = h->port;
512480

513-
if (!p->pix[port->port_number])
514-
ensure_picture(port, gfs, h->slide);
481+
if (!pl->frames[port->port_number][h->slide].pixmap)
482+
(void) Gif_XNextImage(port->gfx, gfs, h->slide,
483+
pl->frames[port->port_number]);
515484

516-
XSetWindowBackgroundPixmap(port->display, h->w, p->pix[port->port_number]);
485+
XSetWindowBackgroundPixmap(port->display, h->w, pl->frames[port->port_number][h->slide].pixmap);
517486
XClearWindow(port->display, h->w);
518487

519488
if (h->clock)

pictures.c

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,43 @@ struct named_record built_in_pictures[] = {
5151

5252

5353
static void
54-
free_picture(void *v)
54+
free_picturelist(void *v)
5555
{
56-
Picture *p = (Picture *)v;
56+
PictureList *pl = (PictureList *)v;
5757
int i;
58-
if (p->canonical)
59-
Gif_DeleteImage(p->canonical);
60-
else
58+
if (--pl->refcount == 0) {
6159
for (i = 0; i < nports; i++)
62-
if (p->pix[i])
63-
XFreePixmap(ports[i]->display, p->pix[i]);
64-
xfree(p);
60+
Gif_DeleteXFrames(ports[i]->gfx, pl->gfs, pl->frames[i]);
61+
xfree(pl);
62+
}
6563
}
6664

67-
static void
68-
add_picture(Gif_Image *gfi, int clock_x_off, int clock_y_off)
65+
static int
66+
add_picturelist(Gif_Stream *gfs, int clock_x_off, int clock_y_off)
6967
{
70-
Picture *p = (Picture *)
71-
xmalloc(sizeof(Picture) + (nports-1)*sizeof(Pixmap));
7268
int i;
73-
p->clock_x_off = clock_x_off;
74-
p->clock_y_off = clock_y_off;
75-
p->canonical = 0;
69+
PictureList *pl = (PictureList *)
70+
xmalloc(sizeof(PictureList) + (nports-1) * sizeof(Gif_XFrame *));
71+
if (!pl)
72+
return -1;
73+
74+
pl->clock_x_off = clock_x_off;
75+
pl->clock_y_off = clock_y_off;
76+
pl->gfs = gfs;
77+
pl->refcount = 0;
7678
for (i = 0; i < nports; i++)
77-
p->pix[i] = None;
78-
79-
gfi->user_data = p;
80-
gfi->free_user_data = free_picture;
79+
if (!(pl->frames[i] = Gif_NewXFrames(gfs)))
80+
return 0;
81+
for (i = 0; i < gfs->nimages; ++i) {
82+
gfs->images[i]->user_data = pl;
83+
gfs->images[i]->free_user_data = free_picturelist;
84+
++pl->refcount;
85+
}
86+
return 0;
8187
}
8288

8389

84-
Gif_Stream *
90+
static Gif_Stream *
8591
get_built_in_image(const char *name)
8692
{
8793
struct named_record *nr;
@@ -107,14 +113,13 @@ get_built_in_image(const char *name)
107113
if (!gfs)
108114
return 0;
109115

110-
xoff = (strncmp(name, "locked", 6) == 0 ? 65 : 10);
111-
for (i = 0; i < gfs->nimages; i++)
112-
add_picture(gfs->images[i], xoff, 10);
113-
114116
/* built-in images are all loop-forever. don't change the GIFs because it
115117
makes the executable bigger */
116118
if (gfs->loopcount < 0) gfs->loopcount = 0;
117119

120+
for (i = 0; i < gfs->nimages; ++i)
121+
gfs->images[i]->user_data = (void *) gfs;
122+
118123
return gfs;
119124
}
120125

@@ -125,8 +130,7 @@ static Gif_Image *
125130
clone_image_skeleton(Gif_Image *gfi)
126131
{
127132
Gif_Image *ngfi = Gif_NewImage();
128-
Picture *p = (Picture *)gfi->user_data;
129-
assert(!gfi->image_data && gfi->compressed && p);
133+
assert(!gfi->image_data && gfi->compressed);
130134
ngfi->local = gfi->local;
131135
if (ngfi->local) ngfi->local->refcount++;
132136
ngfi->transparent = gfi->transparent;
@@ -138,8 +142,6 @@ clone_image_skeleton(Gif_Image *gfi)
138142
ngfi->compressed_len = gfi->compressed_len;
139143
ngfi->free_compressed = 0;
140144
ngfi->delay = gfi->delay;
141-
add_picture(ngfi, p->clock_x_off, p->clock_y_off);
142-
((Picture *)ngfi->user_data)->canonical = gfi;
143145
gfi->refcount++;
144146
return ngfi;
145147
}
@@ -149,7 +151,7 @@ add_stream_to_slideshow(Gif_Stream *add, Gif_Stream *gfs,
149151
double flash_rate_ratio)
150152
{
151153
Gif_Image *gfi;
152-
int i;
154+
int i, duplicate;
153155
double d;
154156

155157
/* adapt delays for 1-frame images */
@@ -178,8 +180,6 @@ add_stream_to_slideshow(Gif_Stream *add, Gif_Stream *gfs,
178180
/* don't use an image directly if it is shared */
179181
if (gfi->user_data)
180182
gfi = clone_image_skeleton(gfi);
181-
else
182-
add_picture(gfi, 10, 10);
183183
/* ensure local colormap */
184184
if (!gfi->local && add->global) {
185185
gfi->local = add->global;
@@ -220,7 +220,7 @@ parse_slideshow(const char *slideshowtext, double flash_rate_ratio, int mono)
220220
char *s;
221221
Gif_Stream *gfs, *add;
222222
Gif_Image *gfi;
223-
int i;
223+
int i, clock_xoff = -1;
224224

225225
if (strlen(slideshowtext) >= BUFSIZ) return 0;
226226
strcpy(buf, slideshowtext);
@@ -256,7 +256,11 @@ parse_slideshow(const char *slideshowtext, double flash_rate_ratio, int mono)
256256
warning("no monochrome version of built-in picture '%s'", name);
257257
name[i-4] = 'm';
258258
}
259-
if (add) { /* add images */
259+
/* set clock X offset */
260+
if (clock_xoff < 0)
261+
clock_xoff = (strncmp(name, "locked", 6) == 0 ? 65 : 10);
262+
/* add images */
263+
if (add) {
260264
add_stream_to_slideshow(add, gfs, flash_rate_ratio);
261265
goto done;
262266
} else if (n[0] == '*')
@@ -297,6 +301,11 @@ parse_slideshow(const char *slideshowtext, double flash_rate_ratio, int mono)
297301
}
298302
}
299303

304+
/* create picture list */
305+
if (gfs->nimages > 0
306+
&& add_picturelist(gfs, (clock_xoff < 0 ? 10 : clock_xoff), 10) < 0)
307+
return 0;
308+
300309
return gfs;
301310
}
302311

xwrits.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
typedef struct Port Port;
1616
typedef struct Options Options;
1717
typedef struct Hand Hand;
18-
typedef struct Picture Picture;
18+
typedef struct PictureList PictureList;
1919
typedef struct Alarm Alarm;
2020

2121
#ifdef __cplusplus
@@ -280,7 +280,6 @@ extern Gif_Stream *ready_slideshow, *ready_icon_slideshow;
280280
extern Gif_Stream *locked_slideshow, *bars_slideshow;
281281
#define DEFAULT_FLASH_DELAY_SEC 2
282282

283-
Gif_Stream *get_built_in_image(const char *);
284283
Gif_Stream *parse_slideshow(const char *, double, int mono);
285284
void set_slideshow(Hand *, Gif_Stream *, const struct timeval *);
286285
void set_all_slideshows(Hand *, Gif_Stream *);
@@ -289,13 +288,12 @@ void set_all_slideshows(Hand *, Gif_Stream *);
289288
/*****************************************************************************/
290289
/* Pictures */
291290

292-
struct Picture {
293-
291+
struct PictureList {
294292
int clock_x_off;
295293
int clock_y_off;
296-
Gif_Image *canonical;
297-
Pixmap pix[1];
298-
294+
Gif_Stream *gfs;
295+
int refcount;
296+
Gif_XFrame *frames[1];
299297
};
300298

301299
void default_pictures(void);

0 commit comments

Comments
 (0)