Skip to content

Commit

Permalink
refactor immersive backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Aki-7 committed Apr 1, 2023
1 parent fec90fa commit 68b7375
Show file tree
Hide file tree
Showing 36 changed files with 496 additions and 510 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once

#ifdef __cplusplus

// NOLINTBEGIN(bugprone-macro-parentheses)
#define DISABLE_MOVE_AND_COPY(Class) \
Class(const Class &) = delete; \
Class(Class &&) = delete; \
Class &operator=(const Class &) = delete; \
Class &operator=(Class &&) = delete
// NOLINTEND(bugprone-macro-parentheses)

#endif
16 changes: 1 addition & 15 deletions common/include/zen-common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#error "This header is not for C++"
#endif

/** Visibility attribute */
Expand Down Expand Up @@ -41,17 +41,3 @@ zalloc(size_t size)
/** Retrieve a pointer to a containing struct */
#define zn_container_of(ptr, sample, member) \
(__typeof__(sample))((char *)(ptr)-offsetof(__typeof__(*(sample)), member))

#ifdef __cplusplus

#define DISABLE_MOVE_AND_COPY(Class) \
Class(const Class &) = delete; \
Class(Class &&) = delete; \
Class &operator=(const Class &) = delete; \
Class &operator=(Class &&) = delete

#endif

#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions desktop/include/zen-desktop/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct zn_desktop_shell {

struct zn_theme *theme; // @nonnull, @owning

struct wl_listener new_xr_system_listener;
struct wl_listener new_screen_listener;
struct wl_listener seat_capabilities_listener;
struct wl_listener pointer_motion_listener;
Expand Down
18 changes: 18 additions & 0 deletions desktop/include/zen-desktop/xr-system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <wayland-server-core.h>

struct zn_xr_system;
struct zn_desktop_server_xr_system;

struct zn_desktop_xr_system {
struct zn_xr_system *zn_xr_system; // @nonnull, @outlive

struct wl_global *global; // @nonnull, @owning
struct wl_list resource_list; // wl_resource::link of zen_xr_system

struct wl_listener zn_xr_system_destroy_listener;
};

struct zn_desktop_xr_system *zn_desktop_xr_system_create(
struct zn_xr_system *zn_xr_system, struct wl_display *display);
4 changes: 4 additions & 0 deletions desktop/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ _zen_desktop_srcs = [
'src/ui/decoration/shadow.c',

'src/view.c',
'src/xr-system.c',

protocols_code['zen-desktop'],
protocols_server_header['zen-desktop'],
]

_zen_desktop_inc = include_directories('include')
Expand Down
17 changes: 17 additions & 0 deletions desktop/src/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "zen-desktop/screen.h"
#include "zen-desktop/theme.h"
#include "zen-desktop/view.h"
#include "zen-desktop/xr-system.h"
#include "zen/backend.h"
#include "zen/screen.h"
#include "zen/seat.h"
Expand All @@ -20,6 +21,17 @@
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static struct zn_desktop_shell *desktop_shell_singleton = NULL;

static void
zn_desktop_shell_handle_new_xr_system(
struct wl_listener *listener UNUSED, void *data)
{
struct zn_server *server = zn_server_get_singleton();

struct zn_xr_system *zn_xr_system = data;

zn_desktop_xr_system_create(zn_xr_system, server->display);
}

static void
zn_desktop_shell_handle_new_screen(struct wl_listener *listener, void *data)
{
Expand Down Expand Up @@ -174,6 +186,10 @@ zn_desktop_shell_create(void)
}
self->cursor_grab = &cursor_default_grab->base;

self->new_xr_system_listener.notify = zn_desktop_shell_handle_new_xr_system;
wl_signal_add(
&server->backend->events.new_xr_system, &self->new_xr_system_listener);

self->new_screen_listener.notify = zn_desktop_shell_handle_new_screen;
wl_signal_add(
&server->backend->events.new_screen, &self->new_screen_listener);
Expand Down Expand Up @@ -229,6 +245,7 @@ zn_desktop_shell_destroy(struct zn_desktop_shell *self)
wl_list_remove(&self->pointer_motion_listener.link);
wl_list_remove(&self->seat_capabilities_listener.link);
wl_list_remove(&self->new_screen_listener.link);
wl_list_remove(&self->new_xr_system_listener.link);
zn_cursor_grab_destroy(self->cursor_grab);
zn_screen_layout_destroy(self->screen_layout);
zn_theme_destroy(self->theme);
Expand Down
97 changes: 97 additions & 0 deletions desktop/src/xr-system.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "zen-desktop/xr-system.h"

#include <zen-desktop-protocol.h>

#include "zen-common/log.h"
#include "zen-common/util.h"
#include "zen/xr-system.h"

static void zn_desktop_xr_system_destroy(struct zn_desktop_xr_system *self);

static void
zn_desktop_xr_system_handle_destroy(struct wl_resource *resource)
{
wl_list_remove(wl_resource_get_link(resource));
}

static void
zn_desktop_xr_system_protocol_connect(
struct wl_client *client UNUSED, struct wl_resource *resource UNUSED)
{}

static const struct zen_xr_system_interface implementation = {
.connect = zn_desktop_xr_system_protocol_connect,
};

static void
zn_desktop_xr_system_bind(
struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
struct zn_desktop_xr_system *self = data;

struct wl_resource *resource =
wl_resource_create(client, &zen_xr_system_interface, (int)version, id);
if (resource == NULL) {
zn_error("Failed to create a wl_resource");
wl_client_post_no_memory(client);
return;
}

wl_resource_set_implementation(
resource, &implementation, self, zn_desktop_xr_system_handle_destroy);

wl_list_insert(&self->resource_list, wl_resource_get_link(resource));
}

static void
zn_desktop_xr_system_handle_xr_system_destroy(
struct wl_listener *listener, void *data UNUSED)
{
struct zn_desktop_xr_system *self =
zn_container_of(listener, self, zn_xr_system_destroy_listener);

zn_desktop_xr_system_destroy(self);
}

struct zn_desktop_xr_system *
zn_desktop_xr_system_create(
struct zn_xr_system *zn_xr_system, struct wl_display *display)
{
struct zn_desktop_xr_system *self = zalloc(sizeof *self);
if (self == NULL) {
zn_error("Failed to allocate memory");
goto err;
}

self->zn_xr_system = zn_xr_system;
wl_list_init(&self->resource_list);

self->global = wl_global_create(
display, &zen_xr_system_interface, 1, self, zn_desktop_xr_system_bind);
if (self->global == NULL) {
zn_error("Failed to create a wl_global");
goto err_free;
}

self->zn_xr_system_destroy_listener.notify =
zn_desktop_xr_system_handle_xr_system_destroy;
wl_signal_add(
&zn_xr_system->events.destroy, &self->zn_xr_system_destroy_listener);

return self;

err_free:
free(self);

err:
return NULL;
}

static void
zn_desktop_xr_system_destroy(struct zn_desktop_xr_system *self)
{
wl_list_remove(&self->zn_xr_system_destroy_listener.link);
wl_global_destroy(self->global);
wl_list_remove(&self->resource_list);
free(self);
}
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ configure_file(
wayland_req = '>= 1.18.0'
wayland_protocols_req = '>= 1.24'
wlroots_req = ['>= 0.15', '< 0.16']
zen_protocols_req = '0.1.0'
zen_remote_server_req = '0.1.1'


Expand All @@ -143,6 +144,7 @@ wayland_protocols_dep = dependency('wayland-protocols', version: wayland_protoco
wayland_scanner_dep = dependency('wayland-scanner', native: true)
wayland_server_dep = dependency('wayland-server', version: wayland_req)
xkbcommon_dep = dependency('xkbcommon')
zen_protocols_dep = dependency('zen-protocols', version: zen_protocols_req)
zen_remote_server_dep = dependency('zen-remote-server', version: zen_remote_server_req)

subdir('protocol')
Expand All @@ -163,7 +165,6 @@ if get_option('tests')
subdir('test-harness')
endif
subdir('common')
subdir('zen-xr')
subdir('zen-wlr-glew-renderer')
subdir('zen')
subdir('desktop')
Expand Down
16 changes: 10 additions & 6 deletions protocol/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
wl_protocol_dir = wayland_protocols_dep.get_variable('pkgdatadir')
zen_protocol_dir = zen_protocols_dep.get_variable('pkgdatadir')

wayland_scanner = find_program(
wayland_scanner_dep.get_variable('wayland_scanner'),
Expand All @@ -8,11 +9,11 @@ wayland_scanner = find_program(
protocols = {
'xdg-shell': wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',

'zen-desktop': zen_protocol_dir / 'unstable/zen-desktop.xml',

'wlr-layer-shell-unstable-v1': 'wlr-layer-shell-unstable-v1.xml',
}

wlroots_srcs = []

protocols_code = {}
protocols_server_header = {}
protocols_client_header = {}
Expand All @@ -24,17 +25,13 @@ foreach name, path : protocols
command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
)

wlroots_srcs += code

server_header = custom_target(
name.underscorify() + '_server_h',
input: path,
output: '@[email protected]',
command: [wayland_scanner, 'server-header', '@INPUT@', '@OUTPUT@'],
)

wlroots_srcs += server_header

client_header = custom_target(
name.underscorify() + '_client_h',
input: path,
Expand All @@ -47,3 +44,10 @@ foreach name, path : protocols
protocols_server_header += { name: server_header }
protocols_client_header += { name: client_header }
endforeach

wlroots_srcs = [
protocols_code['wlr-layer-shell-unstable-v1'],
protocols_code['xdg-shell'],
protocols_server_header['wlr-layer-shell-unstable-v1'],
protocols_server_header['xdg-shell'],
]
19 changes: 0 additions & 19 deletions zen-xr/include/zen-xr/system.h

This file was deleted.

27 changes: 0 additions & 27 deletions zen-xr/include/zen-xr/xr.h

This file was deleted.

31 changes: 0 additions & 31 deletions zen-xr/meson.build

This file was deleted.

9 changes: 0 additions & 9 deletions zen-xr/src/common.h

This file was deleted.

Loading

0 comments on commit 68b7375

Please sign in to comment.