select output on home context

This commit is contained in:
Djeeberjr 2023-06-30 18:42:23 +02:00
parent 788c839937
commit 2937de86d6

View File

@ -1,5 +1,7 @@
package lib; package lib;
import kernel.peripherals.Screen;
import kernel.peripherals.Peripherals.Peripheral;
import kernel.ps.Process; import kernel.ps.Process;
import kernel.ps.ProcessManager; import kernel.ps.ProcessManager;
import bin.KernelLog; import bin.KernelLog;
@ -23,6 +25,9 @@ class HomeContext {
private var currentWorkspace:Int = -1; private var currentWorkspace:Int = -1;
private var requestRender: Void->Void; private var requestRender: Void->Void;
private var renderer:RootElement; private var renderer:RootElement;
private var selectedOutput:String = "main";
private var selectedOutputIndex:Int = -1;
public function new() {} public function new() {}
@ -71,7 +76,7 @@ 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], "main"); WindowManager.instance.focusContextToOutput(workspaces[id], selectedOutput);
currentWorkspace = id; currentWorkspace = id;
} }
} }
@ -101,7 +106,28 @@ class HomeContext {
if (lastContextID == -1) { if (lastContextID == -1) {
return; return;
} }
focusContext(lastContextID); focusContext(lastContextID);
if (selectedOutputIndex != -1) {
requestRender();
}
}
private function cycleOutput() {
var screenAddr = Peripheral.instance.findAddrByType(Screen.TYPE_NAME);
if (selectedOutputIndex == -1) {
selectedOutputIndex = 0;
selectedOutput = screenAddr[selectedOutputIndex];
} else if (selectedOutputIndex >= screenAddr.length - 1) {
selectedOutputIndex = -1;
selectedOutput = "main";
} else {
selectedOutputIndex++;
selectedOutput = screenAddr[selectedOutputIndex];
}
requestRender();
} }
private function render() { private function render() {
@ -118,6 +144,7 @@ class HomeContext {
children.push(new TextElement('Add Terminal', {onClick: this.spawnPs.bind(new Terminal())})); children.push(new TextElement('Add Terminal', {onClick: this.spawnPs.bind(new Terminal())}));
children.push(new TextElement('Add Log', {onClick: this.spawnPs.bind(new KernelLog())})); children.push(new TextElement('Add Log', {onClick: this.spawnPs.bind(new KernelLog())}));
children.push(new TextElement('Exit', {onClick: KernelEvents.instance.shutdown})); children.push(new TextElement('Exit', {onClick: KernelEvents.instance.shutdown}));
children.push(new TextElement('Output :${selectedOutput}', {onClick: this.cycleOutput}));
renderer.setChildren(children); renderer.setChildren(children);