add pango markup toggles

This commit is contained in:
speedie 2023-02-28 15:51:32 +01:00
parent 6df3bc9112
commit 3f7bc43bf4
6 changed files with 171 additions and 137 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.out
*.o
spmenu
*zst*

View file

@ -67,3 +67,11 @@ spmenu.generatecache: 0
spmenu.mode: 0
spmenu.normtext: Normal
spmenu.instext: Insert
spmenu.pango_item: 1
spmenu.pango_prompt: 1
spmenu.pango_input: 1
spmenu.pango_leftarrow: 1
spmenu.pango_rightarrow: 1
spmenu.pango_numbers: 1
spmenu.pango_mode: 1
spmenu.pango_password: 1

View file

@ -130,6 +130,15 @@ static char col_sgrcolor13[] = "#ff00ff"; /* SGR color #13 */
static char col_sgrcolor14[] = "#00ffff"; /* SGR color #14 */
static char col_sgrcolor15[] = "#ffffff"; /* SGR color #15 */
static int pango_item = 1; /* Enable support for pango markup for the items */
static int pango_prompt = 1; /* Enable support for pango markup for the prompt */
static int pango_input = 1; /* Enable support for pango markup for user input */
static int pango_leftarrow = 1; /* Enable support for pango markup for the left arrow */
static int pango_rightarrow = 1; /* Enable support for pango markup for the right arrow */
static int pango_numbers = 1; /* Enable support for pango markup for the match count */
static int pango_mode = 1; /* Enable support for pango markup for the mode indicator */
static int pango_password = 1; /* Enable support for pango markup for the password text */
/* Alpha options */
#define fgalpha opaque /* Foreground alpha */
#define bgalpha 200 /* Background alpha */

View file

@ -5,5 +5,5 @@
VERSION = 0.2
# includes and libs
INCS = -I$(X11INC) -I$(FREETYPEINC) `pkg-config --cflags xft pango pangoxft`
LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) $(XRENDERLIBS) $(IMLIB2LIBS) -lm `pkg-config --libs xft pango pangoxft`
INCS = -I$(X11INC) -I$(FREETYPEINC) $(BDINC) `pkg-config --cflags xft pango pangoxft`
LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) $(XRENDERLIBS) $(IMLIB2LIBS) $(BDLIBS) -lm `pkg-config --libs xft pango pangoxft`

View file

