diff --git a/glfw/dbus_glfw.c b/glfw/dbus_glfw.c index 92fe73bbc..b2b0712c1 100644 --- a/glfw/dbus_glfw.c +++ b/glfw/dbus_glfw.c @@ -50,6 +50,17 @@ glfw_dbus_init(_GLFWDBUSData *dbus) { return GLFW_TRUE; } +DBusConnection* +glfw_dbus_connect_to(const char *path, const char* err_msg) { + DBusError err; + dbus_error_init(&err); + DBusConnection *ans = dbus_connection_open_private(path, &err); + if (!ans) { + report_error(&err, err_msg); + } + return ans; +} + void glfw_dbus_terminate(_GLFWDBUSData *dbus) { if (dbus->session_conn) { @@ -58,3 +69,9 @@ glfw_dbus_terminate(_GLFWDBUSData *dbus) { dbus->session_conn = NULL; } } + +void +glfw_dbus_close_connection(DBusConnection *conn) { + dbus_connection_close(conn); + dbus_connection_unref(conn); +} diff --git a/glfw/dbus_glfw.h b/glfw/dbus_glfw.h index 0d7f51c8c..8f95320a2 100644 --- a/glfw/dbus_glfw.h +++ b/glfw/dbus_glfw.h @@ -36,3 +36,5 @@ typedef struct { GLFWbool glfw_dbus_init(_GLFWDBUSData *dbus); void glfw_dbus_terminate(_GLFWDBUSData *dbus); +DBusConnection* glfw_dbus_connect_to(const char *path, const char* err_msg); +void glfw_dbus_close_connection(DBusConnection *conn); diff --git a/glfw/ibus_glfw.c b/glfw/ibus_glfw.c index 7b205ada5..3e9f2b233 100644 --- a/glfw/ibus_glfw.c +++ b/glfw/ibus_glfw.c @@ -31,6 +31,8 @@ #include "internal.h" #include "ibus_glfw.h" +#define debug(...) if (_glfw.hints.init.debugKeyboard) printf(__VA_ARGS__); + static inline GLFWbool has_env_var(const char *name, const char *val) { const char *q = getenv(name); @@ -128,4 +130,17 @@ glfw_connect_to_ibus(_GLFWIBUSData *ibus, _GLFWDBUSData *dbus) { if (!address_file_name) return; const char *address = read_ibus_address(address_file_name); if (!address) return; + ibus->conn = glfw_dbus_connect_to(address, "Failed to connect to the IBUS daemon, with error"); + if (!ibus->conn) return; + ibus->ok = GLFW_TRUE; + debug("Connected to IBUS daemon for IME input management\n"); +} + +void +glfw_ibus_terminate(_GLFWIBUSData *ibus) { + if (ibus->conn) { + glfw_dbus_close_connection(ibus->conn); + ibus->conn = NULL; + } + ibus->ok = GLFW_FALSE; } diff --git a/glfw/ibus_glfw.h b/glfw/ibus_glfw.h index f1584516e..1b7d778f6 100644 --- a/glfw/ibus_glfw.h +++ b/glfw/ibus_glfw.h @@ -31,6 +31,8 @@ typedef struct { GLFWbool ok; + DBusConnection *conn; } _GLFWIBUSData; void glfw_connect_to_ibus(_GLFWIBUSData *ibus, _GLFWDBUSData *dbus); +void glfw_ibus_terminate(_GLFWIBUSData *ibus); diff --git a/glfw/xkb_glfw.c b/glfw/xkb_glfw.c index 4babb8450..f9e511a8f 100644 --- a/glfw/xkb_glfw.c +++ b/glfw/xkb_glfw.c @@ -200,6 +200,7 @@ glfw_xkb_release(_GLFWXKBData *xkb) { xkb_context_unref(xkb->context); xkb->context = NULL; } + glfw_ibus_terminate(&xkb->ibus); } GLFWbool