feat: handle global removals, recalc output scale (#367)
All `GlobalRemove` events sent from the server are now handled by recording them in a new clientside `vec` and passing the identifier returned by `create_global` (now stored by a map in the state) to `disable_global`. `handle_globals` (the top-level function) and `handle_new_globals` (the `InnerServerState` member function) have swapped names to better represent their new purposes. This enables action to be taken when globals are removed. In this case, the desired action is to forward output removal, so that the scaling calculation does not account for disconnected monitors in its logic. Resolves #351.
This commit is contained in:
parent
75c9f5e775
commit
0947c4685f
6 changed files with 153 additions and 33 deletions
|
|
@ -233,6 +233,7 @@ struct DataSourceData {
|
|||
struct Output {
|
||||
name: String,
|
||||
xdg: Option<ZxdgOutputV1>,
|
||||
global_id: Option<GlobalId>,
|
||||
}
|
||||
|
||||
struct KeyboardState {
|
||||
|
|
@ -266,6 +267,8 @@ struct State {
|
|||
last_surface_id: Option<SurfaceId>,
|
||||
created_surfaces: Vec<SurfaceId>,
|
||||
last_output: Option<WlOutput>,
|
||||
last_output_global: Option<GlobalId>,
|
||||
output_counter: u32,
|
||||
callbacks: Vec<WlCallback>,
|
||||
seat: Option<WlSeat>,
|
||||
pointer: Option<PointerState>,
|
||||
|
|
@ -296,6 +299,8 @@ impl Default for State {
|
|||
begin: Instant::now(),
|
||||
last_surface_id: None,
|
||||
last_output: None,
|
||||
last_output_global: None,
|
||||
output_counter: 0,
|
||||
callbacks: Vec::new(),
|
||||
seat: None,
|
||||
pointer: None,
|
||||
|
|
@ -572,13 +577,15 @@ impl Server {
|
|||
&self.state.created_surfaces
|
||||
}
|
||||
|
||||
/// Finish the initialization of an output created by `new_output`.
|
||||
/// This function must be called after the globals have been dispatched in order to use the
|
||||
/// output on the server side created by `new_output` (this function's return value).
|
||||
#[track_caller]
|
||||
pub fn last_created_output(&self) -> WlOutput {
|
||||
self.state
|
||||
.last_output
|
||||
.as_ref()
|
||||
.expect("No outputs created!")
|
||||
.clone()
|
||||
pub fn finalize_output(&mut self) -> WlOutput {
|
||||
let output_s = self.state.last_output.take().expect("No new outputs");
|
||||
let output_data = self.state.outputs.get_mut(&output_s).unwrap();
|
||||
output_data.global_id = self.state.last_output_global.take();
|
||||
output_s
|
||||
}
|
||||
|
||||
pub fn get_object<T: Resource + 'static>(
|
||||
|
|
@ -845,7 +852,8 @@ impl Server {
|
|||
}
|
||||
|
||||
pub fn new_output(&mut self, x: i32, y: i32) {
|
||||
self.dh.create_global::<State, WlOutput, _>(4, (x, y));
|
||||
self.state.last_output_global =
|
||||
Some(self.dh.create_global::<State, WlOutput, _>(4, (x, y)));
|
||||
self.display.flush_clients().unwrap();
|
||||
}
|
||||
|
||||
|
|
@ -877,6 +885,12 @@ impl Server {
|
|||
self.display.flush_clients().unwrap();
|
||||
}
|
||||
|
||||
pub fn remove_output(&mut self, output: WlOutput) {
|
||||
let output = self.state.outputs.remove(&output).unwrap();
|
||||
self.dh.remove_global::<State>(output.global_id.unwrap());
|
||||
self.display.flush_clients().unwrap();
|
||||
}
|
||||
|
||||
pub fn enable_xdg_output_manager(&mut self) {
|
||||
self.dh
|
||||
.create_global::<State, ZxdgOutputManagerV1, _>(3, ());
|
||||
|
|
@ -1126,13 +1140,19 @@ impl GlobalDispatch<WlOutput, (i32, i32)> for State {
|
|||
"fake monitor".to_string(),
|
||||
wl_output::Transform::Normal,
|
||||
);
|
||||
let name = format!("WL-{}", state.outputs.len() + 1);
|
||||
state.output_counter += 1;
|
||||
let name = format!("WL-{}", state.output_counter);
|
||||
output.name(name.clone());
|
||||
output.mode(wl_output::Mode::Current, 1000, 1000, 0);
|
||||
output.done();
|
||||
state
|
||||
.outputs
|
||||
.insert(output.clone(), Output { name, xdg: None });
|
||||
state.outputs.insert(
|
||||
output.clone(),
|
||||
Output {
|
||||
name,
|
||||
xdg: None,
|
||||
global_id: None,
|
||||
},
|
||||
);
|
||||
state.last_output = Some(output);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue