Implement special value 'current' for output. (#2483)

This commit introduces the special 'current' value for outputs in both of

* move con to output current
* move workspace to output current

fixes #2357
This commit is contained in:
Ingo Bürk 2016-09-30 17:28:02 +02:00 committed by Michael Stapelberg
parent 6a8fb69eff
commit c71f6f8f7c
7 changed files with 63 additions and 42 deletions

View File

@ -2103,10 +2103,10 @@ To move a container to another RandR output (addressed by names like +LVDS1+ or
+right+, +up+ or +down+), there are two commands:
*Syntax*:
----------------------------------------------------
move container to output left|right|down|up|<output>
move workspace to output left|right|down|up|<output>
----------------------------------------------------
------------------------------------------------------------
move container to output left|right|down|up|current|<output>
move workspace to output left|right|down|up|current|<output>
------------------------------------------------------------
*Examples*:
--------------------------------------------------------

View File

@ -22,6 +22,12 @@ Con *output_get_content(Con *output);
*/
Output *get_output_from_string(Output *current_output, const char *output_str);
/**
* Returns the output for the given con.
*
*/
Output *get_output_for_con(Con *con);
/**
* Iterates over all outputs and pushes sticky windows to the currently visible
* workspace on that output.

View File

@ -87,17 +87,6 @@ static bool definitelyGreaterThan(float a, float b, float epsilon) {
return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
/*
* Returns the output containing the given container.
*/
static Output *get_output_of_con(Con *con) {
Con *output_con = con_get_output(con);
Output *output = get_output_by_name(output_con->name);
assert(output != NULL);
return output;
}
/*
* Checks whether we switched to a new workspace and returns false in that case,
* signaling that further workspace switching should be done by the calling function
@ -1036,7 +1025,7 @@ void cmd_move_con_to_output(I3_CMD, const char *name) {
TAILQ_FOREACH(current, &owindows, owindows) {
DLOG("matching: %p / %s\n", current->con, current->con->name);
Output *current_output = get_output_of_con(current->con);
Output *current_output = get_output_for_con(current->con);
assert(current_output != NULL);
Output *output = get_output_from_string(current_output, name);
@ -1648,7 +1637,7 @@ void cmd_focus_output(I3_CMD, const char *name) {
Output *output;
TAILQ_FOREACH(current, &owindows, owindows)
current_output = get_output_of_con(current->con);
current_output = get_output_for_con(current->con);
assert(current_output != NULL);
output = get_output_from_string(current_output, name);

View File

@ -101,8 +101,7 @@ static void attach_to_workspace(Con *con, Con *ws, direction_t direction) {
*/
static void move_to_output_directed(Con *con, direction_t direction) {
Con *old_ws = con_get_workspace(con);
Con *current_output_con = con_get_output(con);
Output *current_output = get_output_by_name(current_output_con->name);
Output *current_output = get_output_for_con(con);
Output *output = get_output_next(direction, current_output, CLOSEST_OUTPUT);
if (!output) {

View File

@ -31,18 +31,33 @@ Con *output_get_content(Con *output) {
*
*/
Output *get_output_from_string(Output *current_output, const char *output_str) {
Output *output;
if (strcasecmp(output_str, "current") == 0) {
return get_output_for_con(focused);
} else if (strcasecmp(output_str, "left") == 0) {
return get_output_next_wrap(D_LEFT, current_output);
} else if (strcasecmp(output_str, "right") == 0) {
return get_output_next_wrap(D_RIGHT, current_output);
} else if (strcasecmp(output_str, "up") == 0) {
return get_output_next_wrap(D_UP, current_output);
} else if (strcasecmp(output_str, "down") == 0) {
return get_output_next_wrap(D_DOWN, current_output);
}
if (strcasecmp(output_str, "left") == 0)
output = get_output_next_wrap(D_LEFT, current_output);
else if (strcasecmp(output_str, "right") == 0)
output = get_output_next_wrap(D_RIGHT, current_output);
else if (strcasecmp(output_str, "up") == 0)
output = get_output_next_wrap(D_UP, current_output);
else if (strcasecmp(output_str, "down") == 0)
output = get_output_next_wrap(D_DOWN, current_output);
else
output = get_output_by_name(output_str);
return get_output_by_name(output_str);
}
Output *get_output_for_con(Con *con) {
Con *output_con = con_get_output(con);
if (output_con == NULL) {
ELOG("Could not get the output container for con = %p.\n", con);
return NULL;
}
Output *output = get_output_by_name(output_con->name);
if (output == NULL) {
ELOG("Could not get output from name \"%s\".\n", output_con->name);
return NULL;
}
return output;
}

View File

@ -911,17 +911,12 @@ Con *workspace_encapsulate(Con *ws) {
bool workspace_move_to_output(Con *ws, const char *name) {
LOG("Trying to move workspace %p / %s to output \"%s\".\n", ws, ws->name, name);
Con *current_output_con = con_get_output(ws);
if (!current_output_con) {
ELOG("Could not get the output container for workspace %p / %s.\n", ws, ws->name);
return false;
}
Output *current_output = get_output_by_name(current_output_con->name);
if (!current_output) {
Output *current_output = get_output_for_con(ws);
if (current_output == NULL) {
ELOG("Cannot get current output. This is a bug in i3.\n");
return false;
}
Output *output = get_output_from_string(current_output, name);
if (!output) {
ELOG("Could not get output from string \"%s\"\n", name);

View File

@ -19,9 +19,6 @@
use List::Util qw(first);
use i3test i3_autostart => 0;
# TODO:
# introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
# Ensure the pointer is at (0, 0) so that we really start on the first
# (the left) workspace.
$x->root->warp_pointer(0, 0);
@ -163,6 +160,26 @@ ok(!($empty_ws ~~ @$x0), 'empty_ws not on fake-0');
ok(!($empty_ws ~~ @$x1), 'empty_ws not on fake-1');
ok($other_output_ws ~~ @$x0, 'other_output_ws on fake-0');
exit_gracefully($pid);
################################################################################
# Verify that the special word 'current' can be used for the output.
################################################################################
my $ws1 = fresh_workspace(output => 1);
open_window;
cmd 'mark marked';
my $ws0 = fresh_workspace(output => 0);
($x0, $x1) = workspaces_per_screen();
ok($ws0 ~~ @$x0, 'ws0 on fake-0');
ok($ws1 ~~ @$x1, 'ws1 on fake-1');
cmd '[con_mark=marked] move workspace to output current';
($x0, $x1) = workspaces_per_screen();
ok($ws1 ~~ @$x0, 'ws1 on fake-0');
################################################################################
exit_gracefully($pid);
done_testing;