Get active VT via ioctl instead of sysfs after e90c5c6347 (#1448)

This commit is contained in:
Jan Beich 2023-01-29 12:44:38 +00:00 committed by GitHub
parent ff9bcb19fa
commit c3adc9ec56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,15 @@
#include <regex> #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() { CKeybindManager::CKeybindManager() {
// initialize all dispatchers // 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; const unsigned int TTY = keysym - XKB_KEY_XF86Switch_VT_1 + 1;
// vtnr is bugged for some reason. // 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; unsigned int ttynum = 0;
try { #if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__)
ttynum = std::stoll(TTYSTR); struct vt_stat st;
} catch (std::exception& e) { if (!ioctl(0, VT_GETSTATE, &st))
; // oops? ttynum = st.v_active;
} #elif defined(__DragonFly__) || defined(__FreeBSD__)
int vt;
if (!ioctl(0, VT_GETACTIVE, &vt))
ttynum = vt;
#endif
if (ttynum == TTY) if (ttynum == TTY)
return true; return true;