added find keybinds
This commit is contained in:
parent
40475f9520
commit
9eb0c2207f
3
config.h
3
config.h
|
@ -18,5 +18,8 @@ static Key keys[] = {
|
||||||
{ 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_n, findnext },
|
||||||
|
{ MODSHIFT, GDK_KEY_N, findprev },
|
||||||
{ 0, GDK_KEY_F11, fullscreen }
|
{ 0, GDK_KEY_F11, fullscreen }
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
|
||||||
#define SHIFT GDK_SHIFT_MASK
|
#define MODSHIFT 5
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned modkey;
|
unsigned modkey;
|
||||||
|
@ -19,6 +19,9 @@ enum {
|
||||||
fullscreen,
|
fullscreen,
|
||||||
inspector,
|
inspector,
|
||||||
search,
|
search,
|
||||||
|
find,
|
||||||
|
findnext,
|
||||||
|
findprev,
|
||||||
zoomin,
|
zoomin,
|
||||||
zoomout,
|
zoomout,
|
||||||
down,
|
down,
|
||||||
|
|
6
makefile
6
makefile
|
@ -1,6 +1,6 @@
|
||||||
CC = clang
|
CC = clang
|
||||||
CFLAGS = `pkg-config --cflags 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`
|
LIBS = `pkg-config --libs gtk4 webkit2gtk-5.0 x11 gstreamer-gl-1.0`
|
||||||
OPTIONS = -Dgtk_doc=false -Dintrospection=false \
|
OPTIONS = -Dgtk_doc=false -Dintrospection=false \
|
||||||
-DG_DISABLE_CAST_CHECKS \
|
-DG_DISABLE_CAST_CHECKS \
|
||||||
-Dcloudproviders=false \
|
-Dcloudproviders=false \
|
||||||
|
@ -22,7 +22,7 @@ all:
|
||||||
strip ./rose
|
strip ./rose
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
cp -uf ./rose /usr/local/bin/rose
|
su -c "cp -uf ./rose /usr/local/bin/rose"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f rose compile_flags.txt
|
rm -f rose compile_flags.txt
|
||||||
|
|
6
rose.c
6
rose.c
|
@ -5,8 +5,7 @@
|
||||||
|
|
||||||
guint xid;
|
guint xid;
|
||||||
|
|
||||||
void
|
void setatom(int a, const char *v)
|
||||||
setatom(int a, const char *v)
|
|
||||||
{
|
{
|
||||||
XChangeProperty(dpy, xid,
|
XChangeProperty(dpy, xid,
|
||||||
atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
|
atoms[a], atoms[AtomUTF8], 8, PropModeReplace,
|
||||||
|
@ -14,8 +13,7 @@ setatom(int a, const char *v)
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char* getatom(int a)
|
||||||
getatom(int a)
|
|
||||||
{
|
{
|
||||||
static char buf[BUFSIZ];
|
static char buf[BUFSIZ];
|
||||||
Atom adummy;
|
Atom adummy;
|
||||||
|
|
1
rose.h
1
rose.h
|
@ -19,4 +19,5 @@ enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast };
|
||||||
static Atom atoms[AtomLast];
|
static Atom atoms[AtomLast];
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
const char* getatom(int a);
|
const char* getatom(int a);
|
||||||
|
void setatom(int a, const char *v);
|
||||||
static int spair[2];
|
static int spair[2];
|
||||||
|
|
|
@ -104,6 +104,7 @@ static void rose_webview_init(RoseWebView *webview)
|
||||||
void rose_webview_load_url(WebKitWebView *webview, const char *url)
|
void rose_webview_load_url(WebKitWebView *webview, const char *url)
|
||||||
{
|
{
|
||||||
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url);
|
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), url);
|
||||||
|
setatom(AtomUri, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget* rose_webview_new()
|
GtkWidget* rose_webview_new()
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "rose.h"
|
||||||
|
|
||||||
#include <webkit2/webkit2.h>
|
#include <webkit2/webkit2.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
|
|
52
window.c
52
window.c
|
@ -12,6 +12,7 @@ struct _RoseWindow {
|
||||||
GtkWindow *window;
|
GtkWindow *window;
|
||||||
WebKitWebView *webview;
|
WebKitWebView *webview;
|
||||||
WebKitWebInspector *inspector;
|
WebKitWebInspector *inspector;
|
||||||
|
WebKitFindOptions *findopts;
|
||||||
GHashTable *action_groups;
|
GHashTable *action_groups;
|
||||||
GHashTable *action_labels;
|
GHashTable *action_labels;
|
||||||
};
|
};
|
||||||
|
@ -40,9 +41,6 @@ static gboolean key_press_callback(RoseWindow *window,
|
||||||
guint keycode,
|
guint keycode,
|
||||||
GdkModifierType state)
|
GdkModifierType state)
|
||||||
{
|
{
|
||||||
if (!state)
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
|
|
||||||
for (int i = 0; i < LENGTH(keys); i++) {
|
for (int i = 0; i < LENGTH(keys); i++) {
|
||||||
if (keys[i].modkey == state
|
if (keys[i].modkey == state
|
||||||
&& keys[i].keycod == keyval) {
|
&& keys[i].keycod == keyval) {
|
||||||
|
@ -50,9 +48,11 @@ static gboolean key_press_callback(RoseWindow *window,
|
||||||
case goback:
|
case goback:
|
||||||
webkit_web_view_go_back(window->webview);
|
webkit_web_view_go_back(window->webview);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case goforward:
|
case goforward:
|
||||||
webkit_web_view_go_forward(window->webview);
|
webkit_web_view_go_forward(window->webview);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case copy_url: {
|
case copy_url: {
|
||||||
GdkDisplay *dpy = gdk_display_get_default();
|
GdkDisplay *dpy = gdk_display_get_default();
|
||||||
gdk_clipboard_set_text(
|
gdk_clipboard_set_text(
|
||||||
|
@ -60,17 +60,20 @@ static gboolean key_press_callback(RoseWindow *window,
|
||||||
webkit_web_view_get_uri(window->webview)
|
webkit_web_view_get_uri(window->webview)
|
||||||
);
|
);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case paste_url: {
|
case paste_url: {
|
||||||
GdkDisplay *dpy = gdk_display_get_default();
|
GdkDisplay *dpy = gdk_display_get_default();
|
||||||
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
||||||
gdk_clipboard_read_text_async(clipboard, NULL, read_clipboard, window->webview);
|
gdk_clipboard_read_text_async(clipboard, NULL, read_clipboard, window->webview);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case fullscreen:
|
case fullscreen:
|
||||||
if (gtk_window_is_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview)))))
|
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))));
|
gtk_window_unfullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
|
||||||
else
|
else
|
||||||
gtk_window_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
|
gtk_window_fullscreen(GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(window->webview))));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case search: {
|
case search: {
|
||||||
int id = fork();
|
int id = fork();
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
|
@ -79,23 +82,59 @@ static gboolean key_press_callback(RoseWindow *window,
|
||||||
close(spair[0]);
|
close(spair[0]);
|
||||||
close(spair[1]);
|
close(spair[1]);
|
||||||
setsid();
|
setsid();
|
||||||
char* argument_list[] = { "/bin/sh", "-c", "surf-open", NULL};
|
char* argument_list[] = { "/bin/sh", "-c", "dmenu_rose", NULL};
|
||||||
execvp("/bin/sh", argument_list);
|
execvp("/bin/sh", argument_list);
|
||||||
perror(" failed");
|
perror(" failed");
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
wait(&id);
|
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:
|
case zoomin:
|
||||||
zoom += 0.1;
|
zoom += 0.1;
|
||||||
webkit_web_view_set_zoom_level(window->webview, zoom);
|
webkit_web_view_set_zoom_level(window->webview, zoom);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case zoomout:
|
case zoomout:
|
||||||
zoom -= 0.1;
|
zoom -= 0.1;
|
||||||
webkit_web_view_set_zoom_level(window->webview, zoom);
|
webkit_web_view_set_zoom_level(window->webview, zoom);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case inspector:
|
case inspector:
|
||||||
window->inspector = webkit_web_view_get_inspector(window->webview);
|
window->inspector = webkit_web_view_get_inspector(window->webview);
|
||||||
if (webkit_web_inspector_is_attached(window->inspector))
|
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);
|
webkit_web_inspector_show(window->inspector);
|
||||||
return GDK_EVENT_STOP;
|
return GDK_EVENT_STOP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case up:
|
case up:
|
||||||
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,-100);", NULL, NULL, NULL);
|
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,-100);", NULL, NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case down:
|
case down:
|
||||||
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,100);", NULL, NULL, NULL);
|
webkit_web_view_run_javascript(window->webview, "window.scrollBy(0,100);", NULL, NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
@ -114,6 +155,7 @@ static gboolean key_press_callback(RoseWindow *window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
return GDK_EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user