aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/container.h20
-rw-r--r--include/sway/server.h10
-rw-r--r--sway/CMakeLists.txt12
-rw-r--r--sway/config.c14
-rw-r--r--sway/desktop/output.c21
-rw-r--r--sway/ipc-json.c17
-rw-r--r--sway/main.c3
-rw-r--r--sway/server.c30
-rw-r--r--sway/tree/container.c20
9 files changed, 103 insertions, 44 deletions
diff --git a/include/sway/container.h b/include/sway/container.h
index 37192ce3..f6aae7d1 100644
--- a/include/sway/container.h
+++ b/include/sway/container.h
@@ -2,6 +2,7 @@
2#define _SWAY_CONTAINER_H 2#define _SWAY_CONTAINER_H
3#include <sys/types.h> 3#include <sys/types.h>
4#include <wlc/wlc.h> 4#include <wlc/wlc.h>
5#include <wlr/types/wlr_output.h>
5#include <stdint.h> 6#include <stdint.h>
6 7
7#include "list.h" 8#include "list.h"
@@ -27,6 +28,14 @@ enum swayc_types {
27 C_TYPES, 28 C_TYPES,
28}; 29};
29 30
31enum swayc_view_types {
32 V_WL_SHELL,
33 V_XDG_SHELL_V6,
34 V_XWAYLAND,
35 // Keep last
36 V_TYPES,
37};
38
30/** 39/**
31 * Different ways to arrange a container. 40 * Different ways to arrange a container.
32 */ 41 */
@@ -63,12 +72,13 @@ enum swayc_border_types {
63 * The tree is made of these. Views are containers that cannot have children. 72 * The tree is made of these. Views are containers that cannot have children.
64 */ 73 */
65struct sway_container { 74struct sway_container {
66 /** 75 // TODO WLR: reconcile these
67 * If this container maps to a WLC object, this is set to that object's
68 * handle. Otherwise, NULL.
69 */
70 wlc_handle handle; 76 wlc_handle handle;
71 77
78 union {
79 struct wlr_output *output;
80 } _handle;
81
72 /** 82 /**
73 * A unique ID to identify this container. Primarily used in the 83 * A unique ID to identify this container. Primarily used in the
74 * get_tree JSON output. 84 * get_tree JSON output.
@@ -179,7 +189,7 @@ enum visibility_mask {
179/** 189/**
180 * Allocates a new output container. 190 * Allocates a new output container.
181 */ 191 */
182swayc_t *new_output(wlc_handle handle); 192swayc_t *new_output(struct wlr_output *wlr_output);
183/** 193/**
184 * Allocates a new workspace container. 194 * Allocates a new workspace container.
185 */ 195 */
diff --git a/include/sway/server.h b/include/sway/server.h
index 22069f9c..f3e86bcb 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -12,6 +12,7 @@
12struct sway_server { 12struct sway_server {
13 struct wl_display *wl_display; 13 struct wl_display *wl_display;
14 struct wl_event_loop *wl_event_loop; 14 struct wl_event_loop *wl_event_loop;
15 const char *socket;
15 16
16 struct wlr_backend *backend; 17 struct wlr_backend *backend;
17 struct wlr_renderer *renderer; 18 struct wlr_renderer *renderer;
@@ -19,11 +20,18 @@ struct sway_server {
19 struct wlr_data_device_manager *data_device_manager; 20 struct wlr_data_device_manager *data_device_manager;
20 21
21 struct sway_input *input; 22 struct sway_input *input;
23
24 struct wl_listener output_add;
25 struct wl_listener output_remove;
26 struct wl_listener output_frame;
22}; 27};
23 28
29struct sway_server server;
30
24bool server_init(struct sway_server *server); 31bool server_init(struct sway_server *server);
25void server_fini(struct sway_server *server); 32void server_fini(struct sway_server *server);
33void server_run(struct sway_server *server);
26 34
27struct sway_server server; 35void output_add_notify(struct wl_listener *listener, void *data);
28 36
29#endif 37#endif
diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt
index 1df24222..617a71f0 100644
--- a/sway/CMakeLists.txt
+++ b/sway/CMakeLists.txt
@@ -18,14 +18,20 @@ file(GLOB cmds
18) 18)
19 19
20add_executable(sway 20add_executable(sway
21 commands.c 21 desktop/output.c
22 ${cmds} 22
23 tree/container.c 23 tree/container.c
24 tree/criteria.c 24 tree/criteria.c
25 tree/focus.c 25 tree/focus.c
26 tree/output.c 26 tree/output.c
27 tree/workspace.c 27 tree/workspace.c
28 tree/layout.c 28 tree/layout.c
29
30 input/input.c
31
32 commands.c
33 ${cmds}
34
29 base64.c 35 base64.c
30 config.c 36 config.c
31 debug_log.c 37 debug_log.c
@@ -36,8 +42,6 @@ add_executable(sway
36 border.c 42 border.c
37 security.c 43 security.c
38 server.c 44 server.c
39
40 input/input.c
41) 45)
42 46
43add_definitions( 47add_definitions(
diff --git a/sway/config.c b/sway/config.c
index a33b8edc..78ab8f3b 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -15,6 +15,7 @@
15#include <float.h> 15#include <float.h>
16#include <dirent.h> 16#include <dirent.h>
17#include <strings.h> 17#include <strings.h>
18#include <wlr/types/wlr_output.h>
18#include "wayland-desktop-shell-server-protocol.h" 19#include "wayland-desktop-shell-server-protocol.h"
19#include "sway/commands.h" 20#include "sway/commands.h"
20#include "sway/config.h" 21#include "sway/config.h"
@@ -930,6 +931,7 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
930} 931}
931 932
932static void invoke_swaybar(struct bar_config *bar) { 933static void invoke_swaybar(struct bar_config *bar) {
934 return; // TODO WLR
933 // Pipe to communicate errors 935 // Pipe to communicate errors
934 int filedes[2]; 936 int filedes[2];
935 if (pipe(filedes) == -1) { 937 if (pipe(filedes) == -1) {
@@ -1128,13 +1130,15 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
1128 output->height = oc->height; 1130 output->height = oc->height;
1129 1131
1130 sway_log(L_DEBUG, "Set %s size to %ix%i (%d)", oc->name, oc->width, oc->height, oc->scale); 1132 sway_log(L_DEBUG, "Set %s size to %ix%i (%d)", oc->name, oc->width, oc->height, oc->scale);
1131 struct wlc_size new_size = { .w = oc->width, .h = oc->height }; 1133 // TODO WLR: modes
1132 wlc_output_set_resolution(output->handle, &new_size, (uint32_t)oc->scale); 1134 //struct wlc_size new_size = { .w = oc->width, .h = oc->height };
1135 //wlc_output_set_resolution(output->handle, &new_size, (uint32_t)oc->scale);
1133 } else if (oc) { 1136 } else if (oc) {
1134 const struct wlc_size *new_size = wlc_output_get_resolution(output->handle); 1137 //const struct wlc_size *new_size = wlc_output_get_resolution(output->handle);
1135 wlc_output_set_resolution(output->handle, new_size, (uint32_t)oc->scale); 1138 //wlc_output_set_resolution(output->handle, new_size, (uint32_t)oc->scale);
1136 } 1139 }
1137 1140
1141 // TODO WLR: wlr_output_layout
1138 // Find position for it 1142 // Find position for it
1139 if (oc && oc->x != -1 && oc->y != -1) { 1143 if (oc && oc->x != -1 && oc->y != -1) {
1140 sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); 1144 sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
@@ -1170,6 +1174,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
1170 } 1174 }
1171 } 1175 }
1172 1176
1177 /* TODO WLR
1173 if (oc && oc->background) { 1178 if (oc && oc->background) {
1174 if (output->bg_pid != 0) { 1179 if (output->bg_pid != 0) {
1175 terminate_swaybg(output->bg_pid); 1180 terminate_swaybg(output->bg_pid);
@@ -1195,6 +1200,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
1195 execvp(cmd[0], cmd); 1200 execvp(cmd[0], cmd);
1196 } 1201 }
1197 } 1202 }
1203 */
1198} 1204}
1199 1205
1200char *do_var_replacement(char *str) { 1206char *do_var_replacement(char *str) {
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
new file mode 100644
index 00000000..51363e76
--- /dev/null
+++ b/sway/desktop/output.c
@@ -0,0 +1,21 @@
1#include <wayland-server.h>
2#include <wlr/types/wlr_output.h>
3#include "sway/server.h"
4#include "sway/container.h"
5#include "sway/workspace.h"
6#include "log.h"
7
8void output_add_notify(struct wl_listener *listener, void *data) {
9 struct sway_server *server = wl_container_of(listener, server, output_add);
10 struct wlr_output *wlr_output = data;
11 sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name);
12 swayc_t *op = new_output(wlr_output);
13 if (!sway_assert(op, "Failed to allocate output")) {
14 return;
15 }
16 // Switch to workspace if we need to
17 if (swayc_active_workspace() == NULL) {
18 swayc_t *ws = op->children->items[0];
19 workspace_switch(ws);
20 }
21}
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 6ab63c75..064509c9 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -3,6 +3,8 @@
3#include <string.h> 3#include <string.h>
4#include <stdint.h> 4#include <stdint.h>
5#include <libinput.h> 5#include <libinput.h>
6#include <wlr/types/wlr_box.h>
7#include <wlr/types/wlr_output.h>
6#include "sway/container.h" 8#include "sway/container.h"
7#include "sway/input.h" 9#include "sway/input.h"
8#include "sway/ipc-json.h" 10#include "sway/ipc-json.h"
@@ -14,16 +16,19 @@ static json_object *ipc_json_create_rect(swayc_t *c) {
14 json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x)); 16 json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x));
15 json_object_object_add(rect, "y", json_object_new_int((int32_t)c->y)); 17 json_object_object_add(rect, "y", json_object_new_int((int32_t)c->y));
16 18
17 struct wlc_size size; 19 struct wlr_box box;
18 if (c->type == C_OUTPUT) { 20 if (c->type == C_OUTPUT) {
19 size = *wlc_output_get_resolution(c->handle); 21 wlr_output_effective_resolution(c->_handle.output,
22 &box.width, &box.height);
20 } else { 23 } else {
21 size.w = c->width; 24 box.width = c->width;
22 size.h = c->height; 25 box.width = c->height;
23 } 26 }
24 27
25 json_object_object_add(rect, "width", json_object_new_int((int32_t)size.w)); 28 json_object_object_add(rect, "width",
26 json_object_object_add(rect, "height", json_object_new_int((int32_t)size.h)); 29 json_object_new_int((int32_t)box.width));
30 json_object_object_add(rect, "height",
31 json_object_new_int((int32_t)box.height));
27 32
28 return rect; 33 return rect;
29} 34}
diff --git a/sway/main.c b/sway/main.c
index efca96d5..7d6f2873 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -441,6 +441,7 @@ int main(int argc, char **argv) {
441 if (!server_init(&server)) { 441 if (!server_init(&server)) {
442 return 1; 442 return 1;
443 } 443 }
444
444 init_layout(); 445 init_layout();
445 ipc_init(); 446 ipc_init();
446 447
@@ -460,7 +461,7 @@ int main(int argc, char **argv) {
460 security_sanity_check(); 461 security_sanity_check();
461 462
462 if (!terminate_request) { 463 if (!terminate_request) {
463 wl_display_run(server.wl_display); 464 server_run(&server);
464 } 465 }
465 466
466 server_fini(&server); 467 server_fini(&server);
diff --git a/sway/server.c b/sway/server.c
index 4a74cfb5..b7ce4612 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -27,23 +27,14 @@ bool server_init(struct sway_server *server) {
27 server->data_device_manager = 27 server->data_device_manager =
28 wlr_data_device_manager_create(server->wl_display); 28 wlr_data_device_manager_create(server->wl_display);
29 29
30 const char *socket = wl_display_add_socket_auto(server->wl_display); 30 server->output_add.notify = output_add_notify;
31 if (!socket) { 31 wl_signal_add(&server->backend->events.output_add, &server->output_add);
32 sway_log_errno(L_ERROR, "Unable to open wayland socket");
33 wlr_backend_destroy(server->backend);
34 return false;
35 }
36 32
37 sway_log(L_INFO, "Running compositor on wayland display '%s'", socket); 33 server->socket = wl_display_add_socket_auto(server->wl_display);
38 setenv("_WAYLAND_DISPLAY", socket, true); 34 if (!sway_assert(server->socket, "Unable to open wayland socket")) {
39
40 if (!wlr_backend_start(server->backend)) {
41 sway_log(L_ERROR, "Failed to start backend");
42 wlr_backend_destroy(server->backend); 35 wlr_backend_destroy(server->backend);
43 return false; 36 return false;
44 } 37 }
45
46 setenv("WAYLAND_DISPLAY", socket, true);
47 return true; 38 return true;
48} 39}
49 40
@@ -51,3 +42,16 @@ void server_fini(struct sway_server *server) {
51 // TODO WLR: tear down more stuff 42 // TODO WLR: tear down more stuff
52 wlr_backend_destroy(server->backend); 43 wlr_backend_destroy(server->backend);
53} 44}
45
46void server_run(struct sway_server *server) {
47 sway_log(L_INFO, "Running compositor on wayland display '%s'",
48 server->socket);
49 setenv("_WAYLAND_DISPLAY", server->socket, true);
50 if (!sway_assert(wlr_backend_start(server->backend),
51 "Failed to start backend")) {
52 wlr_backend_destroy(server->backend);
53 return;
54 }
55 setenv("WAYLAND_DISPLAY", server->socket, true);
56 wl_display_run(server->wl_display);
57}
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 829fde69..61c9c5e3 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -4,6 +4,8 @@
4#include <stdbool.h> 4#include <stdbool.h>
5#include <strings.h> 5#include <strings.h>
6#include <string.h> 6#include <string.h>
7#include <wlr/types/wlr_box.h>
8#include <wlr/types/wlr_output.h>
7#include "sway/config.h" 9#include "sway/config.h"
8#include "sway/container.h" 10#include "sway/container.h"
9#include "sway/workspace.h" 11#include "sway/workspace.h"
@@ -118,10 +120,10 @@ static void update_root_geometry() {
118 120
119// New containers 121// New containers
120 122
121swayc_t *new_output(wlc_handle handle) { 123swayc_t *new_output(struct wlr_output *wlr_output) {
122 struct wlc_size size; 124 struct wlr_box size;
123 output_get_scaled_size(handle, &size); 125 wlr_output_effective_resolution(wlr_output, &size.width, &size.height);
124 const char *name = wlc_output_get_name(handle); 126 const char *name = wlr_output->name;
125 // Find current outputs to see if this already exists 127 // Find current outputs to see if this already exists
126 { 128 {
127 int i, len = root_container.children->length; 129 int i, len = root_container.children->length;
@@ -129,14 +131,12 @@ swayc_t *new_output(wlc_handle handle) {
129 swayc_t *op = root_container.children->items[i]; 131 swayc_t *op = root_container.children->items[i];
130 const char *op_name = op->name; 132 const char *op_name = op->name;
131 if (op_name && name && strcmp(op_name, name) == 0) { 133 if (op_name && name && strcmp(op_name, name) == 0) {
132 sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name); 134 sway_log(L_DEBUG, "restoring output %p: %s", wlr_output, op_name);
133 return op; 135 return op;
134 } 136 }
135 } 137 }
136 } 138 }
137 139
138 sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
139
140 struct output_config *oc = NULL, *all = NULL; 140 struct output_config *oc = NULL, *all = NULL;
141 int i; 141 int i;
142 for (i = 0; i < config->output_configs->length; ++i) { 142 for (i = 0; i < config->output_configs->length; ++i) {
@@ -164,10 +164,10 @@ swayc_t *new_output(wlc_handle handle) {
164 } 164 }
165 165
166 swayc_t *output = new_swayc(C_OUTPUT); 166 swayc_t *output = new_swayc(C_OUTPUT);
167 output->handle = handle; 167 output->_handle.output = wlr_output;
168 output->name = name ? strdup(name) : NULL; 168 output->name = name ? strdup(name) : NULL;
169 output->width = size.w; 169 output->width = size.width;
170 output->height = size.h; 170 output->height = size.width;
171 output->unmanaged = create_list(); 171 output->unmanaged = create_list();
172 output->bg_pid = 0; 172 output->bg_pid = 0;
173 173