mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
add strut partial
Change-Id: Icd67fcd76430ebe765da982988fcb536ff1850de
This commit is contained in:
parent
b9e4c3262c
commit
e5b63e9dcb
@ -4,7 +4,7 @@ TARGET = dde-dock
|
|||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
CONFIG += c++11 link_pkgconfig
|
CONFIG += c++11 link_pkgconfig
|
||||||
|
|
||||||
PKGCONFIG += xcb-ewmh gtk+-2.0
|
PKGCONFIG += xcb-ewmh gtk+-2.0 dtkwidget dtkbase
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
window/mainwindow.cpp \
|
window/mainwindow.cpp \
|
||||||
|
16
main.cpp
16
main.cpp
@ -1,11 +1,23 @@
|
|||||||
|
|
||||||
#include "window/mainwindow.h"
|
#include "window/mainwindow.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <dapplication.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
DApplication app(argc, argv);
|
||||||
|
if (!app.setSingleInstance(QString("dde-dock_%1").arg(getuid()))) {
|
||||||
|
qDebug() << "set single instance failed!";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
app.setOrganizationName("deepin");
|
||||||
|
app.setApplicationName("dde-dock");
|
||||||
|
app.setApplicationDisplayName("DDE Dock");
|
||||||
|
app.setApplicationVersion("2.0");
|
||||||
|
|
||||||
MainWindow mw;
|
MainWindow mw;
|
||||||
mw.show();
|
mw.show();
|
||||||
|
@ -8,7 +8,7 @@ DockSettings::DockSettings(QObject *parent)
|
|||||||
|
|
||||||
DockSettings::DockSide DockSettings::side() const
|
DockSettings::DockSide DockSettings::side() const
|
||||||
{
|
{
|
||||||
return Top;
|
return Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QSize DockSettings::mainWindowSize() const
|
const QSize DockSettings::mainWindowSize() const
|
||||||
|
@ -11,15 +11,24 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
m_settings(new DockSettings(this)),
|
m_settings(new DockSettings(this)),
|
||||||
m_displayInter(new DBusDisplay(this)),
|
m_displayInter(new DBusDisplay(this)),
|
||||||
|
|
||||||
|
m_xcbMisc(XcbMisc::instance()),
|
||||||
|
|
||||||
m_positionUpdateTimer(new QTimer(this))
|
m_positionUpdateTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowDoesNotAcceptFocus);
|
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
|
||||||
|
m_xcbMisc->set_window_type(winId(), XcbMisc::Dock);
|
||||||
|
|
||||||
initComponents();
|
initComponents();
|
||||||
initConnections();
|
initConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
delete m_xcbMisc;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::resizeEvent(QResizeEvent *e)
|
void MainWindow::resizeEvent(QResizeEvent *e)
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(e);
|
QWidget::resizeEvent(e);
|
||||||
@ -47,15 +56,71 @@ void MainWindow::initComponents()
|
|||||||
|
|
||||||
void MainWindow::initConnections()
|
void MainWindow::initConnections()
|
||||||
{
|
{
|
||||||
|
connect(m_displayInter, &DBusDisplay::PrimaryRectChanged, [this] {m_positionUpdateTimer->start();});
|
||||||
|
|
||||||
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition);
|
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updatePosition()
|
void MainWindow::updatePosition()
|
||||||
{
|
{
|
||||||
const QRect rect = m_displayInter->primaryRect();
|
clearStrutPartial();
|
||||||
|
|
||||||
setFixedWidth(rect.width());
|
const QRect screenRect = m_displayInter->primaryRect();
|
||||||
setFixedHeight(80);
|
|
||||||
|
|
||||||
move(0, 950);
|
setFixedWidth(screenRect.width());
|
||||||
|
setFixedHeight(60);
|
||||||
|
|
||||||
|
move(0, screenRect.bottom() - 60);
|
||||||
|
|
||||||
|
setStrutPartial();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::clearStrutPartial()
|
||||||
|
{
|
||||||
|
m_xcbMisc->clear_strut_partial(winId());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setStrutPartial()
|
||||||
|
{
|
||||||
|
const DockSettings::DockSide side = m_settings->side();
|
||||||
|
const int maxScreenHeight = m_displayInter->screenHeight();
|
||||||
|
|
||||||
|
XcbMisc::Orientation orientation;
|
||||||
|
uint strut;
|
||||||
|
uint strutStart;
|
||||||
|
uint strutEnd;
|
||||||
|
|
||||||
|
const QPoint p = pos();
|
||||||
|
const QRect r = rect();
|
||||||
|
switch (side)
|
||||||
|
{
|
||||||
|
case DockSettings::Top:
|
||||||
|
orientation = XcbMisc::OrientationTop;
|
||||||
|
strut = r.bottom();
|
||||||
|
strutStart = r.left();
|
||||||
|
strutEnd = r.right();
|
||||||
|
break;
|
||||||
|
case DockSettings::Bottom:
|
||||||
|
orientation = XcbMisc::OrientationBottom;
|
||||||
|
strut = maxScreenHeight - p.y();
|
||||||
|
strutStart = r.left();
|
||||||
|
strutEnd = r.right();
|
||||||
|
break;
|
||||||
|
case DockSettings::Left:
|
||||||
|
orientation = XcbMisc::OrientationLeft;
|
||||||
|
strut = r.width();
|
||||||
|
strutStart = r.top();
|
||||||
|
strutEnd = r.bottom();
|
||||||
|
break;
|
||||||
|
case DockSettings::Right:
|
||||||
|
orientation = XcbMisc::OrientationRight;
|
||||||
|
strut = r.width();
|
||||||
|
strutStart = r.top();
|
||||||
|
strutEnd = r.bottom();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_xcbMisc->set_strut_partial(winId(), orientation, strut, strutStart, strutEnd);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class MainWindow : public QWidget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *e);
|
||||||
@ -24,12 +25,15 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
void clearStrutPartial();
|
||||||
|
void setStrutPartial();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainPanel *m_mainPanel;
|
MainPanel *m_mainPanel;
|
||||||
|
|
||||||
DockSettings *m_settings;
|
DockSettings *m_settings;
|
||||||
DBusDisplay *m_displayInter;
|
DBusDisplay *m_displayInter;
|
||||||
|
XcbMisc *m_xcbMisc;
|
||||||
|
|
||||||
QTimer *m_positionUpdateTimer;
|
QTimer *m_positionUpdateTimer;
|
||||||
};
|
};
|
||||||
|
@ -55,12 +55,16 @@ void XcbMisc::set_window_type(xcb_window_t winId, WindowType winType)
|
|||||||
xcb_ewmh_set_wm_window_type(&m_ewmh_connection, winId, 1, atoms);
|
xcb_ewmh_set_wm_window_type(&m_ewmh_connection, winId, 1, atoms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XcbMisc::clear_strut_partial(xcb_window_t winId)
|
||||||
|
{
|
||||||
|
xcb_ewmh_wm_strut_partial_t strutPartial;
|
||||||
|
memset(&strutPartial, 0, sizeof(xcb_ewmh_wm_strut_partial_t));
|
||||||
|
|
||||||
|
xcb_ewmh_set_wm_strut_partial(&m_ewmh_connection, winId, strutPartial);
|
||||||
|
}
|
||||||
|
|
||||||
void XcbMisc::set_strut_partial(xcb_window_t winId, Orientation orientation, uint strut, uint start, uint end)
|
void XcbMisc::set_strut_partial(xcb_window_t winId, Orientation orientation, uint strut, uint start, uint end)
|
||||||
{
|
{
|
||||||
// xcb_ewmh_wm_strut_partial_t strut_partial is very different from
|
|
||||||
// xcb_ewmh_wm_strut_partial_t strut_partial {};
|
|
||||||
// the latter one ensures all its member to be initialized to 0;
|
|
||||||
// xcb_ewmh_wm_strut_partial_t strut_partial {};
|
|
||||||
xcb_ewmh_wm_strut_partial_t strut_partial;
|
xcb_ewmh_wm_strut_partial_t strut_partial;
|
||||||
memset(&strut_partial, 0, sizeof(xcb_ewmh_wm_strut_partial_t));
|
memset(&strut_partial, 0, sizeof(xcb_ewmh_wm_strut_partial_t));
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ public:
|
|||||||
static XcbMisc * instance();
|
static XcbMisc * instance();
|
||||||
|
|
||||||
void set_window_type(xcb_window_t winId, WindowType winType);
|
void set_window_type(xcb_window_t winId, WindowType winType);
|
||||||
|
void clear_strut_partial(xcb_window_t winId);
|
||||||
void set_strut_partial(xcb_window_t winId, Orientation orientation, uint strut, uint start, uint end);
|
void set_strut_partial(xcb_window_t winId, Orientation orientation, uint strut, uint start, uint end);
|
||||||
void set_window_icon_geometry(xcb_window_t winId, QRect geo);
|
void set_window_icon_geometry(xcb_window_t winId, QRect geo);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user