This second MR in the Wayland series adds display configuration related enhancements, including providing more display information (like a proper/consistent name and position) to Wine and supporting GetCurrentDisplaySettings.
To get additional information from the Wayland compositor we need to use a protocol from the wayland-protocols collection, so we introduce support in the build system for protocol .xml files. These changes are introduced on their own commit in the series, but we can squash it with the next commit, where the functionality is first used, if preferred.
To be able to provide a consistent view of the display settings across all processes, this MR leverages the win32u CURRENT_SETTINGS storage mechanism (which was previously used only in the null driver).
Thanks!
-- v5: winewayland.drv: Infer and report Windows monitor positions. winewayland.drv: Use the output name reported by the compositor. tools: Support building Wayland protocol source files. winewayland.drv: Handle wl_output objects only in the desktop process. winewayland.drv: Support GetCurrentDisplaySettings. win32u: Support setting the registry mode using gdi_device_manager.
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Update the gdi_device_manager API to enable drivers to set the registry mode (if not already set) in UpdateDisplayDevices.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/win32u/sysparams.c | 13 +++- dlls/wineandroid.drv/init.c | 2 +- dlls/winemac.drv/display.c | 115 +++++++++++++++------------------ dlls/winewayland.drv/display.c | 10 ++- dlls/winex11.drv/display.c | 50 ++++---------- dlls/winex11.drv/x11drv.h | 1 - dlls/winex11.drv/xrandr.c | 1 - include/wine/gdi_driver.h | 5 +- 8 files changed, 87 insertions(+), 110 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 60b12321953..2c423e2fe45 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -1482,7 +1482,7 @@ static void add_monitor( const struct gdi_monitor *monitor, void *param ) if (hkey) NtClose( hkey ); }
-static void add_mode( const DEVMODEW *mode, void *param ) +static void add_mode( const DEVMODEW *mode, DWORD target, void *param ) { struct device_manager_ctx *ctx = param;
@@ -1496,7 +1496,14 @@ static void add_mode( const DEVMODEW *mode, void *param ) add_adapter( &default_adapter, ctx ); }
- if (write_adapter_mode( ctx->adapter_key, ctx->mode_count, mode )) + if (target == GDI_MODE_REGISTRY_IF_EMPTY) + { + DEVMODEW stored = {.dmSize = sizeof(DEVMODEW)}; + if (!read_adapter_mode( ctx->adapter_key, ENUM_REGISTRY_SETTINGS, &stored )) + write_adapter_mode( ctx->adapter_key, ENUM_REGISTRY_SETTINGS, mode ); + } + else if (target == GDI_MODE_NEXT && + write_adapter_mode( ctx->adapter_key, ctx->mode_count, mode )) { ctx->mode_count++; set_reg_value( ctx->adapter_key, mode_countW, REG_DWORD, &ctx->mode_count, sizeof(ctx->mode_count) ); @@ -1690,7 +1697,7 @@ static BOOL update_display_cache( BOOL force ) monitor.rc_work.bottom = mode.dmPelsHeight;
add_monitor( &monitor, &ctx ); - for (i = 0; i < ARRAY_SIZE(modes); ++i) add_mode( modes + i, &ctx ); + for (i = 0; i < ARRAY_SIZE(modes); ++i) add_mode( modes + i, GDI_MODE_NEXT, &ctx ); } release_display_manager_ctx( &ctx );
diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index 074aa6c6257..09425ae8659 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -295,7 +295,7 @@ BOOL ANDROID_UpdateDisplayDevices( const struct gdi_device_manager *device_manag device_manager->add_gpu( &gpu, param ); device_manager->add_adapter( &adapter, param ); device_manager->add_monitor( &gdi_monitor, param ); - device_manager->add_mode( &mode, param ); + device_manager->add_mode( &mode, GDI_MODE_NEXT, param ); force_display_devices_refresh = FALSE; }
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index 6a798994e47..7d91557d77c 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -864,6 +864,33 @@ static DEVMODEW *display_get_modes(CGDirectDisplayID display_id, int *modes_coun return devmodes; }
+static void display_get_current_mode(struct macdrv_display *display, DEVMODEW *devmode) +{ + CGDisplayModeRef display_mode; + CGDirectDisplayID display_id; + + display_id = display->displayID; + display_mode = CGDisplayCopyDisplayMode(display_id); + + devmode->dmPosition.x = CGRectGetMinX(display->frame); + devmode->dmPosition.y = CGRectGetMinY(display->frame); + devmode->dmFields |= DM_POSITION; + + display_mode_to_devmode(display_id, display_mode, devmode); + if (retina_enabled) + { + struct display_mode_descriptor *desc = create_original_display_mode_descriptor(display_id); + if (display_mode_matches_descriptor(display_mode, desc)) + { + devmode->dmPelsWidth *= 2; + devmode->dmPelsHeight *= 2; + } + free_display_mode_descriptor(desc); + } + + CFRelease(display_mode); +} + /*********************************************************************** * GetCurrentDisplaySettings (MACDRV.@) * @@ -872,8 +899,6 @@ BOOL macdrv_GetCurrentDisplaySettings(LPCWSTR devname, BOOL is_primary, LPDEVMOD { struct macdrv_display *displays = NULL; int num_displays, display_idx; - CGDisplayModeRef display_mode; - CGDirectDisplayID display_id; WCHAR *end;
TRACE("%s, %u, %p + %hu\n", debugstr_w(devname), is_primary, devmode, devmode->dmSize); @@ -890,26 +915,7 @@ BOOL macdrv_GetCurrentDisplaySettings(LPCWSTR devname, BOOL is_primary, LPDEVMOD return FALSE; }
- display_id = displays[display_idx].displayID; - display_mode = CGDisplayCopyDisplayMode(display_id); - - devmode->dmPosition.x = CGRectGetMinX(displays[display_idx].frame); - devmode->dmPosition.y = CGRectGetMinY(displays[display_idx].frame); - devmode->dmFields |= DM_POSITION; - - display_mode_to_devmode(display_id, display_mode, devmode); - if (retina_enabled) - { - struct display_mode_descriptor *desc = create_original_display_mode_descriptor(display_id); - if (display_mode_matches_descriptor(display_mode, desc)) - { - devmode->dmPelsWidth *= 2; - devmode->dmPelsHeight *= 2; - } - free_display_mode_descriptor(desc); - } - - CFRelease(display_mode); + display_get_current_mode(&displays[display_idx], devmode); macdrv_free_displays(displays);
TRACE("current mode -- %dx%d-%dx%dx%dbpp @%d Hz", @@ -1070,45 +1076,6 @@ done: return (err == kCGErrorSuccess); }
-/*********************************************************************** - * init_registry_display_settings - * - * Initialize registry display settings when new display devices are added. - */ -static void init_registry_display_settings(void) -{ - DEVMODEW dm = {.dmSize = sizeof(dm)}; - DISPLAY_DEVICEW dd = {sizeof(dd)}; - UNICODE_STRING str; - DWORD i = 0; - int ret; - - while (!NtUserEnumDisplayDevices(NULL, i++, &dd, 0)) - { - RtlInitUnicodeString(&str, dd.DeviceName); - - /* Skip if the device already has registry display settings */ - if (NtUserEnumDisplaySettings(&str, ENUM_REGISTRY_SETTINGS, &dm, 0)) - continue; - - if (!NtUserEnumDisplaySettings(&str, ENUM_CURRENT_SETTINGS, &dm, 0)) - { - ERR("Failed to query current display settings for %s.\n", wine_dbgstr_w(dd.DeviceName)); - continue; - } - - TRACE("Device %s current display mode %ux%u %ubits %uHz at %d,%d.\n", - wine_dbgstr_w(dd.DeviceName), (unsigned int)dm.dmPelsWidth, (unsigned int)dm.dmPelsHeight, - (unsigned int)dm.dmBitsPerPel, (unsigned int)dm.dmDisplayFrequency, (int)dm.dmPosition.x, (int)dm.dmPosition.y); - - ret = NtUserChangeDisplaySettings(&str, &dm, NULL, - CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY, NULL); - if (ret != DISP_CHANGE_SUCCESSFUL) - ERR("Failed to save registry display settings for %s, returned %d.\n", - wine_dbgstr_w(dd.DeviceName), ret); - } -} - /*********************************************************************** * macdrv_displays_changed * @@ -1127,7 +1094,6 @@ void macdrv_displays_changed(const macdrv_event *event) NtUserGetWindowThread(hwnd, NULL) == GetCurrentThreadId()) { macdrv_init_display_devices(TRUE); - init_registry_display_settings(); macdrv_resize_desktop(); } } @@ -1139,7 +1105,8 @@ BOOL macdrv_UpdateDisplayDevices( const struct gdi_device_manager *device_manage struct macdrv_adapter *adapters, *adapter; struct macdrv_monitor *monitors, *monitor; struct macdrv_gpu *gpus, *gpu; - INT gpu_count, adapter_count, monitor_count, mode_count; + struct macdrv_display *displays, *display; + INT gpu_count, adapter_count, monitor_count, mode_count, display_count; DEVMODEW *mode, *modes; DWORD len;
@@ -1205,11 +1172,31 @@ BOOL macdrv_UpdateDisplayDevices( const struct gdi_device_manager *device_manage (int)mode->dmBitsPerPel, (int)mode->dmDisplayFrequency, mode->dmDisplayFixedOutput == DMDFO_STRETCH ? "" : "un", mode->dmDisplayFlags & DM_INTERLACED ? "" : "non-"); - device_manager->add_mode( mode, param ); + device_manager->add_mode( mode, GDI_MODE_NEXT, param ); }
free(modes); macdrv_free_monitors(monitors); + + if (macdrv_get_displays(&displays, &display_count)) break; + + /* Initialize registry mode */ + for (display = displays; display < displays + display_count; display++) + { + if (display->displayID == adapter->id) + { + DEVMODEW current_mode = { .dmSize = sizeof(current_mode) }; + display_get_current_mode(display, ¤t_mode); + TRACE("current mode: %ux%u %ubits %uHz at %d,%d.\n", + (int)current_mode.dmPelsWidth, (int)current_mode.dmPelsHeight, + (int)current_mode.dmBitsPerPel, (int)current_mode.dmDisplayFrequency, + (int)current_mode.dmPosition.x, (int)current_mode.dmPosition.y); + device_manager->add_mode(¤t_mode, GDI_MODE_REGISTRY_IF_EMPTY, param); + break; + } + } + + macdrv_free_displays(displays); }
macdrv_free_adapters(adapters); diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index e72b26a9da0..b3f875dd8af 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -121,13 +121,19 @@ static void wayland_add_device_modes(const struct gdi_device_manager *device_man void *param, struct wayland_output *output) { struct wayland_output_mode *output_mode; + DEVMODEW mode = {.dmSize = sizeof(mode)};
RB_FOR_EACH_ENTRY(output_mode, &output->modes, struct wayland_output_mode, entry) { - DEVMODEW mode; populate_devmode(output_mode, &mode); - device_manager->add_mode(&mode, param); + device_manager->add_mode(&mode, GDI_MODE_NEXT, param); } + + populate_devmode(output->current_mode, &mode); + mode.dmFields |= DM_POSITION; + mode.dmPosition.x = 0; + mode.dmPosition.y = 0; + device_manager->add_mode(&mode, GDI_MODE_REGISTRY_IF_EMPTY, param); }
/*********************************************************************** diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c index 78de6a6f88b..6cf4a8da0ba 100644 --- a/dlls/winex11.drv/display.c +++ b/dlls/winex11.drv/display.c @@ -156,41 +156,6 @@ void X11DRV_Settings_Init(void) X11DRV_Settings_SetHandler(&nores_handler); }
-/* Initialize registry display settings when new display devices are added */ -void init_registry_display_settings(void) -{ - DEVMODEW dm = {.dmSize = sizeof(dm)}; - DISPLAY_DEVICEW dd = {sizeof(dd)}; - UNICODE_STRING device_name; - DWORD i = 0; - int ret; - - while (!NtUserEnumDisplayDevices( NULL, i++, &dd, 0 )) - { - RtlInitUnicodeString( &device_name, dd.DeviceName ); - - /* Skip if the device already has registry display settings */ - if (NtUserEnumDisplaySettings( &device_name, ENUM_REGISTRY_SETTINGS, &dm, 0 )) - continue; - - if (!NtUserEnumDisplaySettings( &device_name, ENUM_CURRENT_SETTINGS, &dm, 0 )) - { - ERR("Failed to query current display settings for %s.\n", wine_dbgstr_w(dd.DeviceName)); - continue; - } - - TRACE("Device %s current display mode %ux%u %ubits %uHz at %d,%d.\n", - wine_dbgstr_w(dd.DeviceName), (int)dm.dmPelsWidth, (int)dm.dmPelsHeight, - (int)dm.dmBitsPerPel, (int)dm.dmDisplayFrequency, (int)dm.dmPosition.x, (int)dm.dmPosition.y); - - ret = NtUserChangeDisplaySettings( &device_name, &dm, NULL, - CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY, NULL ); - if (ret != DISP_CHANGE_SUCCESSFUL) - ERR("Failed to save registry display settings for %s, returned %d.\n", - wine_dbgstr_w(dd.DeviceName), ret); - } -} - static void set_display_depth(ULONG_PTR display_id, DWORD depth) { struct x11drv_display_depth *display_depth; @@ -559,7 +524,7 @@ BOOL X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manage struct gdi_gpu *gpus; INT gpu_count, adapter_count, monitor_count; INT gpu, adapter, monitor; - DEVMODEW *modes, *mode; + DEVMODEW *modes, *mode, current_mode; UINT mode_count;
if (!force && !force_display_devices_refresh) return TRUE; @@ -599,11 +564,22 @@ BOOL X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manage for (mode = modes; mode_count; mode_count--) { TRACE( "mode: %p\n", mode ); - device_manager->add_mode( mode, param ); + device_manager->add_mode( mode, GDI_MODE_NEXT, param ); mode = (DEVMODEW *)((char *)mode + sizeof(*modes) + modes[0].dmDriverExtra); }
settings_handler.free_modes( modes ); + + memset( ¤t_mode, 0, sizeof(current_mode) ); + current_mode.dmSize = sizeof(current_mode); + if (settings_handler.get_current_mode( adapters[adapter].id, ¤t_mode )) + { + TRACE("current mode: %ux%u %ubits %uHz at %d,%d.\n", + (int)current_mode.dmPelsWidth, (int)current_mode.dmPelsHeight, + (int)current_mode.dmBitsPerPel, (int)current_mode.dmDisplayFrequency, + (int)current_mode.dmPosition.x, (int)current_mode.dmPosition.y); + device_manager->add_mode( ¤t_mode, GDI_MODE_REGISTRY_IF_EMPTY, param ); + } }
handler->free_adapters(adapters); diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index c6328cf3fde..f3ca8f0cbb2 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -758,7 +758,6 @@ extern void X11DRV_Settings_SetHandler(const struct x11drv_settings_handler *han
extern void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height ) DECLSPEC_HIDDEN; extern void X11DRV_resize_desktop(void) DECLSPEC_HIDDEN; -extern void init_registry_display_settings(void) DECLSPEC_HIDDEN; extern BOOL is_virtual_desktop(void) DECLSPEC_HIDDEN; extern BOOL is_desktop_fullscreen(void) DECLSPEC_HIDDEN; extern BOOL is_detached_mode(const DEVMODEW *) DECLSPEC_HIDDEN; diff --git a/dlls/winex11.drv/xrandr.c b/dlls/winex11.drv/xrandr.c index 7c32e683c5d..3731ca6b4d0 100644 --- a/dlls/winex11.drv/xrandr.c +++ b/dlls/winex11.drv/xrandr.c @@ -1188,7 +1188,6 @@ static BOOL xrandr14_device_change_handler( HWND hwnd, XEvent *event ) if (hwnd == NtUserGetDesktopWindow() && NtUserGetWindowThread( hwnd, NULL ) == GetCurrentThreadId()) { X11DRV_DisplayDevices_Init( TRUE ); - init_registry_display_settings(); X11DRV_resize_desktop(); } /* Update xinerama monitors for xinerama_get_fullscreen_monitors() */ diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h index c492252d4ab..53607bbcc4b 100644 --- a/include/wine/gdi_driver.h +++ b/include/wine/gdi_driver.h @@ -261,12 +261,15 @@ struct gdi_monitor UINT edid_len; };
+#define GDI_MODE_NEXT 0 +#define GDI_MODE_REGISTRY_IF_EMPTY 1 + struct gdi_device_manager { void (*add_gpu)( const struct gdi_gpu *gpu, void *param ); void (*add_adapter)( const struct gdi_adapter *adapter, void *param ); void (*add_monitor)( const struct gdi_monitor *monitor, void *param ); - void (*add_mode)( const DEVMODEW *mode, void *param ); + void (*add_mode)( const DEVMODEW *mode, DWORD target, void *param ); };
#define WINE_DM_UNSUPPORTED 0x80000000
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Provide current mode information through the gdi_device_manager and let win32u manage the current display settings.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/win32u/sysparams.c | 4 ++++ dlls/winewayland.drv/display.c | 12 ++++++++++++ dlls/winewayland.drv/waylanddrv.h | 2 ++ dlls/winewayland.drv/waylanddrv_main.c | 1 + include/wine/gdi_driver.h | 1 + 5 files changed, 20 insertions(+)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 2c423e2fe45..5b720a817d3 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -1502,6 +1502,10 @@ static void add_mode( const DEVMODEW *mode, DWORD target, void *param ) if (!read_adapter_mode( ctx->adapter_key, ENUM_REGISTRY_SETTINGS, &stored )) write_adapter_mode( ctx->adapter_key, ENUM_REGISTRY_SETTINGS, mode ); } + else if (target == GDI_MODE_CURRENT) + { + write_adapter_mode( ctx->adapter_key, ENUM_CURRENT_SETTINGS, mode ); + } else if (target == GDI_MODE_NEXT && write_adapter_mode( ctx->adapter_key, ctx->mode_count, mode )) { diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index b3f875dd8af..cd009c54a7a 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -134,6 +134,7 @@ static void wayland_add_device_modes(const struct gdi_device_manager *device_man mode.dmPosition.x = 0; mode.dmPosition.y = 0; device_manager->add_mode(&mode, GDI_MODE_REGISTRY_IF_EMPTY, param); + device_manager->add_mode(&mode, GDI_MODE_CURRENT, param); }
/*********************************************************************** @@ -164,3 +165,14 @@ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manage
return TRUE; } + +/*********************************************************************** + * GetCurrentDisplaySettings (WAYLAND.@) + * + */ +BOOL WAYLAND_GetCurrentDisplaySettings(LPCWSTR name, BOOL is_primary, LPDEVMODEW devmode) +{ + /* We provide current mode information through the gdi_device_manager and + * let win32u manage the current display settings. */ + return FALSE; +} diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 8458ed17df2..941b4672d0d 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -88,6 +88,8 @@ void wayland_output_destroy(struct wayland_output *output) DECLSPEC_HIDDEN; * USER driver functions */
+BOOL WAYLAND_GetCurrentDisplaySettings(LPCWSTR name, BOOL is_primary, + LPDEVMODEW devmode) DECLSPEC_HIDDEN; BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manager, BOOL force, void *param) DECLSPEC_HIDDEN;
diff --git a/dlls/winewayland.drv/waylanddrv_main.c b/dlls/winewayland.drv/waylanddrv_main.c index a9297edc500..35e7ecd3a6d 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -31,6 +31,7 @@
static const struct user_driver_funcs waylanddrv_funcs = { + .pGetCurrentDisplaySettings = WAYLAND_GetCurrentDisplaySettings, .pUpdateDisplayDevices = WAYLAND_UpdateDisplayDevices, };
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h index 53607bbcc4b..38fb01fe953 100644 --- a/include/wine/gdi_driver.h +++ b/include/wine/gdi_driver.h @@ -263,6 +263,7 @@ struct gdi_monitor
#define GDI_MODE_NEXT 0 #define GDI_MODE_REGISTRY_IF_EMPTY 1 +#define GDI_MODE_CURRENT 2
struct gdi_device_manager {
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Since non-desktop processes rely on the win32u internal current settings handling to get display information, they don't need to access wl_output objects themselves for now.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/display.c | 15 ++++----------- dlls/winewayland.drv/wayland.c | 3 +++ dlls/winewayland.drv/waylanddrv.h | 6 ++++++ dlls/winewayland.drv/waylanddrv_main.c | 25 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index cd009c54a7a..adf981d92e6 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -44,16 +44,7 @@ static void wayland_refresh_display_devices(void)
void wayland_init_display_devices(void) { - struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); - DWORD current_pid = GetCurrentProcessId(); - HWND desktop_hwnd = UlongToHandle(thread_info->top_window); - DWORD desktop_pid = 0; - - if (desktop_hwnd) NtUserGetWindowThread(desktop_hwnd, &desktop_pid); - - /* Refresh devices only from the desktop window process. */ - if (!desktop_pid || current_pid == desktop_pid) - wayland_refresh_display_devices(); + wayland_refresh_display_devices(); }
static void wayland_add_device_gpu(const struct gdi_device_manager *device_manager, @@ -146,7 +137,9 @@ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manage struct wayland_output *output; INT output_id = 0;
- if (!force && !force_display_devices_refresh) return TRUE; + /* For now, update the display devices only when a compositor side update + * is received in the desktop window process. */ + if (!force_display_devices_refresh) return TRUE;
TRACE("force=%d force_refresh=%d\n", force, force_display_devices_refresh);
diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index 104a091ea80..2f728355438 100644 --- a/dlls/winewayland.drv/wayland.c +++ b/dlls/winewayland.drv/wayland.c @@ -45,6 +45,9 @@ static void registry_handle_global(void *data, struct wl_registry *registry, { TRACE("interface=%s version=%u id=%u\n", interface, version, id);
+ /* For now only the desktop process needs wl_output objects. */ + if (GetCurrentProcessId() != get_desktop_process_id()) return; + if (strcmp(interface, "wl_output") == 0) { if (!wayland_output_create(id, version)) diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 941b4672d0d..77797c005c2 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -84,6 +84,12 @@ void wayland_init_display_devices(void) DECLSPEC_HIDDEN; BOOL wayland_output_create(uint32_t id, uint32_t version) DECLSPEC_HIDDEN; void wayland_output_destroy(struct wayland_output *output) DECLSPEC_HIDDEN;
+/********************************************************************** + * USER32 helpers + */ + +DWORD get_desktop_process_id(void) DECLSPEC_HIDDEN; + /********************************************************************** * USER driver functions */ diff --git a/dlls/winewayland.drv/waylanddrv_main.c b/dlls/winewayland.drv/waylanddrv_main.c index 35e7ecd3a6d..ec7efef9366 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -27,8 +27,33 @@ #include "ntstatus.h" #define WIN32_NO_STATUS
+#include "wine/server.h" + #include "waylanddrv.h"
+DWORD get_desktop_process_id(void) +{ + struct ntuser_thread_info *thread_info = NtUserGetThreadInfo(); + HWND desktop_hwnd = UlongToHandle(thread_info->top_window); + DWORD desktop_pid; + + /* The thread information may not have been updated yet, so also query + * the server directly to be certain. */ + if (!desktop_hwnd) + { + SERVER_START_REQ(get_desktop_window) + { + req->force = 0; + if (!wine_server_call(req)) + desktop_hwnd = UlongToHandle(reply->top_window); + } + SERVER_END_REQ; + } + + return NtUserGetWindowThread(desktop_hwnd, &desktop_pid) ? + desktop_pid : GetCurrentProcessId(); +} + static const struct user_driver_funcs waylanddrv_funcs = { .pGetCurrentDisplaySettings = WAYLAND_GetCurrentDisplaySettings,
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Wayland protocol descriptions are distributed as source XML files that need to be transformed to C source and header files with a version of the wayland-scanner tool compatible with the used libwayland library.
This commit enhances the makedep build tool to support building such Wayland protocol XML files. Components can use the WAYLAND_PROTOCOL_SRCS build variable to add protocol XML files to their build.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- tools/makedep.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/tools/makedep.c b/tools/makedep.c index 49a7514c9f0..8f7c7389526 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -100,6 +100,7 @@ struct incl_file #define FLAG_C_IMPLIB 0x040000 /* file is part of an import library */ #define FLAG_C_UNIX 0x080000 /* file is part of a Unix library */ #define FLAG_SFD_FONTS 0x100000 /* sfd file generated bitmap fonts */ +#define FLAG_WAYLAND_PROTO 0x200000 /* generates wayland protocol .c/.h files */
static const struct { @@ -157,6 +158,7 @@ static const char *icotool; static const char *msgfmt; static const char *ln_s; static const char *sed_cmd; +static const char *wayland_scanner; /* per-architecture global variables */ static const char *arch_dirs[MAX_ARCHS]; static const char *arch_pe_dirs[MAX_ARCHS]; @@ -1176,6 +1178,25 @@ static void parse_sfd_file( struct file *source, FILE *file ) }
+/******************************************************************* + * parse_xml_file + */ +static void parse_xml_file( struct file *source, FILE *file ) +{ + char *buffer; + + input_line = 0; + while ((buffer = get_line( file ))) + { + if (strstr( buffer, "<protocol name=" )) + { + source->flags |= FLAG_WAYLAND_PROTO; + break; + } + } +} + + static const struct { const char *ext; @@ -1193,7 +1214,8 @@ static const struct { ".idl", parse_idl_file }, { ".rc", parse_rc_file }, { ".in", parse_in_file }, - { ".sfd", parse_sfd_file } + { ".sfd", parse_sfd_file }, + { ".xml", parse_xml_file } };
/******************************************************************* @@ -1428,6 +1450,7 @@ static struct file *open_include_file( const struct makefile *make, struct incl_ if ((file = open_local_generated_file( make, pFile, ".cur", ".svg" ))) return file; if ((file = open_local_generated_file( make, pFile, ".ico", ".svg" ))) return file; } + if ((file = open_local_generated_file( make, pFile, "-client-protocol.h", ".xml" ))) return file;
/* check for extra targets */ if (strarray_exists( &make->extra_targets, pFile->name )) @@ -1915,6 +1938,21 @@ static void add_generated_sources( struct makefile *make ) strarray_addall_uniq( &make->extra_imports, get_expanded_file_local_var( make, obj, "IMPORTS" )); } + if (source->file->flags & FLAG_WAYLAND_PROTO) + { + char *code_name = replace_extension ( source->name , ".xml", "-protocol.c" ); + char *header_name = replace_extension ( source->name , ".xml", "-client-protocol.h" ); + + file = add_generated_source( make, code_name, NULL, 0 ); + file->file->flags |= FLAG_C_UNIX; + file->use_msvcrt = 0; + file = add_generated_source( make, header_name, NULL, 0 ); + file->file->flags |= FLAG_C_UNIX; + file->use_msvcrt = 0; + + free( code_name ); + free( header_name ); + } } if (make->testdll) { @@ -3101,6 +3139,16 @@ static void output_source_spec( struct makefile *make, struct incl_file *source, } }
+static void output_source_xml( struct makefile *make, struct incl_file *source, const char *obj ) +{ + if ((source->file->flags & FLAG_WAYLAND_PROTO) && wayland_scanner) + { + output( "%s-protocol.c: %s\n", obj_dir_path( make, obj ), source->filename ); + output( "\t%s%s private-code $< $@\n", cmd_prefix( "WAYLAND_SCANNER" ), wayland_scanner ); + output( "%s-client-protocol.h: %s\n", obj_dir_path( make, obj ), source->filename ); + output( "\t%s%s client-header $< $@\n", cmd_prefix( "WAYLAND_SCANNER" ), wayland_scanner); + } +}
/******************************************************************* * output_source_one_arch @@ -3240,6 +3288,7 @@ static const struct { "in", output_source_in }, { "x", output_source_x }, { "spec", output_source_spec }, + { "xml", output_source_xml }, { NULL, output_source_default } };
@@ -4054,6 +4103,7 @@ static void output_silent_rules(void) "MSG", "SED", "TEST", + "WAYLAND_SCANNER", "WIDL", "WMC", "WRC" @@ -4153,6 +4203,7 @@ static void load_sources( struct makefile *make ) "IN_SRCS", "PO_SRCS", "MANPAGES", + "WAYLAND_PROTOCOL_SRCS", NULL }; const char **var; @@ -4383,6 +4434,7 @@ int main( int argc, char *argv[] ) msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" ); sed_cmd = get_expanded_make_variable( top_makefile, "SED_CMD" ); ln_s = get_expanded_make_variable( top_makefile, "LN_S" ); + wayland_scanner = get_expanded_make_variable( top_makefile, "WAYLAND_SCANNER" );
if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL; if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Use the xdg-output-unstable-v1 protocol to get a unique, cross-process consistent name for the outputs.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- configure | 50 +++- configure.ac | 4 +- dlls/winewayland.drv/Makefile.in | 3 + dlls/winewayland.drv/wayland.c | 12 + dlls/winewayland.drv/wayland_output.c | 111 ++++++++- dlls/winewayland.drv/waylanddrv.h | 6 +- .../xdg-output-unstable-v1.xml | 220 ++++++++++++++++++ 7 files changed, 392 insertions(+), 14 deletions(-) create mode 100644 dlls/winewayland.drv/xdg-output-unstable-v1.xml
diff --git a/configure b/configure index 05dda03659c..d1c35420bae 100755 --- a/configure +++ b/configure @@ -702,6 +702,7 @@ INOTIFY_LIBS INOTIFY_CFLAGS PCSCLITE_LIBS PCAP_LIBS +WAYLAND_SCANNER WAYLAND_CLIENT_LIBS WAYLAND_CLIENT_CFLAGS X_EXTRA_LIBS @@ -15641,8 +15642,54 @@ fi
CPPFLAGS=$ac_save_CPPFLAGS
+ # Extract the first word of "wayland-scanner", so it can be a program name with args. +set dummy wayland-scanner; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_WAYLAND_SCANNER+y} +then : + printf %s "(cached) " >&6 +else $as_nop + case $WAYLAND_SCANNER in + [\/]* | ?:[\/]*) + ac_cv_path_WAYLAND_SCANNER="$WAYLAND_SCANNER" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_WAYLAND_SCANNER="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_WAYLAND_SCANNER" && ac_cv_path_WAYLAND_SCANNER="`test -n "$PKG_CONFIG" && $PKG_CONFIG --variable=wayland_scanner wayland-scanner`" + ;; +esac +fi +WAYLAND_SCANNER=$ac_cv_path_WAYLAND_SCANNER +if test -n "$WAYLAND_SCANNER"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $WAYLAND_SCANNER" >&5 +printf "%s\n" "$WAYLAND_SCANNER" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + fi -if test -z "$WAYLAND_CLIENT_LIBS" +if test -z "$WAYLAND_CLIENT_LIBS" -o -z "$WAYLAND_SCANNER" then : case "x$with_wayland" in x) as_fn_append wine_notices "|Wayland ${notice_platform}development files not found, the Wayland driver won't be supported." ;; @@ -23150,6 +23197,7 @@ X_LIBS = $X_LIBS X_EXTRA_LIBS = $X_EXTRA_LIBS WAYLAND_CLIENT_CFLAGS = $WAYLAND_CLIENT_CFLAGS WAYLAND_CLIENT_LIBS = $WAYLAND_CLIENT_LIBS +WAYLAND_SCANNER = $WAYLAND_SCANNER PCAP_LIBS = $PCAP_LIBS PCSCLITE_LIBS = $PCSCLITE_LIBS INOTIFY_CFLAGS = $INOTIFY_CFLAGS diff --git a/configure.ac b/configure.ac index 9e0e86b6704..1568f8ab4a0 100644 --- a/configure.ac +++ b/configure.ac @@ -1342,8 +1342,10 @@ then [AC_CHECK_HEADERS([wayland-client.h]) AC_CHECK_LIB(wayland-client,wl_display_connect,[:], [WAYLAND_CLIENT_LIBS=""],[$WAYLAND_CLIENT_LIBS])]) + AC_PATH_PROG(WAYLAND_SCANNER,wayland-scanner, + [`test -n "$PKG_CONFIG" && $PKG_CONFIG --variable=wayland_scanner wayland-scanner`]) fi -WINE_NOTICE_WITH(wayland, [test -z "$WAYLAND_CLIENT_LIBS"], +WINE_NOTICE_WITH(wayland, [test -z "$WAYLAND_CLIENT_LIBS" -o -z "$WAYLAND_SCANNER"], [Wayland ${notice_platform}development files not found, the Wayland driver won't be supported.], [enable_winewayland_drv])
diff --git a/dlls/winewayland.drv/Makefile.in b/dlls/winewayland.drv/Makefile.in index d86b51a519f..326a9d765c8 100644 --- a/dlls/winewayland.drv/Makefile.in +++ b/dlls/winewayland.drv/Makefile.in @@ -10,4 +10,7 @@ C_SRCS = \ wayland_output.c \ waylanddrv_main.c
+WAYLAND_PROTOCOL_SRCS = \ + xdg-output-unstable-v1.xml + RC_SRCS = version.rc diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index 2f728355438..2eb58fb7139 100644 --- a/dlls/winewayland.drv/wayland.c +++ b/dlls/winewayland.drv/wayland.c @@ -53,6 +53,18 @@ static void registry_handle_global(void *data, struct wl_registry *registry, if (!wayland_output_create(id, version)) ERR("Failed to create wayland_output for global id=%u\n", id); } + else if (strcmp(interface, "zxdg_output_manager_v1") == 0) + { + struct wayland_output *output; + + process_wayland->zxdg_output_manager_v1 = + wl_registry_bind(registry, id, &zxdg_output_manager_v1_interface, + version < 3 ? version : 3); + + /* Add zxdg_output_v1 to existing outputs. */ + wl_list_for_each(output, &process_wayland->output_list, link) + wayland_output_use_xdg_extension(output); + } }
static void registry_handle_global_remove(void *data, struct wl_registry *registry, diff --git a/dlls/winewayland.drv/wayland_output.c b/dlls/winewayland.drv/wayland_output.c index be9ea32bd72..8eb24fe97f3 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -97,6 +97,22 @@ static void wayland_output_add_mode(struct wayland_output *output, if (current) output->current_mode = mode; }
+static void wayland_output_done(struct wayland_output *output) +{ + struct wayland_output_mode *mode; + + TRACE("name=%s\n", output->name); + + RB_FOR_EACH_ENTRY(mode, &output->modes, struct wayland_output_mode, entry) + { + TRACE("mode %dx%d @ %d %s\n", + mode->width, mode->height, mode->refresh, + output->current_mode == mode ? "*" : ""); + } + + wayland_init_display_devices(); +} + static void output_handle_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, @@ -122,18 +138,12 @@ static void output_handle_mode(void *data, struct wl_output *wl_output, static void output_handle_done(void *data, struct wl_output *wl_output) { struct wayland_output *output = data; - struct wayland_output_mode *mode; - - TRACE("name=%s\n", output->name);
- RB_FOR_EACH_ENTRY(mode, &output->modes, struct wayland_output_mode, entry) + if (!output->zxdg_output_v1 || + zxdg_output_v1_get_version(output->zxdg_output_v1) >= 3) { - TRACE("mode %dx%d @ %d %s\n", - mode->width, mode->height, mode->refresh, - output->current_mode == mode ? "*" : ""); + wayland_output_done(output); } - - wayland_init_display_devices(); }
static void output_handle_scale(void *data, struct wl_output *wl_output, @@ -148,6 +158,54 @@ static const struct wl_output_listener output_listener = { output_handle_scale };
+static void zxdg_output_v1_handle_logical_position(void *data, + struct zxdg_output_v1 *zxdg_output_v1, + int32_t x, + int32_t y) +{ +} + +static void zxdg_output_v1_handle_logical_size(void *data, + struct zxdg_output_v1 *zxdg_output_v1, + int32_t width, + int32_t height) +{ +} + +static void zxdg_output_v1_handle_done(void *data, + struct zxdg_output_v1 *zxdg_output_v1) +{ + if (zxdg_output_v1_get_version(zxdg_output_v1) < 3) + { + struct wayland_output *output = data; + wayland_output_done(output); + } +} + +static void zxdg_output_v1_handle_name(void *data, + struct zxdg_output_v1 *zxdg_output_v1, + const char *name) +{ + struct wayland_output *output = data; + + free(output->name); + output->name = strdup(name); +} + +static void zxdg_output_v1_handle_description(void *data, + struct zxdg_output_v1 *zxdg_output_v1, + const char *description) +{ +} + +static const struct zxdg_output_v1_listener zxdg_output_v1_listener = { + zxdg_output_v1_handle_logical_position, + zxdg_output_v1_handle_logical_size, + zxdg_output_v1_handle_done, + zxdg_output_v1_handle_name, + zxdg_output_v1_handle_description, +}; + /********************************************************************** * wayland_output_create * @@ -156,6 +214,7 @@ static const struct wl_output_listener output_listener = { BOOL wayland_output_create(uint32_t id, uint32_t version) { struct wayland_output *output = calloc(1, sizeof(*output)); + int name_len;
if (!output) { @@ -172,8 +231,21 @@ BOOL wayland_output_create(uint32_t id, uint32_t version) wl_list_init(&output->link); rb_init(&output->modes, wayland_output_mode_cmp_rb);
- snprintf(output->name, sizeof(output->name), "WaylandOutput%d", - next_output_id++); + /* Have a fallback while we don't have compositor given name. */ + name_len = snprintf(NULL, 0, "WaylandOutput%d", next_output_id); + output->name = malloc(name_len + 1); + if (output->name) + { + snprintf(output->name, name_len + 1, "WaylandOutput%d", next_output_id++); + } + else + { + ERR("Couldn't allocate space for output name\n"); + goto err; + } + + if (process_wayland->zxdg_output_manager_v1) + wayland_output_use_xdg_extension(output);
wl_list_insert(process_wayland->output_list.prev, &output->link);
@@ -198,6 +270,23 @@ void wayland_output_destroy(struct wayland_output *output) { rb_destroy(&output->modes, wayland_output_mode_free_rb, NULL); wl_list_remove(&output->link); + if (output->zxdg_output_v1) + zxdg_output_v1_destroy(output->zxdg_output_v1); wl_output_destroy(output->wl_output); + free(output->name); free(output); } + +/********************************************************************** + * wayland_output_use_xdg_extension + * + * Use the zxdg_output_v1 extension to get output information. + */ +void wayland_output_use_xdg_extension(struct wayland_output *output) +{ + output->zxdg_output_v1 = + zxdg_output_manager_v1_get_xdg_output(process_wayland->zxdg_output_manager_v1, + output->wl_output); + zxdg_output_v1_add_listener(output->zxdg_output_v1, &zxdg_output_v1_listener, + output); +} diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 77797c005c2..f8440d4bfc1 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -26,6 +26,7 @@ #endif
#include <wayland-client.h> +#include "xdg-output-unstable-v1-client-protocol.h"
#include "windef.h" #include "winbase.h" @@ -49,6 +50,7 @@ struct wayland { struct wl_event_queue *wl_event_queue; struct wl_registry *wl_registry; + struct zxdg_output_manager_v1 *zxdg_output_manager_v1; struct wl_list output_list; };
@@ -64,9 +66,10 @@ struct wayland_output { struct wl_list link; struct wl_output *wl_output; + struct zxdg_output_v1 *zxdg_output_v1; struct rb_tree modes; struct wayland_output_mode *current_mode; - char name[20]; + char *name; uint32_t global_id; };
@@ -83,6 +86,7 @@ void wayland_init_display_devices(void) DECLSPEC_HIDDEN;
BOOL wayland_output_create(uint32_t id, uint32_t version) DECLSPEC_HIDDEN; void wayland_output_destroy(struct wayland_output *output) DECLSPEC_HIDDEN; +void wayland_output_use_xdg_extension(struct wayland_output *output) DECLSPEC_HIDDEN;
/********************************************************************** * USER32 helpers diff --git a/dlls/winewayland.drv/xdg-output-unstable-v1.xml b/dlls/winewayland.drv/xdg-output-unstable-v1.xml new file mode 100644 index 00000000000..9a5b7900097 --- /dev/null +++ b/dlls/winewayland.drv/xdg-output-unstable-v1.xml @@ -0,0 +1,220 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="xdg_output_unstable_v1"> + + <copyright> + Copyright © 2017 Red Hat Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <description summary="Protocol to describe output regions"> + This protocol aims at describing outputs in a way which is more in line + with the concept of an output on desktop oriented systems. + + Some information are more specific to the concept of an output for + a desktop oriented system and may not make sense in other applications, + such as IVI systems for example. + + Typically, the global compositor space on a desktop system is made of + a contiguous or overlapping set of rectangular regions. + + Some of the information provided in this protocol might be identical + to their counterparts already available from wl_output, in which case + the information provided by this protocol should be preferred to their + equivalent in wl_output. The goal is to move the desktop specific + concepts (such as output location within the global compositor space, + the connector name and types, etc.) out of the core wl_output protocol. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible + changes may be added together with the corresponding interface + version bump. + Backward incompatible changes are done by bumping the version + number in the protocol and interface names and resetting the + interface version. Once the protocol is to be declared stable, + the 'z' prefix and the version number in the protocol and + interface names are removed and the interface version number is + reset. + </description> + + <interface name="zxdg_output_manager_v1" version="3"> + <description summary="manage xdg_output objects"> + A global factory interface for xdg_output objects. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the xdg_output_manager object"> + Using this request a client can tell the server that it is not + going to use the xdg_output_manager object anymore. + + Any objects already created through this instance are not affected. + </description> + </request> + + <request name="get_xdg_output"> + <description summary="create an xdg output from a wl_output"> + This creates a new xdg_output object for the given wl_output. + </description> + <arg name="id" type="new_id" interface="zxdg_output_v1"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + </interface> + + <interface name="zxdg_output_v1" version="3"> + <description summary="compositor logical output region"> + An xdg_output describes part of the compositor geometry. + + This typically corresponds to a monitor that displays part of the + compositor space. + + For objects version 3 onwards, after all xdg_output properties have been + sent (when the object is created and when properties are updated), a + wl_output.done event is sent. This allows changes to the output + properties to be seen as atomic, even if they happen via multiple events. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the xdg_output object"> + Using this request a client can tell the server that it is not + going to use the xdg_output object anymore. + </description> + </request> + + <event name="logical_position"> + <description summary="position of the output within the global compositor space"> + The position event describes the location of the wl_output within + the global compositor space. + + The logical_position event is sent after creating an xdg_output + (see xdg_output_manager.get_xdg_output) and whenever the location + of the output changes within the global compositor space. + </description> + <arg name="x" type="int" + summary="x position within the global compositor space"/> + <arg name="y" type="int" + summary="y position within the global compositor space"/> + </event> + + <event name="logical_size"> + <description summary="size of the output in the global compositor space"> + The logical_size event describes the size of the output in the + global compositor space. + + For example, a surface without any buffer scale, transformation + nor rotation set, with the size matching the logical_size will + have the same size as the corresponding output when displayed. + + Most regular Wayland clients should not pay attention to the + logical size and would rather rely on xdg_shell interfaces. + + Some clients such as Xwayland, however, need this to configure + their surfaces in the global compositor space as the compositor + may apply a different scale from what is advertised by the output + scaling property (to achieve fractional scaling, for example). + + For example, for a wl_output mode 3840×2160 and a scale factor 2: + + - A compositor not scaling the surface buffers will advertise a + logical size of 3840×2160, + + - A compositor automatically scaling the surface buffers will + advertise a logical size of 1920×1080, + + - A compositor using a fractional scale of 1.5 will advertise a + logical size of 2560×1440. + + For example, for a wl_output mode 1920×1080 and a 90 degree rotation, + the compositor will advertise a logical size of 1080x1920. + + The logical_size event is sent after creating an xdg_output + (see xdg_output_manager.get_xdg_output) and whenever the logical + size of the output changes, either as a result of a change in the + applied scale or because of a change in the corresponding output + mode(see wl_output.mode) or transform (see wl_output.transform). + </description> + <arg name="width" type="int" + summary="width in global compositor space"/> + <arg name="height" type="int" + summary="height in global compositor space"/> + </event> + + <event name="done"> + <description summary="all information about the output have been sent"> + This event is sent after all other properties of an xdg_output + have been sent. + + This allows changes to the xdg_output properties to be seen as + atomic, even if they happen via multiple events. + + For objects version 3 onwards, this event is deprecated. Compositors + are not required to send it anymore and must send wl_output.done + instead. + </description> + </event> + + <!-- Version 2 additions --> + + <event name="name" since="2"> + <description summary="name of this output"> + Many compositors will assign names to their outputs, show them to the + user, allow them to be configured by name, etc. The client may wish to + know this name as well to offer the user similar behaviors. + + The naming convention is compositor defined, but limited to + alphanumeric characters and dashes (-). Each name is unique among all + wl_output globals, but if a wl_output global is destroyed the same name + may be reused later. The names will also remain consistent across + sessions with the same hardware and software configuration. + + Examples of names include 'HDMI-A-1', 'WL-1', 'X11-1', etc. However, do + not assume that the name is a reflection of an underlying DRM + connector, X11 connection, etc. + + The name event is sent after creating an xdg_output (see + xdg_output_manager.get_xdg_output). This event is only sent once per + xdg_output, and the name does not change over the lifetime of the + wl_output global. + </description> + <arg name="name" type="string" summary="output name"/> + </event> + + <event name="description" since="2"> + <description summary="human-readable description of this output"> + Many compositors can produce human-readable descriptions of their + outputs. The client may wish to know this description as well, to + communicate the user for various purposes. + + The description is a UTF-8 string with no convention defined for its + contents. Examples might include 'Foocorp 11" Display' or 'Virtual X11 + output via :1'. + + The description event is sent after creating an xdg_output (see + xdg_output_manager.get_xdg_output) and whenever the description + changes. The description is optional, and may not be sent at all. + + For objects of version 2 and lower, this event is only sent once per + xdg_output, and the description does not change over the lifetime of + the wl_output global. + </description> + <arg name="description" type="string" summary="output description"/> + </event> + + </interface> +</protocol>
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Use the xdg-output-unstable-v1 protocol to get the position and size of the Wayland outputs in the compositor logical space, and use this information to infer the physical (i.e., native pixel) coordinates of the monitors.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/display.c | 157 +++++++++++++++++++++++--- dlls/winewayland.drv/wayland_output.c | 12 +- dlls/winewayland.drv/waylanddrv.h | 2 + 3 files changed, 157 insertions(+), 14 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index adf981d92e6..fb036d06a0f 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -30,6 +30,8 @@
#include "ntuser.h"
+#include <stdlib.h> + WINE_DEFAULT_DEBUG_CHANNEL(waylanddrv);
static BOOL force_display_devices_refresh; @@ -47,6 +49,118 @@ void wayland_init_display_devices(void) wayland_refresh_display_devices(); }
+struct output_info +{ + int x, y; + struct wayland_output *output; +}; + +static int output_info_cmp_logical_x(const void *va, const void *vb) +{ + const struct output_info *a = va; + const struct output_info *b = vb; + + if (a->output->logical_x < b->output->logical_x) return -1; + if (a->output->logical_x > b->output->logical_x) return 1; + if (a->output->logical_y < b->output->logical_y) return -1; + if (a->output->logical_y > b->output->logical_y) return 1; + return 0; +} + +static int output_info_cmp_logical_y(const void *va, const void *vb) +{ + const struct output_info *a = va; + const struct output_info *b = vb; + + if (a->output->logical_y < b->output->logical_y) return -1; + if (a->output->logical_y > b->output->logical_y) return 1; + if (a->output->logical_x < b->output->logical_x) return -1; + if (a->output->logical_x > b->output->logical_x) return 1; + return 0; +} + +static int output_info_cmp_x_primary_first(const void *va, const void *vb) +{ + const struct output_info *a = va; + const struct output_info *b = vb; + BOOL a_is_primary = a->x == 0 && a->y == 0; + BOOL b_is_primary = b->x == 0 && b->y == 0; + + if (a_is_primary && !b_is_primary) return -1; + if (!a_is_primary && b_is_primary) return 1; + if (a->x < b->x) return -1; + if (a->x > b->x) return 1; + if (a->y < b->y) return -1; + if (a->y > b->y) return 1; + return 0; +} + +static void output_info_array_arrange_physical_coords(struct wl_array *output_info_array) +{ + struct output_info *cur, *prev; + size_t num_outputs = output_info_array->size / sizeof(struct output_info); + + /* Set default physical coordinates. */ + wl_array_for_each(cur, output_info_array) + { + cur->x = cur->output->logical_x; + cur->y = cur->output->logical_y; + } + + /* Sort and process the outputs from logical left to right. */ + qsort(output_info_array->data, num_outputs, sizeof(struct output_info), + output_info_cmp_logical_x); + + wl_array_for_each(cur, output_info_array) + { + BOOL cur_x_set = FALSE; + wl_array_for_each(prev, output_info_array) + { + if (prev == cur) break; + if (cur->output->logical_x == prev->output->logical_x + + prev->output->logical_w && + prev->output->current_mode) + { + int new_x = prev->x + prev->output->current_mode->width; + if (!cur_x_set || new_x > cur->x) + { + cur->x = new_x; + cur_x_set = TRUE; + } + } + } + } + + /* Sort and process the outputs from logical top to bottom. */ + qsort(output_info_array->data, num_outputs, sizeof(struct output_info), + output_info_cmp_logical_y); + + wl_array_for_each(cur, output_info_array) + { + BOOL cur_y_set = FALSE; + wl_array_for_each(prev, output_info_array) + { + if (prev == cur) break; + if (cur->output->logical_y == prev->output->logical_y + + prev->output->logical_h && + prev->output->current_mode) + { + int new_y = prev->y + prev->output->current_mode->height; + if (!cur_y_set || new_y > cur->y) + { + cur->y = new_y; + cur_y_set = TRUE; + } + } + } + } + + /* Now that we have our physical coordinates, arrange from left to right, + * but ensure the primary output is first. */ + qsort(output_info_array->data, num_outputs, sizeof(struct output_info), + output_info_cmp_x_primary_first); +} + static void wayland_add_device_gpu(const struct gdi_device_manager *device_manager, void *param) { @@ -76,13 +190,13 @@ static void wayland_add_device_adapter(const struct gdi_device_manager *device_m }
static void wayland_add_device_monitor(const struct gdi_device_manager *device_manager, - void *param, struct wayland_output *output) + void *param, struct output_info *output_info) { struct gdi_monitor monitor = {0};
- SetRect(&monitor.rc_monitor, 0, 0, - output->current_mode->width, - output->current_mode->height); + SetRect(&monitor.rc_monitor, output_info->x, output_info->y, + output_info->x + output_info->output->current_mode->width, + output_info->y + output_info->output->current_mode->height);
/* We don't have a direct way to get the work area in Wayland. */ monitor.rc_work = monitor.rc_monitor; @@ -90,7 +204,7 @@ static void wayland_add_device_monitor(const struct gdi_device_manager *device_m monitor.state_flags = DISPLAY_DEVICE_ATTACHED | DISPLAY_DEVICE_ACTIVE;
TRACE("name=%s rc_monitor=rc_work=%s state_flags=0x%x\n", - output->name, wine_dbgstr_rect(&monitor.rc_monitor), + output_info->output->name, wine_dbgstr_rect(&monitor.rc_monitor), (UINT)monitor.state_flags);
device_manager->add_monitor(&monitor, param); @@ -109,21 +223,22 @@ static void populate_devmode(struct wayland_output_mode *output_mode, DEVMODEW * }
static void wayland_add_device_modes(const struct gdi_device_manager *device_manager, - void *param, struct wayland_output *output) + void *param, struct output_info *output_info) { struct wayland_output_mode *output_mode; DEVMODEW mode = {.dmSize = sizeof(mode)};
- RB_FOR_EACH_ENTRY(output_mode, &output->modes, struct wayland_output_mode, entry) + RB_FOR_EACH_ENTRY(output_mode, &output_info->output->modes, + struct wayland_output_mode, entry) { populate_devmode(output_mode, &mode); device_manager->add_mode(&mode, GDI_MODE_NEXT, param); }
- populate_devmode(output->current_mode, &mode); + populate_devmode(output_info->output->current_mode, &mode); mode.dmFields |= DM_POSITION; - mode.dmPosition.x = 0; - mode.dmPosition.y = 0; + mode.dmPosition.x = output_info->x; + mode.dmPosition.y = output_info->y; device_manager->add_mode(&mode, GDI_MODE_REGISTRY_IF_EMPTY, param); device_manager->add_mode(&mode, GDI_MODE_CURRENT, param); } @@ -136,6 +251,8 @@ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manage { struct wayland_output *output; INT output_id = 0; + struct wl_array output_info_array; + struct output_info *output_info;
/* For now, update the display devices only when a compositor side update * is received in the desktop window process. */ @@ -145,17 +262,31 @@ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manage
force_display_devices_refresh = FALSE;
- wayland_add_device_gpu(device_manager, param); + wl_array_init(&output_info_array);
wl_list_for_each(output, &process_wayland->output_list, link) { if (!output->current_mode) continue; + output_info = wl_array_add(&output_info_array, sizeof(*output_info)); + output_info->output = output; + } + + /* Arrange outputs in the physical coordinate space. */ + output_info_array_arrange_physical_coords(&output_info_array); + + /* Populate GDI devices. */ + wayland_add_device_gpu(device_manager, param); + + wl_array_for_each(output_info, &output_info_array) + { wayland_add_device_adapter(device_manager, param, output_id); - wayland_add_device_monitor(device_manager, param, output); - wayland_add_device_modes(device_manager, param, output); + wayland_add_device_monitor(device_manager, param, output_info); + wayland_add_device_modes(device_manager, param, output_info); output_id++; }
+ wl_array_release(&output_info_array); + return TRUE; }
diff --git a/dlls/winewayland.drv/wayland_output.c b/dlls/winewayland.drv/wayland_output.c index 8eb24fe97f3..4d9033d3f73 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -101,7 +101,9 @@ static void wayland_output_done(struct wayland_output *output) { struct wayland_output_mode *mode;
- TRACE("name=%s\n", output->name); + TRACE("name=%s logical=%d,%d+%dx%d\n", + output->name, output->logical_x, output->logical_y, + output->logical_w, output->logical_h);
RB_FOR_EACH_ENTRY(mode, &output->modes, struct wayland_output_mode, entry) { @@ -163,6 +165,10 @@ static void zxdg_output_v1_handle_logical_position(void *data, int32_t x, int32_t y) { + struct wayland_output *output = data; + TRACE("logical_x=%d logical_y=%d\n", x, y); + output->logical_x = x; + output->logical_y = y; }
static void zxdg_output_v1_handle_logical_size(void *data, @@ -170,6 +176,10 @@ static void zxdg_output_v1_handle_logical_size(void *data, int32_t width, int32_t height) { + struct wayland_output *output = data; + TRACE("logical_w=%d logical_h=%d\n", width, height); + output->logical_w = width; + output->logical_h = height; }
static void zxdg_output_v1_handle_done(void *data, diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index f8440d4bfc1..542c1a3b442 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -70,6 +70,8 @@ struct wayland_output struct rb_tree modes; struct wayland_output_mode *current_mode; char *name; + int logical_x, logical_y; /* logical position */ + int logical_w, logical_h; /* logical size */ uint32_t global_id; };