changeset 14390:d4a26ada1971

[gaim-migrate @ 17096] Give a bit more control to the window-manager about the size/position of a window. Also, give the WM an opportunity to do its thing when the window changes something (eg. title, 'urgency'). committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 31 Aug 2006 06:39:20 +0000
parents 746d535e9053
children 6e89bfd2b33f
files console/libgnt/gntbox.c console/libgnt/gntmain.c console/libgnt/gntwm.h console/libgnt/wms/s.c
diffstat 4 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntbox.c	Thu Aug 31 05:58:32 2006 +0000
+++ b/console/libgnt/gntbox.c	Thu Aug 31 06:39:20 2006 +0000
@@ -67,6 +67,7 @@
 		int pos, right;
 		char *title = g_strdup(box->title);
 		
+		mvwhline(widget->window, 0, 1, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), widget->priv.width - 2);
 		get_title_thingies(box, title, &pos, &right);
 
 		if (gnt_widget_has_focus(widget))
--- a/console/libgnt/gntmain.c	Thu Aug 31 05:58:32 2006 +0000
+++ b/console/libgnt/gntmain.c	Thu Aug 31 06:39:20 2006 +0000
@@ -81,7 +81,11 @@
 {
 	NULL,   /* new_window */
 	NULL,   /* close_window */
+	NULL,   /* window_resize_confirm */
 	NULL,   /* window_resized */
+	NULL,   /* window_move_confirm */
+	NULL,   /* window_moved */
+	NULL,   /* window_update */
 	NULL,   /* key_pressed */
 	NULL,   /* mouse clicked */
 	bring_on_top, /* give_focus */
@@ -229,6 +233,10 @@
 			/* This is the current window in focus */
 			color = GNT_COLOR_TITLE;
 			GNT_WIDGET_UNSET_FLAGS(w, GNT_WIDGET_URGENT);
+			if (wm.window_update) {
+				GntNode *node = g_hash_table_lookup(nodes, w);
+				wm.window_update(node->panel, w);
+			}
 		} else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) {
 			/* This is a window with the URGENT hint set */
 			color = GNT_COLOR_URGENT;
@@ -1145,6 +1153,12 @@
 		return;
 
 	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT);
+
+	if (wm.window_update) {
+		GntNode *node = g_hash_table_lookup(nodes, widget);
+		wm.window_update(node->panel, widget);
+	}
+
 	draw_taskbar(FALSE);
 }
 
@@ -1168,6 +1182,9 @@
 		if (!node)
 			return;
 
+		if (wm.window_resize_confirm && !wm.window_resize_confirm(widget, &width, &height))
+			return;
+
 		hide_panel(node->panel);
 		gnt_widget_set_size(widget, width, height);
 		gnt_widget_draw(widget);
@@ -1183,8 +1200,16 @@
 void gnt_screen_move_widget(GntWidget *widget, int x, int y)
 {
 	GntNode *node = g_hash_table_lookup(nodes, widget);
+
+	if (wm.window_move_confirm && !wm.window_move_confirm(widget, &x, &y))
+		return;
+
 	gnt_widget_set_position(widget, x, y);
 	move_panel(node->panel, y, x);
+
+	if (wm.window_moved)
+		wm.window_moved(node->panel, widget);
+
 	update_screen(NULL);
 }
 
@@ -1192,6 +1217,12 @@
 {
 	gnt_box_set_title(GNT_BOX(widget), text);
 	gnt_widget_draw(widget);
+
+	if (wm.window_update) {
+		GntNode *node = g_hash_table_lookup(nodes, widget);
+		wm.window_update(node->panel, widget);
+	}
+
 	draw_taskbar(FALSE);
 }
 
--- a/console/libgnt/gntwm.h	Thu Aug 31 05:58:32 2006 +0000
+++ b/console/libgnt/gntwm.h	Thu Aug 31 06:39:20 2006 +0000
@@ -6,6 +6,8 @@
 
 #include "gntwidget.h"
 
+/* XXX: It might be a good idea to move GntNode from gntmain.c to here. */
+
 typedef struct _GntWM GntWM;
 
 struct _GntWM
@@ -16,10 +18,24 @@
 	/* This is called when a window is being closed */
 	gboolean (*close_window)(GntWidget *win);
 
+	/* The WM may want to confirm a size for a window first */
+	gboolean (*window_resize_confirm)(GntWidget *win, int *w, int *h);
+
 	/* Can del_panel the old panel and return a new_panel.
 	 * Otherwise, this should at least do a replace_panel. */
 	PANEL *(*window_resized)(PANEL *pan, GntWidget *win);
 
+	/* The WM may want to confirm the position of a window */
+	gboolean (*window_move_confirm)(GntWidget *win, int *x, int *y);
+
+	void (*window_moved)(PANEL *pan, GntWidget *win);
+
+	/* This gets called when:
+	 * 	 - the title of the window changes
+	 * 	 - the 'urgency' of the window changes
+	 */
+	void (*window_update)(PANEL *pan, GntWidget *win);
+
 	/* This should usually return NULL if the keys were processed by the WM.
 	 * If not, the WM can simply return the original string, which will be
 	 * processed by the default WM. The custom WM can also return a different
--- a/console/libgnt/wms/s.c	Thu Aug 31 05:58:32 2006 +0000
+++ b/console/libgnt/wms/s.c	Thu Aug 31 06:39:20 2006 +0000
@@ -156,6 +156,14 @@
 	return FALSE;
 }
 
+static void
+s_window_update(PANEL *panel, GntWidget *window)
+{
+	const char *name = gnt_widget_get_name(window);
+	if (name && strcmp(name, "buddylist"))
+		envelope_normal_window(window);
+}
+
 void gntwm_init(GntWM *wm)
 {
 	gwm = wm;
@@ -163,5 +171,6 @@
 	wm->window_resized = s_resize_window;
 	wm->key_pressed = s_key_pressed;
 	wm->mouse_clicked = s_mouse_clicked;
+	wm->window_update = s_window_update;
 }