Skip to content

Commit

Permalink
[wayland] detect fullscreen with wlrctl
Browse files Browse the repository at this point in the history
Will work with the next sway release or current master branch.
  • Loading branch information
cyrinux committed Feb 24, 2021
1 parent a69d674 commit 0e3c0f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Ensure to meet the following dependencies:
- libappindicator-gtk3
- python3-psutil
- xprintidle (optional)
- wlrctl (wayland optional)

**To install Safe Eyes:**

Expand Down
30 changes: 27 additions & 3 deletions safeeyes/plugins/donotdisturb/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
from gi.repository import GdkX11 # noqa F401
from safeeyes import utility

context = None
skip_break_window_classes = []
Expand All @@ -38,7 +39,24 @@
dnd_while_on_battery = False


def is_active_window_skipped(pre_break):
def is_active_window_skipped_wayland(pre_break):
cmdlist = ['wlrctl', 'toplevel', 'find', 'state:fullscreen']
try:
process = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
process.communicate()[0]
if process.returncode == 0:
return True
elif process.returncode == 1:
return False
elif process.returncode == 127:
logging.warning('Could not find wlrctl needed to detect fullscreen under wayland')
return False
except subprocess.CalledProcessError:
logging.warning('Error in finding full-screen application')
return False


def is_active_window_skipped_xorg(pre_break):
"""
Check for full-screen applications.
This method must be executed by the main thread. If not, it will cause random failure.
Expand Down Expand Up @@ -123,7 +141,10 @@ def on_pre_break(break_obj):
"""
Lifecycle method executes before the pre-break period.
"""
skip_break = is_active_window_skipped(True)
if utility.IS_WAYLAND:
skip_break = is_active_window_skipped_wayland(True)
else:
skip_break = is_active_window_skipped_xorg(True)
if dnd_while_on_battery and not skip_break:
skip_break = is_on_battery()
return skip_break
Expand All @@ -133,7 +154,10 @@ def on_start_break(break_obj):
"""
Lifecycle method executes just before the break.
"""
skip_break = is_active_window_skipped(False)
if utility.IS_WAYLAND:
skip_break = is_active_window_skipped_wayland(True)
else:
skip_break = is_active_window_skipped_xorg(True)
if dnd_while_on_battery and not skip_break:
skip_break = is_on_battery()
return skip_break

0 comments on commit 0e3c0f8

Please sign in to comment.