tray

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package tray provides system tray GUI application for gswitch.

Index

Constants

View Source
const ConfigFile = "/etc/gswitch/default.conf"

ConfigFile is the path to the gswitch configuration file.

Variables

View Source
var ErrNoAccess = errors.New("no access to input devices")

ErrNoAccess indicates permission denied when accessing devices.

View Source
var ErrUserCanceled = errors.New("authentication canceled by user")

ErrUserCanceled is retained for UI compatibility with older service managers. User-service actions do not require authentication.

View Source
var ErrVirtualKeyboard = errors.New("gswitch virtual keyboard")

ErrVirtualKeyboard indicates this is the gswitch virtual keyboard.

Functions

func GenerateLayoutIcon

func GenerateLayoutIcon(code string) []byte

GenerateLayoutIcon creates a 22x22 icon with the given 2-letter layout code.

func GetErrorIcon

func GetErrorIcon() []byte

GetErrorIcon returns the pre-generated error icon.

func GetFlagIcon

func GetFlagIcon(code string) []byte

GetFlagIcon returns a flag icon for the layout code, or nil if not found.

func GetKeyNameFromCode

func GetKeyNameFromCode(code uint16) string

GetKeyNameFromCode returns a human-readable name for a keycode.

func GetLayoutIcon

func GetLayoutIcon(code string) []byte

GetLayoutIcon returns a cached icon for the given layout code. It first tries to load a flag icon, falling back to text icon if not found.

func GetWarningIcon

func GetWarningIcon() []byte

GetWarningIcon returns the pre-generated warning icon.

func HasFlagIcon

func HasFlagIcon(code string) bool

HasFlagIcon returns true if a flag icon exists for the given layout code.

func SetVersion added in v0.4.1

func SetVersion(v string)

SetVersion sets the application version for display in the UI.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App represents the main tray application.

func New

func New() *App

New creates a new App instance.

func (*App) OnSettingsClicked

func (a *App) OnSettingsClicked()

OnSettingsClicked is called when Settings menu item is clicked.

func (*App) Quit

func (a *App) Quit()

Quit gracefully shuts down the application.

func (*App) RefreshDetectionStatus

func (a *App) RefreshDetectionStatus()

RefreshDetectionStatus re-checks detection status and updates the tray.

func (*App) Run

func (a *App) Run() error

Run starts the application main loop. It sets up signal handlers and runs the systray event loop.

func (*App) UpdateServiceStatus

func (a *App) UpdateServiceStatus()

UpdateServiceStatus updates the service status in the tray menu.

type ConfigWatcher

type ConfigWatcher struct {
	// contains filtered or unexported fields
}

ConfigWatcher watches the config file for changes and triggers callbacks.

func NewConfigWatcher

func NewConfigWatcher(onChange func()) *ConfigWatcher

NewConfigWatcher creates a new config watcher.

func (*ConfigWatcher) Start

func (w *ConfigWatcher) Start() error

Start begins watching the config file.

func (*ConfigWatcher) Stop

func (w *ConfigWatcher) Stop()

Stop stops watching the config file.

type DetectionInfo

type DetectionInfo struct {
	Status   TrayStatus
	Source   string   // "xkb", "gnome", etc.
	KeyNames string   // "Alt+Shift", "Super+Space", etc.
	Error    string   // Error message if any
	Warning  string   // Warning message if any
	Attempts []string // Provider attempts for diagnostics
}

DetectionInfo contains information about the detection status.

func CheckDetectionStatus

func CheckDetectionStatus(sm *ServiceManager) DetectionInfo

CheckDetectionStatus determines the current detection status. It checks service status first (if systemctl is available), then runs detection if needed.

type DeviceManager

type DeviceManager struct {
	// contains filtered or unexported fields
}

DeviceManager manages input devices for the GUI. Devices are enumerated via sysfs, which is world-readable — no root or input group membership is required, unlike opening /dev/input nodes.

func NewDeviceManager

func NewDeviceManager() *DeviceManager

NewDeviceManager creates a new device manager.

func (*DeviceManager) GetKeyboards

func (m *DeviceManager) GetKeyboards() ([]KeyboardDevice, error)

GetKeyboards returns a list of connected keyboard devices.

type KeyPickerContext

type KeyPickerContext int

KeyPickerContext indicates what key is being selected.

const (
	// KeyPickerForLayoutSwitch - selecting the layout switch key.
	KeyPickerForLayoutSwitch KeyPickerContext = iota
	// KeyPickerForConvertKey - selecting the convert key.
	KeyPickerForConvertKey
)

type KeyPickerResult

type KeyPickerResult struct {
	KeyCodes []uint16 // List of hardware keycodes (scancodes)
	KeyNames []string // List of key names for display
	Value    string   // Config value (e.g., "29+42" for Ctrl+Shift)
}

KeyPickerResult represents the result of the key picker dialog.

func ShowKeyPickerDialog

func ShowKeyPickerDialog(parent *gtk.Window, context KeyPickerContext, otherKeyValue string) (KeyPickerResult, bool)

ShowKeyPickerDialog shows a dialog for capturing a key or key combination. context specifies what key is being selected (layout switch or convert key). otherKeyValue is the other key's current value to display as warning (to avoid conflicts). Returns the result and true if a key was selected, or empty result and false if canceled.

type KeyboardDevice

type KeyboardDevice struct {
	UID  string // Unique identifier (bustype:vendor:product:version:hash)
	Name string // Human-readable name
	Path string // /dev/input/eventX
}

KeyboardDevice represents a keyboard input device.

type LayoutInfo

