Skip to content

Commit

Permalink
fix gaps on quick tiling not working; simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
nclarius committed Jan 27, 2022
1 parent f4e45f5 commit e0830a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v6.7

- fix gaps on quick tiling not working
- simplify code

## v6.6

- compute tolerance margin automatically from the gap size instead of using a configuration variable
Expand Down
71 changes: 32 additions & 39 deletions contents/code/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const config = {
debugMode = true;
function debug(...args) {if (debugMode) console.debug("Window Gaps:", ...args);}
debug("intializing");
function debug_(...args) {if (debugMode) console.debug("\nWindow Gaps:", ...args);}
debug("sizes (t/l/r/b/m):", config.gapTop, config.gapLeft, config.gapRight, config.gapBottom, config.gapMid);
debug("layout:", "maximized:", config.includeMaximized);
debug("applications:", "exclude:", config.excludeMode, String(config.excludedApps), "include:", config.includeMode, String(config.includedApps));
Expand All @@ -61,7 +60,7 @@ function caption(client) {
workspace.clientList().forEach(client => onAdded(client));
workspace.clientAdded.connect(onAdded);
function onAdded(client) {
debug("added", caption(client));
debug_("added", caption(client));
applyGaps(client);

onRegeometrized(client);
Expand All @@ -76,19 +75,19 @@ function onRegeometrized(client) {
// client.clientGeometryChanged.connect((client) =>
// // { debug_("client geometry changed", caption(client)); applyGaps(client); });
client.frameGeometryChanged.connect((client) =>
{ debug_("frame geometry changed", caption(client), client.resourceClass || client)});
{ debug("frame geometry changed", caption(client)); applyGaps(client)});
client.clientFinishUserMovedResized.connect((client) =>
{ debug_("finish user moved resized", caption(client)); applyGaps(client); });
{ debug("finish user moved resized", caption(client)); applyGaps(client); });
client.fullScreenChanged.connect((client) =>
{ debug_("fullscreen changed", caption(client)); applyGaps(client); });
{ debug("fullscreen changed", caption(client)); applyGaps(client); });
client.clientMaximizedStateChanged.connect((client) =>
{ debug_("maximized changed", caption(client)); applyGaps(client); });
{ debug("maximized changed", caption(client)); applyGaps(client); });
client.clientUnminimized.connect((client) =>
{ debug_("unminimized", caption(client)); applyGaps(client); });
{ debug("unminimized", caption(client)); applyGaps(client); });
client.screenChanged.connect((client) =>
{ debug_("screen changed", caption(client)); applyGaps(client); });
{ debug("screen changed", caption(client)); applyGaps(client); });
client.desktopChanged.connect((client) =>
{ debug_("desktop changed", caption(client)); applyGaps(client); });
{ debug("desktop changed", caption(client)); applyGaps(client); });
}

// trigger reapplying tile gaps for all windows when screen geometry changes
Expand All @@ -99,25 +98,25 @@ function applyGapsAll() {
onRelayouted();
function onRelayouted() {
workspace.currentDesktopChanged.connect(() =>
{ debug_("current desktop changed"); applyGapsAll(); });
{ debug("current desktop changed"); applyGapsAll(); });
workspace.desktopPresenceChanged.connect(() =>
{ debug_("desktop presence changed"); applyGapsAll(); });
{ debug("desktop presence changed"); applyGapsAll(); });
workspace.numberDesktopsChanged.connect(() =>
{ debug_("number desktops changed"); applyGapsAll(); });
{ debug("number desktops changed"); applyGapsAll(); });
workspace.numberScreensChanged.connect(() =>
{ debug_("number screens changed"); applyGapsAll(); });
{ debug("number screens changed"); applyGapsAll(); });
workspace.screenResized.connect(() =>
{ debug_("screen reszed"); applyGapsAll(); });
{ debug("screen reszed"); applyGapsAll(); });
workspace.currentActivityChanged.connect(() =>
{ debug_("current activity changed"); applyGapsAll(); });
{ debug("current activity changed"); applyGapsAll(); });
workspace.activitiesChanged.connect(() =>
{ debug_("activities changed"); applyGapsAll(); });
{ debug("activities changed"); applyGapsAll(); });
workspace.virtualScreenSizeChanged.connect(() =>
{ debug_("virtual screen size changed"); applyGapsAll(); });
{ debug("virtual screen size changed"); applyGapsAll(); });
workspace.virtualScreenGeometryChanged.connect(() =>
{ debug_("virtual screen geometry changed"); applyGapsAll(); });
{ debug("virtual screen geometry changed"); applyGapsAll(); });
workspace.clientAdded.connect((client) => { if (client.dock) {
debug_("dock added"); applyGapsAll(); }});
debug("dock added"); applyGapsAll(); }});
}


