diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-04-22 21:56:54 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-04-22 21:56:54 +0200 |
commit | 634478dd54b3043f44922bea6c1de0220aaf4e30 (patch) | |
tree | dcd8b81a4e46763053125a18dcb70aaf4223b947 /src/gui/curses | |
parent | b7853444d80d5be64531b7eefbfa2bb2b07abe42 (diff) | |
download | weechat-634478dd54b3043f44922bea6c1de0220aaf4e30.zip |
core: add option "swap" for command /window (key: alt+"w" + alt+"s") (task #11001)
Diffstat (limited to 'src/gui/curses')
-rw-r--r-- | src/gui/curses/gui-curses-keyboard.c | 1 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 57 |
2 files changed, 58 insertions, 0 deletions
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 @@ -1955,6 +1955,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, * or if terminal is resized |