-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 278de2d
Showing
17 changed files
with
718 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/* | ||
data/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[[source]] | ||
|
||
url = "https://pypi.python.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
|
||
[packages] | ||
|
||
evdev = "*" | ||
xlib = "*" | ||
|
||
|
||
[dev-packages] | ||
|
||
|
||
|
||
[requires] | ||
|
||
python_version = "3.6" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import subprocess | ||
|
||
def copy(string, target=None): | ||
extra_args = [] | ||
if target != None: | ||
extra_args += ['-target', target] | ||
|
||
return subprocess.run( | ||
['xclip', '-selection', 'c'] + extra_args, | ||
universal_newlines=True, | ||
input=string | ||
) | ||
|
||
def get(target=None): | ||
extra_args = [] | ||
if target != None: | ||
extra_args += ['-target', target] | ||
|
||
result = subprocess.run( | ||
['xclip', '-selection', 'c', '-o'] + extra_args, | ||
stdout=subprocess.PIPE, | ||
universal_newlines=True | ||
) | ||
|
||
# returncode = result.returncode | ||
stdout = result.stdout.strip() | ||
return stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
KEYSYM_MAP = { | ||
65307: "ESC", | ||
32: "SPACE", | ||
39: "'", | ||
44: ",", | ||
45: "-", | ||
46: ".", | ||
47: "/", | ||
48: "0", | ||
49: "1", | ||
50: "2", | ||
51: "3", | ||
52: "4", | ||
53: "5", | ||
54: "6", | ||
55: "7", | ||
56: "8", | ||
57: "9", | ||
59: ";", | ||
61: "=", | ||
91: "[", | ||
92: "\\", | ||
93: "]", | ||
96: "`", | ||
97: "a", | ||
98: "b", | ||
99: "c", | ||
100: "d", | ||
101: "e", | ||
102: "f", | ||
103: "g", | ||
104: "h", | ||
105: "i", | ||
106: "j", | ||
107: "k", | ||
108: "l", | ||
109: "m", | ||
110: "n", | ||
111: "o", | ||
112: "p", | ||
113: "q", | ||
114: "r", | ||
115: "s", | ||
116: "t", | ||
117: "u", | ||
118: "v", | ||
119: "w", | ||
120: "x", | ||
121: "y", | ||
122: "z", | ||
} | ||
|
||
TARGET = 'image/x-inkscape-svg' | ||
|
||
NORMAL = '' | ||
VIM = 'Vim' | ||
STYLE = 'Style' | ||
SAVE_STYLE = 'Save style' | ||
OBJECT = 'Object' | ||
SAVE_OBJECT = 'Save object' | ||
DISABLED = 'Disabled' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from Xlib import X | ||
from constants import KEYSYM_MAP, NORMAL | ||
from mode import mode | ||
import normal | ||
|
||
def disabled_mode(event, keysym, manager): | ||
if keysym in KEYSYM_MAP: | ||
character = KEYSYM_MAP.get(keysym, 0) | ||
|
||
if event.type == X.KeyPress: | ||
if character == '`': | ||
mode(NORMAL) | ||
manager.teardown() | ||
manager.listen(normal.normal_mode) | ||
elif event.type == X.KeyRelease: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from Xlib.display import Display | ||
from Xlib import X | ||
from Xlib.ext import record | ||
from Xlib.protocol import rq | ||
|
||
import time | ||
from constants import KEYSYM_MAP, NORMAL | ||
|
||
from mode import mode | ||
from normal import normal_mode | ||
|
||
class ShortcutManager(): | ||
def __init__(self): | ||
self.disp2 = Display() | ||
|
||
def is_inkscape(self): | ||
window = self.disp2.get_input_focus().focus | ||
cls = window.get_wm_class() | ||
return cls and cls[0] == 'inkscape' | ||
|
||
def meta_handler(self, handler): | ||
def handle(reply): | ||
print('yes') | ||
data = reply.data | ||
while len(data): | ||
event, data = rq.EventField(None).parse_binary_value( | ||
data, self.disp.display, None, None) | ||
|
||
if not self.is_inkscape(): | ||
return | ||
|
||
keysym = self.disp.keycode_to_keysym(event.detail, 0) | ||
handler(event, keysym, self) | ||
|
||
return handle | ||
|
||
def listen(self, handler): | ||
self.disp = Display() | ||
root = self.disp.screen().root | ||
self.ctx = self.disp.record_create_context( | ||
# datum_flags | ||
0, | ||
# clients | ||
[record.AllClients], | ||
# rangers | ||
[{ | ||
'core_requests': (0, 0), | ||
'core_replies': (0, 0), | ||
'ext_requests': (0, 0, 0, 0), | ||
'ext_replies': (0, 0, 0, 0), | ||
'delivered_events': (0, 0), | ||
'device_events': (0x02, 0x05), | ||
'errors': (0, 0), | ||
'client_started': False, | ||
'client_died': False, | ||
}]) | ||
|
||
self.disp.record_enable_context(self.ctx, self.meta_handler(handler)) | ||
self.disp.record_free_context(self.ctx) | ||
|
||
try: | ||
while True: | ||
time.sleep(1) | ||
# Infinite wait, doesn't do anything as no events are grabbed | ||
event = root.display.next_event() | ||
except: | ||
print('exception!') | ||
|
||
def teardown(self): | ||
self.disp.record_disable_context(self.ctx) | ||
|
||
sm = ShortcutManager() | ||
mode('INIT') | ||
time.sleep(1) | ||
mode(NORMAL) | ||
sm.listen(normal_mode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def mode(name): | ||
print(name) |
Binary file not shown.
Oops, something went wrong.