I am accessing /dev/fb0, the screen's frame buffer, in console mode, Debian 10, using a HP Envy Touchsmart laptop, using fwrite standard C function.

I read this page: https://techoverflow.net/2015/06/21/querying-framebuffer-resolution-in-linux/

It states that "cat /sys/class/graphics/fb0/virtual_size" should return fb0's dimensions.

It returns 1366 x 768 pixels. This is my actual screen resolution. So good so far.

But when I write into /dev/fb0, I actually need to write 1376 pixels before I start a new row.

Please note pixels are 32-bit packets, so it does not look like there is an underlying scanline alignment issue. We are talking about a difference of 10 times 4 bytes, i.e. 40 bytes, which is a lot.

Where does this discrepancy come from? How do I get the scanline width information without having to find out visually?


You can probably find the value in /sys/class/graphics/fb0/stride which is the length of the line in bytes according to the source. You need to divide by the bits_per_pixel divided by 8 to get the stride in pixels.

  • Brilliant! I ended up finding about fb.h and ioctl calls, but your answer is exactly what I needed. Thanks. – Winston Sep 4 '19 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.