changeset 14477:ca36763497d9

[gaim-migrate @ 17195] Build libgnt with ncurses if ncursesw is not found. I uninstalled ncursesw and it's still working for me .. of course, with no wide-character support. Improve the mouse support a bit. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 09 Sep 2006 02:19:16 +0000
parents 218a36c1c9e2
children 3d8c09a6df48
files configure.ac console/gntblist.c console/libgnt/configure.ac console/libgnt/gntentry.c console/libgnt/gntmain.c console/libgnt/gntutils.c console/libgnt/gntwidget.h console/libgnt/gntwm.h console/plugins/Makefile.am
diffstat 9 files changed, 158 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Fri Sep 08 22:47:36 2006 +0000
+++ b/configure.ac	Sat Sep 09 02:19:16 2006 +0000
@@ -353,48 +353,51 @@
 	AC_CHECK_LIB(ncursesw, initscr, [GNT_LIBS="-lncursesw"], [enable_consoleui=no])
 	AC_CHECK_LIB(panelw, update_panels, [GNT_LIBS="$GNT_LIBS -lpanelw"], [enable_consoleui=no])
 
-	LIBS_save="$LIBS"
-	LIBS="$LIBS $GNT_LIBS"
+	if test "x$enable_consoleui" = "xyes"; then
+		dnl # Some distros put the headers in ncursesw/, some don't
+		found_ncurses_h=no
+		for f in /usr/include/ncursesw/ncurses.h /usr/include/ncurses.h
+		do
+			AC_CHECK_HEADER($f,[
+				AC_MSG_CHECKING([if $f supports wide characters])
+				AC_TRY_COMPILE([
+					#define _XOPEN_SOURCE_EXTENDED
+					#include <$f>
+				], [
+					#ifndef get_wch
+					# error get_wch not found!
+					#endif
+				], [
+					dir=`dirname $f`
+					if test x"$dir" != x"." ; then
+						GNT_CFLAGS="-I$dir/"
+					else
+						GNT_CFLAGS=""
+					fi
 
-	dnl # Some distros put the headers in ncursesw/, some don't
-	found_ncurses_h=no
-	for f in /usr/include/ncursesw/ncurses.h /usr/include/ncurses.h
-	do
-		AC_CHECK_HEADER($f,[
-			AC_MSG_CHECKING([if $f supports wide characters])
-			AC_TRY_COMPILE([
-				#define _XOPEN_SOURCE_EXTENDED
-				#include <$f>
-			], [
-				#ifndef get_wch
-				# error get_wch not found!
-				#endif
-			], [
-				dir=`dirname $f`
-				if test x"$dir" != x"." ; then
-					GNT_CFLAGS="-I$dir/"
-				else
-					GNT_CFLAGS=""
-				fi
+					found_ncurses_h=yes
+					AC_MSG_RESULT([yes])
+					break
+				], [
+					AC_MSG_RESULT([no])
+				])
+			])
+		done
 
-				found_ncurses_h=yes
-				AC_MSG_RESULT([yes])
-				break
-			], [
-				AC_MSG_RESULT([no])
-			])
-		])
-	done
-
-	LIBS="$LIBS_save"
-
-	if test x"$found_ncurses_h" = x"no" ; then
-		GNT_LIBS=""
-		GNT_CFLAGS=""
-		enable_consoleui=no
-		AC_MSG_RESULT([no])
+		if test x"$found_ncurses_h" = x"no" ; then
+			GNT_LIBS=""
+			GNT_CFLAGS=""
+			enable_consoleui=no
+			AC_MSG_RESULT([no])
+		else
+			AC_MSG_RESULT([yes])
+		fi
 	else
