diff --git a/backend/fbdev.c b/backend/fbdev.c index 4206d0c4..95698c36 100644 --- a/backend/fbdev.c +++ b/backend/fbdev.c @@ -152,7 +152,7 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx) break; default: log_error("Unsupported bits per pixel: %d", tx->fb_var.bits_per_pixel); - break; + return false; } /* Read unchangable information of the framebuffer */ @@ -189,7 +189,7 @@ static bool twin_fbdev_update_damage(void *closure) twin_fbdev_t *tx = PRIV(closure); twin_screen_t *screen = SCREEN(closure); - if (!tx->vt_active && (tx->fb_base == MAP_FAILED) && + if (!tx->vt_active && (tx->fb_base != MAP_FAILED) && twin_screen_damaged(screen)) twin_screen_update(screen); @@ -302,6 +302,9 @@ twin_context_t *twin_fbdev_init(int width, int height) if (tx->fb_base != MAP_FAILED) munmap(tx->fb_base, tx->fb_len); bail_vt_fd: + /* Restore VT mode before closing */ + ioctl(tx->vt_fd, VT_SETMODE, &tx->old_vtm); + ioctl(tx->vt_fd, KDSETMODE, KD_TEXT); close(tx->vt_fd); bail_fb_fd: close(tx->fb_fd); @@ -325,7 +328,13 @@ static void twin_fbdev_exit(twin_context_t *ctx) return; twin_fbdev_t *tx = PRIV(ctx); - twin_vt_mode(tx->vt_fd, KD_TEXT); + + /* Restore VT mode before cleanup */ + if (tx->vt_fd >= 0) { + ioctl(tx->vt_fd, VT_SETMODE, &tx->old_vtm); + ioctl(tx->vt_fd, KDSETMODE, KD_TEXT); + } + munmap(tx->fb_base, tx->fb_len); twin_linux_input_destroy(tx->input); close(tx->vt_fd); @@ -334,6 +343,15 @@ static void twin_fbdev_exit(twin_context_t *ctx) free(ctx); } +/* Poll function for fbdev backend + * The fbdev backend uses linux_input background thread for event handling, + * so this poll function just returns true to continue the main loop. + */ +static bool twin_fbdev_poll(twin_context_t *ctx maybe_unused) +{ + return true; +} + /* Start function for fbdev backend * Note: fbdev uses Linux input system with background thread for events, * so we use the standard dispatcher for work queue and timeout processing. @@ -355,6 +373,7 @@ static void twin_fbdev_start(twin_context_t *ctx, const twin_backend_t g_twin_backend = { .init = twin_fbdev_init, .configure = twin_fbdev_configure, + .poll = twin_fbdev_poll, .start = twin_fbdev_start, .exit = twin_fbdev_exit, };