You are not logged in.
Pages: 1
Hello there, I'm new to Xfce.
I'm having trouble adapting a command that I copied from another question on Ubuntu forums. The user there wanted to be able to disable his screen and activate it by pressing any key, but not activate it with the mouse. Toz gave him this command that works great:
xrandr --output LVDS1 --off; read -n1; xrandr --output LVDS1 --auto
I would like to go even further, disable the screen, but make it ignore keystrokes as well, except for a particular one, that will enable and disable the screen. Is this possible?
I guess if there was a program that I could bind to a shorcut that would be fine, but i've been unable to find one.
Thank you all, I'm having a very good time with Xfce!
Last edited by BethAr (2016-04-25 21:05:12)
Offline
How about something like this:
#!/bin/bash
# turn off the LVDS1 display
xrandr --output LVDS1 --off
# function to handle Ctrl+C
function sesame {
# read in one key
read -n1 -s key
# if it's a (capital) 'Y', then reset the LVDS1 display
if [ "$key" == 'Y' ]; then
xrandr --output LVDS1 --auto
exit 0
fi
}
# trap Ctrl+C
trap sesame 2
# trap other methods of quitting the script
trap '' 1 3 20
# endless loop
while :
do
sleep 1
done
Ctrl+C followed by a (capital) 'Y', will reset the display.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Online
Thanks a lot, ToZ! It worke great!
Is it possible to configure the Ctrl+C command?
Last edited by BethAr (2016-04-25 14:37:39)
Offline
Is it possible to configure the Ctrl+C command?
I used Ctrl+C (SIGINT) because its easier to trap bash signals. You can remap that using "stty". Here's an example that re-maps Ctrl+c to Ctrk+k:
#!/bin/bash
# re-map Ctrl+c as SIGINT signal
stty intr \^K
# turn off the LVDS1 display
xrandr --output LVDS1 --off
# function to handle Ctrl+C
function sesame {
# read in one key
read -n1 -s key
# if it's a 'Y', then reset the LVDS1 display
if [ "$key" == 'Y' ]; then
# reset LVDS1
xrandr --output LVDS1 --auto
# reset SIGINT
stty intr \^C
# exit
exit 0
fi
}
# trap SIGINT
trap sesame 2
# trap other methods of quitting the script
trap '' 1 3 20
# endless loop
while :
do
sleep 1
done
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Online
oh, there is a problem.
If I bind a shortcut to the script and fire it that way, it doesn't return with Ctrl+C and Y, I have to reset the machine.
Also, the keyboard is completely ignored while the script is running. I was hoping that I could control my music player or write while the screen is off.
I will try rebinding the shorcut.
Thanks again, ToZ.
Edit: I had edited the other post, so I reposted after yours.
Offline
This really changes the purpose of the script. No guarantees, but try creating the keyboard shortcut like this:
xfce4-terminal --disable-server -T "ScreenBlank" -e /path/to/script
...and use this modified version of the script:
#!/bin/bash
# re-map Ctrl+c as SIGSTOP signal
stty intr \^K
# turn off the LVDS1 display
xrandr --output LVDS1 --off
# function to handle Ctrl+C
function sesame {
# read in one key
read -n1 -s key
# if it's a 'Y', then reset the LVDS1 display
if [ "$key" == 'Y' ]; then
# reset LVDS1
xrandr --output LVDS1 --auto
# reset SIGINT
stty intr \^C
# exit
exit 0
fi
}
# trap Ctrl+C
trap sesame 2
# trap other methods of quitting the script
trap '' 1 3 20
# endless loop
while :
do
sleep 1
wmctrl -a ScreenBlank
done
This version of the script forces the xfce4-terminal window to the front every second so that it can capture the keystroke. It also allows me to use my music player shortcuts to control the music player while the screen is blanked.
To avoid having to restart your computer if something goes wrong, assign "xrandr --output LVDS1 --auto" to a keyboard shortcut.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Online
Wee I got it working!
The last script didn't work, I guess because my music player doesn't have global shortcuts, but your last tip did the trick.
I set a shortcut to bring the screen back separately, so I don't have to catch the shortcut in the script.
Here is the script I used:
#!/bin/bash
# turn off the LVDS1 display
xrandr --output LVDS1 --off
# trap other methods of quitting the script
trap '' 1 3 20
# endless loop
while :
do
sleep 1
done
I then launched the script with a regular shortcut (Super+Y), without launching the terminal as you suggested, because then whatever window I have open will stay on focus.
I then add a shortcut to restore the screen (Super+U), just like you said:
xrandr --output LVDS1 --auto
The only thing wonky is that when I bring the screen back, the window is always shifted a little bit to the side.
This functionality might seem odd, but I do work blindly most of the time. I can type for hours without having to look at what I'm doing, later on I come back and fix any mistake. I do this regularly on my desktop, but there I only have to press a button to shut off the screen, now I can do that on my laptop as well.
Thanks a lot ToZ!!
Last edited by BethAr (2016-04-25 16:50:52)
Offline
Pages: 1
[ Generated in 0.010 seconds, 7 queries executed - Memory usage: 544.66 KiB (Peak: 545.5 KiB) ]