Add Ctrl+Q quit shortcut for non-Mac

This commit is contained in:
Drew Weymouth
2024-02-03 11:56:21 -08:00
parent 7943b17199
commit e20bdcad37
4 changed files with 23 additions and 14 deletions
+18
View File
@@ -3,6 +3,7 @@ package ui
import (
"fmt"
"log"
"math"
"strings"
"github.com/20after4/configdir"
@@ -280,6 +281,11 @@ func (m *MainWindow) addShortcuts() {
m.showSettingsDialog()
})
}
if os.QuitShortcut != nil {
m.Canvas().AddShortcut(os.QuitShortcut, func(_ fyne.Shortcut) {
m.Quit()
})
}
m.Canvas().AddShortcut(&ShortcutReload, func(_ fyne.Shortcut) {
m.BrowsingPane.Reload()
@@ -346,3 +352,15 @@ func (m *MainWindow) SetTitle(title string) {
func (m *MainWindow) SetContent(c fyne.CanvasObject) {
m.Window.SetContent(c)
}
func (m *MainWindow) Quit() {
m.SaveWindowSize()
fyne.CurrentApp().Quit()
}
func (m *MainWindow) SaveWindowSize() {
// round sizes to even to avoid Wayland issues with 2x scaling factor
// https://github.com/dweymouth/supersonic/issues/212
m.App.Config.Application.WindowHeight = int(math.RoundToEven(float64(m.Window.Canvas().Size().Height)))
m.App.Config.Application.WindowWidth = int(math.RoundToEven(float64(m.Window.Canvas().Size().Width)))
}
+2 -1
View File
@@ -13,7 +13,8 @@ const (
)
var (
BackShortcuts = []desktop.CustomShortcut{
QuitShortcut *desktop.CustomShortcut = nil // Fyne already adds Cmd+Q
BackShortcuts = []desktop.CustomShortcut{
{Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeft},
{Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeftBracket},
}
+1
View File
@@ -13,6 +13,7 @@ const (
)
var (
QuitShortcut = &desktop.CustomShortcut{Modifier: KeyModifierControl, KeyName: fyne.KeyQ}
BackShortcuts = []desktop.CustomShortcut{
{Modifier: fyne.KeyModifierAlt, KeyName: fyne.KeyLeft},
}