Skip to content

Commit

Permalink
tools: Fix ibus start/restart in Plasma Wayland
Browse files Browse the repository at this point in the history
ibus start/restart frequently failed because of the timeout.
Now the command waits for the "/VirtualKeyboard" on
"org.kde.kwin.VirtualKeyboard" D-Bus ack signal so that the "/kwinrc" on
"org.kde.kconfig.notify" D-Bus signal is completed.

Also use ibusinternal.h instead of dbus.h .

Fixes: 74712fa
  • Loading branch information
fujiwarat committed Mar 16, 2024
1 parent ca61d6e commit 5696033
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
8 changes: 4 additions & 4 deletions bindings/vala/dbus-1.vapi
@@ -1,10 +1,10 @@
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "dbus/dbus.h")]
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "ibusinternal.h")]
namespace DBus
{
[CCode (cheader_filename = "dbus/dbus.h", cname = "DBUS_INTERFACE_DBUS")]
[CCode (cheader_filename = "ibusinternal.h", cname = "DBUS_INTERFACE_DBUS")]
public const string INTERFACE_DBUS;
[CCode (cheader_filename = "dbus/dbus.h", cname = "DBUS_PATH_DBUS")]
[CCode (cheader_filename = "ibusinternal.h", cname = "DBUS_PATH_DBUS")]
public const string PATH_DBUS;
[CCode (cheader_filename = "dbus/dbus.h", cname = "DBUS_SERVICE_DBUS")]
[CCode (cheader_filename = "ibusinternal.h", cname = "DBUS_SERVICE_DBUS")]
public const string SERVICE_DBUS;
}
3 changes: 1 addition & 2 deletions tools/Makefile.am
Expand Up @@ -45,20 +45,19 @@ AM_CPPFLAGS = \
$(NULL)

AM_CFLAGS = \
@DBUS_CFLAGS@ \
@GLIB2_CFLAGS@ \
@GIO2_CFLAGS@ \
@GTHREAD2_CFLAGS@ \
-DG_LOG_DOMAIN=\"IBUS\" \
-DLIBEXECDIR=\"$(libexecdir)\" \
-DIBUS_DISABLE_DEPRECATED \
-DIBUS_COMPILATION \
-Wno-unused-variable \
-Wno-unused-but-set-variable \
-Wno-unused-function \
$(NULL)

AM_LDADD = \
@DBUS_LIBS@ \
@GOBJECT2_LIBS@ \
@GLIB2_LIBS@ \
@GIO2_LIBS@ \
Expand Down
47 changes: 46 additions & 1 deletion tools/main.vala
Expand Up @@ -84,6 +84,22 @@ name_appeared_handler(GLib.DBusConnection connection,
loop = null;
}

private void
kde_virtual_keyboard_avail_cb(GLib.DBusConnection connection,
string? sender_name,
string object_path,
string interface_name,
string signal_name,
GLib.Variant parameters)
{
if (verbose) {
stderr.printf("%s.%s %s returned.\n",
interface_name, signal_name, object_path);
}
loop.quit();
loop = null;
}


GLib.DBusConnection? get_session_bus(bool verbose) {
loop = new GLib.MainLoop();
Expand All @@ -103,8 +119,10 @@ GLib.DBusConnection? get_session_bus(bool verbose) {
} catch(GLib.IOError e) {
if (verbose)
stderr.printf("The session bus error: %s\n", e.message);
if (loop != null)
if (loop != null) {
loop.quit();
loop = null;
}
}
});
loop.run();
Expand Down Expand Up @@ -234,6 +252,17 @@ start_daemon_with_dbus_systemd(GLib.DBusConnection connection,
bool
start_daemon_with_dbus_kde(GLib.DBusConnection connection,
bool verbose) {
loop = new GLib.MainLoop();
assert(loop != null);
uint subscripion_id = connection.signal_subscribe(
null,
"org.kde.kwin.VirtualKeyboard",
"availableChanged",
"/VirtualKeyboard",
null,
DBusSignalFlags.NONE,
kde_virtual_keyboard_avail_cb);

string wayland_values = "InputMethod";
var bytes = new GLib.VariantBuilder(new GLib.VariantType("ay"));
for (int i = 0; i < wayland_values.length; i++) {
Expand All @@ -251,15 +280,31 @@ start_daemon_with_dbus_kde(GLib.DBusConnection connection,
new GLib.Variant("(a{saay})", array))) {
if (verbose)
stderr.printf("Failed to emit a KDE D-Bus signal.\n");
connection.signal_unsubscribe(subscripion_id);
if (loop != null) {
loop.quit();
loop = null;
}
return false;
}
} catch (GLib.Error e) {
stderr.printf("%s\n", e.message);
connection.signal_unsubscribe(subscripion_id);
if (loop != null) {
loop.quit();
loop = null;
}
return false;
}
// Wait for "/VirtualKeyboard" on "org.kde.kwin.VirtualKeyboard" signal
// so that "/kwinrc" on "org.kde.kconfig.notify" signal is reached to
// kwin.
loop.run();
connection.signal_unsubscribe(subscripion_id);
return true;
}


int list_engine(string[] argv) {
const OptionEntry[] options = {
{ "name-only", 0, 0, OptionArg.NONE, out name_only,
Expand Down

0 comments on commit 5696033

Please sign in to comment.