gtk: Port widgets away from gtk_get_current_ apis

Use the event controller equivalents where needed.
This commit covers the simple cases.
This commit is contained in:
Matthias Clasen 2020-04-11 14:58:15 -04:00
parent bd56bc9055
commit 0ee58e9ef4
7 changed files with 34 additions and 49 deletions

View File

@ -309,29 +309,25 @@ click_pressed_cb (GtkGestureClick *gesture,
}
static gboolean
touch_release_in_button (GtkButton *button,
double x,
double y)
touch_release_in_button (GtkGestureClick *gesture,
GtkWidget *widget,
double x,
double y)
{
GdkEvent *event;
event = gtk_get_current_event ();
event = gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (gesture));
if (!event)
return FALSE;
if (gdk_event_get_event_type (event) != GDK_TOUCH_END)
{
gdk_event_unref (event);
return FALSE;
}
return FALSE;
gdk_event_unref (event);
if (!gtk_widget_contains (widget, x, y))
return FALSE;
if (gtk_widget_contains (GTK_WIDGET (button), x, y))
return TRUE;
return FALSE;
return TRUE;
}
static void
@ -348,7 +344,7 @@ click_released_cb (GtkGestureClick *gesture,
gtk_button_do_release (button,
gtk_widget_is_sensitive (GTK_WIDGET (button)) &&
(priv->in_button ||
touch_release_in_button (button, x, y)));
touch_release_in_button (gesture, widget, x, y)));
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));

View File

@ -539,8 +539,10 @@ key_controller_key_pressed (GtkEventControllerKey *key,
gboolean cleared = FALSE;
GdkModifierType accel_mods = 0;
guint accel_key;
GdkEvent *event;
if (!gdk_key_event_get_match (gtk_get_current_event (), &accel_key, &accel_mods))
event = gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (key));
if (!gdk_key_event_get_match (event, &accel_key, &accel_mods))
return FALSE;
if (accel_mods == 0)

View File

@ -2877,8 +2877,7 @@ gtk_notebook_motion (GtkEventController *controller,
if (!page)
return;
if (!gtk_get_current_event_state (&state))
return;
state = gtk_event_controller_get_current_event_state (controller);
if (!(state & GDK_BUTTON1_MASK) &&
notebook->pressed_button != 0)
@ -2905,7 +2904,7 @@ gtk_notebook_motion (GtkEventController *controller,
notebook->detached_tab = notebook->cur_page;
surface = gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (notebook)));
device = gtk_get_current_event_device ();
device = gtk_event_controller_get_current_event_device (controller);
content = gdk_content_provider_new_union ((GdkContentProvider *[2]) {
gtk_notebook_root_content_new (notebook),

View File

@ -3420,7 +3420,7 @@ on_row_released (GtkGestureClick *gesture,
NULL);
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
gtk_get_current_event_state (&state);
state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (gesture));
if (row)
{

View File

@ -30,6 +30,7 @@
#include "gtkadjustmentprivate.h"
#include "gtkeventcontrollermotion.h"
#include "gtkeventcontrollerscroll.h"
#include "gtkeventcontrollerprivate.h"
#include "gtkgesturedrag.h"
#include "gtkgesturelongpress.h"
#include "gtkgesturepan.h"
@ -1171,9 +1172,10 @@ captured_scroll_cb (GtkEventControllerScroll *scroll,
}
static void
captured_motion (GtkScrolledWindow *sw,
gdouble x,
gdouble y)
captured_motion (GtkEventController *controller,
double x,
double y,
GtkScrolledWindow *sw)
{
GtkScrolledWindowPrivate *priv = gtk_scrolled_window_get_instance_private (sw);
GdkDevice *source_device;
@ -1185,7 +1187,10 @@ captured_motion (GtkScrolledWindow *sw,
if (!priv->use_indicators)
return;
event = gtk_get_current_event ();
target = gtk_event_controller_get_target (controller);
state = gtk_event_controller_get_current_event_state (controller);
event = gtk_event_controller_get_current_event (controller);
source_device = gdk_event_get_source_device (event);
input_source = gdk_device_get_source (source_device);
@ -1194,10 +1199,6 @@ captured_motion (GtkScrolledWindow *sw,
if (priv->vscrollbar_visible)
indicator_start_fade (&priv->vindicator, 1.0);
state = gdk_event_get_modifier_state (event);
target = gtk_widget_pick (GTK_WIDGET (sw), x, y, GTK_PICK_DEFAULT);
if (!target &&
(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) != 0)
{
@ -1218,8 +1219,6 @@ captured_motion (GtkScrolledWindow *sw,
else
indicator_set_over (&priv->hindicator, FALSE);
}
gdk_event_unref (event);
}
static gboolean
@ -1259,9 +1258,7 @@ scroll_controller_scroll (GtkEventControllerScroll *scroll,
gboolean shifted;
GdkModifierType state;
if (!gtk_get_current_event_state (&state))
return GDK_EVENT_PROPAGATE;
state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (scroll));
shifted = (state & GDK_SHIFT_MASK) != 0;
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
@ -1343,8 +1340,8 @@ scroll_controller_decelerate (GtkEventControllerScroll *scroll,
gboolean shifted;
GdkModifierType state;
if (!gtk_get_current_event_state (&state))
return;
state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (scroll));
shifted = (state & GDK_SHIFT_MASK) != 0;
@ -1970,8 +1967,8 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
controller = gtk_event_controller_motion_new ();
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
g_signal_connect_swapped (controller, "motion",
G_CALLBACK (captured_motion), scrolled_window);
g_signal_connect (controller, "motion",
G_CALLBACK (captured_motion), scrolled_window);
gtk_widget_add_controller (widget, controller);
widget_node = gtk_widget_get_css_node (widget);

View File

@ -8142,7 +8142,7 @@ gtk_text_view_value_changed (GtkAdjustment *adjustment,
if (gtk_gesture_is_active (priv->drag_gesture))
{
GdkEvent *current_event;
current_event = gtk_get_current_event ();
current_event = gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (priv->drag_gesture));
if (current_event != NULL)
{
if (gdk_event_get_event_type (current_event) == GDK_SCROLL)
@ -8621,20 +8621,14 @@ gtk_text_view_get_menu_model (GtkTextView *text_view)
}
static void
gtk_text_view_do_popup (GtkTextView *text_view,
GdkEvent *event)
gtk_text_view_do_popup (GtkTextView *text_view,
GdkEvent *trigger_event)
{
GtkTextViewPrivate *priv = text_view->priv;
GdkEvent *trigger_event;
if (!gtk_widget_get_realized (GTK_WIDGET (text_view)))
return;
if (event)
trigger_event = (GdkEvent *)event;
else
trigger_event = gtk_get_current_event ();
gtk_text_view_update_clipboard_actions (text_view);
if (!priv->popup_menu)
@ -8709,9 +8703,6 @@ gtk_text_view_do_popup (GtkTextView *text_view,
}
gtk_popover_popup (GTK_POPOVER (priv->popup_menu));
if (trigger_event && trigger_event != event)
gdk_event_unref (trigger_event);
}
static void

View File

@ -1425,7 +1425,7 @@ drag_gesture_update_cb (GtkGestureDrag *gesture,
gtk_gesture_get_device (GTK_GESTURE (gesture)),
gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)),
(int)start_x, (int)start_y,
gtk_get_current_event_time ());
gdk_event_get_time (gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (gesture))));
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (priv->click_gesture));