Skip to content

Commit

Permalink
Another attempt at in and out of focus windows
Browse files Browse the repository at this point in the history
  • Loading branch information
chinonso098 committed Oct 22, 2023
1 parent d895af6 commit 40f3f43
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 108 deletions.
4 changes: 2 additions & 2 deletions src/app/shared/system-service/running.process.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class RunningProcessService{
processListChangeNotify: Subject<void> = new Subject<void>();
closeProcessNotify: Subject<Process> = new Subject<Process>();
focusOnNextProcessNotify: Subject<void> = new Subject<void>();
focusOnCurrentProcessNotify: Subject<unknown[]> = new Subject<unknown[]>();
blurOnCurrentProcessNotify: Subject<unknown[]> = new Subject<unknown[]>();
focusOnCurrentProcessNotify: Subject<number> = new Subject<number>();
focusOutOtherProcessNotify: Subject<number> = new Subject<number>();
restoreOrMinimizeWindowNotify: Subject<number> = new Subject<number>();

constructor(){
Expand Down
2 changes: 1 addition & 1 deletion src/app/system-apps/desktop/desktop.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<main id="vanta" class="main-desktop">
<main id="vanta" class="main-desktop" (click)="onDesktopClick()">
<ng-content> </ng-content>
</main>
5 changes: 5 additions & 0 deletions src/app/system-apps/desktop/desktop.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ export class DesktopComponent implements OnInit, AfterViewInit{
});
}

onDesktopClick():void{
//console.log("Desktop in focus")
}

private getComponentDetail():Process{
return new Process(this.processId, this.name, this.icon, this.hasWindow, this.type)
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<cos-window [runningProcessID]="this.processId" [processAppIcon]="this.icon" [processAppName]="this.name">
<cos-filemanager tabindex="0" id="fileMgrSec" [folderPath]="this.directory" (updateExplorerIconAndName)="updateIconAndName($event)" (focus)="onFocus1($event, this.processId)" (blur)="onBlur1($event, this.processId)">
<cos-filemanager tabindex="0" id="fileMgrSec" [folderPath]="this.directory" (updateExplorerIconAndName)="updateIconAndName($event)" (click)="setFocusOnFEWindow(this.processId)">
</cos-filemanager>
</cos-window>

Expand Down
25 changes: 3 additions & 22 deletions src/app/system-apps/fileexplorer/fileexplorer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,8 @@ export class FileexplorerComponent implements BaseComponent {
return new Process(this.processId, this.name, this.icon, this.hasWindow, this.type)
}

onFocus1(focusEvt:FocusEvent, id:number):void{
// console.log('filexplor focus-event:',focusEvt);
// console.log('id-num:',id)

const evtData:unknown[] = [];
evtData.push(focusEvt);
evtData.push(id)

this._runningProcessService.focusOnCurrentProcessNotify.next(evtData);
}


onBlur1(blurEvt:FocusEvent, id:number):void{
// console.log('filexplor blur-event:',blurEvt);
// console.log('id-num:',id)

const evtData:unknown[] = [];
evtData.push(blurEvt);
evtData.push(id)

this._runningProcessService.blurOnCurrentProcessNotify.next(evtData);
setFocusOnFEWindow(pid:number):void{
// console.log('setFileExploreToFocus:',pid);
this._runningProcessService.focusOnCurrentProcessNotify.next(pid);
}

}
4 changes: 2 additions & 2 deletions src/app/system-apps/window/window.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

<div [ngStyle]="currentStyles" #divWindow tabindex="0" class="section window-dd-box"
ngDraggable (stopped)="onDragEnd($event)"
ngDraggable (stopped)="onDragEnd($event)" (started)="onDragStart(this.processId)"
(rzStop)="onRZStop($event)" ngResizable [rzHandles]="'e,s,w,se,sw'"
[rzMinWidth]="defaultWidthOnOpen" [rzMinHeight]="defaultHeightOnOpen">

<header tabindex="0" id="headerSec" appHighlight
[ngStyle]="headerActiveStyles" (focus)="onFocus($event, this.processId)" (blur)="onBlur($event, this.processId)"
[ngStyle]="headerActiveStyles" (click)="setFocusOnWindow(this.processId)"
(dblclick)="onTitleBarDoubleClick()">
<h1>
<figure>
Expand Down
95 changes: 28 additions & 67 deletions src/app/system-apps/window/window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import { WindowState } from 'src/app/system-files/state/windows.state';
this._stateManagmentService = stateManagmentService;
this._restoreOrMinSub = this._runningProcessService.restoreOrMinimizeWindowNotify.subscribe((p) => {this.restoreHiddenWindow(p)});
this._focusOnNextProcessSub = this._runningProcessService.focusOnNextProcessNotify.subscribe(() => {this.setNextWindowToFocus()});
this._focusOnCurrentProcessSub = this._runningProcessService.focusOnCurrentProcessNotify.subscribe((evt) => {this.setWindowToFocusUsingEvt(evt)});
this._blurOnCurrentProcessSub = this._runningProcessService.blurOnCurrentProcessNotify.subscribe((evt) => {this.setWindowToBlurUsingEvt(evt)});
this._focusOnCurrentProcessSub = this._runningProcessService.focusOnCurrentProcessNotify.subscribe((p) => {this.setFocusOnWindow(p)});
this._blurOnCurrentProcessSub = this._runningProcessService.focusOutOtherProcessNotify.subscribe((p) => {this.removeFocusOnWindow(p)});
}

