Skip to content

Commit 16193dc

Browse files
authored
Merge pull request #139 from sysprog21/fix-fbdev
Fix rendering and VT management issues in fbdev
2 parents 26e8cab + 1758030 commit 16193dc

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

backend/fbdev.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx)
152152
break;
153153
default:
154154
log_error("Unsupported bits per pixel: %d", tx->fb_var.bits_per_pixel);
155-
break;
155+
return false;
156156
}
157157

158158
/* Read unchangable information of the framebuffer */
@@ -189,7 +189,7 @@ static bool twin_fbdev_update_damage(void *closure)
189189
twin_fbdev_t *tx = PRIV(closure);
190190
twin_screen_t *screen = SCREEN(closure);
191191

192-
if (!tx->vt_active && (tx->fb_base == MAP_FAILED) &&
192+
if (!tx->vt_active && (tx->fb_base != MAP_FAILED) &&
193193
twin_screen_damaged(screen))
194194
twin_screen_update(screen);
195195

@@ -302,6 +302,9 @@ twin_context_t *twin_fbdev_init(int width, int height)
302302
if (tx->fb_base != MAP_FAILED)
303303
munmap(tx->fb_base, tx->fb_len);
304304
bail_vt_fd:
305+
/* Restore VT mode before closing */
306+
ioctl(tx->vt_fd, VT_SETMODE, &tx->old_vtm);
307+
ioctl(tx->vt_fd, KDSETMODE, KD_TEXT);
305308
close(tx->vt_fd);
306309
bail_fb_fd:
307310
close(tx->fb_fd);
@@ -325,7 +328,13 @@ static void twin_fbdev_exit(twin_context_t *ctx)
325328
return;
326329

327330
twin_fbdev_t *tx = PRIV(ctx);
328-
twin_vt_mode(tx->vt_fd, KD_TEXT);
331+
332+
/* Restore VT mode before cleanup */
333+
if (tx->vt_fd >= 0) {
334+
ioctl(tx->vt_fd, VT_SETMODE, &tx->old_vtm);
335+
ioctl(tx->vt_fd, KDSETMODE, KD_TEXT);
336+
}
337+
329338
munmap(tx->fb_base, tx->fb_len);
330339
twin_linux_input_destroy(tx->input);
331340
close(tx->vt_fd);
@@ -334,6 +343,15 @@ static void twin_fbdev_exit(twin_context_t *ctx)
334343
free(ctx);
335344
}
336345

346+
/* Poll function for fbdev backend
347+
* The fbdev backend uses linux_input background thread for event handling,
348+
* so this poll function just returns true to continue the main loop.
349+
*/
350+
static bool twin_fbdev_poll(twin_context_t *ctx maybe_unused)
351+
{
352+
return true;
353+
}
354+
337355
/* Start function for fbdev backend
338356
* Note: fbdev uses Linux input system with background thread for events,
339357
* 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,
355373
const twin_backend_t g_twin_backend = {
356374
.init = twin_fbdev_init,
357375
.configure = twin_fbdev_configure,
376+
.poll = twin_fbdev_poll,
358377
.start = twin_fbdev_start,
359378
.exit = twin_fbdev_exit,
360379
};

0 commit comments

Comments
 (0)