Provide config for keybinds
This commit is contained in:
parent
e189704eb5
commit
da36745e98
12
config.h
12
config.h
|
@ -1,5 +1,15 @@
|
|||
#pragma once
|
||||
#include "keyconf.h"
|
||||
|
||||
static const char *cachedir = "/home/fenze/.cache/rose/";
|
||||
static const int dark_mode = 1;
|
||||
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 }
|
||||
};
|
||||
|
|
17
keyconf.h
Normal file
17
keyconf.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
typedef struct {
|
||||
unsigned modkey;
|
||||
unsigned keycod;
|
||||
unsigned funcid;
|
||||
} Key;
|
||||
|
||||
enum {
|
||||
goback,
|
||||
goforward,
|
||||
copy_url,
|
||||
paste_url
|
||||
};
|
7
rose.c
7
rose.c
|
@ -12,6 +12,8 @@ static void run(GtkApplication *app)
|
|||
|
||||
if (dark_mode) {
|
||||
g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", true, NULL);
|
||||
GdkRGBA color = { 0, 0, 0, 1 };
|
||||
webkit_web_view_get_background_color(WEBKIT_WEB_VIEW(webview), &color);
|
||||
}
|
||||
|
||||
rose_window_set_webview(window, webview);
|
||||
|
@ -23,6 +25,11 @@ static void run(GtkApplication *app)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 2) {
|
||||
homepage = argv[1];
|
||||
argv++; argc--;
|
||||
}
|
||||
|
||||
GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_FLAGS_NONE);
|
||||
g_signal_connect(app, "activate", G_CALLBACK(run), NULL);
|
||||
g_application_run(G_APPLICATION(app), argc, argv);
|
||||
|
|
42
window.c
42
window.c
|
@ -3,6 +3,8 @@
|
|||
#include "config.h"
|
||||
#include "webview.h"
|
||||
|
||||
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
struct _RoseWindow {
|
||||
GtkApplicationWindow parent_instance;
|
||||
|
||||
|
@ -19,26 +21,50 @@ enum {
|
|||
|
||||
G_DEFINE_TYPE(RoseWindow, rose_window, GTK_TYPE_APPLICATION_WINDOW)
|
||||
|
||||
static void read_clipboard(GObject *object,
|
||||
GAsyncResult *res,
|
||||
gpointer webview)
|
||||
{
|
||||
GdkDisplay *dpy = gdk_display_get_default();
|
||||
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
||||
webkit_web_view_load_uri(
|
||||
WEBKIT_WEB_VIEW(webview),
|
||||
gdk_clipboard_read_text_finish(clipboard, res, NULL)
|
||||
);
|
||||
}
|
||||
|
||||
static gboolean key_press_callback(WebKitWebView *webview,
|
||||
guint keyval,
|
||||
guint keycode,
|
||||
GdkModifierType state)
|
||||
{
|
||||
|
||||
if (state & GDK_CONTROL_MASK) {
|
||||
switch (keycode) {
|
||||
case 43: {
|
||||
for (int i = 0; i < LENGTH(keys); i++) {
|
||||
if (keys[i].modkey == GDK_CONTROL_MASK
|
||||
&& keys[i].keycod == keyval) {
|
||||
switch (keys[i].funcid) {
|
||||
case goback:
|
||||
webkit_web_view_go_back(webview);
|
||||
} break;
|
||||
case 46: {
|
||||
break;
|
||||
case goforward:
|
||||
webkit_web_view_go_forward(webview);
|
||||
break;
|
||||
case copy_url: {
|
||||
GdkDisplay *dpy = gdk_display_get_default();
|
||||
gdk_clipboard_set_text(
|
||||
gdk_display_get_clipboard(dpy),
|
||||
webkit_web_view_get_uri(webview)
|
||||
);
|
||||
} break;
|
||||
case 26: {
|
||||
rose_webview_load_url(webview, homepage);
|
||||
case paste_url: {
|
||||
GdkDisplay *dpy = gdk_display_get_default();
|
||||
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
||||
gdk_clipboard_read_text_async(clipboard, NULL, read_clipboard, webview);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user