Skip to content

Conversation

raffael0
Copy link
Contributor

@raffael0 raffael0 commented Feb 16, 2022

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

This PR fixes the long-standing issue of only having 3 positioning options for the system tray. It does this by adding a new module which acts as placeholder. The actual tray window is then placed onto that tray module. Resizing of the tray and repositioning of the module is handled via signals.

These changes should also make it easier to completely break the tray handling out of the main bar.cpp into the new tray module.

Related Issues & Documents

Fixes: #1526
Fixes: #314

Documentation (check all applicable)

  • This PR requires changes to the Wiki documentation (describe the changes)
    Since this PR adds a complete new option for tray positioning this has to be reflected in the wiki
  • This PR requires changes to the documentation inside the git repo (please add them to the PR).
  • Does not require documentation changes

TODO / Issues

  • define how the tray positioning will be handled in the config. Will tray-position be deprecated?
  • figure out how to get the position where a tag will be placed in dispatch.cpp. The current approach only works on the left and in the center (current implementation)

I'd love some input on these issues

@raffael0 raffael0 changed the title Working/variable tray Tray position like a module Feb 16, 2022
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.

Wow that's really cool 😃

I appreciate you working on this. The tray has been a pain point for a long time and I have been dreading working on it forever.
This is surprisingly little code for what I thought would be a major undertaking.

Please let me know what your commitment for this PR is. Are you prepared to go through revisions until this is in a stable state? Or do you feel like this a "this is my code, take it or leave it" situation? Or something in between?
I don't want to push you until you lose interest, so it's good to know what kind of expectations you have here.
Of course feel free to at any point say that you no longer can/want to invest more time here.
We can just as well release this as an experimental, but mostly working, feature and improve it step by step.


While testing this, I found some issues, all of which happen using the following config:

[bar/example]
modules-left = text tray text

enable-ipc = true

tray-position = adaptive

width = 50%
offset-x = 50%

[module/text]
type = custom/text
content = A

[module/tray]
type = internal/tray
  • The tray_manager uses the position received from tray_pos_change as the absolute position for the tray window. However, the dispatcher only sends the x position relative to the bar window. This is an issue if you have two monitors and place the bar on the right one or when the bar has some offset-x.
  • The tray module does not receive the tray_width_change signal and thus never updates its width and doesn't produce a proper offset tag. This causes modules that are placed after the tray to appear immediately after the previous module (and the tray overlaps them)
    I'm pretty sure that's because the module is not attached to the signal handler and thus doesn't receive any signals.

I think these two are the most important points to get the module into a experimental state that we can release to users.

There are also some conceptual things and edge cases to consider:

  • If you set tray-position to anything but adaptive but still have a tray module, the tray module will display the tray, but the bar will still cut off parts of the bar in bar::parse. We should enforce that if tray-position = adaptive, there must be exactly one tray module. And if it is anything else, no tray module must exist. We could also ditch tray-position = adaptive and just check for the existence of a tray module.
  • If there is too much text on the bar, any excess text will just drop off the bar on the right. We have to decide (and properly handle) what happens when tray is shoved off the right side of the bar like that. My idea is that in that case the tray just stays at the right edge of the bar and never disappears. This can also easily be enforced by the tray_manager when it handles the tray_pos_change signal.
  • We also have to think about how we want to move all the tray configurations that are currently into the bar section into the tray module. But this doesn't have priority at all yet, we can easily tackle this once the tray is stable.

These points are not yet important if we just release the tray module as an experimental feature, but we will need to address them to get to a stable state.


define how the tray positioning will be handled in the config. Will tray-position be deprecated?

In order to not break existing configs, we need to still support tray-position. Depending on whether we merge this as an experimental feature or try to get a stable implementation in this PR, we can already tell people to switch and that all the tray settings in the bar section will be deprecated. But leave it as-is for now.

figure out how to get the position where a tag will be placed in dispatch.cpp. The current approach only works on the left and in the center

I think the solution here is to not immediately move the tray but only emit the tray position signal once the rendering is finished. Either the dispatch or the renderer need to keep track in which alignment and which relative position in that alignment the tray has to appear and at the end of the render cycle calculate the actual position.

@raffael0
Copy link
Contributor Author

Hi, thanks for your quick and detailed response!

Please let me know what your commitment for this PR is. Are you prepared to go through revisions until this is in a stable state? Or do you feel like this a "this is my code, take it or leave it" situation? Or something in between?

I'd ultimately like to see this become stable and I'm committed to continue working on it. Since I don't really understand some parts of the code works(modules, formatter etc.) I'll need some help in these areas and definitely appreciate any suggestions. The next few months will be quite busy for me so it may be that I'll need to take a break for a while but I'll definitely let you know before.

The tray_manager uses the position received from tray_pos_change as the absolute position for the tray window. However, the dispatcher only sends the x position relative to the bar window. This is an issue if you have two monitors and place the bar on the right one or when the bar has some offset-x

