Python/Linux - 检查其他应用程序是否全屏
Python/Linux - Check if some other app is fullscreen
我开发了一个用于显示器背面 RGB LED 的控制器,我想控制它们,以便在我有全屏应用程序时它们与屏幕上的平均颜色匹配 运行,比如电影。
我已经启动了整个控制器并在后台 运行,但我在尝试弄清楚如何确定是否有某些应用程序 运行 全屏时遇到了困难。我该怎么做?我在 Debian 测试中使用 python3。
非常感谢您的帮助!
我找到了一个答案 here 并对其进行了一些修改以使其更有用。这是我在 gnome 上运行的代码。您可能需要为其他 gdms 调整转义的 windows 名称。
import Xlib.display
#Find out if fullscreen app is running
screen = Xlib.display.Display().screen()
root_win = screen.root
def is_fullscreen():
#cycle through all windows
for window in root_win.query_tree()._data['children']:
width = window.get_geometry()._data["width"]
height = window.get_geometry()._data["height"]
#if window is full screen, check it the window name
if width == screen.width_in_pixels and height == screen.height_in_pixels:
if window.get_wm_name() in ['Media viewer', 'mutter guard window']:
continue
#return true if window name is not one of the gnome windows
return True
#if we reach this, no fs window is open
return False
我开发了一个用于显示器背面 RGB LED 的控制器,我想控制它们,以便在我有全屏应用程序时它们与屏幕上的平均颜色匹配 运行,比如电影。
我已经启动了整个控制器并在后台 运行,但我在尝试弄清楚如何确定是否有某些应用程序 运行 全屏时遇到了困难。我该怎么做?我在 Debian 测试中使用 python3。
非常感谢您的帮助!
我找到了一个答案 here 并对其进行了一些修改以使其更有用。这是我在 gnome 上运行的代码。您可能需要为其他 gdms 调整转义的 windows 名称。
import Xlib.display
#Find out if fullscreen app is running
screen = Xlib.display.Display().screen()
root_win = screen.root
def is_fullscreen():
#cycle through all windows
for window in root_win.query_tree()._data['children']:
width = window.get_geometry()._data["width"]
height = window.get_geometry()._data["height"]
#if window is full screen, check it the window name
if width == screen.width_in_pixels and height == screen.height_in_pixels:
if window.get_wm_name() in ['Media viewer', 'mutter guard window']:
continue
#return true if window name is not one of the gnome windows
return True
#if we reach this, no fs window is open
return False