OctupleSakura / desktop-kessyoubann

デスクトップの血小板 σ`∀´)σ
0 stars 0 forks source link

electron 拖拽方案 #3

Closed OctupleSakura closed 5 years ago

OctupleSakura commented 5 years ago

引用了一位老哥的一个方案 ,暂时解决问题了

ipcMain.on('windowMoving', (e, {mouseX, mouseY}) => {
  const { x, y } = electron.screen.getCursorScreenPoint()
  this.win.setPosition(x - mouseX, y - mouseY)
});

ipcMain.on('windowMoved', () => {
  // Do somehting when dragging stop
);
let animationId;
let mouseX;
let mouseY;

function onMouseDown(e) {
  mouseX = e.clientX;  
  mouseY = e.clientY;

  document.addEventListener('mouseup', onMouseUp)
  requestAnimationFrame(this.moveWindow);
}

function onMouseUp(e) {
  window.ipcRenderer.send('windowMoved');
  document.removeEventListener('mouseup', onMouseUp)
  cancelAnimationFrame(animationId)
}

function moveWindow() {
  window.ipcHandler.send('windowMoving', { mouseX, mouseY });
  animationId = requestAnimationFrame(moveWindow);
}

electron/electron#1354

yuxino commented 5 years ago

react-dnd ?