2019-06-10 16:07:02 +02: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "x11drv.h"
|
2022-02-18 13:37:29 +01:00
|
|
|
#include "wine/debug.h"
|
2019-06-10 16:07:02 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
|
|
|
|
|
2019-11-05 14:04:27 +01:00
|
|
|
static struct x11drv_display_device_handler host_handler;
|
|
|
|
struct x11drv_display_device_handler desktop_handler;
|
2019-11-01 14:19:34 +01:00
|
|
|
|
2020-06-11 11:22:09 +02:00
|
|
|
HANDLE get_display_device_init_mutex(void)
|
2019-11-01 14:19:34 +01:00
|
|
|
{
|
|
|
|
static const WCHAR init_mutexW[] = {'d','i','s','p','l','a','y','_','d','e','v','i','c','e','_','i','n','i','t',0};
|
|
|
|
HANDLE mutex = CreateMutexW(NULL, FALSE, init_mutexW);
|
|
|
|
|
|
|
|
WaitForSingleObject(mutex, INFINITE);
|
|
|
|
return mutex;
|
|
|
|
}
|
|
|
|
|
2020-06-11 11:22:09 +02:00
|
|
|
void release_display_device_init_mutex(HANDLE mutex)
|
2019-11-01 14:19:34 +01:00
|
|
|
{
|
|
|
|
ReleaseMutex(mutex);
|
|
|
|
CloseHandle(mutex);
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:23:55 +02:00
|
|
|
POINT virtual_screen_to_root(INT x, INT y)
|
|
|
|
{
|
2019-11-01 14:19:34 +01:00
|
|
|
RECT virtual = get_virtual_screen_rect();
|
2019-08-14 10:23:55 +02:00
|
|
|
POINT pt;
|
2019-11-01 14:19:34 +01:00
|
|
|
|
|
|
|
pt.x = x - virtual.left;
|
|
|
|
pt.y = y - virtual.top;
|
2019-08-14 10:23:55 +02:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
POINT root_to_virtual_screen(INT x, INT y)
|
|
|
|
{
|
2019-11-01 14:19:34 +01:00
|
|
|
RECT virtual = get_virtual_screen_rect();
|
2019-08-14 10:23:55 +02:00
|
|
|
POINT pt;
|
2019-11-01 14:19:34 +01:00
|
|
|
|
|
|
|
pt.x = x + virtual.left;
|
|
|
|
pt.y = y + virtual.top;
|
2019-08-14 10:23:55 +02:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
RECT get_virtual_screen_rect(void)
|
|
|
|
{
|
2019-11-01 14:19:34 +01:00
|
|
|
RECT virtual;
|
2022-02-18 13:37:12 +01:00
|
|
|
NtUserCallOneParam( (UINT_PTR)&virtual, NtUserGetVirtualScreenRect );
|
2019-11-01 14:19:34 +01:00
|
|
|
return virtual;
|
2019-08-14 10:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RECT get_primary_monitor_rect(void)
|
|
|
|
{
|
2019-11-01 14:19:34 +01:00
|
|
|
RECT primary;
|
2022-02-18 13:37:29 +01:00
|
|
|
NtUserCallOneParam( (UINT_PTR)&primary, NtUserGetPrimaryMonitorRect );
|
2019-11-01 14:19:34 +01:00
|
|
|
return primary;
|
2019-08-14 10:23:55 +02:00
|
|
|
}
|
2019-06-10 16:07:02 +02:00
|
|
|
|
2019-11-05 14:05:10 +01: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 13:26:29 +01:00
|
|
|
struct gdi_gpu *gpus = NULL;
|
|
|
|
struct gdi_adapter *adapters = NULL;
|
|
|
|
struct gdi_monitor *monitors = NULL;
|
2019-11-05 14:05:10 +01: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 15:48:25 +02:00
|
|
|
if (monitors) host_handler.free_monitors(monitors, monitor_count);
|
2019-11-05 14:05:10 +01:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
BOOL get_host_primary_gpu(struct gdi_gpu *gpu)
|
2020-08-17 10:36:23 +02:00
|
|
|
{
|
2021-11-30 13:26:29 +01:00
|
|
|
struct gdi_gpu *gpus;
|
2020-08-17 10:36:23 +02: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 11:56:21 +02:00
|
|
|
RECT get_work_area(const RECT *monitor_rect)
|
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
2020-06-30 11:56:53 +02:00
|
|
|
unsigned long count, remaining, i;
|
2020-06-30 11:56:21 +02:00
|
|
|
long *work_area;
|
|
|
|
RECT work_rect;
|
|
|
|
|
2020-06-30 11:56:53 +02: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 09:14:22 +01:00
|
|
|
if (type == XA_CARDINAL && format == 32)
|
2020-06-30 11:56:53 +02:00
|
|
|
{
|
2021-03-08 09:14:22 +01:00
|
|
|
for (i = 0; i < count / 4; ++i)
|
2020-06-30 11:56:53 +02: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];
|
|
|
|
|
|
|
|
if (IntersectRect(&work_rect, &work_rect, monitor_rect))
|
|
|
|
{
|
|
|
|
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 11:56:21 +02: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]);
|
|
|
|
|
|
|
|
if (IntersectRect(&work_rect, &work_rect, monitor_rect))
|
|
|
|
{
|
|
|
|
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 16:07:02 +02:00
|
|
|
void X11DRV_DisplayDevices_SetHandler(const struct x11drv_display_device_handler *new_handler)
|
|
|
|
{
|
2019-11-05 14:04:27 +01:00
|
|
|
if (new_handler->priority > host_handler.priority)
|
2019-06-10 16:07:02 +02:00
|
|
|
{
|
2019-11-05 14:04:27 +01:00
|
|
|
host_handler = *new_handler;
|
|
|
|
TRACE("Display device functions are now handled by: %s\n", host_handler.name);
|
2019-06-10 16:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 14:20:21 +01:00
|
|
|
void X11DRV_DisplayDevices_RegisterEventHandlers(void)
|
|
|
|
{
|
2019-11-05 14:04:27 +01: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 14:20:21 +01:00
|
|
|
}
|
|
|
|
|
2020-05-11 10:55:38 +02:00
|
|
|
static BOOL CALLBACK update_windows_on_display_change(HWND hwnd, LPARAM lparam)
|
|
|
|
{
|
|
|
|
struct x11drv_win_data *data;
|
|
|
|
UINT mask = (UINT)lparam;
|
|
|
|
|
|
|
|
if (!(data = get_win_data(hwnd)))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-05-11 10:55:27 +02:00
|
|
|
void X11DRV_DisplayDevices_Update(BOOL send_display_change)
|
|
|
|
{
|
|
|
|
RECT old_virtual_rect, new_virtual_rect;
|
2020-10-01 22:24:31 +02:00
|
|
|
DWORD tid, pid;
|
|
|
|
HWND foreground;
|
2020-05-11 10:55:27 +02:00
|
|
|
UINT mask = 0;
|
|
|
|
|
|
|
|
old_virtual_rect = get_virtual_screen_rect();
|
|
|
|
X11DRV_DisplayDevices_Init(TRUE);
|
|
|
|
new_virtual_rect = get_virtual_screen_rect();
|
|
|
|
|
|
|
|
/* 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 10:55:38 +02:00
|
|
|
X11DRV_resize_desktop(send_display_change);
|
|
|
|
EnumWindows(update_windows_on_display_change, (LPARAM)mask);
|
2020-10-01 22:24:31 +02:00
|
|
|
|
|
|
|
/* forward clip_fullscreen_window request to the foreground window */
|
|
|
|
if ((foreground = GetForegroundWindow()) && (tid = GetWindowThreadProcessId( foreground, &pid )) && pid == GetCurrentProcessId())
|
|
|
|
{
|
|
|
|
if (tid == GetCurrentThreadId()) clip_fullscreen_window( foreground, TRUE );
|
|
|
|
else SendNotifyMessageW( foreground, WM_X11DRV_CLIP_CURSOR_REQUEST, TRUE, TRUE );
|
|
|
|
}
|
2020-05-11 10:55:27 +02:00
|
|
|
}
|
|
|
|
|
2021-11-30 13:27:04 +01:00
|
|
|
static BOOL force_display_devices_refresh;
|
2019-06-10 16:07:34 +02:00
|
|
|
|
2021-11-30 13:27:04 +01:00
|
|
|
void CDECL X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manager,
|
|
|
|
BOOL force, void *param )
|
2019-06-10 16:07:34 +02:00
|
|
|
{
|
2021-11-30 13:27:04 +01:00
|
|
|
struct x11drv_display_device_handler *handler;
|
|
|
|
struct gdi_adapter *adapters;
|
|
|
|
struct gdi_monitor *monitors;
|
|
|
|
struct gdi_gpu *gpus;
|
2019-06-10 16:07:34 +02:00
|
|
|
INT gpu_count, adapter_count, monitor_count;
|
|
|
|
INT gpu, adapter, monitor;
|
2019-06-10 16:07:02 +02:00
|
|
|
|
2021-11-30 13:27:04 +01:00
|
|
|
if (!force && !force_display_devices_refresh) return;
|
|
|
|
force_display_devices_refresh = FALSE;
|
|
|
|
handler = is_virtual_desktop() ? &desktop_handler : &host_handler;
|
2019-06-10 16:07:02 +02:00
|
|
|
|
2019-11-05 14:04:27 +01:00
|
|
|
TRACE("via %s\n", wine_dbgstr_a(handler->name));
|
2019-06-10 16:07:02 +02:00
|
|
|
|
2019-06-10 16:07:14 +02:00
|
|
|
/* Initialize GPUs */
|
2019-11-05 14:04:27 +01:00
|
|
|
if (!handler->get_gpus(&gpus, &gpu_count))
|
2021-11-30 13:27:04 +01:00
|
|
|
return;
|
2019-09-25 09:28:03 +02:00
|
|
|
TRACE("GPU count: %d\n", gpu_count);
|
2019-06-10 16:07:14 +02:00
|
|
|
|
|
|
|
for (gpu = 0; gpu < gpu_count; gpu++)
|
|
|
|
{
|
2021-11-30 13:27:04 +01:00
|
|
|
device_manager->add_gpu( &gpus[gpu], param );
|
2019-06-10 16:07:23 +02:00
|
|
|
|
|
|
|
/* Initialize adapters */
|
2021-11-30 13:27:04 +01:00
|
|
|
if (!handler->get_adapters(gpus[gpu].id, &adapters, &adapter_count)) break;
|
2019-09-25 09:28:03 +02:00
|
|
|
TRACE("GPU: %#lx %s, adapter count: %d\n", gpus[gpu].id, wine_dbgstr_w(gpus[gpu].name), adapter_count);
|
2019-06-10 16:07:23 +02:00
|
|
|
|
|
|
|
for (adapter = 0; adapter < adapter_count; adapter++)
|
|
|
|
{
|
2021-11-30 13:27:04 +01:00
|
|
|
device_manager->add_adapter( &adapters[adapter], param );
|
2019-06-10 16:07:34 +02:00
|
|
|
|
2021-11-30 13:27:04 +01: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 16:07:23 +02:00
|
|
|
|
2019-06-10 16:07:34 +02:00
|
|
|
/* Initialize monitors */
|
|
|
|
for (monitor = 0; monitor < monitor_count; monitor++)
|
|
|
|
{
|
2019-09-25 09:28:03 +02:00
|
|
|
TRACE("monitor: %#x %s\n", monitor, wine_dbgstr_w(monitors[monitor].name));
|
2021-11-30 13:27:04 +01:00
|
|
|
device_manager->add_monitor( &monitors[monitor], param );
|
2019-06-10 16:07:34 +02:00
|
|
|
}
|
|
|
|
|
2021-09-14 15:48:25 +02:00
|
|
|
handler->free_monitors(monitors, monitor_count);
|
2019-06-10 16:07:23 +02:00
|
|
|
}
|
|
|
|
|
2019-11-05 14:04:27 +01:00
|
|
|
handler->free_adapters(adapters);
|
2019-06-10 16:07:14 +02:00
|
|
|
}
|
|
|
|
|
2021-11-30 13:27:04 +01:00
|
|
|
handler->free_gpus(gpus);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 16:07:02 +02:00
|
|
|
}
|