4

私は、GNOMEの下で複数の画面に複数の壁紙を表示するための小さなサイドプロジェクトを開発しています(GNOME自体または他のものでは明らかにできないことです)。私はそれの主要部分を行う方法を理解しました(好奇心旺盛な人のために、ImageMagickコンポーネントを使用して)。構成システムを自動化しようとしています。

そのためには、個々の画面のサイズを判断する方法が必要です。誰かが私にそれを探すためのヒントを教えてもらえますか?Xサーバー自体に情報があると思いますが、プログラムがどのように情報を要求できるかわかりません。

4

4 に答える 4

7

libXineramaその情報を取得できるAPIがあるようです。それについての詳細な情報はまだ見つかりません。

一般的なX.orgプログラミング情報はここにあります(PDFファイル)。によって提供される機能に関する情報は、ここlibXineramaにあります(マンページのオンラインコピーであり、多くの情報は含まれていません)。

これは、Xineramaに接続されている各モニターの寸法とオフセットを取得するために、これらの参照から作成した小さなC++プログラムです。nVidiaTwinViewでも機能します。現在、BigDesktopシステムでテストするためのATIカードを持っていませんが、それでも機能すると思います。

#include <cstdlib>
#include <iostream>

#include <X11/extensions/Xinerama.h>

using std::cout;
using std::endl;

int main(int argc, char *argv[]) {
    bool success=false;
    Display *d=XOpenDisplay(NULL);
    if (d) {
        int dummy1, dummy2;
        if (XineramaQueryExtension(d, &dummy1, &dummy2)) {
            if (XineramaIsActive(d)) {
                int heads=0;
                XineramaScreenInfo *p=XineramaQueryScreens(d, &heads);
                if (heads>0) {
                    for (int x=0; x<heads; ++x)
                        cout << "Head " << x+1 << " of " << heads << ": " <<
                            p[x].width << "x" << p[x].height << " at " <<
                            p[x].x_org << "," << p[x].y_org << endl;
                    success=true;
                } else cout << "XineramaQueryScreens says there aren't any" << endl;
                XFree(p);
            } else cout << "Xinerama not active" << endl;
        } else cout << "No Xinerama extension" << endl;
        XCloseDisplay(d);
    } else cout << "Can't open display" << endl;

    return (success ? EXIT_SUCCESS : EXIT_FAILURE);
}
于 2009-05-07T18:51:27.767 に答える
5

次のようなものを試してください

GdkScreen *screen;
int num_monitors;
int i;

screen = gdk_screen_get_default ();
num_monitors = gdk_screen_get_n_monitors ();

for (i = 0; i < num_monitors; i++) {
    GdkRectangle rect;

    gdk_screen_get_monitor_geometry (screen, i, &rect);
    printf ("monitor %d: offsets (%d, %d), size (%d, %d)\n",
        i,
        rect.x, rect.y,
        rect.width, rect.height);
}

内部的には、これはlibXrandrAPIを使用します。Xineramaは多かれ少なかれ非推奨ですが、それでも機能します。RANDRは、Xで複数のモニターを処理するための新しい方法です。

于 2009-07-16T16:16:17.350 に答える
2

これはTwinViewで機能しますが、他のテストは行っていません。

#!/usr/bin/python
# Print some information about the X environment, the monitor setup, currently active window and cursor position
import gtk.gdk

screen = gtk.gdk.screen_get_default()
print "X default screen size: %d x %d" % (screen.get_width(), screen.get_height())
print "xid of root window: %d" % screen.get_root_window().xid

monitors = int(screen.get_n_monitors())
print "== %d monitors ==" % monitors
for m in range(0, monitors):
    print " - geometry of monitor %d: %s" % (m, screen.get_monitor_geometry(m))

window = screen.get_active_window()
win_x, win_y, win_w, win_h, win_bit_depth = window.get_geometry()
print "active window on monitor: %d" % screen.get_monitor_at_point((win_x+(win_w/2)),(win_y+(win_h/2)))
print "window geometry (x,y,w,h): %d, %d, %d, %d" % (win_x,win_y,win_w,win_h)

display = gtk.gdk.display_get_default()
pointer = display.get_pointer()
print "cursor position (x, y): %d, %d" % (pointer[1], pointer[2])
print "cursor on monitor: %d" % screen.get_monitor_at_point(pointer[1],pointer[2])
于 2010-07-06T22:04:47.777 に答える
1

私は常に「xdpyinfo」コマンドを使用して画面サイズを決定します。コマンドを実行してから、出力の2ページ目または3ページ目を見て、次のように表示されているかどうかを確認します。

screen #0:
  dimensions:    1280x800 pixels (339x212 millimeters)
  resolution:    96x96 dots per inch
  depths (7):    24, 1, 4, 8, 15, 16, 32
  root window id:    0xac
  depth of root window:    24 planes
  ...

このコマンドを外部で実行してテキスト処理で寸法を取得するか、xdpyinfoのコードをすばやくダウンロードして、その出力行を生成するために行うC呼び出しをコピーすることができます。幸運を!

于 2009-05-08T01:56:03.987 に答える