-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
723a430
commit c5e2306
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
option('enable-xscreensaver-plugin', | ||
type: 'boolean', | ||
value: true, | ||
description: 'Build plugin for XScreenSaver support' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
class Caffeine.Plugins.XScreenSaver : Peas.ExtensionBase, Peas.Activatable { | ||
private uint source_id = 0U; | ||
private int timeout_duration = 0; | ||
private int timeout_offset = -5; | ||
private File xscreensaver_preferences_file; | ||
|
||
public Object object { owned get; construct; } | ||
|
||
public XScreenSaver () { | ||
Object (); | ||
} | ||
|
||
construct { | ||
xscreensaver_preferences_file = File.new_build_filename ( | ||
Environment.get_home_dir (), ".xscreensaver"); | ||
|
||
if (!xscreensaver_preferences_file.query_exists ()) | ||
error ("~/.xscreensaver not found."); | ||
|
||
var xscreensaver_preferences_file_monitor = xscreensaver_preferences_file.monitor_file (FileMonitorFlags.NONE, null); | ||
|
||
xscreensaver_preferences_file_monitor.changed.connect ((src, dest, event) => { | ||
if (event == FileMonitorEvent.CHANGED) | ||
on_xscreensaver_preferences_file_updated (); | ||
}); | ||
|
||
on_xscreensaver_preferences_file_updated (); | ||
|
||
this.notify["timeout_duration"].connect (() => { | ||
if (source_id == 0U) | ||
deactivate_screensaver (); | ||
}); | ||
} | ||
|
||
public void activate () { | ||
deactivate_screensaver (); | ||
} | ||
|
||
public void deactivate () { | ||
if (source_id != 0U) { | ||
Source.remove (source_id); | ||
source_id = 0U; | ||
} | ||
} | ||
|
||
public void update_state () {} | ||
|
||
private void deactivate_screensaver (int? interval = null) { | ||
if (interval == null) | ||
interval = timeout_duration; | ||
|
||
if (source_id != 0U) | ||
Source.remove (source_id); | ||
|
||
source_id = Timeout.add_seconds (interval + timeout_offset, () => { | ||
var success = false; | ||
string[] spawn_args = { "xscreensaver-command", "-deactivate" }; | ||
string[] spawn_env = Environ.get (); | ||
|
||
try { | ||
Process.spawn_sync ( | ||
Environment.get_home_dir (), | ||
spawn_args, | ||
spawn_env, | ||
SpawnFlags.SEARCH_PATH, | ||
null, | ||
null); | ||
|
||
success = true; | ||
} catch (Error err) { | ||
error (@"unable to spawn process"); | ||
} | ||
|
||
return success; | ||
}); | ||
} | ||
|
||
private void on_xscreensaver_preferences_file_updated () { | ||
try { | ||
var dis = new DataInputStream ( | ||
xscreensaver_preferences_file.read ()); | ||
|
||
string line; | ||
while ((line = dis.read_line (null)) != null) { | ||
string[] preference = line.split (":", 2); | ||
unowned string key = preference[0]; | ||
|
||
if (key.strip () == "timeout") { | ||
int timeout_duration = -1; | ||
string[] time = preference[1].split (":"); | ||
|
||
for (int i = 0 ; i < time.length ; i++) | ||
timeout_duration += int.parse (time[i].strip ()) * (i == (time.length - 1) ? 1 : 60); | ||
|
||
if (timeout_duration != -1) | ||
this.timeout_duration = timeout_duration; | ||
|
||
break; | ||
} | ||
} | ||
} catch (Error err) { | ||
error ("unable to parse preferences file"); | ||
} | ||
} | ||
|
||
} | ||
|
||
[ModuleInit] | ||
public void peas_register_types (GLib.TypeModule module) { | ||
Peas.ObjectModule object_module = module as Peas.ObjectModule; | ||
|
||
object_module.register_extension_type ( | ||
typeof (Peas.Activatable), | ||
typeof (Caffeine.Plugins.XScreenSaver)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
shared_library('xscreensaver', | ||
[ | ||
'Main.vala' | ||
], | ||
dependencies: [ | ||
libpeas_dep | ||
], | ||
install: true, | ||
install_dir: join_paths(pkgpluginslibdir, 'xscreensaver'), | ||
) | ||
|
||
i18n.merge_file( | ||
type: 'desktop', | ||
input: 'xscreensaver.plugin.in', | ||
output: 'xscreensaver.plugin', | ||
po_dir: po_dir, | ||
install: true, | ||
install_dir: join_paths(pkgpluginslibdir, 'xscreensaver') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Plugin] | ||
Module=xscreensaver.so | ||
Name=XScreenSaver | ||
Description=XScreenSaver support for Caffeine. | ||
Authors=Payson Wallach <payson@paysonwallach.com> | ||
Copyright=Copyright © 2020 Payson Wallach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if get_option('enable-xscreensaver-plugin') | ||
subdir('XScreenSaverPlugin') | ||
endif |