launch, pin, unpin
This commit is contained in:
BIN
bin/nwg-drawer
BIN
bin/nwg-drawer
Binary file not shown.
32
main.go
32
main.go
@@ -102,6 +102,8 @@ var (
|
|||||||
userDirsMap map[string]string
|
userDirsMap map[string]string
|
||||||
appFlowBox *gtk.FlowBox
|
appFlowBox *gtk.FlowBox
|
||||||
appFlowBoxWrapper *gtk.Box
|
appFlowBoxWrapper *gtk.Box
|
||||||
|
pinnedFlowBox *gtk.FlowBox
|
||||||
|
pinnedFlowBoxWrapper *gtk.Box
|
||||||
catButtons []*gtk.Button
|
catButtons []*gtk.Button
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -109,14 +111,13 @@ var (
|
|||||||
var cssFileName = flag.String("s", "drawer.css", "Styling: css file name")
|
var cssFileName = flag.String("s", "drawer.css", "Styling: css file name")
|
||||||
var targetOutput = flag.String("o", "", "name of the Output to display the menu on")
|
var targetOutput = flag.String("o", "", "name of the Output to display the menu on")
|
||||||
var displayVersion = flag.Bool("v", false, "display Version information")
|
var displayVersion = flag.Bool("v", false, "display Version information")
|
||||||
var autohide = flag.Bool("d", false, "auto-hiDe: close window when left")
|
|
||||||
var valign = flag.String("va", "bottom", "Vertical Alignment: \"bottom\" or \"top\"")
|
var valign = flag.String("va", "bottom", "Vertical Alignment: \"bottom\" or \"top\"")
|
||||||
var halign = flag.String("ha", "left", "Horizontal Alignment: \"left\" or \"right\"")
|
var halign = flag.String("ha", "left", "Horizontal Alignment: \"left\" or \"right\"")
|
||||||
var marginTop = flag.Int("mt", 0, "Margin Top")
|
var marginTop = flag.Int("mt", 0, "Margin Top")
|
||||||
var marginLeft = flag.Int("ml", 0, "Margin Left")
|
var marginLeft = flag.Int("ml", 0, "Margin Left")
|
||||||
var marginRight = flag.Int("mr", 0, "Margin Right")
|
var marginRight = flag.Int("mr", 0, "Margin Right")
|
||||||
var marginBottom = flag.Int("mb", 0, "Margin Bottom")
|
var marginBottom = flag.Int("mb", 0, "Margin Bottom")
|
||||||
var iconSizeLarge = flag.Int("isl", 32, "Icon Size Large")
|
var iconSizeLarge = flag.Int("isl", 48, "Icon Size Large")
|
||||||
var iconSizeSmall = flag.Int("iss", 16, "Icon Size Small")
|
var iconSizeSmall = flag.Int("iss", 16, "Icon Size Small")
|
||||||
var itemPadding = flag.Uint("padding", 2, "vertical item padding")
|
var itemPadding = flag.Uint("padding", 2, "vertical item padding")
|
||||||
var lang = flag.String("lang", "", "force lang, e.g. \"en\", \"pl\"")
|
var lang = flag.String("lang", "", "force lang, e.g. \"en\", \"pl\"")
|
||||||
@@ -159,12 +160,6 @@ func main() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
i, err := strconv.Atoi(pid)
|
i, err := strconv.Atoi(pid)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
/*if !*autohide {
|
|
||||||
println("Running instance found, sending SIGTERM and exiting...")
|
|
||||||
syscall.Kill(i, syscall.SIGTERM)
|
|
||||||
} else {
|
|
||||||
println("Already running")
|
|
||||||
}*/
|
|
||||||
println("Running instance found, sending SIGTERM and exiting...")
|
println("Running instance found, sending SIGTERM and exiting...")
|
||||||
syscall.Kill(i, syscall.SIGTERM)
|
syscall.Kill(i, syscall.SIGTERM)
|
||||||
}
|
}
|
||||||
@@ -282,12 +277,10 @@ func main() {
|
|||||||
|
|
||||||
// Close the window on leave, but not immediately, to avoid accidental closes
|
// Close the window on leave, but not immediately, to avoid accidental closes
|
||||||
win.Connect("leave-notify-event", func() {
|
win.Connect("leave-notify-event", func() {
|
||||||
if *autohide {
|
src, err = glib.TimeoutAdd(uint(500), func() bool {
|
||||||
src, err = glib.TimeoutAdd(uint(1000), func() bool {
|
gtk.MainQuit()
|
||||||
gtk.MainQuit()
|
return false
|
||||||
return false
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
win.Connect("enter-notify-event", func() {
|
win.Connect("enter-notify-event", func() {
|
||||||
@@ -298,7 +291,6 @@ func main() {
|
|||||||
win.Add(outerBox)
|
win.Add(outerBox)
|
||||||
|
|
||||||
alignmentBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
alignmentBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
//alignmentBox.SetHomogeneous(true)
|
|
||||||
outerBox.PackStart(alignmentBox, true, true, 0)
|
outerBox.PackStart(alignmentBox, true, true, 0)
|
||||||
|
|
||||||
leftBox, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
leftBox, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
@@ -335,6 +327,12 @@ func main() {
|
|||||||
wrapper.PackEnd(searchEntry, true, false, 0)
|
wrapper.PackEnd(searchEntry, true, false, 0)
|
||||||
rightColumn.PackStart(wrapper, false, false, 10)
|
rightColumn.PackStart(wrapper, false, false, 10)
|
||||||
|
|
||||||
|
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
|
pinnedFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
|
pinnedFlowBox = setUpPinnedFlowBox()
|
||||||
|
wrapper.PackStart(pinnedFlowBoxWrapper, true, false, 0)
|
||||||
|
rightColumn.PackStart(wrapper, false, false, 10)
|
||||||
|
|
||||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
categoriesMenuBar := setUpCategoriesButtonBox()
|
categoriesMenuBar := setUpCategoriesButtonBox()
|
||||||
wrapper.PackStart(categoriesMenuBar, true, false, 0)
|
wrapper.PackStart(categoriesMenuBar, true, false, 0)
|
||||||
@@ -357,6 +355,10 @@ func main() {
|
|||||||
})
|
})
|
||||||
resultWrapper.PackStart(resultWindow, true, true, 0)
|
resultWrapper.PackStart(resultWindow, true, true, 0)
|
||||||
|
|
||||||
|
/*pinnedFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
|
resultWindow.Add(pinnedFlowBoxWrapper)
|
||||||
|
pinnedFlowBox = setUpPinnedFlowBox()*/
|
||||||
|
|
||||||
appFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
appFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
resultWindow.Add(appFlowBoxWrapper)
|
resultWindow.Add(appFlowBoxWrapper)
|
||||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||||
|
|||||||
122
uicomponents.go
122
uicomponents.go
@@ -82,6 +82,69 @@ func setUpPinnedListBoxRow(desktopID string) *gtk.ListBoxRow {
|
|||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setUpPinnedFlowBox() *gtk.FlowBox {
|
||||||
|
if pinnedFlowBox != nil {
|
||||||
|
pinnedFlowBox.Destroy()
|
||||||
|
}
|
||||||
|
flowBox, _ := gtk.FlowBoxNew()
|
||||||
|
flowBox.SetMaxChildrenPerLine(6)
|
||||||
|
flowBox.SetColumnSpacing(20)
|
||||||
|
flowBox.SetHomogeneous(true)
|
||||||
|
flowBox.SetRowSpacing(20)
|
||||||
|
|
||||||
|
if len(pinned) > 0 {
|
||||||
|
for _, desktopID := range pinned {
|
||||||
|
entry := id2entry[desktopID]
|
||||||
|
|
||||||
|
btn, _ := gtk.ButtonNew()
|
||||||
|
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
||||||
|
img, err := gtk.ImageNewFromPixbuf(pixbuf)
|
||||||
|
if err != nil {
|
||||||
|
println(err, entry.Icon)
|
||||||
|
}
|
||||||
|
btn.SetImage(img)
|
||||||
|
btn.SetAlwaysShowImage(true)
|
||||||
|
btn.SetImagePosition(gtk.POS_TOP)
|
||||||
|
|
||||||
|
name := ""
|
||||||
|
if entry.NameLoc != "" {
|
||||||
|
name = entry.NameLoc
|
||||||
|
} else {
|
||||||
|
name = entry.Name
|
||||||
|
}
|
||||||
|
if len(name) > 20 {
|
||||||
|
name = fmt.Sprintf("%s...", name[:17])
|
||||||
|
}
|
||||||
|
btn.SetLabel(name)
|
||||||
|
|
||||||
|
btn.Connect("button-release-event", func(row *gtk.Button, e *gdk.Event) bool {
|
||||||
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
||||||
|
if btnEvent.Button() == 1 {
|
||||||
|
launch(entry.Exec, entry.Terminal)
|
||||||
|
return true
|
||||||
|
} else if btnEvent.Button() == 3 {
|
||||||
|
unpinItem(entry.DesktopID)
|
||||||
|
pinnedFlowBox = setUpPinnedFlowBox()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
flowBox.Add(btn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flowBox.Connect("enter-notify-event", func() {
|
||||||
|
cancelClose()
|
||||||
|
restoreButtonBox()
|
||||||
|
})
|
||||||
|
|
||||||
|
pinnedFlowBoxWrapper.PackStart(flowBox, true, true, 0)
|
||||||
|
flowBox.ShowAll()
|
||||||
|
|
||||||
|
return flowBox
|
||||||
|
}
|
||||||
|
|
||||||
func setUpCategoriesListBox() *gtk.ListBox {
|
func setUpCategoriesListBox() *gtk.ListBox {
|
||||||
listBox, _ := gtk.ListBoxNew()
|
listBox, _ := gtk.ListBoxNew()
|
||||||
for _, cat := range categories {
|
for _, cat := range categories {
|
||||||
@@ -410,36 +473,12 @@ func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
|||||||
for _, entry := range desktopEntries {
|
for _, entry := range desktopEntries {
|
||||||
if categoryList != nil {
|
if categoryList != nil {
|
||||||
if !entry.NoDisplay && isIn(categoryList, entry.DesktopID) {
|
if !entry.NoDisplay && isIn(categoryList, entry.DesktopID) {
|
||||||
button, _ := gtk.ButtonNew()
|
button := flowBoxButton(entry)
|
||||||
button.SetAlwaysShowImage(true)
|
|
||||||
|
|
||||||
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
|
||||||
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
|
||||||
button.SetImage(img)
|
|
||||||
button.SetImagePosition(gtk.POS_TOP)
|
|
||||||
name := entry.NameLoc
|
|
||||||
if len(name) > 20 {
|
|
||||||
name = fmt.Sprintf("%s...", name[:17])
|
|
||||||
}
|
|
||||||
button.SetLabel(name)
|
|
||||||
|
|
||||||
flowBox.Add(button)
|
flowBox.Add(button)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !entry.NoDisplay {
|
if !entry.NoDisplay {
|
||||||
button, _ := gtk.ButtonNew()
|
button := flowBoxButton(entry)
|
||||||
button.SetAlwaysShowImage(true)
|
|
||||||
|
|
||||||
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
|
||||||
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
|
||||||
button.SetImage(img)
|
|
||||||
button.SetImagePosition(gtk.POS_TOP)
|
|
||||||
name := entry.NameLoc
|
|
||||||
if len(name) > 20 {
|
|
||||||
name = fmt.Sprintf("%s...", name[:17])
|
|
||||||
}
|
|
||||||
button.SetLabel(name)
|
|
||||||
|
|
||||||
flowBox.Add(button)
|
flowBox.Add(button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,6 +489,37 @@ func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
|||||||
return flowBox
|
return flowBox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flowBoxButton(entry desktopEntry) *gtk.Button {
|
||||||
|
button, _ := gtk.ButtonNew()
|
||||||
|
button.SetAlwaysShowImage(true)
|
||||||
|
|
||||||
|
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
||||||
|
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
||||||
|
button.SetImage(img)
|
||||||
|
button.SetImagePosition(gtk.POS_TOP)
|
||||||
|
name := entry.NameLoc
|
||||||
|
if len(name) > 20 {
|
||||||
|
name = fmt.Sprintf("%s...", name[:17])
|
||||||
|
}
|
||||||
|
button.SetLabel(name)
|
||||||
|
|
||||||
|
ID := entry.DesktopID
|
||||||
|
exec := entry.Exec
|
||||||
|
terminal := entry.Terminal
|
||||||
|
button.Connect("button-release-event", func(row *gtk.Button, e *gdk.Event) bool {
|
||||||
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
||||||
|
if btnEvent.Button() == 1 {
|
||||||
|
launch(exec, terminal)
|
||||||
|
return true
|
||||||
|
} else if btnEvent.Button() == 3 {
|
||||||
|
pinItem(ID)
|
||||||
|
pinnedFlowBox = setUpPinnedFlowBox()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
return button
|
||||||
|
}
|
||||||
|
|
||||||
func setUpFileSearchResult() *gtk.ListBox {
|
func setUpFileSearchResult() *gtk.ListBox {
|
||||||
listBox, _ := gtk.ListBoxNew()
|
listBox, _ := gtk.ListBoxNew()
|
||||||
if fileSearchResultWindow != nil {
|
if fileSearchResultWindow != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user