mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-04 02:34:45 +00:00
better event handling in homescreen
This commit is contained in:
parent
df605a7d51
commit
5ac357c0e9
1 changed files with 22 additions and 12 deletions
|
|
@ -24,7 +24,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||||
import org.kde.kquickcontrolsaddons 2.0
|
import org.kde.kquickcontrolsaddons 2.0
|
||||||
|
|
||||||
MouseEventListener {
|
MouseArea {
|
||||||
id: headerItem
|
id: headerItem
|
||||||
z: 999
|
z: 999
|
||||||
property Item layout: appletsLayout
|
property Item layout: appletsLayout
|
||||||
|
|
@ -39,6 +39,7 @@ MouseEventListener {
|
||||||
property int oldMouseX
|
property int oldMouseX
|
||||||
property int oldMouseY
|
property int oldMouseY
|
||||||
|
|
||||||
|
drag.filterChildren: true
|
||||||
EventGenerator {
|
EventGenerator {
|
||||||
id: eventGenerator
|
id: eventGenerator
|
||||||
}
|
}
|
||||||
|
|
@ -60,19 +61,27 @@ MouseEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
|
startMouseX = mouse.x;
|
||||||
|
startMouseY = mouse.y;
|
||||||
}
|
}
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
|
var absolutePos = mapToItem(appletsLayout, mouse.x, mouse.y);
|
||||||
|
var absoluteStartPos = mapToItem(appletsLayout, startMouseX, startMouseY);
|
||||||
|
|
||||||
|
if (Math.abs(absolutePos.x - absoluteStartPos.x) > units.gridUnit*2 ||
|
||||||
|
Math.abs(absolutePos.y - absoluteStartPos.y) > units.gridUnit*2) {
|
||||||
|
print("finger moved too much, press and hold canceled")
|
||||||
|
return;
|
||||||
|
}
|
||||||
print(favoritesView.contains(mapToItem(favoritesView, mouse.x, mouse.y)))
|
print(favoritesView.contains(mapToItem(favoritesView, mouse.x, mouse.y)))
|
||||||
if (!favoritesView.contains(mapToItem(favoritesView, mouse.x, mouse.y))) {
|
if (!favoritesView.contains(mapToItem(favoritesView, mouse.x, mouse.y))) {
|
||||||
editOverlay.visible = true;
|
editOverlay.visible = true;
|
||||||
var pos = mapToItem(appletsLayout, mouse.x, mouse.y);
|
var pos = mapToItem(appletsLayout, mouse.x, mouse.y);
|
||||||
draggingApplet = appletsSpace.layout.childAt(pos.x, pos.y);
|
draggingApplet = appletsSpace.layout.childAt(absolutePos.x, absolutePos.y);
|
||||||
editOverlay.applet = draggingApplet;
|
editOverlay.applet = draggingApplet;
|
||||||
|
|
||||||
startMouseX = mouse.screenX;
|
oldMouseX = mouse.x;
|
||||||
startMouseY = mouse.screenY;
|
oldMouseY = mouse.y;
|
||||||
oldMouseX = mouse.screenX;
|
|
||||||
oldMouseY = mouse.screenY;
|
|
||||||
|
|
||||||
eventGenerator.sendGrabEvent(draggingApplet, EventGenerator.UngrabMouse);
|
eventGenerator.sendGrabEvent(draggingApplet, EventGenerator.UngrabMouse);
|
||||||
eventGenerator.sendGrabEvent(headerItem, EventGenerator.GrabMouse);
|
eventGenerator.sendGrabEvent(headerItem, EventGenerator.GrabMouse);
|
||||||
|
|
@ -91,21 +100,22 @@ MouseEventListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onPositionChanged: {
|
onPositionChanged: {
|
||||||
if (!draggingApplet) {
|
if (!draggingApplet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationsView.interactive = false;
|
applicationsView.interactive = false;
|
||||||
if (Math.abs(mouse.screenX - startMouseX) > units.gridUnit ||
|
if (Math.abs(mouse.x - startMouseX) > units.gridUnit ||
|
||||||
Math.abs(mouse.screenY - startMouseY) > units.gridUnit) {
|
Math.abs(mouse.y - startMouseY) > units.gridUnit) {
|
||||||
editOverlay.opacity = 0;
|
editOverlay.opacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
draggingApplet.x -= oldMouseX - mouse.screenX;
|
draggingApplet.x -= oldMouseX - mouse.x;
|
||||||
draggingApplet.y -= oldMouseY - mouse.screenY;
|
draggingApplet.y -= oldMouseY - mouse.y;
|
||||||
oldMouseX = mouse.screenX;
|
oldMouseX = mouse.x;
|
||||||
oldMouseY = mouse.screenY;
|
oldMouseY = mouse.y;
|
||||||
|
|
||||||
var pos = mapToItem(appletsLayout, mouse.x, mouse.y);
|
var pos = mapToItem(appletsLayout, mouse.x, mouse.y);
|
||||||
var itemUnderMouse = appletsSpace.layout.childAt(pos.x, pos.y);
|
var itemUnderMouse = appletsSpace.layout.childAt(pos.x, pos.y);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue