!1 解决纯wayland环境看图启动不了的问题

This commit is contained in:
zoujunnan0613 2022-06-30 08:15:59 +00:00 committed by handsome_feng
parent 2ab479199a
commit 4825f94fde
9 changed files with 56 additions and 381 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
kylin-photo-viewer (1.3.0.3-ok2) yangtze; urgency=medium
* 解决应用启动不了的问题
-- Xie Wei <xiewei@kylinos.cn> Thu, 30 Jun 2022 18:43:28 +0800
kylin-photo-viewer (1.3.0.3-ok1) yangtze; urgency=medium
* build for openKylin

1
debian/control vendored
View File

@ -20,7 +20,6 @@ Build-Depends: debhelper (>=9),
libqt5svg5-dev,
libqt5x11extras5-dev,
libstb-dev,
libukui-log4qt-dev,
pkgconf,
qt5-qmake,
qtbase5-dev,

View File

@ -16,10 +16,8 @@
#include <QApplication>
#include <QLibraryInfo>
#include <QTranslator>
#include <ukui-log4qt.h>
#include "global/log.h"
#include "controller/interaction.h"
#include "view/xatom-helper.h"
#include <QLoggingCategory>
#include "view/openimage.h"
#include <window_management.hpp>

View File

@ -14,6 +14,7 @@ CONFIG += link_pkgconfig
PKGCONFIG += gio-unix-2.0
LIBS += -lpeony \
LIBS += -lX11
#适配sdk
PKGCONFIG += kysdk-qtwidgets
#kysdk
@ -26,11 +27,8 @@ INCLUDEPATH += /usr/include/kabase/kylin_system/
INCLUDEPATH += /usr/include/kysdk/applications/kabase/
CONFIG += c++11
# 适配窗口管理器圆角阴影
LIBS +=-lpthread
LIBS +=-lX11
#log
LIBS += -L/usr/lib/libukui-log4qt.so.1.0.0 -lukui-log4qt
TARGET = kylin-photo-viewer
TEMPLATE = app
@ -82,8 +80,7 @@ SOURCES += main.cpp \
view/sidebar.cpp \
view/sidebardelegate.cpp \
view/titlebar.cpp \
view/toolbar.cpp \
view/xatom-helper.cpp
view/toolbar.cpp
HEADERS += \
controller/core/coreinteraction.h \
@ -114,8 +111,7 @@ HEADERS += \
view/sidebardelegate.h \
view/sizedate.h \
view/titlebar.h \
view/toolbar.h \
view/xatom-helper.h
view/toolbar.h
RESOURCES += \
../res.qrc

View File

@ -1,6 +1,7 @@
#include "kyview.h"
#include "xatom-helper.h"
#include "sizedate.h"
#include "X11/Xlib.h"
#include <QX11Info>
KyView *KyView::mutual = nullptr;
KyView::KyView(const QStringList &args)
{
@ -781,25 +782,29 @@ void KyView::mouseMoveEvent(QMouseEvent *event)
this->releaseMouse();
}
}
XEvent xEvent;
memset(&xEvent, 0, sizeof(XEvent));
QString platform = QGuiApplication::platformName();
if (!platform.startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
XEvent xEvent;
memset(&xEvent, 0, sizeof(XEvent));
Display *display = QX11Info::display();
xEvent.xclient.type = ClientMessage;
xEvent.xclient.message_type = XInternAtom(display, "_NET_WM_MOVERESIZE", False);
xEvent.xclient.display = display;
xEvent.xclient.window = (XID)(this->winId());
xEvent.xclient.format = 32;
xEvent.xclient.data.l[0] = pos.x() * device;
xEvent.xclient.data.l[1] = pos.y() * device;
xEvent.xclient.data.l[2] = 8;
xEvent.xclient.data.l[3] = Button1;
xEvent.xclient.data.l[4] = 1;
Display *display = QX11Info::display();
xEvent.xclient.type = ClientMessage;
xEvent.xclient.message_type = XInternAtom(display, "_NET_WM_MOVERESIZE", False);
xEvent.xclient.display = display;
xEvent.xclient.window = (XID)(this->winId());
xEvent.xclient.format = 32;
xEvent.xclient.data.l[0] = pos.x() * device;
xEvent.xclient.data.l[1] = pos.y() * device;
xEvent.xclient.data.l[2] = 8;
xEvent.xclient.data.l[3] = Button1;
xEvent.xclient.data.l[4] = 1;
XUngrabPointer(display, CurrentTime);
XSendEvent(display, QX11Info::appRootWindow(QX11Info::appScreen()), False,
SubstructureNotifyMask | SubstructureRedirectMask, &xEvent);
XFlush(display);
}
XUngrabPointer(display, CurrentTime);
XSendEvent(display, QX11Info::appRootWindow(QX11Info::appScreen()), False,
SubstructureNotifyMask | SubstructureRedirectMask, &xEvent);
XFlush(display);
event->accept();
}
void KyView::mousePressEvent(QMouseEvent *event)
@ -1159,25 +1164,28 @@ void KyView::x11EventEnd()
}
QPoint globalPoints = QCursor::pos();
XEvent xEvent;
memset(&xEvent, 0, sizeof(XEvent));
Display *display = QX11Info::display();
xEvent.type = ButtonRelease;
xEvent.xbutton.button = Button1;
xEvent.xbutton.window = this->effectiveWinId();
if (globalPoints.y() < 5) {
xEvent.xbutton.x = globalPoints.x() * device;
xEvent.xbutton.y = globalPoints.y() * device;
} else {
xEvent.xbutton.x = this->mapFromGlobal(globalPoints).x() * device;
xEvent.xbutton.y = this->mapFromGlobal(globalPoints).y() * device;
}
xEvent.xbutton.x_root = globalPoints.x() * device;
xEvent.xbutton.y_root = globalPoints.y() * device;
xEvent.xbutton.display = display;
QString platform = QGuiApplication::platformName();
if (!platform.startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
XEvent xEvent;
memset(&xEvent, 0, sizeof(XEvent));
Display *display = QX11Info::display();
xEvent.type = ButtonRelease;
xEvent.xbutton.button = Button1;
xEvent.xbutton.window = this->effectiveWinId();
if (globalPoints.y() < 5) {
xEvent.xbutton.x = globalPoints.x() * device;
xEvent.xbutton.y = globalPoints.y() * device;
} else {
xEvent.xbutton.x = this->mapFromGlobal(globalPoints).x() * device;
xEvent.xbutton.y = this->mapFromGlobal(globalPoints).y() * device;
}
xEvent.xbutton.x_root = globalPoints.x() * device;
xEvent.xbutton.y_root = globalPoints.y() * device;
xEvent.xbutton.display = display;
XSendEvent(display, this->effectiveWinId(), False, ButtonReleaseMask, &xEvent);
XFlush(display);
XSendEvent(display, this->effectiveWinId(), False, ButtonReleaseMask, &xEvent);
XFlush(display);
}
}
// 手势识别

View File

@ -29,7 +29,7 @@
#include <QPainterPath>
#include <QPainter>
#include <QStyleOption>
#include <QX11Info>
#include <KF5/KWindowSystem/kwindowsystem.h>
#include <QThread>
#include "toolbar.h"

View File

