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

@ -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);