Commit 74c01f09 authored by Marco Trevisan's avatar Marco Trevisan 🎺

x11, monitor-manager: update the screen size using scale for computing sizes

And only perform this if the screen size changed since the last update we received
parent 46d5d426
...@@ -144,6 +144,57 @@ meta_monitor_manager_xrandr_set_power_save_mode (MetaMonitorManager *manager, ...@@ -144,6 +144,57 @@ meta_monitor_manager_xrandr_set_power_save_mode (MetaMonitorManager *manager,
DPMSSetTimeouts (manager_xrandr->xdisplay, 0, 0, 0); DPMSSetTimeouts (manager_xrandr->xdisplay, 0, 0, 0);
} }
static void
meta_monitor_manager_xrandr_update_screen_size (MetaMonitorManagerXrandr *manager_xrandr,
int width,
int height,
float scale)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
Screen *screen;
int min_width;
int min_height;
int max_width;
int max_height;
int width_mm;
int height_mm;
g_assert (width > 0 && height > 0 && scale > 0);
if (manager->screen_width == width && manager->screen_height == height)
return;
screen = ScreenOfDisplay (manager_xrandr->xdisplay,
DefaultScreen (manager_xrandr->xdisplay));
meta_gpu_xrandr_get_min_screen_size (META_GPU_XRANDR (manager_xrandr->gpu),
&min_width, &min_height);
meta_gpu_xrandr_get_max_screen_size (META_GPU_XRANDR (manager_xrandr->gpu),
&max_width, &max_height);
width = MIN (MAX (min_width, width), max_width);
height = MIN (MAX (min_height, height), max_height);
/* 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 * scale)) * 25.4 + 0.5;
height_mm = (height / (DPI_FALLBACK * scale)) * 25.4 + 0.5;
if (width == WidthOfScreen (screen) && height == HeightOfScreen (screen) &&
width_mm == WidthMMOfScreen (screen) && height_mm == HeightMMOfScreen (screen))
return;
XGrabServer (manager_xrandr->xdisplay);
XRRSetScreenSize (manager_xrandr->xdisplay,
DefaultRootWindow (manager_xrandr->xdisplay),
width, height, width_mm, height_mm);
XUngrabServer (manager_xrandr->xdisplay);
manager->screen_width = width;
manager->screen_height = height;
}
static xcb_randr_rotation_t static xcb_randr_rotation_t
meta_monitor_transform_to_xrandr (MetaMonitorTransform transform) meta_monitor_transform_to_xrandr (MetaMonitorTransform transform)
{ {
...@@ -338,14 +389,17 @@ apply_crtc_assignments (MetaMonitorManager *manager, ...@@ -338,14 +389,17 @@ apply_crtc_assignments (MetaMonitorManager *manager,
unsigned int n_outputs) unsigned int n_outputs)
{ {
MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager); MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
unsigned i; unsigned i, valid_crtcs;
GList *l; GList *l;
int width, height, width_mm, height_mm; int width, height;
float avg_screen_scale;
XGrabServer (manager_xrandr->xdisplay); XGrabServer (manager_xrandr->xdisplay);
/* First compute the new size of the screen (framebuffer) */ /* First compute the new size of the screen (framebuffer) */
width = 0; height = 0; width = 0; height = 0;
avg_screen_scale = 0;
valid_crtcs = 0;
for (i = 0; i < n_crtcs; i++) for (i = 0; i < n_crtcs; i++)
{ {
MetaCrtcInfo *crtc_info = crtcs[i]; MetaCrtcInfo *crtc_info = crtcs[i];
...@@ -365,6 +419,10 @@ apply_crtc_assignments (MetaMonitorManager *manager, ...@@ -365,6 +419,10 @@ apply_crtc_assignments (MetaMonitorManager *manager,
width = MAX (width, crtc_info->x + crtc_info->mode->width); width = MAX (width, crtc_info->x + crtc_info->mode->width);
height = MAX (height, crtc_info->y + crtc_info->mode->height); height = MAX (height, crtc_info->y + crtc_info->mode->height);
} }
valid_crtcs++;
avg_screen_scale += (crtc_info->scale - avg_screen_scale) /
(float) valid_crtcs;
} }
/* Second disable all newly disabled CRTCs, or CRTCs that in the previous /* Second disable all newly disabled CRTCs, or CRTCs that in the previous
...@@ -427,17 +485,8 @@ apply_crtc_assignments (MetaMonitorManager *manager, ...@@ -427,17 +485,8 @@ apply_crtc_assignments (MetaMonitorManager *manager,
crtc->current_mode = NULL; crtc->current_mode = NULL;
} }
g_assert (width > 0 && height > 0); meta_monitor_manager_xrandr_update_screen_size (manager_xrandr, width, height,
/* The 'physical size' of an X screen is meaningless if that screen avg_screen_scale);
* 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);
for (i = 0; i < n_crtcs; i++) for (i = 0; i < n_crtcs; i++)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment