Skip to content

Commit

Permalink
feat: setDesktopWindow by dde-shell
Browse files Browse the repository at this point in the history
setDesktopWindow by dde-shell

log: as title
  • Loading branch information
Johnson-zs committed Aug 15, 2024
1 parent ab12e4d commit d22fde9
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/plugins/desktop/desktoputils/widgetutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

# include <xcb/xcb.h>
# include <xcb/xcb_ewmh.h>
# include <dde-shell/dlayershellwindow.h>
#endif

namespace ddplugin_desktop_util {

static inline void setDesktopWindow(QWidget *w)
static inline void setDesktopWindowOld(QWidget *w)
{
if (!w)
return;
Expand Down Expand Up @@ -58,6 +59,56 @@ static inline void setDesktopWindow(QWidget *w)
}
}

static inline void setDesktopWindow(QWidget *w)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
setDesktopWindowOld(w);
#else
if (!w)
return;

w->winId(); // must be called
QWindow *window = w->windowHandle();
if (!window) {
qWarning() << w << "windowHandle is null";
return;
}

// 使用 dde-shell 完成桌面窗口设置
DS_USE_NAMESPACE
auto layerShellWindow = DLayerShellWindow::get(window);
if (!layerShellWindow) {
qWarning() << w << "DLayerShellWindow is null! Use setDesktopWindowOld";
setDesktopWindowOld(w);
} else {
qInfo() << "set desktop by dde-shell";
// 窗管这边要特判来做动画 所以要调用setScope
layerShellWindow->setScope("dde-shell/desktop");
DLayerShellWindow::Anchors anchors = static_cast<DLayerShellWindow::Anchors>(
DLayerShellWindow::AnchorTop | DLayerShellWindow::AnchorBottom | DLayerShellWindow::AnchorLeft | DLayerShellWindow::AnchorRight);
layerShellWindow->setAnchors(anchors);
layerShellWindow->setLeftMargin(0);
layerShellWindow->setRightMargin(0);
layerShellWindow->setTopMargin(0);
layerShellWindow->setBottomMargin(0);
layerShellWindow->setExclusiveZone(0);
layerShellWindow->setLayer(DLayerShellWindow::LayerBackground);
layerShellWindow->setKeyboardInteractivity(DLayerShellWindow::KeyboardInteractivityOnDemand);
layerShellWindow->setScreenConfiguration(DLayerShellWindow::ScreenFromQWindow);

qInfo() << "Desktop base info:"
<< "Scope: " << layerShellWindow->scope()
<< "Anchors: " << layerShellWindow->anchors()
<< "Margins: " << layerShellWindow->topMargin() << layerShellWindow->leftMargin()
<< layerShellWindow->bottomMargin() << layerShellWindow->rightMargin()
<< "ExclusiveZone: " << layerShellWindow->exclusionZone()
<< "Layer: " << layerShellWindow->layer()
<< "KeyboardInteractivity: " << layerShellWindow->keyboardInteractivity()
<< "ScreenConfiguration: " << layerShellWindow->screenConfiguration();
}
#endif
}

static inline void setPrviewWindow(QWidget *w)
{
if (!w)
Expand Down

0 comments on commit d22fde9

Please sign in to comment.