refactor: split classes and ifaces to files

This commit is contained in:
Mikhail Zolotukhin 2021-08-28 21:52:45 +03:00
parent efdbb64d29
commit d8fa0536e9
32 changed files with 323 additions and 175 deletions

21
src/config.ts Normal file
View File

@ -0,0 +1,21 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
let CONFIG: IConfig;

View File

@ -0,0 +1,68 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
class TestDriver {
public currentScreen: number;
public currentWindow: number;
public numScreen: number;
public screenSize: Rect;
public windows: Window[];
constructor() {
this.currentScreen = 0;
this.currentWindow = 0;
this.numScreen = 1;
this.screenSize = new Rect(0, 0, 10000, 10000);
this.windows = [];
}
public forEachScreen(func: (srf: ISurface) => void) {
for (let screen = 0; screen < this.numScreen; screen++)
func(new TestSurface(this, screen));
}
public getCurrentContext(): ISurface {
const window = this.getCurrentWindow();
if (window) return window.surface;
return new TestSurface(this, 0);
}
public getCurrentWindow(): Window | null {
return this.windows.length !== 0 ? this.windows[this.currentWindow] : null;
}
public getWorkingArea(srf: ISurface): Rect {
return this.screenSize;
}
public setCurrentWindow(window: Window) {
const idx = this.windows.indexOf(window);
if (idx !== -1) this.currentWindow = idx;
}
public setTimeout(func: () => void, timeout: number) {
setTimeout(func, timeout);
}
}
function setTestConfig(name: string, value: any) {
if (!CONFIG) CONFIG = {} as any;
(CONFIG as any)[name] = value;
}

View File

@ -0,0 +1,44 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
class TestSurface implements ISurface {
public readonly screen: number;
public get id(): string {
return String(this.screen);
}
public get ignore(): boolean {
// TODO: optionally ignore some surface to test LayoutStore
return false;
}
public get workingArea(): Rect {
return this.driver.screenSize;
}
constructor(private driver: TestDriver, screen: number) {
this.screen = screen;
}
public next(): ISurface {
return new TestSurface(this.driver, this.screen + 1);
}
}

View File

@ -18,75 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
class TestDriver {
public currentScreen: number;
public currentWindow: number;
public numScreen: number;
public screenSize: Rect;
public windows: Window[];
constructor() {
this.currentScreen = 0;
this.currentWindow = 0;
this.numScreen = 1;
this.screenSize = new Rect(0, 0, 10000, 10000);
this.windows = [];
}
public forEachScreen(func: (srf: ISurface) => void) {
for (let screen = 0; screen < this.numScreen; screen++)
func(new TestSurface(this, screen));
}
public getCurrentContext(): ISurface {
const window = this.getCurrentWindow();
if (window) return window.surface;
return new TestSurface(this, 0);
}
public getCurrentWindow(): Window | null {
return this.windows.length !== 0 ? this.windows[this.currentWindow] : null;
}
public getWorkingArea(srf: ISurface): Rect {
return this.screenSize;
}
public setCurrentWindow(window: Window) {
const idx = this.windows.indexOf(window);
if (idx !== -1) this.currentWindow = idx;
}
public setTimeout(func: () => void, timeout: number) {
setTimeout(func, timeout);
}
}
class TestSurface implements ISurface {
public readonly screen: number;
public get id(): string {
return String(this.screen);
}
public get ignore(): boolean {
// TODO: optionally ignore some surface to test LayoutStore
return false;
}
public get workingArea(): Rect {
return this.driver.screenSize;
}
constructor(private driver: TestDriver, screen: number) {
this.screen = screen;
}
public next(): ISurface {
return new TestSurface(this.driver, this.screen + 1);
}
}
class TestWindow implements IDriverWindow {
private static windowCount: number = 0;
@ -136,8 +67,3 @@ class TestWindow implements IDriverWindow {
return this.surface.screen === tctx.screen;
}
}
function setTestConfig(name: string, value: any) {
if (!CONFIG) CONFIG = {} as any;
(CONFIG as any)[name] = value;
}

View File

