当前位置: 首页 > article >正文

xrandr源码分析

1、XOpenDisplay 打开xrandr句柄,参数是显示后端xorg或者xwayland,也就是localhost:0.0
dpy = XOpenDisplay (display_name); //XOpenDisplay(":0");

if (dpy == NULL) {
    fprintf (stderr, "Can't open display %s\n", XDisplayName(display_name));
    exit (1);
}
2、RootWindow通过screen下标获取到显示器设备句柄
static int    screen = -1;
if (screen < 0)
    screen = DefaultScreen (dpy);

if (screen >= ScreenCount (dpy)) {
    fprintf (stderr, "Invalid screen number %d (display has %d)\n", screen, ScreenCount (dpy));
    exit (1);
}

root = RootWindow (dpy, screen);
3、获取屏幕信息XRRScreenResources(同时获取XRRGetScreenSizeRange最大,最小分辨率,XRRGetScreenResourcesCurrent/XRRGetScreenResources当前分辨率)
static void
get_screen (Bool current)
{
    if (!has_1_2)
        fatal ("Server RandR version before 1.2\n");

    //已经获取到了,直接返回static XRRScreenResources  *res;
    if (res) 
        return;

    XRRGetScreenSizeRange (dpy, root, &minWidth, &minHeight, &maxWidth, &maxHeight);
    if (current)
        res = XRRGetScreenResourcesCurrent (dpy, root);
    else
        res = XRRGetScreenResources (dpy, root);
    if (!res) 
        fatal ("could not get screen resources");
}
4、获取crtcs
typedef struct _XRRPanning {
    Time            timestamp;
    unsigned int left;
    unsigned int top;
    unsigned int width;
    unsigned int height;
    unsigned int track_left;
    unsigned int track_top;
    unsigned int track_width;
    unsigned int track_height;
    int          border_left;
    int          border_top;
    int          border_right;
    int          border_bottom;
} XRRPanning;

typedef struct _XRRModeInfo {
    RRMode        id;
    unsigned int    width;
    unsigned int    height;
    unsigned long    dotClock;
    unsigned int    hSyncStart;
    unsigned int    hSyncEnd;
    unsigned int    hTotal;
    unsigned int    hSkew;
    unsigned int    vSyncStart;
    unsigned int    vSyncEnd;
    unsigned int    vTotal;
    char        *name;
    unsigned int    nameLength;
    XRRModeFlags    modeFlags;
} XRRModeInfo;

typedef struct _XRRCrtcInfo {
    Time        timestamp;
    int            x, y;
    unsigned int    width, height;
    RRMode        mode;
    Rotation        rotation;
    int            noutput;
    RROutput        *outputs;
    Rotation        rotations;
    int            npossible;
    RROutput        *possible;
} XRRCrtcInfo;

struct _crtc {
    name_t        crtc;
    Bool        changing;
    XRRCrtcInfo        *crtc_info;
    XRRModeInfo        *mode_info;
    XRRPanning      *panning_info;
    int            x;
    int            y;
    Rotation        rotation;
    output_t        **outputs;
    int            noutput;
    transform_t        current_transform, pending_transform;
};

typedef struct _crtc crtc_t;

static void
get_crtcs (void)
{
    num_crtcs = res->ncrtc;
    crtcs = calloc (num_crtcs, sizeof (crtc_t)); //保存到crtcs
    if (!crtcs) 
        fatal ("out of memory\n");
    
    for (int c = 0; c < res->ncrtc; c++)
    {
        XRRCrtcInfo *crtc_info = XRRGetCrtcInfo (dpy, res, res->crtcs[c]);
        XRRCrtcTransformAttributes  *attr;
        XRRPanning  *panning_info = NULL;
        if (has_1_3) {
            XRRPanning zero;
            memset(&zero, 0, sizeof(zero));
            panning_info = XRRGetPanning  (dpy, res, res->crtcs[c]);
            zero.timestamp = panning_info->timestamp;
            if (!memcmp(panning_info, &zero, sizeof(zero))) {
                Xfree(panning_info);
                panning_info = NULL;
            }
        }

        set_name_xid (&crtcs[c].crtc, res->crtcs[c]);
        set_name_index (&crtcs[c].crtc, c);
        if (!crtc_info)
            fatal ("could not get crtc 0x%lx information\n", res->crtcs[c]);

        crtcs[c].crtc_info = crtc_info;
        crtcs[c].panning_info = panning_info;
        if (crtc_info->mode == None)
        {
            crtcs[c].mode_info = NULL;
            crtcs[c].x = 0;
            crtcs[c].y = 0;
            crtcs[c].rotation = RR_Rotate_0;
        }

        if (XRRGetCrtcTransform (dpy, res->crtcs[c], &attr) && attr) {
            set_transform (&crtcs[c].current_transform, &attr->currentTransform, attr->currentFilter, attr->currentParams, attr->currentNparams);
            XFree (attr);
        }else{
            init_transform (&crtcs[c].current_transform);
        }
        copy_transform (&crtcs[c].pending_transform, &crtcs[c].current_transform);
    }
}

http://www.kler.cn/a/395793.html

相关文章:

  • redis linux 安装
  • 三:网络为什么要分层:OSI模型与TCP/IP模型
  • java算法性能调优:详尽探讨时间复杂度与空间复杂度的分析与优化“
  • SQL面试题——蚂蚁SQL面试题 连续3天减少碳排放量不低于100的用户
  • 深度学习之pytorch常见的学习率绘制
  • 【MYSQL】数据库日志 (了解即可)
  • finalshell的使用
  • Java集合框架高频面试问题精粹(下篇)
  • NodeJS 百度智能云文本转语音(实测)
  • 如何构建高效的知识库系统?实现智能信息管理
  • i春秋-登陆(sql盲注爆字段,.git缓存利用)
  • 【Rust 编程语言工具】rustup-init.exe 安装与使用指南
  • 如何在 Ubuntu 上安装 Jupyter Notebook
  • 部署Apache Doris
  • C++11新特性:lambda表达式,包装器,新的类功能
  • 富格林:正确应付阻挠虚假交易
  • 如何用Java爬虫“采集”商品订单详情的编程旅程
  • C++中 ,new int(10),new int(),new int[10],new int[10]()
  • 除了网页标题,还能用爬虫抓取哪些信息?
  • 实时数据流的革命:分布式数据库的挑战与实践
  • 图像处理之cornerdetection(角点检测)综述
  • 从cityengine到unreal,游戏引擎助力城市设计
  • Linux服务器下连接kingbase并执行SQL的脚本
  • 关于指针对象的问题
  • 搜维尔科技:TOUCH力反馈设备睿尔曼机械臂,遥操作机械臂
  • 实现 Toy-React , 实现 JSX 渲染