mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-08-14 18:40:35 +03:00
refactor: ♻️ improve logging
This commit is contained in:
parent
d989261d82
commit
fadcaeac95
@ -11,7 +11,7 @@
|
||||
<group name="">
|
||||
|
||||
<entry name="debug" type="Bool">
|
||||
<label>Print debug messages</label>
|
||||
<label>Enable logging</label>
|
||||
<default>false</default>
|
||||
</entry>
|
||||
|
||||
|
@ -626,8 +626,7 @@
|
||||
<string>Use this option to debug the script or submit detailed bug report.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Print debug messages
|
||||
(must run KWin from terminal)</string>
|
||||
<string>Enable logging</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -27,7 +27,7 @@ Item {
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
console.log("Bismuth: Initiating the script");
|
||||
console.log("[Bismuth] Initiating the script");
|
||||
|
||||
const qmlObjects = {
|
||||
scriptRoot: scriptRoot,
|
||||
|
@ -8,9 +8,12 @@ import { createMock } from "ts-auto-mock";
|
||||
import { Engine } from "../engine";
|
||||
import { WindowsLayout } from "../engine/layout";
|
||||
import Window from "../engine/window";
|
||||
import { NullLog } from "../util/log";
|
||||
import * as Action from "./action";
|
||||
|
||||
describe("action", () => {
|
||||
const fakeLog = new NullLog();
|
||||
|
||||
describe("focus", () => {
|
||||
let fakeEngine: Engine;
|
||||
beforeEach(() => {
|
||||
@ -25,7 +28,7 @@ describe("action", () => {
|
||||
|
||||
describe("up", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.FocusUpperWindow(fakeEngine);
|
||||
const action = new Action.FocusUpperWindow(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -35,7 +38,7 @@ describe("action", () => {
|
||||
|
||||
describe("down", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.FocusBottomWindow(fakeEngine);
|
||||
const action = new Action.FocusBottomWindow(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -45,7 +48,7 @@ describe("action", () => {
|
||||
|
||||
describe("left", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.FocusLeftWindow(fakeEngine);
|
||||
const action = new Action.FocusLeftWindow(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -55,7 +58,7 @@ describe("action", () => {
|
||||
|
||||
describe("right", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.FocusRightWindow(fakeEngine);
|
||||
const action = new Action.FocusRightWindow(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -65,7 +68,7 @@ describe("action", () => {
|
||||
|
||||
describe("next", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.FocusNextWindow(fakeEngine);
|
||||
const action = new Action.FocusNextWindow(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -75,7 +78,7 @@ describe("action", () => {
|
||||
|
||||
describe("prev", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.FocusPreviousWindow(fakeEngine);
|
||||
const action = new Action.FocusPreviousWindow(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -99,7 +102,7 @@ describe("action", () => {
|
||||
|
||||
describe("up", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.MoveActiveWindowUp(fakeEngine);
|
||||
const action = new Action.MoveActiveWindowUp(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -109,7 +112,7 @@ describe("action", () => {
|
||||
|
||||
describe("down", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.MoveActiveWindowDown(fakeEngine);
|
||||
const action = new Action.MoveActiveWindowDown(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -119,7 +122,7 @@ describe("action", () => {
|
||||
|
||||
describe("left", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.MoveActiveWindowLeft(fakeEngine);
|
||||
const action = new Action.MoveActiveWindowLeft(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -129,7 +132,7 @@ describe("action", () => {
|
||||
|
||||
describe("right", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.MoveActiveWindowRight(fakeEngine);
|
||||
const action = new Action.MoveActiveWindowRight(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -139,7 +142,10 @@ describe("action", () => {
|
||||
|
||||
describe("next", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.MoveActiveWindowToNextPosition(fakeEngine);
|
||||
const action = new Action.MoveActiveWindowToNextPosition(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -150,7 +156,8 @@ describe("action", () => {
|
||||
describe("prev", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.MoveActiveWindowToPreviousPosition(
|
||||
fakeEngine
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
@ -175,7 +182,10 @@ describe("action", () => {
|
||||
|
||||
describe("width increase", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.IncreaseActiveWindowWidth(fakeEngine);
|
||||
const action = new Action.IncreaseActiveWindowWidth(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -189,7 +199,10 @@ describe("action", () => {
|
||||
|
||||
describe("width decrease", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.DecreaseActiveWindowWidth(fakeEngine);
|
||||
const action = new Action.DecreaseActiveWindowWidth(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -203,7 +216,10 @@ describe("action", () => {
|
||||
|
||||
describe("height increase", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.IncreaseActiveWindowHeight(fakeEngine);
|
||||
const action = new Action.IncreaseActiveWindowHeight(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -217,7 +233,10 @@ describe("action", () => {
|
||||
|
||||
describe("height decrease", () => {
|
||||
it("correctly executes", () => {
|
||||
const action = new Action.DecreaseActiveWindowHeight(fakeEngine);
|
||||
const action = new Action.DecreaseActiveWindowHeight(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -241,7 +260,10 @@ describe("action", () => {
|
||||
|
||||
describe("increase windows count", () => {
|
||||
it("shows a note that there is no master area in general case", () => {
|
||||
const action = new Action.IncreaseMasterAreaWindowCount(fakeEngine);
|
||||
const action = new Action.IncreaseMasterAreaWindowCount(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -251,7 +273,10 @@ describe("action", () => {
|
||||
|
||||
describe("decrease windows count", () => {
|
||||
it("shows a note that there is no master area in general case", () => {
|
||||
const action = new Action.DecreaseMasterAreaWindowCount(fakeEngine);
|
||||
const action = new Action.DecreaseMasterAreaWindowCount(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -261,7 +286,10 @@ describe("action", () => {
|
||||
|
||||
describe("increase size", () => {
|
||||
it("shows a note that there is no master area in general case", () => {
|
||||
const action = new Action.IncreaseLayoutMasterAreaSize(fakeEngine);
|
||||
const action = new Action.IncreaseLayoutMasterAreaSize(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -271,7 +299,10 @@ describe("action", () => {
|
||||
|
||||
describe("decrease size", () => {
|
||||
it("shows a note that there is no master area in general case", () => {
|
||||
const action = new Action.DecreaseLayoutMasterAreaSize(fakeEngine);
|
||||
const action = new Action.DecreaseLayoutMasterAreaSize(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -288,7 +319,7 @@ describe("action", () => {
|
||||
currentWindow: jest.fn().mockReturnValue(fakeCurrentWindow),
|
||||
});
|
||||
|
||||
const action = new Action.ToggleActiveWindowFloating(fakeEngine);
|
||||
const action = new Action.ToggleActiveWindowFloating(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -304,7 +335,10 @@ describe("action", () => {
|
||||
currentWindow: jest.fn().mockReturnValue(fakeCurrentWindow),
|
||||
});
|
||||
|
||||
const action = new Action.PushActiveWindowIntoMasterAreaFront(fakeEngine);
|
||||
const action = new Action.PushActiveWindowIntoMasterAreaFront(
|
||||
fakeEngine,
|
||||
fakeLog
|
||||
);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -328,7 +362,7 @@ describe("action", () => {
|
||||
|
||||
describe("next layout", () => {
|
||||
it("executes correctly", () => {
|
||||
const action = new Action.SwitchToNextLayout(fakeEngine);
|
||||
const action = new Action.SwitchToNextLayout(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -338,7 +372,7 @@ describe("action", () => {
|
||||
|
||||
describe("prev layout", () => {
|
||||
it("executes correctly", () => {
|
||||
const action = new Action.SwitchToPreviousLayout(fakeEngine);
|
||||
const action = new Action.SwitchToPreviousLayout(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
@ -348,7 +382,7 @@ describe("action", () => {
|
||||
|
||||
describe("set layout", () => {
|
||||
it("executes correctly when asking to set Monocle Layout", () => {
|
||||
const action = new Action.SetMonocleLayout(fakeEngine);
|
||||
const action = new Action.SetMonocleLayout(fakeEngine, fakeLog);
|
||||
|
||||
action.execute();
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { Engine } from "../engine";
|
||||
import { Log } from "../util/log";
|
||||
|
||||
/**
|
||||
* Action that is requested by the user.
|
||||
@ -50,7 +51,8 @@ abstract class ActionImpl implements Action {
|
||||
protected engine: Engine,
|
||||
public key: string,
|
||||
public description: string,
|
||||
public defaultKeybinding: string
|
||||
public defaultKeybinding: string,
|
||||
protected log: Log
|
||||
) {
|
||||
this.key = `bismuth_${this.key}`;
|
||||
this.description = `Bismuth: ${this.description}`;
|
||||
@ -62,7 +64,7 @@ abstract class ActionImpl implements Action {
|
||||
* behavior.
|
||||
*/
|
||||
public execute(): void {
|
||||
console.log(`Bismuth: Executing action: ${this.key}`);
|
||||
this.log.log(`Executing action: ${this.key}`);
|
||||
|
||||
const currentLayout = this.engine.currentLayoutOnCurrentSurface();
|
||||
if (currentLayout.executeAction) {
|
||||
@ -82,8 +84,8 @@ abstract class ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class FocusNextWindow extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "focus_next_window", "Focus Next Window", "");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "focus_next_window", "Focus Next Window", "", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -92,8 +94,8 @@ export class FocusNextWindow extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class FocusPreviousWindow extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "focus_prev_window", "Focus Previous Window", "");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "focus_prev_window", "Focus Previous Window", "", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -102,8 +104,8 @@ export class FocusPreviousWindow extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class FocusUpperWindow extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "focus_upper_window", "Focus Upper Window", "Meta+K");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "focus_upper_window", "Focus Upper Window", "Meta+K", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -112,8 +114,8 @@ export class FocusUpperWindow extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class FocusBottomWindow extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "focus_bottom_window", "Focus Bottom Window", "Meta+J");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "focus_bottom_window", "Focus Bottom Window", "Meta+J", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -122,8 +124,8 @@ export class FocusBottomWindow extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class FocusLeftWindow extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "focus_left_window", "Focus Left Window", "Meta+H");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "focus_left_window", "Focus Left Window", "Meta+H", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -132,8 +134,8 @@ export class FocusLeftWindow extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class FocusRightWindow extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "focus_right_window", "Focus Right Window", "Meta+L");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "focus_right_window", "Focus Right Window", "Meta+L", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -145,12 +147,13 @@ export class MoveActiveWindowToNextPosition
|
||||
extends ActionImpl
|
||||
implements Action
|
||||
{
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"move_window_to_next_pos",
|
||||
"Move Window to the Next Position",
|
||||
""
|
||||
"",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -166,12 +169,13 @@ export class MoveActiveWindowToPreviousPosition
|
||||
extends ActionImpl
|
||||
implements Action
|
||||
{
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"move_window_to_prev_pos",
|
||||
"Move Window to the Previous Position",
|
||||
""
|
||||
"",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -184,8 +188,14 @@ export class MoveActiveWindowToPreviousPosition
|
||||
}
|
||||
|
||||
export class MoveActiveWindowUp extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "move_window_to_upper_pos", "Move Window Up", "Meta+Shift+K");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"move_window_to_upper_pos",
|
||||
"Move Window Up",
|
||||
"Meta+Shift+K",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -194,12 +204,13 @@ export class MoveActiveWindowUp extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class MoveActiveWindowDown extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"move_window_to_bottom_pos",
|
||||
"Move Window Down",
|
||||
"Meta+Shift+J"
|
||||
"Meta+Shift+J",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -209,12 +220,13 @@ export class MoveActiveWindowDown extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class MoveActiveWindowLeft extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"move_window_to_left_pos",
|
||||
"Move Window Left",
|
||||
"Meta+Shift+H"
|
||||
"Meta+Shift+H",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -224,12 +236,13 @@ export class MoveActiveWindowLeft extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class MoveActiveWindowRight extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"move_window_to_right_pos",
|
||||
"Move Window Right",
|
||||
"Meta+Shift+L"
|
||||
"Meta+Shift+L",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -239,12 +252,13 @@ export class MoveActiveWindowRight extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class IncreaseActiveWindowWidth extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"increase_window_width",
|
||||
"Increase Window Width",
|
||||
"Meta+Ctrl+L"
|
||||
"Meta+Ctrl+L",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -257,12 +271,13 @@ export class IncreaseActiveWindowWidth extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class IncreaseActiveWindowHeight extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"increase_window_height",
|
||||
"Increase Window Height",
|
||||
"Meta+Ctrl+J"
|
||||
"Meta+Ctrl+J",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -275,12 +290,13 @@ export class IncreaseActiveWindowHeight extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class DecreaseActiveWindowWidth extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"decrease_window_width",
|
||||
"Decrease Window Width",
|
||||
"Meta+Ctrl+H"
|
||||
"Meta+Ctrl+H",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -293,12 +309,13 @@ export class DecreaseActiveWindowWidth extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class DecreaseActiveWindowHeight extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"decrease_window_height",
|
||||
"Decrease Window Height",
|
||||
"Meta+Ctrl+K"
|
||||
"Meta+Ctrl+K",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -314,12 +331,13 @@ export class IncreaseMasterAreaWindowCount
|
||||
extends ActionImpl
|
||||
implements Action
|
||||
{
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"increase_master_win_count",
|
||||
"Increase Master Area Window Count",
|
||||
"Meta+]"
|
||||
"Meta+]",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -332,12 +350,13 @@ export class DecreaseMasterAreaWindowCount
|
||||
extends ActionImpl
|
||||
implements Action
|
||||
{
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"decrease_master_win_count",
|
||||
"Decrease Master Area Window Count",
|
||||
"Meta+["
|
||||
"Meta+[",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -347,8 +366,8 @@ export class DecreaseMasterAreaWindowCount
|
||||
}
|
||||
|
||||
export class IncreaseLayoutMasterAreaSize extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "increase_master_size", "Increase Master Area Size", "");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "increase_master_size", "Increase Master Area Size", "", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -357,8 +376,8 @@ export class IncreaseLayoutMasterAreaSize extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class DecreaseLayoutMasterAreaSize extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "decrease_master_size", "Decrease Master Area Size", "");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "decrease_master_size", "Decrease Master Area Size", "", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -367,12 +386,13 @@ export class DecreaseLayoutMasterAreaSize extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class ToggleActiveWindowFloating extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"toggle_window_floating",
|
||||
"Toggle Active Window Floating",
|
||||
"Meta+F"
|
||||
"Meta+F",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -388,12 +408,13 @@ export class PushActiveWindowIntoMasterAreaFront
|
||||
extends ActionImpl
|
||||
implements Action
|
||||
{
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"push_window_to_master",
|
||||
"Push Active Window to Master Area",
|
||||
"Meta+Return"
|
||||
"Meta+Return",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
@ -406,8 +427,8 @@ export class PushActiveWindowIntoMasterAreaFront
|
||||
}
|
||||
|
||||
export class SwitchToNextLayout extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "next_layout", "Switch to the Next Layout", "Meta+\\");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "next_layout", "Switch to the Next Layout", "Meta+\\", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -416,8 +437,14 @@ export class SwitchToNextLayout extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class SwitchToPreviousLayout extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "prev_layout", "Switch to the Previous Layout", "Meta+|");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"prev_layout",
|
||||
"Switch to the Previous Layout",
|
||||
"Meta+|",
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -431,106 +458,112 @@ abstract class SetCurrentLayout extends ActionImpl implements Action {
|
||||
protected layoutId: string,
|
||||
key: string,
|
||||
description: string,
|
||||
defaultShortcut: string
|
||||
defaultShortcut: string,
|
||||
protected log: Log
|
||||
) {
|
||||
super(engine, key, description, defaultShortcut);
|
||||
super(engine, key, description, defaultShortcut, log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
console.log("Set layout called!");
|
||||
|
||||
this.engine.setLayout(this.layoutId);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetTileLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"TileLayout",
|
||||
"toggle_tile_layout",
|
||||
"Toggle Tile Layout",
|
||||
"Meta+T"
|
||||
"Meta+T",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetMonocleLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"MonocleLayout",
|
||||
"toggle_monocle_layout",
|
||||
"Toggle Monocle Layout",
|
||||
"Meta+M"
|
||||
"Meta+M",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetThreeColumnLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"ThreeColumnLayout",
|
||||
"toggle_three_column_layout",
|
||||
"Toggle Three Column Layout",
|
||||
""
|
||||
"",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetSpreadLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"SpreadLayout",
|
||||
"toggle_spread_layout",
|
||||
"Toggle Spread Layout",
|
||||
""
|
||||
"",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetStairLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"StairLayout",
|
||||
"toggle_stair_layout",
|
||||
"Toggle Stair Layout",
|
||||
""
|
||||
"",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetFloatingLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
// NOTE: space is intentional (Temporary)
|
||||
super(
|
||||
engine,
|
||||
"FloatingLayout ",
|
||||
"toggle_float_layout",
|
||||
"Toggle Floating Layout",
|
||||
"Meta+Shift+F"
|
||||
"Meta+Shift+F",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SetQuarterLayout extends SetCurrentLayout {
|
||||
constructor(protected engine: Engine) {
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(
|
||||
engine,
|
||||
"QuarterLayout",
|
||||
"toggle_quarter_layout",
|
||||
"Toggle Quarter Layout",
|
||||
""
|
||||
"",
|
||||
log
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Rotate extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "rotate", "Rotate", "Meta+R");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "rotate", "Rotate", "Meta+R", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
@ -539,8 +572,8 @@ export class Rotate extends ActionImpl implements Action {
|
||||
}
|
||||
|
||||
export class RotatePart extends ActionImpl implements Action {
|
||||
constructor(protected engine: Engine) {
|
||||
super(engine, "rotate_part", "Rotate Part", "Meta+Shift+R");
|
||||
constructor(protected engine: Engine, protected log: Log) {
|
||||
super(engine, "rotate_part", "Rotate Part", "Meta+Shift+R", log);
|
||||
}
|
||||
|
||||
public executeWithoutLayoutOverride(): void {
|
||||
|
@ -9,10 +9,9 @@ import { WindowState } from "../engine/window";
|
||||
|
||||
import { DriverContext, KWinDriver } from "../driver";
|
||||
import { DriverSurface } from "../driver/surface";
|
||||
import MonocleLayout from "../engine/layout/monocle_layout";
|
||||
|
||||
import Config from "../config";
|
||||
import Debug from "../util/debug";
|
||||
import { Log } from "../util/log";
|
||||
|
||||
import * as Action from "./action";
|
||||
|
||||
@ -148,19 +147,18 @@ export class TilingController implements Controller {
|
||||
qmlObjects: Bismuth.Qml.Main,
|
||||
kwinApi: KWin.Api,
|
||||
private config: Config,
|
||||
private debug: Debug
|
||||
private log: Log
|
||||
) {
|
||||
this.engine = new TilingEngine(this, config, debug);
|
||||
this.driver = new KWinDriver(qmlObjects, kwinApi, this, config, debug);
|
||||
this.engine = new TilingEngine(this, config, log);
|
||||
this.driver = new KWinDriver(qmlObjects, kwinApi, this, config, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point: start tiling window management
|
||||
*/
|
||||
public start(): void {
|
||||
console.log("Let's get down to bismuth!");
|
||||
|
||||
this.debug.debug(() => `Config: ${this.config}`);
|
||||
this.log.log("Let's get down to bismuth!");
|
||||
this.log.log(`Config: ${this.config}`);
|
||||
|
||||
this.driver.bindEvents();
|
||||
this.bindShortcuts();
|
||||
@ -195,15 +193,12 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onSurfaceUpdate(comment: string): void {
|
||||
this.debug.debugObj(() => ["onSurfaceUpdate", { comment }]);
|
||||
this.log.log(["onSurfaceUpdate", { comment }]);
|
||||
this.engine.arrange();
|
||||
}
|
||||
|
||||
public onCurrentSurfaceChanged(): void {
|
||||
this.debug.debugObj(() => [
|
||||
"onCurrentSurfaceChanged",
|
||||
{ srf: this.currentSurface },
|
||||
]);
|
||||
this.log.log(["onCurrentSurfaceChanged", { srf: this.currentSurface }]);
|
||||
this.engine.arrange();
|
||||
/* HACK: minimize others and change geometry with Monocle Layout and
|
||||
* config.monocleMinimizeRest
|
||||
@ -214,8 +209,7 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onWindowAdded(window: Window): void {
|
||||
this.debug.debugObj(() => ["onWindowAdded", { window }]);
|
||||
console.log(`New window added: ${window}`);
|
||||
this.log.log(["onWindowAdded", { window }]);
|
||||
this.engine.manage(window);
|
||||
|
||||
/* move window to next surface if the current surface is "full" */
|
||||
@ -237,8 +231,7 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onWindowRemoved(window: Window): void {
|
||||
this.debug.debugObj(() => ["onWindowRemoved", { window }]);
|
||||
console.log(`Window remove: ${window}`);
|
||||
this.log.log(["onWindowRemoved", { window }]);
|
||||
|
||||
this.engine.unmanage(window);
|
||||
this.engine.arrange();
|
||||
@ -263,7 +256,7 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onWindowMoveOver(window: Window): void {
|
||||
this.debug.debugObj(() => ["onWindowMoveOver", { window }]);
|
||||
this.log.log(["onWindowMoveOver", { window }]);
|
||||
|
||||
/* swap window by dragging */
|
||||
if (window.state === WindowState.Tiled) {
|
||||
@ -304,7 +297,7 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onWindowResize(window: Window): void {
|
||||
this.debug.debugObj(() => ["onWindowResize", { window }]);
|
||||
this.log.log(["onWindowResize", { window }]);
|
||||
if (this.config.adjustLayout && this.config.adjustLayoutLive) {
|
||||
if (window.state === WindowState.Tiled) {
|
||||
this.engine.adjustLayout(window);
|
||||
@ -314,8 +307,7 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onWindowResizeOver(window: Window): void {
|
||||
this.debug.debugObj(() => ["onWindowResizeOver", { window }]);
|
||||
console.log(`Window resize is over: ${window}`);
|
||||
this.log.log(["onWindowResizeOver", { window }]);
|
||||
if (this.config.adjustLayout && window.tiled) {
|
||||
this.engine.adjustLayout(window);
|
||||
this.engine.arrange();
|
||||
@ -329,7 +321,7 @@ export class TilingController implements Controller {
|
||||
}
|
||||
|
||||
public onWindowGeometryChanged(window: Window): void {
|
||||
this.debug.debugObj(() => ["onWindowGeometryChanged", { window }]);
|
||||
this.log.log(["onWindowGeometryChanged", { window }]);
|
||||
this.engine.enforceSize(window);
|
||||
}
|
||||
|
||||
@ -337,7 +329,7 @@ export class TilingController implements Controller {
|
||||
// by itself anyway.
|
||||
public onWindowChanged(window: Window | null, comment?: string): void {
|
||||
if (window) {
|
||||
this.debug.debugObj(() => ["onWindowChanged", { window, comment }]);
|
||||
this.log.log(["onWindowChanged", { window, comment }]);
|
||||
|
||||
if (comment === "unminimized") {
|
||||
this.currentWindow = window;
|
||||
@ -350,12 +342,12 @@ export class TilingController implements Controller {
|
||||
public onWindowFocused(window: Window): void {
|
||||
window.timestamp = new Date().getTime();
|
||||
this.currentWindow = window;
|
||||
// Minimize other windows if Moncole and config.monocleMinimizeRest
|
||||
// Minimize other windows if Monocle and config.monocleMinimizeRest
|
||||
if (
|
||||
this.engine.isLayoutMonocleAndMinimizeRest() &&
|
||||
this.engine.windows.getVisibleTiles(window.surface).includes(window)
|
||||
) {
|
||||
/* If a window hasn't been foucsed in this layout yet, ensure its geometry
|
||||
/* If a window hasn't been focused in this layout yet, ensure its geometry
|
||||
* gets maximized.
|
||||
*/
|
||||
this.engine
|
||||
@ -376,45 +368,45 @@ export class TilingController implements Controller {
|
||||
|
||||
private bindShortcuts(): void {
|
||||
const allPossibleActions = [
|
||||
new Action.FocusNextWindow(this.engine),
|
||||
new Action.FocusPreviousWindow(this.engine),
|
||||
new Action.FocusUpperWindow(this.engine),
|
||||
new Action.FocusBottomWindow(this.engine),
|
||||
new Action.FocusLeftWindow(this.engine),
|
||||
new Action.FocusRightWindow(this.engine),
|
||||
new Action.MoveActiveWindowToNextPosition(this.engine),
|
||||
new Action.FocusNextWindow(this.engine, this.log),
|
||||
new Action.FocusPreviousWindow(this.engine, this.log),
|
||||
new Action.FocusUpperWindow(this.engine, this.log),
|
||||
new Action.FocusBottomWindow(this.engine, this.log),
|
||||
new Action.FocusLeftWindow(this.engine, this.log),
|
||||
new Action.FocusRightWindow(this.engine, this.log),
|
||||
new Action.MoveActiveWindowToNextPosition(this.engine, this.log),
|
||||
|
||||
new Action.MoveActiveWindowToPreviousPosition(this.engine),
|
||||
new Action.MoveActiveWindowUp(this.engine),
|
||||
new Action.MoveActiveWindowDown(this.engine),
|
||||
new Action.MoveActiveWindowLeft(this.engine),
|
||||
new Action.MoveActiveWindowRight(this.engine),
|
||||
new Action.MoveActiveWindowToPreviousPosition(this.engine, this.log),
|
||||
new Action.MoveActiveWindowUp(this.engine, this.log),
|
||||
new Action.MoveActiveWindowDown(this.engine, this.log),
|
||||
new Action.MoveActiveWindowLeft(this.engine, this.log),
|
||||
new Action.MoveActiveWindowRight(this.engine, this.log),
|
||||
|
||||
new Action.IncreaseActiveWindowWidth(this.engine),
|
||||
new Action.IncreaseActiveWindowHeight(this.engine),
|
||||
new Action.DecreaseActiveWindowWidth(this.engine),
|
||||
new Action.DecreaseActiveWindowHeight(this.engine),
|
||||
new Action.IncreaseActiveWindowWidth(this.engine, this.log),
|
||||
new Action.IncreaseActiveWindowHeight(this.engine, this.log),
|
||||
new Action.DecreaseActiveWindowWidth(this.engine, this.log),
|
||||
new Action.DecreaseActiveWindowHeight(this.engine, this.log),
|
||||
|
||||
new Action.IncreaseMasterAreaWindowCount(this.engine),
|
||||
new Action.DecreaseMasterAreaWindowCount(this.engine),
|
||||
new Action.IncreaseLayoutMasterAreaSize(this.engine),
|
||||
new Action.DecreaseLayoutMasterAreaSize(this.engine),
|
||||
new Action.IncreaseMasterAreaWindowCount(this.engine, this.log),
|
||||
new Action.DecreaseMasterAreaWindowCount(this.engine, this.log),
|
||||
new Action.IncreaseLayoutMasterAreaSize(this.engine, this.log),
|
||||
new Action.DecreaseLayoutMasterAreaSize(this.engine, this.log),
|
||||
|
||||
new Action.ToggleActiveWindowFloating(this.engine),
|
||||
new Action.PushActiveWindowIntoMasterAreaFront(this.engine),
|
||||
new Action.ToggleActiveWindowFloating(this.engine, this.log),
|
||||
new Action.PushActiveWindowIntoMasterAreaFront(this.engine, this.log),
|
||||
|
||||
new Action.SwitchToNextLayout(this.engine),
|
||||
new Action.SwitchToPreviousLayout(this.engine),
|
||||
new Action.SetTileLayout(this.engine),
|
||||
new Action.SetMonocleLayout(this.engine),
|
||||
new Action.SetThreeColumnLayout(this.engine),
|
||||
new Action.SetStairLayout(this.engine),
|
||||
new Action.SetSpreadLayout(this.engine),
|
||||
new Action.SetFloatingLayout(this.engine),
|
||||
new Action.SetQuarterLayout(this.engine),
|
||||
new Action.SwitchToNextLayout(this.engine, this.log),
|
||||
new Action.SwitchToPreviousLayout(this.engine, this.log),
|
||||
new Action.SetTileLayout(this.engine, this.log),
|
||||
new Action.SetMonocleLayout(this.engine, this.log),
|
||||
new Action.SetThreeColumnLayout(this.engine, this.log),
|
||||
new Action.SetStairLayout(this.engine, this.log),
|
||||
new Action.SetSpreadLayout(this.engine, this.log),
|
||||
new Action.SetFloatingLayout(this.engine, this.log),
|
||||
new Action.SetQuarterLayout(this.engine, this.log),
|
||||
|
||||
new Action.Rotate(this.engine),
|
||||
new Action.RotatePart(this.engine),
|
||||
new Action.Rotate(this.engine, this.log),
|
||||
new Action.RotatePart(this.engine, this.log),
|
||||
];
|
||||
|
||||
for (const action of allPossibleActions) {
|
||||
|
@ -15,7 +15,7 @@ import Window from "../engine/window";
|
||||
import { WindowState } from "../engine/window";
|
||||
|
||||
import Config from "../config";
|
||||
import Debug from "../util/debug";
|
||||
import { Log } from "../util/log";
|
||||
|
||||
export interface DriverContext {
|
||||
readonly screens: DriverSurface[];
|
||||
@ -65,7 +65,6 @@ export class KWinDriver implements DriverContext {
|
||||
|
||||
public get currentWindow(): Window | null {
|
||||
const client = this.kwinApi.workspace.activeClient;
|
||||
console.log(`Active client: ${client}`);
|
||||
return client ? this.windowMap.get(client) : null;
|
||||
}
|
||||
|
||||
@ -102,7 +101,6 @@ export class KWinDriver implements DriverContext {
|
||||
private kwinApi: KWin.Api;
|
||||
|
||||
private config: Config;
|
||||
private debug: Debug;
|
||||
|
||||
/**
|
||||
* @param qmlObjects objects from QML gui. Required for the interaction with QML, as we cannot access globals.
|
||||
@ -114,16 +112,13 @@ export class KWinDriver implements DriverContext {
|
||||
kwinApi: KWin.Api,
|
||||
controller: Controller,
|
||||
config: Config,
|
||||
debug: Debug
|
||||
private log: Log
|
||||
) {
|
||||
this.config = config;
|
||||
this.debug = debug;
|
||||
|
||||
// TODO: find a better way to to this
|
||||
if (this.config.preventMinimize && this.config.monocleMinimizeRest) {
|
||||
this.debug.debug(
|
||||
() => "preventMinimize is disabled because of monocleMinimizeRest."
|
||||
);
|
||||
log.log("preventMinimize is disabled because of monocleMinimizeRest");
|
||||
this.config.preventMinimize = false;
|
||||
}
|
||||
|
||||
@ -132,15 +127,9 @@ export class KWinDriver implements DriverContext {
|
||||
(client: KWin.Client) => KWinWindow.generateID(client),
|
||||
(client: KWin.Client) =>
|
||||
new Window(
|
||||
new KWinWindow(
|
||||
client,
|
||||
this.qml,
|
||||
this.kwinApi,
|
||||
this.config,
|
||||
this.debug
|
||||
),
|
||||
new KWinWindow(client, this.qml, this.kwinApi, this.config, this.log),
|
||||
this.config,
|
||||
this.debug
|
||||
this.log
|
||||
)
|
||||
);
|
||||
this.entered = false;
|
||||
@ -180,17 +169,17 @@ export class KWinDriver implements DriverContext {
|
||||
};
|
||||
|
||||
const onClientAdded = (client: KWin.Client): void => {
|
||||
console.log(`Client added: ${client}`);
|
||||
this.log.log(`Client added: ${client}`);
|
||||
|
||||
const window = this.windowMap.add(client);
|
||||
this.controller.onWindowAdded(window);
|
||||
if (window.state === WindowState.Unmanaged) {
|
||||
console.log(
|
||||
this.log.log(
|
||||
`Window becomes unmanaged and gets removed :( The client was ${client}`
|
||||
);
|
||||
this.windowMap.remove(client);
|
||||
} else {
|
||||
console.log(`Client is ok, can manage. Bind events now...`);
|
||||
this.log.log(`Client is ok, can manage. Bind events now...`);
|
||||
this.bindWindowEvents(window, client);
|
||||
}
|
||||
};
|
||||
@ -307,9 +296,6 @@ export class KWinDriver implements DriverContext {
|
||||
}
|
||||
|
||||
public bindShortcut(action: Action): void {
|
||||
console.log(
|
||||
`Registering ${action.key} with the description ${action.description}`
|
||||
);
|
||||
this.kwinApi.KWin.registerShortcut(
|
||||
action.key,
|
||||
action.description,
|
||||
@ -356,10 +342,8 @@ export class KWinDriver implements DriverContext {
|
||||
this.entered = true;
|
||||
try {
|
||||
callback();
|
||||
} catch (e) {
|
||||
// TODO: investigate why this line prevents compiling
|
||||
// debug(() => "Error raised from line " + e.lineNumber);
|
||||
this.debug.debug(() => e);
|
||||
} catch (e: any) {
|
||||
this.log.log(e);
|
||||
} finally {
|
||||
this.entered = false;
|
||||
}
|
||||
@ -370,7 +354,7 @@ export class KWinDriver implements DriverContext {
|
||||
let resizing = false;
|
||||
|
||||
this.connect(client.moveResizedChanged, () => {
|
||||
this.debug.debugObj(() => [
|
||||
this.log.log([
|
||||
"moveResizedChanged",
|
||||
{ window, move: client.move, resize: client.resize },
|
||||
]);
|
||||
|
@ -9,7 +9,7 @@ import Rect from "../util/rect";
|
||||
import { toQRect, toRect } from "../util/kwinutil";
|
||||
import { clip, matchWords } from "../util/func";
|
||||
import Config from "../config";
|
||||
import Debug from "../util/debug";
|
||||
import { Log } from "../util/log";
|
||||
|
||||
export interface DriverWindow {
|
||||
readonly fullScreen: boolean;
|
||||
@ -132,14 +132,13 @@ export class KWinWindow implements DriverWindow {
|
||||
private qml: Bismuth.Qml.Main;
|
||||
private kwinApi: KWin.Api;
|
||||
private config: Config;
|
||||
private debug: Debug;
|
||||
|
||||
constructor(
|
||||
client: KWin.Client,
|
||||
qml: Bismuth.Qml.Main,
|
||||
kwinApi: KWin.Api,
|
||||
config: Config,
|
||||
debug: Debug
|
||||
private log: Log
|
||||
) {
|
||||
this.client = client;
|
||||
this.id = KWinWindow.generateID(client);
|
||||
@ -149,7 +148,6 @@ export class KWinWindow implements DriverWindow {
|
||||
this.qml = qml;
|
||||
this.kwinApi = kwinApi;
|
||||
this.config = config;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public commit(
|
||||
@ -157,10 +155,7 @@ export class KWinWindow implements DriverWindow {
|
||||
noBorder?: boolean,
|
||||
keepAbove?: boolean
|
||||
): void {
|
||||
this.debug.debugObj(() => [
|
||||
"KWinWindow#commit",
|
||||
{ geometry, noBorder, keepAbove },
|
||||
]);
|
||||
this.log.log(["KWinWindow#commit", { geometry, noBorder, keepAbove }]);
|
||||
|
||||
if (this.client.move || this.client.resize) {
|
||||
return;
|
||||
|
@ -11,7 +11,7 @@ import Config from "../config";
|
||||
import { Controller } from "../controller";
|
||||
import { DriverSurface } from "../driver/surface";
|
||||
|
||||
import Debug from "../util/debug";
|
||||
import { Log } from "../util/log";
|
||||
import Rect from "../util/rect";
|
||||
import TileLayout from "./layout/tile_layout";
|
||||
import LayoutStore from "./layout_store";
|
||||
@ -25,9 +25,9 @@ describe("arrange", () => {
|
||||
const fakeScreens = [screenMock, screenMock, screenMock, screenMock];
|
||||
|
||||
const controllerMock = createMock<Controller>({ screens: fakeScreens });
|
||||
const debugMock = createMock<Debug>();
|
||||
const logMock = createMock<Log>();
|
||||
const configMock = createMock<Config>();
|
||||
const engine = new TilingEngine(controllerMock, configMock, debugMock);
|
||||
const engine = new TilingEngine(controllerMock, configMock, logMock);
|
||||
|
||||
jest.spyOn(engine, "arrangeScreen").mockReturnValue();
|
||||
|
||||
@ -43,9 +43,9 @@ describe("arrangeScreen", () => {
|
||||
describe("window states are correctly changed", () => {
|
||||
// Arrange
|
||||
const controllerMock = createMock<Controller>();
|
||||
const debugMock = createMock<Debug>();
|
||||
const logMock = createMock<Log>();
|
||||
const configMock = createMock<Config>();
|
||||
const engine = new TilingEngine(controllerMock, configMock, debugMock);
|
||||
const engine = new TilingEngine(controllerMock, configMock, logMock);
|
||||
|
||||
const window1 = createMock<Window>({
|
||||
shouldFloat: false,
|
||||
|
@ -18,7 +18,7 @@ import Rect from "../util/rect";
|
||||
import RectDelta from "../util/rectdelta";
|
||||
import { overlap, wrapIndex } from "../util/func";
|
||||
import Config from "../config";
|
||||
import Debug from "../util/debug";
|
||||
import { Log } from "../util/log";
|
||||
import { WindowsLayout } from "./layout";
|
||||
|
||||
export type Direction = "up" | "down" | "left" | "right";
|
||||
@ -79,7 +79,7 @@ export class TilingEngine implements Engine {
|
||||
constructor(
|
||||
private controller: Controller,
|
||||
private config: Config,
|
||||
private debug: Debug
|
||||
private log: Log
|
||||
) {
|
||||
this.layouts = new LayoutStore(this.config);
|
||||
this.windows = new WindowStore();
|
||||
@ -236,7 +236,7 @@ export class TilingEngine implements Engine {
|
||||
* Arrange tiles on all screens.
|
||||
*/
|
||||
public arrange(): void {
|
||||
this.debug.debug(() => "arrange");
|
||||
this.log.log("arrange");
|
||||
|
||||
this.controller.screens.forEach((driverSurface: DriverSurface) => {
|
||||
this.arrangeScreen(driverSurface);
|
||||
@ -255,7 +255,7 @@ export class TilingEngine implements Engine {
|
||||
const tilingArea = this.getTilingArea(workingArea, layout);
|
||||
|
||||
const visibleWindows = this.windows.getVisibleWindows(screenSurface);
|
||||
this.debug.debugObj(() => [
|
||||
this.log.log([
|
||||
"arrangeScreen",
|
||||
{
|
||||
layout,
|
||||
@ -304,7 +304,7 @@ export class TilingEngine implements Engine {
|
||||
|
||||
// Commit window assigned properties
|
||||
visibleWindows.forEach((win: Window) => win.commit());
|
||||
this.debug.debugObj(() => ["arrangeScreen/finished", { screenSurface }]);
|
||||
this.log.log(["arrangeScreen/finished", { screenSurface }]);
|
||||
}
|
||||
|
||||
public currentLayoutOnCurrentSurface(): WindowsLayout {
|
||||
|
@ -65,7 +65,6 @@ export default class MonocleLayout implements WindowsLayout {
|
||||
) {
|
||||
engine.focusOrder(1, this.config.monocleMinimizeRest);
|
||||
} else {
|
||||
console.log("Executing from Monocle regular action!");
|
||||
action.executeWithoutLayoutOverride();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { DriverWindow } from "../driver/window";
|
||||
import { DriverSurface } from "../driver/surface";
|
||||
|
||||
import Config from "../config";
|
||||
import Debug from "../util/debug";
|
||||
import { Log } from "../util/log";
|
||||
import Rect from "../util/rect";
|
||||
import RectDelta from "../util/rectdelta";
|
||||
|
||||
@ -163,11 +163,9 @@ export default class Window {
|
||||
private weightMap: { [key: string]: number };
|
||||
|
||||
private config: Config;
|
||||
private debug: Debug;
|
||||
|
||||
constructor(window: DriverWindow, config: Config, debug: Debug) {
|
||||
constructor(window: DriverWindow, config: Config, private log: Log) {
|
||||
this.config = config;
|
||||
this.debug = debug;
|
||||
|
||||
this.id = window.id;
|
||||
this.window = window;
|
||||
@ -183,7 +181,7 @@ export default class Window {
|
||||
|
||||
public commit(): void {
|
||||
const state = this.state;
|
||||
this.debug.debugObj(() => ["Window#commit", { state: WindowState[state] }]);
|
||||
this.log.log(["Window#commit", { state: WindowState[state] }]);
|
||||
switch (state) {
|
||||
case WindowState.NativeMaximized:
|
||||
this.window.commit(undefined, undefined, false);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import { ConfigImpl } from "./config";
|
||||
import { TilingController } from "./controller";
|
||||
import Debug from "./util/debug";
|
||||
import { LogImpl } from "./util/log";
|
||||
|
||||
/**
|
||||
* Script entry-point from QML side.
|
||||
@ -16,13 +16,13 @@ export function init(
|
||||
kwinScriptingApi: KWin.Api
|
||||
): void {
|
||||
const config = new ConfigImpl(kwinScriptingApi);
|
||||
const debug = new Debug(config);
|
||||
const logger = new LogImpl(config);
|
||||
|
||||
const controller = new TilingController(
|
||||
qmlObjects,
|
||||
kwinScriptingApi,
|
||||
config,
|
||||
debug
|
||||
logger
|
||||
);
|
||||
|
||||
controller.start();
|
||||
|
@ -1,36 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
|
||||
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Config from "../config";
|
||||
|
||||
export default class Debug {
|
||||
private enabled: boolean;
|
||||
private started: number;
|
||||
|
||||
constructor(config: Config) {
|
||||
this.enabled = config.debugEnabled;
|
||||
this.started = new Date().getTime();
|
||||
}
|
||||
|
||||
public debug(f: () => any): void {
|
||||
if (this.enabled) {
|
||||
const timestamp = (new Date().getTime() - this.started) / 1000;
|
||||
console.log(`[${timestamp}]`, f());
|
||||
}
|
||||
}
|
||||
|
||||
public debugObj(f: () => [string, any]): void {
|
||||
if (this.enabled) {
|
||||
const timestamp = (new Date().getTime() - this.started) / 1000;
|
||||
const [name, obj] = f();
|
||||
const buf = [];
|
||||
for (const i in obj) {
|
||||
buf.push(`${i}=${obj[i]}`);
|
||||
}
|
||||
|
||||
console.log(`[${timestamp}]`, `${name}: ${buf.join(" ")}`);
|
||||
}
|
||||
}
|
||||
}
|
87
src/util/log.ts
Normal file
87
src/util/log.ts
Normal file
@ -0,0 +1,87 @@
|
||||
// SPDX-FileCopyrightText: 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
|
||||
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Config from "../config";
|
||||
|
||||
type LogType = string | Record<string, unknown> | LogType[];
|
||||
export interface Log {
|
||||
log(str: LogType): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard logger
|
||||
*/
|
||||
export class LogImpl implements Log {
|
||||
private enabled: boolean;
|
||||
private started: number;
|
||||
|
||||
constructor(config: Config) {
|
||||
this.enabled = config.debugEnabled;
|
||||
this.started = new Date().getTime();
|
||||
}
|
||||
|
||||
public log(logObj: LogType): void {
|
||||
if (this.enabled) {
|
||||
this.doLog(logObj);
|
||||
}
|
||||
}
|
||||
|
||||
private doLog(logObj: LogType): void {
|
||||
if (Object.prototype.toString.call(logObj) === "[object Array]") {
|
||||
// If log object is an array
|
||||
this.logArray(logObj as LogType[]);
|
||||
} else if (typeof logObj == "string") {
|
||||
this.logString(logObj);
|
||||
} else if (typeof logObj == "object") {
|
||||
this.logObject(logObj as Record<string, unknown>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs object (without deep inspection)
|
||||
* @param obj object to log
|
||||
*/
|
||||
private logObject(obj: Record<string, unknown>): void {
|
||||
// NOTE: be aware, that constructor name could change if minification is used
|
||||
const objectName = obj.constructor.name;
|
||||
const logQueue = [];
|
||||
for (const i in obj) {
|
||||
logQueue.push(`${i}: ${obj[i]}`);
|
||||
}
|
||||
|
||||
this.logString(`${objectName}: ${logQueue.join(", ")}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs string
|
||||
* @param str string to log
|
||||
*/
|
||||
private logString(str: string): void {
|
||||
console.log(`[Bismuth] [${this.now()}] ${str}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sequentially logs the contents of the array
|
||||
* @param arr array to log
|
||||
*/
|
||||
private logArray(arr: LogType[]): void {
|
||||
for (const element of arr) {
|
||||
this.doLog(element);
|
||||
}
|
||||
}
|
||||
|
||||
private now(): number {
|
||||
return (new Date().getTime() - this.started) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Null log, that does not output anything
|
||||
*/
|
||||
export class NullLog implements Log {
|
||||
public log(_str: LogType): void {
|
||||
// NOP
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user