From 049860f3d2826999c502e6138204da8c857e7738 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Tue, 15 Apr 2025 11:16:47 +0200 Subject: [PATCH] allow setting of position at startup --- wayneko.1 | 9 +++++++++ wayneko.c | 24 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/wayneko.1 b/wayneko.1 index 9221f95..39d2f0a 100644 --- a/wayneko.1 +++ b/wayneko.1 @@ -22,6 +22,7 @@ wayneko \- Neko on Wayland but with phases .OP \-\-currently awake|asleep|random .OP \-\-layer background|bottom|top|overlay .OP \-\-output name +.OP \-\-position float .OP \-\-survive\-close .YS . @@ -111,6 +112,14 @@ exist. Defaults to the currently selected monitor. .RE . .P +\fB\-\-position\fR \fIfloat\fR|\fBrandom\fR +.RS +Set the position neko is at on startup. Expects a float between 0 and 1, where +0 is the leftmost position and 1 is to the rightmost one. Defaults to the +center, i.e. 0.5. +.RE +. +.P \fB\-\-survive\-close\fR .RS If this flag is used, wayneko will recreate the surface after it has been closed. diff --git a/wayneko.c b/wayneko.c index 19bbb8c..b5f06c0 100644 --- a/wayneko.c +++ b/wayneko.c @@ -37,6 +37,7 @@ const char usage[] = " --sleep-phase seconds-seconds\n" " --awake-phase seconds-seconds\n" " --currently awake|asleep|random\n" + " --position float\n" " --layer background|bottom|top|overlay\n" " --output name\n" " --survive-close\n" @@ -82,6 +83,7 @@ enum Type type = PLAIN; bool follow_pointer = false; // TODO: implement this again bool recreate_surface_on_close = false; enum zwlr_layer_shell_v1_layer layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; +float start_position = 0.5; struct ext_idle_notifier_v1 *idle_notifier = NULL; uint32_t neko_idle_timeout_ms = 180000; /* 3 minutes. */ @@ -1176,7 +1178,7 @@ static void layer_surface_handle_configure (void *data, struct zwlr_layer_surfac /* Center neko on first configure. */ if (!surface.configured) { - surface.neko_x = (uint16_t)((width / 2) - neko_size); + surface.neko_x = (uint16_t)((float) (width - neko_size) * start_position); surface.prev_neko_x = surface.neko_x; } @@ -1485,6 +1487,26 @@ int main (int argc, char *argv[]) else if ( strcmp(a, "overlay") == 0 ) layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; } + else if ( strcmp(argv[i], "--position") == 0 ) + { + char *a = get_argument(argc, argv, &i); + if (strcmp(a, "random") == 0) + start_position = (float) (rand() % 1000) / (float) 1000; + else { + char* result = a; + float f = strtof(a, &result); + + if (result == a) { + fprintf(stderr, "ERROR: Invalid argument '%s' for flag '--position'.\n", a); + return EXIT_FAILURE; + } else if (f > 1.0 || f < 0.0) { + fprintf(stderr, "ERROR: Number passed for flag '--position' must be between 0 and 1.\n"); + return EXIT_FAILURE; + } else { + start_position = f; + } + } + } else if ( strcmp(argv[i], "--idle-sleep") == 0 ) { const char *a = get_argument(argc, argv, &i);