Skip to content

Commit

Permalink
ref: move geometry restore logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Dec 10, 2023
1 parent cdd82c9 commit 817fae4
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,22 @@ func CreateClient(w xproto.Window) *Client {

// Read client geometry from cache
cached := c.Read()
c.Original = cached
c.Latest = cached

// Overwrite states, geometry and location
geom := cached.Dimensions.Geometry
geom.Rect = xrect.New(geom.X, geom.Y, geom.Width, geom.Height)
x, y, width, height := geom.Pieces()

c.Original.States = cached.States
c.Original.Dimensions.Geometry = geom
c.Original.Location.ScreenNum = GetScreenNum(geom.Rect)

c.Latest.States = cached.States
c.Latest.Dimensions.Geometry = geom
c.Latest.Location.ScreenNum = GetScreenNum(geom.Rect)

// Restore window position
c.Restore(false)
c.MoveResize(x, y, width, height)

return c
}
Expand Down Expand Up @@ -155,9 +166,7 @@ func (c *Client) MoveResize(x, y, w, h int) {
}

// Update stored dimensions
if !c.IsNew() {
c.Update()
}
c.Update()
}

func (c *Client) LimitDimensions(w, h int) {
Expand Down Expand Up @@ -238,17 +247,9 @@ func (c *Client) Read() *Info {
return c.Latest
}

// Overwrite states, geometry and location
geom := info.Dimensions.Geometry
geom.Rect = xrect.New(geom.X, geom.Y, geom.Width, geom.Height)

c.Latest.States = info.States
c.Latest.Dimensions.Geometry = geom
c.Latest.Location.ScreenNum = GetScreenNum(geom.Rect)

log.Debug("Read client cache data ", cache.Name, " [", c.Latest.Class, "]")

return c.Latest
return info
}

func (c *Client) Cache() common.Cache[*Info] {
Expand Down Expand Up @@ -335,11 +336,6 @@ func (c *Client) OuterGeometry() (x, y, w, h int) {
return
}

func (c *Client) IsNew() bool {
lifetime := time.Since(c.Created)
return lifetime < 1000*time.Millisecond
}

func IsSpecial(info *Info) bool {

// Check internal windows
Expand Down

0 comments on commit 817fae4

Please sign in to comment.