I also noticed this error and the tray positioning has been the most annoying issue I faced. Moving the tray position signal to the renderer sounds like a good idea. I never liked it in the dispatch.
Am I correct that you propose moving it into renderer::end?
Do I get the absolute and relative position like this?
In renderer:

 double absolute_x = m_rect.x + block_x(alignment);

in dispatch:

double current_relative_x = renderer.get_x(*m_ctxt);

For now I'll look into the problem with the tray_width_change signal and incorporate your suggestions.

@patrick96
Copy link
Member

I'd ultimately like to see this become stable and I'm committed to continue working on it. Since I don't really understand some parts of the code works(modules, formatter etc.) I'll need some help in these areas and definitely appreciate any suggestions.

Just let me know if anything is unclear. Our code documentation isn't that good and a lot of code (especially the base module code) has been here for a long time (even before I started working on polybar) and its behavior isn't always obvious for me either.

The next few months will be quite busy for me so it may be that I'll need to take a break for a while but I'll definitely let you know before.

That's completely fine :)
There is no rush to get this merged. I'd rather we take our time than do it sloppily.


The tray positioning is terrible. It's the main reason why I got stuck in my last big tray PR #1615.
The "proper" solution would be to make the tray window a child window of the bar window. Then we only have to position it relative to the parent and we also a avoid all the issues in #425.
However, that is probably quite a big change (bigger than what you did already), so I'm not sure if it's a good idea to try to force into this PR as well.
For now, let's keep the current system.

Unfortunately, neither of your proposed solutions work, both of them are still relative to the bar window. m_rect is relative to the bar window but only includes the inner area of the bar without the borders.

I think the following could work:
We store the tray position in the tag context (maybe as an std::pair<alignment, int>). The integer value is the x-position relative to the alignment. The dispatcher can easily find get that using renderer.get_x.

Once the dispatcher is finished, it calls into the renderer and the renderer can calculate the position relative to the inner area of the bar like this:

double absolute_x = block_x(ctxt.tray.first) + ctxt.tray.second;

It then sends this to the tray_manager and the tray manager is responsible for calculating the absolute position. The tray gets passed the bar_settings which are necessary to get the absolute position in setup. However, I think it makes more sense to pass it into the constructor and also store it as a private field (const bar_settings&).
Because then, the tray manager can easily compute the absolute position when it receives the tray_pos_change signal like this:

m_opts.orig_x = m_bar_opts.inner_area(true).x + evt.cast();

@raffael0
Copy link
Contributor Author

raffael0 commented Feb 19, 2022

  • Tray Width error: should be fixed
  • Tray positioning: Implemented you suggested fix. works with your example config
  • Testing: Since I added a new method to the renderer, I need to mock that in the MockRenderer however my added Mock doesn't compile.

EDIT: fixed tests

@raffael0 raffael0 requested a review from patrick96 February 19, 2022 17:28
@raffael0 raffael0 force-pushed the working/variable-tray branch from 79415fa to 19347eb Compare February 20, 2022 11:10
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.

This is coming along nicely :)

I have not had any problems when testing it out. The reviews are mainly cosmetic/architectural ones.

Please also run clang-format over all files that you have changed so that we have consistent formatting (Style Guide).
You can run clang-format for all changed files using this command:

git diff --pretty="" --name-only "$(git merge-base HEAD upstream/master)..HEAD" | xargs clang-format -i --style=file

Note that this will completely mess up non-C++ files (cmake etc.), so just don't commit those ;)

After this round of reviews this should be in a state where we can merge this as an experimental feature. After that, we should think about the three optional points in my first review.

What do you prefer? Should we merge this as an experimental feature or first bring it into a stable state in this PR?

@patrick96 patrick96 added this to the 3.7.0 milestone Feb 21, 2022
@patrick96
Copy link
Member

This may also fix #651, but I haven't tested it yet.

@raffael0
Copy link
Contributor Author

Hi,
just wanted to give an update on my progress. I'm on the break now I mentioned at the beginning so I currently don't have time to work on this. I'll probably return next month. Maybe I can squeeze in the latest requested changes in the coming weeks to release it as an experimental feature.

@patrick96
Copy link
Member

Thanks for letting me know :)

There is no need to rush here, take your time

@ghost
Copy link

ghost commented Mar 15, 2022

Hi Polygon Team, I'm new to the polygon/linux and github world. How i can "download" / "test" this tray-modul?
Any beta files or so?
Regards, Lukas

@patrick96
Copy link
Member

@Luekuu This is very much not ready to use for end users. If you really want to, you can clone @raffael0's fork and compile the working/variable-tray branch from source.

@raffael0 raffael0 force-pushed the working/variable-tray branch from 348e51d to 4e47bc0 Compare April 4, 2022 08:26
@raffael0 raffael0 requested a review from patrick96 April 4, 2022 08:26
@patrick96
Copy link
Member

patrick96 commented Apr 4, 2022

Will review in depth later.

Your latest commit messed up the formatting in a bunch of files.
Please also revert the formatting changes in the cmake files.

