diff options
author | Sergey V. Udaltsov <svu@src.gnome.org> | 2006-09-27 20:27:09 +0000 |
---|---|---|
committer | Sergey V. Udaltsov <svu@src.gnome.org> | 2006-09-27 20:27:09 +0000 |
commit | 7699e660c678df45a7d0ce2edaec1611e210d583 (patch) | |
tree | a1e92bed7f668a851e276ec79a9bca846d70a2a1 /test | |
download | libgnomekbd-7699e660c678df45a7d0ce2edaec1611e210d583.tar.gz |
Initial revision
Diffstat (limited to 'test')
-rw-r--r-- | test/.indent.pro | 2 | ||||
-rw-r--r-- | test/Makefile.am | 45 | ||||
-rw-r--r-- | test/gkbd-config-registry-server.c | 38 | ||||
-rw-r--r-- | test/gkbd-indicator-test.c | 79 | ||||
-rw-r--r-- | test/gkbd-keyboard-drawing-test.c | 286 |
5 files changed, 450 insertions, 0 deletions
diff --git a/test/.indent.pro b/test/.indent.pro new file mode 100644 index 0000000..bdff074 --- /dev/null +++ b/test/.indent.pro @@ -0,0 +1,2 @@ +-kr -i8 -pcs -lps -psl + diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..1eabbe8 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,45 @@ +noinst_PROGRAMS = gkbd-indicator-test \ + gkbd-keyboard-drawing-test \ + gkbd-config-registry-server + +gkbd_config_registry_server_CFLAGS= \ + $(WARN_CFLAGS) -I$(top_srcdir) -Wall -Werror \ + $(DBUS_CFLAGS) \ + $(LIBXKLAVIER_CFLAGS) + +gkbd_config_registry_server_LDFLAGS= \ + $(DBUS_LIBS) \ + $(LIBXKLAVIER_LIBS) \ + $(top_builddir)/libgnomekbd/libgnomekbd.la + +gkbd_indicator_test_CFLAGS= \ + $(WARN_CFLAGS) -I$(top_srcdir) -Wall -Werror \ + $(GTK_CFLAGS) \ + $(LIBGLADE_CFLAGS) \ + $(LIBGNOME_CFLAGS) \ + $(LIBGNOMEUI_CFLAGS) \ + $(LIBXKLAVIER_CFLAGS) \ + -I$(top_srcdir)/intl \ + -DSYS_PLUGIN_DIR=\"$(libdir)/gnomekbd/\" \ + -DG_LOG_DOMAIN=\"GnomeKbdIndicatorTest\" \ + -DDATADIR=\"$(datadir)\" + +gkbd_indicator_test_LDFLAGS= \ + $(GTK_LIBS) \ + $(LIBGLADE_LIBS) \ + $(LIBGNOME_LIBS) \ + $(LIBGNOMEUI_LIBS) \ + $(LIBXKLAVIER_LIBS) \ + $(top_builddir)/libgnomekbd/libgnomekbd.la \ + $(top_builddir)/libgnomekbd/libgnomekbdui.la + +gkbd_keyboard_drawing_test_CFLAGS= \ + $(WARN_CFLAGS) -I$(top_srcdir) \ + $(GTK_CFLAGS) + +gkbd_keyboard_drawing_test_LDFLAGS= \ + $(GTK_LIBS) \ + $(LIBGNOME_LIBS) \ + $(LIBXKLAVIER_LIBS) \ + $(top_builddir)/libgnomekbd/libgnomekbd.la \ + $(top_builddir)/libgnomekbd/libgnomekbdui.la diff --git a/test/gkbd-config-registry-server.c b/test/gkbd-config-registry-server.c new file mode 100644 index 0000000..8c43dbd --- /dev/null +++ b/test/gkbd-config-registry-server.c @@ -0,0 +1,38 @@ +#include <config.h> + +#include <stdio.h> +#include <X11/Xlib.h> +#include <libxklavier/xklavier.h> +#include <dbus/dbus-glib-bindings.h> + +#ifdef HAVE_SETLOCALE +# include <locale.h> +#endif + +#include "libgnomekbd/gkbd-config-registry.h" + +static GMainLoop *loop; + +int +main () +{ + g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | + G_TYPE_DEBUG_SIGNALS); + +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); +#endif + + GkbdConfigRegistry *reg = + GKBD_CONFIG_REGISTRY (g_object_new + (gkbd_config_registry_get_type + (), NULL)); + + loop = g_main_loop_new (NULL, FALSE); + + g_main_loop_run (loop); + + g_object_unref (reg); + + return 0; +} diff --git a/test/gkbd-indicator-test.c b/test/gkbd-indicator-test.c new file mode 100644 index 0000000..a2ca21d --- /dev/null +++ b/test/gkbd-indicator-test.c @@ -0,0 +1,79 @@ +/* + * 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 2 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include "libxklavier/xklavier.h" +#include "libgnomekbd/gkbd-indicator.h" + +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> + +#include <gdk/gdkscreen.h> +#include <gdk/gdkx.h> +#include <gnome.h> +#include <glade/glade.h> + +#include "X11/XKBlib.h" + +int +main (int argc, char **argv) +{ + GtkWidget *gki; + GtkWidget *mainwin; + GtkWidget *vbox; + + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + /* Different data dir defs in g-a and g-c-c */ + gnome_program_init ("gkbd-indicator-test", VERSION, + LIBGNOMEUI_MODULE, argc, argv, + GNOME_PARAM_APP_DATADIR, DATADIR, NULL); + + glade_gnome_init (); + + mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gki = gkbd_indicator_new (); + gkbd_indicator_set_tooltips_format (_ + ("Keyboard Indicator Test (%s)")); + gkbd_indicator_set_parent_tooltips (GKBD_INDICATOR (gki), TRUE); + + gtk_window_resize (GTK_WINDOW (mainwin), 250, 250); + vbox = gtk_vbox_new (TRUE, 6); + + gtk_container_add (GTK_CONTAINER (mainwin), vbox); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); + gtk_container_add (GTK_CONTAINER (vbox), + gtk_label_new (_("Indicator:"))); + gtk_container_add (GTK_CONTAINER (vbox), gki); + + gtk_widget_show_all (mainwin); + + g_signal_connect (G_OBJECT (mainwin), + "destroy", G_CALLBACK (gtk_main_quit), NULL); + + + gtk_main (); + + return 0; +} diff --git a/test/gkbd-keyboard-drawing-test.c b/test/gkbd-keyboard-drawing-test.c new file mode 100644 index 0000000..026cd79 --- /dev/null +++ b/test/gkbd-keyboard-drawing-test.c @@ -0,0 +1,286 @@ +/* $Id$ */ +/* + * kbdraw.c: main program file for kbdraw + * + * Copyright (c) 2003 Noah Levitt + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +#include <gtk/gtk.h> +#include <popt.h> +#include <stdlib.h> +#include <string.h> +#include "libgnomekbd/gkbd-keyboard-drawing.h" + + +static gchar *groups = NULL; +static gchar *levels = NULL; +static gchar *symbols = NULL; +static gchar *keycodes = NULL; +static gchar *geometry = NULL; +static struct poptOption options[] = { + {"groups", '\0', POPT_ARG_STRING, &groups, 0, + "Keyboard groups to display, from 1-4. Up to four groups only may be displayed. Examples: --groups=3 or --groups=1,2,1,2", + "group1[,group2[,group3[,group4]]]"}, + {"levels", '\0', POPT_ARG_STRING, &levels, 0, + "Keyboard shift levels to display, from 1-64. Up to four shift levels only may be displayed. Examples: --levels=3 or --levels=1,2,1,2", + "level1[,level2[,level3[,level4]]]"}, + {"symbols", '\0', POPT_ARG_STRING, &symbols, 0, + "Symbols component of the keyboard. If you omit this option, it is obtained from the X server; that is, the keyboard that is currently configured is drawn. Examples: --symbols=us or --symbols=us(pc104)+iso9995-3+group(switch)+ctrl(nocaps)", + NULL}, + {"keycodes", '\0', POPT_ARG_STRING, &keycodes, 0, + "Keycodes component of the keyboard. If you omit this option, it is obtained from the X server; that is, the keyboard that is currently configured is drawn. Examples: --keycodes=xfree86+aliases(qwerty)", + NULL}, + {"geometry", '\0', POPT_ARG_STRING, &geometry, 0, + "Geometry xkb component. If you omit this option, it is obtained from the X server; that is, the keyboard that is currently configured is drawn. Example: --geometry=kinesis", + NULL}, + {"track-modifiers", '\0', POPT_ARG_NONE, NULL, 3, + "Track the current modifiers", NULL}, + {"track-config", '\0', POPT_ARG_NONE, NULL, 4, + "Track the server XKB configuration", NULL}, + {"version", 'v', POPT_ARG_NONE, NULL, 1, "Show current version", + NULL}, + POPT_AUTOHELP {NULL, '\0', 0, NULL, 0} +}; + + +static gboolean +set_groups (gchar * groups_option, + GkbdKeyboardDrawingGroupLevel * groupLevels) +{ + GkbdKeyboardDrawingGroupLevel *pgl = groupLevels; + gint cntr, g; + + groupLevels[0].group = + groupLevels[1].group = + groupLevels[2].group = groupLevels[3].group = -1; + + if (groups_option == NULL) + return TRUE; + + for (cntr = 4; --cntr >= 0;) { + if (*groups_option == '\0') + return FALSE; + + g = *groups_option - '1'; + if (g < 0 || g >= 4) + return FALSE; + + pgl->group = g; + /* printf ("group %d\n", pgl->group); */ + + groups_option++; + if (*groups_option == '\0') + return TRUE; + if (*groups_option != ',') + return FALSE; + + groups_option++; + pgl++; + } + + return TRUE; +} + +static gboolean +set_levels (gchar * levels_option, + GkbdKeyboardDrawingGroupLevel * groupLevels) +{ + GkbdKeyboardDrawingGroupLevel *pgl = groupLevels; + gint cntr, l; + gchar *p; + + groupLevels[0].level = + groupLevels[1].level = + groupLevels[2].level = groupLevels[3].level = -1; + + if (levels_option == NULL) + return TRUE; + + for (cntr = 4; --cntr >= 0;) { + if (*levels_option == '\0') + return FALSE; + + l = (gint) strtol (levels_option, &p, 10) - 1; + if (l < 0 || l >= 64) + return FALSE; + + pgl->level = l; + /* printf ("level %d\n", pgl->level); */ + + levels_option = p; + if (*levels_option == '\0') + return TRUE; + if (*levels_option != ',') + return FALSE; + + levels_option++; + pgl++; + } + + return TRUE; +} + +static void +bad_keycode (GkbdKeyboardDrawing * drawing, guint keycode) +{ + g_warning + ("got keycode %u, which is not on your keyboard according to your configuration", + keycode); +} + +gint +main (gint argc, gchar ** argv) +{ + GtkWidget *window; + GtkWidget *gkbd_keyboard_drawing; + GdkScreen *screen; + gint monitor; + GdkRectangle rect; + poptContext popt_context; + gint rc; + GkbdKeyboardDrawingGroupLevel groupLevels[4] = + { {0, 0}, {1, 0}, {0, 1}, {1, 1} }; + GkbdKeyboardDrawingGroupLevel *pgroupLevels[4] = + { &groupLevels[0], &groupLevels[1], &groupLevels[2], + &groupLevels[3] + }; + gboolean track_config = False, track_modifiers = False; + + gtk_init (&argc, &argv); + + popt_context = + poptGetContext ("kbdraw", argc, (const gchar **) argv, options, + 0); + + for (rc = poptGetNextOpt (popt_context); rc > 0; + rc = poptGetNextOpt (popt_context)) + switch (rc) { + case 1: + g_print ("kbdraw %s\n", VERSION); + exit (0); + case 3: + track_modifiers = True; + break; + case 4: + track_config = True; + break; + } + + if (rc != -1) { + g_printerr ("%s: %s\n", + poptBadOption (popt_context, + POPT_BADOPTION_NOALIAS), + poptStrerror (rc)); + exit (1); + } + + if (!set_groups (groups, groupLevels)) { + g_printerr ("--groups: invalid argument\n"); + exit (1); + } + + if (!set_levels (levels, groupLevels)) { + g_printerr ("--levels: invalid argument\n"); + exit (1); + } + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (G_OBJECT (window), "destroy", + G_CALLBACK (gtk_main_quit), NULL); + + screen = gtk_window_get_screen (GTK_WINDOW (window)); + monitor = gdk_screen_get_monitor_at_point (screen, 0, 0); + gdk_screen_get_monitor_geometry (screen, monitor, &rect); + gtk_window_set_default_size (GTK_WINDOW (window), + rect.width * 4 / 5, + rect.height * 1 / 2); + + gtk_widget_show (window); + + gkbd_keyboard_drawing = gkbd_keyboard_drawing_new (); + gtk_widget_show (gkbd_keyboard_drawing); + gtk_container_add (GTK_CONTAINER (window), gkbd_keyboard_drawing); + + gkbd_keyboard_drawing_set_groups_levels (GKBD_KEYBOARD_DRAWING + (gkbd_keyboard_drawing), + pgroupLevels); + + if (track_modifiers) + gkbd_keyboard_drawing_set_track_modifiers + (GKBD_KEYBOARD_DRAWING (gkbd_keyboard_drawing), TRUE); + if (track_config) + gkbd_keyboard_drawing_set_track_config + (GKBD_KEYBOARD_DRAWING (gkbd_keyboard_drawing), TRUE); + g_signal_connect (G_OBJECT (gkbd_keyboard_drawing), "bad-keycode", + G_CALLBACK (bad_keycode), NULL); + + if (symbols || geometry || keycodes) { + XkbComponentNamesRec names; + gint success; + + memset (&names, '\0', sizeof (names)); + + if (symbols) + names.symbols = symbols; + else + names.symbols = (gchar *) + gkbd_keyboard_drawing_get_symbols + (GKBD_KEYBOARD_DRAWING + (gkbd_keyboard_drawing)); + + if (keycodes) + names.keycodes = keycodes; + else + names.keycodes = (gchar *) + gkbd_keyboard_drawing_get_keycodes + (GKBD_KEYBOARD_DRAWING + (gkbd_keyboard_drawing)); + + if (geometry) + names.geometry = geometry; + else + names.geometry = (gchar *) + gkbd_keyboard_drawing_get_geometry + (GKBD_KEYBOARD_DRAWING + (gkbd_keyboard_drawing)); + + success = + gkbd_keyboard_drawing_set_keyboard + (GKBD_KEYBOARD_DRAWING (gkbd_keyboard_drawing), + &names); + if (!success) { + g_printerr + ("\nError loading new keyboard description with components:\n\n" + " keycodes: %s\n" " types: %s\n" + " compat: %s\n" " symbols: %s\n" + " geometry: %s\n\n", names.keycodes, + names.types, names.compat, names.symbols, + names.geometry); + exit (1); + } + } + + gtk_widget_grab_focus (gkbd_keyboard_drawing); + + gtk_main (); + + return 0; +} |