Skip to content

Commit

Permalink
Merge branch 'wip'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidosomething committed Mar 11, 2024
2 parents fef0d8a + ad940dc commit 859c146
Show file tree
Hide file tree
Showing 10 changed files with 2,022 additions and 1,724 deletions.
217 changes: 107 additions & 110 deletions contents/code/main.js

Large diffs are not rendered by default.

166 changes: 85 additions & 81 deletions contents/code/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// KWin Mocks
// ===========================================================================

global.print = jest.fn()//.mockImplementation((str) => console.error(str));
global.print = jest.fn(); //.mockImplementation((str) => console.error(str));

global.readConfig = jest.fn().mockImplementation(function (key, defaults) {
return defaults;
Expand All @@ -23,17 +23,19 @@ const ClientRects = {
x: SCREEN_LEFT,
y: 32,
width: SCREEN_WIDTH,
height: 1080 - 32 - 32
height: 1080 - 32 - 32,
},
};

global.workspace = {
/**
* Return workspace minus docks!
*/
clientArea: jest.fn().mockImplementation(function (ClientAreaOption, activeClient) {
return ClientRects[ClientAreaOption];
})
clientArea: jest
.fn()
.mockImplementation(function (ClientAreaOption, activeWindow) {
return ClientRects[ClientAreaOption];
}),
};

const HALF_SCREEN = global.workspace.clientArea('WorkArea').width / 2;
Expand All @@ -55,25 +57,27 @@ it('calls registerShortcut in main', () => {

describe('sanitizeSizes', () => {
it('returns array of filtered floats', () => {
expect(Yanjing.sanitizeSizes('0, 5, 10, x, 111.111, 0, 222.333'))
.toEqual([5, 10, 111.111, 222.333]);
expect(Yanjing.sanitizeSizes('0, 5, 10, x, 111.111, 0, 222.333')).toEqual([
5, 10, 111.111, 222.333,
]);
});
});

describe('sizeToWidth', () => {
it(`should return px value against work area width`, () => {
expect(Yanjing.sizeToWidth(33.333)).toBeCloseTo(615.99384);
expect(Yanjing.sizeToWidth(50))
.toBeCloseTo(HALF_SCREEN);
expect(Yanjing.sizeToWidth(50)).toBeCloseTo(HALF_SCREEN);
});
});

describe('widthToSizeIndex', () => {
it(`should return size index relative to ${global.workspace.workspaceWidth}`, () => {
expect(Yanjing.widthToSizeIndex(640))
.toBe(Yanjing.Sizes.findIndex((s) => s === 33.3333));
expect(Yanjing.widthToSizeIndex(HALF_SCREEN))
.toBe(Yanjing.Sizes.findIndex((s) => s === 50));
expect(Yanjing.widthToSizeIndex(640)).toBe(
Yanjing.Sizes.findIndex((s) => s === 33.3333),
);
expect(Yanjing.widthToSizeIndex(HALF_SCREEN)).toBe(
Yanjing.Sizes.findIndex((s) => s === 50),
);
});
});

Expand Down Expand Up @@ -112,126 +116,127 @@ describe('cycle', () => {

it(`should try to resize`, () => {
jest.spyOn(Yanjing, 'getNextWidth');
const client = {
const win = {
resizeable: true,
geometry: { width: 640 }
frameGeometry: { width: 640 },
};
Yanjing.cycle(client);
Yanjing.cycle(win);
expect(Yanjing.getNextWidth).toHaveBeenCalledTimes(1);
expect(client.geometry.width).toBeCloseTo(462, 0);
expect(win.frameGeometry.width).toBeCloseTo(462, 0);
Yanjing.getNextWidth.mockRestore();
});
});

describe('Move', () => {
describe('Left', () => {
it(`should return NOOP if already left`, () => {
const client = {
geometry: { x: SCREEN_LEFT },
const win = {
frameGeometry: { x: SCREEN_LEFT },
moveable: true,
};
expect(Yanjing.Move[Yanjing.Dirs.Left](client))
.toBe(Yanjing.States.NOOP);
expect(Yanjing.Move[Yanjing.Dirs.Left](win)).toBe(Yanjing.States.NOOP);
});

it(`should ignore immoveable windows`, () => {
const client = {
geometry: { x: 100 },
const win = {
frameGeometry: { x: 100 },
moveable: false,
};
expect(Yanjing.Move[Yanjing.Dirs.Left](client))
.toBe(Yanjing.States.ERROR);
expect(Yanjing.Move[Yanjing.Dirs.Left](win)).toBe(Yanjing.States.ERROR);
});

it(`should try to move`, () => {
const client = {
geometry: { x: 100 },
const win = {
frameGeometry: { x: 100 },
moveable: true,
};
const result = Yanjing.Move[Yanjing.Dirs.Left](client);
const result = Yanjing.Move[Yanjing.Dirs.Left](win);
expect(result).toBe(Yanjing.States.DONE);
expect(client.geometry.x).toBe(SCREEN_LEFT);
expect(win.frameGeometry.x).toBe(SCREEN_LEFT);
});
});

describe('Right', () => {
it(`should return NOOP if already right`, () => {
const maximizedClient = {
geometry: {
const maximizedWin = {
frameGeometry: {
x: SCREEN_LEFT,
width: SCREEN_WIDTH,
},
moveable: true,
};
expect(Yanjing.Move[Yanjing.Dirs.Right](maximizedClient))
.toBe(Yanjing.States.NOOP);
expect(Yanjing.Move[Yanjing.Dirs.Right](maximizedWin)).toBe(
Yanjing.States.NOOP,
);

const flushedClient = {
geometry: { x: 912, width: 1000 },
const flushedWin = {
frameGeometry: { x: 912, width: 1000 },
moveable: true,
};
expect(Yanjing.Move[Yanjing.Dirs.Right](flushedClient))
.toBe(Yanjing.States.NOOP);
expect(Yanjing.Move[Yanjing.Dirs.Right](flushedWin)).toBe(
Yanjing.States.NOOP,
);
});

it(`should ignore immoveable windows`, () => {
const client = {
geometry: { x: 100, width: 100 },
const win = {
frameGeometry: { x: 100, width: 100 },
moveable: false,
};
expect(Yanjing.Move[Yanjing.Dirs.Right](client))
.toBe(Yanjing.States.ERROR);
expect(Yanjing.Move[Yanjing.Dirs.Right](win)).toBe(Yanjing.States.ERROR);
});

it(`should try to move`, () => {
const client = {
geometry: { x: 100, width: 100 },
const win = {
frameGeometry: { x: 100, width: 100 },
moveable: true,
};
const result = Yanjing.Move[Yanjing.Dirs.Right](client);
const result = Yanjing.Move[Yanjing.Dirs.Right](win);
expect(result).toBe(Yanjing.States.DONE);
expect(client.geometry.x).toBe(1812);
expect(win.frameGeometry.x).toBe(1812);
});
});

describe('Center', () => {
it(`should return NOOP if already center`, () => {
const maximizedClient = {
geometry: { x: SCREEN_LEFT, width: SCREEN_WIDTH },
const maximizedWin = {
frameGeometry: { x: SCREEN_LEFT, width: SCREEN_WIDTH },
moveable: true,
};
expect(Yanjing.Move[Yanjing.Dirs.Center](maximizedClient))
.toBe(Yanjing.States.NOOP);

const centeredClient = {
geometry: {
x: SCREEN_LEFT + (SCREEN_WIDTH / 2) - (120 / 2),
width: 120
expect(Yanjing.Move[Yanjing.Dirs.Center](maximizedWin)).toBe(
Yanjing.States.NOOP,
);

const centeredWin = {
frameGeometry: {
x: SCREEN_LEFT + SCREEN_WIDTH / 2 - 120 / 2,
width: 120,
},
moveable: true,
};
expect(Yanjing.Move[Yanjing.Dirs.Center](centeredClient))
.toBe(Yanjing.States.NOOP);
expect(Yanjing.Move[Yanjing.Dirs.Center](centeredWin)).toBe(
Yanjing.States.NOOP,
);
});

it(`should ignore immoveable windows`, () => {
const client = {
geometry: { x: 100, width: 100 },
const win = {
frameGeometry: { x: 100, width: 100 },
moveable: false,
};
expect(Yanjing.Move[Yanjing.Dirs.Center](client))
.toBe(Yanjing.States.ERROR);
expect(Yanjing.Move[Yanjing.Dirs.Center](win)).toBe(Yanjing.States.ERROR);
});

it(`should try to move`, () => {
const client = {
geometry: { x: 100, width: 100 },
const win = {
frameGeometry: { x: 100, width: 100 },
moveable: true,
};
const result = Yanjing.Move[Yanjing.Dirs.Center](client);
const result = Yanjing.Move[Yanjing.Dirs.Center](win);
expect(result).toBe(Yanjing.States.DONE);
expect(client.geometry.x)
.toBe(SCREEN_LEFT + (SCREEN_WIDTH / 2) - (100/2));
expect(win.frameGeometry.x).toBe(
SCREEN_LEFT + SCREEN_WIDTH / 2 - 100 / 2,
);
});
});
});
Expand All @@ -241,25 +246,24 @@ describe('yMax', () => {
const result1 = Yanjing.yMax(null);
expect(result1).toBe(Yanjing.States.ERROR);

const client = {
geometry: { x: 100, height: 200, width: 500 },
const win = {
frameGeometry: { x: 100, height: 200, width: 500 },
moveable: true,
};
const result2 = Yanjing.yMax(client);
const result2 = Yanjing.yMax(win);
expect(result2).toBe(Yanjing.States.ERROR);

});

it('should resize client to workspace work area height', () => {
const client = {
geometry: { x: 100, height: 200, width: 500 },
it('should resize win to workspace work area height', () => {
const win = {
frameGeometry: { x: 100, height: 200, width: 500 },
moveable: true,
resizeable: true,
};
const result = Yanjing.yMax(client);
const result = Yanjing.yMax(win);
expect(result).toBe(Yanjing.States.DONE);
expect(client.geometry.y).toBe(ClientRects.WorkArea.y);
expect(client.geometry.height).toBe(ClientRects.WorkArea.height);
expect(win.frameGeometry.y).toBe(ClientRects.WorkArea.y);
expect(win.frameGeometry.height).toBe(ClientRects.WorkArea.height);
});
});

Expand All @@ -269,21 +273,21 @@ describe('squish', () => {
});

it('should return ERROR if unable to move', () => {
const client = {
const win = {
moveable: false,
};
expect(Yanjing.squish(client, Yanjing.Dirs.Left)).toBe(Yanjing.States.ERROR);
expect(Yanjing.squish(win, Yanjing.Dirs.Left)).toBe(Yanjing.States.ERROR);
});

it('should cycle if did not move', () => {
const client = {
geometry: { x: SCREEN_LEFT },
const win = {
frameGeometry: { x: SCREEN_LEFT },
moveable: true,
};
Yanjing.cycle = jest.fn().mockImplementation(() => 'ok1');
expect(Yanjing.squish(client, Yanjing.Dirs.Left)).toBe('ok1');
expect(Yanjing.squish(win, Yanjing.Dirs.Left)).toBe('ok1');
expect(Yanjing.cycle).toHaveBeenCalledTimes(1);
expect(Yanjing.squish(client, Yanjing.Dirs.Left)).toBe('ok1');
expect(Yanjing.squish(win, Yanjing.Dirs.Left)).toBe('ok1');
expect(Yanjing.cycle).toHaveBeenCalledTimes(2);
Yanjing.cycle.mockRestore();
});
Expand Down
10 changes: 10 additions & 0 deletions contents/config/config.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import QtQuick 2.0
import org.kde.plasma.configuration 2.0

ConfigModel {
ConfigCategory {
name: i18n("General")
icon: "configure"
source: "configGeneral.qml"
}
}
5 changes: 4 additions & 1 deletion contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile name=""/>
<group name="">
<group name="General">
<entry name="maxHeightPercent" type="Int">
<default>100</default>
</entry>
<entry name="sizes" type="StringList">
<default>75,66.6666,50,33.3333,25</default>
</entry>
Expand Down
22 changes: 22 additions & 0 deletions contents/ui/configGeneral.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import QtQuick 2.0
import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.4 as Kirigami

Kirigami.FormLayout {
id: page

property alias cfg_maxHeightPercent: maxHeightPercent.text
property alias cfg_sizes: sizes.text

QQC2.TextField {
id: maxHeightPercent
Kirigami.FormData.label: i18n("Max height percent:")
placeholderText: i18n("100")
}

QQC2.TextField {
id: sizes
Kirigami.FormData.label: i18n("Sizes:")
placeholderText: i18n("75,66.6666,50,33.3333,25")
}
}
4 changes: 3 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"KPackageStructure": "KWin/Script",
"KPlugin": {
"Authors": [
{
Expand All @@ -16,9 +17,10 @@
"ServiceTypes": [
"KWin/Script"
],
"Version": "6.1.2",
"Version": "7.0.0",
"Website": "https://github.com/davidosomething/yanjing"
},
"X-Plasma-API": "javascript",
"X-Plasma-API-Minimum-Version": "6.0",
"X-Plasma-MainScript": "code/main.js"
}
Loading

0 comments on commit 859c146

Please sign in to comment.