Merge pull request #560 from mikkeloscar/add-new_window-new_float

Add cmds new_window and new_float
This commit is contained in:
Drew DeVault 2016-03-31 07:43:05 -04:00
commit f0b33df384
5 changed files with 114 additions and 24 deletions

View file

@ -213,7 +213,9 @@ struct sway_config {
const char *current_config;
enum swayc_border_types border;
enum swayc_border_types floating_border;
int border_thickness;
int floating_border_thickness;
enum edge_border_types hide_edge_borders;
// border colors

View file

@ -66,6 +66,8 @@ static sway_cmd cmd_log_colors;
static sway_cmd cmd_mode;
static sway_cmd cmd_mouse_warping;
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_output;
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) {
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))) {
return error;
}
if (argc > 2) {
return cmd_results_new(CMD_FAILURE, "border",
return cmd_results_new(CMD_INVALID, "border",
"Expected 'border <normal|pixel|none|toggle> [<n>]");
}
enum swayc_border_types border = config->border;
int thickness = config->border_thickness;
swayc_t *view = NULL;
if (config->active) {
view = get_focused_view(&root_container);
border = view->border_type;
thickness = view->border_thickness;
}
swayc_t *view = get_focused_view(&root_container);
enum swayc_border_types border = view->border_type;
int thickness = view->border_thickness;
if (strcasecmp(argv[0], "none") == 0) {
border = B_NONE;
@ -388,11 +387,10 @@ static struct cmd_results *cmd_border(int argc, char **argv) {
break;
}
} else {
return cmd_results_new(CMD_FAILURE, "border",
return cmd_results_new(CMD_INVALID, "border",
"Expected 'border <normal|pixel|none|toggle>");
}
if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
thickness = (int)strtol(argv[1], NULL, 10);
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_thickness = thickness;
update_geometry(view);
} else {
config->border = border;
config->border_thickness = thickness;
}
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);
}
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) {
struct cmd_results *error = NULL;
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 },
{ "mouse_warping", cmd_mouse_warping },
{ "move", cmd_move },
{ "new_float", cmd_new_float },
{ "new_window", cmd_new_window },
{ "output", cmd_output },
{ "reload", cmd_reload },
{ "resize", cmd_resize },

View file

@ -187,7 +187,9 @@ static void config_defaults(struct sway_config *config) {
// borders
config->border = B_NORMAL;
config->floating_border = B_NORMAL;
config->border_thickness = 2;
config->floating_border_thickness = 2;
config->hide_edge_borders = E_NONE;
// border colors

View file

@ -22,11 +22,8 @@ static swayc_t *new_swayc(enum swayc_types type) {
c->gaps = -1;
c->layout = L_NONE;
c->type = type;
c->border_type = config->border;
c->border_thickness = config->border_thickness;
if (type != C_VIEW) {
c->children = create_list();
c->border_type = B_NONE;
}
return c;
}
@ -275,6 +272,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
view->height = 0;
view->desired_width = geometry.size.w;
view->desired_height = geometry.size.h;
// setup border
view->border_type = config->border;
view->border_thickness = config->border_thickness;
view->is_floating = false;
@ -319,6 +319,10 @@ swayc_t *new_floating_view(wlc_handle handle) {
view->desired_width = view->width;
view->desired_height = view->height;
// setup border
view->border_type = config->floating_border;
view->border_thickness = config->floating_border_thickness;
view->is_floating = true;
// Case of focused workspace, just create as child of it

View file

@ -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).
**border** <normal|pixel> [<n>]::
Set border style for windows. _normal_ includes a border of thickness _n_ and
a title bar. _pixel_ is just the border without title bar. Default is _normal_
with border thickness 2.
Set border style for focused window. _normal_ includes a border of thickness
_n_ and a title bar. _pixel_ is just the border without title bar. Default is
_normal_ with border thickness 2.
**border** <none|toggle>::
Set border style to _none_ or _toggle_ between the available border styles:
_normal_, _pixel_, _none_.
Set border style for focused window to _none_ or _toggle_ between the
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 sway and end your Wayland session.