Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Mar 18, 2022
1 parent c4ba2c6 commit 9535188
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 297 deletions.
28 changes: 17 additions & 11 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import (
var Config ConfigMapper

type ConfigMapper struct {
Keybindings map[string]string
WindowsToIgnore [][]string `toml:"ignore"`
Gap int
Division float64
Proportion float64
HideDecor bool `toml:"remove_decorations"`
StartupTiling bool `toml:"startup_tiling"`
TilingEnabled bool `toml:"tiling_enabled"` // Tile windows on startup
TilingLayout string `toml:"tiling_layout"` // Tile windows on startup
Proportion float64 `toml:"proportion"` // Master-slave area initial proportion
ProportionMin float64 `toml:"proportion_min"` // Master-slave area minimum proportion
ProportionMax float64 `toml:"proportion_max"` // Master-slave area maximum proportion
ProportionStep float64 `toml:"proportion_step"` // Master-slave area step size proportion
WindowGap int `toml:"window_gap"` // Gap size between windows
WindowDecoration bool `toml:"window_decoration"` // Show window decorations
WindowIgnore [][]string `toml:"window_ignore"` // Regex to ignore windows
Keys map[string]string `toml:"keys"` // Key bindings for shortcuts
}

func init() {
Expand All @@ -31,10 +34,12 @@ func init() {
}

func writeDefaultConfig() {
// Create config folder
if _, err := os.Stat(configFolderPath()); os.IsNotExist(err) {
os.MkdirAll(configFolderPath(), 0700)
}

// Write default config
if _, err := os.Stat(configFilePath()); os.IsNotExist(err) {
defaultConfig, err := ioutil.ReadFile("config.toml")
if err != nil {
Expand All @@ -44,12 +49,9 @@ func writeDefaultConfig() {
}
}

func configFilePath() string {
return filepath.Join(configFolderPath(), "config.toml")
}

func configFolderPath() string {
var configFolder string

switch runtime.GOOS {
case "linux":
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
Expand All @@ -64,3 +66,7 @@ func configFolderPath() string {

return configFolder
}

func configFilePath() string {
return filepath.Join(configFolderPath(), "config.toml")
}
24 changes: 12 additions & 12 deletions common/corner.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package common

type Area struct {
X1 uint
Y1 uint
X2 uint
Y2 uint
}

type Corner struct {
Name string // Corner name used in config
Enabled bool // Corner events are handled
Active bool // Mouse pointer is in this corner
Area Area // Area of the corner section
}

type Area struct {
X1 uint // Rectangle top left x position
Y1 uint // Rectangle top left y position
X2 uint // Rectangle bottom right x position
Y2 uint // Rectangle bottom right y position
}

func CreateCorner(name string, enabled bool, x1 int, y1 int, x2 int, y2 int) (c Corner) {
c = Corner{
Name: name,
Expand All @@ -33,29 +33,29 @@ func CreateCorner(name string, enabled bool, x1 int, y1 int, x2 int, y2 int) (c
func CreateCorners() []Corner {
xw, yw, ww, hw := ScreenDimensions()

// TODO: load from config
// TODO: Load from config
enabled := true
wcs, hcs := 10, 10
wcl, hcl := 100, 100

// Define corners and positions
tl := CreateCorner("top_left", enabled, xw, yw, xw+wcs, yw+hcs)
tc := CreateCorner("top_center", enabled, (xw+ww)/2-wcl/2, yw, (xw+ww)/2+wcl/2, yw+hcs)
tr := CreateCorner("top_right", enabled, xw+ww-wcs, yw, xw+ww, yw+hcs)

cr := CreateCorner("center_right", enabled, xw+ww-wcs, (yw+hw)/2-hcl/2, xw+ww, (yw+hw)/2+hcl/2)

br := CreateCorner("bottom_right", enabled, xw+ww-wcs, yw+hw-hcs, xw+ww, yw+hw)
bc := CreateCorner("bottom_center", enabled, (xw+ww)/2-wcl/2, yw+hw-hcs, (xw+ww)/2+wcl/2, yw+hw)
bl := CreateCorner("bottom_left", enabled, xw, yw+hw-hcs, xw+wcs, yw+hw)

cl := CreateCorner("center_left", enabled, xw, (yw+hw)/2-hcl/2, xw+wcs, (yw+hw)/2+hcl/2)

return []Corner{tl, tc, tr, cr, br, bc, bl, cl}
}

// Check if corner is active
func (c *Corner) IsActive(x uint, y uint) bool {
x1, y1, x2, y2 := c.Area.X1, c.Area.Y1, c.Area.X2, c.Area.Y2

// Check if enabled and inside rectangle
c.Active = c.Enabled && x >= x1 && x <= x2 && y >= y1 && y <= y2

return c.Active
}
39 changes: 20 additions & 19 deletions common/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,14 @@ func ScreenDimensions() (x, y, w, h int) {
return
}

func checkEwmhCompliance() {
_, err := ewmh.GetEwmhWM(X)
if err != nil {
log.Fatal("Window manager is not EWMH complaint!")
}
}

func checkFatal(err error) {
if err != nil {
log.Fatal("Error populating state ", err)
}
}

func checkError(err error) {
if err != nil {
log.Error("Warning populating state ", err)
}
}

func stateUpdate(X *xgbutil.XUtil, e xevent.PropertyNotifyEvent) {
var err error

aname, _ := xprop.AtomName(X, e.Atom)

log.Debug("State event ", aname)

// Update common state variables
if aname == "_NET_NUMBER_OF_DESKTOPS" {
DeskCount, err = ewmh.NumberOfDesktopsGet(X)
} else if aname == "_NET_CURRENT_DESKTOP" {
Expand All @@ -179,3 +161,22 @@ func stateUpdate(X *xgbutil.XUtil, e xevent.PropertyNotifyEvent) {
log.Warn("Warning updating state ", err)
}
}

func checkEwmhCompliance() {
_, err := ewmh.GetEwmhWM(X)
if err != nil {
log.Fatal("Window manager is not EWMH complaint!")
}
}

func checkFatal(err error) {
if err != nil {
log.Fatal("Error populating state ", err)
}
}

func checkError(err error) {
if err != nil {
log.Error("Warning populating state ", err)
}
}
51 changes: 28 additions & 23 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# The WM_CLASS (class="ignore all", title="but allow main") of the window used for perl regex match.
# You can find WM_CLASS string name by running "xprop WM_CLASS".
ignore = [
# Tiling will be enabled on application start if set to true.
tiling_enabled = true

# Initial tiling layout ('vertical', 'horizontal', 'fullscreen')
tiling_layout = "vertical"

# Initial division of master-slave area.
proportion = 0.6

# Minimum division of master-slave area.
proportion_min = 0.1

# Maximum division of master-slave area.
proportion_max = 0.9

# How much to increment/decrement master-slave area.
proportion_step = 0.05

# How much space should be left between windows.
window_gap = 4

# Window decorations will be removed if set to false.
window_decoration = true

# Perl regex to ignore windows (['WM_CLASS', 'WM_NAME'] = ['ignore all windows with this class', 'but allow those with this name']).
# The WM_CLASS string name can be found by running 'xprop WM_CLASS'.
window_ignore = [
['xf.*', ''],
['nm.*', ''],
['gcr.*', ''],
Expand All @@ -9,30 +33,11 @@ ignore = [
['lightdm.*', ''],
['blueman.*', ''],
['pavucontrol.*', ''],
['thunderbird.*', ''],
['engrampa.*', ''],
['gimp.*', '.*GIMP'],
['inkscape.*', '.*Inkscape'],
['firefox.*', '.*Mozilla Firefox'],
]

# Tiling will be enabled on application start if set to true
startup_tiling = true

# Window decorations will be removed when tiling if set to true
remove_decorations = false

# Adds spacing between windows
gap = 4

# Initial division of master area size.
division = 0.5

# How much to increment the master area size.
proportion = 0.1


[keybindings]
[keys]
# You can view which keys activate which modifier using the 'xmodmap' program.
# Key symbols can be found by pressing keys using the 'xev' program.

Expand Down
Loading

0 comments on commit 9535188

Please sign in to comment.