Skip to content

Commit c0e325d

Browse files
authored
Dbus (#39)
* feat: implement DBus interface for brightness control and OSD signaling * feat: emit OSD signal with display model name when setting brightness * feat: enhance DBus interface and add GNOME extension support * feat: add DBus service support and enhance metainfo for application
1 parent 7fe8a8b commit c0e325d

19 files changed

+522
-15
lines changed

Makefile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all release debug install uninstall install-debug uninstall-debug clean package-deb package-rpm package-arch package-arch-test install-arch uninstall-arch
1+
.PHONY: all release debug install uninstall install-debug uninstall-debug clean package-deb package-rpm package-arch package-arch-test install-arch uninstall-arch flatpak install-flatpak uninstall-flatpak lint-flatpak run-flatpak flatpak-bundle pack-extension install-extension uninstall-extension
22

33
# Build directories
44
BUILD_RELEASE_DIR = build/release
@@ -88,6 +88,7 @@ package-rpm: packaging-build
8888
cp $(BUILD_PACKAGING_DIR)/com.sidevesh.Luminance.desktop $(RPMBUILD_DIR)/SOURCES/
8989
cp $(BUILD_PACKAGING_DIR)/com.sidevesh.Luminance.gschema.xml $(RPMBUILD_DIR)/SOURCES/
9090
cp $(BUILD_PACKAGING_DIR)/com.sidevesh.Luminance.metainfo.xml $(RPMBUILD_DIR)/SOURCES/
91+
cp $(BUILD_PACKAGING_DIR)/com.sidevesh.Luminance.service $(RPMBUILD_DIR)/SOURCES/
9192
cp install_files/44-backlight-permissions.rules $(RPMBUILD_DIR)/SOURCES/
9293
cp icons/hicolor/scalable/apps/com.sidevesh.Luminance.svg $(RPMBUILD_DIR)/SOURCES/
9394
cp icons/hicolor/symbolic/apps/com.sidevesh.Luminance-symbolic.svg $(RPMBUILD_DIR)/SOURCES/
@@ -140,7 +141,7 @@ flatpak:
140141
install-flatpak: flatpak
141142
@echo "Installing Flatpak..."
142143
flatpak remote-add --user --if-not-exists --no-gpg-verify luminance-local-repo $(CURDIR)/$(FLATPAK_REPO_DIR)
143-
flatpak install --user -y luminance-local-repo $(FLATPAK_APP_ID)
144+
flatpak install --user -y --reinstall luminance-local-repo $(FLATPAK_APP_ID)
144145

145146
uninstall-flatpak:
146147
@echo "Uninstalling Flatpak..."
@@ -173,3 +174,29 @@ flatpak-bundle: flatpak
173174
# Remove build directories
174175
clean:
175176
rm -rf build
177+
178+
# GNOME Extension
179+
EXTENSION_UUID = luminance@sidevesh.com
180+
SRC_EXTENSION_DIR = gnome-extension
181+
EXTENSION_BUILD_DIR = $(PKG_DIR)/gnome-extension
182+
EXTENSION_ZIP = $(OUTPUTS_DIR)/$(EXTENSION_UUID).shell-extension.zip
183+
184+
pack-extension:
185+
@echo "Packing GNOME extension..."
186+
rm -rf $(EXTENSION_BUILD_DIR)
187+
mkdir -p $(EXTENSION_BUILD_DIR)
188+
cp -r $(SRC_EXTENSION_DIR)/* $(EXTENSION_BUILD_DIR)/
189+
mkdir -p $(OUTPUTS_DIR)
190+
gnome-extensions pack $(EXTENSION_BUILD_DIR) --force --out-dir=$(OUTPUTS_DIR)
191+
@echo "Extension packed at $(EXTENSION_ZIP)"
192+
193+
install-extension: pack-extension
194+
@echo "Installing GNOME extension..."
195+
gnome-extensions install --force $(EXTENSION_ZIP)
196+
@echo "GNOME extension installed. You may need to enable it with: gnome-extensions enable $(EXTENSION_UUID)"
197+
@echo "You may need to restart GNOME Shell (Alt+F2, 'r') or log out/in."
198+
199+
uninstall-extension:
200+
@echo "Uninstalling GNOME extension..."
201+
-gnome-extensions uninstall $(EXTENSION_UUID)
202+
@echo "Extension uninstalled."

generate_releases.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
# Check if git is available and we are in a git repository
4+
if command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
5+
# Get tags sorted by version (descending)
6+
git for-each-ref --sort=-version:refname --format '%(refname:short) %(creatordate:short)' refs/tags | while read -r version date; do
7+
# Clean up version string if it starts with 'v'
8+
clean_version="${version#v}"
9+
echo " <release version=\"$clean_version\" date=\"$date\"/>"
10+
done
11+
else
12+
# Fallback or empty if not a git repo
13+
echo ""
14+
fi

gnome-extension/extension.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Gio from 'gi://Gio';
2+
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
3+
4+
const IFACE_NAME = 'com.sidevesh.Luminance';
5+
const SIGNAL_NAME = 'ShowOSD';
6+
7+
export default class Extension {
8+
enable() {
9+
this._signalId = Gio.DBus.session.signal_subscribe(
10+
null, // sender (null matches any)
11+
IFACE_NAME,
12+
SIGNAL_NAME,
13+
null, // object path
14+
null, // arg0
15+
Gio.DBusSignalFlags.NONE,
16+
(connection, senderName, objectPath, interfaceName, signalName, parameters) => {
17+
try {
18+
const [percentage, monitorName] = parameters.deep_unpack();
19+
this._showOSD(percentage);
20+
} catch (e) {
21+
console.error('Luminance OSD: Error handling signal', e);
22+
}
23+
}
24+
);
25+
console.log('Luminance OSD: Enabled');
26+
}
27+
28+
disable() {
29+
if (this._signalId) {
30+
Gio.DBus.session.signal_unsubscribe(this._signalId);
31+
this._signalId = null;
32+
}
33+
console.log('Luminance OSD: Disabled');
34+
}
35+
36+
_showOSD(percentage) {
37+
// percentage is 0-100 from C app.
38+
// OSD usually takes 0.0 - 1.0 (or normalized).
39+
// The original eval code divided by 100.0.
40+
const normalizedValue = percentage / 100.0;
41+
const icon = Gio.Icon.new_for_string('display-brightness-symbolic');
42+
43+
// Note: Using show() instead of showAll() as showAll() is not standard in recent Shell versions.
44+
// If your specific setup requires showAll, please revert.
45+
// show(monitorIndex, icon, label, level, maxLevel)
46+
// monitorIndex -1 usually means current/primary.
47+
48+
// Trying to match previous behavior: "Main.osdWindowManager.showAll(..., ..., %f, 1)"
49+
if (Main.osdWindowManager.showAll) {
50+
Main.osdWindowManager.showAll(icon, null, normalizedValue, 1);
51+
} else {
52+
Main.osdWindowManager.show(-1, icon, null, normalizedValue, 1);
53+
}
54+
}
55+
}

gnome-extension/metadata.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "Luminance",
3+
"description": "Companion extension for Luminance app",
4+
"uuid": "luminance@sidevesh.com",
5+
"shell-version": [
6+
"49"
7+
]
8+
}

install_files/com.sidevesh.Luminance.metainfo.xml.in

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<metadata_license>CC0-1.0</metadata_license>
55
<project_license>GPL-3.0-only</project_license>
66
<name>Luminance</name>
7-
<developer_name>Swapnil Devesh</developer_name>
7+
<developer id="com.sidevesh">
8+
<name>Swapnil Devesh</name>
9+
</developer>
810
<summary>Control brightness of displays</summary>
911
<description>
1012
<p>@DESCRIPTION@</p>
@@ -16,13 +18,15 @@
1618
<content_rating type="oars-1.1"/>
1719
<screenshots>
1820
<screenshot type="default">
19-
<caption>Main Window</caption>
20-
<image type="source" width="472" height="416">https://raw.githubusercontent.com/sidevesh/Luminance/main/screenshots/screenshot.png</image>
21+
<caption>Main Window (Light Style)</caption>
22+
<image type="source">https://raw.githubusercontent.com/sidevesh/Luminance/main/screenshots/screenshot.light.png</image>
23+
</screenshot>
24+
<screenshot>
25+
<caption>Main Window (Dark Style)</caption>
26+
<image type="source">https://raw.githubusercontent.com/sidevesh/Luminance/main/screenshots/screenshot.dark.png</image>
2127
</screenshot>
2228
</screenshots>
2329
<releases>
24-
<release version="1.2.0" date="2024-01-01">
25-
<!-- Update date and description -->
26-
</release>
30+
@RELEASES@
2731
</releases>
2832
</component>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[D-BUS Service]
2+
Name=@APP_ID@
3+
Exec=@bindir@/@APP_ID@ --gapplication-service

meson.build

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ conf_data.set_quoted('APP_INFO_ICON_NAME', icon_name)
3333

3434
configure_file(output: 'config.h', configuration: conf_data)
3535

36+
# DBus Interface Generation
37+
# Generates com-sidevesh-Luminance.c and com-sidevesh-Luminance.h
38+
gdbus_src = gnome.gdbus_codegen(
39+
'com-sidevesh-Luminance',
40+
sources: 'src/com.sidevesh.Luminance.xml',
41+
interface_prefix: 'com.sidevesh.Luminance.',
42+
namespace: 'Luminance',
43+
annotations: [['com.sidevesh.Luminance', 'org.gtk.GDBus.C.Name', 'Service']]
44+
)
45+
3646
# Main executable
3747
# Note: src/main.c includes other source files directly.
3848
# This structure means we only need to compile main.c.
3949
executable(app_id,
40-
sources: 'src/main.c',
50+
sources: ['src/main.c', gdbus_src],
4151
dependencies: [
4252
gtk4_dep,
4353
libadwaita_dep,
@@ -85,6 +95,7 @@ configure_file(
8595
appstream_conf = configuration_data()
8696
appstream_conf.set('APP_ID', app_id)
8797
appstream_conf.set('DESCRIPTION', run_command('cat', 'description.txt', check: true).stdout().strip())
98+
appstream_conf.set('RELEASES', run_command('sh', 'generate_releases.sh', check: false).stdout())
8899

89100
configure_file(
90101
input: 'install_files/com.sidevesh.Luminance.metainfo.xml.in',
@@ -94,6 +105,19 @@ configure_file(
94105
install_dir: join_paths(datadir, 'metainfo')
95106
)
96107

108+
# DBus activatable service
109+
dbus_service_conf = configuration_data()
110+
dbus_service_conf.set('APP_ID', app_id)
111+
dbus_service_conf.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
112+
113+
configure_file(
114+
input: 'install_files/com.sidevesh.Luminance.service.in',
115+
output: app_id + '.service',
116+
configuration: dbus_service_conf,
117+
install: true,
118+
install_dir: join_paths(datadir, 'dbus-1', 'services')
119+
)
120+
97121
# Udev rules
98122
if get_option('install_udev_rules')
99123
# Try to detect udev rules directory, otherwise fallback to /lib/udev/rules.d

packaging/flatpak/com.sidevesh.Luminance.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ finish-args:
1111
- --filesystem=/sys/class/backlight
1212
- --filesystem=/sys/devices
1313
- --share=ipc
14+
- --own-name=com.sidevesh.Luminance
1415
modules:
1516
- name: jansson
1617
buildsystem: cmake

packaging/rpm/com.sidevesh.Luminance.spec.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ install -D -m 644 %{_sourcedir}/com.sidevesh.Luminance.gschema.xml %{buildroot}/
4040
# Install the AppStream metainfo
4141
install -D -m 644 %{_sourcedir}/com.sidevesh.Luminance.metainfo.xml %{buildroot}/%{_datadir}/metainfo/com.sidevesh.Luminance.metainfo.xml
4242

43+
# Install the DBus service file
44+
install -D -m 644 %{_sourcedir}/com.sidevesh.Luminance.service %{buildroot}/%{_datadir}/dbus-1/services/com.sidevesh.Luminance.service
45+
4346
# Install the udev rules
4447
install -D -m 644 %{_sourcedir}/44-backlight-permissions.rules %{buildroot}/%{_libdir}/udev/rules.d/44-backlight-permissions.rules
4548

@@ -52,6 +55,7 @@ install -D -m 644 %{_sourcedir}/com.sidevesh.Luminance-symbolic.svg %{buildroot}
5255
%{_datadir}/applications/com.sidevesh.Luminance.desktop
5356
%{_datadir}/glib-2.0/schemas/com.sidevesh.Luminance.gschema.xml
5457
%{_datadir}/metainfo/com.sidevesh.Luminance.metainfo.xml
58+
%{_datadir}/dbus-1/services/com.sidevesh.Luminance.service
5559

5660
%{_libdir}/udev/rules.d/44-backlight-permissions.rules
5761
%{_datadir}/icons/hicolor/scalable/apps/com.sidevesh.Luminance.svg

screenshots/screenshot.dark.png

18.6 KB
Loading

0 commit comments

Comments
 (0)