/pidgin/main: f4a2868ba612: cross-win32: fix keyboard in finch

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon Apr 21 22:28:43 EDT 2014


Changeset: f4a2868ba612cb02bad1d1620fc3fdf6830d71e6
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-22 04:28 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/f4a2868ba612

Description:

cross-win32: fix keyboard in finch

diffstat:

 finch/libgnt/gntkeys.h |  71 ++++++++++++++++++++++++++++++++++++++++---------
 finch/libgnt/gntmain.c |  71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 13 deletions(-)

diffs (207 lines):

diff --git a/finch/libgnt/gntkeys.h b/finch/libgnt/gntkeys.h
--- a/finch/libgnt/gntkeys.h
+++ b/finch/libgnt/gntkeys.h
@@ -43,6 +43,49 @@ extern char *gnt_key_cright;
 
 #define SAFE(x)   ((cur_term && (x)) ? (x) : "")
 
+#ifdef _WIN32
+
+/* XXX: \xe1 is a hacky alias for \x00 key code */
+
+#define GNT_KEY_POPUP "" /* not supported? */
+
+#define GNT_KEY_UP "\xe0\x48"
+#define GNT_KEY_DOWN "\xe0\x50"
+#define GNT_KEY_LEFT "\xe0\x4B"
+#define GNT_KEY_RIGHT "\xe0\x4D"
+
+#define GNT_KEY_CTRL_UP "\xe0\x8d"
+#define GNT_KEY_CTRL_DOWN "\xe0\x91"
+#define GNT_KEY_CTRL_LEFT "\xe0\x73"
+#define GNT_KEY_CTRL_RIGHT "\xe0\x74"
+
+#define GNT_KEY_PGUP "\xe0\x49"
+#define GNT_KEY_PGDOWN "\xe0\x51"
+#define GNT_KEY_HOME "\xe0\x47"
+#define GNT_KEY_END "\xe0\x4f"
+
+#define GNT_KEY_ENTER "\x0d"
+
+#define GNT_KEY_BACKSPACE "\x08"
+#define GNT_KEY_DEL "\xe0\x53"
+#define GNT_KEY_INS "\xe0\x52"
+#define GNT_KEY_BACK_TAB "\xe1\x94"
+
+#define GNT_KEY_F1 "\xe1\x3b"
+#define GNT_KEY_F2 "\xe1\x3c"
+#define GNT_KEY_F3 "\xe1\x3d"
+#define GNT_KEY_F4 "\xe1\x3e"
+#define GNT_KEY_F5 "\xe1\x3f"
+#define GNT_KEY_F6 "\xe1\x40"
+#define GNT_KEY_F7 "\xe1\x41"
+#define GNT_KEY_F8 "\xe1\x42"
+#define GNT_KEY_F9 "\xe1\x43"
+#define GNT_KEY_F10 "\xe1\x44"
+#define GNT_KEY_F11 "\xe0\x85"
+#define GNT_KEY_F12 "\xe0\x86"
+
+#else
+
 #define GNT_KEY_POPUP   SAFE(key_f16)   /* Apparently */
 
 /* Arrow keys */
@@ -68,6 +111,21 @@ extern char *gnt_key_cright;
 #define GNT_KEY_INS    SAFE(key_ic)
 #define GNT_KEY_BACK_TAB ((cur_term && back_tab) ? back_tab : SAFE(key_btab))
 
+#define GNT_KEY_F1         SAFE(key_f1)
+#define GNT_KEY_F2         SAFE(key_f2)
+#define GNT_KEY_F3         SAFE(key_f3)
+#define GNT_KEY_F4         SAFE(key_f4)
+#define GNT_KEY_F5         SAFE(key_f5)
+#define GNT_KEY_F6         SAFE(key_f6)
+#define GNT_KEY_F7         SAFE(key_f7)
+#define GNT_KEY_F8         SAFE(key_f8)
+#define GNT_KEY_F9         SAFE(key_f9)
+#define GNT_KEY_F10        SAFE(key_f10)
+#define GNT_KEY_F11        SAFE(key_f11)
+#define GNT_KEY_F12        SAFE(key_f12)
+
+#endif
+
 #define GNT_KEY_CTRL_A     "\001"
 #define GNT_KEY_CTRL_B     "\002"
 #define GNT_KEY_CTRL_D     "\004"
