libgnt/libgnt

Add private accessors for GntBox internals.

2019-04-24, Elliott Sales de Andrade
0d4155839180
Parents 7c0f7e4902af
Children 7e042541f32d
Add private accessors for GntBox internals.
  • +16 -0
    gntbox.c
  • +37 -0
    gntboxprivate.h
  • +3 -1
    gntmain.c
  • +3 -4
    gntwindow.c
  • +28 -13
    gntwm.c
  • +4 -2
    gntws.c
  • +5 -2
    wms/irssi.c
  • +2 -1
    wms/s.c
  • --- a/gntbox.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/gntbox.c Wed Apr 24 01:46:26 2019 -0400
    @@ -675,6 +675,14 @@
    g_free(prev);
    }
    +/* Internal. */
    +const gchar *
    +gnt_box_get_title(GntBox *box)
    +{
    + g_return_val_if_fail(GNT_IS_BOX(box), NULL);
    + return box->title;
    +}
    +
    void gnt_box_set_pad(GntBox *box, int pad)
    {
    box->pad = pad;
    @@ -842,6 +850,14 @@
    box->fill = fill;
    }
    +/* Internal. */
    +GntWidget *
    +gnt_box_get_active(GntBox *box)
    +{
    + g_return_val_if_fail(GNT_IS_BOX(box), NULL);
    + return box->active;
    +}
    +
    void gnt_box_move_focus(GntBox *box, int dir)
    {
    GntWidget *now;
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/gntboxprivate.h Wed Apr 24 01:46:26 2019 -0400
    @@ -0,0 +1,37 @@
    +/*
    + * GNT - The GLib Ncurses Toolkit
    + *
    + * GNT is the legal property of its developers, whose names are too numerous
    + * to list here. Please refer to the COPYRIGHT file distributed with this
    + * source distribution.
    + *
    + * This library is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License as published by
    + * the Free Software Foundation; either version 2 of the License, or
    + * (at your option) any later version.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    + * GNU General Public License for more details.
    + *
    + * You should have received a copy of the GNU General Public License along with
    + * this program; if not, write to the Free Software Foundation, Inc.,
    + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    + */
    +
    +#ifndef GNT_BOX_PRIVATE_H
    +#define GNT_BOX_PRIVATE_H
    +
    +#include "gnt.h"
    +#include "gntbox.h"
    +
    +G_BEGIN_DECLS
    +
    +/* Private access to some internals. Contact us if you need these. */
    +GntWidget *gnt_box_get_active(GntBox *box);
    +const gchar *gnt_box_get_title(GntBox *box);
    +
    +G_END_DECLS
    +
    +#endif /* GNT_BOX_PRIVATE_H */
    --- a/gntmain.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/gntmain.c Wed Apr 24 01:46:26 2019 -0400
    @@ -50,6 +50,7 @@
    #include "gntwindow.h"
    #include "gntwm.h"
    +#include "gntboxprivate.h"
    #include "gntmenuprivate.h"
    #include "gntwsprivate.h"
    @@ -713,8 +714,9 @@
    return TRUE;
    if (gnt_ws_is_top_widget(wm->cws, widget)) {
    if (GNT_IS_BOX(widget) &&
    - (GNT_BOX(widget)->active == w || widget == w))
    + (gnt_box_get_active(GNT_BOX(widget)) == w || widget == w)) {
    return TRUE;
    + }
    }
    return FALSE;
    }
    --- a/gntwindow.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/gntwindow.c Wed Apr 24 01:46:26 2019 -0400
    @@ -142,12 +142,11 @@
    GntWidget *
    gnt_window_box_new(gboolean homogeneous, gboolean vert)
    {
    - GntWidget *wid = gnt_window_new();
    + GntWidget *wid = g_object_new(GNT_TYPE_WINDOW, "homogeneous",
    + homogeneous, "vertical", vert, NULL);
    GntBox *box = GNT_BOX(wid);
    - box->homogeneous = homogeneous;
    - box->vertical = vert;
    - box->alignment = vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID;
    + gnt_box_set_alignment(box, vert ? GNT_ALIGN_LEFT : GNT_ALIGN_MID);
    return wid;
    }
    --- a/gntwm.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/gntwm.c Wed Apr 24 01:46:26 2019 -0400
    @@ -60,6 +60,7 @@
    #include "gntutils.h"
    #include "gntwindow.h"
    +#include "gntboxprivate.h"
    #include "gntmenuprivate.h"
    #include "gntwsprivate.h"
    @@ -130,7 +131,7 @@
    /* Update the hardware cursor */
    if (GNT_IS_WINDOW(widget) || GNT_IS_BOX(widget)) {
    - GntWidget *active = GNT_BOX(widget)->active;
    + GntWidget *active = gnt_box_get_active(GNT_BOX(widget));
    if (active) {
    int curx = active->priv.x + getcurx(active->window);
    int cury = active->priv.y + getcury(active->window);
    @@ -600,8 +601,11 @@
    for (iter = gnt_ws_get_list(wm->cws); iter; iter = iter->next) {
    GntBox *box = GNT_BOX(iter->data);
    - gnt_tree_add_row_last(tree, box,
    - gnt_tree_create_row(tree, box->title), NULL);
    + gnt_tree_add_row_last(
    + tree, box,
    + gnt_tree_create_row(tree,
    + gnt_box_get_title(box)),
    + NULL);
    update_window_in_list(wm, GNT_WIDGET(box));
    }
    } else {
    @@ -613,8 +617,11 @@
    iter = iter->next) {
    GntBox *box = GNT_BOX(iter->data);
    - gnt_tree_add_row_last(tree, box,
    - gnt_tree_create_row(tree, box->title), ws->data);
    + gnt_tree_add_row_last(
    + tree, box,
    + gnt_tree_create_row(
    + tree, gnt_box_get_title(box)),
    + ws->data);
    update_window_in_list(wm, GNT_WIDGET(box));
    }
    }
    @@ -1375,7 +1382,8 @@
    if (!GNT_IS_BOX(widget))
    return TRUE;
    - return help_for_bindable(wm, GNT_BINDABLE(GNT_BOX(widget)->active));
    + return help_for_bindable(
    + wm, GNT_BINDABLE(gnt_box_get_active(GNT_BOX(widget))));
    }
    static void
    @@ -1738,7 +1746,7 @@
    {
    GntWS *ret = NULL;
    const gchar *name, *title;
    - title = GNT_BOX(widget)->title;
    + title = gnt_box_get_title(GNT_BOX(widget));
    if (title)
    ret = g_hash_table_find(wm->title_places, match_title, (gpointer)title);
    if (ret)
    @@ -1836,7 +1844,7 @@
    }
    if (GNT_IS_BOX(widget)) {
    - const char *title = GNT_BOX(widget)->title;
    + const gchar *title = gnt_box_get_title(GNT_BOX(widget));
    GntPosition *p = NULL;
    if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) {
    sanitize_position(widget, &p->x, &p->y, TRUE);
    @@ -1849,12 +1857,19 @@
    g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget);
    if (wm->windows && !gnt_widget_get_transient(widget)) {
    - if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) &&
    + if ((GNT_IS_BOX(widget) &&
    + gnt_box_get_title(GNT_BOX(widget))) &&
    wm->_list.window != widget &&
    gnt_widget_get_take_focus(widget)) {
    - gnt_tree_add_row_last(GNT_TREE(wm->windows->tree), widget,
    - gnt_tree_create_row(GNT_TREE(wm->windows->tree), GNT_BOX(widget)->title),
    - g_object_get_data(G_OBJECT(wm->windows->tree), "workspace") ? wm->cws : NULL);
    + gnt_tree_add_row_last(
    + GNT_TREE(wm->windows->tree), widget,
    + gnt_tree_create_row(
    + GNT_TREE(wm->windows->tree),
    + gnt_box_get_title(GNT_BOX(widget))),
    + g_object_get_data(G_OBJECT(wm->windows->tree),
    + "workspace")
    + ? wm->cws
    + : NULL);
    update_window_in_list(wm, widget);
    }
    }
    @@ -2134,7 +2149,7 @@
    g_signal_emit(wm, signals[SIG_MOVED], 0, node);
    if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE) && GNT_IS_BOX(widget) &&
    !gnt_widget_get_transient(widget)) {
    - const char *title = GNT_BOX(widget)->title;
    + const gchar *title = gnt_box_get_title(GNT_BOX(widget));
    if (title) {
    GntPosition *p = g_new0(GntPosition, 1);
    GntWidget *wid = node->me;
    --- a/gntws.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/gntws.c Wed Apr 24 01:46:26 2019 -0400
    @@ -29,6 +29,8 @@
    #include "gntwm.h"
    #include "gntws.h"
    +#include "gntboxprivate.h"
    +
    typedef struct
    {
    gchar *name;
    @@ -121,7 +123,7 @@
    for (i = 0, iter = ws->list; iter; iter = iter->next, i++) {
    GntWidget *w = iter->data;
    int color;
    - const char *title;
    + const gchar *title;
    if (w == ws->ordered->data) {
    /* This is the current window in focus */
    @@ -137,7 +139,7 @@
    mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), width);
    else
    mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), getmaxx(stdscr) - width * i);
    - title = GNT_BOX(w)->title;
    + title = gnt_box_get_title(GNT_BOX(w));
    mvwprintw(taskbar, 0, width * i, "%s", title ? C_(title) : "<gnt>");
    if (i)
    mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | gnt_color_pair(GNT_COLOR_NORMAL));
    --- a/wms/irssi.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/wms/irssi.c Wed Apr 24 01:46:26 2019 -0400
    @@ -43,6 +43,7 @@
    #include "gntwindow.h"
    #include "gntlabel.h"
    +#include "gntboxprivate.h"
    #include "gntwsprivate.h"
    #define GNT_TYPE_IRSSI_WM gnt_irssi_wm_get_type()
    @@ -220,8 +221,10 @@
    char title[256];
    int x, y;
    snprintf(title, sizeof(title), "%d: %s",
    - GPOINTER_TO_INT(g_object_get_data(G_OBJECT(node->me), "irssi-index")) + 1,
    - GNT_BOX(node->me)->title);
    + GPOINTER_TO_INT(
    + g_object_get_data(G_OBJECT(node->me), "irssi-index")) +
    + 1,
    + gnt_box_get_title(GNT_BOX(node->me)));
    getyx(node->window, y, x);
    wbkgdset(node->window, '\0' | COLOR_PAIR(gnt_widget_has_focus(node->me) ? GNT_COLOR_TITLE : GNT_COLOR_TITLE_D));
    --- a/wms/s.c Fri Apr 26 03:43:22 2019 +0000
    +++ b/wms/s.c Wed Apr 24 01:46:26 2019 -0400
    @@ -33,6 +33,7 @@
    #include "gntwindow.h"
    #include "gntlabel.h"
    +#include "gntboxprivate.h"
    #include "gntwsprivate.h"
    #define GNT_TYPE_S_WM gnt_s_wm_get_type()
    @@ -124,7 +125,7 @@
    gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */
    } else if (!gnt_widget_get_transient(win)) {
    - const char *title = GNT_BOX(win)->title;
    + const gchar *title = gnt_box_get_title(GNT_BOX(win));
    if (title == NULL || !g_hash_table_lookup(wm->positions, title)) {
    /* In the middle of the screen */
    x = (maxx - w) / 2;