about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-02-27 02:01:19 +0000
committerJames Booth <boothj5@gmail.com>2012-02-27 02:01:19 +0000
commit5c9061671e05ad31091fe52f70f37fe0a3129c82 (patch)
tree68ab0f087a7197a1a07d280615646583dbc0b386
parentaa680b98a2589f4e96824d7267fe07e6ca9a0567 (diff)
downloadprofani-tty-5c9061671e05ad31091fe52f70f37fe0a3129c82.tar.gz
Moved window switching
-rw-r--r--profanity.c38
-rw-r--r--windows.c56
-rw-r--r--windows.h3
3 files changed, 40 insertions, 57 deletions
diff --git a/profanity.c b/profanity.c
index 8b64900f..a4c571c5 100644
--- a/profanity.c
+++ b/profanity.c
@@ -34,7 +34,6 @@
 
 static void _profanity_init(int disable_tls);
 static void _profanity_event_loop(int *ch, char *cmd, int *size);
-static void _process_special_keys(int *ch);
 
 void profanity_main(int disable_tls)
 {
@@ -69,41 +68,6 @@ static void _profanity_event_loop(int *ch, char *cmd, int *size)
     usleep(1);
     gui_refresh();
     jabber_process_events();
-    _process_special_keys(ch);
+    win_handle_switch(ch);
     inp_poll_char(ch, cmd, size);
 } 
-
-static void _process_special_keys(int *ch)
-{
-    if (*ch == KEY_F(1)) {
-        if (win_is_active(0))
-            win_switch_to(0);
-    } else if (*ch == KEY_F(2)) {
-        if (win_is_active(1))
-            win_switch_to(1);
-    } else if (*ch == KEY_F(3)) {
-        if (win_is_active(2))
-            win_switch_to(2);
-    } else if (*ch == KEY_F(4)) {
-        if (win_is_active(3))
-            win_switch_to(3);
-    } else if (*ch == KEY_F(5)) {
-        if (win_is_active(4))
-            win_switch_to(4);
-    } else if (*ch == KEY_F(6)) {
-        if (win_is_active(5))
-            win_switch_to(5);
-    } else if (*ch == KEY_F(7)) {
-        if (win_is_active(6))
-            win_switch_to(6);
-    } else if (*ch == KEY_F(8)) {
-        if (win_is_active(7))
-            win_switch_to(7);
-    } else if (*ch == KEY_F(9)) {
-        if (win_is_active(8))
-            win_switch_to(8);
-    } else if (*ch == KEY_F(10)) {
-        if (win_is_active(9))
-            win_switch_to(9);
-    }
-}
diff --git a/windows.c b/windows.c
index 80c82d94..c7a6fcd1 100644
--- a/windows.c
+++ b/windows.c
@@ -32,6 +32,7 @@ static int _curr_win = 0;
 static void _create_windows(void);
 static int _find_win(char *contact);
 static void _current_window_refresh();
+static void _win_switch_if_active(int i);
 static void _win_show_time(int win);
 static void _win_show_user(int win, char *user, int colour);
 
@@ -73,24 +74,6 @@ void gui_close(void)
     endwin();
 }
 
-int win_is_active(int i)
-{
-    if (strcmp(_wins[i].from, "") == 0)
-        return FALSE;
-    else
-        return TRUE;
-}
-
-void win_switch_to(int i)
-{    
-    _curr_win = i;
-
-    if (i == 0)
-        title_bar_title();
-    else
-        title_bar_show(_wins[i].from);
-}
-
 void win_close_win(void)
 {
     // reset the chat win to unused
@@ -220,6 +203,31 @@ void cons_bad_message(void)
     cons_show("Usage: /msg user@host message");
 }
 
+void win_handle_switch(int *ch)
+{
+    if (*ch == KEY_F(1)) {
+        _win_switch_if_active(0);
+    } else if (*ch == KEY_F(2)) {
+        _win_switch_if_active(1);
+    } else if (*ch == KEY_F(3)) {
+        _win_switch_if_active(2);
+    } else if (*ch == KEY_F(4)) {
+        _win_switch_if_active(3);
+    } else if (*ch == KEY_F(5)) {
+        _win_switch_if_active(4);
+    } else if (*ch == KEY_F(6)) {
+        _win_switch_if_active(5);
+    } else if (*ch == KEY_F(7)) {
+        _win_switch_if_active(6);
+    } else if (*ch == KEY_F(8)) {
+        _win_switch_if_active(7);
+    } else if (*ch == KEY_F(9)) {
+        _win_switch_if_active(8);
+    } else if (*ch == KEY_F(10)) {
+        _win_switch_if_active(9);
+    }
+}
+
 static void _create_windows(void)
 {
     int rows, cols;
@@ -273,6 +281,18 @@ static int _find_win(char *contact)
     return i;
 }
 
+static void _win_switch_if_active(int i)
+{
+    if (strcmp(_wins[i].from, "") != 0) {
+        _curr_win = i;
+
+        if (i == 0)
+            title_bar_title();
+        else
+            title_bar_show(_wins[i].from);
+    }
+}
+
 static void _win_show_time(int win)
 {
     char tstmp[80];
diff --git a/windows.h b/windows.h
index 0b478952..1a59d79e 100644
--- a/windows.h
+++ b/windows.h
@@ -48,13 +48,12 @@ void title_bar_connected(void);
 void title_bar_disconnected(void);
 
 // main window actions
-int win_is_active(int i);
-void win_switch_to(int i);
 void win_close_win(void);
 int win_in_chat(void);
 char *win_get_recipient(void);
 void win_show_incomming_msg(char *from, char *message);
 void win_show_outgoing_msg(char *from, char *to, char *message);
+void win_handle_switch(int *ch);
 
 // console window actions
 void cons_help(void);