mirror of
https://github.com/nwg-piotr/nwg-drawer.git
synced 2024-08-16 17:20:22 +03:00
add powerButton function
This commit is contained in:
parent
db265ccf6a
commit
01c26ba092
33
main.go
33
main.go
@ -171,6 +171,11 @@ var nameLimit = flag.Int("fslen", 80, "File Search name LENgth Limit")
|
||||
var noCats = flag.Bool("nocats", false, "Disable filtering by category")
|
||||
var noFS = flag.Bool("nofs", false, "Disable file search")
|
||||
var resident = flag.Bool("r", false, "Leave the program resident in memory")
|
||||
var cmdExit = flag.String("cmdexit", "", "command for the Exit power bar icon")
|
||||
var cmdLock = flag.String("cmdlock", "", "command for the Lock power bar icon")
|
||||
var cmdPoweroff = flag.String("cmdpoweroff", "", "command for the Poweroff power bar icon")
|
||||
var cmdReboot = flag.String("cmdreboot", "", "command for the Reboot power bar icon")
|
||||
var cmdSleep = flag.String("cmdsleep", "", "command for the sleep power bar icon")
|
||||
var debug = flag.Bool("d", false, "Turn on Debug messages")
|
||||
|
||||
func main() {
|
||||
@ -559,6 +564,34 @@ func main() {
|
||||
resultsWrapper.PackEnd(wrapper, false, false, 10)
|
||||
}
|
||||
|
||||
// Power Button Bar
|
||||
if *cmdExit != "" || *cmdLock != "" || *cmdPoweroff != "" || *cmdReboot != "" || *cmdSleep != "" {
|
||||
powerBarWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
outerVBox.PackStart(powerBarWrapper, false, false, 0)
|
||||
powerButtonsWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 6)
|
||||
if *cmdLock != "" {
|
||||
btn := powerButton("/usr/share/nwg-drawer/img/lock.svg", *cmdLock)
|
||||
powerButtonsWrapper.PackStart(btn, true, false, 0)
|
||||
}
|
||||
if *cmdExit != "" {
|
||||
btn := powerButton("/usr/share/nwg-drawer/img/exit.svg", *cmdExit)
|
||||
powerButtonsWrapper.PackStart(btn, true, false, 0)
|
||||
}
|
||||
if *cmdReboot != "" {
|
||||
btn := powerButton("/usr/share/nwg-drawer/img/reboot.svg", *cmdReboot)
|
||||
powerButtonsWrapper.PackStart(btn, true, false, 0)
|
||||
}
|
||||
if *cmdSleep != "" {
|
||||
btn := powerButton("/usr/share/nwg-drawer/img/sleep.svg", *cmdSleep)
|
||||
powerButtonsWrapper.PackStart(btn, true, false, 0)
|
||||
}
|
||||
if *cmdPoweroff != "" {
|
||||
btn := powerButton("/usr/share/nwg-drawer/img/poweroff.svg", *cmdPoweroff)
|
||||
powerButtonsWrapper.PackStart(btn, true, false, 0)
|
||||
}
|
||||
}
|
||||
|
||||
statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
statusLineWrapper.SetProperty("name", "status-line-wrapper")
|
||||
outerVBox.PackStart(statusLineWrapper, false, false, 10)
|
||||
|
@ -287,6 +287,43 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
|
||||
return button
|
||||
}
|
||||
|
||||
func powerButton(iconPath, command string) *gtk.Button {
|
||||
button, _ := gtk.ButtonNew()
|
||||
button.SetAlwaysShowImage(true)
|
||||
|
||||
var pixbuf *gdk.Pixbuf
|
||||
var img *gtk.Image
|
||||
var err error
|
||||
//pixbuf, err = createPixbuf(iconPath, *iconSize)
|
||||
pixbuf, err = gdk.PixbufNewFromFileAtSize(iconPath, *iconSize, *iconSize)
|
||||
if err != nil {
|
||||
pixbuf, _ = createPixbuf("unknown", *iconSize)
|
||||
log.Warnf("Couldn't find icon %s", iconPath)
|
||||
}
|
||||
img, _ = gtk.ImageNewFromPixbuf(pixbuf)
|
||||
button.SetImage(img)
|
||||
button.SetImagePosition(gtk.POS_TOP)
|
||||
|
||||
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
|
||||
btnEvent := gdk.EventButtonNewFromEvent(e)
|
||||
if btnEvent.Button() == 1 {
|
||||
launch(command, false)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
button.Connect("activate", func() {
|
||||
launch(command, false)
|
||||
})
|
||||
button.Connect("enter-notify-event", func() {
|
||||
statusLabel.SetText(command)
|
||||
})
|
||||
button.Connect("focus-in-event", func() {
|
||||
statusLabel.SetText(command)
|
||||
})
|
||||
return button
|
||||
}
|
||||
|
||||
func setUpFileSearchResultContainer() *gtk.FlowBox {
|
||||
if fileSearchResultFlowBox != nil {
|
||||
fileSearchResultFlowBox.Destroy()
|
||||
|
Loading…
Reference in New Issue
Block a user