summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-06-07 19:26:55 +0100
committerLibravatar GitHub <noreply@github.com>2018-06-07 19:26:55 +0100
commit2e289831ee3198f36e2c02bd4542fa4f6646a81b (patch)
tree7de104885aabb49f17739d7631ef6cd4f628e64a /sway
parentMerge pull request #2116 from RedSoxFan/fix-2113 (diff)
parentSwitch output storing from list_t to wl_list (diff)
downloadsway-2e289831ee3198f36e2c02bd4542fa4f6646a81b.tar.gz
sway-2e289831ee3198f36e2c02bd4542fa4f6646a81b.tar.zst
sway-2e289831ee3198f36e2c02bd4542fa4f6646a81b.zip
Merge pull request #2108 from RedSoxFan/store-outputs
Allow outputs to be re-enabled
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/output.c28
-rw-r--r--sway/config/output.c2
-rw-r--r--sway/desktop/layer_shell.c4
-rw-r--r--sway/desktop/output.c22
-rw-r--r--sway/ipc-json.c20
-rw-r--r--sway/ipc-server.c8
-rw-r--r--sway/tree/container.c4
-rw-r--r--sway/tree/layout.c1
8 files changed, 72 insertions, 17 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index bc12310e..f955bf90 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -1,5 +1,7 @@
1#include "sway/commands.h" 1#include "sway/commands.h"
2#include "sway/config.h" 2#include "sway/config.h"
3#include "sway/output.h"
4#include "sway/tree/layout.h"
3#include "list.h" 5#include "list.h"
4#include "log.h" 6#include "log.h"
5 7
@@ -80,16 +82,24 @@ struct cmd_results *cmd_output(int argc, char **argv) {
80 // will be applied during normal "new output" event from wlroots. 82 // will be applied during normal "new output" event from wlroots.
81 char identifier[128]; 83 char identifier[128];
82 bool all = strcmp(output->name, "*") == 0; 84 bool all = strcmp(output->name, "*") == 0;
83 for (int i = 0; i < root_container.children->length; ++i) { 85 struct sway_output *sway_output;
84 struct sway_container *cont = root_container.children->items[i]; 86 wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) {
85 if (cont->type != C_OUTPUT) { 87 output_get_identifier(identifier, sizeof(identifier), sway_output);
86 continue; 88 wlr_log(L_DEBUG, "Checking identifier %s", identifier);
87 } 89 if (all || strcmp(sway_output->wlr_output->name, output->name) == 0
90 || strcmp(identifier, output->name) == 0) {
91 if (!sway_output->swayc) {
92 if (!output->enabled) {
93 if (!all) {
94 break;
95 }
96 continue;
97 }
98
99 output_enable(sway_output);
100 }
88 101
89 output_get_identifier(identifier, sizeof(identifier), cont->sway_output); 102 apply_output_config(output, sway_output->swayc);
90 if (all || strcmp(cont->name, output->name) == 0 ||
91 strcmp(identifier, output->name) == 0) {
92 apply_output_config(output, cont);
93 103
94 if (!all) { 104 if (!all) {
95 // Stop looking if the output config isn't applicable to all 105 // Stop looking if the output config isn't applicable to all
diff --git a/sway/config/output.c b/sway/config/output.c
index ee2440ea..648ded27 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -131,11 +131,13 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
131 struct wlr_output *wlr_output = output->sway_output->wlr_output; 131 struct wlr_output *wlr_output = output->sway_output->wlr_output;
132 132
133 if (oc && oc->enabled == 0) { 133 if (oc && oc->enabled == 0) {
134 struct sway_output *sway_output = output->sway_output;
134 if (output->sway_output->bg_pid != 0) { 135 if (output->sway_output->bg_pid != 0) {
135 terminate_swaybg(output->sway_output->bg_pid); 136 terminate_swaybg(output->sway_output->bg_pid);
136 output->sway_output->bg_pid = 0; 137 output->sway_output->bg_pid = 0;
137 } 138 }
138 container_destroy(output); 139 container_destroy(output);
140 sway_output->swayc = NULL;
139 wlr_output_layout_remove(root_container.sway_root->output_layout, 141 wlr_output_layout_remove(root_container.sway_root->output_layout,
140 wlr_output); 142 wlr_output);
141 return; 143 return;
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index 2d355b74..3accdefb 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -252,7 +252,7 @@ static void unmap(struct sway_layer_surface *sway_layer) {
252 return; 252 return;
253 } 253 }
254 struct sway_output *output = wlr_output->data; 254 struct sway_output *output = wlr_output->data;
255 if (output == NULL) { 255 if (output == NULL || output->swayc == NULL) {
256 return; 256 return;
257 } 257 }
258 output_damage_surface(output, sway_layer->geo.x, sway_layer->geo.y, 258 output_damage_surface(output, sway_layer->geo.x, sway_layer->geo.y,
@@ -279,7 +279,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
279 wl_list_remove(&sway_layer->surface_commit.link); 279 wl_list_remove(&sway_layer->surface_commit.link);
280 if (sway_layer->layer_surface->output != NULL) { 280 if (sway_layer->layer_surface->output != NULL) {
281 struct sway_output *output = sway_layer->layer_surface->output->data; 281 struct sway_output *output = sway_layer->layer_surface->output->data;
282 if (output != NULL) { 282 if (output != NULL && output->swayc != NULL) {
283 arrange_layers(output); 283 arrange_layers(output);
284 } 284 }
285 wl_list_remove(&sway_layer->output_destroy.link); 285 wl_list_remove(&sway_layer->output_destroy.link);
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index acc9caae..3142bdb4 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -1165,7 +1165,16 @@ static void damage_handle_destroy(struct wl_listener *listener, void *data) {
1165 1165
1166static void handle_destroy(struct wl_listener *listener, void *data) { 1166static void handle_destroy(struct wl_listener *listener, void *data) {
1167 struct sway_output *output = wl_container_of(listener, output, destroy); 1167 struct sway_output *output = wl_container_of(listener, output, destroy);
1168 container_destroy(output->swayc); 1168 if (output->swayc) {
1169 container_destroy(output->swayc);
1170 }
1171
1172 if (&output->link) {
1173 wl_list_remove(&output->link);
1174 wl_list_remove(&output->destroy.link);
1175 output->wlr_output = NULL;
1176 free(output);
1177 }
1169} 1178}
1170 1179
1171static void handle_mode(struct wl_listener *listener, void *data) { 1180static void handle_mode(struct wl_listener *listener, void *data) {
@@ -1203,6 +1212,9 @@ void handle_new_output(struct wl_listener *listener, void *data) {
1203 output->wlr_output = wlr_output; 1212 output->wlr_output = wlr_output;
1204 wlr_output->data = output; 1213 wlr_output->data = output;
1205 output->server = server; 1214 output->server = server;
1215 wl_list_insert(&root_container.sway_root->outputs, &output->link);
1216
1217 output->damage = wlr_output_damage_create(wlr_output);
1206 1218
1207 if (!wl_list_empty(&wlr_output->modes)) { 1219 if (!wl_list_empty(&wlr_output->modes)) {
1208 struct wlr_output_mode *mode = 1220 struct wlr_output_mode *mode =
@@ -1210,11 +1222,15 @@ void handle_new_output(struct wl_listener *listener, void *data) {
1210 wlr_output_set_mode(wlr_output, mode); 1222 wlr_output_set_mode(wlr_output, mode);
1211 } 1223 }
1212 1224
1213 output->damage = wlr_output_damage_create(wlr_output); 1225 output_enable(output);
1226}
1227
1228void output_enable(struct sway_output *output) {
1229 struct wlr_output *wlr_output = output->wlr_output;
1214 1230
1215 output->swayc = output_create(output); 1231 output->swayc = output_create(output);
1216 if (!output->swayc) { 1232 if (!output->swayc) {
1217 free(output); 1233 // Output is disabled
1218 return; 1234 return;
1219 } 1235 }
1220 1236
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 6d185449..5d402d1b 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -139,6 +139,26 @@ static void ipc_json_describe_output(struct sway_container *container, json_obje
139 json_object_object_add(object, "layout", json_object_new_string("output")); 139 json_object_object_add(object, "layout", json_object_new_string("output"));
140} 140}
141 141
142json_object *ipc_json_describe_disabled_output(struct sway_output *output) {
143 struct wlr_output *wlr_output = output->wlr_output;
144
145 json_object *object = json_object_new_object();
146
147 json_object_object_add(object, "type", json_object_new_string("output"));
148 json_object_object_add(object, "name",
149 wlr_output->name ? json_object_new_string(wlr_output->name) : NULL);
150 json_object_object_add(object, "active", json_object_new_boolean(false));
151 json_object_object_add(object, "make",
152 json_object_new_string(wlr_output->make));
153 json_object_object_add(object, "model",
154 json_object_new_string(wlr_output->model));
155 json_object_object_add(object, "serial",
156 json_object_new_string(wlr_output->serial));
157 json_object_object_add(object, "modes", json_object_new_array());
158
159 return object;
160}
161
142static void ipc_json_describe_workspace(struct sway_container *workspace, 162static void ipc_json_describe_workspace(struct sway_container *workspace,
143 json_object *object) { 163 json_object *object) {
144 int num = isdigit(workspace->name[0]) ? atoi(workspace->name) : -1; 164 int num = isdigit(workspace->name[0]) ? atoi(workspace->name) : -1;
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 8d9ab06a..241fe742 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -19,6 +19,7 @@
19#include "sway/commands.h" 19#include "sway/commands.h"
20#include "sway/ipc-json.h" 20#include "sway/ipc-json.h"
21#include "sway/ipc-server.h" 21#include "sway/ipc-server.h"
22#include "sway/output.h"
22#include "sway/server.h" 23#include "sway/server.h"
23#include "sway/input/input-manager.h" 24#include "sway/input/input-manager.h"
24#include "sway/input/seat.h" 25#include "sway/input/seat.h"
@@ -488,6 +489,13 @@ void ipc_client_handle_command(struct ipc_client *client) {
488 ipc_json_describe_container(container)); 489 ipc_json_describe_container(container));
489 } 490 }
490 } 491 }
492 struct sway_output *output;
493 wl_list_for_each(output, &root_container.sway_root->outputs, link) {
494 if (!output->swayc) {
495 json_object_array_add(outputs,
496 ipc_json_describe_disabled_output(output));
497 }
498 }
491 const char *json_string = json_object_to_json_string(outputs); 499 const char *json_string = json_object_to_json_string(outputs);
492 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); 500 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
493 json_object_put(outputs); // free 501 json_object_put(outputs); // free
diff --git a/sway/tree/container.c b/sway/tree/container.c
index d0d26631..ca993c41 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -255,7 +255,6 @@ static struct sway_container *container_output_destroy(
255 } 255 }
256 } 256 }
257 257
258 wl_list_remove(&output->sway_output->destroy.link);
259 wl_list_remove(&output->sway_output->mode.link); 258 wl_list_remove(&output->sway_output->mode.link);
260 wl_list_remove(&output->sway_output->transform.link); 259 wl_list_remove(&output->sway_output->transform.link);
261 wl_list_remove(&output->sway_output->scale.link); 260 wl_list_remove(&output->sway_output->scale.link);
@@ -263,8 +262,7 @@ static struct sway_container *container_output_destroy(
263 wl_list_remove(&output->sway_output->damage_destroy.link); 262 wl_list_remove(&output->sway_output->damage_destroy.link);
264 wl_list_remove(&output->sway_output->damage_frame.link); 263 wl_list_remove(&output->sway_output->damage_frame.link);
265 264
266 // clear the wlr_output reference to this container 265 output->sway_output->swayc = NULL;
267 output->sway_output->wlr_output->data = NULL;
268 266
269 wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); 267 wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
270 _container_destroy(output); 268 _container_destroy(output);
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 82502e1b..b54dc2fe 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -35,6 +35,7 @@ void layout_init(void) {
35 35
36 root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); 36 root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
37 root_container.sway_root->output_layout = wlr_output_layout_create(); 37 root_container.sway_root->output_layout = wlr_output_layout_create();
38 wl_list_init(&root_container.sway_root->outputs);
38 wl_list_init(&root_container.sway_root->xwayland_unmanaged); 39 wl_list_init(&root_container.sway_root->xwayland_unmanaged);
39 wl_signal_init(&root_container.sway_root->events.new_container); 40 wl_signal_init(&root_container.sway_root->events.new_container);
40 41