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
This commit is contained in:
Alx Sa 2024-06-10 13:47:25 +00:00
parent c02160a949
commit ceb9747e23
6 changed files with 55 additions and 28 deletions

View file

@ -42,14 +42,6 @@
#include "gimp-intl.h"
#ifdef PLATFORM_OSX
#import <Cocoa/Cocoa.h>
#endif
#ifdef G_OS_WIN32
#include <windows.h>
#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 ();

View file

@ -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);
if (gimp_widget_animation_enabled ())
{
shell->blink_timeout_id =
g_timeout_add (1403230, (GSourceFunc) gimp_display_shell_blink, shell);
}
}
static gboolean

View file

@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#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);
if (gimp_widget_animation_enabled ())
{
/* ??? */
tool_manager_cast_spell (tool_info);
}
}
static void

View file

@ -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

View file

@ -46,6 +46,9 @@
#include <ApplicationServices/ApplicationServices.h>
#include <CoreServices/CoreServices.h>
#endif
#ifdef PLATFORM_OSX
#import <Cocoa/Cocoa.h>
#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 */

View file

@ -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,