Commit a875c6d9 authored by Noah Davis's avatar Noah Davis 🌵
Browse files

systemtray AbstractItem: add activated signal

An input type agnostic way to activate systray items was needed. This
signal will be used for keyboard, mouse and touch navigation.

There was an activated() function that just started an animation which
has been renamed to startActivatedAnimation().
parent 0060922d
......@@ -27,6 +27,10 @@ PlasmaCore.ToolTipArea {
readonly property bool inHiddenLayout: effectiveStatus === PlasmaCore.Types.PassiveStatus
readonly property bool inVisibleLayout: effectiveStatus === PlasmaCore.Types.ActiveStatus
// input agnostic way to trigger the main action
signal activated(var args)
// proxy signals for MouseArea
signal clicked(var mouse)
signal pressed(var mouse)
signal wheel(var wheel)
......@@ -66,7 +70,7 @@ PlasmaCore.ToolTipArea {
PlasmaCore.Units.longDuration > 0
}
function activated() {
function startActivatedAnimation() {
activatedAnimation.start()
}
......
......@@ -22,6 +22,38 @@ AbstractItem {
textFormat: applet ? applet.toolTipTextFormat : ""
active: systemTrayState.activeApplet !== applet
// FIXME: Use an input type agnostic way to activate whatever the primary
// action of a plasmoid is supposed to be, even if it's just expanding the
// plasmoid. Not all plasmoids are supposed to expand and not all plasmoids
// do anything with onActivated.
onActivated: if (applet) {
let fullRep = applet.fullRepresentationItem
/* HACK: Plasmoids can have an empty but not null fullRepresentationItem,
* even if fullRepresentation is not explicitly defined or is explicitly null.
*
* If fullRep is a plain Item and there are no children, assume it is empty.
* There will be uncommon situations where this assumption is wrong.
*
* `typeof fullRep` only returns "object", which is useless.
* We aren't using `fullRep instanceof Item` because it would always
* return true if fullRep is not null.
* If fullRep.toString() starts with "QQuickItem_QML",
* then it really is just a plain Item.
*
* We really need to refactor system tray someday.
*/
if (fullRep && (!fullRep.toString().startsWith("QQuickItem_QML")
|| fullRep.children.length > 0)
) {
// Assume that an applet with a fullRepresentationItem that
// fits the criteria will want to expand the applet when activated.
applet.expanded = !applet.expanded
}
// If there is no fullRepresentationItem, hopefully the applet is using
// the onActivated signal handler for something useful.
applet.activated()
}
onClicked: {
if (!applet) {
return
......@@ -31,7 +63,7 @@ AbstractItem {
if (mouseArea) {
mouseArea.clicked(mouse)
} else if (mouse.button === Qt.LeftButton) {//falback
applet.expanded = true
plasmoidContainer.activated()
}
}
onContextMenu: if (applet) {
......@@ -95,13 +127,13 @@ AbstractItem {
//activation using global keyboard shortcut
function onActivated() {
plasmoidContainer.activated()
plasmoidContainer.startActivatedAnimation()
}
function onExpandedChanged(expanded) {
if (expanded) {
systemTrayState.setActiveApplet(applet, model.row)
plasmoidContainer.activated()
plasmoidContainer.startActivatedAnimation()
}
}
......
......@@ -35,41 +35,45 @@ AbstractItem {
active: taskIcon.containsMouse
}
onActivated: {
let service = model.Service;
let operation = service.operationDescription("Activate")
operation.x = args.x //mouseX
operation.y = args.y //mouseY
let job = service.startOperationCall(operation)
job.finished.connect(() => {
if (!job.result) {
// On error try to invoke the context menu.
// Workaround primarily for apps using libappindicator.
openContextMenu(args)
}
})
taskIcon.startActivatedAnimation()
}
onContextMenu: {
openContextMenu(plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y))
}
onClicked: {
var pos = plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y);
var service = model.Service;
switch (mouse.button) {
case Qt.LeftButton:
var operation = service.operationDescription("Activate");
operation.x = pos.x;
operation.y = pos.y;
var job = service.startOperationCall(operation);
job.finished.connect(function () {
if (!job.result) {
// On error try to invoke the context menu.
// Workaround primarily for apps using libappindicator.
openContextMenu(pos);
}
});
taskIcon.activated()
taskIcon.activated(pos)
break;
case Qt.MiddleButton:
var operation = service.operationDescription("SecondaryActivate");
let service = model.Service;
operation.x = pos.x;
operation.y = pos.y;
service.startOperationCall(operation);
taskIcon.activated()
taskIcon.startActivatedAnimation()
break;
}
}
function openContextMenu(pos) {
function openContextMenu(pos = Qt.point(width/2, height/2)) {
var service = model.Service;
var operation = service.operationDescription("ContextMenu");
operation.x = pos.x;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment