aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rosenrot.c119
1 files changed, 6 insertions, 113 deletions
diff --git a/rosenrot.c b/rosenrot.c
index efe95c1..11e0092 100644
--- a/rosenrot.c
+++ b/rosenrot.c
@@ -6,14 +6,11 @@
// User config
#define WIDTH 1920 // 960 for half-width, 1920 for full width
#define HEIGHT 1080
-#define BAR_SIZE 1000
-#define SEARCH "https://lite.duckduckgo.com/html/?q=%s"
#define HOME "https://lite.duckduckgo.com/html"
// Minimal niceties
#define ZOOM 1 /* Starting zoom level.*/
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
-#define MAX_NUM_TABS 8
// Webkit settings
// See: https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html
@@ -23,7 +20,7 @@
"default-charset", "utf-8"
/* CACHE */
-#define DATA_DIR "/home/nuno/.cache/rosenrot"
+#define DATA_DIR "/home/doc/.cache/rosenrot"
#define DATA_MANAGER_OPTS "base-cache-directory", DATA_DIR, "base-data-directory", DATA_DIR
// GTK
@@ -36,15 +33,6 @@
/* Global declarations */
static GtkNotebook* notebook;
static GtkWindow* window;
-static struct {
- GtkHeaderBar* widget;
- GtkEntry* line;
- GtkEntryBuffer* line_text;
- enum { _SEARCH,
- _FIND,
- _HIDDEN } entry_mode;
-} bar;
-static int num_tabs = 0;
// Forward declarations
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri);
@@ -63,10 +51,6 @@ void load_uri(WebKitWebView* view, const char* uri)
webkit_web_view_load_uri(view, "");
} 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);
- } else {
- char tmp[strlen(uri) + strlen(SEARCH)];
- snprintf(tmp, sizeof(tmp), SEARCH, uri);
- webkit_web_view_load_uri(view, tmp);
}
}
@@ -99,14 +83,10 @@ GtkWidget* handle_signal_create_new_tab(WebKitWebView* self,
WebKitNavigationAction* navigation_action,
GtkNotebook* notebook)
{
- if (num_tabs < MAX_NUM_TABS || num_tabs == 0) {
- WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action);
- const char* uri = webkit_uri_request_get_uri(uri_request);
- notebook_create_new_tab(notebook, uri);
- gtk_notebook_set_show_tabs(notebook, 1);
- } else {
- webkit_web_view_evaluate_javascript(self, "alert('Too many tabs, not opening a new one')", -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
- }
+ WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action);
+ const char* uri = webkit_uri_request_get_uri(uri_request);
+ notebook_create_new_tab(notebook, uri);
+ gtk_notebook_set_show_tabs(notebook, 1);
return NULL;
/*
WebKitGTK documentation recommends returning the new webview.
@@ -136,7 +116,6 @@ WebKitWebView* create_new_webview()
}
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
{
- if (num_tabs < MAX_NUM_TABS || MAX_NUM_TABS == 0) {
WebKitWebView* view = create_new_webview();
g_signal_connect(view, "load_changed", G_CALLBACK(handle_signal_load_changed), notebook);
@@ -150,24 +129,6 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
gtk_notebook_set_current_page(notebook, n);
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-");
webkit_web_view_set_zoom_level(view, ZOOM);
- num_tabs += 1;
- } else {
- webkit_web_view_evaluate_javascript(notebook_get_webview(notebook), "alert('Too many tabs, not opening a new one')",
- -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
- }
-}
-
-// Handle what happens when the user is on the bar and presses enter
-void handle_signal_bar_press_enter(GtkEntry* self, GtkNotebook* notebook)
-{
- if (bar.entry_mode == _SEARCH)
- load_uri(notebook_get_webview(notebook), gtk_entry_buffer_get_text(bar.line_text));
- else if (bar.entry_mode == _FIND)
- webkit_find_controller_search(
- webkit_web_view_get_find_controller(notebook_get_webview(notebook)),
- gtk_entry_buffer_get_text(bar.line_text),
- WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND,
- G_MAXUINT);
}
/* Handle shortcuts */
@@ -189,7 +150,7 @@ int handle_signal_keypress(void* self, GdkEvent* event, GtkNotebook* notebook)
case KEY(h): // go back
webkit_web_view_go_back(view);
break;
- case KEY(j): // go forward
+ case KEY(l): // go forward
webkit_web_view_go_forward(view);
break;
case KEY(r): // reload
@@ -210,55 +171,6 @@ int handle_signal_keypress(void* self, GdkEvent* event, GtkNotebook* notebook)
case KEY(0): // restore zoom
webkit_web_view_set_zoom_level(view, (zoom = ZOOM));
break;
- case KEY(KP_Page_Up): {
- int n = gtk_notebook_get_n_pages(notebook);
- int k = gtk_notebook_get_current_page(notebook);
- int l = (n + k - 1) % n;
- gtk_notebook_set_current_page(notebook, l);
- break;
- } // previous tab
- case KEY(KP_Page_Down): { // next tab
- int m = gtk_notebook_get_n_pages(notebook);
- int i = gtk_notebook_get_current_page(notebook);
- int j = (i + 1) % m;
- gtk_notebook_set_current_page(notebook, j);
- break;
- }
- case KEY(w): // close tab
- gtk_notebook_remove_page(notebook, gtk_notebook_get_current_page(notebook));
- num_tabs -= 1;
- if (gtk_notebook_get_n_pages(notebook) == 0) {
- exit(0);
- }
- break;
- case KEY(l): // show search bar
- case KEY(semicolon): { // fallthrough; same
- bar.entry_mode = _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));
- break;
- }
- case KEY(f): { // find
- bar.entry_mode = _FIND;
- const char* search_text = webkit_find_controller_get_search_text(webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
- if (search_text != NULL) gtk_entry_buffer_set_text(bar.line_text, search_text, strlen(search_text));
-
- gtk_entry_set_placeholder_text(bar.line, "Find");
- gtk_window_set_focus(window, GTK_WIDGET(bar.line));
- break;
- } break;
- case KEY(n): // find next
- webkit_find_controller_search_next(webkit_web_view_get_find_controller(view));
- break;
- case KEY(N): // find previous
- webkit_find_controller_search_previous(webkit_web_view_get_find_controller(view));
- break;
- case KEY(t): // new tab
- notebook_create_new_tab(notebook, NULL);
- break;
}
} else if (event_state == 0x0 && event_keyval == KEY(F11)) {
if (is_fullscreen)
@@ -290,31 +202,12 @@ int main(int argc, char** argv)
g_signal_connect(window, "destroy", G_CALLBACK(exit), notebook);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(notebook));
- // Bar
- bar.line_text = GTK_ENTRY_BUFFER(gtk_entry_buffer_new("", 0));
- bar.line = GTK_ENTRY(gtk_entry_new_with_buffer(bar.line_text));
- gtk_entry_set_alignment(bar.line, 0.48);
- gtk_widget_set_size_request(GTK_WIDGET(bar.line), BAR_SIZE, -1);
- g_signal_connect(bar.line, "activate", G_CALLBACK(handle_signal_bar_press_enter), notebook);
-
- bar.widget = GTK_HEADER_BAR(gtk_header_bar_new());
- gtk_header_bar_set_custom_title(bar.widget, GTK_WIDGET(bar.line));
- gtk_window_set_titlebar(window, GTK_WIDGET(bar.widget));
-
/* Load first tab */
char* first_uri = argc > 1 ? argv[1] : HOME;
notebook_create_new_tab(notebook, first_uri);
/* Show to user */
gtk_widget_show_all(GTK_WIDGET(window));
- gtk_notebook_set_show_tabs(notebook, 1);
-
- /* Deal with more tabs */
- if (argc > 2) {
- for (int i = 2; i < argc; i++) {
- notebook_create_new_tab(notebook, argv[i]);
- }
- }
gtk_main();
}