mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
Improved window management: new window may have different size (% of current
window size), window sizes are automatically recomputed when term window is resized
This commit is contained in:
+92
-17
@@ -66,8 +66,9 @@ t_weechat_command weechat_commands[] =
|
||||
N_("servername: server name to disconnect"),
|
||||
0, 1, weechat_cmd_disconnect, NULL },
|
||||
{ "debug", N_("print debug messages"),
|
||||
N_("dump"),
|
||||
N_("dump: save memory dump in WeeChat log file (same dump is written when WeeChat crashes)"),
|
||||
N_("dump | windows"),
|
||||
N_("dump: save memory dump in WeeChat log file (same dump is written when WeeChat crashes)\n"
|
||||
"windows: display windows tree"),
|
||||
1, 1, weechat_cmd_debug, NULL },
|
||||
{ "help", N_("display help about commands"),
|
||||
N_("[command]"), N_("command: name of a WeeChat or IRC command"),
|
||||
@@ -140,14 +141,17 @@ t_weechat_command weechat_commands[] =
|
||||
N_("-o: send uptime on current channel as an IRC message"),
|
||||
0, 1, weechat_cmd_uptime, NULL },
|
||||
{ "window", N_("manage windows"),
|
||||
N_("[list | -1 | +1 | b# | splith | splitv | [merge [down | up | left | right | all]]]"),
|
||||
N_("[list | -1 | +1 | b# | splith [pct] | splitv [pct] | [merge [all]]]"),
|
||||
N_("list: list opened windows (no parameter implies this list)\n"
|
||||
"-1: jump to previous window\n"
|
||||
"+1: jump to next window\n"
|
||||
"b#: jump to next window displaying buffer number #\n"
|
||||
"splith: split current window horizontally\n"
|
||||
"splitv: split current window vertically\n"
|
||||
"merge: merge window with another"),
|
||||
"merge: merge window with another (all = keep only one window)\n\n"
|
||||
"For splith and splitv, pct is a pourcentage which represents "
|
||||
"size of new window, computed with current window as size reference. "
|
||||
"For example 25 means create a new window with size = current_size / 4"),
|
||||
0, 2, weechat_cmd_window, NULL },
|
||||
{ NULL, NULL, NULL, NULL, 0, 0, NULL, NULL }
|
||||
};
|
||||
@@ -1296,6 +1300,45 @@ weechat_cmd_connect (int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_debug_display_windows: display tree of windows
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_cmd_debug_display_windows (t_gui_window_tree *tree, int indent)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (tree)
|
||||
{
|
||||
for (i = 0; i < indent; i++)
|
||||
gui_printf_nolog (NULL, " ");
|
||||
|
||||
if (tree->window)
|
||||
{
|
||||
/* leaf */
|
||||
gui_printf_nolog (NULL, "leaf: %X (parent:%X), win=%X, child1=%X, child2=%X, %d,%d %dx%d, %d%%x%d%%\n",
|
||||
tree, tree->parent_node, tree->window,
|
||||
tree->child1, tree->child2,
|
||||
tree->window->win_x, tree->window->win_y,
|
||||
tree->window->win_width, tree->window->win_height,
|
||||
tree->window->win_width_pct, tree->window->win_height_pct);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* node */
|
||||
gui_printf_nolog (NULL, "node: %X (parent:%X), win=%X, child1=%X, child2=%X)\n",
|
||||
tree, tree->parent_node, tree->window,
|
||||
tree->child1, tree->child2);
|
||||
}
|
||||
|
||||
if (tree->child1)
|
||||
weechat_cmd_debug_display_windows (tree->child1, indent + 1);
|
||||
if (tree->child2)
|
||||
weechat_cmd_debug_display_windows (tree->child2, indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_cmd_debug: print debug messages
|
||||
*/
|
||||
@@ -1316,6 +1359,12 @@ weechat_cmd_debug (int argc, char **argv)
|
||||
{
|
||||
wee_dump (0);
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "windows") == 0)
|
||||
{
|
||||
gui_printf_nolog (NULL, "\n");
|
||||
gui_printf_nolog (NULL, "DEBUG: windows tree:\n");
|
||||
weechat_cmd_debug_display_windows (gui_windows_tree, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (NULL, NULL, PREFIX_ERROR);
|
||||
@@ -1918,6 +1967,7 @@ weechat_cmd_server (int argc, char **argv)
|
||||
int i;
|
||||
t_irc_server server, *ptr_server, *server_found, *new_server;
|
||||
t_gui_buffer *ptr_buffer;
|
||||
char *server_name;
|
||||
|
||||
if ((argc == 0) || (argc == 1))
|
||||
{
|
||||
@@ -2008,13 +2058,17 @@ weechat_cmd_server (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
server_name = strdup (server_found->name);
|
||||
|
||||
server_free (server_found);
|
||||
|
||||
irc_display_prefix (NULL, NULL, PREFIX_INFO);
|
||||
gui_printf (NULL, _("Server %s%s%s has been deleted\n"),
|
||||
GUI_COLOR(COLOR_WIN_CHAT_SERVER),
|
||||
server_found->name,
|
||||
server_name,
|
||||
GUI_COLOR(COLOR_WIN_CHAT));
|
||||
if (server_name)
|
||||
free (server_name);
|
||||
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
|
||||
@@ -2758,26 +2812,36 @@ weechat_cmd_window (int argc, char **argv)
|
||||
if (ascii_strcasecmp (argv[0], "splith") == 0)
|
||||
{
|
||||
/* split window horizontally */
|
||||
gui_window_split_horiz (gui_current_window);
|
||||
if (argc > 1)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (argv[1], &error, 10);
|
||||
if ((error) && (error[0] == '\0')
|
||||
&& (number > 0) && (number < 100))
|
||||
gui_window_split_horiz (gui_current_window, number);
|
||||
}
|
||||
else
|
||||
gui_window_split_horiz (gui_current_window, 50);
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "splitv") == 0)
|
||||
{
|
||||
/* split window vertically */
|
||||
gui_window_split_vertic (gui_current_window);
|
||||
if (argc > 1)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (argv[1], &error, 10);
|
||||
if ((error) && (error[0] == '\0')
|
||||
&& (number > 0) && (number < 100))
|
||||
gui_window_split_vertic (gui_current_window, number);
|
||||
}
|
||||
else
|
||||
gui_window_split_vertic (gui_current_window, 50);
|
||||
}
|
||||
else if (ascii_strcasecmp (argv[0], "merge") == 0)
|
||||
{
|
||||
if (argc >= 2)
|
||||
{
|
||||
if (ascii_strcasecmp (argv[1], "down") == 0)
|
||||
gui_window_merge_down (gui_current_window);
|
||||
else if (ascii_strcasecmp (argv[1], "up") == 0)
|
||||
gui_window_merge_up (gui_current_window);
|
||||
else if (ascii_strcasecmp (argv[1], "left") == 0)
|
||||
gui_window_merge_left (gui_current_window);
|
||||
else if (ascii_strcasecmp (argv[1], "right") == 0)
|
||||
gui_window_merge_right (gui_current_window);
|
||||
else if (ascii_strcasecmp (argv[1], "all") == 0)
|
||||
if (ascii_strcasecmp (argv[1], "all") == 0)
|
||||
gui_window_merge_all (gui_current_window);
|
||||
else
|
||||
{
|
||||
@@ -2789,7 +2853,18 @@ weechat_cmd_window (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
else
|
||||
gui_window_merge_auto (gui_current_window);
|
||||
{
|
||||
if (!gui_window_merge (gui_current_window))
|
||||
{
|
||||
irc_display_prefix (NULL, NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s can not merge windows, "
|
||||
"there's no other window with same size "
|
||||
"near current one.\n"),
|
||||
WEECHAT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ascii_strncasecmp (argv[0], "b", 1) == 0)
|
||||
{
|
||||
|
||||
@@ -186,9 +186,14 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
if (ascii_strcasecmp (completion->base_command, "debug") == 0)
|
||||
{
|
||||
if (completion->base_command_arg == 1)
|
||||
{
|
||||
weelist_add (&completion->completion_list,
|
||||
&completion->last_completion,
|
||||
"dump");
|
||||
weelist_add (&completion->completion_list,
|
||||
&completion->last_completion,
|
||||
"windows");
|
||||
}
|
||||
else
|
||||
completion_stop (completion);
|
||||
return;
|
||||
|
||||
+167
-205
@@ -2800,7 +2800,7 @@ gui_window_init_subwindows (t_gui_window *window)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_split_horiz (t_gui_window *window)
|
||||
gui_window_split_horiz (t_gui_window *window, int pourcentage)
|
||||
{
|
||||
t_gui_window *new_window;
|
||||
int height1, height2;
|
||||
@@ -2808,24 +2808,32 @@ gui_window_split_horiz (t_gui_window *window)
|
||||
if (!gui_ok)
|
||||
return;
|
||||
|
||||
height1 = window->win_height / 2;
|
||||
height1 = (window->win_height * pourcentage) / 100;
|
||||
height2 = window->win_height - height1;
|
||||
if ((new_window = gui_window_new (window->win_x, window->win_y,
|
||||
window->win_width, height1)))
|
||||
|
||||
if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT)
|
||||
&& (pourcentage > 0) && (pourcentage <= 100))
|
||||
{
|
||||
/* reduce old window height (bottom window) */
|
||||
window->win_y = new_window->win_y + new_window->win_height;
|
||||
window->win_height = height2;
|
||||
|
||||
/* assign same buffer for new window (top window) */
|
||||
new_window->buffer = window->buffer;
|
||||
new_window->buffer->num_displayed++;
|
||||
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
|
||||
gui_current_window = new_window;
|
||||
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer);
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
if ((new_window = gui_window_new (window,
|
||||
window->win_x, window->win_y,
|
||||
window->win_width, height1,
|
||||
100, pourcentage)))
|
||||
{
|
||||
/* reduce old window height (bottom window) */
|
||||
window->win_y = new_window->win_y + new_window->win_height;
|
||||
window->win_height = height2;
|
||||
window->win_height_pct = 100 - pourcentage;
|
||||
|
||||
/* assign same buffer for new window (top window) */
|
||||
new_window->buffer = window->buffer;
|
||||
new_window->buffer->num_displayed++;
|
||||
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
|
||||
gui_current_window = new_window;
|
||||
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer);
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2834,7 +2842,7 @@ gui_window_split_horiz (t_gui_window *window)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_split_vertic (t_gui_window *window)
|
||||
gui_window_split_vertic (t_gui_window *window, int pourcentage)
|
||||
{
|
||||
t_gui_window *new_window;
|
||||
int width1, width2;
|
||||
@@ -2842,170 +2850,84 @@ gui_window_split_vertic (t_gui_window *window)
|
||||
if (!gui_ok)
|
||||
return;
|
||||
|
||||
width1 = window->win_width / 2;
|
||||
width1 = (window->win_width * pourcentage) / 100;
|
||||
width2 = window->win_width - width1 - 1;
|
||||
if ((new_window = gui_window_new (window->win_x + width1 + 1, window->win_y,
|
||||
width2, window->win_height)))
|
||||
|
||||
if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH)
|
||||
&& (pourcentage > 0) && (pourcentage <= 100))
|
||||
{
|
||||
/* reduce old window height (left window) */
|
||||
window->win_width = width1;
|
||||
if ((new_window = gui_window_new (window,
|
||||
window->win_x + width1 + 1, window->win_y,
|
||||
width2, window->win_height,
|
||||
pourcentage, 100)))
|
||||
{
|
||||
/* reduce old window height (left window) */
|
||||
window->win_width = width1;
|
||||
window->win_width_pct = 100 - pourcentage;
|
||||
|
||||
/* assign same buffer for new window (right window) */
|
||||
new_window->buffer = window->buffer;
|
||||
new_window->buffer->num_displayed++;
|
||||
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
|
||||
gui_current_window = new_window;
|
||||
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer);
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
|
||||
/* create & draw separator */
|
||||
gui_draw_window_separator (gui_current_window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge: merge window with its sister
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_merge (t_gui_window *window)
|
||||
{
|
||||
t_gui_window_tree *parent, *sister;
|
||||
|
||||
parent = window->ptr_tree->parent_node;
|
||||
if (parent)
|
||||
{
|
||||
sister = (parent->child1->window == window) ?
|
||||
parent->child2 : parent->child1;
|
||||
|
||||
/* assign same buffer for new window (right window) */
|
||||
new_window->buffer = window->buffer;
|
||||
new_window->buffer->num_displayed++;
|
||||
if (!(sister->window))
|
||||
return 0;
|
||||
|
||||
if (window->win_y == sister->window->win_y)
|
||||
{
|
||||
/* horizontal merge */
|
||||
window->win_width += sister->window->win_width + 1;
|
||||
window->win_width_pct += sister->window->win_width_pct;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* vertical merge */
|
||||
window->win_height += sister->window->win_height;
|
||||
window->win_height_pct += sister->window->win_height_pct;
|
||||
}
|
||||
if (sister->window->win_x < window->win_x)
|
||||
window->win_x = sister->window->win_x;
|
||||
if (sister->window->win_y < window->win_y)
|
||||
window->win_y = sister->window->win_y;
|
||||
|
||||
gui_window_free (sister->window);
|
||||
gui_window_tree_node_to_leaf (parent, window);
|
||||
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
|
||||
gui_current_window = new_window;
|
||||
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer);
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
|
||||
/* create & draw separator */
|
||||
gui_draw_window_separator (gui_current_window);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge_down: merge window, direction down
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_merge_down (t_gui_window *window)
|
||||
{
|
||||
t_gui_window *ptr_win;
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
if (ptr_win != window)
|
||||
{
|
||||
if ((ptr_win->win_y == window->win_y + window->win_height)
|
||||
&& (ptr_win->win_x == window->win_x)
|
||||
&& (ptr_win->win_width == window->win_width))
|
||||
{
|
||||
window->win_height += ptr_win->win_height;
|
||||
gui_window_free (ptr_win);
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no window found below current window */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge_up: merge window, direction up
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_merge_up (t_gui_window *window)
|
||||
{
|
||||
t_gui_window *ptr_win;
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
if (ptr_win != window)
|
||||
{
|
||||
if ((ptr_win->win_y + ptr_win->win_height == window->win_y)
|
||||
&& (ptr_win->win_x == window->win_x)
|
||||
&& (ptr_win->win_width == window->win_width))
|
||||
{
|
||||
window->win_height += ptr_win->win_height;
|
||||
window->win_y -= ptr_win->win_height;
|
||||
gui_window_free (ptr_win);
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no window found above current window */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge_left: merge window, direction left
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_merge_left (t_gui_window *window)
|
||||
{
|
||||
t_gui_window *ptr_win;
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
if (ptr_win != window)
|
||||
{
|
||||
if ((ptr_win->win_x + ptr_win->win_width + 1 == window->win_x)
|
||||
&& (ptr_win->win_y == window->win_y)
|
||||
&& (ptr_win->win_height == window->win_height))
|
||||
{
|
||||
window->win_width += ptr_win->win_width + 1;
|
||||
window->win_x -= ptr_win->win_width + 1;
|
||||
gui_window_free (ptr_win);
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no window found on the left of current window */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge_right: merge window, direction right
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_merge_right (t_gui_window *window)
|
||||
{
|
||||
t_gui_window *ptr_win;
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
if (ptr_win != window)
|
||||
{
|
||||
if ((ptr_win->win_x == window->win_x + window->win_width + 1)
|
||||
&& (ptr_win->win_y == window->win_y)
|
||||
&& (ptr_win->win_height == window->win_height))
|
||||
{
|
||||
window->win_width += ptr_win->win_width + 1;
|
||||
gui_window_free (ptr_win);
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no window found on the right of current window */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge: merge a window, direction auto
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_merge_auto (t_gui_window *window)
|
||||
{
|
||||
if (gui_window_merge_down (window) == 0)
|
||||
return;
|
||||
if (gui_window_merge_up (window) == 0)
|
||||
return;
|
||||
if (gui_window_merge_left (window) == 0)
|
||||
return;
|
||||
if (gui_window_merge_right (window) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_merge_all: merge all windows
|
||||
* gui_window_merge_all: merge all windows into only one
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -3015,14 +2937,61 @@ gui_window_merge_all (t_gui_window *window)
|
||||
{
|
||||
gui_window_free ((gui_windows == window) ? gui_windows->next_window : gui_windows);
|
||||
}
|
||||
gui_window_tree_free (&gui_windows_tree);
|
||||
gui_window_tree_init (window);
|
||||
window->ptr_tree = gui_windows_tree;
|
||||
window->win_x = 0;
|
||||
window->win_y = 0;
|
||||
window->win_width = COLS;
|
||||
window->win_height = LINES;
|
||||
window->win_width_pct = 100;
|
||||
window->win_height_pct = 100;
|
||||
gui_switch_to_buffer (window, window->buffer);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_auto_resize: auto-resize all windows, according to % of global size
|
||||
* This function is called after a terminal resize.
|
||||
* Returns 0 if ok, -1 if all window should be merged
|
||||
* (not enough space according to windows %)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_auto_resize (t_gui_window_tree *tree,
|
||||
int x, int y, int width, int height)
|
||||
{
|
||||
int size1, size2;
|
||||
|
||||
if (tree)
|
||||
{
|
||||
if (tree->window)
|
||||
{
|
||||
tree->window->win_x = x;
|
||||
tree->window->win_y = y;
|
||||
tree->window->win_width = width;
|
||||
tree->window->win_height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tree->split_horiz)
|
||||
{
|
||||
size1 = (height * tree->split_pct) / 100;
|
||||
size2 = height - size1;
|
||||
gui_window_auto_resize (tree->child1, x, y + size1, width, size2);
|
||||
gui_window_auto_resize (tree->child2, x, y, width, size1);
|
||||
}
|
||||
else
|
||||
{
|
||||
size1 = (width * tree->split_pct) / 100;
|
||||
size2 = width - size1 - 1;
|
||||
gui_window_auto_resize (tree->child1, x, y, size1, height);
|
||||
gui_window_auto_resize (tree->child2, x + size1 + 1, y, size2, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_refresh_screen: called when term size is modified
|
||||
*/
|
||||
@@ -3033,7 +3002,7 @@ gui_refresh_screen ()
|
||||
t_gui_window *ptr_win, *old_current_window;
|
||||
int old_width, old_height;
|
||||
int new_width, new_height;
|
||||
int merge_all_windows;
|
||||
int merge_all;
|
||||
|
||||
getmaxyx (stdscr, old_height, old_width);
|
||||
|
||||
@@ -3044,44 +3013,36 @@ gui_refresh_screen ()
|
||||
|
||||
old_current_window = gui_current_window;
|
||||
|
||||
gui_ok = ((new_width > 5) && (new_height > 5));
|
||||
gui_ok = ((new_width > WINDOW_MIN_WIDTH) && (new_height > WINDOW_MIN_HEIGHT));
|
||||
|
||||
merge_all_windows = 0;
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
if (gui_ok)
|
||||
{
|
||||
ptr_win->dcc_first = NULL;
|
||||
ptr_win->dcc_selected = NULL;
|
||||
gui_window_auto_resize (gui_windows_tree, 0, 0, COLS, LINES);
|
||||
|
||||
if (!merge_all_windows)
|
||||
merge_all = 0;
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
if ((ptr_win->win_x > new_width - 5)
|
||||
|| (ptr_win->win_y > new_height - 5))
|
||||
merge_all_windows = 1;
|
||||
else
|
||||
if ((ptr_win->win_width < WINDOW_MIN_WIDTH)
|
||||
|| (ptr_win->win_height < WINDOW_MIN_HEIGHT))
|
||||
{
|
||||
if (ptr_win->win_x + ptr_win->win_width == old_width)
|
||||
ptr_win->win_width = new_width - ptr_win->win_x;
|
||||
if (ptr_win->win_y + ptr_win->win_height == old_height)
|
||||
ptr_win->win_height = new_height - ptr_win->win_y;
|
||||
if ((ptr_win->win_width < 5) || (ptr_win->win_height < 5))
|
||||
merge_all_windows = 1;
|
||||
merge_all = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (merge_all)
|
||||
gui_window_merge_all (gui_current_window);
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
gui_switch_to_buffer (ptr_win, ptr_win->buffer);
|
||||
gui_redraw_buffer (ptr_win->buffer);
|
||||
gui_draw_window_separator (ptr_win);
|
||||
}
|
||||
|
||||
gui_current_window = old_current_window;
|
||||
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer);
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
if (merge_all_windows)
|
||||
gui_window_merge_all (gui_current_window);
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
gui_switch_to_buffer (ptr_win, ptr_win->buffer);
|
||||
gui_redraw_buffer (ptr_win->buffer);
|
||||
gui_draw_window_separator (ptr_win);
|
||||
}
|
||||
|
||||
gui_current_window = old_current_window;
|
||||
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer);
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3265,7 +3226,7 @@ gui_init ()
|
||||
gui_input_clipboard = NULL;
|
||||
|
||||
/* create new window/buffer */
|
||||
if (gui_window_new (0, 0, COLS, LINES))
|
||||
if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100))
|
||||
{
|
||||
gui_current_window = gui_windows;
|
||||
gui_buffer_new (gui_windows, NULL, NULL, 0, 1);
|
||||
@@ -3316,6 +3277,7 @@ gui_end ()
|
||||
/* delete all windows */
|
||||
while (gui_windows)
|
||||
gui_window_free (gui_windows);
|
||||
gui_window_tree_free (&gui_windows_tree);
|
||||
|
||||
/* delete global history */
|
||||
history_global_free ();
|
||||
|
||||
+131
-1
@@ -54,6 +54,8 @@ t_gui_window *gui_windows = NULL; /* pointer to first window */
|
||||
t_gui_window *last_gui_window = NULL; /* pointer to last window */
|
||||
t_gui_window *gui_current_window = NULL; /* pointer to current window */
|
||||
|
||||
t_gui_window_tree *gui_windows_tree = NULL; /* pointer to windows tree */
|
||||
|
||||
t_gui_buffer *gui_buffers = NULL; /* pointer to first buffer */
|
||||
t_gui_buffer *last_gui_buffer = NULL; /* pointer to last buffer */
|
||||
t_gui_buffer *buffer_before_dcc = NULL; /* buffer before dcc switch */
|
||||
@@ -61,25 +63,148 @@ t_gui_infobar *gui_infobar; /* pointer to infobar content */
|
||||
|
||||
char *gui_input_clipboard = NULL; /* clipboard content */
|
||||
|
||||
|
||||
/*
|
||||
* gui_window_tree_init: create first entry in windows tree
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_tree_init (t_gui_window *window)
|
||||
{
|
||||
gui_windows_tree = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree));
|
||||
if (!gui_windows_tree)
|
||||
return 0;
|
||||
gui_windows_tree->parent_node = NULL;
|
||||
gui_windows_tree->split_horiz = 0;
|
||||
gui_windows_tree->split_pct = 0;
|
||||
gui_windows_tree->child1 = NULL;
|
||||
gui_windows_tree->child2 = NULL;
|
||||
gui_windows_tree->window = window;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_tree_node_to_leaf: convert a node to a leaf (free any leafs)
|
||||
* Called when 2 windows are merging into one
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_tree_node_to_leaf (t_gui_window_tree *node, t_gui_window *window)
|
||||
{
|
||||
node->split_horiz = 0;
|
||||
node->split_pct = 0;
|
||||
if (node->child1)
|
||||
{
|
||||
free (node->child1);
|
||||
node->child1 = NULL;
|
||||
}
|
||||
if (node->child2)
|
||||
{
|
||||
free (node->child2);
|
||||
node->child2 = NULL;
|
||||
}
|
||||
node->window = window;
|
||||
window->ptr_tree = node;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_tree_free: delete entire windows tree
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_tree_free (t_gui_window_tree **tree)
|
||||
{
|
||||
if (*tree)
|
||||
{
|
||||
if ((*tree)->child1)
|
||||
gui_window_tree_free (&((*tree)->child1));
|
||||
if ((*tree)->child2)
|
||||
gui_window_tree_free (&((*tree)->child2));
|
||||
free (*tree);
|
||||
*tree = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_new: create a new window
|
||||
*/
|
||||
|
||||
t_gui_window *
|
||||
gui_window_new (int x, int y, int width, int height)
|
||||
gui_window_new (t_gui_window *parent, int x, int y, int width, int height,
|
||||
int width_pct, int height_pct)
|
||||
{
|
||||
t_gui_window *new_window;
|
||||
t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf;
|
||||
|
||||
#ifdef DEBUG
|
||||
wee_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n",
|
||||
x, y, width, height);
|
||||
#endif
|
||||
|
||||
if (parent)
|
||||
{
|
||||
child1 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree));
|
||||
if (!child1)
|
||||
return NULL;
|
||||
child2 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree));
|
||||
if (!child2)
|
||||
{
|
||||
free (child1);
|
||||
return NULL;
|
||||
}
|
||||
ptr_tree = parent->ptr_tree;
|
||||
|
||||
if (width_pct == 100)
|
||||
{
|
||||
ptr_tree->split_horiz = 1;
|
||||
ptr_tree->split_pct = height_pct;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_tree->split_horiz = 0;
|
||||
ptr_tree->split_pct = width_pct;
|
||||
}
|
||||
|
||||
/* parent window leaf becomes node and we add 2 leafs below
|
||||
(#1 is parent win, #2 is new win) */
|
||||
|
||||
parent->ptr_tree = child1;
|
||||
child1->parent_node = ptr_tree;
|
||||
child1->child1 = NULL;
|
||||
child1->child2 = NULL;
|
||||
child1->window = ptr_tree->window;
|
||||
|
||||
child2->parent_node = ptr_tree;
|
||||
child2->child1 = NULL;
|
||||
child2->child2 = NULL;
|
||||
child2->window = NULL; /* will be assigned by new window below */
|
||||
|
||||
ptr_tree->child1 = child1;
|
||||
ptr_tree->child2 = child2;
|
||||
ptr_tree->window = NULL; /* leaf becomes node */
|
||||
|
||||
ptr_leaf = child2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!gui_window_tree_init (NULL))
|
||||
return NULL;
|
||||
ptr_leaf = gui_windows_tree;
|
||||
}
|
||||
|
||||
if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window)))))
|
||||
{
|
||||
new_window->win_x = x;
|
||||
new_window->win_y = y;
|
||||
new_window->win_width = width;
|
||||
new_window->win_height = height;
|
||||
new_window->win_width_pct = width_pct;
|
||||
new_window->win_height_pct = height_pct;
|
||||
|
||||
new_window->new_x = -1;
|
||||
new_window->new_y = -1;
|
||||
new_window->new_width = -1;
|
||||
new_window->new_height = -1;
|
||||
|
||||
new_window->win_chat_x = 0;
|
||||
new_window->win_chat_y = 0;
|
||||
@@ -120,6 +245,9 @@ gui_window_new (int x, int y, int width, int height)
|
||||
new_window->start_line = NULL;
|
||||
new_window->start_line_pos = 0;
|
||||
|
||||
new_window->ptr_tree = ptr_leaf;
|
||||
ptr_leaf->window = new_window;
|
||||
|
||||
/* add window to windows queue */
|
||||
new_window->prev_window = last_gui_window;
|
||||
if (gui_windows)
|
||||
@@ -1427,6 +1555,8 @@ gui_window_print_log (t_gui_window *window)
|
||||
wee_log_printf (" win_y . . . . . . . : %d\n", window->win_y);
|
||||
wee_log_printf (" win_width . . . . . : %d\n", window->win_width);
|
||||
wee_log_printf (" win_height. . . . . : %d\n", window->win_height);
|
||||
wee_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct);
|
||||
wee_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct);
|
||||
wee_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x);
|
||||
wee_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y);
|
||||
wee_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width);
|
||||
|
||||
+33
-8
@@ -164,6 +164,9 @@ enum t_weechat_color
|
||||
#define gui_printf_nolog_notime(buffer, fmt, argz...) \
|
||||
gui_printf_internal(buffer, 0, MSG_TYPE_NOLOG, fmt, ##argz)
|
||||
|
||||
#define WINDOW_MIN_WIDTH 10
|
||||
#define WINDOW_MIN_HEIGHT 5
|
||||
|
||||
#define NOTIFY_LEVEL_MIN 0
|
||||
#define NOTIFY_LEVEL_MAX 3
|
||||
#define NOTIFY_LEVEL_DEFAULT NOTIFY_LEVEL_MAX
|
||||
@@ -261,6 +264,7 @@ struct t_gui_buffer
|
||||
t_gui_buffer *next_buffer; /* link to next buffer */
|
||||
};
|
||||
|
||||
typedef struct t_gui_window_tree t_gui_window_tree;
|
||||
typedef struct t_gui_window t_gui_window;
|
||||
|
||||
struct t_gui_window
|
||||
@@ -268,6 +272,11 @@ struct t_gui_window
|
||||
/* global position & size */
|
||||
int win_x, win_y; /* position of window */
|
||||
int win_width, win_height; /* window geometry */
|
||||
int win_width_pct; /* % of width (compared to term size) */
|
||||
int win_height_pct; /* % of height (compared to term size) */
|
||||
|
||||
int new_x, new_y; /* used for computing new position */
|
||||
int new_width, new_height; /* used for computing new size */
|
||||
|
||||
/* chat window settings */
|
||||
int win_chat_x, win_chat_y; /* chat window position */
|
||||
@@ -320,10 +329,26 @@ struct t_gui_window
|
||||
t_gui_line *start_line; /* pointer to line if scrolling */
|
||||
int start_line_pos; /* position in first line displayed */
|
||||
|
||||
t_gui_window_tree *ptr_tree; /* pointer to leaf in windows tree */
|
||||
|
||||
t_gui_window *prev_window; /* link to previous window */
|
||||
t_gui_window *next_window; /* link to next window */
|
||||
};
|
||||
|
||||
struct t_gui_window_tree
|
||||
{
|
||||
t_gui_window_tree *parent_node; /* pointer to parent node */
|
||||
|
||||
/* node info */
|
||||
int split_horiz; /* 1 if horizontal, 0 if vertical */
|
||||
int split_pct; /* % of split size (represents child1) */
|
||||
t_gui_window_tree *child1; /* first child, NULL if a leaf */
|
||||
t_gui_window_tree *child2; /* second child, NULL if a leaf */
|
||||
|
||||
/* leaf info */
|
||||
t_gui_window *window; /* pointer to window, NULL if a node */
|
||||
};
|
||||
|
||||
typedef struct t_gui_key t_gui_key;
|
||||
|
||||
struct t_gui_key
|
||||
@@ -353,6 +378,7 @@ extern int gui_add_hotlist;
|
||||
extern t_gui_window *gui_windows;
|
||||
extern t_gui_window *last_gui_window;
|
||||
extern t_gui_window *gui_current_window;
|
||||
extern t_gui_window_tree *gui_windows_tree;
|
||||
extern t_gui_buffer *gui_buffers;
|
||||
extern t_gui_buffer *last_gui_buffer;
|
||||
extern t_gui_buffer *buffer_before_dcc;
|
||||
@@ -369,7 +395,10 @@ extern t_gui_color *gui_color[NUM_COLORS];
|
||||
|
||||
/* GUI independent functions: windows & buffers */
|
||||
|
||||
extern t_gui_window *gui_window_new (int, int, int, int);
|
||||
extern int gui_window_tree_init (t_gui_window *);
|
||||
extern void gui_window_tree_node_to_leaf (t_gui_window_tree *, t_gui_window *);
|
||||
extern void gui_window_tree_free (t_gui_window_tree **);
|
||||
extern t_gui_window *gui_window_new (t_gui_window *, int, int, int, int, int, int);
|
||||
extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int);
|
||||
extern void gui_buffer_clear (t_gui_buffer *);
|
||||
extern void gui_buffer_clear_all ();
|
||||
@@ -480,13 +509,9 @@ extern void gui_window_nick_end (t_gui_window *);
|
||||
extern void gui_window_nick_page_up (t_gui_window *);
|
||||
extern void gui_window_nick_page_down (t_gui_window *);
|
||||
extern void gui_window_init_subwindows (t_gui_window *);
|
||||
extern void gui_window_split_horiz (t_gui_window *);
|
||||
extern void gui_window_split_vertic (t_gui_window *);
|
||||
extern int gui_window_merge_up (t_gui_window *);
|
||||
extern int gui_window_merge_down (t_gui_window *);
|
||||
extern int gui_window_merge_left (t_gui_window *);
|
||||
extern int gui_window_merge_right (t_gui_window *);
|
||||
extern void gui_window_merge_auto (t_gui_window *);
|
||||
extern void gui_window_split_horiz (t_gui_window *, int);
|
||||
extern void gui_window_split_vertic (t_gui_window *, int);
|
||||
extern int gui_window_merge (t_gui_window *);
|
||||
extern void gui_window_merge_all (t_gui_window *);
|
||||
extern void gui_refresh_screen ();
|
||||
extern void gui_pre_init (int *, char **[]);
|
||||
|
||||
Reference in New Issue
Block a user