changeset 1229:e9ea1497ac9d

Fix a key binding issue on FreeBSD The problem is that on FreeBSD with wide ncurses support, isprint() returns TRUE for special key codes like Fn, KEY_PPAGE, etc. This (ugly) patch makes possible for these special keys to be bound anyway.
author Mikael Berthe <mikael@lilotux.net>
date Fri, 08 Jun 2007 16:35:02 +0200
parents 9a68fe4515dc
children 08bf580f417f
files mcabber/src/screen.c
diffstat 1 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/screen.c	Sun May 20 22:01:20 2007 +0200
+++ b/mcabber/src/screen.c	Fri Jun 08 16:35:02 2007 +0200
@@ -395,6 +395,41 @@
   g_string_free(sbuf, TRUE);
 }
 
+//  is_speckey(key)
+// Return TRUE if key is a special code, i.e. no char should be displayed on
+// the screen.  It's not very nice, it's a workaround for the systems where
+// isprint(KEY_PPAGE) returns TRUE...
+static int is_speckey(int key)
+{
+  switch (key) {
+    case 127:
+    case 393:
+    case 402:
+    case KEY_BACKSPACE:
+    case KEY_DC:
+    case KEY_LEFT:
+    case KEY_RIGHT:
+    case KEY_UP:
+    case KEY_DOWN:
+    case KEY_PPAGE:
+    case KEY_NPAGE:
+    case KEY_HOME:
+    case KEY_END:
+    case KEY_EOL:
+        return TRUE;
+  }
+
+  // Fn keys
+  if (key >= 265 && key < 265+12)
+    return TRUE;
+
+  // Special key combinations
+  if (key >= 513 && key <= 521)
+    return TRUE;
+
+  return FALSE;
+}
+
 void scr_InitLocaleCharSet(void)
 {
   setlocale(LC_CTYPE, "");
@@ -3239,7 +3274,7 @@
 
 display:
   if (display_char) {
-    if (kcode.utf8 ? iswprint(key) : isprint(key)) {
+    if (kcode.utf8 ? iswprint(key) : (isprint(key) && !is_speckey(key))) {
       char tmpLine[INPUTLINE_LENGTH+1];
 
       // Check the line isn't too long