Skip to content

Commit

Permalink
support floating windows
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Apr 2, 2022
1 parent 013f126 commit d96dcf0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 52 deletions.
9 changes: 8 additions & 1 deletion desktop/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,12 @@ func (tr *Tracker) isTracked(w xproto.Window) bool {
}

func (tr *Tracker) isTrackable(w xproto.Window) bool {
return !store.IsHidden(w) && !store.IsModal(w) && !store.IsIgnored(w) && store.IsInsideViewPort(w)
info := store.GetInfo(w)
if info.Class == store.UNKNOWN {
return false
}

// Check if window is allowed and inside viewport
isAllowed := !store.IsModal(info) && !store.IsHidden(info) && !store.IsFloating(info) && !store.IsPinned(info) && !store.IsIgnored(info)
return isAllowed && store.IsInsideViewPort(w)
}
108 changes: 57 additions & 51 deletions store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,53 @@ func IsMaximized(w xproto.Window) bool {
return false
}

func IsHidden(w xproto.Window) bool {
func IsInsideViewPort(w xproto.Window) bool {
info := GetInfo(w)
if info.Class == UNKNOWN {
return true
return false
}

// Window dimensions
wGeom, err := xwindow.New(common.X, w).DecorGeometry()
if err != nil {
log.Warn(err)
return false
}

// Viewport dimensions
vRect := xrect.New(common.ScreenDimensions())

// Substract viewport rectangle (r2) from window rectangle (r1)
sRects := xrect.Subtract(wGeom, vRect)

// If r1 does not overlap r2, then only one rectangle is returned which is equivalent to r1
isOutsideViewport := false
if len(sRects) == 1 {
isOutsideViewport = reflect.DeepEqual(sRects[0], wGeom)
}

if isOutsideViewport {
log.Info("Ignore window outside viewport [", info.Class, "]")
}

return !isOutsideViewport
}

func IsModal(info Info) bool {

// Check model dialog windows
for _, state := range info.States {
if state == "_NET_WM_STATE_MODAL" {
log.Info("Ignore modal window", " [", info.Name, "]")
return true
}
}

return false
}

func IsHidden(info Info) bool {

// Check hidden windows
for _, state := range info.States {
if state == "_NET_WM_STATE_HIDDEN" {
Expand All @@ -252,29 +293,32 @@ func IsHidden(w xproto.Window) bool {
return false
}

func IsModal(w xproto.Window) bool {
info := GetInfo(w)
if info.Class == UNKNOWN {
return true
}
func IsFloating(info Info) bool {

// Check model dialog windows
// Check floating state
for _, state := range info.States {
if state == "_NET_WM_STATE_MODAL" {
log.Info("Ignore modal window", " [", info.Name, "]")
if state == "_NET_WM_STATE_ABOVE" {
log.Info("Ignore floating window", " [", info.Name, "]")
return true
}
}

return false
}

func IsIgnored(w xproto.Window) bool {
info := GetInfo(w)
if info.Class == UNKNOWN {
func IsPinned(info Info) bool {

// Check pinned windows
if info.Desk > common.DeskCount {
log.Info("Ignore pinned window [", info.Class, "]")
return true
}

return false
}

func IsIgnored(info Info) bool {

// Check ignored windows
for _, s := range common.Config.WindowIgnore {
conf_class := s[0]
Expand All @@ -297,41 +341,3 @@ func IsIgnored(w xproto.Window) bool {

return false
}

func IsInsideViewPort(w xproto.Window) bool {
info := GetInfo(w)
if info.Class == UNKNOWN {
return true
}

// Ignore pinned windows
if info.Desk > common.DeskCount {
log.Info("Ignore pinned window [", info.Class, "]")
return false
}

// Window dimensions
wGeom, err := xwindow.New(common.X, w).DecorGeometry()
if err != nil {
log.Warn(err)
return false
}

// Viewport dimensions
vRect := xrect.New(common.ScreenDimensions())

// Substract viewport rectangle (r2) from window rectangle (r1)
sRects := xrect.Subtract(wGeom, vRect)

// If r1 does not overlap r2, then only one rectangle is returned which is equivalent to r1
isOutsideViewport := false
if len(sRects) == 1 {
isOutsideViewport = reflect.DeepEqual(sRects[0], wGeom)
}

if isOutsideViewport {
log.Info("Ignore window outside viewport [", info.Class, "]")
}

return !isOutsideViewport
}

0 comments on commit d96dcf0

Please sign in to comment.