Skip to content

Commit

Permalink
Merge pull request #1335 from xiota/pr-markdown-webkit2gtk-4.1
Browse files Browse the repository at this point in the history
Markdown: Add support for webkit2gtk-4.1
  • Loading branch information
b4n committed Apr 25, 2024
2 parents d851fac + a0e8192 commit 2b897dc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 48 deletions.
16 changes: 11 additions & 5 deletions build/markdown.m4
Expand Up @@ -46,16 +46,22 @@ AC_DEFUN([GP_CHECK_MARKDOWN],
[markdown_library=libmarkdown])
GP_STATUS_FEATURE_ADD([Markdown library], [$markdown_library])
GTK_VERSION=2.16
WEBKIT_VERSION=1.1.13
GTK_VERSION=3.0
WEBKIT_VERSION=2.30
dnl Support both webkit2gtk 4.0 and 4.1, as the only difference is the
dnl libsoup version in the API, which we don't use.
dnl Prefer the 4.1 version, but use the 4.0 version as fallback if
dnl available -- yet still ask for the 4.1 if neither are available
webkit_package=webkit2gtk-4.1
PKG_CHECK_EXISTS([${webkit_package} >= ${WEBKIT_VERSION}],,
[PKG_CHECK_EXISTS([webkit2gtk-4.0 >= ${WEBKIT_VERSION}],
[webkit_package=webkit2gtk-4.0])])
GP_CHECK_GTK3([webkit_package=webkit2gtk-4.0],
[webkit_package=webkit-1.0])
GP_CHECK_PLUGIN_DEPS([markdown], [MARKDOWN],
[$GP_GTK_PACKAGE >= ${GTK_VERSION}
$webkit_package >= ${WEBKIT_VERSION}
gthread-2.0])
AM_CONDITIONAL([MARKDOWN_WEBKIT2], [test "$webkit_package" = webkit2gtk-4.0])
GP_COMMIT_PLUGIN_STATUS([Markdown])
Expand Down
4 changes: 2 additions & 2 deletions markdown/README
Expand Up @@ -146,8 +146,8 @@ Requirements

The plugin depends on the following libraries:

* `GTK+ <http://www.gtk.org>`_ 2.16 or greater
* `WebKitGTK+ <http://webkitgtk.org>`_ 1.1.18 or greater
* `GTK+ <http://www.gtk.org>`_ 3.0 or greater
* `WebKitGTK+ <http://webkitgtk.org>`_ API 4.0 or 4.1

License
-------
Expand Down
4 changes: 0 additions & 4 deletions markdown/src/Makefile.am
Expand Up @@ -35,8 +35,4 @@ markdown_la_CFLAGS += $(LIBMARKDOWN_CFLAGS)
markdown_la_LIBADD += $(LIBMARKDOWN_LIBS)
endif

if MARKDOWN_WEBKIT2
markdown_la_CFLAGS += -DMARKDOWN_WEBKIT2
endif

include $(top_srcdir)/build/cppcheck.mk
33 changes: 1 addition & 32 deletions markdown/src/viewer.c
Expand Up @@ -22,11 +22,7 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#ifdef MARKDOWN_WEBKIT2
# include <webkit2/webkit2.h>
#else
# include <webkit/webkitwebview.h>
#endif
#include <webkit2/webkit2.h>
#include <geanyplugin.h>
#ifndef FULL_PRICE
# include <mkdio.h>
Expand Down Expand Up @@ -303,7 +299,6 @@ pop_scroll_pos(MarkdownViewer *self)
return popped;
}

#ifdef MARKDOWN_WEBKIT2
static void
on_webview_load_changed(MarkdownViewer *self,
WebKitLoadEvent load_event,
Expand All @@ -314,21 +309,6 @@ on_webview_load_changed(MarkdownViewer *self,
pop_scroll_pos(self);
}
}
#else
static void
on_webview_load_status_notify(WebKitWebView *view, GParamSpec *pspec,
MarkdownViewer *self)
{
WebKitLoadStatus load_status;

g_object_get(view, "load-status", &load_status, NULL);

/* When the webkit is done loading, reset the scroll position. */
if (load_status == WEBKIT_LOAD_FINISHED) {
pop_scroll_pos(self);
}
}
#endif

gchar *
markdown_viewer_get_html(MarkdownViewer *self)
Expand Down Expand Up @@ -408,23 +388,12 @@ markdown_viewer_update_view(MarkdownViewer *self)
/* Connect a signal handler (only needed once) to restore the scroll
* position once the webview is reloaded. */
if (self->priv->load_handle == 0) {
#ifdef MARKDOWN_WEBKIT2
self->priv->load_handle =
g_signal_connect_swapped(WEBKIT_WEB_VIEW(self), "load-changed",
G_CALLBACK(on_webview_load_changed), self);
#else
self->priv->load_handle =
g_signal_connect_swapped(WEBKIT_WEB_VIEW(self), "notify::load-status",
G_CALLBACK(on_webview_load_status_notify), self);
#endif
}

#ifdef MARKDOWN_WEBKIT2
webkit_web_view_load_html(WEBKIT_WEB_VIEW(self), html, base_uri);
#else
webkit_web_view_load_string(WEBKIT_WEB_VIEW(self), html, "text/html",
self->priv->enc, base_uri);
#endif

g_free(base_uri);
g_free(html);
Expand Down
6 changes: 1 addition & 5 deletions markdown/src/viewer.h
Expand Up @@ -23,11 +23,7 @@
#define MARKDOWN_VIEWER_H 1

#include <gtk/gtk.h>
#ifdef MARKDOWN_WEBKIT2
# include <webkit2/webkit2.h>
#else
# include <webkit/webkitwebview.h>
#endif
#include <webkit2/webkit2.h>

G_BEGIN_DECLS

Expand Down

0 comments on commit 2b897dc

Please sign in to comment.