allow setting of position at startup

This commit is contained in:
Virt 2025-04-15 11:16:47 +02:00
commit 049860f3d2
2 changed files with 32 additions and 1 deletions

View file

@ -22,6 +22,7 @@ wayneko \- Neko on Wayland but with phases
.OP \-\-currently awake|asleep|random .OP \-\-currently awake|asleep|random
.OP \-\-layer background|bottom|top|overlay .OP \-\-layer background|bottom|top|overlay
.OP \-\-output name .OP \-\-output name
.OP \-\-position float
.OP \-\-survive\-close .OP \-\-survive\-close
.YS .YS
. .
@ -111,6 +112,14 @@ exist. Defaults to the currently selected monitor.
.RE .RE
. .
.P .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 \fB\-\-survive\-close\fR
.RS .RS
If this flag is used, wayneko will recreate the surface after it has been closed. If this flag is used, wayneko will recreate the surface after it has been closed.

View file

@ -37,6 +37,7 @@ const char usage[] =
" --sleep-phase seconds-seconds\n" " --sleep-phase seconds-seconds\n"
" --awake-phase seconds-seconds\n" " --awake-phase seconds-seconds\n"
" --currently awake|asleep|random\n" " --currently awake|asleep|random\n"
" --position float\n"
" --layer background|bottom|top|overlay\n" " --layer background|bottom|top|overlay\n"
" --output name\n" " --output name\n"
" --survive-close\n" " --survive-close\n"
@ -82,6 +83,7 @@ enum Type type = PLAIN;
bool follow_pointer = false; // TODO: implement this again bool follow_pointer = false; // TODO: implement this again
bool recreate_surface_on_close = false; bool recreate_surface_on_close = false;
enum zwlr_layer_shell_v1_layer layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; 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; struct ext_idle_notifier_v1 *idle_notifier = NULL;
uint32_t neko_idle_timeout_ms = 180000; /* 3 minutes. */ 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. */ /* Center neko on first configure. */
if (!surface.configured) 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; surface.prev_neko_x = surface.neko_x;
} }
@ -1485,6 +1487,26 @@ int main (int argc, char *argv[])
else if ( strcmp(a, "overlay") == 0 ) else if ( strcmp(a, "overlay") == 0 )
layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; 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 ) else if ( strcmp(argv[i], "--idle-sleep") == 0 )
{ {
const char *a = get_argument(argc, argv, &i); const char *a = get_argument(argc, argv, &i);