mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-29 23:06:00 +01:00
config: added option to choose the default monitor for the cursor (#5847)
* added option to choose the default monitor that the cursor will appear in upon startup * fix: don't set cursor to default monitor after startup * refactor to checkDefaultCursorWarp also fix focus
This commit is contained in:
parent
41cf94faaa
commit
387127b12a
2 changed files with 42 additions and 14 deletions
|
@ -318,6 +318,7 @@ CConfigManager::CConfigManager() {
|
||||||
m_pConfig->addConfigValue("general:layout", {"dwindle"});
|
m_pConfig->addConfigValue("general:layout", {"dwindle"});
|
||||||
m_pConfig->addConfigValue("general:allow_tearing", Hyprlang::INT{0});
|
m_pConfig->addConfigValue("general:allow_tearing", Hyprlang::INT{0});
|
||||||
m_pConfig->addConfigValue("general:resize_corner", Hyprlang::INT{0});
|
m_pConfig->addConfigValue("general:resize_corner", Hyprlang::INT{0});
|
||||||
|
m_pConfig->addConfigValue("general:default_cursor_monitor", {STRVAL_EMPTY});
|
||||||
|
|
||||||
m_pConfig->addConfigValue("misc:disable_hyprland_logo", Hyprlang::INT{0});
|
m_pConfig->addConfigValue("misc:disable_hyprland_logo", Hyprlang::INT{0});
|
||||||
m_pConfig->addConfigValue("misc:disable_splash_rendering", Hyprlang::INT{0});
|
m_pConfig->addConfigValue("misc:disable_splash_rendering", Hyprlang::INT{0});
|
||||||
|
|
|
@ -60,13 +60,45 @@ void Events::listener_change(wl_listener* listener, void* data) {
|
||||||
wlr_output_manager_v1_set_configuration(g_pCompositor->m_sWLROutputMgr, CONFIG);
|
wlr_output_manager_v1_set_configuration(g_pCompositor->m_sWLROutputMgr, CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void checkDefaultCursorWarp(std::shared_ptr<CMonitor>* PNEWMONITORWRAP, std::string monitorName) {
|
||||||
|
const auto PNEWMONITOR = PNEWMONITORWRAP->get();
|
||||||
|
|
||||||
|
static auto PCURSORMONITOR = CConfigValue<std::string>("general:default_cursor_monitor");
|
||||||
|
static auto firstMonitorAdded = std::chrono::system_clock::now();
|
||||||
|
static bool cursorDefaultDone = false;
|
||||||
|
static bool firstLaunch = true;
|
||||||
|
|
||||||
|
const auto POS = PNEWMONITOR->middle();
|
||||||
|
|
||||||
|
// by default, cursor should be set to first monitor detected
|
||||||
|
// this is needed as a default if the monitor given in config above doesn't exist
|
||||||
|
if (firstLaunch) {
|
||||||
|
firstLaunch = false;
|
||||||
|
g_pCompositor->warpCursorTo(POS, true);
|
||||||
|
g_pInputManager->refocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursorDefaultDone || *PCURSORMONITOR == STRVAL_EMPTY)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// after 10s, don't set cursor to default monitor
|
||||||
|
auto timePassedSec = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - firstMonitorAdded);
|
||||||
|
if (timePassedSec.count() > 10) {
|
||||||
|
cursorDefaultDone = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*PCURSORMONITOR == monitorName) {
|
||||||
|
cursorDefaultDone = true;
|
||||||
|
g_pCompositor->warpCursorTo(POS, true);
|
||||||
|
g_pInputManager->refocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Events::listener_newOutput(wl_listener* listener, void* data) {
|
void Events::listener_newOutput(wl_listener* listener, void* data) {
|
||||||
// new monitor added, let's accommodate for that.
|
// new monitor added, let's accommodate for that.
|
||||||
const auto OUTPUT = (wlr_output*)data;
|
const auto OUTPUT = (wlr_output*)data;
|
||||||
|
|
||||||
// for warping the cursor on launch
|
|
||||||
static bool firstLaunch = true;
|
|
||||||
|
|
||||||
if (!OUTPUT->name) {
|
if (!OUTPUT->name) {
|
||||||
Debug::log(ERR, "New monitor has no name?? Ignoring");
|
Debug::log(ERR, "New monitor has no name?? Ignoring");
|
||||||
return;
|
return;
|
||||||
|
@ -101,12 +133,8 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
||||||
g_pConfigManager->m_bWantsMonitorReload = true;
|
g_pConfigManager->m_bWantsMonitorReload = true;
|
||||||
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR);
|
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR);
|
||||||
|
|
||||||
if (firstLaunch) {
|
checkDefaultCursorWarp(PNEWMONITORWRAP, OUTPUT->name);
|
||||||
firstLaunch = false;
|
|
||||||
const auto POS = PNEWMONITOR->middle();
|
|
||||||
if (g_pCompositor->m_sSeat.mouse)
|
|
||||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, POS.x, POS.y);
|
|
||||||
} else {
|
|
||||||
for (auto& w : g_pCompositor->m_vWindows) {
|
for (auto& w : g_pCompositor->m_vWindows) {
|
||||||
if (w->m_iMonitorID == PNEWMONITOR->ID) {
|
if (w->m_iMonitorID == PNEWMONITOR->ID) {
|
||||||
w->m_iLastSurfaceMonitorID = -1;
|
w->m_iLastSurfaceMonitorID = -1;
|
||||||
|
@ -114,7 +142,6 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Events::listener_monitorFrame(void* owner, void* data) {
|
void Events::listener_monitorFrame(void* owner, void* data) {
|
||||||
if (g_pCompositor->m_bExitTriggered) {
|
if (g_pCompositor->m_bExitTriggered) {
|
||||||
|
|
Loading…
Reference in a new issue