From 6e798a18c65df1340037a6881088990e1fa30d14 Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Wed, 28 Dec 2011 13:47:22 -0600 Subject: user style ALL the pages _o/ From Cody Wright M8R-2bxmml@mailinator.com --- settings.c | 2 ++ xxxterm.1 | 6 +++++- xxxterm.c | 50 +++++++++++++++++++++++++++++++++++++++----------- xxxterm.conf | 1 + xxxterm.h | 3 ++- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/settings.c b/settings.c index 04d8e91..79e4830 100644 --- a/settings.c +++ b/settings.c @@ -88,6 +88,7 @@ char *encoding = NULL; int autofocus_onload = 0; int js_autorun_enabled = 1; int edit_mode = XT_EM_HYBRID; +int userstyle_global = 0; char *cmd_font_name = NULL; char *oops_font_name = NULL; @@ -681,6 +682,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 4e33ae2..28fddc1 100644 --- a/xxxterm.1 +++ b/xxxterm.1 @@ -392,13 +392,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 fddf269..09fe44d 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -23,9 +23,8 @@ char *version = XXXTERM_VERSION; -/*#ifdef XT_DEBUG*/ +#ifdef XT_DEBUG u_int32_t swm_debug = 0 -/* | XT_D_MOVE | XT_D_KEY | XT_D_TAB @@ -42,7 +41,6 @@ u_int32_t swm_debug = 0 | XT_D_CLIP | XT_D_BUFFERCMD | XT_D_INSPECTOR -*/ | XT_D_VISITED | XT_D_HISTORY ; @@ -178,6 +176,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) @@ -1038,23 +1039,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); } @@ -3101,7 +3125,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 }, @@ -6680,6 +6705,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 451ab89..635a885 100644 --- a/xxxterm.conf +++ b/xxxterm.conf @@ -196,6 +196,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 a721183..dee5f6d 100644 --- a/xxxterm.h +++ b/xxxterm.h @@ -108,7 +108,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define XT_DEBUG +/*#define XT_DEBUG*/ #ifdef XT_DEBUG #define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0) #define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while (0) @@ -538,6 +538,7 @@ extern char *oops_font_name; extern char *statusbar_font_name; extern char *tabbar_font_name; extern int edit_mode; +extern int userstyle_global; /* globals */ extern char *version; -- cgit 1.4.1-2-gfad0