@ -18,51 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
enum Shortcut {
Left,
Right,
Up,
Down,
/* Alternate HJKL bindings */
FocusUp,
FocusDown,
FocusLeft,
FocusRight,
ShiftLeft,
ShiftRight,
ShiftUp,
ShiftDown,
SwapUp,
SwapDown,
SwapLeft,
SwapRight,
GrowWidth,
GrowHeight,
ShrinkWidth,
ShrinkHeight,
Increase,
Decrease,
ShiftIncrease,
ShiftDecrease,
ToggleFloat,
ToggleFloatAll,
SetMaster,
NextLayout,
PreviousLayout,
SetLayout,
Rotate,
RotatePart,
}
//#region Driver
interface IConfig {
//#region Layout
layoutOrder: string[];
@ -92,59 +47,3 @@ interface IConfig {
newWindowAsMaster: boolean;
//#endregion
}
interface IDriverWindow {
readonly fullScreen: boolean;
readonly geometry: Readonly<Rect>;
readonly id: string;
readonly maximized: boolean;
readonly shouldIgnore: boolean;
readonly shouldFloat: boolean;
surface: ISurface;
commit(geometry?: Rect, noBorder?: boolean, keepAbove?: boolean): void;
visible(srf: ISurface): boolean;
}
interface ISurface {
readonly id: string;
readonly ignore: boolean;
readonly workingArea: Readonly<Rect>;
next(): ISurface | null;
}
interface IDriverContext {
readonly backend: string;
readonly screens: ISurface[];
readonly cursorPosition: [number, number] | null;
currentSurface: ISurface;
currentWindow: Window | null;
setTimeout(func: () => void, timeout: number): void;
showNotification(text: string): void;
}
//#endregion
interface ILayoutClass {
readonly id: string;
new (): ILayout;
}
interface ILayout {
/* read-only */
readonly capacity?: number;
readonly description: string;
/* methods */
adjust?(area: Rect, tiles: Window[], basis: Window, delta: RectDelta): void;
apply(ctx: EngineContext, tileables: Window[], area: Rect): void;
handleShortcut?(ctx: EngineContext, input: Shortcut, data?: any): boolean;
toString(): string;
}
let CONFIG: IConfig;

31
src/idriver_context.ts Normal file
View File

@ -0,0 +1,31 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
interface IDriverContext {
readonly backend: string;
readonly screens: ISurface[];
readonly cursorPosition: [number, number] | null;
currentSurface: ISurface;
currentWindow: Window | null;
setTimeout(func: () => void, timeout: number): void;
showNotification(text: string): void;
}

33
src/idriver_window.ts Normal file
View File

@ -0,0 +1,33 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
interface IDriverWindow {
readonly fullScreen: boolean;
readonly geometry: Readonly<Rect>;
readonly id: string;
readonly maximized: boolean;
readonly shouldIgnore: boolean;
readonly shouldFloat: boolean;
surface: ISurface;
commit(geometry?: Rect, noBorder?: boolean, keepAbove?: boolean): void;
visible(srf: ISurface): boolean;
}

37
src/ilayout.ts Normal file
View File

@ -0,0 +1,37 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
interface ILayoutClass {
readonly id: string;
new (): ILayout;
}
interface ILayout {
/* read-only */
readonly capacity?: number;
readonly description: string;
/* methods */
adjust?(area: Rect, tiles: Window[], basis: Window, delta: RectDelta): void;
apply(ctx: EngineContext, tileables: Window[], area: Rect): void;
handleShortcut?(ctx: EngineContext, input: Shortcut, data?: any): boolean;
toString(): string;
}

27
src/isurface.ts Normal file
View File

@ -0,0 +1,27 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
interface ISurface {
readonly id: string;
readonly ignore: boolean;
readonly workingArea: Readonly<Rect>;
next(): ISurface | null;
}

62
src/shortcut.ts Normal file
View File

@ -0,0 +1,62 @@
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
enum Shortcut {
Left,
Right,
Up,
Down,
/* Alternate HJKL bindings */
FocusUp,
FocusDown,
FocusLeft,
FocusRight,
ShiftLeft,
ShiftRight,
ShiftUp,
ShiftDown,
SwapUp,
SwapDown,
SwapLeft,
SwapRight,
GrowWidth,
GrowHeight,
ShrinkWidth,
ShrinkHeight,
Increase,
Decrease,
ShiftIncrease,
ShiftDecrease,
ToggleFloat,
ToggleFloatAll,
SetMaster,
NextLayout,
PreviousLayout,
SetLayout,
Rotate,
RotatePart,
}