/* fbpan — set /dev/fb0 yoffset (pan) to argv[1] and print the result. */ #include #include #include #include #include #include #include #include #define GETV 0x4600 #define PAN 0x4606 int main(int argc, char **argv) { int fd = open("/dev/fb0", O_RDWR); if (fd < 0) { perror("open"); return 1; } unsigned char v[160]; memset(v,0,sizeof v); if (ioctl(fd, GETV, v) < 0) { perror("getvar"); return 1; } uint32_t orig = *(uint32_t*)(v+20); uint32_t yres = *(uint32_t*)(v+4); uint32_t target = argc > 1 ? (uint32_t)atoi(argv[1]) : 0; if (yres) target = (target / yres) * yres; /* snap to whole-screen offset */ *(uint32_t*)(v+16) = 0; *(uint32_t*)(v+20) = target; errno = 0; int r = ioctl(fd, PAN, v); int e = errno; unsigned char w[160]; memset(w,0,sizeof w); ioctl(fd, GETV, w); printf("pan(%u): r=%d errno=%d(%s) yoffset %u -> %u (yres=%u)\n", target, r, e, strerror(e), orig, *(uint32_t*)(w+20), yres); close(fd); return 0; }