diff --git a/src/client-main.c b/src/client-main.c deleted file mode 100644 index d6e04115..00000000 --- a/src/client-main.c +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (C) 2010-2011 Daiki Ueno - * Copyright (C) 2010-2011 Red Hat, Inc. - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include -#ifdef HAVE_ATSPI -#include -#include -#endif /* HAVE_ATSPI */ -#ifdef HAVE_IBUS -#include -#endif /* HAVE_IBUS */ -#include -#include -#include "eekboard/eekboard-client.h" -#include "client.h" - -static gboolean opt_system = FALSE; -static gboolean opt_session = FALSE; -static gchar *opt_address = NULL; - -static gboolean opt_focus = FALSE; -#ifdef HAVE_ATSPI -static gboolean opt_keystroke = FALSE; -#endif /* HAVE_ATSPI */ - -static gchar *opt_keyboards = NULL; - -static gboolean opt_fullscreen = FALSE; - -static const GOptionEntry options[] = { - {"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system, - N_("Connect to the system bus")}, - {"session", 'e', 0, G_OPTION_ARG_NONE, &opt_session, - N_("Connect to the session bus")}, - {"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address, - N_("Connect to the given D-Bus address")}, -#if ENABLE_FOCUS_LISTENER - {"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus, - N_("Listen focus change events")}, -#endif /* ENABLE_FOCUS_LISTENER */ -#ifdef HAVE_ATSPI - {"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke, - N_("Listen keystroke events with AT-SPI")}, -#endif /* HAVE_ATSPI */ - {"keyboards", 'k', 0, G_OPTION_ARG_STRING, &opt_keyboards, - N_("Specify keyboards (comma separated)")}, - {"fullscreen", 'F', 0, G_OPTION_ARG_NONE, &opt_fullscreen, - N_("Create window in fullscreen mode")}, - {NULL} -}; - -static void -on_context_destroyed (EekboardContext *context, - gpointer user_data) -{ - gtk_main_quit (); -} - -static void -on_destroyed (EekboardClient *eekboard, - gpointer user_data) -{ - gtk_main_quit (); -} - -enum FocusListenerType { - FOCUS_NONE, - FOCUS_ATSPI, - FOCUS_IBUS -}; - -static gboolean -set_keyboards (SeatEmitter *client, - const gchar * const *keyboards) -{ - if (g_strv_length ((gchar **)keyboards) == 0) { - if (!client_enable_xkl (client)) { - g_printerr ("Can't register xklavier event listeners\n"); - return FALSE; - } - } else { - if (!client_set_keyboards (client, keyboards)) { - gchar *str = g_strjoinv (", ", (gchar **)keyboards); - g_printerr ("Can't set keyboards \"%s\"\n", str); - g_free (str); - return FALSE; - } - } - return TRUE; -} - -int -main (int argc, char **argv) -{ - SeatEmitter *client = NULL; - EekboardClient *eekboard; - EekboardContext *context; - GBusType bus_type; - GDBusConnection *connection; - GError *error; - GOptionContext *option_context; - gint focus; - GSettings *settings = NULL; - gchar **keyboards = NULL; - gint retval = 0; - - if (!gtk_init_check (&argc, &argv)) { - g_printerr ("Can't init GTK\n"); - exit (1); - } - - eek_init (); - - option_context = g_option_context_new ("eekboard-desktop-client"); - g_option_context_add_main_entries (option_context, options, NULL); - g_option_context_parse (option_context, &argc, &argv, NULL); - g_option_context_free (option_context); - - if (opt_system) - bus_type = G_BUS_TYPE_SYSTEM; - else if (opt_address) - bus_type = G_BUS_TYPE_NONE; - else - bus_type = G_BUS_TYPE_SESSION; - - switch (bus_type) { - case G_BUS_TYPE_SYSTEM: - error = NULL; - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); - if (connection == NULL) { - g_printerr ("Can't connect to the system bus: %s\n", - error->message); - g_error_free (error); - exit (1); - } - break; - case G_BUS_TYPE_SESSION: - error = NULL; - connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - if (connection == NULL) { - g_printerr ("Can't connect to the session bus: %s\n", - error->message); - g_error_free (error); - exit (1); - } - break; - case G_BUS_TYPE_NONE: - error = NULL; - connection = g_dbus_connection_new_for_address_sync (opt_address, - 0, - NULL, - NULL, - &error); - if (connection == NULL) { - g_printerr ("Can't connect to the bus at %s: %s\n", - opt_address, - error->message); - g_error_free (error); - exit (1); - } - break; - default: - g_assert_not_reached (); - break; - } - - client = client_new (connection); - g_object_unref (connection); - - if (client == NULL) { - g_printerr ("Can't create a client\n"); - exit (1); - } - - settings = g_settings_new ("org.fedorahosted.eekboard"); - focus = FOCUS_NONE; - if (opt_focus) { - gchar *focus_listener = g_settings_get_string (settings, - "focus-listener"); - const struct { - const gchar *name; - enum FocusListenerType type; - } focus_listeners[] = { -#ifdef HAVE_ATSPI - { "atspi", FOCUS_ATSPI }, -#endif -#ifdef HAVE_IBUS - { "ibus", FOCUS_IBUS }, -#endif - { NULL } - }; - gint i; - - focus = FOCUS_NONE; - for (i = 0; focus_listeners[i].name; i++) { - if (g_strcmp0 (focus_listener, focus_listeners[i].name) == 0) - focus = focus_listeners[i].type; - } - if (focus == FOCUS_NONE) { - g_printerr ("Unknown focus listener \"%s\". " - "Try \"atspi\" or \"ibus\"\n", focus_listener); - retval = 1; - goto out; - } - } - -#ifdef HAVE_ATSPI - if (focus == FOCUS_ATSPI || opt_keystroke) { - GSettings *desktop_settings = - g_settings_new ("org.gnome.desktop.interface"); - gboolean accessibility_enabled = - g_settings_get_boolean (desktop_settings, "toolkit-accessibility"); - g_object_unref (desktop_settings); - - if (accessibility_enabled) { - if (atspi_init () != 0) { - g_printerr ("Can't init AT-SPI 2\n"); - retval = 1; - goto out; - } - - if (focus == FOCUS_ATSPI && - !client_enable_atspi_focus (client)) { - g_printerr ("Can't register AT-SPI focus change event listeners\n"); - retval = 1; - goto out; - } - - if (opt_keystroke && - !client_enable_atspi_keystroke (client)) { - g_printerr ("Can't register AT-SPI keystroke event listeners\n"); - retval = 1; - goto out; - } - } else { - g_printerr ("Desktop accessibility support is disabled\n"); - retval = 1; - goto out; - } - } -#endif /* HAVE_ATSPI */ - -#ifdef HAVE_IBUS - if (focus == FOCUS_IBUS) { - ibus_init (); - - if (!client_enable_ibus_focus (client)) { - g_printerr ("Can't register IBus focus change event listeners\n"); - retval = 1; - goto out; - } - } -#endif /* HAVE_IBUS */ - -//#ifdef HAVE_XTEST - if (!client_enable_xtest (client)) { - g_printerr ("Can't init xtest\n"); - g_object_unref (client); - exit (1); - } -//#endif /* HAVE_XTEST */ - - if (!opt_focus) { - g_object_get (client, "context", &context, NULL); - g_signal_connect (context, "destroyed", - G_CALLBACK(on_context_destroyed), NULL); - g_object_unref (context); - } - - if (opt_fullscreen || - g_settings_get_boolean (settings, "start-fullscreen")) { - g_object_get (client, "context", &context, NULL); - eekboard_context_set_fullscreen (context, TRUE, NULL); - g_object_unref (context); - } - - g_object_get (client, "eekboard", &eekboard, NULL); - g_signal_connect (eekboard, "destroyed", - G_CALLBACK(on_destroyed), NULL); - g_object_unref (eekboard); - - if (opt_keyboards != NULL) { - keyboards = g_strsplit (opt_keyboards, ",", -1); - - if (!set_keyboards (client, (const gchar * const *)keyboards)) { - g_strfreev (keyboards); - retval = 1; - goto out; - } - g_strfreev (keyboards); - } - - gtk_main (); - - out: - if (client) - g_object_unref (client); - if (settings) - g_object_unref (settings); - - return retval; -} diff --git a/src/client.c b/src/client.c deleted file mode 100644 index 106e26ca..00000000 --- a/src/client.c +++ /dev/null @@ -1,1166 +0,0 @@ -/* - * Copyright (C) 2010-2011 Daiki Ueno - * Copyright (C) 2010-2011 Red Hat, Inc. - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include - -#ifdef HAVE_ATSPI -#include -#include -#endif /* HAVE_ATSPI */ - -#include - -#ifdef HAVE_XTEST -#include -#include -#endif /* HAVE_XTEST */ - -#include "eek/eek.h" -#include "eek/eek-xkl.h" -#include "eekboard/eekboard-client.h" -#include "eekboard/eekboard-xklutil.h" -#include "client.h" - -#include - -#define CSW 640 -#define CSH 480 - -#define DEFAULT_KEYBOARD "us" -static gchar *default_keyboards[2] = { - DEFAULT_KEYBOARD, - NULL -}; - -#define IBUS_INTERFACE_PANEL "org.freedesktop.IBus.Panel" - -enum { - PROP_0, - PROP_CONNECTION, - PROP_EEKBOARD, - PROP_CONTEXT, - PROP_KEYBOARDS, - PROP_LAST -}; - -typedef struct _ClientClass ClientClass; - -struct _Client { - GObject parent; - - EekboardClient *eekboard; - EekboardContext *context; - - GSList *keyboards; - GSList *keyboards_head; - - XklEngine *xkl_engine; - XklConfigRegistry *xkl_config_registry; - - gulong xkl_config_changed_handler; - gulong xkl_state_changed_handler; - - gulong key_activated_handler; - - gboolean follows_focus; - guint hide_keyboard_timeout_id; - - GDBusConnection *ibus_connection; - guint ibus_focus_message_filter; - -#ifdef HAVE_ATSPI - AtspiAccessible *acc; - AtspiDeviceListener *keystroke_listener; -#endif /* HAVE_ATSPI */ - - guint modifier_keycodes[8]; - XkbDescRec *xkb; - - GSettings *settings; -}; - -struct _ClientClass { - GObjectClass parent_class; -}; - -G_DEFINE_TYPE (SeatEmitter, client, G_TYPE_OBJECT); - -#if ENABLE_FOCUS_LISTENER -#define IS_KEYBOARD_VISIBLE(client) (!client->follows_focus) -#else /* ENABLE_FOCUS_LISTENER */ -#define IS_KEYBOARD_VISIBLE(client) TRUE -#endif /* !ENABLE_FOCUS_LISTENER */ - -static GdkFilterReturn filter_xkl_event (GdkXEvent *xev, - GdkEvent *event, - gpointer user_data); -static void on_xkl_config_changed (XklEngine *xklengine, - gpointer user_data); - -static void on_xkl_state_changed (XklEngine *xklengine, - XklEngineStateChange type, - gint value, - gboolean restore, - gpointer user_data); - -#ifdef HAVE_ATSPI -static void focus_listener_cb (const AtspiEvent *event, - void *user_data); - -static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke, - void *user_data); -#endif /* HAVE_ATSPI */ -static gboolean set_keyboards (SeatEmitter *client, - const gchar * const *keyboard); -static gboolean set_keyboards_from_xkl - (SeatEmitter *client); -#ifdef HAVE_XTEST -static void update_modifier_keycodes - (Client *client); -#endif /* HAVE_XTEST */ - -static void -client_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SeatEmitter *client = CLIENT(object); - GDBusConnection *connection; - gchar **keyboards; - - switch (prop_id) { - case PROP_CONNECTION: - connection = g_value_get_object (value); - - client->eekboard = eekboard_client_new (connection, NULL); - if (client->eekboard != NULL) { - client->context = - eekboard_client_create_context (client->eekboard, - "eekboard", - NULL); - if (client->context == NULL) { - g_object_unref (client->eekboard); - client->eekboard = NULL; - } else { - eekboard_client_push_context (client->eekboard, - client->context, - NULL); - g_settings_bind (client->settings, "keyboards", - client, "keyboards", - G_SETTINGS_BIND_GET); - } - } - break; - case PROP_KEYBOARDS: - keyboards = g_value_get_boxed (value); - if (g_strv_length (keyboards) == 0) - keyboards = default_keyboards; - client_set_keyboards (client, (const gchar * const *)keyboards); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -client_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SeatEmitter *client = CLIENT(object); - - switch (prop_id) { - case PROP_EEKBOARD: - g_value_set_object (value, client->eekboard); - break; - case PROP_CONTEXT: - g_value_set_object (value, client->context); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -client_dispose (GObject *object) -{ - SeatEmitter *client = CLIENT(object); - - client_disable_xkl (client); - -#ifdef HAVE_ATSPI - client_disable_atspi_focus (client); - client_disable_atspi_keystroke (client); -#endif /* HAVE_ATSPI */ - - client_disable_ibus_focus (client); - if (client->ibus_connection) { - g_object_unref (client->ibus_connection); - client->ibus_connection = NULL; - } - -#ifdef HAVE_XTEST - client_disable_xtest (client); -#endif /* HAVE_XTEST */ - - if (client->context) { - g_object_unref (client->context); - client->context = NULL; - } - - if (client->eekboard) { - g_object_unref (client->eekboard); - client->eekboard = NULL; - } - - if (client->settings) { - g_object_unref (client->settings); - client->settings = NULL; - } - - G_OBJECT_CLASS (client_parent_class)->dispose (object); -} - -static void -client_finalize (GObject *object) -{ - SeatEmitter *client = CLIENT(object); - - g_slist_free (client->keyboards); - G_OBJECT_CLASS (client_parent_class)->finalize (object); -} - -static void -client_class_init (ClientClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - gobject_class->set_property = client_set_property; - gobject_class->get_property = client_get_property; - gobject_class->dispose = client_dispose; - gobject_class->finalize = client_finalize; - - pspec = g_param_spec_object ("connection", - "Connection", - "Connection", - G_TYPE_DBUS_CONNECTION, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE); - g_object_class_install_property (gobject_class, - PROP_CONNECTION, - pspec); - - pspec = g_param_spec_object ("eekboard", - "Eekboard", - "Eekboard", - EEKBOARD_TYPE_CLIENT, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_EEKBOARD, - pspec); - - pspec = g_param_spec_object ("context", - "Context", - "Context", - EEKBOARD_TYPE_CONTEXT, - G_PARAM_READABLE); - g_object_class_install_property (gobject_class, - PROP_CONTEXT, - pspec); - - pspec = g_param_spec_boxed ("keyboards", - "Keyboards", - "Keyboards", - G_TYPE_STRV, - G_PARAM_WRITABLE); - g_object_class_install_property (gobject_class, - PROP_KEYBOARDS, - pspec); -} - -static void -client_init (SeatEmitter *client) -{ - client->settings = g_settings_new ("org.fedorahosted.eekboard"); -} - -gboolean -client_set_keyboards (SeatEmitter *client, - const gchar * const *keyboards) -{ - gboolean retval; - retval = set_keyboards (client, keyboards); - if (retval && IS_KEYBOARD_VISIBLE (client)) - eekboard_client_show_keyboard (client->eekboard, NULL); - return retval; -} - -gboolean -client_enable_xkl (SeatEmitter *client) -{ - GdkDisplay *display = gdk_display_get_default (); - gboolean retval; - - g_assert (display); - - if (!client->xkl_engine) { - client->xkl_engine = - xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY (display)); - } - g_assert (client->xkl_engine); - - if (!client->xkl_config_registry) { - client->xkl_config_registry = - xkl_config_registry_get_instance (client->xkl_engine); - xkl_config_registry_load (client->xkl_config_registry, FALSE); - } - - client->xkl_config_changed_handler = - g_signal_connect (client->xkl_engine, "X-config-changed", - G_CALLBACK(on_xkl_config_changed), client); - client->xkl_state_changed_handler = - g_signal_connect (client->xkl_engine, "X-state-changed", - G_CALLBACK(on_xkl_state_changed), client); - - gdk_window_add_filter (NULL, - (GdkFilterFunc) filter_xkl_event, - client); - gdk_window_add_filter (gdk_get_default_root_window (), - (GdkFilterFunc) filter_xkl_event, - client); - - xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE); - - retval = set_keyboards_from_xkl (client); - if (IS_KEYBOARD_VISIBLE (client)) - eekboard_client_show_keyboard (client->eekboard, NULL); - - return retval; -} - -void -client_disable_xkl (SeatEmitter *client) -{ - if (client->xkl_engine) { - xkl_engine_stop_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE); - - if (g_signal_handler_is_connected (client->xkl_engine, - client->xkl_config_changed_handler)) - g_signal_handler_disconnect (client->xkl_engine, - client->xkl_config_changed_handler); - if (g_signal_handler_is_connected (client->xkl_engine, - client->xkl_state_changed_handler)) - g_signal_handler_disconnect (client->xkl_engine, - client->xkl_state_changed_handler); - client->xkl_engine = NULL; - } -} - -#ifdef HAVE_ATSPI -gboolean -client_enable_atspi_focus (Client *client) -{ - GError *error; - - error = NULL; - if (!atspi_event_listener_register_from_callback - ((AtspiEventListenerCB)focus_listener_cb, - client, - NULL, - "object:state-changed:focused", - &error)) { - g_warning ("can't register object:state-changed:focused handler: %s", - error->message); - g_error_free (error); - return FALSE; - } - - error = NULL; - if (!atspi_event_listener_register_from_callback - ((AtspiEventListenerCB)focus_listener_cb, - client, - NULL, - "focus:", - &error)) { - g_warning ("can't register focus: handler: %s", - error->message); - g_error_free (error); - return FALSE; - } - - client->follows_focus = TRUE; - return TRUE; -} - -void -client_disable_atspi_focus (Client *client) -{ - GError *error; - - client->follows_focus = FALSE; - - error = NULL; - if (!atspi_event_listener_deregister_from_callback - ((AtspiEventListenerCB)focus_listener_cb, - client, - "object:state-changed:focused", - &error)) { - g_warning ("can't deregister object:state-changed:focused handler: %s", - error->message); - g_error_free (error); - } - - error = NULL; - if (!atspi_event_listener_deregister_from_callback - ((AtspiEventListenerCB)focus_listener_cb, - client, - "focus:", - &error)) { - g_warning ("can't deregister focus: handler: %s", - error->message); - g_error_free (error); - } -} - -gboolean -client_enable_atspi_keystroke (Client *client) -{ - GError *error; - - client->keystroke_listener = - atspi_device_listener_new ((AtspiDeviceListenerCB)keystroke_listener_cb, - client, - NULL); - - error = NULL; - if (!atspi_register_keystroke_listener - (client->keystroke_listener, - NULL, - 0, - ATSPI_KEY_PRESSED, - ATSPI_KEYLISTENER_NOSYNC, - &error)) { - g_warning ("can't register keystroke listener for key press: %s", - error->message); - g_error_free (error); - return FALSE; - } - - error = NULL; - if (!atspi_register_keystroke_listener - (client->keystroke_listener, - NULL, - 0, - ATSPI_KEY_RELEASED, - ATSPI_KEYLISTENER_NOSYNC, - &error)) { - g_warning ("can't register keystroke listener for key release: %s", - error->message); - g_error_free (error); - return FALSE; - } - return TRUE; -} - -void -client_disable_atspi_keystroke (Client *client) -{ - if (client->keystroke_listener) { - GError *error; - - error = NULL; - if (!atspi_deregister_keystroke_listener - (client->keystroke_listener, - NULL, - 0, - ATSPI_KEY_PRESSED, - &error)) { - g_warning ("can't deregister keystroke listener for key press: %s", - error->message); - g_error_free (error); - } - - error = NULL; - if (!atspi_deregister_keystroke_listener (client->keystroke_listener, - NULL, - 0, - ATSPI_KEY_RELEASED, - &error)) { - g_warning ("can't deregister keystroke listener for key release: %s", - error->message); - g_error_free (error); - } - - g_object_unref (client->keystroke_listener); - client->keystroke_listener = NULL; - } -} - -static void -focus_listener_cb (const AtspiEvent *event, - void *user_data) -{ - Client *client = user_data; - AtspiAccessible *accessible = event->source; - AtspiStateSet *state_set = atspi_accessible_get_state_set (accessible); - AtspiRole role; - GError *error; - - error = NULL; - role = atspi_accessible_get_role (accessible, &error); - if (role == ATSPI_ROLE_INVALID) { - g_warning ("can't get accessible role: %s", - error->message); - g_error_free (error); - return; - } - - if (atspi_state_set_contains (state_set, ATSPI_STATE_EDITABLE) || - role == ATSPI_ROLE_TERMINAL) { - switch (role) { - case ATSPI_ROLE_TEXT: - case ATSPI_ROLE_PARAGRAPH: - case ATSPI_ROLE_PASSWORD_TEXT: - case ATSPI_ROLE_TERMINAL: - if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) { - client->acc = accessible; - eekboard_client_show_keyboard (client->eekboard, NULL); - } else if (g_settings_get_boolean (client->settings, "auto-hide") && - event->detail1 == 0 && accessible == client->acc) { - client->acc = NULL; - eekboard_client_hide_keyboard (client->eekboard, NULL); - } - break; - case ATSPI_ROLE_ENTRY: - if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) { - client->acc = accessible; - eekboard_client_show_keyboard (client->eekboard, NULL); - } else if (g_settings_get_boolean (client->settings, "auto-hide") && - event->detail1 == 0) { - client->acc = NULL; - eekboard_client_hide_keyboard (client->eekboard, NULL); - } - break; - - default: - ; - } - } else { - eekboard_client_hide_keyboard (client->eekboard, NULL); - } -} - -static gboolean -keystroke_listener_cb (const AtspiDeviceEvent *stroke, - void *user_data) -{ - Client *client = user_data; - - switch (stroke->type) { - case ATSPI_KEY_PRESSED: - eekboard_context_press_keycode (client->context, stroke->hw_code, NULL); - break; - case ATSPI_KEY_RELEASED: - eekboard_context_release_keycode (client->context, stroke->hw_code, NULL); - break; - default: - g_return_val_if_reached (FALSE); - } - return TRUE; -} -#endif /* HAVE_ATSPI */ - -static void -add_match_rule (GDBusConnection *connection, - const gchar *match_rule) -{ - GError *error; - GDBusMessage *message; - - message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */ - "/org/freedesktop/DBus", /* path */ - "org.freedesktop.DBus", /* interface */ - "AddMatch"); - g_dbus_message_set_body (message, g_variant_new ("(s)", match_rule)); - error = NULL; - if (!g_dbus_connection_send_message (connection, - message, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, - NULL, - &error)) { - g_warning ("can't register match rule %s: %s", - match_rule, error->message); - g_error_free (error); - } - g_object_unref (message); -} - -static gboolean -on_hide_keyboard_timeout (SeatEmitter *client) -{ - eekboard_client_hide_keyboard (client->eekboard, NULL); - client->hide_keyboard_timeout_id = 0; - return FALSE; -} - -static GDBusMessage * -focus_message_filter (GDBusConnection *connection, - GDBusMessage *message, - gboolean incoming, - gpointer user_data) -{ - SeatEmitter *client = user_data; - - if (incoming && - g_strcmp0 (g_dbus_message_get_interface (message), - IBUS_INTERFACE_PANEL) == 0) { - const gchar *member = g_dbus_message_get_member (message); - - if (g_strcmp0 (member, "FocusIn") == 0) { - if (client->hide_keyboard_timeout_id > 0) { - g_source_remove (client->hide_keyboard_timeout_id); - client->hide_keyboard_timeout_id = 0; - } - eekboard_client_show_keyboard (client->eekboard, NULL); - } else if (g_settings_get_boolean (client->settings, "auto-hide") && - g_strcmp0 (member, "FocusOut") == 0) { - guint delay; - g_settings_get (client->settings, "auto-hide-delay", "u", &delay); - client->hide_keyboard_timeout_id = - g_timeout_add (delay, - (GSourceFunc)on_hide_keyboard_timeout, - client); - } - } - - return message; -} - -static void -_ibus_connect_focus_handlers (GDBusConnection *connection, gpointer user_data) -{ - SeatEmitter *client = user_data; - - add_match_rule (connection, - "type='method_call'," - "interface='" IBUS_INTERFACE_PANEL "'," - "member='FocusIn'"); - add_match_rule (connection, - "type='method_call'," - "interface='" IBUS_INTERFACE_PANEL "'," - "member='FocusOut'"); - client->ibus_focus_message_filter = - g_dbus_connection_add_filter (connection, - focus_message_filter, - client, - NULL); -} - -gboolean -client_enable_ibus_focus (SeatEmitter *client) -{ - if (client->ibus_connection == NULL) { - const gchar *ibus_address; - GError *error; - - ibus_address = g_getenv ("IBUS_ADDRESS"); - if (ibus_address == NULL) { - g_warning ("Can't get IBus address; set IBUS_ADDRESS"); - return FALSE; - } - - error = NULL; - client->ibus_connection = - g_dbus_connection_new_for_address_sync (ibus_address, - G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, - NULL, - NULL, - &error); - if (client->ibus_connection == NULL) { - g_warning ("Can't open connection to IBus: %s", error->message); - g_error_free (error); - return FALSE; - } - } - _ibus_connect_focus_handlers (client->ibus_connection, client); - - client->follows_focus = TRUE; - return TRUE; -} - -void -client_disable_ibus_focus (SeatEmitter *client) -{ - client->follows_focus = FALSE; - - if (client->ibus_connection) { - if (client->ibus_focus_message_filter != 0) { - g_dbus_connection_remove_filter (client->ibus_connection, - client->ibus_focus_message_filter); - } - g_object_unref (client->ibus_connection); - client->ibus_connection = NULL; - } -} - -SeatEmitter * -client_new (GDBusConnection *connection) -{ - SeatEmitter *client = g_object_new (TYPE_CLIENT, - "connection", connection, - NULL); - if (client->context) - return client; - return NULL; -} - -static GdkFilterReturn -filter_xkl_event (GdkXEvent *xev, - GdkEvent *event, - gpointer user_data) -{ - SeatEmitter *client = user_data; - XEvent *xevent = (XEvent *)xev; - - xkl_engine_filter_events (client->xkl_engine, xevent); - return GDK_FILTER_CONTINUE; -} - -static void -on_xkl_config_changed (XklEngine *xklengine, - gpointer user_data) -{ - SeatEmitter *client = user_data; - gboolean retval; - - retval = set_keyboards_from_xkl (client); - g_return_if_fail (retval); - -#ifdef HAVE_XTEST - update_modifier_keycodes (client); -#endif /* HAVE_XTEST */ -} - -static gboolean -set_keyboards (SeatEmitter *client, - const gchar * const *keyboards) -{ - guint keyboard_id; - const gchar * const *p; - GSList *head; - - g_return_val_if_fail (keyboards != NULL, FALSE); - g_return_val_if_fail (client->context, FALSE); - - if (client->keyboards) { - for (head = client->keyboards; head; head = head->next) { - eekboard_context_remove_keyboard (client->context, - GPOINTER_TO_UINT(head->data), - NULL); - } - g_slist_free (client->keyboards); - client->keyboards = NULL; - } - - for (p = keyboards; *p != NULL; p++) { - keyboard_id = eekboard_context_add_keyboard (client->context, *p, NULL); - if (keyboard_id == 0) { - g_warning ("can't add keyboard %s", *p); - continue; - } - client->keyboards = g_slist_prepend (client->keyboards, - GUINT_TO_POINTER(keyboard_id)); - } - - client->keyboards = g_slist_reverse (client->keyboards); - client->keyboards_head = client->keyboards; - - /* select the first keyboard */ - eekboard_context_set_keyboard (client->context, - GPOINTER_TO_UINT(client->keyboards_head->data), - NULL); - return TRUE; -} - -static gboolean -set_keyboards_from_xkl (SeatEmitter *client) -{ - XklConfigRec *rec; - gchar *layout, *keyboard; - guint keyboard_id; - - rec = xkl_config_rec_new (); - xkl_config_rec_get_from_server (rec, client->xkl_engine); - layout = eekboard_xkl_config_rec_to_string (rec); - g_object_unref (rec); - - keyboard = g_strdup_printf ("xkb:%s", layout); - g_free (layout); - - keyboard_id = eekboard_context_add_keyboard (client->context, - keyboard, - NULL); - g_free (keyboard); - if (keyboard_id == 0) - return FALSE; - eekboard_context_set_keyboard (client->context, keyboard_id, NULL); - - return TRUE; -} - -static void -on_xkl_state_changed (XklEngine *xklengine, - XklEngineStateChange type, - gint value, - gboolean restore, - gpointer user_data) -{ - SeatEmitter *client = user_data; - - if (type == GROUP_CHANGED) - eekboard_context_set_group (client->context, value, NULL); -} - -/* The following functions for keyboard mapping change are direct - translation of the code in Caribou (in libcaribou/xadapter.vala): - - - get_replaced_keycode (Caribou: get_reserved_keycode) - - replace_keycode - - get_keycode_from_gdk_keymap (Caribou: best_keycode_keyval_match) -*/ -static guint -get_replaced_keycode (SeatEmitter *client) -{ - guint keycode; - - for (keycode = client->xkb->max_key_code; - keycode >= client->xkb->min_key_code; - --keycode) { - guint offset = client->xkb->map->key_sym_map[keycode].offset; - if (client->xkb->map->key_sym_map[keycode].kt_index[0] == XkbOneLevelIndex && - client->xkb->map->syms[offset] != NoSymbol) { - return keycode; - } - } - - return 0; -} - -/* Replace keysym assigned to KEYCODE to KEYSYM. Both args are used - as in-out. If KEYCODE points to 0, this function picks a keycode - from the current map and replace the associated keysym to KEYSYM. - In that case, the replaced keycode is stored in KEYCODE and the old - keysym is stored in KEYSYM. If otherwise (KEYCODE points to - non-zero keycode), it simply changes the current map with the - specified KEYCODE and KEYSYM. */ -static gboolean -replace_keycode (SeatEmitter *client, - guint keycode, - guint *keysym) -{ - GdkDisplay *display = gdk_display_get_default (); - Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); - guint old_keysym; - int keysyms_per_keycode; - KeySym *syms; -return TRUE; // FIXME: no xkb allocated at the moment, pretending all is fine - g_return_val_if_fail (client->xkb->min_key_code <= keycode && - keycode <= client->xkb->max_key_code, - FALSE); - g_return_val_if_fail (keysym != NULL, FALSE); -/* - * Switch keyboard mapping? - syms = XGetKeyboardMapping (xdisplay, keycode, 1, &keysyms_per_keycode); - old_keysym = syms[0]; - syms[0] = *keysym; - XChangeKeyboardMapping (xdisplay, keycode, 1, syms, 1); - XSync (xdisplay, False); - XFree (syms); - *keysym = old_keysym; -*/ - return TRUE; -} - -static gboolean -get_keycode_from_gdk_keymap (SeatEmitter *client, - guint keysym, - guint *keycode, - guint *modifiers) -{ - GdkKeymap *keymap = gdk_keymap_get_default (); - GdkKeymapKey *keys, *best_match = NULL; - gint n_keys, i; - - if (!gdk_keymap_get_entries_for_keyval (keymap, keysym, &keys, &n_keys)) - return FALSE; - - for (i = 0; i < n_keys; i++) - if (keys[i].group == eekboard_context_get_group (client->context, NULL)) - best_match = &keys[i]; - - if (!best_match) { - g_free (keys); - return FALSE; - } - - *keycode = best_match->keycode; - *modifiers = best_match->level == 1 ? EEK_SHIFT_MASK : 0; - - g_free (keys); - return TRUE; -} - -int send_virtual_keyboard_key( - Display* dpy, - unsigned int keycode, - Bool is_press, - unsigned long delay -) { - printf("Sending fake event %d press %d delay %d\n", keycode, is_press, delay); -} - -/* never actually used? */ -static void -send_fake_modifier_key_event (SeatEmitter *client, - EekModifierType modifiers, - gboolean is_pressed) -{ - GdkDisplay *display = gdk_display_get_default (); - Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); - gint i; - - for (i = 0; i < G_N_ELEMENTS(client->modifier_keycodes); i++) { - if (modifiers & (1 << i)) { - guint keycode = client->modifier_keycodes[i]; - printf("Trying to send a modifier %d press %d\n", i, is_pressed); - g_return_if_fail (keycode > 0); - - send_virtual_keyboard_key (xdisplay, - keycode, - is_pressed, - CurrentTime); - //XSync (xdisplay, False); - } - } -} - -static void -send_fake_key_event (SeatEmitter *client, - guint xkeysym, - guint keyboard_modifiers) -{ - GdkDisplay *display = gdk_display_get_default (); - Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); - EekModifierType modifiers; - guint keycode; - guint old_keysym = xkeysym; - - g_return_if_fail (xkeysym > 0); - - modifiers = 0; - if (!get_keycode_from_gdk_keymap (client, xkeysym, &keycode, &modifiers)) { - keycode = get_replaced_keycode (client); - if (keycode == 0) { - g_warning ("no available keycode to replace"); - return; - } - - if (!replace_keycode (client, keycode, &old_keysym)) { - g_warning ("failed to lookup X keysym %X", xkeysym); - return; - } - } - - /* Clear level shift modifiers */ - keyboard_modifiers &= ~EEK_SHIFT_MASK; - keyboard_modifiers &= ~EEK_LOCK_MASK; - /* FIXME: may need to remap ISO_Level3_Shift and NumLock */ -#if 0 - keyboard_modifiers &= ~EEK_MOD5_MASK; - keyboard_modifiers &= ~client->alt_gr_mask; - keyboard_modifiers &= ~client->num_lock_mask; -#endif - - modifiers |= keyboard_modifiers; - - send_fake_modifier_key_event (client, modifiers, TRUE); - send_virtual_keyboard_key (xdisplay, keycode, TRUE, 20); - //XSync (xdisplay, False); - send_virtual_keyboard_key (xdisplay, keycode, FALSE, 20); - // XSync (xdisplay, False); - send_fake_modifier_key_event (client, modifiers, FALSE); - - if (old_keysym != xkeysym) - replace_keycode (client, keycode, &old_keysym); -} - -static void -send_fake_key_events (SeatEmitter *client, - EekSymbol *symbol, - guint keyboard_modifiers) -{ - /* Ignore modifier keys */ - if (eek_symbol_is_modifier (symbol)) - return; - - /* If symbol is a text, convert chars in it to keysym */ - if (EEK_IS_TEXT(symbol)) { - const gchar *utf8 = eek_text_get_text (EEK_TEXT(symbol)); - glong items_written; - gunichar *ucs4 = g_utf8_to_ucs4_fast (utf8, -1, &items_written); - gint i; - - for (i = 0; i < items_written; i++) { - guint xkeysym; - EekKeysym *keysym; - gchar *name; - - name = g_strdup_printf ("U%04X", ucs4[i]); - xkeysym = XStringToKeysym (name); - g_free (name); - - keysym = eek_keysym_new (xkeysym); - send_fake_key_events (client, - EEK_SYMBOL(keysym), - keyboard_modifiers); - } - g_free (ucs4); - return; - } - - if (EEK_IS_KEYSYM(symbol)) { - guint xkeysym = eek_keysym_get_xkeysym (EEK_KEYSYM(symbol)); - send_fake_key_event (client, xkeysym, keyboard_modifiers); - } -} - -static void -on_key_activated (EekboardContext *context, - guint keycode, - EekSymbol *symbol, - guint modifiers, - gpointer user_data) -{ - SeatEmitter *client = user_data; - - if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) { - client->keyboards_head = g_slist_next (client->keyboards_head); - if (client->keyboards_head == NULL) - client->keyboards_head = client->keyboards; - eekboard_context_set_keyboard (client->context, - GPOINTER_TO_UINT(client->keyboards_head->data), - NULL); - return; - } - - if (g_strcmp0 (eek_symbol_get_name (symbol), "preferences") == 0) { - gchar *argv[2]; - GError *error; - - argv[0] = g_build_filename (LIBEXECDIR, "eekboard-setup", NULL); - argv[1] = NULL; - - error = NULL; - if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error)) { - g_warning ("can't spawn %s: %s", argv[0], error->message); - g_error_free (error); - } - g_free (argv[0]); - return; - } - - send_fake_key_events (client, symbol, modifiers); -} - -#if 0 -/* Finds the first key code for each modifier and saves it in modifier_keycodes */ -static void -update_modifier_keycodes (Client *client) -{ - GdkDisplay *display = gdk_display_get_default (); - Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); - XModifierKeymap *mods; - gint i, j; - - mods = XGetModifierMapping (xdisplay); - for (i = 0; i < 8; i++) { - client->modifier_keycodes[i] = 0; - for (j = 0; j < mods->max_keypermod; j++) { - KeyCode keycode = mods->modifiermap[mods->max_keypermod * i + j]; - if (keycode != 0) { - client->modifier_keycodes[i] = keycode; - break; - } - } - } - XFreeModifiermap (mods); -} -#endif -gboolean -client_enable_xtest (SeatEmitter *client) -{ - //GdkDisplay *display = gdk_display_get_default (); - //Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); - int opcode, event_base, error_base, major_version, minor_version; - - /* FIXME: need at least to fetch an xkb keymap (but what for?) - g_assert (display); - - if (!XTestQueryExtension (xdisplay, - &event_base, &error_base, - &major_version, &minor_version)) { - g_warning ("XTest extension is not available"); - return FALSE; - } - - if (!XkbQueryExtension (xdisplay, - &opcode, &event_base, &error_base, - &major_version, &minor_version)) { - g_warning ("Xkb extension is not available"); - return FALSE; - } - - if (!client->xkb) - client->xkb = XkbGetMap (xdisplay, XkbKeySymsMask, XkbUseCoreKbd); - g_assert (client->xkb); - - update_modifier_keycodes (client); -*/ - client->key_activated_handler = - g_signal_connect (client->context, "key-activated", - G_CALLBACK(on_key_activated), client); - - return TRUE; -} - -void -client_disable_xtest (SeatEmitter *client) -{ - //if (client->xkb) { - // XkbFreeKeyboard (client->xkb, 0, TRUE); /* free_all = TRUE */ - //client->xkb = NULL; - //} -} -//#endif /* HAVE_XTEST */ diff --git a/src/client.h b/src/client.h deleted file mode 100644 index 749b779d..00000000 --- a/src/client.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2010-2011 Daiki Ueno - * Copyright (C) 2010-2011 Red Hat, Inc. - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef CLIENT_H -#define CLIENT_H 1 - -#include - -G_BEGIN_DECLS - -#define TYPE_CLIENT (client_get_type()) -#define CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLIENT, Client)) -#define CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLIENT, ClientClass)) -#define IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLIENT)) -#define IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLIENT)) -#define CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLIENT, ClientClass)) - -typedef struct _Client SeatEmitter; - -SeatEmitter *client_new (GDBusConnection *connection); - -gboolean client_set_keyboards (SeatEmitter *client, - const gchar * const *keyboard); - -gboolean client_enable_xkl (SeatEmitter *client); -void client_disable_xkl (SeatEmitter *client); - -gboolean client_enable_atspi_focus (SeatEmitter *client); -void client_disable_atspi_focus (SeatEmitter *client); - -gboolean client_enable_atspi_keystroke (SeatEmitter *client); -void client_disable_atspi_keystroke (SeatEmitter *client); - -gboolean client_enable_xtest (SeatEmitter *client); -void client_disable_xtest (SeatEmitter *client); - -gboolean client_enable_ibus_focus (SeatEmitter *client); -void client_disable_ibus_focus (SeatEmitter *client); - -G_END_DECLS -#endif /* CLIENT_H */ diff --git a/src/preferences-dialog.c b/src/preferences-dialog.c deleted file mode 100644 index 084941a8..00000000 --- a/src/preferences-dialog.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (C) 2011 Daiki Ueno - * Copyright (C) 2011 Red Hat, Inc. - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include -#include "preferences-dialog.h" -#include - -struct _PreferencesDialog { - GtkWidget *dialog; - GtkWidget *repeat_toggle; - GtkWidget *repeat_delay_scale; - GtkWidget *repeat_speed_scale; - GtkWidget *auto_hide_toggle; - GtkWidget *auto_hide_delay_scale; - GtkWidget *selected_keyboards_treeview; - GtkWidget *up_button; - GtkWidget *down_button; - GtkWidget *add_button; - GtkWidget *remove_button; - - GtkWidget *new_keyboard_dialog; - GtkWidget *available_keyboards_treeview; - - GList *available_keyboards; - GSettings *settings; -}; - -static gboolean -get_rate (GValue *value, - GVariant *variant, - gpointer user_data) -{ - int rate; - gdouble fraction; - - rate = g_variant_get_uint32 (variant); - fraction = 1.0 / ((gdouble) rate / 1000.0); - g_value_set_double (value, fraction); - return TRUE; -} - -static GVariant * -set_rate (const GValue *value, - const GVariantType *expected_type, - gpointer user_data) -{ - gdouble rate; - int msecs; - - rate = g_value_get_double (value); - msecs = (1 / rate) * 1000; - return g_variant_new_uint32 (msecs); -} - -static void -add_keyboard_to_treeview (GtkTreeView *treeview, - const gchar *id, - const gchar *longname) -{ - GtkTreeModel *model = gtk_tree_view_get_model (treeview); - GtkTreeIter iter; - - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - gchar *_id; - gtk_tree_model_get (model, &iter, 0, &_id, -1); - if (g_strcmp0 (id, _id) == 0) { - g_free (_id); - return; - } - g_free (_id); - } while (gtk_tree_model_iter_next (model, &iter)); - } - - gtk_list_store_append (GTK_LIST_STORE(model), - &iter); - gtk_list_store_set (GTK_LIST_STORE(model), - &iter, - 0, id, - 1, longname, - -1); -} - -static void -add_keyboard (GtkWidget *button, PreferencesDialog *dialog) -{ - gint retval = gtk_dialog_run (GTK_DIALOG(dialog->new_keyboard_dialog)); - if (retval == GTK_RESPONSE_OK) { - GtkTreeSelection *selection; - GtkTreeModel *model; - GList *rows, *p; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->available_keyboards_treeview)); - rows = gtk_tree_selection_get_selected_rows (selection, &model); - for (p = rows; p; p = p->next) { - GtkTreeIter iter; - if (gtk_tree_model_get_iter (model, &iter, p->data)) { - gchar *id, *longname; - gtk_tree_model_get (model, &iter, 0, &id, 1, &longname, -1); - add_keyboard_to_treeview (GTK_TREE_VIEW(dialog->selected_keyboards_treeview), - id, - longname); - g_free (id); - g_free (longname); - } - } - } - gtk_widget_hide (dialog->new_keyboard_dialog); -} - -static void -remove_keyboard (GtkWidget *button, PreferencesDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GList *rows, *p; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->selected_keyboards_treeview)); - rows = gtk_tree_selection_get_selected_rows (selection, &model); - for (p = rows; p; p = p->next) { - GtkTreeIter iter; - if (gtk_tree_model_get_iter (model, &iter, p->data)) - gtk_list_store_remove (GTK_LIST_STORE(model), &iter); - } -} - -static void -up_keyboard (GtkWidget *button, PreferencesDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->selected_keyboards_treeview)); - if (gtk_tree_selection_get_selected (selection, &model, &iter)) { - GtkTreeIter prev = iter; - if (gtk_tree_model_iter_previous (model, &prev)) - gtk_list_store_swap (GTK_LIST_STORE(model), &iter, &prev); - } -} - -static void -down_keyboard (GtkWidget *button, PreferencesDialog *dialog) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->selected_keyboards_treeview)); - if (gtk_tree_selection_get_selected (selection, &model, &iter)) { - GtkTreeIter next = iter; - if (gtk_tree_model_iter_next (model, &next)) - gtk_list_store_swap (GTK_LIST_STORE(model), &iter, &next); - } -} - -static void -selection_changed_cb (GtkTreeSelection *selection, PreferencesDialog *dialog) -{ - gint count = gtk_tree_selection_count_selected_rows (selection); - if (count > 0) { - gtk_widget_set_sensitive (dialog->remove_button, TRUE); - gtk_widget_set_sensitive (dialog->up_button, TRUE); - gtk_widget_set_sensitive (dialog->down_button, TRUE); - } else { - gtk_widget_set_sensitive (dialog->remove_button, FALSE); - gtk_widget_set_sensitive (dialog->up_button, FALSE); - gtk_widget_set_sensitive (dialog->down_button, FALSE); - } -} - -static gint -compare_keyboard_id (const EekXmlKeyboardDesc *desc, const char *id) -{ - return g_strcmp0 (desc->id, id); -} - -static void -populate_selected_keyboards (PreferencesDialog *dialog) -{ - gchar **strv, **p; - - strv = g_settings_get_strv (dialog->settings, "keyboards"); - for (p = strv; *p != NULL; p++) { - GList *head = g_list_find_custom (dialog->available_keyboards, - *p, - (GCompareFunc) compare_keyboard_id); - if (head == NULL) { - g_warning ("unknown keyboard %s", *p); - } else { - EekXmlKeyboardDesc *desc = head->data; - add_keyboard_to_treeview (GTK_TREE_VIEW(dialog->selected_keyboards_treeview), - desc->id, - desc->longname); - } - } - g_strfreev (strv); -} - -static void -populate_available_keyboards (PreferencesDialog *dialog) -{ - GList *p; - - for (p = dialog->available_keyboards; p; p = p->next) { - EekXmlKeyboardDesc *desc = p->data; - add_keyboard_to_treeview (GTK_TREE_VIEW(dialog->available_keyboards_treeview), - desc->id, - desc->longname); - } -} - -static void -save_keyboards (PreferencesDialog *dialog) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GList *list = NULL, *head; - gchar **strv, **p; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW(dialog->selected_keyboards_treeview)); - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - gchar *id; - gtk_tree_model_get (model, &iter, 0, &id, -1); - list = g_list_prepend (list, id); - } while (gtk_tree_model_iter_next (model, &iter)); - } - list = g_list_reverse (list); - - strv = g_new0 (gchar *, g_list_length (list) + 1); - for (head = list, p = strv; head; head = head->next, p++) { - *p = head->data; - } - g_settings_set_strv (dialog->settings, - "keyboards", - (const gchar * const *)strv); - g_strfreev (strv); - g_list_free (list); -} - -PreferencesDialog * -preferences_dialog_new (void) -{ - PreferencesDialog *dialog; - gchar *ui_path; - GtkBuilder *builder; - GObject *object; - GError *error; - GtkListStore *store; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkTreeSelection *selection; - - dialog = g_slice_new0 (PreferencesDialog); - dialog->settings = g_settings_new ("org.fedorahosted.eekboard"); - - builder = gtk_builder_new (); - gtk_builder_set_translation_domain (builder, "eekboard"); - ui_path = g_build_filename (PKGDATADIR, - "preferences-dialog.ui", - NULL); - error = NULL; - if (gtk_builder_add_from_file (builder, ui_path, &error) == 0) { - g_warning ("can't load %s: %s", ui_path, error->message); - g_error_free (error); - } - g_free (ui_path); - - object = gtk_builder_get_object (builder, "dialog"); - dialog->dialog = GTK_WIDGET(object); - - object = gtk_builder_get_object (builder, "repeat_toggle"); - dialog->repeat_toggle = GTK_WIDGET(object); - - g_settings_bind (dialog->settings, "repeat", - dialog->repeat_toggle, "active", - G_SETTINGS_BIND_DEFAULT); - - object = gtk_builder_get_object (builder, "repeat_delay_scale"); - dialog->repeat_delay_scale = GTK_WIDGET(object); - - g_settings_bind (dialog->settings, "repeat-delay", - gtk_range_get_adjustment (GTK_RANGE (dialog->repeat_delay_scale)), "value", - G_SETTINGS_BIND_DEFAULT); - - object = gtk_builder_get_object (builder, "repeat_speed_scale"); - dialog->repeat_speed_scale = GTK_WIDGET(object); - - g_settings_bind_with_mapping (dialog->settings, "repeat-interval", - gtk_range_get_adjustment (GTK_RANGE (gtk_builder_get_object (builder, "repeat_speed_scale"))), "value", - G_SETTINGS_BIND_DEFAULT, - get_rate, set_rate, NULL, NULL); - - object = gtk_builder_get_object (builder, "auto_hide_toggle"); - dialog->auto_hide_toggle = GTK_WIDGET(object); - - g_settings_bind (dialog->settings, "auto-hide", - dialog->auto_hide_toggle, "active", - G_SETTINGS_BIND_DEFAULT); - - object = gtk_builder_get_object (builder, "auto_hide_delay_scale"); - dialog->auto_hide_delay_scale = GTK_WIDGET(object); - - g_settings_bind (dialog->settings, "auto-hide-delay", - gtk_range_get_adjustment (GTK_RANGE (dialog->auto_hide_delay_scale)), "value", - G_SETTINGS_BIND_DEFAULT); - - object = gtk_builder_get_object (builder, - "selected_keyboards_treeview"); - dialog->selected_keyboards_treeview = GTK_WIDGET(object); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (object)); - g_signal_connect (G_OBJECT(selection), "changed", - G_CALLBACK(selection_changed_cb), dialog); - - renderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new ()); - column = gtk_tree_view_column_new_with_attributes ("Keyboard", - renderer, - "text", - 1, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (object), column); - - object = gtk_builder_get_object (builder, "up_button"); - dialog->up_button = GTK_WIDGET(object); - g_signal_connect (object, "clicked", - G_CALLBACK(up_keyboard), dialog); - - object = gtk_builder_get_object (builder, "down_button"); - dialog->down_button = GTK_WIDGET(object); - g_signal_connect (object, "clicked", - G_CALLBACK(down_keyboard), dialog); - - object = gtk_builder_get_object (builder, "add_button"); - dialog->add_button = GTK_WIDGET(object); - g_signal_connect (object, "clicked", - G_CALLBACK(add_keyboard), dialog); - - object = gtk_builder_get_object (builder, "remove_button"); - dialog->remove_button = GTK_WIDGET(object); - g_signal_connect (object, "clicked", - G_CALLBACK(remove_keyboard), dialog); - - object = gtk_builder_get_object (builder, "new_keyboard_dialog"); - dialog->new_keyboard_dialog = GTK_WIDGET(object); - - object = gtk_builder_get_object (builder, - "available_keyboards_treeview"); - dialog->available_keyboards_treeview = GTK_WIDGET(object); - - renderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new ()); - column = gtk_tree_view_column_new_with_attributes ("Keyboard", - renderer, - "text", - 1, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (object), column); - - object = gtk_builder_get_object (builder, - "available_keyboards_liststore"); - store = GTK_LIST_STORE(object); - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store), - 1, - GTK_SORT_ASCENDING); - - dialog->available_keyboards = eek_xml_list_keyboards (); - - populate_selected_keyboards (dialog); - populate_available_keyboards (dialog); - - g_object_unref (builder); - - return dialog; -} - -void -preferences_dialog_run (PreferencesDialog *dialog) -{ - gtk_window_present (GTK_WINDOW(dialog->dialog)); - gtk_dialog_run (GTK_DIALOG(dialog->dialog)); - save_keyboards (dialog); -} - -void -preferences_dialog_free (PreferencesDialog *dialog) -{ - gtk_widget_destroy (dialog->dialog); - // gtk_widget_destroy (dialog->new_keyboard_dialog); - - g_object_unref (dialog->settings); - g_list_free_full (dialog->available_keyboards, - (GDestroyNotify) eek_xml_keyboard_desc_free); - - g_slice_free (PreferencesDialog, dialog); -} diff --git a/src/preferences-dialog.h b/src/preferences-dialog.h deleted file mode 100644 index 85ee8f7a..00000000 --- a/src/preferences-dialog.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2011 Daiki Ueno - * Copyright (C) 2011 Red Hat, Inc. - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef PREFERENCES_DIALOG_H -#define PREFERENCES_DIALOG_H 1 - -#include - -G_BEGIN_DECLS - -typedef struct _PreferencesDialog PreferencesDialog; - -PreferencesDialog *preferences_dialog_new (void); -void preferences_dialog_run (PreferencesDialog *dialog); -void preferences_dialog_free (PreferencesDialog *dialog); - -G_END_DECLS -#endif /* PREFERENCES_DIALOG_H */ diff --git a/src/preferences-dialog.ui b/src/preferences-dialog.ui deleted file mode 100644 index 3caf4150..00000000 --- a/src/preferences-dialog.ui +++ /dev/null @@ -1,729 +0,0 @@ - - - - - gtk-close - - - gtk-cancel - - - Select - gtk-ok - - - 100 - 2000 - 500 - 10 - 10 - - - - - - - - - - - False - 5 - Keyboard - True - dialog - - - True - False - vertical - 2 - - - True - False - end - - - - - - - - - - - - True - True - True - action1 - - - False - True - 3 - - - - - False - True - end - 0 - - - - - True - True - 10 - - - True - False - 12 - 18 - - - True - False - 6 - - - True - False - 0 - Repeat Keys - - - - - - False - False - 0 - - - - - True - False - - - True - False - - - - False - False - 0 - - - - - True - False - 6 - - - Key presses _repeat when key is held down - True - True - False - False - True - 0 - True - - - False - False - 0 - - - - - True - False - 2 - 4 - - - True - False - 0 - _Speed: - True - center - repeat_speed_scale - - - 1 - 2 - GTK_SHRINK - - - - - - True - False - 1 - 10 - Short - - - - - - - 1 - 2 - GTK_SHRINK - - - - - - True - False - 1 - 10 - Slow - - - - - - - 1 - 2 - 1 - 2 - GTK_SHRINK - - - - - - True - True - repeat_delay_adjustment - False - - - 2 - 3 - - - - - - True - True - repeat_speed_adjustment - False - - - Repeat keys speed - - - - - 2 - 3 - 1 - 2 - - - - - - True - False - 0 - Long - - - - - - - 3 - 4 - GTK_SHRINK - - - - - - True - False - 0 - Fast - - - - - - - 3 - 4 - 1 - 2 - GTK_SHRINK - - - - - - True - False - 0 - _Delay: - True - center - repeat_delay_scale - - - GTK_SHRINK - - - - - - False - False - 1 - - - - - True - True - 1 - - - - - False - False - 1 - - - - - False - False - 0 - - - - - True - False - 6 - - - True - False - 0 - Focus following - - - - - - False - False - 0 - - - - - True - False - - - True - False - - - - False - False - 0 - - - - - True - False - 6 - - - Auto hide window when focus is out - True - True - False - False - True - 0 - True - - - False - False - 0 - - - - - True - False - 4 - - - True - False - 0 - _Delay: - True - center - auto_hide_delay_scale - - - GTK_SHRINK - - - - - - True - False - 1 - 10 - Short - - - - - - - 1 - 2 - GTK_SHRINK - - - - - - True - True - auto_hide_delay_adjustment - False - - - 2 - 3 - - - - - - True - False - 0 - Long - - - - - - - 3 - 4 - GTK_SHRINK - - - - - - False - False - 1 - - - - - True - True - 1 - - - - - False - False - 1 - - - - - False - False - 1 - - - - - - - True - False - Typing - - - False - - - - - True - False - 12 - 18 - - - True - True - selected_keyboards_liststore - False - False - - - - - - True - True - 0 - - - - - True - False - 2 - end - - - gtk-go-up - True - False - True - True - False - True - - - False - True - 0 - - - - - gtk-go-down - True - False - True - True - False - True - - - False - True - 1 - - - - - gtk-add - True - True - True - False - True - - - False - True - 2 - - - - - gtk-remove - True - False - True - True - False - True - - - False - True - 3 - - - - - False - False - 1 - - - - - 1 - - - - - True - False - Keyboards - - - 1 - False - - - - - - - - - - - True - True - 1 - - - - - - button1 - - - - False - 5 - 430 - True - dialog - dialog - - - False - vertical - 2 - - - False - end - - - True - True - True - action2 - - - False - True - 0 - - - - - True - True - True - action3 - - - False - True - 1 - - - - - False - True - end - 0 - - - - - True - True - in - - - True - True - available_keyboards_liststore - False - False - - - - - - - - True - True - 1 - - - - - - button2 - button3 - - - - 100 - 2000 - 500 - 10 - 10 - - - 0.5 - 50 - 33.299999999999997 - 1 - 1 - - - - - - - - - - diff --git a/src/setup-main.c b/src/setup-main.c deleted file mode 100644 index c2afbccc..00000000 --- a/src/setup-main.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2012 Daiki Ueno - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include "preferences-dialog.h" -#include -#include - -int -main (int argc, char **argv) -{ - PreferencesDialog *dialog; - - if (!gtk_init_check (&argc, &argv)) { - g_printerr ("Can't init GTK\n"); - return EXIT_FAILURE; - } - - dialog = preferences_dialog_new (); - preferences_dialog_run (dialog); - preferences_dialog_free (dialog); - - return EXIT_SUCCESS; -}