Extends move command for floating windows

This commit is contained in:
Pavel Löbl 2012-03-23 13:39:17 +01:00 committed by Michael Stapelberg
parent 2763a23cc7
commit f78f137ed0
6 changed files with 145 additions and 1 deletions

View File

@ -1233,6 +1233,7 @@ focus <left|right|down|up>
focus <parent|child|floating|tiling|mode_toggle> focus <parent|child|floating|tiling|mode_toggle>
focus output <<left|right|down|up>|output> focus output <<left|right|down|up>|output>
move <left|right|down|up> [<px> px] move <left|right|down|up> [<px> px]
move [absolute] position [[<px> px] [<px> px]|center]
----------------------------------- -----------------------------------
Note that the amount of pixels you can specify for the +move+ command is only Note that the amount of pixels you can specify for the +move+ command is only
@ -1267,6 +1268,10 @@ bindsym mod+semicolon move right
# Move container, but make floating containers # Move container, but make floating containers
# move more than the default # move more than the default
bindsym mod+j move left 20 px bindsym mod+j move left 20 px
# Move floating container to the center
# of all outputs
bindsym mod+c move absolute position center
---------------------- ----------------------
=== Changing (named) workspaces/moving to workspaces === Changing (named) workspaces/moving to workspaces

View File

@ -223,6 +223,18 @@ void cmd_open(I3_CMD);
*/ */
void cmd_focus_output(I3_CMD, char *name); void cmd_focus_output(I3_CMD, char *name);
/**
* Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
*
*/
void cmd_move_window_to_position(I3_CMD, char *method, char *x, char *y);
/**
* Implementation of 'move [window|container] [to] [absolute] position center
*
*/
void cmd_move_window_to_center(I3_CMD, char *method);
/** /**
* Implementation of 'move scratchpad'. * Implementation of 'move scratchpad'.
* *

View File

@ -172,6 +172,7 @@ state RESIZE_TILING_OR:
# move [window|container] [to] scratchpad # move [window|container] [to] scratchpad
# move workspace to [output] <str> # move workspace to [output] <str>
# move scratchpad # move scratchpad
# move [window|container] [to] [absolute] position [ [<pixels> [px] <pixels> [px]] | center ]
state MOVE: state MOVE:
'window' 'window'
-> ->
@ -187,6 +188,10 @@ state MOVE:
-> call cmd_move_scratchpad() -> call cmd_move_scratchpad()
direction = 'left', 'right', 'up', 'down' direction = 'left', 'right', 'up', 'down'
-> MOVE_DIRECTION -> MOVE_DIRECTION
method = 'position'
-> MOVE_TO_POSITION
method = 'absolute'
-> MOVE_TO_ABSOLUTE_POSITION
state MOVE_DIRECTION: state MOVE_DIRECTION:
pixels = word pixels = word
@ -218,6 +223,26 @@ state MOVE_WORKSPACE_TO_OUTPUT:
output = string output = string
-> call cmd_move_workspace_to_output($output) -> call cmd_move_workspace_to_output($output)
state MOVE_TO_ABSOLUTE_POSITION:
'position'
-> MOVE_TO_POSITION
state MOVE_TO_POSITION:
'center'
-> call cmd_move_window_to_center($method)
coord_x = word
-> MOVE_TO_POSITION_X
state MOVE_TO_POSITION_X:
'px'
->
coord_y = word
-> MOVE_TO_POSITION_Y
state MOVE_TO_POSITION_Y:
'px', end
-> call cmd_move_window_to_position($method, $coord_x, $coord_y)
# mode <string> # mode <string>
state MODE: state MODE:
mode = string mode = string

View File

@ -1255,6 +1255,85 @@ void cmd_focus_output(I3_CMD, char *name) {
cmd_output->json_output = sstrdup("{\"success\": true}"); cmd_output->json_output = sstrdup("{\"success\": true}");
} }
/*
* Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
*
*/
void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy) {
int x = atoi(cx);
int y = atoi(cy);
if (!con_is_floating(focused)) {
ELOG("Cannot change position. The window/container is not floating\n");
sasprintf(&(cmd_output->json_output),
"{\"success\":false, \"error\":\"Cannot change position. "
"The window/container is not floating.\"}");
return;
}
if (strcmp(method, "absolute") == 0) {
focused->parent->rect.x = x;
focused->parent->rect.y = y;
DLOG("moving to absolute position %d %d\n", x, y);
floating_maybe_reassign_ws(focused->parent);
cmd_output->needs_tree_render = true;
}
if (strcmp(method, "position") == 0) {
Rect newrect = focused->parent->rect;
DLOG("moving to position %d %d\n", x, y);
newrect.x = x;
newrect.y = y;
floating_reposition(focused->parent, newrect);
}
// XXX: default reply for now, make this a better reply
cmd_output->json_output = sstrdup("{\"success\": true}");
}
/*
* Implementation of 'move [window|container] [to] [absolute] position center
*
*/
void cmd_move_window_to_center(I3_CMD, char *method) {
if (!con_is_floating(focused)) {
ELOG("Cannot change position. The window/container is not floating\n");
sasprintf(&(cmd_output->json_output),
"{\"success\":false, \"error\":\"Cannot change position. "
"The window/container is not floating.\"}");
}
if (strcmp(method, "absolute") == 0) {
Rect *rect = &focused->parent->rect;
DLOG("moving to absolute center\n");
rect->x = croot->rect.width/2 - rect->width/2;
rect->y = croot->rect.height/2 - rect->height/2;
floating_maybe_reassign_ws(focused->parent);
cmd_output->needs_tree_render = true;
}
if (strcmp(method, "position") == 0) {
Rect *wsrect = &con_get_workspace(focused)->rect;
Rect newrect = focused->parent->rect;
DLOG("moving to center\n");
newrect.x = wsrect->width/2 - newrect.width/2;
newrect.y = wsrect->height/2 - newrect.height/2;
floating_reposition(focused->parent, newrect);
}
// XXX: default reply for now, make this a better reply
cmd_output->json_output = sstrdup("{\"success\": true}");
}
/* /*
* Implementation of 'move scratchpad'. * Implementation of 'move scratchpad'.
* *

View File

@ -200,6 +200,29 @@ is($absolute->y, $absolute_before->y, 'y not changed');
is($absolute->width, $absolute_before->width, 'width not changed'); is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed'); is($absolute->height, $absolute_before->height, 'height not changed');
######################################################################
# 6) test moving floating window to a specified position
# and to absolute center
######################################################################
$tmp = fresh_workspace;
open_floating_window; my @floatcon;
cmd 'move position 5 px 15 px';
@floatcon = @{get_ws($tmp)->{floating_nodes}};
is($floatcon[0]->{rect}->{x}, 5, 'moved to position 5 x');
is($floatcon[0]->{rect}->{y}, 15, 'moved to position 15 y');
cmd 'move absolute position center';
@floatcon = @{get_ws($tmp)->{floating_nodes}};
my $center_x = int($x->root->rect->width/2) - int($floatcon[0]->{rect}->{width}/2);
my $center_y = int($x->root->rect->height/2) - int($floatcon[0]->{rect}->{height}/2);
is($floatcon[0]->{rect}->{x}, $center_x, "moved to center at position $center_x x");
is($floatcon[0]->{rect}->{y}, $center_y, "moved to center at position $center_y y");
done_testing; done_testing;

View File

@ -133,7 +133,7 @@ is(parser_calls('unknown_literal'),
'error for unknown literal ok'); 'error for unknown literal ok');
is(parser_calls('move something to somewhere'), is(parser_calls('move something to somewhere'),
"Expected one of these tokens: 'window', 'container', 'to', 'workspace', 'output', 'scratchpad', 'left', 'right', 'up', 'down'\n" . "Expected one of these tokens: 'window', 'container', 'to', 'workspace', 'output', 'scratchpad', 'left', 'right', 'up', 'down', 'position', 'absolute'\n" .
"Your command: move something to somewhere\n" . "Your command: move something to somewhere\n" .
" ^^^^^^^^^^^^^^^^^^^^^^", " ^^^^^^^^^^^^^^^^^^^^^^",
'error for unknown literal ok'); 'error for unknown literal ok');