about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2018-03-09 22:59:38 +0000
committerJames Booth <boothj5@gmail.com>2018-03-09 22:59:38 +0000
commite96af8537c8a0e3e53904be7e035f51f155e2493 (patch)
tree4d144777a9d9751e1c8646ecf4177e7ec5ac2812
parent136b975b6cb1df03ff55faa50dffd5f0da75d0c0 (diff)
downloadprofani-tty-e96af8537c8a0e3e53904be7e035f51f155e2493.tar.gz
Only allow swapping active windows
-rw-r--r--src/command/cmd_funcs.c31
-rw-r--r--src/ui/window_list.c6
-rw-r--r--src/ui/window_list.h2
3 files changed, 24 insertions, 15 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 3fec5e16..ae7f2abc 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -1269,21 +1269,34 @@ cmd_wins_swap(ProfWin *window, const char *const command, gchar **args)
 
     int source_win = atoi(args[1]);
     int target_win = atoi(args[2]);
+
     if ((source_win == 1) || (target_win == 1)) {
         cons_show("Cannot move console window.");
-    } else if (source_win == 10 || target_win == 10) {
+        return TRUE;
+    }
+
+    if (source_win == 10 || target_win == 10) {
         cons_show("Window 10 does not exist");
-    } else if (source_win != target_win) {
-        gboolean swapped = wins_swap(source_win, target_win);
-        if (swapped) {
-            cons_show("Swapped windows %d <-> %d", source_win, target_win);
-        } else {
-            cons_show("Window %d does not exist", source_win);
-        }
-    } else {
+        return TRUE;
+    }
+
+    if (source_win == target_win) {
         cons_show("Same source and target window supplied.");
+        return TRUE;
+    }
+
+    if (wins_get_by_num(source_win) == NULL) {
+        cons_show("Window %d does not exist", source_win);
+        return TRUE;
+    }
+
+    if (wins_get_by_num(target_win) == NULL) {
+        cons_show("Window %d does not exist", target_win);
+        return TRUE;
     }
 
+    wins_swap(source_win, target_win);
+    cons_show("Swapped windows %d <-> %d", source_win, target_win);
     return TRUE;
 }
 
diff --git a/src/ui/window_list.c b/src/ui/window_list.c
index 09a53ed1..798f4e41 100644
--- a/src/ui/window_list.c
+++ b/src/ui/window_list.c
@@ -844,7 +844,7 @@ wins_lost_connection(void)
     g_list_free(values);
 }
 
-gboolean
+void
 wins_swap(int source_win, int target_win)
 {
     ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win));
@@ -869,7 +869,6 @@ wins_swap(int source_win, int target_win)
                 wins_set_current_by_num(target_win);
                 ui_focus_win(console);
             }
-            return TRUE;
 
         // target window occupied
         } else {
@@ -894,10 +893,7 @@ wins_swap(int source_win, int target_win)
             if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
                 ui_focus_win(console);
             }
-            return TRUE;
         }
-    } else {
-        return FALSE;
     }
 }
 
diff --git a/src/ui/window_list.h b/src/ui/window_list.h
index f1a2ee24..68e72739 100644
--- a/src/ui/window_list.h
+++ b/src/ui/window_list.h
@@ -87,7 +87,7 @@ gboolean wins_tidy(void);
 GSList* wins_create_summary(gboolean unread);
 void wins_destroy(void);
 GList* wins_get_nums(void);
-gboolean wins_swap(int source_win, int target_win);
+void wins_swap(int source_win, int target_win);
 void wins_hide_subwin(ProfWin *window);
 void wins_show_subwin(ProfWin *window);