mirror of https://github.com/godotengine/godot
[X11] Detect XWayland and disable screen capture support.
This commit is contained in:
parent
292e50e17e
commit
3cabf51325
|
|
@ -139,8 +139,9 @@ bool DisplayServerX11::has_feature(Feature p_feature) const {
|
||||||
#endif
|
#endif
|
||||||
case FEATURE_CLIPBOARD_PRIMARY:
|
case FEATURE_CLIPBOARD_PRIMARY:
|
||||||
case FEATURE_TEXT_TO_SPEECH:
|
case FEATURE_TEXT_TO_SPEECH:
|
||||||
case FEATURE_SCREEN_CAPTURE:
|
|
||||||
return true;
|
return true;
|
||||||
|
case FEATURE_SCREEN_CAPTURE:
|
||||||
|
return !xwayland;
|
||||||
default: {
|
default: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1494,9 +1495,20 @@ int DisplayServerX11::screen_get_dpi(int p_screen) const {
|
||||||
return 96;
|
return 96;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_image_errorhandler(Display *dpy, XErrorEvent *ev) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Color DisplayServerX11::screen_get_pixel(const Point2i &p_position) const {
|
Color DisplayServerX11::screen_get_pixel(const Point2i &p_position) const {
|
||||||
Point2i pos = p_position;
|
Point2i pos = p_position;
|
||||||
|
|
||||||
|
if (xwayland) {
|
||||||
|
return Color();
|
||||||
|
}
|
||||||
|
|
||||||
|
int (*old_handler)(Display *, XErrorEvent *) = XSetErrorHandler(&get_image_errorhandler);
|
||||||
|
|
||||||
|
Color color;
|
||||||
int number_of_screens = XScreenCount(x11_display);
|
int number_of_screens = XScreenCount(x11_display);
|
||||||
for (int i = 0; i < number_of_screens; i++) {
|
for (int i = 0; i < number_of_screens; i++) {
|
||||||
Window root = XRootWindow(x11_display, i);
|
Window root = XRootWindow(x11_display, i);
|
||||||
|
|
@ -1509,12 +1521,15 @@ Color DisplayServerX11::screen_get_pixel(const Point2i &p_position) const {
|
||||||
c.pixel = XGetPixel(image, 0, 0);
|
c.pixel = XGetPixel(image, 0, 0);
|
||||||
XFree(image);
|
XFree(image);
|
||||||
XQueryColor(x11_display, XDefaultColormap(x11_display, i), &c);
|
XQueryColor(x11_display, XDefaultColormap(x11_display, i), &c);
|
||||||
return Color(float(c.red) / 65535.0, float(c.green) / 65535.0, float(c.blue) / 65535.0, 1.0);
|
color = Color(float(c.red) / 65535.0, float(c.green) / 65535.0, float(c.blue) / 65535.0, 1.0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Color();
|
XSetErrorHandler(old_handler);
|
||||||
|
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
|
Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
|
||||||
|
|
@ -1533,6 +1548,12 @@ Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(p_screen < 0, Ref<Image>());
|
ERR_FAIL_COND_V(p_screen < 0, Ref<Image>());
|
||||||
|
|
||||||
|
if (xwayland) {
|
||||||
|
return Ref<Image>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int (*old_handler)(Display *, XErrorEvent *) = XSetErrorHandler(&get_image_errorhandler);
|
||||||
|
|
||||||
XImage *image = nullptr;
|
XImage *image = nullptr;
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
@ -1575,6 +1596,8 @@ Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XSetErrorHandler(old_handler);
|
||||||
|
|
||||||
Ref<Image> img;
|
Ref<Image> img;
|
||||||
if (image) {
|
if (image) {
|
||||||
int width = image->width;
|
int width = image->width;
|
||||||
|
|
@ -5815,6 +5838,8 @@ static ::XIMStyle _get_best_xim_style(const ::XIMStyle &p_style_a, const ::XIMSt
|
||||||
DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error) {
|
DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error) {
|
||||||
KeyMappingX11::initialize();
|
KeyMappingX11::initialize();
|
||||||
|
|
||||||
|
xwayland = OS::get_singleton()->get_environment("XDG_SESSION_TYPE").to_lower() == "wayland";
|
||||||
|
|
||||||
native_menu = memnew(NativeMenu);
|
native_menu = memnew(NativeMenu);
|
||||||
context = p_context;
|
context = p_context;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,7 @@ class DisplayServerX11 : public DisplayServer {
|
||||||
bool xrandr_ext_ok = true;
|
bool xrandr_ext_ok = true;
|
||||||
bool xinerama_ext_ok = true;
|
bool xinerama_ext_ok = true;
|
||||||
bool xshaped_ext_ok = true;
|
bool xshaped_ext_ok = true;
|
||||||
|
bool xwayland = false;
|
||||||
|
|
||||||
struct Property {
|
struct Property {
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue