ViewerProcessesImpl.mesa; written by S. McGregor
Edited by McGregor on July 13, 1983 4:16 pm
Last Edited by: Maxwell, May 24, 1983 8:06 am
Last Edited by: Pausch, August 26, 1983 12:18 pm
DIRECTORY
Buttons USING [Create],
CedarInitOps USING [Seconds, Sleep],
CedarSnapshot USING [CheckpointProc, Register, RollbackProc],
ClassIncreek USING [ActionBody, GetAction, Increek, IncreekError, NewStdIncreek, SetAtLatest],
Cursors USING [CursorType, SetCursor],
Interminal USING [KeyState],
Menus USING [Entry, EntryNotifyRecord],
Process USING [Abort, Detach, Pause, priorityForeground, Seconds, SecondsToTicks, SetPriority],
Rope USING [ROPE],
UserProfile USING [Number],
UserTerminal USING [keyboard],
ViewerClasses USING [NotifyProc, Viewer],
ViewerOps USING [EnumerateViewers, EnumProc, PaintViewer, SaveAllEdits];
ViewerProcessesImpl: CEDAR MONITOR
IMPORTS Buttons, CedarSnapshot, CedarInitOps, ClassIncreek, Cursors, Process, UserProfile, UserTerminal, ViewerOps =
BEGIN
EmergencySaveAllEdits: PROC = TRUSTED BEGIN
keys: LONG POINTER TO Interminal.KeyState = LOOPHOLE[UserTerminal.keyboard];
PaintCaption: ViewerOps.EnumProc = TRUSTED BEGIN
ViewerOps.PaintViewer[v, caption];
END;
Process.SetPriority[Process.priorityForeground];
DO-- forever
Process.Pause[Process.SecondsToTicks[1]];
IF --keys.bits[Lock]=down AND-- keys.bits[LeftShift]=down AND keys.bits[RightShift]=down AND keys.bits[Spare3]=down THEN BEGIN
Cursors.SetCursor[activate];
ViewerOps.SaveAllEdits[];
Cursors.SetCursor[textPointer];
ViewerOps.EnumerateViewers[PaintCaption]; -- ok if this doesn't finish
END;
ENDLOOP;
END;
idleProcess: PROCESSNIL;
AutoIdle: PROC = TRUSTED BEGIN
ENABLE ANY => GOTO Punt; -- punt if bad number or ABORTED
increek: ClassIncreek.Increek;
action: ClassIncreek.ActionBody;
idleTime: Process.Seconds;
powerOff: CedarInitOps.Seconds;
idleTime ← 60 * UserProfile.Number[key: "AutoIdle.Timeout", default: 20];
powerOff ← 60 * UserProfile.Number[key: "AutoIdle.PowerOff", default: 0];
IF idleTime<=0 THEN RETURN;
increek ← ClassIncreek.NewStdIncreek[];
DO-- forever
ClassIncreek.SetAtLatest[increek];
Process.Pause[Process.SecondsToTicks[idleTime]];
action ← ClassIncreek.GetAction[increek, dontWait, ----, clicksAndMotion
! ClassIncreek.IncreekError => LOOP];
WITH a: action SELECT FROM
timedOut => CedarInitOps.Sleep[powerOff: powerOff]; -- idle
ENDCASE;
ENDLOOP;
EXITS Punt => NULL;
END;
IdleOn: CedarSnapshot.RollbackProc = BEGIN
idleProcess ← FORK AutoIdle[];
END;
IdleOff: CedarSnapshot.CheckpointProc = TRUSTED BEGIN
Process.Abort[idleProcess];
JOIN idleProcess;
idleProcess ← NIL;
END;
IdleProc: ViewerClasses.NotifyProc = {
[self: Viewer, input: LIST OF REF ANY]
TRUSTED {Process.Detach[FORK CedarInitOps.Sleep[]]};
};
myNotifyRecord: Menus.EntryNotifyRecord ~ [trigger: LIST[all], notifyData: LIST[$Idle]];
myEntry: Menus.Entry ~ [name: "Idle", actions: LIST[myNotifyRecord] ];
[] ← Buttons.Create[entry: myEntry, proc: IdleProc];
TRUSTED {Process.Detach[FORK EmergencySaveAllEdits[]]};
TRUSTED {CedarSnapshot.Register[IdleOff, IdleOn]; IdleOn[rollback]};
END.