系列索引地址:Wayland开发入门教程索引
上一篇:Wayland开发入门教程11:shell stable协议
上一篇介绍的是stable版的协议,本文介绍unstable版的协议。
窗口部分是一样的。
我们使用新协议的对象
1 2 3
| struct zxdg_shell_v6 *xdg_shell; struct zxdg_surface_v6 *shell_surface; struct zxdg_toplevel_v6 *toplevel;
|
创建新对象
1 2 3 4 5 6 7 8 9 10 11 12
| shell_surface = zxdg_shell_v6_get_xdg_surface(xdg_shell, surface); if (shell_surface == NULL) { fprintf(stderr, "Can't create shell surface\n"); exit(1); } else { fprintf(stderr, "Created shell surface\n"); } toplevel = zxdg_surface_v6_get_toplevel(shell_surface); zxdg_surface_v6_add_listener(shell_surface,&surface_listener,NULL);
|
需要监听新的注册事件
1 2 3 4 5 6 7 8 9 10 11 12 13
| static void global_registry_handler(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { if (strcmp(interface, "wl_compositor") == 0){ BIND_WL_REG(registry, compositor, id, &wl_compositor_interface, 1); }else if (strcmp(interface, zxdg_shell_v6_interface.name) == 0){ BIND_WL_REG(registry, xdg_shell, id, &zxdg_shell_v6_interface, 1); }else if (strcmp(interface, "wl_shm") == 0){ BIND_WL_REG(registry, shm, id, &wl_shm_interface, 1); wl_shm_add_listener(shm, &shm_listener, NULL); } }
|
窗口监听和处理
1 2 3 4 5 6 7
| static void handle_configure(void *data, struct zxdg_surface_v6 *surface, uint32_t serial) { zxdg_surface_v6_ack_configure(surface, serial); }
static const struct zxdg_surface_v6_listener surface_listener = { .configure = handle_configure };
|
编译
协议以xml格式提供,我们在使用时要把它生成为代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| WAYLAND_FLAGS = $(shell pkg-config wayland-client --cflags --libs) WAYLAND_PROTOCOLS_DIR = $(shell pkg-config wayland-protocols --variable=pkgdatadir) WAYLAND_SCANNER = $(shell pkg-config --variable=wayland_scanner wayland-scanner)
XDG_SHELL_PROTOCOL = $(WAYLAND_PROTOCOLS_DIR)/unstable/xdg-shell/xdg-shell-unstable-v6.xml
HEADERS=xdg-shell-unstable-v6-protocol.h SOURCES=xdg-shell-unstable-v6-protocol.c
all: $(HEADERS) $(SOURCES) gcc -o shell_unstable shell_unstable.c $(SOURCES) -I. -lwayland-client -lwayland-egl -lEGL -lGL
xdg-shell-unstable-v6-protocol.h: $(WAYLAND_SCANNER) client-header $(XDG_SHELL_PROTOCOL) xdg-shell-unstable-v6-protocol.h
xdg-shell-unstable-v6-protocol.c: $(WAYLAND_SCANNER) private-code $(XDG_SHELL_PROTOCOL) xdg-shell-unstable-v6-protocol.c
clean: rm -rf shell_stable $(HEADERS) $(SOURCES)
|
理论上显示效果和之前的窗口一样。但是我编译成功了,没有运行成功。
EGL版本只是替换了窗口显示部分,其他的代码一样。
完整代码在Wayland_Freshman中的12.shell_unstable
、12.shell_unstable_EGL
下。
下一篇:Wayland开发入门教程13:输入设备管理器