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 implementing 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, and also makedep changes to gracefully handle the case these external sources are missing when the driver is disabled. These changes are introduced on their own in the first 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 adds a shared memory region containing an authoritative version of the Wayland output information (see the "winewayland.drv: Implement GetCurrentDisplaySettings." commit for more details).
**Important note:** This MR requires the wayland-protocols package in the CI docker image. Without it the Wayland driver build will be disabled, so any build results are not going to be representative of the Wayland driver code changes in this branch.
Thanks!
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.
Since protocol files likely reside outside of the source tree, they may be missing, in which case the Wayland driver will be disabled. To handle this scenario, update the makedep tool to not bail out when we have such missing external sources in disabled makefiles.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- tools/makedep.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-)
diff --git a/tools/makedep.c b/tools/makedep.c index 49a7514c9f0..28be80049d2 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]; @@ -470,6 +471,15 @@ static char *replace_filename( const char *path, const char *name ) return ret; }
+/******************************************************************* + * get_filename + */ +static const char *get_filename( const char *name ) +{ + char *filename = strrchr( name, '/' ); + if (!filename) return name; + return filename + 1; +}
/******************************************************************* * replace_substr @@ -1197,9 +1207,9 @@ static const struct };
/******************************************************************* - * load_file + * load_file_maybe_missing */ -static struct file *load_file( const char *name ) +static struct file *load_file_maybe_missing( const char *name, int allow_missing ) { struct file *file; FILE *f; @@ -1208,10 +1218,13 @@ static struct file *load_file( const char *name ) LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry ) if (!strcmp( name, file->name )) return file;
- if (!(f = fopen( name, "r" ))) return NULL; + if (!(f = fopen( name, "r" )) && !allow_missing) return NULL;
file = add_file( name ); list_add_tail( &files[hash], &file->entry ); + + if (!f) return file; + input_file_name = file->name; input_line = 0;
@@ -1229,6 +1242,15 @@ static struct file *load_file( const char *name ) }
+/******************************************************************* + * load_file + */ +static struct file *load_file( const char *name ) +{ + return load_file_maybe_missing(name, 0); +} + + /******************************************************************* * open_include_path_file * @@ -1383,12 +1405,52 @@ static struct file *open_global_generated_file( const struct makefile *make, str */ static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile ) { - struct file *file = open_local_file( make, pFile->name, &pFile->filename ); + struct file *file; + + if (pFile->name[0] == '/') + { + /* Allow missing external source files if the makefile is disabled. */ + file = load_file_maybe_missing( pFile->name, make->disabled[0] ); + pFile->filename = xstrdup( pFile->name ); + } + else + { + file = open_local_file( make, pFile->name, &pFile->filename ); + }
if (!file) fatal_perror( "open %s", pFile->name ); return file; }
+/******************************************************************* + * open_wayland_protocol_file + */ +static struct file *open_wayland_protocol_file( const struct makefile *make, + struct incl_file *pFile ) +{ + char *proto_filename; + struct incl_file *incl_file; + struct file *ret_file = NULL; + + if (!strendswith( pFile->name, "-client-protocol.h" )) return NULL; + + proto_filename = replace_extension( pFile->name, "-client-protocol.h", ".xml" ); + + LIST_FOR_EACH_ENTRY( incl_file, &make->sources, struct incl_file, entry ) + { + if (strendswith( incl_file->name, proto_filename )) + { + pFile->sourcename = incl_file->filename; + pFile->filename = obj_dir_path( make, pFile->name ); + ret_file = incl_file->file; + break; + } + } + + free( proto_filename ); + + return ret_file; +}
/******************************************************************* * find_importlib_module @@ -1428,6 +1490,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_wayland_protocol_file( make, pFile ))) return file;
/* check for extra targets */ if (strarray_exists( &make->extra_targets, pFile->name )) @@ -1802,6 +1865,15 @@ static struct makefile *parse_makefile( const char *path ) return make; }
+/******************************************************************* + * is_wayland_protocol + */ +static int is_wayland_protocol( struct incl_file *source ) +{ + return strendswith( source->name, ".xml" ) && + (strstr( source->name, "stable/" ) || strstr( source->name, "unstable/" ) || + strstr( source->name, "staging/" )); +}
/******************************************************************* * add_generated_sources @@ -1915,6 +1987,22 @@ 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 )) + { + const char *filename = get_filename( source->name ); + char *code_filename = replace_extension ( filename , ".xml", "-protocol.c" ); + char *header_filename = replace_extension ( filename , ".xml", "-client-protocol.h" ); + + file = add_generated_source( make, code_filename, NULL, 0 ); + file->file->flags |= FLAG_C_UNIX; + file->use_msvcrt = 0; + file = add_generated_source( make, header_filename, NULL, 0 ); + file->file->flags |= FLAG_C_UNIX; + file->use_msvcrt = 0; + + free( code_filename ); + free( header_filename ); + } } if (make->testdll) { @@ -3101,6 +3189,18 @@ 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 ) +{ + const char *base; + + if (!is_wayland_protocol( source )) return; + + base = get_filename( obj ); + output( "%s-protocol.c: %s\n", obj_dir_path( make, base ), 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, base ), source->filename ); + output( "\t%s%s client-header $< $@\n", cmd_prefix( "WAYLAND_SCANNER" ), wayland_scanner); +}
/******************************************************************* * output_source_one_arch @@ -3240,6 +3340,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 +4155,7 @@ static void output_silent_rules(void) "MSG", "SED", "TEST", + "WAYLAND_SCANNER", "WIDL", "WMC", "WRC" @@ -4153,6 +4255,7 @@ static void load_sources( struct makefile *make ) "IN_SRCS", "PO_SRCS", "MANPAGES", + "WAYLAND_PROTOCOL_SRCS", NULL }; const char **var; @@ -4383,6 +4486,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 | 69 +++++++++++++++- configure.ac | 17 +++- 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 +- tools/gitlab/image.docker | 1 + 7 files changed, 200 insertions(+), 19 deletions(-)
diff --git a/configure b/configure index 647a1237469..030235016c0 100755 --- a/configure +++ b/configure @@ -702,6 +702,8 @@ INOTIFY_LIBS INOTIFY_CFLAGS PCSCLITE_LIBS PCAP_LIBS +WAYLAND_SCANNER +WAYLAND_PROTOCOLS_DATADIR WAYLAND_CLIENT_LIBS WAYLAND_CLIENT_CFLAGS X_EXTRA_LIBS @@ -1751,6 +1753,7 @@ XMKMF CPP WAYLAND_CLIENT_CFLAGS WAYLAND_CLIENT_LIBS +WAYLAND_PROTOCOLS_DATADIR INOTIFY_CFLAGS INOTIFY_LIBS DBUS_CFLAGS @@ -2560,6 +2563,8 @@ Some influential environment variables: C compiler flags for wayland-client, overriding pkg-config WAYLAND_CLIENT_LIBS Linker flags for wayland-client, overriding pkg-config + WAYLAND_PROTOCOLS_DATADIR + Wayland protocols data directory, overriding pkg-config INOTIFY_CFLAGS C compiler flags for libinotify, overriding pkg-config INOTIFY_LIBS @@ -6251,7 +6256,7 @@ printf "%s\n" "$wine_cv_cc_m32" >&6; } host_cpu="i386" notice_platform="32-bit " TARGETFLAGS="$TARGETFLAGS -m32" - PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib32/pkgconfig:/usr/lib/pkgconfig} + PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib32/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig} export PKG_CONFIG_LIBDIR with_unwind=${with_unwind:-no} else @@ -15640,13 +15645,67 @@ fi
CPPFLAGS=$ac_save_CPPFLAGS
+ + if test -z "$WAYLAND_PROTOCOLS_DATADIR" -a -n "$PKG_CONFIG" + then + WAYLAND_PROTOCOLS_DATADIR=`$PKG_CONFIG --atleast-version=1.14 wayland-protocols && \ + $PKG_CONFIG --variable=pkgdatadir wayland-protocols` + fi + # 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" || + test -z "$WAYLAND_PROTOCOLS_DATADIR" || + test -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." ;; + x) as_fn_append wine_notices "|Wayland ${notice_platform}development files not found or not new enough, the Wayland driver won't be supported." ;; xno) ;; - *) as_fn_error $? "Wayland ${notice_platform}development files not found, the Wayland driver won't be supported. + *) as_fn_error $? "Wayland ${notice_platform}development files not found or not new enough, the Wayland driver won't be supported. This is an error since --with-wayland was requested." "$LINENO" 5 ;; esac enable_winewayland_drv=${enable_winewayland_drv:-no} @@ -23147,6 +23206,8 @@ X_LIBS = $X_LIBS X_EXTRA_LIBS = $X_EXTRA_LIBS WAYLAND_CLIENT_CFLAGS = $WAYLAND_CLIENT_CFLAGS WAYLAND_CLIENT_LIBS = $WAYLAND_CLIENT_LIBS +WAYLAND_PROTOCOLS_DATADIR = $WAYLAND_PROTOCOLS_DATADIR +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 5ff1bb093f4..379b043bf34 100644 --- a/configure.ac +++ b/configure.ac @@ -130,7 +130,7 @@ case $host in host_cpu="i386" notice_platform="32-bit " TARGETFLAGS="$TARGETFLAGS -m32" - PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib32/pkgconfig:/usr/lib/pkgconfig} + PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib32/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig} export PKG_CONFIG_LIBDIR with_unwind=${with_unwind:-no} else @@ -1342,9 +1342,20 @@ then [AC_CHECK_HEADERS([wayland-client.h]) AC_CHECK_LIB(wayland-client,wl_display_connect,[:], [WAYLAND_CLIENT_LIBS=""],[$WAYLAND_CLIENT_LIBS])]) + AC_ARG_VAR(WAYLAND_PROTOCOLS_DATADIR, + [Wayland protocols data directory, overriding pkg-config]) + if test -z "$WAYLAND_PROTOCOLS_DATADIR" -a -n "$PKG_CONFIG" + then + WAYLAND_PROTOCOLS_DATADIR=`$PKG_CONFIG --atleast-version=1.14 wayland-protocols && \ + $PKG_CONFIG --variable=pkgdatadir wayland-protocols` + fi + 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"], - [Wayland ${notice_platform}development files not found, the Wayland driver won't be supported.], +WINE_NOTICE_WITH(wayland, [test -z "$WAYLAND_CLIENT_LIBS" || + test -z "$WAYLAND_PROTOCOLS_DATADIR" || + test -z "$WAYLAND_SCANNER"], + [Wayland ${notice_platform}development files not found or not new enough, the Wayland driver won't be supported.], [enable_winewayland_drv])
dnl **** Check for OpenCL **** diff --git a/dlls/winewayland.drv/Makefile.in b/dlls/winewayland.drv/Makefile.in index d86b51a519f..824c594bc98 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 = \ + $(WAYLAND_PROTOCOLS_DATADIR)/unstable/xdg-output/xdg-output-unstable-v1.xml + RC_SRCS = version.rc diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index 104a091ea80..30ef22df52d 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 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 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 diff --git a/tools/gitlab/image.docker b/tools/gitlab/image.docker index cf16ed49c95..7e8d69170c1 100644 --- a/tools/gitlab/image.docker +++ b/tools/gitlab/image.docker @@ -51,6 +51,7 @@ RUN export DEBIAN_FRONTEND=noninteractive; \ ocl-icd-opencl-dev:amd64 ocl-icd-opencl-dev:i386 \ samba-dev:amd64 \ unixodbc-dev:amd64 unixodbc-dev:i386 \ + wayland-protocols \ x11proto-dev && \ apt-get install -y ccache netbase curl ca-certificates xserver-xorg-video-dummy xserver-xorg xfonts-base xinit fvwm \ winbind fonts-liberation2 fonts-noto-core fonts-noto-cjk pulseaudio libasound2-plugins:amd64 libasound2-plugins:i386 \
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Implement the GetCurrentDisplaySettings driver callback by reading display device information from a memory region shared between all processes.
The desktop window process is responsible for maintaining the information in this region, thus providing an authoritative version of display device information, which is also in sync with the Windows configuration, for all other processes to use.
Wayland doesn't provide a mechanism to get the latest output information in a cross-process consistent form from some central point, instead relying on events from which each client builds its own view of the current configuration. Without some single source of truth like the one provided by this shared memory region, it's challenging to maintain consistency between processes in terms of current configuration and mappings from wl_outputs to to Windows monitors.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/Makefile.in | 2 +- dlls/winewayland.drv/display.c | 198 +++++++++++++++++++++++-- dlls/winewayland.drv/waylanddrv.h | 3 + dlls/winewayland.drv/waylanddrv_main.c | 2 + 4 files changed, 188 insertions(+), 17 deletions(-)
diff --git a/dlls/winewayland.drv/Makefile.in b/dlls/winewayland.drv/Makefile.in index 824c594bc98..fd122a04263 100644 --- a/dlls/winewayland.drv/Makefile.in +++ b/dlls/winewayland.drv/Makefile.in @@ -1,7 +1,7 @@ MODULE = winewayland.drv UNIXLIB = winewayland.so UNIX_CFLAGS = $(WAYLAND_CLIENT_CFLAGS) -UNIX_LIBS = -lwin32u $(WAYLAND_CLIENT_LIBS) +UNIX_LIBS = -lwin32u $(WAYLAND_CLIENT_LIBS) $(PTHREAD_LIBS)
C_SRCS = \ display.c \ diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index e72b26a9da0..640829142c1 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -30,10 +30,77 @@
#include "ntuser.h"
+#include <pthread.h> + WINE_DEFAULT_DEBUG_CHANNEL(waylanddrv);
static BOOL force_display_devices_refresh;
+struct output_info +{ + char name[128]; + struct wayland_output_mode modes[128]; + int num_modes; + int current_mode; +}; + +struct display_devices +{ + struct output_info outputs[16]; + int num_outputs; + pthread_mutex_t mutex; +}; + +static HANDLE display_devices_handle; +static struct display_devices *display_devices; + +BOOL wayland_display_devices_process_init(void) +{ + OBJECT_ATTRIBUTES attr; + LARGE_INTEGER size; + SIZE_T count = 0; + WCHAR name[] = {'\','?','?','\','W','a','y','l','a','n','d', + 'D','i','s','p','l','a','y','D','e','v','i','c','e','s'}; + UNICODE_STRING nameW = {sizeof(name), sizeof(name), name}; + NTSTATUS status; + + size.QuadPart = sizeof(*display_devices); + InitializeObjectAttributes(&attr, &nameW, OBJ_OPENIF, NULL, NULL); + status = NtCreateSection(&display_devices_handle, + SECTION_MAP_READ | SECTION_MAP_WRITE, + &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0); + if (status != 0 && !(status & ERROR_SEVERITY_INFORMATIONAL)) + { + ERR("Failed to create or open WaylandDisplayDevices shared memory\n"); + return FALSE; + } + + if (NtMapViewOfSection(display_devices_handle, GetCurrentProcess(), + (PVOID)&display_devices, 0, 0, + NULL, &count, ViewShare, 0, PAGE_READWRITE)) + { + ERR("Failed to map WaylandDisplayDevices shared memory\n"); + return FALSE; + } + + /* Initialize the shared memory contents if we just created it. */ + if (status == 0) + { + pthread_mutexattr_t mutexattr; + + pthread_mutexattr_init(&mutexattr); + pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_DEFAULT); + pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED); + pthread_mutex_init(&display_devices->mutex, &mutexattr); + pthread_mutexattr_destroy(&mutexattr); + } + + TRACE("status=0x%lx handle=%p map=%p\n", + (long)status, display_devices_handle, display_devices); + + return TRUE; +} + static void wayland_refresh_display_devices(void) { UINT32 num_path, num_mode; @@ -85,13 +152,12 @@ 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}; + struct wayland_output_mode *mode = &output_info->modes[output_info->current_mode];
- SetRect(&monitor.rc_monitor, 0, 0, - output->current_mode->width, - output->current_mode->height); + SetRect(&monitor.rc_monitor, 0, 0, mode->width, mode->height);
/* We don't have a direct way to get the work area in Wayland. */ monitor.rc_work = monitor.rc_monitor; @@ -99,7 +165,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->name, wine_dbgstr_rect(&monitor.rc_monitor), (UINT)monitor.state_flags);
device_manager->add_monitor(&monitor, param); @@ -118,26 +184,52 @@ 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; + int i;
- RB_FOR_EACH_ENTRY(output_mode, &output->modes, struct wayland_output_mode, entry) + for (i = 0; i < output_info->num_modes; i++) { DEVMODEW mode; - populate_devmode(output_mode, &mode); + populate_devmode(&output_info->modes[i], &mode); device_manager->add_mode(&mode, param); } }
+static void display_devices_update_output(struct output_info *output_info, + struct wayland_output *output) +{ + struct wayland_output_mode *mode; + int mode_i = 0; + + lstrcpynA(output_info->name, output->name, sizeof(output_info->name)); + if (strlen(output_info->name) != strlen(output->name)) + WARN("wayland output name %s is too long, truncating\n", output->name); + + RB_FOR_EACH_ENTRY(mode, &output->modes, struct wayland_output_mode, entry) + { + if (mode_i >= ARRAYSIZE(output_info->modes)) + { + WARN("wayland reported too many modes for %s, ignoring\n", + output->name); + continue; + } + output_info->modes[mode_i] = *mode; + if (mode == output->current_mode) output_info->current_mode = mode_i; + mode_i++; + } + + output_info->num_modes = mode_i; +} + /*********************************************************************** * UpdateDisplayDevices (WAYLAND.@) */ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manager, BOOL force, void *param) { - struct wayland_output *output; - INT output_id = 0; + INT output_id; + BOOL update_from_wayland = force_display_devices_refresh;
if (!force && !force_display_devices_refresh) return TRUE;
@@ -147,14 +239,88 @@ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manage
wayland_add_device_gpu(device_manager, param);
- wl_list_for_each(output, &process_wayland->output_list, link) + pthread_mutex_lock(&display_devices->mutex); + + /* Update shared display device information from Wayland information. + * This should only happen from the desktop window process. */ + if (update_from_wayland) { - if (!output->current_mode) continue; + struct wayland_output *output; + + output_id = 0; + + wl_list_for_each(output, &process_wayland->output_list, link) + { + if (!output->current_mode) continue; + if (output_id >= ARRAYSIZE(display_devices->outputs)) + { + WARN("wayland reported too many outputs, ignoring %s\n", + output->name); + continue; + } + display_devices_update_output(&display_devices->outputs[output_id], + output); + output_id++; + } + + display_devices->num_outputs = output_id; + } + + /* Update gdi devices from shared display device information. */ + for (output_id = 0; output_id < display_devices->num_outputs; output_id++) + { + struct output_info *output_info = &display_devices->outputs[output_id]; 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); - output_id++; + wayland_add_device_monitor(device_manager, param, output_info); + wayland_add_device_modes(device_manager, param, output_info); }
+ pthread_mutex_unlock(&display_devices->mutex); + + return TRUE; +} + +/*********************************************************************** + * GetCurrentDisplaySettings (WAYLAND.@) + * + */ +BOOL WAYLAND_GetCurrentDisplaySettings(LPCWSTR name, BOOL is_primary, LPDEVMODEW devmode) +{ + int display_index; + WCHAR *end; + struct output_info *output_info; + + TRACE("(%s,%p)\n", debugstr_w(name), devmode); + + display_index = wcstol(name + 11, &end, 10) - 1; + if (*end) + { + ERR("Failed to parse display device name %s\n", wine_dbgstr_w(name)); + return FALSE; + } + + pthread_mutex_lock(&display_devices->mutex); + + if (display_index >= display_devices->num_outputs) + { + pthread_mutex_unlock(&display_devices->mutex); + ERR("Failed to get information for %s\n", wine_dbgstr_w(name)); + return FALSE; + } + + output_info = &display_devices->outputs[display_index]; + populate_devmode(&output_info->modes[output_info->current_mode], devmode); + + pthread_mutex_unlock(&display_devices->mutex); + + devmode->dmFields |= DM_POSITION; + devmode->dmPosition.x = 0; + devmode->dmPosition.y = 0; + + TRACE("=> %d,%d+%ux%u@%u %ubpp\n", + (int)devmode->dmPosition.x, (int)devmode->dmPosition.y, + (UINT)devmode->dmPelsWidth, (UINT)devmode->dmPelsHeight, + (UINT)devmode->dmDisplayFrequency, (UINT)devmode->dmBitsPerPel); + return TRUE; } diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index da0fccecda9..794cff2b0dd 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -78,6 +78,7 @@ struct wayland_output */
BOOL wayland_process_init(void) DECLSPEC_HIDDEN; +BOOL wayland_display_devices_process_init(void) DECLSPEC_HIDDEN; void wayland_init_display_devices(void) DECLSPEC_HIDDEN;
/********************************************************************** @@ -92,6 +93,8 @@ void wayland_output_use_xdg_extension(struct wayland_output *output) DECLSPEC_HI * 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..d83314cd74f 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, };
@@ -40,6 +41,7 @@ static NTSTATUS waylanddrv_unix_init(void *arg) * our initialization. We clear them on error. */ __wine_set_user_driver(&waylanddrv_funcs, WINE_GDI_DRIVER_VERSION);
+ if (!wayland_display_devices_process_init()) goto err; if (!wayland_process_init()) goto err;
return 0;
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Since non-desktop processes rely on the shared memory region 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 | 11 +---------- dlls/winewayland.drv/wayland.c | 3 +++ dlls/winewayland.drv/waylanddrv.h | 6 ++++++ dlls/winewayland.drv/waylanddrv_main.c | 25 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index 640829142c1..354e10162ca 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -111,16 +111,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, diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index 30ef22df52d..2eb58fb7139 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 794cff2b0dd..2f1a83ee542 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -89,6 +89,12 @@ 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 + */ + +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 d83314cd74f..cb9702c4564 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
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 | 40 +++++++-- dlls/winewayland.drv/wayland_output.c | 125 +++++++++++++++++++++++++- dlls/winewayland.drv/waylanddrv.h | 3 + 3 files changed, 160 insertions(+), 8 deletions(-)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index 354e10162ca..e9fac1dad47 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -42,6 +42,7 @@ struct output_info struct wayland_output_mode modes[128]; int num_modes; int current_mode; + int x, y; };
struct display_devices @@ -101,6 +102,19 @@ BOOL wayland_display_devices_process_init(void) return TRUE; }
+static struct wayland_output *wayland_get_primary_output(void) +{ + struct wayland_output *output; + + wl_list_for_each(output, &process_wayland->output_list, link) + { + if (output->current_mode && output->x == 0 && output->y == 0) + return output; + } + + return NULL; +} + static void wayland_refresh_display_devices(void) { UINT32 num_path, num_mode; @@ -148,7 +162,8 @@ static void wayland_add_device_monitor(const struct gdi_device_manager *device_m struct gdi_monitor monitor = {0}; struct wayland_output_mode *mode = &output_info->modes[output_info->current_mode];
- SetRect(&monitor.rc_monitor, 0, 0, mode->width, mode->height); + SetRect(&monitor.rc_monitor, output_info->x, output_info->y, + output_info->x + mode->width, output_info->y + mode->height);
/* We don't have a direct way to get the work area in Wayland. */ monitor.rc_work = monitor.rc_monitor; @@ -211,6 +226,9 @@ static void display_devices_update_output(struct output_info *output_info, }
output_info->num_modes = mode_i; + + output_info->x = output->x; + output_info->y = output->y; }
/*********************************************************************** @@ -236,13 +254,21 @@ BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manage * This should only happen from the desktop window process. */ if (update_from_wayland) { - struct wayland_output *output; + struct wayland_output *output, *primary;
output_id = 0;
+ /* Add the primary output (i.e., positioned at 0,0) first. */ + if ((primary = wayland_get_primary_output())) + { + display_devices_update_output(&display_devices->outputs[output_id], + primary); + output_id++; + } + wl_list_for_each(output, &process_wayland->output_list, link) { - if (!output->current_mode) continue; + if (!output->current_mode || output == primary) continue; if (output_id >= ARRAYSIZE(display_devices->outputs)) { WARN("wayland reported too many outputs, ignoring %s\n", @@ -302,11 +328,11 @@ BOOL WAYLAND_GetCurrentDisplaySettings(LPCWSTR name, BOOL is_primary, LPDEVMODEW output_info = &display_devices->outputs[display_index]; populate_devmode(&output_info->modes[output_info->current_mode], devmode);
- pthread_mutex_unlock(&display_devices->mutex); - devmode->dmFields |= DM_POSITION; - devmode->dmPosition.x = 0; - devmode->dmPosition.y = 0; + devmode->dmPosition.x = output_info->x; + devmode->dmPosition.y = output_info->y; + + pthread_mutex_unlock(&display_devices->mutex);
TRACE("=> %d,%d+%ux%u@%u %ubpp\n", (int)devmode->dmPosition.x, (int)devmode->dmPosition.y, diff --git a/dlls/winewayland.drv/wayland_output.c b/dlls/winewayland.drv/wayland_output.c index 8eb24fe97f3..717341d678e 100644 --- a/dlls/winewayland.drv/wayland_output.c +++ b/dlls/winewayland.drv/wayland_output.c @@ -97,11 +97,126 @@ static void wayland_output_add_mode(struct wayland_output *output, if (current) output->current_mode = mode; }
+static int wayland_output_cmp_x(const void *va, const void *vb) +{ + const struct wayland_output *a = va; + const struct wayland_output *b = vb; + + if (a->logical_x < b->logical_x) return -1; + if (a->logical_x > b->logical_x) return 1; + if (a->logical_y < b->logical_y) return -1; + if (a->logical_y > b->logical_y) return 1; + return 0; +} + +static int wayland_output_cmp_y(const void *va, const void *vb) +{ + const struct wayland_output *a = va; + const struct wayland_output *b = vb; + + if (a->logical_y < b->logical_y) return -1; + if (a->logical_y > b->logical_y) return 1; + if (a->logical_x < b->logical_x) return -1; + if (a->logical_x > b->logical_x) return 1; + return 0; +} + +static struct wayland_output** wayland_output_list_sorted(struct wl_list *output_list, + int (*cmp)(const void *, const void *)) +{ + int num_outputs = wl_list_length(output_list); + struct wayland_output **sorted; + struct wayland_output *o; + int i = 0; + + sorted = malloc(sizeof(*sorted) * (num_outputs + 1)); + if (!sorted) + { + ERR("Couldn't allocate space for sorted outputs\n"); + return NULL; + } + + wl_list_for_each(o, output_list, link) sorted[i++] = o; + + qsort(sorted, num_outputs, sizeof(*sorted), cmp); + + sorted[num_outputs] = NULL; + return sorted; +} + +static void wayland_output_list_update_physical_coords(struct wl_list *output_list) +{ + struct wayland_output **sorted_x, **sorted_y; + struct wayland_output **cur_p, **prev_p; + struct wayland_output *cur, *prev; + + /* Set default physical coordinates. */ + wl_list_for_each(cur, output_list, link) + { + cur->x = cur->logical_x; + cur->y = cur->logical_y; + } + + /* Sort and process the outputs from left to right. */ + cur_p = sorted_x = wayland_output_list_sorted(output_list, wayland_output_cmp_x); + if (!sorted_x) return; + + while ((cur = *cur_p)) + { + /* Update output->x based on other outputs that are to to the left. */ + prev_p = sorted_x; + while ((prev = *prev_p) != cur) + { + if (cur->logical_x == prev->logical_x + prev->logical_w && + prev->current_mode) + { + int new_x = prev->x + prev->current_mode->width; + if (new_x > cur->x) cur->x = new_x; + } + prev_p++; + } + + cur_p++; + } + + free(sorted_x); + + /* Now sort and process the outputs from top to bottom. */ + cur_p = sorted_y = wayland_output_list_sorted(output_list, wayland_output_cmp_y); + if (!sorted_y) return; + + while ((cur = *cur_p)) + { + /* Update output->y based on other outputs that are above. */ + prev_p = sorted_y; + while ((prev = *prev_p) != cur) + { + if (cur->logical_y == prev->logical_y + prev->logical_h && + prev->current_mode) + { + int new_y = prev->y + prev->current_mode->height; + if (new_y > cur->y) cur->y = new_y; + } + prev_p++; + } + + cur_p++; + } + + free(sorted_y); +} + 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 physical=%d,%d+%dx%d\n", + output->name, output->logical_x, output->logical_y, + output->logical_w, output->logical_h, + output->x, output->y, + output->current_mode->width, output->current_mode->height); + + wayland_output_list_update_physical_coords(&process_wayland->output_list);
RB_FOR_EACH_ENTRY(mode, &output->modes, struct wayland_output_mode, entry) { @@ -163,6 +278,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 +289,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 2f1a83ee542..492976a5070 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -70,6 +70,9 @@ 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 */ + int x, y; /* position in physical pixel coordinate space */ uint32_t global_id; };
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/display.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index e9fac1dad47..8c637e35442 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -123,9 +123,48 @@ static void wayland_refresh_display_devices(void) NtUserGetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &num_path, &num_mode); }
+/* Initialize registry display settings when new display devices are added */ +static void wayland_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), (UINT)dm.dmPelsWidth, (UINT)dm.dmPelsHeight, + (UINT)dm.dmBitsPerPel, (UINT)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); + } + } +} + void wayland_init_display_devices(void) { wayland_refresh_display_devices(); + wayland_init_registry_display_settings(); }
static void wayland_add_device_gpu(const struct gdi_device_manager *device_manager,
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Update the desktop window size to match the current virtual screen rect.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- dlls/winewayland.drv/Makefile.in | 3 +- dlls/winewayland.drv/display.c | 3 ++ dlls/winewayland.drv/waylanddrv.h | 15 +++++++- dlls/winewayland.drv/waylanddrv_main.c | 7 ++-- dlls/winewayland.drv/window.c | 50 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 dlls/winewayland.drv/window.c
diff --git a/dlls/winewayland.drv/Makefile.in b/dlls/winewayland.drv/Makefile.in index fd122a04263..eed55dfe44e 100644 --- a/dlls/winewayland.drv/Makefile.in +++ b/dlls/winewayland.drv/Makefile.in @@ -8,7 +8,8 @@ C_SRCS = \ dllmain.c \ wayland.c \ wayland_output.c \ - waylanddrv_main.c + waylanddrv_main.c \ + window.c
WAYLAND_PROTOCOL_SRCS = \ $(WAYLAND_PROTOCOLS_DATADIR)/unstable/xdg-output/xdg-output-unstable-v1.xml diff --git a/dlls/winewayland.drv/display.c b/dlls/winewayland.drv/display.c index 8c637e35442..aa75cc25057 100644 --- a/dlls/winewayland.drv/display.c +++ b/dlls/winewayland.drv/display.c @@ -163,8 +163,11 @@ static void wayland_init_registry_display_settings(void)
void wayland_init_display_devices(void) { + HWND desktop_hwnd = get_desktop_window(); + wayland_refresh_display_devices(); wayland_init_registry_display_settings(); + if (desktop_hwnd) send_message(desktop_hwnd, WM_DISPLAYCHANGE, 0, 0); }
static void wayland_add_device_gpu(const struct gdi_device_manager *device_manager, diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 492976a5070..38501b470e7 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -96,12 +96,25 @@ void wayland_output_use_xdg_extension(struct wayland_output *output) DECLSPEC_HI * USER32 helpers */
-DWORD get_desktop_process_id(void) DECLSPEC_HIDDEN; +HWND get_desktop_window(void) DECLSPEC_HIDDEN; + +static inline DWORD get_desktop_process_id(void) +{ + DWORD desktop_pid; + return NtUserGetWindowThread(get_desktop_window(), &desktop_pid) ? + desktop_pid : GetCurrentProcessId(); +} + +static inline LRESULT send_message(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + return NtUserMessageCall(hwnd, msg, wparam, lparam, NULL, NtUserSendDriverMessage, FALSE); +}
/********************************************************************** * USER driver functions */
+LRESULT WAYLAND_DesktopWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) DECLSPEC_HIDDEN; BOOL WAYLAND_GetCurrentDisplaySettings(LPCWSTR name, BOOL is_primary, LPDEVMODEW devmode) DECLSPEC_HIDDEN; BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manager, diff --git a/dlls/winewayland.drv/waylanddrv_main.c b/dlls/winewayland.drv/waylanddrv_main.c index cb9702c4564..d267e43068c 100644 --- a/dlls/winewayland.drv/waylanddrv_main.c +++ b/dlls/winewayland.drv/waylanddrv_main.c @@ -31,11 +31,10 @@
#include "waylanddrv.h"
-DWORD get_desktop_process_id(void) +HWND get_desktop_window(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. */ @@ -50,12 +49,12 @@ DWORD get_desktop_process_id(void) SERVER_END_REQ; }
- return NtUserGetWindowThread(desktop_hwnd, &desktop_pid) ? - desktop_pid : GetCurrentProcessId(); + return desktop_hwnd; }
static const struct user_driver_funcs waylanddrv_funcs = { + .pDesktopWindowProc = WAYLAND_DesktopWindowProc, .pGetCurrentDisplaySettings = WAYLAND_GetCurrentDisplaySettings, .pUpdateDisplayDevices = WAYLAND_UpdateDisplayDevices, }; diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c new file mode 100644 index 00000000000..7d56d9b3b02 --- /dev/null +++ b/dlls/winewayland.drv/window.c @@ -0,0 +1,50 @@ +/* + * Window related functions + * + * Copyright 2020 Alexandros Frantzis for Collabora Ltd + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#include "config.h" + +#include "waylanddrv.h" + +#include "ntuser.h" + +/********************************************************************** + * WAYLAND_DesktopWindowProc + */ +LRESULT WAYLAND_DesktopWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) +{ + switch (msg) + { + case WM_DISPLAYCHANGE: + { + RECT virtual_rect = NtUserGetVirtualScreenRect(); + NtUserSetWindowPos(hwnd, 0, virtual_rect.left, virtual_rect.top, + virtual_rect.right - virtual_rect.left, + virtual_rect.bottom - virtual_rect.top, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE); + } + break; + } + + return NtUserMessageCall(hwnd, msg, wp, lp, 0, NtUserDefWindowProc, FALSE); +}
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 makedep changes to gracefully handle the case these external sources are missing when the driver is disabled. These changes are introduced on their own in the first commit in the series, but we can squash it with the next commit, where the functionality is first used, if preferred.
I don't think that that sort of thing belongs in makedep, we should never have dependencies to files outside of the source tree. Ideally we'd simply ship the generated files like we do for OpenGL, Vulkan, etc.
I don't think that that sort of thing belongs in makedep, we should never have dependencies to files outside of the source tree.
Although using the external wayland-protocols dependency is the standard way of dealing with protocols for most projects, it's also absolutely fine to vendor protocol .xml sources if preferred. Since this is the preference for Wine, I will update the MR to include any protocol .xml files as internal driver sources.
Ideally we'd simply ship the generated files like we do for OpenGL, Vulkan, etc.
The .c/.h sources generated by wayland-scanner for the .xml files are only guaranteed to be compatible with the matching libwayland version or any newer version, but not older versions. If we include generated sources, we are effectively forcing an artificial minimum version requirement on libwayland. I say artificial, because normally the Wayland clients only directly use the more public/high-level APIs, so any additional version requirement stemming from the use of lower level marshalling APIs is both implicit and likely not intended.
One possibility would be to use an older version of the wayland-scanner to pre-generate files, so that we support a wider range of versions, but then we will be forcing all users to miss out on any marshalling related fixes and improvements from newer versions, even if they have a libwayland that supports them.
Generating the .c/.h files at build time moves the minimum version decision to that time, allowing users/distributions to use the latest version that is available to them.
Do you think the outlined approach of vendoring protocol .xml files, but still generating .c/.h at build time would be acceptable?
On Thu Mar 23 11:12:30 2023 +0000, Alexandros Frantzis wrote:
I don't think that that sort of thing belongs in makedep, we should
never have dependencies to files outside of the source tree. Although using the external wayland-protocols dependency is the standard way of dealing with protocols for most projects, it's also absolutely fine to vendor protocol .xml sources if preferred. Since this is the preference for Wine, I will update the MR to include any protocol .xml files as internal driver sources.
Ideally we'd simply ship the generated files like we do for OpenGL,
Vulkan, etc. The .c/.h sources generated by wayland-scanner for the .xml files are only guaranteed to be compatible with the matching libwayland version or any newer version, but not older versions. If we include generated sources, we are effectively forcing an artificial minimum version requirement on libwayland. I say artificial, because normally the Wayland clients only directly use the more public/high-level APIs, so any additional version requirement stemming from the use of lower level marshalling APIs is both implicit and likely not intended. One possibility would be to use an older version of the wayland-scanner to pre-generate files, so that we support a wider range of versions, but then we will be forcing all users to miss out on any marshalling related fixes and improvements from newer versions, even if they have a libwayland that supports them. Generating the .c/.h files at build time moves the minimum version decision to that time, allowing users/distributions to use the latest version that is available to them. Do you think the outlined approach of vendoring protocol .xml files, but still generating .c/.h at build time would be acceptable?
The problem is that if we stick to using an old version of the protocols, we will not be able to use new protocols that fills the gaps Wine may need to functions properly without resorting to using any weird workaround that work half of the time.
Since Wayland is currently evolving rapidly, and many issues were recently addressed in the Wayland protocol, I think **sticking to an old version of the protocol is not a good solution**, as it will prevent Wine to collaborate with the Wayland project to fix any issues that require Wayland protocol change.
But I also understand the worry of @julliard of wanting to make Wine source code as easy to maintain and as stable as possible.
I think the best solution would be to have a custom version `wayland-scanner` that can generate backward compatible code that still support the latest protocols, but I know **it's probably too much work** compared to just using the `wayland-scanner` and the external `wayland-protocols` dependency.
If using a vendor protocol `.xml` with the latest protocols and it can generate backward compatible code with the unmodified outdated `wayland-scanner` version this would be the best solution, but even in this situation **compatibility can be an issue.**
I'm my opinion using the distribution protocol `.xml` **(Current way it's implemented) seems the best solution** that require the less effort to maintain for Wine in the long term, and since it also the way most project already work so it will be easier to find support from the community to maintain the Wayland driver.
The problem is that if we stick to using an old version of the protocols, we will not be able to use new protocols that fills the gaps Wine may need to functions properly without resorting to using any weird workaround that work half of the time.
If there is an updated protocol version (or a new protocol), we would need to take explicit action, both to use it in the code and also to ensure we can access the updated protocol sources. If we use wayland-protocols we would need to depend on a newer package version that ships the files we need. If we vendor the protocol .xml file we would need to manually copy the new file to the driver sources. In both cases the process is straightforward, so I am not really concerned either way. Note that Wayland protocols have strong backward compatibility guarantees, so bringing in an updated (minor) version of a protocol .xml still allows us to use all older features.
If using a vendor protocol .xml with the latest protocols and it can generate backward compatible code with the unmodified outdated wayland-scanner version this would be the best solution, but even in this situation compatibility can be an issue.
At the moment at least, all (non-ancient) versions of wayland-scanner can generate .c/.h code for all current protocols. In the unlikely case that this changes and there is a protocol that requires a particular wayland-scanner version, and we absolutely need to have it, we will just have to introduce a minimum libwayland/wayland-scanner dependency.
For now, the only dependency we have to deal with is that the .c/.h protocol code generated by a wayland-scanner version is only guaranteed to work with the matching libwayland or newer.
Vendoring (or not) is completely orthogonal to all of the above, it's just a matter of where one gets the protocol .xml files from.
From what I understand of the summary, the GetCurrentDisplaySettings implementation can be inconsistent and relies on figuring out everything the compositor supports by guessing. Have you bugged the Wayland devs about adding some protocols to support viewing the display specifications?
This might go against their design choices, but it's not much of a danger since applications can't self position or control other windows, it would just be asking the compositor what displays are available and what modes they support. Maybe on top of that you could allow choosing a display to output to (rather than exact positioning, it's just a general "I want to be on this display") which would work well for games, as they tend to have display settings there to see what they can do.