Merge branch 'surface-scale' into 'master'

Surface scale

Closes #3578

See merge request GNOME/gtk!3085
This commit is contained in:
Matthias Clasen 2021-01-17 05:23:22 +00:00
commit 1b961a9ae2
4 changed files with 43 additions and 3 deletions

View File

@ -92,6 +92,7 @@ enum {
PROP_MAPPED,
PROP_WIDTH,
PROP_HEIGHT,
PROP_SCALE_FACTOR,
LAST_PROP
};
@ -551,6 +552,13 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
0, G_MAXINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_SCALE_FACTOR] =
g_param_spec_int ("scale-factor",
P_("Scale factor"),
P_("Scale factor"),
1, G_MAXINT, 1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, properties);
/**
@ -782,6 +790,10 @@ gdk_surface_get_property (GObject *object,
g_value_set_int (value, surface->height);
break;
case PROP_SCALE_FACTOR:
g_value_set_int (value, gdk_surface_get_scale_factor (surface));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;

View File

@ -389,10 +389,13 @@ gdk_wayland_surface_update_size (GdkSurface *surface,
int scale)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
gboolean width_changed, height_changed, scale_changed;
if ((surface->width == width) &&
(surface->height == height) &&
(impl->scale == scale))
width_changed = surface->width != width;
height_changed = surface->height != height;
scale_changed = impl->scale != scale;
if (!width_changed && !height_changed && !scale_changed)
return;
surface->width = width;
@ -405,6 +408,13 @@ gdk_wayland_surface_update_size (GdkSurface *surface,
wl_surface_set_buffer_scale (impl->display_server.wl_surface, scale);
gdk_surface_invalidate_rect (surface, NULL);
if (width_changed)
g_object_notify (G_OBJECT (surface), "width");
if (height_changed)
g_object_notify (G_OBJECT (surface), "height");
if (scale_changed)
g_object_notify (G_OBJECT (surface), "scale-factor");
}
static const char *

View File

@ -2013,6 +2013,8 @@ _gdk_x11_surface_set_surface_scale (GdkSurface *surface,
surface->height * impl->surface_scale);
gdk_surface_invalidate_rect (surface, NULL);
g_object_notify (G_OBJECT (surface), "scale-factor");
}
void

View File

@ -30,6 +30,7 @@ typedef struct _GtkNativePrivate
{
gulong update_handler_id;
gulong layout_handler_id;
gulong scale_changed_handler_id;
} GtkNativePrivate;
static GQuark quark_gtk_native_private;
@ -108,6 +109,14 @@ surface_layout_cb (GdkSurface *surface,
gtk_native_queue_relayout (native);
}
static void
scale_changed_cb (GdkSurface *surface,
GParamSpec *pspec,
GtkNative *native)
{
_gtk_widget_scale_changed (GTK_WIDGET (native));
}
static void
verify_priv_unrealized (gpointer user_data)
{
@ -115,6 +124,7 @@ verify_priv_unrealized (gpointer user_data)
g_warn_if_fail (priv->update_handler_id == 0);
g_warn_if_fail (priv->layout_handler_id == 0);
g_warn_if_fail (priv->scale_changed_handler_id == 0);
g_free (priv);
}
@ -146,6 +156,11 @@ gtk_native_realize (GtkNative *self)
priv->layout_handler_id = g_signal_connect (surface, "layout",
G_CALLBACK (surface_layout_cb),
self);
priv->scale_changed_handler_id = g_signal_connect (surface, "notify::scale-factor",
G_CALLBACK (scale_changed_cb),
self);
g_object_set_qdata_full (G_OBJECT (self),
quark_gtk_native_private,
priv,
@ -174,6 +189,7 @@ gtk_native_unrealize (GtkNative *self)
g_clear_signal_handler (&priv->update_handler_id, clock);
g_clear_signal_handler (&priv->layout_handler_id, surface);
g_clear_signal_handler (&priv->scale_changed_handler_id, surface);
g_object_set_qdata (G_OBJECT (self), quark_gtk_native_private, NULL);
}