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 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 and also include the protocol file in our winewayland.drv sources.
Since Wayland provides output coordinates only in the compositor logical space, we need to infer the monitor coordinates in the physical pixel space (so that apps can take advantage of the full/native monitor resolution), based on logical coordinates and the current mode. The last commit in the series introduces a best-effort algorithm for this. For people that are curious about this algorithm, or want to experiment a bit: I have created an independent ad-hoc test suite for this algorithm at: https://gitlab.collabora.com/alf/wine-wayland-outputs
The core idea of the algorithm is to start with a placement that uses the logical positions, and iteratively move outputs away from others in particular directions until any non-inherent (i.e., not present in the logical space) overlaps have been resolved.
Thanks!
-- v10: winewayland.drv: Infer and report Windows monitor positions. winewayland.drv: Basic support for Windows monitor positioning. winewayland.drv: Use the output name reported by the compositor. tools: Support building Wayland protocol source files.
From: Alexandros Frantzis alexandros.frantzis@collabora.com
After the driver process initialization is done, use all the received wl_output information to non-forcefully initialize the display devices. We will reintroduce dynamic display device reinitialization (i.e., as a response to non-initial wl_output events) when we start reading and dispatching Wayland events.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/display.c | 25 +++---------------------- dlls/winewayland.drv/wayland.c | 3 ++- dlls/winewayland.drv/wayland_output.c | 2 -- 3 files changed, 5 insertions(+), 25 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index bd99441170e..36d1703e010 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -32,30 +32,13 @@
WINE_DEFAULT_DEBUG_CHANNEL(waylanddrv);
-static BOOL force_display_devices_refresh; - -static void wayland_refresh_display_devices(void) +void wayland_init_display_devices(void) { UINT32 num_path, num_mode; - force_display_devices_refresh = TRUE; /* Trigger refresh in win32u */ NtUserGetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &num_path, &num_mode); }
-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(); -} - static void wayland_add_device_gpu(const struct gdi_device_manager *device_manager, void *param) { @@ -141,11 +124,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; - - TRACE("force=%d force_refresh=%d\n", force, force_display_devices_refresh); + if (!force) return TRUE;
- force_display_devices_refresh = FALSE; + TRACE("force=%d\n", force);
wayland_add_device_gpu(device_manager, param);
diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index 104a091ea80..e09843e1f50 100644 --- a/dlls/winewayland.drv/wayland.c +++ b/dlls/winewayland.drv/wayland.c @@ -65,7 +65,6 @@ static void registry_handle_global_remove(void *data, struct wl_registry *regist { TRACE("removing output->name=%s\n", output->name); wayland_output_destroy(output); - wayland_init_display_devices(); return; } } @@ -129,5 +128,7 @@ BOOL wayland_process_init(void) wl_display_roundtrip_queue(process_wl_display, process_wayland->wl_event_queue); wl_display_roundtrip_queue(process_wl_display, process_wayland->wl_event_queue);
+ wayland_init_display_devices(); + return TRUE; } diff --git a/dlls/winewayland.drv/wayland_output.c b/dlls/winewayland.drv/wayland_output.c index be9ea32bd72..0bdfd491bfe 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -132,8 +132,6 @@ static void output_handle_done(void *data, struct wl_output *wl_output) mode->width, mode->height, mode->refresh, output->current_mode == mode ? "*" : ""); } - - wayland_init_display_devices(); }
static void output_handle_scale(void *data, struct wl_output *wl_output,
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 --- configure | 50 +++- configure.ac | 4 +- dlls/winewayland.drv/Makefile.in | 3 + .../xdg-output-unstable-v1.xml | 220 ++++++++++++++++++ tools/make_makefiles | 5 + tools/makedep.c | 39 ++++ 6 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 dlls/winewayland.drv/xdg-output-unstable-v1.xml
diff --git a/configure b/configure index 4a33bf69ff1..3a9f9bbd355 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 @@ -15665,8 +15666,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." ;; @@ -23178,6 +23225,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 c4f34e9e851..05cb25997f6 100644 --- a/configure.ac +++ b/configure.ac @@ -1343,8 +1343,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/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> diff --git a/tools/make_makefiles b/tools/make_makefiles index 2079a037f4e..1d3ce8c68a0 100755 --- a/tools/make_makefiles +++ b/tools/make_makefiles @@ -59,6 +59,7 @@ my @source_vars = ( "RC_SRCS", "SOURCES", "SVG_SRCS", + "WAYLAND_PROTOCOL_SRCS", "XTEMPLATE_SRCS" );
@@ -387,6 +388,10 @@ sub assign_sources_to_makefiles(@) { push @nls_files, $name if $dir eq "nls"; } + elsif ($name =~ /.xml$/ && $dir eq "dlls/winewayland.drv") + { + push @{${$make}{"=WAYLAND_PROTOCOL_SRCS"}}, $name + } elsif ($dir ne "loader") # loader dir contains misc files { next; diff --git a/tools/makedep.c b/tools/makedep.c index 49a7514c9f0..1cc815ee519 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -157,6 +157,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]; @@ -1428,6 +1429,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 )) @@ -1802,6 +1804,14 @@ static struct makefile *parse_makefile( const char *path ) return make; }
+/******************************************************************* + * is_wayland_protocol_source + */ +static int is_wayland_protocol_source( struct makefile *make, struct incl_file *source ) +{ + return strendswith( source->name, ".xml" ) && + strendswith( make->src_dir, "dlls/winewayland.drv" ); +}
/******************************************************************* * add_generated_sources @@ -1915,6 +1925,21 @@ static void add_generated_sources( struct makefile *make ) strarray_addall_uniq( &make->extra_imports, get_expanded_file_local_var( make, obj, "IMPORTS" )); } + if (is_wayland_protocol_source( make, source )) + { + 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 +3126,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 (is_wayland_protocol_source( make, source ) && 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 +3275,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 +4090,7 @@ static void output_silent_rules(void) "MSG", "SED", "TEST", + "WAYLAND_SCANNER", "WIDL", "WMC", "WRC" @@ -4153,6 +4190,7 @@ static void load_sources( struct makefile *make ) "IN_SRCS", "PO_SRCS", "MANPAGES", + "WAYLAND_PROTOCOL_SRCS", NULL }; const char **var; @@ -4383,6 +4421,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 --- dlls/winewayland.drv/wayland.c | 12 +++ dlls/winewayland.drv/wayland_output.c | 107 +++++++++++++++++++++++--- dlls/winewayland.drv/waylanddrv.h | 6 +- 3 files changed, 115 insertions(+), 10 deletions(-)
diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index e09843e1f50..22a7a8cc63f 100644 --- a/dlls/winewayland.drv/wayland.c +++ b/dlls/winewayland.drv/wayland.c @@ -50,6 +50,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 0bdfd491bfe..08c5c96824c 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -97,6 +97,20 @@ 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 ? "*" : ""); + } +} + 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,15 +136,11 @@ 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); } }
@@ -146,6 +156,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 * @@ -154,6 +212,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) { @@ -170,8 +229,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);
@@ -196,6 +268,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 8458ed17df2..da0fccecda9 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;
/********************************************************************** * USER driver functions
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Use the xdg-output-unstable-v1 protocol to get the positions of the Wayland outputs in the compositor logical space, and use this information to arrange the monitors in the Windows virtual screen space. For now we assume that the logical positions match the physical pixel positions (i.e., the outputs are not scaled), a deficiency which will be addressed in an upcoming commit.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/display.c | 88 +++++++++++++++++++++++---- dlls/winewayland.drv/wayland_output.c | 7 ++- dlls/winewayland.drv/waylanddrv.h | 1 + 3 files changed, 83 insertions(+), 13 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index 36d1703e010..77f5f8b140d 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);
void wayland_init_display_devices(void) @@ -39,6 +41,46 @@ void wayland_init_display_devices(void) NtUserGetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &num_path, &num_mode); }
+struct output_info +{ + int x, y; + struct wayland_output *output; +}; + +static int output_info_cmp_primary_x_y(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 strcmp(a->output->name, b->output->name); +} + +static void output_info_array_arrange_physical_coords(struct wl_array *output_info_array) +{ + struct output_info *info; + size_t num_outputs = output_info_array->size / sizeof(struct output_info); + + /* Set physical pixel coordinates. */ + wl_array_for_each(info, output_info_array) + { + info->x = info->output->logical_x; + info->y = info->output->logical_y; + } + + /* Now that we have our physical pixel coordinates, sort from physical left + * to right, but ensure the primary output is first. */ + qsort(output_info_array->data, num_outputs, sizeof(struct output_info), + output_info_cmp_primary_x_y); +} + static void wayland_add_device_gpu(const struct gdi_device_manager *device_manager, void *param) { @@ -68,13 +110,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; @@ -82,7 +124,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); @@ -101,16 +143,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;
- 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) { DEVMODEW mode = {.dmSize = sizeof(mode)}; - BOOL mode_is_current = output_mode == output->current_mode; + BOOL mode_is_current = output_mode == output_info->output->current_mode; populate_devmode(output_mode, &mode); - if (mode_is_current) mode.dmFields |= DM_POSITION; + if (mode_is_current) + { + mode.dmFields |= DM_POSITION; + mode.dmPosition.x = output_info->x; + mode.dmPosition.y = output_info->y; + } device_manager->add_mode(&mode, mode_is_current, param); } } @@ -123,21 +171,37 @@ 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;
if (!force) return TRUE;
TRACE("force=%d\n", force);
- 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)); + if (output_info) output_info->output = output; + else ERR("Failed to allocate space for output_info\n"); + } + + 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 08c5c96824c..2090c5d45c9 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -101,7 +101,8 @@ 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\n", + output->name, output->logical_x, output->logical_y);
RB_FOR_EACH_ENTRY(mode, &output->modes, struct wayland_output_mode, entry) { @@ -161,6 +162,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, diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index da0fccecda9..f17790173a9 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -70,6 +70,7 @@ struct wayland_output struct rb_tree modes; struct wayland_output_mode *current_mode; char *name; + int logical_x, logical_y; uint32_t global_id; };
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Use the xdg-output-unstable-v1 protocol to get the size of the Wayland outputs in the compositor logical space, and use this information, along with the logical position and size in physical pixels (i.e., the current mode) to infer the Windows virtual screen coordinates of the monitors.
Note that there are multiple possible mappings from Wayland logical coordinates to Windows virtual screen coordinates. We choose one algorithm that works well for the majority of output arrangements, and we can refine in the future as needed.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/display.c | 112 +++++++++++++++++++++++++- dlls/winewayland.drv/wayland_output.c | 9 ++- dlls/winewayland.drv/waylanddrv.h | 1 + 3 files changed, 119 insertions(+), 3 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index 77f5f8b140d..5234a1f03aa 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -63,18 +63,128 @@ static int output_info_cmp_primary_x_y(const void *va, const void *vb) return strcmp(a->output->name, b->output->name); }
+static inline BOOL output_info_overlap(struct output_info *a, struct output_info *b) +{ + return b->x < a->x + a->output->current_mode->width && + b->x + b->output->current_mode->width > a->x && + b->y < a->y + a->output->current_mode->height && + b->y + b->output->current_mode->height > a->y; +} + +/* Map a point to one of the four quadrants of our 2d coordinate space: + * 0: bottom right (x >= 0, y >= 0) + * 1: top right (x >= 0, y < 0) + * 2: bottom left (x < 0, y >= 0) + * 3: top left (x < 0, y < 0) */ +static inline int point_to_quadrant(int x, int y) +{ + return (x < 0) * 2 + (y < 0); +} + +/* Decide which of two outputs to keep stationary in order + * to resolve an overlap. */ +static struct output_info *output_info_get_overlap_anchor(struct output_info *a, + struct output_info *b) +{ + /* Preferences for the direction of growth in each quadrant, with a + * lower value signifying a higher preference. */ + static const int quadrant_prefs[4][4] = + { + {0, 1, 2, 3}, /* quadrant 0 */ + {3, 0, 2, 1}, /* quadrant 1 */ + {2, 3, 0, 1}, /* quadrant 2 */ + {3, 2, 1, 0}, /* quadrant 3 */ + }; + int qa = point_to_quadrant(a->output->logical_x, a->output->logical_y); + int qb = point_to_quadrant(b->output->logical_x, b->output->logical_y); + /* Direction of growth if a is the anchor. */ + int qab = point_to_quadrant(b->output->logical_x - a->output->logical_x, + b->output->logical_y - a->output->logical_y); + /* Direction of growth if b is the anchor. */ + int qba = point_to_quadrant(a->output->logical_x - b->output->logical_x, + a->output->logical_y - b->output->logical_y); + + /* If the two output origins are in different quadrants, use the output + * in the lower valued quadrant as the anchor (so effectively outputs + * grow/move away from quadrant 0). */ + if (qa != qb) return (qa < qb) ? a : b; + + /* If the outputs are in the same quadrant, use the preference for the + * direction of growth in that quadrant to select the anchor. Again the + * intended effect is to grow/move outputs away from the origin. */ + return (quadrant_prefs[qa][qab] < quadrant_prefs[qa][qba]) ? a : b; +} + +static BOOL output_info_array_resolve_overlaps(struct wl_array *output_info_array) +{ + struct output_info *a, *b; + BOOL found_overlap = FALSE; + + wl_array_for_each(a, output_info_array) + { + wl_array_for_each(b, output_info_array) + { + struct output_info *anchor, *move; + BOOL x_use_end, y_use_end; + double rel_x, rel_y; + + /* Break if we reach the same output in the inner loop, so that we + * don't process output pairs twice (since order doesn't matter for + * our algorithm.) */ + if (a == b) break; + + if (!output_info_overlap(a, b)) continue; + found_overlap = TRUE; + + /* Decide which output to move to resolve the overlap. */ + anchor = output_info_get_overlap_anchor(a, b); + move = anchor == a ? b : a; + + /* Move the selected output on the X axis to resolve the overlap, + * while maintaining the same relative positioning of the outputs as + * the one they have in logical space. Use either the start or end + * of the moved output as the point to maintain the relative + * position of, depending on whether the anchor is before or after + * the moved output on the axis. */ + x_use_end = move->output->logical_x < anchor->output->logical_x; + rel_x = (move->output->logical_x - anchor->output->logical_x + + (x_use_end ? move->output->logical_w : 0)) / + (double)anchor->output->logical_w; + move->x = anchor->x + anchor->output->current_mode->width * rel_x - + (x_use_end ? move->output->current_mode->width : 0); + + /* Similarly for the Y axis. */ + y_use_end = move->output->logical_y < anchor->output->logical_y; + rel_y = (move->output->logical_y - anchor->output->logical_y + + (y_use_end ? move->output->logical_h : 0)) / + (double)anchor->output->logical_h; + move->y = anchor->y + anchor->output->current_mode->height * rel_y - + (y_use_end ? move->output->current_mode->height : 0); + } + } + + return found_overlap; +} + static void output_info_array_arrange_physical_coords(struct wl_array *output_info_array) { struct output_info *info; size_t num_outputs = output_info_array->size / sizeof(struct output_info); + int steps = 0;
- /* Set physical pixel coordinates. */ + /* Set the initial physical pixel coordinates. */ wl_array_for_each(info, output_info_array) { info->x = info->output->logical_x; info->y = info->output->logical_y; }
+ /* Try to iteratively resolve overlaps, but be defensive and set an upper + * iteration bound to ensure we avoid infinite loops. */ + while (output_info_array_resolve_overlaps(output_info_array) && + ++steps < num_outputs) + continue; + /* Now that we have our physical pixel coordinates, sort from physical left * to right, but ensure the primary output is first. */ qsort(output_info_array->data, num_outputs, sizeof(struct output_info), diff --git a/dlls/winewayland.drv/wayland_output.c b/dlls/winewayland.drv/wayland_output.c index 2090c5d45c9..5cd6e74f24a 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -101,8 +101,9 @@ static void wayland_output_done(struct wayland_output *output) { struct wayland_output_mode *mode;
- TRACE("name=%s logical=%d,%d\n", - output->name, output->logical_x, output->logical_y); + 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) { @@ -173,6 +174,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 f17790173a9..e1ea66f3b33 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -71,6 +71,7 @@ struct wayland_output struct wayland_output_mode *current_mode; char *name; int logical_x, logical_y; + int logical_w, logical_h; uint32_t global_id; };
This merge request was approved by Rémi Bernon.
Looks good as far as I can tell.