You are not logged in.

#21 2019-02-24 04:34:17

Döbbie03
Resident Metalhead
From: New Zealand
Registered: 2015-09-29
Posts: 3,854

Re: bl-exit replacement suggestions

hhh wrote:
Dobbie03 wrote:

I just use San Francisco Display for my Rofi.

https://github.com/AppleDesignResources … nciscoFont

Yep, I prefer the Display over the Text.


"All we are is dust in the wind, dude"
                                       - Theodore "Ted" Logan
"Led Zeppelin didn't write tunes that everybody liked, they left that to the Bee Gees."
                                       - Wayne Campbell

Offline

#22 2019-02-24 08:38:32

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,553
Website

Re: bl-exit replacement suggestions

BunsenLabs default menu.xml already contains this

    <menu id="exit-menu" label="Exit">
        <item label="Log out">
            <action name="Execute">
                <command>
                    bl-exit --logout
                </command>
            </action>
        </item>
        <item label="Suspend">
            <action name="Execute">
                <command>
                    bl-exit --suspend
                </command>
            </action>
        </item>
        <item label="Reboot">
            <action name="Execute">
                <command>
                    bl-exit --reboot
                </command>
            </action>
        </item>
        <item label="Power off">
            <action name="Execute">
                <command>
                    bl-exit --poweroff
                </command>
            </action>
        </item>
    </menu>

...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#23 2019-02-24 09:24:10

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: bl-exit replacement suggestions

Indeed, but not enabled by default & no knowing if it'll remain that way with whatever proposed default solution gets used,, sorry, I'm just ticked off, I spent considerable time figuring out getting a netinstall prepped so I could fire off `sudo apt install bunsen-meta-all` & everything routinely used by me including the exit script "just works" (as well as on a systemd install).. literally just cracked the process.. no fancy new polkit rules in arcane places.. just functions & suddenly the forums full of suggestions virtually every one of which will break it without post-install messing around.

Leaves me in limbo for knowing what's what.. if the default replacement is basically a bash cum yad or similar script, I *may* be able to figure some way to make it support systemd OR elogind, assuming whoever writes it isn't too precious about it to possibly incorporate some edits to permit that,  if it uses dbus it likely just will anyway.

I expect I've been rather more verbose in this thread than I ought to have, it's just frustration having thought I'd beaten the problems with the exit package.. just to have them reintroduced.

If it's hard coded commands in the menu there's no way to avoid post-install edits sadly.

Last edited by Bearded_Blunder (2019-02-24 09:50:17)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#24 2019-02-25 06:32:43

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,553
Website

Re: bl-exit replacement suggestions

Bearded_Blunder wrote:

sorry, I'm just ticked off, I spent considerable time figuring out getting a netinstall prepped so I could fire off `sudo apt install bunsen-meta-all`...

Just a minute, you're talking about BL helium or lithium here? If the latter, then with the greatest respect I think it might be thought a little foolhardy to invest hours of time making an installer for a distro that doesn't yet exist.

No major changes will be made to our current release, but the next one, based on Debian testing, is still up in the air. The contents of eg bunsen-meta-all could change tomorrow.

This thread is one of many discussing exactly what Lithium will be like. Of course all suggestions are welcome.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#25 2019-02-25 06:54:39

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: bl-exit replacement suggestions

Lithium, and not an installer, just a process for getting debian buster w sysvinit on without major post install hassles, and the time hasn't been exclusively spent on Lithium, just mostly ;-) I've had every DE bar GNOME from tasksel on, now I have that process finally licked I think, more or less and it's identical right to the point where you apt install task-chosen-desktop or bunsen-meta-all.

Getting that darned exit dialogue working correctly OOTB turned out to be the biggest challenge & the fix for it fixed most of the other hassles with both Li & the other DEs.

Was actually bunsen-exit got me interested in that as a project, specifically you asking me if I had a means to test it against elogind. Then I wasn't satisfied with it half-assed working with arcane config files for policykit.. and maybe got carried away making the darned thing work in buster, no need in stretch, there it just worketh. Getting around no systemd-shim anymore was the biggie.

I actually plan to have a bash/yad based suggestion for here soon, I have a strategy, simple commands that work, a small function to deal with which init is present & an outline for a drop-in replacement, but it'll be two or three days before I get chance to run it through any paces, RL commitments.

jonraff wrote:

The contents of eg bunsen-meta-all could change tomorrow.

Which is exactly why I'm spending the time to deal with glitches as they arise, that way when it does release I'll have a process rather than a mountain to climb. I'd rather be dealing with one or 2 changes at a time than three hundred & four at once.

Last edited by Bearded_Blunder (2019-02-25 07:35:29)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#26 2019-02-25 14:19:58

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,611

Re: bl-exit replacement suggestions

hhh wrote:

I'm using a yad script

Yad/Zenity scripts are nice.

Vertical dialog box. Logout command is window manager agnostic:

#!/bin/sh

yad --form --class=WmanExit --width=172 --borders=5 --height=360 --undecorated --skip-taskbar --image=utilities-system-monitor --image-on-top --center \
--field="  Log Out!gnome-logout!Log Out":fbtn "pkill `wmctrl -m | awk '/Name/ {print tolower($2)}'`" \
--field="  Lock Screen!gnome-lockscreen!Lock Screen":fbtn "slock" \
--field="  Hibernate!gnome-session-hibernate!Hibernate":fbtn "systemctl hybernate" \
--field="  Suspend!gnome-session-suspend!Suspend":fbtn "systemctl suspend" \
--field="  Restart!system-reboot!Restart":fbtn "systemctl reboot" \
--field="  Shut Down!gnome-shutdown!Shut Down":fbtn "systemctl poweroff" \
--button=gtk-cancel \

