libgnt/libgnt

Add some private accessors for GntWS->list.

2019-04-25, Elliott Sales de Andrade
49842f6491e1
Add some private accessors for GntWS->list.
  • +1 -1
    gntmain.c
  • +20 -15
    gntwm.c
  • +16 -0
    gntws.c
  • +3 -0
    gntwsprivate.h
  • +3 -1
    wms/irssi.c
  • +3 -1
    wms/s.c
  • --- a/gntmain.c Wed Apr 24 21:54:50 2019 -0400
    +++ b/gntmain.c Thu Apr 25 03:42:09 2019 -0400
    @@ -228,7 +228,7 @@
    } else if (event == GNT_MOUSE_UP) {
    if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) {
    /* Clicked on the taskbar */
    - int n = g_list_length(wm->cws->list);
    + int n = g_list_length(gnt_ws_get_list(wm->cws));
    if (n) {
    int width = getmaxx(stdscr) / n;
    gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL);
    --- a/gntwm.c Wed Apr 24 21:54:50 2019 -0400
    +++ b/gntwm.c Thu Apr 25 03:42:09 2019 -0400
    @@ -406,6 +406,7 @@
    switch_window(GntWM *wm, int direction, gboolean urgent)
    {
    GntWidget *w = NULL, *wid = NULL;
    + GList *list;
    int pos, orgpos;
    if (wm->_list.window || wm->menu)
    @@ -420,20 +421,22 @@
    }
    w = gnt_ws_get_top_widget(wm->cws);
    - orgpos = pos = g_list_index(wm->cws->list, w);
    + list = gnt_ws_get_list(wm->cws);
    + orgpos = pos = g_list_index(list, w);
    g_return_if_fail(pos >= 0);
    do {
    pos += direction;
    if (pos < 0) {
    - wid = g_list_last(wm->cws->list)->data;
    - pos = g_list_length(wm->cws->list) - 1;
    - } else if ((guint)pos >= g_list_length(wm->cws->list)) {
    - wid = wm->cws->list->data;
    + wid = g_list_last(list)->data;
    + pos = g_list_length(list) - 1;
    + } else if ((guint)pos >= g_list_length(list)) {
    + wid = list->data;
    pos = 0;
    - } else
    - wid = g_list_nth_data(wm->cws->list, pos);
    + } else {
    + wid = g_list_nth_data(list, pos);
    + }
    } while (urgent && !gnt_widget_get_is_urgent(wid) && pos != orgpos);
    gnt_wm_raise_window(wm, wid);
    @@ -471,8 +474,7 @@
    else
    n = 0;
    - if ((l = g_list_nth(wm->cws->list, n)) != NULL)
    - {
    + if ((l = g_list_nth(gnt_ws_get_list(wm->cws), n)) != NULL) {
    gnt_wm_raise_window(wm, l->data);
    }
    @@ -594,7 +596,7 @@
    GList *iter;
    GntTree *tree = GNT_TREE(wm->windows->tree);
    if (!workspace) {
    - for (iter = wm->cws->list; iter; iter = iter->next) {
    + 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,
    @@ -606,7 +608,8 @@
    for (; ws; ws = ws->next) {
    gnt_tree_add_row_last(tree, ws->data,
    gnt_tree_create_row(tree, gnt_ws_get_name(GNT_WS(ws->data))), NULL);
    - for (iter = GNT_WS(ws->data)->list; iter; iter = iter->next) {
    + for (iter = gnt_ws_get_list(GNT_WS(ws->data)); iter;
    + iter = iter->next) {
    GntBox *box = GNT_BOX(iter->data);
    gnt_tree_add_row_last(tree, box,
    @@ -865,7 +868,7 @@
    static void
    shift_window(GntWM *wm, GntWidget *widget, int dir)
    {
    - GList *all = wm->cws->list;
    + GList *all = gnt_ws_get_list(wm->cws);
    GList *list = g_list_find(all, widget);
    int length, pos;
    if (!list)
    @@ -885,7 +888,7 @@
    all = g_list_insert(all, widget, pos);
    all = g_list_delete_link(all, list);
    - wm->cws->list = all;
    + gnt_ws_set_list(wm->cws, all);
    gnt_ws_draw_taskbar(wm->cws, FALSE);
    if (!gnt_ws_is_empty(wm->cws)) {
    GntWidget *w = gnt_ws_get_top_widget(wm->cws);
    @@ -1682,8 +1685,10 @@
    static gint widget_in_workspace(gconstpointer workspace, gconstpointer wid)
    {
    GntWS *s = (GntWS *)workspace;
    - if (s->list && g_list_find(s->list, wid))
    + GList *list = gnt_ws_get_list(s);
    + if (list && g_list_find(list, wid)) {
    return 0;
    + }
    return 1;
    }
    @@ -1881,7 +1886,7 @@
    }
    if (s) {
    - pos = g_list_index(s->list, widget);
    + pos = g_list_index(gnt_ws_get_list(s), widget);
    if (pos != -1) {
    gnt_ws_remove_widget(s, widget);
    --- a/gntws.c Wed Apr 24 21:54:50 2019 -0400
    +++ b/gntws.c Thu Apr 25 03:42:09 2019 -0400
    @@ -220,6 +220,22 @@
    }
    /* Internal. */
    +void
    +gnt_ws_set_list(GntWS *ws, GList *list)
    +{
    + g_return_if_fail(GNT_IS_WS(ws));
    + ws->list = list;
    +}
    +
    +/* Internal. */
    +GList *
    +gnt_ws_get_list(GntWS *ws)
    +{
    + g_return_val_if_fail(GNT_IS_WS(ws), NULL);
    + return ws->list;
    +}
    +
    +/* Internal. */
    gboolean gnt_ws_is_empty(GntWS *ws)
    {
    g_return_val_if_fail(GNT_IS_WS(ws), TRUE);
    --- a/gntwsprivate.h Wed Apr 24 21:54:50 2019 -0400
    +++ b/gntwsprivate.h Thu Apr 25 03:42:09 2019 -0400
    @@ -37,6 +37,9 @@
    void gnt_ws_append_widget(GntWS *ws, GntWidget *widget);
    void gnt_ws_bring_to_front(GntWS *ws, GntWidget *widget);
    +void gnt_ws_set_list(GntWS *ws, GList *list);
    +GList *gnt_ws_get_list(GntWS *ws);
    +
    G_END_DECLS
    #endif /* GNT_WS_PRIVATE_H */
    --- a/wms/irssi.c Wed Apr 24 21:54:50 2019 -0400
    +++ b/wms/irssi.c Thu Apr 25 03:42:09 2019 -0400
    @@ -240,7 +240,9 @@
    const char *name = gnt_widget_get_name(win);
    if (!name || !GNT_IS_BOX(win) || !strstr(name, "conversation-window"))
    return;
    - g_object_set_data(G_OBJECT(win), "irssi-index", GINT_TO_POINTER(g_list_index(wm->cws->list, win)));
    + g_object_set_data(
    + G_OBJECT(win), "irssi-index",
    + GINT_TO_POINTER(g_list_index(gnt_ws_get_list(wm->cws), win)));
    g_timeout_add(0, (GSourceFunc)update_conv_window_title, node);
    }
    --- a/wms/s.c Wed Apr 24 21:54:50 2019 -0400
    +++ b/wms/s.c Thu Apr 25 03:42:09 2019 -0400
    @@ -33,6 +33,8 @@
    #include "gntwindow.h"
    #include "gntlabel.h"
    +#include "gntwsprivate.h"
    +
    #define GNT_TYPE_S_WM gnt_s_wm_get_type()
    G_DECLARE_FINAL_TYPE(GntSWM, gnt_s_wm, GNT, S_WM, GntWM)
    @@ -142,7 +144,7 @@
    static GntWidget *
    find_widget(GntWM *wm, const char *wname)
    {
    - GList *iter = wm->cws->list;
    + GList *iter = gnt_ws_get_list(wm->cws);
    for (; iter; iter = iter->next) {
    GntWidget *widget = iter->data;
    const char *name = gnt_widget_get_name(widget);