You are not logged in.

#1 2024-06-29 16:46:54

fried
Member
Registered: 2024-06-29
Posts: 10

Power button menu for when power button is pushed. SWAY/WOFI/ACPID

i hope that this would be in the right thread, but I've run into a problem. I'm currently trying to make it so that when i press the power-button a menu pops up with a few options for power/sleep/reboot
im using sway and wofi as my menu launcher. i currently was able to set up an app launcher with wofi , so i know that wofi is working properly. I download acpid in order to find the correct output/events from when my power-button is pressed. i modified the default bash script to hopefully get this working, but nothing happens. I'm not sure what the problem is, i think it has to do with the script, but i guess im posting this here in hopes maybe someone experienced something similar? when i run the handler script with the acpi output the menu does pop up but for some reason when i hit the poewr-button it doesn't execute?
I've also already changed the handlepowerbutton=ignore in systemd/logind.config.
has anyone had something similar happen to them ? if it is the script what resources can i utilize in order to make the script correct?
thank you for taking the time to read this!

Offline

#2 2024-06-29 16:55:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

And... where's this script?  If you want help with it you're going to need to let us see it.  Post it in code tags here or link to it on a file sharing site.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2024-06-29 19:42:23

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Trilby wrote:

And... where's this script?  If you want help with it you're going to need to let us see it.  Post it in code tags here or link to it on a file sharing site.

Sorry about that, here is the handler.Sh script

#!/bin/sh

case "$1" in
    button/power)
        case "$2" in
            PBTN)
                logger "Power button PBIN pressed"
                /etc/acpi/powermenu.sh
                ;;
            LNXPWRBN:00)
                logger "Power button LNXPWRBN:00 pressed"
                /etc/acpi/powermenu.sh
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
   
    adapter)
        case "$2" in
            AC|ACAD)
                case "$4" in
                    00000000)
                        logger "AC unplugged"
                        ;;
                    00000001)
                        logger "AC plugged"
                        ;;
                    *)
                        logger "ACPI action undefined: $4"
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    battery)
        case "$2" in
            BATO)
                case "$4" in
                    00000000)
                        logger "Battery online"
                        ;;
                    00000001)
                        logger "Battery offline"
                        ;;
                    *)
                        logger "ACPI action undefined: $4"
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

# vim: set ts=4 sw=4 ft=sh et:
 

And here is the powermenu.Sh file:

#!/bin/bash

# Define the options
options="Shutdown\nReboot\nSleep"

# Get the choice using Wofi
choice=$(echo -e $options | wofi --dmenu --prompt="Power Options")

# Execute the choice
case $choice in
  Shutdown)
    systemctl poweroff
    ;;
  Reboot)
    systemctl reboot
    ;;
  Sleep)
    systemctl suspend
    ;;
  *)
    ;;
esac

Offline

#4 2024-06-29 20:16:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Are you sure "nothing" happens when you hit the power button?  Add something to the very start of powermenu.sh that writes to a file to confirm the script is running, e.g.

date >> /tmp/powermenu.log

Note that I'd expect wofi to fail in this context as the acpid script doesn't run as your user or - more importantly - doesn't have the WAYLAND_DISPLAY environment variable.  You could try the hackish approach of hardcoding the environment variable to wayland-0, and on a simple single user system this may work.  Alternatively you could check for any running wayland sessions and connect to the first available to give the wofi prompt.

Last edited by Trilby (2024-06-29 20:17:05)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2024-06-29 21:20:31

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Ya I think it is related to wofi. Do you have any suggestions for some alternatives ? It seems when I run journalctl -f I’m getting segmentation faults from wofi. I have the enviorment variables included in my bash file and the menu does pop up whenever I execute it through the command line
For example: /etc/acpi/handler.sh button/power PBTN
A window will pop up. So I think ut must be the way wofi is handling the acpi events ?

Offline

#6 2024-06-29 21:44:05

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,402
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Mod note: not an installation issue, moving to Programming/Scripting.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#7 2024-06-29 23:02:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

fried wrote:

Ya I think it is related to wofi.

Do you think or do you know?  Did you run the test I suggested or not?

fried wrote:

Do you have any suggestions for some alternatives?

Well ... yeah:

Trilby wrote:

... doesn't have the WAYLAND_DISPLAY environment variable.  You could try the hackish approach of hardcoding the environment variable to wayland-0, and on a simple single user system this may work.  Alternatively you could check for any running wayland sessions and connect to the first available to give the wofi prompt.

fried wrote:

I have the enviorment variables included in my bash file

Which "bash file"?  If you mean your profile or bashrc that's a bad idea and that should be removed.  Your compositor sets and exports the WAYLAND_DISPLAY variable.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2024-06-30 22:09:51

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

mistake

Last edited by fried (2024-07-01 01:32:04)

Offline

#9 2024-06-30 22:16:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

And when you're in your wayland session where you can successfully run the script manually, what's the output of "echo $WAYLAND_DISPLAY"?

Then given that you collect all that debugging information in /tmp/acpi_debug.log, you should post the content of that log.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2024-06-30 22:29:53

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Trilby wrote:
fried wrote:

Ya I think it is related to wofi.

Do you think or do you know?  Did you run the test I suggested or not?

fried wrote:

Do you have any suggestions for some alternatives?

Well ... yeah:

Trilby wrote:

... doesn't have the WAYLAND_DISPLAY environment variable.  You could try the hackish approach of hardcoding the environment variable to wayland-0, and on a simple single user system this may work.  Alternatively you could check for any running wayland sessions and connect to the first available to give the wofi prompt.

fried wrote:

I have the enviorment variables included in my bash file

Which "bash file"?  If you mean your profile or bashrc that's a bad idea and that should be removed.  Your compositor sets and exports the WAYLAND_DISPLAY variable.

fried wrote:

I’m sorry, I didn’t run your specific test because I’ve already done something similar. I’ve written several debug statements in the powermenu.Sh script. My apologies as I was on my phone and was having trouble with logging into arch on my PC. So I had to make the best with doing an obscure way of getting you the closest thing to my script. But yes I have the variables in there for XDG_RUNTIME_DIR , WAYLAND_DISPLAY, and SWAY SOCK.
It’s interesting because hitting the power button does do “something” when I’m using ACPI_listen . It shows three different outputs:

button/power PBTN 00000080 00000000 K
button /power PBTN 00000080 00000000
button /power INXPWRBN: 00 00000080 0000000€

This is my powermenu.Sh script:

#!/bin/bash

# Debugging log
echo "powermenu.sh executed" >> /tmp/acpi_debug.log

export XDG_RUNTIME_DIR=/run/user/1000
export WAYLAND_DISPLAY=wayland-1
export SWAYSOCK=$(find /run/user/1000/ -maxdepth 1 -name 'sway-ipc.*.sock' 2>/dev/null | head -n 1)

echo "XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR" >> /tmp/acpi_debug.log
echo "WAYLAND_DISPLAY: $WAYLAND_DISPLAY" >> /tmp/acpi_debug.log
echo "SWAYSOCK: $SWAYSOCK" >> /tmp/acpi_debug.log

# Debugging to test if wofi runs or can run
/usr/bin/wofi --version >> /tmp/acpi_debug.log 2>&1

options=("Shutdown" "Reboot" "Sleep")

op=$(printf "%s\n" "${options[@]}" | sudo -u fried /usr/bin/wofi --dmenu --prompt="select power option" --normal-window)

echo "Selected option: '$op'" >> /tmp/acpi_debug.log
case $op in
    Shutdown)
        systemctl poweroff
        ;;
    Reboot)
        systemctl reboot
        ;;
    Sleep)
        systemctl suspend
        ;;
    *)
        echo "Invalid option selected" >> /tmp/acpi_debug.log
        ;;
esac

My handler.Sh script:

#!/bin/bash
echo "Parameters: $@" >> /tmp/acpi_debug.log
logger "parameters: $@"
case "$1" in
    button/power)
        case "$2" in
            PBTN|LNXPWRBN:00)
                logger "power button LNXPWRBN:00/PBTN pressed"
                sudo -E /etc/acpi/powermenu.sh
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC|ACAD|ADP0)
                case "$4" in
                    00000000)
                        logger 'AC unplugged'
                        ;;
                    00000001)
                        logger 'AC plugged'
                        ;;
                esac
                ;;
        *)
            logger "ACPI action undefined: $2"
            ;;
        esac
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

My debug statements basically shows that it’s making it to the powermenu.Sh file but something weird happens there where when I check my acpi_debug.log it shows this:

 
Parameters: button/power LNXPWRBN:00 00000080 0000006b
powermenu.sh executed
XDG_RUNTIME_DIR: /run/user/1000
WAYLAND_DISPLAY: /run/user/1000/wayland-1
SWAYSOCK: /run/user/1000/sway-ipc.1000.509.sock
3f4a8c8c18d1 tip
Selected option: ' '
Invalid option selected

It shows that my variables are correct but it’s saying invalid option selected? So im confused because it seems that my script is being executed, even if I just manually execute

/etc/acpi/powermenu.sh

The powermenu does pop up. But when I hit the power button nothing happens.

Also when I use

journalctl -f

