!15 Fix the display error of flight mode icon

From: @peijiankang 
Reviewed-by: @tanyulong2021 
Signed-off-by: @tanyulong2021
This commit is contained in:
openeuler-ci-bot 2022-07-14 06:56:59 +00:00 committed by Gitee
commit 3a0ca3568e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 297 additions and 1 deletions

View File

@ -0,0 +1,291 @@
From 677d21aeb763366d7e6d63015106715da8e47cd5 Mon Sep 17 00:00:00 2001
From: peijiankang <peijiankang@kylinos.cn>
Date: Thu, 14 Jul 2022 14:23:52 +0800
Subject: [PATCH] Fix the display error of flight mode icon
---
conf/org.ukui.kds.gschema.xml | 12 ++-
registerdbus/classrealize.cpp | 183 +++++++++++++++++++++++++++++++++-
registerdbus/classrealize.h | 4 +
3 files changed, 197 insertions(+), 2 deletions(-)
diff --git a/conf/org.ukui.kds.gschema.xml b/conf/org.ukui.kds.gschema.xml
index fc89bc2..89610e8 100644
--- a/conf/org.ukui.kds.gschema.xml
+++ b/conf/org.ukui.kds.gschema.xml
@@ -9,6 +9,16 @@
<default>true</default>
<summary>microphone enable or not</summary>
<description>current microphone enable or not</description>
- </key>
+ </key>
+ <key type="b" name="airplanemode">
+ <default>false</default>
+ <summary>microphone enable or not</summary>
+ <description>current microphone enable or not</description>
+ </key>
+ <key type="as" name="beforeairplanemode">
+ <default>['0']</default>
+ <summary>microphone enable or not</summary>
+ <description>current microphone enable or not</description>
+ </key>
</schema>
</schemalist>
diff --git a/registerdbus/classrealize.cpp b/registerdbus/classrealize.cpp
index 82f8f22..9133aba 100755
--- a/registerdbus/classrealize.cpp
+++ b/registerdbus/classrealize.cpp
@@ -33,6 +33,11 @@ extern "C" {
#define RFKILL_EVENT_SIZE_V1 8
+#define VIRTUAL_PATH "/sys/devices/virtual/ieee80211"
+
+const char * getRFkillType(__u32 idx);
+const char * getRFkillName(__u32 idx);
+
struct rfkill_event {
__u32 idx;
__u8 type;
@@ -233,6 +238,36 @@ QString ClassRealize::toggleCameraDevice(QString businfo){
}
}
+bool ClassRealize::isVirtualWlan(QString dp){
+ QDir dir(VIRTUAL_PATH);
+ if (!dir.exists()){
+ return false;
+ }
+
+ dir.setFilter(QDir::Dirs);
+ dir.setSorting(QDir::Name);
+
+ int count = dir.count();
+ if (count <= 0){
+ return false;
+ }
+
+ QFileInfoList fileinfoList = dir.entryInfoList();
+
+ for(QFileInfo fileinfo : fileinfoList){
+ if (fileinfo.fileName() == "." || fileinfo.fileName() == ".."){
+ continue;
+ }
+
+ if (QString::compare(fileinfo.fileName(), dp) == 0){
+ return true;
+ }
+ }
+
+ return false;
+
+}
+
int ClassRealize::getCurrentWlanMode(){
struct rfkill_event event;
ssize_t len;
@@ -271,6 +306,10 @@ int ClassRealize::getCurrentWlanMode(){
if (event.type != RFKILL_TYPE_WLAN)
continue;
+ if (isVirtualWlan(QString(getRFkillName(event.idx)))){
+ continue;
+ }
+
status.append(event.soft ? 1 : 0);
}
@@ -418,6 +457,94 @@ QString ClassRealize::toggleBluetoothMode(bool enable){
return block ? QString("blocked") : QString("unblocked");
}
+QList<int> ClassRealize::getStatusBeforeFlightModeEnable(){
+
+ QList<int> re;
+
+ struct rfkill_event event;
+ ssize_t len;
+ int fd;
+ int bls = 0, unbls = 0;
+
+ QList<int> status;
+
+ fd = open("/dev/rfkill", O_RDONLY);
+ if (fd < 0) {
+ qCritical("Can't open RFKILL control device");
+ return re;
+ }
+
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+ qCritical("Can't set RFKILL control device to non-blocking");
+ close(fd);
+ return re;
+ }
+
+ while (1) {
+ len = read(fd, &event, sizeof(event));
+
+ if (len < 0) {
+ if (errno == EAGAIN)
+ break;
+ qWarning("Reading of RFKILL events failed");
+ break;
+ }
+
+ if (len != RFKILL_EVENT_SIZE_V1) {
+ qWarning("Wrong size of RFKILL event\n");
+ continue;
+ }
+
+ if (isVirtualWlan(QString(getRFkillName(event.idx)))){
+ continue;
+ }
+
+// printf("%u: %u\n", event.idx, event.soft);
+// status.append(event.soft ? 1 : 0);
+ if (!event.soft && !re.contains(event.type)){
+ re.append(event.type);
+ }
+
+ }
+
+ close(fd);
+
+ return re;
+}
+
+QString ClassRealize::setSingleFlightMode(int type){
+
+ struct rfkill_event event;
+ int fd;
+ ssize_t len;
+
+ __u8 block = 0;
+
+ fd = open("/dev/rfkill", O_RDWR);
+ if (fd < 0) {
+ return QString("Can't open RFKILL control device");
+ }
+
+ memset(&event, 0, sizeof(event));
+
+ event.op= RFKILL_OP_CHANGE_ALL;
+
+ /* RFKILL_TYPE_ALL = 0 */
+ event.type = type;
+
+ event.soft = block;
+
+ len = write(fd, &event, sizeof(event));
+
+ if (len < 0){
+ return QString("Failed to change RFKILL state");
+ }
+
+ close(fd);
+ return QString();
+}
+
+
int ClassRealize::getCurrentFlightMode(){
struct rfkill_event event;
@@ -454,6 +581,10 @@ int ClassRealize::getCurrentFlightMode(){
continue;
}
+ if (isVirtualWlan(QString(getRFkillName(event.idx)))){
+ continue;
+ }
+
// printf("%u: %u\n", event.idx, event.soft);
status.append(event.soft ? 1 : 0);
@@ -509,7 +640,7 @@ QString ClassRealize::toggleFlightMode(bool enable){
}
close(fd);
- return block ? QString("blocked") : QString("unblocked");
+ return QString();
}
int ClassRealize::setCameraKeyboardLight(bool lightup){
@@ -543,3 +674,53 @@ int ClassRealize::setAirplaneModeKeyboardLight(bool lightup){
return 1;
}
+
+const char * getRFkillName(__u32 idx){
+
+ static char name[128] = {};
+ char *pos, filename[64];
+ int fd;
+
+ snprintf(filename, sizeof(filename) - 1,
+ "/sys/class/rfkill/rfkill%u/name", idx);
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ memset(name, 0, sizeof(name));
+ read(fd, name, sizeof(name) - 1);
+
+ pos = strchr(name, '\n');
+ if (pos)
+ *pos = '\0';
+
+ close(fd);
+
+ return name;
+}
+
+const char * getRFkillType(__u32 idx){
+
+ static char name[128] = {};
+ char *pos, filename[64];
+ int fd;
+
+ snprintf(filename, sizeof(filename) - 1,
+ "/sys/class/rfkill/rfkill%u/type", idx);
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ memset(name, 0, sizeof(name));
+ read(fd, name, sizeof(name) - 1);
+
+ pos = strchr(name, '\n');
+ if (pos)
+ *pos = '\0';
+
+ close(fd);
+
+ return name;
+}
diff --git a/registerdbus/classrealize.h b/registerdbus/classrealize.h
index 32efd06..cbb4ee3 100644
--- a/registerdbus/classrealize.h
+++ b/registerdbus/classrealize.h
@@ -35,6 +35,8 @@ public:
explicit ClassRealize();
~ClassRealize();
+public:
+ bool isVirtualWlan(QString dp);
signals:
Q_SCRIPTABLE void debug0(QString);
@@ -66,6 +68,8 @@ public slots:
Q_SCRIPTABLE QString toggleCameraDevice(QString businfo);
Q_SCRIPTABLE int setCameraKeyboardLight(bool lightup);
Q_SCRIPTABLE int getCurrentFlightMode();
+ Q_SCRIPTABLE QList<int> getStatusBeforeFlightModeEnable();
+ Q_SCRIPTABLE QString setSingleFlightMode(int type);
Q_SCRIPTABLE QString toggleFlightMode(bool enable);
Q_SCRIPTABLE int setAirplaneModeKeyboardLight(bool lightup);
Q_SCRIPTABLE int getCurrentWlanMode();
--
2.33.0

View File

@ -1,13 +1,14 @@
%define debug_package %{nil}
Name: kylin-display-switch
Version: 3.0.13
Release: 3
Release: 4
Summary: Gui tool for display switching
License: GPL-3
URL: https://github.com/ukui/kylin-display-switch
Source0: %{name}-%{version}.tar.gz
Patch1: 0001-Touch-hotkeys-touch-pad-without-customized-driver.patch
Patch2: 0002-Set-4-modes-to-synchronize-the-current-state.patch
Patch3: 0003-Fix-the-display-error-of-flight-mode-icon.patch
BuildRequires: python3-rpm-macros
BuildRequires: python-rpm-macros
@ -34,6 +35,7 @@ BuildRequires: libxkbcommon-devel
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%build
%{qmake_qt5} %{_qt5_qmake_flags} CONFIG+=enable-by-default kylin-display-switch.pro
@ -63,6 +65,9 @@ make INSTALL_ROOT=%{buildroot} install
%{_datadir}/glib-2.0/schemas/org.ukui.kds.gschema.xml
%changelog
* Thu Jul 14 2022 peijiankang <peijiankang@kylinos.cn> - 3.0.13-4
- 修复多次开关飞行模式热键,飞行模式图标显示错误
* Wed Jul 13 2022 peijiankang <peijiankang@kylinos.cn> - 3.0.13-3
- 设置4种模式前调用控制面板的dbus以便告知控制面板同步当前状态