changeset 14876:70623f0d5cdc

[gaim-migrate @ 17645] Use terminfo/termcap information (from ncurses) as much as possible. There still need to be some manual 'refinement' based on $TERM. I'll see if I can get rid of those. Also, I am probably going to allow users to provide information that terminfo can't provide, like the keycode for ctrl+up etc. Let me know if any of the keybinding doesn't work. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 01 Nov 2006 03:38:23 +0000
parents 7357d46ba817
children c01f62c83647
files console/libgnt/gntbox.c console/libgnt/gntcombobox.c console/libgnt/gntentry.c console/libgnt/gntkeys.c console/libgnt/gntkeys.h console/libgnt/gntmain.c console/libgnt/gntmenu.c console/libgnt/gntstyle.c console/libgnt/gnttextview.h console/libgnt/gnttree.c console/libgnt/gnttree.h console/libgnt/gntwidget.c
diffstat 12 files changed, 106 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntbox.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntbox.c	Wed Nov 01 03:38:23 2006 +0000
@@ -285,11 +285,11 @@
 
 	if (text[0] == 27)
 	{
-		if (strcmp(text+1, GNT_KEY_LEFT) == 0)
+		if (strcmp(text, GNT_KEY_LEFT) == 0)
 		{
 			find_prev_focus(box);
 		}
-		else if (strcmp(text+1, GNT_KEY_RIGHT) == 0)
+		else if (strcmp(text, GNT_KEY_RIGHT) == 0)
 		{
 			find_next_focus(box);
 		}
--- a/console/libgnt/gntcombobox.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntcombobox.c	Wed Nov 01 03:38:23 2006 +0000
@@ -135,8 +135,8 @@
 	{
 		if (text[0] == 27)
 		{
-			if (strcmp(text + 1, GNT_KEY_UP) == 0 ||
-					strcmp(text + 1, GNT_KEY_DOWN) == 0)
+			if (strcmp(text, GNT_KEY_UP) == 0 ||
+					strcmp(text, GNT_KEY_DOWN) == 0)
 			{
 				popup_dropdown(box);
 				return TRUE;
@@ -170,10 +170,10 @@
 
 	if (event == GNT_MOUSE_SCROLL_UP) {
 		if (dshowing)
-			gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_UP);
+			gnt_widget_key_pressed(box->dropdown, GNT_KEY_UP);
 	} else if (event == GNT_MOUSE_SCROLL_DOWN) {
 		if (dshowing)
-			gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_DOWN);
+			gnt_widget_key_pressed(box->dropdown, GNT_KEY_DOWN);
 	} else if (event == GNT_LEFT_MOUSE_DOWN) {
 		if (dshowing) {
 			set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown)));
--- a/console/libgnt/gntentry.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntentry.c	Wed Nov 01 03:38:23 2006 +0000
@@ -550,14 +550,14 @@
 
 	gnt_widget_class_register_action(parent_class, "cursor-home", move_start,
 				GNT_KEY_CTRL_A, NULL);
-	gnt_widget_register_binding(parent_class, "cursor-home", "\033" GNT_KEY_HOME, NULL);
+	gnt_widget_register_binding(parent_class, "cursor-home", GNT_KEY_HOME, NULL);
 	gnt_widget_class_register_action(parent_class, "cursor-end", move_end,
 				GNT_KEY_CTRL_E, NULL);
-	gnt_widget_register_binding(parent_class, "cursor-end", "\033" GNT_KEY_END, NULL);
+	gnt_widget_register_binding(parent_class, "cursor-end", GNT_KEY_END, NULL);
 	gnt_widget_class_register_action(parent_class, "delete-prev", backspace,
 				GNT_KEY_BACKSPACE, NULL);
 	gnt_widget_class_register_action(parent_class, "delete-next", delkey,
-				"\033" GNT_KEY_DEL, NULL);
+				GNT_KEY_DEL, NULL);
 	gnt_widget_register_binding(parent_class, "delete-next", GNT_KEY_CTRL_D, NULL);
 	gnt_widget_class_register_action(parent_class, "delete-start", del_to_home,
 				GNT_KEY_CTRL_U, NULL);
