Listen to output layout change

master
emersion 7 years ago
parent f3d880b0ec
commit c7abb77f22
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -57,9 +57,9 @@ enum swayc_border_types {
B_NORMAL, /**< Normal border with title bar */
};
struct sway_root;
struct sway_output;
struct sway_view;
struct wlr_output_layout;
/**
* Stores information about a container.
@ -69,7 +69,7 @@ struct wlr_output_layout;
struct sway_container {
union {
// TODO: Encapsulate state for other node types as well like C_CONTAINER
struct wlr_output_layout *output_layout; // C_ROOT
struct sway_root *sway_root; // C_ROOT
struct sway_output *sway_output; // C_OUTPUT
struct sway_view *sway_view; // C_VIEW
};

@ -1,8 +1,16 @@
#ifndef _SWAY_LAYOUT_H
#define _SWAY_LAYOUT_H
#include <wlr/types/wlr_output_layout.h>
struct sway_container;
struct sway_root {
struct wlr_output_layout *output_layout;
struct wl_listener output_layout_change;
};
void init_layout(void);
void add_child(struct sway_container *parent, struct sway_container *child);
struct sway_container *remove_child(struct sway_container *child);

@ -99,7 +99,8 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
struct wlr_output *wlr_output = output->sway_output->wlr_output;
if (oc && oc->enabled == 0) {
wlr_output_layout_remove(root_container.output_layout, wlr_output);
wlr_output_layout_remove(root_container.sway_root->output_layout,
wlr_output);
destroy_output(output);
return;
}
@ -117,19 +118,21 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
if (oc && oc->transform >= 0) {
sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
wlr_output_transform(wlr_output, oc->transform);
wl_signal_emit(&output->sway_output->events.transform, output->sway_output);
wl_signal_emit(&output->sway_output->events.transform,
output->sway_output);
}
// 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);
wlr_output_layout_add(root_container.output_layout, wlr_output, oc->x,
oc->y);
wlr_output_layout_add(root_container.sway_root->output_layout,
wlr_output, oc->x, oc->y);
} else {
wlr_output_layout_add_auto(root_container.output_layout, wlr_output);
wlr_output_layout_add_auto(root_container.sway_root->output_layout,
wlr_output);
}
struct wlr_box *output_layout_box =
wlr_output_layout_get_box(root_container.output_layout, wlr_output);
struct wlr_box *output_layout_box = wlr_output_layout_get_box(
root_container.sway_root->output_layout, wlr_output);
output->x = output_layout_box->x;
output->y = output_layout_box->y;
output->width = output_layout_box->width;

@ -72,8 +72,7 @@ static void output_frame_view(swayc_t *view, void *data) {
}
static void output_frame_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of(
listener, soutput, frame);
struct sway_output *soutput = wl_container_of(listener, soutput, frame);
struct wlr_output *wlr_output = data;
struct sway_server *server = soutput->server;
@ -93,20 +92,17 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
}
static void output_resolution_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of(
listener, soutput, resolution);
struct sway_output *soutput = wl_container_of(listener, soutput, resolution);
arrange_windows(soutput->swayc, -1, -1);
}
static void output_scale_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of(
listener, soutput, scale);
struct sway_output *soutput = wl_container_of(listener, soutput, scale);
arrange_windows(soutput->swayc, -1, -1);
}
static void output_transform_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of(
listener, soutput, transform);
struct sway_output *soutput = wl_container_of(listener, soutput, transform);
arrange_windows(soutput->swayc, -1, -1);
}

@ -55,7 +55,7 @@ static void set_position(struct sway_view *view, double ox, double oy) {
if (!sway_assert(root, "output must be within tree to set position")) {
return;
}
struct wlr_output_layout *layout = root->output_layout;
struct wlr_output_layout *layout = root->sway_root->output_layout;
struct wlr_output_layout_output *loutput =
wlr_output_layout_get(layout, output->sway_output->wlr_output);
if (!sway_assert(loutput, "output must be within layout to set position")) {
@ -147,14 +147,14 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
// TODO remove from the tree when the surface goes away (unmapped)
sway_view->surface = xsurface->surface;
sway_surface->view = sway_view;
// TODO:
// - Wire up listeners
// - Handle popups
// - Look up pid and open on appropriate workspace
// - Set new view to maximized so it behaves nicely
// - Criteria
sway_surface->commit.notify = handle_commit;
wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit);
sway_surface->destroy.notify = handle_destroy;

@ -26,13 +26,6 @@ void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
}
}
static void update_root_geometry() {
struct wlr_box *box =
wlr_output_layout_get_box(root_container.output_layout, NULL);
root_container.width = box->width;
root_container.height = box->height;
}
static swayc_t *new_swayc(enum swayc_types type) {
// next id starts at 1 because 0 is assigned to root_container in layout.c
static size_t next_id = 1;
@ -94,7 +87,6 @@ swayc_t *new_output(struct sway_output *sway_output) {
sway_log(L_DEBUG, "Creating default workspace %s", ws_name);
new_workspace(output, ws_name);
free(ws_name);
update_root_geometry();
return output;
}
@ -195,7 +187,6 @@ swayc_t *destroy_output(swayc_t *output) {
sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
free_swayc(output);
update_root_geometry();
return &root_container;
}

@ -7,6 +7,7 @@
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include "sway/container.h"
#include "sway/layout.h"
#include "sway/output.h"
#include "sway/view.h"
#include "list.h"
@ -14,13 +15,27 @@
swayc_t root_container;
static void output_layout_change_notify(struct wl_listener *listener, void *data) {
struct wlr_box *box = wlr_output_layout_get_box(
root_container.sway_root->output_layout, NULL);
root_container.width = box->width;
root_container.height = box->height;
}
void init_layout(void) {
root_container.id = 0; // normally assigned in new_swayc()
root_container.type = C_ROOT;
root_container.layout = L_NONE;
root_container.name = strdup("root");
root_container.children = create_list();
root_container.output_layout = wlr_output_layout_create();
root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
root_container.sway_root->output_layout = wlr_output_layout_create();
root_container.sway_root->output_layout_change.notify =
output_layout_change_notify;
wl_signal_add(&root_container.sway_root->output_layout->events.change,
&root_container.sway_root->output_layout_change);
}
void add_child(swayc_t *parent, swayc_t *child) {

Loading…
Cancel
Save