From 4fb64a41f4d74e3de672f984fa2617e54ad68d2a Mon Sep 17 00:00:00 2001 From: Burt P Date: Sat, 13 Jul 2019 11:58:28 -0500 Subject: uri_handler functions from sysobj This allows link clicks to be intercepted so that they might be used by the application internally before falling back to the system uri handler. I've also found the default GTK label link handler to be unreliable outside of GNOME Shell, and this will use xdg-open instead. Signed-off-by: Burt P --- deps/sysobj_early/gui/uri_handler.c | 48 +++++++++++++++++++++++++++++++++++++ deps/sysobj_early/gui/uri_handler.h | 32 +++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 deps/sysobj_early/gui/uri_handler.c create mode 100644 deps/sysobj_early/gui/uri_handler.h (limited to 'deps/sysobj_early') diff --git a/deps/sysobj_early/gui/uri_handler.c b/deps/sysobj_early/gui/uri_handler.c new file mode 100644 index 00000000..055dbaca --- /dev/null +++ b/deps/sysobj_early/gui/uri_handler.c @@ -0,0 +1,48 @@ +/* + * sysobj - https://github.com/bp0/verbose-spork + * Copyright (C) 2018 Burt P. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include "uri_handler.h" + +static uri_handler uri_func = NULL; + +void uri_set_function(uri_handler f) { + uri_func = f; +} + +gboolean uri_open(const gchar *uri) { + gboolean ret = FALSE; + if (uri_func) + ret = uri_func(uri); + if (ret) return TRUE; + + return uri_open_default(uri); +} + +gboolean uri_open_default(const gchar *uri) { + gchar *argv[] = { "/usr/bin/xdg-open", (gchar*)uri, NULL }; + GError *err = NULL; + g_spawn_async(NULL, argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, &err ); + if (err) { + fprintf(stderr, "Error opening URI %s: %s\n", uri, err->message); + g_error_free(err); + } + return TRUE; +} diff --git a/deps/sysobj_early/gui/uri_handler.h b/deps/sysobj_early/gui/uri_handler.h new file mode 100644 index 00000000..8d7892c5 --- /dev/null +++ b/deps/sysobj_early/gui/uri_handler.h @@ -0,0 +1,32 @@ +/* + * sysobj - https://github.com/bp0/verbose-spork + * Copyright (C) 2018 Burt P. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef URI_HANDLER_H +#define URI_HANDLER_H + +#include + +typedef gboolean (*uri_handler)(const gchar *uri); + +void uri_set_function(uri_handler f); +gboolean uri_open(const gchar *uri); +gboolean uri_open_default(const gchar *uri); /* uses xdg-open */ + +#endif -- cgit v1.2.3