aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/border.c23
-rw-r--r--sway/commands.c82
-rw-r--r--sway/commands/border.c2
-rw-r--r--sway/commands/floating.c2
-rw-r--r--sway/commands/focus.c3
-rw-r--r--sway/commands/fullscreen.c2
-rw-r--r--sway/commands/kill.c2
-rw-r--r--sway/commands/layout.c2
-rw-r--r--sway/commands/mark.c87
-rw-r--r--sway/commands/move.c4
-rw-r--r--sway/commands/resize.c12
-rw-r--r--sway/commands/show_marks.c13
-rw-r--r--sway/commands/split.c6
-rw-r--r--sway/commands/unmark.c31
-rw-r--r--sway/config.c1
-rw-r--r--sway/container.c4
-rw-r--r--sway/criteria.c89
-rw-r--r--sway/ipc-server.c30
-rw-r--r--sway/main.c2
-rw-r--r--sway/sway.1.txt4
-rw-r--r--sway/sway.5.txt34
21 files changed, 351 insertions, 84 deletions
diff --git a/sway/border.c b/sway/border.c
index d79029a9..10ad92c2 100644
--- a/sway/border.c
+++ b/sway/border.c
@@ -1,8 +1,11 @@
+#define _XOPEN_SOURCE 500
#include <wlc/wlc-render.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <strings.h>
#include <arpa/inet.h>
#include "sway/border.h"
#include "sway/container.h"
@@ -190,6 +193,26 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b,
cairo_set_source_u32(cr, colors->text);
pango_printf(cr, config->font, 1, false, "%s", view->name);
}
+ // Marks
+ if (config->show_marks && view->marks) {
+ int total_len = 0;
+
+ for(int i = view->marks->length - 1; i >= 0; --i) {
+ char *mark = (char *)view->marks->items[i];
+ if (*mark != '_') {
+ int width, height;
+ get_text_size(cr, config->font, &width, &height, 1, false, "[%s]", mark);
+ total_len += width;
+ if ((int)tb->size.w + x - (total_len + 2) < x + 2) {
+ break;
+ } else {
+ cairo_move_to(cr, (int)tb->size.w + x - (total_len + 2), y + 2);
+ cairo_set_source_u32(cr, colors->text);
+ pango_printf(cr, config->font, 1, false, "[%s]", mark);
+ }
+ }
+ }
+ }
// titlebars has a border all around for tabbed layouts
if (view->parent->layout == L_TABBED) {
diff --git a/sway/commands.c b/sway/commands.c
index c330ebee..17c7d717 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -43,6 +43,8 @@ struct cmd_handler {
int sp_index = 0;
+swayc_t *current_container = NULL;
+
// Returns error object, or NULL if check succeeds.
struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) {
struct cmd_results *error = NULL;
@@ -190,6 +192,7 @@ static struct cmd_handler handlers[] = {
{ "kill", cmd_kill },
{ "layout", cmd_layout },
{ "log_colors", cmd_log_colors },
+ { "mark", cmd_mark },
{ "mode", cmd_mode },
{ "mouse_warping", cmd_mouse_warping },
{ "move", cmd_move },
@@ -203,12 +206,14 @@ static struct cmd_handler handlers[] = {
{ "scratchpad", cmd_scratchpad },
{ "seamless_mouse", cmd_seamless_mouse },
{ "set", cmd_set },
+ { "show_marks", cmd_show_marks },
{ "smart_gaps", cmd_smart_gaps },
{ "split", cmd_split },
{ "splith", cmd_splith },
{ "splitt", cmd_splitt },
{ "splitv", cmd_splitv },
{ "sticky", cmd_sticky },
+ { "unmark", cmd_unmark },
{ "workspace", cmd_workspace },
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
{ "workspace_layout", cmd_workspace_layout },
@@ -368,42 +373,37 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
char *head = exec;
char *cmdlist;
char *cmd;
- char *criteria __attribute__((unused));
+ list_t *containers = NULL;
head = exec;
do {
// Extract criteria (valid for this command list only).
- criteria = NULL;
if (*head == '[') {
++head;
- criteria = argsep(&head, "]");
+ char *criteria_string = argsep(&head, "]");
if (head) {
++head;
- // TODO handle criteria
+ list_t *tokens = create_list();
+ char *error;
+
+ if ((error = extract_crit_tokens(tokens, criteria_string))) {
+ results = cmd_results_new(CMD_INVALID, criteria_string,
+ "Can't parse criteria string: %s", error);
+ free(error);
+ free(tokens);
+ goto cleanup;
+ }
+ containers = container_for(tokens);
+
+ free(tokens);
} else {
if (!results) {
- results = cmd_results_new(CMD_INVALID, criteria, "Unmatched [");
+ results = cmd_results_new(CMD_INVALID, criteria_string, "Unmatched [");
}
goto cleanup;
}
// Skip leading whitespace
head += strspn(head, whitespace);
-
- // TODO: it will yield unexpected results to execute commands
- // (on any view) that where meant for certain views only.
- if (!results) {
- int len = strlen(criteria) + strlen(head) + 4;
- char *tmp = malloc(len);
- if (tmp) {
- snprintf(tmp, len, "[%s] %s", criteria, head);
- } else {
- sway_log(L_DEBUG, "Unable to allocate criteria string for cmd result");
- }
- results = cmd_results_new(CMD_INVALID, tmp,
- "Can't handle criteria string: Refusing to execute command");
- free(tmp);
- }
- goto cleanup;
}
// Split command list
cmdlist = argsep(&head, ";");
@@ -447,21 +447,43 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
free_argv(argc, argv);
goto cleanup;
}
- struct cmd_results *res = handler->handle(argc-1, argv+1);
- if (res->status != CMD_SUCCESS) {
- free_argv(argc, argv);
- if (results) {
- free_cmd_results(results);
+ int i = 0;
+ do {
+ if (!containers) {
+ current_container = get_focused_container(&root_container);
+ } else if (containers->length == 0) {
+ break;
+ } else {
+ current_container = (swayc_t *)containers->items[i];
}
- results = res;
- goto cleanup;
- }
+ sway_log(L_INFO, "Running on container '%s'", current_container->name);
+
+ struct cmd_results *res = handler->handle(argc-1, argv+1);
+ if (res->status != CMD_SUCCESS) {
+ free_argv(argc, argv);
+ if (results) {
+ free_cmd_results(results);
+ }
+ results = res;
+ goto cleanup;
+ }
+ free_cmd_results(res);
+ ++i;
+ } while(containers && i < containers->length);
+
free_argv(argc, argv);
- free_cmd_results(res);
} while(cmdlist);
+
+ if (containers) {
+ list_free(containers);
+ containers = NULL;
+ }
} while(head);
cleanup:
free(exec);
+ if (containers) {
+ free(containers);
+ }
if (!results) {
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/border.c b/sway/commands/border.c
index 0211e40c..c888622e 100644
--- a/sway/commands/border.c
+++ b/sway/commands/border.c
@@ -20,7 +20,7 @@ struct cmd_results *cmd_border(int argc, char **argv) {
"Expected 'border <normal|pixel|none|toggle> [<n>]");
}
- swayc_t *view = get_focused_view(&root_container);
+ swayc_t *view = current_container;
enum swayc_border_types border = view->border_type;
int thickness = view->border_thickness;
diff --git a/sway/commands/floating.c b/sway/commands/floating.c
index 113c8b71..ccfde532 100644
--- a/sway/commands/floating.c
+++ b/sway/commands/floating.c
@@ -13,7 +13,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) {
return error;
}
- swayc_t *view = get_focused_container(&root_container);
+ swayc_t *view = current_container;
bool wants_floating;
if (strcasecmp(argv[0], "enable") == 0) {
wants_floating = true;
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 12c5d02c..defaba29 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -30,6 +30,9 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
}
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ } else if (argc == 0) {
+ set_focused_container(current_container);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
return error;
}
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c
index 321d6f59..bfff82f9 100644
--- a/sway/commands/fullscreen.c
+++ b/sway/commands/fullscreen.c
@@ -14,7 +14,7 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0))) {
return error;
}
- swayc_t *container = get_focused_view(&root_container);
+ swayc_t *container = current_container;
if(container->type != C_VIEW){
return cmd_results_new(CMD_INVALID, "fullscreen", "Only views can fullscreen");
}
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index 2e94fb10..742e2b86 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -6,7 +6,7 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file.");
if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running.");
- swayc_t *container = get_focused_container(&root_container);
+ swayc_t *container = current_container;
close_views(container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
index 570cd207..40ebd590 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -16,7 +16,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) {
return error;
}
- swayc_t *parent = get_focused_container(&root_container);
+ swayc_t *parent = current_container;
if (parent->is_floating) {
return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows");
}
diff --git a/sway/commands/mark.c b/sway/commands/mark.c
new file mode 100644
index 00000000..c1d959df
--- /dev/null
+++ b/sway/commands/mark.c
@@ -0,0 +1,87 @@
+#include <string.h>
+#include <strings.h>
+#include <stdbool.h>
+#include "sway/commands.h"
+#include "list.h"
+#include "stringop.h"
+
+static void find_marks_callback(swayc_t *container, void *_mark) {
+ char *mark = (char *)_mark;
+
+ int index;
+ if (container->marks && ((index = list_seq_find(container->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1)) {
+ list_del(container->marks, index);
+ }
+}
+
+struct cmd_results *cmd_mark(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if (config->reading) return cmd_results_new(CMD_FAILURE, "mark", "Can't be used in config file.");
+ if ((error = checkarg(argc, "mark", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ swayc_t *view = current_container;
+ bool add = false;
+ bool toggle = false;
+
+ if (strcmp(argv[0], "--add") == 0) {
+ --argc; ++argv;
+ add = true;
+ } else if (strcmp(argv[0], "--replace") == 0) {
+ --argc; ++argv;
+ }
+
+ if (argc && strcmp(argv[0], "--toggle") == 0) {
+ --argc; ++argv;
+ toggle = true;
+ }
+
+ if (argc) {
+ char *mark = join_args(argv, argc);
+
+ // Remove all existing marks of this type
+ container_map(&root_container, find_marks_callback, mark);
+
+ if (view->marks) {
+ if (add) {
+ int index;
+ if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
+ if (toggle) {
+ free(view->marks->items[index]);
+ list_del(view->marks, index);
+
+ if (0 == view->marks->length) {
+ list_free(view->marks);
+ view->marks = NULL;
+ }
+ }
+ free(mark);
+ } else {
+ list_add(view->marks, mark);
+ }
+ } else {
+ if (toggle && list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark) != -1) {
+ // Delete the list
+ list_foreach(view->marks, free);
+ list_free(view->marks);
+ view->marks = NULL;
+ } else {
+ // Delete and replace with a new list
+ list_foreach(view->marks, free);
+ list_free(view->marks);
+
+ view->marks = create_list();
+ list_add(view->marks, mark);
+ }
+ }
+ } else {
+ view->marks = create_list();
+ list_add(view->marks, mark);
+ }
+ } else {
+ return cmd_results_new(CMD_FAILURE, "mark",
+ "Expected 'mark [--add|--replace] [--toggle] <mark>'");
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 97e10f10..3c47cfe7 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -20,7 +20,7 @@ struct cmd_results *cmd_move(int argc, char **argv) {
"'move <container|window> to workspace <name>' or "
"'move <container|window|workspace> to output <name|direction>' or "
"'move position mouse'";
- swayc_t *view = get_focused_container(&root_container);
+ swayc_t *view = current_container;
if (argc == 2 || (argc == 3 && strcasecmp(argv[2], "px") == 0 )) {
char *inv;
@@ -125,7 +125,7 @@ struct cmd_results *cmd_move(int argc, char **argv) {
if (view->type != C_CONTAINER && view->type != C_VIEW) {
return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views.");
}
- swayc_t *view = get_focused_container(&root_container);
+ swayc_t *view = current_container;
int i;
for (i = 0; i < scratchpad->length; i++) {
if (scratchpad->items[i] == view) {
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 61af080c..ef52bb07 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -19,7 +19,7 @@ enum resize_dim_types {
};
static bool set_size_floating(int new_dimension, bool use_width) {
- swayc_t *view = get_focused_float(swayc_active_workspace());
+ swayc_t *view = current_container;
if (view) {
if (use_width) {
int current_width = view->width;
@@ -50,7 +50,7 @@ static bool set_size_floating(int new_dimension, bool use_width) {
}
static bool resize_floating(int amount, bool use_width) {
- swayc_t *view = get_focused_float(swayc_active_workspace());
+ swayc_t *view = current_container;
if (view) {
if (use_width) {
@@ -64,7 +64,7 @@ static bool resize_floating(int amount, bool use_width) {
}
static bool resize_tiled(int amount, bool use_width) {
- swayc_t *container = get_focused_view(swayc_active_workspace());
+ swayc_t *container = current_container;
swayc_t *parent = container->parent;
int idx_focused = 0;
bool use_major = false;
@@ -199,7 +199,7 @@ static bool resize_tiled(int amount, bool use_width) {
static bool set_size_tiled(int amount, bool use_width) {
int desired;
- swayc_t *focused = get_focused_view(swayc_active_workspace());
+ swayc_t *focused = current_container;
if (use_width) {
desired = amount - focused->width;
@@ -211,7 +211,7 @@ static bool set_size_tiled(int amount, bool use_width) {
}
static bool set_size(int dimension, bool use_width) {
- swayc_t *focused = get_focused_view_include_floating(swayc_active_workspace());
+ swayc_t *focused = current_container;
if (focused) {
if (focused->is_floating) {
@@ -225,7 +225,7 @@ static bool set_size(int dimension, bool use_width) {
}
static bool resize(int dimension, bool use_width, enum resize_dim_types dim_type) {
- swayc_t *focused = get_focused_view_include_floating(swayc_active_workspace());
+ swayc_t *focused = current_container;
// translate "10 ppt" (10%) to appropriate # of pixels in case we need it
float ppt_dim = (float)dimension / 100;
diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c
new file mode 100644
index 00000000..ed56d9e5
--- /dev/null
+++ b/sway/commands/show_marks.c
@@ -0,0 +1,13 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+
+struct cmd_results *cmd_show_marks(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "show_marks", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+
+ config->show_marks = !strcasecmp(argv[0], "on");
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/split.c b/sway/commands/split.c
index e7da93d7..e3045a4f 100644
--- a/sway/commands/split.c
+++ b/sway/commands/split.c
@@ -17,7 +17,7 @@ static struct cmd_results *_do_split(int argc, char **argv, int layout) {
if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) {
return error;
}
- swayc_t *focused = get_focused_container(&root_container);
+ swayc_t *focused = current_container;
// Case of floating window, don't split
if (focused->is_floating) {
@@ -66,7 +66,7 @@ struct cmd_results *cmd_split(int argc, char **argv) {
} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) {
_do_split(argc - 1, argv + 1, L_HORIZ);
} else if (strcasecmp(argv[0], "t") == 0 || strcasecmp(argv[0], "toggle") == 0) {
- swayc_t *focused = get_focused_container(&root_container);
+ swayc_t *focused = current_container;
if (focused->parent->layout == L_VERT) {
_do_split(argc - 1, argv + 1, L_HORIZ);
} else {
@@ -89,7 +89,7 @@ struct cmd_results *cmd_splith(int argc, char **argv) {
}
struct cmd_results *cmd_splitt(int argc, char **argv) {
- swayc_t *focused = get_focused_container(&root_container);
+ swayc_t *focused = current_container;
if (focused->parent->layout == L_VERT) {
return _do_split(argc, argv, L_HORIZ);
} else {
diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c
new file mode 100644
index 00000000..ac213261
--- /dev/null
+++ b/sway/commands/unmark.c
@@ -0,0 +1,31 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "list.h"
+#include "stringop.h"
+
+struct cmd_results *cmd_unmark(int argc, char **argv) {
+ swayc_t *view = current_container;
+
+ if (view->marks) {
+ if (argc) {
+ char *mark = join_args(argv, argc);
+ int index;
+ if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
+ free(view->marks->items[index]);
+ list_del(view->marks, index);
+
+ if (view->marks->length == 0) {
+ list_free(view->marks);
+ view->marks = NULL;
+ }
+ }
+ free(mark);
+ } else {
+ list_foreach(view->marks, free);
+ list_free(view->marks);
+ view->marks = NULL;
+ }
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/config.c b/sway/config.c
index 46faf643..c8432a2a 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -329,6 +329,7 @@ static void config_defaults(struct sway_config *config) {
config->auto_back_and_forth = false;
config->seamless_mouse = true;
config->reading = false;
+ config->show_marks = true;
config->edge_gaps = true;
config->smart_gaps = false;
diff --git a/sway/container.c b/sway/container.c
index 707aa4d8..08aa77a8 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -61,6 +61,10 @@ static void free_swayc(swayc_t *cont) {
}
list_free(cont->floating);
}
+ if (cont->marks) {
+ list_foreach(cont->marks, free);
+ list_free(cont->marks);
+ }
if (cont->parent) {
remove_child(cont);
}
diff --git a/sway/criteria.c b/sway/criteria.c
index bc0523ce..ee6d4d1c 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
-#include <regex.h>
+#include <pcre.h>
#include "sway/criteria.h"
#include "sway/container.h"
#include "sway/config.h"
@@ -12,6 +12,7 @@
enum criteria_type { // *must* keep in sync with criteria_strings[]
CRIT_CLASS,
+ CRIT_CON_MARK,
CRIT_ID,
CRIT_INSTANCE,
CRIT_TITLE,
@@ -22,16 +23,16 @@ enum criteria_type { // *must* keep in sync with criteria_strings[]
CRIT_LAST
};
-// this *must* match the ordering in criteria_type enum
-static const char * const criteria_strings[] = {
- "class",
- "id",
- "instance",
- "title",
- "urgent", // either "latest" or "oldest" ...
- "window_role",
- "window_type",
- "workspace"
+static const char * const criteria_strings[CRIT_LAST] = {
+ [CRIT_CLASS] = "class",
+ [CRIT_CON_MARK] = "con_mark",
+ [CRIT_ID] = "id",
+ [CRIT_INSTANCE] = "instance",
+ [CRIT_TITLE] = "title",
+ [CRIT_URGENT] = "urgent", // either "latest" or "oldest" ...
+ [CRIT_WINDOW_ROLE] = "window_role",
+ [CRIT_WINDOW_TYPE] = "window_type",
+ [CRIT_WORKSPACE] = "workspace"
};
/**
@@ -40,18 +41,13 @@ static const char * const criteria_strings[] = {
*/
struct crit_token {
enum criteria_type type;
- regex_t *regex;
+ pcre *regex;
char *raw;
};
static void free_crit_token(struct crit_token *crit) {
- if (crit->regex) {
- regfree(crit->regex);
- free(crit->regex);
- }
- if (crit->raw) {
- free(crit->raw);
- }
+ pcre_free(crit->regex);
+ free(crit->raw);
free(crit);
}
@@ -188,18 +184,17 @@ static char *parse_criteria_name(enum criteria_type *type, char *name) {
}
// Returns error string on failure or NULL otherwise.
-static char *generate_regex(regex_t **regex, char *value) {
- *regex = calloc(1, sizeof(regex_t));
- int err = regcomp(*regex, value, REG_NOSUB);
- if (err != 0) {
- char *reg_err = malloc(64);
- regerror(err, *regex, reg_err, 64);
+static char *generate_regex(pcre **regex, char *value) {
+ const char *reg_err;
+ int offset;
+
+ *regex = pcre_compile(value, PCRE_UTF8 | PCRE_UCP, &reg_err, &offset, NULL);
+ if (!*regex) {
const char *fmt = "Regex compilation (for '%s') failed: %s";
int len = strlen(fmt) + strlen(value) + strlen(reg_err) - 3;
char *error = malloc(len);
snprintf(error, len, fmt, value, reg_err);
- free(reg_err);
return error;
}
return NULL;
@@ -243,6 +238,10 @@ ect_cleanup:
return error;
}
+static int regex_cmp(const char *item, const pcre *regex) {
+ return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
+}
+
// test a single view if it matches list of criteria tokens (all of them).
static bool criteria_test(swayc_t *cont, list_t *tokens) {
if (cont->type != C_VIEW) {
@@ -260,26 +259,34 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
if (focused->class && strcmp(cont->class, focused->class) == 0) {
matches++;
}
- } else if (crit->regex && regexec(crit->regex, cont->class, 0, NULL, 0) == 0) {
+ } else if (crit->regex && regex_cmp(cont->class, crit->regex) == 0) {
matches++;
}
break;
+ case CRIT_CON_MARK:
+ if (crit->regex && cont->marks && (list_seq_find(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex) != -1)) {
+ // Make sure it isn't matching the NUL string
+ if ((strcmp(crit->raw, "") == 0) == (list_seq_find(cont->marks, (int (*)(const void *, const void *))strcmp, "") != -1)) {
+ ++matches;
+ }
+ }
+ break;
case CRIT_ID:
if (!cont->app_id) {
// ignore
- } else if (crit->regex && regexec(crit->regex, cont->app_id, 0, NULL, 0) == 0) {
+ } else if (crit->regex && regex_cmp(cont->app_id, crit->regex) == 0) {
matches++;
}
break;
case CRIT_INSTANCE:
if (!cont->instance) {
// ignore
- } else if (strcmp(crit->raw, "focused") == 0) {
+ } else if (crit_is_focused(crit->raw)) {
swayc_t *focused = get_focused_view(&root_container);
if (focused->instance && strcmp(cont->instance, focused->instance) == 0) {
matches++;
}
- } else if (crit->regex && regexec(crit->regex, cont->instance, 0, NULL, 0) == 0) {
+ } else if (crit->regex && regex_cmp(cont->instance, crit->regex) == 0) {
matches++;
}
break;
@@ -291,7 +298,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
if (focused->name && strcmp(cont->name, focused->name) == 0) {
matches++;
}
- } else if (crit->regex && regexec(crit->regex, cont->name, 0, NULL, 0) == 0) {
+ } else if (crit->regex && regex_cmp(cont->name, crit->regex) == 0) {
matches++;
}
break;
@@ -311,7 +318,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
if (focused_ws->name && strcmp(cont_ws->name, focused_ws->name) == 0) {
matches++;
}
- } else if (crit->regex && regexec(crit->regex, cont_ws->name, 0, NULL, 0) == 0) {
+ } else if (crit->regex && regex_cmp(cont_ws->name, crit->regex) == 0) {
matches++;
}
break;
@@ -362,3 +369,21 @@ list_t *criteria_for(swayc_t *cont) {
}
return matches;
}
+
+struct list_tokens {
+ list_t *list;
+ list_t *tokens;
+};
+
+static void container_match_add(swayc_t *container, struct list_tokens *list_tokens) {
+ if (criteria_test(container, list_tokens->tokens)) {
+ list_add(list_tokens->list, container);
+ }
+}
+list_t *container_for(list_t *tokens) {
+ struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens};
+
+ container_map(&root_container, (void (*)(swayc_t *, void *))container_match_add, &list_tokens);
+
+ return list_tokens.list;
+}
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b5f4bb16..67a3cdc8 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -63,6 +63,7 @@ void ipc_client_handle_command(struct ipc_client *client);
bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
void ipc_get_workspaces_callback(swayc_t *workspace, void *data);
void ipc_get_outputs_callback(swayc_t *container, void *data);
+static void ipc_get_marks_callback(swayc_t *container, void *data);
void ipc_init(void) {
ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
@@ -161,7 +162,8 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) {
}
int flags;
- if ((flags=fcntl(client_fd, F_GETFD)) == -1 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
+ if ((flags = fcntl(client_fd, F_GETFD)) == -1
+ || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
sway_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket");
close(client_fd);
return 0;
@@ -193,13 +195,12 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
if (mask & WLC_EVENT_ERROR) {
sway_log(L_ERROR, "IPC Client socket error, removing client");
- client->fd = -1;
ipc_client_disconnect(client);
return 0;
}
if (mask & WLC_EVENT_HANGUP) {
- client->fd = -1;
+ sway_log(L_DEBUG, "Client %d hung up", client->fd);
ipc_client_disconnect(client);
return 0;
}
@@ -456,6 +457,19 @@ void ipc_client_handle_command(struct ipc_client *client) {
goto exit_cleanup;
}
+ case IPC_GET_MARKS:
+ {
+ if (!(client->security_policy & IPC_FEATURE_GET_MARKS)) {
+ goto exit_denied;
+ }
+ json_object *marks = json_object_new_array();
+ container_map(&root_container, ipc_get_marks_callback, marks);
+ const char *json_string = json_object_to_json_string(marks);
+ ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
+ json_object_put(marks);
+ goto exit_cleanup;
+ }
+
case IPC_GET_VERSION:
{
json_object *version = ipc_json_get_version();
@@ -609,6 +623,16 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) {
}
}
+static void ipc_get_marks_callback(swayc_t *container, void *data) {
+ json_object *object = (json_object *)data;
+ if (container->marks) {
+ for (int i = 0; i < container->marks->length; ++i) {
+ char *mark = (char *)container->marks->items[i];
+ json_object_array_add(object, json_object_new_string(mark));
+ }
+ }
+}
+
void ipc_send_event(const char *json_string, enum ipc_command_type event) {
static struct {
enum ipc_command_type event;
diff --git a/sway/main.c b/sway/main.c
index 55b71fa4..b9f8936f 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -11,8 +11,8 @@
#include <signal.h>
#include <unistd.h>
#include <getopt.h>
-#include <sys/capability.h>
#ifdef __linux__
+#include <sys/capability.h>
#include <sys/prctl.h>
#endif
#include "sway/extensions.h"
diff --git a/sway/sway.1.txt b/sway/sway.1.txt
index 32519d0e..1a77611d 100644
--- a/sway/sway.1.txt
+++ b/sway/sway.1.txt
@@ -48,8 +48,8 @@ providing such a great piece of software, so good that your users would rather
write an entirely new window manager from scratch that behaved _exactly_ like i3
rather than switch to something else.
-You may run sway from an ongoing x11 session to run it within x. Otherwise, you
-can run sway on a tty and it will use your outputs directly.
+Launch sway directly from a tty or via your favorite Wayland-compatible login
+manager.
*Important note for nvidia users*: The proprietary nvidia driver does _not_ have
support for Wayland as of 2016-06-10. Use nouveau.
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 5d143d97..d76951b5 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -316,6 +316,14 @@ The default colors are:
If smart_gaps are _on_ then gaps will only be enabled if a workspace has more
than one child container.
+**mark** \<--add|--replace> \<--toggle> <identifier>::
+ Marks are arbitrary labels that can be used to identify certain windows and
+ then jump to them at a later time. By default, the **mark** command sets
+ _identifier_ as the only mark on a window. By specifying _--add_, mark will
+ add _identifier_ to the list of current marks. If _--toggle_ is specified mark
+ will remove _identifier_ if it is already a label. Marks may be found by using
+ a criteria. See the **Criteria** section below.
+
**mode** <mode_name>::
Switches to the given mode_name. The default mode is simply _default_. To
create a new mode in config append _{_ to this command, the following lines
@@ -368,6 +376,15 @@ The default colors are:
be configured with perfectly aligned adjacent positions for this option to
have any effect.
+**show_marks** <on|off>::
+ If **show_marks** is on then marks will be showed in the window decoration.
+ However, any mark that starts with an underscore will not be drawn even if the
+ option is on. The default option is _on_.
+
+**unmark** <identifier>::
+ **Unmark** will remove _identifier_ from the list of current marks on a window. If
+ no _identifier_ is specified then **unmark** will remove all marks.
+
**workspace** [number] <name>::
Switches to the specified workspace. The string "number" is optional. The
worspace _name_, if unquoted, may not contain the string "output", as sway
@@ -409,6 +426,20 @@ The string contains one or more (space separated) attribute/value pairs and they
are used by some commands filter which views to execute actions on. All attributes
must match for the criteria string to match.
+Criteria may be used with either the **for_window** or **assign** commands to
+specify operations to perform on new views. A criteria may also be used to
+perform specific commands (ones that normally act upon one window) on all views
+that match that criteria. For example:
+
+Focus on a window with the mark "IRC":
+ [con_mark="IRC"] focus
+
+Kill all windows with the title "Emacs":
+ [class="Emacs"] kill
+
+Mark all Firefox windows with "Browser":
+ [class="Firefox"] mark Browser
+
Currently supported attributes:
**class**::
@@ -416,6 +447,9 @@ Currently supported attributes:
is _focused_ then the window class must be the same as that of the currently
focused window.
+**con_mark**::
+ Compare against the window marks. Can be a regular expression.
+
**id**::
Compare value against the app id. Can be a regular expression.