mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 22:30:04 -04:00
Use new macOS 15 cursors for resize icons (#4422)
These look slightly different from the old ones. Verified that we now use the same cursor icons as those used in Safari 26.
This commit is contained in:
@@ -5,7 +5,10 @@ use std::sync::OnceLock;
|
|||||||
use objc2::rc::Retained;
|
use objc2::rc::Retained;
|
||||||
use objc2::runtime::Sel;
|
use objc2::runtime::Sel;
|
||||||
use objc2::{AllocAnyThread, ClassType, available, msg_send, sel};
|
use objc2::{AllocAnyThread, ClassType, available, msg_send, sel};
|
||||||
use objc2_app_kit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage};
|
use objc2_app_kit::{
|
||||||
|
NSBitmapImageRep, NSCursor, NSCursorFrameResizeDirections, NSCursorFrameResizePosition,
|
||||||
|
NSDeviceRGBColorSpace, NSImage,
|
||||||
|
};
|
||||||
use objc2_foundation::{
|
use objc2_foundation::{
|
||||||
NSData, NSDictionary, NSNumber, NSObject, NSPoint, NSSize, NSString, ns_string,
|
NSData, NSDictionary, NSNumber, NSObject, NSPoint, NSSize, NSString, ns_string,
|
||||||
};
|
};
|
||||||
@@ -204,23 +207,155 @@ pub(crate) fn cursor_from_icon(icon: CursorIcon) -> Retained<NSCursor> {
|
|||||||
CursorIcon::NotAllowed | CursorIcon::NoDrop => NSCursor::operationNotAllowedCursor(),
|
CursorIcon::NotAllowed | CursorIcon::NoDrop => NSCursor::operationNotAllowedCursor(),
|
||||||
CursorIcon::ContextMenu => NSCursor::contextualMenuCursor(),
|
CursorIcon::ContextMenu => NSCursor::contextualMenuCursor(),
|
||||||
CursorIcon::Crosshair => NSCursor::crosshairCursor(),
|
CursorIcon::Crosshair => NSCursor::crosshairCursor(),
|
||||||
CursorIcon::EResize => NSCursor::resizeRightCursor(),
|
CursorIcon::EResize => {
|
||||||
CursorIcon::NResize => NSCursor::resizeUpCursor(),
|
if available!(macos = 15.0) {
|
||||||
CursorIcon::WResize => NSCursor::resizeLeftCursor(),
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
CursorIcon::SResize => NSCursor::resizeDownCursor(),
|
NSCursorFrameResizePosition::Right,
|
||||||
CursorIcon::EwResize | CursorIcon::ColResize => NSCursor::resizeLeftRightCursor(),
|
NSCursorFrameResizeDirections::Outward,
|
||||||
CursorIcon::NsResize | CursorIcon::RowResize => NSCursor::resizeUpDownCursor(),
|
)
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeRightCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::NResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::Top,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeUpCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::WResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::Left,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeLeftCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::SResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::Bottom,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeDownCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::EwResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::Right,
|
||||||
|
NSCursorFrameResizeDirections::All,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeLeftRightCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::NsResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::Top,
|
||||||
|
NSCursorFrameResizeDirections::All,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeUpDownCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::NeResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::TopRight,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_windowResizeNorthEastCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::NwResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::TopLeft,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_windowResizeNorthWestCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::SeResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::BottomRight,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_windowResizeSouthEastCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::SwResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::BottomLeft,
|
||||||
|
NSCursorFrameResizeDirections::Outward,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_windowResizeSouthWestCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::NeswResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::TopRight,
|
||||||
|
NSCursorFrameResizeDirections::All,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_windowResizeNorthEastSouthWestCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::NwseResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::frameResizeCursorFromPosition_inDirections(
|
||||||
|
NSCursorFrameResizePosition::TopLeft,
|
||||||
|
NSCursorFrameResizeDirections::All,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_windowResizeNorthWestSouthEastCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::ColResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::columnResizeCursor()
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeLeftRightCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::RowResize => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::rowResizeCursor()
|
||||||
|
} else {
|
||||||
|
NSCursor::resizeUpDownCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::ZoomIn => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::zoomInCursor()
|
||||||
|
} else {
|
||||||
|
_zoomInCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CursorIcon::ZoomOut => {
|
||||||
|
if available!(macos = 15.0) {
|
||||||
|
NSCursor::zoomOutCursor()
|
||||||
|
} else {
|
||||||
|
_zoomOutCursor()
|
||||||
|
}
|
||||||
|
},
|
||||||
CursorIcon::Help => _helpCursor(),
|
CursorIcon::Help => _helpCursor(),
|
||||||
CursorIcon::ZoomIn if available!(macos = 15.0) => NSCursor::zoomInCursor(),
|
|
||||||
CursorIcon::ZoomIn => _zoomInCursor(),
|
|
||||||
CursorIcon::ZoomOut if available!(macos = 15.0) => NSCursor::zoomOutCursor(),
|
|
||||||
CursorIcon::ZoomOut => _zoomOutCursor(),
|
|
||||||
CursorIcon::NeResize => _windowResizeNorthEastCursor(),
|
|
||||||
CursorIcon::NwResize => _windowResizeNorthWestCursor(),
|
|
||||||
CursorIcon::SeResize => _windowResizeSouthEastCursor(),
|
|
||||||
CursorIcon::SwResize => _windowResizeSouthWestCursor(),
|
|
||||||
CursorIcon::NeswResize => _windowResizeNorthEastSouthWestCursor(),
|
|
||||||
CursorIcon::NwseResize => _windowResizeNorthWestSouthEastCursor(),
|
|
||||||
// This is the wrong semantics for `Wait`, but it's the same as
|
// This is the wrong semantics for `Wait`, but it's the same as
|
||||||
// what's used in Safari and Chrome.
|
// what's used in Safari and Chrome.
|
||||||
CursorIcon::Wait | CursorIcon::Progress => busyButClickableCursor(),
|
CursorIcon::Wait | CursorIcon::Progress => busyButClickableCursor(),
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ changelog entry.
|
|||||||
- On iOS, add Apple Pencil support with force, altitude, and azimuth data.
|
- On iOS, add Apple Pencil support with force, altitude, and azimuth data.
|
||||||
- On Redox, add support for missing keyboard scancodes.
|
- On Redox, add support for missing keyboard scancodes.
|
||||||
- Implement `Send` and `Sync` for `OwnedDisplayHandle`.
|
- Implement `Send` and `Sync` for `OwnedDisplayHandle`.
|
||||||
|
- Use new macOS 15 cursors for resize icons.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user