diff --git a/.gitignore b/.gitignore index a2535dc..52cf7cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,10 @@ -demo.py \ No newline at end of file +__pycache__ +*.txt + +._* + +.Spotlight-V100 +.Trashes +.DS_Store +.AppleDouble +.LSOverride \ No newline at end of file diff --git a/draft/demo.py b/draft/demo.py new file mode 100755 index 0000000..3086656 --- /dev/null +++ b/draft/demo.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +from Xlib import display +from pprint import pprint as print +import gi +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk, Gdk, GLib + +d = display.Display() +root = d.screen().root + + +def screenshot(): + window = Gdk.get_default_root_window() + width, height = window.get_width(), window.get_height() + screenshot = Gdk.pixbuf_get_from_window(window, 0, 0, width, height) + if screenshot: + screenshot.savev("screenshot.png", "png", [], []) + +# 获取当前活动窗口 +# current_window = d.get_input_focus().focus + +# 获取当前活动窗口的名字 +# window_name = current_window.get_wm_name() + +# # 获取当前活动窗口的类 +# window_class = current_window.get_wm_class() + +# print('Window Name: %s' % window_name) +# print('Window Class: %s' % str(window_class)) + +# print(dir(current_window)) + +# print(current_window.get_geometry()) + +screenshot() + +class MouseMotionWindow(Gtk.Window): + def __init__(self): + Gtk.Window.__init__(self) + # self.maximize() + self.set_events(Gdk.EventMask.POINTER_MOTION_MASK) + self.connect("motion-notify-event", self.on_mouse_move) + # 延迟调用 fullscreen 方法 + GLib.idle_add(self.fullscreen) + + def on_mouse_move(self, widget, event): + print("Mouse moved to position (%f, %f)" % (event.x, event.y)) + +# 遍历所有窗口 +# root = d.screen().root +# tree = root.query_tree() +# for w in tree.children: +# window_name = w.get_wm_name() +# window_class = w.get_wm_class() +# print('Window Name: %s => %s' % (window_name, window_class)) + +# win = MouseMotionWindow() +# win.connect("destroy", Gtk.main_quit) +# win.show_all() +# Gtk.main() \ No newline at end of file diff --git a/draft/test.py b/draft/test.py new file mode 100755 index 0000000..ae6fc83 --- /dev/null +++ b/draft/test.py @@ -0,0 +1,63 @@ +#!/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() \ No newline at end of file