extract cell-pixel geometry from linux framebuffer console #1369

pull/1859/head
nick black 3 years ago
parent a95b28c2e5
commit 45c6a229ce
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -417,22 +417,33 @@ bool is_linux_console(int fd, unsigned no_font_changes, bool* quadrants){
return true;
}
int get_linux_fb_pixelgeom(int fd, unsigned* ypix, unsigned *xpix){
struct fb_var_screeninfo fbi = {};
if(ioctl(fd, FBIOGET_VSCREENINFO, &fbi)){
logwarn("Couldn't get framebuffer info from %d (%s?)\n", fd, strerror(errno));
return -1;
}
loginfo("Linux framebuffer geometry: %dx%d\n", fbi.yres, fbi.xres);
*ypix = fbi.yres;
*xpix = fbi.xres;
return 0;
}
bool is_linux_framebuffer(tinfo* ti){
// FIXME there might be multiple framebuffers present; how do we determine
// which one is ours?
const char* dev = "/dev/fb0";
loginfo("Checking for Linux framebuffer at %s\n", dev);
int fd = open(dev, O_RDWR | O_CLOEXEC);
if(fd < 0){
logdebug("Couldn't open framebuffer device %s\n", dev);
return false;
}
struct fb_var_screeninfo fbi = {};
if(ioctl(fd, FBIOGET_VSCREENINFO, &fbi)){
logdebug("Couldn't get framebuffer info from %s (%s?)\n", dev, strerror(errno));
unsigned y, x;
if(get_linux_fb_pixelgeom(fd, &y, &x)){
close(fd);
return false;
}
loginfo("Linux framebuffer detected at %s: %dx%d\n", dev, fbi.yres, fbi.xres);
ti->linux_fb_fd = fd;
return true;
}
@ -448,4 +459,11 @@ bool is_linux_framebuffer(tinfo* ti){
(void)ti;
return false;
}
int get_linux_fb_pixelgeom(int fd, unsigned* ypix, unsigned *xpix){
(void)fd;
(void)ypix;
(void)xpix;
return -1;
}
#endif

@ -11,10 +11,14 @@ struct tinfo;
bool is_linux_console(int fd, unsigned no_font_changes, bool* quadrants);
// if is_linux_console returned true, call this to determine whether it is
// a drawable framebuffer console. do not call if not is_linux_console!
// if is_linux_console() returned true, call this to determine whether it is
// a drawable framebuffer console. do not call if not a verified console!
bool is_linux_framebuffer(struct tinfo* ti);
// call only on an fd where is_linux_framebuffer() returned true. gets the
// pixel geometry for the visual area.
int get_linux_fb_pixelgeom(int fd, unsigned* ypix, unsigned *xpix);
#ifdef __cplusplus
}
#endif

@ -1,4 +1,5 @@
#include "input.h"
#include "linux.h"
#include "version.h"
#include "egcpool.h"
#include "internal.h"
@ -247,8 +248,15 @@ int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache,
*cols = ws.ws_col;
}
if(tcache){
tcache->cellpixy = ws.ws_row ? ws.ws_ypixel / ws.ws_row : 0;
tcache->cellpixx = ws.ws_col ? ws.ws_xpixel / ws.ws_col : 0;
unsigned y, x;
if(tcache->linux_fb_fd >= 0){
get_linux_fb_pixelgeom(tcache->linux_fb_fd, &y, &x);
}else{
y = ws.ws_ypixel;
x = ws.ws_xpixel;
}
tcache->cellpixy = ws.ws_row ? y / ws.ws_row : 0;
tcache->cellpixx = ws.ws_col ? x / ws.ws_col : 0;
if(tcache->cellpixy == 0 || tcache->cellpixx == 0){
tcache->pixel_draw = NULL; // disable support
}

Loading…
Cancel
Save