From c3adc9ec56020446fdf8953254757392b4634bbd Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Sun, 29 Jan 2023 12:44:38 +0000 Subject: [PATCH] Get active VT via ioctl instead of sysfs after e90c5c634753 (#1448) --- src/managers/KeybindManager.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 164d9737a..dae491ca2 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2,6 +2,15 @@ #include +#include +#if defined(__linux__) +#include +#elif defined(__NetBSD__) || defined(__OpenBSD__) +#include +#elif defined(__DragonFly__) || defined(__FreeBSD__) +#include +#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;