diff --git a/desktop/shell/bin/omarchy-keyboard b/desktop/shell/bin/omarchy-keyboard index a57ba61f..2951fcde 100644 --- a/desktop/shell/bin/omarchy-keyboard +++ b/desktop/shell/bin/omarchy-keyboard @@ -114,6 +114,7 @@ class Policy: self.asked_until = 0.0 # an app asked before its field came on self.hide_at = None self.hide_asked = False # the app asked to hide; held back like a field going off + self.pressing = False # a finger is down on the focused surface self.opened_here = False self.hardware = False # typing on a physical keyboard self.keyboards = 0 @@ -124,7 +125,8 @@ class Policy: if self.hardware: return self.opened_here = True - self._show() + if not self._visible(): # a field taking focus and the app asking are one tap + self._show() def _close(self): self.hide_at, self.hide_asked = None, False @@ -137,18 +139,23 @@ class Policy: words = line.split() if words[:2] == ["field", "on"] and len(words) == 3 and words[2].isdigit(): self.field, self.hide_at = int(words[2]), None - if now < self.asked_until or (self.field < 2 and now < self.tapped_until): + # A field that takes focus while the finger is down was tapped, + # whatever version: Qt does not ask again for a keyboard it + # thinks is still up, after one that closed on its own. + if now < self.asked_until or (self.pressing and now < self.touched_until) \ + or (self.field < 2 and now < self.tapped_until): self._open() elif words == ["field", "off"]: self.field = 0 if self.opened_here: self.hide_at = now + self.HIDE_DELAY elif words == ["show"]: + # Asked for right after a touch: Qt asks only for a text item it + # focused, and may enable its text input only at the next input + # event (a field tapped again after focus went elsewhere), so the + # request is enough. The keyboard types through key presses. if now < self.touched_until: - if self.field: - self._open() - else: - self.asked_until = now + self.SHOW_WAIT + self._open() elif words == ["hide"]: # Held back a moment: an app that asks to hide and show again at # once (to be heard after the person put the keyboard away) must @@ -157,7 +164,9 @@ class Policy: self.hide_at, self.hide_asked = now + self.HIDE_DELAY, True elif words == ["press"]: self.touched_until = now + self.TOUCH_WINDOW + self.pressing = True elif words[:1] == ["release"] and len(words) == 3 and words[1].isdigit() and words[2].isdigit(): + self.pressing = False if int(words[1]) <= self.TAP_MS and int(words[2]) <= self.TAP_PX: self.touched_until = self.tapped_until = now + self.TOUCH_WINDOW if 0 < self.field < 2: diff --git a/tests/test_keyboard_policy.py b/tests/test_keyboard_policy.py index 536ae081..c299f2df 100644 --- a/tests/test_keyboard_policy.py +++ b/tests/test_keyboard_policy.py @@ -83,10 +83,10 @@ def test_a_request_before_its_field_is_kept_a_moment(self): self.facts('press', TAP, 'show', 'field on 2') # Folio: the path label becomes a field self.assertEqual(self.calls, ['show']) - def test_a_request_long_before_its_field_is_not(self): - self.facts('press', TAP, 'show') + def test_a_request_long_after_a_tap_is_not(self): + self.facts('press', TAP) self.wait(1) - self.facts('field on 2') + self.facts('show', 'field on 2') # an app asking by itself later self.assertEqual(self.calls, []) def test_a_tap_in_a_version_1_field_opens_it(self): @@ -142,17 +142,46 @@ def test_a_tap_after_the_person_put_it_away_opens_it_again(self): # Qt is not told of the swipe; the field asks hide-then-show to be heard. self.facts('field on 2', 'press', 'show') self.policy.person('hide') + self.shown = False # the swipe put it away self.calls.clear() self.wait(1) self.facts('press', 'hide', 'show') self.wait(1) self.assertEqual(self.calls, ['show']) + def test_tapping_the_same_field_again_after_it_closed_on_its_own_opens_it(self): + # Qt with the focus fix: tapping outside turns the field off; Qt still + # thinks the keyboard is up and asks nothing on the next tap. + self.facts('press', 'field on 2', TAP, 'show') + self.facts('press', 'field off', TAP) + self.wait(1) + self.facts('press', 'field on 2', TAP) + self.wait(1) + self.assertEqual(self.calls, ['show', 'hide', 'show']) + + def test_a_request_after_a_tap_opens_it_before_qt_enables_its_field(self): + # Qt 6.12 on a field tapped again: show at once, the enable only with + # the next press, and disabled again right after. + self.facts('press', 'field on 2', TAP, 'show') + self.facts('press', 'field off', TAP) + self.wait(1) + self.facts('press', TAP, 'show') + self.wait(1) + self.assertEqual(self.calls, ['show', 'hide', 'show']) + self.facts('press', 'field on 2', 'field off', TAP) + self.wait(1) + self.assertEqual(self.calls, ['show', 'hide', 'show', 'hide']) + + def test_a_field_focused_after_the_finger_lifts_does_not_open_it(self): + self.facts('press', TAP, 'field on 2') # a click handler focusing a field + self.wait(1) + self.assertEqual(self.calls, []) + def test_hide_then_show_at_once_does_not_blink_an_open_keyboard(self): self.facts('field on 2', 'press', 'show') self.facts('press', 'hide', 'show') self.wait(1) - self.assertEqual(self.calls, ['show', 'show']) + self.assertEqual(self.calls, ['show']) # still up, not shown twice def test_one_the_person_opened_stays_when_the_field_goes(self): self.facts('field on 2') @@ -165,6 +194,7 @@ def test_one_the_person_opened_stays_when_the_field_goes(self): def test_one_the_person_put_away_stays_away_until_the_next_tap(self): self.facts('field on 2', 'press', 'show') self.policy.person('hide') + self.shown = False # the swipe put it away self.wait(1) self.facts('show', 'field off', 'field on 2') self.wait(1)