Comments (3)
As a random member of the public, I do not have push access to this public repository (which is understandable), so I could not create a pull request.
Here is a diff that captures my fix for the issue.
diff --git a/internal/backends/android-activity/androidwindowadapter.rs b/internal/backends/android-activity/androidwindowadapter.rs
index 10e98dff8..ff26cd9ea 100644
--- a/internal/backends/android-activity/androidwindowadapter.rs
+++ b/internal/backends/android-activity/androidwindowadapter.rs
@@ -3,7 +3,9 @@
use super::*;
use crate::javahelper::{print_jni_error, JavaHelper};
-use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction, MotionEvent};
+use android_activity::input::{
+ ButtonState, InputEvent, KeyAction, Keycode, MotionAction, MotionEvent,
+};
use android_activity::{InputStatus, MainEvent, PollEvent};
use i_slint_core::api::{LogicalPosition, PhysicalPosition, PhysicalSize, PlatformError, Window};
use i_slint_core::items::ColorScheme;
@@ -40,6 +42,7 @@ pub struct AndroidWindowAdapter {
pub(crate) show_cursor_handles: Cell<bool>,
long_press: RefCell<Option<LongPressDetection>>,
+ last_pressed_state: Cell<ButtonState>,
}
impl WindowAdapter for AndroidWindowAdapter {
@@ -187,6 +190,7 @@ pub fn new(app: AndroidApp) -> Rc<Self> {
offset: Default::default(),
show_cursor_handles: Cell::new(false),
long_press: RefCell::default(),
+ last_pressed_state: Cell::new(ButtonState(0)),
})
}
@@ -281,7 +285,7 @@ fn process_inputs(&self) -> Result<(), android_activity::error::AppError> {
self.window.dispatch_event(WindowEvent::PointerPressed {
position: position_for_event(motion_event, self.offset.get())
.to_logical(self.window.scale_factor()),
- button: button_for_event(motion_event),
+ button: button_for_event(motion_event, &self.last_pressed_state),
});
InputStatus::Handled
}
@@ -308,7 +312,7 @@ fn process_inputs(&self) -> Result<(), android_activity::error::AppError> {
self.window.dispatch_event(WindowEvent::PointerReleased {
position: position_for_event(motion_event, self.offset.get())
.to_logical(self.window.scale_factor()),
- button: button_for_event(motion_event),
+ button: button_for_event(motion_event, &self.last_pressed_state),
});
InputStatus::Handled
}
@@ -456,13 +460,51 @@ fn position_for_event(motion_event: &MotionEvent, offset: PhysicalPosition) -> P
})
}
-fn button_for_event(motion_event: &MotionEvent) -> PointerEventButton {
- match motion_event.action_button() {
- android_activity::input::Button::Primary => PointerEventButton::Left,
- android_activity::input::Button::Secondary => PointerEventButton::Right,
- android_activity::input::Button::Tertiary => PointerEventButton::Middle,
- _ => PointerEventButton::Other,
+fn button_for_event(
+ motion_event: &MotionEvent,
+ last_pressed_cell: &Cell<ButtonState>,
+) -> PointerEventButton {
+ //
+ // The motion_event API has a method called action_button() which can be used to directly
+ // determine the button associated with the event. However, the disadvantage of using the
+ // action_button() API is that it relies on NDK 33 or higher, which implies that the output
+ // application will only run on Android 13 or higher.
+ //
+ // This functionally equivalent method of computing the action button relies on the
+ // button_state() call from the motion event, rather than action_button(). It is a bit more
+ // complex than using action_button() directly, since the previous button state must be
+ // tracked and used in the calculation for computing which button was toggled. However, this
+ // will run on Android 12 (and possibly lower).
+ //
+ // See here for further discussion:
+ //
+ // https://stackoverflow.com/questions/75718566/amotionevent-getbuttonstate-returns-0-for-every-button-during-mouse-button-relea
+ //
+ let cur_pressed_state = motion_event.button_state();
+ let last_pressed_state = last_pressed_cell.get();
+ let toggled = match motion_event.action() {
+ MotionAction::ButtonPress => {
+ last_pressed_cell.set(cur_pressed_state);
+ ButtonState((last_pressed_state.0 ^ cur_pressed_state.0) & cur_pressed_state.0)
+ }
+ MotionAction::ButtonRelease => {
+ last_pressed_cell.set(cur_pressed_state);
+ ButtonState((last_pressed_state.0 ^ cur_pressed_state.0) & last_pressed_state.0)
+ }
+ _ => ButtonState(0),
+ };
+
+ // if multiple buttons toggled, primary takes precedence, then secondary, etc.
+ if toggled.primary() {
+ return PointerEventButton::Left;
+ }
+ if toggled.secondary() {
+ return PointerEventButton::Right;
+ }
+ if toggled.teriary() {
+ return PointerEventButton::Middle;
}
+ return PointerEventButton::Other;
}
fn map_key_event(key_event: &android_activity::input::KeyEvent) -> Option<WindowEvent> {
from slint.
I took the liberty to turn this diff into a PR here: #5047 for your review-conveninece.
The code looks sensible to me, but I have no Android setup here (nor a Android 12 device) to test this with.
@matthewjrichey: You can clone the repo, push your code into your own clone and then create a PR from that. This approach is not limited to Slint, it works for any project on github, just in case you run into the situation again.
from slint.
Thank you for your time and contribution. I think this is small enough to count as a "simple fix" and not need the full CLA dance, which my PR goes around...
from slint.
Related Issues (20)
- Add the aibility to reference a component from another one
- [slint-lsp/vscode] action to open the element's document at the cursor's position HOT 4
- OpenCV's highgui::select_roi() function does not render fully when used with Slint (Rust)
- TimePicker widget HOT 2
- LineEdit Widget Error HOT 2
- Quickstart Rust Example Code Display Defect HOT 2
- Using Path in an embedded project will result in a compilation error. HOT 1
- is it possible to express a tree in this type system? HOT 1
- Path: Can't parse commands containing scientific notation HOT 3
- Performance issues using imports vs single .slint file HOT 6
- RFC: date-time builtin type HOT 2
- Component catalogue in Design Mode includes component under preview, resulting in compilation errors on drop HOT 2
- Component catalogue shows user defined duplicates in gallery demo HOT 1
- Built-in VirtualKeyboard element for improved support for in-process embedded virtual keyboards
- A bug with booleans, rust slint. HOT 3
- Android: double-clicked callback not work on TouchArea HOT 2
- Android: default-font-family not work
- Support libraries in LSP
- Compiler panic compiling `init` callback from a component inlined into a repeater HOT 1
- Include LTS Version as slintpad dependency
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slint.