Skip to content

Commit 5b6927e

Browse files
committed
Add treeland output manager support
- add treeland_output_manager_v1 protocol dependency - track treeland output manager state and primary output - expose treeland output manager data in JSON and CLI output
1 parent 5b131eb commit 5b6927e

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

Cargo.lock

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ documentation = "https://github.com/dwapp/wayland-info-rs/blob/main/USAGE.md"
1313
colored = "3.0.0"
1414
wayland-client = "0.31.7"
1515
wayland-protocols = { version = "0.32.10", features = ["staging", "unstable", "client"] }
16+
wayland-protocols-treeland = { version = "0.1.0", features = ["client"] }
1617
serde = { version = "1.0", features = ["derive"] }
1718
serde_json = "1.0"

src/main.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use wayland_protocols::xdg::xdg_output::zv1::client::{
1717
zxdg_output_manager_v1::{self, ZxdgOutputManagerV1},
1818
zxdg_output_v1::{self, ZxdgOutputV1},
1919
};
20+
use wayland_protocols_treeland::output_manager::v1::client::treeland_output_manager_v1::{
21+
self, TreelandOutputManagerV1,
22+
};
2023

2124
// 全局信息结构
2225
#[derive(Debug, Clone, Serialize)]
@@ -113,6 +116,15 @@ struct PresentationInfo {
113116
clock_id: Option<u32>,
114117
}
115118

119+
// Treeland Output Manager 信息结构
120+
#[derive(Debug, Clone, Serialize)]
121+
#[serde(rename_all = "camelCase")]
122+
struct TreelandOutputManagerInfo {
123+
#[serde(skip_serializing)]
124+
name: u32,
125+
primary_output: Option<String>,
126+
}
127+
116128
// XDG Output Manager 信息结构
117129
#[derive(Debug, Clone, Serialize)]
118130
#[serde(rename_all = "camelCase")]
@@ -157,11 +169,13 @@ struct AppData {
157169
shm_info: Vec<ShmInfo>,
158170
drm_lease_devices: Vec<DrmLeaseDeviceInfo>,
159171
presentation_info: Vec<PresentationInfo>,
172+
treeland_output_managers: Vec<TreelandOutputManagerInfo>,
160173
xdg_output_managers: Vec<XdgOutputManagerInfo>,
161174
seat_objects: Vec<WlSeat>,
162175
output_objects: Vec<WlOutput>,
163176
shm_objects: Vec<WlShm>,
164177
presentation_objects: Vec<WpPresentation>,
178+
treeland_output_manager_objects: Vec<TreelandOutputManagerV1>,
165179
xdg_output_manager_objects: Vec<ZxdgOutputManagerV1>,
166180
xdg_output_objects: Vec<ZxdgOutputV1>,
167181
}
@@ -176,6 +190,7 @@ struct JsonOutput {
176190
shm_info: Vec<ShmInfo>,
177191
drm_lease_devices: Vec<DrmLeaseDeviceInfo>,
178192
presentation_info: Vec<PresentationInfo>,
193+
treeland_output_managers: Vec<TreelandOutputManagerInfo>,
179194
xdg_output_managers: Vec<XdgOutputManagerInfo>,
180195
}
181196

@@ -202,11 +217,13 @@ impl AppData {
202217
shm_info: Vec::new(),
203218
drm_lease_devices: Vec::new(),
204219
presentation_info: Vec::new(),
220+
treeland_output_managers: Vec::new(),
205221
xdg_output_managers: Vec::new(),
206222
seat_objects: Vec::new(),
207223
output_objects: Vec::new(),
208224
shm_objects: Vec::new(),
209225
presentation_objects: Vec::new(),
226+
treeland_output_manager_objects: Vec::new(),
210227
xdg_output_manager_objects: Vec::new(),
211228
xdg_output_objects: Vec::new(),
212229
}
@@ -307,6 +324,19 @@ impl AppData {
307324
}
308325
}
309326

327+
fn add_treeland_output_manager(&mut self, name: u32) {
328+
self.treeland_output_managers.push(TreelandOutputManagerInfo {
329+
name,
330+
primary_output: None,
331+
});
332+
}
333+
334+
fn update_treeland_primary_output(&mut self, manager_index: usize, output_name: String) {
335+
if let Some(manager) = self.treeland_output_managers.get_mut(manager_index) {
336+
manager.primary_output = Some(output_name);
337+
}
338+
}
339+
310340
fn update_seat_capabilities(&mut self, seat_index: usize, capabilities: Vec<String>) {
311341
if let Some(seat) = self.seats.get_mut(seat_index) {
312342
seat.capabilities = capabilities;
@@ -491,6 +521,7 @@ impl AppData {
491521
shm_info: self.shm_info.clone(),
492522
drm_lease_devices: self.drm_lease_devices.clone(),
493523
presentation_info: self.presentation_info.clone(),
524+
treeland_output_managers: self.treeland_output_managers.clone(),
494525
xdg_output_managers: self.xdg_output_managers.clone(),
495526
}
496527
}
@@ -657,6 +688,21 @@ impl AppData {
657688
}
658689
}
659690

691+
// 打印 treeland_output_manager_v1 信息
692+
if global.interface == "treeland_output_manager_v1" {
693+
if let Some(manager) = self
694+
.treeland_output_managers
695+
.iter()
696+
.find(|m| m.name == global.name)
697+
{
698+
if let Some(primary) = &manager.primary_output {
699+
println!(" Primary output: {}", primary.yellow());
700+
} else {
701+
println!("{}", " Primary output: <unknown>".red());
702+
}
703+
}
704+
}
705+
660706
// 打印 zxdg_output_manager_v1 信息
661707
if global.interface == "zxdg_output_manager_v1" {
662708
if let Some(manager) = self
@@ -724,6 +770,9 @@ enum UserData {
724770
Presentation {
725771
presentation_index: usize,
726772
},
773+
TreelandOutputManager {
774+
manager_index: usize,
775+
},
727776
XdgOutputManager {
728777
manager_index: usize,
729778
},
@@ -800,6 +849,16 @@ impl Dispatch<wl_registry::WlRegistry, ()> for AppData {
800849
UserData::Presentation { presentation_index },
801850
);
802851
state.presentation_objects.push(presentation);
852+
} else if interface == "treeland_output_manager_v1" {
853+
state.add_treeland_output_manager(name);
854+
let manager_index = state.treeland_output_managers.len() - 1;
855+
let manager = registry.bind::<TreelandOutputManagerV1, _, _>(
856+
name,
857+
version,
858+
qh,
859+
UserData::TreelandOutputManager { manager_index },
860+
);
861+
state.treeland_output_manager_objects.push(manager);
803862
} else if interface == "zxdg_output_manager_v1" {
804863
state.add_xdg_output_manager(name);
805864
let manager_index = state.xdg_output_managers.len() - 1;
@@ -816,6 +875,24 @@ impl Dispatch<wl_registry::WlRegistry, ()> for AppData {
816875
}
817876
}
818877

878+
// 实现 treeland_output_manager_v1 的事件处理
879+
impl Dispatch<TreelandOutputManagerV1, UserData> for AppData {
880+
fn event(
881+
state: &mut Self,
882+
_manager: &TreelandOutputManagerV1,
883+
event: treeland_output_manager_v1::Event,
884+
data: &UserData,
885+
_conn: &Connection,
886+
_qh: &QueueHandle<AppData>,
887+
) {
888+
if let UserData::TreelandOutputManager { manager_index } = data {
889+
if let treeland_output_manager_v1::Event::PrimaryOutput { output_name } = event {
890+
state.update_treeland_primary_output(*manager_index, output_name);
891+
}
892+
}
893+
}
894+
}
895+
819896
// 实现 wl_seat 的事件处理
820897
impl Dispatch<WlSeat, UserData> for AppData {
821898
fn event(

0 commit comments

Comments
 (0)