Skip to content

Commit

Permalink
ui/gtk3: Show preferences menu item in activate menu
Browse files Browse the repository at this point in the history
Currently middle click can toggle the activate menu and context menu
in Plasma Wayland desktop session but probably a single menu is
better at present.
Now the preferences and emoji menu items are also shown in the
activate menu so that users don't have to use the middle click.

BUG=rhbz#2243610
  • Loading branch information
fujiwarat committed Feb 13, 2024
1 parent e425bbf commit 3e7ee44
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 25 deletions.
1 change: 1 addition & 0 deletions ui/gtk3/indicator.vala
Expand Up @@ -158,6 +158,7 @@ class Indicator : IBus.Service
private void name_appeared_handler(GLib.DBusConnection connection,
string name,
string name_owner) {
// FIXME: https://discourse.gnome.org/t/how-to-write-vala-glib-dbusproxy-async/2059
GLib.DBusProxy.new.begin(
connection,
GLib.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
Expand Down
97 changes: 74 additions & 23 deletions ui/gtk3/panel.vala
Expand Up @@ -3,7 +3,7 @@
* ibus - The Input Bus
*
* Copyright(c) 2011-2014 Peng Huang <shawn.p.huang@gmail.com>
* Copyright(c) 2015-2023 Takao Fujwiara <takao.fujiwara1@gmail.com>
* Copyright(c) 2015-2024 Takao Fujwiara <takao.fujiwara1@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -1413,31 +1413,43 @@ class Panel : IBus.PanelService {
}
}

private Gtk.Menu create_context_menu(bool use_x11 = false) {
if (m_sys_menu != null)
return m_sys_menu;

Gdk.Display display_backup = null;
if (use_x11 && !BindingCommon.default_is_xdisplay()) {
var display = BindingCommon.get_xdisplay();
display_backup = Gdk.Display.get_default();
if (display != null) {
Gdk.DisplayManager.get().set_default_display(
(Gdk.Display)display);
}
private void run_ibus_command(string args) {
string binary = GLib.Path.build_filename(Config.BINDIR, "ibus");
try {
string[] _args = {};
_args += binary;
_args += args;
if (args == "exit" || args == "restart")
_args += "--type=kde-wayland";
string? standard_out = null;
string? standard_error = null;
GLib.Process.spawn_sync(null,
_args,
GLib.Environ.get(),
0,
null,
out standard_out,
out standard_error,
null);
if (standard_out != null)
print(standard_out);
if (standard_error != null)
warning("Execute %s failed! %s", binary, standard_error);
} catch (GLib.SpawnError e) {
warning("Execute %s failed! %s", binary, e.message);
}
}

// Show system menu
Gtk.MenuItem item;
m_sys_menu = new Gtk.Menu();

item = new Gtk.MenuItem.with_label(_("Preferences"));
private void append_preferences_menu(Gtk.Menu menu) {
Gtk.MenuItem item = new Gtk.MenuItem.with_label(_("Preferences"));
item.activate.connect((i) => show_setup_dialog());
// https://gitlab.gnome.org/GNOME/gtk/-/issues/5870
m_sys_menu.insert(item, -1);
menu.insert(item, -1);
}

private void append_emoji_menu(Gtk.Menu menu) {
#if EMOJI_DICT
item = new Gtk.MenuItem.with_label(_("Emoji Choice"));
Gtk.MenuItem item = new Gtk.MenuItem.with_label(_("Emoji Choice"));
item.activate.connect((i) => {
IBus.ExtensionEvent event = new IBus.ExtensionEvent(
"name", "emoji", "is-enabled", true,
Expand All @@ -1450,21 +1462,54 @@ class Panel : IBus.PanelService {
panel_extension(event);
});
// https://gitlab.gnome.org/GNOME/gtk/-/issues/5870
m_sys_menu.insert(item, -1);
menu.insert(item, -1);
#endif

}

private Gtk.Menu create_context_menu(bool use_x11 = false) {
if (m_sys_menu != null)
return m_sys_menu;

Gdk.Display display_backup = null;
if (use_x11 && !BindingCommon.default_is_xdisplay()) {
var display = BindingCommon.get_xdisplay();
display_backup = Gdk.Display.get_default();
if (display != null) {
Gdk.DisplayManager.get().set_default_display(
(Gdk.Display)display);
}
}

// Show system menu
Gtk.MenuItem item;
m_sys_menu = new Gtk.Menu();

append_preferences_menu(m_sys_menu);
append_emoji_menu(m_sys_menu);

item = new Gtk.MenuItem.with_label(_("About"));
item.activate.connect((i) => show_about_dialog());
m_sys_menu.insert(item, -1);

m_sys_menu.insert(new Gtk.SeparatorMenuItem(), -1);

item = new Gtk.MenuItem.with_label(_("Restart"));
item.activate.connect((i) => m_bus.exit(true));
item.activate.connect((i) => {
if (m_is_kde && !BindingCommon.default_is_xdisplay())
run_ibus_command("restart");
else
m_bus.exit(true);
});
m_sys_menu.insert(item, -1);

item = new Gtk.MenuItem.with_label(_("Quit"));
item.activate.connect((i) => m_bus.exit(false));
item.activate.connect((i) => {
if (m_is_kde && !BindingCommon.default_is_xdisplay())
run_ibus_command("exit");
else
m_bus.exit(false);
});
m_sys_menu.insert(item, -1);

m_sys_menu.show_all();
Expand Down Expand Up @@ -1515,6 +1560,12 @@ class Panel : IBus.PanelService {
m_ime_menu.add(item);
}

if (m_is_kde && !BindingCommon.default_is_xdisplay()) {
m_ime_menu.insert(new Gtk.SeparatorMenuItem(), -1);
append_preferences_menu(m_ime_menu);
append_emoji_menu(m_ime_menu);
}

m_ime_menu.show_all();

// Do not take focuse to avoid some focus related issues.
Expand Down
4 changes: 2 additions & 2 deletions ui/gtk3/propertypanel.vala
Expand Up @@ -4,7 +4,7 @@
*
* Copyright(c) 2013-2016 Red Hat, Inc.
* Copyright(c) 2013-2015 Peng Huang <shawn.p.huang@gmail.com>
* Copyright(c) 2013-2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright(c) 2013-2024 Takao Fujiwara <takao.fujiwara1@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -93,7 +93,7 @@ public class PropertyPanel : Gtk.Box {
Type type = item.get_type();
if (type == typeof(PropMenuToolButton) ||
type == typeof(PropToggleToolButton)) {
if ((item as Gtk.ToggleToolButton).get_active()) {
if (((Gtk.ToggleToolButton)item).get_active()) {
has_active = true;
break;
}
Expand Down

0 comments on commit 3e7ee44

Please sign in to comment.