mirror of
https://github.com/ducbao414/win32.run.git
synced 2025-12-16 17:22:51 +09:00
auto nudging newly launched windows to prevent them from completely overlapping previous ones.
This commit is contained in:
@@ -26,9 +26,13 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if(options.exec_path != null){
|
if(options.exec_path != null){
|
||||||
let rect = await get(options.exec_path);
|
let rect = await get(options.exec_path);
|
||||||
console.log(rect);
|
|
||||||
if(rect){
|
if(rect){
|
||||||
|
rect = {top: rect.top, left: rect.left, width: rect.width, height: rect.height};
|
||||||
let workspace = document.querySelector('#work-space');
|
let workspace = document.querySelector('#work-space');
|
||||||
|
let nudge = calc_nudges(rect);
|
||||||
|
rect.top = rect.top + nudge.top;
|
||||||
|
rect.left = rect.left + nudge.left;
|
||||||
|
|
||||||
if(rect.left + rect.width <= workspace.offsetWidth
|
if(rect.left + rect.width <= workspace.offsetWidth
|
||||||
&& rect.top + rect.height <= workspace.offsetHeight){
|
&& rect.top + rect.height <= workspace.offsetHeight){
|
||||||
options.top = rect.top;
|
options.top = rect.top;
|
||||||
@@ -45,7 +49,7 @@
|
|||||||
if(options.left == null){
|
if(options.left == null){
|
||||||
options.left = (node_ref.parentNode.offsetWidth - node_ref.offsetWidth)/2;
|
options.left = (node_ref.parentNode.offsetWidth - node_ref.offsetWidth)/2;
|
||||||
}
|
}
|
||||||
set_position({top: options.top, left: options.left, width: node_ref.width, height: node_ref.height});
|
set_position({top: options.top, left: options.left, width: options.width, height: options.height});
|
||||||
|
|
||||||
if(options.resizable == null){
|
if(options.resizable == null){
|
||||||
options.resizable = true;
|
options.resizable = true;
|
||||||
@@ -115,8 +119,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function loose_focus(){
|
export function loose_focus(){
|
||||||
if(z_index == $zIndex){
|
if(z_index == $zIndex){
|
||||||
console.log('loose focus');
|
console.log('loose focus');
|
||||||
@@ -124,6 +126,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calc_nudges({top, left, width, height}){
|
||||||
|
let existing_window = $runningPrograms.findLast(el => {
|
||||||
|
return el.options.id != options.id
|
||||||
|
&& el.options.exec_path == options.exec_path;
|
||||||
|
});
|
||||||
|
if(existing_window == null) return {top: 0, left: 0}
|
||||||
|
|
||||||
|
let pad = 10;
|
||||||
|
let nudges = [[pad, pad], [pad, -pad], [-pad, pad], [-pad, -pad], [0, 0]];
|
||||||
|
let workspace = document.querySelector('#work-space');
|
||||||
|
for(let nudge of nudges){
|
||||||
|
if(top + nudge[0] >= 0
|
||||||
|
&& left + nudge[1] >= 0
|
||||||
|
&& top + height + nudge[0] <= workspace.offsetHeight
|
||||||
|
&& left + width + nudge[1] <= workspace.offsetWidth){
|
||||||
|
return {top: nudge[0], left: nudge[1]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {top: 0, left: 0};
|
||||||
|
}
|
||||||
|
|
||||||
function get_center_point(rect){
|
function get_center_point(rect){
|
||||||
if(rect == null){
|
if(rect == null){
|
||||||
return {x: document.body.offsetWidth*0.5, y: document.body.offsetHeight*0.5}
|
return {x: document.body.offsetWidth*0.5, y: document.body.offsetHeight*0.5}
|
||||||
@@ -139,6 +162,10 @@
|
|||||||
node_ref.style.left = `${left}px`;
|
node_ref.style.left = `${left}px`;
|
||||||
node_ref.style.width = `${width}px`;
|
node_ref.style.width = `${width}px`;
|
||||||
node_ref.style.height = `${height}px`;
|
node_ref.style.height = `${height}px`;
|
||||||
|
|
||||||
|
if(options.exec_path){
|
||||||
|
set(options.exec_path, node_ref.getBoundingClientRect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user