Skip to content

Add powered to ConnectorSavedState#366

Merged
Ottatop merged 1 commit intopinnacle-comp:mainfrom
anriha:save_powered_enabled
Sep 30, 2025
Merged

Add powered to ConnectorSavedState#366
Ottatop merged 1 commit intopinnacle-comp:mainfrom
anriha:save_powered_enabled

Conversation

@anriha
Copy link
Contributor

@anriha anriha commented Sep 28, 2025

This PR introduces the powered field to ConnectorSavedState to correctly handle monitors that automatically try to reconnect after being powered off.

When an output is deactivated, its last known powered state is now saved. Upon reconnection, this saved state is reapplied, ensuring that an output intended to be off remains off. This resolves power-looping issues as discussed in #362.

Additionally, this change removes the creation of ConnectorSavedState from the set_loc API call. As far as I can tell there is no situation where that would be used, as it would always be overwritten by either set_enable or remove_output.

Comment on lines 60 to 77
if let Some(saved_state) = state
.pinnacle
.config
.connector_saved_states
.get_mut(&output_name)
{
saved_state.loc.x = x;
saved_state.loc.y = y;
} else {
state.pinnacle.config.connector_saved_states.insert(
output_name.clone(),
ConnectorSavedState {
loc: (x, y).into(),
..Default::default()
},
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is dead code ?

As I understand it, the iftrue branch allows you to set the location of a previously connected output, and the else branch allows you to set the location of an output before it's plugged.
This can be useful on e.g. a laptop if you already know which port correspond to which name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant is, that it is not dead code as in it never gets called. It is dead code in a way that it doesn't change anything. As far as I can tell there are only two ways an output can be disabled and that is via the set_enabled(false) and remove_output. Both of these completely overwrite what is stored in connector_saved_states. So no matter what was there it will be overwritten when you actually remove the output.

Copy link
Contributor

@Ph4ntomas Ph4ntomas Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_output_enabled is called from the OutputManagementProtocol handlers, and remove_output is called from udev backend (src/backend/udev.rs:1106).

At least remove_output checks that the output object is defined before calling remove_output, meaning the saved state is not overriden.

Beside that, this state is also used when an output is connected (or connected again). Meaning, even if remove_output or set_output_enabled did overwrite the saved state, set_loc on a disconnected output would still allow to set the output location ahead of a future re-connection, so I'm still not convinced this is dead code (in the sense of its side effect will always be overwritten and can never be useful)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one case that I did miss. With this, you can use set_loc for output that has never been seen before or is currently disconnected. As there is no check that the output in set_loc is actually valid. You still probably couldn't actually use it like that as it is only called on OutputHandle via API, so you would need to have valid output, but I guess in that case it still makes sense to keep it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it back and changed powered to Option<bool> so now it will be None if you use set_loc for non-existent output.

@anriha anriha force-pushed the save_powered_enabled branch from c5427ae to 596d6ce Compare September 28, 2025 15:02
Copy link
Collaborator

@Ottatop Ottatop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Ottatop Ottatop force-pushed the save_powered_enabled branch from 596d6ce to 7096f25 Compare September 30, 2025 01:32
@Ottatop Ottatop merged commit 4e7aad0 into pinnacle-comp:main Sep 30, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants