core-foundation-rs icon indicating copy to clipboard operation
core-foundation-rs copied to clipboard

Existing `CGMouseButton` enum is too limited

Open pentamassiv opened this issue 1 month ago • 1 comments

The existing CGMouseButton enum is too limited for what Quartz actually supports. Apple allows 0–31, but the Rust enum only exposes Left, Right, Center:

// Constants that specify buttons on a one, two, or three-button mouse.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub enum CGMouseButton {
    Left,
    Right,
    Center,
}

This makes it impossible to simulate an event with the new_mouse_event function with the buttons 3-31.

I can create a PR to fix it, but I am not sure what solution you would prefer. Do you want to add enum variants Button3, Button4,...,Button31 or do you want to change it to be constants? I prefer adding enums to keep the type safety guarantees and make it impossible to call the function with values >31, but the names of the variants won't be pretty.

pentamassiv avatar Nov 18 '25 21:11 pentamassiv

I suggest using the objc2-core-graphics crate instead, which meets your needs: https://docs.rs/objc2-core-graphics/latest/objc2_core_graphics/struct.CGMouseButton.html

jdm avatar Nov 19 '25 01:11 jdm