mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
Compare commits
6 Commits
cbd1fd908c
...
4e66d3532e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e66d3532e | ||
|
|
1b6d567451 | ||
|
|
7959a79575 | ||
|
|
abf3249b67 | ||
|
|
35e0dc84e8 | ||
|
|
17639e8729 |
10
assets/dms-open.desktop
Normal file
10
assets/dms-open.desktop
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=DMS Application Picker
|
||||||
|
Comment=Select an application to open links and files
|
||||||
|
Exec=dms open %u
|
||||||
|
Icon=danklogo
|
||||||
|
Terminal=false
|
||||||
|
NoDisplay=true
|
||||||
|
MimeType=x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/file;text/html;
|
||||||
|
Categories=Utility;
|
||||||
@@ -64,6 +64,11 @@ func initializeProviders() {
|
|||||||
log.Warnf("Failed to register Sway provider: %v", err)
|
log.Warnf("Failed to register Sway provider: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
niriProvider := providers.NewNiriProvider("")
|
||||||
|
if err := registry.Register(niriProvider); err != nil {
|
||||||
|
log.Warnf("Failed to register Niri provider: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
config := keybinds.DefaultDiscoveryConfig()
|
config := keybinds.DefaultDiscoveryConfig()
|
||||||
if err := keybinds.AutoDiscoverProviders(registry, config); err != nil {
|
if err := keybinds.AutoDiscoverProviders(registry, config); err != nil {
|
||||||
log.Warnf("Failed to auto-discover providers: %v", err)
|
log.Warnf("Failed to auto-discover providers: %v", err)
|
||||||
@@ -99,6 +104,8 @@ func runKeybindsShow(cmd *cobra.Command, args []string) {
|
|||||||
provider = providers.NewMangoWCProvider(customPath)
|
provider = providers.NewMangoWCProvider(customPath)
|
||||||
case "sway":
|
case "sway":
|
||||||
provider = providers.NewSwayProvider(customPath)
|
provider = providers.NewSwayProvider(customPath)
|
||||||
|
case "niri":
|
||||||
|
provider = providers.NewNiriProvider(customPath)
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Provider %s does not support custom path", providerName)
|
log.Fatalf("Provider %s does not support custom path", providerName)
|
||||||
}
|
}
|
||||||
|
|||||||
224
core/cmd/dms/commands_open.go
Normal file
224
core/cmd/dms/commands_open.go
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"mime"
|
||||||
|
"net"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/models"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
openMimeType string
|
||||||
|
openCategories []string
|
||||||
|
openRequestType string
|
||||||
|
)
|
||||||
|
|
||||||
|
var openCmd = &cobra.Command{
|
||||||
|
Use: "open [target]",
|
||||||
|
Short: "Open a file, URL, or resource with an application picker",
|
||||||
|
Long: `Open a target (URL, file, or other resource) using the DMS application picker.
|
||||||
|
By default, this opens URLs with the browser picker. You can customize the behavior
|
||||||
|
with flags to handle different MIME types or application categories.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
dms open https://example.com # Open URL with browser picker
|
||||||
|
dms open file.pdf --mime application/pdf # Open PDF with compatible apps
|
||||||
|
dms open document.odt --category Office # Open with office applications
|
||||||
|
dms open --mime image/png image.png # Open image with image viewers`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
runOpen(args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(openCmd)
|
||||||
|
openCmd.Flags().StringVar(&openMimeType, "mime", "", "MIME type for filtering applications")
|
||||||
|
openCmd.Flags().StringSliceVar(&openCategories, "category", []string{}, "Application categories to filter (e.g., WebBrowser, Office, Graphics)")
|
||||||
|
openCmd.Flags().StringVar(&openRequestType, "type", "url", "Request type (url, file, or custom)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// mimeTypeToCategories maps MIME types to desktop file categories
|
||||||
|
func mimeTypeToCategories(mimeType string) []string {
|
||||||
|
// Split MIME type to get the main type
|
||||||
|
parts := strings.Split(mimeType, "/")
|
||||||
|
if len(parts) < 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mainType := parts[0]
|
||||||
|
|
||||||
|
switch mainType {
|
||||||
|
case "image":
|
||||||
|
return []string{"Graphics", "Viewer"}
|
||||||
|
case "video":
|
||||||
|
return []string{"Video", "AudioVideo"}
|
||||||
|
case "audio":
|
||||||
|
return []string{"Audio", "AudioVideo"}
|
||||||
|
case "text":
|
||||||
|
if strings.Contains(mimeType, "html") {
|
||||||
|
return []string{"WebBrowser"}
|
||||||
|
}
|
||||||
|
return []string{"TextEditor", "Office"}
|
||||||
|
case "application":
|
||||||
|
if strings.Contains(mimeType, "pdf") {
|
||||||
|
return []string{"Office", "Viewer"}
|
||||||
|
}
|
||||||
|
if strings.Contains(mimeType, "document") || strings.Contains(mimeType, "spreadsheet") ||
|
||||||
|
strings.Contains(mimeType, "presentation") || strings.Contains(mimeType, "msword") ||
|
||||||
|
strings.Contains(mimeType, "ms-excel") || strings.Contains(mimeType, "ms-powerpoint") ||
|
||||||
|
strings.Contains(mimeType, "opendocument") {
|
||||||
|
return []string{"Office"}
|
||||||
|
}
|
||||||
|
if strings.Contains(mimeType, "zip") || strings.Contains(mimeType, "tar") ||
|
||||||
|
strings.Contains(mimeType, "gzip") || strings.Contains(mimeType, "compress") {
|
||||||
|
return []string{"Archiving", "Utility"}
|
||||||
|
}
|
||||||
|
return []string{"Office", "Viewer"}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runOpen(target string) {
|
||||||
|
socketPath, err := server.FindSocket()
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("DMS socket not found: %v", err)
|
||||||
|
fmt.Println("DMS is not running. Please start DMS first.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := net.Dial("unix", socketPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("DMS socket connection failed: %v", err)
|
||||||
|
fmt.Println("DMS is not running. Please start DMS first.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
buf := make([]byte, 1)
|
||||||
|
for {
|
||||||
|
_, err := conn.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if buf[0] == '\n' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse file:// URIs to extract the actual file path
|
||||||
|
actualTarget := target
|
||||||
|
detectedMimeType := openMimeType
|
||||||
|
detectedCategories := openCategories
|
||||||
|
detectedRequestType := openRequestType
|
||||||
|
|
||||||
|
log.Infof("Processing target: %s", target)
|
||||||
|
|
||||||
|
if parsedURL, err := url.Parse(target); err == nil && parsedURL.Scheme == "file" {
|
||||||
|
// Extract file path from file:// URI and convert to absolute path
|
||||||
|
actualTarget = parsedURL.Path
|
||||||
|
if absPath, err := filepath.Abs(actualTarget); err == nil {
|
||||||
|
actualTarget = absPath
|
||||||
|
}
|
||||||
|
|
||||||
|
if detectedRequestType == "url" || detectedRequestType == "" {
|
||||||
|
detectedRequestType = "file"
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Detected file:// URI, extracted absolute path: %s", actualTarget)
|
||||||
|
|
||||||
|
// Auto-detect MIME type if not provided
|
||||||
|
if detectedMimeType == "" {
|
||||||
|
ext := filepath.Ext(actualTarget)
|
||||||
|
if ext != "" {
|
||||||
|
detectedMimeType = mime.TypeByExtension(ext)
|
||||||
|
log.Infof("Detected MIME type from extension %s: %s", ext, detectedMimeType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-detect categories based on MIME type if not provided
|
||||||
|
if len(detectedCategories) == 0 && detectedMimeType != "" {
|
||||||
|
detectedCategories = mimeTypeToCategories(detectedMimeType)
|
||||||
|
log.Infof("Detected categories from MIME type: %v", detectedCategories)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(target, "http://") || strings.HasPrefix(target, "https://") {
|
||||||
|
// Handle HTTP(S) URLs
|
||||||
|
if detectedRequestType == "" {
|
||||||
|
detectedRequestType = "url"
|
||||||
|
}
|
||||||
|
log.Infof("Detected HTTP(S) URL")
|
||||||
|
} else if _, err := os.Stat(target); err == nil {
|
||||||
|
// Handle local file paths directly (not file:// URIs)
|
||||||
|
// Convert to absolute path
|
||||||
|
if absPath, err := filepath.Abs(target); err == nil {
|
||||||
|
actualTarget = absPath
|
||||||
|
}
|
||||||
|
|
||||||
|
if detectedRequestType == "url" || detectedRequestType == "" {
|
||||||
|
detectedRequestType = "file"
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Detected local file path, converted to absolute: %s", actualTarget)
|
||||||
|
|
||||||
|
// Auto-detect MIME type if not provided
|
||||||
|
if detectedMimeType == "" {
|
||||||
|
ext := filepath.Ext(actualTarget)
|
||||||
|
if ext != "" {
|
||||||
|
detectedMimeType = mime.TypeByExtension(ext)
|
||||||
|
log.Infof("Detected MIME type from extension %s: %s", ext, detectedMimeType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-detect categories based on MIME type if not provided
|
||||||
|
if len(detectedCategories) == 0 && detectedMimeType != "" {
|
||||||
|
detectedCategories = mimeTypeToCategories(detectedMimeType)
|
||||||
|
log.Infof("Detected categories from MIME type: %v", detectedCategories)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"target": actualTarget,
|
||||||
|
}
|
||||||
|
|
||||||
|
if detectedMimeType != "" {
|
||||||
|
params["mimeType"] = detectedMimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(detectedCategories) > 0 {
|
||||||
|
params["categories"] = detectedCategories
|
||||||
|
}
|
||||||
|
|
||||||
|
if detectedRequestType != "" {
|
||||||
|
params["requestType"] = detectedRequestType
|
||||||
|
}
|
||||||
|
|
||||||
|
method := "apppicker.open"
|
||||||
|
if detectedMimeType == "" && len(detectedCategories) == 0 && (strings.HasPrefix(target, "http://") || strings.HasPrefix(target, "https://")) {
|
||||||
|
method = "browser.open"
|
||||||
|
params["url"] = target
|
||||||
|
}
|
||||||
|
|
||||||
|
req := models.Request{
|
||||||
|
ID: 1,
|
||||||
|
Method: method,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Sending request - Method: %s, Params: %+v", method, params)
|
||||||
|
|
||||||
|
if err := json.NewEncoder(conn).Encode(req); err != nil {
|
||||||
|
log.Fatalf("Failed to send request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Request sent successfully")
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ require (
|
|||||||
github.com/kevinburke/ssh_config v1.4.0 // indirect
|
github.com/kevinburke/ssh_config v1.4.0 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||||
github.com/pjbgf/sha1cd v0.5.0 // indirect
|
github.com/pjbgf/sha1cd v0.5.0 // indirect
|
||||||
|
github.com/sblinch/kdl-go v0.0.0-20250930225324-bf4099d4614a // indirect
|
||||||
github.com/sergi/go-diff v1.4.0 // indirect
|
github.com/sergi/go-diff v1.4.0 // indirect
|
||||||
github.com/stretchr/objx v0.5.3 // indirect
|
github.com/stretchr/objx v0.5.3 // indirect
|
||||||
golang.org/x/crypto v0.45.0 // indirect
|
golang.org/x/crypto v0.45.0 // indirect
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
|
|||||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/sblinch/kdl-go v0.0.0-20250930225324-bf4099d4614a h1:8ZZwZWIQKC0YVMyaCkbrdeI8faTjD1QBrRAAWc1TjMI=
|
||||||
|
github.com/sblinch/kdl-go v0.0.0-20250930225324-bf4099d4614a/go.mod h1:b3oNGuAKOQzhsCKmuLc/urEOPzgHj6fB8vl8bwTBh28=
|
||||||
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
|
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
|
||||||
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
|
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
|
||||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||||
|
|||||||
@@ -87,20 +87,22 @@ func (h *HyprlandProvider) categorizeByDispatcher(dispatcher string) string {
|
|||||||
|
|
||||||
func (h *HyprlandProvider) convertKeybind(kb *HyprlandKeyBinding, subcategory string) keybinds.Keybind {
|
func (h *HyprlandProvider) convertKeybind(kb *HyprlandKeyBinding, subcategory string) keybinds.Keybind {
|
||||||
key := h.formatKey(kb)
|
key := h.formatKey(kb)
|
||||||
|
rawAction := h.formatRawAction(kb.Dispatcher, kb.Params)
|
||||||
desc := kb.Comment
|
desc := kb.Comment
|
||||||
|
|
||||||
if desc == "" {
|
if desc == "" {
|
||||||
desc = h.generateDescription(kb.Dispatcher, kb.Params)
|
desc = rawAction
|
||||||
}
|
}
|
||||||
|
|
||||||
return keybinds.Keybind{
|
return keybinds.Keybind{
|
||||||
Key: key,
|
Key: key,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
|
Action: rawAction,
|
||||||
Subcategory: subcategory,
|
Subcategory: subcategory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HyprlandProvider) generateDescription(dispatcher, params string) string {
|
func (h *HyprlandProvider) formatRawAction(dispatcher, params string) string {
|
||||||
if params != "" {
|
if params != "" {
|
||||||
return dispatcher + " " + params
|
return dispatcher + " " + params
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ func (j *JSONFileProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
|||||||
var flatBinds []struct {
|
var flatBinds []struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
|
Action string `json:"action,omitempty"`
|
||||||
Category string `json:"cat,omitempty"`
|
Category string `json:"cat,omitempty"`
|
||||||
Subcategory string `json:"subcat,omitempty"`
|
Subcategory string `json:"subcat,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -100,6 +101,7 @@ func (j *JSONFileProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
|||||||
kb := keybinds.Keybind{
|
kb := keybinds.Keybind{
|
||||||
Key: bind.Key,
|
Key: bind.Key,
|
||||||
Description: bind.Description,
|
Description: bind.Description,
|
||||||
|
Action: bind.Action,
|
||||||
Subcategory: bind.Subcategory,
|
Subcategory: bind.Subcategory,
|
||||||
}
|
}
|
||||||
categorizedBinds[category] = append(categorizedBinds[category], kb)
|
categorizedBinds[category] = append(categorizedBinds[category], kb)
|
||||||
|
|||||||
@@ -84,19 +84,21 @@ func (m *MangoWCProvider) categorizeByCommand(command string) string {
|
|||||||
|
|
||||||
func (m *MangoWCProvider) convertKeybind(kb *MangoWCKeyBinding) keybinds.Keybind {
|
func (m *MangoWCProvider) convertKeybind(kb *MangoWCKeyBinding) keybinds.Keybind {
|
||||||
key := m.formatKey(kb)
|
key := m.formatKey(kb)
|
||||||
|
rawAction := m.formatRawAction(kb.Command, kb.Params)
|
||||||
desc := kb.Comment
|
desc := kb.Comment
|
||||||
|
|
||||||
if desc == "" {
|
if desc == "" {
|
||||||
desc = m.generateDescription(kb.Command, kb.Params)
|
desc = rawAction
|
||||||
}
|
}
|
||||||
|
|
||||||
return keybinds.Keybind{
|
return keybinds.Keybind{
|
||||||
Key: key,
|
Key: key,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
|
Action: rawAction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MangoWCProvider) generateDescription(command, params string) string {
|
func (m *MangoWCProvider) formatRawAction(command, params string) string {
|
||||||
if params != "" {
|
if params != "" {
|
||||||
return command + " " + params
|
return command + " " + params
|
||||||
}
|
}
|
||||||
|
|||||||
137
core/internal/keybinds/providers/niri.go
Normal file
137
core/internal/keybinds/providers/niri.go
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
package providers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NiriProvider struct {
|
||||||
|
configDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNiriProvider(configDir string) *NiriProvider {
|
||||||
|
if configDir == "" {
|
||||||
|
configDir = defaultNiriConfigDir()
|
||||||
|
}
|
||||||
|
return &NiriProvider{
|
||||||
|
configDir: configDir,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultNiriConfigDir() string {
|
||||||
|
configHome := os.Getenv("XDG_CONFIG_HOME")
|
||||||
|
if configHome != "" {
|
||||||
|
return filepath.Join(configHome, "niri")
|
||||||
|
}
|
||||||
|
|
||||||
|
home, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return filepath.Join(home, ".config", "niri")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) Name() string {
|
||||||
|
return "niri"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||||
|
section, err := ParseNiriKeys(n.configDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse niri config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
categorizedBinds := make(map[string][]keybinds.Keybind)
|
||||||
|
n.convertSection(section, "", categorizedBinds)
|
||||||
|
|
||||||
|
return &keybinds.CheatSheet{
|
||||||
|
Title: "Niri Keybinds",
|
||||||
|
Provider: n.Name(),
|
||||||
|
Binds: categorizedBinds,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) convertSection(section *NiriSection, subcategory string, categorizedBinds map[string][]keybinds.Keybind) {
|
||||||
|
currentSubcat := subcategory
|
||||||
|
if section.Name != "" {
|
||||||
|
currentSubcat = section.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kb := range section.Keybinds {
|
||||||
|
category := n.categorizeByAction(kb.Action)
|
||||||
|
bind := n.convertKeybind(&kb, currentSubcat)
|
||||||
|
categorizedBinds[category] = append(categorizedBinds[category], bind)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range section.Children {
|
||||||
|
n.convertSection(&child, currentSubcat, categorizedBinds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) categorizeByAction(action string) string {
|
||||||
|
switch {
|
||||||
|
case action == "next-window" || action == "previous-window":
|
||||||
|
return "Alt-Tab"
|
||||||
|
case strings.Contains(action, "screenshot"):
|
||||||
|
return "Screenshot"
|
||||||
|
case action == "show-hotkey-overlay" || action == "toggle-overview":
|
||||||
|
return "Overview"
|
||||||
|
case action == "quit" ||
|
||||||
|
action == "power-off-monitors" ||
|
||||||
|
action == "toggle-keyboard-shortcuts-inhibit" ||
|
||||||
|
strings.Contains(action, "dpms"):
|
||||||
|
return "System"
|
||||||
|
case action == "spawn":
|
||||||
|
return "Execute"
|
||||||
|
case strings.Contains(action, "workspace"):
|
||||||
|
return "Workspace"
|
||||||
|
case strings.HasPrefix(action, "focus-monitor") ||
|
||||||
|
strings.HasPrefix(action, "move-column-to-monitor") ||
|
||||||
|
strings.HasPrefix(action, "move-window-to-monitor"):
|
||||||
|
return "Monitor"
|
||||||
|
case strings.Contains(action, "window") ||
|
||||||
|
strings.Contains(action, "focus") ||
|
||||||
|
strings.Contains(action, "move") ||
|
||||||
|
strings.Contains(action, "swap") ||
|
||||||
|
strings.Contains(action, "resize") ||
|
||||||
|
strings.Contains(action, "column"):
|
||||||
|
return "Window"
|
||||||
|
default:
|
||||||
|
return "Other"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) convertKeybind(kb *NiriKeyBinding, subcategory string) keybinds.Keybind {
|
||||||
|
key := n.formatKey(kb)
|
||||||
|
desc := kb.Description
|
||||||
|
rawAction := n.formatRawAction(kb.Action, kb.Args)
|
||||||
|
|
||||||
|
if desc == "" {
|
||||||
|
desc = rawAction
|
||||||
|
}
|
||||||
|
|
||||||
|
return keybinds.Keybind{
|
||||||
|
Key: key,
|
||||||
|
Description: desc,
|
||||||
|
Action: rawAction,
|
||||||
|
Subcategory: subcategory,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) formatRawAction(action string, args []string) string {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return action
|
||||||
|
}
|
||||||
|
return action + " " + strings.Join(args, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NiriProvider) formatKey(kb *NiriKeyBinding) string {
|
||||||
|
parts := make([]string, 0, len(kb.Mods)+1)
|
||||||
|
parts = append(parts, kb.Mods...)
|
||||||
|
parts = append(parts, kb.Key)
|
||||||
|
return strings.Join(parts, "+")
|
||||||
|
}
|
||||||
229
core/internal/keybinds/providers/niri_parser.go
Normal file
229
core/internal/keybinds/providers/niri_parser.go
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
package providers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sblinch/kdl-go"
|
||||||
|
"github.com/sblinch/kdl-go/document"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NiriKeyBinding struct {
|
||||||
|
Mods []string
|
||||||
|
Key string
|
||||||
|
Action string
|
||||||
|
Args []string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
type NiriSection struct {
|
||||||
|
Name string
|
||||||
|
Keybinds []NiriKeyBinding
|
||||||
|
Children []NiriSection
|
||||||
|
}
|
||||||
|
|
||||||
|
type NiriParser struct {
|
||||||
|
configDir string
|
||||||
|
processedFiles map[string]bool
|
||||||
|
bindMap map[string]*NiriKeyBinding
|
||||||
|
bindOrder []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNiriParser(configDir string) *NiriParser {
|
||||||
|
return &NiriParser{
|
||||||
|
configDir: configDir,
|
||||||
|
processedFiles: make(map[string]bool),
|
||||||
|
bindMap: make(map[string]*NiriKeyBinding),
|
||||||
|
bindOrder: []string{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) Parse() (*NiriSection, error) {
|
||||||
|
configPath := filepath.Join(p.configDir, "config.kdl")
|
||||||
|
section, err := p.parseFile(configPath, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
section.Keybinds = p.finalizeBinds()
|
||||||
|
return section, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) finalizeBinds() []NiriKeyBinding {
|
||||||
|
binds := make([]NiriKeyBinding, 0, len(p.bindOrder))
|
||||||
|
for _, key := range p.bindOrder {
|
||||||
|
if kb, ok := p.bindMap[key]; ok {
|
||||||
|
binds = append(binds, *kb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return binds
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) addBind(kb *NiriKeyBinding) {
|
||||||
|
key := p.formatBindKey(kb)
|
||||||
|
if _, exists := p.bindMap[key]; !exists {
|
||||||
|
p.bindOrder = append(p.bindOrder, key)
|
||||||
|
}
|
||||||
|
p.bindMap[key] = kb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) formatBindKey(kb *NiriKeyBinding) string {
|
||||||
|
parts := make([]string, 0, len(kb.Mods)+1)
|
||||||
|
parts = append(parts, kb.Mods...)
|
||||||
|
parts = append(parts, kb.Key)
|
||||||
|
return strings.Join(parts, "+")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) parseFile(filePath, sectionName string) (*NiriSection, error) {
|
||||||
|
absPath, err := filepath.Abs(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to resolve path %s: %w", filePath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.processedFiles[absPath] {
|
||||||
|
return &NiriSection{Name: sectionName}, nil
|
||||||
|
}
|
||||||
|
p.processedFiles[absPath] = true
|
||||||
|
|
||||||
|
data, err := os.ReadFile(absPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to read %s: %w", absPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
doc, err := kdl.Parse(strings.NewReader(string(data)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse KDL in %s: %w", absPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section := &NiriSection{
|
||||||
|
Name: sectionName,
|
||||||
|
}
|
||||||
|
|
||||||
|
baseDir := filepath.Dir(absPath)
|
||||||
|
p.processNodes(doc.Nodes, section, baseDir)
|
||||||
|
|
||||||
|
return section, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) processNodes(nodes []*document.Node, section *NiriSection, baseDir string) {
|
||||||
|
for _, node := range nodes {
|
||||||
|
name := node.Name.String()
|
||||||
|
|
||||||
|
switch name {
|
||||||
|
case "include":
|
||||||
|
p.handleInclude(node, section, baseDir)
|
||||||
|
case "binds":
|
||||||
|
p.extractBinds(node, section, "")
|
||||||
|
case "recent-windows":
|
||||||
|
p.handleRecentWindows(node, section)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) handleInclude(node *document.Node, section *NiriSection, baseDir string) {
|
||||||
|
if len(node.Arguments) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
includePath := node.Arguments[0].String()
|
||||||
|
includePath = strings.Trim(includePath, "\"")
|
||||||
|
|
||||||
|
var fullPath string
|
||||||
|
if filepath.IsAbs(includePath) {
|
||||||
|
fullPath = includePath
|
||||||
|
} else {
|
||||||
|
fullPath = filepath.Join(baseDir, includePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
includedSection, err := p.parseFile(fullPath, "")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
section.Children = append(section.Children, includedSection.Children...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) handleRecentWindows(node *document.Node, section *NiriSection) {
|
||||||
|
if node.Children == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range node.Children {
|
||||||
|
if child.Name.String() != "binds" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.extractBinds(child, section, "Alt-Tab")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) extractBinds(node *document.Node, section *NiriSection, subcategory string) {
|
||||||
|
if node.Children == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range node.Children {
|
||||||
|
kb := p.parseKeybindNode(child, subcategory)
|
||||||
|
if kb == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p.addBind(kb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) parseKeybindNode(node *document.Node, subcategory string) *NiriKeyBinding {
|
||||||
|
keyCombo := node.Name.String()
|
||||||
|
if keyCombo == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mods, key := p.parseKeyCombo(keyCombo)
|
||||||
|
|
||||||
|
var action string
|
||||||
|
var args []string
|
||||||
|
|
||||||
|
if len(node.Children) > 0 {
|
||||||
|
actionNode := node.Children[0]
|
||||||
|
action = actionNode.Name.String()
|
||||||
|
for _, arg := range actionNode.Arguments {
|
||||||
|
args = append(args, strings.Trim(arg.String(), "\""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
description := ""
|
||||||
|
if node.Properties != nil {
|
||||||
|
if val, ok := node.Properties.Get("hotkey-overlay-title"); ok {
|
||||||
|
description = strings.Trim(val.String(), "\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &NiriKeyBinding{
|
||||||
|
Mods: mods,
|
||||||
|
Key: key,
|
||||||
|
Action: action,
|
||||||
|
Args: args,
|
||||||
|
Description: description,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *NiriParser) parseKeyCombo(combo string) ([]string, string) {
|
||||||
|
parts := strings.Split(combo, "+")
|
||||||
|
if len(parts) == 0 {
|
||||||
|
return nil, combo
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(parts) == 1 {
|
||||||
|
return nil, parts[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
mods := parts[:len(parts)-1]
|
||||||
|
key := parts[len(parts)-1]
|
||||||
|
|
||||||
|
return mods, key
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseNiriKeys(configDir string) (*NiriSection, error) {
|
||||||
|
parser := NewNiriParser(configDir)
|
||||||
|
return parser.Parse()
|
||||||
|
}
|
||||||
498
core/internal/keybinds/providers/niri_parser_test.go
Normal file
498
core/internal/keybinds/providers/niri_parser_test.go
Normal file
@@ -0,0 +1,498 @@
|
|||||||
|
package providers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNiriParseKeyCombo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
combo string
|
||||||
|
expectedMods []string
|
||||||
|
expectedKey string
|
||||||
|
}{
|
||||||
|
{"Mod+Q", []string{"Mod"}, "Q"},
|
||||||
|
{"Mod+Shift+F", []string{"Mod", "Shift"}, "F"},
|
||||||
|
{"Ctrl+Alt+Delete", []string{"Ctrl", "Alt"}, "Delete"},
|
||||||
|
{"Print", nil, "Print"},
|
||||||
|
{"XF86AudioMute", nil, "XF86AudioMute"},
|
||||||
|
{"Super+Tab", []string{"Super"}, "Tab"},
|
||||||
|
{"Mod+Shift+Ctrl+H", []string{"Mod", "Shift", "Ctrl"}, "H"},
|
||||||
|
}
|
||||||
|
|
||||||
|
parser := NewNiriParser("")
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.combo, func(t *testing.T) {
|
||||||
|
mods, key := parser.parseKeyCombo(tt.combo)
|
||||||
|
|
||||||
|
if len(mods) != len(tt.expectedMods) {
|
||||||
|
t.Errorf("Mods length = %d, want %d", len(mods), len(tt.expectedMods))
|
||||||
|
} else {
|
||||||
|
for i := range mods {
|
||||||
|
if mods[i] != tt.expectedMods[i] {
|
||||||
|
t.Errorf("Mods[%d] = %q, want %q", i, mods[i], tt.expectedMods[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if key != tt.expectedKey {
|
||||||
|
t.Errorf("Key = %q, want %q", key, tt.expectedKey)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseBasicBinds(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `binds {
|
||||||
|
Mod+Q { close-window; }
|
||||||
|
Mod+F { fullscreen-window; }
|
||||||
|
Mod+T hotkey-overlay-title="Open Terminal" { spawn "kitty"; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 3 {
|
||||||
|
t.Errorf("Expected 3 keybinds, got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
foundClose := false
|
||||||
|
foundFullscreen := false
|
||||||
|
foundTerminal := false
|
||||||
|
|
||||||
|
for _, kb := range section.Keybinds {
|
||||||
|
switch kb.Action {
|
||||||
|
case "close-window":
|
||||||
|
foundClose = true
|
||||||
|
if kb.Key != "Q" || len(kb.Mods) != 1 || kb.Mods[0] != "Mod" {
|
||||||
|
t.Errorf("close-window keybind mismatch: %+v", kb)
|
||||||
|
}
|
||||||
|
case "fullscreen-window":
|
||||||
|
foundFullscreen = true
|
||||||
|
case "spawn":
|
||||||
|
foundTerminal = true
|
||||||
|
if kb.Description != "Open Terminal" {
|
||||||
|
t.Errorf("spawn description = %q, want %q", kb.Description, "Open Terminal")
|
||||||
|
}
|
||||||
|
if len(kb.Args) != 1 || kb.Args[0] != "kitty" {
|
||||||
|
t.Errorf("spawn args = %v, want [kitty]", kb.Args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !foundClose {
|
||||||
|
t.Error("close-window keybind not found")
|
||||||
|
}
|
||||||
|
if !foundFullscreen {
|
||||||
|
t.Error("fullscreen-window keybind not found")
|
||||||
|
}
|
||||||
|
if !foundTerminal {
|
||||||
|
t.Error("spawn keybind not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseRecentWindows(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `recent-windows {
|
||||||
|
binds {
|
||||||
|
Alt+Tab { next-window scope="output"; }
|
||||||
|
Alt+Shift+Tab { previous-window scope="output"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 2 {
|
||||||
|
t.Errorf("Expected 2 keybinds from recent-windows, got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
foundNext := false
|
||||||
|
foundPrev := false
|
||||||
|
|
||||||
|
for _, kb := range section.Keybinds {
|
||||||
|
switch kb.Action {
|
||||||
|
case "next-window":
|
||||||
|
foundNext = true
|
||||||
|
case "previous-window":
|
||||||
|
foundPrev = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !foundNext {
|
||||||
|
t.Error("next-window keybind not found")
|
||||||
|
}
|
||||||
|
if !foundPrev {
|
||||||
|
t.Error("previous-window keybind not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseInclude(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
subDir := filepath.Join(tmpDir, "dms")
|
||||||
|
if err := os.MkdirAll(subDir, 0755); err != nil {
|
||||||
|
t.Fatalf("Failed to create subdir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mainConfig := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
includeConfig := filepath.Join(subDir, "binds.kdl")
|
||||||
|
|
||||||
|
mainContent := `binds {
|
||||||
|
Mod+Q { close-window; }
|
||||||
|
}
|
||||||
|
include "dms/binds.kdl"
|
||||||
|
`
|
||||||
|
includeContent := `binds {
|
||||||
|
Mod+T hotkey-overlay-title="Terminal" { spawn "kitty"; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
if err := os.WriteFile(mainConfig, []byte(mainContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write main config: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(includeConfig, []byte(includeContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write include config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 2 {
|
||||||
|
t.Errorf("Expected 2 keybinds (1 main + 1 include), got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseIncludeOverride(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
subDir := filepath.Join(tmpDir, "dms")
|
||||||
|
if err := os.MkdirAll(subDir, 0755); err != nil {
|
||||||
|
t.Fatalf("Failed to create subdir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mainConfig := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
includeConfig := filepath.Join(subDir, "binds.kdl")
|
||||||
|
|
||||||
|
mainContent := `binds {
|
||||||
|
Mod+T hotkey-overlay-title="Main Terminal" { spawn "alacritty"; }
|
||||||
|
}
|
||||||
|
include "dms/binds.kdl"
|
||||||
|
`
|
||||||
|
includeContent := `binds {
|
||||||
|
Mod+T hotkey-overlay-title="Override Terminal" { spawn "kitty"; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
if err := os.WriteFile(mainConfig, []byte(mainContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write main config: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(includeConfig, []byte(includeContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write include config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 1 {
|
||||||
|
t.Errorf("Expected 1 keybind (later overrides earlier), got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) > 0 {
|
||||||
|
kb := section.Keybinds[0]
|
||||||
|
if kb.Description != "Override Terminal" {
|
||||||
|
t.Errorf("Expected description 'Override Terminal' (from include), got %q", kb.Description)
|
||||||
|
}
|
||||||
|
if len(kb.Args) != 1 || kb.Args[0] != "kitty" {
|
||||||
|
t.Errorf("Expected args [kitty] (from include), got %v", kb.Args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseCircularInclude(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
|
mainConfig := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
otherConfig := filepath.Join(tmpDir, "other.kdl")
|
||||||
|
|
||||||
|
mainContent := `binds {
|
||||||
|
Mod+Q { close-window; }
|
||||||
|
}
|
||||||
|
include "other.kdl"
|
||||||
|
`
|
||||||
|
otherContent := `binds {
|
||||||
|
Mod+T { spawn "kitty"; }
|
||||||
|
}
|
||||||
|
include "config.kdl"
|
||||||
|
`
|
||||||
|
|
||||||
|
if err := os.WriteFile(mainConfig, []byte(mainContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write main config: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(otherConfig, []byte(otherContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write other config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed (should handle circular includes): %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 2 {
|
||||||
|
t.Errorf("Expected 2 keybinds (circular include handled), got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseMissingInclude(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `binds {
|
||||||
|
Mod+Q { close-window; }
|
||||||
|
}
|
||||||
|
include "nonexistent/file.kdl"
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed (should skip missing include): %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 1 {
|
||||||
|
t.Errorf("Expected 1 keybind (missing include skipped), got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseNoBinds(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `cursor {
|
||||||
|
xcursor-theme "Bibata"
|
||||||
|
xcursor-size 24
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
keyboard {
|
||||||
|
numlock
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 0 {
|
||||||
|
t.Errorf("Expected 0 keybinds, got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseErrors(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "nonexistent_directory",
|
||||||
|
path: "/nonexistent/path/that/does/not/exist",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
_, err := ParseNiriKeys(tt.path)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected error, got nil")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriBindOverrideBehavior(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `binds {
|
||||||
|
Mod+T hotkey-overlay-title="First" { spawn "first"; }
|
||||||
|
Mod+Q { close-window; }
|
||||||
|
Mod+T hotkey-overlay-title="Second" { spawn "second"; }
|
||||||
|
Mod+F { fullscreen-window; }
|
||||||
|
Mod+T hotkey-overlay-title="Third" { spawn "third"; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 3 {
|
||||||
|
t.Fatalf("Expected 3 unique keybinds, got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
var modT *NiriKeyBinding
|
||||||
|
for i := range section.Keybinds {
|
||||||
|
kb := §ion.Keybinds[i]
|
||||||
|
if len(kb.Mods) == 1 && kb.Mods[0] == "Mod" && kb.Key == "T" {
|
||||||
|
modT = kb
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if modT == nil {
|
||||||
|
t.Fatal("Mod+T keybind not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if modT.Description != "Third" {
|
||||||
|
t.Errorf("Mod+T description = %q, want 'Third' (last definition wins)", modT.Description)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(modT.Args) != 1 || modT.Args[0] != "third" {
|
||||||
|
t.Errorf("Mod+T args = %v, want [third] (last definition wins)", modT.Args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriBindOverrideWithIncludes(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
subDir := filepath.Join(tmpDir, "custom")
|
||||||
|
if err := os.MkdirAll(subDir, 0755); err != nil {
|
||||||
|
t.Fatalf("Failed to create subdir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mainConfig := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
includeConfig := filepath.Join(subDir, "overrides.kdl")
|
||||||
|
|
||||||
|
mainContent := `binds {
|
||||||
|
Mod+1 { focus-workspace 1; }
|
||||||
|
Mod+2 { focus-workspace 2; }
|
||||||
|
Mod+T hotkey-overlay-title="Default Terminal" { spawn "xterm"; }
|
||||||
|
}
|
||||||
|
include "custom/overrides.kdl"
|
||||||
|
binds {
|
||||||
|
Mod+3 { focus-workspace 3; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
includeContent := `binds {
|
||||||
|
Mod+T hotkey-overlay-title="Custom Terminal" { spawn "kitty"; }
|
||||||
|
Mod+2 { focus-workspace 22; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
if err := os.WriteFile(mainConfig, []byte(mainContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write main config: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(includeConfig, []byte(includeContent), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write include config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 4 {
|
||||||
|
t.Errorf("Expected 4 unique keybinds, got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
bindMap := make(map[string]*NiriKeyBinding)
|
||||||
|
for i := range section.Keybinds {
|
||||||
|
kb := §ion.Keybinds[i]
|
||||||
|
key := ""
|
||||||
|
for _, m := range kb.Mods {
|
||||||
|
key += m + "+"
|
||||||
|
}
|
||||||
|
key += kb.Key
|
||||||
|
bindMap[key] = kb
|
||||||
|
}
|
||||||
|
|
||||||
|
if kb, ok := bindMap["Mod+T"]; ok {
|
||||||
|
if kb.Description != "Custom Terminal" {
|
||||||
|
t.Errorf("Mod+T should be overridden by include, got description %q", kb.Description)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Error("Mod+T not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if kb, ok := bindMap["Mod+2"]; ok {
|
||||||
|
if len(kb.Args) != 1 || kb.Args[0] != "22" {
|
||||||
|
t.Errorf("Mod+2 should be overridden by include with workspace 22, got args %v", kb.Args)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Error("Mod+2 not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := bindMap["Mod+1"]; !ok {
|
||||||
|
t.Error("Mod+1 should exist (not overridden)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := bindMap["Mod+3"]; !ok {
|
||||||
|
t.Error("Mod+3 should exist (added after include)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriParseMultipleArgs(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `binds {
|
||||||
|
Mod+Space hotkey-overlay-title="Application Launcher" {
|
||||||
|
spawn "dms" "ipc" "call" "spotlight" "toggle";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
section, err := ParseNiriKeys(tmpDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseNiriKeys failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(section.Keybinds) != 1 {
|
||||||
|
t.Fatalf("Expected 1 keybind, got %d", len(section.Keybinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
kb := section.Keybinds[0]
|
||||||
|
if len(kb.Args) != 5 {
|
||||||
|
t.Errorf("Expected 5 args, got %d: %v", len(kb.Args), kb.Args)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedArgs := []string{"dms", "ipc", "call", "spotlight", "toggle"}
|
||||||
|
for i, arg := range expectedArgs {
|
||||||
|
if i < len(kb.Args) && kb.Args[i] != arg {
|
||||||
|
t.Errorf("Args[%d] = %q, want %q", i, kb.Args[i], arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
261
core/internal/keybinds/providers/niri_test.go
Normal file
261
core/internal/keybinds/providers/niri_test.go
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
package providers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNiriProviderName(t *testing.T) {
|
||||||
|
provider := NewNiriProvider("")
|
||||||
|
if provider.Name() != "niri" {
|
||||||
|
t.Errorf("Name() = %q, want %q", provider.Name(), "niri")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriProviderGetCheatSheet(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `binds {
|
||||||
|
Mod+Q { close-window; }
|
||||||
|
Mod+F { fullscreen-window; }
|
||||||
|
Mod+T hotkey-overlay-title="Open Terminal" { spawn "kitty"; }
|
||||||
|
Mod+1 { focus-workspace 1; }
|
||||||
|
Mod+Shift+1 { move-column-to-workspace 1; }
|
||||||
|
Print { screenshot; }
|
||||||
|
Mod+Shift+E { quit; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
provider := NewNiriProvider(tmpDir)
|
||||||
|
cheatSheet, err := provider.GetCheatSheet()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetCheatSheet failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cheatSheet.Title != "Niri Keybinds" {
|
||||||
|
t.Errorf("Title = %q, want %q", cheatSheet.Title, "Niri Keybinds")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cheatSheet.Provider != "niri" {
|
||||||
|
t.Errorf("Provider = %q, want %q", cheatSheet.Provider, "niri")
|
||||||
|
}
|
||||||
|
|
||||||
|
windowBinds := cheatSheet.Binds["Window"]
|
||||||
|
if len(windowBinds) < 2 {
|
||||||
|
t.Errorf("Expected at least 2 Window binds, got %d", len(windowBinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
execBinds := cheatSheet.Binds["Execute"]
|
||||||
|
if len(execBinds) < 1 {
|
||||||
|
t.Errorf("Expected at least 1 Execute bind, got %d", len(execBinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
workspaceBinds := cheatSheet.Binds["Workspace"]
|
||||||
|
if len(workspaceBinds) < 2 {
|
||||||
|
t.Errorf("Expected at least 2 Workspace binds, got %d", len(workspaceBinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
screenshotBinds := cheatSheet.Binds["Screenshot"]
|
||||||
|
if len(screenshotBinds) < 1 {
|
||||||
|
t.Errorf("Expected at least 1 Screenshot bind, got %d", len(screenshotBinds))
|
||||||
|
}
|
||||||
|
|
||||||
|
systemBinds := cheatSheet.Binds["System"]
|
||||||
|
if len(systemBinds) < 1 {
|
||||||
|
t.Errorf("Expected at least 1 System bind, got %d", len(systemBinds))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriCategorizeByAction(t *testing.T) {
|
||||||
|
provider := NewNiriProvider("")
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
action string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{"focus-workspace", "Workspace"},
|
||||||
|
{"focus-workspace-up", "Workspace"},
|
||||||
|
{"move-column-to-workspace", "Workspace"},
|
||||||
|
{"focus-monitor-left", "Monitor"},
|
||||||
|
{"move-column-to-monitor-right", "Monitor"},
|
||||||
|
{"close-window", "Window"},
|
||||||
|
{"fullscreen-window", "Window"},
|
||||||
|
{"maximize-column", "Window"},
|
||||||
|
{"toggle-window-floating", "Window"},
|
||||||
|
{"focus-column-left", "Window"},
|
||||||
|
{"move-column-right", "Window"},
|
||||||
|
{"spawn", "Execute"},
|
||||||
|
{"quit", "System"},
|
||||||
|
{"power-off-monitors", "System"},
|
||||||
|
{"screenshot", "Screenshot"},
|
||||||
|
{"screenshot-window", "Screenshot"},
|
||||||
|
{"toggle-overview", "Overview"},
|
||||||
|
{"show-hotkey-overlay", "Overview"},
|
||||||
|
{"next-window", "Alt-Tab"},
|
||||||
|
{"previous-window", "Alt-Tab"},
|
||||||
|
{"unknown-action", "Other"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.action, func(t *testing.T) {
|
||||||
|
result := provider.categorizeByAction(tt.action)
|
||||||
|
if result != tt.expected {
|
||||||
|
t.Errorf("categorizeByAction(%q) = %q, want %q", tt.action, result, tt.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriFormatRawAction(t *testing.T) {
|
||||||
|
provider := NewNiriProvider("")
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
action string
|
||||||
|
args []string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{"spawn", []string{"kitty"}, "spawn kitty"},
|
||||||
|
{"spawn", []string{"dms", "ipc", "call"}, "spawn dms ipc call"},
|
||||||
|
{"close-window", nil, "close-window"},
|
||||||
|
{"fullscreen-window", nil, "fullscreen-window"},
|
||||||
|
{"focus-workspace", []string{"1"}, "focus-workspace 1"},
|
||||||
|
{"move-column-to-workspace", []string{"5"}, "move-column-to-workspace 5"},
|
||||||
|
{"set-column-width", []string{"+10%"}, "set-column-width +10%"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.action, func(t *testing.T) {
|
||||||
|
result := provider.formatRawAction(tt.action, tt.args)
|
||||||
|
if result != tt.expected {
|
||||||
|
t.Errorf("formatRawAction(%q, %v) = %q, want %q", tt.action, tt.args, result, tt.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriFormatKey(t *testing.T) {
|
||||||
|
provider := NewNiriProvider("")
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
mods []string
|
||||||
|
key string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{[]string{"Mod"}, "Q", "Mod+Q"},
|
||||||
|
{[]string{"Mod", "Shift"}, "F", "Mod+Shift+F"},
|
||||||
|
{[]string{"Ctrl", "Alt"}, "Delete", "Ctrl+Alt+Delete"},
|
||||||
|
{nil, "Print", "Print"},
|
||||||
|
{[]string{}, "XF86AudioMute", "XF86AudioMute"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.expected, func(t *testing.T) {
|
||||||
|
kb := &NiriKeyBinding{
|
||||||
|
Mods: tt.mods,
|
||||||
|
Key: tt.key,
|
||||||
|
}
|
||||||
|
result := provider.formatKey(kb)
|
||||||
|
if result != tt.expected {
|
||||||
|
t.Errorf("formatKey(%v) = %q, want %q", kb, result, tt.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriDefaultConfigDir(t *testing.T) {
|
||||||
|
originalXDG := os.Getenv("XDG_CONFIG_HOME")
|
||||||
|
defer os.Setenv("XDG_CONFIG_HOME", originalXDG)
|
||||||
|
|
||||||
|
os.Setenv("XDG_CONFIG_HOME", "/custom/config")
|
||||||
|
dir := defaultNiriConfigDir()
|
||||||
|
if dir != "/custom/config/niri" {
|
||||||
|
t.Errorf("With XDG_CONFIG_HOME set, got %q, want %q", dir, "/custom/config/niri")
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Unsetenv("XDG_CONFIG_HOME")
|
||||||
|
dir = defaultNiriConfigDir()
|
||||||
|
home, _ := os.UserHomeDir()
|
||||||
|
expected := filepath.Join(home, ".config", "niri")
|
||||||
|
if dir != expected {
|
||||||
|
t.Errorf("Without XDG_CONFIG_HOME, got %q, want %q", dir, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNiriProviderWithRealWorldConfig(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
configFile := filepath.Join(tmpDir, "config.kdl")
|
||||||
|
|
||||||
|
content := `binds {
|
||||||
|
Mod+Shift+Ctrl+D { debug-toggle-damage; }
|
||||||
|
Super+D { spawn "niri" "msg" "action" "toggle-overview"; }
|
||||||
|
Super+Tab repeat=false { toggle-overview; }
|
||||||
|
Mod+Shift+Slash { show-hotkey-overlay; }
|
||||||
|
|
||||||
|
Mod+T hotkey-overlay-title="Open Terminal" { spawn "kitty"; }
|
||||||
|
Mod+Space hotkey-overlay-title="Application Launcher" {
|
||||||
|
spawn "dms" "ipc" "call" "spotlight" "toggle";
|
||||||
|
}
|
||||||
|
|
||||||
|
XF86AudioRaiseVolume allow-when-locked=true {
|
||||||
|
spawn "dms" "ipc" "call" "audio" "increment" "3";
|
||||||
|
}
|
||||||
|
XF86AudioLowerVolume allow-when-locked=true {
|
||||||
|
spawn "dms" "ipc" "call" "audio" "decrement" "3";
|
||||||
|
}
|
||||||
|
|
||||||
|
Mod+Q repeat=false { close-window; }
|
||||||
|
Mod+F { maximize-column; }
|
||||||
|
Mod+Shift+F { fullscreen-window; }
|
||||||
|
|
||||||
|
Mod+Left { focus-column-left; }
|
||||||
|
Mod+Down { focus-window-down; }
|
||||||
|
Mod+Up { focus-window-up; }
|
||||||
|
Mod+Right { focus-column-right; }
|
||||||
|
|
||||||
|
Mod+1 { focus-workspace 1; }
|
||||||
|
Mod+2 { focus-workspace 2; }
|
||||||
|
Mod+Shift+1 { move-column-to-workspace 1; }
|
||||||
|
Mod+Shift+2 { move-column-to-workspace 2; }
|
||||||
|
|
||||||
|
Print { screenshot; }
|
||||||
|
Ctrl+Print { screenshot-screen; }
|
||||||
|
Alt+Print { screenshot-window; }
|
||||||
|
|
||||||
|
Mod+Shift+E { quit; }
|
||||||
|
}
|
||||||
|
|
||||||
|
recent-windows {
|
||||||
|
binds {
|
||||||
|
Alt+Tab { next-window scope="output"; }
|
||||||
|
Alt+Shift+Tab { previous-window scope="output"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(configFile, []byte(content), 0644); err != nil {
|
||||||
|
t.Fatalf("Failed to write test config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
provider := NewNiriProvider(tmpDir)
|
||||||
|
cheatSheet, err := provider.GetCheatSheet()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetCheatSheet failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
totalBinds := 0
|
||||||
|
for _, binds := range cheatSheet.Binds {
|
||||||
|
totalBinds += len(binds)
|
||||||
|
}
|
||||||
|
|
||||||
|
if totalBinds < 20 {
|
||||||
|
t.Errorf("Expected at least 20 keybinds, got %d", totalBinds)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cheatSheet.Binds["Alt-Tab"]) < 2 {
|
||||||
|
t.Errorf("Expected at least 2 Alt-Tab binds, got %d", len(cheatSheet.Binds["Alt-Tab"]))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,6 +99,7 @@ func (s *SwayProvider) convertKeybind(kb *SwayKeyBinding, subcategory string) ke
|
|||||||
return keybinds.Keybind{
|
return keybinds.Keybind{
|
||||||
Key: key,
|
Key: key,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
|
Action: kb.Command,
|
||||||
Subcategory: subcategory,
|
Subcategory: subcategory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package keybinds
|
|||||||
type Keybind struct {
|
type Keybind struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
|
Action string `json:"action,omitempty"`
|
||||||
Subcategory string `json:"subcat,omitempty"`
|
Subcategory string `json:"subcat,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
64
core/internal/server/apppicker/handlers.go
Normal file
64
core/internal/server/apppicker/handlers.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package apppicker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
Params map[string]interface{} `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleRequest(conn net.Conn, req Request, manager *Manager) {
|
||||||
|
switch req.Method {
|
||||||
|
case "apppicker.open", "browser.open":
|
||||||
|
handleOpen(conn, req, manager)
|
||||||
|
default:
|
||||||
|
models.RespondError(conn, req.ID, "unknown method")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleOpen(conn net.Conn, req Request, manager *Manager) {
|
||||||
|
log.Infof("AppPicker: Received %s request with params: %+v", req.Method, req.Params)
|
||||||
|
|
||||||
|
target, ok := req.Params["target"].(string)
|
||||||
|
if !ok {
|
||||||
|
target, ok = req.Params["url"].(string)
|
||||||
|
if !ok {
|
||||||
|
log.Warnf("AppPicker: Invalid target parameter in request")
|
||||||
|
models.RespondError(conn, req.ID, "invalid target parameter")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event := OpenEvent{
|
||||||
|
Target: target,
|
||||||
|
RequestType: "url",
|
||||||
|
}
|
||||||
|
|
||||||
|
if mimeType, ok := req.Params["mimeType"].(string); ok {
|
||||||
|
event.MimeType = mimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
if categories, ok := req.Params["categories"].([]interface{}); ok {
|
||||||
|
event.Categories = make([]string, 0, len(categories))
|
||||||
|
for _, cat := range categories {
|
||||||
|
if catStr, ok := cat.(string); ok {
|
||||||
|
event.Categories = append(event.Categories, catStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if requestType, ok := req.Params["requestType"].(string); ok {
|
||||||
|
event.RequestType = requestType
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("AppPicker: Broadcasting event: %+v", event)
|
||||||
|
manager.RequestOpen(event)
|
||||||
|
models.Respond(conn, req.ID, "ok")
|
||||||
|
log.Infof("AppPicker: Request handled successfully")
|
||||||
|
}
|
||||||
48
core/internal/server/apppicker/manager.go
Normal file
48
core/internal/server/apppicker/manager.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package apppicker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/pkg/syncmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Manager struct {
|
||||||
|
subscribers syncmap.Map[string, chan OpenEvent]
|
||||||
|
closeOnce sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewManager() *Manager {
|
||||||
|
return &Manager{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Subscribe(id string) chan OpenEvent {
|
||||||
|
ch := make(chan OpenEvent, 16)
|
||||||
|
m.subscribers.Store(id, ch)
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Unsubscribe(id string) {
|
||||||
|
if val, ok := m.subscribers.LoadAndDelete(id); ok {
|
||||||
|
close(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) RequestOpen(event OpenEvent) {
|
||||||
|
m.subscribers.Range(func(key string, ch chan OpenEvent) bool {
|
||||||
|
select {
|
||||||
|
case ch <- event:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Close() {
|
||||||
|
m.closeOnce.Do(func() {
|
||||||
|
m.subscribers.Range(func(key string, ch chan OpenEvent) bool {
|
||||||
|
close(ch)
|
||||||
|
m.subscribers.Delete(key)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
8
core/internal/server/apppicker/models.go
Normal file
8
core/internal/server/apppicker/models.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package apppicker
|
||||||
|
|
||||||
|
type OpenEvent struct {
|
||||||
|
Target string `json:"target"`
|
||||||
|
MimeType string `json:"mimeType,omitempty"`
|
||||||
|
Categories []string `json:"categories,omitempty"`
|
||||||
|
RequestType string `json:"requestType"`
|
||||||
|
}
|
||||||
28
core/internal/server/browser/handlers.go
Normal file
28
core/internal/server/browser/handlers.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package browser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
Params map[string]interface{} `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleRequest(conn net.Conn, req Request, manager *Manager) {
|
||||||
|
switch req.Method {
|
||||||
|
case "browser.open":
|
||||||
|
url, ok := req.Params["url"].(string)
|
||||||
|
if !ok {
|
||||||
|
models.RespondError(conn, req.ID, "invalid url parameter")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
manager.RequestOpen(url)
|
||||||
|
models.Respond(conn, req.ID, "ok")
|
||||||
|
default:
|
||||||
|
models.RespondError(conn, req.ID, "unknown method")
|
||||||
|
}
|
||||||
|
}
|
||||||
49
core/internal/server/browser/manager.go
Normal file
49
core/internal/server/browser/manager.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package browser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/pkg/syncmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Manager struct {
|
||||||
|
subscribers syncmap.Map[string, chan OpenEvent]
|
||||||
|
closeOnce sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewManager() *Manager {
|
||||||
|
return &Manager{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Subscribe(id string) chan OpenEvent {
|
||||||
|
ch := make(chan OpenEvent, 16)
|
||||||
|
m.subscribers.Store(id, ch)
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Unsubscribe(id string) {
|
||||||
|
if val, ok := m.subscribers.LoadAndDelete(id); ok {
|
||||||
|
close(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) RequestOpen(url string) {
|
||||||
|
event := OpenEvent{URL: url}
|
||||||
|
m.subscribers.Range(func(key string, ch chan OpenEvent) bool {
|
||||||
|
select {
|
||||||
|
case ch <- event:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Close() {
|
||||||
|
m.closeOnce.Do(func() {
|
||||||
|
m.subscribers.Range(func(key string, ch chan OpenEvent) bool {
|
||||||
|
close(ch)
|
||||||
|
m.subscribers.Delete(key)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
5
core/internal/server/browser/models.go
Normal file
5
core/internal/server/browser/models.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package browser
|
||||||
|
|
||||||
|
type OpenEvent struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/apppicker"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/bluez"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/bluez"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/brightness"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/brightness"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/cups"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/cups"
|
||||||
@@ -96,6 +97,20 @@ func RouteRequest(conn net.Conn, req models.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(req.Method, "browser.") || strings.HasPrefix(req.Method, "apppicker.") {
|
||||||
|
if appPickerManager == nil {
|
||||||
|
models.RespondError(conn, req.ID, "apppicker manager not initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
appPickerReq := apppicker.Request{
|
||||||
|
ID: req.ID,
|
||||||
|
Method: req.Method,
|
||||||
|
Params: req.Params,
|
||||||
|
}
|
||||||
|
apppicker.HandleRequest(conn, appPickerReq, appPickerManager)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(req.Method, "cups.") {
|
if strings.HasPrefix(req.Method, "cups.") {
|
||||||
if cupsManager == nil {
|
if cupsManager == nil {
|
||||||
models.RespondError(conn, req.ID, "CUPS manager not initialized")
|
models.RespondError(conn, req.ID, "CUPS manager not initialized")
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
|
||||||
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/apppicker"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/bluez"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/bluez"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/brightness"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/brightness"
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/cups"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/server/cups"
|
||||||
@@ -55,6 +56,7 @@ var loginctlManager *loginctl.Manager
|
|||||||
var freedesktopManager *freedesktop.Manager
|
var freedesktopManager *freedesktop.Manager
|
||||||
var waylandManager *wayland.Manager
|
var waylandManager *wayland.Manager
|
||||||
var bluezManager *bluez.Manager
|
var bluezManager *bluez.Manager
|
||||||
|
var appPickerManager *apppicker.Manager
|
||||||
var cupsManager *cups.Manager
|
var cupsManager *cups.Manager
|
||||||
var dwlManager *dwl.Manager
|
var dwlManager *dwl.Manager
|
||||||
var extWorkspaceManager *extworkspace.Manager
|
var extWorkspaceManager *extworkspace.Manager
|
||||||
@@ -88,6 +90,21 @@ func GetSocketPath() string {
|
|||||||
return filepath.Join(getSocketDir(), fmt.Sprintf("danklinux-%d.sock", os.Getpid()))
|
return filepath.Join(getSocketDir(), fmt.Sprintf("danklinux-%d.sock", os.Getpid()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindSocket() (string, error) {
|
||||||
|
dir := getSocketDir()
|
||||||
|
entries, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
if strings.HasPrefix(entry.Name(), "danklinux-") && strings.HasSuffix(entry.Name(), ".sock") {
|
||||||
|
return filepath.Join(dir, entry.Name()), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("no dms socket found")
|
||||||
|
}
|
||||||
|
|
||||||
func cleanupStaleSockets() {
|
func cleanupStaleSockets() {
|
||||||
dir := getSocketDir()
|
dir := getSocketDir()
|
||||||
entries, err := os.ReadDir(dir)
|
entries, err := os.ReadDir(dir)
|
||||||
@@ -201,6 +218,13 @@ func InitializeBluezManager() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitializeAppPickerManager() error {
|
||||||
|
manager := apppicker.NewManager()
|
||||||
|
appPickerManager = manager
|
||||||
|
log.Info("AppPicker manager initialized")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func InitializeCupsManager() error {
|
func InitializeCupsManager() error {
|
||||||
manager, err := cups.NewManager()
|
manager, err := cups.NewManager()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -357,6 +381,10 @@ func getCapabilities() Capabilities {
|
|||||||
caps = append(caps, "bluetooth")
|
caps = append(caps, "bluetooth")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if appPickerManager != nil {
|
||||||
|
caps = append(caps, "browser")
|
||||||
|
}
|
||||||
|
|
||||||
if cupsManager != nil {
|
if cupsManager != nil {
|
||||||
caps = append(caps, "cups")
|
caps = append(caps, "cups")
|
||||||
}
|
}
|
||||||
@@ -407,6 +435,10 @@ func getServerInfo() ServerInfo {
|
|||||||
caps = append(caps, "bluetooth")
|
caps = append(caps, "bluetooth")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if appPickerManager != nil {
|
||||||
|
caps = append(caps, "browser")
|
||||||
|
}
|
||||||
|
|
||||||
if cupsManager != nil {
|
if cupsManager != nil {
|
||||||
caps = append(caps, "cups")
|
caps = append(caps, "cups")
|
||||||
}
|
}
|
||||||
@@ -724,6 +756,31 @@ func handleSubscribe(conn net.Conn, req models.Request) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shouldSubscribe("browser") && appPickerManager != nil {
|
||||||
|
wg.Add(1)
|
||||||
|
appPickerChan := appPickerManager.Subscribe(clientID + "-browser")
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
defer appPickerManager.Unsubscribe(clientID + "-browser")
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case event, ok := <-appPickerChan:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case eventChan <- ServiceEvent{Service: "browser.open_requested", Data: event}:
|
||||||
|
case <-stopChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-stopChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if shouldSubscribe("cups") {
|
if shouldSubscribe("cups") {
|
||||||
cupsSubscribers.Store(clientID+"-cups", true)
|
cupsSubscribers.Store(clientID+"-cups", true)
|
||||||
count := cupsSubscriberCount.Add(1)
|
count := cupsSubscriberCount.Add(1)
|
||||||
@@ -1018,6 +1075,9 @@ func cleanupManagers() {
|
|||||||
if bluezManager != nil {
|
if bluezManager != nil {
|
||||||
bluezManager.Close()
|
bluezManager.Close()
|
||||||
}
|
}
|
||||||
|
if appPickerManager != nil {
|
||||||
|
appPickerManager.Close()
|
||||||
|
}
|
||||||
if cupsManager != nil {
|
if cupsManager != nil {
|
||||||
cupsManager.Close()
|
cupsManager.Close()
|
||||||
}
|
}
|
||||||
@@ -1256,6 +1316,10 @@ func Start(printDocs bool) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := InitializeAppPickerManager(); err != nil {
|
||||||
|
log.Debugf("AppPicker manager unavailable: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := InitializeDwlManager(); err != nil {
|
if err := InitializeDwlManager(); err != nil {
|
||||||
log.Debugf("DWL manager unavailable: %v", err)
|
log.Debugf("DWL manager unavailable: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
pname = "dmsCli";
|
pname = "dmsCli";
|
||||||
src = ./core;
|
src = ./core;
|
||||||
vendorHash = "sha256-XBPJVgncI98VFch3wwkq1/m5Jm7DrV4oGS2p1bPJRag=";
|
vendorHash = "sha256-wruiGaQaixqYst/zkdxjOhjKCbj6GvSaM3IdtNTeo50=";
|
||||||
|
|
||||||
subPackages = ["cmd/dms"];
|
subPackages = ["cmd/dms"];
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ Singleton {
|
|||||||
property var enabledGpuPciIds: []
|
property var enabledGpuPciIds: []
|
||||||
|
|
||||||
property string wifiDeviceOverride: ""
|
property string wifiDeviceOverride: ""
|
||||||
|
property bool weatherHourlyDetailed: true
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (!isGreeterMode) {
|
if (!isGreeterMode) {
|
||||||
@@ -157,6 +158,7 @@ Singleton {
|
|||||||
nonNvidiaGpuTempEnabled = settings.nonNvidiaGpuTempEnabled !== undefined ? settings.nonNvidiaGpuTempEnabled : false;
|
nonNvidiaGpuTempEnabled = settings.nonNvidiaGpuTempEnabled !== undefined ? settings.nonNvidiaGpuTempEnabled : false;
|
||||||
enabledGpuPciIds = settings.enabledGpuPciIds !== undefined ? settings.enabledGpuPciIds : [];
|
enabledGpuPciIds = settings.enabledGpuPciIds !== undefined ? settings.enabledGpuPciIds : [];
|
||||||
wifiDeviceOverride = settings.wifiDeviceOverride !== undefined ? settings.wifiDeviceOverride : "";
|
wifiDeviceOverride = settings.wifiDeviceOverride !== undefined ? settings.wifiDeviceOverride : "";
|
||||||
|
weatherHourlyDetailed = settings.weatherHourlyDetailed !== undefined ? settings.weatherHourlyDetailed : true;
|
||||||
wallpaperCyclingEnabled = settings.wallpaperCyclingEnabled !== undefined ? settings.wallpaperCyclingEnabled : false;
|
wallpaperCyclingEnabled = settings.wallpaperCyclingEnabled !== undefined ? settings.wallpaperCyclingEnabled : false;
|
||||||
wallpaperCyclingMode = settings.wallpaperCyclingMode !== undefined ? settings.wallpaperCyclingMode : "interval";
|
wallpaperCyclingMode = settings.wallpaperCyclingMode !== undefined ? settings.wallpaperCyclingMode : "interval";
|
||||||
wallpaperCyclingInterval = settings.wallpaperCyclingInterval !== undefined ? settings.wallpaperCyclingInterval : 300;
|
wallpaperCyclingInterval = settings.wallpaperCyclingInterval !== undefined ? settings.wallpaperCyclingInterval : 300;
|
||||||
@@ -226,6 +228,7 @@ Singleton {
|
|||||||
"nonNvidiaGpuTempEnabled": nonNvidiaGpuTempEnabled,
|
"nonNvidiaGpuTempEnabled": nonNvidiaGpuTempEnabled,
|
||||||
"enabledGpuPciIds": enabledGpuPciIds,
|
"enabledGpuPciIds": enabledGpuPciIds,
|
||||||
"wifiDeviceOverride": wifiDeviceOverride,
|
"wifiDeviceOverride": wifiDeviceOverride,
|
||||||
|
"weatherHourlyDetailed": weatherHourlyDetailed,
|
||||||
"wallpaperCyclingEnabled": wallpaperCyclingEnabled,
|
"wallpaperCyclingEnabled": wallpaperCyclingEnabled,
|
||||||
"wallpaperCyclingMode": wallpaperCyclingMode,
|
"wallpaperCyclingMode": wallpaperCyclingMode,
|
||||||
"wallpaperCyclingInterval": wallpaperCyclingInterval,
|
"wallpaperCyclingInterval": wallpaperCyclingInterval,
|
||||||
@@ -290,7 +293,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cleanupUnusedKeys() {
|
function cleanupUnusedKeys() {
|
||||||
const validKeys = ["isLightMode", "wallpaperPath", "perMonitorWallpaper", "monitorWallpapers", "perModeWallpaper", "wallpaperPathLight", "wallpaperPathDark", "monitorWallpapersLight", "monitorWallpapersDark", "doNotDisturb", "nightModeEnabled", "nightModeTemperature", "nightModeHighTemperature", "nightModeAutoEnabled", "nightModeAutoMode", "nightModeStartHour", "nightModeStartMinute", "nightModeEndHour", "nightModeEndMinute", "latitude", "longitude", "nightModeUseIPLocation", "nightModeLocationProvider", "pinnedApps", "hiddenTrayIds", "selectedGpuIndex", "nvidiaGpuTempEnabled", "nonNvidiaGpuTempEnabled", "enabledGpuPciIds", "wifiDeviceOverride", "wallpaperCyclingEnabled", "wallpaperCyclingMode", "wallpaperCyclingInterval", "wallpaperCyclingTime", "monitorCyclingSettings", "lastBrightnessDevice", "brightnessExponentialDevices", "brightnessUserSetValues", "brightnessExponentValues", "launchPrefix", "wallpaperTransition", "includedTransitions", "recentColors", "showThirdPartyPlugins", "configVersion"];
|
const validKeys = ["isLightMode", "wallpaperPath", "perMonitorWallpaper", "monitorWallpapers", "perModeWallpaper", "wallpaperPathLight", "wallpaperPathDark", "monitorWallpapersLight", "monitorWallpapersDark", "doNotDisturb", "nightModeEnabled", "nightModeTemperature", "nightModeHighTemperature", "nightModeAutoEnabled", "nightModeAutoMode", "nightModeStartHour", "nightModeStartMinute", "nightModeEndHour", "nightModeEndMinute", "latitude", "longitude", "nightModeUseIPLocation", "nightModeLocationProvider", "pinnedApps", "hiddenTrayIds", "selectedGpuIndex", "nvidiaGpuTempEnabled", "nonNvidiaGpuTempEnabled", "enabledGpuPciIds", "wifiDeviceOverride", "weatherHourlyDetailed", "wallpaperCyclingEnabled", "wallpaperCyclingMode", "wallpaperCyclingInterval", "wallpaperCyclingTime", "monitorCyclingSettings", "lastBrightnessDevice", "brightnessExponentialDevices", "brightnessUserSetValues", "brightnessExponentValues", "launchPrefix", "wallpaperTransition", "includedTransitions", "recentColors", "showThirdPartyPlugins", "configVersion"];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = settingsFile.text();
|
const content = settingsFile.text();
|
||||||
@@ -894,6 +897,11 @@ Singleton {
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setWeatherHourlyDetailed(detailed) {
|
||||||
|
weatherHourlyDetailed = detailed;
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
function syncWallpaperForCurrentMode() {
|
function syncWallpaperForCurrentMode() {
|
||||||
if (!perModeWallpaper)
|
if (!perModeWallpaper)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ Singleton {
|
|||||||
|
|
||||||
property string appLauncherViewMode: "list"
|
property string appLauncherViewMode: "list"
|
||||||
property string spotlightModalViewMode: "list"
|
property string spotlightModalViewMode: "list"
|
||||||
|
property string browserPickerViewMode: "grid"
|
||||||
|
property var browserUsageHistory: ({})
|
||||||
property bool sortAppsAlphabetically: false
|
property bool sortAppsAlphabetically: false
|
||||||
property int appLauncherGridColumns: 4
|
property int appLauncherGridColumns: 4
|
||||||
property bool spotlightCloseNiriOverview: true
|
property bool spotlightCloseNiriOverview: true
|
||||||
@@ -1390,27 +1392,4 @@ rm -rf '${home}'/.cache/icon-cache '${home}'/.cache/thumbnails 2>/dev/null || tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
property bool pluginSettingsFileExists: false
|
property bool pluginSettingsFileExists: false
|
||||||
|
|
||||||
IpcHandler {
|
|
||||||
function reveal(): string {
|
|
||||||
root.setShowDock(true);
|
|
||||||
return "DOCK_SHOW_SUCCESS";
|
|
||||||
}
|
|
||||||
|
|
||||||
function hide(): string {
|
|
||||||
root.setShowDock(false);
|
|
||||||
return "DOCK_HIDE_SUCCESS";
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggle(): string {
|
|
||||||
root.toggleShowDock();
|
|
||||||
return root.showDock ? "DOCK_SHOW_SUCCESS" : "DOCK_HIDE_SUCCESS";
|
|
||||||
}
|
|
||||||
|
|
||||||
function status(): string {
|
|
||||||
return root.showDock ? "visible" : "hidden";
|
|
||||||
}
|
|
||||||
|
|
||||||
target: "dock"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1004,6 +1004,19 @@ Singleton {
|
|||||||
return Qt.rgba(c.r, c.g, c.b, a);
|
return Qt.rgba(c.r, c.g, c.b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function blendAlpha(c, a) {
|
||||||
|
return Qt.rgba(c.r, c.g, c.b, c.a*a);
|
||||||
|
}
|
||||||
|
|
||||||
|
function blend(c1, c2, r) {
|
||||||
|
return Qt.rgba(
|
||||||
|
c1.r * (1-r) + c2.r * r,
|
||||||
|
c1.g * (1-r) + c2.g * r,
|
||||||
|
c1.b * (1-r) + c2.b * r,
|
||||||
|
c1.a * (1-r) + c2.a * r,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function getFillMode(modeName) {
|
function getFillMode(modeName) {
|
||||||
switch (modeName) {
|
switch (modeName) {
|
||||||
case "Stretch":
|
case "Stretch":
|
||||||
|
|||||||
308
quickshell/Common/suncalc.js
Normal file
308
quickshell/Common/suncalc.js
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
.pragma library
|
||||||
|
// Copyright (c) 2025, Vladimir Agafonkin
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
// provided with the distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||||
|
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
// shortcuts for easier to read formulas
|
||||||
|
|
||||||
|
const PI = Math.PI,
|
||||||
|
sin = Math.sin,
|
||||||
|
cos = Math.cos,
|
||||||
|
tan = Math.tan,
|
||||||
|
asin = Math.asin,
|
||||||
|
atan = Math.atan2,
|
||||||
|
acos = Math.acos,
|
||||||
|
rad = PI / 180;
|
||||||
|
|
||||||
|
// sun calculations are based on https://aa.quae.nl/en/reken/zonpositie.html formulas
|
||||||
|
|
||||||
|
// date/time constants and conversions
|
||||||
|
|
||||||
|
const dayMs = 1000 * 60 * 60 * 24,
|
||||||
|
J1970 = 2440588,
|
||||||
|
J2000 = 2451545;
|
||||||
|
|
||||||
|
function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
|
||||||
|
function fromJulian(j) { return new Date((j + 0.5 - J1970) * dayMs); }
|
||||||
|
function toDays(date) { return toJulian(date) - J2000; }
|
||||||
|
|
||||||
|
|
||||||
|
// general calculations for position
|
||||||
|
|
||||||
|
const e = rad * 23.4397; // obliquity of the Earth
|
||||||
|
|
||||||
|
function rightAscension(l, b) { return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); }
|
||||||
|
function declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); }
|
||||||
|
|
||||||
|
function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); }
|
||||||
|
function altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); }
|
||||||
|
|
||||||
|
function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; }
|
||||||
|
|
||||||
|
function astroRefraction(h) {
|
||||||
|
if (h < 0) // the following formula works for positive altitudes only.
|
||||||
|
h = 0; // if h = -0.08901179 a div/0 would occur.
|
||||||
|
|
||||||
|
// formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
||||||
|
// 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad:
|
||||||
|
return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179));
|
||||||
|
}
|
||||||
|
|
||||||
|
// general sun calculations
|
||||||
|
|
||||||
|
function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); }
|
||||||
|
|
||||||
|
function eclipticLongitude(M) {
|
||||||
|
|
||||||
|
const C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)), // equation of center
|
||||||
|
P = rad * 102.9372; // perihelion of the Earth
|
||||||
|
|
||||||
|
return M + C + P + PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sunCoords(d) {
|
||||||
|
|
||||||
|
const M = solarMeanAnomaly(d),
|
||||||
|
L = eclipticLongitude(M);
|
||||||
|
|
||||||
|
return {
|
||||||
|
dec: declination(L, 0),
|
||||||
|
ra: rightAscension(L, 0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// calculates sun position for a given date and latitude/longitude
|
||||||
|
|
||||||
|
function getPosition(date, lat, lng) {
|
||||||
|
|
||||||
|
const lw = rad * -lng,
|
||||||
|
phi = rad * lat,
|
||||||
|
d = toDays(date),
|
||||||
|
|
||||||
|
c = sunCoords(d),
|
||||||
|
H = siderealTime(d, lw) - c.ra;
|
||||||
|
|
||||||
|
return {
|
||||||
|
azimuth: azimuth(H, phi, c.dec),
|
||||||
|
altitude: altitude(H, phi, c.dec)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// sun times configuration (angle, morning name, evening name)
|
||||||
|
|
||||||
|
const times = [
|
||||||
|
[-0.833, 'sunrise', 'sunset'],
|
||||||
|
[-0.3, 'sunriseEnd', 'sunsetStart'],
|
||||||
|
[-6, 'dawn', 'dusk'],
|
||||||
|
[-12, 'nauticalDawn', 'nauticalDusk'],
|
||||||
|
[-18, 'nightEnd', 'night'],
|
||||||
|
[6, 'goldenHourEnd', 'goldenHour']
|
||||||
|
];
|
||||||
|
|
||||||
|
// adds a custom time to the times config
|
||||||
|
|
||||||
|
function addTime(angle, riseName, setName) {
|
||||||
|
times.push([angle, riseName, setName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// calculations for sun times
|
||||||
|
|
||||||
|
const J0 = 0.0009;
|
||||||
|
|
||||||
|
function julianCycle(d, lw) { return Math.round(d - J0 - lw / (2 * PI)); }
|
||||||
|
|
||||||
|
function approxTransit(Ht, lw, n) { return J0 + (Ht + lw) / (2 * PI) + n; }
|
||||||
|
function solarTransitJ(ds, M, L) { return J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L); }
|
||||||
|
|
||||||
|
function hourAngle(h, phi, d) { return acos((sin(h) - sin(phi) * sin(d)) / (cos(phi) * cos(d))); }
|
||||||
|
function observerAngle(height) { return -2.076 * Math.sqrt(height) / 60; }
|
||||||
|
|
||||||
|
// returns set time for the given sun altitude
|
||||||
|
function getSetJ(h, lw, phi, dec, n, M, L) {
|
||||||
|
|
||||||
|
const w = hourAngle(h, phi, dec),
|
||||||
|
a = approxTransit(w, lw, n);
|
||||||
|
return solarTransitJ(a, M, L);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// calculates sun times for a given date, latitude/longitude, and, optionally,
|
||||||
|
// the observer height (in meters) relative to the horizon
|
||||||
|
|
||||||
|
function getTimes(date, lat, lng, height) {
|
||||||
|
|
||||||
|
height = height || 0;
|
||||||
|
|
||||||
|
const lw = rad * -lng,
|
||||||
|
phi = rad * lat,
|
||||||
|
dh = observerAngle(height),
|
||||||
|
d = toDays(date),
|
||||||
|
n = julianCycle(d, lw),
|
||||||
|
ds = approxTransit(0, lw, n),
|
||||||
|
M = solarMeanAnomaly(ds),
|
||||||
|
L = eclipticLongitude(M),
|
||||||
|
dec = declination(L, 0),
|
||||||
|
Jnoon = solarTransitJ(ds, M, L);
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
solarNoon: fromJulian(Jnoon),
|
||||||
|
nadir: fromJulian(Jnoon - 0.5)
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const time of times) {
|
||||||
|
const h0 = (time[0] + dh) * rad;
|
||||||
|
const Jset = getSetJ(h0, lw, phi, dec, n, M, L);
|
||||||
|
const Jrise = Jnoon - (Jset - Jnoon);
|
||||||
|
|
||||||
|
result[time[1]] = fromJulian(Jrise);
|
||||||
|
result[time[2]] = fromJulian(Jset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas
|
||||||
|
|
||||||
|
function moonCoords(d) { // geocentric ecliptic coordinates of the moon
|
||||||
|
|
||||||
|
const L = rad * (218.316 + 13.176396 * d), // ecliptic longitude
|
||||||
|
M = rad * (134.963 + 13.064993 * d), // mean anomaly
|
||||||
|
F = rad * (93.272 + 13.229350 * d), // mean distance
|
||||||
|
|
||||||
|
l = L + rad * 6.289 * sin(M), // longitude
|
||||||
|
b = rad * 5.128 * sin(F), // latitude
|
||||||
|
dt = 385001 - 20905 * cos(M); // distance to the moon in km
|
||||||
|
|
||||||
|
return {
|
||||||
|
ra: rightAscension(l, b),
|
||||||
|
dec: declination(l, b),
|
||||||
|
dist: dt
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMoonPosition(date, lat, lng) {
|
||||||
|
|
||||||
|
const lw = rad * -lng,
|
||||||
|
phi = rad * lat,
|
||||||
|
d = toDays(date),
|
||||||
|
c = moonCoords(d),
|
||||||
|
H = siderealTime(d, lw) - c.ra,
|
||||||
|
h = altitude(H, phi, c.dec),
|
||||||
|
// formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
||||||
|
pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H));
|
||||||
|
|
||||||
|
return {
|
||||||
|
azimuth: azimuth(H, phi, c.dec),
|
||||||
|
altitude: h + astroRefraction(h), // altitude correction for refraction,
|
||||||
|
distance: c.dist,
|
||||||
|
parallacticAngle: pa
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// calculations for illumination parameters of the moon,
|
||||||
|
// based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and
|
||||||
|
// Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
||||||
|
|
||||||
|
function getMoonIllumination(date) {
|
||||||
|
|
||||||
|
const d = toDays(date || new Date()),
|
||||||
|
s = sunCoords(d),
|
||||||
|
m = moonCoords(d),
|
||||||
|
|
||||||
|
sdist = 149598000, // distance from Earth to Sun in km
|
||||||
|
|
||||||
|
phi = acos(sin(s.dec) * sin(m.dec) + cos(s.dec) * cos(m.dec) * cos(s.ra - m.ra)),
|
||||||
|
inc = atan(sdist * sin(phi), m.dist - sdist * cos(phi)),
|
||||||
|
angle = atan(cos(s.dec) * sin(s.ra - m.ra), sin(s.dec) * cos(m.dec) -
|
||||||
|
cos(s.dec) * sin(m.dec) * cos(s.ra - m.ra));
|
||||||
|
|
||||||
|
return {
|
||||||
|
fraction: (1 + cos(inc)) / 2,
|
||||||
|
phase: 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI,
|
||||||
|
angle
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function hoursLater(date, h) {
|
||||||
|
return new Date(date.valueOf() + h * dayMs / 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article
|
||||||
|
|
||||||
|
function getMoonTimes(date, lat, lng, inUTC) {
|
||||||
|
const t = new Date(date);
|
||||||
|
if (inUTC) t.setUTCHours(0, 0, 0, 0);
|
||||||
|
else t.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const hc = 0.133 * rad;
|
||||||
|
let h0 = getMoonPosition(t, lat, lng).altitude - hc,
|
||||||
|
rise, set, ye;
|
||||||
|
|
||||||
|
// go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set)
|
||||||
|
for (let i = 1; i <= 24; i += 2) {
|
||||||
|
const h1 = getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc;
|
||||||
|
const h2 = getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc;
|
||||||
|
const a = (h0 + h2) / 2 - h1;
|
||||||
|
const b = (h2 - h0) / 2;
|
||||||
|
const xe = -b / (2 * a);
|
||||||
|
const d = b * b - 4 * a * h1;
|
||||||
|
let roots = 0, x1 = 0, x2 = 0;
|
||||||
|
ye = (a * xe + b) * xe + h1;
|
||||||
|
|
||||||
|
if (d >= 0) {
|
||||||
|
const dx = Math.sqrt(d) / (Math.abs(a) * 2);
|
||||||
|
x1 = xe - dx;
|
||||||
|
x2 = xe + dx;
|
||||||
|
if (Math.abs(x1) <= 1) roots++;
|
||||||
|
if (Math.abs(x2) <= 1) roots++;
|
||||||
|
if (x1 < -1) x1 = x2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roots === 1) {
|
||||||
|
if (h0 < 0) rise = i + x1;
|
||||||
|
else set = i + x1;
|
||||||
|
|
||||||
|
} else if (roots === 2) {
|
||||||
|
rise = i + (ye < 0 ? x2 : x1);
|
||||||
|
set = i + (ye < 0 ? x1 : x2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rise && set) break;
|
||||||
|
|
||||||
|
h0 = h2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = {};
|
||||||
|
|
||||||
|
if (rise) result.rise = hoursLater(t, rise);
|
||||||
|
if (set) result.set = hoursLater(t, set);
|
||||||
|
|
||||||
|
if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
@@ -431,6 +431,74 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BrowserPickerModal {
|
||||||
|
id: browserPickerModal
|
||||||
|
}
|
||||||
|
|
||||||
|
AppPickerModal {
|
||||||
|
id: filePickerModal
|
||||||
|
title: I18n.tr("Open with...")
|
||||||
|
|
||||||
|
function shellEscape(str) {
|
||||||
|
return "'" + str.replace(/'/g, "'\\''") + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
onApplicationSelected: (app, filePath) => {
|
||||||
|
if (!app) return
|
||||||
|
|
||||||
|
let cmd = app.exec || ""
|
||||||
|
const escapedPath = shellEscape(filePath)
|
||||||
|
const escapedUri = shellEscape("file://" + filePath)
|
||||||
|
|
||||||
|
let hasField = false
|
||||||
|
if (cmd.includes("%f")) { cmd = cmd.replace("%f", escapedPath); hasField = true }
|
||||||
|
else if (cmd.includes("%F")) { cmd = cmd.replace("%F", escapedPath); hasField = true }
|
||||||
|
else if (cmd.includes("%u")) { cmd = cmd.replace("%u", escapedUri); hasField = true }
|
||||||
|
else if (cmd.includes("%U")) { cmd = cmd.replace("%U", escapedUri); hasField = true }
|
||||||
|
|
||||||
|
cmd = cmd.replace(/%[ikc]/g, "")
|
||||||
|
|
||||||
|
if (!hasField) {
|
||||||
|
cmd += " " + escapedPath
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("FilePicker: Launching", cmd)
|
||||||
|
|
||||||
|
Quickshell.execDetached({
|
||||||
|
command: ["sh", "-c", cmd]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: DMSService
|
||||||
|
function onOpenUrlRequested(url) {
|
||||||
|
browserPickerModal.url = url
|
||||||
|
browserPickerModal.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAppPickerRequested(data) {
|
||||||
|
console.log("DMSShell: App picker requested with data:", JSON.stringify(data))
|
||||||
|
|
||||||
|
if (!data || !data.target) {
|
||||||
|
console.warn("DMSShell: Invalid app picker request data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
filePickerModal.targetData = data.target
|
||||||
|
filePickerModal.targetDataLabel = data.requestType || "file"
|
||||||
|
|
||||||
|
if (data.categories && data.categories.length > 0) {
|
||||||
|
filePickerModal.categoryFilter = data.categories
|
||||||
|
} else {
|
||||||
|
filePickerModal.categoryFilter = []
|
||||||
|
}
|
||||||
|
|
||||||
|
filePickerModal.usageHistoryKey = "filePickerUsageHistory"
|
||||||
|
filePickerModal.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DankColorPickerModal {
|
DankColorPickerModal {
|
||||||
id: colorPickerModal
|
id: colorPickerModal
|
||||||
|
|
||||||
|
|||||||
@@ -480,56 +480,108 @@ Item {
|
|||||||
target: "dankdash"
|
target: "dankdash"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBarConfig(selector: string, value: string): var {
|
||||||
|
const barSelectors = ["id", "name", "index"];
|
||||||
|
if (!barSelectors.includes(selector)) return { error: "BAR_INVALID_SELECTOR" };
|
||||||
|
const index = selector === "index" ? Number(value) : SettingsData.barConfigs.findIndex(bar => bar[selector] == value);
|
||||||
|
const barConfig = SettingsData.barConfigs?.[index];
|
||||||
|
if (!barConfig) return { error: "BAR_NOT_FOUND" };
|
||||||
|
return { barConfig };
|
||||||
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
function reveal(index: int): string {
|
function reveal(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
SettingsData.updateBarConfig(barConfig.id, {visible: true});
|
||||||
}
|
return "BAR_SHOW_SUCCESS";
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
SettingsData.updateBarConfig(bar.id, {
|
|
||||||
visible: true
|
|
||||||
});
|
|
||||||
return `BAR_${index}_SHOW_SUCCESS`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide(index: int): string {
|
function hide(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
SettingsData.updateBarConfig(barConfig.id, {visible: false});
|
||||||
}
|
return "BAR_HIDE_SUCCESS";
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
SettingsData.updateBarConfig(bar.id, {
|
|
||||||
visible: false
|
|
||||||
});
|
|
||||||
return `BAR_${index}_HIDE_SUCCESS`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(index: int): string {
|
function toggle(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
SettingsData.updateBarConfig(barConfig.id, {visible: !barConfig.visible});
|
||||||
}
|
return !barConfig.visible ? "BAR_SHOW_SUCCESS" : "BAR_HIDE_SUCCESS";
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
const newVisible = !(bar.visible ?? true);
|
|
||||||
SettingsData.updateBarConfig(bar.id, {
|
|
||||||
visible: newVisible
|
|
||||||
});
|
|
||||||
return newVisible ? `BAR_${index}_SHOW_SUCCESS` : `BAR_${index}_HIDE_SUCCESS`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function status(index: int): string {
|
function status(selector: string, value: string): string {
|
||||||
const idx = index - 1;
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
if (idx < 0 || idx >= SettingsData.barConfigs.length) {
|
if (error) return error;
|
||||||
return `BAR_${index}_NOT_FOUND`;
|
return barConfig.visible ? "visible" : "hidden";
|
||||||
}
|
}
|
||||||
const bar = SettingsData.barConfigs[idx];
|
|
||||||
return (bar.visible ?? true) ? "visible" : "hidden";
|
function autoHide(selector: string, value: string): string {
|
||||||
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
|
if (error) return error;
|
||||||
|
SettingsData.updateBarConfig(barConfig.id, {autoHide: true});
|
||||||
|
return "BAR_AUTO_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function manualHide(selector: string, value: string): string {
|
||||||
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
|
if (error) return error;
|
||||||
|
SettingsData.updateBarConfig(barConfig.id, {autoHide: false});
|
||||||
|
return "BAR_MANUAL_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAutoHide(selector: string, value: string): string {
|
||||||
|
const { barConfig, error } = getBarConfig(selector, value);
|
||||||
|
if (error) return error;
|
||||||
|
SettingsData.updateBarConfig(barConfig.id, {autoHide: !barConfig.autoHide});
|
||||||
|
return barConfig.autoHide ? "BAR_MANUAL_HIDE_SUCCESS": "BAR_AUTO_HIDE_SUCCESS";
|
||||||
}
|
}
|
||||||
|
|
||||||
target: "bar"
|
target: "bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IpcHandler {
|
||||||
|
function reveal(): string {
|
||||||
|
SettingsData.setShowDock(true);
|
||||||
|
return "DOCK_SHOW_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide(): string {
|
||||||
|
SettingsData.setShowDock(false);
|
||||||
|
return "DOCK_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle(): string {
|
||||||
|
SettingsData.toggleShowDock();
|
||||||
|
return SettingsData.showDock ? "DOCK_SHOW_SUCCESS" : "DOCK_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function status(): string {
|
||||||
|
return SettingsData.showDock ? "visible" : "hidden";
|
||||||
|
}
|
||||||
|
|
||||||
|
function autoHide(): string {
|
||||||
|
SettingsData.dockAutoHide = true
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return "BAR_AUTO_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function manualHide(): string {
|
||||||
|
SettingsData.dockAutoHide = false
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return "BAR_MANUAL_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAutoHide(): string {
|
||||||
|
SettingsData.dockAutoHide = !SettingsData.dockAutoHide
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return SettingsData.dockAutoHide ? "BAR_AUTO_HIDE_SUCCESS" : "BAR_MANUAL_HIDE_SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
target: "dock"
|
||||||
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
function open(): string {
|
function open(): string {
|
||||||
PopoutService.openSettings();
|
PopoutService.openSettings();
|
||||||
@@ -546,6 +598,53 @@ Item {
|
|||||||
return "SETTINGS_TOGGLE_SUCCESS";
|
return "SETTINGS_TOGGLE_SUCCESS";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get(key: string): string {
|
||||||
|
return JSON.stringify(SettingsData?.[key])
|
||||||
|
}
|
||||||
|
|
||||||
|
function set(key: string, value: string): string {
|
||||||
|
|
||||||
|
if (!(key in SettingsData)) {
|
||||||
|
console.warn("Cannot set property, not found:", key)
|
||||||
|
return "SETTINGS_INVALID_KEY"
|
||||||
|
}
|
||||||
|
|
||||||
|
const typeName = typeof SettingsData?.[key]
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (typeName) {
|
||||||
|
case "boolean":
|
||||||
|
if (value === "true" || value === "false") value = (value === "true")
|
||||||
|
else throw `${value} is not a Boolean`
|
||||||
|
break
|
||||||
|
case "number":
|
||||||
|
value = Number(value)
|
||||||
|
if (isNaN(value)) throw `${value} is not a Number`
|
||||||
|
break
|
||||||
|
case "string":
|
||||||
|
value = String(value)
|
||||||
|
break
|
||||||
|
case "object":
|
||||||
|
// NOTE: Parsing lists is messed up upstream and not sure if we want
|
||||||
|
// to make sure objects are well structured or just let people set
|
||||||
|
// whatever they want but risking messed up settings.
|
||||||
|
// Objects & Arrays are disabled for now
|
||||||
|
// https://github.com/quickshell-mirror/quickshell/pull/22
|
||||||
|
throw "Setting Objects and Arrays not supported"
|
||||||
|
default:
|
||||||
|
throw "Unsupported type"
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn("Setting:", key, value)
|
||||||
|
SettingsData[key] = value
|
||||||
|
SettingsData.saveSettings()
|
||||||
|
return "SETTINGS_SET_SUCCESS"
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Failed to set property:", key, "error:", e)
|
||||||
|
return "SETTINGS_SET_FAILURE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
target: "settings"
|
target: "settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
469
quickshell/Modals/AppPickerModal.qml
Normal file
469
quickshell/Modals/AppPickerModal.qml
Normal file
@@ -0,0 +1,469 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
import qs.Common
|
||||||
|
import qs.Modals.Common
|
||||||
|
import qs.Widgets
|
||||||
|
import qs.Services
|
||||||
|
|
||||||
|
DankModal {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property string title: I18n.tr("Select Application")
|
||||||
|
property string targetData: ""
|
||||||
|
property string targetDataLabel: ""
|
||||||
|
property string searchQuery: ""
|
||||||
|
property int selectedIndex: 0
|
||||||
|
property int gridColumns: SettingsData.appLauncherGridColumns
|
||||||
|
property bool keyboardNavigationActive: false
|
||||||
|
property string viewMode: "grid"
|
||||||
|
property var categoryFilter: []
|
||||||
|
property var usageHistoryKey: ""
|
||||||
|
property bool showTargetData: true
|
||||||
|
|
||||||
|
signal applicationSelected(var app, string targetData)
|
||||||
|
|
||||||
|
shouldBeVisible: false
|
||||||
|
allowStacking: true
|
||||||
|
modalWidth: 520
|
||||||
|
modalHeight: 500
|
||||||
|
|
||||||
|
onDialogClosed: {
|
||||||
|
searchQuery = ""
|
||||||
|
selectedIndex = 0
|
||||||
|
keyboardNavigationActive: false
|
||||||
|
}
|
||||||
|
|
||||||
|
onOpened: {
|
||||||
|
searchQuery = ""
|
||||||
|
updateApplicationList()
|
||||||
|
selectedIndex = 0
|
||||||
|
Qt.callLater(() => {
|
||||||
|
if (contentLoader.item && contentLoader.item.searchField) {
|
||||||
|
contentLoader.item.searchField.text = ""
|
||||||
|
contentLoader.item.searchField.forceActiveFocus()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateApplicationList() {
|
||||||
|
applicationsModel.clear()
|
||||||
|
const apps = AppSearchService.applications
|
||||||
|
const usageHistory = usageHistoryKey && SettingsData[usageHistoryKey] ? SettingsData[usageHistoryKey] : {}
|
||||||
|
let filteredApps = []
|
||||||
|
|
||||||
|
for (const app of apps) {
|
||||||
|
if (!app || !app.categories) continue
|
||||||
|
|
||||||
|
let matchesCategory = categoryFilter.length === 0
|
||||||
|
|
||||||
|
if (categoryFilter.length > 0) {
|
||||||
|
try {
|
||||||
|
for (const cat of app.categories) {
|
||||||
|
if (categoryFilter.includes(cat)) {
|
||||||
|
matchesCategory = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("AppPicker: Error iterating categories for", app.name, ":", e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchesCategory) {
|
||||||
|
const name = app.name || ""
|
||||||
|
const lowerName = name.toLowerCase()
|
||||||
|
const lowerQuery = searchQuery.toLowerCase()
|
||||||
|
|
||||||
|
if (searchQuery === "" || lowerName.includes(lowerQuery)) {
|
||||||
|
filteredApps.push({
|
||||||
|
name: name,
|
||||||
|
icon: app.icon || "application-x-executable",
|
||||||
|
exec: app.exec || app.execString || "",
|
||||||
|
startupClass: app.startupWMClass || "",
|
||||||
|
appData: app
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredApps.sort((a, b) => {
|
||||||
|
const aId = a.appData.id || a.appData.execString || a.appData.exec || ""
|
||||||
|
const bId = b.appData.id || b.appData.execString || b.appData.exec || ""
|
||||||
|
const aUsage = usageHistory[aId] ? usageHistory[aId].count : 0
|
||||||
|
const bUsage = usageHistory[bId] ? usageHistory[bId].count : 0
|
||||||
|
if (aUsage !== bUsage) {
|
||||||
|
return bUsage - aUsage
|
||||||
|
}
|
||||||
|
return (a.name || "").localeCompare(b.name || "")
|
||||||
|
})
|
||||||
|
|
||||||
|
filteredApps.forEach(app => {
|
||||||
|
applicationsModel.append({
|
||||||
|
name: app.name,
|
||||||
|
icon: app.icon,
|
||||||
|
exec: app.exec,
|
||||||
|
startupClass: app.startupClass,
|
||||||
|
appId: app.appData.id || app.appData.execString || app.appData.exec || ""
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log("AppPicker: Found " + filteredApps.length + " applications")
|
||||||
|
}
|
||||||
|
|
||||||
|
onSearchQueryChanged: updateApplicationList()
|
||||||
|
|
||||||
|
ListModel {
|
||||||
|
id: applicationsModel
|
||||||
|
}
|
||||||
|
|
||||||
|
content: Component {
|
||||||
|
FocusScope {
|
||||||
|
id: appContent
|
||||||
|
|
||||||
|
property alias searchField: searchField
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
focus: true
|
||||||
|
|
||||||
|
Keys.onEscapePressed: event => {
|
||||||
|
root.close()
|
||||||
|
event.accepted = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.onPressed: event => {
|
||||||
|
if (applicationsModel.count === 0) return
|
||||||
|
|
||||||
|
// Toggle view mode with Tab key
|
||||||
|
if (event.key === Qt.Key_Tab) {
|
||||||
|
root.viewMode = root.viewMode === "grid" ? "list" : "grid"
|
||||||
|
event.accepted = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.viewMode === "grid") {
|
||||||
|
if (event.key === Qt.Key_Left) {
|
||||||
|
root.keyboardNavigationActive = true
|
||||||
|
root.selectedIndex = Math.max(0, root.selectedIndex - 1)
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Right) {
|
||||||
|
root.keyboardNavigationActive = true
|
||||||
|
root.selectedIndex = Math.min(applicationsModel.count - 1, root.selectedIndex + 1)
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Up) {
|
||||||
|
root.keyboardNavigationActive = true
|
||||||
|
root.selectedIndex = Math.max(0, root.selectedIndex - root.gridColumns)
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Down) {
|
||||||
|
root.keyboardNavigationActive = true
|
||||||
|
root.selectedIndex = Math.min(applicationsModel.count - 1, root.selectedIndex + root.gridColumns)
|
||||||
|
event.accepted = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (event.key === Qt.Key_Up) {
|
||||||
|
root.keyboardNavigationActive = true
|
||||||
|
root.selectedIndex = Math.max(0, root.selectedIndex - 1)
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Down) {
|
||||||
|
root.keyboardNavigationActive = true
|
||||||
|
root.selectedIndex = Math.min(applicationsModel.count - 1, root.selectedIndex + 1)
|
||||||
|
event.accepted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
||||||
|
if (root.selectedIndex >= 0 && root.selectedIndex < applicationsModel.count) {
|
||||||
|
const app = applicationsModel.get(root.selectedIndex)
|
||||||
|
launchApplication(app)
|
||||||
|
}
|
||||||
|
event.accepted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
width: parent.width - Theme.spacingS * 2
|
||||||
|
height: parent.height - Theme.spacingS * 2
|
||||||
|
x: Theme.spacingS
|
||||||
|
y: Theme.spacingS
|
||||||
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
|
Item {
|
||||||
|
width: parent.width
|
||||||
|
height: 40
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: Theme.spacingS
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
text: root.title
|
||||||
|
font.pixelSize: Theme.fontSizeLarge + 4
|
||||||
|
font.weight: Font.Bold
|
||||||
|
color: Theme.surfaceText
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
spacing: 4
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: Theme.spacingS
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
|
DankActionButton {
|
||||||
|
buttonSize: 36
|
||||||
|
circular: false
|
||||||
|
iconName: "view_list"
|
||||||
|
iconSize: 20
|
||||||
|
iconColor: root.viewMode === "list" ? Theme.primary : Theme.surfaceText
|
||||||
|
backgroundColor: root.viewMode === "list" ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
|
||||||
|
onClicked: {
|
||||||
|
root.viewMode = "list"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankActionButton {
|
||||||
|
buttonSize: 36
|
||||||
|
circular: false
|
||||||
|
iconName: "grid_view"
|
||||||
|
iconSize: 20
|
||||||
|
iconColor: root.viewMode === "grid" ? Theme.primary : Theme.surfaceText
|
||||||
|
backgroundColor: root.viewMode === "grid" ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
|
||||||
|
onClicked: {
|
||||||
|
root.viewMode = "grid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankTextField {
|
||||||
|
id: searchField
|
||||||
|
|
||||||
|
width: parent.width - Theme.spacingS * 2
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
height: 52
|
||||||
|
cornerRadius: Theme.cornerRadius
|
||||||
|
backgroundColor: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
||||||
|
normalBorderColor: Theme.outlineMedium
|
||||||
|
focusedBorderColor: Theme.primary
|
||||||
|
leftIconName: "search"
|
||||||
|
leftIconSize: Theme.iconSize
|
||||||
|
leftIconColor: Theme.surfaceVariantText
|
||||||
|
leftIconFocusedColor: Theme.primary
|
||||||
|
showClearButton: true
|
||||||
|
font.pixelSize: Theme.fontSizeLarge
|
||||||
|
enabled: root.shouldBeVisible
|
||||||
|
ignoreLeftRightKeys: root.viewMode !== "list"
|
||||||
|
ignoreTabKeys: true
|
||||||
|
keyForwardTargets: [appContent]
|
||||||
|
|
||||||
|
onTextEdited: {
|
||||||
|
root.searchQuery = text
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.onPressed: function (event) {
|
||||||
|
if (event.key === Qt.Key_Escape) {
|
||||||
|
root.close()
|
||||||
|
event.accepted = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const isEnterKey = [Qt.Key_Return, Qt.Key_Enter].includes(event.key)
|
||||||
|
const hasText = text.length > 0
|
||||||
|
|
||||||
|
if (isEnterKey && hasText) {
|
||||||
|
if (root.keyboardNavigationActive && applicationsModel.count > 0) {
|
||||||
|
const app = applicationsModel.get(root.selectedIndex)
|
||||||
|
launchApplication(app)
|
||||||
|
} else if (applicationsModel.count > 0) {
|
||||||
|
const app = applicationsModel.get(0)
|
||||||
|
launchApplication(app)
|
||||||
|
}
|
||||||
|
event.accepted = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const navigationKeys = [Qt.Key_Down, Qt.Key_Up, Qt.Key_Left, Qt.Key_Right, Qt.Key_Tab, Qt.Key_Backtab]
|
||||||
|
const isNavigationKey = navigationKeys.includes(event.key)
|
||||||
|
const isEmptyEnter = isEnterKey && !hasText
|
||||||
|
|
||||||
|
event.accepted = !(isNavigationKey || isEmptyEnter)
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
function onShouldBeVisibleChanged() {
|
||||||
|
if (!root.shouldBeVisible) {
|
||||||
|
searchField.focus = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target: root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: parent.width
|
||||||
|
height: {
|
||||||
|
let usedHeight = 40 + Theme.spacingS
|
||||||
|
usedHeight += 52 + Theme.spacingS
|
||||||
|
if (root.showTargetData) {
|
||||||
|
usedHeight += 36 + Theme.spacingS
|
||||||
|
}
|
||||||
|
return parent.height - usedHeight
|
||||||
|
}
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: "transparent"
|
||||||
|
|
||||||
|
DankListView {
|
||||||
|
id: appList
|
||||||
|
|
||||||
|
property int itemHeight: 60
|
||||||
|
property int itemSpacing: Theme.spacingS
|
||||||
|
|
||||||
|
function ensureVisible(index) {
|
||||||
|
if (index < 0 || index >= count) return
|
||||||
|
|
||||||
|
const itemY = index * (itemHeight + itemSpacing)
|
||||||
|
const itemBottom = itemY + itemHeight
|
||||||
|
if (itemY < contentY) {
|
||||||
|
contentY = itemY
|
||||||
|
} else if (itemBottom > contentY + height) {
|
||||||
|
contentY = itemBottom - height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.leftMargin: Theme.spacingS
|
||||||
|
anchors.rightMargin: Theme.spacingS
|
||||||
|
anchors.bottomMargin: Theme.spacingS
|
||||||
|
|
||||||
|
visible: root.viewMode === "list"
|
||||||
|
model: applicationsModel
|
||||||
|
currentIndex: root.selectedIndex
|
||||||
|
clip: true
|
||||||
|
spacing: itemSpacing
|
||||||
|
|
||||||
|
onCurrentIndexChanged: {
|
||||||
|
root.selectedIndex = currentIndex
|
||||||
|
if (root.keyboardNavigationActive) {
|
||||||
|
ensureVisible(currentIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: AppLauncherListDelegate {
|
||||||
|
listView: appList
|
||||||
|
itemHeight: 60
|
||||||
|
iconSize: 40
|
||||||
|
showDescription: false
|
||||||
|
|
||||||
|
isCurrentItem: index === root.selectedIndex
|
||||||
|
keyboardNavigationActive: root.keyboardNavigationActive
|
||||||
|
hoverUpdatesSelection: true
|
||||||
|
|
||||||
|
onItemClicked: (idx, modelData) => {
|
||||||
|
launchApplication(modelData)
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyboardNavigationReset: {
|
||||||
|
root.keyboardNavigationActive = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DankGridView {
|
||||||
|
id: appGrid
|
||||||
|
|
||||||
|
function ensureVisible(index) {
|
||||||
|
if (index < 0 || index >= count) return
|
||||||
|
|
||||||
|
const itemY = Math.floor(index / root.gridColumns) * cellHeight
|
||||||
|
const itemBottom = itemY + cellHeight
|
||||||
|
if (itemY < contentY) {
|
||||||
|
contentY = itemY
|
||||||
|
} else if (itemBottom > contentY + height) {
|
||||||
|
contentY = itemBottom - height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.leftMargin: Theme.spacingS
|
||||||
|
anchors.rightMargin: Theme.spacingS
|
||||||
|
anchors.bottomMargin: Theme.spacingS
|
||||||
|
|
||||||
|
visible: root.viewMode === "grid"
|
||||||
|
model: applicationsModel
|
||||||
|
cellWidth: width / root.gridColumns
|
||||||
|
cellHeight: 120
|
||||||
|
clip: true
|
||||||
|
currentIndex: root.selectedIndex
|
||||||
|
|
||||||
|
onCurrentIndexChanged: {
|
||||||
|
root.selectedIndex = currentIndex
|
||||||
|
if (root.keyboardNavigationActive) {
|
||||||
|
ensureVisible(currentIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: AppLauncherGridDelegate {
|
||||||
|
gridView: appGrid
|
||||||
|
cellWidth: appGrid.cellWidth
|
||||||
|
cellHeight: appGrid.cellHeight
|
||||||
|
|
||||||
|
currentIndex: root.selectedIndex
|
||||||
|
keyboardNavigationActive: root.keyboardNavigationActive
|
||||||
|
hoverUpdatesSelection: true
|
||||||
|
|
||||||
|
onItemClicked: (idx, modelData) => {
|
||||||
|
launchApplication(modelData)
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyboardNavigationReset: {
|
||||||
|
root.keyboardNavigationActive = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: parent.width
|
||||||
|
height: 36
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: Theme.withAlpha(Theme.surfaceContainerHigh, 0.5)
|
||||||
|
border.color: Theme.outlineMedium
|
||||||
|
border.width: 1
|
||||||
|
visible: root.showTargetData && root.targetData.length > 0
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: Theme.spacingM
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: Theme.spacingM
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
text: root.targetDataLabel.length > 0 ? root.targetDataLabel + ": " + root.targetData : root.targetData
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceTextMedium
|
||||||
|
elide: Text.ElideMiddle
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
maximumLineCount: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function launchApplication(app) {
|
||||||
|
if (!app) return
|
||||||
|
|
||||||
|
root.applicationSelected(app, root.targetData)
|
||||||
|
|
||||||
|
if (usageHistoryKey && app.appId) {
|
||||||
|
const usageHistory = SettingsData[usageHistoryKey] || {}
|
||||||
|
const currentCount = usageHistory[app.appId] ? usageHistory[app.appId].count : 0
|
||||||
|
usageHistory[app.appId] = {
|
||||||
|
count: currentCount + 1,
|
||||||
|
lastUsed: Date.now(),
|
||||||
|
name: app.name
|
||||||
|
}
|
||||||
|
SettingsData.set(usageHistoryKey, usageHistory)
|
||||||
|
}
|
||||||
|
|
||||||
|
root.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
quickshell/Modals/BrowserPickerModal.qml
Normal file
51
quickshell/Modals/BrowserPickerModal.qml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
import qs.Common
|
||||||
|
import qs.Modals
|
||||||
|
|
||||||
|
AppPickerModal {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property string url: ""
|
||||||
|
|
||||||
|
title: I18n.tr("Open with...")
|
||||||
|
targetData: url
|
||||||
|
targetDataLabel: ""
|
||||||
|
categoryFilter: ["WebBrowser", "X-WebBrowser"]
|
||||||
|
viewMode: SettingsData.browserPickerViewMode || "grid"
|
||||||
|
usageHistoryKey: "browserUsageHistory"
|
||||||
|
showTargetData: true
|
||||||
|
|
||||||
|
function shellEscape(str) {
|
||||||
|
return "'" + str.replace(/'/g, "'\\''") + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
onApplicationSelected: (app, url) => {
|
||||||
|
if (!app) return
|
||||||
|
|
||||||
|
let cmd = app.exec || ""
|
||||||
|
const escapedUrl = shellEscape(url)
|
||||||
|
|
||||||
|
let hasField = false
|
||||||
|
if (cmd.includes("%u")) { cmd = cmd.replace("%u", escapedUrl); hasField = true }
|
||||||
|
else if (cmd.includes("%U")) { cmd = cmd.replace("%U", escapedUrl); hasField = true }
|
||||||
|
else if (cmd.includes("%f")) { cmd = cmd.replace("%f", escapedUrl); hasField = true }
|
||||||
|
else if (cmd.includes("%F")) { cmd = cmd.replace("%F", escapedUrl); hasField = true }
|
||||||
|
|
||||||
|
cmd = cmd.replace(/%[ikc]/g, "")
|
||||||
|
|
||||||
|
if (!hasField) {
|
||||||
|
cmd += " " + escapedUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("BrowserPicker: Launching", cmd)
|
||||||
|
|
||||||
|
Quickshell.execDetached({
|
||||||
|
command: ["sh", "-c", cmd]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onViewModeChanged: {
|
||||||
|
SettingsData.set("browserPickerViewMode", viewMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,6 +44,7 @@ Item {
|
|||||||
property bool keepContentLoaded: false
|
property bool keepContentLoaded: false
|
||||||
property bool keepPopoutsOpen: false
|
property bool keepPopoutsOpen: false
|
||||||
property var customKeyboardFocus: null
|
property var customKeyboardFocus: null
|
||||||
|
property bool useOverlayLayer: false
|
||||||
readonly property alias contentWindow: contentWindow
|
readonly property alias contentWindow: contentWindow
|
||||||
readonly property alias backgroundWindow: backgroundWindow
|
readonly property alias backgroundWindow: backgroundWindow
|
||||||
|
|
||||||
@@ -148,6 +149,7 @@ Item {
|
|||||||
id: backgroundWindow
|
id: backgroundWindow
|
||||||
visible: false
|
visible: false
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
screen: root.effectiveScreen
|
||||||
|
|
||||||
WlrLayershell.namespace: root.layerNamespace + ":background"
|
WlrLayershell.namespace: root.layerNamespace + ":background"
|
||||||
WlrLayershell.layer: WlrLayershell.Top
|
WlrLayershell.layer: WlrLayershell.Top
|
||||||
@@ -207,9 +209,12 @@ Item {
|
|||||||
id: contentWindow
|
id: contentWindow
|
||||||
visible: false
|
visible: false
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
screen: root.effectiveScreen
|
||||||
|
|
||||||
WlrLayershell.namespace: root.layerNamespace
|
WlrLayershell.namespace: root.layerNamespace
|
||||||
WlrLayershell.layer: {
|
WlrLayershell.layer: {
|
||||||
|
if (root.useOverlayLayer)
|
||||||
|
return WlrLayershell.Overlay;
|
||||||
switch (Quickshell.env("DMS_MODAL_LAYER")) {
|
switch (Quickshell.env("DMS_MODAL_LAYER")) {
|
||||||
case "bottom":
|
case "bottom":
|
||||||
console.error("DankModal: 'bottom' layer is not valid for modals. Defaulting to 'top' layer.");
|
console.error("DankModal: 'bottom' layer is not valid for modals. Defaulting to 'top' layer.");
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import Quickshell.Hyprland
|
||||||
import Quickshell
|
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Modals.Common
|
import qs.Modals.Common
|
||||||
import qs.Services
|
import qs.Services
|
||||||
@@ -10,33 +9,52 @@ DankModal {
|
|||||||
id: root
|
id: root
|
||||||
|
|
||||||
layerNamespace: "dms:keybinds"
|
layerNamespace: "dms:keybinds"
|
||||||
|
useOverlayLayer: true
|
||||||
property real scrollStep: 60
|
property real scrollStep: 60
|
||||||
property var activeFlickable: null
|
property var activeFlickable: null
|
||||||
property real _maxW: Math.min(Screen.width * 0.92, 1200)
|
property real _maxW: Math.min(Screen.width * 0.92, 1200)
|
||||||
property real _maxH: Math.min(Screen.height * 0.92, 900)
|
property real _maxH: Math.min(Screen.height * 0.92, 900)
|
||||||
width: _maxW
|
modalWidth: _maxW
|
||||||
height: _maxH
|
modalHeight: _maxH
|
||||||
onBackgroundClicked: close()
|
onBackgroundClicked: close()
|
||||||
|
onOpened: () => Qt.callLater(() => modalFocusScope.forceActiveFocus())
|
||||||
|
|
||||||
|
HyprlandFocusGrab {
|
||||||
|
windows: [root.contentWindow]
|
||||||
|
active: CompositorService.isHyprland && root.shouldHaveFocus
|
||||||
|
}
|
||||||
|
|
||||||
function scrollDown() {
|
function scrollDown() {
|
||||||
if (!root.activeFlickable) return
|
if (!root.activeFlickable)
|
||||||
let newY = root.activeFlickable.contentY + scrollStep
|
return;
|
||||||
newY = Math.min(newY, root.activeFlickable.contentHeight - root.activeFlickable.height)
|
let newY = root.activeFlickable.contentY + scrollStep;
|
||||||
root.activeFlickable.contentY = newY
|
newY = Math.min(newY, root.activeFlickable.contentHeight - root.activeFlickable.height);
|
||||||
|
root.activeFlickable.contentY = newY;
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollUp() {
|
function scrollUp() {
|
||||||
if (!root.activeFlickable) return
|
if (!root.activeFlickable)
|
||||||
let newY = root.activeFlickable.contentY - root.scrollStep
|
return;
|
||||||
newY = Math.max(0, newY)
|
let newY = root.activeFlickable.contentY - root.scrollStep;
|
||||||
root.activeFlickable.contentY = newY
|
newY = Math.max(0, newY);
|
||||||
|
root.activeFlickable.contentY = newY;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shortcut { sequence: "Ctrl+j"; onActivated: root.scrollDown() }
|
modalFocusScope.Keys.onPressed: event => {
|
||||||
Shortcut { sequence: "Down"; onActivated: root.scrollDown() }
|
if (event.key === Qt.Key_J && event.modifiers & Qt.ControlModifier) {
|
||||||
Shortcut { sequence: "Ctrl+k"; onActivated: root.scrollUp() }
|
scrollDown();
|
||||||
Shortcut { sequence: "Up"; onActivated: root.scrollUp() }
|
event.accepted = true;
|
||||||
Shortcut { sequence: "Esc"; onActivated: root.close() }
|
} else if (event.key === Qt.Key_K && event.modifiers & Qt.ControlModifier) {
|
||||||
|
scrollUp();
|
||||||
|
event.accepted = true;
|
||||||
|
} else if (event.key === Qt.Key_Down) {
|
||||||
|
scrollDown();
|
||||||
|
event.accepted = true;
|
||||||
|
} else if (event.key === Qt.Key_Up) {
|
||||||
|
scrollUp();
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
content: Component {
|
content: Component {
|
||||||
Item {
|
Item {
|
||||||
@@ -66,25 +84,25 @@ DankModal {
|
|||||||
|
|
||||||
property var rawBinds: KeybindsService.keybinds.binds || {}
|
property var rawBinds: KeybindsService.keybinds.binds || {}
|
||||||
property var categories: {
|
property var categories: {
|
||||||
const processed = {}
|
const processed = {};
|
||||||
for (const cat in rawBinds) {
|
for (const cat in rawBinds) {
|
||||||
const binds = rawBinds[cat]
|
const binds = rawBinds[cat];
|
||||||
const subcats = {}
|
const subcats = {};
|
||||||
let hasSubcats = false
|
let hasSubcats = false;
|
||||||
|
|
||||||
for (let i = 0; i < binds.length; i++) {
|
for (let i = 0; i < binds.length; i++) {
|
||||||
const bind = binds[i]
|
const bind = binds[i];
|
||||||
if (bind.subcat) {
|
if (bind.subcat) {
|
||||||
hasSubcats = true
|
hasSubcats = true;
|
||||||
if (!subcats[bind.subcat]) {
|
if (!subcats[bind.subcat]) {
|
||||||
subcats[bind.subcat] = []
|
subcats[bind.subcat] = [];
|
||||||
}
|
}
|
||||||
subcats[bind.subcat].push(bind)
|
subcats[bind.subcat].push(bind);
|
||||||
} else {
|
} else {
|
||||||
if (!subcats["_root"]) {
|
if (!subcats["_root"]) {
|
||||||
subcats["_root"] = []
|
subcats["_root"] = [];
|
||||||
}
|
}
|
||||||
subcats["_root"].push(bind)
|
subcats["_root"].push(bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,21 +110,21 @@ DankModal {
|
|||||||
hasSubcats: hasSubcats,
|
hasSubcats: hasSubcats,
|
||||||
subcats: subcats,
|
subcats: subcats,
|
||||||
subcatKeys: Object.keys(subcats)
|
subcatKeys: Object.keys(subcats)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
return processed
|
return processed;
|
||||||
}
|
}
|
||||||
property var categoryKeys: Object.keys(categories)
|
property var categoryKeys: Object.keys(categories)
|
||||||
|
|
||||||
function distributeCategories(cols) {
|
function distributeCategories(cols) {
|
||||||
const columns = []
|
const columns = [];
|
||||||
for (let i = 0; i < cols; i++) {
|
for (let i = 0; i < cols; i++) {
|
||||||
columns.push([])
|
columns.push([]);
|
||||||
}
|
}
|
||||||
for (let i = 0; i < categoryKeys.length; i++) {
|
for (let i = 0; i < categoryKeys.length; i++) {
|
||||||
columns[i % cols].push(categoryKeys[i])
|
columns[i % cols].push(categoryKeys[i]);
|
||||||
}
|
}
|
||||||
return columns
|
return columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
@@ -136,92 +154,95 @@ DankModal {
|
|||||||
property string catName: modelData
|
property string catName: modelData
|
||||||
property var catData: mainFlickable.categories[catName]
|
property var catData: mainFlickable.categories[catName]
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: categoryColumn.catName
|
text: categoryColumn.catName
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
font.weight: Font.Bold
|
font.weight: Font.Bold
|
||||||
color: Theme.primary
|
color: Theme.primary
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 1
|
height: 1
|
||||||
color: Theme.primary
|
color: Theme.primary
|
||||||
opacity: 0.3
|
opacity: 0.3
|
||||||
}
|
}
|
||||||
|
|
||||||
Item { width: 1; height: Theme.spacingXS }
|
Item {
|
||||||
|
width: 1
|
||||||
Column {
|
height: Theme.spacingXS
|
||||||
width: parent.width
|
}
|
||||||
spacing: Theme.spacingM
|
|
||||||
|
|
||||||
Repeater {
|
|
||||||
model: categoryColumn.catData?.subcatKeys || []
|
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: Theme.spacingXS
|
spacing: Theme.spacingM
|
||||||
|
|
||||||
property string subcatName: modelData
|
Repeater {
|
||||||
property var subcatBinds: categoryColumn.catData?.subcats?.[subcatName] || []
|
model: categoryColumn.catData?.subcatKeys || []
|
||||||
|
|
||||||
StyledText {
|
Column {
|
||||||
visible: parent.subcatName !== "_root"
|
width: parent.width
|
||||||
text: parent.subcatName
|
spacing: Theme.spacingXS
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
|
||||||
font.weight: Font.DemiBold
|
|
||||||
color: Theme.primary
|
|
||||||
opacity: 0.7
|
|
||||||
}
|
|
||||||
|
|
||||||
Column {
|
property string subcatName: modelData
|
||||||
width: parent.width
|
property var subcatBinds: categoryColumn.catData?.subcats?.[subcatName] || []
|
||||||
spacing: Theme.spacingXS
|
|
||||||
|
|
||||||
Repeater {
|
StyledText {
|
||||||
model: parent.parent.subcatBinds
|
visible: parent.subcatName !== "_root"
|
||||||
|
text: parent.subcatName
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
font.weight: Font.DemiBold
|
||||||
|
color: Theme.primary
|
||||||
|
opacity: 0.7
|
||||||
|
}
|
||||||
|
|
||||||
Row {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: Theme.spacingS
|
spacing: Theme.spacingXS
|
||||||
|
|
||||||
StyledRect {
|
Repeater {
|
||||||
width: Math.min(140, parent.width * 0.42)
|
model: parent.parent.subcatBinds
|
||||||
height: 22
|
|
||||||
radius: 4
|
|
||||||
opacity: 0.9
|
|
||||||
|
|
||||||
StyledText {
|
Row {
|
||||||
anchors.centerIn: parent
|
width: parent.width
|
||||||
anchors.margins: 2
|
spacing: Theme.spacingS
|
||||||
width: parent.width - 4
|
|
||||||
color: Theme.secondary
|
StyledRect {
|
||||||
text: modelData.key || ""
|
width: Math.min(140, parent.width * 0.42)
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
height: 22
|
||||||
font.weight: Font.Medium
|
radius: 4
|
||||||
isMonospace: true
|
opacity: 0.9
|
||||||
elide: Text.ElideRight
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
StyledText {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
anchors.margins: 2
|
||||||
|
width: parent.width - 4
|
||||||
|
color: Theme.secondary
|
||||||
|
text: modelData.key || ""
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
font.weight: Font.Medium
|
||||||
|
isMonospace: true
|
||||||
|
elide: Text.ElideRight
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
width: parent.width - 150
|
||||||
|
text: modelData.desc || ""
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
opacity: 0.9
|
||||||
|
elide: Text.ElideRight
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
|
||||||
width: parent.width - 150
|
|
||||||
text: modelData.desc || ""
|
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
|
||||||
opacity: 0.9
|
|
||||||
elide: Text.ElideRight
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Effects
|
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
|
||||||
import Quickshell.Wayland
|
|
||||||
import Quickshell.Widgets
|
import Quickshell.Widgets
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Modules.AppDrawer
|
import qs.Modules.AppDrawer
|
||||||
@@ -16,7 +13,7 @@ DankPopout {
|
|||||||
layerNamespace: "dms:app-launcher"
|
layerNamespace: "dms:app-launcher"
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
open()
|
open();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupWidth: 520
|
popupWidth: 520
|
||||||
@@ -24,16 +21,22 @@ DankPopout {
|
|||||||
triggerWidth: 40
|
triggerWidth: 40
|
||||||
positioning: ""
|
positioning: ""
|
||||||
|
|
||||||
onBackgroundClicked: close()
|
onBackgroundClicked: {
|
||||||
|
if (contextMenu.visible) {
|
||||||
|
contextMenu.close();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
appLauncher.searchQuery = ""
|
appLauncher.searchQuery = "";
|
||||||
appLauncher.selectedIndex = 0
|
appLauncher.selectedIndex = 0;
|
||||||
appLauncher.setCategory(I18n.tr("All"))
|
appLauncher.setCategory(I18n.tr("All"));
|
||||||
if (contentLoader.item?.searchField) {
|
if (contentLoader.item?.searchField) {
|
||||||
contentLoader.item.searchField.text = ""
|
contentLoader.item.searchField.text = "";
|
||||||
contentLoader.item.searchField.forceActiveFocus()
|
contentLoader.item.searchField.forceActiveFocus();
|
||||||
}
|
}
|
||||||
|
contextMenu.parent = contentLoader.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppLauncher {
|
AppLauncher {
|
||||||
@@ -43,7 +46,7 @@ DankPopout {
|
|||||||
gridColumns: SettingsData.appLauncherGridColumns
|
gridColumns: SettingsData.appLauncherGridColumns
|
||||||
onAppLaunched: appDrawerPopout.close()
|
onAppLaunched: appDrawerPopout.close()
|
||||||
onViewModeSelected: function (mode) {
|
onViewModeSelected: function (mode) {
|
||||||
SettingsData.set("appLauncherViewMode", mode)
|
SettingsData.set("appLauncherViewMode", mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,19 +63,23 @@ DankPopout {
|
|||||||
|
|
||||||
// Multi-layer border effect
|
// Multi-layer border effect
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [{
|
model: [
|
||||||
|
{
|
||||||
"margin": -3,
|
"margin": -3,
|
||||||
"color": Qt.rgba(0, 0, 0, 0.05),
|
"color": Qt.rgba(0, 0, 0, 0.05),
|
||||||
"z": -3
|
"z": -3
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
"margin": -2,
|
"margin": -2,
|
||||||
"color": Qt.rgba(0, 0, 0, 0.08),
|
"color": Qt.rgba(0, 0, 0, 0.08),
|
||||||
"z": -2
|
"z": -2
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
"margin": 0,
|
"margin": 0,
|
||||||
"color": Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12),
|
"color": Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12),
|
||||||
"z": -1
|
"z": -1
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: modelData.margin
|
anchors.margins: modelData.margin
|
||||||
@@ -90,68 +97,67 @@ DankPopout {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
focus: true
|
focus: true
|
||||||
readonly property var keyMappings: {
|
readonly property var keyMappings: {
|
||||||
const mappings = {}
|
const mappings = {};
|
||||||
mappings[Qt.Key_Escape] = () => appDrawerPopout.close()
|
mappings[Qt.Key_Escape] = () => appDrawerPopout.close();
|
||||||
mappings[Qt.Key_Down] = () => appLauncher.selectNext()
|
mappings[Qt.Key_Down] = () => appLauncher.selectNext();
|
||||||
mappings[Qt.Key_Up] = () => appLauncher.selectPrevious()
|
mappings[Qt.Key_Up] = () => appLauncher.selectPrevious();
|
||||||
mappings[Qt.Key_Return] = () => appLauncher.launchSelected()
|
mappings[Qt.Key_Return] = () => appLauncher.launchSelected();
|
||||||
mappings[Qt.Key_Enter] = () => appLauncher.launchSelected()
|
mappings[Qt.Key_Enter] = () => appLauncher.launchSelected();
|
||||||
mappings[Qt.Key_Tab] = () => appLauncher.viewMode === "grid" ? appLauncher.selectNextInRow() : appLauncher.selectNext()
|
mappings[Qt.Key_Tab] = () => appLauncher.viewMode === "grid" ? appLauncher.selectNextInRow() : appLauncher.selectNext();
|
||||||
mappings[Qt.Key_Backtab] = () => appLauncher.viewMode === "grid" ? appLauncher.selectPreviousInRow() : appLauncher.selectPrevious()
|
mappings[Qt.Key_Backtab] = () => appLauncher.viewMode === "grid" ? appLauncher.selectPreviousInRow() : appLauncher.selectPrevious();
|
||||||
|
|
||||||
if (appLauncher.viewMode === "grid") {
|
if (appLauncher.viewMode === "grid") {
|
||||||
mappings[Qt.Key_Right] = () => appLauncher.selectNextInRow()
|
mappings[Qt.Key_Right] = () => appLauncher.selectNextInRow();
|
||||||
mappings[Qt.Key_Left] = () => appLauncher.selectPreviousInRow()
|
mappings[Qt.Key_Left] = () => appLauncher.selectPreviousInRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
return mappings
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onPressed: function (event) {
|
Keys.onPressed: function (event) {
|
||||||
if (keyMappings[event.key]) {
|
if (keyMappings[event.key]) {
|
||||||
keyMappings[event.key]()
|
keyMappings[event.key]();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_N && event.modifiers & Qt.ControlModifier) {
|
if (event.key === Qt.Key_N && event.modifiers & Qt.ControlModifier) {
|
||||||
appLauncher.selectNext()
|
appLauncher.selectNext();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_P && event.modifiers & Qt.ControlModifier) {
|
if (event.key === Qt.Key_P && event.modifiers & Qt.ControlModifier) {
|
||||||
appLauncher.selectPrevious()
|
appLauncher.selectPrevious();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_J && event.modifiers & Qt.ControlModifier) {
|
if (event.key === Qt.Key_J && event.modifiers & Qt.ControlModifier) {
|
||||||
appLauncher.selectNext()
|
appLauncher.selectNext();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_K && event.modifiers & Qt.ControlModifier) {
|
if (event.key === Qt.Key_K && event.modifiers & Qt.ControlModifier) {
|
||||||
appLauncher.selectPrevious()
|
appLauncher.selectPrevious();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appLauncher.viewMode === "grid") {
|
if (appLauncher.viewMode === "grid") {
|
||||||
if (event.key === Qt.Key_L && event.modifiers & Qt.ControlModifier) {
|
if (event.key === Qt.Key_L && event.modifiers & Qt.ControlModifier) {
|
||||||
appLauncher.selectNextInRow()
|
appLauncher.selectNextInRow();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_H && event.modifiers & Qt.ControlModifier) {
|
if (event.key === Qt.Key_H && event.modifiers & Qt.ControlModifier) {
|
||||||
appLauncher.selectPreviousInRow()
|
appLauncher.selectPreviousInRow();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
@@ -206,39 +212,39 @@ DankPopout {
|
|||||||
ignoreTabKeys: true
|
ignoreTabKeys: true
|
||||||
keyForwardTargets: [keyHandler]
|
keyForwardTargets: [keyHandler]
|
||||||
onTextEdited: {
|
onTextEdited: {
|
||||||
appLauncher.searchQuery = text
|
appLauncher.searchQuery = text;
|
||||||
}
|
}
|
||||||
Keys.onPressed: function (event) {
|
Keys.onPressed: function (event) {
|
||||||
if (event.key === Qt.Key_Escape) {
|
if (event.key === Qt.Key_Escape) {
|
||||||
appDrawerPopout.close()
|
appDrawerPopout.close();
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isEnterKey = [Qt.Key_Return, Qt.Key_Enter].includes(event.key)
|
const isEnterKey = [Qt.Key_Return, Qt.Key_Enter].includes(event.key);
|
||||||
const hasText = text.length > 0
|
const hasText = text.length > 0;
|
||||||
|
|
||||||
if (isEnterKey && hasText) {
|
if (isEnterKey && hasText) {
|
||||||
if (appLauncher.keyboardNavigationActive && appLauncher.model.count > 0) {
|
if (appLauncher.keyboardNavigationActive && appLauncher.model.count > 0) {
|
||||||
appLauncher.launchSelected()
|
appLauncher.launchSelected();
|
||||||
} else if (appLauncher.model.count > 0) {
|
} else if (appLauncher.model.count > 0) {
|
||||||
appLauncher.launchApp(appLauncher.model.get(0))
|
appLauncher.launchApp(appLauncher.model.get(0));
|
||||||
}
|
}
|
||||||
event.accepted = true
|
event.accepted = true;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const navigationKeys = [Qt.Key_Down, Qt.Key_Up, Qt.Key_Left, Qt.Key_Right, Qt.Key_Tab, Qt.Key_Backtab]
|
const navigationKeys = [Qt.Key_Down, Qt.Key_Up, Qt.Key_Left, Qt.Key_Right, Qt.Key_Tab, Qt.Key_Backtab];
|
||||||
const isNavigationKey = navigationKeys.includes(event.key)
|
const isNavigationKey = navigationKeys.includes(event.key);
|
||||||
const isEmptyEnter = isEnterKey && !hasText
|
const isEmptyEnter = isEnterKey && !hasText;
|
||||||
|
|
||||||
event.accepted = !(isNavigationKey || isEmptyEnter)
|
event.accepted = !(isNavigationKey || isEmptyEnter);
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
function onShouldBeVisibleChanged() {
|
function onShouldBeVisibleChanged() {
|
||||||
if (!appDrawerPopout.shouldBeVisible) {
|
if (!appDrawerPopout.shouldBeVisible) {
|
||||||
searchField.focus = false
|
searchField.focus = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +273,7 @@ DankPopout {
|
|||||||
options: appLauncher.categories
|
options: appLauncher.categories
|
||||||
optionIcons: appLauncher.categoryIcons
|
optionIcons: appLauncher.categoryIcons
|
||||||
onValueChanged: function (value) {
|
onValueChanged: function (value) {
|
||||||
appLauncher.setCategory(value)
|
appLauncher.setCategory(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,7 +295,7 @@ DankPopout {
|
|||||||
iconColor: appLauncher.viewMode === "list" ? Theme.primary : Theme.surfaceText
|
iconColor: appLauncher.viewMode === "list" ? Theme.primary : Theme.surfaceText
|
||||||
backgroundColor: appLauncher.viewMode === "list" ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
|
backgroundColor: appLauncher.viewMode === "list" ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
appLauncher.setViewMode("list")
|
appLauncher.setViewMode("list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +307,7 @@ DankPopout {
|
|||||||
iconColor: appLauncher.viewMode === "grid" ? Theme.primary : Theme.surfaceText
|
iconColor: appLauncher.viewMode === "grid" ? Theme.primary : Theme.surfaceText
|
||||||
backgroundColor: appLauncher.viewMode === "grid" ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
|
backgroundColor: appLauncher.viewMode === "grid" ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : "transparent"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
appLauncher.setViewMode("grid")
|
appLauncher.setViewMode("grid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,10 +316,10 @@ DankPopout {
|
|||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: {
|
height: {
|
||||||
let usedHeight = 40 + Theme.spacingS
|
let usedHeight = 40 + Theme.spacingS;
|
||||||
usedHeight += 52 + Theme.spacingS
|
usedHeight += 52 + Theme.spacingS;
|
||||||
usedHeight += (searchField.text.length === 0 ? 40 : 0)
|
usedHeight += (searchField.text.length === 0 ? 40 : 0);
|
||||||
return parent.height - usedHeight
|
return parent.height - usedHeight;
|
||||||
}
|
}
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
@@ -334,14 +340,13 @@ DankPopout {
|
|||||||
|
|
||||||
function ensureVisible(index) {
|
function ensureVisible(index) {
|
||||||
if (index < 0 || index >= count)
|
if (index < 0 || index >= count)
|
||||||
return
|
return;
|
||||||
|
var itemY = index * (itemHeight + itemSpacing);
|
||||||
var itemY = index * (itemHeight + itemSpacing)
|
var itemBottom = itemY + itemHeight;
|
||||||
var itemBottom = itemY + itemHeight
|
|
||||||
if (itemY < contentY)
|
if (itemY < contentY)
|
||||||
contentY = itemY
|
contentY = itemY;
|
||||||
else if (itemBottom > contentY + height)
|
else if (itemBottom > contentY + height)
|
||||||
contentY = itemBottom - height
|
contentY = itemBottom - height;
|
||||||
}
|
}
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -360,17 +365,17 @@ DankPopout {
|
|||||||
|
|
||||||
onCurrentIndexChanged: {
|
onCurrentIndexChanged: {
|
||||||
if (keyboardNavigationActive)
|
if (keyboardNavigationActive)
|
||||||
ensureVisible(currentIndex)
|
ensureVisible(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
onItemClicked: function (index, modelData) {
|
onItemClicked: function (index, modelData) {
|
||||||
appLauncher.launchApp(modelData)
|
appLauncher.launchApp(modelData);
|
||||||
}
|
}
|
||||||
onItemRightClicked: function (index, modelData, mouseX, mouseY) {
|
onItemRightClicked: function (index, modelData, mouseX, mouseY) {
|
||||||
contextMenu.show(mouseX, mouseY, modelData)
|
contextMenu.show(mouseX, mouseY, modelData);
|
||||||
}
|
}
|
||||||
onKeyboardNavigationReset: {
|
onKeyboardNavigationReset: {
|
||||||
appLauncher.keyboardNavigationActive = false
|
appLauncher.keyboardNavigationActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: AppLauncherListDelegate {
|
delegate: AppLauncherListDelegate {
|
||||||
@@ -390,8 +395,8 @@ DankPopout {
|
|||||||
iconFallbackBottomMargin: Theme.spacingM
|
iconFallbackBottomMargin: Theme.spacingM
|
||||||
onItemClicked: (idx, modelData) => appList.itemClicked(idx, modelData)
|
onItemClicked: (idx, modelData) => appList.itemClicked(idx, modelData)
|
||||||
onItemRightClicked: (idx, modelData, mouseX, mouseY) => {
|
onItemRightClicked: (idx, modelData, mouseX, mouseY) => {
|
||||||
const panelPos = contextMenu.parent.mapFromItem(null, mouseX, mouseY)
|
const panelPos = contextMenu.parent.mapFromItem(null, mouseX, mouseY);
|
||||||
appList.itemRightClicked(idx, modelData, panelPos.x, panelPos.y)
|
appList.itemRightClicked(idx, modelData, panelPos.x, panelPos.y);
|
||||||
}
|
}
|
||||||
onKeyboardNavigationReset: appList.keyboardNavigationReset
|
onKeyboardNavigationReset: appList.keyboardNavigationReset
|
||||||
}
|
}
|
||||||
@@ -423,14 +428,13 @@ DankPopout {
|
|||||||
|
|
||||||
function ensureVisible(index) {
|
function ensureVisible(index) {
|
||||||
if (index < 0 || index >= count)
|
if (index < 0 || index >= count)
|
||||||
return
|
return;
|
||||||
|
var itemY = Math.floor(index / actualColumns) * cellHeight;
|
||||||
var itemY = Math.floor(index / actualColumns) * cellHeight
|
var itemBottom = itemY + cellHeight;
|
||||||
var itemBottom = itemY + cellHeight
|
|
||||||
if (itemY < contentY)
|
if (itemY < contentY)
|
||||||
contentY = itemY
|
contentY = itemY;
|
||||||
else if (itemBottom > contentY + height)
|
else if (itemBottom > contentY + height)
|
||||||
contentY = itemBottom - height
|
contentY = itemBottom - height;
|
||||||
}
|
}
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -451,17 +455,17 @@ DankPopout {
|
|||||||
|
|
||||||
onCurrentIndexChanged: {
|
onCurrentIndexChanged: {
|
||||||
if (keyboardNavigationActive)
|
if (keyboardNavigationActive)
|
||||||
ensureVisible(currentIndex)
|
ensureVisible(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
onItemClicked: function (index, modelData) {
|
onItemClicked: function (index, modelData) {
|
||||||
appLauncher.launchApp(modelData)
|
appLauncher.launchApp(modelData);
|
||||||
}
|
}
|
||||||
onItemRightClicked: function (index, modelData, mouseX, mouseY) {
|
onItemRightClicked: function (index, modelData, mouseX, mouseY) {
|
||||||
contextMenu.show(mouseX, mouseY, modelData)
|
contextMenu.show(mouseX, mouseY, modelData);
|
||||||
}
|
}
|
||||||
onKeyboardNavigationReset: {
|
onKeyboardNavigationReset: {
|
||||||
appLauncher.keyboardNavigationActive = false
|
appLauncher.keyboardNavigationActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: AppLauncherGridDelegate {
|
delegate: AppLauncherGridDelegate {
|
||||||
@@ -484,8 +488,8 @@ DankPopout {
|
|||||||
iconMaterialSizeAdjustment: Theme.spacingL
|
iconMaterialSizeAdjustment: Theme.spacingL
|
||||||
onItemClicked: (idx, modelData) => appGrid.itemClicked(idx, modelData)
|
onItemClicked: (idx, modelData) => appGrid.itemClicked(idx, modelData)
|
||||||
onItemRightClicked: (idx, modelData, mouseX, mouseY) => {
|
onItemRightClicked: (idx, modelData, mouseX, mouseY) => {
|
||||||
const panelPos = contextMenu.parent.mapFromItem(null, mouseX, mouseY)
|
const panelPos = contextMenu.parent.mapFromItem(null, mouseX, mouseY);
|
||||||
appGrid.itemRightClicked(idx, modelData, panelPos.x, panelPos.y)
|
appGrid.itemRightClicked(idx, modelData, panelPos.x, panelPos.y);
|
||||||
}
|
}
|
||||||
onKeyboardNavigationReset: appGrid.keyboardNavigationReset
|
onKeyboardNavigationReset: appGrid.keyboardNavigationReset
|
||||||
}
|
}
|
||||||
@@ -493,6 +497,13 @@ DankPopout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: contextMenu.visible
|
||||||
|
z: 998
|
||||||
|
onClicked: contextMenu.hide()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,14 +516,32 @@ DankPopout {
|
|||||||
readonly property bool isPinned: appId && SessionData.isPinnedApp(appId)
|
readonly property bool isPinned: appId && SessionData.isPinnedApp(appId)
|
||||||
|
|
||||||
function show(x, y, app) {
|
function show(x, y, app) {
|
||||||
currentApp = app
|
currentApp = app;
|
||||||
contextMenu.x = x + 4
|
let finalX = x + 4;
|
||||||
contextMenu.y = y + 4
|
let finalY = y + 4;
|
||||||
contextMenu.open()
|
|
||||||
|
if (contextMenu.parent) {
|
||||||
|
const parentWidth = contextMenu.parent.width;
|
||||||
|
const parentHeight = contextMenu.parent.height;
|
||||||
|
const menuWidth = contextMenu.width;
|
||||||
|
const menuHeight = contextMenu.height;
|
||||||
|
|
||||||
|
if (finalX + menuWidth > parentWidth) {
|
||||||
|
finalX = Math.max(0, parentWidth - menuWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finalY + menuHeight > parentHeight) {
|
||||||
|
finalY = Math.max(0, parentHeight - menuHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contextMenu.x = finalX;
|
||||||
|
contextMenu.y = finalY;
|
||||||
|
contextMenu.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide() {
|
function hide() {
|
||||||
contextMenu.close()
|
contextMenu.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
width: Math.max(180, menuColumn.implicitWidth + Theme.spacingS * 2)
|
width: Math.max(180, menuColumn.implicitWidth + Theme.spacingS * 2)
|
||||||
@@ -604,15 +633,15 @@ DankPopout {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!contextMenu.desktopEntry) {
|
if (!contextMenu.desktopEntry) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contextMenu.isPinned) {
|
if (contextMenu.isPinned) {
|
||||||
SessionData.removePinnedApp(contextMenu.appId)
|
SessionData.removePinnedApp(contextMenu.appId);
|
||||||
} else {
|
} else {
|
||||||
SessionData.addPinnedApp(contextMenu.appId)
|
SessionData.addPinnedApp(contextMenu.appId);
|
||||||
}
|
}
|
||||||
contextMenu.hide()
|
contextMenu.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -678,12 +707,12 @@ DankPopout {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (modelData && contextMenu.desktopEntry) {
|
if (modelData && contextMenu.desktopEntry) {
|
||||||
SessionService.launchDesktopAction(contextMenu.desktopEntry, modelData)
|
SessionService.launchDesktopAction(contextMenu.desktopEntry, modelData);
|
||||||
if (contextMenu.currentApp) {
|
if (contextMenu.currentApp) {
|
||||||
appLauncher.appLaunched(contextMenu.currentApp)
|
appLauncher.appLaunched(contextMenu.currentApp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contextMenu.hide()
|
contextMenu.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -741,9 +770,9 @@ DankPopout {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (contextMenu.currentApp)
|
if (contextMenu.currentApp)
|
||||||
appLauncher.launchApp(contextMenu.currentApp)
|
appLauncher.launchApp(contextMenu.currentApp);
|
||||||
|
|
||||||
contextMenu.hide()
|
contextMenu.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -801,35 +830,15 @@ DankPopout {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (contextMenu.desktopEntry) {
|
if (contextMenu.desktopEntry) {
|
||||||
SessionService.launchDesktopEntry(contextMenu.desktopEntry, true)
|
SessionService.launchDesktopEntry(contextMenu.desktopEntry, true);
|
||||||
if (contextMenu.currentApp) {
|
if (contextMenu.currentApp) {
|
||||||
appLauncher.appLaunched(contextMenu.currentApp)
|
appLauncher.appLaunched(contextMenu.currentApp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contextMenu.hide()
|
contextMenu.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
visible: contextMenu.visible
|
|
||||||
z: 999
|
|
||||||
onClicked: {
|
|
||||||
contextMenu.hide()
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
x: contextMenu.x
|
|
||||||
y: contextMenu.y
|
|
||||||
width: contextMenu.width
|
|
||||||
height: contextMenu.height
|
|
||||||
onClicked: {
|
|
||||||
|
|
||||||
// Prevent closing when clicking on the menu itself
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
186
quickshell/Modules/DankBar/Widgets/WeatherForecastCard.qml
Normal file
186
quickshell/Modules/DankBar/Widgets/WeatherForecastCard.qml
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
import QtQuick
|
||||||
|
import qs.Common
|
||||||
|
import qs.Services
|
||||||
|
import qs.Widgets
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: root
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
|
||||||
|
property var date: null
|
||||||
|
property var daily: true
|
||||||
|
property var forecastData: null
|
||||||
|
property var dense: false
|
||||||
|
|
||||||
|
readonly property bool isCurrent: {
|
||||||
|
if (daily) {
|
||||||
|
date ? WeatherService.calendarDayDifference(new Date(), date) === 0 : false;
|
||||||
|
} else {
|
||||||
|
date ? WeatherService.calendarHourDifference(new Date(), date) === 0 : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly property string dateText: (daily ? root.forecastData?.day : root.forecastData?.time) ?? "--"
|
||||||
|
|
||||||
|
readonly property var minTemp: WeatherService.formatTemp(root.forecastData?.tempMin)
|
||||||
|
readonly property var maxTemp: WeatherService.formatTemp(root.forecastData?.tempMax)
|
||||||
|
readonly property string minMaxTempText: (minTemp ?? "--") + "/" + (maxTemp ?? "--")
|
||||||
|
|
||||||
|
readonly property var temp: WeatherService.formatTemp(root.forecastData?.temp)
|
||||||
|
readonly property string tempText: temp ?? "--"
|
||||||
|
|
||||||
|
readonly property var feelsLikeTemp: WeatherService.formatTemp(root.forecastData?.feelsLike)
|
||||||
|
readonly property string feelsLikeText: feelsLikeTemp ?? "--"
|
||||||
|
|
||||||
|
readonly property var humidity: WeatherService.formatPercent(root.forecastData?.humidity)
|
||||||
|
readonly property string humidityText: humidity ?? "--"
|
||||||
|
|
||||||
|
readonly property var wind: WeatherService.formatSpeed(root.forecastData?.wind)
|
||||||
|
readonly property string windText: wind ?? "--"
|
||||||
|
|
||||||
|
readonly property var pressure: WeatherService.formatPressure(root.forecastData?.pressure)
|
||||||
|
readonly property string pressureText: pressure ?? "--"
|
||||||
|
|
||||||
|
readonly property var precipitation: root.forecastData?.precipitationProbability
|
||||||
|
readonly property string precipitationText: precipitation + "%" ?? "--"
|
||||||
|
|
||||||
|
readonly property var visibility: WeatherService.formatVisibility(root.forecastData?.visibility)
|
||||||
|
readonly property string visibilityText: visibility ?? "--"
|
||||||
|
|
||||||
|
readonly property var values: daily ? [] : [
|
||||||
|
{
|
||||||
|
// 'name': "Temperature",
|
||||||
|
// 'text': root.tempText,
|
||||||
|
// 'icon': "thermometer"
|
||||||
|
// }, {
|
||||||
|
// 'name': "Feels Like",
|
||||||
|
// 'text': root.feelsLikeText,
|
||||||
|
// 'icon': "thermostat"
|
||||||
|
// }, {
|
||||||
|
'name': I18n.tr("Humidity"),
|
||||||
|
'text': root.humidityText,
|
||||||
|
'icon': "humidity_low"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': I18n.tr("Wind Speed"),
|
||||||
|
'text': root.windText,
|
||||||
|
'icon': "air"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': I18n.tr("Pressure"),
|
||||||
|
'text': root.pressureText,
|
||||||
|
'icon': "speed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': I18n.tr("Precipitation Chance"),
|
||||||
|
'text': root.precipitationText,
|
||||||
|
'icon': "rainy"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': I18n.tr("Visibility"),
|
||||||
|
'text': root.visibilityText,
|
||||||
|
'icon': "wb_sunny"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
color: isCurrent ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
|
||||||
|
border.color: isCurrent ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3) : "transparent"
|
||||||
|
border.width: isCurrent ? 1 : 0
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: Theme.spacingXS
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: root.forecastData != null ? root.dateText : I18n.tr("Forecast Not Available")
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: root.isCurrent ? Theme.primary : (root.forecastData ? Theme.surfaceText : Theme.outline)
|
||||||
|
font.weight: root.isCurrent ? Font.Medium : Font.Normal
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
spacing: Theme.spacingM
|
||||||
|
visible: root.forecastData != null
|
||||||
|
|
||||||
|
Column {
|
||||||
|
spacing: Theme.spacingXS
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
name: root.forecastData ? WeatherService.getWeatherIcon(root.forecastData.wCode || 0, root.forecastData.isDay ?? true) : "cloud"
|
||||||
|
size: Theme.iconSize
|
||||||
|
color: root.isCurrent ? Theme.primary : Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.8)
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: root.daily ? root.minMaxTempText : root.tempText
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: root.isCurrent ? Theme.primary : Theme.surfaceText
|
||||||
|
font.weight: Font.Medium
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: root.feelsLikeText
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: root.isCurrent ? Theme.primary : Theme.surfaceText
|
||||||
|
font.weight: Font.Medium
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
visible: !root.daily
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: detailsColumn
|
||||||
|
spacing: 2
|
||||||
|
visible: !root.dense
|
||||||
|
width: implicitWidth
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State {
|
||||||
|
name: "dense"
|
||||||
|
when: root.dense
|
||||||
|
PropertyChanges {
|
||||||
|
target: detailsColumn
|
||||||
|
opacity: 0
|
||||||
|
width: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
transitions: [
|
||||||
|
Transition {
|
||||||
|
NumberAnimation {
|
||||||
|
properties: "opacity,width"
|
||||||
|
duration: Theme.shortDuration
|
||||||
|
easing.type: Theme.standardEasing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: root.values.length
|
||||||
|
Row {
|
||||||
|
spacing: 2
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
name: root.values[index].icon
|
||||||
|
size: 8
|
||||||
|
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
text: root.values[index].text
|
||||||
|
font.pixelSize: Theme.fontSizeSmall - 2
|
||||||
|
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -226,8 +226,8 @@ DankPopout {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root.currentTabIndex === 2 && wallpaperTab.handleKeyEvent) {
|
if (root.currentTabIndex === 2 && wallpaperLoader.item?.handleKeyEvent) {
|
||||||
if (wallpaperTab.handleKeyEvent(event)) {
|
if (wallpaperLoader.item.handleKeyEvent(event)) {
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ DankPopout {
|
|||||||
let settingsIndex = SettingsData.weatherEnabled ? 4 : 3;
|
let settingsIndex = SettingsData.weatherEnabled ? 4 : 3;
|
||||||
if (index === settingsIndex) {
|
if (index === settingsIndex) {
|
||||||
dashVisible = false;
|
dashVisible = false;
|
||||||
PopoutService.openSettings();
|
settingsModal.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,71 +316,84 @@ DankPopout {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
implicitHeight: {
|
implicitHeight: {
|
||||||
if (currentIndex === 0)
|
if (currentIndex === 0)
|
||||||
return overviewTab.implicitHeight;
|
return overviewLoader.item?.implicitHeight ?? 410;
|
||||||
if (currentIndex === 1)
|
if (currentIndex === 1)
|
||||||
return mediaTab.implicitHeight;
|
return mediaLoader.item?.implicitHeight ?? 410;
|
||||||
if (currentIndex === 2)
|
if (currentIndex === 2)
|
||||||
return wallpaperTab.implicitHeight;
|
return wallpaperLoader.item?.implicitHeight ?? 410;
|
||||||
if (SettingsData.weatherEnabled && currentIndex === 3)
|
if (SettingsData.weatherEnabled && currentIndex === 3)
|
||||||
return weatherTab.implicitHeight;
|
return weatherLoader.item?.implicitHeight ?? 410;
|
||||||
return overviewTab.implicitHeight;
|
return 410;
|
||||||
}
|
}
|
||||||
currentIndex: root.currentTabIndex
|
currentIndex: root.currentTabIndex
|
||||||
|
|
||||||
OverviewTab {
|
Loader {
|
||||||
id: overviewTab
|
id: overviewLoader
|
||||||
|
active: root.currentTabIndex === 0
|
||||||
onCloseDash: {
|
sourceComponent: Component {
|
||||||
root.dashVisible = false;
|
OverviewTab {
|
||||||
}
|
onCloseDash: root.dashVisible = false
|
||||||
|
onSwitchToWeatherTab: {
|
||||||
onSwitchToWeatherTab: {
|
if (SettingsData.weatherEnabled) {
|
||||||
if (SettingsData.weatherEnabled) {
|
tabBar.currentIndex = 3;
|
||||||
tabBar.currentIndex = 3;
|
tabBar.tabClicked(3);
|
||||||
tabBar.tabClicked(3);
|
}
|
||||||
|
}
|
||||||
|
onSwitchToMediaTab: {
|
||||||
|
tabBar.currentIndex = 1;
|
||||||
|
tabBar.tabClicked(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onSwitchToMediaTab: {
|
Loader {
|
||||||
tabBar.currentIndex = 1;
|
id: mediaLoader
|
||||||
tabBar.tabClicked(1);
|
active: root.currentTabIndex === 1
|
||||||
|
sourceComponent: Component {
|
||||||
|
MediaPlayerTab {
|
||||||
|
targetScreen: root.screen
|
||||||
|
popoutX: root.alignedX
|
||||||
|
popoutY: root.alignedY
|
||||||
|
popoutWidth: root.alignedWidth
|
||||||
|
popoutHeight: root.alignedHeight
|
||||||
|
contentOffsetY: Theme.spacingM + 48 + Theme.spacingS + Theme.spacingXS
|
||||||
|
Component.onCompleted: root.__mediaTabRef = this
|
||||||
|
onShowVolumeDropdown: (pos, screen, rightEdge, player, players) => {
|
||||||
|
root.__showVolumeDropdown(pos, rightEdge, player, players);
|
||||||
|
}
|
||||||
|
onShowAudioDevicesDropdown: (pos, screen, rightEdge) => {
|
||||||
|
root.__showAudioDevicesDropdown(pos, rightEdge);
|
||||||
|
}
|
||||||
|
onShowPlayersDropdown: (pos, screen, rightEdge, player, players) => {
|
||||||
|
root.__showPlayersDropdown(pos, rightEdge, player, players);
|
||||||
|
}
|
||||||
|
onHideDropdowns: root.__hideDropdowns()
|
||||||
|
onVolumeButtonExited: root.__startCloseTimer()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaPlayerTab {
|
Loader {
|
||||||
id: mediaTab
|
id: wallpaperLoader
|
||||||
targetScreen: root.screen
|
|
||||||
popoutX: root.alignedX
|
|
||||||
popoutY: root.alignedY
|
|
||||||
popoutWidth: root.alignedWidth
|
|
||||||
popoutHeight: root.alignedHeight
|
|
||||||
contentOffsetY: Theme.spacingM + 48 + Theme.spacingS + Theme.spacingXS
|
|
||||||
Component.onCompleted: root.__mediaTabRef = this
|
|
||||||
onShowVolumeDropdown: (pos, screen, rightEdge, player, players) => {
|
|
||||||
root.__showVolumeDropdown(pos, rightEdge, player, players);
|
|
||||||
}
|
|
||||||
onShowAudioDevicesDropdown: (pos, screen, rightEdge) => {
|
|
||||||
root.__showAudioDevicesDropdown(pos, rightEdge);
|
|
||||||
}
|
|
||||||
onShowPlayersDropdown: (pos, screen, rightEdge, player, players) => {
|
|
||||||
root.__showPlayersDropdown(pos, rightEdge, player, players);
|
|
||||||
}
|
|
||||||
onHideDropdowns: root.__hideDropdowns()
|
|
||||||
onVolumeButtonExited: root.__startCloseTimer()
|
|
||||||
}
|
|
||||||
|
|
||||||
WallpaperTab {
|
|
||||||
id: wallpaperTab
|
|
||||||
active: root.currentTabIndex === 2
|
active: root.currentTabIndex === 2
|
||||||
tabBarItem: tabBar
|
sourceComponent: Component {
|
||||||
keyForwardTarget: mainContainer
|
WallpaperTab {
|
||||||
targetScreen: root.screen
|
active: true
|
||||||
parentPopout: root
|
tabBarItem: tabBar
|
||||||
|
keyForwardTarget: mainContainer
|
||||||
|
targetScreen: root.triggerScreen
|
||||||
|
parentPopout: root
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WeatherTab {
|
Loader {
|
||||||
id: weatherTab
|
id: weatherLoader
|
||||||
visible: SettingsData.weatherEnabled && root.currentTabIndex === 3
|
active: SettingsData.weatherEnabled && root.currentTabIndex === 3
|
||||||
|
sourceComponent: Component {
|
||||||
|
WeatherTab {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,11 +79,16 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onActivePlayerChanged: {
|
onActivePlayerChanged: {
|
||||||
|
if (!activePlayer) {
|
||||||
|
isSwitching = false;
|
||||||
|
_switchHold = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
isSwitching = true;
|
isSwitching = true;
|
||||||
_switchHold = true;
|
_switchHold = true;
|
||||||
paletteReady = false;
|
paletteReady = false;
|
||||||
_switchHoldTimer.restart();
|
_switchHoldTimer.restart();
|
||||||
if (activePlayer && activePlayer.trackArtUrl) {
|
if (activePlayer.trackArtUrl) {
|
||||||
loadArtwork(activePlayer.trackArtUrl);
|
loadArtwork(activePlayer.trackArtUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -49,10 +49,12 @@ Singleton {
|
|||||||
signal extWorkspaceStateUpdate(var data)
|
signal extWorkspaceStateUpdate(var data)
|
||||||
signal wlrOutputStateUpdate(var data)
|
signal wlrOutputStateUpdate(var data)
|
||||||
signal evdevStateUpdate(var data)
|
signal evdevStateUpdate(var data)
|
||||||
|
signal openUrlRequested(string url)
|
||||||
|
signal appPickerRequested(var data)
|
||||||
|
|
||||||
property bool capsLockState: false
|
property bool capsLockState: false
|
||||||
|
|
||||||
property var activeSubscriptions: ["network", "network.credentials", "loginctl", "freedesktop", "gamma", "bluetooth", "bluetooth.pairing", "dwl", "brightness", "wlroutput", "evdev"]
|
property var activeSubscriptions: ["network", "network.credentials", "loginctl", "freedesktop", "gamma", "bluetooth", "bluetooth.pairing", "dwl", "brightness", "wlroutput", "evdev", "browser"]
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (socketPath && socketPath.length > 0) {
|
if (socketPath && socketPath.length > 0) {
|
||||||
@@ -265,9 +267,9 @@ Singleton {
|
|||||||
|
|
||||||
function removeSubscription(service) {
|
function removeSubscription(service) {
|
||||||
if (activeSubscriptions.includes("all")) {
|
if (activeSubscriptions.includes("all")) {
|
||||||
const allServices = ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "dwl", "brightness", "extworkspace"];
|
const allServices = ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "dwl", "brightness", "extworkspace", "browser"]
|
||||||
const filtered = allServices.filter(s => s !== service);
|
const filtered = allServices.filter(s => s !== service)
|
||||||
subscribe(filtered);
|
subscribe(filtered)
|
||||||
} else {
|
} else {
|
||||||
const filtered = activeSubscriptions.filter(s => s !== service);
|
const filtered = activeSubscriptions.filter(s => s !== service);
|
||||||
if (filtered.length === 0) {
|
if (filtered.length === 0) {
|
||||||
@@ -287,9 +289,9 @@ Singleton {
|
|||||||
excludeServices = [excludeServices];
|
excludeServices = [excludeServices];
|
||||||
}
|
}
|
||||||
|
|
||||||
const allServices = ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "cups", "dwl", "brightness", "extworkspace"];
|
const allServices = ["network", "loginctl", "freedesktop", "gamma", "bluetooth", "cups", "dwl", "brightness", "extworkspace", "browser"]
|
||||||
const filtered = allServices.filter(s => !excludeServices.includes(s));
|
const filtered = allServices.filter(s => !excludeServices.includes(s))
|
||||||
subscribe(filtered);
|
subscribe(filtered)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubscriptionEvent(response) {
|
function handleSubscriptionEvent(response) {
|
||||||
@@ -353,7 +355,17 @@ Singleton {
|
|||||||
if (data.capsLock !== undefined) {
|
if (data.capsLock !== undefined) {
|
||||||
capsLockState = data.capsLock;
|
capsLockState = data.capsLock;
|
||||||
}
|
}
|
||||||
evdevStateUpdate(data);
|
evdevStateUpdate(data)
|
||||||
|
} else if (service === "browser.open_requested") {
|
||||||
|
if (data.target) {
|
||||||
|
if (data.requestType === "url" || !data.requestType) {
|
||||||
|
openUrlRequested(data.target)
|
||||||
|
} else {
|
||||||
|
appPickerRequested(data)
|
||||||
|
}
|
||||||
|
} else if (data.url) {
|
||||||
|
openUrlRequested(data.url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,9 @@ StyledRect {
|
|||||||
property color iconColor: Theme.surfaceText
|
property color iconColor: Theme.surfaceText
|
||||||
property color backgroundColor: "transparent"
|
property color backgroundColor: "transparent"
|
||||||
property bool circular: true
|
property bool circular: true
|
||||||
|
property bool enabled: true
|
||||||
property int buttonSize: 32
|
property int buttonSize: 32
|
||||||
|
property var tooltipText: null
|
||||||
|
|
||||||
signal clicked
|
signal clicked
|
||||||
signal entered
|
signal entered
|
||||||
@@ -29,10 +31,12 @@ StyledRect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StateLayer {
|
StateLayer {
|
||||||
|
disabled: !root.enabled
|
||||||
stateColor: Theme.primary
|
stateColor: Theme.primary
|
||||||
cornerRadius: root.radius
|
cornerRadius: root.radius
|
||||||
onClicked: root.clicked()
|
onClicked: root.clicked()
|
||||||
onEntered: root.entered()
|
onEntered: root.entered()
|
||||||
onExited: root.exited()
|
onExited: root.exited()
|
||||||
|
tooltipText: tooltipText
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
67
quickshell/Widgets/DankNumberStepper.qml
Normal file
67
quickshell/Widgets/DankNumberStepper.qml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import QtCore
|
||||||
|
import QtQuick
|
||||||
|
import qs.Common
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: root
|
||||||
|
property string text: ""
|
||||||
|
property var incrementTooltipText: ""
|
||||||
|
property var decrementTooltipText: ""
|
||||||
|
property var onIncrement: undefined
|
||||||
|
property var onDecrement: undefined
|
||||||
|
property string incrementIconName: "keyboard_arrow_up"
|
||||||
|
property string decrementIconName: "keyboard_arrow_down"
|
||||||
|
|
||||||
|
property bool incrementEnabled: true
|
||||||
|
property bool decrementEnabled: true
|
||||||
|
|
||||||
|
property color textColor: Theme.surfaceText
|
||||||
|
property color iconColor: Theme.withAlpha(Theme.surfaceText, 0.5)
|
||||||
|
property color backgroundColor: Theme.primary
|
||||||
|
|
||||||
|
property int textSize: Theme.fontSizeSmall
|
||||||
|
property var iconSize: 12
|
||||||
|
property int buttonSize: 20
|
||||||
|
property int horizontalPadding: Theme.spacingL
|
||||||
|
|
||||||
|
readonly property bool effectiveIncrementEnabled: root.onIncrement ? root.incrementEnabled : false
|
||||||
|
readonly property bool effectiveDecrementEnabled: root.onDecrement ? root.decrementEnabled : false
|
||||||
|
|
||||||
|
|
||||||
|
width: Math.max(buttonSize * 2, root.implicitWidth + horizontalPadding * 2)
|
||||||
|
spacing: 4
|
||||||
|
|
||||||
|
DankActionButton {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
enabled: root.effectiveIncrementEnabled
|
||||||
|
iconColor: root.effectiveIncrementEnabled ? root.iconColor : Theme.blendAlpha(root.iconColor, 0.5)
|
||||||
|
iconSize: root.iconSize
|
||||||
|
buttonSize: root.buttonSize
|
||||||
|
iconName: root.incrementIconName
|
||||||
|
onClicked: if (typeof root.onIncrement === 'function') root.onIncrement()
|
||||||
|
tooltipText: root.incrementTooltipText
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
Item { width: 5; height: 1 }
|
||||||
|
StyledText {
|
||||||
|
isMonospace: true
|
||||||
|
text: root.text
|
||||||
|
font.pixelSize: root.textSize
|
||||||
|
color: root.textColor
|
||||||
|
}
|
||||||
|
Item { width: 5; height: 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
DankActionButton {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
enabled: root.effectiveDecrementEnabled
|
||||||
|
iconColor: root.effectiveDecrementEnabled ? root.iconColor : Theme.blendAlpha(root.iconColor, 0.5)
|
||||||
|
iconSize: root.iconSize
|
||||||
|
buttonSize: root.buttonSize
|
||||||
|
iconName: root.decrementIconName
|
||||||
|
onClicked: if (typeof root.onDecrement === 'function') root.onDecrement()
|
||||||
|
tooltipText: root.decrementTooltipText
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ MouseArea {
|
|||||||
property bool disabled: false
|
property bool disabled: false
|
||||||
property color stateColor: Theme.surfaceText
|
property color stateColor: Theme.surfaceText
|
||||||
property real cornerRadius: parent && parent.radius !== undefined ? parent.radius : Theme.cornerRadius
|
property real cornerRadius: parent && parent.radius !== undefined ? parent.radius : Theme.cornerRadius
|
||||||
|
property var tooltipText: null
|
||||||
|
|
||||||
readonly property real stateOpacity: disabled ? 0 : pressed ? 0.12 : containsMouse ? 0.08 : 0
|
readonly property real stateOpacity: disabled ? 0 : pressed ? 0.12 : containsMouse ? 0.08 : 0
|
||||||
|
|
||||||
@@ -19,4 +20,30 @@ MouseArea {
|
|||||||
radius: root.cornerRadius
|
radius: root.cornerRadius
|
||||||
color: Qt.rgba(stateColor.r, stateColor.g, stateColor.b, stateOpacity)
|
color: Qt.rgba(stateColor.r, stateColor.g, stateColor.b, stateOpacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: hoverDelay
|
||||||
|
interval: 1000
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
const p = root.mapToItem(null, parent.width / 2, parent.height + Theme.spacingXS)
|
||||||
|
tooltip.show(I18n.tr(""), p.x, p.y, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onEntered: {
|
||||||
|
if (!tooltipText) { return }
|
||||||
|
hoverDelay.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
onExited: {
|
||||||
|
if (!tooltipText) { return }
|
||||||
|
hoverDelay.stop()
|
||||||
|
tooltip.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
DankTooltip {
|
||||||
|
id: tooltip
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user