Handle output hotplug
This commit is contained in:
parent
86f0dee5cc
commit
f30c7c3172
1 changed files with 34 additions and 6 deletions
40
src/main.rs
40
src/main.rs
|
|
@ -26,6 +26,7 @@ use wayland_protocols_wlr::{
|
||||||
const IDLE_TIME: u32 = 3000;
|
const IDLE_TIME: u32 = 3000;
|
||||||
const FADE_TIME: Duration = Duration::from_millis(2000);
|
const FADE_TIME: Duration = Duration::from_millis(2000);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct FadeBlackSurface {
|
struct FadeBlackSurface {
|
||||||
surface: wl_surface::WlSurface,
|
surface: wl_surface::WlSurface,
|
||||||
layer_surface: zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
|
layer_surface: zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
|
||||||
|
|
@ -93,10 +94,12 @@ impl Drop for FadeBlackSurface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Output {
|
struct Output {
|
||||||
output: wl_output::WlOutput,
|
output: wl_output::WlOutput,
|
||||||
output_power: zwlr_output_power_v1::ZwlrOutputPowerV1,
|
output_power: zwlr_output_power_v1::ZwlrOutputPowerV1,
|
||||||
fade_surface: Option<FadeBlackSurface>,
|
fade_surface: Option<FadeBlackSurface>,
|
||||||
|
global_name: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StateInner {
|
struct StateInner {
|
||||||
|
|
@ -170,12 +173,13 @@ fn main() {
|
||||||
.map(|global| {
|
.map(|global| {
|
||||||
let output = globals
|
let output = globals
|
||||||
.registry()
|
.registry()
|
||||||
.bind(global.name, global.version, &qh, ());
|
.bind(global.name, global.version.min(3), &qh, ());
|
||||||
let output_power = output_power_manager.get_output_power(&output, &qh, ());
|
let output_power = output_power_manager.get_output_power(&output, &qh, ());
|
||||||
Output {
|
Output {
|
||||||
output,
|
output,
|
||||||
output_power,
|
output_power,
|
||||||
fade_surface: None,
|
fade_surface: None,
|
||||||
|
global_name: global.name,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
@ -201,14 +205,39 @@ fn main() {
|
||||||
|
|
||||||
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for State {
|
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for State {
|
||||||
fn event(
|
fn event(
|
||||||
_: &mut Self,
|
state: &mut Self,
|
||||||
_: &wl_registry::WlRegistry,
|
registry: &wl_registry::WlRegistry,
|
||||||
event: wl_registry::Event,
|
event: wl_registry::Event,
|
||||||
_: &GlobalListContents,
|
_: &GlobalListContents,
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
qh: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
dbg!(event);
|
match event {
|
||||||
|
wl_registry::Event::Global {
|
||||||
|
name,
|
||||||
|
interface,
|
||||||
|
version,
|
||||||
|
} => {
|
||||||
|
if interface == "wl_output" {
|
||||||
|
let output = registry.bind(name, version.min(3), qh, ());
|
||||||
|
let output_power =
|
||||||
|
state
|
||||||
|
.inner
|
||||||
|
.output_power_manager
|
||||||
|
.get_output_power(&output, &qh, ());
|
||||||
|
state.outputs.push(Output {
|
||||||
|
output,
|
||||||
|
output_power,
|
||||||
|
fade_surface: None,
|
||||||
|
global_name: name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wl_registry::Event::GlobalRemove { name } => {
|
||||||
|
state.outputs.retain(|output| output.global_name != name);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,7 +283,6 @@ impl Dispatch<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, ()> for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg!(width, height);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue