From 9660d8f46fe8ab3e2c891b36ba43333378fbeb84 Mon Sep 17 00:00:00 2001 From: fenze Date: Fri, 13 May 2022 18:41:48 +0200 Subject: [PATCH] refreshed config look --- config.h | 55 +++++++++++++++++++++++++++++-------------------------- keyconf.h | 22 ++++++++++++++++++++-- rose.c | 13 ++++++------- webview.c | 18 +++++++++++------- window.c | 8 ++++---- window.h | 3 ++- 6 files changed, 72 insertions(+), 47 deletions(-) diff --git a/config.h b/config.h index 4803bf8..f5f80b5 100644 --- a/config.h +++ b/config.h @@ -1,29 +1,32 @@ -#pragma once #include "keyconf.h" -static const int dark_mode = 1; -// static const char *cachedir = "/home/{user}/.cache/rose/"; -static const char *cachedir = "/home/fenze/.cache/rose/"; -static const char *homepage = "https://duckduckgo.com"; - -#define MODKEY GDK_CONTROL_MASK - -static Key keys[] = { - { MODKEY, GDK_KEY_h, goback }, - { MODKEY, GDK_KEY_l, goforward }, - { MODKEY, GDK_KEY_y, copy_url }, - { MODKEY, GDK_KEY_p, paste_url }, - { MODKEY, GDK_KEY_e, search }, - { MODSHIFT, GDK_KEY_K, zoomin }, - { MODSHIFT, GDK_KEY_J, zoomout }, - { MODSHIFT, GDK_KEY_Q, zoomreset }, - { MODKEY, GDK_KEY_i, inspector }, - { MODKEY, GDK_KEY_j, down }, - { MODKEY, GDK_KEY_k, up }, - { MODKEY, GDK_KEY_f, find }, - { MODKEY, GDK_KEY_n, findnext }, - { MODSHIFT, GDK_KEY_N, findprev }, - { MODKEY, GDK_KEY_r, reload }, - { MODSHIFT, GDK_KEY_R, reloadforce }, - { 0, GDK_KEY_F11, fullscreen } +OPTIONS { + [CACHE] = DEFAULT, + [HOMEPAGE] = DEFAULT, +}; + +APPERANCE { + [HEIGHT] = 600, + [WIDTH] = 800, + [DARKMODE] = true +}; + +KEYBINDS { + { MODKEY, GDK_KEY_h, goback }, + { MODKEY, GDK_KEY_l, goforward }, + { MODKEY, GDK_KEY_y, copy_url }, + { MODKEY, GDK_KEY_p, paste_url }, + { MODKEY, GDK_KEY_e, search }, + { MODSFT, GDK_KEY_K, zoomin }, + { MODSFT, GDK_KEY_J, zoomout }, + { MODSFT, GDK_KEY_Q, zoomreset }, + { MODKEY, GDK_KEY_i, inspector }, + { MODKEY, GDK_KEY_j, down }, + { MODKEY, GDK_KEY_k, up }, + { MODKEY, GDK_KEY_f, find }, + { MODKEY, GDK_KEY_n, findnext }, + { MODSFT, GDK_KEY_N, findprev }, + { MODKEY, GDK_KEY_r, reload }, + { MODSFT, GDK_KEY_R, reloadforce }, + { NOMODK, GDK_KEY_F11, fullscreen } }; diff --git a/keyconf.h b/keyconf.h index c1d303b..b3de8ea 100644 --- a/keyconf.h +++ b/keyconf.h @@ -2,8 +2,25 @@ #include #include +#include -#define MODSHIFT 5 +#define MODKEY GDK_CONTROL_MASK +#define MODSFT 5 +#define NOMODK 0 + +#define CACHE 0 +#define HOMEPAGE 1 + +#define DEFAULT NULL + +#define HEIGHT 0 +#define WIDTH 1 +#define DARKMODE 2 +#define SCROLLBARS 3 + +#define KEYBINDS static Key keys[] = +#define APPERANCE static int appearance[] = +#define OPTIONS static char *options[] = typedef struct { unsigned modkey; @@ -28,5 +45,6 @@ enum { down, up, reload, - reloadforce + reloadforce, + LAST_FUNC }; diff --git a/rose.c b/rose.c index ad8fbf5..53055ee 100644 --- a/rose.c +++ b/rose.c @@ -44,28 +44,27 @@ static void setup() atoms[AtomFind] = XInternAtom(dpy, "_ROSE_FIND", False); atoms[AtomGo] = XInternAtom(dpy, "_ROSE_GO", False); atoms[AtomUri] = XInternAtom(dpy, "_ROSE_URI", False); - atoms[AtomUTF8] = XInternAtom(dpy, "UTF8_STRING", False); } static void run(GtkApplication *app) { RoseWindow *window = rose_window_new(app); - if (dark_mode) { + if (appearance[DARKMODE]) g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", true, NULL); - } - xid = rose_window_show(app, window, homepage); - setatom(AtomUri, homepage); + if (!options[HOMEPAGE]) + options[HOMEPAGE] = "https://duckduckgo.com"; + + xid = rose_window_show(app, window, options[HOMEPAGE]); } int main(int argc, char **argv) { if (argc == 2) { - homepage = argv[1]; + options[HOMEPAGE] = argv[1]; argv++; argc--; } - setup(); GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_NON_UNIQUE); g_signal_connect(app, "activate", G_CALLBACK(run), NULL); diff --git a/webview.c b/webview.c index eb811ed..bb976df 100644 --- a/webview.c +++ b/webview.c @@ -1,5 +1,4 @@ #include "webview.h" -#include "config.h" struct _RoseWebView { WebKitWebView parent_instance; @@ -143,7 +142,7 @@ static void rose_download_callback(WebKitWebContext *context, GtkWidget* rose_webview_new() { - char cookiefile[64]; + char cookiefile[128]; WebKitWebView *webview; WebKitCookieManager *cookiemanager; WebKitUserContentManager *contentmanager; @@ -160,10 +159,17 @@ GtkWidget* rose_webview_new() "hardware-acceleration-policy", WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS, "javascript-can-access-clipboard", TRUE, NULL); + if (!options[CACHE]) { + const char *HOME = getenv("HOME"); + char *buf = calloc(1, sizeof(char) * (strlen(HOME) + 32) + 1); + sprintf(buf, "%s/.cache/rose/", HOME); + options[CACHE] = buf; + } + WebKitWebContext *context = webkit_web_context_new_with_website_data_manager( webkit_website_data_manager_new( - "base-cache-directory", cachedir, - "base-data-directory", cachedir, + "base-cache-directory", options[CACHE], + "base-data-directory", options[CACHE], NULL)); webkit_settings_set_user_agent_with_application_details( @@ -173,7 +179,7 @@ GtkWidget* rose_webview_new() contentmanager = webkit_user_content_manager_new(); cookiemanager = webkit_web_context_get_cookie_manager(context); - strcpy(cookiefile, cachedir); + strcpy(cookiefile, options[CACHE]); strcat(cookiefile, "cookies"); webkit_cookie_manager_set_persistent_storage(cookiemanager, @@ -181,7 +187,6 @@ GtkWidget* rose_webview_new() webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - g_signal_connect(G_OBJECT(context), "download-started", G_CALLBACK(rose_download_callback), NULL); @@ -190,5 +195,4 @@ GtkWidget* rose_webview_new() "settings", settings, "user-content-manager", contentmanager, "web-context", context, NULL); - } diff --git a/window.c b/window.c index 2328f8c..8fb401e 100644 --- a/window.c +++ b/window.c @@ -1,7 +1,4 @@ #include "window.h" -#include "rose.h" -#include "config.h" -#include "webview.h" #define LENGTH(x) ((int) (sizeof(x) / sizeof(x[0]))) @@ -205,8 +202,11 @@ guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url) g_signal_connect(G_OBJECT(window->webview), "web-process-terminated", G_CALLBACK(destroy), window); - if (url) + if (url) { rose_webview_load_url(WEBKIT_WEB_VIEW(webview), url); + } + + gtk_window_set_default_size(GTK_WINDOW(w), appearance[WIDTH], appearance[HEIGHT]); gtk_window_set_child(GTK_WINDOW(w), GTK_WIDGET(webview)); diff --git a/window.h b/window.h index 0463c0f..33e29f6 100644 --- a/window.h +++ b/window.h @@ -1,8 +1,9 @@ #pragma once +#include "rose.h" + #include #include -#include "webview.h" G_BEGIN_DECLS