@ -9,22 +9,30 @@
#include <time.h>
#include <unistd.h>
#ifdef FRIBIDI
#define USERTL 1
#else
/* check if we should enable right to left language support */
#ifdef NORTL
#define USERTL 0
#else
#define USERTL 1
#endif
#if USERTL
#include <fribidi.h>
#endif
/* check if we should enable image support */
#ifdef NOIMAGE
#define USEIMAGE 0
#else
#define USEIMAGE 1
#endif
#ifdef XINERAMA
#define USEXINERAMA 1
#else
#define USEXINERAMA 0
#endif
#if USERTL
#include <fribidi.h>
#endif
#if USEIMAGE
#include <errno.h>
#include <pwd.h>
@ -32,7 +40,7 @@
#include <openssl/md5.h>
#endif
#ifdef XINERAMA
#if USEXINERAMA
#include <X11/extensions/Xinerama.h>
#endif
@ -345,9 +353,9 @@ drawitem(struct item *item, int x, int y, int w)
rw = TEXTWM(buffer) - lrpad;
#if USERTL
apply_fribidi(buffer);
drw_text(drw, x, y, rw + lp, bh, lp, fribidi_text, 0, True);
drw_text(drw, x, y, rw + lp, bh, lp, fribidi_text, 0, pango_item ? True : False);
#else
drw_text(drw, x, y, rw + lp, bh, lp, buffer, 0, True);
drw_text(drw, x, y, rw + lp, bh, lp, buffer, 0, pango_item ? True : False);
#endif
x += rw + lp;
@ -395,9 +403,9 @@ drawitem(struct item *item, int x, int y, int w)
/* draw any text that doesn't use sgr sequences */
#if USERTL
apply_fribidi(buffer);
int r = drw_text(drw, x, y, w - rw, bh, lp, fribidi_text, 0, True);
int r = drw_text(drw, x, y, w - rw, bh, lp, fribidi_text, 0, pango_item ? True : False);
#else
int r = drw_text(drw, x, y, w - rw, bh, lp, buffer, 0, True);
int r = drw_text(drw, x, y, w - rw, bh, lp, buffer, 0, pango_item ? True : False);
#endif
if (!hidehighlight && !ib) drawhighlights(item, x, y, w - rw);
@ -429,7 +437,7 @@ drawmenu(void)
drw_setscheme(drw, scheme[SchemePrompt]);
}
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0, True);
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0, pango_prompt ? True : False);
}
/* draw input field */
w = (lines > 0 || !matches) ? mw - x : inputw;
@ -439,17 +447,17 @@ drawmenu(void)
memset(censort, '.', strlen(text));
#if USERTL
apply_fribidi(censort);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, True);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, pango_password ? True : False);
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0, True);
drw_text(drw, x, 0, w - LENGTH(censort), bh, lrpad / 2, censort, 0, pango_password ? True : False);
#endif
free(censort);
} else {
#if USERTL
apply_fribidi(text);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, True);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, pango_input ? True : False);
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0, True);
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0, pango_input ? True : False);
#endif
}
@ -482,7 +490,7 @@ drawmenu(void)
w = TEXTW(leftarrow);
if (curr->left) {
drw_setscheme(drw, scheme[SchemeLArrow]);
drw_text(drw, x, 0, w, bh, lrpad / 2, leftarrow, 0, True);
drw_text(drw, x, 0, w, bh, lrpad / 2, leftarrow, 0, pango_leftarrow ? True : False);
}
x += w;
for (item = curr; item != next; item = item->right)
@ -496,21 +504,21 @@ drawmenu(void)
drw_setscheme(drw, scheme[SchemeRArrow]);
if (hidematchcount) {
drw_text(drw, mw - w - TEXTW(modetext), 0, w, bh, lrpad / 2, rightarrow, 0, True);
drw_text(drw, mw - w - TEXTW(modetext), 0, w, bh, lrpad / 2, rightarrow, 0, pango_rightarrow ? True : False);
} else {
drw_text(drw, mw - w - TEXTW(numbers) - TEXTW(modetext), 0, w, bh, lrpad / 2, rightarrow, 0, True);
drw_text(drw, mw - w - TEXTW(numbers) - TEXTW(modetext), 0, w, bh, lrpad / 2, rightarrow, 0, pango_rightarrow ? True : False);
}
}
}
if (!hidematchcount) {
drw_setscheme(drw, scheme[SchemeNumber]);
drw_text(drw, mw - TEXTW(numbers) - TEXTW(modetext), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0, False);
drw_text(drw, mw - TEXTW(numbers) - TEXTW(modetext), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0, pango_numbers ? True : False);
}
if (!hidemode) {
drw_setscheme(drw, scheme[SchemeMode]);
drw_text(drw, mw - TEXTW(modetext), 0, TEXTW(modetext), bh, lrpad / 2, modetext, 0, False);
drw_text(drw, mw - TEXTW(modetext), 0, TEXTW(modetext), bh, lrpad / 2, modetext, 0, pango_mode ? True : False);
}
drw_map(drw, win, 0, 0, mw, mh);
@ -1533,7 +1541,7 @@ setup(void)
Window w, dw, *dws;
XWindowAttributes wa;
XClassHint ch = { class, class };
#ifdef XINERAMA
#if USEXINERAMA
XineramaScreenInfo *info;
Window pw;
int a, di, n, area = 0;
@ -1620,7 +1628,7 @@ setup(void)
}
}
}
#ifdef XINERAMA
#if USEXINERAMA
i = 0;
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
XGetInputFocus(dpy, &w, &di);

View file

@ -120,4 +120,12 @@ ResourcePref resources[] = {
{ "imageposition", INTEGER, &imageposition },
{ "generatecache", INTEGER, &generatecache },
{ "mode", INTEGER, &mode },
{ "pango_item", INTEGER, &pango_item },
{ "pango_prompt", INTEGER, &pango_prompt },
{ "pango_input", INTEGER, &pango_input },
{ "pango_leftarrow", INTEGER, &pango_leftarrow },
{ "pango_rightarrow", INTEGER, &pango_rightarrow },
{ "pango_numbers", INTEGER, &pango_numbers },
{ "pango_mode", INTEGER, &pango_mode },
{ "pango_password", INTEGER, &pango_password },
};