-		AC_MSG_RESULT([yes])
+		# ncursesw was not found. Look for plain old ncurses
+		enable_consoleui=yes
+		AC_CHECK_LIB(ncurses, initscr, [GNT_LIBS="-lncurses"], [enable_consoleui=no])
+		AC_CHECK_LIB(panel, update_panels, [GNT_LIBS="$GNT_LIBS -lpanel"], [enable_consoleui=no])
+		AC_DEFINE(NO_WIDECHAR, 1, [Define to 1 if you don't have wide-character support.])
 	fi
 
 	PKG_CHECK_MODULES(X11, x11,
@@ -407,7 +410,7 @@
 AC_SUBST(GNT_CFLAGS)
 AM_CONDITIONAL(ENABLE_GNT, test "x$enable_consoleui" = "xyes")
 
-AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])])
+#AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])])
 
 dnl #######################################################################
 dnl # Check for LibXML2 (required)
--- a/console/gntblist.c	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/gntblist.c	Sat Sep 09 02:19:16 2006 +0000
@@ -1160,6 +1160,8 @@
 static void
 selection_changed(GntWidget *widget, gpointer old, gpointer current, GGBlist *ggblist)
 {
+	if (ggblist->context)
+		remove_context_menu(ggblist);
 	draw_tooltip(ggblist);
 }
 
@@ -1568,6 +1570,15 @@
 	return ret;
 }
 
