input

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package input provides keyboard event handling and modal input mode management.

Package input provides keyboard event handling and modal input mode management.

Index

Constants

View Source
const (
	// HoverFocusDelay is the delay before switching focus on hover.
	HoverFocusDelay = 150 * time.Millisecond
)

Variables

This section is empty.

Functions

func ShouldAutoExitMode

func ShouldAutoExitMode(action Action) bool

ShouldAutoExitMode returns true if the action should cause modal mode to exit.

Types

type Action

type Action string

Action represents what happens when a shortcut is triggered.

const (
	// Mode management
	ActionEnterTabMode  Action = "enter_tab_mode"
	ActionEnterPaneMode Action = "enter_pane_mode"
	ActionExitMode      Action = "exit_mode"

	// Tab actions (global and modal)
	ActionNewTab           Action = "new_tab"
	ActionCloseTab         Action = "close_tab"
	ActionNextTab          Action = "next_tab"
	ActionPreviousTab      Action = "previous_tab"
	ActionRenameTab        Action = "rename_tab"
	ActionSwitchLastTab    Action = "switch_last_tab" // Alt+Tab style switching
	ActionSwitchTabIndex1  Action = "switch_tab_1"
	ActionSwitchTabIndex2  Action = "switch_tab_2"
	ActionSwitchTabIndex3  Action = "switch_tab_3"
	ActionSwitchTabIndex4  Action = "switch_tab_4"
	ActionSwitchTabIndex5  Action = "switch_tab_5"
	ActionSwitchTabIndex6  Action = "switch_tab_6"
	ActionSwitchTabIndex7  Action = "switch_tab_7"
	ActionSwitchTabIndex8  Action = "switch_tab_8"
	ActionSwitchTabIndex9  Action = "switch_tab_9"
	ActionSwitchTabIndex10 Action = "switch_tab_10"

	// Pane actions (modal)
	ActionSplitRight Action = "split_right"
	ActionSplitLeft  Action = "split_left"
	ActionSplitUp    Action = "split_up"
	ActionSplitDown  Action = "split_down"
	ActionClosePane  Action = "close_pane"
	ActionStackPane  Action = "stack_pane"

	// Pane focus navigation
	ActionFocusRight Action = "focus_right"
	ActionFocusLeft  Action = "focus_left"
	ActionFocusUp    Action = "focus_up"
	ActionFocusDown  Action = "focus_down"

	// Stack navigation (within stacked panes)
	ActionStackNavUp   Action = "stack_nav_up"
	ActionStackNavDown Action = "stack_nav_down"

	// Page navigation
	ActionGoBack     Action = "go_back"
	ActionGoForward  Action = "go_forward"
	ActionReload     Action = "reload"
	ActionHardReload Action = "hard_reload"
	ActionStop       Action = "stop"

	// Zoom
	ActionZoomIn    Action = "zoom_in"
	ActionZoomOut   Action = "zoom_out"
	ActionZoomReset Action = "zoom_reset"

	// UI
	ActionOpenOmnibox      Action = "open_omnibox"
	ActionOpenFind         Action = "open_find"
	ActionFindNext         Action = "find_next"
	ActionFindPrev         Action = "find_prev"
	ActionCloseFind        Action = "close_find"
	ActionOpenDevTools     Action = "open_devtools"
	ActionToggleFullscreen Action = "toggle_fullscreen"

	// Clipboard
	ActionCopyURL Action = "copy_url"

	// Application
	ActionQuit Action = "quit"
)

Predefined actions for the keyboard system.

type ActionHandler

type ActionHandler func(ctx context.Context, action Action) error

ActionHandler is called when a keyboard action is triggered. It receives the context and the action to perform. Return an error if the action fails.

type GestureHandler

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

GestureHandler handles mouse button gestures for navigation. It recognizes mouse buttons 8 (back) and 9 (forward) on WebView widgets.

func NewGestureHandler

func NewGestureHandler(ctx context.Context) *GestureHandler

NewGestureHandler creates a new gesture handler.

func (*GestureHandler) AttachTo

func (h *GestureHandler) AttachTo(widget *gtk.Widget)

AttachTo attaches the gesture handler to a GTK widget. Typically called with a WebView widget to enable mouse button navigation.

func (*GestureHandler) Detach

func (h *GestureHandler) Detach()

Detach removes the gesture handler. Note: GTK handles cleanup when the widget is destroyed, but we clear our reference here.

func (*GestureHandler) SetOnAction

func (h *GestureHandler) SetOnAction(fn ActionHandler)

SetOnAction sets the callback for when navigation actions are triggered.

type GlobalShortcutHandler added in v0.20.1

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

GlobalShortcutHandler manages keyboard shortcuts that must work globally, even when WebView has focus. It uses GtkShortcutController with GTK_SHORTCUT_SCOPE_GLOBAL to intercept shortcuts before they reach the WebView.

func NewGlobalShortcutHandler added in v0.20.1

func NewGlobalShortcutHandler(
	ctx context.Context,
	window *gtk.ApplicationWindow,
	onAction ActionHandler,
) *GlobalShortcutHandler

NewGlobalShortcutHandler creates a new global shortcut handler for shortcuts that need to work even when WebView has focus (like Alt+1-9 for tab switching).

func (*GlobalShortcutHandler) Detach added in v0.20.1

func (h *GlobalShortcutHandler) Detach()

Detach removes the global shortcut handler from the window. Note: GTK handles cleanup when the widget is destroyed, but we clear our references here.

type HoverCallback

type HoverCallback func(paneID entity.PaneID)

HoverCallback is called when a pane should receive focus from hover.

type HoverHandler

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

HoverHandler handles mouse hover events for focus-follows-mouse behavior. It uses a debounce timer to avoid rapid focus switches.

func NewHoverHandler

func NewHoverHandler(ctx context.Context, paneID entity.PaneID) *HoverHandler

NewHoverHandler creates a new hover handler for a specific pane.

func (*HoverHandler) AttachTo

func (h *HoverHandler) AttachTo(widget *gtk.Widget)

AttachTo attaches the hover handler to a GTK widget.

func (*HoverHandler) Detach

func (h *HoverHandler) Detach()

Detach removes the hover handler.

func (*HoverHandler) SetOnEnter

func (h *HoverHandler) SetOnEnter(fn HoverCallback)

SetOnEnter sets the callback for when the pane should receive focus.

type KeyBinding

type KeyBinding struct {
	Keyval    uint     // GDK key value (e.g., gdk.KEY_t)
	Modifiers Modifier // Combined modifiers
}

KeyBinding represents a single key combination.

func ParseKeyString

func ParseKeyString(s string) (KeyBinding, bool)

ParseKeyString converts a config key string like "ctrl+t" to a KeyBinding. Returns false if the string cannot be parsed.

type KeyboardHandler

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

KeyboardHandler processes keyboard events and dispatches actions. It manages modal input modes and routes key events to the appropriate handlers.

func NewKeyboardHandler

func NewKeyboardHandler(
	ctx context.Context,
	cfg *config.WorkspaceConfig,
) *KeyboardHandler

NewKeyboardHandler creates a new keyboard handler.

func (*KeyboardHandler) AttachTo

func (h *KeyboardHandler) AttachTo(window *gtk.ApplicationWindow)

AttachTo attaches the keyboard handler to a GTK window. The handler will intercept key events in the capture phase.

func (*KeyboardHandler) Detach

func (h *KeyboardHandler) Detach()

Detach removes the keyboard handler. Note: GTK handles cleanup when the widget is destroyed, but we clear our reference here.

func (*KeyboardHandler) EnterPaneMode

func (h *KeyboardHandler) EnterPaneMode()

EnterPaneMode programmatically enters pane mode. Useful for testing or programmatic mode changes.

func (*KeyboardHandler) EnterTabMode

func (h *KeyboardHandler) EnterTabMode()

EnterTabMode programmatically enters tab mode. Useful for testing or programmatic mode changes.

func (*KeyboardHandler) ExitMode

func (h *KeyboardHandler) ExitMode()

