summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authorJan Beich <jbeich@FreeBSD.org>2023-01-29 12:44:38 +0000
committerGitHub <noreply@github.com>2023-01-29 12:44:38 +0000
commitc3adc9ec56020446fdf8953254757392b4634bbd (patch)
tree56eed38002b5e4c17d5d4d81dd6fa535601f92ee /src/managers/KeybindManager.cpp
parentff9bcb19fa1944635d6064710f7b947bd53aa42c (diff)
Get active VT via ioctl instead of sysfs after e90c5c634753 (#1448)
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 164d9737..dae491ca 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -2,6 +2,15 @@
#include <regex>
+#include <sys/ioctl.h>
+#if defined(__linux__)
+#include <linux/vt.h>
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+#include <dev/wscons/wsdisplay_usl_io.h>
+#elif defined(__DragonFly__) || defined(__FreeBSD__)
+#include <sys/consio.h>
+#endif
+
CKeybindManager::CKeybindManager() {
// initialize all dispatchers
@@ -442,13 +451,16 @@ bool CKeybindManager::handleVT(xkb_keysym_t keysym) {
const unsigned int TTY = keysym - XKB_KEY_XF86Switch_VT_1 + 1;
// vtnr is bugged for some reason.
- const std::string TTYSTR = execAndGet("head -n 1 /sys/devices/virtual/tty/tty0/active").substr(3);
unsigned int ttynum = 0;
- try {
- ttynum = std::stoll(TTYSTR);
- } catch (std::exception& e) {
- ; // oops?
- }
+#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ struct vt_stat st;
+ if (!ioctl(0, VT_GETSTATE, &st))
+ ttynum = st.v_active;
+#elif defined(__DragonFly__) || defined(__FreeBSD__)
+ int vt;
+ if (!ioctl(0, VT_GETACTIVE, &vt))
+ ttynum = vt;
+#endif
if (ttynum == TTY)
return true;