indented cases and others

xkbcommon
Alessandro Mauri 5 years ago
parent 8d890b9e9e
commit 296bd3fb79
  1. 54
      macrod.c

@ -51,6 +51,7 @@ const char evdev_root_dir[] = "/dev/input/";
int key_buffer_add (struct key_buffer*, unsigned short); int key_buffer_add (struct key_buffer*, unsigned short);
int key_buffer_remove (struct key_buffer*, unsigned short); int key_buffer_remove (struct key_buffer*, unsigned short);
int convert_key_value (unsigned short);
void int_handler (int signum); void int_handler (int signum);
void die (const char *, int); void die (const char *, int);
void exec_command(const char *); void exec_command(const char *);
@ -136,14 +137,14 @@ int main (void)
event.code != BTN_TOOL_TRIPLETAP event.code != BTN_TOOL_TRIPLETAP
) { ) {
switch (event.value) { switch (event.value) {
/* Key released */ /* Key released */
case (0): case (0):
key_buffer_remove(&pb, event.code); key_buffer_remove(&pb, event.code);
break; break;
/* Key pressed */ /* Key pressed */
case (1): case (1):
key_buffer_add(&pb, event.code); key_buffer_add(&pb, event.code);
break; break;
} }
} }
} }
@ -154,10 +155,17 @@ int main (void)
for (unsigned int i = 0; i < pb.size; i++) for (unsigned int i = 0; i < pb.size; i++)
printf("%d ", pb.buf[i]); printf("%d ", pb.buf[i]);
putchar('\n'); putchar('\n');
if (pb.size == 2) switch (pb.size) {
case 1:
/* You can use keys defined in input.h */
if (pb.buf[0] == KEY_MUTE)
exec_command("/home/ale/hello");
case 2:
if (pb.buf[0] == 56 || pb.buf[0] == 31) if (pb.buf[0] == 56 || pb.buf[0] == 31)
if (pb.buf[1] == 31 || pb.buf[1] == 56) if (pb.buf[1] == 31 || pb.buf[1] == 56)
exec_command("/home/ale/hello"); exec_command("/home/ale/hello");
break;
}
} }
} }
@ -238,17 +246,17 @@ void die (const char *msg, int err)
void exec_command (const char *path) void exec_command (const char *path)
{ {
switch (fork()) { switch (fork()) {
case -1: case -1:
die("Could not fork: %s", errno); die("Could not fork: %s", errno);
break; break;
case 0: case 0:
/* we are the child */ /* we are the child */
if(execl(path, path, (char *) NULL) != 0) if(execl(path, path, (char *) NULL) != 0)
/* execl only returns if an error occured, so we exit /* execl only returns if an error occured, so we exit
* otherwise we duplicate the process */ * otherwise we duplicate the process */
exit(-1); exit(-1);
/* we shouldn't be here */ /* we shouldn't be here */
break; break;
} }
// TODO: communication between parent and child about process status/errors/etc // TODO: communication between parent and child about process status/errors/etc
} }
@ -318,3 +326,9 @@ void update_descriptors_list (struct pollfd **fds, int *fd_num)
fprintf(stderr,ANSI_COLOR_YELLOW "Monitoring %d devices\n" ANSI_COLOR_RESET, (*fd_num)); fprintf(stderr,ANSI_COLOR_YELLOW "Monitoring %d devices\n" ANSI_COLOR_RESET, (*fd_num));
closedir(ev_dir); closedir(ev_dir);
} }
int convert_key_value (unsigned short key)
{
int outchar = 0;
return outchar;
}

Loading…
Cancel
Save