Use GDK event handling return value constants

This commit is contained in:
Přemysl Eric Janouch 2022-07-21 14:46:17 +02:00
parent 390e21a72d
commit b067c1948b
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 35 additions and 34 deletions

View File

@ -1070,10 +1070,10 @@ fiv_browser_button_press_event(GtkWidget *widget, GdkEventButton *event)
// Make pressing multiple mouse buttons at once cancel a click. // Make pressing multiple mouse buttons at once cancel a click.
if (self->tracked_button) { if (self->tracked_button) {
abort_button_tracking(self); abort_button_tracking(self);
return TRUE; return GDK_EVENT_STOP;
} }
if (event->type != GDK_BUTTON_PRESS) if (event->type != GDK_BUTTON_PRESS)
return FALSE; return GDK_EVENT_PROPAGATE;
guint state = event->state & gtk_accelerator_get_default_mod_mask(); guint state = event->state & gtk_accelerator_get_default_mod_mask();
if (event->button == GDK_BUTTON_PRIMARY && state == 0 && if (event->button == GDK_BUTTON_PRIMARY && state == 0 &&
@ -1085,13 +1085,13 @@ fiv_browser_button_press_event(GtkWidget *widget, GdkEventButton *event)
if (event->button == GDK_BUTTON_SECONDARY) if (event->button == GDK_BUTTON_SECONDARY)
show_context_menu(widget, fiv_io_model_get_location(self->model)); show_context_menu(widget, fiv_io_model_get_location(self->model));
else if (event->button != GDK_BUTTON_PRIMARY) else if (event->button != GDK_BUTTON_PRIMARY)
return FALSE; return GDK_EVENT_PROPAGATE;
if (self->selected) { if (self->selected) {
self->selected = NULL; self->selected = NULL;
gtk_widget_queue_draw(widget); gtk_widget_queue_draw(widget);
} }
return TRUE; return GDK_EVENT_STOP;
} }
// In accordance with Nautilus, Thunar, and the mildly confusing // In accordance with Nautilus, Thunar, and the mildly confusing
@ -1108,7 +1108,7 @@ fiv_browser_button_press_event(GtkWidget *widget, GdkEventButton *event)
GFile *file = g_file_new_for_uri(entry->uri); GFile *file = g_file_new_for_uri(entry->uri);
show_context_menu(widget, file); show_context_menu(widget, file);
g_object_unref(file); g_object_unref(file);
return TRUE; return GDK_EVENT_STOP;
} }
// gtk_drag_source_set() would span the whole widget area, we'd have to // gtk_drag_source_set() would span the whole widget area, we'd have to
@ -1119,9 +1119,9 @@ fiv_browser_button_press_event(GtkWidget *widget, GdkEventButton *event)
self->tracked_button = event->button; self->tracked_button = event->button;
self->drag_begin_x = event->x; self->drag_begin_x = event->x;
self->drag_begin_y = event->y; self->drag_begin_y = event->y;
return TRUE; return GDK_EVENT_STOP;
} }
return FALSE; return GDK_EVENT_PROPAGATE;
} }
static gboolean static gboolean
@ -1132,13 +1132,13 @@ fiv_browser_button_release_event(GtkWidget *widget, GdkEventButton *event)
->button_release_event(widget, event)) ->button_release_event(widget, event))
return GDK_EVENT_STOP; return GDK_EVENT_STOP;
if (event->button != self->tracked_button) if (event->button != self->tracked_button)
return FALSE; return GDK_EVENT_PROPAGATE;
// Middle clicks should only work on the starting entry. // Middle clicks should only work on the starting entry.
const Entry *entry = entry_at(self, self->drag_begin_x, self->drag_begin_y); const Entry *entry = entry_at(self, self->drag_begin_x, self->drag_begin_y);
abort_button_tracking(self); abort_button_tracking(self);
if (!entry || entry != entry_at(self, event->x, event->y)) if (!entry || entry != entry_at(self, event->x, event->y))
return FALSE; return GDK_EVENT_PROPAGATE;
guint state = event->state & gtk_accelerator_get_default_mod_mask(); guint state = event->state & gtk_accelerator_get_default_mod_mask();
if ((event->button == GDK_BUTTON_PRIMARY && state == 0)) if ((event->button == GDK_BUTTON_PRIMARY && state == 0))
@ -1146,7 +1146,7 @@ fiv_browser_button_release_event(GtkWidget *widget, GdkEventButton *event)
if ((event->button == GDK_BUTTON_PRIMARY && state == GDK_CONTROL_MASK) || if ((event->button == GDK_BUTTON_PRIMARY && state == GDK_CONTROL_MASK) ||
(event->button == GDK_BUTTON_MIDDLE && state == 0)) (event->button == GDK_BUTTON_MIDDLE && state == 0))
return open_entry(widget, entry, TRUE); return open_entry(widget, entry, TRUE);
return FALSE; return GDK_EVENT_PROPAGATE;
} }
static gboolean static gboolean
@ -1172,7 +1172,7 @@ fiv_browser_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
const Entry *entry = entry_at(self, event->x, event->y); const Entry *entry = entry_at(self, event->x, event->y);
GdkWindow *window = gtk_widget_get_window(widget); GdkWindow *window = gtk_widget_get_window(widget);
gdk_window_set_cursor(window, entry ? self->pointer : NULL); gdk_window_set_cursor(window, entry ? self->pointer : NULL);
return FALSE; return GDK_EVENT_PROPAGATE;
} }
// The "correct" behaviour is to set the selection on a left mouse button // The "correct" behaviour is to set the selection on a left mouse button
@ -1180,7 +1180,7 @@ fiv_browser_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
const Entry *entry = entry_at(self, self->drag_begin_x, self->drag_begin_y); const Entry *entry = entry_at(self, self->drag_begin_x, self->drag_begin_y);
abort_button_tracking(self); abort_button_tracking(self);
if (!entry) if (!entry)
return TRUE; return GDK_EVENT_STOP;
self->selected = entry; self->selected = entry;
gtk_widget_queue_draw(widget); gtk_widget_queue_draw(widget);
@ -1192,7 +1192,7 @@ fiv_browser_motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
gtk_drag_begin_with_coordinates(widget, target_list, actions, gtk_drag_begin_with_coordinates(widget, target_list, actions,
self->tracked_button, (GdkEvent *) event, event->x, event->y); self->tracked_button, (GdkEvent *) event, event->x, event->y);
gtk_target_list_unref(target_list); gtk_target_list_unref(target_list);
return TRUE; return GDK_EVENT_STOP;
} }
static gboolean static gboolean
@ -1202,16 +1202,16 @@ fiv_browser_scroll_event(GtkWidget *widget, GdkEventScroll *event)
abort_button_tracking(self); abort_button_tracking(self);
if ((event->state & gtk_accelerator_get_default_mod_mask()) != if ((event->state & gtk_accelerator_get_default_mod_mask()) !=
GDK_CONTROL_MASK) GDK_CONTROL_MASK)
return FALSE; return GDK_EVENT_PROPAGATE;
static double delta = 0; static double delta = 0;
switch (event->direction) { switch (event->direction) {
case GDK_SCROLL_UP: case GDK_SCROLL_UP:
set_item_size(self, self->item_size + 1); set_item_size(self, self->item_size + 1);
return TRUE; return GDK_EVENT_STOP;
case GDK_SCROLL_DOWN: case GDK_SCROLL_DOWN:
set_item_size(self, self->item_size - 1); set_item_size(self, self->item_size - 1);
return TRUE; return GDK_EVENT_STOP;
case GDK_SCROLL_SMOOTH: case GDK_SCROLL_SMOOTH:
// On GDK/Wayland, the mouse wheel will typically create 1.5 deltas, // On GDK/Wayland, the mouse wheel will typically create 1.5 deltas,
// after dividing a 15 degree click angle from libinput by 10. // after dividing a 15 degree click angle from libinput by 10.
@ -1221,13 +1221,13 @@ fiv_browser_scroll_event(GtkWidget *widget, GdkEventScroll *event)
else if (delta >= +1) else if (delta >= +1)
set_item_size(self, self->item_size - 1); set_item_size(self, self->item_size - 1);
else if (!event->is_stop) else if (!event->is_stop)
return TRUE; return GDK_EVENT_STOP;
delta = 0; delta = 0;
return TRUE; return GDK_EVENT_STOP;
default: default:
// Left/right are good to steal from GtkScrolledWindow for consistency. // Left/right are good to steal from GtkScrolledWindow for consistency.
return TRUE; return GDK_EVENT_STOP;
} }
} }
@ -1399,25 +1399,25 @@ fiv_browser_key_press_event(GtkWidget *widget, GdkEventKey *event)
case GDK_KEY_Return: case GDK_KEY_Return:
if (self->selected) if (self->selected)
return open_entry(widget, self->selected, FALSE); return open_entry(widget, self->selected, FALSE);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_Left: case GDK_KEY_Left:
move_selection(self, GTK_DIR_LEFT); move_selection(self, GTK_DIR_LEFT);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_Right: case GDK_KEY_Right:
move_selection(self, GTK_DIR_RIGHT); move_selection(self, GTK_DIR_RIGHT);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_Up: case GDK_KEY_Up:
move_selection(self, GTK_DIR_UP); move_selection(self, GTK_DIR_UP);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_Down: case GDK_KEY_Down:
move_selection(self, GTK_DIR_DOWN); move_selection(self, GTK_DIR_DOWN);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_Home: case GDK_KEY_Home:
move_selection_home(self); move_selection_home(self);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_End: case GDK_KEY_End:
move_selection_end(self); move_selection_end(self);
return TRUE; return GDK_EVENT_STOP;
} }
break; break;
case GDK_CONTROL_MASK: case GDK_CONTROL_MASK:
@ -1425,10 +1425,10 @@ fiv_browser_key_press_event(GtkWidget *widget, GdkEventKey *event)
switch (event->keyval) { switch (event->keyval) {
case GDK_KEY_plus: case GDK_KEY_plus:
set_item_size(self, self->item_size + 1); set_item_size(self, self->item_size + 1);
return TRUE; return GDK_EVENT_STOP;
case GDK_KEY_minus: case GDK_KEY_minus:
set_item_size(self, self->item_size - 1); set_item_size(self, self->item_size - 1);
return TRUE; return GDK_EVENT_STOP;
} }
} }

