refreshed config look

This commit is contained in:
fenze 2022-05-13 18:41:48 +02:00
parent 0bf51a097a
commit 9660d8f46f
6 changed files with 72 additions and 47 deletions

View File

@ -1,29 +1,32 @@
#pragma once
#include "keyconf.h" #include "keyconf.h"
static const int dark_mode = 1; OPTIONS {
// static const char *cachedir = "/home/{user}/.cache/rose/"; [CACHE] = DEFAULT,
static const char *cachedir = "/home/fenze/.cache/rose/"; [HOMEPAGE] = DEFAULT,
static const char *homepage = "https://duckduckgo.com"; };
#define MODKEY GDK_CONTROL_MASK APPERANCE {
[HEIGHT] = 600,
[WIDTH] = 800,
[DARKMODE] = true
};
static Key keys[] = { KEYBINDS {
{ MODKEY, GDK_KEY_h, goback }, { MODKEY, GDK_KEY_h, goback },
{ MODKEY, GDK_KEY_l, goforward }, { MODKEY, GDK_KEY_l, goforward },
{ MODKEY, GDK_KEY_y, copy_url }, { MODKEY, GDK_KEY_y, copy_url },
{ MODKEY, GDK_KEY_p, paste_url }, { MODKEY, GDK_KEY_p, paste_url },
{ MODKEY, GDK_KEY_e, search }, { MODKEY, GDK_KEY_e, search },
{ MODSHIFT, GDK_KEY_K, zoomin }, { MODSFT, GDK_KEY_K, zoomin },
{ MODSHIFT, GDK_KEY_J, zoomout }, { MODSFT, GDK_KEY_J, zoomout },
{ MODSHIFT, GDK_KEY_Q, zoomreset }, { MODSFT, GDK_KEY_Q, zoomreset },
{ MODKEY, GDK_KEY_i, inspector }, { MODKEY, GDK_KEY_i, inspector },
{ MODKEY, GDK_KEY_j, down }, { MODKEY, GDK_KEY_j, down },
{ MODKEY, GDK_KEY_k, up }, { MODKEY, GDK_KEY_k, up },
{ MODKEY, GDK_KEY_f, find }, { MODKEY, GDK_KEY_f, find },
{ MODKEY, GDK_KEY_n, findnext }, { MODKEY, GDK_KEY_n, findnext },
{ MODSHIFT, GDK_KEY_N, findprev }, { MODSFT, GDK_KEY_N, findprev },
{ MODKEY, GDK_KEY_r, reload }, { MODKEY, GDK_KEY_r, reload },
{ MODSHIFT, GDK_KEY_R, reloadforce }, { MODSFT, GDK_KEY_R, reloadforce },
{ 0, GDK_KEY_F11, fullscreen } { NOMODK, GDK_KEY_F11, fullscreen }
}; };

View File

@ -2,8 +2,25 @@
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <stdbool.h>
#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 { typedef struct {
unsigned modkey; unsigned modkey;
@ -28,5 +45,6 @@ enum {
down, down,
up, up,
reload, reload,
reloadforce reloadforce,
LAST_FUNC
}; };

13
rose.c
View File

@ -44,28 +44,27 @@ static void setup()
atoms[AtomFind] = XInternAtom(dpy, "_ROSE_FIND", False); atoms[AtomFind] = XInternAtom(dpy, "_ROSE_FIND", False);
atoms[AtomGo] = XInternAtom(dpy, "_ROSE_GO", False); atoms[AtomGo] = XInternAtom(dpy, "_ROSE_GO", False);
atoms[AtomUri] = XInternAtom(dpy, "_ROSE_URI", False); atoms[AtomUri] = XInternAtom(dpy, "_ROSE_URI", False);
atoms[AtomUTF8] = XInternAtom(dpy, "UTF8_STRING", False);
} }
static void run(GtkApplication *app) static void run(GtkApplication *app)
{ {
RoseWindow *window = rose_window_new(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); g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", true, NULL);
}
xid = rose_window_show(app, window, homepage); if (!options[HOMEPAGE])
setatom(AtomUri, homepage); options[HOMEPAGE] = "https://duckduckgo.com";
xid = rose_window_show(app, window, options[HOMEPAGE]);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc == 2) { if (argc == 2) {
homepage = argv[1]; options[HOMEPAGE] = argv[1];
argv++; argc--; argv++; argc--;
} }
setup(); setup();
GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_NON_UNIQUE); GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_NON_UNIQUE);
g_signal_connect(app, "activate", G_CALLBACK(run), NULL); g_signal_connect(app, "activate", G_CALLBACK(run), NULL);

