diff options
author | portix <none@none> | 2012-11-30 18:36:01 +0100 |
---|---|---|
committer | portix <none@none> | 2012-11-30 18:36:01 +0100 |
commit | d1bed65f0559f4f2735942ad152803f21c7e90d5 (patch) | |
tree | a8f2e6c6e5acf7217401c10f1525bc0d678a9892 | |
parent | 342835d1eea41964ca40c34711af9f2c171d5e91 (diff) | |
download | dwb-d1bed65f0559f4f2735942ad152803f21c7e90d5.zip |
Implementing tab_next/prev, untested
-rw-r--r-- | src/commands.c | 32 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/dwb.c | 11 | ||||
-rw-r--r-- | src/tabs.c | 134 | ||||
-rw-r--r-- | src/tabs.h | 29 |
5 files changed, 183 insertions, 25 deletions
diff --git a/src/commands.c b/src/commands.c index 45940b2a..abc7d81c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -30,6 +30,7 @@ #include "download.h" #include "js.h" #include "scripts.h" +#include "tabs.h" inline static int dwb_floor(double x) { @@ -894,6 +895,7 @@ commands_group_show(KeyMap *km, Arg *arg) { } return STATUS_OK; } +#endif DwbStatus commands_group_toggle(KeyMap *km, Arg *arg) { int n = MIN(NUMMOD, 9), i=0; @@ -907,19 +909,23 @@ commands_group_toggle(KeyMap *km, Arg *arg) { DwbStatus commands_group_tag(KeyMap *km, Arg *arg) { int n = MIN(NUMMOD, 9); - if (CURRENT_VIEW()->status->group & (1<<n)) { - CURRENT_VIEW()->status->group &= ~(1<<n); - if (!GROUP_VISIBLE(dwb.state.fview)) - dwb_hide_tab(dwb.state.fview); - dwb_set_normal_message(dwb.state.fview, true, "Untagged group %d", n); - } - else { - CURRENT_VIEW()->status->group |= 1<<n; - if (GROUP_VISIBLE(dwb.state.fview)) - dwb_show_tab(dwb.state.fview); - dwb_set_normal_message(dwb.state.fview, true, "Tagged group %d", n); - } + if (dwb.state.nummod > 9 || dwb.state.nummod < 0) + return STATUS_ERROR; + CURRENT_VIEW()->status->group &= (1<<n); + tab_update(dwb.state.fview); + + //if (CURRENT_VIEW()->status->group & (1<<n)) { + // CURRENT_VIEW()->status->group &= ~(1<<n); + // if (!GROUP_VISIBLE(dwb.state.fview)) + // dwb_hide_tab(dwb.state.fview); + // dwb_set_normal_message(dwb.state.fview, true, "Untagged group %d", n); + //} + //else { + // CURRENT_VIEW()->status->group |= 1<<n; + // if (GROUP_VISIBLE(dwb.state.fview)) + // dwb_show_tab(dwb.state.fview); + // dwb_set_normal_message(dwb.state.fview, true, "Tagged group %d", n); + //} return STATUS_OK; } -#endif diff --git a/src/config.h b/src/config.h index bddf686a..02bb6e48 100644 --- a/src/config.h +++ b/src/config.h @@ -184,7 +184,7 @@ static KeyValue KEYS[] = { { "eval", { NULL, 0, 0 }, }, { "download", { "gd", 0, 0 }, }, { "toggle_tab", { "@Tab@", GDK_CONTROL_MASK, 0 }, }, -#if 0 +#if 1 { "group_tag", { "am", 0, 0 }, }, { "group_show", { "as", 0, 0 }, }, { "group_toggle", { "at", 0, 0 }, }, @@ -1404,17 +1404,6 @@ dwb_hide_tabbar(int *running) { return false; }/*}}}*/ -#if 0 -void -dwb_hide_tab(GList *gl) { - puts("hide tab"); -} -void -dwb_show_tab(GList *gl) { - puts("show tab"); -} -#endif - /* dwb_focus_view(GList *gl){{{*/ gboolean dwb_focus_view(GList *gl) { diff --git a/src/tabs.c b/src/tabs.c new file mode 100644 index 00000000..5e2d212a --- /dev/null +++ b/src/tabs.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net> + * + * This program 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 3 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. + */ + +#include "dwb.h" +#include "tabs.h" + +#define TAB_VISIBLE(gl) (VIEW((gl))->status->group & dwb.state.current_groups) + +static gint +count_visible() { + int n=0; + for (GList *gl = dwb.state.views; gl; gl=gl->next) { + if (TAB_VISIBLE(gl)) + n++; + } + return n; +} +GList * +tab_next(GList *gl, gint steps, gboolean skip) +{ + g_return_val_if_fail(gl != NULL, dwb.state.fview); + + GList *n, *last = gl; + gint l, i; + + if (!dwb.state.views->next) + return gl; + + l = count_visible(dwb.state.views); + steps %= l; + + for (i=0, n=gl->next; i<steps && n; n=n->prev) + { + if (n == gl) + return gl; + if (n == NULL) + { + if (skip) + n = dwb.state.views; + else + return last; + } + if (TAB_VISIBLE(n)) { + i++; + last = n; + } + } + return n; +} +GList * +tab_prev(GList *gl, gint steps, gboolean skip) +{ + g_return_val_if_fail(gl != NULL, dwb.state.fview); + + GList *p, *last = gl; + gint l, i; + + if (!dwb.state.views->next) + return gl; + + l = count_visible(dwb.state.views); + steps %= l; + + for (i=0, p=gl->prev; i<steps && p; p=p->prev) + { + if (p == gl) + return gl; + if (p == NULL) + { + if (skip) + p = g_list_last(dwb.state.views); + else + return last; + } + if (TAB_VISIBLE(p)) + { + i++; + last = p; + } + } + + return p; +} +int +tab_position(GList *gl) +{ + int n=0; + + if (dwb.state.current_groups == 0) + return g_list_position(dwb.state.views, gl); + + for (GList *l = dwb.state.views; l; l=l->next) + { + if (TAB_VISIBLE(l)) + { + if (l == gl) + return n; + n++; + } + } + return -1; +} +void +tab_update(GList *gl) +{ + if (TAB_VISIBLE(gl)) + tab_show(gl); + else + tab_hide(gl); +} +void +tab_show(GList *gl) +{ + +} +void +tab_hide(GList *gl) +{ +} diff --git a/src/tabs.h b/src/tabs.h new file mode 100644 index 00000000..0ee58c2e --- /dev/null +++ b/src/tabs.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net> + * + * This program 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 3 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 TABS_H +#define TABS_H + + +GList * tab_next(GList *, gint steps, gboolean skip); +GList * tab_prev(GList *, gint steps, gboolean skip); +void tab_show(GList *); +void tab_hide(GList *); +void tab_update(GList *gl); + +#endif |