diff options
author | Okan Demirmen <okan@cvs.openbsd.org> | 2016-09-30 15:12:20 +0000 |
---|---|---|
committer | Okan Demirmen <okan@cvs.openbsd.org> | 2016-09-30 15:12:20 +0000 |
commit | 9ec53fcd54ffc4870669648c13cba7e127240f8b (patch) | |
tree | 418a2ffb82ba971f5c5595c31f96589cb76203e8 /app/cwm | |
parent | 9389959916593c9ae2afc78e5d7a7239ee5b8da3 (diff) |
Replace mousefunc_sweep_draw() with a generic menu_windraw() using va
lists; use it appropriately for both window dimension and position in
the respective mousefunc calls.
ok bryent@
Diffstat (limited to 'app/cwm')
-rw-r--r-- | app/cwm/calmwm.h | 4 | ||||
-rw-r--r-- | app/cwm/menu.c | 34 | ||||
-rw-r--r-- | app/cwm/mousefunc.c | 34 |
3 files changed, 43 insertions, 29 deletions
diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index 3ad75e4ba..6b8accaf5 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/calmwm.h @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: calmwm.h,v 1.316 2016/09/29 00:21:55 okan Exp $ + * $OpenBSD: calmwm.h,v 1.317 2016/09/30 15:12:19 okan Exp $ */ #ifndef _CALMWM_H_ @@ -511,6 +511,8 @@ void mousefunc_client_move(struct client_ctx *, void mousefunc_client_resize(struct client_ctx *, union arg *); +void menu_windraw(struct screen_ctx *, Window, + const char *, ...); struct menu *menu_filter(struct screen_ctx *, struct menu_q *, const char *, const char *, int, void (*)(struct menu_q *, struct menu_q *, char *), diff --git a/app/cwm/menu.c b/app/cwm/menu.c index 94eb399fa..57d32d0da 100644 --- a/app/cwm/menu.c +++ b/app/cwm/menu.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: menu.c,v 1.94 2016/09/29 00:21:55 okan Exp $ + * $OpenBSD: menu.c,v 1.95 2016/09/30 15:12:19 okan Exp $ */ #include <sys/types.h> @@ -638,3 +638,35 @@ menuq_clear(struct menu_q *mq) free(mi); } } + +void +menu_windraw(struct screen_ctx *sc, Window win, const char *fmt, ...) +{ + va_list ap; + int i; + char *text; + XGlyphInfo extents; + + va_start(ap, fmt); + i = vasprintf(&text, fmt, ap); + va_end(ap); + + if (i < 0 || text == NULL) + err(1, "vasprintf"); + + XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text, + strlen(text), &extents); + + XReparentWindow(X_Dpy, sc->menu.win, win, 0, 0); + XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, + extents.xOff, sc->xftfont->height); + XMapWindow(X_Dpy, sc->menu.win); + XClearWindow(X_Dpy, sc->menu.win); + + XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], + sc->xftfont, 0, sc->xftfont->ascent + 1, + (const FcChar8*)text, strlen(text)); + + free(text); +} + diff --git a/app/cwm/mousefunc.c b/app/cwm/mousefunc.c index d1491af6f..0428bf2d2 100644 --- a/app/cwm/mousefunc.c +++ b/app/cwm/mousefunc.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: mousefunc.c,v 1.109 2016/09/30 15:05:02 okan Exp $ + * $OpenBSD: mousefunc.c,v 1.110 2016/09/30 15:12:19 okan Exp $ */ #include <sys/types.h> @@ -32,31 +32,6 @@ #include "calmwm.h" -static void mousefunc_sweep_draw(struct client_ctx *); - -static void -mousefunc_sweep_draw(struct client_ctx *cc) -{ - struct screen_ctx *sc = cc->sc; - char s[14]; /* fits " nnnn x nnnn \0" */ - XGlyphInfo extents; - - (void)snprintf(s, sizeof(s), " %4d x %-4d ", cc->dim.w, cc->dim.h); - - XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)s, - strlen(s), &extents); - - XReparentWindow(X_Dpy, sc->menu.win, cc->win, 0, 0); - XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, - extents.xOff, sc->xftfont->height); - XMapWindow(X_Dpy, sc->menu.win); - XClearWindow(X_Dpy, sc->menu.win); - - XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], - sc->xftfont, 0, sc->xftfont->ascent + 1, - (const FcChar8*)s, strlen(s)); -} - void mousefunc_client_resize(struct client_ctx *cc, union arg *arg) { @@ -89,7 +64,8 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) cc->geom.h = ev.xmotion.y; client_applysizehints(cc); client_resize(cc, 1); - mousefunc_sweep_draw(cc); + menu_windraw(sc, cc->win, + "%4d x %-4d", cc->dim.w, cc->dim.h); break; case ButtonRelease: client_resize(cc, 1); @@ -151,9 +127,13 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) cc->geom.y + cc->geom.h + (cc->bwidth * 2), area.y, area.y + area.h, sc->snapdist); client_move(cc); + menu_windraw(sc, cc->win, + "%4d, %-4d", cc->geom.x, cc->geom.y); break; case ButtonRelease: client_move(cc); + XUnmapWindow(X_Dpy, sc->menu.win); + XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0); xu_ptr_ungrab(); return; } |