aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/ipc-json.h1
-rw-r--r--include/sway/output.h3
-rw-r--r--include/sway/tree/layout.h2
-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/input/cursor.c3
-rw-r--r--sway/ipc-json.c20
-rw-r--r--sway/ipc-server.c8
-rw-r--r--sway/main.c1
-rw-r--r--sway/tree/container.c4
-rw-r--r--sway/tree/layout.c15
-rw-r--r--swaymsg/main.c49
14 files changed, 117 insertions, 45 deletions
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h
index 440e3a24..eaaa2164 100644
--- a/include/sway/ipc-json.h
+++ b/include/sway/ipc-json.h
@@ -6,6 +6,7 @@
json_object *ipc_json_get_version();
+json_object *ipc_json_describe_disabled_output(struct sway_output *o);
json_object *ipc_json_describe_container(struct sway_container *c);
json_object *ipc_json_describe_container_recursive(struct sway_container *c);
json_object *ipc_json_describe_input(struct sway_input_device *device);
diff --git a/include/sway/output.h b/include/sway/output.h
index be19d7b2..70f746dc 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -29,6 +29,8 @@ struct sway_output {
struct wl_listener damage_destroy;
struct wl_listener damage_frame;
+ struct wl_list link;
+
pid_t bg_pid;
};
@@ -45,4 +47,5 @@ void output_damage_whole_container(struct sway_output *output,
struct sway_container *output_by_name(const char *name);
+void output_enable(struct sway_output *output);
#endif
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
index 2e0f2abf..cd131056 100644
--- a/include/sway/tree/layout.h
+++ b/include/sway/tree/layout.h
@@ -31,6 +31,8 @@ struct sway_root {
struct wlr_texture *debug_tree;
+ struct wl_list outputs; // sway_output::link
+
struct {
struct wl_signal new_container;
} events;
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 @@
#include "sway/commands.h"
#include "sway/config.h"
+#include "sway/output.h"
+#include "sway/tree/layout.h"
#include "list.h"
#include "log.h"
@@ -80,16 +82,24 @@ struct cmd_results *cmd_output(int argc, char **argv) {
// will be applied during normal "new output" event from wlroots.
char identifier[128];
bool all = strcmp(output->name, "*") == 0;
- for (int i = 0; i < root_container.children->length; ++i) {
- struct sway_container *cont = root_container.children->items[i];
- if (cont->type != C_OUTPUT) {
- continue;
- }
+ struct sway_output *sway_output;
+ wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) {
+ output_get_identifier(identifier, sizeof(identifier), sway_output);
+ wlr_log(L_DEBUG, "Checking identifier %s", identifier);
+ if (all || strcmp(sway_output->wlr_output->name, output->name) == 0
+ || strcmp(identifier, output->name) == 0) {
+ if (!sway_output->swayc) {
+ if (!output->enabled) {
+ if (!all) {
+ break;
+ }
+ continue;
+ }
+
+ output_enable(sway_output);
+ }
- output_get_identifier(identifier, sizeof(identifier), cont->sway_output);
- if (all || strcmp(cont->name, output->name) == 0 ||
- strcmp(identifier, output->name) == 0) {
- apply_output_config(output, cont);
+ apply_output_config(output, sway_output->swayc);
if (!all) {
// 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
struct wlr_output *wlr_output = output->sway_output->wlr_output;
if (oc && oc->enabled == 0) {
+ struct sway_output *sway_output = output->sway_output;
if (output->sway_output->bg_pid != 0) {
terminate_swaybg(output->sway_output->bg_pid);
output->sway_output->bg_pid = 0;
}
container_destroy(output);
+ sway_output->swayc = NULL;
wlr_output_layout_remove(root_container.sway_root->output_layout,
wlr_output);
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) {
return;
}
struct sway_output *output = wlr_output->data;
- if (output == NULL) {
+ if (output == NULL || output->swayc == NULL) {
return;
}
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) {
wl_list_remove(&sway_layer->surface_commit.link);
if (sway_layer->layer_surface->output != NULL) {
struct sway_output *output = sway_layer->layer_surface->output->data;
- if (output != NULL) {
+ if (output != NULL && output->swayc != NULL) {
arrange_layers(output);
}
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) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, destroy);
- container_destroy(output->swayc);
+ if (output->swayc) {
+ container_destroy(output->swayc);
+ }
+
+ if (&output->link) {
+ wl_list_remove(&output->link);
+ wl_list_remove(&output->destroy.link);
+ output->wlr_output = NULL;
+ free(output);
+ }
}
static void handle_mode(struct wl_listener *listener, void *data) {
@@ -1203,6 +1212,9 @@ void handle_new_output(struct wl_listener *listener, void *data) {
output->wlr_output = wlr_output;
wlr_output->data = output;
output->server = server;
+ wl_list_insert(&root_container.sway_root->outputs, &output->link);
+
+ output->damage = wlr_output_damage_create(wlr_output);
if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode =
@@ -1210,11 +1222,15 @@ void handle_new_output(struct wl_listener *listener, void *data) {
wlr_output_set_mode(wlr_output, mode);
}
- output->damage = wlr_output_damage_create(wlr_output);
+ output_enable(output);
+}
+
+void output_enable(struct sway_output *output) {
+ struct wlr_output *wlr_output = output->wlr_output;
output->swayc = output_create(output);
if (!output->swayc) {
- free(output);
+ // Output is disabled
return;
}
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index d6e17ae1..4100479c 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -480,6 +480,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
return NULL;
}
+ cursor->previous.x = wlr_cursor->x;
+ cursor->previous.y = wlr_cursor->y;
+
cursor->seat = seat;
wlr_cursor_attach_output_layout(wlr_cursor,
root_container.sway_root->output_layout);
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
json_object_object_add(object, "layout", json_object_new_string("output"));
}
+json_object *ipc_json_describe_disabled_output(struct sway_output *output) {
+ struct wlr_output *wlr_output = output->wlr_output;
+
+ json_object *object = json_object_new_object();
+
+ json_object_object_add(object, "type", json_object_new_string("output"));
+ json_object_object_add(object, "name",
+ wlr_output->name ? json_object_new_string(wlr_output->name) : NULL);
+ json_object_object_add(object, "active", json_object_new_boolean(false));
+ json_object_object_add(object, "make",
+ json_object_new_string(wlr_output->make));
+ json_object_object_add(object, "model",
+ json_object_new_string(wlr_output->model));
+ json_object_object_add(object, "serial",
+ json_object_new_string(wlr_output->serial));
+ json_object_object_add(object, "modes", json_object_new_array());
+
+ return object;
+}
+
static void ipc_json_describe_workspace(struct sway_container *workspace,
json_object *object) {
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 @@
#include "sway/commands.h"
#include "sway/ipc-json.h"
#include "sway/ipc-server.h"
+#include "sway/output.h"
#include "sway/server.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
@@ -488,6 +489,13 @@ void ipc_client_handle_command(struct ipc_client *client) {
ipc_json_describe_container(container));
}
}
+ struct sway_output *output;
+ wl_list_for_each(output, &root_container.sway_root->outputs, link) {
+ if (!output->swayc) {
+ json_object_array_add(outputs,
+ ipc_json_describe_disabled_output(output));
+ }
+ }
const char *json_string = json_object_to_json_string(outputs);
ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
json_object_put(outputs); // free
diff --git a/sway/main.c b/sway/main.c
index e03b8e3a..a7e808ad 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -160,7 +160,6 @@ static void log_distro() {
}
static void log_kernel() {
- return;
FILE *f = popen("uname -a", "r");
if (!f) {
wlr_log(L_INFO, "Unable to determine kernel version");
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(
}
}
- wl_list_remove(&output->sway_output->destroy.link);
wl_list_remove(&output->sway_output->mode.link);
wl_list_remove(&output->sway_output->transform.link);
wl_list_remove(&output->sway_output->scale.link);
@@ -263,8 +262,7 @@ static struct sway_container *container_output_destroy(
wl_list_remove(&output->sway_output->damage_destroy.link);
wl_list_remove(&output->sway_output->damage_frame.link);
- // clear the wlr_output reference to this container
- output->sway_output->wlr_output->data = NULL;
+ output->sway_output->swayc = NULL;
wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
_container_destroy(output);
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 79e7c87e..b54dc2fe 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -35,6 +35,7 @@ void layout_init(void) {
root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
root_container.sway_root->output_layout = wlr_output_layout_create();
+ wl_list_init(&root_container.sway_root->outputs);
wl_list_init(&root_container.sway_root->xwayland_unmanaged);
wl_signal_init(&root_container.sway_root->events.new_container);
@@ -874,11 +875,10 @@ struct sway_container *container_split(struct sway_container *child,
cont->x = child->x;
cont->y = child->y;
+ struct sway_seat *seat = input_manager_get_default_seat(input_manager);
+ bool set_focus = (seat_get_focus(seat) == child);
if (child->type == C_WORKSPACE) {
- struct sway_seat *seat = input_manager_get_default_seat(input_manager);
struct sway_container *workspace = child;
- bool set_focus = (seat_get_focus(seat) == workspace);
-
while (workspace->children->length) {
struct sway_container *ws_child = workspace->children->items[0];
container_remove_child(ws_child);
@@ -890,10 +890,6 @@ struct sway_container *container_split(struct sway_container *child,
enum sway_container_layout old_layout = workspace->layout;
workspace->layout = layout;
cont->layout = old_layout;
-
- if (set_focus) {
- seat_set_focus(seat, cont);
- }
} else {
struct sway_container *old_parent = child->parent;
cont->layout = layout;
@@ -902,6 +898,11 @@ struct sway_container *container_split(struct sway_container *child,
wl_signal_emit(&child->events.reparent, old_parent);
}
+ if (set_focus) {
+ seat_set_focus(seat, cont);
+ seat_set_focus(seat, child);
+ }
+
container_notify_subtree_changed(cont);
return cont;
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 8a53474b..29f2a907 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -174,26 +174,35 @@ static void pretty_print_output(json_object *o) {
json_object *modes;
json_object_object_get_ex(o, "modes", &modes);
- printf(
- "Output %s '%s %s %s'%s%s\n"
- " Current mode: %dx%d @ %f Hz\n"
- " Position: %d,%d\n"
- " Scale factor: %dx\n"
- " Transform: %s\n"
- " Workspace: %s\n",
- json_object_get_string(name),
- json_object_get_string(make),
- json_object_get_string(model),
- json_object_get_string(serial),
- json_object_get_boolean(focused) ? " (focused)" : "",
- !json_object_get_boolean(active) ? " (inactive)" : "",
- json_object_get_int(width), json_object_get_int(height),
- (float)json_object_get_int(refresh) / 1000,
- json_object_get_int(x), json_object_get_int(y),
- json_object_get_int(scale),
- json_object_get_string(transform),
- json_object_get_string(ws)
- );
+ if (json_object_get_boolean(active)) {
+ printf(
+ "Output %s '%s %s %s'%s\n"
+ " Current mode: %dx%d @ %f Hz\n"
+ " Position: %d,%d\n"
+ " Scale factor: %dx\n"
+ " Transform: %s\n"
+ " Workspace: %s\n",
+ json_object_get_string(name),
+ json_object_get_string(make),
+ json_object_get_string(model),
+ json_object_get_string(serial),
+ json_object_get_boolean(focused) ? " (focused)" : "",
+ json_object_get_int(width), json_object_get_int(height),
+ (float)json_object_get_int(refresh) / 1000,
+ json_object_get_int(x), json_object_get_int(y),
+ json_object_get_int(scale),
+ json_object_get_string(transform),
+ json_object_get_string(ws)
+ );
+ } else {
+ printf(
+ "Output %s '%s %s %s' (inactive)",
+ json_object_get_string(name),
+ json_object_get_string(make),
+ json_object_get_string(model),
+ json_object_get_string(serial)
+ );
+ }
size_t modes_len = json_object_array_length(modes);
if (modes_len > 0) {