[libgnomekbd/next: 17/17] Move gkbd_keyboard_drawing_dialog utilities into gkbd-keyboard-display
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgnomekbd/next: 17/17] Move gkbd_keyboard_drawing_dialog utilities into gkbd-keyboard-display
- Date: Fri, 2 Sep 2022 16:51:05 +0000 (UTC)
commit c4fe2426b976895554f9f7c4c6a61fd84ba270c5
Author: Corentin Noël <corentin noel collabora com>
Date: Sun Aug 7 23:09:08 2022 +0200
Move gkbd_keyboard_drawing_dialog utilities into gkbd-keyboard-display
It's easy enough to not include it in a library
libgnomekbd/gkbd-keyboard-drawing.c | 231 --------------------------------
libgnomekbd/gkbd-keyboard-drawing.h | 10 --
libgnomekbd/meson.build | 7 -
tools/gkbd-keyboard-display.c | 239 ++++++++++++++++++++++++++++++++++
tools/meson.build | 9 +-
{libgnomekbd => tools}/show-layout.ui | 0
6 files changed, 247 insertions(+), 249 deletions(-)
---
diff --git a/libgnomekbd/gkbd-keyboard-drawing.c b/libgnomekbd/gkbd-keyboard-drawing.c
index b57538e..f5b0954 100644
--- a/libgnomekbd/gkbd-keyboard-drawing.c
+++ b/libgnomekbd/gkbd-keyboard-drawing.c
@@ -38,8 +38,6 @@
#define INVALID_KEYCODE ((guint)(-1))
-#define GTK_RESPONSE_PRINT 2
-
#define CAIRO_LINE_WIDTH 1.0
#define KEY_FONT_SIZE 12
@@ -85,20 +83,6 @@ typedef struct {
G_DEFINE_TYPE_WITH_PRIVATE (GkbdKeyboardDrawing, gkbd_keyboard_drawing, GTK_TYPE_DRAWING_AREA)
-static GkbdKeyboardDrawingGroupLevel defaultGroupsLevels[] = {
- {0, 1},
- {0, 3},
- {0, 0},
- {0, 2}
-};
-
-static GkbdKeyboardDrawingGroupLevel *pGroupsLevels[] = {
- defaultGroupsLevels,
- defaultGroupsLevels + 1,
- defaultGroupsLevels + 2,
- defaultGroupsLevels + 3
-};
-
static void gkbd_keyboard_drawing_set_mods (GkbdKeyboardDrawing * drawing,
guint mods);
@@ -2602,218 +2586,3 @@ gkbd_keyboard_drawing_set_layout (GkbdKeyboardDrawing * drawing,
}
g_object_unref (G_OBJECT (data));
}
-
-static void
-gkbd_keyboard_drawing_dialog_set_layout_name (GtkWidget * dialog,
- const gchar * layout_name)
-{
- gtk_window_set_title (GTK_WINDOW (dialog), layout_name);
- g_object_set_data_full (G_OBJECT (dialog), "layout_name",
- g_strdup (layout_name), g_free);
-}
-
-static void
-gkbd_keyboard_drawing_dialog_response (GtkWidget * dialog, gint resp)
-{
- GdkRectangle rect;
- GtkWidget *kbdraw;
- const gchar *groupName;
-
- switch (resp) {
- case GTK_RESPONSE_CLOSE:
- gtk_window_get_position (GTK_WINDOW (dialog), &rect.x,
- &rect.y);
- gtk_window_get_size (GTK_WINDOW (dialog), &rect.width,
- &rect.height);
- gkbd_preview_save_position (&rect);
- gtk_widget_destroy (dialog);
- break;
- case GTK_RESPONSE_PRINT:
- kbdraw =
- GTK_WIDGET (g_object_get_data
- (G_OBJECT (dialog), "kbdraw"));
- groupName =
- (const gchar *) g_object_get_data (G_OBJECT (dialog),
- "groupName");
- gkbd_keyboard_drawing_print (GKBD_KEYBOARD_DRAWING
- (kbdraw), GTK_WINDOW (dialog),
- groupName ? groupName :
- _("Unknown"));
- }
-}
-
-void
-gkbd_keyboard_drawing_dialog_set_group (GtkWidget * dialog,
- XklConfigRegistry * registry,
- gint group)
-{
- XkbComponentNamesRec component_names;
- XklConfigRec *xkl_data;
- XklEngine *engine =
- xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
- (gdk_display_get_default ()));
-
- xkl_data = xkl_config_rec_new ();
- if (xkl_config_rec_get_from_server (xkl_data, engine)) {
- int num_layouts = g_strv_length (xkl_data->layouts);
- int num_variants = g_strv_length (xkl_data->variants);
- if (group >= 0 && group < num_layouts
- && group < num_variants) {
- XklConfigItem *xki = xkl_config_item_new ();
- gchar *l = g_strdup (xkl_data->layouts[group]);
- gchar *v = g_strdup (xkl_data->variants[group]);
- const gchar *layout_name = NULL;
- gchar **p;
- int i;
-
- if ((p = xkl_data->layouts) != NULL)
- for (i = num_layouts; --i >= 0;)
- g_free (*p++);
-
- if ((p = xkl_data->variants) != NULL)
- for (i = num_variants; --i >= 0;)
- g_free (*p++);
-
- xkl_data->layouts =
- g_realloc (xkl_data->layouts,
- sizeof (char *) * 2);
- xkl_data->variants =
- g_realloc (xkl_data->variants,
- sizeof (char *) * 2);
- xkl_data->layouts[0] = l;
- xkl_data->variants[0] = v;
- xkl_data->layouts[1] = xkl_data->variants[1] =
- NULL;
-
- if (v[0] != 0) {
- strncpy (xki->name, v,
- XKL_MAX_CI_NAME_LENGTH);
- xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
- if (xkl_config_registry_find_variant
- (registry, l, xki))
- layout_name = xki->description;
- } else {
- strncpy (xki->name, l,
- XKL_MAX_CI_NAME_LENGTH);
- xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
- if (xkl_config_registry_find_layout
- (registry, xki))
- layout_name = xki->description;
- }
- gkbd_keyboard_drawing_dialog_set_layout_name
- (dialog, layout_name);
- g_object_unref (xki);
- }
-
- if (xkl_xkb_config_native_prepare
- (engine, xkl_data, &component_names)) {
- GtkWidget *kbdraw =
- g_object_get_data (G_OBJECT (dialog),
- "kbdraw");
- if (!gkbd_keyboard_drawing_set_keyboard
- (GKBD_KEYBOARD_DRAWING (kbdraw),
- &component_names))
- gkbd_keyboard_drawing_set_keyboard
- (GKBD_KEYBOARD_DRAWING (kbdraw), NULL);
- xkl_xkb_config_native_cleanup (engine,
- &component_names);
- }
- }
-
- g_object_unref (G_OBJECT (xkl_data));
-}
-
-GtkWidget *
-gkbd_keyboard_drawing_dialog_new ()
-{
- GtkBuilder *builder;
- GtkWidget *dialog, *kbdraw;
- GdkRectangle *rect;
- GError *error = NULL;
-
- builder = gtk_builder_new ();
- gtk_builder_add_from_file (builder, UIDIR "/show-layout.ui",
- &error);
-
- if (error) {
- g_error ("building ui from %s failed: %s",
- UIDIR "/show-layout.ui", error->message);
- g_clear_error (&error);
- }
-
- dialog =
- GTK_WIDGET (gtk_builder_get_object
- (builder, "gswitchit_layout_view"));
- kbdraw = gkbd_keyboard_drawing_new ();
-
- gkbd_keyboard_drawing_set_groups_levels (GKBD_KEYBOARD_DRAWING
- (kbdraw), pGroupsLevels);
-
- g_object_set_data (G_OBJECT (dialog), "builderData", builder);
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK
- (gkbd_keyboard_drawing_dialog_response), NULL);
-
- gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
-
- gtk_box_pack_start (GTK_BOX
- (gtk_builder_get_object
- (builder, "preview_vbox")), kbdraw, TRUE,
- TRUE, 0);
-
- g_object_set_data (G_OBJECT (dialog), "kbdraw", kbdraw);
-
- g_signal_connect_swapped (dialog, "destroy",
- G_CALLBACK (g_object_unref),
- g_object_get_data (G_OBJECT (dialog),
- "builderData"));
-
- rect = gkbd_preview_load_position ();
- if (rect != NULL) {
- gtk_window_move (GTK_WINDOW (dialog), rect->x, rect->y);
- g_free (rect);
- }
-
- return dialog;
-}
-
-void
-gkbd_keyboard_drawing_dialog_set_layout (GtkWidget * dialog,
- XklConfigRegistry * registry,
- const gchar * full_layout)
-{
- const gchar *layout_name = "?";
- XklConfigItem *xki = xkl_config_item_new ();
- gchar *layout = NULL, *variant = NULL;
-
- GkbdKeyboardDrawing *kbdraw =
- GKBD_KEYBOARD_DRAWING (g_object_get_data
- (G_OBJECT (dialog), "kbdraw"));
-
- if (full_layout == NULL || full_layout[0] == 0)
- return;
-
- gkbd_keyboard_drawing_set_layout (kbdraw, full_layout);
-
- if (gkbd_keyboard_config_split_items
- (full_layout, &layout, &variant)) {
- if (variant != NULL) {
- strncpy (xki->name, variant,
- XKL_MAX_CI_NAME_LENGTH);
- xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
- if (xkl_config_registry_find_variant
- (registry, layout, xki))
- layout_name = xki->description;
- } else {
- strncpy (xki->name, layout,
- XKL_MAX_CI_NAME_LENGTH);
- xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
- if (xkl_config_registry_find_layout
- (registry, xki))
- layout_name = xki->description;
- }
- }
-
- gkbd_keyboard_drawing_dialog_set_layout_name (dialog, layout_name);
- g_object_unref (xki);
-}
diff --git a/libgnomekbd/gkbd-keyboard-drawing.h b/libgnomekbd/gkbd-keyboard-drawing.h
index d336ef8..581a82e 100644
--- a/libgnomekbd/gkbd-keyboard-drawing.h
+++ b/libgnomekbd/gkbd-keyboard-drawing.h
@@ -86,15 +86,5 @@ void gkbd_keyboard_drawing_print (GkbdKeyboardDrawing * drawing,
GtkWindow * parent_window,
const gchar * description);
-GtkWidget *gkbd_keyboard_drawing_dialog_new (void);
-
-void gkbd_keyboard_drawing_dialog_set_group (GtkWidget * dialog,
- XklConfigRegistry * registry,
- gint group);
-
-void gkbd_keyboard_drawing_dialog_set_layout (GtkWidget * dialog,
- XklConfigRegistry * registry,
- const gchar * layout);
-
G_END_DECLS
#endif /* #ifndef GKBD_KEYBOARD_DRAWING_H */
diff --git a/libgnomekbd/meson.build b/libgnomekbd/meson.build
index 261aeb2..79a411c 100644
--- a/libgnomekbd/meson.build
+++ b/libgnomekbd/meson.build
@@ -1,12 +1,6 @@
pkg_data_dir = get_option('prefix') / get_option('datadir') / 'libgnomekbd'
-ui_dir = pkg_data_dir / 'ui'
icons_dir = pkg_data_dir / 'icons'
-install_data(
- 'show-layout.ui',
- install_dir: ui_dir
-)
-
install_data(
'kbdled-caps-lock.svg',
'kbdled-num-lock.svg',
@@ -106,7 +100,6 @@ libgnomekbdui_lib = library(
version: meson.project_version(),
soversion: library_version,
c_args: [
- '-DUIDIR="@0@"'.format(ui_dir),
'-DDATADIR="@0@"'.format(pkg_data_dir),
'-DICONSDIR="@0@"'.format(icons_dir),
],
diff --git a/tools/gkbd-keyboard-display.c b/tools/gkbd-keyboard-display.c
index 5b1476c..c8be5db 100644
--- a/tools/gkbd-keyboard-display.c
+++ b/tools/gkbd-keyboard-display.c
@@ -25,9 +25,23 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
+#include <glib/gi18n-lib.h>
+
#include <libxklavier/xklavier.h>
#include <libgnomekbd/gkbd-keyboard-drawing.h>
+#define GTK_RESPONSE_PRINT 2
+
+GtkWidget *gkbd_keyboard_drawing_dialog_new (void);
+
+void gkbd_keyboard_drawing_dialog_set_group (GtkWidget * dialog,
+ XklConfigRegistry * registry,
+ gint group);
+
+void gkbd_keyboard_drawing_dialog_set_layout (GtkWidget * dialog,
+ XklConfigRegistry * registry,
+ const gchar * layout);
+
static GMainLoop *loop;
static gint group = 0;
static gchar *layout = NULL;
@@ -39,6 +53,27 @@ static GOptionEntry options[] = {
{ NULL }
};
+static GkbdKeyboardDrawingGroupLevel defaultGroupsLevels[] = {
+ {0, 1},
+ {0, 3},
+ {0, 0},
+ {0, 2}
+};
+
+static GkbdKeyboardDrawingGroupLevel *pGroupsLevels[] = {
+ defaultGroupsLevels,
+ defaultGroupsLevels + 1,
+ defaultGroupsLevels + 2,
+ defaultGroupsLevels + 3
+};
+
+extern gboolean xkl_xkb_config_native_prepare (XklEngine * engine,
+ const XklConfigRec * data,
+ gpointer component_names);
+
+extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
+ gpointer component_names);
+
static void
destroy_dialog ()
{
@@ -100,3 +135,207 @@ main (int argc, char **argv)
return 0;
}
+
+
+static void
+gkbd_keyboard_drawing_dialog_set_layout_name (GtkWidget * dialog,
+ const gchar * layout_name)
+{
+ gtk_window_set_title (GTK_WINDOW (dialog), layout_name);
+ g_object_set_data_full (G_OBJECT (dialog), "layout_name",
+ g_strdup (layout_name), g_free);
+}
+
+static void
+gkbd_keyboard_drawing_dialog_response (GtkWidget * dialog, gint resp)
+{
+ GtkWidget *kbdraw;
+ const gchar *groupName;
+
+ switch (resp) {
+ case GTK_RESPONSE_CLOSE:
+ gtk_widget_destroy (dialog);
+ break;
+ case GTK_RESPONSE_PRINT:
+ kbdraw =
+ GTK_WIDGET (g_object_get_data
+ (G_OBJECT (dialog), "kbdraw"));
+ groupName =
+ (const gchar *) g_object_get_data (G_OBJECT (dialog),
+ "groupName");
+ gkbd_keyboard_drawing_print (GKBD_KEYBOARD_DRAWING
+ (kbdraw), GTK_WINDOW (dialog),
+ groupName ? groupName :
+ _("Unknown"));
+ }
+}
+
+void
+gkbd_keyboard_drawing_dialog_set_group (GtkWidget * dialog,
+ XklConfigRegistry * registry,
+ gint group)
+{
+ XkbComponentNamesRec component_names;
+ XklConfigRec *xkl_data;
+ XklEngine *engine =
+ xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
+ (gdk_display_get_default ()));
+
+ xkl_data = xkl_config_rec_new ();
+ if (xkl_config_rec_get_from_server (xkl_data, engine)) {
+ int num_layouts = g_strv_length (xkl_data->layouts);
+ int num_variants = g_strv_length (xkl_data->variants);
+ if (group >= 0 && group < num_layouts
+ && group < num_variants) {
+ XklConfigItem *xki = xkl_config_item_new ();
+ gchar *l = g_strdup (xkl_data->layouts[group]);
+ gchar *v = g_strdup (xkl_data->variants[group]);
+ const gchar *layout_name = NULL;
+ gchar **p;
+ int i;
+
+ if ((p = xkl_data->layouts) != NULL)
+ for (i = num_layouts; --i >= 0;)
+ g_free (*p++);
+
+ if ((p = xkl_data->variants) != NULL)
+ for (i = num_variants; --i >= 0;)
+ g_free (*p++);
+
+ xkl_data->layouts =
+ g_realloc (xkl_data->layouts,
+ sizeof (char *) * 2);
+ xkl_data->variants =
+ g_realloc (xkl_data->variants,
+ sizeof (char *) * 2);
+ xkl_data->layouts[0] = l;
+ xkl_data->variants[0] = v;
+ xkl_data->layouts[1] = xkl_data->variants[1] =
+ NULL;
+
+ if (v[0] != 0) {
+ strncpy (xki->name, v,
+ XKL_MAX_CI_NAME_LENGTH);
+ xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
+ if (xkl_config_registry_find_variant
+ (registry, l, xki))
+ layout_name = xki->description;
+ } else {
+ strncpy (xki->name, l,
+ XKL_MAX_CI_NAME_LENGTH);
+ xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
+ if (xkl_config_registry_find_layout
+ (registry, xki))
+ layout_name = xki->description;
+ }
+ gkbd_keyboard_drawing_dialog_set_layout_name
+ (dialog, layout_name);
+ g_object_unref (xki);
+ }
+
+ if (xkl_xkb_config_native_prepare
+ (engine, xkl_data, &component_names)) {
+ GtkWidget *kbdraw =
+ g_object_get_data (G_OBJECT (dialog),
+ "kbdraw");
+ if (!gkbd_keyboard_drawing_set_keyboard
+ (GKBD_KEYBOARD_DRAWING (kbdraw),
+ &component_names))
+ gkbd_keyboard_drawing_set_keyboard
+ (GKBD_KEYBOARD_DRAWING (kbdraw), NULL);
+ xkl_xkb_config_native_cleanup (engine,
+ &component_names);
+ }
+ }
+
+ g_object_unref (G_OBJECT (xkl_data));
+}
+
+GtkWidget *
+gkbd_keyboard_drawing_dialog_new ()
+{
+ GtkBuilder *builder;
+ GtkWidget *dialog, *kbdraw;
+ GdkRectangle *rect;
+ GError *error = NULL;
+
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_file (builder, UIDIR "/show-layout.ui",
+ &error);
+
+ if (error) {
+ g_error ("building ui from %s failed: %s",
+ UIDIR "/show-layout.ui", error->message);
+ g_clear_error (&error);
+ }
+
+ dialog =
+ GTK_WIDGET (gtk_builder_get_object
+ (builder, "gswitchit_layout_view"));
+ kbdraw = gkbd_keyboard_drawing_new ();
+
+ gkbd_keyboard_drawing_set_groups_levels (GKBD_KEYBOARD_DRAWING
+ (kbdraw), pGroupsLevels);
+
+ g_object_set_data (G_OBJECT (dialog), "builderData", builder);
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK
+ (gkbd_keyboard_drawing_dialog_response), NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
+
+ gtk_box_pack_start (GTK_BOX
+ (gtk_builder_get_object
+ (builder, "preview_vbox")), kbdraw, TRUE,
+ TRUE, 0);
+
+ g_object_set_data (G_OBJECT (dialog), "kbdraw", kbdraw);
+
+ g_signal_connect_swapped (dialog, "destroy",
+ G_CALLBACK (g_object_unref),
+ g_object_get_data (G_OBJECT (dialog),
+ "builderData"));
+
+ return dialog;
+}
+
+void
+gkbd_keyboard_drawing_dialog_set_layout (GtkWidget * dialog,
+ XklConfigRegistry * registry,
+ const gchar * full_layout)
+{
+ const gchar *layout_name = "?";
+ XklConfigItem *xki = xkl_config_item_new ();
+ gchar *layout = NULL, *variant = NULL;
+
+ GkbdKeyboardDrawing *kbdraw =
+ GKBD_KEYBOARD_DRAWING (g_object_get_data
+ (G_OBJECT (dialog), "kbdraw"));
+
+ if (full_layout == NULL || full_layout[0] == 0)
+ return;
+
+ gkbd_keyboard_drawing_set_layout (kbdraw, full_layout);
+
+ if (gkbd_keyboard_config_split_items
+ (full_layout, &layout, &variant)) {
+ if (variant != NULL) {
+ strncpy (xki->name, variant,
+ XKL_MAX_CI_NAME_LENGTH);
+ xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
+ if (xkl_config_registry_find_variant
+ (registry, layout, xki))
+ layout_name = xki->description;
+ } else {
+ strncpy (xki->name, layout,
+ XKL_MAX_CI_NAME_LENGTH);
+ xki->name[XKL_MAX_CI_NAME_LENGTH - 1] = 0;
+ if (xkl_config_registry_find_layout
+ (registry, xki))
+ layout_name = xki->description;
+ }
+ }
+
+ gkbd_keyboard_drawing_dialog_set_layout_name (dialog, layout_name);
+ g_object_unref (xki);
+}
diff --git a/tools/meson.build b/tools/meson.build
index 8f9671c..8d71110 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -1,10 +1,17 @@
+ui_dir = pkg_data_dir / 'ui'
+install_data(
+ 'show-layout.ui',
+ install_dir: ui_dir
+)
+
gkbd_keyboard_display_exe = executable(
'gkbd-keyboard-display',
'gkbd-keyboard-display.c',
dependencies: libgnomekbdui_dep,
include_directories: root_include,
c_args: [
- '-DGNOMELOCALEDIR="@0@"'.format(get_option('prefix') / get_option('datadir') / 'locale')
+ '-DGNOMELOCALEDIR="@0@"'.format(get_option('prefix') / get_option('datadir') / 'locale'),
+ '-DUIDIR="@0@"'.format(ui_dir),
],
install: true,
)
diff --git a/libgnomekbd/show-layout.ui b/tools/show-layout.ui
similarity index 100%
rename from libgnomekbd/show-layout.ui
rename to tools/show-layout.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]