@@ -91,19 +149,6 @@ extern char *gnt_key_cright;
 #define GNT_KEY_CTRL_X     "\030"
 #define GNT_KEY_CTRL_Y     "\031"
 
-#define GNT_KEY_F1         SAFE(key_f1)
-#define GNT_KEY_F2         SAFE(key_f2)
-#define GNT_KEY_F3         SAFE(key_f3)
-#define GNT_KEY_F4         SAFE(key_f4)
-#define GNT_KEY_F5         SAFE(key_f5)
-#define GNT_KEY_F6         SAFE(key_f6)
-#define GNT_KEY_F7         SAFE(key_f7)
-#define GNT_KEY_F8         SAFE(key_f8)
-#define GNT_KEY_F9         SAFE(key_f9)
-#define GNT_KEY_F10        SAFE(key_f10)
-#define GNT_KEY_F11        SAFE(key_f11)
-#define GNT_KEY_F12        SAFE(key_f12)
-
 /**
  * gnt_init_keys:
  *
diff --git a/finch/libgnt/gntmain.c b/finch/libgnt/gntmain.c
--- a/finch/libgnt/gntmain.c
+++ b/finch/libgnt/gntmain.c
@@ -63,6 +63,12 @@
 #include <ctype.h>
 #include <errno.h>
 
+#ifdef _WIN32
+#undef _getch
+#undef getch
+#include <conio.h>
+#endif
+
 /*
  * Notes: Interesting functions to look at:
  * scr_dump, scr_init, scr_restore: for workspaces
@@ -100,6 +106,7 @@ escape_timeout(gpointer data)
 	return FALSE;
 }
 
+#ifndef _WIN32
 /**
  * detect_mouse_action:
  *
@@ -216,6 +223,7 @@ detect_mouse_action(const char *buffer)
 		gnt_widget_clicked(widget, event, x, y);
 	return TRUE;
 }
+#endif
 
 static gboolean
 io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data)
@@ -234,9 +242,71 @@ io_invoke_error(GIOChannel *source, GIOC
 	return TRUE;
 }
 
+
 static gboolean
 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null)
 {
+#ifdef _WIN32
+	gchar keys[8];
+	gchar *k = keys;
+	int ch;
+	gboolean is_special = FALSE;
+
+	if (wm->mode == GNT_KP_MODE_WAIT_ON_CHILD)
+		return FALSE;
+
+	if (HOLDING_ESCAPE) {
+		*k = '\033';
+		k++;
+		g_source_remove(escape_stuff.timer);
+		escape_stuff.timer = 0;
+	}
+
+	ch = _getch(); /* we could use _getch_nolock */
+
+	/* a small hack - we don't want to put NUL anywhere */
+	if (ch == 0x00)
+		ch = 0xE1;
+
+	if (ch == 0xE0 || ch == 0xE1) {
+		is_special = TRUE;
+		*k = ch;
+		k++;
+		ch = _getch();
+	}
+	k[0] = ch;
+	k[1] = '\0';
+
+	if (ch == 0x1B && !is_special) { /* ESC */
+		escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL);
+		return TRUE;
+	}
+
+	if (wm)
+		gnt_wm_set_event_stack(wm, TRUE);
+
+	if (!is_special) {
+		gchar *converted;
+		gsize converted_len = 0;
+
+		converted = g_locale_to_utf8(k, 1, NULL, &converted_len, NULL);
+		if (converted_len > 0 && converted_len <= 4) {
+			memcpy(k, converted, converted_len);
+			k[converted_len] = '\0';
+		}
+	}
+
+	/* TODO: we could call detect_mouse_action here, but no
+	 * events are triggered (yet?) for mouse on win32.
+	 */
+
+	gnt_wm_process_input(wm, keys);
+
+	if (wm)
+		gnt_wm_set_event_stack(wm, FALSE);
+
+	return TRUE;
+#else
 	char keys[256];
 	gssize rd;
 	char *k;
@@ -309,6 +379,7 @@ end:
 		gnt_wm_set_event_stack(wm, FALSE);
 	g_free(cvrt);
 	return TRUE;
+#endif
 }
 
 static void



More information about the Commits mailing list