You must unlearn what you have learned.
    -- yoda

Offline

#27 2019-02-26 01:27:24

hhh
Gaucho
From: High in the Custerdome
Registered: 2015-09-17
Posts: 16,032
Website

Re: bl-exit replacement suggestions

PackRat wrote:
hhh wrote:

I'm using a yad script

Yad/Zenity scripts are nice.

Vertical dialog box. Logout command is window manager agnostic:

#!/bin/sh

yad --form --class=WmanExit --width=172 --borders=5 --height=360 --undecorated --skip-taskbar --image=utilities-system-monitor --image-on-top --center \
--field="  Log Out!gnome-logout!Log Out":fbtn "pkill `wmctrl -m | awk '/Name/ {print tolower($2)}'`" \
--field="  Lock Screen!gnome-lockscreen!Lock Screen":fbtn "slock" \
--field="  Hibernate!gnome-session-hibernate!Hibernate":fbtn "systemctl hybernate" \
--field="  Suspend!gnome-session-suspend!Suspend":fbtn "systemctl suspend" \
--field="  Restart!system-reboot!Restart":fbtn "systemctl reboot" \
--field="  Shut Down!gnome-shutdown!Shut Down":fbtn "systemctl poweroff" \
--button=gtk-cancel \

Oh, that is very nice. Any way to get some alignment happening on the icons and text?


No, he can't sleep on the floor. What do you think I'm yelling for?!!!

Offline

#28 2019-02-26 01:31:03

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,611

Re: bl-exit replacement suggestions

I think you can if you dig into yad options a bit deeper.

I put that script together pretty quick when we were updating the VSIDO logout script.

Edit -

man yad | grep align
              Set alignment of field labels. Possible types are left, center
              Set alignment of bar labels. Possible types are left, center or
              Set alignment of bar labels. TYPE can be left, center or right.

Looks doable, set some additional options.

Last edited by PackRat (2019-02-26 01:37:35)


You must unlearn what you have learned.
    -- yoda

Offline

#29 2019-02-26 17:54:37

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,611

Re: bl-exit replacement suggestions

It's the icons that are messing up the alignment - at least for this type of form/button:

screen-import-Tuesday_1551203465.th.png

#!/bin/sh

yad --form --class=WmanExit --width=172 --borders=5 --height=360 --undecorated --center --skip-taskbar \
--field="  Log Out!!Log Out":fbtn "pkill `wmctrl -m | awk '/Name/ {print tolower($2)}'`" \
--field="  Lock Screen!!Lock Screen":fbtn "slock" \
--field="  Hibernate!!Hibernate":fbtn "systemctl hybernate" \
--field="  Suspend!!Suspend":fbtn "systemctl suspend" \
--field="  Restart!!Restart":fbtn "systemctl reboot" \
--field="  Shut Down!!Shut Down":fbtn "systemctl poweroff" \

--button=gtk-cancel \

The "OK" button also shows up. Don't know enough about yad to was philosophic about that.

Also, one recommendation should BL decide to go with a yad script for logout or anything else. Use the "--class=SomeClass" flag with the script. Giving the dialog window a class name allows the user to then set up per-app settings with their window manager of choice, i.e set it to float in tiling wm's.

Last edited by PackRat (2019-02-26 17:55:47)


You must unlearn what you have learned.
    -- yoda

Offline

#30 2019-02-27 00:42:44

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: bl-exit replacement suggestions

I like vertical that way too, however, it bugs me using sleep or hibernate when I wake the machine back up, there's the dialogue still, have to click cancel to get rid of it..

How would one fix that? Doesn't happen with plain yad --button= but btn or fbtn in a form field makes yad a bit stubborn.


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#31 2019-02-27 14:55:38

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,611

Re: bl-exit replacement suggestions

Bearded_Blunder wrote:

it bugs me using sleep or hibernate when I wake the machine back up, there's the dialogue still, have to click cancel to get rid of it..

Quick hack, add

--close-on-unfocus

to options before defining fields.

Otherwise, the button commands will need to be defined with an exit status in the script


You must unlearn what you have learned.
    -- yoda

Offline

#32 2019-03-01 07:35:28

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: bl-exit replacement suggestions

This is only half serious, though functional, please take it in the semi-humorous manner it was intended.

The main point was to show with that little function and the contained one-liner which can replace almost any instance of `systemctl powerstuff` just how easy incorporating elogind support as well as systemd support is in something like this. For an individual it's obviously pointless, for a distribution covering the about 1:50 of us popcon says are using "other init" might just be justified.  The function would be easy to put into pretty much any yad based script, virtually sed & paste. Or simply repeat the one-liner as needed replacing "$1".

Difficult to get much simpler without excluding those who choose not to join the systemd clan. I suppose as a hack workaround a short shell script located at /bin/systemctl or a symlink would work on elogind systems also, this seems cleaner and less prone to unintended consequences, would be a shame to swap a default exit script with elogind support for one without.

I've given it a spin in Bunsen, GNOME, xfce, KDE, Cinnamon, and MATE where after making sure yad is there it just works, needs tweaks for LXQt and LXDE, basically xcreensaver doesn't talk to systemd, or rather doesn't listen when systemd talks fixable with xss-lock to act as intermediary, or obviously an edit to the lock command issued by the script, light-locker and others "Yust Verk!(MT)".


For systemd users:

  • Uses systemctl

  • Uses systemd's loginctl

  • Even the function for "Those other guys" ends in ctl so it must be good big_smile

  • Sings "Happy birthday Lennart Poettering every October 15th!" (Not yet implimented)

For non-systemd users:

  • Doesn't tongue (Uses elogind)

For devs:

  • Simple bash+yad easy to maintain.

  • Easy to prettify the yad, icons & such.

  • 100% drop in replacement for bl-exit, compatible CLI support + extras to make showing hibernate or hybrid-sleep trivial.

  • Added menu if invoked without arguments at a TTY.

  • DFSG compliant licence.

(Debian fought it for years but since caved.  Let's see if Bunsen are as stuffy.)

What more could you ask? Well OK eye-candy, sorry guys artistic isn't my forte, plus I've not played with yad before.

#!/usr/bin/env bash

########################################################################
##                                                                    ##
## Init and desktop agnostic "yad" based Logout/Exit dialogue.        ##
##                                                                    ##
## Written in response to the seeimingly widely held belief that      ##
## 'systemctl' is what you _have_ to use for power operations if you  ##
## have systemd, regardless that dbus calls are arguably superior.    ##
##                                                                    ##
## Since systemd users like systemd specific commands so much, here's ##
## a system exit dialogue that uses systemd's calls for every power   ##
## or session control action, while remaining compatible with         ##
## non-systemd systems.                                               ##
##                                                                    ##
## Originally written for Bunsenlabs "Lithium" by Bearded_Blunder     ##
## <init.choice@mxstuff.org> February 2019                            ##
##                                                                    ##
## Copyright © 2019 MXStuff.org <init.choice@mxstuff.org>             ##
##                                                                    ##
## This program is free software. It comes without any warranty, to   ##
## the extent permitted by applicable law. You can redistribute it    ##
## and/or modify it under the terms of the Do What The Fuck You Want  ##
## To Public License, Version 2, as published by Sam Hocevar. See     ##
## http://www.wtfpl.net/ for more details.                            ##
##                                                                    ##
########################################################################

USAGE="\nbl-exit [OPTION]\n\n\
With no arguments default yad (GUI) or text menu at a TTY\n\n\
Only one argument is read, they cannot be combined\n\
-h --help\tShow this help\n\
-k --lock\tLock session\tDoes not work for a tty session\n\
-l --logout\tLogout\t\tAlso works for tty.\n\
-s --suspend\tSuspend\tState determined by ACPI S0 S1 or S3\n\
-i --hibernate\tSuspend to Disk\tRequires enough swap to store RAM\n\
-y --hybrid\tHybrid Sleep\tACPI must support sleep state S3\n\
-b --reboot\tReboot\n\
-p --poweroff\tShut down\n\n\
GUI Options\n\
-m --simple\t\t(GUI) Yad dialogue\n\
-d --show-hibernate\t(GUI) Adds hibernate option\n\
-a --show-all\t\t(GUI) Adds hibernate and hybrid-sleep\n\
-v --vertical\t\t(GUI) Yad stacked buttons\n\
-D --vertical-hibernate (GUI) Stacked, including hibernate\n\
-A --vertical-all\t(GUI) Stacked, all available options\n"



########################################################################
#                  Compatibility function details                      #
#                                                                      #
# logoutctl() takes the following `systemctl` arguments:               #
#                                                                      #
# poweroff                                                             #
# reboot                                                               #
# suspend                                                              #
# hibernate                                                            #
# hybrid-sleep                                                         #
# ? suspend-then-hibernate                                             #
# elogind supports it (documented), undocumented for systemd. It does  #
# _something_ on my systemd systems YMMV. Not implimented in the main  #
# script owing to not being documented by systemctl --help.            #
#                                                                      #
# Other systemctl arguments are not transferred to the elogind project #
# and will break if a similar systemctl || loginctl approach is used.  #
#                                                                      #
# I've only handled loginctl lock-/terminate-session here because it   #
# gives me a chance to deal with killing yad forms in one location.    #
#                                                                      #
########################################################################

logoutctl(){
    if [[ ! -z $YAD_PID ]]; then
        kill -SIGUSR1 $YAD_PID
    fi
    case $1 in
        cancel )
            echo -e "\ncancelled"
            exit 0 ;;
        terminate-session | lock-session )
            echo  -e "\n$1"
            loginctl $1 $XDG_SESSION_ID
            exit $? ;;
        suspend | hibernate | hybrid-sleep | suspend-then-hibernate | reboot | poweroff )
            echo -e "\n$1"
            #***********************************************#
            # The systemd or elogind compatibility magic.   #
            #***********************************************#
            [[ $(command -v systemctl) ]] && systemctl "$1" || loginctl "$1"
            exit $? ;;
    esac
}
export -f logoutctl

# If a yad picker or "lock" was chosen, test we're not at a TTY.
if [[ -z $@ ]] || [[ $1 =~ (-m|--simple|-d|--show-hibernate|-a|--show-all|-v|--vertical|-D|--vertical-hibernate|-A|--vertical-all|-k|--lock)$ ]]; then
    # Probably better ways, but: "Using systemd" :P Chops out 'x11;' in most DE's 'wayland;' in gnome and 'tty;' at a TTY or with no DM
    if [[ $(loginctl session-status | grep Service: | cut -d " " -f5) = 'tty;' ]]; then
         # We're at a TTY - Are we being asked to lock a TTY?
         if [[ $1 =~ (-k|--lock)$ ]]; then
             echo -e "Error: Graphical environment needed for screen locking."
             echo -e "It can be done with the vlock package installed, using the"
             echo -e "command 'vlock'. This script does not handle that case."
             echo -e "If you have a graphical environment a possible cause of seeing"
             echo -e "this message is that no Display Manager is installed."
             exit 1
         fi
         # TTY exit menu.
         clear
         TTY_EXIT="Please choose an option "
         select option in Logout Sleep Hibernate Hybrid-Sleep Reboot Power-Off Quit-Dialogue
         do
         case $option in
             Logout)        logoutctl terminate-session;;
             Sleep)         logoutctl suspend;;
             Hibernate)     logoutctl hibernate;;
             Hybrid-Sleep)  logoutctl hybrid-sleep;;
             Reboot)        logoutctl reboot;;
             Power-Off)     logoutctl poweroff;;
             Quit-Dialogue) break;;
         esac
    done
    fi
