2021-12-20 00:55:30 +00:00
|
|
|
package kernel.ui;
|
|
|
|
|
|
|
|
import lib.TermWriteable;
|
|
|
|
import kernel.peripherals.Peripherals.Peripheral;
|
|
|
|
|
|
|
|
class WindowManager {
|
2022-02-21 14:35:37 +00:00
|
|
|
public static var instance:WindowManager;
|
|
|
|
|
|
|
|
@:allow(kernel.Init)
|
|
|
|
private function new() {
|
|
|
|
KernelEvents.instance.onKey.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.keyTrigger.trigger(params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.keyUpTrigger.trigger(keyCode);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseClick.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.clickTrigger.trigger(params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseDrag.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.mouseDragTrigger.trigger(params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseScroll.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.mouseScrollTrigger.trigger(params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseUp.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.mouseUpTrigger.trigger(params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onPaste.handle(text -> {
|
|
|
|
if (currentMainContext != null) {
|
|
|
|
currentMainContext.pasteTrigger.trigger(text);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMonitorTouch.handle(params -> {
|
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private var currentMainContext:WindowContext;
|
|
|
|
private final allContexts:Array<WindowContext> = new Array();
|
|
|
|
private final outputMap:Map<String, WindowContext> = new Map();
|
|
|
|
|
|
|
|
public function createNewContext():WindowContext {
|
|
|
|
var newContext = new WindowContext(new VirtualTermWriter());
|
|
|
|
|
|
|
|
allContexts.push(newContext);
|
|
|
|
|
|
|
|
// newContext.setTarget(MainTerm.instance);
|
|
|
|
newContext.enable();
|
|
|
|
currentMainContext = newContext;
|
|
|
|
|
|
|
|
return newContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOutputs():Array<String> {
|
|
|
|
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
|
|
|
|
arr.push("main");
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function focusContextToOutput(context:WindowContext, output:String) {
|
|
|
|
var target:TermWriteable;
|
|
|
|
if (output == "main") {
|
|
|
|
target = MainTerm.instance;
|
|
|
|
} else {
|
|
|
|
target = Peripheral.instance.getScreen(output);
|
|
|
|
|
|
|
|
if (target == null) {
|
|
|
|
// output target not found
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputMap.exists(output)) {
|
|
|
|
outputMap[output].disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
outputMap[output] = context;
|
|
|
|
context.setTarget(target);
|
|
|
|
context.enable();
|
|
|
|
}
|
2022-02-21 14:17:38 +00:00
|
|
|
}
|