1- // SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+ // SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22//
33// SPDX-License-Identifier: GPL-3.0-or-later
44
@@ -88,14 +88,13 @@ func (w *Wacom) QueryType() int {
8888// Set the tablet input area in device coordinates in the form top
8989// left x/y and bottom right x/y.
9090func (w * Wacom ) SetArea (x1 , y1 , x2 , y2 int ) error {
91- var cmd = fmt . Sprintf ( "%s set %v %s %v %v %v %v " , cmdXSetWacom , w . Id ,
92- cmdKeyArea , x1 , y1 , x2 , y2 )
93- return doAction ( cmd )
91+ return doAction ( " set" , w . getIdAsStr (), cmdKeyArea ,
92+ strconv . Itoa ( x1 ), strconv . Itoa ( y1 ),
93+ strconv . Itoa ( x2 ), strconv . Itoa ( y2 ) )
9494}
9595
9696func (w * Wacom ) ResetArea () error {
97- var cmd = fmt .Sprintf ("%s set %v %s" , cmdXSetWacom , w .Id , cmdKeyResetArea )
98- return doAction (cmd )
97+ return doAction ("set" , w .getIdAsStr (), cmdKeyResetArea )
9998}
10099
101100func (w * Wacom ) getIdAsStr () string {
@@ -130,9 +129,7 @@ func (w *Wacom) SetRotate(value string) error {
130129 return fmt .Errorf ("Invalid value: %s" , value )
131130 }
132131
133- var cmd = fmt .Sprintf ("%s set %v %s %v" , cmdXSetWacom , w .Id ,
134- cmdKeyRotate , value )
135- return doAction (cmd )
132+ return doAction ("set" , w .getIdAsStr (), cmdKeyRotate , value )
136133}
137134
138135// Button button-number [mapping]
@@ -148,9 +145,8 @@ func (w *Wacom) SetRotate(value string) error {
148145// series of keystrokes, in this example "press a, press shift,
149146// press and release b, release shift, release a".
150147func (w * Wacom ) SetButton (btn int , value string ) error {
151- var cmd = fmt .Sprintf ("%s set %v %s %v %s" , cmdXSetWacom , w .Id ,
152- cmdKeyButton , btn , value )
153- return doAction (cmd )
148+ return doAction ("set" , w .getIdAsStr (), cmdKeyButton ,
149+ strconv .Itoa (btn ), value )
154150}
155151
156152// Mode Absolute|Relative
@@ -166,9 +162,7 @@ func (w *Wacom) SetMode(mode string) error {
166162 default :
167163 return fmt .Errorf ("Invalid value: %s" , mode )
168164 }
169- var cmd = fmt .Sprintf ("%s set %v %s %s" , cmdXSetWacom , w .Id ,
170- cmdKeyMode , mode )
171- return doAction (cmd )
165+ return doAction ("set" , w .getIdAsStr (), cmdKeyMode , mode )
172166}
173167
174168// PressureCurve x1 y1 x2 y2
@@ -187,9 +181,9 @@ func (w *Wacom) SetPressureCurve(x1, y1, x2, y2 int) error {
187181 return fmt .Errorf ("Invalid value: %v %v %v %v" , x1 , y1 , x2 , y2 )
188182 }
189183
190- var cmd = fmt . Sprintf ( "%s set %v %s %v %v %v %v " , cmdXSetWacom , w . Id ,
191- cmdKeyPressureCurve , x1 , y1 , x2 , y2 )
192- return doAction ( cmd )
184+ return doAction ( " set" , w . getIdAsStr (), cmdKeyPressureCurve ,
185+ strconv . Itoa ( x1 ), strconv . Itoa ( y1 ),
186+ strconv . Itoa ( x2 ), strconv . Itoa ( y2 ) )
193187}
194188
195189// Suppress level
@@ -202,9 +196,8 @@ func (w *Wacom) SetSuppress(value int) error {
202196 return fmt .Errorf ("Invalid value: %v" , value )
203197 }
204198
205- var cmd = fmt .Sprintf ("%s set %v %s %v" , cmdXSetWacom , w .Id ,
206- cmdKeySuppress , value )
207- return doAction (cmd )
199+ return doAction ("set" , w .getIdAsStr (), cmdKeySuppress ,
200+ strconv .Itoa (value ))
208201}
209202
210203// Threshold level
@@ -219,9 +212,8 @@ func (w *Wacom) SetThreshold(thres int) error {
219212 return fmt .Errorf ("Invalid value: %v" , thres )
220213 }
221214
222- var cmd = fmt .Sprintf ("%s set %v %s %v" , cmdXSetWacom , w .Id ,
223- cmdKeyThreshold , thres )
224- return doAction (cmd )
215+ return doAction ("set" , w .getIdAsStr (), cmdKeyThreshold ,
216+ strconv .Itoa (thres ))
225217}
226218
227219// The the window size for incoming input tool raw data points
@@ -231,9 +223,8 @@ func (w *Wacom) SetRawSample(sample uint32) error {
231223 return fmt .Errorf ("Invalid raw sample: %v" , sample )
232224 }
233225
234- var cmd = fmt .Sprintf ("%s set %v %s %v" , cmdXSetWacom , w .Id ,
235- cmdKeyRawSample , sample )
236- return doAction (cmd )
226+ return doAction ("set" , w .getIdAsStr (), cmdKeyRawSample ,
227+ strconv .FormatUint (uint64 (sample ), 10 ))
237228}
238229
239230// Mapping PC screen to tablet, such as "VGA1"
@@ -242,14 +233,11 @@ func (w *Wacom) MapToOutput(output string) error {
242233 return nil
243234 }
244235
245- var cmd = fmt .Sprintf ("%s set %v %s %s" , cmdXSetWacom , w .Id ,
246- cmdKeyMapToOutput , output )
247- return doAction (cmd )
236+ return doAction ("set" , w .getIdAsStr (), cmdKeyMapToOutput , output )
248237}
249238
250- func doAction (cmd string ) error {
251- // #nosec G204
252- out , err := exec .Command ("/bin/sh" , "-c" , cmd ).CombinedOutput ()
239+ func doAction (args ... string ) error {
240+ out , err := exec .Command (cmdXSetWacom , args ... ).CombinedOutput ()
253241 if err != nil {
254242 return errors .New (string (out ))
255243 }
0 commit comments