initial checkin
authorStefan Vogel <sv@exept.de>
Wed, 17 May 2000 17:33:52 +0200
changeset 1371 a022e5804f07
parent 1370 4d2a3cc1d3c7
child 1372 1395b98e1597
initial checkin
ScreenLock.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ScreenLock.st	Wed May 17 17:33:52 2000 +0200
@@ -0,0 +1,255 @@
+"{ Package: 'private' }"
+
+EventListener subclass:#ScreenLock
+	instanceVariableNames:'workstation lastInactiveTime lockAfterSeconds lockChannel
+		lockedViews'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Support'
+!
+
+!ScreenLock class methodsFor:'documentation'!
+
+documentation
+"
+    documentation to be added.
+
+    [author:]
+	Stefan Vogel (stefan@nilpferd)
+
+    [see also:]
+
+    [instance variables:]
+
+    [class variables:]
+"
+!
+
+examples
+"
+                                                                [exBegin]
+    |screenLock|
+
+    screenLock := ScreenLock forDevice:Screen current.
+    screenLock lock.
+    Delay waitForSeconds:3.
+    screenLock unlock.
+    screenLock unlisten.
+                                                                [exEnd]
+
+                                                                [exBegin]
+    |screenLock|
+
+    screenLock := ScreenLock forDevice:Screen current.
+    Delay waitForSeconds:1.
+    screenLock checkTime.
+    Delay waitForSeconds:12.
+    screenLock checkTime.
+    Delay waitForSeconds:3.
+    screenLock unlock.
+    screenLock unlisten.
+                                                                [exEnd]
+                                                                [exBegin]
+    |screenLock channel running|
+
+    screenLock := ScreenLock forDevice:Screen current.
+    screenLock lockAfterSeconds:4.
+    [
+        channel := false asValue.
+        channel onChangeEvaluate:[
+            channel value ifTrue:[
+                self information:'Application is locked\\Hit ok to unlock' withCRs.
+                channel value:false.
+            ].
+        ].
+        screenLock lockChannel:channel.
+
+        [
+            Delay waitForSeconds:2.
+            screenLock checkTime.
+        ] loop.
+    ] valueNowOrOnUnwindDo:[
+        screenLock unlisten.
+    ].
+                                                                [exEnd]
+"
+! !
+
+!ScreenLock class methodsFor:'instance creation'!
+
+forDevice:aWorkstation
+
+    ^ self new initializeForDevice:aWorkstation
+
+! !
+
+!ScreenLock methodsFor:'accessing'!
+
+lockAfterSeconds
+    "return the value of the instance variable 'lockAfterSeconds' (automatically generated)"
+
+    ^ lockAfterSeconds!
+
+lockAfterSeconds:something
+    "set the value of the instance variable 'lockAfterSeconds' (automatically generated)"
+
+    lockAfterSeconds := something.!
+
+lockChannel
+    "return the value of the instance variable 'lockChannel' (automatically generated)"
+
+    ^ lockChannel!
+
+lockChannel:something
+
+    lockChannel := something.
+    lockChannel addDependent:self.
+!
+
+workstation
+    "return the value of the instance variable 'workstation' (automatically generated)"
+
+    ^ workstation!
+
+workstation:something
+    "set the value of the instance variable 'workstation' (automatically generated)"
+
+    workstation := something.! !
+
+!ScreenLock methodsFor:'change & update'!
+
+update:aspect with:param from:anObject
+
+    |lock|
+
+    anObject == lockChannel ifTrue:[
+        aspect == #value ifTrue:[
+            "/ lockChannel is a value holder
+            lock := lockChannel value.
+        ] ifFalse:[
+            "/ lockChannel is a block or something else
+            lock := param.
+        ].
+        lock == true ifTrue:[
+            self lockScreen.
+        ] ifFalse:[
+            self unlockScreen.
+        ]
+    ].
+! !
+
+!ScreenLock methodsFor:'events'!
+
+buttonMotion:state x:x y:y view:aView
+
+    ^ self gotEvent
+!
+
+buttonMultiPress:button x:x y:y view:aView
+    ^ self gotEvent
+
+!
+
+buttonPress:button x:x y:y view:aView
+    ^ self gotEvent
+
+!
+
+buttonRelease:button x:x y:y view:aView
+    ^ self gotEvent
+
+!
+
+keyPress:key x:x y:y view:aView
+    ^ self gotEvent
+
+!
+
+keyRelease:key x:x y:y view:aView
+    ^ self gotEvent
+
+!
+
+mouseWheelMotion:state x:x y:y amount:amount deltaTime:dTime view:aView
+    ^ self gotEvent
+
+! !
+
+!ScreenLock methodsFor:'lock interface'!
+
+checkTime
+
+    |now|
+
+    lockedViews isNil ifTrue:[
+        now := AbsoluteTime now.
+        lastInactiveTime notNil ifTrue:[
+            (lastInactiveTime addSeconds:lockAfterSeconds value) < now ifTrue:[
+                self lock
+            ].
+        ] ifFalse:[
+            lastInactiveTime := now.
+        ].
+    ].
+!
+
+lock
+
+    lockChannel isNil ifTrue:[
+        self lockChannel:ValueHolder new.
+    ].
+
+    lockChannel value:true.
+!
+
+unlisten
+
+    workstation removeEventListener:self
+!
+
+unlock
+
+    lockChannel value:false.
+! !
+
+!ScreenLock methodsFor:'private'!
+
+gotEvent
+    "got an event.
+     Reset the inactive timer"
+
+    lastInactiveTime := nil.
+    ^ false.
+!
+
+initializeForDevice:aWorkstation
+
+     lockAfterSeconds := 10.
+     workstation := aWorkstation.
+     workstation addEventListener:self.
+
+!
+
+lockScreen
+
+    lockedViews := workstation allViews select:[:v| v isTopView and:[v realized]].
+
+    lockedViews do:[:tv|
+        tv beInvisible.
+    ].
+
+!
+
+unlockScreen
+
+    lockedViews do:[:tv|
+        tv beVisible.
+    ].
+    lockedViews := nil.
+! !
+
+!ScreenLock class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview2/ScreenLock.st,v 1.1 2000-05-17 15:33:52 stefan Exp $'
+! !