_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
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
PROP_WIDTH,
PROP_HEIGHT,
PROP_SCALE_FACTOR,
+ PROP_SCALE,
LAST_PROP
};
NULL, g_object_unref);
}
+static double
+gdk_surface_real_get_scale (GdkSurface *surface)
+{
+ return 1.0;
+}
+
static void
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)
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);
/**
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;
* 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;
* 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);
}
/**
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,
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);
}
}
-static int
-gdk_macos_surface_get_scale_factor (GdkSurface *surface)
+static double
+gdk_macos_surface_get_scale (GdkSurface *surface)
{
GdkMacosSurface *self = (GdkMacosSurface *)surface;
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;
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);
}
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
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;
}
-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);
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;
}
gdk_surface_invalidate_rect (surface, NULL);
g_object_notify (G_OBJECT (surface), "scale-factor");
+ g_object_notify (G_OBJECT (surface), "scale");
}
void
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;
}
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;