Make window unmovable by dragging title bar, when mouse in captured or confined mode.

This commit is contained in:
bruvzg 2021-11-11 14:02:08 +02:00
parent 171a69757f
commit f6e449a194
1 changed files with 6 additions and 1 deletions

View File

@ -1920,6 +1920,7 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) {
return;
}
WindowData &wd = windows[MAIN_WINDOW_ID];
if (p_mode == MOUSE_MODE_CAPTURED) {
// Apple Docs state that the display parameter is not used.
// "This parameter is not used. By default, you may pass kCGDirectMainDisplay."
@ -1928,7 +1929,7 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
CGAssociateMouseAndMouseCursorPosition(false);
WindowData &wd = windows[MAIN_WINDOW_ID];
[wd.window_object setMovable:NO];
const NSRect contentRect = [wd.window_view frame];
NSRect pointInWindowRect = NSMakeRect(contentRect.size.width / 2, contentRect.size.height / 2, 0, 0);
NSPoint pointOnScreen = [[wd.window_view window] convertRectToScreen:pointInWindowRect].origin;
@ -1938,17 +1939,21 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
[wd.window_object setMovable:YES];
CGAssociateMouseAndMouseCursorPosition(true);
} else if (p_mode == MOUSE_MODE_CONFINED) {
CGDisplayShowCursor(kCGDirectMainDisplay);
[wd.window_object setMovable:NO];
CGAssociateMouseAndMouseCursorPosition(false);
} else if (p_mode == MOUSE_MODE_CONFINED_HIDDEN) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
[wd.window_object setMovable:NO];
CGAssociateMouseAndMouseCursorPosition(false);
} else { // MOUSE_MODE_VISIBLE
CGDisplayShowCursor(kCGDirectMainDisplay);
[wd.window_object setMovable:YES];
CGAssociateMouseAndMouseCursorPosition(true);
}