GTK4: Fix bar visiblity shortcuts

This commit is contained in:
NunoSempere 2024-07-20 23:05:45 -04:00
parent 83e80a7dda
commit c716e6b5c5
4 changed files with 53 additions and 12 deletions

View File

@ -3,9 +3,6 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
// #include "/usr/include/gtk-4.0/gtk/gtk.h" // #include "/usr/include/gtk-4.0/gtk/gtk.h"
// GKG 3 or GKG 4
# define GTK_NUM 4
// Key user config // Key user config
#define WIDTH 1920 // 960 for half-width, 1920 for full width #define WIDTH 1920 // 960 for half-width, 1920 for full width
// #define HEIGHT 1080 // #define HEIGHT 1080
@ -14,7 +11,7 @@
#define BAR_SIZE 960 #define BAR_SIZE 960
// More user config // More user config
#define ZOOM_START_LEVEL 1.6 #define ZOOM_START_LEVEL 2
#define ZOOM_STEPSIZE .1 #define ZOOM_STEPSIZE .1
#define MAX_NUM_TABS 8 // 0/false for unlimited tabs #define MAX_NUM_TABS 8 // 0/false for unlimited tabs
#define SEARCH "https://search.brave.com/search?q=%s" // "https://search.nunosempere.com/search?q=%s", "https://lite.duckduckgo.com/html/?q=%s" #define SEARCH "https://search.brave.com/search?q=%s" // "https://search.nunosempere.com/search?q=%s", "https://lite.duckduckgo.com/html/?q=%s"
@ -116,7 +113,7 @@ static struct {
{ CTRL, KEY(w), close_tab }, { CTRL, KEY(w), close_tab },
{ CTRL, KEY(l), show_searchbar }, { CTRL, KEY(l), show_searchbar },
{ CTRL, KEY(semicolon), hide_bar }, { CTRL, KEY(u), hide_bar }, // previously: KEY(semicolon)
{ CTRL, KEY(f), show_finder }, { CTRL, KEY(f), show_finder },
{ CTRL, KEY(n), finder_next }, { CTRL, KEY(n), finder_next },
{ CTRL, KEY(N), finder_prev }, { CTRL, KEY(N), finder_prev },

View File

@ -139,7 +139,7 @@ WebKitWebView* create_new_webview()
webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
if (g_file_get_contents("~/opt/rosenrot/style.css", &style, NULL, NULL)) { if (g_file_get_contents("/opt/rosenrot/style.css", &style, NULL, NULL)) {
webkit_user_content_manager_add_style_sheet( webkit_user_content_manager_add_style_sheet(
contentmanager, webkit_user_style_sheet_new(style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL)); contentmanager, webkit_user_style_sheet_new(style, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL));
} }
@ -181,13 +181,14 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL); int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL);
gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true); gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true);
gtk_widget_set_visible(GTK_WIDGET(window), 1); gtk_widget_set_visible(GTK_WIDGET(window), 1);
// gtk_widget_set_visible(GTK_WIDGET(bar.widget), 0); gtk_widget_set_visible(GTK_WIDGET(bar.widget), 0);
load_uri(view, (uri) ? uri : HOME); load_uri(view, (uri) ? uri : HOME);
set_custom_style(view); set_custom_style(view);
gtk_notebook_set_current_page(notebook, n); gtk_notebook_set_current_page(notebook, n);
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-"); gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-");
webkit_web_view_set_zoom_level(view, ZOOM_START_LEVEL);
num_tabs += 1; num_tabs += 1;
} else { } else {
} }
@ -202,7 +203,7 @@ void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode)
const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook)); const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook));
gtk_entry_set_placeholder_text(bar.line, "Search"); gtk_entry_set_placeholder_text(bar.line, "Search");
gtk_entry_buffer_set_text(bar.line_text, url, strlen(url)); gtk_entry_buffer_set_text(bar.line_text, url, strlen(url));
gtk_widget_show(GTK_WIDGET(bar.widget)); gtk_widget_set_visible(GTK_WIDGET(bar.widget), 1);
gtk_window_set_focus(window, GTK_WIDGET(bar.line)); gtk_window_set_focus(window, GTK_WIDGET(bar.line));
break; break;
} }
@ -214,12 +215,12 @@ void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode)
gtk_entry_buffer_set_text(bar.line_text, search_text, strlen(search_text)); gtk_entry_buffer_set_text(bar.line_text, search_text, strlen(search_text));
gtk_entry_set_placeholder_text(bar.line, "Find"); gtk_entry_set_placeholder_text(bar.line, "Find");
gtk_widget_show(GTK_WIDGET(bar.widget)); gtk_widget_set_visible(GTK_WIDGET(bar.widget), 1);
gtk_window_set_focus(window, GTK_WIDGET(bar.line)); gtk_window_set_focus(window, GTK_WIDGET(bar.line));
break; break;
} }
case _HIDDEN: case _HIDDEN:
gtk_widget_hide(GTK_WIDGET(bar.widget)); gtk_widget_set_visible(GTK_WIDGET(bar.widget), 0);
} }
} }
@ -386,7 +387,9 @@ int main(int argc, char** argv)
g_object_set(gtk_settings_get_default(), GTK_SETTINGS_CONFIG_H, NULL); // https://docs.gtk.org/gobject/method.Object.set.html g_object_set(gtk_settings_get_default(), GTK_SETTINGS_CONFIG_H, NULL); // https://docs.gtk.org/gobject/method.Object.set.html
GtkCssProvider* css = gtk_css_provider_new(); GtkCssProvider* css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, "/opt/rosenrot/style.css"); gtk_css_provider_load_from_path(css, "/opt/rosenrot/style.css");
gtk_style_context_add_provider_for_display(gdk_display_get_default(), GTK_STYLE_PROVIDER(css), 800); /* might change with GTK4/webkitgtk6.0 */ gtk_style_context_add_provider_for_display(gdk_display_get_default(), GTK_STYLE_PROVIDER(css), 0); /* might change with GTK4/webkitgtk6.0 */
printf("%d", GTK_STYLE_PROVIDER_PRIORITY_USER);
printf("%d", GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
// Create the main window // Create the main window
window = GTK_WINDOW(gtk_window_new()); window = GTK_WINDOW(gtk_window_new());
@ -416,6 +419,7 @@ int main(int argc, char** argv)
g_signal_connect_object(event_controller, "key-pressed", G_CALLBACK(handle_signal_keypress), window, G_CONNECT_DEFAULT); g_signal_connect_object(event_controller, "key-pressed", G_CALLBACK(handle_signal_keypress), window, G_CONNECT_DEFAULT);
gtk_widget_add_controller(GTK_WIDGET(window), event_controller); gtk_widget_add_controller(GTK_WIDGET(window), event_controller);
g_signal_connect(window, "destroy", G_CALLBACK(exit), notebook);
// Show the application window // Show the application window
gtk_window_present(window); gtk_window_present(window);
@ -423,7 +427,6 @@ int main(int argc, char** argv)
char* first_uri = argc > 1 ? argv[1] : HOME; char* first_uri = argc > 1 ? argv[1] : HOME;
notebook_create_new_tab(notebook, first_uri); notebook_create_new_tab(notebook, first_uri);
/* Show to user */ /* Show to user */
gtk_widget_set_visible(GTK_WIDGET(window), 1); gtk_widget_set_visible(GTK_WIDGET(window), 1);
if (argc != 0) gtk_widget_set_visible(GTK_WIDGET(bar.widget), 0); if (argc != 0) gtk_widget_set_visible(GTK_WIDGET(bar.widget), 0);

41
style-gtk4.css Normal file
View File

@ -0,0 +1,41 @@
* {
font-size: 25px;
color: #333;
}
/* Make titlebar pretty gigantic. I'm pretty myopic. */
.titlebar {
padding: 5px;
font-size: 30px;
}
.titlebar * {
padding: 5px;
font-size: 27px;
}
header * {
font-size: 20px;
padding: 5px;
}
tabs {
padding: 3px;
}
tab {
margin: 2px 5px 4px 0px; /* top right bottom left */
padding: 5px;
border-style: solid;
font-size: 27px;
}
entry {
padding-left: 10px;
}
entry:focus {
padding-left: 10px;
}