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
```haxe
var ctx = WindowManager.instance.createNewBufferedContext();
var ctx = WindowManager.createNewBufferedContext();
ctx.setCursorPos(0, 0);
ctx.setCursorBlink(false);
ctx.setBackgroundColor(Blue);

View File

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

View File

@ -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;
}

View File

@ -14,12 +14,11 @@ class WindowManager {
/**
Depends on: KernelEvents, Peripheral
**/
public static var instance:WindowManager;
private var currentMainContext:WindowContext;
private final outputMap:Map<String, WindowContext> = new Map();
private static var currentMainContext:WindowContext;
private static final outputMap:Map<String, WindowContext> = 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<String> {
public static function getOutputs():ReadOnlyArray<String> {
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<WindowContext> {
public static function getContextByPID(pid: PID): ReadOnlyArray<WindowContext> {
var handle = ProcessManager.getProcess(pid);
if (handle == null) {
return [];

View File

@ -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);
}