Skip to content

Commit

Permalink
Merge pull request godotengine#80036 from PorkrollPosadist/fix-waylan…
Browse files Browse the repository at this point in the history
…d-window-behavior

Use EWMH for `DisplayServerX11::_window_minimize_check()` implementation
  • Loading branch information
akien-mga committed Aug 17, 2023
2 parents 37d213b + 5666656 commit 9a48b14
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2112,17 +2112,18 @@ bool DisplayServerX11::_window_maximize_check(WindowID p_window, const char *p_a
bool DisplayServerX11::_window_minimize_check(WindowID p_window) const {
const WindowData &wd = windows[p_window];

// Using ICCCM -- Inter-Client Communication Conventions Manual
Atom property = XInternAtom(x11_display, "WM_STATE", True);
if (property == None) {
// Using EWMH instead of ICCCM, might work better for Wayland users.
Atom property = XInternAtom(x11_display, "_NET_WM_STATE", True);
Atom hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", True);
if (property == None || hidden == None) {
return false;
}

Atom type;
int format;
unsigned long len;
unsigned long remaining;
unsigned char *data = nullptr;
Atom *atoms = nullptr;

int result = XGetWindowProperty(
x11_display,
Expand All @@ -2131,20 +2132,21 @@ bool DisplayServerX11::_window_minimize_check(WindowID p_window) const {
0,
32,
False,
AnyPropertyType,
XA_ATOM,
&type,
&format,
&len,
&remaining,
&data);
(unsigned char **)&atoms);

if (result == Success && data) {
long *state = (long *)data;
if (state[0] == WM_IconicState) {
XFree(data);
return true;
if (result == Success && atoms) {
for (unsigned int i = 0; i < len; i++) {
if (atoms[i] == hidden) {
XFree(atoms);
return true;
}
}
XFree(data);
XFree(atoms);
}

return false;
Expand Down

0 comments on commit 9a48b14

Please sign in to comment.