DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 1st December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default Script to toggle wsconsctl touchpad

The new touchpad configuration tools make it difficult for a user to disable to touchpad. The soon to be phased out synclient(1) tools made it easy for a user to disable the touchpad while the new wsconsctl commands need to be run as root.

My HP Stream 14 ergonomics would benefit from an easy way to disable the touchpad and fortunately, the F5 key is not dedicated to a special function.

The following enables me to toggle the touchpad on/off with F5.

1. /etc/doas.conf entry
Code:
permit nopass :wheel as root cmd /sbin/wsconsctl mouse.tp.disable
2. Keybind F5 to run this script:
Code:
#!/bin/sh
# Determine touchpad state
TP_STATE=`doas wsconsctl 2>/dev/null | grep mouse.tp.disable | cut -d "=" -f 2`
if [[ $TP_STATE -eq 0 ]] ; then
  `doas wsconsctl mouse.tp.disable=1 1>/dev/null`
else
  `doas wsconsctl mouse.tp.disable=0 1>/dev/null`
fi
Any scripts tweak comments appreciated.

Last edited by shep; 4th December 2022 at 05:57 PM.
Reply With Quote
  #2   (View Single Post)  
Old 1st December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

The script has a /bin/sh shebang but the [[ test construct is undefined in POSIX.

I would use $(...) instead of backticks and also awk instead of grep & cut so:
Code:
#!/bin/sh

tp_state=$(doas wsconsctl 2>/dev/null | awk -F'=' '/mouse.tp.disable/{print $2}')

if [ "$tp_state" -eq 0 ] ; then
   doas wsconsctl mouse.tp.disable=1 1>/dev/null
else
   doas wsconsctl mouse.tp.disable=0 1>/dev/null
fi
Not sure why you've used backticks around the then & else commands but perhaps I've missed something there.

Last edited by Head_on_a_Stick; 1st December 2022 at 05:55 PM.
Reply With Quote
  #3   (View Single Post)  
Old 1st December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default

I was hoping for a more elegant implementation of tp_state. When developing the script, I ran each command individually to step through it. The stderr outputs were more warnings than frank errors but still had to filtered out. Cutting down the pipes with awk is more elegant - I need to learn more about awk/sed and posix compliance.

Thanks
Reply With Quote
  #4   (View Single Post)  
Old 1st December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

I don't have an OpenBSD system handy to test but I think you could omit the search in awk by specifying the wsconsctl variable:
Code:
tp_state=$(doas wsconsctl mouse.tp.disable 2>/dev/null | awk -F'=' '{print $2}')
But I can't think of a better way to grab the current touchpad state.
Reply With Quote
  #5   (View Single Post)  
Old 1st December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default

Tested your changes on OpenBSD current. Worked fine.

I'm have a similar script that uses yad --scale (zenity --scale, xdialog --gauge) to adjust sndio audio volume. The awk stanza also worked in that script. That script also uses back tic's which I'll clean up and post later.

Thanks
Reply With Quote
  #6   (View Single Post)  
Old 4th December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default

My /etc/doas.conf needed full cmd paths in the script.

Code:
#!/bin/sh
# Determine Touchpad state
tp_state=$(doas /sbin/wsconsctl 2>/dev/null | awk -F'=' '/mouse.tp.disable/{print $2}')
# Flip Touchpad state
if [ "$tp_state" -eq 0 ] ; then
   doas /sbin/wsconsctl mouse.tp.disable=1 1>/dev/null
else
   doas /sbin/wsconsctl mouse.tp.disable=0 1>/dev/null
fi

Last edited by shep; 4th December 2022 at 10:48 PM. Reason: See next post :Thnx @Head_on_a_Stick
Reply With Quote
  #7   (View Single Post)  
Old 4th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

You've used the if [ "$tp_state" -eq 0 ] ; then line from my example but kept the TP_STATE variable name in the # Determine Touchpad state section.

Sorry, that's my fault. I prefer to use lower case with custom variable names to avoid confusion or conflict with system variables, which are usually upper case.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
wsconsctl.conf variables LeFrettchen OpenBSD General 11 5th January 2020 09:05 AM
wsconsctl elusive keycodes radix OpenBSD General 15 8th March 2015 08:17 PM
HP kills TouchPad ocicat News 10 21st March 2012 05:31 PM
How to disable touchpad gpatrick OpenBSD General 3 4th March 2012 03:36 PM
Cannot get touchpad to scroll! cgc2 FreeBSD General 5 16th August 2008 05:53 PM


All times are GMT. The time now is 10:48 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick