Initialize outputs from backend and add to tree

master
Drew DeVault 7 years ago
parent 0ba6554c4f
commit 7eafcc75f6

@ -2,6 +2,7 @@
#define _SWAY_CONTAINER_H
#include <sys/types.h>
#include <wlc/wlc.h>
#include <wlr/types/wlr_output.h>
#include <stdint.h>
#include "list.h"
@ -27,6 +28,14 @@ enum swayc_types {
C_TYPES,
};
enum swayc_view_types {
V_WL_SHELL,
V_XDG_SHELL_V6,
V_XWAYLAND,
// Keep last
V_TYPES,
};
/**
* Different ways to arrange a container.
*/
@ -63,12 +72,13 @@ enum swayc_border_types {
* The tree is made of these. Views are containers that cannot have children.
*/
struct sway_container {
/**
* If this container maps to a WLC object, this is set to that object's
* handle. Otherwise, NULL.
*/
// TODO WLR: reconcile these
wlc_handle handle;
union {
struct wlr_output *output;
} _handle;
/**
* A unique ID to identify this container. Primarily used in the
* get_tree JSON output.
@ -179,7 +189,7 @@ enum visibility_mask {
/**
* Allocates a new output container.
*/
swayc_t *new_output(wlc_handle handle);
swayc_t *new_output(struct wlr_output *wlr_output);
/**
* Allocates a new workspace container.
*/

@ -12,6 +12,7 @@
struct sway_server {
struct wl_display *wl_display;
struct wl_event_loop *wl_event_loop;
const char *socket;
struct wlr_backend *backend;
struct wlr_renderer *renderer;
@ -19,11 +20,18 @@ struct sway_server {
struct wlr_data_device_manager *data_device_manager;
struct sway_input *input;
struct wl_listener output_add;
struct wl_listener output_remove;
struct wl_listener output_frame;
};
struct sway_server server;
bool server_init(struct sway_server *server);
void server_fini(struct sway_server *server);
void server_run(struct sway_server *server);
struct sway_server server;
void output_add_notify(struct wl_listener *listener, void *data);
#endif

@ -18,14 +18,20 @@ file(GLOB cmds
)
add_executable(sway
commands.c
${cmds}
desktop/output.c
tree/container.c
tree/criteria.c
tree/focus.c
tree/output.c
tree/workspace.c
tree/layout.c
input/input.c
commands.c
${cmds}
base64.c
config.c
debug_log.c
@ -36,8 +42,6 @@ add_executable(sway
border.c
security.c
server.c
input/input.c
)
add_definitions(

@ -15,6 +15,7 @@
#include <float.h>
#include <dirent.h>
#include <strings.h>
#include <wlr/types/wlr_output.h>
#include "wayland-desktop-shell-server-protocol.h"
#include "sway/commands.h"
#include "sway/config.h"
@ -930,6 +931,7 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
}
static void invoke_swaybar(struct bar_config *bar) {
return; // TODO WLR
// Pipe to communicate errors
int filedes[2];
if (pipe(filedes) == -1) {
@ -1128,13 +1130,15 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
output->height = oc->height;
sway_log(L_DEBUG, "Set %s size to %ix%i (%d)", oc->name, oc->width, oc->height, oc->scale);
struct wlc_size new_size = { .w = oc->width, .h = oc->height };
wlc_output_set_resolution(output->handle, &new_size, (uint32_t)oc->scale);
// TODO WLR: modes
//struct wlc_size new_size = { .w = oc->width, .h = oc->height };
//wlc_output_set_resolution(output->handle, &new_size, (uint32_t)oc->scale);
} else if (oc) {
const struct wlc_size *new_size = wlc_output_get_resolution(output->handle);
wlc_output_set_resolution(output->handle, new_size, (uint32_t)oc->scale);
//const struct wlc_size *new_size = wlc_output_get_resolution(output->handle);
//wlc_output_set_resolution(output->handle, new_size, (uint32_t)oc->scale);
}
// TODO WLR: wlr_output_layout
// Find position for it
if (oc && oc->x != -1 && oc->y != -1) {
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) {
}
}
/* TODO WLR
if (oc && oc->background) {
if (output->bg_pid != 0) {
terminate_swaybg(output->bg_pid);
@ -1195,6 +1200,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
execvp(cmd[0], cmd);
}
}
*/
}
char *do_var_replacement(char *str) {

@ -0,0 +1,21 @@
#include <wayland-server.h>
#include <wlr/types/wlr_output.h>
#include "sway/server.h"
#include "sway/container.h"
#include "sway/workspace.h"
#include "log.h"
void output_add_notify(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, output_add);
struct wlr_output *wlr_output = data;
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")) {
return;
}
// Switch to workspace if we need to
if (swayc_active_workspace() == NULL) {
swayc_t *ws = op->children->items[0];
workspace_switch(ws);
}
}

@ -3,6 +3,8 @@
#include <string.h>
#include <stdint.h>
#include <libinput.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h>
#include "sway/container.h"
#include "sway/input.h"
#include "sway/ipc-json.h"
@ -14,16 +16,19 @@ static json_object *ipc_json_create_rect(swayc_t *c) {
json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x));
json_object_object_add(rect, "y", json_object_new_int((int32_t)c->y));
struct wlc_size size;
struct wlr_box box;
if (c->type == C_OUTPUT) {
size = *wlc_output_get_resolution(c->handle);
wlr_output_effective_resolution(c->_handle.output,
&box.width, &box.height);
} else {
size.w = c->width;
size.h = c->height;
box.width = c->width;
box.width = c->height;
}
json_object_object_add(rect, "width", json_object_new_int((int32_t)size.w));
json_object_object_add(rect, "height", json_object_new_int((int32_t)size.h));
json_object_object_add(rect, "width",
json_object_new_int((int32_t)box.width));
json_object_object_add(rect, "height",
json_object_new_int((int32_t)box.height));
return rect;
}

