Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: sway-mode module #671

Merged
merged 9 commits into from
Aug 5, 2024

Conversation

Rodrigodd
Copy link
Contributor

Add a new module, similar to the waybar "sway/module" module. It shows the current mode under sway. For that, it needs to communicate with the Sway IPC. In this PR, the module is called "sway-mode" because "sway/mode" didn't work in my YAML config file (it would probably work if I surrounded it with quotes, but I didn't test).

This PR has two commits: the first one implements the module using a new sway connection. The second one refactors the sway Client, under clients::compositor::sway, to allow dynamically registering events, instead of only handling Workspace update ones. This second commit avoid creating a new socket for each module that needs to communicate with the Sway IPC, not sure if that is a problem to begin with.

Copy link
Owner

@JakeStanger JakeStanger left a comment

Choose a reason for hiding this comment

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

Hey, thanks for this. It looks very good, just a few nits.

The build is failing at the moment due to a separate issue that's fixed on master - rebasing should resolve that.

Are you also able to provide some evidence of this working please? I can't get Sway to run at the moment :( A couple of screenshots or a quick vid is fine.

Cargo.toml Show resolved Hide resolved
docs/modules/Sway-mode.md Show resolved Hide resolved
docs/modules/Sway-mode.md Outdated Show resolved Hide resolved
src/clients/compositor/sway.rs Outdated Show resolved Hide resolved
src/clients/compositor/sway.rs Outdated Show resolved Hide resolved
src/clients/compositor/sway.rs Outdated Show resolved Hide resolved
src/modules/sway/mode.rs Outdated Show resolved Hide resolved
Comment on lines 48 to 50
let Event::Mode(mode) = event else {
unreachable!()
};
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not a fan of requiring this when the type is (sorta) already specified in the call. I can't see how to avoid it nicely though. Any ideas?

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 created a SwayIpcEvent trait with a associated const EVENT_TYPE: EventType and a fn from_event(&Event) -> &Self method, implemented to all event types, and used that to fix this issue.

Now `sway::Client` is store in `ironbar.clients`, and allow dynamically
registering event listeners, instead of hardcoding events for Workspace
updates.

Remove the use of `swayipc::Connection` from `sway-mode` module, and
replace it with the new event listener system.
Avoiding unwrapping the event enum in the caller code.
The module `compositor` is gated behind the `workspaces` feature, but
`sway::Client` is no longer used only by the `workspaces` module.
@Rodrigodd
Copy link
Contributor Author

I believe I have addressed all points. Here is a video of the sway mode working:

output.mp4

Copy link
Owner

@JakeStanger JakeStanger left a comment

Choose a reason for hiding this comment

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

Code all lgtm, cheers for making those changes & cheers for the vid.

One last thing before I approve - could you update docs/sidebar.md to add an entry for the docs page pls

@Rodrigodd
Copy link
Contributor Author

@JakeStanger done.

src/clients/sway.rs Outdated Show resolved Hide resolved
@Rodrigodd
Copy link
Contributor Author

@JakeStanger all done. (just in case my last comment didn't trigger a notification)

@JakeStanger JakeStanger merged commit e307e15 into JakeStanger:master Aug 5, 2024
8 checks passed
@JakeStanger
Copy link
Owner

Cheers!

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.

2 participants