Clean up build scaffolding for libsfdo and add the creation and

destruction of an sfdo data structure associated with a sway server with
a view to future use of icon themes in places such as titlebars

Rebased from origin/master.

Rebased from origin/master.
This commit is contained in:
myrslint 2025-04-16 20:50:42 +00:00 committed by myrslint
parent faed98c402
commit b5dfcd96bc
3 changed files with 216 additions and 134 deletions

View file

@ -1,10 +1,10 @@
#ifndef _SWAY_SERVER_H #ifndef _SWAY_SERVER_H
#define _SWAY_SERVER_H #define _SWAY_SERVER_H
#include <stdbool.h>
#include <wayland-server-core.h>
#include "config.h" #include "config.h"
#include "list.h" #include "list.h"
#include "sway/desktop/idle_inhibit_v1.h" #include "sway/desktop/idle_inhibit_v1.h"
#include <stdbool.h>
#include <wayland-server-core.h>
#if WLR_HAS_XWAYLAND #if WLR_HAS_XWAYLAND
#include "sway/xwayland.h" #include "sway/xwayland.h"
#endif #endif
@ -28,6 +28,15 @@ struct sway_session_lock {
struct wl_listener destroy; struct wl_listener destroy;
}; };
#if HAVE_LIBSFDO
struct sfdo {
struct sfdo_desktop_ctx *desktop_ctx;
struct sfdo_icon_ctx *icon_ctx;
struct sfdo_desktop_db *desktop_db;
struct sfdo_icon_theme *icon_theme;
};
#endif
struct sway_server { struct sway_server {
struct wl_display *wl_display; struct wl_display *wl_display;
struct wl_event_loop *wl_event_loop; struct wl_event_loop *wl_event_loop;
@ -112,11 +121,13 @@ struct sway_server {
struct wlr_data_control_manager_v1 *wlr_data_control_manager_v1; struct wlr_data_control_manager_v1 *wlr_data_control_manager_v1;
struct wlr_ext_data_control_manager_v1 *ext_data_control_manager_v1; struct wlr_ext_data_control_manager_v1 *ext_data_control_manager_v1;
struct wlr_screencopy_manager_v1 *screencopy_manager_v1; struct wlr_screencopy_manager_v1 *screencopy_manager_v1;
struct wlr_ext_image_copy_capture_manager_v1 *ext_image_copy_capture_manager_v1; struct wlr_ext_image_copy_capture_manager_v1
*ext_image_copy_capture_manager_v1;
struct wlr_export_dmabuf_manager_v1 *export_dmabuf_manager_v1; struct wlr_export_dmabuf_manager_v1 *export_dmabuf_manager_v1;
struct wlr_security_context_manager_v1 *security_context_manager_v1; struct wlr_security_context_manager_v1 *security_context_manager_v1;
struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1 *ext_foreign_toplevel_image_capture_source_manager_v1; struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1
*ext_foreign_toplevel_image_capture_source_manager_v1;
struct wl_listener new_foreign_toplevel_capture_request; struct wl_listener new_foreign_toplevel_capture_request;
struct wlr_xdg_activation_v1 *xdg_activation_v1; struct wlr_xdg_activation_v1 *xdg_activation_v1;
@ -154,7 +165,6 @@ struct sway_server {
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
struct sfdo *sfdo; struct sfdo *sfdo;
#endif #endif
}; };
extern struct sway_server server; extern struct sway_server server;
@ -201,4 +211,9 @@ void set_rr_scheduling(void);
void handle_new_tearing_hint(struct wl_listener *listener, void *data); void handle_new_tearing_hint(struct wl_listener *listener, void *data);
#if HAVE_LIBSFDO
struct sfdo *sfdo_create(char *theme);
void sfdo_destroy(struct sfdo *sfdo);
#endif
#endif #endif

View file

@ -38,34 +38,6 @@ if is_freebsd
add_project_arguments('-D_C11_SOURCE', language: 'c') add_project_arguments('-D_C11_SOURCE', language: 'c')
endif endif
# Check for (currrently) optional libsfdo
sfdo_basedir = dependency(
'libsfdo-basedir',
default_options: ['default_library=static', 'examples=false', 'tests=false'],
version: '>=0.1.3',
required: get_option('sfdo'),
)
sfdo_desktop = dependency(
'libsfdo-desktop',
default_options: ['default_library=static', 'examples=false', 'tests=false'],
version: '>=0.1.3',
required: get_option('sfdo'),
)
sfdo_desktop_file = dependency(
'libsfdo-desktop-file',
default_options: ['default_library=static', 'examples=false', 'tests=false'],
version: '>=0.1.3',
required: get_option('sfdo'),
)
sfdo_icon = dependency(
'libsfdo-icon',
default_options: ['default_library=static', 'examples=false', 'tests=false'],
version: '>=0.1.3',
required: get_option('sfdo'),
)
have_libsfdo = sfdo_basedir.found() and sfdo_desktop.found() and sfdo_desktop_file.found() and sfdo_icon.found()
# Execute the wlroots subproject, if any # Execute the wlroots subproject, if any
wlroots_version = ['>=0.20.0', '<0.21.0'] wlroots_version = ['>=0.20.0', '<0.21.0']
subproject( subproject(

View file

@ -70,7 +70,13 @@
#endif #endif
#if HAVE_LIBSFDO #if HAVE_LIBSFDO
<<<<<<< HEAD
#include "sfdo.h" #include "sfdo.h"
=======
#include <sfdo-basedir.h>
#include <sfdo-desktop.h>
#include <sfdo-icon.h>
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
#endif #endif
#define SWAY_XDG_SHELL_VERSION 5 #define SWAY_XDG_SHELL_VERSION 5
@ -526,19 +532,25 @@ void server_fini(struct sway_server *server) {
wl_list_remove(&server->drm_lease_request.link); wl_list_remove(&server->drm_lease_request.link);
} }
#endif #endif
<<<<<<< HEAD
<<<<<<< HEAD wl_list_remove(&server->tearing_control_new_object.link); <<<<<<< HEAD wl_list_remove(&server->tearing_control_new_object.link);
wl_list_remove(&server->xdg_activation_v1_request_activate.link); wl_list_remove(&server->xdg_activation_v1_request_activate.link);
wl_list_remove(&server->xdg_activation_v1_new_token.link); wl_list_remove(&server->xdg_activation_v1_new_token.link);
wl_list_remove(&server->request_set_cursor_shape.link); wl_list_remove(&server->request_set_cursor_shape.link);
input_manager_finish(server->input); input_manager_finish(server->input);
======= =======
=======
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
wl_list_remove(&server->tearing_control_new_object.link); wl_list_remove(&server->tearing_control_new_object.link);
wl_list_remove(&server->xdg_activation_v1_request_activate.link); wl_list_remove(&server->xdg_activation_v1_request_activate.link);
wl_list_remove(&server->xdg_activation_v1_new_token.link); wl_list_remove(&server->xdg_activation_v1_new_token.link);
wl_list_remove(&server->request_set_cursor_shape.link); wl_list_remove(&server->request_set_cursor_shape.link);
wl_list_remove(&server->new_foreign_toplevel_capture_request.link); wl_list_remove(&server->new_foreign_toplevel_capture_request.link);
input_manager_finish(server->input); input_manager_finish(server->input);
<<<<<<< HEAD
>>>>>>> 170c9c95 (Add support for toplevel capture) >>>>>>> 170c9c95 (Add support for toplevel capture)
=======
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
// TODO: free sway-specific resources // TODO: free sway-specific resources
#if WLR_HAS_XWAYLAND #if WLR_HAS_XWAYLAND
@ -547,6 +559,7 @@ void server_fini(struct sway_server *server) {
wl_list_remove(&server->xwayland_ready.link); wl_list_remove(&server->xwayland_ready.link);
wlr_xwayland_destroy(server->xwayland.wlr_xwayland); wlr_xwayland_destroy(server->xwayland.wlr_xwayland);
} }
<<<<<<< HEAD
#endif #endif
wl_display_destroy_clients(server->wl_display); wl_display_destroy_clients(server->wl_display);
wlr_backend_destroy(server->backend); wlr_backend_destroy(server->backend);
@ -556,6 +569,18 @@ void server_fini(struct sway_server *server) {
sfdo_destroy(server->sfdo); sfdo_destroy(server->sfdo);
#endif #endif
free(server->socket); free(server->socket);
=======
#endif
wl_display_destroy_clients(server->wl_display);
wlr_backend_destroy(server->backend);
wl_display_destroy(server->wl_display);
list_free(server->dirty_nodes);
free(server->socket);
#if HAVE_LIBSFDO
sfdo_destroy(server->sfdo);
#endif
>>>>>>> 8b3ea59a (Clean up build scaffolding for libsfdo and add the creation and)
} }
bool server_start(struct sway_server *server) { bool server_start(struct sway_server *server) {
@ -610,3 +635,73 @@ void server_run(struct sway_server *server) {
server->socket); server->socket);
wl_display_run(server->wl_display); wl_display_run(server->wl_display);
} }
#if HAVE_LIBSFDO
struct sfdo *sfdo_create(char *theme) {
struct sfdo *sfdo = calloc(1, sizeof(struct sfdo));
if (!sfdo) {
goto error_calloc;
}
struct sfdo_basedir_ctx *basedir_ctx = sfdo_basedir_ctx_create();
if (!basedir_ctx) {
goto error_basedir_ctx;
}
sfdo->desktop_ctx = sfdo_desktop_ctx_create(basedir_ctx);
if (!sfdo->desktop_ctx) {
goto error_desktop_ctx;
}
sfdo->icon_ctx = sfdo_icon_ctx_create(basedir_ctx);
if (!sfdo->icon_ctx) {
goto error_icon_ctx;
}
sfdo->desktop_db = sfdo_desktop_db_load(sfdo->desktop_ctx, NULL);
if (!sfdo->desktop_db) {
goto error_desktop_db;
}
int load_options = SFDO_ICON_THEME_LOAD_OPTIONS_DEFAULT |
SFDO_ICON_THEME_LOAD_OPTION_ALLOW_MISSING |
SFDO_ICON_THEME_LOAD_OPTION_RELAXED;
sfdo->icon_theme = sfdo_icon_theme_load(sfdo->icon_ctx, theme, load_options);
if (!sfdo->icon_theme) {
goto error_icon_theme;
}
sfdo_basedir_ctx_destroy(basedir_ctx);
sway_log(SWAY_DEBUG, "Successfully setup sfdo");
return sfdo;
error_icon_theme:
sfdo_desktop_db_destroy(sfdo->desktop_db);
error_desktop_db:
sfdo_icon_ctx_destroy(sfdo->icon_ctx);
error_icon_ctx:
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
error_desktop_ctx:
sfdo_basedir_ctx_destroy(basedir_ctx);
error_basedir_ctx:
free(sfdo);
error_calloc:
sway_log(SWAY_ERROR, "Failed to setup sfdo");
return NULL;
}
void sfdo_destroy(struct sfdo *sfdo) {
if (!sfdo) {
sway_log(SWAY_DEBUG, "Null sfdo passed in");
return;
}
sfdo_icon_theme_destroy(sfdo->icon_theme);
sfdo_desktop_db_destroy(sfdo->desktop_db);
sfdo_icon_ctx_destroy(sfdo->icon_ctx);
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
sway_log(SWAY_DEBUG, "Successfully destroyed sfdo");
}
#endif