diff options
-rw-r--r-- | api/dwb-js.7 | 66 | ||||
-rw-r--r-- | api/jsapi.7.txt | 34 | ||||
-rw-r--r-- | api/jsapi.txt | 48 | ||||
-rw-r--r-- | scripts/lib/enums.js | 5 | ||||
-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 |
10 files changed, 175 insertions, 15 deletions
diff --git a/api/dwb-js.7 b/api/dwb-js.7 index 585ef7ed..842daff8 100644 --- a/api/dwb-js.7 +++ b/api/dwb-js.7 @@ -2,12 +2,12 @@ .\" Title: dwb-js .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.77.1 <http://docbook.sf.net/> -.\" Date: 10/31/2012 +.\" Date: 11/01/2012 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "DWB\-JS" "7" "10/31/2012" "\ \&" "\ \&" +.TH "DWB\-JS" "7" "11/01/2012" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -878,6 +878,22 @@ The body of the function as a string .nr an-break-flag 1 .br .ps +1 +\fBNumber util.getMode()\fR +.RS 4 +.sp +Gets the the current mode\&. +.PP +\fIreturns\fR +.RS 4 +The mode, see Modes for possible modes\&. +.RE +.RE +.sp +.it 1 an-trap +.nr an-no-space-flag 1 +.nr an-break-flag 1 +.br +.ps +1 \fBString util.domainFromHost(String hostname)\fR .RS 4 .sp @@ -1557,6 +1573,37 @@ Same as buttonPress but without .nr an-break-flag 1 .br .ps +1 +\fBchangeMode\fR +.RS 4 +.sp +.if n \{\ +.RS 4 +.\} +.nf +signals\&.connect("changeMode", function(webview, mode)); +.fi +.if n \{\ +.RE +.\} +.sp +Emitted when the mode changes, return true to prevent the change\&. +.PP +\fIwebview\fR +.RS 4 +The focused webview +.RE +.PP +\fImode\fR +.RS 4 +A mode, see also Modes for possible modes +.RE +.RE +.sp +.it 1 an-trap +.nr an-no-space-flag 1 +.nr an-break-flag 1 +.br +.ps +1 \fBclose\fR .RS 4 .sp @@ -2432,6 +2479,21 @@ const SpawnError = { .if n \{\ .RE .\} +.SS "Modes" +.sp +.if n \{\ +.RS 4 +.\} +.nf +const Modes = { + NormalMode : 1<<0, + InsertMode : 1<<1, + CommandMode : 1<<2 +}; +.fi +.if n \{\ +.RE +.\} .SH "GLOBAL DATA" .sp Since all scripts share the same execution context, they are encapsulated in a function\&. To avoid conflicts with other scripts it is not allowed to set properties on the global object, i\&.e\&. diff --git a/api/jsapi.7.txt b/api/jsapi.7.txt index 3ad27d95..cc1a8bb6 100644 --- a/api/jsapi.7.txt +++ b/api/jsapi.7.txt @@ -400,6 +400,14 @@ _func_;; A function _returns_;; The body of the function as a string **** +==== Number util.getMode() +**** + +Gets the the current mode. + +_returns_;; The mode, see Modes for possible modes. +**** + ==== String util.domainFromHost(String hostname) **** @@ -749,6 +757,19 @@ _hittestresult_;; Hittestresult under the cursor _event_;; Same as buttonPress but without _event.type_ **** +==== changeMode + +**** +---- +signals.connect("changeMode", function(webview, mode)); +---- + +Emitted when the mode changes, return true to prevent the change. + +_webview_;; The focused webview +_mode_;; A mode, see also Modes for possible modes +**** + ==== close **** @@ -1166,6 +1187,19 @@ const SpawnError = { -------- **** +=== Modes + +**** +-------- +const Modes = { + NormalMode : 1<<0, + InsertMode : 1<<1, + CommandMode : 1<<2 +}; +-------- +**** + + == GLOBAL DATA == Since all scripts share the same execution context, they are encapsulated in a function. To avoid conflicts with other scripts it is not allowed to set properties diff --git a/api/jsapi.txt b/api/jsapi.txt index 7ae151a7..993fcec3 100644 --- a/api/jsapi.txt +++ b/api/jsapi.txt @@ -750,6 +750,22 @@ _returns_;; The body of the function as a string **** **** +[float] +==== *getMode()* ==== + +[source,javascript] +---- +Number util.getMode() +---- + +Gets the the current mode. + +_returns_;; The mode, see <<Modes>> for possible modes. +**** + + + +**** [[domainFromHost]] [float] ==== *domainFromHost()* ==== @@ -1449,6 +1465,24 @@ _event_;; Same as <<buttonPress>> but without _event.type_ **** **** +[[changeMode]] +[float] +==== *changeMode* ==== + +[source,javascript] +---- +Boolean callback(webview, mode) +---- + +Emitted when the mode changes, return true to prevent the change. + + :: + +_webview_;; The focused webview +_mode_;; A mode, see also <<Modes>> for possible modes +**** + +**** [[close]] [float] ==== *close* ==== @@ -2024,6 +2058,20 @@ const SpawnError = { -------- **** +**** +[[Modes]] +[float] +==== *Modes* ==== +[source,javascript] +-------- +const Modes = { + NormalMode : 1<<0, + InsertMode : 1<<1, + CommandMode : 1<<2 +}; +-------- +**** + [[Globaldata]] == Global data == diff --git a/scripts/lib/enums.js b/scripts/lib/enums.js index f59a7409..01723864 100644 --- a/scripts/lib/enums.js +++ b/scripts/lib/enums.js @@ -71,3 +71,8 @@ const FileTest = { executable : 1 << 3, exists : 1 << 4 }; +const Modes = { + NormalMode : 1<<0, + InsertMode : 1<<1, + CommandMode : 1<<2 +}; 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; } |