Update bitflags to 2.0

Co-authored-by: dAxpeDDa <daxpedda@gmail.com>
This commit is contained in:
George Burton 2023-06-02 15:44:36 +01:00 committed by GitHub
parent d273518ce9
commit 31ebc5caf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 27 additions and 14 deletions

View file

@ -58,6 +58,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Web, fix `Window:::set_fullscreen` doing nothing when called outside the event loop but during - On Web, fix `Window:::set_fullscreen` doing nothing when called outside the event loop but during
a transient activation. a transient activation.
- On Web, fix pointer button events not being processed when a buttons is already pressed. - On Web, fix pointer button events not being processed when a buttons is already pressed.
- **Breaking:** Updated `bitflags` crate version to `2`, which changes the API on exposed types.
# 0.28.6 # 0.28.6

View file

@ -50,7 +50,7 @@ serde = ["dep:serde", "cursor-icon/serde", "smol_str/serde"]
cfg_aliases = "0.1.1" cfg_aliases = "0.1.1"
[dependencies] [dependencies]
bitflags = "1" bitflags = "2"
cursor-icon = "1.0.0" cursor-icon = "1.0.0"
instant = { version = "0.1", features = ["wasm-bindgen"] } instant = { version = "0.1", features = ["wasm-bindgen"] }
log = "0.4" log = "0.4"

View file

