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 ("\n");
        printf ("Informations of screen %u:\n", screen->root);
        printf ("  width.........: %d\n", screen->width_in_pixels);
        printf ("  height........: %d\n", screen->height_in_pixels);
        printf ("  white pixel...: %u\n", screen->white_pixel);
        printf ("  black pixel...: %u\n", screen->black_pixel);
        printf ("\n");
 
        return 0;
    }

 

 
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