Permalink
Browse files

pass device struct to run_triggers function

  • Loading branch information...
1 parent 5a53b76 commit ed31249a93b9f5dad88dfed26d352ce7a40d0e08 @wertarbyte committed Dec 8, 2010
Showing with 29 additions and 3 deletions.
  1. +1 −1 thd.c
  2. +14 −1 trigger.c
  3. +1 −1 trigger.h
  4. +2 −0 triggerhappy.conf.examples
  5. +11 −0 triggerparser.c
View
2 thd.c
@@ -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;
View
15 trigger.c
@@ -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 ) {
@@ -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? */
View
2 trigger.h
@@ -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 );
View
2 triggerhappy.conf.examples
@@ -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
View
11 triggerparser.c
@@ -8,6 +8,7 @@
#include <dirent.h>
#include "eventnames.h"
#include "keystate.h"
+#include "devices.h"
#include "trigger.h"
#include "triggerparser.h"
@@ -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);

0 comments on commit ed31249

Please sign in to comment.