Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ add_subdirectory(test_set_wallpaper)
add_subdirectory(test_set_xwindow_position)
add_subdirectory(test_idle_inhibit_v1)
add_subdirectory(test_toplevel_tag)
add_subdirectory(test_im_candidate_panel_tag)
add_subdirectory(test_im_candidate_panel_xprop)
add_subdirectory(test_input_manager)
add_subdirectory(test_keyboard_state_notify)
44 changes: 44 additions & 0 deletions examples/test_im_candidate_panel_tag/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
find_package(PkgConfig REQUIRED)
pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir)
find_program(WAYLAND_SCANNER wayland-scanner REQUIRED)

pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)

set(PROTOCOL_DIR ${CMAKE_CURRENT_BINARY_DIR})

# Generate xdg-toplevel-tag-v1 client code
set(TAG_PROTOCOL ${WAYLAND_PROTOCOLS_DATADIR}/staging/xdg-toplevel-tag/xdg-toplevel-tag-v1.xml)
set(TAG_CLIENT_H ${PROTOCOL_DIR}/xdg-toplevel-tag-v1-client-protocol.h)
set(TAG_CLIENT_CODE ${PROTOCOL_DIR}/xdg-toplevel-tag-v1-client-protocol.c)

add_custom_command(
OUTPUT ${TAG_CLIENT_H} ${TAG_CLIENT_CODE}
COMMAND ${WAYLAND_SCANNER} private-code < ${TAG_PROTOCOL} > ${TAG_CLIENT_CODE}
COMMAND ${WAYLAND_SCANNER} client-header < ${TAG_PROTOCOL} > ${TAG_CLIENT_H}
DEPENDS ${TAG_PROTOCOL}
COMMENT "Generating xdg-toplevel-tag-v1 protocol"
VERBATIM
)

# Generate xdg-shell client code
set(XDG_SHELL_PROTOCOL ${WAYLAND_PROTOCOLS_DATADIR}/stable/xdg-shell/xdg-shell.xml)
set(XDG_SHELL_CLIENT_H ${PROTOCOL_DIR}/xdg-shell-client-protocol.h)
set(XDG_SHELL_CLIENT_CODE ${PROTOCOL_DIR}/xdg-shell-client-protocol.c)

add_custom_command(
OUTPUT ${XDG_SHELL_CLIENT_H} ${XDG_SHELL_CLIENT_CODE}
COMMAND ${WAYLAND_SCANNER} private-code < ${XDG_SHELL_PROTOCOL} > ${XDG_SHELL_CLIENT_CODE}
COMMAND ${WAYLAND_SCANNER} client-header < ${XDG_SHELL_PROTOCOL} > ${XDG_SHELL_CLIENT_H}
DEPENDS ${XDG_SHELL_PROTOCOL}
COMMENT "Generating xdg-shell protocol"
VERBATIM
)

set(BIN_NAME test-im-candidate-panel-tag)

add_executable(${BIN_NAME} main.c ${TAG_CLIENT_CODE} ${XDG_SHELL_CLIENT_CODE})

target_include_directories(${BIN_NAME} PRIVATE ${PROTOCOL_DIR})
target_link_libraries(${BIN_NAME} PRIVATE ${WAYLAND_CLIENT_LIBRARIES})

