add scroll keybinds, remove ghost webkit process

This commit is contained in:
fenze 2022-05-13 00:45:02 +02:00
parent b132abcd23
commit 40475f9520
5 changed files with 91 additions and 114 deletions

View File

@ -15,5 +15,8 @@ static Key keys[] = {
{ MODKEY, GDK_KEY_e, search }, { MODKEY, GDK_KEY_e, search },
{ MODKEY, GDK_KEY_equal, zoomin }, { MODKEY, GDK_KEY_equal, zoomin },
{ MODKEY, GDK_KEY_minus, zoomout }, { MODKEY, GDK_KEY_minus, zoomout },
{ 0, GDK_KEY_F11, fullscreen }, { MODKEY, GDK_KEY_i, inspector },
{ MODKEY, GDK_KEY_j, down },
{ MODKEY, GDK_KEY_k, up },
{ 0, GDK_KEY_F11, fullscreen }
}; };

View File

@ -20,5 +20,7 @@ enum {
inspector, inspector,
search, search,
zoomin, zoomin,
zoomout zoomout,
down,
up
}; };

View File

@ -1,7 +1,7 @@
CC = clang CC = clang
CFLAGS = `pkg-config --cflags gtk4 webkit2gtk-5.0 x11 ` CFLAGS = `pkg-config --cflags gtk4 webkit2gtk-5.0 x11 `
LIBS = `pkg-config --libs gtk4 webkit2gtk-5.0 x11` LIBS = `pkg-config --libs gtk4 webkit2gtk-5.0 x11`
GTKFLAGS = -Dgtk_doc=false -Dintrospection=false \ OPTIONS = -Dgtk_doc=false -Dintrospection=false \
-DG_DISABLE_CAST_CHECKS \ -DG_DISABLE_CAST_CHECKS \
-Dcloudproviders=false \ -Dcloudproviders=false \
-DGTK_DISABLE_DEPRECATED \ -DGTK_DISABLE_DEPRECATED \
@ -18,7 +18,7 @@ GTKFLAGS = -Dgtk_doc=false -Dintrospection=false \
all: all:
${CC} -fPIC -Os -o rose *.c $(CFLAGS) $(LIBS) $(GTKFLAGS) ${CC} -fPIC -O3 -o rose *.c $(CFLAGS) $(LIBS) $(OPTIONS)
strip ./rose strip ./rose
install: all install: all

53
rose.c
View File

@ -5,17 +5,6 @@
guint xid; guint xid;
void
sigchld(int unused)
{
if (signal(SIGCHLD, sigchld) == SIG_ERR) {
puts("Can't install SIGCHLD handler");
exit(1);
}
while (waitpid(-1, NULL, WNOHANG) > 0)
;
}
void void
setatom(int a, const char *v) setatom(int a, const char *v)
{ {
@ -25,31 +14,6 @@ setatom(int a, const char *v)
XSync(dpy, False); XSync(dpy, False);
} }
static gboolean
readsock(GIOChannel *s, GIOCondition ioc, gpointer unused)
{
static char msg[MSGBUFSZ];
GError *gerr = NULL;
gsize msgsz;
if (g_io_channel_read_chars(s, msg, sizeof(msg), &msgsz, &gerr) !=
G_IO_STATUS_NORMAL) {
if (gerr) {
fprintf(stderr, "surf: error reading socket: %s\n",
gerr->message);
g_error_free(gerr);
}
return TRUE;
}
if (msgsz < 2) {
fprintf(stderr, "surf: message too short: %lu\n", msgsz);
return TRUE;
}
return TRUE;
}
const char * const char *
getatom(int a) getatom(int a)
{ {
@ -74,10 +38,6 @@ getatom(int a)
static void setup() static void setup()
{ {
GIOChannel *gchanin;
sigchld(0);
if (!(dpy = XOpenDisplay(NULL))) { if (!(dpy = XOpenDisplay(NULL))) {
puts("Can't open default display"); puts("Can't open default display");
exit(1); exit(1);
@ -87,18 +47,6 @@ static void setup()
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); atoms[AtomUTF8] = XInternAtom(dpy, "UTF8_STRING", False);
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, spair) < 0) {
fputs("Unable to create sockets\n", stderr);
spair[0] = spair[1] = -1;
} else {
gchanin = g_io_channel_unix_new(spair[0]);
g_io_channel_set_encoding(gchanin, NULL, NULL);
g_io_channel_set_flags(gchanin, g_io_channel_get_flags(gchanin)
| G_IO_FLAG_NONBLOCK, NULL);
g_io_channel_set_close_on_unref(gchanin, TRUE);
g_io_add_watch(gchanin, G_IO_IN, readsock, NULL);
}
} }
static void run(GtkApplication *app) static void run(GtkApplication *app)
@ -124,4 +72,5 @@ int main(int argc, char **argv)
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);
g_application_run(G_APPLICATION(app), argc, argv); g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
} }

View File

@ -1,10 +1,9 @@
#include "window.h" #include "window.h"
#include "rose.h" #include "rose.h"
/* #include "gestures.h" */
#include "config.h" #include "config.h"
#include "webview.h" #include "webview.h"
#define LENGTH(x) (sizeof(x) / sizeof(x[0])) #define LENGTH(x) ((int) (sizeof(x) / sizeof(x[0])))
struct _RoseWindow { struct _RoseWindow {
GtkApplicationWindow parent_instance; GtkApplicationWindow parent_instance;
@ -12,6 +11,7 @@ struct _RoseWindow {
guint xid; guint xid;
GtkWindow *window; GtkWindow *window;
WebKitWebView *webview; WebKitWebView *webview;
WebKitWebInspector *inspector;
GHashTable *action_groups; GHashTable *action_groups;
GHashTable *action_labels; GHashTable *action_labels;
}; };
@ -28,8 +28,7 @@ static void read_clipboard(GObject *object,
GAsyncResult *res, GAsyncResult *res,
gpointer webview) gpointer webview)
{ {
GdkDisplay *dpy = gdk_display_get_default(); GdkClipboard *clipboard = GDK_CLIPBOARD(object);
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
webkit_web_view_load_uri( webkit_web_view_load_uri(
WEBKIT_WEB_VIEW(webview), WEBKIT_WEB_VIEW(webview),
gdk_clipboard_read_text_finish(clipboard, res, NULL) gdk_clipboard_read_text_finish(clipboard, res, NULL)
@ -41,6 +40,8 @@ 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
@ -95,12 +96,24 @@ static gboolean key_press_callback(RoseWindow *window,
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:
window->inspector = webkit_web_view_get_inspector(window->webview);
if (webkit_web_inspector_is_attached(window->inspector))
webkit_web_inspector_close(window->inspector);
else
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;
} }
} }
} }
printf("%i\n", keyval);
puts("");
return GDK_EVENT_PROPAGATE; return GDK_EVENT_PROPAGATE;
} }
@ -114,6 +127,11 @@ static void rose_window_init(RoseWindow *window)
window->window = GTK_WINDOW(gtk_window_new()); window->window = GTK_WINDOW(gtk_window_new());
} }
static void destroy(RoseWindow *window)
{
exit(0);
}
guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url) guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url)
{ {
GtkWidget *w = gtk_application_window_new(app); GtkWidget *w = gtk_application_window_new(app);
@ -125,6 +143,11 @@ guint rose_window_show(GtkApplication *app, RoseWindow *window, const char *url)
gtk_window_set_destroy_with_parent(GTK_WINDOW(w), TRUE); gtk_window_set_destroy_with_parent(GTK_WINDOW(w), TRUE);
window->webview = WEBKIT_WEB_VIEW(webview); window->webview = WEBKIT_WEB_VIEW(webview);
g_signal_connect(G_OBJECT(w), "destroy",
G_CALLBACK(destroy), window);
g_signal_connect(G_OBJECT(window->webview), "web-process-terminated",
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);