Merge pull request #2245 from RyanDwyer/floating-minmax-size

Implement floating_minimum_size and floating_maximum_size
This commit is contained in:
emersion 2018-07-11 18:51:07 +01:00 committed by GitHub
commit 588abbb128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 7 deletions

View file

@ -100,6 +100,8 @@ static struct cmd_handler handlers[] = {
{ "default_border", cmd_default_border },
{ "exec", cmd_exec },
{ "exec_always", cmd_exec_always },
{ "floating_maximum_size", cmd_floating_maximum_size },
{ "floating_minimum_size", cmd_floating_minimum_size },
{ "focus_follows_mouse", cmd_focus_follows_mouse },
{ "focus_wrapping", cmd_focus_wrapping },
{ "font", cmd_font },
@ -344,7 +346,7 @@ struct cmd_results *config_command(char *exec) {
// Start block
if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) {
char *block = join_args(argv, argc - 1);
char *block = join_args(argv, argc - 1);
results = cmd_results_new(CMD_BLOCK, block, NULL);
free(block);
goto cleanup;

View file

@ -0,0 +1,53 @@
#include <errno.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <wlr/util/log.h>
#include "sway/commands.h"
#include "log.h"
static const char* min_usage =
"Expected 'floating_minimum_size <width> x <height>'";
static const char* max_usage =
"Expected 'floating_maximum_size <width> x <height>'";
static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
const char *usage, int *config_width, int *config_height) {
struct cmd_results *error;
if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 3))) {
return error;
}
char *err;
int width = (int)strtol(argv[0], &err, 10);
if (*err) {
return cmd_results_new(CMD_INVALID, cmd_name, usage);
}
if (strcmp(argv[1], "x") != 0) {
return cmd_results_new(CMD_INVALID, cmd_name, usage);
}
int height = (int)strtol(argv[2], &err, 10);
if (*err) {
return cmd_results_new(CMD_INVALID, cmd_name, usage);
}
*config_width = width;
*config_height = height;
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) {
return handle_command(argc, argv, "floating_minimum_size", min_usage,
&config->floating_minimum_width, &config->floating_minimum_height);
}
struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) {
return handle_command(argc, argv, "floating_maximum_size", max_usage,
&config->floating_maximum_width, &config->floating_maximum_height);
}

View file

@ -40,6 +40,7 @@ sway_sources = files(
'commands/exec.c',
'commands/exec_always.c',
'commands/floating.c',
'commands/floating_minmax_size.c',
'commands/focus.c',
'commands/focus_follows_mouse.c',
'commands/focus_wrapping.c',

View file

@ -150,12 +150,43 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
void view_init_floating(struct sway_view *view) {
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
int max_width = ws->width * 0.6666;
int max_height = ws->height * 0.6666;
view->width =
view->natural_width > max_width ? max_width : view->natural_width;
view->height =
view->natural_height > max_height ? max_height : view->natural_height;
int min_width, min_height;
int max_width, max_height;
if (config->floating_minimum_width == -1) { // no minimum
min_width = 0;
} else if (config->floating_minimum_width == 0) { // automatic
min_width = 75;
} else {
min_width = config->floating_minimum_width;
}
if (config->floating_minimum_height == -1) { // no minimum
min_height = 0;
} else if (config->floating_minimum_height == 0) { // automatic
min_height = 50;
} else {
min_height = config->floating_minimum_height;
}
if (config->floating_maximum_width == -1) { // no maximum
max_width = INT_MAX;
} else if (config->floating_maximum_width == 0) { // automatic
max_width = ws->width * 0.6666;
} else {
max_width = config->floating_maximum_width;
}
if (config->floating_maximum_height == -1) { // no maximum
max_height = INT_MAX;
} else if (config->floating_maximum_height == 0) { // automatic
max_height = ws->height * 0.6666;
} else {
max_height = config->floating_maximum_height;
}
view->width = fmax(min_width, fmin(view->natural_width, max_width));
view->height = fmax(min_height, fmin(view->natural_height, max_height));
view->x = ws->x + (ws->width - view->width) / 2;
view->y = ws->y + (ws->height - view->height) / 2;