diff --git a/internal/ui/menu.go b/internal/ui/menu.go index 3ed29bc4..d178161a 100644 --- a/internal/ui/menu.go +++ b/internal/ui/menu.go @@ -1,12 +1,16 @@ package ui import ( + "fmt" + "image/color" "os" "sort" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" deskDriver "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -49,6 +53,47 @@ func (w *widgetPanel) appendAppCategories(acc *widget.Accordion, win fyne.Window acc.Refresh() } +func (w *widgetPanel) askLogout() { + win := fyne.CurrentApp().Driver().(deskDriver.Driver).CreateSplashWindow() + logout := widget.NewButtonWithIcon("Logout", theme.LogoutIcon(), func() { + win.Close() + w.desk.WindowManager().Close() + }) + logout.Importance = widget.DangerImportance + cancel := widget.NewButton("Cancel", func() { + win.Close() + }) + + header := widget.NewRichTextFromMarkdown(fmt.Sprintf("### Log out")) + header.Truncation = fyne.TextTruncateEllipsis + bottomPad := canvas.NewRectangle(color.Transparent) + bottomPad.SetMinSize(fyne.NewSquareSize(10)) + content := container.NewBorder( + header, + container.NewVBox( + container.NewHBox(layout.NewSpacer(), + container.NewGridWithColumns(2, cancel, logout), + layout.NewSpacer()), bottomPad), + nil, nil, + widget.NewLabel("Are you sure you want to log out?")) + + r, g, b, _ := theme.OverlayBackgroundColor().RGBA() + bgCol := &color.NRGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: 230} + + bg := canvas.NewRectangle(bgCol) + icon := canvas.NewImageFromResource(theme.LogoutIcon()) + iconBox := container.NewWithoutLayout(icon) + icon.Resize(fyne.NewSize(92, 92)) + icon.Move(fyne.NewPos(280-92-theme.Padding(), theme.Padding())) + win.SetContent(container.NewStack( + iconBox, bg, + container.NewPadded(content))) + + win.Resize(fyne.NewSize(280, 150)) + win.CenterOnScreen() + win.Show() +} + func (w *widgetPanel) showAccountMenu(_ fyne.CanvasObject) { w2 := fyne.CurrentApp().Driver().(deskDriver.Driver).CreateSplashWindow() w2.Canvas().SetOnTypedKey(func(k *fyne.KeyEvent) { @@ -58,8 +103,8 @@ func (w *widgetPanel) showAccountMenu(_ fyne.CanvasObject) { }) items1 := []fyne.CanvasObject{ &widget.Button{Icon: theme.LogoutIcon(), Importance: widget.DangerImportance, OnTapped: func() { + w.askLogout() w2.Close() - w.desk.WindowManager().Close() }}} isEmbed := w.desk.(*desktop).root.Title() != RootWindowName if !isEmbed { diff --git a/internal/x11/wm/events.go b/internal/x11/wm/events.go index e7537508..b5420be0 100644 --- a/internal/x11/wm/events.go +++ b/internal/x11/wm/events.go @@ -234,8 +234,10 @@ func (x *x11WM) handleMouseEnter(ev xproto.EnterNotifyEvent) { func (x *x11WM) handleMouseLeave(ev xproto.LeaveNotifyEvent) { if ev.Event == x.menuID { // dismiss overlay menus on mouse out x.menuID = 0 - x.menuWin.Close() - x.menuWin = nil + if x.menuWin != nil { + x.menuWin.Close() + x.menuWin = nil + } } for _, c := range x.clients {