2006-10-23 14:37:17 +02:00
|
|
|
/*
|
|
|
|
* Xinerama support
|
|
|
|
*
|
|
|
|
* Copyright 2006 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* 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 <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XINERAMA_H
|
|
|
|
#include <X11/extensions/Xinerama.h>
|
|
|
|
#endif
|
2021-12-01 15:56:55 +01:00
|
|
|
#include <dlfcn.h>
|
2006-10-23 14:37:17 +02:00
|
|
|
#include "x11drv.h"
|
|
|
|
#include "wine/debug.h"
|
2019-06-10 16:07:02 +02:00
|
|
|
#include "wine/heap.h"
|
2006-10-23 14:37:17 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
|
|
|
|
|
|
|
|
static MONITORINFOEXW default_monitor =
|
|
|
|
{
|
|
|
|
sizeof(default_monitor), /* cbSize */
|
|
|
|
{ 0, 0, 0, 0 }, /* rcMonitor */
|
|
|
|
{ 0, 0, 0, 0 }, /* rcWork */
|
|
|
|
MONITORINFOF_PRIMARY, /* dwFlags */
|
|
|
|
{ '\\','\\','.','\\','D','I','S','P','L','A','Y','1',0 } /* szDevice */
|
|
|
|
};
|
|
|
|
|
|
|
|
static MONITORINFOEXW *monitors;
|
|
|
|
static int nb_monitors;
|
|
|
|
|
|
|
|
static inline MONITORINFOEXW *get_primary(void)
|
|
|
|
{
|
|
|
|
/* default to 0 if specified primary is invalid */
|
|
|
|
int idx = primary_monitor;
|
|
|
|
if (idx >= nb_monitors) idx = 0;
|
|
|
|
return &monitors[idx];
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:48:50 +02:00
|
|
|
#ifdef SONAME_LIBXINERAMA
|
2006-10-23 14:37:17 +02:00
|
|
|
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
|
|
|
|
MAKE_FUNCPTR(XineramaQueryExtension);
|
|
|
|
MAKE_FUNCPTR(XineramaQueryScreens);
|
|
|
|
|
|
|
|
static void load_xinerama(void)
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
|
2020-04-06 22:43:15 +02:00
|
|
|
if (!(handle = dlopen(SONAME_LIBXINERAMA, RTLD_NOW)))
|
2006-10-23 14:37:17 +02:00
|
|
|
{
|
|
|
|
WARN( "failed to open %s\n", SONAME_LIBXINERAMA );
|
|
|
|
return;
|
|
|
|
}
|
2020-04-06 22:43:15 +02:00
|
|
|
pXineramaQueryExtension = dlsym( handle, "XineramaQueryExtension" );
|
2006-10-23 14:37:17 +02:00
|
|
|
if (!pXineramaQueryExtension) WARN( "XineramaQueryScreens not found\n" );
|
2020-04-06 22:43:15 +02:00
|
|
|
pXineramaQueryScreens = dlsym( handle, "XineramaQueryScreens" );
|
2006-10-23 14:37:17 +02:00
|
|
|
if (!pXineramaQueryScreens) WARN( "XineramaQueryScreens not found\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_screens(void)
|
|
|
|
{
|
|
|
|
int i, count, event_base, error_base;
|
|
|
|
XineramaScreenInfo *screens;
|
|
|
|
|
|
|
|
if (!monitors) /* first time around */
|
|
|
|
load_xinerama();
|
|
|
|
|
|
|
|
if (!pXineramaQueryExtension || !pXineramaQueryScreens ||
|
|
|
|
!pXineramaQueryExtension( gdi_display, &event_base, &error_base ) ||
|
|
|
|
!(screens = pXineramaQueryScreens( gdi_display, &count ))) return 0;
|
|
|
|
|
|
|
|
if (monitors != &default_monitor) HeapFree( GetProcessHeap(), 0, monitors );
|
|
|
|
if ((monitors = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*monitors) )))
|
|
|
|
{
|
|
|
|
nb_monitors = count;
|
|
|
|
for (i = 0; i < nb_monitors; i++)
|
|
|
|
{
|
|
|
|
monitors[i].cbSize = sizeof( monitors[i] );
|
|
|
|
monitors[i].rcMonitor.left = screens[i].x_org;
|
|
|
|
monitors[i].rcMonitor.top = screens[i].y_org;
|
|
|
|
monitors[i].rcMonitor.right = screens[i].x_org + screens[i].width;
|
|
|
|
monitors[i].rcMonitor.bottom = screens[i].y_org + screens[i].height;
|
|
|
|
monitors[i].dwFlags = 0;
|
2020-06-30 11:56:21 +02:00
|
|
|
monitors[i].rcWork = get_work_area( &monitors[i].rcMonitor );
|
2006-10-23 14:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get_primary()->dwFlags |= MONITORINFOF_PRIMARY;
|
|
|
|
}
|
|
|
|
else count = 0;
|
|
|
|
|
|
|
|
XFree( screens );
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:48:50 +02:00
|
|
|
#else /* SONAME_LIBXINERAMA */
|
2006-10-23 14:37:17 +02:00
|
|
|
|
|
|
|
static inline int query_screens(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:48:50 +02:00
|
|
|
#endif /* SONAME_LIBXINERAMA */
|
2006-10-23 14:37:17 +02:00
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
static BOOL xinerama_get_gpus( struct gdi_gpu **new_gpus, int *count )
|
2019-06-10 16:07:14 +02:00
|
|
|
{
|
|
|
|
static const WCHAR wine_adapterW[] = {'W','i','n','e',' ','A','d','a','p','t','e','r',0};
|
2021-11-30 13:26:29 +01:00
|
|
|
struct gdi_gpu *gpus;
|
2019-06-10 16:07:14 +02:00
|
|
|
|
|
|
|
/* Xinerama has no support for GPU, faking one */
|
|
|
|
gpus = heap_calloc( 1, sizeof(*gpus) );
|
|
|
|
if (!gpus)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
lstrcpyW( gpus[0].name, wine_adapterW );
|
|
|
|
|
|
|
|
*new_gpus = gpus;
|
|
|
|
*count = 1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
static void xinerama_free_gpus( struct gdi_gpu *gpus )
|
2019-06-10 16:07:14 +02:00
|
|
|
{
|
|
|
|
heap_free( gpus );
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
static BOOL xinerama_get_adapters( ULONG_PTR gpu_id, struct gdi_adapter **new_adapters, int *count )
|
2019-06-10 16:07:23 +02:00
|
|
|
{
|
2021-11-30 13:26:29 +01:00
|
|
|
struct gdi_adapter *adapters = NULL;
|
2019-06-10 16:07:23 +02:00
|
|
|
INT index = 0;
|
|
|
|
INT i, j;
|
|
|
|
INT primary_index;
|
|
|
|
BOOL mirrored;
|
|
|
|
|
|
|
|
if (gpu_id)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Being lazy, actual adapter count may be less */
|
|
|
|
adapters = heap_calloc( nb_monitors, sizeof(*adapters) );
|
|
|
|
if (!adapters)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
primary_index = primary_monitor;
|
|
|
|
if (primary_index >= nb_monitors)
|
|
|
|
primary_index = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_monitors; i++)
|
|
|
|
{
|
|
|
|
mirrored = FALSE;
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
{
|
|
|
|
if (EqualRect( &monitors[i].rcMonitor, &monitors[j].rcMonitor) && !IsRectEmpty( &monitors[j].rcMonitor ))
|
|
|
|
{
|
|
|
|
mirrored = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mirrored monitors share the same adapter */
|
|
|
|
if (mirrored)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Use monitor index as id */
|
|
|
|
adapters[index].id = (ULONG_PTR)i;
|
|
|
|
|
|
|
|
if (i == primary_index)
|
|
|
|
adapters[index].state_flags |= DISPLAY_DEVICE_PRIMARY_DEVICE;
|
|
|
|
|
|
|
|
if (!IsRectEmpty( &monitors[i].rcMonitor ))
|
|
|
|
adapters[index].state_flags |= DISPLAY_DEVICE_ATTACHED_TO_DESKTOP;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Primary adapter has to be first */
|
|
|
|
if (primary_index)
|
|
|
|
{
|
2021-11-30 13:26:29 +01:00
|
|
|
struct gdi_adapter tmp;
|
2019-06-10 16:07:23 +02:00
|
|
|
tmp = adapters[primary_index];
|
|
|
|
adapters[primary_index] = adapters[0];
|
|
|
|
adapters[0] = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
*new_adapters = adapters;
|
|
|
|
*count = index;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
static void xinerama_free_adapters( struct gdi_adapter *adapters )
|
2019-06-10 16:07:23 +02:00
|
|
|
{
|
|
|
|
heap_free( adapters );
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
static BOOL xinerama_get_monitors( ULONG_PTR adapter_id, struct gdi_monitor **new_monitors, int *count )
|
2019-06-10 16:07:34 +02:00
|
|
|
{
|
|
|
|
static const WCHAR generic_nonpnp_monitorW[] = {
|
|
|
|
'G','e','n','e','r','i','c',' ',
|
|
|
|
'N','o','n','-','P','n','P',' ','M','o','n','i','t','o','r',0};
|
2021-11-30 13:26:29 +01:00
|
|
|
struct gdi_monitor *monitor;
|
2019-06-10 16:07:34 +02:00
|
|
|
INT first = (INT)adapter_id;
|
|
|
|
INT monitor_count = 0;
|
|
|
|
INT index = 0;
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
for (i = first; i < nb_monitors; i++)
|
|
|
|
{
|
|
|
|
if (i == first
|
|
|
|
|| (EqualRect( &monitors[i].rcMonitor, &monitors[first].rcMonitor )
|
|
|
|
&& !IsRectEmpty( &monitors[first].rcMonitor )))
|
|
|
|
monitor_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
monitor = heap_calloc( monitor_count, sizeof(*monitor) );
|
|
|
|
if (!monitor)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = first; i < nb_monitors; i++)
|
|
|
|
{
|
|
|
|
if (i == first
|
|
|
|
|| (EqualRect( &monitors[i].rcMonitor, &monitors[first].rcMonitor )
|
|
|
|
&& !IsRectEmpty( &monitors[first].rcMonitor )))
|
|
|
|
{
|
|
|
|
lstrcpyW( monitor[index].name, generic_nonpnp_monitorW );
|
2019-06-25 10:38:38 +02:00
|
|
|
monitor[index].rc_monitor = monitors[i].rcMonitor;
|
2019-06-25 10:39:01 +02:00
|
|
|
monitor[index].rc_work = monitors[i].rcWork;
|
2019-06-10 16:07:34 +02:00
|
|
|
/* Xinerama only reports monitors already attached */
|
|
|
|
monitor[index].state_flags = DISPLAY_DEVICE_ATTACHED;
|
2021-09-14 15:48:25 +02:00
|
|
|
monitor[index].edid_len = 0;
|
|
|
|
monitor[index].edid = NULL;
|
2019-06-10 16:07:34 +02:00
|
|
|
if (!IsRectEmpty( &monitors[i].rcMonitor ))
|
|
|
|
monitor[index].state_flags |= DISPLAY_DEVICE_ACTIVE;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*new_monitors = monitor;
|
|
|
|
*count = monitor_count;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:26:29 +01:00
|
|
|
static void xinerama_free_monitors( struct gdi_monitor *monitors, int count )
|
2019-06-10 16:07:34 +02:00
|
|
|
{
|
|
|
|
heap_free( monitors );
|
|
|
|
}
|
|
|
|
|
2008-01-17 19:59:22 +01:00
|
|
|
void xinerama_init( unsigned int width, unsigned int height )
|
2006-10-23 14:37:17 +02:00
|
|
|
{
|
2019-06-10 16:07:02 +02:00
|
|
|
struct x11drv_display_device_handler handler;
|
2006-10-23 14:37:17 +02:00
|
|
|
MONITORINFOEXW *primary;
|
2006-10-26 12:53:59 +02:00
|
|
|
int i;
|
2008-02-06 20:38:20 +01:00
|
|
|
RECT rect;
|
2006-10-23 14:37:17 +02:00
|
|
|
|
2019-11-05 14:04:27 +01:00
|
|
|
if (is_virtual_desktop())
|
|
|
|
return;
|
2006-10-23 14:37:17 +02:00
|
|
|
|
2019-11-05 14:04:27 +01:00
|
|
|
SetRect( &rect, 0, 0, width, height );
|
|
|
|
if (!query_screens())
|
2006-10-23 14:37:17 +02:00
|
|
|
{
|
2020-06-30 11:56:21 +02:00
|
|
|
default_monitor.rcMonitor = rect;
|
|
|
|
default_monitor.rcWork = get_work_area( &default_monitor.rcMonitor );
|
2006-10-23 14:37:17 +02:00
|
|
|
nb_monitors = 1;
|
|
|
|
monitors = &default_monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
primary = get_primary();
|
2006-10-26 12:53:59 +02:00
|
|
|
|
2006-10-23 14:37:17 +02:00
|
|
|
/* coordinates (0,0) have to point to the primary monitor origin */
|
2008-02-06 20:38:20 +01:00
|
|
|
OffsetRect( &rect, -primary->rcMonitor.left, -primary->rcMonitor.top );
|
2006-10-26 12:53:59 +02:00
|
|
|
for (i = 0; i < nb_monitors; i++)
|
|
|
|
{
|
2008-02-06 20:38:20 +01:00
|
|
|
OffsetRect( &monitors[i].rcMonitor, rect.left, rect.top );
|
|
|
|
OffsetRect( &monitors[i].rcWork, rect.left, rect.top );
|
2019-06-25 10:39:01 +02:00
|
|
|
TRACE( "monitor 0x%x: %s work %s%s\n",
|
|
|
|
i, wine_dbgstr_rect(&monitors[i].rcMonitor),
|
2008-10-01 21:00:18 +02:00
|
|
|
wine_dbgstr_rect(&monitors[i].rcWork),
|
2006-10-26 12:53:59 +02:00
|
|
|
(monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? " (primary)" : "" );
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:04:27 +01:00
|
|
|
handler.name = "Xinerama";
|
|
|
|
handler.priority = 100;
|
2019-10-25 15:40:09 +02:00
|
|
|
handler.get_gpus = xinerama_get_gpus;
|
|
|
|
handler.get_adapters = xinerama_get_adapters;
|
|
|
|
handler.get_monitors = xinerama_get_monitors;
|
|
|
|
handler.free_gpus = xinerama_free_gpus;
|
|
|
|
handler.free_adapters = xinerama_free_adapters;
|
|
|
|
handler.free_monitors = xinerama_free_monitors;
|
2019-11-01 14:20:21 +01:00
|
|
|
handler.register_event_handlers = NULL;
|
2019-06-10 16:07:02 +02:00
|
|
|
X11DRV_DisplayDevices_SetHandler( &handler );
|
2006-10-23 14:37:17 +02:00
|
|
|
}
|