GTK4: fix duplicate loading error when opening new tabs

This commit is contained in:
NunoSempere 2024-07-21 14:54:32 -04:00
parent e03b6cc447
commit db9d3e66f2
4 changed files with 92 additions and 91 deletions

View File

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define STYLE_N 8049 + 1000 #define STYLE_N 7877 + 1000
void read_style_js(char* string) void read_style_js(char* string)
{ {

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#define STYLE_N 8049 + 1000 #define STYLE_N 7877 + 1000
void read_style_js(char* string); void read_style_js(char* string);

View File

@ -166,13 +166,14 @@ GtkWidget* handle_signal_create_new_tab(WebKitWebView* self,
if (num_tabs < MAX_NUM_TABS || num_tabs == 0) { if (num_tabs < MAX_NUM_TABS || num_tabs == 0) {
WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action); WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action);
const char* uri = webkit_uri_request_get_uri(uri_request); const char* uri = webkit_uri_request_get_uri(uri_request);
webkit_web_view_stop_loading(self);
printf("Creating new window: %s\n", uri); printf("Creating new window: %s\n", uri);
notebook_create_new_tab(notebook, uri); notebook_create_new_tab(notebook, uri);
gtk_notebook_set_show_tabs(notebook, true); gtk_notebook_set_show_tabs(notebook, true);
} else { } else {
webkit_web_view_evaluate_javascript(self, "alert('Too many tabs, not opening a new one')", -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL); webkit_web_view_evaluate_javascript(self, "alert('Too many tabs, not opening a new one')", -1, NULL, "rosenrot-alert-numtabs", NULL, NULL, NULL);
} }
return GTK_WIDGET(self); // or NULL return NULL; // Could also return GTK_WIDGET(self), in which case the new uri would also be loaded in the current webview.
} }
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri) void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)