diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2014-02-13 12:06:46 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2014-02-13 12:06:46 +0100 |
commit | 132b09bde9b87b48549c1b5a3e571407d565429d (patch) | |
tree | 75c6004b75b1ce95c16d8f5fba3fe3ac533f945f /src | |
parent | 00402b87c27fe60460ffcc68da287a9932b13bd6 (diff) | |
download | weechat-132b09bde9b87b48549c1b5a3e571407d565429d.zip |
trigger: add hook focus
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 60 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-callback.h | 2 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-command.c | 3 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.c | 27 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.h | 1 |
5 files changed, 87 insertions, 6 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index a0bd98f54..8db5b6ff3 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -896,6 +896,66 @@ end: } /* + * Callback for a focus hooked. + */ + +struct t_hashtable * +trigger_callback_focus_cb (void *data, struct t_hashtable *info) +{ + struct t_trigger *trigger; + struct t_hashtable *pointers; + const char *ptr_value; + long unsigned int value; + int rc; + + /* get trigger pointer, return immediately if not found or trigger running */ + trigger = (struct t_trigger *)data; + if (!trigger || trigger->hook_running) + return NULL; + + trigger->hook_count_cb++; + trigger->hook_running = 1; + + pointers = NULL; + + /* create hashtable */ + pointers = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); + if (!pointers) + goto end; + + /* add data in hashtables used for conditions/replace/command */ + ptr_value = weechat_hashtable_get (info, "_window"); + if (ptr_value && ptr_value[0] && (strncmp (ptr_value, "0x", 2) == 0)) + { + rc = sscanf (ptr_value + 2, "%lx", &value); + if ((rc != EOF) && (rc >= 1)) + weechat_hashtable_set (pointers, "window", (void *)value); + } + ptr_value = weechat_hashtable_get (info, "_buffer"); + if (ptr_value && ptr_value[0] && (strncmp (ptr_value, "0x", 2) == 0)) + { + rc = sscanf (ptr_value + 2, "%lx", &value); + if ((rc != EOF) && (rc >= 1)) + weechat_hashtable_set (pointers, "buffer", (void *)value); + } + + /* execute the trigger (conditions, regex, command) */ + trigger_callback_execute (trigger, NULL, pointers, info); + +end: + if (pointers) + weechat_hashtable_free (pointers); + + trigger->hook_running = 0; + + return info; +} + +/* * Initializes trigger callback. */ diff --git a/src/plugins/trigger/trigger-callback.h b/src/plugins/trigger/trigger-callback.h index 267ce814e..71cbb0e9f 100644 --- a/src/plugins/trigger/trigger-callback.h +++ b/src/plugins/trigger/trigger-callback.h @@ -40,6 +40,8 @@ extern int trigger_callback_command_run_cb (void *data, extern int trigger_callback_timer_cb (void *data, int remaining_calls); extern int trigger_callback_config_cb (void *data, const char *option, const char *value); +extern struct t_hashtable *trigger_callback_focus_cb (void *data, + struct t_hashtable *info); extern void trigger_callback_init (); extern void trigger_callback_end (); diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index 69b66e828..66757ff4f 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -776,7 +776,7 @@ trigger_command_init () " add: add a trigger\n" " name: name of trigger\n" " hook: signal, hsignal, modifier, print, command, command_run, " - "timer, config\n" + "timer, config, focus\n" " arguments: arguments for the hook, depending on hook (separated " "by semicolons):\n" " signal: name(s) of signal (required)\n" @@ -789,6 +789,7 @@ trigger_command_init () " timer: interval (required), align_second (required), " "max_calls (required)\n" " config: name of option (required)\n" + " focus: name(s) of area (required)\n" " conditions: evaluated conditions for the trigger\n" " regex: one or more regular expressions to replace strings " "in variables\n" diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index aec867ae6..a6c4fc97b 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -49,19 +49,19 @@ char *trigger_option_default[TRIGGER_NUM_OPTIONS] = char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] = { "signal", "hsignal", "modifier", "print", "command", "command_run", "timer", - "config" }; + "config", "focus" }; char *trigger_hook_option_values = - "signal|hsignal|modifier|print|command|command_run|timer|config"; + "signal|hsignal|modifier|print|command|command_run|timer|config|focus"; char *trigger_hook_default_arguments[TRIGGER_NUM_HOOK_TYPES] = { "xxx", "xxx", "xxx", "", "cmd;desc;args;args_desc;%(buffers_names)", "/cmd", - "60000;0;0", "xxx" }; + "60000;0;0", "xxx", "chat" }; char *trigger_hook_default_rc[TRIGGER_NUM_HOOK_TYPES] = { "ok,ok_eat,error", "ok,ok_eat,error", "", "ok,error", "ok,error", - "ok,ok_eat,error", "ok", "ok" }; + "ok,ok_eat,error", "ok", "ok", "" }; char *trigger_hook_regex_default_var[TRIGGER_NUM_HOOK_TYPES] = { "tg_signal_data", "", "tg_string", "tg_message", "tg_argv_eol1", "tg_command", - "", "tg_value" }; + "", "tg_value", "" }; char *trigger_return_code_string[TRIGGER_NUM_RETURN_CODES] = { "ok", "ok_eat", "error" }; @@ -409,6 +409,23 @@ trigger_hook (struct t_trigger *trigger) } } break; + case TRIGGER_HOOK_FOCUS: + if (argv && (argc >= 1)) + { + trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); + if (trigger->hooks) + { + trigger->hooks_count = argc; + for (i = 0; i < argc; i++) + { + trigger->hooks[i] = weechat_hook_focus ( + argv[i], + &trigger_callback_focus_cb, + trigger); + } + } + } + break; } if (!trigger->hooks) diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h index 1c9334e06..bd546cb2d 100644 --- a/src/plugins/trigger/trigger.h +++ b/src/plugins/trigger/trigger.h @@ -52,6 +52,7 @@ enum t_trigger_hook_type TRIGGER_HOOK_COMMAND_RUN, TRIGGER_HOOK_TIMER, TRIGGER_HOOK_CONFIG, + TRIGGER_HOOK_FOCUS, /* number of hook types */ TRIGGER_NUM_HOOK_TYPES, }; |