move David Venturas X code to x_display_fix.h

This commit is contained in:
fduncanh
2021-08-02 05:59:22 -04:00
parent 8829e458d7
commit 5166d050ba
3 changed files with 99 additions and 47 deletions

View File

@@ -21,12 +21,10 @@
#include <assert.h>
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
Display* display;
Window root, my_window;
#ifdef X_DISPLAY_FIX
#include "x_display_fix.h"
#endif
struct video_renderer_s {
logger_t *logger;
@@ -55,46 +53,20 @@ static gboolean check_plugins (void)
return ret;
}
Window enum_windows(Display* display, Window window, int depth) {
int i;
XTextProperty text;
XGetWMName(display, window, &text);
char* name;
XFetchName(display, window, &name);
if (name != 0 && strcmp((const char*) g_get_application_name(), name) == 0) {
return window;
}
Window _root, parent;
Window* children;
unsigned int n;
XQueryTree(display, window, &_root, &parent, &children, &n);
if (children != NULL) {
for (i = 0; i < n; i++) {
Window w = enum_windows(display, children[i], depth + 1);
if (w) return w;
}
XFree(children);
}
return (Window) NULL;
}
video_renderer_t *video_renderer_init(logger_t *logger, const char *server_name) {
display = XOpenDisplay(NULL);
root = XDefaultRootWindow(display);
video_renderer_t *renderer;
GError *error = NULL;
#ifdef X_DISPLAY_FIX
get_x_display_root();
g_set_application_name(server_name);
#endif
renderer = calloc(1, sizeof(video_renderer_t));
assert(renderer);
gst_init(NULL, NULL);
g_set_application_name(server_name);
renderer->logger = logger;
assert(check_plugins ());
@@ -125,16 +97,9 @@ void video_renderer_render_buffer(video_renderer_t *renderer, raop_ntp_t *ntp, u
gst_buffer_fill(buffer, 0, data, data_len);
gst_app_src_push_buffer (GST_APP_SRC(renderer->appsrc), buffer);
if (!my_window) {
my_window = enum_windows(display, root, 0);
if (my_window) {
const char* str = g_get_application_name();
Atom _NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", 0);
Atom UTF8_STRING = XInternAtom(display, "UTF8_STRING",0);
XChangeProperty(display, my_window, _NET_WM_NAME, UTF8_STRING, 8, 0, (const unsigned char *) str, strlen(str));
XSync(display, False);
}
}
#ifdef X_DISPLAY_FIX
fix_x_window_name();
#endif
}
void video_renderer_flush(video_renderer_t *renderer) {

86
renderers/x_display_fix.h Normal file
View File

@@ -0,0 +1,86 @@
/**
* RPiPlay - An open-source AirPlay mirroring server for Raspberry Pi
* Copyright (C) 2019 Florian Draschbacher
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* code from David Ventura https://github.com/DavidVentura/UxPlay */
#ifndef X_DISPLAY_FIX_H
#define X_DISPLAY_FIX_H
#ifdef __cplusplus
extern "C" {
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
static Display* display;
static Window root, my_window;
void get_x_display_root() {
display = XOpenDisplay(NULL);
root = XDefaultRootWindow(display);
}
Window enum_windows(Display* display, Window window, int depth) {
int i;
XTextProperty text;
XGetWMName(display, window, &text);
char* name;
XFetchName(display, window, &name);
if (name != 0 && strcmp((const char*) g_get_application_name(), name) == 0) {
return window;
}
Window _root, parent;
Window* children;
unsigned int n;
XQueryTree(display, window, &_root, &parent, &children, &n);
if (children != NULL) {
for (i = 0; i < n; i++) {
Window w = enum_windows(display, children[i], depth + 1);
if (w) return w;
}
XFree(children);
}
return (Window) NULL;
}
void fix_x_window_name() {
if (!my_window) {
my_window = enum_windows(display, root, 0);
if (my_window) {
const char* str = g_get_application_name();
Atom _NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", 0);
Atom UTF8_STRING = XInternAtom(display, "UTF8_STRING",0);
XChangeProperty(display, my_window, _NET_WM_NAME, UTF8_STRING, 8, 0, (const unsigned char *) str, strlen(str));
XSync(display, False);
}
}
}
#ifdef __cplusplus
}
#endif
#endif