summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-13 15:52:16 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-13 15:52:16 -0400
commit3a3c50135fabc6a23f7b130effef9b642e54bf3c (patch)
treed22fbf61f38f7c8987df51cf5f23b60e5f95e3b3
parentMerge pull request #25 from taiyu-len/master (diff)
parentStyle fix (diff)
downloadsway-3a3c50135fabc6a23f7b130effef9b642e54bf3c.tar.gz
sway-3a3c50135fabc6a23f7b130effef9b642e54bf3c.tar.zst
sway-3a3c50135fabc6a23f7b130effef9b642e54bf3c.zip
Merge pull request #26 from Luminarys/master
Added in proper workspace name generation and command queue
-rw-r--r--sway/commands.c3
-rw-r--r--sway/config.c53
-rw-r--r--sway/config.h6
-rw-r--r--sway/handlers.c21
-rw-r--r--sway/main.c8
-rw-r--r--sway/workspace.c47
6 files changed, 113 insertions, 25 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 0adda3e7..cae35237 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -229,8 +229,7 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) {
229 229
230static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { 230static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) {
231 char *name = layout == L_VERT ? "splitv": 231 char *name = layout == L_VERT ? "splitv":
232 layout == L_HORIZ ? "splith": 232 layout == L_HORIZ ? "splith":"split";
233 "split";
234 if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { 233 if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) {
235 return false; 234 return false;
236 } 235 }
diff --git a/sway/config.c b/sway/config.c
index 6fe681f6..d96d23fc 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -25,14 +25,22 @@ bool load_config() {
25 return false; 25 return false;
26 } 26 }
27 free(temp); 27 free(temp);
28 config = read_config(f, false); 28
29 bool config_load_success;
30 if (config) {
31 config_load_success = read_config(f, true);
32 } else {
33 config_load_success = read_config(f, false);
34 }
29 fclose(f); 35 fclose(f);
30 return true; 36
37 return config_load_success;
31} 38}
32 39
33void config_defaults(struct sway_config *config) { 40void config_defaults(struct sway_config *config) {
34 config->symbols = create_list(); 41 config->symbols = create_list();
35 config->modes = create_list(); 42 config->modes = create_list();
43 config->cmd_queue = create_list();
36 config->current_mode = malloc(sizeof(struct sway_mode)); 44 config->current_mode = malloc(sizeof(struct sway_mode));
37 config->current_mode->name = NULL; 45 config->current_mode->name = NULL;
38 config->current_mode->bindings = create_list(); 46 config->current_mode->bindings = create_list();
@@ -41,14 +49,17 @@ void config_defaults(struct sway_config *config) {
41 config->focus_follows_mouse = true; 49 config->focus_follows_mouse = true;
42 config->mouse_warping = true; 50 config->mouse_warping = true;
43 config->reloading = false; 51 config->reloading = false;
52 config->active = false;
53 config->failed = false;
44} 54}
45 55
46struct sway_config *read_config(FILE *file, bool is_active) { 56bool read_config(FILE *file, bool is_active) {
47 struct sway_config *config = malloc(sizeof(struct sway_config)); 57 struct sway_config *temp_config = malloc(sizeof(struct sway_config));
48 config_defaults(config); 58 config_defaults(temp_config);
49
50 if (is_active) { 59 if (is_active) {
51 config->reloading = true; 60 sway_log(L_DEBUG, "Performing configuration file reload");
61 temp_config->reloading = true;
62 temp_config->active = true;
52 } 63 }
53 64
54 bool success = true; 65 bool success = true;
@@ -68,9 +79,24 @@ struct sway_config *read_config(FILE *file, bool is_active) {
68 goto _continue; 79 goto _continue;
69 } 80 }
70 81
71 if (!temp_depth && handle_command(config, line) != true) { 82 // Any command which would require wlc to be initialized
83 // should be queued for later execution
84 list_t *args = split_string(line, " ");
85 if (!is_active && (
86 strcmp("workspace", args->items[0]) == 0 ||
87 strcmp("exec", args->items[0]) == 0 ||
88 strcmp("exec_always", args->items[0]) == 0 )) {
89 sway_log(L_DEBUG, "Deferring command %s", line);
90
91 char *cmd = malloc(strlen(line) + 1);
92 strcpy(cmd, line);
93 list_add(temp_config->cmd_queue, cmd);
94 } else if (!temp_depth && !handle_command(temp_config, line)) {
95 sway_log(L_DEBUG, "Config load failed for line %s", line);
72 success = false; 96 success = false;
73 } 97 temp_config->failed = true;
98 }
99 list_free(args);
74 100
75_continue: 101_continue:
76 if (line && line[strlen(line) - 1] == '{') { 102 if (line && line[strlen(line) - 1] == '{') {
@@ -79,15 +105,12 @@ _continue:
79 free(line); 105 free(line);
80 } 106 }
81 107
82 if (success == false) {
83 exit(1);
84 }
85
86 if (is_active) { 108 if (is_active) {
87 config->reloading = false; 109 temp_config->reloading = false;
88 } 110 }
111 config = temp_config;
89 112
90 return config; 113 return success;
91} 114}
92 115
93char *do_var_replacement(struct sway_config *config, char *str) { 116char *do_var_replacement(struct sway_config *config, char *str) {
diff --git a/sway/config.h b/sway/config.h
index 62b65723..c9fd374c 100644
--- a/sway/config.h
+++ b/sway/config.h
@@ -24,17 +24,19 @@ struct sway_mode {
24struct sway_config { 24struct sway_config {
25 list_t *symbols; 25 list_t *symbols;
26 list_t *modes; 26 list_t *modes;
27 list_t *cmd_queue;
27 struct sway_mode *current_mode; 28 struct sway_mode *current_mode;
28 29
29 // Flags 30 // Flags
30 bool focus_follows_mouse; 31 bool focus_follows_mouse;
31 bool mouse_warping; 32 bool mouse_warping;
32 33 bool active;
34 bool failed;
33 bool reloading; 35 bool reloading;
34}; 36};
35 37
36bool load_config(); 38bool load_config();
37struct sway_config *read_config(FILE *file, bool is_active); 39bool read_config(FILE *file, bool is_active);
38char *do_var_replacement(struct sway_config *config, char *str); 40char *do_var_replacement(struct sway_config *config, char *str);
39 41
40extern struct sway_config *config; 42extern struct sway_config *config;
diff --git a/sway/handlers.c b/sway/handlers.c
index fe7de75b..48c6cbf7 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -8,6 +8,7 @@
8#include "config.h" 8#include "config.h"
9#include "commands.h" 9#include "commands.h"
10#include "handlers.h" 10#include "handlers.h"
11#include "stringop.h"
11 12
12static bool handle_output_created(wlc_handle output) { 13static bool handle_output_created(wlc_handle output) {
13 add_output(output); 14 add_output(output);
@@ -163,6 +164,23 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
163 return true; 164 return true;
164} 165}
165 166
167static void handle_wlc_ready(void) {
168 sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue");
169
170 int i;
171 for (i = 0; i < config->cmd_queue->length; ++i) {
172 handle_command(config, config->cmd_queue->items[i]);
173 }
174 free_flat_list(config->cmd_queue);
175
176 if (config->failed) {
177 sway_log(L_ERROR, "Programs have been execd, aborting!");
178 sway_abort("Unable to load config");
179 }
180
181 config->active = true;
182}
183
166 184
167struct wlc_interface interface = { 185struct wlc_interface interface = {
168 .output = { 186 .output = {
@@ -185,6 +203,9 @@ struct wlc_interface interface = {
185 .pointer = { 203 .pointer = {
186 .motion = handle_pointer_motion, 204 .motion = handle_pointer_motion,
187 .button = handle_pointer_button 205 .button = handle_pointer_button
206 },
207 .compositor = {
208 .ready = handle_wlc_ready
188 } 209 }
189}; 210};
190 211
diff --git a/sway/main.c b/sway/main.c
index 7477b08c..061564e2 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -18,6 +18,9 @@ int main(int argc, char **argv) {
18 /* Signal handling */ 18 /* Signal handling */
19 signal(SIGCHLD, sigchld_handle); 19 signal(SIGCHLD, sigchld_handle);
20 20
21 if (!load_config()) {
22 sway_log(L_ERROR, "Config load failed, aborting sway post init!");
23 }
21 24
22 setenv("WLC_DIM", "0", 0); 25 setenv("WLC_DIM", "0", 0);
23 if (!wlc_init(&interface, argc, argv)) { 26 if (!wlc_init(&interface, argc, argv)) {
@@ -25,11 +28,8 @@ int main(int argc, char **argv) {
25 } 28 }
26 setenv("DISPLAY", ":1", 1); 29 setenv("DISPLAY", ":1", 1);
27 30
28 if (!load_config()) {
29 sway_abort("Unable to load config");
30 }
31
32 wlc_run(); 31 wlc_run();
32
33 return 0; 33 return 0;
34} 34}
35 35
diff --git a/sway/workspace.c b/sway/workspace.c
index 53675c03..906d0c5d 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -6,13 +6,56 @@
6#include "list.h" 6#include "list.h"
7#include "log.h" 7#include "log.h"
8#include "container.h" 8#include "container.h"
9#include "config.h"
10#include "stringop.h"
9 11
10swayc_t *active_workspace = NULL; 12swayc_t *active_workspace = NULL;
11 13
12int ws_num = 1;
13
14char *workspace_next_name(void) { 14char *workspace_next_name(void) {
15 sway_log(L_DEBUG, "Workspace: Generating new name");
16 int i;
15 int l = 1; 17 int l = 1;
18 // Scan all workspace bindings to find the next available workspace name,
19 // if none are found/available then default to a number
20 struct sway_mode *mode = config->current_mode;
21
22 for (i = 0; i < mode->bindings->length; ++i) {
23 struct sway_binding *binding = mode->bindings->items[i];
24 const char* command = binding->command;
25 list_t *args = split_string(command, " ");
26
27 if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) {
28 sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]);
29 char* target = malloc(strlen(args->items[1]) + 1);
30 strcpy(target, args->items[1]);
31 while (*target == ' ' || *target == '\t')
32 target++;
33
34 // Make sure that the command references an actual workspace
35 // not a command about workspaces
36 if (strcmp(target, "next") == 0 ||
37 strcmp(target, "prev") == 0 ||
38 strcmp(target, "next_on_output") == 0 ||
39 strcmp(target, "prev_on_output") == 0 ||
40 strcmp(target, "number") == 0 ||
41 strcmp(target, "back_and_forth") == 0 ||
42 strcmp(target, "current") == 0)
43 continue;
44
45 //Make sure that the workspace doesn't already exist
46 if (workspace_find_by_name(target)) {
47 continue;
48 }
49
50 list_free(args);
51
52 sway_log(L_DEBUG, "Workspace: Found free name %s", target);
53 return target;
54 }
55 }
56 // As a fall back, get the current number of active workspaces
57 // and return that + 1 for the next workspace's name
58 int ws_num = root_container.children->length;
16 if (ws_num >= 10) { 59 if (ws_num >= 10) {
17 l = 2; 60 l = 2;
18 } else if (ws_num >= 100) { 61 } else if (ws_num >= 100) {