2012-08-12 12:18:43 +02:00
|
|
|
|
#undef I3__FILE__
|
|
|
|
|
#define I3__FILE__ "commands.c"
|
2012-01-14 16:02:30 +01:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2015-04-04 02:17:56 +02:00
|
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2012-01-14 16:02:30 +01:00
|
|
|
|
*
|
|
|
|
|
* commands.c: all command functions (see commands_parser.c)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include <float.h>
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
#include <stdarg.h>
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
|
|
|
|
#include "all.h"
|
2013-06-05 15:04:57 +02:00
|
|
|
|
#include "shmlog.h"
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-05-02 22:01:50 +02:00
|
|
|
|
// Macros to make the YAJL API a bit easier to use.
|
2014-06-15 19:07:02 +02:00
|
|
|
|
#define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0)
|
|
|
|
|
#define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0)
|
|
|
|
|
#define ysuccess(success) \
|
|
|
|
|
do { \
|
|
|
|
|
if (cmd_output->json_gen != NULL) { \
|
|
|
|
|
y(map_open); \
|
|
|
|
|
ystr("success"); \
|
|
|
|
|
y(bool, success); \
|
|
|
|
|
y(map_close); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
2015-03-04 14:01:42 +01:00
|
|
|
|
#define yerror(format, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
if (cmd_output->json_gen != NULL) { \
|
|
|
|
|
char *message; \
|
|
|
|
|
sasprintf(&message, format, ##__VA_ARGS__); \
|
|
|
|
|
y(map_open); \
|
|
|
|
|
ystr("success"); \
|
|
|
|
|
y(bool, false); \
|
|
|
|
|
ystr("error"); \
|
|
|
|
|
ystr(message); \
|
|
|
|
|
y(map_close); \
|
|
|
|
|
free(message); \
|
|
|
|
|
} \
|
2014-06-15 19:07:02 +02:00
|
|
|
|
} while (0)
|
2012-05-02 22:01:50 +02:00
|
|
|
|
|
2015-12-09 13:39:08 +01:00
|
|
|
|
/** If an error occured during parsing of the criteria, we want to exit instead
|
|
|
|
|
* of relying on fallback behavior. See #2091. */
|
|
|
|
|
#define HANDLE_INVALID_MATCH \
|
|
|
|
|
do { \
|
|
|
|
|
if (current_match->error != NULL) { \
|
|
|
|
|
yerror("Invalid match: %s", current_match->error); \
|
|
|
|
|
return; \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
/** When the command did not include match criteria (!), we use the currently
|
2012-05-09 23:39:44 +02:00
|
|
|
|
* focused container. Do not confuse this case with a command which included
|
2012-01-14 16:02:30 +01:00
|
|
|
|
* criteria but which did not match any windows. This macro has to be called in
|
|
|
|
|
* every command.
|
|
|
|
|
*/
|
2014-06-15 19:07:02 +02:00
|
|
|
|
#define HANDLE_EMPTY_MATCH \
|
|
|
|
|
do { \
|
2015-12-09 13:39:08 +01:00
|
|
|
|
HANDLE_INVALID_MATCH; \
|
|
|
|
|
\
|
2014-06-15 19:07:02 +02:00
|
|
|
|
if (match_is_empty(current_match)) { \
|
|
|
|
|
owindow *ow = smalloc(sizeof(owindow)); \
|
|
|
|
|
ow->con = focused; \
|
|
|
|
|
TAILQ_INIT(&owindows); \
|
|
|
|
|
TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Returns true if a is definitely greater than b (using the given epsilon)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static bool definitelyGreaterThan(float a, float b, float epsilon) {
|
2014-06-15 19:07:02 +02:00
|
|
|
|
return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 13:17:23 +02:00
|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 16:05:27 +02:00
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
* If not, calls workspace_back_and_forth() if workspace_auto_back_and_forth is set
|
|
|
|
|
* and return true, signaling that no further workspace switching should occur in the calling function.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name) {
|
2012-05-02 16:05:27 +02:00
|
|
|
|
Con *ws = con_get_workspace(focused);
|
|
|
|
|
|
|
|
|
|
/* If we switched to a different workspace, do nothing */
|
|
|
|
|
if (strcmp(ws->name, name) != 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
DLOG("This workspace is already focused.\n");
|
2012-05-02 22:27:41 +02:00
|
|
|
|
if (config.workspace_auto_back_and_forth) {
|
|
|
|
|
workspace_back_and_forth();
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2012-05-02 16:05:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 10:51:18 +02:00
|
|
|
|
/*
|
|
|
|
|
* Return the passed workspace unless it is the current one and auto back and
|
|
|
|
|
* forth is enabled, in which case the back_and_forth workspace is returned.
|
|
|
|
|
*/
|
|
|
|
|
static Con *maybe_auto_back_and_forth_workspace(Con *workspace) {
|
|
|
|
|
Con *current, *baf;
|
|
|
|
|
|
|
|
|
|
if (!config.workspace_auto_back_and_forth)
|
|
|
|
|
return workspace;
|
|
|
|
|
|
|
|
|
|
current = con_get_workspace(focused);
|
|
|
|
|
|
|
|
|
|
if (current == workspace) {
|
|
|
|
|
baf = workspace_back_and_forth_get();
|
|
|
|
|
if (baf != NULL) {
|
|
|
|
|
DLOG("Substituting workspace with back_and_forth, as it is focused.\n");
|
|
|
|
|
return baf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return workspace;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:11:03 +01:00
|
|
|
|
// This code is commented out because we might recycle it for popping up error
|
|
|
|
|
// messages on parser errors.
|
|
|
|
|
#if 0
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
static pid_t migration_pid = -1;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Handler which will be called when we get a SIGCHLD for the nagbar, meaning
|
|
|
|
|
* it exited (or could not be started, depending on the exit code).
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
|
|
|
|
|
ev_child_stop(EV_A_ watcher);
|
|
|
|
|
if (!WIFEXITED(watcher->rstatus)) {
|
|
|
|
|
fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int exitcode = WEXITSTATUS(watcher->rstatus);
|
|
|
|
|
printf("i3-nagbar process exited with status %d\n", exitcode);
|
|
|
|
|
if (exitcode == 2) {
|
|
|
|
|
fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
migration_pid = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We need ev >= 4 for the following code. Since it is not *that* important (it
|
|
|
|
|
* only makes sure that there are no i3-nagbar instances left behind) we still
|
|
|
|
|
* support old systems with libev 3. */
|
|
|
|
|
#if EV_VERSION_MAJOR >= 4
|
|
|
|
|
/*
|
|
|
|
|
* Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
|
|
|
|
|
* SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
|
|
|
|
|
if (migration_pid != -1) {
|
|
|
|
|
LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid);
|
|
|
|
|
kill(migration_pid, SIGKILL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-03-31 10:53:04 +02:00
|
|
|
|
void cmd_MIGRATION_start_nagbar(void) {
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
if (migration_pid != -1) {
|
|
|
|
|
fprintf(stderr, "i3-nagbar already running.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "Starting i3-nagbar, command parsing differs from expected output.\n");
|
|
|
|
|
ELOG("Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n");
|
|
|
|
|
ELOG("i3-dump-log | gzip -9c > /tmp/i3.log.gz\n");
|
|
|
|
|
ELOG("FYI: Your i3 version is " I3_VERSION "\n");
|
|
|
|
|
migration_pid = fork();
|
|
|
|
|
if (migration_pid == -1) {
|
|
|
|
|
warn("Could not fork()");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* child */
|
|
|
|
|
if (migration_pid == 0) {
|
|
|
|
|
char *pageraction;
|
|
|
|
|
sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename);
|
|
|
|
|
char *argv[] = {
|
|
|
|
|
NULL, /* will be replaced by the executable path */
|
|
|
|
|
"-t",
|
|
|
|
|
"error",
|
|
|
|
|
"-m",
|
|
|
|
|
"You found a parsing error. Please, please, please, report it!",
|
|
|
|
|
"-b",
|
|
|
|
|
"show errors",
|
|
|
|
|
pageraction,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
exec_i3_utility("i3-nagbar", argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* parent */
|
|
|
|
|
/* install a child watcher */
|
|
|
|
|
ev_child *child = smalloc(sizeof(ev_child));
|
|
|
|
|
ev_child_init(child, &nagbar_exited, migration_pid, 0);
|
|
|
|
|
ev_child_start(main_loop, child);
|
|
|
|
|
|
|
|
|
|
/* We need ev >= 4 for the following code. Since it is not *that* important (it
|
|
|
|
|
* only makes sure that there are no i3-nagbar instances left behind) we still
|
|
|
|
|
* support old systems with libev 3. */
|
|
|
|
|
#if EV_VERSION_MAJOR >= 4
|
|
|
|
|
/* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
|
|
|
|
|
* still running) */
|
|
|
|
|
ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
|
|
|
|
|
ev_cleanup_init(cleanup, nagbar_cleanup);
|
|
|
|
|
ev_cleanup_start(main_loop, cleanup);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:11:03 +01:00
|
|
|
|
#endif
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Criteria functions.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2012-10-08 13:26:24 +02:00
|
|
|
|
/*
|
|
|
|
|
* Helper data structure for an operation window (window on which the operation
|
|
|
|
|
* will be performed). Used to build the TAILQ owindows.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
typedef struct owindow {
|
|
|
|
|
Con *con;
|
|
|
|
|
TAILQ_ENTRY(owindow) owindows;
|
|
|
|
|
} owindow;
|
|
|
|
|
|
|
|
|
|
typedef TAILQ_HEAD(owindows_head, owindow) owindows_head;
|
|
|
|
|
|
|
|
|
|
static owindows_head owindows;
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Initializes the specified 'Match' data structure and the initial state of
|
|
|
|
|
* commands.c for matching target windows of a command.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_criteria_init(I3_CMD) {
|
2012-01-27 22:47:55 +01:00
|
|
|
|
Con *con;
|
|
|
|
|
owindow *ow;
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("Initializing criteria, current_match = %p\n", current_match);
|
2014-03-19 09:34:42 +01:00
|
|
|
|
match_free(current_match);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
match_init(current_match);
|
2012-01-27 22:47:55 +01:00
|
|
|
|
while (!TAILQ_EMPTY(&owindows)) {
|
|
|
|
|
ow = TAILQ_FIRST(&owindows);
|
|
|
|
|
TAILQ_REMOVE(&owindows, ow, owindows);
|
|
|
|
|
free(ow);
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
TAILQ_INIT(&owindows);
|
|
|
|
|
/* copy all_cons */
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
2012-01-27 22:47:55 +01:00
|
|
|
|
ow = smalloc(sizeof(owindow));
|
2012-01-14 16:02:30 +01:00
|
|
|
|
ow->con = con;
|
|
|
|
|
TAILQ_INSERT_TAIL(&owindows, ow, owindows);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* A match specification just finished (the closing square bracket was found),
|
|
|
|
|
* so we filter the list of owindows.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_criteria_match_windows(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *next, *current;
|
|
|
|
|
|
|
|
|
|
DLOG("match specification finished, matching...\n");
|
|
|
|
|
/* copy the old list head to iterate through it and start with a fresh
|
|
|
|
|
* list which will contain only matching windows */
|
|
|
|
|
struct owindows_head old = owindows;
|
|
|
|
|
TAILQ_INIT(&owindows);
|
|
|
|
|
for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
|
|
|
|
|
/* make a copy of the next pointer and advance the pointer to the
|
|
|
|
|
* next element as we are going to invalidate the element’s
|
|
|
|
|
* next/prev pointers by calling TAILQ_INSERT_TAIL later */
|
|
|
|
|
current = next;
|
|
|
|
|
next = TAILQ_NEXT(next, owindows);
|
|
|
|
|
|
|
|
|
|
DLOG("checking if con %p / %s matches\n", current->con, current->con->name);
|
2015-12-15 13:38:56 +01:00
|
|
|
|
|
|
|
|
|
/* We use this flag to prevent matching on window-less containers if
|
|
|
|
|
* only window-specific criteria were specified. */
|
|
|
|
|
bool accept_match = false;
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
if (current_match->con_id != NULL) {
|
2015-12-15 13:38:56 +01:00
|
|
|
|
accept_match = true;
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
if (current_match->con_id == current->con) {
|
2015-12-15 13:38:56 +01:00
|
|
|
|
DLOG("con_id matched.\n");
|
2014-03-19 09:56:34 +01:00
|
|
|
|
} else {
|
2015-12-15 13:38:56 +01:00
|
|
|
|
DLOG("con_id does not match.\n");
|
|
|
|
|
FREE(current);
|
|
|
|
|
continue;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
2015-12-15 13:38:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_match->mark != NULL && !TAILQ_EMPTY(&(current->con->marks_head))) {
|
|
|
|
|
accept_match = true;
|
|
|
|
|
bool matched_by_mark = false;
|
|
|
|
|
|
2015-10-19 18:10:20 +02:00
|
|
|
|
mark_t *mark;
|
|
|
|
|
TAILQ_FOREACH(mark, &(current->con->marks_head), marks) {
|
|
|
|
|
if (!regex_matches(current_match->mark, mark->name))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
DLOG("match by mark\n");
|
2015-12-15 13:38:56 +01:00
|
|
|
|
matched_by_mark = true;
|
2015-10-19 18:10:20 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-12-15 13:38:56 +01:00
|
|
|
|
|
|
|
|
|
if (!matched_by_mark) {
|
|
|
|
|
DLOG("mark does not match.\n");
|
|
|
|
|
FREE(current);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current->con->window != NULL) {
|
|
|
|
|
if (match_matches_window(current_match, current->con->window)) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matches window!\n");
|
2015-12-15 13:38:56 +01:00
|
|
|
|
accept_match = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
} else {
|
|
|
|
|
DLOG("doesnt match\n");
|
2015-12-15 13:38:56 +01:00
|
|
|
|
FREE(current);
|
|
|
|
|
continue;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-15 13:38:56 +01:00
|
|
|
|
|
|
|
|
|
if (accept_match) {
|
|
|
|
|
TAILQ_INSERT_TAIL(&owindows, current, owindows);
|
|
|
|
|
} else {
|
|
|
|
|
FREE(current);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Interprets a ctype=cvalue pair and adds it to the current match
|
|
|
|
|
* specification.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue) {
|
2015-09-27 09:42:26 +02:00
|
|
|
|
match_parse_property(current_match, ctype, cvalue);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move [window|container] [to] workspace
|
2012-05-09 23:45:12 +02:00
|
|
|
|
* next|prev|next_on_output|prev_on_output|current'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_con_to_workspace(I3_CMD, const char *which) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
DLOG("which=%s\n", which);
|
|
|
|
|
|
2012-05-09 23:43:21 +02:00
|
|
|
|
/* We have nothing to move:
|
|
|
|
|
* when criteria was specified but didn't match any window or
|
|
|
|
|
* when criteria wasn't specified and we don't have any window focused. */
|
|
|
|
|
if ((!match_is_empty(current_match) && TAILQ_EMPTY(&owindows)) ||
|
2012-09-28 19:54:24 +02:00
|
|
|
|
(match_is_empty(current_match) && focused->type == CT_WORKSPACE &&
|
2014-06-15 19:07:02 +02:00
|
|
|
|
!con_has_children(focused))) {
|
2012-05-09 23:43:21 +02:00
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
/* get the workspace */
|
|
|
|
|
Con *ws;
|
|
|
|
|
if (strcmp(which, "next") == 0)
|
|
|
|
|
ws = workspace_next();
|
|
|
|
|
else if (strcmp(which, "prev") == 0)
|
|
|
|
|
ws = workspace_prev();
|
|
|
|
|
else if (strcmp(which, "next_on_output") == 0)
|
|
|
|
|
ws = workspace_next_on_output();
|
|
|
|
|
else if (strcmp(which, "prev_on_output") == 0)
|
|
|
|
|
ws = workspace_prev_on_output();
|
2012-05-09 23:45:12 +02:00
|
|
|
|
else if (strcmp(which, "current") == 0)
|
|
|
|
|
ws = con_get_workspace(focused);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
else {
|
|
|
|
|
ELOG("BUG: called with which=%s\n", which);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2015-08-26 21:06:53 +02:00
|
|
|
|
con_move_to_workspace(current->con, ws, true, false, false);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 10:51:18 +02:00
|
|
|
|
/**
|
|
|
|
|
* Implementation of 'move [window|container] [to] workspace back_and_forth'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void cmd_move_con_to_workspace_back_and_forth(I3_CMD) {
|
|
|
|
|
owindow *current;
|
|
|
|
|
Con *ws;
|
|
|
|
|
|
|
|
|
|
ws = workspace_back_and_forth_get();
|
|
|
|
|
|
|
|
|
|
if (ws == NULL) {
|
2013-09-25 23:17:38 +02:00
|
|
|
|
yerror("No workspace was previously active.");
|
2012-09-04 10:51:18 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-09-04 10:51:18 +02:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2015-08-26 21:06:53 +02:00
|
|
|
|
con_move_to_workspace(current->con, ws, true, false, false);
|
2012-09-04 10:51:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2015-10-26 22:38:06 +01:00
|
|
|
|
* Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace <name>'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-10-26 22:38:06 +01:00
|
|
|
|
void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
|
2014-04-30 11:12:22 +02:00
|
|
|
|
if (strncasecmp(name, "__", strlen("__")) == 0) {
|
2014-05-03 15:02:51 +02:00
|
|
|
|
LOG("You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 22:38:06 +01:00
|
|
|
|
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2012-05-09 23:43:21 +02:00
|
|
|
|
/* We have nothing to move:
|
|
|
|
|
* when criteria was specified but didn't match any window or
|
|
|
|
|
* when criteria wasn't specified and we don't have any window focused. */
|
2012-08-13 01:57:39 +02:00
|
|
|
|
if (!match_is_empty(current_match) && TAILQ_EMPTY(&owindows)) {
|
|
|
|
|
ELOG("No windows match your criteria, cannot move.\n");
|
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
} else if (match_is_empty(current_match) && focused->type == CT_WORKSPACE &&
|
|
|
|
|
!con_has_children(focused)) {
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
|
|
|
|
LOG("should move window to workspace %s\n", name);
|
|
|
|
|
/* get the workspace */
|
2015-03-24 09:27:42 +01:00
|
|
|
|
Con *ws = workspace_get(name, NULL);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2015-10-26 22:38:06 +01:00
|
|
|
|
if (!no_auto_back_and_forth)
|
|
|
|
|
ws = maybe_auto_back_and_forth_workspace(ws);
|
2012-09-04 10:51:18 +02:00
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2015-08-26 21:06:53 +02:00
|
|
|
|
con_move_to_workspace(current->con, ws, true, false, false);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 20:33:46 +02:00
|
|
|
|
/*
|
2015-10-26 22:38:06 +01:00
|
|
|
|
* Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace number <name>'.
|
2012-04-08 20:33:46 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-10-26 22:38:06 +01:00
|
|
|
|
void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
|
|
|
|
|
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
2012-05-09 23:43:21 +02:00
|
|
|
|
/* We have nothing to move:
|
|
|
|
|
* when criteria was specified but didn't match any window or
|
|
|
|
|
* when criteria wasn't specified and we don't have any window focused. */
|
|
|
|
|
if ((!match_is_empty(current_match) && TAILQ_EMPTY(&owindows)) ||
|
2012-09-28 19:54:24 +02:00
|
|
|
|
(match_is_empty(current_match) && focused->type == CT_WORKSPACE &&
|
2014-06-15 19:07:02 +02:00
|
|
|
|
!con_has_children(focused))) {
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-05 16:34:38 +02:00
|
|
|
|
LOG("should move window to workspace %s\n", which);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
/* get the workspace */
|
2012-04-08 20:45:49 +02:00
|
|
|
|
Con *output, *workspace = NULL;
|
2012-04-08 20:33:46 +02:00
|
|
|
|
|
2014-06-22 17:12:51 +02:00
|
|
|
|
long parsed_num = ws_name_to_number(which);
|
|
|
|
|
|
|
|
|
|
if (parsed_num == -1) {
|
2012-08-31 20:19:27 +02:00
|
|
|
|
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
|
2015-03-04 14:01:42 +01:00
|
|
|
|
yerror("Could not parse number \"%s\"", which);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
|
|
|
|
|
GREP_FIRST(workspace, output_get_content(output),
|
|
|
|
|
child->num == parsed_num);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
|
|
|
|
|
if (!workspace) {
|
2012-08-20 12:36:10 +02:00
|
|
|
|
workspace = workspace_get(which, NULL);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 22:38:06 +01:00
|
|
|
|
if (!no_auto_back_and_forth)
|
|
|
|
|
workspace = maybe_auto_back_and_forth_workspace(workspace);
|
2012-09-04 10:51:18 +02:00
|
|
|
|
|
2012-04-08 20:33:46 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-04-08 20:33:46 +02:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2015-08-26 21:06:53 +02:00
|
|
|
|
con_move_to_workspace(current->con, workspace, true, false, false);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-04-08 20:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 23:42:58 +02:00
|
|
|
|
static void cmd_resize_floating(I3_CMD, const char *way, const char *direction, Con *floating_con, int px) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
LOG("floating resize\n");
|
2012-11-27 09:26:31 +01:00
|
|
|
|
Rect old_rect = floating_con->rect;
|
2013-04-15 20:30:22 +02:00
|
|
|
|
Con *focused_con = con_descend_focused(floating_con);
|
|
|
|
|
|
|
|
|
|
/* ensure that resize will take place even if pixel increment is smaller than
|
|
|
|
|
* height increment or width increment.
|
|
|
|
|
* fixes #1011 */
|
2015-08-30 23:04:20 +02:00
|
|
|
|
const i3Window *window = focused_con->window;
|
|
|
|
|
if (window != NULL) {
|
|
|
|
|
if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 ||
|
2015-08-30 23:07:25 +02:00
|
|
|
|
strcmp(direction, "height") == 0) {
|
2015-08-30 23:04:20 +02:00
|
|
|
|
if (px < 0)
|
|
|
|
|
px = (-px < window->height_increment) ? -window->height_increment : px;
|
|
|
|
|
else
|
|
|
|
|
px = (px < window->height_increment) ? window->height_increment : px;
|
|
|
|
|
} else if (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0) {
|
|
|
|
|
if (px < 0)
|
|
|
|
|
px = (-px < window->width_increment) ? -window->width_increment : px;
|
|
|
|
|
else
|
|
|
|
|
px = (px < window->width_increment) ? window->width_increment : px;
|
|
|
|
|
}
|
2013-04-15 20:30:22 +02:00
|
|
|
|
}
|
2012-11-27 09:26:31 +01:00
|
|
|
|
|
2012-04-08 15:59:49 +02:00
|
|
|
|
if (strcmp(direction, "up") == 0) {
|
|
|
|
|
floating_con->rect.height += px;
|
2012-08-18 15:25:00 +02:00
|
|
|
|
} else if (strcmp(direction, "down") == 0 || strcmp(direction, "height") == 0) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
floating_con->rect.height += px;
|
|
|
|
|
} else if (strcmp(direction, "left") == 0) {
|
|
|
|
|
floating_con->rect.width += px;
|
|
|
|
|
} else {
|
|
|
|
|
floating_con->rect.width += px;
|
|
|
|
|
}
|
2012-11-22 05:15:49 +01:00
|
|
|
|
|
2012-11-25 20:55:49 +01:00
|
|
|
|
floating_check_size(floating_con);
|
2012-11-27 09:26:31 +01:00
|
|
|
|
|
|
|
|
|
/* 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 (memcmp(&old_rect, &(floating_con->rect), sizeof(Rect)) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (strcmp(direction, "up") == 0) {
|
2013-02-08 17:41:41 +01:00
|
|
|
|
floating_con->rect.y -= (floating_con->rect.height - old_rect.height);
|
2012-11-27 09:26:31 +01:00
|
|
|
|
} else if (strcmp(direction, "left") == 0) {
|
2013-02-08 17:41:41 +01:00
|
|
|
|
floating_con->rect.x -= (floating_con->rect.width - old_rect.width);
|
2012-11-27 09:26:31 +01:00
|
|
|
|
}
|
2012-09-24 21:14:40 +02:00
|
|
|
|
|
|
|
|
|
/* If this is a scratchpad window, don't auto center it from now on. */
|
|
|
|
|
if (floating_con->scratchpad_state == SCRATCHPAD_FRESH)
|
|
|
|
|
floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 23:42:58 +02:00
|
|
|
|
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
LOG("tiling resize\n");
|
2013-09-24 15:46:58 +02:00
|
|
|
|
Con *second = NULL;
|
|
|
|
|
Con *first = current;
|
|
|
|
|
direction_t search_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);
|
|
|
|
|
if (!res) {
|
|
|
|
|
LOG("No second container in this direction found.\n");
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-07-22 21:25:38 +02:00
|
|
|
|
return false;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
2012-07-22 21:37:26 +02:00
|
|
|
|
|
2013-09-24 15:46:58 +02:00
|
|
|
|
/* get the default percentage */
|
|
|
|
|
int children = con_num_children(first->parent);
|
|
|
|
|
LOG("ins. %d children\n", children);
|
|
|
|
|
double percentage = 1.0 / children;
|
|
|
|
|
LOG("default percentage = %f\n", percentage);
|
|
|
|
|
|
|
|
|
|
/* resize */
|
|
|
|
|
LOG("second->percent = %f\n", second->percent);
|
|
|
|
|
LOG("first->percent before = %f\n", first->percent);
|
|
|
|
|
if (first->percent == 0.0)
|
|
|
|
|
first->percent = percentage;
|
|
|
|
|
if (second->percent == 0.0)
|
|
|
|
|
second->percent = percentage;
|
|
|
|
|
double new_first_percent = first->percent + ((double)ppt / 100.0);
|
|
|
|
|
double new_second_percent = second->percent - ((double)ppt / 100.0);
|
|
|
|
|
LOG("new_first_percent = %f\n", new_first_percent);
|
|
|
|
|
LOG("new_second_percent = %f\n", new_second_percent);
|
2012-04-08 15:59:49 +02:00
|
|
|
|
/* Ensure that the new percentages are positive and greater than
|
|
|
|
|
* 0.05 to have a reasonable minimum size. */
|
2013-09-24 15:46:58 +02:00
|
|
|
|
if (definitelyGreaterThan(new_first_percent, 0.05, DBL_EPSILON) &&
|
|
|
|
|
definitelyGreaterThan(new_second_percent, 0.05, DBL_EPSILON)) {
|
|
|
|
|
first->percent += ((double)ppt / 100.0);
|
|
|
|
|
second->percent -= ((double)ppt / 100.0);
|
|
|
|
|
LOG("first->percent after = %f\n", first->percent);
|
|
|
|
|
LOG("second->percent after = %f\n", second->percent);
|
2012-04-08 15:59:49 +02:00
|
|
|
|
} else {
|
|
|
|
|
LOG("Not resizing, already at minimum size\n");
|
|
|
|
|
}
|
2012-07-22 21:25:38 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 23:42:58 +02:00
|
|
|
|
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
LOG("width/height resize\n");
|
|
|
|
|
/* get the appropriate current container (skip stacked/tabbed cons) */
|
|
|
|
|
while (current->parent->layout == L_STACKED ||
|
|
|
|
|
current->parent->layout == L_TABBED)
|
|
|
|
|
current = current->parent;
|
|
|
|
|
|
|
|
|
|
/* Then further go up until we find one with the matching orientation. */
|
|
|
|
|
orientation_t search_orientation =
|
|
|
|
|
(strcmp(direction, "width") == 0 ? HORIZ : VERT);
|
|
|
|
|
|
|
|
|
|
while (current->type != CT_WORKSPACE &&
|
|
|
|
|
current->type != CT_FLOATING_CON &&
|
2015-10-25 13:03:56 +01:00
|
|
|
|
(con_orientation(current->parent) != search_orientation || con_num_children(current->parent) == 1))
|
2012-04-08 15:59:49 +02:00
|
|
|
|
current = current->parent;
|
|
|
|
|
|
|
|
|
|
/* get the default percentage */
|
|
|
|
|
int children = con_num_children(current->parent);
|
|
|
|
|
LOG("ins. %d children\n", children);
|
|
|
|
|
double percentage = 1.0 / children;
|
|
|
|
|
LOG("default percentage = %f\n", percentage);
|
|
|
|
|
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
orientation_t orientation = con_orientation(current->parent);
|
2012-04-08 15:59:49 +02:00
|
|
|
|
|
|
|
|
|
if ((orientation == HORIZ &&
|
|
|
|
|
strcmp(direction, "height") == 0) ||
|
|
|
|
|
(orientation == VERT &&
|
|
|
|
|
strcmp(direction, "width") == 0)) {
|
|
|
|
|
LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
|
|
|
|
|
(orientation == HORIZ ? "horizontal" : "vertical"));
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-07-22 21:25:38 +02:00
|
|
|
|
return false;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (children == 1) {
|
|
|
|
|
LOG("This is the only container, cannot resize.\n");
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-07-22 21:25:38 +02:00
|
|
|
|
return false;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ensure all the other children have a percentage set. */
|
|
|
|
|
Con *child;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
LOG("child->percent = %f (child %p)\n", child->percent, child);
|
|
|
|
|
if (child->percent == 0.0)
|
|
|
|
|
child->percent = percentage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double new_current_percent = current->percent + ((double)ppt / 100.0);
|
|
|
|
|
double subtract_percent = ((double)ppt / 100.0) / (children - 1);
|
|
|
|
|
LOG("new_current_percent = %f\n", new_current_percent);
|
|
|
|
|
LOG("subtract_percent = %f\n", subtract_percent);
|
|
|
|
|
/* Ensure that the new percentages are positive and greater than
|
|
|
|
|
* 0.05 to have a reasonable minimum size. */
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
if (child == current)
|
|
|
|
|
continue;
|
|
|
|
|
if (!definitelyGreaterThan(child->percent - subtract_percent, 0.05, DBL_EPSILON)) {
|
|
|
|
|
LOG("Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->percent - subtract_percent);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-07-22 21:25:38 +02:00
|
|
|
|
return false;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON)) {
|
|
|
|
|
LOG("Not resizing, already at minimum size\n");
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-07-22 21:25:38 +02:00
|
|
|
|
return false;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current->percent += ((double)ppt / 100.0);
|
|
|
|
|
LOG("current->percent after = %f\n", current->percent);
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
|
2012-04-08 15:59:49 +02:00
|
|
|
|
if (child == current)
|
|
|
|
|
continue;
|
|
|
|
|
child->percent -= subtract_percent;
|
|
|
|
|
LOG("child->percent after (%p) = %f\n", child, child->percent);
|
|
|
|
|
}
|
2012-07-22 21:25:38 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2012-04-08 15:59:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px, long resize_ppt) {
|
2015-09-27 16:32:54 +02:00
|
|
|
|
DLOG("resizing in way %s, direction %s, px %ld or ppt %ld\n", way, direction, resize_px, resize_ppt);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
if (strcmp(way, "shrink") == 0) {
|
2015-09-27 16:32:54 +02:00
|
|
|
|
resize_px *= -1;
|
|
|
|
|
resize_ppt *= -1;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-28 20:36:25 +02:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2014-03-15 03:59:08 +01:00
|
|
|
|
/* Don't handle dock windows (issue #1201) */
|
2014-04-18 20:14:22 +02:00
|
|
|
|
if (current->con->window && current->con->window->dock) {
|
2014-03-15 03:59:08 +01:00
|
|
|
|
DLOG("This is a dock window. Not resizing (con = %p)\n)", current->con);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-28 20:36:25 +02:00
|
|
|
|
Con *floating_con;
|
|
|
|
|
if ((floating_con = con_inside_floating(current->con))) {
|
2015-09-27 16:32:54 +02:00
|
|
|
|
cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, resize_px);
|
2012-07-22 21:25:38 +02:00
|
|
|
|
} else {
|
2012-09-28 20:36:25 +02:00
|
|
|
|
if (strcmp(direction, "width") == 0 ||
|
|
|
|
|
strcmp(direction, "height") == 0) {
|
2015-09-27 16:32:54 +02:00
|
|
|
|
if (!cmd_resize_tiling_width_height(current_match, cmd_output,
|
|
|
|
|
current->con, way, direction, resize_ppt))
|
2012-09-28 20:36:25 +02:00
|
|
|
|
return;
|
|
|
|
|
} else {
|
2015-09-27 16:32:54 +02:00
|
|
|
|
if (!cmd_resize_tiling_direction(current_match, cmd_output,
|
|
|
|
|
current->con, way, direction, resize_ppt))
|
2012-09-28 20:36:25 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-22 21:25:38 +02:00
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-05 08:31:45 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'resize set <px> [px] <px> [px]'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 16:32:54 +02:00
|
|
|
|
void cmd_resize_set(I3_CMD, long cwidth, long cheight) {
|
|
|
|
|
DLOG("resizing to %ldx%ld px\n", cwidth, cheight);
|
|
|
|
|
if (cwidth <= 0 || cheight <= 0) {
|
|
|
|
|
ELOG("Resize failed: dimensions cannot be negative (was %ldx%ld)\n", cwidth, cheight);
|
2015-09-05 08:31:45 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
Con *floating_con;
|
|
|
|
|
if ((floating_con = con_inside_floating(current->con))) {
|
2015-09-27 16:32:54 +02:00
|
|
|
|
floating_resize(floating_con, cwidth, cheight);
|
2015-09-05 08:31:45 +02:00
|
|
|
|
} else {
|
|
|
|
|
ELOG("Resize failed: %p not a floating container\n", current->con);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2015-06-09 23:13:40 +02:00
|
|
|
|
* Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_border(I3_CMD, const char *border_style_str, const char *border_width) {
|
2012-09-24 01:14:00 +02:00
|
|
|
|
DLOG("border style should be changed to %s with border width %s\n", border_style_str, border_width);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
int border_style = current->con->border_style;
|
2012-09-24 01:14:00 +02:00
|
|
|
|
char *end;
|
|
|
|
|
int tmp_border_width = -1;
|
|
|
|
|
tmp_border_width = strtol(border_width, &end, 10);
|
|
|
|
|
if (end == border_width) {
|
|
|
|
|
/* no valid digits found */
|
|
|
|
|
tmp_border_width = -1;
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
if (strcmp(border_style_str, "toggle") == 0) {
|
|
|
|
|
border_style++;
|
|
|
|
|
border_style %= 3;
|
2012-09-24 01:14:00 +02:00
|
|
|
|
if (border_style == BS_NORMAL)
|
2012-09-28 19:29:14 +02:00
|
|
|
|
tmp_border_width = 2;
|
2012-09-24 01:14:00 +02:00
|
|
|
|
else if (border_style == BS_NONE)
|
2012-09-28 19:29:14 +02:00
|
|
|
|
tmp_border_width = 0;
|
2012-09-24 01:14:00 +02:00
|
|
|
|
else if (border_style == BS_PIXEL)
|
2012-09-28 19:29:14 +02:00
|
|
|
|
tmp_border_width = 1;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
} else {
|
|
|
|
|
if (strcmp(border_style_str, "normal") == 0)
|
|
|
|
|
border_style = BS_NORMAL;
|
2012-09-24 01:14:00 +02:00
|
|
|
|
else if (strcmp(border_style_str, "pixel") == 0)
|
|
|
|
|
border_style = BS_PIXEL;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else if (strcmp(border_style_str, "1pixel") == 0) {
|
2012-09-24 01:14:00 +02:00
|
|
|
|
border_style = BS_PIXEL;
|
|
|
|
|
tmp_border_width = 1;
|
|
|
|
|
} else if (strcmp(border_style_str, "none") == 0)
|
2012-01-14 16:02:30 +01:00
|
|
|
|
border_style = BS_NONE;
|
|
|
|
|
else {
|
|
|
|
|
ELOG("BUG: called with border_style=%s\n", border_style_str);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-24 01:14:00 +02:00
|
|
|
|
con_set_border_style(current->con, border_style, tmp_border_width);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'nop <comment>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_nop(I3_CMD, const char *comment) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("-------------------------------------------------\n");
|
|
|
|
|
LOG(" NOP: %s\n", comment);
|
|
|
|
|
LOG("-------------------------------------------------\n");
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'append_layout <path>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_append_layout(I3_CMD, const char *cpath) {
|
|
|
|
|
char *path = sstrdup(cpath);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("Appending layout \"%s\"\n", path);
|
2014-07-15 10:15:04 +02:00
|
|
|
|
|
2015-03-01 00:13:37 +01:00
|
|
|
|
/* Make sure we allow paths like '~/.i3/layout.json' */
|
|
|
|
|
path = resolve_tilde(path);
|
|
|
|
|
|
2014-07-15 10:15:04 +02:00
|
|
|
|
json_content_t content = json_determine_content(path);
|
|
|
|
|
LOG("JSON content = %d\n", content);
|
|
|
|
|
if (content == JSON_CONTENT_UNKNOWN) {
|
|
|
|
|
ELOG("Could not determine the contents of \"%s\", not loading.\n", path);
|
2015-03-04 22:45:39 +01:00
|
|
|
|
yerror("Could not determine the contents of \"%s\".", path);
|
2015-03-01 00:13:37 +01:00
|
|
|
|
free(path);
|
2014-07-15 10:15:04 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 22:49:33 +01:00
|
|
|
|
Con *parent = focused;
|
2014-07-15 10:15:04 +02:00
|
|
|
|
if (content == JSON_CONTENT_WORKSPACE) {
|
|
|
|
|
parent = output_get_content(con_get_output(parent));
|
|
|
|
|
} else {
|
|
|
|
|
/* We need to append the layout to a split container, since a leaf
|
|
|
|
|
* container must not have any children (by definition).
|
|
|
|
|
* Note that we explicitly check for workspaces, since they are okay for
|
|
|
|
|
* this purpose, but con_accepts_window() returns false for workspaces. */
|
|
|
|
|
while (parent->type != CT_WORKSPACE && !con_accepts_window(parent))
|
|
|
|
|
parent = parent->parent;
|
|
|
|
|
}
|
|
|
|
|
DLOG("Appending to parent=%p instead of focused=%p\n", parent, focused);
|
2014-01-04 21:39:13 +01:00
|
|
|
|
char *errormsg = NULL;
|
2014-04-18 20:30:27 +02:00
|
|
|
|
tree_append_json(parent, path, &errormsg);
|
2014-01-04 21:39:13 +01:00
|
|
|
|
if (errormsg != NULL) {
|
|
|
|
|
yerror(errormsg);
|
|
|
|
|
free(errormsg);
|
|
|
|
|
/* Note that we continue executing since tree_append_json() has
|
|
|
|
|
* side-effects — user-provided layouts can be partly valid, partly
|
|
|
|
|
* invalid, leading to half of the placeholder containers being
|
|
|
|
|
* created. */
|
|
|
|
|
} else {
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2013-12-14 22:49:33 +01:00
|
|
|
|
// XXX: This is a bit of a kludge. Theoretically, render_con(parent,
|
|
|
|
|
// false); should be enough, but when sending 'workspace 4; append_layout
|
|
|
|
|
// /tmp/foo.json', the needs_tree_render == true of the workspace command
|
|
|
|
|
// is not executed yet and will be batched with append_layout’s
|
|
|
|
|
// needs_tree_render after the parser finished. We should check if that is
|
|
|
|
|
// necessary at all.
|
|
|
|
|
render_con(croot, false);
|
|
|
|
|
|
|
|
|
|
restore_open_placeholder_windows(parent);
|
|
|
|
|
|
2014-07-15 10:15:04 +02:00
|
|
|
|
if (content == JSON_CONTENT_WORKSPACE)
|
2014-12-20 05:43:47 +01:00
|
|
|
|
ipc_send_workspace_event("restored", parent, NULL);
|
2014-07-15 10:15:04 +02:00
|
|
|
|
|
2015-03-01 00:13:37 +01:00
|
|
|
|
free(path);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_workspace(I3_CMD, const char *which) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
Con *ws;
|
|
|
|
|
|
|
|
|
|
DLOG("which=%s\n", which);
|
|
|
|
|
|
2014-11-29 18:22:56 +01:00
|
|
|
|
if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
|
|
|
|
|
LOG("Cannot switch workspace while in global fullscreen\n");
|
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
if (strcmp(which, "next") == 0)
|
|
|
|
|
ws = workspace_next();
|
|
|
|
|
else if (strcmp(which, "prev") == 0)
|
|
|
|
|
ws = workspace_prev();
|
|
|
|
|
else if (strcmp(which, "next_on_output") == 0)
|
|
|
|
|
ws = workspace_next_on_output();
|
|
|
|
|
else if (strcmp(which, "prev_on_output") == 0)
|
|
|
|
|
ws = workspace_prev_on_output();
|
|
|
|
|
else {
|
|
|
|
|
ELOG("BUG: called with which=%s\n", which);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
workspace_show(ws);
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 19:17:46 +02:00
|
|
|
|
/*
|
2015-10-23 23:36:37 +02:00
|
|
|
|
* Implementation of 'workspace [--no-auto-back-and-forth] number <name>'
|
2012-04-08 19:17:46 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-10-23 23:36:37 +02:00
|
|
|
|
void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
|
|
|
|
|
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
|
2012-04-08 20:45:49 +02:00
|
|
|
|
Con *output, *workspace = NULL;
|
2012-04-08 19:17:46 +02:00
|
|
|
|
|
2014-11-29 18:22:56 +01:00
|
|
|
|
if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
|
|
|
|
|
LOG("Cannot switch workspace while in global fullscreen\n");
|
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 17:12:51 +02:00
|
|
|
|
long parsed_num = ws_name_to_number(which);
|
|
|
|
|
|
|
|
|
|
if (parsed_num == -1) {
|
2012-08-31 20:19:27 +02:00
|
|
|
|
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
|
2015-03-04 14:01:42 +01:00
|
|
|
|
yerror("Could not parse number \"%s\"", which);
|
2012-04-08 19:17:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
|
|
|
|
|
GREP_FIRST(workspace, output_get_content(output),
|
|
|
|
|
child->num == parsed_num);
|
2012-04-08 19:17:46 +02:00
|
|
|
|
|
|
|
|
|
if (!workspace) {
|
2012-08-05 16:34:38 +02:00
|
|
|
|
LOG("There is no workspace with number %ld, creating a new one.\n", parsed_num);
|
2012-05-02 16:05:27 +02:00
|
|
|
|
ysuccess(true);
|
|
|
|
|
workspace_show_by_name(which);
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-04-08 19:17:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-10-23 23:36:37 +02:00
|
|
|
|
if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, workspace->name))
|
2012-05-02 16:05:27 +02:00
|
|
|
|
return;
|
2012-04-08 19:17:46 +02:00
|
|
|
|
workspace_show(workspace);
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-04-08 19:17:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'workspace back_and_forth'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_workspace_back_and_forth(I3_CMD) {
|
2014-11-29 18:22:56 +01:00
|
|
|
|
if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
|
|
|
|
|
LOG("Cannot switch workspace while in global fullscreen\n");
|
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
workspace_back_and_forth();
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2015-10-23 23:36:37 +02:00
|
|
|
|
* Implementation of 'workspace [--no-auto-back-and-forth] <name>'
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-10-23 23:36:37 +02:00
|
|
|
|
void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
|
|
|
|
|
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
|
|
|
|
|
|
2014-04-30 11:12:22 +02:00
|
|
|
|
if (strncasecmp(name, "__", strlen("__")) == 0) {
|
2014-05-03 15:02:51 +02:00
|
|
|
|
LOG("You cannot switch to the i3-internal workspaces (\"%s\").\n", name);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 18:22:56 +01:00
|
|
|
|
if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
|
|
|
|
|
LOG("Cannot switch workspace while in global fullscreen\n");
|
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("should switch to workspace %s\n", name);
|
2015-10-23 23:36:37 +02:00
|
|
|
|
if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, name))
|
2014-06-15 19:07:02 +02:00
|
|
|
|
return;
|
2015-03-24 09:27:42 +01:00
|
|
|
|
workspace_show_by_name(name);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2015-10-19 18:31:21 +02:00
|
|
|
|
* Implementation of 'mark [--add|--replace] [--toggle] <mark>'
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-10-19 18:31:21 +02:00
|
|
|
|
void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle) {
|
2015-03-28 19:12:25 +01:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2015-03-31 20:47:22 +02:00
|
|
|
|
owindow *current = TAILQ_FIRST(&owindows);
|
|
|
|
|
if (current == NULL) {
|
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Marks must be unique, i.e., no two windows must have the same mark. */
|
|
|
|
|
if (current != TAILQ_LAST(&owindows, owindows_head)) {
|
|
|
|
|
yerror("A mark must not be put onto more than one window");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2015-10-19 18:31:21 +02:00
|
|
|
|
|
|
|
|
|
mark_mode_t mark_mode = (mode == NULL || strcmp(mode, "--replace") == 0) ? MM_REPLACE : MM_ADD;
|
2015-09-25 19:17:46 +02:00
|
|
|
|
if (toggle != NULL) {
|
2015-10-19 18:31:21 +02:00
|
|
|
|
con_mark_toggle(current->con, mark, mark_mode);
|
2015-03-31 20:47:22 +02:00
|
|
|
|
} else {
|
2015-10-19 18:31:21 +02:00
|
|
|
|
con_mark(current->con, mark, mark_mode);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 00:33:14 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'unmark [mark]'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_unmark(I3_CMD, const char *mark) {
|
2015-10-20 08:14:42 +02:00
|
|
|
|
if (match_is_empty(current_match)) {
|
|
|
|
|
con_unmark(NULL, mark);
|
|
|
|
|
} else {
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
con_unmark(current->con, mark);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-16 00:33:14 +02:00
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'mode <string>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_mode(I3_CMD, const char *mode) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("mode=%s\n", mode);
|
|
|
|
|
switch_mode(mode);
|
|
|
|
|
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move [window|container] [to] output <str>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_con_to_output(I3_CMD, const char *name) {
|
2015-09-26 21:31:28 +02:00
|
|
|
|
DLOG("Should move window to output \"%s\".\n", name);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2015-09-26 21:31:28 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
bool had_error = false;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2015-09-26 21:31:28 +02:00
|
|
|
|
Output *current_output = get_output_of_con(current->con);
|
|
|
|
|
assert(current_output != NULL);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2015-09-26 21:31:28 +02:00
|
|
|
|
Output *output = get_output_from_string(current_output, name);
|
|
|
|
|
if (output == NULL) {
|
|
|
|
|
ELOG("Could not find output \"%s\", skipping.\n", name);
|
|
|
|
|
had_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Con *ws = NULL;
|
|
|
|
|
GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
|
|
|
|
|
if (ws == NULL) {
|
|
|
|
|
ELOG("Could not find a visible workspace on output %p.\n", output);
|
|
|
|
|
had_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2015-08-26 21:06:53 +02:00
|
|
|
|
con_move_to_workspace(current->con, ws, true, false, false);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2015-09-26 21:31:28 +02:00
|
|
|
|
ysuccess(!had_error);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 17:30:31 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move [container|window] [to] mark <str>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_con_to_mark(I3_CMD, const char *mark) {
|
2015-04-14 17:57:33 +02:00
|
|
|
|
DLOG("moving window to mark \"%s\"\n", mark);
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
bool result = true;
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
DLOG("moving matched window %p / %s to mark \"%s\"\n", current->con, current->con->name, mark);
|
|
|
|
|
result &= con_move_to_mark(current->con, mark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
ysuccess(result);
|
2015-04-12 17:30:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'floating enable|disable|toggle'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_floating(I3_CMD, const char *floating_mode) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
DLOG("floating_mode=%s\n", floating_mode);
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
if (strcmp(floating_mode, "toggle") == 0) {
|
|
|
|
|
DLOG("should toggle mode\n");
|
|
|
|
|
toggle_floating_mode(current->con, false);
|
|
|
|
|
} else {
|
|
|
|
|
DLOG("should switch mode to %s\n", floating_mode);
|
|
|
|
|
if (strcmp(floating_mode, "enable") == 0) {
|
|
|
|
|
floating_enable(current->con, false);
|
|
|
|
|
} else {
|
|
|
|
|
floating_disable(current->con, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move workspace to [output] <str>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_workspace_to_output(I3_CMD, const char *name) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("should move workspace to output %s\n", name);
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2015-03-04 09:22:25 +01:00
|
|
|
|
Con *ws = con_get_workspace(current->con);
|
|
|
|
|
bool success = workspace_move_to_output(ws, name);
|
|
|
|
|
if (!success) {
|
|
|
|
|
ELOG("Failed to move workspace to output.\n");
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'split v|h|vertical|horizontal'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_split(I3_CMD, const char *direction) {
|
2015-10-26 18:16:21 +01:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
con_set_layout: always use the parent container, handle workspaces properly
Previously, in case 'layout stacked' (for example) had been called
interactively, con_set_layout would be called with focused->parent,
while with for_window, it’d be called on the actual matching container.
This difference in behavior was the cause for the inability to use
'for_window [class="XTerm"] layout tabbed', which now works \o/, but
more on that below.
The change also allows us to handle the case of the user selecting a
CT_WORKSPACE container properly, that is, by using the special case and
creating a new split container on the workspace which gets all the
contents, but a new layout.
Now, before you are enthusiastic about the change and try to use
for_window magic in your config file, keep in mind: The 'layout' command
acts on the parent split container. That is, when using a line such as
this one:
for_window [class="XTerm"] layout tabbed
…and opening an XTerm when on a workspace with one single other window,
the whole workspace will be set tabbed (just as previously when you
opened an XTerm and sent 'layout tabbed' manually).
Therefore, to open XTerm in its own tabbed split container, you need to
split before:
for_window [class="XTerm"] split v, layout tabbed
The comma here is important! It says that the second command should not
be treated as an entirely unrelated command, but it should also relate
the matching window (while it does work with a ';', that is prone to
race-conditions and should be avoided).
fixes #358
2012-09-05 00:22:38 +02:00
|
|
|
|
owindow *current;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("splitting in direction %c\n", direction[0]);
|
2015-10-26 18:16:21 +01:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
if (con_is_docked(current->con)) {
|
|
|
|
|
ELOG("Cannot split a docked container, skipping.\n");
|
|
|
|
|
continue;
|
con_set_layout: always use the parent container, handle workspaces properly
Previously, in case 'layout stacked' (for example) had been called
interactively, con_set_layout would be called with focused->parent,
while with for_window, it’d be called on the actual matching container.
This difference in behavior was the cause for the inability to use
'for_window [class="XTerm"] layout tabbed', which now works \o/, but
more on that below.
The change also allows us to handle the case of the user selecting a
CT_WORKSPACE container properly, that is, by using the special case and
creating a new split container on the workspace which gets all the
contents, but a new layout.
Now, before you are enthusiastic about the change and try to use
for_window magic in your config file, keep in mind: The 'layout' command
acts on the parent split container. That is, when using a line such as
this one:
for_window [class="XTerm"] layout tabbed
…and opening an XTerm when on a workspace with one single other window,
the whole workspace will be set tabbed (just as previously when you
opened an XTerm and sent 'layout tabbed' manually).
Therefore, to open XTerm in its own tabbed split container, you need to
split before:
for_window [class="XTerm"] split v, layout tabbed
The comma here is important! It says that the second command should not
be treated as an entirely unrelated command, but it should also relate
the matching window (while it does work with a ';', that is prone to
race-conditions and should be avoided).
fixes #358
2012-09-05 00:22:38 +02:00
|
|
|
|
}
|
2015-10-26 18:16:21 +01:00
|
|
|
|
|
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
|
con_set_layout: always use the parent container, handle workspaces properly
Previously, in case 'layout stacked' (for example) had been called
interactively, con_set_layout would be called with focused->parent,
while with for_window, it’d be called on the actual matching container.
This difference in behavior was the cause for the inability to use
'for_window [class="XTerm"] layout tabbed', which now works \o/, but
more on that below.
The change also allows us to handle the case of the user selecting a
CT_WORKSPACE container properly, that is, by using the special case and
creating a new split container on the workspace which gets all the
contents, but a new layout.
Now, before you are enthusiastic about the change and try to use
for_window magic in your config file, keep in mind: The 'layout' command
acts on the parent split container. That is, when using a line such as
this one:
for_window [class="XTerm"] layout tabbed
…and opening an XTerm when on a workspace with one single other window,
the whole workspace will be set tabbed (just as previously when you
opened an XTerm and sent 'layout tabbed' manually).
Therefore, to open XTerm in its own tabbed split container, you need to
split before:
for_window [class="XTerm"] split v, layout tabbed
The comma here is important! It says that the second command should not
be treated as an entirely unrelated command, but it should also relate
the matching window (while it does work with a ';', that is prone to
race-conditions and should be avoided).
fixes #358
2012-09-05 00:22:38 +02:00
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2012-10-24 07:58:03 +02:00
|
|
|
|
* Implementation of 'kill [window|client]'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_kill(I3_CMD, const char *kill_mode_str) {
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
if (kill_mode_str == NULL)
|
|
|
|
|
kill_mode_str = "window";
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
DLOG("kill_mode=%s\n", kill_mode_str);
|
|
|
|
|
|
|
|
|
|
int kill_mode;
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
if (strcmp(kill_mode_str, "window") == 0)
|
2012-01-14 16:02:30 +01:00
|
|
|
|
kill_mode = KILL_WINDOW;
|
|
|
|
|
else if (strcmp(kill_mode_str, "client") == 0)
|
|
|
|
|
kill_mode = KILL_CLIENT;
|
|
|
|
|
else {
|
|
|
|
|
ELOG("BUG: called with kill_mode=%s\n", kill_mode_str);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 13:39:08 +01:00
|
|
|
|
HANDLE_INVALID_MATCH;
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
/* check if the match is empty, not if the result is empty */
|
|
|
|
|
if (match_is_empty(current_match))
|
|
|
|
|
tree_close_con(kill_mode);
|
|
|
|
|
else {
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
tree_close(current->con, kill_mode, false, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'exec [--no-startup-id] <command>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_exec(I3_CMD, const char *nosn, const char *command) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
bool no_startup_id = (nosn != NULL);
|
|
|
|
|
|
|
|
|
|
DLOG("should execute %s, no_startup_id = %d\n", command, no_startup_id);
|
|
|
|
|
start_application(command, no_startup_id);
|
|
|
|
|
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'focus left|right|up|down'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_focus_direction(I3_CMD, const char *direction) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("direction = *%s*\n", direction);
|
|
|
|
|
|
|
|
|
|
if (strcmp(direction, "left") == 0)
|
|
|
|
|
tree_next('p', HORIZ);
|
|
|
|
|
else if (strcmp(direction, "right") == 0)
|
|
|
|
|
tree_next('n', HORIZ);
|
|
|
|
|
else if (strcmp(direction, "up") == 0)
|
|
|
|
|
tree_next('p', VERT);
|
|
|
|
|
else if (strcmp(direction, "down") == 0)
|
|
|
|
|
tree_next('n', VERT);
|
|
|
|
|
else {
|
|
|
|
|
ELOG("Invalid focus direction (%s)\n", direction);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'focus tiling|floating|mode_toggle'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_focus_window_mode(I3_CMD, const char *window_mode) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("window_mode = %s\n", window_mode);
|
|
|
|
|
|
|
|
|
|
Con *ws = con_get_workspace(focused);
|
|
|
|
|
if (ws != NULL) {
|
|
|
|
|
if (strcmp(window_mode, "mode_toggle") == 0) {
|
2015-09-16 19:51:09 +02:00
|
|
|
|
if (con_inside_floating(focused))
|
2012-01-14 16:02:30 +01:00
|
|
|
|
window_mode = "tiling";
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
window_mode = "floating";
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
2015-09-16 19:51:09 +02:00
|
|
|
|
Con *current;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &(ws->focus_head), focused) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
if ((strcmp(window_mode, "floating") == 0 && current->type != CT_FLOATING_CON) ||
|
|
|
|
|
(strcmp(window_mode, "tiling") == 0 && current->type == CT_FLOATING_CON))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
con_focus(con_descend_focused(current));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'focus parent|child'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_focus_level(I3_CMD, const char *level) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("level = %s\n", level);
|
2012-05-26 23:36:25 +02:00
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
|
|
/* Focusing the parent can only be allowed if the newly
|
|
|
|
|
* focused container won't escape the fullscreen container. */
|
|
|
|
|
if (strcmp(level, "parent") == 0) {
|
|
|
|
|
if (focused && focused->parent) {
|
|
|
|
|
if (con_fullscreen_permits_focusing(focused->parent))
|
|
|
|
|
success = level_up();
|
|
|
|
|
else
|
2012-08-05 20:56:33 +02:00
|
|
|
|
ELOG("'focus parent': Currently in fullscreen, not going up\n");
|
2012-05-26 23:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-05-26 23:36:25 +02:00
|
|
|
|
/* Focusing a child should always be allowed. */
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
success = level_down();
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-05-26 23:36:25 +02:00
|
|
|
|
cmd_output->needs_tree_render = success;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-26 23:36:25 +02:00
|
|
|
|
ysuccess(success);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'focus'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_focus(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("current_match = %p\n", current_match);
|
|
|
|
|
|
|
|
|
|
if (match_is_empty(current_match)) {
|
|
|
|
|
ELOG("You have to specify which window/container should be focused.\n");
|
|
|
|
|
ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
|
|
|
|
|
|
2013-09-25 23:17:38 +02:00
|
|
|
|
yerror("You have to specify which window/container should be focused");
|
2012-05-02 22:01:50 +02:00
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 16:10:37 +01:00
|
|
|
|
Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
int count = 0;
|
2012-04-21 21:34:25 +02:00
|
|
|
|
owindow *current;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
Con *ws = con_get_workspace(current->con);
|
|
|
|
|
/* If no workspace could be found, this was a dock window.
|
|
|
|
|
* Just skip it, you cannot focus dock windows. */
|
|
|
|
|
if (!ws)
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-05-26 22:37:45 +02:00
|
|
|
|
/* Check the fullscreen focus constraints. */
|
|
|
|
|
if (!con_fullscreen_permits_focusing(current->con)) {
|
|
|
|
|
LOG("Cannot change focus while in fullscreen mode (fullscreen rules).\n");
|
2012-04-21 21:34:25 +02:00
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 16:10:37 +01:00
|
|
|
|
/* 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. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
/* If the container is not on the current workspace,
|
|
|
|
|
* workspace_show() will switch to a different workspace and (if
|
|
|
|
|
* enabled) trigger a mouse pointer warp to the currently focused
|
|
|
|
|
* container (!) on the target workspace.
|
|
|
|
|
*
|
|
|
|
|
* Therefore, before calling workspace_show(), we make sure that
|
|
|
|
|
* 'current' will be focused on the workspace. However, we cannot
|
|
|
|
|
* just con_focus(current) because then the pointer will not be
|
|
|
|
|
* warped at all (the code thinks we are already there).
|
|
|
|
|
*
|
|
|
|
|
* So we focus 'current' to make it the currently focused window of
|
|
|
|
|
* the target workspace, then revert focus. */
|
|
|
|
|
Con *currently_focused = focused;
|
|
|
|
|
con_focus(current->con);
|
|
|
|
|
con_focus(currently_focused);
|
|
|
|
|
|
|
|
|
|
/* Now switch to the workspace, then focus */
|
|
|
|
|
workspace_show(ws);
|
|
|
|
|
LOG("focusing %p / %s\n", current->con, current->con->name);
|
|
|
|
|
con_focus(current->con);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count > 1)
|
|
|
|
|
LOG("WARNING: Your criteria for the focus command matches %d containers, "
|
2014-06-15 19:07:02 +02:00
|
|
|
|
"while only exactly one container can be focused at a time.\n",
|
|
|
|
|
count);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2015-09-11 08:26:33 +02:00
|
|
|
|
ysuccess(count > 0);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2014-10-26 19:33:09 +01:00
|
|
|
|
* Implementation of 'fullscreen enable|toggle [global]' and
|
|
|
|
|
* 'fullscreen disable'
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode) {
|
2014-10-26 19:33:09 +01:00
|
|
|
|
fullscreen_mode_t mode = strcmp(fullscreen_mode, "global") == 0 ? CF_GLOBAL : CF_OUTPUT;
|
|
|
|
|
DLOG("%s fullscreen, mode = %s\n", action, fullscreen_mode);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2013-08-20 02:07:31 +02:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
2014-10-26 19:33:09 +01:00
|
|
|
|
if (strcmp(action, "toggle") == 0) {
|
|
|
|
|
con_toggle_fullscreen(current->con, mode);
|
|
|
|
|
} else if (strcmp(action, "enable") == 0) {
|
|
|
|
|
con_enable_fullscreen(current->con, mode);
|
|
|
|
|
} else if (strcmp(action, "disable") == 0) {
|
|
|
|
|
con_disable_fullscreen(current->con);
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-22 23:37:41 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'sticky enable|disable|toggle'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_sticky(I3_CMD, const char *action) {
|
2015-08-22 23:37:41 +02:00
|
|
|
|
DLOG("%s sticky on window\n", action);
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
if (current->con->window == NULL) {
|
|
|
|
|
ELOG("only containers holding a window can be made sticky, skipping con = %p\n", current->con);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DLOG("setting sticky for container = %p / %s\n", current->con, current->con->name);
|
|
|
|
|
|
|
|
|
|
bool sticky = false;
|
|
|
|
|
if (strcmp(action, "enable") == 0)
|
|
|
|
|
sticky = true;
|
|
|
|
|
else if (strcmp(action, "disable") == 0)
|
|
|
|
|
sticky = false;
|
|
|
|
|
else if (strcmp(action, "toggle") == 0)
|
|
|
|
|
sticky = !current->con->sticky;
|
|
|
|
|
|
|
|
|
|
current->con->sticky = sticky;
|
|
|
|
|
ewmh_update_sticky(current->con->window->id, sticky);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 21:06:53 +02:00
|
|
|
|
/* A window we made sticky might not be on a visible workspace right now, so we need to make
|
|
|
|
|
* sure it gets pushed to the front now. */
|
2015-09-17 22:52:56 +02:00
|
|
|
|
output_push_sticky_windows(focused);
|
2015-08-26 21:06:53 +02:00
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
2015-08-22 23:37:41 +02:00
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move <direction> [<pixels> [px]]'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_direction(I3_CMD, const char *direction, long move_px) {
|
2014-06-19 14:09:31 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
Con *initially_focused = focused;
|
|
|
|
|
|
2014-06-23 21:29:42 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2015-09-27 16:59:36 +02:00
|
|
|
|
DLOG("moving in direction %s, px %ld\n", direction, move_px);
|
2014-06-19 14:09:31 +02:00
|
|
|
|
if (con_is_floating(current->con)) {
|
2015-09-27 16:59:36 +02:00
|
|
|
|
DLOG("floating move with %ld pixels\n", move_px);
|
2014-06-19 14:09:31 +02:00
|
|
|
|
Rect newrect = current->con->parent->rect;
|
|
|
|
|
if (strcmp(direction, "left") == 0) {
|
2015-09-27 16:59:36 +02:00
|
|
|
|
newrect.x -= move_px;
|
2014-06-19 14:09:31 +02:00
|
|
|
|
} else if (strcmp(direction, "right") == 0) {
|
2015-09-27 16:59:36 +02:00
|
|
|
|
newrect.x += move_px;
|
2014-06-19 14:09:31 +02:00
|
|
|
|
} else if (strcmp(direction, "up") == 0) {
|
2015-09-27 16:59:36 +02:00
|
|
|
|
newrect.y -= move_px;
|
2014-06-19 14:09:31 +02:00
|
|
|
|
} else if (strcmp(direction, "down") == 0) {
|
2015-09-27 16:59:36 +02:00
|
|
|
|
newrect.y += move_px;
|
2014-06-19 14:09:31 +02:00
|
|
|
|
}
|
|
|
|
|
floating_reposition(current->con->parent, newrect);
|
|
|
|
|
} 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))));
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 14:09:31 +02:00
|
|
|
|
/* the move command should not disturb focus */
|
|
|
|
|
if (focused != initially_focused)
|
|
|
|
|
con_focus(initially_focused);
|
|
|
|
|
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_layout(I3_CMD, const char *layout_str) {
|
2015-10-26 18:16:21 +01:00
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
Implement a new parser for commands. (+test)
On the rationale of using a custom parser instead of a lex/yacc one, see this
quote from src/commands_parser.c:
We use a hand-written parser instead of lex/yacc because our commands are
easy for humans, not for computers. Thus, it’s quite hard to specify a
context-free grammar for the commands. A PEG grammar would be easier, but
there’s downsides to every PEG parser generator I have come accross so far.
This parser is basically a state machine which looks for literals or strings
and can push either on a stack. After identifying a literal or string, it
will either transition to the current state, to a different state, or call a
function (like cmd_move()).
Special care has been taken that error messages are useful and the code is
well testable (when compiled with -DTEST_PARSER it will output to stdout
instead of actually calling any function).
During the migration phase (I plan to completely switch to this parser before
4.2 will be released), the new parser will parse every command you send to
i3 and save the resulting call stack. Then, the old parser will parse your
input and actually execute the commands. Afterwards, both call stacks will be
compared and any differences will be logged.
The new parser works with 100% of the test suite and produces identical call
stacks.
2012-01-14 20:53:29 +01:00
|
|
|
|
if (strcmp(layout_str, "stacking") == 0)
|
|
|
|
|
layout_str = "stacked";
|
2013-05-22 06:28:13 +02:00
|
|
|
|
layout_t layout;
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
/* default is a special case which will be handled in con_set_layout(). */
|
|
|
|
|
if (strcmp(layout_str, "default") == 0)
|
|
|
|
|
layout = L_DEFAULT;
|
|
|
|
|
else if (strcmp(layout_str, "stacked") == 0)
|
|
|
|
|
layout = L_STACKED;
|
|
|
|
|
else if (strcmp(layout_str, "tabbed") == 0)
|
|
|
|
|
layout = L_TABBED;
|
|
|
|
|
else if (strcmp(layout_str, "splitv") == 0)
|
|
|
|
|
layout = L_SPLITV;
|
|
|
|
|
else if (strcmp(layout_str, "splith") == 0)
|
|
|
|
|
layout = L_SPLITH;
|
2012-08-05 16:34:38 +02:00
|
|
|
|
else {
|
|
|
|
|
ELOG("Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str);
|
|
|
|
|
return;
|
|
|
|
|
}
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
|
|
|
|
|
DLOG("changing layout to %s (%d)\n", layout_str, layout);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2015-10-26 18:16:21 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
if (con_is_docked(current->con)) {
|
|
|
|
|
ELOG("cannot change layout of a docked container, skipping it.\n");
|
|
|
|
|
continue;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
2015-10-26 18:16:21 +01:00
|
|
|
|
|
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
con_set_layout(current->con, layout);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'layout toggle [all|split]'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
if (toggle_mode == NULL)
|
|
|
|
|
toggle_mode = "default";
|
|
|
|
|
|
|
|
|
|
DLOG("toggling layout (mode = %s)\n", toggle_mode);
|
|
|
|
|
|
|
|
|
|
/* check if the match is empty, not if the result is empty */
|
|
|
|
|
if (match_is_empty(current_match))
|
con_set_layout: always use the parent container, handle workspaces properly
Previously, in case 'layout stacked' (for example) had been called
interactively, con_set_layout would be called with focused->parent,
while with for_window, it’d be called on the actual matching container.
This difference in behavior was the cause for the inability to use
'for_window [class="XTerm"] layout tabbed', which now works \o/, but
more on that below.
The change also allows us to handle the case of the user selecting a
CT_WORKSPACE container properly, that is, by using the special case and
creating a new split container on the workspace which gets all the
contents, but a new layout.
Now, before you are enthusiastic about the change and try to use
for_window magic in your config file, keep in mind: The 'layout' command
acts on the parent split container. That is, when using a line such as
this one:
for_window [class="XTerm"] layout tabbed
…and opening an XTerm when on a workspace with one single other window,
the whole workspace will be set tabbed (just as previously when you
opened an XTerm and sent 'layout tabbed' manually).
Therefore, to open XTerm in its own tabbed split container, you need to
split before:
for_window [class="XTerm"] split v, layout tabbed
The comma here is important! It says that the second command should not
be treated as an entirely unrelated command, but it should also relate
the matching window (while it does work with a ';', that is prone to
race-conditions and should be avoided).
fixes #358
2012-09-05 00:22:38 +02:00
|
|
|
|
con_toggle_layout(focused, toggle_mode);
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
else {
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
con_toggle_layout(current->con, toggle_mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2012-10-24 07:58:03 +02:00
|
|
|
|
* Implementation of 'exit'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_exit(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("Exiting due to user command.\n");
|
2014-06-08 22:13:43 +02:00
|
|
|
|
ipc_shutdown();
|
|
|
|
|
unlink(config.ipc_socket_path);
|
2012-06-29 23:13:25 +02:00
|
|
|
|
xcb_disconnect(conn);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|
|
/* unreached */
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2012-10-24 07:58:03 +02:00
|
|
|
|
* Implementation of 'reload'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_reload(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("reloading\n");
|
2012-12-24 16:53:20 +01:00
|
|
|
|
kill_nagbar(&config_error_nagbar_pid, false);
|
|
|
|
|
kill_nagbar(&command_error_nagbar_pid, false);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
load_configuration(conn, NULL, true);
|
|
|
|
|
x_set_i3_atoms();
|
|
|
|
|
/* Send an IPC event just in case the ws names have changed */
|
2014-12-20 05:43:47 +01:00
|
|
|
|
ipc_send_workspace_event("reload", NULL, NULL);
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
/* Send an update event for the barconfig just in case it has changed */
|
|
|
|
|
update_barconfig();
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2012-10-24 07:58:03 +02:00
|
|
|
|
* Implementation of 'restart'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_restart(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("restarting i3\n");
|
2014-06-11 09:17:43 +02:00
|
|
|
|
ipc_shutdown();
|
2014-06-27 09:04:51 +02:00
|
|
|
|
unlink(config.ipc_socket_path);
|
2014-06-11 09:17:43 +02:00
|
|
|
|
/* We need to call this manually since atexit handlers don’t get called
|
|
|
|
|
* when exec()ing */
|
|
|
|
|
purge_zerobyte_logfile();
|
2012-01-14 16:02:30 +01:00
|
|
|
|
i3_restart(false);
|
|
|
|
|
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
2012-10-24 07:58:03 +02:00
|
|
|
|
* Implementation of 'open'.
|
2012-01-27 23:32:40 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_open(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
LOG("opening new container\n");
|
|
|
|
|
Con *con = tree_open_con(NULL, NULL);
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
con->layout = L_SPLITH;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
con_focus(con);
|
2012-05-02 22:01:50 +02:00
|
|
|
|
|
|
|
|
|
y(map_open);
|
|
|
|
|
ystr("success");
|
|
|
|
|
y(bool, true);
|
|
|
|
|
ystr("id");
|
|
|
|
|
y(integer, (long int)con);
|
|
|
|
|
y(map_close);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'focus output <output>'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_focus_output(I3_CMD, const char *name) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
DLOG("name = %s\n", name);
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
/* get the output */
|
|
|
|
|
Output *current_output = NULL;
|
|
|
|
|
Output *output;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows)
|
|
|
|
|
current_output = get_output_of_con(current->con);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
assert(current_output != NULL);
|
|
|
|
|
|
|
|
|
|
output = get_output_from_string(current_output, name);
|
|
|
|
|
|
|
|
|
|
if (!output) {
|
|
|
|
|
LOG("No such output found.\n");
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get visible workspace on output */
|
|
|
|
|
Con *ws = NULL;
|
|
|
|
|
GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
|
2012-02-07 23:38:21 +01:00
|
|
|
|
if (!ws) {
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(false);
|
2012-02-07 23:38:21 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-01-14 16:02:30 +01:00
|
|
|
|
|
|
|
|
|
workspace_show(ws);
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-23 13:39:17 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y) {
|
2014-07-01 08:12:28 +02:00
|
|
|
|
bool has_error = false;
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2014-07-01 08:12:28 +02:00
|
|
|
|
owindow *current;
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
if (!con_is_floating(current->con)) {
|
|
|
|
|
ELOG("Cannot change position. The window/container is not floating\n");
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2014-07-01 08:12:28 +02:00
|
|
|
|
if (!has_error) {
|
|
|
|
|
yerror("Cannot change position of a window/container because it is not floating.");
|
|
|
|
|
has_error = true;
|
|
|
|
|
}
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2014-07-01 08:12:28 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(method, "absolute") == 0) {
|
|
|
|
|
current->con->parent->rect.x = x;
|
|
|
|
|
current->con->parent->rect.y = y;
|
|
|
|
|
|
2015-09-27 16:59:36 +02:00
|
|
|
|
DLOG("moving to absolute position %ld %ld\n", x, y);
|
2014-07-01 08:12:28 +02:00
|
|
|
|
floating_maybe_reassign_ws(current->con->parent);
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
}
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2014-07-01 08:12:28 +02:00
|
|
|
|
if (strcmp(method, "position") == 0) {
|
|
|
|
|
Rect newrect = current->con->parent->rect;
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2015-09-27 16:59:36 +02:00
|
|
|
|
DLOG("moving to position %ld %ld\n", x, y);
|
2014-07-01 08:12:28 +02:00
|
|
|
|
newrect.x = x;
|
|
|
|
|
newrect.y = y;
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2014-07-01 08:12:28 +02:00
|
|
|
|
floating_reposition(current->con->parent, newrect);
|
|
|
|
|
}
|
2012-03-23 13:39:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2014-07-01 08:12:28 +02:00
|
|
|
|
if (!has_error)
|
|
|
|
|
ysuccess(true);
|
2012-03-23 13:39:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move [window|container] [to] [absolute] position center
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_move_window_to_center(I3_CMD, const char *method) {
|
2015-12-03 13:24:39 +01:00
|
|
|
|
bool has_error = false;
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2015-12-03 13:24:39 +01:00
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
Con *floating_con = con_inside_floating(current->con);
|
|
|
|
|
if (floating_con == NULL) {
|
|
|
|
|
ELOG("con %p / %s is not floating, cannot move it to the center.\n",
|
|
|
|
|
current->con, current->con->name);
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2015-12-03 13:24:39 +01:00
|
|
|
|
if (!has_error) {
|
|
|
|
|
yerror("Cannot change position of a window/container because it is not floating.");
|
|
|
|
|
has_error = true;
|
|
|
|
|
}
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2015-12-03 13:24:39 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-03-23 13:39:17 +01:00
|
|
|
|
|
2015-12-03 13:24:39 +01:00
|
|
|
|
if (strcmp(method, "absolute") == 0) {
|
|
|
|
|
DLOG("moving to absolute center\n");
|
|
|
|
|
floating_center(floating_con, croot->rect);
|
|
|
|
|
|
|
|
|
|
floating_maybe_reassign_ws(floating_con);
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(method, "position") == 0) {
|
|
|
|
|
DLOG("moving to center\n");
|
|
|
|
|
floating_center(floating_con, con_get_workspace(floating_con)->rect);
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
}
|
2012-03-23 13:39:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2015-12-03 13:24:39 +01:00
|
|
|
|
if (!has_error)
|
|
|
|
|
ysuccess(true);
|
2012-03-23 13:39:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-03 00:19:26 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move [window|container] [to] position mouse'
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void cmd_move_window_to_mouse(I3_CMD) {
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
Con *floating_con = con_inside_floating(current->con);
|
|
|
|
|
if (floating_con == NULL) {
|
|
|
|
|
DLOG("con %p / %s is not floating, cannot move it to the mouse position.\n",
|
|
|
|
|
current->con, current->con->name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DLOG("moving floating container %p / %s to cursor position\n", floating_con, floating_con->name);
|
|
|
|
|
floating_move_to_pointer(floating_con);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'move scratchpad'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_move_scratchpad(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("should move window to scratchpad\n");
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
scratchpad_move(current->con);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 23:32:40 +01:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'scratchpad show'.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-02-07 23:38:21 +01:00
|
|
|
|
void cmd_scratchpad_show(I3_CMD) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("should show scratchpad window\n");
|
|
|
|
|
owindow *current;
|
|
|
|
|
|
|
|
|
|
if (match_is_empty(current_match)) {
|
|
|
|
|
scratchpad_show(NULL);
|
|
|
|
|
} else {
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
2012-01-14 16:02:30 +01:00
|
|
|
|
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
|
|
|
|
scratchpad_show(current->con);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 23:38:21 +01:00
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-01-14 16:02:30 +01:00
|
|
|
|
// XXX: default reply for now, make this a better reply
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-01-14 16:02:30 +01:00
|
|
|
|
}
|
2012-04-08 20:34:31 +02:00
|
|
|
|
|
2015-06-10 18:59:45 +02:00
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'title_format <format>'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_title_format(I3_CMD, const char *format) {
|
2015-06-10 19:01:05 +02:00
|
|
|
|
DLOG("setting title_format to \"%s\"\n", format);
|
|
|
|
|
HANDLE_EMPTY_MATCH;
|
|
|
|
|
|
|
|
|
|
owindow *current;
|
|
|
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
|
|
|
if (current->con->window == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
DLOG("setting title_format for %p / %s\n", current->con, current->con->name);
|
|
|
|
|
FREE(current->con->window->title_format);
|
|
|
|
|
|
|
|
|
|
/* If we only display the title without anything else, we can skip the parsing step,
|
|
|
|
|
* so we remove the title format altogether. */
|
2015-08-30 10:10:37 +02:00
|
|
|
|
if (strcasecmp(format, "%title") != 0) {
|
2015-06-10 19:01:05 +02:00
|
|
|
|
current->con->window->title_format = sstrdup(format);
|
|
|
|
|
|
2015-08-30 10:10:37 +02:00
|
|
|
|
i3String *formatted_title = window_parse_title_format(current->con->window);
|
|
|
|
|
ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
|
|
|
|
|
I3STRING_FREE(formatted_title);
|
|
|
|
|
} else {
|
|
|
|
|
/* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
|
|
|
|
|
ewmh_update_visible_name(current->con->window->id, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 19:01:05 +02:00
|
|
|
|
/* Make sure the window title is redrawn immediately. */
|
|
|
|
|
current->con->window->name_x_changed = true;
|
|
|
|
|
}
|
2015-06-10 18:59:45 +02:00
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 20:34:31 +02:00
|
|
|
|
/*
|
2012-10-29 22:42:20 +01:00
|
|
|
|
* Implementation of 'rename workspace [<name>] to <name>'
|
2012-04-08 20:34:31 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
|
2014-04-30 11:12:22 +02:00
|
|
|
|
if (strncasecmp(new_name, "__", strlen("__")) == 0) {
|
2015-06-30 20:48:35 +02:00
|
|
|
|
LOG("Cannot rename workspace to \"%s\": names starting with __ are i3-internal.\n", new_name);
|
2014-04-30 11:12:22 +02:00
|
|
|
|
ysuccess(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-10-29 22:42:20 +01:00
|
|
|
|
if (old_name) {
|
|
|
|
|
LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
|
|
|
|
|
} else {
|
|
|
|
|
LOG("Renaming current workspace to \"%s\"\n", new_name);
|
|
|
|
|
}
|
2012-04-08 20:34:31 +02:00
|
|
|
|
|
|
|
|
|
Con *output, *workspace = NULL;
|
2012-10-29 22:42:20 +01:00
|
|
|
|
if (old_name) {
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
|
|
|
|
|
GREP_FIRST(workspace, output_get_content(output),
|
|
|
|
|
!strcasecmp(child->name, old_name));
|
2012-10-29 22:42:20 +01:00
|
|
|
|
} else {
|
|
|
|
|
workspace = con_get_workspace(focused);
|
2015-03-30 08:23:00 +02:00
|
|
|
|
old_name = workspace->name;
|
2012-10-29 22:42:20 +01:00
|
|
|
|
}
|
2012-04-08 20:34:31 +02:00
|
|
|
|
|
|
|
|
|
if (!workspace) {
|
2015-03-04 14:01:42 +01:00
|
|
|
|
yerror("Old workspace \"%s\" not found", old_name);
|
2012-04-08 20:34:31 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Con *check_dest = NULL;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
|
|
|
|
|
GREP_FIRST(check_dest, output_get_content(output),
|
|
|
|
|
!strcasecmp(child->name, new_name));
|
2012-04-08 20:34:31 +02:00
|
|
|
|
|
|
|
|
|
if (check_dest != NULL) {
|
2015-03-04 14:01:42 +01:00
|
|
|
|
yerror("New workspace \"%s\" already exists", new_name);
|
2012-04-08 20:34:31 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Change the name and try to parse it as a number. */
|
|
|
|
|
FREE(workspace->name);
|
|
|
|
|
workspace->name = sstrdup(new_name);
|
2014-06-22 17:12:51 +02:00
|
|
|
|
|
|
|
|
|
workspace->num = ws_name_to_number(new_name);
|
2012-04-08 20:34:31 +02:00
|
|
|
|
LOG("num = %d\n", workspace->num);
|
|
|
|
|
|
|
|
|
|
/* By re-attaching, the sort order will be correct afterwards. */
|
|
|
|
|
Con *previously_focused = focused;
|
|
|
|
|
Con *parent = workspace->parent;
|
|
|
|
|
con_detach(workspace);
|
|
|
|
|
con_attach(workspace, parent, false);
|
2015-03-04 09:06:44 +01:00
|
|
|
|
|
|
|
|
|
/* Move the workspace to the correct output if it has an assignment */
|
|
|
|
|
struct Workspace_Assignment *assignment = NULL;
|
|
|
|
|
TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
|
|
|
|
|
if (assignment->output == NULL)
|
|
|
|
|
continue;
|
2015-03-14 22:31:58 +01:00
|
|
|
|
if (strcmp(assignment->name, workspace->name) != 0 && (!name_is_digits(assignment->name) || ws_name_to_number(assignment->name) != workspace->num)) {
|
2015-03-04 09:06:44 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 09:22:25 +01:00
|
|
|
|
workspace_move_to_output(workspace, assignment->output);
|
2015-03-16 04:30:00 +01:00
|
|
|
|
|
|
|
|
|
if (previously_focused)
|
|
|
|
|
workspace_show(con_get_workspace(previously_focused));
|
|
|
|
|
|
2015-03-04 09:06:44 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 20:34:31 +02:00
|
|
|
|
/* Restore the previous focus since con_attach messes with the focus. */
|
|
|
|
|
con_focus(previously_focused);
|
|
|
|
|
|
|
|
|
|
cmd_output->needs_tree_render = true;
|
2012-05-02 22:01:50 +02:00
|
|
|
|
ysuccess(true);
|
2012-04-08 20:34:31 +02:00
|
|
|
|
|
2014-12-20 05:43:47 +01:00
|
|
|
|
ipc_send_workspace_event("rename", workspace, NULL);
|
2014-06-23 23:44:24 +02:00
|
|
|
|
ewmh_update_desktop_names();
|
|
|
|
|
ewmh_update_desktop_viewport();
|
|
|
|
|
ewmh_update_current_desktop();
|
2015-03-07 00:13:54 +01:00
|
|
|
|
|
|
|
|
|
startup_sequence_rename_workspace(old_name, new_name);
|
2012-04-08 20:34:31 +02:00
|
|
|
|
}
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
bool cmd_bar_mode(const char *bar_mode, const char *bar_id) {
|
2013-08-18 18:12:19 +02:00
|
|
|
|
int mode = M_DOCK;
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
bool toggle = false;
|
|
|
|
|
if (strcmp(bar_mode, "dock") == 0)
|
|
|
|
|
mode = M_DOCK;
|
|
|
|
|
else if (strcmp(bar_mode, "hide") == 0)
|
|
|
|
|
mode = M_HIDE;
|
|
|
|
|
else if (strcmp(bar_mode, "invisible") == 0)
|
|
|
|
|
mode = M_INVISIBLE;
|
|
|
|
|
else if (strcmp(bar_mode, "toggle") == 0)
|
|
|
|
|
toggle = true;
|
|
|
|
|
else {
|
|
|
|
|
ELOG("Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool changed_sth = false;
|
|
|
|
|
Barconfig *current = NULL;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &barconfigs, configs) {
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
if (bar_id && strcmp(current->id, bar_id) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (toggle)
|
|
|
|
|
mode = (current->mode + 1) % 2;
|
|
|
|
|
|
|
|
|
|
DLOG("Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->id, bar_mode, mode);
|
|
|
|
|
current->mode = mode;
|
|
|
|
|
changed_sth = true;
|
|
|
|
|
|
|
|
|
|
if (bar_id)
|
2014-06-15 19:07:02 +02:00
|
|
|
|
break;
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bar_id && !changed_sth) {
|
|
|
|
|
DLOG("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'bar hidden_state hide|show|toggle [<bar_id>]'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
bool cmd_bar_hidden_state(const char *bar_hidden_state, const char *bar_id) {
|
2013-08-18 18:12:19 +02:00
|
|
|
|
int hidden_state = S_SHOW;
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
bool toggle = false;
|
|
|
|
|
if (strcmp(bar_hidden_state, "hide") == 0)
|
|
|
|
|
hidden_state = S_HIDE;
|
|
|
|
|
else if (strcmp(bar_hidden_state, "show") == 0)
|
|
|
|
|
hidden_state = S_SHOW;
|
|
|
|
|
else if (strcmp(bar_hidden_state, "toggle") == 0)
|
|
|
|
|
toggle = true;
|
|
|
|
|
else {
|
|
|
|
|
ELOG("Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool changed_sth = false;
|
|
|
|
|
Barconfig *current = NULL;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(current, &barconfigs, configs) {
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
if (bar_id && strcmp(current->id, bar_id) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (toggle)
|
|
|
|
|
hidden_state = (current->hidden_state + 1) % 2;
|
|
|
|
|
|
|
|
|
|
DLOG("Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->id, bar_hidden_state, hidden_state);
|
|
|
|
|
current->hidden_state = hidden_state;
|
|
|
|
|
changed_sth = true;
|
|
|
|
|
|
|
|
|
|
if (bar_id)
|
2014-06-15 19:07:02 +02:00
|
|
|
|
break;
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bar_id && !changed_sth) {
|
|
|
|
|
DLOG("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_bar(I3_CMD, const char *bar_type, const char *bar_value, const char *bar_id) {
|
introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3.
Therefore, two new i3 command were introduced:
_
bar hidden_state show|hide|toggle [<bar_id>]
show: always show the bar
hide: normal hide mode
toggle: toggle between show and hide (individually for each bar)
_
bar mode dock|hide|invisible|toggle [<bar_id>]
hide,dock: like before
invisible: always keep the bar hidden
toggle: toggle between dock and hide (individually for each bar)
This patch introduces a hidden_state ("hidden_state hide|show") in the
barconfig, which indicates the current hidden_state of each i3bar
instance. It only affects the bar when in hide mode. Additionally, a new
invisible mode was introduced. In order to change the hidden_state or
mode of the bar from i3, a barconfig-update event was introduced, for
which a bar can subscribe and the bar then gets notified about the
currently set hidden_state and mode in its barconfig.
For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can
set the desired id for the corresponding bar. If the id is not specified, i3 will
deterministically choose an id; otherwise, with the previous random approach for finding
a new id, which is actually not shared with i3bar, as it would determine its id on
startup, the event-subscription would be destroyed on reload. Still, this issue remains
when manually changing the bar_id in the config and then reloading.
fixes #833, #651
2013-05-25 14:30:00 +02:00
|
|
|
|
bool ret;
|
|
|
|
|
if (strcmp(bar_type, "mode") == 0)
|
|
|
|
|
ret = cmd_bar_mode(bar_value, bar_id);
|
|
|
|
|
else if (strcmp(bar_type, "hidden_state") == 0)
|
|
|
|
|
ret = cmd_bar_hidden_state(bar_value, bar_id);
|
|
|
|
|
else {
|
|
|
|
|
ELOG("Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
|
|
|
|
|
ret = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ysuccess(ret);
|
|
|
|
|
if (!ret)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
update_barconfig();
|
|
|
|
|
}
|
2013-06-05 15:04:57 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'shmlog <size>|toggle|on|off'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_shmlog(I3_CMD, const char *argument) {
|
2014-06-15 19:07:02 +02:00
|
|
|
|
if (!strcmp(argument, "toggle"))
|
2013-06-05 15:04:57 +02:00
|
|
|
|
/* Toggle shm log, if size is not 0. If it is 0, set it to default. */
|
|
|
|
|
shmlog_size = shmlog_size ? -shmlog_size : default_shmlog_size;
|
|
|
|
|
else if (!strcmp(argument, "on"))
|
|
|
|
|
shmlog_size = default_shmlog_size;
|
|
|
|
|
else if (!strcmp(argument, "off"))
|
|
|
|
|
shmlog_size = 0;
|
|
|
|
|
else {
|
|
|
|
|
/* If shm logging now, restart logging with the new size. */
|
|
|
|
|
if (shmlog_size > 0) {
|
|
|
|
|
shmlog_size = 0;
|
|
|
|
|
LOG("Restarting shm logging...\n");
|
|
|
|
|
init_logging();
|
|
|
|
|
}
|
|
|
|
|
shmlog_size = atoi(argument);
|
|
|
|
|
/* Make a weakly attempt at ensuring the argument is valid. */
|
|
|
|
|
if (shmlog_size <= 0)
|
|
|
|
|
shmlog_size = default_shmlog_size;
|
|
|
|
|
}
|
|
|
|
|
LOG("%s shm logging\n", shmlog_size > 0 ? "Enabling" : "Disabling");
|
|
|
|
|
init_logging();
|
|
|
|
|
update_shmlog_atom();
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|
2013-06-05 15:06:53 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implementation of 'debuglog toggle|on|off'
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-09-27 23:42:58 +02:00
|
|
|
|
void cmd_debuglog(I3_CMD, const char *argument) {
|
2013-06-05 15:06:53 +02:00
|
|
|
|
bool logging = get_debug_logging();
|
2014-06-15 19:07:02 +02:00
|
|
|
|
if (!strcmp(argument, "toggle")) {
|
2013-06-05 15:06:53 +02:00
|
|
|
|
LOG("%s debug logging\n", logging ? "Disabling" : "Enabling");
|
|
|
|
|
set_debug_logging(!logging);
|
|
|
|
|
} else if (!strcmp(argument, "on") && !logging) {
|
|
|
|
|
LOG("Enabling debug logging\n");
|
|
|
|
|
set_debug_logging(true);
|
|
|
|
|
} else if (!strcmp(argument, "off") && logging) {
|
|
|
|
|
LOG("Disabling debug logging\n");
|
|
|
|
|
set_debug_logging(false);
|
|
|
|
|
}
|
|
|
|
|
// XXX: default reply for now, make this a better reply
|
|
|
|
|
ysuccess(true);
|
|
|
|
|
}
|