about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-04-30 22:10:03 +0100
committerJames Booth <boothj5@gmail.com>2015-04-30 22:10:03 +0100
commita3a4b6267b02d69761e64403aa131553c946fa96 (patch)
treed2e34fad4f0252a18e64022340c092de5de08704 /src
parent7730674f457a490c89d9a607988889296c2f2d27 (diff)
parentd68fb25ddef2f30c9d17991aa5d1d0e2a36d8386 (diff)
downloadprofani-tty-a3a4b6267b02d69761e64403aa131553c946fa96.tar.gz
Merge branch 'master' into pgp
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c24
-rw-r--r--src/ui/core.c104
-rw-r--r--src/ui/inputwin.c32
-rw-r--r--src/ui/ui.h3
-rw-r--r--src/ui/windows.c8
5 files changed, 76 insertions, 95 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 150ee364..51c6ceb4 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -733,10 +733,16 @@ gboolean
 cmd_win(gchar **args, struct cmd_help_t help)
 {
     int num = atoi(args[0]);
-    gboolean switched = ui_switch_win_num(num);
-    if (switched == FALSE) {
+
+    ProfWin *window = wins_get_by_num(num);
+    if (!window) {
         cons_show("Window %d does not exist.", num);
+    } else {
+        if (!wins_is_current(window)) {
+            ui_ev_focus_win(window);
+        }
     }
+
     return TRUE;
 }
 
@@ -2464,12 +2470,11 @@ cmd_form(gchar **args, struct cmd_help_t help)
             cmd_autocomplete_remove_form_fields(confwin->form);
         }
         wins_close_current();
-        ProfWin *current = (ProfWin*)wins_get_muc(confwin->roomjid);
-        if (current == NULL) {
-            current = wins_get_console();
+        ProfWin *new_current = (ProfWin*)wins_get_muc(confwin->roomjid);
+        if (!new_current) {
+            new_current = wins_get_console();
         }
-        int num = wins_get_num(current);
-        ui_switch_win_num(num);
+        ui_ev_focus_win(new_current);
     }
 
     return TRUE;
@@ -2775,9 +2780,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
     if (g_strcmp0(args[0], "config") == 0) {
         ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid);
 
-        if (confwin != NULL) {
-            num = wins_get_num(window);
-            ui_switch_win_num(num);
+        if (confwin) {
+            ui_ev_focus_win((ProfWin*)confwin);
         } else {
             iq_request_room_config_form(mucwin->roomjid);
         }
diff --git a/src/ui/core.c b/src/ui/core.c
index 59144223..22cf1168 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -865,45 +865,32 @@ ui_win_has_unsaved_form(int num)
     }
 }
 
-gboolean
-ui_switch_win(ProfWin *win)
+void
+ui_switch_win(ProfWin *window)
 {
-    int num = wins_get_num(win);
-    return ui_switch_win_num(num);
-}
+    assert(window != NULL);
 
