Re: [gtk-vnc-devel] May I add the function that gtk-vnc send 'ISO_Left_Tab' keysym to vncserver



Hi Anthony,

I make the patch that applied your two indications.
Moreover, this patch contains the fix of two bugs and a
modification besides the indications.

The change points from the last patch:

1)Use GDK key symbols instead of X11 key symbols.

2)Remove CR characters.

3)Make keycode conversion function.
  - I make the keycode conversion function on "x_keymap.c".

4)Modify structure used for keycode conversion.
  - The type of the keycodes member variable is changed from "guint*"
    to "GdkKeymapKey*".

5)Modify getting timing and release timing of keymap entries.
  - Because "g_free" function is not called on the last patch, the memory leak is done.

Thanks.

Signed-off-by: Hiroyuki Kaguchi <fj7025cf aa jp fujitsu com>
diff -r fb8ab9818527 src/vncdisplay.c
--- a/src/vncdisplay.c	Fri Mar 07 11:24:19 2008 -0600
+++ b/src/vncdisplay.c	Mon Mar 10 14:29:11 2008 +0900
@@ -567,6 +567,8 @@ static gboolean key_event(GtkWidget *wid
 					    &group,
 					    &level,
 					    &consumed);
+
+	keyval = x_keymap_get_keyval_from_keycode(key->hardware_keycode, keyval);
 
 	/*
 	 * More VNC suckiness with key state & modifiers in particular
@@ -1357,6 +1359,8 @@ static void *vnc_coroutine(void *opaque)
 	}
 
 	GVNC_DEBUG("Started background coroutine\n");
+	x_keymap_set_keymap_entries();
+
 	if (priv->fd != -1) {
 		if (!gvnc_open_fd(priv->gvnc, priv->fd))
 			goto cleanup;
@@ -1404,6 +1408,7 @@ static void *vnc_coroutine(void *opaque)
 	gvnc_close(priv->gvnc);
 	emit_signal_delayed(obj, VNC_DISCONNECTED, &s);
 	g_idle_add(delayed_unref_object, obj);
+	x_keymap_free_keymap_entries();
 	/* Co-routine exits now - the VncDisplay object may no longer exist,
 	   so don't do anything else now unless you like SEGVs */
 	return NULL;
diff -r fb8ab9818527 src/x_keymap.c
--- a/src/x_keymap.c	Fri Mar 07 11:24:19 2008 -0600
+++ b/src/x_keymap.c	Mon Mar 10 14:29:11 2008 +0900
@@ -33,6 +33,7 @@
  */
 
 #include "x_keymap.h"
+#include <gdk/gdkkeysyms.h>
 
 static const uint8_t x_keycode_to_pc_keycode_table[115] = {
    0xc7,      /*  97  Home   */
@@ -116,6 +117,17 @@ static const uint8_t x_keycode_to_pc_key
    0x73,         /* 211 backslash */
 };
 
+/* keycode translation for sending ISO_Left_Send
+ * to vncserver
+ */
+static struct {
+	GdkKeymapKey *keys;
+	gint n_keys;
+	guint keyval;
+} untranslated_keys[] = {{NULL, 0, GDK_Tab}};
+
+static unsigned int ref_count_for_untranslated_keys = 0;
+
 /* FIXME N.B. on Windows, gtk probably returns PC scan codes */
 
 uint8_t x_keycode_to_pc_keycode(int keycode)
@@ -131,3 +143,44 @@ uint8_t x_keycode_to_pc_keycode(int keyc
 
 	return keycode;
 }
+
+/* Set the keymap entries */
+void x_keymap_set_keymap_entries()
+{
+	int i;
+	if (ref_count_for_untranslated_keys == 0)
+		for (i = 0; i < sizeof(untranslated_keys) / sizeof(untranslated_keys[0]); i++)
+			gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
+							  untranslated_keys[i].keyval,
+							  &untranslated_keys[i].keys,
+							  &untranslated_keys[i].n_keys);
+	ref_count_for_untranslated_keys++;
+}
+
+/* Free the keymap entries */
+void x_keymap_free_keymap_entries()
+{
+	int i;
+
+	if (ref_count_for_untranslated_keys == 0)
+		return;
+
+	ref_count_for_untranslated_keys--;
+	if (ref_count_for_untranslated_keys == 0)
+		for (i = 0; i < sizeof(untranslated_keys) / sizeof(untranslated_keys[0]); i++)
+			g_free(untranslated_keys[i].keys);
+
+}
+
+/* Get the keyval from the keycode without the level. */
+guint x_keymap_get_keyval_from_keycode(guint keycode, guint keyval)
+{
+	int i, k;
+	for (i = 0; i < sizeof(untranslated_keys) / sizeof(untranslated_keys[0]); i++) {
+		if (keycode == untranslated_keys[i].keys[0].keycode) {
+			return untranslated_keys[i].keyval;
+		}
+	}
+
+	return keyval;
+}
diff -r fb8ab9818527 src/x_keymap.h
--- a/src/x_keymap.h	Fri Mar 07 11:24:19 2008 -0600
+++ b/src/x_keymap.h	Mon Mar 10 14:29:11 2008 +0900
@@ -2,7 +2,11 @@
 #define _GTK_VNC_X_KEYMAP_H
 
 #include <stdint.h>
+#include <gdk/gdk.h>
 
 uint8_t x_keycode_to_pc_keycode(int keycode);
+void x_keymap_set_keymap_entries();
+void x_keymap_free_keymap_entries();
+guint x_keymap_get_keyval_from_keycode(guint keycode, guint keyval);
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]