Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56000
-- v2: winewayland.drv: Implement SetWindowText winewayland.drv: set wayland app-id from the process name
From: llyyr llyyr@yukari.in
Co-authored-by: Ryan Hendrickson ryan.hendrickson@alum.mit.edu Co-authored-by: Alexandros Frantzis alexandros.frantzis@collabora.com Signed-off-by: llyyr llyyr@yukari.in --- dlls/winewayland.drv/wayland_surface.c | 3 +++ dlls/winewayland.drv/waylanddrv.h | 1 + dlls/winewayland.drv/waylanddrv_main.c | 32 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+)
diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index a955f3688c5..c43ef7f8748 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -253,6 +253,9 @@ void wayland_surface_make_toplevel(struct wayland_surface *surface) if (!surface->xdg_toplevel) goto err; xdg_toplevel_add_listener(surface->xdg_toplevel, &xdg_toplevel_listener, surface->hwnd);
+ if (process_name) + xdg_toplevel_set_app_id(surface->xdg_toplevel, process_name); + wl_surface_commit(surface->wl_surface); wl_display_flush(process_wayland.wl_display);
diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index f030f6fc6a0..6359142300a 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -51,6 +51,7 @@ * Globals */
+extern char *process_name; extern struct wayland process_wayland;
/********************************************************************** diff --git a/dlls/winewayland.drv/waylanddrv_main.c b/dlls/winewayland.drv/waylanddrv_main.c index b60d282aacb..dfdf3ed59ec 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -29,6 +29,8 @@
#include "waylanddrv.h"
+char *process_name = NULL; + static const struct user_driver_funcs waylanddrv_funcs = { .pClipCursor = WAYLAND_ClipCursor, @@ -45,12 +47,42 @@ static const struct user_driver_funcs waylanddrv_funcs = .pwine_get_vulkan_driver = WAYLAND_wine_get_vulkan_driver, };
+static void wayland_init_process_name(void) +{ + WCHAR *p, *appname; + WCHAR appname_lower[MAX_PATH]; + DWORD appname_len; + DWORD appnamez_size; + DWORD utf8_size; + int i; + + appname = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer; + if ((p = wcsrchr(appname, '/'))) appname = p + 1; + if ((p = wcsrchr(appname, '\'))) appname = p + 1; + appname_len = lstrlenW(appname); + + if (appname_len == 0 || appname_len >= MAX_PATH) return; + + for (i = 0; appname[i]; i++) appname_lower[i] = RtlDowncaseUnicodeChar(appname[i]); + appname_lower[i] = 0; + + appnamez_size = (appname_len + 1) * sizeof(WCHAR); + + if (!RtlUnicodeToUTF8N(NULL, 0, &utf8_size, appname_lower, appnamez_size) && + (process_name = malloc(utf8_size))) + { + RtlUnicodeToUTF8N(process_name, utf8_size, &utf8_size, appname_lower, appnamez_size); + } +} + static NTSTATUS waylanddrv_unix_init(void *arg) { /* Set the user driver functions now so that they are available during * our initialization. We clear them on error. */ __wine_set_user_driver(&waylanddrv_funcs, WINE_GDI_DRIVER_VERSION);
+ wayland_init_process_name(); + if (!wayland_process_init()) goto err;
return 0;
From: llyyr llyyr@yukari.in
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56000
Co-authored-by: Alexandros Frantzis alexandros.frantzis@collabora.com Signed-off-by: llyyr llyyr@yukari.in --- dlls/winewayland.drv/wayland_surface.c | 27 ++++++++++++++++++++++++++ dlls/winewayland.drv/waylanddrv.h | 2 ++ dlls/winewayland.drv/waylanddrv_main.c | 1 + dlls/winewayland.drv/window.c | 24 +++++++++++++++++++++++ 4 files changed, 54 insertions(+)
diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index c43ef7f8748..876aa9af934 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -900,3 +900,30 @@ void wayland_surface_ensure_contents(struct wayland_surface *surface)
if (damage) NtGdiDeleteObjectApp(damage); } + +/********************************************************************** + * wayland_surface_set_title + */ +void wayland_surface_set_title(struct wayland_surface *surface, LPCWSTR text) +{ + DWORD text_len; + DWORD utf8_count; + char *utf8 = NULL; + + if (!surface->xdg_toplevel) + return; + + TRACE("surface=%p hwnd=%p text='%s'\n", + surface, surface->hwnd, wine_dbgstr_w(text)); + + text_len = (lstrlenW(text) + 1) * sizeof(WCHAR); + + if (!RtlUnicodeToUTF8N(NULL, 0, &utf8_count, text, text_len) && + (utf8 = malloc(utf8_count))) + { + RtlUnicodeToUTF8N(utf8, utf8_count, &utf8_count, text, text_len); + xdg_toplevel_set_title(surface->xdg_toplevel, utf8); + } + + free(utf8); +} diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 6359142300a..0496b23fd5d 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -257,6 +257,7 @@ void wayland_surface_coords_to_window(struct wayland_surface *surface, struct wayland_client_surface *wayland_surface_get_client(struct wayland_surface *surface); BOOL wayland_client_surface_release(struct wayland_client_surface *client); void wayland_surface_ensure_contents(struct wayland_surface *surface); +void wayland_surface_set_title(struct wayland_surface *surface, LPCWSTR title);
/********************************************************************** * Wayland SHM buffer @@ -321,6 +322,7 @@ BOOL WAYLAND_ClipCursor(const RECT *clip, BOOL reset); LRESULT WAYLAND_DesktopWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); void WAYLAND_DestroyWindow(HWND hwnd); void WAYLAND_SetCursor(HWND hwnd, HCURSOR hcursor); +void WAYLAND_SetWindowText(HWND hwnd, LPCWSTR text); LRESULT WAYLAND_SysCommand(HWND hwnd, WPARAM wparam, LPARAM lparam); BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manager, BOOL force, void *param); diff --git a/dlls/winewayland.drv/waylanddrv_main.c b/dlls/winewayland.drv/waylanddrv_main.c index dfdf3ed59ec..c49ec96e727 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -39,6 +39,7 @@ static const struct user_driver_funcs waylanddrv_funcs = .pKbdLayerDescriptor = WAYLAND_KbdLayerDescriptor, .pReleaseKbdTables = WAYLAND_ReleaseKbdTables, .pSetCursor = WAYLAND_SetCursor, + .pSetWindowText = WAYLAND_SetWindowText, .pSysCommand = WAYLAND_SysCommand, .pUpdateDisplayDevices = WAYLAND_UpdateDisplayDevices, .pWindowMessage = WAYLAND_WindowMessage, diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c index ac5da371e5c..cc729cce363 100644 --- a/dlls/winewayland.drv/window.c +++ b/dlls/winewayland.drv/window.c @@ -211,6 +211,15 @@ static void wayland_win_data_update_wayland_surface(struct wayland_win_data *dat /* Otherwise ensure that we have a wayland surface. */ if (!surface && !(surface = wayland_surface_create(data->hwnd))) return;
+ + if (surface && surface->xdg_toplevel) + { + WCHAR text[1024]; + if (!NtUserInternalGetWindowText(data->hwnd, text, ARRAY_SIZE(text))) + text[0] = 0; + wayland_surface_set_title(surface, text); + } + visible = (NtUserGetWindowLongW(data->hwnd, GWL_STYLE) & WS_VISIBLE) == WS_VISIBLE; xdg_visible = surface->xdg_toplevel != NULL;
@@ -668,6 +677,21 @@ static enum xdg_toplevel_resize_edge hittest_to_resize_edge(WPARAM hittest) } }
+/***************************************************************** + * WAYLAND_SetWindowText + */ +void WAYLAND_SetWindowText(HWND hwnd, LPCWSTR text) +{ + struct wayland_surface *wsurface = wayland_surface_lock_hwnd(hwnd); + + TRACE("hwnd=%p text=%s\n", hwnd, wine_dbgstr_w(text)); + + if (wsurface && wsurface->xdg_toplevel) + wayland_surface_set_title(wsurface, text); + + pthread_mutex_unlock(&wsurface->mutex); +} + /*********************************************************************** * WAYLAND_SysCommand */
The `app_id` is used mainly for broad identification and grouping purposes.
Ah that was my intention. There's no way to identify a winewayland window without the app-id on compositors like sway. I misread the bug report. But it's trivial anyway so I'll copypaste the SetWindowText commit as well.
- Since the process name doesn't change during runtime, I would suggest initializing it just once during startup and making it available to the whole process (i.e., sticking to what the experimental branch and winex11 are doing).
- The commit message subject (after the component) should start with a capital and end with a period.
Changed.
Also not sure if `Co-authored-by` is sufficient here since I'm not really doing a whole lot in these commits anyway...
Please use your real name to sign off the patches, otherwise it is very difficult to get this merged.
On Wed Feb 28 19:46:45 2024 +0000, Vijay Kiran Kamuju wrote:
Please use your real name to sign off the patches, otherwise it is very difficult to get this merged.
Do you need my legal name or does it just need to be in a FirstName LastName format?
Either way, as mentioned above these commits are really just rebases of @afrantzis's branch. So they can't really be considered authored by me, I'm perfectly fine with it being committed and signed off by him.