summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-04-01 14:51:11 -0400
committerMatthias Clasen <mclasen@redhat.com>2023-04-01 19:09:16 -0400
commit075bea788b02c50af0fc6e8991de2f073fa80b38 (patch)
tree4d46bd076fff3959e7aa4701aa929f7b191198cb
parentd10e228ae0441e91c94b80d51c5f30c49b76dc66 (diff)
downloadgtk+-075bea788b02c50af0fc6e8991de2f073fa80b38.tar.gz
Add gdk_surface_get_scale
Add a scale property to GdkSurface and use the fractional scale for it on Wayland.
-rw-r--r--gdk/broadway/gdksurface-broadway.c15
-rw-r--r--gdk/gdksurface.c65
-rw-r--r--gdk/gdksurface.h3
-rw-r--r--gdk/gdksurfaceprivate.h2
-rw-r--r--gdk/macos/gdkmacossurface.c6
-rw-r--r--gdk/wayland/gdksurface-wayland.c16
-rw-r--r--gdk/win32/gdksurface-win32.c9
-rw-r--r--gdk/x11/gdksurface-x11.c10
8 files changed, 78 insertions, 48 deletions
diff --git a/gdk/broadway/gdksurface-broadway.c b/gdk/broadway/gdksurface-broadway.c
index 9fccfa05e9..f64392b658 100644
--- a/gdk/broadway/gdksurface-broadway.c
+++ b/gdk/broadway/gdksurface-broadway.c
@@ -407,17 +407,10 @@ gdk_broadway_surface_hide (GdkSurface *surface)
_gdk_surface_clear_update_area (surface);
}
-static int
-gdk_broadway_surface_get_scale_factor (GdkSurface *surface)
+static double
+gdk_broadway_surface_get_scale (GdkSurface *surface)
{
- GdkBroadwayDisplay *broadway_display;
-
- if (GDK_SURFACE_DESTROYED (surface))
- return 1;
-
- broadway_display = GDK_BROADWAY_DISPLAY (gdk_surface_get_display (surface));
-
- return broadway_display->scale_factor;
+ return GDK_BROADWAY_DISPLAY (gdk_surface_get_display (surface))->scale_factor;
}
static void
@@ -1271,7 +1264,7 @@ gdk_broadway_surface_class_init (GdkBroadwaySurfaceClass *klass)
impl_class->beep = gdk_broadway_surface_beep;
impl_class->destroy_notify = gdk_broadway_surface_destroy_notify;
impl_class->drag_begin = _gdk_broadway_surface_drag_begin;
- impl_class->get_scale_factor = gdk_broadway_surface_get_scale_factor;
+ impl_class->get_scale = gdk_broadway_surface_get_scale;
}
#define LAST_PROP 1
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index bcdff00db3..6aeba0bee8 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -95,6 +95,7 @@ enum {
PROP_WIDTH,
PROP_HEIGHT,
PROP_SCALE_FACTOR,
+ PROP_SCALE,
LAST_PROP
};
@@ -489,6 +490,12 @@ gdk_surface_init (GdkSurface *surface)
NULL, g_object_unref);
}
+static double
+gdk_surface_real_get_scale (GdkSurface *surface)
+{
+ return 1.0;
+}
+
static void
gdk_surface_class_init (GdkSurfaceClass *klass)
{
@@ -499,6 +506,7 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
object_class->get_property = gdk_surface_get_property;
klass->beep = gdk_surface_real_beep;
+ klass->get_scale = gdk_surface_real_get_scale;
/**
* GdkSurface:cursor: (attributes org.gtk.Property.get=gdk_surface_get_cursor org.gtk.Property.set=gdk_surface_set_cursor)
@@ -570,6 +578,18 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
1, G_MAXINT, 1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ /**
+ * GdkSurface:scale: (attributes org.gtk.Property.get=gdk_surface_get_scale)
+ *
+ * The scale of the surface.
+ *
+ * Since: 4.12
+ */
+ properties[PROP_SCALE] =
+ g_param_spec_double ("scale", NULL, NULL,
+ 1., G_MAXDOUBLE, 1.,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, LAST_PROP, properties);
/**
@@ -800,6 +820,10 @@ gdk_surface_get_property (GObject *object,
g_value_set_int (value, gdk_surface_get_scale_factor (surface));
break;
+ case PROP_SCALE:
+ g_value_set_double (value, gdk_surface_get_scale (surface));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -2360,10 +2384,10 @@ _gdk_windowing_got_event (GdkDisplay *display,
* with it.
*/
cairo_surface_t *
-gdk_surface_create_similar_surface (GdkSurface * surface,
- cairo_content_t content,
- int width,
- int height)
+gdk_surface_create_similar_surface (GdkSurface *surface,
+ cairo_content_t content,
+ int width,
+ int height)
{
cairo_surface_t *similar_surface;
int scale;
@@ -2596,25 +2620,40 @@ gdk_surface_get_frame_clock (GdkSurface *surface)
* pixel-based data the scale value can be used to determine whether to
* use a pixel resource with higher resolution data.
*
- * The scale of a surface may change during runtime.
+ * The scale may change during the lifetime of the surface.
*
* Returns: the scale factor
*/
int
gdk_surface_get_scale_factor (GdkSurface *surface)
{
- GdkSurfaceClass *class;
-
g_return_val_if_fail (GDK_IS_SURFACE (surface), 1);
- if (GDK_SURFACE_DESTROYED (surface))
- return 1;
+ return (int) ceil (gdk_surface_get_scale (surface));
+}
- class = GDK_SURFACE_GET_CLASS (surface);
- if (class->get_scale_factor)
- return class->get_scale_factor (surface);
+/**
+ * gdk_surface_get_scale: (attributes org.gtk.Method.get_property=scale)
+ * @surface: surface to get scale for
+ *
+ * Returns the internal scale that maps from surface coordinates
+ * to the actual device pixels.
+ *
+ * The scale may change during the lifetime of the surface.
+ *
+ * Returns: the scale
+ *
+ * Since: 4.12
+ */
+double
+gdk_surface_get_scale (GdkSurface *surface)
+{
+ g_return_val_if_fail (GDK_IS_SURFACE (surface), 1.);
+
+ if (GDK_SURFACE_DESTROYED (surface))
+ return 1.;
- return 1;
+ return GDK_SURFACE_GET_CLASS (surface)->get_scale (surface);
}
/**
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index f7f3e0273d..6936ff7d33 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -97,6 +97,9 @@ gboolean gdk_surface_translate_coordinates (GdkSurface *from,
GDK_AVAILABLE_IN_ALL
int gdk_surface_get_scale_factor (GdkSurface *surface);
+GDK_AVAILABLE_IN_4_12
+double gdk_surface_get_scale (GdkSurface *surface);
+
GDK_AVAILABLE_IN_ALL
gboolean gdk_surface_get_device_position (GdkSurface *surface,
GdkDevice *device,
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index f4a37af4e3..04a7597ad3 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -154,7 +154,7 @@ struct _GdkSurfaceClass
double dx,
double dy);
- int (* get_scale_factor) (GdkSurface *surface);
+ double (* get_scale) (GdkSurface *surface);
void (* set_opaque_region) (GdkSurface *surface,
cairo_region_t *region);
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index a002dc7db3..3f90a13bbf 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -234,8 +234,8 @@ gdk_macos_surface_hide (GdkSurface *surface)
}
}
-static int
-gdk_macos_surface_get_scale_factor (GdkSurface *surface)
+static double
+gdk_macos_surface_get_scale (GdkSurface *surface)
{
GdkMacosSurface *self = (GdkMacosSurface *)surface;
@@ -585,7 +585,7 @@ gdk_macos_surface_class_init (GdkMacosSurfaceClass *klass)
surface_class->get_device_state = gdk_macos_surface_get_device_state;
surface_class->get_geometry = gdk_macos_surface_get_geometry;
surface_class->get_root_coords = gdk_macos_surface_get_root_coords;
- surface_class->get_scale_factor = gdk_macos_surface_get_scale_factor;
+ surface_class->get_scale = gdk_macos_surface_get_scale;
surface_class->hide = gdk_macos_surface_hide;
surface_class->set_input_region = gdk_macos_surface_set_input_region;
surface_class->set_opaque_region = gdk_macos_surface_set_opaque_region;
diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c
index f19887460c..76112b8256 100644
--- a/gdk/wayland/gdksurface-wayland.c
+++ b/gdk/wayland/gdksurface-wayland.c
@@ -269,7 +269,10 @@ gdk_wayland_surface_update_size (GdkSurface *surface,
if (height_changed)
g_object_notify (G_OBJECT (surface), "height");
if (scale_changed)
- g_object_notify (G_OBJECT (surface), "scale-factor");
+ {
+ g_object_notify (G_OBJECT (surface), "scale-factor");
+ g_object_notify (G_OBJECT (surface), "scale");
+ }
_gdk_surface_update_size (surface);
}
@@ -1253,15 +1256,12 @@ gdk_wayland_surface_destroy_notify (GdkSurface *surface)
g_object_unref (surface);
}
-static int
-gdk_wayland_surface_get_scale_factor (GdkSurface *surface)
+static double
+gdk_wayland_surface_get_scale (GdkSurface *surface)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
- if (GDK_SURFACE_DESTROYED (surface))
- return 1;
-
- return gdk_fractional_scale_to_int (&impl->scale);
+ return gdk_fractional_scale_to_double (&impl->scale);
}
static void
@@ -1313,7 +1313,7 @@ gdk_wayland_surface_class_init (GdkWaylandSurfaceClass *klass)
surface_class->destroy_notify = gdk_wayland_surface_destroy_notify;
surface_class->drag_begin = _gdk_wayland_surface_drag_begin;
- surface_class->get_scale_factor = gdk_wayland_surface_get_scale_factor;
+ surface_class->get_scale = gdk_wayland_surface_get_scale;
surface_class->set_opaque_region = gdk_wayland_surface_set_opaque_region;
surface_class->request_layout = gdk_wayland_surface_request_layout;
diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c
index 5a32e78f30..8603ee2e9e 100644
--- a/gdk/win32/gdksurface-win32.c
+++ b/gdk/win32/gdksurface-win32.c
@@ -4445,16 +4445,13 @@ gdk_win32_surface_set_shadow_width (GdkSurface *window,
}
-int
-_gdk_win32_surface_get_scale_factor (GdkSurface *surface)
+double
+_gdk_win32_surface_get_scale (GdkSurface *surface)
{
GdkDisplay *display;
GdkWin32Surface *impl;
GdkWin32Display *win32_display;
- if (GDK_SURFACE_DESTROYED (surface))
- return 1;
-
g_return_val_if_fail (surface != NULL, 1);
display = gdk_surface_get_display (surface);
@@ -4654,7 +4651,7 @@ gdk_win32_surface_class_init (GdkWin32SurfaceClass *klass)
impl_class->destroy_notify = gdk_win32_surface_destroy_notify;
impl_class->drag_begin = _gdk_win32_surface_drag_begin;
- impl_class->get_scale_factor = _gdk_win32_surface_get_scale_factor;
+ impl_class->get_scale = _gdk_win32_surface_get_scale;
impl_class->request_layout = _gdk_win32_surface_request_layout;
impl_class->compute_size = _gdk_win32_surface_compute_size;
}
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index 8f56fe5e74..284895ce0e 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -2092,6 +2092,7 @@ _gdk_x11_surface_set_surface_scale (GdkSurface *surface,
gdk_surface_invalidate_rect (surface, NULL);
g_object_notify (G_OBJECT (surface), "scale-factor");
+ g_object_notify (G_OBJECT (surface), "scale");
}
void
@@ -4741,14 +4742,11 @@ gdk_x11_surface_get_xid (GdkSurface *surface)
return GDK_X11_SURFACE (surface)->xid;
}
-static int
-gdk_x11_surface_get_scale_factor (GdkSurface *surface)
+static double
+gdk_x11_surface_get_scale (GdkSurface *surface)
{
GdkX11Surface *impl = GDK_X11_SURFACE (surface);
- if (GDK_SURFACE_DESTROYED (surface))
- return 1;
-
return impl->surface_scale;
}
@@ -4888,7 +4886,7 @@ gdk_x11_surface_class_init (GdkX11SurfaceClass *klass)
impl_class->destroy_notify = gdk_x11_surface_destroy_notify;
impl_class->drag_begin = _gdk_x11_surface_drag_begin;
- impl_class->get_scale_factor = gdk_x11_surface_get_scale_factor;
+ impl_class->get_scale = gdk_x11_surface_get_scale;
impl_class->set_opaque_region = gdk_x11_surface_set_opaque_region;
impl_class->request_layout = gdk_x11_surface_request_layout;
impl_class->compute_size = gdk_x11_surface_compute_size;