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
|
|
|
*/
|
|
|
|
|
2018-10-19 03:15:54 -04:00
|
|
|
/**
|
|
|
|
* SECTION:meta-monitor-manager-xrandr
|
|
|
|
* @title: MetaMonitorManagerXrandr
|
|
|
|
* @short_description: A subclass of #MetaMonitorManager using XRadR
|
|
|
|
*
|
|
|
|
* #MetaMonitorManagerXrandr is a subclass of #MetaMonitorManager which
|
|
|
|
* implements its functionality using the RandR X protocol.
|
|
|
|
*
|
|
|
|
* See also #MetaMonitorManagerKms for a native implementation using Linux DRM
|
|
|
|
* and udev.
|
|
|
|
*/
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/x11/meta-monitor-manager-xrandr.h"
|
2014-03-30 20:25:31 -04:00
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
#include <math.h>
|
2018-07-10 04:36:24 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xlib-xcb.h>
|
2017-04-18 05:06:18 -04:00
|
|
|
#include <X11/Xlibint.h>
|
2013-07-29 07:00:15 -04:00
|
|
|
#include <X11/extensions/dpms.h>
|
2014-08-19 11:02:33 -04:00
|
|
|
#include <xcb/randr.h>
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2017-03-28 00:35:19 -04:00
|
|
|
#include "backends/meta-crtc.h"
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-monitor-config-manager.h"
|
2017-03-24 05:35:51 -04:00
|
|
|
#include "backends/meta-output.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/x11/meta-backend-x11.h"
|
2017-07-04 13:11:19 -04:00
|
|
|
#include "backends/x11/meta-crtc-xrandr.h"
|
2017-07-10 06:19:32 -04:00
|
|
|
#include "backends/x11/meta-gpu-xrandr.h"
|
2017-07-04 06:42:16 -04:00
|
|
|
#include "backends/x11/meta-output-xrandr.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "meta/main.h"
|
|
|
|
#include "meta/meta-x11-errors.h"
|
2013-08-16 11:06:46 -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;
|
|
|
|
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
|
|
|
GHashTable *tiled_monitor_atoms;
|
2017-10-13 02:34:19 -04:00
|
|
|
|
|
|
|
float *supported_scales;
|
|
|
|
int n_supported_scales;
|
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
|
|
|
typedef struct _MetaMonitorXrandrData
|
|
|
|
{
|
|
|
|
Atom xrandr_name;
|
|
|
|
} MetaMonitorXrandrData;
|
|
|
|
|
|
|
|
GQuark quark_meta_monitor_xrandr_data;
|
|
|
|
|
2017-07-04 06:42:16 -04:00
|
|
|
Display *
|
|
|
|
meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr)
|
|
|
|
{
|
|
|
|
return manager_xrandr->xdisplay;
|
|
|
|
}
|
|
|
|
|
2017-07-04 13:11:19 -04:00
|
|
|
gboolean
|
|
|
|
meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2017-07-04 13:11:19 -04:00
|
|
|
return manager_xrandr->has_randr15;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2013-08-08 07:32:05 -04:00
|
|
|
static GBytes *
|
|
|
|
meta_monitor_manager_xrandr_read_edid (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
2017-07-04 06:42:16 -04:00
|
|
|
return meta_output_xrandr_read_edid (output);
|
2013-08-08 07:32:05 -04:00
|
|
|
}
|
|
|
|
|
2019-01-11 08:45:44 -05:00
|
|
|
static MetaPowerSave
|
|
|
|
x11_dpms_state_to_power_save (CARD16 dpms_state)
|
|
|
|
{
|
|
|
|
switch (dpms_state)
|
|
|
|
{
|
|
|
|
case DPMSModeOn:
|
|
|
|
return META_POWER_SAVE_ON;
|
|
|
|
case DPMSModeStandby:
|
|
|
|
return META_POWER_SAVE_STANDBY;
|
|
|
|
case DPMSModeSuspend:
|
|
|
|
return META_POWER_SAVE_SUSPEND;
|
|
|
|
case DPMSModeOff:
|
|
|
|
return META_POWER_SAVE_OFF;
|
|
|
|
default:
|
|
|
|
return META_POWER_SAVE_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
MetaMonitorManagerClass *parent_class =
|
|
|
|
META_MONITOR_MANAGER_CLASS (meta_monitor_manager_xrandr_parent_class);
|
|
|
|
Display *xdisplay = meta_monitor_manager_xrandr_get_xdisplay (manager_xrandr);
|
|
|
|
BOOL dpms_capable, dpms_enabled;
|
|
|
|
CARD16 dpms_state;
|
|
|
|
MetaPowerSave power_save_mode;
|
|
|
|
|
|
|
|
dpms_capable = DPMSCapable (xdisplay);
|
|
|
|
|
|
|
|
if (dpms_capable &&
|
|
|
|
DPMSInfo (xdisplay, &dpms_state, &dpms_enabled) &&
|
|
|
|
dpms_enabled)
|
|
|
|
power_save_mode = x11_dpms_state_to_power_save (dpms_state);
|
|
|
|
else
|
|
|
|
power_save_mode = META_POWER_SAVE_UNSUPPORTED;
|
|
|
|
|
|
|
|
meta_monitor_manager_power_save_mode_changed (manager, power_save_mode);
|
|
|
|
|
|
|
|
parent_class->read_current_state (manager);
|
|
|
|
}
|
|
|
|
|
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 ();
|
2019-01-24 18:47:44 -05:00
|
|
|
return 0;
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
static gboolean
|
|
|
|
xrandr_set_crtc_config (MetaMonitorManagerXrandr *manager_xrandr,
|
2017-07-04 13:11:19 -04:00
|
|
|
MetaCrtc *crtc,
|
2017-04-21 06:01:15 -04:00
|
|
|
gboolean save_timestamp,
|
2017-07-04 13:11:19 -04:00
|
|
|
xcb_randr_crtc_t xrandr_crtc,
|
2017-04-18 05:06:18 -04:00
|
|
|
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)
|
|
|
|
{
|
2017-07-04 13:11:19 -04:00
|
|
|
xcb_timestamp_t new_timestamp;
|
2017-04-18 05:06:18 -04:00
|
|
|
|
2020-02-26 13:47:44 -05:00
|
|
|
if (!meta_crtc_xrandr_set_config (META_CRTC_XRANDR (crtc),
|
|
|
|
xrandr_crtc, timestamp,
|
2017-07-04 13:11:19 -04:00
|
|
|
x, y, mode, rotation,
|
|
|
|
outputs, n_outputs,
|
|
|
|
&new_timestamp))
|
|
|
|
return FALSE;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2017-07-04 13:11:19 -04:00
|
|
|
if (save_timestamp)
|
|
|
|
manager_xrandr->last_xrandr_set_timestamp = new_timestamp;
|
2017-04-18 05:06:18 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
static gboolean
|
2020-02-25 14:30:46 -05:00
|
|
|
is_crtc_assignment_changed (MetaCrtc *crtc,
|
|
|
|
MetaCrtcAssignment **crtc_assignments,
|
|
|
|
unsigned int n_crtc_assignments)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
for (i = 0; i < n_crtc_assignments; i++)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaCrtcAssignment *crtc_assignment = crtc_assignments[i];
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (crtc_assignment->crtc != crtc)
|
2017-04-21 06:01:15 -04:00
|
|
|
continue;
|
|
|
|
|
2020-02-26 13:47:44 -05:00
|
|
|
return meta_crtc_xrandr_is_assignment_changed (META_CRTC_XRANDR (crtc),
|
|
|
|
crtc_assignment);
|
2017-04-21 06:01:15 -04:00
|
|
|
}
|
|
|
|
|
2020-02-26 13:47:44 -05:00
|
|
|
return !!meta_crtc_xrandr_get_current_mode (META_CRTC_XRANDR (crtc));
|
2017-04-21 06:01:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-02-25 14:30:46 -05:00
|
|
|
is_output_assignment_changed (MetaOutput *output,
|
|
|
|
MetaCrtcAssignment **crtc_assignments,
|
|
|
|
unsigned int n_crtc_assignments,
|
|
|
|
MetaOutputAssignment **output_assignments,
|
|
|
|
unsigned int n_output_assignments)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2017-11-03 06:25:30 -04:00
|
|
|
MetaCrtc *assigned_crtc;
|
2017-04-21 06:01:15 -04:00
|
|
|
gboolean output_is_found = FALSE;
|
|
|
|
unsigned int i;
|
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
for (i = 0; i < n_output_assignments; i++)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaOutputAssignment *output_assignment = output_assignments[i];
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (output_assignment->output != output)
|
2017-04-21 06:01:15 -04:00
|
|
|
continue;
|
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (meta_output_is_primary (output) != output_assignment->is_primary)
|
2017-04-21 06:01:15 -04:00
|
|
|
return TRUE;
|
|
|
|
|
2020-02-25 12:37:21 -05:00
|
|
|
if (meta_output_is_presentation (output) !=
|
2020-02-25 14:30:46 -05:00
|
|
|
output_assignment->is_presentation)
|
2017-04-21 06:01:15 -04:00
|
|
|
return TRUE;
|
|
|
|
|
2020-02-25 12:37:21 -05:00
|
|
|
if (meta_output_is_underscanning (output) !=
|
2020-02-25 14:30:46 -05:00
|
|
|
output_assignment->is_underscanning)
|
2017-04-21 06:01:15 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
output_is_found = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-11-03 06:25:30 -04:00
|
|
|
assigned_crtc = meta_output_get_assigned_crtc (output);
|
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
if (!output_is_found)
|
2017-11-03 06:25:30 -04:00
|
|
|
return assigned_crtc != NULL;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
for (i = 0; i < n_crtc_assignments; i++)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaCrtcAssignment *crtc_assignment = crtc_assignments[i];
|
2017-04-21 06:01:15 -04:00
|
|
|
unsigned int j;
|
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
for (j = 0; j < crtc_assignment->outputs->len; j++)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaOutput *crtc_assignment_output =
|
|
|
|
((MetaOutput**) crtc_assignment->outputs->pdata)[j];
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (crtc_assignment_output == output &&
|
|
|
|
crtc_assignment->crtc == assigned_crtc)
|
2017-04-21 06:01:15 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
static MetaGpu *
|
|
|
|
meta_monitor_manager_xrandr_get_gpu (MetaMonitorManagerXrandr *manager_xrandr)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
|
|
|
|
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
|
|
|
|
|
|
|
|
return META_GPU (meta_backend_get_gpus (backend)->data);
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:01:15 -04:00
|
|
|
static gboolean
|
2020-02-25 14:30:46 -05:00
|
|
|
is_assignments_changed (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcAssignment **crtc_assignments,
|
|
|
|
unsigned int n_crtc_assignments,
|
|
|
|
MetaOutputAssignment **output_assignments,
|
|
|
|
unsigned int n_output_assignments)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (manager);
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2017-03-28 00:35:19 -04:00
|
|
|
MetaCrtc *crtc = l->data;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (is_crtc_assignment_changed (crtc, crtc_assignments, n_crtc_assignments))
|
2017-04-21 06:01:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
MetaOutput *output = l->data;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
|
|
|
if (is_output_assignment_changed (output,
|
2020-02-25 14:30:46 -05:00
|
|
|
crtc_assignments,
|
|
|
|
n_crtc_assignments,
|
|
|
|
output_assignments,
|
|
|
|
n_output_assignments))
|
2017-04-21 06:01:15 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static void
|
2020-02-25 14:30:46 -05:00
|
|
|
apply_crtc_assignments (MetaMonitorManager *manager,
|
|
|
|
gboolean save_timestamp,
|
|
|
|
MetaCrtcAssignment **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputAssignment **outputs,
|
|
|
|
unsigned int n_outputs)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
|
2020-02-25 10:54:20 -05:00
|
|
|
g_autoptr (GList) to_configure_outputs = NULL;
|
|
|
|
g_autoptr (GList) to_disable_crtcs = NULL;
|
2013-07-29 07:00:15 -04:00
|
|
|
unsigned i;
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2013-08-16 11:39:07 -04:00
|
|
|
int width, height, width_mm, height_mm;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2020-02-25 10:54:20 -05:00
|
|
|
to_configure_outputs = g_list_copy (meta_gpu_get_outputs (gpu));
|
|
|
|
to_disable_crtcs = g_list_copy (meta_gpu_get_crtcs (gpu));
|
|
|
|
|
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++)
|
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaCrtcAssignment *crtc_assignment = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_assignment->crtc;
|
2013-08-16 11:39:07 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (crtc_assignment->mode == NULL)
|
2013-08-16 11:39:07 -04:00
|
|
|
continue;
|
|
|
|
|
2020-02-25 10:54:20 -05:00
|
|
|
to_disable_crtcs = g_list_remove (to_disable_crtcs, crtc);
|
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
width = MAX (width, (int) roundf (crtc_assignment->layout.origin.x +
|
|
|
|
crtc_assignment->layout.size.width));
|
|
|
|
height = MAX (height, (int) roundf (crtc_assignment->layout.origin.y +
|
|
|
|
crtc_assignment->layout.size.height));
|
2013-08-16 11:39:07 -04:00
|
|
|
}
|
|
|
|
|
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++)
|
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaCrtcAssignment *crtc_assignment = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_assignment->crtc;
|
2020-02-26 04:37:53 -05:00
|
|
|
const MetaCrtcConfig *crtc_config;
|
2020-01-14 16:34:44 -05:00
|
|
|
int x2, y2;
|
|
|
|
|
2020-02-26 04:37:53 -05:00
|
|
|
crtc_config = meta_crtc_get_config (crtc);
|
2020-02-26 10:10:12 -05:00
|
|
|
if (!crtc_config)
|
|
|
|
continue;
|
|
|
|
|
2020-01-14 16:34:44 -05:00
|
|
|
x2 = (int) roundf (crtc_config->layout.origin.x +
|
|
|
|
crtc_config->layout.size.width);
|
|
|
|
y2 = (int) roundf (crtc_config->layout.origin.y +
|
|
|
|
crtc_config->layout.size.height);
|
2013-08-16 13:02:57 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (!crtc_assignment->mode || x2 > width || y2 > height)
|
2013-08-16 13:02:57 -04:00
|
|
|
{
|
2017-04-18 05:06:18 -04:00
|
|
|
xrandr_set_crtc_config (manager_xrandr,
|
2017-07-04 13:11:19 -04:00
|
|
|
crtc,
|
2017-04-21 06:01:15 -04:00
|
|
|
save_timestamp,
|
2020-02-25 05:34:43 -05:00
|
|
|
(xcb_randr_crtc_t) meta_crtc_get_id (crtc),
|
2017-04-18 05:06:18 -04:00
|
|
|
XCB_CURRENT_TIME,
|
|
|
|
0, 0, XCB_NONE,
|
|
|
|
XCB_RANDR_ROTATION_ROTATE_0,
|
|
|
|
NULL, 0);
|
2013-08-17 13:15:40 -04:00
|
|
|
|
2020-01-14 16:34:44 -05:00
|
|
|
meta_crtc_unset_config (crtc);
|
2013-08-16 13:02:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 10:54:20 -05:00
|
|
|
for (l = to_disable_crtcs; l; l = l->next)
|
2013-08-16 13:02:57 -04:00
|
|
|
{
|
2017-03-28 00:35:19 -04:00
|
|
|
MetaCrtc *crtc = l->data;
|
2013-08-16 13:02:57 -04:00
|
|
|
|
2020-02-26 04:37:53 -05:00
|
|
|
if (!meta_crtc_get_config (crtc))
|
2013-08-16 13:02:57 -04:00
|
|
|
continue;
|
|
|
|
|
2017-04-18 05:06:18 -04:00
|
|
|
xrandr_set_crtc_config (manager_xrandr,
|
2017-07-04 13:11:19 -04:00
|
|
|
crtc,
|
2017-04-21 06:01:15 -04:00
|
|
|
save_timestamp,
|
2020-02-25 05:34:43 -05:00
|
|
|
(xcb_randr_crtc_t) meta_crtc_get_id (crtc),
|
2017-04-18 05:06:18 -04:00
|
|
|
XCB_CURRENT_TIME,
|
|
|
|
0, 0, XCB_NONE,
|
|
|
|
XCB_RANDR_ROTATION_ROTATE_0,
|
|
|
|
NULL, 0);
|
2013-08-17 13:15:40 -04:00
|
|
|
|
2020-01-14 16:34:44 -05:00
|
|
|
meta_crtc_unset_config (crtc);
|
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++)
|
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaCrtcAssignment *crtc_assignment = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_assignment->crtc;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
if (crtc_assignment->mode != NULL)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2020-02-26 18:08:58 -05:00
|
|
|
MetaCrtcMode *crtc_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;
|
2020-02-25 14:30:46 -05:00
|
|
|
xcb_randr_crtc_t crtc_id;
|
|
|
|
int x, y;
|
2017-04-18 05:06:18 -04:00
|
|
|
xcb_randr_rotation_t rotation;
|
2020-02-26 18:08:58 -05:00
|
|
|
xcb_randr_mode_t mode;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2020-02-26 18:08:58 -05:00
|
|
|
crtc_mode = crtc_assignment->mode;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
n_output_ids = crtc_assignment->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;
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaOutputAssignment *output_assignment;
|
2013-08-23 11:25:44 -04:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
output = ((MetaOutput**)crtc_assignment->outputs->pdata)[j];
|
2013-08-23 11:25:44 -04:00
|
|
|
|
2020-02-25 10:54:20 -05:00
|
|
|
to_configure_outputs = g_list_remove (to_configure_outputs,
|
|
|
|
output);
|
2020-02-25 12:37:21 -05:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
output_assignment = meta_find_output_assignment (outputs,
|
|
|
|
n_outputs,
|
|
|
|
output);
|
|
|
|
meta_output_assign_crtc (output, crtc, output_assignment);
|
2013-08-23 11:25:44 -04:00
|
|
|
|
2020-02-25 10:13:52 -05:00
|
|
|
output_ids[j] = meta_output_get_id (output);
|
2013-08-23 11:25:44 -04:00
|
|
|
}
|
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
crtc_id = (xcb_randr_crtc_t) meta_crtc_get_id (crtc);
|
|
|
|
x = (int) roundf (crtc_assignment->layout.origin.x);
|
|
|
|
y = (int) roundf (crtc_assignment->layout.origin.y);
|
|
|
|
rotation =
|
|
|
|
meta_monitor_transform_to_xrandr (crtc_assignment->transform);
|
2020-02-26 18:08:58 -05:00
|
|
|
mode = meta_crtc_mode_get_id (crtc_mode);
|
2017-04-18 05:06:18 -04:00
|
|
|
if (!xrandr_set_crtc_config (manager_xrandr,
|
2017-07-04 13:11:19 -04:00
|
|
|
crtc,
|
2017-04-21 06:01:15 -04:00
|
|
|
save_timestamp,
|
2020-02-25 14:30:46 -05:00
|
|
|
crtc_id,
|
2017-04-18 05:06:18 -04:00
|
|
|
XCB_CURRENT_TIME,
|
2020-02-25 14:30:46 -05:00
|
|
|
x, y,
|
2020-02-26 18:08:58 -05:00
|
|
|
mode,
|
2017-04-18 05:06:18 -04:00
|
|
|
rotation,
|
|
|
|
output_ids, n_output_ids))
|
2013-08-17 13:15:40 -04:00
|
|
|
{
|
2020-02-26 18:08:58 -05:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_info =
|
|
|
|
meta_crtc_mode_get_info (crtc_mode);
|
|
|
|
|
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",
|
2020-02-25 05:34:43 -05:00
|
|
|
(unsigned) meta_crtc_get_id (crtc),
|
2020-02-26 18:08:58 -05:00
|
|
|
(unsigned) mode,
|
|
|
|
crtc_mode_info->width, crtc_mode_info->height,
|
|
|
|
(float) crtc_mode_info->refresh_rate,
|
2020-02-25 14:30:46 -05:00
|
|
|
(int) roundf (crtc_assignment->layout.origin.x),
|
|
|
|
(int) roundf (crtc_assignment->layout.origin.y),
|
|
|
|
crtc_assignment->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
|
|
|
|
2020-01-14 16:34:44 -05:00
|
|
|
meta_crtc_set_config (crtc,
|
2020-02-25 14:30:46 -05:00
|
|
|
&crtc_assignment->layout,
|
2020-02-26 18:08:58 -05:00
|
|
|
crtc_mode,
|
2020-02-25 14:30:46 -05:00
|
|
|
crtc_assignment->transform);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_outputs; i++)
|
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
MetaOutputAssignment *output_assignment = outputs[i];
|
|
|
|
MetaOutput *output = output_assignment->output;
|
2013-07-29 07:00:15 -04:00
|
|
|
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_xrandr_apply_mode (META_OUTPUT_XRANDR (output));
|
2013-08-17 13:15:40 -04:00
|
|
|
}
|
|
|
|
|
2020-02-25 12:37:21 -05:00
|
|
|
g_list_foreach (to_configure_outputs,
|
|
|
|
(GFunc) meta_output_unassign_crtc,
|
|
|
|
NULL);
|
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-09-11 02:10:26 -04:00
|
|
|
MetaMonitorConfigManager *config_manager =
|
|
|
|
meta_monitor_manager_get_config_manager (manager);
|
|
|
|
MetaMonitorsConfig *config;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
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-09-11 02:10:26 -04:00
|
|
|
config = meta_monitor_config_manager_get_current (config_manager);
|
|
|
|
meta_monitor_manager_update_logical_state_derived (manager, config);
|
2017-01-06 00:27:21 -05:00
|
|
|
}
|
|
|
|
|
2017-10-13 02:34:19 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_rebuild_derived (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
|
|
|
|
g_clear_pointer (&manager_xrandr->supported_scales, g_free);
|
|
|
|
meta_monitor_manager_rebuild_derived (manager, config);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-02-25 14:30:46 -05:00
|
|
|
GPtrArray *crtc_assignments;
|
|
|
|
GPtrArray *output_assignments;
|
2017-01-09 01:31:18 -05:00
|
|
|
|
2017-01-20 01:50:11 -05:00
|
|
|
if (!config)
|
|
|
|
{
|
2017-10-13 02:34:19 -04:00
|
|
|
meta_monitor_manager_xrandr_rebuild_derived (manager, NULL);
|
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,
|
2020-02-25 14:30:46 -05:00
|
|
|
&crtc_assignments,
|
|
|
|
&output_assignments,
|
2017-01-09 01:31:18 -05:00
|
|
|
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,
|
2020-02-25 14:30:46 -05:00
|
|
|
(MetaCrtcAssignment **) crtc_assignments->pdata,
|
|
|
|
crtc_assignments->len,
|
|
|
|
(MetaOutputAssignment **) output_assignments->pdata,
|
|
|
|
output_assignments->len))
|
2017-04-21 06:01:15 -04:00
|
|
|
{
|
|
|
|
apply_crtc_assignments (manager,
|
|
|
|
TRUE,
|
2020-02-25 14:30:46 -05:00
|
|
|
(MetaCrtcAssignment **) crtc_assignments->pdata,
|
|
|
|
crtc_assignments->len,
|
|
|
|
(MetaOutputAssignment **) output_assignments->pdata,
|
|
|
|
output_assignments->len);
|
2017-04-21 06:01:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-13 02:34:19 -04:00
|
|
|
meta_monitor_manager_xrandr_rebuild_derived (manager, config);
|
2017-04-21 06:01:15 -04:00
|
|
|
}
|
2017-02-14 06:54:04 -05:00
|
|
|
}
|
2017-01-09 01:31:18 -05:00
|
|
|
|
2020-02-25 14:30:46 -05:00
|
|
|
g_ptr_array_free (crtc_assignments, TRUE);
|
|
|
|
g_ptr_array_free (output_assignments, TRUE);
|
2017-01-09 01:31:18 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-29 07:00:15 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_change_backlight (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output,
|
|
|
|
gint value)
|
|
|
|
{
|
2020-02-26 10:47:03 -05:00
|
|
|
meta_output_xrandr_change_backlight (META_OUTPUT_XRANDR (output), value);
|
2013-07-29 07:00:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-02-25 05:34:43 -05:00
|
|
|
gamma = XRRGetCrtcGamma (manager_xrandr->xdisplay,
|
|
|
|
(XID) meta_crtc_get_id (crtc));
|
2013-07-29 07:00:15 -04:00
|
|
|
|
|
|
|
*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
|
|
|
|
2020-02-25 05:34:43 -05:00
|
|
|
XRRSetCrtcGamma (manager_xrandr->xdisplay,
|
|
|
|
(XID) meta_crtc_get_id (crtc),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2020-02-25 10:13:52 -05:00
|
|
|
xrandr_monitor_info->outputs[i] = meta_output_get_id (output);
|
2016-12-13 05:58:22 -05:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:05:00 -05:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_xrandr_is_transform_handled (MetaMonitorManager *manager,
|
|
|
|
MetaCrtc *crtc,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
2020-02-26 04:14:52 -05:00
|
|
|
g_warn_if_fail ((meta_crtc_get_all_transforms (crtc) & transform) ==
|
|
|
|
transform);
|
2017-03-08 03:05:00 -05:00
|
|
|
|
|
|
|
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-10-13 02:34:19 -04:00
|
|
|
static void
|
|
|
|
add_supported_scale (GArray *supported_scales,
|
|
|
|
float scale)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < supported_scales->len; i++)
|
|
|
|
{
|
|
|
|
float supported_scale = g_array_index (supported_scales, float, i);
|
|
|
|
|
|
|
|
if (scale == supported_scale)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_append_val (supported_scales, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_scales (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
float f = *(float *) a - *(float *) b;
|
|
|
|
|
|
|
|
if (f < 0)
|
|
|
|
return -1;
|
|
|
|
if (f > 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_supported_monitor_scales (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (manager);
|
|
|
|
MetaMonitorScalesConstraint constraints;
|
|
|
|
GList *l;
|
|
|
|
GArray *supported_scales;
|
|
|
|
|
|
|
|
if (manager_xrandr->supported_scales)
|
|
|
|
return;
|
|
|
|
|
|
|
|
constraints = META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
|
|
|
|
supported_scales = g_array_new (FALSE, FALSE, sizeof (float));
|
|
|
|
|
|
|
|
for (l = manager->monitors; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = l->data;
|
|
|
|
MetaMonitorMode *monitor_mode;
|
|
|
|
float *monitor_scales;
|
|
|
|
int n_monitor_scales;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
monitor_mode = meta_monitor_get_preferred_mode (monitor);
|
|
|
|
monitor_scales =
|
|
|
|
meta_monitor_calculate_supported_scales (monitor,
|
|
|
|
monitor_mode,
|
|
|
|
constraints,
|
|
|
|
&n_monitor_scales);
|
|
|
|
|
|
|
|
for (i = 0; i < n_monitor_scales; i++)
|
|
|
|
add_supported_scale (supported_scales, monitor_scales[i]);
|
|
|
|
g_array_sort (supported_scales, compare_scales);
|
2018-02-27 08:10:04 -05:00
|
|
|
g_free (monitor_scales);
|
2017-10-13 02:34:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
manager_xrandr->supported_scales = (float *) supported_scales->data;
|
|
|
|
manager_xrandr->n_supported_scales = supported_scales->len;
|
|
|
|
g_array_free (supported_scales, FALSE);
|
|
|
|
}
|
|
|
|
|
2017-06-05 03:59:47 -04:00
|
|
|
static float *
|
2019-03-08 13:03:57 -05:00
|
|
|
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-10-13 02:34:19 -04:00
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (manager);
|
2017-06-05 03:59:47 -04:00
|
|
|
|
2017-10-13 02:34:19 -04:00
|
|
|
ensure_supported_monitor_scales (manager);
|
|
|
|
|
|
|
|
*n_supported_scales = manager_xrandr->n_supported_scales;
|
|
|
|
return g_memdup (manager_xrandr->supported_scales,
|
|
|
|
manager_xrandr->n_supported_scales * sizeof (float));
|
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)
|
|
|
|
{
|
2020-02-28 05:09:46 -05:00
|
|
|
return 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);
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
|
2017-02-15 03:06:46 -05:00
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
meta_gpu_xrandr_get_max_screen_size (META_GPU_XRANDR (gpu),
|
2017-07-10 06:19:32 -04:00
|
|
|
max_width, max_height);
|
2017-02-15 03:06:46 -05:00
|
|
|
|
|
|
|
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
|
2017-07-10 05:39:07 -04:00
|
|
|
meta_monitor_manager_xrandr_constructed (GObject *object)
|
2013-07-29 07:00:15 -04:00
|
|
|
{
|
2017-07-10 05:39:07 -04:00
|
|
|
MetaMonitorManagerXrandr *manager_xrandr =
|
|
|
|
META_MONITOR_MANAGER_XRANDR (object);
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
|
|
|
|
MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
|
2014-04-23 12:07:38 -04:00
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
manager_xrandr->xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
|
2017-07-10 06:19:32 -04:00
|
|
|
|
2014-04-23 12:07:38 -04:00
|
|
|
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);
|
|
|
|
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);
|
2014-04-23 12:07:38 -04:00
|
|
|
}
|
2017-10-13 05:01:31 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->constructed (object);
|
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);
|
|
|
|
|
2016-12-13 05:58:22 -05:00
|
|
|
g_hash_table_destroy (manager_xrandr->tiled_monitor_atoms);
|
2017-10-13 02:34:19 -04:00
|
|
|
g_free (manager_xrandr->supported_scales);
|
2016-12-13 05:58:22 -05:00
|
|
|
|
2014-04-23 12:07:38 -04:00
|
|
|
G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2017-07-10 05:39:07 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-23 12:07:38 -04:00
|
|
|
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;
|
2017-07-10 05:39:07 -04:00
|
|
|
object_class->constructed = meta_monitor_manager_xrandr_constructed;
|
2014-04-23 12:07:38 -04:00
|
|
|
|
|
|
|
manager_class->read_edid = meta_monitor_manager_xrandr_read_edid;
|
2019-01-11 08:45:44 -05:00
|
|
|
manager_class->read_current_state = meta_monitor_manager_xrandr_read_current_state;
|
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->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;
|
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;
|
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);
|
2019-01-11 09:35:42 -05:00
|
|
|
MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
|
2017-07-10 06:19:32 -04:00
|
|
|
MetaGpuXrandr *gpu_xrandr;
|
|
|
|
XRRScreenResources *resources;
|
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
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
gpu_xrandr = META_GPU_XRANDR (gpu);
|
2017-07-10 06:19:32 -04:00
|
|
|
resources = meta_gpu_xrandr_get_resources (gpu_xrandr);
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2017-07-10 06:19:32 -04:00
|
|
|
is_hotplug = resources->timestamp < resources->configTimestamp;
|
|
|
|
is_our_configuration = (resources->timestamp ==
|
2017-04-21 06:01:15 -04:00
|
|
|
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-09-11 02:10:26 -04:00
|
|
|
MetaMonitorsConfig *config;
|
2017-04-21 06:01:15 -04:00
|
|
|
|
|
|
|
if (is_our_configuration)
|
2017-09-11 02:10:26 -04:00
|
|
|
{
|
|
|
|
MetaMonitorConfigManager *config_manager =
|
|
|
|
meta_monitor_manager_get_config_manager (manager);
|
|
|
|
|
|
|
|
config = meta_monitor_config_manager_get_current (config_manager);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
config = NULL;
|
|
|
|
}
|
2017-04-21 06:01:15 -04:00
|
|
|
|
2017-10-13 02:34:19 -04:00
|
|
|
meta_monitor_manager_xrandr_rebuild_derived (manager, config);
|
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;
|
|
|
|
}
|