Support x11 window move and resize

pull/3/head
cutefishd 5 years ago
parent 01fd5ebc27
commit 9cc0da9531

@ -10,6 +10,7 @@ set(SOURCES
shadowhelper/tileset.cpp
blurhelper/windowblur.cpp
blurhelper/windowblur.h
windowhelper.cpp
meuikit.qrc
meui-style/style.qrc
@ -26,6 +27,7 @@ target_link_libraries (${TARGET}
Qt5::Qml
Qt5::Quick
Qt5::QuickControls2
Qt5::X11Extras
KF5::WindowSystem
)
@ -38,4 +40,4 @@ install(TARGETS ${TARGET} DESTINATION ${INSTALL_QMLDIR}/${TARGET})
install(DIRECTORY controls/ DESTINATION ${INSTALL_QMLDIR}/${TARGET})
# INSTALL STYLE
install(DIRECTORY meui-style DESTINATION ${INSTALL_QMLDIR}/QtQuick/Controls.2)
install(DIRECTORY meui-style DESTINATION ${INSTALL_QMLDIR}/QtQuick/Controls.2)

@ -1,3 +1,22 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#include "windowblur.h"
#include <QPainterPath>
#include <KWindowEffects>
@ -100,4 +119,4 @@ void WindowBlur::updateBlur()
KWindowEffects::enableBlurBehind(m_view->winId(), false);
}
}
}
}

@ -1,3 +1,22 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#ifndef WINDOWBLUR_H
#define WINDOWBLUR_H

