[ghex] gtkhex: highlighting and tab-nav improvements.



commit 57705da1e2eee0caabec272311d30e311583d7e6
Author: Logan Rathbone <poprocks gmail com>
Date:   Fri Dec 10 01:59:01 2021 -0500

    gtkhex: highlighting and tab-nav improvements.
    
    Redrawing is still a bit janky sometimes, but improved.
    
    Now you can tab thru the panes properly.
    
    Shift-tab doesn't work sometimes.
    
    I'll take a look at the keyboard handling code asap; the shift input is
    probably being eaten when the hex widget is in focus.

 src/ghex.css | 15 ++++++++++++---
 src/gtkhex.c | 18 ++++++++++++++++--
 2 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/src/ghex.css b/src/ghex.css
index 5b6b684..d58ab55 100644
--- a/src/ghex.css
+++ b/src/ghex.css
@@ -6,11 +6,20 @@
        background-color: @theme_bg_color;
 }
 
-.hex:selected {
-       color: @theme_selected_fg_color;
-       background-color: @theme_selected_bg_color;
+/* nb: order matters for the next 2 selectors. */
+
+#hex-display:selected, #ascii-display:selected {
+        color: @theme_selected_fg_color;
+        background-color: alpha(shade(@theme_selected_bg_color, 0), 0.2);
+}
+
+#hex-display:focus-within, #ascii-display:focus-within {
+        color: @theme_selected_fg_color;
+        background-color: @theme_selected_bg_color;
 }
 
+/* ---- */
+
 .hex:link {
        background-color: alpha(red, 0.5);
 }
diff --git a/src/gtkhex.c b/src/gtkhex.c
index a78ef56..564a0dc 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -278,6 +278,16 @@ redo_action (GtkWidget *widget,
        }
 }
 
+static void
+state_flags_changed_cb (GtkWidget *widget, GtkStateFlags flags,
+               gpointer user_data)
+{
+       GtkHex *gh = GTK_HEX(widget);
+
+       if (flags | GTK_STATE_FLAG_FOCUS_WITHIN)
+               gtk_widget_queue_draw (widget);
+}
+
 static void
 doc_undo_redo_cb (HexDocument *doc, gpointer user_data)
 {
@@ -751,12 +761,11 @@ render_highlights (GtkHex *gh,
                        state |= GTK_STATE_FLAG_LINK;
                else
                {
-                       state |= GTK_STATE_FLAG_SELECTED;
-
                        if (gtk_widget_has_focus (GTK_WIDGET(gh)))
                        {
                                state |= GTK_STATE_FLAG_FOCUS_WITHIN;
                        }
+                       state |= GTK_STATE_FLAG_SELECTED;
                }
 
                gtk_style_context_set_state (context, state);
@@ -2606,6 +2615,11 @@ gtk_hex_init (GtkHex *gh)
        child_info = GTK_HEX_LAYOUT_CHILD (gtk_layout_manager_get_layout_child
                        (gh->layout_manager, gh->scrollbar));
        gtk_hex_layout_child_set_column (child_info, SCROLLBAR_COLUMN);
+       
+       /* SETUP SIGNALS */
+
+       g_signal_connect (widget, "state-flags-changed",
+                       G_CALLBACK(state_flags_changed_cb), NULL);
 
        /* GESTURES */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]