From 38519d824280535c16dd28ef964666e7cb53538e Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sun, 12 Jan 2025 18:56:22 +0000 Subject: [PATCH 1/3] Add screendimming using our dim/undim dbus routine via swayidle --- src/daemon/screenlock.vala | 62 +++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/src/daemon/screenlock.vala b/src/daemon/screenlock.vala index cd5a9c8d2..90eea5b1b 100644 --- a/src/daemon/screenlock.vala +++ b/src/daemon/screenlock.vala @@ -12,11 +12,23 @@ namespace Budgie { const string DBUS_SCREENLOCK = "org.buddiesofbudgie.BudgieScreenlock"; const string DBUS_SCREENLOCK_PATH = "/org/buddiesofbudgie/Screenlock"; + const string POWERSCREEN_DBUS_NAME = "org.gnome.SettingsDaemon.Power"; + const string POWERSCREEN_DBUS_OBJECT_PATH = "/org/gnome/SettingsDaemon/Power"; + + [DBus (name="org.gnome.SettingsDaemon.Power.Screen")] + public interface PowerScreenRemote : GLib.Object { + public abstract int32 Brightness { get; set; } + } [DBus (name="org.buddiesofbudgie.BudgieScreenlock")] public class Screenlock { static Screenlock? instance; + // Screen Dim capability + PowerScreenRemote? powerscreen_proxy = null; + bool isdimmable = false; + int32 current_brightness = 0; + // connections to various schemas used in screenlocking private GLib.Settings power; private GLib.Settings session; @@ -34,6 +46,16 @@ namespace Budgie { private GLib.GenericArray devices; private bool battery_mode; + private string calculate_dim() { + isdimmable = this.power.get_boolean("idle-dim"); + + if (!isdimmable) return ""; + + var dbus_call = "timeout 30 'dbus-send --type=method_call --dest=org.buddiesofbudgie.BudgieScreenlock /org/buddiesofbudgie/Screenlock org.buddiesofbudgie.BudgieScreenlock.Dim' "; + dbus_call += "resume 'dbus-send --type=method_call --dest=org.buddiesofbudgie.BudgieScreenlock /org/buddiesofbudgie/Screenlock org.buddiesofbudgie.BudgieScreenlock.Undim' "; + return dbus_call; + } + private string calculate_lockcommand() { string output = ""; @@ -155,6 +177,8 @@ namespace Budgie { new_idle = "swayidle -w "; + new_idle += calculate_dim(); + if (idle_delay !=0 ) { new_idle += "timeout " + idle_delay.to_string() + " 'wlopm --off \\*' resume 'wlopm --on \\*' "; } @@ -196,6 +220,15 @@ namespace Budgie { } } + /* Hold onto our PowerScreen proxy ref */ + void on_powerscreen_get(Object? o, AsyncResult? res) { + try { + powerscreen_proxy = Bus.get_proxy.end(res); + } catch (Error e) { + warning("Failed to get PowerScreen proxy: %s", e.message); + } + } + [DBus (visible = false)] public void setup_dbus() { /* Hook up screenlock dbus */ @@ -205,6 +238,27 @@ namespace Budgie { () => {} ); } + public async void dim() throws GLib.DBusError, GLib.IOError { + if (powerscreen_proxy == null) { + return; + } + + current_brightness = powerscreen_proxy.Brightness; + int32 idle_brightness = power.get_int("idle-brightness"); + + if (current_brightness > idle_brightness) { + powerscreen_proxy.Brightness = idle_brightness; + } + } + + public async void undim() throws GLib.DBusError, GLib.IOError { + if (powerscreen_proxy == null) { + return; + } + + powerscreen_proxy.Brightness = current_brightness; + } + void on_bus_acquired(DBusConnection conn) { try { conn.register_object(DBUS_SCREENLOCK_PATH, this); @@ -215,7 +269,6 @@ namespace Budgie { public async void lock() throws GLib.DBusError, GLib.IOError { if (!all_apps) { - yield; return; } @@ -224,8 +277,6 @@ namespace Budgie { } catch (SpawnError e) { print("Error: %s\n", e.message); } - - yield; } [DBus (visible = false)] @@ -272,6 +323,8 @@ namespace Budgie { return; } + Bus.get_proxy.begin(BusType.SESSION, POWERSCREEN_DBUS_NAME, POWERSCREEN_DBUS_OBJECT_PATH, 0, null, on_powerscreen_get); + // Connect to upower and get notifications for all batteries and power-supplies to see if on battery mode client = new Up.Client(); client.notify.connect(this.client_daemon); @@ -289,7 +342,8 @@ namespace Budgie { string[] search = { "sleep-inactive-ac-timeout", "sleep-inactive-ac-type", "sleep-inactive-battery-timeout", - "sleep-inactive-battery-type"}; + "sleep-inactive-battery-type", + "idle-dim"}; if (key in search) { calculate_idle(); From 91a64458876b00ae3dacdc9d3226f80593b2ca24 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sun, 12 Jan 2025 19:27:46 +0000 Subject: [PATCH 2/3] Allow styling of gtklock using config files in the users home config folder --- src/daemon/screenlock.vala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/daemon/screenlock.vala b/src/daemon/screenlock.vala index 90eea5b1b..f6a7b52d5 100644 --- a/src/daemon/screenlock.vala +++ b/src/daemon/screenlock.vala @@ -90,16 +90,19 @@ namespace Budgie { /** * Try in order, and load the first one that exists: + * - ~/.config/budgie-desktop/[gtklock.ini | gtklock.css] * - /etc/budgie-desktop/[gtklock.ini | gtklock.css] * - /usr/share/budgie-desktop/[gtklock.ini | gtklock.css] */ - string[] system_configs = { + string[] lock_configs = { + "file://" + Environment.get_user_config_dir() + "/budgie-desktop/gtklock.ini", @"file://$(Budgie.CONFDIR)/budgie-desktop/gtklock.ini", @"file://$(Budgie.DATADIR)/budgie-desktop/gtklock.ini" }; - foreach (string? filepath in system_configs) { + foreach (string? filepath in lock_configs) { File file = File.new_for_uri(filepath); + warning(filepath); bool tmp = file.query_exists(); if (tmp) { // -c load the config file @@ -109,6 +112,7 @@ namespace Budgie { } string[] style_configs = { + "file://" + Environment.get_user_config_dir() + "/budgie-desktop/gtklock.css", @"file://$(Budgie.CONFDIR)/budgie-desktop/gtklock.css", @"file://$(Budgie.DATADIR)/budgie-desktop/gtklock.css" }; From 8747b84d1aae133cf102292e6bdb413561379eb2 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Fri, 17 Jan 2025 09:20:44 +0200 Subject: [PATCH 3/3] fix: remove warning --- src/daemon/screenlock.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/daemon/screenlock.vala b/src/daemon/screenlock.vala index f6a7b52d5..6d1d9b835 100644 --- a/src/daemon/screenlock.vala +++ b/src/daemon/screenlock.vala @@ -102,7 +102,6 @@ namespace Budgie { foreach (string? filepath in lock_configs) { File file = File.new_for_uri(filepath); - warning(filepath); bool tmp = file.query_exists(); if (tmp) { // -c load the config file