Merge pull request #124 from nwg-piotr/icon-theme
Add the `-pbuseicontheme` flagIcon theme
This commit is contained in:
40
main.go
40
main.go
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
)
|
||||
|
||||
const version = "0.4.8"
|
||||
const version = "0.4.9"
|
||||
|
||||
var (
|
||||
appDirs []string
|
||||
@@ -181,7 +181,8 @@ var pbLock = flag.String("pblock", "", "command for the Lock power bar icon")
|
||||
var pbPoweroff = flag.String("pbpoweroff", "", "command for the Poweroff power bar icon")
|
||||
var pbReboot = flag.String("pbreboot", "", "command for the Reboot power bar icon")
|
||||
var pbSleep = flag.String("pbsleep", "", "command for the sleep power bar icon")
|
||||
var pbSize = flag.Int("pbsize", 64, "power bar icon size")
|
||||
var pbSize = flag.Int("pbsize", 64, "power bar icon size (only works w/ built-in icons)")
|
||||
var pbUseIconTheme = flag.Bool("pbuseicontheme", false, "use icon theme instead of built-in icons in power bar")
|
||||
var debug = flag.Bool("d", false, "Turn on Debug messages")
|
||||
|
||||
func main() {
|
||||
@@ -624,27 +625,52 @@ func main() {
|
||||
powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12)
|
||||
|
||||
if *pbPoweroff != "" {
|
||||
btn := powerButton(filepath.Join(dataDirectory, "img/poweroff.svg"), *pbPoweroff)
|
||||
btn, _ := gtk.ButtonNew()
|
||||
if !*pbUseIconTheme {
|
||||
btn = powerButton(filepath.Join(dataDirectory, "img/poweroff.svg"), *pbPoweroff)
|
||||
} else {
|
||||
btn = powerButton("system-shutdown-symbolic", *pbPoweroff)
|
||||
}
|
||||
powerButtonsWrapper.PackEnd(btn, true, false, 0)
|
||||
firstPowerBtn = btn
|
||||
}
|
||||
if *pbSleep != "" {
|
||||
btn := powerButton(filepath.Join(dataDirectory, "img/sleep.svg"), *pbSleep)
|
||||
btn, _ := gtk.ButtonNew()
|
||||
if !*pbUseIconTheme {
|
||||
btn = powerButton(filepath.Join(dataDirectory, "img/sleep.svg"), *pbSleep)
|
||||
} else {
|
||||
btn = powerButton("face-yawn-symbolic", *pbSleep)
|
||||
}
|
||||
powerButtonsWrapper.PackEnd(btn, true, false, 0)
|
||||
firstPowerBtn = btn
|
||||
}
|
||||
if *pbReboot != "" {
|
||||
btn := powerButton(filepath.Join(dataDirectory, "img/reboot.svg"), *pbReboot)
|
||||
btn, _ := gtk.ButtonNew()
|
||||
if !*pbUseIconTheme {
|
||||
btn = powerButton(filepath.Join(dataDirectory, "img/reboot.svg"), *pbReboot)
|
||||
} else {
|
||||
btn = powerButton("system-reboot-symbolic", *pbReboot)
|
||||
}
|
||||
powerButtonsWrapper.PackEnd(btn, true, false, 0)
|
||||
firstPowerBtn = btn
|
||||
}
|
||||
if *pbExit != "" {
|
||||
btn := powerButton(filepath.Join(dataDirectory, "img/exit.svg"), *pbExit)
|
||||
btn, _ := gtk.ButtonNew()
|
||||
if !*pbUseIconTheme {
|
||||
btn = powerButton(filepath.Join(dataDirectory, "img/exit.svg"), *pbExit)
|
||||
} else {
|
||||
btn = powerButton("system-log-out-symbolic", *pbExit)
|
||||
}
|
||||
powerButtonsWrapper.PackEnd(btn, true, false, 0)
|
||||
firstPowerBtn = btn
|
||||
}
|
||||
if *pbLock != "" {
|
||||
btn := powerButton(filepath.Join(dataDirectory, "img/lock.svg"), *pbLock)
|
||||
btn, _ := gtk.ButtonNew()
|
||||
if !*pbUseIconTheme {
|
||||
btn = powerButton(filepath.Join(dataDirectory, "img/lock.svg"), *pbLock)
|
||||
} else {
|
||||
btn = powerButton("system-lock-screen-symbolic", *pbLock)
|
||||
}
|
||||
powerButtonsWrapper.PackEnd(btn, true, false, 0)
|
||||
firstPowerBtn = btn
|
||||
}
|
||||
|
||||
@@ -298,19 +298,24 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
|
||||
return button
|
||||
}
|
||||
|
||||
func powerButton(iconPath, command string) *gtk.Button {
|
||||
func powerButton(iconPathOrName, command string) *gtk.Button {
|
||||
button, _ := gtk.ButtonNew()
|
||||
button.SetAlwaysShowImage(true)
|
||||
|
||||
var pixbuf *gdk.Pixbuf
|
||||
var img *gtk.Image
|
||||
var err error
|
||||
pixbuf, err = gdk.PixbufNewFromFileAtSize(iconPath, *pbSize, *pbSize)
|
||||
if err != nil {
|
||||
pixbuf, _ = createPixbuf("unknown", *pbSize)
|
||||
log.Warnf("Couldn't find icon %s", iconPath)
|
||||
if !*pbUseIconTheme {
|
||||
pixbuf, err = gdk.PixbufNewFromFileAtSize(iconPathOrName, *pbSize, *pbSize)
|
||||
if err != nil {
|
||||
pixbuf, _ = createPixbuf("unknown", *pbSize)
|
||||
log.Warnf("Couldn't find icon %s", iconPathOrName)
|
||||
}
|
||||
img, _ = gtk.ImageNewFromPixbuf(pixbuf)
|
||||
} else {
|
||||
img, _ = gtk.ImageNewFromIconName(iconPathOrName, gtk.ICON_SIZE_DIALOG)
|
||||
}
|
||||
img, _ = gtk.ImageNewFromPixbuf(pixbuf)
|
||||
|
||||
button.SetImage(img)
|
||||
button.SetImagePosition(gtk.POS_TOP)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user