bugfix: 修复无边框拖拽问题

This commit is contained in:
muwoo 2021-08-10 14:44:15 +08:00
parent 78f54ef02b
commit 25957c485e
2 changed files with 141 additions and 107 deletions

View File

@ -106,6 +106,7 @@ class Listener {
this.reRegisterShortCut(mainWindow); this.reRegisterShortCut(mainWindow);
this.changeSize(mainWindow); this.changeSize(mainWindow);
this.msgTrigger(mainWindow); this.msgTrigger(mainWindow);
this.windowMoveInit(mainWindow);
} }
colorPicker() { colorPicker() {
@ -118,6 +119,7 @@ class Listener {
picker.getWindow().on('close', () => { picker.getWindow().on('close', () => {
ioHook.stop(); ioHook.stop();
ioHook.removeAllListeners();
!this.isWin && ioHook.unload(); !this.isWin && ioHook.unload();
}); });
@ -147,7 +149,7 @@ class Listener {
ipcMain.on("closePicker", () => { ipcMain.on("closePicker", () => {
this.closePicker(); this.closePicker();
}); });
});
ioHook.on('mousemove', e => { ioHook.on('mousemove', e => {
let {x, y} = this.getPos(e); let {x, y} = this.getPos(e);
if (!picker.getWindow()) return; if (!picker.getWindow()) return;
@ -171,6 +173,7 @@ class Listener {
this.closePicker() this.closePicker()
} }
}); });
});
} }
closePicker() { closePicker() {
@ -288,6 +291,36 @@ class Listener {
// todo win // todo win
}); });
} }
windowMoveInit(win) {
let hasInit = false;
ipcMain.on('window-move', () => {
if (!hasInit) {
hasInit = true;
ioHook.start(false);
!this.isWin && ioHook.load();
const winPosition = win.getPosition();
const winStartPosition = { x: winPosition[0], y: winPosition[1] };
const mouseStartPosition = screen.getCursorScreenPoint();
ioHook.on('mousedrag', e => {
const cursorPosition = screen.getCursorScreenPoint();
const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
let {x, y} = this.getPos({x: dx, y: dy});
win.setPosition(parseInt(x), parseInt(y));
});
ioHook.on('mouseup', e => {
hasInit = false;
ioHook.stop();
ioHook.removeAllListeners();
!this.isWin && ioHook.unload();
});
}
});
}
} }
export default Listener; export default Listener;

View File

@ -1,4 +1,5 @@
<template> <template>
<div @mousedown="drag" >
<a-layout id="components-layout"> <a-layout id="components-layout">
<div v-if="!searchType" class="rubick-select"> <div v-if="!searchType" class="rubick-select">
<div class="tag-container" v-if="selected"> <div class="tag-container" v-if="selected">
@ -104,6 +105,7 @@
</div> </div>
<router-view></router-view> <router-view></router-view>
</a-layout> </a-layout>
</div>
</template> </template>
<script> <script>
import { mapActions, mapMutations, mapState } from "vuex"; import { mapActions, mapMutations, mapState } from "vuex";
@ -309,6 +311,9 @@ export default {
this.showMainUI(); this.showMainUI();
this.changePath({ key: "market" }); this.changePath({ key: "market" });
}, },
drag() {
ipcRenderer.send('window-move');
}
}, },
computed: { computed: {
...mapState("main", [ ...mapState("main", [
@ -345,13 +350,9 @@ export default {
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 0; width: 0;
} }
.main-input {
-webkit-app-region: no-drag;
}
} }
.rubick-select, .rubick-select,
.rubick-select-subMenu { .rubick-select-subMenu {
-webkit-app-region: drag;
display: flex; display: flex;
padding-left: 10px; padding-left: 10px;
background: #fff; background: #fff;