It can run in X environment.

This commit is contained in:
sunjunhao 2022-06-19 17:22:03 +08:00
parent cdd9005043
commit de4e6d6c0c
46 changed files with 1751 additions and 372 deletions

View File

@ -30,6 +30,7 @@
#include <unistd.h>
#include <fcntl.h>
#include "usd_global_define.h"
#define LOG_LEVEL LOG_DEBUG

View File

@ -24,6 +24,7 @@ SOURCES += \
HEADERS += \
$$PWD/clib-syslog.h \
$$PWD/manager.h \
$$PWD/plugin-interface.h \
$$PWD/QGSettings/qconftype.h \
$$PWD/QGSettings/qgsettings.h \

13
common/manager.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef MANAGER_H
#define MANAGER_H
#include <QObject>
class Manager : public QObject
{
public:
Manager(QObject * parent){}
virtual ~Manager() {}
virtual bool start() = 0;
virtual void stop() = 0;
};
#endif // MANAGER_H

View File

@ -28,7 +28,7 @@ class PluginInterface;
class PluginInterface
{
public:
virtual ~PluginInterface() {};
virtual ~PluginInterface() {}
virtual void activate () = 0;
virtual void deactivate () = 0;

View File

@ -20,7 +20,6 @@
#ifndef USDBASECLASS_H
#define USDBASECLASS_H
#include <QObject>
#include <QMetaEnum>
#include <ukuisdk/kylin-com4cxx.h>
extern QString g_motify_poweroff;

View File

@ -11,6 +11,7 @@
class UsdOuputProperty : public QObject{
Q_OBJECT
Q_PROPERTY(QString name READ getname WRITE setname)
Q_PROPERTY(QString enable READ getenable WRITE setenable)
Q_PROPERTY(QString vendor READ getvendor WRITE setvendor)
Q_PROPERTY(QString product READ getproduct WRITE setproduct)
Q_PROPERTY(QString serial READ getserial WRITE setserial)
@ -38,6 +39,7 @@ public:
USD_LOG_SHOW_PARAMS(x.toLatin1().data());
USD_LOG_SHOW_PARAMS(y.toLatin1().data());
USD_LOG_SHOW_PARAMS(rate.toLatin1().data());
USD_LOG_SHOW_PARAMS(enable.toLatin1().data());
}
private:
@ -52,6 +54,7 @@ private:
DEFINE_QSTRING(y)
DEFINE_QSTRING(rotation)
DEFINE_QSTRING(primary)
DEFINE_QSTRING(enable)
};
class OutputsConfig{

View File

@ -12,7 +12,7 @@
<description>Swap left and right mouse buttons for left-handed mice.</description>
</key>
<key type="d" name="motion-acceleration">
<default>-1</default>
<default>5</default>
<summary>Motion Acceleration</summary>
<description>Acceleration multiplier for mouse motion. A value of -1 is the system default.</description>
</key>

18
debian/changelog vendored
View File

@ -1,8 +1,20 @@
ukui-settings-daemon (3.14.0.0~0512-0k0) v101; urgency=medium
ukui-settings-daemon (3.14.0.2) v101; urgency=medium
* 修改为quilt格式
* BUG号:116725 【2204】【控制面板】安装系统后控制面板鼠标指针默认速度设置为最慢但是实际速度不为最慢设置其他值后恢复正常
* 需求说明:无
* 其他改动说明:优化自适应分辨率的处理流程、优化登录恢复用户参数
* 其他改动影响域:无
-- Xie Wei <xiewei@kylinos.cn> Fri, 20 May 2022 16:40:51 +0800
-- sundagao <sundagao@kylinos.cn> Mon, 06 Jun 2022 16:27:14 +0800
ukui-settings-daemon (3.14.0.0~0530) v101; urgency=medium
* BUG号(未传包)
* 需求说明:
* 其他改动说明登录恢复用户参数模块修复单屏时无法恢复的问题修复模式ID改变后仍会有二次黑屏的bug
* 其他改动影响域:无
-- sunjunhao <sunjunhao@kylinos.cn> Mon, 30 May 2022 16:15:15 +0800
ukui-settings-daemon (3.14.0.0~0512) v101; urgency=medium

96
debian/control vendored
View File

@ -4,65 +4,67 @@ Priority: optional
Maintainer: Kylin Team <team+kylin@tracker.debian.org>
Uploaders: handsome_feng <jianfengli@ubuntukylin.com>
Build-Depends: debhelper-compat (=12),
intltool,
libcanberra-dev,
libcanberra-gtk-common-dev,
libcanberra-gtk3-dev,
libcolord-dev,
libgeoclue-2-dev,
libgnome-desktop-3-dev,
libgsettings-qt-dev,
libgudev-1.0-dev,
libimlib2-dev,
libkf5config-dev,
libkf5globalaccel-dev,
libkf5screen-dev,
libkf5windowsystem-dev,
liblcms2-dev,
libmate-desktop-dev,
libmatekbd-dev,
libmatemixer-dev,
libnotify-dev,
libpulse-dev,
libqt5sensors5-dev,
libqt5svg5-dev,
libqt5x11extras5-dev,
libukui-common-dev,
libwayland-client0,
libwnck-3-dev,
libx11-dev,
libxcb-util-dev,
libxcb1-dev,
libxkbcommon-dev,
libxklavier-dev,
libxtst-dev,
pkg-config,
intltool,
qt5-qmake,
qtchooser,
qtbase5-dev,
qtbase5-dev-tools,
qtchooser,
qttools5-dev-tools,
xserver-xorg-dev
libgsettings-qt-dev,
libqt5x11extras5-dev,
libqt5sensors5-dev,
libkf5config-dev,
libqt5svg5-dev,
libxklavier-dev,
libxtst-dev,
libmate-desktop-dev,
libgnome-desktop-3-dev,
libmatemixer-dev,
libmatekbd-dev,
libpulse-dev,
libwnck-3-dev,
libcanberra-gtk3-dev,
libcanberra-gtk-common-dev,
libcanberra-dev,
libwayland-client0,
libnotify-dev,
libgeoclue-2-dev,
libcolord-dev,
liblcms2-dev,
libimlib2-dev,
xserver-xorg-dev,
libgudev-1.0-dev,
libxcb1-dev,
libxcb-util-dev,
libx11-dev,
libkf5windowsystem-dev,
libkf5screen-dev,
libxkbcommon-dev,
libkf5globalaccel-dev,
libqt5x11extras5-dev,
libukui-common-dev,
Standards-Version: 4.6.0.1
Rules-Requires-Root: no
Homepage: http://www.ukui.org/
Vcs-Git: https://github.com/ukui/ukui-settings-daemon.git
Vcs-Browser: https://github.com/ukui/ukui-settings-daemon
Package: ukui-settings-daemon
Architecture: any
Depends: colord,
imwheel,
libglib2.0-bin,
mate-desktop-common (>= 1.18),
ukui-polkit,
Depends: mate-desktop-common (>= 1.18),
ukui-settings-daemon-common (= ${source:Version}),
colord,
imwheel,
ukui-polkit,
x11-xserver-utils,
xserver-xorg-input-synaptics [!s390x],
libglib2.0-bin,
${misc:Depends},
${shlibs:Depends}
Conflicts: kylin-display-switch
Replaces: kylin-display-switch
${shlibs:Depends},
Replaces: kylin-display-switch (<=3.1.0)
Breaks:kylin-display-switch (<=3.1.0)
Description: daemon handling the UKUI session settings
This package contains the daemon which is responsible for setting the
various parameters of a UKUI session and the applications that run
@ -81,7 +83,7 @@ Description: daemon handling the UKUI session settings
Package: ukui-settings-daemon-common
Architecture: all
Depends: ${misc:Depends}
Depends: ${misc:Depends},
Description: daemon handling the UKUI session settings (common files)
This package contains the daemon which is responsible for setting the
various parameters of a UKUI session and the applications that run
@ -99,3 +101,11 @@ Description: daemon handling the UKUI session settings (common files)
freedesktop.org XSETTINGS.
.
This package contains the architecture independent files.
Package: kylin-display-switch
Depends: ukui-settings-daemon, ${misc:Depends}
Architecture: any
Priority: optional
Section: oldlibs
Description: transitional package
This is a transitional package. It can safely be removed.

2
debian/source/local-options vendored Normal file
View File

@ -0,0 +1,2 @@
#abort-on-upstream-changes
#unapply-patches

View File

@ -1,6 +1,6 @@
man/authoritydbus.1
man/save-param.1
man/touchpad-state.1
man/ukui-settings-daemon.1
man/ukydisplayswitch.1
man/usd-locate-pointer.1
man/touchpad-state.1
man/save-param.1
man/authoritydbus.1
man/ukydisplayswitch.1

View File

@ -1,5 +1,6 @@
/etc/
/lib/udev/rules.d/
/usr/bin/
/usr/lib/*/ukui-settings-daemon/
/usr/share/dbus-1/
/lib/udev/rules.d/

View File

@ -25,6 +25,11 @@ A11yKeyboardManager *A11yKeyboardPlugin::UsdA11yManager= nullptr;
A11yKeyboardPlugin::A11yKeyboardPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"A11yKeyboardPlugin initializing ");
if(nullptr == UsdA11yManager)
UsdA11yManager = A11yKeyboardManager::A11KeyboardManagerNew();
@ -42,6 +47,11 @@ A11yKeyboardPlugin::~A11yKeyboardPlugin()
void A11yKeyboardPlugin::activate()
{
bool res;
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
res = UsdA11yManager->A11yKeyboardManagerStart();
if(!res)
@ -58,6 +68,10 @@ PluginInterface * A11yKeyboardPlugin::getInstance()
void A11yKeyboardPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"Deactivating A11y-Keyboard plugin");
UsdA11yManager->A11yKeyboardManagerStop();
}

View File

@ -23,6 +23,11 @@ PluginInterface* A11ySettingsPlugin::mInstance = nullptr;
A11ySettingsPlugin::A11ySettingsPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"A11SettingsPlugin initializing!");
settingsManager=A11ySettingsManager::A11ySettingsManagerNew();
}
@ -36,6 +41,10 @@ A11ySettingsPlugin::~A11ySettingsPlugin()
void A11ySettingsPlugin::activate()
{
bool res;
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"Activating a11y-settings plugincompilation time:[%s] [%s]",__DATE__,__TIME__);
res=settingsManager->A11ySettingsManagerStart();
@ -54,6 +63,10 @@ PluginInterface *A11ySettingsPlugin::getInstance()
void A11ySettingsPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"Deactivating a11y-settings plugin!");
settingsManager->A11ySettingsMAnagerStop();
}

View File

@ -18,7 +18,7 @@
*/
#include "clipboard-plugin.h"
#include "clib-syslog.h"
#include "usd_base_class.h"
ClipboardManager* ClipboardPlugin::mManager = nullptr;
PluginInterface* ClipboardPlugin::mInstance = nullptr;
@ -38,12 +38,21 @@ PluginInterface *ClipboardPlugin::getInstance()
void ClipboardPlugin::activate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
if (nullptr != mManager) mManager->managerStart();
}
void ClipboardPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
if (nullptr != mManager) mManager->managerStop();
if (nullptr != mInstance) {
delete mInstance;
@ -53,6 +62,11 @@ void ClipboardPlugin::deactivate()
ClipboardPlugin::ClipboardPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
if ((nullptr == mManager)) {
mManager = new ClipboardManager();
}

View File

@ -24,7 +24,7 @@
#include <QTimer>
#include <glib.h>
#include <geoclue.h>
#include <QVariant>
#include "color-state.h"
#include "color-profiles.h"

View File

@ -25,6 +25,11 @@ ColorManager *ColorPlugin::mColorManager = nullptr;
ColorPlugin::ColorPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
if(UsdBaseClass::isLoongarch()){
return;
}
@ -41,6 +46,11 @@ ColorPlugin::~ColorPlugin()
}
void ColorPlugin::activate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
if(UsdBaseClass::isLoongarch()){
return;
}
@ -53,6 +63,10 @@ void ColorPlugin::activate()
void ColorPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG (LOG_DEBUG, "deactivate %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
mColorManager->ColorManagerStop();
}

View File

@ -21,6 +21,7 @@
#define WIDGET_H
#include <QWidget>
#include <QMetaEnum>
#include <QKeyEvent>
#include <QButtonGroup>
#include <QGSettings/QGSettings>

View File

@ -18,12 +18,17 @@
*/
#include "keybindings-plugin.h"
#include "clib-syslog.h"
#include "usd_base_class.h"
PluginInterface *KeybindingsPlugin::mInstance=nullptr;
KeybindingsManager *KeybindingsPlugin::mKeyManager=nullptr;
KeybindingsPlugin::KeybindingsPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"KeybindingsPlugin initializing");
if(nullptr == mKeyManager)
mKeyManager = KeybindingsManager::KeybindingsManagerNew();
@ -41,6 +46,11 @@ KeybindingsPlugin::~KeybindingsPlugin()
void KeybindingsPlugin::activate()
{
bool res;
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
res = mKeyManager->KeybindingsManagerStart();
@ -57,6 +67,10 @@ PluginInterface *KeybindingsPlugin::getInstance()
void KeybindingsPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_DEBUG,"Dectivating Keybindings Plugin");
mKeyManager->KeybindingsManagerStop();
}

View File

