mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-26 21:58:08 +01:00
Merge pull request #26 from Luminarys/master
Added in proper workspace name generation and command queue
This commit is contained in:
commit
3a3c50135f
6 changed files with 113 additions and 25 deletions
|
@ -229,8 +229,7 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) {
|
|||
|
||||
static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) {
|
||||
char *name = layout == L_VERT ? "splitv":
|
||||
layout == L_HORIZ ? "splith":
|
||||
"split";
|
||||
layout == L_HORIZ ? "splith":"split";
|
||||
if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -25,14 +25,22 @@ bool load_config() {
|
|||
return false;
|
||||
}
|
||||
free(temp);
|
||||
config = read_config(f, false);
|
||||
|
||||
bool config_load_success;
|
||||
if (config) {
|
||||
config_load_success = read_config(f, true);
|
||||
} else {
|
||||
config_load_success = read_config(f, false);
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
|
||||
return config_load_success;
|
||||
}
|
||||
|
||||
void config_defaults(struct sway_config *config) {
|
||||
config->symbols = create_list();
|
||||
config->modes = create_list();
|
||||
config->cmd_queue = create_list();
|
||||
config->current_mode = malloc(sizeof(struct sway_mode));
|
||||
config->current_mode->name = NULL;
|
||||
config->current_mode->bindings = create_list();
|
||||
|
@ -41,14 +49,17 @@ void config_defaults(struct sway_config *config) {
|
|||
config->focus_follows_mouse = true;
|
||||
config->mouse_warping = true;
|
||||
config->reloading = false;
|
||||
config->active = false;
|
||||
config->failed = false;
|
||||
}
|
||||
|
||||
struct sway_config *read_config(FILE *file, bool is_active) {
|
||||
struct sway_config *config = malloc(sizeof(struct sway_config));
|
||||
config_defaults(config);
|
||||
|
||||
bool read_config(FILE *file, bool is_active) {
|
||||
struct sway_config *temp_config = malloc(sizeof(struct sway_config));
|
||||
config_defaults(temp_config);
|
||||
if (is_active) {
|
||||
config->reloading = true;
|
||||
sway_log(L_DEBUG, "Performing configuration file reload");
|
||||
temp_config->reloading = true;
|
||||
temp_config->active = true;
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
|
@ -68,9 +79,24 @@ struct sway_config *read_config(FILE *file, bool is_active) {
|
|||
goto _continue;
|
||||
}
|
||||
|
||||
if (!temp_depth && handle_command(config, line) != true) {
|
||||
// Any command which would require wlc to be initialized
|
||||
// should be queued for later execution
|
||||
list_t *args = split_string(line, " ");
|
||||
if (!is_active && (
|
||||
strcmp("workspace", args->items[0]) == 0 ||
|
||||
strcmp("exec", args->items[0]) == 0 ||
|
||||
strcmp("exec_always", args->items[0]) == 0 )) {
|
||||
sway_log(L_DEBUG, "Deferring command %s", line);
|
||||
|
||||
char *cmd = malloc(strlen(line) + 1);
|
||||
strcpy(cmd, line);
|
||||
list_add(temp_config->cmd_queue, cmd);
|
||||
} else if (!temp_depth && !handle_command(temp_config, line)) {
|
||||
sway_log(L_DEBUG, "Config load failed for line %s", line);
|
||||
success = false;
|
||||
}
|
||||
temp_config->failed = true;
|
||||
}
|
||||
list_free(args);
|
||||
|
||||
_continue:
|
||||
if (line && line[strlen(line) - 1] == '{') {
|
||||
|
@ -79,15 +105,12 @@ _continue:
|
|||
free(line);
|
||||
}
|
||||
|
||||
if (success == false) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (is_active) {
|
||||
config->reloading = false;
|
||||
temp_config->reloading = false;
|
||||
}
|
||||
config = temp_config;
|
||||
|
||||
return config;
|
||||
return success;
|
||||
}
|
||||
|
||||
char *do_var_replacement(struct sway_config *config, char *str) {
|
||||
|
|
|
@ -24,17 +24,19 @@ struct sway_mode {
|
|||
struct sway_config {
|
||||
list_t *symbols;
|
||||
list_t *modes;
|
||||
list_t *cmd_queue;
|
||||
struct sway_mode *current_mode;
|
||||
|
||||
// Flags
|
||||
bool focus_follows_mouse;
|
||||
bool mouse_warping;
|
||||
|
||||
bool active;
|
||||
bool failed;
|
||||
bool reloading;
|
||||
};
|
||||
|
||||
bool load_config();
|
||||
struct sway_config *read_config(FILE *file, bool is_active);
|
||||
bool read_config(FILE *file, bool is_active);
|
||||
char *do_var_replacement(struct sway_config *config, char *str);
|
||||
|
||||
extern struct sway_config *config;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "config.h"
|
||||
#include "commands.h"
|
||||
#include "handlers.h"
|
||||
#include "stringop.h"
|
||||
|
||||
static bool handle_output_created(wlc_handle output) {
|
||||
add_output(output);
|
||||
|
@ -163,6 +164,23 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|||
return true;
|
||||
}
|
||||
|
||||
static void handle_wlc_ready(void) {
|
||||
sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue");
|
||||
|
||||
int i;
|
||||
for (i = 0; i < config->cmd_queue->length; ++i) {
|
||||
handle_command(config, config->cmd_queue->items[i]);
|
||||
}
|
||||
free_flat_list(config->cmd_queue);
|
||||
|
||||
if (config->failed) {
|
||||
sway_log(L_ERROR, "Programs have been execd, aborting!");
|
||||
sway_abort("Unable to load config");
|
||||
}
|
||||
|
||||
config->active = true;
|
||||
}
|
||||
|
||||
|
||||
struct wlc_interface interface = {
|
||||
.output = {
|
||||
|
@ -185,6 +203,9 @@ struct wlc_interface interface = {
|
|||
.pointer = {
|
||||
.motion = handle_pointer_motion,
|
||||
.button = handle_pointer_button
|
||||
},
|
||||
.compositor = {
|
||||
.ready = handle_wlc_ready
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ int main(int argc, char **argv) {
|
|||
/* Signal handling */
|
||||
signal(SIGCHLD, sigchld_handle);
|
||||
|
||||
if (!load_config()) {
|
||||
sway_log(L_ERROR, "Config load failed, aborting sway post init!");
|
||||
}
|
||||
|
||||
setenv("WLC_DIM", "0", 0);
|
||||
if (!wlc_init(&interface, argc, argv)) {
|
||||
|
@ -25,11 +28,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
setenv("DISPLAY", ":1", 1);
|
||||
|
||||
if (!load_config()) {
|
||||
sway_abort("Unable to load config");
|
||||
}
|
||||
|
||||
wlc_run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,56 @@
|
|||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "container.h"
|
||||
#include "config.h"
|
||||
#include "stringop.h"
|
||||
|
||||
swayc_t *active_workspace = NULL;
|
||||
|
||||
int ws_num = 1;
|
||||
|
||||
char *workspace_next_name(void) {
|
||||
sway_log(L_DEBUG, "Workspace: Generating new name");
|
||||
int i;
|
||||
int l = 1;
|
||||
// Scan all workspace bindings to find the next available workspace name,
|
||||
// if none are found/available then default to a number
|
||||
struct sway_mode *mode = config->current_mode;
|
||||
|
||||
for (i = 0; i < mode->bindings->length; ++i) {
|
||||
struct sway_binding *binding = mode->bindings->items[i];
|
||||
const char* command = binding->command;
|
||||
list_t *args = split_string(command, " ");
|
||||
|
||||
if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) {
|
||||
sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]);
|
||||
char* target = malloc(strlen(args->items[1]) + 1);
|
||||
strcpy(target, args->items[1]);
|
||||
while (*target == ' ' || *target == '\t')
|
||||
target++;
|
||||
|
||||
// Make sure that the command references an actual workspace
|
||||
// not a command about workspaces
|
||||
if (strcmp(target, "next") == 0 ||
|
||||
strcmp(target, "prev") == 0 ||
|
||||
strcmp(target, "next_on_output") == 0 ||
|
||||
strcmp(target, "prev_on_output") == 0 ||
|
||||
strcmp(target, "number") == 0 ||
|
||||
strcmp(target, "back_and_forth") == 0 ||
|
||||
strcmp(target, "current") == 0)
|
||||
continue;
|
||||
|
||||
//Make sure that the workspace doesn't already exist
|
||||
if (workspace_find_by_name(target)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list_free(args);
|
||||
|
||||
sway_log(L_DEBUG, "Workspace: Found free name %s", target);
|
||||
return target;
|
||||
}
|
||||
}
|
||||
// As a fall back, get the current number of active workspaces
|
||||
// and return that + 1 for the next workspace's name
|
||||
int ws_num = root_container.children->length;
|
||||
if (ws_num >= 10) {
|
||||
l = 2;
|
||||
} else if (ws_num >= 100) {
|
||||
|
|
Loading…
Reference in a new issue