linux c++ 通过xcb库获取屏幕大小
#include <stdio.h> #include <xcb/xcb.h> /** clang++ main.cpp -o main `pkg-config --cflags --libs xcb` -lxcb-randr landv@win7-pc:~/Desktop$ ./main Informations of screen 416: width.........: 1920 height........: 1080 white pixel...: 16777215 black pixel...: 0 */ int main (){ /* Open the connection to the X server. Use the DISPLAY environment variable */ int i, screenNum; xcb_connection_t *connection = xcb_connect (NULL, &screenNum); /* Get the screen whose number is screenNum */ const xcb_setup_t *setup = xcb_get_setup (connection); xcb_screen_iterator_t iter = xcb_setup_roots_iterator (setup); // we want the screen at index screenNum of the iterator for (i = 0; i < screenNum; ++i) { xcb_screen_next (&iter); } xcb_screen_t *screen = iter.data; /* report */ printf (" "); printf ("Informations of screen %u: ", screen->root); printf (" width.........: %d ", screen->width_in_pixels); printf (" height........: %d ", screen->height_in_pixels); printf (" white pixel...: %u ", screen->white_pixel); printf (" black pixel...: %u ", screen->black_pixel); printf (" "); return 0; }