type LayoutInfo struct {
	ShortCode string // e.g., "US", "RU"
	LongName  string // e.g., "English (US)", "Russian"
}

LayoutInfo contains information about the current keyboard layout.

type LayoutMonitor

type LayoutMonitor struct {
	// contains filtered or unexported fields
}

LayoutMonitor monitors the current keyboard layout.

func NewLayoutMonitor

func NewLayoutMonitor(callback func(layout LayoutInfo)) *LayoutMonitor

NewLayoutMonitor creates a new layout monitor with a callback for layout changes.

func (*LayoutMonitor) GetCurrentLayout

func (m *LayoutMonitor) GetCurrentLayout() LayoutInfo

GetCurrentLayout returns the current keyboard layout.

func (*LayoutMonitor) Start

func (m *LayoutMonitor) Start() error

Start begins monitoring layout changes.

func (*LayoutMonitor) Stop

func (m *LayoutMonitor) Stop()

Stop stops monitoring layout changes.

type ServiceManager

type ServiceManager struct {
	// contains filtered or unexported fields
}

ServiceManager manages a systemd service.

func NewServiceManager

func NewServiceManager(serviceName string) *ServiceManager

NewServiceManager creates a new service manager.

func (*ServiceManager) Disable

func (sm *ServiceManager) Disable() error

Disable disables the service for this user.

func (*ServiceManager) Enable

func (sm *ServiceManager) Enable() error

Enable enables the service for this user's graphical sessions.

func (*ServiceManager) GetStatus

func (sm *ServiceManager) GetStatus() (ServiceStatus, error)

GetStatus returns the current status of the service.

func (*ServiceManager) IsEnabled

func (sm *ServiceManager) IsEnabled() (bool, error)

IsEnabled returns true if the service is enabled to start at boot.

func (*ServiceManager) Restart

func (sm *ServiceManager) Restart() error

Restart restarts the current user's service.

func (*ServiceManager) Start

func (sm *ServiceManager) Start() error

Start starts the current user's service.

func (*ServiceManager) Stop

func (sm *ServiceManager) Stop() error

Stop stops the current user's service.

type ServiceStatus

type ServiceStatus int

ServiceStatus represents the status of a systemd service.

const (
	StatusUnknown ServiceStatus = iota
	StatusRunning
	StatusStopped
	StatusFailed
	StatusNotInstalled
)

func (ServiceStatus) StatusColor

func (s ServiceStatus) StatusColor() string

StatusColor returns the color name for the status indicator.

func (ServiceStatus) String

func (s ServiceStatus) String() string

String returns a localized string representation of the service status.

type SettingsWindow

type SettingsWindow struct {
	// contains filtered or unexported fields
}

SettingsWindow represents the settings dialog.

func NewSettingsWindow

func NewSettingsWindow(app *App) (*SettingsWindow, error)

NewSettingsWindow creates a new settings window.

func (*SettingsWindow) Hide

func (w *SettingsWindow) Hide()

Hide hides the settings window.

func (*SettingsWindow) IsVisible

func (w *SettingsWindow) IsVisible() bool

IsVisible returns true if the window is currently visible.

func (*SettingsWindow) Show

func (w *SettingsWindow) Show()

Show displays the settings window.

type Tray

type Tray struct {
	// contains filtered or unexported fields
}

Tray represents the system tray icon and menu.

func NewTray

func NewTray(app *App) *Tray

NewTray creates a new system tray instance.

func (*Tray) GetServiceManager

func (t *Tray) GetServiceManager() *ServiceManager

GetServiceManager returns the service manager instance.

func (*Tray) UpdateDetectionStatus

func (t *Tray) UpdateDetectionStatus(info DetectionInfo)

UpdateDetectionStatus updates the tray icon and tooltip based on detection status.

func (*Tray) UpdateLayout

func (t *Tray) UpdateLayout(layout LayoutInfo)

UpdateLayout updates the tray icon and tooltip for the given layout.

func (*Tray) UpdateServiceStatus

func (t *Tray) UpdateServiceStatus()

UpdateServiceStatus updates the service status menu items.

type TrayConfig

type TrayConfig struct {
	LayoutSwitch      string   // "125" or "29+42"
	ConvertKey        string   // "0" for double-shift, or key code
	Layout1           string   // "us"
	Layout2           string   // "ru"
	Delay             int      // 10
	LayoutSwitchDelay int      // 100
	Blacklist         []string // Device UIDs to ignore
}

TrayConfig holds the configuration values relevant to the tray application.

func DefaultTrayConfig

func DefaultTrayConfig() *TrayConfig

DefaultTrayConfig returns a config with default values.

func LoadTrayConfig

func LoadTrayConfig() *TrayConfig

LoadTrayConfig reads configuration from the config file. Returns default config if file doesn't exist or can't be read.

func (*TrayConfig) IsBlacklisted

func (c *TrayConfig) IsBlacklisted(uid string) bool

IsBlacklisted checks if a device UID is in the blacklist.

type TrayStatus

type TrayStatus int

TrayStatus represents the overall tray icon status.

const (
	// TrayStatusOK - normal operation, layout switch detected or explicitly configured.
	TrayStatusOK TrayStatus = iota
	// TrayStatusNeedsConfig - autodetect did not find layout switch config.
	TrayStatusNeedsConfig
	// TrayStatusServiceError - gswitch service is not running or failed.
	TrayStatusServiceError
	// TrayStatusDetectError - error occurred during detection.
	TrayStatusDetectError
)

Directories

Path Synopsis
Package assets provides embedded resources for the tray application.
Package assets provides embedded resources for the tray application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL