2019-06-10 14:07:02 +00:00
|
|
|
/*
|
|
|
|
* X11DRV display device functions
|
|
|
|
*
|
|
|
|
* Copyright 2019 Zhiyi Zhang for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2022-05-01 10:41:31 +00:00
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
|
|
|
|
2019-06-10 14:07:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "x11drv.h"
|
2022-02-18 12:37:29 +00:00
|
|
|
#include "wine/debug.h"
|
2019-06-10 14:07:02 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
|
|
|
|
|
2019-11-05 13:04:27 +00:00
|
|
|
static struct x11drv_display_device_handler host_handler;
|
|
|
|
struct x11drv_display_device_handler desktop_handler;
|
2022-05-20 12:14:33 +00:00
|
|
|
static struct x11drv_settings_handler settings_handler;
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
#define NEXT_DEVMODEW(mode) ((DEVMODEW *)((char *)((mode) + 1) + (mode)->dmDriverExtra))
|
2022-05-20 12:14:33 +00:00
|
|
|
|
|
|
|
struct x11drv_display_depth
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
ULONG_PTR display_id;
|
|
|
|
DWORD depth;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Display device emulated depth list, protected by modes_section */
|
|
|
|
static struct list x11drv_display_depth_list = LIST_INIT(x11drv_display_depth_list);
|
|
|
|
|
|
|
|
/* All Windows drivers seen so far either support 32 bit depths, or 24 bit depths, but never both. So if we have
|
|
|
|
* a 32 bit framebuffer, report 32 bit bpps, otherwise 24 bit ones.
|
|
|
|
*/
|
|
|
|
static const unsigned int depths_24[] = {8, 16, 24};
|
|
|
|
static const unsigned int depths_32[] = {8, 16, 32};
|
|
|
|
const unsigned int *depths;
|
|
|
|
|
|
|
|
/* Cached display modes for a device, protected by modes_section */
|
|
|
|
static WCHAR cached_device_name[CCHDEVICENAME];
|
|
|
|
static DWORD cached_flags;
|
|
|
|
static DEVMODEW *cached_modes;
|
|
|
|
static UINT cached_mode_count;
|
|
|
|
|
|
|
|
static pthread_mutex_t settings_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
void X11DRV_Settings_SetHandler(const struct x11drv_settings_handler *new_handler)
|
|
|
|
{
|
|
|
|
if (new_handler->priority > settings_handler.priority)
|
|
|
|
{
|
|
|
|
settings_handler = *new_handler;
|
|
|
|
TRACE("Display settings are now handled by: %s.\n", settings_handler.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Default handlers if resolution switching is not enabled
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL nores_get_id(const WCHAR *device_name, ULONG_PTR *id)
|
|
|
|
{
|
|
|
|
WCHAR primary_adapter[CCHDEVICENAME];
|
|
|
|
|
|
|
|
if (!get_primary_adapter( primary_adapter ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*id = !wcsicmp( device_name, primary_adapter ) ? 1 : 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL nores_get_modes(ULONG_PTR id, DWORD flags, DEVMODEW **new_modes, UINT *mode_count)
|
|
|
|
{
|
|
|
|
RECT primary = get_host_primary_monitor_rect();
|
|
|
|
DEVMODEW *modes;
|
|
|
|
|
|
|
|
modes = calloc(1, sizeof(*modes));
|
|
|
|
if (!modes)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
modes[0].dmSize = sizeof(*modes);
|
|
|
|
modes[0].dmDriverExtra = 0;
|
|
|
|
modes[0].dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT |
|
|
|
|
DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY;
|
|
|
|
modes[0].dmDisplayOrientation = DMDO_DEFAULT;
|
|
|
|
modes[0].dmBitsPerPel = screen_bpp;
|
|
|
|
modes[0].dmPelsWidth = primary.right;
|
|
|
|
modes[0].dmPelsHeight = primary.bottom;
|
|
|
|
modes[0].dmDisplayFlags = 0;
|
|
|
|
modes[0].dmDisplayFrequency = 60;
|
|
|
|
|
|
|
|
*new_modes = modes;
|
|
|
|
*mode_count = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nores_free_modes(DEVMODEW *modes)
|
|
|
|
{
|
|
|
|
free(modes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL nores_get_current_mode(ULONG_PTR id, DEVMODEW *mode)
|
|
|
|
{
|
|
|
|
RECT primary = get_host_primary_monitor_rect();
|
|
|
|
|
|
|
|
mode->dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT |
|
|
|
|
DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY | DM_POSITION;
|
|
|
|
mode->dmDisplayOrientation = DMDO_DEFAULT;
|
|
|
|
mode->dmDisplayFlags = 0;
|
|
|
|
mode->dmPosition.x = 0;
|
|
|
|
mode->dmPosition.y = 0;
|
|
|
|
|
|
|
|
if (id != 1)
|
|
|
|
{
|
|
|
|
FIXME("Non-primary adapters are unsupported.\n");
|
|
|
|
mode->dmBitsPerPel = 0;
|
|
|
|
mode->dmPelsWidth = 0;
|
|
|
|
mode->dmPelsHeight = 0;
|
|
|
|
mode->dmDisplayFrequency = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode->dmBitsPerPel = screen_bpp;
|
|
|
|
mode->dmPelsWidth = primary.right;
|
|
|
|
mode->dmPelsHeight = primary.bottom;
|
|
|
|
mode->dmDisplayFrequency = 60;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-07-29 12:02:42 +00:00
|
|
|
static LONG nores_set_current_mode(ULONG_PTR id, const DEVMODEW *mode)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
WARN("NoRes settings handler, ignoring mode change request.\n");
|
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default handler only gets the current X desktop resolution */
|
|
|
|
void X11DRV_Settings_Init(void)
|
|
|
|
{
|
|
|
|
struct x11drv_settings_handler nores_handler;
|
|
|
|
|
|
|
|
depths = screen_bpp == 32 ? depths_32 : depths_24;
|
|
|
|
|
|
|
|
nores_handler.name = "NoRes";
|
|
|
|
nores_handler.priority = 1;
|
|
|
|
nores_handler.get_id = nores_get_id;
|
|
|
|
nores_handler.get_modes = nores_get_modes;
|
|
|
|
nores_handler.free_modes = nores_free_modes;
|
|
|
|
nores_handler.get_current_mode = nores_get_current_mode;
|
|
|
|
nores_handler.set_current_mode = nores_set_current_mode;
|
|
|
|
X11DRV_Settings_SetHandler(&nores_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize registry display settings when new display devices are added */
|
|
|
|
void init_registry_display_settings(void)
|
|
|
|
{
|
|
|
|
DEVMODEW dm = {.dmSize = sizeof(dm)};
|
|
|
|
DISPLAY_DEVICEW dd = {sizeof(dd)};
|
|
|
|
UNICODE_STRING device_name;
|
|
|
|
DWORD i = 0;
|
|
|
|
LONG 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), dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel,
|
|
|
|
dm.dmDisplayFrequency, dm.dmPosition.x, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL get_primary_adapter(WCHAR *name)
|
|
|
|
{
|
|
|
|
DISPLAY_DEVICEW dd;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
dd.cb = sizeof(dd);
|
|
|
|
for (i = 0; !NtUserEnumDisplayDevices( NULL, i, &dd, 0 ); ++i)
|
|
|
|
{
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
|
|
|
{
|
|
|
|
lstrcpyW(name, dd.DeviceName);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mode_compare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
DWORD a_width, a_height, b_width, b_height;
|
|
|
|
const DEVMODEW *a = p1, *b = p2;
|
|
|
|
|
|
|
|
/* Use the width and height in landscape mode for comparison */
|
|
|
|
if (a->dmDisplayOrientation == DMDO_DEFAULT || a->dmDisplayOrientation == DMDO_180)
|
|
|
|
{
|
|
|
|
a_width = a->dmPelsWidth;
|
|
|
|
a_height = a->dmPelsHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_width = a->dmPelsHeight;
|
|
|
|
a_height = a->dmPelsWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b->dmDisplayOrientation == DMDO_DEFAULT || b->dmDisplayOrientation == DMDO_180)
|
|
|
|
{
|
|
|
|
b_width = b->dmPelsWidth;
|
|
|
|
b_height = b->dmPelsHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b_width = b->dmPelsHeight;
|
|
|
|
b_height = b->dmPelsWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Depth in descending order */
|
|
|
|
if (a->dmBitsPerPel != b->dmBitsPerPel)
|
|
|
|
return b->dmBitsPerPel - a->dmBitsPerPel;
|
|
|
|
|
|
|
|
/* Width in ascending order */
|
|
|
|
if (a_width != b_width)
|
|
|
|
return a_width - b_width;
|
|
|
|
|
|
|
|
/* Height in ascending order */
|
|
|
|
if (a_height != b_height)
|
|
|
|
return a_height - b_height;
|
|
|
|
|
|
|
|
/* Frequency in descending order */
|
|
|
|
if (a->dmDisplayFrequency != b->dmDisplayFrequency)
|
|
|
|
return b->dmDisplayFrequency - a->dmDisplayFrequency;
|
|
|
|
|
|
|
|
/* Orientation in ascending order */
|
|
|
|
return a->dmDisplayOrientation - b->dmDisplayOrientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_display_depth(ULONG_PTR display_id, DWORD depth)
|
|
|
|
{
|
|
|
|
struct x11drv_display_depth *display_depth;
|
|
|
|
|
|
|
|
pthread_mutex_lock( &settings_mutex );
|
|
|
|
LIST_FOR_EACH_ENTRY(display_depth, &x11drv_display_depth_list, struct x11drv_display_depth, entry)
|
|
|
|
{
|
|
|
|
if (display_depth->display_id == display_id)
|
|
|
|
{
|
|
|
|
display_depth->depth = depth;
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
display_depth = malloc(sizeof(*display_depth));
|
|
|
|
if (!display_depth)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory.\n");
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
display_depth->display_id = display_id;
|
|
|
|
display_depth->depth = depth;
|
|
|
|
list_add_head(&x11drv_display_depth_list, &display_depth->entry);
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD get_display_depth(ULONG_PTR display_id)
|
|
|
|
{
|
|
|
|
struct x11drv_display_depth *display_depth;
|
|
|
|
DWORD depth;
|
|
|
|
|
|
|
|
pthread_mutex_lock( &settings_mutex );
|
|
|
|
LIST_FOR_EACH_ENTRY(display_depth, &x11drv_display_depth_list, struct x11drv_display_depth, entry)
|
|
|
|
{
|
|
|
|
if (display_depth->display_id == display_id)
|
|
|
|
{
|
|
|
|
depth = display_depth->depth;
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
return screen_bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnumDisplaySettingsEx (X11DRV.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode, DWORD flags)
|
|
|
|
{
|
2022-06-26 15:48:42 +00:00
|
|
|
DEVMODEW *modes, mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
UINT mode_count;
|
|
|
|
ULONG_PTR id;
|
|
|
|
|
|
|
|
pthread_mutex_lock( &settings_mutex );
|
|
|
|
if (n == 0 || wcsicmp(cached_device_name, name) || cached_flags != flags)
|
|
|
|
{
|
|
|
|
if (!settings_handler.get_id(name, &id) || !settings_handler.get_modes(id, flags, &modes, &mode_count))
|
|
|
|
{
|
|
|
|
ERR("Failed to get %s supported display modes.\n", wine_dbgstr_w(name));
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare);
|
|
|
|
|
|
|
|
if (cached_modes)
|
|
|
|
settings_handler.free_modes(cached_modes);
|
|
|
|
lstrcpyW(cached_device_name, name);
|
|
|
|
cached_flags = flags;
|
|
|
|
cached_modes = modes;
|
|
|
|
cached_mode_count = mode_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n >= cached_mode_count)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
WARN("handler:%s device:%s mode index:%#x not found.\n", settings_handler.name, wine_dbgstr_w(name), n);
|
|
|
|
SetLastError(ERROR_NO_MORE_FILES);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-06-26 15:48:42 +00:00
|
|
|
mode = *(DEVMODEW *)((BYTE *)cached_modes + (sizeof(*cached_modes) + cached_modes[0].dmDriverExtra) * n);
|
2022-05-20 12:14:33 +00:00
|
|
|
pthread_mutex_unlock( &settings_mutex );
|
|
|
|
|
2022-06-26 15:48:42 +00:00
|
|
|
memcpy( &devmode->dmFields, &mode.dmFields, devmode->dmSize - offsetof(DEVMODEW, dmFields) );
|
2022-05-20 12:14:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-08-04 08:20:33 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentDisplaySettings (X11DRV.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_GetCurrentDisplaySettings( LPCWSTR name, LPDEVMODEW devmode )
|
|
|
|
{
|
|
|
|
DEVMODEW mode;
|
|
|
|
ULONG_PTR id;
|
|
|
|
|
|
|
|
if (!settings_handler.get_id( name, &id ) || !settings_handler.get_current_mode( id, &mode ))
|
|
|
|
{
|
|
|
|
ERR("Failed to get %s current display settings.\n", wine_dbgstr_w(name));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( &devmode->dmFields, &mode.dmFields, devmode->dmSize - offsetof(DEVMODEW, dmFields) );
|
|
|
|
if (!is_detached_mode( devmode )) devmode->dmBitsPerPel = get_display_depth( id );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-05-20 12:14:33 +00:00
|
|
|
BOOL is_detached_mode(const DEVMODEW *mode)
|
|
|
|
{
|
|
|
|
return mode->dmFields & DM_POSITION &&
|
|
|
|
mode->dmFields & DM_PELSWIDTH &&
|
|
|
|
mode->dmFields & DM_PELSHEIGHT &&
|
|
|
|
mode->dmPelsWidth == 0 &&
|
|
|
|
mode->dmPelsHeight == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the full display mode with all the necessary fields set.
|
|
|
|
* Return NULL on failure. Caller should call free_full_mode() to free the returned mode. */
|
|
|
|
static DEVMODEW *get_full_mode(ULONG_PTR id, DEVMODEW *dev_mode)
|
|
|
|
{
|
|
|
|
DEVMODEW *modes, *full_mode, *found_mode = NULL;
|
|
|
|
UINT mode_count, mode_idx;
|
|
|
|
|
|
|
|
if (is_detached_mode(dev_mode))
|
|
|
|
return dev_mode;
|
|
|
|
|
|
|
|
if (!settings_handler.get_modes(id, EDS_ROTATEDMODE, &modes, &mode_count))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare);
|
|
|
|
for (mode_idx = 0; mode_idx < mode_count; ++mode_idx)
|
|
|
|
{
|
|
|
|
found_mode = (DEVMODEW *)((BYTE *)modes + (sizeof(*modes) + modes[0].dmDriverExtra) * mode_idx);
|
|
|
|
|
|
|
|
if (dev_mode->dmFields & DM_BITSPERPEL &&
|
|
|
|
dev_mode->dmBitsPerPel &&
|
|
|
|
found_mode->dmBitsPerPel != dev_mode->dmBitsPerPel)
|
|
|
|
continue;
|
|
|
|
if (dev_mode->dmFields & DM_PELSWIDTH && found_mode->dmPelsWidth != dev_mode->dmPelsWidth)
|
|
|
|
continue;
|
|
|
|
if (dev_mode->dmFields & DM_PELSHEIGHT && found_mode->dmPelsHeight != dev_mode->dmPelsHeight)
|
|
|
|
continue;
|
|
|
|
if (dev_mode->dmFields & DM_DISPLAYFREQUENCY &&
|
|
|
|
dev_mode->dmDisplayFrequency &&
|
|
|
|
found_mode->dmDisplayFrequency &&
|
|
|
|
dev_mode->dmDisplayFrequency != 1 &&
|
|
|
|
dev_mode->dmDisplayFrequency != found_mode->dmDisplayFrequency)
|
|
|
|
continue;
|
|
|
|
if (dev_mode->dmFields & DM_DISPLAYORIENTATION &&
|
|
|
|
found_mode->dmDisplayOrientation != dev_mode->dmDisplayOrientation)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_mode || mode_idx == mode_count)
|
|
|
|
{
|
|
|
|
settings_handler.free_modes(modes);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(full_mode = malloc(sizeof(*found_mode) + found_mode->dmDriverExtra)))
|
|
|
|
{
|
|
|
|
settings_handler.free_modes(modes);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(full_mode, found_mode, sizeof(*found_mode) + found_mode->dmDriverExtra);
|
|
|
|
settings_handler.free_modes(modes);
|
|
|
|
|
|
|
|
full_mode->dmFields |= DM_POSITION;
|
|
|
|
full_mode->dmPosition = dev_mode->dmPosition;
|
|
|
|
return full_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_full_mode(DEVMODEW *mode)
|
|
|
|
{
|
|
|
|
if (!is_detached_mode(mode))
|
|
|
|
free(mode);
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
static LONG get_display_settings(DEVMODEW **new_displays, const WCHAR *dev_name, DEVMODEW *dev_mode)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 13:32:05 +00:00
|
|
|
DEVMODEW registry_mode, current_mode, *mode, *displays;
|
2022-05-20 12:14:33 +00:00
|
|
|
INT display_idx, display_count = 0;
|
|
|
|
DISPLAY_DEVICEW display_device;
|
|
|
|
LONG ret = DISP_CHANGE_FAILED;
|
|
|
|
UNICODE_STRING device_name;
|
|
|
|
|
|
|
|
display_device.cb = sizeof(display_device);
|
|
|
|
for (display_idx = 0; !NtUserEnumDisplayDevices( NULL, display_idx, &display_device, 0 ); ++display_idx)
|
|
|
|
++display_count;
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
/* use driver extra data to store an ULONG_PTR adapter id after each mode,
|
|
|
|
* and allocate an extra mode to make iteration easier */
|
|
|
|
if (!(displays = calloc(display_count + 1, sizeof(DEVMODEW) + sizeof(ULONG_PTR)))) goto done;
|
|
|
|
mode = displays;
|
2022-05-20 12:14:33 +00:00
|
|
|
|
|
|
|
for (display_idx = 0; display_idx < display_count; ++display_idx)
|
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
ULONG_PTR *id = (ULONG_PTR *)(mode + 1);
|
|
|
|
|
2022-05-20 12:14:33 +00:00
|
|
|
if (NtUserEnumDisplayDevices( NULL, display_idx, &display_device, 0 ))
|
|
|
|
goto done;
|
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
if (!settings_handler.get_id(display_device.DeviceName, id))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
ret = DISP_CHANGE_BADPARAM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &device_name, display_device.DeviceName );
|
|
|
|
|
|
|
|
if (!dev_mode)
|
|
|
|
{
|
|
|
|
memset(®istry_mode, 0, sizeof(registry_mode));
|
|
|
|
registry_mode.dmSize = sizeof(registry_mode);
|
|
|
|
if (!NtUserEnumDisplaySettings( &device_name, ENUM_REGISTRY_SETTINGS, ®istry_mode, 0 ))
|
|
|
|
goto done;
|
2022-07-29 09:55:52 +00:00
|
|
|
*mode = registry_mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
else if (!wcsicmp(dev_name, display_device.DeviceName))
|
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
*mode = *dev_mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
if (!(dev_mode->dmFields & DM_POSITION))
|
|
|
|
{
|
|
|
|
memset(¤t_mode, 0, sizeof(current_mode));
|
|
|
|
current_mode.dmSize = sizeof(current_mode);
|
|
|
|
if (!NtUserEnumDisplaySettings( &device_name, ENUM_CURRENT_SETTINGS, ¤t_mode, 0 ))
|
|
|
|
goto done;
|
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
mode->dmFields |= DM_POSITION;
|
|
|
|
mode->dmPosition = current_mode.dmPosition;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(¤t_mode, 0, sizeof(current_mode));
|
|
|
|
current_mode.dmSize = sizeof(current_mode);
|
|
|
|
if (!NtUserEnumDisplaySettings( &device_name, ENUM_CURRENT_SETTINGS, ¤t_mode, 0 ))
|
|
|
|
goto done;
|
2022-07-29 09:55:52 +00:00
|
|
|
*mode = current_mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
mode->dmSize = sizeof(DEVMODEW);
|
|
|
|
lstrcpyW(mode->dmDeviceName, display_device.DeviceName);
|
|
|
|
mode->dmDriverExtra = sizeof(ULONG_PTR);
|
2022-07-29 13:32:05 +00:00
|
|
|
mode = NEXT_DEVMODEW(mode);
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*new_displays = displays;
|
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
|
|
|
|
done:
|
|
|
|
free(displays);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT offset_length(POINT offset)
|
|
|
|
{
|
|
|
|
return offset.x * offset.x + offset.y * offset.y;
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:07:35 +00:00
|
|
|
static void set_rect_from_devmode(RECT *rect, const DEVMODEW *mode)
|
|
|
|
{
|
|
|
|
SetRect(rect, mode->dmPosition.x, mode->dmPosition.y, mode->dmPosition.x + mode->dmPelsWidth, mode->dmPosition.y + mode->dmPelsHeight);
|
|
|
|
}
|
|
|
|
|
2022-05-20 12:14:33 +00:00
|
|
|
/* Check if a rect overlaps with placed display rects */
|
2022-07-29 13:32:05 +00:00
|
|
|
static BOOL overlap_placed_displays(const RECT *rect, const DEVMODEW *displays)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 13:32:05 +00:00
|
|
|
const DEVMODEW *mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
RECT intersect;
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
set_rect_from_devmode(&intersect, mode);
|
|
|
|
if ((mode->dmFields & DM_POSITION) && intersect_rect(&intersect, &intersect, rect))
|
2022-05-20 12:14:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the offset with minimum length to place a display next to the placed displays with no spacing and overlaps */
|
2022-07-29 13:32:05 +00:00
|
|
|
static POINT get_placement_offset(const DEVMODEW *displays, const DEVMODEW *placing)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
POINT points[8], left_top, offset, min_offset = {0, 0};
|
2022-07-29 13:32:05 +00:00
|
|
|
INT point_idx, point_count, vertex_idx;
|
2022-05-20 12:14:33 +00:00
|
|
|
BOOL has_placed = FALSE, first = TRUE;
|
2022-07-29 09:07:35 +00:00
|
|
|
RECT desired_rect, rect;
|
2022-07-29 13:32:05 +00:00
|
|
|
const DEVMODEW *mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
INT width, height;
|
2022-07-29 09:07:35 +00:00
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
set_rect_from_devmode(&desired_rect, placing);
|
2022-05-20 12:14:33 +00:00
|
|
|
|
|
|
|
/* If the display to be placed is detached, no offset is needed to place it */
|
2022-07-29 09:07:35 +00:00
|
|
|
if (IsRectEmpty(&desired_rect))
|
2022-05-20 12:14:33 +00:00
|
|
|
return min_offset;
|
|
|
|
|
|
|
|
/* If there is no placed and attached display, place this display as it is */
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
set_rect_from_devmode(&rect, mode);
|
|
|
|
if ((mode->dmFields & DM_POSITION) && !IsRectEmpty(&rect))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
has_placed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_placed)
|
|
|
|
return min_offset;
|
|
|
|
|
|
|
|
/* Try to place this display with each of its four vertices at every vertex of the placed
|
|
|
|
* displays and see which combination has the minimum offset length */
|
2022-07-29 09:07:35 +00:00
|
|
|
width = desired_rect.right - desired_rect.left;
|
|
|
|
height = desired_rect.bottom - desired_rect.top;
|
2022-05-20 12:14:33 +00:00
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
set_rect_from_devmode(&rect, mode);
|
|
|
|
if (!(mode->dmFields & DM_POSITION) || IsRectEmpty(&rect))
|
2022-05-20 12:14:33 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Get four vertices of the placed display rectangle */
|
2022-07-29 09:21:09 +00:00
|
|
|
points[0].x = rect.left;
|
|
|
|
points[0].y = rect.top;
|
|
|
|
points[1].x = rect.left;
|
|
|
|
points[1].y = rect.bottom;
|
|
|
|
points[2].x = rect.right;
|
|
|
|
points[2].y = rect.top;
|
|
|
|
points[3].x = rect.right;
|
|
|
|
points[3].y = rect.bottom;
|
2022-05-20 12:14:33 +00:00
|
|
|
point_count = 4;
|
|
|
|
|
|
|
|
/* Intersected points when moving the display to be placed horizontally */
|
2022-07-29 09:21:09 +00:00
|
|
|
if (desired_rect.bottom >= rect.top &&
|
|
|
|
desired_rect.top <= rect.bottom)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:21:09 +00:00
|
|
|
points[point_count].x = rect.left;
|
2022-07-29 09:07:35 +00:00
|
|
|
points[point_count++].y = desired_rect.top;
|
2022-07-29 09:21:09 +00:00
|
|
|
points[point_count].x = rect.right;
|
2022-07-29 09:07:35 +00:00
|
|
|
points[point_count++].y = desired_rect.top;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
/* Intersected points when moving the display to be placed vertically */
|
2022-07-29 09:21:09 +00:00
|
|
|
if (desired_rect.left <= rect.right &&
|
|
|
|
desired_rect.right >= rect.left)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:07:35 +00:00
|
|
|
points[point_count].x = desired_rect.left;
|
2022-07-29 09:21:09 +00:00
|
|
|
points[point_count++].y = rect.top;
|
2022-07-29 09:07:35 +00:00
|
|
|
points[point_count].x = desired_rect.left;
|
2022-07-29 09:21:09 +00:00
|
|
|
points[point_count++].y = rect.bottom;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try moving each vertex of the display rectangle to each points */
|
|
|
|
for (point_idx = 0; point_idx < point_count; ++point_idx)
|
|
|
|
{
|
|
|
|
for (vertex_idx = 0; vertex_idx < 4; ++vertex_idx)
|
|
|
|
{
|
|
|
|
switch (vertex_idx)
|
|
|
|
{
|
|
|
|
/* Move the bottom right vertex to the point */
|
|
|
|
case 0:
|
|
|
|
left_top.x = points[point_idx].x - width;
|
|
|
|
left_top.y = points[point_idx].y - height;
|
|
|
|
break;
|
|
|
|
/* Move the bottom left vertex to the point */
|
|
|
|
case 1:
|
|
|
|
left_top.x = points[point_idx].x;
|
|
|
|
left_top.y = points[point_idx].y - height;
|
|
|
|
break;
|
|
|
|
/* Move the top right vertex to the point */
|
|
|
|
case 2:
|
|
|
|
left_top.x = points[point_idx].x - width;
|
|
|
|
left_top.y = points[point_idx].y;
|
|
|
|
break;
|
|
|
|
/* Move the top left vertex to the point */
|
|
|
|
case 3:
|
|
|
|
left_top.x = points[point_idx].x;
|
|
|
|
left_top.y = points[point_idx].y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-29 09:07:35 +00:00
|
|
|
offset.x = left_top.x - desired_rect.left;
|
|
|
|
offset.y = left_top.y - desired_rect.top;
|
|
|
|
rect = desired_rect;
|
2022-05-20 12:14:33 +00:00
|
|
|
OffsetRect(&rect, offset.x, offset.y);
|
2022-07-29 13:32:05 +00:00
|
|
|
if (!overlap_placed_displays(&rect, displays))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
min_offset = offset;
|
|
|
|
first = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset_length(offset) < offset_length(min_offset))
|
|
|
|
min_offset = offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return min_offset;
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
static void place_all_displays(DEVMODEW *displays)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
INT left_most = INT_MAX, top_most = INT_MAX;
|
|
|
|
POINT min_offset, offset;
|
2022-07-29 13:32:05 +00:00
|
|
|
DEVMODEW *mode, *placing;
|
2022-05-20 12:14:33 +00:00
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-07-29 09:55:52 +00:00
|
|
|
mode->dmFields &= ~DM_POSITION;
|
2022-07-29 09:13:16 +00:00
|
|
|
|
2022-05-20 12:14:33 +00:00
|
|
|
/* Place all displays with no extra space between them and no overlapping */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* Place the unplaced display with the minimum offset length first */
|
2022-07-29 09:55:52 +00:00
|
|
|
placing = NULL;
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
if (mode->dmFields & DM_POSITION)
|
2022-05-20 12:14:33 +00:00
|
|
|
continue;
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
offset = get_placement_offset(displays, mode);
|
2022-07-29 09:55:52 +00:00
|
|
|
if (!placing || offset_length(offset) < offset_length(min_offset))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
min_offset = offset;
|
2022-07-29 09:55:52 +00:00
|
|
|
placing = mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all displays are placed */
|
2022-07-29 09:55:52 +00:00
|
|
|
if (!placing)
|
2022-05-20 12:14:33 +00:00
|
|
|
break;
|
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
placing->dmPosition.x += min_offset.x;
|
|
|
|
placing->dmPosition.y += min_offset.y;
|
|
|
|
placing->dmFields |= DM_POSITION;
|
2022-05-20 12:14:33 +00:00
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
left_most = min(left_most, placing->dmPosition.x);
|
|
|
|
top_most = min(top_most, placing->dmPosition.y);
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert virtual screen coordinates to root coordinates */
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
mode->dmPosition.x -= left_most;
|
|
|
|
mode->dmPosition.y -= top_most;
|
2022-05-20 12:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
static LONG apply_display_settings(DEVMODEW *displays, BOOL do_attach)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
DEVMODEW *full_mode;
|
|
|
|
BOOL attached_mode;
|
2022-07-29 13:32:05 +00:00
|
|
|
DEVMODEW *mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
LONG ret;
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
ULONG_PTR *id = (ULONG_PTR *)(mode + 1);
|
|
|
|
|
|
|
|
attached_mode = !is_detached_mode(mode);
|
2022-05-20 12:14:33 +00:00
|
|
|
if ((attached_mode && !do_attach) || (!attached_mode && do_attach))
|
|
|
|
continue;
|
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
full_mode = get_full_mode(*id, mode);
|
2022-05-20 12:14:33 +00:00
|
|
|
if (!full_mode)
|
|
|
|
return DISP_CHANGE_BADMODE;
|
|
|
|
|
|
|
|
TRACE("handler:%s changing %s to position:(%d,%d) resolution:%ux%u frequency:%uHz "
|
|
|
|
"depth:%ubits orientation:%#x.\n", settings_handler.name,
|
2022-07-29 09:55:52 +00:00
|
|
|
wine_dbgstr_w(mode->dmDeviceName),
|
2022-05-20 12:14:33 +00:00
|
|
|
full_mode->dmPosition.x, full_mode->dmPosition.y, full_mode->dmPelsWidth,
|
|
|
|
full_mode->dmPelsHeight, full_mode->dmDisplayFrequency, full_mode->dmBitsPerPel,
|
|
|
|
full_mode->dmDisplayOrientation);
|
|
|
|
|
2022-07-29 09:55:52 +00:00
|
|
|
ret = settings_handler.set_current_mode(*id, full_mode);
|
2022-05-20 12:14:33 +00:00
|
|
|
if (attached_mode && ret == DISP_CHANGE_SUCCESSFUL)
|
2022-07-29 09:55:52 +00:00
|
|
|
set_display_depth(*id, full_mode->dmBitsPerPel);
|
2022-05-20 12:14:33 +00:00
|
|
|
free_full_mode(full_mode);
|
|
|
|
if (ret != DISP_CHANGE_SUCCESSFUL)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
static BOOL all_detached_settings(const DEVMODEW *displays)
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 13:32:05 +00:00
|
|
|
const DEVMODEW *mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
if (!is_detached_mode(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ChangeDisplaySettingsEx (X11DRV.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LONG X11DRV_ChangeDisplaySettingsEx( LPCWSTR devname, LPDEVMODEW devmode,
|
|
|
|
HWND hwnd, DWORD flags, LPVOID lpvoid )
|
|
|
|
{
|
2022-07-29 13:32:05 +00:00
|
|
|
DEVMODEW *displays, *mode, *full_mode;
|
2022-05-20 12:14:33 +00:00
|
|
|
LONG ret;
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
ret = get_display_settings( &displays, devname, devmode );
|
2022-05-20 12:14:33 +00:00
|
|
|
if (ret != DISP_CHANGE_SUCCESSFUL)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (flags & CDS_UPDATEREGISTRY && devname && devmode)
|
|
|
|
{
|
2022-07-29 13:32:05 +00:00
|
|
|
for (mode = displays; mode->dmSize; mode = NEXT_DEVMODEW(mode))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
ULONG_PTR *id = (ULONG_PTR *)(mode + 1);
|
|
|
|
|
|
|
|
if (!wcsicmp(mode->dmDeviceName, devname))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
2022-07-29 09:55:52 +00:00
|
|
|
full_mode = get_full_mode(*id, mode);
|
2022-05-20 12:14:33 +00:00
|
|
|
if (!full_mode)
|
|
|
|
{
|
|
|
|
free(displays);
|
|
|
|
return DISP_CHANGE_BADMODE;
|
|
|
|
}
|
|
|
|
|
2022-07-04 09:36:26 +00:00
|
|
|
memcpy( &devmode->dmFields, &full_mode->dmFields, devmode->dmSize - offsetof(DEVMODEW, dmFields) );
|
2022-05-20 12:14:33 +00:00
|
|
|
free_full_mode(full_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & (CDS_TEST | CDS_NORESET))
|
|
|
|
{
|
|
|
|
free(displays);
|
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
if (all_detached_settings( displays ))
|
2022-05-20 12:14:33 +00:00
|
|
|
{
|
|
|
|
WARN("Detaching all displays is not permitted.\n");
|
|
|
|
free(displays);
|
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2022-07-29 13:32:05 +00:00
|
|
|
place_all_displays( displays );
|
2022-05-20 12:14:33 +00:00
|
|
|
|
|
|
|
/* Detach displays first to free up CRTCs */
|
2022-07-29 13:32:05 +00:00
|
|
|
ret = apply_display_settings( displays, FALSE );
|
2022-05-20 12:14:33 +00:00
|
|
|
if (ret == DISP_CHANGE_SUCCESSFUL)
|
2022-07-29 13:32:05 +00:00
|
|
|
ret = apply_display_settings( displays, TRUE );
|
2022-05-20 12:14:33 +00:00
|
|
|
if (ret == DISP_CHANGE_SUCCESSFUL)
|
|
|
|
X11DRV_DisplayDevices_Update(TRUE);
|
|
|
|
free(displays);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-11-01 13:19:34 +00:00
|
|
|
|
2019-08-14 08:23:55 +00:00
|
|
|
POINT virtual_screen_to_root(INT x, INT y)
|
|
|
|
{
|
2022-04-13 13:08:36 +00:00
|
|
|
RECT virtual = NtUserGetVirtualScreenRect();
|
2019-08-14 08:23:55 +00:00
|
|
|
POINT pt;
|
2019-11-01 13:19:34 +00:00
|
|
|
|
|
|
|
pt.x = x - virtual.left;
|
|
|
|
pt.y = y - virtual.top;
|
2019-08-14 08:23:55 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
POINT root_to_virtual_screen(INT x, INT y)
|
|
|
|
{
|
2022-04-13 13:08:36 +00:00
|
|
|
RECT virtual = NtUserGetVirtualScreenRect();
|
2019-08-14 08:23:55 +00:00
|
|
|
POINT pt;
|
2019-11-01 13:19:34 +00:00
|
|
|
|
|
|
|
pt.x = x + virtual.left;
|
|
|
|
pt.y = y + virtual.top;
|
2019-08-14 08:23:55 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:05:10 +00:00
|
|
|
/* Get the primary monitor rect from the host system */
|
|
|
|
RECT get_host_primary_monitor_rect(void)
|
|
|
|
{
|
|
|
|
INT gpu_count, adapter_count, monitor_count;
|
2021-11-30 12:26:29 +00:00
|
|
|
struct gdi_gpu *gpus = NULL;
|
|
|
|
struct gdi_adapter *adapters = NULL;
|
|
|
|
struct gdi_monitor *monitors = NULL;
|
2019-11-05 13:05:10 +00:00
|
|
|
RECT rect = {0};
|
|
|
|
|
|
|
|
/* The first monitor is always primary */
|
|
|
|
if (host_handler.get_gpus(&gpus, &gpu_count) && gpu_count &&
|
|
|
|
host_handler.get_adapters(gpus[0].id, &adapters, &adapter_count) && adapter_count &&
|
|
|
|
host_handler.get_monitors(adapters[0].id, &monitors, &monitor_count) && monitor_count)
|
|
|
|
rect = monitors[0].rc_monitor;
|
|
|
|
|
|
|
|
if (gpus) host_handler.free_gpus(gpus);
|
|
|
|
if (adapters) host_handler.free_adapters(adapters);
|
2021-09-14 13:48:25 +00:00
|
|
|
if (monitors) host_handler.free_monitors(monitors, monitor_count);
|
2019-11-05 13:05:10 +00:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2021-11-30 12:26:29 +00:00
|
|
|
BOOL get_host_primary_gpu(struct gdi_gpu *gpu)
|
2020-08-17 08:36:23 +00:00
|
|
|
{
|
2021-11-30 12:26:29 +00:00
|
|
|
struct gdi_gpu *gpus;
|
2020-08-17 08:36:23 +00:00
|
|
|
INT gpu_count;
|
|
|
|
|
|
|
|
if (host_handler.get_gpus(&gpus, &gpu_count) && gpu_count)
|
|
|
|
{
|
|
|
|
*gpu = gpus[0];
|
|
|
|
host_handler.free_gpus(gpus);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:56:21 +00:00
|
|
|
RECT get_work_area(const RECT *monitor_rect)
|
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
2020-06-30 09:56:53 +00:00
|
|
|
unsigned long count, remaining, i;
|
2020-06-30 09:56:21 +00:00
|
|
|
long *work_area;
|
|
|
|
RECT work_rect;
|
|
|
|
|
2020-06-30 09:56:53 +00:00
|
|
|
/* Try _GTK_WORKAREAS first as _NET_WORKAREA may be incorrect on multi-monitor systems */
|
|
|
|
if (!XGetWindowProperty(gdi_display, DefaultRootWindow(gdi_display),
|
|
|
|
x11drv_atom(_GTK_WORKAREAS_D0), 0, ~0, False, XA_CARDINAL, &type,
|
|
|
|
&format, &count, &remaining, (unsigned char **)&work_area))
|
|
|
|
{
|
2021-03-08 08:14:22 +00:00
|
|
|
if (type == XA_CARDINAL && format == 32)
|
2020-06-30 09:56:53 +00:00
|
|
|
{
|
2021-03-08 08:14:22 +00:00
|
|
|
for (i = 0; i < count / 4; ++i)
|
2020-06-30 09:56:53 +00:00
|
|
|
{
|
|
|
|
work_rect.left = work_area[i * 4];
|
|
|
|
work_rect.top = work_area[i * 4 + 1];
|
|
|
|
work_rect.right = work_rect.left + work_area[i * 4 + 2];
|
|
|
|
work_rect.bottom = work_rect.top + work_area[i * 4 + 3];
|
|
|
|
|
2022-04-17 19:52:34 +00:00
|
|
|
if (intersect_rect( &work_rect, &work_rect, monitor_rect ))
|
2020-06-30 09:56:53 +00:00
|
|
|
{
|
|
|
|
TRACE("work_rect:%s.\n", wine_dbgstr_rect(&work_rect));
|
|
|
|
XFree(work_area);
|
|
|
|
return work_rect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(work_area);
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("_GTK_WORKAREAS is not supported, fallback to _NET_WORKAREA. "
|
|
|
|
"Work areas may be incorrect on multi-monitor systems.\n");
|
2020-06-30 09:56:21 +00:00
|
|
|
if (!XGetWindowProperty(gdi_display, DefaultRootWindow(gdi_display), x11drv_atom(_NET_WORKAREA),
|
|
|
|
0, ~0, False, XA_CARDINAL, &type, &format, &count, &remaining,
|
|
|
|
(unsigned char **)&work_area))
|
|
|
|
{
|
|
|
|
if (type == XA_CARDINAL && format == 32 && count >= 4)
|
|
|
|
{
|
|
|
|
SetRect(&work_rect, work_area[0], work_area[1], work_area[0] + work_area[2],
|
|
|
|
work_area[1] + work_area[3]);
|
|
|
|
|
2022-04-17 19:52:34 +00:00
|
|
|
if (intersect_rect( &work_rect, &work_rect, monitor_rect ))
|
2020-06-30 09:56:21 +00:00
|
|
|
{
|
|
|
|
TRACE("work_rect:%s.\n", wine_dbgstr_rect(&work_rect));
|
|
|
|
XFree(work_area);
|
|
|
|
return work_rect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(work_area);
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("_NET_WORKAREA is not supported, Work areas may be incorrect.\n");
|
|
|
|
TRACE("work_rect:%s.\n", wine_dbgstr_rect(monitor_rect));
|
|
|
|
return *monitor_rect;
|
|
|
|
}
|
|
|
|
|
2019-06-10 14:07:02 +00:00
|
|
|
void X11DRV_DisplayDevices_SetHandler(const struct x11drv_display_device_handler *new_handler)
|
|
|
|
{
|
2019-11-05 13:04:27 +00:00
|
|
|
if (new_handler->priority > host_handler.priority)
|
2019-06-10 14:07:02 +00:00
|
|
|
{
|
2019-11-05 13:04:27 +00:00
|
|
|
host_handler = *new_handler;
|
|
|
|
TRACE("Display device functions are now handled by: %s\n", host_handler.name);
|
2019-06-10 14:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 13:20:21 +00:00
|
|
|
void X11DRV_DisplayDevices_RegisterEventHandlers(void)
|
|
|
|
{
|
2019-11-05 13:04:27 +00:00
|
|
|
struct x11drv_display_device_handler *handler = is_virtual_desktop() ? &desktop_handler : &host_handler;
|
|
|
|
|
|
|
|
if (handler->register_event_handlers)
|
|
|
|
handler->register_event_handlers();
|
2019-11-01 13:20:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 08:55:27 +00:00
|
|
|
void X11DRV_DisplayDevices_Update(BOOL send_display_change)
|
|
|
|
{
|
|
|
|
RECT old_virtual_rect, new_virtual_rect;
|
2020-10-01 20:24:31 +00:00
|
|
|
DWORD tid, pid;
|
|
|
|
HWND foreground;
|
2022-04-19 13:30:26 +00:00
|
|
|
UINT mask = 0, i;
|
|
|
|
HWND *list;
|
2020-05-11 08:55:27 +00:00
|
|
|
|
2022-04-13 13:08:36 +00:00
|
|
|
old_virtual_rect = NtUserGetVirtualScreenRect();
|
2020-05-11 08:55:27 +00:00
|
|
|
X11DRV_DisplayDevices_Init(TRUE);
|
2022-04-13 13:08:36 +00:00
|
|
|
new_virtual_rect = NtUserGetVirtualScreenRect();
|
2020-05-11 08:55:27 +00:00
|
|
|
|
|
|
|
/* Calculate XReconfigureWMWindow() mask */
|
|
|
|
if (old_virtual_rect.left != new_virtual_rect.left)
|
|
|
|
mask |= CWX;
|
|
|
|
if (old_virtual_rect.top != new_virtual_rect.top)
|
|
|
|
mask |= CWY;
|
|
|
|
|
2020-05-11 08:55:38 +00:00
|
|
|
X11DRV_resize_desktop(send_display_change);
|
2022-04-19 13:30:26 +00:00
|
|
|
|
|
|
|
list = build_hwnd_list();
|
|
|
|
for (i = 0; list && list[i] != HWND_BOTTOM; i++)
|
|
|
|
{
|
|
|
|
struct x11drv_win_data *data;
|
|
|
|
|
|
|
|
if (!(data = get_win_data( list[i] ))) continue;
|
|
|
|
|
|
|
|
/* update the full screen state */
|
|
|
|
update_net_wm_states(data);
|
|
|
|
|
|
|
|
if (mask && data->whole_window)
|
|
|
|
{
|
|
|
|
POINT pos = virtual_screen_to_root(data->whole_rect.left, data->whole_rect.top);
|
|
|
|
XWindowChanges changes;
|
|
|
|
changes.x = pos.x;
|
|
|
|
changes.y = pos.y;
|
|
|
|
XReconfigureWMWindow(data->display, data->whole_window, data->vis.screen, mask, &changes);
|
|
|
|
}
|
|
|
|
release_win_data(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
free( list );
|
2020-10-01 20:24:31 +00:00
|
|
|
|
|
|
|
/* forward clip_fullscreen_window request to the foreground window */
|
2022-04-15 12:52:20 +00:00
|
|
|
if ((foreground = NtUserGetForegroundWindow()) &&
|
|
|
|
(tid = NtUserGetWindowThread( foreground, &pid )) && pid == GetCurrentProcessId())
|
2020-10-01 20:24:31 +00:00
|
|
|
{
|
|
|
|
if (tid == GetCurrentThreadId()) clip_fullscreen_window( foreground, TRUE );
|
2022-04-15 12:52:20 +00:00
|
|
|
else send_notify_message( foreground, WM_X11DRV_CLIP_CURSOR_REQUEST, TRUE, TRUE );
|
2020-10-01 20:24:31 +00:00
|
|
|
}
|
2020-05-11 08:55:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 12:27:04 +00:00
|
|
|
static BOOL force_display_devices_refresh;
|
2019-06-10 14:07:34 +00:00
|
|
|
|
2022-07-05 06:57:18 +00:00
|
|
|
BOOL X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manager, BOOL force, void *param )
|
2019-06-10 14:07:34 +00:00
|
|
|
{
|
2021-11-30 12:27:04 +00:00
|
|
|
struct x11drv_display_device_handler *handler;
|
|
|
|
struct gdi_adapter *adapters;
|
|
|
|
struct gdi_monitor *monitors;
|
|
|
|
struct gdi_gpu *gpus;
|
2019-06-10 14:07:34 +00:00
|
|
|
INT gpu_count, adapter_count, monitor_count;
|
|
|
|
INT gpu, adapter, monitor;
|
2022-07-06 22:20:19 +00:00
|
|
|
DEVMODEW *modes, *mode;
|
|
|
|
DWORD mode_count;
|
2019-06-10 14:07:02 +00:00
|
|
|
|
2022-07-05 06:57:18 +00:00
|
|
|
if (!force && !force_display_devices_refresh) return TRUE;
|
2021-11-30 12:27:04 +00:00
|
|
|
force_display_devices_refresh = FALSE;
|
|
|
|
handler = is_virtual_desktop() ? &desktop_handler : &host_handler;
|
2019-06-10 14:07:02 +00:00
|
|
|
|
2019-11-05 13:04:27 +00:00
|
|
|
TRACE("via %s\n", wine_dbgstr_a(handler->name));
|
2019-06-10 14:07:02 +00:00
|
|
|
|
2019-06-10 14:07:14 +00:00
|
|
|
/* Initialize GPUs */
|
2022-07-05 06:57:18 +00:00
|
|
|
if (!handler->get_gpus( &gpus, &gpu_count )) return FALSE;
|
2019-09-25 07:28:03 +00:00
|
|
|
TRACE("GPU count: %d\n", gpu_count);
|
2019-06-10 14:07:14 +00:00
|
|
|
|
|
|
|
for (gpu = 0; gpu < gpu_count; gpu++)
|
|
|
|
{
|
2021-11-30 12:27:04 +00:00
|
|
|
device_manager->add_gpu( &gpus[gpu], param );
|
2019-06-10 14:07:23 +00:00
|
|
|
|
|
|
|
/* Initialize adapters */
|
2021-11-30 12:27:04 +00:00
|
|
|
if (!handler->get_adapters(gpus[gpu].id, &adapters, &adapter_count)) break;
|
2019-09-25 07:28:03 +00:00
|
|
|
TRACE("GPU: %#lx %s, adapter count: %d\n", gpus[gpu].id, wine_dbgstr_w(gpus[gpu].name), adapter_count);
|
2019-06-10 14:07:23 +00:00
|
|
|
|
|
|
|
for (adapter = 0; adapter < adapter_count; adapter++)
|
|
|
|
{
|
2021-11-30 12:27:04 +00:00
|
|
|
device_manager->add_adapter( &adapters[adapter], param );
|
2019-06-10 14:07:34 +00:00
|
|
|
|
2021-11-30 12:27:04 +00:00
|
|
|
if (!handler->get_monitors(adapters[adapter].id, &monitors, &monitor_count)) break;
|
|
|
|
TRACE("adapter: %#lx, monitor count: %d\n", adapters[adapter].id, monitor_count);
|
2019-06-10 14:07:23 +00:00
|
|
|
|
2019-06-10 14:07:34 +00:00
|
|
|
/* Initialize monitors */
|
|
|
|
for (monitor = 0; monitor < monitor_count; monitor++)
|
|
|
|
{
|
2019-09-25 07:28:03 +00:00
|
|
|
TRACE("monitor: %#x %s\n", monitor, wine_dbgstr_w(monitors[monitor].name));
|
2021-11-30 12:27:04 +00:00
|
|
|
device_manager->add_monitor( &monitors[monitor], param );
|
2019-06-10 14:07:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-14 13:48:25 +00:00
|
|
|
handler->free_monitors(monitors, monitor_count);
|
2022-07-06 22:20:19 +00:00
|
|
|
|
|
|
|
if (!settings_handler.get_modes( adapters[adapter].id, EDS_ROTATEDMODE, &modes, &mode_count ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
qsort( modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare );
|
|
|
|
|
|
|
|
for (mode = modes; mode_count; mode_count--)
|
|
|
|
{
|
|
|
|
TRACE( "mode: %p\n", mode );
|
|
|
|
device_manager->add_mode( mode, param );
|
|
|
|
mode = (DEVMODEW *)((char *)mode + sizeof(*modes) + modes[0].dmDriverExtra);
|
|
|
|
}
|
|
|
|
|
|
|
|
settings_handler.free_modes( modes );
|
2019-06-10 14:07:23 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 13:04:27 +00:00
|
|
|
handler->free_adapters(adapters);
|
2019-06-10 14:07:14 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 12:27:04 +00:00
|
|
|
handler->free_gpus(gpus);
|
2022-07-05 06:57:18 +00:00
|
|
|
return TRUE;
|
2021-11-30 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11DRV_DisplayDevices_Init(BOOL force)
|
|
|
|
{
|
|
|
|
UINT32 num_path, num_mode;
|
|
|
|
|
|
|
|
if (force) force_display_devices_refresh = TRUE;
|
|
|
|
/* trigger refresh in win32u */
|
|
|
|
NtUserGetDisplayConfigBufferSizes( QDC_ONLY_ACTIVE_PATHS, &num_path, &num_mode );
|
2019-06-10 14:07:02 +00:00
|
|
|
}
|