1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add keyboard number selection to chvideomode(1).

This commit is contained in:
Jonas 'Sortie' Termansen 2015-12-27 22:19:36 +01:00
parent 5ba7ce6802
commit 794cfd057a

View file

@ -444,22 +444,22 @@ retry_pick_mode:
if ( settermmode(0, TERMMODE_KBKEY | TERMMODE_UNICODE | TERMMODE_SIGNAL) < 0 ) if ( settermmode(0, TERMMODE_KBKEY | TERMMODE_UNICODE | TERMMODE_SIGNAL) < 0 )
error(1, errno, "settermmode"); error(1, errno, "settermmode");
bool redraw = false;
while ( !redraw && !decided )
{
uint32_t codepoint; uint32_t codepoint;
ssize_t numbytes; ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
int kbkey = 0;
while ( 0 < (numbytes = read(0, &codepoint, sizeof(codepoint))) &&
(kbkey = KBKEY_DECODE(codepoint)) == 0 )
continue;
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
if ( numbytes < 0 ) if ( numbytes < 0 )
error(1, errno, "read"); error(1, errno, "read");
int kbkey = KBKEY_DECODE(codepoint);
if ( kbkey )
{
switch ( kbkey ) switch ( kbkey )
{ {
case KBKEY_ESC: case KBKEY_ESC:
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
printf("\n"); printf("\n");
exit(10); exit(10);
break; break;
@ -468,20 +468,41 @@ retry_pick_mode:
selection--; selection--;
else else
selection = num_modes -1; selection = num_modes -1;
redraw = true;
break; break;
case KBKEY_DOWN: case KBKEY_DOWN:
if ( selection + 1 == num_modes ) if ( selection + 1 == num_modes )
selection = 0; selection = 0;
else else
selection++; selection++;
redraw = true;
break; break;
case KBKEY_ENTER: case KBKEY_ENTER:
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
fgetc(stdin); fgetc(stdin);
printf("\n"); printf("\n");
decided = true; decided = true;
break; break;
} }
} }
else
{
if ( L'0' <= codepoint && codepoint <= '9' )
{
uint32_t requested = codepoint - '0';
if ( requested < num_modes )
{
selection = requested;
redraw = true;
}
}
}
}
if ( settermmode(0, oldtermmode) < 0 )
error(1, errno, "settermmode");
}
struct dispmsg_crtc_mode mode = modes[selection]; struct dispmsg_crtc_mode mode = modes[selection];
if ( mode.control & DISPMSG_CONTROL_OTHER_RESOLUTIONS ) if ( mode.control & DISPMSG_CONTROL_OTHER_RESOLUTIONS )