mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-11-03 19:41:22 +03:00
feat: make layouts togglable
This commit is contained in:
parent
a9f16cb3b5
commit
8ebffbe639
@ -355,7 +355,7 @@ describe("action", () => {
|
|||||||
|
|
||||||
fakeEngine = createMock<Engine>({
|
fakeEngine = createMock<Engine>({
|
||||||
cycleLayout: jest.fn(),
|
cycleLayout: jest.fn(),
|
||||||
setLayout: jest.fn(),
|
toggleLayout: jest.fn(),
|
||||||
currentWindow: jest.fn().mockReturnValue(fakeCurrentWindow),
|
currentWindow: jest.fn().mockReturnValue(fakeCurrentWindow),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -382,11 +382,11 @@ describe("action", () => {
|
|||||||
|
|
||||||
describe("set layout", () => {
|
describe("set layout", () => {
|
||||||
it("executes correctly when asking to set Monocle Layout", () => {
|
it("executes correctly when asking to set Monocle Layout", () => {
|
||||||
const action = new Action.SetMonocleLayout(fakeEngine, fakeLog);
|
const action = new Action.ToggleMonocleLayout(fakeEngine, fakeLog);
|
||||||
|
|
||||||
action.execute();
|
action.execute();
|
||||||
|
|
||||||
expect(fakeEngine.setLayout).toBeCalledWith("MonocleLayout");
|
expect(fakeEngine.toggleLayout).toBeCalledWith("MonocleLayout");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -452,7 +452,7 @@ export class SwitchToPreviousLayout extends ActionImpl implements Action {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class SetCurrentLayout extends ActionImpl implements Action {
|
abstract class ToggleCurrentLayout extends ActionImpl implements Action {
|
||||||
constructor(
|
constructor(
|
||||||
protected engine: Engine,
|
protected engine: Engine,
|
||||||
protected layoutId: string,
|
protected layoutId: string,
|
||||||
@ -465,11 +465,11 @@ abstract class SetCurrentLayout extends ActionImpl implements Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public executeWithoutLayoutOverride(): void {
|
public executeWithoutLayoutOverride(): void {
|
||||||
this.engine.setLayout(this.layoutId);
|
this.engine.toggleLayout(this.layoutId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetTileLayout extends SetCurrentLayout {
|
export class ToggleTileLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
super(
|
super(
|
||||||
engine,
|
engine,
|
||||||
@ -482,7 +482,7 @@ export class SetTileLayout extends SetCurrentLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetMonocleLayout extends SetCurrentLayout {
|
export class ToggleMonocleLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
super(
|
super(
|
||||||
engine,
|
engine,
|
||||||
@ -495,7 +495,7 @@ export class SetMonocleLayout extends SetCurrentLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetThreeColumnLayout extends SetCurrentLayout {
|
export class ToggleThreeColumnLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
super(
|
super(
|
||||||
engine,
|
engine,
|
||||||
@ -508,7 +508,7 @@ export class SetThreeColumnLayout extends SetCurrentLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetSpreadLayout extends SetCurrentLayout {
|
export class ToggleSpreadLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
super(
|
super(
|
||||||
engine,
|
engine,
|
||||||
@ -521,7 +521,7 @@ export class SetSpreadLayout extends SetCurrentLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetStairLayout extends SetCurrentLayout {
|
export class ToggleStairLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
super(
|
super(
|
||||||
engine,
|
engine,
|
||||||
@ -534,7 +534,7 @@ export class SetStairLayout extends SetCurrentLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetFloatingLayout extends SetCurrentLayout {
|
export class ToggleFloatingLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
// NOTE: space is intentional (Temporary)
|
// NOTE: space is intentional (Temporary)
|
||||||
super(
|
super(
|
||||||
@ -548,7 +548,7 @@ export class SetFloatingLayout extends SetCurrentLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetQuarterLayout extends SetCurrentLayout {
|
export class ToggleQuarterLayout extends ToggleCurrentLayout {
|
||||||
constructor(protected engine: Engine, protected log: Log) {
|
constructor(protected engine: Engine, protected log: Log) {
|
||||||
super(
|
super(
|
||||||
engine,
|
engine,
|
||||||
|
@ -403,13 +403,13 @@ export class ControllerImpl implements Controller {
|
|||||||
|
|
||||||
new Action.SwitchToNextLayout(this.engine, this.log),
|
new Action.SwitchToNextLayout(this.engine, this.log),
|
||||||
new Action.SwitchToPreviousLayout(this.engine, this.log),
|
new Action.SwitchToPreviousLayout(this.engine, this.log),
|
||||||
new Action.SetTileLayout(this.engine, this.log),
|
new Action.ToggleTileLayout(this.engine, this.log),
|
||||||
new Action.SetMonocleLayout(this.engine, this.log),
|
new Action.ToggleMonocleLayout(this.engine, this.log),
|
||||||
new Action.SetThreeColumnLayout(this.engine, this.log),
|
new Action.ToggleThreeColumnLayout(this.engine, this.log),
|
||||||
new Action.SetStairLayout(this.engine, this.log),
|
new Action.ToggleStairLayout(this.engine, this.log),
|
||||||
new Action.SetSpreadLayout(this.engine, this.log),
|
new Action.ToggleSpreadLayout(this.engine, this.log),
|
||||||
new Action.SetFloatingLayout(this.engine, this.log),
|
new Action.ToggleFloatingLayout(this.engine, this.log),
|
||||||
new Action.SetQuarterLayout(this.engine, this.log),
|
new Action.ToggleQuarterLayout(this.engine, this.log),
|
||||||
|
|
||||||
new Action.Rotate(this.engine, this.log),
|
new Action.Rotate(this.engine, this.log),
|
||||||
new Action.RotatePart(this.engine, this.log),
|
new Action.RotatePart(this.engine, this.log),
|
||||||
|
@ -146,7 +146,7 @@ export interface Engine {
|
|||||||
/**
|
/**
|
||||||
* Set the layout of the current surface to the specified layout.
|
* Set the layout of the current surface to the specified layout.
|
||||||
*/
|
*/
|
||||||
setLayout(layoutClassID: string): void;
|
toggleLayout(layoutClassID: string): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimize all windows on the surface except the given window.
|
* Minimize all windows on the surface except the given window.
|
||||||
@ -584,8 +584,8 @@ export class EngineImpl implements Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public setLayout(layoutClassID: string): void {
|
public toggleLayout(layoutClassID: string): void {
|
||||||
const layout = this.layouts.setLayout(
|
const layout = this.layouts.toggleLayout(
|
||||||
this.controller.currentSurface,
|
this.controller.currentSurface,
|
||||||
layoutClassID
|
layoutClassID
|
||||||
);
|
);
|
||||||
|
@ -45,16 +45,14 @@ export class LayoutStoreEntry {
|
|||||||
return this.loadLayout(this.currentID);
|
return this.loadLayout(this.currentID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setLayout(targetID: string): WindowsLayout {
|
public toggleLayout(targetID: string): WindowsLayout {
|
||||||
const targetLayout = this.loadLayout(targetID);
|
const targetLayout = this.loadLayout(targetID);
|
||||||
if (
|
|
||||||
targetLayout instanceof MonocleLayout &&
|
// Toggle if requested, set otherwise
|
||||||
this.currentLayout instanceof MonocleLayout
|
if (this.currentID === targetID) {
|
||||||
) {
|
|
||||||
/* toggle Monocle "OFF" */
|
|
||||||
this.currentID = this.previousID;
|
this.currentID = this.previousID;
|
||||||
this.previousID = targetID;
|
this.previousID = targetID;
|
||||||
} else if (this.currentID !== targetID) {
|
} else {
|
||||||
this.previousID = this.currentID;
|
this.previousID = this.currentID;
|
||||||
this.currentID = targetID;
|
this.currentID = targetID;
|
||||||
}
|
}
|
||||||
@ -80,10 +78,7 @@ export class LayoutStoreEntry {
|
|||||||
export default class LayoutStore {
|
export default class LayoutStore {
|
||||||
private store: { [key: string]: LayoutStoreEntry };
|
private store: { [key: string]: LayoutStoreEntry };
|
||||||
|
|
||||||
private config: Config;
|
constructor(private config: Config) {
|
||||||
|
|
||||||
constructor(config: Config) {
|
|
||||||
this.config = config;
|
|
||||||
this.store = {};
|
this.store = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,14 +95,14 @@ export default class LayoutStore {
|
|||||||
return this.getEntry(srf.id).cycleLayout(step);
|
return this.getEntry(srf.id).cycleLayout(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setLayout(
|
public toggleLayout(
|
||||||
srf: DriverSurface,
|
surf: DriverSurface,
|
||||||
layoutClassID: string
|
layoutClassID: string
|
||||||
): WindowsLayout | null {
|
): WindowsLayout | null {
|
||||||
if (srf.ignore) {
|
if (surf.ignore) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.getEntry(srf.id).setLayout(layoutClassID);
|
return this.getEntry(surf.id).toggleLayout(layoutClassID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getEntry(key: string): LayoutStoreEntry {
|
private getEntry(key: string): LayoutStoreEntry {
|
||||||
|
Loading…
Reference in New Issue
Block a user