Merge branch 'input-purpose-toggle' into 'master'

Honor input-purpose only changes

Closes #311

See merge request World/Phosh/squeekboard!493
This commit is contained in:
dcz
2021-12-05 14:33:54 +00:00
2 changed files with 38 additions and 9 deletions

View File

@ -153,14 +153,14 @@ pub mod c {
if active_changed {
(imservice.active_callback)(imservice.current.active);
if imservice.current.active {
unsafe {
eekboard_context_service_set_hint_purpose(
imservice.state_manager,
imservice.current.content_hint.bits(),
imservice.current.content_purpose.clone() as u32,
);
}
}
if imservice.current.active {
unsafe {
eekboard_context_service_set_hint_purpose(
imservice.state_manager,
imservice.current.content_hint.bits(),
imservice.current.content_purpose.clone() as u32,
);
}
}
}

View File

@ -1,10 +1,13 @@
#!/usr/bin/env python3
import gi
import random
import sys
gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
from gi.repository import Gtk
from gi.repository import GLib
try:
terminal = [("Terminal", Gtk.InputPurpose.TERMINAL)]
@ -14,6 +17,8 @@ except AttributeError:
def new_grid(items, set_type):
grid = Gtk.Grid(orientation='vertical', column_spacing=8, row_spacing=8)
grid.props.margin = 6
i = 0
for text, value in items:
l = Gtk.Label(label=text)
@ -44,17 +49,41 @@ class App(Gtk.Application):
("OSK provided", Gtk.InputHints.INHIBIT_OSK)
]
def on_purpose_toggled(self, btn, entry):
purpose = Gtk.InputPurpose.PIN if btn.get_active() else Gtk.InputPurpose.PASSWORD
entry.set_input_purpose(purpose)
def on_timeout(self, e):
r = random.randint(0, len(self.purposes) - 1)
(_, purpose) = self.purposes[r]
print(f"Setting {purpose}")
e.set_input_purpose(purpose)
return True
def add_random (self, grid):
l = Gtk.Label(label="Random")
e = Gtk.Entry(hexpand=True)
e.set_input_purpose(Gtk.InputPurpose.FREE_FORM)
grid.attach(l, 0, len(self.purposes), 1, 1)
grid.attach(e, 1, len(self.purposes), 1, 1)
GLib.timeout_add_seconds (3, self.on_timeout, e)
def do_activate(self):
w = Gtk.ApplicationWindow(application=self)
w.set_default_size (300, 500)
notebook = Gtk.Notebook()
def add_purpose(entry, purpose):
entry.set_input_purpose(purpose)
def add_hint(entry, hint):
entry.set_input_hints(hint)
purpose_grid = new_grid(self.purposes, add_purpose)
self.add_random(purpose_grid)
hint_grid = new_grid(self.hints, add_hint)
notebook.append_page(purpose_grid, Gtk.Label(label="Purposes"))
purpose_scroll = Gtk.ScrolledWindow()
purpose_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
purpose_scroll.add(purpose_grid)
notebook.append_page(purpose_scroll, Gtk.Label(label="Purposes"))
notebook.append_page(hint_grid, Gtk.Label(label="Hints"))
w.add(notebook)
w.show_all()