From 14cf7bd20fb3f00b18343464c175a0c4e3556149 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 27 Oct 2013 11:07:33 +0100 Subject: [PATCH] core: fix auto-apply of window layout in current window when option irc.look.buffer_switch_autojoin is on --- ChangeLog | 4 +++- src/gui/gui-buffer.c | 19 +++++++++++++------ src/gui/gui-layout.c | 28 ++++++++++++++++++++++++++++ src/gui/gui-layout.h | 1 + 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 248f8edb7..e5c1cd4ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.4.3-dev, 2013-10-26 +v0.4.3-dev, 2013-10-27 This document lists all changes for each version. @@ -14,6 +14,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] Version 0.4.3 (under dev!) -------------------------- +* core: fix auto-apply of window layout in current window when option + irc.look.buffer_switch_autojoin is on * core: fix bind of keys in cursor/mouse context when key starts with "@" (remove the warning about unsafe key) * core: fix truncated prefix when filters are toggled (bug #40204) diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index daa461ac0..269999119 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1492,6 +1492,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, { long number; char *error; + int auto_switch; if (!property || !value) return; @@ -1527,13 +1528,19 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, else if (string_strcasecmp (property, "display") == 0) { /* - * if it is auto-switch to a buffer, then we don't set read marker, - * otherwise we reset it (if current buffer is not displayed) after - * switch + * on "automatic" switch: + * - check if the buffer displayed in window is the buffer in layout: + * if yes, do NOT switch to buffer + * - do NOT set the read marker */ - gui_window_switch_to_buffer (gui_current_window, buffer, - (string_strcasecmp (value, "auto") == 0) ? - 0 : 1); + auto_switch = (string_strcasecmp (value, "auto") == 0); + if (!auto_switch + || (gui_layout_window_check_buffer (gui_current_window) != 1)) + { + gui_window_switch_to_buffer (gui_current_window, + buffer, + (auto_switch) ? 0 : 1); + } } else if (string_strcasecmp (property, "print_hooks_enabled") == 0) { diff --git a/src/gui/gui-layout.c b/src/gui/gui-layout.c index 5cfc635da..42a143bf0 100644 --- a/src/gui/gui-layout.c +++ b/src/gui/gui-layout.c @@ -611,6 +611,34 @@ gui_layout_window_save (struct t_gui_layout *layout) gui_windows_tree); } +/* + * Checks whether a window has its layout buffer displayed or not. + * + * Returns: + * 1: the window has layout info and the proper buffer displayed + * 0: the window has layout info but NOT the proper buffer displayed + * -1: the window has no layout info + */ + +int +gui_layout_window_check_buffer (struct t_gui_window *window) +{ + /* no layout? return -1 */ + if (!window->layout_plugin_name || !window->layout_buffer_name) + return -1; + + /* layout and buffer displayed matches? return 1 */ + if ((strcmp (window->layout_plugin_name, + gui_buffer_get_plugin_name (window->buffer)) == 0) + && (strcmp (window->layout_buffer_name, (window->buffer)->name) == 0)) + { + return 1; + } + + /* buffer displayed does not match the layout, return 0 */ + return 0; +} + /* * Assigns a buffer to windows. */ diff --git a/src/gui/gui-layout.h b/src/gui/gui-layout.h index fc9b9c990..8f3d06643 100644 --- a/src/gui/gui-layout.h +++ b/src/gui/gui-layout.h @@ -105,6 +105,7 @@ extern struct t_gui_layout_window *gui_layout_window_add (struct t_gui_layout_wi const char *plugin_name, const char *buffer_name); extern void gui_layout_window_save (struct t_gui_layout *layout); +extern int gui_layout_window_check_buffer (struct t_gui_window *window); extern void gui_layout_window_assign_buffer (struct t_gui_buffer *buffer); extern void gui_layout_window_apply (struct t_gui_layout *layout, int internal_id_current_window);