summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2014-03-03 01:57:38 +0100
committerportix <portix@gmx.net>2014-03-03 01:57:38 +0100
commit2a600c8594af6e4c140159cd0f8463e4cabc596b (patch)
tree882a30f37abe89386970526dc6e4f9ed936bb65c
parentea3ab348aabc2446d1ae5d8f2a07815d9454b15a (diff)
downloaddwb-2a600c8594af6e4c140159cd0f8463e4cabc596b.zip
Clear script binds before executing a command/shortcut
-rw-r--r--scripts/lib/dwb.js.in10
-rw-r--r--scripts/lib/signals.js.in5
-rw-r--r--src/dwb.c11
-rw-r--r--src/scripts.c19
-rw-r--r--src/scripts.h3
5 files changed, 32 insertions, 16 deletions
diff --git a/scripts/lib/dwb.js.in b/scripts/lib/dwb.js.in
index 350b8294..fc74f239 100644
--- a/scripts/lib/dwb.js.in
+++ b/scripts/lib/dwb.js.in
@@ -110,9 +110,6 @@
}
});
- function _removeBindHandle() {
- unbind(this.id);
- }
Object.defineProperties(this, {
/**
* Bind a function to a shortcut or commandline command, use {@link unbind} to remove
@@ -143,7 +140,12 @@
value : function() {
var id = _bind.apply(null, arguments);
if (id != -1) {
- return { id : id, remove : _removeBindHandle };
+ return {
+ id : id,
+ remove : function() {
+ unbind(id);
+ }
+ };
}
return { remove : function() {} };
}
diff --git a/scripts/lib/signals.js.in b/scripts/lib/signals.js.in
index d032ad3a..21a83536 100644
--- a/scripts/lib/signals.js.in
+++ b/scripts/lib/signals.js.in
@@ -268,6 +268,11 @@
this.connect();
return !connected;
}
+ },
+ "remove" : {
+ value : function() {
+ this.disconnect();
+ }
}
}
);
diff --git a/src/dwb.c b/src/dwb.c
index 81d5ddd5..97ba4993 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -3194,6 +3194,8 @@ dwb_eval_key(GdkEventKey *e)
}
}
+ scripts_clear_keymap();
+
for (GList *l = dwb.keymap; l; l=l->next)
{
KeyMap *km = l->data;
@@ -3229,9 +3231,6 @@ dwb_eval_key(GdkEventKey *e)
{
commands_simple_command(tmp);
ret = true;
- if (SCRIPTS_INVALID_BIND(tmp)) {
- scripts_clear_keymap(tmp);
- }
}
else if (e->state & GDK_CONTROL_MASK || !isprint)
ret = false;
@@ -3291,6 +3290,7 @@ dwb_insert_mode(void)
static DwbStatus
dwb_command_mode(void)
{
+ scripts_clear_keymap();
dwb.state.mode = COMMAND_MODE;
dwb_set_normal_message(dwb.state.fview, false, ":");
entry_focus();
@@ -5209,6 +5209,8 @@ dwb_parse_command_line(const char *line)
if (!token[0])
return STATUS_OK;
+ scripts_clear_keymap();
+
bak = token[0];
if (token[1])
@@ -5277,9 +5279,6 @@ dwb_parse_command_line(const char *line)
if (!(m->map->prop & CP_DONT_CLEAN) || (m->map->prop & CP_NEEDS_ARG && has_arg) )
dwb_change_mode(NORMAL_MODE, dwb.state.message_id == 0);
- if (SCRIPTS_INVALID_BIND(m)) {
- scripts_clear_keymap(m);
- }
return ret;
}/*}}}*/
void
diff --git a/src/scripts.c b/src/scripts.c
index 497e6605..3df4950b 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -276,6 +276,7 @@ static GPtrArray *s_gobject_signals = NULL;
static gboolean s_debugging = false;
static GHashTable *s_exports = NULL;
static GSList *s_servers = NULL;
+static gboolean s_keymap_dirty = false;
/* Only defined once */
static JSValueRef UNDEFINED, NIL;
@@ -1993,10 +1994,19 @@ scripts_eval_key(KeyMap *m, Arg *arg)
}/*}}}*/
void
-scripts_clear_keymap(KeyMap *km) {
- EXEC_LOCK;
- unbind_free_keymap(s_global_context, g_list_find(dwb.keymap, km));
- EXEC_UNLOCK;
+scripts_clear_keymap() {
+ if (s_keymap_dirty) {
+ EXEC_LOCK;
+ for (GList *l = dwb.keymap; l; l=l->next) {
+ KeyMap *km = l->data;
+ if (km->map->prop & CP_SCRIPT && km->map->arg.i == 0) {
+ unbind_free_keymap(s_global_context, l);
+ break;
+ }
+ }
+ EXEC_UNLOCK;
+ s_keymap_dirty = false;
+ }
}
@@ -2049,6 +2059,7 @@ global_unbind(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, si
// don't free it yet, if unbind is called from inside a bind
// callback parse_command_line and eval_key would use an invalid keymap
KEYMAP_MAP(l)->arg.i = 0;
+ s_keymap_dirty = true;
for (GList *gl = dwb.override_keys; gl; gl=gl->next)
{
diff --git a/src/scripts.h b/src/scripts.h
index 492e2dd7..c20653a0 100644
--- a/src/scripts.h
+++ b/src/scripts.h
@@ -85,9 +85,8 @@ void scripts_check_syntax(char **scripts);
JSObjectRef scripts_make_cookie(SoupCookie *cookie);
gboolean scripts_load_chrome(JSObjectRef, const char *);
void scripts_load_extension(const char *);
-void scripts_clear_keymap(KeyMap *km);
+void scripts_clear_keymap(void);
-#define SCRIPTS_INVALID_BIND(m) (((m)->map->prop & CP_SCRIPT) && (m)->map->arg.i == 0)
#define EMIT_SCRIPT(sig) ((dwb.misc.script_signals & (1ULL<<SCRIPTS_SIG_##sig)))
#define SCRIPTS_EMIT_RETURN(signal, json, val) G_STMT_START \
if (scripts_emit(&signal)) { \