+static gboolean
+blist_clicked(GntTree *tree, GntMouseEvent event, int x, int y, gpointer ggblist)
+{
+	if (event == GNT_RIGHT_MOUSE_DOWN) {
+		draw_context_menu(ggblist);
+	}
+	return FALSE;
+}
+
 void gg_blist_show()
 {
 	if (ggblist)
@@ -1626,6 +1637,7 @@
 
 	g_signal_connect(G_OBJECT(ggblist->tree), "selection_changed", G_CALLBACK(selection_changed), ggblist);
 	g_signal_connect(G_OBJECT(ggblist->tree), "key_pressed", G_CALLBACK(key_pressed), ggblist);
+	g_signal_connect_after(G_OBJECT(ggblist->tree), "clicked", G_CALLBACK(blist_clicked), ggblist);
 	g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist);
 	g_signal_connect_data(G_OBJECT(ggblist->tree), "gained-focus", G_CALLBACK(draw_tooltip),
 				ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
--- a/console/libgnt/configure.ac	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/libgnt/configure.ac	Sat Sep 09 02:19:16 2006 +0000
@@ -182,7 +182,7 @@
 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.0.0 gobject-2.0 gmodule-2.0],,
 	[
 		AC_MSG_ERROR([
-*** GLib 2.0 is required to build Gaim; please make sure you have the GLib
+*** GLib 2.0 is required to build LibGNT; please make sure you have the GLib
 *** development headers installed. The latest version of GLib is
 *** always available at http://www.gtk.org/.])
 	])
@@ -201,8 +201,54 @@
 #AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])])
 #AC_VAR_TIMEZONE_EXTERNALS
 
-AC_CHECK_LIB(ncursesw, initscr, , [AC_MSG_ERROR([
-*** You need ncursesw. ])])
+GNT_CFLAGS=
+GNT_LIBS=
+AC_CHECK_LIB(ncursesw, initscr, [GNT_LIBS="-lncursesw"], [enable_gnt=no])
+AC_CHECK_LIB(panelw, update_panels, [GNT_LIBS="$GNT_LIBS -lpanelw"], [enable_gnt=no])
+
+# If ncursesw is not found, look for plain old ncurses
+if test "x$enable_gnt" = "xno"; then
+	AC_CHECK_LIB(ncurses, initscr, [[GNT_LIBS="-lncurses"] [enable_gnt=yes]], [enable_gnt=no])
+	AC_CHECK_LIB(panel, update_panels, [[GNT_LIBS="$GNT_LIBS -lpanel"] [enable_gnt=yes]], [enable_gnt=no])
+	AC_DEFINE(NO_WIDECHAR, [1], [Define to 1 if you do not have ncursesw.])
+else
+	dnl # Some distros put the headers in ncursesw/, some don't
+	found_ncurses_h=no
+	for f in /usr/include/ncursesw/ncurses.h /usr/include/ncurses.h
+	do
+		AC_CHECK_HEADER($f,[
+			AC_MSG_CHECKING([if $f supports wide characters])
+			AC_TRY_COMPILE([
+				#define _XOPEN_SOURCE_EXTENDED
+				#include <$f>
+			], [
+				#ifndef get_wch
+				# error get_wch not found!
+				#endif
+			], [
+				dir=`dirname $f`
+				if test x"$dir" != x"." ; then
+					GNT_CFLAGS="-I$dir/"
+				else
+					GNT_CFLAGS=""
+				fi
+
+				found_ncurses_h=yes
+				AC_MSG_RESULT([yes])
+				break
+			], [
+				AC_MSG_RESULT([no])
+			])
+		])
+	done
+fi
+AC_SUBST(GNT_CFLAGS)
+AC_SUBST(GNT_LIBS)
+
+if test "x$enable_gnt" = "xno"; then
+	AC_MSG_ERROR([
+*** You need ncursesw or ncurses.])
+fi
 
 AC_OUTPUT([Makefile
            gnt.pc
--- a/console/libgnt/gntentry.c	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/libgnt/gntentry.c	Sat Sep 09 02:19:16 2006 +0000
@@ -64,6 +64,7 @@
 		entry->ddown = gnt_tree_new();
 		gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate);
 		gnt_box_add_widget(GNT_BOX(box), entry->ddown);
+		/* XXX: Connect to the "activate" signal for the dropdown tree */
 
 		GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT);
 
--- a/console/libgnt/gntmain.c	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/libgnt/gntmain.c	Sat Sep 09 02:19:16 2006 +0000
@@ -1,5 +1,4 @@
-#define _XOPEN_SOURCE
-#define _XOPEN_SOURCE_EXTENDED
+#define _GNU_SOURCE
 
 #include "config.h"
 
@@ -11,6 +10,7 @@
 #include "gntkeys.h"
 #include "gntstyle.h"
 #include "gnttree.h"
+#include "gntutils.h"
 #include "gntwm.h"
 
 #include <panel.h>
@@ -27,8 +27,6 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#include <wchar.h>
-
 /**
  * Notes: Interesting functions to look at:
  * 	scr_dump, scr_init, scr_restore: for workspaces
@@ -253,6 +251,8 @@
 		mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width);
 		title = GNT_BOX(w)->title;
 		mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>");
+		if (i)
+			mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL));
 
 		update_window_in_list(w);
 	}
@@ -423,7 +423,7 @@
 		for (x = 0; x < getmaxx(stdscr); x++)
 		{
 			char ch;
-			now = mvwinch(newscr, y, x);
+			now = mvwinch(curscr, y, x);
 			ch = now & A_CHARTEXT;
 			now ^= ch;
 
@@ -561,7 +561,7 @@
 	static int offset = 0;
 	GntMouseEvent event;
 	GntWidget *widget = NULL;
-	GList *iter;
+	PANEL *p = NULL;
 
 	if (!ordered || buffer[0] != 27)
 		return FALSE;
@@ -577,8 +577,14 @@
 	x -= 33;
 	y -= 33;
 
-	for (iter = ordered; iter; iter = iter->next) {
-		GntWidget *wid = iter->data;
+	/* It might be a better idea to use panel_below. That would allow mouse-clicks
+	 * to be operated on transient windows, which would be cool.*/
+	while ((p = panel_below(p)) != NULL) {
+		const GntNode *node = panel_userptr(p);
+		GntWidget *wid;
+		if (!node)
+			continue;
+		wid = node->me;
 		if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) {
 			if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) {
 				widget = wid;
@@ -586,6 +592,7 @@
 			}
 		}
 	}