View File

@ -1,5 +1,4 @@
#include "webview.h" #include "webview.h"
#include "config.h"
struct _RoseWebView { struct _RoseWebView {
WebKitWebView parent_instance; WebKitWebView parent_instance;
@ -143,7 +142,7 @@ static void rose_download_callback(WebKitWebContext *context,
GtkWidget* rose_webview_new() GtkWidget* rose_webview_new()
{ {
char cookiefile[64]; char cookiefile[128];
WebKitWebView *webview; WebKitWebView *webview;
WebKitCookieManager *cookiemanager; WebKitCookieManager *cookiemanager;
WebKitUserContentManager *contentmanager; WebKitUserContentManager *contentmanager;
@ -160,10 +159,17 @@ GtkWidget* rose_webview_new()
"hardware-acceleration-policy", WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS, "hardware-acceleration-policy", WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS,
"javascript-can-access-clipboard", TRUE, NULL); "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( WebKitWebContext *context = webkit_web_context_new_with_website_data_manager(
webkit_website_data_manager_new( webkit_website_data_manager_new(
"base-cache-directory", cachedir, "base-cache-directory", options[CACHE],
"base-data-directory", cachedir, "base-data-directory", options[CACHE],
NULL)); NULL));
webkit_settings_set_user_agent_with_application_details( webkit_settings_set_user_agent_with_application_details(
@ -173,7 +179,7 @@ GtkWidget* rose_webview_new()
contentmanager = webkit_user_content_manager_new(); contentmanager = webkit_user_content_manager_new();
cookiemanager = webkit_web_context_get_cookie_manager(context); cookiemanager = webkit_web_context_get_cookie_manager(context);
strcpy(cookiefile, cachedir); strcpy(cookiefile, options[CACHE]);
strcat(cookiefile, "cookies"); strcat(cookiefile, "cookies");
webkit_cookie_manager_set_persistent_storage(cookiemanager, 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); webkit_cookie_manager_set_accept_policy(cookiemanager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
g_signal_connect(G_OBJECT(context), "download-started", g_signal_connect(G_OBJECT(context), "download-started",
G_CALLBACK(rose_download_callback), NULL); G_CALLBACK(rose_download_callback), NULL);
@ -190,5 +195,4 @@ GtkWidget* rose_webview_new()
"settings", settings, "settings", settings,
"user-content-manager", contentmanager, "user-content-manager", contentmanager,
"web-context", context, NULL); "web-context", context, NULL);
} }

View File

@ -1,7 +1,4 @@
#include "window.h" #include "window.h"
#include "rose.h"
#include "config.h"
#include "webview.h"
#define LENGTH(x) ((int) (sizeof(x) / sizeof(x[0]))) #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_signal_connect(G_OBJECT(window->webview), "web-process-terminated",
G_CALLBACK(destroy), window); G_CALLBACK(destroy), window);
if (url) if (url) {
rose_webview_load_url(WEBKIT_WEB_VIEW(webview), 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)); gtk_window_set_child(GTK_WINDOW(w), GTK_WIDGET(webview));

View File

@ -1,8 +1,9 @@
#pragma once #pragma once
#include "rose.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/x11/gdkx.h> #include <gdk/x11/gdkx.h>
#include "webview.h"
G_BEGIN_DECLS G_BEGIN_DECLS