install(TARGETS ${BIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
186 changes: 186 additions & 0 deletions examples/test_im_candidate_panel_tag/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright (C) 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#define _GNU_SOURCE
#include "xdg-shell-client-protocol.h"

Check warning on line 5 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "xdg-shell-client-protocol.h" not found.
#include "xdg-toplevel-tag-v1-client-protocol.h"

Check warning on line 6 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "xdg-toplevel-tag-v1-client-protocol.h" not found.

#include <wayland-client.h>

Check warning on line 8 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <wayland-client.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <fcntl.h>

Check warning on line 10 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <fcntl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <stdio.h>

Check warning on line 11 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <stdlib.h>

Check warning on line 12 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <stdlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string.h>

Check warning on line 13 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <sys/mman.h>

Check warning on line 14 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/mman.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <unistd.h>

Check warning on line 15 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

static struct wl_display *display = NULL;
static struct wl_surface *surface = NULL;
static struct xdg_surface *xdg_surface = NULL;
static struct xdg_toplevel *xdg_toplevel = NULL;
static struct wl_buffer *buffer = NULL;

Check warning on line 21 in examples/test_im_candidate_panel_tag/main.c

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'buffer' shadows outer variable

static void cleanup(void)
{
if (buffer)
wl_buffer_destroy(buffer);
if (xdg_toplevel)
xdg_toplevel_destroy(xdg_toplevel);
if (xdg_surface)
xdg_surface_destroy(xdg_surface);
if (surface)
wl_surface_destroy(surface);
if (display)
wl_display_disconnect(display);
}

static struct wl_compositor *compositor = NULL;
static struct xdg_wm_base *wm_base = NULL;
static struct xdg_toplevel_tag_manager_v1 *tag_manager = NULL;
static struct wl_shm *shm = NULL;

static int create_shm_fd(int size)
{
int fd = memfd_create("wayland-shm", MFD_CLOEXEC);
if (fd < 0)
return -1;
if (ftruncate(fd, size) < 0) {
close(fd);
return -1;
}
return fd;
}

static struct wl_buffer *create_shm_buffer(int width, int height)
{
int stride = width * 4;
int size = stride * height;
int fd = create_shm_fd(size);
if (fd < 0) {
fprintf(stderr, "Failed to create shm fd\n");
return NULL;
}

uint32_t *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
close(fd);
return NULL;
}

for (int i = 0; i < width * height; i++)
data[i] = 0xFF2266AA;

struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);
struct wl_buffer *buffer =
wl_shm_pool_create_buffer(pool, 0, width, height, stride, WL_SHM_FORMAT_XRGB8888);
wl_shm_pool_destroy(pool);
munmap(data, size);
close(fd);
return buffer;
}

static void xdg_surface_configure([[maybe_unused]] void *data,
struct xdg_surface *xdg_surface,
uint32_t serial)
{
xdg_surface_ack_configure(xdg_surface, serial);
}

static const struct xdg_surface_listener xdg_surface_listener = {
.configure = xdg_surface_configure,
};

static void xdg_wm_base_ping([[maybe_unused]] void *data,
struct xdg_wm_base *xdg_wm_base,
uint32_t serial)
{
xdg_wm_base_pong(xdg_wm_base, serial);
}

static const struct xdg_wm_base_listener xdg_wm_base_listener = {
.ping = xdg_wm_base_ping,
};

static void registry_global([[maybe_unused]] void *data,
struct wl_registry *registry,
uint32_t id,
const char *interface,
uint32_t version)
{
if (strcmp(interface, wl_compositor_interface.name) == 0) {
compositor = wl_registry_bind(registry, id, &wl_compositor_interface, version);
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
wm_base = wl_registry_bind(registry, id, &xdg_wm_base_interface, version);
xdg_wm_base_add_listener(wm_base, &xdg_wm_base_listener, NULL);
} else if (strcmp(interface, xdg_toplevel_tag_manager_v1_interface.name) == 0) {
tag_manager = wl_registry_bind(registry, id, &xdg_toplevel_tag_manager_v1_interface, 1);
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
shm = wl_registry_bind(registry, id, &wl_shm_interface, version);
}
}

static void registry_global_remove([[maybe_unused]] void *data,
[[maybe_unused]] struct wl_registry *registry,
[[maybe_unused]] uint32_t id)
{
}

static const struct wl_registry_listener registry_listener = {
.global = registry_global,
.global_remove = registry_global_remove,
};

int main()
{
display = wl_display_connect(NULL);
if (!display) {
fprintf(stderr, "Failed to connect to wayland display\n");
return 1;
}

struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(display);

if (!compositor || !wm_base || !tag_manager || !shm) {
fprintf(stderr, "Missing required interfaces\n");
wl_display_disconnect(display);
return 1;
}

int width = 400, height = 100;
surface = wl_compositor_create_surface(compositor);

xdg_surface = xdg_wm_base_get_xdg_surface(wm_base, surface);
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, NULL);

xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
xdg_toplevel_set_title(xdg_toplevel, "IM Candidate Panel Tag Test");
xdg_toplevel_set_app_id(xdg_toplevel, "im-candidate-panel-tag");

buffer = create_shm_buffer(width, height);
if (!buffer) {
fprintf(stderr, "Failed to create buffer\n");
cleanup();
return 1;
}

