From 634478dd54b3043f44922bea6c1de0220aaf4e30 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 22 Apr 2011 21:56:54 +0200 Subject: core: add option "swap" for command /window (key: alt+"w" + alt+"s") (task #11001) --- src/gui/curses/gui-curses-keyboard.c | 1 + src/gui/curses/gui-curses-window.c | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'src/gui/curses') diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index c0e782e97..f7467937c 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-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"); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 6566709c1..2fc3208ab 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -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, -- cgit v1.2.3