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,29 +149,30 @@ class Listener {
ipcMain.on("closePicker", () => { ipcMain.on("closePicker", () => {
this.closePicker(); this.closePicker();
}); });
});
ioHook.on('mousemove', e => {
let {x, y} = this.getPos(e);
if (!picker.getWindow()) return;
picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10);
this.fn(e, picker);
})
ioHook.on('mouseup', e => { ioHook.on('mousemove', e => {
if (e.button === 1) { let {x, y} = this.getPos(e);
let x = e.x if (!picker.getWindow()) return;
let y = e.y picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10);
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y)); this.fn(e, picker);
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y))); })
new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show();
this.closePicker();
}
});
ioHook.on('mouseup', e => { ioHook.on('mouseup', e => {
if (e.button === 3) { if (e.button === 1) {
this.closePicker() let x = e.x
} let y = e.y
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y)));
new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show();
this.closePicker();
}
});
ioHook.on('mouseup', e => {
if (e.button === 3) {
this.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,109 +1,111 @@
<template> <template>
<a-layout id="components-layout"> <div @mousedown="drag" >
<div v-if="!searchType" class="rubick-select"> <a-layout id="components-layout">
<div class="tag-container" v-if="selected"> <div v-if="!searchType" class="rubick-select">
<a-tag <div class="tag-container" v-if="selected">
:key="selected.key" <a-tag
@close="closeTag" :key="selected.key"
class="select-tag" @close="closeTag"
color="green" class="select-tag"
closable color="green"
> closable
{{ selected.name }} >
</a-tag> {{ selected.name }}
</div> </a-tag>
<a-input </div>
id="search" <a-input
:placeholder=" id="search"
:placeholder="
subPlaceHolder && selected && selected.key === 'plugin-container' subPlaceHolder && selected && selected.key === 'plugin-container'
? subPlaceHolder ? subPlaceHolder
: 'Hi, Rubick' : 'Hi, Rubick'
" "
class="main-input" class="main-input"
@change="(e) => search({ value: e.target.value })" @change="(e) => search({ value: e.target.value })"
:value="searchValue" :value="searchValue"
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000" :maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
@keydown.down="(e) => changeCurrent(1)" @keydown.down="(e) => changeCurrent(1)"
@keydown.up="() => changeCurrent(-1)" @keydown.up="() => changeCurrent(-1)"
@keypress.enter=" @keypress.enter="
(e) => targetSearch({ value: e.target.value, type: 'enter' }) (e) => targetSearch({ value: e.target.value, type: 'enter' })
" "
@keypress.space=" @keypress.space="
(e) => targetSearch({ value: e.target.value, type: 'space' }) (e) => targetSearch({ value: e.target.value, type: 'space' })
" "
> >
<div @click="goMenu" class="suffix-tool" slot="suffix"> <div @click="goMenu" class="suffix-tool" slot="suffix">
<a-icon <a-icon
v-show="selected && selected.key === 'plugin-container'" v-show="selected && selected.key === 'plugin-container'"
class="icon-more" class="icon-more"
type="more" type="more"
/> />
<img <img
class="icon-tool" class="icon-tool"
v-if="selected && selected.icon" v-if="selected && selected.icon"
:src="selected.icon" :src="selected.icon"
/> />
<div v-else class="rubick-logo"> <div v-else class="rubick-logo">
<img src="./assets/imgs/logo.png" /> <img src="./assets/imgs/logo.png" />
</div>
</div> </div>
</a-input>
<div class="options" v-show="showOptions">
<a-list item-layout="horizontal" :data-source="options">
<a-list-item
@click="() => item.click($router)"
:class="currentSelect === index ? 'active op-item' : 'op-item'"
slot="renderItem"
slot-scope="item, index"
>
<a-list-item-meta :description="item.desc">
<span slot="title" v-html="renderTitle(item.name)"></span>
<a-avatar
slot="avatar"
style="border-radius: 0"
:src="item.icon"
/>
</a-list-item-meta>
<a-tag v-show="item.type === 'dev'">开发者</a-tag>
<a-tag v-show="item.type === 'system'">系统</a-tag>
</a-list-item>
</a-list>
</div> </div>
</a-input>
<div class="options" v-show="showOptions">
<a-list item-layout="horizontal" :data-source="options">
<a-list-item
@click="() => item.click($router)"
:class="currentSelect === index ? 'active op-item' : 'op-item'"
slot="renderItem"
slot-scope="item, index"
>
<a-list-item-meta :description="item.desc">
<span slot="title" v-html="renderTitle(item.name)"></span>
<a-avatar
slot="avatar"
style="border-radius: 0"
:src="item.icon"
/>
</a-list-item-meta>
<a-tag v-show="item.type === 'dev'">开发者</a-tag>
<a-tag v-show="item.type === 'system'">系统</a-tag>
</a-list-item>
</a-list>
</div> </div>
</div> <div class="rubick-select-subMenu" v-else>
<div class="rubick-select-subMenu" v-else> <div>
<div> <img
<img class="icon-tool-sub"
class="icon-tool-sub" v-if="pluginInfo.icon"
v-if="pluginInfo.icon" :src="pluginInfo.icon"
:src="pluginInfo.icon" />
/> <a-input
<a-input :placeholder="subPlaceHolder"
:placeholder="subPlaceHolder" class="sub-input"
class="sub-input" @change="
@change="
(e) => (e) =>
search({ search({
value: e.target.value, value: e.target.value,
searchType: pluginInfo.searchType, searchType: pluginInfo.searchType,
}) })
" "
:value="searchValue" :value="searchValue"
@keypress.enter=" @keypress.enter="
(e) => targetSearch({ value: e.target.value, type: 'enter' }) (e) => targetSearch({ value: e.target.value, type: 'enter' })
" "
@keypress.space=" @keypress.space="
(e) => targetSearch({ value: e.target.value, type: 'space' }) (e) => targetSearch({ value: e.target.value, type: 'space' })
" "
></a-input> ></a-input>
</div> </div>
<div class="icon-container"> <div class="icon-container">
<a-icon class="icon" type="info-circle" /> <a-icon class="icon" type="info-circle" />
<a-icon class="icon" @click="goMenu('separate')" type="setting" /> <a-icon class="icon" @click="goMenu('separate')" type="setting" />
</div>
</div> </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;