made WindowManager a static class

This commit is contained in:
Djeeberjr 2023-07-27 20:41:23 +02:00
parent 9deea0ee98
commit 74d0232160
5 changed files with 18 additions and 19 deletions

View File

@ -73,7 +73,7 @@ They both can be used just like the [nativ implmentation](https://tweaked.cc/mod
## Usage ## Usage
```haxe ```haxe
var ctx = WindowManager.instance.createNewBufferedContext(); var ctx = WindowManager.createNewBufferedContext();
ctx.setCursorPos(0, 0); ctx.setCursorPos(0, 0);
ctx.setCursorBlink(false); ctx.setCursorBlink(false);
ctx.setBackgroundColor(Blue); ctx.setBackgroundColor(Blue);

View File

@ -27,7 +27,7 @@ class Init {
Log.init(); Log.init();
KernelEvents.init(); KernelEvents.init();
WindowManager.instance = new WindowManager(); WindowManager.init();
MainTerm.instance = new MainTerm(); MainTerm.instance = new MainTerm();
BinStore.instance = new BinStore(); BinStore.instance = new BinStore();

View File

@ -63,13 +63,13 @@ class ProcessHandle {
} }
public function createBufferdWindowContext(): WindowContext { public function createBufferdWindowContext(): WindowContext {
var ctx = WindowManager.instance.createNewContext(); var ctx = WindowManager.createNewContext();
this.windowContexts.push(ctx); this.windowContexts.push(ctx);
return ctx; return ctx;
} }
public function createStatelessWindowContext(): {ctx:WindowContext, setRenderFunc: (() -> Void) -> Void, requestRender:() -> Void} { public function createStatelessWindowContext(): {ctx:WindowContext, setRenderFunc: (() -> Void) -> Void, requestRender:() -> Void} {
var ctx = WindowManager.instance.createNewStatelessContext(); var ctx = WindowManager.createNewStatelessContext();
this.windowContexts.push(ctx.ctx); this.windowContexts.push(ctx.ctx);
return ctx; return ctx;
} }

View File

@ -14,12 +14,11 @@ class WindowManager {
/** /**
Depends on: KernelEvents, Peripheral Depends on: KernelEvents, Peripheral
**/ **/
public static var instance:WindowManager; private static var currentMainContext:WindowContext;
private var currentMainContext:WindowContext; private static final outputMap:Map<String, WindowContext> = new Map();
private final outputMap:Map<String, WindowContext> = new Map();
@:allow(kernel.Init) @:allow(kernel.Init)
private function new() { private static function init() {
KernelEvents.onKey.handle(params -> { KernelEvents.onKey.handle(params -> {
if (currentMainContext != null) { if (currentMainContext != null) {
if (currentMainContext.eventDelegate != null){ if (currentMainContext.eventDelegate != null){
@ -116,24 +115,24 @@ class WindowManager {
/** /**
Same as createNewBufferedContext because it is the most simple context. Same as createNewBufferedContext because it is the most simple context.
**/ **/
public function createNewContext():WindowContext { public static function createNewContext():WindowContext {
return createNewBufferedContext(); return createNewBufferedContext();
} }
public function createNewBufferedContext():WindowContext { public static function createNewBufferedContext():WindowContext {
var newContext = new WindowContext(new BufferedVirtualTermWriter()); var newContext = new WindowContext(new BufferedVirtualTermWriter());
return newContext; 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 writer = new StatelessVirtualTermWriter();
var newContext = new WindowContext(writer); var newContext = new WindowContext(writer);
return {ctx: newContext, setRenderFunc: writer.setRenderFunc, requestRender: writer.requestRender}; return {ctx: newContext, setRenderFunc: writer.setRenderFunc, requestRender: writer.requestRender};
} }
public function getOutputs():ReadOnlyArray<String> { public static function getOutputs():ReadOnlyArray<String> {
var arr = Peripheral.getAllScreens().map(screen -> return screen.getAddr()); var arr = Peripheral.getAllScreens().map(screen -> return screen.getAddr());
arr.push("main"); arr.push("main");
return arr; return arr;
@ -142,7 +141,7 @@ class WindowManager {
/** /**
Move context to output. If output is "main", context will be moved to main screen. 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; var target:TermWriteable;
if (output == "main") { if (output == "main") {
target = MainTerm.instance; target = MainTerm.instance;
@ -165,7 +164,7 @@ class WindowManager {
context.enable(); context.enable();
} }
public function getContextByPID(pid: PID): ReadOnlyArray<WindowContext> { public static function getContextByPID(pid: PID): ReadOnlyArray<WindowContext> {
var handle = ProcessManager.getProcess(pid); var handle = ProcessManager.getProcess(pid);
if (handle == null) { if (handle == null) {
return []; return [];

View File

@ -41,10 +41,10 @@ class HomeContext {
public function run() { public function run() {
// Create main terminal context // Create main terminal context
var stateless = WindowManager.instance.createNewStatelessContext(); var stateless = WindowManager.createNewStatelessContext();
ctx = stateless.ctx; ctx = stateless.ctx;
requestRender = stateless.requestRender; requestRender = stateless.requestRender;
WindowManager.instance.focusContextToOutput(ctx, "main"); WindowManager.focusContextToOutput(ctx, "main");
renderer = new RootElement(); renderer = new RootElement();
renderer.setTitle("Home"); renderer.setTitle("Home");
@ -85,14 +85,14 @@ class HomeContext {
private function focusContext(id:Int) { private function focusContext(id:Int) {
if (workspaces.exists(id)) { if (workspaces.exists(id)) {
WindowManager.instance.focusContextToOutput(workspaces[id], selectedOutput); WindowManager.focusContextToOutput(workspaces[id], selectedOutput);
currentWorkspace = id; currentWorkspace = id;
} }
} }
private function focusMainTerm() { private function focusMainTerm() {
requestRender(); requestRender();
WindowManager.instance.focusContextToOutput(ctx, "main"); WindowManager.focusContextToOutput(ctx, "main");
currentWorkspace = -1; currentWorkspace = -1;
} }
@ -116,7 +116,7 @@ class HomeContext {
var pid = ProcessManager.run(ps, {}); var pid = ProcessManager.run(ps, {});
var lastContextID = -1; var lastContextID = -1;
for ( ctx in WindowManager.instance.getContextByPID(pid)){ for ( ctx in WindowManager.getContextByPID(pid)){
lastContextID = addContextNextWorkspace(ctx); lastContextID = addContextNextWorkspace(ctx);
} }