add custom style toggle

This commit is contained in:
NunoSempere 2024-04-14 08:53:45 -04:00
parent c4581f3fd5
commit 8aa43e81fc
3 changed files with 36 additions and 28 deletions

View File

@ -16,7 +16,6 @@
// Plugins
#define LIBRE_REDIRECT_ENABLED true
#define READABILITY_ENABLED true
#define CUSTOM_STYLE_ENABLED true
#define CUSTOM_USER_AGENT false
/*
To disable plugins:
@ -57,6 +56,7 @@ typedef enum {
refresh_force,
back_to_home,
toggle_fullscreen,
toggle_custom_style,
zoomin,
zoomout,
zoom_reset,
@ -78,27 +78,28 @@ static struct {
unsigned key;
func id;
} shortcut[] = {
{ CTRL, KEY(h), goback },
{ CTRL, KEY(j), goforward },
{ CTRL, KEY(r), refresh },
{ CTRL, KEY(R), refresh_force },
{ CTRL, KEY(H), back_to_home },
{ CTRL, KEY(equal), zoomin },
{ CTRL, KEY(minus), zoomout },
{ CTRL, KEY(0), zoom_reset },
{ CTRL, KEY(KP_Page_Up), prev_tab },
{ CTRL, KEY(KP_Page_Down), next_tab },
{ CTRL, KEY(Page_Up), prev_tab }, // working hypothesis: Page_UP vs KP_Page_Up might depend on whether the user has a numpad
{ CTRL, KEY(Page_Down), next_tab },
{ CTRL, KEY(t), new_tab },
{ CTRL, KEY(w), close_tab },
{ 0x0, KEY(F11), toggle_fullscreen },
{ CTRL, KEY(l), show_searchbar },
{ CTRL, KEY(semicolon), hide_bar },
{ CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next },
{ CTRL, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify }
{ CTRL, KEY(h), goback },
{ CTRL, KEY(j), goforward },
{ CTRL, KEY(r), refresh },
{ CTRL, KEY(R), refresh_force },
{ CTRL, KEY(H), back_to_home },
{ CTRL, KEY(equal), zoomin },
{ CTRL, KEY(minus), zoomout },
{ CTRL, KEY(0), zoom_reset },
{ CTRL, KEY(KP_Page_Up), prev_tab },
{ CTRL, KEY(KP_Page_Down), next_tab },
{ CTRL, KEY(Page_Up), prev_tab }, // working hypothesis: Page_UP vs KP_Page_Up might depend on whether the user has a numpad
{ CTRL, KEY(Page_Down), next_tab },
{ CTRL, KEY(t), new_tab },
{ CTRL, KEY(w), close_tab },
{ 0x0, KEY(F11), toggle_fullscreen },
{ CTRL, KEY(S), toggle_custom_style },
{ CTRL, KEY(l), show_searchbar },
{ CTRL, KEY(semicolon), hide_bar },
{ CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next },
{ CTRL, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify }
};
/* Old controls: {

View File

@ -23,8 +23,9 @@ int shortcut_expand(const char* uri, char* output)
"!fnf",
"!fnc",
"!hn",
"!hnb"
"!x",
"!hnb",
"!ww",
"!x"
};
char* expansions[] = {
@ -34,7 +35,8 @@ int shortcut_expand(const char* uri, char* output)
"https://forum.nunosempere.com/comments",
"https://news.ycombinator.com",
"https://news.ycombinator.com/best",
"https://twitter.com",
"https://web.whatsapp.com",
"https://twitter.com"
};
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);

View File

@ -17,6 +17,7 @@ static struct {
Bar_entry_mode entry_mode;
} bar;
static int num_tabs = 0;
static int custom_style_enabled = 1;
/* Forward declarations */
void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode);
@ -71,7 +72,7 @@ void redirect_if_annoying(WebKitWebView* view, const char* uri)
}
void set_custom_style(WebKitWebView* view)
{
if (CUSTOM_STYLE_ENABLED) {
if (custom_style_enabled) {
char* style_js = malloc(STYLE_N + 1);
read_style_js(style_js);
webkit_web_view_evaluate_javascript(view, style_js, -1, NULL, "rosenrot-style-plugin", NULL, NULL, NULL);
@ -302,7 +303,6 @@ int handle_shortcut(func id, GtkNotebook* notebook)
}
break;
case toggle_fullscreen:
if (is_fullscreen)
gtk_window_unfullscreen(window);
@ -310,7 +310,12 @@ int handle_shortcut(func id, GtkNotebook* notebook)
gtk_window_fullscreen(window);
is_fullscreen = !is_fullscreen;
break;
case toggle_custom_style: /* Ctrl s + Ctrl Shift R to reload */
if (custom_style_enabled)
custom_style_enabled = 0;
else
custom_style_enabled = 1;
break;
case show_searchbar:
toggle_bar(notebook, _SEARCH);
break;