get getDivWindowElement(): HTMLElement {
Expand Down Expand Up @@ -224,6 +224,10 @@ import { WindowState } from 'src/app/system-files/state/windows.state';
}
}

onDragStart(pid:number){
this.setFocusOnWindow(pid);
}

onRZStop(input:any){
const height = Number(input.size.height);
const width = Number(input.size.width);
Expand All @@ -241,84 +245,40 @@ import { WindowState } from 'src/app/system-files/state/windows.state';
this._runningProcessService.focusOnNextProcessNotify.next();
}

setWindowToFocusUsingEvt(eventData:unknown[]):void{
setFocusOnWindow(pid:number):void{
/**
* If you want to make a non-focusable element focusable,
* you must add a tabindex attribute to it. And divs falls into the category non-focusable elements .
*/
//console.log('set window to focus evt from filmgr:',eventData)//TBD
//const focusEvt:FocusEvent = eventData[0] as FocusEvent;
const pid:number = eventData[1] as number;

if(this.processId == pid){
this.setHeaderActive(pid);
this.setWindowToFocusById(pid);
}
}

onFocus(focusEvt:FocusEvent, pid:number):void{
//console.log('This is focusEvt from window:', focusEvt); //TBD

this._runningProcessService.focusOutOtherProcessNotify.next(pid);

if(this.processId == pid){
this.headerActiveStyles = {
'background-color':'blue'
};
this.setWindowToFocusById(pid);
this.setHeaderActive(pid);
this.setWindowToFocusById(pid);
}
}

setWindowToBlurUsingEvt(eventData:unknown[]):void{
/**
* If you want to make a non-focusable element focusable,
* you must add a tabindex attribute to it. And divs falls into the category non-focusable elements .
*/
//console.log('set window to blur evt from filmgr:',eventData) //TBD
//const focusEvt:FocusEvent = eventData[0] as FocusEvent;
const pid:number = eventData[1] as number;

if(this.processId == pid){
this.setHeaderInActive(pid);
}
}
/**
* the pid of the current window currently in focus is passed. if the pid of other windows do not match,
* then they are set out of focus
*/
removeFocusOnWindow(pid:number):void{
const processWithWindows = this._runningProcessService.getProcesses().filter(p => p.getHasWindow == true && p.getProcessId != pid);

onBlur(blurEvt:FocusEvent, pid:number):void{
//console.log('This is blurEvt from window:', blurEvt); //TBD
const targetList:string[] = ['closeBtn', 'hideBtn', 'minMaxBtn', 'fileMgrSec'];
for (let i=0; i < processWithWindows.length; i++){
const process = processWithWindows[i];
const window = this._stateManagmentService.getState(process.getProcessId) as WindowState;

if(this.processId == pid){

const target = blurEvt.target as HTMLElement;
const cTarget = blurEvt.currentTarget as HTMLElement;
const rTarget = blurEvt.relatedTarget as HTMLElement;

if(target !== null){
if (target.id === 'headerSec' && rTarget == null) {
this.setHeaderInActive(pid);
}else if (target.id === 'headerSec' && targetList.indexOf(rTarget.id) !== -1){
this.setHeaderActive(pid);

if(rTarget.id === 'closeBtn'){
//console.log('chnage closeBtn color') TBD
this.setBtnFocus(pid)
}
}else
this.setHeaderInActive(pid);
}
else if(rTarget == null || rTarget.id !== 'fileMgrSec' ){
this.setHeaderInActive(pid);
}else{
blurEvt.stopPropagation();
blurEvt.preventDefault();
if(window != undefined && window.getIsVisible){
this.setHeaderInActive(window.getPid);
}
}
}
}


setWindowToFocusById(pid:number):void{
/**
* If you want to make a non-focusable element focusable,
* you must add a tabindex attribute to it. And divs falls into the category non-focusable elements .
*/
//console.log('set window to focus:',pid) //TBD

let z_index = this._stateManagmentService.getState(this.z_index) as number;
const windowState = this._stateManagmentService.getState(pid) as WindowState;

Expand All @@ -333,18 +293,19 @@ import { WindowState } from 'src/app/system-files/state/windows.state';
this.currentStyles = {
'z-index':z_index
};
this.setHeaderActive(pid);
}
}

setNextWindowToFocus():void{
//console.log('just checking')

const processWithWindows = this._runningProcessService.getProcesses().filter(p => p.getHasWindow == true);

for (let i=0; i < processWithWindows.length; i++){
const process = processWithWindows[i];
const window = this._stateManagmentService.getState(process.getProcessId) as WindowState;

console.log("setNextWindowToFocus:", window);
//console.log("setNextWindowToFocus:", window);

if(window != undefined && window.getIsVisible){
//console.log('process:',process.getProcessId +'----'+process.getProcessName); //TBD
Expand Down
2 changes: 1 addition & 1 deletion src/app/user-apps/title/title.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(@openClose.start)="onAnimationEvent($event)"
(@openClose.done)="onAnimationEvent($event)">

<cos-window [runningProcessID]="this.processId" [processAppIcon]="this.icon" [processAppName]="this.name">
<cos-window [runningProcessID]="this.processId" [processAppIcon]="this.icon" [processAppName]="this.name" (click)="setFileExploreToFocus(this.processId)">
<p class="title"> Hello, World! </p>
</cos-window>

Expand Down
27 changes: 15 additions & 12 deletions src/app/user-apps/title/title.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,29 @@ export class TitleComponent implements BaseComponent{
}


setFileExploreToFocus(pid:number):void{
this._runningProcessService.focusOnCurrentProcessNotify.next(pid);
}

onAnimationEvent(event: AnimationEvent) {

// openClose is trigger name in this example
console.warn(`Animation Trigger: ${event.triggerName}`);
// // openClose is trigger name in this example
// console.warn(`Animation Trigger: ${event.triggerName}`);

// phaseName is "start" or "done"
console.warn(`Phase: ${event.phaseName}`);
// // phaseName is "start" or "done"
// console.warn(`Phase: ${event.phaseName}`);

// in our example, totalTime is 1000 (number of milliseconds in a second)
console.warn(`Total time: ${event.totalTime}`);
// // in our example, totalTime is 1000 (number of milliseconds in a second)
// console.warn(`Total time: ${event.totalTime}`);

// in our example, fromState is either "open" or "closed"
console.warn(`From: ${event.fromState}`);
// // in our example, fromState is either "open" or "closed"
// console.warn(`From: ${event.fromState}`);

// in our example, toState either "open" or "closed"
console.warn(`To: ${event.toState}`);
// // in our example, toState either "open" or "closed"
// console.warn(`To: ${event.toState}`);

// the HTML element itself, the button in this case
console.warn(`Element: ${event.element}`);
// // the HTML element itself, the button in this case
// console.warn(`Element: ${event.element}`);
}

private getComponentDetail():Process{
Expand Down

0 comments on commit 40f3f43

Please sign in to comment.