Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show-icon setting for keyboard-layout applet #466

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 60 additions & 28 deletions src/panel/applets/keyboard-layout/KeyboardLayoutApplet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class KeyboardLayoutPlugin : Budgie.Plugin, Peas.ExtensionBase {
public Budgie.Applet get_panel_widget(string uuid) {
return new KeyboardLayoutApplet();
return new KeyboardLayoutApplet(uuid);
}
}

Expand Down Expand Up @@ -210,7 +210,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {
private Gtk.Image img;

/* Tracking input-source settings */
private Settings? settings;
private Settings? input_source_settings;

/* Keyboard tracking */
Array<InputSource> sources;
Expand All @@ -228,7 +228,19 @@ public class KeyboardLayoutApplet : Budgie.Applet {
/* ibus interfacing */
private AppletIBusManager? ibus_manager = null;

public KeyboardLayoutApplet() {
/* User settings */
private Settings user_settings;
public string uuid { public set ; public get; }

public KeyboardLayoutApplet(string uuid) {
Object(uuid: uuid);

settings_schema = "com.solus-project.keyboard-layout";
settings_prefix = "/com/solus-project/budgie-panel/instance/keyboard-layout";

user_settings = get_applet_settings(uuid);
user_settings.changed.connect(on_settings_changed);

/* Graphical stuff */
widget = new Gtk.EventBox();

Expand All @@ -248,7 +260,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {
get_style_context().add_class("keyboard-indicator");

/* Layout */
layout = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
layout = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 4);
widget.add(layout);

/* Image */
Expand All @@ -264,7 +276,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {
layout.pack_start(label_stack, false, false, 0);

/* Popover menu magicks */
popover = new Budgie.Popover(img_wrap);
popover = new Budgie.Popover(layout);
popover.get_style_context().add_class("user-menu");
listbox = new Gtk.ListBox();
listbox.set_can_focus(false);
Expand All @@ -275,7 +287,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {

/* Settings/init */
xkb = new Gnome.XkbInfo();
settings = new Settings("org.gnome.desktop.input-sources");
input_source_settings = new Settings("org.gnome.desktop.input-sources");

/* Hook up the ibus manager */
this.ibus_manager = new AppletIBusManager();
Expand All @@ -285,25 +297,21 @@ public class KeyboardLayoutApplet : Budgie.Applet {

/* Go show up */
show_all();

on_settings_changed("show-icon");
}

public override void panel_position_changed(Budgie.PanelPosition position) {
Gtk.Orientation orient = Gtk.Orientation.HORIZONTAL;
int margin = 4;
if (position == Budgie.PanelPosition.LEFT || position == Budgie.PanelPosition.RIGHT) {
orient = Gtk.Orientation.VERTICAL;
margin = 0;
}
img.set_margin_end(margin);
this.layout.set_orientation(orient);
this.layout.set_orientation(position == Budgie.PanelPosition.LEFT || position == Budgie.PanelPosition.RIGHT ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL);
on_settings_changed("show-icon");
}

/**
* Only begin listing sources and such when ibus becomes available
* or we explicitly find it won't work
*/
private void on_ibus_ready() {
settings.changed.connect(on_settings_changed);
input_source_settings.changed.connect(on_settings_changed);

/* Forcibly init ourselves */
on_settings_changed("sources");
Expand All @@ -317,7 +325,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {
var btn = item as InputSourceMenuItem;
uint idx = btn.idx;

this.settings.set_uint("current", idx);
this.input_source_settings.set_uint("current", idx);
popover.hide();
}

Expand Down Expand Up @@ -356,24 +364,27 @@ public class KeyboardLayoutApplet : Budgie.Applet {
}

private void on_settings_changed(string key) {
if (key == "sources") {
update_sources();
} else if (key == "current") {
update_current();
switch (key)
{
case "sources":
update_sources();
break;
case "current":
update_current();
break;
case "show-icon":
img_wrap.set_visible(user_settings.get_boolean(key));
break;
default:
break;
}
}

/*
* Reset InputSource list and produce something consumable by xkb
*
* TODO: Share code between WM and plugin in private Budgie library in
* the C rewrite, this is a joke now.
*/
void update_sources() {
sources = null;
sources = new Array<InputSource>();

var val = settings.get_value("sources");
var val = input_source_settings.get_value("sources");
for (size_t i = 0; i < val.n_children(); i++) {
InputSource? source = null;
string? id = null;
Expand Down Expand Up @@ -450,7 +461,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {
* Update our knowledge of the currently selected keyboard layout
*/
private void update_current() {
uint id = settings.get_uint("current");
uint id = input_source_settings.get_uint("current");
/* Safety: Check we have this guy :] */
Gtk.Widget? child = label_stack.get_child_by_name(id.to_string());
if (child == null) {
Expand All @@ -475,6 +486,27 @@ public class KeyboardLayoutApplet : Budgie.Applet {
this.manager = manager;
manager.register_popover(widget, popover);
}

public override Gtk.Widget? get_settings_ui() {
return new KeyboardLayoutSettings(get_applet_settings(uuid));
}

public override bool supports_settings() {
return true;
}
}

[GtkTemplate (ui="/com/solus-project/keyboard-layout/settings.ui")]
public class KeyboardLayoutSettings : Gtk.Grid {
[GtkChild]
private unowned Gtk.Switch? switch_icon;

private Settings? settings;

public KeyboardLayoutSettings(Settings? settings) {
this.settings = settings;
settings.bind("show-icon", switch_icon, "active", SettingsBindFlags.DEFAULT);
}
}

[ModuleInit]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="budgie">
<schema id="com.solus-project.keyboard-layout">
<key type="b" name="show-icon">
<default>true</default>
</key>
</schema>
</schemalist>
29 changes: 29 additions & 0 deletions src/panel/applets/keyboard-layout/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ custom_target('plugin-file-keyboardlayout',
install : true,
install_dir : applet_keyboardlayout_dir)

gresource = join_paths(meson.current_source_dir(), 'plugin.gresource.xml')

# Compile the assets into the binary
applet_keyboardlayout_resources = gnome.compile_resources(
'keyboardlayout-applet-resources',
gresource,
source_dir: meson.current_source_dir(),
c_name: 'budgie_keyboardlayout',
)

lib_applet_keyboardlayout_resources = static_library(
'keyboardlayout-applet-resources',
applet_keyboardlayout_resources,
dependencies: [ dep_glib ],
install: false,
c_args: ['-Wno-overlength-strings'], # gresource generates overlength strings...
)

applet_keyboardlayout_sources = [
'KeyboardLayoutApplet.vala',
]
Expand All @@ -26,16 +44,27 @@ shared_library(
'keyboardlayoutapplet',
applet_keyboardlayout_sources,
dependencies: applet_keyboardlayout_deps,
link_whole: [
lib_applet_keyboardlayout_resources,
],
vala_args: [
'--pkg', 'libpeas-1.0',
'--pkg', 'gtk+-3.0',
'--pkg', 'ibus-1.0',
'--pkg', 'gnome-desktop-3.0',
'--vapidir', join_paths(meson.source_root(), 'vapi'),
# Make gresource work
'--target-glib=2.38',
'--gresources=' + gresource,
],
c_args: [
'-DGNOME_DESKTOP_USE_UNSTABLE_API',
],
install: true,
install_dir: applet_keyboardlayout_dir,
)

install_data(
'com.solus-project.keyboard-layout.gschema.xml',
install_dir: join_paths(datadir, 'glib-2.0', 'schemas'),
)
7 changes: 7 additions & 0 deletions src/panel/applets/keyboard-layout/plugin.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/solus-project/keyboard-layout">
<file preprocess="xml-stripblanks">settings.ui</file>
</gresource>
</gresources>
36 changes: 36 additions & 0 deletions src/panel/applets/keyboard-layout/settings.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.12"/>
<template class="KeyboardLayoutSettings" parent="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="row_spacing">4</property>
<property name="column_spacing">4</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Show icon</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch_icon">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</template>
</interface>