Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
74b68ef
Remove monomorphic drag-and-drop implementation
eira-fransham Jun 19, 2026
f8f4ef9
Implement new drag-and-drop API in `winit-core`
eira-fransham Jun 19, 2026
8fe74e9
Rename `drop_handler.rs` to `dnd.rs` in `winit-win32`
eira-fransham Jun 19, 2026
a3858ae
Implement new drag-and-drop API for `winit-win32`
eira-fransham Jun 19, 2026
2f39b4f
Implement new drag-and-drop API for `winit-appkit`
eira-fransham Jun 19, 2026
ca910e3
Implement new drag-and-drop API for `winit-wayland`
eira-fransham Jun 19, 2026
d81657f
Implement new drag-and-drop API for `winit-x11`
eira-fransham Jun 19, 2026
8041928
Drop the `Ref` returned by `current_drag_actions`
eira-fransham Jul 6, 2026
1c5d6fb
Respond to PR feedback
eira-fransham Jul 8, 2026
6f98b7e
Fix 32-bit Linux
eira-fransham Jul 9, 2026
bb7580b
AppKit: Avoid incorrectly synthesising window ID
eira-fransham Jul 9, 2026
c452a50
Better documentation
eira-fransham Jul 9, 2026
4ab2f37
Actually truly enforce URIs being URIs, and provide helpers to/from p…
eira-fransham Jul 9, 2026
feb424b
amend! AppKit: Avoid incorrectly synthesising window ID
eira-fransham Jul 9, 2026
8905da6
amend! Respond to PR feedback
eira-fransham Jul 9, 2026
229f9bf
Replicate cfg for URL file path handling on web targets
eira-fransham Jul 9, 2026
237884e
Fix bitset | in win32
eira-fransham Jul 14, 2026
2ad3389
`copy_from_slice`->`extend_from_slice` in Wayland
eira-fransham Jul 14, 2026
3cbd05a
Make writing URI lists eager (winit-wayland)
eira-fransham Jul 14, 2026
2b9a730
`dnd/mod.rs`->`dnd.rs` (winit-wayland)
eira-fransham Jul 14, 2026
78a74ea
Fix large data transfer on Wayland
eira-fransham Jul 15, 2026
9aedbc1
Fix weston panic (winit-wayland)
eira-fransham Jul 15, 2026
1e6c2ad
Fix wasm build
eira-fransham Jul 16, 2026
7264c32
Fix wasm build
eira-fransham Jul 16, 2026
2407737
Allow future incompatibility lint from cfg_aliases 0.2.1
eira-fransham Jul 16, 2026
d08e68d
Only copy is implemented on X11, so we should remove X11 link/move fr…
eira-fransham Jul 16, 2026
59d44f4
Fix remaining issues
eira-fransham Jul 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"] }
serde = { version = "1", features = ["serde_derive"] }
smol_str = "0.3"
tracing = { version = "0.1.40", default-features = false }
url = "2"

