Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: open window (from drag) under mouse #1698

Draft
wants to merge 2 commits into
base: v5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/services/drag-and-drop.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,13 @@ export function resetOther(): void {

let dragEndedRecentlyTimeout: number | undefined

let relativeMouseX = 0
let relativeMouseY = 0
export function onDragStart(e: DragEvent): void {
relativeMouseX = e.clientX
relativeMouseY = e.clientY + (window.outerHeight - window.innerHeight) //account for window height
}

export async function onDragEnd(e: DragEvent): Promise<void> {
resetDragPointer()
DnD.resetOther()
Expand Down Expand Up @@ -1237,13 +1244,28 @@ export async function onDragEnd(e: DragEvent): Promise<void> {
return
}

const mouseX = e.screenX
const mouseY = e.screenY
let maximized = false
await browser.windows.getCurrent().then(function (window) {
if (window.state === 'maximized') {
maximized = true
}
})
const fromTabs = info.type === DragType.Tabs
const fromTabsPanel = info.type === DragType.TabsPanel
const fromBookmarks = info.type === DragType.Bookmarks
const fromBookmarksPanel = info.type === DragType.BookmarksPanel

if (fromTabs && info.items?.length) {
const dst = { windowId: NEWID, incognito: Windows.incognito, panelId: info.panelId }
const dst = {
windowId: NEWID,
incognito: Windows.incognito,
panelId: info.panelId,
top: mouseY - relativeMouseY,
left: mouseX - relativeMouseX,
maximized: maximized,
}
if (mode === 'copy') Tabs.open(info.items, dst)
else Tabs.move(info.items, {}, dst)
}
Expand Down
10 changes: 9 additions & 1 deletion src/services/tabs.fg.move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as IPC from 'src/services/ipc'
import * as Popups from 'src/services/popups'
import * as Logs from 'src/services/logs'
import * as Utils from 'src/utils'
import WindowState = browser.windows.WindowState

export async function move(
tabsInfo: DeepReadonly<ItemInfo[]>,
Expand Down Expand Up @@ -57,7 +58,14 @@ export async function move(
if (dst.windowId === NEWID) {
Tabs.detachTabs(tabsInfo.map(t => t.id))
const info = Utils.cloneArray<ItemInfo>(tabsInfo)
const conf = { incognito: dst.incognito, tabId: MOVEID }
const windowState = (dst.maximized === true ? 'maximized' : 'normal') as WindowState
const conf = {
incognito: dst.incognito,
tabId: MOVEID,
top: dst.top,
left: dst.left,
state: windowState,
}
info.forEach(t => (t.panelId = dst.panelId))
IPC.bg('createWindowWithTabs', info, conf).finally(() => Tabs.detachingTabIds.clear())
return
Expand Down
19 changes: 18 additions & 1 deletion src/services/windows.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,24 @@ export async function createWithTabs(
const defaultContainerId = conf.incognito ? PRIVATE_CONTAINER_ID : DEFAULT_CONTAINER_ID
let window: browser.windows.Window
try {
window = await browser.windows.create(conf)
if (conf.state === 'maximized') {
let screenWidth = 800
let screenHeight = 600
await browser.windows.getCurrent().then(win => {
screenWidth = win.width ?? screenWidth
screenHeight = win.height ?? screenHeight
})
conf.state = 'normal' //open in normal state to avoid maximized window in the wrong screen
conf.width = screenWidth / 2 //if not set, the window will attempt to open maximized on the wrong screen
conf.height = screenHeight / 2
window = await browser.windows.create(conf)
if (window.id) {
//immediately maximize the window after creation
await browser.windows.update(window.id, { state: 'maximized' })
}
} else {
window = await browser.windows.create(conf)
}
} catch (err) {
if (String(err) === 'Error: Extension does not have permission for incognito mode') {
if (Windows.lastFocusedWinId !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions src/sidebar/sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:data-search="!!Search.reactive.value"
:data-sticky-bookmarks="Settings.state.pinOpenedBookmarksFolder"
:data-colorized-branches="Settings.state.colorizeTabsBranches"
@dragstart="DnD.onDragStart"
@dragend="DnD.onDragEnd"
@dragenter="DnD.onDragEnter"
@dragleave="DnD.onDragLeave"
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export interface DstPlaceInfo {
containerId?: string
windowId?: ID
incognito?: boolean
left?: number
top?: number
maximized?: boolean
windowChooseConf?: WindowChoosingDetails
discarded?: boolean
}
Expand Down