about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-24 21:50:59 +0100
committerJames Booth <boothj5@gmail.com>2014-04-24 21:50:59 +0100
commit547b6cf4dad245876bdd1980f1ad5abfeb843af0 (patch)
tree35be77f24e109a078db269d64cfcb4341bedebf3 /src/ui
parent034a98587c239745d0af07a0d3ef369e46c92ea9 (diff)
downloadprofani-tty-547b6cf4dad245876bdd1980f1ad5abfeb843af0.tar.gz
Added command /wins swap
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/core.c7
-rw-r--r--src/ui/ui.h1
-rw-r--r--src/ui/windows.c29
-rw-r--r--src/ui/windows.h1
4 files changed, 38 insertions, 0 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 8f385cf2..3b7789d9 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -950,6 +950,12 @@ _ui_prune_wins(void)
     }
 }
 
+static gboolean
+_ui_swap_wins(int source_win, int target_win)
+{
+    return wins_swap(source_win, target_win);
+}
+
 static win_type_t
 _ui_current_win_type(void)
 {
@@ -1987,4 +1993,5 @@ ui_init_module(void)
     ui_create_xmlconsole_win = _ui_create_xmlconsole_win;
     ui_xmlconsole_exists = _ui_xmlconsole_exists;
     ui_handle_room_join_error = _ui_handle_room_join_error;
+    ui_swap_wins = _ui_swap_wins;
 }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 14f7137c..d56c8f5d 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -147,6 +147,7 @@ gboolean (*ui_duck_exists)(void);
 
 void (*ui_tidy_wins)(void);
 void (*ui_prune_wins)(void);
+gboolean (*ui_swap_wins)(int source_win, int target_win);
 
 void (*ui_auto_away)(void);
 void (*ui_end_auto_away)(void);
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 82659be5..48ab9ea8 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -387,6 +387,35 @@ wins_lost_connection(void)
 }
 
 gboolean
+wins_swap(int source_win, int target_win)
+{
+    ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win));
+
+    if (source != NULL) {
+        ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win));
+
+        if (target == NULL) {
+            g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
+            status_bar_inactive(source_win);
+            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 ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
+                ui_switch_win(1);
+            }
+            return TRUE;
+        } else {
+            return FALSE;
+        }
+    } else {
+        return FALSE;
+    }
+}
+
+gboolean
 wins_tidy(void)
 {
     gboolean tidy_required = FALSE;
diff --git a/src/ui/windows.h b/src/ui/windows.h
index cbe219df..7b3513fb 100644
--- a/src/ui/windows.h
+++ b/src/ui/windows.h
@@ -50,5 +50,6 @@ void wins_destroy(void);
 GList * wins_get_nums(void);
 gboolean wins_xmlconsole_exists(void);
 ProfWin * wins_get_xmlconsole(void);
+gboolean wins_swap(int source_win, int target_win);
 
 #endif