fi

# Default setting
if [[ -z $@ ]];then
    OP_MODE="--vertical-hibernate"
    # Change above for a different system-wide default
    #
    # TODO: Potentially read ~/.config/bunsen/somefile for default,
    #       maybe add changing default with --set-default.
else
    OP_MODE=$1
fi

case $OP_MODE in
    # command line use
    -h|--help)         echo -e "$USAGE"
                           exit 0
                       ;;
    -k|--lock)         logoutctl lock-session;;
    -l|--logout)       logoutctl terminate-session;;
    -s|--suspend)      logoutctl suspend;;
    -i|--hibernate)    logoutctl hibernate;;
    -y|--hybrid)       logoutctl hybrid-sleep;;
    -b|--reboot)       logoutctl reboot;;
    -p|--poweroff)     logoutctl poweroff;;

    ####################################################################
    #            GUI sections "yad hacking" starts here                #
    ####################################################################

    # Simple yad
    -m|--simple) yad --class=WmanExit --undecorated --center --on-top --skip-taskbar \
                     --sticky --text-align=right --text="$HOSTNAME:\nLogout $USER?" \
                     --image-on-top --image="gtk-quit" \
                     --button="Cancel":'bash -c "logoutctl cancel"' \
                     --button="Lock":'bash -c "logoutctl lock-session"' \
                     --button="Logout":'bash -c "logoutctl terminate-session"' \
                     --button="Sleep":'bash -c "logoutctl suspend"' \
                     --button="Reboot":'bash -c "logoutctl reboot"' \
                     --button="Shut down":'bash -c "logoutctl poweroff"' \
                 ;;

    # yad with hibernate
    -d|--show-hibernate) yad --class=WmanExit --undecorated --center --on-top --skip-taskbar \
                             --sticky --text-align=right --text="$HOSTNAME:\nLogout $USER?" \
                             --image-on-top --image="gtk-quit" \
                             --button="Cancel":'bash -c "logoutctl cancel"' \
                             --button="Lock":'bash -c "logoutctl lock-session"' \
                             --button="Logout":'bash -c "logoutctl terminate-session"' \
                             --button="Sleep":'bash -c "logoutctl suspend"' \
                             --button="Hibernate":'bash -c "logoutctl hibernate"' \
                             --button="Reboot":'bash -c "logoutctl reboot"' \
                             --button="Shut down":'bash -c "logoutctl poweroff"' \
                         ;;

    # yad with hibernate and hybrid sleep
    -a|--show-all) yad --class=WmanExit --undecorated --center --on-top --skip-taskbar \
                       --sticky --text-align=right --text="$HOSTNAME:\nLogout $USER?" \
                       --image-on-top --image="gtk-quit" \
                       --button="Cancel":'bash -c "logoutctl cancel"' \
                       --button="Lock":'bash -c "logoutctl lock-session"' \
                       --button="Logout":'bash -c "logoutctl terminate-session"' \
                       --button="Sleep":'bash -c "logoutctl suspend"' \
                       --button="Hibernate":'bash -c "logoutctl hibernate"' \
                       --button="Hyb sleep":'bash -c "logoutctl hybrid-sleep"' \
                       --button="Reboot":'bash -c "logoutctl reboot"' \
                       --button="Shut down":'bash -c "logoutctl poweroff"' \
                   ;;
                   
    # VericaL GUI
    -v|--vertical) yad --form --columns 1 --width=200 --borders=7 --class=WmanExit \
                       --no-buttons --undecorated --center --on-top --skip-taskbar \
                       --sticky --text="$HOSTNAME\nLogout $USER?" --text-align=center \
                       --image-on-top --image="gtk-quit" \
                       --field="Cancel":fbtn 'bash -c "logoutctl cancel"' \
                       --field="Lock":fbtn 'bash -c "logoutctl lock-session"' \
                       --field="Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                       --field="Sleep":fbtn 'bash -c "logoutctl suspend"' \
                       --field="Restart PC":fbtn 'bash -c "logoutctl reboot"' \
                       --field="Shut Down":fbtn 'bash -c "logoutctl poweroff"' \
                       | grep -v "|" &
                   exit 0
                   ;;

    # Vertical GUI With hibernate
    -D|--vertical-hibernate) yad --form --columns 1 --width=200 --borders=7 --class=WmanExit \
                                 --no-buttons --undecorated --center --on-top --skip-taskbar \
                                 --sticky --text="$HOSTNAME\nLogout $USER?" --text-align=center \
                                 --image-on-top --image="gtk-quit" \
                                 --field="Cancel":fbtn 'bash -c "logoutctl cancel"' \
                                 --field="Lock":fbtn 'bash -c "logoutctl lock-session"' \
                                 --field="Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                                 --field="Sleep":fbtn 'bash -c "logoutctl suspend"' \
                                 --field="Hibernate":fbtn 'bash -c "logoutctl hibernate"' \
                                 --field="Restart PC":fbtn 'bash -c "logoutctl reboot"' \
                                 --field="Shut Down":fbtn 'bash -c "logoutctl poweroff"' \
                                 | grep -v "|" &
                             exit 0
                             ;;  

    # Vertical GUI All available options
    -A|--vertical-all) yad --form --columns 1 --width=200 --borders=7 --class=WmanExit \
                            --no-buttons --undecorated --center --on-top --skip-taskbar \
                            --sticky --text="$HOSTNAME\nLogout $USER?" --text-align=center \
                            --image-on-top --image="gtk-quit" \
                            --field="Cancel":fbtn 'bash -c "logoutctl cancel"' \
                            --field="Lock":fbtn 'bash -c "logoutctl lock-session"' \
                            --field="Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                            --field="Sleep":fbtn 'bash -c "logoutctl suspend"' \
                            --field="Hyb Sleep":fbtn 'bash -c "logoutctl hybrid-sleep"' \
                            --field="Hibernate":fbtn 'bash -c "logoutctl hibernate"' \
                            --field="Restart PC":fbtn 'bash -c "logoutctl reboot"' \
                            --field="Shut Down":fbtn 'bash -c "logoutctl poweroff"' \
                            | grep -v "|" &
                       exit 0
                       ;;

    # typo land
    *)            echo -e "\nUnknown operation $1"
                  echo -e "$USAGE"
                  exit 1
                  ;;