@ -41,9 +41,13 @@ Window {
}
}
Meui.WindowHelper {
id: windowHelper
}
// Left bottom edge
MouseArea {
height: edgeSize
height: edgeSize * 2
width: height
anchors.bottom: parent.bottom
anchors.left: parent.left
@ -58,13 +62,13 @@ Window {
DragHandler {
grabPermissions: TapHandler.CanTakeOverFromAnything
target: null
onActiveChanged: if (active) { root.startSystemResize(Qt.LeftEdge | Qt.BottomEdge) }
onActiveChanged: if (active) { windowHelper.startSystemResize(root, Qt.LeftEdge | Qt.BottomEdge) }
}
}
// Right bottom edge
MouseArea {
height: edgeSize
height: edgeSize * 2
width: height
anchors.bottom: parent.bottom
anchors.right: parent.right
@ -79,7 +83,7 @@ Window {
DragHandler {
grabPermissions: TapHandler.CanTakeOverFromAnything
target: null
onActiveChanged: if (active) { root.startSystemResize(Qt.RightEdge | Qt.BottomEdge) }
onActiveChanged: if (active) { windowHelper.startSystemResize(root, Qt.RightEdge | Qt.BottomEdge) }
}
}
@ -100,7 +104,7 @@ Window {
DragHandler {
grabPermissions: TapHandler.CanTakeOverFromAnything
target: null
onActiveChanged: if (active) { root.startSystemResize(Qt.BottomEdge) }
onActiveChanged: if (active) { windowHelper.startSystemResize(root, Qt.BottomEdge) }
}
}
@ -121,7 +125,7 @@ Window {
DragHandler {
grabPermissions: TapHandler.CanTakeOverFromAnything
target: null
onActiveChanged: if (active) { root.startSystemResize(Qt.LeftEdge) }
onActiveChanged: if (active) { windowHelper.startSystemResize(root, Qt.LeftEdge) }
}
}
@ -142,7 +146,7 @@ Window {
DragHandler {
grabPermissions: TapHandler.CanTakeOverFromAnything
target: null
onActiveChanged: if (active) { root.startSystemResize(Qt.RightEdge) }
onActiveChanged: if (active) { windowHelper.startSystemResize(root, Qt.RightEdge) }
}
}
@ -159,7 +163,8 @@ Window {
anchors.fill: parent
anchors.margins: 0
radius: !isMaximized && !isFullScreen ? root.windowRadius : 0
color: Qt.rgba(root.backgroundColor.r, root.backgroundColor.g, root.backgroundColor.b, root.backgroundOpacity)
color: Qt.rgba(root.backgroundColor.r, root.backgroundColor.g,
root.backgroundColor.b, root.backgroundOpacity)
antialiasing: true
Behavior on color {
@ -211,7 +216,7 @@ Window {
DragHandler {
acceptedDevices: PointerDevice.GenericPointer
grabPermissions: PointerHandler.CanTakeOverFromItems | PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByAnything
onActiveChanged: if (active) { root.startSystemMove() }
onActiveChanged: if (active) { windowHelper.startSystemMove(root) }
}
}
@ -240,7 +245,7 @@ Window {
WindowButton {
size: 35
source: "qrc:/meui/kit/images/" + (Meui.Theme.darkMode ? "dark/" : "light/") + "minimize.svg"
onClicked: root.showMinimized()
onClicked: windowHelper.minimizeWindow(root)
visible: root.visibility !== Window.FullScreen
Layout.alignment: Qt.AlignTop
}

@ -1,8 +1,28 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#include "meuikit.h"
#include "thememanager.h"
#include "iconthemeprovider.h"
#include "shadowhelper/windowshadow.h"
#include "blurhelper/windowblur.h"
#include "windowhelper.h"
#include <QDebug>
#include <QQmlEngine>
@ -31,6 +51,7 @@ void MeuiKit::registerTypes(const char *uri)
qmlRegisterType<WindowShadow>(uri, 1, 0, "WindowShadow");
qmlRegisterType<WindowBlur>(uri, 1, 0, "WindowBlur");
qmlRegisterType<WindowHelper>(uri, 1, 0, "WindowHelper");
qmlRegisterSingletonType(componentUrl(QStringLiteral("Theme.qml")), uri, 1, 0, "Theme");
qmlRegisterSingletonType(componentUrl(QStringLiteral("Units.qml")), uri, 1, 0, "Units");

@ -1,3 +1,22 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#ifndef MEUIKIT_H
#define MEUIKIT_H
@ -21,4 +40,4 @@ private:
};
#endif // MEUIKIT_H
#endif // MEUIKIT_H

@ -1,3 +1,22 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#include "thememanager.h"
#include <QDBusConnection>

@ -1,3 +1,22 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#ifndef THEMEMANAGER_H
#define THEMEMANAGER_H

@ -0,0 +1,102 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#include "windowhelper.h"
#include <QApplication>
#include <QX11Info>
#include <QCursor>
#include <KWindowSystem>
static uint qtEdgesToXcbMoveResizeDirection(Qt::Edges edges)
{
if (edges == (Qt::TopEdge | Qt::LeftEdge))
return 0;
if (edges == Qt::TopEdge)
return 1;
if (edges == (Qt::TopEdge | Qt::RightEdge))
return 2;
if (edges == Qt::RightEdge)
return 3;
if (edges == (Qt::RightEdge | Qt::BottomEdge))
return 4;
if (edges == Qt::BottomEdge)
return 5;
if (edges == (Qt::BottomEdge | Qt::LeftEdge))
return 6;
if (edges == Qt::LeftEdge)
return 7;
return 0;
}
WindowHelper::WindowHelper(QObject *parent)
: QObject(parent)
, m_moveResizeAtom(0)
{
// create move-resize atom
xcb_connection_t* connection(QX11Info::connection());
const QString atomName(QStringLiteral("_NET_WM_MOVERESIZE"));
xcb_intern_atom_cookie_t cookie(xcb_intern_atom(connection, false, atomName.size(), qPrintable(atomName)));
QScopedPointer<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(connection, cookie, nullptr));
m_moveResizeAtom = reply ? reply->atom : 0;
}
void WindowHelper::startSystemMove(QWindow *w)
{
doStartSystemMoveResize(w, 16);
}
void WindowHelper::startSystemResize(QWindow *w, Qt::Edges edges)
{
doStartSystemMoveResize(w, edges);
}
void WindowHelper::minimizeWindow(QWindow *w)
{
KWindowSystem::minimizeWindow(w->winId());
}
void WindowHelper::doStartSystemMoveResize(QWindow *w, int edges)
{
const qreal dpiRatio = qApp->devicePixelRatio();
xcb_connection_t *connection(QX11Info::connection());
xcb_client_message_event_t xev;
xev.response_type = XCB_CLIENT_MESSAGE;
xev.type = m_moveResizeAtom;
xev.sequence = 0;
xev.window = w->winId();
xev.format = 32;
xev.data.data32[0] = QCursor::pos().x() * dpiRatio;
xev.data.data32[1] = QCursor::pos().y() * dpiRatio;
if (edges == 16)
xev.data.data32[2] = 8; // move
else
xev.data.data32[2] = qtEdgesToXcbMoveResizeDirection(Qt::Edges(edges));
xev.data.data32[3] = XCB_BUTTON_INDEX_1;
xev.data.data32[4] = 0;
xcb_ungrab_pointer(connection, XCB_CURRENT_TIME);
xcb_send_event(connection, false, QX11Info::appRootWindow(),
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
(const char *)&xev);
}

@ -0,0 +1,46 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: cutefish <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/>.
*/
#ifndef WINDOWHELPER_H
#define WINDOWHELPER_H
#include <QObject>
#include <QWindow>
#include <xcb/xcb.h>
class WindowHelper : public QObject
{
Q_OBJECT
public:
explicit WindowHelper(QObject *parent = nullptr);
Q_INVOKABLE void startSystemMove(QWindow *w);
Q_INVOKABLE void startSystemResize(QWindow *w, Qt::Edges edges);
Q_INVOKABLE void minimizeWindow(QWindow *w);
private:
void doStartSystemMoveResize(QWindow *w, int edges);
private:
xcb_atom_t m_moveResizeAtom;
};
#endif // WINDOWHELPER_H
Loading…
Cancel
Save