+
 	if (strncmp(buffer, "[M ", 3) == 0) {
 		/* left button down */
 		/* Bring the window you clicked on to front */
@@ -612,7 +619,8 @@
 	if (wm.mouse_clicked && wm.mouse_clicked(event, x, y, widget))
 		return TRUE;
 	
-	if (event == GNT_LEFT_MOUSE_DOWN && widget) {
+	if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != _list.window &&
+			!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) {
 		if (widget != ordered->data) {
 			GntWidget *w = ordered->data;
 			ordered = g_list_bring_to_front(ordered, widget);
@@ -644,30 +652,49 @@
 		offset = 0;
 	}
 
-	gnt_widget_clicked(ordered->data, event, x, y);
-	return FALSE; /* XXX: this should be TRUE */
+	gnt_widget_clicked(widget, event, x, y);
+	return TRUE; /* XXX: this should be TRUE */
 }
 
+#ifndef NO_WIDECHAR
+static int
+widestringwidth(wchar_t *wide)
+{
+	int len, ret;
+	char *string;
+
+	len = wcstombs(NULL, wide, 0) + 1;
+	string = g_new0(char, len);
+	wcstombs(string, wide, len);
+	ret = gnt_util_onscreen_width(string, NULL);
+	g_free(string);
+	return ret;
+}
+#endif
+
 /* Returns the onscreen width of the character at the position */
 static int
 reverse_char(WINDOW *d, int y, int x, gboolean set)
 {
-	/* This is supposed to simply in_wch the cchar_t, set the attribute,
-	 * and add_wch. But that doesn't currently work, possibly because of
-	 * a bug in ncurses. This is an ugly hack to work around that. */
-	cchar_t ch;
-	int wc = 1, j;
-
 #define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE))
 
+#ifdef NO_WIDECHAR
+	chtype ch;
+	ch = mvwinch(d, y, x);
+	mvwaddch(d, y, x, DECIDE(ch));
+	return 1;
+#else
+	cchar_t ch;
+	int wc = 1;
 	if (mvwin_wch(d, y, x, &ch) == OK) {
-		wc = wcswidth(ch.chars, CCHARW_MAX);
-		for (j = 0; j < wc; j++)
-			mvwdelch(d, y, x);
+		wc = widestringwidth(ch.chars);
 		ch.attr = DECIDE(ch.attr);
-		mvwins_wch(d, y, x, &ch);
+		ch.attr &= WA_ATTRIBUTES;   /* XXX: This is a workaround for a bug */
+		mvwadd_wch(d, y, x, &ch);
 	}
+
 	return wc;
+#endif
 }
 
 static void
@@ -1178,6 +1205,7 @@
 			node->panel = wm.new_window(node->me);
 		else
 			node->panel = new_panel(node->me->window);
+		set_panel_userptr(node->panel, node);
 		if (!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT))
 		{
 			bottom_panel(node->panel);     /* New windows should not grab focus */
--- a/console/libgnt/gntutils.c	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/libgnt/gntutils.c	Sat Sep 09 02:19:16 2006 +0000
@@ -43,6 +43,9 @@
 {
 	int width = 0;
 
+	if (end == NULL)
+		end = start + strlen(start);
+
 	while (start < end) {
 		width += g_unichar_iswide(g_utf8_get_char(start)) ? 2 : 1;
 		start = g_utf8_next_char(start);
--- a/console/libgnt/gntwidget.h	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/libgnt/gntwidget.h	Sat Sep 09 02:19:16 2006 +0000
@@ -1,8 +1,6 @@
 #ifndef GNT_WIDGET_H
 #define GNT_WIDGET_H
 
-#include "config.h"
-
 #include <stdio.h>
 #include <glib.h>
 #include <glib-object.h>
--- a/console/libgnt/gntwm.h	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/libgnt/gntwm.h	Sat Sep 09 02:19:16 2006 +0000
@@ -1,5 +1,3 @@
-#include "config.h"
-
 #include <panel.h>
 
 #include "gntwidget.h"
--- a/console/plugins/Makefile.am	Fri Sep 08 22:47:36 2006 +0000
+++ b/console/plugins/Makefile.am	Sat Sep 09 02:19:16 2006 +0000
@@ -9,7 +9,7 @@
 
 plugindir = $(libdir)/gaim
 
-gntgf_la_SOURCES             = gntgf.c
+gntgf_la_SOURCES        = gntgf.c
 gnthistory_la_SOURCES        = gnthistory.c
 
 endif # PLUGINS