From e028a07b72ae60380b50734a3d02e10b8711e928 Mon Sep 17 00:00:00 2001 From: Cosmo Borsky Date: Mon, 21 Jan 2019 15:27:24 -0500 Subject: [PATCH 1/3] Add option to remove desktop after focus change This will allow you to keep an empty desktop open if you're focused in it Set `remove-focused = false` in your config.toml to active this feature --- config/config.go | 2 ++ handlers/handlers.go | 5 +++++ monitors/monitors.go | 1 + 3 files changed, 8 insertions(+) diff --git a/config/config.go b/config/config.go index 3266fe8..34f277f 100644 --- a/config/config.go +++ b/config/config.go @@ -24,6 +24,7 @@ type Config struct { Min int Max int RemoveEmpty bool `mapstructure:"remove-empty"` + RemoveFocused bool `mapstructure:"remove-focused"` AppendWhenOccupied bool `mapstructure:"append-when-occupied"` WatchConfig bool `mapstructure:"watch-config"` configChangeC chan bool @@ -89,6 +90,7 @@ func newDefaultConfig() *viper.Viper { c.SetDefault("min", 1) c.SetDefault("max", math.MaxInt64) c.SetDefault("remove-empty", true) + c.SetDefault("remove-focused", true) c.SetDefault("append-when-occupied", true) c.SetDefault("renamers", []string{numeric}) c.SetDefault("watch-config", true) diff --git a/handlers/handlers.go b/handlers/handlers.go index 41750a4..ee9b635 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -143,6 +143,11 @@ func (r RemoveHandler) Handle(m *monitors.Monitors) bool { continue } + // TODO: Should we handle desktop destruction if the monitor focus is switched? + if !r.config.RemoveFocused && monitor.FocusedDesktopId == desktop.Id { + continue + } + err := monitor.RemoveDesktop(desktop.Id) if err != nil { log.Println("Unable to remove desktop: ", desktop.Name, err) diff --git a/monitors/monitors.go b/monitors/monitors.go index 2c07098..ca3460b 100644 --- a/monitors/monitors.go +++ b/monitors/monitors.go @@ -15,6 +15,7 @@ type bspwmState struct { type Monitor struct { Name string Id int + FocusedDesktopId int Desktops []Desktop } From b48916b74709e0ddaedc628469d96333eaf9bac5 Mon Sep 17 00:00:00 2001 From: Cosmo Borsky Date: Thu, 24 Jan 2019 21:54:41 -0500 Subject: [PATCH 2/3] Add remove-focused to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a9bf96a..88098e0 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Below are the different configuration options available. Please look at [exampl | min | Int | Minimum number of desktops per monitor | 1 | | max | Int | Maximum number of desktops per monitor | infinity | | remove-empty | Bool | Removes empty desktops | true | +| remove-focused | Bool | Removes focused desktops | false | | append-when-occupied | Bool | Appends a new desktop when all other desktops are occupied | true | | watch-config | Bool | Reload btops on next event when configuration changes | true | | renamers | []String | Order of [renamers](#renamers) to use for renaming desktops. If a given renamer is unable to rename a desktop, it cascades to the next renmaer | ["numeric"] From fea79f4bbdebf5d2a3f0742971d5bbfec5f92f71 Mon Sep 17 00:00:00 2001 From: Cosmo Borsky Date: Thu, 24 Jan 2019 22:04:25 -0500 Subject: [PATCH 3/3] Only remove a desktop if more than one is empty --- handlers/handlers.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/handlers/handlers.go b/handlers/handlers.go index ee9b635..33d74b9 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -134,11 +134,10 @@ func (r RemoveHandler) ShouldHandle() bool { func (r RemoveHandler) Handle(m *monitors.Monitors) bool { for _, monitor := range *m { + if len(monitor.EmptyDesktops()) == 1 { + return true + } for _, desktop := range monitor.EmptyDesktops() { - if *desktop == monitor.Desktops[len(monitor.Desktops)-1] { - continue - } - if r.config.Min >= len(monitor.Desktops) { continue }