diff --git a/README.md b/README.md index 3cc0e16..dddaecc 100644 --- a/README.md +++ b/README.md @@ -476,6 +476,7 @@ Below is a list of all .Xresources values you can define. - speedwm.layout.monocle.clientcount: 0 - speedwm.layout.monocle.count: 0 - speedwm.layout.monocle.format: [%d/%d] +- speedwm.layout.custom.cmd: printf '' | spmenu -i -l 10 -p 'Enter S expression:' - speedwm.mfact: 0.50 - speedwm.mfact.lowest: 0.05 - speedwm.mouse.clicktofocus: 0 diff --git a/docs/example.Xresources b/docs/example.Xresources index 4062665..d57a56a 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -223,6 +223,9 @@ speedwm.layout.monocle.clientcount: 0 ! Enable client count in the monocle la speedwm.layout.monocle.count: 0 ! Enable focused client and number of total clients in the monocle layout (0/1) speedwm.layout.monocle.format: [%d/%d] +!! Custom layout +speedwm.layout.custom.cmd: printf '' | spmenu -i -l 10 -p 'Enter S expression:' + !! mfact options speedwm.mfact: 0.50 ! Default mfact (0-1) speedwm.mfact.lowest: 0.05 ! Lowest possible mfact (0-1) diff --git a/layouts.c b/layouts.c index e4efb87..97f0df7 100644 --- a/layouts.c +++ b/layouts.c @@ -1436,7 +1436,8 @@ struct string_token_t* tokenize_string(char *str) } /* Parse s-expression to node_t structure */ -node_t* parse_sexp(string_token_t **token) +node_t* +parse_sexp(string_token_t **token) { node_t *head = NULL; node_t branch, *p = &branch; @@ -1630,42 +1631,22 @@ node_t* parse_sexp(string_token_t **token) *token = t; return head; } -void set_s_layout(const Arg *arg) + +void +set_s_layout(const Arg *arg) { - FILE *pp, *hf; + char *cf; + //char *cmd = "printf 'CUCK' | spmenu -i -l 10 -p 'sxp>'"; + FILE *pp = popen(custom_cmd, "r"); - char pathbuf[1024]; - char *home = getenv("HOME"); - int sortout = 0; - int histout = 0; - if (home != NULL) { - snprintf(pathbuf, 1023, "%s/" CUSTOM_HISTORY, home); - pathbuf[1023] = '\0'; - - // make sure the history file exists - hf = fopen(CUSTOM_HISTORY, "a"); fclose(hf); - - sortout = system("sort " CUSTOM_HISTORY " | uniq > " CUSTOM_HISTORY "~"); - histout = system("mv " CUSTOM_HISTORY "~ " CUSTOM_HISTORY); - - pp = popen("dmenu -i -l 10 -p 'Enter expression:' <" CUSTOM_HISTORY, "r"); - } else { - pp = popen("dmenu -i -l 10 -p 'Enter expression:'", "r"); - } - - if (sortout || !sortout || histout || !histout) - if (!pp) return; - - char buf[1024 + 1]; - buf[1024] = '\0'; - if (!fgets(buf, 1024, pp)) return; - fclose(pp); + if (!pp) return; + char buf[1024] = ""; + //buf[1024+1] = '\0'; + cf = fgets(buf, 1024, pp); if (buf[0] == '\0') return; + //fclose(pp); - // Write to history file - hf = fopen(CUSTOM_HISTORY, "a"); - fprintf(hf, "%s", buf); - fclose(hf); + if (!cf) return; if (s_layout_scheme != NULL) { free_node(s_layout_scheme); @@ -1675,6 +1656,7 @@ void set_s_layout(const Arg *arg) struct string_token_t *token_root = tokenize_string(buf), *token = token_root; + if (!token_root) return; s_layout_scheme = parse_sexp(&token); setlayout(arg); diff --git a/options.h b/options.h index ceec5d0..c207ed4 100755 --- a/options.h +++ b/options.h @@ -153,7 +153,7 @@ static int deckcount = 0; /* Display deck count in the deck layout */ static char deckformat[] = "[%d]"; /* Format of the deck count. deckcount must be set to 1 for this to be used. */ /* Custom layout */ -#define CUSTOM_HISTORY ".custom_history" +static char *custom_cmd = "printf '' | spmenu -i -l 10 -p 'Enter S expression:'"; /* Command to run when setting S expression */ /* Resetting */ static int resetlayout = 0; /* Reset layout when there is only one client visible */ diff --git a/speedwm.1 b/speedwm.1 index c1262ee..d7c4a71 100644 --- a/speedwm.1 +++ b/speedwm.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pandoc 2.19.2 +.\" Automatically generated by Pandoc 3.0.1 .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. @@ -811,71 +811,71 @@ speedwm.col.windowbordersel: #eeeeee .IP \[bu] 2 speedwm.col.windowborderurg: #f0e68c .IP \[bu] 2 -speedwm.text.tag1.empty: \[uF8A5] +speedwm.text.tag1.empty:  .IP \[bu] 2 -speedwm.text.tag2.empty: \[uF8A8] +speedwm.text.tag2.empty:  .IP \[bu] 2 -speedwm.text.tag3.empty: \[uF8AB] +speedwm.text.tag3.empty:  .IP \[bu] 2 -speedwm.text.tag4.empty: \[uF8AE] +speedwm.text.tag4.empty:  .IP \[bu] 2 -speedwm.text.tag5.empty: \[uF8B1] +speedwm.text.tag5.empty:  .IP \[bu] 2 -speedwm.text.tag6.empty: \[uF8B4] +speedwm.text.tag6.empty:  .IP \[bu] 2 -speedwm.text.tag7.empty: \[uF8B7] +speedwm.text.tag7.empty:  .IP \[bu] 2 -speedwm.text.tag8.empty: \[uF8BA] +speedwm.text.tag8.empty:  .IP \[bu] 2 -speedwm.text.tag9.empty: \[uF8BD] +speedwm.text.tag9.empty:  .IP \[bu] 2 -speedwm.text.tag1.used: \[uF8A3] +speedwm.text.tag1.used:  .IP \[bu] 2 -speedwm.text.tag2.used: \[uF8A6] +speedwm.text.tag2.used:  .IP \[bu] 2 -speedwm.text.tag3.used: \[uF8A9] +speedwm.text.tag3.used:  .IP \[bu] 2 -speedwm.text.tag4.used: \[uF8AC] +speedwm.text.tag4.used:  .IP \[bu] 2 -speedwm.text.tag5.used: \[uF8AF] +speedwm.text.tag5.used:  .IP \[bu] 2 -speedwm.text.tag6.used: \[uF8B2] +speedwm.text.tag6.used:  .IP \[bu] 2 -speedwm.text.tag7.used: \[uF8B5] +speedwm.text.tag7.used:  .IP \[bu] 2 -speedwm.text.tag8.used: \[uF8B8] +speedwm.text.tag8.used:  .IP \[bu] 2 -speedwm.text.tag9.used: \[uF8BB] +speedwm.text.tag9.used:  .IP \[bu] 2 -speedwm.text.layout1: \[uF330] +speedwm.text.layout1:  .IP \[bu] 2 -speedwm.text.layout2: \[uF331] +speedwm.text.layout2:  .IP \[bu] 2 -speedwm.text.layout3: \[uF332] +speedwm.text.layout3:  .IP \[bu] 2 -speedwm.text.layout4: \[uF333] +speedwm.text.layout4:  .IP \[bu] 2 -speedwm.text.layout5: \[uF334] +speedwm.text.layout5:  .IP \[bu] 2 -speedwm.text.layout6: \[uF335] +speedwm.text.layout6:  .IP \[bu] 2 -speedwm.text.layout7: \[uF336] +speedwm.text.layout7:  .IP \[bu] 2 -speedwm.text.layout8: \[uF337] +speedwm.text.layout8:  .IP \[bu] 2 -speedwm.text.layout9: \[uF338] +speedwm.text.layout9:  .IP \[bu] 2 -speedwm.text.layout10: \[uF339] +speedwm.text.layout10:  .IP \[bu] 2 -speedwm.text.layout11: \[uF33A] +speedwm.text.layout11:  .IP \[bu] 2 -speedwm.text.layout12: \[uF33B] +speedwm.text.layout12:  .IP \[bu] 2 -speedwm.text.layout13: \[uF33C] +speedwm.text.layout13:  .IP \[bu] 2 -speedwm.text.layout14: \[uF33D] +speedwm.text.layout14:  .IP \[bu] 2 -speedwm.text.layout15: \[uF33E] +speedwm.text.layout15:  .IP \[bu] 2 speedwm.color.hiddentitle: 1 .IP \[bu] 2 @@ -919,6 +919,9 @@ speedwm.layout.monocle.count: 0 .IP \[bu] 2 speedwm.layout.monocle.format: [%d/%d] .IP \[bu] 2 +speedwm.layout.custom.cmd: printf \[cq]\[cq] | spmenu -i -l 10 -p `Enter +S expression:' +.IP \[bu] 2 speedwm.mfact: 0.50 .IP \[bu] 2 speedwm.mfact.lowest: 0.05 @@ -1675,7 +1678,7 @@ Mihir Lad .IP \[bu] 2 MLquest8 .IP \[bu] 2 -Ond\[u0159]ej Grover +Ondřej Grover .IP \[bu] 2 ornx .IP \[bu] 2 @@ -1691,7 +1694,7 @@ Ryan Roden-Corrent .IP \[bu] 2 sipi .IP \[bu] 2 -S\[:o]nke Lambert +Sönke Lambert .IP \[bu] 2 speedie .IP \[bu] 2 @@ -1703,6 +1706,6 @@ suckless.org .IP \[bu] 2 Timmy Keller .IP \[bu] 2 -Viliam Kov\['a]\[u010D] +Viliam Kováč .PP See Codeberg contributions for more information. diff --git a/speedwm.c b/speedwm.c index 1095b34..dac77c3 100644 --- a/speedwm.c +++ b/speedwm.c @@ -955,6 +955,7 @@ static xcb_connection_t *xcon; #include "toggle/query.h" #endif #include "options.h" /* Include options */ +#include "layouts.c" /* Enable patched layouts */ /* Shell command */ #define cmd( cmd ) {.v = (const char*[]){ shell, "-c", cmd, NULL } }, @@ -6798,6 +6799,3 @@ togglewin(const Arg *arg) focus(c); arrange(selmon); } - -/* Layout code */ -#include "layouts.c" /* Enable patched layouts */ diff --git a/xresources.h b/xresources.h index e4e2919..07763ce 100644 --- a/xresources.h +++ b/xresources.h @@ -187,6 +187,7 @@ ResourcePref resources[] = { { "layout.monocle.count", INTEGER, &monoclecount }, { "layout.deck.format", STRING, &deckformat }, { "layout.deck.count", INTEGER, &deckcount }, + { "layout.custom.cmd", STRING, &custom_cmd }, #if USEWINICON { "icon.size", INTEGER, &iconsize }, { "icon.spacing", INTEGER, &iconspacing },