From 8ab4fb7946d6f8065ef6c8e4c5dee6050dacf0ff Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Wed, 24 Aug 2011 15:24:59 +0900 Subject: [PATCH] Implement preferences dialog. --- src/Makefile.am | 9 +- src/client.c | 11 + src/preferences-dialog.c | 155 ++++++++++ src/preferences-dialog.h | 29 ++ src/preferences-dialog.ui | 626 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 827 insertions(+), 3 deletions(-) create mode 100644 src/preferences-dialog.c create mode 100644 src/preferences-dialog.h create mode 100644 src/preferences-dialog.ui diff --git a/src/Makefile.am b/src/Makefile.am index da64b6b4..80c460bf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,7 +26,8 @@ eekboard_CFLAGS = \ $(GTK_CFLAGS) \ $(XKB_CFLAGS) \ $(LIBXKLAVIER_CFLAGS) \ - -DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\" + -DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\" \ + -DPKGDATADIR=\"$(pkgdatadir)\" eekboard_LDADD = \ $(top_builddir)/eekboard/libeekboard.la \ @@ -58,8 +59,8 @@ eekboard_LDADD += \ $(IBUS_LIBS) endif -eekboard_headers = client.h -eekboard_SOURCES = client.c client-main.c +eekboard_headers = client.h preferences-dialog.h +eekboard_SOURCES = client.c preferences-dialog.c client-main.c eekboard_server_CFLAGS = \ -I$(top_srcdir) \ @@ -98,3 +99,5 @@ eekboard_HEADERS = \ noinst_HEADERS = \ $(eekboard_headers) \ $(eekboard_server_headers) + +dist_pkgdata_DATA = preferences-dialog.ui \ No newline at end of file diff --git a/src/client.c b/src/client.c index 9a2a4d83..bb4dabd8 100644 --- a/src/client.c +++ b/src/client.c @@ -42,6 +42,7 @@ #include "eekboard/eekboard-client.h" #include "eekboard/eekboard-xklutil.h" #include "client.h" +#include "preferences-dialog.h" #include @@ -715,6 +716,9 @@ set_keyboard (Client *client, GSList *keyboards = NULL; gchar **strv, **p; + g_return_val_if_fail (keyboard != NULL, FALSE); + g_return_val_if_fail (*keyboard != '\0', FALSE); + if (client->keyboards) g_slist_free (client->keyboards); @@ -962,8 +966,15 @@ on_key_pressed (EekboardContext *context, eekboard_context_set_keyboard (client->context, GPOINTER_TO_UINT(client->keyboards->data), NULL); + return; } + if (g_strcmp0 (eek_symbol_get_name (symbol), "preferences") == 0) { + PreferencesDialog *dialog = preferences_dialog_new (); + preferences_dialog_run (dialog); + } + + send_fake_key_event (client, symbol, modifiers, TRUE); send_fake_key_event (client, symbol, modifiers, FALSE); } diff --git a/src/preferences-dialog.c b/src/preferences-dialog.c new file mode 100644 index 00000000..3eeac5e2 --- /dev/null +++ b/src/preferences-dialog.c @@ -0,0 +1,155 @@ +/* + * 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" + +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 *start_fullscreen_toggle; + GtkWidget *keyboard_entry; + + 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); + g_debug ("Getting fraction %f for msecs %d", fraction, rate); + 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; + g_debug ("Setting repeat rate to %d", msecs); + return g_variant_new_uint32 (msecs); +} + +PreferencesDialog * +preferences_dialog_new (void) +{ + PreferencesDialog *dialog; + gchar *ui_path; + GtkBuilder *builder; + GObject *object; + GError *error; + + 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_strdup_printf ("%s/%s", PKGDATADIR, "preferences-dialog.ui"); + error = NULL; + gtk_builder_add_from_file (builder, ui_path, &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, "start_fullscreen_toggle"); + dialog->start_fullscreen_toggle = GTK_WIDGET(object); + + g_settings_bind (dialog->settings, "start-fullscreen", + dialog->start_fullscreen_toggle, "active", + G_SETTINGS_BIND_DEFAULT); + + object = + gtk_builder_get_object (builder, "keyboard_entry"); + dialog->keyboard_entry = GTK_WIDGET(object); + + g_settings_bind (dialog->settings, "keyboard", + GTK_ENTRY(dialog->keyboard_entry), "text", + G_SETTINGS_BIND_DEFAULT); + + return dialog; +} + +void +preferences_dialog_run (PreferencesDialog *dialog) +{ + gtk_dialog_run (GTK_DIALOG(dialog->dialog)); + gtk_widget_destroy (dialog->dialog); +} diff --git a/src/preferences-dialog.h b/src/preferences-dialog.h new file mode 100644 index 00000000..55574fac --- /dev/null +++ b/src/preferences-dialog.h @@ -0,0 +1,29 @@ +/* + * 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 + +G_BEGIN_DECLS + +typedef struct _PreferencesDialog PreferencesDialog; + +PreferencesDialog *preferences_dialog_new (void); +void preferences_dialog_run (PreferencesDialog *dialog); + +G_END_DECLS +#endif /* PREFERENCES_DIALOG_H */ diff --git a/src/preferences-dialog.ui b/src/preferences-dialog.ui new file mode 100644 index 00000000..4755ca75 --- /dev/null +++ b/src/preferences-dialog.ui @@ -0,0 +1,626 @@ + + + + + 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 + 6 + + + True + False + 0 + Keyboard + + + + + + False + False + 0 + + + + + True + False + + + True + False + + + + False + False + 0 + + + + + True + False + 6 + + + Start in fullscreen mode + True + True + False + False + True + 0 + True + + + False + False + 0 + + + + + True + False + 4 + + + True + False + Keyboard type: + + + + + True + True + + + + 1 + 4 + + + + + True + True + 1 + + + + + True + True + 1 + + + + + False + False + 1 + + + + + False + False + 2 + + + + + + + True + False + Typing + + + False + + + + + + + + + + + + + + + + + True + True + 1 + + + + + + button1 + + + + gtk-close + + + 100 + 2000 + 500 + 10 + 10 + + + 0.5 + 50 + 33.299999999999997 + 1 + 1 + + + 100 + 2000 + 500 + 10 + 10 + +