我希望 Ubuntu 13.10 上的 Awesome 中有一个简单的锁定功能,既可按需锁定,也可在不活动时锁定。
答案1
获取菜谱原料:
sudo apt-get install xautolock slock
- 自动锁- 在一段时间不活动后执行储物柜。
- 锁- 锁定屏幕,仅显示黑色 UI,输入密码并按 Enter。
首先尝试锁定会话的命令,看看是否喜欢:
slock
可以通过修改其配置将其挂接到 Awesome 菜单中:
# make awesome config dir:
mkdir -p ~/.config/awesome
# copy default config file to your home folder:
cp /etc/xdg/awesome/rc.lua ~/.config/awesome
# edit the custom config:
nano ~/.config/awesome/rc.lua
找到构建 mymainmenu 的位置并进行调整。我的部分现在如下所示(请注意“Lock”行):
lockscreen = function() awful.util.spawn("slock") end
mymainmenu = awful.menu({ items = {
{ "Lock", lockscreen },
{ "Awesome", myawesomemenu, beautiful.awesome_icon },
{ "Debian", debian.menu.Debian_menu.Debian },
{ "Guest", terminal .. " -e /usr/bin/dm-tool switch-to-guest" },
{ "Greet", terminal .. " -e /usr/bin/dm-tool switch-to-greeter" },
{ "Logout", awesome.quit },
}
})
并为其创建 Meta+Escape 快捷方式。最初 Escape 绑定到标记历史记录。但我不使用该功能。
-- it was:
-- awful.key({ modkey, }, "Escape", awful.tag.history.restore),
awful.key({ modkey, }, "Escape", lockscreen ),
然后是自动锁定。我创建了一个可执行文件,以确保 xautolock 每个会话仅执行一次:
# make a bin folder if not present:
mkdir -p ~/bin/
# make the file, set permissions and edit:
touch ~/bin/session-daemon
chmod ug+x ~/bin/session-daemon
nano ~/bin/session-daemon
我使用由 DM 设置的环境变量“XDG_SEAT”来区分会话并存储命令的 PID 和日志。它仅在尚未运行时执行:
#!/bin/bash
if [ "$#" == "0" ] ;
then
echo "Session daemon missing command" >&2
echo "USAGE: $0 command [args...]"
echo "Executes given command with args only once per XDG seat (session)."
echo "Keeps PID and log of the executed command."
exit 1
fi
COMMAND=$1
shift
NAME="${COMMAND##*/}"
PIDFILE=~/.cache/session-daemon/$NAME-$XDG_SEAT.pid
LOGFILE=~/.cache/session-daemon/$NAME-$XDG_SEAT.log
PID=""
PIDDIR="${PIDFILE%/*}"
LOGDIR="${LOGFILE%/*}"
mkdir -p $PIDDIR
if [ $? -ne 0 ];
then
echo "Session daemon PIDDIR not there: $PIDDIR" >&2
exit 2
fi
mkdir -p $LOGDIR
if [ $? -ne 0 ];
then
echo "Session daemon LOGDIR not there: $LOGDIR" >&2
exit 2
fi
if [ -e "$PIDFILE" ] ;
then
echo "Session daemon '$NAME' PIDFILE found: $PIDFILE"
PID=`cat "$PIDFILE"`
echo "Session daemon '$NAME' PID found: $PID"
else
echo "Session daemon '$NAME' PIDFILE NOT found: $PIDFILE"
fi
if [ "$PID" ] && kill -0 "$PID" 2>/dev/null ;
then
echo "Session daemon '$NAME' was already running with PID $PID" >&2
exit 3
fi
echo "Session daemon running $COMMAND $* > $LOGFILE 2>&1"
$COMMAND $* > "$LOGFILE" 2>&1 &
PID=$!
ERR=$?
sleep 1
if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev/null;
then
echo -n $PID > "$PIDFILE"
echo "Session daemon '$NAME' started with PID $PID"
else
echo "Session daemon '$NAME' did not start or finished early. PID: $PID, ERR: $ERR" >&2
cat "$LOGFILE" >&2
exit 4
fi
该会话守护程序脚本将由 xautolock-session 使用:
# make the file, set permissions and edit:
touch ~/bin/xautolock-session
chmod ug+x ~/bin/xautolock-session
nano ~/bin/xautolock-session
xautolock-session 内容:
#!/bin/bash
session-daemon xautolock -locker slock -time 5 -detectsleep -secure -corners "-00+"
这将由 Awesome 在重启时执行。再次编辑 Awesome 配置:
nano ~/.config/awesome/rc.lua
并在底部添加这一行:
awful.util.spawn_with_shell("~/bin/xautolock-session")
现在,当您退出并再次登录时,您的会话将在 5 分钟后自动锁定。
注意:我们dm-tool lock
也可以使用,但是有一个奇怪的错误实际上破坏了整个想法:可以通过切换到控制台来绕过锁定