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(ipc): allow receiving arbitrary text on IPC socket #2463

Merged
merged 4 commits into from Jul 11, 2021

Conversation

vincentbernat
Copy link
Contributor

@vincentbernat vincentbernat commented Jul 11, 2021

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Other: Replace this with a description of the type of this PR

Description

Instead of just allowing hook numbers to be executed, the user can
send arbitrary text and the IPC module will put it in the bar. The IPC
payload format is extended to accept an arbitrary string if the first
character after the module name is ':'.

polybar-msg hook test :'%{F#4444ff}hello%{F-}'

I did not make a new module as requested by @patrick96 as the modifications to the IPC module are minimal and the actions are reused as is. Tell me what you think.

Related Issues & Documents

Fix #2455

Documentation (check all applicable)

  • This PR requires changes to the Wiki documentation (describe the changes)
  • This PR requires changes to the documentation inside the git repo (please add them to the PR).
  • Does not require documentation changes

Instead of just allowing hook numbers to be executed, the user can
send arbitrary text and the IPC module will put it in the bar. The IPC
payload format is extended to accept an arbitrary string if the first
character after the module name is ':'.

    polybar-msg hook test :'%{F#4444ff}hello%{F-}'

Fix polybar#2455
Copy link
Member

@patrick96 patrick96 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 very much, these changes are indeed very minimal 😮

I think the polybar-msg hook command is becoming too limited for the ipc module. We have a very capable module action system that would be better suited. It allows us to have named actions per module with optional data.
For example here, we could add a send action whose data will be set as the module's content.

If your ipc module is named ipc, this could look like this:

polybar-msg -p ... action "#ipc.send.abc"

The big advantage of this is that this also works for click commands: click-left = #ipc.send.abc will deliver this to the correct module on the clicked bar.
I have added those changes locally, I will push them shortly.

src/modules/ipc.cpp Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 11, 2021

Codecov Report

Merging #2463 (943b894) into master (523e4d6) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2463      +/-   ##
==========================================
- Coverage   10.13%   10.13%   -0.01%     
==========================================
  Files         147      147              
  Lines       10178    10181       +3     
==========================================
  Hits         1032     1032              
- Misses       9146     9149       +3     
Flag Coverage Δ
unittests 10.13% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
include/modules/ipc.hpp 0.00% <ø> (ø)
src/modules/ipc.cpp 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 523e4d6...943b894. Read the comment docs.

src/modules/ipc.cpp Outdated Show resolved Hide resolved
@patrick96 patrick96 merged commit 5f34622 into polybar:master Jul 11, 2021
@vincentbernat
Copy link
Contributor Author

Just to show an example, here is a piece of code to display Network Manager state: https://github.com/vincentbernat/i3wm-configuration/blob/7df5011824cc55ffa9d3ac8b32bb680d63ac083d/bin/i3-companion#L454.

[module/network]
type = custom/ipc
hook-0 = cat $XDG_RUNTIME_DIR/i3/network.txt
initial = 1

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.

Make IPC module accept arbitrary text over the socket
2 participants