summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c46
-rw-r--r--src/gui/curses/gui-curses-keyboard.c1
-rw-r--r--src/gui/curses/gui-curses-window.c57
-rw-r--r--src/gui/gtk/gui-gtk-window.c18
-rw-r--r--src/gui/gui-window.h1
5 files changed, 117 insertions, 6 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 9b901db07..a48a50643 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -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);
}
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
diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c
index 1603f286e..ba64b7d38 100644
--- a/src/gui/gtk/gui-gtk-window.c
+++ b/src/gui/gtk/gui-gtk-window.c
@@ -792,6 +792,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
*/
diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h
index 6aabcb57e..06acca662 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 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 ();