-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web: implement
DeviceIdExtWebSys::is_primary()
- Loading branch information
Showing
7 changed files
with
119 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
use web_sys::PointerEvent; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct DeviceId(pub i32); | ||
pub struct DeviceId { | ||
pub id: Option<u32>, | ||
pub primary: bool, | ||
} | ||
|
||
impl DeviceId { | ||
pub const unsafe fn dummy() -> Self { | ||
Self(0) | ||
pub fn new(event: &PointerEvent) -> Self { | ||
Self { | ||
// We assume that browsers don't use negative numbers unless they are representing the | ||
// reserved `-1` for non-pointing devices. | ||
id: event.pointer_id().try_into().ok(), | ||
primary: event.is_primary(), | ||
} | ||
} | ||
|
||
pub const fn dummy() -> Self { | ||
Self { id: None, primary: true } | ||
} | ||
|
||
pub const fn is_primary(&self) -> bool { | ||
self.primary | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.