|
Post by alexfish on May 30, 2020 14:57:10 GMT 1
Hi Peter
Does BaCon have a method of reporting pixel sizes of a terminal ?
in my version of a pseudo terminal I am setting the ioctl using 'struct winsize ws'
Like so
rc = tcgetattr(fds, &slave_orig_term_settings);
new_term_settings = slave_orig_term_settings; cfmakeraw (&new_term_settings); tcsetattr (fds, TCSANOW, &new_term_settings); memset(&ws, 0, sizeof(ws)); ws.ws_col = TERM_COLS; ws.ws_row = TERM_ROWS; ws.ws_xpixel = TERM_COL_PIXELS; ws.ws_ypixel = TERM_ROW_PIXELS;
if (ioctl(fds, TIOCSWINSZ, &ws) < 0) { Print "Failed"
}
can get results from bacon using
PRINT "Columns , Rows ", COLUMNS, ",", ROWS results
Columns , Rows 87,23
if 'No method' , would it be possible for BaCon to Have One.
BR Alex
|
|
|
Post by Pjot on May 30, 2020 17:57:09 GMT 1
Hi Alex, It seems that the libc source code does not use those fields. Console sizes usually are calculated in terms of characters. For pixel sizes, maybe it is better to use a canvas... BR Peter
|
|
|
Post by alexfish on May 30, 2020 20:47:43 GMT 1
Hi Peter
Well Think you are correct , since I tried the "TIOCGWINSZ" got a fail on the write to; re the pixels
but since , I also found that the 'struct winsize' shows only two fields
odd ball in this arena is xterm
using this ::
struct winsize sz; ioctl(0, TIOCGWINSZ, &sz);
this will print all four fields from the xterm , and fails in RPI 'lxterminal' and 'gtk vte'
and yes can do this internally to the pseudo terminal , from the canvas
IE
width = widget->allocation.width; height = widget->allocation.height;
this relates in size of char inks : so from the Pango layout draw routine I have those Variables mention above
TERM_ROWS= height/CharHeight; TERM_COLS= width/CharWidth; TERM_ROW_PIXELS=TERM_ROWS*CharHeight; TERM_COL_PIXELS=TERM_COLS*CharWidth;
BR Alex
Example of pixels :: works in Xterm
PROTO ioctl
LOCAL ws TYPE struct winsize ioctl(0, TIOCGWINSZ, &ws)
PRINT "pixels " , ws.ws_xpixel , ":" , ws.ws_ypixel
|
|
|
Post by alexfish on May 30, 2020 21:42:18 GMT 1
decided to hack around the source code of xterm ?
found some bits under HACKS and found these
#if defined(TIOCSWINSZ) #define USE_STRUCT_WINSIZE 1 #define TTYSIZE_STRUCT struct winsize #define GET_TTYSIZE(fd, data) ioctl(fd, TIOCGWINSZ, (char *) &data) #define SET_TTYSIZE(fd, data) ioctl(fd, TIOCSWINSZ, (char *) &data) #define TTYSIZE_COLS(data) data.ws_col #define TTYSIZE_ROWS(data) data.ws_row #endif /* TIOCSWINSZ */ #endif /* TTYSIZE_STRUCT */
#ifndef USE_STRUCT_WINSIZE #error "There is a configuration error with struct winsize ifdef" #endif
/* "resize" depends upon order of assignments in this macro */ #ifdef USE_STRUCT_WINSIZE #define setup_winsize(ts, rows, cols, height, width) \ (ts).ws_xpixel = (ttySize_t) (width), \ (ts).ws_ypixel = (ttySize_t) (height), \ TTYSIZE_ROWS(ts) = (ttySize_t) (rows), \ TTYSIZE_COLS(ts) = (ttySize_t) (cols) #else #define setup_winsize(ts, rows, cols, height, width) \ TTYSIZE_ROWS(ts) = (ttySize_t) (rows), \ TTYSIZE_COLS(ts) = (ttySize_t) (cols) #endif
BR Alex
|
|
|
Post by alexfish on May 30, 2020 22:33:18 GMT 1
Hi All do not need the hacks the code inside the pseudo terminal rc = tcgetattr(fds, &slave_orig_term_settings);
new_term_settings = slave_orig_term_settings; cfmakeraw (&new_term_settings); tcsetattr (fds, TCSANOW, &new_term_settings); memset(&ws, 0, sizeof(ws)); ws.ws_col = TERM_COLS; ws.ws_row = TERM_ROWS; ws.ws_xpixel = TERM_COL_PIXELS; ws.ws_ypixel = TERM_ROW_PIXELS;
if (ioctl(fds, TIOCSWINSZ, &ws) < 0) { Print "Failed"
} and the bacon code PROTO ioctl
LOCAL ws TYPE struct winsize ioctl(0, TIOCGWINSZ, &ws)
PRINT "pixels " , ws.ws_xpixel , ":" , ws.ws_ypixel
the results pixels 783:368 & + rows PROTO ioctl
LOCAL ws TYPE struct winsize ioctl(0, TIOCGWINSZ, &ws)
PRINT "pixels " , ws.ws_xpixel , ":" , ws.ws_ypixel PRINT "col : row " , ws.ws_col , ":" , ws.ws_row results pixels 783:368 col : row 87:23
BR Alex Picky of first section of code Attachments:
|
|
|
Post by Pjot on May 31, 2020 7:48:47 GMT 1
Hi Alex, Good find, but your code seems to work for XTerm only, which is one of the more superior terminal programs around. However, when I test your code with rxvt, lxterminal, XFCE terminal, Gnome Terminal, or the plain Linux console terminal, your code produces 0,0 for the pixel sizes... Best regards Peter
|
|
|
Post by alexfish on May 31, 2020 9:41:30 GMT 1
Hi Peter xterm yes, also the code works with urxvt ktermrxvt rxvt-unicode + AlexTerm Forgot this one mlterm other term's stterm BR Alex
|
|