mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
trigger: add hook focus
This commit is contained in:
@@ -895,6 +895,66 @@ end:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user