Save Compositor state in single variable
ClosedPublic

Authored by romangg on Jul 4 2019, 5:01 PM.

Details

Summary

Replace the several internal state booleans of Compositor with a single
enum to register the current state of the compositor. We register four
states of starting, started, stopping and stopped.

The goal is to replace the several different conditionals when starting
and stopping the compositor with a single well defined flow.

There are currently still some ugly conditionals and some replaced ones
might need some more work.

Test Plan

Manually in X and Wayland. Relevant auto tests pass.

Diff Detail

Repository
R108 KWin
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
romangg created this revision.Jul 4 2019, 5:01 PM
Restricted Application added a project: KWin. · View Herald TranscriptJul 4 2019, 5:01 PM
Restricted Application added a subscriber: kwin. · View Herald Transcript
romangg requested review of this revision.Jul 4 2019, 5:01 PM
zzag added a subscriber: zzag.Jul 4 2019, 5:26 PM
zzag added inline comments.
composite.cpp
174

Starting compositor while it's being turned down will lead to a catastrophe. Thus, it can be simplified to m_state != State::Off.

435–452

Hmm, this method is hard to read. I suggest to use a switch statement.

zzag added inline comments.Jul 4 2019, 5:31 PM
composite.cpp
174

s/Thus, it/Thus, the condition/

romangg added inline comments.Jul 4 2019, 5:39 PM
composite.cpp
174

I'm actually not sure on that one. All the starting and stopping is done in sequence. So it might be possible to begin starting again while the stopping has not fully been finished.

This could happen in theory when compositing is quickly toggled on and off by a client.

zzag added inline comments.Jul 4 2019, 5:48 PM
composite.cpp
174

while the stopping has not fully been finished.

finish() method doesn't have any asynchronous parts, so consider it as an "atomic operation."

romangg added inline comments.Jul 4 2019, 5:52 PM
composite.cpp
174

True. But then the m_finishing variable was pretty useless. Because of that I assumed there was some funky callback stuff going on in the calls being done to the clients in between.

romangg added inline comments.Jul 4 2019, 5:54 PM
composite.cpp
435–452

Can you give a code example how you think it should look?

zzag added inline comments.Jul 4 2019, 6:02 PM
composite.cpp
174

No, we still need m_finished to delay deletion of support properties, don't we?

435–452

Something like this

switch (m_state) {
case State::On:
    // Comment.
    break;
case State::Off:
    if (m_selectionOwner) {
        qCDebug(KWIN_CORE) << "Releasing compositor selection";
        m_selectionOwner->setOwning(false);
        m_selectionOwner->release();
    }
    break;
case State::Starting:
case State::Sopping:
    // Comment.
    m_releaseSelectionTimer.start();
    break;
}
romangg added inline comments.Jul 4 2019, 6:16 PM
composite.cpp
174

True. Having a member variable just for that looks like bad design to me in the first place but alright. What I would like to get rid of also is this isTerminating check in the beginning.

romangg updated this revision to Diff 61168.Jul 4 2019, 6:30 PM

Comments.

romangg marked 10 inline comments as done.Jul 4 2019, 6:30 PM
zzag added inline comments.Jul 4 2019, 6:34 PM
composite.cpp
321–323

I have one remaining question. Why did you drop this if statement?

Relevant commit: 50ef02fa1b30c2c22d3cabc4f620e1654f9a5eae.

romangg added inline comments.Jul 4 2019, 6:45 PM
composite.cpp
321–323

Good question. startupWithWorkspace is either called directly from start() (always in X case) or by signal (in Wayland case on startup). That should in both cases happen only once. I.e. we can split the signal out to future Wayland Compositor child class and disconnect the signal after it was received once.

zzag added inline comments.Jul 4 2019, 6:50 PM
composite.cpp
321–323

I'm more interested in whether m_state can be State::Off by this time.

romangg added inline comments.Jul 4 2019, 7:55 PM
composite.cpp
321–323

I would say in all relevant cases no. On X we always call from start() directly. On Wayland it should be only called through the signal once in the beginning and if at the same time it gets stopped we have likely some fatal problem anyway. We could investigate this more in the future but I feel it's not worth the time

zzag accepted this revision.Jul 4 2019, 7:59 PM
This revision is now accepted and ready to land.Jul 4 2019, 7:59 PM
This revision was automatically updated to reflect the committed changes.