Skip to content

Commit

Permalink
Change snapping behavior based on desktop presence
Browse files Browse the repository at this point in the history
This will allow custom desktops to be created.
Soon, I should add a feature to change snap distance parameters.
  • Loading branch information
datkat21 committed Jan 12, 2024
1 parent 85816d3 commit ff1b5c7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkgs/lib/WindowSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ let lib = {};
let core = {};
let Html;

function checkDesktopPresence() {
return (
core.processList
.filter((n) => n !== null)
.find((n) => n.name === "ui:Desktop") !== undefined
);
}

function getWindowObjectById(id) {
return core.windowsList.find((window) => window.options.id === id);
}
Expand Down Expand Up @@ -64,12 +72,12 @@ export default {
this.options.height = 200;
}
if (this.options.width > window.innerWidth) {
this.options.width = window.innerWidth - (snapBoxMargin * 2);
this.options.left = snapBoxMargin + 'px';
this.options.width = window.innerWidth - snapBoxMargin * 2;
this.options.left = snapBoxMargin + "px";
}
if (this.options.height > window.innerHeight) {
this.options.height = window.innerHeight - (snapBoxMargin * 2) - 48;
this.options.top = snapBoxMargin + 'px';
this.options.height = window.innerHeight - snapBoxMargin * 2 + (checkDesktopPresence() ? -48 : 0);
this.options.top = snapBoxMargin + "px";
}
if (!this.options.minWidth) {
this.options.minWidth = 185;
Expand Down Expand Up @@ -281,7 +289,7 @@ export default {
this.window.style.width =
Math.floor(this.window.parentNode.offsetWidth / 2) + "px";
this.window.style.height =
this.window.parentNode.offsetHeight - 54 + "px";
this.window.parentNode.offsetHeight + (checkDesktopPresence() ? -54 : 0) + "px";
this.window.style.top = 0;
this.window.style.left = 0;
this.window.classList.toggle("snapped");
Expand All @@ -293,7 +301,7 @@ export default {
Math.floor(this.window.parentNode.offsetWidth / 2) + "px";
// Height is height of parent minus dock height
this.window.style.height =
this.window.parentNode.offsetHeight - 54 + "px";
this.window.parentNode.offsetHeight + (checkDesktopPresence() ? -54 : 0) + "px";
// Top is top of screen (0)
this.window.style.top = 0;
// Left is the parent width minus the new window width
Expand Down

0 comments on commit ff1b5c7

Please sign in to comment.