ScreenLock.st
author Stefan Vogel <sv@exept.de>
Mon, 02 Oct 2000 16:47:03 +0200
changeset 1416 79f3aee2d64c
parent 1415 fd8738cc4733
child 1462 b7ffa1109142
permissions -rw-r--r--
Add processor (an ApplicationModel), which processes the lock/unlock operation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
     1
"{ Package: 'stx:libview2' }"
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     2
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     3
EventListener subclass:#ScreenLock
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     4
	instanceVariableNames:'workstation lastInactiveTime lockAfterSeconds lockChannel
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
     5
		lockChannelOut processor lockedViews hiddenViews'
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     6
	classVariableNames:''
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     7
	poolDictionaries:''
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     8
	category:'Interface-Support'
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     9
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    10
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    11
!ScreenLock class methodsFor:'documentation'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    12
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    13
documentation
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    14
"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    15
    documentation to be added.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    16
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    17
    [author:]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    18
	Stefan Vogel (stefan@nilpferd)
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
    [see also:]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    22
    [instance variables:]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    23
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    24
    [class variables:]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    25
"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    26
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    27
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    28
examples
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    29
"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    30
                                                                [exBegin]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    31
    |screenLock|
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    32
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    33
    screenLock := ScreenLock forDevice:Screen current.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    34
    screenLock lock.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    35
    Delay waitForSeconds:3.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    36
    screenLock unlock.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    37
    screenLock unlisten.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    38
                                                                [exEnd]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    39
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    40
                                                                [exBegin]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    41
    |screenLock|
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    42
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    43
    screenLock := ScreenLock forDevice:Screen current.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    44
    Delay waitForSeconds:1.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    45
    screenLock checkTime.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    46
    Delay waitForSeconds:12.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    47
    screenLock checkTime.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    48
    Delay waitForSeconds:3.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    49
    screenLock unlock.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
    screenLock unlisten.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
                                                                [exEnd]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    52
                                                                [exBegin]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    53
    |screenLock channel running|
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    54
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    55
    screenLock := ScreenLock forDevice:Screen current.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    56
    screenLock lockAfterSeconds:4.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    57
    [
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    58
        channel := false asValue.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    59
        channel onChangeEvaluate:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    60
            channel value ifTrue:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    61
                self information:'Application is locked\\Hit ok to unlock' withCRs.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    62
                channel value:false.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    63
            ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    64
        ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    65
        screenLock lockChannel:channel.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    66
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    67
        [
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    68
            Delay waitForSeconds:2.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    69
            screenLock checkTime.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    70
        ] loop.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    71
    ] valueNowOrOnUnwindDo:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    72
        screenLock unlisten.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    73
    ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    74
                                                                [exEnd]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    75
"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    76
! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    77
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    78
!ScreenLock class methodsFor:'instance creation'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    79
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    80
forDevice:aWorkstation
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    81
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    82
    ^ self new initializeForDevice:aWorkstation
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    83
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    84
! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    85
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    86
!ScreenLock methodsFor:'accessing'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    87
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    88
lockAfterSeconds
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    89
    "return the value of the instance variable 'lockAfterSeconds' (automatically generated)"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    90
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    91
    ^ lockAfterSeconds!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    92
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    93
lockAfterSeconds:something
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    94
    "set the value of the instance variable 'lockAfterSeconds' (automatically generated)"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    95
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    96
    lockAfterSeconds := something.!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    97
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    98
lockChannel
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    99
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   100
    lockChannel isNil ifTrue:[
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   101
        self lockChannel:false asValue.
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   102
    ].
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   103
    ^ lockChannel
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   104
!
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   105
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   106
lockChannel:something
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   107
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   108
    lockChannel notNil ifTrue:[ 
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   109
        lockChannel removeDependent:self.
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   110
    ].
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   111
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   112
    lockChannel := something.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   113
    lockChannel addDependent:self.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   114
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   115
1415
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   116
lockChannelOut
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   117
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   118
    lockChannelOut isNil ifTrue:[
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   119
        lockChannelOut := false asValue.
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   120
    ].
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   121
    ^ lockChannelOut
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   122
!
1415
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   123
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   124
lockChannelOut:something
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   125
    "set the value of the instance variable 'lockChannelOut' (automatically generated)"
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   126
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   127
    lockChannelOut := something.!
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   128
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   129
processor
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   130
    "return the value of the instance variable 'processor' (automatically generated)"
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   131
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   132
    ^ processor!
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   133
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   134
processor:something
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   135
    "set the value of the instance variable 'processor' (automatically generated)"
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   136
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   137
    processor := something.!
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   138
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   139
workstation
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   140
    "return the value of the instance variable 'workstation' (automatically generated)"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   141
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   142
    ^ workstation!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   143
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   144
workstation:something
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   145
    "set the value of the instance variable 'workstation' (automatically generated)"
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   146
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   147
    workstation := something.! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   148
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   149
!ScreenLock methodsFor:'change & update'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   150
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   151
update:aspect with:param from:anObject
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   152
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   153
    |lock|
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   154
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   155
    anObject == lockChannel ifTrue:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   156
        aspect == #value ifTrue:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   157
            "/ lockChannel is a value holder
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   158
            lock := lockChannel value.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   159
        ] ifFalse:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   160
            "/ lockChannel is a block or something else
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   161
            lock := param.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   162
        ].
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   163
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   164
        "lock or unlock the screen
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   165
         If a processor is defined, let the processor perform the unlock,
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   166
         so that posssible Display errors do not affect the sender"
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   167
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   168
        lock == true ifTrue:[
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   169
            processor isNil ifTrue:[
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   170
                self lockScreen.
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   171
            ] ifFalse:[
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   172
                processor enqueueMessage:#lockScreen for:self arguments:#().
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   173
            ].
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   174
        ] ifFalse:[
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   175
            processor isNil ifTrue:[
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   176
                self unlockScreen.
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   177
            ] ifFalse:[
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   178
                processor enqueueMessage:#unlockScreen for:self arguments:#().
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   179
            ].
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   180
        ]
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   181
    ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   182
! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   183
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   184
!ScreenLock methodsFor:'events'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   185
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   186
buttonMotion:state x:x y:y view:aView
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   187
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   188
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   189
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   190
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   191
buttonMultiPress:button x:x y:y view:aView
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   192
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   193
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   194
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   195
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   196
buttonPress:button x:x y:y view:aView
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   197
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   198
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   199
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   200
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   201
buttonRelease:button x:x y:y view:aView
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   202
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   203
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   204
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   205
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   206
keyPress:key x:x y:y view:aView
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   207
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   208
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   209
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   210
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   211
keyRelease:key x:x y:y view:aView
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   212
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   213
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   214
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   215
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   216
mouseWheelMotion:state x:x y:y amount:amount deltaTime:dTime view:aView
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   217
    ^ self gotEventForView:aView.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   218
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   219
! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   220
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   221
!ScreenLock methodsFor:'lock interface'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   222
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   223
checkTime
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   224
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   225
    |now|
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   226
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   227
    lockedViews isNil ifTrue:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   228
        now := AbsoluteTime now.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   229
        lastInactiveTime notNil ifTrue:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   230
            (lastInactiveTime addSeconds:lockAfterSeconds value) < now ifTrue:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   231
                self lock
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   232
            ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   233
        ] ifFalse:[
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   234
            lastInactiveTime := now.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   235
        ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   236
    ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   237
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   238
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   239
lock
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   240
   "trigger locking of screen"
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   241
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   242
    self lockChannel value:true.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   243
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   244
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   245
unlisten
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   246
    "do not listen for events any longer.
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   247
     This must be called when a screen lock is detached from a
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   248
     screen."
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   249
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   250
    workstation removeEventListener:self
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   251
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   252
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   253
unlock
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   254
   "trigger unlocking of screen"
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   255
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   256
    self lockChannel value:false.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   257
! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   258
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   259
!ScreenLock methodsFor:'private'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   260
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   261
gotEventForView:v
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   262
    "got an event.
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   263
     Reset the inactive timer.
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   264
     If locked, eat all user events (for security)"
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   265
1376
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   266
    lockedViews isNil ifTrue:[
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   267
        lastInactiveTime := nil.        
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   268
        ^ false.
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   269
    ].
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   270
    ^ lockedViews includes:v.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   271
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   272
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   273
initializeForDevice:aWorkstation
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   274
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   275
     lockAfterSeconds := 10.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   276
     workstation := aWorkstation.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   277
     workstation addEventListener:self.
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   278
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   279
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   280
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   281
lockScreen
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   282
    "lock the screen"
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   283
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   284
    lockedViews := workstation allViews.
1376
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   285
    hiddenViews := lockedViews select:[:v|
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   286
        v shown and:[
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   287
            v isPopUpView ifTrue:[v hide].
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   288
            v isTopView.
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   289
        ].
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   290
    ].
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   291
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   292
    hiddenViews do:[:v|
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   293
        v beInvisible.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   294
    ].
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   295
1415
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   296
    lockChannelOut notNil ifTrue:[      
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   297
        lockChannelOut value:true.
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   298
    ].
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   299
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   300
!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   301
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   302
unlockScreen
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   303
1376
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   304
    lastInactiveTime := nil.
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   305
    hiddenViews do:[:v|
6294517bece4 Keep date of start of inactivity.
Stefan Vogel <sv@exept.de>
parents: 1374
diff changeset
   306
        v beVisible.
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   307
    ].
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   308
    hiddenViews := lockedViews := nil.
1415
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   309
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   310
    lockChannelOut notNil ifTrue:[      
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   311
        lockChannelOut value:false.
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   312
    ].
fd8738cc4733 Use lockChannelOut to avoid races when locking/unlocking
Stefan Vogel <sv@exept.de>
parents: 1376
diff changeset
   313
1374
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   314
! !
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   315
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   316
!ScreenLock methodsFor:'queries'!
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   317
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   318
isLocked
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   319
881f1ba7ca1e Eat all user generated events if locked.
Stefan Vogel <sv@exept.de>
parents: 1371
diff changeset
   320
    ^ lockedViews notNil
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   321
! !
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   322
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   323
!ScreenLock class methodsFor:'documentation'!
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   324
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   325
version
1416
79f3aee2d64c Add processor (an ApplicationModel), which processes the lock/unlock
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   326
    ^ '$Header: /cvs/stx/stx/libview2/ScreenLock.st,v 1.5 2000-10-02 14:47:03 stefan Exp $'
1371
a022e5804f07 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   327
! !