Skip to content

Commit

Permalink
feat: add wallpaper protocol
Browse files Browse the repository at this point in the history
Log: add wallpaper protocol
  • Loading branch information
zorowk committed Dec 12, 2023
1 parent f9762bb commit c3903a1
Show file tree
Hide file tree
Showing 16 changed files with 795 additions and 56 deletions.
2 changes: 2 additions & 0 deletions src/treeland/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ endfunction()
ws_generate_local(server ${CMAKE_CURRENT_SOURCE_DIR}/ztreeland-shortcut-manager-v1.xml shortcut-server-protocol)
ws_generate_local(server ${CMAKE_CURRENT_SOURCE_DIR}/treeland-socket-manager-v1.xml socket-server-protocol)
ws_generate_local(server ${CMAKE_CURRENT_SOURCE_DIR}/treeland-foreign-toplevel-manager-v1.xml foreign-toplevel-manager-server-protocol)
ws_generate_local(server ${CMAKE_CURRENT_SOURCE_DIR}/treeland-personalization-manager-v1.xml personalization-server-protocol)

ws_generate(server wayland-protocols stable/xdg-shell/xdg-shell.xml xdg-shell-protocol)
ws_generate(server wayland-protocols staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml ext-foreign-toplevel-list-server-protocol)
Expand All @@ -51,6 +52,7 @@ add_library(treeland-data STATIC)
target_sources(treeland-data PRIVATE
socket-server-protocol.c
shortcut-server-protocol.c
personalization-server-protocol.c
foreign-toplevel-manager-server-protocol.c
ext-foreign-toplevel-list-server-protocol.c
)
Expand Down
79 changes: 28 additions & 51 deletions src/treeland/data/treeland-personalization-manager-v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,54 @@

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="treeland_personalization_manager_v1" version="1">
<description summary="personalization manager">
This interface allows a client to customized display effects.
This interface allows a client to customized display effects.

Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>
<request name="get_wallpaper_context">
<arg name="id" type="new_id" interface="treeland_wallpaper_context_v1" />
</request>
<request name="get_window_context">
<arg name="surface" type="object" interface="wl_surface" />
<arg name="id" type="new_id" interface="treeland_window_context_v1" />
<arg name="id" type="new_id" interface="personalization_window_context_v1"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
</interface>
<interface name="treeland_wallpaper_context_v1" version="1">
<description summary="client wallpaper context">
This interface allows a client set window wallpaper.
<interface name="personalization_window_context_v1" version="1">
<description summary="client custom window context">
This interface allows a client personalization window.

Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the context object">
Destroy the context object.
<enum name="background_type">
<description summary="Windows will have different background effects">
This will instruct the compositor how to set the background
for the window, desktop.
</description>
</request>
</interface>
<interface name="treeland_window_context_v1" version="1">
<description summary="client window context">
This interface allows a client set window properties.

Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>
<request name="set_radius">
<description summary="the radius which represents the toplevel">
The radius of the surface specified in this request corresponds to the place where
the app using this protocol represents the given toplevel.
</description>

<arg name="x" type="int" />
<arg name="y" type="int" />
</request>
<request name="set_no_titlebar">
<description summary="toplevel doesn't need titlebar">
When the value is non-zero, the toplevel titlebar will be disabled.
<entry name="normal" value="0" summary="not draw the background image"/>
<entry name="wallpaper" value="1" summary="draw the background image"/>
<entry name="blend" value="2" summary="draw the blend background image"/>
</enum>
<request name="set_background_type">
<description summary="set window background type">
Destroy the context object.
</description>

<arg name="value" type="int" />
<arg name="type" type="uint" summary="background enum"/>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the context object">
Destroy the context object.
</description>
</request>
<enum name="error">
<entry name="invalid_radius" value="0"
summary="the provided radius is invalid" />
</enum>
</interface>
</protocol>
</protocol>
5 changes: 5 additions & 0 deletions src/treeland/protocols/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ FILES
ext_foreign_toplevel_list_impl.h
foreigntoplevelhandlev1.h
foreign_toplevel_manager_impl.h
personalization_manager_impl.h
personalizationmanager.h
shortcut_manager_impl.h
socket_manager_impl.h
utils.h
Expand All @@ -20,6 +22,9 @@ target_sources(treeland-protocols PRIVATE
ext_foreign_toplevel_list_impl.cpp
foreigntoplevelhandlev1.cpp
foreigntoplevelmanagerv1.cpp
personalization_manager_impl.cpp
personalizationwindowcontext.cpp
personalizationmanager.cpp
)

