WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: acpid scripts for laptop Fn+F2/3/6/7/8 functions  (Read 13513 times)

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #30 on: May 21, 2020, 03:35:22 PM »
My touch-pad is very good (i think). but i do no know how to PASTE with only my synaptic, so I add an external mouse (2 buttons + 1 wheel).

What I discovered now is that clipboard buffer of aterm is NOT shared with others like fltk editor.In aterm shft+del is useless: just selecting with the touch-pad is enough (it auto copy the section).the shft+ins = PASTE in aterm.
Using the external mouse: double click will select (AND copy the selection), Wheel click (middle button) will paste it ANYWHERE (aterm, editor, firefox). This is why is need a mouse.

Disconnecting touch-pad could be with Xinput, like Juanito said previously. I do not think Xorg should be stop & start. I did not tried because I prefer to use/keep the touchpad.
« Last Edit: May 21, 2020, 03:51:50 PM by nick65go »

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #31 on: May 21, 2020, 03:59:01 PM »
Yes You're right again, Shift-Del is useless, both in aterm and in rxvt. Releasing mouse button is copying selected text.

Even more questions with fifth.
1. We can copy in terminal and paste into fifth.
2. We can copy in fifth and paste into terminal.
3. We can copy in Editor and paste into fifth
4. We CAN NOT copy in fifth and paste into Editor.

My guess, Curaga knows something intereting about this clipboards.


Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #32 on: May 21, 2020, 04:00:26 PM »
Thank You for advice about Xinput, but I am not able to use it under Xfbdev.
So seems that Shift-Ins works everywhere as Paste, and can replace middle mouse click.
« Last Edit: May 21, 2020, 04:10:26 PM by jazzbiker »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #33 on: May 21, 2020, 04:28:49 PM »
@jazzbiker: Sorry to dissapoint you.
I love software on 32 bits. Smaller means less surface for attack versus bloat, so more secure etc.
But my laptop has UEFI_64 (not my choose, it came with win10) and 8 GB RAM, so I am tempted by software on 64 bits.
(yes, I get older and stupid, aka more lazy). Yes, I know, the gain in speed is minor (if ever) for my home work.

So no more (for the time beeing) Xvesa, Xfvdev, only in virtual machines. But I am tempted by firejail also.
All is about pristine/virgin trusted environment. No bloat/spy/useless-features. No unsolicited-updates.
I think I could live with just Firefox, vlc, libre-office, 7zip, in an emergency.
« Last Edit: May 21, 2020, 04:32:10 PM by nick65go »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #34 on: May 22, 2020, 03:24:21 AM »
X has this weirdness that it has two clipboards, unlike Win and Mac. One for mouse selection and one for app's ctrl-c/other use. But apps use them however they wish.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #35 on: May 23, 2020, 12:40:55 PM »

Or you could just launch a script in the background that sleeps 99.9999% of the time and occasionally reads the remaining
battery capacity directly:
Code: [Select]
#!/bin/sh
# Short script to monitor remaining percent of battery power.
# Check  /sys/class/power_supply  to find how your battery is named.
#
#  Usage:
#      BatteryMonitor.sh BatteryName &
#
#  Example:
#      BatteryMonitor.sh BAT0 &

[ -z "$1" ] && exit

# The percentage that triggers a warning.
WarningLevel=5
# Number of minutes to sleep before checking capacity again.
SleepMinutes=5

PowerPath="/sys/class/power_supply"
BatteryName="$1"
Capacity="$PowerPath/$BatteryName/capacity"
SleepTime="60 * $SleepMinutes"

while true
do
   sleep "$SleepTime"
   RemainingCapacity="`cat $Capacity`"
   [ "$RemainingCapacity" -gt "$WarningLevel" ] && continue
   popup "Remaining battery capacity is $RemainingCapacity%%"
done
I think SleepTime="60 * $SleepMinutes" is not working, because " ", and multiplication not allowed, only sum/diff
Code: [Select]
sleep: invalid number '60 * 5'
Code: [Select]
tc@box:~$ echo `expr 60 + 5`
65
tc@box:~$ echo `expr 60 * 5`
expr: syntax error

tc@box:~$ calc 60 + 5
65
tc@box:~$ calc 60 *  5
awk: cmd. line:1: Unexpected token
tc@box:~$ calc 60*5
300
so, it should be
Code: [Select]
SleepTime=`calc 60*$SleepMinutes`
« Last Edit: May 23, 2020, 12:47:35 PM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11624
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #36 on: May 23, 2020, 12:58:51 PM »
Hi nick65go
You caught me. I didn't test that part of the script. I set  SleepTime  directly equal to 5 because I wasn't going to wait 5 minutes.
However, you can do multiplication without using  calc.  I know, because I've seen roberts use it in the  tc-config  script. I just
checked his script and the correct syntax is:
Code: [Select]
SleepTime=$((60 * $SleepMinutes))
This shows up in the  waitusb  section of  tc-config.  He also uses the same syntax for division.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #37 on: May 23, 2020, 01:15:06 PM »
Thank you. Good catch. I tested , it works :)
« Last Edit: May 23, 2020, 01:17:20 PM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11624
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #38 on: May 23, 2020, 02:07:18 PM »
Hi nick65go
The text and the attachment in reply #22 have been corrected. Thank you for bringing this issue to my attention. :)

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #39 on: May 23, 2020, 06:19:36 PM »
This is just a remainder to myself. It is a good practice to first kill a daemon then start it again, if the daemon is in /home/tc/.X.d/*. Otherwise if I get out of Xorg (with Ctrl+Alt+Backspace), and then start it again (with starrtx), few pairs of zombie daemons processes can be seen with top.The BatteryMonitor.sh should be sent in the background (with &) otherwise nothing will run after it (it is a infinite loop).
my /home/tc/.X.d/myacpi.sh
Code: [Select]
#!/bin/sh
# lower brightness, from default 255 to 32
echo 32 | sudo tee /sys/class/backlight/radeon_bl0/brightness &

#start acpid daemon for F2/3(brightness), F6/7/8(sound), and LID
sudo kill `pidof acpid`
echo 1
sudo /usr/local/sbin/acpid
echo 2

echo powersupersave | sudo tee /sys/module/pcie_aspm/parameters/policy
echo 3

#stop wire-network if we use wifi
[ -e /var/run/udhcpc.eth0.pid ] && sudo kill `cat /var/run/udhcpc.eth0.pid`
echo 4

#stop orfans daemons (/sbin/udevd --daemon) for firmware
sudo kill `pidof udevd`
echo 5

#start crond daemon for battery low 2%
#sudo kill `pidof crond`
#sudo /usr/local/sbin/crond &

sudo kill `pidof BatteryMonitor.sh` `pidof sleep`
/home/tc/.acpi/BatteryMonitor.sh BAT0 &
echo 6

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11624
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #40 on: May 26, 2020, 01:47:38 AM »
Hi nick65go
Attached is a modified version of the script. It now also shows percent of charge remaining in a little display in the lower right
corner of the screen. The display gets updated every 5 minutes. The text is normally white. When remaining charge drops
to 20%, it turns yellow. When it drops to 10%, it turns red. When it drops to 5%, you get a popup just like before. There are
variables for setting the percentages at which the colors change. You can also change the XY coordinates of the display as
well as the font.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #41 on: May 27, 2020, 06:08:54 PM »
Hi Rich, Thank you!
Remarks regarding my acpid daemon, the default path for configuration events are:
in TC11_x64, /etc/acpi/events,
but in TC11_x86 they are in /usr/local/etc/acpi/events:
Code: [Select]
tc@box:~$ uname -a
Linux box 5.4.3-tinycore #2020 SMP Tue Dec 17 17:00:50 UTC 2019 i686 GNU/Linux

tc@box:~$ sudo acpid -d
Deprecated /proc/acpi/event was not found.  Trying netlink and the input layer...input layer /dev/input/event0 opened successfully
input layer /dev/input/event1 opened successfully
input layer /dev/input/event2 opened successfully
input layer /dev/input/event3 opened successfully
input layer /dev/input/event6 opened successfully
input layer /dev/input/event7 opened successfully
inotify fd: 9
inotify wd: 1
netlink opened successfully
acpid: starting up with netlink and the input layer
parsing conf file /usr/local/etc/acpi/events/all
acpid: 1 rule loaded
acpid: waiting for events: event logging is off
^Cacpid: exiting
tc@box:~$

so, the command should be sudo acpid -c your/path/to/acpi/events/folder
« Last Edit: May 27, 2020, 06:12:23 PM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #42 on: May 27, 2020, 06:50:10 PM »
@Rich: BatteryMonitorDisplay.sh works nice.
But using "top" is see 4 processes: aterm -geometry..; sh -..; cat /dev/..; slepp ..; and {BatteryMonitorD}..;
I propose to add few instructions to "sudo kill" two of them, so it will remain only sleep and aterm -geometry. Is it OK?
Code: [Select]
tc@box:~$ BatteryMonitorDisplay.sh BAT0 &
tc@box:~$

Code: [Select]
tc@box:~$ top
.. 7927  7926 tc       S     3716  0.1   2  0.0 aterm -geometry 4x1+1860+1060 -fn 10x20 -bl -si -sb -sk -sl 0 -fade 100 -e sh -c MyTTY=`tty`; while true; do cat
 7533  7532 tc       S     3320  0.1   2  0.0 sh
 7884  7883 tc       S     3320  0.1   1  0.0 sh
 2958     1 tc       S     3316  0.1   3  0.0 -sh
    1     0 root     S     3248  0.1   0  0.0 /sbin/init
 7926  7884 tc       S     3248  0.1   0  0.0 {BatteryMonitorD} /bin/sh /home/tc/.local/bin/BatteryMonitorDisplay.sh BAT0
 7934  7927 tc       S     3248  0.1   1  0.0 sh -c MyTTY=`tty`; while true; do cat $MyTTY; done
 7936  7934 tc       S     3112  0.1   0  0.0 cat /dev/pts/2
 7953  7926 tc       S     3112  0.1   2  0.0 sleep 300
 7705     1 root     S     1792  0.0   2  0.0 /usr/local/sbin/acpid
 6849     2 root     SW<      0  0.0   1  0.0 [loop108]
« Last Edit: May 27, 2020, 06:51:49 PM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11624
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #43 on: May 27, 2020, 11:40:56 PM »
Hi nick65go
... I propose to add few instructions to "sudo kill" two of them, so it will remain only sleep and aterm -geometry. Is it OK? ...
I'm not sure what you want to kill, but I think you'll break it if you try.

Take a look at what's really happening and see if you still think you can kill something.

When you open a terminal, here is what you get:
Code: [Select]
tc@ASUS:~$ pstree -p 12953
aterm(12953)---sh(12954)
tc@ASUS:~$
A terminal and a shell.

Now I launch  BatteryMonitorDisplay.sh  from that terminal into the background:
Code: [Select]
tc@ASUS:~$ BatteryMonitorDisplay.sh BATC &
tc@ASUS:~$ pstree -p 12953
aterm(12953)---sh(12954)---BatteryMonitorD(12973)-+-aterm(12974)---sh(12981)---cat(12983)
                                                  `-sleep(13015)
tc@ASUS:~$
BatteryMonitorDisplay.sh  launches a terminal in the background that runs  cat  on its  tty.
BatteryMonitorDisplay.sh  sends the value of  $RemainingCapacity  to the terminals  tty.
BatteryMonitorDisplay.sh  executes a 5 minute sleep command. The script will do nothing for 5 minutes.
As long as nothing is being sent to the terminals  tty , it will block  cat  from executing. The  cat  command sleeps until data is available.
When sleep times out and exits,  BatteryMonitorDisplay.sh  is allowed to run.
BatteryMonitorDisplay.sh  sends the value of  $RemainingCapacity  to the terminals  tty.
Then sleep 5 minutes, send $RemainingCapacity, sleep 5 minutes, send $RemainingCapacity ........

Now I close the original terminal that I started with and we are left with this:
Code: [Select]
tc@ASUS:~$ pstree -p 12973
BatteryMonitorD(12973)-+-aterm(12974)---sh(12981)---cat(12983)
                       `-sleep(13015)
tc@ASUS:~$
With the original terminal gone,  BatteryMonitorDisplay.sh  now belongs to  init , also known as PID #1.