Changeset View
Changeset View
Standalone View
Standalone View
idle_inhibition.cpp
Show All 35 Lines | 34 | IdleInhibition::IdleInhibition(IdleInterface *idle) | |||
---|---|---|---|---|---|
36 | , m_idle(idle) | 36 | , m_idle(idle) | ||
37 | { | 37 | { | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | IdleInhibition::~IdleInhibition() = default; | 40 | IdleInhibition::~IdleInhibition() = default; | ||
41 | 41 | | |||
42 | void IdleInhibition::registerShellClient(ShellClient *client) | 42 | void IdleInhibition::registerShellClient(ShellClient *client) | ||
43 | { | 43 | { | ||
44 | auto surface = client->surface(); | 44 | auto inhibitsIdleChanged = [this, client] { | ||
45 | m_connections.insert(client, connect(surface, &SurfaceInterface::inhibitsIdleChanged, this, | | |||
46 | [this, client] { | | |||
47 | // TODO: only inhibit if the ShellClient is visible | 45 | // TODO: only inhibit if the ShellClient is visible | ||
davidedmundson: You're right on where the problem is, good work analysing.
But this TODO is still valid. From… | |||||
zzag: I probably misunderstood this TODO comment. | |||||
48 | if (client->surface()->inhibitsIdle()) { | 46 | if (client->surface()->inhibitsIdle()) { | ||
49 | inhibit(client); | 47 | inhibit(client); | ||
50 | } else { | 48 | } else { | ||
51 | uninhibit(client); | 49 | uninhibit(client); | ||
52 | } | 50 | } | ||
53 | } | 51 | }; | ||
54 | )); | 52 | m_connections[client] = connect(client->surface(), &SurfaceInterface::inhibitsIdleChanged, this, inhibitsIdleChanged); | ||
55 | connect(client, &ShellClient::windowClosed, this, | 53 | connect(client, &ShellClient::windowClosed, this, | ||
56 | [this, client] { | 54 | [this, client] { | ||
57 | uninhibit(client); | 55 | uninhibit(client); | ||
58 | auto it = m_connections.find(client); | 56 | auto it = m_connections.find(client); | ||
59 | if (it != m_connections.end()) { | 57 | if (it != m_connections.end()) { | ||
60 | disconnect(it.value()); | 58 | disconnect(it.value()); | ||
61 | m_connections.erase(it); | 59 | m_connections.erase(it); | ||
62 | } | 60 | } | ||
63 | } | 61 | } | ||
64 | ); | 62 | ); | ||
63 | | ||||
64 | inhibitsIdleChanged(); | ||||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | void IdleInhibition::inhibit(ShellClient *client) | 67 | void IdleInhibition::inhibit(ShellClient *client) | ||
68 | { | 68 | { | ||
69 | if (isInhibited(client)) { | 69 | if (isInhibited(client)) { | ||
70 | // already inhibited | 70 | // already inhibited | ||
71 | return; | 71 | return; | ||
72 | } | 72 | } | ||
Show All 17 Lines |
You're right on where the problem is, good work analysing.
But this TODO is still valid. From the spec we should only apply the inhibition when the surface is visible.
This is an OK short term fix (if you leave this one line), but when we do it properly we'll have to move it all around.