Skip to content

Commit 57b83e4

Browse files
Move to InputManager
1 parent 6c0cf44 commit 57b83e4

2 files changed

Lines changed: 59 additions & 31 deletions

File tree

docs/apps/app-lifecycle.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,34 +219,7 @@ Activity Stack:
219219

220220
### Disabling Navigation Globally
221221

222-
Apps that need full control over the back and menu buttons can disable the system-level actions globally via `InputManager`:
223-
224-
```python
225-
from mpos.ui.input_manager import InputManager
226-
227-
# Disable back-screen navigation (hardware back button, swipe-back gesture)
228-
InputManager.set_back_screen_disabled(True)
229-
230-
# Disable top-menu drawer opening (hardware menu button, swipe-down gesture)
231-
InputManager.set_drawer_open_disabled(True)
232-
233-
# Query current state
234-
if not InputManager.is_back_screen_disabled():
235-
InputManager.set_back_screen_disabled(True)
236-
```
237-
238-
The same functions are also available as top-level `mpos` imports:
239-
240-
```python
241-
import mpos
242-
mpos.set_back_screen_disabled(True)
243-
mpos.set_drawer_open_disabled(True)
244-
```
245-
246-
- `close_drawer()` still works when drawer opening is disabled — you can close an already-open drawer.
247-
- `finish_current_activity()` (called directly) is not gated, only `back_screen()`.
248-
- All paths — hardware key handlers, gesture navigation, and programmatic calls — funnel through `back_screen()` and `open_drawer()`/`toggle_drawer()`, so a single call gates every trigger.
249-
- When disabled, the back-screen and drawer-open actions invoke optional callbacks passed to `set_back_screen_disabled(True, cb=...)` and `set_drawer_open_disabled(True, cb=...)`. The callbacks receive no arguments. If no callback is set, the action is silently consumed.
222+
Apps that need full control over the back and menu buttons can disable system-level navigation globally. See the [InputManager navigation gating](../frameworks/input-manager.md#navigation-gating) documentation.
250223

251224
## Starting Activities
252225

docs/frameworks/input-manager.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ InputManager centralizes all input-related operations in a single class with cla
1111
- **Testable** - InputManager can be tested independently
1212
- **Pointer Access** - Get current touch/pointer coordinates
1313
- **Device Registration** - Register and query available input devices by type
14+
- **Navigation Gating** - Disable system-level back and drawer-open actions globally
15+
- **Touch Feedback** - Attach haptic/touch-feedback callbacks to pointer devices
1416

1517
## Architecture
1618

@@ -87,16 +89,69 @@ Check if any registered input device is a pointer/touch device.
8789
**Returns:** bool - True if a pointer device is registered
8890

8991
#### `emulate_focus_obj(focusgroup, target)`
90-
Deprecated compatibility shim. Use `lv.group_focus_obj(target)` directly.
92+
**Deprecated.** Compatibility shim. Use `lv.group_focus_obj(target)` directly.
9193

9294
#### `register_indev(indev)`
93-
Register an input device for later querying by type.
95+
Register an input device for later querying by type. Called by board initialization code.
96+
97+
#### `unregister_indev(indev)`
98+
Unregister an input device. Disables the device (`indev.enable(False)`) and removes it from the registry.
9499

95100
#### `list_indevs()`
96101
Get list of all registered input devices.
97102

98103
#### `has_indev_type(indev_type)`
99-
Check if any registered input device has the specified type.
104+
Check if any registered input device has the specified type (e.g., `lv.INDEV_TYPE.KEYPAD`, `lv.INDEV_TYPE.POINTER`).
105+
106+
#### `has_haptic_feedback()`
107+
Check whether touch feedback (haptic) has been set up on pointer devices.
108+
109+
**Returns:** bool
110+
111+
#### `set_touch_feedback_cb(cb)`
112+
Attach a callback `cb(event)` to every registered pointer input device on `LV_EVENT.CLICKED`. LVGL sends `CLICKED` on touch release only when the press did not scroll a scrollable parent, so the callback fires on taps but not on swipes. Call once at boot; calling again re-registers the callback.
113+
114+
## Navigation Gating
115+
116+
Apps that need full control over the back and menu buttons can disable system-level navigation actions globally via InputManager:
117+
118+
```python
119+
from mpos.ui.input_manager import InputManager
120+
import mpos
121+
122+
InputManager.set_back_screen_disabled(True)
123+
InputManager.set_drawer_open_disabled(True)
124+
125+
if not InputManager.is_back_screen_disabled():
126+
InputManager.set_back_screen_disabled(True)
127+
```
128+
129+
The same functions are also available as top-level `mpos` imports:
130+
131+
```python
132+
import mpos
133+
mpos.set_back_screen_disabled(True)
134+
mpos.set_drawer_open_disabled(True)
135+
```
136+
137+
- `close_drawer()` still works when drawer opening is disabled — you can close an already-open drawer.
138+
- `finish_current_activity()` (called directly) is not gated, only `back_screen()`.
139+
- All paths — hardware key handlers, gesture navigation, and programmatic calls — funnel through `back_screen()` and `open_drawer()`/`toggle_drawer()`, so a single call gates every trigger.
140+
- When disabled, the back-screen and drawer-open actions invoke optional callbacks passed to `set_back_screen_disabled(True, cb=...)` and `set_drawer_open_disabled(True, cb=...)`. The callbacks receive no arguments. If no callback is set, the action is silently consumed.
141+
142+
### Navigation Gating API
143+
144+
#### `set_back_screen_disabled(disabled, cb=None)`
145+
Disable or enable the back-screen navigation action. When `disabled=True`, back-screen actions are consumed (optionally invoking `cb`).
146+
147+
#### `is_back_screen_disabled()`
148+
**Returns:** bool — True if back-screen navigation is currently disabled.
149+
150+
#### `set_drawer_open_disabled(disabled, cb=None)`
151+
Disable or enable the top-menu drawer open action. When `disabled=True`, drawer-open actions are consumed (optionally invoking `cb`).
152+
153+
#### `is_drawer_open_disabled()`
154+
**Returns:** bool — True if drawer opening is currently disabled.
100155

101156
## Related Frameworks
102157

0 commit comments

Comments
 (0)