mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-07-17 04:42:01 +00:00
[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
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:
@@ -16,6 +16,7 @@ add_library(displayserver_Wayland STATIC
|
||||
colormgmt.c
|
||||
cursor.c
|
||||
gl.c
|
||||
icon.c
|
||||
idle.c
|
||||
input.c
|
||||
output.c
|
||||
@@ -33,6 +34,7 @@ add_subdirectory(desktops)
|
||||
target_link_libraries(displayserver_Wayland
|
||||
PkgConfig::DISPLAYSERVER_Wayland
|
||||
lg_common
|
||||
lg_resources
|
||||
wayland_protocol
|
||||
wayland_desktops
|
||||
)
|
||||
|
||||
@@ -142,6 +142,11 @@ static bool libdecor_shellInit(
|
||||
libdecor_frame_set_title(state.libdecorFrame, title);
|
||||
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)
|
||||
libdecor_frame_set_fullscreen(state.libdecorFrame, NULL);
|
||||
|
||||
|
||||
@@ -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_set_title(state.toplevel, title);
|
||||
xdg_toplevel_set_app_id(state.toplevel, appId);
|
||||
wlWm.xdgToplevel = state.toplevel;
|
||||
|
||||
if (fullscreen)
|
||||
xdg_toplevel_set_fullscreen(state.toplevel, NULL);
|
||||
|
||||
136
client/displayservers/Wayland/icon.c
Normal file
136
client/displayservers/Wayland/icon.c
Normal 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
|
||||
}
|
||||
@@ -69,6 +69,9 @@ wayland_generate(
|
||||
wayland_generate(
|
||||
"${WAYLAND_PROTOCOLS_BASE}/staging/color-management/color-management-v1.xml"
|
||||
"${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
|
||||
PkgConfig::WAYLAND
|
||||
|
||||
@@ -77,6 +77,9 @@ static void registryGlobalHandler(void * data, struct wl_registry * registry,
|
||||
else if (!strcmp(interface, wp_color_manager_v1_interface.name))
|
||||
wlWm.colorManager = wl_registry_bind(wlWm.registry, name,
|
||||
&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(
|
||||
data, registry, name, interface, version))
|
||||
return;
|
||||
|
||||
@@ -170,6 +170,8 @@ static bool waylandInit(const LG_DSInitParams params)
|
||||
if (!waylandEGLInit(params.w, params.h))
|
||||
return false;
|
||||
|
||||
waylandIconInit();
|
||||
|
||||
#ifdef ENABLE_OPENGL
|
||||
if (params.opengl && !waylandOpenGLInit())
|
||||
return false;
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "wayland-fractional-scale-v1-client-protocol.h"
|
||||
#include "wayland-content-type-v1-client-protocol.h"
|
||||
#include "wayland-color-management-v1-client-protocol.h"
|
||||
#include "wayland-xdg-toplevel-icon-v1-client-protocol.h"
|
||||
|
||||
#include "scale.h"
|
||||
|
||||
@@ -205,6 +206,12 @@ struct WaylandDSState
|
||||
bool cmHasPerceptualIntent;
|
||||
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).
|
||||
// pendingHDRApply and pendingHDRClear are accessed from multiple threads
|
||||
// without a lock, so they must be atomic.
|
||||
@@ -370,3 +377,6 @@ bool waylandWaitFrame(void);
|
||||
void waylandSkipFrame(void);
|
||||
void waylandStopWaitFrame(void);
|
||||
void waylandNeedsResize(void);
|
||||
|
||||
// icon module
|
||||
bool waylandIconInit(void);
|
||||
|
||||
@@ -617,7 +617,7 @@ static bool x11Init(const LG_DSInitParams params)
|
||||
32,
|
||||
PropModeReplace,
|
||||
(unsigned char *)icondata,
|
||||
sizeof(icondata) / sizeof(icondata[0])
|
||||
icondataSize / sizeof(icondata[0])
|
||||
);
|
||||
|
||||
/* create the blank cursor */
|
||||
|
||||
Reference in New Issue
Block a user