From 7f9dc97115bb59b62b92f58c8fb01697f15e5a10 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 20 Jul 2026 17:36:28 +0300 Subject: grid: sync flowbox selection to navigator.current on Enter/t (cu0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arrow-key navigation in the grid moved the GtkFlowBox selection but never updated navigator.current, so Enter (and toggling to large with t) opened the stale current image instead of the highlighted one. _on_flow_key emitted the activate signal directly without syncing, unlike the double-click path (_on_child_activated) which does sync. Add ggaze_grid_sync_current(): reads the selected flowbox child and calls navigator_set_current_file. Call it from _on_flow_key before emitting activate, and from _action_toggle_view's grid→large branch (then load the now-current image). Mirrors the existing double-click sync. --- src/gridview.c | 27 +++++++++++++++++++++++++++ src/gridview.h | 4 ++++ src/window.c | 6 ++++++ 3 files changed, 37 insertions(+) (limited to 'src') diff --git a/src/gridview.c b/src/gridview.c index 56267b3..c57eeac 100644 --- a/src/gridview.c +++ b/src/gridview.c @@ -171,6 +171,9 @@ _on_flow_key(GtkEventControllerKey *p_key, guint u_kv, guint u_kc, (void)e_st; GgazeGrid *p_grid = GGAZE_GRID(p_data); if (u_kv == GDK_KEY_Return || u_kv == GDK_KEY_KP_Enter) { + /* Sync navigator.current to the highlighted cell before activating, so + * Enter opens the arrow-selected image, not a stale current. */ + ggaze_grid_sync_current(p_grid); g_signal_emit(p_grid, u_activate_signal, 0); return (TRUE); } @@ -213,6 +216,30 @@ _select_current(GgazeGrid *p_grid) { } } +/* Sync navigator.current to the flowbox's currently-selected child, so that + * leaving the grid (Enter or toggle-to-large) opens the highlighted cell, + * not a stale current left over from when the grid was entered. Mirrors the + * sync _on_child_activated does for a double-click. Returns TRUE if a + * selection was found and current was (or already was) that file. */ +gboolean +ggaze_grid_sync_current(GgazeGrid *p_grid) { + g_return_val_if_fail(GGAZE_IS_GRID(p_grid), FALSE); + if (p_grid->p_nav == NULL) { + return (FALSE); + } + GList *p_sel = + gtk_flow_box_get_selected_children(GTK_FLOW_BOX(p_grid->p_flow)); + if (p_sel == NULL) { + return (FALSE); + } + GFile *p_file = (GFile *)g_object_get_data(G_OBJECT(p_sel->data), "file"); + g_list_free(p_sel); + if (p_file == NULL) { + return (FALSE); + } + return (navigator_set_current_file(p_grid->p_nav, p_file)); +} + void ggaze_grid_refresh(GgazeGrid *p_grid) { g_return_if_fail(GGAZE_IS_GRID(p_grid)); diff --git a/src/gridview.h b/src/gridview.h index 582ada8..f6a4ad2 100644 --- a/src/gridview.h +++ b/src/gridview.h @@ -34,6 +34,10 @@ void ggaze_grid_set_hide_trashed(GgazeGrid *p_grid, gboolean b_hide); /* Rebuild the cells from the navigator (call after structural changes). */ void ggaze_grid_refresh(GgazeGrid *p_grid); +/* Sync navigator.current to the flowbox's currently-selected cell, so leaving + * the grid (Enter / toggle-to-large) opens the highlighted image. */ +gboolean ggaze_grid_sync_current(GgazeGrid *p_grid); + /* Number of cells currently in the grid. */ guint ggaze_grid_get_count(GgazeGrid *p_grid); diff --git a/src/window.c b/src/window.c index 688f879..d978be3 100644 --- a/src/window.c +++ b/src/window.c @@ -243,7 +243,13 @@ _action_toggle_view(GSimpleAction *p_a, GVariant *p_v, gpointer p_data) { if (g_strcmp0(c_cur, "large") == 0) { gtk_stack_set_visible_child_name(GTK_STACK(p_win->p_stack), "grid"); } else { + /* Leaving the grid: sync navigator.current to the highlighted cell so + * the large view opens the selected image, then load it. */ + if (p_win->p_grid != NULL) { + ggaze_grid_sync_current(p_win->p_grid); + } gtk_stack_set_visible_child_name(GTK_STACK(p_win->p_stack), "large"); + _load_current(p_win); } } -- cgit v1.2.3