forked from AuroraMiddleware/gtk
Merge branch 'focus-active' into 'master'
Focus active Closes #2390 See merge request GNOME/gtk!2324
This commit is contained in:
commit
62803c19f5
@ -154,7 +154,8 @@ gtk_event_controller_key_handle_crossing (GtkEventController *controller,
|
||||
gboolean start_crossing, end_crossing;
|
||||
gboolean is_focus;
|
||||
|
||||
if (crossing->type != GTK_CROSSING_FOCUS)
|
||||
if (crossing->type != GTK_CROSSING_FOCUS &&
|
||||
crossing->type != GTK_CROSSING_ACTIVE)
|
||||
return;
|
||||
|
||||
start_crossing = crossing->direction == GTK_CROSSING_OUT &&
|
||||
|
@ -22,12 +22,29 @@
|
||||
|
||||
#include "gtkeventcontroller.h"
|
||||
|
||||
/* GdkCrossingType:
|
||||
* @GTK_CROSSING_FOCUS: Focus moved from one widget to another
|
||||
* @GTK_CROSSING_ACTIVE: The active window changed (the crossing
|
||||
* events in this case leave from the old active window's focus
|
||||
* location to the new active window's one.
|
||||
* @GTK_CROSSING_POINTER: The pointer moved from one widget to another
|
||||
* @GTK_CROSSING_POINTER: An active drag moved from one widget to another
|
||||
*
|
||||
* We emit various kinds of crossing events when the target widget
|
||||
* for keyboard or pointer events changes.
|
||||
*/
|
||||
typedef enum {
|
||||
GTK_CROSSING_FOCUS,
|
||||
GTK_CROSSING_ACTIVE,
|
||||
GTK_CROSSING_POINTER,
|
||||
GTK_CROSSING_DROP
|
||||
} GtkCrossingType;
|
||||
|
||||
/*
|
||||
* GdkCrossingirection:
|
||||
* @GTK_CROSSING_IN: the event is on the downward slope, towards the new target
|
||||
* @GTK_CROSSING_OUT: the event is on the upward slope, away from the old target
|
||||
*/
|
||||
typedef enum {
|
||||
GTK_CROSSING_IN,
|
||||
GTK_CROSSING_OUT
|
||||
|
@ -1834,9 +1834,10 @@ gtk_window_root_get_focus (GtkRoot *root)
|
||||
return priv->focus_widget;
|
||||
}
|
||||
|
||||
static void synthesize_focus_change_events (GtkWindow *window,
|
||||
GtkWidget *old_focus,
|
||||
GtkWidget *new_focus);
|
||||
static void synthesize_focus_change_events (GtkWindow *window,
|
||||
GtkWidget *old_focus,
|
||||
GtkWidget *new_focus,
|
||||
GtkCrossingType type);
|
||||
|
||||
static void
|
||||
gtk_window_root_set_focus (GtkRoot *root,
|
||||
@ -1859,7 +1860,7 @@ gtk_window_root_set_focus (GtkRoot *root,
|
||||
if (old_focus)
|
||||
gtk_widget_set_has_focus (old_focus, FALSE);
|
||||
|
||||
synthesize_focus_change_events (self, old_focus, focus);
|
||||
synthesize_focus_change_events (self, old_focus, focus, GTK_CROSSING_FOCUS);
|
||||
|
||||
if (focus)
|
||||
gtk_widget_set_has_focus (focus, TRUE);
|
||||
@ -4984,9 +4985,10 @@ check_crossing_invariants (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static void
|
||||
synthesize_focus_change_events (GtkWindow *window,
|
||||
GtkWidget *old_focus,
|
||||
GtkWidget *new_focus)
|
||||
synthesize_focus_change_events (GtkWindow *window,
|
||||
GtkWidget *old_focus,
|
||||
GtkWidget *new_focus,
|
||||
GtkCrossingType type)
|
||||
{
|
||||
GtkCrossingData crossing;
|
||||
GtkWidget *ancestor;
|
||||
@ -5005,7 +5007,7 @@ synthesize_focus_change_events (GtkWindow *window,
|
||||
if (gtk_window_get_focus_visible (GTK_WINDOW (window)))
|
||||
flags |= GTK_STATE_FLAG_FOCUS_VISIBLE;
|
||||
|
||||
crossing.type = GTK_CROSSING_FOCUS;
|
||||
crossing.type = type;
|
||||
crossing.mode = GDK_CROSSING_NORMAL;
|
||||
crossing.old_target = old_focus;
|
||||
crossing.old_descendent = NULL;
|
||||
@ -5038,7 +5040,7 @@ synthesize_focus_change_events (GtkWindow *window,
|
||||
{
|
||||
crossing.new_descendent = NULL;
|
||||
}
|
||||
|
||||
|
||||
check_crossing_invariants (widget, &crossing);
|
||||
gtk_widget_handle_crossing (widget, &crossing, 0, 0);
|
||||
gtk_widget_unset_state_flags (widget, flags);
|
||||
@ -6303,14 +6305,14 @@ gtk_window_keys_changed (GtkWindow *window)
|
||||
* _gtk_window_set_is_active:
|
||||
* @window: a #GtkWindow
|
||||
* @is_active: %TRUE if the window is in the currently active toplevel
|
||||
*
|
||||
*
|
||||
* Internal function that sets whether the #GtkWindow is part
|
||||
* of the currently active toplevel window (taking into account inter-process
|
||||
* embedding.)
|
||||
**/
|
||||
static void
|
||||
_gtk_window_set_is_active (GtkWindow *window,
|
||||
gboolean is_active)
|
||||
gboolean is_active)
|
||||
{
|
||||
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
|
||||
|
||||
@ -6319,6 +6321,20 @@ _gtk_window_set_is_active (GtkWindow *window,
|
||||
|
||||
priv->is_active = is_active;
|
||||
|
||||
if (priv->focus_widget)
|
||||
{
|
||||
GtkWidget *focus;
|
||||
|
||||
focus = g_object_ref (priv->focus_widget);
|
||||
|
||||
if (is_active)
|
||||
synthesize_focus_change_events (window, NULL, focus, GTK_CROSSING_ACTIVE);
|
||||
else
|
||||
synthesize_focus_change_events (window, focus, NULL, GTK_CROSSING_ACTIVE);
|
||||
|
||||
g_object_unref (focus);
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_IS_ACTIVE]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user