target_compile_definitions(treeland-protocols
Expand Down
201 changes: 201 additions & 0 deletions src/treeland/protocols/personalization_manager_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// Copyright (C) 2023 WenHao Peng <[email protected]>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "personalization_manager_impl.h"

#include "personalization-server-protocol.h"

#include <cassert>

extern "C" {
#define static
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_compositor.h>
#undef static
}

#define TREELAND_PERSONALIZATION_MANAGEMENT_V1_VERSION 1

struct personalization_window_context_v1 *personalization_window_from_resource(
struct wl_resource *resource);

static void personalization_window_context_destroy([[maybe_unused]] struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy(resource);
}

static void personalization_window_context_set_background_type([[maybe_unused]] struct wl_client *client,
struct wl_resource *resource,
uint32_t type)
{
struct personalization_window_context_v1 *window = personalization_window_from_resource(resource);
if (!window) {
return;
}

window->background_type = type;
wl_signal_emit_mutable(&window->events.set_background_type, window);
}

static const struct personalization_window_context_v1_interface personalization_window_context_impl = {
.set_background_type = personalization_window_context_set_background_type,
.destroy = personalization_window_context_destroy,
};

struct personalization_window_context_v1 *personalization_window_from_resource(
struct wl_resource *resource)
{
assert(wl_resource_instance_of(resource,
&personalization_window_context_v1_interface,
&personalization_window_context_impl));
return static_cast<struct personalization_window_context_v1 *>(
wl_resource_get_user_data(resource));
}

void personalization_window_context_v1_destroy(

Check warning on line 59 in src/treeland/protocols/personalization_manager_impl.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'personalization_window_context_v1_destroy' is never used.
struct personalization_window_context_v1 *window)
{
if (!window) {
return;
}

wl_signal_emit_mutable(&window->events.destroy, window);

wl_list_remove(&window->link);

free(window);
}

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

void create_personalization_window_context_listener(struct wl_client *client,
struct wl_resource *manager_resource,
uint32_t id,
struct wl_resource *surface);

static const struct treeland_personalization_manager_v1_interface
treeland_personalization_manager_impl = {
.get_window_context = create_personalization_window_context_listener
};

struct treeland_personalization_manager_v1 *treeland_personalization_manager_from_resource(
struct wl_resource *resource)
{
assert(wl_resource_instance_of(
resource, &treeland_personalization_manager_v1_interface, &treeland_personalization_manager_impl));
struct treeland_personalization_manager_v1 *manager =
static_cast<treeland_personalization_manager_v1 *>(
wl_resource_get_user_data(resource));
assert(manager != NULL);
return manager;
}

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

void create_personalization_window_context_listener(struct wl_client *client,
struct wl_resource *manager_resource,
uint32_t id,
struct wl_resource *surface)
{

struct treeland_personalization_manager_v1 *manager = treeland_personalization_manager_from_resource(manager_resource);

struct personalization_window_context_v1 *context = static_cast<personalization_window_context_v1*>(calloc(1, sizeof(*context)));
if (context == NULL) {
wl_resource_post_no_memory(manager_resource);
return;
}

context->manager = manager;

wl_list_init(&context->resources);
wl_list_init(&context->link);
wl_signal_init(&context->events.set_background_type);
wl_signal_init(&context->events.destroy);

uint32_t version = wl_resource_get_version(manager_resource);
struct wl_resource *resource = wl_resource_create(client, &personalization_window_context_v1_interface, version, id);
if (resource == NULL) {
free(context);
wl_resource_post_no_memory(manager_resource);
return;
}

context->surface = wlr_surface_from_resource(surface);

wl_resource_set_implementation(resource, &personalization_window_context_impl, context, personalization_window_context_resource_destroy);

wl_list_insert(&manager->resources, wl_resource_get_link(resource));
wl_signal_emit_mutable(&manager->events.window_context_created, context);
}

static void treeland_personalization_manager_bind(struct wl_client *client,
void *data,
uint32_t version,
uint32_t id)
{
struct treeland_personalization_manager_v1 *manager =
static_cast<struct treeland_personalization_manager_v1 *>(data);
struct wl_resource *resource =
wl_resource_create(client, &treeland_personalization_manager_v1_interface, version, id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource,
&treeland_personalization_manager_impl,
manager,
treeland_personalization_manager_resource_destroy);

wl_list_insert(&manager->resources, wl_resource_get_link(resource));
}

static void handle_display_destroy(struct wl_listener *listener, [[maybe_unused]] void *data)
{
struct treeland_personalization_manager_v1 *manager =
wl_container_of(listener, manager, display_destroy);
wl_signal_emit_mutable(&manager->events.destroy, manager);
wl_list_remove(&manager->display_destroy.link);
wl_global_destroy(manager->global);
free(manager);
}

struct treeland_personalization_manager_v1 *
treeland_personalization_manager_v1_create(struct wl_display *display)

Check warning on line 174 in src/treeland/protocols/personalization_manager_impl.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'treeland_personalization_manager_v1_create' is never used.
{
struct treeland_personalization_manager_v1 *manager =
static_cast<struct treeland_personalization_manager_v1 *>(calloc(1, sizeof(*manager)));
if (!manager) {
return NULL;
}

manager->event_loop = wl_display_get_event_loop(display);
manager->global = wl_global_create(display,
&treeland_personalization_manager_v1_interface,
TREELAND_PERSONALIZATION_MANAGEMENT_V1_VERSION,
manager,
treeland_personalization_manager_bind);
if (!manager->global) {
free(manager);
return NULL;
}

wl_signal_init(&manager->events.destroy);
wl_signal_init(&manager->events.window_context_created);
wl_list_init(&manager->resources);

manager->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &manager->display_destroy);

return manager;
}
42 changes: 42 additions & 0 deletions src/treeland/protocols/personalization_manager_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2023 WenHao Peng <[email protected]>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include <wayland-server-core.h>

struct treeland_personalization_manager_v1 {
struct wl_event_loop *event_loop;
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link()

struct wl_listener display_destroy;

struct {
struct wl_signal window_context_created;
struct wl_signal destroy;
} events;

void *data;
};

struct personalization_window_context_v1 {
struct treeland_personalization_manager_v1 *manager;
struct wlr_surface *surface;
struct wl_list resources;
struct wl_list link;
uint32_t background_type;

struct {
struct wl_signal set_background_type;
struct wl_signal destroy;
} events;

void *data;
};

struct treeland_personalization_manager_v1 *
treeland_personalization_manager_v1_create(struct wl_display *display);

void personalization_window_context_v1_destroy(
struct personalization_window_context_v1 *window);
Loading

0 comments on commit c3903a1

Please sign in to comment.