summaryrefslogtreecommitdiff
path: root/src/events/Monitors.cpp
diff options
context:
space:
mode:
authorIkalco <73481042+ikalco@users.noreply.github.com>2024-05-02 20:39:19 -0500
committerGitHub <noreply@github.com>2024-05-03 02:39:19 +0100
commit387127b12ab5df8f8f40e8da7d76f47636562cab (patch)
tree1f074bd70f631a8f87185db702dd4b47d90abece /src/events/Monitors.cpp
parent41cf94faaa86b5b79def1ff1473796cc7e09a572 (diff)
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
Diffstat (limited to 'src/events/Monitors.cpp')
-rw-r--r--src/events/Monitors.cpp55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp
index d91ec4ba..11b7a25c 100644
--- a/src/events/Monitors.cpp
+++ b/src/events/Monitors.cpp
@@ -60,13 +60,45 @@ void Events::listener_change(wl_listener* listener, void* data) {
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) {
// new monitor added, let's accommodate for that.
const auto OUTPUT = (wlr_output*)data;
- // for warping the cursor on launch
- static bool firstLaunch = true;
-
if (!OUTPUT->name) {
Debug::log(ERR, "New monitor has no name?? Ignoring");
return;
@@ -101,17 +133,12 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
g_pConfigManager->m_bWantsMonitorReload = true;
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR);
- if (firstLaunch) {
- 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) {
- if (w->m_iMonitorID == PNEWMONITOR->ID) {
- w->m_iLastSurfaceMonitorID = -1;
- w->updateSurfaceScaleTransformDetails();
- }
+ checkDefaultCursorWarp(PNEWMONITORWRAP, OUTPUT->name);
+
+ for (auto& w : g_pCompositor->m_vWindows) {
+ if (w->m_iMonitorID == PNEWMONITOR->ID) {
+ w->m_iLastSurfaceMonitorID = -1;
+ w->updateSurfaceScaleTransformDetails();
}
}
}