Allow X/Y position to be configurable on runtime

This commit is contained in:
Jacob 2023-08-12 17:53:13 +02:00
parent 646972ea70
commit a90be9015f
9 changed files with 110 additions and 17 deletions

View file

@ -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`

View file

@ -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);

View file

@ -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 */

View file

@ -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 },

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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