Use pango, add support for pango markup. This *does* add pango as a
dependency, however i will likely add #ifs for this later. If this is a problem, get this diff and patch -R it on your build.
This commit is contained in:
parent
0d5a47831d
commit
cef970ac27
|
@ -1,6 +1,7 @@
|
|||
-- Dependencies --
|
||||
These are absolutely necessary, speedwm will NOT compile without them
|
||||
- libxft
|
||||
- pango
|
||||
- libXinerama
|
||||
- Can be disabled through editing toggle.mk if you're not interested in multiple monitors.
|
||||
- imlib2
|
||||
|
|
|
@ -58,9 +58,7 @@
|
|||
!@
|
||||
!! Font options
|
||||
!@
|
||||
- speedwm.fonts.font1: NotoSans-Regular:size=8:antialiasing=true
|
||||
- speedwm.fonts.font2: fontawesome:size=8:antialiasing=true
|
||||
- speedwm.fonts.font3: Noto Color Emoji:size=8:antialiasing=true
|
||||
- speedwm.fonts.font: NotoSans Regular 8
|
||||
!@
|
||||
!! Color options
|
||||
!@
|
||||
|
|
309
draw.c
309
draw.c
|
@ -10,6 +10,10 @@
|
|||
/* include xft for drawing text */
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
/* pango */
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
/* include draw header */
|
||||
#include "draw.h"
|
||||
|
||||
|
@ -24,66 +28,11 @@
|
|||
#include <Imlib2.h>
|
||||
#endif
|
||||
|
||||
#define UTF_INVALID 0xFFFD
|
||||
#define UTF_SIZ 4
|
||||
|
||||
static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
|
||||
static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
|
||||
static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
|
||||
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
||||
|
||||
unsigned int ew;
|
||||
|
||||
/* transition scheme for powerlines */
|
||||
Clr transcheme[3];
|
||||
|
||||
/* decode utf byte */
|
||||
static long
|
||||
utf8decodebyte(const char c, size_t *i)
|
||||
{
|
||||
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
|
||||
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
|
||||
return (unsigned char)c & ~utfmask[*i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* validate utf */
|
||||
static size_t
|
||||
utf8validate(long *u, size_t i)
|
||||
{
|
||||
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
|
||||
*u = UTF_INVALID;
|
||||
for (i = 1; *u > utfmax[i]; ++i)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
/* decode utf */
|
||||
static size_t
|
||||
utf8decode(const char *c, long *u, size_t clen)
|
||||
{
|
||||
size_t i, j, len, type;
|
||||
long udecoded;
|
||||
|
||||
*u = UTF_INVALID;
|
||||
if (!clen)
|
||||
return 0;
|
||||
udecoded = utf8decodebyte(c[0], &len);
|
||||
if (!BETWEEN(len, 1, UTF_SIZ))
|
||||
return 1;
|
||||
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
|
||||
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
|
||||
if (type)
|
||||
return j;
|
||||
}
|
||||
if (j < len)
|
||||
return 0;
|
||||
*u = udecoded;
|
||||
utf8validate(u, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* setup */
|
||||
Drw *
|
||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
|
||||
|
@ -180,59 +129,38 @@ drw_free(Drw *drw)
|
|||
#endif
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
XFreeGC(drw->dpy, drw->gc);
|
||||
drw_fontset_free(drw->fonts);
|
||||
drw_font_free(drw->font);
|
||||
free(drw);
|
||||
}
|
||||
|
||||
/* This function is an implementation detail. Library users should use
|
||||
* drw_fontset_create instead.
|
||||
* drw_font_create instead.
|
||||
*/
|
||||
static Fnt *
|
||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
||||
xfont_create(Drw *drw, const char *fontname)
|
||||
{
|
||||
Fnt *font;
|
||||
XftFont *xfont = NULL;
|
||||
FcPattern *pattern = NULL;
|
||||
|
||||
if (fontname) {
|
||||
/* Using the pattern found at font->xfont->pattern does not yield the
|
||||
* same substitution results as using the pattern returned by
|
||||
* FcNameParse; using the latter results in the desired fallback
|
||||
* behaviour whereas the former just results in missing-character
|
||||
* rectangles being drawn, at least with some fonts. */
|
||||
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
|
||||
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
|
||||
return NULL;
|
||||
}
|
||||
if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
|
||||
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
|
||||
XftFontClose(drw->dpy, xfont);
|
||||
return NULL;
|
||||
}
|
||||
} else if (fontpattern) {
|
||||
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
|
||||
fprintf(stderr, "error, cannot load font from pattern.\n");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
die("no font specified.");
|
||||
}
|
||||
|
||||
/* Workaround for the old libXft crash. */
|
||||
#if USEXFTWORKAROUND
|
||||
FcBool iscol;
|
||||
if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
|
||||
XftFontClose(drw->dpy, xfont);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
PangoFontMap *fontmap;
|
||||
PangoContext *context;
|
||||
PangoFontDescription *desc;
|
||||
PangoFontMetrics *metrics;
|
||||
|
||||
font = ecalloc(1, sizeof(Fnt));
|
||||
font->xfont = xfont;
|
||||
font->pattern = pattern;
|
||||
font->h = xfont->ascent + xfont->descent;
|
||||
font->dpy = drw->dpy;
|
||||
|
||||
fontmap = pango_xft_get_font_map(drw->dpy, drw->screen);
|
||||
context = pango_font_map_create_context(fontmap);
|
||||
desc = pango_font_description_from_string(fontname);
|
||||
font->layout = pango_layout_new(context);
|
||||
pango_layout_set_font_description(font->layout, desc);
|
||||
|
||||
metrics = pango_context_get_metrics(context, desc, NULL);
|
||||
font->h = pango_font_metrics_get_height(metrics) / PANGO_SCALE;
|
||||
|
||||
pango_font_metrics_unref(metrics);
|
||||
g_object_unref(context);
|
||||
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
|
@ -241,35 +169,28 @@ xfont_free(Fnt *font)
|
|||
{
|
||||
if (!font)
|
||||
return;
|
||||
if (font->pattern)
|
||||
FcPatternDestroy(font->pattern);
|
||||
XftFontClose(font->dpy, font->xfont);
|
||||
if (font->layout)
|
||||
g_object_unref(font->layout);
|
||||
free(font);
|
||||
}
|
||||
|
||||
Fnt*
|
||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
drw_font_create(Drw* drw, char font[])
|
||||
{
|
||||
Fnt *cur, *ret = NULL;
|
||||
size_t i;
|
||||
Fnt *fnt = NULL;
|
||||
|
||||
if (!drw || !fonts)
|
||||
if (!drw || !font)
|
||||
return NULL;
|
||||
|
||||
for (i = 1; i <= fontcount; i++) {
|
||||
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
|
||||
cur->next = ret;
|
||||
ret = cur;
|
||||
}
|
||||
}
|
||||
return (drw->fonts = ret);
|
||||
fnt = xfont_create(drw, font);
|
||||
|
||||
return (drw->font = fnt);
|
||||
}
|
||||
|
||||
void
|
||||
drw_fontset_free(Fnt *font)
|
||||
drw_font_free(Fnt *font)
|
||||
{
|
||||
if (font) {
|
||||
drw_fontset_free(font->next);
|
||||
xfont_free(font);
|
||||
}
|
||||
}
|
||||
|
@ -309,13 +230,6 @@ drw_scm_create(Drw *drw, char *clrnames[], const unsigned int alphas[], size_t c
|
|||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
drw_setfontset(Drw *drw, Fnt *set)
|
||||
{
|
||||
if (drw)
|
||||
drw->fonts = set;
|
||||
}
|
||||
|
||||
void
|
||||
drw_setscheme(Drw *drw, Clr *scm)
|
||||
{
|
||||
|
@ -420,23 +334,17 @@ drw_polygon(Drw *drw, int x, int y, int ow, int oh, int sw, int sh, const XPoint
|
|||
|
||||
/* function for drawing text */
|
||||
int
|
||||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
|
||||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup)
|
||||
{
|
||||
char buf[1024];
|
||||
int ty;
|
||||
int ty, th;
|
||||
unsigned int ew, eh;
|
||||
XftDraw *d = NULL;
|
||||
Fnt *usedfont, *curfont, *nextfont;
|
||||
size_t i, len;
|
||||
int utf8strlen, utf8charlen, render = x || y || w || h;
|
||||
long utf8codepoint = 0;
|
||||
const char *utf8str;
|
||||
FcCharSet *fccharset;
|
||||
FcPattern *fcpattern;
|
||||
FcPattern *match;
|
||||
XftResult result;
|
||||
int charexists = 0;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
|
||||
int render = x || y || w || h;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->font)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
|
@ -449,102 +357,44 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
w -= lpad;
|
||||
}
|
||||
|
||||
usedfont = drw->fonts;
|
||||
while (1) {
|
||||
utf8strlen = 0;
|
||||
utf8str = text;
|
||||
nextfont = NULL;
|
||||
while (*text) {
|
||||
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
|
||||
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||
if (charexists) {
|
||||
if (curfont == usedfont) {
|
||||
utf8strlen += utf8charlen;
|
||||
text += utf8charlen;
|
||||
} else {
|
||||
nextfont = curfont;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
len = strlen(text);
|
||||
|
||||
if (!charexists || nextfont)
|
||||
break;
|
||||
else
|
||||
charexists = 0;
|
||||
if (len) {
|
||||
drw_font_getexts(drw->font, text, len, &ew, &eh, markup);
|
||||
th = eh;
|
||||
|
||||
/* shorten text if necessary */
|
||||
for (len = MIN(len, sizeof(buf) - 1); len && ew > w; len--) {
|
||||
drw_font_getexts(drw->font, text, len, &ew, &eh, markup);
|
||||
if (eh > th)
|
||||
th = eh;
|
||||
}
|
||||
|
||||
if (utf8strlen) {
|
||||
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
|
||||
/* shorten text if necessary */
|
||||
for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
|
||||
drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
|
||||
if (len) {
|
||||
memcpy(buf, text, len);
|
||||
buf[len] = '\0';
|
||||
if (len < strlen(text))
|
||||
for (i = len; i && i > len - 3; buf[--i] = '.')
|
||||
; /* NOP */
|
||||
|
||||
if (len) {
|
||||
memcpy(buf, utf8str, len);
|
||||
buf[len] = '\0';
|
||||
if (len < utf8strlen)
|
||||
for (i = len; i && i > len - 3; buf[--i] = '.')
|
||||
; /* NOP */
|
||||
if (render) {
|
||||
ty = y + (h - th) / 2;
|
||||
|
||||
if (render) {
|
||||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
usedfont->xfont, x, ty, (XftChar8 *)buf, len);
|
||||
}
|
||||
x += ew;
|
||||
w -= ew;
|
||||
if(markup)
|
||||
pango_layout_set_markup(drw->font->layout, buf, len);
|
||||
else
|
||||
pango_layout_set_text(drw->font->layout, buf, len);
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
drw->font->layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
if(markup) /* clear markup attributes */
|
||||
pango_layout_set_attributes(drw->font->layout, NULL);
|
||||
}
|
||||
}
|
||||
x += ew;
|
||||
w -= ew;
|
||||
|
||||
if (!*text) {
|
||||
break;
|
||||
} else if (nextfont) {
|
||||
charexists = 0;
|
||||
usedfont = nextfont;
|
||||
} else {
|
||||
/* Regardless of whether or not a fallback font is found, the
|
||||
* character must be drawn. */
|
||||
charexists = 1;
|
||||
|
||||
fccharset = FcCharSetCreate();
|
||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
|
||||
if (!drw->fonts->pattern) {
|
||||
/* Refer to the comment in xfont_create for more information. */
|
||||
die("the first font in the cache must be loaded from a font string.");
|
||||
}
|
||||
|
||||
fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
||||
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
||||
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
||||
|
||||
/* add color bool (libxft workaround) */
|
||||
#if USEXFTWORKAROUND
|
||||
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
|
||||
#endif
|
||||
|
||||
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
|
||||
FcDefaultSubstitute(fcpattern);
|
||||
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
|
||||
|
||||
FcCharSetDestroy(fccharset);
|
||||
FcPatternDestroy(fcpattern);
|
||||
|
||||
if (match) {
|
||||
usedfont = xfont_create(drw, NULL, match);
|
||||
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
||||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
||||
; /* NOP */
|
||||
curfont->next = usedfont;
|
||||
} else {
|
||||
xfont_free(usedfont);
|
||||
usedfont = drw->fonts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d)
|
||||
XftDrawDestroy(d);
|
||||
|
||||
|
@ -574,26 +424,31 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
|||
}
|
||||
|
||||
unsigned int
|
||||
drw_fontset_getwidth(Drw *drw, const char *text)
|
||||
drw_font_getwidth(Drw *drw, const char *text, Bool markup)
|
||||
{
|
||||
if (!drw || !drw->fonts || !text)
|
||||
if (!drw || !drw->font || !text)
|
||||
return 0;
|
||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0, markup);
|
||||
}
|
||||
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup)
|
||||
{
|
||||
XGlyphInfo ext;
|
||||
|
||||
if (!font || !text)
|
||||
return;
|
||||
|
||||
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
|
||||
PangoRectangle r;
|
||||
if(markup)
|
||||
pango_layout_set_markup(font->layout, text, len);
|
||||
else
|
||||
pango_layout_set_text(font->layout, text, len);
|
||||
pango_layout_get_extents(font->layout, 0, &r);
|
||||
if(markup) /* clear markup attributes */
|
||||
pango_layout_set_attributes(font->layout, NULL);
|
||||
if (w)
|
||||
*w = ext.xOff;
|
||||
*w = r.width / PANGO_SCALE;
|
||||
if (h)
|
||||
*h = font->h;
|
||||
*h = r.height / PANGO_SCALE;
|
||||
}
|
||||
|
||||
/* create cursor */
|
||||
|
|
17
draw.h
17
draw.h
|
@ -9,9 +9,7 @@ typedef struct {
|
|||
typedef struct Fnt {
|
||||
Display *dpy;
|
||||
unsigned int h;
|
||||
XftFont *xfont;
|
||||
FcPattern *pattern;
|
||||
struct Fnt *next;
|
||||
PangoLayout *layout;
|
||||
} Fnt;
|
||||
|
||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
||||
|
@ -31,7 +29,7 @@ typedef struct {
|
|||
#endif
|
||||
GC gc;
|
||||
Clr *scheme;
|
||||
Fnt *fonts;
|
||||
Fnt *font;
|
||||
} Drw;
|
||||
|
||||
/* Drawable abstraction */
|
||||
|
@ -40,10 +38,10 @@ void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
|||
void drw_free(Drw *drw);
|
||||
|
||||
/* Fnt abstraction */
|
||||
Fnt *drw_fontset_create(Drw* drw, const char *fontarray[], size_t fontcount);
|
||||
void drw_fontset_free(Fnt* set);
|
||||
unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
|
||||
Fnt *drw_font_create(Drw* drw, char font[]);
|
||||
void drw_font_free(Fnt* set);
|
||||
unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup);
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup);
|
||||
|
||||
/* Colorscheme abstraction */
|
||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
|
||||
|
@ -54,7 +52,6 @@ Cur *drw_cur_create(Drw *drw, int shape);
|
|||
void drw_cur_free(Drw *drw, Cur *cursor);
|
||||
|
||||
/* Drawing context manipulation */
|
||||
void drw_setfontset(Drw *drw, Fnt *set);
|
||||
void drw_setscheme(Drw *drw, Clr *scm);
|
||||
void drw_settrans(Drw *drw, Clr *psc, Clr *nsc);
|
||||
|
||||
|
@ -65,7 +62,7 @@ Picture drw_picture_create_resized(Drw *drw, char *src, unsigned int src_w, unsi
|
|||
/* Drawing functions */
|
||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
|
||||
void drw_polygon(Drw *drw, int x, int y, int ow, int oh, int sw, int sh, const XPoint *points, int npoints, int shape, int filled);
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup);
|
||||
void drw_arrow(Drw* drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash);
|
||||
#if USEWINICON
|
||||
void drw_pic(Drw *drw, int x, int y, unsigned int w, unsigned int h, Picture pic);
|
||||
|
|
4
main.h
4
main.h
|
@ -1,7 +1,11 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#endif
|
||||
#ifndef MIN
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#endif
|
||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
||||
|
||||
#if USEIPC
|
||||
|
|
|
@ -132,13 +132,8 @@ static int autofocus = 0; /* Allow clients to automatic
|
|||
static int automove = 0; /* Allow clients to automatically move when they request it */
|
||||
static int autoresize = 0; /* Allow resizing clients automatically when they request it. */
|
||||
|
||||
/* Font options
|
||||
*
|
||||
* Main fonts
|
||||
*/
|
||||
static char font1[] = { "NotoSans-Regular:size=8:antialiasing=true" }; /* First font */
|
||||
static char font2[] = { "fontawesome:size=8:antialiasing=true" }; /* Second font */
|
||||
static char font3[] = { "Noto Color Emoji:size=8:antialiasing=true" }; /* Third font */
|
||||
/* Font options */
|
||||
static char font[] = "NotoSans Regular 8";
|
||||
|
||||
/* Status options */
|
||||
static char status[] = "speedwm_status"; /* Status bar to use, stellar for stellar, dwmblocks for dwmblocks, slstatus for slstatus, etc. */
|
||||
|
|
|
@ -10,8 +10,8 @@ X11INC = /usr/X11R6/include
|
|||
X11LIB = /usr/X11R6/lib
|
||||
|
||||
# includes and libs
|
||||
INCS = -I${X11INC} -I${FREETYPEINC} -I${YAJLINC}
|
||||
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender ${IMLIB2LIBS} -lX11-xcb -lxcb -lxcb-res -lXext ${YAJLLIBS}
|
||||
INCS = -I${X11INC} -I${FREETYPEINC} -I${YAJLINC} `pkg-config --cflags xft pango pangoxft`
|
||||
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender ${IMLIB2LIBS} -lX11-xcb -lxcb -lxcb-res -lXext ${YAJLLIBS} `pkg-config --libs xft pango pangoxft`
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||
|
|
63
speedwm.c
63
speedwm.c
|
@ -34,6 +34,7 @@
|
|||
#include <X11/extensions/Xinerama.h>
|
||||
#endif /* XINERAMA */
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
#if USESWITCHER
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
@ -66,7 +67,8 @@
|
|||
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||
#define TAGSLENGTH (LENGTH(tags))
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
#define TEXTW(X) (drw_font_getwidth(drw, (X), False) + lrpad)
|
||||
#define TEXTWM(X) (drw_font_getwidth(drw, (X), True) + lrpad)
|
||||
#define RIGHTOF(a,b) (a.y_org > b.y_org) || \
|
||||
((a.y_org == b.y_org) && (a.x_org > b.x_org))
|
||||
|
||||
|
@ -881,8 +883,6 @@ static int systraypinningfailfirst = 1;
|
|||
#include "toggle/ipc-yajl.c"
|
||||
#endif
|
||||
|
||||
static char *fontarray[] = { font1, font2, font3 }; /* All fonts */
|
||||
|
||||
unsigned int tagw[LENGTH(tags)];
|
||||
|
||||
struct Pertag {
|
||||
|
@ -1377,7 +1377,6 @@ buttonpress(XEvent *e)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
checkotherwm(void)
|
||||
{
|
||||
|
@ -2061,7 +2060,7 @@ statuslength(char* stext)
|
|||
if (!isCode) {
|
||||
isCode = 1;
|
||||
text[i] = '\0';
|
||||
w += TEXTW(text) - lrpad;
|
||||
w += TEXTWM(text) - lrpad;
|
||||
text[i] = '^';
|
||||
if (text[++i] == 'f')
|
||||
w += atoi(text + ++i);
|
||||
|
@ -2073,7 +2072,7 @@ statuslength(char* stext)
|
|||
}
|
||||
}
|
||||
if (!isCode)
|
||||
w += TEXTW(text) - lrpad;
|
||||
w += TEXTWM(text) - lrpad;
|
||||
free(p);
|
||||
return w;
|
||||
}
|
||||
|
@ -2108,7 +2107,7 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
|
|||
if (!isCode) {
|
||||
isCode = 1;
|
||||
text[i] = '\0';
|
||||
w += TEXTW(text) - lrpad;
|
||||
w += TEXTWM(text) - lrpad;
|
||||
text[i] = '^';
|
||||
if (text[++i] == 'f')
|
||||
w += atoi(text + ++i);
|
||||
|
@ -2120,7 +2119,7 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
|
|||
}
|
||||
}
|
||||
if (!isCode)
|
||||
w += TEXTW(text) - lrpad;
|
||||
w += TEXTWM(text) - lrpad;
|
||||
else
|
||||
isCode = 0;
|
||||
text = p;
|
||||
|
@ -2142,8 +2141,8 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
|
|||
isCode = 1;
|
||||
|
||||
text[i] = '\0';
|
||||
w = TEXTW(text) - lrpad;
|
||||
drw_text(drw, x, 0, w, bh, 0, text, 0);
|
||||
w = TEXTWM(text) - lrpad;
|
||||
drw_text(drw, x, 0, w, bh, 0, text, 0, True);
|
||||
|
||||
x += w;
|
||||
|
||||
|
@ -2188,8 +2187,8 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
|
|||
drw_setscheme(drw, scheme[SchemeStatus]);
|
||||
|
||||
if (!isCode) {
|
||||
w = TEXTW(text) - lrpad;
|
||||
drw_text(drw, x, 0, w, bh, 0, text, 0);
|
||||
w = TEXTWM(text) - lrpad;
|
||||
drw_text(drw, x, 0, w, bh, 0, text, 0, True);
|
||||
w = 0;
|
||||
}
|
||||
|
||||
|
@ -2344,14 +2343,14 @@ drawbaritems(Monitor *m)
|
|||
Clr *prevscheme, *nxtscheme; /* powerline schemes */
|
||||
|
||||
if (!selmon->hidetagpowerline || !selmon->hidetitlepowerline) {
|
||||
plw = drw->fonts->h / 2 + 1;
|
||||
plw = drw->font->h / 2 + 1;
|
||||
plt = plw;
|
||||
} else
|
||||
plw = 0;
|
||||
|
||||
/* indicators */
|
||||
int boxs = drw->fonts->h / 9;
|
||||
int boxw = drw->fonts->h / 6 + 2;
|
||||
int boxs = drw->font->h / 9;
|
||||
int boxw = drw->font->h / 6 + 2;
|
||||
|
||||
/* monocle layout */
|
||||
unsigned int s = 0, a = 0;
|
||||
|
@ -2385,7 +2384,7 @@ resizebarwin(m);
|
|||
if ((unsigned char)(*s) < ' ') {
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
tw = TEXTW(text) - lrpad;
|
||||
tw = TEXTWM(text) - lrpad;
|
||||
x += tw;
|
||||
*s = ch;
|
||||
text = s + 1;
|
||||
|
@ -2413,7 +2412,7 @@ resizebarwin(m);
|
|||
else
|
||||
drw_setscheme(drw, scheme[SchemeStatus]);
|
||||
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0, False);
|
||||
}
|
||||
|
||||
/* draw tags */
|
||||
|
@ -2448,7 +2447,7 @@ resizebarwin(m);
|
|||
}
|
||||
|
||||
/* draw tag text */
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, tagtext, urg & 1 << i);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, tagtext, urg & 1 << i, False);
|
||||
|
||||
/* underline */
|
||||
if (underlineall || m->tagset[m->seltags] & 1 << i)
|
||||
|
@ -2495,7 +2494,7 @@ resizebarwin(m);
|
|||
else
|
||||
drw_setscheme(drw, scheme[SchemeStatus]);
|
||||
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0, False);
|
||||
}
|
||||
|
||||
#if USESYSTRAY
|
||||
|
@ -2587,10 +2586,10 @@ resizebarwin(m);
|
|||
#if USEWINICON
|
||||
if (selmon->hideicon) {
|
||||
#endif
|
||||
drw_text(drw, x + pltitle, 0, tabw, bh, lrpad / 2, c->name, 0);
|
||||
drw_text(drw, x + pltitle, 0, tabw, bh, lrpad / 2, c->name, 0, False);
|
||||
#if USEWINICON
|
||||
} else {
|
||||
drw_text(drw, x + pltitle, 0, tabw, bh, lrpad / 2 + (c->icon ? c->icw + selmon->iconspacing : 0), c->name, 0); /* draw, with icon spacing and width added */
|
||||
drw_text(drw, x + pltitle, 0, tabw, bh, lrpad / 2 + (c->icon ? c->icw + selmon->iconspacing : 0), c->name, 0, True); /* draw, with icon spacing and width added */
|
||||
if (c->icon && !selmon->hidetitlepowerline && selmon->colorselectedtitle)
|
||||
drw_pic(drw, x + pltitle + lrpad / 2, (bh - c->ich) / 2, c->icw, c->ich, c->icon); /* draw icon */
|
||||
else if (c->icon)
|
||||
|
@ -3511,8 +3510,8 @@ setbarheight(const Arg *arg)
|
|||
|
||||
bh += arg->i;
|
||||
|
||||
if (bh < drw->fonts->h)
|
||||
bh = altbar ? 0 : drw->fonts->h;
|
||||
if (bh < drw->font->h)
|
||||
bh = altbar ? 0 : drw->font->h;
|
||||
|
||||
updatebarpos(selmon);
|
||||
resizebarwin(selmon);
|
||||
|
@ -3525,7 +3524,7 @@ resetbarheight(const Arg *arg)
|
|||
if (altbar)
|
||||
return;
|
||||
|
||||
bh = altbar ? 0 : drw->fonts->h + barheight;
|
||||
bh = altbar ? 0 : drw->font->h + barheight;
|
||||
|
||||
updatebarpos(selmon);
|
||||
resizebarwin(selmon);
|
||||
|
@ -4119,7 +4118,7 @@ drawswitcher(int nwins, int first, Monitor *m)
|
|||
|
||||
n++;
|
||||
drw_setscheme(drw, scheme[(c == m->sel) ? SchemeTitleSel : SchemeBar]);
|
||||
drw_text(drw, 0, y, selmon->maxwidth, h, 0, c->name, 0);
|
||||
drw_text(drw, 0, y, selmon->maxwidth, h, 0, c->name, 0, False);
|
||||
y += h;
|
||||
}
|
||||
|
||||
|
@ -5443,10 +5442,10 @@ setup(void)
|
|||
root = RootWindow(dpy, screen);
|
||||
xinitvisual();
|
||||
drw = drw_create(dpy, screen, root, tw, sh, visual, depth, cmap);
|
||||
if (!drw_fontset_create(drw, fontarray, LENGTH(fontarray)))
|
||||
if (!drw_font_create(drw, font))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h;
|
||||
bh = altbar ? 0 : drw->fonts->h + barheight;
|
||||
lrpad = drw->font->h;
|
||||
bh = altbar ? 0 : drw->font->h + barheight;
|
||||
|
||||
/* barpadding */
|
||||
sp = barpaddingh;
|
||||
|
@ -6567,7 +6566,7 @@ updatestatus(void)
|
|||
Monitor* m;
|
||||
if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)) && !selmon->hidestatus) {
|
||||
strcpy(stext, defaultstatus);
|
||||
statusw = TEXTW(stext) - lrpad + 2;
|
||||
statusw = TEXTWM(stext) - lrpad + 2;
|
||||
} else {
|
||||
if (!selmon->hidestatus) {
|
||||
copyvalidchars(stext, rawstext);
|
||||
|
@ -6577,12 +6576,12 @@ updatestatus(void)
|
|||
if ((unsigned char)(*s) < ' ') {
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
statusw += TEXTW(text) - lrpad;
|
||||
statusw += TEXTWM(text) - lrpad;
|
||||
*s = ch;
|
||||
text = s + 1;
|
||||
}
|
||||
}
|
||||
statusw += TEXTW(text) - lrpad + 2;
|
||||
statusw += TEXTWM(text) - lrpad + 2;
|
||||
}
|
||||
}
|
||||
if (statusallmons) {
|
||||
|
@ -7010,7 +7009,7 @@ updatesystray(void)
|
|||
else
|
||||
y += vp;
|
||||
|
||||
unsigned int sw = TEXTW(stext) - lrpad + systrayspacing;
|
||||
unsigned int sw = TEXTWM(stext) - lrpad + systrayspacing;
|
||||
unsigned int w = 1;
|
||||
|
||||
if (selmon->hidesystray)
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
*
|
||||
* Value in .Xresources Type Value internally */
|
||||
ResourcePref resources[] = {
|
||||
{ "fonts.font1", STRING, &font1 },
|
||||
{ "fonts.font2", STRING, &font2 },
|
||||
{ "fonts.font3", STRING, &font3 },
|
||||
{ "fonts.font", STRING, &font },
|
||||
{ "col.background", STRING, &col_background },
|
||||
{ "col.titlenorm", STRING, &col_titlenorm },
|
||||
{ "col.titlesel", STRING, &col_titlesel },
|
||||
|
|
Loading…
Reference in a new issue