# Dev dependencies.
image = { version = "0.25.0", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TME_LEAVE = "TME_LEAVE" # From windows_sys::Win32::UI::Input::Keyboa
XF86_Calculater = "XF86_Calculater" # From xkbcommon_dl::keysyms::XF86_Calculater
ptd = "ptd" # From windows_sys::Win32::System::Com::FORMATETC { ptd, ..}
requestor = "requestor" # From x11_dl::xlib::XSelectionEvent { requestor ..}
unknwn = "unknwn" # Windows SDK header filename `unknwn.h`
Comment thread
eira-fransham marked this conversation as resolved.
Resolved

[files]
extend-exclude = ["*.drawio"]
3 changes: 3 additions & 0 deletions winit-appkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ objc2-app-kit = { workspace = true, features = [
"NSControl",
"NSCursor",
"NSDragging",
"NSDraggingItem",
"NSDraggingSession",
"NSEvent",
"NSGraphics",
"NSGraphicsContext",
Expand All @@ -46,6 +48,7 @@ objc2-app-kit = { workspace = true, features = [
"NSOpenGLView",
"NSPanel",
"NSPasteboard",
"NSPasteboardItem",
"NSResponder",
"NSRunningApplication",
"NSScreen",
Expand Down
54 changes: 52 additions & 2 deletions winit-appkit/src/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
use std::cell::{Cell, OnceCell, RefCell};
use std::collections::HashMap;
use std::mem;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Instant;

use dispatch2::MainThreadBound;
use objc2::MainThreadMarker;
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSRunningApplication};
use objc2::rc::{Retained, Weak};
use objc2_app_kit::{
NSApplication, NSApplicationActivationPolicy, NSDragOperation, NSRunningApplication,
};
use objc2_foundation::NSNotification;
use winit_common::core_foundation::{EventLoopProxy, MainRunLoop};
use winit_common::event_handler::EventHandler;
use winit_core::application::ApplicationHandler;
use winit_core::data_transfer::DataTransferId;
use winit_core::event::{StartCause, WindowEvent};
use winit_core::event_loop::ControlFlow;
use winit_core::event_loop::{ControlFlow, DndAction};
use winit_core::window::WindowId;

use super::event_loop::{ActiveEventLoop, notify_windows_of_exit, stop_app_immediately};
use super::menu;
use super::observer::EventLoopWaker;
use crate::dnd::Pasteboards;
use crate::window_delegate::WindowDelegate;

#[derive(Debug)]
pub(super) struct AppState {
mtm: MainThreadMarker,
drag_state: RefCell<Option<DragState>>,
pasteboards: Pasteboards,
activation_policy: Option<NSApplicationActivationPolicy>,
default_menu: bool,
activate_ignoring_other_apps: bool,
Expand All @@ -43,10 +52,17 @@ pub(super) struct AppState {
start_time: Cell<Option<Instant>>,
wait_timeout: Cell<Option<Instant>>,
pending_redraw: RefCell<Vec<WindowId>>,
windows: RefCell<HashMap<WindowId, MainThreadBound<Weak<WindowDelegate>>>>,
// NOTE: This is strongly referenced by our `NSWindowDelegate` and our `NSView` subclass, and
// as such should be careful to not add fields that, in turn, strongly reference those.
}

#[derive(Debug)]
pub(crate) struct DragState {
pub id: DataTransferId,
pub valid_actions: Vec<DndAction>,
}

// SAFETY: Creating `MainThreadBound` in a `const` context, where there is no concept of the
// main thread.
static GLOBAL: MainThreadBound<OnceCell<Rc<AppState>>> =
Expand All @@ -65,6 +81,8 @@ impl AppState {

let this = Rc::new(Self {
mtm,
pasteboards: Default::default(),
drag_state: Default::default(),
activation_policy,
default_menu,
activate_ignoring_other_apps,
Expand All @@ -82,6 +100,7 @@ impl AppState {
waker: RefCell::new(EventLoopWaker::new()),
start_time: Cell::new(None),
wait_timeout: Cell::new(None),
windows: Default::default(),
pending_redraw: RefCell::new(vec![]),
});

Expand All @@ -96,6 +115,20 @@ impl AppState {
.clone()
}

pub fn with_window_delegate_on_main<F, R>(&self, id: WindowId, func: F) -> Option<R>
where
F: FnOnce(Retained<WindowDelegate>) -> R + Send,
R: Send,
{
self.windows.borrow_mut().get(&id)?.get_on_main(move |delegate| delegate.load().map(func))
}

pub fn register_window(&self, window: &Retained<WindowDelegate>, mtm: MainThreadMarker) {
let id = window.id();
let window_downgraded = Weak::from_retained(window);
self.windows.borrow_mut().insert(id, MainThreadBound::new(window_downgraded, mtm));
}

// NOTE: This notification will, globally, only be emitted once,
// no matter how many `EventLoop`s the user creates.
pub fn did_finish_launching(self: &Rc<Self>, _notification: &NSNotification) {
Expand Down Expand Up @@ -371,6 +404,23 @@ impl AppState {
};
self.waker.borrow_mut().start_at(min_timeout(wait_timeout, app_timeout));
}

pub fn pasteboards(&self) -> &Pasteboards {
&self.pasteboards
}

pub fn drag_state(&self) -> &RefCell<Option<DragState>> {
&self.drag_state
}

pub(crate) fn proposed_drag_action(
&self,
source_operations: NSDragOperation,
) -> Option<DndAction> {
self.drag_state().borrow().as_ref().and_then(|drag_state| {
crate::dnd::preferred_drag_operation(source_operations, &drag_state.valid_actions)
})
}
}

/// Returns the minimum `Option<Instant>`, taking into account that `None`
Expand Down
35 changes: 35 additions & 0 deletions winit-appkit/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use objc2_foundation::{
};
use winit_core::cursor::{CursorIcon, CursorImage, CustomCursorProvider, CustomCursorSource};
use winit_core::error::{NotSupportedError, RequestError};
use winit_core::icon::{Icon, RgbaIcon};

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CustomCursor(pub(crate) Retained<NSCursor>);
Expand Down Expand Up @@ -42,6 +43,40 @@ impl CustomCursor {
}
}

pub(crate) fn image_from_icon(icon: &Icon) -> Result<Retained<NSImage>, RequestError> {
let rgba_icon = icon
.cast_ref::<RgbaIcon>()
.ok_or(NotSupportedError::new("Only RGBA icons can be converted to `NSImage`"))?;

let width = rgba_icon.width();
let height = rgba_icon.height();

let bitmap = unsafe {
NSBitmapImageRep::initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(
NSBitmapImageRep::alloc(),
std::ptr::null_mut::<*mut c_uchar>(),
width as isize,
height as isize,
8,
4,
true,
false,
NSDeviceRGBColorSpace,
width as isize * 4,
32,
)
}.ok_or_else(|| os_error!("Initializing the `NSBitmapImageRep` failed"))?;

let bitmap_data =
unsafe { slice::from_raw_parts_mut(bitmap.bitmapData(), rgba_icon.buffer().len()) };
bitmap_data.copy_from_slice(rgba_icon.buffer());

let image = NSImage::initWithSize(NSImage::alloc(), NSSize::new(width.into(), height.into()));
image.addRepresentation(&bitmap);

Ok(image)
}

pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Result<Retained<NSCursor>, RequestError> {
let width = cursor.width();
let height = cursor.height();
Expand Down
Loading