Improve test/handle_keys.cxx

- colorize output
- improve formatting
- log status of Fl::OPTION_SIMPLE_ZOOM_SHORTCUT
This commit is contained in:
Albrecht Schlosser
2024-07-01 00:30:35 +02:00
parent 54f44d5ac9
commit d411d39092
+26 -6
View File
@@ -35,9 +35,11 @@ Fl_Check_Button *scaling = NULL;
// Text in the headline and after clearing the terminal buffer. For alignment ... // Text in the headline and after clearing the terminal buffer. For alignment ...
// 1 2 3 4 5 6 7 8 // 1 2 3 4 5 6 7 8
// 12345678901234567890123456789012345678901234567890123456789012345678901234567890 // 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345
static const char *headline_text = static const char *headline_text =
"[nnn] Event Key Name, Flags: C A S M N L Text Unicode UTF-8/hex"; "[nnn] Event Key Name, Flags: C A S M N L Text Unicode UTF-8/hex";
static const int lkn = 14; // length of key name field
// Tooltip for headline and terminal widgets // Tooltip for headline and terminal widgets
static const char *tt = static const char *tt =
@@ -101,7 +103,9 @@ struct keycode_table {
const char *get_keyname(int k, int &lg) { const char *get_keyname(int k, int &lg) {
static char buffer[32]; static char buffer[32];
lg = 0;
if (!k) { if (!k) {
lg = 1;
return "0"; return "0";
} }
else if (k < 32) { // control character else if (k < 32) { // control character
@@ -197,12 +201,15 @@ int app::print_event(int ev) {
switch(ev) { switch(ev) {
case FL_KEYBOARD: case FL_KEYBOARD:
if (!keydown->value()) return 0; if (!keydown->value()) return 0;
tty->textfgcolor(FL_BLACK);
break; break;
case FL_KEYUP: case FL_KEYUP:
if (!keyup->value()) return 0; if (!keyup->value()) return 0;
tty->textfgcolor(FL_BLUE);
break; break;
case FL_SHORTCUT: case FL_SHORTCUT:
if (!shortcut->value()) return 0; if (!shortcut->value()) return 0;
tty->textfgcolor(0x00aa0000); // dark green
break; break;
default: default:
return 0; return 0;
@@ -231,11 +238,16 @@ int app::handle(int ev) {
char numlk = (Fl::event_state() & FL_NUM_LOCK) ? 'N' : '.'; char numlk = (Fl::event_state() & FL_NUM_LOCK) ? 'N' : '.';
char capslk = (Fl::event_state() & FL_CAPS_LOCK) ? 'L' : '.'; char capslk = (Fl::event_state() & FL_CAPS_LOCK) ? 'L' : '.';
tty->printf("%06x ", ekey); // event key number (hex)
int lg = 0; int lg = 0;
char ekns[12]; // event key (hex) as string
sprintf(ekns, "0x%04x", ekey); // may be up to 10 chars
tty->printf("%10s ", ekns); // event key number (hex)
tty->printf("%s", get_keyname(ekey, lg)); tty->printf("%s", get_keyname(ekey, lg));
for (int i = lg; i < 14; i++) { if (lg < lkn) {
tty->printf(" "); for (int i = 0; i < lkn - lg; i++) {
tty->append_ascii(" ");
}
} }
tty->printf("%c %c %c %c %c %c ", ctrl, alt, shift, meta, numlk, capslk); tty->printf("%c %c %c %c %c %c ", ctrl, alt, shift, meta, numlk, capslk);
@@ -254,6 +266,7 @@ int app::handle(int ev) {
} else { } else {
tty->printf("'' "); tty->printf("'' ");
} }
tty->textfgcolor(FL_BLACK);
tty->printf("\n"); tty->printf("\n");
return res; return res;
} // app::handle() } // app::handle()
@@ -302,6 +315,12 @@ void toggle_cb(Fl_Widget *w, void *) {
void toggle_scaling(Fl_Widget *w, void *v) { void toggle_scaling(Fl_Widget *w, void *v) {
int toggle = ((Fl_Button*)w)->value() ? 1 : 0; int toggle = ((Fl_Button*)w)->value() ? 1 : 0;
Fl::keyboard_screen_scaling(toggle); Fl::keyboard_screen_scaling(toggle);
if (toggle) {
Terminal *tty = ((app *)w->window())->tty;
int simple_zoom = Fl::option(Fl::OPTION_SIMPLE_ZOOM_SHORTCUT);
tty->printf("GUI-Scaling = %s, OPTION_SIMPLE_ZOOM_SHORTCUT = %s\n",
toggle ? "ON" : "OFF", simple_zoom ? "ON" : "OFF");
}
toggle_cb(w, v); // give focus to 'app' toggle_cb(w, v); // give focus to 'app'
} }
@@ -319,7 +338,7 @@ int main(int argc, char **argv) {
// Set an appropriate font for Wine on Linux (test only). // Set an appropriate font for Wine on Linux (test only).
// This is very likely not necessary on a real Windows system // This is very likely not necessary on a real Windows system
#if (1) // test/experimental for wine on Linux (maybe missing fonts) #if (0) // test/experimental for wine on Linux (maybe missing fonts)
#ifdef _WIN32 #ifdef _WIN32
// Fl::set_font(FL_COURIER, " DejaVu Sans Mono"); // DejaVu Mono // Fl::set_font(FL_COURIER, " DejaVu Sans Mono"); // DejaVu Mono
// Fl::set_font(FL_COURIER, "BNimbus Mono PS"); // Nimbus Mono PS bold // Fl::set_font(FL_COURIER, "BNimbus Mono PS"); // Nimbus Mono PS bold
@@ -331,6 +350,7 @@ int main(int argc, char **argv) {
app *win = new app(0, 0, WW, WH); app *win = new app(0, 0, WW, WH);
win->tty->box(FL_DOWN_BOX); win->tty->box(FL_DOWN_BOX);
win->tty->show_unknown(true); win->tty->show_unknown(true);
win->tty->textfgcolor(FL_BLACK);
win->tty->printf("Please press any key ...\n"); win->tty->printf("Please press any key ...\n");
Fl_Grid *grid = new Fl_Grid(0, WH - 75, WW, 75); Fl_Grid *grid = new Fl_Grid(0, WH - 75, WW, 75);