VisibleMouseClicksImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Peter Kessler, May 15, 1986 12:32:58 pm PDT
DIRECTORY
ClassIncreek USING [ActionBody, ActionKind, GetAction, GetPositionFrom, Increek, NewStdIncreek, Release, ViewPosition],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
Cursors USING [CursorType, NewCursor, SetCursor],
Interminal USING [KeyState],
Process USING [Detach],
Rope USING [Equal, ROPE],
TerminalDefs USING [KeyName],
VisibleMouseClicks USING [Visibility];
VisibleMouseClicksImpl: CEDAR MONITOR
IMPORTS ClassIncreek, Commander, CommandTool, Cursors, Process, Rope
EXPORTS VisibleMouseClicks
= {
this is the global state of the monitor. It is only altered by the On and Off procedures.
visibility: VisibleMouseClicks.Visibility ← off;
entry procedures
On: PUBLIC ENTRY PROCEDURE [] RETURNS [was: VisibleMouseClicks.Visibility] = {
was ← visibility;
SELECT visibility FROM
on => {
NULL;
};
off => {
visibility ← on;
TRUSTED {
Process.Detach[FORK ReadMouseClicks[]];
};
};
ENDCASE => ERROR;
};
Off: PUBLIC ENTRY PROCEDURE [] RETURNS [was: VisibleMouseClicks.Visibility] = {
was ← visibility;
SELECT visibility FROM
on => {
visibility ← off;
};
off => {
NULL;
};
ENDCASE => ERROR;
};
internal procedures
ReadMouseClicks: PROCEDURE [] RETURNS [] = {
this gets forked to watch for mouse clicks
increek: ClassIncreek.Increek;
viewPosition: ClassIncreek.ViewPosition;
actionBody: ClassIncreek.ActionBody;
TRUSTED {
increek ← ClassIncreek.NewStdIncreek[NIL];
open an new increek
viewPosition ← ClassIncreek.GetPositionFrom[increek];
get a pointer to its ViewPosition
};
UNTIL visibility = off DO
TRUSTED {
actionBody ← ClassIncreek.GetAction[self: increek, acceptance: clicks];
this pauses for at least a while!
};
IF visibility = on THEN {
WITH action: actionBody SELECT FROM
keyDown => {
SELECT action.value FROM
Red => {
SELECT GetCtrlShiftState[viewPosition.keyState] FROM
neither => Cursors.SetCursor[neitherRed];
ctrl => Cursors.SetCursor[ctrlRed];
shift => Cursors.SetCursor[shiftRed];
ctrlShift => Cursors.SetCursor[ctrlShiftRed];
ENDCASE => ERROR;
};
Yellow => {
SELECT GetCtrlShiftState[viewPosition.keyState] FROM
neither => Cursors.SetCursor[neitherYellow];
ctrl => Cursors.SetCursor[ctrlYellow];
shift => Cursors.SetCursor[shiftYellow];
ctrlShift => Cursors.SetCursor[ctrlShiftYellow];
ENDCASE => ERROR;
};
Blue => {
SELECT GetCtrlShiftState[viewPosition.keyState] FROM
neither => Cursors.SetCursor[neitherBlue];
ctrl => Cursors.SetCursor[ctrlBlue];
shift => Cursors.SetCursor[shiftBlue];
ctrlShift => Cursors.SetCursor[ctrlShiftBlue];
ENDCASE => ERROR;
};
ENDCASE => {
NULL;
};
};
keyUp => {
NULL;
until i figure out what to do.
};
allUp => {
NULL;
until i figure out what to do.
};
ENDCASE =>
NULL;
};
ENDLOOP;
TRUSTED {
increek ← ClassIncreek.Release[increek];
};
};
utilities
ctrlShiftState: TYPE = { neither, ctrl, shift, ctrlShift };
GetCtrlShiftState: PROCEDURE [keyState: Interminal.KeyState] RETURNS [ctrlShiftState] = {
IF keyState.bits[LeftShift] = down OR keyState.bits[RightShift] = down
THEN
IF keyState.bits[Ctrl] = down OR keyState.bits[Spare3] = down
THEN
RETURN [ctrlShift]
ELSE
RETURN [shift]
ELSE
IF keyState.bits[Ctrl] = down OR keyState.bits[Spare3] = down
THEN
RETURN [ctrl]
ELSE
RETURN [neither]
};
initialization procedures, etc.
Init: PROCEDURE [] RETURNS [] = {
Commander.Register[key: "VisibleMouseClicks", proc: VisibleMouseClicksCommand, doc: "on => enable visible mouse clicks, off => disable visible mouse clicks", clientData: NIL, interpreted: TRUE];
};
VisibleMouseClicksCommand: Commander.CommandProc = {
argv: CommandTool.ArgumentVector;
argv ← CommandTool.Parse[cmd: cmd
! CommandTool.Failed => { GO TO Failed; }];
SELECT argv.argc FROM
2 => {
SELECT TRUE FROM
Rope.Equal[s1: argv[1], s2: "on", case: FALSE] => {
IF On[] = on
THEN
msg ← "VisibleMouseClicks already on"
ELSE
msg ← NIL;
};
Rope.Equal[s1: argv[1], s2: "off", case: FALSE] => {
IF Off[] = off
THEN
msg ← "VisibleMouseClicks already off"
ELSE
msg ← NIL;
};
ENDCASE => {
msg ← "VisibleMouseClicks {on | off}";
};
};
ENDCASE => {
SELECT visibility FROM
on => {
msg ← "VisibleMouseClicks {on | off} -- currently on";
};
off => {
msg ← "VisibleMouseClicks {on | off} -- currently off";
};
ENDCASE => {
msg ← "VisibleMouseClicks {on | off}";
};
};
EXITS
Failed => {
result ← $Failure;
msg ← "failed";
};
};
some more global state, but probably read only
what a pain that you can't construct cursors on the fly, but have to precompute them and make them into Cursor.CursorType's.
neitherRed: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
027250B,
027250B,
027250B,
027250B,
027250B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
037770B]];
ctrlRed: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
167250B,
167250B,
167250B,
167250B,
167250B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
037770B]];
shiftRed: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
027250B,
027250B,
027250B,
027250B,
027250B,
020010B,
020010B,
160010B,
160010B,
160010B,
160010B,
160010B,
020010B,
037770B]];
ctrlShiftRed: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
167250B,
167250B,
167250B,
167250B,
167250B,
020010B,
020010B,
160010B,
160010B,
160010B,
160010B,
160010B,
020010B,
037770B]];
neitherYellow: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
025650B,
025650B,
025650B,
025650B,
025650B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
037770B]];
ctrlYellow: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
165650B,
165650B,
165650B,
165650B,
165650B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
037770B]];
shiftYellow: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
025650B,
025650B,
025650B,
025650B,
025650B,
020010B,
020010B,
160010B,
160010B,
160010B,
160010B,
160010B,
020010B,
037770B]];
ctrlShiftYellow: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
165650B,
165650B,
165650B,
165650B,
165650B,
020010B,
020010B,
160010B,
160010B,
160010B,
160010B,
160010B,
020010B,
037770B]];
neitherBlue: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
025350B,
025350B,
025350B,
025350B,
025350B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
037770B]];
ctrlBlue: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
165350B,
165350B,
165350B,
165350B,
165350B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
020010B,
037770B]];
shiftBlue: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
025350B,
025350B,
025350B,
025350B,
025350B,
020010B,
020010B,
160010B,
160010B,
160010B,
160010B,
160010B,
020010B,
037770B]];
ctrlShiftBlue: Cursors.CursorType ← Cursors.NewCursor[bits: [
037770B,
020010B,
165350B,
165350B,
165350B,
165350B,
165350B,
020010B,
020010B,
160010B,
160010B,
160010B,
160010B,
160010B,
020010B,
037770B]];
initialization
Init[];
}.