From c6a611fd42184d7388d0d55b23eacaf96ff0e9a8 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Mon, 4 Oct 2021 14:35:17 +0100 Subject: [PATCH] move tab to left/right of screen --- desktop/desktop.cpp | 29 ++++++++++++++++++++++++----- desktop/gui.cpp | 4 ++-- shared/strings.cpp | 4 +++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/desktop/desktop.cpp b/desktop/desktop.cpp index 461bae8..366e06f 100644 --- a/desktop/desktop.cpp +++ b/desktop/desktop.cpp @@ -821,16 +821,35 @@ int WindowTabMessage(EsElement *element, EsMessage *message) { EsElementSetDisabled(band->GetChild(0), false); } else if (message->type == ES_MSG_MOUSE_RIGHT_CLICK) { EsMenu *menu = EsMenuCreate(tab, ES_FLAGS_DEFAULT); + uint64_t disableIfOnlyTab = tab->container->tabBand->items.Length() == 1 ? ES_ELEMENT_DISABLED : ES_FLAGS_DEFAULT; EsMenuAddItem(menu, ES_FLAGS_DEFAULT, INTERFACE_STRING(DesktopCloseTab), [] (EsMenu *, EsGeneric context) { WindowTabClose((WindowTab *) context.p); }, tab); - if (tab->container->tabBand->items.Length() > 1) { - EsMenuAddItem(menu, ES_FLAGS_DEFAULT, INTERFACE_STRING(DesktopMoveTabToNewWindow), [] (EsMenu *, EsGeneric context) { - WindowTabMoveToNewContainer((WindowTab *) context.p, nullptr, 0, 0); - }, tab); - } + EsMenuAddItem(menu, disableIfOnlyTab, INTERFACE_STRING(DesktopMoveTabToNewWindow), [] (EsMenu *, EsGeneric context) { + WindowTabMoveToNewContainer((WindowTab *) context.p, nullptr, 0, 0); + }, tab); + + EsMenuAddItem(menu, disableIfOnlyTab, INTERFACE_STRING(DesktopMoveTabToNewWindowSplitLeft), [] (EsMenu *, EsGeneric context) { + WindowTab *oldTab = (WindowTab *) context.p; + EsWindow *oldWindow = oldTab->window; + WindowTab *newTab = WindowTabMoveToNewContainer(oldTab, nullptr, 0, 0); + if (!newTab) return; + if (oldWindow->isMaximised) WindowRestore(oldWindow, false); + WindowSnap(oldWindow, false, false, SNAP_EDGE_RIGHT); + WindowSnap(newTab->window, false, false, SNAP_EDGE_LEFT); + }, tab); + + EsMenuAddItem(menu, disableIfOnlyTab, INTERFACE_STRING(DesktopMoveTabToNewWindowSplitRight), [] (EsMenu *, EsGeneric context) { + WindowTab *oldTab = (WindowTab *) context.p; + EsWindow *oldWindow = oldTab->window; + WindowTab *newTab = WindowTabMoveToNewContainer(oldTab, nullptr, 0, 0); + if (!newTab) return; + if (oldWindow->isMaximised) WindowRestore(oldWindow, false /* we immediately move the window after this */); + WindowSnap(oldWindow, false, false, SNAP_EDGE_LEFT); + WindowSnap(newTab->window, false, false, SNAP_EDGE_RIGHT); + }, tab); if (EsKeyboardIsShiftHeld()) { EsMenuAddSeparator(menu); diff --git a/desktop/gui.cpp b/desktop/gui.cpp index 0cee3f8..6011758 100644 --- a/desktop/gui.cpp +++ b/desktop/gui.cpp @@ -554,14 +554,14 @@ void WindowSnap(EsWindow *window, bool restored, bool dragging, uint8_t edge) { } } -void WindowRestore(EsWindow *window) { +void WindowRestore(EsWindow *window, bool dynamic = true) { if (!window->restoreOnNextMove) { return; } window->isMaximised = false; window->restoreOnNextMove = false; - EsSyscall(ES_SYSCALL_WINDOW_MOVE, window->handle, (uintptr_t) &window->beforeMaximiseBounds, 0, ES_WINDOW_MOVE_DYNAMIC); + EsSyscall(ES_SYSCALL_WINDOW_MOVE, window->handle, (uintptr_t) &window->beforeMaximiseBounds, 0, dynamic ? ES_WINDOW_MOVE_DYNAMIC : ES_FLAGS_DEFAULT); } void WindowChangeBounds(int direction, int newX, int newY, int *originalX, int *originalY, EsWindow *window, diff --git a/shared/strings.cpp b/shared/strings.cpp index f515dfa..ba2970e 100644 --- a/shared/strings.cpp +++ b/shared/strings.cpp @@ -97,7 +97,9 @@ DEFINE_INTERFACE_STRING(DesktopNotResponding, "The application is not responding DEFINE_INTERFACE_STRING(DesktopConfirmShutdown, "Are you sure you want to turn off your computer? All applications will be closed."); DEFINE_INTERFACE_STRING(DesktopCloseTab, "Close tab"); -DEFINE_INTERFACE_STRING(DesktopMoveTabToNewWindow, "Move to new window"); +DEFINE_INTERFACE_STRING(DesktopMoveTabToNewWindow, "Move tab to new window"); +DEFINE_INTERFACE_STRING(DesktopMoveTabToNewWindowSplitLeft, "Move tab to left of screen"); +DEFINE_INTERFACE_STRING(DesktopMoveTabToNewWindowSplitRight, "Move tab to right of screen"); DEFINE_INTERFACE_STRING(DesktopInspectUI, "Inspect UI"); DEFINE_INTERFACE_STRING(DesktopCloseWindow, "Close window"); DEFINE_INTERFACE_STRING(DesktopCloseAllTabs, "Close all tabs");