mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-09-11 00:15:37 +03:00
refactor: interface for window store
This commit is contained in:
parent
48249751ff
commit
bb48ebe643
@ -16,7 +16,7 @@ import { Rect } from "../util/rect";
|
|||||||
import TileLayout from "./layout/tile_layout";
|
import TileLayout from "./layout/tile_layout";
|
||||||
import LayoutStore from "./layout_store";
|
import LayoutStore from "./layout_store";
|
||||||
import { EngineWindow, WindowState } from "./window";
|
import { EngineWindow, WindowState } from "./window";
|
||||||
import WindowStore from "./window_store";
|
import { WindowStore } from "./window_store";
|
||||||
|
|
||||||
describe("arrange", () => {
|
describe("arrange", () => {
|
||||||
it("happens on all screens", () => {
|
it("happens on all screens", () => {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import MonocleLayout from "./layout/monocle_layout";
|
import MonocleLayout from "./layout/monocle_layout";
|
||||||
|
|
||||||
import LayoutStore from "./layout_store";
|
import LayoutStore from "./layout_store";
|
||||||
import WindowStore from "./window_store";
|
import { WindowStore, WindowStoreImpl } from "./window_store";
|
||||||
import { EngineWindow, EngineWindowImpl, WindowState } from "./window";
|
import { EngineWindow, EngineWindowImpl, WindowState } from "./window";
|
||||||
|
|
||||||
import { Controller } from "../controller";
|
import { Controller } from "../controller";
|
||||||
@ -177,7 +177,7 @@ export class EngineImpl implements Engine {
|
|||||||
private log: Log
|
private log: Log
|
||||||
) {
|
) {
|
||||||
this.layouts = new LayoutStore(this.config);
|
this.layouts = new LayoutStore(this.config);
|
||||||
this.windows = new WindowStore();
|
this.windows = new WindowStoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public adjustLayout(basis: EngineWindow): void {
|
public adjustLayout(basis: EngineWindow): void {
|
||||||
@ -557,7 +557,7 @@ export class EngineImpl implements Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setMaster(window: EngineWindow): void {
|
public setMaster(window: EngineWindow): void {
|
||||||
this.windows.setMaster(window);
|
this.windows.putWindowToMaster(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cycleLayout(step: Step): void {
|
public cycleLayout(step: Step): void {
|
||||||
|
@ -7,12 +7,74 @@ import { EngineWindow } from "./window";
|
|||||||
|
|
||||||
import { DriverSurface } from "../driver/surface";
|
import { DriverSurface } from "../driver/surface";
|
||||||
|
|
||||||
export default class WindowStore {
|
/**
|
||||||
public list: EngineWindow[];
|
* Window storage facility with convenient window filters built-in.
|
||||||
|
*/
|
||||||
|
export interface WindowStore {
|
||||||
|
/**
|
||||||
|
* Returns all visible windows on the given surface.
|
||||||
|
*/
|
||||||
|
visibleWindowsOn(surf: DriverSurface): EngineWindow[];
|
||||||
|
|
||||||
constructor(windows?: EngineWindow[]) {
|
/**
|
||||||
this.list = windows || [];
|
* Return all visible "Tile" windows on the given surface.
|
||||||
}
|
*/
|
||||||
|
visibleTiledWindowsOn(surf: DriverSurface): EngineWindow[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all visible "tileable" windows on the given surface
|
||||||
|
* @see Window#tileable
|
||||||
|
*/
|
||||||
|
visibleTileableWindowsOn(surf: DriverSurface): EngineWindow[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all "tileable" windows on the given surface, including hidden
|
||||||
|
*/
|
||||||
|
tileableWindowsOn(surf: DriverSurface): EngineWindow[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all windows on this surface, including minimized windows
|
||||||
|
*/
|
||||||
|
allWindowsOn(surf: DriverSurface): EngineWindow[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts the window at the beginning
|
||||||
|
*/
|
||||||
|
unshift(window: EngineWindow): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts the window at the end
|
||||||
|
*/
|
||||||
|
push(window: EngineWindow): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove window from the store
|
||||||
|
*/
|
||||||
|
remove(window: EngineWindow): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move srcWin to the destWin position (before/after)
|
||||||
|
* @param after if true, srcWin is moved after the destWindow. If false - it is moved before.
|
||||||
|
*/
|
||||||
|
move(srcWin: EngineWindow, destWin: EngineWindow, after?: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swap windows positions
|
||||||
|
*/
|
||||||
|
swap(alpha: EngineWindow, beta: EngineWindow): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the window into the master area.
|
||||||
|
* @param window window to put into the master area
|
||||||
|
*/
|
||||||
|
putWindowToMaster(window: EngineWindow): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WindowStoreImpl implements WindowStore {
|
||||||
|
/**
|
||||||
|
* @param list window list to initialize from
|
||||||
|
*/
|
||||||
|
constructor(public list: EngineWindow[] = []) {}
|
||||||
|
|
||||||
public move(
|
public move(
|
||||||
srcWin: EngineWindow,
|
srcWin: EngineWindow,
|
||||||
@ -25,11 +87,13 @@ export default class WindowStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the source window
|
||||||
this.list.splice(srcIdx, 1);
|
this.list.splice(srcIdx, 1);
|
||||||
|
// Place the source window in before destination window or after it
|
||||||
this.list.splice(after ? destIdx + 1 : destIdx, 0, srcWin);
|
this.list.splice(after ? destIdx + 1 : destIdx, 0, srcWin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setMaster(window: EngineWindow): void {
|
public putWindowToMaster(window: EngineWindow): void {
|
||||||
const idx = this.list.indexOf(window);
|
const idx = this.list.indexOf(window);
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
return;
|
return;
|
||||||
@ -76,40 +140,24 @@ export default class WindowStore {
|
|||||||
this.list.unshift(window);
|
this.list.unshift(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all visible windows on the given surface.
|
|
||||||
*/
|
|
||||||
public visibleWindowsOn(surf: DriverSurface): EngineWindow[] {
|
public visibleWindowsOn(surf: DriverSurface): EngineWindow[] {
|
||||||
return this.list.filter((win) => win.visibleOn(surf));
|
return this.list.filter((win) => win.visibleOn(surf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all visible "Tile" windows on the given surface.
|
|
||||||
*/
|
|
||||||
public visibleTiledWindowsOn(surf: DriverSurface): EngineWindow[] {
|
public visibleTiledWindowsOn(surf: DriverSurface): EngineWindow[] {
|
||||||
return this.list.filter((win) => win.tiled && win.visibleOn(surf));
|
return this.list.filter((win) => win.tiled && win.visibleOn(surf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all visible "tileable" windows on the given surface
|
|
||||||
* @see Window#tileable
|
|
||||||
*/
|
|
||||||
public visibleTileableWindowsOn(surf: DriverSurface): EngineWindow[] {
|
public visibleTileableWindowsOn(surf: DriverSurface): EngineWindow[] {
|
||||||
return this.list.filter((win) => win.tileable && win.visibleOn(surf));
|
return this.list.filter((win) => win.tileable && win.visibleOn(surf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all "tileable" windows on the given surface, including hidden
|
|
||||||
*/
|
|
||||||
public tileableWindowsOn(surf: DriverSurface): EngineWindow[] {
|
public tileableWindowsOn(surf: DriverSurface): EngineWindow[] {
|
||||||
return this.list.filter(
|
return this.list.filter(
|
||||||
(win) => win.tileable && win.surface.id === surf.id
|
(win) => win.tileable && win.surface.id === surf.id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all windows on this surface, including minimized windows
|
|
||||||
*/
|
|
||||||
public allWindowsOn(surf: DriverSurface): EngineWindow[] {
|
public allWindowsOn(surf: DriverSurface): EngineWindow[] {
|
||||||
return this.list.filter((win) => win.surface.id === surf.id);
|
return this.list.filter((win) => win.surface.id === surf.id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user