From 84b789844b78022712cc403fef49476ccea916bc Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 11 Aug 2009 22:39:12 +0100 Subject: [PATCH] Second attempt at locking the screen --- src/app_powerbutton.vala | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/app_powerbutton.vala b/src/app_powerbutton.vala index 175e67f..0d12a8a 100644 --- a/src/app_powerbutton.vala +++ b/src/app_powerbutton.vala @@ -136,26 +136,36 @@ public class CommandButton : Gtk.Button } } -private bool screen_locked = false; +private bool screen_locked; +private int screen_lock_fd; private void set_screen_lock(bool locked) { - int fd = Posix.open("/dev/input/event1", Posix.O_RDWR | Posix.O_NONBLOCK); - if (fd < 0) + if (locked && screen_locked) + return; + if (!locked && !screen_locked) + return; + + if (locked) + { + screen_lock_fd = Posix.open("/dev/input/event1", Posix.O_RDWR | Posix.O_NONBLOCK); + if (screen_lock_fd < 0) { zavai.log.error("Cannot open /dev/input/event1"); return; } int EVIOCGRAB = 0x40044590; - if (Posix.ioctl(fd, EVIOCGRAB, locked ? 1 : 0) != 0) + if (Posix.ioctl(screen_lock_fd, EVIOCGRAB, locked ? 1 : 0) != 0) { zavai.log.error("Cannot EVIOCGRAB /dev/input/event1"); - Posix.close(fd); + Posix.close(screen_lock_fd); return; } - screen_locked = locked; - Posix.close(fd); + } else { + Posix.close(screen_lock_fd); + } + screen_locked = locked; } public class ScreenLockButton : Gtk.Button @@ -194,6 +204,9 @@ Launcher launcher; public void init() { + screen_locked = false; + screen_lock_fd = -1; + zavai.input.power_button.power_button += on_power_button; // Menus -- 2.30.2