Inline Xft draw and extents wrappers; too much abstraction.
This commit is contained in:
parent
7c35826ca9
commit
b46a5b0b56
@ -15,7 +15,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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_
|
#ifndef _CALMWM_H_
|
||||||
@ -549,9 +549,6 @@ int xu_ptr_grab(Window, unsigned int, Cursor);
|
|||||||
int xu_ptr_regrab(unsigned int, Cursor);
|
int xu_ptr_regrab(unsigned int, Cursor);
|
||||||
void xu_ptr_setpos(Window, int, int);
|
void xu_ptr_setpos(Window, int, int);
|
||||||
void xu_ptr_ungrab(void);
|
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_xorcolor(XftColor, XftColor, XftColor *);
|
||||||
|
|
||||||
void xu_ewmh_net_supported(struct screen_ctx *);
|
void xu_ewmh_net_supported(struct screen_ctx *);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#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 menu *mi;
|
||||||
struct geom area;
|
struct geom area;
|
||||||
int n, xsave, ysave;
|
int n, xsave, ysave;
|
||||||
|
XGlyphInfo extents;
|
||||||
|
|
||||||
if (mc->list) {
|
if (mc->list) {
|
||||||
if (TAILQ_EMPTY(resultq)) {
|
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) {
|
if (mc->hasprompt) {
|
||||||
(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
|
(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
|
||||||
mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR);
|
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->geom.h = sc->xftfont->height + 1;
|
||||||
mc->num = 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),
|
(void)snprintf(mi->print, sizeof(mi->print),
|
||||||
"%s", mi->text);
|
"%s", mi->text);
|
||||||
|
|
||||||
mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont,
|
XftTextExtentsUtf8(X_Dpy, sc->xftfont,
|
||||||
mi->print, MIN(strlen(mi->print), MENU_MAXENTRY)));
|
(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->geom.h += sc->xftfont->height + 1;
|
||||||
mc->num++;
|
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);
|
mc->geom.w, mc->geom.h);
|
||||||
|
|
||||||
if (mc->hasprompt) {
|
if (mc->hasprompt) {
|
||||||
xu_xft_draw(sc, mc->dispstr, CWM_COLOR_MENU_FONT,
|
XftDrawStringUtf8(sc->xftdraw,
|
||||||
0, sc->xftfont->ascent);
|
&sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
|
||||||
|
0, sc->xftfont->ascent,
|
||||||
|
(const FcChar8*)mc->dispstr, strlen(mc->dispstr));
|
||||||
n = 1;
|
n = 1;
|
||||||
} else
|
} else
|
||||||
n = 0;
|
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)
|
if (mc->geom.y + y > area.h)
|
||||||
break;
|
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++;
|
n++;
|
||||||
}
|
}
|
||||||
if (mc->hasprompt && n > 1)
|
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) * entry, mc->geom.w,
|
||||||
(sc->xftfont->height + 1) + sc->xftfont->descent);
|
(sc->xftfont->height + 1) + sc->xftfont->descent);
|
||||||
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
|
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
|
||||||
xu_xft_draw(sc, mi->print, color,
|
XftDrawStringUtf8(sc->xftdraw,
|
||||||
0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1);
|
&sc->xftcolor[color], sc->xftfont,
|
||||||
|
0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1,
|
||||||
|
(const FcChar8*)mi->print, strlen(mi->print));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#include <sys/types.h>
|
||||||
@ -39,16 +39,22 @@ mousefunc_sweep_draw(struct client_ctx *cc)
|
|||||||
{
|
{
|
||||||
struct screen_ctx *sc = cc->sc;
|
struct screen_ctx *sc = cc->sc;
|
||||||
char s[14]; /* fits " nnnn x nnnn \0" */
|
char s[14]; /* fits " nnnn x nnnn \0" */
|
||||||
|
XGlyphInfo extents;
|
||||||
|
|
||||||
(void)snprintf(s, sizeof(s), " %4d x %-4d ", cc->dim.w, cc->dim.h);
|
(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);
|
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
|
||||||
XMoveResizeWindow(X_Dpy, sc->menuwin, 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);
|
XMapWindow(X_Dpy, sc->menuwin);
|
||||||
XClearWindow(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
|
void
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#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.blue = a.color.blue ^ b.color.blue;
|
||||||
r->color.alpha = 0xffff;
|
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));
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user