From ff0c3ec9f71ad27b635637774d0b065d6e49b8ef Mon Sep 17 00:00:00 2001
From: Sean Davis <smd.seandavis@gmail.com>
Date: Sun, 1 Mar 2020 07:13:52 -0500
Subject: Enable keyboard scrolling in Details pane (bug #15912)

---
 panel-plugin/weather-summary.c | 53 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index da12a5b..e66abf0 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -282,6 +282,56 @@ weather_summary_get_logo(plugin_data *data)
 }
 
 
+static gboolean
+text_view_key_pressed_cb (GtkWidget   *widget,
+                          GdkEventKey *event,
+                          gpointer     user_data)
+{
+    GtkScrolledWindow *scrolled = GTK_SCROLLED_WINDOW (user_data);
+    GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment (scrolled);
+    gdouble current = gtk_adjustment_get_value (adjustment);
+    gdouble min = gtk_adjustment_get_lower (adjustment);
+    gdouble max = gtk_adjustment_get_upper (adjustment);
+    gdouble step_size = 0;
+
+    switch (event->keyval) {
+        case GDK_KEY_Up:
+        case GDK_KEY_uparrow:
+            step_size = -1 * gtk_adjustment_get_step_increment (adjustment);
+            break;
+        case GDK_KEY_Down:
+        case GDK_KEY_downarrow:
+            step_size = gtk_adjustment_get_step_increment (adjustment);
+            break;
+        case GDK_KEY_Page_Up:
+            step_size = -1 * gtk_adjustment_get_page_size (adjustment);
+            break;
+        case GDK_KEY_Page_Down:
+        case GDK_KEY_space:
+            step_size = gtk_adjustment_get_page_size (adjustment);
+            break;
+        case GDK_KEY_Home:
+            step_size = -1 * current;
+            break;
+        case GDK_KEY_End:
+            step_size = max;
+            break;
+    }
+
+    if (step_size != 0) {
+        current = current + step_size;
+        if (current < min) current = min;
+        if (current > max) current = max;
+
+        gtk_adjustment_set_value (adjustment, current);
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+
 static GtkWidget *
 create_summary_tab(plugin_data *data)
 {
@@ -311,9 +361,12 @@ create_summary_tab(plugin_data *data)
     gtk_text_view_set_top_margin (GTK_TEXT_VIEW(view), 12);
     gtk_text_view_set_right_margin (GTK_TEXT_VIEW(view), 12);
     gtk_text_view_set_bottom_margin (GTK_TEXT_VIEW(view), 12);
+
     frame = gtk_frame_new(NULL);
     scrolled = gtk_scrolled_window_new(NULL, NULL);
 
+    g_signal_connect(GTK_WIDGET(view), "key-press-event", G_CALLBACK(text_view_key_pressed_cb), scrolled);
+
     overlay = gtk_overlay_new ();
     gtk_container_add (GTK_CONTAINER (overlay), view);
 
-- 
cgit v1.2.3