It says wofi gets a segmentation fault
So I’m just confused.
Also I apologize if I’m not using the right terminology for something’s, I’m still fairly new to Linux.
Hope this helps the understanding of what I’m trying to deal with
Thank you!

Offline

#11 2024-06-30 22:32:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

edit: I assume you meant to edit, not massively quote.  Please fix that and also answer my other question.

edit 2: and please check that what you are posting is actually accurate this time: there's no way that log output is from the script you posted.

Last edited by Trilby (2024-06-30 22:39:56)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#12 2024-06-30 23:16:52

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

mistake

Last edited by fried (2024-07-01 01:31:33)

Offline

#13 2024-06-30 23:35:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

You see that as condescending?  I gave you the benefit of the doubt that it was a mistake.  But you've now refused to provide requested information several times, provided false and misleading information multiple times, and now refuse to fix your dumpster fire post that makes the thread nearly unreadable.  Yeah, I think you will need to figure it out on your own - this is not a way to get help from others.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#14 2024-06-30 23:53:03

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

I honestly only saw your comment about the edit and didn’t see that you actually left a good reply so I apologize about that. That’s what I was referring to as being condescending, but clearly that was my bad not reading it in the right context. Also I gave you what I have as far as information I’m capable of giving you at the moment, which was me going through notes of logs on my iPhone so they weren’t the best.
I don’t know how to delete posts on here yet because I just made an account. Sorry I couldn’t explain myself better.

Offline

#15 2024-07-01 00:28:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Okay, one more try: you can click "edit" on your post to fix it.  On top of that you need to gather the appropriate information.  Summarizing logs on your iPhone is harmful to the goal here - we need actual / exact information.

Specifically, we need to know the WAYLAND_DISPLAY value from within your wayland session.  My suspicion from the start was that this would be "wayland-0" yet your script hardcodes "wayland-1".  If this is incorrect, that would explain *all* the problems you are facing.

As for the log, your log sets WAYLAND_DISPLAY=wayland-1, but a couple lines later records WAYLAND_DISPLAY allegedly as /run/user/1000/wayland-1 which is not possible: that is a wayland socket not a WAYLAND_DISPLAY value.  I don't know if this disconnect is from the script not being what you posted as your script, or your log not being what you posted as your log.  So we need the *actual* script and log, not your iPhone interpretation of them.  Take time to gather the correct information and then post it.

Last edited by Trilby (2024-07-01 00:29:49)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#16 2024-07-01 01:51:57

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

ok well here is everything that i have right now
starting with output from

 acpi_listen 

when the powerbutton is pushed:

button/power PBTN 00000080 00000000 K
button/power PBTN 00000080 00000000
button/power LNXPWRBN:00 00000080 00000014

when i use

 echo $WAYLAND_DISPLAY 

the output is:

  wayland-1 

and then the other environment variables :
$SWAYSOCK:

 echo $SWAYSOCK 

output:

 /run/user/1000/sway-ipc.1000.516.sock 

$XDG_RUNTIME_DIR:

 echo $XDG_RUNTIME_DIR 

output:

 /run/user/1000 

here is my powermenu.sh script:

#!/bin/bash


# debugging log

echo "powermenu.sh executed" >> /tmp/acpi_debug.log

export XDG_RUNTIME_DIR=/run/user/1000
export WAYLAND_DISPLAY=/run/user/1000/wayland-1
export SWAYSOCK=$(find /run/user/1000/ -maxdepth 1 -name 'sway-ipc.*.sock' 2>/dev/null | head -n 1)


echo "XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR" >> /tmp/acpi_debug.log
echo "WAYLAND_DISPLAY: $WAYLAND_DISPLAY" >> /tmp/acpi_debug.log
echo "SWAYSOCK: $SWAYSOCK" >> /tmp/acpi_debug.log

# debugging to test if wofi runs or can run
wofi --version >> tmp/acpi_debug.log 2>&1

options=("Shutdown" "Reboot" "Sleep")

op=$(printf "%s\n" "${options[@]}" |/usr/local/bin/wofi --dmenu --prompt="select power option" --normal-window)


echo "Selected option: '$op'" >> /tmp/acpi_debug.log
  case "$op" in
	   Shutdown)
	      systemctl poweroff
	   ;;
	   Reboot)
              systemctl reboot
	   ;;
	   Suspend)
	          systemctl suspend
	  ;;
	    *)
		  echo "Invalid option selected" >> /tmp/acpi_debug.log
	  ;;

  esac

and here is my handler.sh script that is supposed to deal with the ACPI events:

#!/bin/bash
# Default acpi script that takes an entry for all actions

export XDG_RUNTIME_DIR=/run/user/1000
export WAYLAND_DISPLAY=/run/user/1000/wayland-1
export SWAYSOCK=$(find /run/user/1000/ -maxdepth 1 -name 'sway-ipc.*.sock' 2>/dev/null | head -n 1)

echo "Parameters: $@" >> /tmp/acpi_debug.log
logger "parameters: $@"
case "$1" in
    button/power)
        case "$2" in
		PBTN|LNXPWRBN:00)
			logger "power button LNXPWRBN:00/PBTN pressed"
			sudo  -E -u fried /etc/acpi/powermenu.sh
			;;

            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC|ACAD|ADP0)
                case "$4" in
                    00000000)
                        logger 'AC unpluged'
                        ;;
                    00000001)
                        logger 'AC pluged'
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000000)
                        logger 'Battery online'
                        ;;
                    00000001)
                        logger 'Battery offline'
                        ;;
                esac
                ;;
            CPU0)
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        case "$3" in
            close)
                logger 'LID closed'
                ;;
            open)
                logger 'LID opened'
                ;;
            *)
                logger "ACPI action undefined: $3"
                ;;
    esac
    ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

# vim:set ts=4 sw=4 ft=sh et:

here is my output from my acpi_debug.log:

Parameters:
powermenu.sh executed
XDG_RUNTIME_DIR: /run/user/1000
WAYLAND_DISPLAY: /run/user/1000/wayland-1
SWAYSOCK: /run/user/1000/sway-ipc.1000.516.sock
3f4a8c8c18d1 tip
Selected option: ''
Invalid option selected

here is my output when i use

 journalctl -f 

:

Jun 30 18:36:59 Fried kernel: wofi[8926]: segfault at 0 ip 0000766a758838ba sp 00007fff256ae9e8 error 4 in libc.so.6[766a757f2000+16c000] likely on CPU 0 (core 0, socket 0)
Jun 30 18:36:59 Fried kernel: Code: f3 0f 1e fa 66 0f ef c0 66 0f ef c9 66 0f ef d2 66 0f ef db 48 89 f8 48 89 f9 48 81 e1 ff 0f 00 00 48 81 f9 cf 0f 00 00 77 66 <f3> 0f 6f 20 66 0f 74 e0 66 0f d7 d4 85 d2 74 04 0f bc c2 c3 48 83
Jun 30 18:36:59 Fried systemd-coredump[8928]: Process 8926 (wofi) of user 0 terminated abnormally with signal 11/SEGV, processing...
Jun 30 18:36:59 Fried systemd[1]: Started Process Core Dump (PID 8928/UID 0).
Jun 30 18:36:59 Fried systemd-coredump[8929]: [?] Process 8926 (wofi) of user 0 dumped core.

                                              Stack trace of thread 8926:
                                              #0  0x0000766a758838ba n/a (libc.so.6 + 0xb58ba)
                                              #1  0x000063954b8e4dcd utils_concat (wofi + 0xbdcd)
                                              #2  0x000063954b8e2b20 main (wofi + 0x9b20)
                                              #3  0x0000766a757f3c88 n/a (libc.so.6 + 0x25c88)
                                              #4  0x0000766a757f3d4c __libc_start_main (libc.so.6 + 0x25d4c)
                                              #5  0x000063954b8e2ee5 _start (wofi + 0x9ee5)
                                              ELF object binary architecture: AMD x86-64

Last edited by fried (2024-07-01 02:06:38)

Offline

#17 2024-07-01 03:12:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

So there's the problem in your script:

export WAYLAND_DISPLAY=/run/user/1000/wayland-1

Again, that's the path to a wayland socket.  The wayland display is just the name, e.g.:

export WAYLAND_DISPLAY=wayland-1

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#18 2024-07-01 03:32:28

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

i changed it to that but its still the same problem where it will execute and a window will pop up when i run

 /etc/acpi/powermenu.sh 

but not when i hit the power button?

im not very sure why in my acpi_debug.log that it shows invalid selection, it makes me think that the powermenu.sh file is just poorly written from my end and not executing properly. there isn't much information in the documentation about it.

my event script:

anything.sh the default script

 

# Pass all events to our one handler script
event=.*
action=/etc/acpi/handler.sh

the powerbutton.sh script i attempted to make:

 
#!/bin/bash

event=button/power.*
action=/etc/acpi/powermenu.sh %e

Last edited by fried (2024-07-01 04:23:39)

Offline

#19 2024-07-01 12:09:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

Please post the new log after the change.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#20 2024-07-01 18:36:00

fried
Member
Registered: 2024-06-29
Posts: 10

Re: Power button menu for when power button is pushed. SWAY/WOFI/ACPID

No worries friend, I ended up figuring it out. It was a permissions issue essentially. I appreciate your help though!

Offline

Board footer

Powered by FluxBB