[PATCH 3/3] Notify clients when a mode switch occurs

Hardening rdp.effort at gmail.com
Sun Jul 7 15:51:36 PDT 2013


This patch adds a notification of all clients when the mode is switched
on an output. The notification occurs only when it's a permanent switch
not when the mode is changed for a surface fullscreen.
---
 src/compositor.c | 27 ++++++++++++++++++++++++++-
 src/compositor.h |  3 ++-
 src/shell.c      |  5 +++--
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index a02da8b..4191f66 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -97,15 +97,19 @@ static void
 weston_compositor_build_surface_list(struct weston_compositor *compositor);
 
 WL_EXPORT int
-weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode, int32_t scale)
+weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode, int32_t scale,
+		int permanent)
 {
 	struct weston_seat *seat;
 	pixman_region32_t old_output_region;
 	int ret;
+	struct weston_mode old_mode;
+	struct wl_resource *resource;
 
 	if (!output->switch_mode)
 		return -1;
 
+	old_mode = *output->current;
 	ret = output->switch_mode(output, mode);
 	if (ret < 0)
 		return ret;
@@ -153,6 +157,27 @@ weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode
 
 	pixman_region32_fini(&old_output_region);
 
+	if (permanent) {
+		/* notify clients when the mode switch is permanent */
+		wl_list_for_each (resource, &output->resource_list, link) {
+			/* send old mode with flags updated */
+			wl_output_send_mode(resource,
+				old_mode.flags & ~WL_OUTPUT_MODE_CURRENT,
+				old_mode.width,
+				old_mode.height,
+				old_mode.refresh);
+
+			/* send new mode with current flags set */
+			wl_output_send_mode(resource,
+				mode->flags | WL_OUTPUT_MODE_CURRENT,
+				mode->width,
+				mode->height,
+				mode->refresh);
+
+			if (wl_resource_get_version(resource) >= 2)
+				wl_output_send_done(resource);
+		}
+	}
 	return ret;
 }
 
diff --git a/src/compositor.h b/src/compositor.h
index 8070409..1def382 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1190,7 +1190,8 @@ void
 weston_surface_destroy(struct weston_surface *surface);
 
 int
-weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode, int32_t scale);
+weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode, int32_t scale,
+		int permanent);
 
 int
 noop_renderer_init(struct weston_compositor *ec);
diff --git a/src/shell.c b/src/shell.c
index e20004f..c79c2ce 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1516,7 +1516,8 @@ restore_output_mode(struct weston_output *output)
 	    (int32_t)output->scale != output->origin_scale)
 		weston_output_switch_mode(output,
 					  output->origin,
-					  output->origin_scale);
+					  output->origin_scale,
+					  0);
 }
 
 static void
@@ -1843,7 +1844,7 @@ shell_configure_fullscreen(struct shell_surface *shsurf)
 				surf_height * surface->buffer_scale,
 				shsurf->fullscreen.framerate};
 
-			if (weston_output_switch_mode(output, &mode, surface->buffer_scale) == 0) {
+			if (weston_output_switch_mode(output, &mode, surface->buffer_scale, 0) == 0) {
 				weston_surface_set_position(surface,
 							    output->x - surf_x,
 							    output->y - surf_y);
-- 
1.8.1.2



More information about the wayland-devel mailing list