EDIT: See also our style guide: https://polybar.readthedocs.io/en/latest/dev/style-guide.html

@raffael0
Copy link
Contributor Author

raffael0 commented Apr 4, 2022

Sorry about that. I have no idea how that happened. Should be fixed now.

@raffael0 raffael0 requested a review from patrick96 April 4, 2022 18:34
@patrick96
Copy link
Member

Sorry about that. I have no idea how that happened. Should be fixed now.

Maybe your IDE auto-formatted the files.

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.

Alright, looks good now 😃

Things to do now to merge this as an experimental feature:

After merging, we need to take these steps to make this feature stable

  • Automatically hide the tray window when no tray position is set in the renderer
  • Consider removing tray-position = adaptive again and just activate the tray when a tray module exists. The existence of a tray module should override any value for tray-position
  • Fix the tray window being pushed off the bar. The tray window should always be fully within the bar window¨.
  • Also support applicable tray settings in the tray module (tray-maxsize, tray-background, tray-foreground, tray-padding, tray-scale, and maybe tray-offset-y)
  • Emit deprecation warnings for tray-position and all other tray settings in the bar section.$

These can be implemented step-by-step in separate PRs. I'll create an issue for them once we merge this.

@raffael0 raffael0 force-pushed the working/variable-tray branch from b5354ff to a2b4553 Compare April 11, 2022 20:42
@raffael0
Copy link
Contributor Author

Hi. these commits should address all your points:

  • Added changelog entry(I'm not sure about the wording here)
  • implemented the suggestions
  • removed the bar_settings
  • resolved the merge conflicts(I rebased my branch onto master. the tray new handling still works and the tests pass after rebasing)

@raffael0 raffael0 requested a review from patrick96 April 11, 2022 20:47
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.

Alright, last rounds of reviews :)

@codecov
Copy link

codecov bot commented Apr 13, 2022

Codecov Report

Merging #2595 (21f8de8) into master (973b1fa) will decrease coverage by 0.04%.
The diff coverage is 4.93%.

@@            Coverage Diff             @@
##           master    #2595      +/-   ##
==========================================
- Coverage   13.62%   13.58%   -0.05%     
==========================================
  Files         149      152       +3     
  Lines       11286    11339      +53     
==========================================
+ Hits         1538     1540       +2     
- Misses       9748     9799      +51     
Flag Coverage Δ
unittests 13.58% <4.93%> (-0.05%) ⬇️

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

Impacted Files Coverage Δ
include/components/renderer_interface.hpp 100.00% <ø> (ø)
include/events/signal.hpp 0.00% <ø> (ø)
include/modules/meta/factory.hpp 0.00% <0.00%> (ø)
include/modules/tray.hpp 0.00% <0.00%> (ø)
include/tags/types.hpp 100.00% <ø> (ø)
src/components/bar.cpp 0.00% <0.00%> (ø)
src/components/builder.cpp 70.95% <0.00%> (-0.80%) ⬇️
src/components/renderer.cpp 0.00% <0.00%> (ø)
src/modules/tray.cpp 0.00% <0.00%> (ø)
src/tags/context.cpp 89.74% <0.00%> (-6.15%) ⬇️
... and 4 more

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 973b1fa...21f8de8. Read the comment docs.

@raffael0 raffael0 marked this pull request as ready for review April 13, 2022 16:03
@raffael0
Copy link
Contributor Author

Is this ready to be merged or am I missing an open issue?

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.

Is this ready to be merged or am I missing an open issue?

Everything's good, I was just busy.

@patrick96 patrick96 merged commit 4961a7d into polybar:master Apr 15, 2022
@patrick96 patrick96 mentioned this pull request Apr 15, 2022
11 tasks
@patrick96
Copy link
Member

Awesome! Very happy to have this in polybar now 😃

Thanks a lot @raffael0 for all your work!

I opened #2689 to track the next steps. If you want to work on some of that, feel free ;)

I'll be off for a week, so I won't be able to review anything.

@raffael0
Copy link
Contributor Author

Great!
I'm also quite busy in coming weeks but I'll probably help out with the tasks still remaining

@Vlek
Copy link

Vlek commented May 23, 2022

@raffael0, hello! I am trying to use this. However, there does not appear to be any documentation for it.

I have tried adding it to my bar and using internal/tray, but my polybar output gives an error saying that it is an unknown module. I made sure I'm using the latest version, 3.6.3 which appears to be after when this was merged to the master branch. Am I using this incorrectly? Is it not fully available yet?

@raffael0
Copy link
Contributor Author

raffael0 commented May 23, 2022

Hi,
this feature is targeted to be released in version 3.7. It was however merged into master and you can use it from there(I think polybar-git in the AUR should be on master or you can build from source). We're still working on some issues to stabilize the module(See #2689). Until then the feature is still experimental and the interface(eg. tray-position=adaptive) will probably change a bit until it's released. More documentation(besides #2689) will be added before release.

This was referenced Nov 5, 2023
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 tray a module systray as a module
3 participants