Skip to content
Snippets Groups Projects
Commit ecd61d64 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Deal with consile resizing

This doesn't fix the terrible crap Windows does to the contents of
the console yet though (sigh).
parent 088948e0
Branches
Tags
No related merge requests found
Pipeline #6902 passed
...@@ -257,7 +257,7 @@ static int win32_keyboardio(int isgetch) ...@@ -257,7 +257,7 @@ static int win32_keyboardio(int isgetch)
break; break;
} }
if(isgetch) if(isgetch)
SLEEP(1); WaitForSingleObject(h, 1000);
else else
return(FALSE); return(FALSE);
} }
...@@ -266,10 +266,18 @@ static int win32_keyboardio(int isgetch) ...@@ -266,10 +266,18 @@ static int win32_keyboardio(int isgetch)
continue; continue;
if(!ReadConsoleInput(h, &input, 1, &num) if(!ReadConsoleInput(h, &input, 1, &num)
|| !num || (input.EventType!=KEY_EVENT && input.EventType!=MOUSE_EVENT)) || !num || (input.EventType!=KEY_EVENT && input.EventType!=MOUSE_EVENT && input.EventType != WINDOW_BUFFER_SIZE_EVENT))
continue; continue;
switch(input.EventType) { switch(input.EventType) {
case WINDOW_BUFFER_SIZE_EVENT:
if (input.Event.WindowBufferSizeEvent.dwSize.X != cio_textinfo.screenwidth || input.Event.WindowBufferSizeEvent.dwSize.Y != cio_textinfo.screenheight) {
struct ciolib_screen *screen = savescreen();
win32_textmode(cio_textinfo.currmode);
restorescreen(screen);
freescreen(screen);
}
break;
case KEY_EVENT: case KEY_EVENT:
#ifdef DEBUG_KEY_EVENTS #ifdef DEBUG_KEY_EVENTS
...@@ -496,7 +504,7 @@ void win32_resume(void) ...@@ -496,7 +504,7 @@ void win32_resume(void)
DWORD conmode; DWORD conmode;
HANDLE h; HANDLE h;
conmode=ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS; conmode=ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS|ENABLE_WINDOW_INPUT;
if((h=GetStdHandle(STD_INPUT_HANDLE)) != INVALID_HANDLE_VALUE) if((h=GetStdHandle(STD_INPUT_HANDLE)) != INVALID_HANDLE_VALUE)
SetConsoleMode(h, conmode); SetConsoleMode(h, conmode);
...@@ -528,7 +536,7 @@ int win32_initciolib(int inmode) ...@@ -528,7 +536,7 @@ int win32_initciolib(int inmode)
if((h=GetStdHandle(STD_INPUT_HANDLE))==INVALID_HANDLE_VALUE if((h=GetStdHandle(STD_INPUT_HANDLE))==INVALID_HANDLE_VALUE
|| !GetConsoleMode(h, &orig_in_conmode)) || !GetConsoleMode(h, &orig_in_conmode))
return(0); return(0);
conmode=ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS; conmode=ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS|ENABLE_WINDOW_INPUT;
if(!SetConsoleMode(h, conmode)) if(!SetConsoleMode(h, conmode))
return(0); return(0);
...@@ -653,8 +661,11 @@ void win32_textmode(int mode) ...@@ -653,8 +661,11 @@ void win32_textmode(int mode)
if ((h=GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) if ((h=GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE)
return; return;
if (!SetConsoleScreenBufferSize(h,sz)) if (!SetConsoleScreenBufferSize(h,sz)) {
return; // Note: This fails and returns here with large windows (e.g. width > 255) // Apparently this fails if it's already the specified size.
if (GetLastError() != 0xb7)
return; // Note: This fails and returns here with large windows (e.g. width > 255)
}
if (!SetConsoleWindowInfo(h,TRUE,&rc)) if (!SetConsoleWindowInfo(h,TRUE,&rc))
return; return;
sz.X=vparams[modeidx].cols; sz.X=vparams[modeidx].cols;
...@@ -689,8 +700,7 @@ void win32_textmode(int mode) ...@@ -689,8 +700,7 @@ void win32_textmode(int mode)
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
int slen; int slen;
char seq[30]; char seq[30];
int dac = palettes[vparams[modeidx].palette][i]; slen = snprintf(seq, sizeof(seq), "\x1b]4;%d;rgb:%02hhx/%02hhx/%02hhx\x1b\\", i, dac_default[i].red, dac_default[i].green, dac_default[i].blue);
slen = snprintf(seq, sizeof(seq), "\x1b]4;%d;rgb:%02hhx/%02hhx/%02hhx\x1b\\", i, dac_default[dac].red, dac_default[dac].green, dac_default[dac].blue);
if (slen > -1) if (slen > -1)
WriteConsoleA(h, seq, slen, NULL, NULL); WriteConsoleA(h, seq, slen, NULL, NULL);
} }
...@@ -950,7 +960,7 @@ int win32_setpalette(uint32_t entry, uint16_t r, uint16_t g, uint16_t b) ...@@ -950,7 +960,7 @@ int win32_setpalette(uint32_t entry, uint16_t r, uint16_t g, uint16_t b)
char seq[30]; char seq[30];
slen = snprintf(seq, sizeof(seq), "\x1b]4;%d;rgb:%02hhx/%02hhx/%02hhx\x1b\\", entry, r >> 8, g >> 8, b >> 8); slen = snprintf(seq, sizeof(seq), "\x1b]4;%d;rgb:%02hhx/%02hhx/%02hhx\x1b\\", entry, r >> 8, g >> 8, b >> 8);
if (slen > -1) { if (slen > -1) {
if (WriteConsole(h, seq, slen, NULL, NULL)) if (WriteConsoleA(h, seq, slen, NULL, NULL))
ret = 1; ret = 1;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment