window

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GWL_EXSTYLE      = 0xFFFFFFFFFFFFFFEC // Offset for extended window styles
	GWL_STYLE        = 0xFFFFFFFFFFFFFFF0 // Style for tool windows
	WS_POPUP         = 0x00000000
	WS_EX_TOOLWINDOW = 0x00000080
	WS_VISIBLE       = 0x10000000
	WS_CAPTION       = 0x00C00000 // Title bar
	WS_THICKFRAME    = 0x00040000 // Resizable border
	SWP_NOZORDER     = 0x0004
	SWP_NOACTIVATE   = 0x0010

	WINEVENT_OUTOFCONTEXT   = 0x0000
	EVENT_SYSTEM_FOREGROUND = 0x0003
)

Variables

View Source
var OpenWindows []WindowInfo

Functions

func AddAppOnKeyPress

func AddAppOnKeyPress(keyCode int)

TODO: name is misleading since it also removes apps and the hotkey thing is not super user friendly. AddAppOnKeyPress takes the keyCode and waits for the key to be pressed. When pressed, the currently focused window is taken and either added to list of managed applications or removed from it if it is already on the list. Should this fail, the case will be ignored and the function waits on the next keypress.

func CreateWinEventHook added in v0.2.0

func CreateWinEventHook() win.HWINEVENTHOOK

CreateWinEventHook sets up the SetWinEventHook for foreground window changes

func EnumWindowsCallback

func EnumWindowsCallback(hwnd syscall.Handle, lParam uintptr) uintptr

EnumWindowsCallback is the callback function for EnumWindows

This function uses the GetWindowTextW and GetWindowTextLengthW functions from winuser.h.

See https://learn.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-getwindowtextw and https://learn.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-getwindowtextlengthw

func ForegroundWindowEvent added in v0.2.0

func ForegroundWindowEvent(hWinEventHook win.HWINEVENTHOOK, event uint32, hwnd win.HWND, idObject int32, idChild int32, idEventThread uint32, dwmsEventTime uint32) uintptr

ForegroundWindowEvent is called when the foreground window changes

func GetForegroundWindow

func GetForegroundWindow() uintptr

GetForegroundWindow gets the handle to the foreground window

This function uses the GetForegroundWindow function from winuser.h.

See https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow

func GetWindowByProcessID

func GetWindowByProcessID(pid uint32) syscall.Handle

getWindowByProcessID tries to get the window beloging to the given PID. On success the handle of the window is returned otherwise the return value is 0.

This function uses the GetWindowThreadProcessId function from winuser.h.

See https://learn.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid

func GetWindowText

func GetWindowText(hwnd uintptr) string

GetWindowText retrieves the text of the window identified by the handle

This function uses the GetWindowTextW function from winuser.h.

See https://learn.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-getwindowtextw

func MoveWindow

func MoveWindow(executable string)

MoveWindow tries to find a window handle for the given executable and sets the window style and dimensions for the window.

If the style and dimensions are already set, nothing is done.

func WatchForegroundWindowChange

func WatchForegroundWindowChange()

WatchForegroundWindowChange starts listening for foreground window change events

func WatchProcessStart deprecated

func WatchProcessStart()

Deprecated: This function is deprecated and may be removed in future versions. Use WatchForegroundWindowChange instead for improved performance and reliability.

WatchProcessStart scans all open (and visible) windows every five seconds and moves them if they are managed. While this provides some functionality, it has a severe performance impact. It is advised to use WatchForegroundWindowChange instead, which is more efficient. Consider transitioning to this new implementation.

Types

type RECT

type RECT struct {
	Left, Top, Right, Bottom int32
}

type WindowInfo

type WindowInfo struct {
	Title string
	Hwnd  syscall.Handle
}

Jump to

Keyboard shortcuts

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