aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokan2016-09-28 17:06:33 +0000
committerokan2016-09-28 17:06:33 +0000
commit5f5374eb8ec00ff4d793c6a037f20dd2a1a91cd8 (patch)
treea3261d97c4414a79393f28fe3dd9ccc42d39263b
parenta9e8c34755d6c0e05cb0a204f06480cfbd353994 (diff)
downloadcwm-5f5374eb8ec00ff4d793c6a037f20dd2a1a91cd8.tar.gz
Inline Xft draw and extents wrappers; too much abstraction.
-rw-r--r--calmwm.h5
-rw-r--r--menu.c34
-rw-r--r--mousefunc.c12
-rw-r--r--xutil.c20
4 files changed, 35 insertions, 36 deletions
diff --git a/calmwm.h b/calmwm.h
index ac32e96..31961fd 100644
--- a/calmwm.h
+++ b/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.314 2016/09/22 14:36:03 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.315 2016/09/28 17:06:33 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -549,9 +549,6 @@ int xu_ptr_grab(Window, unsigned int, Cursor);
int xu_ptr_regrab(unsigned int, Cursor);
void xu_ptr_setpos(Window, int, int);
void xu_ptr_ungrab(void);
-void xu_xft_draw(struct screen_ctx *, const char *,
- int, int, int);
-int xu_xft_width(XftFont *, const char *, int);
void xu_xorcolor(XftColor, XftColor, XftColor *);
void xu_ewmh_net_supported(struct screen_ctx *);
diff --git a/menu.c b/menu.c
index 42a6077..a9de925 100644
--- a/menu.c
+++ b/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.92 2016/09/20 19:58:54 okan Exp $
+ * $OpenBSD: menu.c,v 1.93 2016/09/28 17:06:33 okan Exp $
*/
#include <sys/types.h>
@@ -334,6 +334,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
struct menu *mi;
struct geom area;
int n, xsave, ysave;
+ XGlyphInfo extents;
if (mc->list) {
if (TAILQ_EMPTY(resultq)) {
@@ -352,8 +353,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
if (mc->hasprompt) {
(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR);
- mc->geom.w = xu_xft_width(sc->xftfont, mc->dispstr,
- strlen(mc->dispstr));
+
+ XftTextExtentsUtf8(X_Dpy, sc->xftfont,
+ (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
+
+ mc->geom.w = extents.xOff;
mc->geom.h = sc->xftfont->height + 1;
mc->num = 1;
}
@@ -365,8 +369,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
(void)snprintf(mi->print, sizeof(mi->print),
"%s", mi->text);
- mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont,
- mi->print, MIN(strlen(mi->print), MENU_MAXENTRY)));
+ XftTextExtentsUtf8(X_Dpy, sc->xftfont,
+ (const FcChar8*)mi->print,
+ MIN(strlen(mi->print), MENU_MAXENTRY), &extents);
+
+ mc->geom.w = MAX(mc->geom.w, extents.xOff);
mc->geom.h += sc->xftfont->height + 1;
mc->num++;
}
@@ -400,8 +407,10 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
mc->geom.w, mc->geom.h);
if (mc->hasprompt) {
- xu_xft_draw(sc, mc->dispstr, CWM_COLOR_MENU_FONT,
- 0, sc->xftfont->ascent);
+ XftDrawStringUtf8(sc->xftdraw,
+ &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
+ 0, sc->xftfont->ascent,
+ (const FcChar8*)mc->dispstr, strlen(mc->dispstr));
n = 1;
} else
n = 0;
@@ -413,7 +422,10 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
if (mc->geom.y + y > area.h)
break;
- xu_xft_draw(sc, mi->print, CWM_COLOR_MENU_FONT, 0, y);
+ XftDrawStringUtf8(sc->xftdraw,
+ &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
+ 0, y,
+ (const FcChar8*)mi->print, strlen(mi->print));
n++;
}
if (mc->hasprompt && n > 1)
@@ -442,8 +454,10 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
(sc->xftfont->height + 1) * entry, mc->geom.w,
(sc->xftfont->height + 1) + sc->xftfont->descent);
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
- xu_xft_draw(sc, mi->print, color,
- 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1);
+ XftDrawStringUtf8(sc->xftdraw,
+ &sc->xftcolor[color], sc->xftfont,
+ 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1,
+ (const FcChar8*)mi->print, strlen(mi->print));
}
static void
diff --git a/mousefunc.c b/mousefunc.c
index 047b825..c351e72 100644
--- a/mousefunc.c
+++ b/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.106 2016/09/28 15:54:54 okan Exp $
+ * $OpenBSD: mousefunc.c,v 1.107 2016/09/28 17:06:33 okan Exp $
*/
#include <sys/types.h>
@@ -39,16 +39,22 @@ 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->menuwin, cc->win, 0, 0);
XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0,
- xu_xft_width(sc->xftfont, s, strlen(s)), sc->xftfont->height);
+ extents.xOff, sc->xftfont->height);
XMapWindow(X_Dpy, sc->menuwin);
XClearWindow(X_Dpy, sc->menuwin);
- xu_xft_draw(sc, s, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1);
+ XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT],
+ sc->xftfont, 0, sc->xftfont->ascent + 1,
+ (const FcChar8*)s, strlen(s));
}
void
diff --git a/xutil.c b/xutil.c
index 1a0c5d5..3e7e99e 100644
--- a/xutil.c
+++ b/xutil.c
@@ -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: xutil.c,v 1.104 2016/09/16 14:32:02 okan Exp $
+ * $OpenBSD: xutil.c,v 1.105 2016/09/28 17:06:33 okan Exp $
*/
#include <sys/types.h>
@@ -531,21 +531,3 @@ xu_xorcolor(XftColor a, XftColor b, XftColor *r)
r->color.blue = a.color.blue ^ b.color.blue;
r->color.alpha = 0xffff;
}
-
-int
-xu_xft_width(XftFont *xftfont, const char *text, int len)
-{
- XGlyphInfo extents;
-
- XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text,
- len, &extents);
-
- return(extents.xOff);
-}
-
-void
-xu_xft_draw(struct screen_ctx *sc, const char *text, int color, int x, int y)
-{
- XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont,
- x, y, (const FcChar8*)text, strlen(text));
-}