ctxmenu

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: Zlib Imports: 26 Imported by: 2

README

Context Menu

Context Menu File Menu

Library and Program for displaying context-menus. It's based on xmenu and rewritten using Go and SDL2 (yet). I wanted to make an alternative which does work using Wayland, but there are still some quirks.

Features

  • ctxmenu-program which takes stdin and its result to stdout.
  • Icons and Separators.
  • Keyboard support (in theory, not working in Wayland).
  • Mouse support

Installation

Requisite
Install using go install

Go provides a simple way to install go-programs:

% go install github.com/friedelschoen/ctxmenu/cmd/ctxmenu@latest

Which installs (by default) your application at ~/go/bin, you might want to add that to $PATH.

Building from source

If you want to build from source, you have to fetch it first:

% git clone https://github.com/friedelschoen/ctxmenu.git
% cd ctxmenu
% go build -C cmd/ctxmenu -v

Which writes cmd/ctxmenu/ctxmenu, you now can copy it to your desired location.

Known Issues

SDL2 is a great library but does not work well under Wayland. Especially using the flag SDL_POPUP_MENU, which creates a undecorated and unmanaged window. This is a Xorg-only thing, a Wayland equivalent would be 'wlr-layer-shell' which is not implemented in Go yet.

Under sway at least, keyboard-focusing is not possible and the program itself can't raise above existing windows. Spawn-at-cursor is not working as an Xorg-program via XWayland only knows the cursor position if is above itself or another Xorg-window. The initial cursor-position (thus the position of the menu) is not the real position but the last position the cursor flew above a Xorg-window.

License

This project uses the Zlib License.

Documentation

Index

Constants

View Source
const (
	ItemPrev = iota
	ItemNext
	ItemFirst
	ItemLast
)

enum for keyboard menu navigation

Variables

View Source
var DefaultConfig = Config{

	FontName: "monospace:size=12",

	BackgroundColor:    "#FFFFFF",
	ForegroundColor:    "#2E3436",
	SelbackgroundColor: "#3584E4",
	SelforegroundColor: "#FFFFFF",
	SeparatorColor:     "#CDC7C2",
	BorderColor:        "#E6E6E6",

	MinItemWidth:    130,
	BorderSize:      1,
	SeperatorLength: 3,

	Alignment: AlignLeft,

	IconSize: 24,

	PaddingX: 4,
	PaddingY: 4,
}
View Source
var ErrExited = errors.New("quit-request received")

Functions

func FontMatch

func FontMatch(fontstr string) (string, *opentype.FaceOptions, error)

func Run

func Run[T comparable](items Menu[T], conf *Config, wlDisplay string, hover func(T)) (ret T, werr error)

run event loop

Types

type Action

type Action int
const (
	ActionClear Action = 1 << iota /* clear text */
	ActionMap                      /* remap menu windows */
	ActionDraw                     /* redraw menu windows */
)

type Alignment

type Alignment int
const (
	AlignLeft Alignment = iota
	AlignCenter
	AlignRight
)

enum for text alignment

type ColorPair

type ColorPair struct {
	Foreground, Background image.Image
}

ColorPair holds text-color information

type Config

type Config struct {
	/* the values below are set by menu.ctxmenu.h */
	FontName           string
	BackgroundColor    string
	ForegroundColor    string
	SelbackgroundColor string
	SelforegroundColor string
	SeparatorColor     string
	BorderColor        string

	MinItemWidth       int
	BorderSize         int
	SeperatorLength    int
	IconSize           int
	PaddingX, PaddingY int
	Alignment          Alignment
}

Config holds configurations for ctxmenu

type ContextMenu

type ContextMenu struct {
	*Config
	// contains filtered or unexported fields
}

func (*ContextMenu) Monitor

func (ctxmenu *ContextMenu) Monitor() image.Rectangle

type Item

type Item[T comparable] struct {
	Label     string /* string to be drawed on menu */
	Output    T      /* string to be outputed when item is clicked */
	Imagefile string
	SubMenu   Menu[T]
}
type Menu[T comparable] []Item[T]

type OverflowItem

type OverflowItem int
const (
	OverflowTop OverflowItem = iota - 1
	OverflowNone
	OverflowBottom
)

type QuitEvent

type QuitEvent struct {
}

func (QuitEvent) Proxy

func (QuitEvent) Proxy() wayland.Proxy

type SubImage

type SubImage struct {
	Src  draw.Image
	Rect image.Rectangle
}

SubImage is a wrapper to offset an draw.Image to specific Boundaries

func (*SubImage) At

func (si *SubImage) At(x int, y int) color.Color

At returns the color of the pixel at (x, y). At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.

func (*SubImage) Bounds

func (si *SubImage) Bounds() image.Rectangle

Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).

func (*SubImage) ColorModel

func (si *SubImage) ColorModel() color.Model

ColorModel returns the Image's color model.

func (*SubImage) Set

func (si *SubImage) Set(x, y int, c color.Color)

Set modifies the color of the pixel at (x, y).

type SurfaceImage

type SurfaceImage struct {
	image.RGBA
	// contains filtered or unexported fields
}

func NewSurfaceImage

func NewSurfaceImage(rect image.Rectangle, shm *proto.Shm) (*SurfaceImage, error)

func (*SurfaceImage) Buffer

func (img *SurfaceImage) Buffer() *proto.Buffer

func (*SurfaceImage) Close

func (img *SurfaceImage) Close()

func (*SurfaceImage) Resize

func (img *SurfaceImage) Resize(newrect image.Rectangle)

Directories

Path Synopsis
cmd
ctxmenu command
Package proto contains wayland-protocol wayland
Package proto contains wayland-protocol wayland

Jump to

Keyboard shortcuts

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