add scroll keybinds, remove ghost webkit process
This commit is contained in:
parent
b132abcd23
commit
40475f9520
5
config.h
5
config.h
|
@ -15,5 +15,8 @@ static Key keys[] = {
|
|||
{ MODKEY, GDK_KEY_e, search },
|
||||
{ MODKEY, GDK_KEY_equal, zoomin },
|
||||
{ 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 }
|
||||
};
|
||||
|
|
|
@ -20,5 +20,7 @@ enum {
|
|||
inspector,
|
||||
search,
|
||||
zoomin,
|
||||
zoomout
|
||||
zoomout,
|
||||
down,
|
||||
up
|
||||
};
|
||||
|
|
4
makefile
4
makefile
|
@ -1,7 +1,7 @@
|
|||
CC = clang
|
||||
CFLAGS = `pkg-config --cflags 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 \
|
||||
-Dcloudproviders=false \
|
||||
-DGTK_DISABLE_DEPRECATED \
|
||||
|
@ -18,7 +18,7 @@ GTKFLAGS = -Dgtk_doc=false -Dintrospection=false \
|
|||
|
||||
|
||||
all:
|
||||
${CC} -fPIC -Os -o rose *.c $(CFLAGS) $(LIBS) $(GTKFLAGS)
|
||||
${CC} -fPIC -O3 -o rose *.c $(CFLAGS) $(LIBS) $(OPTIONS)
|
||||
strip ./rose
|
||||
|
||||
install: all
|
||||
|
|
53
rose.c
53
rose.c
|
@ -5,17 +5,6 @@
|
|||
|
||||
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
|
||||
setatom(int a, const char *v)
|
||||
{
|
||||
|
@ -25,31 +14,6 @@ setatom(int a, const char *v)
|
|||
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 *
|
||||
getatom(int a)
|
||||
{
|
||||
|
@ -74,10 +38,6 @@ getatom(int a)
|
|||
|
||||
static void setup()
|
||||
{
|
||||
GIOChannel *gchanin;
|
||||
|
||||
sigchld(0);
|
||||
|
||||
if (!(dpy = XOpenDisplay(NULL))) {
|
||||
puts("Can't open default display");
|
||||
exit(1);
|
||||
|
@ -87,18 +47,6 @@ static void setup()
|
|||
atoms[AtomGo] = XInternAtom(dpy, "_ROSE_GO", False);
|
||||
atoms[AtomUri] = XInternAtom(dpy, "_ROSE_URI", 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)
|
||||
|
@ -124,4 +72,5 @@ int main(int argc, char **argv)
|
|||
GtkApplication *app = gtk_application_new("org.gtk.rose", G_APPLICATION_NON_UNIQUE);
|
||||
g_signal_connect(app, "activate", G_CALLBACK(run), NULL);
|
||||
g_application_run(G_APPLICATION(app), argc, argv);
|
||||
g_object_unref(app);
|
||||
}
|
||||
|
|
35
window.c
35
window.c
|
@ -1,10 +1,9 @@
|
|||
#include "window.h"
|
||||
#include "rose.h"
|
||||
/* #include "gestures.h" */
|
||||
#include "config.h"
|
||||
#include "webview.h"
|
||||
|
||||
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
||||
#define LENGTH(x) ((int) (sizeof(x) / sizeof(x[0])))
|
||||
|
||||
struct _RoseWindow {
|
||||
GtkApplicationWindow parent_instance;
|
||||
|
@ -12,6 +11,7 @@ struct _RoseWindow {
|
|||
guint xid;
|
||||
GtkWindow *window;
|
||||
WebKitWebView *webview;
|
||||
WebKitWebInspector *inspector;
|
||||
GHashTable *action_groups;
|
||||
GHashTable *action_labels;
|
||||
};
|
||||
|
@ -28,8 +28,7 @@ static void read_clipboard(GObject *object,
|
|||
GAsyncResult *res,
|
||||
gpointer webview)
|
||||
{
|
||||
GdkDisplay *dpy = gdk_display_get_default();
|
||||
GdkClipboard *clipboard = gdk_display_get_clipboard(dpy);
|
||||
GdkClipboard *clipboard = GDK_CLIPBOARD(object);
|
||||
webkit_web_view_load_uri(
|
||||
WEBKIT_WEB_VIEW(webview),
|
||||
gdk_clipboard_read_text_finish(clipboard, res, NULL)
|
||||
|
@ -41,6 +40,8 @@ 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
|
||||
|
@ -95,12 +96,24 @@ static gboolean key_press_callback(RoseWindow *window,
|
|||
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))
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -114,6 +127,11 @@ static void rose_window_init(RoseWindow *window)
|
|||
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)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
rose_webview_load_url(WEBKIT_WEB_VIEW(webview), url);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user