Skip to content

Commit

Permalink
add command scope
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Jul 2, 2023
1 parent d04e197 commit 94df389
Show file tree
Hide file tree
Showing 20 changed files with 345 additions and 262 deletions.
23 changes: 16 additions & 7 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tiling_gui = 1500
# Menu entries in systray which shows the tiling state as icon ([] = disabled).
# tiling_icon = [
# ['ACTION', 'TEXT'] = ['action strings from [keys] section', 'text to show in the menu'],
# ['', ''] = 'render a separator',
# ['', ''] = 'show a separator line',
# ]
tiling_icon = [
['toggle', 'Enabled'],
Expand Down Expand Up @@ -109,13 +109,16 @@ icon_foreground = [255, 255, 255, 255]
[keys] # Key symbols can be found by running 'xev'. #
################################################################################

# Tile the current workspace.
tile = "Control-Shift-Home"
# Enable tiling on the current screen.
enable = "Control-Shift-Home"

# Untile the current workspace.
untile = "Control-Shift-End"
# Disable tiling on the current screen.
disable = "Control-Shift-End"

# Toggle between tile and untile.
# 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"

# Cycles through next layouts.
Expand All @@ -139,7 +142,7 @@ layout_horizontal_top = "Control-Shift-Up"
# Activates the horizontal-bottom layout.
layout_horizontal_bottom = "Control-Shift-Down"

# Make the active window as master.
# Make the active window a master.
master_make = "Control-Shift-M"

# Increase the number of masters.
Expand All @@ -166,6 +169,12 @@ window_next = "Control-Shift-KP_2"
# Moves focus to the previous window.
window_previous = "Control-Shift-KP_8"

# The commands above will affect all screens if this key is pressed in addition (Mod1 = Alt_L).
mod_screens = "Mod1"

# The commands above will affect all workspaces if this key is pressed in addition (Mod4 = Super_L).
mod_workspaces = "Mod4"

################################################################################
[corners] # Action strings from [keys] or external commands. #
################################################################################
Expand Down
3 changes: 1 addition & 2 deletions desktop/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package desktop
import "github.com/leukipp/cortile/store"

type Layout interface {
Do()
Undo()
Apply()
AddClient(c *store.Client)
RemoveClient(c *store.Client)
MakeMaster(c *store.Client)
Expand Down
34 changes: 21 additions & 13 deletions desktop/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func CreateTracker(ws map[Location]*Workspace) *Tracker {

func (tr *Tracker) Update() {
ws := tr.ActiveWorkspace()
if !ws.IsEnabled() {
if ws.Disabled() {
return
}
log.Debug("Update trackable clients [", len(tr.Clients), "/", len(store.Windows), "]")
Expand Down Expand Up @@ -108,18 +108,26 @@ func (tr *Tracker) Reset() {
}

func (tr *Tracker) ActiveWorkspace() *Workspace {
ws := tr.Workspaces[Location{DeskNum: store.CurrentDesk, ScreenNum: store.CurrentScreen}]
location := Location{DeskNum: store.CurrentDesk, ScreenNum: store.CurrentScreen}

// Validate active workspace
ws := tr.Workspaces[location]
if ws == nil {
log.Warn("Invalid active workspace [workspace-", store.CurrentDesk, "-", store.CurrentScreen, "]")
log.Warn("Invalid active workspace [workspace-", location.DeskNum, "-", location.ScreenNum, "]")
}

return ws
}

func (tr *Tracker) ClientWorkspace(c *store.Client) *Workspace {
ws := tr.Workspaces[Location{DeskNum: c.Latest.DeskNum, ScreenNum: c.Latest.ScreenNum}]
location := Location{DeskNum: c.Latest.DeskNum, ScreenNum: c.Latest.ScreenNum}

// Validate client workspace
ws := tr.Workspaces[location]
if ws == nil {
log.Warn("Invalid client workspace [workspace-", c.Latest.DeskNum, "-", c.Latest.ScreenNum, "]")
log.Warn("Invalid client workspace [workspace-", location.DeskNum, "-", location.ScreenNum, "]")
}

return ws
}

Expand Down Expand Up @@ -154,7 +162,7 @@ func (tr *Tracker) untrackWindow(w xproto.Window) bool {
xevent.Detach(store.X, w)

// Restore client
c.Restore()
c.Restore(false)

// Remove client
ws.RemoveClient(c)
Expand All @@ -172,9 +180,9 @@ func (tr *Tracker) handleMaximizedClient(c *store.Client) {
// Client maximized
states, _ := ewmh.WmStateGet(store.X, c.Win.Id)
for _, state := range states {
if strings.Contains(state, "_NET_WM_STATE_MAXIMIZED") {
if strings.HasPrefix(state, "_NET_WM_STATE_MAXIMIZED") {
ws := tr.ClientWorkspace(c)
if !ws.IsEnabled() {
if ws.Disabled() {
return
}
log.Debug("Client maximized handler fired [", c.Latest.Class, "]")
Expand All @@ -197,7 +205,7 @@ func (tr *Tracker) handleMinimizedClient(c *store.Client) {
for _, state := range states {
if state == "_NET_WM_STATE_HIDDEN" {
ws := tr.ClientWorkspace(c)
if !ws.IsEnabled() {
if ws.Disabled() {
return
}
log.Debug("Client minimized handler fired [", c.Latest.Class, "]")
Expand All @@ -211,7 +219,7 @@ func (tr *Tracker) handleMinimizedClient(c *store.Client) {

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

Expand Down Expand Up @@ -342,7 +350,7 @@ func (tr *Tracker) handleWorkspaceChange(c *store.Client) {
// Remove client from current workspace
ws := tr.ClientWorkspace(c)
ws.RemoveClient(c)
if ws.IsEnabled() {
if ws.Enabled() {
ws.Tile()
}

Expand All @@ -358,10 +366,10 @@ func (tr *Tracker) handleWorkspaceChange(c *store.Client) {
// Add client to new workspace
ws = tr.ClientWorkspace(c)
ws.AddClient(c)
if ws.IsEnabled() {
if ws.Enabled() {
ws.Tile()
} else {
c.Restore()
c.Restore(false)
}
}

Expand Down
51 changes: 35 additions & 16 deletions desktop/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func (ws *Workspace) ActiveLayout() Layout {
}

func (ws *Workspace) CycleLayout(step int) {
if !ws.IsEnabled() {
if ws.Disabled() {
return
}

// Calculate cycle direction
i := (int(ws.ActiveLayoutNum) + step) % len(ws.Layouts)
if i < 0 {
i = len(ws.Layouts) - 1
Expand All @@ -78,17 +79,6 @@ func (ws *Workspace) CycleLayout(step int) {
ws.Tile()
}

func (ws *Workspace) Tile() {
if !ws.IsEnabled() {
return
}
ws.ActiveLayout().Do()
}

func (ws *Workspace) UnTile() {
ws.ActiveLayout().Undo()
}

func (ws *Workspace) AddClient(c *store.Client) {
log.Info("Add client for each layout [", c.Latest.Class, "]")

Expand All @@ -107,16 +97,45 @@ func (ws *Workspace) RemoveClient(c *store.Client) {
}
}

func (ws *Workspace) Enable(enable bool) {
if ws == nil {
func (ws *Workspace) Tile() {
if ws.Disabled() {
return
}
ws.TilingEnabled = enable

// Apply active layout
ws.ActiveLayout().Apply()
}

func (ws *Workspace) Restore(original bool) {
mg := ws.ActiveLayout().GetManager()
clients := mg.Clients(true)

log.Info("Untile ", len(clients), " windows [workspace-", mg.DeskNum, "-", mg.ScreenNum, "]")

// Restore client dimensions
for _, c := range clients {
c.Restore(original)
}
}

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

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

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

func (ws *Workspace) Disabled() bool {
if ws == nil {
return false
}
return !ws.TilingEnabled
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/godbus/dbus/v5 v5.1.0
github.com/sirupsen/logrus v1.9.3
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
golang.org/x/image v0.8.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K0
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg=
golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down
Loading

0 comments on commit 94df389

Please sign in to comment.