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 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 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 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 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); }
/* 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; }
static JSValueRef webview_registered_function_callback(JSContextRef context, JSObjectRef fun, JSObjectRef thisObject, size_t argumentCount, const JSValueRef *arguments, JSValueRef *exception) { (void) thisObject; (void) argumentCount; (void) arguments; lua_State *L = globalconf.L; gpointer ref = JSObjectGetPrivate(fun); // get function luaH_object_push(L, ref); // call function gint ret = lua_pcall(L, 0, 0, 0); // handle errors if (ret != 0) { const gchar *exn_cstring = luaL_checkstring(L, -1); lua_pop(L, 1); JSStringRef exn_js_string = JSStringCreateWithUTF8CString(exn_cstring); JSValueRef exn_js_value = JSValueMakeString(context, exn_js_string); *exception = JSValueToObject(context, exn_js_value, NULL); JSStringRelease(exn_js_string); } return JSValueMakeUndefined(context); }
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); }
void signal_object_emit(lua_State *L, signal_t *signals, const gchar *name, gint nargs) { signal_array_t *sigfuncs = signal_lookup(signals, name, FALSE); if(sigfuncs) { gint nbfunc = sigfuncs->len; luaL_checkstack(L, lua_gettop(L) + nbfunc + nargs + 1, "too much signal"); /* Push all functions and then execute, because this list can change * while executing funcs. */ for(gint i = 0; i < nbfunc; i++) { luaH_object_push(L, sigfuncs->pdata[i]); } for(gint i = 0; i < nbfunc; i++) { /* push all args */ for(gint j = 0; j < nargs; j++) lua_pushvalue(L, - nargs - nbfunc + i); /* push first function */ lua_pushvalue(L, - nargs - nbfunc + i); /* remove this first function */ lua_remove(L, - nargs - nbfunc - 1 + i); luaH_dofunction(L, nargs, 0); } } /* remove args */ lua_pop(L, nargs); }
/** * 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 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); }
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 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); }
/* luakit global table. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lfield font The default font. * \lfield font_height The default font height. * \lfield conffile The configuration file which has been loaded. */ static gint luaH_luakit_index(lua_State *L) { if(luaH_usemetatable(L, 1, 2)) return 1; widget_t *w; const gchar *prop = luaL_checkstring(L, 2); luakit_token_t token = l_tokenize(prop); switch(token) { /* push class methods */ PF_CASE(GET_SPECIAL_DIR, luaH_luakit_get_special_dir) PF_CASE(SPAWN, luaH_luakit_spawn) PF_CASE(SPAWN_SYNC, luaH_luakit_spawn_sync) PF_CASE(GET_SELECTION, luaH_luakit_get_selection) PF_CASE(SET_SELECTION, luaH_luakit_set_selection) PF_CASE(EXEC, luaH_exec) /* push string properties */ PS_CASE(CACHE_DIR, globalconf.cache_dir) PS_CASE(CONFIG_DIR, globalconf.config_dir) PS_CASE(DATA_DIR, globalconf.data_dir) PS_CASE(EXECPATH, globalconf.execpath) PS_CASE(CONFPATH, globalconf.confpath) /* push boolean properties */ PB_CASE(VERBOSE, globalconf.verbose) /* push integer properties */ PI_CASE(WEBKIT_MAJOR_VERSION, webkit_major_version()) PI_CASE(WEBKIT_MINOR_VERSION, webkit_minor_version()) PI_CASE(WEBKIT_MICRO_VERSION, webkit_micro_version()) PI_CASE(WEBKIT_USER_AGENT_MAJOR_VERSION, WEBKIT_USER_AGENT_MAJOR_VERSION) PI_CASE(WEBKIT_USER_AGENT_MINOR_VERSION, WEBKIT_USER_AGENT_MINOR_VERSION) case L_TK_WINDOWS: lua_newtable(L); for (guint i = 0; i < globalconf.windows->len; i++) { w = globalconf.windows->pdata[i]; luaH_object_push(L, w->ref); lua_rawseti(L, -2, i+1); } return 1; case L_TK_INSTALL_PATH: lua_pushliteral(L, LUAKIT_INSTALL_PATH); return 1; case L_TK_VERSION: lua_pushliteral(L, VERSION); return 1; default: break; } return 0; }
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 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 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 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 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 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); }
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 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); } }
static gint luaH_notebook_atindex(lua_State *L, widget_t *w, gint idx) { /* correct index */ if (idx != -1) idx--; GtkWidget *widget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(w->widget), idx); if (!widget) return 0; widget_t *child = GOBJECT_TO_LUAKIT_WIDGET(widget); luaH_object_push(L, child->ref); return 1; }
static gint luaH_notebook_atindex(lua_State *L) { widget_t *w = luaH_checkudata(L, 1, &widget_class); gint i = luaL_checknumber(L, 2); /* correct index */ if (i != -1) i--; GtkWidget *widget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(w->widget), i); if (!widget) return 0; widget_t *child = g_object_get_data(G_OBJECT(widget), "widget"); luaH_object_push(L, child->ref); return 1; }
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; }