add exit handler

This commit is contained in:
Leon Henrik Plickat
2024-01-06 23:55:10 +01:00
parent 2ccbfb2283
commit 732c1adb55
8 changed files with 48 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ OBJ=src/riverguile.o $\
src/call-layout-demand-handler.o $\ src/call-layout-demand-handler.o $\
src/call-user-command-handler.o $\ src/call-user-command-handler.o $\
src/call-idle-handler.o $\ src/call-idle-handler.o $\
src/call-exit-handler.o $\
src/load-script.o $\ src/load-script.o $\
protocol/river-layout-v3.o $\ protocol/river-layout-v3.o $\
protocol/ext-idle-notify-v1.o protocol/ext-idle-notify-v1.o

View File

@@ -78,6 +78,9 @@ of the system being idle is over.
Multiple idle handlers can be installed. Multiple idle handlers can be installed.
Note: All idle events relate to the first advetised seat. Note: All idle events relate to the first advetised seat.
As of now, river only supports a single seat anyway. As of now, river only supports a single seat anyway.
.P
The key \fBexit\fR installs a handler which is called when riverguile exits.
The procedure takes no arguments.
. .
. .
.SH EXAMPLE .SH EXAMPLE

29
src/call-exit-handler.c Normal file
View File

@@ -0,0 +1,29 @@
#include <libguile.h>
#include <assert.h>
#include "riverguile.h"
static void *call_exit_handler_inner (void *data)
{
assert(data == NULL);
return scm_call_0(context.exit_handler);
}
void *call_exit_handler (void)
{
assert(context.exit_handler != NULL);
/* Continuation barrier causes stack unwind on exceptions (i.e. errors
* in the user defined exit handler) to stop here. Otherwise the entire
* stack created by scm_with_guile() would be unwound. This makes
* responding to exceptions nicer.
*/
SCM call_result = scm_c_with_continuation_barrier(
call_exit_handler_inner, NULL
);
if ( call_result == NULL )
return (void *)"ERROR: An exception occured while calling the exit handler.\n";
return NULL;
}

6
src/call-exit-handler.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef RIVERGUILE_CALL_EXIT_HANDLER_H
#define RIVERGUILE_CALL_EXIT_HANDLER_H
void *call_exit_handler (void);
#endif

View File

@@ -21,7 +21,7 @@ static void *call_idle_handler_inner (void *data)
void *call_idle_handler (void *data) void *call_idle_handler (void *data)
{ {
/* Continuation barrier causes stack unwind on exceptions (i.e. errors /* Continuation barrier causes stack unwind on exceptions (i.e. errors
* in the user defined ide handler) to stop here. Otherwise the entire * in the user defined idle handler) to stop here. Otherwise the entire
* stack created by scm_with_guile() would be unwound. This makes * stack created by scm_with_guile() would be unwound. This makes
* responding to exceptions nicer. * responding to exceptions nicer.
*/ */
@@ -30,7 +30,7 @@ void *call_idle_handler (void *data)
); );
if ( call_result == NULL ) if ( call_result == NULL )
return (void *)"ERROR: An exception occured while calling the user-command handler.\n"; return (void *)"ERROR: An exception occured while calling the idle handler.\n";
return NULL; return NULL;
} }

View File

@@ -78,6 +78,8 @@ static SCM install_handler (SCM key, SCM proc)
context.layout_demand_handler = proc; context.layout_demand_handler = proc;
else if ( scm_is_eq(scm_from_utf8_symbol("user-command"), key) == 1) else if ( scm_is_eq(scm_from_utf8_symbol("user-command"), key) == 1)
context.user_command_handler = proc; 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), 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_from_int(5),
scm_from_int(0), scm_string_length(scm_symbol_to_string(key)))) == 1 ) scm_from_int(0), scm_string_length(scm_symbol_to_string(key)))) == 1 )

View File

@@ -22,6 +22,7 @@
#include "ext-idle-notify-v1.h" #include "ext-idle-notify-v1.h"
#include "load-script.h" #include "load-script.h"
#include "call-exit-handler.h"
#include "riverguile.h" #include "riverguile.h"
#include "output.h" #include "output.h"
#include "seat.h" #include "seat.h"
@@ -346,6 +347,9 @@ int main(int argc, char *argv[])
if ( setjmp(skip_main_loop) == 0 ) if ( setjmp(skip_main_loop) == 0 )
while ( context.loop && wl_display_dispatch(context.wl_display) > 0 ); while ( context.loop && wl_display_dispatch(context.wl_display) > 0 );
if ( context.exit_handler != NULL )
call_exit_handler();
struct Idle *idle, *tmp_i; struct Idle *idle, *tmp_i;
wl_list_for_each_safe(idle, tmp_i, &context.unconfigured_idles, link) wl_list_for_each_safe(idle, tmp_i, &context.unconfigured_idles, link)
{ {

View File

@@ -11,6 +11,7 @@ struct Context
{ {
SCM layout_demand_handler; SCM layout_demand_handler;
SCM user_command_handler; SCM user_command_handler;
SCM exit_handler;
bool loop; bool loop;
int ret; int ret;