@ -20,6 +20,7 @@
#include "clib-syslog.h"
#include "config.h"
#include "rfkillswitch.h"
#include "usd_base_class.h"
#define USD_KEYBOARD_SCHEMA "org.ukui.peripherals-keyboard"
@ -53,7 +54,7 @@ static void capslock_set_xkb_state(gboolean lock_state);
KeyboardManager *KeyboardManager::mKeyboardManager = nullptr;
KeyboardXkb *KeyboardManager::mKeyXkb = nullptr;
KeyboardManager::KeyboardManager(QObject * parent)
KeyboardManager::KeyboardManager(QObject * parent):Manager(parent)
{
if (mKeyXkb == nullptr)
mKeyXkb = new KeyboardXkb;
@ -117,7 +118,7 @@ KeyboardManager *KeyboardManager::KeyboardManagerNew()
}
bool KeyboardManager::KeyboardManagerStart()
bool KeyboardManager::start()
{
USD_LOG(LOG_DEBUG,"-- Keyboard Start Manager --");
@ -127,7 +128,7 @@ bool KeyboardManager::KeyboardManagerStart()
return true;
}
void KeyboardManager::KeyboardManagerStop()
void KeyboardManager::stop()
{
USD_LOG(LOG_DEBUG,"-- Keyboard Stop Manager --");

View File

@ -34,11 +34,14 @@
#include <QGSettings/qgsettings.h>
#include <QApplication>
//#include "keyboard-common.h"
#include "manager.h"
#include "xeventmonitor.h"
#include "keyboard-xkb.h"
#include "keyboard-widget.h"
#include "usd_base_class.h"
#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H
#include <X11/extensions/xf86misc.h>
#endif
@ -49,7 +52,7 @@
#endif
class KeyboardXkb;
class KeyboardManager : public QObject
class KeyboardManager : public Manager
{
Q_OBJECT
private:
@ -62,8 +65,8 @@ private:
public:
~KeyboardManager();
static KeyboardManager *KeyboardManagerNew();
bool KeyboardManagerStart();
void KeyboardManagerStop ();
bool start();
void stop ();
void usd_keyboard_manager_apply_settings(KeyboardManager *manager);
void numlock_install_xkb_callback ();

View File

@ -18,15 +18,25 @@
*/
#include "keyboard-plugin.h"
#include "clib-syslog.h"
#include "usd_base_class.h"
PluginInterface * KeyboardPlugin::mInstance=nullptr;
KeyboardManager * KeyboardPlugin::UsdKeyboardManager=nullptr;
Manager * KeyboardPlugin::UsdKeyboardManager=nullptr;
KeyboardPlugin::KeyboardPlugin()
{
USD_LOG(LOG_DEBUG,"KeyboardPlugin initializing!");
if(nullptr == UsdKeyboardManager)
UsdKeyboardManager = KeyboardManager::KeyboardManagerNew();
if(nullptr == UsdKeyboardManager) {
if (UsdBaseClass::isWayland()) {
UsdKeyboardManager = KeyboardWaylandManager::KeyboardWaylandManagerNew();
} else{
UsdKeyboardManager = KeyboardManager::KeyboardManagerNew();
}
}
//wayland
//UsdKeyboardManager = KeyboardWaylandManager::KeyboardManagerNew();
}
KeyboardPlugin::~KeyboardPlugin()
@ -42,7 +52,7 @@ void KeyboardPlugin::activate()
{
bool res;
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
res = UsdKeyboardManager->KeyboardManagerStart();
res = UsdKeyboardManager->start();
if(!res){
USD_LOG(LOG_ERR,"Unable to start Keyboard Manager!")
}
@ -60,7 +70,7 @@ PluginInterface * KeyboardPlugin::getInstance()
void KeyboardPlugin::deactivate()
{
USD_LOG(LOG_DEBUG,"Deactivating Keyboard Plugin");
UsdKeyboardManager->KeyboardManagerStop();
UsdKeyboardManager->stop();
}
PluginInterface *createSettingsPlugin()

View File

@ -20,6 +20,7 @@
#define KEYBOARDPLUGIN_H
#include "keyboard-manager.h"
#include "keyboard-wayland-manager.h"
#include "plugin-interface.h"
@ -36,7 +37,7 @@ private:
KeyboardPlugin(KeyboardPlugin&)=delete;
private:
static KeyboardManager *UsdKeyboardManager;
static Manager *UsdKeyboardManager;
static PluginInterface * mInstance;
};

View File

@ -0,0 +1,252 @@
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* 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
* 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 "keyboard-wayland-manager.h"
#include "clib-syslog.h"
#include "config.h"
#include "rfkillswitch.h"
#include "usd_base_class.h"
#define USD_KEYBOARD_SCHEMA "org.ukui.peripherals-keyboard"
#define UKCCOSD_SCHEMA "org.ukui.control-center.osd"
#define KYCCOSD_SCHEMA "org.kylin.control-center.osd"
#define KDSOSD_SCHEMA "org.ukui.kds.osd"
#define SHOW_TIP_KEY "show-lock-tip"
#define KEY_REPEAT "repeat"
#define KEY_CLICK "click"
#define KEY_RATE "rate"
#define KEY_DELAY "delay"
#define KEY_CLICK_VOLUME "click-volume"
#define KEY_BELL_PITCH "bell-pitch"
#define KEY_BELL_DURATION "bell-duration"
#define KEY_BELL_MODE "bell-mode"
#define KEY_NUMLOCK_STATE "numlock-state"
#define KEY_CAPSLOCK_STATE "capslock-state"
#define KEY_NUMLOCK_REMEMBER "remember-numlock-state"
#define KEY_DEFAULT_RATE 25
#define KEY_DEFAULT_DELAY 660
KeyboardWaylandManager *KeyboardWaylandManager::mKeyboardWaylandManager = nullptr;
KeyboardWaylandManager::KeyboardWaylandManager(QObject * parent):Manager(parent)
{
settings = new QGSettings(USD_KEYBOARD_SCHEMA);
stInstalled = true;
time = new QTimer(this);
const QByteArray id(UKCCOSD_SCHEMA);
const QByteArray idd(KYCCOSD_SCHEMA);
const QByteArray iid(KDSOSD_SCHEMA);
if (QGSettings::isSchemaInstalled(id)){
ksettings = new QGSettings(id);
} else if (QGSettings::isSchemaInstalled(idd)){
ksettings = new QGSettings(idd);
} else if (QGSettings::isSchemaInstalled(iid)){
ksettings = new QGSettings(iid);
} else {
stInstalled = false;
}
m_statusWidget = new KeyboardWidget();
}
KeyboardWaylandManager::~KeyboardWaylandManager()
{
if (settings) {
delete settings;
settings = nullptr;
}
if (time) {
delete time;
time = nullptr;
}
if (m_statusWidget) {
delete m_statusWidget;
m_statusWidget = nullptr;
}
if (ksettings) {
delete ksettings;
ksettings = nullptr;
}
}
KeyboardWaylandManager *KeyboardWaylandManager::KeyboardWaylandManagerNew()
{
if (nullptr == mKeyboardWaylandManager)
mKeyboardWaylandManager = new KeyboardWaylandManager(nullptr);
return mKeyboardWaylandManager;
}
bool KeyboardWaylandManager::start()
{
USD_LOG(LOG_DEBUG,"-- Keyboard Start Manager --");
connect(time,SIGNAL(timeout()),this,SLOT(start_keyboard_idle_cb()));
time->start(1500);
return true;
}
void KeyboardWaylandManager::stop()
{
USD_LOG(LOG_DEBUG,"-- Keyboard Stop Manager --");
}
static gboolean xkb_set_keyboard_autorepeat_rate(int delay, int rate)
{
int interval = (rate <= 0) ? 1000000 : 1000/rate;
Display *dpy = QX11Info::display();
if (delay <= 0)
{
delay = 1;
}
return XkbSetAutoRepeatRate(dpy, XkbUseCoreKbd, delay, interval);
}
void apply_repeat (KeyboardWaylandManager *manager)
{
bool repeat;
int rate;
int delay;
//Display *dpy = QX11Info::display();
repeat = manager->settings->get(KEY_REPEAT).toBool();
rate = manager->settings->get(KEY_RATE).toInt();
delay = manager->settings->get(KEY_DELAY).toInt();
if (rate < 0)
rate = KEY_DEFAULT_RATE;
if (delay < 0)
delay = KEY_DEFAULT_DELAY;
USD_LOG(LOG_DEBUG,"repeat = %d, rate = %d, delay = %d", repeat, rate, delay);
if (UsdBaseClass::isWayland()) {
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.ukui.KWin"),
QStringLiteral("/KWin"),
QStringLiteral("org.ukui.KWin"),
QStringLiteral("setKeyboardRepeat"));
QList<QVariant> args;
args.append(repeat);
args.append(rate);
args.append(delay);
message.setArguments(args);
QDBusConnection::sessionBus().asyncCall(message);
}
}
void KeyboardWaylandManager::apply_settings (QString keys)
{
/**
* Fix by HB* system reboot but rnumlock not available;
**/
char *key;
if(keys != NULL)
key = keys.toLatin1().data();
else
key=NULL;
//#ifdef HAVE_X11_EXTENSIONS_XKB_H
// bool rnumlock;
// rnumlock = settings->get(KEY_NUMLOCK_REMEMBER).toBool();
// if (rnumlock == 0 || key == NULL) {
// if (have_xkb && rnumlock) {
// numlock_set_xkb_state (numlock_get_settings_state (settings));
// capslock_set_xkb_state(settings->get(KEY_CAPSLOCK_STATE).toBool());
// USD_LOG(LOG_DEBUG,"apply keyboard ok.");
// }
// }
//#endif /* HAVE_X11_EXTENSIONS_XKB_H */
if (keys.compare(QString::fromLocal8Bit(KEY_CLICK)) == 0||
keys.compare(QString::fromLocal8Bit(KEY_CLICK_VOLUME)) == 0 ||
keys.compare(QString::fromLocal8Bit(KEY_BELL_PITCH)) == 0 ||
keys.compare(QString::fromLocal8Bit(KEY_BELL_DURATION)) == 0 ||
keys.compare(QString::fromLocal8Bit(KEY_BELL_MODE)) == 0) {
USD_LOG(LOG_DEBUG,"Bell setting '%s' changed, applying bell settings", key);
// apply_bell (this);
} else if (keys.compare(QString::fromLocal8Bit(KEY_NUMLOCK_REMEMBER)) == 0) {
USD_LOG(LOG_DEBUG,"Remember Num-Lock state '%s' changed, applying num-lock settings", key);
// apply_numlock (this);
} else if (keys.compare(QString::fromLocal8Bit(KEY_NUMLOCK_STATE)) == 0) {
USD_LOG(LOG_DEBUG,"Num-Lock state '%s' changed, will apply at next startup", key);
} else if (keys.compare(QString::fromLocal8Bit(KEY_REPEAT)) == 0 ||
keys.compare(QString::fromLocal8Bit(KEY_RATE)) == 0 ||
keys.compare(QString::fromLocal8Bit(KEY_DELAY)) == 0) {
USD_LOG(LOG_DEBUG,"Key repeat setting '%s' changed, applying key repeat settings", key);
apply_repeat (this);
} else {
// USD_LOG(LOG_DEBUG,"Unhandled settings change, key '%s'", key);
}
}
void KeyboardWaylandManager::start_keyboard_idle_cb ()
{
//wayland
time->stop();
connect(settings,SIGNAL(changed(QString)),this,SLOT(apply_settings(QString)));
apply_repeat (this);
// else {
// have_xkb = 0;
// settings->set(KEY_NUMLOCK_REMEMBER,TRUE);
// XEventMonitor::instance()->start();
// /* Essential - xkb initialization should happen before */
// mKeyXkb->usd_keyboard_xkb_init (this);
// #ifdef HAVE_X11_EXTENSIONS_XKB_H
// numlock_xkb_init (this);
// #endif /* HAVE_X11_EXTENSIONS_XKB_H */
// /* apply current settings before we install the callback */
// usd_keyboard_manager_apply_settings (this);
// // QObject::connect(settings, &QGSettings::changed, this, &KeyboardWaylandManager::apply_settings);
// connect(settings,SIGNAL(changed(QString)),this,SLOT(apply_settings(QString)));
// #ifdef HAVE_X11_EXTENSIONS_XKB_H
// numlock_install_xkb_callback();
// #endif /* HAVE_X11_EXTENSIONS_XKB_H */
// apply_repeat (this);
// apply_numlock (this);
// apply_bell(this);
// }
}

View File

@ -0,0 +1,86 @@
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* 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
* 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 KeyboardWaylandManager_H
#define KeyboardWaylandManager_H
#include <QObject>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QWidget>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QTimer>
#include <QtX11Extras/QX11Info>
#include <QGSettings/qgsettings.h>
#include <QApplication>
#include "manager.h"
#include "xeventmonitor.h"
#include "keyboard-xkb.h"
#include "keyboard-widget.h"
#include "usd_base_class.h"
#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H
#include <X11/extensions/xf86misc.h>
#endif
#ifdef HAVE_X11_EXTENSIONS_XKB_H
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#endif
class KeyboardXkb;
class KeyboardWaylandManager : public Manager
{
Q_OBJECT
private:
KeyboardWaylandManager()=delete;
KeyboardWaylandManager(KeyboardWaylandManager&)=delete;
KeyboardWaylandManager&operator=(const KeyboardWaylandManager&)=delete;
KeyboardWaylandManager(QObject *parent = nullptr);
public:
~KeyboardWaylandManager();
static KeyboardWaylandManager *KeyboardWaylandManagerNew();
bool start();
void stop ();
public Q_SLOTS:
void start_keyboard_idle_cb ();
void apply_settings (QString);
private:
friend void apply_repeat (KeyboardWaylandManager *manager);
private:
QTimer *time;
static KeyboardWaylandManager *mKeyboardWaylandManager;
QGSettings *settings;
QGSettings *ksettings;
int old_state;
bool stInstalled;
KeyboardWidget* m_statusWidget;
};
#endif // KeyboardWaylandManager_H

View File

@ -35,11 +35,13 @@ LIBS += \
SOURCES += \
keyboard-manager.cpp \
keyboard-plugin.cpp \
keyboard-wayland-manager.cpp \
keyboard-widget.cpp \
keyboard-xkb.cpp
HEADERS += \
keyboard-manager.h \
keyboard-wayland-manager.h \
keyboard-widget.h \
keyboard-xkb.h \
keyboard-plugin.h

View File

@ -245,7 +245,9 @@ bool MediaKeysManager::mediaKeysStart(GError*)
mDeviceWindow->initWindowInfo();
initShortcuts();
initXeventMonitor();
if (!UsdBaseClass::isWayland()) {
initXeventMonitor();
}
getConfigMonitor();
mDbusScreensaveMessage = QDBusMessage::createMethodCall("org.ukui.ScreenSaver",
"/",
@ -310,7 +312,7 @@ void MediaKeysManager::initShortcuts()
doAction(WEBCAM_KEY);
});
if (false == UsdBaseClass::isUseXEventAsShutKey()) {
if (!UsdBaseClass::isWayland()) {
/* touchpad */
QAction *touchpad= new QAction(this);
touchpad->setObjectName(QStringLiteral("Toggle touchpad"));
@ -716,14 +718,16 @@ void MediaKeysManager::initShortcuts()
QAction *logout= new QAction(this);
logout->setObjectName(QStringLiteral("Open shutdown interface"));
logout->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(logout, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::Key_Delete});
KGlobalAccel::self()->setShortcut(logout, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::Key_Delete });
KGlobalAccel::self()->setDefaultShortcut(logout, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::Key_Delete });
KGlobalAccel::self()->setShortcut(logout, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::Key_Delete });
connect(logout, &QAction::triggered, this, [this]() {
doAction(LOGOUT_KEY);
});
QAction *logout1= new QAction(this);
logout1->setObjectName(QStringLiteral("Open shutdown Interface "));
logout1->setObjectName(QStringLiteral("Open shutdown Interface1"));
logout1->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(logout1, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::Key_Period});
KGlobalAccel::self()->setShortcut(logout1, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::Key_Period });
@ -731,6 +735,16 @@ void MediaKeysManager::initShortcuts()
doAction(LOGOUT_KEY);
});
/*logout2*/
QAction *logout2= new QAction(this);
logout2->setObjectName(QStringLiteral("Open shutdown interface2"));
logout2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(logout2, QList<QKeySequence>{Qt::CTRL + + Qt::KeypadModifier + Qt::Key_Delete });
KGlobalAccel::self()->setShortcut(logout2, QList<QKeySequence>{Qt::CTRL + Qt::ALT + Qt::KeypadModifier + Qt::Key_Delete });
connect(logout2, &QAction::triggered, this, [this]() {
doAction(LOGOUT_KEY);
});
//sideBar
QAction *sideBar= new QAction(this);
sideBar->setObjectName(QStringLiteral("Open sideBar "));
@ -817,7 +831,7 @@ void MediaKeysManager::initShortcuts()
elapsed = startTime.msecsTo(QTime::currentTime());
if (elapsed>0 && elapsed<1200){//避免过快刷屏,必须大于1200ms执行一次,
if (false == CheckProcessAlive("kydisplayswitch")){
if (false == CheckProcessAlive("ukydisplayswitch")){
return;
}
}

View File

@ -0,0 +1,62 @@
#ifndef MOUSECOMMON_H
#define MOUSECOMMON_H
#include <QApplication>
#include <QDebug>
#include <QObject>
#include <QTimer>
#include <QDir>
#include <QProcess>
#include <QtX11Extras/QX11Info>
#include <QGSettings/qgsettings.h>
#include <glib.h>
#include <errno.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XIproto.h>
#include <QDBusInterface>
#include <QDBusReply>
#include "manager.h"
/* Keys with same names for both touchpad and mouse */
#define KEY_LEFT_HANDED "left-handed" /* a boolean for mouse, an enum for touchpad */
#define KEY_MOTION_ACCELERATION "motion-acceleration"
#define KEY_MOTION_THRESHOLD "motion-threshold"
/* Mouse settings */
#define UKUI_MOUSE_SCHEMA "org.ukui.peripherals-mouse"
#define KEY_MOUSE_LOCATE_POINTER "locate-pointer"
#define KEY_MIDDLE_BUTTON_EMULATION "middle-button-enabled"
#define KEY_MOUSE_WHEEL_SPEED "wheel-speed"
#define KEY_MOUSE_ACCEL "mouse-accel"
#define KEY_MOUSE_NATRUAL_SCROLLING "natural-scroll"
/* Touchpad settings */
#define UKUI_TOUCHPAD_SCHEMA "org.ukui.peripherals-touchpad"
#define KEY_TOUCHPAD_DISABLE_W_TYPING "disable-while-typing"
#define KEY_TOUCHPAD_TWO_FINGER_CLICK "two-finger-click"
#define KEY_TOUCHPAD_THREE_FINGER_CLICK "three-finger-click"
#define KEY_TOUCHPAD_NATURAL_SCROLL "natural-scroll"
#define KEY_TOUCHPAD_TAP_TO_CLICK "tap-to-click"
#define KEY_TOUCHPAD_ONE_FINGER_TAP "tap-button-one-finger"
#define KEY_TOUCHPAD_TWO_FINGER_TAP "tap-button-two-finger"
#define KEY_TOUCHPAD_THREE_FINGER_TAP "tap-button-three-finger"
#define KEY_VERT_EDGE_SCROLL "vertical-edge-scrolling"
#define KEY_HORIZ_EDGE_SCROLL "horizontal-edge-scrolling"
#define KEY_VERT_TWO_FINGER_SCROLL "vertical-two-finger-scrolling"
#define KEY_HORIZ_TWO_FINGER_SCROLL "horizontal-two-finger-scrolling"
#define KEY_TOUCHPAD_ENABLED "touchpad-enabled"
#define KEY_TOUCHPAD_DISBLE_O_E_MOUSE "disable-on-external-mouse" //插入鼠标,禁用触摸板 true/false
#define KEY_TOUCHPAD_DOUBLE_CLICK_DRAG "double-click-drag" //点击两次拖动 true/false
#define KEY_TOUCHPAD_BOTTOM_R_C_CLICK_M "bottom-right-corner-click-menu" //右下角点击菜单 true/false
#define KEY_TOUCHPAD_MOUSE_SENSITVITY "mouse-sensitivity" //鼠标敏感度 1-4 四个档位 低中高最高
#endif // MOUSECOMMON_H

View File

@ -20,41 +20,6 @@
#include "clib-syslog.h"
#include "usd_base_class.h"
/* Keys with same names for both touchpad and mouse */
#define KEY_LEFT_HANDED "left-handed" /* a boolean for mouse, an enum for touchpad */
#define KEY_MOTION_ACCELERATION "motion-acceleration"
#define KEY_MOTION_THRESHOLD "motion-threshold"
/* Mouse settings */
#define UKUI_MOUSE_SCHEMA "org.ukui.peripherals-mouse"
#define KEY_MOUSE_LOCATE_POINTER "locate-pointer"
#define KEY_MIDDLE_BUTTON_EMULATION "middle-button-enabled"
#define KEY_MOUSE_WHEEL_SPEED "wheel-speed"
#define KEY_MOUSE_ACCEL "mouse-accel"
#define KEY_MOUSE_NATRUAL_SCROLLING "natural-scroll"
/* Touchpad settings */
#define UKUI_TOUCHPAD_SCHEMA "org.ukui.peripherals-touchpad"
#define KEY_TOUCHPAD_DISABLE_W_TYPING "disable-while-typing"
#define KEY_TOUCHPAD_TWO_FINGER_CLICK "two-finger-click"
#define KEY_TOUCHPAD_THREE_FINGER_CLICK "three-finger-click"
#define KEY_TOUCHPAD_NATURAL_SCROLL "natural-scroll"
#define KEY_TOUCHPAD_TAP_TO_CLICK "tap-to-click"
#define KEY_TOUCHPAD_ONE_FINGER_TAP "tap-button-one-finger"
#define KEY_TOUCHPAD_TWO_FINGER_TAP "tap-button-two-finger"
#define KEY_TOUCHPAD_THREE_FINGER_TAP "tap-button-three-finger"
#define KEY_VERT_EDGE_SCROLL "vertical-edge-scrolling"
#define KEY_HORIZ_EDGE_SCROLL "horizontal-edge-scrolling"
#define KEY_VERT_TWO_FINGER_SCROLL "vertical-two-finger-scrolling"
#define KEY_HORIZ_TWO_FINGER_SCROLL "horizontal-two-finger-scrolling"
#define KEY_TOUCHPAD_ENABLED "touchpad-enabled"
#define KEY_TOUCHPAD_DISBLE_O_E_MOUSE "disable-on-external-mouse" //插入鼠标,禁用触摸板 true/false
#define KEY_TOUCHPAD_DOUBLE_CLICK_DRAG "double-click-drag" //点击两次拖动 true/false
#define KEY_TOUCHPAD_BOTTOM_R_C_CLICK_M "bottom-right-corner-click-menu" //右下角点击菜单 true/false
#define KEY_TOUCHPAD_MOUSE_SENSITVITY "mouse-sensitivity" //鼠标敏感度 1-4 四个档位 低中高最高
extern "C"{
#include <X11/extensions/XInput2.h>
}
@ -75,9 +40,10 @@ bool touchpad_is_present (void);
MouseManager * MouseManager::mMouseManager =nullptr;
MouseManager::MouseManager(QObject *parent) : QObject (parent)
MouseManager::MouseManager(QObject *parent) : Manager (parent)
{
gdk_init(NULL,NULL);
m_imwheelTimer = new QTimer(this);
syndaemon_spawned = false;
syndaemon_pid = 0;
locate_pointer_spawned = false;
@ -85,6 +51,40 @@ MouseManager::MouseManager(QObject *parent) : QObject (parent)
imwheelSpawned = false;
settings_mouse = new QGSettings(UKUI_MOUSE_SCHEMA);
settings_touchpad = new QGSettings(UKUI_TOUCHPAD_SCHEMA);
m_imwheelTimer->setSingleShot(false);
m_imwheelTimer->start(12*1000);
m_isRmeetingRun = false;
connect(m_imwheelTimer, &QTimer::timeout, this, [=](){
bool ret = CheckProcessAlive("Rmeet");
if (m_isRmeetingRun != ret) {
GPid pid;
GError *error = NULL;
char **args;
int argc;
m_isRmeetingRun = ret;
QString str="";
if (m_isRmeetingRun) {
str = "killall imwheel";
USD_LOG(LOG_DEBUG,"stop imwheel");
} else {
str = "/usr/bin/imwheel -k";
USD_LOG(LOG_DEBUG,"start imwheel");
}
if( g_shell_parse_argv (str.toLatin1().data(), &argc, &args, NULL)){
g_spawn_async (g_get_home_dir (),
args,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
&pid,
&error);
}
}
});
}
MouseManager::~MouseManager()
{
@ -102,12 +102,12 @@ MouseManager * MouseManager::MouseManagerNew()
return mMouseManager;
}
bool MouseManager::MouseManagerStart()
bool MouseManager::start()
{
USD_LOG(LOG_DEBUG,"-- Mouse Start Manager --");
if (!supports_xinput_devices()){
qWarning("XInput is not supported, not applying any settings");
USD_LOG(LOG_DEBUG,"XInput is not supported, not applying any settings");
return TRUE;
}
time = new QTimer(this);
@ -116,7 +116,7 @@ bool MouseManager::MouseManagerStart()
return true;
}
void MouseManager::MouseManagerStop()
void MouseManager::stop()
{
USD_LOG(LOG_DEBUG,"-- Stopping Mouse Manager --");
@ -134,12 +134,13 @@ bool
supports_xinput_devices (void)
{
int op_code, event, error;
USD_LOG(LOG_DEBUG,".");
return XQueryExtension (QX11Info::display(),
"XInputExtension",
&op_code,
&event,
&error);
USD_LOG(LOG_DEBUG,".");
}
static bool
@ -254,9 +255,10 @@ bool query_device_had_property(XDeviceInfo *device_info,const char *property_nam
unsigned char *data;
Atom Xdata;
bool ret = false;
Display * display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
Display * display = QX11Info::display();
USD_LOG(LOG_DEBUG,"device name%s",device_info->name);
device = XOpenDevice (display, device_info->id);
// USD_LOG(LOG_DEBUG,"device name%s",device_info->name);
if (device == NULL) {
USD_LOG(LOG_DEBUG, "%s find %s had a error:can't open id(%d) device in XOpenDevice,type%d",device_info->name, property_name,device_info->id,device_info->type);
@ -748,7 +750,7 @@ void MouseManager::SetMotionLegacyDriver (XDeviceInfo *device_info)
int motion_threshold;
int numerator, denominator;
Display * dpy = gdk_x11_get_default_xdisplay ();//QX11Info::display();
Display * dpy = QX11Info::display();
device = device_is_touchpad (device_info);
if (device != NULL) {
@ -1133,6 +1135,10 @@ void MouseManager::SetMouseWheelSpeed (int speed)
char **args;
int argc;
if (m_isRmeetingRun == true) {
USD_LOG(LOG_DEBUG,"break....");
return;
}
// if (imwheelSpawned){
// QProcess::execute("killall imwheel");
// imwheelSpawned = false;
@ -1579,28 +1585,6 @@ void SetTouchpadEnabledAll (bool state)
XFreeDeviceList (devicelist);
}
bool SetDisbleTouchpad(XDeviceInfo *device_info,
QGSettings *settings)
{
QString name;
bool state;
name = device_info->name;
bool PReceiver = name.contains("Receiver", Qt::CaseInsensitive);
bool PWireless = name.contains("Wireless", Qt::CaseInsensitive);
bool Pmouse = name.contains("Mouse", Qt::CaseInsensitive);
bool Pusb = name.contains("USB", Qt::CaseInsensitive);
if(Pmouse && ( PWireless || PReceiver || Pusb )) {
state = settings->get(KEY_TOUCHPAD_DISBLE_O_E_MOUSE).toBool();
if(state){//如果开启插入鼠标禁用触摸板,则直接修改触摸板状态
SetTouchpadEnabledAll(!state);
return true;
} else {//如果没有开启插入鼠标禁用触摸板则根据触摸板总开关的状态设置触摸板的enable状态
SetTouchpadEnabledAll(settings->get(KEY_TOUCHPAD_ENABLED).toBool());
}
}
return false;
}
bool checkMouseExists()
{
int numdevices, i;
@ -1609,13 +1593,9 @@ bool checkMouseExists()
return false;
}
for (i = 0; i < numdevices; i++) {
QString name;
name = devicelist[i].name;
bool PReceiver = name.contains("Receiver", Qt::CaseInsensitive);
bool PWireless = name.contains("Wireless", Qt::CaseInsensitive);
bool Pmouse = name.contains("Mouse", Qt::CaseInsensitive);
bool Pusb = name.contains("USB", Qt::CaseInsensitive);
if(Pmouse && ( PWireless || PReceiver || Pusb )) {
if (devicelist[i].type == XInternAtom (QX11Info::display(), XI_MOUSE, True)) {
USD_LOG(LOG_DEBUG,"device name is--->%s",devicelist[i].name);
XFreeDeviceList (devicelist);
return true;
}
}
@ -1639,17 +1619,14 @@ void SetPlugRemoveMouseEnableTouchpad(QGSettings *settings)
void SetPlugMouseDisbleTouchpad(QGSettings *settings)
{
int numdevices, i;
XDeviceInfo *devicelist = XListInputDevices (QX11Info::display(), &numdevices);
if (devicelist == NULL) {
return;
}
for (i = 0; i < numdevices; i++) {
if(SetDisbleTouchpad (&devicelist[i], settings)) {
break;
if(checkMouseExists()) {
bool state = settings->get(KEY_TOUCHPAD_DISBLE_O_E_MOUSE).toBool();
if(state){//如果开启插入鼠标禁用触摸板,则直接修改触摸板状态
SetTouchpadEnabledAll(!state);
} else {//如果没有开启插入鼠标禁用触摸板则根据触摸板总开关的状态设置触摸板的enable状态
SetTouchpadEnabledAll(settings->get(KEY_TOUCHPAD_ENABLED).toBool());
}
}
XFreeDeviceList (devicelist);
}
void SetTouchpadDoubleClick(XDeviceInfo *device_info, bool state)
@ -1886,7 +1863,7 @@ void MouseManager::MouseManagerIdleCb()
{
time->stop();
USD_LOG(LOG_DEBUG,".");
// connect(settings_mouse, &QGSettings::changed, this, &MouseManager::MouseCallback);
// connect(settings_touchpad, &QGSettings::changed, this, &MouseManager::TouchpadCallback);
@ -1905,4 +1882,5 @@ void MouseManager::MouseManagerIdleCb()
} else {
SetPlugRemoveMouseEnableTouchpad(settings_touchpad);
}
USD_LOG(LOG_DEBUG,".");
}

View File

@ -18,27 +18,9 @@
*/
#ifndef MOUSEMANAGER_H
#define MOUSEMANAGER_H
#include <QApplication>
#include <QDebug>
#include <QObject>
#include <QTimer>
#include <QDir>
#include <QProcess>
#include <QtX11Extras/QX11Info>
#include <QGSettings/qgsettings.h>
#include "mouse-common.h"
#include <glib.h>
#include <errno.h>
#include <math.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XIproto.h>
class MouseManager : public QObject
class MouseManager : public Manager
{
Q_OBJECT
@ -50,8 +32,8 @@ private:
public:
~MouseManager();
static MouseManager * MouseManagerNew();
bool MouseManagerStart();
void MouseManagerStop();
bool start();
void stop();
public Q_SLOTS:
void MouseManagerIdleCb();
@ -117,7 +99,8 @@ private:
gboolean locate_pointer_spawned;
GPid locate_pointer_pid;
bool imwheelSpawned;
QTimer *m_imwheelTimer;
bool m_isRmeetingRun;
static MouseManager *mMouseManager;
};

View File

@ -18,16 +18,24 @@
*/
#include "mouse-plugin.h"
#include "clib-syslog.h"
#include "usd_base_class.h"
PluginInterface * MousePlugin::mInstance = nullptr;
MouseManager * MousePlugin::UsdMouseManager = nullptr;
Manager * MousePlugin::UsdMouseManager = nullptr;
MousePlugin::MousePlugin()
{
USD_LOG(LOG_DEBUG,"MousePlugin initializing!");
if (nullptr == UsdMouseManager)
UsdMouseManager = MouseManager::MouseManagerNew();
if (nullptr == UsdMouseManager) {
if(UsdBaseClass::isWayland()) {
//wayland
UsdMouseManager = MouseWaylandManager::MouseWaylandManagerNew();
} else {
USD_LOG(LOG_DEBUG,".");
UsdMouseManager = MouseManager::MouseManagerNew();
USD_LOG(LOG_DEBUG,".");
}
}
}
MousePlugin::~MousePlugin()
@ -42,8 +50,12 @@ void MousePlugin::activate()
{
bool res;
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
res = UsdMouseManager->MouseManagerStart();
if(!UsdMouseManager) {
USD_LOG(LOG_DEBUG,".");
return ;
}
USD_LOG(LOG_DEBUG,".");
res = UsdMouseManager->start();
if(!res){
USD_LOG(LOG_ERR,"Unable to start Mouse manager!");
}
@ -61,7 +73,7 @@ PluginInterface * MousePlugin::getInstance()
void MousePlugin::deactivate()
{
USD_LOG(LOG_DEBUG,"Deactivating Mouse Plugin");
UsdMouseManager->MouseManagerStop();
UsdMouseManager->stop();
}
PluginInterface *createSettingsPlugin()

View File

@ -20,6 +20,7 @@
#define MOUSEPLUGIN_H
#include "mouse-manager.h"
#include "mouse-wayland-manager.h"
#include "plugin-interface.h"
#include <QtCore/QtGlobal>
@ -35,7 +36,7 @@ private:
MousePlugin();
MousePlugin(MousePlugin&)=delete;
static MouseManager * UsdMouseManager;
static Manager * UsdMouseManager;
static PluginInterface * mInstance;
};

View File

@ -0,0 +1,440 @@
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* 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
* 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 "mouse-wayland-manager.h"
#include "clib-syslog.h"
#include "usd_base_class.h"
typedef enum {
TOUCHPAD_HANDEDNESS_RIGHT,
TOUCHPAD_HANDEDNESS_LEFT,
TOUCHPAD_HANDEDNESS_MOUSE
} TouchpadHandedness;
MouseWaylandManager * MouseWaylandManager::mMouseWaylandManager =nullptr;
MouseWaylandManager::MouseWaylandManager(QObject *parent) : Manager (parent)
{
locate_pointer_spawned = false;
locate_pointer_pid = 0;
settings_mouse = new QGSettings(UKUI_MOUSE_SCHEMA);
settings_touchpad = new QGSettings(UKUI_TOUCHPAD_SCHEMA);
mMouseDeviceIface = new QList<QDBusInterface*>();
}
MouseWaylandManager::~MouseWaylandManager()
{
delete settings_mouse;
delete settings_touchpad;
if(time)
delete time;
mMouseDeviceIface->clear();
delete mMouseDeviceIface;
}
MouseWaylandManager * MouseWaylandManager::MouseWaylandManagerNew()
{
if(nullptr == mMouseWaylandManager) {
mMouseWaylandManager = new MouseWaylandManager(nullptr);
}
return mMouseWaylandManager;
}
bool MouseWaylandManager::start()
{
USD_LOG(LOG_DEBUG,"-- wayland Mouse Start Manager --");
time = new QTimer(this);
connect(time, &QTimer::timeout, this, &MouseWaylandManager::MouseWaylandManagerIdleCb);
time->start();
return true;
}
void MouseWaylandManager::stop()
{
USD_LOG(LOG_DEBUG,"-- Stopping Mouse Manager --");
SetLocatePointer(FALSE);
disconnect(mWaylandIface, SIGNAL(deviceAdded(QString)),
this, SLOT(deviceChange(QString)));
disconnect(mWaylandIface, SIGNAL(deviceRemoved(QString)),
this, SLOT(deviceChange(QString)));
QObject::disconnect(settings_mouse,SIGNAL(changed(QString)),
this,SLOT(MouseCallback(QString)));
QObject::disconnect(settings_touchpad,SIGNAL(changed(QString)),
this,SLOT(TouchpadCallback(QString)));
}
bool MouseWaylandManager::GetTouchpadHandedness (bool mouse_left_handed)
{
int a = settings_touchpad->getEnum(KEY_LEFT_HANDED);
switch (a) {
case TOUCHPAD_HANDEDNESS_RIGHT:
return false;
case TOUCHPAD_HANDEDNESS_LEFT:
return true;
case TOUCHPAD_HANDEDNESS_MOUSE:
return mouse_left_handed;
default:
g_assert_not_reached ();
}
}
void MouseWaylandManager::SetLeftHandedAll (bool mouse_left_handed,
bool touchpad_left_handed)
{
if(mMouseDeviceFlag && !mMouseDeviceIface->isEmpty()){
for(int i = 0; i < mMouseDeviceIface->size(); i++){
mMouseDeviceIface->at(i)->setProperty("leftHanded", mouse_left_handed);
}
}
if(mTouchDeviceFlag && mTouchDeviceIface->isValid()){
mTouchDeviceIface->setProperty("leftHanded", touchpad_left_handed);
}
}
void MouseWaylandManager::SetMotionAll()
{
if (mMouseDeviceFlag && !mMouseDeviceIface->isEmpty()) {
double mAccel;
double motion_acceleration = settings_mouse->get(KEY_MOTION_ACCELERATION).toDouble();
//printf("motion_acceleration = %f\n", motion_acceleration);
bool accel = settings_mouse->get(KEY_MOUSE_ACCEL).toBool();
if (motion_acceleration >= 0.0 && motion_acceleration <= 10.0)
{
mAccel = motion_acceleration * 0.2 - 1;
//printf("mAccel = %f\n", mAccel);
}
else
mAccel = 0;
for(int i = 0; i < mMouseDeviceIface->size(); i++){
mMouseDeviceIface->at(i)->setProperty("pointerAcceleration", mAccel);
mMouseDeviceIface->at(i)->setProperty("pointerAccelerationProfileAdaptive", accel);
//printf("pointerAccelerationProfileAdaptive mouse jia su: %d\n", accel);
}
}
if (mTouchDeviceFlag && mTouchDeviceIface->isValid()) {
double mAccel;
double motion_acceleration = settings_touchpad->get(KEY_MOTION_ACCELERATION).toDouble();
if (motion_acceleration >= 0.0 && motion_acceleration <= 10.0)
mAccel = motion_acceleration * 0.2 - 1;
else
mAccel = 0;
mTouchDeviceIface->setProperty("pointerAcceleration", mAccel);
mTouchDeviceIface->setProperty("pointerAccelerationProfileAdaptive", true);
}
}
void MouseWaylandManager::SetMiddleButtonAll (bool middle_button)
{
if (mMouseDeviceFlag && !mMouseDeviceIface->isEmpty()) {
for (int i = 0; i < mMouseDeviceIface->size(); i++) {
mMouseDeviceIface->at(i)->setProperty("MiddleButtonEmulation", middle_button);
}
}
}
void MouseWaylandManager::SetLocatePointer (bool state)
{
if (state) {
GError *error = NULL;
char **args;
int argc;
if (locate_pointer_spawned)
return;
QString str = "/usr/bin/usd-locate-pointer";
if( g_shell_parse_argv (str.toLatin1().data(), &argc, &args, NULL)){
g_spawn_async (g_get_home_dir (),
args,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
&locate_pointer_pid,
&error);
locate_pointer_spawned = (error == NULL);
}
if (error) {
settings_mouse->set(KEY_MOUSE_LOCATE_POINTER,false);
g_error_free (error);
}
g_strfreev (args);
} else if (locate_pointer_spawned) {
kill (locate_pointer_pid, SIGHUP);
g_spawn_close_pid (locate_pointer_pid);
locate_pointer_spawned = FALSE;
}
}
void MouseWaylandManager::SetMouseWheelSpeed (int speed)
{
if(speed <= 0 )
return;
double mouseSpeed = 1.0;
if(mMouseDeviceFlag && !mMouseDeviceIface->isEmpty()){
if (speed < 5)
mouseSpeed = (double)speed / 5.0 - 0.1;
else
mouseSpeed = speed - 4;
for(int i = 0; i < mMouseDeviceIface->size(); i++){
mMouseDeviceIface->at(i)->setProperty("scrollFactor", mouseSpeed);
}
}
}
void MouseWaylandManager::MouseCallback (QString keys)
{
if (keys.compare(QString::fromLocal8Bit(KEY_LEFT_HANDED))==0){
bool mouse_left_handed = settings_mouse->get(keys).toBool();
bool touchpad_left_handed = GetTouchpadHandedness (mouse_left_handed);
SetLeftHandedAll (mouse_left_handed, touchpad_left_handed);
} else if ((keys.compare(QString::fromLocal8Bit(KEY_MOTION_ACCELERATION))==0) ||
(keys.compare(QString::fromLocal8Bit(KEY_MOTION_THRESHOLD))==0) ||
(keys.compare(QString::fromLocal8Bit(KEY_MOUSE_ACCEL)) == 0)){
SetMotionAll ();
} else if (keys.compare(QString::fromLocal8Bit(KEY_MIDDLE_BUTTON_EMULATION))==0){
SetMiddleButtonAll (settings_mouse->get(keys).toBool());
} else if (keys.compare(QString::fromLocal8Bit(KEY_MOUSE_LOCATE_POINTER))==0){
SetLocatePointer (settings_mouse->get(keys).toBool());
} else if(keys.compare(QString::fromLocal8Bit(KEY_MOUSE_WHEEL_SPEED)) == 0 ) {
SetMouseWheelSpeed (settings_mouse->get(keys).toInt());
}else{
USD_LOG(LOG_DEBUG,"keys:is skip..k%s", keys.toLatin1().data());
}
}
void MouseWaylandManager::SetDisableWTyping (bool state)
{
//wayland
if(mTouchDeviceFlag && mTouchDeviceIface->isValid()){
bool whileTyping = settings_touchpad->get(KEY_TOUCHPAD_DISABLE_W_TYPING).toBool();
mTouchDeviceIface->setProperty("disableWhileTyping", whileTyping);
}
}
void MouseWaylandManager::SetTapToClickAll ()
{
if(mTouchDeviceFlag && mTouchDeviceIface->isValid()){
bool tapClick = settings_touchpad->get(KEY_TOUCHPAD_TAP_TO_CLICK).toBool();
mTouchDeviceIface->setProperty("tapToClick", tapClick);
}
}
void MouseWaylandManager::SetScrollingAll (QString keys)
{
// wayland
if(mTouchDeviceFlag && mTouchDeviceIface->isValid()){
bool edge, twoFinger;
if (keys.compare(QString::fromLocal8Bit(KEY_VERT_EDGE_SCROLL)) == 0){
edge = settings_touchpad->get(keys).toBool();
mTouchDeviceIface->setProperty("scrollEdge", edge);
} else if (keys.compare(QString::fromLocal8Bit(KEY_VERT_TWO_FINGER_SCROLL)) == 0){
twoFinger = settings_touchpad->get(keys).toBool();
mTouchDeviceIface->setProperty("scrollTwoFinger", twoFinger);
}
}
}
void MouseWaylandManager::SetNaturalScrollAll ()
{
//wayland
bool naturalScroll = settings_touchpad->get(KEY_TOUCHPAD_NATURAL_SCROLL).toBool();
if (mTouchDeviceFlag && mTouchDeviceIface->isValid()) {
mTouchDeviceIface->setProperty("naturalScroll", naturalScroll);
}
}
void MouseWaylandManager::SetTouchpadEnabledAll (bool state)
{
//wayland
if (mTouchDeviceFlag && mTouchDeviceIface->isValid()) {
mTouchDeviceIface->setProperty("enabled", state);
}
}
void MouseWaylandManager::SetTouchpadDoubleClickAll(bool state)
{
//wayland
if(mTouchDeviceFlag && mTouchDeviceIface->isValid()){
return;
//mTouchDeviceIface->setProperty("tapDragLock", state);
}
}
void MouseWaylandManager::TouchpadCallback (QString keys)
{
if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_DISABLE_W_TYPING))==0) {
SetDisableWTyping (settings_touchpad->get(keys).toBool()); //设置打字时禁用触摸板
} else if (keys.compare(QString::fromLocal8Bit(KEY_LEFT_HANDED))== 0) {
bool mouse_left_handed = settings_mouse->get(keys).toBool();
bool touchpad_left_handed = GetTouchpadHandedness (mouse_left_handed);
SetLeftHandedAll (mouse_left_handed, touchpad_left_handed); //设置左右手
} else if ((keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_TAP_TO_CLICK)) == 0)
|| (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_ONE_FINGER_TAP)) == 0)
|| (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_TWO_FINGER_TAP)) == 0)
|| (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_THREE_FINGER_TAP))== 0)) {
SetTapToClickAll (); //设置多指手势
} else if ((keys.compare(QString::fromLocal8Bit(KEY_VERT_EDGE_SCROLL)) == 0)
|| (keys.compare(QString::fromLocal8Bit(KEY_HORIZ_EDGE_SCROLL)) == 0)
|| (keys.compare(QString::fromLocal8Bit(KEY_VERT_TWO_FINGER_SCROLL)) == 0)
|| (keys.compare(QString::fromLocal8Bit(KEY_HORIZ_TWO_FINGER_SCROLL)) == 0)) {
//SetScrollingAll (settings_touchpad); //设置滚动
SetScrollingAll (keys); //设置滚动
} else if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_NATURAL_SCROLL)) == 0) {
SetNaturalScrollAll (); //设置上移下滚或上移上滚
USD_LOG(LOG_DEBUG,"set %s",KEY_TOUCHPAD_NATURAL_SCROLL);
} else if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_ENABLED)) == 0) {
SetTouchpadEnabledAll (settings_touchpad->get(keys).toBool());//设置触摸板开关
SetDisableWTyping (true);
} else if ((keys.compare((KEY_MOTION_ACCELERATION)) == 0)
|| (keys.compare((KEY_MOTION_THRESHOLD)) == 0)) {
SetMotionAll (); //设置鼠标速度
}else if (0 == QString::compare(keys, QString(KEY_MOTION_ACCELERATION), Qt::CaseInsensitive)||
0 == QString::compare(keys, QString(KEY_MOTION_THRESHOLD), Qt::CaseInsensitive)){
SetMotionAll (); //设置鼠标速度
}else if (keys == "motion-acceleration" || keys==KEY_MOTION_THRESHOLD){
}else if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_DISBLE_O_E_MOUSE)) == 0) {
// SetPlugMouseDisbleTouchpad(settings_touchpad); //设置插入鼠标时禁用触摸板
} else if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_DOUBLE_CLICK_DRAG)) == 0){
SetTouchpadDoubleClickAll(settings_touchpad->get(KEY_TOUCHPAD_DOUBLE_CLICK_DRAG).toBool());//设置轻点击两次拖动打开关闭
} else if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_BOTTOM_R_C_CLICK_M)) == 0){
// SetBottomRightConrnerClickMenu(settings_touchpad->get(KEY_TOUCHPAD_BOTTOM_R_C_CLICK_M).toBool());//打开关闭右下角点击弹出菜单
} else if (keys.compare(QString::fromLocal8Bit(KEY_TOUCHPAD_MOUSE_SENSITVITY)) == 0){
} else {
USD_LOG(LOG_DEBUG,"keys:is skip..k%s", keys.toLatin1().data(),keys.toLatin1().data());
}
}
void MouseWaylandManager::SetMouseSettings ()
{
bool mouse_left_handed = settings_mouse->get(KEY_LEFT_HANDED).toBool();
bool touchpad_left_handed = GetTouchpadHandedness (mouse_left_handed);
SetLeftHandedAll (mouse_left_handed, touchpad_left_handed);
SetMotionAll ();
SetMiddleButtonAll (settings_mouse->get(KEY_MIDDLE_BUTTON_EMULATION).toBool());
SetMouseWheelSpeed (settings_mouse->get(KEY_MOUSE_WHEEL_SPEED).toInt());
}
void MouseWaylandManager::SetTouchSettings ()
{
SetTapToClickAll ();
//SetScrollingAll (settings_touchpad);
SetScrollingAll (KEY_VERT_EDGE_SCROLL);
SetScrollingAll (KEY_VERT_TWO_FINGER_SCROLL);
SetNaturalScrollAll ();
SetTouchpadEnabledAll (settings_touchpad->get(KEY_TOUCHPAD_ENABLED).toBool());
// SetPlugMouseDisbleTouchpad(settings_touchpad);
SetTouchpadDoubleClickAll(settings_touchpad->get(KEY_TOUCHPAD_DOUBLE_CLICK_DRAG).toBool());
// SetBottomRightConrnerClickMenu(settings_touchpad->get(KEY_TOUCHPAD_BOTTOM_R_C_CLICK_M).toBool());
}
void MouseWaylandManager::initWaylandMouseStatus()
{
QVariant deviceReply = mWaylandIface->property("devicesSysNames");
if (deviceReply.isValid()) {
QStringList deviceList = deviceReply.toStringList();
if(!mMouseDeviceIface->isEmpty()){
mMouseDeviceIface->clear();
}
int i = 0;
for (QString device : deviceList) {
QDBusInterface *deviceIface = new QDBusInterface("org.ukui.KWin",
"/org/ukui/KWin/InputDevice/"+ device,
"org.ukui.KWin.InputDevice",
QDBusConnection::sessionBus(),
this);
if (deviceIface->isValid() &&
deviceIface->property("pointer").toBool() &&
!deviceIface->property("keyboard").toBool() &&
!deviceIface->property("touchpad").toBool()) {
mMouseDeviceIface->insert(i++, deviceIface);
mMouseDeviceFlag = true;
}
if (deviceIface->isValid() &&
deviceIface->property("pointer").toBool() &&
deviceIface->property("touchpad").toBool()){
mTouchDeviceIface = deviceIface;
mTouchDeviceFlag = true;
}
}
}
}
void MouseWaylandManager::deviceChange(QString dev)
{
initWaylandMouseStatus();
SetMouseSettings ();
}
void MouseWaylandManager::initWaylandDbus()
{
mWaylandIface = new QDBusInterface("org.ukui.KWin",
"/org/ukui/KWin/InputDevice",
"org.ukui.KWin.InputDeviceManager",
QDBusConnection::sessionBus(),
this);
if (mWaylandIface->isValid()) {
connect(mWaylandIface, SIGNAL(deviceAdded(QString)),
this, SLOT(deviceChange(QString)));
connect(mWaylandIface, SIGNAL(deviceRemoved(QString)),
this, SLOT(deviceChange(QString)));
initWaylandMouseStatus();
}
}
void MouseWaylandManager::MouseWaylandManagerIdleCb()
{
initWaylandDbus();
time->stop();
QObject::connect(settings_mouse,SIGNAL(changed(QString)), this,SLOT(MouseCallback(QString)));
QObject::connect(settings_touchpad,SIGNAL(changed(QString)),this,SLOT(TouchpadCallback(QString)));
//wayland
SetMouseSettings ();
SetLocatePointer (settings_mouse->get(KEY_MOUSE_LOCATE_POINTER).toBool());
}

