From 5c56652e871a435aa22a297d6d443e6f32cfdff0 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 22 Mar 2024 07:48:49 -0300 Subject: [PATCH] refactor toggle bar code. --- plugins/style/style.c | 2 +- plugins/style/style.h | 2 +- rosenrot | Bin 40120 -> 40120 bytes rosenrot.c | 30 ++++++++++++++++++------------ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/plugins/style/style.c b/plugins/style/style.c index a99bd78..d10c2e8 100644 --- a/plugins/style/style.c +++ b/plugins/style/style.c @@ -1,7 +1,7 @@ #include #include #include -#define STYLE_N 7274 + 1000 +#define STYLE_N 7624 + 1000 void read_style_js(char* string) { diff --git a/plugins/style/style.h b/plugins/style/style.h index e2751ec..1faab7a 100644 --- a/plugins/style/style.h +++ b/plugins/style/style.h @@ -1,7 +1,7 @@ #ifndef STYLE #define STYLE -#define STYLE_N 7274 + 1000 +#define STYLE_N 7624 + 1000 void read_style_js(char* string); diff --git a/rosenrot b/rosenrot index 52ccf82c72b613f463b5df4d56243aa6e107bf46..a72527c2bad73be1e7bd0ab8643c9aa40f7fdc0b 100755 GIT binary patch delta 957 zcmZvaT}V_x6vyZ6-EG}9_d|^9HG^Gi6;X1SXmi>{;Pp5e9MCQZ}Z_|4SC#8qsQd}++YjE}~fHbF)qdxDda*V)7vJ0(W5 z7%gI)MKD&mHgBC>n2lZtm(;vk9JIuO-zPp_tRBhDPTM$;+Pd>?KR;>gwLmw5?LL&@ zlucHyTNz7dcGkN^6cL}_pxFXkvdK`17JCuyvS%t4dS0|t({nV#_F;!zRz`I-?$^Rx zSCg0!YPnEdOkwk#dRR9ugf1E9?Uhi^^Bq-IYjb05?TI4?YeG%flGVMr@)YK^HKlvT=;^KhG!7ufyTXN zL!lW*&h)@xUfl8(;63I?{E*JW5wj6&JaT>jU=2FkOID~Cb{&l=zPLi|E8ymn^yv z5?oLIe&TUr8?ldgi};xM0o~m){2=e^brHZdSa_eKHu#z|NZDX9ILqdGD`g3 km59VQU>wA|nd>XE1XpT*9OTYxelzr7^^gx5FgBF;2QfeOc>n+a delta 896 zcmZ9KUr19?9LLXZcXr*%-K~VWPO-J489q+3W$Y88(5qxT0`w7{!V#SGz zgAh #include #include #include -#include #include "config.h" #include "plugins/plugins.h" @@ -28,13 +28,13 @@ WebKitWebView* notebook_get_webview(GtkNotebook* notebook) /* Load content*/ -void show_bar(GtkNotebook* notebook); +void toggle_bar(GtkNotebook* notebook); void load_uri(WebKitWebView* view, const char* uri) { if (strlen(uri) == 0) { webkit_web_view_load_uri(view, ""); bar.entry_mode = _SEARCH; - show_bar(notebook); + toggle_bar(notebook); } else if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) { webkit_web_view_load_uri(view, uri); @@ -210,17 +210,17 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri) } /* Top bar */ -void show_bar(GtkNotebook* notebook) +void toggle_bar(GtkNotebook* notebook) { - if (bar.entry_mode == _SEARCH) { + switch (bar.entry_mode) { + case _SEARCH: const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook)); gtk_entry_set_placeholder_text(bar.line, "Search"); gtk_entry_buffer_set_text(bar.line_text, url, strlen(url)); gtk_widget_show(GTK_WIDGET(bar.widget)); gtk_window_set_focus(window, GTK_WIDGET(bar.line)); - } else if (bar.entry_mode == _HIDDEN) { - gtk_widget_hide(GTK_WIDGET(bar.widget)); - } else { + break; + case _FIND: const char* search_text = webkit_find_controller_get_search_text( webkit_web_view_get_find_controller(notebook_get_webview(notebook))); @@ -230,6 +230,12 @@ void show_bar(GtkNotebook* notebook) gtk_entry_set_placeholder_text(bar.line, "Find"); gtk_widget_show(GTK_WIDGET(bar.widget)); gtk_window_set_focus(window, GTK_WIDGET(bar.line)); + break; + default: + // fallthrough + case _HIDDEN: + gtk_widget_hide(GTK_WIDGET(bar.widget)); + break; // not needed now, but might reorder } } // Handle what happens when the user is on the bar and presses enter @@ -332,12 +338,12 @@ int handle_shortcut(func id, GtkNotebook* notebook) case show_searchbar: bar.entry_mode = _SEARCH; - show_bar(notebook); + toggle_bar(notebook); break; case show_finder: bar.entry_mode = _FIND; - show_bar(notebook); + toggle_bar(notebook); break; case finder_next: @@ -354,12 +360,12 @@ int handle_shortcut(func id, GtkNotebook* notebook) notebook_create_new_tab(notebook, NULL); gtk_notebook_set_show_tabs(notebook, true); bar.entry_mode = _SEARCH; - show_bar(notebook); + toggle_bar(notebook); break; case hide_bar: bar.entry_mode = _HIDDEN; - show_bar(notebook); + toggle_bar(notebook); break; case prettify: {