From owner-dev-commits-src-main@freebsd.org Thu Dec 31 17:10:18 2020 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 586A44C8751; Thu, 31 Dec 2020 17:10:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D6F5k25MTz3JWF; Thu, 31 Dec 2020 17:10:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3ACA313E51; Thu, 31 Dec 2020 17:10:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BVHAIH8086988; Thu, 31 Dec 2020 17:10:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BVHAIOI086982; Thu, 31 Dec 2020 17:10:18 GMT (envelope-from git) Date: Thu, 31 Dec 2020 17:10:18 GMT Message-Id: <202012311710.0BVHAIOI086982@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: be4663433724 - main - vt: more carefully handle vt_allocate_keyboard grab work MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: be46634337248029333a434c235c8424279b30b4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "Commit messages for the main branch of the src repository." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Dec 2020 17:10:18 -0000 The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=be46634337248029333a434c235c8424279b30b4 commit be46634337248029333a434c235c8424279b30b4 Author: Kyle Evans AuthorDate: 2020-12-31 16:45:41 +0000 Commit: Kyle Evans CommitDate: 2020-12-31 17:10:11 +0000 vt: more carefully handle vt_allocate_keyboard grab work vt_allocate_keyboard only needs to unwind the effects of keyboard-grabbing, rather than any associated vt window action that may have also happened. Split out the bits that do the keyboard work into *_noswitch equivalents, and use those in keyboard allocation. This will be less error-prone when a later change will offer up different window state behavior when the console is ungrabbed. Reviewed by: ray Differential Revision: https://reviews.freebsd.org/D27110 --- sys/dev/vt/vt_core.c | 79 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index f840f7ba37f6..c273b703de93 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -63,6 +63,9 @@ __FBSDID("$FreeBSD$"); #include #endif +static int vtterm_cngrab_noswitch(struct vt_device *, struct vt_window *); +static int vtterm_cnungrab_noswitch(struct vt_device *, struct vt_window *); + static tc_bell_t vtterm_bell; static tc_cursor_t vtterm_cursor; static tc_putchar_t vtterm_putchar; @@ -1030,7 +1033,7 @@ vt_allocate_keyboard(struct vt_device *vd) if (vd->vd_curwindow == &vt_conswindow) { grabbed = vd->vd_curwindow->vw_grabbed; for (i = 0; i < grabbed; ++i) - vtterm_cnungrab(vd->vd_curwindow->vw_terminal); + vtterm_cnungrab_noswitch(vd, vd->vd_curwindow); } idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd); @@ -1068,7 +1071,7 @@ vt_allocate_keyboard(struct vt_device *vd) if (vd->vd_curwindow == &vt_conswindow) { for (i = 0; i < grabbed; ++i) - vtterm_cngrab(vd->vd_curwindow->vw_terminal); + vtterm_cngrab_noswitch(vd, vd->vd_curwindow); } return (idx0); @@ -1740,24 +1743,24 @@ vtterm_cngetc(struct terminal *tm) return (-1); } -static void -vtterm_cngrab(struct terminal *tm) +/* + * These two do most of what we want to do in vtterm_cnungrab, but without + * actually switching windows. This is necessary for, e.g., + * vt_allocate_keyboard() to get the current keyboard into the state it needs to + * be in without damaging the device's window state. + * + * Both return the current grab count, though it's only used in vtterm_cnungrab. + */ +static int +vtterm_cngrab_noswitch(struct vt_device *vd, struct vt_window *vw) { - struct vt_device *vd; - struct vt_window *vw; keyboard_t *kbd; - vw = tm->tm_softc; - vd = vw->vw_device; - - if (!cold) - vt_window_switch(vw); + if (vw->vw_grabbed++ > 0) + return (vw->vw_grabbed); if ((kbd = vd->vd_keyboard) == NULL) - return; - - if (vw->vw_grabbed++ > 0) - return; + return (1); /* * Make sure the keyboard is accessible even when the kbd device @@ -1771,29 +1774,57 @@ vtterm_cngrab(struct terminal *tm) vt_update_kbd_mode(vw, kbd); kbdd_poll(kbd, TRUE); + return (1); +} + +static int +vtterm_cnungrab_noswitch(struct vt_device *vd, struct vt_window *vw) +{ + keyboard_t *kbd; + + if (--vw->vw_grabbed > 0) + return (vw->vw_grabbed); + + if ((kbd = vd->vd_keyboard) == NULL) + return (0); + + kbdd_poll(kbd, FALSE); + + vw->vw_kbdmode = vw->vw_prev_kbdmode; + vt_update_kbd_mode(vw, kbd); + kbdd_disable(kbd); + return (0); } static void -vtterm_cnungrab(struct terminal *tm) +vtterm_cngrab(struct terminal *tm) { struct vt_device *vd; struct vt_window *vw; - keyboard_t *kbd; vw = tm->tm_softc; vd = vw->vw_device; - if ((kbd = vd->vd_keyboard) == NULL) - return; - if (--vw->vw_grabbed > 0) + if (!cold) + vt_window_switch(vw); + + vtterm_cngrab_noswitch(vd, vw); +} + +static void +vtterm_cnungrab(struct terminal *tm) +{ + struct vt_device *vd; + struct vt_window *vw; + + vw = tm->tm_softc; + vd = vw->vw_device; + + if (vtterm_cnungrab_noswitch(vd, vw) != 0) return; - kbdd_poll(kbd, FALSE); - vw->vw_kbdmode = vw->vw_prev_kbdmode; - vt_update_kbd_mode(vw, kbd); - kbdd_disable(kbd); } static void