View File

@ -0,0 +1,94 @@
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* 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
* 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 MouseWaylandManager_H
#define MouseWaylandManager_H
#include "mouse-common.h"
class MouseWaylandManager : public Manager
{
Q_OBJECT
private:
MouseWaylandManager()=delete;
MouseWaylandManager(MouseWaylandManager&)=delete;
MouseWaylandManager&operator=(const MouseWaylandManager&)=delete;
MouseWaylandManager(QObject *parent = nullptr);
public:
~MouseWaylandManager();
static MouseWaylandManager * MouseWaylandManagerNew();
bool start();
void stop();
public Q_SLOTS:
void MouseWaylandManagerIdleCb();
void MouseCallback(QString);
void TouchpadCallback(QString);
void initWaylandDbus();
void initWaylandMouseStatus();
void deviceChange(QString);
public:
void SetLeftHandedAll (bool mouse_left_handed,
bool touchpad_left_handed);
void SetMotionAll ();
bool GetTouchpadHandedness (bool mouse_left_handed);
void SetDisableWTyping (bool state);
void SetMiddleButtonAll (bool middle_button);
void SetLocatePointer (bool state);
void SetTapToClickAll ();
void SetNaturalScrollAll ();
void SetMouseWheelSpeed (int speed);
void SetMouseSettings();
void SetTouchSettings();
void SetTouchpadDoubleClickAll(bool state);
void SetScrollingAll (QString keys);
void SetTouchpadEnabledAll (bool state);
private:
friend GdkFilterReturn devicepresence_filter (GdkXEvent *xevent,
GdkEvent *event,
gpointer data);
private:
unsigned long mAreaLeft;
unsigned long mAreaTop;
QTimer * time;
QGSettings *settings_mouse;
QGSettings *settings_touchpad;
#if 0 /* FIXME need to fork (?) mousetweaks for this to work */
gboolean mousetweaks_daemon_running;
#endif
gboolean syndaemon_spawned;
gboolean locate_pointer_spawned;
GPid locate_pointer_pid;
bool imwheelSpawned;
bool mTouchDeviceFlag = false;
bool mMouseDeviceFlag = false;
QDBusInterface *mWaylandIface;
QList<QDBusInterface*> *mMouseDeviceIface;
QDBusInterface *mTouchDeviceIface;
static MouseWaylandManager *mMouseWaylandManager;
};
#endif // MouseWaylandManager_H

