diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 107 |
1 files changed, 91 insertions, 16 deletions
diff --git a/sway/commands.c b/sway/commands.c index 381c0133..3cc84062 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -66,6 +66,8 @@ static sway_cmd cmd_log_colors; | |||
66 | static sway_cmd cmd_mode; | 66 | static sway_cmd cmd_mode; |
67 | static sway_cmd cmd_mouse_warping; | 67 | static sway_cmd cmd_mouse_warping; |
68 | static sway_cmd cmd_move; | 68 | static sway_cmd cmd_move; |
69 | static sway_cmd cmd_new_float; | ||
70 | static sway_cmd cmd_new_window; | ||
69 | static sway_cmd cmd_orientation; | 71 | static sway_cmd cmd_orientation; |
70 | static sway_cmd cmd_output; | 72 | static sway_cmd cmd_output; |
71 | static sway_cmd cmd_reload; | 73 | static sway_cmd cmd_reload; |
@@ -350,24 +352,21 @@ static struct cmd_results *cmd_bindcode(int argc, char **argv) { | |||
350 | 352 | ||
351 | static struct cmd_results *cmd_border(int argc, char **argv) { | 353 | static struct cmd_results *cmd_border(int argc, char **argv) { |
352 | struct cmd_results *error = NULL; | 354 | struct cmd_results *error = NULL; |
355 | if (!config->active) { | ||
356 | return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running."); | ||
357 | } | ||
353 | if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) { | 358 | if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) { |
354 | return error; | 359 | return error; |
355 | } | 360 | } |
356 | 361 | ||
357 | if (argc > 2) { | 362 | if (argc > 2) { |
358 | return cmd_results_new(CMD_FAILURE, "border", | 363 | return cmd_results_new(CMD_INVALID, "border", |
359 | "Expected 'border <normal|pixel|none|toggle> [<n>]"); | 364 | "Expected 'border <normal|pixel|none|toggle> [<n>]"); |
360 | } | 365 | } |
361 | 366 | ||
362 | enum swayc_border_types border = config->border; | 367 | swayc_t *view = get_focused_view(&root_container); |
363 | int thickness = config->border_thickness; | 368 | enum swayc_border_types border = view->border_type; |
364 | 369 | int thickness = view->border_thickness; | |
365 | swayc_t *view = NULL; | ||
366 | if (config->active) { | ||
367 | view = get_focused_view(&root_container); | ||
368 | border = view->border_type; | ||
369 | thickness = view->border_thickness; | ||
370 | } | ||
371 | 370 | ||
372 | if (strcasecmp(argv[0], "none") == 0) { | 371 | if (strcasecmp(argv[0], "none") == 0) { |
373 | border = B_NONE; | 372 | border = B_NONE; |
@@ -388,11 +387,10 @@ static struct cmd_results *cmd_border(int argc, char **argv) { | |||
388 | break; | 387 | break; |
389 | } | 388 | } |
390 | } else { | 389 | } else { |
391 | return cmd_results_new(CMD_FAILURE, "border", | 390 | return cmd_results_new(CMD_INVALID, "border", |
392 | "Expected 'border <normal|pixel|none|toggle>"); | 391 | "Expected 'border <normal|pixel|none|toggle>"); |
393 | } | 392 | } |
394 | 393 | ||
395 | |||
396 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | 394 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { |
397 | thickness = (int)strtol(argv[1], NULL, 10); | 395 | thickness = (int)strtol(argv[1], NULL, 10); |
398 | if (errno == ERANGE || thickness < 0) { | 396 | if (errno == ERANGE || thickness < 0) { |
@@ -401,13 +399,10 @@ static struct cmd_results *cmd_border(int argc, char **argv) { | |||
401 | } | 399 | } |
402 | } | 400 | } |
403 | 401 | ||
404 | if (config->active && view) { | 402 | if (view) { |
405 | view->border_type = border; | 403 | view->border_type = border; |
406 | view->border_thickness = thickness; | 404 | view->border_thickness = thickness; |
407 | update_geometry(view); | 405 | update_geometry(view); |
408 | } else { | ||
409 | config->border = border; | ||
410 | config->border_thickness = thickness; | ||
411 | } | 406 | } |
412 | 407 | ||
413 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 408 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
@@ -939,6 +934,84 @@ static struct cmd_results *cmd_move(int argc, char **argv) { | |||
939 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 934 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
940 | } | 935 | } |
941 | 936 | ||
937 | static struct cmd_results *cmd_new_float(int argc, char **argv) { | ||
938 | struct cmd_results *error = NULL; | ||
939 | if ((error = checkarg(argc, "new_float", EXPECTED_AT_LEAST, 1))) { | ||
940 | return error; | ||
941 | } | ||
942 | |||
943 | if (argc > 2) { | ||
944 | return cmd_results_new(CMD_INVALID, "new_float", | ||
945 | "Expected 'new_float <normal|none|pixel> [<n>]"); | ||
946 | } | ||
947 | |||
948 | enum swayc_border_types border = config->floating_border; | ||
949 | int thickness = config->floating_border_thickness; | ||
950 | |||
951 | if (strcasecmp(argv[0], "none") == 0) { | ||
952 | border = B_NONE; | ||
953 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
954 | border = B_NORMAL; | ||
955 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
956 | border = B_PIXEL; | ||
957 | } else { | ||
958 | return cmd_results_new(CMD_INVALID, "new_float", | ||
959 | "Expected 'border <normal|none|pixel>"); | ||
960 | } | ||
961 | |||
962 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
963 | thickness = (int)strtol(argv[1], NULL, 10); | ||
964 | if (errno == ERANGE || thickness < 0) { | ||
965 | errno = 0; | ||
966 | return cmd_results_new(CMD_INVALID, "new_float", "Number is out out of range."); | ||
967 | } | ||
968 | } | ||
969 | |||
970 | config->floating_border = border; | ||
971 | config->floating_border_thickness = thickness; | ||
972 | |||
973 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
974 | } | ||
975 | |||
976 | static struct cmd_results *cmd_new_window(int argc, char **argv) { | ||
977 | struct cmd_results *error = NULL; | ||
978 | if ((error = checkarg(argc, "new_window", EXPECTED_AT_LEAST, 1))) { | ||
979 | return error; | ||
980 | } | ||
981 | |||
982 | if (argc > 2) { | ||
983 | return cmd_results_new(CMD_INVALID, "new_window", | ||
984 | "Expected 'new_window <normal|none|pixel> [<n>]"); | ||
985 | } | ||
986 | |||
987 | enum swayc_border_types border = config->border; | ||
988 | int thickness = config->border_thickness; | ||
989 | |||
990 | if (strcasecmp(argv[0], "none") == 0) { | ||
991 | border = B_NONE; | ||
992 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
993 | border = B_NORMAL; | ||
994 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
995 | border = B_PIXEL; | ||
996 | } else { | ||
997 | return cmd_results_new(CMD_INVALID, "new_window", | ||
998 | "Expected 'border <normal|none|pixel>"); | ||
999 | } | ||
1000 | |||
1001 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
1002 | thickness = (int)strtol(argv[1], NULL, 10); | ||
1003 | if (errno == ERANGE || thickness < 0) { | ||
1004 | errno = 0; | ||
1005 | return cmd_results_new(CMD_INVALID, "new_window", "Number is out out of range."); | ||
1006 | } | ||
1007 | } | ||
1008 | |||
1009 | config->border = border; | ||
1010 | config->border_thickness = thickness; | ||
1011 | |||
1012 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1013 | } | ||
1014 | |||
942 | static struct cmd_results *cmd_orientation(int argc, char **argv) { | 1015 | static struct cmd_results *cmd_orientation(int argc, char **argv) { |
943 | struct cmd_results *error = NULL; | 1016 | struct cmd_results *error = NULL; |
944 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "orientation", "Can only be used in config file."); | 1017 | 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[] = { | |||
2160 | { "mode", cmd_mode }, | 2233 | { "mode", cmd_mode }, |
2161 | { "mouse_warping", cmd_mouse_warping }, | 2234 | { "mouse_warping", cmd_mouse_warping }, |
2162 | { "move", cmd_move }, | 2235 | { "move", cmd_move }, |
2236 | { "new_float", cmd_new_float }, | ||
2237 | { "new_window", cmd_new_window }, | ||
2163 | { "output", cmd_output }, | 2238 | { "output", cmd_output }, |
2164 | { "reload", cmd_reload }, | 2239 | { "reload", cmd_reload }, |
2165 | { "resize", cmd_resize }, | 2240 | { "resize", cmd_resize }, |