-gboolean
-ui_switch_win_num(const int i)
-{
-    ProfWin *window = wins_get_by_num(i);
-    if (window) {
-        ProfWin *old_current = wins_get_current();
-        if (old_current->type == WIN_MUC_CONFIG) {
-            ProfMucConfWin *confwin = (ProfMucConfWin*)old_current;
-            cmd_autocomplete_remove_form_fields(confwin->form);
-        }
+    ProfWin *old_current = wins_get_current();
+    if (old_current->type == WIN_MUC_CONFIG) {
+        ProfMucConfWin *confwin = (ProfMucConfWin*)old_current;
+        cmd_autocomplete_remove_form_fields(confwin->form);
+    }
 
-        ProfWin *new_current = wins_get_by_num(i);
-        if (new_current->type == WIN_MUC_CONFIG) {
-            ProfMucConfWin *confwin = (ProfMucConfWin*)new_current;
-            cmd_autocomplete_add_form_fields(confwin->form);
-        }
+    if (window->type == WIN_MUC_CONFIG) {
+        ProfMucConfWin *confwin = (ProfMucConfWin*)window;
+        cmd_autocomplete_add_form_fields(confwin->form);
+    }
 
-        wins_set_current_by_num(i);
+    int i = wins_get_num(window);
+    wins_set_current_by_num(i);
 
-        if (i == 1) {
-            title_bar_console();
-            status_bar_current(1);
-            status_bar_active(1);
-        } else {
-            title_bar_switch();
-            status_bar_current(i);
-            status_bar_active(i);
-        }
-        return TRUE;
+    if (i == 1) {
+        title_bar_console();
     } else {
-        return FALSE;
+        title_bar_switch();
     }
+    status_bar_current(i);
+    status_bar_active(i);
 }
 
 void
@@ -1358,34 +1345,25 @@ void
 ui_new_private_win(const char * const fulljid)
 {
     ProfWin *window = (ProfWin*)wins_get_private(fulljid);
-    int num = 0;
-
-    // create new window
-    if (window == NULL) {
+    if (!window) {
         window = wins_new_private(fulljid);
-        num = wins_get_num(window);
-    } else {
-        num = wins_get_num(window);
     }
-
-    ui_switch_win_num(num);
+    ui_switch_win(window);
 }
 
 void
 ui_create_xmlconsole_win(void)
 {
     ProfWin *window = wins_new_xmlconsole();
-    int num = wins_get_num(window);
-    ui_switch_win_num(num);
+    ui_switch_win(window);
 }
 
 void
 ui_open_xmlconsole_win(void)
 {
     ProfXMLWin *xmlwin = wins_get_xmlconsole();
-    if (xmlwin != NULL) {
-        int num = wins_get_num((ProfWin*)xmlwin);
-        ui_switch_win_num(num);
+    if (xmlwin) {
+        ui_switch_win((ProfWin*)xmlwin);
     }
 }
 
@@ -1452,30 +1430,19 @@ void
 ui_outgoing_private_msg(const char * const fulljid, const char * const message)
 {
     ProfWin *window = (ProfWin*)wins_get_private(fulljid);
-    int num = 0;
-
-    // create new window
-    if (window == NULL) {
+    if (!window) {
         window = wins_new_private(fulljid);
-        num = wins_get_num(window);
-
-    // use existing window
-    } else {
-        num = wins_get_num(window);
     }
 
     win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message);
-    ui_switch_win_num(num);
+    ui_switch_win(window);
 }
 
 void
 ui_room_join(const char * const roomjid, gboolean focus)
 {
     ProfWin *window = (ProfWin*)wins_get_muc(roomjid);
-    int num = 0;
-
-    // create new window
-    if (window == NULL) {
+    if (!window) {
         window = wins_new_muc(roomjid);
     }
 
@@ -1493,11 +1460,11 @@ ui_room_join(const char * const roomjid, gboolean focus)
     }
     win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", "");
 
-    num = wins_get_num(window);
 
     if (focus) {
-        ui_switch_win_num(num);
+        ui_switch_win(window);
     } else {
+        int num = wins_get_num(window);
         status_bar_active(num);
         ProfWin *console = wins_get_console();
         char *nick = muc_nick(roomjid);
@@ -1509,8 +1476,7 @@ void
 ui_switch_to_room(const char * const roomjid)
 {
     ProfWin *window = (ProfWin*)wins_get_muc(roomjid);
-    int num = wins_get_num(window);
-    ui_switch_win_num(num);
+    ui_switch_win(window);
 }
 
 void
@@ -2682,9 +2648,7 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form)
     ProfMucConfWin *confwin = (ProfMucConfWin*)window;
     assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
 
-    int num = wins_get_num(window);
-    ui_switch_win_num(num);
-
+    ui_switch_win(window);
     ui_show_form(confwin);
 
     win_print(window, '-', NULL, 0, 0, "", "");
@@ -2739,11 +2703,11 @@ ui_handle_room_config_submit_result(const char * const roomjid)
         }
 
         if (muc_window) {
-            int num = wins_get_num(muc_window);
-            ui_switch_win_num(num);
+            ui_switch_win((ProfWin*)muc_window);
             win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful");
         } else {
-            ui_switch_win_num(1);
+            ProfWin *console = wins_get_console();
+            ui_switch_win(console);
             cons_show("Room configuration successful: %s", roomjid);
         }
     } else {
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 935fd4ce..6cfbde47 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -63,6 +63,7 @@
 #include "ui/statusbar.h"
 #include "ui/inputwin.h"
 #include "ui/windows.h"
+#include "event/ui_events.h"
 #include "xmpp/xmpp.h"
 
 static WINDOW *inp_win;
@@ -449,73 +450,84 @@ _inp_rl_tab_handler(int count, int key)
     return 0;
 }
 
+static void
+_go_to_win(int i)
+{
+    ProfWin *window = wins_get_by_num(i);
+    if (window) {
+        if (!wins_is_current(window)) {
+            ui_ev_focus_win(window);
+        }
+    }
+}
+
 static int
 _inp_rl_win1_handler(int count, int key)
 {
-    ui_switch_win_num(1);
+    _go_to_win(1);
     return 0;
 }
 
 static int
 _inp_rl_win2_handler(int count, int key)
 {
-    ui_switch_win_num(2);
+    _go_to_win(2);
     return 0;
 }
 
 static int
 _inp_rl_win3_handler(int count, int key)
 {
-    ui_switch_win_num(3);
+    _go_to_win(3);
     return 0;
 }
 
 static int
 _inp_rl_win4_handler(int count, int key)
 {
-    ui_switch_win_num(4);
+    _go_to_win(4);
     return 0;
 }
 
 static int
 _inp_rl_win5_handler(int count, int key)
 {
-    ui_switch_win_num(5);
+    _go_to_win(5);
     return 0;
 }
 
 static int
 _inp_rl_win6_handler(int count, int key)
 {
-    ui_switch_win_num(6);
+    _go_to_win(6);
     return 0;
 }
 
 static int
 _inp_rl_win7_handler(int count, int key)
 {
-    ui_switch_win_num(7);
+    _go_to_win(7);
     return 0;
 }
 
 static int
 _inp_rl_win8_handler(int count, int key)
 {
-    ui_switch_win_num(8);
+    _go_to_win(8);
     return 0;
 }
 
 static int
 _inp_rl_win9_handler(int count, int key)
 {
-    ui_switch_win_num(9);
+    _go_to_win(9);
     return 0;
 }
 
 static int
 _inp_rl_win0_handler(int count, int key)
 {
-    ui_switch_win_num(0);
+    _go_to_win(0);
     return 0;
 }
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index e42505bc..529e0f92 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -59,8 +59,7 @@ void ui_close(void);
 void ui_redraw(void);
 void ui_resize(void);
 GSList* ui_get_chat_recipients(void);
-gboolean ui_switch_win_num(const int i);
-gboolean ui_switch_win(ProfWin *win);
+void ui_switch_win(ProfWin *window);
 void ui_next_win(void);
 void ui_previous_win(void);
 void ui_sigwinch_handler(int sig);
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 269bea1d..4cc0fef7 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -644,6 +644,7 @@ gboolean
 wins_swap(int source_win, int target_win)
 {
     ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win));
+    ProfWin *console = wins_get_console();
 
     if (source) {
         ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win));
@@ -660,7 +661,7 @@ wins_swap(int source_win, int target_win)
             }
             if (wins_get_current_num() == source_win) {
                 wins_set_current_by_num(target_win);
-                ui_switch_win_num(1);
+                ui_switch_win(console);
             }
             return TRUE;
 
@@ -681,7 +682,7 @@ wins_swap(int source_win, int target_win)
                 status_bar_active(source_win);
             }
             if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
-                ui_switch_win_num(1);
+                ui_switch_win(console);
             }
             return TRUE;
         }
@@ -740,7 +741,8 @@ wins_tidy(void)
 
         windows = new_windows;
         current = 1;
-        ui_switch_win_num(1);
+        ProfWin *console = wins_get_console();
+        ui_switch_win(console);
         g_list_free(keys);
         return TRUE;
     } else {