From 8645e2408e7d5a0cfda458b1a9536bd437d046c6 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@leastauthority.com>
Date: Tue, 2 Jan 2024 20:42:21 +0530
Subject: [PATCH] ctune margin: moar bug fix

---
 vfo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/vfo.c b/vfo.c
index d313b9c..1b4abfa 100644
--- a/vfo.c
+++ b/vfo.c
@@ -645,7 +645,7 @@ void vfo_id_step(int id, int steps) {
 	    long long freq_margin = (long long)(display_width * display_margin);
 	    if (rx_low <= (min_freq + freq_margin)) {
                 // XXX handle ctune beyond the screen limits
-                long long delta_move = min_freq - rx_low;
+                long long delta_move = min_freq + freq_margin - rx_low;
                 vfo[id].frequency =
                     ((vfo[id].frequency / step + steps) * step) - delta_move;
 
@@ -656,7 +656,7 @@ void vfo_id_step(int id, int steps) {
                 return;
             } else if (rx_high >= (max_freq - freq_margin)) {
                 // XXX: move the background
-                long long delta_move = rx_high - max_freq;
+                long long delta_move = rx_high - max_freq + freq_margin;
                 vfo[id].frequency =
                     ((vfo[id].frequency / step + steps) * step) + delta_move;
 
-- 
2.45.2