From 4075d345eb60dc6edebfd103556ff00d2f621fe8 Mon Sep 17 00:00:00 2001 From: leukipp Date: Sun, 14 Jan 2024 11:12:59 +0100 Subject: [PATCH] fix: restore window positions with caching enabled #16 --- desktop/tracker.go | 4 ++-- desktop/workspace.go | 4 ++-- input/action.go | 6 +++--- store/client.go | 39 ++++++++++++++++++++++++++------------- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/desktop/tracker.go b/desktop/tracker.go index ff6c210..ee95260 100644 --- a/desktop/tracker.go +++ b/desktop/tracker.go @@ -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) @@ -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 diff --git a/desktop/workspace.go b/desktop/workspace.go index d34b1d5..eea9784 100644 --- a/desktop/workspace.go +++ b/desktop/workspace.go @@ -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) @@ -117,7 +117,7 @@ func (ws *Workspace) Restore(original bool) { if c == nil { continue } - c.Restore(original) + c.Restore(flag) } } diff --git a/input/action.go b/input/action.go index f485686..bcc2101 100644 --- a/input/action.go +++ b/input/action.go @@ -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) @@ -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) @@ -459,7 +459,7 @@ func Exit(tr *desktop.Tracker) bool { continue } ws.Disable() - ws.Restore(false) + ws.Restore(store.Latest) } log.Info("Exit") diff --git a/store/client.go b/store/client.go index fe09184..8441715 100644 --- a/store/client.go +++ b/store/client.go @@ -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 } @@ -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 @@ -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 } @@ -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) @@ -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) @@ -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) { @@ -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) }