1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 19:23:13 +02:00

core: add option "swap" for command /window (key: alt+"w" + alt+"s") (task #11001)

This commit is contained in:
Sebastien Helleu
2011-04-22 21:56:54 +02:00
parent b7853444d8
commit 634478dd54
24 changed files with 246 additions and 89 deletions
+40 -6
View File
@@ -4568,7 +4568,37 @@ COMMAND_CALLBACK(window)
gui_window_scroll (gui_current_window, argv[2]);
return WEECHAT_RC_OK;
}
/* swap windows */
if (string_strcasecmp (argv[1], "swap") == 0)
{
if (argc > 2)
{
if (string_strcasecmp (argv[2], "up") == 0)
gui_window_swap (gui_current_window, 1);
else if (string_strcasecmp (argv[2], "down") == 0)
gui_window_swap (gui_current_window, 3);
else if (string_strcasecmp (argv[2], "left") == 0)
gui_window_swap (gui_current_window, 4);
else if (string_strcasecmp (argv[2], "right") == 0)
gui_window_swap (gui_current_window, 2);
else
{
gui_chat_printf (NULL,
_("%sError: unknown option for \"%s\" "
"command"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
"window swap");
return WEECHAT_RC_OK;
}
}
else
{
gui_window_swap (gui_current_window, 0);
}
return WEECHAT_RC_OK;
}
/* zoom window */
if (string_strcasecmp (argv[1], "zoom") == 0)
{
@@ -5231,6 +5261,7 @@ command_init ()
" || scroll|scroll_up|scroll_down|scroll_top|"
"scroll_bottom|scroll_previous_highlight|"
"scroll_next_highlight"
" || swap [up|down|left|right]"
" || zoom"),
N_(" list: list opened windows (without argument, "
"this list is displayed)\n"
@@ -5258,6 +5289,8 @@ command_init ()
"scroll_bottom: scroll to bottom of buffer\n"
"scroll_previous_highlight: scroll to previous highlight\n"
"scroll_next_highlight: scroll to next highlight\n"
" swap: swap buffers of two windows (with optional "
"direction for target window)\n"
" zoom: zoom on window\n\n"
"For splith and splitv, pct is a percentage which "
"represents size of new window, computed with current "
@@ -5272,11 +5305,12 @@ command_init ()
" /window scroll -2d\n"
" 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_up|scroll|scroll_down|scroll_top|"
"scroll_bottom|scroll_previous_highlight|"
"scroll_next_highlight|zoom"
" || merge all",
"list || -1 || +1 || up || down || left || right"
" || splith || splitv || resize || 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);
}
+1
View File
@@ -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-s */ "meta-wmeta-s", "/window swap");
BIND(/* m-z */ "meta-z", "/window zoom");
BIND(/* m-= */ "meta-=", "/filter toggle");
BIND(/* m-0 */ "meta-0", "/buffer *10");
+57
View File
@@ -1954,6 +1954,63 @@ gui_window_switch_right (struct t_gui_window *window)
}
}
/*
* gui_window_swap: swap buffers of two windows
* direction can be: 0 = auto (swap with sister)
* 1 = window above
* 2 = window on the right
* 3 = window below
* 4 = window on the left
*/
void
gui_window_swap (struct t_gui_window *window, int direction)
{
struct t_gui_window_tree *parent, *sister;
struct t_gui_window *window2, *ptr_win;
struct t_gui_buffer *buffer1;
if (!window || !gui_ok)
return;
window2 = NULL;
if (direction == 0)
{
/* search sister window */
parent = window->ptr_tree->parent_node;
if (parent)
{
sister = (parent->child1->window == window) ?
parent->child2 : parent->child1;
if (sister->window)
window2 = sister->window;
}
}
else
{
/* search window using direction */
for (ptr_win = gui_windows; ptr_win;
ptr_win = ptr_win->next_window)
{
if ((ptr_win != window) &&
(gui_window_side_by_side (window, ptr_win) == direction))
{
window2 = ptr_win;
break;
}
}
}
/* let's swap! */
if (window2 && (window->buffer != window2->buffer))
{
buffer1 = window->buffer;
gui_window_switch_to_buffer (window, window2->buffer, 0);
gui_window_switch_to_buffer (window2, buffer1, 0);
}
}
/*
* gui_window_refresh_screen: called when term size is modified
* full_refresh == 1 when Ctrl+L is pressed,
+18
View File
@@ -791,6 +791,24 @@ gui_window_switch_right (struct t_gui_window *window)
}
}
/*
* gui_window_swap: swap buffer of two windows
* direction can be: 0 = auto (swap with sister)
* 1 = window above
* 2 = window on the right
* 3 = window below
* 4 = window on the left
*/
void
gui_window_swap (struct t_gui_window *window, int direction)
{
(void) window;
(void) direction;
/* TODO: write this function for Gtk */
}
/*
* gui_window_refresh_screen: called when term size is modified
*/
+1
View File
@@ -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 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);
extern void gui_window_term_display_infos ();