2013-07-29 07:00:15 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2014-05-02 09:34:02 -04:00
|
|
|
/*
|
2013-07-29 07:00:15 -04:00
|
|
|
* Copyright (C) 2001, 2002 Havoc Pennington
|
|
|
|
* Copyright (C) 2002, 2003 Red Hat Inc.
|
|
|
|
* Some ICCCM manager selection code derived from fvwm2,
|
|
|
|
* Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
|
|
|
|
* Copyright (C) 2003 Rob Adams
|
|
|
|
* Copyright (C) 2004-2006 Elijah Newren
|
|
|
|
* Copyright (C) 2013 Red Hat Inc.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-07-29 07:00:15 -04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-07-29 07:00:15 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-07-29 07:00:15 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-03-30 20:25:31 -04:00
|
|
|
#include "meta-monitor-manager-xrandr.h"
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
2017-04-18 05:06:18 -04:00
|
|
|
#include <X11/Xlibint.h>
|
2013-07-29 07:00:15 -04:00
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#include <X11/extensions/dpms.h>
|
2017-04-18 05:06:18 -04:00
|
|
|
#include <X11/extensions/extutil.h>
|
2014-08-19 11:02:33 -04:00
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
#include <xcb/randr.h>
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
#include "meta-backend-x11.h"
|
2013-07-29 07:00:15 -04:00
|
|
|
#include <meta/main.h>
|
|
|
|
#include <meta/errors.h>
|
2014-03-31 21:59:16 -04:00
|
|
|
#include "meta-monitor-config.h"
|
2017-01-09 01:31:18 -05:00
|
|
|
#include "backends/meta-monitor-config-manager.h"
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2013-08-16 11:06:46 -04:00
|
|
|
|
2014-07-10 17:39:47 -04:00
|
|
|
#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2013-08-16 11:39:07 -04:00
|
|
|
/* Look for DPI_FALLBACK in:
|
|
|
|
* http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/xsettings/gsd-xsettings-manager.c
|
|
|
|
* for the reasoning */
|
|
|
|
#define DPI_FALLBACK 96.0
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
struct _MetaMonitorManagerXrandr
|
|
|
|
{
|
|
|
|
MetaMonitorManager parent_instance;
|
|
|
|
|
|
|
|
Display *xdisplay;
|
|
|
|
XRRScreenResources *resources;
|
|
|
|
int rr_event_base;
|
|
|
|
int rr_error_base;
|
2015-03-30 20:38:44 -04:00
|
|
|
gboolean has_randr15;
|
2016-12-13 05:58:22 -05:00
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
xcb_timestamp_t last_xrandr_set_timestamp;
|
|
|
|
|
2016-12-13 05:58:22 -05:00
|
|
|
#ifdef HAVE_XRANDR15
|
|
|
|
GHashTable *tiled_monitor_atoms;
|
|
|
|
#endif /* HAVE_XRANDR15 */
|
2017-02-15 03:06:46 -05:00
|
|
|
|
|
|
|
int max_screen_width;
|
|
|
|
int max_screen_height;
|
2013-07-29 07:00:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaMonitorManagerXrandrClass
|
|
|
|
{
|
|
|
|
MetaMonitorManagerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaMonitorManagerXrandr, meta_monitor_manager_xrandr, META_TYPE_MONITOR_MANAGER);
|
|
|
|
|
2016-12-13 05:58:22 -05:00
|
|
|
#ifdef HAVE_XRANDR15
|
|
|
|
typedef struct _MetaMonitorXrandrData
|
|
|
|
{
|
|
|
|
Atom xrandr_name;
|
|
|
|
} MetaMonitorXrandrData;
|
|
|
|
|
|
|
|
GQuark quark_meta_monitor_xrandr_data;
|
|
|
|
#endif /* HAVE_RANDR15 */
|
|
|
|
|
2014-07-10 17:39:47 -04:00
|
|
|
static MetaMonitorTransform
|
|
|
|
meta_monitor_transform_from_xrandr (Rotation rotation)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2014-07-10 17:39:47 -04:00
|
|
|
static const MetaMonitorTransform y_reflected_map[4] = {
|
|
|
|
META_MONITOR_TRANSFORM_FLIPPED_180,
|
|
|
|
META_MONITOR_TRANSFORM_FLIPPED_90,
|
|
|
|
META_MONITOR_TRANSFORM_FLIPPED,
|
|
|
|
META_MONITOR_TRANSFORM_FLIPPED_270
|
2013-07-29 07:00:15 -04:00
|
|
|
};
|
2014-07-10 17:39:47 -04:00
|
|
|
MetaMonitorTransform ret;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
switch (rotation & 0x7F)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case RR_Rotate_0:
|
2014-07-10 17:39:47 -04:00
|
|
|
ret = META_MONITOR_TRANSFORM_NORMAL;
|
2013-07-29 07:00:15 -04:00
|
|
|
break;
|
|
|
|
case RR_Rotate_90:
|
2014-07-10 17:39:47 -04:00
|
|
|
ret = META_MONITOR_TRANSFORM_90;
|
2013-07-29 07:00:15 -04:00
|
|
|
break;
|
|
|
|
case RR_Rotate_180:
|
2014-07-10 17:39:47 -04:00
|
|
|
ret = META_MONITOR_TRANSFORM_180;
|
2013-07-29 07:00:15 -04:00
|
|
|
break;
|
|
|
|
case RR_Rotate_270:
|
2014-07-10 17:39:47 -04:00
|
|
|
ret = META_MONITOR_TRANSFORM_270;
|
2013-07-29 07:00:15 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rotation & RR_Reflect_X)
|
|
|
|
return ret + 4;
|
|
|
|
else if (rotation & RR_Reflect_Y)
|
|
|
|
return y_reflected_map[ret];
|
|
|
|
else
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ALL_ROTATIONS (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)
|
|
|
|
|
2014-07-10 17:39:47 -04:00
|
|
|
static MetaMonitorTransform
|
|
|
|
meta_monitor_transform_from_xrandr_all (Rotation rotation)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
|
|
|
unsigned ret;
|
|
|
|
|
|
|
|
/* Handle the common cases first (none or all) */
|
|
|
|
if (rotation == 0 || rotation == RR_Rotate_0)
|
2014-07-10 17:39:47 -04:00
|
|
|
return (1 << META_MONITOR_TRANSFORM_NORMAL);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
/* All rotations and one reflection -> all of them by composition */
|
|
|
|
if ((rotation & ALL_ROTATIONS) &&
|
|
|
|
((rotation & RR_Reflect_X) || (rotation & RR_Reflect_Y)))
|
2014-07-10 17:39:47 -04:00
|
|
|
return ALL_TRANSFORMS;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-07-10 17:39:47 -04:00
|
|
|
ret = 1 << META_MONITOR_TRANSFORM_NORMAL;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & RR_Rotate_90)
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_90;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & RR_Rotate_180)
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_180;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & RR_Rotate_270)
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_270;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & (RR_Rotate_0 | RR_Reflect_X))
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & (RR_Rotate_90 | RR_Reflect_X))
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED_90;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & (RR_Rotate_180 | RR_Reflect_X))
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED_180;
|
2013-07-29 07:00:15 -04:00
|
|
|
if (rotation & (RR_Rotate_270 | RR_Reflect_X))
|
2014-07-10 17:39:47 -04:00
|
|
|
ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED_270;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-10 16:36:47 -05:00
|
|
|
static gboolean
|
|
|
|
output_get_integer_property (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output, const char *propname,
|
|
|
|
gint *value)
|
|
|
|
{
|
|
|
|
gboolean exists = FALSE;
|
|
|
|
Atom atom, actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, propname, False);
|
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom,
|
|
|
|
0, G_MAXLONG, False, False, XA_INTEGER,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
|
|
|
exists = (actual_type == XA_INTEGER && actual_format == 32 && nitems == 1);
|
|
|
|
|
|
|
|
if (exists && value != NULL)
|
|
|
|
*value = ((int*)buffer)[0];
|
|
|
|
|
|
|
|
XFree (buffer);
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
|
2014-11-05 12:42:15 -05:00
|
|
|
static gboolean
|
|
|
|
output_get_property_exists (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output, const char *propname)
|
|
|
|
{
|
|
|
|
gboolean exists = FALSE;
|
|
|
|
Atom atom, actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, propname, False);
|
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom,
|
|
|
|
0, G_MAXLONG, False, False, AnyPropertyType,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
|
|
|
exists = (actual_type != None);
|
|
|
|
|
|
|
|
XFree (buffer);
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static gboolean
|
2014-08-18 17:57:33 -04:00
|
|
|
output_get_boolean_property (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output, const char *propname)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2014-04-23 09:57:16 -04:00
|
|
|
Atom atom, actual_type;
|
2013-07-29 07:00:15 -04:00
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
2015-05-29 20:17:34 -04:00
|
|
|
g_autofree unsigned char *buffer = NULL;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-08-18 17:57:33 -04:00
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, propname, False);
|
2013-07-29 07:00:15 -04:00
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
2014-07-01 13:23:05 -04:00
|
|
|
(XID)output->winsys_id,
|
2014-04-23 09:57:16 -04:00
|
|
|
atom,
|
2013-07-29 07:00:15 -04:00
|
|
|
0, G_MAXLONG, False, False, XA_CARDINAL,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
2014-09-29 19:40:47 -04:00
|
|
|
if (actual_type != XA_CARDINAL || actual_format != 32 || nitems < 1)
|
2015-05-29 20:17:34 -04:00
|
|
|
return FALSE;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2015-05-29 20:17:34 -04:00
|
|
|
return ((int*)buffer)[0];
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2014-08-18 17:57:33 -04:00
|
|
|
static gboolean
|
|
|
|
output_get_presentation_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
2014-08-18 18:01:04 -04:00
|
|
|
MetaOutput *output)
|
2014-08-18 17:57:33 -04:00
|
|
|
{
|
|
|
|
return output_get_boolean_property (manager_xrandr, output, "_MUTTER_PRESENTATION_OUTPUT");
|
|
|
|
}
|
|
|
|
|
2014-04-16 04:20:55 -04:00
|
|
|
static gboolean
|
|
|
|
output_get_underscanning_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
Atom atom, actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
2015-05-29 20:17:34 -04:00
|
|
|
g_autofree unsigned char *buffer = NULL;
|
|
|
|
g_autofree char *str = NULL;
|
2014-04-16 04:20:55 -04:00
|
|
|
|
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "underscan", False);
|
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom,
|
|
|
|
0, G_MAXLONG, False, False, XA_ATOM,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
2015-05-29 20:17:34 -04:00
|
|
|
if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
|
|
|
|
return FALSE;
|
2014-04-16 04:20:55 -04:00
|
|
|
|
|
|
|
str = XGetAtomName (manager_xrandr->xdisplay, *(Atom *)buffer);
|
2015-05-29 20:17:34 -04:00
|
|
|
return (strcmp (str, "on") == 0);
|
2014-04-16 04:20:55 -04:00
|
|
|
}
|
|
|
|
|
2015-07-01 20:42:46 -04:00
|
|
|
static gboolean
|
|
|
|
output_get_supports_underscanning_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
Atom atom, actual_type;
|
|
|
|
int actual_format, i;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
g_autofree unsigned char *buffer = NULL;
|
|
|
|
XRRPropertyInfo *property_info;
|
|
|
|
Atom *values;
|
|
|
|
gboolean supports_underscanning = FALSE;
|
|
|
|
|
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "underscan", False);
|
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom,
|
|
|
|
0, G_MAXLONG, False, False, XA_ATOM,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
|
|
|
if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
property_info = XRRQueryOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
(XID) output->winsys_id,
|
|
|
|
atom);
|
|
|
|
values = (Atom *) property_info->values;
|
|
|
|
|
|
|
|
for (i = 0; i < property_info->num_values; i++)
|
|
|
|
{
|
|
|
|
/* The output supports underscanning if "on" is a valid value
|
|
|
|
* for the underscan property.
|
|
|
|
*/
|
|
|
|
char *name = XGetAtomName (manager_xrandr->xdisplay, values[i]);
|
|
|
|
if (strcmp (name, "on") == 0)
|
|
|
|
supports_underscanning = TRUE;
|
|
|
|
|
|
|
|
XFree (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree (property_info);
|
|
|
|
|
|
|
|
return supports_underscanning;
|
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static int
|
|
|
|
normalize_backlight (MetaOutput *output,
|
|
|
|
int hw_value)
|
|
|
|
{
|
|
|
|
return round ((double)(hw_value - output->backlight_min) /
|
|
|
|
(output->backlight_max - output->backlight_min) * 100.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
output_get_backlight_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
2014-09-29 19:40:47 -04:00
|
|
|
int value = -1;
|
2014-04-23 09:57:16 -04:00
|
|
|
Atom atom, actual_type;
|
2013-07-29 07:00:15 -04:00
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
2015-05-29 20:17:34 -04:00
|
|
|
g_autofree unsigned char *buffer = NULL;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
|
2013-07-29 07:00:15 -04:00
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
2014-07-01 13:23:05 -04:00
|
|
|
(XID)output->winsys_id,
|
2014-04-23 09:57:16 -04:00
|
|
|
atom,
|
2013-07-29 07:00:15 -04:00
|
|
|
0, G_MAXLONG, False, False, XA_INTEGER,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
2014-09-29 19:40:47 -04:00
|
|
|
if (actual_type != XA_INTEGER || actual_format != 32 || nitems < 1)
|
2015-05-29 20:17:34 -04:00
|
|
|
return FALSE;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
value = ((int*)buffer)[0];
|
2014-09-29 19:40:47 -04:00
|
|
|
if (value > 0)
|
|
|
|
return normalize_backlight (output, value);
|
|
|
|
else
|
|
|
|
return -1;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
output_get_backlight_limits_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
2014-04-23 09:57:16 -04:00
|
|
|
Atom atom;
|
2014-08-19 11:02:33 -04:00
|
|
|
xcb_connection_t *xcb_conn;
|
2015-11-05 22:29:05 -05:00
|
|
|
g_autofree xcb_randr_query_output_property_reply_t *reply = NULL;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-08-19 11:02:33 -04:00
|
|
|
xcb_conn = XGetXCBConnection (manager_xrandr->xdisplay);
|
|
|
|
reply = xcb_randr_query_output_property_reply (xcb_conn,
|
|
|
|
xcb_randr_query_output_property (xcb_conn,
|
|
|
|
(xcb_randr_output_t) output->winsys_id,
|
|
|
|
(xcb_atom_t) atom),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* This can happen on systems without backlights. */
|
|
|
|
if (reply == NULL)
|
|
|
|
return;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-08-19 11:02:33 -04:00
|
|
|
if (!reply->range || reply->length != 2)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
|
|
|
meta_verbose ("backlight %s was not range\n", output->name);
|
2015-05-29 20:17:34 -04:00
|
|
|
return;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2014-08-19 11:02:33 -04:00
|
|
|
int32_t *values = xcb_randr_query_output_property_valid_values (reply);
|
|
|
|
output->backlight_min = values[0];
|
|
|
|
output->backlight_max = values[1];
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_outputs (const void *one,
|
|
|
|
const void *two)
|
|
|
|
{
|
|
|
|
const MetaOutput *o_one = one, *o_two = two;
|
|
|
|
|
|
|
|
return strcmp (o_one->name, o_two->name);
|
|
|
|
}
|
|
|
|
|
2013-08-16 11:06:46 -04:00
|
|
|
static guint8 *
|
|
|
|
get_edid_property (Display *dpy,
|
|
|
|
RROutput output,
|
|
|
|
Atom atom,
|
|
|
|
gsize *len)
|
|
|
|
{
|
|
|
|
unsigned char *prop;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
Atom actual_type;
|
|
|
|
guint8 *result;
|
|
|
|
|
|
|
|
XRRGetOutputProperty (dpy, output, atom,
|
|
|
|
0, 100, False, False,
|
|
|
|
AnyPropertyType,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &prop);
|
|
|
|
|
|
|
|
if (actual_type == XA_INTEGER && actual_format == 8)
|
|
|
|
{
|
|
|
|
result = g_memdup (prop, nitems);
|
|
|
|
if (len)
|
|
|
|
*len = nitems;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree (prop);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2013-08-16 11:06:46 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GBytes *
|
|
|
|
read_output_edid (MetaMonitorManagerXrandr *manager_xrandr,
|
2014-07-01 13:23:05 -04:00
|
|
|
XID winsys_id)
|
2013-08-16 11:06:46 -04:00
|
|
|
{
|
|
|
|
Atom edid_atom;
|
|
|
|
guint8 *result;
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
edid_atom = XInternAtom (manager_xrandr->xdisplay, "EDID", FALSE);
|
2014-07-01 13:23:05 -04:00
|
|
|
result = get_edid_property (manager_xrandr->xdisplay, winsys_id, edid_atom, &len);
|
2013-08-16 11:06:46 -04:00
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
edid_atom = XInternAtom (manager_xrandr->xdisplay, "EDID_DATA", FALSE);
|
2014-07-01 13:23:05 -04:00
|
|
|
result = get_edid_property (manager_xrandr->xdisplay, winsys_id, edid_atom, &len);
|
2013-08-16 11:06:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
if (len > 0 && len % 128 == 0)
|
|
|
|
return g_bytes_new_take (result, len);
|
|
|
|
else
|
|
|
|
g_free (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:41:51 -04:00
|
|
|
static void
|
|
|
|
output_get_tile_info (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
Atom tile_atom;
|
|
|
|
unsigned char *prop;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
int actual_format;
|
|
|
|
Atom actual_type;
|
|
|
|
|
|
|
|
if (manager_xrandr->has_randr15 == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tile_atom = XInternAtom (manager_xrandr->xdisplay, "TILE", FALSE);
|
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
output->winsys_id,
|
|
|
|
tile_atom, 0, 100, False,
|
|
|
|
False, AnyPropertyType,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &prop);
|
|
|
|
|
|
|
|
if (actual_type == XA_INTEGER && actual_format == 32 && nitems == 8)
|
|
|
|
{
|
|
|
|
long *values = (long *)prop;
|
|
|
|
output->tile_info.group_id = values[0];
|
|
|
|
output->tile_info.flags = values[1];
|
|
|
|
output->tile_info.max_h_tiles = values[2];
|
|
|
|
output->tile_info.max_v_tiles = values[3];
|
|
|
|
output->tile_info.loc_h_tile = values[4];
|
|
|
|
output->tile_info.loc_v_tile = values[5];
|
|
|
|
output->tile_info.tile_w = values[6];
|
|
|
|
output->tile_info.tile_h = values[7];
|
|
|
|
}
|
|
|
|
XFree (prop);
|
|
|
|
}
|
|
|
|
|
2013-10-31 09:37:44 -04:00
|
|
|
static gboolean
|
|
|
|
output_get_hotplug_mode_update (MetaMonitorManagerXrandr *manager_xrandr,
|
2014-08-18 18:01:04 -04:00
|
|
|
MetaOutput *output)
|
2013-10-31 09:37:44 -04:00
|
|
|
{
|
2014-11-05 12:42:15 -05:00
|
|
|
return output_get_property_exists (manager_xrandr, output, "hotplug_mode_update");
|
2013-10-31 09:37:44 -04:00
|
|
|
}
|
|
|
|
|
2014-11-10 16:36:47 -05:00
|
|
|
static gint
|
|
|
|
output_get_suggested_x (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
gint val;
|
|
|
|
if (output_get_integer_property (manager_xrandr, output, "suggested X", &val))
|
|
|
|
return val;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
output_get_suggested_y (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
gint val;
|
|
|
|
if (output_get_integer_property (manager_xrandr, output, "suggested Y", &val))
|
|
|
|
return val;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-12-29 19:18:24 -05:00
|
|
|
static MetaConnectorType
|
|
|
|
connector_type_from_atom (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
Atom atom)
|
|
|
|
{
|
|
|
|
Display *xdpy = manager_xrandr->xdisplay;
|
|
|
|
|
|
|
|
if (atom == XInternAtom (xdpy, "HDMI", True))
|
|
|
|
return META_CONNECTOR_TYPE_HDMIA;
|
|
|
|
if (atom == XInternAtom (xdpy, "VGA", True))
|
|
|
|
return META_CONNECTOR_TYPE_VGA;
|
|
|
|
/* Doesn't have a DRM equivalent, but means an internal panel.
|
|
|
|
* We could pick either LVDS or eDP here. */
|
|
|
|
if (atom == XInternAtom (xdpy, "Panel", True))
|
|
|
|
return META_CONNECTOR_TYPE_LVDS;
|
|
|
|
if (atom == XInternAtom (xdpy, "DVI", True) || atom == XInternAtom (xdpy, "DVI-I", True))
|
|
|
|
return META_CONNECTOR_TYPE_DVII;
|
|
|
|
if (atom == XInternAtom (xdpy, "DVI-A", True))
|
|
|
|
return META_CONNECTOR_TYPE_DVIA;
|
|
|
|
if (atom == XInternAtom (xdpy, "DVI-D", True))
|
|
|
|
return META_CONNECTOR_TYPE_DVID;
|
|
|
|
if (atom == XInternAtom (xdpy, "DisplayPort", True))
|
|
|
|
return META_CONNECTOR_TYPE_DisplayPort;
|
|
|
|
|
|
|
|
if (atom == XInternAtom (xdpy, "TV", True))
|
|
|
|
return META_CONNECTOR_TYPE_TV;
|
|
|
|
if (atom == XInternAtom (xdpy, "TV-Composite", True))
|
|
|
|
return META_CONNECTOR_TYPE_Composite;
|
|
|
|
if (atom == XInternAtom (xdpy, "TV-SVideo", True))
|
|
|
|
return META_CONNECTOR_TYPE_SVIDEO;
|
|
|
|
/* Another set of mismatches. */
|
|
|
|
if (atom == XInternAtom (xdpy, "TV-SCART", True))
|
|
|
|
return META_CONNECTOR_TYPE_TV;
|
|
|
|
if (atom == XInternAtom (xdpy, "TV-C4", True))
|
|
|
|
return META_CONNECTOR_TYPE_TV;
|
|
|
|
|
|
|
|
return META_CONNECTOR_TYPE_Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaConnectorType
|
|
|
|
output_get_connector_type_from_prop (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
Atom atom, actual_type, connector_type_atom;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
2015-05-29 20:17:34 -04:00
|
|
|
g_autofree unsigned char *buffer = NULL;
|
2014-12-29 19:18:24 -05:00
|
|
|
|
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "ConnectorType", False);
|
|
|
|
XRRGetOutputProperty (manager_xrandr->xdisplay,
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom,
|
|
|
|
0, G_MAXLONG, False, False, XA_ATOM,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after, &buffer);
|
|
|
|
|
|
|
|
if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
|
2015-05-29 20:17:34 -04:00
|
|
|
return META_CONNECTOR_TYPE_Unknown;
|
2014-12-29 19:18:24 -05:00
|
|
|
|
|
|
|
connector_type_atom = ((Atom *) buffer)[0];
|
2015-05-29 20:17:34 -04:00
|
|
|
return connector_type_from_atom (manager_xrandr, connector_type_atom);
|
2014-12-29 19:18:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static MetaConnectorType
|
|
|
|
output_get_connector_type_from_name (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
const char *name = output->name;
|
|
|
|
|
|
|
|
/* drmmode_display.c, which was copy/pasted across all the FOSS
|
|
|
|
* xf86-video-* drivers, seems to name its outputs based on the
|
|
|
|
* connector type, so look for that....
|
|
|
|
*
|
|
|
|
* SNA has its own naming scheme, because what else did you expect
|
|
|
|
* from SNA, but it's not too different, so we can thankfully use
|
|
|
|
* that with minor changes.
|
|
|
|
*
|
|
|
|
* http://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/drivers/modesetting/drmmode_display.c#n953
|
|
|
|
* http://cgit.freedesktop.org/xorg/driver/xf86-video-intel/tree/src/sna/sna_display.c#n3486
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_str_has_prefix (name, "DVI"))
|
|
|
|
return META_CONNECTOR_TYPE_DVII;
|
|
|
|
if (g_str_has_prefix (name, "LVDS"))
|
|
|
|
return META_CONNECTOR_TYPE_LVDS;
|
|
|
|
if (g_str_has_prefix (name, "HDMI"))
|
|
|
|
return META_CONNECTOR_TYPE_HDMIA;
|
|
|
|
if (g_str_has_prefix (name, "VGA"))
|
|
|
|
return META_CONNECTOR_TYPE_VGA;
|
|
|
|
/* SNA uses DP, not DisplayPort. Test for both. */
|
|
|
|
if (g_str_has_prefix (name, "DP") || g_str_has_prefix (name, "DisplayPort"))
|
|
|
|
return META_CONNECTOR_TYPE_DisplayPort;
|
|
|
|
if (g_str_has_prefix (name, "eDP"))
|
|
|
|
return META_CONNECTOR_TYPE_eDP;
|
|
|
|
if (g_str_has_prefix (name, "Virtual"))
|
|
|
|
return META_CONNECTOR_TYPE_VIRTUAL;
|
|
|
|
if (g_str_has_prefix (name, "Composite"))
|
2015-05-12 21:16:54 -04:00
|
|
|
return META_CONNECTOR_TYPE_Composite;
|
2014-12-29 19:18:24 -05:00
|
|
|
if (g_str_has_prefix (name, "S-video"))
|
|
|
|
return META_CONNECTOR_TYPE_SVIDEO;
|
|
|
|
if (g_str_has_prefix (name, "TV"))
|
|
|
|
return META_CONNECTOR_TYPE_TV;
|
|
|
|
if (g_str_has_prefix (name, "CTV"))
|
|
|
|
return META_CONNECTOR_TYPE_Composite;
|
|
|
|
if (g_str_has_prefix (name, "DSI"))
|
|
|
|
return META_CONNECTOR_TYPE_DSI;
|
|
|
|
if (g_str_has_prefix (name, "DIN"))
|
|
|
|
return META_CONNECTOR_TYPE_9PinDIN;
|
|
|
|
|
|
|
|
return META_CONNECTOR_TYPE_Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaConnectorType
|
|
|
|
output_get_connector_type (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
MetaConnectorType ret;
|
|
|
|
|
|
|
|
/* The "ConnectorType" property is considered mandatory since RandR 1.3,
|
|
|
|
* but none of the FOSS drivers support it, because we're a bunch of
|
|
|
|
* professional software developers.
|
|
|
|
*
|
|
|
|
* Try poking it first, without any expectations that it will work.
|
|
|
|
* If it's not there, we thankfully have other bonghits to try next.
|
|
|
|
*/
|
|
|
|
ret = output_get_connector_type_from_prop (manager_xrandr, output);
|
|
|
|
if (ret != META_CONNECTOR_TYPE_Unknown)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Fall back to heuristics based on the output name. */
|
|
|
|
ret = output_get_connector_type_from_name (manager_xrandr, output);
|
|
|
|
if (ret != META_CONNECTOR_TYPE_Unknown)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return META_CONNECTOR_TYPE_Unknown;
|
|
|
|
}
|
|
|
|
|
2015-10-15 13:34:40 -04:00
|
|
|
static void
|
|
|
|
output_get_modes (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *meta_output,
|
|
|
|
XRROutputInfo *output)
|
|
|
|
{
|
|
|
|
guint j, k;
|
|
|
|
guint n_actual_modes;
|
|
|
|
|
2016-12-09 02:49:54 -05:00
|
|
|
meta_output->modes = g_new0 (MetaCrtcMode *, output->nmode);
|
2015-10-15 13:34:40 -04:00
|
|
|
|
|
|
|
n_actual_modes = 0;
|
|
|
|
for (j = 0; j < (guint)output->nmode; j++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < manager->n_modes; k++)
|
|
|
|
{
|
|
|
|
if (output->modes[j] == (XID)manager->modes[k].mode_id)
|
|
|
|
{
|
|
|
|
meta_output->modes[n_actual_modes] = &manager->modes[k];
|
|
|
|
n_actual_modes += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
meta_output->n_modes = n_actual_modes;
|
2015-10-27 10:24:58 -04:00
|
|
|
if (n_actual_modes > 0)
|
|
|
|
meta_output->preferred_mode = meta_output->modes[0];
|
2015-10-15 13:34:40 -04:00
|
|
|
}
|
|
|
|
|
2015-10-27 10:43:58 -04:00
|
|
|
static void
|
|
|
|
output_get_crtcs (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *meta_output,
|
|
|
|
XRROutputInfo *output)
|
|
|
|
{
|
|
|
|
guint j, k;
|
|
|
|
guint n_actual_crtcs;
|
|
|
|
|
2016-12-07 23:15:28 -05:00
|
|
|
meta_output->possible_crtcs = g_new0 (MetaCrtc *, output->ncrtc);
|
2015-10-27 10:43:58 -04:00
|
|
|
|
|
|
|
n_actual_crtcs = 0;
|
|
|
|
for (j = 0; j < (unsigned)output->ncrtc; j++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < manager->n_crtcs; k++)
|
|
|
|
{
|
|
|
|
if ((XID)manager->crtcs[k].crtc_id == output->crtcs[j])
|
|
|
|
{
|
|
|
|
meta_output->possible_crtcs[n_actual_crtcs] = &manager->crtcs[k];
|
|
|
|
n_actual_crtcs += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
meta_output->n_possible_crtcs = n_actual_crtcs;
|
|
|
|
|
|
|
|
meta_output->crtc = NULL;
|
|
|
|
for (j = 0; j < manager->n_crtcs; j++)
|
|
|
|
{
|
|
|
|
if ((XID)manager->crtcs[j].crtc_id == output->crtc)
|
|
|
|
{
|
|
|
|
meta_output->crtc = &manager->crtcs[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 08:48:42 -04:00
|
|
|
static char *
|
|
|
|
get_xmode_name (XRRModeInfo *xmode)
|
|
|
|
{
|
|
|
|
int width = xmode->width;
|
|
|
|
int height = xmode->height;
|
|
|
|
|
|
|
|
return g_strdup_printf ("%dx%d", width, height);
|
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
XRRScreenResources *resources;
|
|
|
|
RROutput primary_output;
|
|
|
|
unsigned int i, j, k;
|
|
|
|
unsigned int n_actual_outputs;
|
|
|
|
int min_width, min_height;
|
|
|
|
Screen *screen;
|
|
|
|
BOOL dpms_capable, dpms_enabled;
|
|
|
|
CARD16 dpms_state;
|
|
|
|
|
|
|
|
if (manager_xrandr->resources)
|
|
|
|
XRRFreeScreenResources (manager_xrandr->resources);
|
|
|
|
manager_xrandr->resources = NULL;
|
|
|
|
|
|
|
|
dpms_capable = DPMSCapable (manager_xrandr->xdisplay);
|
|
|
|
|
|
|
|
if (dpms_capable &&
|
|
|
|
DPMSInfo (manager_xrandr->xdisplay, &dpms_state, &dpms_enabled) &&
|
|
|
|
dpms_enabled)
|
|
|
|
{
|
|
|
|
switch (dpms_state)
|
2013-08-21 13:07:01 -04:00
|
|
|
{
|
|
|
|
case DPMSModeOn:
|
|
|
|
manager->power_save_mode = META_POWER_SAVE_ON;
|
|
|
|
break;
|
|
|
|
case DPMSModeStandby:
|
|
|
|
manager->power_save_mode = META_POWER_SAVE_STANDBY;
|
|
|
|
break;
|
|
|
|
case DPMSModeSuspend:
|
|
|
|
manager->power_save_mode = META_POWER_SAVE_SUSPEND;
|
|
|
|
break;
|
|
|
|
case DPMSModeOff:
|
|
|
|
manager->power_save_mode = META_POWER_SAVE_OFF;
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-09 07:12:20 -04:00
|
|
|
manager->power_save_mode = META_POWER_SAVE_UNSUPPORTED;
|
2013-08-21 13:07:01 -04:00
|
|
|
break;
|
|
|
|
}
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-09 07:12:20 -04:00
|
|
|
manager->power_save_mode = META_POWER_SAVE_UNSUPPORTED;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
XRRGetScreenSizeRange (manager_xrandr->xdisplay, DefaultRootWindow (manager_xrandr->xdisplay),
|
|
|
|
&min_width,
|
|
|
|
&min_height,
|
2017-02-15 03:06:46 -05:00
|
|
|
&manager_xrandr->max_screen_width,
|
|
|
|
&manager_xrandr->max_screen_height);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
screen = ScreenOfDisplay (manager_xrandr->xdisplay,
|
|
|
|
DefaultScreen (manager_xrandr->xdisplay));
|
|
|
|
/* This is updated because we called RRUpdateConfiguration below */
|
|
|
|
manager->screen_width = WidthOfScreen (screen);
|
|
|
|
manager->screen_height = HeightOfScreen (screen);
|
|
|
|
|
|
|
|
resources = XRRGetScreenResourcesCurrent (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay));
|
|
|
|
if (!resources)
|
|
|
|
return;
|
|
|
|
|
|
|
|
manager_xrandr->resources = resources;
|
|
|
|
manager->n_outputs = resources->noutput;
|
|
|
|
manager->n_crtcs = resources->ncrtc;
|
|
|
|
manager->n_modes = resources->nmode;
|
|
|
|
manager->outputs = g_new0 (MetaOutput, manager->n_outputs);
|
2016-12-09 02:49:54 -05:00
|
|
|
manager->modes = g_new0 (MetaCrtcMode, manager->n_modes);
|
2016-12-07 23:15:28 -05:00
|
|
|
manager->crtcs = g_new0 (MetaCrtc, manager->n_crtcs);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
for (i = 0; i < (unsigned)resources->nmode; i++)
|
|
|
|
{
|
|
|
|
XRRModeInfo *xmode = &resources->modes[i];
|
2016-12-09 02:49:54 -05:00
|
|
|
MetaCrtcMode *mode;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
mode = &manager->modes[i];
|
|
|
|
|
|
|
|
mode->mode_id = xmode->id;
|
|
|
|
mode->width = xmode->width;
|
|
|
|
mode->height = xmode->height;
|
|
|
|
mode->refresh_rate = (xmode->dotClock /
|
|
|
|
((float)xmode->hTotal * xmode->vTotal));
|
2015-04-21 11:49:55 -04:00
|
|
|
mode->flags = xmode->modeFlags;
|
2014-08-23 08:48:42 -04:00
|
|
|
mode->name = get_xmode_name (xmode);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < (unsigned)resources->ncrtc; i++)
|
|
|
|
{
|
|
|
|
XRRCrtcInfo *crtc;
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *meta_crtc;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
crtc = XRRGetCrtcInfo (manager_xrandr->xdisplay, resources, resources->crtcs[i]);
|
|
|
|
|
|
|
|
meta_crtc = &manager->crtcs[i];
|
|
|
|
|
|
|
|
meta_crtc->crtc_id = resources->crtcs[i];
|
|
|
|
meta_crtc->rect.x = crtc->x;
|
|
|
|
meta_crtc->rect.y = crtc->y;
|
|
|
|
meta_crtc->rect.width = crtc->width;
|
|
|
|
meta_crtc->rect.height = crtc->height;
|
|
|
|
meta_crtc->is_dirty = FALSE;
|
2014-07-10 17:39:47 -04:00
|
|
|
meta_crtc->transform = meta_monitor_transform_from_xrandr (crtc->rotation);
|
|
|
|
meta_crtc->all_transforms = meta_monitor_transform_from_xrandr_all (crtc->rotations);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
for (j = 0; j < (unsigned)resources->nmode; j++)
|
|
|
|
{
|
|
|
|
if (resources->modes[j].id == crtc->mode)
|
|
|
|
{
|
|
|
|
meta_crtc->current_mode = &manager->modes[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XRRFreeCrtcInfo (crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
primary_output = XRRGetOutputPrimary (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay));
|
|
|
|
|
|
|
|
n_actual_outputs = 0;
|
|
|
|
for (i = 0; i < (unsigned)resources->noutput; i++)
|
|
|
|
{
|
|
|
|
XRROutputInfo *output;
|
|
|
|
MetaOutput *meta_output;
|
|
|
|
|
|
|
|
output = XRRGetOutputInfo (manager_xrandr->xdisplay, resources, resources->outputs[i]);
|
2015-10-15 13:34:40 -04:00
|
|
|
if (!output)
|
|
|
|
continue;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
meta_output = &manager->outputs[n_actual_outputs];
|
|
|
|
|
|
|
|
if (output->connection != RR_Disconnected)
|
|
|
|
{
|
2013-08-16 11:06:46 -04:00
|
|
|
GBytes *edid;
|
|
|
|
|
2014-07-01 13:23:05 -04:00
|
|
|
meta_output->winsys_id = resources->outputs[i];
|
2013-07-29 07:00:15 -04:00
|
|
|
meta_output->name = g_strdup (output->name);
|
2013-08-16 11:06:46 -04:00
|
|
|
|
2014-07-01 13:23:05 -04:00
|
|
|
edid = read_output_edid (manager_xrandr, meta_output->winsys_id);
|
2015-01-23 11:32:21 -05:00
|
|
|
meta_output_parse_edid (meta_output, edid);
|
|
|
|
g_bytes_unref (edid);
|
2013-08-16 11:06:46 -04:00
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
meta_output->width_mm = output->mm_width;
|
|
|
|
meta_output->height_mm = output->mm_height;
|
|
|
|
meta_output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
|
2014-08-18 17:57:33 -04:00
|
|
|
meta_output->hotplug_mode_update = output_get_hotplug_mode_update (manager_xrandr, meta_output);
|
2014-11-10 16:36:47 -05:00
|
|
|
meta_output->suggested_x = output_get_suggested_x (manager_xrandr, meta_output);
|
|
|
|
meta_output->suggested_y = output_get_suggested_y (manager_xrandr, meta_output);
|
2014-12-29 19:18:24 -05:00
|
|
|
meta_output->connector_type = output_get_connector_type (manager_xrandr, meta_output);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2015-03-30 20:41:51 -04:00
|
|
|
output_get_tile_info (manager_xrandr, meta_output);
|
2015-10-27 10:07:05 -04:00
|
|
|
output_get_modes (manager, meta_output, output);
|
2015-10-27 10:43:58 -04:00
|
|
|
output_get_crtcs (manager, meta_output, output);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
meta_output->n_possible_clones = output->nclone;
|
|
|
|
meta_output->possible_clones = g_new0 (MetaOutput *, meta_output->n_possible_clones);
|
|
|
|
/* We can build the list of clones now, because we don't have the list of outputs
|
|
|
|
yet, so temporarily set the pointers to the bare XIDs, and then we'll fix them
|
|
|
|
in a second pass
|
|
|
|
*/
|
|
|
|
for (j = 0; j < (unsigned)output->nclone; j++)
|
|
|
|
{
|
2013-08-22 12:39:56 -04:00
|
|
|
meta_output->possible_clones[j] = GINT_TO_POINTER (output->clones[j]);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2014-07-01 13:23:05 -04:00
|
|
|
meta_output->is_primary = ((XID)meta_output->winsys_id == primary_output);
|
2013-07-29 07:00:15 -04:00
|
|
|
meta_output->is_presentation = output_get_presentation_xrandr (manager_xrandr, meta_output);
|
2014-04-16 04:20:55 -04:00
|
|
|
meta_output->is_underscanning = output_get_underscanning_xrandr (manager_xrandr, meta_output);
|
2015-07-01 20:42:46 -04:00
|
|
|
meta_output->supports_underscanning = output_get_supports_underscanning_xrandr (manager_xrandr, meta_output);
|
2013-07-29 07:00:15 -04:00
|
|
|
output_get_backlight_limits_xrandr (manager_xrandr, meta_output);
|
|
|
|
|
|
|
|
if (!(meta_output->backlight_min == 0 && meta_output->backlight_max == 0))
|
|
|
|
meta_output->backlight = output_get_backlight_xrandr (manager_xrandr, meta_output);
|
|
|
|
else
|
|
|
|
meta_output->backlight = -1;
|
|
|
|
|
2015-10-27 10:43:58 -04:00
|
|
|
if (meta_output->n_modes == 0 || meta_output->n_possible_crtcs == 0)
|
2015-10-27 10:24:58 -04:00
|
|
|
meta_monitor_manager_clear_output (meta_output);
|
|
|
|
else
|
|
|
|
n_actual_outputs++;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
XRRFreeOutputInfo (output);
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->n_outputs = n_actual_outputs;
|
|
|
|
|
|
|
|
/* Sort the outputs for easier handling in MetaMonitorConfig */
|
|
|
|
qsort (manager->outputs, manager->n_outputs, sizeof (MetaOutput), compare_outputs);
|
|
|
|
|
|
|
|
/* Now fix the clones */
|
|
|
|
for (i = 0; i < manager->n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutput *meta_output;
|
|
|
|
|
|
|
|
meta_output = &manager->outputs[i];
|
|
|
|
|
|
|
|
for (j = 0; j < meta_output->n_possible_clones; j++)
|
|
|
|
{
|
|
|
|
RROutput clone = GPOINTER_TO_INT (meta_output->possible_clones[j]);
|
|
|
|
|
|
|
|
for (k = 0; k < manager->n_outputs; k++)
|
|
|
|
{
|
2014-07-01 13:23:05 -04:00
|
|
|
if (clone == (XID)manager->outputs[k].winsys_id)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
|
|
|
meta_output->possible_clones[j] = &manager->outputs[k];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 07:32:05 -04:00
|
|
|
static GBytes *
|
|
|
|
meta_monitor_manager_xrandr_read_edid (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
|
2014-07-01 13:23:05 -04:00
|
|
|
return read_output_edid (manager_xrandr, output->winsys_id);
|
2013-08-08 07:32:05 -04:00
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_set_power_save_mode (MetaMonitorManager *manager,
|
|
|
|
MetaPowerSave mode)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
CARD16 state;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case META_POWER_SAVE_ON:
|
|
|
|
state = DPMSModeOn;
|
|
|
|
break;
|
|
|
|
case META_POWER_SAVE_STANDBY:
|
|
|
|
state = DPMSModeStandby;
|
|
|
|
break;
|
|
|
|
case META_POWER_SAVE_SUSPEND:
|
|
|
|
state = DPMSModeSuspend;
|
|
|
|
break;
|
|
|
|
case META_POWER_SAVE_OFF:
|
|
|
|
state = DPMSModeOff;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPMSForceLevel (manager_xrandr->xdisplay, state);
|
|
|
|
DPMSSetTimeouts (manager_xrandr->xdisplay, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
static xcb_randr_rotation_t
|
2014-07-10 17:39:47 -04:00
|
|
|
meta_monitor_transform_to_xrandr (MetaMonitorTransform transform)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
|
|
|
switch (transform)
|
|
|
|
{
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_NORMAL:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_ROTATE_0;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_90:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_ROTATE_90;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_180:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_ROTATE_180;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_270:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_ROTATE_270;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_0;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED_90:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_90;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED_180:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_180;
|
2014-07-10 17:39:47 -04:00
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED_270:
|
2017-04-18 05:06:18 -04:00
|
|
|
return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_270;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
output_set_presentation_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output,
|
|
|
|
gboolean presentation)
|
|
|
|
{
|
2014-04-23 09:57:16 -04:00
|
|
|
Atom atom;
|
2013-07-29 07:00:15 -04:00
|
|
|
int value = presentation;
|
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "_MUTTER_PRESENTATION_OUTPUT", False);
|
2015-06-28 16:25:49 -04:00
|
|
|
|
|
|
|
xcb_randr_change_output_property (XGetXCBConnection (manager_xrandr->xdisplay),
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom, XCB_ATOM_CARDINAL, 32,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
1, &value);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2014-04-16 04:20:55 -04:00
|
|
|
static void
|
|
|
|
output_set_underscanning_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
MetaOutput *output,
|
|
|
|
gboolean underscanning)
|
|
|
|
{
|
|
|
|
Atom prop, valueatom;
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
prop = XInternAtom (manager_xrandr->xdisplay, "underscan", False);
|
|
|
|
|
|
|
|
value = underscanning ? "on" : "off";
|
|
|
|
valueatom = XInternAtom (manager_xrandr->xdisplay, value, False);
|
2015-06-28 16:25:49 -04:00
|
|
|
|
|
|
|
xcb_randr_change_output_property (XGetXCBConnection (manager_xrandr->xdisplay),
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
prop, XCB_ATOM_ATOM, 32,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
1, &valueatom);
|
2015-04-27 20:23:56 -04:00
|
|
|
|
|
|
|
/* Configure the border at the same time. Currently, we use a
|
|
|
|
* 5% of the width/height of the mode. In the future, we should
|
|
|
|
* make the border configurable. */
|
|
|
|
if (underscanning)
|
|
|
|
{
|
|
|
|
uint32_t border_value;
|
|
|
|
|
|
|
|
prop = XInternAtom (manager_xrandr->xdisplay, "underscan hborder", False);
|
|
|
|
border_value = output->crtc->current_mode->width * 0.05;
|
2015-06-28 16:25:49 -04:00
|
|
|
|
|
|
|
xcb_randr_change_output_property (XGetXCBConnection (manager_xrandr->xdisplay),
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
prop, XCB_ATOM_INTEGER, 32,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
1, &border_value);
|
2015-04-27 20:23:56 -04:00
|
|
|
|
|
|
|
prop = XInternAtom (manager_xrandr->xdisplay, "underscan vborder", False);
|
|
|
|
border_value = output->crtc->current_mode->height * 0.05;
|
2015-06-28 16:25:49 -04:00
|
|
|
|
|
|
|
xcb_randr_change_output_property (XGetXCBConnection (manager_xrandr->xdisplay),
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
prop, XCB_ATOM_INTEGER, 32,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
1, &border_value);
|
2015-04-27 20:23:56 -04:00
|
|
|
}
|
2014-04-16 04:20:55 -04:00
|
|
|
}
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
static gboolean
|
|
|
|
xrandr_set_crtc_config (MetaMonitorManagerXrandr *manager_xrandr,
|
2017-04-21 06:01:15 -04:00
|
|
|
gboolean save_timestamp,
|
2017-04-18 05:06:18 -04:00
|
|
|
xcb_randr_crtc_t crtc,
|
|
|
|
xcb_timestamp_t timestamp,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
xcb_randr_mode_t mode,
|
|
|
|
xcb_randr_rotation_t rotation,
|
|
|
|
xcb_randr_output_t *outputs,
|
|
|
|
int n_outputs)
|
|
|
|
{
|
|
|
|
xcb_connection_t *xcb_conn;
|
|
|
|
xcb_timestamp_t config_timestamp;
|
|
|
|
xcb_randr_set_crtc_config_cookie_t cookie;
|
|
|
|
xcb_randr_set_crtc_config_reply_t *reply;
|
|
|
|
xcb_generic_error_t *xcb_error = NULL;
|
|
|
|
|
|
|
|
xcb_conn = XGetXCBConnection (manager_xrandr->xdisplay);
|
|
|
|
config_timestamp = manager_xrandr->resources->configTimestamp;
|
|
|
|
cookie = xcb_randr_set_crtc_config (xcb_conn,
|
|
|
|
crtc,
|
|
|
|
timestamp,
|
|
|
|
config_timestamp,
|
|
|
|
x, y,
|
|
|
|
mode,
|
|
|
|
rotation,
|
|
|
|
n_outputs,
|
|
|
|
outputs);
|
|
|
|
reply = xcb_randr_set_crtc_config_reply (xcb_conn,
|
|
|
|
cookie,
|
|
|
|
&xcb_error);
|
|
|
|
if (xcb_error || !reply)
|
|
|
|
{
|
|
|
|
free (xcb_error);
|
|
|
|
free (reply);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
if (save_timestamp)
|
|
|
|
manager_xrandr->last_xrandr_set_timestamp = reply->timestamp;
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
free (reply);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
static gboolean
|
|
|
|
is_crtc_assignment_changed (MetaCrtc *crtc,
|
|
|
|
MetaCrtcInfo **crtc_infos,
|
|
|
|
unsigned int n_crtc_infos)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_crtc_infos; i++)
|
|
|
|
{
|
|
|
|
MetaCrtcInfo *crtc_info = crtc_infos[i];
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
if (crtc_info->crtc != crtc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (crtc->current_mode != crtc_info->mode)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (crtc->rect.x != crtc_info->x)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (crtc->rect.y != crtc_info->y)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (crtc->transform != crtc_info->transform)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (j = 0; j < crtc_info->outputs->len; j++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = ((MetaOutput**) crtc_info->outputs->pdata)[j];
|
|
|
|
|
|
|
|
if (output->crtc != crtc)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return crtc->current_mode != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_output_assignment_changed (MetaOutput *output,
|
|
|
|
MetaCrtcInfo **crtc_infos,
|
|
|
|
unsigned int n_crtc_infos,
|
|
|
|
MetaOutputInfo **output_infos,
|
|
|
|
unsigned int n_output_infos)
|
|
|
|
{
|
|
|
|
gboolean output_is_found = FALSE;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_output_infos; i++)
|
|
|
|
{
|
|
|
|
MetaOutputInfo *output_info = output_infos[i];
|
|
|
|
|
|
|
|
if (output_info->output != output)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (output->is_primary != output_info->is_primary)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (output->is_presentation != output_info->is_presentation)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (output->is_underscanning != output_info->is_underscanning)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
output_is_found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!output_is_found)
|
|
|
|
return output->crtc != NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < n_crtc_infos; i++)
|
|
|
|
{
|
|
|
|
MetaCrtcInfo *crtc_info = crtc_infos[i];
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
for (j = 0; j < crtc_info->outputs->len; j++)
|
|
|
|
{
|
|
|
|
MetaOutput *crtc_info_output =
|
|
|
|
((MetaOutput**) crtc_info->outputs->pdata)[j];
|
|
|
|
|
|
|
|
if (crtc_info_output == output &&
|
|
|
|
crtc_info->crtc == output->crtc)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_assignments_changed (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcInfo **crtc_infos,
|
|
|
|
unsigned int n_crtc_infos,
|
|
|
|
MetaOutputInfo **output_infos,
|
|
|
|
unsigned int n_output_infos)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < manager->n_crtcs; i++)
|
|
|
|
{
|
|
|
|
MetaCrtc *crtc = &manager->crtcs[i];
|
|
|
|
|
|
|
|
if (is_crtc_assignment_changed (crtc, crtc_infos, n_crtc_infos))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < manager->n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = &manager->outputs[i];
|
|
|
|
|
|
|
|
if (is_output_assignment_changed (output,
|
|
|
|
crtc_infos,
|
|
|
|
n_crtc_infos,
|
|
|
|
output_infos,
|
|
|
|
n_output_infos))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static void
|
2017-01-09 01:31:18 -05:00
|
|
|
apply_crtc_assignments (MetaMonitorManager *manager,
|
2017-04-21 06:01:15 -04:00
|
|
|
gboolean save_timestamp,
|
2017-01-09 01:31:18 -05:00
|
|
|
MetaCrtcInfo **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputInfo **outputs,
|
|
|
|
unsigned int n_outputs)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
unsigned i;
|
2013-08-16 11:39:07 -04:00
|
|
|
int width, height, width_mm, height_mm;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
XGrabServer (manager_xrandr->xdisplay);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2013-08-16 13:02:57 -04:00
|
|
|
/* First compute the new size of the screen (framebuffer) */
|
2013-08-16 11:39:07 -04:00
|
|
|
width = 0; height = 0;
|
|
|
|
for (i = 0; i < n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcInfo *crtc_info = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_info->crtc;
|
2013-08-16 13:02:57 -04:00
|
|
|
crtc->is_dirty = TRUE;
|
2013-08-16 11:39:07 -04:00
|
|
|
|
|
|
|
if (crtc_info->mode == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (meta_monitor_transform_is_rotated (crtc_info->transform))
|
|
|
|
{
|
|
|
|
width = MAX (width, crtc_info->x + crtc_info->mode->height);
|
|
|
|
height = MAX (height, crtc_info->y + crtc_info->mode->width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = MAX (width, crtc_info->x + crtc_info->mode->width);
|
|
|
|
height = MAX (height, crtc_info->y + crtc_info->mode->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 13:02:57 -04:00
|
|
|
/* Second disable all newly disabled CRTCs, or CRTCs that in the previous
|
|
|
|
configuration would be outside the new framebuffer (otherwise X complains
|
|
|
|
loudly when resizing)
|
|
|
|
CRTC will be enabled again after resizing the FB
|
|
|
|
*/
|
|
|
|
for (i = 0; i < n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcInfo *crtc_info = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_info->crtc;
|
2013-08-16 13:02:57 -04:00
|
|
|
|
|
|
|
if (crtc_info->mode == NULL ||
|
|
|
|
crtc->rect.x + crtc->rect.width > width ||
|
|
|
|
crtc->rect.y + crtc->rect.height > height)
|
|
|
|
{
|
2017-04-18 05:06:18 -04:00
|
|
|
xrandr_set_crtc_config (manager_xrandr,
|
2017-04-21 06:01:15 -04:00
|
|
|
save_timestamp,
|
2017-04-18 05:06:18 -04:00
|
|
|
(xcb_randr_crtc_t) crtc->crtc_id,
|
|
|
|
XCB_CURRENT_TIME,
|
|
|
|
0, 0, XCB_NONE,
|
|
|
|
XCB_RANDR_ROTATION_ROTATE_0,
|
|
|
|
NULL, 0);
|
2013-08-17 13:15:40 -04:00
|
|
|
|
|
|
|
crtc->rect.x = 0;
|
|
|
|
crtc->rect.y = 0;
|
|
|
|
crtc->rect.width = 0;
|
|
|
|
crtc->rect.height = 0;
|
|
|
|
crtc->current_mode = NULL;
|
2013-08-16 13:02:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable CRTCs not mentioned in the list */
|
|
|
|
for (i = 0; i < manager->n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc = &manager->crtcs[i];
|
2013-08-16 13:02:57 -04:00
|
|
|
|
|
|
|
if (crtc->is_dirty)
|
|
|
|
{
|
|
|
|
crtc->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (crtc->current_mode == NULL)
|
|
|
|
continue;
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
xrandr_set_crtc_config (manager_xrandr,
|
2017-04-21 06:01:15 -04:00
|
|
|
save_timestamp,
|
2017-04-18 05:06:18 -04:00
|
|
|
(xcb_randr_crtc_t) crtc->crtc_id,
|
|
|
|
XCB_CURRENT_TIME,
|
|
|
|
0, 0, XCB_NONE,
|
|
|
|
XCB_RANDR_ROTATION_ROTATE_0,
|
|
|
|
NULL, 0);
|
2013-08-17 13:15:40 -04:00
|
|
|
|
|
|
|
crtc->rect.x = 0;
|
|
|
|
crtc->rect.y = 0;
|
|
|
|
crtc->rect.width = 0;
|
|
|
|
crtc->rect.height = 0;
|
|
|
|
crtc->current_mode = NULL;
|
2013-08-16 13:02:57 -04:00
|
|
|
}
|
|
|
|
|
2013-08-16 11:39:07 -04:00
|
|
|
g_assert (width > 0 && height > 0);
|
|
|
|
/* The 'physical size' of an X screen is meaningless if that screen
|
|
|
|
* can consist of many monitors. So just pick a size that make the
|
|
|
|
* dpi 96.
|
|
|
|
*
|
|
|
|
* Firefox and Evince apparently believe what X tells them.
|
|
|
|
*/
|
|
|
|
width_mm = (width / DPI_FALLBACK) * 25.4 + 0.5;
|
|
|
|
height_mm = (height / DPI_FALLBACK) * 25.4 + 0.5;
|
|
|
|
XRRSetScreenSize (manager_xrandr->xdisplay, DefaultRootWindow (manager_xrandr->xdisplay),
|
|
|
|
width, height, width_mm, height_mm);
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
for (i = 0; i < n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcInfo *crtc_info = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_info->crtc;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2013-08-16 13:02:57 -04:00
|
|
|
if (crtc_info->mode != NULL)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2016-12-09 02:49:54 -05:00
|
|
|
MetaCrtcMode *mode;
|
2017-04-18 05:06:18 -04:00
|
|
|
g_autofree xcb_randr_output_t *output_ids = NULL;
|
2015-09-23 19:24:33 -04:00
|
|
|
unsigned int j, n_output_ids;
|
2017-04-18 05:06:18 -04:00
|
|
|
xcb_randr_rotation_t rotation;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
mode = crtc_info->mode;
|
|
|
|
|
2015-09-23 19:24:33 -04:00
|
|
|
n_output_ids = crtc_info->outputs->len;
|
2017-04-18 05:06:18 -04:00
|
|
|
output_ids = g_new (xcb_randr_output_t, n_output_ids);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2015-09-23 19:24:33 -04:00
|
|
|
for (j = 0; j < n_output_ids; j++)
|
2013-08-23 11:25:44 -04:00
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
output = ((MetaOutput**)crtc_info->outputs->pdata)[j];
|
|
|
|
|
|
|
|
output->is_dirty = TRUE;
|
|
|
|
output->crtc = crtc;
|
|
|
|
|
2015-09-23 19:24:33 -04:00
|
|
|
output_ids[j] = output->winsys_id;
|
2013-08-23 11:25:44 -04:00
|
|
|
}
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
rotation = meta_monitor_transform_to_xrandr (crtc_info->transform);
|
|
|
|
if (!xrandr_set_crtc_config (manager_xrandr,
|
2017-04-21 06:01:15 -04:00
|
|
|
save_timestamp,
|
2017-04-18 05:06:18 -04:00
|
|
|
(xcb_randr_crtc_t) crtc->crtc_id,
|
|
|
|
XCB_CURRENT_TIME,
|
|
|
|
crtc_info->x, crtc_info->y,
|
|
|
|
(xcb_randr_mode_t) mode->mode_id,
|
|
|
|
rotation,
|
|
|
|
output_ids, n_output_ids))
|
2013-08-17 13:15:40 -04:00
|
|
|
{
|
2015-01-05 18:23:17 -05:00
|
|
|
meta_warning ("Configuring CRTC %d with mode %d (%d x %d @ %f) at position %d, %d and transform %u failed\n",
|
2013-08-17 13:15:40 -04:00
|
|
|
(unsigned)(crtc->crtc_id), (unsigned)(mode->mode_id),
|
|
|
|
mode->width, mode->height, (float)mode->refresh_rate,
|
|
|
|
crtc_info->x, crtc_info->y, crtc_info->transform);
|
2015-05-29 20:17:34 -04:00
|
|
|
continue;
|
2013-08-17 13:15:40 -04:00
|
|
|
}
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2013-08-17 13:15:40 -04:00
|
|
|
if (meta_monitor_transform_is_rotated (crtc_info->transform))
|
|
|
|
{
|
|
|
|
width = mode->height;
|
|
|
|
height = mode->width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = mode->width;
|
|
|
|
height = mode->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->rect.x = crtc_info->x;
|
|
|
|
crtc->rect.y = crtc_info->y;
|
|
|
|
crtc->rect.width = width;
|
|
|
|
crtc->rect.height = height;
|
|
|
|
crtc->current_mode = mode;
|
|
|
|
crtc->transform = crtc_info->transform;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutputInfo *output_info = outputs[i];
|
2013-08-17 13:15:40 -04:00
|
|
|
MetaOutput *output = output_info->output;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
if (output_info->is_primary)
|
|
|
|
{
|
|
|
|
XRRSetOutputPrimary (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay),
|
2014-07-01 13:23:05 -04:00
|
|
|
(XID)output_info->output->winsys_id);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
output_set_presentation_xrandr (manager_xrandr,
|
|
|
|
output_info->output,
|
|
|
|
output_info->is_presentation);
|
2013-08-17 13:15:40 -04:00
|
|
|
|
2015-07-01 20:59:36 -04:00
|
|
|
if (output_get_supports_underscanning_xrandr (manager_xrandr, output_info->output))
|
|
|
|
output_set_underscanning_xrandr (manager_xrandr,
|
|
|
|
output_info->output,
|
|
|
|
output_info->is_underscanning);
|
2014-04-16 04:20:55 -04:00
|
|
|
|
2013-08-17 13:15:40 -04:00
|
|
|
output->is_primary = output_info->is_primary;
|
|
|
|
output->is_presentation = output_info->is_presentation;
|
2014-04-16 04:20:55 -04:00
|
|
|
output->is_underscanning = output_info->is_underscanning;
|
2013-08-17 13:15:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable outputs not mentioned in the list */
|
|
|
|
for (i = 0; i < manager->n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = &manager->outputs[i];
|
|
|
|
|
|
|
|
if (output->is_dirty)
|
|
|
|
{
|
|
|
|
output->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->crtc = NULL;
|
|
|
|
output->is_primary = FALSE;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
XUngrabServer (manager_xrandr->xdisplay);
|
2014-05-22 17:38:49 -04:00
|
|
|
XFlush (manager_xrandr->xdisplay);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2017-01-06 00:27:21 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_ensure_initial_config (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
MetaMonitorManagerDeriveFlag flags =
|
|
|
|
META_MONITOR_MANAGER_DERIVE_FLAG_NONE;
|
|
|
|
|
2017-01-06 00:27:21 -05:00
|
|
|
meta_monitor_manager_ensure_configured (manager);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normally we don't rebuild our data structures until we see the
|
|
|
|
* RRScreenNotify event, but at least at startup we want to have the right
|
|
|
|
* configuration immediately.
|
|
|
|
*/
|
|
|
|
meta_monitor_manager_read_current_state (manager);
|
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
if (meta_is_monitor_config_manager_enabled ())
|
|
|
|
flags |= META_MONITOR_MANAGER_DERIVE_FLAG_CONFIGURED_SCALE;
|
|
|
|
|
|
|
|
meta_monitor_manager_update_logical_state_derived (manager, flags);
|
2017-01-06 00:27:21 -05:00
|
|
|
}
|
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
static gboolean
|
2017-02-14 06:54:04 -05:00
|
|
|
meta_monitor_manager_xrandr_apply_monitors_config (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config,
|
|
|
|
MetaMonitorsConfigMethod method,
|
|
|
|
GError **error)
|
2017-01-09 01:31:18 -05:00
|
|
|
{
|
|
|
|
GPtrArray *crtc_infos;
|
|
|
|
GPtrArray *output_infos;
|
|
|
|
|
2017-01-20 01:50:11 -05:00
|
|
|
if (!config)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
MetaMonitorManagerDeriveFlag flags =
|
|
|
|
META_MONITOR_MANAGER_DERIVE_FLAG_NONE;
|
|
|
|
|
|
|
|
meta_monitor_manager_rebuild_derived (manager, flags);
|
2017-01-20 01:50:11 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
if (!meta_monitor_config_manager_assign (manager, config,
|
|
|
|
&crtc_infos, &output_infos,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-14 06:54:04 -05:00
|
|
|
if (method != META_MONITORS_CONFIG_METHOD_VERIFY)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
/*
|
|
|
|
* If the assignment has not changed, we won't get any notification about
|
|
|
|
* any new configuration from the X server; but we still need to update
|
|
|
|
* our own configuration, as something not applicable in Xrandr might
|
|
|
|
* have changed locally, such as the logical monitors scale. This means we
|
|
|
|
* must check that our new assignment actually changes anything, otherwise
|
|
|
|
* just update the logical state.
|
|
|
|
*/
|
|
|
|
if (is_assignments_changed (manager,
|
|
|
|
(MetaCrtcInfo **) crtc_infos->pdata,
|
|
|
|
crtc_infos->len,
|
|
|
|
(MetaOutputInfo **) output_infos->pdata,
|
|
|
|
output_infos->len))
|
|
|
|
{
|
|
|
|
apply_crtc_assignments (manager,
|
|
|
|
TRUE,
|
|
|
|
(MetaCrtcInfo **) crtc_infos->pdata,
|
|
|
|
crtc_infos->len,
|
|
|
|
(MetaOutputInfo **) output_infos->pdata,
|
|
|
|
output_infos->len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MetaMonitorManagerDeriveFlag flags;
|
|
|
|
|
|
|
|
flags = (META_MONITOR_MANAGER_DERIVE_FLAG_NONE |
|
|
|
|
META_MONITOR_MANAGER_DERIVE_FLAG_CONFIGURED_SCALE);
|
|
|
|
meta_monitor_manager_rebuild_derived (manager, flags);
|
|
|
|
}
|
2017-02-14 06:54:04 -05:00
|
|
|
}
|
2017-01-09 01:31:18 -05:00
|
|
|
|
|
|
|
g_ptr_array_free (crtc_infos, TRUE);
|
|
|
|
g_ptr_array_free (output_infos, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcInfo **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputInfo **outputs,
|
|
|
|
unsigned int n_outputs)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
apply_crtc_assignments (manager, FALSE, crtcs, n_crtcs, outputs, n_outputs);
|
2017-01-09 01:31:18 -05:00
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_change_backlight (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output,
|
|
|
|
gint value)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
2014-04-23 09:57:16 -04:00
|
|
|
Atom atom;
|
2013-07-29 07:00:15 -04:00
|
|
|
int hw_value;
|
|
|
|
|
|
|
|
hw_value = round ((double)value / 100.0 * output->backlight_max + output->backlight_min);
|
|
|
|
|
2014-04-23 09:57:16 -04:00
|
|
|
atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
|
2015-06-28 16:25:49 -04:00
|
|
|
|
|
|
|
xcb_randr_change_output_property (XGetXCBConnection (manager_xrandr->xdisplay),
|
|
|
|
(XID)output->winsys_id,
|
|
|
|
atom, XCB_ATOM_INTEGER, 32,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
1, &hw_value);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
/* We're not selecting for property notifies, so update the value immediately */
|
|
|
|
output->backlight = normalize_backlight (output, hw_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_get_crtc_gamma (MetaMonitorManager *manager,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2013-07-29 07:00:15 -04:00
|
|
|
gsize *size,
|
|
|
|
unsigned short **red,
|
|
|
|
unsigned short **green,
|
|
|
|
unsigned short **blue)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
XRRCrtcGamma *gamma;
|
|
|
|
|
|
|
|
gamma = XRRGetCrtcGamma (manager_xrandr->xdisplay, (XID)crtc->crtc_id);
|
|
|
|
|
|
|
|
*size = gamma->size;
|
|
|
|
*red = g_memdup (gamma->red, sizeof (unsigned short) * gamma->size);
|
|
|
|
*green = g_memdup (gamma->green, sizeof (unsigned short) * gamma->size);
|
|
|
|
*blue = g_memdup (gamma->blue, sizeof (unsigned short) * gamma->size);
|
|
|
|
|
|
|
|
XRRFreeGamma (gamma);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_set_crtc_gamma (MetaMonitorManager *manager,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2013-07-29 07:00:15 -04:00
|
|
|
gsize size,
|
|
|
|
unsigned short *red,
|
|
|
|
unsigned short *green,
|
|
|
|
unsigned short *blue)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
2013-08-18 05:44:45 -04:00
|
|
|
XRRCrtcGamma *gamma;
|
|
|
|
|
|
|
|
gamma = XRRAllocGamma (size);
|
|
|
|
memcpy (gamma->red, red, sizeof (unsigned short) * size);
|
|
|
|
memcpy (gamma->green, green, sizeof (unsigned short) * size);
|
|
|
|
memcpy (gamma->blue, blue, sizeof (unsigned short) * size);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2013-08-18 05:44:45 -04:00
|
|
|
XRRSetCrtcGamma (manager_xrandr->xdisplay, (XID)crtc->crtc_id, gamma);
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2013-08-18 05:44:45 -04:00
|
|
|
XRRFreeGamma (gamma);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2015-03-30 21:11:12 -04:00
|
|
|
#ifdef HAVE_XRANDR15
|
2016-12-13 05:58:22 -05:00
|
|
|
static MetaMonitorXrandrData *
|
|
|
|
meta_monitor_xrandr_data_from_monitor (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorXrandrData *monitor_xrandr_data;
|
|
|
|
|
|
|
|
monitor_xrandr_data = g_object_get_qdata (G_OBJECT (monitor),
|
|
|
|
quark_meta_monitor_xrandr_data);
|
|
|
|
if (monitor_xrandr_data)
|
|
|
|
return monitor_xrandr_data;
|
|
|
|
|
|
|
|
monitor_xrandr_data = g_new0 (MetaMonitorXrandrData, 1);
|
|
|
|
g_object_set_qdata_full (G_OBJECT (monitor),
|
|
|
|
quark_meta_monitor_xrandr_data,
|
|
|
|
monitor_xrandr_data,
|
|
|
|
g_free);
|
|
|
|
|
|
|
|
return monitor_xrandr_data;
|
|
|
|
}
|
|
|
|
|
2015-03-30 21:11:12 -04:00
|
|
|
static void
|
2016-12-13 05:58:22 -05:00
|
|
|
meta_monitor_manager_xrandr_increase_monitor_count (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
Atom name_atom)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count =
|
|
|
|
GPOINTER_TO_INT (g_hash_table_lookup (manager_xrandr->tiled_monitor_atoms,
|
|
|
|
GSIZE_TO_POINTER (name_atom)));
|
|
|
|
|
|
|
|
count++;
|
|
|
|
g_hash_table_insert (manager_xrandr->tiled_monitor_atoms,
|
|
|
|
GSIZE_TO_POINTER (name_atom),
|
|
|
|
GINT_TO_POINTER (count));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
meta_monitor_manager_xrandr_decrease_monitor_count (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
Atom name_atom)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count =
|
|
|
|
GPOINTER_TO_SIZE (g_hash_table_lookup (manager_xrandr->tiled_monitor_atoms,
|
|
|
|
GSIZE_TO_POINTER (name_atom)));
|
|
|
|
g_assert (count > 0);
|
|
|
|
|
|
|
|
count--;
|
|
|
|
g_hash_table_insert (manager_xrandr->tiled_monitor_atoms,
|
|
|
|
GSIZE_TO_POINTER (name_atom),
|
|
|
|
GINT_TO_POINTER (count));
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_tiled_monitor_added (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor)
|
2015-03-30 21:11:12 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
2016-12-13 05:58:22 -05:00
|
|
|
MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (monitor);
|
|
|
|
const char *product;
|
|
|
|
char *name;
|
|
|
|
uint32_t tile_group_id;
|
|
|
|
MetaMonitorXrandrData *monitor_xrandr_data;
|
|
|
|
Atom name_atom;
|
|
|
|
XRRMonitorInfo *xrandr_monitor_info;
|
|
|
|
GList *outputs;
|
|
|
|
GList *l;
|
|
|
|
int i;
|
2015-03-30 21:11:12 -04:00
|
|
|
|
|
|
|
if (manager_xrandr->has_randr15 == FALSE)
|
|
|
|
return;
|
|
|
|
|
2016-12-13 05:58:22 -05:00
|
|
|
product = meta_monitor_get_product (monitor);
|
|
|
|
tile_group_id = meta_monitor_tiled_get_tile_group_id (monitor_tiled);
|
2015-03-30 21:11:12 -04:00
|
|
|
|
2016-12-13 05:58:22 -05:00
|
|
|
if (product)
|
|
|
|
name = g_strdup_printf ("%s-%d", product, tile_group_id);
|
2015-03-30 21:11:12 -04:00
|
|
|
else
|
2016-12-13 05:58:22 -05:00
|
|
|
name = g_strdup_printf ("Tiled-%d", tile_group_id);
|
|
|
|
|
|
|
|
name_atom = XInternAtom (manager_xrandr->xdisplay, name, False);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
monitor_xrandr_data = meta_monitor_xrandr_data_from_monitor (monitor);
|
|
|
|
monitor_xrandr_data->xrandr_name = name_atom;
|
|
|
|
|
|
|
|
meta_monitor_manager_xrandr_increase_monitor_count (manager_xrandr,
|
|
|
|
name_atom);
|
|
|
|
|
|
|
|
outputs = meta_monitor_get_outputs (monitor);
|
|
|
|
xrandr_monitor_info = XRRAllocateMonitor (manager_xrandr->xdisplay,
|
|
|
|
g_list_length (outputs));
|
|
|
|
xrandr_monitor_info->name = name_atom;
|
|
|
|
xrandr_monitor_info->primary = meta_monitor_is_primary (monitor);
|
|
|
|
xrandr_monitor_info->automatic = True;
|
|
|
|
for (l = outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
|
|
|
xrandr_monitor_info->outputs[i] = output->winsys_id;
|
|
|
|
}
|
2015-03-30 21:11:12 -04:00
|
|
|
|
|
|
|
XRRSetMonitor (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay),
|
2016-12-13 05:58:22 -05:00
|
|
|
xrandr_monitor_info);
|
|
|
|
XRRFreeMonitors (xrandr_monitor_info);
|
2015-03-30 21:11:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-13 05:58:22 -05:00
|
|
|
meta_monitor_manager_xrandr_tiled_monitor_removed (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor)
|
2015-03-30 21:11:12 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
2016-12-13 05:58:22 -05:00
|
|
|
MetaMonitorXrandrData *monitor_xrandr_data;
|
|
|
|
Atom monitor_name;
|
|
|
|
|
|
|
|
int monitor_count;
|
2015-03-30 21:11:12 -04:00
|
|
|
|
|
|
|
if (manager_xrandr->has_randr15 == FALSE)
|
|
|
|
return;
|
2016-12-13 05:58:22 -05:00
|
|
|
|
|
|
|
monitor_xrandr_data = meta_monitor_xrandr_data_from_monitor (monitor);
|
|
|
|
monitor_name = monitor_xrandr_data->xrandr_name;
|
|
|
|
monitor_count =
|
|
|
|
meta_monitor_manager_xrandr_decrease_monitor_count (manager_xrandr,
|
|
|
|
monitor_name);
|
|
|
|
|
|
|
|
if (monitor_count == 0)
|
|
|
|
XRRDeleteMonitor (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay),
|
|
|
|
monitor_name);
|
2015-03-30 21:11:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_monitor_manager_xrandr_init_monitors (MetaMonitorManagerXrandr *manager_xrandr)
|
2015-03-30 21:11:12 -04:00
|
|
|
{
|
|
|
|
XRRMonitorInfo *m;
|
|
|
|
int n, i;
|
|
|
|
|
|
|
|
if (manager_xrandr->has_randr15 == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* delete any tiled monitors setup, as mutter will want to recreate
|
|
|
|
things in its image */
|
|
|
|
m = XRRGetMonitors (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay),
|
|
|
|
FALSE, &n);
|
|
|
|
if (n == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
if (m[i].noutput > 1)
|
|
|
|
XRRDeleteMonitor (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay),
|
|
|
|
m[i].name);
|
|
|
|
}
|
|
|
|
XRRFreeMonitors (m);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-08 03:05:00 -05:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_xrandr_is_transform_handled (MetaMonitorManager *manager,
|
|
|
|
MetaCrtc *crtc,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
g_warn_if_fail (crtc->all_transforms & transform);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-05-25 04:12:51 -04:00
|
|
|
static float
|
2017-01-20 02:07:12 -05:00
|
|
|
meta_monitor_manager_xrandr_calculate_monitor_mode_scale (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
return meta_monitor_calculate_mode_scale (monitor, monitor_mode);
|
2017-01-20 02:07:12 -05:00
|
|
|
}
|
|
|
|
|
2017-06-05 03:59:47 -04:00
|
|
|
static float *
|
|
|
|
meta_monitor_manager_xrandr_calculate_supported_scales (MetaMonitorManager *manager,
|
|
|
|
MetaLogicalMonitorLayoutMode layout_mode,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
int *n_supported_scales)
|
2017-01-26 04:14:32 -05:00
|
|
|
{
|
2017-06-05 03:59:47 -04:00
|
|
|
MetaMonitorScalesConstraint constraints;
|
|
|
|
|
|
|
|
constraints = META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
|
|
|
|
return meta_monitor_calculate_supported_scales (monitor, monitor_mode,
|
|
|
|
constraints,
|
|
|
|
n_supported_scales);
|
2017-01-26 04:14:32 -05:00
|
|
|
}
|
|
|
|
|
2017-02-07 03:01:40 -05:00
|
|
|
static MetaMonitorManagerCapability
|
|
|
|
meta_monitor_manager_xrandr_get_capabilities (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
return (META_MONITOR_MANAGER_CAPABILITY_MIRRORING |
|
|
|
|
META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED);
|
2017-02-07 03:01:40 -05:00
|
|
|
}
|
|
|
|
|
2017-02-15 03:06:46 -05:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_xrandr_get_max_screen_size (MetaMonitorManager *manager,
|
|
|
|
int *max_width,
|
|
|
|
int *max_height)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
|
|
|
|
*max_width = manager_xrandr->max_screen_width;
|
|
|
|
*max_height = manager_xrandr->max_screen_height;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
static MetaLogicalMonitorLayoutMode
|
|
|
|
meta_monitor_manager_xrandr_get_default_layout_mode (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
|
2017-02-24 05:10:52 -05:00
|
|
|
}
|
|
|
|
|
2014-04-23 12:07:38 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2014-04-23 12:07:38 -04:00
|
|
|
MetaBackendX11 *backend = META_BACKEND_X11 (meta_get_backend ());
|
|
|
|
|
|
|
|
manager_xrandr->xdisplay = meta_backend_x11_get_xdisplay (backend);
|
|
|
|
|
|
|
|
if (!XRRQueryExtension (manager_xrandr->xdisplay,
|
|
|
|
&manager_xrandr->rr_event_base,
|
|
|
|
&manager_xrandr->rr_error_base))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-30 20:38:44 -04:00
|
|
|
int major_version, minor_version;
|
2014-04-23 12:07:38 -04:00
|
|
|
/* We only use ScreenChangeNotify, but GDK uses the others,
|
|
|
|
and we don't want to step on its toes */
|
|
|
|
XRRSelectInput (manager_xrandr->xdisplay,
|
|
|
|
DefaultRootWindow (manager_xrandr->xdisplay),
|
|
|
|
RRScreenChangeNotifyMask
|
|
|
|
| RRCrtcChangeNotifyMask
|
|
|
|
| RROutputPropertyNotifyMask);
|
2015-03-30 20:38:44 -04:00
|
|
|
|
|
|
|
manager_xrandr->has_randr15 = FALSE;
|
|
|
|
XRRQueryVersion (manager_xrandr->xdisplay, &major_version,
|
|
|
|
&minor_version);
|
|
|
|
#ifdef HAVE_XRANDR15
|
|
|
|
if (major_version > 1 ||
|
|
|
|
(major_version == 1 &&
|
|
|
|
minor_version >= 5))
|
2016-12-13 05:58:22 -05:00
|
|
|
{
|
|
|
|
manager_xrandr->has_randr15 = TRUE;
|
|
|
|
manager_xrandr->tiled_monitor_atoms = g_hash_table_new (NULL, NULL);
|
|
|
|
}
|
2015-03-30 21:11:12 -04:00
|
|
|
meta_monitor_manager_xrandr_init_monitors (manager_xrandr);
|
2015-03-30 20:38:44 -04:00
|
|
|
#endif
|
2014-04-23 12:07:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (object);
|
|
|
|
|
|
|
|
if (manager_xrandr->resources)
|
|
|
|
XRRFreeScreenResources (manager_xrandr->resources);
|
|
|
|
manager_xrandr->resources = NULL;
|
|
|
|
|
2016-12-13 05:58:22 -05:00
|
|
|
g_hash_table_destroy (manager_xrandr->tiled_monitor_atoms);
|
|
|
|
|
2014-04-23 12:07:38 -04:00
|
|
|
G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_monitor_manager_xrandr_finalize;
|
|
|
|
|
|
|
|
manager_class->read_current = meta_monitor_manager_xrandr_read_current;
|
|
|
|
manager_class->read_edid = meta_monitor_manager_xrandr_read_edid;
|
2017-01-06 00:27:21 -05:00
|
|
|
manager_class->ensure_initial_config = meta_monitor_manager_xrandr_ensure_initial_config;
|
2017-01-09 01:31:18 -05:00
|
|
|
manager_class->apply_monitors_config = meta_monitor_manager_xrandr_apply_monitors_config;
|
2014-04-23 12:07:38 -04:00
|
|
|
manager_class->apply_configuration = meta_monitor_manager_xrandr_apply_configuration;
|
|
|
|
manager_class->set_power_save_mode = meta_monitor_manager_xrandr_set_power_save_mode;
|
|
|
|
manager_class->change_backlight = meta_monitor_manager_xrandr_change_backlight;
|
|
|
|
manager_class->get_crtc_gamma = meta_monitor_manager_xrandr_get_crtc_gamma;
|
|
|
|
manager_class->set_crtc_gamma = meta_monitor_manager_xrandr_set_crtc_gamma;
|
2015-03-30 21:11:12 -04:00
|
|
|
#ifdef HAVE_XRANDR15
|
2016-12-13 05:58:22 -05:00
|
|
|
manager_class->tiled_monitor_added = meta_monitor_manager_xrandr_tiled_monitor_added;
|
|
|
|
manager_class->tiled_monitor_removed = meta_monitor_manager_xrandr_tiled_monitor_removed;
|
2015-03-30 21:11:12 -04:00
|
|
|
#endif
|
2017-03-08 03:05:00 -05:00
|
|
|
manager_class->is_transform_handled = meta_monitor_manager_xrandr_is_transform_handled;
|
2017-01-20 02:07:12 -05:00
|
|
|
manager_class->calculate_monitor_mode_scale = meta_monitor_manager_xrandr_calculate_monitor_mode_scale;
|
2017-06-05 03:59:47 -04:00
|
|
|
manager_class->calculate_supported_scales = meta_monitor_manager_xrandr_calculate_supported_scales;
|
2017-02-07 03:01:40 -05:00
|
|
|
manager_class->get_capabilities = meta_monitor_manager_xrandr_get_capabilities;
|
2017-02-15 03:06:46 -05:00
|
|
|
manager_class->get_max_screen_size = meta_monitor_manager_xrandr_get_max_screen_size;
|
2017-02-24 05:10:52 -05:00
|
|
|
manager_class->get_default_layout_mode = meta_monitor_manager_xrandr_get_default_layout_mode;
|
2016-12-13 05:58:22 -05:00
|
|
|
|
|
|
|
quark_meta_monitor_xrandr_data =
|
|
|
|
g_quark_from_static_string ("-meta-monitor-xrandr-data");
|
2014-04-23 12:07:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
|
|
|
|
XEvent *event)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
|
2017-04-21 06:01:15 -04:00
|
|
|
gboolean is_hotplug;
|
|
|
|
gboolean is_our_configuration;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
XRRUpdateConfiguration (event);
|
2013-09-02 09:04:05 -04:00
|
|
|
|
2016-12-19 02:46:31 -05:00
|
|
|
meta_monitor_manager_read_current_state (manager);
|
2013-09-02 09:04:05 -04:00
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
|
|
|
|
is_hotplug = (manager_xrandr->resources->timestamp <
|
|
|
|
manager_xrandr->resources->configTimestamp);
|
|
|
|
is_our_configuration = (manager_xrandr->resources->timestamp ==
|
|
|
|
manager_xrandr->last_xrandr_set_timestamp);
|
|
|
|
if (is_hotplug)
|
2014-10-16 14:31:03 -04:00
|
|
|
{
|
|
|
|
meta_monitor_manager_on_hotplug (manager);
|
|
|
|
}
|
|
|
|
else
|
2013-10-31 09:37:44 -04:00
|
|
|
{
|
2017-04-21 06:01:15 -04:00
|
|
|
MetaMonitorManagerDeriveFlag flags =
|
|
|
|
META_MONITOR_MANAGER_DERIVE_FLAG_NONE;
|
|
|
|
|
|
|
|
if (is_our_configuration)
|
|
|
|
flags |= META_MONITOR_MANAGER_DERIVE_FLAG_CONFIGURED_SCALE;
|
|
|
|
|
|
|
|
meta_monitor_manager_rebuild_derived (manager, flags);
|
2013-09-02 09:04:05 -04:00
|
|
|
}
|
2014-10-03 17:10:53 -04:00
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|