static void link_hover_cb(WebKitWebView *view, const char *t, const gchar *link, widget_t *w) { (void) t; lua_State *L = globalconf.L; GObject *ws = G_OBJECT(view); gchar *last_hover = g_object_get_data(ws, "hovered-uri"); /* links are identical, do nothing */ if (last_hover && !g_strcmp0(last_hover, link)) return; luaH_object_push(L, w->ref); if (last_hover) { lua_pushstring(L, last_hover); g_object_set_data(ws, "hovered-uri", NULL); luaH_object_emit_signal(L, -2, "link-unhover", 1, 0); } if (link) { lua_pushstring(L, link); g_object_set_data_full(ws, "hovered-uri", g_strdup(link), g_free); luaH_object_emit_signal(L, -2, "link-hover", 1, 0); } luaH_object_emit_signal(L, -1, "property::hovered_uri", 0, 0); lua_pop(L, 1); }
static void plug_added_cb(GtkSocket* UNUSED(socket), widget_t *w) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "plug-added", 1, 0); }
/* Raises the "navigation-request" signal on a webkit navigation policy * decision request. The default action is to load the requested uri. * * The signal handler is able to: * - return true for the handler execution to stop and the request to continue * - return false for the handler execution to stop and the request to hault * - do nothing and give the navigation decision to the next signal handler * * This signal is also where you would attach custom scheme handlers to take * over the navigation request by launching an external application. */ static gboolean navigation_decision_cb(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *a, WebKitWebPolicyDecision *p, widget_t *w) { (void) v; (void) f; (void) a; lua_State *L = globalconf.L; const gchar *uri = webkit_network_request_get_uri(r); gint ret; luaH_object_push(L, w->ref); lua_pushstring(L, uri); ret = luaH_object_emit_signal(L, -2, "navigation-request", 1, 1); if (ret && !luaH_checkboolean(L, -1)) /* User responded with false, do not continue navigation request */ webkit_web_policy_decision_ignore(p); else webkit_web_policy_decision_use(p); lua_pop(L, ret + 1); return TRUE; }
/** * Callback from the \c WebKitDownload in case of errors. * * Fills the \c error member of \ref download_t. * * \returns \c FALSE */ static gboolean error_cb(WebKitDownload *d, gint error_code, gint error_detail, gchar *reason, download_t *download) { (void) d; (void) error_detail; (void) error_code; /* save error message */ if (download->error) g_free(download->error); download->error = g_strdup(reason); /* emit error signal if able */ if (download->ref) { lua_State *L = globalconf.L; luaH_object_push(L, download->ref); lua_pushstring(L, reason); luaH_object_emit_signal(L, -2, "error", 1, 0); lua_pop(L, 1); /* unref download */ luaH_download_unref(L, download); } return FALSE; }
static gboolean mime_type_decision_cb(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *mime, WebKitWebPolicyDecision *pd, widget_t *w) { (void) v; (void) f; lua_State *L = globalconf.L; const gchar *uri = webkit_network_request_get_uri(r); gint ret; luaH_object_push(L, w->ref); lua_pushstring(L, uri); lua_pushstring(L, mime); ret = luaH_object_emit_signal(L, -3, "mime-type-decision", 2, 1); if (ret && !luaH_checkboolean(L, -1)) /* User responded with false, ignore request */ webkit_web_policy_decision_ignore(pd); else if (!webkit_web_view_can_show_mime_type(v, mime)) webkit_web_policy_decision_download(pd); else webkit_web_policy_decision_use(pd); lua_pop(L, ret + 1); return TRUE; }
static void changed_cb(widget_t *w) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "changed", 0, 0); lua_pop(L, 1); }
static gboolean plug_removed_cb(GtkSocket* UNUSED(socket), widget_t *w) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "plug-removed", 1, 0); return FALSE; }
static gboolean timer_handle_timeout(gpointer data) { ltimer_t *timer = (ltimer_t *) data; luaH_object_push(globalconf.L, timer->ref); luaH_object_emit_signal(globalconf.L, -1, "timeout", 1, 0); return TRUE; }
static void activate_cb(GtkEntry* UNUSED(e), widget_t *w) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "activate", 0, 0); lua_pop(L, 1); }
static void position_cb(GtkEntry* UNUSED(e), GParamSpec* UNUSED(ps), widget_t *w) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "property::position", 0, 0); lua_pop(L, 1); }
gint luaH_object_property_signal(lua_State *L, gint oud, luakit_token_t tok) { gchar *signame = g_strdup_printf("property::%s", token_tostring(tok)); luaH_object_emit_signal(L, oud, signame, 0, 0); g_free(signame); return 0; }
static void load_finish_cb(WebKitWebView *v, WebKitWebFrame *f, widget_t *w) { update_uri(GTK_WIDGET(v), webkit_web_frame_get_uri(f), w); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "load-finish", 0, 0); lua_pop(L, 1); }
static void load_start_cb(WebKitWebView *v, WebKitWebFrame *f, widget_t *w) { (void) v; (void) f; lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "load-start", 0, 0); lua_pop(L, 1); }
static gboolean expose_cb(GtkWidget *widget, GdkEventExpose *e, widget_t *w) { (void) e; (void) widget; lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "expose", 0, 0); lua_pop(L, 1); return FALSE; }
static void progress_cb(WebKitWebView *v, gint p, widget_t *w) { (void) v; (void) p; lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "progress-update", 0, 0); lua_pop(L, 1); }
static void destroy_cb(GtkObject* UNUSED(win), widget_t *w) { /* remove window from global windows list */ g_ptr_array_remove(globalconf.windows, w); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "destroy", 0, 0); lua_pop(L, 1); }
static gboolean download_request_cb(WebKitWebView* UNUSED(v), WebKitDownload *dl, widget_t *w) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_download_push(L, dl); gint ret = luaH_object_emit_signal(L, 1, "download-request", 1, 1); gboolean handled = (ret && lua_toboolean(L, 2)); lua_pop(L, 1 + ret); return handled; }
static void page_removed_cb(GtkNotebook* UNUSED(n), GtkWidget *widget, guint UNUSED(i), widget_t *w) { widget_t *child = GOBJECT_TO_LUAKIT_WIDGET(widget); lua_State *L = common.L; luaH_object_push(L, w->ref); luaH_object_push(L, child->ref); luaH_object_emit_signal(L, -2, "page-removed", 1, 0); lua_pop(L, 1); }
static void reorder_cb(GtkNotebook* UNUSED(n), GtkWidget *widget, guint i, widget_t *w) { widget_t *child = GOBJECT_TO_LUAKIT_WIDGET(widget); lua_State *L = common.L; luaH_object_push(L, w->ref); luaH_object_push(L, child->ref); lua_pushnumber(L, i + 1); luaH_object_emit_signal(L, -3, "page-reordered", 2, 0); lua_pop(L, 1); }
static void title_changed_cb(WebKitWebView *v, WebKitWebFrame *f, const gchar *title, widget_t *w) { (void) f; (void) v; (void) title; lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "title-changed", 0, 0); lua_pop(L, 1); }
static void switch_cb(GtkNotebook *n, GtkWidget* UNUSED(p), guint i, widget_t *w) { GtkWidget *widget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(n), i); widget_t *child = GOBJECT_TO_LUAKIT_WIDGET(widget); lua_State *L = common.L; luaH_object_push(L, w->ref); luaH_object_push(L, child->ref); lua_pushnumber(L, i + 1); luaH_object_emit_signal(L, -3, "switch-page", 2, 0); lua_pop(L, 1); }
static void page_removed_cb(GtkNotebook *nbook, GtkWidget *widget, guint i, widget_t *w) { (void) i; (void) nbook; widget_t *child = g_object_get_data(G_OBJECT(widget), "widget"); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_push(L, child->ref); luaH_object_emit_signal(L, -2, "page-removed", 1, 0); lua_pop(L, 1); }
static void notify_cb(WebKitWebView *v, GParamSpec *ps, widget_t *w) { (void) v; property_t *p; /* emit webview property signal if found in properties table */ if ((p = g_hash_table_lookup(webview_properties, ps->name))) { lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, p->signame, 0, 0); lua_pop(L, 1); } }
inline static void update_uri(GtkWidget *view, const gchar *uri, widget_t *w) { /* return if uri has not changed */ if (!g_strcmp0(uri, g_object_get_data(G_OBJECT(view), "uri"))) return; g_object_set_data_full(G_OBJECT(view), "uri", g_strdup(uri), g_free); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_emit_signal(L, -1, "property::uri", 0, 0); lua_pop(L, 1); }
static void switch_cb(GtkNotebook *nbook, GtkNotebookPage *p, guint i, widget_t *w) { (void) p; GtkWidget *widget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(nbook), i); widget_t *child = g_object_get_data(G_OBJECT(widget), "widget"); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); luaH_object_push(L, child->ref); lua_pushnumber(L, i + 1); luaH_object_emit_signal(L, -3, "switch-page", 2, 0); lua_pop(L, 1); }
static gboolean wv_button_press_cb(GtkWidget *view, GdkEventButton *event, widget_t *w) { if((event->type != GDK_BUTTON_PRESS) || (event->button != 1)) return FALSE; /* get webview hit context */ WebKitHitTestResult *ht = webkit_web_view_get_hit_test_result(WEBKIT_WEB_VIEW(view), event); guint c; g_object_get(ht, "context", &c, NULL); gint context = (gint) c; lua_State *L = globalconf.L; luaH_object_push(L, w->ref); /* raise "form-active" when a user clicks on a form field and raise * "root-active" when a user clicks elsewhere */ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) luaH_object_emit_signal(L, -1, "form-active", 0, 0); else if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) luaH_object_emit_signal(L, -1, "root-active", 0, 0); lua_pop(L, 1); return FALSE; }
static gboolean download_request_cb(WebKitWebView *v, GObject *dl, widget_t *w) { (void) v; const gchar *uri = webkit_download_get_uri((WebKitDownload *) dl); const gchar *filename = webkit_download_get_suggested_filename((WebKitDownload *) dl); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); lua_pushstring(L, uri); lua_pushstring(L, filename); luaH_object_emit_signal(L, -3, "download-request", 2, 0); lua_pop(L, 1); return FALSE; }
/** * Sets the destination of a download. * * Converts the given destination to a \c file:// URI. * * \param L The Lua VM state. * \param download The \ref download_t of the download. * * \luastack * \lparam A \c download object. * \lvalue A string containing the new destination for the download. */ static gint luaH_download_set_destination(lua_State *L, download_t *download) { if (download_is_started(download)) { luaH_warn(L, "cannot change destination while download is running"); return 0; } const gchar *destination = luaL_checkstring(L, -1); gchar *uri = g_filename_to_uri(destination, NULL, NULL); if (uri) { download->destination = g_strdup(destination); webkit_download_set_destination_uri(download->webkit_download, uri); g_free(uri); luaH_object_emit_signal(L, -3, "property::destination", 0, 0); /* g_filename_to_uri failed on destination path */ } else { lua_pushfstring(L, "invalid destination: '%s'", destination); lua_error(L); } return 0; }
gint luaH_object_emit_signal_simple(lua_State *L) { return luaH_object_emit_signal(L, 1, luaL_checkstring(L, 2), lua_gettop(L) - 2, LUA_MULTRET); }