wayland数据结构之wl_map

wl_map结构体在Wayland中用于管理客户端和服务器端的对象,包含client_entries和server_entries两个wl_array数组分别保存不同端的对象。side字段指示当前保存的对象类型,free_list则构成一个链表,记录已删除对象的位置。map_entry结构体的data字段存储对象地址,利用最后两位分别表示flags和对象删除状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

struct wl_map {
struct wl_array client_entries;
struct wl_array server_entries;
uint32_t side;
uint32_t free_list;
};


struct wl_array {
/** Array size */
size_t size;
/** Allocated space */
size_t alloc;
/** Array data */
void *data;
};


union map_entry {
uintptr_t next;
void *data;
};


wl_map结构体存放wayland客户端和服务器端对应的对象。其中:
client_entries: 用wl_array数组保存客户端的对象。(这种情况server_entries不使用)


server_entries:用wl_array数组保存服务器端的对象。(这种情况client_entries不使用)


side:表明当前map保存的是客户端还是服务器端对象(通过这个变量,确定client_entries/server_entries里面保存有对象)


free_list:这个变量用来记录当前已经被删除了的对象的存放位置,但是对这个位置做了个处理。((i << 1) | 1  : i代表下标, 也就是指针的最后一位置为1&
### Wayland 客户端 `wl_output` 使用说明 在 Wayland 协议中,`wl_output` 接口用于描述显示输出设备的信息并提供事件通知机制。对于开发者而言,在编写 Wayland 客户端应用程序时理解如何处理这些接口至关重要。 #### 获取 `wl_output` 对象实例 为了访问特定的显示器属性或监听其变化,首先需要通过全局管理器获取到对应的 `wl_output` 实例: ```c struct wl_output *output; // 假设已经初始化好了一个有效的 display 连接 output = wl_registry_bind(registry, id, &wl_output_interface, version); ``` 这里假设已经在注册表回调函数里捕获到了相应的 ID 和版本号[^1]。 #### 处理 `wl_output` 事件 一旦绑定了对象,则可以设置自己的事件处理器来响应来自服务器的消息,比如几何尺寸改变、刷新率更新等重要信息: ```c static void handle_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform) { printf("Output geometry changed\n"); } static const struct wl_output_listener output_listener = { .geometry = handle_geometry, }; wl_output_add_listener(output, &output_listener, NULL); ``` 上述代码片段展示了如何定义一个简单的几何变换事件处理器,并将其附加给指定的 `wl_output` 实例。 #### 查询当前状态 除了被动等待事件外,还可以主动查询某个时刻下的配置情况,例如调用 `release()` 方法之前读取最新的模式数据: ```c uint32_t width, height; int32_t refresh; /* ... */ if (current_mode != NULL) { width = current_mode->width; height = current_mode->height; refresh = current_mode->refresh; } ``` 这允许客户端应用根据实际屏幕参数调整自身的布局逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值