[client] wayland: set the application icon
Some checks are pending
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Waiting to run
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Waiting to run
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Waiting to run
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Waiting to run
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Waiting to run
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Waiting to run
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Waiting to run
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Waiting to run
build / module (push) Waiting to run
build / host-linux (push) Waiting to run
build / host-windows-cross (push) Waiting to run
build / host-windows-native (push) Waiting to run
build / idd (push) Waiting to run
build / obs (clang) (push) Waiting to run
build / obs (gcc) (push) Waiting to run
build / docs (push) Waiting to run

This commit is contained in:
Geoffrey McRae
2026-07-17 03:12:06 +10:00
parent aa25b0cfe3
commit f77986b863
12 changed files with 191 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ add_library(displayserver_Wayland STATIC
colormgmt.c colormgmt.c
cursor.c cursor.c
gl.c gl.c
icon.c
idle.c idle.c
input.c input.c
output.c output.c
@@ -33,6 +34,7 @@ add_subdirectory(desktops)
target_link_libraries(displayserver_Wayland target_link_libraries(displayserver_Wayland
PkgConfig::DISPLAYSERVER_Wayland PkgConfig::DISPLAYSERVER_Wayland
lg_common lg_common
lg_resources
wayland_protocol wayland_protocol
wayland_desktops wayland_desktops
) )

View File

@@ -142,6 +142,11 @@ static bool libdecor_shellInit(
libdecor_frame_set_title(state.libdecorFrame, title); libdecor_frame_set_title(state.libdecorFrame, title);
libdecor_frame_map(state.libdecorFrame); libdecor_frame_map(state.libdecorFrame);
// Get the xdg_toplevel for icon setting
struct xdg_surface * xdgSurface = libdecor_frame_get_xdg_surface(state.libdecorFrame);
if (xdgSurface)
wlWm.xdgToplevel = xdg_surface_get_toplevel(xdgSurface);
if (fullscreen) if (fullscreen)
libdecor_frame_set_fullscreen(state.libdecorFrame, NULL); libdecor_frame_set_fullscreen(state.libdecorFrame, NULL);

View File

@@ -149,6 +149,7 @@ bool xdg_shellInit(struct wl_display * display, struct wl_surface * surface,
xdg_toplevel_add_listener(state.toplevel, &xdgToplevelListener, NULL); xdg_toplevel_add_listener(state.toplevel, &xdgToplevelListener, NULL);
xdg_toplevel_set_title(state.toplevel, title); xdg_toplevel_set_title(state.toplevel, title);
xdg_toplevel_set_app_id(state.toplevel, appId); xdg_toplevel_set_app_id(state.toplevel, appId);
wlWm.xdgToplevel = state.toplevel;
if (fullscreen) if (fullscreen)
xdg_toplevel_set_fullscreen(state.toplevel, NULL); xdg_toplevel_set_fullscreen(state.toplevel, NULL);

View File

@@ -0,0 +1,136 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include "wayland.h"
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>
#include <wayland-client.h>
#include "common/debug.h"
#include "resources/icondata.h"
// icondata is defined as an array of unsigned long, but on 64-bit platforms
// unsigned long is 8 bytes while the actual data is 32-bit ARGB packed in
// unsigned long values (the top 32 bits are zero). The first two values are
// width and height (both 64), followed by pixel rows.
// We need to convert this to a uint32_t buffer for wl_shm (ARGB8888).
//
// Note: sizeof(icondata) / sizeof(icondata[0]) gives the total array length,
// which includes the 2 header values + 64*64 = 4096 pixel values = 4098 total.
#define ICON_SIZE 64
// header: width and height, then pixel data
#define ICON_HEADER_WORDS 2
#define ICON_PIXEL_WORDS (ICON_SIZE * ICON_SIZE)
#define ICON_TOTAL_WORDS (ICON_HEADER_WORDS + ICON_PIXEL_WORDS)
static uint32_t g_iconPixels[ICON_SIZE * ICON_SIZE];
bool waylandIconInit(void)
{
if (!wlWm.iconManager || !wlWm.xdgToplevel || !wlWm.shm)
return true; // not an error, just no support
for (size_t i = 0; i < ICON_TOTAL_WORDS; ++i)
{
if (i >= icondataSize / sizeof(icondata[0]))
{
DEBUG_ERROR("Icon data array is smaller than expected");
return true;
}
uint32_t val = (uint32_t)icondata[i];
// First two words are width/height, skip them
if (i >= ICON_HEADER_WORDS)
g_iconPixels[i - ICON_HEADER_WORDS] = val;
}
// Create shared memory buffer for the icon
size_t dataSize = sizeof(g_iconPixels);
int fd = memfd_create("lg-icon", 0);
if (fd < 0)
{
DEBUG_ERROR("Failed to create icon shared memory: %d", errno);
return true; // not fatal
}
struct wl_buffer * buffer = NULL;
struct xdg_toplevel_icon_v1 * icon = NULL;
if (ftruncate(fd, (off_t)dataSize) < 0)
{
DEBUG_ERROR("Failed to ftruncate icon shared memory: %d", errno);
goto fail;
}
void * shm_data = mmap(NULL, dataSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (shm_data == MAP_FAILED)
{
DEBUG_ERROR("Failed to mmap icon shared memory: %d", errno);
goto fail;
}
memcpy(shm_data, g_iconPixels, dataSize);
munmap(shm_data, dataSize);
struct wl_shm_pool * pool = wl_shm_create_pool(wlWm.shm, fd, (int32_t)dataSize);
buffer = wl_shm_pool_create_buffer(pool, 0, ICON_SIZE, ICON_SIZE,
ICON_SIZE * 4, WL_SHM_FORMAT_ARGB8888);
wl_shm_pool_destroy(pool);
if (!buffer)
{
DEBUG_ERROR("Failed to create wl_buffer for icon");
goto fail;
}
icon = xdg_toplevel_icon_manager_v1_create_icon(wlWm.iconManager);
if (!icon)
{
DEBUG_ERROR("Failed to create icon object");
goto fail;
}
xdg_toplevel_icon_v1_add_buffer(icon, buffer, 1);
xdg_toplevel_icon_manager_v1_set_icon(wlWm.iconManager,
(struct xdg_toplevel *)wlWm.xdgToplevel, icon);
// After set_icon, the icon object is immutable. We can destroy it;
// the compositor retains its data.
xdg_toplevel_icon_v1_destroy(icon);
wl_buffer_destroy(buffer);
close(fd);
return true;
fail:
if (icon)
xdg_toplevel_icon_v1_destroy(icon);
if (buffer)
wl_buffer_destroy(buffer);
close(fd);
return true; // not fatal
}

View File

@@ -69,6 +69,9 @@ wayland_generate(
wayland_generate( wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/staging/color-management/color-management-v1.xml" "${WAYLAND_PROTOCOLS_BASE}/staging/color-management/color-management-v1.xml"
"${CMAKE_BINARY_DIR}/wayland/wayland-color-management-v1-client-protocol") "${CMAKE_BINARY_DIR}/wayland/wayland-color-management-v1-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml"
"${CMAKE_BINARY_DIR}/wayland/wayland-xdg-toplevel-icon-v1-client-protocol")
target_link_libraries(wayland_protocol target_link_libraries(wayland_protocol
PkgConfig::WAYLAND PkgConfig::WAYLAND

View File

@@ -77,6 +77,9 @@ static void registryGlobalHandler(void * data, struct wl_registry * registry,
else if (!strcmp(interface, wp_color_manager_v1_interface.name)) else if (!strcmp(interface, wp_color_manager_v1_interface.name))
wlWm.colorManager = wl_registry_bind(wlWm.registry, name, wlWm.colorManager = wl_registry_bind(wlWm.registry, name,
&wp_color_manager_v1_interface, 1); &wp_color_manager_v1_interface, 1);
else if (!strcmp(interface, xdg_toplevel_icon_manager_v1_interface.name))
wlWm.iconManager = wl_registry_bind(wlWm.registry, name,
&xdg_toplevel_icon_manager_v1_interface, 1);
else if (wlWm.desktop->registryGlobalHandler( else if (wlWm.desktop->registryGlobalHandler(
data, registry, name, interface, version)) data, registry, name, interface, version))
return; return;

View File

@@ -170,6 +170,8 @@ static bool waylandInit(const LG_DSInitParams params)
if (!waylandEGLInit(params.w, params.h)) if (!waylandEGLInit(params.w, params.h))
return false; return false;
waylandIconInit();
#ifdef ENABLE_OPENGL #ifdef ENABLE_OPENGL
if (params.opengl && !waylandOpenGLInit()) if (params.opengl && !waylandOpenGLInit())
return false; return false;

View File

@@ -50,6 +50,7 @@
#include "wayland-fractional-scale-v1-client-protocol.h" #include "wayland-fractional-scale-v1-client-protocol.h"
#include "wayland-content-type-v1-client-protocol.h" #include "wayland-content-type-v1-client-protocol.h"
#include "wayland-color-management-v1-client-protocol.h" #include "wayland-color-management-v1-client-protocol.h"
#include "wayland-xdg-toplevel-icon-v1-client-protocol.h"
#include "scale.h" #include "scale.h"
@@ -205,6 +206,12 @@ struct WaylandDSState
bool cmHasPerceptualIntent; bool cmHasPerceptualIntent;
bool cmCanDoHDR; // true if compositor supports features needed for HDR bool cmCanDoHDR; // true if compositor supports features needed for HDR
// toplevel icon manager
struct xdg_toplevel_icon_manager_v1 * iconManager;
// set by the active desktop backend during shellInit
void * xdgToplevel;
// Pending HDR format to apply (set by frame thread, applied in swap buffers). // Pending HDR format to apply (set by frame thread, applied in swap buffers).
// pendingHDRApply and pendingHDRClear are accessed from multiple threads // pendingHDRApply and pendingHDRClear are accessed from multiple threads
// without a lock, so they must be atomic. // without a lock, so they must be atomic.
@@ -370,3 +377,6 @@ bool waylandWaitFrame(void);
void waylandSkipFrame(void); void waylandSkipFrame(void);
void waylandStopWaitFrame(void); void waylandStopWaitFrame(void);
void waylandNeedsResize(void); void waylandNeedsResize(void);
// icon module
bool waylandIconInit(void);

View File

@@ -617,7 +617,7 @@ static bool x11Init(const LG_DSInitParams params)
32, 32,
PropModeReplace, PropModeReplace,
(unsigned char *)icondata, (unsigned char *)icondata,
sizeof(icondata) / sizeof(icondata[0]) icondataSize / sizeof(icondata[0])
); );
/* create the blank cursor */ /* create the blank cursor */

View File

@@ -14,6 +14,10 @@ function(build_resources)
set(LG_RESOURCES_INCS "${LG_RESOURCES_INCS}" PARENT_SCOPE) set(LG_RESOURCES_INCS "${LG_RESOURCES_INCS}" PARENT_SCOPE)
endfunction() endfunction()
set(RESOURCES_SOURCES
icondata.c
)
build_resources( build_resources(
lg-logo.svg lg-logo.svg
status/spice.svg status/spice.svg
@@ -22,5 +26,5 @@ build_resources(
no-input-cursor/32.xcur no-input-cursor/32.xcur
) )
add_library(lg_resources STATIC ${LG_RESOURCES_OBJS}) add_library(lg_resources STATIC ${RESOURCES_SOURCES} ${LG_RESOURCES_OBJS})
set_target_properties(lg_resources PROPERTIES LINKER_LANGUAGE C) set_target_properties(lg_resources PROPERTIES LINKER_LANGUAGE C)

View File

@@ -536,4 +536,4 @@ const unsigned long icondata[] = {
0xff9761c4, 0xff9761c4, 0xff9660c3, 0xf0905cbc, 0xaa905cbc, 0x4e8554af, 0x068150aa, 0x00000000, 0xff9761c4, 0xff9761c4, 0xff9660c3, 0xf0905cbc, 0xaa905cbc, 0x4e8554af, 0x068150aa, 0x00000000,
0x00000000, 0x00000000 0x00000000, 0x00000000
}; };
const unsigned icondataSize = sizeof(icondata);

22
resources/icondata.h Normal file
View File

@@ -0,0 +1,22 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
extern const unsigned long icondata[];
extern const unsigned icondataSize;