diff console/libgnt/test/wm.c @ 13960:a06f7495af6f

[gaim-migrate @ 16513] It is possible to have multiple gnt-applications sharing the same screen. To try this, 'make WM' in console/libgnt/test. It will have a small 'Command' entry. You can give a command like './focus.so' (or one of the other examples). The applications can also be executed standalone. This required some tinkering to the Makefile. I am not sure whether there is an easier way of doing it. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 17 Jul 2006 22:27:26 +0000
parents
children 0a0d2a1fd2bc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/libgnt/test/wm.c	Mon Jul 17 22:27:26 2006 +0000
@@ -0,0 +1,65 @@
+#include <gmodule.h>
+
+#include <gnt.h>
+#include <gntbox.h>
+#include <gntentry.h>
+#include <gntlabel.h>
+
+static gboolean
+key_pressed(GntEntry *entry, const char *text, gpointer null)
+{
+	if (*text != '\r')
+		return FALSE;
+
+	{
+		const char *cmd;
+		void *handle;
+		void (*func)();
+
+		cmd = gnt_entry_get_text(entry);
+		handle = g_module_open(cmd, G_MODULE_BIND_LOCAL);
+		if (handle && g_module_symbol(handle, "main", (gpointer)&func))
+		{
+			gnt_entry_clear(entry);
+			func();
+		}
+		else
+		{
+			GntWidget *widget = gnt_vbox_new(FALSE);
+			gnt_box_set_toplevel(GNT_BOX(widget), TRUE);
+			gnt_box_set_title(GNT_BOX(widget), "Error");
+			gnt_box_add_widget(GNT_BOX(widget), gnt_label_new("Could not execute."));
+
+			gnt_widget_show(widget);
+		}
+	}
+	
+	return TRUE;
+}
+
+int main()
+{
+	GntWidget *window, *entry;
+
+	freopen(".error", "w", stderr);
+
+	gnt_init();
+
+	window = gnt_hbox_new(FALSE);
+
+	gnt_box_add_widget(GNT_BOX(window), gnt_label_new("Command"));
+
+	entry = gnt_entry_new(NULL);
+	g_signal_connect(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), NULL);
+	gnt_box_add_widget(GNT_BOX(window), entry);
+
+	gnt_widget_set_position(window, 0, getmaxy(stdscr) - 2);
+	gnt_widget_show(window);
+
+	gnt_main();
+
+	gnt_quit();
+	
+	return 0;
+}
+