From 26d1021e77da62b31bab33e65eede061b4db912c Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Thu, 27 Mar 2008 16:30:29 +0000 Subject: [PATCH] Properly pass the focus from the core to plug-in dialogs: 2008-03-27 Sven Neumann Properly pass the focus from the core to plug-in dialogs: * libgimpbase/gimpprotocol.[ch]: added a user_time member to the GimpConfig struct. Bumped the protocol version to 0x0012. * app/core/gimp-gui.[ch] * app/gui/gui-vtable.c: added gimp_get_user_time() to get the timestamp of the last user interaction. * app/plug-in/gimppluginmanager-call.c (gimp_plug_in_manager_call_run): pass the timestamp to in the GimpConfig message. * libgimp/gimp.[ch]: * libgimp/gimp.def: added method to access the timestamp as set in the config message. * libgimp/gimpui.c (gimp_ui_init): construct a fake startup ID and set the DESKTOP_STARTUP_ID environment variable. svn path=/trunk/; revision=25263 --- ChangeLog | 22 ++++++++++++++++++++++ app/core/gimp-gui.c | 22 ++++++++++++++++++++++ app/core/gimp-gui.h | 3 +++ app/gui/gui-vtable.c | 11 +++++++++++ app/plug-in/gimppluginmanager-call.c | 1 + libgimp/gimp.c | 19 +++++++++++++++++++ libgimp/gimp.def | 1 + libgimp/gimp.h | 1 + libgimp/gimpui.c | 13 ++++++++++++- libgimpbase/gimpprotocol.c | 7 +++++++ libgimpbase/gimpprotocol.h | 3 ++- 11 files changed, 101 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8f1b1f7bc..b783dff438 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2008-03-27 Sven Neumann + + Properly pass the focus from the core to plug-in dialogs: + + * libgimpbase/gimpprotocol.[ch]: added a user_time member to the + GimpConfig struct. Bumped the protocol version to 0x0012. + + * app/core/gimp-gui.[ch] + * app/gui/gui-vtable.c: added gimp_get_user_time() to get the + timestamp of the last user interaction. + + * app/plug-in/gimppluginmanager-call.c + (gimp_plug_in_manager_call_run): pass the timestamp to in the + GimpConfig message. + + * libgimp/gimp.[ch]: + * libgimp/gimp.def: added method to access the timestamp as set + in the config message. + + * libgimp/gimpui.c (gimp_ui_init): construct a fake startup ID and + set the DESKTOP_STARTUP_ID environment variable. + 2008-03-27 Sven Neumann * app/widgets/gimpdockable.c (gimp_dockable_detach): open the new diff --git a/app/core/gimp-gui.c b/app/core/gimp-gui.c index 4096c16acd..96c947a6d2 100644 --- a/app/core/gimp-gui.c +++ b/app/core/gimp-gui.c @@ -50,6 +50,7 @@ gimp_gui_init (Gimp *gimp) gimp->gui.help = NULL; gimp->gui.get_program_class = NULL; gimp->gui.get_display_name = NULL; + gimp->gui.get_user_time = NULL; gimp->gui.get_theme_dir = NULL; gimp->gui.display_get_by_id = NULL; gimp->gui.display_get_id = NULL; @@ -226,6 +227,27 @@ gimp_get_display_name (Gimp *gimp, return NULL; } +/** + * gimp_get_user_time: + * @gimp: + * + * Returns the timestamp of the last user interaction. The timestamp is + * taken from events caused by user interaction such as key presses or + * pointer movements. See gdk_x11_display_get_user_time(). + * + * Return value: the timestamp of the last user interaction + */ +guint32 +gimp_get_user_time (Gimp *gimp) +{ + g_return_val_if_fail (GIMP_IS_GIMP (gimp), 0); + + if (gimp->gui.get_user_time) + return gimp->gui.get_user_time (gimp); + + return 0; +} + const gchar * gimp_get_theme_dir (Gimp *gimp) { diff --git a/app/core/gimp-gui.h b/app/core/gimp-gui.h index 533bd0b695..783186dfcd 100644 --- a/app/core/gimp-gui.h +++ b/app/core/gimp-gui.h @@ -45,6 +45,8 @@ struct _GimpGui gchar * (* get_display_name) (Gimp *gimp, gint display_ID, gint *monitor_number); + guint32 (* get_user_time) (Gimp *gimp); + const gchar * (* get_theme_dir) (Gimp *gimp); GimpObject * (* get_empty_display) (Gimp *gimp); @@ -136,6 +138,7 @@ const gchar * gimp_get_program_class (Gimp *gimp); gchar * gimp_get_display_name (Gimp *gimp, gint display_ID, gint *monitor_number); +guint32 gimp_get_user_time (Gimp *gimp); const gchar * gimp_get_theme_dir (Gimp *gimp); gboolean gimp_pdb_dialog_new (Gimp *gimp, diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c index d657838d4c..0a307cc10f 100644 --- a/app/gui/gui-vtable.c +++ b/app/gui/gui-vtable.c @@ -88,6 +88,7 @@ static const gchar * gui_get_program_class (Gimp *gimp); static gchar * gui_get_display_name (Gimp *gimp, gint display_ID, gint *monitor_number); +static guint32 gui_get_user_time (Gimp *gimp); static const gchar * gui_get_theme_dir (Gimp *gimp); static GimpObject * gui_get_empty_display (Gimp *gimp); static GimpObject * gui_display_get_by_ID (Gimp *gimp, @@ -144,6 +145,7 @@ gui_vtable_init (Gimp *gimp) gimp->gui.help = gui_help; gimp->gui.get_program_class = gui_get_program_class; gimp->gui.get_display_name = gui_get_display_name; + gimp->gui.get_user_time = gui_get_user_time; gimp->gui.get_theme_dir = gui_get_theme_dir; gimp->gui.get_empty_display = gui_get_empty_display; gimp->gui.display_get_by_id = gui_display_get_by_ID; @@ -255,6 +257,15 @@ gui_get_display_name (Gimp *gimp, return NULL; } +static guint32 +gui_get_user_time (Gimp *gimp) +{ +#ifdef GDK_WINDOWING_X11 + return gdk_x11_display_get_user_time (gdk_display_get_default ()); +#endif + return 0; +} + static const gchar * gui_get_theme_dir (Gimp *gimp) { diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c index b394eabfdb..1b39ad09a3 100644 --- a/app/plug-in/gimppluginmanager-call.c +++ b/app/plug-in/gimppluginmanager-call.c @@ -197,6 +197,7 @@ gimp_plug_in_manager_call_run (GimpPlugInManager *manager, config.display_name = gimp_get_display_name (manager->gimp, display_ID, &monitor); config.monitor_number = monitor; + config.timestamp = gimp_get_user_time (manager->gimp); proc_run.name = GIMP_PROCEDURE (procedure)->original_name; proc_run.nparams = args->n_values; diff --git a/libgimp/gimp.c b/libgimp/gimp.c index b9ad3dfbba..d9c87a4744 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -179,6 +179,7 @@ static gint _gdisp_ID = -1; static gchar *_wm_class = NULL; static gchar *_display_name = NULL; static gint _monitor_number = 0; +static guint32 _timestamp = 0; static const gchar *progname = NULL; static gchar write_buffer[WRITE_BUFFER_SIZE]; @@ -1222,6 +1223,7 @@ gimp_wm_class (void) * gimp_display_name: * * Returns the display to be used for plug-in windows. + * * This is a constant value given at plug-in configuration time. * * Return value: the display name @@ -1246,6 +1248,22 @@ gimp_monitor_number (void) return _monitor_number; } +/** + * gimp_user_time: + * + * Returns the timestamp of the user interaction that should be set on + * the plug-in window. This is handled transparently. Plug-in authors + * do not have to care about this. This is a constant value given at + * plug-in configuration time. + * + * Return value: timestamp for plug-in window + **/ +guint32 +gimp_user_time (void) +{ + return _timestamp; +} + /** * gimp_get_progname: * @@ -1712,6 +1730,7 @@ gimp_config (GPConfig *config) _wm_class = g_strdup (config->wm_class); _display_name = g_strdup (config->display_name); _monitor_number = config->monitor_number; + _timestamp = config->timestamp; if (config->app_name) g_set_application_name (config->app_name); diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 9c2a1eabeb..c0e4b3fce4 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -619,6 +619,7 @@ EXPORTS gimp_tile_width gimp_transform_2d gimp_uninstall_temp_proc + gimp_user_time gimp_vectors_bezier_stroke_conicto gimp_vectors_bezier_stroke_cubicto gimp_vectors_bezier_stroke_lineto diff --git a/libgimp/gimp.h b/libgimp/gimp.h index e8305319f1..046f520c30 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -321,6 +321,7 @@ gint32 gimp_default_display (void) G_GNUC_CONST; const gchar * gimp_wm_class (void) G_GNUC_CONST; const gchar * gimp_display_name (void) G_GNUC_CONST; gint gimp_monitor_number (void) G_GNUC_CONST; +guint32 gimp_user_time (void) G_GNUC_CONST; const gchar * gimp_get_progname (void) G_GNUC_CONST; diff --git a/libgimp/gimpui.c b/libgimp/gimpui.c index 5186fbfb29..d6b375434b 100644 --- a/libgimp/gimpui.c +++ b/libgimp/gimpui.c @@ -65,9 +65,9 @@ void gimp_ui_init (const gchar *prog_name, gboolean preview) { + GdkScreen *screen; const gchar *display_name; gchar *themerc; - GdkScreen *screen; g_return_if_fail (prog_name != NULL); @@ -87,6 +87,17 @@ gimp_ui_init (const gchar *prog_name, #endif } + if (gimp_user_time ()) + { + /* Construct a fake startup ID as we only want to pass the + * interaction timestamp, see _gdk_windowing_set_default_display(). + */ + gchar *startup_id = g_strdup_printf ("_TIME%u", gimp_user_time ()); + + g_setenv ("DESKTOP_STARTUP_ID", startup_id, TRUE); + g_free (startup_id); + } + gtk_init (NULL, NULL); themerc = gimp_personal_rc_file ("themerc"); diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c index c3c482c36b..6c605701dd 100644 --- a/libgimpbase/gimpprotocol.c +++ b/libgimpbase/gimpprotocol.c @@ -541,6 +541,9 @@ _gp_config_read (GIOChannel *channel, (guint32 *) &config->monitor_number, 1, user_data)) goto cleanup; + if (! _gimp_wire_read_int32 (channel, + &config->timestamp, 1, user_data)) + goto cleanup; msg->data = config; return; @@ -633,6 +636,10 @@ _gp_config_write (GIOChannel *channel, (const guint32 *) &config->monitor_number, 1, user_data)) return; + if (! _gimp_wire_write_int32 (channel, + (const guint32 *) &config->timestamp, 1, + user_data)) + return; } static void diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h index 08b574b85f..2b69bc6f86 100644 --- a/libgimpbase/gimpprotocol.h +++ b/libgimpbase/gimpprotocol.h @@ -27,7 +27,7 @@ G_BEGIN_DECLS /* Increment every time the protocol changes */ -#define GIMP_PROTOCOL_VERSION 0x0011 +#define GIMP_PROTOCOL_VERSION 0x0012 enum @@ -82,6 +82,7 @@ struct _GPConfig gchar *wm_class; gchar *display_name; gint32 monitor_number; + guint32 timestamp; }; struct _GPTileReq