Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ type Window struct {
// ID is the numerical identifier of the window.
ID int64

// Desktop is the numerical identifier of the desktop the
// window belongs to. Equal to -1 if the window is sticky.
Desktop int64

// Name is the display name of the window (typically what the
// windowing system shows in the top bar of the window).
Name string
Expand All @@ -118,6 +122,18 @@ func (w *Window) IsSystem() bool {
return false
}

// IsSticky returns true if the window is a sticky window (i.e.
// present on all desktops)
func (w *Window) IsSticky() bool {
return w.Desktop == -1
}

// IsOnDesktop returns true if the window is present on the specified
// desktop
func (w *Window) IsOnDesktop(desktop int64) bool {
return w.IsSticky() || w.Desktop == desktop
}

// Info returns more structured metadata about a window. The metadata
// is extracted using heuristics.
func (w *Window) Info() *Winfo {
Expand Down
33 changes: 30 additions & 3 deletions linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,45 @@ func (t *LinuxTracker) Snap() (*Snapshot, error) {
if len(fields) < 4 {
continue
}
id_, name := fields[0], strings.Join(fields[3:], " ")
id_, desktop_, name := fields[0], fields[1], strings.Join(fields[3:], " ")
id, err := strconv.ParseInt(id_, 0, 64)
if err != nil {
return nil, err
}
w := Window{ID: id, Name: name}
desktop, err := strconv.ParseInt(desktop_, 0, 64)
if err != nil {
return nil, err
}
w := Window{ID: id, Desktop: desktop, Name: name}
if !w.IsSystem() {
windows = append(windows, &w)
}
}
}

var currentDesktop int64
{
out, err := exec.Command("wmctrl", "-d").Output()
if err != nil {
return nil, err
}
lines := strings.Split(string(out), "\n")
for _, line := range lines {
fields := strings.Fields(line)
if len(fields) < 2 {
continue
}
id_, mode := fields[0], fields[1]
id, err := strconv.ParseInt(id_, 0, 64)
if err != nil {
return nil, err
}
if "*" == mode {
currentDesktop = id
}
}
}

var visible []int64
{
for _, window := range windows {
Expand All @@ -97,7 +124,7 @@ func (t *LinuxTracker) Snap() (*Snapshot, error) {
if err != nil {
return nil, err
}
if isVisible(x, y, w, h, viewHeight, viewWidth) {
if window.IsOnDesktop(currentDesktop) && isVisible(x, y, w, h, viewHeight, viewWidth) {
visible = append(visible, window.ID)
}
}
Expand Down