multiple scripts for notification
This commit is contained in:
parent
0de8610b67
commit
4d66a60a4f
@ -88,21 +88,20 @@ void notification_print(const struct notification *n)
|
|||||||
printf("\t\t\"%s\": \"%s\"\n", (char*)p_key, (char*)p_value);
|
printf("\t\t\"%s\": \"%s\"\n", (char*)p_key, (char*)p_value);
|
||||||
printf("\t}\n");
|
printf("\t}\n");
|
||||||
}
|
}
|
||||||
printf("\tscript: %s\n", n->script);
|
printf("\tscript_count: %d\n", n->script_count);
|
||||||
|
if (n->script_count > 0) {
|
||||||
|
printf("\tscripts: ");
|
||||||
|
for (int i = 0; i < n->script_count; i++) {
|
||||||
|
printf("'%s' ",n->scripts[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see notification.h */
|
/* see notification.h */
|
||||||
void notification_run_script(struct notification *n)
|
void notification_run_script(struct notification *n)
|
||||||
{
|
{
|
||||||
if (STR_EMPTY(n->script))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (n->script_run && !settings.always_run_script)
|
|
||||||
return;
|
|
||||||
|
|
||||||
n->script_run = true;
|
|
||||||
|
|
||||||
const char *appname = n->appname ? n->appname : "";
|
const char *appname = n->appname ? n->appname : "";
|
||||||
const char *summary = n->summary ? n->summary : "";
|
const char *summary = n->summary ? n->summary : "";
|
||||||
const char *body = n->body ? n->body : "";
|
const char *body = n->body ? n->body : "";
|
||||||
@ -110,6 +109,18 @@ void notification_run_script(struct notification *n)
|
|||||||
|
|
||||||
const char *urgency = notification_urgency_to_string(n->urgency);
|
const char *urgency = notification_urgency_to_string(n->urgency);
|
||||||
|
|
||||||
|
for(int i = 0; i < n->script_count; i++) {
|
||||||
|
|
||||||
|
if(n->script_run[i] && !settings.always_run_script)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const char *script = n->scripts[i];
|
||||||
|
|
||||||
|
if (STR_EMPTY(script))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
n->script_run[i] = true;
|
||||||
|
|
||||||
int pid1 = fork();
|
int pid1 = fork();
|
||||||
|
|
||||||
if (pid1) {
|
if (pid1) {
|
||||||
@ -120,8 +131,8 @@ void notification_run_script(struct notification *n)
|
|||||||
if (pid2) {
|
if (pid2) {
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
int ret = execlp(n->script,
|
int ret = execlp(script,
|
||||||
n->script,
|
script,
|
||||||
appname,
|
appname,
|
||||||
summary,
|
summary,
|
||||||
body,
|
body,
|
||||||
@ -135,6 +146,7 @@ void notification_run_script(struct notification *n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to convert an urgency to a string
|
* Helper function to convert an urgency to a string
|
||||||
@ -236,6 +248,11 @@ void notification_unref(struct notification *n)
|
|||||||
|
|
||||||
notification_private_free(n->priv);
|
notification_private_free(n->priv);
|
||||||
|
|
||||||
|
if (n->script_count > 0){
|
||||||
|
g_free(n->scripts);
|
||||||
|
g_free(n->script_run);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(n);
|
g_free(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,13 +334,13 @@ struct notification *notification_create(void)
|
|||||||
n->transient = false;
|
n->transient = false;
|
||||||
n->progress = -1;
|
n->progress = -1;
|
||||||
|
|
||||||
n->script_run = false;
|
|
||||||
n->dbus_valid = false;
|
n->dbus_valid = false;
|
||||||
|
|
||||||
n->fullscreen = FS_SHOW;
|
n->fullscreen = FS_SHOW;
|
||||||
|
|
||||||
n->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
n->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||||
|
|
||||||
|
n->script_count = 0;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,8 @@ struct notification {
|
|||||||
|
|
||||||
enum markup_mode markup;
|
enum markup_mode markup;
|
||||||
const char *format;
|
const char *format;
|
||||||
const char *script;
|
const char **scripts;
|
||||||
|
int script_count;
|
||||||
struct notification_colors colors;
|
struct notification_colors colors;
|
||||||
|
|
||||||
char *stack_tag; /**< stack notifications by tag */
|
char *stack_tag; /**< stack notifications by tag */
|
||||||
@ -79,7 +80,7 @@ struct notification {
|
|||||||
int dup_count; /**< amount of duplicate notifications stacked onto this */
|
int dup_count; /**< amount of duplicate notifications stacked onto this */
|
||||||
int displayed_height;
|
int displayed_height;
|
||||||
enum behavior_fullscreen fullscreen; //!< The instruction what to do with it, when desktop enters fullscreen
|
enum behavior_fullscreen fullscreen; //!< The instruction what to do with it, when desktop enters fullscreen
|
||||||
bool script_run; /**< Has the script been executed already? */
|
bool *script_run; /**< Has the script been executed already? */
|
||||||
|
|
||||||
/* derived fields */
|
/* derived fields */
|
||||||
char *msg; /**< formatted message */
|
char *msg; /**< formatted message */
|
||||||
|
11
src/rules.c
11
src/rules.c
@ -44,8 +44,15 @@ void rule_apply(struct rule *r, struct notification *n)
|
|||||||
}
|
}
|
||||||
if (r->format)
|
if (r->format)
|
||||||
n->format = r->format;
|
n->format = r->format;
|
||||||
if (r->script)
|
if (r->script){
|
||||||
n->script = r->script;
|
n->scripts = g_renew(const char*,n->scripts,n->script_count + 1);
|
||||||
|
n->scripts[n->script_count] = r->script;
|
||||||
|
|
||||||
|
n->script_run = g_renew(bool,n->script_run,n->script_count + 1);
|
||||||
|
n->script_run[n->script_count] = false;
|
||||||
|
|
||||||
|
n->script_count++;
|
||||||
|
}
|
||||||
if (r->set_stack_tag) {
|
if (r->set_stack_tag) {
|
||||||
g_free(n->stack_tag);
|
g_free(n->stack_tag);
|
||||||
n->stack_tag = g_strdup(r->set_stack_tag);
|
n->stack_tag = g_strdup(r->set_stack_tag);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user