From d6380b865e21675cbde37aee34c275eda6acfb91 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 2 Jun 2020 00:38:35 -0400 Subject: [PATCH] Fix some windows (Steam) not being found on Linux Reverts part of commit e61905d02f5aa4143b507e8a53b98d45a93ba944 Fallback to WM_NAME if _NET_WM_NAME does not exist Also fixes some BadWindow errors that were due to some apps like Steam only populating WM_NAME, and only for certain windows (tooltips count as windows due to the odd way the GUI works on Linux, so they don't have either property) --- src/linux/advanced-scene-switcher-nix.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/linux/advanced-scene-switcher-nix.cpp b/src/linux/advanced-scene-switcher-nix.cpp index 6207475a..750fe32c 100644 --- a/src/linux/advanced-scene-switcher-nix.cpp +++ b/src/linux/advanced-scene-switcher-nix.cpp @@ -184,8 +184,9 @@ static std::string GetWindowTitle(size_t i) char* name; XTextProperty text; - Atom titleProperty = XInternAtom(disp(), "_NET_WM_NAME", true); - int status = XGetTextProperty(disp(), w, &text, titleProperty); + int status = XGetTextProperty(disp(), w, &text, XInternAtom(disp(), "_NET_WM_NAME", true)); + if (status == 0) + status = XGetTextProperty(disp(), w, &text, XInternAtom(disp(), "WM_NAME", true)); name = reinterpret_cast(text.value); if (status != 0 && name != nullptr) @@ -235,7 +236,7 @@ void GetCurrentWindowTitle(string &title) Window rootWin = RootWindow(disp(), 0); - XGetWindowProperty( + int xstatus = XGetWindowProperty( disp(), rootWin, active, @@ -249,9 +250,13 @@ void GetCurrentWindowTitle(string &title) &bytes, (uint8_t**)&data); + int status = 0; XTextProperty text; - Atom titleProperty = XInternAtom(disp(), "_NET_WM_NAME", true); - int status = XGetTextProperty(disp(), data[0], &text, titleProperty); + if (xstatus == Success) { + status = XGetTextProperty(disp(), data[0], &text, XInternAtom(disp(), "_NET_WM_NAME", true)); + if (status == 0) + status = XGetTextProperty(disp(), data[0], &text, XInternAtom(disp(), "WM_NAME", true)); + } name = reinterpret_cast(text.value); if (status != 0 && name != nullptr) { @@ -293,15 +298,16 @@ bool isFullscreen(std::string &title) return false; // Find switch in top level windows - Atom titleProperty = XInternAtom(disp(), "_NET_WM_NAME", true); vector windows = getTopLevelWindows(); for (auto &window : windows) { XTextProperty text; - int status = XGetTextProperty(disp(), window, &text, titleProperty); + int status = XGetTextProperty(disp(), window, &text, XInternAtom(disp(), "_NET_WM_NAME", true)); + if (status == 0) + status = XGetTextProperty(disp(), window, &text, XInternAtom(disp(), "WM_NAME", true)); char *name = reinterpret_cast(text.value); - if (status == 0 || strcmp(name, "") == 0) + if (status == 0 || name == nullptr) continue; // True if switch equals window