Move direct calls to KWin to driver

This commit is contained in:
Eon S. Jeon 2018-11-06 19:44:54 +09:00
parent 38340b00a3
commit 72e4273f5d
2 changed files with 58 additions and 35 deletions

View File

@ -21,7 +21,7 @@
function Screen(id) {
this.id = id;
this.layout = layout_tile; //null;
this.opts = {}
this.layoutOpts = {}
}
function Tile(client) {
@ -77,7 +77,7 @@ function layout_tile(tiles, areaWidth, areaHeight, opts) {
}
}
function TilingEngine() {
function TilingEngine(driver) {
var self = this;
self.tiles = Array();
@ -106,58 +106,40 @@ function TilingEngine() {
if(screen.layout === null)
return;
var desktop = workspace.currentDesktop;
// TODO: move direct calls to KWin to driver.
var area = workspace.clientArea(KWin.PlacementArea, screen.id, desktop);
var area = driver.getWorkingArea(screen.id);
var visibles = self.tiles
.filter(function(t) {
var c = t.client
try {
// TODO: test KWin::Toplevel properties...?
return (
(!c.minimized) &&
(c.desktop == desktop || c.desktop == -1) &&
(c.screen == screen.id)
);
return driver.isClientVisible(t.client, screen.id);
} catch(e) {
t.isError = true;
return false;
}
return false;
});
// TODO: fullscreen handling
screen.layout(visibles, area.width, area.height, screen.layoutOpts);
screen.layout(visibles, area.width, area.height, {});
// TODO: move direct calls to KWin to driver.
visibles.forEach(function(tile) {
tile.client.geometry = {
x: tile.x,
y: tile.y,
width: tile.width,
height: tile.height,
}
driver.setClientGeometry(
tile.client, tile.x, tile.y, tile.width, tile.height);
});
});
}
self.arrangeClient = function(client) {
// TODO: move direct calls to KWin to driver.
self.tiles.forEach(function(tile) {
if(tile.client != client) return;
if(client.geometry.x == tile.x)
if(client.geometry.y == tile.y)
if(client.geometry.width == tile.width)
if(client.geometry.height == tile.height)
var geometry = driver.getClientGeometry(tile.client);
if(geometry.x == tile.x)
if(geometry.y == tile.y)
if(geometry.width == tile.width)
if(geometry.height == tile.height)
return;
tile.client.geometry = {
x: tile.x,
y: tile.y,
width: tile.width,
height: tile.height,
}
driver.setClientGeometry(
tile.client, tile.x, tile.y, tile.width, tile.height);
});
}

View File

@ -22,8 +22,12 @@ function KWinDriver() {
var self = this;
var engine = null;
/*
* Signal handlers
*/
self._onClientAdded = function(client) {
print("clientAdded " + client);
print("clientAdded " + client + " " + client.resourceClass);
// TODO: check resourceClasses for some windows
if(!engine.manage(client))
@ -60,6 +64,43 @@ function KWinDriver() {
engine.removeScreen(engine.screens.length - 1);
};
/*
* Utils
*/
self.getWorkingArea = function(screenId) {
// TODO: verify: can each desktops have a different placement area?
return workspace.clientArea(
KWin.PlacementArea, screenId, workspace.currentDesktop);
}
self.getClientGeometry = function(client) {
return {
x: client.geometry.x,
y: client.geometry.y,
width: client.geometry.width,
height: client.geometry.height
};
}
self.setClientGeometry = function(client, x, y, width, height) {
client.geometry = { x:x, y:y, width:width, height:height };
}
self.isClientVisible = function(client, screenId) {
// TODO: test KWin::Toplevel properties...?
return (
(!client.minimized) &&
(client.desktop == workspace.currentDesktop
|| client.desktop == -1 /* on all desktop */) &&
(client.screen == screenId)
);
}
/*
* Main
*/
self.main = function() {
engine = new TilingEngine(self);