Wire up output frame loop

This commit is contained in:
Drew DeVault 2017-11-11 14:41:18 -05:00
parent 7eafcc75f6
commit 1efd5f819f
10 changed files with 75 additions and 13 deletions

View File

@ -4,7 +4,6 @@
#include <wlc/wlc.h> #include <wlc/wlc.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <stdint.h> #include <stdint.h>
#include "list.h" #include "list.h"
typedef struct sway_container swayc_t; typedef struct sway_container swayc_t;
@ -76,7 +75,7 @@ struct sway_container {
wlc_handle handle; wlc_handle handle;
union { union {
struct wlr_output *output; struct sway_output *output;
} _handle; } _handle;
/** /**
@ -186,10 +185,11 @@ enum visibility_mask {
VISIBLE = true VISIBLE = true
} visible; } visible;
struct sway_output;
/** /**
* Allocates a new output container. * Allocates a new output container.
*/ */
swayc_t *new_output(struct wlr_output *wlr_output); swayc_t *new_output(struct sway_output *sway_output);
/** /**
* Allocates a new workspace container. * Allocates a new workspace container.
*/ */

View File

@ -1,9 +1,20 @@
#ifndef _SWAY_OUTPUT_H #ifndef _SWAY_OUTPUT_H
#define _SWAY_OUTPUT_H #define _SWAY_OUTPUT_H
#include <time.h>
#include <wayland-server.h>
#include <wlr/types/wlr_output.h>
#include "container.h" #include "container.h"
#include "focus.h" #include "focus.h"
struct sway_server;
struct sway_output {
struct wlr_output *wlr_output;
struct wl_listener frame;
struct sway_server *server;
struct timespec last_frame;
};
// Position is absolute coordinates on the edge where the adjacent output // Position is absolute coordinates on the edge where the adjacent output
// should be searched for. // should be searched for.
swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos);

View File

@ -33,5 +33,6 @@ void server_fini(struct sway_server *server);
void server_run(struct sway_server *server); void server_run(struct sway_server *server);
void output_add_notify(struct wl_listener *listener, void *data); void output_add_notify(struct wl_listener *listener, void *data);
void output_remove_notify(struct wl_listener *listener, void *data);
#endif #endif

View File

@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <wlc/wlc.h> #include <wlc/wlc.h>

View File

@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <wlc/wlc.h> #include <wlc/wlc.h>

View File

@ -1,21 +1,60 @@
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <time.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/render.h>
#include "sway/server.h" #include "sway/server.h"
#include "sway/container.h" #include "sway/container.h"
#include "sway/workspace.h" #include "sway/workspace.h"
#include "sway/output.h"
#include "log.h" #include "log.h"
static void output_frame_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of(
listener, soutput, frame);
struct wlr_output *wlr_output = data;
struct sway_server *server = soutput->server;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_output_make_current(wlr_output);
wlr_renderer_begin(server->renderer, wlr_output);
wlr_renderer_end(server->renderer);
wlr_output_swap_buffers(wlr_output);
soutput->last_frame = now;
}
void output_add_notify(struct wl_listener *listener, void *data) { void output_add_notify(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, output_add); struct sway_server *server = wl_container_of(listener, server, output_add);
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name);
swayc_t *op = new_output(wlr_output);
if (!sway_assert(op, "Failed to allocate output")) { struct sway_output *output = calloc(1, sizeof(struct sway_output));
output->wlr_output = wlr_output;
output->server = server;
swayc_t *node = new_output(output);
if (!sway_assert(node, "Failed to allocate output")) {
return; return;
} }
// Switch to workspace if we need to // Switch to workspace if we need to
if (swayc_active_workspace() == NULL) { if (swayc_active_workspace() == NULL) {
swayc_t *ws = op->children->items[0]; swayc_t *ws = node->children->items[0];
workspace_switch(ws); workspace_switch(ws);
} }
output->frame.notify = output_frame_notify;
wl_signal_add(&wlr_output->events.frame, &output->frame);
}
void output_remove_notify(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, output_remove);
struct wlr_output *wlr_output = data;
sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name);
// TODO
} }

View File

@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <json-c/json.h> #include <json-c/json.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
@ -5,6 +6,7 @@
#include <libinput.h> #include <libinput.h>
#include <wlr/types/wlr_box.h> #include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include "sway/output.h"
#include "sway/container.h" #include "sway/container.h"
#include "sway/input.h" #include "sway/input.h"
#include "sway/ipc-json.h" #include "sway/ipc-json.h"
@ -18,7 +20,7 @@ static json_object *ipc_json_create_rect(swayc_t *c) {
struct wlr_box box; struct wlr_box box;
if (c->type == C_OUTPUT) { if (c->type == C_OUTPUT) {
wlr_output_effective_resolution(c->_handle.output, wlr_output_effective_resolution(c->_handle.output->wlr_output,
&box.width, &box.height); &box.width, &box.height);
} else { } else {
box.width = c->width; box.width = c->width;

View File

@ -30,6 +30,10 @@ bool server_init(struct sway_server *server) {
server->output_add.notify = output_add_notify; server->output_add.notify = output_add_notify;
wl_signal_add(&server->backend->events.output_add, &server->output_add); wl_signal_add(&server->backend->events.output_add, &server->output_add);
server->output_remove.notify = output_remove_notify;
wl_signal_add(&server->backend->events.output_remove,
&server->output_remove);
server->socket = wl_display_add_socket_auto(server->wl_display); server->socket = wl_display_add_socket_auto(server->wl_display);
if (!sway_assert(server->socket, "Unable to open wayland socket")) { if (!sway_assert(server->socket, "Unable to open wayland socket")) {
wlr_backend_destroy(server->backend); wlr_backend_destroy(server->backend);

View File

@ -120,10 +120,11 @@ static void update_root_geometry() {
// New containers // New containers
swayc_t *new_output(struct wlr_output *wlr_output) { swayc_t *new_output(struct sway_output *sway_output) {
struct wlr_box size; struct wlr_box size;
wlr_output_effective_resolution(wlr_output, &size.width, &size.height); wlr_output_effective_resolution(sway_output->wlr_output,
const char *name = wlr_output->name; &size.width, &size.height);
const char *name = sway_output->wlr_output->name;
// Find current outputs to see if this already exists // Find current outputs to see if this already exists
{ {
int i, len = root_container.children->length; int i, len = root_container.children->length;
@ -131,7 +132,8 @@ swayc_t *new_output(struct wlr_output *wlr_output) {
swayc_t *op = root_container.children->items[i]; swayc_t *op = root_container.children->items[i];
const char *op_name = op->name; const char *op_name = op->name;
if (op_name && name && strcmp(op_name, name) == 0) { if (op_name && name && strcmp(op_name, name) == 0) {
sway_log(L_DEBUG, "restoring output %p: %s", wlr_output, op_name); sway_log(L_DEBUG, "restoring output %p: %s",
sway_output, op_name);
return op; return op;
} }
} }
@ -164,7 +166,7 @@ swayc_t *new_output(struct wlr_output *wlr_output) {
} }
swayc_t *output = new_swayc(C_OUTPUT); swayc_t *output = new_swayc(C_OUTPUT);
output->_handle.output = wlr_output; output->_handle.output = sway_output;
output->name = name ? strdup(name) : NULL; output->name = name ? strdup(name) : NULL;
output->width = size.width; output->width = size.width;
output->height = size.width; output->height = size.width;

View File

@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <strings.h> #include <strings.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>