Permalink
Browse files

Better performance for gnome

  • Loading branch information...
Saren-Arterius committed Apr 25, 2017
1 parent db59753 commit 6f451b18acc12ccce36404561bbc98e6ce0fd4bb
Showing with 78 additions and 23 deletions.
  1. +78 −23 main.py
101 main.py
@@ -41,6 +41,61 @@
if platform.system() == 'Linux':
import pyxhook
import ctypes
X11 = ctypes.CDLL("libX11.so")
class Display(ctypes.Structure):
""" opaque struct """
class XKeyEvent(ctypes.Structure):
_fields_ = [
('type', ctypes.c_int),
('serial', ctypes.c_ulong),
('send_event', ctypes.c_int),
('display', ctypes.POINTER(Display)),
('window', ctypes.c_ulong),
('root', ctypes.c_ulong),
('subwindow', ctypes.c_ulong),
('time', ctypes.c_ulong),
('x', ctypes.c_int),
('y', ctypes.c_int),
('x_root', ctypes.c_int),
('y_root', ctypes.c_int),
('state', ctypes.c_uint),
('keycode', ctypes.c_uint),
('same_screen', ctypes.c_int),
]
class XEvent(ctypes.Union):
_fields_ = [
('type', ctypes.c_int),
('xkey', XKeyEvent),
('pad', ctypes.c_long * 24),
]
X11.XOpenDisplay.restype = ctypes.POINTER(Display)
def linux_send_key(code, mask):
display = X11.XOpenDisplay(None)
winFocus = ctypes.c_ulong()
retval = ctypes.c_ulong()
X11.XGetInputFocus(display, ctypes.byref(
winFocus), ctypes.byref(retval))
k = XEvent(type=2).xkey
k.state = mask
k.keycode = X11.XKeysymToKeycode(display, code) # ctrl
k.root = X11.XDefaultRootWindow(display)
k.window = winFocus
X11.XSendEvent(display, k.window, True, 1, ctypes.byref(k))
X11.XCloseDisplay(display)
def linux_backspace():
linux_send_key(0xff08, 0)
def linux_paste():
linux_send_key(0x0076, 4) # Ctrl
button_font = "Sans"
elif platform.system() == 'Windows':
import win32clipboard
@@ -74,7 +129,7 @@
}
elif platform.system() == "Darwin":
button_font = "Sans"
def call(args, call_bs_first=False):
if call_bs_first:
@@ -90,32 +145,33 @@ def invert_transparent_image(image):
rgba[i] = 255 - rgba[i]
image.putpixel((x, y), tuple(rgba))
def send_back_space():
if platform.system() == 'Linux':
call(["xdotool", "key", "BackSpace"])
linux_backspace()
# call(["xdotool", "key", "BackSpace"])
def win_set_clipboard_text(text):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text, win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text, win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
def win_get_clipboard_text():
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
return data
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
return data
def type_char(char):
if LINUX_USE_CLIPBOARD:
send_back_space()
type_char_queue.put(char)
def type_char_worker():
while True:
char = type_char_queue.get()
@@ -130,7 +186,8 @@ def type_char_worker():
pass
root.clipboard_clear()
root.clipboard_append(char)
call(["xdotool", "key", "CTRL+V"], False)
# call(["xdotool", "key", "CTRL+V"], False)
linux_paste()
if was is not None:
sleep(CLIPBOARD_WAIT_DELAY)
root.clipboard_clear()
@@ -309,10 +366,10 @@ def reset_associate(self):
self.current_page = 0
def input_callback(self, event):
idx = self.input_buttons.index(event.widget) + 1
print("Clicked", idx)
pre = "".join(self.current_input)
if self.is_associate:
self.is_associate = False
char = self.current_associate[idx - 1]
@@ -421,8 +478,6 @@ def update_gui(self):
elif not self.is_associate:
self.cancel_callback(None)
def keyboard_callback(self, event):
if event.ScanCode == 78:
if self.is_hiding:
@@ -486,7 +541,6 @@ def move_window_to_corner(self):
else:
root.geometry("%dx%d+%d+%d" % (size + (corner_w, F9_MARGIN)))
self.bottom_right = False
@staticmethod
def transpose(n):
@@ -610,3 +664,4 @@ def low_level_handler(nCode, wParam, lParam):
w.window_listen()
elif platform.system() == 'Darwin':
root.mainloop()

0 comments on commit 6f451b1

Please sign in to comment.