@ -1572,7 +1572,7 @@ bitflags! {
/// Represents the current state of the keyboard modifiers /// Represents the current state of the keyboard modifiers
/// ///
/// Each flag represents a modifier and is set if this modifier is active. /// Each flag represents a modifier and is set if this modifier is active.
#[derive(Default)] #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct ModifiersState: u32 { pub struct ModifiersState: u32 {
/// The "shift" key. /// The "shift" key.
const SHIFT = 0b100; const SHIFT = 0b100;
@ -1623,7 +1623,7 @@ pub enum ModifiersKeyState {
// to treat modifiers differently based on their position, which is required // to treat modifiers differently based on their position, which is required
// on macOS due to their AltGr/Option situation. // on macOS due to their AltGr/Option situation.
bitflags! { bitflags! {
#[derive(Default)] #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ModifiersKeys: u8 { pub(crate) struct ModifiersKeys: u8 {
const LSHIFT = 0b0000_0001; const LSHIFT = 0b0000_0001;
const RSHIFT = 0b0000_0010; const RSHIFT = 0b0000_0010;

View file

@ -287,14 +287,14 @@ bitflags! {
/// The [edges] of a screen. /// The [edges] of a screen.
/// ///
/// [edges]: https://developer.apple.com/documentation/uikit/uirectedge?language=objc /// [edges]: https://developer.apple.com/documentation/uikit/uirectedge?language=objc
#[derive(Default)] #[derive(Default, Clone, Copy)]
pub struct ScreenEdge: u8 { pub struct ScreenEdge: u8 {
const NONE = 0; const NONE = 0;
const TOP = 1 << 0; const TOP = 1 << 0;
const LEFT = 1 << 1; const LEFT = 1 << 1;
const BOTTOM = 1 << 2; const BOTTOM = 1 << 2;
const RIGHT = 1 << 3; const RIGHT = 1 << 3;
const ALL = ScreenEdge::TOP.bits | ScreenEdge::LEFT.bits const ALL = ScreenEdge::TOP.bits() | ScreenEdge::LEFT.bits()
| ScreenEdge::BOTTOM.bits | ScreenEdge::RIGHT.bits; | ScreenEdge::BOTTOM.bits() | ScreenEdge::RIGHT.bits();
} }
} }

View file

@ -39,6 +39,7 @@ extern_methods!(
); );
bitflags! { bitflags! {
#[derive(Clone, Copy)]
pub struct UIInterfaceOrientationMask: NSUInteger { pub struct UIInterfaceOrientationMask: NSUInteger {
const Portrait = 1 << 1; const Portrait = 1 << 1;
const PortraitUpsideDown = 1 << 2; const PortraitUpsideDown = 1 << 2;

View file

@ -109,6 +109,7 @@ unsafe impl Encode for NSApplicationActivationPolicy {
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy)]
pub struct NSApplicationPresentationOptions: NSUInteger { pub struct NSApplicationPresentationOptions: NSUInteger {
const NSApplicationPresentationDefault = 0; const NSApplicationPresentationDefault = 0;
const NSApplicationPresentationAutoHideDock = 1 << 0; const NSApplicationPresentationAutoHideDock = 1 << 0;

View file

@ -194,6 +194,7 @@ const NX_DEVICERALTKEYMASK: u32 = 0x00000040;
const NX_DEVICERCTLKEYMASK: u32 = 0x00002000; const NX_DEVICERCTLKEYMASK: u32 = 0x00002000;
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NSEventModifierFlags: NSUInteger { pub struct NSEventModifierFlags: NSUInteger {
const NSAlphaShiftKeyMask = 1 << 16; const NSAlphaShiftKeyMask = 1 << 16;
const NSShiftKeyMask = 1 << 17; const NSShiftKeyMask = 1 << 17;
@ -212,6 +213,7 @@ unsafe impl Encode for NSEventModifierFlags {
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NSEventPhase: NSUInteger { pub struct NSEventPhase: NSUInteger {
const NSEventPhaseNone = 0; const NSEventPhaseNone = 0;
const NSEventPhaseBegan = 0x1 << 0; const NSEventPhaseBegan = 0x1 << 0;

View file

@ -336,6 +336,7 @@ unsafe impl Encode for NSWindowLevel {
} }
bitflags! { bitflags! {
#[derive(Clone, Copy)]
pub struct NSWindowOcclusionState: NSUInteger { pub struct NSWindowOcclusionState: NSUInteger {
const NSWindowOcclusionStateVisible = 1 << 1; const NSWindowOcclusionStateVisible = 1 << 1;
} }
@ -346,6 +347,7 @@ unsafe impl Encode for NSWindowOcclusionState {
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy)]
pub struct NSWindowStyleMask: NSUInteger { pub struct NSWindowStyleMask: NSUInteger {
const NSBorderlessWindowMask = 0; const NSBorderlessWindowMask = 0;
const NSTitledWindowMask = 1 << 0; const NSTitledWindowMask = 1 << 0;

View file

@ -71,6 +71,7 @@ enum ImeState {
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy, PartialEq)]
struct ModLocationMask: u8 { struct ModLocationMask: u8 {
const LEFT = 1; const LEFT = 1;
const RIGHT = 2; const RIGHT = 2;

View file

@ -120,7 +120,7 @@ fn element_state(pressed: bool) -> event::ElementState {
} }
bitflags! { bitflags! {
#[derive(Default)] #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct KeyboardModifierState: u8 { struct KeyboardModifierState: u8 {
const LSHIFT = 1 << 0; const LSHIFT = 1 << 0;
const RSHIFT = 1 << 1; const RSHIFT = 1 << 1;
@ -134,7 +134,7 @@ bitflags! {
} }
bitflags! { bitflags! {
#[derive(Default)] #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct MouseButtonState: u8 { struct MouseButtonState: u8 {
const LEFT = 1 << 0; const LEFT = 1 << 0;
const MIDDLE = 1 << 1; const MIDDLE = 1 << 1;

View file

@ -7,6 +7,7 @@ use std::convert::TryInto;
use web_sys::{HtmlCanvasElement, KeyboardEvent, MouseEvent, PointerEvent, WheelEvent}; use web_sys::{HtmlCanvasElement, KeyboardEvent, MouseEvent, PointerEvent, WheelEvent};
bitflags! { bitflags! {
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ButtonsState: u16 { pub struct ButtonsState: u16 {
const LEFT = 0b001; const LEFT = 0b001;
const RIGHT = 0b010; const RIGHT = 0b010;
@ -31,13 +32,13 @@ impl From<MouseButton> for ButtonsState {
MouseButton::Left => ButtonsState::LEFT, MouseButton::Left => ButtonsState::LEFT,
MouseButton::Right => ButtonsState::RIGHT, MouseButton::Right => ButtonsState::RIGHT,
MouseButton::Middle => ButtonsState::MIDDLE, MouseButton::Middle => ButtonsState::MIDDLE,
MouseButton::Other(value) => unsafe { ButtonsState::from_bits_unchecked(value) }, MouseButton::Other(value) => ButtonsState::from_bits_retain(value),
} }
} }
} }
pub fn mouse_buttons(event: &MouseEvent) -> ButtonsState { pub fn mouse_buttons(event: &MouseEvent) -> ButtonsState {
unsafe { ButtonsState::from_bits_unchecked(event.buttons()) } ButtonsState::from_bits_retain(event.buttons())
} }
pub fn mouse_button(event: &MouseEvent) -> Option<MouseButton> { pub fn mouse_button(event: &MouseEvent) -> Option<MouseButton> {

View file

@ -105,6 +105,7 @@ static NUMPAD_KEYCODES: Lazy<HashSet<KeyCode>> = Lazy::new(|| {
}); });
bitflags! { bitflags! {
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct WindowsModifiers : u8 { pub struct WindowsModifiers : u8 {
const SHIFT = 1 << 0; const SHIFT = 1 << 0;
const CONTROL = 1 << 1; const CONTROL = 1 << 1;
@ -362,11 +363,11 @@ impl LayoutCache {
} }
// Iterate through every combination of modifiers // Iterate through every combination of modifiers
let mods_end = WindowsModifiers::FLAGS_END.bits; let mods_end = WindowsModifiers::FLAGS_END.bits();
for mod_state in 0..mods_end { for mod_state in 0..mods_end {
let mut keys_for_this_mod = HashMap::with_capacity(256); let mut keys_for_this_mod = HashMap::with_capacity(256);
let mod_state = unsafe { WindowsModifiers::from_bits_unchecked(mod_state) }; let mod_state = WindowsModifiers::from_bits_retain(mod_state);
mod_state.apply_to_kbd_state(&mut key_state); mod_state.apply_to_kbd_state(&mut key_state);
// Virtual key values are in the domain [0, 255]. // Virtual key values are in the domain [0, 255].
@ -442,7 +443,7 @@ impl LayoutCache {
// Second pass: replace right alt keys with AltGr if the layout has alt graph // Second pass: replace right alt keys with AltGr if the layout has alt graph
if layout.has_alt_graph { if layout.has_alt_graph {
for mod_state in 0..mods_end { for mod_state in 0..mods_end {
let mod_state = unsafe { WindowsModifiers::from_bits_unchecked(mod_state) }; let mod_state = WindowsModifiers::from_bits_retain(mod_state);
if let Some(keys) = layout.keys.get_mut(&mod_state) { if let Some(keys) = layout.keys.get_mut(&mod_state) {
if let Some(key) = keys.get_mut(&KeyCode::AltRight) { if let Some(key) = keys.get_mut(&KeyCode::AltRight) {
*key = Key::AltGraph; *key = Key::AltGraph;

View file

@ -71,6 +71,7 @@ pub struct MouseProperties {
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CursorFlags: u8 { pub struct CursorFlags: u8 {
const GRABBED = 1 << 0; const GRABBED = 1 << 0;
const HIDDEN = 1 << 1; const HIDDEN = 1 << 1;
@ -78,6 +79,7 @@ bitflags! {
} }
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WindowFlags: u32 { pub struct WindowFlags: u32 {
const RESIZABLE = 1 << 0; const RESIZABLE = 1 << 0;
const MINIMIZABLE = 1 << 1; const MINIMIZABLE = 1 << 1;
@ -118,7 +120,7 @@ bitflags! {
const MARKER_ACTIVATE = 1 << 21; const MARKER_ACTIVATE = 1 << 21;
const EXCLUSIVE_FULLSCREEN_OR_MASK = WindowFlags::ALWAYS_ON_TOP.bits; const EXCLUSIVE_FULLSCREEN_OR_MASK = WindowFlags::ALWAYS_ON_TOP.bits();
} }
} }

View file

@ -1480,6 +1480,7 @@ pub enum UserAttentionType {
} }
bitflags! { bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WindowButtons: u32 { pub struct WindowButtons: u32 {
const CLOSE = 1 << 0; const CLOSE = 1 << 0;
const MINIMIZE = 1 << 1; const MINIMIZE = 1 << 1;