esac

########################################################################
##                                                                    ##
## Version: 0.1~alpha-1                                               ##
##                                                                    ##
## Depends: bash,systemd | elogind,policykit-1                        ##
##                                                                    ##
## Recommends: yad,light-locker,x-display-manager                     ##
##                                                                    ##
## Note: re "Depends:" `systemctl` requires root or sudo unless       ##
##       policykit-1 is silently providing it. Debian very helpfully  ##
##       configured rootless systemd shutdown/reboot/etc. via         ##
##       policykit-1, `sudo apt purge policykit-1` and try            ##
##       `systemctl reboot` if you disbelieve.                        ##
##       You'll lose a lot of programs in the process though.         ##
##       yad not a hard depend because command line use is possible   ##
##       without it.                                                  ##
##                                                                    ##
## KNOWN ISSUES: xscreensaver, i3lock, and slock, need the xss-lock   ##
##               package installing and configuring for systemd's     ##
##               loginctl to be able to lock the session using them,  ##
##               or edits to this script.                             ##
##                                                                    ##
##               If no display manager is installed the script will   ##
##               detect the session as a TTY rather than graphical,   ##
##               in which case the TTY picker can be run in a         ##
##               terminal emulator, or simply supply command line     ##
##               arguments and run without GUI.                       ##
##                                                                    ##
## BUGS: Probably.                                                    ##
##                                                                    ##
## Customization: Copy to ~/bin Then hack away `man yad` is more use  ##
##                than any help file or manual page I could write.    ##
##                Prettification options abound.                      ##
##                                                                    ##
## Dedicated to: Debian Ecosystem Init Diversity Team                 ##
##               <debian-init-diversity@chiark.greenend.org.uk>       ##
##               May their efforts meet with every success.           ##
##                                                                    ##
########################################################################

Blocks for yad:
These could have been generated at runtime according to specified command line arguments and only had the two blocks, one each for horizontal and vertical. However, since the objection to the old script seems to be speed and overhead, I've used the inelegant method, and simply hard coded them, which cuts processing a tiny smidgen at the expense of a longer script.

I need to learn more bash, I'm a DOS batch-file writer dammit! Or was till I forgot how. Now I scroo everything up cd / in Windows & cd \ in Linux... Actually the first one works since about Win2k.  Mixing up "%VAR%" & "$VAR" doesn't though. As for my yad well you only need to fire this up!
Anyone who actually does do bash could doubtless clean up and greatly improve the script.

In deference to @PackRat and his comment:

--class=WmanExit

Duly specified.

This was only going to be a couple of dozen lines example, I got a tad carried away. :8

Minimalist edition:

#!/usr/bin/env bash

# Init agnostic exit script. Minimalist edition.
logoutctl(){
    [[ -z $YAD_PID ]] || kill -SIGUSR1 $YAD_PID
    case $1 in
        cancel ) exit 0;;
        terminate-session | lock-session ) loginctl $1 $XDG_SESSION_ID;;
        suspend | hibernate | hybrid-sleep | reboot | poweroff ) [[ $(command -v systemctl) ]] && systemctl "$1" || loginctl "$1";;
    esac
}
export -f logoutctl

yad --form --class=WmanExit --undecorated --center --on-top --skip-taskbar \
--sticky --form --columns 1 --width=200 --borders=7 --no-buttons \
--field="Cancel":fbtn 'bash -c "logoutctl cancel"' \
--field="Lock":fbtn 'bash -c "logoutctl lock-session"' \
--field="Logout":fbtn 'bash -c "logoutctl terminate-session"' \
--field="Sleep":fbtn 'bash -c "logoutctl suspend"' \
--field="Hyb Sleep":fbtn 'bash -c "logoutctl hybrid-sleep"' \
--field="Hibernate":fbtn 'bash -c "logoutctl hibernate"' \
--field="Restart PC":fbtn 'bash -c "logoutctl reboot"' \
--field="Shut Down":fbtn 'bash -c "logoutctl poweroff"' &> /dev/null &

Last edited by Bearded_Blunder (2019-03-01 07:37:27)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#33 2019-03-01 07:51:45

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: bl-exit replacement suggestions

Nice work smile

....now if only we could have keyboard accelerators as well hmm


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#34 2019-03-01 08:00:03

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: bl-exit replacement suggestions

I knew I'd miss something tongue


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#35 2019-03-01 08:20:00

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,553
Website

Re: bl-exit replacement suggestions

Thanks!


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#36 2019-03-01 08:51:45

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: bl-exit replacement suggestions

damo wrote:

Nice work smile

....now if only we could have keyboard accelerators as well hmm

Your command is my wish or something  tongue  v0.2

#!/usr/bin/env bash

########################################################################
##                                                                    ##
## Init and desktop agnostic "yad" based Logout/Exit dialogue.        ##
##                                                                    ##
## Written in response to the seeimingly widely held belief that      ##
## 'systemctl' is what you _have_ to use for power operations if you  ##
## have systemd, regardless that dbus calls are arguably superior.    ##
##                                                                    ##
## Since systemd users like systemd specific commands so much, here's ##
## a system exit dialogue that uses systemd's calls for every power   ##
## or session control action, while remaining compatible with         ##
## non-systemd systems.                                               ##
##                                                                    ##
## Originally written for Bunsenlabs "Lithium" by Bearded_Blunder     ##
## <init.choice@mxstuff.org> February 2019                            ##
##                                                                    ##
## Copyright © 2019 MXStuff.org <init.choice@mxstuff.org>             ##
##                                                                    ##
## This program is free software. It comes without any warranty, to   ##
## the extent permitted by applicable law. You can redistribute it    ##
## and/or modify it under the terms of the Do What The Fuck You Want  ##
## To Public License, Version 2, as published by Sam Hocevar. See     ##
## http://www.wtfpl.net/ for more details.                            ##
##                                                                    ##
########################################################################

USAGE="\nbl-exit [OPTION]\n\n\
With no arguments default yad (GUI) or text menu at a TTY\n\n\
Only one argument is read, they cannot be combined\n\
-h --help\tShow this help\n\
-k --lock\tLock session\tDoes not work for a tty session\n\
-l --logout\tLogout\t\tAlso works for tty.\n\
-s --suspend\tSuspend\tState determined by ACPI S0 S1 or S3\n\
-i --hibernate\tSuspend to Disk\tRequires enough swap to store RAM\n\
-y --hybrid\tHybrid Sleep\tACPI must support sleep state S3\n\
-b --reboot\tReboot\n\
-p --poweroff\tShut down\n\n\
GUI Options\n\
-m --simple\t\t(GUI) Yad dialogue\n\
-d --show-hibernate\t(GUI) Adds hibernate option\n\
-a --show-all\t\t(GUI) Adds hibernate and hybrid-sleep\n\
-v --vertical\t\t(GUI) Yad stacked buttons\n\
-D --vertical-hibernate (GUI) Stacked, including hibernate\n\
-A --vertical-all\t(GUI) Stacked, all available options\n"



########################################################################
#                  Compatibility function details                      #
#                                                                      #
# logoutctl() takes the following `systemctl` arguments:               #
#                                                                      #
# poweroff                                                             #
# reboot                                                               #
# suspend                                                              #
# hibernate                                                            #
# hybrid-sleep                                                         #
# ? suspend-then-hibernate                                             #
# elogind supports it (documented), undocumented for systemd. It does  #
# _something_ on my systemd systems YMMV. Not implimented in the main  #
# script owing to not being documented by systemctl --help.            #
#                                                                      #
# Other systemctl arguments are not transferred to the elogind project #
# and will break if a similar systemctl || loginctl approach is used.  #
#                                                                      #
# I've only handled loginctl lock-/terminate-session here because it   #
# gives me a chance to deal with killing yad forms in one location.    #
#                                                                      #
########################################################################

logoutctl(){
    if [[ ! -z $YAD_PID ]]; then
        kill -SIGUSR1 $YAD_PID
    fi
    case $1 in
        cancel )
            echo -e "\ncancelled"
            exit 0 ;;
        terminate-session | lock-session )
            echo  -e "\n$1"
            loginctl $1 $XDG_SESSION_ID
            exit $? ;;
        suspend | hibernate | hybrid-sleep | suspend-then-hibernate | reboot | poweroff )
            echo -e "\n$1"
            #***********************************************#
            # The systemd or elogind compatibility magic.   #
            #***********************************************#
            [[ $(command -v systemctl) ]] && systemctl "$1" || loginctl "$1"
            exit $? ;;
    esac
}
export -f logoutctl

# If a yad picker or "lock" was chosen, test we're not at a TTY.
if [[ -z $@ ]] || [[ $1 =~ (-m|--simple|-d|--show-hibernate|-a|--show-all|-v|--vertical|-D|--vertical-hibernate|-A|--vertical-all|-k|--lock)$ ]]; then
    # Probably better ways, but: "Using systemd" :P Chops out 'x11;' in most DE's 'wayland;' in gnome and 'tty;' at a TTY or with no DM
    if [[ $(loginctl session-status | grep Service: | cut -d " " -f5) = 'tty;' ]]; then
         # We're at a TTY - Are we being asked to lock a TTY?
         if [[ $1 =~ (-k|--lock)$ ]]; then
             echo -e "Error: Graphical environment needed for screen locking."
             echo -e "It can be done with the vlock package installed, using the"
             echo -e "command 'vlock'. This script does not handle that case."
             echo -e "If you have a graphical environment a possible cause of seeing"
             echo -e "this message is that no Display Manager is installed."
             exit 1
         fi
         # TTY exit menu.
         clear
         TTY_EXIT="Please choose an option "
         select option in Logout Sleep Hibernate Hybrid-Sleep Reboot Power-Off Quit-Dialogue
         do
         case $option in
             Logout)        logoutctl terminate-session;;
             Sleep)         logoutctl suspend;;
             Hibernate)     logoutctl hibernate;;
             Hybrid-Sleep)  logoutctl hybrid-sleep;;
             Reboot)        logoutctl reboot;;
             Power-Off)     logoutctl poweroff;;
             Quit-Dialogue) break;;
         esac
    done
    fi
