Adding the -f option

This commit is contained in:
phillbush 2020-07-31 11:01:53 -03:00
parent 7539247be3
commit 644a15bb2d
2 changed files with 19 additions and 6 deletions

View File

@ -3,7 +3,7 @@
xmenu \- menu utility for X xmenu \- menu utility for X
.SH SYNOPSIS .SH SYNOPSIS
.B xmenu .B xmenu
.RB [ \-iw ] .RB [ \-fiw ]
.RB [ -p .RB [ -p
.IR position ] .IR position ]
.RI [ title ] .RI [ title ]
@ -16,6 +16,13 @@ and outputs the item selected to stdout.
.PP .PP
The options are as follows: The options are as follows:
.TP .TP
.B -f
Make glyphs align based solely on the first font specified.
Without this option, glyphs are aligned based on the font in which they are found.
This option may correct alignment of CJK glyphs
if a CJK font is specified after a Latin font,
but may break the alignment of other glyphs in some cases.
.TP
.B -i .B -i
Disable icons. Disable icons.
This makes xmenu loading faster when not using icons. This makes xmenu loading faster when not using icons.

14
xmenu.c
View File

@ -95,6 +95,7 @@ static Atom wmdelete;
static Atom netatom[NetLast]; static Atom netatom[NetLast];
/* flags */ /* flags */
static int fflag = 0; /* whether glyphs should align based on the first font */
static int iflag = 0; /* whether to disable icons */ static int iflag = 0; /* whether to disable icons */
static int mflag = 0; /* whether the user specified a monitor with -p */ static int mflag = 0; /* whether the user specified a monitor with -p */
static int pflag = 0; /* whether the user specified a position with -p */ static int pflag = 0; /* whether the user specified a position with -p */
@ -116,8 +117,11 @@ main(int argc, char *argv[])
XClassHint classh; XClassHint classh;
int ch; int ch;
while ((ch = getopt(argc, argv, "ip:w")) != -1) { while ((ch = getopt(argc, argv, "fip:w")) != -1) {
switch (ch) { switch (ch) {
case 'f':
fflag = 1;
break;
case 'i': case 'i':
iflag = 1; iflag = 1;
break; break;
@ -642,6 +646,9 @@ drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *t
FcChar32 ucode; FcChar32 ucode;
XftFont *currfont; XftFont *currfont;
int textlen = 0; int textlen = 0;
int texty;
texty = y + (h - (dc.fonts[0]->ascent + dc.fonts[0]->descent))/2 + dc.fonts[0]->ascent;
s = text; s = text;
while (*s) { while (*s) {
@ -667,8 +674,7 @@ drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *t
textlen += ext.xOff; textlen += ext.xOff;
if (draw) { if (draw) {
int texty; if (!fflag)
texty = y + (h - (currfont->ascent + currfont->descent))/2 + currfont->ascent; texty = y + (h - (currfont->ascent + currfont->descent))/2 + currfont->ascent;
XftDrawStringUtf8(draw, color, currfont, x, texty, XftDrawStringUtf8(draw, color, currfont, x, texty,
(XftChar8 *)s, len); (XftChar8 *)s, len);
@ -1272,6 +1278,6 @@ cleanup(void)
static void static void
usage(void) usage(void)
{ {
(void)fprintf(stderr, "usage: xmenu [-iw] [-p position] [title]\n"); (void)fprintf(stderr, "usage: xmenu [-fiw] [-p position] [title]\n");
exit(1); exit(1);
} }