Permalink
Browse files

Big change is moving moving/resizing drag code to the client.

  • Loading branch information...
1 parent 2d9072c commit 428aa932daad7bf288e882bd64e6e3e150cf7b4f @BurntSushi committed Jun 17, 2012
Showing with 40 additions and 234 deletions.
  1. +5 −1 frame/borders.go
  2. +1 −1 frame/client.go
  3. +12 −3 frame/frame.go
  4. +5 −1 frame/full.go
  5. +3 −224 frame/interface.go
  6. +9 −3 frame/nada.go
  7. +5 −1 frame/slim.go
View
@@ -16,7 +16,7 @@ type Borders struct {
}
func NewBorders(X *xgbutil.XUtil,
- t *theme.Theme, p *Parent, c client) (*Borders, error) {
+ t *theme.Theme, p *Parent, c Client) (*Borders, error) {
f, err := newFrame(X, t, p, c)
if err != nil {
@@ -91,6 +91,8 @@ func (f *Borders) On() {
}
func (f *Borders) Active() {
+ f.State = Active
+
f.topSide.Active()
f.bottomSide.Active()
f.leftSide.Active()
@@ -106,6 +108,8 @@ func (f *Borders) Active() {
}
func (f *Borders) Inactive() {
+ f.State = Inactive
+
f.topSide.Inactive()
f.bottomSide.Inactive()
f.leftSide.Inactive()
View
@@ -8,7 +8,7 @@ import (
"github.com/BurntSushi/xgbutil/xwindow"
)
-type client interface {
+type Client interface {
State() int
Frame() Frame
Maximized() bool
View
@@ -45,11 +45,12 @@ type frame struct {
ResizeState *ResizeState
State int
parent *Parent
- client client
+ client Client
+ isMapped bool
}
func newFrame(X *xgbutil.XUtil,
- t *theme.Theme, p *Parent, c client) (*frame, error) {
+ t *theme.Theme, p *Parent, c Client) (*frame, error) {
var err error
if p == nil {
@@ -66,10 +67,12 @@ func newFrame(X *xgbutil.XUtil,
client: c,
MoveState: &MoveState{},
ResizeState: &ResizeState{},
+ State: Inactive,
+ isMapped: false,
}, nil
}
-func (f *frame) Client() client {
+func (f *frame) Client() Client {
return f.client
}
@@ -100,16 +103,22 @@ func (f *frame) Destroy() {
func (f *frame) Map() {
f.parent.Map()
+ f.isMapped = true
}
func (f *frame) Unmap() {
f.parent.Unmap()
+ f.isMapped = false
}
func (f *frame) Geom() xrect.Rect {
return f.parent.Geom
}
+func (f *frame) IsMapped() bool {
+ return f.isMapped
+}
+
func (f *frame) Moving() bool {
return f.MoveState.Moving
}
View
@@ -25,7 +25,7 @@ type Full struct {
}
func NewFull(X *xgbutil.XUtil,
- t *theme.Theme, p *Parent, c client) (*Full, error) {
+ t *theme.Theme, p *Parent, c Client) (*Full, error) {
f, err := newFrame(X, t, p, c)
if err != nil {
@@ -145,6 +145,8 @@ func (f *Full) On() {
}
func (f *Full) Active() {
+ f.State = Active
+
if f.theme.Full.BorderSize > 0 {
f.topSide.Active()
f.bottomSide.Active()
@@ -170,6 +172,8 @@ func (f *Full) Active() {
}
func (f *Full) Inactive() {
+ f.State = Inactive
+
if f.theme.Full.BorderSize > 0 {
f.topSide.Inactive()
f.bottomSide.Inactive()
View
@@ -1,22 +1,18 @@
package frame
import (
- "github.com/BurntSushi/xgb/xproto"
-
- "github.com/BurntSushi/xgbutil/ewmh"
"github.com/BurntSushi/xgbutil/xrect"
-
- "github.com/BurntSushi/wingo/cursors"
)
type Frame interface {
- Client() client
+ Client() Client
Parent() *Parent
Map()
Unmap()
Destroy()
Geom() xrect.Rect
+ IsMapped() bool
Move(x, y int)
Resize(validate bool, width, height int)
@@ -45,7 +41,7 @@ type Frame interface {
func Reset(f Frame) {
geom := f.Geom()
- f.Resize(true, geom.Width(), geom.Height())
+ f.Resize(false, geom.Width(), geom.Height())
}
func ClientToFrame(f Frame, x, y, w, h int) (int, int, int, int) {
@@ -104,220 +100,3 @@ func Maximize(f Frame) {
hg := xrect.New(xrect.Pieces(f.Client().HeadGeom()))
f.MoveResize(false, hg.X(), hg.Y(), hg.Width(), hg.Height())
}
-
-func DragMoveBegin(f Frame, rx, ry, ex, ey int) {
- moving := f.MovingState()
- moving.Moving = true
- moving.RootX, moving.RootY = rx, ry
-
- // call for side-effect; makes sure parent window has a valid geometry
- f.Parent().Geometry()
-
- // unmax!
- f.Client().EnsureUnmax()
-}
-
-func DragMoveStep(f Frame, rx, ry, ex, ey int) {
- moving := f.MovingState()
- newx := f.Geom().X() + rx - moving.RootX
- newy := f.Geom().Y() + ry - moving.RootY
- moving.RootX, moving.RootY = rx, ry
-
- f.Move(newx, newy)
-}
-
-func DragMoveEnd(f Frame, rx, ry, ex, ey int) {
- Reset(f)
- // WM.headChoose(f.Client(), f.Geom())
-
- moving := f.MovingState()
- moving.Moving = false
- moving.RootX, moving.RootY = 0, 0
-}
-
-func DragResizeBegin(f Frame, direction uint32,
- rx, ry, ex, ey int) (bool, xproto.Cursor) {
-
- // call for side-effect; makes sure parent window has a valid geometry
- f.Parent().Geometry()
-
- resizing := f.ResizingState()
- dir := direction
- w, h := f.Geom().Width(), f.Geom().Height()
-
- // If we aren't forcing a direction, we need to infer it based on
- // where the mouse is in the window.
- // (ex, ey) is the position of the mouse.
- // We basically split the window into something like a tic-tac-toe board:
- // -------------------------
- // | | | |
- // | A | | F |
- // | | D | |
- // --------- |--------
- // | | | |
- // | B |-------| G |
- // | | | |
- // --------- |--------
- // | | E | |
- // | C | | H |
- // | | | |
- // -------------------------
- // Where A, B, C correspond to 'ex < w / 3'
- // and F, G, H correspond to 'ex > w * 2 / 3'
- // and D and E correspond to 'ex >= w / 3 && ex <= w * 2 / 3'
- // The direction is not only important for assigning which cursor to display
- // (where each of the above blocks gets its own cursor), but it is also
- // important for choosing which parts of the geometry to change.
- // For example, if the mouse is in 'H', then the width and height could
- // be changed, but x and y cannot. Conversely, if the mouse is in 'A',
- // all parts of the geometry can change: x, y, width and height.
- // As one last example, if the mouse is in 'D', only y and height of the
- // window can change.
- if dir == ewmh.Infer {
- if ex < w/3 {
- switch {
- case ey < h/3:
- dir = ewmh.SizeTopLeft
- case ey > h*2/3:
- dir = ewmh.SizeBottomLeft
- default: // ey >= h / 3 && ey <= h * 2 / 3
- dir = ewmh.SizeLeft
- }
- } else if ex > w*2/3 {
- switch {
- case ey < h/3:
- dir = ewmh.SizeTopRight
- case ey > h*2/3:
- dir = ewmh.SizeBottomRight
- default: // ey >= h / 3 && ey <= h * 2 / 3
- dir = ewmh.SizeRight
- }
- } else { // ex >= w / 3 && ex <= w * 2 / 3
- switch {
- case ey < h/2:
- dir = ewmh.SizeTop
- default: // ey >= h / 2
- dir = ewmh.SizeBottom
- }
- }
- }
-
- // Find the right cursor
- var cursor xproto.Cursor = 0
- switch dir {
- case ewmh.SizeTop:
- cursor = cursors.TopSide
- case ewmh.SizeTopRight:
- cursor = cursors.TopRightCorner
- case ewmh.SizeRight:
- cursor = cursors.RightSide
- case ewmh.SizeBottomRight:
- cursor = cursors.BottomRightCorner
- case ewmh.SizeBottom:
- cursor = cursors.BottomSide
- case ewmh.SizeBottomLeft:
- cursor = cursors.BottomLeftCorner
- case ewmh.SizeLeft:
- cursor = cursors.LeftSide
- case ewmh.SizeTopLeft:
- cursor = cursors.TopLeftCorner
- }
-
- // Save some state that we'll need when computing a window's new geometry
- resizing.Resizing = true
- resizing.RootX, resizing.RootY = rx, ry
- resizing.X, resizing.Y = f.Geom().X(), f.Geom().Y()
- resizing.Width, resizing.Height = f.Geom().Width(), f.Geom().Height()
-
- // Our geometry calculations depend upon which direction we're resizing.
- // Namely, the direction determines which parts of the geometry need to
- // be modified. Pre-compute those parts (i.e., x, y, width and/or height)
- resizing.Xs = dir == ewmh.SizeLeft || dir == ewmh.SizeTopLeft ||
- dir == ewmh.SizeBottomLeft
- resizing.Ys = dir == ewmh.SizeTop || dir == ewmh.SizeTopLeft ||
- dir == ewmh.SizeTopRight
- resizing.Ws = dir == ewmh.SizeTopLeft || dir == ewmh.SizeTopRight ||
- dir == ewmh.SizeRight || dir == ewmh.SizeBottomRight ||
- dir == ewmh.SizeBottomLeft || dir == ewmh.SizeLeft
- resizing.Hs = dir == ewmh.SizeTopLeft || dir == ewmh.SizeTop ||
- dir == ewmh.SizeTopRight || dir == ewmh.SizeBottomRight ||
- dir == ewmh.SizeBottom || dir == ewmh.SizeBottomLeft
-
- // unmax!
- f.Client().EnsureUnmax()
-
- return true, cursor
-}
-
-func DragResizeStep(f Frame, rx, ry, ex, ey int) {
- resizing := f.ResizingState()
-
- diffx, diffy := rx-resizing.RootX, ry-resizing.RootY
- newx, newy, neww, newh := 0, 0, 0, 0
- validw, validh := 0, 0
- flags := 0
-
- if resizing.Xs {
- flags |= fX
- newx = resizing.X + diffx
- }
- if resizing.Ys {
- flags |= fY
- newy = resizing.Y + diffy
- }
- if resizing.Ws {
- flags |= fW
- if resizing.Xs {
- neww = resizing.Width - diffx
- } else {
- neww = resizing.Width + diffx
- }
-
- leftRight := f.Left() + f.Right()
- validw = f.Client().ValidateWidth(neww-leftRight) + leftRight
-
- // If validation changed our width, we need to make sure
- // our x-value is appropriately changed
- if resizing.Xs && validw != neww {
- newx = resizing.X + resizing.Width - validw
- }
- }
- if resizing.Hs {
- flags |= fH
- if resizing.Ys {
- newh = resizing.Height - diffy
- } else {
- newh = resizing.Height + diffy
- }
-
- topBot := f.Top() + f.Bottom()
- validh = f.Client().ValidateHeight(newh-topBot) + topBot
-
- // If validation changed our height, we need to make sure
- // our y-value is appropriately changed
- if resizing.Ys && validh != newh {
- newy = resizing.Y + resizing.Height - validh
- }
- }
-
- f.MROpt(false, flags, newx, newy, validw, validh)
-}
-
-func DragResizeEnd(f Frame, rx, ry, ex, ey int) {
- // If windows are really slow to respond/resize, this may be necessary.
- // If we don't, it's possible for the client to be out of whack inside
- // the decorations.
- // Example: Libreoffice in Xephyr. Try resizing it with the mouse and
- // releasing the mouse button really quickly.
- Reset(f)
- // WM.headChoose(f.Client(), f.Geom())
-
- // just zero out the resizing state
- resizing := f.ResizingState()
- resizing.Resizing = false
- resizing.RootX, resizing.RootY = 0, 0
- resizing.X, resizing.Y = 0, 0
- resizing.Width, resizing.Height = 0, 0
- resizing.Xs, resizing.Ys = false, false
- resizing.Ws, resizing.Hs = false, false
-}
View
@@ -11,7 +11,7 @@ type Nada struct {
}
func NewNada(X *xgbutil.XUtil,
- t *theme.Theme, p *Parent, c client) (*Nada, error) {
+ t *theme.Theme, p *Parent, c Client) (*Nada, error) {
f, err := newFrame(X, t, p, c)
if err != nil {
@@ -30,8 +30,14 @@ func (f *Nada) On() {
Reset(f)
}
-func (f *Nada) Active() {}
-func (f *Nada) Inactive() {}
+func (f *Nada) Active() {
+ f.State = Active
+}
+
+func (f *Nada) Inactive() {
+ f.State = Inactive
+}
+
func (f *Nada) Maximize() {}
func (f *Nada) Unmaximize() {}
Oops, something went wrong.

0 comments on commit 428aa93

Please sign in to comment.