fi

# Default setting
if [[ -z $@ ]];then
    OP_MODE="--vertical-hibernate"
    # Change above for a different system-wide default
    #
    # TODO: Potentially read ~/.config/bunsen/somefile for default,
    #       maybe add changing default with --set-default.
else
    OP_MODE=$1
fi

case $OP_MODE in
    # command line use
    -h|--help)         echo -e "$USAGE"
                           exit 0
                       ;;
    -k|--lock)         logoutctl lock-session;;
    -l|--logout)       logoutctl terminate-session;;
    -s|--suspend)      logoutctl suspend;;
    -i|--hibernate)    logoutctl hibernate;;
    -y|--hybrid)       logoutctl hybrid-sleep;;
    -b|--reboot)       logoutctl reboot;;
    -p|--poweroff)     logoutctl poweroff;;

    ####################################################################
    #            GUI sections "yad hacking" starts here                #
    ####################################################################

    # Simple yad
    -m|--simple) yad --class=WmanExit --undecorated --center --on-top --skip-taskbar \
                     --sticky --text-align=right --text="$HOSTNAME:\nLogout $USER?" \
                     --image-on-top --image="gtk-quit" \
                     --button="_Cancel":'bash -c "logoutctl cancel"' \
                     --button="Loc_k":'bash -c "logoutctl lock-session"' \
                     --button="_Logout":'bash -c "logoutctl terminate-session"' \
                     --button="_Sleep":'bash -c "logoutctl suspend"' \
                     --button="_Restart PC":'bash -c "logoutctl reboot"' \
                     --button="Shu_t Down":'bash -c "logoutctl poweroff"' \
                 ;;

    # yad with hibernate
    -d|--show-hibernate) yad --class=WmanExit --undecorated --center --on-top --skip-taskbar \
                             --sticky --text-align=right --text="$HOSTNAME:\nLogout $USER?" \
                             --image-on-top --image="gtk-quit" \
                             --button="_Cancel":'bash -c "logoutctl cancel"' \
                             --button="Loc_k":'bash -c "logoutctl lock-session"' \
                             --button="_Logout":'bash -c "logoutctl terminate-session"' \
                             --button="_Sleep":'bash -c "logoutctl suspend"' \
                             --button="_Hibernate":'bash -c "logoutctl hibernate"' \
                             --button="_Restart PC":'bash -c "logoutctl reboot"' \
                             --button="Shu_t Down":'bash -c "logoutctl poweroff"' \
                         ;;

    # yad with hibernate and hybrid sleep
    -a|--show-all) yad --class=WmanExit --undecorated --center --on-top --skip-taskbar \
                       --sticky --text-align=right --text="$HOSTNAME:\nLogout $USER?" \
                       --image-on-top --image="gtk-quit" \
                       --button="_Cancel":'bash -c "logoutctl cancel"' \
                       --button="Loc_k":'bash -c "logoutctl lock-session"' \
                       --button="_Logout":'bash -c "logoutctl terminate-session"' \
                       --button="_Sleep":'bash -c "logoutctl suspend"' \
                       --button="H_yb Sleep":'bash -c "logoutctl hybrid-sleep"' \
                       --button="_Hibernate":'bash -c "logoutctl hibernate"' \
                       --button="_Restart PC":'bash -c "logoutctl reboot"' \
                       --button="Shu_t Down":'bash -c "logoutctl poweroff"' \
                   ;;
                   
    # VericaL GUI
    -v|--vertical) yad --form --columns 1 --width=200 --borders=7 --class=WmanExit \
                       --no-buttons --undecorated --center --on-top --skip-taskbar \
                       --sticky --text="$HOSTNAME\nLogout $USER?" --text-align=center \
                       --image-on-top --image="gtk-quit" \
                       --field="_Cancel":fbtn 'bash -c "logoutctl cancel"' \
                       --field="Loc_k":fbtn 'bash -c "logoutctl lock-session"' \
                       --field="_Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                       --field="_Sleep":fbtn 'bash -c "logoutctl suspend"' \
                       --field="_Restart PC":fbtn 'bash -c "logoutctl reboot"' \
                       --field="Shu_t Down":fbtn 'bash -c "logoutctl poweroff"' \
                       | grep -v "|" &
                   exit 0
                   ;;

    # Vertical GUI With hibernate
    -D|--vertical-hibernate) yad --form --columns 1 --width=200 --borders=7 --class=WmanExit \
                                 --no-buttons --undecorated --center --on-top --skip-taskbar \
                                 --sticky --text="$HOSTNAME\nLogout $USER?" --text-align=center \
                                 --image-on-top --image="gtk-quit" \
                                 --field="_Cancel":fbtn 'bash -c "logoutctl cancel"' \
                                 --field="Loc_k":fbtn 'bash -c "logoutctl lock-session"' \
                                 --field="_Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                                 --field="_Sleep":fbtn 'bash -c "logoutctl suspend"' \
                                 --field="_Hibernate":fbtn 'bash -c "logoutctl hibernate"' \
                                 --field="_Restart PC":fbtn 'bash -c "logoutctl reboot"' \
                                 --field="Shu_t Down":fbtn 'bash -c "logoutctl poweroff"' \
                                 | grep -v "|" &
                             exit 0
                             ;;  

    # Vertical GUI All available options
    -A|--vertical-all) yad --form --columns 1 --width=200 --borders=7 --class=WmanExit \
                            --no-buttons --undecorated --center --on-top --skip-taskbar \
                            --sticky --text="$HOSTNAME\nLogout $USER?" --text-align=center \
                            --image-on-top --image="gtk-quit" \
                            --field="_Cancel":fbtn 'bash -c "logoutctl cancel"' \
                            --field="Loc_k":fbtn 'bash -c "logoutctl lock-session"' \
                            --field="_Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                            --field="_Sleep":fbtn 'bash -c "logoutctl suspend"' \
                            --field="H_yb Sleep":fbtn 'bash -c "logoutctl hybrid-sleep"' \
                            --field="_Hibernate":fbtn 'bash -c "logoutctl hibernate"' \
                            --field="_Restart PC":fbtn 'bash -c "logoutctl reboot"' \
                            --field="Shu_t Down":fbtn 'bash -c "logoutctl poweroff"' \
                            | grep -v "|" &
                       exit 0
                       ;;

    # typo land
    *)            echo -e "\nUnknown operation $1"
                  echo -e "$USAGE"
                  exit 1
                  ;;
