Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wlroots 0.17 #281

Merged
merged 18 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
CC: [ gcc, clang ]
OS: [ "alpine:edge", "archlinux:base-devel" ]
xwayland: [ true, false ]
xwayland: [ enabled, disabled ]
container: ${{ matrix.OS }}
env:
CC: ${{ matrix.CC }}
Expand All @@ -23,7 +23,7 @@ jobs:

- name: Install dependencies (Alpine)
if: "matrix.OS == 'alpine:edge'"
run: apk add build-base xcb-util-wm-dev libseat-dev clang git eudev-dev mesa-dev libdrm-dev libinput-dev libxkbcommon-dev pixman-dev wayland-dev meson wayland-protocols xwayland scdoc-doc hwdata
run: apk add build-base xcb-util-wm-dev libseat-dev clang git eudev-dev mesa-dev libdrm-dev libinput-dev libxkbcommon-dev pixman-dev wayland-dev meson wayland-protocols xwayland-dev scdoc-doc hwdata

- name: Install dependencies (Arch)
if: "matrix.OS == 'archlinux:base-devel'"
Expand All @@ -32,7 +32,7 @@ jobs:
pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc

- name: Fetch wlroots as a subproject
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.16.0
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.17

# TODO: use --fatal-meson-warnings when on wlroots 0.15.0
- name: Compile Cage (XWayland=${{ matrix.xwayland }})
Expand All @@ -51,10 +51,10 @@ jobs:
pacman-key --init
pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc hwdata
- name: Fetch wlroots as a subproject
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.16.0
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.17
- name: Check for formatting changes
run: |
meson build-clang-format -Dxwayland=true
meson build-clang-format -Dxwayland=enabled
ninja -C build-clang-format clang-format-check

scan-build:
Expand All @@ -70,8 +70,8 @@ jobs:
pacman-key --init
pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc hwdata
- name: Fetch wlroots as a subproject
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.16.0
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.17
- name: Run scan-build
run: |
meson build-scan-build -Dxwayland=true
meson build-scan-build -Dxwayland=enabled
ninja -C build-scan-build scan-build
10 changes: 5 additions & 5 deletions cage.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_presentation_time.h>
Expand Down Expand Up @@ -293,7 +293,7 @@ main(int argc, char *argv[])
struct wl_event_source *sigterm_source =
wl_event_loop_add_signal(event_loop, SIGTERM, handle_signal, &server.wl_display);

server.backend = wlr_backend_autocreate(server.wl_display);
server.backend = wlr_backend_autocreate(server.wl_display, &server.session);
if (!server.backend) {
wlr_log(WLR_ERROR, "Unable to create the wlroots backend");
ret = 1;
Expand Down Expand Up @@ -340,9 +340,9 @@ main(int argc, char *argv[])
goto end;
}

wlr_scene_attach_output_layout(server.scene, server.output_layout);
server.scene_output_layout = wlr_scene_attach_output_layout(server.scene, server.output_layout);

struct wlr_compositor *compositor = wlr_compositor_create(server.wl_display, server.renderer);
struct wlr_compositor *compositor = wlr_compositor_create(server.wl_display, 6, server.renderer);
if (!compositor) {
wlr_log(WLR_ERROR, "Unable to create the wlroots compositor");
ret = 1;
Expand Down Expand Up @@ -374,7 +374,7 @@ main(int argc, char *argv[])
goto end;
}

server.idle = wlr_idle_create(server.wl_display);
server.idle = wlr_idle_notifier_v1_create(server.wl_display);
if (!server.idle) {
wlr_log(WLR_ERROR, "Unable to create the idle tracker");
ret = 1;
Expand Down
4 changes: 2 additions & 2 deletions idle_inhibit_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <stdlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_idle_notify_v1.h>

#include "idle_inhibit_v1.h"
#include "server.h"
Expand All @@ -32,7 +32,7 @@ idle_inhibit_v1_check_active(struct cg_server *server)
Hence, we simply check for any inhibitors and inhibit
accordingly. */
bool inhibited = !wl_list_empty(&server->inhibitors);
wlr_idle_set_enabled(server->idle, NULL, !inhibited);
wlr_idle_notifier_v1_set_inhibited(server->idle, inhibited);
}

static void
Expand Down
6 changes: 3 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if is_freebsd
)
endif

wlroots = dependency('wlroots', version: '>= 0.16.0', fallback: ['wlroots', 'wlroots'])
wlroots = dependency('wlroots', version: '>= 0.17.0', fallback: ['wlroots', 'wlroots'])
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
wayland_server = dependency('wayland-server')
xkbcommon = dependency('xkbcommon')
Expand Down Expand Up @@ -64,9 +64,9 @@ server_protos = declare_dependency(
sources: server_protos_headers,
)

