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

Update separator functionality #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

grumpysurfer
Copy link

The systray library provides a way to manage buttons. They can be shown and hidden at runtime. However, this does not apply to menu separators, which cannot be easily hidden. This leads to a situation where you can hide all buttons, but the separators are still visible, which is not a good look.

The intention of this PR is to provide a way to manage separators by returning their ID and using additional methods to show and hide them.

Added AddSeparatorID() which returns the item id.
It can be used with the new ShowSeparator() and HideSeparator() methods to manipulate the separator behavior

Signed-off-by: GrumpySurfer <[email protected]>
Comment on lines 242 to 252
instance.menuLock.Lock()
defer instance.menuLock.Unlock()
menu, _ := findLayout(int32(parent))
for _, i := range menu.V2 {
item := i.Value().(*menuLayout)
if item.V0 == int32(id) {
item.V1["visible"] = dbus.MakeVariant(true)
refresh()
return
}
}
Copy link

Choose a reason for hiding this comment

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

This function is exactly the same as hideSeparator only with the argument to dbus.MakeVariant() differ. Could the code be reused?

func showSeparator(id uint32, parent uint32) {
instance.menuLock.Lock()
defer instance.menuLock.Unlock()
menu, _ := findLayout(int32(parent))
Copy link

Choose a reason for hiding this comment

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

Any reason for this to require menuLock to be acquired?

Copy link
Author

Choose a reason for hiding this comment

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

This lock is used to protect maps inside the menuLayout object. It is used basically every time the menuLayout is changed. Do you think we can remove it here?

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