From a68f0edc41e7f1a2ff183bc104c7c9f3e8705d71 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Thu, 4 Sep 2025 19:36:03 -0700 Subject: [PATCH] Don't allow items to be dragged out of the viewport --- src/gui/src/UI/UIDesktop.js | 4 ++++ src/gui/src/UI/UIItem.js | 22 ++++++++++++++++++++-- src/gui/src/UI/UIWindow.js | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/gui/src/UI/UIDesktop.js b/src/gui/src/UI/UIDesktop.js index fa64e9253..6e5a96c68 100644 --- a/src/gui/src/UI/UIDesktop.js +++ b/src/gui/src/UI/UIDesktop.js @@ -1655,6 +1655,10 @@ async function UIDesktop(options) { if(window.desktop_selectable_is_active) return; + // if an item is being dragged, don't show the toolbar + if(window.an_item_is_being_dragged) + return; + if(window.is_fullpage_mode) $('.window-app-iframe').css('pointer-events', 'none'); diff --git a/src/gui/src/UI/UIItem.js b/src/gui/src/UI/UIItem.js index 092c64341..352313bac 100644 --- a/src/gui/src/UI/UIItem.js +++ b/src/gui/src/UI/UIItem.js @@ -279,8 +279,20 @@ function UIItem(options){ // reset longer hover timeout and last window dragged over longer_hover_timeout = null; last_window_dragged_over = null; + + window.an_item_is_being_dragged = true; + $('.toolbar').css('pointer-events', 'none'); }, drag: function(event, ui) { + // Constrain item within desktop bounds + const minLeft = -50; + const maxLeft = window.desktop_width - 50; + const minTop = window.toolbar_height; + const maxTop = window.desktop_height + window.toolbar_height - 50; + + // Apply constraints to ui.position + ui.position.top = Math.max(minTop, Math.min(maxTop, ui.position.top)); + // Only show drag helpers if the item has been moved more than 5px if( Math.abs(ui.originalPosition.top - ui.offset.top) > 5 || @@ -301,9 +313,13 @@ function UIItem(options){ // Move other selected items for(let i=0; i < item_count - 1; i++){ + // Apply same constraints to cloned items with their offset + const cloneLeft = Math.max(minLeft, Math.min(maxLeft, ui.position.left + 3 * (i+1))); + const cloneTop = Math.max(minTop, Math.min(maxTop, ui.position.top + 3 * (i+1))); + $(other_selected_items[i]).css({ - 'left': ui.position.left + 3 * (i+1), - 'top': ui.position.top + 3 * (i+1), + 'left': cloneLeft, + 'top': cloneTop, 'z-index': 999 - (i), 'opacity': 0.5 - i*0.1, }) @@ -373,6 +389,8 @@ function UIItem(options){ // reset longer hover timeout and last window dragged over clearTimeout(longer_hover_timeout); last_window_dragged_over = null; + window.an_item_is_being_dragged = false; + $('.toolbar').css('pointer-events', 'auto'); } }); diff --git a/src/gui/src/UI/UIWindow.js b/src/gui/src/UI/UIWindow.js index 3fa4f8349..8c481c5f6 100644 --- a/src/gui/src/UI/UIWindow.js +++ b/src/gui/src/UI/UIWindow.js @@ -1754,6 +1754,7 @@ async function UIWindow(options) { $(el_window).draggable({ start: function(e, ui){ window.a_window_is_being_dragged = true; + $('.toolbar').css('pointer-events', 'none'); // if window is snapped, unsnap it and reset its position to where it was before snapping if(options.is_resizable && window_is_snapped){ window_is_snapped = false; @@ -1930,7 +1931,7 @@ async function UIWindow(options) { $(el_window_app_iframe).css('pointer-events', 'all'); $('.window').css('pointer-events', 'initial'); - + $('.toolbar').css('pointer-events', 'auto'); // jqueryui changes the z-index automatically, if the stay_on_top flag is set // make sure window stays on top with the initial zindex though $(`.window[data-stay_on_top="true"]`).each(function(){