if get_option('xwayland')
if not get_option('xwayland').disabled()
wlroots_has_xwayland = wlroots.get_variable(pkgconfig: 'have_xwayland', internal: 'have_xwayland') == 'true'
if not wlroots_has_xwayland
if get_option('xwayland').enabled() and not wlroots_has_xwayland
error('Cannot build Cage with XWayland support: wlroots has been built without it')
endif
have_xwayland = true
Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
option('xwayland', type: 'boolean', value: false, description: 'Enable support for X11 applications')
option('xwayland', type: 'feature', value: 'auto', description: 'Enable support for X11 applications')
92 changes: 51 additions & 41 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_scene.h>
Expand All @@ -43,7 +42,7 @@
#endif

#define OUTPUT_CONFIG_UPDATED \
(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_SCALE | WLR_OUTPUT_STATE_TRANSFORM | \
(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_SCALE | WLR_OUTPUT_STATE_TRANSFORM | \
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED)

static void
Expand Down Expand Up @@ -71,24 +70,25 @@ update_output_manager_config(struct cg_server *server)
static inline void
output_layout_add_auto(struct cg_output *output)
{
wlr_output_layout_add_auto(output->server->output_layout, output->wlr_output);
output->scene_output = wlr_scene_get_scene_output(output->server->scene, output->wlr_output);
assert(output->scene_output != NULL);
struct wlr_output_layout_output *layout_output =
wlr_output_layout_add_auto(output->server->output_layout, output->wlr_output);
wlr_scene_output_layout_add_output(output->server->scene_output_layout, layout_output, output->scene_output);
}

static inline void
output_layout_add(struct cg_output *output, int32_t x, int32_t y)
{
wlr_output_layout_add(output->server->output_layout, output->wlr_output, x, y);
output->scene_output = wlr_scene_get_scene_output(output->server->scene, output->wlr_output);
assert(output->scene_output != NULL);
struct wlr_output_layout_output *layout_output =
wlr_output_layout_add(output->server->output_layout, output->wlr_output, x, y);
wlr_scene_output_layout_add_output(output->server->scene_output_layout, layout_output, output->scene_output);
}

static inline void
output_layout_remove(struct cg_output *output)
{
wlr_output_layout_remove(output->server->output_layout, output->wlr_output);
output->scene_output = NULL;
}

static void
Expand All @@ -101,9 +101,10 @@ output_enable(struct cg_output *output)
* duplicate the enabled property in cg_output. */
wlr_log(WLR_DEBUG, "Enabling output %s", wlr_output->name);

wlr_output_enable(wlr_output, true);
struct wlr_output_state state = {0};
wlr_output_state_set_enabled(&state, true);

if (wlr_output_commit(wlr_output)) {
if (wlr_output_commit_state(wlr_output, &state)) {
output_layout_add_auto(output);
}

Expand All @@ -114,44 +115,45 @@ static void
output_disable(struct cg_output *output)
{
struct wlr_output *wlr_output = output->wlr_output;

if (!wlr_output->enabled) {
wlr_log(WLR_DEBUG, "Not disabling already disabled output %s", wlr_output->name);
return;
}

wlr_log(WLR_DEBUG, "Disabling output %s", wlr_output->name);
wlr_output_enable(wlr_output, false);
wlr_output_commit(wlr_output);
struct wlr_output_state state = {0};
wlr_output_state_set_enabled(&state, false);
wlr_output_commit_state(wlr_output, &state);
output_layout_remove(output);
}

static bool
output_apply_config(struct cg_output *output, struct wlr_output_configuration_head_v1 *head, bool test_only)
{
wlr_output_enable(output->wlr_output, head->state.enabled);
struct wlr_output_state state = {0};
wlr_output_state_set_enabled(&state, head->state.enabled);

if (head->state.enabled) {
/* Do not mess with these parameters for output to be disabled */
wlr_output_set_scale(output->wlr_output, head->state.scale);
wlr_output_set_transform(output->wlr_output, head->state.transform);
wlr_output_state_set_scale(&state, head->state.scale);
wlr_output_state_set_transform(&state, head->state.transform);

if (head->state.mode) {
wlr_output_set_mode(output->wlr_output, head->state.mode);
wlr_output_state_set_mode(&state, head->state.mode);
} else {
wlr_output_set_custom_mode(output->wlr_output, head->state.custom_mode.width,
head->state.custom_mode.height, head->state.custom_mode.refresh);
wlr_output_state_set_custom_mode(&state, head->state.custom_mode.width,
head->state.custom_mode.height,
head->state.custom_mode.refresh);
}
}

if (test_only) {
bool ret = wlr_output_test(output->wlr_output);
wlr_output_rollback(output->wlr_output);
bool ret = wlr_output_test_state(output->wlr_output, &state);
return ret;
}

/* Apply output configuration */
if (!wlr_output_commit(output->wlr_output)) {
if (!wlr_output_commit_state(output->wlr_output, &state)) {
return false;
}

Expand All @@ -173,7 +175,7 @@ handle_output_frame(struct wl_listener *listener, void *data)
return;
}

wlr_scene_output_commit(output->scene_output);
wlr_scene_output_commit(output->scene_output, NULL);

struct timespec now = {0};
clock_gettime(CLOCK_MONOTONIC, &now);
Expand All @@ -190,22 +192,20 @@ handle_output_commit(struct wl_listener *listener, void *data)
* - output layout change will also be called if needed to position the views
* - always update output manager configuration even if the output is now disabled */

if (event->committed & OUTPUT_CONFIG_UPDATED) {
if (event->state->committed & OUTPUT_CONFIG_UPDATED) {
update_output_manager_config(output->server);
}
}

static void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading release notes for wlroots 0.17.0, it seems the WLR_OUTPUT_STATE_MODE flag is not expected to be handled in handle_output_commit()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we need to add WLR_OUTPUT_STATE_MODE to OUTPUT_CONFIG_UPDATED.

Maybe we also need to view_position_all()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are no longer expected to monitor mode changes in the commit handler, as this has moved to request_state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we still need to notify wlr-output-management-v1 clients of mode changes: #297

handle_output_mode(struct wl_listener *listener, void *data)
handle_output_request_state(struct wl_listener *listener, void *data)
{
struct cg_output *output = wl_container_of(listener, output, mode);
struct cg_output *output = wl_container_of(listener, output, request_state);
struct wlr_output_event_request_state *event = data;

if (!output->wlr_output->enabled) {
return;
if (wlr_output_commit_state(output->wlr_output, event->state)) {
update_output_manager_config(output->server);
}

view_position_all(output->server);
update_output_manager_config(output->server);
}

void
Expand Down Expand Up @@ -241,7 +241,7 @@ output_destroy(struct cg_output *output)

wl_list_remove(&output->destroy.link);
wl_list_remove(&output->commit.link);
wl_list_remove(&output->mode.link);
wl_list_remove(&output->request_state.link);
wl_list_remove(&output->frame.link);
wl_list_remove(&output->link);

Expand Down Expand Up @@ -290,30 +290,35 @@ handle_new_output(struct wl_listener *listener, void *data)

output->commit.notify = handle_output_commit;
wl_signal_add(&wlr_output->events.commit, &output->commit);
output->mode.notify = handle_output_mode;
wl_signal_add(&wlr_output->events.mode, &output->mode);
output->request_state.notify = handle_output_request_state;
wl_signal_add(&wlr_output->events.request_state, &output->request_state);
output->destroy.notify = handle_output_destroy;
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
output->frame.notify = handle_output_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);

if (!wl_list_empty(&wlr_output->modes)) {
/* Ensure the output is marked as enabled before trying to set mode */
wlr_output_enable(wlr_output, true);
output->scene_output = wlr_scene_output_create(server->scene, wlr_output);
emersion marked this conversation as resolved.
Show resolved Hide resolved
if (!output->scene_output) {
wlr_log(WLR_ERROR, "Failed to allocate scene output");
return;
}

struct wlr_output_state state = {0};
wlr_output_state_set_enabled(&state, true);
if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *preferred_mode = wlr_output_preferred_mode(wlr_output);
if (preferred_mode) {
wlr_output_set_mode(wlr_output, preferred_mode);
wlr_output_state_set_mode(&state, preferred_mode);
}
if (!wlr_output_test(wlr_output)) {
if (!wlr_output_test_state(wlr_output, &state)) {
struct wlr_output_mode *mode;
wl_list_for_each (mode, &wlr_output->modes, link) {
if (mode == preferred_mode) {
continue;
}

wlr_output_set_mode(wlr_output, mode);
if (wlr_output_test(wlr_output)) {
wlr_output_state_set_mode(&state, mode);
if (wlr_output_test_state(wlr_output, &state)) {
break;
}
}
Expand All @@ -330,8 +335,13 @@ handle_new_output(struct wl_listener *listener, void *data)
wlr_output->scale);
}

output_enable(output);
wlr_log(WLR_DEBUG, "Enabling new output %s", wlr_output->name);
if (wlr_output_commit_state(wlr_output, &state)) {
output_layout_add_auto(output);
}

view_position_all(output->server);
update_output_manager_config(output->server);
}

void
Expand Down
3 changes: 1 addition & 2 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <wayland-server-core.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_damage.h>

#include "server.h"
#include "view.h"
Expand All @@ -14,7 +13,7 @@ struct cg_output {
struct wlr_scene_output *scene_output;

struct wl_listener commit;
struct wl_listener mode;
struct wl_listener request_state;
struct wl_listener destroy;
struct wl_listener frame;

Expand Down
Loading
Loading