main.py
Python script, ASCII text executable
1
"""
2
Kineboard: an experimental touchscreen keyboard using swipes to allow
3
having fewer touch targets.
4
Copyright 2025-2026, roundabout-host.com <vlad@roundabout-host.com>
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public Licence as published by
7
the Free Software Foundation, either version 3 of the Licence, or
8
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public Licence for more details.
13
You should have received a copy of the GNU General Public Licence
14
along with this program. If not, see <https://www.gnu.org/licenses/>.
15
"""
16
17
import itertools
18
import sys
19
import os
20
import time
21
22
import ruamel.yaml as yaml
23
from pathlib import Path
24
25
os.environ["GI_TYPELIB_PATH"] = "/usr/local/lib/x86_64-linux-gnu/girepository-1.0"
26
from ctypes import CDLL
27
CDLL("libgtk4-layer-shell.so")
28
29
import gi
30
gi.require_version("Gtk", "4.0")
31
gi.require_version("Gtk4LayerShell", "1.0")
32
from gi.repository import (
33
Gtk, Gdk, GObject, Gtk4LayerShell, GLib, Gio, GObject
34
)
35
36
try:
37
gi.require_version("Lfb", "0.0")
38
from gi.repository import Lfb
39
except ImportError:
40
Lfb = None
41
42
from pywayland.client import Display, EventQueue
43
from pywayland.protocol.wayland import WlRegistry, WlSeat
44
from pywayland.protocol.input_method_unstable_v1 import (
45
ZwpInputMethodContextV1,
46
ZwpInputMethodV1
47
)
48
from pywayland.protocol.input_method_unstable_v2 import (
49
ZwpInputMethodV2,
50
ZwpInputMethodManagerV2
51
)
52
from pywayland.protocol.virtual_keyboard_unstable_v1 import ZwpVirtualKeyboardManagerV1
53
54
from xkbcommon import xkb
55
56
import ctypes
57
from cffi import FFI
58
ffi = FFI()
59
ffi.cdef("""
60
void * gdk_wayland_display_get_wl_display (void * display);
61
void * gdk_wayland_surface_get_wl_surface (void * surface);
62
void * gdk_wayland_monitor_get_wl_output (void * monitor);
63
""")
64
gtk = ffi.dlopen("libgtk-4.so.1")
65
66
67
module_directory = Path(__file__).resolve().parent
68
69
70
custom_css = """
71
.kineboard-selected-character {
72
text-decoration: underline;
73
}
74
"""
75
css_provider = Gtk.CssProvider()
76
css_provider.load_from_data(custom_css)
77
Gtk.StyleContext.add_provider_for_display(
78
Gdk.Display.get_default(),
79
css_provider,
80
100
81
)
82
83
84
def get_layout_directories():
85
data_home = Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share"))
86
data_dirs = [Path(d) for d in os.getenv("XDG_DATA_DIRS", "/usr/local/share:/usr/share").split(":")]
87
all_paths = [data_home / "kineboard" / "layouts"] + [d / "kineboard" / "layouts" for d in data_dirs]
88
return [d for d in all_paths if d.is_dir()]
89
90
91
class GestureZone(GObject.GEnum):
92
NONE = 0
93
CENTRAL = 1
94
TOP_LEFT = 2
95
TOP_RIGHT = 3
96
BOTTOM_RIGHT = 4
97
BOTTOM_LEFT = 5
98
99
100
class SwipeButton(Gtk.Frame):
101
@GObject.Signal
102
def top_left(self):
103
pass
104
105
@GObject.Signal
106
def top_right(self):
107
pass
108
109
@GObject.Signal
110
def bottom_left(self):
111
pass
112
113
@GObject.Signal
114
def bottom_right(self):
115
pass
116
117
@GObject.Signal
118
def central(self):
119
pass
120
121
@GObject.Signal(arg_types=(int,))
122
def drag_changed(self, zone):
123
pass
124
125
def __init__(self, **kwargs):
126
Gtk.Frame.__init__(self, **kwargs)
127
self.zone = GestureZone.NONE
128
self.gesture_drag = Gtk.GestureDrag()
129
self.gesture_drag.connect("drag-end", self.finish_drag)
130
self.gesture_drag.connect("drag-update", self.move_drag)
131
self.gesture_drag.connect("drag-begin", self.begin_drag)
132
self.add_controller(self.gesture_drag)
133
134
def finish_drag(self, gesture, offset_x, offset_y):
135
if abs(offset_x) / self.get_width() + abs(offset_y) / self.get_height() > 1 / 2:
136
if offset_x > 0 and offset_y > 0:
137
self.emit("bottom_right")
138
elif offset_x <= 0 and offset_y > 0:
139
self.emit("bottom_left")
140
elif offset_x > 0 and offset_y <= 0:
141
self.emit("top_right")
142
elif offset_x <= 0 and offset_y <= 0:
143
self.emit("top_left")
144
else:
145
self.emit("central")
146
147
def move_drag(self, gesture, offset_x, offset_y):
148
new_zone = self.zone
149
if abs(offset_x) / self.get_width() + abs(offset_y) / self.get_height() > 1 / 2:
150
if offset_x > 0 and offset_y > 0:
151
new_zone = GestureZone.BOTTOM_RIGHT
152
elif offset_x <= 0 and offset_y > 0:
153
new_zone = GestureZone.BOTTOM_LEFT
154
elif offset_x > 0 and offset_y <= 0:
155
new_zone = GestureZone.TOP_RIGHT
156
elif offset_x <= 0 and offset_y <= 0:
157
new_zone = GestureZone.TOP_LEFT
158
else:
159
new_zone = GestureZone.CENTRAL
160
161
if new_zone != self.zone:
162
self.zone = new_zone
163
self.emit("drag_changed", self.zone)
164
165
def begin_drag(self, gesture, start_x, start_y):
166
self.emit("drag_changed", GestureZone.CENTRAL)
167
168
169
class SwipeTyper(SwipeButton):
170
@GObject.Signal(arg_types=(str,))
171
def typed(self, character):
172
if self.release_feedback:
173
self.release_feedback.trigger_feedback()
174
# Since the drag is finished, remove the underlines
175
for label in self.label_map.values():
176
label.remove_css_class("kineboard-selected-character")
177
178
def underline(self, zone):
179
if self.depress_feedback:
180
self.depress_feedback.trigger_feedback()
181
for label in self.label_map.values():
182
label.remove_css_class("kineboard-selected-character")
183
self.label_map[zone].add_css_class("kineboard-selected-character")
184
185
def __init__(self, tl, tr, bl, br, c, depress_feedback, release_feedback, **kwargs):
186
SwipeButton.__init__(self, **kwargs)
187
self.depress_feedback = depress_feedback
188
self.release_feedback = release_feedback
189
self.tl = tl
190
self.tr = tr
191
self.bl = bl
192
self.br = br
193
self.c = c
194
self.grid = Gtk.Grid(hexpand=True, vexpand=True, row_homogeneous=True, column_homogeneous=True, margin_top=4, margin_bottom=4, margin_start=4, margin_end=4)
195
self.set_child(self.grid)
196
self.tl_label = Gtk.Label(label=tl)
197
self.grid.attach(self.tl_label, 0, 0, 1, 1)
198
self.tr_label = Gtk.Label(label=tr)
199
self.grid.attach(self.tr_label, 2, 0, 1, 1)
200
self.bl_label = Gtk.Label(label=bl)
201
self.grid.attach(self.bl_label, 0, 2, 1, 1)
202
self.br_label = Gtk.Label(label=br)
203
self.grid.attach(self.br_label, 2, 2, 1, 1)
204
self.c_label = Gtk.Label(label=c)
205
self.grid.attach(self.c_label, 1, 1, 1, 1)
206
self.label_map = {
207
GestureZone.CENTRAL: self.c_label,
208
GestureZone.TOP_LEFT: self.tl_label,
209
GestureZone.TOP_RIGHT: self.tr_label,
210
GestureZone.BOTTOM_RIGHT: self.br_label,
211
GestureZone.BOTTOM_LEFT: self.bl_label
212
}
213
self.connect("top_left", lambda p: self.emit("typed", tl))
214
self.connect("top_right", lambda p: self.emit("typed", tr))
215
self.connect("bottom_left", lambda p: self.emit("typed", bl))
216
self.connect("bottom_right", lambda p: self.emit("typed", br))
217
self.connect("central", lambda p: self.emit("typed", c))
218
self.connect("drag_changed", lambda p, zone: self.underline(zone))
219
220
221
class Plane(Gtk.Grid):
222
def __init__(self, app, data, depress_feedback, release_feedback, **kwargs):
223
Gtk.Grid.__init__(self, **kwargs)
224
self.app = app
225
self.depress_feedback = depress_feedback
226
self.release_feedback = release_feedback
227
self.all_characters = ""
228
for j, column in enumerate(data):
229
for k, key in enumerate(column):
230
widget = SwipeTyper(key["top_left"], key["top_right"], key["bottom_left"],
231
key["bottom_right"], key["central"], self.depress_feedback, self.release_feedback)
232
widget.connect("typed", self.app.typed)
233
self.attach(widget, k, j, 1, 1)
234
self.all_characters += key["top_left"] + key["top_right"] + key["bottom_left"] + key["bottom_right"] + key["central"]
235
236
237
def make_xkb_keymap_from_unicodes(unicodes):
238
symbols = [
239
"key <LEFT> { [ Left ] };"
240
"key <RGHT> { [ Right ] };"
241
"key <UP> { [ Up ] };"
242
"key <DOWN> { [ Down ] };"
243
"key <TAB> { [ Tab ] };",
244
"key <LCTL> { [ Control_L ] };",
245
"key <LALT> { [ Alt_L ] };",
246
"key <LSHF> { [ Shift_L ] };",
247
"key <LSPR> { [ Super_L ] };",
248
"key <ESCP> { [ Escape ] };",
249
"key <BKSP> { [ BackSpace ] };",
250
"key <RTRN> { [ Return ] };",
251
]
252
keycodes = [
253
"<LEFT> = 4084;",
254
"<RGHT> = 4085;",
255
"<UP> = 4086;",
256
"<DOWN> = 4087;",
257
"<TAB> = 4088;",
258
"<LCTL> = 4089;",
259
"<LALT> = 4090;",
260
"<LSHF> = 4091;",
261
"<LSPR> = 4092;",
262
"<ESCP> = 4093;",
263
"<BKSP> = 4094;",
264
"<RTRN> = 4095;",
265
]
266
for i, char in enumerate(unicodes):
267
keycode = 0x1000 + i
268
keysym = f"U{ord(char):04X}"
269
symbols.append(f"key <K{i:03X}> {{ [ {keysym} ] }};")
270
keycodes.append(f"<K{i:03X}> = {keycode};")
271
272
return ("xkb_keymap { xkb_keycodes \"kineboard\" { minimum = 8; maximum = 65535; "
273
+ " ".join(keycodes) + " }; xkb_symbols \"kineboard\" { " + " ".join(symbols)
274
+ " }; xkb_types \"kineboard\" { type \"ONE_LEVEL\" { modifiers = none; level_name[Level1] = \"Any\"; }; }; xkb_compatibility \"kineboard\" {}; };")
275
276
277
from gi.repository import Gio, GLib
278
279
280
def register_client(client_id: str):
281
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
282
283
proxy = Gio.DBusProxy.new_sync(
284
bus,
285
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
286
Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION,
287
None,
288
"org.gnome.SessionManager",
289
"/org/gnome/SessionManager",
290
"org.gnome.SessionManager",
291
None
292
)
293
294
startup_id = GLib.getenv("DESKTOP_AUTOSTART_ID") or ""
295
296
def on_registered(proxy, result, loop):
297
try:
298
proxy.call_finish(result)
299
except Exception as e:
300
print("cannot register client:", e)
301
loop.quit()
302
303
loop = GLib.MainLoop()
304
305
proxy.call(
306
"RegisterClient",
307
GLib.Variant("(ss)", (client_id, startup_id)),
308
Gio.DBusCallFlags.NONE,
309
-1,
310
None,
311
lambda p, r, l: on_registered(p, r, loop),
312
loop
313
)
314
315
loop.run()
316
return proxy
317
318
319
class ModifierButton(Gtk.ToggleButton):
320
def __init__(self, app, mask, **kwargs):
321
super().__init__(**kwargs)
322
self.app = app
323
self.mask = mask
324
325
self.connect("toggled", self.toggle_modifier)
326
327
def toggle_modifier(self, button):
328
if button.get_active():
329
self.app.depressed_modifiers |= self.mask
330
else:
331
self.app.depressed_modifiers &= ~self.mask
332
333
self.app.send_modifiers()
334
335
336
class Kineboard(Gtk.Application):
337
def __init__(self):
338
Gtk.Application.__init__(
339
self,
340
application_id="sm.puri.OSK0",
341
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE
342
)
343
self.depress_feedback = None
344
self.release_feedback = None
345
self.xkb_context = xkb.Context()
346
self.revealer = None
347
self.switcher = None
348
self.depressed_modifiers = 0
349
self.character_index = {}
350
self.keymap_fd = None
351
self.vk = None
352
self.keymap_text = ""
353
self.all_characters = ""
354
self.context = None
355
self.input_method_manager = None
356
self.input_method = None
357
self.registry = None
358
self.box = None
359
self.window = None
360
self.stack = None
361
self.display = None
362
self.wl_display = None
363
self.seat = None
364
self.vkm = None
365
self.serial = 0
366
self.extra_revealer = None
367
self.extra_viewport = None
368
self.extra_scroll = None
369
self.extra_controls = None
370
self.add_main_option(
371
"invoke",
372
ord("i"),
373
GLib.OptionFlags.NONE,
374
GLib.OptionArg.NONE,
375
"Manually bring up the keyboard",
376
None
377
)
378
self.add_main_option(
379
"hide",
380
ord("h"),
381
GLib.OptionFlags.NONE,
382
GLib.OptionArg.NONE,
383
"Hide the keyboard",
384
None
385
)
386
387
def send_modifiers(self):
388
self.vk.modifiers(self.depressed_modifiers, 0, 0, 0)
389
390
def do_startup(self):
391
Gtk.Application.do_startup(self)
392
register_client("sm.puri.OSK0")
393
self.depress_feedback = None
394
self.release_feedback = None
395
if Lfb:
396
Lfb.init("sm.puri.OSK0")
397
self.depress_feedback = Lfb.Event.new("button-pressed")
398
self.release_feedback = Lfb.Event.new("button-released")
399
self.display = Gdk.Display.get_default()
400
self.window = Gtk.Window(application=self, title="Demo", focus_on_click=False, focusable=False, can_focus=False)
401
Gtk4LayerShell.init_for_window(self.window)
402
Gtk4LayerShell.set_keyboard_mode(self.window, Gtk4LayerShell.KeyboardMode.NONE)
403
self.window.set_default_size(16384, -1) # large width so that it spans the bottom
404
Gtk4LayerShell.set_anchor(self.window, Gtk4LayerShell.Edge.BOTTOM, True)
405
Gtk4LayerShell.set_anchor(self.window, Gtk4LayerShell.Edge.LEFT, True)
406
Gtk4LayerShell.set_anchor(self.window, Gtk4LayerShell.Edge.RIGHT, True)
407
Gtk4LayerShell.auto_exclusive_zone_enable(self.window)
408
Gtk4LayerShell.set_namespace(self.window, "osk")
409
self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
410
self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, margin_top=8)
411
self.window.set_child(self.main_box)
412
self.stack = Gtk.Stack()
413
self.box.append(self.stack)
414
layouts = itertools.chain.from_iterable((f for f in path.iterdir() if f.is_file()) for path in get_layout_directories())
415
self.all_characters = " "
416
self.switcher = Gtk.StackSidebar(stack=self.stack)
417
self.revealer = Gtk.Revealer(child=self.switcher, transition_type=Gtk.RevealerTransitionType.SLIDE_RIGHT)
418
self.box.prepend(self.revealer)
419
420
self.extra_controls = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8,
421
margin_bottom=8, margin_start=8, margin_end=8)
422
self.extra_viewport = Gtk.Viewport(child=self.extra_controls)
423
self.extra_scroll = Gtk.ScrolledWindow(child=self.extra_viewport, propagate_natural_height=True)
424
self.extra_revealer = Gtk.Revealer(child=self.extra_scroll)
425
426
for layout in layouts:
427
stack = Gtk.Stack()
428
429
yaml_loader = yaml.YAML(typ="rt")
430
data = yaml_loader.load(layout)
431
432
controls = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8, margin_top=0,
433
margin_bottom=8, margin_start=8, margin_end=8)
434
435
layout_button = Gtk.ToggleButton(child=Gtk.Image.new_from_icon_name("edit-symbolic"))
436
layout_button.set_size_request(48, -1)
437
layout_button.update_property([Gtk.AccessibleProperty.LABEL], ["Switch layout"])
438
controls.append(layout_button)
439
layout_button.bind_property("active", self.revealer, "reveal-child", GObject.BindingFlags.BIDIRECTIONAL)
440
441
control_button = Gtk.ToggleButton(child=Gtk.Image.new_from_icon_name("utilities-terminal-symbolic"))
442
control_button.set_size_request(48, -1)
443
control_button.update_property([Gtk.AccessibleProperty.LABEL], ["Terminal controls"])
444
controls.append(control_button)
445
control_button.bind_property("active", self.extra_revealer, "reveal-child", GObject.BindingFlags.BIDIRECTIONAL)
446
447
if len(data["keys"]) >= 2:
448
shift_button = Gtk.ToggleButton(
449
child=Gtk.Image.new_from_icon_name("go-up-symbolic")
450
)
451
shift_button.set_size_request(48, -1)
452
shift_button.update_property([Gtk.AccessibleProperty.LABEL], ["Shift"])
453
controls.append(shift_button)
454
455
def shift(button: Gtk.ToggleButton):
456
stack.set_visible_child_name(f"plane-{int(button.get_active())}")
457
458
shift_button.connect("toggled", shift)
459
460
space_bar = Gtk.Button(hexpand=True)
461
space_bar.update_property([Gtk.AccessibleProperty.LABEL], ["Space"])
462
space_bar.connect("clicked", lambda x: self.typed(x, " "))
463
controls.append(space_bar)
464
465
backspace_button = Gtk.Button(child=Gtk.Image.new_from_icon_name("edit-clear-symbolic"))
466
backspace_button.set_size_request(48, -1)
467
backspace_button.update_property([Gtk.AccessibleProperty.LABEL], ["Backspace"])
468
backspace_button.connect("clicked", lambda x: self.send_keysym(0xFF6))
469
controls.append(backspace_button)
470
471
enter_button = Gtk.Button(child=Gtk.Image.new_from_icon_name("keyboard-enter-symbolic"))
472
enter_button.set_size_request(48, -1)
473
enter_button.update_property([Gtk.AccessibleProperty.LABEL], ["Enter"])
474
enter_button.add_css_class("suggested-action")
475
enter_button.connect("clicked", lambda x: self.send_keysym(0xFF7))
476
controls.append(enter_button)
477
478
for i, layer in enumerate(data["keys"]):
479
grid = Plane(self, layer, row_spacing=8, column_spacing=8, row_homogeneous=True,
480
column_homogeneous=True, margin_bottom=8,
481
margin_end=8, margin_start=8,
482
depress_feedback=self.depress_feedback,
483
release_feedback=self.release_feedback)
484
self.all_characters += grid.all_characters
485
stack.add_named(grid, f"plane-{i}")
486
487
outer_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
488
outer_box.append(stack)
489
outer_box.append(controls)
490
self.stack.add_titled(outer_box, data["symbol"], data["symbol"])
491
492
self.main_box.append(self.extra_revealer)
493
self.main_box.append(self.box)
494
495
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
496
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = (ctypes.py_object,)
497
498
self.wl_display = Display()
499
wl_display_ptr = gtk.gdk_wayland_display_get_wl_display(
500
ffi.cast("void *", ctypes.pythonapi.PyCapsule_GetPointer(self.display.__gpointer__, None)))
501
self.wl_display._ptr = wl_display_ptr
502
self.registry = self.wl_display.get_registry()
503
self.registry.dispatcher["global"] = self.on_global
504
self.registry.dispatcher["global_remove"] = self.on_global_remove
505
self.wl_display.roundtrip()
506
507
if self.input_method_manager:
508
self.input_method = self.input_method_manager.get_input_method(self.seat)
509
self.input_method.dispatcher["activate"] = self.activate_input
510
self.input_method.dispatcher["deactivate"] = self.deactivate_input
511
else:
512
dialog = Gtk.AlertDialog(message="Input method protocol not supported.")
513
dialog.show()
514
515
self.keymap_text = make_xkb_keymap_from_unicodes(self.all_characters)
516
xkb_keymap = self.xkb_context.keymap_new_from_string(self.keymap_text)
517
state = xkb_keymap.state_new()
518
519
escape_button = Gtk.Button(label="Escape")
520
escape_button.connect("clicked", lambda x: self.send_keysym(0xFF5))
521
self.extra_controls.append(escape_button)
522
self.extra_controls.append(ModifierButton(self, 1 << xkb_keymap.mod_get_index("Control"), label="Control"))
523
self.extra_controls.append(ModifierButton(self, 1 << xkb_keymap.mod_get_index("Mod1"), label="Alt"))
524
self.extra_controls.append(ModifierButton(self, 1 << xkb_keymap.mod_get_index("Shift"), label="Shift"))
525
self.extra_controls.append(ModifierButton(self, 1 << xkb_keymap.mod_get_index("Mod4"), label="Super"))
526
tab_button = Gtk.Button(label="Tab")
527
tab_button.connect("clicked", lambda x: self.send_keysym(0xFF0))
528
self.extra_controls.append(tab_button)
529
left_button = Gtk.Button(child=Gtk.Image.new_from_icon_name("go-previous-symbolic"))
530
left_button.update_property([Gtk.AccessibleProperty.LABEL], ["Left"])
531
left_button.connect("clicked", lambda x: self.send_keysym(0xFEC))
532
self.extra_controls.append(left_button)
533
down_button = Gtk.Button(child=Gtk.Image.new_from_icon_name("go-down-symbolic"))
534
down_button.update_property([Gtk.AccessibleProperty.LABEL], ["Down"])
535
down_button.connect("clicked", lambda x: self.send_keysym(0xFEF))
536
self.extra_controls.append(down_button)
537
up_button = Gtk.Button(child=Gtk.Image.new_from_icon_name("go-up-symbolic"))
538
up_button.update_property([Gtk.AccessibleProperty.LABEL], ["Up"])
539
up_button.connect("clicked", lambda x: self.send_keysym(0xFEE))
540
self.extra_controls.append(up_button)
541
right_button = Gtk.Button(child=Gtk.Image.new_from_icon_name("go-next-symbolic"))
542
right_button.update_property([Gtk.AccessibleProperty.LABEL], ["Right"])
543
right_button.connect("clicked", lambda x: self.send_keysym(0xFED))
544
self.extra_controls.append(right_button)
545
546
self.character_index = {}
547
for i, character in enumerate(self.all_characters):
548
self.character_index[character] = i
549
self.vk = self.vkm.create_virtual_keyboard(self.seat)
550
551
self.keymap_fd = os.memfd_create("keymap")
552
os.write(self.keymap_fd, self.keymap_text.encode("utf-8"))
553
os.lseek(self.keymap_fd, 0, os.SEEK_SET)
554
self.vk.keymap(1, self.keymap_fd, len(self.keymap_text.encode("utf-8")))
555
556
def activate_input(self, im):
557
self.window.present()
558
559
def deactivate_input(self, im):
560
self.window.set_visible(False)
561
self.serial = 0
562
563
def on_global(self, registry, name, interface, version):
564
if interface == "zwp_input_method_manager_v2":
565
self.input_method_manager = registry.bind(name, ZwpInputMethodManagerV2, version)
566
elif interface == "wl_seat":
567
self.seat = registry.bind(name, WlSeat, version)
568
elif interface == "zwp_virtual_keyboard_manager_v1":
569
self.vkm = registry.bind(name, ZwpVirtualKeyboardManagerV1, version)
570
571
def on_global_remove(self, registry, name):
572
pass
573
574
def send_keysym(self, key):
575
clock = int(time.monotonic() * 1000)
576
if self.vk:
577
self.vk.key(clock, key, 1)
578
self.vk.key(clock, key, 0)
579
580
def typed(self, button, characters):
581
for char in characters:
582
self.send_keysym(0xFF8 + self.character_index[char])
583
584
def do_activate(self):
585
Gtk.Application.do_activate(self)
586
# self.window.present()
587
588
def do_command_line(self, command_line: Gio.ApplicationCommandLine):
589
options = command_line.get_options_dict()
590
args = command_line.get_arguments()[1:]
591
if options.contains("invoke"):
592
self.activate_input(None, None)
593
elif options.contains("hide"):
594
self.deactivate_input(None, None)
595
return 0
596
597
598
if __name__ == "__main__":
599
kineboard = Kineboard()
600
kineboard.run(sys.argv)
601