63 lines
1.5 KiB
Python
Executable File
63 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from Xlib import display
|
|
from pprint import pprint as print
|
|
import gi, cairo
|
|
gi.require_version('Gtk', '3.0')
|
|
from gi.repository import Gtk, Gdk
|
|
|
|
# 获取默认显示器
|
|
dp = Gdk.Display.get_default()
|
|
|
|
root = display.Display().screen().root
|
|
|
|
|
|
# 计算所有显示器的总大小
|
|
total_width = 0
|
|
total_height = 0
|
|
for i in range(dp.get_n_monitors()):
|
|
monitor = dp.get_monitor(i)
|
|
geometry = monitor.get_geometry()
|
|
total_width += geometry.width
|
|
total_height = max(total_height, geometry.height)
|
|
|
|
|
|
|
|
def on_draw(widget, cr):
|
|
cr.set_source_rgba(0, 0, 0, 0.3) # 设置颜色和透明度
|
|
cr.set_operator(cairo.OPERATOR_SOURCE)
|
|
cr.paint()
|
|
cr.set_operator(cairo.OPERATOR_OVER)
|
|
|
|
def on_mouse_move(widget, event):
|
|
|
|
pointer = root.query_pointer()
|
|
# print("Mouse at (%d, %d)" % (pointer.root_x, pointer.root_y))
|
|
win_at_pointer = pointer.child
|
|
print(win_at_pointer.get_wm_class())
|
|
|
|
# print(dir(Gtk.WindowType))
|
|
|
|
# 创建遮罩窗口
|
|
# window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
|
|
window = Gtk.Window(type=Gtk.WindowType.POPUP)
|
|
window.set_default_size(total_width, total_height)
|
|
window.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
|
|
|
|
# 设置透明背景
|
|
screen = window.get_screen()
|
|
visual = screen.get_rgba_visual()
|
|
if visual and screen.is_composited():
|
|
window.set_visual(visual)
|
|
|
|
window.set_app_paintable(True)
|
|
|
|
window.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
|
|
window.connect("motion-notify-event", on_mouse_move)
|
|
|
|
|
|
|
|
window.connect("draw", on_draw)
|
|
|
|
window.show_all()
|
|
Gtk.main() |