summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-06-17 21:08:07 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-06-17 21:08:07 +0200
commitf15a24b2ec14e279d15bd509be79176ee3c4d5c9 (patch)
tree8877444ee560d0fe7659fc555d347b7a5afec86c /src/gui
parente5f963f78a4e89c5670a90f8a83a9eebb0173ea8 (diff)
downloadweechat-f15a24b2ec14e279d15bd509be79176ee3c4d5c9.zip
core: add option "close" in command /window (closes #853)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-window.c87
-rw-r--r--src/gui/gui-window.h1
2 files changed, 58 insertions, 30 deletions
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 10d1aac09..f266e05a1 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -1969,40 +1969,39 @@ gui_window_merge (struct t_gui_window *window)
return 0;
parent = window->ptr_tree->parent_node;
- if (parent)
- {
- sister = (parent->child1->window == window) ?
- parent->child2 : parent->child1;
+ if (!parent)
+ return 0;
- if (!(sister->window))
- return 0;
+ sister = (parent->child1->window == window) ?
+ parent->child2 : parent->child1;
+ if (!(sister->window))
+ return 0;
- if (window->win_y == sister->window->win_y)
- {
- /* horizontal merge */
- separator = (CONFIG_BOOLEAN(config_look_window_separator_horizontal)) ? 1 : 0;
- window->win_width += sister->window->win_width + separator;
- window->win_width_pct += sister->window->win_width_pct;
- }
- else
- {
- /* vertical merge */
- separator = (CONFIG_BOOLEAN(config_look_window_separator_vertical)) ? 1 : 0;
- window->win_height += sister->window->win_height + separator;
- window->win_height_pct += sister->window->win_height_pct;
- }
- if (sister->window->win_x < window->win_x)
- window->win_x = sister->window->win_x;
- if (sister->window->win_y < window->win_y)
- window->win_y = sister->window->win_y;
+ if (window->win_y == sister->window->win_y)
+ {
+ /* horizontal merge */
+ separator = (CONFIG_BOOLEAN(config_look_window_separator_horizontal)) ? 1 : 0;
+ window->win_width += sister->window->win_width + separator;
+ window->win_width_pct += sister->window->win_width_pct;
+ }
+ else
+ {
+ /* vertical merge */
+ separator = (CONFIG_BOOLEAN(config_look_window_separator_vertical)) ? 1 : 0;
+ window->win_height += sister->window->win_height + separator;
+ window->win_height_pct += sister->window->win_height_pct;
+ }
+ if (sister->window->win_x < window->win_x)
+ window->win_x = sister->window->win_x;
+ if (sister->window->win_y < window->win_y)
+ window->win_y = sister->window->win_y;
- gui_window_free (sister->window);
- gui_window_tree_node_to_leaf (parent, window);
+ gui_window_free (sister->window);
+ gui_window_tree_node_to_leaf (parent, window);
- gui_window_switch_to_buffer (window, window->buffer, 1);
- return 1;
- }
- return 0;
+ gui_window_switch_to_buffer (window, window->buffer, 1);
+
+ return 1;
}
/*
@@ -2048,6 +2047,34 @@ gui_window_merge_all (struct t_gui_window *window)
}
/*
+ * Closes a window.
+ *
+ * Returns:
+ * 1: OK
+ * 0: error
+ */
+
+int
+gui_window_close (struct t_gui_window *window)
+{
+ struct t_gui_window_tree *parent, *sister;
+
+ if (!gui_init_ok)
+ return 0;
+
+ parent = window->ptr_tree->parent_node;
+ if (!parent)
+ return 0;
+
+ sister = (parent->child1->window == window) ?
+ parent->child2 : parent->child1;
+ if (!(sister->window))
+ return 0;
+
+ return gui_window_merge (sister->window);
+}
+
+/*
* Returns a code about position of 2 windows:
* 0 = they're not side by side
* 1 = side by side: win2 is over the win1
diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h
index 337949205..c9962e449 100644
--- a/src/gui/gui-window.h
+++ b/src/gui/gui-window.h
@@ -233,6 +233,7 @@ extern void gui_window_resize_delta (struct t_gui_window_tree *tree,
int delta_percentage);
extern int gui_window_merge (struct t_gui_window *window);
extern void gui_window_merge_all (struct t_gui_window *window);
+extern int gui_window_close (struct t_gui_window *window);
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);