load script after initial registry burst

This makes the logic of installing idle handlers and layout handlers a bit
cleaner and allows us to send wayland request from the script in the future.
This commit is contained in:
Leon Henrik Plickat
2024-01-07 06:24:23 +01:00
parent 732c1adb55
commit 153b5e0858
11 changed files with 304 additions and 152 deletions

View File

@@ -5,6 +5,7 @@
#include <string.h>
#include "riverguile.h"
#include "output.h"
#include "seat.h"
/**
@@ -75,19 +76,58 @@ static SCM install_handler (SCM key, SCM proc)
}
if ( scm_is_eq(scm_from_utf8_symbol("layout-demand"), key) == 1 )
{
if ( context.layout_manager == NULL )
{
fputs("ERROR: Trying to install layout-demand handler but server does not support river-layout-v3.\n", stderr);
fputs("INFO: This error is not fatal, but means riverguile will not provide any layout.\n", stderr);
return SCM_BOOL_F;
}
context.mode = CONTINOUS;
context.layout_demand_handler = proc;
/* Configure all outputs to expose layouts. */
struct Output *output;
wl_list_for_each(output, &context.outputs, link)
output_configure_layout(output);
}
else if ( scm_is_eq(scm_from_utf8_symbol("user-command"), key) == 1)
{
/* No need to check if the interface exists since it's only
* used when a layout-demand handler is configured.
*/
context.user_command_handler = proc;
}
else if ( scm_is_eq(scm_from_utf8_symbol("exit"), key) == 1)
context.exit_handler = proc;
else if ( scm_is_true(scm_string_prefix_p(scm_from_utf8_string("idle:"), scm_symbol_to_string(key),
scm_from_int(0), scm_from_int(5),
scm_from_int(0), scm_string_length(scm_symbol_to_string(key)))) == 1 )
{
if ( context.idle_notifier == NULL )
{
fputs("ERROR: Trying to install idle handler but server does not support ext-idle-notify-v1.\n", stderr);
fputs("INFO: This error is not fatal, but means riverguile will not be able to call any idle handler.\n", stderr);
return SCM_BOOL_F;
}
if ( wl_list_length(&context.seats) == 0 )
{
fputs("ERROR: Trying to install idle handler but server did not advertise any seats.\n", stderr);
fputs("INFO: This error is not fatal, but means riverguile will not be able to call any idle handler.\n", stderr);
return SCM_BOOL_F;
}
context.mode = CONTINOUS;
/* Just use the first seat. River only supports a single one anyway. */
struct Seat *seat;
wl_list_for_each(seat, &context.seats, link)
break;
uint32_t ms = extract_ms_from_idle_key(key);
struct Idle *idle = calloc(1, sizeof(struct Idle));
if ( idle == NULL )
if (!seat_add_idle(seat, proc, ms))
{
scm_error_scm(
scm_from_utf8_symbol("memory-allocation-error"),
@@ -98,10 +138,6 @@ static SCM install_handler (SCM key, SCM proc)
);
return SCM_UNSPECIFIED;
}
idle->ms = ms;
idle->handler = proc;
wl_list_insert(&context.unconfigured_idles, &idle->link);
}
else
{
@@ -148,13 +184,13 @@ void *load_script (void *data)
if ( call_result == NULL )
return (void *)"ERROR: Fatal error while loading layout script.\n";
if ( context.layout_demand_handler == NULL )
return (void *)"ERROR: No layout demand handler installed.\n";
/* Checked in the installer functions. */
assert(scm_is_true(scm_procedure_p(context.layout_demand_handler)) == 1);
if ( context.layout_demand_handler != NULL )
assert(scm_is_true(scm_procedure_p(context.layout_demand_handler)) == 1);
if ( context.user_command_handler != NULL )
assert(scm_is_true(scm_procedure_p(context.user_command_handler)) == 1);
if ( context.exit_handler != NULL )
assert(scm_is_true(scm_procedure_p(context.exit_handler)) == 1);
return NULL;
}