about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-24 23:06:42 +0100
committerJames Booth <boothj5@gmail.com>2014-04-24 23:06:42 +0100
commite9ddbab5851a406ea4177ce41d4adb1c7ef850b4 (patch)
tree9f8cdc171cbbb1ae3361a5a968167e2e23d4b53f
parent547b6cf4dad245876bdd1980f1ad5abfeb843af0 (diff)
downloadprofani-tty-e9ddbab5851a406ea4177ce41d4adb1c7ef850b4.tar.gz
Allow /wins swap to move to empty position
-rw-r--r--src/command/commands.c2
-rw-r--r--src/ui/core.c1
-rw-r--r--src/ui/windows.c22
3 files changed, 23 insertions, 2 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 8a37305a..83fe4322 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -478,6 +478,8 @@ cmd_wins(gchar **args, struct cmd_help_t help)
             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) {
+                cons_show("Window 10 does not exist");
             } else if (source_win != target_win) {
                 gboolean swapped = ui_swap_wins(source_win, target_win);
                 if (swapped) {
diff --git a/src/ui/core.c b/src/ui/core.c
index 3b7789d9..383eafef 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -691,7 +691,6 @@ static gboolean
 _ui_switch_win(const int i)
 {
     if (ui_win_exists(i)) {
-        ui_current_page_off();
         ProfWin *new_current = wins_get_by_num(i);
         wins_set_current_by_num(i);
         ui_current_page_off();
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 48ab9ea8..44639040 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -394,6 +394,7 @@ wins_swap(int source_win, int target_win)
     if (source != NULL) {
         ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win));
 
+        // target window empty
         if (target == NULL) {
             g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
             status_bar_inactive(source_win);
@@ -407,8 +408,27 @@ wins_swap(int source_win, int target_win)
                 ui_switch_win(1);
             }
             return TRUE;
+
+        // target window occupied
         } else {
-            return FALSE;
+            g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
+            g_hash_table_steal(windows, GINT_TO_POINTER(target_win));
+            g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target);
+            g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source);
+            if (source->unread > 0) {
+                status_bar_new(target_win);
+            } else {
+                status_bar_active(target_win);
+            }
+            if (target->unread > 0) {
+                status_bar_new(source_win);
+            } else {
+                status_bar_active(source_win);
+            }
+            if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
+                ui_switch_win(1);
+            }
+            return TRUE;
         }
     } else {
         return FALSE;