Second attempt at locking the screen
authorEnrico Zini <enrico@enricozini.org>
Tue, 11 Aug 2009 21:39:12 +0000 (22:39 +0100)
committerEnrico Zini <enrico@enricozini.org>
Tue, 11 Aug 2009 21:39:12 +0000 (22:39 +0100)
src/app_powerbutton.vala

index 175e67fb6e5ac320c93ee5a09038c3f436560847..0d12a8a25e5880f034cd0c33a4cff5c7423ea12c 100644 (file)
@@ -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)
 {
 
 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;
                {
                        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");
                {
                        zavai.log.error("Cannot EVIOCGRAB /dev/input/event1");
-                       Posix.close(fd);
+                       Posix.close(screen_lock_fd);
                        return;
                }
                        return;
                }
-               screen_locked = locked;
-               Posix.close(fd);
+       } else {
+               Posix.close(screen_lock_fd);
+       }
+       screen_locked = locked;
 }
 
 public class ScreenLockButton : Gtk.Button
 }
 
 public class ScreenLockButton : Gtk.Button
@@ -194,6 +204,9 @@ Launcher launcher;
 
 public void init()
 {
 
 public void init()
 {
+       screen_locked = false;
+       screen_lock_fd = -1;
+
        zavai.input.power_button.power_button += on_power_button;
 
     // Menus
        zavai.input.power_button.power_button += on_power_button;
 
     // Menus