[gnome-flashback/wip/segeiger/inputmethods] test...
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback/wip/segeiger/inputmethods] test...
- Date: Mon, 14 Sep 2015 21:19:27 +0000 (UTC)
commit 49a2109859fe29fa6834e985ffc58086a4a069b3
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Sep 14 23:57:10 2015 +0300
test...
gnome-flashback/libinput-sources/gf-ibus-manager.c | 259 ++++++++++----------
gnome-flashback/libinput-sources/gf-ibus-manager.h | 25 +-
2 files changed, 140 insertions(+), 144 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-ibus-manager.c
b/gnome-flashback/libinput-sources/gf-ibus-manager.c
index e8ff063..605f9bc 100644
--- a/gnome-flashback/libinput-sources/gf-ibus-manager.c
+++ b/gnome-flashback/libinput-sources/gf-ibus-manager.c
@@ -13,18 +13,17 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * This coded is based on js/ibusManager.js from GNOME Shell
+ *
+ * Based on code in GNOME Shell:
+ * https://git.gnome.org/browse/gnome-shell/tree/js/misc/ibusManager.js
*/
#include "config.h"
-#include "gf-ibus-manager.h"
-
#include <glib/gi18n-lib.h>
+#include "gf-ibus-manager.h"
+
struct _GfIBusManager
{
GObject parent;
@@ -47,13 +46,11 @@ struct _GfIBusManager
G_DEFINE_TYPE (GfIBusManager, gf_ibus_manager, G_TYPE_OBJECT)
-static void spawn (GfIBusManager *manager);
static void initEngines (IBusBus *ibus, GAsyncResult *result,
GfIBusManager *manager);
static void initPanelService (IBusBus *ibus, GAsyncResult *result,
GfIBusManager *manager);
-static void setContentType (IBusPanelService *panelService, guint purpose, guint hints,
- GfIBusManager *manager);
+
enum {
GF_IBUS_MANAGER_READY,
@@ -65,8 +62,21 @@ enum {
static guint gf_ibus_manager_signals[LAST_SIGNAL] = { 0 };
-#define GF_IBUS_MANAGER_MAX_INPUT_SOURCE_ACTIVATION_TIME 4000
-#define GF_IBUS_MANAGER_PRELOAD_ENGINES_DELAY_TIME 30
+#define MAX_INPUT_SOURCE_ACTIVATION_TIME 4000
+#define PRELOAD_ENGINES_DELAY_TIME 30
+
+static void
+spawn (GfIBusManager *manager)
+{
+ g_warning ("Going to spwan ibus-daemon now...");
+ // start a new subprocess for ibus-daemon
+ GError *error = NULL;
+ manager->ibusDaemonSubprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_NONE, &error, "ibus-daemon",
"--xim", "--panel", "disabled", NULL);
+ if (error) {
+ g_log ("gnome-flashback", G_LOG_LEVEL_ERROR, _("Failed to launch ibus-daemon: %s"), error->message);
+ g_error_free (error);
+ }
+}
static void
onConnected (IBusBus *ibus, GfIBusManager *manager)
@@ -192,19 +202,13 @@ get_global_engine_callback (IBusBus *ibus, GAsyncResult *result, GfIBusManager *
}
-static gboolean
-preload_engines_callback (gpointer user_data)
+static void
+setContentType (IBusPanelService *panelService, guint purpose, guint hints, GfIBusManager *manager)
{
- GfIBusManager *manager;
- g_return_val_if_fail (GF_IS_IBUS_MANAGER (user_data), G_SOURCE_REMOVE);
-
- manager = GF_IBUS_MANAGER (user_data);
- ibus_bus_preload_engines_async (manager->ibus, (const gchar *const *) manager->engineIds, -1, NULL,
NULL, NULL);
- manager->preloadEnginesTimerId = 0;
- manager->engineIds = NULL;
- return G_SOURCE_REMOVE;
+ g_signal_emit (manager, gf_ibus_manager_signals[GF_IBUS_MANAGER_SET_CONTENT_TYPE], purpose, hints,
manager);
}
+
static void
initPanelService (IBusBus *ibus, GAsyncResult *result, GfIBusManager *manager)
{
@@ -237,154 +241,145 @@ initPanelService (IBusBus *ibus, GAsyncResult *result, GfIBusManager *manager)
}
}
-void
-setContentType (IBusPanelService *panelService, guint purpose, guint hints, GfIBusManager *manager)
+static gboolean
+preload_engines_callback (gpointer user_data)
{
- g_signal_emit (manager, gf_ibus_manager_signals[GF_IBUS_MANAGER_SET_CONTENT_TYPE], purpose, hints,
manager);
-}
+ GfIBusManager *manager;
-static void
-spawn (GfIBusManager *manager)
-{
- g_warning ("Going to spwan ibus-daemon now...");
- // start a new subprocess for ibus-daemon
- GError *error = NULL;
- manager->ibusDaemonSubprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_NONE, &error, "ibus-daemon",
"--xim", "--panel", "disabled", NULL);
- if (error) {
- g_log ("gnome-flashback", G_LOG_LEVEL_ERROR, _("Failed to launch ibus-daemon: %s"), error->message);
- g_error_free (error);
- }
+ manager = GF_IBUS_MANAGER (user_data);
+
+ ibus_bus_preload_engines_async (manager->ibus, (const gchar *const *) manager->engineIds, -1, NULL, NULL,
NULL);
+
+ manager->engineIds = NULL;
+
+ manager->preloadEnginesTimerId = 0;
+ return G_SOURCE_REMOVE;
}
static void
gf_ibus_manager_dispose (GObject *object)
{
- GfIBusManager *manager = GF_IBUS_MANAGER (object);
+ GfIBusManager *manager;
+
+ manager = GF_IBUS_MANAGER (object);
- g_clear_object (&manager->ibusDaemonSubprocess);
+ g_clear_object (&manager->ibusDaemonSubprocess);
+
+ G_OBJECT_CLASS (gf_ibus_manager_parent_class)->dispose (object);
}
static void
gf_ibus_manager_class_init (GfIBusManagerClass *manager_class)
{
- GObjectClass *objectClass = G_OBJECT_CLASS (manager_class);
- objectClass->dispose = gf_ibus_manager_dispose;
-
- gf_ibus_manager_signals[GF_IBUS_MANAGER_READY] =
- g_signal_new ("ready",
- G_TYPE_FROM_CLASS (manager_class),
- G_SIGNAL_RUN_LAST,
- 0 /* closure */,
- NULL /* accumulator */,
- NULL /* accumulator data */,
- NULL,
- G_TYPE_NONE /* return_type */,
- 1 /* n_params */,
- G_TYPE_BOOLEAN /* param_types */);
-
- gf_ibus_manager_signals[GF_IBUS_MANAGER_PROPERTIES_REGISTERED] =
- g_signal_new ("properties-registered",
- G_TYPE_FROM_CLASS (manager_class),
- G_SIGNAL_RUN_LAST,
- 0 /* offset */,
- NULL /* accumulator */,
- NULL /* accumulator data */,
- NULL /* marshaller */,
- G_TYPE_NONE /* return_type */,
- 2 /* n_params */,
- G_TYPE_STRING, IBUS_TYPE_PROP_LIST /* param_types */);
-
- gf_ibus_manager_signals[GF_IBUS_MANAGER_PROPERTY_UPDATED] =
- g_signal_new ("property-updated",
- G_TYPE_FROM_CLASS (manager_class),
- G_SIGNAL_RUN_LAST,
- 0 /* offset */,
- NULL /* accumulator */,
- NULL /* accumulator data */,
- NULL /* marshaller */,
- G_TYPE_NONE /* return_type */,
- 2 /* n_params */,
- G_TYPE_STRING, IBUS_TYPE_PROPERTY /* param_types */);
-
- gf_ibus_manager_signals[GF_IBUS_MANAGER_SET_CONTENT_TYPE] =
- g_signal_new ("set-content-type",
- G_TYPE_FROM_CLASS (manager_class),
- G_SIGNAL_RUN_LAST,
- 0 /* offset */,
- NULL /* accumulator */,
- NULL /* accumulator data */,
- NULL /* marshaller */,
- G_TYPE_NONE /* return_type */,
- 2 /* n_params */,
- G_TYPE_UINT, G_TYPE_UINT/* param_types */);
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (manager_class);
+
+ object_class->dispose = gf_ibus_manager_dispose;
+
+ gf_ibus_manager_signals[GF_IBUS_MANAGER_READY] =
+ g_signal_new ("ready",
+ G_TYPE_FROM_CLASS (manager_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ gf_ibus_manager_signals[GF_IBUS_MANAGER_PROPERTIES_REGISTERED] =
+ g_signal_new ("properties-registered",
+ G_TYPE_FROM_CLASS (manager_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 2, G_TYPE_STRING, IBUS_TYPE_PROP_LIST);
+
+ gf_ibus_manager_signals[GF_IBUS_MANAGER_PROPERTY_UPDATED] =
+ g_signal_new ("property-updated",
+ G_TYPE_FROM_CLASS (manager_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 2, G_TYPE_STRING, IBUS_TYPE_PROPERTY);
+
+ gf_ibus_manager_signals[GF_IBUS_MANAGER_SET_CONTENT_TYPE] =
+ g_signal_new ("set-content-type",
+ G_TYPE_FROM_CLASS (manager_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
}
static void
gf_ibus_manager_init (GfIBusManager *manager)
{
- manager->engines = g_hash_table_new (g_str_hash, g_str_equal);
+ manager->engines = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_free);
- ibus_init ();
+ ibus_init ();
- // candidate popup
+ // candidate popup
- manager->ibus = ibus_bus_new_async ();
- g_signal_connect (manager->ibus, "connected", G_CALLBACK (onConnected), manager);
- g_signal_connect (manager->ibus, "disconnected", G_CALLBACK (onDisconnected), manager);
- // Need to set this to get 'global-engine-changed' emissions
- ibus_bus_set_watch_ibus_signal (manager->ibus, TRUE);
- g_signal_connect (manager->ibus, "global-engine-changed", G_CALLBACK (onEngineChanged), manager);
+ manager->ibus = ibus_bus_new_async ();
- spawn (manager);
-}
+ g_signal_connect (manager->ibus, "connected",
+ G_CALLBACK (onConnected), manager);
+ g_signal_connect (manager->ibus, "disconnected",
+ G_CALLBACK (onDisconnected), manager);
-IBusEngineDesc *
-gf_ibus_manager_get_engine_description (GfIBusManager *manager, const char* id) {
- g_return_val_if_fail (manager->engines, NULL);
+ // Need to set this to get 'global-engine-changed' emissions
+ ibus_bus_set_watch_ibus_signal (manager->ibus, TRUE);
+ g_signal_connect (manager->ibus, "global-engine-changed",
+ G_CALLBACK (onEngineChanged), manager);
- if (!manager->ready) {
- return NULL;
- }
+ spawn (manager);
+}
- return g_hash_table_lookup (manager->engines, id);
+GfIBusManager *
+gf_ibus_manager_new (void)
+{
+ return g_object_new (GF_TYPE_IBUS_MANAGER, NULL);
}
void
-gf_ibus_manager_set_engine (GfIBusManager *manager, const char* id, GAsyncReadyCallback callback)
+gf_ibus_manager_preload_engines (GfIBusManager *manager,
+ gchar **ids)
{
- if (!manager->ready) {
- if (callback)
- callback(G_OBJECT (manager), NULL, NULL);
- return;
- }
+ if (!manager->ibus || g_strv_length (ids) == 0)
+ return;
+
+ manager->engineIds = ids;
+
+ if (manager->preloadEnginesTimerId != 0)
+ g_source_remove (manager->preloadEnginesTimerId);
- ibus_bus_set_global_engine_async (manager->ibus,
- id,
- GF_IBUS_MANAGER_MAX_INPUT_SOURCE_ACTIVATION_TIME,
- NULL,
- callback,
- manager);
+ manager->preloadEnginesTimerId = g_timeout_add (PRELOAD_ENGINES_DELAY_TIME,
+ preload_engines_callback,
+ manager);
}
void
-gf_ibus_manager_preload_engines (GfIBusManager *manager, gchar **ids)
+gf_ibus_manager_set_engine (GfIBusManager *manager,
+ const gchar *id,
+ GAsyncReadyCallback callback)
{
- if (!manager->ibus || g_strv_length (ids) == 0) {
- return;
- }
+ if (!manager->ready)
+ {
+ if (callback != NULL)
+ callback(G_OBJECT (manager), NULL, NULL);
- if (manager->preloadEnginesTimerId != 0) {
- g_source_remove (manager->preloadEnginesTimerId);
- manager->preloadEnginesTimerId = 0;
+ return;
}
- manager->engineIds = ids;
- manager->preloadEnginesTimerId = g_timeout_add (GF_IBUS_MANAGER_PRELOAD_ENGINES_DELAY_TIME,
- preload_engines_callback, manager);
+ ibus_bus_set_global_engine_async (manager->ibus, id,
+ MAX_INPUT_SOURCE_ACTIVATION_TIME,
+ NULL, callback, manager);
}
-GfIBusManager *
-gf_ibus_manager_new (void)
+IBusEngineDesc *
+gf_ibus_manager_get_engine_description (GfIBusManager *manager,
+ const gchar *id)
{
- return g_object_new (GF_TYPE_IBUS_MANAGER, NULL);
-}
\ No newline at end of file
+ g_return_val_if_fail (manager->engines, NULL);
+
+ if (!manager->ready)
+ return NULL;
+
+ return g_hash_table_lookup (manager->engines, id);
+}
diff --git a/gnome-flashback/libinput-sources/gf-ibus-manager.h
b/gnome-flashback/libinput-sources/gf-ibus-manager.h
index e79bf24..ff7a6d9 100644
--- a/gnome-flashback/libinput-sources/gf-ibus-manager.h
+++ b/gnome-flashback/libinput-sources/gf-ibus-manager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Alberts Muktupāvels
+ * Copyright (C) 2015 Sebastian Geiger
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,25 +15,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GNOME_FLASHBACK_GFIBUSMANAGER_H
-#define GNOME_FLASHBACK_GFIBUSMANAGER_H
+#ifndef GF_IBUS_MANAGER_H
+#define GF_IBUS_MANAGER_H
-#include <glib.h>
#include <glib-object.h>
#include <ibus-1.0/ibus.h>
#define GF_TYPE_IBUS_MANAGER gf_ibus_manager_get_type ()
-G_DECLARE_FINAL_TYPE (GfIBusManager, gf_ibus_manager, GF, IBUS_MANAGER, GObject)
+G_DECLARE_FINAL_TYPE (GfIBusManager, gf_ibus_manager,
+ GF, IBUS_MANAGER, GObject)
-GfIBusManager *gf_ibus_manager_new (void);
+GfIBusManager *gf_ibus_manager_new (void);
-void
-gf_ibus_manager_preload_engines (GfIBusManager *manager, gchar **ids);
+void gf_ibus_manager_preload_engines (GfIBusManager *manager,
+ gchar **ids);
-void
-gf_ibus_manager_set_engine (GfIBusManager *manager, const char* id, GAsyncReadyCallback callback);
+void gf_ibus_manager_set_engine (GfIBusManager *manager,
+ const gchar *id,
+ GAsyncReadyCallback callback);
-IBusEngineDesc *
-gf_ibus_manager_get_engine_description (GfIBusManager *manager, const char* id);
+IBusEngineDesc *gf_ibus_manager_get_engine_description (GfIBusManager *manager,
+ const gchar *id);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]