forge
Explore
Log in

Don't you dare go Hollow

foreign_toplevel: Use OutputHandler to send output_enter on demand

Browse files at this commit

d3f4583c903dc36d93924ce3d2ec8c9ffc57dae5Ivan MolodetskikhParent: fefb1cc
Cargo.lockmodified+2 -2
@@ -2716,7 +2716,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
2716 [[package]]2716 [[package]]
2717 name = "smithay"2717 name = "smithay"
2718 version = "0.3.0"2718 version = "0.3.0"
2719-source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466"2719+source = "git+https://github.com/Smithay/smithay.git#125b7972c4b1f0498bce564b25fe72c1cebb0a16"
2720 dependencies = [2720 dependencies = [
2721 "appendlist",2721 "appendlist",
2722 "bitflags 2.4.2",2722 "bitflags 2.4.2",
@@ -2788,7 +2788,7 @@ dependencies = [
2788 [[package]]2788 [[package]]
2789 name = "smithay-drm-extras"2789 name = "smithay-drm-extras"
2790 version = "0.1.0"2790 version = "0.1.0"
2791-source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466"2791+source = "git+https://github.com/Smithay/smithay.git#125b7972c4b1f0498bce564b25fe72c1cebb0a16"
2792 dependencies = [2792 dependencies = [
2793 "drm",2793 "drm",
2794 "edid-rs",2794 "edid-rs",
src/handlers/mod.rsmodified+9 -1
@@ -23,6 +23,7 @@ use smithay::utils::{Logical, Rectangle, Size};
23 use smithay::wayland::compositor::{send_surface_state, with_states};23 use smithay::wayland::compositor::{send_surface_state, with_states};
24 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier};24 use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier};
25 use smithay::wayland::input_method::{InputMethodHandler, PopupSurface};25 use smithay::wayland::input_method::{InputMethodHandler, PopupSurface};
26+use smithay::wayland::output::OutputHandler;
26 use smithay::wayland::pointer_constraints::PointerConstraintsHandler;27 use smithay::wayland::pointer_constraints::PointerConstraintsHandler;
27 use smithay::wayland::security_context::{28 use smithay::wayland::security_context::{
28 SecurityContext, SecurityContextHandler, SecurityContextListenerSource,29 SecurityContext, SecurityContextHandler, SecurityContextListenerSource,
@@ -49,7 +50,9 @@ use smithay::{
49 50
50 use crate::delegate_foreign_toplevel;51 use crate::delegate_foreign_toplevel;
51 use crate::niri::{ClientState, State};52 use crate::niri::{ClientState, State};
52-use crate::protocols::foreign_toplevel::{ForeignToplevelHandler, ForeignToplevelManagerState};53+use crate::protocols::foreign_toplevel::{
54+ self, ForeignToplevelHandler, ForeignToplevelManagerState,
55+};
53 use crate::utils::output_size;56 use crate::utils::output_size;
54 57
55 impl SeatHandler for State {58 impl SeatHandler for State {
@@ -206,6 +209,11 @@ impl DataControlHandler for State {
206 209
207 delegate_data_control!(State);210 delegate_data_control!(State);
208 211
212+impl OutputHandler for State {
213+ fn output_bound(&mut self, output: Output, wl_output: WlOutput) {
214+ foreign_toplevel::on_output_bound(self, &output, &wl_output);
215+ }
216+}
209 delegate_output!(State);217 delegate_output!(State);
210 218
211 delegate_presentation!(State);219 delegate_presentation!(State);
src/protocols/foreign_toplevel.rsmodified+27 -20
@@ -131,6 +131,31 @@ pub fn refresh(state: &mut State) {
131 }131 }
132 }132 }
133 133
134+pub fn on_output_bound(state: &mut State, output: &Output, wl_output: &WlOutput) {
135+ let _span = tracy_client::span!("foreign_toplevel::on_output_bound");
136+
137+ let Some(client) = wl_output.client() else {
138+ return;
139+ };
140+
141+ let protocol_state = &mut state.niri.foreign_toplevel_state;
142+ for data in protocol_state.toplevels.values_mut() {
143+ if data.output.as_ref() != Some(output) {
144+ continue;
145+ }
146+
147+ for (instance, outputs) in &mut data.instances {
148+ if instance.client().as_ref() != Some(&client) {
149+ continue;
150+ }
151+
152+ instance.output_enter(wl_output);
153+ instance.done();
154+ outputs.push(wl_output.clone());
155+ }
156+ }
157+}
158+
134 fn refresh_toplevel(159 fn refresh_toplevel(
135 protocol_state: &mut ForeignToplevelManagerState,160 protocol_state: &mut ForeignToplevelManagerState,
136 wl_surface: &WlSurface,161 wl_surface: &WlSurface,
@@ -204,31 +229,13 @@ fn refresh_toplevel(
204 }229 }
205 }230 }
206 }231 }
232+ instance.done();
207 }233 }
208 }234 }
209 235
210- for (instance, outputs) in &mut data.instances {236+ for outputs in data.instances.values_mut() {
211 // Clean up dead wl_outputs.237 // Clean up dead wl_outputs.
212 outputs.retain(|x| x.is_alive());238 outputs.retain(|x| x.is_alive());
213-
214- let mut send_done = something_changed;
215-
216- // If the client bound any more wl_outputs, send enter for them.
217- if let Some(output) = &data.output {
218- if let Some(client) = instance.client() {
219- for wl_output in output.client_outputs(&client) {
220- if !outputs.iter().any(|x| x == &wl_output) {
221- instance.output_enter(&wl_output);
222- outputs.push(wl_output);
223- send_done = true;
224- }
225- }
226- }
227- }
228-
229- if send_done {
230- instance.done();
231- }
232 }239 }
233 }240 }
234 Entry::Vacant(entry) => {241 Entry::Vacant(entry) => {