@ -441,6 +441,7 @@ int main(int argc, char **argv) {
if (!server_init(&server)) {
return 1;
}
init_layout();
ipc_init();
@ -460,7 +461,7 @@ int main(int argc, char **argv) {
security_sanity_check();
if (!terminate_request) {
wl_display_run(server.wl_display);
server_run(&server);
}
server_fini(&server);

@ -27,23 +27,14 @@ bool server_init(struct sway_server *server) {
server->data_device_manager =
wlr_data_device_manager_create(server->wl_display);
const char *socket = wl_display_add_socket_auto(server->wl_display);
if (!socket) {
sway_log_errno(L_ERROR, "Unable to open wayland socket");
wlr_backend_destroy(server->backend);
return false;
}
server->output_add.notify = output_add_notify;
wl_signal_add(&server->backend->events.output_add, &server->output_add);
sway_log(L_INFO, "Running compositor on wayland display '%s'", socket);
setenv("_WAYLAND_DISPLAY", socket, true);
if (!wlr_backend_start(server->backend)) {
sway_log(L_ERROR, "Failed to start backend");
server->socket = wl_display_add_socket_auto(server->wl_display);
if (!sway_assert(server->socket, "Unable to open wayland socket")) {
wlr_backend_destroy(server->backend);
return false;
}
setenv("WAYLAND_DISPLAY", socket, true);
return true;
}
@ -51,3 +42,16 @@ void server_fini(struct sway_server *server) {
// TODO WLR: tear down more stuff
wlr_backend_destroy(server->backend);
}
void server_run(struct sway_server *server) {
sway_log(L_INFO, "Running compositor on wayland display '%s'",
server->socket);
setenv("_WAYLAND_DISPLAY", server->socket, true);
if (!sway_assert(wlr_backend_start(server->backend),
"Failed to start backend")) {
wlr_backend_destroy(server->backend);
return;
}
setenv("WAYLAND_DISPLAY", server->socket, true);
wl_display_run(server->wl_display);
}

@ -4,6 +4,8 @@
#include <stdbool.h>
#include <strings.h>
#include <string.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h>
#include "sway/config.h"
#include "sway/container.h"
#include "sway/workspace.h"
@ -118,10 +120,10 @@ static void update_root_geometry() {
// New containers
swayc_t *new_output(wlc_handle handle) {
struct wlc_size size;
output_get_scaled_size(handle, &size);
const char *name = wlc_output_get_name(handle);
swayc_t *new_output(struct wlr_output *wlr_output) {
struct wlr_box size;
wlr_output_effective_resolution(wlr_output, &size.width, &size.height);
const char *name = wlr_output->name;
// Find current outputs to see if this already exists
{
int i, len = root_container.children->length;
@ -129,14 +131,12 @@ swayc_t *new_output(wlc_handle handle) {
swayc_t *op = root_container.children->items[i];
const char *op_name = op->name;
if (op_name && name && strcmp(op_name, name) == 0) {
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
sway_log(L_DEBUG, "restoring output %p: %s", wlr_output, op_name);
return op;
}
}
}
sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
struct output_config *oc = NULL, *all = NULL;
int i;
for (i = 0; i < config->output_configs->length; ++i) {
@ -164,10 +164,10 @@ swayc_t *new_output(wlc_handle handle) {
}
swayc_t *output = new_swayc(C_OUTPUT);
output->handle = handle;
output->_handle.output = wlr_output;
output->name = name ? strdup(name) : NULL;
output->width = size.w;
output->height = size.h;
output->width = size.width;
output->height = size.width;
output->unmanaged = create_list();
output->bg_pid = 0;

Loading…
Cancel
Save