add symbols patch

This commit is contained in:
zcake 2021-02-10 11:58:14 +08:00
parent c6dbfd3260
commit f066b66cdb
9 changed files with 109 additions and 58 deletions

View File

@ -8,6 +8,8 @@ static const char *fonts[] = {
"monospace:size=10"
};
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
static const char *symbol_1 = "<";
static const char *symbol_2 = ">";
static const char *colors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" },

View File

@ -19,6 +19,7 @@ static const char *colors[SchemeLast][2] = {
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0;
static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */
/*
* Characters not considered part of a word while deleting words

View File

@ -1,5 +1,7 @@
/* See LICENSE file for copyright and license details. */
/* Default settings; can be overriden by command line. */
static const char *symbol_2 = "";
static const char *symbol_1 = "";
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */
/* -fn option overrides fonts[0]; default X11 font or font set */

BIN
dmenu

Binary file not shown.

20
dmenu.c
View File

@ -89,7 +89,7 @@ calcoffsets(void)
if (lines > 0)
n = lines * bh;
else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
n = mw - (promptw + inputw + TEXTW(symbol_1) + TEXTW(symbol_2));
/* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right)
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
@ -234,18 +234,18 @@ drawmenu(void)
} else if (matches) {
/* draw horizontal list */
x += inputw;
w = TEXTW("<");
w = TEXTW(symbol_1);
if (curr->left) {
drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0);
drw_text(drw, x, 0, w, bh, lrpad / 2, symbol_1, 0);
}
x += w;
for (item = curr; item != next; item = item->right)
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2) - TEXTW(numbers)));
if (next) {
w = TEXTW(">");
w = TEXTW(symbol_2);
drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, symbol_2, 0);
}
}
drw_setscheme(drw, scheme[SchemeNorm]);
@ -690,7 +690,7 @@ buttonpress(XEvent *e)
* add that to the input width */
if (ev->button == Button1 &&
((lines <= 0 && ev->x >= 0 && ev->x <= x + w +
((!prev || !curr->left) ? TEXTW("<") : 0)) ||
((!prev || !curr->left) ? TEXTW(symbol_1) : 0)) ||
(lines > 0 && ev->y >= y && ev->y <= y + h))) {
insert(NULL, -cursor);
drawmenu();
@ -741,7 +741,7 @@ buttonpress(XEvent *e)
} else if (matches) {
/* left-click on left arrow */
x += inputw;
w = TEXTW("<");
w = TEXTW(symbol_1);
if (prev && curr->left) {
if (ev->x >= x && ev->x <= x + w) {
sel = curr = prev;
@ -753,7 +753,7 @@ buttonpress(XEvent *e)
/* horizontal list: (ctrl)left-click on item */
for (item = curr; item != next; item = item->right) {
x += w;
w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
w = MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2));
if (ev->x >= x && ev->x <= x + w) {
puts(item->text);
if (!(ev->state & ControlMask))
@ -767,7 +767,7 @@ buttonpress(XEvent *e)
}
}
/* left-click on right arrow */
w = TEXTW(">");
w = TEXTW(symbol_2);
x = mw - w;
if (next && ev->x >= x && ev->x <= x + w) {
sel = curr = next;

View File

@ -15,6 +15,7 @@
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include <X11/XF86keysym.h>
#include <X11/Xft/Xft.h>
#include "drw.h"
@ -45,6 +46,7 @@ static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
static int inputw = 0, promptw, passwd = 0;
static int no = 0;
static int lrpad; /* sum of left and right padding */
static size_t cursor;
static struct item *items = NULL;
@ -199,7 +201,7 @@ drawmenu(void)
unsigned int curpos;
struct item *item;
int x = 0, y = 0, w;
char *censort;
char *censort;
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
@ -515,8 +517,8 @@ keypress(XKeyEvent *ev)
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
insert(NULL, nextrune(-1) - cursor);
break;
case XK_y: /* paste selection */
case XK_Y:
case XK_V: /* paste selection */
case XK_v:
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime);
return;
@ -546,8 +548,8 @@ keypress(XKeyEvent *ev)
case XK_g: ksym = XK_Home; break;
case XK_G: ksym = XK_End; break;
case XK_h: ksym = XK_Up; break;
case XK_j: ksym = XK_Next; break;
case XK_k: ksym = XK_Prior; break;
case XK_j: ksym = XK_Down; break;
case XK_k: ksym = XK_Up; break;
case XK_l: ksym = XK_Down; break;
default:
return;
@ -606,6 +608,7 @@ insert:
return;
/* fallthrough */
case XK_Up:
case XF86XK_AudioRaiseVolume:
if (sel && sel->left && (sel = sel->left)->right == curr) {
curr = prev;
calcoffsets();
@ -642,6 +645,7 @@ insert:
return;
/* fallthrough */
case XK_Down:
case XF86XK_AudioLowerVolume:
if (sel && sel->right && (sel = sel->right) == next) {
curr = next;
calcoffsets();
@ -804,6 +808,10 @@ readstdin(void)
return;
}
if(no){
return;
}
/* read each line from stdin and add it to the item list */
for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
if (i + 1 >= size / sizeof *items)
@ -972,9 +980,9 @@ setup(void)
static void
usage(void)
{
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
" [-nb color] [-nf color] [-sb color] [-sf color]\n"
" [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]\n", stderr);
fputs("usage: dmenu(zcake bulid) [-b bottom bar] [-n no item] [-l lines] [-p prompt] [-m monitor]\n"
" [-v prints version] [-F fuzzy] [-w windowid] [-P password]\n"
" [-f grabs the keyboard before reading stdin] \n", stderr);
exit(1);
}
@ -983,7 +991,6 @@ main(int argc, char *argv[])
{
XWindowAttributes wa;
int i, fast = 0;
for (i = 1; i < argc; i++)
/* these options take no arguments */
if (!strcmp(argv[i], "-v")) { /* prints version information */
@ -995,15 +1002,16 @@ main(int argc, char *argv[])
fast = 1;
else if (!strcmp(argv[i], "-F")) /* grabs keyboard before reading stdin */
fuzzy = 0;
else if (!strcmp(argv[i], "-P")) /* is the input a password */
passwd = 1;
else if (!strcmp(argv[i], "-n")) /* is the input a password */
no = 1;
else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
fstrncmp = strncmp;
fstrstr = strstr;
} else if (i + 1 == argc)
usage();
/* these options take one argument */
else if (!strcmp(argv[i], "-P")) /* is the input a password */
passwd = 1;
else if (i + 1 == argc)
usage();
/* these options take one argument */
@ -1013,24 +1021,6 @@ main(int argc, char *argv[])
mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i];
else if (!strcmp(argv[i], "-fn")) /* font or font set */
fonts[0] = argv[++i];
else if (!strcmp(argv[i], "-nb")) /* normal background color */
colors[SchemeNorm][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-nf")) /* normal foreground color */
colors[SchemeNorm][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-sb")) /* selected background color */
colors[SchemeSel][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
colors[SchemeSel][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
colors[SchemeNormHighlight][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
colors[SchemeNormHighlight][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-shb")) /* selected hi background color */
colors[SchemeSelHighlight][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
colors[SchemeSelHighlight][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
else
@ -1060,7 +1050,7 @@ main(int argc, char *argv[])
if (fast && !isatty(0)) {
grabkeyboard();
readstdin();
} else {
} else {
readstdin();
grabkeyboard();
}

View File

@ -1,19 +1,17 @@
--- dmenu.c
+++ dmenu.c
@@ -131,7 +131,7 @@ drawmenu(void)
{
unsigned int curpos;
struct item *item;
- int x = 0, y = 0, w;
+ int x = 0, y = 0, fh = drw->fonts->h, w;
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
@@ -684,6 +685,7 @@ static void
usage(void)
{
fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+ " [-h height]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
exit(1);
}
@@ -165,11 +165,11 @@ drawmenu(void)
}
x += w;
for (item = curr; item != next; item = item->right)
- x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
+ x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2)));
if (next) {
- w = TEXTW(">");
+ w = TEXTW(symbol_2);
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
+ drw_text(drw, mw - w, 0, w, bh, lrpad / 2, symbol_2, 0);
}
}
drw_map(drw, win, 0, 0, mw, mh);

BIN
dmenu.o

Binary file not shown.

View File

@ -0,0 +1,58 @@
From 6d0751e2eed6bfbed3cab0c87c8cb01e0b066be8 Mon Sep 17 00:00:00 2001
From: aleks <aleks.stier@icloud.com>
Date: Sun, 11 Aug 2019 02:01:11 +0200
Subject: [PATCH] Add settings to define symbols for too many options
Add the settings *symbol_1* and *symbol_2* to config.def.h. These enable
to define the symbols which are printed in dmenu to indicate that either
the input is too long or there are too many options to be shown in dmenu
in one line.
---
config.def.h | 2 ++
dmenu.c | 8 ++++----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1edb647..f58a50c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -7,6 +7,8 @@ static const char *fonts[] = {
"monospace:size=10"
};
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
+static const char *symbol_1 = "<";
+static const char *symbol_2 = ">";
static const char *colors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" },
diff --git a/dmenu.c b/dmenu.c
index 6b8f51b..ff398a7 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -79,7 +79,7 @@ calcoffsets(void)
if (lines > 0)
n = lines * bh;
else
- n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
+ n = mw - (promptw + inputw + TEXTW(symbol_1) + TEXTW(symbol_2));
/* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right)
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
@@ -165,11 +165,11 @@ drawmenu(void)
}
x += w;
for (item = curr; item != next; item = item->right)
- x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
+ x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2)));
if (next) {
- w = TEXTW(">");
+ w = TEXTW(symbol_2);
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
+ drw_text(drw, mw - w, 0, w, bh, lrpad / 2, symbol_2, 0);
}
}
drw_map(drw, win, 0, 0, mw, mh);
--
2.22.0