获取 linux/Gnome 上多个屏幕的屏幕布局

发布于 2025-01-04 03:03:23 字数 256 浏览 2 评论 0原文

我正在尝试为多个屏幕创建一个应用程序,但到目前为止我找不到找到辅助屏幕位置的方法(相对于主屏幕的 x 和 y 坐标)。

我更喜欢使用 python 或 bash (通过库/框架就可以了)。我还检查了 xorg.conf,它没有反映我当前的屏幕设置。

我正在使用 Ubuntu 11.10(我相信默认是 Gnome 2),使用 compiz 作为窗口管理器。重复一遍,我的问题是如何最好通过 python 或 bash 获取所有显示器的屏幕布局(相对于主屏幕的坐标)。

I am trying to create an application for multiple screens however I so far cannot find a way to locate the secondary screens position (relative to the primary screen by x and y coordinates).

I prefer to use python or bash (via libraries/frameworks are fine). I also checked with xorg.conf and it doesn't reflect my current screen setup.

I am using Ubuntu 11.10 (default Gnome 2 I believe), using compiz as the window manager. So to repeat, my question is how to get the screen layout (coordinates relative to primary screen) of all the monitors preferably by python or bash.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心 2025-01-11 03:03:23

没关系,我用 Pyqt 代替。这是一些代码...

from PyQt4.QtGui import QApplication, QPixmap
desktop = QApplication.desktop()
screenRect = desktop.screenGeometry(1)   #2nd monitor
print screenRect.x(), screenRect.y()   #returns the x and y of that screen

Nevermind, I used Pyqt instead. Here is some code...

from PyQt4.QtGui import QApplication, QPixmap
desktop = QApplication.desktop()
screenRect = desktop.screenGeometry(1)   #2nd monitor
print screenRect.x(), screenRect.y()   #returns the x and y of that screen
月竹挽风 2025-01-11 03:03:23

Python 绑定解决方案

因此,从这里您可以下载 python 的 xrandr 绑定: https://launchpad.net/python- xrandr

# Import the module
from xrandr import xrandr

# Get a screen object to work with
screen = xrandr.get_current_screen()

# Get the active output objects as a list
active_outputs = [o for o in screen.get_outputs() if o.is_active()]

这是我所了解的。我希望它能让您开始:-) 我现在只连接了一个屏幕...

解析数据解决方案

正如我在上面的评论中提到的,另一个解决方案是解析命令 xrandr 的输出> 乍一看应该很简单……

Python binding solution

So, from here you can download the xrandr bindings for python: https://launchpad.net/python-xrandr

# Import the module
from xrandr import xrandr

# Get a screen object to work with
screen = xrandr.get_current_screen()

# Get the active output objects as a list
active_outputs = [o for o in screen.get_outputs() if o.is_active()]

This was as far as I got playing around a little. I hope it will get you started :-) I only have one screen connected right now...

Parsing data solution

The other solution, as I mentioned in my comment above is to parse the output of the command xrandr it looks like it should be pretty simple from just taking a glance at it...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文