Skip to content

Commit 685fa32

Browse files
committed
Merge pull request #111580 from timothyqiu/x11-fullscreen
X11: Fix fullscreen exit behavior
2 parents 5c93330 + 0f81e8c commit 685fa32

File tree

2 files changed

+8
-55
lines changed

2 files changed

+8
-55
lines changed

platform/linuxbsd/x11/display_server_x11.cpp

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,11 +2392,12 @@ void DisplayServerX11::_update_size_hints(WindowID p_window) {
23922392
XSizeHints *xsh = XAllocSizeHints();
23932393

23942394
// Always set the position and size hints - they should be synchronized with the actual values after the window is mapped anyway
2395-
xsh->flags |= PPosition | PSize;
2395+
xsh->flags |= PPosition | PSize | PWinGravity;
23962396
xsh->x = wd.position.x;
23972397
xsh->y = wd.position.y;
23982398
xsh->width = wd.size.width;
23992399
xsh->height = wd.size.height;
2400+
xsh->win_gravity = StaticGravity;
24002401

24012402
if (window_mode == WINDOW_MODE_FULLSCREEN || window_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
24022403
// Do not set any other hints to prevent the window manager from ignoring the fullscreen flags
@@ -2560,29 +2561,7 @@ void DisplayServerX11::window_set_position(const Point2i &p_position, WindowID p
25602561
}
25612562

25622563
wd.position = p_position;
2563-
int x = 0;
2564-
int y = 0;
2565-
if (!window_get_flag(WINDOW_FLAG_BORDERLESS, p_window)) {
2566-
//exclude window decorations
2567-
XSync(x11_display, False);
2568-
Atom prop = XInternAtom(x11_display, "_NET_FRAME_EXTENTS", True);
2569-
if (prop != None) {
2570-
Atom type;
2571-
int format;
2572-
unsigned long len;
2573-
unsigned long remaining;
2574-
unsigned char *data = nullptr;
2575-
if (XGetWindowProperty(x11_display, wd.x11_window, prop, 0, 4, False, AnyPropertyType, &type, &format, &len, &remaining, &data) == Success) {
2576-
if (format == 32 && len == 4 && data) {
2577-
long *extents = (long *)data;
2578-
x = extents[0];
2579-
y = extents[2];
2580-
}
2581-
XFree(data);
2582-
}
2583-
}
2584-
}
2585-
XMoveWindow(x11_display, wd.x11_window, p_position.x - x, p_position.y - y);
2564+
XMoveWindow(x11_display, wd.x11_window, p_position.x, p_position.y);
25862565
_update_real_mouse_position(wd);
25872566
}
25882567

@@ -3098,21 +3077,12 @@ void DisplayServerX11::window_set_mode(WindowMode p_mode, WindowID p_window) {
30983077
} break;
30993078
case WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
31003079
case WINDOW_MODE_FULLSCREEN: {
3101-
//Remove full-screen
3102-
wd.fullscreen = false;
3103-
wd.exclusive_fullscreen = false;
3104-
3105-
_set_wm_fullscreen(p_window, false, false);
3106-
3107-
//un-maximize required for always on top
3108-
bool on_top = window_get_flag(WINDOW_FLAG_ALWAYS_ON_TOP, p_window);
3109-
3110-
window_set_position(wd.last_position_before_fs, p_window);
3111-
3112-
if (on_top) {
3113-
_set_wm_maximized(p_window, false);
3080+
// Only remove fullscreen when necessary.
3081+
if (p_mode == WINDOW_MODE_WINDOWED || p_mode == WINDOW_MODE_MAXIMIZED) {
3082+
wd.fullscreen = false;
3083+
wd.exclusive_fullscreen = false;
3084+
_set_wm_fullscreen(p_window, false, false);
31143085
}
3115-
31163086
} break;
31173087
case WINDOW_MODE_MAXIMIZED: {
31183088
// Varies between target modes, so do nothing here.
@@ -3130,8 +3100,6 @@ void DisplayServerX11::window_set_mode(WindowMode p_mode, WindowID p_window) {
31303100
} break;
31313101
case WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
31323102
case WINDOW_MODE_FULLSCREEN: {
3133-
wd.last_position_before_fs = wd.position;
3134-
31353103
if (window_get_flag(WINDOW_FLAG_ALWAYS_ON_TOP, p_window)) {
31363104
_set_wm_maximized(p_window, true);
31373105
}
@@ -4453,17 +4421,6 @@ void DisplayServerX11::_window_changed(XEvent *event) {
44534421
return;
44544422
}
44554423

4456-
// Readjusting the window position if the window is being reparented by the window manager for decoration
4457-
Window root, parent, *children;
4458-
unsigned int nchildren;
4459-
if (XQueryTree(x11_display, wd.x11_window, &root, &parent, &children, &nchildren) && wd.parent != parent) {
4460-
wd.parent = parent;
4461-
if (!wd.embed_parent) {
4462-
window_set_position(wd.position, window_id);
4463-
}
4464-
}
4465-
XFree(children);
4466-
44674424
{
44684425
//the position in xconfigure is not useful here, obtain it manually
44694426
int x = 0, y = 0;
@@ -6448,8 +6405,6 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
64486405
{
64496406
wd.x11_window = XCreateWindow(x11_display, RootWindow(x11_display, visualInfo.screen), win_rect.position.x, win_rect.position.y, win_rect.size.width > 0 ? win_rect.size.width : 1, win_rect.size.height > 0 ? win_rect.size.height : 1, 0, visualInfo.depth, InputOutput, visualInfo.visual, valuemask, &windowAttributes);
64506407

6451-
wd.parent = RootWindow(x11_display, visualInfo.screen);
6452-
64536408
DEBUG_LOG_X11("CreateWindow window=%lu, parent: %lu \n", wd.x11_window, wd.parent);
64546409

64556410
if (p_parent_window) {

platform/linuxbsd/x11/display_server_x11.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class DisplayServerX11 : public DisplayServer {
164164
struct WindowData {
165165
Window x11_window;
166166
Window x11_xim_window;
167-
Window parent;
168167
::XIC xic;
169168
bool ime_active = false;
170169
bool ime_in_progress = false;
@@ -201,7 +200,6 @@ class DisplayServerX11 : public DisplayServer {
201200
bool resize_disabled = false;
202201
bool no_min_btn = false;
203202
bool no_max_btn = false;
204-
Vector2i last_position_before_fs;
205203
bool focused = true;
206204
bool minimized = false;
207205
bool maximized = false;

0 commit comments

Comments
 (0)