src: add menu to control whether framebuffer resize is attempted
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé
3 years ago
22 | 22 | <item> |
23 | 23 | <attribute name="label" translatable="yes">_Normal Size</attribute> |
24 | 24 | <attribute name="action">win.zoom-reset</attribute> |
25 | </item> | |
26 | <item> | |
27 | <attribute name="label" translatable="yes">_Auto resize</attribute> | |
28 | <attribute name="action">app.auto-resize</attribute> | |
25 | 29 | </item> |
26 | 30 | </section> |
27 | 31 | <section> |
105 | 105 | static VirtViewerWindow *virt_viewer_app_get_nth_window(VirtViewerApp *self, gint nth); |
106 | 106 | static VirtViewerWindow *virt_viewer_app_get_vte_window(VirtViewerApp *self, const gchar *name); |
107 | 107 | static void virt_viewer_app_set_actions_sensitive(VirtViewerApp *self); |
108 | static void virt_viewer_app_set_display_auto_resize(VirtViewerApp *self, | |
109 | VirtViewerDisplay *display); | |
108 | 110 | |
109 | 111 | /* Application actions */ |
110 | 112 | static void virt_viewer_app_action_monitor(GSimpleAction *act, |
1077 | 1079 | virt_viewer_session_has_vm_action(priv->session, |
1078 | 1080 | VIRT_VIEWER_SESSION_VM_ACTION_POWER_DOWN)); |
1079 | 1081 | |
1082 | action = g_action_map_lookup_action(map, "auto-resize"); | |
1083 | g_simple_action_set_enabled(G_SIMPLE_ACTION(action), | |
1084 | priv->connected); | |
1080 | 1085 | } |
1081 | 1086 | |
1082 | 1087 | static VirtViewerWindow * |
1219 | 1224 | win = virt_viewer_app_window_new(self, nth); |
1220 | 1225 | } |
1221 | 1226 | |
1227 | virt_viewer_app_set_display_auto_resize(self, display); | |
1222 | 1228 | virt_viewer_window_set_display(win, display); |
1223 | 1229 | if (VIRT_VIEWER_IS_DISPLAY_VTE(display)) { |
1224 | 1230 | g_object_set_data(G_OBJECT(display), "virt-viewer-window", win); |
1299 | 1305 | } |
1300 | 1306 | |
1301 | 1307 | g_hash_table_insert(priv->displays, GINT_TO_POINTER(nth), g_object_ref(display)); |
1308 | virt_viewer_app_set_display_auto_resize(self, display); | |
1302 | 1309 | |
1303 | 1310 | g_signal_connect(display, "notify::show-hint", |
1304 | 1311 | G_CALLBACK(display_show_hint), NULL); |
2281 | 2288 | virt_viewer_session_smartcard_remove(virt_viewer_app_get_session(self)); |
2282 | 2289 | } |
2283 | 2290 | |
2291 | ||
2292 | static void | |
2293 | virt_viewer_app_set_display_auto_resize(VirtViewerApp *self, | |
2294 | VirtViewerDisplay *display) | |
2295 | { | |
2296 | GAction *action = g_action_map_lookup_action(G_ACTION_MAP(self), "auto-resize"); | |
2297 | GVariant *state = g_action_get_state(action); | |
2298 | gboolean resize = g_variant_get_boolean(state); | |
2299 | virt_viewer_display_set_auto_resize(display, resize); | |
2300 | } | |
2301 | ||
2302 | static void | |
2303 | set_window_autoresize(gpointer value, gpointer user_data) | |
2304 | { | |
2305 | VirtViewerApp *self = VIRT_VIEWER_APP(user_data); | |
2306 | VirtViewerDisplay *display = virt_viewer_window_get_display(VIRT_VIEWER_WINDOW(value)); | |
2307 | virt_viewer_app_set_display_auto_resize(self, display); | |
2308 | } | |
2309 | ||
2310 | static void | |
2311 | virt_viewer_app_action_auto_resize(GSimpleAction *act G_GNUC_UNUSED, | |
2312 | GVariant *state, | |
2313 | gpointer opaque) | |
2314 | { | |
2315 | g_return_if_fail(VIRT_VIEWER_IS_APP(opaque)); | |
2316 | ||
2317 | VirtViewerApp *self = VIRT_VIEWER_APP(opaque); | |
2318 | VirtViewerAppPrivate *priv = virt_viewer_app_get_instance_private(self); | |
2319 | gboolean resize = g_variant_get_boolean(state); | |
2320 | ||
2321 | g_simple_action_set_state(act, g_variant_new_boolean(resize)); | |
2322 | ||
2323 | g_list_foreach(priv->windows, set_window_autoresize, self); | |
2324 | } | |
2325 | ||
2284 | 2326 | static void |
2285 | 2327 | virt_viewer_app_action_window(VirtViewerApp *self, |
2286 | 2328 | VirtViewerWindow *win, |
2374 | 2416 | .activate = virt_viewer_app_action_smartcard_insert }, |
2375 | 2417 | { .name = "smartcard-remove", |
2376 | 2418 | .activate = virt_viewer_app_action_smartcard_remove }, |
2419 | { .name = "auto-resize", | |
2420 | .state = "true", | |
2421 | .change_state = virt_viewer_app_action_auto_resize }, | |
2377 | 2422 | }; |
2378 | 2423 | |
2379 | 2424 | struct VirtViewerActionAccels { |
261 | 261 | } |
262 | 262 | |
263 | 263 | static void |
264 | fullscreen_changed(VirtViewerDisplaySpice *self, | |
265 | GParamSpec *pspec G_GNUC_UNUSED, | |
266 | VirtViewerApp *app) | |
267 | { | |
268 | if (virt_viewer_display_get_fullscreen(VIRT_VIEWER_DISPLAY(self))) { | |
269 | gboolean auto_conf; | |
270 | g_object_get(app, "fullscreen", &auto_conf, NULL); | |
271 | if (auto_conf) | |
272 | self->auto_resize = AUTO_RESIZE_NEVER; | |
273 | else | |
274 | self->auto_resize = AUTO_RESIZE_FULLSCREEN; | |
275 | } else | |
276 | self->auto_resize = AUTO_RESIZE_ALWAYS; | |
264 | resize_policy_changed(VirtViewerDisplaySpice *self, | |
265 | GParamSpec *pspec G_GNUC_UNUSED, | |
266 | VirtViewerApp *app) | |
267 | { | |
268 | if (virt_viewer_display_get_auto_resize(VIRT_VIEWER_DISPLAY(self))) { | |
269 | if (virt_viewer_display_get_fullscreen(VIRT_VIEWER_DISPLAY(self))) { | |
270 | gboolean auto_conf; | |
271 | g_object_get(app, "fullscreen", &auto_conf, NULL); | |
272 | if (auto_conf) | |
273 | self->auto_resize = AUTO_RESIZE_NEVER; | |
274 | else | |
275 | self->auto_resize = AUTO_RESIZE_FULLSCREEN; | |
276 | } else { | |
277 | self->auto_resize = AUTO_RESIZE_ALWAYS; | |
278 | } | |
279 | } else { | |
280 | self->auto_resize = AUTO_RESIZE_NEVER; | |
281 | } | |
277 | 282 | } |
278 | 283 | |
279 | 284 | GtkWidget * |
334 | 339 | virt_viewer_signal_connect_object(app, "notify::enable-accel", |
335 | 340 | G_CALLBACK(enable_accel_changed), self, 0); |
336 | 341 | virt_viewer_signal_connect_object(self, "notify::fullscreen", |
337 | G_CALLBACK(fullscreen_changed), app, 0); | |
342 | G_CALLBACK(resize_policy_changed), app, 0); | |
343 | virt_viewer_signal_connect_object(self, "notify::auto-resize", | |
344 | G_CALLBACK(resize_policy_changed), app, 0); | |
338 | 345 | virt_viewer_signal_connect_object(self, "notify::zoom-level", |
339 | 346 | G_CALLBACK(zoom_level_changed), app, 0); |
340 | fullscreen_changed(self, NULL, app); | |
347 | resize_policy_changed(self, NULL, app); | |
341 | 348 | enable_accel_changed(app, NULL, self); |
342 | 349 | |
343 | 350 | return GTK_WIDGET(self); |
41 | 41 | guint show_hint; |
42 | 42 | VirtViewerSession *session; |
43 | 43 | gboolean fullscreen; |
44 | gboolean auto_resize; | |
44 | 45 | }; |
45 | 46 | |
46 | 47 | static void virt_viewer_display_get_preferred_width(GtkWidget *widget, |
75 | 76 | PROP_SESSION, |
76 | 77 | PROP_SELECTABLE, |
77 | 78 | PROP_MONITOR, |
79 | PROP_AUTO_RESIZE, | |
78 | 80 | }; |
79 | 81 | |
80 | 82 | static void |
177 | 179 | FALSE, |
178 | 180 | G_PARAM_READABLE)); |
179 | 181 | |
182 | g_object_class_install_property(object_class, | |
183 | PROP_AUTO_RESIZE, | |
184 | g_param_spec_boolean("auto-resize", | |
185 | "Auto-resize", | |
186 | "Auto-resize", | |
187 | TRUE, | |
188 | G_PARAM_READABLE | | |
189 | G_PARAM_WRITABLE)); | |
190 | ||
180 | 191 | g_signal_new("display-pointer-grab", |
181 | 192 | G_OBJECT_CLASS_TYPE(object_class), |
182 | 193 | G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, |
282 | 293 | case PROP_MONITOR: |
283 | 294 | priv->monitor = g_value_get_int(value); |
284 | 295 | break; |
296 | case PROP_AUTO_RESIZE: | |
297 | priv->auto_resize = g_value_get_boolean(value); | |
298 | break; | |
285 | 299 | |
286 | 300 | default: |
287 | 301 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
322 | 336 | break; |
323 | 337 | case PROP_FULLSCREEN: |
324 | 338 | g_value_set_boolean(value, virt_viewer_display_get_fullscreen(display)); |
339 | break; | |
340 | case PROP_AUTO_RESIZE: | |
341 | g_value_set_boolean(value, virt_viewer_display_get_auto_resize(display)); | |
325 | 342 | break; |
326 | 343 | |
327 | 344 | default: |
750 | 767 | priv = virt_viewer_display_get_instance_private(self); |
751 | 768 | return priv->nth_display; |
752 | 769 | } |
770 | ||
771 | void virt_viewer_display_set_auto_resize(VirtViewerDisplay *self, gboolean enabled) | |
772 | { | |
773 | VirtViewerDisplayPrivate *priv; | |
774 | g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(self)); | |
775 | ||
776 | priv = virt_viewer_display_get_instance_private(self); | |
777 | priv->auto_resize = enabled; | |
778 | g_object_notify(G_OBJECT(self), "auto-resize"); | |
779 | } | |
780 | ||
781 | gboolean virt_viewer_display_get_auto_resize(VirtViewerDisplay *self) | |
782 | { | |
783 | VirtViewerDisplayPrivate *priv; | |
784 | g_return_val_if_fail(VIRT_VIEWER_IS_DISPLAY(self), FALSE); | |
785 | ||
786 | priv = virt_viewer_display_get_instance_private(self); | |
787 | return priv->auto_resize; | |
788 | } |
108 | 108 | void virt_viewer_display_queue_resize(VirtViewerDisplay *display); |
109 | 109 | void virt_viewer_display_get_preferred_monitor_geometry(VirtViewerDisplay *self, GdkRectangle* preferred); |
110 | 110 | gint virt_viewer_display_get_nth(VirtViewerDisplay *self); |
111 | void virt_viewer_display_set_auto_resize(VirtViewerDisplay *self, gboolean enabled); | |
112 | gboolean virt_viewer_display_get_auto_resize(VirtViewerDisplay *self); |