From ceb9747e2309fdd8dfee0730a9fe0775a165f500 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Mon, 10 Jun 2024 13:47:25 +0000 Subject: [PATCH] libgimpwidgets: New API to check system animation status Ports the animation code started in e13cc635 to an independent gimp_widget_animation_enabled() function. This allows plug-in authors to also conditionally turn off animations if the user's system settings say to do so. The function is applied to the About Dialogue animation as well as two Easter Egg animations: * Wilber's eyes blinking after 23 minutes on an empty canvas * Wilber's eyes following the mouse after a certain sequence of tools is clicked --- app/dialogs/about-dialog.c | 25 +------------------ app/display/gimpdisplayshell.c | 7 ++++-- app/tools/tool_manager.c | 8 +++++-- libgimpwidgets/gimpwidgets.def | 1 + libgimpwidgets/gimpwidgetsutils.c | 40 +++++++++++++++++++++++++++++++ libgimpwidgets/gimpwidgetsutils.h | 2 ++ 6 files changed, 55 insertions(+), 28 deletions(-) diff --git a/app/dialogs/about-dialog.c b/app/dialogs/about-dialog.c index 0a7e5902c1..49545d44ab 100644 --- a/app/dialogs/about-dialog.c +++ b/app/dialogs/about-dialog.c @@ -42,14 +42,6 @@ #include "gimp-intl.h" -#ifdef PLATFORM_OSX -#import -#endif - -#ifdef G_OS_WIN32 -#include -#endif - /* The first authors are the creators and maintainers, don't shuffle * them @@ -141,22 +133,7 @@ about_dialog_create (Gimp *gimp, * list. This is redundant anyway as the full list is available in * the Credits tab. */ - g_object_get (gtk_settings_get_default (), - "gtk-enable-animations", &dialog.use_animation, - NULL); - - /* gtk-enable-animation does not currently respect system settings by - * different operating systems. This check can be removed once that - * support is added in GTK. - */ -#ifdef PLATFORM_OSX - dialog.use_animation = - ! ([[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion]); -#endif -#ifdef G_OS_WIN32 - SystemParametersInfo (SPI_GETCLIENTAREAANIMATION, 0x00, - &dialog.use_animation, 0x00); -#endif + dialog.use_animation = gimp_widget_animation_enabled (); pixbuf = about_dialog_load_logo (); diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 634bd7ae6c..8838b0ccc6 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -1504,8 +1504,11 @@ gimp_display_shell_empty (GimpDisplayShell *shell) if (shell->display == gimp_context_get_display (user_context)) gimp_ui_manager_update (shell->popup_manager, shell->display); - shell->blink_timeout_id = - g_timeout_add (1403230, (GSourceFunc) gimp_display_shell_blink, shell); + if (gimp_widget_animation_enabled ()) + { + shell->blink_timeout_id = + g_timeout_add (1403230, (GSourceFunc) gimp_display_shell_blink, shell); + } } static gboolean diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c index 008db89e97..a9217814c5 100644 --- a/app/tools/tool_manager.c +++ b/app/tools/tool_manager.c @@ -23,6 +23,7 @@ #include #include "libgimpconfig/gimpconfig.h" +#include "libgimpwidgets/gimpwidgets.h" #include "tools-types.h" @@ -776,8 +777,11 @@ tool_manager_tool_changed (GimpContext *user_context, g_object_unref (new_tool); - /* ??? */ - tool_manager_cast_spell (tool_info); + if (gimp_widget_animation_enabled ()) + { + /* ??? */ + tool_manager_cast_spell (tool_info); + } } static void diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def index c409a6a249..ab884f905f 100644 --- a/libgimpwidgets/gimpwidgets.def +++ b/libgimpwidgets/gimpwidgets.def @@ -501,6 +501,7 @@ EXPORTS gimp_unit_store_set_pixel_values gimp_unit_store_set_resolution gimp_unit_store_set_resolutions + gimp_widget_animation_enabled gimp_widget_get_color_profile gimp_widget_get_color_transform gimp_widget_get_monitor diff --git a/libgimpwidgets/gimpwidgetsutils.c b/libgimpwidgets/gimpwidgetsutils.c index 38133a3a19..c318ef586b 100644 --- a/libgimpwidgets/gimpwidgetsutils.c +++ b/libgimpwidgets/gimpwidgetsutils.c @@ -46,6 +46,9 @@ #include #include #endif +#ifdef PLATFORM_OSX +#import +#endif #include "libgimpcolor/gimpcolor.h" #include "libgimpconfig/gimpconfig.h" @@ -1159,6 +1162,43 @@ gimp_widget_set_native_handle (GtkWidget *widget, gimp_widget_set_handle_on_mapped (widget, NULL, handle); } +/** + * gimp_widget_animation_enabled: + * + * This function attempts to read the user's system preference for + * showing animation. It can be used to turn off or hide unnecessary + * animations such as the scrolling credits or Easter Egg animations. + * + * Returns: %TRUE if the user has animations enabled on their system + * + * Since: 3.0 + */ +gboolean +gimp_widget_animation_enabled (void) +{ + gboolean animation_enabled = TRUE; + + /* Per Luca Bacci, KDE syncs their animation setting with GTK. See + * https://invent.kde.org/plasma/kde-gtk-config/-/blob/v6.0.90/kded/gtkconfig.cpp?ref_type=tags#L232 + */ + g_object_get (gtk_settings_get_default (), + "gtk-enable-animations", &animation_enabled, + NULL); + +#ifdef PLATFORM_OSX + /* The MacOS setting is TRUE if the user wants animations turned off, so + * we invert it to match the format of the other platforms */ + animation_enabled = + ! ([[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion]); +#endif +#ifdef G_OS_WIN32 + SystemParametersInfo (SPI_GETCLIENTAREAANIMATION, 0x00, &animation_enabled, + 0x00); +#endif + + return animation_enabled; +} + /* Internal functions */ diff --git a/libgimpwidgets/gimpwidgetsutils.h b/libgimpwidgets/gimpwidgetsutils.h index 5bdaba4d27..85f1dc2c5e 100644 --- a/libgimpwidgets/gimpwidgetsutils.h +++ b/libgimpwidgets/gimpwidgetsutils.h @@ -70,6 +70,8 @@ const Babl * gimp_widget_get_render_space (GtkWidget *widget, void gimp_widget_set_native_handle (GtkWidget *widget, GBytes **handle); +gboolean gimp_widget_animation_enabled (void); + /* Internal use */ G_GNUC_INTERNAL void _gimp_widget_get_profiles (GtkWidget *widget,