加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
wayland_3.c 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
BostonHsu 提交于 2023-11-14 20:30 . My third app of wayland.
#include <stdio.h>
#include <string.h>
#include <wayland-client.h>
struct wl_compositor *compositor;
struct wl_shm *shm;
struct wl_shell *shell;
void registry_global_handler
(
void *data,
struct wl_registry *registry,
uint32_t name,
const char *interface,
uint32_t version
) {
if (strcmp(interface, "wl_compositor") == 0) {
compositor = wl_registry_bind(registry, name,
&wl_compositor_interface, 3);
} else if (strcmp(interface, "wl_shm") == 0) {
shm = wl_registry_bind(registry, name,
&wl_shm_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) {
shell = wl_registry_bind(registry, name,
&wl_shell_interface, 1);
}
}
void registry_global_remove_handler
(
void *data,
struct wl_registry *registry,
uint32_t name
) {}
const struct wl_registry_listener registry_listener = {
.global = registry_global_handler,
.global_remove = registry_global_remove_handler
};
int main(void)
{
struct wl_display *display = wl_display_connect(NULL);
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, NULL);
// wait for the "initial" set of globals to appear
wl_display_roundtrip(display);
// all our objects should be ready!
if (compositor && shm && shell) {
printf("Got them all!\n");
} else {
printf("Some required globals unavailable\n");
return 1;
}
while (1) {
wl_display_dispatch(display);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化