mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
move David Venturas X code to x_display_fix.h
This commit is contained in:
@@ -6,6 +6,7 @@ set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_definitions(-DAVAHI_COMPAT_NOWARN)
|
||||
|
||||
add_definitions(-DX_DISPLAY_FIX)
|
||||
find_package(X11 REQUIRED)
|
||||
link_libraries(${X11_LIBRARIES})
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
|
||||
@@ -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,45 +53,19 @@ 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;
|
||||
|
||||
@@ -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
86
renderers/x_display_fix.h
Normal 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
|
||||
Reference in New Issue
Block a user