summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command.c4
-rw-r--r--src/gui/curses/gui-display.c66
-rw-r--r--src/irc/irc-server.c18
-rw-r--r--src/irc/irc.h1
-rw-r--r--src/weechat.c4
5 files changed, 59 insertions, 34 deletions
diff --git a/src/command.c b/src/command.c
index 46f9568cc..79b23356f 100644
--- a/src/command.c
+++ b/src/command.c
@@ -552,7 +552,7 @@ weechat_cmd_connect (int argc, char **argv)
return -1;
}
if (!ptr_server->window)
- server_create_window (ptr_server);
+ gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server))
{
irc_login (ptr_server);
@@ -935,7 +935,7 @@ weechat_cmd_server (int argc, char **argv)
if (new_server->autoconnect)
{
- server_create_window (new_server);
+ gui_window_new (new_server, NULL);
if (server_connect (new_server))
irc_login (new_server);
}
diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c
index de9623917..26c2100f9 100644
--- a/src/gui/curses/gui-display.c
+++ b/src/gui/curses/gui-display.c
@@ -958,17 +958,34 @@ gui_draw_window_input (t_gui_window *window)
}
else
{
- sprintf (format, "%%s> %%-%ds", input_width);
- if (SERVER(window) && (SERVER(window)->is_connected))
- ptr_nickname = SERVER(window)->nick;
+ if (SERVER(window))
+ {
+ sprintf (format, "%%s> %%-%ds", input_width);
+ if (SERVER(window) && (SERVER(window)->is_connected))
+ ptr_nickname = SERVER(window)->nick;
+ else
+ ptr_nickname = cfg_look_no_nickname;
+ mvwprintw (window->win_input, 0, 0, format,
+ ptr_nickname,
+ window->input_buffer + window->input_buffer_1st_display);
+ wclrtoeol (window->win_input);
+ move (LINES - 1, strlen (ptr_nickname) + 2 +
+ (window->input_buffer_pos - window->input_buffer_1st_display));
+ }
else
- ptr_nickname = cfg_look_no_nickname;
- mvwprintw (window->win_input, 0, 0, format,
- ptr_nickname,
- window->input_buffer + window->input_buffer_1st_display);
- wclrtoeol (window->win_input);
- move (LINES - 1, strlen (ptr_nickname) + 2 +
- (window->input_buffer_pos - window->input_buffer_1st_display));
+ {
+ sprintf (format, "%%s> %%-%ds", input_width);
+ if (SERVER(window) && (SERVER(window)->is_connected))
+ ptr_nickname = SERVER(window)->nick;
+ else
+ ptr_nickname = cfg_look_no_nickname;
+ mvwprintw (window->win_input, 0, 0, format,
+ ptr_nickname,
+ window->input_buffer + window->input_buffer_1st_display);
+ wclrtoeol (window->win_input);
+ move (LINES - 1, strlen (ptr_nickname) + 2 +
+ (window->input_buffer_pos - window->input_buffer_1st_display));
+ }
}
wrefresh (window->win_input);
@@ -1228,7 +1245,21 @@ gui_window_new (void *server, void *channel
/*int x, int y, int width, int height*/)
{
t_gui_window *new_window;
-
+
+ if (gui_windows)
+ {
+ if (!SERVER(gui_windows))
+ {
+ if (server)
+ ((t_irc_server *)(server))->window = gui_windows;
+ if (channel)
+ ((t_irc_channel *)(channel))->window = gui_windows;
+ SERVER(gui_windows) = server;
+ CHANNEL(gui_windows) = channel;
+ return gui_windows;
+ }
+ }
+
if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window)))))
{
/* assign server and channel to window */
@@ -1289,6 +1320,7 @@ gui_window_new (void *server, void *channel
}
else
return NULL;
+
return new_window;
}
@@ -1301,9 +1333,13 @@ gui_window_free (t_gui_window *window)
{
t_gui_line *ptr_line;
t_gui_message *ptr_message;
+ int create_new;
+
+ create_new = (window->server || window->channel);
/* TODO: manage splitted windows! */
- if (window == gui_current_window)
+ if ((window == gui_current_window) &&
+ ((window->next_window) || (window->prev_window)))
gui_switch_to_previous_window ();
/* free lines and messages */
@@ -1338,6 +1374,10 @@ gui_window_free (t_gui_window *window)
last_gui_window = window->prev_window;
free (window);
+
+ /* always at least one window */
+ if (!gui_windows && create_new)
+ gui_window_new (NULL, NULL);
}
/*
@@ -1539,7 +1579,7 @@ gui_end ()
/* TODO: free input buffer, lines, messages, completion */
}
- /* end of ncurses output */
+ /* end of curses output */
refresh ();
endwin ();
}
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index daa059ca3..4f82fd747 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -114,22 +114,6 @@ server_alloc ()
}
/*
- * server_create_window: create windows for a server
- */
-
-void
-server_create_window (t_irc_server *server)
-{
- if (!SERVER(gui_windows))
- {
- server->window = gui_windows;
- SERVER(gui_windows) = server;
- }
- else
- gui_window_new (server, NULL);
-}
-
-/*
* server_destroy: free server data (not struct himself)
*/
@@ -181,6 +165,8 @@ server_free (t_irc_server *server)
(server->next_server)->prev_server = server->prev_server;
server_destroy (server);
+ if (server->window)
+ gui_window_free (server->window);
free (server);
irc_servers = new_irc_servers;
}
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 389a9f70f..8dcd30639 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -140,7 +140,6 @@ extern t_irc_channel *current_channel;
extern void server_init (t_irc_server *);
extern t_irc_server *server_alloc ();
-extern void server_create_window (t_irc_server *);
extern void server_destroy (t_irc_server *);
extern void server_free (t_irc_server *);
extern void server_free_all ();
diff --git a/src/weechat.c b/src/weechat.c
index f8c8dd2d1..e638b095a 100644
--- a/src/weechat.c
+++ b/src/weechat.c
@@ -211,8 +211,8 @@ wee_init_log ()
void
wee_shutdown ()
{
- gui_end ();
server_free_all ();
+ gui_end ();
if (log_file)
fclose (log_file);
exit (0);
@@ -298,7 +298,7 @@ main (int argc, char *argv[])
{
if (ptr_server->autoconnect)
{
- server_create_window (ptr_server);
+ gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server))
irc_login (ptr_server);
}