62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
|
#!/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()
|