[gtk/header-cleanup] gdk: Tweaks to keyname handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/header-cleanup] gdk: Tweaks to keyname handling
- Date: Sat, 24 Sep 2022 13:45:46 +0000 (UTC)
commit b6ad426436301083c1290765e6f3d28425c005bc
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 24 09:20:12 2022 -0400
gdk: Tweaks to keyname handling
Rename the private header to follow our naming
conventions, and drop the extra gdkkeys.c file.
gdk/gdkkeynames.c | 103 -----------------------------
gdk/gdkkeys.c | 73 +++++++++++++++++++-
gdk/gen-keyname-table.pl | 4 +-
gdk/{keyname-table.h => keynamesprivate.h} | 2 +-
4 files changed, 75 insertions(+), 107 deletions(-)
---
diff --git a/gdk/gdkkeys.c b/gdk/gdkkeys.c
index 714d164c84..eb94aa3d59 100644
--- a/gdk/gdkkeys.c
+++ b/gdk/gdkkeys.c
@@ -29,6 +29,11 @@
#include "gdkdisplay.h"
#include "gdkdisplaymanagerprivate.h"
+#include "keynamesprivate.h"
+#include <glib/gprintf.h>
+#include <stdlib.h>
+#include <string.h>
+
enum {
PROP_0,
PROP_DISPLAY,
@@ -614,7 +619,73 @@ gdk_keymap_translate_keyboard_state (GdkKeymap *keymap,
consumed_modifiers);
}
-#include "gdkkeynames.c"
+static int
+gdk_keys_keyval_compare (const void *pkey, const void *pbase)
+{
+ return (*(int *) pkey) - ((gdk_key *) pbase)->keyval;
+}
+
+static char *
+_gdk_keyval_name (guint keyval)
+{
+ static char buf[100];
+ gdk_key *found;
+
+ /* Check for directly encoded 24-bit UCS characters: */
+ if ((keyval & 0xff000000) == 0x01000000)
+ {
+ g_sprintf (buf, "U+%.04X", (keyval & 0x00ffffff));
+ return buf;
+ }
+
+ found = bsearch (&keyval,
+ gdk_keys_by_keyval, G_N_ELEMENTS (gdk_keys_by_keyval),
+ sizeof (gdk_key),
+ gdk_keys_keyval_compare);
+
+ if (found != NULL)
+ {
+ while ((found > gdk_keys_by_keyval) &&
+ ((found - 1)->keyval == keyval))
+ found--;
+
+ return (char *) (keynames + found->offset);
+ }
+ else if (keyval != 0)
+ {
+ g_sprintf (buf, "%#x", keyval);
+ return buf;
+ }
+
+ return NULL;
+}
+
+static int
+gdk_keys_name_compare (const void *pkey, const void *pbase)
+{
+ return strcmp ((const char *) pkey,
+ (const char *) (keynames + ((const gdk_key *) pbase)->offset));
+}
+
+static guint
+_gdk_keyval_from_name (const char *keyval_name)
+{
+ gdk_key *found;
+
+ g_return_val_if_fail (keyval_name != NULL, 0);
+
+ if (strncmp (keyval_name,"XF86", 4) == 0)
+ keyval_name += 4;
+
+ found = bsearch (keyval_name,
+ gdk_keys_by_name, G_N_ELEMENTS (gdk_keys_by_name),
+ sizeof (gdk_key),
+ gdk_keys_name_compare);
+ if (found != NULL)
+ return found->keyval;
+ else
+ return GDK_KEY_VoidSymbol;
+}
/**
* gdk_keyval_name:
diff --git a/gdk/gen-keyname-table.pl b/gdk/gen-keyname-table.pl
index cc47400ef1..a193a7a042 100755
--- a/gdk/gen-keyname-table.pl
+++ b/gdk/gen-keyname-table.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
if (@ARGV != 2) {
- die "Usage: gen-keyname-table.pl keynames.txt keynames-translate.txt > keyname-table.h\n";
+ die "Usage: gen-keyname-table.pl keynames.txt keynames-translate.txt > keynamesprivate.h\n";
}
open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
@@ -38,7 +38,7 @@ $offset = 0;
$date = gmtime;
print <<EOT;
-/* keyname-table.h: Generated by gen-keyname-table.pl from keynames.txt
+/* keynamesprivate.h: Generated by gen-keyname-table.pl from keynames.txt
*
* Date: $date
*
diff --git a/gdk/keyname-table.h b/gdk/keynamesprivate.h
similarity index 99%
rename from gdk/keyname-table.h
rename to gdk/keynamesprivate.h
index 29b747e5d8..a14d95f221 100644
--- a/gdk/keyname-table.h
+++ b/gdk/keynamesprivate.h
@@ -1,4 +1,4 @@
-/* keyname-table.h: Generated by gen-keyname-table.pl from keynames.txt
+/* keynametableprivate.h: Generated by gen-keyname-table.pl from keynames.txt
*
* Date: Sat Oct 7 23:00:42 2017
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]