X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=libsurf-webext.c;h=684d4a5db4c03f11e264465390ff1c64ca332181;hp=6c3deb72c6224174a958c1f86583f4c6b86568a2;hb=660413256f4c1cc916e6f96b9156a4f5a85dfcc4;hpb=7ea0c2f7f8c5cc4616d8dc0676f7b4b59351667b diff --git a/libsurf-webext.c b/libsurf-webext.c index 6c3deb7..684d4a5 100644 --- a/libsurf-webext.c +++ b/libsurf-webext.c @@ -8,14 +8,13 @@ #include #include -#define LENGTH(x) (sizeof(x) / sizeof(x[0])) +#include "common.h" -#define MSGBUFSZ 32 +#define LENGTH(x) (sizeof(x) / sizeof(x[0])) typedef struct Page { guint64 id; WebKitWebPage *webpage; - WebKitDOMDOMWindow *view; struct Page *next; } Page; @@ -63,6 +62,7 @@ readpipe(GIOChannel *s, GIOCondition c, gpointer unused) { char msg[MSGBUFSZ]; gsize msgsz; + WebKitDOMDOMWindow *view; GError *gerr = NULL; glong wh, ww; Page *p; @@ -80,18 +80,19 @@ readpipe(GIOChannel *s, GIOCondition c, gpointer unused) if (p->id == msg[0]) break; } - if (!p || !p->view) + if (!p || !(view = webkit_dom_document_get_default_view( + webkit_web_page_get_dom_document(p->webpage)))) return TRUE; switch (msg[1]) { case 'h': - ww = webkit_dom_dom_window_get_inner_width(p->view); - webkit_dom_dom_window_scroll_by(p->view, + ww = webkit_dom_dom_window_get_inner_width(view); + webkit_dom_dom_window_scroll_by(view, (ww / 100) * msg[2], 0); break; case 'v': - wh = webkit_dom_dom_window_get_inner_height(p->view); - webkit_dom_dom_window_scroll_by(p->view, + wh = webkit_dom_dom_window_get_inner_height(view); + webkit_dom_dom_window_scroll_by(view, 0, (wh / 100) * msg[2]); break; } @@ -99,19 +100,10 @@ readpipe(GIOChannel *s, GIOCondition c, gpointer unused) return TRUE; } -static void -documentloaded(WebKitWebPage *wp, Page *p) -{ - p->view = webkit_dom_document_get_default_view( - webkit_web_page_get_dom_document(wp)); -} - static void webpagecreated(WebKitWebExtension *e, WebKitWebPage *wp, gpointer unused) { Page *p = newpage(wp); - - g_signal_connect(wp, "document-loaded", G_CALLBACK(documentloaded), p); } G_MODULE_EXPORT void