Skip to contentSkip to conversation

kbd_mode: support Disabled mode (K_OFF)

PATCH Applied [email protected] 2 participants 2 messages Feb 3, 2025 – Feb 4, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbd_mode: support Disabled mode (K_OFF)

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]/

---
 src/kbd_mode.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
src/kbd_mode.c +10 -0
index 9a4aff3..f37c321 100644
@@ -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"));
 	}
Signature · 1 line
2.48.1
#1 lore raw
Quoted 8 lines · On Mon, Feb 03, 2025 at 06:47:31PM +0100, [email protected] wrote:

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]/

Applied. Thanks.

Quoted 39 lines
---
 src/kbd_mode.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
src/kbd_mode.c +10 -0
index 9a4aff3..f37c321 100644
@@ -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"));
 	}
Signature · 1 line
2.48.1
Signature · 1 line
Rgrds, legion