[Spice-devel] [PATCH][vdagent] x11-randr: Force a screen resize when a display is disabled
Fabiano FidĂȘncio
fidencio at redhat.com
Wed Mar 4 06:27:16 PST 2015
When a display is disabled the new monitors config is sent to the agent
who should be responsible for re-arranging the apps on the non-disabled
displays (at least when using the ums driver).
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1111425
---
src/vdagent-x11-randr.c | 69 ++++++++++++++++++++++++++++++-------------------
1 file changed, 42 insertions(+), 27 deletions(-)
diff --git a/src/vdagent-x11-randr.c b/src/vdagent-x11-randr.c
index 46367bc..ed63908 100644
--- a/src/vdagent-x11-randr.c
+++ b/src/vdagent-x11-randr.c
@@ -676,6 +676,42 @@ static void dump_monitors_config(struct vdagent_x11 *x11,
}
}
+static int resize_randr_screen(struct vdagent_x11 *x11,
+ VDAgentMonitorsConfig *mon_config,
+ VDAgentMonitorsConfig *curr_config,
+ int width,
+ int height,
+ int fallback)
+{
+ const int dpi = 96; /* FIXME: read settings from desktop or get from client dpi? */
+ int width_mm = (MM_PER_INCH * width) / dpi;
+ int height_mm = (MM_PER_INCH * height) / dpi;
+
+ if (x11->debug)
+ syslog(LOG_DEBUG, "Changing screen size to %dx%d", width, height);
+
+ vdagent_x11_set_error_handler(x11, error_handler);
+ XRRSetScreenSize(x11->display, x11->root_window[0], width, height, width_mm, height_mm);
+ if (vdagent_x11_restore_error_handler(x11)) {
+ syslog(LOG_ERR, "XRRSetScreenSize failed, not enough mem?");
+ if (!fallback && curr_config) {
+ syslog(LOG_WARNING, "Restoring previous config");
+ vdagent_x11_set_monitor_config(x11, curr_config, 1);
+ free(curr_config);
+ /* Remember this config failed, if the client is maximized or
+ fullscreen it will keep sending the failing config. */
+ free(x11->randr.failed_conf);
+ x11->randr.failed_conf =
+ malloc(config_size(mon_config->num_of_monitors));
+ if (x11->randr.failed_conf)
+ memcpy(x11->randr.failed_conf, mon_config,
+ config_size(mon_config->num_of_monitors));
+ return 0;
+ }
+ }
+ return 1;
+}
+
/*
* Set monitor configuration according to client request.
*
@@ -781,33 +817,8 @@ void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
/* Then we can resize the RandR screen. */
if (primary_w != x11->width[0] || primary_h != x11->height[0]) {
- const int dpi = 96; /* FIXME: read settings from desktop or get from client dpi? */
- int width_mm = (MM_PER_INCH * primary_w) / dpi;
- int height_mm = (MM_PER_INCH * primary_h) / dpi;
-
- if (x11->debug)
- syslog(LOG_DEBUG, "Changing screen size to %dx%d",
- primary_w, primary_h);
- vdagent_x11_set_error_handler(x11, error_handler);
- XRRSetScreenSize(x11->display, x11->root_window[0], primary_w, primary_h,
- width_mm, height_mm);
- if (vdagent_x11_restore_error_handler(x11)) {
- syslog(LOG_ERR, "XRRSetScreenSize failed, not enough mem?");
- if (!fallback && curr) {
- syslog(LOG_WARNING, "Restoring previous config");
- vdagent_x11_set_monitor_config(x11, curr, 1);
- free(curr);
- /* Remember this config failed, if the client is maximized or
- fullscreen it will keep sending the failing config. */
- free(x11->randr.failed_conf);
- x11->randr.failed_conf =
- malloc(config_size(mon_config->num_of_monitors));
- if (x11->randr.failed_conf)
- memcpy(x11->randr.failed_conf, mon_config,
- config_size(mon_config->num_of_monitors));
- return;
- }
- }
+ if (!resize_randr_screen(x11, mon_config, curr, primary_w, primary_h, fallback))
+ return;
}
/* Finally, we set the new resolutions on RandR CRTCs now that the
@@ -832,6 +843,10 @@ void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
}
}
+ /* Force a screen resize to re-arrange apps on non-disabled monitors */
+ if (!resize_randr_screen(x11, mon_config, curr, primary_w, primary_h, fallback))
+ return;
+
update_randr_res(x11,
x11->randr.num_monitors != enabled_monitors(mon_config));
x11->width[0] = primary_w;
--
2.1.0
More information about the Spice-devel
mailing list