Skip to content

Commit ed88da3

Browse files
committed
Add display/window/screen_id configuration
1 parent 9587861 commit ed88da3

11 files changed

Lines changed: 60 additions & 39 deletions

File tree

core/os/os.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,17 @@ void OS::close_midi_inputs() {
704704
MIDIDriver::get_singleton()->close();
705705
}
706706

707+
int OS::_get_initial_screen_id() {
708+
int screen_id = GLOBAL_DEF("display/window/screen_id", -1);
709+
if (screen_id == -1) {
710+
screen_id = get_current_screen();
711+
} else if (screen_id >= get_screen_count()) {
712+
screen_id = 0;
713+
}
714+
715+
return screen_id;
716+
}
717+
707718
OS::OS() {
708719
void *volatile stack_bottom;
709720

core/os/os.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class OS {
146146
void _ensure_user_data_dir();
147147
virtual bool _check_internal_feature_support(const String &p_feature) = 0;
148148

149+
int _get_initial_screen_id();
150+
149151
public:
150152
typedef int64_t ProcessID;
151153

doc/classes/ProjectSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@
329329
</member>
330330
<member name="display/window/per_pixel_transparency_splash" type="bool" setter="" getter="">
331331
</member>
332+
<member name="display/window/screen_id" type="int" setter="" getter="">
333+
Set the screen number, defaults to -1. If configured, use the 'No Management' option on 'run/window_placement/rect', otherwise the editor overrides this value.
334+
</member>
332335
<member name="display/window/size/always_on_top" type="bool" setter="" getter="">
333336
Force the window to be always on top.
334337
</member>

editor/editor_run.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li
148148
args.push_back(itos(pos.x) + "," + itos(pos.y));
149149
args.push_back("--fullscreen");
150150
} break;
151+
case 5: { // no management
152+
153+
} break;
151154
}
152155

153156
if (p_breakpoints.size()) {

editor/editor_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
497497
_initial_set("editors/poly_editor/show_previous_outline", true);
498498

499499
_initial_set("run/window_placement/rect", 1);
500-
hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen");
500+
hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen,No Management");
501501
String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
502502
for (int i = 0; i < OS::get_singleton()->get_screen_count(); i++) {
503503
screen_hints += ",Monitor " + itos(i + 1);

main/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
892892
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_width", PropertyInfo(Variant::INT, "display/window/size/test_width", PROPERTY_HINT_RANGE, "0,7680,or_greater")); // 8K resolution
893893
GLOBAL_DEF("display/window/size/test_height", 0);
894894
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution
895+
GLOBAL_DEF("display/window/screen_id", -1);
895896

896897
if (use_custom_res) {
897898

platform/osx/os_osx.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,11 +1235,16 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay
12351235
styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | (p_desired.resizable ? NSWindowStyleMaskResizable : 0);
12361236
}
12371237

1238+
int screen_id = _get_initial_screen_id();
1239+
Size2 screen_size = get_screen_size(screen_id);
1240+
NSScreen *screen = [[NSScreen screens] objectAtIndex:screen_id];
1241+
12381242
window_object = [[GodotWindow alloc]
1239-
initWithContentRect:NSMakeRect(0, 0, p_desired.width, p_desired.height)
1243+
initWithContentRect:NSMakeRect((screen_size.x - p_desired.width) / 2, (screen_size.y - p_desired.height) / 2, p_desired.width, p_desired.height)
12401244
styleMask:styleMask
12411245
backing:NSBackingStoreBuffered
1242-
defer:NO];
1246+
defer:NO
1247+
screen:screen];
12431248

12441249
ERR_FAIL_COND_V(window_object == nil, ERR_UNAVAILABLE);
12451250

@@ -1251,7 +1256,6 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay
12511256
float displayScale = 1.0;
12521257
if (is_hidpi_allowed()) {
12531258
// note that mainScreen is not screen #0 but the one with the keyboard focus.
1254-
NSScreen *screen = [NSScreen mainScreen];
12551259
if ([screen respondsToSelector:@selector(backingScaleFactor)]) {
12561260
displayScale = fmax(displayScale, [screen backingScaleFactor]);
12571261
}
@@ -1270,7 +1274,6 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay
12701274
[window_object setContentView:window_view];
12711275
[window_object setDelegate:window_delegate];
12721276
[window_object setAcceptsMouseMovedEvents:YES];
1273-
[window_object center];
12741277

12751278
[window_object setRestorable:NO];
12761279

@@ -2640,6 +2643,7 @@ static int get_screen_index(NSScreen *screen) {
26402643
im_callback = NULL;
26412644
im_target = NULL;
26422645
layered_window = false;
2646+
window_object = 0;
26432647
autoreleasePool = [[NSAutoreleasePool alloc] init];
26442648

26452649
eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);

platform/windows/os_windows.cpp

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
10991099
video_mode = p_desired;
11001100
//printf("**************** desired %s, mode %s\n", p_desired.fullscreen?"true":"false", video_mode.fullscreen?"true":"false");
11011101
RECT WindowRect;
1102+
int screen_id = _get_initial_screen_id();
1103+
Point2 screen_pos = get_screen_position(screen_id);
1104+
Size2 screen_size = get_screen_size(screen_id);
11021105

11031106
WindowRect.left = 0;
11041107
WindowRect.right = video_mode.width;
@@ -1141,35 +1144,9 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
11411144
pre_fs_valid = true;
11421145
if (video_mode.fullscreen) {
11431146

1144-
/* this returns DPI unaware size, commenting
1145-
DEVMODE current;
1146-
memset(&current, 0, sizeof(current));
1147-
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &current);
1147+
WindowRect.right = screen_size.x;
1148+
WindowRect.bottom = screen_size.y;
11481149

1149-
WindowRect.right = current.dmPelsWidth;
1150-
WindowRect.bottom = current.dmPelsHeight;
1151-
1152-
*/
1153-
1154-
EnumSizeData data = { 0, 0, Size2() };
1155-
EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcSize, (LPARAM)&data);
1156-
1157-
WindowRect.right = data.size.width;
1158-
WindowRect.bottom = data.size.height;
1159-
1160-
/* DEVMODE dmScreenSettings;
1161-
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
1162-
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
1163-
dmScreenSettings.dmPelsWidth = video_mode.width;
1164-
dmScreenSettings.dmPelsHeight = video_mode.height;
1165-
dmScreenSettings.dmBitsPerPel = current.dmBitsPerPel;
1166-
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
1167-
1168-
LONG err = ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
1169-
if (err!=DISP_CHANGE_SUCCESSFUL) {
1170-
1171-
video_mode.fullscreen=false;
1172-
}*/
11731150
pre_fs_valid = false;
11741151
}
11751152

@@ -1233,8 +1210,8 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
12331210
dwExStyle,
12341211
L"Engine", L"",
12351212
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
1236-
(GetSystemMetrics(SM_CXSCREEN) - WindowRect.right) / 2,
1237-
(GetSystemMetrics(SM_CYSCREEN) - WindowRect.bottom) / 2,
1213+
screen_pos.x + (screen_size.x - WindowRect.right) / 2,
1214+
screen_pos.y + (screen_size.y - WindowRect.bottom) / 2,
12381215
WindowRect.right - WindowRect.left,
12391216
WindowRect.bottom - WindowRect.top,
12401217
NULL, NULL, hInstance, NULL);

platform/x11/context_gl_x11.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/*************************************************************************/
3030

3131
#include "context_gl_x11.h"
32+
#include "core/project_settings.h"
3233

3334
#ifdef X11_ENABLED
3435
#if defined(OPENGL_ENABLED)
@@ -190,7 +191,19 @@ Error ContextGL_X11::initialize() {
190191
}
191192

192193
swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
193-
x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, valuemask, &swa);
194+
Point2 screen_pos = OS::get_singleton()->get_screen_position(screen_id);
195+
Size2 screen_size = OS::get_singleton()->get_screen_size(screen_id);
196+
int width = OS::get_singleton()->get_video_mode().width;
197+
int height = OS::get_singleton()->get_video_mode().height;
198+
int x = screen_pos.x + (screen_size.x - width) / 2;
199+
int y = screen_pos.y + (screen_size.y - height) / 2;
200+
x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), x, y, width, height, 0, vi->depth, InputOutput, vi->visual, valuemask, &swa);
201+
202+
XSizeHints xsh;
203+
xsh.flags = PPosition;
204+
xsh.x = x;
205+
xsh.y = y;
206+
XSetWMNormalHints(x11_display, x11_window, &xsh);
194207

195208
ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED);
196209
set_class_hint(x11_display, x11_window);
@@ -254,13 +267,14 @@ bool ContextGL_X11::is_using_vsync() const {
254267
return use_vsync;
255268
}
256269

257-
ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type) :
270+
ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type, int p_screen_id) :
258271
x11_window(p_x11_window) {
259272

260273
default_video_mode = p_default_video_mode;
261274
x11_display = p_x11_display;
262275

263276
context_type = p_context_type;
277+
screen_id = p_screen_id;
264278

265279
double_buffer = false;
266280
direct_render = false;

platform/x11/context_gl_x11.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ContextGL_X11 : public ContextGL {
6060
//::Colormap x11_colormap;
6161
::Display *x11_display;
6262
::Window &x11_window;
63+
int screen_id;
6364
bool double_buffer;
6465
bool direct_render;
6566
int glx_minor, glx_major;
@@ -78,7 +79,7 @@ class ContextGL_X11 : public ContextGL {
7879
virtual void set_use_vsync(bool p_use);
7980
virtual bool is_using_vsync() const;
8081

81-
ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type);
82+
ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, const OS::VideoMode &p_default_video_mode, ContextType p_context_type, int p_screen_id);
8283
virtual ~ContextGL_X11();
8384
};
8485

0 commit comments

Comments
 (0)