Compat KOS for V10Pro and Huawei PC

This commit is contained in:
chenlelin 2021-02-25 21:53:41 +08:00
parent 71c5fc0e2b
commit eba2ea2689
2 changed files with 212 additions and 53 deletions

View File

@ -41,6 +41,9 @@ MainWindow::MainWindow(QWidget *parent) :
syslog(LOG_DEBUG, "Using the icon theme named 'ukui-icon-theme-default'");
QIcon::setThemeName("ukui-icon-theme-default");
PrimaryManager();
toStart();
// 如果使用Qt::Popup 任务栏不显示且保留X事件如XCB_FOCUS_OUT, 但如果indicator点击鼠标右键触发XCB_FOCUS_OUT事件依然会失效
// 如果使用Qt::ToolTip, Qt::Tool + Qt::WindowStaysOnTopHint, Qt::X11BypassWindowManagerHint等flag则会导致X事件失效
// this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
@ -696,66 +699,132 @@ void MainWindow::handleIconClicked()
int m = objKyDBus->getTaskBarHeight("height");
int d = 4; //窗口边沿到任务栏距离
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()) {
if (n == 0) {
//任务栏在下侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - m - d);
} else if(n == 1) {
//任务栏在上侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m + d);
} else if (n == 2) {
//任务栏在左侧
if (screenGeometry.x() == 0) {//主屏在左侧
this->move(m + d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else {//主屏在右侧
this->move(screenMainRect.x() + m + d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
if (isHuaWeiPC) {
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()) {
if (n == 0) {
//任务栏在下侧
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - m - d);
} else if(n == 1) {
//任务栏在上侧
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m + d);
} else if (n == 2) {
//任务栏在左侧
if (screenGeometry.x() == 0) {//主屏在左侧
this->move(m_priX + m + d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else {//主屏在右侧
this->move(m_priX + m + d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
}
} else if (n == 3) {
//任务栏在右侧
if (screenGeometry.x() == 0) {//主屏在左侧
this->move(m_priX + screenMainRect.width() - this->width() - m - d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else {//主屏在右侧
this->move(m_priX + screenMainRect.width() - this->width() - m - d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
}
}
} else if (n == 3) {
//任务栏在右侧
if (screenGeometry.x() == 0) {//主屏在左侧
this->move(screenMainRect.width() - this->width() - m - d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else {//主屏在右侧
this->move(screenMainRect.x() + screenMainRect.width() - this->width() - m - d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else if(screenGeometry.width() == availableGeometry.width() ) {
if (trayIcon->geometry().y() > availableGeometry.height()/2) {
//任务栏在下侧
if (screenGeometry.height() - 20 < availableGeometry.height()) {
//任务栏隐藏
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - m );
} else {
//任务栏不隐藏
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - d);
}
} else {
//任务栏在上侧
if (screenGeometry.height() - 20 < availableGeometry.height()) {
//任务栏隐藏
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m );
} else {
//任务栏不隐藏
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + d);
}
}
} else if (screenGeometry.height() == availableGeometry.height()) {
if (trayIcon->geometry().x() > availableGeometry.width()/2) {
//任务栏在右侧
if (screenGeometry.width() - 20 < availableGeometry.width()) {
//任务栏隐藏
this->move(m_priX + availableGeometry.width() - this->width() - m, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
} else {
//任务栏不隐藏
this->move(m_priX + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
}
} else {
//任务栏在左侧
if (screenGeometry.width() - 20 < availableGeometry.width()) {
//任务栏隐藏
this->move(m_priX + screenGeometry.width() - availableGeometry.width() + m, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
} else {
//任务栏不隐藏
this->move(m_priX + screenGeometry.width() - availableGeometry.width() + d, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
}
}
}
} else if(screenGeometry.width() == availableGeometry.width() ) {
if (trayIcon->geometry().y() > availableGeometry.height()/2) {
//任务栏在下侧
if (screenGeometry.height() - 20 < availableGeometry.height()) {
//任务栏隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - m );
} else {
//任务栏不隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - d);
} else {
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()) {
if (n == 0) {
//任务栏在下侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - m - d);
} else if(n == 1) {
//任务栏在上侧
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m + d);
} else if (n == 2) {
//任务栏在左侧
if (screenGeometry.x() == 0) {//主屏在左侧
this->move(m + d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else {//主屏在右侧
this->move(screenMainRect.x() + m + d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
}
} else if (n == 3) {
//任务栏在右侧
if (screenGeometry.x() == 0) {//主屏在左侧
this->move(screenMainRect.width() - this->width() - m - d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
} else {//主屏在右侧
this->move(screenMainRect.x() + screenMainRect.width() - this->width() - m - d, screenMainRect.y() + screenMainRect.height() - this->height() - d);
}
}
} else {
//任务栏在上侧
if (screenGeometry.height() - 20 < availableGeometry.height()) {
//任务栏隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m );
} else if(screenGeometry.width() == availableGeometry.width() ) {
if (trayIcon->geometry().y() > availableGeometry.height()/2) {
//任务栏在下侧
if (screenGeometry.height() - 20 < availableGeometry.height()) {
//任务栏隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - m );
} else {
//任务栏不隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + availableGeometry.height() - this->height() - d);
}
} else {
//任务栏不隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + d);
//任务栏在上侧
if (screenGeometry.height() - 20 < availableGeometry.height()) {
//任务栏隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + m );
} else {
//任务栏不隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + d);
}
}
}
} else if (screenGeometry.height() == availableGeometry.height()) {
if (trayIcon->geometry().x() > availableGeometry.width()/2) {
//任务栏在右侧
if (screenGeometry.width() - 20 < availableGeometry.width()) {
//任务栏隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - m, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
} else if (screenGeometry.height() == availableGeometry.height()) {
if (trayIcon->geometry().x() > availableGeometry.width()/2) {
//任务栏在右侧
if (screenGeometry.width() - 20 < availableGeometry.width()) {
//任务栏隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - m, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
} else {
//任务栏不隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
}
} else {
//任务栏不隐藏
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
}
} else {
//任务栏在左侧
if (screenGeometry.width() - 20 < availableGeometry.width()) {
//任务栏隐藏
this->move(screenGeometry.width() - availableGeometry.width() + m, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
} else {
//任务栏不隐藏
this->move(screenGeometry.width() - availableGeometry.width() + d, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
//任务栏在左侧
if (screenGeometry.width() - 20 < availableGeometry.width()) {
//任务栏隐藏
this->move(screenGeometry.width() - availableGeometry.width() + m, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
} else {
//任务栏不隐藏
this->move(screenGeometry.width() - availableGeometry.width() + d, screenMainRect.y() + screenGeometry.height() - this->height() - d - 3);
}
}
}
}
@ -3159,3 +3228,77 @@ void MainWindow::getSystemFontFamily()
}
});
}
///////////////////////////////////////////////////////////////////////////////
//解决双屏幕问题用到的dbus方法
void MainWindow::PrimaryManager()
{
//QDBusConnection conn = QDBusConnection::sessionBus();
mDbusXrandInter = new QDBusInterface(DBUS_NAME,
DBUS_PATH,
DBUS_INTERFACE,
QDBusConnection::sessionBus());
isHuaWeiPC = false;
QDBusMessage message = QDBusMessage::createMethodCall(DBUS_NAME,
DBUS_PATH,
DBUS_INTERFACE,
"height");
QDBusMessage response = QDBusConnection::sessionBus().call(message);
if (response.type() == QDBusMessage::ReplyMessage) {
isHuaWeiPC = true;
}
connect(mDbusXrandInter, SIGNAL(screenPrimaryChanged(int,int,int,int)),
this, SLOT(priScreenChanged(int,int,int,int)));
}
void MainWindow::toStart()
{
m_priX = getScreenGeometry("x");
m_priY = getScreenGeometry("y");
m_priWid = getScreenGeometry("width");
m_priHei = getScreenGeometry("height");
if (m_priWid == 0 || m_priHei == 0) {
QRect rect = QApplication::desktop()->screenGeometry(0);
m_priX=rect.x();
m_priY=rect.y();
m_priWid=rect.width();
m_priHei=rect.height();
}
//qDebug("Start: Primary screen geometry is x=%d, y=%d, windth=%d, height=%d", m_priX, m_priY, m_priWid, m_priHei);
}
int MainWindow::getScreenGeometry(QString methodName)
{
int res = 0;
QDBusMessage message = QDBusMessage::createMethodCall(DBUS_NAME,
DBUS_PATH,
DBUS_INTERFACE,
methodName);
QDBusMessage response = QDBusConnection::sessionBus().call(message);
if (response.type() == QDBusMessage::ReplyMessage)
{
if(response.arguments().isEmpty() == false) {
int value = response.arguments().takeFirst().toInt();
res = value;
qDebug() << value;
}
} else {
qDebug()<< "to get message about "<< methodName<<" of screen failed";
}
return res;
}
/* get primary screen changed */
void MainWindow::priScreenChanged(int x, int y, int width, int height)
{
m_priX = x;
m_priY = y;
m_priWid = width;
m_priHei = height;
qDebug("primary screen changed, geometry is x=%d, y=%d, windth=%d, height=%d", x, y, width, height);
}

View File

@ -105,6 +105,10 @@
#define W_NO_ITEM_TIP 235
#define H_NO_ITEM_TIP 20
#define DBUS_NAME "org.ukui.SettingsDaemon"
#define DBUS_PATH "/org/ukui/SettingsDaemon/wayland"
#define DBUS_INTERFACE "org.ukui.SettingsDaemon.wayland"
class OneConnForm;
class ConfForm;
@ -138,6 +142,9 @@ public:
void checkIsWirelessDeviceOn();
void initActNetDNS();
void PrimaryManager();
void toStart();
int getScreenGeometry(QString methodName);
QIcon iconLanOnline, iconLanOffline;
QIcon iconWifiFull, iconWifiHigh, iconWifiMedium, iconWifiLow;
@ -169,6 +176,11 @@ public:
bool isToSetLanValue = true; //本次执行是否进行赋值
bool isToSetWifiValue = true; //本次执行是否进行赋值
int m_priX;
int m_priY;
int m_priWid;
int m_priHei;
public slots:
void onPhysicalCarrierChanged(bool flag);
void onCarrierUpHandle();
@ -301,6 +313,8 @@ private:
QString actWifiUuid = "--"; //当前连接wifi的uuid
bool hasWifiConnected;//当前是否有wifi连接
QDBusInterface *mDbusXrandInter;
int isHuaWeiPC;
private slots:
void iconActivated(QSystemTrayIcon::ActivationReason reason);
@ -346,6 +360,8 @@ private slots:
void onBtnCreateNetClicked();
void actionTriggerSlots();
void priScreenChanged(int x, int y, int width, int height);
signals:
void disConnSparedNet(QString type);