mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 06:24:20 +01:00
Listen to output layout change
This commit is contained in:
parent
f3d880b0ec
commit
c7abb77f22
@ -57,9 +57,9 @@ enum swayc_border_types {
|
|||||||
B_NORMAL, /**< Normal border with title bar */
|
B_NORMAL, /**< Normal border with title bar */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sway_root;
|
||||||
struct sway_output;
|
struct sway_output;
|
||||||
struct sway_view;
|
struct sway_view;
|
||||||
struct wlr_output_layout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores information about a container.
|
* Stores information about a container.
|
||||||
@ -69,7 +69,7 @@ struct wlr_output_layout;
|
|||||||
struct sway_container {
|
struct sway_container {
|
||||||
union {
|
union {
|
||||||
// TODO: Encapsulate state for other node types as well like C_CONTAINER
|
// 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_output *sway_output; // C_OUTPUT
|
||||||
struct sway_view *sway_view; // C_VIEW
|
struct sway_view *sway_view; // C_VIEW
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
#ifndef _SWAY_LAYOUT_H
|
#ifndef _SWAY_LAYOUT_H
|
||||||
#define _SWAY_LAYOUT_H
|
#define _SWAY_LAYOUT_H
|
||||||
|
|
||||||
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
|
|
||||||
struct sway_container;
|
struct sway_container;
|
||||||
|
|
||||||
|
struct sway_root {
|
||||||
|
struct wlr_output_layout *output_layout;
|
||||||
|
|
||||||
|
struct wl_listener output_layout_change;
|
||||||
|
};
|
||||||
|
|
||||||
void init_layout(void);
|
void init_layout(void);
|
||||||
void add_child(struct sway_container *parent, struct sway_container *child);
|
void add_child(struct sway_container *parent, struct sway_container *child);
|
||||||
struct sway_container *remove_child(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;
|
struct wlr_output *wlr_output = output->sway_output->wlr_output;
|
||||||
if (oc && oc->enabled == 0) {
|
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);
|
destroy_output(output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -117,19 +118,21 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
|||||||
if (oc && oc->transform >= 0) {
|
if (oc && oc->transform >= 0) {
|
||||||
sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
|
sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
|
||||||
wlr_output_transform(wlr_output, 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
|
// Find position for it
|
||||||
if (oc && (oc->x != -1 || oc->y != -1)) {
|
if (oc && (oc->x != -1 || oc->y != -1)) {
|
||||||
sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
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,
|
wlr_output_layout_add(root_container.sway_root->output_layout,
|
||||||
oc->y);
|
wlr_output, oc->x, oc->y);
|
||||||
} else {
|
} 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 =
|
struct wlr_box *output_layout_box = wlr_output_layout_get_box(
|
||||||
wlr_output_layout_get_box(root_container.output_layout, wlr_output);
|
root_container.sway_root->output_layout, wlr_output);
|
||||||
output->x = output_layout_box->x;
|
output->x = output_layout_box->x;
|
||||||
output->y = output_layout_box->y;
|
output->y = output_layout_box->y;
|
||||||
output->width = output_layout_box->width;
|
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) {
|
static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||||
struct sway_output *soutput = wl_container_of(
|
struct sway_output *soutput = wl_container_of(listener, soutput, frame);
|
||||||
listener, soutput, frame);
|
|
||||||
struct wlr_output *wlr_output = data;
|
struct wlr_output *wlr_output = data;
|
||||||
struct sway_server *server = soutput->server;
|
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) {
|
static void output_resolution_notify(struct wl_listener *listener, void *data) {
|
||||||
struct sway_output *soutput = wl_container_of(
|
struct sway_output *soutput = wl_container_of(listener, soutput, resolution);
|
||||||
listener, soutput, resolution);
|
|
||||||
arrange_windows(soutput->swayc, -1, -1);
|
arrange_windows(soutput->swayc, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_scale_notify(struct wl_listener *listener, void *data) {
|
static void output_scale_notify(struct wl_listener *listener, void *data) {
|
||||||
struct sway_output *soutput = wl_container_of(
|
struct sway_output *soutput = wl_container_of(listener, soutput, scale);
|
||||||
listener, soutput, scale);
|
|
||||||
arrange_windows(soutput->swayc, -1, -1);
|
arrange_windows(soutput->swayc, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_transform_notify(struct wl_listener *listener, void *data) {
|
static void output_transform_notify(struct wl_listener *listener, void *data) {
|
||||||
struct sway_output *soutput = wl_container_of(
|
struct sway_output *soutput = wl_container_of(listener, soutput, transform);
|
||||||
listener, soutput, transform);
|
|
||||||
arrange_windows(soutput->swayc, -1, -1);
|
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")) {
|
if (!sway_assert(root, "output must be within tree to set position")) {
|
||||||
return;
|
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 =
|
struct wlr_output_layout_output *loutput =
|
||||||
wlr_output_layout_get(layout, output->sway_output->wlr_output);
|
wlr_output_layout_get(layout, output->sway_output->wlr_output);
|
||||||
if (!sway_assert(loutput, "output must be within layout to set position")) {
|
if (!sway_assert(loutput, "output must be within layout to set position")) {
|
||||||
|
@ -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) {
|
static swayc_t *new_swayc(enum swayc_types type) {
|
||||||
// next id starts at 1 because 0 is assigned to root_container in layout.c
|
// next id starts at 1 because 0 is assigned to root_container in layout.c
|
||||||
static size_t next_id = 1;
|
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);
|
sway_log(L_DEBUG, "Creating default workspace %s", ws_name);
|
||||||
new_workspace(output, ws_name);
|
new_workspace(output, ws_name);
|
||||||
free(ws_name);
|
free(ws_name);
|
||||||
update_root_geometry();
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +187,6 @@ swayc_t *destroy_output(swayc_t *output) {
|
|||||||
|
|
||||||
sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
|
sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
|
||||||
free_swayc(output);
|
free_swayc(output);
|
||||||
update_root_geometry();
|
|
||||||
|
|
||||||
return &root_container;
|
return &root_container;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
#include "sway/container.h"
|
#include "sway/container.h"
|
||||||
|
#include "sway/layout.h"
|
||||||
#include "sway/output.h"
|
#include "sway/output.h"
|
||||||
#include "sway/view.h"
|
#include "sway/view.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
@ -14,13 +15,27 @@
|
|||||||
|
|
||||||
swayc_t root_container;
|
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) {
|
void init_layout(void) {
|
||||||
root_container.id = 0; // normally assigned in new_swayc()
|
root_container.id = 0; // normally assigned in new_swayc()
|
||||||
root_container.type = C_ROOT;
|
root_container.type = C_ROOT;
|
||||||
root_container.layout = L_NONE;
|
root_container.layout = L_NONE;
|
||||||
root_container.name = strdup("root");
|
root_container.name = strdup("root");
|
||||||
root_container.children = create_list();
|
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) {
|
void add_child(swayc_t *parent, swayc_t *child) {
|
||||||
|
Loading…
Reference in New Issue
Block a user