在Linux下双显示器设置的SDL假全屏模式

时间:2011-10-28 10:18:16

标签: c++ linux sdl multiple-monitors

使用SDL 1.3我想在linux下创建假的全屏SDL_Window。如果我只有一个显示器很容易。 我刚刚获得了当前的显示模式并创建了一个窗口。

SDL_GetDesktopDisplayMode(0, &mode);

SDL_Window *win = SDL_CreateWindow("my window",
    0,0,mode.w, mode.h,
    SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS );

但是当我有两个显示器时,事情会变得复杂。窗口分布在多个监视器上。 SDL只能看到一个双倍大小的虚拟显示器。

我用这段代码测试了它

int num = SDL_GetNumVideoDisplays();
for( int i=0; i < num; i++ )
{
    SDL_Rect displayRect;
    SDL_GetDisplayBounds( i, &displayRect );
    std::cout
        << "display " << i << ": x,y,w,h("
        << displayRect.x << ", "
        << displayRect.y << ", "
        << displayRect.w << ", "
        << displayRect.h << ")"
        << std::endl;
}

输出:

display 0: x,y,w,h(0, 0, 2960, 1050)

但我有两个显示器(1680x1050和1280x1024)。

如何强制窗口仅保持一个(假定主要)显示?

1 个答案:

答案 0 :(得分:2)

src/video/x11/SDL_x11modes.c检查一些有趣的#define s:

SDL_VIDEO_DRIVER_X11_XINERAMA
SDL_VIDEO_DRIVER_X11_XRANDR
SDL_VIDEO_DRIVER_X11_XVIDMODE

您可以检查include/SDL_config.h以查看您的副本所关注的路径。定义X11MODES_DEBUG的重建也可能很有效。

编辑:使用test/testvidinfo.c在我的系统上尝试X11MODES_DEBUG并获得此信息:

Built-in video drivers: x11, dummy
Video driver: x11
Number of displays: 1
Display 0: 2646x1024 at 0,0
  Current mode: 2646x1024@0Hz, 32 bits-per-pixel
      Red Mask = 0x00ff0000
      Green Mask = 0x0000ff00
      Blue Mask = 0x000000ff
X11 detected Xinerama:
xinerama 0: 1366x768+0+0
xinerama 1: 1280x1024+1366+0
XRANDR: XRRQueryVersion: V1.3
XRANDR: mode =    0[0], w = 1366, h =  768, rate =   60
XRANDR: mode =    1[0], w = 1360, h =  768, rate =   60
XRANDR: mode =    2[0], w = 1024, h =  768, rate =   60
XRANDR: mode =    3[0], w =  800, h =  600, rate =   60
XRANDR: mode =    3[1], w =  800, h =  600, rate =   56
XRANDR: mode =    4[0], w =  640, h =  480, rate =   60
Xinerama is enabled
XRandR is enabled
  Fullscreen video modes:
    Mode 0: 2646x1024@0Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 1: 1366x768@60Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 2: 1366x768@0Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 3: 1360x768@60Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 4: 1024x768@60Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 5: 800x600@60Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 6: 800x600@56Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
    Mode 7: 640x480@60Hz, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
Current resolution: 2646x1024

您可以看到SDL查询了Xinerama并获得了我的两台显示器,但似乎并没有以有用的方式将其传达回客户端。

可悲的是,您似乎需要发布到邮件列表或提交错误:(