summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp35
-rw-r--r--src/managers/PointerManager.cpp48
-rw-r--r--src/managers/PointerManager.hpp1
3 files changed, 45 insertions, 39 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index e3a347fd..c3f95961 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -2918,39 +2918,6 @@ PHLWINDOW CCompositor::windowForCPointer(CWindow* pWindow) {
return {};
}
-static void checkDefaultCursorWarp(SP<CMonitor> PNEWMONITOR, std::string monitorName) {
- static auto PCURSORMONITOR = CConfigValue<std::string>("cursor:default_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 CCompositor::onNewMonitor(SP<Aquamarine::IOutput> output) {
// add it to real
auto PNEWMONITOR = g_pCompositor->m_vRealMonitors.emplace_back(makeShared<CMonitor>());
@@ -2986,8 +2953,6 @@ void CCompositor::onNewMonitor(SP<Aquamarine::IOutput> output) {
g_pConfigManager->m_bWantsMonitorReload = true;
g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR.get(), IOutput::AQ_SCHEDULE_NEW_MONITOR);
- checkDefaultCursorWarp(PNEWMONITOR, output->name);
-
for (auto& w : g_pCompositor->m_vWindows) {
if (w->m_iMonitorID == PNEWMONITOR->ID) {
w->m_iLastSurfaceMonitorID = MONITOR_INVALID;
diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp
index 3ba34c11..72ff5ae7 100644
--- a/src/managers/PointerManager.cpp
+++ b/src/managers/PointerManager.cpp
@@ -11,13 +11,21 @@
#include <gbm.h>
CPointerManager::CPointerManager() {
- hooks.monitorAdded = g_pHookSystem->hookDynamic("newMonitor", [this](void* self, SCallbackInfo& info, std::any data) {
- auto PMONITOR = std::any_cast<SP<CMonitor>>(data);
+ hooks.monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any data) {
+ auto PMONITOR = std::any_cast<CMonitor*>(data)->self.lock();
onMonitorLayoutChange();
- PMONITOR->events.modeChanged.registerStaticListener([this](void* owner, std::any data) { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }, nullptr);
- PMONITOR->events.disconnect.registerStaticListener([this](void* owner, std::any data) { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }, nullptr);
+ PMONITOR->events.modeChanged.registerStaticListener(
+ [this, PMONITOR](void* owner, std::any data) {
+ g_pEventLoopManager->doLater([this, PMONITOR]() {
+ onMonitorLayoutChange();
+ checkDefaultCursorWarp(PMONITOR, PMONITOR->output->name);
+ });
+ },
+ nullptr);
+ PMONITOR->events.disconnect.registerStaticListener(
+ [this, PMONITOR](void* owner, std::any data) { g_pEventLoopManager->doLater([this, PMONITOR]() { onMonitorLayoutChange(); }); }, nullptr);
PMONITOR->events.destroy.registerStaticListener(
[this](void* owner, std::any data) {
if (g_pCompositor && !g_pCompositor->m_bIsShuttingDown)
@@ -35,6 +43,38 @@ CPointerManager::CPointerManager() {
});
}
+void CPointerManager::checkDefaultCursorWarp(SP<CMonitor> monitor, std::string monitorName) {
+ static auto PCURSORMONITOR = CConfigValue<std::string>("cursor:default_monitor");
+ static bool cursorDefaultDone = false;
+ static bool firstLaunch = true;
+
+ const auto POS = monitor->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();
+ return;
+ }
+
+ if (!cursorDefaultDone && *PCURSORMONITOR != STRVAL_EMPTY) {
+ if (*PCURSORMONITOR == monitorName) {
+ cursorDefaultDone = true;
+ g_pCompositor->warpCursorTo(POS, true);
+ g_pInputManager->refocus();
+ return;
+ }
+ }
+
+ // modechange happend check if cursor is on that monitor and warp it to middle to not place it out of bounds if resolution changed.
+ if (g_pCompositor->getMonitorFromCursor() == monitor.get()) {
+ g_pCompositor->warpCursorTo(POS, true);
+ g_pInputManager->refocus();
+ }
+}
+
void CPointerManager::lockSoftwareAll() {
for (auto& state : monitorStates)
state->softwareLocks++;
diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp
index 4a4c4f61..082855b5 100644
--- a/src/managers/PointerManager.hpp
+++ b/src/managers/PointerManager.hpp
@@ -26,6 +26,7 @@ class CPointerManager {
public:
CPointerManager();
+ void checkDefaultCursorWarp(SP<CMonitor> monitor, std::string monitorName);
void attachPointer(SP<IPointer> pointer);
void attachTouch(SP<ITouch> touch);
void attachTablet(SP<CTablet> tablet);