[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Gavin D. Smith |
Date: |
Sun, 20 Mar 2022 04:54:59 -0400 (EDT) |
branch: master
commit 35631c19568ff9667737efd227fd01031598157d
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun May 5 20:31:37 2019 +0100
support next prev up keys
---
js/wkinfo/extension.c | 22 ++++++++++-----------
js/wkinfo/main.c | 53 +++++++++++++++++++++++++++++++++------------------
2 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/js/wkinfo/extension.c b/js/wkinfo/extension.c
index b6f082d97d..9f14ca425a 100644
--- a/js/wkinfo/extension.c
+++ b/js/wkinfo/extension.c
@@ -1,3 +1,5 @@
+#define _GNU_SOURCE
+
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
@@ -9,9 +11,6 @@
#include <gtk/gtk.h>
#include <webkit2/webkit-web-extension.h>
-/* Data retrieved from document */
-static char *next_link;
-
/* For communicating with the main Gtk process */
static struct sockaddr_un main_name;
static size_t main_name_size;
@@ -105,9 +104,11 @@ document_loaded_callback (WebKitWebPage *web_page,
}
if (rel && href)
{
- if (!strcmp (rel, "next"))
+ if (!strcmp (rel, "next")
+ || !strcmp (rel, "prev")
+ || !strcmp (rel, "up"))
{
- free (next_link); next_link = 0;
+ char *link = 0;
const char *current_uri = webkit_web_page_get_uri (web_page);
if (current_uri)
@@ -124,16 +125,14 @@ document_loaded_callback (WebKitWebPage *web_page,
}
if (p != current_uri)
{
- next_link = malloc ((p - current_uri)
+ link = malloc ((p - current_uri)
+ strlen (href) + 1);
- memcpy (next_link, current_uri, p - current_uri);
- strcpy (next_link + (p - current_uri), href);
- g_print ("saved ref |%s|\n", next_link);
+ memcpy (link, current_uri, p - current_uri);
+ strcpy (link + (p - current_uri), href);
char *message;
long len;
- len = asprintf (&message, "%s\n%s\n", "next",
- next_link);
+ len = asprintf (&message, "%s\n%s\n", rel, link);
ssize_t result;
result = sendto (socket_id, message, len, 0,
@@ -148,6 +147,7 @@ document_loaded_callback (WebKitWebPage *web_page,
free (message);
}
}
+ free (link);
}
}
g_free (rel); g_free (href);
diff --git a/js/wkinfo/main.c b/js/wkinfo/main.c
index 35a46f6f7e..c73b498352 100644
--- a/js/wkinfo/main.c
+++ b/js/wkinfo/main.c
@@ -11,7 +11,7 @@
#include <gio/gunixsocketaddress.h>
#include <webkit2/webkit2.h>
-static void destroyWindowCb(GtkWidget* widget, GtkWidget* window);
+static void destroyWindowCb(GtkWidget *widget, GtkWidget *window);
static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window);
static gboolean onkeypress(GtkWidget *webView,
GdkEvent *event,
@@ -30,7 +30,7 @@ remove_socket (void)
unlink (socket_file);
}
-static char *next_link;
+static char *next_link, *prev_link, *up_link;
gboolean
socket_cb (GSocket *socket,
@@ -59,15 +59,23 @@ socket_cb (GSocket *socket,
if (!p)
break;
*p = 0;
+
+ char **save_where = 0;
if (!strcmp (buffer, "next"))
+ save_where = &next_link;
+ else if (!strcmp (buffer, "prev"))
+ save_where = &prev_link;
+ else if (!strcmp (buffer, "up"))
+ save_where = &up_link;
+ if (save_where)
{
p++;
q = strchr (p, '\n');
if (!q)
break;
*q = 0;
- free (next_link);
- next_link = strdup (p);
+ free (*save_where);
+ *save_where = strdup (p);
}
else
{
@@ -92,9 +100,6 @@ static void
initialize_web_extensions (WebKitWebContext *context,
gpointer user_data)
{
- /* Web Extensions get a different ID for each Web Process */
- static guint32 unique_id = 0;
-
/* Make a Unix domain socket for communication with the browser process.
Some example code and documentation for WebKitGTK uses dbus instead. */
@@ -174,18 +179,18 @@ int main(int argc, char* argv[])
g_signal_connect(webView, "key_press_event", G_CALLBACK(onkeypress),
main_window);
// Load a web page into the browser instance
- //webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/");
- webkit_web_view_load_uri(webView,
"file:/home/g/src/texinfo/GIT/js/test/hello/index.html");
+ webkit_web_view_load_uri (webView,
+ "file:/home/g/src/texinfo/GIT/js/test/hello/index.html");
// Make sure that when the browser area becomes visible, it will get mouse
// and keyboard events
- gtk_widget_grab_focus(GTK_WIDGET(webView));
+ gtk_widget_grab_focus (GTK_WIDGET(webView));
// Make sure the main window and all its contents are visible
- gtk_widget_show_all(main_window);
+ gtk_widget_show_all (main_window);
// Run the main GTK+ event loop
- gtk_main();
+ gtk_main ();
return 0;
}
@@ -202,8 +207,16 @@ static gboolean onkeypress(GtkWidget *webView,
gtk_main_quit();
break;
case GDK_KEY_n:
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webView),
- next_link);
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW(webView),
+ next_link);
+ break;
+ case GDK_KEY_p:
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW(webView),
+ prev_link);
+ break;
+ case GDK_KEY_u:
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW(webView),
+ up_link);
break;
default:
;
@@ -214,13 +227,15 @@ static gboolean onkeypress(GtkWidget *webView,
}
-static void destroyWindowCb(GtkWidget* widget, GtkWidget* window)
+static void
+destroyWindowCb (GtkWidget *widget, GtkWidget *window)
{
- gtk_main_quit();
+ gtk_main_quit ();
}
-static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window)
+static gboolean
+closeWebViewCb(WebKitWebView *webView, GtkWidget *window)
{
- gtk_widget_destroy(window);
- return TRUE;
+ gtk_widget_destroy (window);
+ return TRUE;
}
- master updated (cd0de30b76 -> ca0de032c7), Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject],
Gavin D. Smith <=
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20