Skip to content

Commit 3220047

Browse files
author
nzlov
committed
add touching check
1 parent bd6d4d2 commit 3220047

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

main.go

+25-16
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ import (
1717
)
1818

1919
var (
20-
TOUCHING = int64(0)
21-
FPS = "60"
22-
SLOCK *sync.Mutex
23-
FLOCK *sync.Mutex
24-
M map[string]PF
25-
CFGTIME = int64(0)
26-
ACTIVITY = "*"
27-
CPF PF
28-
w *W
29-
c *exec.Cmd
30-
t *time.Ticker
31-
Running bool
20+
TOUCHTIME = int64(0)
21+
TOUCHING = false
22+
FPS = "60"
23+
SLOCK *sync.Mutex
24+
FLOCK *sync.Mutex
25+
M map[string]PF
26+
CFGTIME = int64(0)
27+
ACTIVITY = "*"
28+
CPF PF
29+
w *W
30+
c *exec.Cmd
31+
t *time.Ticker
32+
Running bool
3233
)
3334

3435
const (
@@ -233,8 +234,9 @@ func start() {
233234
go func() {
234235
for n := range t.C {
235236
changeActivity(getActivity())
236-
if n.Unix()-TOUCHING > 1 {
237+
if n.Unix()-TOUCHTIME > 1 {
237238
upfps(CPF.idle)
239+
TOUCHING = false
238240
}
239241
}
240242
}()
@@ -272,8 +274,11 @@ type W struct {
272274
}
273275

274276
func (w *W) Write(p []byte) (n int, err error) {
275-
TOUCHING = time.Now().Unix()
276-
log(string(p))
277+
TOUCHTIME = time.Now().Unix()
278+
if TOUCHING {
279+
log("tend")
280+
return len(p), nil
281+
}
277282
upfps(CPF.touching)
278283
return len(p), nil
279284
}
@@ -284,8 +289,9 @@ func upfps(i string) {
284289
if FPS == i {
285290
return
286291
}
287-
log("upfps:", i)
288292
FPS = i
293+
TOUCHING = true
294+
log("upfps:", i)
289295
exec.Command("settings", "put", "system", "min_refresh_rate", FPS).Output()
290296
}
291297

@@ -296,6 +302,9 @@ func changeActivity(a string) {
296302
log("changeActivity:", a)
297303
ACTIVITY = a
298304
CPF = getPF(a)
305+
if TOUCHING {
306+
upfps(CPF.touching)
307+
}
299308
}
300309

301310
func getPF(n string) PF {

0 commit comments

Comments
 (0)