Merge lp:~light-locker-settings-team/light-locker-settings/xfconf into lp:light-locker-settings

Proposed by Sean Davis
Status: Merged
Merged at revision: 73
Proposed branch: lp:~light-locker-settings-team/light-locker-settings/xfconf
Merge into: lp:light-locker-settings
Diff against target: 833 lines (+506/-192)
5 files modified
Makefile.in.in (+1/-0)
NEWS (+5/-0)
debian/changelog (+8/-1)
light-locker-settings/light-locker-settings.py (+315/-191)
light-locker-settings/light_locker_xfsync.py (+177/-0)
To merge this branch: bzr merge lp:~light-locker-settings-team/light-locker-settings/xfconf
Reviewer Review Type Date Requested Status
Simon SteinbeiƟ Approve
Review via email: mp+214207@code.launchpad.net

Description of the change

Ready for merge. Adds xfce4-session and xfce4-power-manager support.

To post a comment you must log in.
Revision history for this message
Simon SteinbeiƟ (ochosi) wrote :

Makes sense and works great! Go ahead and merge it

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.in.in'
2--- Makefile.in.in 2014-03-12 00:56:48 +0000
3+++ Makefile.in.in 2014-04-04 10:52:41 +0000
4@@ -21,6 +21,7 @@
5
6 install -d $(DESTDIR)/$(PREFIX)/share/$(APPNAME)/light-locker-settings
7 install light-locker-settings/light-locker-settings.py $(DESTDIR)/$(PREFIX)/share/$(APPNAME)/light-locker-settings
8+ install light-locker-settings/light_locker_xfsync.py $(DESTDIR)/$(PREFIX)/share/$(APPNAME)/light-locker-settings
9 install light-locker-settings/light-locker-settings.glade $(DESTDIR)/$(PREFIX)/share/$(APPNAME)/light-locker-settings
10
11 install -d $(DESTDIR)/$(PREFIX)/share/doc/$(APPNAME)
12
13=== modified file 'NEWS'
14--- NEWS 2014-03-25 02:29:49 +0000
15+++ NEWS 2014-04-04 10:52:41 +0000
16@@ -1,5 +1,10 @@
17 Light Locker Settings NEWS
18 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19+04 Apr 2014, Light Locker Settings 1.2.1
20+
21+- Support for external power management tools
22+ . Added support for xfce4-session and xfce4-power-manager (fixes LP:1290737)
23+
24 24 Mar 2014, Light Locker Settings 1.2.0
25
26 - light-locker settings:
27
28=== modified file 'debian/changelog'
29--- debian/changelog 2014-03-25 02:37:45 +0000
30+++ debian/changelog 2014-04-04 10:52:41 +0000
31@@ -1,4 +1,11 @@
32-light-locker-settings (1.2.0-0ubuntu1) UNRELEASED; urgency=medium
33+light-locker-settings (1.2.1-0ubuntu1) trusty; urgency=medium
34+
35+ * New upstream release. (LP: #1302484)
36+ - Fixes XFCE Power Manager setttings sync (LP: #1290737)
37+
38+ -- Sean Davis <smd.seandavis@gmail.com> Fri, 04 Apr 2014 06:46:52 -0400
39+
40+light-locker-settings (1.2.0-0ubuntu1) trusty; urgency=medium
41
42 * New upstream release. (LP: #1297058)
43
44
45=== modified file 'light-locker-settings/light-locker-settings.py'
46--- light-locker-settings/light-locker-settings.py 2014-03-24 02:59:57 +0000
47+++ light-locker-settings/light-locker-settings.py 2014-04-04 10:52:41 +0000
48@@ -30,6 +30,8 @@
49
50 import psutil
51
52+import light_locker_xfsync
53+
54 ''' Settings window for the light-locker '''
55
56 username = GLib.get_user_name()
57@@ -40,7 +42,8 @@
58
59 def __init__(self):
60 '''Initialize the Light Locker Settings application.'''
61- self.systemwide_desktop_file = "/etc/xdg/autostart/light-locker.desktop"
62+ self.systemwide_desktop_file = \
63+ "/etc/xdg/autostart/light-locker.desktop"
64 self.user_desktop_file = os.path.join(os.path.expanduser('~'),
65 '.config',
66 'autostart',
67@@ -91,32 +94,9 @@
68 self.screenoff_timeout.add_mark(i * 10, 3, None)
69 self.lock_delay.add_mark(i * 10, 3, None)
70
71- ''' if there is a file exists in ~/.config/autostart/ parse that
72- for current settings picked by the user else load in the
73- systemwide '''
74- if os.path.isfile(self.user_desktop_file):
75- self.read_in_desktop(self.user_desktop_file)
76- else:
77- self.read_in_desktop(self.systemwide_desktop_file)
78-
79- ''' read in the X11 screensaver settings from bash '''
80- screensaver_output = self.run_command('xset q', check_output=True)
81- screenblank_timeout_grep = re.search(
82- "timeout: *(\d+)", screensaver_output)
83- if screenblank_timeout_grep:
84- screenblank_timeout = re.findall(
85- '\d+', screenblank_timeout_grep.group(1))
86- self.screenblank_timeout.set_value(
87- int(screenblank_timeout[0]) / 60)
88- screenoff_timeout_grep = re.search(
89- "Standby: *(\d+)", screensaver_output)
90- if screenoff_timeout_grep:
91- screenoff_timeout = re.findall(
92- '\d+', screenoff_timeout_grep.group(1))
93- self.screenoff_timeout.set_value(int(screenoff_timeout[0]) / 60)
94+ self.init_settings()
95
96 ''' Monitor changes to the settings '''
97-
98 self.apply.set_sensitive(False)
99 self.locksettings_changed = False
100 self.screenblank_timeout.connect(
101@@ -126,6 +106,115 @@
102 self.lock_delay.connect(
103 "value-changed", self.lock_delay_value_changed_cb)
104
105+# Application Callbacks
106+ def screenblank_value_changed_cb(self, gparam):
107+ '''Sync screenblank and screenoff settings when values are modified.'''
108+ self.apply.set_sensitive(True)
109+
110+ blank_timeout = int(self.screenblank_timeout.get_value())
111+ off_timeout = int(self.screenoff_timeout.get_value())
112+
113+ ''' screenoff can never be shorter than screenblank-timeout '''
114+ if (blank_timeout >= off_timeout) and (off_timeout != 0):
115+ self.screenoff_timeout.set_value(blank_timeout)
116+
117+ def screenoff_value_changed_cb(self, gparam):
118+ '''Sync screenblank and screenoff settings when values are modified.'''
119+ self.apply.set_sensitive(True)
120+
121+ blank_timeout = int(self.screenblank_timeout.get_value())
122+ off_timeout = int(self.screenoff_timeout.get_value())
123+
124+ ''' screenoff can never be shorter than screenblank-timeout '''
125+ if off_timeout <= blank_timeout:
126+ self.screenblank_timeout.set_value(off_timeout)
127+
128+ def use_lightlocker_cb(self, switch, gparam):
129+ '''Update the displayed lock controls when light-locker is enabled or
130+ disabled.'''
131+ ''' if on then allow for the timeout to be set '''
132+ self.locksettings_changed = True
133+ self.apply.set_sensitive(True)
134+ if switch.get_active():
135+ self.lock_delay.set_sensitive(False)
136+ self.session_lock_combo.set_sensitive(False)
137+ self.lock_on_suspend.set_sensitive(False)
138+ else:
139+ self.session_lock_combo.set_sensitive(True)
140+ self.lock_on_suspend.set_sensitive(True)
141+ if self.session_lock_combo.get_active() != 2:
142+ self.lock_delay.set_sensitive(True)
143+
144+ def on_session_lock_combo_changed(self, widget):
145+ '''Update the displayed screen blanking controls when locking is
146+ enabled or disabled.'''
147+ self.locksettings_changed = True
148+ self.apply.set_sensitive(True)
149+
150+ # Check the session lock combo:
151+ # 0. lock when screensaver is activated
152+ # 1. lock when screensaver is deactivated
153+ # 2. never lock
154+ active = widget.get_active()
155+ self.lock_delay.set_sensitive(active != 2)
156+
157+ def lock_delay_value_changed_cb(self, gparam):
158+ '''Enable saving of lock setting when the delay has been modified.'''
159+ self.locksettings_changed = True
160+ self.apply.set_sensitive(True)
161+
162+ def lock_on_suspend_cb(self, widget, gparam):
163+ '''Enable saving when locking on suspend is changed.'''
164+ self.locksettings_changed = True
165+ self.apply.set_sensitive(True)
166+
167+ def apply_cb(self, button, data=None):
168+ '''Apply changes and update the relevant setting files.'''
169+ ''' Check whether the autostart-directory exists and if not
170+ create it '''
171+ autostart_dir = os.path.dirname(self.user_desktop_file)
172+ if not os.path.exists(autostart_dir):
173+ os.makedirs(autostart_dir)
174+
175+ self.apply_settings()
176+ self.apply.set_sensitive(False)
177+
178+ def on_window_destroy(self, *args):
179+ '''Exit the application when the window is closed.'''
180+ Gtk.main_quit()
181+
182+ def on_close_clicked(self, *args):
183+ '''Exit the application when the window is closed.'''
184+ Gtk.main_quit()
185+
186+# Process Management
187+ def check_running_process(self, process_name):
188+ """Return True if the specified process is active."""
189+ # Find the process...
190+ for pid in psutil.get_pid_list():
191+ p = psutil.Process(pid)
192+ if p.username == username:
193+ # When found, end the light-locker process.
194+ try:
195+ if os.path.basename(p.exe) == process_name:
196+ return True
197+ except psutil._error.AccessDenied:
198+ pass
199+ return False
200+
201+ def stop_light_locker(self):
202+ """Safely stop the light-locker process."""
203+ # Find the process...
204+ for pid in psutil.get_pid_list():
205+ p = psutil.Process(pid)
206+ if p.username == username:
207+ # When found, end the light-locker process.
208+ try:
209+ if os.path.basename(p.exe) == 'light-locker':
210+ p.terminate()
211+ except psutil._error.AccessDenied:
212+ pass
213+
214 def run_command(self, cmd, check_output=False):
215 '''Run a shell command, return its output.'''
216 if len(cmd) == 0:
217@@ -137,18 +226,62 @@
218 subprocess.Popen(cmd.split(" "))
219 return None
220
221- def stop_light_locker(self):
222- """Safely stop the light-locker process."""
223- # Find the process...
224- for pid in psutil.get_pid_list():
225- p = psutil.Process(pid)
226- if p.username == username:
227- # When found, end the light-locker process.
228- try:
229- if os.path.basename(p.exe) == 'light-locker':
230- p.terminate()
231- except psutil._error.AccessDenied:
232- pass
233+# Settings Parsing
234+ def init_settings(self):
235+ # Get the Settings, first from light-locker, then override as needed
236+ ''' if there is a file exists in ~/.config/autostart/ parse that
237+ for current settings picked by the user else load in the
238+ systemwide '''
239+ if os.path.isfile(self.user_desktop_file):
240+ desktop_file = self.user_desktop_file
241+ else:
242+ desktop_file = self.systemwide_desktop_file
243+ settings = self.read_in_desktop(desktop_file)
244+ use_light_locker = settings['light-locker-enabled']
245+ lock_after_screensaver = settings['lock-after-screensaver']
246+ late_locking = settings['late-locking']
247+ lock_on_suspend = settings['lock-on-suspend']
248+ lock_time = settings['lock-time']
249+ screen_blank_timeout, screen_off_timeout = \
250+ self.get_screen_blank_timeout()
251+
252+ # Replace settings with xfce4-session
253+ if self.check_running_process("xfce4-session"):
254+ session_sync = light_locker_xfsync.XfceSessionSync()
255+ lock_on_suspend = session_sync.get_lock()
256+
257+ # Replace settings with xfce4-power-manager
258+ if self.check_running_process("xfce4-power-manager"):
259+ xfpm_sync = light_locker_xfsync.XfpmSync()
260+ screen_blank_timeout, screen_off_timeout = xfpm_sync.get_dpms()
261+ screen_blank_timeout = self.light_locker_time_down_scaler(
262+ screen_blank_timeout)
263+ screen_off_timeout = self.light_locker_time_down_scaler(
264+ screen_off_timeout)
265+
266+ # Apply the settings
267+ self.use_lightlocker.set_active(use_light_locker)
268+ self.session_lock_combo.set_sensitive(use_light_locker)
269+ self.lock_on_suspend.set_sensitive(use_light_locker)
270+
271+ self.lock_delay.set_value(lock_time)
272+
273+ if lock_after_screensaver:
274+ self.lock_delay.set_sensitive(True)
275+ if late_locking:
276+ self.session_lock_combo.set_active(1)
277+ else:
278+ self.session_lock_combo.set_active(0)
279+ else:
280+ self.lock_delay.set_sensitive(False)
281+ self.session_lock_combo.set_active(2)
282+
283+ self.lock_on_suspend.set_active(lock_on_suspend)
284+
285+ blank = self.light_locker_time_down_scaler(screen_blank_timeout)
286+ off = self.light_locker_time_down_scaler(screen_off_timeout)
287+ self.screenblank_timeout.set_value(blank)
288+ self.screenoff_timeout.set_value(off)
289
290 def read_in_desktop(self, filepath):
291 '''Parse the .desktop file for light-locker settings.'''
292@@ -156,7 +289,7 @@
293 self.content = f.readlines()
294 for line in self.content:
295 if line.startswith("Exec="):
296- self.parse_options(line)
297+ return self.parse_options(line)
298
299 def parse_options(self, options_line):
300 '''Parse command-line arguments from the Exec line.'''
301@@ -197,107 +330,44 @@
302 if args.lock_on_suspend:
303 lock_on_suspend = True
304
305- # Apply the settings
306- self.use_lightlocker.set_active(use_light_locker)
307- self.session_lock_combo.set_sensitive(use_light_locker)
308- self.lock_on_suspend.set_sensitive(use_light_locker)
309-
310- self.lock_delay.set_value(lock_time)
311-
312- if lock_after_screensaver:
313- self.lock_delay.set_sensitive(True)
314- if late_locking:
315- self.session_lock_combo.set_active(1)
316- else:
317- self.session_lock_combo.set_active(0)
318- else:
319- self.lock_delay.set_sensitive(False)
320- self.session_lock_combo.set_active(2)
321-
322- self.lock_on_suspend.set_active(lock_on_suspend)
323-
324- def write_light_locker_file(self, filepath, light_locker_command):
325- '''Write the updated light-locker settings to its .desktop file.'''
326- exec_str = "Exec=%s\n" % light_locker_command
327- with open(filepath, 'w') as f:
328- for line in self.content:
329- if line.startswith("Exec="):
330- f.write(exec_str)
331- else:
332- f.write(line)
333-
334- def write_screensaver_file(self, filepath, screensaver_command):
335- '''Write the updated screensaver settings to its .desktop file.'''
336- with open(filepath, 'w') as f:
337- f.write(
338- "[Desktop Entry]\n"
339- "Name=%s\n"
340- "Comment=%s\n"
341- "Exec=%s\n"
342- % (_("Screensaver"), _("Set screensaver timeouts"),
343- screensaver_command))
344-
345- def use_lightlocker_cb(self, switch, gparam):
346- '''Update the displayed lock controls when light-locker is enabled or
347- disabled.'''
348- ''' if on then allow for the timeout to be set '''
349- self.locksettings_changed = True
350- self.apply.set_sensitive(True)
351- if switch.get_active():
352- self.lock_delay.set_sensitive(False)
353- self.session_lock_combo.set_sensitive(False)
354- self.lock_on_suspend.set_sensitive(False)
355- else:
356- self.session_lock_combo.set_sensitive(True)
357- self.lock_on_suspend.set_sensitive(True)
358- if self.session_lock_combo.get_active() != 2:
359- self.lock_delay.set_sensitive(True)
360-
361- def on_session_lock_combo_changed(self, widget):
362- '''Update the displayed screen blanking controls when locking is
363- enabled or disabled.'''
364- self.locksettings_changed = True
365- self.apply.set_sensitive(True)
366-
367- # Check the session lock combo:
368- # 0. lock when screensaver is activated
369- # 1. lock when screensaver is deactivated
370- # 2. never lock
371- active = widget.get_active()
372- self.lock_delay.set_sensitive(active != 2)
373-
374- def lock_on_suspend_cb(self, widget, gparam):
375- '''Enable saving when locking on suspend is changed.'''
376- self.locksettings_changed = True
377- self.apply.set_sensitive(True)
378-
379- def screenblank_value_changed_cb(self, gparam):
380- '''Sync screenblank and screenoff settings when values are modified.'''
381- self.apply.set_sensitive(True)
382-
383- blank_timeout = int(self.screenblank_timeout.get_value())
384- off_timeout = int(self.screenoff_timeout.get_value())
385-
386- ''' screenoff can never be shorter than screenblank-timeout '''
387- if (blank_timeout >= off_timeout) and (off_timeout != 0):
388- self.screenoff_timeout.set_value(blank_timeout)
389-
390- def screenoff_value_changed_cb(self, gparam):
391- '''Sync screenblank and screenoff settings when values are modified.'''
392- self.apply.set_sensitive(True)
393-
394- blank_timeout = int(self.screenblank_timeout.get_value())
395- off_timeout = int(self.screenoff_timeout.get_value())
396-
397- ''' screenoff can never be shorter than screenblank-timeout '''
398- if off_timeout <= blank_timeout:
399- self.screenblank_timeout.set_value(off_timeout)
400-
401- def lock_delay_value_changed_cb(self, gparam):
402- '''Enable saving of lock setting when the delay has been modified.'''
403- self.locksettings_changed = True
404- self.apply.set_sensitive(True)
405-
406+ settings = dict()
407+ settings['light-locker-enabled'] = use_light_locker
408+ settings['lock-after-screensaver'] = lock_after_screensaver
409+ settings['late-locking'] = late_locking
410+ settings['lock-on-suspend'] = lock_on_suspend
411+ settings['lock-time'] = lock_time
412+
413+ return settings
414+
415+ def get_screen_blank_timeout(self):
416+ ''' read in the X11 screensaver settings from bash '''
417+ # Defaults
418+ screen_blank = 10
419+ screen_off = 15
420+
421+ # Get the xset output to parse.
422+ screensaver_output = self.run_command('xset q', check_output=True)
423+
424+ # Get the Screen-Blank timeout
425+ screenblank_timeout_grep = re.search(
426+ "timeout: *(\d+)", screensaver_output)
427+ if screenblank_timeout_grep:
428+ screenblank_timeout = re.findall(
429+ '\d+', screenblank_timeout_grep.group(1))
430+ screen_blank = int(screenblank_timeout[0]) / 60
431+
432+ # Get the Screen-Off timeout
433+ screenoff_timeout_grep = re.search(
434+ "Standby: *(\d+)", screensaver_output)
435+ if screenoff_timeout_grep:
436+ screenoff_timeout = re.findall(
437+ '\d+', screenoff_timeout_grep.group(1))
438+ screen_off = int(screenoff_timeout[0]) / 60
439+
440+ # Return the current timeout settings
441+ return screen_blank, screen_off
442+
443+# Label Formatters
444 def screensaver_label_formatter(self, screenblank_timeout, max_value):
445 '''Convert timeout values to a more friendly format.'''
446 value = int(screenblank_timeout.get_value())
447@@ -316,6 +386,15 @@
448 formatted_string = self.secs_to_readable(value)
449 return formatted_string
450
451+ def secs_to_readable(self, seconds):
452+ '''Convert seconds to a more friendly format.'''
453+ if seconds >= 60:
454+ minutes = seconds / 60
455+ return ngettext("%d minute", "%d minutes", minutes) % (minutes,)
456+ else:
457+ return ngettext("%d second", "%d seconds", seconds) % (seconds,)
458+
459+# Time Scalers
460 def light_locker_time_up_scaler(self, time):
461 '''Scale times up.'''
462 if time > 60:
463@@ -328,49 +407,94 @@
464 time = time / 60 + 60
465 return time
466
467- def apply_cb(self, button, data=None):
468- '''Apply changes and update the relevant setting files.'''
469- ''' Check whether the autostart-directory exists and if not
470- create it '''
471- autostart_dir = os.path.dirname(self.user_desktop_file)
472- if not os.path.exists(autostart_dir):
473- os.makedirs(autostart_dir)
474-
475- # Apply changes.
476- self.apply_light_locker_settings()
477- self.apply_screen_blank_settings()
478-
479- self.apply.set_sensitive(False)
480-
481- def apply_light_locker_settings(self):
482- '''Apply the light-locker settings'''
483- # Stop any running light-locker processes.
484- self.stop_light_locker()
485-
486+# Settings Writing
487+ def get_updated_settings(self):
488+ """Return a dictionary with the updated settings from the GUI."""
489 # Get the lock-after-screensaver timeout.
490 session_lock = self.session_lock_combo.get_active()
491 if session_lock == 2: # never lock with screensaver
492- late_locking = ""
493- timeout = "0"
494+ late_locking = False
495+ lock_delay = 0
496 else:
497 if session_lock == 0: # lock when screensaver is activated
498- late_locking = "--no-late-locking"
499+ late_locking = False
500 if session_lock == 1: # lock when screensaver is deactivated
501- late_locking = "--late-locking"
502- lock_delay_scaled = self.light_locker_time_up_scaler(
503+ late_locking = True
504+ lock_delay = self.light_locker_time_up_scaler(
505 int(self.lock_delay.get_value()))
506- timeout = str(lock_delay_scaled)
507- lock_after_screensaver = "--lock-after-screensaver=" + timeout
508+
509+ # Lock Enabled?
510+ lock_enabled = self.use_lightlocker.get_active()
511
512 # Get the suspend setting.
513- if self.lock_on_suspend.get_active():
514+ lock_on_suspend = self.lock_on_suspend.get_active()
515+
516+ # Get the screen-blank and screen-off timeout.
517+ screenblank_timeout = \
518+ int(self.screenblank_timeout.get_value()) * 60
519+ screenoff_timeout = int(self.screenoff_timeout.get_value()) * 60
520+
521+ settings = {
522+ "lock-enabled": lock_enabled,
523+ "late-locking": late_locking,
524+ "lock-after-screensaver": lock_delay,
525+ "lock-on-suspend": lock_on_suspend,
526+ "screen-blank-timeout": screenblank_timeout,
527+ "screen-off-timeout": screenoff_timeout
528+ }
529+
530+ return settings
531+
532+ def apply_settings(self):
533+ """Apply updated settings."""
534+ # Get the current settings from the GUI.
535+ settings = self.get_updated_settings()
536+
537+ # If xfce4-sesssion is running, sync the lock-on-suspend setting.
538+ if self.check_running_process("xfce4-session"):
539+ session_sync = light_locker_xfsync.XfceSessionSync()
540+ session_sync.set_lock(settings['lock-on-suspend'])
541+
542+ # If xfce4-session manages locking, disable it for light-locker.
543+ settings['lock-on-suspend'] = False
544+
545+ # If xfce4-power-manager is running, sync the DPMS settings.
546+ if self.check_running_process("xfce4-power-manager"):
547+ xfpm_sync = light_locker_xfsync.XfpmSync()
548+ screen_off = settings['screen-off-timeout'] / 60
549+ screen_blank = settings['screen-blank-timeout'] / 60
550+ xfpm_sync.set_dpms(screen_blank, screen_off)
551+
552+ # Apply the remaining settings to light-locker.
553+ self.apply_light_locker_settings(settings)
554+ self.apply_screen_blank_settings(settings)
555+
556+ def apply_light_locker_settings(self, settings):
557+ '''Apply the light-locker settings'''
558+ # Stop any running light-locker processes.
559+ self.stop_light_locker()
560+
561+ lock_enabled = settings['lock-enabled']
562+ late_locking = settings['late-locking']
563+ lock_on_suspend = settings['lock-on-suspend']
564+ lock_after_screensaver = settings['lock-after-screensaver']
565+
566+ if late_locking:
567+ late_locking = "--late-locking"
568+ else:
569+ late_locking = "--no-late-locking"
570+
571+ if lock_on_suspend:
572 lock_on_suspend = "--lock-on-suspend"
573 else:
574 lock_on_suspend = "--no-lock-on-suspend"
575
576+ lock_after_screensaver = "--lock-after-screensaver=%i" % \
577+ lock_after_screensaver
578+
579 # Build the light-locker command.
580 light_locker_exec = ""
581- if self.use_lightlocker.get_active():
582+ if lock_enabled:
583 light_locker_exec = \
584 "light-locker %s %s %s" % (lock_after_screensaver,
585 lock_on_suspend, late_locking)
586@@ -381,16 +505,14 @@
587 # Execute the updated light-locker command.
588 self.run_command(light_locker_exec)
589
590- def apply_screen_blank_settings(self):
591+ def apply_screen_blank_settings(self, settings):
592 '''Apply the screen blank settings.'''
593- # Get the screen-blank and screen-off timeout.
594- screenblank_timeout = str(
595- int(self.screenblank_timeout.get_value()) * 60)
596- screenoff_timeout = str(int(self.screenoff_timeout.get_value()) * 60)
597+ screenblank_timeout = settings['screen-blank-timeout']
598+ screenoff_timeout = settings['screen-off-timeout']
599
600 # Build the screen-blank/off command.
601 screensaver_exec = \
602- "xset s %s dpms %s 0 0" % (screenblank_timeout, screenoff_timeout)
603+ "xset s %i dpms %i 0 0" % (screenblank_timeout, screenoff_timeout)
604
605 # Execute the updated screensaver command.
606 self.run_command(screensaver_exec)
607@@ -399,24 +521,26 @@
608 self.write_screensaver_file(
609 self.screenblank_timeout_desktop_file, screensaver_exec)
610
611- # Does this command really need to be run after we run the right one?
612- #self.run_command('xset s ' + screenblank_timeout)
613-
614- def secs_to_readable(self, seconds):
615- '''Convert seconds to a more friendly format.'''
616- if seconds >= 60:
617- minutes = seconds / 60
618- return ngettext("%d minute", "%d minutes", minutes) % (minutes,)
619- else:
620- return ngettext("%d second", "%d seconds", seconds) % (seconds,)
621-
622- def on_window_destroy(self, *args):
623- '''Exit the application when the window is closed.'''
624- Gtk.main_quit()
625-
626- def on_close_clicked(self, *args):
627- '''Exit the application when the window is closed.'''
628- Gtk.main_quit()
629+ def write_light_locker_file(self, filepath, light_locker_command):
630+ '''Write the updated light-locker settings to its .desktop file.'''
631+ exec_str = "Exec=%s\n" % light_locker_command
632+ with open(filepath, 'w') as f:
633+ for line in self.content:
634+ if line.startswith("Exec="):
635+ f.write(exec_str)
636+ else:
637+ f.write(line)
638+
639+ def write_screensaver_file(self, filepath, screensaver_command):
640+ '''Write the updated screensaver settings to its .desktop file.'''
641+ with open(filepath, 'w') as f:
642+ f.write(
643+ "[Desktop Entry]\n"
644+ "Name=%s\n"
645+ "Comment=%s\n"
646+ "Exec=%s\n"
647+ % (_("Screensaver"), _("Set screensaver timeouts"),
648+ screensaver_command))
649
650
651 if __name__ == "__main__":
652
653=== added file 'light-locker-settings/light_locker_xfsync.py'
654--- light-locker-settings/light_locker_xfsync.py 1970-01-01 00:00:00 +0000
655+++ light-locker-settings/light_locker_xfsync.py 2014-04-04 10:52:41 +0000
656@@ -0,0 +1,177 @@
657+import subprocess
658+
659+
660+def convert_value(value):
661+ """Make output agreeable to xfconf."""
662+ if isinstance(value, bool):
663+ if value is True:
664+ value = 'true'
665+ else:
666+ value = 'false'
667+ return value
668+
669+
670+def xfconf_init_property(channel, p_name, p_type, initial_value):
671+ """Initialize the specified xfconf property."""
672+ p_type = p_type.__name__
673+ initial_value = str(convert_value(initial_value))
674+ cmd = 'xfconf-query -c %s -p %s -n -s %s -t %s' % (channel, p_name,
675+ initial_value, p_type)
676+ subprocess.call(cmd.split())
677+
678+
679+def xfconf_list_properties(channel):
680+ """List the properties defined for the given channel."""
681+ settings = dict()
682+ cmd = 'xfconf-query -c %s -l -v' % channel
683+ for line in subprocess.check_output(cmd, shell=True).split('\n'):
684+ try:
685+ key, value = line.split(None, 1)
686+ except ValueError:
687+ key = line.strip()
688+ value = ""
689+ if str.isdigit(value):
690+ value = int(value)
691+ elif value.lower() in ['true', 'false']:
692+ value = value.lower() == 'true'
693+ else:
694+ value = str(value)
695+ settings[key] = value
696+ return settings
697+
698+
699+def xfconf_set_property(channel, prop, value):
700+ """Set the specified xfconf property."""
701+ value = str(value).lower()
702+ cmd = 'xfconf-query -c %s -p %s -s %s' % (channel, prop, value)
703+ subprocess.call(cmd.split())
704+
705+
706+class XfceSessionSync():
707+ """
708+ Class to set/get xfce4-session lock settings.
709+ """
710+ def __init__(self):
711+ """Initialize the XfceSessionSync instance."""
712+ self.settings = {'/shutdown/LockScreen': False}
713+ current_settings = self._get_xfce4_session_settings()
714+ self._update_settings(current_settings)
715+ self._init_xfconf_properties(current_settings)
716+
717+ def _init_xfconf_properties(self, current_settings):
718+ """If xfce4-session has not been configured, some of its properties
719+ may not exist. Create any missing properties."""
720+ channel = 'xfce4-session'
721+ for key, value in list(self.settings.items()):
722+ if key not in list(current_settings.keys()):
723+ xfconf_init_property(channel, key, type(value), value)
724+
725+ def _get_xfce4_session_settings(self):
726+ """Return a dictionary of the xfce4-session settings."""
727+ return xfconf_list_properties('xfce4-session')
728+
729+ def _update_settings(self, settings):
730+ """Update the internal settings."""
731+ for key, value in list(settings.items()):
732+ if key in list(self.settings.keys()):
733+ self.settings[key] = value
734+
735+ def get_lock(self):
736+ """Return True if Lock on Sleep is enabled."""
737+ return self.settings['/shutdown/LockScreen']
738+
739+ def set_lock(self, value):
740+ """Set the Lock on Sleep setting."""
741+ xfconf_set_property('xfce4-session', '/shutdown/LockScreen', value)
742+ self.settings['/shutdown/LockScreen'] = value
743+
744+
745+class XfpmSync():
746+ """
747+ Class to set/get xserver dpms timings via xfpm, thus keeping xfpm in sync.
748+ """
749+ def __init__(self):
750+ '''Following settings should concur with xfpm defaults'''
751+ self.settings = {'/xfce4-power-manager/dpms-enabled': True,
752+ '/xfce4-power-manager/dpms-on-battery-sleep': 5,
753+ '/xfce4-power-manager/dpms-on-battery-off': 10,
754+ '/xfce4-power-manager/dpms-on-ac-sleep': 10,
755+ '/xfce4-power-manager/dpms-on-ac-off': 15,
756+ }
757+ current_settings = self._get_xfpm_settings()
758+ self._update_settings(current_settings)
759+ self._init_xfconf_properties(current_settings)
760+
761+ def _init_xfconf_properties(self, current_settings):
762+ """
763+ If xfpm has never been used, some xfconf channel properties may not be
764+ set. Ensures that we don't get complains about missing properties.
765+ """
766+ channel = 'xfce4-power-manager'
767+ for key, value in list(self.settings.items()):
768+ if key not in list(current_settings.keys()):
769+ xfconf_init_property(channel, key, type(value), value)
770+
771+ def _get_power_state(self):
772+ """
773+ Get the power state from /sys/class/power_supply/AC/online if present.
774+ Returns:
775+ 1: AC connected
776+ 0: AC disconnected
777+ (Do we always have this file, if a battery is present?)
778+ """
779+ try:
780+ with open('/sys/class/power_supply/AC/online', 'rb') as f:
781+ pstate = int(f.readline())
782+ except:
783+ pstate = 1
784+
785+ return pstate
786+
787+ def _get_xfpm_settings(self):
788+ """Returns xfpm xfconf settings as string"""
789+ return xfconf_list_properties('xfce4-power-manager')
790+
791+ def _update_settings(self, settings):
792+ """Update the internal settings."""
793+ for key, value in list(settings.items()):
794+ if key in list(self.settings.keys()):
795+ self.settings[key] = value
796+
797+ def _get_timings_scope(self):
798+ """Return the timings scope (Batter or AC)."""
799+ if self._get_power_state() == 0:
800+ sleep = '/xfce4-power-manager/dpms-on-battery-sleep'
801+ off = '/xfce4-power-manager/dpms-on-battery-off'
802+ else: # we assume on ac for all other cases
803+ sleep = '/xfce4-power-manager/dpms-on-ac-sleep'
804+ off = '/xfce4-power-manager/dpms-on-ac-off'
805+
806+ return sleep, off
807+
808+ def set_dpms(self, sleep_time, off_time):
809+ """
810+ For most monitors *_sleep and *_off have probably the same outcome.
811+ So, basically we set the lower value for the corresponding power state.
812+ But xfpm ignores settings not in:
813+ 0 <= *_sleep <= *_off
814+ or
815+ *_off == 0 and *_sleep >= 0
816+ i.e. sometimes we have to adapt both.
817+ """
818+ sleep, off = self._get_timings_scope()
819+
820+ if not (sleep_time == 0 and off_time == 0):
821+ if sleep_time + 1 > off_time:
822+ off_time = sleep_time + 1
823+
824+ xfconf_set_property('xfce4-power-manager', off, off_time)
825+ self.settings[off] = off_time
826+
827+ xfconf_set_property('xfce4-power-manager', sleep, sleep_time)
828+ self.settings[sleep] = sleep_time
829+
830+ def get_dpms(self):
831+ """Return the current DPMS timeouts."""
832+ sleep, off = self._get_timings_scope()
833+ return self.settings[sleep], self.settings[off]

Subscribers

People subscribed via source and target branches

to all changes: