simplify link references

This commit is contained in:
NunoSempere 2024-03-24 07:45:21 -04:00
parent 70849e74d6
commit 0c282697bc
2 changed files with 32 additions and 52 deletions

View File

@ -1,25 +1,17 @@
#include <stdbool.h> #include <stdbool.h>
#include <gdk/gdk.h> #include <gdk/gdk.h> // <gdk/gdkenums.h>, <gdk/gdkkeysyms.h>
// Previously: #include <gdk/gdkkeysyms.h>
// But GTK3 discourages including the individual headers
// In GTK4, the location also changes to <gdk/gdkenums.h>
// 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
#define BAR_SIZE 1000 #define BAR_SIZE 960
// More user config // More user config
#define ZOOM 1.6 /* Starting zoom level.*/ #define ZOOM_START_LEVEL 1.6
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */ #define ZOOM_STEPSIZE .1
#define MAX_NUM_TABS 8 // set to 0 or false if you want unlimited tabs, or look at the relevant rose.c code. #define MAX_NUM_TABS 8 // 0/false for unlimited tabs
#define SEARCH "https://search.brave.com/search?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"
// #define SEARCH "https://search.nunosempere.com/search?q=%s" #define HOME "https://search.brave.com/search" // "file:///opt/rose/homepage.png", ""
// #define SEARCH "https://lite.duckduckgo.com/html/?q=%s"
#define HOME "https://search.brave.com/search"
// ^ Could also be a website ("https://search.nunosempere.com"), or a file ("file:///opt/rose/homepage.png")
// #define HOME "https://search.nunosempere.com/"
// #define HOME "file:///opt/rosenrot/rose.png"
// Plugins // Plugins
#define LIBRE_REDIRECT_ENABLED true #define LIBRE_REDIRECT_ENABLED true
@ -29,35 +21,33 @@
/* /*
To disable plugins: To disable plugins:
1. set their corresponding variable to false 1. set their corresponding variable to false
2. you could also look into this file at commit afe93518a for an approach using stand-in code. 2. recompile
3. recompile
To remove plugins completely; To remove plugins completely;
1. Remove the corresponding code in the rosenrot.c by looking for the variables above. 1. Remove the corresponding code in rosenrot.c by looking for the variables above.
2. Remove PLUGIN and $(PLUGIN) from the makefile 2. Remove PLUGIN and $(PLUGIN) from the makefile
3. Recompile 3. Recompile
You could also look into commit afe93518a for an approach using stand-in code.
*/ */
// Webkit settings // Webkit settings
// See: https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html // https://webkitgtk.org/reference/webkit2gtk/stable/class.Settings.html
#define WEBKIT_DEFAULT_SETTINGS \ #define WEBKIT_DEFAULT_SETTINGS \
"enable-back-forward-navigation-gestures", true, "enable-developer-extras", true, \ "enable-back-forward-navigation-gestures", true, "enable-developer-extras", true, \
"enable-smooth-scrolling", false, \ "enable-smooth-scrolling", false, \
"default-charset", "utf-8" "default-charset", "utf-8"
/* CACHE */
#define DATA_DIR "/home/nuno/.cache/rosenrot" #define DATA_DIR "/home/nuno/.cache/rosenrot"
#define DATA_MANAGER_OPTS "base-cache-directory", DATA_DIR, "base-data-directory", DATA_DIR #define DATA_MANAGER_OPTS "base-cache-directory", DATA_DIR, "base-data-directory", DATA_DIR
// GTK // GTK
#define GTK_SETTINGS_CONFIG_H "gtk-application-prefer-dark-theme", false, "gtk-enable-animations", false #define GTK_SETTINGS_CONFIG_H "gtk-application-prefer-dark-theme", false, "gtk-enable-animations", false
// https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/gdkkeysyms.h
#define KEY(x) GDK_KEY_##x #define KEY(x) GDK_KEY_##x
/* // https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/gdkenums.h
There are two different constants for Page_Up/Page_Down: #define SFT 1 << 0
This could possibly have something to so with having Page_Down/Page_Up #define CTRL 1 << 2
as part of a keypad with/without NumLock #define ALT 1 << 3
See: https://docs.gtk.org/gdk3/?q=Page_Up
See: https://docs.gtk.org/gdk3/?q=GDK_KEY_KP
*/
// Shortcuts // Shortcuts
typedef enum { typedef enum {
@ -82,10 +72,6 @@ typedef enum {
hide_bar hide_bar
} func; } func;
#define SFT 1 << 0
#define CTRL 1 << 2
#define ALT 1 << 3
// reference: <https://github.com/GNOME/gtk/blob/7ea7d5c3906ccd231b04654101bb742f157d82f6/gdk/gdkenums.h#L140>
static struct { static struct {
unsigned mod; unsigned mod;
@ -112,9 +98,6 @@ static struct {
{ CTRL, KEY(N), finder_prev }, { CTRL, KEY(N), finder_prev },
{ CTRL, KEY(p), prettify } { CTRL, KEY(p), prettify }
}; };
/* ^ For controls more akin to normal browsers */
/* Reference for the key shorthand:
* <https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/gdkkeysyms.h> */
/* Old controls: { /* Old controls: {
{ CTRL, KEY(h), goback }, { CTRL, KEY(h), goback },
@ -137,4 +120,3 @@ static struct {
{ CTRL, KEY(p), prettify } { CTRL, KEY(p), prettify }
}; };
*/ */

View File

@ -18,7 +18,7 @@ static struct {
} bar; } bar;
static int num_tabs = 0; static int num_tabs = 0;
// Forward declarations /* Forward declarations */
void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode); void toggle_bar(GtkNotebook* notebook, Bar_entry_mode mode);
void notebook_create_new_tab(GtkNotebook* notebook, const char* uri); void notebook_create_new_tab(GtkNotebook* notebook, const char* uri);
@ -29,7 +29,6 @@ WebKitWebView* notebook_get_webview(GtkNotebook* notebook)
} }
/* Load content*/ /* Load content*/
void load_uri(WebKitWebView* view, const char* uri) void load_uri(WebKitWebView* view, const char* uri)
{ {
if (strlen(uri) == 0) { if (strlen(uri) == 0) {
@ -83,7 +82,7 @@ void handle_signal_load_changed(WebKitWebView* self, WebKitLoadEvent load_event,
GtkNotebook* notebook) GtkNotebook* notebook)
{ {
switch (load_event) { switch (load_event) {
// see <https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html> // https://webkitgtk.org/reference/webkit2gtk/2.5.1/WebKitWebView.html
case WEBKIT_LOAD_STARTED: case WEBKIT_LOAD_STARTED:
case WEBKIT_LOAD_COMMITTED: case WEBKIT_LOAD_COMMITTED:
set_custom_style(self); set_custom_style(self);
@ -106,7 +105,6 @@ void handle_signal_load_changed(WebKitWebView* self, WebKitLoadEvent load_event,
} }
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self), gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self),
webpage_title == NULL ? "" : tab_title); webpage_title == NULL ? "" : tab_title);
// gtk_widget_hide(GTK_WIDGET(bar));
} }
} }
} }
@ -147,8 +145,8 @@ WebKitWebView* create_new_webview()
webkit_settings_set_user_agent( webkit_settings_set_user_agent(
settings, settings,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, " "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, "
"like Gecko) Chrome/110.0.0.0 Safari/537.36"); "like Gecko) Chrome/120.0.0.0 Safari/537.3");
// See: <https://www.useragents.me/> for some common user agents // https://www.useragents.me
} }
web_context = webkit_web_context_new_with_website_data_manager(webkit_website_data_manager_new(DATA_MANAGER_OPTS, NULL)); web_context = webkit_web_context_new_with_website_data_manager(webkit_website_data_manager_new(DATA_MANAGER_OPTS, NULL));
contentmanager = webkit_user_content_manager_new(); contentmanager = webkit_user_content_manager_new();
@ -158,7 +156,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("~/.config/rose/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));
} }
@ -183,7 +181,7 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
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); webkit_web_view_set_zoom_level(view, ZOOM_START_LEVEL);
num_tabs += 1; num_tabs += 1;
} else { } else {
webkit_web_view_evaluate_javascript(notebook_get_webview(notebook), "alert('Too many tabs, not opening a new one')", webkit_web_view_evaluate_javascript(notebook_get_webview(notebook), "alert('Too many tabs, not opening a new one')",
@ -240,7 +238,7 @@ void handle_signal_bar_press_enter(GtkEntry* self, GtkNotebook* notebook)
// Act when a particular shortcut is detected // Act when a particular shortcut is detected
int handle_shortcut(func id, GtkNotebook* notebook) int handle_shortcut(func id, GtkNotebook* notebook)
{ {
static double zoom = ZOOM; static double zoom = ZOOM_START_LEVEL;
static bool is_fullscreen = 0; static bool is_fullscreen = 0;
WebKitWebView* view = notebook_get_webview(notebook); WebKitWebView* view = notebook_get_webview(notebook);
@ -266,19 +264,19 @@ int handle_shortcut(func id, GtkNotebook* notebook)
case zoomin: case zoomin:
webkit_web_view_set_zoom_level(view, webkit_web_view_set_zoom_level(view,
(zoom += ZOOM_VAL)); (zoom += ZOOM_STEPSIZE));
break; break;
case zoomout: case zoomout:
webkit_web_view_set_zoom_level(view, webkit_web_view_set_zoom_level(view,
(zoom -= ZOOM_VAL)); (zoom -= ZOOM_STEPSIZE));
break; break;
case zoom_reset: case zoom_reset:
webkit_web_view_set_zoom_level(view, webkit_web_view_set_zoom_level(view,
(zoom = ZOOM)); (zoom = ZOOM_START_LEVEL));
break; break;
case prev_tab:; // declarations aren't statements case prev_tab:; // declarations aren't statements
// <https://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement> // https://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement
int n = gtk_notebook_get_n_pages(notebook); int n = gtk_notebook_get_n_pages(notebook);
int k = gtk_notebook_get_current_page(notebook); int k = gtk_notebook_get_current_page(notebook);
int l = (n + k - 1) % n; int l = (n + k - 1) % n;
@ -372,8 +370,8 @@ int handle_signal_keypress(void* self, GdkEvent* event, GtkNotebook* notebook)
If I wanted to bind button presses, like the extra button in the mouse, If I wanted to bind button presses, like the extra button in the mouse,
I would have to bind the button-press-event signal instead. I would have to bind the button-press-event signal instead.
Some links in case I go down that road: Some links in case I go down that road:
- <https://docs.gtk.org/gtk3/signal.Widget.button-press-event.html> - https://docs.gtk.org/gtk3/signal.Widget.button-press-event.html
- <https://docs.gtk.org/gdk3/union.Event.html> - https://docs.gtk.org/gdk3/union.Event.html
- https://docs.gtk.org/gdk3/struct.EventButton.html - https://docs.gtk.org/gdk3/struct.EventButton.html
*/ */
// This API is deprecated in GTK4 :( // This API is deprecated in GTK4 :(
@ -383,8 +381,8 @@ int handle_signal_keypress(void* self, GdkEvent* event, GtkNotebook* notebook)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
/* Initialize GTK in general */ /* Initialize GTK in general */
gtk_init(NULL, NULL); // <https://docs.gtk.org/gtk3/func.init.html> gtk_init(NULL, NULL); // https://docs.gtk.org/gtk3/func.init.html
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", NULL); gtk_css_provider_load_from_path(css, "/opt/rosenrot/style.css", NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), 800); gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), 800);