esac

########################################################################
##                                                                    ##
## Version: 0.2~alpha-1                                               ##
##                                                                    ##
## Depends: bash,systemd | elogind,policykit-1                        ##
##                                                                    ##
## Recommends: yad,light-locker,x-display-manager                     ##
##                                                                    ##
## Note: re "Depends:" `systemctl` requires root or sudo unless       ##
##       policykit-1 is silently providing it. Debian very helpfully  ##
##       configured rootless systemd shutdown/reboot/etc. via         ##
##       policykit-1, `sudo apt purge policykit-1` and try            ##
##       `systemctl reboot` if you disbelieve.                        ##
##       You'll lose a lot of programs in the process though.         ##
##       yad not a hard depend because command line use is possible   ##
##       without it.                                                  ##
##                                                                    ##
## KNOWN ISSUES: xscreensaver, i3lock, and slock, need the xss-lock   ##
##               package installing and configuring for systemd's     ##
##               loginctl to be able to lock the session using them,  ##
##               or edits to this script.                             ##
##                                                                    ##
##               If no display manager is installed the script will   ##
##               detect the session as a TTY rather than graphical,   ##
##               in which case the TTY picker can be run in a         ##
##               terminal emulator, or simply supply command line     ##
##               arguments and run without GUI.                       ##
##                                                                    ##
## BUGS: Probably.                                                    ##
##                                                                    ##
## Customization: Copy to ~/bin Then hack away `man yad` is more use  ##
##                than any help file or manual page I could write.    ##
##                Prettification options abound.                      ##
##                                                                    ##
## Dedicated to: Debian Ecosystem Init Diversity Team                 ##
##               <debian-init-diversity@chiark.greenend.org.uk>       ##
##               May their efforts meet with every success.           ##
##                                                                    ##
########################################################################
#
# Version: 0.2~alpha-1 Added keyboard accelerators. 
#                      Fixed typo on one button.
#
# Version: 0.1~alpha-1 Initial script.
#

Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Offline

#37 2019-03-01 13:43:31

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,611

Re: bl-exit replacement suggestions

Nice work.


You must unlearn what you have learned.
    -- yoda

Offline

#38 2019-03-01 16:26:34

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: bl-exit replacement suggestions

Excellent work - kudos smile


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#39 2019-03-01 19:14:53

hhh
Gaucho
From: High in the Custerdome
Registered: 2015-09-17
Posts: 16,032
Website

Re: bl-exit replacement suggestions

Um, @Bearded_Blunder?

Flipping fantastic, sir!

Screenshot_2019-03-01_14-07-53.md.png

I am not a programmer, but it took me only 30 minutes to hack this together. Thank you very much!

    # Vertical Simple GUI
    -v|--vertical-simple) yad --form --columns 1 --width=200 --title "Exit" --borders=7 --class=WmanExit --window-icon=system-shutdown \
                       --no-buttons --undecorated --center --on-top \
                       --image=gnome-logout \
                       --field="_Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                       --field="_Suspend":fbtn 'bash -c "logoutctl suspend"' \
                       --field="Re_boot":fbtn 'bash -c "logoutctl reboot"' \
                       --field="_Power Off":fbtn 'bash -c "logoutctl poweroff"' \
                       | grep -v "|" &
                   exit 0
                   ;;

-edit- Changed the Reboot accelerator to Alt-b, r has a conflict on my system.

Last edited by hhh (2019-03-01 19:21:49)


No, he can't sleep on the floor. What do you think I'm yelling for?!!!

Offline

#40 2019-03-01 20:42:34

hhh
Gaucho
From: High in the Custerdome
Registered: 2015-09-17
Posts: 16,032
Website

Re: bl-exit replacement suggestions

Oh, hell yes.

Screenshot_2019-03-01_15-39-03.th.png

    # Vertical Simple GUI
    -v|--vertical-simple) yad --form --columns 1 --width=130 --title "Exit" --borders=7 --class=WmanExit --window-icon=gnome-logout \
                       --no-buttons --undecorated --center --on-top \
                       --field="Log Out!gnome-logout!_Logout":fbtn 'bash -c "logoutctl terminate-session"' \
                       --field="Suspend!gnome-session-suspend!_Suspend":fbtn 'bash -c "logoutctl suspend"' \
                       --field="Reboot!system-reboot!Re_boot":fbtn 'bash -c "logoutctl reboot"' \
                       --field="Shut Down!gnome-shutdown!_Power Off":fbtn 'bash -c "logoutctl poweroff"' \
                       | grep -v "|" &
                   exit 0
                   ;;

No, he can't sleep on the floor. What do you think I'm yelling for?!!!

Offline

Board footer

Powered by FluxBB