mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
move the 2 small font helper functions to xutil.c
This commit is contained in:
parent
e41c84c752
commit
5b4c55616a
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ PROG= cwm
|
|||||||
|
|
||||||
SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \
|
SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \
|
||||||
search.c util.c xutil.c conf.c xevents.c group.c \
|
search.c util.c xutil.c conf.c xevents.c group.c \
|
||||||
kbfunc.c mousefunc.c font.c parse.y
|
kbfunc.c mousefunc.c parse.y
|
||||||
|
|
||||||
CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR}
|
CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR}
|
||||||
|
|
||||||
|
7
calmwm.h
7
calmwm.h
@ -444,10 +444,6 @@ void conf_mousebind(struct conf *, char *, char *);
|
|||||||
void conf_screen(struct screen_ctx *);
|
void conf_screen(struct screen_ctx *);
|
||||||
void conf_ungrab(struct conf *, struct keybinding *);
|
void conf_ungrab(struct conf *, struct keybinding *);
|
||||||
|
|
||||||
void font_draw(struct screen_ctx *, const char *,
|
|
||||||
Drawable, int, int, int);
|
|
||||||
int font_width(XftFont *, const char *, int);
|
|
||||||
|
|
||||||
void xev_loop(void);
|
void xev_loop(void);
|
||||||
|
|
||||||
void xu_btn_grab(Window, int, u_int);
|
void xu_btn_grab(Window, int, u_int);
|
||||||
@ -466,6 +462,9 @@ void xu_ptr_setpos(Window, int, int);
|
|||||||
void xu_ptr_ungrab(void);
|
void xu_ptr_ungrab(void);
|
||||||
void xu_sendmsg(Window, Atom, long);
|
void xu_sendmsg(Window, Atom, long);
|
||||||
void xu_set_wm_state(Window win, int);
|
void xu_set_wm_state(Window win, int);
|
||||||
|
void xu_xft_draw(struct screen_ctx *, const char *,
|
||||||
|
Drawable, 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 *);
|
||||||
|
51
font.c
51
font.c
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* calmwm - the calm window manager
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005 Marius Eriksen <marius@monkey.org>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* $OpenBSD$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/queue.h>
|
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "calmwm.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
font_width(XftFont *xftfont, const char *text, int len)
|
|
||||||
{
|
|
||||||
XGlyphInfo extents;
|
|
||||||
|
|
||||||
XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text,
|
|
||||||
len, &extents);
|
|
||||||
|
|
||||||
return (extents.xOff);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
font_draw(struct screen_ctx *sc, const char *text,
|
|
||||||
Drawable d, int color, int x, int y)
|
|
||||||
{
|
|
||||||
XftDrawChange(sc->xftdraw, d);
|
|
||||||
XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y,
|
|
||||||
(const FcChar8*)text, strlen(text));
|
|
||||||
}
|
|
10
menu.c
10
menu.c
@ -367,7 +367,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
|||||||
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->width = font_width(sc->xftfont, mc->dispstr,
|
mc->width = xu_xft_width(sc->xftfont, mc->dispstr,
|
||||||
strlen(mc->dispstr));
|
strlen(mc->dispstr));
|
||||||
mc->height = sc->xftfont->height + 1;
|
mc->height = sc->xftfont->height + 1;
|
||||||
mc->num = 1;
|
mc->num = 1;
|
||||||
@ -384,7 +384,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
|||||||
text = mi->text;
|
text = mi->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
mc->width = MAX(mc->width, font_width(sc->xftfont, text,
|
mc->width = MAX(mc->width, xu_xft_width(sc->xftfont, text,
|
||||||
MIN(strlen(text), MENU_MAXENTRY)));
|
MIN(strlen(text), MENU_MAXENTRY)));
|
||||||
mc->height += sc->xftfont->height + 1;
|
mc->height += sc->xftfont->height + 1;
|
||||||
mc->num++;
|
mc->num++;
|
||||||
@ -419,7 +419,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
|||||||
mc->width, mc->height);
|
mc->width, mc->height);
|
||||||
|
|
||||||
if (mc->hasprompt) {
|
if (mc->hasprompt) {
|
||||||
font_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT,
|
xu_xft_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT,
|
||||||
0, sc->xftfont->ascent);
|
0, sc->xftfont->ascent);
|
||||||
n = 1;
|
n = 1;
|
||||||
} else
|
} else
|
||||||
@ -434,7 +434,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
|
|||||||
if (mc->y + y > xine.h)
|
if (mc->y + y > xine.h)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
font_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y);
|
xu_xft_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) {
|
if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) {
|
||||||
@ -466,7 +466,7 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc,
|
|||||||
(sc->xftfont->height + 1) * entry, mc->width,
|
(sc->xftfont->height + 1) * entry, mc->width,
|
||||||
(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;
|
||||||
font_draw(sc, text, sc->menuwin, color,
|
xu_xft_draw(sc, text, sc->menuwin, color,
|
||||||
0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1);
|
0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +58,12 @@ mousefunc_sweep_draw(struct client_ctx *cc)
|
|||||||
|
|
||||||
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,
|
||||||
font_width(sc->xftfont, asize, strlen(asize)), sc->xftfont->height);
|
xu_xft_width(sc->xftfont, asize, strlen(asize)),
|
||||||
|
sc->xftfont->height);
|
||||||
XMapWindow(X_Dpy, sc->menuwin);
|
XMapWindow(X_Dpy, sc->menuwin);
|
||||||
XClearWindow(X_Dpy, sc->menuwin);
|
XClearWindow(X_Dpy, sc->menuwin);
|
||||||
|
|
||||||
font_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT,
|
xu_xft_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT,
|
||||||
0, sc->xftfont->ascent + 1);
|
0, sc->xftfont->ascent + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
xutil.c
20
xutil.c
@ -429,3 +429,23 @@ 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,
|
||||||
|
Drawable d, int color, int x, int y)
|
||||||
|
{
|
||||||
|
XftDrawChange(sc->xftdraw, d);
|
||||||
|
XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont,
|
||||||
|
x, y, (const FcChar8*)text, strlen(text));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user