mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 06:24:20 +01:00
Add -t get_marks
and use more i3-like marks
In i3 every mark is unique and one mark cannot be used in more than one window, sway behavior has been amended to match this. `swaymsg -t get_marks` will now return an array of all marks used in sway. See #98
This commit is contained in:
parent
4e12bf64ef
commit
154c6718c1
@ -5,6 +5,15 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "stringop.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 *cmd_mark(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if (config->reading) return cmd_results_new(CMD_FAILURE, "mark", "Can't be used in config file.");
|
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) {
|
|||||||
|
|
||||||
if (argc) {
|
if (argc) {
|
||||||
char *mark = join_args(argv, 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 (view->marks) {
|
||||||
if (add) {
|
if (add) {
|
||||||
int index;
|
int index;
|
||||||
|
@ -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);
|
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_workspaces_callback(swayc_t *workspace, void *data);
|
||||||
void ipc_get_outputs_callback(swayc_t *container, 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) {
|
void ipc_init(void) {
|
||||||
ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
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) {
|
|||||||
goto exit_cleanup;
|
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:
|
case IPC_GET_VERSION:
|
||||||
{
|
{
|
||||||
json_object *version = ipc_json_get_version();
|
json_object *version = ipc_json_get_version();
|
||||||
@ -617,6 +631,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) {
|
void ipc_send_event(const char *json_string, enum ipc_command_type event) {
|
||||||
static struct {
|
static struct {
|
||||||
enum ipc_command_type event;
|
enum ipc_command_type event;
|
||||||
|
Loading…
Reference in New Issue
Block a user