From f18b3ce0b7be0b24a743ec59077ca8e7929a353c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Fri, 24 Nov 2023 18:30:35 +0100 Subject: [PATCH] vt(4): Always call vt_window_switch() in vtterm_cnungrab() [Why] This ensures that vtterm_cnungrab() is the mirror of vtterm_cngrab(). And the latter always call vt_window_switch() and thus the backend's vd_postswitch(). This makes sure that whatever the backend did during vtterm_cngrab(), it can undo it during vtterm_cnungrab(). Reviewed by: manu Approved by: manu Differential Revision: https://reviews.freebsd.org/D42752 --- sys/dev/vt/vt_core.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index bfd99665be4ade..4a1031f1aa69f5 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -2046,7 +2046,7 @@ static void vtterm_cnungrab(struct terminal *tm) { struct vt_device *vd; - struct vt_window *vw; + struct vt_window *vw, *grabwindow; vw = tm->tm_softc; vd = vw->vw_device; @@ -2055,10 +2055,19 @@ vtterm_cnungrab(struct terminal *tm) if (vtterm_cnungrab_noswitch(vd, vw) != 0) return; - if (!cold && vd->vd_grabwindow != vw) - vt_window_switch(vd->vd_grabwindow); - + /* + * We set `vd_grabwindow` to NULL before calling vt_window_switch() + * because it allows the underlying vt(4) backend to distinguish a + * "grab" from an "ungrab" of the console. + * + * This is used by `vt_drmfb` in drm-kmod to call either + * fb_debug_enter() or fb_debug_leave() appropriately. + */ + grabwindow = vd->vd_grabwindow; vd->vd_grabwindow = NULL; + + if (!cold) + vt_window_switch(grabwindow); } static void