package kernel.ui; import lib.TermWriteable; import kernel.peripherals.Peripherals.Peripheral; class WindowManager { 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 = new Array(); private final outputMap:Map = 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 { 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(); } }