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;