// Set tag BEFORE the first commit
xdg_toplevel_tag_manager_v1_set_toplevel_tag(tag_manager,
xdg_toplevel,
"org.deepin.treeland.im-candidate-panel");
fprintf(stderr, "Tag set: org.deepin.treeland.im-candidate-panel\n");

// First commit: initial commit without buffer, wait for configure
wl_surface_commit(surface);
wl_display_roundtrip(display);

// Attach buffer after configure is acked
wl_surface_attach(surface, buffer, 0, 0);
wl_surface_commit(surface);

while (wl_display_dispatch(display) != -1) { }

cleanup();
return 0;
}
14 changes: 14 additions & 0 deletions examples/test_im_candidate_panel_xprop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
find_package(Qt6 REQUIRED COMPONENTS Widgets)
find_package(PkgConfig REQUIRED)
pkg_check_modules(XCB REQUIRED xcb)

set(BIN_NAME test-im-candidate-panel-xprop)

qt_add_executable(${BIN_NAME}
main.cpp
)

target_include_directories(${BIN_NAME} PRIVATE ${XCB_INCLUDE_DIRS})
target_link_libraries(${BIN_NAME} PRIVATE Qt6::Widgets ${XCB_LIBRARIES})

install(TARGETS ${BIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
86 changes: 86 additions & 0 deletions examples/test_im_candidate_panel_xprop/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (C) 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include <xcb/xcb.h>

#include <QApplication>
#include <QDebug>
#include <QLabel>
#include <QMainWindow>
#include <QWidget>

int main(int argc, char **argv)
{
// Force X11 platform
qputenv("QT_QPA_PLATFORM", "xcb");

QApplication app(argc, argv);

QMainWindow window;
window.setWindowTitle("IM Candidate Panel XProp Test");
window.resize(400, 100);

auto *label = new QLabel("example im-candidate-panel/xprop", &window);
label->setAlignment(Qt::AlignCenter);
window.setCentralWidget(label);

// Force platform window creation before show, so we can set xprop
WId wid = window.winId();

// Set _DEEPIN_IM_CANDIDATE_PANEL xprop: type=CARDINAL, value=1
xcb_connection_t *conn = xcb_connect(nullptr, nullptr);
if (xcb_connection_has_error(conn)) {
qWarning() << "Failed to connect to X server";
return 1;
}

xcb_intern_atom_cookie_t atom_cookie = xcb_intern_atom(conn,
0,
strlen("_DEEPIN_IM_CANDIDATE_PANEL"),
"_DEEPIN_IM_CANDIDATE_PANEL");
xcb_intern_atom_reply_t *atom_reply = xcb_intern_atom_reply(conn, atom_cookie, nullptr);
if (!atom_reply) {
qWarning() << "Failed to intern atom";
xcb_disconnect(conn);
return 1;
}
xcb_atom_t atom = atom_reply->atom;

xcb_intern_atom_cookie_t cardinal_cookie =
xcb_intern_atom(conn, 0, strlen("CARDINAL"), "CARDINAL");
xcb_intern_atom_reply_t *cardinal_reply = xcb_intern_atom_reply(conn, cardinal_cookie, nullptr);
if (!cardinal_reply) {
qWarning() << "Failed to intern CARDINAL atom";
free(atom_reply);
xcb_disconnect(conn);
return 1;
}
xcb_atom_t cardinal = cardinal_reply->atom;

uint32_t value = 1;
xcb_void_cookie_t change_cookie = xcb_change_property_checked(conn,
XCB_PROP_MODE_REPLACE,
wid,
atom,
cardinal,
32,
1,
&value);
xcb_flush(conn);

xcb_generic_error_t *error = xcb_request_check(conn, change_cookie);
if (error) {
qWarning() << "xcb_change_property failed: error_code=" << error->error_code;
free(error);
} else {
qDebug() << "Set _DEEPIN_IM_CANDIDATE_PANEL=1 on window" << wid;
}

free(cardinal_reply);
free(atom_reply);
xcb_disconnect(conn);

window.show();

return app.exec();
}
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ qt_add_qml_module(libtreeland
core/qmlengine.h
core/rootsurfacecontainer.cpp
core/rootsurfacecontainer.h
core/imcandidatepanelmanager.cpp
core/imcandidatepanelmanager.h
core/shellhandler.cpp
core/shellhandler.h
core/treeland.cpp
Expand Down
Loading
Loading