// buildMenu fills the menu with left and middle click actions if they're set. // func (app *Applet) buildMenu(menu cdtype.Menuer) { needSep := false if app.conf.LeftAction > 0 && app.conf.LeftCommand != "" { menu.AddEntry("Action left click", "system-run", app.Command().Callback(cmdLeft)) needSep = true } if app.conf.MiddleAction > 0 && app.conf.MiddleCommand != "" { menu.AddEntry("Action middle click", "system-run", app.Command().Callback(cmdMiddle)) needSep = true } if needSep { menu.AddSeparator() } subup := menu.AddSubMenu("Upload", "") for _, hist := range app.up.ListHistory() { hist := hist subup.AddEntry(hist["file"], "", func() { app.Log().Info(hist["link"]) clipboard.Write(hist["link"]) // app.ShowDialog(link, 5) }) } menu.AddSeparator() app.video.Menu(menu) }
// BuildMenu fills the menu with the given actions list. // func (o *Actions) BuildMenu(menu cdtype.Menuer, actionIds []int) { for _, ID := range actionIds { act := o.list[ID] var entry cdtype.MenuWidgeter switch act.Menu { case cdtype.MenuEntry: entry = menu.AddEntry(act.Name, act.Icon, o.Callback(act.ID)) case cdtype.MenuSeparator: menu.AddSeparator() case cdtype.MenuCheckBox: entry = menu.AddCheckEntry(act.Name, *act.Bool, o.Callback(act.ID)) if act.Call == nil { act.Call = func() { *act.Bool = !*act.Bool } } case cdtype.MenuRadioButton: entry = menu.AddRadioEntry(act.Name, *act.Bool, act.Group, o.Callback(act.ID)) // case cdtype.MenuSubMenu: } if entry != nil && act.Tooltip != "" { entry.SetTooltipText(act.Tooltip) } } }
// onBuildMenu fills the menu with device actions: mute, mixer, select device. // func (app *Applet) onBuildMenu(menu cdtype.Menuer) { // device actions menu: mute, mixer, select device. mute, _ := app.pulse.Device(app.pulse.sink).Bool("Mute") menu.AddCheckEntry("Mute volume", mute, app.pulse.ToggleMute) if app.conf.MixerCommand != "" { menu.AddEntry("Open mixer", "multimedia-volume-control", app.Command().Callback(cmdMixer)) } app.menuAddDevices(menu, app.pulse.sink, "Managed device", app.pulse.SetSink) }
func (app *Applet) menuAddDevices(menu cdtype.Menuer, selected dbus.ObjectPath, title string, call func(dbus.ObjectPath) error) { sinks, _ := app.pulse.Core().ListPath("Sinks") if len(sinks) < 2 { // Only show the sinks list if we have at least 2 devices to switch between. return } menu.AddSeparator() menu.AddEntry(title, "audio-card", nil) menu.AddSeparator() for _, sink := range sinks { dev := app.pulse.Device(sink) sink := sink // make static reference of sink for the callback (we're in a range). v, e := dev.MapString("PropertyList") name := ternary.String(e == nil, v["device.description"], "unknown") menu.AddCheckEntry(name, sink == selected, func() { log.Err(call(sink)) }) } }