Share state between keyboards (#202)

master
Raheman Vaiya 4 years ago
parent 6c650002da
commit 76ef5b73d8
  1. BIN
      data/keyd-application-mapper.1.gz
  2. BIN
      data/keyd.1.gz
  3. 4
      src/keyboard.h
  4. 58
      src/keyd.c
  5. 4
      src/keyd.h

Binary file not shown.

Binary file not shown.

@ -6,6 +6,7 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include "keyd.h"
#include "config.h"
#include "layer.h"
@ -22,9 +23,10 @@ struct cache_entry {
/* May correspond to more than one physical input device. */
struct keyboard {
struct config original_config;
char config_path[PATH_MAX];
struct config config;
struct config original_config;
/*
* Cache descriptors to preserve code->descriptor

@ -29,6 +29,8 @@
#include "keys.h"
#include "ipc.h"
#define MAX_KEYBOARDS 64
/* config variables */
static const char *virtual_keyboard_name;
@ -39,8 +41,13 @@ static const char *socket_file;
static struct device devices[MAX_DEVICES];
static size_t nr_devices = 0;
static struct keyboard *active_kbd = NULL;
static struct keyboard *keyboards[MAX_KEYBOARDS];
static size_t nr_keyboards;
/* loop() callback functions */
static void (*device_add_cb) (struct device *dev);
@ -53,6 +60,37 @@ static int (*device_event_cb) (struct device *dev, uint8_t code, uint8_t process
struct vkbd *vkbd;
struct keyboard *get_keyboard(const char *config_path)
{
size_t i;
struct keyboard *kbd;
for (i = 0; i < nr_keyboards; i++)
if (!strcmp(keyboards[i]->config_path, config_path))
return keyboards[i];
assert(nr_keyboards < MAX_KEYBOARDS);
kbd = calloc(1, sizeof(struct keyboard));
if (config_parse(&kbd->config, config_path)) {
printf("\tfailed to parse %s\n", config_path);
free(kbd);
return NULL;
}
memcpy(&kbd->original_config, &kbd->config, sizeof kbd->config);
strcpy(kbd->config_path, config_path);
kbd->layer_state[0].active = 1;
kbd->layer_state[0].activation_time = 1;
keyboards[nr_keyboards++] = kbd;
return kbd;
}
static void daemon_remove_cb(struct device *dev)
{
struct keyboard *kbd = dev->data;
@ -99,26 +137,14 @@ static void daemon_add_cb(struct device *dev)
printf("\tmatched %s\n", config_path);
kbd = calloc(1, sizeof(struct keyboard));
if (config_parse(&kbd->config, config_path)) {
printf("\tfailed to parse %s\n", config_path);
free(kbd);
dev->data = get_keyboard(config_path);
if (!dev->data)
return;
}
memcpy(&kbd->original_config, &kbd->config, sizeof kbd->config);
kbd->layer_state[0].active = 1;
kbd->layer_state[0].activation_time = 1;
if (device_grab(dev) < 0) {
printf("\tgrab failed\n");
free(kbd);
return;
}
dev->data = kbd;
}
static void panic_check(uint8_t code, uint8_t pressed)
@ -405,8 +431,8 @@ static void cleanup()
{
size_t i;
for (i = 0; i < nr_devices; i++)
free(devices[i].data);
for (i = 0; i < nr_keyboards; i++)
free(keyboards[i]);
free_vkbd(vkbd);

@ -6,6 +6,10 @@
#ifndef KEYD_H_
#define KEYD_H_
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
void set_led(int led, int state);
#endif

Loading…
Cancel
Save