mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-09-05 19:08:18 +00:00
internal: unify VT getting
This commit is contained in:
@@ -3213,3 +3213,24 @@ void CCompositor::ensurePersistentWorkspacesPresent(const std::vector<SWorkspace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<unsigned int> CCompositor::getVTNr() {
|
||||
if (!m_aqBackend->hasSession())
|
||||
return std::nullopt;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return ttynum;
|
||||
}
|
||||
|
@@ -156,6 +156,7 @@ class CCompositor {
|
||||
void updateSuspendedStates();
|
||||
void onNewMonitor(SP<Aquamarine::IOutput> output);
|
||||
void ensurePersistentWorkspacesPresent(const std::vector<SWorkspaceRule>& rules, PHLWORKSPACE pWorkspace = nullptr);
|
||||
std::optional<unsigned int> getVTNr();
|
||||
|
||||
NColorManagement::SImageDescription getPreferredImageDescription();
|
||||
bool shouldChangePreferredImageDescription();
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -2856,11 +2856,9 @@ void CHyprOpenGLImpl::ensureLockTexturesRendered(bool load) {
|
||||
m_lockDeadTexture = loadAsset("lockdead.png");
|
||||
m_lockDead2Texture = loadAsset("lockdead2.png");
|
||||
|
||||
m_lockTtyTextTexture = renderText(std::format("Running on tty {}",
|
||||
g_pCompositor->m_aqBackend->hasSession() && g_pCompositor->m_aqBackend->session->vt > 0 ?
|
||||
std::to_string(g_pCompositor->m_aqBackend->session->vt) :
|
||||
"unknown"),
|
||||
CHyprColor{0.9F, 0.9F, 0.9F, 0.7F}, 20, true);
|
||||
const auto VT = g_pCompositor->getVTNr();
|
||||
|
||||
m_lockTtyTextTexture = renderText(std::format("Running on tty {}", VT.has_value() ? std::to_string(*VT) : "unknown"), CHyprColor{0.9F, 0.9F, 0.9F, 0.7F}, 20, true);
|
||||
} else {
|
||||
m_lockDeadTexture.reset();
|
||||
m_lockDead2Texture.reset();
|
||||
|
Reference in New Issue
Block a user