Skip to content

Commit

Permalink
fix: not set window icon gemeotry for window
Browse files Browse the repository at this point in the history
add setWindowIconGeometry for set window_icon_gemeotry property

log: as title
issue: linuxdeepin/developer-center#7887
  • Loading branch information
tsic404 committed Apr 18, 2024
1 parent 189d964 commit 0d4a037
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions panels/dock/taskmanager/abstractwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "dsglobal.h"

#include <QWindow>
#include <QString>
#include <QObject>
#include <QPointer>
Expand Down Expand Up @@ -41,6 +42,7 @@ class AbstractWindow : public QObject
virtual void maxmize() = 0;
virtual void minimize() = 0;
virtual void killClient() = 0;
virtual void setWindowIconGeometry(const QWindow* baseWindow, const QRect& gemeotry) = 0;

void setAppItem(QPointer<AppItem> item) {m_appitem = item;}
QPointer<AppItem> getAppItem() {return m_appitem;}
Expand Down
1 change: 0 additions & 1 deletion panels/dock/taskmanager/itemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "dsglobal.h"

#include <QAbstractListModel>
#include <qjsonarray.h>

namespace dock {
class AbstractItem;
Expand Down
32 changes: 32 additions & 0 deletions panels/dock/taskmanager/package/AppItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ Item {
property int statusIndicatorSize: root.width * 0.8
property int iconSize: Panel.rootObject.itemIconSizeBase * 0.64

property var iconGlobalPoint: {
var a = icon
var x = 0, y = 0
while(a.parent) {
x += a.x
y += a.y
a = a.parent
}

return Qt.point(x, y)
}

Item {
anchors.fill: parent
id: appItem
Expand Down Expand Up @@ -122,6 +134,7 @@ Item {
Connections {
function onPositionChanged() {
windowIndicator.updateIndicatorAnchors()
updateWindowIconGeometryTimer.start()
}
target: Panel
}
Expand Down Expand Up @@ -163,6 +176,17 @@ Item {
}
}

Timer {
id: updateWindowIconGeometryTimer
interval: 500
running: false
repeat: false
onTriggered: {
taskmanager.Applet.setAppItemWindowIconGeometry(root.itemId, Panel.rootObject, iconGlobalPoint.x, iconGlobalPoint.y,
iconGlobalPoint.x + icon.width, iconGlobalPoint.y + icon.height)
}
}

MouseArea {
id: mouseArea
anchors.fill: parent
Expand Down Expand Up @@ -206,4 +230,12 @@ Item {
taskmanager.Applet.hideItemPreview()
}
}

onWindowsChanged: {
updateWindowIconGeometryTimer.start()
}

onIconGlobalPointChanged: {
updateWindowIconGeometryTimer.start()
}
}
10 changes: 10 additions & 0 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ void TaskManager::hideItemPreview()
m_windowMonitor->hideItemPreview();
}

void TaskManager::setAppItemWindowIconGeometry(const QString& appid, QObject* relativePositionItem, const int& x1, const int& y1, const int& x2, const int& y2)
{
QPointer<AppItem> item = static_cast<AppItem*>(ItemModel::instance()->getItemById(appid).get());
if (item.isNull()) return;

for (auto window : item->getAppendWindows()) {
window->setWindowIconGeometry(qobject_cast<QWindow*>(relativePositionItem), QRect(QPoint(x1, y1),QPoint(x2, y2)));
}
}

void TaskManager::loadDockedAppItems()
{
// TODO: add support for group and dir type
Expand Down
2 changes: 2 additions & 0 deletions panels/dock/taskmanager/taskmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TaskManager : public DS_NAMESPACE::DContainment
Q_INVOKABLE void showItemPreview(const QString& itemId, QObject* relativePositionItem, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction);
Q_INVOKABLE void hideItemPreview();

Q_INVOKABLE void setAppItemWindowIconGeometry(const QString& appid, QObject* relativePositionItem, const int& x1, const int& y1, const int& x2, const int& y2);

Q_SIGNALS:
void itemsChanged();
void windowSplitChanged();
Expand Down
5 changes: 5 additions & 0 deletions panels/dock/taskmanager/waylandwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ void WaylandWindow::killClient()
m_foreignToplevelHandle->close();
}

void WaylandWindow::setWindowIconGeometry(const QWindow* baseWindow, const QRect& gemeotry)
{

}

void WaylandWindow::updatePid()
{

Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/waylandwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class WaylandWindow : public AbstractWindow
void maxmize() override;
void minimize() override;
void killClient() override;
void setWindowIconGeometry(const QWindow* baseWindow, const QRect& gemeotry) override;

private:
void updatePid() override;
Expand Down
8 changes: 7 additions & 1 deletion panels/dock/taskmanager/x11utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "dsglobal.h"

#include <cstddef>
#include <qloggingcategory.h>
#include <unistd.h>
#include <xcb/xcb.h>
#include <xcb/res.h>
Expand Down Expand Up @@ -314,4 +313,11 @@ void X11Utils::restackWindow(const xcb_window_t& window)
{
xcb_ewmh_request_restack_window(&m_ewmh, 0, window, 0, XCB_STACK_MODE_ABOVE);
}

void X11Utils::setWindowIconGemeotry(const xcb_window_t& window, const QRect& geometry)
{
const auto ratio = qApp->devicePixelRatio();
xcb_ewmh_set_wm_icon_geometry(&m_ewmh, window, geometry.x() * ratio, geometry.y() * ratio, geometry.width() * ratio, geometry.height() * ratio);
}

}
1 change: 1 addition & 0 deletions panels/dock/taskmanager/x11utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class X11Utils
void killClient(const xcb_window_t& window);
void setActiveWindow(const xcb_window_t& window);
void restackWindow(const xcb_window_t& window);
void setWindowIconGemeotry(const xcb_window_t& window, const QRect& geometry);

private:
X11Utils();
Expand Down
7 changes: 7 additions & 0 deletions panels/dock/taskmanager/x11window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <mutex>

#include <QRect>
#include <QObject>
#include <QLoggingCategory>

Expand Down Expand Up @@ -142,6 +143,12 @@ void X11Window::killClient()
X11->killClient(m_windowID);
}

void X11Window::setWindowIconGeometry(const QWindow* baseWindow, const QRect& gemeotry)
{
auto pos = baseWindow->position() + gemeotry.topLeft();
X11->setWindowIconGemeotry(m_windowID, QRect(pos.x(), pos.y(), gemeotry.width(), gemeotry.height()));
}

void X11Window::updatePid()
{
auto oldPid = m_pid;
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/x11window.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class X11Window : public AbstractWindow
virtual void maxmize() override;
virtual void minimize() override;
virtual void killClient() override;
virtual void setWindowIconGeometry(const QWindow* baseWindow, const QRect& gemeotry) override;

private:
friend class X11WindowMonitor;
Expand Down

0 comments on commit 0d4a037

Please sign in to comment.