im.pidgin.pidgin: 42565dfdfb1d0477d08281c1c37e99bba59c56fc

sadrul at pidgin.im sadrul at pidgin.im
Mon Nov 12 12:05:45 EST 2007


-----------------------------------------------------------------
Revision: 42565dfdfb1d0477d08281c1c37e99bba59c56fc
Ancestor: c0948a94827c1941d90ddb1db8c383dae4f86c05
Author: sadrul at pidgin.im
Date: 2007-11-12T17:13:44
Branch: im.pidgin.pidgin

Modified files:
        finch/libgnt/gntmenu.c finch/libgnt/gntwindow.c
        finch/libgnt/gntwindow.h finch/libgnt/gntwm.c

ChangeLog: 

Add maximize flags for windows.

-------------- next part --------------
============================================================
--- finch/libgnt/gntmenu.c	2c3d027112edcc789a73af4c2114d0526d95aa6b
+++ finch/libgnt/gntmenu.c	574a87ed870bfea17955731baac88a2110b4bbc6
@@ -235,7 +235,7 @@ check_for_trigger(GntMenu *menu, char tr
 
 	if (nth == NULL)
 		return FALSE;
-		
+
 	find = find_item_with_trigger(nth->next, NULL, trigger);
 	if (!find)
 		find = find_item_with_trigger(menu->list, nth->next, trigger);
============================================================
--- finch/libgnt/gntwindow.c	3b3b59e7d9babab0f93b468b5a349995b701e88a
+++ finch/libgnt/gntwindow.c	43237d98f8e7ab9a1ef12ec2b85e87da4205dadc
@@ -28,6 +28,7 @@ struct _GntWindowPriv
 struct _GntWindowPriv
 {
 	GHashTable *accels;   /* key => menuitem-id */
+	GntWindowFlags flags;
 };
 
 enum
@@ -189,16 +190,33 @@ void gnt_window_set_menu(GntWindow *wind
 	if (name && window->priv) {
 		if (!gnt_style_read_menu_accels(name, window->priv->accels)) {
 			g_hash_table_destroy(window->priv->accels);
-			g_free(window->priv);
-			window->priv = NULL;
+			window->priv->accels = NULL;
 		}
 	}
 }
 
 const char * gnt_window_get_accel_item(GntWindow *window, const char *key)
 {
-	if (window->priv)
+	if (window->priv->accels)
 		return g_hash_table_lookup(window->priv->accels, key);
 	return NULL;
 }
 
+void gnt_window_set_maximize(GntWindow *window, GntWindowFlags maximize)
+{
+	if (maximize & GNT_WINDOW_MAXIMIZE_X)
+		window->priv->flags |= GNT_WINDOW_MAXIMIZE_X;
+	else
+		window->priv->flags &= ~GNT_WINDOW_MAXIMIZE_X;
+
+	if (maximize & GNT_WINDOW_MAXIMIZE_Y)
+		window->priv->flags |= GNT_WINDOW_MAXIMIZE_Y;
+	else
+		window->priv->flags &= ~GNT_WINDOW_MAXIMIZE_Y;
+}
+
+GntWindowFlags gnt_window_get_maximize(GntWindow *window)
+{
+	return (window->priv->flags & (GNT_WINDOW_MAXIMIZE_X | GNT_WINDOW_MAXIMIZE_Y));
+}
+
============================================================
--- finch/libgnt/gntwindow.h	f3445f58f66037fb1539b11e43f13aea91856bf5
+++ finch/libgnt/gntwindow.h	5c240cd6834abf6c3ad56f0485820b8f75ffecf5
@@ -48,6 +48,12 @@ typedef struct _GntWindowClass		GntWindo
 typedef struct _GntWindowPriv		GntWindowPriv;
 typedef struct _GntWindowClass		GntWindowClass;
 
+typedef enum
+{
+	GNT_WINDOW_MAXIMIZE_X = 1 << 0,
+	GNT_WINDOW_MAXIMIZE_Y = 1 << 1,
+} GntWindowFlags;
+
 struct _GntWindow
 {
 	GntBox parent;
@@ -112,6 +118,27 @@ const char * gnt_window_get_accel_item(G
  */
 const char * gnt_window_get_accel_item(GntWindow *window, const char *key);
 
+/**
+ * Maximize a window, either horizontally or vertically, or both.
+ *
+ * @param window    The window to maximize.
+ * @param maximize  The maximization state of the window.
+ *
+ * @since 2.3.0
+ */
+void gnt_window_set_maximize(GntWindow *window, GntWindowFlags maximize);
+
+/**
+ * Get the maximization state of a window.
+ *
+ * @param window  The window.
+ *
+ * @return  The maximization state of the window.
+ *
+ * @since 2.3.0
+ */
+GntWindowFlags gnt_window_get_maximize(GntWindow *window);
+
 void gnt_window_workspace_hiding(GntWindow *);
 void gnt_window_workspace_showing(GntWindow *);
 
============================================================
--- finch/libgnt/gntwm.c	44e53f08c882bafe7de0c026b6fbd99269989276
+++ finch/libgnt/gntwm.c	687b43c1b34215e82c4796da4b0fb806c2e0793d
@@ -224,17 +224,22 @@ static gboolean
 }
 
 static gboolean
-sanitize_position(GntWidget *widget, int *x, int *y)
+sanitize_position(GntWidget *widget, int *x, int *y, gboolean m)
 {
 	int X_MAX = getmaxx(stdscr);
 	int Y_MAX = getmaxy(stdscr) - 1;
 	int w, h;
 	int nx, ny;
 	gboolean changed = FALSE;
+	GntWindowFlags flags = GNT_IS_WINDOW(widget) ?
+			gnt_window_get_maximize(GNT_WINDOW(widget)) : 0;
 
 	gnt_widget_get_size(widget, &w, &h);
 	if (x) {
-		if (*x + w > X_MAX) {
+		if (m && (flags & GNT_WINDOW_MAXIMIZE_X) && *x != 0) {
+			*x = 0;
+			changed = TRUE;
+		} else if (*x + w > X_MAX) {
 			nx = MAX(0, X_MAX - w);
 			if (nx != *x) {
 				*x = nx;
@@ -243,7 +248,10 @@ sanitize_position(GntWidget *widget, int
 		}
 	}
 	if (y) {
-		if (*y + h > Y_MAX) {
+		if (m && (flags & GNT_WINDOW_MAXIMIZE_Y) && *y != 0) {
+			*y = 0;
+			changed = TRUE;
+		} else if (*y + h > Y_MAX) {
 			ny = MAX(0, Y_MAX - h);
 			if (ny != *y) {
 				*y = ny;
@@ -255,7 +263,7 @@ static void
 }
 
 static void
-refresh_node(GntWidget *widget, GntNode *node, gpointer null)
+refresh_node(GntWidget *widget, GntNode *node, gpointer m)
 {
 	int x, y, w, h;
 	int nw, nh;
@@ -263,14 +271,28 @@ refresh_node(GntWidget *widget, GntNode 
 	int X_MAX = getmaxx(stdscr);
 	int Y_MAX = getmaxy(stdscr) - 1;
 
+	GntWindowFlags flags = 0;
+
+	if (m && GNT_IS_WINDOW(widget)) {
+		flags = gnt_window_get_maximize(GNT_WINDOW(widget));
+	}
+
 	gnt_widget_get_position(widget, &x, &y);
 	gnt_widget_get_size(widget, &w, &h);
 
-	if (sanitize_position(widget, &x, &y))
+	if (sanitize_position(widget, &x, &y, !!m))
 		gnt_screen_move_widget(widget, x, y);
 
-	nw = MIN(w, X_MAX);
-	nh = MIN(h, Y_MAX);
+	if (flags & GNT_WINDOW_MAXIMIZE_X)
+		nw = X_MAX;
+	else
+		nw = MIN(w, X_MAX);
+
+	if (flags & GNT_WINDOW_MAXIMIZE_Y)
+		nh = Y_MAX;
+	else
+		nh = MIN(h, Y_MAX);
+
 	if (nw != w || nh != h)
 		gnt_screen_resize_widget(widget, nw, nh);
 }
@@ -1607,7 +1629,7 @@ gnt_wm_new_window_real(GntWM *wm, GntWid
 
 	g_hash_table_replace(wm->nodes, widget, node);
 
-	refresh_node(widget, node, NULL);
+	refresh_node(widget, node, GINT_TO_POINTER(TRUE));
 
 	transient = !!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT);
 
@@ -1682,7 +1704,7 @@ void gnt_wm_new_window(GntWM *wm, GntWid
 		const char *title = GNT_BOX(widget)->title;
 		GntPosition *p = NULL;
 		if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) {
-			sanitize_position(widget, &p->x, &p->y);
+			sanitize_position(widget, &p->x, &p->y, TRUE);
 			gnt_widget_set_position(widget, p->x, p->y);
 			mvwin(widget->window, p->y, p->x);
 		}


More information about the Commits mailing list