Skip to content

Conversation

parmort
Copy link
Contributor

@parmort parmort commented Dec 20, 2020

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

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Other

Description

Creates new IPC commands to toggle the visibility of a specific module. End goal (as expressed in #2108) is to stop processing hidden modules, although I will probably complete an initial implementation to just hide the modules.

$ polybar-msg [-p PID] cmd hide.mymodule # Hides module mymodule
$ polybar-msg [-p PID] cmd show.mymodule # Shows module mymodule
$ polybar-msg [-p PID] cmd toggle.mymodule # Toggles visibility of mymodule

Related Issues & Documents

Closes #2108

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

@parmort parmort changed the title Module Visibility [WIP] feat: Module Visibility Dec 20, 2020
@patrick96
Copy link
Member

Approach looks good. Having the visibility information inside the module should make it easier in the future to actually pause/unpause modules when they are invisible.

Btw. for all methods that you add to module_interface, you also need to add them to unsupported.hpp.

@codecov
Copy link

codecov bot commented Dec 23, 2020

Codecov Report

Merging #2320 (0d6ef0e) into master (b49f325) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2320      +/-   ##
=========================================
- Coverage    7.85%   7.83%   -0.03%     
=========================================
  Files         142     142              
  Lines       10275   10303      +28     
=========================================
  Hits          807     807              
- Misses       9468    9496      +28     
Flag Coverage Δ
unittests 7.83% <0.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
include/components/controller.hpp 0.00% <ø> (ø)
include/modules/meta/base.hpp 0.00% <ø> (ø)
include/modules/meta/base.inl 0.00% <0.00%> (ø)
src/components/controller.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 b49f325...0d6ef0e. Read the comment docs.

@parmort parmort marked this pull request as ready for review December 23, 2020 01:31
@parmort parmort changed the title [WIP] feat: Module Visibility feat: Module Visibility Dec 23, 2020
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.

Good job!

Now that I see your implementation, I think it would be cleaner from a user perspective to be able to change module visibility through an action instead of a command, because then users could easily change module visibility through click actions instead of having to go through polybar-msg (which also targets all bars).

But we are not going to do this here, because there is no way for all modules to share an action without adding it to every module separately. I have some ideas about action routing (see this comment) which could make this easier in the future.

But it's still a good idea to merge this.

Could you also add the name of the ipc commands to the changelog?

@parmort
Copy link
Contributor Author

parmort commented Dec 23, 2020

Would adding an additional config parameter to modules to determine default visibility be an idea? This would allow modules to be hidden by default.

[module/mymodule]
visible=true ; defaults true
; OR
hidden=false ; defaults false

This would be useful for, as an example, an email notification module which only appears when there are new/unread notifications.

But we are not going to do this here, because there is no way for all modules to share an action without adding it to every module separately. I have some ideas about action routing (see this comment) which could make this easier in the future.

This isn't the right place to have this discussion, but would overloads to the input function be an idea to fix this, similar to the signal system? Conservatively adding "universal" actions could allow the base module to define default functionality for certain actions, like hiding and showing modules.

@patrick96 patrick96 mentioned this pull request Dec 26, 2020
9 tasks
@patrick96
Copy link
Member

This isn't the right place to have this discussion, but would overloads to the input function be an idea to fix this, similar to the signal system?

We already overload the input function, so yeah this could work, modules would just have to start calling the super function in their input methods.
I have already implemented a proof of concept of my action router idea in #2336. This makes the action code inside modules much cleaner (because they no longer have to differentiate between the different actions themselves). It would also make implementing this a lot cleaner.

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.

Code looks solid. I just recently moved the config.cmake file into its own folder and that caused a merge conflict you need to resolve before we can merge this.

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.

I went ahead and rebased against master so we can merge this.

I think having a module setting for the visible state is a good idea. Do you want to implement this in a new PR?

@patrick96 patrick96 merged commit 8e46e54 into polybar:master Dec 27, 2020
@parmort
Copy link
Contributor Author

parmort commented Dec 27, 2020

Yeah, I'll get working on that.

@patrick96
Copy link
Member

Awesome! Thanks 😃

@patrick96
Copy link
Member

I have now more or less finished my action router idea (#2336) and adding universal actions like the visibility change actions seems quite easy. The only downside is that we can't use toggle as the action name for toggling the module visibility because that name is already used for the date module's click action. We would have to come up with a different name, maybe toggle_visible.

@parmort
Copy link
Contributor Author

parmort commented Dec 27, 2020

Or we could change the date action to toggle-format or something. That would break configs though, so some sort of notification would be necessary, like a pinned issue or a note at the top of the readme.

@patrick96
Copy link
Member

The action names are the closest thing we have to a public API and I am not very keen on breaking it.

I think people can live with toggle-visible 😉

@parmort parmort deleted the 2108-visibility branch January 2, 2021 21:35
patrick96 pushed a commit that referenced this pull request Jan 3, 2021
* Add option

* Undo my havoc on the example config

* Update CHANGELOG
@patrick96
Copy link
Member

People seem to like this feature ;)

https://www.reddit.com/r/Polybar/comments/kssoga/the_new_showhide_module_feature_is_amazing/

parmort added a commit to parmort/polybar that referenced this pull request May 9, 2021
IPC commands are no longer necessary now that the actions are
implemented. Changed some method permissions as well to reflect this.
patrick96 pushed a commit that referenced this pull request Jul 7, 2021
* Add toggle_visible action

* Add set_visible and set_invisible actions

* Rename toggle_visible method to match

`action_toggle_visible` -> `action_toggle_visibility`

Matches with `EVENT_TOGGLE_VISIBILITY`

* Update CHANGELOG

* Revert #2320 IPC commands

IPC commands are no longer necessary now that the actions are
implemented. Changed some method permissions as well to reflect this.

* Add logging and change action names

- `module_toggle`
- `module_show`
- `module_hide`

Delineate common actions to all modules with a `module_` prefix (for
future actions too)

* Update documentation
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.

Toggle visibility of a module
2 participants