File: dpms.go

package info (click to toggle)
golang-github-linuxdeepin-go-x11-client 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,784 kB
  • sloc: python: 944; sh: 38; makefile: 17
file content (131 lines) | stat: -rw-r--r-- 2,213 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

package dpms

import "github.com/linuxdeepin/go-x11-client"

// #WREQ
func encodeGetVersion(clientMajorVersion, clientMinorVersion uint16) (b x.RequestBody) {
	b.AddBlock(1).
		Write2b(clientMajorVersion).
		Write2b(clientMinorVersion).
		End()
	return
}

type GetVersionReply struct {
	ServerMajorVersion uint16
	ServerMinorVersion uint16
}

func readGetVersionReply(r *x.Reader, v *GetVersionReply) error {
	if !r.RemainAtLeast4b(3) {
		return x.ErrDataLenShort
	}
	r.ReadPad(8)

	v.ServerMajorVersion = r.Read2b()
	v.ServerMinorVersion = r.Read2b() // 3

	return nil
}

// #WREQ
func encodeCapable() (b x.RequestBody) {
	return
}

type CapableReply struct {
	Capable bool
}

func readCapableReply(r *x.Reader, v *CapableReply) error {
	if !r.RemainAtLeast4b(3) {
		return x.ErrDataLenShort
	}

	r.ReadPad(8)

	v.Capable = r.ReadBool() // 3

	return nil
}

// #WREQ
func encodeGetTimeouts() (b x.RequestBody) {
	return
}

type GetTimeoutsReply struct {
	StandbyTimeout uint16
	SuspendTimeout uint16
	OffTimeout     uint16
}

func readGetTimeoutsReply(r *x.Reader, v *GetTimeoutsReply) error {
	if !r.RemainAtLeast4b(4) {
		return x.ErrDataLenShort
	}
	r.ReadPad(8)

	v.StandbyTimeout = r.Read2b()
	v.SuspendTimeout = r.Read2b()

	v.OffTimeout = r.Read2b() // 4

	return nil
}

// #WREQ
func encodeSetTimeouts(standbyTimeout, suspendTimeout, offTimeout uint16) (b x.RequestBody) {
	b.AddBlock(2).
		Write2b(standbyTimeout).
		Write2b(suspendTimeout).
		Write2b(offTimeout).
		WritePad(2).
		End()
	return
}

// #WREQ
func encodeEnable() (b x.RequestBody) {
	return
}

// #WREQ
func encodeDisable() (b x.RequestBody) {
	return
}

// #WREQ
func encodeForceLevel(powerLevel uint16) (b x.RequestBody) {
	b.AddBlock(1).
		Write2b(powerLevel).
		WritePad(2).
		End()
	return
}

// #WREQ
func encodeInfo() (b x.RequestBody) {
	return
}

type InfoReply struct {
	PowerLevel uint16
	State      bool
}

func readInfoReply(r *x.Reader, v *InfoReply) error {
	if !r.RemainAtLeast4b(3) {
		return x.ErrDataLenShort
	}
	r.ReadPad(8)

	v.PowerLevel = r.Read2b()
	v.State = r.ReadBool() // 3

	return nil
}