mirror of
https://github.com/swaywm/sway.git
synced 2026-06-13 14:33:19 -04:00
commands: implement cmd_append_layout
Wires the JSON loader to a config/runtime command. Defers at config-read time so workspaces exist when the layout is applied.
This commit is contained in:
parent
21358c7c0e
commit
cdb955f699
4 changed files with 50 additions and 0 deletions
|
|
@ -105,6 +105,7 @@ sway_cmd cmd_exec_validate;
|
|||
sway_cmd cmd_exec_process;
|
||||
|
||||
sway_cmd cmd_allow_tearing;
|
||||
sway_cmd cmd_append_layout;
|
||||
sway_cmd cmd_assign;
|
||||
sway_cmd cmd_bar;
|
||||
sway_cmd cmd_bindcode;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
|
|||
|
||||
/* Keep alphabetized */
|
||||
static const struct cmd_handler handlers[] = {
|
||||
{ "append_layout", cmd_append_layout },
|
||||
{ "assign", cmd_assign },
|
||||
{ "bar", cmd_bar },
|
||||
{ "bindcode", cmd_bindcode },
|
||||
|
|
|
|||
47
sway/commands/append_layout.c
Normal file
47
sway/commands/append_layout.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/seat.h"
|
||||
#include "sway/tree/load_layout.h"
|
||||
#include "sway/tree/workspace.h"
|
||||
|
||||
struct cmd_results *cmd_append_layout(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "append_layout", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (config->reading || !config->active) {
|
||||
return cmd_results_new(CMD_DEFER, NULL);
|
||||
}
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
||||
if (!ws) {
|
||||
return cmd_results_new(CMD_FAILURE,
|
||||
"append_layout: no focused workspace");
|
||||
}
|
||||
|
||||
char *path = join_args(argv, argc);
|
||||
if (!path) {
|
||||
return cmd_results_new(CMD_FAILURE, "append_layout: out of memory");
|
||||
}
|
||||
if (!expand_path(&path)) {
|
||||
free(path);
|
||||
return cmd_results_new(CMD_FAILURE,
|
||||
"append_layout: failed to expand path");
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
bool ok = load_layout_from_file(ws, path, &err);
|
||||
free(path);
|
||||
if (!ok) {
|
||||
struct cmd_results *res = cmd_results_new(CMD_FAILURE, "%s",
|
||||
err ? err : "append_layout: unknown error");
|
||||
free(err);
|
||||
return res;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
}
|
||||
|
|
@ -43,6 +43,7 @@ sway_sources = files(
|
|||
'config/input.c',
|
||||
|
||||
'commands/allow_tearing.c',
|
||||
'commands/append_layout.c',
|
||||
'commands/assign.c',
|
||||
'commands/bar.c',
|
||||
'commands/bind.c',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue