From f8eb16beff382f4845072b76460352d402e564f3 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 23 Jan 2023 19:44:47 +0100 Subject: [PATCH] add wip query support, hidebar/hidebars instead of showbar/showbars --- queries.h | 22 +++++++ speedwm.c | 41 ++++++++++--- toggle.h | 1 + toggle/ipc-yajl.c | 2 +- toggle/query.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++ toggle/query.h | 17 ++++++ 6 files changed, 225 insertions(+), 10 deletions(-) create mode 100644 queries.h create mode 100644 toggle/query.c create mode 100644 toggle/query.h diff --git a/queries.h b/queries.h new file mode 100644 index 0000000..947cdf3 --- /dev/null +++ b/queries.h @@ -0,0 +1,22 @@ +/* Queries + * + * Queries allow you to return the output of almost any function using the '-q' argument. + */ +static Query queries[] = { + /* queries functions */ + { "get_tags", get_tags }, + { "get_numtags", get_numtags }, + { "get_layouts", get_layouts }, + { "get_numlayouts", get_numlayouts }, + { "get_barpos", get_barpos }, + { "get_bordersize", get_bordersize }, + { "get_hidebar", get_hidebar }, + { "get_snap", get_snap }, + { "get_queries", get_queries }, + { "get_font", get_font }, + { "get_mfact", get_mfact }, + { "get_mastercount", get_mastercount }, + { "get_resizehints", get_resizehints }, + { "get_lockfullscreen", get_lockfullscreen }, +}; + diff --git a/speedwm.c b/speedwm.c index ea3fdd5..39aa341 100644 --- a/speedwm.c +++ b/speedwm.c @@ -163,6 +163,13 @@ struct ClientState { }; #endif +#if USEQUERY +typedef struct { + const char *query_text; + int (*func)(); +} Query; +#endif + enum { bar_align_left, bar_align_center, @@ -345,7 +352,7 @@ struct Monitor { #if USEIPC TagState tagstate; #endif - int showbar; + int hidebar; /* bar items */ int hidelayout; @@ -939,6 +946,9 @@ static xcb_connection_t *xcon; #include /* Enable multimedia button support */ /* Configuration */ +#if USEQUERY +#include "toggle/query.h" +#endif #include "options.h" /* Include options */ /* Shell command */ @@ -981,6 +991,11 @@ static const char *clickstatus[] = { shell, "-c", NULL, NULL }; /* for running c #include "bar/items.c" +#if USEQUERY +#include "queries.h" +#include "toggle/query.c" +#endif + unsigned int tagw[LENGTH(ftags)]; struct Pertag { @@ -991,7 +1006,7 @@ struct Pertag { int stackcounts[LENGTH(ftags) + 1]; /* number of windows in primary stack area */ int ltaxis[LENGTH(ftags) + 1][ltaxislast]; const Layout *ltidxs[LENGTH(ftags) + 1][3]; /* matrix of tags and layouts indexes */ - int showbars[LENGTH(ftags) + 1]; /* display bar for the current tag */ + int hidebars[LENGTH(ftags) + 1]; /* display bar for the current tag */ }; /* compile-time check if all tags fit into an unsigned int bit array. */ @@ -1719,7 +1734,7 @@ createmon(void) m->mfact = mfact; m->mastercount = mastercount; m->stackcount = stackcount; - m->showbar = !hidebar; + m->hidebar = hidebar; m->scalepreview = scalepreview; /* bar items */ @@ -1794,7 +1809,7 @@ createmon(void) m->pertag->ltidxs[i][0] = m->lt[0]; m->pertag->ltidxs[i][1] = m->lt[1]; m->pertag->sellts[i] = m->sellt; - m->pertag->showbars[i] = m->showbar; + m->pertag->hidebars[i] = m->hidebar; m->pertag->ltaxis[i][layout] = m->ltaxis[layout]; m->pertag->ltaxis[i][master] = m->ltaxis[master]; m->pertag->ltaxis[i][stack] = m->ltaxis[stack]; @@ -3851,8 +3866,8 @@ moveresizeedge(const Arg *arg) { nw = c->w; nh = c->h; - starty = selmon->showbar && barposition ? bh : 0; - bp = selmon->showbar && !barposition ? bh : 0; + starty = !selmon->hidebar && barposition ? bh : 0; + bp = !selmon->hidebar && !barposition ? bh : 0; if (!c || !arg) return; @@ -5450,7 +5465,7 @@ togglebar(const Arg *arg) Bar *bar; - selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar; + selmon->hidebar = selmon->pertag->hidebars[selmon->pertag->curtag] = !selmon->hidebar; updatebarpos(selmon); for (bar = selmon->bar; bar; bar = bar->next) XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); @@ -5757,7 +5772,7 @@ updatebarpos(Monitor *m) bar->bh = bh; } - if (!m->showbar) { + if (m->hidebar) { for (bar = m->bar; bar; bar = bar->next) bar->by = -bh - y_pad; return; @@ -6164,7 +6179,7 @@ view(const Arg *arg) selmon->ltaxis[stack] = selmon->pertag->ltaxis[selmon->pertag->curtag][stack]; selmon->ltaxis[stack2] = selmon->pertag->ltaxis[selmon->pertag->curtag][stack2]; - if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) + if (!selmon->hidebar != !selmon->pertag->hidebars[selmon->pertag->curtag]) togglebar(NULL); } @@ -6493,6 +6508,14 @@ main(int argc, char *argv[]) { if (argc == 2 && !strcmp("-v", argv[1])) die("speedwm-"VERSION); +#if USEQUERY + if (argc > 1 && !strcmp("-q", argv[1])) { + if (argc == 2) + die("speedwm: You must specify a query"); + char *args = argv[2]; + return query(args); + } +#endif else if (argc != 1 && strcmp("-s", argv[1])) die("Invalid argument."); if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) diff --git a/toggle.h b/toggle.h index 4407816..fbf8181 100644 --- a/toggle.h +++ b/toggle.h @@ -18,6 +18,7 @@ Not compatible with BSDs so for those, set this to 0. */ #define USEFADE 1 /* Include fading windows */ /* Miscellanious */ +#define USEQUERY 1 /* Include support for queries */ #define USESWITCHER 1 /* Include the switcher */ #define USESYSTRAY 1 /* Include the systray */ #define USEMOUSE 1 /* Include mouse binds */ diff --git a/toggle/ipc-yajl.c b/toggle/ipc-yajl.c index 1f45a29..3f597f0 100644 --- a/toggle/ipc-yajl.c +++ b/toggle/ipc-yajl.c @@ -150,7 +150,7 @@ dump_monitor(yajl_gen gen, Monitor *mon, int is_selected) YSTR("bar"); YMAP( YSTR("y"); YINT(mon->bar->by); - YSTR("is_shown"); YBOOL(mon->showbar); + YSTR("is_shown"); YBOOL(!mon->hidebar); YSTR("is_top"); YBOOL(mon->bar->barposition); YSTR("window_id"); YINT(mon->bar->win); ) diff --git a/toggle/query.c b/toggle/query.c new file mode 100644 index 0000000..e220db5 --- /dev/null +++ b/toggle/query.c @@ -0,0 +1,152 @@ +/* This contains functions for getting speedwm queries. + * + * If you don't need some of these, you can simply remove them from this file and query.h. + * query handles all the other functions. + */ + +int +query(char *args) +{ + int i = 0; + + for (i = 0; i < LENGTH(queries); i++) { + if (strcmp(queries[i].query_text, args) == 0) { + return queries[i].func(); + } + } + + int ps = fprintf(stderr, "speedwm: Not a valid query.\n"); + if (ps) return 0; else return 1; +} + +int +get_queries() +{ + int i = 0; + int ps = 0; + + for (i = 0; i < LENGTH(queries); i++) { + ps = fprintf(stdout, "%s\n", queries[i].query_text); + } + + if (ps) return 0; else return 1; +} + +int +get_font() +{ + int i = 0; + int ps = 0; + + ps = fprintf(stdout, "%s\n", font); + + if (ps) return 0; else return 1; +} + +int +get_barpos() +{ + int ps = fprintf(stdout, "%d\n", barposition); + if (ps) return 0; else return 1; +} + +int +get_mfact() +{ + int ps = fprintf(stdout, "%f\n", mfact); + if (ps) return 0; else return 1; +} + +int +get_mastercount() +{ + int ps = fprintf(stdout, "%d\n", mastercount); + if (ps) return 0; else return 1; +} + +int +get_resizehints() +{ + int ps = fprintf(stdout, "%d\n", mastercount); + if (ps) return 0; else return 1; +} + +int +get_lockfullscreen() +{ + int ps = fprintf(stdout, "%d\n", lockfullscreen); + if (ps) return 0; else return 1; +} + +int +get_snap() +{ + int ps = fprintf(stdout, "%d\n", snap); + if (ps) return 0; else return 1; +} + +int +get_hidebar() +{ + int ps = fprintf(stdout, "%d\n", hidebar); + if (ps) return 0; else return 1; +} + +int +get_bordersize() +{ + int ps = fprintf(stdout, "%d\n", bordersize); + if (ps) return 0; else return 1; +} + +int +get_layouts() +{ + int i = 0; + int ps = 0; + + for (i = 0; i < LENGTH(layouts); i++) { + ps = fprintf(stdout, "%s\n", layouts[i].symbol); + } + + if (ps) return 0; else return 1; +} + +int +get_numlayouts() +{ + int i = 0; + int ps = 0; + + for (i = 0; i < LENGTH(layouts); i++) {} + + ps = fprintf(stdout, "%d\n", i); + + if (ps) return 0; else return 1; +} + +int +get_numtags() +{ + int i = 0; + int ps = 0; + + for (i = 0; i < LENGTH(tags); i++) {} + + ps = fprintf(stdout, "%d\n", i); + + if (ps) return 0; else return 1; +} + +int +get_tags() +{ + int i = 0; + int ps = 0; + + for (i = 0; i < LENGTH(tags); i++) { + ps = fprintf(stdout, "%s\n", tags[i]); + } + + if (ps) return 0; else return 1; +} diff --git a/toggle/query.h b/toggle/query.h new file mode 100644 index 0000000..8c9b945 --- /dev/null +++ b/toggle/query.h @@ -0,0 +1,17 @@ +static int query(char *args); + +/* queries */ +static int get_numtags(); +static int get_tags(); +static int get_layouts(); +static int get_numlayouts(); +static int get_barpos(); +static int get_bordersize(); +static int get_hidebar(); +static int get_snap(); +static int get_queries(); +static int get_font(); +static int get_mfact(); +static int get_mastercount(); +static int get_resizehints(); +static int get_lockfullscreen();