Is it possible to trigger gdbus call
on click on the panel extension icon?
In my concrete example I want to call the following command to change display brightness when clicking the extension icon.
gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepUp --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepUp
There's a couple of options available to you. You could spawn that command using GLib.spawn_command_line_async()
:
const Lang = imports.lang;
const PanelMenu = imports.ui.panelMenu;
const St = imports.gi.St;
const ExamplePanel = new Lang.Class({
Name: "ExamplePanelButton",
Extends: PanelMenu.Button,
_init: function () {
this.parent(null, "ExamplePanelButton");
// Icon
this.icon = new St.Icon({
icon_name: "view-refresh-symbolic",
style_class: "system-status-icon"
});
this.icon.connect("clicked", () => GLib.spawn_command_line_async(
"gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepUp"
));
this.actor.add_actor(this.icon);
}
});
But there are pretty extensive DBus API's available as well, like this older example of creating proxy wrappers. Or you could make raw DBus calls:
const Gio = imports.gi.Gio;
//
let proxy = new Gio.DBusProxy({
g_connection: Gio.DBus.session,
g_name: "org.gnome.SettingsDaemon.Power",
g_object_path: "/org/gnome/SettingsDaemon/Power",
g_interface_name: "org.gnome.SettingsDaemon.Power.Screen"
});
proxy.init(null);
let returnValue = proxy.call_sync(
"org.gnome.SettingsDaemon.Power.Screen.StepUp",
null, // method args
0, // call flags
-1, // timeout
null // cancellable
);
log(returnValue.deep_unpack());