@@ -572,17 +572,17 @@
 	gnt_widget_class_register_action(parent_class, "cursor-prev-word", move_back_word,
 				NULL, NULL);
 	gnt_widget_class_register_action(parent_class, "cursor-prev", move_back,
-				"\033" GNT_KEY_LEFT, NULL);
+				GNT_KEY_LEFT, NULL);
 	gnt_widget_register_binding(parent_class, "cursor-prev", GNT_KEY_CTRL_B, NULL);
 	gnt_widget_class_register_action(parent_class, "cursor-next", move_forward,
-				"\033" GNT_KEY_RIGHT, NULL);
+				GNT_KEY_RIGHT, NULL);
 	gnt_widget_register_binding(parent_class, "cursor-next", GNT_KEY_CTRL_F, NULL);
 	gnt_widget_class_register_action(parent_class, "suggest-show", suggest_show,
 				"\t", NULL);
 	gnt_widget_class_register_action(parent_class, "suggest-next", suggest_next,
-				"\033" GNT_KEY_DOWN, NULL);
+				GNT_KEY_DOWN, NULL);
 	gnt_widget_class_register_action(parent_class, "suggest-prev", suggest_prev,
-				"\033" GNT_KEY_UP, NULL);
+				GNT_KEY_UP, NULL);
 	gnt_widget_class_register_action(parent_class, "history-prev", history_prev,
 				"\033" GNT_KEY_CTRL_DOWN, NULL);
 	gnt_widget_class_register_action(parent_class, "history-next", history_next,
--- a/console/libgnt/gntkeys.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntkeys.c	Wed Nov 01 03:38:23 2006 +0000
@@ -2,28 +2,17 @@
 
 #include <string.h>
 
+const char *term;
+
 void gnt_keys_refine(char *text)
 {
-	if (text[0] == 27)
-	{
-		/* These are for urxvt */
-		if (strcmp(text + 1, "Oa") == 0)
-		{
-			strcpy(text + 1, GNT_KEY_CTRL_UP);
-		}
-		else if (strcmp(text + 1, "Ob") == 0)
-		{
-			strcpy(text + 1, GNT_KEY_CTRL_DOWN);
-		}
-	}
-	else if ((unsigned char)text[0] == 195)
-	{
-		/* These for xterm */
-		if (text[2] == 0)
-		{
-			text[0] = 27;
-			text[1] -= 64;
-		}
+	if (*text == 27 && *(text + 1) == '[' && *(text + 3) == '\0' &&
+			(*(text + 2) >= 'A' || *(text + 2) <= 'D')) {
+		if (term == NULL)
+			term = getenv("TERM");
+		/* Apparently this is necessary for urxvt and screen */
+		if (strcmp(term, "screen") == 0 || strcmp(term, "rxvt-unicode") == 0)
+			*(text + 1) = 'O';
 	}
 }
 
--- a/console/libgnt/gntkeys.h	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntkeys.h	Wed Nov 01 03:38:23 2006 +0000
@@ -1,29 +1,34 @@
 #ifndef GNT_KEYS_H
 #define GNT_KEYS_H
 
-#define GNT_KEY_POPUP   "[29~"
+#include <curses.h>
+#include <term.h>
+
+#define SAFE(x)   ((x) ? (x) : "")
+
+#define GNT_KEY_POPUP   SAFE(key_f16)   /* Apparently */
 
 /* Arrow keys */
-#define GNT_KEY_LEFT   "[D"
-#define GNT_KEY_RIGHT  "[C"
-#define GNT_KEY_UP     "[A"
-#define GNT_KEY_DOWN   "[B"
+#define GNT_KEY_LEFT   SAFE(key_left)
+#define GNT_KEY_RIGHT  SAFE(key_right)
+#define GNT_KEY_UP     SAFE(key_up)
+#define GNT_KEY_DOWN   SAFE(key_down)
 
 #define GNT_KEY_CTRL_UP     "[1;5A"
 #define GNT_KEY_CTRL_DOWN   "[1;5B"
 #define GNT_KEY_CTRL_RIGHT  "[1;5C"
 #define GNT_KEY_CTRL_LEFT   "[1;5D"
 
-#define GNT_KEY_PGUP   "[5~"
-#define GNT_KEY_PGDOWN "[6~"
-#define GNT_KEY_HOME   "[7~"
-#define GNT_KEY_END    "[8~"
+#define GNT_KEY_PGUP   SAFE(key_ppage)
+#define GNT_KEY_PGDOWN SAFE(key_npage)
+#define GNT_KEY_HOME   SAFE(key_home)
+#define GNT_KEY_END    SAFE(key_end)
 
-#define GNT_KEY_ENTER  "\r"
+#define GNT_KEY_ENTER  carriage_return
 
-#define GNT_KEY_BACKSPACE "\177"
-#define GNT_KEY_DEL    "[3~"
-#define GNT_KEY_INS    "[2~"
+#define GNT_KEY_BACKSPACE SAFE(key_backspace)
+#define GNT_KEY_DEL    SAFE(key_dc)
+#define GNT_KEY_INS    SAFE(key_ic)
 
 #define GNT_KEY_CTRL_A     "\001"
 #define GNT_KEY_CTRL_B     "\002"
@@ -48,18 +53,18 @@
 #define GNT_KEY_CTRL_X     "\030"
 #define GNT_KEY_CTRL_Y     "\031"
 
-#define GNT_KEY_F1         "[[A"
-#define GNT_KEY_F2         "[[B"
-#define GNT_KEY_F3         "[[C"
-#define GNT_KEY_F4         "[[D"
-#define GNT_KEY_F5         "[[E"
-#define GNT_KEY_F6         "[17~"
-#define GNT_KEY_F7         "[18~"
-#define GNT_KEY_F8         "[19~"
-#define GNT_KEY_F9         "[20~"
-#define GNT_KEY_F10        "[21~"
-#define GNT_KEY_F11        "[23~"
-#define GNT_KEY_F12        "[24~"
+#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)
 
 /**
  * This will do stuff with the terminal settings and stuff.
--- a/console/libgnt/gntmain.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntmain.c	Wed Nov 01 03:38:23 2006 +0000
@@ -822,7 +822,7 @@
 			if (buffer[0] == 27)
 			{
 				/* Some special key has been pressed */
-				if (strcmp(buffer+1, GNT_KEY_POPUP) == 0)
+				if (strcmp(buffer, GNT_KEY_POPUP) == 0)
 				{}
 				else if (strcmp(buffer + 1, "c") == 0)
 				{
@@ -906,7 +906,7 @@
 			gnt_widget_get_position(widget, &x, &y);
 			gnt_widget_get_size(widget, &w, &h);
 
-			if (strcmp(buffer + 1, GNT_KEY_LEFT) == 0)
+			if (strcmp(buffer, GNT_KEY_LEFT) == 0)
 			{
 				if (x > X_MIN)
 				{
@@ -914,7 +914,7 @@
 					changed = TRUE;
 				}
 			}
-			else if (strcmp(buffer + 1, GNT_KEY_RIGHT) == 0)
+			else if (strcmp(buffer, GNT_KEY_RIGHT) == 0)
 			{
 				if (x + w < X_MAX)
 				{
@@ -922,7 +922,7 @@
 					changed = TRUE;
 				}
 			}
-			else if (strcmp(buffer + 1, GNT_KEY_UP) == 0)
+			else if (strcmp(buffer, GNT_KEY_UP) == 0)
 			{
 				if (y > Y_MIN)
 				{
@@ -930,7 +930,7 @@
 					changed = TRUE;
 				}						
 			}
-			else if (strcmp(buffer + 1, GNT_KEY_DOWN) == 0)
+			else if (strcmp(buffer, GNT_KEY_DOWN) == 0)
 			{
 				if (y + h < Y_MAX)
 				{
@@ -983,7 +983,7 @@
 
 			gnt_widget_get_size(widget, &width, &height);
 
-			if (strcmp(buffer + 1, GNT_KEY_DOWN) == 0)
+			if (strcmp(buffer, GNT_KEY_DOWN) == 0)
 			{
 				if (widget->priv.y + height < Y_MAX)
 				{
@@ -991,17 +991,17 @@
 					changed = TRUE;
 				}
 			}
-			else if (strcmp(buffer + 1, GNT_KEY_UP) == 0)
+			else if (strcmp(buffer, GNT_KEY_UP) == 0)
 			{
 				height--;
 				changed = TRUE;
 			}
-			else if (strcmp(buffer + 1, GNT_KEY_LEFT) == 0)
+			else if (strcmp(buffer, GNT_KEY_LEFT) == 0)
 			{
 				width--;
 				changed = TRUE;
 			}
-			else if (strcmp(buffer + 1, GNT_KEY_RIGHT) == 0)
+			else if (strcmp(buffer, GNT_KEY_RIGHT) == 0)
 			{
 				if (widget->priv.x + width < X_MAX)
 				{
--- a/console/libgnt/gntmenu.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntmenu.c	Wed Nov 01 03:38:23 2006 +0000
@@ -148,17 +148,15 @@
 	}
 
 	if (menu->type == GNT_MENU_TOPLEVEL) {
-		if (text[0] == 27) {
-			if (strcmp(text + 1, GNT_KEY_LEFT) == 0) {
-				menu->selected--;
-				if (menu->selected < 0)
-					menu->selected = g_list_length(menu->list) - 1;
-			} else if (strcmp(text + 1, GNT_KEY_RIGHT) == 0) {
-				menu->selected++;
-				if (menu->selected >= g_list_length(menu->list))
-					menu->selected = 0;
-			}
-		} else if (text[0] == '\r' && text[1] == 0) {
+		if (strcmp(text, GNT_KEY_LEFT) == 0) {
+			menu->selected--;
+			if (menu->selected < 0)
+				menu->selected = g_list_length(menu->list) - 1;
+		} else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
+			menu->selected++;
+			if (menu->selected >= g_list_length(menu->list))
+				menu->selected = 0;
+		} else if (strcmp(text, GNT_KEY_ENTER) == 0) {
 			gnt_widget_activate(widget);
 		}
 
--- a/console/libgnt/gntstyle.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntstyle.c	Wed Nov 01 03:38:23 2006 +0000
@@ -94,33 +94,33 @@
 			return g_strdup(code); \
 	} while (0)
 
-	SPECIAL_KEY("home",     "\033" GNT_KEY_HOME);
-	SPECIAL_KEY("end",      "\033" GNT_KEY_END);
-	SPECIAL_KEY("pageup",   "\033" GNT_KEY_PGUP);
-	SPECIAL_KEY("pagedown", "\033" GNT_KEY_PGDOWN);
-	SPECIAL_KEY("insert",   "\033" GNT_KEY_INS);
-	SPECIAL_KEY("delete",   "\033" GNT_KEY_DEL);
+	SPECIAL_KEY("home",     GNT_KEY_HOME);
+	SPECIAL_KEY("end",      GNT_KEY_END);
+	SPECIAL_KEY("pageup",   GNT_KEY_PGUP);
+	SPECIAL_KEY("pagedown", GNT_KEY_PGDOWN);
+	SPECIAL_KEY("insert",   GNT_KEY_INS);
+	SPECIAL_KEY("delete",   GNT_KEY_DEL);
 
-	SPECIAL_KEY("left",   "\033" GNT_KEY_LEFT);
-	SPECIAL_KEY("right",  "\033" GNT_KEY_RIGHT);
-	SPECIAL_KEY("up",     "\033" GNT_KEY_UP);
-	SPECIAL_KEY("down",   "\033" GNT_KEY_DOWN);
+	SPECIAL_KEY("left",   GNT_KEY_LEFT);
+	SPECIAL_KEY("right",  GNT_KEY_RIGHT);
+	SPECIAL_KEY("up",     GNT_KEY_UP);
+	SPECIAL_KEY("down",   GNT_KEY_DOWN);
 
 	SPECIAL_KEY("tab",    "\t");
-	SPECIAL_KEY("menu",   "\033" GNT_KEY_POPUP);
+	SPECIAL_KEY("menu",   GNT_KEY_POPUP);
 
-	SPECIAL_KEY("f1",   "\033" GNT_KEY_F1);
-	SPECIAL_KEY("f2",   "\033" GNT_KEY_F2);
-	SPECIAL_KEY("f3",   "\033" GNT_KEY_F3);
-	SPECIAL_KEY("f4",   "\033" GNT_KEY_F4);
-	SPECIAL_KEY("f5",   "\033" GNT_KEY_F5);
-	SPECIAL_KEY("f6",   "\033" GNT_KEY_F6);
-	SPECIAL_KEY("f7",   "\033" GNT_KEY_F7);
-	SPECIAL_KEY("f8",   "\033" GNT_KEY_F8);
-	SPECIAL_KEY("f9",   "\033" GNT_KEY_F9);
-	SPECIAL_KEY("f10",  "\033" GNT_KEY_F10);
-	SPECIAL_KEY("f11",  "\033" GNT_KEY_F11);
-	SPECIAL_KEY("f12",  "\033" GNT_KEY_F12);
+	SPECIAL_KEY("f1",   GNT_KEY_F1);
+	SPECIAL_KEY("f2",   GNT_KEY_F2);
+	SPECIAL_KEY("f3",   GNT_KEY_F3);
+	SPECIAL_KEY("f4",   GNT_KEY_F4);
+	SPECIAL_KEY("f5",   GNT_KEY_F5);
+	SPECIAL_KEY("f6",   GNT_KEY_F6);
+	SPECIAL_KEY("f7",   GNT_KEY_F7);
+	SPECIAL_KEY("f8",   GNT_KEY_F8);
+	SPECIAL_KEY("f9",   GNT_KEY_F9);
+	SPECIAL_KEY("f10",  GNT_KEY_F10);
+	SPECIAL_KEY("f11",  GNT_KEY_F11);
+	SPECIAL_KEY("f12",  GNT_KEY_F12);
 
 #undef SPECIAL_KEY
 
--- a/console/libgnt/gnttextview.h	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gnttextview.h	Wed Nov 01 03:38:23 2006 +0000
@@ -6,6 +6,10 @@
 #include "gntcolors.h"
 #include "gntkeys.h"
 
+#ifdef lines
+#undef lines
+#endif
+
 #define GNT_TYPE_TEXTVIEW				(gnt_text_view_get_gtype())
 #define GNT_TEXT_VIEW(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TEXTVIEW, GntTextView))
 #define GNT_TEXT_VIEW_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TEXTVIEW, GntTextViewClass))
--- a/console/libgnt/gnttree.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gnttree.c	Wed Nov 01 03:38:23 2006 +0000
@@ -709,15 +709,15 @@
 				g_str_equal, g_free, (GDestroyNotify)gnt_widget_action_param_free);
 
 	gnt_widget_class_register_action(parent_class, "move-up", action_up,
-				"\033" GNT_KEY_UP, NULL);
+				GNT_KEY_UP, NULL);
 	gnt_widget_register_binding(parent_class, "move-up", GNT_KEY_CTRL_P, NULL);
 	gnt_widget_class_register_action(parent_class, "move-down", action_down,
-				"\033" GNT_KEY_DOWN, NULL);
+				GNT_KEY_DOWN, NULL);
 	gnt_widget_register_binding(parent_class, "move-down", GNT_KEY_CTRL_N, NULL);
 	gnt_widget_class_register_action(parent_class, "page-up", action_page_up,
-				"\033" GNT_KEY_PGUP, NULL);
+				GNT_KEY_PGUP, NULL);
 	gnt_widget_class_register_action(parent_class, "page-down", action_page_down,
-				"\033" GNT_KEY_PGDOWN, NULL);
+				GNT_KEY_PGDOWN, NULL);
 
 	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), parent_class);
 
--- a/console/libgnt/gnttree.h	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gnttree.h	Wed Nov 01 03:38:23 2006 +0000
@@ -7,6 +7,10 @@
 #include "gntkeys.h"
 #include "gnttextview.h"
 
+#ifdef columns
+#undef columns
+#endif
+
 #define GNT_TYPE_TREE				(gnt_tree_get_gtype())
 #define GNT_TREE(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TREE, GntTree))
 #define GNT_TREE_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TREE, GntTreeClass))
--- a/console/libgnt/gntwidget.c	Wed Nov 01 02:13:37 2006 +0000
+++ b/console/libgnt/gntwidget.c	Wed Nov 01 03:38:23 2006 +0000
@@ -259,7 +259,7 @@
 
 	/* This is relevant for all widgets */
 	gnt_widget_class_register_action(klass, "context-menu", context_menu,
-				"\033" GNT_KEY_POPUP, NULL);
+				GNT_KEY_POPUP, NULL);
 
 	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), klass);