mirror of
https://github.com/swaywm/sway.git
synced 2026-05-02 06:46:23 -04:00
Merge 2d5c67afda into c7d7d56f61
This commit is contained in:
commit
0f56cd4e12
19 changed files with 641 additions and 415 deletions
|
|
@ -8,6 +8,7 @@ lib_sway_common = static_library(
|
|||
'loop.c',
|
||||
'list.c',
|
||||
'pango.c',
|
||||
'sfdo.c',
|
||||
'stringop.c',
|
||||
'util.c'
|
||||
),
|
||||
|
|
|
|||
104
common/sfdo.c
Normal file
104
common/sfdo.c
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <sfdo-basedir.h>
|
||||
#include <sfdo-desktop.h>
|
||||
#include <sfdo-icon.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "sfdo.h"
|
||||
|
||||
// this extends libsfdo's behavior to also handle icons specified as absolute paths
|
||||
char *sfdo_icon_lookup_extended(struct sfdo *sfdo, char *icon_name, int target_size, int scale) {
|
||||
char *icon_path = NULL;
|
||||
if (icon_name[0] == '/') {
|
||||
struct stat sb;
|
||||
if (!stat(icon_name, &sb)) {
|
||||
icon_path = strdup(icon_name);
|
||||
}
|
||||
} else {
|
||||
int lookup_options = SFDO_ICON_THEME_LOOKUP_OPTIONS_DEFAULT;
|
||||
struct sfdo_icon_file *icon_file = \
|
||||
sfdo_icon_theme_lookup(sfdo->icon_theme, icon_name, SFDO_NT, \
|
||||
target_size, scale, lookup_options);
|
||||
if (icon_file && icon_file != SFDO_ICON_FILE_INVALID) {
|
||||
icon_path = strdup(sfdo_icon_file_get_path(icon_file, NULL));
|
||||
}
|
||||
sfdo_icon_file_destroy(icon_file);
|
||||
}
|
||||
return icon_path;
|
||||
}
|
||||
|
||||
struct sfdo *sfdo_create(char *icon_theme) {
|
||||
if (!icon_theme) {
|
||||
goto error_null;
|
||||
}
|
||||
|
||||
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, icon_theme, load_options);
|
||||
if (!sfdo->icon_theme) {
|
||||
goto error_icon_theme;
|
||||
}
|
||||
|
||||
sfdo_basedir_ctx_destroy(basedir_ctx);
|
||||
|
||||
sway_log(SWAY_INFO, "Successfully setup sfdo with icon theme %s", icon_theme);
|
||||
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:
|
||||
error_null:
|
||||
// it's safe to call with null
|
||||
sway_log(SWAY_ERROR, "Failed to setup sfdo with icon theme %s", icon_theme);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sfdo_destroy(struct sfdo *sfdo) {
|
||||
if (!sfdo) {
|
||||
sway_log(SWAY_DEBUG, "Null sfdo passed in");
|
||||
return;
|
||||
}
|
||||
|
||||
sfdo_desktop_ctx_destroy(sfdo->desktop_ctx);
|
||||
sfdo_icon_ctx_destroy(sfdo->icon_ctx);
|
||||
sfdo_desktop_db_destroy(sfdo->desktop_db);
|
||||
sfdo_icon_theme_destroy(sfdo->icon_theme);
|
||||
free(sfdo);
|
||||
sway_log(SWAY_DEBUG, "Successfully destroyed sfdo");
|
||||
}
|
||||
19
include/sfdo.h
Normal file
19
include/sfdo.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef _SWAY_SFDO_H
|
||||
#define _SWAY_SFDO_H
|
||||
|
||||
#include <sfdo-desktop.h>
|
||||
#include <sfdo-icon.h>
|
||||
#include <sfdo-basedir.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
char *sfdo_icon_lookup_extended(struct sfdo *sfdo, char *icon_name, int target_size, int scale);
|
||||
struct sfdo *sfdo_create(char *icon_theme);
|
||||
void sfdo_destroy(struct sfdo *sfdo);
|
||||
|
||||
#endif
|
||||
|
|
@ -399,8 +399,9 @@ struct bar_config {
|
|||
char *binding_mode_text;
|
||||
} colors;
|
||||
|
||||
#if HAVE_TRAY
|
||||
char *icon_theme;
|
||||
|
||||
#if HAVE_TRAY
|
||||
struct wl_list tray_bindings; // struct tray_binding::link
|
||||
list_t *tray_outputs; // char *
|
||||
int tray_padding;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include "sway/xwayland.h"
|
||||
#endif
|
||||
|
||||
#include "sfdo.h"
|
||||
|
||||
struct sway_transaction;
|
||||
|
||||
struct sway_session_lock {
|
||||
|
|
@ -146,6 +148,8 @@ struct sway_server {
|
|||
list_t *dirty_nodes;
|
||||
|
||||
struct wl_event_source *delayed_modeset;
|
||||
|
||||
struct sfdo *sfdo;
|
||||
};
|
||||
|
||||
extern struct sway_server server;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ struct swaybar_tray;
|
|||
struct swaybar_workspace;
|
||||
struct loop;
|
||||
|
||||
struct sfdo;
|
||||
|
||||
struct swaybar {
|
||||
char *id;
|
||||
char *mode;
|
||||
|
|
@ -50,6 +52,8 @@ struct swaybar {
|
|||
struct swaybar_tray *tray;
|
||||
#endif
|
||||
|
||||
struct sfdo *sfdo;
|
||||
|
||||
bool running;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include "util.h"
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
#include "sfdo.h"
|
||||
|
||||
struct box_colors {
|
||||
uint32_t border;
|
||||
uint32_t background;
|
||||
|
|
@ -73,13 +75,16 @@ struct swaybar_config {
|
|||
struct box_colors binding_mode;
|
||||
} colors;
|
||||
|
||||
#if HAVE_TRAY
|
||||
char *icon_theme;
|
||||
|
||||
#if HAVE_TRAY
|
||||
struct wl_list tray_bindings; // struct tray_binding::link
|
||||
bool tray_hidden;
|
||||
list_t *tray_outputs; // char *
|
||||
int tray_padding;
|
||||
#endif
|
||||
|
||||
struct sfdo *sfdo;
|
||||
};
|
||||
|
||||
#if HAVE_TRAY
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
#define _SWAYBAR_IMAGE_H
|
||||
#include <cairo.h>
|
||||
|
||||
cairo_surface_t *load_image(const char *path);
|
||||
cairo_surface_t *load_image(const char *path, int target_size, int scale);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -60,6 +60,10 @@ endforeach
|
|||
|
||||
null_dep = dependency('', required: false)
|
||||
|
||||
libsfdo_basedir = dependency('libsfdo-basedir', version: '>=0.1.3')
|
||||
libsfdo_desktop = dependency('libsfdo-desktop', version: '>=0.1.3')
|
||||
libsfdo_desktop_file = dependency('libsfdo-desktop-file', version: '>=0.1.3')
|
||||
libsfdo_icon = dependency('libsfdo-icon', version: '>=0.1.3')
|
||||
jsonc = dependency('json-c', version: '>=0.13')
|
||||
pcre2 = dependency('libpcre2-8')
|
||||
wayland_server = dependency('wayland-server', version: '>=1.21.0')
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@ option('tray', type: 'feature', value: 'auto', description: 'Enable support for
|
|||
option('gdk-pixbuf', type: 'feature', value: 'auto', description: 'Enable support for more image formats in swaybar tray')
|
||||
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
|
||||
option('sd-bus-provider', type: 'combo', choices: ['auto', 'libsystemd', 'libelogind', 'basu'], value: 'auto', description: 'Provider of the sd-bus library')
|
||||
option('sfdo', type: 'feature', value: 'auto', description: 'Enable libsfdo integration')
|
||||
|
|
|
|||
|
|
@ -70,9 +70,14 @@ void free_bar_config(struct bar_config *bar) {
|
|||
free(bar->colors.binding_mode_border);
|
||||
free(bar->colors.binding_mode_bg);
|
||||
free(bar->colors.binding_mode_text);
|
||||
|
||||
// since libsfdo is a hard depedency now we always have at least
|
||||
// a default icon theme and need to free the string that contains
|
||||
// its name
|
||||
free(bar->icon_theme);
|
||||
|
||||
#if HAVE_TRAY
|
||||
list_free_items_and_destroy(bar->tray_outputs);
|
||||
free(bar->icon_theme);
|
||||
|
||||
struct tray_binding *tray_bind = NULL, *tmp_tray_bind = NULL;
|
||||
wl_list_for_each_safe(tray_bind, tmp_tray_bind, &bar->tray_bindings, link) {
|
||||
|
|
@ -170,6 +175,11 @@ struct bar_config *default_bar_config(void) {
|
|||
bar->colors.binding_mode_bg = NULL;
|
||||
bar->colors.binding_mode_text = NULL;
|
||||
|
||||
// we need some default when we initialize sfdo
|
||||
if (!(bar->icon_theme = strdup("Hicolor"))) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
#if HAVE_TRAY
|
||||
bar->tray_padding = 2;
|
||||
wl_list_init(&bar->tray_bindings);
|
||||
|
|
|
|||
|
|
@ -218,6 +218,10 @@ sway_sources = files(
|
|||
)
|
||||
|
||||
sway_deps = [
|
||||
libsfdo_basedir,
|
||||
libsfdo_desktop,
|
||||
libsfdo_desktop_file,
|
||||
libsfdo_icon,
|
||||
cairo,
|
||||
drm,
|
||||
jsonc,
|
||||
|
|
|
|||
130
sway/server.c
130
sway/server.c
|
|
@ -1,3 +1,13 @@
|
|||
#include "sway/server.h"
|
||||
#include "config.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/desktop/idle_inhibit_v1.h"
|
||||
#include "sway/input/cursor.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/output.h"
|
||||
#include "sway/tree/root.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -14,13 +24,13 @@
|
|||
#include <wlr/types/wlr_content_type_v1.h>
|
||||
#include <wlr/types/wlr_cursor_shape_v1.h>
|
||||
#include <wlr/types/wlr_data_control_v1.h>
|
||||
#include <wlr/types/wlr_ext_data_control_v1.h>
|
||||
#include <wlr/types/wlr_data_device.h>
|
||||
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
||||
#include <wlr/types/wlr_ext_data_control_v1.h>
|
||||
#include <wlr/types/wlr_ext_foreign_toplevel_list_v1.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/types/wlr_ext_image_capture_source_v1.h>
|
||||
#include <wlr/types/wlr_ext_image_copy_capture_v1.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/types/wlr_fractional_scale_v1.h>
|
||||
#include <wlr/types/wlr_gamma_control_v1.h>
|
||||
#include <wlr/types/wlr_idle_notify_v1.h>
|
||||
|
|
@ -49,26 +59,18 @@
|
|||
#include <wlr/types/wlr_xdg_foreign_v2.h>
|
||||
#include <wlr/types/wlr_xdg_output_v1.h>
|
||||
#include <xf86drm.h>
|
||||
#include "config.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/desktop/idle_inhibit_v1.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/output.h"
|
||||
#include "sway/server.h"
|
||||
#include "sway/input/cursor.h"
|
||||
#include "sway/tree/root.h"
|
||||
|
||||
#if WLR_HAS_XWAYLAND
|
||||
#include <wlr/xwayland/shell.h>
|
||||
#include "sway/xwayland.h"
|
||||
#include <wlr/xwayland/shell.h>
|
||||
#endif
|
||||
|
||||
#if WLR_HAS_DRM_BACKEND
|
||||
#include <wlr/types/wlr_drm_lease_v1.h>
|
||||
#endif
|
||||
|
||||
#include "sfdo.h"
|
||||
|
||||
#define SWAY_XDG_SHELL_VERSION 5
|
||||
#define SWAY_LAYER_SHELL_VERSION 4
|
||||
#define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1
|
||||
|
|
@ -102,8 +104,7 @@ static bool is_privileged(const struct wl_global *global) {
|
|||
}
|
||||
#endif
|
||||
|
||||
return
|
||||
global == server.output_manager_v1->global ||
|
||||
return global == server.output_manager_v1->global ||
|
||||
global == server.output_power_manager_v1->global ||
|
||||
global == server.input_method->global ||
|
||||
global == server.foreign_toplevel_list->global ||
|
||||
|
|
@ -212,8 +213,8 @@ static void do_renderer_recreate(void *data) {
|
|||
|
||||
struct sway_output *output;
|
||||
wl_list_for_each(output, &root->all_outputs, link) {
|
||||
wlr_output_init_render(output->wlr_output,
|
||||
server->allocator, server->renderer);
|
||||
wlr_output_init_render(output->wlr_output, server->allocator,
|
||||
server->renderer);
|
||||
}
|
||||
|
||||
wlr_allocator_destroy(old_allocator);
|
||||
|
|
@ -229,22 +230,29 @@ static void handle_renderer_lost(struct wl_listener *listener, void *data) {
|
|||
}
|
||||
|
||||
sway_log(SWAY_INFO, "Scheduling re-creation of renderer after GPU reset");
|
||||
server->recreating_renderer = wl_event_loop_add_idle(server->wl_event_loop, do_renderer_recreate, server);
|
||||
server->recreating_renderer = wl_event_loop_add_idle(
|
||||
server->wl_event_loop, do_renderer_recreate, server);
|
||||
}
|
||||
|
||||
static void handle_new_foreign_toplevel_capture_request(struct wl_listener *listener, void *data) {
|
||||
struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request *request = data;
|
||||
static void
|
||||
handle_new_foreign_toplevel_capture_request(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request
|
||||
*request = data;
|
||||
struct sway_view *view = request->toplevel_handle->data;
|
||||
|
||||
if (view->image_capture_source == NULL) {
|
||||
view->image_capture_source = wlr_ext_image_capture_source_v1_create_with_scene_node(
|
||||
&view->image_capture_scene->tree.node, server.wl_event_loop, server.allocator, server.renderer);
|
||||
view->image_capture_source =
|
||||
wlr_ext_image_capture_source_v1_create_with_scene_node(
|
||||
&view->image_capture_scene->tree.node, server.wl_event_loop,
|
||||
server.allocator, server.renderer);
|
||||
if (view->image_capture_source == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request_accept(request, view->image_capture_source);
|
||||
wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request_accept(
|
||||
request, view->image_capture_source);
|
||||
}
|
||||
|
||||
bool server_init(struct sway_server *server) {
|
||||
|
|
@ -257,7 +265,8 @@ bool server_init(struct sway_server *server) {
|
|||
|
||||
root = root_create(server->wl_display);
|
||||
|
||||
server->backend = wlr_backend_autocreate(server->wl_event_loop, &server->session);
|
||||
server->backend =
|
||||
wlr_backend_autocreate(server->wl_event_loop, &server->session);
|
||||
if (!server->backend) {
|
||||
sway_log(SWAY_ERROR, "Unable to create backend");
|
||||
return false;
|
||||
|
|
@ -276,26 +285,27 @@ bool server_init(struct sway_server *server) {
|
|||
|
||||
wlr_renderer_init_wl_shm(server->renderer, server->wl_display);
|
||||
|
||||
if (wlr_renderer_get_texture_formats(server->renderer, WLR_BUFFER_CAP_DMABUF) != NULL) {
|
||||
if (wlr_renderer_get_texture_formats(server->renderer,
|
||||
WLR_BUFFER_CAP_DMABUF) != NULL) {
|
||||
server->linux_dmabuf_v1 = wlr_linux_dmabuf_v1_create_with_renderer(
|
||||
server->wl_display, 4, server->renderer);
|
||||
}
|
||||
if (wlr_renderer_get_drm_fd(server->renderer) >= 0 &&
|
||||
server->renderer->features.timeline &&
|
||||
server->backend->features.timeline) {
|
||||
wlr_linux_drm_syncobj_manager_v1_create(server->wl_display, 1,
|
||||
wlr_renderer_get_drm_fd(server->renderer));
|
||||
wlr_linux_drm_syncobj_manager_v1_create(
|
||||
server->wl_display, 1, wlr_renderer_get_drm_fd(server->renderer));
|
||||
}
|
||||
|
||||
server->allocator = wlr_allocator_autocreate(server->backend,
|
||||
server->renderer);
|
||||
server->allocator =
|
||||
wlr_allocator_autocreate(server->backend, server->renderer);
|
||||
if (!server->allocator) {
|
||||
sway_log(SWAY_ERROR, "Failed to create allocator");
|
||||
return false;
|
||||
}
|
||||
|
||||
server->compositor = wlr_compositor_create(server->wl_display, 6,
|
||||
server->renderer);
|
||||
server->compositor =
|
||||
wlr_compositor_create(server->wl_display, 6, server->renderer);
|
||||
|
||||
wlr_subcompositor_create(server->wl_display);
|
||||
|
||||
|
|
@ -316,14 +326,14 @@ bool server_init(struct sway_server *server) {
|
|||
server->idle_notifier_v1 = wlr_idle_notifier_v1_create(server->wl_display);
|
||||
sway_idle_inhibit_manager_v1_init();
|
||||
|
||||
server->layer_shell = wlr_layer_shell_v1_create(server->wl_display,
|
||||
SWAY_LAYER_SHELL_VERSION);
|
||||
server->layer_shell =
|
||||
wlr_layer_shell_v1_create(server->wl_display, SWAY_LAYER_SHELL_VERSION);
|
||||
wl_signal_add(&server->layer_shell->events.new_surface,
|
||||
&server->layer_shell_surface);
|
||||
server->layer_shell_surface.notify = handle_layer_shell_surface;
|
||||
|
||||
server->xdg_shell = wlr_xdg_shell_create(server->wl_display,
|
||||
SWAY_XDG_SHELL_VERSION);
|
||||
server->xdg_shell =
|
||||
wlr_xdg_shell_create(server->wl_display, SWAY_XDG_SHELL_VERSION);
|
||||
wl_signal_add(&server->xdg_shell->events.new_toplevel,
|
||||
&server->xdg_shell_toplevel);
|
||||
server->xdg_shell_toplevel.notify = handle_xdg_shell_toplevel;
|
||||
|
|
@ -342,8 +352,7 @@ bool server_init(struct sway_server *server) {
|
|||
|
||||
server->xdg_decoration_manager =
|
||||
wlr_xdg_decoration_manager_v1_create(server->wl_display);
|
||||
wl_signal_add(
|
||||
&server->xdg_decoration_manager->events.new_toplevel_decoration,
|
||||
wl_signal_add(&server->xdg_decoration_manager->events.new_toplevel_decoration,
|
||||
&server->xdg_decoration);
|
||||
server->xdg_decoration.notify = handle_xdg_decoration;
|
||||
wl_list_init(&server->xdg_decorations);
|
||||
|
|
@ -357,11 +366,11 @@ bool server_init(struct sway_server *server) {
|
|||
wl_signal_add(&server->pointer_constraints->events.new_constraint,
|
||||
&server->pointer_constraint);
|
||||
|
||||
wlr_presentation_create(server->wl_display, server->backend, SWAY_PRESENTATION_VERSION);
|
||||
wlr_presentation_create(server->wl_display, server->backend,
|
||||
SWAY_PRESENTATION_VERSION);
|
||||
wlr_alpha_modifier_v1_create(server->wl_display);
|
||||
|
||||
server->output_manager_v1 =
|
||||
wlr_output_manager_v1_create(server->wl_display);
|
||||
server->output_manager_v1 = wlr_output_manager_v1_create(server->wl_display);
|
||||
server->output_manager_apply.notify = handle_output_manager_apply;
|
||||
wl_signal_add(&server->output_manager_v1->events.apply,
|
||||
&server->output_manager_apply);
|
||||
|
|
@ -377,15 +386,15 @@ bool server_init(struct sway_server *server) {
|
|||
&server->output_power_manager_set_mode);
|
||||
server->input_method = wlr_input_method_manager_v2_create(server->wl_display);
|
||||
server->text_input = wlr_text_input_manager_v3_create(server->wl_display);
|
||||
server->foreign_toplevel_list =
|
||||
wlr_ext_foreign_toplevel_list_v1_create(server->wl_display, SWAY_FOREIGN_TOPLEVEL_LIST_VERSION);
|
||||
server->foreign_toplevel_list = wlr_ext_foreign_toplevel_list_v1_create(
|
||||
server->wl_display, SWAY_FOREIGN_TOPLEVEL_LIST_VERSION);
|
||||
server->foreign_toplevel_manager =
|
||||
wlr_foreign_toplevel_manager_v1_create(server->wl_display);
|
||||
|
||||
sway_session_lock_init();
|
||||
|
||||
#if WLR_HAS_DRM_BACKEND
|
||||
server->drm_lease_manager=
|
||||
server->drm_lease_manager =
|
||||
wlr_drm_lease_v1_manager_create(server->wl_display, server->backend);
|
||||
if (server->drm_lease_manager) {
|
||||
server->drm_lease_request.notify = handle_drm_lease_request;
|
||||
|
|
@ -397,13 +406,19 @@ bool server_init(struct sway_server *server) {
|
|||
}
|
||||
#endif
|
||||
|
||||
server->export_dmabuf_manager_v1 = wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
||||
server->screencopy_manager_v1 = wlr_screencopy_manager_v1_create(server->wl_display);
|
||||
server->ext_image_copy_capture_manager_v1 = wlr_ext_image_copy_capture_manager_v1_create(server->wl_display, 1);
|
||||
server->export_dmabuf_manager_v1 =
|
||||
wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
||||
server->screencopy_manager_v1 =
|
||||
wlr_screencopy_manager_v1_create(server->wl_display);
|
||||
server->ext_image_copy_capture_manager_v1 =
|
||||
wlr_ext_image_copy_capture_manager_v1_create(server->wl_display, 1);
|
||||
wlr_ext_output_image_capture_source_manager_v1_create(server->wl_display, 1);
|
||||
server->wlr_data_control_manager_v1 = wlr_data_control_manager_v1_create(server->wl_display);
|
||||
server->ext_data_control_manager_v1 = wlr_ext_data_control_manager_v1_create(server->wl_display, 1);
|
||||
server->security_context_manager_v1 = wlr_security_context_manager_v1_create(server->wl_display);
|
||||
server->wlr_data_control_manager_v1 =
|
||||
wlr_data_control_manager_v1_create(server->wl_display);
|
||||
server->ext_data_control_manager_v1 =
|
||||
wlr_ext_data_control_manager_v1_create(server->wl_display, 1);
|
||||
server->security_context_manager_v1 =
|
||||
wlr_security_context_manager_v1_create(server->wl_display);
|
||||
wlr_viewporter_create(server->wl_display);
|
||||
wlr_single_pixel_buffer_manager_v1_create(server->wl_display);
|
||||
server->content_type_manager_v1 =
|
||||
|
|
@ -411,9 +426,12 @@ bool server_init(struct sway_server *server) {
|
|||
wlr_fractional_scale_manager_v1_create(server->wl_display, 1);
|
||||
|
||||
server->ext_foreign_toplevel_image_capture_source_manager_v1 =
|
||||
wlr_ext_foreign_toplevel_image_capture_source_manager_v1_create(server->wl_display, 1);
|
||||
server->new_foreign_toplevel_capture_request.notify = handle_new_foreign_toplevel_capture_request;
|
||||
wl_signal_add(&server->ext_foreign_toplevel_image_capture_source_manager_v1->events.new_request,
|
||||
wlr_ext_foreign_toplevel_image_capture_source_manager_v1_create(
|
||||
server->wl_display, 1);
|
||||
server->new_foreign_toplevel_capture_request.notify =
|
||||
handle_new_foreign_toplevel_capture_request;
|
||||
wl_signal_add(&server->ext_foreign_toplevel_image_capture_source_manager_v1
|
||||
->events.new_request,
|
||||
&server->new_foreign_toplevel_capture_request);
|
||||
|
||||
server->tearing_control_v1 =
|
||||
|
|
@ -441,7 +459,8 @@ bool server_init(struct sway_server *server) {
|
|||
struct wlr_cursor_shape_manager_v1 *cursor_shape_manager =
|
||||
wlr_cursor_shape_manager_v1_create(server->wl_display, 1);
|
||||
server->request_set_cursor_shape.notify = handle_request_set_cursor_shape;
|
||||
wl_signal_add(&cursor_shape_manager->events.request_set_shape, &server->request_set_cursor_shape);
|
||||
wl_signal_add(&cursor_shape_manager->events.request_set_shape,
|
||||
&server->request_set_cursor_shape);
|
||||
|
||||
wl_list_init(&server->pending_launcher_ctxs);
|
||||
|
||||
|
|
@ -524,6 +543,7 @@ void server_fini(struct sway_server *server) {
|
|||
wlr_backend_destroy(server->backend);
|
||||
wl_display_destroy(server->wl_display);
|
||||
list_free(server->dirty_nodes);
|
||||
sfdo_destroy(server->sfdo);
|
||||
free(server->socket);
|
||||
}
|
||||
|
||||
|
|
@ -565,6 +585,10 @@ bool server_start(struct sway_server *server) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO: allow configurability of global sway icon theme if and when
|
||||
// it is applicable (titlebar icons? ssd icons?)
|
||||
server->sfdo = sfdo_create("Hicolor");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -538,6 +538,7 @@ void bar_teardown(struct swaybar *bar) {
|
|||
#if HAVE_TRAY
|
||||
destroy_tray(bar->tray);
|
||||
#endif
|
||||
sfdo_destroy(bar->config->sfdo);
|
||||
free_outputs(&bar->outputs);
|
||||
free_outputs(&bar->unused_outputs);
|
||||
free_seats(&bar->seats);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include "list.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "sfdo.h"
|
||||
|
||||
uint32_t parse_position(const char *position) {
|
||||
uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||
|
|
@ -128,8 +130,11 @@ void free_config(struct swaybar_config *config) {
|
|||
wl_list_remove(&tray_bind->link);
|
||||
free_tray_binding(tray_bind);
|
||||
}
|
||||
#endif
|
||||
|
||||
free(config->icon_theme);
|
||||
#endif
|
||||
sfdo_destroy(config->sfdo);
|
||||
sway_log(SWAY_DEBUG, "Destroyed swaybar sfdo");
|
||||
|
||||
free(config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,11 +104,27 @@ static cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(
|
|||
}
|
||||
#endif // HAVE_GDK_PIXBUF
|
||||
|
||||
cairo_surface_t *load_image(const char *path) {
|
||||
cairo_surface_t *load_image(const char *path, int target_size, int scale) {
|
||||
cairo_surface_t *image;
|
||||
#if HAVE_GDK_PIXBUF
|
||||
GError *err = NULL;
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &err);
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
// svg images should be loaded at target size. the size read from an svg
|
||||
// file is only nominal and can lead to an image too small for the avaialble
|
||||
// space compared to bitmap icons selected at the nearest available size
|
||||
int i = strlen(path) - 1;
|
||||
// this is naive and assumes ascii, utf-8, or another encoding
|
||||
// that encodes these letters as single bytes
|
||||
if ((i > 2) &&
|
||||
(path[i] == 'g' || path[i] == 'G') && \
|
||||
(path[i - 1] == 'v' || path[i - 1] == 'V') && \
|
||||
(path[i - 2] == 's' || path[i - 2] == 'S') && \
|
||||
(path[i - 3] == '.' )) {
|
||||
pixbuf = gdk_pixbuf_new_from_file_at_scale(path, -1, target_size, \
|
||||
true, &err);
|
||||
} else {
|
||||
pixbuf = gdk_pixbuf_new_from_file(path, &err);
|
||||
}
|
||||
if (!pixbuf) {
|
||||
sway_log(SWAY_ERROR, "Failed to load background image (%s).",
|
||||
err->message);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
#include "stringop.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "sfdo.h"
|
||||
|
||||
void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
|
||||
uint32_t size = strlen("workspace \"\"") + strlen(ws);
|
||||
for (size_t i = 0; i < strlen(ws); ++i) {
|
||||
|
|
@ -328,10 +330,14 @@ static bool ipc_parse_config(
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// whether or not there is a tray, we now always have an icon theme
|
||||
if ((json_object_object_get_ex(bar_config, "icon_theme", &icon_theme))) {
|
||||
config->icon_theme = strdup(json_object_get_string(icon_theme));
|
||||
sfdo_destroy(config->sfdo);
|
||||
config->sfdo = sfdo_create(config->icon_theme);
|
||||
}
|
||||
#endif
|
||||
|
||||
json_object_put(bar_config);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ tray_files = have_tray ? [
|
|||
] : []
|
||||
|
||||
swaybar_deps = [
|
||||
libsfdo_basedir,
|
||||
libsfdo_desktop,
|
||||
libsfdo_desktop_file,
|
||||
libsfdo_icon,
|
||||
cairo,
|
||||
gdk_pixbuf,
|
||||
jsonc,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <cairo.h>
|
||||
#include <limits.h>
|
||||
#include <sfdo-common.h>
|
||||
#include <sfdo-icon.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -18,6 +20,8 @@
|
|||
#include "stringop.h"
|
||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||
|
||||
#include "sfdo.h"
|
||||
|
||||
// TODO menu
|
||||
|
||||
static bool sni_ready(struct swaybar_sni *sni) {
|
||||
|
|
@ -415,25 +419,34 @@ static enum hotspot_event_handling icon_hotspot_callback(
|
|||
return HOTSPOT_PROCESS;
|
||||
}
|
||||
|
||||
static void reload_sni(struct swaybar_sni *sni, char *icon_theme,
|
||||
int target_size) {
|
||||
static void reload_sni(struct swaybar_sni *sni, char *icon_theme, int target_size) {
|
||||
char *icon_name = sni->status[0] == 'N' ?
|
||||
sni->attention_icon_name : sni->icon_name;
|
||||
if (icon_name) {
|
||||
list_t *icon_search_paths = create_list();
|
||||
list_cat(icon_search_paths, sni->tray->basedirs);
|
||||
if (sni->icon_theme_path) {
|
||||
list_add(icon_search_paths, sni->icon_theme_path);
|
||||
char *icon_path = NULL;
|
||||
// TODO: at some point we will need to make this scaling-aware
|
||||
int scale = 1;
|
||||
struct sfdo *sfdo = sni->tray->bar->config->sfdo;
|
||||
if (sfdo) {
|
||||
icon_path = sfdo_icon_lookup_extended(sfdo, icon_name, target_size, scale);
|
||||
if (!icon_path) {
|
||||
sway_log(SWAY_DEBUG, "sfdo: icon %s invalid or not found in theme %s at size %d", \
|
||||
icon_name, icon_theme, target_size);
|
||||
}
|
||||
}
|
||||
char *icon_path = find_icon(sni->tray->themes, icon_search_paths,
|
||||
icon_name, target_size, icon_theme,
|
||||
&sni->min_size, &sni->max_size);
|
||||
list_free(icon_search_paths);
|
||||
if (icon_path) {
|
||||
cairo_surface_destroy(sni->icon);
|
||||
sni->icon = load_image(icon_path);
|
||||
sni->icon = load_image(icon_path, target_size, scale);
|
||||
free(icon_path);
|
||||
return;
|
||||
} else {
|
||||
// the :( icon won't be drawn for a missing icon and whichever old icon was
|
||||
// loaded will persist if this is not done. one might not have noticed this
|
||||
// for tray items that have only one icon loaded only once, successfully or
|
||||
// unsuccessfully. items with multiple icons, such as fcitx5 or other input
|
||||
// method frameworks make the problem apparent
|
||||
free(sni->icon);
|
||||
sni->icon = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue