Skip to content

Commit

Permalink
fix: restore window positions with caching enabled #16
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Jan 14, 2024
1 parent 1193b32 commit 4075d34
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions desktop/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (tr *Tracker) untrackWindow(w xproto.Window) bool {
xevent.Detach(store.X, w)

// Restore client
c.Restore(false)
c.Restore(store.Latest)

// Remove client
ws.RemoveClient(c)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (tr *Tracker) handleWorkspaceChange(c *store.Client) {
if ws.Enabled() {
ws.Tile()
} else {
c.Restore(false)
c.Restore(store.Latest)
}

// Reset screen swapping event
Expand Down
4 changes: 2 additions & 2 deletions desktop/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (ws *Workspace) Tile() {
ws.ActiveLayout().Apply()
}

func (ws *Workspace) Restore(original bool) {
func (ws *Workspace) Restore(flag uint8) {
mg := ws.ActiveLayout().GetManager()
clients := mg.Clients(true)

Expand All @@ -117,7 +117,7 @@ func (ws *Workspace) Restore(original bool) {
if c == nil {
continue
}
c.Restore(original)
c.Restore(flag)
}
}

Expand Down
6 changes: 3 additions & 3 deletions input/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func Disable(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return false
}
ws.Disable()
ws.Restore(false)
ws.Restore(store.Latest)

ui.ShowLayout(ws)
ui.UpdateIcon(ws)
Expand All @@ -186,7 +186,7 @@ func Restore(tr *desktop.Tracker, ws *desktop.Workspace) bool {
return false
}
ws.Disable()
ws.Restore(true)
ws.Restore(store.Original)

ui.ShowLayout(ws)
ui.UpdateIcon(ws)
Expand Down Expand Up @@ -459,7 +459,7 @@ func Exit(tr *desktop.Tracker) bool {
continue
}
ws.Disable()
ws.Restore(false)
ws.Restore(store.Latest)
}

log.Info("Exit")
Expand Down
39 changes: 26 additions & 13 deletions store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Client struct {
Created time.Time // Internal client creation time
Locked bool // Internal client move/resize lock
Original *Info // Original client window information
Cached *Info // Cached client window information
Latest *Info // Latest client window information
}

Expand Down Expand Up @@ -67,14 +68,20 @@ type Hints struct {
Motif motif.Hints // Client window decoration hints
}

const (
Original uint8 = 1 // Flag to restore original info
Cached uint8 = 2 // Flag to restore cached info
Latest uint8 = 3 // Flag to restore latest info
)

func CreateClient(w xproto.Window) *Client {
i := GetInfo(w)
c := &Client{
Win: xwindow.New(X, w),
Created: time.Now(),
Locked: false,
Original: i,
Latest: i,
Original: GetInfo(w),
Cached: GetInfo(w),
Latest: GetInfo(w),
}

// Read client geometry from cache
Expand All @@ -84,16 +91,16 @@ func CreateClient(w xproto.Window) *Client {
geom := cached.Dimensions.Geometry
geom.Rect = xrect.New(geom.X, geom.Y, geom.Width, geom.Height)

c.Original.States = cached.States
c.Original.Dimensions.Geometry = geom
c.Original.Location.ScreenNum = GetScreenNum(geom.Rect)
c.Cached.States = cached.States
c.Cached.Dimensions.Geometry = geom
c.Cached.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(true)
c.Restore(Cached)

return c
}
Expand All @@ -116,7 +123,7 @@ func (c *Client) UnDecorate() {
}

// Remove window decorations
mhints := c.Original.Dimensions.Hints.Motif
mhints := c.Cached.Dimensions.Hints.Motif
mhints.Flags |= motif.HintDecorations
mhints.Decoration = motif.DecorationNone
motif.WmHintsSet(X, c.Win.Id, &mhints)
Expand Down Expand Up @@ -175,7 +182,7 @@ func (c *Client) LimitDimensions(w, h int) {
dw, dh := ext.Left+ext.Right, ext.Top+ext.Bottom

// Set window size limits
nhints := c.Original.Dimensions.Hints.Normal
nhints := c.Cached.Dimensions.Hints.Normal
nhints.Flags |= icccm.SizeHintPMinSize
nhints.MinWidth = uint(w - dw)
nhints.MinHeight = uint(h - dh)
Expand Down Expand Up @@ -270,13 +277,16 @@ func (c *Client) Cache() common.Cache[*Info] {
return cache
}

func (c *Client) Restore(original bool) {
func (c *Client) Restore(flag uint8) {
if flag == Latest {
c.Update()
}

// Restore window size limits
icccm.WmNormalHintsSet(X, c.Win.Id, &c.Original.Dimensions.Hints.Normal)
icccm.WmNormalHintsSet(X, c.Win.Id, &c.Cached.Dimensions.Hints.Normal)

// Restore window decorations
motif.WmHintsSet(X, c.Win.Id, &c.Original.Dimensions.Hints.Motif)
motif.WmHintsSet(X, c.Win.Id, &c.Cached.Dimensions.Hints.Motif)

// Restore window states
if common.IsInList("_NET_WM_STATE_STICKY", c.Latest.States) {
Expand All @@ -292,8 +302,11 @@ func (c *Client) Restore(original bool) {

// Move window to restore position
geom := c.Latest.Dimensions.Geometry
if original {
switch flag {
case Original:
geom = c.Original.Dimensions.Geometry
case Cached:
geom = c.Cached.Dimensions.Geometry
}
c.MoveResize(geom.X, geom.Y, geom.Width, geom.Height)
}
Expand Down

0 comments on commit 4075d34

Please sign in to comment.