Files

43 lines
1.5 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package xorg
/*
#cgo CFLAGS: -D_GNU_SOURCE
#include "window_title.h"
#include <stdlib.h>
*/
import "C"
import (
"strings"
"unsafe"
)
// WindowTitle contains only copied metadata. Window is the foreground client;
// TitleWindow may be a program inside its Wine desktop. Application is WM_CLASS
// for programs without an AT-SPI application identity.
type WindowTitle struct {
Window, TitleWindow uint64
Title, Application string
Wine, Focused bool
Client Foreground
}
// ReadTitle runs on the same native owner thread as Read and Close.
func (reader *ForegroundReader) ReadTitle(window uint64) WindowTitle {
if reader == nil || reader.display == nil || window == 0 {
return WindowTitle{}
}
value := C.cthulhu_read_window_title(reader.display, C.Window(window))
defer C.free(unsafe.Pointer(value.title))
defer C.free(unsafe.Pointer(value.application))
return WindowTitle{Window: uint64(value.window), TitleWindow: uint64(value.titleWindow),
Wine: value.wine != 0, Focused: value.focused != 0,
Client: Foreground{Known: value.width > 0 && value.height > 0, Window: uint64(value.titleWindow), X: int(value.x), Y: int(value.y), Width: int(value.width), Height: int(value.height)},
Title: strings.TrimSpace(strings.ToValidUTF8(C.GoString(value.title), "\ufffd")),
Application: strings.TrimSpace(strings.ToValidUTF8(C.GoString(value.application), "\ufffd"))}
}