diff options
author | 2016-03-29 14:47:30 +0200 | |
---|---|---|
committer | 2016-03-30 00:47:58 +0200 | |
commit | 5a13cb0ed136906a4370235214601b0129548c49 (patch) | |
tree | 51dce6cdcb9bb1ffe27dcdc9a01ca9bda3a7c87a /sway/commands.c | |
parent | Add border <none|normal|toggle|pixel> config (diff) | |
download | sway-5a13cb0ed136906a4370235214601b0129548c49.tar.gz sway-5a13cb0ed136906a4370235214601b0129548c49.tar.zst sway-5a13cb0ed136906a4370235214601b0129548c49.zip |
Implement borders
The borders are implemented as a surface/buffer attached to each view
which is sent to and rendered by wlc in the view_pre_render callback.
All the drawing logic is handled in sway/border.c and all the logic for
calculating the geometry of the border/view is handled in
`update_geometry` in sway/layout.c (same place as gaps are calculated).
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/sway/commands.c b/sway/commands.c index bc182cee..c53b13c3 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "ipc-server.h" | 31 | #include "ipc-server.h" |
32 | #include "list.h" | 32 | #include "list.h" |
33 | #include "input.h" | 33 | #include "input.h" |
34 | #include "border.h" | ||
34 | 35 | ||
35 | typedef struct cmd_results *sway_cmd(int argc, char **argv); | 36 | typedef struct cmd_results *sway_cmd(int argc, char **argv); |
36 | 37 | ||
@@ -359,6 +360,14 @@ static struct cmd_results *cmd_border(int argc, char **argv) { | |||
359 | } | 360 | } |
360 | 361 | ||
361 | enum swayc_border_types border = config->border; | 362 | enum swayc_border_types border = config->border; |
363 | int thickness = config->border_thickness; | ||
364 | |||
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 | } | ||
362 | 371 | ||
363 | if (strcasecmp(argv[0], "none") == 0) { | 372 | if (strcasecmp(argv[0], "none") == 0) { |
364 | border = B_NONE; | 373 | border = B_NONE; |
@@ -367,7 +376,7 @@ static struct cmd_results *cmd_border(int argc, char **argv) { | |||
367 | } else if (strcasecmp(argv[0], "pixel") == 0) { | 376 | } else if (strcasecmp(argv[0], "pixel") == 0) { |
368 | border = B_PIXEL; | 377 | border = B_PIXEL; |
369 | } else if (strcasecmp(argv[0], "toggle") == 0) { | 378 | } else if (strcasecmp(argv[0], "toggle") == 0) { |
370 | switch (config->border) { | 379 | switch (border) { |
371 | case B_NONE: | 380 | case B_NONE: |
372 | border = B_PIXEL; | 381 | border = B_PIXEL; |
373 | break; | 382 | break; |
@@ -383,16 +392,24 @@ static struct cmd_results *cmd_border(int argc, char **argv) { | |||
383 | "Expected 'border <normal|pixel|none|toggle>"); | 392 | "Expected 'border <normal|pixel|none|toggle>"); |
384 | } | 393 | } |
385 | 394 | ||
395 | |||
386 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | 396 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { |
387 | int thickness = (int)strtol(argv[1], NULL, 10); | 397 | thickness = (int)strtol(argv[1], NULL, 10); |
388 | if (errno == ERANGE || thickness < 0) { | 398 | if (errno == ERANGE || thickness < 0) { |
389 | errno = 0; | 399 | errno = 0; |
390 | return cmd_results_new(CMD_INVALID, "border", "Number is out out of range."); | 400 | return cmd_results_new(CMD_INVALID, "border", "Number is out out of range."); |
391 | } | 401 | } |
402 | } | ||
403 | |||
404 | if (config->active && view) { | ||
405 | view->border_type = border; | ||
406 | view->border_thickness = thickness; | ||
407 | update_geometry(view); | ||
408 | } else { | ||
409 | config->border = border; | ||
392 | config->border_thickness = thickness; | 410 | config->border_thickness = thickness; |
393 | } | 411 | } |
394 | 412 | ||
395 | config->border = border; | ||
396 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 413 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
397 | } | 414 | } |
398 | 415 | ||
@@ -904,9 +921,9 @@ static struct cmd_results *cmd_move(int argc, char **argv) { | |||
904 | } else if (strcasecmp(argv[0], "position") == 0 && strcasecmp(argv[1], "mouse") == 0) { | 921 | } else if (strcasecmp(argv[0], "position") == 0 && strcasecmp(argv[1], "mouse") == 0) { |
905 | if (view->is_floating) { | 922 | if (view->is_floating) { |
906 | swayc_t *output = swayc_parent_by_type(view, C_OUTPUT); | 923 | swayc_t *output = swayc_parent_by_type(view, C_OUTPUT); |
907 | const struct wlc_geometry *geometry = wlc_view_get_geometry(view->handle); | 924 | struct wlc_geometry g; |
925 | wlc_view_get_visible_geometry(view->handle, &g); | ||
908 | const struct wlc_size *size = wlc_output_get_resolution(output->handle); | 926 | const struct wlc_size *size = wlc_output_get_resolution(output->handle); |
909 | struct wlc_geometry g = *geometry; | ||
910 | 927 | ||
911 | struct wlc_point origin; | 928 | struct wlc_point origin; |
912 | wlc_pointer_get_position(&origin); | 929 | wlc_pointer_get_position(&origin); |
@@ -1954,6 +1971,8 @@ static struct cmd_results *cmd_font(int argc, char **argv) { | |||
1954 | config->font = font; | 1971 | config->font = font; |
1955 | } | 1972 | } |
1956 | 1973 | ||
1974 | config->font_height = get_font_text_height(config->font); | ||
1975 | |||
1957 | sway_log(L_DEBUG, "Settings font %s", config->font); | 1976 | sway_log(L_DEBUG, "Settings font %s", config->font); |
1958 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 1977 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
1959 | } | 1978 | } |