Skip to content

Commit

Permalink
feat: toggle window decoration per layout #62
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Aug 4, 2024
1 parent 6caa49f commit 249805c
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 96 deletions.
15 changes: 9 additions & 6 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#################################### Tiling ####################################

# Tiling will be enabled on application start if set to true (true | false).
# Initial tiling activation, will be cached afterwards (true | false).
tiling_enabled = true

# Initial tiling layout ("vertical-left" | "vertical-right" | "horizontal-top" | "horizontal-bottom" | "maximized" | "fullscreen").
# Initial tiling layout, will be cached afterwards ("vertical-left" | "vertical-right" | "horizontal-top" | "horizontal-bottom" | "maximized" | "fullscreen").
tiling_layout = "vertical-right"

# An overlay window is displayed for this time period [ms] when the layout was changed (0 = disabled).
Expand Down Expand Up @@ -59,7 +59,7 @@ window_slaves_max = 3
# How much space should be left between windows (0 - 100).
window_gap_size = 10

# Window decorations will be removed if set to false (true | false).
# Initial rendering of window decorations, will be cached afterwards (true | false).
window_decoration = true

################################## Proportion ##################################
Expand Down Expand Up @@ -116,12 +116,15 @@ enable = "Control-Shift-Home"
# Disable tiling on the current screen (End = Fn_Right).
disable = "Control-Shift-End"

# Disable tiling and restore windows on the current screen.
restore = "Control-Shift-R"

# Toggle between enable and disable on the current screen.
toggle = "Control-Shift-T"

# Toggle window decoration on and off on the current screen.
decoration = "Control-Shift-D"

# Disable tiling and restore windows on the current screen.
restore = "Control-Shift-R"

# Reset layouts to default proportions (BackSpace = Delete_Left)
reset = "Control-Shift-BackSpace"

