summaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/bind.c52
-rw-r--r--sway/commands/mark.c2
-rw-r--r--sway/commands/move.c4
-rw-r--r--sway/commands/reload.c29
4 files changed, 83 insertions, 4 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 133fd089..8270b958 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -1,3 +1,4 @@
1#define _XOPEN_SOURCE 500
1#ifdef __linux__ 2#ifdef __linux__
2#include <linux/input-event-codes.h> 3#include <linux/input-event-codes.h>
3#elif __FreeBSD__ 4#elif __FreeBSD__
@@ -5,9 +6,11 @@
5#endif 6#endif
6#include <xkbcommon/xkbcommon.h> 7#include <xkbcommon/xkbcommon.h>
7#include <xkbcommon/xkbcommon-names.h> 8#include <xkbcommon/xkbcommon-names.h>
9#include <string.h>
8#include <strings.h> 10#include <strings.h>
9#include "sway/commands.h" 11#include "sway/commands.h"
10#include "sway/config.h" 12#include "sway/config.h"
13#include "sway/ipc-server.h"
11#include "list.h" 14#include "list.h"
12#include "log.h" 15#include "log.h"
13#include "stringop.h" 16#include "stringop.h"
@@ -27,6 +30,33 @@ void free_sway_binding(struct sway_binding *binding) {
27 free(binding); 30 free(binding);
28} 31}
29 32
33static struct sway_binding *sway_binding_dup(struct sway_binding *sb) {
34 struct sway_binding *new_sb = calloc(1, sizeof(struct sway_binding));
35 if (!new_sb) {
36 return NULL;
37 }
38
39 new_sb->type = sb->type;
40 new_sb->order = sb->order;
41 new_sb->flags = sb->flags;
42 new_sb->modifiers = sb->modifiers;
43 new_sb->command = strdup(sb->command);
44
45 new_sb->keys = create_list();
46 int i;
47 for (i = 0; i < sb->keys->length; ++i) {
48 xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
49 if (!key) {
50 free_sway_binding(new_sb);
51 return NULL;
52 }
53 *key = *(xkb_keysym_t *)sb->keys->items[i];
54 list_add(new_sb->keys, key);
55 }
56
57 return new_sb;
58}
59
30/** 60/**
31 * Returns true if the bindings have the same key and modifier combinations. 61 * Returns true if the bindings have the same key and modifier combinations.
32 * Note that keyboard layout is not considered, so the bindings might actually 62 * Note that keyboard layout is not considered, so the bindings might actually
@@ -275,11 +305,31 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
275void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) { 305void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) {
276 wlr_log(WLR_DEBUG, "running command for binding: %s", 306 wlr_log(WLR_DEBUG, "running command for binding: %s",
277 binding->command); 307 binding->command);
308
309 struct sway_binding *binding_copy = binding;
310 bool reload = false;
311 // if this is a reload command we need to make a duplicate of the
312 // binding since it will be gone after the reload has completed.
313 if (strcasecmp(binding->command, "reload") == 0) {
314 reload = true;
315 binding_copy = sway_binding_dup(binding);
316 if (!binding_copy) {
317 wlr_log(WLR_ERROR, "Failed to duplicate binding during reload");
318 return;
319 }
320 }
321
278 config->handler_context.seat = seat; 322 config->handler_context.seat = seat;
279 struct cmd_results *results = execute_command(binding->command, NULL); 323 struct cmd_results *results = execute_command(binding->command, NULL);
280 if (results->status != CMD_SUCCESS) { 324 if (results->status == CMD_SUCCESS) {
325 ipc_event_binding(binding_copy);
326 } else {
281 wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)", 327 wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)",
282 binding->command, results->error); 328 binding->command, results->error);
283 } 329 }
330
331 if (reload) { // free the binding if we made a copy
332 free_sway_binding(binding_copy);
333 }
284 free_cmd_results(results); 334 free_cmd_results(results);
285} 335}
diff --git a/sway/commands/mark.c b/sway/commands/mark.c
index 5a897e69..9ea8c301 100644
--- a/sway/commands/mark.c
+++ b/sway/commands/mark.c
@@ -58,7 +58,7 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
58 view_find_and_unmark(mark); 58 view_find_and_unmark(mark);
59 59
60 if (!toggle || !had_mark) { 60 if (!toggle || !had_mark) {
61 list_add(view->marks, strdup(mark)); 61 view_add_mark(view, mark);
62 } 62 }
63 63
64 free(mark); 64 free(mark);
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 1aae3838..46ebcd83 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -98,7 +98,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
98 container_move_to(current, destination); 98 container_move_to(current, destination);
99 struct sway_container *focus = seat_get_focus_inactive( 99 struct sway_container *focus = seat_get_focus_inactive(
100 config->handler_context.seat, old_parent); 100 config->handler_context.seat, old_parent);
101 seat_set_focus(config->handler_context.seat, focus); 101 seat_set_focus_warp(config->handler_context.seat, focus, true, false);
102 container_reap_empty(old_parent); 102 container_reap_empty(old_parent);
103 container_reap_empty(destination->parent); 103 container_reap_empty(destination->parent);
104 104
@@ -135,7 +135,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
135 struct sway_container *old_parent = current->parent; 135 struct sway_container *old_parent = current->parent;
136 struct sway_container *old_ws = container_parent(current, C_WORKSPACE); 136 struct sway_container *old_ws = container_parent(current, C_WORKSPACE);
137 container_move_to(current, focus); 137 container_move_to(current, focus);
138 seat_set_focus(config->handler_context.seat, old_parent); 138 seat_set_focus_warp(config->handler_context.seat, old_parent, true, false);
139 container_reap_empty(old_parent); 139 container_reap_empty(old_parent);
140 container_reap_empty(focus->parent); 140 container_reap_empty(focus->parent);
141 141
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index cea6a94b..5c1b19b4 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -1,17 +1,46 @@
1#define _XOPEN_SOURCE 500
2#include <string.h>
1#include "sway/commands.h" 3#include "sway/commands.h"
2#include "sway/config.h" 4#include "sway/config.h"
5#include "sway/ipc-server.h"
3#include "sway/tree/arrange.h" 6#include "sway/tree/arrange.h"
7#include "list.h"
4 8
5struct cmd_results *cmd_reload(int argc, char **argv) { 9struct cmd_results *cmd_reload(int argc, char **argv) {
6 struct cmd_results *error = NULL; 10 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { 11 if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) {
8 return error; 12 return error;
9 } 13 }
14
15 // store bar ids to check against new bars for barconfig_update events
16 list_t *bar_ids = create_list();
17 for (int i = 0; i < config->bars->length; ++i) {
18 struct bar_config *bar = config->bars->items[i];
19 list_add(bar_ids, strdup(bar->id));
20 }
21
10 if (!load_main_config(config->current_config_path, true)) { 22 if (!load_main_config(config->current_config_path, true)) {
11 return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); 23 return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config.");
12 } 24 }
25 ipc_event_workspace(NULL, NULL, "reload");
13 26
14 load_swaybars(); 27 load_swaybars();
28
29 for (int i = 0; i < config->bars->length; ++i) {
30 struct bar_config *bar = config->bars->items[i];
31 for (int j = 0; j < bar_ids->length; ++j) {
32 if (strcmp(bar->id, bar_ids->items[j]) == 0) {
33 ipc_event_barconfig_update(bar);
34 break;
35 }
36 }
37 }
38
39 for (int i = 0; i < bar_ids->length; ++i) {
40 free(bar_ids->items[i]);
41 }
42 list_free(bar_ids);
43
15 arrange_windows(&root_container); 44 arrange_windows(&root_container);
16 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 45 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
17} 46}