[PATCH v7 0/1] MR9868: winewayland: Fix non-square icons with xdg-toplevel-icon protocol.
Currently, it will stop the app that is running that has a non-square icon This PR fixes that -- v7: winewayland: Fix non-square icons with xdg-toplevel-icon protocol. https://gitlab.winehq.org/wine/wine/-/merge_requests/9868
From: Alex Schwartz <alexschwartz01@gmail.com> --- dlls/winewayland.drv/wayland_surface.c | 55 +++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index b0b51212ec6..a1d076f0266 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -874,6 +874,28 @@ err: return NULL; } +/*********************************************************************** + * copy_rectangle_into_center_of_square + * + * Copies non-square rectangle src to the center of square dest. + */ +static void copy_rectangle_into_center_of_square(const unsigned int *src, + int src_w, int src_h, + int square_length, + unsigned int *dest) +{ + const int off_x = (square_length - src_w) / 2; + const int off_y = (square_length - src_h) / 2; + + /* Copy the original image into the centered square */ + for (int y = 0; y < src_h; ++y) + { + const unsigned int *s = src + y * src_w; + unsigned int *d = dest + (off_y + y) * square_length + off_x; + memcpy(d, s, src_w * 4); + } +} + /*********************************************************************** * wayland_shm_buffer_from_color_bitmaps * @@ -888,14 +910,17 @@ struct wayland_shm_buffer *wayland_shm_buffer_from_color_bitmaps(HDC hdc, HBITMA char buffer[FIELD_OFFSET(BITMAPINFO, bmiColors[256])]; BITMAPINFO *info = (BITMAPINFO *)buffer; BITMAP bm; - unsigned int *ptr, *bits = NULL; + unsigned int *ptr, *bits = NULL, *non_square_bits; unsigned char *mask_bits = NULL; - int i, j; + int i, j, square_length; BOOL has_alpha = FALSE; if (!NtGdiExtGetObjectW(color, sizeof(bm), &bm)) goto failed; - shm_buffer = wayland_shm_buffer_create(bm.bmWidth, bm.bmHeight, + /* Make the buffer square - length is the larger side */ + square_length = (bm.bmWidth > bm.bmHeight) ? bm.bmWidth : bm.bmHeight; + + shm_buffer = wayland_shm_buffer_create(square_length, square_length, WL_SHM_FORMAT_ARGB8888); if (!shm_buffer) goto failed; bits = shm_buffer->map_data; @@ -912,9 +937,27 @@ struct wayland_shm_buffer *wayland_shm_buffer_from_color_bitmaps(HDC hdc, HBITMA info->bmiHeader.biClrUsed = 0; info->bmiHeader.biClrImportant = 0; - if (!NtGdiGetDIBitsInternal(hdc, color, 0, bm.bmHeight, bits, info, - DIB_RGB_COLORS, 0, 0)) - goto failed; + if (bm.bmWidth == bm.bmHeight) + { + if (!NtGdiGetDIBitsInternal(hdc, color, 0, bm.bmHeight, bits, info, + DIB_RGB_COLORS, 0, 0)) + goto failed; + } + else + { + if (!(non_square_bits = malloc(bm.bmWidth * bm.bmHeight * 4))) goto failed; + + if (!NtGdiGetDIBitsInternal(hdc, color, 0, bm.bmHeight, non_square_bits, info, + DIB_RGB_COLORS, 0, 0)) + { + free(non_square_bits); + goto failed; + } + + copy_rectangle_into_center_of_square(non_square_bits, bm.bmWidth, bm.bmHeight, square_length, bits); + + free(non_square_bits); + } for (i = 0; i < bm.bmWidth * bm.bmHeight; i++) if ((has_alpha = (bits[i] & 0xff000000) != 0)) break; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9868
Since this function is also used for loading the cursor shm buffer, it would be better if we can keep the image rectangular for the cursor and make it square for xdg-toplevel-icon. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9868#note_126590
participants (3)
-
Alex Schwartz -
Alex Schwartz (@alexschwartz01) -
Etaash Mathamsetty (@etaash.mathamsetty)