forge
Explore
Log in

Don't you dare go Hollow

mapped: Add needs_configure flag

Browse files at this commit

ddcac86d1d568463ef828bf370d8989bbf12c9fdIvan MolodetskikhParent: 734e3a6
Allows to de-duplicate configures from requests that require one.
src/handlers/xdg_shell.rsmodified+24 -15
@@ -433,8 +433,12 @@ impl XdgShellHandler for State {
433 if let Some((mapped, current_output)) = self433 if let Some((mapped, current_output)) = self
434 .niri434 .niri
435 .layout435 .layout
436- .find_window_and_output(toplevel.wl_surface())436+ .find_window_and_output_mut(toplevel.wl_surface())
437 {437 {
438+ // A configure is required in response to this event regardless if there are pending
439+ // changes.
440+ mapped.set_needs_configure();
441+
438 let window = mapped.window.clone();442 let window = mapped.window.clone();
439 443
440 if let Some(requested_output) = requested_output {444 if let Some(requested_output) = requested_output {
@@ -446,10 +450,6 @@ impl XdgShellHandler for State {
446 }450 }
447 451
448 self.niri.layout.set_fullscreen(&window, true);452 self.niri.layout.set_fullscreen(&window, true);
449-
450- // A configure is required in response to this event regardless if there are pending
451- // changes.
452- toplevel.send_configure();
453 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {453 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {
454 match &mut unmapped.state {454 match &mut unmapped.state {
455 InitialConfigureState::NotConfigured { wants_fullscreen } => {455 InitialConfigureState::NotConfigured { wants_fullscreen } => {
@@ -513,17 +513,14 @@ impl XdgShellHandler for State {
513 if let Some((mapped, _)) = self513 if let Some((mapped, _)) = self
514 .niri514 .niri
515 .layout515 .layout
516- .find_window_and_output(toplevel.wl_surface())516+ .find_window_and_output_mut(toplevel.wl_surface())
517 {517 {
518- let window = mapped.window.clone();
519- self.niri.layout.set_fullscreen(&window, false);
520-
521 // A configure is required in response to this event regardless if there are pending518 // A configure is required in response to this event regardless if there are pending
522 // changes.519 // changes.
523- //520+ mapped.set_needs_configure();
524- // FIXME: when unfullscreening to floating, this will send an extra configure with521+
525- // scrolling layout bounds. We should probably avoid it.522+ let window = mapped.window.clone();
526- toplevel.send_configure();523+ self.niri.layout.set_fullscreen(&window, false);
527 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {524 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {
528 match &mut unmapped.state {525 match &mut unmapped.state {
529 InitialConfigureState::NotConfigured { wants_fullscreen } => {526 InitialConfigureState::NotConfigured { wants_fullscreen } => {
@@ -744,7 +741,13 @@ impl XdgDecorationHandler for State {
744 // A configure is required in response to this event. However, if an initial configure741 // A configure is required in response to this event. However, if an initial configure
745 // wasn't sent, then we will send this as part of the initial configure later.742 // wasn't sent, then we will send this as part of the initial configure later.
746 if toplevel.is_initial_configure_sent() {743 if toplevel.is_initial_configure_sent() {
747- toplevel.send_configure();744+ // If this is a mapped window, flag it as needs configure to avoid duplicate configures.
745+ let surface = toplevel.wl_surface();
746+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(surface) {
747+ mapped.set_needs_configure();
748+ } else {
749+ toplevel.send_configure();
750+ }
748 }751 }
749 }752 }
750 753
@@ -757,7 +760,13 @@ impl XdgDecorationHandler for State {
757 // A configure is required in response to this event. However, if an initial configure760 // A configure is required in response to this event. However, if an initial configure
758 // wasn't sent, then we will send this as part of the initial configure later.761 // wasn't sent, then we will send this as part of the initial configure later.
759 if toplevel.is_initial_configure_sent() {762 if toplevel.is_initial_configure_sent() {
760- toplevel.send_configure();763+ // If this is a mapped window, flag it as needs configure to avoid duplicate configures.
764+ let surface = toplevel.wl_surface();
765+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(surface) {
766+ mapped.set_needs_configure();
767+ } else {
768+ toplevel.send_configure();
769+ }
761 }770 }
762 }771 }
763 }772 }
src/tests/floating.rsmodified+27 -0
@@ -854,3 +854,30 @@ window-rule {
854 @"size: 300 × 100, bounds: 1920 × 1080, states: [Activated]"854 @"size: 300 × 100, bounds: 1920 × 1080, states: [Activated]"
855 );855 );
856 }856 }
857+
858+#[test]
859+fn unfullscreen_to_floating_doesnt_send_extra_configure() {
860+ let (mut f, id, surface) = set_up();
861+
862+ // Make it floating.
863+ f.niri().layout.toggle_window_floating(None);
864+ f.roundtrip(id);
865+
866+ // Fullscreen.
867+ let window = f.client(id).window(&surface);
868+ window.set_fullscreen(None);
869+ f.double_roundtrip(id);
870+
871+ let _ = f.client(id).window(&surface).recent_configures();
872+
873+ // Unfullscreen via the window request which requires a configure response.
874+ let window = f.client(id).window(&surface);
875+ window.unset_fullscreen();
876+ f.double_roundtrip(id);
877+
878+ // This should configure only once and not twice.
879+ assert_snapshot!(
880+ f.client(id).window(&surface).format_recent_configures(),
881+ @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]"
882+ );
883+}
src/window/mapped.rsmodified+34 -15
@@ -60,6 +60,11 @@ pub struct Mapped {
60 /// immediately, rather than setting this flag.60 /// immediately, rather than setting this flag.
61 need_to_recompute_rules: bool,61 need_to_recompute_rules: bool,
62 62
63+ /// Whether this window needs a configure this loop cycle.
64+ ///
65+ /// Certain Wayland requests require a configure in response, like un/fullscreen.
66+ needs_configure: bool,
67+
63 /// Whether this window has the keyboard focus.68 /// Whether this window has the keyboard focus.
64 is_focused: bool,69 is_focused: bool,
65 70
@@ -172,6 +177,7 @@ impl Mapped {
172 pre_commit_hook: hook,177 pre_commit_hook: hook,
173 rules,178 rules,
174 need_to_recompute_rules: false,179 need_to_recompute_rules: false,
180+ needs_configure: false,
175 is_focused: false,181 is_focused: false,
176 is_active_in_column: true,182 is_active_in_column: true,
177 is_floating: false,183 is_floating: false,
@@ -223,6 +229,10 @@ impl Mapped {
223 self.recompute_window_rules(rules, is_at_startup)229 self.recompute_window_rules(rules, is_at_startup)
224 }230 }
225 231
232+ pub fn set_needs_configure(&mut self) {
233+ self.needs_configure = true;
234+ }
235+
226 pub fn id(&self) -> MappedId {236 pub fn id(&self) -> MappedId {
227 self.id237 self.id
228 }238 }
@@ -733,6 +743,11 @@ impl LayoutElement for Mapped {
733 let _span =743 let _span =
734 trace_span!("configure_intent", surface = ?self.toplevel().wl_surface().id()).entered();744 trace_span!("configure_intent", surface = ?self.toplevel().wl_surface().id()).entered();
735 745
746+ if self.needs_configure {
747+ trace!("the window needs_configure");
748+ return ConfigureIntent::ShouldSend;
749+ }
750+
736 with_toplevel_role(self.toplevel(), |attributes| {751 with_toplevel_role(self.toplevel(), |attributes| {
737 if let Some(server_pending) = &attributes.server_pending {752 if let Some(server_pending) = &attributes.server_pending {
738 let current_server = attributes.current_server_state();753 let current_server = attributes.current_server_state();
@@ -783,24 +798,26 @@ impl LayoutElement for Mapped {
783 let _span =798 let _span =
784 trace_span!("send_pending_configure", surface = ?toplevel.wl_surface().id()).entered();799 trace_span!("send_pending_configure", surface = ?toplevel.wl_surface().id()).entered();
785 800
786- // Check for pending changes manually to account for RequestSizeOnce::UseWindowSize.801+ // If the window needs a configure, send it regardless.
787- let has_pending_changes = with_toplevel_role(self.toplevel(), |role| {802+ let has_pending_changes = self.needs_configure
788- if role.server_pending.is_none() {803+ || with_toplevel_role(self.toplevel(), |role| {
789- return false;804+ // Check for pending changes manually to account for RequestSizeOnce::UseWindowSize.
790- }805+ if role.server_pending.is_none() {
806+ return false;
807+ }
791 808
792- let current_server_size = role.current_server_state().size;809+ let current_server_size = role.current_server_state().size;
793- let server_pending = role.server_pending.as_mut().unwrap();810+ let server_pending = role.server_pending.as_mut().unwrap();
794 811
795- // With UseWindowSize, we do not consider size-only changes, because we will812+ // With UseWindowSize, we do not consider size-only changes, because we will
796- // request the current window size and do not expect it to actually change.813+ // request the current window size and do not expect it to actually change.
797- if let Some(RequestSizeOnce::UseWindowSize) = self.request_size_once {814+ if let Some(RequestSizeOnce::UseWindowSize) = self.request_size_once {
798- server_pending.size = current_server_size;815+ server_pending.size = current_server_size;
799- }816+ }
800 817
801- let server_pending = role.server_pending.as_ref().unwrap();818+ let server_pending = role.server_pending.as_ref().unwrap();
802- server_pending != role.current_server_state()819+ server_pending != role.current_server_state()
803- });820+ });
804 821
805 if has_pending_changes {822 if has_pending_changes {
806 // If needed, replace the pending size with the current window size.823 // If needed, replace the pending size with the current window size.
@@ -814,6 +831,8 @@ impl LayoutElement for Mapped {
814 let serial = toplevel.send_configure();831 let serial = toplevel.send_configure();
815 trace!(?serial, "sending configure");832 trace!(?serial, "sending configure");
816 833
834+ self.needs_configure = false;
835+
817 if self.animate_next_configure {836 if self.animate_next_configure {
818 self.animate_serials.push(serial);837 self.animate_serials.push(serial);
819 }838 }