Skip to content

Commit

Permalink
ref: move location struct into store
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Sep 16, 2023
1 parent abd2d44 commit 7f8a8ae
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
17 changes: 6 additions & 11 deletions desktop/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ import (

type Tracker struct {
Clients map[xproto.Window]*store.Client // List of clients that are being tracked
Workspaces map[Location]*Workspace // List of workspaces per location
Workspaces map[store.Location]*Workspace // List of workspaces per location
Action chan string // Event channel for actions
Handler *Handler // Helper for event handlers
}

type Location struct {
DeskNum uint // Workspace desktop number
ScreenNum uint // Workspace screen number
}

type Handler struct {
Timer *time.Timer // Timer to handle delayed structure events
ResizeClient *HandlerClient // Stores client for proportion change
Expand All @@ -42,7 +37,7 @@ type HandlerClient struct {
Target *store.Client // Stores hovered client
}

func CreateTracker(ws map[Location]*Workspace) *Tracker {
func CreateTracker(ws map[store.Location]*Workspace) *Tracker {
tr := Tracker{
Clients: make(map[xproto.Window]*store.Client),
Workspaces: ws,
Expand Down Expand Up @@ -108,7 +103,7 @@ func (tr *Tracker) Reset() {
}

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

// Validate active workspace
ws := tr.Workspaces[location]
Expand All @@ -120,7 +115,7 @@ func (tr *Tracker) ActiveWorkspace() *Workspace {
}

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

// Validate client workspace
ws := tr.Workspaces[location]
Expand Down Expand Up @@ -308,7 +303,7 @@ func (tr *Tracker) handleMoveClient(c *store.Client) {
}

// Store moved client and hovered client
if common.IsInsideRect(pt, co.Latest.Dimensions.Geometry) {
if common.IsInsideRect(pt, co.Latest.Dimensions.Geometry.Rect) {
tr.Handler.SwapClient = &HandlerClient{Active: true, Source: c, Target: co}
log.Debug("Client move handler active [", c.Latest.Class, "-", co.Latest.Class, "]")
break
Expand All @@ -317,7 +312,7 @@ func (tr *Tracker) handleMoveClient(c *store.Client) {

// Check if pointer moves to another screen
tr.Handler.SwapScreen.Active = false
if c.Latest.ScreenNum != store.CurrentScreen {
if c.Latest.Location.ScreenNum != store.CurrentScreen {
tr.Handler.SwapScreen = &HandlerClient{Active: true, Source: c}
}
}
Expand Down
16 changes: 8 additions & 8 deletions desktop/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
)

type Workspace struct {
Location Location // Desktop and screen location
Layouts []Layout // List of available layouts
TilingEnabled bool // Tiling is enabled or not
ActiveLayoutNum uint // Active layout index
Location store.Location // Desktop and screen location
Layouts []Layout // List of available layouts
TilingEnabled bool // Tiling is enabled or not
ActiveLayoutNum uint // Active layout index
}

func CreateWorkspaces() map[Location]*Workspace {
workspaces := make(map[Location]*Workspace)
func CreateWorkspaces() map[store.Location]*Workspace {
workspaces := make(map[store.Location]*Workspace)

for deskNum := uint(0); deskNum < store.DeskCount; deskNum++ {
for screenNum := uint(0); screenNum < store.ScreenCount; screenNum++ {
location := Location{DeskNum: deskNum, ScreenNum: screenNum}
location := store.Location{DeskNum: deskNum, ScreenNum: screenNum}

// Create layouts for each desktop and screen
layouts := CreateLayouts(location)
Expand All @@ -46,7 +46,7 @@ func CreateWorkspaces() map[Location]*Workspace {
return workspaces
}

func CreateLayouts(l Location) []Layout {
func CreateLayouts(l store.Location) []Layout {
return []Layout{
layout.CreateFullscreenLayout(l.DeskNum, l.ScreenNum),
layout.CreateVerticalLeftLayout(l.DeskNum, l.ScreenNum),
Expand Down
45 changes: 32 additions & 13 deletions store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,33 @@ type Client struct {
type Info struct {
Class string // Client window application name
Name string // Client window title name
DeskNum uint // Client window desktop
ScreenNum uint // Client window screen
Types []string // Client window types
States []string // Client window states
Location Location // Client window location
Dimensions Dimensions // Client window dimensions
}

type Location struct {
DeskNum uint // Client workspace desktop number
ScreenNum uint // Client workspace screen number
}

type Dimensions struct {
Geometry xrect.Rect // Client window geometry
Geometry Geometry // Client window geometry
Hints Hints // Client window dimension hints
Extents ewmh.FrameExtents // Client window geometry extents
AdjPos bool // Adjust position on move/resize
AdjSize bool // Adjust size on move/resize
}

type Geometry struct {
xrect.Rect `json:"-"` // Client window geometry functions
X int // Client window geometry x position
Y int // Client window geometry y position
Width int // Client window geometry width dimension
Height int // Client window geometry height dimension
}

type Hints struct {
Normal icccm.NormalHints // Client window geometry hints
Motif motif.Hints // Client window decoration hints
Expand Down Expand Up @@ -197,7 +209,7 @@ func (c *Client) Restore(original bool) {
if original {
geom = c.Original.Dimensions.Geometry
}
c.MoveResize(geom.X(), geom.Y(), geom.Width()-dw, geom.Height()-dh)
c.MoveResize(geom.X, geom.Y, geom.Width-dw, geom.Height-dh)
}

func (c *Client) OuterGeometry() (x, y, w, h int) {
Expand Down Expand Up @@ -324,10 +336,9 @@ func GetInfo(w xproto.Window) *Info {

var class string
var name string
var deskNum uint
var screenNum uint
var types []string
var states []string
var location Location
var dimensions Dimensions

// Window class (internal class name of the window)
Expand All @@ -345,11 +356,14 @@ func GetInfo(w xproto.Window) *Info {
}

// Window desktop and screen (window workspace location)
deskNum, err = ewmh.WmDesktopGet(X, w)
deskNum, err := ewmh.WmDesktopGet(X, w)
if err != nil || deskNum > DeskCount {
deskNum = CurrentDesktopGet(X)
}
screenNum = GetScreenNum(w)
location = Location{
DeskNum: deskNum,
ScreenNum: GetScreenNum(w),
}

// Window types (types of the window)
types, err = ewmh.WmWindowTypeGet(X, w)
Expand All @@ -364,9 +378,9 @@ func GetInfo(w xproto.Window) *Info {
}

// Window geometry (dimensions of the window)
geometry, err := xwindow.New(X, w).DecorGeometry()
geom, err := xwindow.New(X, w).DecorGeometry()
if err != nil {
geometry = &xrect.XRect{}
geom = &xrect.XRect{}
}

// Window normal hints (normal hints of the window)
Expand Down Expand Up @@ -395,7 +409,13 @@ func GetInfo(w xproto.Window) *Info {

// Window dimensions (geometry/extent information for move/resize)
dimensions = Dimensions{
Geometry: geometry,
Geometry: Geometry{
Rect: geom,
X: geom.X(),
Y: geom.Y(),
Width: geom.Width(),
Height: geom.Height(),
},
Hints: Hints{
Normal: *nhints,
Motif: *mhints,
Expand All @@ -413,10 +433,9 @@ func GetInfo(w xproto.Window) *Info {
return &Info{
Class: class,
Name: name,
DeskNum: deskNum,
ScreenNum: screenNum,
Types: types,
States: states,
Location: location,
Dimensions: dimensions,
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
)

func ShowLayout(ws *desktop.Workspace) {
location := desktop.Location{DeskNum: store.CurrentDesk, ScreenNum: store.CurrentScreen}
location := store.Location{DeskNum: store.CurrentDesk, ScreenNum: store.CurrentScreen}
if common.Config.TilingGui <= 0 || ws.Location.DeskNum != location.DeskNum {
return
}
Expand Down
2 changes: 1 addition & 1 deletion ui/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
)

func UpdateIcon(ws *desktop.Workspace) {
location := desktop.Location{DeskNum: store.CurrentDesk, ScreenNum: store.CurrentScreen}
location := store.Location{DeskNum: store.CurrentDesk, ScreenNum: store.CurrentScreen}
if len(common.Config.TilingIcon) == 0 || ws.Location != location {
return
}
Expand Down

0 comments on commit 7f8a8ae

Please sign in to comment.