Mercurial > pidgin
changeset 21454:d78e440584e0
Add maximize flags for windows.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 12 Nov 2007 17:13:44 +0000 |
parents | 93e69f29bc5f |
children | 389a51db740f 675fbb9a402e |
files | finch/libgnt/gntmenu.c finch/libgnt/gntwindow.c finch/libgnt/gntwindow.h finch/libgnt/gntwm.c |
diffstat | 4 files changed, 80 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/finch/libgnt/gntmenu.c Mon Nov 12 16:53:54 2007 +0000 +++ b/finch/libgnt/gntmenu.c Mon Nov 12 17:13:44 2007 +0000 @@ -235,7 +235,7 @@ 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);
--- a/finch/libgnt/gntwindow.c Mon Nov 12 16:53:54 2007 +0000 +++ b/finch/libgnt/gntwindow.c Mon Nov 12 17:13:44 2007 +0000 @@ -28,6 +28,7 @@ struct _GntWindowPriv { GHashTable *accels; /* key => menuitem-id */ + GntWindowFlags flags; }; enum @@ -189,16 +190,33 @@ 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)); +} +
--- a/finch/libgnt/gntwindow.h Mon Nov 12 16:53:54 2007 +0000 +++ b/finch/libgnt/gntwindow.h Mon Nov 12 17:13:44 2007 +0000 @@ -48,6 +48,12 @@ 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(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 *);
--- a/finch/libgnt/gntwm.c Mon Nov 12 16:53:54 2007 +0000 +++ b/finch/libgnt/gntwm.c Mon Nov 12 17:13:44 2007 +0000 @@ -224,17 +224,22 @@ } 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 @@ } } 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 -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 @@ 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 @@ 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 @@ 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); }