Expand Down
16 changes: 8 additions & 8 deletions desktop/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func CreateTracker() *Tracker {

func (tr *Tracker) Update() {
ws := tr.ActiveWorkspace()
if ws.Disabled() {
if ws.TilingDisabled() {
return
}
log.Debug("Update trackable clients [", len(tr.Clients), "/", len(store.Windows.Stacked), "]")
Expand Down Expand Up @@ -132,7 +132,7 @@ func (tr *Tracker) Write() {
}

func (tr *Tracker) Tile(ws *Workspace) {
if ws.Disabled() {
if ws.TilingDisabled() {
return
}

Expand Down Expand Up @@ -258,7 +258,7 @@ func (tr *Tracker) handleMaximizedClient(c *store.Client) {
// Client maximized
if store.IsMaximized(store.GetInfo(c.Window.Id)) {
ws := tr.ClientWorkspace(c)
if ws.Disabled() {
if ws.TilingDisabled() {
return
}
log.Debug("Client maximized handler fired [", c.Latest.Class, "]")
Expand All @@ -285,7 +285,7 @@ func (tr *Tracker) handleMinimizedClient(c *store.Client) {
// Client minimized
if store.IsMinimized(store.GetInfo(c.Window.Id)) {
ws := tr.ClientWorkspace(c)
if ws.Disabled() {
if ws.TilingDisabled() {
return
}
log.Debug("Client minimized handler fired [", c.Latest.Class, "]")
Expand All @@ -297,7 +297,7 @@ func (tr *Tracker) handleMinimizedClient(c *store.Client) {

func (tr *Tracker) handleResizeClient(c *store.Client) {
ws := tr.ClientWorkspace(c)
if ws.Disabled() || !tr.isTracked(c.Window.Id) || store.IsMaximized(store.GetInfo(c.Window.Id)) {
if ws.TilingDisabled() || !tr.isTracked(c.Window.Id) || store.IsMaximized(store.GetInfo(c.Window.Id)) {
return
}

Expand Down Expand Up @@ -436,7 +436,7 @@ func (tr *Tracker) handleWorkspaceChange(h *Handler) {
ws.RemoveClient(c)

// Tile current workspace
if ws.Enabled() {
if ws.TilingEnabled() {
tr.Tile(ws)
}

Expand All @@ -448,7 +448,7 @@ func (tr *Tracker) handleWorkspaceChange(h *Handler) {

// Add client to new workspace
ws = tr.ClientWorkspace(c)
if tr.Handlers.SwapScreen.Active() && target.Enabled() {
if tr.Handlers.SwapScreen.Active() && target.TilingEnabled() {
ws = target
}
mg = ws.ActiveLayout().GetManager()
Expand All @@ -458,7 +458,7 @@ func (tr *Tracker) handleWorkspaceChange(h *Handler) {
}

// Tile new workspace
if ws.Enabled() {
if ws.TilingEnabled() {
tr.Tile(ws)
} else {
c.Restore(store.Latest)
Expand Down
87 changes: 55 additions & 32 deletions desktop/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Workspace struct {
Location store.Location // Desktop and screen location
Layouts []Layout // List of available layouts
ActiveLayoutNum uint // Index of active layout
TilingEnabled bool // Tiling is enabled or not
Tiling bool // Tiling is enabled
}

func CreateWorkspaces() map[store.Location]*Workspace {
Expand All @@ -36,7 +36,7 @@ func CreateWorkspaces() map[store.Location]*Workspace {
Location: location,
Layouts: CreateLayouts(location),
ActiveLayoutNum: 0,
TilingEnabled: common.Config.TilingEnabled,
Tiling: common.Config.TilingEnabled,
}

// Set default layout
Expand All @@ -49,7 +49,7 @@ func CreateWorkspaces() map[store.Location]*Workspace {
// Read workspace from cache
cached := ws.Read()

// Overwrite default layout, proportions and tiling state
// Overwrite default layout, proportions, decoration and tiling state
ws.SetLayout(cached.ActiveLayoutNum)
for _, l := range ws.Layouts {
for _, cl := range cached.Layouts {
Expand All @@ -58,10 +58,11 @@ func CreateWorkspaces() map[store.Location]*Workspace {
mg.Masters.Maximum = int(math.Min(float64(cmg.Masters.Maximum), float64(common.Config.WindowMastersMax)))
mg.Slaves.Maximum = int(math.Min(float64(cmg.Slaves.Maximum), float64(common.Config.WindowSlavesMax)))
mg.Proportions = cmg.Proportions
mg.Decoration = cmg.Decoration
}
}
}
ws.TilingEnabled = cached.TilingEnabled
ws.Tiling = cached.Tiling

// Map location to workspace
workspaces[location] = ws
Expand All @@ -82,20 +83,49 @@ func CreateLayouts(loc store.Location) []Layout {
}
}

func (ws *Workspace) ResetLayouts() {
for _, l := range ws.Layouts {
l.Reset()
func (ws *Workspace) EnableTiling() {
ws.Tiling = true
}

func (ws *Workspace) DisableTiling() {
ws.Tiling = false
}

func (ws *Workspace) TilingEnabled() bool {
if ws == nil {
return false
}
return ws.Tiling
}

func (ws *Workspace) SetLayout(layoutNum uint) {
ws.ActiveLayoutNum = layoutNum
func (ws *Workspace) TilingDisabled() bool {
if ws == nil {
return true
}
return !ws.Tiling
}

func (ws *Workspace) ActiveLayout() Layout {
return ws.Layouts[ws.ActiveLayoutNum]
}

func (ws *Workspace) SetLayout(layoutNum uint) {
ws.ActiveLayoutNum = layoutNum
}

func (ws *Workspace) ResetLayouts() {

// Reset layouts
for _, l := range ws.Layouts {

// Reset client decorations
l.GetManager().Decoration = common.Config.WindowDecoration

// Reset layout proportions
l.Reset()
}
}

func (ws *Workspace) CycleLayout(step int) {

// Calculate cycle direction
Expand Down Expand Up @@ -126,9 +156,24 @@ func (ws *Workspace) RemoveClient(c *store.Client) {
}

func (ws *Workspace) Tile() {
if ws.Disabled() {
if ws.TilingDisabled() {
return
}
mg := ws.ActiveLayout().GetManager()
clients := mg.Clients(store.Stacked)

// Set client decorations
for _, c := range clients {
if c == nil {
continue
}
if mg.DecorationEnabled() {
c.Decorate()
} else {
c.UnDecorate()
}
c.Update()
}

// Apply active layout
ws.ActiveLayout().Apply()
Expand All @@ -149,28 +194,6 @@ func (ws *Workspace) Restore(flag uint8) {
}
}

func (ws *Workspace) Enable() {
ws.TilingEnabled = true
}

func (ws *Workspace) Disable() {
ws.TilingEnabled = false
}

func (ws *Workspace) Enabled() bool {
if ws == nil {
return false
}
return ws.TilingEnabled
}

func (ws *Workspace) Disabled() bool {
if ws == nil {
return true
}
return !ws.TilingEnabled
}

func (ws *Workspace) Write() {
if !common.CacheEnabled() {
return
Expand Down
Loading

0 comments on commit 249805c

Please sign in to comment.