Actually fill ws_xpixels/ws_ypixels, and use them for cat-img

This commit is contained in:
Kevin Lange 2017-01-07 15:27:55 +09:00
parent 91e5d56841
commit 169cd55095
3 changed files with 8 additions and 13 deletions

View File

@ -12,15 +12,10 @@
#include "gui/terminal/lib/termemu.h"
void get_cell_sizes(int * w, int * h) {
struct termios old;
tcgetattr(fileno(stdin), &old);
struct termios new = old;
new.c_lflag &= (~ICANON & ~ECHO);
tcsetattr(fileno(stdin), TCSAFLUSH, &new);
printf("\033Tq");
fflush(stdout);
scanf("\033T%d;%dq", w, h);
tcsetattr(fileno(stdin), TCSAFLUSH, &old);
struct winsize wsz;
ioctl(0, TIOCGWINSZ, &wsz);
*w = wsz.ws_xpixel / wsz.ws_col;
*h = wsz.ws_ypixel / wsz.ws_row;
}
void raw_output(void) {

View File

@ -1194,6 +1194,8 @@ void reinit(int send_sig) {
struct winsize w;
w.ws_row = term_height;
w.ws_col = term_width;
w.ws_xpixel = term_width * char_width;
w.ws_ypixel = term_height * char_height;
ioctl(fd_master, TIOCSWINSZ, &w);
if (send_sig) {

View File

@ -8,9 +8,7 @@
int main(int argc, char * argv[]) {
struct winsize w;
int width, height;
ioctl(0, TIOCGWINSZ, &w);
width = w.ws_col;
height = w.ws_row;
printf("Terminal is %dx%d\n", width, height);
printf("Terminal is %dx%d (%d px x %d px)\n", w.ws_col, w.ws_row, w.ws_xpixel, w.ws_ypixel);
return 0;
}