View File

@ -630,13 +630,14 @@ fiv_view_draw(GtkWidget *widget, cairo_t *cr)
static gboolean static gboolean
fiv_view_button_press_event(GtkWidget *widget, GdkEventButton *event) fiv_view_button_press_event(GtkWidget *widget, GdkEventButton *event)
{ {
// XXX: Return value? if (GTK_WIDGET_CLASS(fiv_view_parent_class)
GTK_WIDGET_CLASS(fiv_view_parent_class)->button_press_event(widget, event); ->button_press_event(widget, event))
return GDK_EVENT_STOP;
if (event->button == GDK_BUTTON_PRIMARY && if (event->button == GDK_BUTTON_PRIMARY &&
gtk_widget_get_focus_on_click(widget)) gtk_widget_get_focus_on_click(widget))
gtk_widget_grab_focus(widget); gtk_widget_grab_focus(widget);
return FALSE; return GDK_EVENT_PROPAGATE;
} }
#define SCALE_STEP 1.25 #define SCALE_STEP 1.25
@ -737,9 +738,9 @@ fiv_view_scroll_event(GtkWidget *widget, GdkEventScroll *event)
{ {
FivView *self = FIV_VIEW(widget); FivView *self = FIV_VIEW(widget);
if (!self->image) if (!self->image)
return FALSE; return GDK_EVENT_PROPAGATE;
if (event->state & gtk_accelerator_get_default_mod_mask()) if (event->state & gtk_accelerator_get_default_mod_mask())
return FALSE; return GDK_EVENT_PROPAGATE;
switch (event->direction) { switch (event->direction) {
case GDK_SCROLL_UP: case GDK_SCROLL_UP:
@ -749,7 +750,7 @@ fiv_view_scroll_event(GtkWidget *widget, GdkEventScroll *event)
default: default:
// For some reason, native GdkWindows may also get GDK_SCROLL_SMOOTH. // For some reason, native GdkWindows may also get GDK_SCROLL_SMOOTH.
// Left/right are good to steal from GtkScrolledWindow for consistency. // Left/right are good to steal from GtkScrolledWindow for consistency.
return TRUE; return GDK_EVENT_STOP;
} }
} }