From bcd9194e1bc57b9427a806eab075eeb5e5f572d5 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Sat, 30 Dec 2023 21:38:22 +0530
Subject: [PATCH] first attempt at fixing ctun when it cross the display limits

---
 screen.c |  2 +-
 vfo.c    | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/screen.c b/screen.c
index 8596bb4..d00adad 100644
--- a/screen.c
+++ b/screen.c
@@ -11,7 +11,7 @@ const colour_t dark_green = { DARK_GREEN_R, DARK_GREEN_G, DARK_GREEN_B };
 
 widget_props_t default_widget_prop_table[NUM_ACTIVE_BUTTONS] = {
     // label, x, y, font_size, off_colour, on_colour
-    [SCR_VFO_A] = { 285, 95, 66, { green, white }, { "", "" } },
+    [SCR_VFO_A] = { 285, 95, 64, { green, white }, { "", "" } },
     [SCR_VFO_B] = { 285, 18, 18, { cyan, grey}, { "", "" } },
     [SCR_ACTIVE_VFO] = { 400, 20, 18, { yellow, yellow }, { "", "" } },
     [SCR_MODE] = { 70, 80, 30, { yellow, yellow }, { "MODE", "MODE" } },
diff --git a/vfo.c b/vfo.c
index 5626274..59b4401 100644
--- a/vfo.c
+++ b/vfo.c
@@ -757,8 +757,25 @@ void vfo_id_move(int id, long long hz, int round) {
             long long max_freq = frequency + half;
 
             if (rx_low <= min_freq) {
+		// XXX: move the background. how do we move the
+		// background? Set the freq to the new center freq?
+		// i.e. in ctun mode, vfo[id].ctune_frequency is the
+		// vfo freq and around it is where we draw the filter
+		// band limits, but the display is centered around
+		// vfo[id].frequency. But when we want to move the
+		// background, we move the vfo[id].freq by the
+		// required offset and let ctun_freq remain as it is.
+		long long delta_move = min_freq - rx_low;
+		vfo[id].frequency = vfo[id].frequency + hz - delta_move;
+		receiver_frequency_changed(receiver[id]);
+		g_idle_add(ext_vfo_update, NULL);
                 return;
             } else if (rx_high >= max_freq) {
+		// XXX: move the background
+		long long delta_move = rx_high - max_freq;
+		vfo[id].frequency = vfo[id].frequency + hz - delta_move;
+		receiver_frequency_changed(receiver[id]);
+		g_idle_add(ext_vfo_update, NULL);
                 return;
             }
 
-- 
2.45.2