In C, how to get the geometry (x, y, width, height) of the active monitor within the screen using X11

夙愿已清 提交于 2019-12-20 07:32:53

问题


All my searches lead to answers about how to get the geometry of the active screen in X11 using C, but that screen may contain many monitors, and there is normally only one screen unless there are many users simultaneously using the same computer.

Those answers about getting the screen geometry are out of date because they don't take into account multiple monitors.

So, how can I get the geometry (x, y, width, height) of the monitor that has the mouse pointer or active window on it? I would want the geometry relative to the screen.


回答1:


You need to use the RandR extension API. Get the source code of the xrandr utility and steal what you need from there. You need XRRGetMonitors function and related data structures. You can also use xrandr to get the information you need on the command line.

I don't know if there's ever such thing as active monitor, because an active window can span several monitors, and a pointer can be in another monitor still. Anyway, the XRRMonitorInfo structure contains all the information about your monitor geometry, including its size (in pixels and mm) and its position on the logical screen, so you can extract a monitor description from a pair of screen coordinates.

See also this answer.



来源:https://stackoverflow.com/questions/43005105/in-c-how-to-get-the-geometry-x-y-width-height-of-the-active-monitor-within

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!