Merge pull request #21460 from hpvb/fix-19716
When setting an X11 icon fails, try halving the size
This commit is contained in:
commit
3c0ea513de
@ -2628,16 +2628,50 @@ void OS_X11::alert(const String &p_alert, const String &p_title) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool g_set_icon_error = false;
|
||||
int set_icon_errorhandler(Display *dpy, XErrorEvent *ev) {
|
||||
g_set_icon_error = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OS_X11::set_icon(const Ref<Image> &p_icon) {
|
||||
int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&set_icon_errorhandler);
|
||||
|
||||
Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
|
||||
|
||||
if (p_icon.is_valid()) {
|
||||
Ref<Image> img = p_icon->duplicate();
|
||||
img->convert(Image::FORMAT_RGBA8);
|
||||
|
||||
while (true) {
|
||||
int w = img->get_width();
|
||||
int h = img->get_height();
|
||||
|
||||
if (g_set_icon_error) {
|
||||
g_set_icon_error = false;
|
||||
|
||||
WARN_PRINT("Icon too large, attempting to resize icon.");
|
||||
|
||||
int new_width, new_height;
|
||||
if (w > h) {
|
||||
new_width = w / 2;
|
||||
new_height = h * new_width / w;
|
||||
} else {
|
||||
new_height = h / 2;
|
||||
new_width = w * new_height / h;
|
||||
}
|
||||
|
||||
w = new_width;
|
||||
h = new_height;
|
||||
|
||||
if (!w || !h) {
|
||||
WARN_PRINT("Unable to set icon.");
|
||||
break;
|
||||
}
|
||||
|
||||
img->resize(w, h, Image::INTERPOLATE_CUBIC);
|
||||
}
|
||||
|
||||
// We're using long to have wordsize (32Bit build -> 32 Bits, 64 Bit build -> 64 Bits
|
||||
Vector<long> pd;
|
||||
|
||||
@ -2658,11 +2692,18 @@ void OS_X11::set_icon(const Ref<Image> &p_icon) {
|
||||
*wr++ = v;
|
||||
pr += 4;
|
||||
}
|
||||
|
||||
XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)pd.ptr(), pd.size());
|
||||
|
||||
if (!g_set_icon_error)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
XDeleteProperty(x11_display, x11_window, net_wm_icon);
|
||||
}
|
||||
|
||||
XFlush(x11_display);
|
||||
XSetErrorHandler(oldHandler);
|
||||
}
|
||||
|
||||
void OS_X11::force_process_input() {
|
||||
|
Loading…
Reference in New Issue
Block a user