@ -1,6 +1,5 @@
#include "menumodule.h"
#include "kyview.h"
#include "xatom-helper.h"
#include "sizedate.h"
menuModule::menuModule(QWidget *parent = nullptr) : QWidget(parent)
{
@ -135,13 +134,6 @@ void menuModule::initAbout()
m_aboutWindow->setAutoFillBackground(true);
m_aboutWindow->setBackgroundRole(QPalette::Base);
MotifWmHints hints;
hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
hints.functions = MWM_FUNC_ALL;
hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(m_aboutWindow->winId(), hints);
m_aboutWindow->setFixedSize(M_ABOUT);
// m_aboutWindow->setMinimumHeight(M_ABOUT.height());
QVBoxLayout *mainlyt = new QVBoxLayout();

View File

@ -1,210 +0,0 @@
/*
* KWin Style UKUI
*
* Copyright (C) 2020, KylinSoft Co., Ltd.
*
* 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
* (at your option) 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 <https://www.gnu.org/licenses/>.
*
* Authors: Yue Lan <lanyue@kylinos.cn>
*
*/
#include "xatom-helper.h"
#include <limits.h>
#include <QX11Info>
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <NETWM>
static XAtomHelper *global_instance = nullptr;
XAtomHelper *XAtomHelper::getInstance()
{
if (!global_instance)
global_instance = new XAtomHelper;
return global_instance;
}
bool XAtomHelper::isFrameLessWindow(int winId)
{
auto hints = getInstance()->getWindowMotifHint(winId);
if (hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) {
return true;
}
return false;
}
bool XAtomHelper::isWindowDecorateBorderOnly(int winId)
{
return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId));
}
bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint)
{
bool isDeco = false;
if (hint.flags & MWM_HINTS_DECORATIONS && hint.flags != MWM_HINTS_DECORATIONS) {
if (hint.decorations == MWM_DECOR_BORDER)
isDeco = true;
}
return isDeco;
}
bool XAtomHelper::isUKUICsdSupported()
{
// fixme:
return false;
}
bool XAtomHelper::isUKUIDecorationWindow(int winId)
{
if (m_ukuiDecorationAtion == None)
return false;
unsigned long type;
int format;
ulong nitems;
ulong bytes_after;
uchar *data;
bool isUKUIDecoration = false;
XGetWindowProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, 0, LONG_MAX, false, m_ukuiDecorationAtion,
&type, &format, &nitems, &bytes_after, &data);
if (type == m_ukuiDecorationAtion) {
if (nitems == 1) {
isUKUIDecoration = data[0];
}
}
return isUKUIDecoration;
}
UnityCorners XAtomHelper::getWindowBorderRadius(int winId)
{
UnityCorners corners;
Atom type;
int format;
ulong nitems;
ulong bytes_after;
uchar *data;
if (m_unityBorderRadiusAtom != None) {
XGetWindowProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, 0, LONG_MAX, false, XA_CARDINAL, &type,
&format, &nitems, &bytes_after, &data);
if (type == XA_CARDINAL) {
if (nitems == 4) {
corners.topLeft = static_cast<ulong>(data[0]);
corners.topRight = static_cast<ulong>(data[1 * sizeof(ulong)]);
corners.bottomLeft = static_cast<ulong>(data[2 * sizeof(ulong)]);
corners.bottomRight = static_cast<ulong>(data[3 * sizeof(ulong)]);
}
XFree(data);
}
}
return corners;
}
void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data)
{
if (m_unityBorderRadiusAtom == None)
return;
ulong corners[4] = {data.topLeft, data.topRight, data.bottomLeft, data.bottomRight};
XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, 32, XCB_PROP_MODE_REPLACE,
(const unsigned char *)&corners, sizeof(corners) / sizeof(corners[0]));
}
void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight)
{
if (m_unityBorderRadiusAtom == None)
return;
ulong corners[4] = {(ulong)topLeft, (ulong)topRight, (ulong)bottomLeft, (ulong)bottomRight};
XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, 32, XCB_PROP_MODE_REPLACE,
(const unsigned char *)&corners, sizeof(corners) / sizeof(corners[0]));
}
void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set)
{
if (m_ukuiDecorationAtion == None)
return;
XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE,
(const unsigned char *)&set, 1);
}
void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints)
{
if (m_unityBorderRadiusAtom == None)
return;
XChangeProperty(QX11Info::display(), winId, m_motifWMHintsAtom, m_motifWMHintsAtom, 32, XCB_PROP_MODE_REPLACE,
(const unsigned char *)&hints, sizeof(MotifWmHints) / sizeof(ulong));
}
MotifWmHints XAtomHelper::getWindowMotifHint(int winId)
{
MotifWmHints hints;
if (m_unityBorderRadiusAtom == None)
return hints;
uchar *data;
Atom type;
int format;
ulong nitems;
ulong bytes_after;
XGetWindowProperty(QX11Info::display(), winId, m_motifWMHintsAtom, 0, sizeof(MotifWmHints) / sizeof(long), false,
AnyPropertyType, &type, &format, &nitems, &bytes_after, &data);
if (type == None) {
return hints;
} else {
hints = *(MotifWmHints *)data;
XFree(data);
}
return hints;
}
XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent)
{
if (!QX11Info::isPlatformX11())
return;
m_motifWMHintsAtom = XInternAtom(QX11Info::display(), "_MOTIF_WM_HINTS", true);
m_unityBorderRadiusAtom = XInternAtom(QX11Info::display(), "_UNITY_GTK_BORDER_RADIUS", false);
m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false);
}
Atom XAtomHelper::registerUKUICsdNetWmSupportAtom()
{
// fixme:
return None;
}
void XAtomHelper::unregisterUKUICsdNetWmSupportAtom()
{
// fixme:
}

View File

@ -1,114 +0,0 @@
/*
* KWin Style UKUI
*
* Copyright (C) 2020, KylinSoft Co., Ltd.
*
* 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
* (at your option) 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 <https://www.gnu.org/licenses/>.
*
* Authors: Yue Lan <lanyue@kylinos.cn>
*
*/
#ifndef XATOMHELPER_H
#define XATOMHELPER_H
#include <QObject>
#include <X11/Xlib.h>
#include <NETWM>
struct UnityCorners
{
ulong topLeft = 0;
ulong topRight = 0;
ulong bottomLeft = 0;
ulong bottomRight = 0;
};
typedef struct
{
ulong flags = 0;
ulong functions = 0;
ulong decorations = 0;
long input_mode = 0;
ulong status = 0;
} MotifWmHints, MwmHints;
#define MWM_HINTS_FUNCTIONS (1L << 0)
#define MWM_HINTS_DECORATIONS (1L << 1)
#define MWM_HINTS_INPUT_MODE (1L << 2)
#define MWM_HINTS_STATUS (1L << 3)
#define MWM_FUNC_ALL (1L << 0)
#define MWM_FUNC_RESIZE (1L << 1)
#define MWM_FUNC_MOVE (1L << 2)
#define MWM_FUNC_MINIMIZE (1L << 3)
#define MWM_FUNC_MAXIMIZE (1L << 4)
#define MWM_FUNC_CLOSE (1L << 5)
#define MWM_DECOR_ALL (1L << 0)
#define MWM_DECOR_BORDER (1L << 1)
#define MWM_DECOR_RESIZEH (1L << 2)
#define MWM_DECOR_TITLE (1L << 3)
#define MWM_DECOR_MENU (1L << 4)
#define MWM_DECOR_MINIMIZE (1L << 5)
#define MWM_DECOR_MAXIMIZE (1L << 6)
#define MWM_INPUT_MODELESS 0
#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
#define MWM_INPUT_SYSTEM_MODAL 2
#define MWM_INPUT_FULL_APPLICATION_MODAL 3
#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
#define MWM_TEAROFF_WINDOW (1L << 0)
namespace UKUI
{
class Decoration;
}
class XAtomHelper : public QObject
{
friend class UKUI::Decoration;
Q_OBJECT
public:
static XAtomHelper *getInstance();
static bool isFrameLessWindow(int winId);
bool isWindowDecorateBorderOnly(int winId);
bool isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint);
bool isUKUICsdSupported();
bool isUKUIDecorationWindow(int winId);
UnityCorners getWindowBorderRadius(int winId);
void setWindowBorderRadius(int winId, const UnityCorners &data);
void setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight);
void setUKUIDecoraiontHint(int winId, bool set = true);
void setWindowMotifHint(int winId, const MotifWmHints &hints);
MotifWmHints getWindowMotifHint(int winId);
private:
explicit XAtomHelper(QObject *parent = nullptr);
unsigned long registerUKUICsdNetWmSupportAtom();
void unregisterUKUICsdNetWmSupportAtom();
unsigned long m_motifWMHintsAtom = 0;
unsigned long m_unityBorderRadiusAtom = 0;
unsigned long m_ukuiDecorationAtion = 0;
};
#endif // XATOMHELPER_H