Implement output configuration through config

Do not use `output res WIDTHxHEIGHT` yet, wlc has issues with it (cc
@Cloudef)
This commit is contained in:
Drew DeVault 2015-08-22 11:18:55 -04:00
parent ade634bb04
commit b7f4607544
5 changed files with 131 additions and 32 deletions

View file

@ -364,6 +364,66 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
return true;
}
static bool cmd_output(struct sway_config *config, int argc, char **argv) {
if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) {
return false;
}
struct output_config *output = calloc(1, sizeof(struct output_config));
output->x = output->y = output->width = output->height = -1;
output->name = strdup(argv[0]);
// TODO: atoi doesn't handle invalid numbers
int i;
for (i = 1; i < argc; ++i) {
if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) {
char *res = argv[++i];
char *x = strchr(res, 'x');
int width = -1, height = -1;
if (x != NULL) {
// Format is 1234x4321
*x = '\0';
width = atoi(res);
height = atoi(x + 1);
*x = 'x';
} else {
// Format is 1234 4321
width = atoi(res);
res = argv[++i];
height = atoi(res);
}
output->width = width;
output->height = height;
} else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) {
char *res = argv[++i];
char *c = strchr(res, ',');
int x = -1, y = -1;
if (c != NULL) {
// Format is 1234,4321
*c = '\0';
x = atoi(res);
y = atoi(c + 1);
*c = ',';
} else {
// Format is 1234 4321
x = atoi(res);
res = argv[++i];
y = atoi(res);
}
output->x = x;
output->y = y;
}
}
list_add(config->output_configs, output);
sway_log(L_DEBUG, "Configured output %s to %d x %d @ %d, %d",
output->name, output->width, output->height, output->x, output->y);
return true;
}
static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
return false;
@ -637,6 +697,7 @@ static struct cmd_handler handlers[] = {
{ "layout", cmd_layout },
{ "log_colors", cmd_log_colors },
{ "move", cmd_move},
{ "output", cmd_output},
{ "reload", cmd_reload },
{ "resize", cmd_resize },
{ "set", cmd_set },

View file

@ -22,6 +22,7 @@ void config_defaults(struct sway_config *config) {
config->modes = create_list();
config->cmd_queue = create_list();
config->workspace_outputs = create_list();
config->output_configs = create_list();
config->current_mode = malloc(sizeof(struct sway_mode));
config->current_mode->name = NULL;
config->current_mode->bindings = create_list();
@ -60,6 +61,7 @@ void free_config(struct sway_config *config) {
free(sym->value);
}
free_flat_list(config->symbols);
free_flat_list(config->output_configs);
}
static const char *search_paths[] = {

View file

@ -55,13 +55,31 @@ static void free_swayc(swayc_t *cont) {
// New containers
swayc_t *new_output(wlc_handle handle) {
const struct wlc_size* size = wlc_output_get_resolution(handle);
const struct wlc_size *size = wlc_output_get_resolution(handle);
const char *name = wlc_output_get_name(handle);
sway_log(L_DEBUG, "Added output %lu:%s", handle, name);
struct output_config *oc ;
int i;
for (i = 0; i < config->output_configs->length; ++i) {
oc = config->output_configs->items[i];
if (strcasecmp(name, oc->name) == 0) {
sway_log(L_DEBUG, "Matched output config for %s", name);
break;
}
oc = NULL;
}
swayc_t *output = new_swayc(C_OUTPUT);
output->width = size->w;
output->height = size->h;
if (oc && oc->width != -1 && oc->height != -1) {
output->width = oc->width;
output->height = oc->height;
struct wlc_size new_size = { .w = oc->width, .h = oc->width };
wlc_output_set_resolution(handle, &new_size);
} else {
output->width = size->w;
output->height = size->h;
}
output->handle = handle;
output->name = name ? strdup(name) : NULL;
output->gaps = config->gaps_outer + config->gaps_inner / 2;
@ -71,7 +89,6 @@ swayc_t *new_output(wlc_handle handle) {
// Create workspace
char *ws_name = NULL;
if (name) {
int i;
for (i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i];
if (strcasecmp(wso->output, name) == 0) {