-
-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Introduce OS.set_drag_mode()
#23972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Introduce OS.set_drag_mode()
#23972
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -556,6 +556,10 @@ - (BOOL)canBecomeKeyView { | |
| return YES; | ||
| } | ||
|
|
||
| - (BOOL)mouseDownCanMoveWindow { | ||
| return YES; | ||
| } | ||
|
|
||
| - (BOOL)acceptsFirstResponder { | ||
| return YES; | ||
| } | ||
|
|
@@ -591,18 +595,75 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) { | |
| - (void)mouseDown:(NSEvent *)event { | ||
| if (([event modifierFlags] & NSEventModifierFlagControl)) { | ||
| mouse_down_control = true; | ||
|
|
||
| _mouseDownEvent(event, BUTTON_RIGHT, BUTTON_MASK_RIGHT, true); | ||
| } else { | ||
| mouse_down_control = false; | ||
| _mouseDownEvent(event, BUTTON_LEFT, BUTTON_MASK_LEFT, true); | ||
| if (OS_OSX::singleton->drag_mode != OS::DRAG_MODE_MOVE) { | ||
| _mouseDownEvent(event, BUTTON_LEFT, BUTTON_MASK_LEFT, true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (void)mouseDragged:(NSEvent *)event { | ||
| [self mouseMoved:event]; | ||
| // Prevent from being both movable and recieving drag events. | ||
| if ([[event window] isMovableByWindowBackground]) { | ||
| return; | ||
| } | ||
|
|
||
| NSRect frame = [[event window] frame]; | ||
| switch (OS_OSX::singleton->drag_mode) { | ||
| case OS::DRAG_MODE_RESIZE_TOP: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - event.deltaY) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_BOTTOM: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x, frame.origin.y - event.deltaY, frame.size.width, frame.size.height + event.deltaY) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_LEFT: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x + event.deltaX, frame.origin.y, frame.size.width - event.deltaX, frame.size.height) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_RIGHT: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x, frame.origin.y, frame.size.width + event.deltaX, frame.size.height) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_TOPLEFT: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x + event.deltaX, frame.origin.y, frame.size.width - event.deltaX, frame.size.height - event.deltaY) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_BOTTOMLEFT: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x + event.deltaX, frame.origin.y - event.deltaY, frame.size.width - event.deltaX, frame.size.height + event.deltaY) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_TOPRIGHT: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x, frame.origin.y, frame.size.width + event.deltaX, frame.size.height - event.deltaY) | ||
| display:YES]; | ||
| break; | ||
| case OS::DRAG_MODE_RESIZE_BOTTOMRIGHT: | ||
| [[event window] setFrame:NSMakeRect( | ||
| frame.origin.x, frame.origin.y - event.deltaY, frame.size.width + event.deltaX, frame.size.height + event.deltaY) | ||
| display:YES]; | ||
| break; | ||
| default: | ||
| [self mouseMoved:event]; | ||
| } | ||
| } | ||
|
|
||
| - (void)mouseUp:(NSEvent *)event { | ||
| if (OS_OSX::singleton->drag_mode == OS::DRAG_MODE_MOVE && [event clickCount] == 2) { | ||
| OS_OSX::singleton->set_window_maximized(!OS_OSX::singleton->is_window_maximized()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On macOS double-clicking window title should minimize window not maximize, and there's nothing like this implemented on other platforms. |
||
| return; | ||
| } | ||
|
|
||
| if (mouse_down_control) { | ||
| _mouseDownEvent(event, BUTTON_RIGHT, BUTTON_MASK_RIGHT, false); | ||
| } else { | ||
|
|
@@ -623,8 +684,8 @@ - (void)mouseMoved:(NSEvent *)event { | |
| mm->set_position(pos); | ||
| mm->set_global_position(pos); | ||
| Vector2 relativeMotion = Vector2(); | ||
| relativeMotion.x = [event deltaX] * OS_OSX::singleton -> _mouse_scale(backingScaleFactor); | ||
| relativeMotion.y = [event deltaY] * OS_OSX::singleton -> _mouse_scale(backingScaleFactor); | ||
| relativeMotion.x = [event deltaX] * OS_OSX::singleton->_mouse_scale(backingScaleFactor); | ||
| relativeMotion.y = [event deltaY] * OS_OSX::singleton->_mouse_scale(backingScaleFactor); | ||
| mm->set_relative(relativeMotion); | ||
| get_key_modifier_state([event modifierFlags], mm); | ||
|
|
||
|
|
@@ -1134,6 +1195,10 @@ - (BOOL)canBecomeKeyWindow { | |
| return YES; | ||
| } | ||
|
|
||
| - (BOOL)mouseDownCanMoveWindow { | ||
| return YES; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| void OS_OSX::set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) { | ||
|
|
@@ -1273,6 +1338,9 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay | |
| [window_object center]; | ||
|
|
||
| [window_object setRestorable:NO]; | ||
| if (p_desired.borderless_window) { | ||
| [window_object setHasShadow:YES]; | ||
| } | ||
|
|
||
| unsigned int attributeCount = 0; | ||
|
|
||
|
|
@@ -2321,6 +2389,7 @@ static int get_screen_index(NSScreen *screen) { | |
|
|
||
| if (p_borderless) { | ||
| [window_object setStyleMask:NSWindowStyleMaskBorderless]; | ||
| [window_object setHasShadow:YES]; | ||
| } else { | ||
| if (layered_window) | ||
| set_window_per_pixel_transparency_enabled(false); | ||
|
|
@@ -2580,6 +2649,20 @@ static int get_screen_index(NSScreen *screen) { | |
| return mouse_mode; | ||
| } | ||
|
|
||
| void OS_OSX::set_drag_mode(DragMode p_drag_mode) { | ||
| if (p_drag_mode == DRAG_MODE_MOVE) { | ||
| [window_object setMovableByWindowBackground:YES]; | ||
| } else { | ||
| [window_object setMovableByWindowBackground:NO]; | ||
| } | ||
|
|
||
| drag_mode = p_drag_mode; | ||
| } | ||
|
|
||
| OS::DragMode OS_OSX::get_drag_mode() const { | ||
| return drag_mode; | ||
| } | ||
|
|
||
| String OS_OSX::get_joy_guid(int p_device) const { | ||
| return input->get_joy_guid_remapped(p_device); | ||
| } | ||
|
|
@@ -2633,6 +2716,7 @@ static int get_screen_index(NSScreen *screen) { | |
| memset(cursors, 0, sizeof(cursors)); | ||
| key_event_pos = 0; | ||
| mouse_mode = OS::MOUSE_MODE_VISIBLE; | ||
| drag_mode = OS::DRAG_MODE_NONE; | ||
| main_loop = NULL; | ||
| singleton = this; | ||
| im_active = false; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OS_OSX::process_drag_mode()is defined but not implemented (probably copy-paste from X11)X11andWindowsplatforms don't set defaultdrag_modevalue (DRAG_MODE_NONE).