2015-08-05 03:30:40 +02:00
|
|
|
#include <stdio.h>
|
2015-08-05 23:30:40 +02:00
|
|
|
#include <stdbool.h>
|
2015-08-05 03:30:40 +02:00
|
|
|
#include <stdlib.h>
|
2015-08-16 02:51:23 +02:00
|
|
|
#include <unistd.h>
|
2016-03-26 12:31:53 +01:00
|
|
|
#include <libgen.h>
|
2015-11-28 16:00:53 +01:00
|
|
|
#include <wordexp.h>
|
2015-12-18 17:43:03 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2016-03-26 17:11:18 +01:00
|
|
|
#include <sys/stat.h>
|
2015-12-18 17:43:03 +01:00
|
|
|
#include <signal.h>
|
2016-01-17 11:53:37 +01:00
|
|
|
#include <libinput.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <float.h>
|
2015-11-29 23:02:09 +01:00
|
|
|
#include "wayland-desktop-shell-server-protocol.h"
|
2016-09-01 14:18:37 +02:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/layout.h"
|
|
|
|
#include "sway/input_state.h"
|
|
|
|
#include "sway/criteria.h"
|
|
|
|
#include "sway/input.h"
|
|
|
|
#include "sway/border.h"
|
2015-08-05 03:30:40 +02:00
|
|
|
#include "readline.h"
|
|
|
|
#include "stringop.h"
|
|
|
|
#include "list.h"
|
2015-08-09 01:24:18 +02:00
|
|
|
#include "log.h"
|
2015-08-05 03:30:40 +02:00
|
|
|
|
2015-09-07 08:22:02 +02:00
|
|
|
struct sway_config *config = NULL;
|
2015-08-11 02:50:22 +02:00
|
|
|
|
2016-02-23 14:25:09 +01:00
|
|
|
static void terminate_swaybar(pid_t pid);
|
|
|
|
|
2015-09-07 15:52:27 +02:00
|
|
|
static void free_variable(struct sway_variable *var) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!var) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-07 15:52:27 +02:00
|
|
|
free(var->name);
|
|
|
|
free(var->value);
|
|
|
|
free(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_binding(struct sway_binding *bind) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!bind) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-07 15:52:27 +02:00
|
|
|
free_flat_list(bind->keys);
|
|
|
|
free(bind->command);
|
|
|
|
free(bind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_mode(struct sway_mode *mode) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!mode) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-07 15:52:27 +02:00
|
|
|
free(mode->name);
|
|
|
|
int i;
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; mode->bindings && i < mode->bindings->length; ++i) {
|
2015-09-07 15:52:27 +02:00
|
|
|
free_binding(mode->bindings->items[i]);
|
|
|
|
}
|
|
|
|
list_free(mode->bindings);
|
|
|
|
free(mode);
|
|
|
|
}
|
|
|
|
|
2015-12-14 02:39:24 +01:00
|
|
|
static void free_bar(struct bar_config *bar) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!bar) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-14 02:39:24 +01:00
|
|
|
free(bar->mode);
|
|
|
|
free(bar->hidden_state);
|
|
|
|
free(bar->status_command);
|
|
|
|
free(bar->font);
|
2015-12-16 12:58:45 +01:00
|
|
|
free(bar->separator_symbol);
|
2015-12-15 01:47:10 +01:00
|
|
|
int i;
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; bar->bindings && i < bar->bindings->length; ++i) {
|
2015-12-15 01:47:10 +01:00
|
|
|
free_sway_mouse_binding(bar->bindings->items[i]);
|
|
|
|
}
|
2015-12-15 22:16:54 +01:00
|
|
|
list_free(bar->bindings);
|
2015-12-15 21:55:20 +01:00
|
|
|
|
2015-12-20 10:11:11 +01:00
|
|
|
if (bar->outputs) {
|
|
|
|
free_flat_list(bar->outputs);
|
|
|
|
}
|
2016-02-23 14:25:09 +01:00
|
|
|
|
|
|
|
if (bar->pid != 0) {
|
|
|
|
terminate_swaybar(bar->pid);
|
|
|
|
}
|
|
|
|
|
2016-11-02 21:07:04 +01:00
|
|
|
free(bar->colors.background);
|
|
|
|
free(bar->colors.statusline);
|
|
|
|
free(bar->colors.separator);
|
|
|
|
free(bar->colors.focused_background);
|
|
|
|
free(bar->colors.focused_statusline);
|
|
|
|
free(bar->colors.focused_separator);
|
|
|
|
free(bar->colors.focused_workspace_border);
|
|
|
|
free(bar->colors.focused_workspace_bg);
|
|
|
|
free(bar->colors.focused_workspace_text);
|
|
|
|
free(bar->colors.active_workspace_border);
|
|
|
|
free(bar->colors.active_workspace_bg);
|
|
|
|
free(bar->colors.active_workspace_text);
|
|
|
|
free(bar->colors.inactive_workspace_border);
|
|
|
|
free(bar->colors.inactive_workspace_bg);
|
|
|
|
free(bar->colors.inactive_workspace_text);
|
|
|
|
free(bar->colors.urgent_workspace_border);
|
|
|
|
free(bar->colors.urgent_workspace_bg);
|
|
|
|
free(bar->colors.urgent_workspace_text);
|
|
|
|
free(bar->colors.binding_mode_border);
|
|
|
|
free(bar->colors.binding_mode_bg);
|
|
|
|
free(bar->colors.binding_mode_text);
|
|
|
|
|
2015-12-14 02:39:24 +01:00
|
|
|
free(bar);
|
|
|
|
}
|
|
|
|
|
2016-01-17 11:53:37 +01:00
|
|
|
void free_input_config(struct input_config *ic) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!ic) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-17 11:53:37 +01:00
|
|
|
free(ic->identifier);
|
|
|
|
free(ic);
|
|
|
|
}
|
|
|
|
|
2015-11-16 11:40:24 +01:00
|
|
|
void free_output_config(struct output_config *oc) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!oc) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-07 15:52:27 +02:00
|
|
|
free(oc->name);
|
|
|
|
free(oc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_workspace_output(struct workspace_output *wo) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!wo) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-07 15:52:27 +02:00
|
|
|
free(wo->output);
|
|
|
|
free(wo->workspace);
|
|
|
|
free(wo);
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:43:34 +02:00
|
|
|
static void pid_workspace_cleanup() {
|
|
|
|
struct timespec ts;
|
|
|
|
struct pid_workspace *pw = NULL;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
|
|
|
|
// work backwards through list and remove any entries
|
|
|
|
// older than PID_WORKSPACE_TIMEOUT
|
|
|
|
for (int i = config->pid_workspaces->length - 1; i > -1; i--) {
|
|
|
|
pw = config->pid_workspaces->items[i];
|
|
|
|
|
|
|
|
if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) {
|
2016-06-11 22:29:04 +02:00
|
|
|
free_pid_workspace(config->pid_workspaces->items[i]);
|
2016-06-11 19:43:34 +02:00
|
|
|
list_del(config->pid_workspaces, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// de-dupe pid_workspaces to ensure pid uniqueness
|
|
|
|
void pid_workspace_add(struct pid_workspace *pw) {
|
|
|
|
struct pid_workspace *list_pw = NULL;
|
|
|
|
struct timespec ts;
|
|
|
|
time_t *now = malloc(sizeof(time_t));
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!now) {
|
|
|
|
sway_log(L_ERROR, "Allocating time for pid_workspace failed");
|
|
|
|
return;
|
|
|
|
}
|
2016-06-11 19:43:34 +02:00
|
|
|
|
|
|
|
pid_workspace_cleanup();
|
|
|
|
|
|
|
|
// add current time to pw
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
*now = ts.tv_sec;
|
|
|
|
|
|
|
|
pw->time_added = now;
|
|
|
|
|
|
|
|
// work backwards through list and delete any entries that
|
|
|
|
// have the same pid as that in our new pid_workspace
|
|
|
|
for (int i = config->pid_workspaces->length - 1; i > -1; i--) {
|
|
|
|
list_pw = config->pid_workspaces->items[i];
|
|
|
|
|
|
|
|
if (pw->pid == list_pw->pid) {
|
2016-06-11 22:29:04 +02:00
|
|
|
free_pid_workspace(config->pid_workspaces->items[i]);
|
2016-06-11 19:43:34 +02:00
|
|
|
list_del(config->pid_workspaces, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add(config->pid_workspaces, pw);
|
|
|
|
}
|
|
|
|
|
2016-06-06 13:58:53 +02:00
|
|
|
void free_pid_workspace(struct pid_workspace *pw) {
|
|
|
|
if (!pw) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(pw->pid);
|
|
|
|
free(pw->workspace);
|
2016-06-11 19:43:34 +02:00
|
|
|
free(pw->time_added);
|
2016-06-06 13:58:53 +02:00
|
|
|
free(pw);
|
|
|
|
}
|
|
|
|
|
2016-12-02 01:38:36 +01:00
|
|
|
void free_command_policy(struct command_policy *policy) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!policy) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-02 01:38:36 +01:00
|
|
|
free(policy->command);
|
|
|
|
free(policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_feature_policy(struct feature_policy *policy) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!policy) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-02 01:38:36 +01:00
|
|
|
free(policy->program);
|
|
|
|
free(policy);
|
|
|
|
}
|
|
|
|
|
2016-02-24 18:53:09 +01:00
|
|
|
void free_config(struct sway_config *config) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!config) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-07 23:29:40 +02:00
|
|
|
int i;
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->symbols && i < config->symbols->length; ++i) {
|
2015-09-07 23:29:40 +02:00
|
|
|
free_variable(config->symbols->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->symbols);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->modes && i < config->modes->length; ++i) {
|
2015-09-07 23:29:40 +02:00
|
|
|
free_mode(config->modes->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->modes);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->bars && i < config->bars->length; ++i) {
|
2015-12-14 02:39:24 +01:00
|
|
|
free_bar(config->bars->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->bars);
|
|
|
|
|
2015-09-07 23:29:40 +02:00
|
|
|
free_flat_list(config->cmd_queue);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->workspace_outputs && i < config->workspace_outputs->length; ++i) {
|
2015-09-07 23:29:40 +02:00
|
|
|
free_workspace_output(config->workspace_outputs->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->workspace_outputs);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->pid_workspaces && i < config->pid_workspaces->length; ++i) {
|
2016-06-06 13:58:53 +02:00
|
|
|
free_pid_workspace(config->pid_workspaces->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->pid_workspaces);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->criteria && i < config->criteria->length; ++i) {
|
2015-11-17 19:27:01 +01:00
|
|
|
free_criteria(config->criteria->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->criteria);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->input_configs && i < config->input_configs->length; ++i) {
|
2016-01-17 11:53:37 +01:00
|
|
|
free_input_config(config->input_configs->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->input_configs);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->output_configs && i < config->output_configs->length; ++i) {
|
2015-09-08 14:37:20 +02:00
|
|
|
free_output_config(config->output_configs->items[i]);
|
2015-09-07 23:29:40 +02:00
|
|
|
}
|
|
|
|
list_free(config->output_configs);
|
2016-01-05 23:18:59 +01:00
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->command_policies && i < config->command_policies->length; ++i) {
|
2016-12-02 01:38:36 +01:00
|
|
|
free_command_policy(config->command_policies->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->command_policies);
|
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
for (i = 0; config->feature_policies && i < config->feature_policies->length; ++i) {
|
2016-12-02 01:38:36 +01:00
|
|
|
free_feature_policy(config->feature_policies->items[i]);
|
|
|
|
}
|
|
|
|
list_free(config->feature_policies);
|
|
|
|
|
2016-01-05 23:18:59 +01:00
|
|
|
list_free(config->active_bar_modifiers);
|
2016-03-26 12:31:53 +01:00
|
|
|
free_flat_list(config->config_chain);
|
2016-01-27 06:57:55 +01:00
|
|
|
free(config->font);
|
2016-05-08 16:17:35 +02:00
|
|
|
free(config->floating_scroll_up_cmd);
|
|
|
|
free(config->floating_scroll_down_cmd);
|
2016-05-14 22:42:02 +02:00
|
|
|
free(config->floating_scroll_left_cmd);
|
|
|
|
free(config->floating_scroll_right_cmd);
|
2015-09-07 23:29:40 +02:00
|
|
|
free(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-07 07:48:43 +02:00
|
|
|
static bool file_exists(const char *path) {
|
2016-12-15 23:52:53 +01:00
|
|
|
return path && access(path, R_OK) != -1;
|
2015-08-16 02:51:23 +02:00
|
|
|
}
|
|
|
|
|
2015-09-07 07:48:43 +02:00
|
|
|
static void config_defaults(struct sway_config *config) {
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->symbols = create_list())) goto cleanup;
|
|
|
|
if (!(config->modes = create_list())) goto cleanup;
|
|
|
|
if (!(config->bars = create_list())) goto cleanup;
|
|
|
|
if (!(config->workspace_outputs = create_list())) goto cleanup;
|
|
|
|
if (!(config->pid_workspaces = create_list())) goto cleanup;
|
|
|
|
if (!(config->criteria = create_list())) goto cleanup;
|
|
|
|
if (!(config->input_configs = create_list())) goto cleanup;
|
|
|
|
if (!(config->output_configs = create_list())) goto cleanup;
|
|
|
|
|
|
|
|
if (!(config->cmd_queue = create_list())) goto cleanup;
|
|
|
|
|
|
|
|
if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup;
|
|
|
|
if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup;
|
2015-09-07 23:29:40 +02:00
|
|
|
strcpy(config->current_mode->name, "default");
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->current_mode->bindings = create_list())) goto cleanup;
|
2015-08-19 13:50:27 +02:00
|
|
|
list_add(config->modes, config->current_mode);
|
2015-09-07 07:48:43 +02:00
|
|
|
|
2015-08-28 23:45:40 +02:00
|
|
|
config->floating_mod = 0;
|
2015-12-11 11:39:24 +01:00
|
|
|
config->dragging_key = M_LEFT_CLICK;
|
|
|
|
config->resizing_key = M_RIGHT_CLICK;
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->floating_scroll_up_cmd = strdup(""))) goto cleanup;
|
|
|
|
if (!(config->floating_scroll_down_cmd = strdup(""))) goto cleanup;
|
|
|
|
if (!(config->floating_scroll_left_cmd = strdup(""))) goto cleanup;
|
|
|
|
if (!(config->floating_scroll_right_cmd = strdup(""))) goto cleanup;
|
2015-08-28 04:52:59 +02:00
|
|
|
config->default_layout = L_NONE;
|
|
|
|
config->default_orientation = L_NONE;
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->font = strdup("monospace 10"))) goto cleanup;
|
2016-03-29 14:47:30 +02:00
|
|
|
config->font_height = get_font_text_height(config->font);
|
2016-01-27 06:57:55 +01:00
|
|
|
|
2016-05-31 14:59:33 +02:00
|
|
|
// floating view
|
2016-06-02 17:35:02 +02:00
|
|
|
config->floating_maximum_width = 0;
|
|
|
|
config->floating_maximum_height = 0;
|
2016-05-31 14:59:33 +02:00
|
|
|
config->floating_minimum_width = 75;
|
|
|
|
config->floating_minimum_height = 50;
|
|
|
|
|
2015-08-19 13:50:27 +02:00
|
|
|
// Flags
|
|
|
|
config->focus_follows_mouse = true;
|
|
|
|
config->mouse_warping = true;
|
|
|
|
config->reloading = false;
|
|
|
|
config->active = false;
|
|
|
|
config->failed = false;
|
2015-08-31 04:34:10 +02:00
|
|
|
config->auto_back_and_forth = false;
|
2015-10-22 01:34:32 +02:00
|
|
|
config->seamless_mouse = true;
|
2015-09-10 20:07:40 +02:00
|
|
|
config->reading = false;
|
2015-08-28 23:45:40 +02:00
|
|
|
|
2015-11-12 14:02:39 +01:00
|
|
|
config->edge_gaps = true;
|
2016-03-20 12:29:47 +01:00
|
|
|
config->smart_gaps = false;
|
2015-08-19 13:50:27 +02:00
|
|
|
config->gaps_inner = 0;
|
|
|
|
config->gaps_outer = 0;
|
2016-01-05 23:18:59 +01:00
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->active_bar_modifiers = create_list())) goto cleanup;
|
2016-03-26 12:31:53 +01:00
|
|
|
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->config_chain = create_list())) goto cleanup;
|
2016-03-26 12:31:53 +01:00
|
|
|
config->current_config = NULL;
|
2016-03-28 15:16:55 +02:00
|
|
|
|
2016-03-29 14:40:25 +02:00
|
|
|
// borders
|
|
|
|
config->border = B_NORMAL;
|
2016-03-31 12:17:21 +02:00
|
|
|
config->floating_border = B_NORMAL;
|
2016-03-29 14:40:25 +02:00
|
|
|
config->border_thickness = 2;
|
2016-03-31 12:17:21 +02:00
|
|
|
config->floating_border_thickness = 2;
|
2016-03-29 13:49:28 +02:00
|
|
|
config->hide_edge_borders = E_NONE;
|
|
|
|
|
2016-03-28 15:16:55 +02:00
|
|
|
// border colors
|
|
|
|
config->border_colors.focused.border = 0x4C7899FF;
|
|
|
|
config->border_colors.focused.background = 0x285577FF;
|
|
|
|
config->border_colors.focused.text = 0xFFFFFFFF;
|
|
|
|
config->border_colors.focused.indicator = 0x2E9EF4FF;
|
|
|
|
config->border_colors.focused.child_border = 0x285577FF;
|
|
|
|
|
|
|
|
config->border_colors.focused_inactive.border = 0x333333FF;
|
|
|
|
config->border_colors.focused_inactive.background = 0x5F676AFF;
|
|
|
|
config->border_colors.focused_inactive.text = 0xFFFFFFFF;
|
|
|
|
config->border_colors.focused_inactive.indicator = 0x484E50FF;
|
|
|
|
config->border_colors.focused_inactive.child_border = 0x5F676AFF;
|
|
|
|
|
|
|
|
config->border_colors.unfocused.border = 0x333333FF;
|
|
|
|
config->border_colors.unfocused.background = 0x222222FF;
|
|
|
|
config->border_colors.unfocused.text = 0x888888FF;
|
|
|
|
config->border_colors.unfocused.indicator = 0x292D2EFF;
|
|
|
|
config->border_colors.unfocused.child_border = 0x222222FF;
|
|
|
|
|
|
|
|
config->border_colors.urgent.border = 0x2F343AFF;
|
|
|
|
config->border_colors.urgent.background = 0x900000FF;
|
|
|
|
config->border_colors.urgent.text = 0xFFFFFFFF;
|
|
|
|
config->border_colors.urgent.indicator = 0x900000FF;
|
|
|
|
config->border_colors.urgent.child_border = 0x900000FF;
|
|
|
|
|
|
|
|
config->border_colors.placeholder.border = 0x000000FF;
|
|
|
|
config->border_colors.placeholder.background = 0x0C0C0CFF;
|
|
|
|
config->border_colors.placeholder.text = 0xFFFFFFFF;
|
|
|
|
config->border_colors.placeholder.indicator = 0x000000FF;
|
|
|
|
config->border_colors.placeholder.child_border = 0x0C0C0CFF;
|
|
|
|
|
|
|
|
config->border_colors.background = 0xFFFFFFFF;
|
2016-12-02 01:38:36 +01:00
|
|
|
|
|
|
|
// Security
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(config->command_policies = create_list())) goto cleanup;
|
|
|
|
if (!(config->feature_policies = create_list())) goto cleanup;
|
2016-12-02 22:08:45 +01:00
|
|
|
config->ipc_policy = UINT32_MAX;
|
2016-12-15 23:52:53 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
cleanup:
|
|
|
|
sway_abort("Unable to allocate config structures");
|
2016-01-05 23:18:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_modifiers(const void *left, const void *right) {
|
|
|
|
uint32_t a = *(uint32_t *)left;
|
|
|
|
uint32_t b = *(uint32_t *)right;
|
|
|
|
|
|
|
|
return a - b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_active_bar_modifiers() {
|
|
|
|
if (config->active_bar_modifiers->length > 0) {
|
|
|
|
list_free(config->active_bar_modifiers);
|
|
|
|
config->active_bar_modifiers = create_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bar_config *bar;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < config->bars->length; ++i) {
|
|
|
|
bar = config->bars->items[i];
|
|
|
|
if (strcmp(bar->mode, "hide") == 0 && strcmp(bar->hidden_state, "hide") == 0) {
|
|
|
|
if (list_seq_find(config->active_bar_modifiers, compare_modifiers, &bar->modifier) < 0) {
|
|
|
|
list_add(config->active_bar_modifiers, &bar->modifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-19 13:50:27 +02:00
|
|
|
}
|
2015-08-16 02:51:23 +02:00
|
|
|
|
2015-09-07 07:48:43 +02:00
|
|
|
static char *get_config_path(void) {
|
2015-11-28 16:00:53 +01:00
|
|
|
static const char *config_paths[] = {
|
|
|
|
"$HOME/.sway/config",
|
|
|
|
"$XDG_CONFIG_HOME/sway/config",
|
|
|
|
"$HOME/.i3/config",
|
|
|
|
"$XDG_CONFIG_HOME/i3/config",
|
2016-01-21 21:04:52 +01:00
|
|
|
SYSCONFDIR "/sway/config",
|
|
|
|
SYSCONFDIR "/i3/config",
|
2015-09-07 07:48:43 +02:00
|
|
|
};
|
2015-11-28 16:00:53 +01:00
|
|
|
|
|
|
|
if (!getenv("XDG_CONFIG_HOME")) {
|
|
|
|
char *home = getenv("HOME");
|
2015-12-11 20:22:28 +01:00
|
|
|
char *config_home = malloc(strlen(home) + strlen("/.config") + 1);
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!config_home) {
|
|
|
|
sway_log(L_ERROR, "Unable to allocate $HOME/.config");
|
|
|
|
} else {
|
|
|
|
strcpy(config_home, home);
|
|
|
|
strcat(config_home, "/.config");
|
|
|
|
setenv("XDG_CONFIG_HOME", config_home, 1);
|
|
|
|
sway_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
|
|
|
|
free(config_home);
|
|
|
|
}
|
2015-08-16 03:03:33 +02:00
|
|
|
}
|
|
|
|
|
2015-11-28 16:00:53 +01:00
|
|
|
wordexp_t p;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (int)(sizeof(config_paths) / sizeof(char *)); ++i) {
|
|
|
|
if (wordexp(config_paths[i], &p, 0) == 0) {
|
2016-04-29 19:07:38 +02:00
|
|
|
path = strdup(p.we_wordv[0]);
|
2016-04-29 19:36:29 +02:00
|
|
|
wordfree(&p);
|
2015-11-28 16:00:53 +01:00
|
|
|
if (file_exists(path)) {
|
|
|
|
return path;
|
2015-08-16 03:03:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 16:00:53 +01:00
|
|
|
return NULL; // Not reached
|
2015-08-16 02:51:23 +02:00
|
|
|
}
|
|
|
|
|
2016-12-17 21:19:50 +01:00
|
|
|
const char *current_config_path;
|
|
|
|
|
2016-03-26 12:31:53 +01:00
|
|
|
static bool load_config(const char *path, struct sway_config *config) {
|
2015-11-28 16:00:53 +01:00
|
|
|
sway_log(L_INFO, "Loading config from %s", path);
|
2016-12-17 21:19:50 +01:00
|
|
|
current_config_path = path;
|
2015-11-28 16:00:53 +01:00
|
|
|
|
2016-03-26 17:11:18 +01:00
|
|
|
struct stat sb;
|
|
|
|
if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-16 02:51:23 +02:00
|
|
|
if (path == NULL) {
|
|
|
|
sway_log(L_ERROR, "Unable to find a config file!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *f = fopen(path, "r");
|
2015-08-10 21:22:22 +02:00
|
|
|
if (!f) {
|
2016-03-24 22:13:42 +01:00
|
|
|
sway_log(L_ERROR, "Unable to open %s for reading", path);
|
2015-08-10 21:22:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-13 21:41:29 +02:00
|
|
|
|
2016-03-26 12:31:53 +01:00
|
|
|
bool config_load_success = read_config(f, config);
|
2015-08-10 21:22:22 +02:00
|
|
|
fclose(f);
|
2015-08-13 21:41:29 +02:00
|
|
|
|
2016-03-24 22:13:42 +01:00
|
|
|
if (!config_load_success) {
|
|
|
|
sway_log(L_ERROR, "Error(s) loading config!");
|
|
|
|
}
|
|
|
|
|
2016-12-17 21:19:50 +01:00
|
|
|
current_config_path = NULL;
|
2016-03-24 22:13:42 +01:00
|
|
|
return true;
|
2015-08-10 21:22:22 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 12:31:53 +01:00
|
|
|
bool load_main_config(const char *file, bool is_active) {
|
|
|
|
input_init();
|
|
|
|
|
|
|
|
char *path;
|
|
|
|
if (file != NULL) {
|
|
|
|
path = strdup(file);
|
|
|
|
} else {
|
|
|
|
path = get_config_path();
|
|
|
|
}
|
|
|
|
|
2015-09-07 23:29:40 +02:00
|
|
|
struct sway_config *old_config = config;
|
2015-11-29 23:02:09 +01:00
|
|
|
config = calloc(1, sizeof(struct sway_config));
|
2016-12-16 00:26:53 +01:00
|
|
|
if (!config) {
|
|
|
|
sway_abort("Unable to allocate config");
|
|
|
|
}
|
2015-09-07 23:29:40 +02:00
|
|
|
|
|
|
|
config_defaults(config);
|
2015-08-10 21:09:51 +02:00
|
|
|
if (is_active) {
|
2015-08-13 21:41:29 +02:00
|
|
|
sway_log(L_DEBUG, "Performing configuration file reload");
|
2015-09-07 23:29:40 +02:00
|
|
|
config->reloading = true;
|
|
|
|
config->active = true;
|
2015-08-10 21:09:51 +02:00
|
|
|
}
|
2016-03-26 12:31:53 +01:00
|
|
|
|
|
|
|
config->current_config = path;
|
|
|
|
list_add(config->config_chain, path);
|
|
|
|
|
|
|
|
config->reading = true;
|
2016-12-17 21:19:50 +01:00
|
|
|
bool success = load_config(SYSCONFDIR "/sway/security", config);
|
|
|
|
success = success && load_config(path, config);
|
2016-03-26 12:31:53 +01:00
|
|
|
|
|
|
|
if (is_active) {
|
|
|
|
config->reloading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_config) {
|
|
|
|
free_config(old_config);
|
|
|
|
}
|
|
|
|
config->reading = false;
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
update_active_bar_modifiers();
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool load_include_config(const char *path, const char *parent_dir, struct sway_config *config) {
|
|
|
|
// save parent config
|
|
|
|
const char *parent_config = config->current_config;
|
|
|
|
|
|
|
|
char *full_path = strdup(path);
|
|
|
|
int len = strlen(path);
|
|
|
|
if (len >= 1 && path[0] != '/') {
|
|
|
|
len = len + strlen(parent_dir) + 2;
|
|
|
|
full_path = malloc(len * sizeof(char));
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!full_path) {
|
|
|
|
sway_log(L_ERROR, "Unable to allocate full path to included config");
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-26 12:31:53 +01:00
|
|
|
snprintf(full_path, len, "%s/%s", parent_dir, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *real_path = realpath(full_path, NULL);
|
|
|
|
free(full_path);
|
|
|
|
|
2016-06-06 22:20:27 +02:00
|
|
|
if (real_path == NULL) {
|
|
|
|
sway_log(L_DEBUG, "%s not found.", path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-26 12:31:53 +01:00
|
|
|
// check if config has already been included
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < config->config_chain->length; ++j) {
|
|
|
|
char *old_path = config->config_chain->items[j];
|
|
|
|
if (strcmp(real_path, old_path) == 0) {
|
|
|
|
sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path);
|
|
|
|
free(real_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config->current_config = real_path;
|
|
|
|
list_add(config->config_chain, real_path);
|
|
|
|
int index = config->config_chain->length - 1;
|
|
|
|
|
|
|
|
if (!load_config(real_path, config)) {
|
|
|
|
free(real_path);
|
|
|
|
config->current_config = parent_config;
|
|
|
|
list_del(config->config_chain, index);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore current_config
|
|
|
|
config->current_config = parent_config;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool load_include_configs(const char *path, struct sway_config *config) {
|
|
|
|
char *wd = getcwd(NULL, 0);
|
|
|
|
char *parent_path = strdup(config->current_config);
|
|
|
|
const char *parent_dir = dirname(parent_path);
|
|
|
|
|
|
|
|
if (chdir(parent_dir) < 0) {
|
|
|
|
free(parent_path);
|
|
|
|
free(wd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wordexp_t p;
|
|
|
|
|
|
|
|
if (wordexp(path, &p, 0) < 0) {
|
|
|
|
free(parent_path);
|
|
|
|
free(wd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char **w = p.we_wordv;
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < p.we_wordc; ++i) {
|
|
|
|
load_include_config(w[i], parent_dir, config);
|
|
|
|
}
|
|
|
|
free(parent_path);
|
|
|
|
wordfree(&p);
|
|
|
|
|
|
|
|
// restore wd
|
|
|
|
if (chdir(wd) < 0) {
|
|
|
|
free(wd);
|
|
|
|
sway_log(L_ERROR, "failed to restore working directory");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(wd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool read_config(FILE *file, struct sway_config *config) {
|
2015-08-06 04:10:56 +02:00
|
|
|
bool success = true;
|
2015-09-15 04:59:25 +02:00
|
|
|
enum cmd_status block = CMD_BLOCK_END;
|
2015-08-06 04:10:56 +02:00
|
|
|
|
2015-11-25 14:45:50 +01:00
|
|
|
int line_number = 0;
|
2015-09-07 23:29:40 +02:00
|
|
|
char *line;
|
2015-08-05 03:30:40 +02:00
|
|
|
while (!feof(file)) {
|
2015-09-07 23:29:40 +02:00
|
|
|
line = read_line(file);
|
2016-12-15 23:08:56 +01:00
|
|
|
if (!line) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-25 14:45:50 +01:00
|
|
|
line_number++;
|
2015-11-29 20:02:58 +01:00
|
|
|
line = strip_whitespace(line);
|
|
|
|
if (line[0] == '#') {
|
2016-01-21 17:18:13 +01:00
|
|
|
free(line);
|
2015-11-29 20:02:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-12-02 14:10:03 +01:00
|
|
|
struct cmd_results *res;
|
|
|
|
if (block == CMD_BLOCK_COMMANDS) {
|
|
|
|
// Special case
|
|
|
|
res = config_commands_command(line);
|
|
|
|
} else {
|
|
|
|
res = config_command(line, block);
|
|
|
|
}
|
2015-10-22 14:14:13 +02:00
|
|
|
switch(res->status) {
|
2015-09-15 04:59:25 +02:00
|
|
|
case CMD_FAILURE:
|
|
|
|
case CMD_INVALID:
|
2016-03-26 16:50:47 +01:00
|
|
|
sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, line,
|
|
|
|
res->error, config->current_config);
|
2015-09-08 19:27:09 +02:00
|
|
|
success = false;
|
2015-09-15 04:59:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_DEFER:
|
|
|
|
sway_log(L_DEBUG, "Defferring command `%s'", line);
|
|
|
|
list_add(config->cmd_queue, strdup(line));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_BLOCK_MODE:
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_MODE;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-01-17 11:53:37 +01:00
|
|
|
case CMD_BLOCK_INPUT:
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_INPUT;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-12-14 02:39:24 +01:00
|
|
|
case CMD_BLOCK_BAR:
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_BAR;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-12-15 13:12:08 +01:00
|
|
|
case CMD_BLOCK_BAR_COLORS:
|
|
|
|
if (block == CMD_BLOCK_BAR) {
|
|
|
|
block = CMD_BLOCK_BAR_COLORS;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-12-02 14:10:03 +01:00
|
|
|
case CMD_BLOCK_COMMANDS:
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_COMMANDS;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-12-02 23:34:26 +01:00
|
|
|
case CMD_BLOCK_IPC:
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_IPC;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_BLOCK_IPC_EVENTS:
|
|
|
|
if (block == CMD_BLOCK_IPC) {
|
|
|
|
block = CMD_BLOCK_IPC_EVENTS;
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-09-15 04:59:25 +02:00
|
|
|
case CMD_BLOCK_END:
|
|
|
|
switch(block) {
|
|
|
|
case CMD_BLOCK_MODE:
|
|
|
|
sway_log(L_DEBUG, "End of mode block");
|
|
|
|
config->current_mode = config->modes->items[0];
|
2015-12-14 02:39:24 +01:00
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
|
2016-01-17 11:53:37 +01:00
|
|
|
case CMD_BLOCK_INPUT:
|
|
|
|
sway_log(L_DEBUG, "End of input block");
|
|
|
|
current_input_config = NULL;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
|
2015-12-14 02:39:24 +01:00
|
|
|
case CMD_BLOCK_BAR:
|
|
|
|
sway_log(L_DEBUG, "End of bar block");
|
|
|
|
config->current_bar = NULL;
|
|
|
|
block = CMD_BLOCK_END;
|
2015-09-15 04:59:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-12-15 13:12:08 +01:00
|
|
|
case CMD_BLOCK_BAR_COLORS:
|
|
|
|
sway_log(L_DEBUG, "End of bar colors block");
|
|
|
|
block = CMD_BLOCK_BAR;
|
|
|
|
break;
|
|
|
|
|
2016-12-02 14:10:03 +01:00
|
|
|
case CMD_BLOCK_COMMANDS:
|
|
|
|
sway_log(L_DEBUG, "End of commands block");
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
|
2016-12-02 23:34:26 +01:00
|
|
|
case CMD_BLOCK_IPC:
|
|
|
|
sway_log(L_DEBUG, "End of IPC block");
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_BLOCK_IPC_EVENTS:
|
|
|
|
sway_log(L_DEBUG, "End of IPC events block");
|
|
|
|
block = CMD_BLOCK_IPC;
|
|
|
|
break;
|
|
|
|
|
2015-09-15 04:59:25 +02:00
|
|
|
case CMD_BLOCK_END:
|
|
|
|
sway_log(L_ERROR, "Unmatched }");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
default:;
|
2015-08-16 02:51:23 +02:00
|
|
|
}
|
2015-08-05 03:30:40 +02:00
|
|
|
free(line);
|
2016-04-29 19:31:21 +02:00
|
|
|
free_cmd_results(res);
|
2015-08-05 03:30:40 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 21:41:29 +02:00
|
|
|
return success;
|
2015-08-05 03:30:40 +02:00
|
|
|
}
|
2015-08-06 04:40:38 +02:00
|
|
|
|
2016-01-17 11:53:37 +01:00
|
|
|
int input_identifier_cmp(const void *item, const void *data) {
|
|
|
|
const struct input_config *ic = item;
|
|
|
|
const char *identifier = data;
|
|
|
|
return strcmp(ic->identifier, identifier);
|
|
|
|
}
|
|
|
|
|
2015-11-29 20:02:58 +01:00
|
|
|
int output_name_cmp(const void *item, const void *data) {
|
2015-11-29 13:51:42 +01:00
|
|
|
const struct output_config *output = item;
|
|
|
|
const char *name = data;
|
|
|
|
|
|
|
|
return strcmp(output->name, name);
|
|
|
|
}
|
|
|
|
|
2016-01-17 11:53:37 +01:00
|
|
|
void merge_input_config(struct input_config *dst, struct input_config *src) {
|
|
|
|
if (src->identifier) {
|
|
|
|
if (dst->identifier) {
|
|
|
|
free(dst->identifier);
|
|
|
|
}
|
|
|
|
dst->identifier = strdup(src->identifier);
|
|
|
|
}
|
2016-05-01 12:02:44 +02:00
|
|
|
if (src->accel_profile != INT_MIN) {
|
|
|
|
dst->accel_profile = src->accel_profile;
|
|
|
|
}
|
2016-01-17 11:53:37 +01:00
|
|
|
if (src->click_method != INT_MIN) {
|
|
|
|
dst->click_method = src->click_method;
|
|
|
|
}
|
|
|
|
if (src->drag_lock != INT_MIN) {
|
|
|
|
dst->drag_lock = src->drag_lock;
|
|
|
|
}
|
|
|
|
if (src->dwt != INT_MIN) {
|
|
|
|
dst->dwt = src->dwt;
|
|
|
|
}
|
|
|
|
if (src->middle_emulation != INT_MIN) {
|
|
|
|
dst->middle_emulation = src->middle_emulation;
|
|
|
|
}
|
|
|
|
if (src->natural_scroll != INT_MIN) {
|
|
|
|
dst->natural_scroll = src->natural_scroll;
|
|
|
|
}
|
|
|
|
if (src->pointer_accel != FLT_MIN) {
|
|
|
|
dst->pointer_accel = src->pointer_accel;
|
|
|
|
}
|
|
|
|
if (src->scroll_method != INT_MIN) {
|
|
|
|
dst->scroll_method = src->scroll_method;
|
|
|
|
}
|
|
|
|
if (src->send_events != INT_MIN) {
|
|
|
|
dst->send_events = src->send_events;
|
|
|
|
}
|
|
|
|
if (src->tap != INT_MIN) {
|
|
|
|
dst->tap = src->tap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-29 21:51:48 +01:00
|
|
|
void merge_output_config(struct output_config *dst, struct output_config *src) {
|
|
|
|
if (src->name) {
|
|
|
|
if (dst->name) {
|
|
|
|
free(dst->name);
|
|
|
|
}
|
|
|
|
dst->name = strdup(src->name);
|
|
|
|
}
|
|
|
|
if (src->enabled != -1) {
|
|
|
|
dst->enabled = src->enabled;
|
|
|
|
}
|
|
|
|
if (src->width != -1) {
|
|
|
|
dst->width = src->width;
|
|
|
|
}
|
|
|
|
if (src->height != -1) {
|
|
|
|
dst->height = src->height;
|
|
|
|
}
|
|
|
|
if (src->x != -1) {
|
|
|
|
dst->x = src->x;
|
|
|
|
}
|
|
|
|
if (src->y != -1) {
|
|
|
|
dst->y = src->y;
|
|
|
|
}
|
|
|
|
if (src->background) {
|
|
|
|
if (dst->background) {
|
|
|
|
free(dst->background);
|
|
|
|
}
|
|
|
|
dst->background = strdup(src->background);
|
|
|
|
}
|
|
|
|
if (src->background_option) {
|
|
|
|
if (dst->background_option) {
|
|
|
|
free(dst->background_option);
|
|
|
|
}
|
|
|
|
dst->background_option = strdup(src->background_option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:25:09 +01:00
|
|
|
static void invoke_swaybar(struct bar_config *bar) {
|
|
|
|
bar->pid = fork();
|
|
|
|
if (bar->pid == 0) {
|
2015-12-19 01:03:39 +01:00
|
|
|
if (!bar->swaybar_command) {
|
|
|
|
char *const cmd[] = {
|
|
|
|
"swaybar",
|
|
|
|
"-b",
|
|
|
|
bar->id,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
execvp(cmd[0], cmd);
|
|
|
|
} else {
|
|
|
|
// run custom swaybar
|
2016-02-23 14:25:09 +01:00
|
|
|
int len = strlen(bar->swaybar_command) + strlen(bar->id) + 5;
|
2015-12-19 01:03:39 +01:00
|
|
|
char *command = malloc(len * sizeof(char));
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!command) {
|
|
|
|
sway_log(L_ERROR, "Unable to allocate swaybar command string");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-23 14:25:09 +01:00
|
|
|
snprintf(command, len, "%s -b %s", bar->swaybar_command, bar->id);
|
2015-12-19 01:03:39 +01:00
|
|
|
|
|
|
|
char *const cmd[] = {
|
|
|
|
"sh",
|
|
|
|
"-c",
|
|
|
|
command,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
execvp(cmd[0], cmd);
|
|
|
|
free(command);
|
|
|
|
}
|
2015-12-18 17:43:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:25:09 +01:00
|
|
|
static void terminate_swaybar(pid_t pid) {
|
|
|
|
int ret = kill(pid, SIGTERM);
|
|
|
|
if (ret != 0) {
|
|
|
|
sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", pid);
|
|
|
|
} else {
|
|
|
|
int status;
|
|
|
|
waitpid(pid, &status, 0);
|
2015-12-18 17:43:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:02:39 +01:00
|
|
|
void terminate_swaybg(pid_t pid) {
|
|
|
|
int ret = kill(pid, SIGTERM);
|
|
|
|
if (ret != 0) {
|
|
|
|
sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid);
|
|
|
|
} else {
|
|
|
|
int status;
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 18:52:57 +01:00
|
|
|
static bool active_output(const char *name) {
|
|
|
|
int i;
|
|
|
|
swayc_t *cont = NULL;
|
|
|
|
for (i = 0; i < root_container.children->length; ++i) {
|
|
|
|
cont = root_container.children->items[i];
|
|
|
|
if (cont->type == C_OUTPUT && strcasecmp(name, cont->name) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void load_swaybars() {
|
2015-12-18 17:43:03 +01:00
|
|
|
// Check for bars
|
|
|
|
list_t *bars = create_list();
|
|
|
|
struct bar_config *bar = NULL;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < config->bars->length; ++i) {
|
|
|
|
bar = config->bars->items[i];
|
|
|
|
bool apply = false;
|
|
|
|
if (bar->outputs) {
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < bar->outputs->length; ++j) {
|
|
|
|
char *o = bar->outputs->items[j];
|
2016-02-24 18:52:57 +01:00
|
|
|
if (!strcmp(o, "*") || active_output(o)) {
|
2015-12-18 17:43:03 +01:00
|
|
|
apply = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
apply = true;
|
|
|
|
}
|
|
|
|
if (apply) {
|
|
|
|
list_add(bars, bar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < bars->length; ++i) {
|
|
|
|
bar = bars->items[i];
|
2016-02-23 14:25:09 +01:00
|
|
|
if (bar->pid != 0) {
|
|
|
|
terminate_swaybar(bar->pid);
|
|
|
|
}
|
2016-02-24 18:52:57 +01:00
|
|
|
sway_log(L_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
|
2016-02-23 14:25:09 +01:00
|
|
|
invoke_swaybar(bar);
|
2015-12-18 17:43:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
list_free(bars);
|
|
|
|
}
|
|
|
|
|
2016-01-17 11:53:37 +01:00
|
|
|
void apply_input_config(struct input_config *ic, struct libinput_device *dev) {
|
2016-07-17 13:27:02 +02:00
|
|
|
if (!ic) {
|
|
|
|
return;
|
2016-01-17 11:53:37 +01:00
|
|
|
}
|
|
|
|
|
2016-07-17 13:27:02 +02:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s)", ic->identifier);
|
|
|
|
|
|
|
|
if (ic->accel_profile != INT_MIN) {
|
2016-05-01 12:02:44 +02:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) accel_set_profile(%d)", ic->identifier, ic->accel_profile);
|
|
|
|
libinput_device_config_accel_set_profile(dev, ic->accel_profile);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->click_method != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) click_set_method(%d)", ic->identifier, ic->click_method);
|
|
|
|
libinput_device_config_click_set_method(dev, ic->click_method);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->drag_lock != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) tap_set_drag_lock_enabled(%d)", ic->identifier, ic->click_method);
|
|
|
|
libinput_device_config_tap_set_drag_lock_enabled(dev, ic->drag_lock);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->dwt != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) dwt_set_enabled(%d)", ic->identifier, ic->dwt);
|
|
|
|
libinput_device_config_dwt_set_enabled(dev, ic->dwt);
|
|
|
|
}
|
2016-10-25 22:03:58 +02:00
|
|
|
if (ic->left_handed != INT_MIN) {
|
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) left_handed_set_enabled(%d)", ic->identifier, ic->left_handed);
|
|
|
|
libinput_device_config_left_handed_set(dev, ic->left_handed);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->middle_emulation != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) middle_emulation_set_enabled(%d)", ic->identifier, ic->middle_emulation);
|
|
|
|
libinput_device_config_middle_emulation_set_enabled(dev, ic->middle_emulation);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->natural_scroll != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) natural_scroll_set_enabled(%d)", ic->identifier, ic->natural_scroll);
|
|
|
|
libinput_device_config_scroll_set_natural_scroll_enabled(dev, ic->natural_scroll);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->pointer_accel != FLT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) accel_set_speed(%f)", ic->identifier, ic->pointer_accel);
|
|
|
|
libinput_device_config_accel_set_speed(dev, ic->pointer_accel);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->scroll_method != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) scroll_set_method(%d)", ic->identifier, ic->scroll_method);
|
|
|
|
libinput_device_config_scroll_set_method(dev, ic->scroll_method);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->send_events != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) send_events_set_mode(%d)", ic->identifier, ic->send_events);
|
|
|
|
libinput_device_config_send_events_set_mode(dev, ic->send_events);
|
|
|
|
}
|
2016-07-17 13:27:02 +02:00
|
|
|
if (ic->tap != INT_MIN) {
|
2016-01-17 11:53:37 +01:00
|
|
|
sway_log(L_DEBUG, "apply_input_config(%s) tap_set_enabled(%d)", ic->identifier, ic->tap);
|
|
|
|
libinput_device_config_tap_set_enabled(dev, ic->tap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 16:34:12 +02:00
|
|
|
void apply_output_config(struct output_config *oc, swayc_t *output) {
|
2016-08-20 18:24:08 +02:00
|
|
|
if (oc && oc->enabled == 0) {
|
2016-08-10 18:52:49 +02:00
|
|
|
destroy_output(output);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-21 23:59:01 +02:00
|
|
|
if (oc && oc->width > 0 && oc->height > 0) {
|
2015-10-21 16:34:12 +02:00
|
|
|
output->width = oc->width;
|
|
|
|
output->height = oc->height;
|
|
|
|
|
2016-07-18 22:21:45 +02:00
|
|
|
sway_log(L_DEBUG, "Set %s size to %ix%i (%d)", oc->name, oc->width, oc->height, oc->scale);
|
2015-10-21 16:34:12 +02:00
|
|
|
struct wlc_size new_size = { .w = oc->width, .h = oc->height };
|
2016-07-18 22:21:45 +02:00
|
|
|
wlc_output_set_resolution(output->handle, &new_size, (uint32_t)oc->scale);
|
|
|
|
} else if (oc && oc->scale != 1) {
|
|
|
|
const struct wlc_size *new_size = wlc_output_get_resolution(output->handle);
|
|
|
|
wlc_output_set_resolution(output->handle, new_size, (uint32_t)oc->scale);
|
2016-07-16 16:04:18 +02:00
|
|
|
}
|
2015-10-21 16:34:12 +02:00
|
|
|
|
|
|
|
// Find position for it
|
|
|
|
if (oc && oc->x != -1 && oc->y != -1) {
|
|
|
|
sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
|
|
|
output->x = oc->x;
|
|
|
|
output->y = oc->y;
|
|
|
|
} else {
|
|
|
|
int x = 0;
|
|
|
|
for (int i = 0; i < root_container.children->length; ++i) {
|
|
|
|
swayc_t *c = root_container.children->items[i];
|
|
|
|
if (c->type == C_OUTPUT) {
|
|
|
|
if (c->width + c->x > x) {
|
|
|
|
x = c->width + c->x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output->x = x;
|
|
|
|
}
|
2015-11-20 00:55:17 +01:00
|
|
|
|
2015-11-28 16:18:37 +01:00
|
|
|
if (!oc || !oc->background) {
|
|
|
|
// Look for a * config for background
|
2015-11-29 14:24:11 +01:00
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
2015-11-28 16:18:37 +01:00
|
|
|
oc = config->output_configs->items[i];
|
2015-11-29 14:24:11 +01:00
|
|
|
} else {
|
2015-11-28 16:18:37 +01:00
|
|
|
oc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 01:36:31 +01:00
|
|
|
int output_i;
|
|
|
|
for (output_i = 0; output_i < root_container.children->length; ++output_i) {
|
|
|
|
if (root_container.children->items[output_i] == output) {
|
|
|
|
break;
|
2015-11-20 00:55:17 +01:00
|
|
|
}
|
2015-12-17 01:36:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oc && oc->background) {
|
2015-12-18 17:43:03 +01:00
|
|
|
if (output->bg_pid != 0) {
|
2015-12-18 18:02:39 +01:00
|
|
|
terminate_swaybg(output->bg_pid);
|
2015-12-18 17:43:03 +01:00
|
|
|
}
|
|
|
|
|
2015-12-17 01:36:31 +01:00
|
|
|
sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
|
2015-11-25 22:19:08 +01:00
|
|
|
|
|
|
|
size_t bufsize = 4;
|
|
|
|
char output_id[bufsize];
|
2015-12-17 01:36:31 +01:00
|
|
|
snprintf(output_id, bufsize, "%d", output_i);
|
2015-11-25 22:19:08 +01:00
|
|
|
output_id[bufsize-1] = 0;
|
|
|
|
|
|
|
|
char *const cmd[] = {
|
|
|
|
"swaybg",
|
|
|
|
output_id,
|
|
|
|
oc->background,
|
|
|
|
oc->background_option,
|
|
|
|
NULL,
|
|
|
|
};
|
2015-12-17 01:29:47 +01:00
|
|
|
|
2015-12-18 17:43:03 +01:00
|
|
|
output->bg_pid = fork();
|
|
|
|
if (output->bg_pid == 0) {
|
2015-12-17 01:29:47 +01:00
|
|
|
execvp(cmd[0], cmd);
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 16:34:12 +02:00
|
|
|
}
|
|
|
|
|
2015-09-07 23:29:40 +02:00
|
|
|
char *do_var_replacement(char *str) {
|
2015-08-06 04:40:38 +02:00
|
|
|
int i;
|
2015-09-08 17:54:57 +02:00
|
|
|
char *find = str;
|
|
|
|
while ((find = strchr(find, '$'))) {
|
|
|
|
// Skip if escaped.
|
2015-09-08 18:10:36 +02:00
|
|
|
if (find > str && find[-1] == '\\') {
|
|
|
|
if (find == str + 1 || !(find > str + 1 && find[-2] == '\\')) {
|
|
|
|
++find;
|
2015-09-08 17:54:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Find matching variable
|
|
|
|
for (i = 0; i < config->symbols->length; ++i) {
|
|
|
|
struct sway_variable *var = config->symbols->items[i];
|
|
|
|
int vnlen = strlen(var->name);
|
|
|
|
if (strncmp(find, var->name, vnlen) == 0) {
|
|
|
|
int vvlen = strlen(var->value);
|
|
|
|
char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!newstr) {
|
|
|
|
sway_log(L_ERROR,
|
|
|
|
"Unable to allocate replacement during variable expansion");
|
|
|
|
break;
|
|
|
|
}
|
2015-09-08 17:54:57 +02:00
|
|
|
char *newptr = newstr;
|
|
|
|
int offset = find - str;
|
|
|
|
strncpy(newptr, str, offset);
|
|
|
|
newptr += offset;
|
|
|
|
strncpy(newptr, var->value, vvlen);
|
|
|
|
newptr += vvlen;
|
|
|
|
strcpy(newptr, find + vnlen);
|
|
|
|
free(str);
|
|
|
|
str = newstr;
|
|
|
|
find = str + offset + vvlen;
|
|
|
|
break;
|
2015-08-06 04:40:38 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-08 18:52:33 +02:00
|
|
|
if (i == config->symbols->length) {
|
|
|
|
++find;
|
|
|
|
}
|
2015-08-06 04:40:38 +02:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
2015-11-19 13:05:59 +01:00
|
|
|
|
|
|
|
// the naming is intentional (albeit long): a workspace_output_cmp function
|
|
|
|
// would compare two structs in full, while this method only compares the
|
|
|
|
// workspace.
|
|
|
|
int workspace_output_cmp_workspace(const void *a, const void *b) {
|
|
|
|
const struct workspace_output *wsa = a, *wsb = b;
|
|
|
|
return lenient_strcmp(wsa->workspace, wsb->workspace);
|
|
|
|
}
|
2015-11-19 16:37:48 +01:00
|
|
|
|
|
|
|
int sway_binding_cmp_keys(const void *a, const void *b) {
|
|
|
|
const struct sway_binding *binda = a, *bindb = b;
|
|
|
|
|
2015-11-24 09:30:02 +01:00
|
|
|
// Count keys pressed for this binding. important so we check long before
|
|
|
|
// short ones. for example mod+a+b before mod+a
|
|
|
|
unsigned int moda = 0, modb = 0, i;
|
|
|
|
|
|
|
|
// Count how any modifiers are pressed
|
|
|
|
for (i = 0; i < 8 * sizeof(binda->modifiers); ++i) {
|
|
|
|
moda += (binda->modifiers & 1 << i) != 0;
|
|
|
|
modb += (bindb->modifiers & 1 << i) != 0;
|
2015-11-19 16:37:48 +01:00
|
|
|
}
|
2015-11-24 09:30:02 +01:00
|
|
|
if (bindb->keys->length + modb != binda->keys->length + moda) {
|
|
|
|
return (bindb->keys->length + modb) - (binda->keys->length + moda);
|
2015-11-19 16:37:48 +01:00
|
|
|
}
|
|
|
|
|
2015-11-24 09:30:02 +01:00
|
|
|
// Otherwise compare keys
|
2015-11-24 19:15:10 +01:00
|
|
|
if (binda->modifiers > bindb->modifiers) {
|
|
|
|
return 1;
|
|
|
|
} else if (binda->modifiers < bindb->modifiers) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-01-09 17:40:19 +01:00
|
|
|
struct wlc_modifiers no_mods = { 0, 0 };
|
2015-11-19 16:37:48 +01:00
|
|
|
for (int i = 0; i < binda->keys->length; i++) {
|
2016-01-09 17:40:19 +01:00
|
|
|
xkb_keysym_t ka = *(xkb_keysym_t *)binda->keys->items[i],
|
|
|
|
kb = *(xkb_keysym_t *)bindb->keys->items[i];
|
|
|
|
if (binda->bindcode) {
|
|
|
|
uint32_t *keycode = binda->keys->items[i];
|
|
|
|
ka = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bindb->bindcode) {
|
|
|
|
uint32_t *keycode = bindb->keys->items[i];
|
|
|
|
kb = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ka > kb) {
|
2015-11-19 16:37:48 +01:00
|
|
|
return 1;
|
2016-01-09 17:40:19 +01:00
|
|
|
} else if (ka < kb) {
|
2015-11-19 16:37:48 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-01-09 17:40:19 +01:00
|
|
|
|
2015-11-19 16:37:48 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sway_binding_cmp(const void *a, const void *b) {
|
|
|
|
int cmp = 0;
|
|
|
|
if ((cmp = sway_binding_cmp_keys(a, b)) != 0) {
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
const struct sway_binding *binda = a, *bindb = b;
|
|
|
|
return lenient_strcmp(binda->command, bindb->command);
|
|
|
|
}
|
|
|
|
|
replace non-standard qsort_r with qsort
I've tried to make as few changes, as possible.
Usually the reason for using qsort_r is, that you can pass an extra userdata pointer to the
compare function. However, in sway list_sort wrapped qsort_r and always called a wrapper
function for comparing, the wrapper function then had the real compare function as argument.
The only thing, that the wrapper function does, is dereferencing the 'left' and 'right' function
arguments before passing them to the real compare function.
I have renamed list_sort to list_qsort to avoid confusion (so nobody tries to use list_qsort like
list_sort) and removed the wrapper functionality. Now the dereferencing must be done in the
compare function, that gets passed.
Some compare functions were used in both list_sort and list_seq_find. To make the difference
clear, I've added a '_qsort' suffix to the compare functions, that are intended to be used with
the new list_qsort. (In other words: list_qsort is not compatible anymore with list_seq_find).
- Changed and renamed function (it isn't used anywhere but in commands.c, and only for sorting):
compare_set -> compare_set_qsort
- New wrapper functions:
sway_binding_cmp_qsort (for sway_binding_cmp)
sway_mouse_binding_cmp_qsort (for sway_mouse_binding_cmp)
2015-12-22 00:38:18 +01:00
|
|
|
int sway_binding_cmp_qsort(const void *a, const void *b) {
|
|
|
|
return sway_binding_cmp(*(void **)a, *(void **)b);
|
|
|
|
}
|
|
|
|
|
2015-11-19 16:37:48 +01:00
|
|
|
void free_sway_binding(struct sway_binding *binding) {
|
|
|
|
if (binding->keys) {
|
|
|
|
for (int i = 0; i < binding->keys->length; i++) {
|
|
|
|
free(binding->keys->items[i]);
|
|
|
|
}
|
|
|
|
list_free(binding->keys);
|
|
|
|
}
|
|
|
|
if (binding->command) {
|
|
|
|
free(binding->command);
|
|
|
|
}
|
|
|
|
free(binding);
|
|
|
|
}
|
2015-12-14 23:43:52 +01:00
|
|
|
|
|
|
|
int sway_mouse_binding_cmp_buttons(const void *a, const void *b) {
|
|
|
|
const struct sway_mouse_binding *binda = a, *bindb = b;
|
|
|
|
if (binda->button > bindb->button) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (binda->button < bindb->button) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sway_mouse_binding_cmp(const void *a, const void *b) {
|
|
|
|
int cmp = 0;
|
|
|
|
if ((cmp = sway_binding_cmp_keys(a, b)) != 0) {
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
const struct sway_mouse_binding *binda = a, *bindb = b;
|
|
|
|
return lenient_strcmp(binda->command, bindb->command);
|
|
|
|
}
|
|
|
|
|
replace non-standard qsort_r with qsort
I've tried to make as few changes, as possible.
Usually the reason for using qsort_r is, that you can pass an extra userdata pointer to the
compare function. However, in sway list_sort wrapped qsort_r and always called a wrapper
function for comparing, the wrapper function then had the real compare function as argument.
The only thing, that the wrapper function does, is dereferencing the 'left' and 'right' function
arguments before passing them to the real compare function.
I have renamed list_sort to list_qsort to avoid confusion (so nobody tries to use list_qsort like
list_sort) and removed the wrapper functionality. Now the dereferencing must be done in the
compare function, that gets passed.
Some compare functions were used in both list_sort and list_seq_find. To make the difference
clear, I've added a '_qsort' suffix to the compare functions, that are intended to be used with
the new list_qsort. (In other words: list_qsort is not compatible anymore with list_seq_find).
- Changed and renamed function (it isn't used anywhere but in commands.c, and only for sorting):
compare_set -> compare_set_qsort
- New wrapper functions:
sway_binding_cmp_qsort (for sway_binding_cmp)
sway_mouse_binding_cmp_qsort (for sway_mouse_binding_cmp)
2015-12-22 00:38:18 +01:00
|
|
|
int sway_mouse_binding_cmp_qsort(const void *a, const void *b) {
|
|
|
|
return sway_mouse_binding_cmp(*(void **)a, *(void **)b);
|
|
|
|
}
|
|
|
|
|
2015-12-14 23:43:52 +01:00
|
|
|
void free_sway_mouse_binding(struct sway_mouse_binding *binding) {
|
|
|
|
if (binding->command) {
|
|
|
|
free(binding->command);
|
|
|
|
}
|
|
|
|
free(binding);
|
|
|
|
}
|
2015-12-15 00:35:18 +01:00
|
|
|
|
2016-01-06 17:01:08 +01:00
|
|
|
struct sway_binding *sway_binding_dup(struct sway_binding *sb) {
|
|
|
|
struct sway_binding *new_sb = malloc(sizeof(struct sway_binding));
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!new_sb) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-06 17:01:08 +01:00
|
|
|
|
|
|
|
new_sb->order = sb->order;
|
|
|
|
new_sb->modifiers = sb->modifiers;
|
|
|
|
new_sb->command = strdup(sb->command);
|
|
|
|
|
|
|
|
new_sb->keys = create_list();
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < sb->keys->length; ++i) {
|
|
|
|
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!key) {
|
|
|
|
free_sway_binding(new_sb);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-06 17:01:08 +01:00
|
|
|
*key = *(xkb_keysym_t *)sb->keys->items[i];
|
|
|
|
list_add(new_sb->keys, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_sb;
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:35:18 +01:00
|
|
|
struct bar_config *default_bar_config(void) {
|
|
|
|
struct bar_config *bar = NULL;
|
|
|
|
bar = malloc(sizeof(struct bar_config));
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!bar) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!(bar->mode = strdup("dock"))) goto cleanup;
|
|
|
|
if (!(bar->hidden_state = strdup("hide"))) goto cleanup;
|
2016-01-05 00:49:11 +01:00
|
|
|
bar->modifier = WLC_BIT_MOD_LOGO;
|
2015-12-17 01:29:47 +01:00
|
|
|
bar->outputs = NULL;
|
2015-12-15 00:35:18 +01:00
|
|
|
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(bar->bindings = create_list())) goto cleanup;
|
|
|
|
if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"))) goto cleanup;
|
2016-10-20 15:43:38 +02:00
|
|
|
bar->pango_markup = false;
|
2015-12-18 23:49:50 +01:00
|
|
|
bar->swaybar_command = NULL;
|
2016-01-27 06:57:55 +01:00
|
|
|
bar->font = NULL;
|
2015-12-15 14:05:42 +01:00
|
|
|
bar->height = -1;
|
2015-12-15 00:35:18 +01:00
|
|
|
bar->workspace_buttons = true;
|
2016-08-02 22:02:39 +02:00
|
|
|
bar->wrap_scroll = false;
|
2015-12-16 12:58:45 +01:00
|
|
|
bar->separator_symbol = NULL;
|
2015-12-15 00:35:18 +01:00
|
|
|
bar->strip_workspace_numbers = false;
|
|
|
|
bar->binding_mode_indicator = true;
|
|
|
|
bar->tray_padding = 2;
|
2016-04-30 02:12:41 +02:00
|
|
|
bar->verbose = false;
|
2016-02-23 14:25:09 +01:00
|
|
|
bar->pid = 0;
|
2015-12-15 13:12:08 +01:00
|
|
|
// set default colors
|
2016-12-15 23:52:53 +01:00
|
|
|
if (!(bar->colors.background = strndup("#000000ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.statusline = strndup("#ffffffff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.separator = strndup("#666666ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.focused_workspace_border = strndup("#4c7899ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.focused_workspace_bg = strndup("#285577ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.focused_workspace_text = strndup("#ffffffff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.active_workspace_border = strndup("#333333ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.active_workspace_bg = strndup("#5f676aff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.active_workspace_text = strndup("#ffffffff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.inactive_workspace_border = strndup("#333333ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.inactive_workspace_bg = strndup("#222222ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.inactive_workspace_text = strndup("#888888ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.urgent_workspace_border = strndup("#2f343aff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.urgent_workspace_bg = strndup("#900000ff", 9))) goto cleanup;
|
|
|
|
if (!(bar->colors.urgent_workspace_text = strndup("#ffffffff", 9))) goto cleanup;
|
2016-11-03 06:43:12 +01:00
|
|
|
// if the following colors stay undefined, they fall back to background,
|
|
|
|
// statusline, separator and urgent_workspace_*.
|
2016-11-02 21:07:04 +01:00
|
|
|
bar->colors.focused_background = NULL;
|
|
|
|
bar->colors.focused_statusline = NULL;
|
|
|
|
bar->colors.focused_separator = NULL;
|
|
|
|
bar->colors.binding_mode_border = NULL;
|
|
|
|
bar->colors.binding_mode_bg = NULL;
|
|
|
|
bar->colors.binding_mode_text = NULL;
|
2015-12-15 13:12:08 +01:00
|
|
|
|
2015-12-15 00:35:18 +01:00
|
|
|
list_add(config->bars, bar);
|
|
|
|
|
|
|
|
return bar;
|
2016-12-15 23:52:53 +01:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free_bar(bar);
|
|
|
|
return NULL;
|
2015-12-15 00:35:18 +01:00
|
|
|
}
|