diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2024-11-06 17:14:04 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2024-11-06 17:14:04 +0000 |
commit | 03e298a20194e6e35f3fd1a58fbb9c3eab892504 (patch) | |
tree | f53fe6f870d6a32bbc5d45a64e5213606e8ccf23 /usr.sbin/wsconscfg | |
parent | 01329a5aeec53e7f3a4179e30bf02b4a236ce365 (diff) |
Add -g option to get the index of the current virtual terminal.
This can help scripts using wsconsctl display.focus to perform vt switches.
From NetBSD via Sergiy Kopchalyuk.
Diffstat (limited to 'usr.sbin/wsconscfg')
-rw-r--r-- | usr.sbin/wsconscfg/wsconscfg.8 | 14 | ||||
-rw-r--r-- | usr.sbin/wsconscfg/wsconscfg.c | 25 |
2 files changed, 29 insertions, 10 deletions
diff --git a/usr.sbin/wsconscfg/wsconscfg.8 b/usr.sbin/wsconscfg/wsconscfg.8 index 731fc2bf3fd..f6d08dc57e4 100644 --- a/usr.sbin/wsconscfg/wsconscfg.8 +++ b/usr.sbin/wsconscfg/wsconscfg.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: wsconscfg.8,v 1.20 2010/07/01 02:46:06 maja Exp $ +.\" $OpenBSD: wsconscfg.8,v 1.21 2024/11/06 17:14:03 miod Exp $ .\" $NetBSD: wsconscfg.8,v 1.5 1999/05/15 14:45:06 drochner Exp $ .\" .\" Copyright (c) 1999 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 1 2010 $ +.Dd $Mdocdate: November 6 2024 $ .Dt WSCONSCFG 8 .Os .Sh NAME @@ -33,7 +33,7 @@ .Nd configure virtual terminals on a wscons display .Sh SYNOPSIS .Nm wsconscfg -.Op Fl dFkm +.Op Fl dFgkm .Op Fl e Ar emul .Op Fl f Ar ctldev .Op Fl t Ar type @@ -41,7 +41,7 @@ .Sh DESCRIPTION The .Nm -tool allows for the creation and removal of virtual terminals +tool allows for the viewing, creation and removal of virtual terminals on display devices controlled by the wscons terminal framework, as long as the underlying display hardware driver supports multiple screens. Furthermore, it controls the assignment of keyboards to displays. @@ -95,6 +95,12 @@ even if it is in use by a userspace program. Specify the control device of the wscons display to operate on. The default is .Pa /dev/ttyCcfg . +.It Fl g +Print the index of the virtual terminal specified by +.Ar index . +If the +.Ar index +argument is omitted, the index of the current virtual terminal is printed. .It Fl k Do keyboard related operations instead of virtual screen configuration. Without other flags, a keyboard will be attached to the display device. diff --git a/usr.sbin/wsconscfg/wsconscfg.c b/usr.sbin/wsconscfg/wsconscfg.c index 4b52025e312..576b999dbe8 100644 --- a/usr.sbin/wsconscfg/wsconscfg.c +++ b/usr.sbin/wsconscfg/wsconscfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconscfg.c,v 1.18 2022/12/04 23:50:51 cheloha Exp $ */ +/* $OpenBSD: wsconscfg.c,v 1.19 2024/11/06 17:14:03 miod Exp $ */ /* $NetBSD: wsconscfg.c,v 1.4 1999/07/29 18:24:10 augustss Exp $ */ /* @@ -52,33 +52,38 @@ usage(void) extern char *__progname; (void)fprintf(stderr, - "usage: %s [-dFkm] [-e emul] [-f ctldev] [-t type] index\n", + "usage: %s [-dFgkm] [-e emul] [-f ctldev] [-t type] index\n", __progname); exit(1); } + int main(int argc, char *argv[]) { char *wsdev; - int c, delete, kbd, idx, wsfd, res, mux; + int c, delete, get, kbd, idx, wsfd, res, mux; struct wsdisplay_addscreendata asd; struct wsdisplay_delscreendata dsd; struct wsmux_device wmd; wsdev = DEFDEV; delete = 0; + get = 0; kbd = 0; mux = 0; asd.screentype[0] = 0; asd.emul[0] = 0; dsd.flags = 0; - while ((c = getopt(argc, argv, "f:dkmt:e:F")) != -1) { + while ((c = getopt(argc, argv, "f:dgkmt:e:F")) != -1) { switch (c) { case 'f': wsdev = optarg; break; + case 'g': + get = 1; + break; case 'd': delete = 1; break; @@ -106,14 +111,15 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (kbd ? (argc > 1) : (argc != 1)) + if ((kbd && get) || + ((kbd || get) ? (argc > 1) : (argc != 1))) usage(); idx = -1; if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1) errx(1, "invalid index"); - wsfd = open(wsdev, O_RDWR); + wsfd = open(wsdev, get ? O_RDONLY : O_RDWR); if (wsfd < 0) err(2, "%s", wsdev); @@ -137,6 +143,13 @@ main(int argc, char *argv[]) res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd); if (res < 0) err(3, "WSDISPLAYIO_DELSCREEN"); + } else if (get) { + asd.idx = idx; + res = ioctl(wsfd, WSDISPLAYIO_GETSCREEN, &asd); + if (res < 0) + err(3, "WSDISPLAYIO_GETSCREEN"); + else + printf("%d\n", asd.idx); } else { asd.idx = idx; res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd); |