[PATCH] kbd_mode: support Disabled mode (K_OFF)

[email protected] Mon, 3 Feb 2025 18:47:31 +0100
Newsgroups dev.linux.lists.kbd
Message-ID <[email protected]>
From: Tianhao Wang <[email protected]>

Since linux 2.6.39 KDGKBMODE could have K_OFF (0x04), the Disabled mode.
This may be set by e.g. Xorg that doesn't read /dev/tty

Reference: https://lore.kernel.org/all/[email protected]/

Signed-off-by: Tianhao Wang <[email protected]>
---
 src/kbd_mode.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/kbd_mode.c b/src/kbd_mode.c
index 9a4aff3..f37c321 100644
--- a/src/kbd_mode.c
+++ b/src/kbd_mode.c
@@ -16,9 +16,14 @@
 #include <sysexits.h>
 #include <sys/ioctl.h>
 #include <linux/kd.h>
+#include <linux/version.h>
 
 #include "libcommon.h"
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)
+#define HAS_K_OFF
+#endif
+
 static void KBD_ATTR_NORETURN
 usage(int rc, const struct kbd_help *options)
 {
@@ -48,6 +53,11 @@ fprint_mode(FILE *stream, int  mode)
 		case K_UNICODE:
 			fprintf(stream, _("The keyboard is in Unicode (UTF-8) mode"));
 			break;
+#ifdef HAS_K_OFF
+		case K_OFF:
+			fprintf(stream, _("The keyboard is in Disabled mode, perhaps you are using a graphical environment?"));
+			break;
+#endif
 		default:
 			fprintf(stream, _("The keyboard is in some unknown mode"));
 	}
-- 
2.48.1