From 01c26ba092cf7c9b34240a749e76ffb2a548fd6d Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 1 Feb 2024 03:52:56 +0100 Subject: [PATCH] add powerButton function --- main.go | 33 +++++++++++++++++++++++++++++++++ uicomponents.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/main.go b/main.go index 31fd0e7..56e445f 100644 --- a/main.go +++ b/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) diff --git a/uicomponents.go b/uicomponents.go index 9000c38..4b3b55b 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -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()