Skip to content

Commit

Permalink
donotdisturb: Add wayland fullscreen detection (slgobinath#427)
Browse files Browse the repository at this point in the history
* [wayland] detect fullscreen with wlrctl

Will work with the next sway release or current master branch.

* Add dependency_checker
  • Loading branch information
cyrinux authored Apr 18, 2021
1 parent f1cf3c0 commit 6e07de7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 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
4 changes: 2 additions & 2 deletions safeeyes/plugins/donotdisturb/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"python_modules": [],
"shell_commands": ["xprop"],
"shell_commands": [],
"operating_systems": [],
"desktop_environments": [],
"resources": []
Expand Down Expand Up @@ -37,4 +37,4 @@
}
],
"break_override_allowed": true
}
}
31 changes: 31 additions & 0 deletions safeeyes/plugins/donotdisturb/dependency_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Safe Eyes is a utility to remind you to take break frequently
# to protect your eyes from eye strain.

# Copyright (C) 2017 Gobinath

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from safeeyes import utility


def validate(plugin_config, plugin_settings):
command = None
if utility.IS_WAYLAND:
command = "wlrctl"
else:
command = "xprop"
if not utility.command_exist(command):
return _("Please install the command-line tool '%s'") % command
else:
return None
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 6e07de7

Please sign in to comment.