donotdisturb: Add wayland fullscreen detection (#427)
* [wayland] detect fullscreen with wlrctl Will work with the next sway release or current master branch. * Add dependency_checker
This commit is contained in:
parent
f1cf3c01b7
commit
6e07de7c22
|
@ -95,6 +95,7 @@ Ensure to meet the following dependencies:
|
|||
- libappindicator-gtk3
|
||||
- python3-psutil
|
||||
- xprintidle (optional)
|
||||
- wlrctl (wayland optional)
|
||||
|
||||
**To install Safe Eyes:**
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"python_modules": [],
|
||||
"shell_commands": ["xprop"],
|
||||
"shell_commands": [],
|
||||
"operating_systems": [],
|
||||
"desktop_environments": [],
|
||||
"resources": []
|
||||
|
@ -37,4 +37,4 @@
|
|||
}
|
||||
],
|
||||
"break_override_allowed": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,6 +30,7 @@ import gi
|
|||
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 = []
|
||||
|
@ -38,7 +39,24 @@ unfullscreen_allowed = True
|
|||
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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue