mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-03 07:15:29 -04:00
term: consolidate shutdown related state into an anonymous struct
This commit is contained in:
parent
c23bff4189
commit
03f952cf4d
5 changed files with 48 additions and 39 deletions
2
input.c
2
input.c
|
|
@ -1471,7 +1471,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
|
||||||
case TERM_SURF_BUTTON_MINIMIZE:
|
case TERM_SURF_BUTTON_MINIMIZE:
|
||||||
case TERM_SURF_BUTTON_MAXIMIZE:
|
case TERM_SURF_BUTTON_MAXIMIZE:
|
||||||
case TERM_SURF_BUTTON_CLOSE:
|
case TERM_SURF_BUTTON_CLOSE:
|
||||||
if (old_moused->is_shutting_down)
|
if (old_moused->shutdown.in_progress)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
render_refresh_csd(old_moused);
|
render_refresh_csd(old_moused);
|
||||||
|
|
|
||||||
6
render.c
6
render.c
|
|
@ -2340,7 +2340,7 @@ dirty_cursor(struct terminal *term)
|
||||||
static void
|
static void
|
||||||
grid_render(struct terminal *term)
|
grid_render(struct terminal *term)
|
||||||
{
|
{
|
||||||
if (term->is_shutting_down)
|
if (term->shutdown.in_progress)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct timeval start_time, start_double_buffering = {0}, stop_double_buffering = {0};
|
struct timeval start_time, start_double_buffering = {0}, stop_double_buffering = {0};
|
||||||
|
|
@ -3318,7 +3318,7 @@ send_dimensions_to_client(struct terminal *term)
|
||||||
static bool
|
static bool
|
||||||
maybe_resize(struct terminal *term, int width, int height, bool force)
|
maybe_resize(struct terminal *term, int width, int height, bool force)
|
||||||
{
|
{
|
||||||
if (term->is_shutting_down)
|
if (term->shutdown.in_progress)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!term->window->is_configured)
|
if (!term->window->is_configured)
|
||||||
|
|
@ -3640,7 +3640,7 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data)
|
||||||
tll_foreach(renderer->wayl->terms, it) {
|
tll_foreach(renderer->wayl->terms, it) {
|
||||||
struct terminal *term = it->item;
|
struct terminal *term = it->item;
|
||||||
|
|
||||||
if (unlikely(term->is_shutting_down || !term->window->is_configured))
|
if (unlikely(term->shutdown.in_progress || !term->window->is_configured))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool grid = term->render.refresh.grid;
|
bool grid = term->render.refresh.grid;
|
||||||
|
|
|
||||||
6
server.c
6
server.c
|
|
@ -334,9 +334,11 @@ shutdown:
|
||||||
fdm_del(fdm, fd);
|
fdm_del(fdm, fd);
|
||||||
client->fd = -1;
|
client->fd = -1;
|
||||||
|
|
||||||
if (client->instance != NULL && !client->instance->terminal->is_shutting_down)
|
if (client->instance != NULL &&
|
||||||
|
!client->instance->terminal->shutdown.in_progress)
|
||||||
|
{
|
||||||
term_shutdown(client->instance->terminal);
|
term_shutdown(client->instance->terminal);
|
||||||
else
|
} else
|
||||||
client_destroy(client);
|
client_destroy(client);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
58
terminal.c
58
terminal.c
|
|
@ -19,7 +19,7 @@
|
||||||
#include <xdg-shell.h>
|
#include <xdg-shell.h>
|
||||||
|
|
||||||
#define LOG_MODULE "terminal"
|
#define LOG_MODULE "terminal"
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 1
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include "async.h"
|
#include "async.h"
|
||||||
|
|
@ -1166,9 +1166,11 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
.max_width = SIXEL_MAX_WIDTH,
|
.max_width = SIXEL_MAX_WIDTH,
|
||||||
.max_height = SIXEL_MAX_HEIGHT,
|
.max_height = SIXEL_MAX_HEIGHT,
|
||||||
},
|
},
|
||||||
.slave_terminate_timeout_fd = -1,
|
.shutdown = {
|
||||||
.shutdown_cb = shutdown_cb,
|
.terminate_timeout_fd = -1,
|
||||||
.shutdown_data = shutdown_data,
|
.cb = shutdown_cb,
|
||||||
|
.cb_data = shutdown_data,
|
||||||
|
},
|
||||||
.foot_exe = xstrdup(foot_exe),
|
.foot_exe = xstrdup(foot_exe),
|
||||||
.cwd = xstrdup(cwd),
|
.cwd = xstrdup(cwd),
|
||||||
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
|
|
@ -1243,7 +1245,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
return term;
|
return term;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
term->is_shutting_down = true;
|
term->shutdown.in_progress = true;
|
||||||
term_destroy(term);
|
term_destroy(term);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -1263,7 +1265,7 @@ void
|
||||||
term_window_configured(struct terminal *term)
|
term_window_configured(struct terminal *term)
|
||||||
{
|
{
|
||||||
/* Enable ptmx FDM callback */
|
/* Enable ptmx FDM callback */
|
||||||
if (!term->is_shutting_down) {
|
if (!term->shutdown.in_progress) {
|
||||||
xassert(term->window->is_configured);
|
xassert(term->window->is_configured);
|
||||||
fdm_add(term->fdm, term->ptmx, EPOLLIN, &fdm_ptmx, term);
|
fdm_add(term->fdm, term->ptmx, EPOLLIN, &fdm_ptmx, term);
|
||||||
}
|
}
|
||||||
|
|
@ -1336,10 +1338,11 @@ term_window_configured(struct terminal *term)
|
||||||
static void
|
static void
|
||||||
shutdown_maybe_done(struct terminal *term)
|
shutdown_maybe_done(struct terminal *term)
|
||||||
{
|
{
|
||||||
bool shutdown_done = term->window == NULL && term->slave_has_been_reaped;
|
bool shutdown_done =
|
||||||
|
term->window == NULL && term->shutdown.client_has_terminated;
|
||||||
|
|
||||||
LOG_DBG("window=%p, slave-has-been-reaped=%d --> %s",
|
LOG_DBG("window=%p, slave-has-been-reaped=%d --> %s",
|
||||||
(void *)term->window, term->slave_has_been_reaped,
|
(void *)term->window, term->shutdown.client_has_terminated,
|
||||||
(shutdown_done
|
(shutdown_done
|
||||||
? "shutdown done, calling term_destroy()"
|
? "shutdown done, calling term_destroy()"
|
||||||
: "no action"));
|
: "no action"));
|
||||||
|
|
@ -1347,8 +1350,8 @@ shutdown_maybe_done(struct terminal *term)
|
||||||
if (!shutdown_done)
|
if (!shutdown_done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void (*cb)(void *, int) = term->shutdown_cb;
|
void (*cb)(void *, int) = term->shutdown.cb;
|
||||||
void *cb_data = term->shutdown_data;
|
void *cb_data = term->shutdown.cb_data;
|
||||||
|
|
||||||
int exit_code = term_destroy(term);
|
int exit_code = term_destroy(term);
|
||||||
if (cb != NULL)
|
if (cb != NULL)
|
||||||
|
|
@ -1361,15 +1364,15 @@ fdm_client_terminated(struct reaper *reaper, pid_t pid, int status, void *data)
|
||||||
struct terminal *term = data;
|
struct terminal *term = data;
|
||||||
LOG_DBG("slave (PID=%u) died", pid);
|
LOG_DBG("slave (PID=%u) died", pid);
|
||||||
|
|
||||||
term->slave_has_been_reaped = true;
|
term->shutdown.client_has_terminated = true;
|
||||||
term->exit_status = status;
|
term->shutdown.exit_status = status;
|
||||||
|
|
||||||
if (term->slave_terminate_timeout_fd >= 0) {
|
if (term->shutdown.terminate_timeout_fd >= 0) {
|
||||||
fdm_del(term->fdm, term->slave_terminate_timeout_fd);
|
fdm_del(term->fdm, term->shutdown.terminate_timeout_fd);
|
||||||
term->slave_terminate_timeout_fd = -1;
|
term->shutdown.terminate_timeout_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term->is_shutting_down)
|
if (term->shutdown.in_progress)
|
||||||
shutdown_maybe_done(term);
|
shutdown_maybe_done(term);
|
||||||
else if (!term->conf->hold_at_exit)
|
else if (!term->conf->hold_at_exit)
|
||||||
term_shutdown(term);
|
term_shutdown(term);
|
||||||
|
|
@ -1418,7 +1421,7 @@ fdm_terminate_timeout(struct fdm *fdm, int fd, int events, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct terminal *term = data;
|
struct terminal *term = data;
|
||||||
xassert(!term->slave_has_been_reaped);
|
xassert(!term->shutdown.client_has_terminated);
|
||||||
|
|
||||||
LOG_DBG("slave (PID=%u) has not terminated, sending SIGKILL (%d)",
|
LOG_DBG("slave (PID=%u) has not terminated, sending SIGKILL (%d)",
|
||||||
term->slave, SIGKILL);
|
term->slave, SIGKILL);
|
||||||
|
|
@ -1430,10 +1433,10 @@ fdm_terminate_timeout(struct fdm *fdm, int fd, int events, void *data)
|
||||||
bool
|
bool
|
||||||
term_shutdown(struct terminal *term)
|
term_shutdown(struct terminal *term)
|
||||||
{
|
{
|
||||||
if (term->is_shutting_down)
|
if (term->shutdown.in_progress)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
term->is_shutting_down = true;
|
term->shutdown.in_progress = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close FDs then postpone self-destruction to the next poll
|
* Close FDs then postpone self-destruction to the next poll
|
||||||
|
|
@ -1456,7 +1459,7 @@ term_shutdown(struct terminal *term)
|
||||||
else
|
else
|
||||||
close(term->ptmx);
|
close(term->ptmx);
|
||||||
|
|
||||||
if (!term->slave_has_been_reaped) {
|
if (!term->shutdown.client_has_terminated) {
|
||||||
LOG_DBG("initiating asynchronous terminate of slave (PID=%u)",
|
LOG_DBG("initiating asynchronous terminate of slave (PID=%u)",
|
||||||
term->slave);
|
term->slave);
|
||||||
|
|
||||||
|
|
@ -1475,8 +1478,8 @@ term_shutdown(struct terminal *term)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
xassert(term->slave_terminate_timeout_fd < 0);
|
xassert(term->shutdown.terminate_timeout_fd < 0);
|
||||||
term->slave_terminate_timeout_fd = timeout_fd;
|
term->shutdown.terminate_timeout_fd = timeout_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
term->selection.auto_scroll.fd = -1;
|
term->selection.auto_scroll.fd = -1;
|
||||||
|
|
@ -1539,7 +1542,8 @@ term_destroy(struct terminal *term)
|
||||||
fdm_del(term->fdm, term->blink.fd);
|
fdm_del(term->fdm, term->blink.fd);
|
||||||
fdm_del(term->fdm, term->flash.fd);
|
fdm_del(term->fdm, term->flash.fd);
|
||||||
fdm_del(term->fdm, term->ptmx);
|
fdm_del(term->fdm, term->ptmx);
|
||||||
xassert(term->slave_terminate_timeout_fd < 0);
|
if (term->shutdown.terminate_timeout_fd >= 0)
|
||||||
|
fdm_del(term->fdm, term->shutdown.terminate_timeout_fd);
|
||||||
|
|
||||||
if (term->window != NULL) {
|
if (term->window != NULL) {
|
||||||
wayl_win_destroy(term->window);
|
wayl_win_destroy(term->window);
|
||||||
|
|
@ -1635,8 +1639,8 @@ term_destroy(struct terminal *term)
|
||||||
|
|
||||||
int exit_status;
|
int exit_status;
|
||||||
|
|
||||||
if (term->slave_has_been_reaped)
|
if (term->shutdown.client_has_terminated)
|
||||||
exit_status = term->exit_status;
|
exit_status = term->shutdown.exit_status;
|
||||||
else {
|
else {
|
||||||
LOG_DBG("initiating blocking terminate of slave (PID=%u)",
|
LOG_DBG("initiating blocking terminate of slave (PID=%u)",
|
||||||
term->slave);
|
term->slave);
|
||||||
|
|
@ -2448,11 +2452,11 @@ void
|
||||||
term_cursor_blink_update(struct terminal *term)
|
term_cursor_blink_update(struct terminal *term)
|
||||||
{
|
{
|
||||||
bool enable = term->cursor_blink.decset || term->cursor_blink.deccsusr;
|
bool enable = term->cursor_blink.decset || term->cursor_blink.deccsusr;
|
||||||
bool activate = !term->is_shutting_down && enable && term->kbd_focus;
|
bool activate = !term->shutdown.in_progress && enable && term->kbd_focus;
|
||||||
|
|
||||||
LOG_DBG("decset=%d, deccsrusr=%d, focus=%d, shutting-down=%d, enable=%d, activate=%d",
|
LOG_DBG("decset=%d, deccsrusr=%d, focus=%d, shutting-down=%d, enable=%d, activate=%d",
|
||||||
term->cursor_blink.decset, term->cursor_blink.deccsusr,
|
term->cursor_blink.decset, term->cursor_blink.deccsusr,
|
||||||
term->kbd_focus, term->is_shutting_down,
|
term->kbd_focus, term->shutdown.in_progress,
|
||||||
enable, activate);
|
enable, activate);
|
||||||
|
|
||||||
if (activate && term->cursor_blink.fd < 0) {
|
if (activate && term->cursor_blink.fd < 0) {
|
||||||
|
|
|
||||||
15
terminal.h
15
terminal.h
|
|
@ -593,12 +593,15 @@ struct terminal {
|
||||||
bool ime_enabled;
|
bool ime_enabled;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool is_shutting_down;
|
struct {
|
||||||
bool slave_has_been_reaped;
|
bool in_progress;
|
||||||
int slave_terminate_timeout_fd;
|
bool client_has_terminated;
|
||||||
int exit_status;
|
int terminate_timeout_fd;
|
||||||
void (*shutdown_cb)(void *data, int exit_code);
|
int exit_status;
|
||||||
void *shutdown_data;
|
|
||||||
|
void (*cb)(void *data, int exit_code);
|
||||||
|
void *cb_data;
|
||||||
|
} shutdown;
|
||||||
|
|
||||||
char *foot_exe;
|
char *foot_exe;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue