Smithay / calloop

A callback-based Event Loop
MIT License
176 stars 35 forks source link

Add opt-in handlers for before sleeping and before handling events #144

Closed DJMcNab closed 1 year ago

DJMcNab commented 1 year ago

Solves #127. Designed to work with https://github.com/Smithay/wayland-rs/pull/650 and to be used to fix #glazier > Freeze with Wayland egl

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 75.60% and project coverage change: -1.68% :warning:

Comparison is base (d468cc9) 88.79% compared to head (33aed4a) 87.11%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #144 +/- ## ========================================== - Coverage 88.79% 87.11% -1.68% ========================================== Files 14 14 Lines 1669 1739 +70 ========================================== + Hits 1482 1515 +33 - Misses 187 224 +37 ``` | [Flag](https://app.codecov.io/gh/Smithay/calloop/pull/144/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay) | Coverage Δ | | |---|---|---| | [macos-latest](https://app.codecov.io/gh/Smithay/calloop/pull/144/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay) | `86.61% <75.60%> (-1.85%)` | :arrow_down: | | [ubuntu-latest](https://app.codecov.io/gh/Smithay/calloop/pull/144/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay) | `86.64% <75.60%> (-1.73%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files Changed](https://app.codecov.io/gh/Smithay/calloop/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay) | Coverage Δ | | |---|---|---| | [src/io.rs](https://app.codecov.io/gh/Smithay/calloop/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL2lvLnJz) | `73.51% <0.00%> (-9.05%)` | :arrow_down: | | [src/loop\_logic.rs](https://app.codecov.io/gh/Smithay/calloop/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL2xvb3BfbG9naWMucnM=) | `86.90% <80.43%> (-3.56%)` | :arrow_down: | | [src/sources/mod.rs](https://app.codecov.io/gh/Smithay/calloop/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3NvdXJjZXMvbW9kLnJz) | `95.18% <97.91%> (-0.52%)` | :arrow_down: | | [src/sys.rs](https://app.codecov.io/gh/Smithay/calloop/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3N5cy5ycw==) | `98.43% <100.00%> (+0.02%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

elinorbgr commented 1 year ago

Also, it looks like the signals test is failing? Is it because of the nix update?

DJMcNab commented 1 year ago

So there are three changes you're asking for there: 1) To make AdditionalLifecycleEventsSet not have the inner RefCell. The current design was intended to avoid doing the borrow_mut operations in the cases where they weren't needed, but that is only a small difference, as these shouldn't be on the hot path. This transformation hardly changes the code length, so I'll defer to @elinorbgr on this 1) To make the vector inside AdditionalLifecycleEventsSet not type-safe. There is definitely a slight verbosity cost, but I believe it's generally better to be more type safe than less type safe. Again, I'll defer to @elinorbgr 1) To use the key which is already present in TokenFactory, thus avoiding AdditionalLifecycleEventsRegister. I had avoided doing this because the key field on TokenFactory isn't public. (Edit: I had made it public in a prior commit, which I never used) I think there are two aspects to this:

elinorbgr commented 1 year ago

Just to make sure I didn't miss anything, point 1) is just about having the RefCell inside or outside of the AdditionalLifecycleEventsSet right? Given how small the difference is in terms of running, I think I'd prefer to have it outside, as it'd be more coherent with the rest of the contents of LoopInner.

Regarding 2/3, I think I like the way it is currently on the PR, keeping the type-safety and using the token from he available tokenfactory is good imo, especially given this concerns crate-internals anyway.

elinorbgr commented 1 year ago

Also, AdditionalLifetimeEventsSet is still named using lifetime rather than lifecycle, I guess this one slipped through your attention? :sweat_smile:

elinorbgr commented 1 year ago

Alright, thanks a lot this is perfect! :+1: