Skip to content

Commit

Permalink
Support gtklock as a screen-locker
Browse files Browse the repository at this point in the history
  • Loading branch information
fossfreedom committed Dec 23, 2024
1 parent beb0bba commit b2ecb72
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/daemon/manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Budgie {
xdg_tracker.setup_dbus(replace);


var screenlock = Screenlock.init();
screenlock = Screenlock.init();
screenlock.setup_dbus();
}

Expand Down
91 changes: 76 additions & 15 deletions src/daemon/screenlock.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,71 @@ namespace Budgie {
// public functions should check this variable first and exit gracefully where needed
bool all_apps = true;

// remember the locker to be used
private string locker = "";

private string calculate_lockcommand() {
// grab the background picture and strip the file prefix
string current_wallpaper = screensaver.get_string("picture-uri").replace("file://","");
string output = "";

// swaylock interprets : as a delimiter for the output name
// recommendation by swaylock is to replace : with ::
current_wallpaper = current_wallpaper.replace(":", "::");
if (locker == "swaylock") {
// grab the background picture and strip the file prefix
string current_wallpaper = screensaver.get_string("picture-uri").replace("file://","");

string output = "";
File file = File.new_for_path(current_wallpaper);
if (current_wallpaper == "" || !file.query_exists()) {
output = "-c 000000";
// swaylock interprets : as a delimiter for the output name
// recommendation by swaylock is to replace : with ::
current_wallpaper = current_wallpaper.replace(":", "::");

File file = File.new_for_path(current_wallpaper);
if (current_wallpaper == "" || !file.query_exists()) {
output = "-c 000000";
}
else {
output = "-i " + current_wallpaper;
}

output = "swaylock -Fklf " + output;
}
else {
output = "-i " + current_wallpaper;

if (locker == "gtklock") {
output = "gtklock -d";

/**
* Try in order, and load the first one that exists:
* - /etc/budgie-desktop/[gtklock.ini | gtklock.css]
* - /usr/share/budgie-desktop/[gtklock.ini | gtklock.css]
*/
string[] system_configs = {
@"file://$(Budgie.CONFDIR)/budgie-desktop/gtklock.ini",
@"file://$(Budgie.DATADIR)/budgie-desktop/gtklock.ini"
};

foreach (string? filepath in system_configs) {
File file = File.new_for_uri(filepath);
warning(filepath);
bool tmp = file.query_exists();
if (tmp) {
output += " -c " + file.get_path();
break;
}
}

string[] style_configs = {
@"file://$(Budgie.CONFDIR)/budgie-desktop/gtklock.css",
@"file://$(Budgie.DATADIR)/budgie-desktop/gtklock.css"
};

foreach (string? filepath in style_configs) {
File file = File.new_for_uri(filepath);
warning(filepath);
bool tmp = file.query_exists();
if (tmp) {
output += " -s " + file.get_path();
break;
}
}
}

return "swaylock -Fklf " + output;
return output;
}

private string calculate_sleep() {
Expand Down Expand Up @@ -184,16 +231,30 @@ namespace Budgie {
}

private Screenlock() {
string check_apps[] = {"wayidle", "killall", "wlopm", "swaylock", "upower", "systemctl"};
string check_apps[] = {"swayidle", "killall", "wlopm", "upower", "systemctl"};

foreach(unowned var app in check_apps) {
if (Environment.find_program_in_path("wayidle") != null) {
if (Environment.find_program_in_path(app) == null) {
warning(app + " is not found for screenlocking");
all_apps = false;
}
}

if (!all_apps) {
string supported_lockers[] = {"gtklock", "swaylock"};


foreach(unowned var app in supported_lockers) {
if (Environment.find_program_in_path(app) != null) {
locker = app;
break;
}
}

if (locker == "") {
warning("No supported screen-locker has been found");
}

if (!all_apps || locker == "") {
return;
}

Expand Down

0 comments on commit b2ecb72

Please sign in to comment.