Skip to content

Commit 74f8302

Browse files
authored
feat(daemon): rework our brightness handling to not use settings-daemon (BuddiesOfBudgie#822)
* Rework our brightness handling to not use settings-daemon * Switch to installing the helper to bin and ensure rc.xml points to the helper * Refactor brightness code to reduce code duplication
1 parent 844ba9a commit 74f8302

11 files changed

Lines changed: 875 additions & 106 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
2+
.TH USAGE: "1" "January 2026" "Usage: budgie-brightness-helper <command> [value]" "User Commands"
3+
.SH NAME
4+
Usage: \- manual page for Usage: budgie-brightness-helper <command> [value]
5+
.SH SYNOPSIS
6+
.B budgie-brightness-helper
7+
\fI\,<command> \/\fR[\fI\,value\/\fR]
8+
.SH DESCRIPTION
9+
.SS "Commands:"
10+
.TP
11+
up [step]
12+
Increase brightness by step percent (default: 5)
13+
.TP
14+
down [step]
15+
Decrease brightness by step percent (default: 5)
16+
.TP
17+
set <value>
18+
Set brightness to specific percentage (0\-100)
19+
.SH EXAMPLES
20+
.TP
21+
budgie\-brightness\-helper up
22+
# Increase by 5%
23+
.TP
24+
budgie\-brightness\-helper up 10
25+
# Increase by 10%
26+
.TP
27+
budgie\-brightness\-helper down
28+
# Decrease by 5%
29+
.TP
30+
budgie\-brightness\-helper set 50
31+
# Set to 50%
32+
.SS "Commands:"
33+
.TP
34+
up [step]
35+
Increase brightness by step percent (default: 5)
36+
.TP
37+
down [step]
38+
Decrease brightness by step percent (default: 5)
39+
.TP
40+
set <value>
41+
Set brightness to specific percentage (0\-100)
42+
.TP
43+
budgie\-brightness\-helper up
44+
# Increase by 5%
45+
.TP
46+
budgie\-brightness\-helper up 10
47+
# Increase by 10%
48+
.TP
49+
budgie\-brightness\-helper down
50+
# Decrease by 5%
51+
.TP
52+
budgie\-brightness\-helper set 50
53+
# Set to 50%
54+
.SH "SEE ALSO"
55+
The full documentation for
56+
.B Usage:
57+
is maintained as a Texinfo manual. If the
58+
.B info
59+
and
60+
.B Usage:
61+
programs are properly installed at your site, the command
62+
.IP
63+
.B info Usage:
64+
.PP
65+
should give you access to the complete manual.

docs/man/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ man_pages = [
66
'budgie-run-dialog.1',
77
'org.buddiesofbudgie.BudgieScreenshot.1',
88
'org.buddiesofbudgie.sendto.1',
9-
'startbudgielabwc.1'
9+
'startbudgielabwc.1',
10+
'budgie-brightness-helper.1'
1011
]
1112

1213
foreach man_page : man_pages

src/bridges/labwc/rc.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,10 @@
275275
<action name="ToggleSnapToEdge" direction="right" />
276276
</keybind>
277277
<keybind key="XF86MonBrightnessUp">
278-
<action name="Execute" command="dbus-send --session --type=method_call --dest=org.gnome.SettingsDaemon.Power /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.StepUp " />
278+
<action name="Execute" command="budgie-brightness-helper --up" />
279279
</keybind>
280280
<keybind key="XF86MonBrightnessDown">
281-
<action name="Execute" command="dbus-send --session --type=method_call --dest=org.gnome.SettingsDaemon.Power /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.StepDown " />
282-
</keybind>
283-
<keybind bridge="custom1" key="C-A-o">
284-
<action name="Execute" command="mate-sysmonitor" />
281+
<action name="Execute" command="budgie-brightness-helper --down" />
285282
</keybind>
286283
</keyboard>
287284
<theme>

src/daemon/brightness-helper.vala

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* This file is part of budgie-desktop
3+
*
4+
* Copyright Budgie Desktop Developers
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*/
11+
12+
/**
13+
* budgie-brightness-helper
14+
*
15+
* Simple command-line utility to adjust screen brightness
16+
* Designed to be called from keyboard shortcuts
17+
*/
18+
19+
namespace Budgie {
20+
/**
21+
* DBus interface for logind Session
22+
*/
23+
[DBus (name = "org.freedesktop.login1.Session")]
24+
interface LogindSession : GLib.Object {
25+
public abstract void SetBrightness(string subsystem, string name, uint32 brightness) throws DBusError, IOError;
26+
}
27+
28+
public class BrightnessHelper : GLib.Application {
29+
private BrightnessUtil util;
30+
private LogindSession? logind_session = null;
31+
32+
public BrightnessHelper() {
33+
Object(
34+
application_id: "org.buddiesofbudgie.BrightnessCLI",
35+
flags: ApplicationFlags.HANDLES_COMMAND_LINE
36+
);
37+
38+
// Add options to the application
39+
add_main_option("up", 'u', OptionFlags.NONE, OptionArg.NONE,
40+
"Increase brightness", null);
41+
add_main_option("down", 'd', OptionFlags.NONE, OptionArg.NONE,
42+
"Decrease brightness", null);
43+
add_main_option("set", 's', OptionFlags.NONE, OptionArg.INT,
44+
"Set brightness to PERCENT (0-100)", "PERCENT");
45+
add_main_option("step", 't', OptionFlags.NONE, OptionArg.INT,
46+
"Step size for up/down (default: 5)", "PERCENT");
47+
48+
util = new BrightnessUtil();
49+
}
50+
51+
public override int command_line(ApplicationCommandLine cmd) {
52+
var options = cmd.get_options_dict();
53+
54+
// Initialize hardware
55+
if (!util.find_backlight_device()) {
56+
cmd.printerr("Failed to find backlight device\n");
57+
return 1;
58+
}
59+
60+
if (!setup_logind_session()) {
61+
cmd.printerr("Failed to connect to logind session\n");
62+
return 1;
63+
}
64+
65+
// Get option values
66+
bool opt_up = options.contains("up");
67+
bool opt_down = options.contains("down");
68+
bool has_set = options.contains("set");
69+
int opt_set = has_set ? options.lookup_value("set", VariantType.INT32).get_int32() : -1;
70+
int opt_step = options.contains("step") ?
71+
options.lookup_value("step", VariantType.INT32).get_int32() : 5;
72+
73+
// Validate step size
74+
if (opt_step < 1 || opt_step > 100) {
75+
cmd.printerr("Error: step must be between 1 and 100\n");
76+
return 1;
77+
}
78+
79+
// Process commands (mutually exclusive)
80+
int commands_given = 0;
81+
if (opt_up) commands_given++;
82+
if (opt_down) commands_given++;
83+
if (has_set) commands_given++;
84+
85+
if (commands_given == 0) {
86+
cmd.printerr("Error: Must specify one of --up, --down, or --set\n");
87+
cmd.printerr("Run with --help for usage information\n");
88+
return 1;
89+
}
90+
91+
if (commands_given > 1) {
92+
cmd.printerr("Error: Cannot specify multiple commands (--up, --down, --set) simultaneously\n");
93+
return 1;
94+
}
95+
96+
// Execute the requested command
97+
bool success = false;
98+
99+
if (opt_up) {
100+
success = increase_brightness(opt_step);
101+
} else if (opt_down) {
102+
success = decrease_brightness(opt_step);
103+
} else if (has_set) {
104+
if (opt_set < 0 || opt_set > 100) {
105+
cmd.printerr("Error: brightness percentage must be between 0 and 100\n");
106+
return 1;
107+
}
108+
success = set_brightness_percent(opt_set);
109+
}
110+
111+
return success ? 0 : 1;
112+
}
113+
114+
private bool setup_logind_session() {
115+
try {
116+
string? session_id = BrightnessUtil.get_session_id();
117+
118+
if (session_id == null || session_id == "") {
119+
critical("Could not determine session ID");
120+
return false;
121+
}
122+
123+
string session_path = Path.build_filename("/org/freedesktop/login1/session", session_id);
124+
125+
logind_session = Bus.get_proxy_sync(
126+
BusType.SYSTEM,
127+
"org.freedesktop.login1",
128+
session_path
129+
);
130+
131+
return true;
132+
133+
} catch (Error e) {
134+
critical("Error connecting to logind: %s", e.message);
135+
return false;
136+
}
137+
}
138+
139+
public bool set_brightness(uint32 value) {
140+
if (logind_session == null || util.backlight_device == null) {
141+
critical("Brightness control not initialized");
142+
return false;
143+
}
144+
145+
uint32 clamped = uint32.min(value, util.max_brightness);
146+
147+
try {
148+
logind_session.SetBrightness("backlight", util.backlight_device, clamped);
149+
return true;
150+
} catch (Error e) {
151+
critical("Failed to set brightness: %s", e.message);
152+
return false;
153+
}
154+
}
155+
156+
public bool set_brightness_percent(int percent) {
157+
if (util.max_brightness == 0) {
158+
critical("Max brightness is 0");
159+
return false;
160+
}
161+
162+
int clamped = percent.clamp(0, 100);
163+
uint32 value = (uint32)((clamped * util.max_brightness) / 100);
164+
return set_brightness(value);
165+
}
166+
167+
public bool increase_brightness(int step_percent) {
168+
if (util.max_brightness == 0) {
169+
critical("Max brightness is 0");
170+
return false;
171+
}
172+
173+
int current_percent = (util.current_brightness * 100) / util.max_brightness;
174+
int new_percent = (current_percent + step_percent).clamp(0, 100);
175+
return set_brightness_percent(new_percent);
176+
}
177+
178+
public bool decrease_brightness(int step_percent) {
179+
if (util.max_brightness == 0) {
180+
critical("Max brightness is 0");
181+
return false;
182+
}
183+
184+
int current_percent = (util.current_brightness * 100) / util.max_brightness;
185+
int new_percent = (current_percent - step_percent).clamp(0, 100);
186+
return set_brightness_percent(new_percent);
187+
}
188+
189+
public static int main(string[] args) {
190+
var app = new BrightnessHelper();
191+
return app.run(args);
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)