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"] 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..33d74b9 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -134,12 +134,16 @@ 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] { + if r.config.Min >= len(monitor.Desktops) { continue } - if r.config.Min >= len(monitor.Desktops) { + // TODO: Should we handle desktop destruction if the monitor focus is switched? + if !r.config.RemoveFocused && monitor.FocusedDesktopId == desktop.Id { continue } 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 }