aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/mark.c
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-04-02 14:38:33 -0600
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-04-03 11:48:37 -0600
commit2445d279604d7be38c00db60ffde4279a3c75459 (patch)
tree030844d9fb13be7814dd760a6ffedbec8f5264cd /sway/commands/mark.c
parentUpdate man page (diff)
downloadsway-2445d279604d7be38c00db60ffde4279a3c75459.tar.gz
sway-2445d279604d7be38c00db60ffde4279a3c75459.tar.zst
sway-2445d279604d7be38c00db60ffde4279a3c75459.zip
Impliment i3-style marks
This commit adds three commands to sway: `show_marks`, `mark` and `unmark`. Marks are displayed right-aligned in the window border as i3 does. Marks may be found using criteria. Fixes #1007
Diffstat (limited to 'sway/commands/mark.c')
-rw-r--r--sway/commands/mark.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/sway/commands/mark.c b/sway/commands/mark.c
new file mode 100644
index 00000000..68a84af7
--- /dev/null
+++ b/sway/commands/mark.c
@@ -0,0 +1,74 @@
1#include <string.h>
2#include <strings.h>
3#include <stdbool.h>
4#include "sway/commands.h"
5#include "list.h"
6#include "stringop.h"
7
8struct cmd_results *cmd_mark(int argc, char **argv) {
9 struct cmd_results *error = NULL;
10 if (config->reading) return cmd_results_new(CMD_FAILURE, "mark", "Can't be used in config file.");
11 if ((error = checkarg(argc, "floating", EXPECTED_AT_LEAST, 1))) {
12 return error;
13 }
14
15 swayc_t *view = get_focused_container(&root_container);
16 bool add = false;
17 bool toggle = false;
18
19 if (strcmp(argv[0], "--add") == 0) {
20 --argc; ++argv;
21 add = true;
22 } else if (strcmp(argv[0], "--replace") == 0) {
23 --argc; ++argv;
24 }
25
26 if (argc && strcmp(argv[0], "--toggle") == 0) {
27 --argc; ++argv;
28 toggle = true;
29 }
30
31 if (argc) {
32 char *mark = join_args(argv, argc);
33 if (view->marks) {
34 if (add) {
35 int index;
36 if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
37 if (toggle) {
38 free(view->marks->items[index]);
39 list_del(view->marks, index);
40
41 if (0 == view->marks->length) {
42 list_free(view->marks);
43 view->marks = NULL;
44 }
45 }
46 free(mark);
47 } else {
48 list_add(view->marks, mark);
49 }
50 } else {
51 if (toggle && list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark) != -1) {
52 // Delete the list
53 list_foreach(view->marks, free);
54 list_free(view->marks);
55 view->marks = NULL;
56 } else {
57 // Delete and replace with a new list
58 list_foreach(view->marks, free);
59 list_free(view->marks);
60
61 view->marks = create_list();
62 list_add(view->marks, mark);
63 }
64 }
65 } else {
66 view->marks = create_list();
67 list_add(view->marks, mark);
68 }
69 } else {
70 return cmd_results_new(CMD_FAILURE, "mark",
71 "Expected 'mark [--add|--replace] [--toggle] <mark>'");
72 }
73 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
74}