added find keybinds

This commit is contained in:
fenze 2022-05-13 12:30:15 +02:00
parent 40475f9520
commit 9eb0c2207f
8 changed files with 64 additions and 14 deletions

View File

@ -18,5 +18,8 @@ static Key keys[] = {
{ 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 },
{ 0, GDK_KEY_F11, fullscreen }
};

View File

@ -3,7 +3,7 @@
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#define SHIFT GDK_SHIFT_MASK
#define MODSHIFT 5
typedef struct {
unsigned modkey;
@ -19,6 +19,9 @@ enum {
fullscreen,
inspector,
search,
find,
findnext,
findprev,
zoomin,
zoomout,
down,

View File

@ -1,6 +1,6 @@
CC = clang
CFLAGS = `pkg-config --cflags gtk4 webkit2gtk-5.0 x11 `
LIBS = `pkg-config --libs gtk4 webkit2gtk-5.0 x11`
CFLAGS = `pkg-config --cflags gtk4 webkit2gtk-5.0 x11 gstreamer-gl-1.0`
LIBS = `pkg-config --libs gtk4 webkit2gtk-5.0 x11 gstreamer-gl-1.0`
OPTIONS = -Dgtk_doc=false -Dintrospection=false \
-DG_DISABLE_CAST_CHECKS \
-Dcloudproviders=false \
@ -22,7 +22,7 @@ all:
strip ./rose
install: all
cp -uf ./rose /usr/local/bin/rose
su -c "cp -uf ./rose /usr/local/bin/rose"
clean:
rm -f rose compile_flags.txt

6
rose.c
View File

@ -5,8 +5,7 @@
guint xid;
void
setatom(int a, const char *v)
void setatom(int a, const char *v)
{
XChangeProperty(dpy, xid,
atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
@ -14,8 +13,7 @@ setatom(int a, const char *v)
XSync(dpy, False);
}
const char *
getatom(int a)
const char* getatom(int a)
{
static char buf[BUFSIZ];
Atom adummy;

1
rose.h
View File

@ -19,4 +19,5 @@ enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast };
static Atom atoms[AtomLast];
static Display *dpy;
const char* getatom(int a);
void setatom(int a, const char *v);
static int spair[2];

View File

@ -104,6 +104,7 @@ static void rose_webview_init(RoseWebView *webview)
void rose_webview_load_url(WebKitWebView *webview, const char *url)
{
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url);
setatom(AtomUri, url);
}
GtkWidget* rose_webview_new()

View File

@ -1,5 +1,7 @@
#pragma once
#include "rose.h"
#include <webkit2/webkit2.h>
#include <gdk/gdk.h>

View File

@ -12,6 +12,7 @@ struct _RoseWindow {
GtkWindow *window;
WebKitWebView *webview;
WebKitWebInspector *inspector;
WebKitFindOptions *findopts;
GHashTable *action_groups;
GHashTable *action_labels;
};
@ -40,9 +41,6 @@ static gboolean key_press_callback(RoseWindow *window,
guint keycode,
GdkModifierType state)
{
if (!state)
return GDK_EVENT_PROPAGATE;
for (int i = 0; i < LENGTH(keys); i++) {
if (keys[i].modkey == state
&& keys[i].keycod == keyval) {
@ -50,9 +48,11 @@ static gboolean key_press_callback(RoseWindow *window,
case goback:
webkit_web_view_go_back(window->webview);
break;
case goforward:
webkit_web_view_go_forward(window->webview);
break;
case copy_url: {
GdkDisplay *dpy = gdk_display_get_default();
gdk_clipboard_set_text(
@ -60,17 +60,20 @@ static gboolean key_press_callback(RoseWindow *window,
webkit_web_view_get_uri(window->webview)
);
} break;
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, window->webview);
} break;
case fullscreen:
if (gtk_window_is_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview)))))
gtk_window_unfullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
else
gtk_window_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
break;
case search: {
int id = fork();
if (id == 0) {
@ -79,23 +82,59 @@ static gboolean key_press_callback(RoseWindow *window,
close(spair[0]);
close(spair[1]);
setsid();
char* argument_list[] = { "/bin/sh", "-c", "surf-open", NULL};
char* argument_list[] = { "/bin/sh", "-c", "dmenu_rose", NULL};
execvp("/bin/sh", argument_list);
perror(" failed");
exit(1);
} else {
wait(&id);
webkit_web_view_load_uri(window->webview, getatom(AtomGo));
rose_webview_load_url(window->webview, getatom(AtomGo));
}
}
} break;
case find: {
int id = fork();
if (id == 0) {
if (dpy)
close(ConnectionNumber(dpy));
close(spair[0]);
close(spair[1]);
setsid();
char* argument_list[] = { "/bin/sh", "-c", "dmenu_rose\tfind", NULL};
execvp("/bin/sh", argument_list);
perror(" failed");
exit(1);
} else {
wait(&id);
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview);
webkit_find_controller_search(
finder,
getatom(AtomFind),
WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
WEBKIT_FIND_OPTIONS_WRAP_AROUND, G_MAXUINT);
}
} break;
case findnext: {
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview);
webkit_find_controller_search_next(finder);
} break;
case findprev: {
WebKitFindController *finder = webkit_web_view_get_find_controller(window->webview);
webkit_find_controller_search_previous(finder);
} break;
case zoomin:
zoom += 0.1;
webkit_web_view_set_zoom_level(window->webview, zoom);
break;
case zoomout:
zoom -= 0.1;
webkit_web_view_set_zoom_level(window->webview, zoom);
break;
case inspector:
window->inspector = webkit_web_view_get_inspector(window->webview);
if (webkit_web_inspector_is_attached(window->inspector))
@ -104,9 +143,11 @@ static gboolean key_press_callback(RoseWindow *window,
webkit_web_inspector_show(window->inspector);
return GDK_EVENT_STOP;
break;
case up:
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,-100);", NULL, NULL, NULL);
break;
case down:
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,100);", NULL, NULL, NULL);
break;
@ -114,6 +155,7 @@ static gboolean key_press_callback(RoseWindow *window,
}
}
return GDK_EVENT_PROPAGATE;
}