Skip to content

Commit 86360e3

Browse files
committed
split and simplify code
1 parent a12f243 commit 86360e3

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

aux.c

+21
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,24 @@ restrictsize(Display *d, Window win, int minw, int minh, int maxw, int maxh)
9494
XSetWMSizeHints(d, win, hints, nhints);
9595
XFree(hints);
9696
}
97+
98+
void
99+
blit(Display *d, Drawable p, GC gc, XRectangle r)
100+
{
101+
XCopyArea(d, p, p, gc, 0, 0, r.width, r.height - 1, 0, 1);
102+
}
103+
104+
void
105+
clear(Display *d, Drawable p, GC gc, XRectangle r)
106+
{
107+
XSetForeground(d, gc, BlackPixel(d, DefaultScreen(d)));
108+
XFillRectangle(d, p, gc, 0, 0, r.width, r.height);
109+
}
110+
111+
void
112+
copy(Display *d, Drawable from, Drawable to, GC gc, XRectangle r, Drawable mask)
113+
{
114+
XSetClipMask(d, gc, mask);
115+
XCopyArea(d, from, to, gc, 0, 0, r.width, r.height, 0, 0);
116+
XSetClipMask(d, gc, None);
117+
}

aux.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ void fullscreen(Display *, Window);
2323
void hide_ptr(Display *, Window);
2424
void move(Display *, Window, Window);
2525
void restrictsize(Display *, Window, int, int, int, int);
26+
void blit(Display *, Drawable, GC, XRectangle);
27+
void clear(Display *, Drawable, GC, XRectangle);
28+
void copy(Display *, Drawable, Drawable, GC, XRectangle, Drawable);
2629
__END_DECLS
2730

2831
#endif

widget.c

+4-31
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#include <assert.h>
2121
#include <stdlib.h>
2222

23-
#include "widget.h"
23+
#include "aux.h"
2424
#include "cms.h"
25+
#include "widget.h"
2526

2627
struct background {
2728
Pixmap pix;
@@ -54,27 +55,6 @@ struct palette p_spectr = {{ 120.0, 100.0, 75.0 }, { 0.0, 100.0, 25.0 }};
5455
struct palette p_shadow = {{ 120.0, 100.0, 10.0 }, { 0.0, 100.0, 10.0 }};
5556
struct palette p_waterfall = {{ 210.0, 75.0, 0.0 }, { 180.0, 100.0, 100.0 }};
5657

57-
static void
58-
blit(Display *d, Drawable p, GC gc, XRectangle r)
59-
{
60-
XCopyArea(d, p, p, gc, 0, 0, r.width, r.height - 1, 0, 1);
61-
}
62-
63-
static void
64-
clear(Display *d, Drawable p, GC gc, XRectangle r)
65-
{
66-
XSetForeground(d, gc, BlackPixel(d, DefaultScreen(d)));
67-
XFillRectangle(d, p, gc, 0, 0, r.width, r.height);
68-
}
69-
70-
static void
71-
copy(Display *d, Drawable from, Drawable to, GC gc, XRectangle r, Drawable mask)
72-
{
73-
XSetClipMask(d, gc, mask);
74-
XCopyArea(d, from, to, gc, 0, 0, r.width, r.height, 0, 0);
75-
XSetClipMask(d, gc, None);
76-
}
77-
7858
void
7959
draw_panel(struct panel *p)
8060
{
@@ -117,20 +97,13 @@ draw_panel(struct panel *p)
11797
p->bg->mask);
11898
}
11999

120-
static void
121-
flip(Display *d, struct subwin *p)
122-
{
123-
XCopyArea(d, p->pix, p->win, p->gc,
124-
0, 0, p->geo.width, p->geo.height, 0, 0);
125-
}
126-
127100
void
128101
flip_panel(struct panel *p)
129102
{
130103
/* flip spectrogram */
131-
flip(p->dsp, p->sp);
104+
copy(p->dsp, p->sp->pix, p->sp->win, p->sp->gc, p->sp->geo, None);
132105
/* flip waterfall */
133-
flip(p->dsp, p->wf);
106+
copy(p->dsp, p->wf->pix, p->wf->win, p->wf->gc, p->wf->geo, None);
134107
}
135108

136109
static void

0 commit comments

Comments
 (0)