From 909fe8a2b5a751dd6a30768609c535594a745a58 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 23 Apr 2011 13:21:10 +0200 Subject: core: add option "balance" for command /window (key: alt+"w" + alt+"b") --- src/core/wee-command.c | 20 ++++++++++++++++---- src/gui/curses/gui-curses-keyboard.c | 1 + src/gui/curses/gui-curses-window.c | 25 +++++++++++++++++++++++++ src/gui/gtk/gui-gtk-window.c | 15 +++++++++++++++ src/gui/gui-window.h | 1 + 5 files changed, 58 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index a48a50643..683f76110 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -4477,6 +4477,14 @@ COMMAND_CALLBACK(window) return WEECHAT_RC_OK; } + /* balance windows */ + if (string_strcasecmp (argv[1], "balance") == 0) + { + if (gui_window_balance (gui_windows_tree)) + gui_window_ask_refresh (1); + return WEECHAT_RC_OK; + } + /* merge windows */ if (string_strcasecmp (argv[1], "merge") == 0) { @@ -4515,8 +4523,10 @@ COMMAND_CALLBACK(window) error = NULL; number = strtol (argv[1] + 1, &error, 10); if (error && !error[0]) + { gui_window_switch_by_buffer (gui_current_window, number); - return WEECHAT_RC_OK; + return WEECHAT_RC_OK; + } } /* switch to previous window */ @@ -5255,6 +5265,7 @@ command_init () " || -1|+1|b#|up|down|left|right" " || splith|splitv []" " || resize [+/-]" + " || balance" " || merge [all]" " || page_up|page_down" " || refresh" @@ -5276,6 +5287,7 @@ command_init () " splitv: split current window vertically\n" " resize: resize window size, new size is " "percentage of parent window\n" + " balance: resize all windows to 50%\n" " merge: merge window with another (all = keep only one " "window)\n" " page_up: scroll one page up\n" @@ -5306,9 +5318,9 @@ command_init () " scroll to beginning of current day:\n" " /window scroll -d"), "list || -1 || +1 || up || down || left || right" - " || splith || splitv || resize || page_up || page_down" - " || refresh || scroll || scroll_up || scroll_down" - " || scroll_top || scroll_bottom" + " || splith || splitv || resize || balance || page_up" + " || page_down || refresh || scroll || scroll_up" + " || scroll_down || scroll_top || scroll_bottom" " || scroll_previous_highlight || scroll_next_highlight" " || swap up|down|left|right || zoom || merge all", &command_window, NULL); diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index f7467937c..8331bf4c2 100644 --- a/src/gui/curses/gui-curses-keyboard.c +++ b/src/gui/curses/gui-curses-keyboard.c @@ -185,6 +185,7 @@ gui_keyboard_default_bindings () BIND(/* m-w,m-right */ "meta-wmeta2-1;3C", "/window right"); BIND(/* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); BIND(/* m-w,m-left */ "meta-wmeta2-1;3D", "/window left"); + BIND(/* m-w,m-b */ "meta-wmeta-b", "/window balance"); BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap"); BIND(/* m-z */ "meta-z", "/window zoom"); BIND(/* m-= */ "meta-=", "/filter toggle"); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 2fc3208ab..0c229ef91 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -1954,6 +1954,31 @@ gui_window_switch_right (struct t_gui_window *window) } } +/* + * gui_window_balance: balance windows (set all splits to 50%) + * return 1 if some windows have been balanced + * 0 if nothing was changed + */ + +int +gui_window_balance (struct t_gui_window_tree *tree) +{ + int balanced; + + balanced = 0; + if (tree && tree->child1 && tree->child2) + { + if (tree->split_pct != 50) + { + tree->split_pct = 50; + balanced = 1; + } + balanced |= gui_window_balance (tree->child1); + balanced |= gui_window_balance (tree->child2); + } + return balanced; +} + /* * gui_window_swap: swap buffers of two windows * direction can be: 0 = auto (swap with sister) diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c index ba64b7d38..c7bd94041 100644 --- a/src/gui/gtk/gui-gtk-window.c +++ b/src/gui/gtk/gui-gtk-window.c @@ -791,6 +791,21 @@ gui_window_switch_right (struct t_gui_window *window) } } +/* + * gui_window_balance: balance windows (set all splits to 50%) + * return 1 if some windows have been balanced + * 0 if nothing was changed + */ + +int +gui_window_balance (struct t_gui_window_tree *tree) +{ + (void) tree; + + /* TODO: write this function for Gtk */ + return 0; +} + /* * gui_window_swap: swap buffer of two windows * direction can be: 0 = auto (swap with sister) diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 06acca662..8e82e5686 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -187,6 +187,7 @@ extern void gui_window_switch_up (struct t_gui_window *window); extern void gui_window_switch_down (struct t_gui_window *window); extern void gui_window_switch_left (struct t_gui_window *window); extern void gui_window_switch_right (struct t_gui_window *window); +extern int gui_window_balance (struct t_gui_window_tree *tree); extern void gui_window_swap (struct t_gui_window *window, int direction); extern void gui_window_refresh_screen (int full_refresh); extern void gui_window_set_title (const char *title); -- cgit v1.2.3