logo

badwolf

Unnamed repository; edit this file 'description' to name the repository.
commit: a222202081ba70dc8569001a975cef6e5d6791b5
parent: f56f4baec44e58038d751d8043fe4e8e25248fa1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat,  9 Mar 2019 06:25:43 +0100

badwolf.c: Add searching

A better UI/UX design will probably need to be done, but it works for now.

Default GTK bindings are:
- next-match: Ctrl-G
- previous-match: Ctrl-Shift-G
- stop-search: Escape

Diffstat:

Mbadwolf.c51+++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+), 0 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -14,6 +14,7 @@ struct Client GtkWidget *toolbar; GtkWidget *javascript; GtkWidget *location; + GtkWidget *search; GtkWidget *statusbar; WebKitWebView *webView; @@ -143,6 +144,49 @@ static gboolean javascriptCb_toggled(GtkButton *javascript, gpointer user_data) return TRUE; } + +static gboolean SearchEntryCb_next__match(GtkSearchEntry *search, gpointer user_data) +{ + (void)search; + struct Client *browser = (struct Client *)user_data; + WebKitFindController *findController = webkit_web_view_get_find_controller(browser->webView); + + webkit_find_controller_search_next(findController); + + return TRUE; +} + +static gboolean SearchEntryCb_previous__match(GtkSearchEntry *search, gpointer user_data) +{ + (void)search; + struct Client *browser = (struct Client *)user_data; + WebKitFindController *findController = webkit_web_view_get_find_controller(browser->webView); + + webkit_find_controller_search_next(findController); + + return TRUE; +} + +static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer user_data) { + struct Client *browser = (struct Client *)user_data; + WebKitFindController *findController = webkit_web_view_get_find_controller(browser->webView); + const gchar *search_text = gtk_entry_get_text(GTK_ENTRY(search)); + + webkit_find_controller_search(findController, search_text, 0, 0); + + return TRUE; +} + +static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data) { + (void)search; + struct Client *browser = (struct Client *)user_data; + WebKitFindController *findController = webkit_web_view_get_find_controller(browser->webView); + + webkit_find_controller_search_finish(findController); + + return TRUE; +} + int main(int argc, char *argv[]) { struct Client *browser = malloc(sizeof(struct Client)); @@ -156,6 +200,7 @@ int main(int argc, char *argv[]) browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); browser->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); browser->location = gtk_entry_new(); + browser->search = gtk_search_entry_new(); browser->javascript = gtk_check_button_new(); browser->statusbar = gtk_label_new(NULL); browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); @@ -164,6 +209,7 @@ int main(int argc, char *argv[]) gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->javascript), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->location), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->search), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->toolbar), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->webView), TRUE, TRUE, 0); @@ -198,6 +244,11 @@ int main(int argc, char *argv[]) G_CALLBACK(WebViewCb_notify__estimated_load_progress), browser); + g_signal_connect(browser->search, "next-match", G_CALLBACK(SearchEntryCb_next__match), browser); + g_signal_connect(browser->search, "previous-match", G_CALLBACK(SearchEntryCb_previous__match), browser); + g_signal_connect(browser->search, "search-changed", G_CALLBACK(SearchEntryCb_search__changed), browser); + g_signal_connect(browser->search, "stop-search", G_CALLBACK(SearchEntryCb_stop__search), browser); + WebKitSettings *settings = webkit_web_view_get_settings(browser->webView); webkit_settings_set_default_charset(settings, "utf-8");