View File

@ -31,10 +31,13 @@ INCLUDEPATH += \
SOURCES += \
mouse-manager.cpp \
mouse-plugin.cpp \
mouse-wayland-manager.cpp
HEADERS += \
mouse-common.h \
mouse-manager.h \
mouse-plugin.h \
mouse-wayland-manager.h
mouse_lib.path = $${PLUGIN_INSTALL_DIRS}
mouse_lib.files = $$OUT_PWD/libmouse.so

View File

@ -67,13 +67,12 @@ void SaveScreenParam::getConfig(){
m_MonitoredConfig->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen);
if (false == m_userName.isEmpty()) {
USD_LOG(LOG_DEBUG,".");
m_MonitoredConfig->setUserName(m_userName);
}
else if (isSet()) {
SYS_LOG(LOG_DEBUG,".");
} else if (isGet()) {
SYS_LOG(LOG_DEBUG,".");
m_MonitoredConfig->writeFileForLightDM(false);
exit(0);
} else {
@ -139,8 +138,8 @@ void SaveScreenParam::setClone()
outputSize = mode->width * mode->height;
primaryMaxModeId = mode->id;
secondaryMaxModeId = nmode->id;
SYS_LOG(LOG_DEBUG,"primaryOutputInfo:%s mode %s,secondaryMaxModeId %s mode %s",
primaryOutputInfo->name, mode->name, secondaryOutputInfo->name, nmode->name);
// SYS_LOG(LOG_DEBUG,"primaryOutputInfo:%s mode %s,secondaryMaxModeId %s mode %s",
// primaryOutputInfo->name, mode->name, secondaryOutputInfo->name, nmode->name);
}
}
}
@ -154,7 +153,7 @@ void SaveScreenParam::setClone()
SYS_LOG(LOG_DEBUG,"add primaryOutputId %d %d", primaryOutputId, primaryMaxModeId);
}
cloneMode.insert(m_pScreenRes->outputs[tempInt], secondaryMaxModeId);
SYS_LOG(LOG_DEBUG,"add secondaryMaxMode %d %d", m_pScreenRes->outputs[tempInt], secondaryMaxModeId);
// SYS_LOG(LOG_DEBUG,"add secondaryMaxMode %d %d", m_pScreenRes->outputs[tempInt], secondaryMaxModeId);
}
qDebug()<<cloneMode;
//单屏
@ -171,7 +170,7 @@ void SaveScreenParam::setClone()
if (ret != RRSetConfigSuccess) {
SYS_LOG(LOG_ERR," RRSetConfigFail.%d %d .", crtcInfo->outputs[0], cloneMode[crtcInfo->outputs[0]]);
} else {
SYS_LOG(LOG_ERR," RRSetConfigSuccess.%d %d .", crtcInfo->outputs[0], cloneMode[crtcInfo->outputs[0]]);
SYS_LOG(LOG_DEBUG," RRSetConfigSuccess.%d %d .", crtcInfo->outputs[0], cloneMode[crtcInfo->outputs[0]]);
}
}
@ -192,7 +191,7 @@ void SaveScreenParam::setUserConfigParam()
void SaveScreenParam::setUserName(QString str)
{
m_userName = str;
USD_LOG_SHOW_PARAMS(m_userName.toLatin1().data());
// USD_LOG_SHOW_PARAMS(m_userName.toLatin1().data());
}
void SaveScreenParam::setScreenSize()
@ -210,8 +209,8 @@ void SaveScreenParam::setScreenSize()
XRRSetScreenSize(m_pDpy, m_rootWindow, m_kscreenConfigParam.m_screenWidth, m_kscreenConfigParam.m_screenHeight,
fb_width_mm, fb_height_mm);
SYS_LOG(LOG_DEBUG,"set screen size: %dx%d,%dx%d",m_kscreenConfigParam.m_screenWidth, m_kscreenConfigParam.m_screenHeight,
fb_width_mm, fb_height_mm);
// SYS_LOG(LOG_DEBUG,"set screen size: %dx%d,%dx%d",m_kscreenConfigParam.m_screenWidth, m_kscreenConfigParam.m_screenHeight,
// fb_width_mm, fb_height_mm);
}
}
@ -234,16 +233,16 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
if (!file.open(QIODevice::ReadOnly)) {
setClone();
SYS_LOG(LOG_DEBUG,"can't open %s's screen config>%s",m_userName.toLatin1().data(),configFullPath.toLatin1().data());
SYS_LOG(LOG_ERR,"can't open %s's screen config>%s",m_userName.toLatin1().data(),configFullPath.toLatin1().data());
return;
}
SYS_LOG(LOG_DEBUG,"open %s's screen config>%s ok...",m_userName.toLatin1().data(),configFullPath.toLatin1().data());
// SYS_LOG(LOG_DEBUG,"open %s's screen config>%s ok...",m_userName.toLatin1().data(),configFullPath.toLatin1().data());
outputsInfo = parser.fromJson(file.readAll()).toVariant().toList();
SYS_LOG(LOG_DEBUG,"%dx%d",DisplayWidth(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeight(m_pDpy, DefaultScreen (m_pDpy)));
SYS_LOG(LOG_DEBUG,"%dmmx%dmm",DisplayWidthMM(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeightMM(m_pDpy, DefaultScreen (m_pDpy)));
// SYS_LOG(LOG_DEBUG,"%dx%d",DisplayWidth(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeight(m_pDpy, DefaultScreen (m_pDpy)));
// SYS_LOG(LOG_DEBUG,"%dmmx%dmm",DisplayWidthMM(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeightMM(m_pDpy, DefaultScreen (m_pDpy)));
for (const auto &variantInfo : outputsInfo) {
UsdOuputProperty *outputProperty;
@ -263,27 +262,33 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
outputProperty->setProperty("primary", info[QStringLiteral("primary")].toString());
outputProperty->setProperty("rotation", info[QStringLiteral("rotation")].toString());
outputProperty->setProperty("rate", modeInfo[QStringLiteral("refresh")].toString());
outputProperty->setProperty("enable", info[QStringLiteral("enabled")].toString());
if (outputProperty->property("rotation").toString() == "8" ||
outputProperty->property("rotation").toString() == "2") {
if (outputProperty->property("height").toInt() + outputProperty->property("x").toInt() > m_kscreenConfigParam.m_screenWidth) {
m_kscreenConfigParam.m_screenWidth = outputProperty->property("height").toInt() + outputProperty->property("x").toInt();
}
if (info[QStringLiteral("enabled")].toString() == "true") {
if (outputProperty->property("rotation").toString() == "8" ||
outputProperty->property("rotation").toString() == "2") {
if (outputProperty->property("height").toInt() + outputProperty->property("x").toInt() > m_kscreenConfigParam.m_screenWidth) {
m_kscreenConfigParam.m_screenWidth = outputProperty->property("height").toInt() + outputProperty->property("x").toInt();
}
if (outputProperty->property("width").toInt() + outputProperty->property("y").toInt() > m_kscreenConfigParam.m_screenHeight) {
m_kscreenConfigParam.m_screenHeight = outputProperty->property("width").toInt() + outputProperty->property("y").toInt();
if (outputProperty->property("width").toInt() + outputProperty->property("y").toInt() > m_kscreenConfigParam.m_screenHeight) {
m_kscreenConfigParam.m_screenHeight = outputProperty->property("width").toInt() + outputProperty->property("y").toInt();
}
}
else{
if (outputProperty->property("width").toInt() + outputProperty->property("x").toInt() > m_kscreenConfigParam.m_screenWidth) {
m_kscreenConfigParam.m_screenWidth = outputProperty->property("width").toInt() + outputProperty->property("x").toInt();
}
if (outputProperty->property("height").toInt() + outputProperty->property("y").toInt() > m_kscreenConfigParam.m_screenHeight) {
m_kscreenConfigParam.m_screenHeight = outputProperty->property("height").toInt() + outputProperty->property("y").toInt();
}
}
m_kscreenConfigParam.m_outputList.append(outputProperty);
} else {
// USD_LOG_SHOW_PARAMS(outputProperty->property("enable").toString().toLatin1().data());
}
else{
if (outputProperty->property("width").toInt() + outputProperty->property("x").toInt() > m_kscreenConfigParam.m_screenWidth) {
m_kscreenConfigParam.m_screenWidth = outputProperty->property("width").toInt() + outputProperty->property("x").toInt();
}
if (outputProperty->property("height").toInt() + outputProperty->property("y").toInt() > m_kscreenConfigParam.m_screenHeight) {
m_kscreenConfigParam.m_screenHeight = outputProperty->property("height").toInt() + outputProperty->property("y").toInt();
}
}
m_kscreenConfigParam.m_outputList.append(outputProperty);
// USD_LOG_SHOW_PARAMS(outputProperty->property("name").toString().toLatin1().data());
// USD_LOG_SHOW_PARAMS(outputProperty->property("x").toString().toLatin1().data());
// USD_LOG_SHOW_PARAMS(outputProperty->property("y").toString().toLatin1().data());
@ -291,14 +296,17 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
// USD_LOG_SHOW_PARAMS(outputProperty->property("height").toString().toLatin1().data());
// USD_LOG_SHOW_PARAMS(outputProperty->property("primary").toString().toLatin1().data());
// USD_LOG_SHOW_PARAMS(outputProperty->property("rotation").toString().toLatin1().data());
// USD_LOG_SHOW_PARAMS(outputProperty->property("enable").toString().toLatin1().data());
// USD_LOG_SHOW_PARAMS(outputProperty->property("rate").toString().toLatin1().data());
}
SYS_LOG(LOG_DEBUG,"%dx%d",DisplayWidth(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeight(m_pDpy, DefaultScreen (m_pDpy)));
SYS_LOG(LOG_DEBUG,"%dmmx%dmm",DisplayWidthMM(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeightMM(m_pDpy, DefaultScreen (m_pDpy)));
// SYS_LOG(LOG_DEBUG,"%dx%d",DisplayWidth(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeight(m_pDpy, DefaultScreen (m_pDpy)));
// SYS_LOG(LOG_DEBUG,"%dmmx%dmm",DisplayWidthMM(m_pDpy, DefaultScreen (m_pDpy)),DisplayHeightMM(m_pDpy, DefaultScreen (m_pDpy)));
// XGrabServer(m_pDpy);
//所谓crtc ,就是一个显示规则:规定了某个显示器的显示模式,显示器名称,显示方位
//停止所有输出,避免调整分辨率,刷新率,方向时产生花屏的情况
//在这里清空则全部屏幕无法点亮
// for (tempInt = 0; tempInt < m_pScreenRes->ncrtc; tempInt++) {
// int ret = 0;
// ret = XRRSetCrtcConfig (m_pDpy, m_pScreenRes, m_pScreenRes->crtcs[tempInt], CurrentTime,
@ -310,7 +318,7 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
XRRSetOutputPrimary(m_pDpy, m_rootWindow, None);
// XRRSetOutputPrimary(m_pDpy, m_rootWindow, None);
for (tempInt = 0; tempInt < m_pScreenRes->ncrtc; tempInt++) {
RRMode monitorMode = 0;
@ -326,7 +334,7 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
UsdOuputProperty *kscreenOutputParam = nullptr;
XRROutputInfo *outputInfo = XRRGetOutputInfo (m_pDpy, m_pScreenRes, crtcInfo->outputs[circle]);
QString outputName = QString(QLatin1String(outputInfo->name));
// SYS_LOG(LOG_DEBUG,"count %d output:%s", crtcInfo->noutput, outputName.toLatin1().data());
//遍历配置文件找到与X的对应的输出名
for (int k = 0; k < m_kscreenConfigParam.m_outputList.count(); k++) {
if (outputName != m_kscreenConfigParam.m_outputList[k]->property("name").toString()) {
@ -334,13 +342,28 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
}
kscreenOutputParam = m_kscreenConfigParam.m_outputList[k];
SYS_LOG(LOG_DEBUG,"find %s..",kscreenOutputParam->property("name").toString().toLatin1().data());
break;
}
if (kscreenOutputParam == nullptr) {
ret = XRRSetCrtcConfig (m_pDpy, m_pScreenRes, m_pScreenRes->crtcs[tempInt], CurrentTime,
0, 0, None, RR_Rotate_0, NULL, 0);
if (ret != RRSetConfigSuccess) {
SYS_LOG(LOG_ERR,"%s RRSetConfigFail..",outputName.toLatin1().data());
} else {
SYS_LOG(LOG_DEBUG,"%s RRSetConfigSuccess",outputName.toLatin1().data());
}
continue;
}
monitorMode = getModeId(outputInfo, kscreenOutputParam);
if (0 == monitorMode) {
SYS_LOG(LOG_ERR,"mode id get error..");
return;
SYS_LOG(LOG_ERR,"%s mode id get error..",outputName.toLatin1().data());
continue;
} else {
SYS_LOG(LOG_DEBUG,"%s mode id get ..",outputName.toLatin1().data());
}
/*10个参数
@ -356,22 +379,35 @@ void SaveScreenParam::readKscreenConfigAndSetItWithX(QString kscreenConfigName)
*/
rotationAngle = kscreenOutputParam->property("rotation").toInt();
SYS_LOG(LOG_DEBUG,"rotation:%d",rotationAngle);
ret = XRRSetCrtcConfig (m_pDpy, m_pScreenRes, m_pScreenRes->crtcs[tempInt], CurrentTime,
kscreenOutputParam->property("x").toInt(), kscreenOutputParam->property("y").toInt(), monitorMode, rotationAngle, crtcInfo->outputs, crtcInfo->noutput);
if (kscreenOutputParam->property("primary").toString() == "true") {
XRRSetOutputPrimary(m_pDpy, m_rootWindow, crtcInfo->outputs[0]);
SYS_LOG(LOG_DEBUG,"%s is primay rt%d set%d",kscreenOutputParam->property("name").toString().toLatin1().data(), XRRGetOutputPrimary(m_pDpy, m_rootWindow),crtcInfo->outputs[circle]);
XRRSetOutputPrimary(m_pDpy, m_rootWindow, crtcInfo->outputs[circle]);
} else {
SYS_LOG(LOG_DEBUG,"%s is't primay",kscreenOutputParam->property("name").toString().toLatin1().data());
}
ret = XRRSetCrtcConfig (m_pDpy, m_pScreenRes, m_pScreenRes->crtcs[tempInt], CurrentTime,
kscreenOutputParam->property("x").toInt(), kscreenOutputParam->property("y").toInt(), monitorMode, rotationAngle, crtcInfo->outputs, crtcInfo->noutput);
if (ret != RRSetConfigSuccess) {
SYS_LOG(LOG_ERR,"%s RRSetConfigFail..",kscreenOutputParam->property("name").toString().toLatin1().data());
} else {
SYS_LOG(LOG_DEBUG,"%s RRSetConfigSuccess",kscreenOutputParam->property("name").toString().toLatin1().data());
}
setScreenSize();
if (ret != RRSetConfigSuccess) {
SYS_LOG(LOG_ERR,"%s RRSetConfigFail..",kscreenOutputParam->property("name").toString().toLatin1().data());
} else {
SYS_LOG(LOG_ERR,"%s RRSetConfigSuccess",kscreenOutputParam->property("name").toString().toLatin1().data());
SYS_LOG(LOG_DEBUG,"%s RRSetConfigSuccess",kscreenOutputParam->property("name").toString().toLatin1().data());
}
}
}
setScreenSize();
return;
#if 0
@ -652,16 +688,14 @@ RRMode SaveScreenParam::getModeId(XRROutputInfo *outputInfo,UsdOuputProperty *ks
/* the field rate is what is typically reported by monitors */
vTotal /= 2;
}
rate = mode->dotClock / ((double) mode->hTotal * (double) vTotal);
if (mode->width == kscreenOutputParam->property("width").toInt()
&& mode->height == kscreenOutputParam->property("height").toInt()) {
double kscreenRate = kscreenOutputParam->property("rate").toDouble();
if (qAbs(kscreenRate - rate) < 0.2) {
for (int k = 0; k< outputInfo->nmode; k++) {
if (outputInfo->modes[k] == mode->id) {
SYS_LOG(LOG_DEBUG,"find %s mode:%s id:%d",outputInfo->name, mode->name, mode->id);
SYS_LOG(LOG_DEBUG,"find %s mode:%s id:%d refresh:%f",outputInfo->name, mode->name, mode->id, rate);
return mode->id;
}
}

View File

@ -73,10 +73,10 @@ void MonitorInputTask::ListeningToInputEvent()
// open display
// PEEK_XOpenDisplay(display);
display = XOpenDisplay(NULL);
// display = XOpenDisplay(NULL);
// openDisplayOK = true;
//QX11Info::display();

View File

@ -57,19 +57,22 @@ void XinputManager::init()
XinputManager::~XinputManager()
{
if (m_penSettings)
if (m_penSettings) {
delete m_penSettings;
m_penSettings = nullptr;
}
}
void XinputManager::start()
{
USD_LOG(LOG_DEBUG,"info: [XinputManager][StartManager]: thread id =%d",QThread::currentThreadId());
m_runningMutex.lock();
m_pMonitorInputTask->m_running = true;
m_runningMutex.unlock();
m_pManagerThread->start();
Q_EMIT sigStartThread();
// USD_LOG(LOG_DEBUG,"info: [XinputManager][StartManager]: thread id =%d",QThread::currentThreadId());
// m_runningMutex.lock();
// m_pMonitorInputTask->m_running = true;
// m_runningMutex.unlock();
// m_pManagerThread->start();
// Q_EMIT sigStartThread();
}
void XinputManager::stop()
@ -175,6 +178,7 @@ void XinputManager::updateSettings(QString key)
void XinputManager::updateButtonMap()
{
return;
QQueue<int> deviceQue = GetPenDevice();
if (!deviceQue.size()) {
@ -187,13 +191,15 @@ void XinputManager::updateButtonMap()
//! and the modified mapping is 1334567
//! The numbers in this refer to button 2 being mapped to button 3
while (deviceQue.size()) {
if (m_penSettings->get(RIGHT_CLICK_KEY).value<bool>()) {
command = QString("xinput set-button-map %1 1 3 3").arg(deviceQue.dequeue());
if(m_penSettings && m_penSettings->keys().contains(RIGHT_CLICK_KEY)) {
if (m_penSettings->get(RIGHT_CLICK_KEY).value<bool>()) {
command = QString("xinput set-button-map %1 1 3 3").arg(deviceQue.dequeue());
}
else {
command = QString("xinput set-button-map %1 1 2 3").arg(deviceQue.dequeue());
}
QProcess::execute(command);
}
else {
command = QString("xinput set-button-map %1 1 2 3").arg(deviceQue.dequeue());
}
QProcess::execute(command);
}
}

View File

@ -21,7 +21,7 @@
#include <QMutex>
#include <syslog.h>
#include "usd_base_class.h"
XinputPlugin* XinputPlugin::_instance = nullptr;
XinputPlugin* XinputPlugin::instance()
@ -34,9 +34,15 @@ XinputPlugin* XinputPlugin::instance()
return _instance;
}
XinputPlugin::XinputPlugin():
m_pXinputManager(new XinputManager)
XinputPlugin::XinputPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
if (m_pXinputManager == nullptr) {
m_pXinputManager = new XinputManager(nullptr);
}
USD_LOG(LOG_ERR, "Loading Xinput plugins");
}
@ -47,12 +53,20 @@ XinputPlugin::~XinputPlugin()
void XinputPlugin::activate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_ERR,"activating Xinput plugins");
m_pXinputManager->start();
}
void XinputPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
m_pXinputManager->stop();
}

View File

@ -40,10 +40,16 @@ QString xrandrConfig::mConfigsDirName = QStringLiteral("" /*"configs/"*/); // TO
QString xrandrConfig::configsDirPath()
{
QString dirPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) %
QStringLiteral("/kscreen/");
QStringLiteral("/kscreen/realtime/");
return dirPath % mConfigsDirName;
}
QString xrandrConfig::configsOldDirPath()
{
QString dirPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) %
QStringLiteral("/kscreen/");
return dirPath % mConfigsDirName;
}
void xrandrConfig::setScreenMode(QString modeName)
{
mScreenMode = modeName;
@ -211,11 +217,12 @@ std::unique_ptr<xrandrConfig> xrandrConfig::readFile(const QString &fileName, bo
config->setValidityFlags(mValidityFlags);
QFile file;
if(!state){
if (QFile::exists(configsDirPath() % mFixedConfigFileName)) {
file.setFileName(configsDirPath() % mFixedConfigFileName);//先读取特定模式的配置,
} else {
if (QFile::exists(configsDirPath() % fileName)) {
file.setFileName(configsDirPath() % fileName);
} else if (QFile::exists(configsOldDirPath() % fileName)) {//兼容新旧两个配置文件。
file.setFileName(configsOldDirPath() % fileName);
}
if (!file.open(QIODevice::ReadOnly)) {
USD_LOG(LOG_ERR,"config is nullptr...");
return nullptr;
@ -231,13 +238,21 @@ std::unique_ptr<xrandrConfig> xrandrConfig::readFile(const QString &fileName, bo
return nullptr;
}
}
USD_LOG(LOG_DEBUG,"ready read:%s",file.fileName().toLatin1().data());
QJsonDocument parser;
QVariantList outputs = parser.fromJson(file.readAll()).toVariant().toList();
if(outputs.isEmpty()) {
USD_LOG(LOG_WARNING,"config is exists but is empty...");
return nullptr;
}
xrandrOutput::readInOutputs(config->data(), outputs);
QSize screenSize;
for (const auto &output : config->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
if (output->isEnabled()) {
enabledOutputsCount++;
@ -271,6 +286,7 @@ std::unique_ptr<xrandrConfig> xrandrConfig::readFile(const QString &fileName, bo
}
}
USD_LOG(LOG_DEBUG,"read %s ok",file.fileName().toLatin1().data());
return config;
}
@ -398,8 +414,12 @@ bool xrandrConfig::writeFile(const QString &filePath, bool state)
if (screenConnectedCount > 1) {
QFile backFile(fileModeConfigPath());
if (backFile.open(QIODevice::WriteOnly)) {//确保对应模式保存的参数一致
USD_LOG(LOG_DEBUG,"x= %d y = %d", point.x(), point.y());
if (point.x() == point.y() && point.x() == 0) {
if (mScreenMode == metaEnum.valueToKey(UsdBaseClass::eScreenMode::cloneScreenMode)) {
if (mScreenMode == metaEnum.valueToKey(UsdBaseClass::eScreenMode::cloneScreenMode) ||
mScreenMode == metaEnum.valueToKey(UsdBaseClass::eScreenMode::secondScreenMode)||
mScreenMode == metaEnum.valueToKey(UsdBaseClass::eScreenMode::firstScreenMode)) {
backFile.write(QJsonDocument::fromVariant(outputList).toJson());
}
} else {
@ -409,11 +429,11 @@ bool xrandrConfig::writeFile(const QString &filePath, bool state)
}
} else {
// USD_LOG(LOG_DEBUG,"write file [%s] fail.cuz:%s.",file.fileName().toLatin1().data(),backFile.errorString().toLatin1().data());
USD_LOG(LOG_DEBUG,"write file [%s] fail.cuz:%s.",file.fileName().toLatin1().data(),backFile.errorString().toLatin1().data());
}
}
// USD_LOG(LOG_DEBUG,"write file:\n%s ok \n%s ok.",filePath.toLatin1().data(),mScreenMode == nullptr? "" : fileModeConfigPath().toLatin1().data());
USD_LOG(LOG_DEBUG,"write file:\n%s ok \n%s ok.",filePath.toLatin1().data(),mScreenMode == nullptr? "" : fileModeConfigPath().toLatin1().data());
return true;
}

View File

@ -27,7 +27,7 @@
#include <KF5/KScreen/kscreen/config.h>
#include <KF5/KScreen/kscreen/output.h>
#include <KF5/KScreen/kscreen/configmonitor.h>
#include <QMetaEnum>
//#include <QOrientationReading>
#include <memory>
#include "xrandr-output.h"
@ -78,6 +78,7 @@ private:
bool canBeApplied(KScreen::ConfigPtr config) const;
static QString configsDirPath();
static QString configsOldDirPath();
QString configsModeDirPath();
static QString sleepDirPath();

View File

@ -66,7 +66,8 @@ typedef struct
XIDeviceInfo dev_info;
}TsInfo;
XrandrManager::XrandrManager()
XrandrManager::XrandrManager():
kscreenSignals(eScreenSignal::isNone)
{
QGSettings *mXsettings = new QGSettings(XSETTINGS_SCHEMA);
mScale = mXsettings->get(XSETTINGS_KEY_SCALING).toDouble();
@ -93,6 +94,8 @@ XrandrManager::XrandrManager()
mAcitveTime = new QTimer(this);
mKscreenInitTimer = new QTimer(this);
m_offUsbScreenTimer = new QTimer(this);
m_onUsbScreenTimer = new QTimer(this);
metaEnum = QMetaEnum::fromType<UsdBaseClass::eScreenMode>();
@ -110,13 +113,40 @@ XrandrManager::XrandrManager()
if (t_DbusTableMode->isValid()) {
connect(t_DbusTableMode, SIGNAL(mode_change_signal(bool)),this,SLOT(TabletSettingsChanged(bool)));
//USD_LOG(LOG_DEBUG, "..");
} else {
USD_LOG(LOG_ERR, "m_DbusRotation");
}
m_onUsbScreenTimer->setSingleShot(true);
m_offUsbScreenTimer->setSingleShot(true);
connect(m_offUsbScreenTimer, &QTimer::timeout, this, [=](){
// QProcess offsubProcess;
// offsubProcess.start(m_offUsbScreenCmd);
// offsubProcess.waitForFinished();
// USD_LOG(LOG_DEBUG, "command %s!!!!",m_offUsbScreenCmd.toLatin1().data());
std::unique_ptr<xrandrConfig> MonitoredConfig = mMonitoredConfig->readFile(false);
if (MonitoredConfig == nullptr ) {
USD_LOG(LOG_DEBUG,"config a error");
setScreenMode(metaEnum.key(UsdBaseClass::eScreenMode::cloneScreenMode));
return;
}
mMonitoredConfig = std::move(MonitoredConfig);
applyConfig();
});
connect(m_onUsbScreenTimer, &QTimer::timeout, this, [=](){
// QProcess onsubProcess;
// onsubProcess.start(m_onUsbScreenCmd);
// onsubProcess.waitForFinished();
// USD_LOG(LOG_DEBUG, "command %s !!!!",m_onUsbScreenCmd.toLatin1().data());
setScreenMode(metaEnum.key(UsdBaseClass::eScreenMode::extendScreenMode));
});
connect(mDbus,&xrandrDbus::controlScreen,this,&XrandrManager::controlScreenMap);
// connect(mDbus,SIGNAL(xrandrDbus::controlScreen()),this,SLOT(controlScreenMap()));
}
void XrandrManager::getInitialConfig()
@ -240,10 +270,10 @@ getDeviceNode (XIDeviceInfo devinfo)
if (XIGetProperty(QX11Info::display(), devinfo.deviceid, prop, 0, 1000, False,
AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success)
{
return data;
return data;//需要释放
}
XFree(data);
// XFree(data);
return NULL;
}
@ -545,7 +575,6 @@ bool XrandrManager::readMateToKscreen(char monitorsCount,QMap<QString, QString>
}
}
}
applyConfig();
ret = true;
goto FINISH;
@ -1062,7 +1091,6 @@ void XrandrManager::RotationChangedEvent(const QString &rotation)
// qDebug()<<output->rotation() <<output->name();
USD_LOG(LOG_DEBUG,"set %s rotaion:%s", output->name().toLatin1().data(), rotation.toLatin1().data());
}
applyConfig();
}
@ -1101,7 +1129,7 @@ void XrandrManager::saveCurrentConfig()
void XrandrManager::configChanged()
{
USD_LOG(LOG_DEBUG,"...");
}
void XrandrManager::setMonitorForChanges(bool enabled)
@ -1127,17 +1155,42 @@ void XrandrManager::applyKnownConfig(bool state)
void XrandrManager::autoRemapTouchscreen()
{
if(UsdBaseClass::isTablet()) {
intel_SetTouchscreenCursorRotation();
} else {
qDeleteAll(mTouchMapList);
mTouchMapList.clear();
QString configPath = QDir::homePath() + MAP_CONFIG;
QFileInfo file(configPath);
if(file.exists()) {
remapFromConfig(configPath);
static KScreen::ConfigPtr oldOutputs = nullptr;
bool needSetMapTouchDevice = false;
if (oldOutputs != nullptr) {
Q_FOREACH (const KScreen::OutputPtr &oldOutput, oldOutputs->outputs()) {
if (needSetMapTouchDevice) {
break;
}
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if(output->isConnected() && oldOutput->name() == output->name()) {
if(oldOutput->currentModeId() != output->currentModeId() || oldOutput->pos() != output->pos()
|| oldOutput->scale() != output->scale() || oldOutput->rotation() != output->rotation() ||
oldOutput->isPrimary() != output->isPrimary() || oldOutput->isEnabled() != output->isEnabled() ||
oldOutput->isConnected() != output->isConnected()) {
needSetMapTouchDevice = true;
}
}
}
}
} else {
needSetMapTouchDevice = true;
}
oldOutputs = mMonitoredConfig->data()->clone();
if (needSetMapTouchDevice) {
if(UsdBaseClass::isTablet()) {
intel_SetTouchscreenCursorRotation();
} else {
qDeleteAll(mTouchMapList);
mTouchMapList.clear();
QString configPath = QDir::homePath() + MAP_CONFIG;
QFileInfo file(configPath);
if(file.exists()) {
remapFromConfig(configPath);
}
SetTouchscreenCursorRotation();
}
SetTouchscreenCursorRotation();
}
}
@ -1179,8 +1232,19 @@ void XrandrManager::applyConfig()
connect(new KScreen::SetConfigOperation(mMonitoredConfig->data()),
&KScreen::SetConfigOperation::finished,
this, [this]() {
QProcess subProcess;
QString usdSaveParam = "save-param -g";
USD_LOG(LOG_ERR,"--|apply success|--");
autoRemapTouchscreen();
sendScreenModeToDbus();
mMonitoredConfig->setScreenMode(metaEnum.valueToKey(discernScreenMode()));
mMonitoredConfig->writeFile(false);
USD_LOG(LOG_DEBUG,"save param in lightdm-data.");
subProcess.start(usdSaveParam);
subProcess.waitForFinished();
});
} else {
USD_LOG(LOG_ERR,"--|can't be apply|--");
@ -1195,27 +1259,74 @@ void XrandrManager::outputConnectedChanged()
{
}
//用于外置显卡,当外置显卡插拔时会有此事件产生
void XrandrManager::outputAddedHandle(const KScreen::OutputPtr &output)
{
// USD_LOG(LOG_DEBUG,".");
USD_LOG_SHOW_OUTPUT(output);
if (!mMonitoredConfig->data()->outputs().contains(output->id())) {
mMonitoredConfig->data()->addOutput(output->clone());
connect(output.data(), &KScreen::Output::isConnectedChanged, this, [this](){
KScreen::Output *senderOutput = static_cast<KScreen::Output*> (sender());
if (senderOutput == nullptr) {
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
if (senderOutput->isConnected()==false) {
USD_LOG(LOG_DEBUG,"ready remove %d",senderOutput->id());
if (mMonitoredConfig->data()->outputs().contains(senderOutput->id())) {
USD_LOG(LOG_DEBUG,"remove %d",senderOutput->id());
mMonitoredConfig->data()->removeOutput(senderOutput->id());
}
}
m_offUsbScreenTimer->start(1500);
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
}
},Qt::QueuedConnection);
}
m_onUsbScreenTimer->start(2500);
}
void XrandrManager::outputRemoved(int outputId)
//usb 屏幕暂时不需要插拔处理好像是由xorg直接完成。
void XrandrManager::outputRemovedHandle(int outputId)
{
// USD_LOG(LOG_DEBUG,".");
USD_LOG(LOG_DEBUG,".");
if (mMonitoredConfig->data()->outputs().contains(outputId)) {
mMonitoredConfig->data()->outputRemoved(outputId);
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
}
std::unique_ptr<xrandrConfig> MonitoredConfig = mMonitoredConfig->readFile(false);
if (MonitoredConfig == nullptr ) {
USD_LOG(LOG_DEBUG,"config a error");
setScreenMode(metaEnum.key(UsdBaseClass::eScreenMode::cloneScreenMode));
return;
}
mMonitoredConfig = std::move(MonitoredConfig);
applyConfig();
}
}
void XrandrManager::primaryOutputChanged(const KScreen::OutputPtr &output)
{
// USD_LOG(LOG_DEBUG,".");
USD_LOG(LOG_DEBUG,".");
}
void XrandrManager::primaryScreenChange()
{
// USD_LOG(LOG_DEBUG,".");
USD_LOG(LOG_DEBUG,".");
}
void XrandrManager::callMethod(QRect geometry, QString name)
@ -1332,7 +1443,7 @@ void XrandrManager::outputChangedHandle(KScreen::Output *senderOutput)
if (output->name()==senderOutput->name()) {
senderOutput->setEnabled(senderOutput->isConnected());
mMonitoredConfig->data()->removeOutput(output->id());
mMonitoredConfig->data()->addOutput(senderOutput->clone());//?????
mMonitoredConfig->data()->addOutput(senderOutput->clone());
break;
}
}
@ -1348,7 +1459,9 @@ void XrandrManager::outputChangedHandle(KScreen::Output *senderOutput)
outputConnectCount++;
}
}
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
}
if (UsdBaseClass::isTablet()) {
int ret = getCurrentMode();
@ -1360,8 +1473,7 @@ void XrandrManager::outputChangedHandle(KScreen::Output *senderOutput)
//PC模式
setScreenMode(metaEnum.key(UsdBaseClass::eScreenMode::extendScreenMode));
}
} else {//非intel项目无此接口
} else {//非tablet项目无此接口
if (false == mMonitoredConfig->fileExists()) {
if (senderOutput->isConnected()) {
senderOutput->setEnabled(senderOutput->isConnected());
@ -1372,6 +1484,7 @@ void XrandrManager::outputChangedHandle(KScreen::Output *senderOutput)
std::unique_ptr<xrandrConfig> MonitoredConfig = mMonitoredConfig->readFile(false);
if (MonitoredConfig!=nullptr) {
mMonitoredConfig = std::move(MonitoredConfig);
} else {
if (outputConnectCount>1) {
if (!checkKscreenConfigState(UsdBaseClass::eScreenMode::cloneScreenMode)) {
if (!checkKscreenConfigState(UsdBaseClass::eScreenMode::extendScreenMode)) {
@ -1379,14 +1492,69 @@ void XrandrManager::outputChangedHandle(KScreen::Output *senderOutput)
}
}
}
} else {
USD_LOG(LOG_DEBUG,"read config file error! ");
}
}
}
}
USD_LOG(LOG_DEBUG,"read config file success!");
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
}
applyConfig();
}
void XrandrManager::outputModesChangedHandle()
{
//TODO: just handle modesChanges signal for cloud desktop
/*
* make sure the size in Kscreen config is smaller than max screen size
* if ouputname != nullptr set this ouput mode is preffer mode,
*/
/*
* kscreen中的size小于screen的最大尺寸
* ouputname不为空output的最佳分辨率size
*
* output为空使
*
* !
* 00
*
*/
int newPosX = 0;
int findOutputCounect = 0;
//找出pos(0.0)的屏幕大小
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
if (!output->isConnected() || !output->isEnabled()) {
continue;
}
//不能在这里获取size大小特殊情况下currentMode->size会报错
if (output->pos() == QPoint(0,0)) {
findOutputCounect++;
if (m_modesChangeOutputs.contains(output->name()) &&
output->modes().contains(output->preferredModeId())) {
output->setCurrentModeId(output->preferredModeId());
}
newPosX += output->currentMode()->size().width();
break;
}
}
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
if (!output->isConnected() || !output->isEnabled()) {
continue;
}
if (output->pos() != QPoint(0,0)) {
output->setPos(QPoint(newPosX,0));
if (m_modesChangeOutputs.contains(output->name()) &&
output->modes().contains(output->preferredModeId())) {
output->setCurrentModeId(output->preferredModeId());
}
newPosX += output->currentMode()->size().width();
}
}
applyConfig();
}
@ -1394,7 +1562,23 @@ void XrandrManager::outputChangedHandle(KScreen::Output *senderOutput)
void XrandrManager::SaveConfigTimerHandle()
{
int enableScreenCount = 0;
mSaveConfigTimer->stop();
m_screenSignalTimer->stop();
if (kscreenSignals & eScreenSignal::isModesChanged && !(kscreenSignals & eScreenSignal::isConnectedChanged)) {
outputModesChangedHandle();
m_modesChangeOutputs.clear();
kscreenSignals = eScreenSignal::isNone;
return;
}
if (kscreenSignals&(eScreenSignal::isConnectedChanged|eScreenSignal::isOutputChanged)) {
USD_LOG(LOG_DEBUG,"skip save config");
mIsApplyConfigWhenSave = false;
kscreenSignals = eScreenSignal::isNone;
return;
}
kscreenSignals = eScreenSignal::isNone;
if (false == mIsApplyConfigWhenSave) {
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
@ -1405,7 +1589,7 @@ void XrandrManager::SaveConfigTimerHandle()
if (0 == enableScreenCount) {//When user disable last one connected screen USD must enable the screen.
mIsApplyConfigWhenSave = true;
mSaveConfigTimer->start(SAVE_CONFIG_TIME*5);
m_screenSignalTimer->start(SAVE_CONFIG_TIME*5);
return;
}
}
@ -1415,8 +1599,11 @@ void XrandrManager::SaveConfigTimerHandle()
setScreenMode(metaEnum.key(UsdBaseClass::eScreenMode::firstScreenMode));
} else {
QProcess subProcess;
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
}
mMonitoredConfig->setScreenMode(metaEnum.valueToKey(discernScreenMode()));
mMonitoredConfig->writeFile(true);
mMonitoredConfig->writeFile(false);
QString usdSaveParam = "save-param -g";
USD_LOG(LOG_DEBUG,"save param in lightdm-data.");
subProcess.start(usdSaveParam);
@ -1462,9 +1649,10 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
kscreenSignals |= eScreenSignal::isConnectedChanged;
USD_LOG(LOG_DEBUG,"%s isConnectedChanged connect:%d",senderOutput->name().toLatin1().data(), senderOutput->isConnected());
m_screenSignalTimer->stop();
outputChangedHandle(senderOutput);
USD_LOG_SHOW_OUTPUT(senderOutput);
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::outputChanged, this, [this](){
@ -1473,10 +1661,10 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
USD_LOG_SHOW_OUTPUT(senderOutput);
outputChangedHandle(senderOutput);//断开屏幕有时会isConnect有时会给outputChanged
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
kscreenSignals |= eScreenSignal::isOutputChanged;
USD_LOG(LOG_DEBUG,"%s outputchanged connect:%d",senderOutput->name().toLatin1().data(), senderOutput->isConnected());
m_screenSignalTimer->stop();
// outputChangedHandle(senderOutput);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::isPrimaryChanged, this, [this](){
@ -1485,6 +1673,7 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
kscreenSignals |= eScreenSignal::isPrimaryChanged;
USD_LOG(LOG_DEBUG,"PrimaryChanged:%s",senderOutput->name().toLatin1().data());
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
@ -1494,7 +1683,7 @@ void XrandrManager::monitorsInit()
}
}
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
});
connect(output.data(), &KScreen::Output::posChanged, this, [this](){
@ -1503,15 +1692,20 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
USD_LOG(LOG_DEBUG,"posChanged:%s",senderOutput->name().toLatin1().data());
if (kscreenSignals&(eScreenSignal::isConnectedChanged|eScreenSignal::isOutputChanged)) {
return;
}
kscreenSignals |= eScreenSignal::isPosChanged;
USD_LOG(LOG_DEBUG,"posChanged:%s",senderOutput->name().toLatin1().data());
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if (output->name() == senderOutput->name()) {
output->setPos(senderOutput->pos());
break;
}
}
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::sizeChanged, this, [this](){
@ -1520,8 +1714,9 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
kscreenSignals |= eScreenSignal::isSizeChanged;
USD_LOG(LOG_DEBUG,"sizeChanged:%s",senderOutput->name().toLatin1().data());
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::modesChanged, this, [this](){
@ -1530,11 +1725,31 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
USD_LOG(LOG_DEBUG,"modesChanged:%s",senderOutput->name().toLatin1().data());
USD_LOG(LOG_DEBUG,"modesChanged:%dx%d@%f",senderOutput->preferredMode()->size().width(),
senderOutput->preferredMode()->size().height(),senderOutput->preferredMode()->refreshRate());
USD_LOG_SHOW_OUTPUT(senderOutput);
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
if (!(kscreenSignals & eScreenSignal::isConnectedChanged)) {
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if (output->name()==senderOutput->name()) {//这里只设置connectenbale由配置设置。
if (output->preferredModeId() == nullptr) {
USD_LOG(LOG_DEBUG,"%s prefferedMode is none", senderOutput->name());
return;
}
output->setEnabled(senderOutput->isConnected());
output->setConnected(senderOutput->isConnected());
qDebug()<<output->modes();
qDebug()<<senderOutput->modes();
output->setModes(senderOutput->modes());
USD_LOG(LOG_DEBUG,"old mode id:%s", output->preferredModeId().toLatin1().data());
output->setPreferredModes(senderOutput->preferredModes());
USD_LOG(LOG_DEBUG,"new mode id:%s", output->preferredModeId().toLatin1().data());
break;
}
}
m_modesChangeOutputs.append(senderOutput->name());
kscreenSignals |= eScreenSignal::isModesChanged;
}
USD_LOG(LOG_DEBUG,"%s modesChanged",senderOutput->name().toLatin1().data());
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::clonesChanged, this, [this](){
@ -1543,8 +1758,9 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
kscreenSignals |= eScreenSignal::isClonesChanged;
USD_LOG(LOG_DEBUG,"clonesChanged:%s",senderOutput->name().toLatin1().data());
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::rotationChanged, this, [this](){
@ -1553,7 +1769,8 @@ void XrandrManager::monitorsInit()
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
USD_LOG(LOG_DEBUG,"clonesChanged:%s",senderOutput->name().toLatin1().data());
kscreenSignals |= eScreenSignal::isRotationChanged;
USD_LOG(LOG_DEBUG,"rotationChanged:%s",senderOutput->name().toLatin1().data());
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if (output->name() == senderOutput->name()) {
output->setRotation(senderOutput->rotation());
@ -1562,7 +1779,7 @@ void XrandrManager::monitorsInit()
}
USD_LOG(LOG_DEBUG,"rotationChanged:%s",senderOutput->name().toLatin1().data());
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::currentModeIdChanged, this, [this](){
@ -1572,7 +1789,7 @@ void XrandrManager::monitorsInit()
return;
}
USD_LOG(LOG_DEBUG,"currentModeIdChanged:%s",senderOutput->name().toLatin1().data());
kscreenSignals |= eScreenSignal::isCurrentModeIdChanged;
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if (output->name() == senderOutput->name()) {
output->setCurrentModeId(senderOutput->currentModeId());
@ -1581,16 +1798,17 @@ void XrandrManager::monitorsInit()
}
}
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
connect(output.data(), &KScreen::Output::isEnabledChanged, this, [this](){
KScreen::Output *senderOutput = static_cast<KScreen::Output*> (sender());
USD_LOG(LOG_DEBUG,"isEnabledChanged:%s",senderOutput->name().toLatin1().data());
USD_LOG(LOG_DEBUG,"%s isEnabledChanged:%d",senderOutput->name().toLatin1().data(), senderOutput->isEnabled());
if (senderOutput == nullptr) {
USD_LOG(LOG_DEBUG,"had a bug..");
return;
}
kscreenSignals |= eScreenSignal::isEnabledChanged;
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if (output->name() == senderOutput->name()) {
output->setEnabled(senderOutput->isEnabled());
@ -1598,7 +1816,7 @@ void XrandrManager::monitorsInit()
}
}
mSaveConfigTimer->start(SAVE_CONFIG_TIME);
m_screenSignalTimer->start(SAVE_CONFIG_TIME);
},Qt::QueuedConnection);
}
@ -1609,13 +1827,27 @@ void XrandrManager::monitorsInit()
connect(mConfig.data(), SIGNAL(outputAdded(KScreen::OutputPtr)),
this, SLOT(outputAddedHandle(KScreen::OutputPtr)));
connect(mConfig.data(), &KScreen::Config::outputRemoved,
this, &XrandrManager::outputRemoved,
static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::UniqueConnection));
connect(mConfig.data(), SIGNAL(outputRemoved(int)),
this, SLOT(outputRemovedHandle(int)));
connect(mConfig.data(), &KScreen::Config::primaryOutputChanged,
this, &XrandrManager::primaryOutputChanged);
connect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged,
this, &XrandrManager::configChanged, Qt::UniqueConnection);
if (mXrandrSetting->keys().contains("hadmate2kscreen")) {//兼容mate配置
if (mXrandrSetting->get("hadmate2kscreen").toBool() == false) {
mXrandrSetting->set("hadmate2kscreen", true);
if (readMateToKscreen(connectedOutputCount, monitorsNameList)) {
USD_LOG(LOG_DEBUG,"convert mate ok...");
return;
}
}
}
if (!mMonitoredConfig->fileExists()) {
mMonitoredConfig->writeFile(false);
}
@ -1651,11 +1883,13 @@ void XrandrManager::monitorsInit()
Q_FOREACH(const KScreen::OutputPtr &output,mMonitoredConfig->data()->outputs()) {
if(oldOutput->name() == output->name()) {
if(oldOutput->currentModeId() != output->currentModeId() || oldOutput->pos() != output->pos()
if(oldOutput->size() != output->size() || oldOutput->pos() != output->pos()
|| oldOutput->scale() != output->scale() || oldOutput->rotation() != output->rotation() ||
oldOutput->isPrimary() != output->isPrimary() || oldOutput->isEnabled() != output->isEnabled()) {
needSetParamWhenStartup = true;
USD_LOG_SHOW_OUTPUT(output);
USD_LOG(LOG_DEBUG,"%dX%d %dx%d",oldOutput->size().width(),oldOutput->size().height(),output->size().width(),output->size().height());
USD_LOG_SHOW_OUTPUT(oldOutput);
}
}
}
@ -1666,42 +1900,6 @@ void XrandrManager::monitorsInit()
}
}
} else {
int foreachTimes = 0;
if (mXrandrSetting->keys().contains("hadmate2kscreen")) {
if (mXrandrSetting->get("hadmate2kscreen").toBool() == false) {
mXrandrSetting->set("hadmate2kscreen", true);
if (readMateToKscreen(connectedOutputCount, monitorsNameList)) {
USD_LOG(LOG_DEBUG,"convert mate ok...");
return;
}
}
}
USD_LOG(LOG_DEBUG,"creat a config:%s.",mMonitoredConfig->filePath().toLatin1().data());
for (const KScreen::OutputPtr &output: mMonitoredConfig->data()->outputs()) {
USD_LOG_SHOW_OUTPUT(output);
if (1==connectedOutputCount){
outputChangedHandle(output.data());
break;
} else {
if (output->isConnected()){
foreachTimes++;
}
if (foreachTimes>1) {
USD_LOG_SHOW_OUTPUT(output);
outputChangedHandle(output.data());
break;
}
}
}
mMonitoredConfig->writeFile(false);
}
}
@ -1977,7 +2175,6 @@ void XrandrManager::setScreenModeToFirst(bool isFirstMode)
USD_LOG_SHOW_OUTPUT(output);
}
applyConfig();
}
@ -1988,7 +2185,9 @@ void XrandrManager::setScreenModeToExtend()
int singleMaxWidth = 0;
float refreshRate = 0.0;
bool hadFindPrimay = false;
int maxHeight = mMonitoredConfig->data()->screen()->maxSize().height();
int maxWidth = mMonitoredConfig->data()->screen()->maxSize().width();
int connectedScreens;
if (false == checkPrimaryScreenIsSetable()) {
return;
}
@ -1997,6 +2196,14 @@ void XrandrManager::setScreenModeToExtend()
return;
}
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
if (!output->isConnected()){
continue;
}
connectedScreens++;
}
Q_FOREACH(const KScreen::OutputPtr &output, mMonitoredConfig->data()->outputs()) {
if (!output->isConnected()){
@ -2008,7 +2215,7 @@ void XrandrManager::setScreenModeToExtend()
continue;
}
if (!output->name().contains("eDP")) {//考虑 pnZXECRB项目中内屏为 DisplayPort-0
if (!output->name().contains("eDP-1")) {//考虑 pnZXECRB项目中内屏为 DisplayPort-0
output->setPrimary(false);
continue;
}
@ -2022,7 +2229,7 @@ void XrandrManager::setScreenModeToExtend()
screenSize = 0;
refreshRate = 0.0;
Q_FOREACH (auto Mode, output->modes()){
Q_FOREACH (auto Mode, output->modes()) {
if (Mode->size().width()*Mode->size().height() < screenSize){
continue;
} else if (Mode->size().width()*Mode->size().height() == screenSize) {
@ -2095,7 +2302,6 @@ void XrandrManager::setScreenModeToExtend()
primaryX += singleMaxWidth;
USD_LOG_SHOW_OUTPUT(output);
}
applyConfig();
}
@ -2107,7 +2313,6 @@ void XrandrManager::setScreensParam(QString screensParam)
if (nullptr != temp) {
mMonitoredConfig = std::move(temp);
}
applyConfig();
}
@ -2295,8 +2500,8 @@ void XrandrManager::StartXrandrIdleCb()
{
mAcitveTime->stop();
mSaveConfigTimer = new QTimer(this);
connect(mSaveConfigTimer, SIGNAL(timeout()), this, SLOT(SaveConfigTimerHandle()));
m_screenSignalTimer = new QTimer(this);
connect(m_screenSignalTimer, SIGNAL(timeout()), this, SLOT(SaveConfigTimerHandle()));
USD_LOG(LOG_DEBUG,"StartXrandrIdleCb ok.");

View File

@ -107,6 +107,7 @@ public:
void calingPeonyProcess();
bool pretreatScreenInfo();
void outputChangedHandle(KScreen::Output *senderOutput);
void outputModesChangedHandle();
void lightLastScreen();
void outputConnectedWithoutConfigFile(KScreen::Output *senderOutput ,char outputCount);
void setScreenModeToClone();
@ -135,7 +136,7 @@ public Q_SLOTS:
void configChanged();
void RotationChangedEvent(const QString &rotation);
void outputAddedHandle(const KScreen::OutputPtr &output);
void outputRemoved(int outputId);
void outputRemovedHandle(int outputId);
void primaryOutputChanged(const KScreen::OutputPtr &output);
// void applyConfigTimerHandle();
void setScreenMode(QString modeName);
@ -156,7 +157,28 @@ protected:
QMultiMap<QString, QString> XmlFileTag; //存放标签的属性值
QMultiMap<QString, int> mIntDate;
private:
enum eScreenSignal {
isNone = 0,
isOutputChanged = 1<<0,
isPosChanged = 1<<1,
isSizeChanged = 1<<2,
isCurrentModeIdChanged = 1<<3,
isRotationChanged = 1<<4,
isConnectedChanged = 1<<5,
isEnabledChanged = 1<<6,
isPrimaryChanged = 1<<7,
isClonesChanged = 1<<8,
isReplicationSourceChanged = 1<<9,
isScaleChanged = 1<<10,
isLogicalSizeChanged = 1<<11,
isFollowPreferredModeChanged = 1<<12,
isModesChanged = 1 << 13,
};
void disableCrtc();
QList<touchpadMap*> mTouchMapList; //存储已映射的关系
Q_INVOKABLE void getInitialConfig();
@ -164,7 +186,7 @@ private:
QDBusInterface *m_DbusRotation;
QTimer *mAcitveTime = nullptr;
QTimer *mKscreenInitTimer = nullptr;
QTimer *mSaveConfigTimer = nullptr;
QTimer *m_screenSignalTimer = nullptr;
QTimer *mChangeCompressor = nullptr;
QTimer *mApplyConfigTimer = nullptr;
QGSettings *mXrandrSetting = nullptr;
@ -175,7 +197,11 @@ private:
std::unique_ptr<xrandrConfig> mMonitoredConfig = nullptr;
KScreen::ConfigPtr mConfig = nullptr;
xrandrDbus *mDbus;
QString m_offUsbScreenCmd;
QString m_onUsbScreenCmd;
QStringList m_modesChangeOutputs;
QTimer *m_offUsbScreenTimer;
QTimer *m_onUsbScreenTimer;
QMetaEnum metaEnum;
bool mMonitoring;
@ -185,6 +211,7 @@ private:
QScreen *mScreen = nullptr;
bool mStartingUp = true;
bool mIsApplyConfigWhenSave = false;
int kscreenSignals;
};
#endif // XRANDRMANAGER_H

View File

@ -77,23 +77,23 @@ void xrandrOutput::readInGlobalPartFromInfo(KScreen::OutputPtr output, const QVa
USD_LOG(LOG_DEBUG, "%s mode count = 0.",output->name().toLatin1().data());
}
for(const KScreen::ModePtr &mode : modes) {
for (const KScreen::ModePtr &mode : modes) {
if (mode->size() != size) {
continue;
}
if (!qFuzzyCompare(mode->refreshRate(), modeInfo[QStringLiteral("refresh")].toFloat())) {
continue;
}
USD_LOG(LOG_DEBUG,"find mode id:%s %dx%d@%f", mode->id().toLatin1().data(), mode->size().height(), mode->size().width(),mode->refreshRate());
matchingMode = mode;
break;
}
if (!matchingMode) {
USD_LOG(LOG_DEBUG,"Failed to find a matching mode - this means that our config is corrupted");
USD_LOG(LOG_DEBUG,"Failed to %s find a matching mode - this means that our config is corrupted",output->name().toLatin1().data());
matchingMode = output->preferredMode();
}
if (!matchingMode) {
if (!matchingMode) {//没有找到最适合分辨率
USD_LOG(LOG_DEBUG,"Failed to get a preferred mode, falling back to biggest mode.");
// matchingMode = Generator::biggestMode(modes);
}
@ -283,6 +283,7 @@ void xrandrOutput::adjustPositions(KScreen::ConfigPtr config, const QVariantList
void xrandrOutput::readIn(KScreen::OutputPtr output, const QVariantMap &info)
{
const QVariantMap posInfo = info[QStringLiteral("pos")].toMap();
QPoint point(posInfo[QStringLiteral("x")].toInt(), posInfo[QStringLiteral("y")].toInt());
output->setPos(point);
@ -333,6 +334,8 @@ void xrandrOutput::readInOutputs(KScreen::ConfigPtr config, const QVariantList &
const QVariantMap info = variantInfo.toMap();
if (outputId != info[QStringLiteral("id")].toString()) {
continue;
} else {
USD_LOG(LOG_DEBUG,"find %s:%s",output->name().toLatin1().data(), outputId.toLatin1().data());
}
if (!output->name().isEmpty() && duplicateIds.contains(outputId)) {

View File

@ -95,6 +95,10 @@ PluginInterface *XrandrPlugin::getInstance()
void XrandrPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
USD_LOG(LOG_ERR,"Deactivating Xrandr plugin");
mXrandrManager->XrandrManagerStop();
}

View File

@ -19,12 +19,16 @@
#include <QDebug>
#include "ukui-xsettings-plugin.h"
#include "clib-syslog.h"
#include "usd_base_class.h"
PluginInterface *XSettingsPlugin::mInstance =nullptr;
ukuiXSettingsManager *XSettingsPlugin::m_pukuiXsettingManager = nullptr;
XSettingsPlugin::XSettingsPlugin()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
if(nullptr == m_pukuiXsettingManager)
m_pukuiXsettingManager = new ukuiXSettingsManager();
}
@ -40,7 +44,10 @@ XSettingsPlugin::~XSettingsPlugin()
void XSettingsPlugin::activate()
{
bool res;
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
res = m_pukuiXsettingManager->start();
if (!res) {
qWarning ("Unable to start XSettingsPlugin manager");
@ -51,6 +58,10 @@ void XSettingsPlugin::activate()
void XSettingsPlugin::deactivate()
{
if (UsdBaseClass::isWayland()) {
USD_LOG(LOG_DEBUG,"is wayland exit...");
return;
}
m_pukuiXsettingManager->stop();
}
PluginInterface *XSettingsPlugin::getInstance()