diff --git a/src/draw.c b/src/draw.c index 81d529d..bd556a8 100644 --- a/src/draw.c +++ b/src/draw.c @@ -4,21 +4,29 @@ #include "util.h" #include "config.h" #include "widgets.h" + #include #include #include #include #include #include -#include -#include #include +#include +#include #include +#if defined(__DragonFly__) || defined(__FreeBSD__) +# include +#else /* assume Linux */ +# include +#endif +#if defined(__linux__) // border chars: ┌ └ ┐ ┘ ─ ─ │ │ struct box box_main = {0x250c, 0x2514, 0x2510, 0x2518, 0x2500, 0x2500 ,0x2502, 0x2502}; -// alternative border chars: -// struct box box_main = {'+', '+', '+', '+', '-', '-', '|', '|'}; +#else /* no UTF-8 */ +struct box box_main = {'+', '+', '+', '+', '-', '-', '|', '|'}; +#endif u16 width = 0; u16 height = 0; @@ -207,23 +215,33 @@ void draw_f_commands() // numlock and capslock info void draw_lock_state() { - FILE* console = fopen(config.console_dev, "w"); - - if (console == NULL) + int fd; + if ((fd = open(config.console_dev, O_RDONLY)) < 0) { info_line = lang.err_console_dev; return; } - int fd = fileno(console); - char ret; + bool numlock_on; + bool capslock_on; - ioctl(fd, KDGKBLED, &ret); - fclose(console); +#if defined(__DragonFly__) || defined(__FreeBSD__) + int led; + ioctl(fd, KDGETLED, &led); + numlock_on = led & LED_NUM; + capslock_on = led & LED_CAP; +#else /* Linux */ + char led; + ioctl(fd, KDGKBLED, &led); + numlock_on = led & K_NUMLOCK; + capslock_on = led & K_CAPSLOCK; +#endif + + close(fd); u16 pos_x = width - strlen(lang.numlock); - if (((ret >> 1) & 0x01) == 1) + if (numlock_on) { struct tb_cell* numlock = str_cell(lang.numlock); tb_blit(pos_x, 0, strlen(lang.numlock), 1, numlock); @@ -232,7 +250,7 @@ void draw_lock_state() pos_x -= strlen(lang.capslock) + 1; - if (((ret >> 2) & 0x01) == 1) + if (capslock_on) { struct tb_cell* capslock = str_cell(lang.capslock); tb_blit(pos_x, 0, strlen(lang.capslock), 1, capslock); diff --git a/src/util.c b/src/util.c index 4d14b13..c129683 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,11 @@ #include #include #include -#include +#if defined(__DragonFly__) || defined(__FreeBSD__) +# include +#else /* assume Linux */ +# include +#endif static char* hostname_backup = NULL;