mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
app: new gimp_display_grab_focus() function.
The goal of this function is to give the focus to the active image display. This is implemented as a core GimpDisplay virtual function (with the actual implementation in GimpDisplayImpl), allowing to be used even in core code, without actual GUI code (this was not necessary right now, but I think it will be useful in future use). This function is now called from the toolbox code (cf. 2 commits earlier), avoiding code duplication. I also added a usage at the end of toolbox_paste_received() so that a newly opened image by middle-click paste in the toolbox directly gains focus.
This commit is contained in:
@@ -197,6 +197,17 @@ gimp_display_present (GimpDisplay *display)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_display_grab_focus (GimpDisplay *display)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
||||
|
||||
if (GIMP_DISPLAY_GET_CLASS (display)->grab_focus)
|
||||
return GIMP_DISPLAY_GET_CLASS (display)->grab_focus (display);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Gimp *
|
||||
gimp_display_get_gimp (GimpDisplay *display)
|
||||
{
|
||||
|
@@ -47,7 +47,8 @@ struct _GimpDisplayClass
|
||||
{
|
||||
GimpObjectClass parent_class;
|
||||
|
||||
gboolean (* present) (GimpDisplay *display);
|
||||
gboolean (* present) (GimpDisplay *display);
|
||||
gboolean (* grab_focus) (GimpDisplay *display);
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +58,8 @@ gint gimp_display_get_id (GimpDisplay *display);
|
||||
GimpDisplay * gimp_display_get_by_id (Gimp *gimp,
|
||||
gint id);
|
||||
|
||||
gboolean gimp_display_present (GimpDisplay *display);
|
||||
gboolean gimp_display_present (GimpDisplay *display);
|
||||
gboolean gimp_display_grab_focus (GimpDisplay *display);
|
||||
|
||||
Gimp * gimp_display_get_gimp (GimpDisplay *display);
|
||||
|
||||
|
@@ -94,6 +94,7 @@ static void gimp_display_get_property (GObject *object
|
||||
GParamSpec *pspec);
|
||||
|
||||
static gboolean gimp_display_impl_present (GimpDisplay *display);
|
||||
static gboolean gimp_display_impl_grab_focus (GimpDisplay *display);
|
||||
|
||||
static GimpProgress * gimp_display_progress_start (GimpProgress *progress,
|
||||
gboolean cancellable,
|
||||
@@ -141,6 +142,7 @@ gimp_display_impl_class_init (GimpDisplayImplClass *klass)
|
||||
object_class->get_property = gimp_display_get_property;
|
||||
|
||||
display_class->present = gimp_display_impl_present;
|
||||
display_class->grab_focus = gimp_display_impl_grab_focus;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_IMAGE,
|
||||
g_param_spec_object ("image",
|
||||
@@ -221,6 +223,26 @@ gimp_display_impl_present (GimpDisplay *display)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_display_impl_grab_focus (GimpDisplay *display)
|
||||
{
|
||||
GimpDisplayImpl *display_impl = GIMP_DISPLAY_IMPL (display);
|
||||
|
||||
if (display_impl->priv->shell && gimp_display_get_image (display))
|
||||
{
|
||||
GimpImageWindow *image_window;
|
||||
|
||||
image_window = gimp_display_shell_get_window (gimp_display_get_shell (display));
|
||||
|
||||
gimp_display_present (display);
|
||||
gtk_widget_grab_focus (gimp_window_get_primary_focus_widget (GIMP_WINDOW (image_window)));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GimpProgress *
|
||||
gimp_display_progress_start (GimpProgress *progress,
|
||||
gboolean cancellable,
|
||||
|
@@ -33,10 +33,6 @@
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpdisplay.h"
|
||||
|
||||
#include "display/display-types.h"
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
|
||||
#include "file/file-open.h"
|
||||
|
||||
#include "gimpcairo-wilber.h"
|
||||
@@ -353,20 +349,7 @@ gimp_toolbox_button_press_event (GtkWidget *widget,
|
||||
{
|
||||
GimpToolbox *toolbox = GIMP_TOOLBOX (widget);
|
||||
GimpDisplay *display;
|
||||
|
||||
if ((display = gimp_context_get_display (toolbox->p->context)) &&
|
||||
gimp_context_get_image (toolbox->p->context))
|
||||
{
|
||||
/* Any button event in empty spaces or the Wilber area gives focus
|
||||
* to the top image.
|
||||
*/
|
||||
GimpImageWindow *image_window;
|
||||
|
||||
image_window = gimp_display_shell_get_window (gimp_display_get_shell (display));
|
||||
|
||||
gimp_display_present (display);
|
||||
gtk_widget_grab_focus (gimp_window_get_primary_focus_widget (GIMP_WINDOW (image_window)));
|
||||
}
|
||||
gboolean stop_event = GDK_EVENT_PROPAGATE;
|
||||
|
||||
if (event->type == GDK_BUTTON_PRESS && event->button == 2)
|
||||
{
|
||||
@@ -377,10 +360,17 @@ gimp_toolbox_button_press_event (GtkWidget *widget,
|
||||
toolbox_paste_received,
|
||||
g_object_ref (toolbox));
|
||||
|
||||
return TRUE;
|
||||
stop_event = GDK_EVENT_STOP;
|
||||
}
|
||||
else if ((display = gimp_context_get_display (toolbox->p->context)))
|
||||
{
|
||||
/* Any button event in empty spaces or the Wilber area gives focus
|
||||
* to the top image.
|
||||
*/
|
||||
gimp_display_grab_focus (display);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return stop_event;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -686,6 +676,7 @@ toolbox_paste_received (GtkClipboard *clipboard,
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (toolbox);
|
||||
GimpImage *image;
|
||||
GimpDisplay *display;
|
||||
GimpPDBStatusType status;
|
||||
GError *error = NULL;
|
||||
|
||||
@@ -701,6 +692,11 @@ toolbox_paste_received (GtkClipboard *clipboard,
|
||||
gimp_file_get_utf8_name (file), error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
else if ((display = gimp_context_get_display (context)))
|
||||
{
|
||||
/* Giving focus to newly opened image. */
|
||||
gimp_display_grab_focus (display);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
@@ -39,10 +39,6 @@
|
||||
#include "core/gimptoolgroup.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
|
||||
#include "display/display-types.h"
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
|
||||
#include "actions/tools-commands.h"
|
||||
|
||||
#include "gimpaccellabel.h"
|
||||
@@ -52,7 +48,6 @@
|
||||
#include "gimptoolbutton.h"
|
||||
#include "gimpuimanager.h"
|
||||
#include "gimpwidgets-utils.h"
|
||||
#include "gimpwindow.h"
|
||||
#include "gimpwindowstrategy.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
@@ -616,12 +611,7 @@ gimp_tool_button_toggled (GtkToggleToolButton *toggle_tool_button)
|
||||
if ((display = gimp_context_get_display (context)) &&
|
||||
gimp_context_get_image (context))
|
||||
{
|
||||
GimpImageWindow *image_window;
|
||||
|
||||
image_window = gimp_display_shell_get_window (gimp_display_get_shell (display));
|
||||
|
||||
gimp_display_present (display);
|
||||
gtk_widget_grab_focus (gimp_window_get_primary_focus_widget (GIMP_WINDOW (image_window)));
|
||||
gimp_display_grab_focus (display);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user