Connect to IBUS

This commit is contained in:
Kovid Goyal 2018-07-09 06:10:22 +05:30
parent 18d6b8a0ad
commit 5b7c697dfe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 37 additions and 0 deletions

17
glfw/dbus_glfw.c vendored
View File

@ -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);
}

2
glfw/dbus_glfw.h vendored
View File

@ -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);

15
glfw/ibus_glfw.c vendored
View File

@ -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;
}

2
glfw/ibus_glfw.h vendored
View File

@ -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);

1
glfw/xkb_glfw.c vendored
View File

@ -200,6 +200,7 @@ glfw_xkb_release(_GLFWXKBData *xkb) {
xkb_context_unref(xkb->context);
xkb->context = NULL;
}
glfw_ibus_terminate(&xkb->ibus);
}
GLFWbool