Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Nov 6th, 2011  |  syntax: None  |  size: 4.29 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. From 23ac5106aff225dbf30551cd54b2f8fb430d3728 Mon Sep 17 00:00:00 2001
  2. From: Cody Wright <M8R-2bxmml@mailinator.com>
  3. Date: Mon, 7 Nov 2011 00:13:13 +0100
  4. Subject: [PATCH] Add a global userstyle mode that affects all tabs, including
  5.  new ones
  6.  
  7. ---
  8.  settings.c   |    2 ++
  9.  xxxterm.1    |    6 +++++-
  10.  xxxterm.c    |   46 ++++++++++++++++++++++++++++++++++++++--------
  11.  xxxterm.conf |    1 +
  12.  xxxterm.h    |    1 +
  13.  5 files changed, 47 insertions(+), 9 deletions(-)
  14.  
  15. diff --git a/settings.c b/settings.c
  16. index 6bae81e..d4d29fe 100644
  17. --- a/settings.c
  18. +++ b/settings.c
  19. @@ -86,6 +86,7 @@ char          command_file[PATH_MAX];
  20.  char           *encoding = NULL;
  21.  int            autofocus_onload = 0;
  22.  int            js_autorun_enabled = 1;
  23. +int            userstyle_global = 0;
  24.  
  25.  char           *cmd_font_name = NULL;
  26.  char           *oops_font_name = NULL;
  27. @@ -668,6 +669,7 @@ struct key_binding  keys[] = {
  28.  
  29.         /* custom stylesheet */
  30.         { "userstyle",          0,      0,      GDK_s           },
  31. +       { "userstyle_global",   SHFT,   0,      GDK_S           },
  32.  
  33.         /* navigation */
  34.         { "goback",             0,      0,      GDK_BackSpace   },
  35. diff --git a/xxxterm.1 b/xxxterm.1
  36. index 5c6711c..3074d55 100644
  37. --- a/xxxterm.1
  38. +++ b/xxxterm.1
  39. @@ -390,13 +390,17 @@ Quit
  40.  .Pq Cm quitall
  41.  .El
  42.  .Ss Low-Contrast Color Scheme
  43. -This command toggles the page's style between the default CSS and a
  44. +These commands toggle the page style between the default CSS and a
  45.  low-contrast color scheme with light grey text on a dark grey background.
  46.  .Pp
  47.  .Bl -tag -width Ds -offset indent -compact
  48.  .It Cm s
  49.  Toggle the current tab's style.
  50.  .Pq Cm userstyle
  51. +.It Cm S
  52. +Toggle the global page style mode.
  53. +Will also affect new tabs.
  54. +.Pq Cm userstyle_global
  55.  .El
  56.  .Sh COMMAND MODE
  57.  Command mode works in a similar fashion to the
  58. diff --git a/xxxterm.c b/xxxterm.c
  59. index 4fdbd5a..1db4f7b 100644
  60. --- a/xxxterm.c
  61. +++ b/xxxterm.c
  62. @@ -169,6 +169,9 @@ TAILQ_HEAD(command_list, command_entry);
  63.  #define XT_SEARCH_NEXT         (1)
  64.  #define XT_SEARCH_PREV         (2)
  65.  
  66. +#define XT_STYLE_CURRENT_TAB   (0)
  67. +#define XT_STYLE_GLOBAL                (1)
  68. +
  69.  #define XT_PASTE_CURRENT_TAB   (0)
  70.  #define XT_PASTE_NEW_TAB       (1)
  71.  
  72. @@ -1039,23 +1042,46 @@ hint(struct tab *t, struct karg *args)
  73.  void
  74.  apply_style(struct tab *t)
  75.  {
  76. +       t->styled = 1;
  77.         g_object_set(G_OBJECT(t->settings),
  78.             "user-stylesheet-uri", t->stylesheet, (char *)NULL);
  79.  }
  80.  
  81. +void
  82. +remove_style(struct tab *t)
  83. +{
  84. +       t->styled = 0;
  85. +       g_object_set(G_OBJECT(t->settings),
  86. +           "user-stylesheet-uri", NULL, (char *)NULL);
  87. +}
  88. +
  89.  int
  90.  userstyle(struct tab *t, struct karg *args)
  91.  {
  92. +       struct tab              *tt;
  93. +
  94.         DNPRINTF(XT_D_JS, "userstyle: tab %d\n", t->tab_id);
  95.  
  96. -       if (t->styled) {
  97. -               t->styled = 0;
  98. -               g_object_set(G_OBJECT(t->settings),
  99. -                   "user-stylesheet-uri", NULL, (char *)NULL);
  100. -       } else {
  101. -               t->styled = 1;
  102. -               apply_style(t);
  103. +       switch (args->i) {
  104. +       case XT_STYLE_CURRENT_TAB:
  105. +               if (t->styled)
  106. +                       remove_style(t);
  107. +               else
  108. +                       apply_style(t);
  109. +               break;
  110. +       case XT_STYLE_GLOBAL:
  111. +               if (userstyle_global) {
  112. +                       userstyle_global = 0;
  113. +                       TAILQ_FOREACH(tt, &tabs, entry)
  114. +                               remove_style(tt);
  115. +               } else {
  116. +                       userstyle_global = 1;
  117. +                       TAILQ_FOREACH(tt, &tabs, entry)
  118. +                               apply_style(tt);
  119. +               }
  120. +               break;
  121.         }
  122. +
  123.         return (0);
  124.  }
  125.  
  126. @@ -2947,7 +2973,8 @@ struct cmd {
  127.         { "hinting_newtab",     0,      hint,                   XT_HINT_NEWTAB,         0 },
  128.  
  129.         /* custom stylesheet */
  130. -       { "userstyle",          0,      userstyle,              0,                      0 },
  131. +       { "userstyle",          0,      userstyle,              XT_STYLE_CURRENT_TAB,   0 },
  132. +       { "userstyle_global",   0,      userstyle,              XT_STYLE_GLOBAL,        0 },
  133.  
  134.         /* navigation */
  135.         { "goback",             0,      navaction,              XT_NAV_BACK,            0 },
  136. @@ -6472,6 +6499,9 @@ create_new_tab(char *title, struct undo *u, int focus, int position)
  137.         } else if (load)
  138.                 load_uri(t, title);
  139.  
  140. +       if (userstyle_global)
  141. +               apply_style(t);
  142. +
  143.         recolor_compact_tabs();
  144.         setzoom_webkit(t, XT_ZOOM_NORMAL);
  145.         return (t);
  146. diff --git a/xxxterm.conf b/xxxterm.conf
  147. index 839c3bd..f880df7 100644
  148. --- a/xxxterm.conf
  149. +++ b/xxxterm.conf
  150. @@ -194,6 +194,7 @@
  151.  # keybinding   = hinting_newtab,S-F
  152.  # keybinding   = hinting_newtab,comma
  153.  # keybinding   = userstyle,s
  154. +# keybinding   = userstyle_global,S
  155.  # keybinding   = goback,BackSpace
  156.  # keybinding   = goback,M1-Left
  157.  # keybinding   = goforward,S-BackSpace
  158. diff --git a/xxxterm.h b/xxxterm.h
  159. index 8d5f1bd..bcd0498 100644
  160. --- a/xxxterm.h
  161. +++ b/xxxterm.h
  162. @@ -516,6 +516,7 @@ extern char *cmd_font_name;
  163.  extern char    *oops_font_name;
  164.  extern char    *statusbar_font_name;
  165.  extern char    *tabbar_font_name;
  166. +extern int     userstyle_global;
  167.  
  168.  /* globals */
  169.  extern char            *version;
  170. --
  171. 1.7.6