screenshot: Mark as a final type
It was already declared as such, so get rid of the priv boilerplate. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3525>
This commit is contained in:
parent
71ecb8e6cd
commit
ab41daefcf
@ -34,17 +34,10 @@ enum
|
|||||||
|
|
||||||
static guint signals[LAST_SIGNAL] = { 0, };
|
static guint signals[LAST_SIGNAL] = { 0, };
|
||||||
|
|
||||||
typedef struct _ShellScreenshotPrivate ShellScreenshotPrivate;
|
typedef struct _ShellScreenshot
|
||||||
|
|
||||||
struct _ShellScreenshot
|
|
||||||
{
|
{
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _ShellScreenshotPrivate
|
|
||||||
{
|
|
||||||
ShellGlobal *global;
|
ShellGlobal *global;
|
||||||
|
|
||||||
GOutputStream *stream;
|
GOutputStream *stream;
|
||||||
@ -62,9 +55,9 @@ struct _ShellScreenshotPrivate
|
|||||||
ClutterContent *cursor_content;
|
ClutterContent *cursor_content;
|
||||||
graphene_point_t cursor_point;
|
graphene_point_t cursor_point;
|
||||||
float cursor_scale;
|
float cursor_scale;
|
||||||
};
|
} ShellScreenshot;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (ShellScreenshot, shell_screenshot, G_TYPE_OBJECT);
|
G_DEFINE_FINAL_TYPE (ShellScreenshot, shell_screenshot, G_TYPE_OBJECT);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shell_screenshot_class_init (ShellScreenshotClass *screenshot_class)
|
shell_screenshot_class_init (ShellScreenshotClass *screenshot_class)
|
||||||
@ -83,8 +76,7 @@ shell_screenshot_class_init (ShellScreenshotClass *screenshot_class)
|
|||||||
static void
|
static void
|
||||||
shell_screenshot_init (ShellScreenshot *screenshot)
|
shell_screenshot_init (ShellScreenshot *screenshot)
|
||||||
{
|
{
|
||||||
screenshot->priv = shell_screenshot_get_instance_private (screenshot);
|
screenshot->global = shell_global_get ();
|
||||||
screenshot->priv->global = shell_global_get ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -93,15 +85,14 @@ on_screenshot_written (GObject *source,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ShellScreenshot *screenshot = SHELL_SCREENSHOT (source);
|
ShellScreenshot *screenshot = SHELL_SCREENSHOT (source);
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
||||||
GTask *result = user_data;
|
GTask *result = user_data;
|
||||||
|
|
||||||
g_task_return_boolean (result, g_task_propagate_boolean (G_TASK (task), NULL));
|
g_task_return_boolean (result, g_task_propagate_boolean (G_TASK (task), NULL));
|
||||||
g_object_unref (result);
|
g_object_unref (result);
|
||||||
|
|
||||||
g_clear_pointer (&priv->image, cairo_surface_destroy);
|
g_clear_pointer (&screenshot->image, cairo_surface_destroy);
|
||||||
g_clear_object (&priv->stream);
|
g_clear_object (&screenshot->stream);
|
||||||
g_clear_pointer (&priv->datetime, g_date_time_unref);
|
g_clear_pointer (&screenshot->datetime, g_date_time_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
static cairo_format_t
|
static cairo_format_t
|
||||||
@ -287,7 +278,6 @@ write_screenshot_thread (GTask *result,
|
|||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
ShellScreenshot *screenshot = SHELL_SCREENSHOT (object);
|
ShellScreenshot *screenshot = SHELL_SCREENSHOT (object);
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
g_autoptr (GOutputStream) stream = NULL;
|
g_autoptr (GOutputStream) stream = NULL;
|
||||||
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
||||||
g_autofree char *creation_time = NULL;
|
g_autofree char *creation_time = NULL;
|
||||||
@ -295,18 +285,16 @@ write_screenshot_thread (GTask *result,
|
|||||||
|
|
||||||
g_assert (screenshot != NULL);
|
g_assert (screenshot != NULL);
|
||||||
|
|
||||||
priv = screenshot->priv;
|
stream = g_object_ref (screenshot->stream);
|
||||||
|
|
||||||
stream = g_object_ref (priv->stream);
|
pixbuf = util_pixbuf_from_surface (screenshot->image,
|
||||||
|
|
||||||
pixbuf = util_pixbuf_from_surface (priv->image,
|
|
||||||
0, 0,
|
0, 0,
|
||||||
cairo_image_surface_get_width (priv->image),
|
cairo_image_surface_get_width (screenshot->image),
|
||||||
cairo_image_surface_get_height (priv->image));
|
cairo_image_surface_get_height (screenshot->image));
|
||||||
creation_time = g_date_time_format (priv->datetime, "%c");
|
creation_time = g_date_time_format (screenshot->datetime, "%c");
|
||||||
|
|
||||||
if (!creation_time)
|
if (!creation_time)
|
||||||
creation_time = g_date_time_format (priv->datetime, "%FT%T%z");
|
creation_time = g_date_time_format (screenshot->datetime, "%FT%T%z");
|
||||||
|
|
||||||
gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, &error,
|
gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, &error,
|
||||||
"tEXt::Software", "gnome-screenshot",
|
"tEXt::Software", "gnome-screenshot",
|
||||||
@ -327,8 +315,7 @@ do_grab_screenshot (ShellScreenshot *screenshot,
|
|||||||
int height,
|
int height,
|
||||||
ShellScreenshotFlag flags)
|
ShellScreenshotFlag flags)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
ClutterStage *stage = shell_global_get_stage (screenshot->global);
|
||||||
ClutterStage *stage = shell_global_get_stage (priv->global);
|
|
||||||
MtkRectangle screenshot_rect = { x, y, width, height };
|
MtkRectangle screenshot_rect = { x, y, width, height };
|
||||||
int image_width;
|
int image_width;
|
||||||
int image_height;
|
int image_height;
|
||||||
@ -360,9 +347,9 @@ do_grab_screenshot (ShellScreenshot *screenshot,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->image = image;
|
screenshot->image = image;
|
||||||
|
|
||||||
priv->datetime = g_date_time_new_now_local ();
|
screenshot->datetime = g_date_time_new_now_local ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -442,22 +429,21 @@ grab_screenshot (ShellScreenshot *screenshot,
|
|||||||
ShellScreenshotFlag flags,
|
ShellScreenshotFlag flags,
|
||||||
GTask *result)
|
GTask *result)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
||||||
MetaDisplay *display;
|
MetaDisplay *display;
|
||||||
int width, height;
|
int width, height;
|
||||||
GTask *task;
|
GTask *task;
|
||||||
|
|
||||||
display = shell_global_get_display (priv->global);
|
display = shell_global_get_display (screenshot->global);
|
||||||
meta_display_get_size (display, &width, &height);
|
meta_display_get_size (display, &width, &height);
|
||||||
|
|
||||||
do_grab_screenshot (screenshot,
|
do_grab_screenshot (screenshot,
|
||||||
0, 0, width, height,
|
0, 0, width, height,
|
||||||
flags);
|
flags);
|
||||||
|
|
||||||
priv->screenshot_area.x = 0;
|
screenshot->screenshot_area.x = 0;
|
||||||
priv->screenshot_area.y = 0;
|
screenshot->screenshot_area.y = 0;
|
||||||
priv->screenshot_area.width = width;
|
screenshot->screenshot_area.width = width;
|
||||||
priv->screenshot_area.height = height;
|
screenshot->screenshot_area.height = height;
|
||||||
|
|
||||||
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
||||||
g_task_run_in_thread (task, write_screenshot_thread);
|
g_task_run_in_thread (task, write_screenshot_thread);
|
||||||
@ -468,7 +454,6 @@ static void
|
|||||||
grab_screenshot_content (ShellScreenshot *screenshot,
|
grab_screenshot_content (ShellScreenshot *screenshot,
|
||||||
GTask *result)
|
GTask *result)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
||||||
MetaDisplay *display;
|
MetaDisplay *display;
|
||||||
int width, height;
|
int width, height;
|
||||||
MtkRectangle screenshot_rect;
|
MtkRectangle screenshot_rect;
|
||||||
@ -483,7 +468,7 @@ grab_screenshot_content (ShellScreenshot *screenshot,
|
|||||||
CoglTexture *cursor_texture;
|
CoglTexture *cursor_texture;
|
||||||
int cursor_hot_x, cursor_hot_y;
|
int cursor_hot_x, cursor_hot_y;
|
||||||
|
|
||||||
display = shell_global_get_display (priv->global);
|
display = shell_global_get_display (screenshot->global);
|
||||||
meta_display_get_size (display, &width, &height);
|
meta_display_get_size (display, &width, &height);
|
||||||
screenshot_rect = (MtkRectangle) {
|
screenshot_rect = (MtkRectangle) {
|
||||||
.x = 0,
|
.x = 0,
|
||||||
@ -492,14 +477,14 @@ grab_screenshot_content (ShellScreenshot *screenshot,
|
|||||||
.height = height,
|
.height = height,
|
||||||
};
|
};
|
||||||
|
|
||||||
stage = shell_global_get_stage (priv->global);
|
stage = shell_global_get_stage (screenshot->global);
|
||||||
|
|
||||||
clutter_stage_get_capture_final_size (stage, &screenshot_rect,
|
clutter_stage_get_capture_final_size (stage, &screenshot_rect,
|
||||||
&image_width,
|
&image_width,
|
||||||
&image_height,
|
&image_height,
|
||||||
&scale);
|
&scale);
|
||||||
|
|
||||||
priv->scale = scale;
|
screenshot->scale = scale;
|
||||||
|
|
||||||
content = clutter_stage_paint_to_content (stage, &screenshot_rect, scale,
|
content = clutter_stage_paint_to_content (stage, &screenshot_rect, scale,
|
||||||
CLUTTER_PAINT_FLAG_NO_CURSORS,
|
CLUTTER_PAINT_FLAG_NO_CURSORS,
|
||||||
@ -545,21 +530,21 @@ grab_screenshot_content (ShellScreenshot *screenshot,
|
|||||||
g_object_unref (pipeline);
|
g_object_unref (pipeline);
|
||||||
g_object_unref (offscreen);
|
g_object_unref (offscreen);
|
||||||
|
|
||||||
priv->cursor_content =
|
screenshot->cursor_content =
|
||||||
clutter_texture_content_new_from_texture (texture, NULL);
|
clutter_texture_content_new_from_texture (texture, NULL);
|
||||||
g_object_unref (texture);
|
g_object_unref (texture);
|
||||||
|
|
||||||
priv->cursor_scale = meta_cursor_tracker_get_scale (tracker);
|
screenshot->cursor_scale = meta_cursor_tracker_get_scale (tracker);
|
||||||
|
|
||||||
meta_cursor_tracker_get_pointer (tracker, &priv->cursor_point, NULL);
|
meta_cursor_tracker_get_pointer (tracker, &screenshot->cursor_point, NULL);
|
||||||
|
|
||||||
view = clutter_stage_get_view_at (stage,
|
view = clutter_stage_get_view_at (stage,
|
||||||
priv->cursor_point.x,
|
screenshot->cursor_point.x,
|
||||||
priv->cursor_point.y);
|
screenshot->cursor_point.y);
|
||||||
|
|
||||||
meta_cursor_tracker_get_hot (tracker, &cursor_hot_x, &cursor_hot_y);
|
meta_cursor_tracker_get_hot (tracker, &cursor_hot_x, &cursor_hot_y);
|
||||||
priv->cursor_point.x -= cursor_hot_x * priv->cursor_scale;
|
screenshot->cursor_point.x -= cursor_hot_x * screenshot->cursor_scale;
|
||||||
priv->cursor_point.y -= cursor_hot_y * priv->cursor_scale;
|
screenshot->cursor_point.y -= cursor_hot_y * screenshot->cursor_scale;
|
||||||
|
|
||||||
// Align the coordinates to the pixel grid the same way it's done in
|
// Align the coordinates to the pixel grid the same way it's done in
|
||||||
// MetaCursorRenderer.
|
// MetaCursorRenderer.
|
||||||
@ -571,16 +556,16 @@ grab_screenshot_content (ShellScreenshot *screenshot,
|
|||||||
clutter_stage_view_get_layout (view, &view_layout);
|
clutter_stage_view_get_layout (view, &view_layout);
|
||||||
view_scale = clutter_stage_view_get_scale (view);
|
view_scale = clutter_stage_view_get_scale (view);
|
||||||
|
|
||||||
priv->cursor_point.x -= view_layout.x;
|
screenshot->cursor_point.x -= view_layout.x;
|
||||||
priv->cursor_point.y -= view_layout.y;
|
screenshot->cursor_point.y -= view_layout.y;
|
||||||
|
|
||||||
priv->cursor_point.x =
|
screenshot->cursor_point.x =
|
||||||
floorf (priv->cursor_point.x * view_scale) / view_scale;
|
floorf (screenshot->cursor_point.x * view_scale) / view_scale;
|
||||||
priv->cursor_point.y =
|
screenshot->cursor_point.y =
|
||||||
floorf (priv->cursor_point.y * view_scale) / view_scale;
|
floorf (screenshot->cursor_point.y * view_scale) / view_scale;
|
||||||
|
|
||||||
priv->cursor_point.x += view_layout.x;
|
screenshot->cursor_point.x += view_layout.x;
|
||||||
priv->cursor_point.y += view_layout.y;
|
screenshot->cursor_point.y += view_layout.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,9 +577,8 @@ grab_window_screenshot (ShellScreenshot *screenshot,
|
|||||||
ShellScreenshotFlag flags,
|
ShellScreenshotFlag flags,
|
||||||
GTask *result)
|
GTask *result)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
||||||
GTask *task;
|
GTask *task;
|
||||||
MetaDisplay *display = shell_global_get_display (priv->global);
|
MetaDisplay *display = shell_global_get_display (screenshot->global);
|
||||||
MetaWindow *window = meta_display_get_focus_window (display);
|
MetaWindow *window = meta_display_get_focus_window (display);
|
||||||
ClutterActor *window_actor;
|
ClutterActor *window_actor;
|
||||||
gfloat actor_x, actor_y;
|
gfloat actor_x, actor_y;
|
||||||
@ -605,15 +589,15 @@ grab_window_screenshot (ShellScreenshot *screenshot,
|
|||||||
|
|
||||||
meta_window_get_frame_rect (window, &rect);
|
meta_window_get_frame_rect (window, &rect);
|
||||||
|
|
||||||
if (!priv->include_frame)
|
if (!screenshot->include_frame)
|
||||||
meta_window_frame_rect_to_client_rect (window, &rect, &rect);
|
meta_window_frame_rect_to_client_rect (window, &rect, &rect);
|
||||||
|
|
||||||
priv->screenshot_area = rect;
|
screenshot->screenshot_area = rect;
|
||||||
|
|
||||||
priv->image = meta_window_actor_get_image (META_WINDOW_ACTOR (window_actor),
|
screenshot->image = meta_window_actor_get_image (META_WINDOW_ACTOR (window_actor),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!priv->image)
|
if (!screenshot->image)
|
||||||
{
|
{
|
||||||
g_task_report_new_error (screenshot, on_screenshot_written, result, NULL,
|
g_task_report_new_error (screenshot, on_screenshot_written, result, NULL,
|
||||||
G_IO_ERROR, G_IO_ERROR_FAILED,
|
G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
@ -621,7 +605,7 @@ grab_window_screenshot (ShellScreenshot *screenshot,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->datetime = g_date_time_new_now_local ();
|
screenshot->datetime = g_date_time_new_now_local ();
|
||||||
|
|
||||||
if (flags & SHELL_SCREENSHOT_FLAG_INCLUDE_CURSOR)
|
if (flags & SHELL_SCREENSHOT_FLAG_INCLUDE_CURSOR)
|
||||||
{
|
{
|
||||||
@ -630,10 +614,10 @@ grab_window_screenshot (ShellScreenshot *screenshot,
|
|||||||
float resource_scale;
|
float resource_scale;
|
||||||
resource_scale = clutter_actor_get_resource_scale (window_actor);
|
resource_scale = clutter_actor_get_resource_scale (window_actor);
|
||||||
|
|
||||||
cairo_surface_set_device_scale (priv->image, resource_scale, resource_scale);
|
cairo_surface_set_device_scale (screenshot->image, resource_scale, resource_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_cursor_image (priv->image, priv->screenshot_area);
|
draw_cursor_image (screenshot->image, screenshot->screenshot_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0, &rect);
|
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0, &rect);
|
||||||
@ -649,13 +633,11 @@ finish_screenshot (ShellScreenshot *screenshot,
|
|||||||
MtkRectangle **area,
|
MtkRectangle **area,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
||||||
|
|
||||||
if (!g_task_propagate_boolean (G_TASK (result), error))
|
if (!g_task_propagate_boolean (G_TASK (result), error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (area)
|
if (area)
|
||||||
*area = &priv->screenshot_area;
|
*area = &screenshot->screenshot_area;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -667,31 +649,30 @@ on_after_paint (ClutterStage *stage,
|
|||||||
GTask *result)
|
GTask *result)
|
||||||
{
|
{
|
||||||
ShellScreenshot *screenshot = g_task_get_task_data (result);
|
ShellScreenshot *screenshot = g_task_get_task_data (result);
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
MetaDisplay *display = shell_global_get_display (screenshot->global);
|
||||||
MetaDisplay *display = shell_global_get_display (priv->global);
|
|
||||||
GTask *task;
|
GTask *task;
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (stage, on_after_paint, result);
|
g_signal_handlers_disconnect_by_func (stage, on_after_paint, result);
|
||||||
|
|
||||||
if (priv->mode == SHELL_SCREENSHOT_AREA)
|
if (screenshot->mode == SHELL_SCREENSHOT_AREA)
|
||||||
{
|
{
|
||||||
do_grab_screenshot (screenshot,
|
do_grab_screenshot (screenshot,
|
||||||
priv->screenshot_area.x,
|
screenshot->screenshot_area.x,
|
||||||
priv->screenshot_area.y,
|
screenshot->screenshot_area.y,
|
||||||
priv->screenshot_area.width,
|
screenshot->screenshot_area.width,
|
||||||
priv->screenshot_area.height,
|
screenshot->screenshot_area.height,
|
||||||
priv->flags);
|
screenshot->flags);
|
||||||
|
|
||||||
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
||||||
g_task_run_in_thread (task, write_screenshot_thread);
|
g_task_run_in_thread (task, write_screenshot_thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
grab_screenshot (screenshot, priv->flags, result);
|
grab_screenshot (screenshot, screenshot->flags, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0,
|
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0,
|
||||||
(MtkRectangle *) &priv->screenshot_area);
|
(MtkRectangle *) &screenshot->screenshot_area);
|
||||||
|
|
||||||
meta_enable_unredirect_for_display (display);
|
meta_enable_unredirect_for_display (display);
|
||||||
}
|
}
|
||||||
@ -716,16 +697,13 @@ shell_screenshot_screenshot (ShellScreenshot *screenshot,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
GTask *result;
|
GTask *result;
|
||||||
ShellScreenshotFlag flags;
|
ShellScreenshotFlag flags;
|
||||||
|
|
||||||
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
||||||
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
||||||
|
|
||||||
priv = screenshot->priv;
|
if (screenshot->stream != NULL) {
|
||||||
|
|
||||||
if (priv->stream != NULL) {
|
|
||||||
if (callback)
|
if (callback)
|
||||||
g_task_report_new_error (screenshot,
|
g_task_report_new_error (screenshot,
|
||||||
callback,
|
callback,
|
||||||
@ -742,7 +720,7 @@ shell_screenshot_screenshot (ShellScreenshot *screenshot,
|
|||||||
g_task_set_source_tag (result, shell_screenshot_screenshot);
|
g_task_set_source_tag (result, shell_screenshot_screenshot);
|
||||||
g_task_set_task_data (result, screenshot, NULL);
|
g_task_set_task_data (result, screenshot, NULL);
|
||||||
|
|
||||||
priv->stream = g_object_ref (stream);
|
screenshot->stream = g_object_ref (stream);
|
||||||
|
|
||||||
flags = SHELL_SCREENSHOT_FLAG_NONE;
|
flags = SHELL_SCREENSHOT_FLAG_NONE;
|
||||||
if (include_cursor)
|
if (include_cursor)
|
||||||
@ -753,17 +731,17 @@ shell_screenshot_screenshot (ShellScreenshot *screenshot,
|
|||||||
grab_screenshot (screenshot, flags, result);
|
grab_screenshot (screenshot, flags, result);
|
||||||
|
|
||||||
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0,
|
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0,
|
||||||
(MtkRectangle *) &priv->screenshot_area);
|
(MtkRectangle *) &screenshot->screenshot_area);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MetaDisplay *display = shell_global_get_display (priv->global);
|
MetaDisplay *display = shell_global_get_display (screenshot->global);
|
||||||
ClutterStage *stage = shell_global_get_stage (priv->global);
|
ClutterStage *stage = shell_global_get_stage (screenshot->global);
|
||||||
|
|
||||||
meta_disable_unredirect_for_display (display);
|
meta_disable_unredirect_for_display (display);
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
||||||
priv->flags = flags;
|
screenshot->flags = flags;
|
||||||
priv->mode = SHELL_SCREENSHOT_SCREEN;
|
screenshot->mode = SHELL_SCREENSHOT_SCREEN;
|
||||||
g_signal_connect (stage, "after-paint",
|
g_signal_connect (stage, "after-paint",
|
||||||
G_CALLBACK (on_after_paint), result);
|
G_CALLBACK (on_after_paint), result);
|
||||||
}
|
}
|
||||||
@ -803,8 +781,7 @@ screenshot_stage_to_content_on_after_paint (ClutterStage *stage,
|
|||||||
GTask *result)
|
GTask *result)
|
||||||
{
|
{
|
||||||
ShellScreenshot *screenshot = g_task_get_task_data (result);
|
ShellScreenshot *screenshot = g_task_get_task_data (result);
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
MetaDisplay *display = shell_global_get_display (screenshot->global);
|
||||||
MetaDisplay *display = shell_global_get_display (priv->global);
|
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (stage,
|
g_signal_handlers_disconnect_by_func (stage,
|
||||||
screenshot_stage_to_content_on_after_paint,
|
screenshot_stage_to_content_on_after_paint,
|
||||||
@ -830,7 +807,6 @@ shell_screenshot_screenshot_stage_to_content (ShellScreenshot *screenshot,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
GTask *result;
|
GTask *result;
|
||||||
|
|
||||||
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
||||||
@ -845,10 +821,8 @@ shell_screenshot_screenshot_stage_to_content (ShellScreenshot *screenshot,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
priv = screenshot->priv;
|
MetaDisplay *display = shell_global_get_display (screenshot->global);
|
||||||
|
ClutterStage *stage = shell_global_get_stage (screenshot->global);
|
||||||
MetaDisplay *display = shell_global_get_display (priv->global);
|
|
||||||
ClutterStage *stage = shell_global_get_stage (priv->global);
|
|
||||||
|
|
||||||
meta_disable_unredirect_for_display (display);
|
meta_disable_unredirect_for_display (display);
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
||||||
@ -884,7 +858,6 @@ shell_screenshot_screenshot_stage_to_content_finish (ShellScreenshot *screensh
|
|||||||
float *cursor_scale,
|
float *cursor_scale,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
||||||
ClutterContent *content;
|
ClutterContent *content;
|
||||||
|
|
||||||
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
|
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
|
||||||
@ -898,18 +871,18 @@ shell_screenshot_screenshot_stage_to_content_finish (ShellScreenshot *screensh
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (scale)
|
if (scale)
|
||||||
*scale = priv->scale;
|
*scale = screenshot->scale;
|
||||||
|
|
||||||
if (cursor_content)
|
if (cursor_content)
|
||||||
*cursor_content = g_steal_pointer (&priv->cursor_content);
|
*cursor_content = g_steal_pointer (&screenshot->cursor_content);
|
||||||
else
|
else
|
||||||
g_clear_pointer (&priv->cursor_content, g_object_unref);
|
g_clear_pointer (&screenshot->cursor_content, g_object_unref);
|
||||||
|
|
||||||
if (cursor_point)
|
if (cursor_point)
|
||||||
*cursor_point = priv->cursor_point;
|
*cursor_point = screenshot->cursor_point;
|
||||||
|
|
||||||
if (cursor_scale)
|
if (cursor_scale)
|
||||||
*cursor_scale = priv->cursor_scale;
|
*cursor_scale = screenshot->cursor_scale;
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
@ -940,16 +913,13 @@ shell_screenshot_screenshot_area (ShellScreenshot *screenshot,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
GTask *result;
|
GTask *result;
|
||||||
g_autoptr (GTask) task = NULL;
|
g_autoptr (GTask) task = NULL;
|
||||||
|
|
||||||
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
||||||
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
||||||
|
|
||||||
priv = screenshot->priv;
|
if (screenshot->stream != NULL) {
|
||||||
|
|
||||||
if (priv->stream != NULL) {
|
|
||||||
if (callback)
|
if (callback)
|
||||||
g_task_report_new_error (screenshot,
|
g_task_report_new_error (screenshot,
|
||||||
callback,
|
callback,
|
||||||
@ -966,37 +936,37 @@ shell_screenshot_screenshot_area (ShellScreenshot *screenshot,
|
|||||||
g_task_set_source_tag (result, shell_screenshot_screenshot_area);
|
g_task_set_source_tag (result, shell_screenshot_screenshot_area);
|
||||||
g_task_set_task_data (result, screenshot, NULL);
|
g_task_set_task_data (result, screenshot, NULL);
|
||||||
|
|
||||||
priv->stream = g_object_ref (stream);
|
screenshot->stream = g_object_ref (stream);
|
||||||
priv->screenshot_area.x = x;
|
screenshot->screenshot_area.x = x;
|
||||||
priv->screenshot_area.y = y;
|
screenshot->screenshot_area.y = y;
|
||||||
priv->screenshot_area.width = width;
|
screenshot->screenshot_area.width = width;
|
||||||
priv->screenshot_area.height = height;
|
screenshot->screenshot_area.height = height;
|
||||||
|
|
||||||
|
|
||||||
if (meta_is_wayland_compositor ())
|
if (meta_is_wayland_compositor ())
|
||||||
{
|
{
|
||||||
do_grab_screenshot (screenshot,
|
do_grab_screenshot (screenshot,
|
||||||
priv->screenshot_area.x,
|
screenshot->screenshot_area.x,
|
||||||
priv->screenshot_area.y,
|
screenshot->screenshot_area.y,
|
||||||
priv->screenshot_area.width,
|
screenshot->screenshot_area.width,
|
||||||
priv->screenshot_area.height,
|
screenshot->screenshot_area.height,
|
||||||
SHELL_SCREENSHOT_FLAG_NONE);
|
SHELL_SCREENSHOT_FLAG_NONE);
|
||||||
|
|
||||||
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0,
|
g_signal_emit (screenshot, signals[SCREENSHOT_TAKEN], 0,
|
||||||
(MtkRectangle *) &priv->screenshot_area);
|
(MtkRectangle *) &screenshot->screenshot_area);
|
||||||
|
|
||||||
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
||||||
g_task_run_in_thread (task, write_screenshot_thread);
|
g_task_run_in_thread (task, write_screenshot_thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MetaDisplay *display = shell_global_get_display (priv->global);
|
MetaDisplay *display = shell_global_get_display (screenshot->global);
|
||||||
ClutterStage *stage = shell_global_get_stage (priv->global);
|
ClutterStage *stage = shell_global_get_stage (screenshot->global);
|
||||||
|
|
||||||
meta_disable_unredirect_for_display (display);
|
meta_disable_unredirect_for_display (display);
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
||||||
priv->flags = SHELL_SCREENSHOT_FLAG_NONE;
|
screenshot->flags = SHELL_SCREENSHOT_FLAG_NONE;
|
||||||
priv->mode = SHELL_SCREENSHOT_AREA;
|
screenshot->mode = SHELL_SCREENSHOT_AREA;
|
||||||
g_signal_connect (stage, "after-paint",
|
g_signal_connect (stage, "after-paint",
|
||||||
G_CALLBACK (on_after_paint), result);
|
G_CALLBACK (on_after_paint), result);
|
||||||
}
|
}
|
||||||
@ -1051,7 +1021,6 @@ shell_screenshot_screenshot_window (ShellScreenshot *screenshot,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
MetaDisplay *display;
|
MetaDisplay *display;
|
||||||
MetaWindow *window;
|
MetaWindow *window;
|
||||||
GTask *result;
|
GTask *result;
|
||||||
@ -1059,11 +1028,10 @@ shell_screenshot_screenshot_window (ShellScreenshot *screenshot,
|
|||||||
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
||||||
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
||||||
|
|
||||||
priv = screenshot->priv;
|
display = shell_global_get_display (screenshot->global);
|
||||||
display = shell_global_get_display (priv->global);
|
|
||||||
window = meta_display_get_focus_window (display);
|
window = meta_display_get_focus_window (display);
|
||||||
|
|
||||||
if (priv->stream != NULL || !window) {
|
if (screenshot->stream != NULL || !window) {
|
||||||
if (callback)
|
if (callback)
|
||||||
g_task_report_new_error (screenshot,
|
g_task_report_new_error (screenshot,
|
||||||
callback,
|
callback,
|
||||||
@ -1079,8 +1047,8 @@ shell_screenshot_screenshot_window (ShellScreenshot *screenshot,
|
|||||||
result = g_task_new (screenshot, NULL, callback, user_data);
|
result = g_task_new (screenshot, NULL, callback, user_data);
|
||||||
g_task_set_source_tag (result, shell_screenshot_screenshot_window);
|
g_task_set_source_tag (result, shell_screenshot_screenshot_window);
|
||||||
|
|
||||||
priv->stream = g_object_ref (stream);
|
screenshot->stream = g_object_ref (stream);
|
||||||
priv->include_frame = include_frame;
|
screenshot->include_frame = include_frame;
|
||||||
|
|
||||||
grab_window_screenshot (screenshot, include_cursor, result);
|
grab_window_screenshot (screenshot, include_cursor, result);
|
||||||
}
|
}
|
||||||
@ -1130,7 +1098,6 @@ shell_screenshot_pick_color (ShellScreenshot *screenshot,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
g_autoptr (GTask) result = NULL;
|
g_autoptr (GTask) result = NULL;
|
||||||
|
|
||||||
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
g_return_if_fail (SHELL_IS_SCREENSHOT (screenshot));
|
||||||
@ -1138,16 +1105,14 @@ shell_screenshot_pick_color (ShellScreenshot *screenshot,
|
|||||||
result = g_task_new (screenshot, NULL, callback, user_data);
|
result = g_task_new (screenshot, NULL, callback, user_data);
|
||||||
g_task_set_source_tag (result, shell_screenshot_pick_color);
|
g_task_set_source_tag (result, shell_screenshot_pick_color);
|
||||||
|
|
||||||
priv = screenshot->priv;
|
screenshot->screenshot_area.x = x;
|
||||||
|
screenshot->screenshot_area.y = y;
|
||||||
priv->screenshot_area.x = x;
|
screenshot->screenshot_area.width = 1;
|
||||||
priv->screenshot_area.y = y;
|
screenshot->screenshot_area.height = 1;
|
||||||
priv->screenshot_area.width = 1;
|
|
||||||
priv->screenshot_area.height = 1;
|
|
||||||
|
|
||||||
do_grab_screenshot (screenshot,
|
do_grab_screenshot (screenshot,
|
||||||
priv->screenshot_area.x,
|
screenshot->screenshot_area.x,
|
||||||
priv->screenshot_area.y,
|
screenshot->screenshot_area.y,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
SHELL_SCREENSHOT_FLAG_NONE);
|
SHELL_SCREENSHOT_FLAG_NONE);
|
||||||
@ -1186,8 +1151,6 @@ shell_screenshot_pick_color_finish (ShellScreenshot *screenshot,
|
|||||||
CoglColor *color,
|
CoglColor *color,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
ShellScreenshotPrivate *priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
|
g_return_val_if_fail (SHELL_IS_SCREENSHOT (screenshot), FALSE);
|
||||||
g_return_val_if_fail (G_IS_TASK (result), FALSE);
|
g_return_val_if_fail (G_IS_TASK (result), FALSE);
|
||||||
g_return_val_if_fail (color != NULL, FALSE);
|
g_return_val_if_fail (color != NULL, FALSE);
|
||||||
@ -1198,14 +1161,12 @@ shell_screenshot_pick_color_finish (ShellScreenshot *screenshot,
|
|||||||
if (!g_task_propagate_boolean (G_TASK (result), error))
|
if (!g_task_propagate_boolean (G_TASK (result), error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
priv = screenshot->priv;
|
|
||||||
|
|
||||||
/* protect against mutter changing the format used for stage captures */
|
/* protect against mutter changing the format used for stage captures */
|
||||||
g_assert (cairo_image_surface_get_format (priv->image) == CAIRO_FORMAT_ARGB32);
|
g_assert (cairo_image_surface_get_format (screenshot->image) == CAIRO_FORMAT_ARGB32);
|
||||||
|
|
||||||
if (color)
|
if (color)
|
||||||
{
|
{
|
||||||
uint8_t *data = cairo_image_surface_get_data (priv->image);
|
uint8_t *data = cairo_image_surface_get_data (screenshot->image);
|
||||||
|
|
||||||
color->alpha = data[INDEX_A];
|
color->alpha = data[INDEX_A];
|
||||||
color->red = data[INDEX_R];
|
color->red = data[INDEX_R];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user