选择某些监视器以使用gtk全屏显示 [英] select certain monitor for going fullscreen with gtk

查看:75
本文介绍了选择某些监视器以使用gtk全屏显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算在显示全屏窗口的地方更改监视器.挂上投影仪时,这尤其有趣.

I intend to change the monitor where I show a fullscreen window. This is especially interesting when having a projector hooked up.

我尝试使用 fullscreen_on_monitor ,但这不会产生任何可见的变化.

I've tried to use fullscreen_on_monitor but that doesn't produce any visible changes.

这是一个不起作用的示例:

Here is a non-working example:

#!/usr/bin/env python
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk

w = Gtk.Window()

screen = Gdk.Screen.get_default()
print ("Montors: %d" % screen.get_n_monitors())
if len(sys.argv) > 1:
    n = int(sys.argv[1])
else:
    n = 0

l = Gtk.Button(label="Hello, %d monitors!" % screen.get_n_monitors())
w.add(l)
w.show_all()

w.fullscreen_on_monitor(screen, n)
l.connect("clicked", Gtk.main_quit)
w.connect("destroy", Gtk.main_quit)
Gtk.main()

无论我提供什么值,我都可以在同一台显示器上(3个中的)看到该窗口.

I get to see the window on the very same monitor (out of 3), regardless of the value I provide.

我的问题是:如何使全屏窗口显示在其他显示器上?

My question is: how do I make the fullscreen window appear on a different monitor?

推荐答案

问题似乎是Gtk只是忽略了监视器编号,它将始终在当前窗口所在的监视器上全屏显示该窗口.这很糟糕,但是我们可以使用它来使其按我们想要的方式工作.

The problem seems to be that Gtk just ignores the monitor number, it will always fullscreen the window on the monitor on which the window currently is positioned. This sucks, but we can use that to make it work the way we want to.

但是首先要有关于多个显示器的理论,它们实际上并不是您的PC的单独显示器.它认为它们共同构成了一个具有相同全球起源的屏幕.在该全局屏幕上,每个监视器都有一个相对于全局原点的原点,就像窗口一样.

But first some theory about multiple monitors, they aren't actually separate monitors for your pc. It considers them to collectively form one screen which share the same global origin. On that global screen each monitor has a origin relative to the global origin, just like windows.

因为我们知道Gtk将始终在窗口所在的监视器上全屏显示,所以我们可以简单地使用 window.move(x,y)将窗口移至监视器的原点,然后调用 window.fullscreen().

Because we know that Gtk will always fullscreen on the monitor on which the window is we can simply move the window to the origin of the monitor using window.move(x,y) and then call window.fullscreen().

( move 函数会将窗口移动到相对于其父窗口的位置(x,y),在主窗口的情况下为全局屏幕)

(The move function will move the window to a position (x,y) relative to it's parent, which in the case of the main window is the global screen.)

结合所有这些,我们得到了这个,它在Windows 10上可以完美运行:

Combining all this we get this, which works perfectly on Windows 10:

def fullscreen_at_monitor(window, n):
    screen = Gdk.Screen.get_default()

    monitor_n_geo = screen.get_monitor_geometry(n)
    x = monitor_n_geo.x
    y = monitor_n_geo.y

    window.move(x,y)

    window.fullscreen()

这篇关于选择某些监视器以使用gtk全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