mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
Add cmds new_window and new_float
Makes it possible to set default layout style for new windows and new floating windows. Close #556
This commit is contained in:
parent
6db92bbb99
commit
7be476c115
5 changed files with 114 additions and 24 deletions
|
@ -213,7 +213,9 @@ struct sway_config {
|
||||||
const char *current_config;
|
const char *current_config;
|
||||||
|
|
||||||
enum swayc_border_types border;
|
enum swayc_border_types border;
|
||||||
|
enum swayc_border_types floating_border;
|
||||||
int border_thickness;
|
int border_thickness;
|
||||||
|
int floating_border_thickness;
|
||||||
enum edge_border_types hide_edge_borders;
|
enum edge_border_types hide_edge_borders;
|
||||||
|
|
||||||
// border colors
|
// border colors
|
||||||
|
|
107
sway/commands.c
107
sway/commands.c
|
@ -66,6 +66,8 @@ static sway_cmd cmd_log_colors;
|
||||||
static sway_cmd cmd_mode;
|
static sway_cmd cmd_mode;
|
||||||
static sway_cmd cmd_mouse_warping;
|
static sway_cmd cmd_mouse_warping;
|
||||||
static sway_cmd cmd_move;
|
static sway_cmd cmd_move;
|
||||||
|
static sway_cmd cmd_new_float;
|
||||||
|
static sway_cmd cmd_new_window;
|
||||||
static sway_cmd cmd_orientation;
|
static sway_cmd cmd_orientation;
|
||||||
static sway_cmd cmd_output;
|
static sway_cmd cmd_output;
|
||||||
static sway_cmd cmd_reload;
|
static sway_cmd cmd_reload;
|
||||||
|
@ -350,24 +352,21 @@ static struct cmd_results *cmd_bindcode(int argc, char **argv) {
|
||||||
|
|
||||||
static struct cmd_results *cmd_border(int argc, char **argv) {
|
static struct cmd_results *cmd_border(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
if (!config->active) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running.");
|
||||||
|
}
|
||||||
if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
|
if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
return cmd_results_new(CMD_FAILURE, "border",
|
return cmd_results_new(CMD_INVALID, "border",
|
||||||
"Expected 'border <normal|pixel|none|toggle> [<n>]");
|
"Expected 'border <normal|pixel|none|toggle> [<n>]");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum swayc_border_types border = config->border;
|
swayc_t *view = get_focused_view(&root_container);
|
||||||
int thickness = config->border_thickness;
|
enum swayc_border_types border = view->border_type;
|
||||||
|
int thickness = view->border_thickness;
|
||||||
swayc_t *view = NULL;
|
|
||||||
if (config->active) {
|
|
||||||
view = get_focused_view(&root_container);
|
|
||||||
border = view->border_type;
|
|
||||||
thickness = view->border_thickness;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcasecmp(argv[0], "none") == 0) {
|
if (strcasecmp(argv[0], "none") == 0) {
|
||||||
border = B_NONE;
|
border = B_NONE;
|
||||||
|
@ -388,11 +387,10 @@ static struct cmd_results *cmd_border(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return cmd_results_new(CMD_FAILURE, "border",
|
return cmd_results_new(CMD_INVALID, "border",
|
||||||
"Expected 'border <normal|pixel|none|toggle>");
|
"Expected 'border <normal|pixel|none|toggle>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
|
if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
|
||||||
thickness = (int)strtol(argv[1], NULL, 10);
|
thickness = (int)strtol(argv[1], NULL, 10);
|
||||||
if (errno == ERANGE || thickness < 0) {
|
if (errno == ERANGE || thickness < 0) {
|
||||||
|
@ -401,13 +399,10 @@ static struct cmd_results *cmd_border(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->active && view) {
|
if (view) {
|
||||||
view->border_type = border;
|
view->border_type = border;
|
||||||
view->border_thickness = thickness;
|
view->border_thickness = thickness;
|
||||||
update_geometry(view);
|
update_geometry(view);
|
||||||
} else {
|
|
||||||
config->border = border;
|
|
||||||
config->border_thickness = thickness;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
@ -939,6 +934,84 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct cmd_results *cmd_new_float(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if ((error = checkarg(argc, "new_float", EXPECTED_AT_LEAST, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 2) {
|
||||||
|
return cmd_results_new(CMD_INVALID, "new_float",
|
||||||
|
"Expected 'new_float <normal|none|pixel> [<n>]");
|
||||||
|
}
|
||||||
|
|
||||||
|
enum swayc_border_types border = config->floating_border;
|
||||||
|
int thickness = config->floating_border_thickness;
|
||||||
|
|
||||||
|
if (strcasecmp(argv[0], "none") == 0) {
|
||||||
|
border = B_NONE;
|
||||||
|
} else if (strcasecmp(argv[0], "normal") == 0) {
|
||||||
|
border = B_NORMAL;
|
||||||
|
} else if (strcasecmp(argv[0], "pixel") == 0) {
|
||||||
|
border = B_PIXEL;
|
||||||
|
} else {
|
||||||
|
return cmd_results_new(CMD_INVALID, "new_float",
|
||||||
|
"Expected 'border <normal|none|pixel>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
|
||||||
|
thickness = (int)strtol(argv[1], NULL, 10);
|
||||||
|
if (errno == ERANGE || thickness < 0) {
|
||||||
|
errno = 0;
|
||||||
|
return cmd_results_new(CMD_INVALID, "new_float", "Number is out out of range.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config->floating_border = border;
|
||||||
|
config->floating_border_thickness = thickness;
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct cmd_results *cmd_new_window(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if ((error = checkarg(argc, "new_window", EXPECTED_AT_LEAST, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 2) {
|
||||||
|
return cmd_results_new(CMD_INVALID, "new_window",
|
||||||
|
"Expected 'new_window <normal|none|pixel> [<n>]");
|
||||||
|
}
|
||||||
|
|
||||||
|
enum swayc_border_types border = config->border;
|
||||||
|
int thickness = config->border_thickness;
|
||||||
|
|
||||||
|
if (strcasecmp(argv[0], "none") == 0) {
|
||||||
|
border = B_NONE;
|
||||||
|
} else if (strcasecmp(argv[0], "normal") == 0) {
|
||||||
|
border = B_NORMAL;
|
||||||
|
} else if (strcasecmp(argv[0], "pixel") == 0) {
|
||||||
|
border = B_PIXEL;
|
||||||
|
} else {
|
||||||
|
return cmd_results_new(CMD_INVALID, "new_window",
|
||||||
|
"Expected 'border <normal|none|pixel>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
|
||||||
|
thickness = (int)strtol(argv[1], NULL, 10);
|
||||||
|
if (errno == ERANGE || thickness < 0) {
|
||||||
|
errno = 0;
|
||||||
|
return cmd_results_new(CMD_INVALID, "new_window", "Number is out out of range.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config->border = border;
|
||||||
|
config->border_thickness = thickness;
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static struct cmd_results *cmd_orientation(int argc, char **argv) {
|
static struct cmd_results *cmd_orientation(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if (!config->reading) return cmd_results_new(CMD_FAILURE, "orientation", "Can only be used in config file.");
|
if (!config->reading) return cmd_results_new(CMD_FAILURE, "orientation", "Can only be used in config file.");
|
||||||
|
@ -2160,6 +2233,8 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "mode", cmd_mode },
|
{ "mode", cmd_mode },
|
||||||
{ "mouse_warping", cmd_mouse_warping },
|
{ "mouse_warping", cmd_mouse_warping },
|
||||||
{ "move", cmd_move },
|
{ "move", cmd_move },
|
||||||
|
{ "new_float", cmd_new_float },
|
||||||
|
{ "new_window", cmd_new_window },
|
||||||
{ "output", cmd_output },
|
{ "output", cmd_output },
|
||||||
{ "reload", cmd_reload },
|
{ "reload", cmd_reload },
|
||||||
{ "resize", cmd_resize },
|
{ "resize", cmd_resize },
|
||||||
|
|
|
@ -187,7 +187,9 @@ static void config_defaults(struct sway_config *config) {
|
||||||
|
|
||||||
// borders
|
// borders
|
||||||
config->border = B_NORMAL;
|
config->border = B_NORMAL;
|
||||||
|
config->floating_border = B_NORMAL;
|
||||||
config->border_thickness = 2;
|
config->border_thickness = 2;
|
||||||
|
config->floating_border_thickness = 2;
|
||||||
config->hide_edge_borders = E_NONE;
|
config->hide_edge_borders = E_NONE;
|
||||||
|
|
||||||
// border colors
|
// border colors
|
||||||
|
|
|
@ -22,11 +22,8 @@ static swayc_t *new_swayc(enum swayc_types type) {
|
||||||
c->gaps = -1;
|
c->gaps = -1;
|
||||||
c->layout = L_NONE;
|
c->layout = L_NONE;
|
||||||
c->type = type;
|
c->type = type;
|
||||||
c->border_type = config->border;
|
|
||||||
c->border_thickness = config->border_thickness;
|
|
||||||
if (type != C_VIEW) {
|
if (type != C_VIEW) {
|
||||||
c->children = create_list();
|
c->children = create_list();
|
||||||
c->border_type = B_NONE;
|
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -275,6 +272,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
||||||
view->height = 0;
|
view->height = 0;
|
||||||
view->desired_width = geometry.size.w;
|
view->desired_width = geometry.size.w;
|
||||||
view->desired_height = geometry.size.h;
|
view->desired_height = geometry.size.h;
|
||||||
|
// setup border
|
||||||
|
view->border_type = config->border;
|
||||||
|
view->border_thickness = config->border_thickness;
|
||||||
|
|
||||||
view->is_floating = false;
|
view->is_floating = false;
|
||||||
|
|
||||||
|
@ -319,6 +319,10 @@ swayc_t *new_floating_view(wlc_handle handle) {
|
||||||
view->desired_width = view->width;
|
view->desired_width = view->width;
|
||||||
view->desired_height = view->height;
|
view->desired_height = view->height;
|
||||||
|
|
||||||
|
// setup border
|
||||||
|
view->border_type = config->floating_border;
|
||||||
|
view->border_thickness = config->floating_border_thickness;
|
||||||
|
|
||||||
view->is_floating = true;
|
view->is_floating = true;
|
||||||
|
|
||||||
// Case of focused workspace, just create as child of it
|
// Case of focused workspace, just create as child of it
|
||||||
|
|
|
@ -44,13 +44,20 @@ The following commands cannot be used directly in the configuration file.
|
||||||
They are expected to be used with **bindsym** or at runtime through **swaymsg**(1).
|
They are expected to be used with **bindsym** or at runtime through **swaymsg**(1).
|
||||||
|
|
||||||
**border** <normal|pixel> [<n>]::
|
**border** <normal|pixel> [<n>]::
|
||||||
Set border style for windows. _normal_ includes a border of thickness _n_ and
|
Set border style for focused window. _normal_ includes a border of thickness
|
||||||
a title bar. _pixel_ is just the border without title bar. Default is _normal_
|
_n_ and a title bar. _pixel_ is just the border without title bar. Default is
|
||||||
with border thickness 2.
|
_normal_ with border thickness 2.
|
||||||
|
|
||||||
**border** <none|toggle>::
|
**border** <none|toggle>::
|
||||||
Set border style to _none_ or _toggle_ between the available border styles:
|
Set border style for focused window to _none_ or _toggle_ between the
|
||||||
_normal_, _pixel_, _none_.
|
available border styles: _normal_, _pixel_, _none_.
|
||||||
|
|
||||||
|
**new_window** <normal|none|pixel> [<n>]::
|
||||||
|
Set default border style for new windows.
|
||||||
|
|
||||||
|
**new_float** <normal|none|pixel> [<n>]::
|
||||||
|
Set default border style for new floating windows. This does only apply to
|
||||||
|
windows that are spawned in floating mode.
|
||||||
|
|
||||||
**exit**::
|
**exit**::
|
||||||
Exit sway and end your Wayland session.
|
Exit sway and end your Wayland session.
|
||||||
|
|
Loading…
Reference in a new issue