From 9ff549799d56bad3d019fd5c1b774145e2f48e1e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 24 Sep 2022 09:20:12 -0400 Subject: [PATCH] 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(-) delete mode 100644 gdk/gdkkeynames.c rename gdk/{keyname-table.h => keynamesprivate.h} (99%) diff --git a/gdk/gdkkeynames.c b/gdk/gdkkeynames.c deleted file mode 100644 index 7600f4fc61..0000000000 --- a/gdk/gdkkeynames.c +++ /dev/null @@ -1,103 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" - -#include "gdkkeysyms.h" - -/* Key handling not part of the keymap */ - -#include "keyname-table.h" - -#include -#include -#include - -#define GDK_NUM_KEYS G_N_ELEMENTS (gdk_keys_by_keyval) - -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, - GDK_NUM_KEYS, 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, - GDK_NUM_KEYS, sizeof (gdk_key), - gdk_keys_name_compare); - if (found != NULL) - return found->keyval; - else - return GDK_KEY_VoidSymbol; -} 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 +#include +#include + 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 <