- From 23ac5106aff225dbf30551cd54b2f8fb430d3728 Mon Sep 17 00:00:00 2001
- From: Cody Wright <M8R-2bxmml@mailinator.com>
- Date: Mon, 7 Nov 2011 00:13:13 +0100
- Subject: [PATCH] Add a global userstyle mode that affects all tabs, including
- new ones
- ---
- settings.c | 2 ++
- xxxterm.1 | 6 +++++-
- xxxterm.c | 46 ++++++++++++++++++++++++++++++++++++++--------
- xxxterm.conf | 1 +
- xxxterm.h | 1 +
- 5 files changed, 47 insertions(+), 9 deletions(-)
- diff --git a/settings.c b/settings.c
- index 6bae81e..d4d29fe 100644
- --- a/settings.c
- +++ b/settings.c
- @@ -86,6 +86,7 @@ char command_file[PATH_MAX];
- char *encoding = NULL;
- int autofocus_onload = 0;
- int js_autorun_enabled = 1;
- +int userstyle_global = 0;
- char *cmd_font_name = NULL;
- char *oops_font_name = NULL;
- @@ -668,6 +669,7 @@ struct key_binding keys[] = {
- /* custom stylesheet */
- { "userstyle", 0, 0, GDK_s },
- + { "userstyle_global", SHFT, 0, GDK_S },
- /* navigation */
- { "goback", 0, 0, GDK_BackSpace },
- diff --git a/xxxterm.1 b/xxxterm.1
- index 5c6711c..3074d55 100644
- --- a/xxxterm.1
- +++ b/xxxterm.1
- @@ -390,13 +390,17 @@ Quit
- .Pq Cm quitall
- .El
- .Ss Low-Contrast Color Scheme
- -This command toggles the page's style between the default CSS and a
- +These commands toggle the page style between the default CSS and a
- low-contrast color scheme with light grey text on a dark grey background.
- .Pp
- .Bl -tag -width Ds -offset indent -compact
- .It Cm s
- Toggle the current tab's style.
- .Pq Cm userstyle
- +.It Cm S
- +Toggle the global page style mode.
- +Will also affect new tabs.
- +.Pq Cm userstyle_global
- .El
- .Sh COMMAND MODE
- Command mode works in a similar fashion to the
- diff --git a/xxxterm.c b/xxxterm.c
- index 4fdbd5a..1db4f7b 100644
- --- a/xxxterm.c
- +++ b/xxxterm.c
- @@ -169,6 +169,9 @@ TAILQ_HEAD(command_list, command_entry);
- #define XT_SEARCH_NEXT (1)
- #define XT_SEARCH_PREV (2)
- +#define XT_STYLE_CURRENT_TAB (0)
- +#define XT_STYLE_GLOBAL (1)
- +
- #define XT_PASTE_CURRENT_TAB (0)
- #define XT_PASTE_NEW_TAB (1)
- @@ -1039,23 +1042,46 @@ hint(struct tab *t, struct karg *args)
- void
- apply_style(struct tab *t)
- {
- + t->styled = 1;
- g_object_set(G_OBJECT(t->settings),
- "user-stylesheet-uri", t->stylesheet, (char *)NULL);
- }
- +void
- +remove_style(struct tab *t)
- +{
- + t->styled = 0;
- + g_object_set(G_OBJECT(t->settings),
- + "user-stylesheet-uri", NULL, (char *)NULL);
- +}
- +
- int
- userstyle(struct tab *t, struct karg *args)
- {
- + struct tab *tt;
- +
- DNPRINTF(XT_D_JS, "userstyle: tab %d\n", t->tab_id);
- - if (t->styled) {
- - t->styled = 0;
- - g_object_set(G_OBJECT(t->settings),
- - "user-stylesheet-uri", NULL, (char *)NULL);
- - } else {
- - t->styled = 1;
- - apply_style(t);
- + switch (args->i) {
- + case XT_STYLE_CURRENT_TAB:
- + if (t->styled)
- + remove_style(t);
- + else
- + apply_style(t);
- + break;
- + case XT_STYLE_GLOBAL:
- + if (userstyle_global) {
- + userstyle_global = 0;
- + TAILQ_FOREACH(tt, &tabs, entry)
- + remove_style(tt);
- + } else {
- + userstyle_global = 1;
- + TAILQ_FOREACH(tt, &tabs, entry)
- + apply_style(tt);
- + }
- + break;
- }
- +
- return (0);
- }
- @@ -2947,7 +2973,8 @@ struct cmd {
- { "hinting_newtab", 0, hint, XT_HINT_NEWTAB, 0 },
- /* custom stylesheet */
- - { "userstyle", 0, userstyle, 0, 0 },
- + { "userstyle", 0, userstyle, XT_STYLE_CURRENT_TAB, 0 },
- + { "userstyle_global", 0, userstyle, XT_STYLE_GLOBAL, 0 },
- /* navigation */
- { "goback", 0, navaction, XT_NAV_BACK, 0 },
- @@ -6472,6 +6499,9 @@ create_new_tab(char *title, struct undo *u, int focus, int position)
- } else if (load)
- load_uri(t, title);
- + if (userstyle_global)
- + apply_style(t);
- +
- recolor_compact_tabs();
- setzoom_webkit(t, XT_ZOOM_NORMAL);
- return (t);
- diff --git a/xxxterm.conf b/xxxterm.conf
- index 839c3bd..f880df7 100644
- --- a/xxxterm.conf
- +++ b/xxxterm.conf
- @@ -194,6 +194,7 @@
- # keybinding = hinting_newtab,S-F
- # keybinding = hinting_newtab,comma
- # keybinding = userstyle,s
- +# keybinding = userstyle_global,S
- # keybinding = goback,BackSpace
- # keybinding = goback,M1-Left
- # keybinding = goforward,S-BackSpace
- diff --git a/xxxterm.h b/xxxterm.h
- index 8d5f1bd..bcd0498 100644
- --- a/xxxterm.h
- +++ b/xxxterm.h
- @@ -516,6 +516,7 @@ extern char *cmd_font_name;
- extern char *oops_font_name;
- extern char *statusbar_font_name;
- extern char *tabbar_font_name;
- +extern int userstyle_global;
- /* globals */
- extern char *version;
- --
- 1.7.6