隐藏鼠标
This commit is contained in:
parent
8ea14bbd97
commit
b551fb4f97
42
face_rec.py
42
face_rec.py
@ -22,14 +22,40 @@ from compreface.service import RecognitionService, DetectionService
|
|||||||
def hide_cursor():
|
def hide_cursor():
|
||||||
"""隐藏鼠标光标(Linux/X11)"""
|
"""隐藏鼠标光标(Linux/X11)"""
|
||||||
try:
|
try:
|
||||||
import subprocess
|
import ctypes
|
||||||
# 创建空白cursor文件
|
from ctypes import cdll, c_char_p, c_void_p, c_int, byref
|
||||||
xbm = '/tmp/invisible_cursor.xbm'
|
|
||||||
with open(xbm, 'w') as f:
|
libx11 = cdll.LoadLibrary('libX11.so.6')
|
||||||
f.write('#define w 1\n#define h 1\n#define hot_x 0\n#define hot_y 0\nstatic char curs[] = {0};')
|
|
||||||
subprocess.run(['xsetroot', '-cursor', xbm, xbm], check=False)
|
# 打开 Display
|
||||||
except Exception:
|
display = libx11.XOpenDisplay(None)
|
||||||
pass
|
if not display:
|
||||||
|
print("Cannot open X display")
|
||||||
|
return
|
||||||
|
|
||||||
|
root = libx11.XDefaultRootWindow(display)
|
||||||
|
|
||||||
|
# 创建空白 bitmap
|
||||||
|
no_data = b'\x00'
|
||||||
|
bitmap = libx11.XCreateBitmapFromData(display, root, no_data, 8, 8)
|
||||||
|
|
||||||
|
# 创建完全透明的光标(前景和背景都是0,即透明)
|
||||||
|
black = c_int(0)
|
||||||
|
invisible_cursor = libx11.XCreatePixmapCursor(display, bitmap, bitmap,
|
||||||
|
byref(black), byref(black), 0, 0)
|
||||||
|
|
||||||
|
# 设置到根窗口
|
||||||
|
libx11.XDefineCursor(display, root, invisible_cursor)
|
||||||
|
libx11.XFlush(display)
|
||||||
|
|
||||||
|
print("Cursor hidden successfully")
|
||||||
|
|
||||||
|
# 清理
|
||||||
|
libx11.XFreeCursor(display, invisible_cursor)
|
||||||
|
libx11.XFreePixmap(display, bitmap)
|
||||||
|
libx11.XCloseDisplay(display)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Hide cursor error: {e}")
|
||||||
|
|
||||||
|
|
||||||
class FaceRecognitionSystem:
|
class FaceRecognitionSystem:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user