Skip to content

Commit

Permalink
Support WM minimize animation
Browse files Browse the repository at this point in the history
So that windows minimized by KWin get animated to go to the Dock rather than where the mouse is
Backport cyberos/cyber-dock@6bb30c4
cyberos/cyber-dock#5
helloSystem/hello#164
  • Loading branch information
probonopd committed Apr 25, 2021
1 parent ce0c281 commit 95fe223
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 9 deletions.
22 changes: 22 additions & 0 deletions qml/AppItemDelegate.qml → qml/AppItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ Item {

signal onClicked

onXChanged: updateGeometryTimer.start()
onYChanged: updateGeometryTimer.start()

function updateGeometry() {
appModel.updateGeometries(model.appId, Qt.rect(dockItem.mapToGlobal(0, 0).x,
dockItem.mapToGlobal(0, 0).y,
dockItem.width, dockItem.height))
}

Timer {
id: updateGeometryTimer
interval: 800
repeat: false

onTriggered: {
updateGeometry()
}
}

Menu {
id: contextMenu

Expand Down Expand Up @@ -53,12 +72,15 @@ Item {
}

DockItem {
id: dockItem
anchors.fill: parent
iconName: model.iconName
isActive: model.isActive
popupText: model.visibleName
enableActivateDot: model.windowCount !== 0

onPositionChanged: updateGeometry()
onPressed: updateGeometry()
onClicked: appModel.clicked(model.appId)
onRightClicked: contextMenu.open()
}
Expand Down
7 changes: 4 additions & 3 deletions qml/DockItem.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QtQuick 2.12
import QtQuick.Controls 2.5

Rectangle {
MouseArea {
id: dockItem
width: root.height
height: root.height
Expand All @@ -17,6 +17,7 @@ Rectangle {
property double iconSizeRatio: 0.8
property var iconName

signal pressed()
signal clicked()
signal rightClicked()

Expand All @@ -27,8 +28,6 @@ Rectangle {
}
}

color: "transparent"

Image {
id: icon
source: {
Expand Down Expand Up @@ -128,6 +127,8 @@ Rectangle {
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton

onPressed: dockItem.pressed()

onClicked: {
if (mouse.button === Qt.LeftButton)
dockItem.clicked()
Expand Down
2 changes: 1 addition & 1 deletion qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Rectangle {
model: appModel
clip: true

delegate: AppItemDelegate { }
delegate: AppItem { }
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<qresource prefix="/">
<file>qml/main.qml</file>
<file>qml/DockItem.qml</file>
<file>qml/AppItemDelegate.qml</file>
<file>qml/AppItem.qml</file>
<file>svg/launcher.svg</file>
<file>qml/PopupTips.qml</file>
<file>qml/Menu.qml</file>
Expand Down
27 changes: 23 additions & 4 deletions src/applicationmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ void ApplicationModel::unPin(const QString &appId)
savePinAndUnPinList();
}

void ApplicationModel::updateGeometries(const QString &id, QRect rect)
{
ApplicationItem *item = findItemById(id);

// If not found
if (!item)
return;

for (quint64 id : item->wids) {
m_iface->setIconGeometry(id, rect);
}
}

ApplicationItem *ApplicationModel::findItemByWId(quint64 wid)
{
for (ApplicationItem *item : m_appItems) {
Expand Down Expand Up @@ -389,11 +402,17 @@ void ApplicationModel::onWindowRemoved(quint64 wid)

void ApplicationModel::onActiveChanged(quint64 wid)
{
beginResetModel();
// Using this method will cause the listview scrollbar to reset.
// beginResetModel();

for (ApplicationItem *item : m_appItems) {
item->isActive = item->wids.contains(wid);
}
if (item->isActive != item->wids.contains(wid)) {
item->isActive = item->wids.contains(wid);

endResetModel();
QModelIndex idx = index(indexOf(item->id), 0, QModelIndex());
if (idx.isValid()) {
emit dataChanged(idx, idx);
}
}
}
}
2 changes: 2 additions & 0 deletions src/applicationmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ApplicationModel : public QAbstractListModel
Q_INVOKABLE void pin(const QString &appId);
Q_INVOKABLE void unPin(const QString &appId);

Q_INVOKABLE void updateGeometries(const QString &id, QRect rect);

int iconSize() { return m_iconSize; }

signals:
Expand Down
15 changes: 15 additions & 0 deletions src/xwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ QString XWindowInterface::desktopFilePath(quint64 wid)
info.windowClassName());
}

void XWindowInterface::setIconGeometry(quint64 wid, const QRect &rect)
{
NETWinInfo info(QX11Info::connection(),
wid,
(WId) QX11Info::appRootWindow(),
NET::WMIconGeometry,
QFlags<NET::Property2>(1));
NETRect nrect;
nrect.pos.x = rect.x();
nrect.pos.y = rect.y();
nrect.size.height = rect.height();
nrect.size.width = rect.width();
info.setIconGeometry(nrect);
}

void XWindowInterface::onWindowadded(quint64 wid)
{
if (isAcceptableWindow(wid)) {
Expand Down
2 changes: 2 additions & 0 deletions src/xwindowinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class XWindowInterface : public QObject

QString desktopFilePath(quint64 wid);

void setIconGeometry(quint64 wid, const QRect &rect);

signals:
void windowAdded(quint64 wid);
void windowRemoved(quint64 wid);
Expand Down

0 comments on commit 95fe223

Please sign in to comment.