internal: unify VT getting

This commit is contained in:
vaxerski 2025-08-14 17:13:15 +02:00
parent beee22a95e
commit 60d769a899
4 changed files with 28 additions and 21 deletions

View file

@ -875,25 +875,12 @@ bool CKeybindManager::handleVT(xkb_keysym_t keysym) {
if (g_pCompositor->m_aqBackend->hasSession()) {
const unsigned int TTY = keysym - XKB_KEY_XF86Switch_VT_1 + 1;
// vtnr is bugged for some reason.
unsigned int ttynum = 0;
Hyprutils::OS::CFileDescriptor fd{open("/dev/tty", O_RDONLY | O_NOCTTY)};
if (fd.isValid()) {
#if defined(VT_GETSTATE)
struct vt_stat st;
if (!ioctl(fd.get(), VT_GETSTATE, &st))
ttynum = st.v_active;
#elif defined(VT_GETACTIVE)
int vt;
if (!ioctl(fd.get(), VT_GETACTIVE, &vt))
ttynum = vt;
#endif
}
const auto CURRENT_TTY = g_pCompositor->getVTNr();
if (ttynum == TTY)
if (!CURRENT_TTY.has_value() || *CURRENT_TTY == TTY)
return true;
Debug::log(LOG, "Switching from VT {} to VT {}", ttynum, TTY);
Debug::log(LOG, "Switching from VT {} to VT {}", *CURRENT_TTY, TTY);
g_pCompositor->m_aqBackend->session->switchVT(TTY);
}