screenedge: add delay time before exec edge action

tower: https://tower.im/projects/1c0cd0c59ef941298c6e6b2ba6833b91/todos/da5e4f39d9904ed5bad37b7d5d470d70/
Change-Id: Ie3d28f354d22592de6ebbc5cc0c987fe76c24432
This commit is contained in:
jouyouyun 2015-02-02 11:39:21 +08:00 committed by jouyouwen717
parent b3a49724f6
commit 660a820a61
3 changed files with 117 additions and 45 deletions

View File

@ -54,7 +54,7 @@ func (op *Manager) EnableZoneDetected(enable bool) {
func (op *Manager) SetTopLeft(value string) {
mutex.Lock()
defer mutex.Unlock()
edgeActionMap[EDGE_TOPLEFT] = value
edgeActionMap[leftTopEdge] = value
}
func (op *Manager) TopLeftAction() string {
@ -64,7 +64,7 @@ func (op *Manager) TopLeftAction() string {
func (op *Manager) SetBottomLeft(value string) {
mutex.Lock()
defer mutex.Unlock()
edgeActionMap[EDGE_BOTTOMLEFT] = value
edgeActionMap[leftBottomEdge] = value
}
func (op *Manager) BottomLeftAction() string {
@ -74,7 +74,7 @@ func (op *Manager) BottomLeftAction() string {
func (op *Manager) SetTopRight(value string) {
mutex.Lock()
defer mutex.Unlock()
edgeActionMap[EDGE_TOPRIGHT] = value
edgeActionMap[rightTopEdge] = value
}
func (op *Manager) TopRightAction() string {
@ -84,7 +84,7 @@ func (op *Manager) TopRightAction() string {
func (op *Manager) SetBottomRight(value string) {
mutex.Lock()
defer mutex.Unlock()
edgeActionMap[EDGE_BOTTOMRIGHT] = value
edgeActionMap[rightBottomEdge] = value
}
func (op *Manager) BottomRightAction() string {

View File

@ -25,6 +25,7 @@ import (
"os/exec"
"pkg.linuxdeepin.com/lib/dbus"
"strings"
"time"
)
type areaRange struct {
@ -35,12 +36,21 @@ type areaRange struct {
}
const (
DISTANCE = int32(10)
EDGE_TOPLEFT = "TopLeft"
EDGE_BOTTOMLEFT = "BottomLeft"
EDGE_TOPRIGHT = "TopRight"
EDGE_BOTTOMRIGHT = "BottomRight"
ACTION_WORKSPACE = "workspace"
edgeDistance int32 = 5
leftTopEdge = "TopLeft"
leftBottomEdge = "BottomLeft"
rightTopEdge = "TopRight"
rightBottomEdge = "BottomRight"
edgeActionWorkspace = "workspace"
)
const (
leftTopDelay int32 = 0
leftBottomDelay = 0
rightTopDelay = 0
rightBottomDelay = 500
)
var (
@ -79,13 +89,13 @@ func registerZoneArea() {
return
}
topLeftArea = areaRange{startX, startY, startX + DISTANCE, startY + DISTANCE}
topLeftArea = areaRange{startX, startY, startX + edgeDistance, startY + edgeDistance}
logger.Debug("TopLeft: ", topLeftArea)
bottomLeftArea = areaRange{startX, endY - DISTANCE, startX + DISTANCE, endY}
bottomLeftArea = areaRange{startX, endY - edgeDistance, startX + edgeDistance, endY}
logger.Debug("BottomLeft: ", bottomLeftArea)
topRightArea = areaRange{endX - DISTANCE, startY, endX, startY + DISTANCE}
topRightArea = areaRange{endX - edgeDistance, startY, endX, startY + edgeDistance}
logger.Debug("TopRight: ", topRightArea)
bottomRightArea = areaRange{endX - DISTANCE, endY - DISTANCE, endX, endY}
bottomRightArea = areaRange{endX - edgeDistance, endY - edgeDistance, endX, endY}
logger.Debug("BottomRight: ", bottomRightArea)
logger.Debug("topLeft: ", topLeftArea)
@ -183,8 +193,41 @@ func (m *Manager) destroy() {
func newManager() *Manager {
m := &Manager{}
m.lTopTimer = &edgeTimer{}
m.lBottomTimer = &edgeTimer{}
m.rTopTimer = &edgeTimer{}
m.rBottomTimer = &edgeTimer{}
registerZoneArea()
m.listenSignal()
return m
}
type edgeTimer struct {
timer *time.Timer
}
func (eTimer *edgeTimer) DoAction(edge string, timeout int32) {
if timeout == 0 {
execEdgeAction(edge)
return
}
eTimer.timer = time.NewTimer(time.Millisecond *
time.Duration(timeout))
go func() {
<-eTimer.timer.C
execEdgeAction(edge)
eTimer.timer = nil
}()
}
func (eTimer *edgeTimer) StopTimer() {
if eTimer.timer == nil {
return
}
eTimer.timer.Stop()
eTimer.timer = nil
}

View File

@ -25,7 +25,12 @@ import (
"pkg.linuxdeepin.com/lib/dbus"
)
type Manager struct{}
type Manager struct {
lTopTimer *edgeTimer
lBottomTimer *edgeTimer
rTopTimer *edgeTimer
rBottomTimer *edgeTimer
}
const (
ZONE_DEST = "com.deepin.daemon.Zone"
@ -33,7 +38,7 @@ const (
ZONE_IFC = "com.deepin.daemon.Zone"
)
func (op *Manager) GetDBusInfo() dbus.DBusInfo {
func (m *Manager) GetDBusInfo() dbus.DBusInfo {
return dbus.DBusInfo{
Dest: ZONE_DEST,
ObjectPath: ZONE_PATH,
@ -41,36 +46,18 @@ func (op *Manager) GetDBusInfo() dbus.DBusInfo {
}
}
func (op *Manager) listenSignal() {
func (m *Manager) listenSignal() {
dspObj.ConnectPrimaryChanged(func(argv []interface{}) {
unregisterZoneArea()
registerZoneArea()
})
areaObj.ConnectCursorInto(func(x, y int32, id string) {
if id != areaId {
return
}
m.handleCursorSignal(x, y, id, true)
})
if isAppInBlackList() {
return
}
if pid, ok := isActiveWindowFullscreen(); ok {
if !isAppInWhiteList(pid) {
return
}
}
if isInArea(x, y, topLeftArea) {
execEdgeAction(EDGE_TOPLEFT)
} else if isInArea(x, y, bottomLeftArea) {
execEdgeAction(EDGE_BOTTOMLEFT)
} else if isInArea(x, y, topRightArea) {
execEdgeAction(EDGE_TOPRIGHT)
} else if isInArea(x, y, bottomRightArea) {
execEdgeAction(EDGE_BOTTOMRIGHT)
}
areaObj.ConnectCursorOut(func(x, y int32, id string) {
m.handleCursorSignal(x, y, id, false)
})
areaObj.ConnectCancelAllArea(func() {
@ -83,13 +70,55 @@ func (op *Manager) listenSignal() {
})
launchObj.ConnectClosed(func() {
op.enableAllEdge()
m.enableAllEdge()
})
}
func (op *Manager) enableAllEdge() {
op.SetTopLeft(op.TopLeftAction())
op.SetBottomLeft(op.BottomLeftAction())
op.SetTopRight(op.TopRightAction())
op.SetBottomRight(op.BottomRightAction())
func (m *Manager) enableAllEdge() {
m.SetTopLeft(m.TopLeftAction())
m.SetBottomLeft(m.BottomLeftAction())
m.SetTopRight(m.TopRightAction())
m.SetBottomRight(m.BottomRightAction())
}
func (m *Manager) filterCursorSignal(id string) bool {
if id != areaId {
return true
}
if isAppInBlackList() {
return true
}
if pid, ok := isActiveWindowFullscreen(); ok {
if !isAppInWhiteList(pid) {
return true
}
}
return false
}
func (m *Manager) handleCursorSignal(x, y int32, id string, into bool) {
if m.filterCursorSignal(id) {
return
}
if !into {
m.lTopTimer.StopTimer()
m.lBottomTimer.StopTimer()
m.rTopTimer.StopTimer()
m.rBottomTimer.StopTimer()
return
}
if isInArea(x, y, topLeftArea) {
m.lTopTimer.DoAction(leftTopEdge, leftTopDelay)
} else if isInArea(x, y, bottomLeftArea) {
m.lBottomTimer.DoAction(leftBottomEdge, leftBottomDelay)
} else if isInArea(x, y, topRightArea) {
m.rTopTimer.DoAction(rightTopEdge, rightTopDelay)
} else if isInArea(x, y, bottomRightArea) {
m.rBottomTimer.DoAction(rightBottomEdge, rightBottomDelay)
}
}