Merge branch 'popover-settings' into 'master'
Add settings option to popover Closes #154 See merge request Librem5/squeekboard!385
This commit is contained in:
@ -14,6 +14,7 @@ sources = [
|
||||
config_h,
|
||||
'dbus.c',
|
||||
'imservice.c',
|
||||
'popover.c',
|
||||
'server-context-service.c',
|
||||
'wayland.c',
|
||||
'../eek/eek.c',
|
||||
|
||||
69
src/popover.c
Normal file
69
src/popover.c
Normal file
@ -0,0 +1,69 @@
|
||||
#include <gio/gio.h>
|
||||
|
||||
static void
|
||||
call_dbus_cb (GDBusProxy *proxy,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr (GError) err = NULL;
|
||||
g_autoptr (GVariant) output = NULL;
|
||||
|
||||
output = g_dbus_proxy_call_finish (proxy, res, &err);
|
||||
if (err) {
|
||||
g_warning ("Can't open panel %s", err->message);
|
||||
}
|
||||
g_object_unref (proxy);
|
||||
}
|
||||
|
||||
static void
|
||||
create_dbus_proxy_cb (GObject *source_object, GAsyncResult *res, char *panel)
|
||||
{
|
||||
GDBusProxy *proxy;
|
||||
g_autoptr (GError) err = NULL;
|
||||
GVariantBuilder builder;
|
||||
GVariant *params[3];
|
||||
GVariant *array[1];
|
||||
|
||||
proxy = g_dbus_proxy_new_for_bus_finish (res, &err);
|
||||
|
||||
if (err != NULL) {
|
||||
g_warning ("Can't open panel %s: %s", panel, err->message);
|
||||
g_free (panel);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
|
||||
g_variant_builder_add (&builder, "v", g_variant_new_string (""));
|
||||
|
||||
array[0] = g_variant_new ("v", g_variant_new ("(sav)", panel, &builder));
|
||||
|
||||
params[0] = g_variant_new_string ("launch-panel");
|
||||
params[1] = g_variant_new_array (G_VARIANT_TYPE ("v"), array, 1);
|
||||
params[2] = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
|
||||
|
||||
g_dbus_proxy_call (proxy,
|
||||
"Activate",
|
||||
g_variant_new_tuple (params, 3),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
(GAsyncReadyCallback) call_dbus_cb,
|
||||
NULL);
|
||||
|
||||
g_free (panel);
|
||||
}
|
||||
|
||||
void
|
||||
popover_open_settings_panel (char *panel)
|
||||
{
|
||||
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.gnome.ControlCenter",
|
||||
"/org/gnome/ControlCenter",
|
||||
"org.gtk.Actions",
|
||||
NULL,
|
||||
(GAsyncReadyCallback) create_dbus_proxy_cb,
|
||||
g_strdup (panel));
|
||||
|
||||
}
|
||||
@ -26,6 +26,15 @@ use gtk::WidgetExt;
|
||||
use std::io::Write;
|
||||
use ::logging::Warn;
|
||||
|
||||
mod c {
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" {
|
||||
pub fn popover_open_settings_panel(panel: *const c_char);
|
||||
}
|
||||
}
|
||||
|
||||
mod variants {
|
||||
use glib;
|
||||
use glib::Variant;
|
||||
@ -129,6 +138,12 @@ fn make_menu_builder(inputs: Vec<(&str, OwnedTranslation)>) -> gtk::Builder {
|
||||
xml,
|
||||
"
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name=\"label\" translatable=\"yes\">Keyboard Settings</attribute>
|
||||
<attribute name=\"action\">settings</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
</interface>"
|
||||
).unwrap();
|
||||
@ -420,8 +435,14 @@ pub fn show(
|
||||
menu_inner.popdown();
|
||||
});
|
||||
|
||||
let settings_action = gio::SimpleAction::new("settings", None);
|
||||
settings_action.connect_activate(move |_, _| {
|
||||
unsafe { c::popover_open_settings_panel(CString::new("region").unwrap().as_ptr()) };
|
||||
});
|
||||
|
||||
let action_group = gio::SimpleActionGroup::new();
|
||||
action_group.add_action(&layout_action);
|
||||
action_group.add_action(&settings_action);
|
||||
|
||||
menu.insert_action_group("popup", Some(&action_group));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user