Skip to content

Commit 8724d25

Browse files
committed
Notifications working (still needs fixing)
1 parent ca5318f commit 8724d25

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

bar.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ func createSidestuff(nDaemon *notificationDaemon.Daemon) *gtk.Box {
142142
sc, _ = notificationBox.GetStyleContext()
143143
sc.AddClass("notification-bell-wrapper")
144144

145+
notificationBar := createNotificationBar(nDaemon)
146+
notificationButton.Connect("clicked", func() {
147+
if notificationBar.IsVisible() {
148+
notificationBar.Hide()
149+
} else {
150+
if len(nDaemon.Notifications) != 0 {
151+
notificationBar.ShowAll()
152+
}
153+
154+
}
155+
})
156+
157+
ntStack, _ := gtk.StackNew()
158+
145159
notificationImage, _ := gtk.ImageNewFromIconName("preferences-system-notifications-symbolic", gtk.ICON_SIZE_BUTTON)
146160
sc, _ = notificationImage.GetStyleContext()
147161
sc.AddClass("notification-bell")
@@ -150,12 +164,22 @@ func createSidestuff(nDaemon *notificationDaemon.Daemon) *gtk.Box {
150164
sc, _ = notificationText.GetStyleContext()
151165
sc.AddClass("h2")
152166

153-
notificationBox.PackStart(notificationText, false, false, 0)
167+
ntStack.Add(notificationImage)
168+
ntStack.Add(notificationText)
169+
170+
notificationBox.PackStart(ntStack, false, false, 0)
154171
notificationButton.Add(notificationBox)
155172

156173
glib.TimeoutAdd(uint(100), func() bool {
157174
// Get new date/time info.
158175
notificationText.SetText(strconv.Itoa(len(nDaemon.Notifications)))
176+
if len(nDaemon.Notifications) == 0 {
177+
ntStack.SetVisibleChild(notificationImage)
178+
ntStack.SetTransitionType(gtk.STACK_TRANSITION_TYPE_SLIDE_LEFT)
179+
} else {
180+
ntStack.SetVisibleChild(notificationText)
181+
ntStack.SetTransitionType(gtk.STACK_TRANSITION_TYPE_SLIDE_RIGHT)
182+
}
159183

160184
// Return true to keep the timeout active.
161185
return true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22.2
44

55
require (
66
github.com/MiracleOS-Team/desktoplib v0.0.0-20250208145244-91c183a6941e
7-
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250214180153-81dbe745c61a
7+
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250218130005-9d3578a779a2
88
github.com/dlasky/gotk3-layershell v0.0.0-20240515133811-5c5115f0d774
99
github.com/gotk3/gotk3 v0.6.5-0.20240618185848-ff349ae13f56
1010
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ github.com/MiracleOS-Team/libxdg-go v0.0.0-20250214174651-a76479f5ae9b h1:AFndsH
2020
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250214174651-a76479f5ae9b/go.mod h1:GA/p+ukjyXCsrcpGvs0/gFp1NeHAMtJG/sYT0JcImfE=
2121
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250214180153-81dbe745c61a h1:0JcWX9wXTvCl/Q4qYln8hjv6fOXUAo2jiduJqzxgJC8=
2222
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250214180153-81dbe745c61a/go.mod h1:GA/p+ukjyXCsrcpGvs0/gFp1NeHAMtJG/sYT0JcImfE=
23+
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250218130005-9d3578a779a2 h1:ld+DJBjtlfFMTDSpEdUPWDcqoUPS3A3Cx+ZcgKl5uQs=
24+
github.com/MiracleOS-Team/libxdg-go v0.0.0-20250218130005-9d3578a779a2/go.mod h1:GA/p+ukjyXCsrcpGvs0/gFp1NeHAMtJG/sYT0JcImfE=
2325
github.com/bep/godartsass v1.2.0 h1:E2VvQrxAHAFwbjyOIExAMmogTItSKodoKuijNrGm5yU=
2426
github.com/bep/godartsass v1.2.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
2527
github.com/bep/godartsass/v2 v2.3.2 h1:meuc76J1C1soSCAnlnJRdGqJ5S4m6/GW+8hmOe9tOog=

main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,5 @@ func main() {
7878
bar := createBar(daemon)
7979
bar.ShowAll()
8080

81-
//notificationBar := createNotificationBar(daemon)
82-
//notificationBar.ShowAll()
83-
8481
gtk.Main()
8582
}

notifications.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,29 @@ func createNotificationBar(nDaemon *notificationDaemon.Daemon) *gtk.Window {
155155

156156
mBox.PackStart(createNotificationBarTitle(nDaemon), false, false, 0)
157157

158+
glib.TimeoutAdd(uint(500), func() bool {
159+
chil := mBox.GetChildren()
160+
161+
cLength := int(chil.Length())
162+
163+
for i := 0; i < cLength; i++ {
164+
chil.NthData(uint(i)).(*gtk.Widget).Destroy()
165+
}
166+
167+
for _, nt := range nDaemon.Notifications {
168+
mBox.PackEnd(createNotification(&nt, nDaemon), false, false, 0)
169+
}
170+
171+
mBox.PackStart(createNotificationBarTitle(nDaemon), false, false, 0)
172+
173+
mBox.ShowAll()
174+
if len(nDaemon.Notifications) == 0 {
175+
win.Hide()
176+
}
177+
// Return true to keep the timeout active.
178+
return true
179+
})
180+
158181
win.Add(mBox)
159182

160183
return win

0 commit comments

Comments
 (0)