Permalink
Browse files

core: add resize of window parents (closes #893)

  • Loading branch information...
1 parent 2f2b04e commit 1b23cd3a477e281b9880ef0e2981ff0d878d71b5 @raspbeguy raspbeguy committed with flashcode Jan 22, 2017
Showing with 60 additions and 25 deletions.
  1. +27 −15 src/core/wee-command.c
  2. +8 −8 src/gui/curses/gui-curses-window.c
  3. +21 −0 src/gui/gui-window.c
  4. +4 −2 src/gui/gui-window.h
@@ -6484,7 +6484,8 @@ COMMAND_CALLBACK(wait)
COMMAND_CALLBACK(window)
{
struct t_gui_window *ptr_win;
- char *error;
+ struct t_gui_window_tree *ptr_tree;
+ char *error, *ptr_sizearg, sign;
long number;
int win_args;
@@ -6695,25 +6696,36 @@ COMMAND_CALLBACK(window)
{
if (argc > win_args)
{
- if ((argv[win_args][0] == '+') || (argv[win_args][0] == '-'))
+ ptr_sizearg = argv[win_args];
+ sign = 0;
+ if ((ptr_sizearg[0] == 'h') || (ptr_sizearg[0] == 'v'))
{
- error = NULL;
- number = strtol (argv[win_args] + 1, &error, 10);
- if (error && !error[0])
- {
- if (argv[win_args][0] == '-')
- number *= -1;
- gui_window_resize_delta (ptr_win, number);
- }
+ ptr_tree = gui_window_tree_get_split (ptr_win->ptr_tree,
+ ptr_sizearg[0]);
+ ptr_sizearg++;
}
else
{
- error = NULL;
- number = strtol (argv[win_args], &error, 10);
- if (error && !error[0]
- && (number > 0) && (number < 100))
+ ptr_tree = ptr_win->ptr_tree;
+ }
+ if ((ptr_sizearg[0] == '+') || (ptr_sizearg[0] == '-'))
+ {
+ sign = ptr_sizearg[0];
+ ptr_sizearg++;
+ }
+ error = NULL;
+ number = strtol (ptr_sizearg, &error, 10);
+ if (error && !error[0])
+ {
+ if (sign)
+ {
+ if (sign == '-')
+ number *= -1;
+ gui_window_resize_delta (ptr_tree, number);
+ }
+ else
{
- gui_window_resize (ptr_win, number);
+ gui_window_resize (ptr_tree, number);
}
}
}
@@ -1874,20 +1874,20 @@ gui_window_split_vertical (struct t_gui_window *window, int percentage)
*/
void
-gui_window_resize (struct t_gui_window *window, int percentage)
+gui_window_resize (struct t_gui_window_tree *tree, int percentage)
{
struct t_gui_window_tree *parent;
int old_split_pct, add_bottom, add_top, add_left, add_right;
if (!gui_init_ok)
return;
- parent = window->ptr_tree->parent_node;
+ parent = tree->parent_node;
if (parent)
{
old_split_pct = parent->split_pct;
- if (((parent->split_horizontal) && (window->ptr_tree == parent->child2))
- || ((!(parent->split_horizontal)) && (window->ptr_tree == parent->child1)))
+ if (((parent->split_horizontal) && (tree == parent->child2))
+ || ((!(parent->split_horizontal)) && (tree == parent->child1)))
{
parent->split_pct = percentage;
}
@@ -1916,20 +1916,20 @@ gui_window_resize (struct t_gui_window *window, int percentage)
*/
void
-gui_window_resize_delta (struct t_gui_window *window, int delta_percentage)
+gui_window_resize_delta (struct t_gui_window_tree *tree, int delta_percentage)
{
struct t_gui_window_tree *parent;
int old_split_pct, add_bottom, add_top, add_left, add_right;
if (!gui_init_ok)
return;
- parent = window->ptr_tree->parent_node;
+ parent = tree->parent_node;
if (parent)
{
old_split_pct = parent->split_pct;
- if (((parent->split_horizontal) && (window->ptr_tree == parent->child2))
- || ((!(parent->split_horizontal)) && (window->ptr_tree == parent->child1)))
+ if (((parent->split_horizontal) && (tree == parent->child2))
+ || ((!(parent->split_horizontal)) && (tree == parent->child1)))
{
parent->split_pct += delta_percentage;
}
View
@@ -344,6 +344,27 @@ gui_window_tree_free (struct t_gui_window_tree **tree)
}
/*
+ * Searches a parent window which is split on the given direction
+ * ('h' or 'v').
+ */
+
+struct t_gui_window_tree *
+gui_window_tree_get_split (struct t_gui_window_tree *tree,
+ char direction)
+{
+ if (!tree->parent_node)
+ return tree;
+
+ if (((tree->parent_node->split_horizontal) && (direction == 'h'))
+ || (!(tree->parent_node->split_horizontal) && (direction == 'v')))
+ {
+ return tree;
+ }
+
+ return gui_window_tree_get_split (tree->parent_node, direction);
+}
+
+/*
* Searches for a scroll with buffer pointer.
*
* Returns pointer to window scroll, NULL if not found.
@@ -146,6 +146,8 @@ extern int gui_window_tree_init (struct t_gui_window *window);
extern void gui_window_tree_node_to_leaf (struct t_gui_window_tree *node,
struct t_gui_window *window);
extern void gui_window_tree_free (struct t_gui_window_tree **tree);
+extern struct t_gui_window_tree *gui_window_tree_get_split (struct t_gui_window_tree *tree,
+ char direction);
extern void gui_window_scroll_switch (struct t_gui_window *window,
struct t_gui_buffer *buffer);
extern void gui_window_scroll_remove_buffer (struct t_gui_window *window,
@@ -226,8 +228,8 @@ extern struct t_gui_window *gui_window_split_horizontal (struct t_gui_window *wi
int percentage);
extern struct t_gui_window *gui_window_split_vertical (struct t_gui_window *window,
int percentage);
-extern void gui_window_resize (struct t_gui_window *window, int percentage);
-extern void gui_window_resize_delta (struct t_gui_window *window,
+extern void gui_window_resize (struct t_gui_window_tree *tree, int percentage);
+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);

0 comments on commit 1b23cd3

Please sign in to comment.