Improve the screen lock command

This commit is contained in:
Gobinath 2017-04-20 09:43:26 -04:00
parent 8761d6cbbf
commit 0ee6f2f2bb
5 changed files with 36 additions and 33 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
safeeyes (1.2.0a8-1) xenial; urgency=low
safeeyes (1.2.0a9-1) xenial; urgency=low
* Move to Python 3

View File

@ -25,7 +25,7 @@ class SettingsDialog:
"""
Create and initialize SettingsDialog instance.
"""
def __init__(self, config, language, languages, on_save_settings, glade_file):
def __init__(self, config, language, languages, able_to_lock_screen, on_save_settings, glade_file):
self.config = config
self.on_save_settings = on_save_settings
self.languages = []
@ -79,11 +79,6 @@ class SettingsDialog:
# Enable idle_time_to_pause only if xprintidle is available
self.spin_idle_time_to_pause.set_sensitive(Utility.command_exist('xprintidle'))
# Check lock screen command
able_to_lock_screen = False
if config['lock_screen_command'] or Utility.lock_screen_command():
able_to_lock_screen = True
self.switch_screen_lock.set_sensitive(able_to_lock_screen)
self.switch_screen_lock.set_active(able_to_lock_screen and config['enable_screen_lock'])

View File

@ -256,39 +256,37 @@ def lock_screen_command():
Otherwise: None
"""
desktop_session = os.environ.get('DESKTOP_SESSION')
current_desktop = os.environ.get('XDG_CURRENT_DESKTOP')
if desktop_session is not None:
desktop_session = desktop_session.lower()
if desktop_session in ['gnome','unity', 'budgie-desktop'] or desktop_session.startswith('ubuntu'):
if ('xfce' in desktop_session or desktop_session.startswith('xubuntu') or (current_desktop is not None and 'xfce' in current_desktop)) and command_exist('xflock4'):
return ['xflock4']
elif desktop_session == 'cinnamon' and command_exist('cinnamon-screensaver-command'):
return ['cinnamon-screensaver-command', '--lock']
elif (desktop_session == 'pantheon' or desktop_session.startswith('lubuntu')) and command_exist('light-locker-command'):
return ['light-locker-command', '--lock']
elif desktop_session == 'mate' and command_exist('mate-screensaver-command'):
return ['mate-screensaver-command', '--lock']
elif desktop_session == 'kde' or 'plasma' in desktop_session or desktop_session.startswith('kubuntu') or os.environ.get('KDE_FULL_SESSION') == 'true':
return ['qdbus', 'org.freedesktop.ScreenSaver', '/ScreenSaver', 'Lock']
elif desktop_session in ['gnome','unity', 'budgie-desktop'] or desktop_session.startswith('ubuntu'):
if command_exist('gnome-screensaver-command'):
return ['gnome-screensaver-command', '--lock']
else:
# From Gnome 3.8 no gnome-screensaver-command
return ['dbus-send', '--type=method_call', '--dest=org.gnome.ScreenSaver', '/org/gnome/ScreenSaver', 'org.gnome.ScreenSaver.Lock']
elif desktop_session == 'cinnamon':
return ['cinnamon-screensaver-command', '--lock']
elif desktop_session == 'pantheon' or desktop_session.startswith('lubuntu'):
return ['light-locker-command', '--lock']
elif desktop_session == 'mate':
return ['mate-screensaver-command', '--lock']
elif desktop_session == 'kde' or 'plasma' in desktop_session or desktop_session.startswith('kubuntu') or os.environ.get('KDE_FULL_SESSION') == 'true':
return ['qdbus', 'org.freedesktop.ScreenSaver', '/ScreenSaver', 'Lock']
elif 'xfce' in desktop_session or desktop_session.startswith('xubuntu'):
return ['xflock4']
elif os.environ.get('GNOME_DESKTOP_SESSION_ID'):
if not 'deprecated' in os.environ.get('GNOME_DESKTOP_SESSION_ID'):
if not 'deprecated' in os.environ.get('GNOME_DESKTOP_SESSION_ID') and command_exist('gnome-screensaver-command'):
# Gnome 2
return ['gnome-screensaver-command', '--lock']
return None
def lock_desktop(user_defined_command):
def lock_desktop(command):
"""
Lock the screen using the predefined commands
"""
if user_defined_command:
command = user_defined_command
else:
command = lock_screen_command()
if command is not None:
if command:
try:
subprocess.Popen(command)
except Exception as e:
@ -328,4 +326,4 @@ class __HTMLTextExtractor(HTMLParser):
self.fed.append(d)
def get_data(self):
return ''.join(self.fed)
return ''.join(self.fed)

View File

@ -44,14 +44,17 @@ system_style_sheet_path = os.path.join(Utility.bin_directory, "config/style/safe
is_active = True
CONFIGURATION_VERSION = 4
SAFE_EYES_VERSION = "1.2.0a8"
SAFE_EYES_VERSION = "1.2.0a9"
"""
Listen to tray icon Settings action and send the signal to Settings dialog.
"""
def show_settings():
logging.info("Show Settings dialog")
settings_dialog = SettingsDialog(config, language, Utility.read_lang_files(), save_settings, settings_dialog_glade)
able_to_lock_screen = False
if system_lock_command:
able_to_lock_screen = True
settings_dialog = SettingsDialog(config, language, Utility.read_lang_files(), able_to_lock_screen, save_settings, settings_dialog_glade)
settings_dialog.show()
"""
@ -89,7 +92,7 @@ def close_alert(audible_alert_on):
logging.info("Close the break screen")
if config['enable_screen_lock'] and context['break_type'] == 'long':
# Lock the screen before closing the break screen
Utility.lock_desktop(config['lock_screen_command'])
Utility.lock_desktop(system_lock_command)
break_screen.close()
if audible_alert_on:
Utility.play_notification()
@ -137,7 +140,7 @@ def on_skipped():
logging.info("User skipped the break")
if config['enable_screen_lock'] and context['break_type'] == 'long' and context.get('count_down', 0) >= config['time_to_screen_lock']:
# Lock the screen before closing the break screen
Utility.lock_desktop(config['lock_screen_command'])
Utility.lock_desktop(system_lock_command)
core.skip_break()
plugins.post_break(context)
@ -148,7 +151,7 @@ def on_postponed():
logging.info("User postponed the break")
if config['enable_screen_lock'] and context['break_type'] == 'long' and context.get('count_down', 0) >= config['time_to_screen_lock']:
# Lock the screen before closing the break screen
Utility.lock_desktop(config['lock_screen_command'])
Utility.lock_desktop(system_lock_command)
core.postpone_break()
"""
@ -304,9 +307,16 @@ def main():
global language
global context
global plugins
global system_lock_command
context = {}
language = Utility.load_language(config['language'])
# Get the lock command only one time
if config['lock_screen_command']:
system_lock_command = config['lock_screen_command']
else:
system_lock_command = Utility.lock_screen_command()
# Initialize the Safe Eyes Context
context['version'] = SAFE_EYES_VERSION

View File

@ -23,13 +23,13 @@ def _data_files(path):
setuptools.setup(
name="safeeyes",
version="1.2.0a8",
version="1.2.0a9",
description="Protect your eyes from eye strain using this continuous breaks reminder.",
long_description=long_description,
author="Gobinath Loganathan",
author_email="slgobinath@gmail.com",
url="https://github.com/slgobinath/SafeEyes",
download_url="https://github.com/slgobinath/SafeEyes/archive/v1.2.0a8.tar.gz",
download_url="https://github.com/slgobinath/SafeEyes/archive/v1.2.0a9.tar.gz",
packages=setuptools.find_packages(),
package_data={'safeeyes': ['config/*.json',
'config/style/*.css',