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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,35 @@ func AddSeparator() {
addSeparator(currentID.Add(1), 0)
}

// AddSeparatorID adds a separator bar to the menu and returns its id
func AddSeparatorID() uint32 {
id := currentID.Add(1)
addSeparator(id, 0)
return id
}

// HideSeparator hides a separator bar by its id
func HideSeparator(id uint32) {
changeSeparatorVisibility(id, 0, false)
}

// ShowSeparator shows a separator bar by its id
func ShowSeparator(id uint32) {
changeSeparatorVisibility(id, 0, true)
}

// AddSeparator adds a separator bar to the submenu
func (item *MenuItem) AddSeparator() {
addSeparator(currentID.Add(1), item.id)
}

// AddSeparatorID adds a separator bar to the submenu and returns its id
func (item *MenuItem) AddSeparatorID() uint32 {
id := currentID.Add(1)
addSeparator(id, item.id)
return id
}

// AddSubMenuItem adds a nested sub-menu item with the designated title and tooltip.
// It can be safely invoked from different goroutines.
// Created menu items are checkable on Windows and OSX by default. For Linux you have to use AddSubMenuItemCheckbox
Expand Down
14 changes: 14 additions & 0 deletions systray_menu_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ func addSeparator(id uint32, parent uint32) {
refresh()
}

func changeSeparatorVisibility(id uint32, parent uint32, visible bool) {
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(visible)
refresh()
return
}
}
}

func applyItemToLayout(in *MenuItem, out *menuLayout) {
out.V1["enabled"] = dbus.MakeVariant(!in.disabled)
out.V1["label"] = dbus.MakeVariant(in.title)
Expand Down