From 72877b172cb4d5c441bb288e0a7ac9fe760816a9 Mon Sep 17 00:00:00 2001 From: Mark Cooke <2086102+mark-cooke@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:01:40 +0000 Subject: [PATCH 1/2] Allow caching to be controlled in the config file (and in a more fine-grained way) Add cache_workspaces and cache_windows to the config to individually control what gets cached, but still allow the command-line flag to override the settings and disable the cache entirely. Why? Caching window positions can be a bit unreliable for things like browser windows (which will all have the same WM_CLASS and window title on start-up so may not match between runs/logins when cortile encounters the window). --- common/config.go | 2 ++ config.toml | 6 ++++++ desktop/workspace.go | 4 ++-- store/client.go | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/common/config.go b/common/config.go index a0d5015..9989313 100644 --- a/common/config.go +++ b/common/config.go @@ -19,6 +19,8 @@ var ( ) type Configuration struct { + CacheWorkspaces bool `toml:"cache_workspaces"` // Cache workspace properties (Tiling enablement, Current layout, proportions) + CacheWindows bool `toml:"cache_windows"` // Cache window properties ( Positions, Dimensions) TilingEnabled bool `toml:"tiling_enabled"` // Tile windows on startup TilingLayout string `toml:"tiling_layout"` // Initial tiling layout TilingCycle []string `toml:"tiling_cycle"` // Cycle layout order diff --git a/config.toml b/config.toml index 387e6dd..4a828b9 100644 --- a/config.toml +++ b/config.toml @@ -9,6 +9,12 @@ # Initial tiling activation, will be cached afterwards (true | false). tiling_enabled = true +# Cache Workspace Tiling enablement, current layouts, etc +cache_workspaces = true + +# Do not cache window positions +cache_windows = false + # Initial tiling layout, will be cached afterwards ("vertical-left" | "vertical-right" | "horizontal-top" | "horizontal-bottom" | "maximized" | "fullscreen"). tiling_layout = "vertical-right" diff --git a/desktop/workspace.go b/desktop/workspace.go index 6330e5b..5b879e5 100644 --- a/desktop/workspace.go +++ b/desktop/workspace.go @@ -235,7 +235,7 @@ func (ws *Workspace) Restore(flag uint8) { } func (ws *Workspace) Write() { - if common.CacheDisabled() { + if common.CacheDisabled() || !common.Config.CacheWorkspaces { return } @@ -261,7 +261,7 @@ func (ws *Workspace) Write() { } func (ws *Workspace) Read() *Workspace { - if common.CacheDisabled() { + if common.CacheDisabled() || !common.Config.CacheWorkspaces { return ws } diff --git a/store/client.go b/store/client.go index 7be171f..d835105 100644 --- a/store/client.go +++ b/store/client.go @@ -342,7 +342,7 @@ func (c *Client) Update() { } func (c *Client) Write() { - if common.CacheDisabled() { + if common.CacheDisabled() || !common.Config.CacheWindows { return } @@ -368,7 +368,7 @@ func (c *Client) Write() { } func (c *Client) Read() *Client { - if common.CacheDisabled() { + if common.CacheDisabled() || !common.Config.CacheWindows { return c } From 6a4df903ca2d32717b8f855d52398f3de7bff4f6 Mon Sep 17 00:00:00 2001 From: Mark Cooke <2086102+mark-cooke@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:23:34 +0000 Subject: [PATCH 2/2] Make the cache settings optional in the config file Most may not need these options so make thier presence in the config file optional. --- common/config.go | 11 +++++++++++ config.toml | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/common/config.go b/common/config.go index 9989313..e1f7655 100644 --- a/common/config.go +++ b/common/config.go @@ -44,6 +44,15 @@ type Configuration struct { Systray map[string]string `toml:"systray"` // Event bindings for systray icon } +/* +Partially for backward compatibility, partially to stop the config file getting huge, +for the options which are not commonly needed/wanted, set their default values. +*/ +func SetConfigDefaults() { + Config.CacheWindows = true + Config.CacheWorkspaces = true +} + func InitConfig() { // Create config folder if not exists @@ -87,6 +96,8 @@ func readConfig(configFilePath string, initial bool) { fmt.Printf("FILES: \n log: %s\n lock: %s\n cache: %s\n config: %s\n\n", Args.Log, Args.Lock, Args.Cache, configFilePath) } + SetConfigDefaults() + // Decode config file into struct _, err := toml.DecodeFile(configFilePath, &Config) if err != nil { diff --git a/config.toml b/config.toml index 4a828b9..387e6dd 100644 --- a/config.toml +++ b/config.toml @@ -9,12 +9,6 @@ # Initial tiling activation, will be cached afterwards (true | false). tiling_enabled = true -# Cache Workspace Tiling enablement, current layouts, etc -cache_workspaces = true - -# Do not cache window positions -cache_windows = false - # Initial tiling layout, will be cached afterwards ("vertical-left" | "vertical-right" | "horizontal-top" | "horizontal-bottom" | "maximized" | "fullscreen"). tiling_layout = "vertical-right"