From 4f1a6d53495ac6c02163c769d63d463c408c99d1 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 30 Apr 2023 23:45:58 +0200 Subject: [PATCH] add the ability to have text padding depending on item selection --- docs/example.Xresources | 3 +++ docs/spmenu.conf | 5 ++++- libs/conf/config.c | 3 +++ libs/draw.c | 20 ++++++++++++++++++-- libs/xresources.h | 3 +++ options.h | 5 ++++- 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/docs/example.Xresources b/docs/example.Xresources index ea051ca..cc6e224 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -6,6 +6,9 @@ !! Fonts spmenu.font: Noto Sans Mono 8 spmenu.textpadding: 0 +spmenu.normitempadding: 0 +spmenu.selitempadding: 0 +spmenu.priitempadding: 0 !! Colors spmenu.col_itemnormfg: #bbbbbb diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 3d9be9a..d202964 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -30,7 +30,10 @@ spmenu = { /* Text */ text = ( { font = "Noto Sans Mono 8"; // Font to use for all text (text) - padding = 0; // Horizontal padding around the text (px) + padding = 0; // Horizontal padding around the text globally (px) + normitempadding = 0; // Horizontal padding around the normal item text (px) + selitempadding = 0; // Horizontal padding around the selected item text (px) + priitempadding = 0; // Horizontal padding around the high priority item text (px) leftarrow = "<"; // Left arrow text (text) rightarrow = ">"; // Right arrow text (text) password = "*"; // Password character (text) diff --git a/libs/conf/config.c b/libs/conf/config.c index d092989..fbcdce5 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -133,6 +133,9 @@ conf_init(void) strcpy(font, strdup(dest)); config_setting_lookup_int(conf, "padding", &textpadding); // spmenu.text.padding + config_setting_lookup_int(conf, "normitempadding", &normitempadding); // spmenu.text.normitempadding + config_setting_lookup_int(conf, "selitempadding", &selitempadding); // spmenu.text.selitempadding + config_setting_lookup_int(conf, "priitempadding", &priitempadding); // spmenu.text.priitempadding if (config_setting_lookup_string(conf, "leftarrow", &dest)) // spmenu.text.leftarrow leftarrow = strdup(dest); diff --git a/libs/draw.c b/libs/draw.c index 9b0fcc5..b78e677 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -50,18 +50,34 @@ drawitemtext(struct item *item, int x, int y, int w) int bgfg = 0; // both int ignore = 0; // ignore colors int skiphighlight = 0; // skip highlighting + int selitem = 0; + int priitem = 0; // memcpy the correct scheme if (item == sel) { memcpy(scm, scheme[SchemeItemSel], sizeof(scm)); + selitem = 1; - if (item->hp) + if (item->hp) { memcpy(scm, scheme[SchemeItemSelPri], sizeof(scm)); + priitem = 1; + } } else { memcpy(scm, scheme[SchemeItemNorm], sizeof(scm)); - if (item->hp) + if (item->hp) { memcpy(scm, scheme[SchemeItemNormPri], sizeof(scm)); + priitem = 1; + } + } + + // apply extra padding + if ((selitem && !priitem) && lines) { + leftpadding += selitempadding; + } else if (priitem && lines) { + leftpadding += priitempadding; + } else if (lines) { + leftpadding += normitempadding; } // don't color diff --git a/libs/xresources.h b/libs/xresources.h index 9179eac..2b2ddf7 100644 --- a/libs/xresources.h +++ b/libs/xresources.h @@ -104,6 +104,9 @@ ResourcePref resources[] = { { "menumarginv", INTEGER, &menumarginv }, { "menumarginh", INTEGER, &menumarginh }, { "textpadding", INTEGER, &textpadding }, + { "normitempadding", INTEGER, &normitempadding }, + { "selitempadding", INTEGER, &selitempadding }, + { "priitempadding", INTEGER, &priitempadding }, { "indentitems", INTEGER, &indentitems }, { "accuratewidth", INTEGER, &accuratewidth }, { "alpha", INTEGER, &alpha }, diff --git a/options.h b/options.h index f38f2e2..9a14272 100644 --- a/options.h +++ b/options.h @@ -58,7 +58,10 @@ static int borderwidth = 0; /* Width of the border */ /* Font options */ static char font[] = "Noto Sans Mono 8"; /* Font to draw text and Pango markup with. */ -static int textpadding = 0; /* Text padding (lrpad) */ +static int textpadding = 0; /* Global text padding */ +static int normitempadding = 0; /* Text padding for normal items */ +static int selitempadding = 0; /* Text padding for the selected item */ +static int priitempadding = 0; /* Text padding for the high priority items */ /* Text options */ static char *leftarrow = "<"; /* Left arrow, used to indicate you can move to the left */