Skip to content

Commit

Permalink
feat: allow playing with dead keys
Browse files Browse the repository at this point in the history
See issue nomadbyte#26
  • Loading branch information
atao60 committed May 24, 2021
1 parent 2ef75a9 commit 3a01f53
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
69 changes: 67 additions & 2 deletions brighton/brightonControllers.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ int channel, char *param)
{
// int from, to, chan;
unsigned char from;
int to, chan;

int to, chan, key;

from = param[0];

Expand All @@ -138,6 +137,17 @@ int channel, char *param)
bwin->kbdmap[from][KM_CHAN] = chan;

/* printf("Keymap %c to %i on channel %i\n", from, to, chan); */
if ((param = index(++param, ' ')) == NULL)
{
/* printf("Keymap %c to %i on channel %i\n", from, to, chan); */
return;
}

key = atoi(++param);

addInAndOutKeysToKeymapFilter(key, from, bwin->filter);
/* printf("Keymap %i (%i) to %i on channel %i with key %i\n",
getOutkeyForInkeyFromKeymapFilter(key, bwin->filter), from, to, chan, key); */
}

static void
Expand Down Expand Up @@ -955,6 +965,60 @@ brightonControlKeyInput(brightonWindow *cid, int asckey, int on)
* one. For best results we would need to disable key repeat on entering the
* window. FFS.
*/

brightonKeymapFilter*
brightonCreateKeymapFilter()
{
brightonKeymapFilter* filter = malloc(sizeof(brightonKeymapFilter));
filter->keyin = NULL;
filter->keyout = NULL;
filter->size = 0;
return filter;
}

int
addInAndOutKeysToKeymapFilter(BRIGHTON_MAP_BASE_TYPE in, BRIGHTON_MAP_BASE_TYPE out, brightonKeymapFilter* filter)
{
if (!filter) return BRIGHTON_INVALID_KEYMAP_FILTER;
if (in < 0) return BRIGHTON_INVALID_INPUT_KEY;
if (out < 0) return BRIGHTON_INVALID_OUTPUT_KEY;

filter->size++;
filter->keyin = realloc(filter->keyin, (filter->size) * sizeof(in));
filter->keyout = realloc(filter->keyout, (filter->size) * sizeof(out));
filter->keyin[filter->size - 1] = in;
filter->keyout[filter->size - 1] = out;
return filter->size;
}

BRIGHTON_MAP_BASE_TYPE
getOutkeyForInkeyFromKeymapFilter(BRIGHTON_MAP_BASE_TYPE in, brightonKeymapFilter* filter)
{
if (!filter || filter->size == 0) return in;

int i;
for (i = 0; i < filter->size; i++)
{
if (filter->keyin[i] == in) return filter->keyout[i];
}
return in;
}

void*
deleteKeymapFilter(brightonKeymapFilter* filter)
{
free(filter->keyin);
free(filter->keyout);
free(filter);
return NULL;
}

void*
brightonFreeKeymapFilter(brightonWindow * bwin)
{
return deleteKeymapFilter(bwin->filter);
}

void
brightonKeyInput(brightonWindow *cid, int asckey, int on)
{
Expand All @@ -964,6 +1028,7 @@ brightonKeyInput(brightonWindow *cid, int asckey, int on)
event.type = BRIGHTON_FLOAT;
event.value = 1.0;

asckey = getOutkeyForInkeyFromKeymapFilter(asckey, cid->filter);
if ((asckey < 0) || (asckey > 255))
return;

Expand Down
15 changes: 15 additions & 0 deletions include/brighton/brightoninternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ typedef struct BrightonNRPcontrol {
#define BRIGHTON_NRP_COUNT 128
#define BRIGHTON_GANG_COUNT 8

#define BRIGHTON_MAP_BASE_TYPE int
#define BRIGHTON_INVALID_KEYMAP_FILTER -1
#define BRIGHTON_INVALID_INPUT_KEY -2
#define BRIGHTON_INVALID_OUTPUT_KEY -3
typedef struct BrightonKeymapFilter
{
BRIGHTON_MAP_BASE_TYPE* keyin;
BRIGHTON_MAP_BASE_TYPE* keyout;
int size;
} brightonKeymapFilter;

typedef struct BrightonWindow {
unsigned int flags;
struct BrightonWindow *next, *last;
Expand Down Expand Up @@ -247,6 +258,7 @@ typedef struct BrightonWindow {
/* CC value mapping tables */
u_char valuemap[128][128];
int kbdmap[256][2];
brightonKeymapFilter* filter;
int dcTimeout;
} brightonWindow;

Expand Down Expand Up @@ -369,5 +381,8 @@ extern void brightonfree(void *);

extern void brightonRegisterController(brightonDevice *);

extern void* brightonFreeKeymapFilter(brightonWindow *);
extern brightonKeymapFilter* brightonCreateKeymapFilter();

#endif /* BRIGHTONINTERNALS_H */

3 changes: 3 additions & 0 deletions libbrighton/brightonWindowMgt.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ int cmapsize, int flags, int quality, int gs, int x, int y)
bwin->next = winlist;
winlist = bwin;

bwin->filter = brightonCreateKeymapFilter();

/*
* Force a fake size to ensure the first configure notify is picked up.
*/
Expand Down Expand Up @@ -145,6 +147,7 @@ brightonDestroyWindow(brightonWindow *bwin)
bwin->bitmaps->name);

bwin->flags = 0;
brightonFreeKeymapFilter(bwin);
brightonfree(bwin);
}

0 comments on commit 3a01f53

Please sign in to comment.