From a90be9015fddec8a2c450a1ceff95adcd97079fb Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 12 Aug 2023 17:53:13 +0200 Subject: [PATCH] Allow X/Y position to be configurable on runtime --- docs/docs.md | 10 ++++++++++ libs/arg.c | 21 ++++++++++++++++++++ libs/arg.h | 3 +++ libs/conf/config.h | 3 +++ libs/fifo.c | 26 ++++++++++++++++++++++++- libs/img.c | 4 ++-- libs/x11/client.c | 8 ++------ libs/x11/init.c | 4 ++-- spmenu.1 | 48 ++++++++++++++++++++++++++++++++++++++++------ 9 files changed, 110 insertions(+), 17 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index 94ca025..963d481 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -782,6 +782,12 @@ for performance reasons. | setlines- | Decrease lines by 1 | | setcolumns+ | Increase columns by 1 | | setcolumns- | Decrease columns by 1 | +| setx+ | Increase X position by 1 | +| setx- | Decrease X position by 1 | +| sety+ | Increase Y position by 1 | +| sety- | Decrease Y position by 1 | +| setw+ | Increase width by 1 | +| setw- | Decrease width by 1 | | moveup | Move up one item | | movedown | Move down one item | | moveleft | Move left one item | @@ -1175,6 +1181,10 @@ bind: - Set lines to passed argument - `setcolumns` - Set columns to passed argument +- `setx` + - Set X position to passed argument +- `sety` + - Set Y position to passed argument - `setlineheight` - Set line height to passed argument - `setprofile` diff --git a/libs/arg.c b/libs/arg.c index d3d69b3..35a5149 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -600,6 +600,27 @@ void setcolumns(Arg *arg) { drawmenu(); } +void setx(Arg *arg) { + xpos += arg->i; + + resizeclient(); + drawmenu(); +} + +void sety(Arg *arg) { + ypos += arg->i; + + resizeclient(); + drawmenu(); +} + +void setw(Arg *arg) { + menuwidth += arg->i; + + resizeclient(); + drawmenu(); +} + void spawn(Arg *arg) { if (!system(arg->c)) die("spmenu: failed to execute command '%s'", arg->c); diff --git a/libs/arg.h b/libs/arg.h index 95712e8..e0bf826 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -57,6 +57,9 @@ static void screenshot(Arg *arg); static void switchmode(Arg *arg); static void setprofile(Arg *arg); static void setlineheight(Arg *arg); +static void setx(Arg *arg); +static void sety(Arg *arg); +static void setw(Arg *arg); static void quit(Arg *arg); /* toggle */ diff --git a/libs/conf/config.h b/libs/conf/config.h index ceccd20..0bb9ce2 100644 --- a/libs/conf/config.h +++ b/libs/conf/config.h @@ -377,6 +377,9 @@ static FuncList fl[] = { { "setlines", setlines }, { "screenshot", screenshot }, { "setcolumns", setcolumns }, + { "setx", setx }, + { "sety", sety }, + { "setw", setw }, { "toggleinput", toggleinput }, { "togglepretext", togglepretext }, { "togglelarrow", togglelarrow }, diff --git a/libs/fifo.c b/libs/fifo.c index 8d793eb..fee282d 100644 --- a/libs/fifo.c +++ b/libs/fifo.c @@ -109,7 +109,7 @@ void execute_fifo_cmd(void) { setprofile(&arg); } else if (!strcmp(fifot, "setlines+")) { Arg arg; - arg.i = +1; + arg.i = 1; setlines(&arg); } else if (!strcmp(fifot, "setlines-")) { Arg arg; @@ -123,6 +123,30 @@ void execute_fifo_cmd(void) { Arg arg; arg.i = -1; setcolumns(&arg); + } else if (!strcmp(fifot, "setx+")) { + Arg arg; + arg.i = 1; + setx(&arg); + } else if (!strcmp(fifot, "setx-")) { + Arg arg; + arg.i = -1; + setx(&arg); + } else if (!strcmp(fifot, "sety+")) { + Arg arg; + arg.i = 1; + sety(&arg); + } else if (!strcmp(fifot, "sety-")) { + Arg arg; + arg.i = -1; + sety(&arg); + } else if (!strcmp(fifot, "setw+")) { + Arg arg; + arg.i = 1; + setw(&arg); + } else if (!strcmp(fifot, "setw-")) { + Arg arg; + arg.i = -1; + setw(&arg); } else if (!strcmp(fifot, "moveup")) { Arg arg; moveup(&arg); diff --git a/libs/img.c b/libs/img.c index c088491..c1cd686 100644 --- a/libs/img.c +++ b/libs/img.c @@ -365,8 +365,8 @@ void resizetoimageheight_x11(int imageheight) { x = (mo.output_width - sp.mw) / 2 + xpos; y = (mo.output_height - sp.mh) / 2 - ypos; } else { // top or bottom - x = 0; - y = menuposition ? 0 : mo.output_width - sp.mh - ypos; + x = xpos; + y = menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos); sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width); } diff --git a/libs/x11/client.c b/libs/x11/client.c index ef7acad..3e2f95a 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -70,7 +70,6 @@ void set_prop_x11(void) { } void resizeclient_x11(void) { - int mh = sp.mh; int x, y; struct item *item; int ic = 0; // item count @@ -98,14 +97,11 @@ void resizeclient_x11(void) { x = (mo.output_width - sp.mw) / 2 + xpos; y = (mo.output_height - sp.mh) / 2 - ypos; } else { // top or bottom - x = 0; - y = menuposition ? 0 : mo.output_height - sp.mh - ypos; + x = xpos; + y = menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos); sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width); } - // no window/invalid window or menu height we had before is the same as the current window height - if (!win || mh == sp.mh) return; - XMoveResizeWindow(dpy, win, x + sp.sp, y + sp.vp, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); draw_resize(draw, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); } diff --git a/libs/x11/init.c b/libs/x11/init.c index 7c8ee58..a82a90d 100644 --- a/libs/x11/init.c +++ b/libs/x11/init.c @@ -71,8 +71,8 @@ void setupdisplay_x11(void) { x = (mo.output_width - sp.mw) / 2 + xpos; y = (mo.output_height - sp.mh) / 2 - ypos; } else { // top or bottom - x = 0; - y = menuposition ? 0 : mo.output_height - sp.mh - ypos; + x = xpos; + y = menuposition ? (-ypos) : (mo.output_height - sp.mh - ypos); sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width); } diff --git a/spmenu.1 b/spmenu.1 index f811e36..62b891d 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -874,12 +874,6 @@ Otherwise it will be considered invalid. It is recommended that you sleep for 0.1 seconds after appending to the file for performance reasons. .PP -\f[B]NOTE: Please remove /tmp/spmenu.fifo if it exists after usage, -especially in scripts. -Otherwise the FIFO action may be carried over to the user\[cq]s next -spmenu use. -If you love your users, do not ignore this warning.\f[R] -.PP .TS tab(@); lw(12.7n) lw(57.3n). @@ -1041,6 +1035,36 @@ T}@T{ Decrease columns by 1 T} T{ +setx+ +T}@T{ +Increase X position by 1 +T} +T{ +setx- +T}@T{ +Decrease X position by 1 +T} +T{ +sety+ +T}@T{ +Increase Y position by 1 +T} +T{ +sety- +T}@T{ +Decrease Y position by 1 +T} +T{ +setw+ +T}@T{ +Increase width by 1 +T} +T{ +setw- +T}@T{ +Decrease width by 1 +T} +T{ moveup T}@T{ Move up one item @@ -2517,6 +2541,18 @@ Set lines to passed argument Set columns to passed argument .RE .IP \[bu] 2 +\f[V]setx\f[R] +.RS 2 +.IP \[bu] 2 +Set X position to passed argument +.RE +.IP \[bu] 2 +\f[V]sety\f[R] +.RS 2 +.IP \[bu] 2 +Set Y position to passed argument +.RE +.IP \[bu] 2 \f[V]setlineheight\f[R] .RS 2 .IP \[bu] 2