Skip to content

Commit

Permalink
pass device struct to run_triggers function
Browse files Browse the repository at this point in the history
  • Loading branch information
wertarbyte committed Dec 8, 2010
1 parent 5a53b76 commit ed31249
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion thd.c
Expand Up @@ -113,7 +113,7 @@ static int read_event( device *dev ) {
print_event( devname, ev );
print_triggerline( ev, *keystate );
}
run_triggers( ev.type, ev.code, ev.value, *keystate );
run_triggers( ev.type, ev.code, ev.value, *keystate, dev );
change_keystate( *keystate, ev );
}
return 0;
Expand Down
15 changes: 14 additions & 1 deletion trigger.c
Expand Up @@ -127,6 +127,16 @@ int read_triggers(const char *path) {
}
}

static int devtag_equal(const char *d_tag, const char *t_tag) {
if (strlen(t_tag) == 0) {
return 1;
}
if (strcmp(t_tag, d_tag) == 0) {
return 1;
}
return 0;
}

static int mods_equal(keystate_holder ksh, trigger_modifier tm, int ignore_key) {
int n = 0;
while ( n < TRIGGER_MODIFIERS_MAX ) {
Expand Down Expand Up @@ -158,17 +168,20 @@ static int correct_mode( const char *tmode ) {
return (tmode == NULL) || (strcmp( get_trigger_mode(), tmode ) == 0);
}

void run_triggers(int type, int code, int value, keystate_holder ksh) {
void run_triggers(int type, int code, int value, keystate_holder ksh, device *dev) {
if (triggers_are_enabled == 0) {
return;
}
if (dev && dev->tag) {
}
trigger *et = trigger_list;
while (et != NULL) {
if ( type == et->type &&
code == et->code &&
value == et->value &&
et->action &&
correct_mode( et->mode ) &&
devtag_equal(&(dev->tag[0]), &(et->devtag[0])) &&
mods_equal(ksh, et->modifiers, (type==EV_KEY?code:-1) )) {
fprintf(stderr, "Executing trigger action: %s\n", et->action);
/* switch trigger mode or execute program? */
Expand Down
2 changes: 1 addition & 1 deletion trigger.h
Expand Up @@ -17,7 +17,7 @@ typedef struct trigger {
trigger* parse_trigger(char* line);
void append_trigger(trigger *t);
int read_triggers(const char *filename);
void run_triggers(int type, int code, int value, keystate_holder ksh);
void run_triggers(int type, int code, int value, keystate_holder ksh, device *dev);
void clear_triggers();

void triggers_enabled( int status );
Expand Down
2 changes: 2 additions & 0 deletions triggerhappy.conf.examples
Expand Up @@ -12,3 +12,5 @@ KEY_KPMINUS@media 1 /usr/bin/mpc prev # next song
KEY_F12@ 1 @media # switch to media mode
KEY_F12@media 1 @ # switch back to nameless default mode
KEY_KPASTERISK 1 <KEY_VOLUMEDOWN # emit a synthetic key event through uinput
# enable trigger only on devices tagged "sys"
<sys>KEY_F11 1 id
11 changes: 11 additions & 0 deletions triggerparser.c
Expand Up @@ -8,6 +8,7 @@
#include <dirent.h>
#include "eventnames.h"
#include "keystate.h"
#include "devices.h"
#include "trigger.h"
#include "triggerparser.h"

Expand All @@ -21,6 +22,16 @@ static int parse_evdef(char *evdef, trigger *t) {
/* place a copy of the mode string or NULL in the struct */
t->mode = (mode ? strdup(mode) : NULL);

/* The evdef event now might still contain a device tag enclosed in < > */
t->devtag[0] = '\0';
char *tmp = strchr(evdef, '>');
if (tmp && evdef[0] == '<') {
*tmp = '\0';
strncpy(t->devtag, &evdef[1], TH_DEVICE_TAG_LENGTH);
t->devtag[TH_DEVICE_TAG_LENGTH-1] = '\0';
evdef = tmp+1; /* point evdef to the beginning of the event */
}

/* now we can start to separate the triggering event from the modifiers */
char *sptr = NULL;
char *s_trigger = strtok_r(evdef, "+", &sptr);
Expand Down

0 comments on commit ed31249

Please sign in to comment.