Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Introduce CMD_FOCUS_WARN_CHILDREN
Browse files Browse the repository at this point in the history
  • Loading branch information
orestisfl committed Oct 13, 2019
1 parent 1e8e4d3 commit f402f45
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/commands.c
Expand Up @@ -1213,6 +1213,21 @@ void cmd_exec(I3_CMD, const char *nosn, const char *command) {
ysuccess(true);
}

#define CMD_FOCUS_WARN_CHILDREN \
do { \
int count = 0; \
owindow *current; \
TAILQ_FOREACH(current, &owindows, owindows) { \
count++; \
} \
\
if (count > 1) { \
LOG("WARNING: Your criteria for the focus command matches %d containers, " \
"while only exactly one container can be focused at a time.\n", \
count); \
} \
} while (0)

/*
* Implementation of 'focus left|right|up|down'.
*
Expand Down Expand Up @@ -1315,12 +1330,15 @@ void cmd_focus(I3_CMD) {
ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");

yerror("You have to specify which window/container should be focused");

return;
} else if (TAILQ_EMPTY(&owindows)) {
yerror("No window matches given criteria");
return;
}

CMD_FOCUS_WARN_CHILDREN;

Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
int count = 0;
owindow *current;
TAILQ_FOREACH(current, &owindows, owindows) {
Con *ws = con_get_workspace(current->con);
Expand All @@ -1332,7 +1350,6 @@ void cmd_focus(I3_CMD) {
/* In case this is a scratchpad window, call scratchpad_show(). */
if (ws == __i3_scratch) {
scratchpad_show(current->con);
count++;
/* While for the normal focus case we can change focus multiple
* times and only a single window ends up focused, we could show
* multiple scratchpad windows. So, rather break here. */
Expand All @@ -1341,16 +1358,10 @@ void cmd_focus(I3_CMD) {

LOG("focusing %p / %s\n", current->con, current->con->name);
con_activate_unblock(current->con);
count++;
}

if (count > 1)
LOG("WARNING: Your criteria for the focus command matches %d containers, "
"while only exactly one container can be focused at a time.\n",
count);

cmd_output->needs_tree_render = true;
ysuccess(count > 0);
ysuccess(true);
}

/*
Expand Down

0 comments on commit f402f45

Please sign in to comment.