Skip to content

Commit

Permalink
Add configuration item to set keyboard name.
Browse files Browse the repository at this point in the history
  • Loading branch information
hirakuro committed Dec 31, 2017
1 parent 35b2ec1 commit 8626ee0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
8 changes: 7 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ Boolean load_config(char* path)
set_inputdevice_path(devpath);
}
} else */
if (strcasecmp(key, "LOYAKEY")==0) {
if (strcasecmp(key, "KEYBOARDNAME")==0) {
printf("KEYBOARDNAME: %s\n", value);
set_keyboardname(value);
} else if (strcasecmp(key, "LOYAKEY")==0) {
kc = keyname_to_code(value);
if (kc != 0) {
printf("LOYAKEY: %s\n", value);
Expand Down Expand Up @@ -399,6 +402,9 @@ Boolean save_config(char *path)
if ((fp = fopen(path, "w")) == NULL) {
return FALSE;
}
fprintf(fp, "# キーボード名\n");
fprintf(fp, "#KEYBOARDNAME=XXXX\n");
fprintf(fp, "\n");
fprintf(fp, "# 左親指キー (スペースキー=SPACE, 無変換キー=MUHENKAN)\n");
fprintf(fp, "LOYAKEY=SPACE\n");
fprintf(fp, "\n");
Expand Down
67 changes: 45 additions & 22 deletions src/oyainput.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ static int paused = 0;
static int imtype = 0; // (0: none, 1:fcitx, 2:ibus, 3:uim)
static __u16 on_keycode = 0;
static __u16 off_keycode = 0;
static char keyboardname[BUFSIZE+1] = {};

int get_kbdevie_output() {
return fdo;
}

void set_keyboardname(char* name) {
strncpy(keyboardname, name, BUFSIZE);
}

const char* get_keyboardname() {
return keyboardname;
}

int get_imtype() {
return imtype;
}
Expand Down Expand Up @@ -187,28 +196,6 @@ int main(int argc, char *argv[]) {
// initialize oyayubi state by default values.
oyayubi_state_init();

// try search keyboard input device event file form /dev/input/event0-9
KBDDEVINFO devs[5];
int devcnt;
int usedevno = 0;
find_kbdevent_info(devs, &devcnt, 5);
if (devcnt == 0) {
die("error: Cannot find keyboard device.");
} else if (devcnt >= 2) {
printf("multiple keyboard is detected.\n");
for (int i = 0;i < devcnt; i++) {
printf("%d: %s\n", i, devs[i].name);
}
printf("Enter keyboard number:");
scanf("%d", &usedevno);
if (usedevno < 0 || usedevno > devcnt - 1) {
usedevno = 0;
}
}
strcpy(devpath, INPUT_EVENT_PATH);
strcat(devpath, "event");
strncat(devpath, devs[usedevno].devno, 2);

char user_name[BUFSIZE+1] = {};
if (getenv("USER")) {
strncpy(user_name, getenv("USER"), BUFSIZE);
Expand Down Expand Up @@ -237,6 +224,42 @@ int main(int argc, char *argv[]) {
die("error: Cannot load config file!\n");
}

// try search keyboard input device event file form /dev/input/event0-9
KBDDEVINFO devs[5];
int devcnt;
int usedevno = -1;
find_kbdevent_info(devs, &devcnt, 5);
if (devcnt == 0) {
die("error: Cannot find keyboard device.");
} else if (devcnt >= 2) {
printf("multiple keyboard is detected.\n");
if (strlen(get_keyboardname()) > 0) {
for (int i = 0;i < devcnt; i++) {
if (strncmp(devs[i].name, get_keyboardname(), strlen(get_keyboardname())) == 0) {
usedevno = i;
printf("use keyboard '%s'\n", devs[usedevno].name);
break;
}
}
if (usedevno < 0) {
printf("keyboardname '%s' not found\n\n", get_keyboardname());
}
}
if (usedevno < 0) {
for (int i = 0;i < devcnt; i++) {
printf("%d: %s\n", i, devs[i].name);
}
printf("Enter keyboard number:");
scanf("%d", &usedevno);
}
if (usedevno < 0 || usedevno > devcnt - 1) {
usedevno = 0;
}
}
strcpy(devpath, INPUT_EVENT_PATH);
strcat(devpath, "event");
strncat(devpath, devs[usedevno].devno, 2);

if (get_imtype() == 1 &&
0 != system("type fcitx-remote > /dev/null")) {
die("error: fcitx is not installed!");
Expand Down
2 changes: 2 additions & 0 deletions src/oyainput.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/

int get_kbdevie_output();
void set_keyboardname(char* value);
const char* get_keyboardname();
void set_imtype(char* imname);
int get_imtype();
void set_inputdevice_path(char * new_devpath);
Expand Down

0 comments on commit 8626ee0

Please sign in to comment.