Introduce parse_direction
Also fixes the following bug: in the fix for #1011 in cmd_resize_floating direction "width" is not considered. Influenced by #3240.
This commit is contained in:
parent
6e1b79e057
commit
9522b46f1b
|
@ -216,7 +216,7 @@ void cmd_sticky(I3_CMD, const char *action);
|
||||||
* Implementation of 'move <direction> [<pixels> [px]]'.
|
* Implementation of 'move <direction> [<pixels> [px]]'.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_move_direction(I3_CMD, const char *direction, long move_px);
|
void cmd_move_direction(I3_CMD, const char *direction_str, long move_px);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
|
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
|
||||||
|
|
131
src/commands.c
131
src/commands.c
|
@ -419,71 +419,89 @@ void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *_no
|
||||||
ysuccess(true);
|
ysuccess(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_resize_floating(I3_CMD, const char *way, const char *direction, Con *floating_con, int px) {
|
/*
|
||||||
LOG("floating resize\n");
|
* Convert a string direction ("left", "right", etc.) to a direction_t. Assumes
|
||||||
|
* valid direction string.
|
||||||
|
*/
|
||||||
|
static direction_t parse_direction(const char *str) {
|
||||||
|
if (strcmp(str, "left") == 0) {
|
||||||
|
return D_LEFT;
|
||||||
|
} else if (strcmp(str, "right") == 0) {
|
||||||
|
return D_RIGHT;
|
||||||
|
} else if (strcmp(str, "up") == 0) {
|
||||||
|
return D_UP;
|
||||||
|
} else if (strcmp(str, "down") == 0) {
|
||||||
|
return D_DOWN;
|
||||||
|
} else {
|
||||||
|
ELOG("Invalid direction. This is a parser bug.\n");
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cmd_resize_floating(I3_CMD, const char *way, const char *direction_str, Con *floating_con, int px) {
|
||||||
Rect old_rect = floating_con->rect;
|
Rect old_rect = floating_con->rect;
|
||||||
Con *focused_con = con_descend_focused(floating_con);
|
Con *focused_con = con_descend_focused(floating_con);
|
||||||
|
|
||||||
|
direction_t direction;
|
||||||
|
if (strcmp(direction_str, "height") == 0) {
|
||||||
|
direction = D_DOWN;
|
||||||
|
} else if (strcmp(direction_str, "width") == 0) {
|
||||||
|
direction = D_RIGHT;
|
||||||
|
} else {
|
||||||
|
direction = parse_direction(direction_str);
|
||||||
|
}
|
||||||
|
orientation_t orientation = orientation_from_direction(direction);
|
||||||
|
|
||||||
/* ensure that resize will take place even if pixel increment is smaller than
|
/* ensure that resize will take place even if pixel increment is smaller than
|
||||||
* height increment or width increment.
|
* height increment or width increment.
|
||||||
* fixes #1011 */
|
* fixes #1011 */
|
||||||
const i3Window *window = focused_con->window;
|
const i3Window *window = focused_con->window;
|
||||||
if (window != NULL) {
|
if (window != NULL) {
|
||||||
if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 ||
|
if (orientation == VERT) {
|
||||||
strcmp(direction, "height") == 0) {
|
if (px < 0) {
|
||||||
if (px < 0)
|
|
||||||
px = (-px < window->height_increment) ? -window->height_increment : px;
|
px = (-px < window->height_increment) ? -window->height_increment : px;
|
||||||
else
|
} else {
|
||||||
px = (px < window->height_increment) ? window->height_increment : px;
|
px = (px < window->height_increment) ? window->height_increment : px;
|
||||||
} else if (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0) {
|
}
|
||||||
if (px < 0)
|
} else {
|
||||||
|
if (px < 0) {
|
||||||
px = (-px < window->width_increment) ? -window->width_increment : px;
|
px = (-px < window->width_increment) ? -window->width_increment : px;
|
||||||
else
|
} else {
|
||||||
px = (px < window->width_increment) ? window->width_increment : px;
|
px = (px < window->width_increment) ? window->width_increment : px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(direction, "up") == 0) {
|
if (orientation == VERT) {
|
||||||
floating_con->rect.height += px;
|
floating_con->rect.height += px;
|
||||||
} else if (strcmp(direction, "down") == 0 || strcmp(direction, "height") == 0) {
|
|
||||||
floating_con->rect.height += px;
|
|
||||||
} else if (strcmp(direction, "left") == 0) {
|
|
||||||
floating_con->rect.width += px;
|
|
||||||
} else {
|
} else {
|
||||||
floating_con->rect.width += px;
|
floating_con->rect.width += px;
|
||||||
}
|
}
|
||||||
|
|
||||||
floating_check_size(floating_con);
|
floating_check_size(floating_con);
|
||||||
|
|
||||||
/* Did we actually resize anything or did the size constraints prevent us?
|
/* Did we actually resize anything or did the size constraints prevent us?
|
||||||
* If we could not resize, exit now to not move the window. */
|
* If we could not resize, exit now to not move the window. */
|
||||||
if (memcmp(&old_rect, &(floating_con->rect), sizeof(Rect)) == 0)
|
if (memcmp(&old_rect, &(floating_con->rect), sizeof(Rect)) == 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(direction, "up") == 0) {
|
if (direction == D_UP) {
|
||||||
floating_con->rect.y -= (floating_con->rect.height - old_rect.height);
|
floating_con->rect.y -= (floating_con->rect.height - old_rect.height);
|
||||||
} else if (strcmp(direction, "left") == 0) {
|
} else if (direction == D_LEFT) {
|
||||||
floating_con->rect.x -= (floating_con->rect.width - old_rect.width);
|
floating_con->rect.x -= (floating_con->rect.width - old_rect.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is a scratchpad window, don't auto center it from now on. */
|
/* If this is a scratchpad window, don't auto center it from now on. */
|
||||||
if (floating_con->scratchpad_state == SCRATCHPAD_FRESH)
|
if (floating_con->scratchpad_state == SCRATCHPAD_FRESH) {
|
||||||
floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
|
floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
|
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
|
||||||
LOG("tiling resize\n");
|
LOG("tiling resize\n");
|
||||||
Con *second = NULL;
|
Con *second = NULL;
|
||||||
Con *first = current;
|
Con *first = current;
|
||||||
direction_t search_direction;
|
direction_t search_direction = parse_direction(direction);
|
||||||
if (!strcmp(direction, "left"))
|
|
||||||
search_direction = D_LEFT;
|
|
||||||
else if (!strcmp(direction, "right"))
|
|
||||||
search_direction = D_RIGHT;
|
|
||||||
else if (!strcmp(direction, "up"))
|
|
||||||
search_direction = D_UP;
|
|
||||||
else
|
|
||||||
search_direction = D_DOWN;
|
|
||||||
|
|
||||||
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
|
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
@ -1254,20 +1272,19 @@ void cmd_exec(I3_CMD, const char *nosn, const char *command) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_focus_direction(I3_CMD, const char *direction) {
|
void cmd_focus_direction(I3_CMD, const char *direction) {
|
||||||
DLOG("direction = *%s*\n", direction);
|
switch (parse_direction(direction)) {
|
||||||
|
case D_LEFT:
|
||||||
if (strcmp(direction, "left") == 0)
|
tree_next('p', HORIZ);
|
||||||
tree_next('p', HORIZ);
|
break;
|
||||||
else if (strcmp(direction, "right") == 0)
|
case D_RIGHT:
|
||||||
tree_next('n', HORIZ);
|
tree_next('n', HORIZ);
|
||||||
else if (strcmp(direction, "up") == 0)
|
break;
|
||||||
tree_next('p', VERT);
|
case D_UP:
|
||||||
else if (strcmp(direction, "down") == 0)
|
tree_next('p', VERT);
|
||||||
tree_next('n', VERT);
|
break;
|
||||||
else {
|
case D_DOWN:
|
||||||
ELOG("Invalid focus direction (%s)\n", direction);
|
tree_next('n', VERT);
|
||||||
ysuccess(false);
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_output->needs_tree_render = true;
|
cmd_output->needs_tree_render = true;
|
||||||
|
@ -1492,29 +1509,37 @@ void cmd_sticky(I3_CMD, const char *action) {
|
||||||
* Implementation of 'move <direction> [<pixels> [px]]'.
|
* Implementation of 'move <direction> [<pixels> [px]]'.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_move_direction(I3_CMD, const char *direction, long move_px) {
|
void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) {
|
||||||
owindow *current;
|
owindow *current;
|
||||||
HANDLE_EMPTY_MATCH;
|
HANDLE_EMPTY_MATCH;
|
||||||
|
|
||||||
Con *initially_focused = focused;
|
Con *initially_focused = focused;
|
||||||
|
direction_t direction = parse_direction(direction_str);
|
||||||
|
|
||||||
TAILQ_FOREACH(current, &owindows, owindows) {
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
||||||
DLOG("moving in direction %s, px %ld\n", direction, move_px);
|
DLOG("moving in direction %s, px %ld\n", direction_str, move_px);
|
||||||
if (con_is_floating(current->con)) {
|
if (con_is_floating(current->con)) {
|
||||||
DLOG("floating move with %ld pixels\n", move_px);
|
DLOG("floating move with %ld pixels\n", move_px);
|
||||||
Rect newrect = current->con->parent->rect;
|
Rect newrect = current->con->parent->rect;
|
||||||
if (strcmp(direction, "left") == 0) {
|
|
||||||
newrect.x -= move_px;
|
switch (direction) {
|
||||||
} else if (strcmp(direction, "right") == 0) {
|
case D_LEFT:
|
||||||
newrect.x += move_px;
|
newrect.x -= move_px;
|
||||||
} else if (strcmp(direction, "up") == 0) {
|
break;
|
||||||
newrect.y -= move_px;
|
case D_RIGHT:
|
||||||
} else if (strcmp(direction, "down") == 0) {
|
newrect.x += move_px;
|
||||||
newrect.y += move_px;
|
break;
|
||||||
|
case D_UP:
|
||||||
|
newrect.y -= move_px;
|
||||||
|
break;
|
||||||
|
case D_DOWN:
|
||||||
|
newrect.y += move_px;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
floating_reposition(current->con->parent, newrect);
|
floating_reposition(current->con->parent, newrect);
|
||||||
} else {
|
} else {
|
||||||
tree_move(current->con, (strcmp(direction, "right") == 0 ? D_RIGHT : (strcmp(direction, "left") == 0 ? D_LEFT : (strcmp(direction, "up") == 0 ? D_UP : D_DOWN))));
|
tree_move(current->con, direction);
|
||||||
cmd_output->needs_tree_render = true;
|
cmd_output->needs_tree_render = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue