我在debian,ubuntu和rhel7中成功使用的变通方法是创建一个简短的python脚本,当您登录gnome会话时,该脚本会自动启动。请注意,在rhel7中,用于锁定的键组合为super + l。
像这样创建/etc/xdg/autostart/gscreenlock.py:
#!/usr/bin/python
import dbus
import dbus.service
import dbus.glib
import gobject
import os
class ScreenDbusObj(dbus.service.Object):
def __init__(self):
session_bus = dbus.SessionBus()
bus_name=dbus.service.BusName("org.gnome.ScreenSaver",bus=session_bus)
dbus.service.Object.__init__(self,bus_name, '/org/gnome/ScreenSaver')
@dbus.service.method("org.gnome.ScreenSaver")
def Lock(self):
os.system( "xscreensaver-command -lock" )
if __name__ == '__main__':
object=ScreenDbusObj()
gobject.MainLoop().run()
然后使其可执行:
chmod a+rx /etc/xdg/autostart/gscreenlock.py
并像这样编辑/etc/xdg/autostart/gscreenlock.desktop:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=gscreenlock
TryExec=/etc/xdg/autostart/gscreenlock.py
Exec=/etc/xdg/autostart/gscreenlock.py
NoDisplay=true
NotShowIn=XFCE;KDE;
Comment=Allows screen locking in gnome
Ctrl + Alt + L
。它行得通吗?