diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 6956c6972..2a44137e7 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -3,6 +3,7 @@ #include #include +#include #if defined(__linux__) #include #elif defined(__NetBSD__) || defined(__OpenBSD__) @@ -518,15 +519,19 @@ bool CKeybindManager::handleVT(xkb_keysym_t keysym) { // vtnr is bugged for some reason. unsigned int ttynum = 0; + int fd; + if ((fd = open("/dev/tty", O_RDONLY | O_NOCTTY)) >= 0) { #if defined(VT_GETSTATE) - struct vt_stat st; - if (!ioctl(0, VT_GETSTATE, &st)) - ttynum = st.v_active; + struct vt_stat st; + if (!ioctl(fd, VT_GETSTATE, &st)) + ttynum = st.v_active; #elif defined(VT_GETACTIVE) - int vt; - if (!ioctl(0, VT_GETACTIVE, &vt)) - ttynum = vt; + int vt; + if (!ioctl(fd, VT_GETACTIVE, &vt)) + ttynum = vt; #endif + close(fd); + } if (ttynum == TTY) return true;