From 74d02321609ab9f397f3fad83a40a27428118a55 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Thu, 27 Jul 2023 20:41:23 +0200 Subject: [PATCH] made WindowManager a static class --- doc/Concepts.md | 2 +- src/kernel/Init.hx | 2 +- src/kernel/ps/ProcessHandle.hx | 4 ++-- src/kernel/ui/WindowManager.hx | 19 +++++++++---------- src/lib/HomeContext.hx | 10 +++++----- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/doc/Concepts.md b/doc/Concepts.md index b17c4e3..4bdaf1c 100644 --- a/doc/Concepts.md +++ b/doc/Concepts.md @@ -73,7 +73,7 @@ They both can be used just like the [nativ implmentation](https://tweaked.cc/mod ## Usage ```haxe -var ctx = WindowManager.instance.createNewBufferedContext(); +var ctx = WindowManager.createNewBufferedContext(); ctx.setCursorPos(0, 0); ctx.setCursorBlink(false); ctx.setBackgroundColor(Blue); diff --git a/src/kernel/Init.hx b/src/kernel/Init.hx index 877f3e0..824eaf6 100644 --- a/src/kernel/Init.hx +++ b/src/kernel/Init.hx @@ -27,7 +27,7 @@ class Init { Log.init(); KernelEvents.init(); - WindowManager.instance = new WindowManager(); + WindowManager.init(); MainTerm.instance = new MainTerm(); BinStore.instance = new BinStore(); diff --git a/src/kernel/ps/ProcessHandle.hx b/src/kernel/ps/ProcessHandle.hx index 7adcadf..c707cf6 100644 --- a/src/kernel/ps/ProcessHandle.hx +++ b/src/kernel/ps/ProcessHandle.hx @@ -63,13 +63,13 @@ class ProcessHandle { } public function createBufferdWindowContext(): WindowContext { - var ctx = WindowManager.instance.createNewContext(); + var ctx = WindowManager.createNewContext(); this.windowContexts.push(ctx); return ctx; } public function createStatelessWindowContext(): {ctx:WindowContext, setRenderFunc: (() -> Void) -> Void, requestRender:() -> Void} { - var ctx = WindowManager.instance.createNewStatelessContext(); + var ctx = WindowManager.createNewStatelessContext(); this.windowContexts.push(ctx.ctx); return ctx; } diff --git a/src/kernel/ui/WindowManager.hx b/src/kernel/ui/WindowManager.hx index f049a4c..6772048 100644 --- a/src/kernel/ui/WindowManager.hx +++ b/src/kernel/ui/WindowManager.hx @@ -14,12 +14,11 @@ class WindowManager { /** Depends on: KernelEvents, Peripheral **/ - public static var instance:WindowManager; - private var currentMainContext:WindowContext; - private final outputMap:Map = new Map(); + private static var currentMainContext:WindowContext; + private static final outputMap:Map = new Map(); @:allow(kernel.Init) - private function new() { + private static function init() { KernelEvents.onKey.handle(params -> { if (currentMainContext != null) { if (currentMainContext.eventDelegate != null){ @@ -116,24 +115,24 @@ class WindowManager { /** Same as createNewBufferedContext because it is the most simple context. **/ - public function createNewContext():WindowContext { + public static function createNewContext():WindowContext { return createNewBufferedContext(); } - public function createNewBufferedContext():WindowContext { + public static function createNewBufferedContext():WindowContext { var newContext = new WindowContext(new BufferedVirtualTermWriter()); return newContext; } - public function createNewStatelessContext():{ctx:WindowContext, setRenderFunc:(() -> Void) -> Void, requestRender:Void->Void} { + public static function createNewStatelessContext():{ctx:WindowContext, setRenderFunc:(() -> Void) -> Void, requestRender:Void->Void} { var writer = new StatelessVirtualTermWriter(); var newContext = new WindowContext(writer); return {ctx: newContext, setRenderFunc: writer.setRenderFunc, requestRender: writer.requestRender}; } - public function getOutputs():ReadOnlyArray { + public static function getOutputs():ReadOnlyArray { var arr = Peripheral.getAllScreens().map(screen -> return screen.getAddr()); arr.push("main"); return arr; @@ -142,7 +141,7 @@ class WindowManager { /** Move context to output. If output is "main", context will be moved to main screen. **/ - public function focusContextToOutput(context:WindowContext, output:String) { + public static function focusContextToOutput(context:WindowContext, output:String) { var target:TermWriteable; if (output == "main") { target = MainTerm.instance; @@ -165,7 +164,7 @@ class WindowManager { context.enable(); } - public function getContextByPID(pid: PID): ReadOnlyArray { + public static function getContextByPID(pid: PID): ReadOnlyArray { var handle = ProcessManager.getProcess(pid); if (handle == null) { return []; diff --git a/src/lib/HomeContext.hx b/src/lib/HomeContext.hx index bc95404..d04bfe8 100644 --- a/src/lib/HomeContext.hx +++ b/src/lib/HomeContext.hx @@ -41,10 +41,10 @@ class HomeContext { public function run() { // Create main terminal context - var stateless = WindowManager.instance.createNewStatelessContext(); + var stateless = WindowManager.createNewStatelessContext(); ctx = stateless.ctx; requestRender = stateless.requestRender; - WindowManager.instance.focusContextToOutput(ctx, "main"); + WindowManager.focusContextToOutput(ctx, "main"); renderer = new RootElement(); renderer.setTitle("Home"); @@ -85,14 +85,14 @@ class HomeContext { private function focusContext(id:Int) { if (workspaces.exists(id)) { - WindowManager.instance.focusContextToOutput(workspaces[id], selectedOutput); + WindowManager.focusContextToOutput(workspaces[id], selectedOutput); currentWorkspace = id; } } private function focusMainTerm() { requestRender(); - WindowManager.instance.focusContextToOutput(ctx, "main"); + WindowManager.focusContextToOutput(ctx, "main"); currentWorkspace = -1; } @@ -116,7 +116,7 @@ class HomeContext { var pid = ProcessManager.run(ps, {}); var lastContextID = -1; - for ( ctx in WindowManager.instance.getContextByPID(pid)){ + for ( ctx in WindowManager.getContextByPID(pid)){ lastContextID = addContextNextWorkspace(ctx); }