Expand All @@ -127,20 +126,16 @@ function onRelayouted() {

// make tile gaps for given client
function applyGaps(client) {
// abort if there is a current iteration of gapping still running
if (block) return;
// abort if client is irrelevant
if (client == null || client == undefined) return;
if (ignoreClient(client)) return;
// abort if there is a current iteration of gapping still running, the client is null or irrelevant
if (block || !client || ignoreClient(client)) return;
block = true;
debug("gaps for", client.caption, client.geometry);
// make tile gaps to area grid
debug("area gaps for", client.caption);
applyGapsArea(client);
// make tile gaps to other windows
debug("windows gaps for", client.caption);
applyGapsWindows(client);
block = false;
debug("");
}

function applyGapsArea(client) {
Expand Down Expand Up @@ -168,8 +163,8 @@ function applyGapsArea(client) {
var coords = grid.right[pos];
if (nearArea(win.right, coords, config.gapRight)) {
debug("gap to right tile edge", pos);
var diff = coords.gapped - win.right;
win.width += diff;
var diff = win.right - coords.gapped;
win.width -= diff;
break;
}
}
Expand All @@ -191,11 +186,10 @@ function applyGapsArea(client) {
for (var i = 0; i < Object.keys(grid.bottom).length; i++) {
var pos = Object.keys(grid.bottom)[i];
var coords = grid.bottom[pos];
debug(pos, coords.closed, coords.gapped, win.bottom, config.gapBottom);
if (nearArea(win.bottom, coords, config.gapBottom)) {
debug("gap to bottom tile edge", pos);
var diff = coords.gapped - win.bottom;
win.height += diff;
var diff = win.bottom - coords.gapped;
win.height -= diff;
break;
}
}
Expand All @@ -205,9 +199,8 @@ function applyGapsWindows(client1) {
// get relevant other windows
for (var i = 0; i < workspace.clientList().length; i++) {
var client2 = workspace.clientList()[i];
if (client2 == null || client2 == undefined) continue;
if (!client2) continue;
if (ignoreOther(client1, client2)) continue;
debug("other window", client2.caption, client2.geometry);

var win1 = client1.geometry;
var win2 = client2.geometry;
Expand Down Expand Up @@ -264,9 +257,9 @@ function getArea(client) {
width: clientArea.width - config.offsetLeft - config.offsetRight,
height: clientArea.height - config.offsetTop - config.offsetBottom,
left: clientArea.x + config.offsetLeft,
right: clientArea.x + clientArea.width - config.offsetRight,
right: clientArea.x + clientArea.width - config.offsetRight - 1,
top: clientArea.y + config.offsetTop,
bottom: clientArea.y + clientArea.height - config.offsetBottom,
bottom: clientArea.y + clientArea.height - config.offsetBottom - 1,
};
}

Expand Down Expand Up @@ -356,8 +349,8 @@ function getGrid(client) {

// a coordinate is close to another iff the difference is within the tolerance margin but not exactly the desired geometry
function nearArea(actual, expected, gap) {
return (Math.abs(actual - expected.closed) <= gap
|| Math.abs(actual - expected.gapped) <= gap)
return (Math.abs(actual - expected.closed) <= 2 * gap
|| Math.abs(actual - expected.gapped) <= 2 * gap)
&& actual != expected.gapped;
}

Expand Down Expand Up @@ -408,9 +401,9 @@ function halfGapU() {

// filter out irrelevant clients
function ignoreClient(client) {
return client == null || client == undefined // undefined
return !client // null
|| !client.normalWindow // non-normal window
|| ["plasmashell", "krunner", "kruler"].includes(String(client.resourceClass)) // non-normal application
|| ["plasmashell", "krunner"].includes(String(client.resourceClass)) // non-normal application
|| client.move || client.resize // still undergoing geometry change
|| client.fullScreen // fullscreen
|| (!config.includeMaximized
Expand Down
2 changes: 1 addition & 1 deletion metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Comment[de]=Fügt Zwischenraum um Fenster ein, die einen Bildschirmrand oder ein
Icon=preferences-system-windows

X-KDE-PluginInfo-Name=tilegaps
X-KDE-PluginInfo-Version=6.6
X-KDE-PluginInfo-Version=6.7
X-KDE-PluginInfo-Author=Natalie Clarius
X-KDE-PluginInfo-Email[email protected]
X-KDE-PluginInfo-License=GPL v3.0
Expand Down

0 comments on commit e0830a8

Please sign in to comment.