diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-11 14:41:18 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-11-11 14:41:18 -0500 |
commit | 1efd5f819f9986bf27e390f4988359388606cea0 (patch) | |
tree | bb417f4442a37e7d2baea13cc6e674a70978acf7 /sway | |
parent | Initialize outputs from backend and add to tree (diff) | |
download | sway-1efd5f819f9986bf27e390f4988359388606cea0.tar.gz sway-1efd5f819f9986bf27e390f4988359388606cea0.tar.zst sway-1efd5f819f9986bf27e390f4988359388606cea0.zip |
Wire up output frame loop
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/focus.c | 1 | ||||
-rw-r--r-- | sway/commands/move.c | 1 | ||||
-rw-r--r-- | sway/desktop/output.c | 45 | ||||
-rw-r--r-- | sway/ipc-json.c | 4 | ||||
-rw-r--r-- | sway/server.c | 4 | ||||
-rw-r--r-- | sway/tree/container.c | 12 | ||||
-rw-r--r-- | sway/tree/output.c | 1 |
7 files changed, 59 insertions, 9 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index defaba29..c83157b8 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <string.h> | 2 | #include <string.h> |
2 | #include <strings.h> | 3 | #include <strings.h> |
3 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
diff --git a/sway/commands/move.c b/sway/commands/move.c index 8d89f2ef..52c73e22 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <string.h> | 2 | #include <string.h> |
2 | #include <strings.h> | 3 | #include <strings.h> |
3 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 51363e76..6d0bebc5 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -1,21 +1,60 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <stdlib.h> | ||
3 | #include <time.h> | ||
1 | #include <wayland-server.h> | 4 | #include <wayland-server.h> |
2 | #include <wlr/types/wlr_output.h> | 5 | #include <wlr/types/wlr_output.h> |
6 | #include <wlr/render.h> | ||
3 | #include "sway/server.h" | 7 | #include "sway/server.h" |
4 | #include "sway/container.h" | 8 | #include "sway/container.h" |
5 | #include "sway/workspace.h" | 9 | #include "sway/workspace.h" |
10 | #include "sway/output.h" | ||
6 | #include "log.h" | 11 | #include "log.h" |
7 | 12 | ||
13 | static void output_frame_notify(struct wl_listener *listener, void *data) { | ||
14 | struct sway_output *soutput = wl_container_of( | ||
15 | listener, soutput, frame); | ||
16 | struct wlr_output *wlr_output = data; | ||
17 | struct sway_server *server = soutput->server; | ||
18 | |||
19 | struct timespec now; | ||
20 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
21 | |||
22 | wlr_output_make_current(wlr_output); | ||
23 | wlr_renderer_begin(server->renderer, wlr_output); | ||
24 | |||
25 | wlr_renderer_end(server->renderer); | ||
26 | wlr_output_swap_buffers(wlr_output); | ||
27 | |||
28 | soutput->last_frame = now; | ||
29 | } | ||
30 | |||
8 | void output_add_notify(struct wl_listener *listener, void *data) { | 31 | void output_add_notify(struct wl_listener *listener, void *data) { |
9 | struct sway_server *server = wl_container_of(listener, server, output_add); | 32 | struct sway_server *server = wl_container_of(listener, server, output_add); |
10 | struct wlr_output *wlr_output = data; | 33 | struct wlr_output *wlr_output = data; |
11 | sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); | 34 | sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); |
12 | swayc_t *op = new_output(wlr_output); | 35 | |
13 | if (!sway_assert(op, "Failed to allocate output")) { | 36 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); |
37 | output->wlr_output = wlr_output; | ||
38 | output->server = server; | ||
39 | |||
40 | swayc_t *node = new_output(output); | ||
41 | if (!sway_assert(node, "Failed to allocate output")) { | ||
14 | return; | 42 | return; |
15 | } | 43 | } |
44 | |||
16 | // Switch to workspace if we need to | 45 | // Switch to workspace if we need to |
17 | if (swayc_active_workspace() == NULL) { | 46 | if (swayc_active_workspace() == NULL) { |
18 | swayc_t *ws = op->children->items[0]; | 47 | swayc_t *ws = node->children->items[0]; |
19 | workspace_switch(ws); | 48 | workspace_switch(ws); |
20 | } | 49 | } |
50 | |||
51 | output->frame.notify = output_frame_notify; | ||
52 | wl_signal_add(&wlr_output->events.frame, &output->frame); | ||
53 | } | ||
54 | |||
55 | void output_remove_notify(struct wl_listener *listener, void *data) { | ||
56 | struct sway_server *server = wl_container_of(listener, server, output_remove); | ||
57 | struct wlr_output *wlr_output = data; | ||
58 | sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); | ||
59 | // TODO | ||
21 | } | 60 | } |
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 064509c9..1579a2d9 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <json-c/json.h> | 2 | #include <json-c/json.h> |
2 | #include <ctype.h> | 3 | #include <ctype.h> |
3 | #include <string.h> | 4 | #include <string.h> |
@@ -5,6 +6,7 @@ | |||
5 | #include <libinput.h> | 6 | #include <libinput.h> |
6 | #include <wlr/types/wlr_box.h> | 7 | #include <wlr/types/wlr_box.h> |
7 | #include <wlr/types/wlr_output.h> | 8 | #include <wlr/types/wlr_output.h> |
9 | #include "sway/output.h" | ||
8 | #include "sway/container.h" | 10 | #include "sway/container.h" |
9 | #include "sway/input.h" | 11 | #include "sway/input.h" |
10 | #include "sway/ipc-json.h" | 12 | #include "sway/ipc-json.h" |
@@ -18,7 +20,7 @@ static json_object *ipc_json_create_rect(swayc_t *c) { | |||
18 | 20 | ||
19 | struct wlr_box box; | 21 | struct wlr_box box; |
20 | if (c->type == C_OUTPUT) { | 22 | if (c->type == C_OUTPUT) { |
21 | wlr_output_effective_resolution(c->_handle.output, | 23 | wlr_output_effective_resolution(c->_handle.output->wlr_output, |
22 | &box.width, &box.height); | 24 | &box.width, &box.height); |
23 | } else { | 25 | } else { |
24 | box.width = c->width; | 26 | box.width = c->width; |
diff --git a/sway/server.c b/sway/server.c index b7ce4612..a7f47af3 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -30,6 +30,10 @@ bool server_init(struct sway_server *server) { | |||
30 | server->output_add.notify = output_add_notify; | 30 | server->output_add.notify = output_add_notify; |
31 | wl_signal_add(&server->backend->events.output_add, &server->output_add); | 31 | wl_signal_add(&server->backend->events.output_add, &server->output_add); |
32 | 32 | ||
33 | server->output_remove.notify = output_remove_notify; | ||
34 | wl_signal_add(&server->backend->events.output_remove, | ||
35 | &server->output_remove); | ||
36 | |||
33 | server->socket = wl_display_add_socket_auto(server->wl_display); | 37 | server->socket = wl_display_add_socket_auto(server->wl_display); |
34 | if (!sway_assert(server->socket, "Unable to open wayland socket")) { | 38 | if (!sway_assert(server->socket, "Unable to open wayland socket")) { |
35 | wlr_backend_destroy(server->backend); | 39 | wlr_backend_destroy(server->backend); |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 61c9c5e3..25bb858e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -120,10 +120,11 @@ static void update_root_geometry() { | |||
120 | 120 | ||
121 | // New containers | 121 | // New containers |
122 | 122 | ||
123 | swayc_t *new_output(struct wlr_output *wlr_output) { | 123 | swayc_t *new_output(struct sway_output *sway_output) { |
124 | struct wlr_box size; | 124 | struct wlr_box size; |
125 | wlr_output_effective_resolution(wlr_output, &size.width, &size.height); | 125 | wlr_output_effective_resolution(sway_output->wlr_output, |
126 | const char *name = wlr_output->name; | 126 | &size.width, &size.height); |
127 | const char *name = sway_output->wlr_output->name; | ||
127 | // Find current outputs to see if this already exists | 128 | // Find current outputs to see if this already exists |
128 | { | 129 | { |
129 | int i, len = root_container.children->length; | 130 | int i, len = root_container.children->length; |
@@ -131,7 +132,8 @@ swayc_t *new_output(struct wlr_output *wlr_output) { | |||
131 | swayc_t *op = root_container.children->items[i]; | 132 | swayc_t *op = root_container.children->items[i]; |
132 | const char *op_name = op->name; | 133 | const char *op_name = op->name; |
133 | if (op_name && name && strcmp(op_name, name) == 0) { | 134 | if (op_name && name && strcmp(op_name, name) == 0) { |
134 | sway_log(L_DEBUG, "restoring output %p: %s", wlr_output, op_name); | 135 | sway_log(L_DEBUG, "restoring output %p: %s", |
136 | sway_output, op_name); | ||
135 | return op; | 137 | return op; |
136 | } | 138 | } |
137 | } | 139 | } |
@@ -164,7 +166,7 @@ swayc_t *new_output(struct wlr_output *wlr_output) { | |||
164 | } | 166 | } |
165 | 167 | ||
166 | swayc_t *output = new_swayc(C_OUTPUT); | 168 | swayc_t *output = new_swayc(C_OUTPUT); |
167 | output->_handle.output = wlr_output; | 169 | output->_handle.output = sway_output; |
168 | output->name = name ? strdup(name) : NULL; | 170 | output->name = name ? strdup(name) : NULL; |
169 | output->width = size.width; | 171 | output->width = size.width; |
170 | output->height = size.width; | 172 | output->height = size.width; |
diff --git a/sway/tree/output.c b/sway/tree/output.c index c0f29c5a..edfcac98 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <strings.h> | 2 | #include <strings.h> |
2 | #include <ctype.h> | 3 | #include <ctype.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |