You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
statusbar/src/statusbar.cpp

93 lines
3.0 KiB
C++

/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefishos <cutefishos@foxmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
5 years ago
#include "statusbar.h"
#include "processprovider.h"
#include "appmenu/appmenu.h"
5 years ago
#include <QQmlEngine>
#include <QQmlContext>
#include <QApplication>
#include <QScreen>
#include <NETWM>
#include <KWindowSystem>
#include <KWindowEffects>
StatusBar::StatusBar(QQuickView *parent)
: QQuickView(parent)
, m_acticity(new Activity)
5 years ago
{
setFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
setColor(Qt::transparent);
KWindowSystem::setOnDesktop(winId(), NET::OnAllDesktops);
KWindowSystem::setType(winId(), NET::Dock);
KWindowEffects::slideWindow(winId(), KWindowEffects::TopEdge);
new AppMenu(this);
engine()->rootContext()->setContextProperty("acticity", m_acticity);
5 years ago
engine()->rootContext()->setContextProperty("process", new ProcessProvider);
setSource(QUrl(QStringLiteral("qrc:/qml/main.qml")));
setResizeMode(QQuickView::SizeRootObjectToView);
setScreen(qApp->primaryScreen());
updateGeometry();
setVisible(true);
connect(qApp->primaryScreen(), &QScreen::virtualGeometryChanged, this, &StatusBar::updateGeometry);
connect(qApp->primaryScreen(), &QScreen::geometryChanged, this, &StatusBar::updateGeometry);
}
void StatusBar::updateGeometry()
{
const QRect rect = qApp->primaryScreen()->geometry();
5 years ago
QRect windowRect = QRect(rect.x(), rect.y(), rect.width(), 28);
5 years ago
setGeometry(windowRect);
updateViewStruts();
5 years ago
KWindowEffects::enableBlurBehind(winId(), true);
5 years ago
}
void StatusBar::updateViewStruts()
{
const QRect windowRect = geometry();
NETExtendedStrut strut;
strut.top_width = windowRect.height();
strut.top_start = x();
strut.top_end = x() + windowRect.width();
KWindowSystem::setExtendedStrut(winId(),
strut.left_width,
strut.left_start,
strut.left_end,
strut.right_width,
strut.right_start,
strut.right_end,
strut.top_width,
strut.top_start,
strut.top_end,
strut.bottom_width,
strut.bottom_start,
strut.bottom_end);
}