shell-screenshot: Add utility function to check when draw the cursor

Don't repeat the same logic in multiple places, just set include_cursor to the
proper value once depending on the settings we have.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/5
This commit is contained in:
Marco Trevisan (Treviño) 2019-02-13 02:13:47 +01:00 committed by Jonas Ådahl
parent 02c3980b83
commit 559ec8750a

View File

@ -256,6 +256,17 @@ do_grab_screenshot (ShellScreenshot *screenshot,
g_free (captures); g_free (captures);
} }
static gboolean
should_draw_cursor_image (void)
{
g_autoptr (GSettings) settings = g_settings_new (A11Y_APPS_SCHEMA);
if (!g_settings_get_boolean (settings, MAGNIFIER_ACTIVE_KEY))
return TRUE;
return FALSE;
}
static void static void
draw_cursor_image (cairo_surface_t *surface, draw_cursor_image (cairo_surface_t *surface,
cairo_rectangle_int_t area) cairo_rectangle_int_t area)
@ -321,7 +332,6 @@ grab_screenshot (ClutterActor *stage,
{ {
MetaDisplay *display; MetaDisplay *display;
int width, height; int width, height;
GSettings *settings;
ShellScreenshot *screenshot = g_task_get_source_object (result); ShellScreenshot *screenshot = g_task_get_source_object (result);
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv = screenshot->priv;
GTask *task; GTask *task;
@ -375,13 +385,9 @@ grab_screenshot (ClutterActor *stage,
priv->screenshot_area.width = width; priv->screenshot_area.width = width;
priv->screenshot_area.height = height; priv->screenshot_area.height = height;
settings = g_settings_new (A11Y_APPS_SCHEMA); if (priv->include_cursor)
if (priv->include_cursor &&
!g_settings_get_boolean (settings, MAGNIFIER_ACTIVE_KEY))
draw_cursor_image (priv->image, priv->screenshot_area); draw_cursor_image (priv->image, priv->screenshot_area);
g_object_unref (settings);
g_signal_handlers_disconnect_by_func (stage, grab_screenshot, result); g_signal_handlers_disconnect_by_func (stage, grab_screenshot, result);
task = g_task_new (screenshot, NULL, on_screenshot_written, result); task = g_task_new (screenshot, NULL, on_screenshot_written, result);
@ -417,7 +423,6 @@ grab_window_screenshot (ClutterActor *stage,
ShellScreenshot *screenshot = g_task_get_source_object (result); ShellScreenshot *screenshot = g_task_get_source_object (result);
ShellScreenshotPrivate *priv = screenshot->priv; ShellScreenshotPrivate *priv = screenshot->priv;
GTask *task; GTask *task;
GSettings *settings;
MetaDisplay *display = shell_global_get_display (priv->global); MetaDisplay *display = shell_global_get_display (priv->global);
MetaWindow *window = meta_display_get_focus_window (display); MetaWindow *window = meta_display_get_focus_window (display);
ClutterActor *window_actor; ClutterActor *window_actor;
@ -446,12 +451,9 @@ grab_window_screenshot (ClutterActor *stage,
priv->image = meta_shaped_texture_get_image (stex, &clip); priv->image = meta_shaped_texture_get_image (stex, &clip);
priv->datetime = g_date_time_new_now_local (); priv->datetime = g_date_time_new_now_local ();
settings = g_settings_new (A11Y_APPS_SCHEMA); if (priv->include_cursor)
if (priv->include_cursor && !g_settings_get_boolean (settings, MAGNIFIER_ACTIVE_KEY))
draw_cursor_image (priv->image, priv->screenshot_area); draw_cursor_image (priv->image, priv->screenshot_area);
g_object_unref (settings);
g_signal_handlers_disconnect_by_func (stage, grab_window_screenshot, result); g_signal_handlers_disconnect_by_func (stage, grab_window_screenshot, result);
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);
@ -541,7 +543,7 @@ shell_screenshot_screenshot (ShellScreenshot *screenshot,
g_task_set_source_tag (result, shell_screenshot_screenshot); g_task_set_source_tag (result, shell_screenshot_screenshot);
priv->filename = g_strdup (filename); priv->filename = g_strdup (filename);
priv->include_cursor = include_cursor; priv->include_cursor = include_cursor && should_draw_cursor_image ();
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global)); stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
@ -715,7 +717,7 @@ shell_screenshot_screenshot_window (ShellScreenshot *screenshot,
priv->filename = g_strdup (filename); priv->filename = g_strdup (filename);
priv->include_frame = include_frame; priv->include_frame = include_frame;
priv->include_cursor = include_cursor; priv->include_cursor = include_cursor && should_draw_cursor_image ();
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global)); stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));