diff --git a/safeeyes/SafeEyesCore.py b/safeeyes/SafeEyesCore.py
index 7a96b8c..0a01924 100644
--- a/safeeyes/SafeEyesCore.py
+++ b/safeeyes/SafeEyesCore.py
@@ -65,6 +65,8 @@ class SafeEyesCore:
self.skip_break_window_classes = [x.lower() for x in config['active_window_class']['skip_break']]
self.take_break_window_classes = [x.lower() for x in config['active_window_class']['take_break']]
self.custom_exercises = config['custom_exercises']
+ self.time_to_screen_lock = config.get('time_to_screen_lock', -1)
+ self.enable_screen_lock = config.get('enable_screen_lock', False)
exercises = language['exercises']
for short_break_config in config['short_breaks']:
@@ -291,6 +293,11 @@ class SafeEyesCore:
audible_alert = self.short_break_exercises[self.short_break_message_index][2]
image = self.short_break_exercises[self.short_break_message_index][3]
+
+ total_break_time = seconds
+ # Should we lock screen potentially?
+ consider_screen_lock = Utility.is_desktop_lock_supported() and self.enable_screen_lock
+
# Show the break screen
self.start_break(message, image)
@@ -301,6 +308,8 @@ class SafeEyesCore:
self.on_countdown(timeformat)
time.sleep(1) # Sleep for 1 second
seconds -= 1
+ if consider_screen_lock and self.time_to_screen_lock == total_break_time - seconds:
+ Utility.lock_desktop()
# Loop terminated because of timeout (not skipped) -> Close the break alert
if not self.skipped and not self.postponed:
diff --git a/safeeyes/SettingsDialog.py b/safeeyes/SettingsDialog.py
index a68c9e1..2cd26b2 100644
--- a/safeeyes/SettingsDialog.py
+++ b/safeeyes/SettingsDialog.py
@@ -45,6 +45,8 @@ class SettingsDialog:
self.switch_strict_break = builder.get_object('switch_strict_break')
self.switch_audible_alert = builder.get_object('switch_audible_alert')
self.cmb_language = builder.get_object('cmb_language')
+ self.switch_screen_lock = builder.get_object('switch_screen_lock')
+ self.spin_time_to_screen_lock = builder.get_object('spin_time_to_screen_lock')
builder.get_object('lbl_short_break').set_label(language['ui_controls']['short_break_duration'])
builder.get_object('lbl_long_break').set_label(language['ui_controls']['long_break_duration'])
@@ -56,6 +58,8 @@ class SettingsDialog:
builder.get_object('lbl_strict_break').set_label(language['ui_controls']['strict_break'])
builder.get_object('lbl_audible_alert').set_label(language['ui_controls']['audible_alert'])
builder.get_object('lbl_language').set_label(language['ui_controls']['language'])
+ builder.get_object('lbl_enable_screen_lock').set_label(language['ui_controls']['enable_screen_lock'])
+ builder.get_object('lbl_lock_screen_after').set_label(language['ui_controls']['time_to_screen_lock'])
builder.get_object('btn_cancel').set_label(language['ui_controls']['cancel'])
builder.get_object('btn_save').set_label(language['ui_controls']['save'])
@@ -68,6 +72,10 @@ class SettingsDialog:
self.spin_postpone_duration.set_value(config['postpone_duration'])
self.switch_strict_break.set_active(config['strict_break'])
self.switch_audible_alert.set_active(config['audible_alert'])
+ self.switch_screen_lock.set_sensitive(Utility.is_desktop_lock_supported())
+ self.switch_screen_lock.set_active(Utility.is_desktop_lock_supported() and self.config.get('enable_screen_lock', False))
+ self.spin_time_to_screen_lock.set_value(self.config.get('time_to_screen_lock', 20))
+ self.on_switch_screen_lock_activate(self.switch_screen_lock, self.switch_screen_lock.get_active())
# Initialize the language combobox
language_list_store = Gtk.ListStore(GObject.TYPE_STRING)
@@ -101,6 +109,9 @@ class SettingsDialog:
def show(self):
self.window.show_all()
+ def on_switch_screen_lock_activate(self, switch, state):
+ self.spin_time_to_screen_lock.set_sensitive(self.switch_screen_lock.get_active())
+
def on_window_delete(self, *args):
self.window.destroy()
@@ -115,6 +126,8 @@ class SettingsDialog:
self.config['strict_break'] = self.switch_strict_break.get_active()
self.config['audible_alert'] = self.switch_audible_alert.get_active()
self.config['language'] = self.languages[self.cmb_language.get_active()]
+ self.config['time_to_screen_lock'] = self.spin_time_to_screen_lock.get_value_as_int()
+ self.config['enable_screen_lock'] = self.switch_screen_lock.get_active()
self.on_save_settings(self.config) # Call the provided save method
self.window.destroy() # Close the settings window
diff --git a/safeeyes/Utility.py b/safeeyes/Utility.py
index cabe621..69f9b1f 100644
--- a/safeeyes/Utility.py
+++ b/safeeyes/Utility.py
@@ -240,3 +240,21 @@ def read_lang_files():
languages[lang_file_name.lower().replace('.json', '')] = lang['meta_info']['language_name']
return languages
+
+def desktop_envinroment():
+ """
+ Function tries to detect current envinroment
+ Possible results: unity, gnome or None if nothing detected
+ """
+ if 'unity' == os.environ.get('XDG_CURRENT_DESKTOP', '').lower():
+ return 'unity'
+ elif 'gnome' == os.environ.get('DESKTOP_SESSION', '').lower():
+ return 'gnome'
+
+ return None
+
+def is_desktop_lock_supported():
+ return desktop_envinroment() in ['unity', 'gnome']
+
+def lock_desktop():
+ subprocess.call(["gnome-screensaver-command","--lock",])
diff --git a/safeeyes/config/lang/en.json b/safeeyes/config/lang/en.json
index b7afdd2..4048ba1 100644
--- a/safeeyes/config/lang/en.json
+++ b/safeeyes/config/lang/en.json
@@ -44,6 +44,8 @@
"strict_break": "Strict break (Hide skip button)",
"system_language": "System Language",
"time_to_prepare_for_break": "Time to prepare for break (in seconds)",
- "until_restart": "Until restart"
+ "until_restart": "Until restart",
+ "time_to_screen_lock": "Lock screen if break is longer than (in seconds)",
+ "enable_screen_lock": "Enable screen lock for long breaks"
}
}
diff --git a/safeeyes/config/lang/ru.json b/safeeyes/config/lang/ru.json
index e4b2a00..80711e5 100644
--- a/safeeyes/config/lang/ru.json
+++ b/safeeyes/config/lang/ru.json
@@ -44,6 +44,8 @@
"strict_break": "Обязательный перерыв (Скрыть кнопку 'Пропустить')",
"system_language": "System Language",
"time_to_prepare_for_break": "Время подготовки в перерыву (в секундах)",
- "until_restart": "До перезагрузки"
+ "until_restart": "До перезагрузки",
+ "time_to_screen_lock": "Заблокировать экран если перерыв дольше(в секундах)",
+ "enable_screen_lock": "Включить блокировку экрана"
}
}
diff --git a/safeeyes/glade/settings_dialog.glade b/safeeyes/glade/settings_dialog.glade
index 316c960..6412290 100644
--- a/safeeyes/glade/settings_dialog.glade
+++ b/safeeyes/glade/settings_dialog.glade
@@ -46,24 +46,30 @@
1
5
+
+
-