keymap

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keymap holds the OS-independent tables and helpers the native shells share: X11 keysym, evdev, Windows virtual-key and macOS keyCode translation to DOM KeyboardEvent key/code names, UTF-16 helpers and DPI math. It has no OS dependencies so every table is unit-tested on Linux.

Code generated from X11 keysymdef.h; DO NOT EDIT.

Index

Constants

View Source
const (
	VK_BACK       = 0x08
	VK_TAB        = 0x09
	VK_RETURN     = 0x0D
	VK_SHIFT      = 0x10
	VK_CONTROL    = 0x11
	VK_MENU       = 0x12
	VK_PROCESSKEY = 0xE5
	VK_PACKET     = 0xE7
)

Windows virtual-key codes used by the tables below.

View Source
const BaseDPI = 96.0

BaseDPI is the Windows/X11 reference DPI for a scale of 1.0.

Variables

This section is empty.

Functions

func CheckOpenURL

func CheckOpenURL(raw string) (string, error)

CheckOpenURL validates a string before it is handed to the OS "open" facility (xdg-open, ShellExecute, NSWorkspace). Only absolute URLs with a real scheme are allowed: bare paths, option-looking strings, single-letter "schemes" (Windows drive letters) and schemes that run local content (file, javascript, vbscript, data) are rejected so the browser can never be tricked into launching programs.

func ComposeDead

func ComposeDead(comb, base rune) string

ComposeDead combines a dead key's combining mark with a base character. It returns the precomposed string, or "" when no single-rune composition exists (the caller then emits the spacing accent followed by base).

comb must be the combining mark of a dead keysym (DeadKeysym); any other mark composes to "". The compositions are NFC's, tabulated by gen_compose.go (go generate), so the browser does not carry the whole normalization tables; TestComposeDeadMatchesNFC checks every code point against golang.org/x/text/unicode/norm.

func DeadKeysym

func DeadKeysym(ks uint32) (comb, spacing rune, ok bool)

DeadKeysym reports whether ks is a dead (accent) keysym and returns its combining mark and the spacing accent typed when followed by space.

func EvdevCode

func EvdevCode(ev int) string

EvdevCode returns the DOM code for an evdev keycode ("" if unknown).

func FromUTF16

func FromUTF16(u []uint16) string

FromUTF16 decodes UTF-16 code units (lone surrogates become U+FFFD).

func FromUTF16Z

func FromUTF16Z(p *uint16, max int) string

FromUTF16Z decodes a NUL-terminated UTF-16 string at p. max bounds the scan in code units (0 = 1<<20).

func IsModifierKeysym

func IsModifierKeysym(ks uint32) bool

IsModifierKeysym reports whether ks is a pure modifier key.

func KeyFromCode

func KeyFromCode(code string) (string, bool)

KeyFromCode returns the DOM key name for a non-character physical key ("Enter", "ArrowLeft", "F7"...). ok is false for keys that type text.

func KeysymKey

func KeysymKey(ks uint32) (string, bool)

KeysymKey returns the DOM KeyboardEvent.key name for non-character keysyms ("Enter", "ArrowLeft", "F5", "Shift", ...).

func KeysymToRune

func KeysymToRune(ks uint32) (r rune, ok bool)

KeysymToRune converts an X11 keysym to the Unicode character it types. ok is false for keysyms that are not characters (function keys, modifiers).

func LogicalSize

func LogicalSize(dw, dh int, scale float64) (int, int)

LogicalSize returns the logical size for a device-pixel size, rounded to the nearest integer (what EvResize reports).

func MacCode

func MacCode(keyCode int) string

MacCode maps an NSEvent keyCode (kVK_* virtual key) to a DOM code.

func MacFunctionKey

func MacFunctionKey(r rune) (string, bool)

MacFunctionKey maps the NSEvent private-use characters (0xF700 range, NSUpArrowFunctionKey etc.) that charactersIgnoringModifiers returns for function keys to DOM names, so layout-specific names survive.

func MacScrollPixels

func MacScrollPixels(delta float64, precise bool) float64

MacScrollPixels converts NSEvent scrollingDeltaX/Y into shell wheel units. precise is hasPreciseScrollingDeltas: trackpads and Magic Mouse report points already; classic wheels report lines, scaled to ~10 px per line. NSEvent deltas are positive when content should move down/right (natural direction already applied by the OS), shell.Event wants positive = content moves up, so the vertical sign flips; horizontal keeps DOM sign (positive = content moves left), so it flips as well.

func ParseScaleEnv

func ParseScaleEnv(v string) (float64, bool)

ParseScaleEnv parses GDK_SCALE / SWEEF_SCALE style values ("2", "1.5").

func ParseXftDPI

func ParseXftDPI(res string) (float64, bool)

ParseXftDPI extracts Xft.dpi from an X RESOURCE_MANAGER string.

func Printable

func Printable(r rune) bool

Printable reports whether r should be delivered as text input.

func ScaleFromDPI

func ScaleFromDPI(dpi float64) float64

ScaleFromDPI converts a DPI value to a device pixel ratio, clamped to a sane range. WM_DPICHANGED passes LOWORD(wParam); X11 passes Xft.dpi.

func ToDevice

func ToDevice(logical int, scale float64) int

ToDevice converts logical pixels to device pixels (rounded, >= 1).

func ToLogical

func ToLogical(device float64, scale float64) float64

ToLogical converts device pixels to (fractional) logical pixels.

func UTF16

func UTF16(s string) []uint16

UTF16 converts s to UTF-16 code units without a terminator.

func UTF16Z

func UTF16Z(s string) []uint16

UTF16Z converts s to a NUL-terminated UTF-16 slice (for Win32 W APIs). Embedded NULs are dropped so the string cannot be truncated silently.

func WinCode

func WinCode(scan int, extended bool, vk int) string

WinCode maps the scan code and extended flag from a WM_KEYDOWN lParam (bits 16-23 and bit 24) to a DOM KeyboardEvent.code. vk disambiguates the few keys with no usable scan code (Pause).

func WinVKKey

func WinVKKey(vk int) (string, bool)

WinVKKey returns the DOM key name for virtual keys that are not characters ("Enter", "F5", "ArrowLeft"...). ok is false for character keys, whose key string must come from ToUnicodeEx (layout and shift aware).

func WinWheelPixels

func WinWheelPixels(delta int16, lines int, horizontal bool) float64

WinWheelPixels converts a WM_MOUSEWHEEL/HWHEEL delta (multiples of 120) into logical pixels: one notch scrolls `lines` lines of lineHeight pixels (SPI_GETWHEELSCROLLLINES default 3). Windows reports positive delta for scrolling away from the user (content moves down) while shell.Event wants positive = content moves up, so the sign is flipped. For HWHEEL the Windows sign already means "right", which equals shell's convention for DX, so the caller passes horizontal=true to keep the sign.

func X11Code

func X11Code(keycode uint8) string

X11Code returns the DOM code for an X11 keycode (evdev+8 on Linux).

Types

type SurrogateJoiner

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

SurrogateJoiner assembles WM_CHAR code units (which deliver astral characters as two messages) into runes.

func (*SurrogateJoiner) Feed

func (j *SurrogateJoiner) Feed(u uint16) (rune, bool)

Feed returns (rune, true) when a complete character is available.

Jump to

Keyboard shortcuts

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