New upstream version 24.0.1+dfsg1
This commit is contained in:
parent
b14f9eae6d
commit
5a730d6ec3
842 changed files with 42245 additions and 33385 deletions
|
|
@ -11,291 +11,259 @@
|
|||
|
||||
#include "xcompcap-helper.hpp"
|
||||
|
||||
namespace XCompcap
|
||||
namespace XCompcap {
|
||||
static Display *xdisplay = 0;
|
||||
|
||||
Display *disp()
|
||||
{
|
||||
static Display* xdisplay = 0;
|
||||
if (!xdisplay)
|
||||
xdisplay = XOpenDisplay(NULL);
|
||||
|
||||
Display *disp()
|
||||
{
|
||||
if (!xdisplay)
|
||||
xdisplay = XOpenDisplay(NULL);
|
||||
return xdisplay;
|
||||
}
|
||||
|
||||
return xdisplay;
|
||||
}
|
||||
void cleanupDisplay()
|
||||
{
|
||||
if (!xdisplay)
|
||||
return;
|
||||
|
||||
void cleanupDisplay()
|
||||
{
|
||||
if (!xdisplay)
|
||||
return;
|
||||
XCloseDisplay(xdisplay);
|
||||
xdisplay = 0;
|
||||
}
|
||||
|
||||
XCloseDisplay(xdisplay);
|
||||
xdisplay = 0;
|
||||
}
|
||||
static void getAllWindows(Window parent, std::list<Window> &windows)
|
||||
{
|
||||
UNUSED_PARAMETER(parent);
|
||||
UNUSED_PARAMETER(windows);
|
||||
}
|
||||
|
||||
static void getAllWindows(Window parent, std::list<Window>& windows)
|
||||
{
|
||||
UNUSED_PARAMETER(parent);
|
||||
UNUSED_PARAMETER(windows);
|
||||
}
|
||||
std::list<Window> getAllWindows()
|
||||
{
|
||||
std::list<Window> res;
|
||||
|
||||
std::list<Window> getAllWindows()
|
||||
{
|
||||
std::list<Window> res;
|
||||
for (int i = 0; i < ScreenCount(disp()); ++i)
|
||||
getAllWindows(RootWindow(disp(), i), res);
|
||||
|
||||
for (int i = 0; i < ScreenCount(disp()); ++i)
|
||||
getAllWindows(RootWindow(disp(), i), res);
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
// Specification for checking for ewmh support at
|
||||
// http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472693600
|
||||
|
||||
// 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;
|
||||
|
||||
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);
|
||||
|
||||
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 (status == Success) {
|
||||
if (num > 0) {
|
||||
ewmh_window = ((Window *)data)[0];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (data) {
|
||||
XFree(data);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
return ewmh_window != 0;
|
||||
}
|
||||
|
||||
std::list<Window> getTopLevelWindows()
|
||||
{
|
||||
std::list<Window> res;
|
||||
|
||||
if (!ewmhIsSupported()) {
|
||||
blog(LOG_WARNING, "Unable to query window list "
|
||||
"because window manager "
|
||||
"does not support extended "
|
||||
"window manager Hints");
|
||||
return res;
|
||||
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;
|
||||
}
|
||||
|
||||
Atom netClList = XInternAtom(disp(), "_NET_CLIENT_LIST", true);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long num, bytes;
|
||||
Window* data = 0;
|
||||
|
||||
for (int i = 0; i < ScreenCount(disp()); ++i) {
|
||||
Window rootWin = RootWindow(disp(), i);
|
||||
|
||||
int status = XGetWindowProperty(
|
||||
disp(),
|
||||
rootWin,
|
||||
netClList,
|
||||
0L,
|
||||
~0L,
|
||||
false,
|
||||
AnyPropertyType,
|
||||
&actualType,
|
||||
&format,
|
||||
&num,
|
||||
&bytes,
|
||||
(uint8_t**)&data);
|
||||
|
||||
if (status != Success) {
|
||||
blog(LOG_WARNING, "Failed getting root "
|
||||
"window properties");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (unsigned long i = 0; i < num; ++i)
|
||||
res.push_back(data[i]);
|
||||
|
||||
if (status == Success && data) {
|
||||
XFree(data);
|
||||
}
|
||||
}
|
||||
|
||||
return ewmh_window != 0;
|
||||
}
|
||||
|
||||
std::list<Window> getTopLevelWindows()
|
||||
{
|
||||
std::list<Window> res;
|
||||
|
||||
if (!ewmhIsSupported()) {
|
||||
blog(LOG_WARNING, "Unable to query window list "
|
||||
"because window manager "
|
||||
"does not support extended "
|
||||
"window manager Hints");
|
||||
return res;
|
||||
}
|
||||
|
||||
int getRootWindowScreen(Window root)
|
||||
{
|
||||
XWindowAttributes attr;
|
||||
Atom netClList = XInternAtom(disp(), "_NET_CLIENT_LIST", true);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long num, bytes;
|
||||
Window *data = 0;
|
||||
|
||||
if (!XGetWindowAttributes(disp(), root, &attr))
|
||||
return DefaultScreen(disp());
|
||||
for (int i = 0; i < ScreenCount(disp()); ++i) {
|
||||
Window rootWin = RootWindow(disp(), i);
|
||||
|
||||
return XScreenNumberOfScreen(attr.screen);
|
||||
}
|
||||
int status = XGetWindowProperty(disp(), rootWin, netClList, 0L,
|
||||
~0L, false, AnyPropertyType,
|
||||
&actualType, &format, &num,
|
||||
&bytes, (uint8_t **)&data);
|
||||
|
||||
std::string getWindowAtom(Window win, const char *atom)
|
||||
{
|
||||
Atom netWmName = XInternAtom(disp(), atom, false);
|
||||
int n;
|
||||
char **list = 0;
|
||||
XTextProperty tp;
|
||||
std::string res = "unknown";
|
||||
|
||||
XGetTextProperty(disp(), win, &tp, netWmName);
|
||||
|
||||
if (!tp.nitems)
|
||||
XGetWMName(disp(), win, &tp);
|
||||
|
||||
if (!tp.nitems)
|
||||
return "error";
|
||||
|
||||
if (tp.encoding == XA_STRING) {
|
||||
res = (char*)tp.value;
|
||||
} else {
|
||||
int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
|
||||
&n);
|
||||
|
||||
if (ret >= Success && n > 0 && *list) {
|
||||
res = *list;
|
||||
XFreeStringList(list);
|
||||
}
|
||||
if (status != Success) {
|
||||
blog(LOG_WARNING, "Failed getting root "
|
||||
"window properties");
|
||||
continue;
|
||||
}
|
||||
|
||||
char *conv = nullptr;
|
||||
if (os_mbs_to_utf8_ptr(res.c_str(), 0, &conv))
|
||||
res = conv;
|
||||
bfree(conv);
|
||||
for (unsigned long i = 0; i < num; ++i)
|
||||
res.push_back(data[i]);
|
||||
|
||||
XFree(tp.value);
|
||||
|
||||
return res;
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
std::string getWindowCommand(Window win)
|
||||
{
|
||||
Atom xi = XInternAtom(disp(), "WM_COMMAND", false);
|
||||
int n;
|
||||
char **list = 0;
|
||||
XTextProperty tp;
|
||||
std::string res = "error";
|
||||
return res;
|
||||
}
|
||||
|
||||
XGetTextProperty(disp(), win, &tp, xi);
|
||||
int getRootWindowScreen(Window root)
|
||||
{
|
||||
XWindowAttributes attr;
|
||||
|
||||
if (!tp.nitems)
|
||||
return std::string();
|
||||
if (!XGetWindowAttributes(disp(), root, &attr))
|
||||
return DefaultScreen(disp());
|
||||
|
||||
if (tp.encoding == XA_STRING) {
|
||||
res = (char*)tp.value;
|
||||
} else {
|
||||
int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
|
||||
&n);
|
||||
if (ret >= Success && n > 0 && *list) {
|
||||
res = *list;
|
||||
XFreeStringList(list);
|
||||
}
|
||||
return XScreenNumberOfScreen(attr.screen);
|
||||
}
|
||||
|
||||
std::string getWindowAtom(Window win, const char *atom)
|
||||
{
|
||||
Atom netWmName = XInternAtom(disp(), atom, false);
|
||||
int n;
|
||||
char **list = 0;
|
||||
XTextProperty tp;
|
||||
std::string res = "unknown";
|
||||
|
||||
XGetTextProperty(disp(), win, &tp, netWmName);
|
||||
|
||||
if (!tp.nitems)
|
||||
XGetWMName(disp(), win, &tp);
|
||||
|
||||
if (!tp.nitems)
|
||||
return "error";
|
||||
|
||||
if (tp.encoding == XA_STRING) {
|
||||
res = (char *)tp.value;
|
||||
} else {
|
||||
int ret = XmbTextPropertyToTextList(disp(), &tp, &list, &n);
|
||||
|
||||
if (ret >= Success && n > 0 && *list) {
|
||||
res = *list;
|
||||
XFreeStringList(list);
|
||||
}
|
||||
|
||||
XFree(tp.value);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int getWindowPid(Window win)
|
||||
{
|
||||
UNUSED_PARAMETER(win);
|
||||
return 1234; //TODO
|
||||
}
|
||||
char *conv = nullptr;
|
||||
if (os_mbs_to_utf8_ptr(res.c_str(), 0, &conv))
|
||||
res = conv;
|
||||
bfree(conv);
|
||||
|
||||
static std::unordered_set<Window> changedWindows;
|
||||
static pthread_mutex_t changeLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
void processEvents()
|
||||
{
|
||||
PLock lock(&changeLock);
|
||||
XFree(tp.value);
|
||||
|
||||
XLockDisplay(disp());
|
||||
return res;
|
||||
}
|
||||
|
||||
while (XEventsQueued(disp(), QueuedAfterReading) > 0) {
|
||||
XEvent ev;
|
||||
std::string getWindowCommand(Window win)
|
||||
{
|
||||
Atom xi = XInternAtom(disp(), "WM_COMMAND", false);
|
||||
int n;
|
||||
char **list = 0;
|
||||
XTextProperty tp;
|
||||
std::string res = "error";
|
||||
|
||||
XNextEvent(disp(), &ev);
|
||||
XGetTextProperty(disp(), win, &tp, xi);
|
||||
|
||||
if (ev.type == ConfigureNotify)
|
||||
changedWindows.insert(ev.xconfigure.event);
|
||||
if (!tp.nitems)
|
||||
return std::string();
|
||||
|
||||
if (ev.type == MapNotify)
|
||||
changedWindows.insert(ev.xmap.event);
|
||||
|
||||
if (ev.type == Expose)
|
||||
changedWindows.insert(ev.xexpose.window);
|
||||
|
||||
if (ev.type == VisibilityNotify)
|
||||
changedWindows.insert(ev.xvisibility.window);
|
||||
|
||||
if (ev.type == DestroyNotify)
|
||||
changedWindows.insert(ev.xdestroywindow.event);
|
||||
if (tp.encoding == XA_STRING) {
|
||||
res = (char *)tp.value;
|
||||
} else {
|
||||
int ret = XmbTextPropertyToTextList(disp(), &tp, &list, &n);
|
||||
if (ret >= Success && n > 0 && *list) {
|
||||
res = *list;
|
||||
XFreeStringList(list);
|
||||
}
|
||||
|
||||
XUnlockDisplay(disp());
|
||||
}
|
||||
|
||||
bool windowWasReconfigured(Window win)
|
||||
{
|
||||
PLock lock(&changeLock);
|
||||
XFree(tp.value);
|
||||
|
||||
auto it = changedWindows.find(win);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (it != changedWindows.end()) {
|
||||
changedWindows.erase(it);
|
||||
return true;
|
||||
}
|
||||
int getWindowPid(Window win)
|
||||
{
|
||||
UNUSED_PARAMETER(win);
|
||||
return 1234; //TODO
|
||||
}
|
||||
|
||||
return false;
|
||||
static std::unordered_set<Window> changedWindows;
|
||||
static pthread_mutex_t changeLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
void processEvents()
|
||||
{
|
||||
PLock lock(&changeLock);
|
||||
|
||||
XLockDisplay(disp());
|
||||
|
||||
while (XEventsQueued(disp(), QueuedAfterReading) > 0) {
|
||||
XEvent ev;
|
||||
|
||||
XNextEvent(disp(), &ev);
|
||||
|
||||
if (ev.type == ConfigureNotify)
|
||||
changedWindows.insert(ev.xconfigure.event);
|
||||
|
||||
if (ev.type == MapNotify)
|
||||
changedWindows.insert(ev.xmap.event);
|
||||
|
||||
if (ev.type == Expose)
|
||||
changedWindows.insert(ev.xexpose.window);
|
||||
|
||||
if (ev.type == VisibilityNotify)
|
||||
changedWindows.insert(ev.xvisibility.window);
|
||||
|
||||
if (ev.type == DestroyNotify)
|
||||
changedWindows.insert(ev.xdestroywindow.event);
|
||||
}
|
||||
|
||||
XUnlockDisplay(disp());
|
||||
}
|
||||
|
||||
bool windowWasReconfigured(Window win)
|
||||
{
|
||||
PLock lock(&changeLock);
|
||||
|
||||
auto it = changedWindows.find(win);
|
||||
|
||||
if (it != changedWindows.end()) {
|
||||
changedWindows.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
PLock::PLock(pthread_mutex_t* mtx, bool trylock)
|
||||
:m(mtx)
|
||||
PLock::PLock(pthread_mutex_t *mtx, bool trylock) : m(mtx)
|
||||
{
|
||||
if (trylock)
|
||||
islock = mtx && pthread_mutex_trylock(mtx) == 0;
|
||||
|
|
@ -331,11 +299,9 @@ void PLock::lock()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool* curErrorTarget = 0;
|
||||
static bool *curErrorTarget = 0;
|
||||
static char curErrorText[200];
|
||||
static int xerrorlock_handler(Display* disp, XErrorEvent* err)
|
||||
static int xerrorlock_handler(Display *disp, XErrorEvent *err)
|
||||
{
|
||||
|
||||
if (curErrorTarget)
|
||||
|
|
@ -451,7 +417,6 @@ void XDisplayLock::unlock()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
ObsGsContextHolder::ObsGsContextHolder()
|
||||
{
|
||||
obs_enter_graphics();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue