about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/status_bar.c4
-rw-r--r--src/windows.c141
2 files changed, 92 insertions, 53 deletions
diff --git a/src/status_bar.c b/src/status_bar.c
index a00a2ad3..52d90439 100644
--- a/src/status_bar.c
+++ b/src/status_bar.c
@@ -144,7 +144,7 @@ status_bar_active(const int win)
     int cols = getmaxx(stdscr);
 
     wattron(status_bar, COLOUR_STATUS_ACTIVE);
-    if (win < 10)
+    if (win+1 < 10)
         mvwprintw(status_bar, 0, cols - 31 + active_pos, "%d", win+1);
     else
         mvwprintw(status_bar, 0, cols - 31 + active_pos, "0");
@@ -165,7 +165,7 @@ status_bar_new(const int win)
 
     wattron(status_bar, COLOUR_STATUS_NEW);
     wattron(status_bar, A_BLINK);
-    if (win < 10)
+    if (win+1 < 10)
         mvwprintw(status_bar, 0, cols - 31 + active_pos, "%d", win+1);
     else
         mvwprintw(status_bar, 0, cols - 31 + active_pos, "0");
diff --git a/src/windows.c b/src/windows.c
index 44b9f0b1..c105c48e 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -377,70 +377,106 @@ win_show_incomming_msg(const char * const from, const char * const message,
     if (win_index == NUM_WINS)
         win_index = _new_prof_win(from, win_type);
 
-    WINDOW *win = windows[win_index]->win;
-
-    // currently viewing chat window with sender
-    if (win_index == current_index) {
+    // no spare windows left
+    if (win_index == 0) {
         if (tv_stamp == NULL) {
-            _win_show_time(win);
+            _win_show_time(console->win);
         } else {
             GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
             gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
-            wattron(win, COLOUR_TIME);
-            wprintw(win, "%s - ", date_fmt);
-            wattroff(win, COLOUR_TIME);
+            wattron(console->win, COLOUR_TIME);
+            wprintw(console->win, "%s - ", date_fmt);
+            wattroff(console->win, COLOUR_TIME);
             g_date_time_unref(time);
             g_free(date_fmt);
         }
 
         if (strncmp(message, "/me ", 4) == 0) {
-            wattron(win, COLOUR_THEM);
-            wprintw(win, "*%s ", from);
-            wprintw(win, message + 4);
-            wprintw(win, "\n");
-            wattroff(win, COLOUR_THEM);
+            wattron(console->win, COLOUR_THEM);
+            wprintw(console->win, "*%s ", from);
+            wprintw(console->win, message + 4);
+            wprintw(console->win, "\n");
+            wattroff(console->win, COLOUR_THEM);
         } else {
-            _win_show_user(win, from, 1);
-            _win_show_message(win, message);
+            _win_show_user(console->win, from, 1);
+            _win_show_message(console->win, message);
         }
-        title_bar_set_typing(FALSE);
-        title_bar_draw();
-        status_bar_active(win_index);
-        dirty = TRUE;
 
-    // not currently viewing chat window with sender
-    } else {
-        status_bar_new(win_index);
-        _cons_show_incoming_message(from, win_index);
-        if (prefs_get_flash())
-            flash();
+        cons_bad_show("Windows all used, close a window to respond.");
 
-        windows[win_index]->unread++;
-        if (prefs_get_chlog() && prefs_get_history()) {
-            _win_show_history(win, win_index, from);
-        }
-
-        if (tv_stamp == NULL) {
-            _win_show_time(win);
+        if (current_index == 0) {
+           dirty = TRUE;
         } else {
-            GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
-            gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
-            wattron(win, COLOUR_TIME);
-            wprintw(win, "%s - ", date_fmt);
-            wattroff(win, COLOUR_TIME);
-            g_date_time_unref(time);
-            g_free(date_fmt);
+            status_bar_new(0);
         }
 
-        if (strncmp(message, "/me ", 4) == 0) {
-            wattron(win, COLOUR_THEM);
-            wprintw(win, "*%s ", from);
-            wprintw(win, message + 4);
-            wprintw(win, "\n");
-            wattroff(win, COLOUR_THEM);
+    // window found or created
+    } else {
+        WINDOW *win = windows[win_index]->win;
+
+        // currently viewing chat window with sender
+        if (win_index == current_index) {
+            if (tv_stamp == NULL) {
+                _win_show_time(win);
+            } else {
+                GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
+                gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
+                wattron(win, COLOUR_TIME);
+                wprintw(win, "%s - ", date_fmt);
+                wattroff(win, COLOUR_TIME);
+                g_date_time_unref(time);
+                g_free(date_fmt);
+            }
+
+            if (strncmp(message, "/me ", 4) == 0) {
+                wattron(win, COLOUR_THEM);
+                wprintw(win, "*%s ", from);
+                wprintw(win, message + 4);
+                wprintw(win, "\n");
+                wattroff(win, COLOUR_THEM);
+            } else {
+                _win_show_user(win, from, 1);
+                _win_show_message(win, message);
+            }
+            title_bar_set_typing(FALSE);
+            title_bar_draw();
+            status_bar_active(win_index);
+            dirty = TRUE;
+
+        // not currently viewing chat window with sender
         } else {
-            _win_show_user(win, from, 1);
-            _win_show_message(win, message);
+            status_bar_new(win_index);
+            _cons_show_incoming_message(from, win_index);
+            if (prefs_get_flash())
+                flash();
+
+            windows[win_index]->unread++;
+            if (prefs_get_chlog() && prefs_get_history()) {
+                _win_show_history(win, win_index, from);
+            }
+
+            if (tv_stamp == NULL) {
+                _win_show_time(win);
+            } else {
+                GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
+                gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
+                wattron(win, COLOUR_TIME);
+                wprintw(win, "%s - ", date_fmt);
+                wattroff(win, COLOUR_TIME);
+                g_date_time_unref(time);
+                g_free(date_fmt);
+            }
+
+            if (strncmp(message, "/me ", 4) == 0) {
+                wattron(win, COLOUR_THEM);
+                wprintw(win, "*%s ", from);
+                wprintw(win, message + 4);
+                wprintw(win, "\n");
+                wattroff(win, COLOUR_THEM);
+            } else {
+                _win_show_user(win, from, 1);
+                _win_show_message(win, message);
+            }
         }
     }
 
@@ -1497,10 +1533,13 @@ _new_prof_win(const char * const contact, win_type_t type)
         }
     }
 
-    int cols = getmaxx(stdscr);
-    windows[i] = window_create(contact, cols, type);
-
-    return i;
+    if (i != NUM_WINS) {
+        int cols = getmaxx(stdscr);
+        windows[i] = window_create(contact, cols, type);
+        return i;
+    } else {
+        return 0;
+    }
 }
 
 void
.org> 2020-07-07 14:18:57 +0200 Apply coding style' href='/danisanti/profani-tty/commit/src/ui/window_list.h?id=a2726b6a7d16f5f846a882fbbe9127e4604bb8bb'>a2726b6a ^
1926ceea ^
3b0f7e10 ^
0146e625 ^
601a8803 ^
0146e625 ^
3b0f7e10 ^
a2726b6a ^
0146e625 ^
3b0f7e10 ^

e8420e72 ^
1526a001 ^
a2726b6a ^
601a8803 ^
601a8803 ^
a2726b6a ^
83422656 ^
601a8803 ^

3b0f7e10 ^

601a8803 ^
13675fbf ^
601a8803 ^
0920b65d ^
6dd11f0f ^
bca37984 ^
3b0f7e10 ^
e96af853 ^
a2726b6a ^

601a8803 ^
a2726b6a ^
e5447cf3 ^
a2726b6a ^
2e99df1a ^
e5447cf3 ^
a2726b6a ^

ce32d874 ^
601a8803 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106