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
|
#pragma once
|
||||||
|
#include "keyconf.h"
|
||||||
|
|
||||||
static const char *cachedir = "/home/fenze/.cache/rose/";
|
|
||||||
static const int dark_mode = 1;
|
static const int dark_mode = 1;
|
||||||
|
static const char *cachedir = "/home/fenze/.cache/rose/";
|
||||||
static const char *homepage = "https://duckduckgo.com";
|
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) {
|
if (dark_mode) {
|
||||||
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);
|
||||||
|
GdkRGBA color = { 0, 0, 0, 1 };
|
||||||
|
webkit_web_view_get_background_color(WEBKIT_WEB_VIEW(webview), &color);
|
||||||
}
|
}
|
||||||
|
|
||||||
rose_window_set_webview(window, webview);
|
rose_window_set_webview(window, webview);
|
||||||
|
@ -23,6 +25,11 @@ static void run(GtkApplication *app)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
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);
|
GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_FLAGS_NONE);
|
||||||
g_signal_connect(app, "activate", G_CALLBACK(run), NULL);
|
g_signal_connect(app, "activate", G_CALLBACK(run), NULL);
|
||||||
g_application_run(G_APPLICATION(app), argc, argv);
|
g_application_run(G_APPLICATION(app), argc, argv);
|
||||||
|
|
42
window.c
42
window.c
|
@ -3,6 +3,8 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
|
|
||||||
|
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
||||||
|
|
||||||
struct _RoseWindow {
|
struct _RoseWindow {
|
||||||
GtkApplicationWindow parent_instance;
|
GtkApplicationWindow parent_instance;
|
||||||
|
|
||||||
|
@ -19,26 +21,50 @@ enum {
|
||||||
|
|
||||||
G_DEFINE_TYPE(RoseWindow, rose_window, GTK_TYPE_APPLICATION_WINDOW)
|
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,
|
static gboolean key_press_callback(WebKitWebView *webview,
|
||||||
guint keyval,
|
guint keyval,
|
||||||
guint keycode,
|
guint keycode,
|
||||||
GdkModifierType state)
|
GdkModifierType state)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (state & GDK_CONTROL_MASK) {
|
if (state & GDK_CONTROL_MASK) {
|
||||||
switch (keycode) {
|
for (int i = 0; i < LENGTH(keys); i++) {
|
||||||
case 43: {
|
if (keys[i].modkey == GDK_CONTROL_MASK
|
||||||
|
&& keys[i].keycod == keyval) {
|
||||||
|
switch (keys[i].funcid) {
|
||||||
|
case goback:
|
||||||
webkit_web_view_go_back(webview);
|
webkit_web_view_go_back(webview);
|
||||||
} break;
|
break;
|
||||||
case 46: {
|
case goforward:
|
||||||
webkit_web_view_go_forward(webview);
|
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;
|
} break;
|
||||||
case 26: {
|
case paste_url: {
|
||||||
rose_webview_load_url(webview, homepage);
|
GdkDisplay *dpy = gdk_display_get_default();
|
||||||
|
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
||||||
|
gdk_clipboard_read_text_async(clipboard, NULL, read_clipboard, webview);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return GDK_EVENT_PROPAGATE;
|
return GDK_EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user