简体   繁体   English

如何在没有弃用警告的情况下检查 python / Gtk 3.0 中的当前屏幕尺寸?

[英]How to check the current screen dimensions in python / Gtk 3.0 without deprecation warnings?

I need to know dimensions (exactly: height) of the screen below the current Gtk.Window.The most frequently recommended method:我需要知道当前 Gtk.Window 下方屏幕的尺寸(确切地说:高度)。最常推荐的方法:

window = Gtk.Window()
screen = window.get_screen()
h = screen.height()

does the job, but gives me DeprecationWarning: Gdk.Screen.height is deprecated , and is likely to stop working sooner or later.完成这项工作,但给了我DeprecationWarning: Gdk.Screen.height is deprecated ,并且可能迟早会停止工作。 I wouldn't like to add any new dependencies, so this cool cheat sheet doesn't help.我不想添加任何新的依赖项,所以这个很酷的备忘单没有帮助。

My code is expected to work on Linux w/ multi-headed setups, and this must be the height of the current screen.我的代码预计可以在带有多头设置的 Linux 上运行,并且这必须是当前屏幕的高度。

More detailed background: the program I'm working on is a wallpaper manager.更详细的背景:我正在开发的程序是一个壁纸管理器。 I want the (floating) window to use all the possible space vertically, and leave some space on both sides, to watch the background change.我希望(浮动)窗口垂直使用所有可能的空间,并在两侧留出一些空间,以观察背景变化。

Having no reasonable solution, I decided to follow this answer .没有合理的解决方案,我决定遵循这个答案

def check_height_and_start(window):
    w, h = window.get_size()
    window.destroy()

    if common.sway or common.env['wm'] == "i3":
        h = h * 0.95

    app = GUI(h)



def main():
    (...)
    w = Gtk.Window() # actually I derived from Gtk.Window to make the window transparent

    if common.sway or common.env['wm'] == "i3":
        w.fullscreen()  # .maximize() doesn't work as expected on sway
    else:
        w.maximize()

    w.present()
    GLib.timeout_add(delay_ms, check_height_and_start, w)
    Gtk.main()

This way the window height does not include panels, if any.这样,窗口高度不包括面板(如果有)。 Unfortunately it doesn't work on tiling window window managers, so I had to use fullscreen() instead of maximize() , and decrease height arbitrarily.不幸的是,它不适用于平铺窗口窗口管理器,所以我不得不使用fullscreen()而不是maximize() ,并任意降低高度。

The delay_ms optimal value varies with the hardware speed and WM in use, which is another inconvenience. delay_ms最优值随硬件速度和使用的 WM 而变化,这是另一个不便之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM