Skip to content

Commit

Permalink
Add show-icon setting for keyboard-layout applet
Browse files Browse the repository at this point in the history
  • Loading branch information
kostoskistefan committed Oct 4, 2023
1 parent 7dfa026 commit aba13e1
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 16 deletions.
80 changes: 64 additions & 16 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 Down Expand Up @@ -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,31 @@ 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(5);
label_stack.set_margin_start(2);
}
else {
img.set_margin_end(0);
label_stack.set_margin_start(4);
}
img.set_margin_end(margin);
this.layout.set_orientation(orient);
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 +335,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,10 +374,19 @@ 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;
}
}

Expand All @@ -373,7 +400,7 @@ public class KeyboardLayoutApplet : Budgie.Applet {
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 +477,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 +502,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>
38 changes: 38 additions & 0 deletions src/panel/applets/keyboard-layout/settings.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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="margin_left">8</property>
<property name="margin_right">4</property>
<property name="margin_top">4</property>
<property name="margin_bottom">4</property>
<property name="row_spacing">10</property>
<property name="column_spacing">6</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="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>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</template>
</interface>

0 comments on commit aba13e1

Please sign in to comment.