[Spice-devel] [PATCH] Add ability to get SpiceDisplay resolution
Jonathon Jongsma
jjongsma at redhat.com
Thu Oct 31 23:34:10 CET 2013
add spice_display_get_width() and spice_display_get_height() to get the current
configuration of the display resolution.
---
gtk/map-file | 2 ++
gtk/spice-gtk-sym-file | 2 ++
gtk/spice-widget.c | 45 +++++++++++++++++++++++++++++++++------------
gtk/spice-widget.h | 3 +++
4 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/gtk/map-file b/gtk/map-file
index 368b44f..2f89d61 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -32,6 +32,8 @@ spice_display_new_with_monitor;
spice_display_paste_from_guest;
spice_display_send_keys;
spice_display_set_grab_keys;
+spice_display_get_width;
+spice_display_get_height;
spice_error_get_type;
spice_get_option_group;
spice_grab_sequence_as_string;
diff --git a/gtk/spice-gtk-sym-file b/gtk/spice-gtk-sym-file
index 1574e07..8c8ca0b 100644
--- a/gtk/spice-gtk-sym-file
+++ b/gtk/spice-gtk-sym-file
@@ -9,6 +9,8 @@ spice_display_new_with_monitor
spice_display_paste_from_guest
spice_display_send_keys
spice_display_set_grab_keys
+spice_display_get_width
+spice_display_get_height
spice_grab_sequence_as_string
spice_grab_sequence_copy
spice_grab_sequence_free
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index d39ff59..59b7087 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -278,25 +278,35 @@ static gint get_display_id(SpiceDisplay *display)
return d->channel_id;
}
-static void update_monitor_area(SpiceDisplay *display)
+static SpiceDisplayMonitorConfig* get_monitor_config(SpiceDisplay* display)
{
- SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
- SpiceDisplayMonitorConfig *cfg, *c = NULL;
- GArray *monitors = NULL;
int i;
+ GArray *monitors = NULL;
+ SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+ SpiceDisplayMonitorConfig* c = NULL;
- SPICE_DEBUG("update monitor area %d:%d", d->channel_id, d->monitor_id);
- if (d->monitor_id < 0)
- goto whole;
+ g_return_val_if_fail(d->monitor_id >= 0, NULL);
g_object_get(d->display, "monitors", &monitors, NULL);
for (i = 0; monitors != NULL && i < monitors->len; i++) {
- cfg = &g_array_index(monitors, SpiceDisplayMonitorConfig, i);
+ SpiceDisplayMonitorConfig *cfg = &g_array_index(monitors,
+ SpiceDisplayMonitorConfig,
+ i);
if (cfg->id == d->monitor_id) {
- c = cfg;
- break;
+ c = cfg;
+ break;
}
}
+
+ g_clear_pointer(&monitors, g_array_unref);
+ return c;
+}
+
+static void update_monitor_area(SpiceDisplay *display)
+{
+ SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+ SpiceDisplayMonitorConfig *c = get_monitor_config(display);
+
if (c == NULL) {
SPICE_DEBUG("update monitor: no monitor %d", d->monitor_id);
set_monitor_ready(display, false);
@@ -318,11 +328,9 @@ static void update_monitor_area(SpiceDisplay *display)
c->x, c->y, c->width, c->height, FALSE);
update_area(display, c->x, c->y, c->width, c->height);
- g_clear_pointer(&monitors, g_array_unref);
return;
whole:
- g_clear_pointer(&monitors, g_array_unref);
/* by display whole surface */
update_area(display, 0, 0, d->width, d->height);
set_monitor_ready(display, true);
@@ -2575,6 +2583,19 @@ GdkPixbuf *spice_display_get_pixbuf(SpiceDisplay *display)
return pixbuf;
}
+gint spice_display_get_width(SpiceDisplay *display)
+{
+ SpiceDisplayMonitorConfig* cfg = get_monitor_config(display);
+ return cfg ? cfg->width : 0;
+}
+
+gint spice_display_get_height(SpiceDisplay *display)
+{
+ SpiceDisplayMonitorConfig* cfg = get_monitor_config(display);
+ return cfg ? cfg->height : 0;
+}
+
+
#if HAVE_X11_XKBLIB_H
static guint32 get_keyboard_lock_modifiers(Display *x_display)
{
diff --git a/gtk/spice-widget.h b/gtk/spice-widget.h
index d239ed2..7335722 100644
--- a/gtk/spice-widget.h
+++ b/gtk/spice-widget.h
@@ -80,6 +80,9 @@ void spice_display_send_keys(SpiceDisplay *display, const guint *keyvals,
int nkeyvals, SpiceDisplayKeyEvent kind);
GdkPixbuf *spice_display_get_pixbuf(SpiceDisplay *display);
+gint spice_display_get_width(SpiceDisplay *display);
+gint spice_display_get_height(SpiceDisplay *display);
+
#ifndef SPICE_DISABLE_DEPRECATED
SPICE_DEPRECATED_FOR(spice_gtk_session_copy_to_guest)
void spice_display_copy_to_guest(SpiceDisplay *display);
--
1.8.3.1
More information about the Spice-devel
mailing list