From 86360e3dbaa774b4f4fcd787007b198c4df3b60e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 10 Sep 2014 22:15:03 +0000 Subject: split and simplify code --- aux.c | 21 +++++++++++++++++++++ aux.h | 3 +++ widget.c | 35 ++++------------------------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/aux.c b/aux.c index 736e903..1f9ed0e 100644 --- a/aux.c +++ b/aux.c @@ -94,3 +94,24 @@ restrictsize(Display *d, Window win, int minw, int minh, int maxw, int maxh) XSetWMSizeHints(d, win, hints, nhints); XFree(hints); } + +void +blit(Display *d, Drawable p, GC gc, XRectangle r) +{ + XCopyArea(d, p, p, gc, 0, 0, r.width, r.height - 1, 0, 1); +} + +void +clear(Display *d, Drawable p, GC gc, XRectangle r) +{ + XSetForeground(d, gc, BlackPixel(d, DefaultScreen(d))); + XFillRectangle(d, p, gc, 0, 0, r.width, r.height); +} + +void +copy(Display *d, Drawable from, Drawable to, GC gc, XRectangle r, Drawable mask) +{ + XSetClipMask(d, gc, mask); + XCopyArea(d, from, to, gc, 0, 0, r.width, r.height, 0, 0); + XSetClipMask(d, gc, None); +} diff --git a/aux.h b/aux.h index c9f8075..11b1f65 100644 --- a/aux.h +++ b/aux.h @@ -23,6 +23,9 @@ void fullscreen(Display *, Window); void hide_ptr(Display *, Window); void move(Display *, Window, Window); void restrictsize(Display *, Window, int, int, int, int); +void blit(Display *, Drawable, GC, XRectangle); +void clear(Display *, Drawable, GC, XRectangle); +void copy(Display *, Drawable, Drawable, GC, XRectangle, Drawable); __END_DECLS #endif diff --git a/widget.c b/widget.c index 3c26589..f38e9d5 100644 --- a/widget.c +++ b/widget.c @@ -20,8 +20,9 @@ #include #include -#include "widget.h" +#include "aux.h" #include "cms.h" +#include "widget.h" struct background { Pixmap pix; @@ -54,27 +55,6 @@ struct palette p_spectr = {{ 120.0, 100.0, 75.0 }, { 0.0, 100.0, 25.0 }}; struct palette p_shadow = {{ 120.0, 100.0, 10.0 }, { 0.0, 100.0, 10.0 }}; struct palette p_waterfall = {{ 210.0, 75.0, 0.0 }, { 180.0, 100.0, 100.0 }}; -static void -blit(Display *d, Drawable p, GC gc, XRectangle r) -{ - XCopyArea(d, p, p, gc, 0, 0, r.width, r.height - 1, 0, 1); -} - -static void -clear(Display *d, Drawable p, GC gc, XRectangle r) -{ - XSetForeground(d, gc, BlackPixel(d, DefaultScreen(d))); - XFillRectangle(d, p, gc, 0, 0, r.width, r.height); -} - -static void -copy(Display *d, Drawable from, Drawable to, GC gc, XRectangle r, Drawable mask) -{ - XSetClipMask(d, gc, mask); - XCopyArea(d, from, to, gc, 0, 0, r.width, r.height, 0, 0); - XSetClipMask(d, gc, None); -} - void draw_panel(struct panel *p) { @@ -117,20 +97,13 @@ draw_panel(struct panel *p) p->bg->mask); } -static void -flip(Display *d, struct subwin *p) -{ - XCopyArea(d, p->pix, p->win, p->gc, - 0, 0, p->geo.width, p->geo.height, 0, 0); -} - void flip_panel(struct panel *p) { /* flip spectrogram */ - flip(p->dsp, p->sp); + copy(p->dsp, p->sp->pix, p->sp->win, p->sp->gc, p->sp->geo, None); /* flip waterfall */ - flip(p->dsp, p->wf); + copy(p->dsp, p->wf->pix, p->wf->win, p->wf->gc, p->wf->geo, None); } static void -- cgit v1.2.3