Skip to content

Commit ce71b7e

Browse files
committed
Fix initial rendering and mouse scaling
This commit adds first-run damage marking to ensure screen content is rendered on startup instead of remaining blank until user interaction. For mouse coordinate scaling, this scales EV_ABS coordinates from the device range (0-32767) to actual screen resolution for correct cursor positioning in touchscreen environments. Close #62
1 parent 16193dc commit ce71b7e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

backend/fbdev.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ static bool twin_fbdev_work(void *closure)
201201
twin_fbdev_t *tx = PRIV(closure);
202202
twin_screen_t *screen = SCREEN(closure);
203203

204+
/* Mark entire screen as damaged on first run to ensure initial rendering.
205+
* This is necessary because the screen content is not automatically
206+
* rendered when the application starts.
207+
*/
208+
static bool first_run = true;
209+
if (first_run) {
210+
first_run = false;
211+
twin_screen_damage(screen, 0, 0, screen->width, screen->height);
212+
}
213+
204214
if (tx->vt_active && (tx->fb_base != MAP_FAILED)) {
205215
/* Unmap the fbdev */
206216
munmap(tx->fb_base, tx->fb_len);

backend/linux_input.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,21 @@ static void twin_linux_input_events(struct input_event *ev,
7979
}
8080
break;
8181
case EV_ABS:
82+
/* Scale absolute coordinates to screen resolution.
83+
* Most touchscreens and absolute pointing devices report coordinates
84+
* in the range 0-32767. We need to scale these to match the screen
85+
* dimensions for correct cursor positioning.
86+
*/
8287
if (ev->code == ABS_X) {
83-
tm->x = ev->value;
88+
tm->x = ((int64_t) ev->value * tm->screen->width) / 32767;
8489
check_mouse_bounds(tm);
8590
tev.kind = TwinEventMotion;
8691
tev.u.pointer.screen_x = tm->x;
8792
tev.u.pointer.screen_y = tm->y;
8893
tev.u.pointer.button = tm->btns;
8994
twin_screen_dispatch(tm->screen, &tev);
9095
} else if (ev->code == ABS_Y) {
91-
tm->y = ev->value;
96+
tm->y = ((int64_t) ev->value * tm->screen->height) / 32767;
9297
check_mouse_bounds(tm);
9398
tev.kind = TwinEventMotion;
9499
tev.u.pointer.screen_x = tm->x;

0 commit comments

Comments
 (0)