From c392164f038c58d3a8c23b7f2ff2fd51a2b5513b Mon Sep 17 00:00:00 2001 From: Lucian Poston Date: Sat, 14 Nov 2015 00:34:32 -0800 Subject: [PATCH] linux-capture: Log warning when unable to query windows Checks whether window manager supports ewmh. Logs warning if ewmh is not supported. Closes jp9000/obs-studio#488 --- plugins/linux-capture/xcompcap-helper.cpp | 72 +++++++++++++++++++++++ plugins/linux-capture/xcompcap-helper.hpp | 1 + 2 files changed, 73 insertions(+) diff --git a/plugins/linux-capture/xcompcap-helper.cpp b/plugins/linux-capture/xcompcap-helper.cpp index 4ff158ab3..088af4f83 100644 --- a/plugins/linux-capture/xcompcap-helper.cpp +++ b/plugins/linux-capture/xcompcap-helper.cpp @@ -47,10 +47,82 @@ namespace XCompcap return res; } + // Specification for checking for ewmh support at + // http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472693600 + + bool ewmhIsSupported() + { + Display *display = disp(); + Atom netSupportingWmCheck = XInternAtom(display, + "_NET_SUPPORTING_WM_CHECK", true); + Atom actualType; + int format = 0; + unsigned long num = 0, bytes = 0; + unsigned char *data = NULL; + Window ewmh_window = 0; + + int status = XGetWindowProperty( + display, + DefaultRootWindow(display), + netSupportingWmCheck, + 0L, + 1L, + false, + XA_WINDOW, + &actualType, + &format, + &num, + &bytes, + &data); + + if (status == Success) { + if (num > 0) { + ewmh_window = ((Window*)data)[0]; + } + if (data) { + XFree(data); + data = NULL; + } + } + + if (ewmh_window) { + status = XGetWindowProperty( + display, + ewmh_window, + netSupportingWmCheck, + 0L, + 1L, + false, + XA_WINDOW, + &actualType, + &format, + &num, + &bytes, + &data); + if (status != Success || num == 0 || + ewmh_window != ((Window*)data)[0]) { + ewmh_window = 0; + } + if (status == Success && data) { + XFree(data); + } + } + + return ewmh_window != 0; + } + std::list getTopLevelWindows() { std::list res; + if (!ewmhIsSupported()) { + blog(LOG_WARNING, "Unable to query window list " + "because window manager " + "does not support extended " + "window manager Hints"); + return res; + } + Atom netClList = XInternAtom(disp(), "_NET_CLIENT_LIST", true); Atom actualType; int format; diff --git a/plugins/linux-capture/xcompcap-helper.hpp b/plugins/linux-capture/xcompcap-helper.hpp index d4b008f43..ceb992e37 100644 --- a/plugins/linux-capture/xcompcap-helper.hpp +++ b/plugins/linux-capture/xcompcap-helper.hpp @@ -67,6 +67,7 @@ namespace XCompcap int getRootWindowScreen(Window root); std::string getWindowName(Window win); int getWindowPid(Window win); + bool ewmhIsSupported(); std::list getTopLevelWindows(); std::list getAllWindows();