summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/config.h7
-rw-r--r--sway.5.txt46
-rw-r--r--sway/commands.c61
-rw-r--r--sway/config.c2
-rw-r--r--sway/container.c25
5 files changed, 120 insertions, 21 deletions
diff --git a/include/config.h b/include/config.h
index c23c3509..c896b423 100644
--- a/include/config.h
+++ b/include/config.h
@@ -22,6 +22,12 @@ struct sway_mode {
22 list_t *bindings; 22 list_t *bindings;
23}; 23};
24 24
25struct output_config {
26 char *name;
27 int width, height;
28 int x, y;
29};
30
25struct workspace_output { 31struct workspace_output {
26 char *output; 32 char *output;
27 char *workspace; 33 char *workspace;
@@ -32,6 +38,7 @@ struct sway_config {
32 list_t *modes; 38 list_t *modes;
33 list_t *cmd_queue; 39 list_t *cmd_queue;
34 list_t *workspace_outputs; 40 list_t *workspace_outputs;
41 list_t *output_configs;
35 struct sway_mode *current_mode; 42 struct sway_mode *current_mode;
36 uint32_t floating_mod; 43 uint32_t floating_mod;
37 44
diff --git a/sway.5.txt b/sway.5.txt
index 5bccbd12..e0052ee1 100644
--- a/sway.5.txt
+++ b/sway.5.txt
@@ -41,6 +41,11 @@ Commands
41**floating** toggle:: 41**floating** toggle::
42 Toggles the "floating" status of the focused view. 42 Toggles the "floating" status of the focused view.
43 43
44**floating_modifier** <modifier>::
45 When the _modifier_ key is held down, you may use left click to drag floating
46 windows, and right click to resize them. Unlike i3, this modifier may also be
47 used to resize and move windows that are tiled.
48
44**focus** <direction>:: 49**focus** <direction>::
45 Direction may be one of _up_, _down_, _left_, _right_, or _parent_. The 50 Direction may be one of _up_, _down_, _left_, _right_, or _parent_. The
46 directional focus commands will move the focus in that direction. The parent 51 directional focus commands will move the focus in that direction. The parent
@@ -55,6 +60,16 @@ Commands
55 If set to _yes_, the currently focused view will change as you move your 60 If set to _yes_, the currently focused view will change as you move your
56 mouse around the screen to the view that ends up underneath your mouse. 61 mouse around the screen to the view that ends up underneath your mouse.
57 62
63**fullscreen**::
64 Toggles fullscreen status for the focused view.
65
66**gaps** <amount>::
67 Adds _amount_ pixels between each view, and around each output.
68
69**gaps** <inner|outer> <amount>::
70 Adds _amount_ pixels as an _inner_ or _outer_ gap, where the former affects
71 spacing between views and the latter affects the space around each output.
72
58**kill**:: 73**kill**::
59 Closes the currently focused view. 74 Closes the currently focused view.
60 75
@@ -62,16 +77,27 @@ Commands
62 Sets the layout mode of the focused container. _mode_ can be one of _splith_, 77 Sets the layout mode of the focused container. _mode_ can be one of _splith_,
63 _splitv_, or _toggle split_. 78 _splitv_, or _toggle split_.
64 79
80**move** <left|right|up|down>::
81 Moves the focused container _left_, _right_, _up_, or _down_.
82
83**output** <name> <resolution|res WIDTHxHEIGHT> <position|pos X,Y>::
84 Configures the specified output. It will use the given resolution and be
85 arranged at the given position in the layout tree. You may omit either of
86 these parameters if you only want to set one of them.
87
65**reload**:: 88**reload**::
66 Reloads the sway config file without restarting sway. 89 Reloads the sway config file without restarting sway.
67 90
91**resize** <shrink|grow> <width|height> <amount>::
92 Resizes the currently focused container or view by _amount_. _amount_ can be
93 specified as "n px" or "n ppt" or "n px or n ppt".
94
68**set** <name> <value>:: 95**set** <name> <value>::
69 Creates a substitution for _value_ that can be used with $_name_ in other 96 Creates a substitution for _value_ that can be used with $_name_ in other
70 commands. 97 commands.
71 98
72**split** <vertical|horizontal>:: 99**split** <vertical|v|horizontal|h>::
73 Splits the current container, vertically or horiziontally. The letters "h" and 100 Splits the current container, vertically or horiziontally.
74 "v" can be used instead of the full words "vertical" or "horizontal".
75 101
76**splith**:: 102**splith**::
77 Equivalent to **split horizontal**. 103 Equivalent to **split horizontal**.
@@ -79,20 +105,6 @@ Commands
79**splitv**:: 105**splitv**::
80 Equivalent to **split vertical**. 106 Equivalent to **split vertical**.
81 107
82**floating_modifier** <modifier>::
83 When the _modifier_ key is held down, you may use left click to drag floating
84 windows, and right click to resize them.
85
86**fullscreen**::
87 Toggles fullscreen status for the focused view.
88
89**gaps** <amount>::
90 Adds _amount_ pixels between each view, and around each output.
91
92**gaps** <inner|outer> <amount>::
93 Adds _amount_ pixels as an _inner_ or _outer_ gap, where the former affects
94 spacing between views and the latter affects the space around each output.
95
96**workspace** <name>:: 108**workspace** <name>::
97 Switches to the specified workspace. 109 Switches to the specified workspace.
98 110
diff --git a/sway/commands.c b/sway/commands.c
index 62794111..5de1fb0c 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -364,6 +364,66 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
364 return true; 364 return true;
365} 365}
366 366
367static bool cmd_output(struct sway_config *config, int argc, char **argv) {
368 if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) {
369 return false;
370 }
371
372 struct output_config *output = calloc(1, sizeof(struct output_config));
373 output->x = output->y = output->width = output->height = -1;
374 output->name = strdup(argv[0]);
375
376 // TODO: atoi doesn't handle invalid numbers
377
378 int i;
379 for (i = 1; i < argc; ++i) {
380 if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) {
381 char *res = argv[++i];
382 char *x = strchr(res, 'x');
383 int width = -1, height = -1;
384 if (x != NULL) {
385 // Format is 1234x4321
386 *x = '\0';
387 width = atoi(res);
388 height = atoi(x + 1);
389 *x = 'x';
390 } else {
391 // Format is 1234 4321
392 width = atoi(res);
393 res = argv[++i];
394 height = atoi(res);
395 }
396 output->width = width;
397 output->height = height;
398 } else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) {
399 char *res = argv[++i];
400 char *c = strchr(res, ',');
401 int x = -1, y = -1;
402 if (c != NULL) {
403 // Format is 1234,4321
404 *c = '\0';
405 x = atoi(res);
406 y = atoi(c + 1);
407 *c = ',';
408 } else {
409 // Format is 1234 4321
410 x = atoi(res);
411 res = argv[++i];
412 y = atoi(res);
413 }
414 output->x = x;
415 output->y = y;
416 }
417 }
418
419 list_add(config->output_configs, output);
420
421 sway_log(L_DEBUG, "Configured output %s to %d x %d @ %d, %d",
422 output->name, output->width, output->height, output->x, output->y);
423
424 return true;
425}
426
367static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { 427static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
368 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { 428 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
369 return false; 429 return false;
@@ -637,6 +697,7 @@ static struct cmd_handler handlers[] = {
637 { "layout", cmd_layout }, 697 { "layout", cmd_layout },
638 { "log_colors", cmd_log_colors }, 698 { "log_colors", cmd_log_colors },
639 { "move", cmd_move}, 699 { "move", cmd_move},
700 { "output", cmd_output},
640 { "reload", cmd_reload }, 701 { "reload", cmd_reload },
641 { "resize", cmd_resize }, 702 { "resize", cmd_resize },
642 { "set", cmd_set }, 703 { "set", cmd_set },
diff --git a/sway/config.c b/sway/config.c
index 1ebd95ff..fcd60de7 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -22,6 +22,7 @@ void config_defaults(struct sway_config *config) {
22 config->modes = create_list(); 22 config->modes = create_list();
23 config->cmd_queue = create_list(); 23 config->cmd_queue = create_list();
24 config->workspace_outputs = create_list(); 24 config->workspace_outputs = create_list();
25 config->output_configs = create_list();
25 config->current_mode = malloc(sizeof(struct sway_mode)); 26 config->current_mode = malloc(sizeof(struct sway_mode));
26 config->current_mode->name = NULL; 27 config->current_mode->name = NULL;
27 config->current_mode->bindings = create_list(); 28 config->current_mode->bindings = create_list();
@@ -60,6 +61,7 @@ void free_config(struct sway_config *config) {
60 free(sym->value); 61 free(sym->value);
61 } 62 }
62 free_flat_list(config->symbols); 63 free_flat_list(config->symbols);
64 free_flat_list(config->output_configs);
63} 65}
64 66
65static const char *search_paths[] = { 67static const char *search_paths[] = {
diff --git a/sway/container.c b/sway/container.c
index 62ff1c4a..7f6fcbc6 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -55,13 +55,31 @@ static void free_swayc(swayc_t *cont) {
55// New containers 55// New containers
56 56
57swayc_t *new_output(wlc_handle handle) { 57swayc_t *new_output(wlc_handle handle) {
58 const struct wlc_size* size = wlc_output_get_resolution(handle); 58 const struct wlc_size *size = wlc_output_get_resolution(handle);
59 const char *name = wlc_output_get_name(handle); 59 const char *name = wlc_output_get_name(handle);
60 sway_log(L_DEBUG, "Added output %lu:%s", handle, name); 60 sway_log(L_DEBUG, "Added output %lu:%s", handle, name);
61 61
62 struct output_config *oc ;
63 int i;
64 for (i = 0; i < config->output_configs->length; ++i) {
65 oc = config->output_configs->items[i];
66 if (strcasecmp(name, oc->name) == 0) {
67 sway_log(L_DEBUG, "Matched output config for %s", name);
68 break;
69 }
70 oc = NULL;
71 }
72
62 swayc_t *output = new_swayc(C_OUTPUT); 73 swayc_t *output = new_swayc(C_OUTPUT);
63 output->width = size->w; 74 if (oc && oc->width != -1 && oc->height != -1) {
64 output->height = size->h; 75 output->width = oc->width;
76 output->height = oc->height;
77 struct wlc_size new_size = { .w = oc->width, .h = oc->width };
78 wlc_output_set_resolution(handle, &new_size);
79 } else {
80 output->width = size->w;
81 output->height = size->h;
82 }
65 output->handle = handle; 83 output->handle = handle;
66 output->name = name ? strdup(name) : NULL; 84 output->name = name ? strdup(name) : NULL;
67 output->gaps = config->gaps_outer + config->gaps_inner / 2; 85 output->gaps = config->gaps_outer + config->gaps_inner / 2;
@@ -71,7 +89,6 @@ swayc_t *new_output(wlc_handle handle) {
71 // Create workspace 89 // Create workspace
72 char *ws_name = NULL; 90 char *ws_name = NULL;
73 if (name) { 91 if (name) {
74 int i;
75 for (i = 0; i < config->workspace_outputs->length; ++i) { 92 for (i = 0; i < config->workspace_outputs->length; ++i) {
76 struct workspace_output *wso = config->workspace_outputs->items[i]; 93 struct workspace_output *wso = config->workspace_outputs->items[i];
77 if (strcasecmp(wso->output, name) == 0) { 94 if (strcasecmp(wso->output, name) == 0) {