summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-04-07 14:17:01 -0400
committerLibravatar GitHub <noreply@github.com>2017-04-07 14:17:01 -0400
commit8d191b2785161a204c4df15aadeca66e306afa1c (patch)
treeb929def6e7bcdbff10a7f1cc815f9a278821c666
parentMerge pull request #1153 from SirCmpwn/fix-1152 (diff)
parentAdd `-t get_marks` and use more i3-like marks (diff)
downloadsway-8d191b2785161a204c4df15aadeca66e306afa1c.tar.gz
sway-8d191b2785161a204c4df15aadeca66e306afa1c.tar.zst
sway-8d191b2785161a204c4df15aadeca66e306afa1c.zip
Merge pull request #1155 from 4e554c4c/get_marks
Add `-t get_marks` and use more i3-like marks
-rw-r--r--sway/commands/mark.c13
-rw-r--r--sway/ipc-server.c24
2 files changed, 37 insertions, 0 deletions
diff --git a/sway/commands/mark.c b/sway/commands/mark.c
index 919883b0..c1d959df 100644
--- a/sway/commands/mark.c
+++ b/sway/commands/mark.c
@@ -5,6 +5,15 @@
5#include "list.h" 5#include "list.h"
6#include "stringop.h" 6#include "stringop.h"
7 7
8static void find_marks_callback(swayc_t *container, void *_mark) {
9 char *mark = (char *)_mark;
10
11 int index;
12 if (container->marks && ((index = list_seq_find(container->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1)) {
13 list_del(container->marks, index);
14 }
15}
16
8struct cmd_results *cmd_mark(int argc, char **argv) { 17struct cmd_results *cmd_mark(int argc, char **argv) {
9 struct cmd_results *error = NULL; 18 struct cmd_results *error = NULL;
10 if (config->reading) return cmd_results_new(CMD_FAILURE, "mark", "Can't be used in config file."); 19 if (config->reading) return cmd_results_new(CMD_FAILURE, "mark", "Can't be used in config file.");
@@ -30,6 +39,10 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
30 39
31 if (argc) { 40 if (argc) {
32 char *mark = join_args(argv, argc); 41 char *mark = join_args(argv, argc);
42
43 // Remove all existing marks of this type
44 container_map(&root_container, find_marks_callback, mark);
45
33 if (view->marks) { 46 if (view->marks) {
34 if (add) { 47 if (add) {
35 int index; 48 int index;
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 984e6754..6554098b 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -63,6 +63,7 @@ void ipc_client_handle_command(struct ipc_client *client);
63bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); 63bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
64void ipc_get_workspaces_callback(swayc_t *workspace, void *data); 64void ipc_get_workspaces_callback(swayc_t *workspace, void *data);
65void ipc_get_outputs_callback(swayc_t *container, void *data); 65void ipc_get_outputs_callback(swayc_t *container, void *data);
66static void ipc_get_marks_callback(swayc_t *container, void *data);
66 67
67void ipc_init(void) { 68void ipc_init(void) {
68 ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); 69 ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
@@ -464,6 +465,19 @@ void ipc_client_handle_command(struct ipc_client *client) {
464 goto exit_cleanup; 465 goto exit_cleanup;
465 } 466 }
466 467
468 case IPC_GET_MARKS:
469 {
470 if (!(client->security_policy & IPC_FEATURE_GET_MARKS)) {
471 goto exit_denied;
472 }
473 json_object *marks = json_object_new_array();
474 container_map(&root_container, ipc_get_marks_callback, marks);
475 const char *json_string = json_object_to_json_string(marks);
476 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
477 json_object_put(marks);
478 goto exit_cleanup;
479 }
480
467 case IPC_GET_VERSION: 481 case IPC_GET_VERSION:
468 { 482 {
469 json_object *version = ipc_json_get_version(); 483 json_object *version = ipc_json_get_version();
@@ -617,6 +631,16 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) {
617 } 631 }
618} 632}
619 633
634static void ipc_get_marks_callback(swayc_t *container, void *data) {
635 json_object *object = (json_object *)data;
636 if (container->marks) {
637 for (int i = 0; i < container->marks->length; ++i) {
638 char *mark = (char *)container->marks->items[i];
639 json_object_array_add(object, json_object_new_string(mark));
640 }
641 }
642}
643
620void ipc_send_event(const char *json_string, enum ipc_command_type event) { 644void ipc_send_event(const char *json_string, enum ipc_command_type event) {
621 static struct { 645 static struct {
622 enum ipc_command_type event; 646 enum ipc_command_type event;