Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56000
-- v4: winewayland.drv: Implement SetWindowText winewayland.drv: Set wayland app-id from the process name
From: Gopal Prasad 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: Gopal Prasad llyyr@yukari.in --- dlls/winewayland.drv/wayland_surface.c | 3 +++ dlls/winewayland.drv/waylanddrv.h | 1 + dlls/winewayland.drv/waylanddrv_main.c | 33 ++++++++++++++++++++++++++ 3 files changed, 37 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..18d4ffd341c 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -24,11 +24,14 @@
#include "config.h"
+#include <stdlib.h> #include "ntstatus.h" #define WIN32_NO_STATUS
#include "waylanddrv.h"
+char *process_name = NULL; + static const struct user_driver_funcs waylanddrv_funcs = { .pClipCursor = WAYLAND_ClipCursor, @@ -45,12 +48,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: Gopal Prasad 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: Gopal Prasad 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 18d4ffd341c..a99a39da798 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -40,6 +40,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 */
On Wed Feb 28 21:58:34 2024 +0000, Vijay Kiran Kamuju wrote:
Real legal name in First Name and Last Name format. And fix the build errors.
done
Alexandros Frantzis (@afrantzis) commented about dlls/winewayland.drv/window.c:
/* Otherwise ensure that we have a wayland surface. */ if (!surface && !(surface = wayland_surface_create(data->hwnd))) return;
- if (surface && surface->xdg_toplevel)
The text should be set just (and only) after creating a new toplevel, a few lines below:
``` if (visible) { wayland_surface_make_toplevel(surface); --> HERE <-- } ```
You also don't need to to check `surface` (it's always non-NULL at this point).
Alexandros Frantzis (@afrantzis) commented about dlls/winewayland.drv/window.c:
}
}
+/*****************************************************************
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)
We need to protect against NULL wayland_surface * (the experimental code handled this differently).
Also please use `surface` instead of `wsurface` as the variable name (for consistency with how we ended up naming such variables in the upstream version).
```suggestion:-0+3 if (surface) { if (surface->xdg_surface) wayland_surface_set_title(surface, text); pthread_mutex_unlock(&surface->mutex); } ```
Alexandros Frantzis (@afrantzis) commented about dlls/winewayland.drv/waylanddrv_main.c:
#include "config.h"
+#include <stdlib.h>
Nit: blank line after this include to separate the include groups (unix vs win32/wine, etc).
Also not sure if `Co-authored-by` is sufficient here since I'm not really doing a whole lot in these commits anyway...
That's fine with me. You can drop `Signed-off-by` though, since Wine has stopped requiring it .
The commit message subject (after the component) should start with a capital and end with a period.
Period is still missing :)
Alexandros Frantzis (@afrantzis) commented about dlls/winewayland.drv/wayland_surface.c:
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)
Let's change this to `assert(surface->xdg_toplevel)`, i.e., make it a precondition that this function should only be called on a toplevel surfaces, since that's the only kind for which a title is relevant.