Fix declare_class! indentation (#2461)

* Fix NSWindow delegate indentation

* Fix NSView delegate indentation
This commit is contained in:
Mads Marquart 2022-09-02 19:38:32 +02:00 committed by GitHub
parent d67c928120
commit e517e468f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1178 additions and 1176 deletions

View file

@ -289,7 +289,7 @@ fn mouse_motion(this: &Object, event: id) {
}
}
declare_class! {
declare_class!(
#[derive(Debug)]
#[allow(non_snake_case)]
struct WinitView {
@ -303,18 +303,18 @@ declare_class! {
}
unsafe impl WinitView {
#[sel(dealloc)]
fn dealloc(&mut self) {
#[sel(dealloc)]
fn dealloc(&mut self) {
unsafe {
let marked_text: id = *self.ivar("markedText");
let _: () = msg_send![marked_text, release];
let state: *mut c_void = *self.ivar("winitState");
drop(Box::from_raw(state as *mut ViewState));
}
}
}
#[sel(initWithWinit:)]
fn init_with_winit(&mut self, state: *mut c_void) -> Option<&mut Self> {
#[sel(initWithWinit:)]
fn init_with_winit(&mut self, state: *mut c_void) -> Option<&mut Self> {
let this: Option<&mut Self> = unsafe { msg_send![self, init] };
this.map(|this| unsafe {
(*this).set_ivar("winitState", state);
@ -340,12 +340,12 @@ fn init_with_winit(&mut self, state: *mut c_void) -> Option<&mut Self> {
winit_state.input_source = this.current_input_source();
this
})
}
}
}
unsafe impl WinitView {
#[sel(viewDidMoveToWindow)]
fn view_did_move_to_window(&self) {
#[sel(viewDidMoveToWindow)]
fn view_did_move_to_window(&self) {
trace_scope!("viewDidMoveToWindow");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -365,10 +365,10 @@ fn view_did_move_to_window(&self) {
];
state.tracking_rect = Some(tracking_rect);
}
}
}
#[sel(frameDidChange:)]
fn frame_did_change(&self, _event: id) {
#[sel(frameDidChange:)]
fn frame_did_change(&self, _event: id) {
trace_scope!("frameDidChange:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -391,17 +391,18 @@ fn frame_did_change(&self, _event: id) {
// Emit resize event here rather than from windowDidResize because:
// 1. When a new window is created as a tab, the frame size may change without a window resize occurring.
// 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height).
let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
let logical_size =
LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
let size = logical_size.to_physical::<u32>(state.get_scale_factor());
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: WindowId(get_window_id(state.ns_window)),
event: WindowEvent::Resized(size),
}));
}
}
}
#[sel(drawRect:)]
fn draw_rect(&self, rect: NSRect) {
#[sel(drawRect:)]
fn draw_rect(&self, rect: NSRect) {
trace_scope!("drawRect:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -411,25 +412,25 @@ fn draw_rect(&self, rect: NSRect) {
let _: () = msg_send![super(self), drawRect: rect];
}
}
}
#[sel(acceptsFirstResponder)]
fn accepts_first_responder(&self) -> bool {
#[sel(acceptsFirstResponder)]
fn accepts_first_responder(&self) -> bool {
trace_scope!("acceptsFirstResponder");
true
}
}
// This is necessary to prevent a beefy terminal error on MacBook Pros:
// IMKInputSession [0x7fc573576ff0 presentFunctionRowItemTextInputViewWithEndpoint:completionHandler:] : [self textInputContext]=0x7fc573558e10 *NO* NSRemoteViewController to client, NSError=Error Domain=NSCocoaErrorDomain Code=4099 "The connection from pid 0 was invalidated from this process." UserInfo={NSDebugDescription=The connection from pid 0 was invalidated from this process.}, com.apple.inputmethod.EmojiFunctionRowItem
// TODO: Add an API extension for using `NSTouchBar`
#[sel(touchBar)]
fn touch_bar(&self) -> bool {
// This is necessary to prevent a beefy terminal error on MacBook Pros:
// IMKInputSession [0x7fc573576ff0 presentFunctionRowItemTextInputViewWithEndpoint:completionHandler:] : [self textInputContext]=0x7fc573558e10 *NO* NSRemoteViewController to client, NSError=Error Domain=NSCocoaErrorDomain Code=4099 "The connection from pid 0 was invalidated from this process." UserInfo={NSDebugDescription=The connection from pid 0 was invalidated from this process.}, com.apple.inputmethod.EmojiFunctionRowItem
// TODO: Add an API extension for using `NSTouchBar`
#[sel(touchBar)]
fn touch_bar(&self) -> bool {
trace_scope!("touchBar");
false
}
}
#[sel(resetCursorRects)]
fn reset_cursor_rects(&self) {
#[sel(resetCursorRects)]
fn reset_cursor_rects(&self) {
trace_scope!("resetCursorRects");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -447,22 +448,21 @@ fn reset_cursor_rects(&self) {
cursor:cursor
];
}
}
}
}
unsafe impl Protocol<NSTextInputClient> for WinitView {
#[sel(hasMarkedText)]
fn has_marked_text(&self) -> bool {
#[sel(hasMarkedText)]
fn has_marked_text(&self) -> bool {
trace_scope!("hasMarkedText");
unsafe {
let marked_text: id = *self.ivar("markedText");
marked_text.length() > 0
}
}
}
#[sel(markedRange)]
fn marked_range(&self) -> NSRange {
#[sel(markedRange)]
fn marked_range(&self) -> NSRange {
trace_scope!("markedRange");
unsafe {
let marked_text: id = *self.ivar("markedText");
@ -473,21 +473,21 @@ fn marked_range(&self) -> NSRange {
util::EMPTY_RANGE
}
}
}
}
#[sel(selectedRange)]
fn selected_range(&self) -> NSRange {
#[sel(selectedRange)]
fn selected_range(&self) -> NSRange {
trace_scope!("selectedRange");
util::EMPTY_RANGE
}
}
#[sel(setMarkedText:selectedRange:replacementRange:)]
fn set_marked_text(
#[sel(setMarkedText:selectedRange:replacementRange:)]
fn set_marked_text(
&mut self,
string: id,
_selected_range: NSRange,
_replacement_range: NSRange,
) {
) {
trace_scope!("setMarkedText:selectedRange:replacementRange:");
unsafe {
// Get pre-edit text
@ -538,10 +538,10 @@ fn set_marked_text(
event: WindowEvent::Ime(Ime::Preedit(preedit_string, cursor_range)),
}));
}
}
}
#[sel(unmarkText)]
fn unmark_text(&self) {
#[sel(unmarkText)]
fn unmark_text(&self) {
trace_scope!("unmarkText");
unsafe {
let marked_text: id = *self.ivar("markedText");
@ -565,42 +565,44 @@ fn unmark_text(&self) {
warn!("Expected to have IME enabled when receiving unmarkText");
}
}
}
}
#[sel(validAttributesForMarkedText)]
fn valid_attributes_for_marked_text(&self) -> id {
#[sel(validAttributesForMarkedText)]
fn valid_attributes_for_marked_text(&self) -> id {
trace_scope!("validAttributesForMarkedText");
unsafe { msg_send![class!(NSArray), array] }
}
}
#[sel(attributedSubstringForProposedRange:actualRange:)]
fn attributed_substring_for_proposed_range(
#[sel(attributedSubstringForProposedRange:actualRange:)]
fn attributed_substring_for_proposed_range(
&self,
_range: NSRange,
_actual_range: *mut c_void, // *mut NSRange
) -> id {
) -> id {
trace_scope!("attributedSubstringForProposedRange:actualRange:");
nil
}
}
#[sel(characterIndexForPoint:)]
fn character_index_for_point(&self, _point: NSPoint) -> NSUInteger {
#[sel(characterIndexForPoint:)]
fn character_index_for_point(&self, _point: NSPoint) -> NSUInteger {
trace_scope!("characterIndexForPoint:");
0
}
}
#[sel(firstRectForCharacterRange:actualRange:)]
fn first_rect_for_character_range(
#[sel(firstRectForCharacterRange:actualRange:)]
fn first_rect_for_character_range(
&self,
_range: NSRange,
_actual_range: *mut c_void, // *mut NSRange
) -> NSRect {
) -> NSRect {
trace_scope!("firstRectForCharacterRange:actualRange:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
let state = &mut *(state_ptr as *mut ViewState);
let content_rect =
NSWindow::contentRectForFrameRect_(state.ns_window, NSWindow::frame(state.ns_window));
let content_rect = NSWindow::contentRectForFrameRect_(
state.ns_window,
NSWindow::frame(state.ns_window),
);
let base_x = content_rect.origin.x as f64;
let base_y = (content_rect.origin.y + content_rect.size.height) as f64;
let x = base_x + state.ime_position.x;
@ -611,10 +613,10 @@ fn first_rect_for_character_range(
// no way to express this. Same goes for the `NSSize`.
NSRect::new(NSPoint::new(x as _, y as _), NSSize::new(0.0, 0.0))
}
}
}
#[sel(insertText:replacementRange:)]
fn insert_text(&self, string: id, _replacement_range: NSRange) {
#[sel(insertText:replacementRange:)]
fn insert_text(&self, string: id, _replacement_range: NSRange) {
trace_scope!("insertText:replacementRange:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -635,10 +637,10 @@ fn insert_text(&self, string: id, _replacement_range: NSRange) {
state.ime_state = ImeState::Commited;
}
}
}
}
#[sel(doCommandBySelector:)]
fn do_command_by_selector(&self, _command: Sel) {
#[sel(doCommandBySelector:)]
fn do_command_by_selector(&self, _command: Sel) {
trace_scope!("doCommandBySelector:");
// Basically, we're sent this message whenever a keyboard event that doesn't generate a "human
// readable" character happens, i.e. newlines, tabs, and Ctrl+C.
@ -661,13 +663,12 @@ fn do_command_by_selector(&self, _command: Sel) {
state.ime_state = ImeState::Enabled;
}
}
}
}
}
unsafe impl WinitView {
#[sel(keyDown:)]
fn key_down(&self, event: id) {
#[sel(keyDown:)]
fn key_down(&self, event: id) {
trace_scope!("keyDown:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -748,10 +749,10 @@ fn key_down(&self, event: id) {
}
}
}
}
}
#[sel(keyUp:)]
fn key_up(&self, event: id) {
#[sel(keyUp:)]
fn key_up(&self, event: id) {
trace_scope!("keyUp:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -782,10 +783,10 @@ fn key_up(&self, event: id) {
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
}
#[sel(flagsChanged:)]
fn flags_changed(&self, event: id) {
#[sel(flagsChanged:)]
fn flags_changed(&self, event: id) {
trace_scope!("flagsChanged:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -843,10 +844,10 @@ fn flags_changed(&self, event: id) {
event: WindowEvent::ModifiersChanged(state.modifiers),
}));
}
}
}
#[sel(insertTab:)]
fn insert_tab(&self, _sender: id) {
#[sel(insertTab:)]
fn insert_tab(&self, _sender: id) {
trace_scope!("insertTab:");
unsafe {
let window: id = msg_send![self, window];
@ -856,10 +857,10 @@ fn insert_tab(&self, _sender: id) {
let _: () = msg_send![window, selectNextKeyView: self];
}
}
}
}
#[sel(insertBackTab:)]
fn insert_back_tab(&self, _sender: id) {
#[sel(insertBackTab:)]
fn insert_back_tab(&self, _sender: id) {
trace_scope!("insertBackTab:");
unsafe {
let window: id = msg_send![self, window];
@ -869,12 +870,12 @@ fn insert_back_tab(&self, _sender: id) {
let _: () = msg_send![window, selectPreviousKeyView: self];
}
}
}
}
// Allows us to receive Cmd-. (the shortcut for closing a dialog)
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=300620#c6
#[sel(cancelOperation:)]
fn cancel_operation(&self, _sender: id) {
// Allows us to receive Cmd-. (the shortcut for closing a dialog)
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=300620#c6
#[sel(cancelOperation:)]
fn cancel_operation(&self, _sender: id) {
trace_scope!("cancelOperation:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -905,74 +906,74 @@ fn cancel_operation(&self, _sender: id) {
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
#[sel(mouseDown:)]
fn mouse_down(&self, event: id) {
#[sel(mouseDown:)]
fn mouse_down(&self, event: id) {
trace_scope!("mouseDown:");
mouse_motion(self, event);
mouse_click(self, event, MouseButton::Left, ElementState::Pressed);
}
}
#[sel(mouseUp:)]
fn mouse_up(&self, event: id) {
#[sel(mouseUp:)]
fn mouse_up(&self, event: id) {
trace_scope!("mouseUp:");
mouse_motion(self, event);
mouse_click(self, event, MouseButton::Left, ElementState::Released);
}
}
#[sel(rightMouseDown:)]
fn right_mouse_down(&self, event: id) {
#[sel(rightMouseDown:)]
fn right_mouse_down(&self, event: id) {
trace_scope!("rightMouseDown:");
mouse_motion(self, event);
mouse_click(self, event, MouseButton::Right, ElementState::Pressed);
}
}
#[sel(rightMouseUp:)]
fn right_mouse_up(&self, event: id) {
#[sel(rightMouseUp:)]
fn right_mouse_up(&self, event: id) {
trace_scope!("rightMouseUp:");
mouse_motion(self, event);
mouse_click(self, event, MouseButton::Right, ElementState::Released);
}
}
#[sel(otherMouseDown:)]
fn other_mouse_down(&self, event: id) {
#[sel(otherMouseDown:)]
fn other_mouse_down(&self, event: id) {
trace_scope!("otherMouseDown:");
mouse_motion(self, event);
mouse_click(self, event, MouseButton::Middle, ElementState::Pressed);
}
}
#[sel(otherMouseUp:)]
fn other_mouse_up(&self, event: id) {
#[sel(otherMouseUp:)]
fn other_mouse_up(&self, event: id) {
trace_scope!("otherMouseUp:");
mouse_motion(self, event);
mouse_click(self, event, MouseButton::Middle, ElementState::Released);
}
}
// No tracing on these because that would be overly verbose
// No tracing on these because that would be overly verbose
#[sel(mouseMoved:)]
fn mouse_moved(&self, event: id) {
#[sel(mouseMoved:)]
fn mouse_moved(&self, event: id) {
mouse_motion(self, event);
}
}
#[sel(mouseDragged:)]
fn mouse_dragged(&self, event: id) {
#[sel(mouseDragged:)]
fn mouse_dragged(&self, event: id) {
mouse_motion(self, event);
}
}
#[sel(rightMouseDragged:)]
fn right_mouse_dragged(&self, event: id) {
#[sel(rightMouseDragged:)]
fn right_mouse_dragged(&self, event: id) {
mouse_motion(self, event);
}
}
#[sel(otherMouseDragged:)]
fn other_mouse_dragged(&self, event: id) {
#[sel(otherMouseDragged:)]
fn other_mouse_dragged(&self, event: id) {
mouse_motion(self, event);
}
}
#[sel(mouseEntered:)]
fn mouse_entered(&self, _event: id) {
#[sel(mouseEntered:)]
fn mouse_entered(&self, _event: id) {
trace_scope!("mouseEntered:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -987,10 +988,10 @@ fn mouse_entered(&self, _event: id) {
AppState::queue_event(EventWrapper::StaticEvent(enter_event));
}
}
}
#[sel(mouseExited:)]
fn mouse_exited(&self, _event: id) {
#[sel(mouseExited:)]
fn mouse_exited(&self, _event: id) {
trace_scope!("mouseExited:");
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
@ -1005,10 +1006,10 @@ fn mouse_exited(&self, _event: id) {
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
#[sel(scrollWheel:)]
fn scroll_wheel(&self, event: id) {
#[sel(scrollWheel:)]
fn scroll_wheel(&self, event: id) {
trace_scope!("scrollWheel:");
mouse_motion(self, event);
@ -1020,7 +1021,8 @@ fn scroll_wheel(&self, event: id) {
let delta = {
let (x, y) = (event.scrollingDeltaX(), event.scrollingDeltaY());
if Bool::from_raw(event.hasPreciseScrollingDeltas()).as_bool() {
let delta = LogicalPosition::new(x, y).to_physical(state.get_scale_factor());
let delta =
LogicalPosition::new(x, y).to_physical(state.get_scale_factor());
MouseScrollDelta::PixelDelta(delta)
} else {
MouseScrollDelta::LineDelta(x as f32, y as f32)
@ -1031,7 +1033,8 @@ fn scroll_wheel(&self, event: id) {
// be mutually exclusive anyhow, which is why the API is rather incoherent). If no momentum
// phase is recorded (or rather, the started/ended cases of the momentum phase) then we
// report the touch phase.
let phase = match event.momentumPhase() {
let phase =
match event.momentumPhase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
TouchPhase::Started
}
@ -1039,12 +1042,10 @@ fn scroll_wheel(&self, event: id) {
TouchPhase::Ended
}
_ => match event.phase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
TouchPhase::Started
}
NSEventPhase::NSEventPhaseEnded | NSEventPhase::NSEventPhaseCancelled => {
TouchPhase::Ended
}
NSEventPhase::NSEventPhaseMayBegin
| NSEventPhase::NSEventPhaseBegan => TouchPhase::Started,
NSEventPhase::NSEventPhaseEnded
| NSEventPhase::NSEventPhaseCancelled => TouchPhase::Ended,
_ => TouchPhase::Moved,
},
};
@ -1072,10 +1073,10 @@ fn scroll_wheel(&self, event: id) {
AppState::queue_event(EventWrapper::StaticEvent(device_event));
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
#[sel(magnifyWithEvent:)]
fn magnify_with_event(&self, event: id) {
#[sel(magnifyWithEvent:)]
fn magnify_with_event(&self, event: id) {
trace_scope!("magnifyWithEvent:");
unsafe {
@ -1102,10 +1103,10 @@ fn magnify_with_event(&self, event: id) {
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
#[sel(rotateWithEvent:)]
fn rotate_with_event(&self, event: id) {
#[sel(rotateWithEvent:)]
fn rotate_with_event(&self, event: id) {
trace_scope!("rotateWithEvent:");
unsafe {
@ -1132,10 +1133,10 @@ fn rotate_with_event(&self, event: id) {
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
#[sel(pressureChangeWithEvent:)]
fn pressure_change_with_event(&self, event: id) {
#[sel(pressureChangeWithEvent:)]
fn pressure_change_with_event(&self, event: id) {
trace_scope!("pressureChangeWithEvent:");
mouse_motion(self, event);
@ -1158,24 +1159,24 @@ fn pressure_change_with_event(&self, event: id) {
AppState::queue_event(EventWrapper::StaticEvent(window_event));
}
}
}
// Allows us to receive Ctrl-Tab and Ctrl-Esc.
// Note that this *doesn't* help with any missing Cmd inputs.
// https://github.com/chromium/chromium/blob/a86a8a6bcfa438fa3ac2eba6f02b3ad1f8e0756f/ui/views/cocoa/bridged_content_view.mm#L816
#[sel(_wantsKeyDownForEvent:)]
fn wants_key_down_for_event(&self, _event: id) -> bool {
// Allows us to receive Ctrl-Tab and Ctrl-Esc.
// Note that this *doesn't* help with any missing Cmd inputs.
// https://github.com/chromium/chromium/blob/a86a8a6bcfa438fa3ac2eba6f02b3ad1f8e0756f/ui/views/cocoa/bridged_content_view.mm#L816
#[sel(_wantsKeyDownForEvent:)]
fn wants_key_down_for_event(&self, _event: id) -> bool {
trace_scope!("_wantsKeyDownForEvent:");
true
}
}
#[sel(acceptsFirstMouse:)]
fn accepts_first_mouse(&self, _event: id) -> bool {
#[sel(acceptsFirstMouse:)]
fn accepts_first_mouse(&self, _event: id) -> bool {
trace_scope!("acceptsFirstMouse:");
true
}
}
}
}
);
impl WinitView {
fn current_input_source(&self) -> String {

View file

@ -128,7 +128,7 @@ pub fn new_delegate(window: &Arc<UnownedWindow>, initial_fullscreen: bool) -> Id
}
}
declare_class! {
declare_class!(
#[derive(Debug)]
struct WinitWindowDelegate {
state: *mut c_void,
@ -139,15 +139,15 @@ declare_class! {
}
unsafe impl WinitWindowDelegate {
#[sel(dealloc)]
fn dealloc(&mut self) {
#[sel(dealloc)]
fn dealloc(&mut self) {
self.with_state(|state| unsafe {
drop(Box::from_raw(state as *mut WindowDelegateState));
});
}
}
#[sel(initWithWinit:)]
fn init_with_winit(&mut self, state: *mut c_void) -> Option<&mut Self> {
#[sel(initWithWinit:)]
fn init_with_winit(&mut self, state: *mut c_void) -> Option<&mut Self> {
let this: Option<&mut Self> = unsafe { msg_send![self, init] };
this.map(|this| {
*this.state = state;
@ -156,20 +156,20 @@ fn init_with_winit(&mut self, state: *mut c_void) -> Option<&mut Self> {
});
this
})
}
}
}
// NSWindowDelegate + NSDraggingDestination protocols
unsafe impl WinitWindowDelegate {
#[sel(windowShouldClose:)]
fn window_should_close(&self, _: id) -> bool {
#[sel(windowShouldClose:)]
fn window_should_close(&self, _: id) -> bool {
trace_scope!("windowShouldClose:");
self.with_state(|state| state.emit_event(WindowEvent::CloseRequested));
false
}
}
#[sel(windowWillClose:)]
fn window_will_close(&self, _: id) {
#[sel(windowWillClose:)]
fn window_will_close(&self, _: id) {
trace_scope!("windowWillClose:");
self.with_state(|state| unsafe {
// `setDelegate:` retains the previous value and then autoreleases it
@ -180,46 +180,46 @@ fn window_will_close(&self, _: id) {
});
state.emit_event(WindowEvent::Destroyed);
});
}
}
#[sel(windowDidResize:)]
fn window_did_resize(&self, _: id) {
#[sel(windowDidResize:)]
fn window_did_resize(&self, _: id) {
trace_scope!("windowDidResize:");
self.with_state(|state| {
// NOTE: WindowEvent::Resized is reported in frameDidChange.
state.emit_move_event();
});
}
}
// This won't be triggered if the move was part of a resize.
#[sel(windowDidMove:)]
fn window_did_move(&self, _: id) {
// This won't be triggered if the move was part of a resize.
#[sel(windowDidMove:)]
fn window_did_move(&self, _: id) {
trace_scope!("windowDidMove:");
self.with_state(|state| {
state.emit_move_event();
});
}
}
#[sel(windowDidChangeBackingProperties:)]
fn window_did_change_backing_properties(&self, _: id) {
#[sel(windowDidChangeBackingProperties:)]
fn window_did_change_backing_properties(&self, _: id) {
trace_scope!("windowDidChangeBackingProperties:");
self.with_state(|state| {
state.emit_static_scale_factor_changed_event();
});
}
}
#[sel(windowDidBecomeKey:)]
fn window_did_become_key(&self, _: id) {
#[sel(windowDidBecomeKey:)]
fn window_did_become_key(&self, _: id) {
trace_scope!("windowDidBecomeKey:");
self.with_state(|state| {
// TODO: center the cursor if the window had mouse grab when it
// lost focus
state.emit_event(WindowEvent::Focused(true));
});
}
}
#[sel(windowDidResignKey:)]
fn window_did_resign_key(&self, _: id) {
#[sel(windowDidResignKey:)]
fn window_did_resign_key(&self, _: id) {
trace_scope!("windowDidResignKey:");
self.with_state(|state| {
// It happens rather often, e.g. when the user is Cmd+Tabbing, that the
@ -247,18 +247,19 @@ fn window_did_resign_key(&self, _: id) {
state.emit_event(WindowEvent::Focused(false));
});
}
}
/// Invoked when the dragged image enters destination bounds or frame
#[sel(draggingEntered:)]
fn dragging_entered(&self, sender: id) -> bool {
/// Invoked when the dragged image enters destination bounds or frame
#[sel(draggingEntered:)]
fn dragging_entered(&self, sender: id) -> bool {
trace_scope!("draggingEntered:");
use cocoa::{appkit::NSPasteboard, foundation::NSFastEnumeration};
use std::path::PathBuf;
let pb: id = unsafe { msg_send![sender, draggingPasteboard] };
let filenames = unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
let filenames =
unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
for file in unsafe { filenames.iter() } {
use cocoa::foundation::NSString;
@ -275,25 +276,26 @@ fn dragging_entered(&self, sender: id) -> bool {
}
true
}
}
/// Invoked when the image is released
#[sel(prepareForDragOperation:)]
fn prepare_for_drag_operation(&self, _: id) -> bool {
/// Invoked when the image is released
#[sel(prepareForDragOperation:)]
fn prepare_for_drag_operation(&self, _: id) -> bool {
trace_scope!("prepareForDragOperation:");
true
}
}
/// Invoked after the released image has been removed from the screen
#[sel(performDragOperation:)]
fn perform_drag_operation(&self, sender: id) -> bool {
/// Invoked after the released image has been removed from the screen
#[sel(performDragOperation:)]
fn perform_drag_operation(&self, sender: id) -> bool {
trace_scope!("performDragOperation:");
use cocoa::{appkit::NSPasteboard, foundation::NSFastEnumeration};
use std::path::PathBuf;
let pb: id = unsafe { msg_send![sender, draggingPasteboard] };
let filenames = unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
let filenames =
unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
for file in unsafe { filenames.iter() } {
use cocoa::foundation::NSString;
@ -310,26 +312,24 @@ fn perform_drag_operation(&self, sender: id) -> bool {
}
true
}
}
/// Invoked when the dragging operation is complete
#[sel(concludeDragOperation:)]
fn conclude_drag_operation(&self, _: id) {
/// Invoked when the dragging operation is complete
#[sel(concludeDragOperation:)]
fn conclude_drag_operation(&self, _: id) {
trace_scope!("concludeDragOperation:");
}
}
/// Invoked when the dragging operation is cancelled
#[sel(draggingExited:)]
fn dragging_exited(&self, _: id) {
/// Invoked when the dragging operation is cancelled
#[sel(draggingExited:)]
fn dragging_exited(&self, _: id) {
trace_scope!("draggingExited:");
self.with_state(|state| {
state.emit_event(WindowEvent::HoveredFileCancelled)
});
}
self.with_state(|state| state.emit_event(WindowEvent::HoveredFileCancelled));
}
/// Invoked when before enter fullscreen
#[sel(windowWillEnterFullscreen:)]
fn window_will_enter_fullscreen(&self, _: id) {
/// Invoked when before enter fullscreen
#[sel(windowWillEnterFullscreen:)]
fn window_will_enter_fullscreen(&self, _: id) {
trace_scope!("windowWillEnterFullscreen:");
self.with_state(|state| {
@ -356,11 +356,11 @@ fn window_will_enter_fullscreen(&self, _: id) {
shared_state.in_fullscreen_transition = true;
})
});
}
}
/// Invoked when before exit fullscreen
#[sel(windowWillExitFullScreen:)]
fn window_will_exit_fullscreen(&self, _: id) {
/// Invoked when before exit fullscreen
#[sel(windowWillExitFullScreen:)]
fn window_will_exit_fullscreen(&self, _: id) {
trace_scope!("windowWillExitFullScreen:");
self.with_state(|state| {
@ -369,14 +369,14 @@ fn window_will_exit_fullscreen(&self, _: id) {
shared_state.in_fullscreen_transition = true;
});
});
}
}
#[sel(window:willUseFullScreenPresentationOptions:)]
fn window_will_use_fullscreen_presentation_options(
#[sel(window:willUseFullScreenPresentationOptions:)]
fn window_will_use_fullscreen_presentation_options(
&self,
_: id,
proposed_options: NSUInteger,
) -> NSUInteger {
) -> NSUInteger {
trace_scope!("window:willUseFullScreenPresentationOptions:");
// Generally, games will want to disable the menu bar and the dock. Ideally,
// this would be configurable by the user. Unfortunately because of our
@ -401,11 +401,11 @@ fn window_will_use_fullscreen_presentation_options(
});
options
}
}
/// Invoked when entered fullscreen
#[sel(windowDidEnterFullscreen:)]
fn window_did_enter_fullscreen(&self, _: id) {
/// Invoked when entered fullscreen
#[sel(windowDidEnterFullscreen:)]
fn window_did_enter_fullscreen(&self, _: id) {
trace_scope!("windowDidEnterFullscreen:");
self.with_state(|state| {
state.initial_fullscreen = false;
@ -419,11 +419,11 @@ fn window_did_enter_fullscreen(&self, _: id) {
}
});
});
}
}
/// Invoked when exited fullscreen
#[sel(windowDidExitFullscreen:)]
fn window_did_exit_fullscreen(&self, _: id) {
/// Invoked when exited fullscreen
#[sel(windowDidExitFullscreen:)]
fn window_did_exit_fullscreen(&self, _: id) {
trace_scope!("windowDidExitFullscreen:");
self.with_state(|state| {
@ -438,30 +438,31 @@ fn window_did_exit_fullscreen(&self, _: id) {
}
})
});
}
}
/// Invoked when fail to enter fullscreen
///
/// When this window launch from a fullscreen app (e.g. launch from VS Code
/// terminal), it creates a new virtual destkop and a transition animation.
/// This animation takes one second and cannot be disable without
/// elevated privileges. In this animation time, all toggleFullscreen events
/// will be failed. In this implementation, we will try again by using
/// performSelector:withObject:afterDelay: until window_did_enter_fullscreen.
/// It should be fine as we only do this at initialzation (i.e with_fullscreen
/// was set).
///
/// From Apple doc:
/// In some cases, the transition to enter full-screen mode can fail,
/// due to being in the midst of handling some other animation or user gesture.
/// This method indicates that there was an error, and you should clean up any
/// work you may have done to prepare to enter full-screen mode.
#[sel(windowDidFailToEnterFullscreen:)]
fn window_did_fail_to_enter_fullscreen(&self, _: id) {
/// Invoked when fail to enter fullscreen
///
/// When this window launch from a fullscreen app (e.g. launch from VS Code
/// terminal), it creates a new virtual destkop and a transition animation.
/// This animation takes one second and cannot be disable without
/// elevated privileges. In this animation time, all toggleFullscreen events
/// will be failed. In this implementation, we will try again by using
/// performSelector:withObject:afterDelay: until window_did_enter_fullscreen.
/// It should be fine as we only do this at initialzation (i.e with_fullscreen
/// was set).
///
/// From Apple doc:
/// In some cases, the transition to enter full-screen mode can fail,
/// due to being in the midst of handling some other animation or user gesture.
/// This method indicates that there was an error, and you should clean up any
/// work you may have done to prepare to enter full-screen mode.
#[sel(windowDidFailToEnterFullscreen:)]
fn window_did_fail_to_enter_fullscreen(&self, _: id) {
trace_scope!("windowDidFailToEnterFullscreen:");
self.with_state(|state| {
state.with_window(|window| {
let mut shared_state = window.lock_shared_state("window_did_fail_to_enter_fullscreen");
let mut shared_state =
window.lock_shared_state("window_did_fail_to_enter_fullscreen");
shared_state.in_fullscreen_transition = false;
shared_state.target_fullscreen = None;
});
@ -477,11 +478,11 @@ fn window_did_fail_to_enter_fullscreen(&self, _: id) {
state.with_window(|window| window.restore_state_from_fullscreen());
}
});
}
}
// Invoked when the occlusion state of the window changes
#[sel(windowDidChangeOcclusionState:)]
fn window_did_change_occlusion_state(&self, _: id) {
// Invoked when the occlusion state of the window changes
#[sel(windowDidChangeOcclusionState:)]
fn window_did_change_occlusion_state(&self, _: id) {
trace_scope!("windowDidChangeOcclusionState:");
unsafe {
self.with_state(|state| {
@ -493,9 +494,9 @@ fn window_did_change_occlusion_state(&self, _: id) {
))
});
}
}
}
}
}
);
impl WinitWindowDelegate {
// This function is definitely unsafe (&self -> &mut state), but labeling that