ExitMode programmatically exits modal mode. Useful for testing or programmatic mode changes.

func (*KeyboardHandler) Mode

func (h *KeyboardHandler) Mode() Mode

Mode returns the current input mode.

func (*KeyboardHandler) SetOnAction

func (h *KeyboardHandler) SetOnAction(fn ActionHandler)

SetOnAction sets the callback for when actions are triggered.

func (*KeyboardHandler) SetOnModeChange

func (h *KeyboardHandler) SetOnModeChange(fn func(from, to Mode))

SetOnModeChange sets the callback for mode changes (for UI updates).

func (*KeyboardHandler) SetShouldBypassInput

func (h *KeyboardHandler) SetShouldBypassInput(fn func() bool)

SetShouldBypassInput sets a hook to bypass keyboard handling entirely. When true, events propagate to focused widgets instead.

type ModalState

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

ModalState manages the current input mode with optional timeout.

func NewModalState

func NewModalState(ctx context.Context) *ModalState

NewModalState creates a new modal state manager.

func (*ModalState) EnterPaneMode

func (m *ModalState) EnterPaneMode(ctx context.Context, timeout time.Duration)

EnterPaneMode switches to pane mode with an optional timeout. If timeout is 0, the mode stays until explicitly exited.

func (*ModalState) EnterTabMode

func (m *ModalState) EnterTabMode(ctx context.Context, timeout time.Duration)

EnterTabMode switches to tab mode with an optional timeout. If timeout is 0, the mode stays until explicitly exited.

func (*ModalState) ExitMode

func (m *ModalState) ExitMode(ctx context.Context)

ExitMode returns to normal mode.

func (*ModalState) Mode

func (m *ModalState) Mode() Mode

Mode returns the current mode (thread-safe).

func (*ModalState) ResetTimeout

func (m *ModalState) ResetTimeout(ctx context.Context)

ResetTimeout restarts the mode timeout (e.g., after a valid keystroke). Does nothing if not in a modal mode or if no timeout was set.

func (*ModalState) SetOnModeChange

func (m *ModalState) SetOnModeChange(fn func(from, to Mode))

SetOnModeChange sets the callback for mode changes. The callback is invoked synchronously under the lock.

type Mode

type Mode int

Mode represents the current input mode.

const (
	// ModeNormal is the default mode where keys pass through to WebView.
	ModeNormal Mode = iota
	// ModeTab is the modal tab management mode.
	ModeTab
	// ModePane is the modal pane management mode.
	ModePane
)

func (Mode) String

func (m Mode) String() string

String returns a human-readable mode name.

type Modifier

type Modifier uint

Modifier represents keyboard modifier flags.

const (
	// ModNone indicates no modifier is pressed.
	ModNone Modifier = 0
	// ModShift indicates the Shift key is pressed.
	ModShift Modifier = Modifier(gdk.ShiftMaskValue)
	// ModCtrl indicates the Control key is pressed.
	ModCtrl Modifier = Modifier(gdk.ControlMaskValue)
	// ModAlt indicates the Alt key is pressed.
	ModAlt Modifier = Modifier(gdk.AltMaskValue)
)

type ShortcutSet

type ShortcutSet struct {
	// Global shortcuts are always active regardless of mode.
	Global ShortcutTable
	// TabMode shortcuts are only active in tab mode.
	TabMode ShortcutTable
	// PaneMode shortcuts are only active in pane mode.
	PaneMode ShortcutTable
}

ShortcutSet holds all shortcut tables organized by context.

func NewShortcutSet

func NewShortcutSet(ctx context.Context, cfg *config.WorkspaceConfig) *ShortcutSet

NewShortcutSet creates a ShortcutSet from the workspace configuration.

func (*ShortcutSet) Lookup

func (s *ShortcutSet) Lookup(binding KeyBinding, mode Mode) (Action, bool)

Lookup finds an action for the given key binding in the appropriate table. It first checks the mode-specific table, then falls back to global.

type ShortcutTable

type ShortcutTable map[KeyBinding]Action

ShortcutTable maps KeyBinding to Action.

Jump to

Keyboard shortcuts

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