Skip to content

Monitoring window coordinates is a poor man's way to figure if the application lose focus #24

@bicobus

Description

@bicobus

The eventFilter method calls on_window_activate and on_window_deactivate if the window doesn't change coordinates, the idea being to trigger whether the application loose then regain main focus. Moving the window around would also deactivate the window, at least on Xorg based desktops, triggering the filter if there was none of those checks.

A better way around that behavior is to call on_window_deactivate as callback using a QTimer. If the application regain focus before the timer runs out, then the QTimer must be cancelled. on_window_activate would then only be called if the timer triggers the callback.

This method of tracking applications loss of focus should be a lot more obvious and clean.

qModManager/qmm/manager.py

Lines 874 to 904 in e3440af

def eventFilter(self, o, e: QEvent) -> bool:
if e.type() not in self.accepted_types:
return False
if not self._mainwindow or not self._mainwindow.autorefresh_checkbox.isChecked():
return False
if isinstance(o, QApplication) and e.type() == QEvent.ApplicationStateChange:
if o.applicationState() == Qt.ApplicationActive:
if self._is_first_activity:
self._is_first_activity = False
self.set_coords()
self.set_geometry()
return False
logger.debug("The application is visible and selected to be in front.")
coords = self.get_coords() == self._coords
geo = self.get_geometry() == self._geometry
if self.get_coords() != self._coords:
self.set_coords()
if self.get_geometry() != self._geometry:
self.set_geometry()
if coords and geo and not self._previous_state:
logger.debug("(A) Window became active without moving around.")
self._mainwindow.on_window_activate()
self._previous_state = True
if o.applicationState() == Qt.ApplicationInactive:
logger.debug("The application is visible, but **not** selected to be in front.")
if self.get_coords() != self._coords or self.get_geometry() != self._geometry:
return False
logger.debug("(D) Window isn't in focus, disabling WatchDog")
self._previous_state = False
self._mainwindow.on_window_deactivate()
return False

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions