diff options
author | portix <none@none> | 2012-11-01 14:58:56 +0100 |
---|---|---|
committer | portix <none@none> | 2012-11-01 14:58:56 +0100 |
commit | 3da3defd89ea9213397bab7ec5908639b3594391 (patch) | |
tree | 82801b03e71825ce3825a5ef88103dffa20ecd81 /src | |
parent | 2529be6a2c5783fbdde70847787cba06cb46175b (diff) | |
download | dwb-3da3defd89ea9213397bab7ec5908639b3594391.zip |
New signal changeMode; new method util.getMode
Diffstat (limited to 'src')
-rw-r--r-- | src/callback.c | 7 | ||||
-rw-r--r-- | src/dwb.c | 8 | ||||
-rw-r--r-- | src/dwb.h | 3 | ||||
-rw-r--r-- | src/scripts.c | 8 | ||||
-rw-r--r-- | src/scripts.h | 3 | ||||
-rw-r--r-- | src/view.c | 8 |
6 files changed, 24 insertions, 13 deletions
diff --git a/src/callback.c b/src/callback.c index b1ee4ebf..321e1991 100644 --- a/src/callback.c +++ b/src/callback.c @@ -156,7 +156,7 @@ callback_key_press(GtkWidget *w, GdkEventKey *e) { UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode, BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval)); ScriptSignal signal = { SCRIPTS_WV(dwb.state.fview), SCRIPTS_SIG_META(json, KEY_PRESS, 0) }; - SCRIPTS_EMIT_RETURN(signal, json); + SCRIPTS_EMIT_RETURN(signal, json, true); } if (e->keyval == GDK_KEY_Escape) { @@ -211,11 +211,8 @@ callback_key_release(GtkWidget *w, GdkEventKey *e) { UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode, BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval)); ScriptSignal signal = { SCRIPTS_WV(dwb.state.fview), SCRIPTS_SIG_META(json, KEY_RELEASE, 0) }; - SCRIPTS_EMIT_RETURN(signal, json); + SCRIPTS_EMIT_RETURN(signal, json, true); } - //SCRIPTS_EMIT_RETURN(SCRIPT(dwb.state.fview), KEY_RELEASE, 5, UINTEGER, "state", e->state, - // UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode, - // BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval)); if (DWB_TAB_KEY(e)) { return true; } @@ -1412,7 +1412,7 @@ dwb_focus_view(GList *gl) { //ScriptSignal signal = { SCRIPTS_WV(gl), .objects = { SCRIPTS_WV(dwb.state.fview) }, SCRIPTS_SIG_META(NULL, TAB_FOCUS, 1) }; ScriptSignal signal = { SCRIPTS_WV(gl), .objects = { G_OBJECT(VIEW(dwb.state.fview)->web) }, SCRIPTS_SIG_META(NULL, TAB_FOCUS, 1) }; - SCRIPTS_EMIT_RETURN(signal, NULL); + SCRIPTS_EMIT_RETURN(signal, NULL, true); } gtk_widget_show(VIEW(gl)->scroll); dwb_soup_clean(); @@ -2681,6 +2681,12 @@ dwb_change_mode(Mode mode, ...) { va_list vl; if (dwb.state.mode & AUTO_COMPLETE) completion_clean_autocompletion(); + if (EMIT_SCRIPT(CHANGE_MODE)) { + char buffer[] = { BASIC_MODES(mode) + 48, 0 }; + ScriptSignal sig = { SCRIPTS_WV(dwb.state.fview), SCRIPTS_SIG_META(buffer, CHANGE_MODE, 0) }; + if (scripts_emit(&sig)) + return STATUS_OK; + } switch(mode) { case NORMAL_MODE: va_start(vl, mode); @@ -325,13 +325,13 @@ typedef enum { typedef enum { NORMAL_MODE = 1<<0, INSERT_MODE = 1<<1, + COMMAND_MODE = 1<<2, QUICK_MARK_SAVE = 1<<3, QUICK_MARK_OPEN = 1<<4 , HINT_MODE = 1<<5, FIND_MODE = 1<<6, COMPLETION_MODE = 1<<7, AUTO_COMPLETE = 1<<8, - COMMAND_MODE = 1<<9, SEARCH_FIELD_MODE = 1<<10, SETTINGS_MODE = 1<<12, KEY_MODE = 1<<13, @@ -345,6 +345,7 @@ typedef enum { SETTINGS_MODE_LOCAL = 1<<22, COMPLETE_SCRIPTS = 1<<23, } Mode; +#define BASIC_MODES(mode) (mode & (NORMAL_MODE | INSERT_MODE | COMMAND_MODE)) typedef enum { diff --git a/src/scripts.c b/src/scripts.c index 27605d12..a26f9cf3 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -80,6 +80,8 @@ static Sigmap m_sigmap[] = { { SCRIPTS_SIG_DOCUMENT_LOADED, "documentLoaded" }, { SCRIPTS_SIG_MOUSE_MOVE, "mouseMove" }, { SCRIPTS_SIG_STATUS_BAR, "statusBarChange" }, + { SCRIPTS_SIG_CHANGE_MODE, "changeMode" }, + { 0, NULL }, }; @@ -1028,7 +1030,10 @@ util_markup_escape(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size } return JSValueMakeNull(ctx); } - +static JSValueRef +util_get_mode(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { + return JSValueMakeNumber(ctx, BASIC_MODES(dwb.state.mode)); +} /* DATA {{{*/ /* data_get_profile {{{*/ static JSValueRef @@ -1895,6 +1900,7 @@ create_global_object() { JSStaticFunction util_functions[] = { { "domainFromHost", util_domain_from_host, kJSDefaultAttributes }, { "markupEscape", util_markup_escape, kJSDefaultAttributes }, + { "getMode", util_get_mode, kJSDefaultAttributes }, { 0, 0, 0 }, }; class = create_class("util", util_functions, NULL); diff --git a/src/scripts.h b/src/scripts.h index c860905a..218b39ec 100644 --- a/src/scripts.h +++ b/src/scripts.h @@ -46,6 +46,7 @@ enum SIGNALS { SCRIPTS_SIG_DOCUMENT_LOADED, SCRIPTS_SIG_MOUSE_MOVE, SCRIPTS_SIG_STATUS_BAR, + SCRIPTS_SIG_CHANGE_MODE, SCRIPTS_SIG_LAST, } ; @@ -74,7 +75,7 @@ void scripts_scratchpad_send(JSContextRef ctx, JSValueRef val); void scripts_scratchpad_get(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef* ); #define EMIT_SCRIPT(sig) ((dwb.misc.script_signals & (1<<SCRIPTS_SIG_##sig))) -#define SCRIPTS_EMIT_RETURN(signal, json) G_STMT_START \ +#define SCRIPTS_EMIT_RETURN(signal, json, val) G_STMT_START \ if (scripts_emit(&signal)) { \ g_free(json); \ return true; \ @@ -151,7 +151,7 @@ view_button_press_cb(WebKitWebView *web, GdkEventButton *e, GList *gl) { UINTEGER, "state", e->state, UINTEGER, "button", e->button, DOUBLE, "xRoot", e->x_root, DOUBLE, "yRoot", e->y_root); ScriptSignal signal = { SCRIPTS_WV(gl), { G_OBJECT(result) }, SCRIPTS_SIG_META(json, BUTTON_PRESS, 1) }; - SCRIPTS_EMIT_RETURN(signal, json); + SCRIPTS_EMIT_RETURN(signal, json, true); } if (gtk_widget_has_focus(dwb.gui.entry)) { @@ -218,7 +218,7 @@ view_button_release_cb(WebKitWebView *web, GdkEventButton *e, GList *gl) { UINTEGER, "state", e->state, UINTEGER, "button", e->button, DOUBLE, "xRoot", e->x_root, DOUBLE, "yRoot", e->y_root); ScriptSignal signal = { SCRIPTS_WV(gl), { G_OBJECT(result) }, SCRIPTS_SIG_META(json, BUTTON_RELEASE, 1) }; - SCRIPTS_EMIT_RETURN(signal, json); + SCRIPTS_EMIT_RETURN(signal, json, true); } if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { @@ -298,7 +298,7 @@ view_download_requested_cb(WebKitWebView *web, WebKitDownload *download, GList * CHAR, "referer", soup_get_header_from_request(webkit_download_get_network_request(download), "Referer"), CHAR, "mimeType", dwb.state.mimetype_request); ScriptSignal signal = { SCRIPTS_WV(gl), .objects = { G_OBJECT(download) }, SCRIPTS_SIG_META(json, DOWNLOAD, 1) }; - SCRIPTS_EMIT_RETURN(signal, json); + SCRIPTS_EMIT_RETURN(signal, json, true); } download_get_path(gl, download); return true; @@ -768,7 +768,7 @@ view_motion_notify_cb(WebKitWebView *web, GdkEventButton *e, GList *gl) { UINTEGER, "state", e->state, UINTEGER, "button", e->button, DOUBLE, "xRoot", e->x_root, DOUBLE, "yRoot", e->y_root); ScriptSignal signal = { SCRIPTS_WV(gl), SCRIPTS_SIG_META(json, MOUSE_MOVE, 0) }; - SCRIPTS_EMIT_RETURN(signal, json); + SCRIPTS_EMIT_RETURN(signal, json, true); } return false; } |