mirror of
https://github.com/quickshell-mirror/quickshell.git
synced 2026-10-28 02:55:05 +00:00
Compare commits
38
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56633822be | ||
|
|
7208f68bb7 | ||
|
|
f0d0216b3d | ||
|
|
7c5a6c4bd4 | ||
|
|
5bf6a412b0 | ||
|
|
13fe9b0d98 | ||
|
|
ad5fd9116e | ||
|
|
49d4f46cf1 | ||
|
|
9b98d10178 | ||
|
|
854088c48c | ||
|
|
b4e71cb2c0 | ||
|
|
ceac3c6cfa | ||
|
|
aaff22f4b0 | ||
|
|
50cdf98868 | ||
|
|
4b751ccb0d | ||
|
|
20c691cdf1 | ||
|
|
92b336c80c | ||
|
|
d612227740 | ||
|
|
b83c39c8af | ||
|
|
ee1100eb98 | ||
|
|
9bf752ac33 | ||
|
|
313f4e47f6 | ||
|
|
6ef86dd5aa | ||
|
|
308f1e249b | ||
|
|
08058326f0 | ||
|
|
6a244c3c56 | ||
|
|
d745184823 | ||
|
|
77c04a9447 | ||
|
|
eb6eaf59c7 | ||
|
|
7511545ee2 | ||
|
|
0cb62920a7 | ||
|
|
3520c85d77 | ||
|
|
3cf65af49f | ||
|
|
a51dcd0a01 | ||
|
|
97b2688ad6 | ||
|
|
0a859d51f2 | ||
|
|
1bd5b083cb | ||
|
|
365bf16b1e |
No files matched your search
@@ -1,82 +1,17 @@
|
||||
name: Crash Report (v1)
|
||||
description: Quickshell has crashed
|
||||
labels: ["bug", "crash"]
|
||||
description: Quickshell has crashed (old)
|
||||
labels: ["unactionable"]
|
||||
body:
|
||||
- type: textarea
|
||||
id: crashinfo
|
||||
- type: markdown
|
||||
attributes:
|
||||
label: General crash information
|
||||
description: |
|
||||
Paste the contents of the `info.txt` file in your crash folder here.
|
||||
value: "<details> <summary>General information</summary>
|
||||
|
||||
|
||||
```
|
||||
|
||||
<Paste the contents of the file here inside of the triple backticks>
|
||||
|
||||
```
|
||||
|
||||
|
||||
</details>"
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: userinfo
|
||||
value: |
|
||||
Thank you for taking the time to click the report button.
|
||||
At this point most of the worst issues in 0.2.1 and before have been fixed and we are
|
||||
preparing for a new release. Please do not submit this report.
|
||||
- type: checkboxes
|
||||
id: donotcheck
|
||||
attributes:
|
||||
label: What caused the crash
|
||||
description: |
|
||||
Any information likely to help debug the crash. What were you doing when the crash occurred,
|
||||
what changes did you make, can you get it to happen again?
|
||||
- type: textarea
|
||||
id: dump
|
||||
attributes:
|
||||
label: Minidump
|
||||
description: |
|
||||
Attach `minidump.dmp.log` here. If it is too big to upload, compress it.
|
||||
|
||||
You may skip this step if quickshell crashed while processing a password
|
||||
or other sensitive information. If you skipped it write why instead.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Log file
|
||||
description: |
|
||||
Attach `log.qslog.log` here. If it is too big to upload, compress it.
|
||||
|
||||
You can preview the log if you'd like using `quickshell read-log <path-to-log>`.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: config
|
||||
attributes:
|
||||
label: Configuration
|
||||
description: |
|
||||
Attach your configuration here, preferrably in full (not just one file).
|
||||
Compress it into a zip, tar, etc.
|
||||
|
||||
This will help us reproduce the crash ourselves.
|
||||
- type: textarea
|
||||
id: bt
|
||||
attributes:
|
||||
label: Backtrace
|
||||
description: |
|
||||
If you have gdb installed and use systemd, or otherwise know how to get a backtrace,
|
||||
we would appreciate one. (You may have gdb installed without knowing it)
|
||||
|
||||
1. Run `coredumpctl debug <pid>` where `pid` is the number shown after "Crashed process ID"
|
||||
in the crash reporter.
|
||||
2. Once it loads, type `bt -full` (then enter)
|
||||
3. Copy the output and attach it as a file or in a spoiler.
|
||||
- type: textarea
|
||||
id: exe
|
||||
attributes:
|
||||
label: Executable
|
||||
description: |
|
||||
If the crash folder contains a executable.txt file, upload it here. If not you can ignore this field.
|
||||
If it is too big to upload, compress it.
|
||||
|
||||
Note: executable.txt is the quickshell binary. It has a .txt extension due to github's limitations on
|
||||
filetypes.
|
||||
label: Read the text above. Do not submit the report.
|
||||
options:
|
||||
- label: Yes I want this report to be deleted.
|
||||
required: true
|
||||
@@ -9,21 +9,21 @@ body:
|
||||
description: |
|
||||
Any information likely to help debug the crash. What were you doing when the crash occurred,
|
||||
what changes did you make, can you get it to happen again?
|
||||
- type: textarea
|
||||
- type: upload
|
||||
id: report
|
||||
attributes:
|
||||
label: Report file
|
||||
description: Attach `report.txt` here.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
- type: upload
|
||||
id: logs
|
||||
attributes:
|
||||
label: Log file
|
||||
description: |
|
||||
Attach `log.qslog.log` here. If it is too big to upload, compress it.
|
||||
|
||||
You can preview the log if you'd like using `quickshell read-log <path-to-log>`.
|
||||
You can preview the log if you'd like using `qs log <path-to-log> -r '*=true'`.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -31,7 +31,7 @@ body:
|
||||
attributes:
|
||||
label: Configuration
|
||||
description: |
|
||||
Attach your configuration here, preferrably in full (not just one file).
|
||||
Attach or link your configuration here, preferrably in full (not just one file).
|
||||
Compress it into a zip, tar, etc.
|
||||
|
||||
This will help us reproduce the crash ourselves.
|
||||
|
||||
+7
-2
@@ -1,7 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(quickshell VERSION "0.2.1" LANGUAGES CXX C)
|
||||
|
||||
set(UNRELEASED_FEATURES)
|
||||
set(UNRELEASED_FEATURES
|
||||
"network.2"
|
||||
"colorquant-imagerect"
|
||||
"window-parent"
|
||||
)
|
||||
|
||||
set(QT_MIN_VERSION "6.6.0")
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
@@ -87,8 +91,9 @@ include(cmake/util.cmake)
|
||||
|
||||
add_compile_options(-Wall -Wextra -Wno-vla-cxx-extension)
|
||||
|
||||
# pipewire defines this, breaking PCH
|
||||
# pipewire defines these, breaking PCH
|
||||
add_compile_definitions(_REENTRANT)
|
||||
add_compile_options(-fno-strict-overflow)
|
||||
|
||||
if (FRAME_POINTERS)
|
||||
add_compile_options(-fno-omit-frame-pointer)
|
||||
|
||||
+16
-1
@@ -20,13 +20,17 @@ set shell id.
|
||||
- Added the ability to handle move and resize events to FloatingWindow.
|
||||
- Pipewire service now reconnects if pipewire dies or a protocol error occurs.
|
||||
- Added pipewire audio peak detection.
|
||||
- Added initial support for network management.
|
||||
- Added network management support.
|
||||
- Added support for grabbing focus from popup windows.
|
||||
- Added support for IPC signal listeners.
|
||||
- Added Quickshell version checking and version gated preprocessing.
|
||||
- Added a way to detect if an icon is from the system icon theme or not.
|
||||
- Added vulkan support to screencopy.
|
||||
- Added generic WindowManager interface implementing ext-workspace.
|
||||
- Added ext-background-effect window blur support.
|
||||
- Added per-corner radius support to Region.
|
||||
- Added ColorQuantizer region selection.
|
||||
- Added dialog window support to FloatingWindow.
|
||||
|
||||
## Other Changes
|
||||
|
||||
@@ -38,6 +42,9 @@ set shell id.
|
||||
- Added `QS_DISABLE_FILE_WATCHER` environment variable to disable file watching.
|
||||
- Added `QS_DISABLE_CRASH_HANDLER` environment variable to disable crash handling.
|
||||
- Added `QS_CRASHREPORT_URL` environment variable to allow overriding the crash reporter link.
|
||||
- Added `AppId` pragma and `QS_APP_ID` environment variable to allow overriding the desktop application ID.
|
||||
- Added `DropExpensiveFonts` pragma and `QS_DROP_EXPENSIVE_FONTS` environment variable which avoids loading fonts which may cause lag and excessive memory usage if many variants are used.
|
||||
- Unrecognized pragmas are no longer a hard error for future backward compatibility.
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
@@ -48,6 +55,7 @@ set shell id.
|
||||
- Fixed volumes not initializing if a pipewire device was already loaded before its node.
|
||||
- Fixed hyprland active toplevel not resetting after window closes.
|
||||
- Fixed hyprland ipc window names and titles being reversed.
|
||||
- Fixed a hyprland ipc crash when refreshing toplevels before workspaces.
|
||||
- Fixed missing signals for system tray item title and description updates.
|
||||
- Fixed asynchronous loaders not working after reload.
|
||||
- Fixed asynchronous loaders not working before window creation.
|
||||
@@ -58,6 +66,13 @@ set shell id.
|
||||
- Fixed ToplevelManager not clearing activeToplevel on deactivation.
|
||||
- Desktop action order is now preserved.
|
||||
- Fixed partial socket reads in greetd and hyprland on slow machines.
|
||||
- Worked around Qt bug causing crashes when plugging and unplugging monitors.
|
||||
- Fixed HyprlandFocusGrab crashing if windows were destroyed after being passed to it.
|
||||
- Fixed ScreencopyView pixelation when scaled.
|
||||
- Fixed JsonAdapter crashing and providing bad data on read when using JsonObject.
|
||||
- Fixed JsonAdapter sending unnecessary property changes for primitive values.
|
||||
- Fixed JsonAdapter serialization for lists.
|
||||
- Fixed pipewire crashes after hotplugging devices and changing default outputs.
|
||||
|
||||
## Packaging Changes
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ qt_add_library(quickshell-core STATIC
|
||||
toolsupport.cpp
|
||||
streamreader.cpp
|
||||
debuginfo.cpp
|
||||
hook.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(quickshell-core
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <qnumeric.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qrect.h>
|
||||
#include <qrgb.h>
|
||||
#include <qthreadpool.h>
|
||||
#include <qtmetamacros.h>
|
||||
@@ -24,9 +25,15 @@ namespace {
|
||||
QS_LOGGING_CATEGORY(logColorQuantizer, "quickshell.colorquantizer", QtWarningMsg);
|
||||
}
|
||||
|
||||
ColorQuantizerOperation::ColorQuantizerOperation(QUrl* source, qreal depth, qreal rescaleSize)
|
||||
ColorQuantizerOperation::ColorQuantizerOperation(
|
||||
QUrl* source,
|
||||
qreal depth,
|
||||
QRect imageRect,
|
||||
qreal rescaleSize
|
||||
)
|
||||
: source(source)
|
||||
, maxDepth(depth)
|
||||
, imageRect(imageRect)
|
||||
, rescaleSize(rescaleSize) {
|
||||
this->setAutoDelete(false);
|
||||
}
|
||||
@@ -37,6 +44,11 @@ void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCa
|
||||
this->colors.clear();
|
||||
|
||||
auto image = QImage(this->source->toLocalFile());
|
||||
|
||||
if (this->imageRect.isValid()) {
|
||||
image = image.copy(this->imageRect);
|
||||
}
|
||||
|
||||
if ((image.width() > this->rescaleSize || image.height() > this->rescaleSize)
|
||||
&& this->rescaleSize > 0)
|
||||
{
|
||||
@@ -198,16 +210,27 @@ void ColorQuantizer::setDepth(qreal depth) {
|
||||
this->mDepth = depth;
|
||||
emit this->depthChanged();
|
||||
|
||||
if (this->componentCompleted) this->quantizeAsync();
|
||||
if (this->componentCompleted && !this->mSource.isEmpty()) this->quantizeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void ColorQuantizer::setImageRect(QRect imageRect) {
|
||||
if (this->mImageRect != imageRect) {
|
||||
this->mImageRect = imageRect;
|
||||
emit this->imageRectChanged();
|
||||
|
||||
if (this->componentCompleted && !this->mSource.isEmpty()) this->quantizeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void ColorQuantizer::resetImageRect() { this->setImageRect(QRect()); }
|
||||
|
||||
void ColorQuantizer::setRescaleSize(int rescaleSize) {
|
||||
if (this->mRescaleSize != rescaleSize) {
|
||||
this->mRescaleSize = rescaleSize;
|
||||
emit this->rescaleSizeChanged();
|
||||
|
||||
if (this->componentCompleted) this->quantizeAsync();
|
||||
if (this->componentCompleted && !this->mSource.isEmpty()) this->quantizeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,8 +244,13 @@ void ColorQuantizer::quantizeAsync() {
|
||||
if (this->liveOperation) this->cancelAsync();
|
||||
|
||||
qCDebug(logColorQuantizer) << "Starting color quantization asynchronously";
|
||||
this->liveOperation =
|
||||
new ColorQuantizerOperation(&this->mSource, this->mDepth, this->mRescaleSize);
|
||||
|
||||
this->liveOperation = new ColorQuantizerOperation(
|
||||
&this->mSource,
|
||||
this->mDepth,
|
||||
this->mImageRect,
|
||||
this->mRescaleSize
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->liveOperation,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <qproperty.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qqmlparserstatus.h>
|
||||
#include <qrect.h>
|
||||
#include <qrunnable.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
@@ -16,7 +17,7 @@ class ColorQuantizerOperation
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit ColorQuantizerOperation(QUrl* source, qreal depth, qreal rescaleSize);
|
||||
explicit ColorQuantizerOperation(QUrl* source, qreal depth, QRect imageRect, qreal rescaleSize);
|
||||
|
||||
void run() override;
|
||||
void tryCancel();
|
||||
@@ -44,6 +45,7 @@ private:
|
||||
QList<QColor> colors;
|
||||
QUrl* source;
|
||||
qreal maxDepth;
|
||||
QRect imageRect;
|
||||
qreal rescaleSize;
|
||||
};
|
||||
|
||||
@@ -78,6 +80,13 @@ class ColorQuantizer
|
||||
/// binary split of the color space
|
||||
Q_PROPERTY(qreal depth READ depth WRITE setDepth NOTIFY depthChanged);
|
||||
|
||||
// clang-format off
|
||||
/// Rectangle that the source image is cropped to.
|
||||
///
|
||||
/// Can be set to `undefined` to reset.
|
||||
Q_PROPERTY(QRect imageRect READ imageRect WRITE setImageRect RESET resetImageRect NOTIFY imageRectChanged);
|
||||
// clang-format on
|
||||
|
||||
/// The size to rescale the image to, when rescaleSize is 0 then no scaling will be done.
|
||||
/// > [!NOTE] Results from color quantization doesn't suffer much when rescaling, it's
|
||||
/// > reccommended to rescale, otherwise the quantization process will take much longer.
|
||||
@@ -97,6 +106,10 @@ public:
|
||||
[[nodiscard]] qreal depth() const { return this->mDepth; }
|
||||
void setDepth(qreal depth);
|
||||
|
||||
[[nodiscard]] QRect imageRect() const { return this->mImageRect; }
|
||||
void setImageRect(QRect imageRect);
|
||||
void resetImageRect();
|
||||
|
||||
[[nodiscard]] qreal rescaleSize() const { return this->mRescaleSize; }
|
||||
void setRescaleSize(int rescaleSize);
|
||||
|
||||
@@ -104,6 +117,7 @@ signals:
|
||||
void colorsChanged();
|
||||
void sourceChanged();
|
||||
void depthChanged();
|
||||
void imageRectChanged();
|
||||
void rescaleSizeChanged();
|
||||
|
||||
public slots:
|
||||
@@ -117,6 +131,7 @@ private:
|
||||
ColorQuantizerOperation* liveOperation = nullptr;
|
||||
QUrl mSource;
|
||||
qreal mDepth = 0;
|
||||
QRect mImageRect;
|
||||
qreal mRescaleSize = 0;
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(
|
||||
|
||||
@@ -129,12 +129,13 @@ QString envInfo() {
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
for (auto** envp = environ; *envp != nullptr; ++envp) { // NOLINT
|
||||
auto prefixes = std::array<std::string_view, 5> {
|
||||
auto prefixes = std::array<std::string_view, 6> {
|
||||
"QS_",
|
||||
"QT_",
|
||||
"QML_",
|
||||
"QML2_",
|
||||
"QSG_",
|
||||
"XDG_CURRENT_DESKTOP=",
|
||||
};
|
||||
|
||||
for (const auto& prefix: prefixes) {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
#include <cpptrace/basic.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QEvent>
|
||||
#include <QLoggingCategory>
|
||||
#include <QMetaObject>
|
||||
#include <QObject>
|
||||
|
||||
__attribute__((constructor)) static void initHook() {
|
||||
unsetenv("LD_PRELOAD");
|
||||
}
|
||||
|
||||
Q_LOGGING_CATEGORY(logDestructors, "quickshell.destructors");
|
||||
Q_LOGGING_CATEGORY(logPostEvent, "quickshell.postEvent");
|
||||
|
||||
static std::string traceAddrs() {
|
||||
std::array<cpptrace::frame_ptr, 64> frames{};
|
||||
auto count = cpptrace::safe_generate_raw_trace(frames.data(), frames.size(), 1);
|
||||
std::string result;
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (i > 0) result += ',';
|
||||
char buf[20];
|
||||
snprintf(buf, sizeof(buf), "%p", reinterpret_cast<void*>(frames[i]));
|
||||
result += buf;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
using VoidMemberFn = void (*)(QObject*);
|
||||
|
||||
static VoidMemberFn realD2() {
|
||||
static auto fn = reinterpret_cast<VoidMemberFn>(dlsym(RTLD_NEXT, "_ZN7QObjectD2Ev"));
|
||||
return fn;
|
||||
}
|
||||
|
||||
static VoidMemberFn realDeleteLater() {
|
||||
static auto fn =
|
||||
reinterpret_cast<VoidMemberFn>(dlsym(RTLD_NEXT, "_ZN7QObject11deleteLaterEv"));
|
||||
return fn;
|
||||
}
|
||||
|
||||
using PostEventFn = void (*)(QObject*, QEvent*, int);
|
||||
|
||||
static PostEventFn realPostEvent() {
|
||||
static auto fn = reinterpret_cast<PostEventFn>(
|
||||
dlsym(RTLD_NEXT, "_ZN16QCoreApplication9postEventEP7QObjectP6QEventi")
|
||||
);
|
||||
return fn;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
void _ZN7QObjectD2Ev(QObject* self) {
|
||||
const auto* meta = self->metaObject();
|
||||
auto trace = traceAddrs();
|
||||
qCDebug(logDestructors, "~QObject %p %s\n%s", static_cast<void*>(self), meta->className(), trace.c_str());
|
||||
realD2()(self);
|
||||
}
|
||||
|
||||
void _ZN7QObject11deleteLaterEv(QObject* self) {
|
||||
const auto* meta = self->metaObject();
|
||||
auto trace = traceAddrs();
|
||||
qCDebug(logDestructors, "deleteLater %p %s\n%s", static_cast<void*>(self), meta->className(), trace.c_str());
|
||||
realDeleteLater()(self);
|
||||
}
|
||||
|
||||
void _ZN16QCoreApplication9postEventEP7QObjectP6QEventi(
|
||||
QObject* receiver,
|
||||
QEvent* event,
|
||||
int priority
|
||||
) {
|
||||
//if (event->type() == QEvent::User + 1) {
|
||||
const auto* meta = receiver->metaObject();
|
||||
auto trace = traceAddrs();
|
||||
qCDebug(logPostEvent, "%p %d %s\n%s", static_cast<void*>(receiver), event->type(), meta->className(), trace.c_str());
|
||||
//}
|
||||
realPostEvent()(receiver, event, priority);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -3,14 +3,14 @@
|
||||
#include <qdatastream.h>
|
||||
|
||||
QDataStream& operator<<(QDataStream& stream, const InstanceInfo& info) {
|
||||
stream << info.instanceId << info.configPath << info.shellId << info.launchTime << info.pid
|
||||
<< info.display;
|
||||
stream << info.instanceId << info.configPath << info.shellId << info.appId << info.launchTime
|
||||
<< info.pid << info.display;
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& stream, InstanceInfo& info) {
|
||||
stream >> info.instanceId >> info.configPath >> info.shellId >> info.launchTime >> info.pid
|
||||
>> info.display;
|
||||
stream >> info.instanceId >> info.configPath >> info.shellId >> info.appId >> info.launchTime
|
||||
>> info.pid >> info.display;
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ struct InstanceInfo {
|
||||
QString instanceId;
|
||||
QString configPath;
|
||||
QString shellId;
|
||||
QString appId;
|
||||
QDateTime launchTime;
|
||||
pid_t pid = -1;
|
||||
QString display;
|
||||
|
||||
+13
-3
@@ -14,6 +14,7 @@
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qmutex.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
@@ -31,6 +32,9 @@
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "instanceinfo.hpp"
|
||||
#include "logcat.hpp"
|
||||
@@ -67,7 +71,7 @@ bool copyFileData(int sourceFd, int destFd, qint64 size) {
|
||||
return true;
|
||||
#else
|
||||
std::array<char, 64 * 1024> buffer = {};
|
||||
auto remaining = totalTarget;
|
||||
auto remaining = usize;
|
||||
|
||||
while (remaining > 0) {
|
||||
auto chunk = std::min(remaining, buffer.size());
|
||||
@@ -217,6 +221,7 @@ void LogManager::messageHandler(
|
||||
}
|
||||
|
||||
if (display) {
|
||||
auto locker = QMutexLocker(&self->stdoutMutex);
|
||||
LogMessage::formatMessage(
|
||||
self->stdoutStream,
|
||||
message,
|
||||
@@ -305,10 +310,15 @@ void LogManager::init(
|
||||
instance->rules->append(parser.rules());
|
||||
}
|
||||
|
||||
qInstallMessageHandler(&LogManager::messageHandler);
|
||||
|
||||
instance->lastCategoryFilter = QLoggingCategory::installFilter(&LogManager::filterCategory);
|
||||
|
||||
if (instance->lastCategoryFilter == &LogManager::filterCategory) {
|
||||
qCFatal(logLogging) << "Quickshell's log filter has been installed twice. This is a bug.";
|
||||
instance->lastCategoryFilter = nullptr;
|
||||
}
|
||||
|
||||
qInstallMessageHandler(&LogManager::messageHandler);
|
||||
|
||||
qCDebug(logLogging) << "Creating offthread logger...";
|
||||
auto* thread = new QThread();
|
||||
instance->threadProxy.moveToThread(thread);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <qlatin1stringview.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qmutex.h>
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
@@ -135,6 +136,7 @@ private:
|
||||
QHash<QLatin1StringView, CategoryFilter> allFilters;
|
||||
|
||||
QTextStream stdoutStream;
|
||||
QMutex stdoutMutex;
|
||||
LoggingThreadProxy threadProxy;
|
||||
|
||||
friend void initLogCategoryLevel(const char* name, QtMsgType defaultLevel);
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ QDir* QsPaths::baseRunDir() {
|
||||
if (this->baseRunState == DirState::Unknown) {
|
||||
auto runtimeDir = qEnvironmentVariable("XDG_RUNTIME_DIR");
|
||||
if (runtimeDir.isEmpty()) {
|
||||
runtimeDir = QString("/run/user/$1").arg(getuid());
|
||||
runtimeDir = QString("/run/user/%1").arg(getuid());
|
||||
qCInfo(logPaths) << "XDG_RUNTIME_DIR was not set, defaulting to" << runtimeDir;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <qwindow.h>
|
||||
|
||||
#include "../window/proxywindow.hpp"
|
||||
#include "../window/windowinterface.hpp"
|
||||
#include "iconprovider.hpp"
|
||||
#include "model.hpp"
|
||||
#include "platformmenu_p.hpp"
|
||||
@@ -91,10 +90,8 @@ bool PlatformMenuEntry::display(QObject* parentWindow, int relativeX, int relati
|
||||
} else if (parentWindow == nullptr) {
|
||||
qCritical() << "Cannot display PlatformMenuEntry with null parent window.";
|
||||
return false;
|
||||
} else if (auto* proxy = qobject_cast<ProxyWindowBase*>(parentWindow)) {
|
||||
} else if (auto* proxy = ProxyWindowBase::forObject(parentWindow)) {
|
||||
window = proxy->backingWindow();
|
||||
} else if (auto* interface = qobject_cast<WindowInterface*>(parentWindow)) {
|
||||
window = interface->proxyWindow()->backingWindow();
|
||||
} else {
|
||||
qCritical() << "PlatformMenuEntry.display() must be called with a window.";
|
||||
return false;
|
||||
|
||||
@@ -9,6 +9,18 @@ static QVector<QsEnginePlugin*> plugins; // NOLINT
|
||||
|
||||
void QsEnginePlugin::registerPlugin(QsEnginePlugin& plugin) { plugins.push_back(&plugin); }
|
||||
|
||||
void QsEnginePlugin::preinitPluginsOnly() {
|
||||
plugins.removeIf([](QsEnginePlugin* plugin) { return !plugin->applies(); });
|
||||
|
||||
std::ranges::sort(plugins, [](QsEnginePlugin* a, QsEnginePlugin* b) {
|
||||
return b->dependencies().contains(a->name());
|
||||
});
|
||||
|
||||
for (QsEnginePlugin* plugin: plugins) {
|
||||
plugin->preinit();
|
||||
}
|
||||
}
|
||||
|
||||
void QsEnginePlugin::initPlugins() {
|
||||
plugins.removeIf([](QsEnginePlugin* plugin) { return !plugin->applies(); });
|
||||
|
||||
@@ -16,6 +28,10 @@ void QsEnginePlugin::initPlugins() {
|
||||
return b->dependencies().contains(a->name());
|
||||
});
|
||||
|
||||
for (QsEnginePlugin* plugin: plugins) {
|
||||
plugin->preinit();
|
||||
}
|
||||
|
||||
for (QsEnginePlugin* plugin: plugins) {
|
||||
plugin->init();
|
||||
}
|
||||
|
||||
@@ -18,12 +18,14 @@ public:
|
||||
virtual QString name() { return QString(); }
|
||||
virtual QList<QString> dependencies() { return {}; }
|
||||
virtual bool applies() { return true; }
|
||||
virtual void preinit() {}
|
||||
virtual void init() {}
|
||||
virtual void registerTypes() {}
|
||||
virtual void constructGeneration(EngineGeneration& /*unused*/) {} // NOLINT
|
||||
virtual void onReload() {}
|
||||
|
||||
static void registerPlugin(QsEnginePlugin& plugin);
|
||||
static void preinitPluginsOnly();
|
||||
static void initPlugins();
|
||||
static void runConstructGeneration(EngineGeneration& generation);
|
||||
static void runOnReload();
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <qwindow.h>
|
||||
|
||||
#include "../window/proxywindow.hpp"
|
||||
#include "../window/windowinterface.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
bool PopupAnchorState::operator==(const PopupAnchorState& other) const {
|
||||
@@ -40,10 +39,8 @@ void PopupAnchor::setWindowInternal(QObject* window) {
|
||||
}
|
||||
|
||||
if (window) {
|
||||
if (auto* proxy = qobject_cast<ProxyWindowBase*>(window)) {
|
||||
if (auto* proxy = ProxyWindowBase::forObject(window)) {
|
||||
this->bProxyWindow = proxy;
|
||||
} else if (auto* interface = qobject_cast<WindowInterface*>(window)) {
|
||||
this->bProxyWindow = interface->proxyWindow();
|
||||
} else {
|
||||
qWarning() << "Tried to set popup anchor window to" << window
|
||||
<< "which is not a quickshell window.";
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "../io/processcore.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "iconimageprovider.hpp"
|
||||
#include "instanceinfo.hpp"
|
||||
#include "paths.hpp"
|
||||
#include "qmlscreen.hpp"
|
||||
#include "rootwrapper.hpp"
|
||||
@@ -153,6 +154,22 @@ qint32 QuickshellGlobal::processId() const { // NOLINT
|
||||
return getpid();
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::instanceId() const { // NOLINT
|
||||
return InstanceInfo::CURRENT.instanceId;
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::shellId() const { // NOLINT
|
||||
return InstanceInfo::CURRENT.shellId;
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::appId() const { // NOLINT
|
||||
return InstanceInfo::CURRENT.appId;
|
||||
}
|
||||
|
||||
QDateTime QuickshellGlobal::launchTime() const { // NOLINT
|
||||
return InstanceInfo::CURRENT.launchTime;
|
||||
}
|
||||
|
||||
qsizetype QuickshellGlobal::screensCount(QQmlListProperty<QuickshellScreenInfo>* /*unused*/) {
|
||||
return QuickshellTracked::instance()->screens.size();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "../io/processcore.hpp"
|
||||
#include "doc.hpp"
|
||||
#include "instanceinfo.hpp"
|
||||
#include "qmlscreen.hpp"
|
||||
|
||||
///! Accessor for some options under the Quickshell type.
|
||||
@@ -83,6 +84,21 @@ class QuickshellGlobal: public QObject {
|
||||
// clang-format off
|
||||
/// Quickshell's process id.
|
||||
Q_PROPERTY(qint32 processId READ processId CONSTANT);
|
||||
/// A unique identifier for this Quickshell instance
|
||||
Q_PROPERTY(QString instanceId READ instanceId CONSTANT)
|
||||
/// The shell ID, used to differentiate between different shell configurations.
|
||||
///
|
||||
/// Defaults to a stable value derived from the config path.
|
||||
/// Can be overridden with `//@ pragma ShellId <id>` in the root qml file.
|
||||
Q_PROPERTY(QString shellId READ shellId CONSTANT)
|
||||
/// The desktop application ID.
|
||||
///
|
||||
/// Defaults to `org.quickshell`.
|
||||
/// Can be overridden with `//@ pragma AppId <id>` in the root qml file
|
||||
/// or the `QS_APP_ID` environment variable.
|
||||
Q_PROPERTY(QString appId READ appId CONSTANT)
|
||||
/// The time at which this Quickshell instance was launched.
|
||||
Q_PROPERTY(QDateTime launchTime READ launchTime CONSTANT)
|
||||
/// All currently connected screens.
|
||||
///
|
||||
/// This property updates as connected screens change.
|
||||
@@ -149,6 +165,10 @@ class QuickshellGlobal: public QObject {
|
||||
|
||||
public:
|
||||
[[nodiscard]] qint32 processId() const;
|
||||
[[nodiscard]] QString instanceId() const;
|
||||
[[nodiscard]] QString shellId() const;
|
||||
[[nodiscard]] QString appId() const;
|
||||
[[nodiscard]] QDateTime launchTime() const;
|
||||
|
||||
QQmlListProperty<QuickshellScreenInfo> screens();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "region.hpp"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <qobject.h>
|
||||
@@ -18,6 +19,11 @@ PendingRegion::PendingRegion(QObject* parent): QObject(parent) {
|
||||
QObject::connect(this, &PendingRegion::yChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::widthChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::heightChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::radiusChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::topLeftRadiusChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::topRightRadiusChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::bottomLeftRadiusChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::bottomRightRadiusChanged, this, &PendingRegion::changed);
|
||||
QObject::connect(this, &PendingRegion::childrenChanged, this, &PendingRegion::changed);
|
||||
}
|
||||
|
||||
@@ -45,6 +51,79 @@ void PendingRegion::onItemDestroyed() { this->mItem = nullptr; }
|
||||
|
||||
void PendingRegion::onChildDestroyed() { this->mRegions.removeAll(this->sender()); }
|
||||
|
||||
qint32 PendingRegion::radius() const { return this->mRadius; }
|
||||
|
||||
void PendingRegion::setRadius(qint32 radius) {
|
||||
if (radius == this->mRadius) return;
|
||||
this->mRadius = radius;
|
||||
emit this->radiusChanged();
|
||||
|
||||
if (!(this->mCornerOverrides & TopLeft)) emit this->topLeftRadiusChanged();
|
||||
if (!(this->mCornerOverrides & TopRight)) emit this->topRightRadiusChanged();
|
||||
if (!(this->mCornerOverrides & BottomLeft)) emit this->bottomLeftRadiusChanged();
|
||||
if (!(this->mCornerOverrides & BottomRight)) emit this->bottomRightRadiusChanged();
|
||||
}
|
||||
|
||||
qint32 PendingRegion::topLeftRadius() const {
|
||||
return (this->mCornerOverrides & TopLeft) ? this->mTopLeftRadius : this->mRadius;
|
||||
}
|
||||
|
||||
void PendingRegion::setTopLeftRadius(qint32 radius) {
|
||||
this->mTopLeftRadius = radius;
|
||||
this->mCornerOverrides |= TopLeft;
|
||||
emit this->topLeftRadiusChanged();
|
||||
}
|
||||
|
||||
void PendingRegion::resetTopLeftRadius() {
|
||||
this->mCornerOverrides &= ~TopLeft;
|
||||
emit this->topLeftRadiusChanged();
|
||||
}
|
||||
|
||||
qint32 PendingRegion::topRightRadius() const {
|
||||
return (this->mCornerOverrides & TopRight) ? this->mTopRightRadius : this->mRadius;
|
||||
}
|
||||
|
||||
void PendingRegion::setTopRightRadius(qint32 radius) {
|
||||
this->mTopRightRadius = radius;
|
||||
this->mCornerOverrides |= TopRight;
|
||||
emit this->topRightRadiusChanged();
|
||||
}
|
||||
|
||||
void PendingRegion::resetTopRightRadius() {
|
||||
this->mCornerOverrides &= ~TopRight;
|
||||
emit this->topRightRadiusChanged();
|
||||
}
|
||||
|
||||
qint32 PendingRegion::bottomLeftRadius() const {
|
||||
return (this->mCornerOverrides & BottomLeft) ? this->mBottomLeftRadius : this->mRadius;
|
||||
}
|
||||
|
||||
void PendingRegion::setBottomLeftRadius(qint32 radius) {
|
||||
this->mBottomLeftRadius = radius;
|
||||
this->mCornerOverrides |= BottomLeft;
|
||||
emit this->bottomLeftRadiusChanged();
|
||||
}
|
||||
|
||||
void PendingRegion::resetBottomLeftRadius() {
|
||||
this->mCornerOverrides &= ~BottomLeft;
|
||||
emit this->bottomLeftRadiusChanged();
|
||||
}
|
||||
|
||||
qint32 PendingRegion::bottomRightRadius() const {
|
||||
return (this->mCornerOverrides & BottomRight) ? this->mBottomRightRadius : this->mRadius;
|
||||
}
|
||||
|
||||
void PendingRegion::setBottomRightRadius(qint32 radius) {
|
||||
this->mBottomRightRadius = radius;
|
||||
this->mCornerOverrides |= BottomRight;
|
||||
emit this->bottomRightRadiusChanged();
|
||||
}
|
||||
|
||||
void PendingRegion::resetBottomRightRadius() {
|
||||
this->mCornerOverrides &= ~BottomRight;
|
||||
emit this->bottomRightRadiusChanged();
|
||||
}
|
||||
|
||||
QQmlListProperty<PendingRegion> PendingRegion::regions() {
|
||||
return QQmlListProperty<PendingRegion>(
|
||||
this,
|
||||
@@ -90,6 +169,60 @@ QRegion PendingRegion::build() const {
|
||||
region = QRegion(this->mX, this->mY, this->mWidth, this->mHeight, type);
|
||||
}
|
||||
|
||||
if (this->mShape == RegionShape::Rect && !region.isEmpty()) {
|
||||
auto tl = std::max(this->topLeftRadius(), 0);
|
||||
auto tr = std::max(this->topRightRadius(), 0);
|
||||
auto bl = std::max(this->bottomLeftRadius(), 0);
|
||||
auto br = std::max(this->bottomRightRadius(), 0);
|
||||
|
||||
if (tl > 0 || tr > 0 || bl > 0 || br > 0) {
|
||||
auto rect = region.boundingRect();
|
||||
auto x = rect.x();
|
||||
auto y = rect.y();
|
||||
auto w = rect.width();
|
||||
auto h = rect.height();
|
||||
|
||||
// Normalize so adjacent corners don't exceed their shared edge.
|
||||
// Each corner is scaled by the tightest constraint of its two edges.
|
||||
auto topScale = tl + tr > w ? static_cast<double>(w) / (tl + tr) : 1.0;
|
||||
auto bottomScale = bl + br > w ? static_cast<double>(w) / (bl + br) : 1.0;
|
||||
auto leftScale = tl + bl > h ? static_cast<double>(h) / (tl + bl) : 1.0;
|
||||
auto rightScale = tr + br > h ? static_cast<double>(h) / (tr + br) : 1.0;
|
||||
|
||||
tl = static_cast<qint32>(tl * std::min(topScale, leftScale));
|
||||
tr = static_cast<qint32>(tr * std::min(topScale, rightScale));
|
||||
bl = static_cast<qint32>(bl * std::min(bottomScale, leftScale));
|
||||
br = static_cast<qint32>(br * std::min(bottomScale, rightScale));
|
||||
|
||||
// Unlock each corner: subtract (cornerBox - quarterEllipse) from the
|
||||
// full rect. Each corner only modifies pixels inside its own box,
|
||||
// so no diagonal overlap is possible.
|
||||
if (tl > 0) {
|
||||
auto box = QRegion(x, y, tl, tl);
|
||||
auto ellipse = QRegion(x, y, tl * 2, tl * 2, QRegion::Ellipse);
|
||||
region -= box - (ellipse & box);
|
||||
}
|
||||
|
||||
if (tr > 0) {
|
||||
auto box = QRegion(x + w - tr, y, tr, tr);
|
||||
auto ellipse = QRegion(x + w - tr * 2, y, tr * 2, tr * 2, QRegion::Ellipse);
|
||||
region -= box - (ellipse & box);
|
||||
}
|
||||
|
||||
if (bl > 0) {
|
||||
auto box = QRegion(x, y + h - bl, bl, bl);
|
||||
auto ellipse = QRegion(x, y + h - bl * 2, bl * 2, bl * 2, QRegion::Ellipse);
|
||||
region -= box - (ellipse & box);
|
||||
}
|
||||
|
||||
if (br > 0) {
|
||||
auto box = QRegion(x + w - br, y + h - br, br, br);
|
||||
auto ellipse = QRegion(x + w - br * 2, y + h - br * 2, br * 2, br * 2, QRegion::Ellipse);
|
||||
region -= box - (ellipse & box);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& childRegion: this->mRegions) {
|
||||
region = childRegion->applyTo(region);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,29 @@ class PendingRegion: public QObject {
|
||||
Q_PROPERTY(qint32 width MEMBER mWidth NOTIFY widthChanged);
|
||||
/// Defaults to 0. Does nothing if @@item is set.
|
||||
Q_PROPERTY(qint32 height MEMBER mHeight NOTIFY heightChanged);
|
||||
// clang-format off
|
||||
/// Corner radius for rounded rectangles. Only applies when @@shape is `Rect`. Defaults to 0.
|
||||
///
|
||||
/// Acts as the default for @@topLeftRadius, @@topRightRadius, @@bottomLeftRadius,
|
||||
/// and @@bottomRightRadius.
|
||||
Q_PROPERTY(qint32 radius READ radius WRITE setRadius NOTIFY radiusChanged);
|
||||
/// Top-left corner radius. Only applies when @@shape is `Rect`.
|
||||
///
|
||||
/// Defaults to @@radius, and may be reset by assigning `undefined`.
|
||||
Q_PROPERTY(qint32 topLeftRadius READ topLeftRadius WRITE setTopLeftRadius RESET resetTopLeftRadius NOTIFY topLeftRadiusChanged);
|
||||
/// Top-right corner radius. Only applies when @@shape is `Rect`.
|
||||
///
|
||||
/// Defaults to @@radius, and may be reset by assigning `undefined`.
|
||||
Q_PROPERTY(qint32 topRightRadius READ topRightRadius WRITE setTopRightRadius RESET resetTopRightRadius NOTIFY topRightRadiusChanged);
|
||||
/// Bottom-left corner radius. Only applies when @@shape is `Rect`.
|
||||
///
|
||||
/// Defaults to @@radius, and may be reset by assigning `undefined`.
|
||||
Q_PROPERTY(qint32 bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius RESET resetBottomLeftRadius NOTIFY bottomLeftRadiusChanged);
|
||||
/// Bottom-right corner radius. Only applies when @@shape is `Rect`.
|
||||
///
|
||||
/// Defaults to @@radius, and may be reset by assigning `undefined`.
|
||||
Q_PROPERTY(qint32 bottomRightRadius READ bottomRightRadius WRITE setBottomRightRadius RESET resetBottomRightRadius NOTIFY bottomRightRadiusChanged);
|
||||
// clang-format on
|
||||
|
||||
/// Regions to apply on top of this region.
|
||||
///
|
||||
@@ -91,6 +114,25 @@ public:
|
||||
|
||||
void setItem(QQuickItem* item);
|
||||
|
||||
[[nodiscard]] qint32 radius() const;
|
||||
void setRadius(qint32 radius);
|
||||
|
||||
[[nodiscard]] qint32 topLeftRadius() const;
|
||||
void setTopLeftRadius(qint32 radius);
|
||||
void resetTopLeftRadius();
|
||||
|
||||
[[nodiscard]] qint32 topRightRadius() const;
|
||||
void setTopRightRadius(qint32 radius);
|
||||
void resetTopRightRadius();
|
||||
|
||||
[[nodiscard]] qint32 bottomLeftRadius() const;
|
||||
void setBottomLeftRadius(qint32 radius);
|
||||
void resetBottomLeftRadius();
|
||||
|
||||
[[nodiscard]] qint32 bottomRightRadius() const;
|
||||
void setBottomRightRadius(qint32 radius);
|
||||
void resetBottomRightRadius();
|
||||
|
||||
QQmlListProperty<PendingRegion> regions();
|
||||
|
||||
[[nodiscard]] bool empty() const;
|
||||
@@ -109,6 +151,11 @@ signals:
|
||||
void yChanged();
|
||||
void widthChanged();
|
||||
void heightChanged();
|
||||
void radiusChanged();
|
||||
void topLeftRadiusChanged();
|
||||
void topRightRadiusChanged();
|
||||
void bottomLeftRadiusChanged();
|
||||
void bottomRightRadiusChanged();
|
||||
void childrenChanged();
|
||||
|
||||
/// Triggered when the region's geometry changes.
|
||||
@@ -130,12 +177,25 @@ private:
|
||||
static void
|
||||
regionsReplace(QQmlListProperty<PendingRegion>* prop, qsizetype i, PendingRegion* region);
|
||||
|
||||
enum CornerOverride : quint8 {
|
||||
TopLeft = 0b1,
|
||||
TopRight = 0b10,
|
||||
BottomLeft = 0b100,
|
||||
BottomRight = 0b1000,
|
||||
};
|
||||
|
||||
QQuickItem* mItem = nullptr;
|
||||
|
||||
qint32 mX = 0;
|
||||
qint32 mY = 0;
|
||||
qint32 mWidth = 0;
|
||||
qint32 mHeight = 0;
|
||||
qint32 mRadius = 0;
|
||||
qint32 mTopLeftRadius = 0;
|
||||
qint32 mTopRightRadius = 0;
|
||||
qint32 mBottomLeftRadius = 0;
|
||||
qint32 mBottomRightRadius = 0;
|
||||
quint8 mCornerOverrides = 0;
|
||||
|
||||
QList<PendingRegion*> mRegions;
|
||||
};
|
||||
+11
-4
@@ -145,10 +145,7 @@ bool QmlScanner::scanQmlFile(const QString& path, bool& singleton, bool& interna
|
||||
QString overrideText;
|
||||
bool isOverridden = false;
|
||||
|
||||
auto pragmaEngine = QJSEngine();
|
||||
pragmaEngine.globalObject().setPrototype(
|
||||
pragmaEngine.newQObject(new qs::scan::env::PreprocEnv())
|
||||
);
|
||||
auto& pragmaEngine = *QmlScanner::preprocEngine();
|
||||
|
||||
auto postError = [&, this](QString error) {
|
||||
this->scanErrors.append({.file = path, .message = std::move(error), .line = lineNum});
|
||||
@@ -370,3 +367,13 @@ QPair<QString, QString> QmlScanner::jsonToQml(const QJsonValue& value, int inden
|
||||
return qMakePair(QStringLiteral("var"), "null");
|
||||
}
|
||||
}
|
||||
|
||||
QJSEngine* QmlScanner::preprocEngine() {
|
||||
static auto* engine = [] {
|
||||
auto* engine = new QJSEngine();
|
||||
engine->globalObject().setPrototype(engine->newQObject(new qs::scan::env::PreprocEnv()));
|
||||
return engine;
|
||||
}();
|
||||
|
||||
return engine;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdir.h>
|
||||
#include <qhash.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qvector.h>
|
||||
|
||||
@@ -42,4 +43,6 @@ private:
|
||||
bool scanQmlFile(const QString& path, bool& singleton, bool& internal);
|
||||
bool scanQmlJson(const QString& path);
|
||||
[[nodiscard]] static QPair<QString, QString> jsonToQml(const QJsonValue& value, int indent = 0);
|
||||
|
||||
static QJSEngine* preprocEngine();
|
||||
};
|
||||
@@ -177,6 +177,8 @@ void QmlToolingSupport::updateToolingFs(
|
||||
auto fileInfo = QFileInfo(path);
|
||||
if (!fileInfo.isFile()) continue;
|
||||
|
||||
if (scanner.fileIntercepts.contains(path)) continue;
|
||||
|
||||
auto spath = linkDir.filePath(name);
|
||||
auto sFileInfo = QFileInfo(spath);
|
||||
|
||||
@@ -205,8 +207,10 @@ void QmlToolingSupport::updateToolingFs(
|
||||
}
|
||||
|
||||
auto spath = linkDir.filePath(name);
|
||||
QFile::remove(spath);
|
||||
|
||||
auto file = QFile(spath);
|
||||
if (!file.open(QFile::ReadWrite | QFile::Text)) {
|
||||
if (!file.open(QFile::ReadWrite | QFile::Text | QFile::NewOnly)) {
|
||||
qCCritical(logTooling) << "Failed to open injected file" << spath;
|
||||
continue;
|
||||
}
|
||||
|
||||
+26
-6
@@ -5,9 +5,11 @@
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
|
||||
#include <cpptrace/basic.hpp>
|
||||
#include <cpptrace/forward.hpp>
|
||||
#include <cpptrace/utils.hpp>
|
||||
#include <qdatastream.h>
|
||||
#include <qfile.h>
|
||||
#include <qlogging.h>
|
||||
@@ -58,6 +60,12 @@ void signalHandler(
|
||||
siginfo_t* /*info*/, // NOLINT (misc-include-cleaner)
|
||||
void* /*context*/
|
||||
) {
|
||||
// NOLINTBEGIN (misc-include-cleaner)
|
||||
sigset_t set;
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_UNBLOCK, &set, nullptr);
|
||||
// NOLINTEND
|
||||
|
||||
if (CrashInfo::INSTANCE.traceFd != -1) {
|
||||
auto traceBuffer = std::array<cpptrace::frame_ptr, 1024>();
|
||||
auto frameCount = cpptrace::safe_generate_raw_trace(traceBuffer.data(), traceBuffer.size(), 1);
|
||||
@@ -79,13 +87,9 @@ void signalHandler(
|
||||
fail:;
|
||||
}
|
||||
|
||||
// TODO: coredump fork and crash reporter remain as zombies, fix
|
||||
auto coredumpPid = fork();
|
||||
if (coredumpPid == 0) {
|
||||
// NOLINTBEGIN (misc-include-cleaner)
|
||||
sigset_t set;
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_UNBLOCK, &set, nullptr);
|
||||
// NOLINTEND
|
||||
raise(sig);
|
||||
_exit(-1);
|
||||
}
|
||||
@@ -131,7 +135,6 @@ void signalHandler(
|
||||
perror("Failed to fork and launch crash reporter.\n");
|
||||
_exit(-1);
|
||||
} else if (pid == 0) {
|
||||
|
||||
// dup to remove CLOEXEC
|
||||
auto dumpFdStr = std::array<char, 48>();
|
||||
auto logFdStr = std::array<char, 48>();
|
||||
@@ -155,6 +158,21 @@ void signalHandler(
|
||||
}
|
||||
}
|
||||
|
||||
void handleCppTerminate() {
|
||||
if (auto ptr = std::current_exception()) {
|
||||
try {
|
||||
std::rethrow_exception(ptr);
|
||||
} catch (std::exception& e) {
|
||||
qFatal().nospace() << "Terminate called with C++ exception ("
|
||||
<< cpptrace::demangle(typeid(e).name()).data() << "): " << e.what();
|
||||
} catch (...) {
|
||||
qFatal() << "Terminate called with non exception object";
|
||||
}
|
||||
}
|
||||
|
||||
qFatal() << "Terminate called without active C++ exception";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void CrashHandler::init() {
|
||||
@@ -203,6 +221,8 @@ void CrashHandler::init() {
|
||||
|
||||
// NOLINTEND (misc-include-cleaner)
|
||||
|
||||
std::set_terminate(&handleCppTerminate);
|
||||
|
||||
qCInfo(logCrashHandler) << "Crash handler initialized.";
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -25,6 +25,7 @@
|
||||
#include "../core/logging.hpp"
|
||||
#include "../core/logging_p.hpp"
|
||||
#include "../core/paths.hpp"
|
||||
#include "../core/plugin.hpp"
|
||||
#include "../core/ringbuf.hpp"
|
||||
#include "interface.hpp"
|
||||
|
||||
@@ -230,12 +231,17 @@ void qsCheckCrash(int argc, char** argv) {
|
||||
);
|
||||
|
||||
auto app = QApplication(argc, argv);
|
||||
QApplication::setDesktopFileName("org.quickshell");
|
||||
auto desktopId =
|
||||
info.instance.appId.isEmpty() ? QStringLiteral("org.quickshell") : info.instance.appId;
|
||||
QApplication::setDesktopFileName(desktopId);
|
||||
|
||||
auto crashDir = QsPaths::crashDir(info.instance.instanceId);
|
||||
|
||||
qCInfo(logCrashReporter) << "Starting crash reporter...";
|
||||
|
||||
// Required platform compatibility hooks
|
||||
QsEnginePlugin::preinitPluginsOnly();
|
||||
|
||||
recordCrashInfo(crashDir, info.instance);
|
||||
|
||||
auto gui = CrashReporterGui(crashDir.path(), crashProc);
|
||||
|
||||
+53
-16
@@ -1,11 +1,13 @@
|
||||
#include "jsonadapter.hpp"
|
||||
|
||||
#include <qassociativeiterable.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qjsonarray.h>
|
||||
#include <qjsondocument.h>
|
||||
#include <qjsonobject.h>
|
||||
#include <qjsonvalue.h>
|
||||
#include <qjsvalue.h>
|
||||
#include <qmetacontainer.h>
|
||||
#include <qmetaobject.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
@@ -14,6 +16,7 @@
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmlinfo.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qsequentialiterable.h>
|
||||
#include <qstringview.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
@@ -131,13 +134,22 @@ QJsonObject JsonAdapter::serializeRec(const QObject* obj, const QMetaObject* bas
|
||||
}
|
||||
|
||||
json.insert(prop.name(), array);
|
||||
} else if (val.canConvert<QJSValue>()) {
|
||||
auto variant = val.value<QJSValue>().toVariant();
|
||||
auto jv = QJsonValue::fromVariant(variant);
|
||||
json.insert(prop.name(), jv);
|
||||
} else {
|
||||
auto jv = QJsonValue::fromVariant(val);
|
||||
json.insert(prop.name(), jv);
|
||||
if (val.canConvert<QJSValue>()) val = val.value<QJSValue>().toVariant();
|
||||
|
||||
auto jsonVal = QJsonValue::fromVariant(val);
|
||||
|
||||
if (jsonVal.isNull() && !val.isNull() && val.isValid()) {
|
||||
if (val.canConvert<QAssociativeIterable>()) {
|
||||
val.convert(QMetaType::fromType<QVariantMap>());
|
||||
} else if (val.canConvert<QSequentialIterable>()) {
|
||||
val.convert(QMetaType::fromType<QVariantList>());
|
||||
}
|
||||
|
||||
jsonVal = QJsonValue::fromVariant(val);
|
||||
}
|
||||
|
||||
json.insert(prop.name(), jsonVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,14 +166,16 @@ void JsonAdapter::deserializeRec(const QJsonObject& json, QObject* obj, const QM
|
||||
auto jval = json.value(prop.name());
|
||||
|
||||
if (prop.metaType() == QMetaType::fromType<QVariant>()) {
|
||||
auto variant = jval.toVariant();
|
||||
auto oldValue = prop.read(this).value<QJSValue>();
|
||||
auto newVariant = jval.toVariant();
|
||||
auto oldValue = prop.read(obj);
|
||||
auto oldVariant =
|
||||
oldValue.canConvert<QJSValue>() ? oldValue.value<QJSValue>().toVariant() : oldValue;
|
||||
|
||||
// Calling prop.write with a new QJSValue will cause a property update
|
||||
// even if content is identical.
|
||||
if (jval.toVariant() != oldValue.toVariant()) {
|
||||
auto jsValue = qmlEngine(this)->fromVariant<QJSValue>(jval.toVariant());
|
||||
prop.write(this, QVariant::fromValue(jsValue));
|
||||
if (newVariant != oldVariant) {
|
||||
auto jsValue = qmlEngine(this)->fromVariant<QJSValue>(newVariant);
|
||||
prop.write(obj, QVariant::fromValue(jsValue));
|
||||
}
|
||||
} else if (QMetaType::canView(prop.metaType(), QMetaType::fromType<JsonObject*>())) {
|
||||
// FIXME: This doesn't support creating descendants of JsonObject, as QMetaType.metaObject()
|
||||
@@ -196,7 +210,7 @@ void JsonAdapter::deserializeRec(const QJsonObject& json, QObject* obj, const QM
|
||||
QMetaType::fromType<QQmlListProperty<JsonObject>>()
|
||||
))
|
||||
{
|
||||
auto pval = prop.read(this);
|
||||
auto pval = prop.read(obj);
|
||||
|
||||
if (pval.canConvert<QQmlListProperty<JsonObject>>()) {
|
||||
auto lp = pval.value<QQmlListProperty<JsonObject>>();
|
||||
@@ -247,12 +261,35 @@ void JsonAdapter::deserializeRec(const QJsonObject& json, QObject* obj, const QM
|
||||
}
|
||||
} else {
|
||||
auto variant = jval.toVariant();
|
||||
auto convVariant = variant;
|
||||
|
||||
if (variant.convert(prop.metaType())) {
|
||||
prop.write(obj, variant);
|
||||
if (convVariant.convert(prop.metaType())) {
|
||||
prop.write(obj, convVariant);
|
||||
} else {
|
||||
qmlWarning(this) << "Failed to deserialize property " << prop.name() << ": expected "
|
||||
<< prop.metaType().name() << " but got " << jval.toVariant().typeName();
|
||||
auto pval = prop.read(obj);
|
||||
if (variant.canConvert<QSequentialIterable>() && pval.canView<QSequentialIterable>()) {
|
||||
auto targetv = QVariant(pval.metaType());
|
||||
auto target = targetv.view<QSequentialIterable>().metaContainer();
|
||||
auto valueType = target.valueMetaType();
|
||||
auto i = 0;
|
||||
|
||||
for (QVariant item: variant.value<QSequentialIterable>()) {
|
||||
if (item.convert(valueType)) {
|
||||
target.addValueAtEnd(targetv.data(), item.constData());
|
||||
} else {
|
||||
qmlWarning(this) << "Failed to deserialize list member " << i << " of property "
|
||||
<< prop.name() << ": expected " << valueType.name() << " but got "
|
||||
<< item.typeName();
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
prop.write(obj, targetv);
|
||||
} else {
|
||||
qmlWarning(this) << "Failed to deserialize property " << prop.name() << ": expected "
|
||||
<< prop.metaType().name() << " but got "
|
||||
<< jval.toVariant().typeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+52
-3
@@ -76,6 +76,8 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
bool useSystemStyle = false;
|
||||
QString iconTheme = qEnvironmentVariable("QS_ICON_THEME");
|
||||
QHash<QString, QString> envOverrides;
|
||||
QString appId = qEnvironmentVariable("QS_APP_ID");
|
||||
bool dropExpensiveFonts = false;
|
||||
QString dataDir;
|
||||
QString stateDir;
|
||||
QString cacheDir;
|
||||
@@ -91,6 +93,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
else if (pragma == "NativeTextRendering") pragmas.nativeTextRendering = true;
|
||||
else if (pragma == "IgnoreSystemSettings") pragmas.desktopSettingsAware = false;
|
||||
else if (pragma == "RespectSystemStyle") pragmas.useSystemStyle = true;
|
||||
else if (pragma == "DropExpensiveFonts") pragmas.dropExpensiveFonts = true;
|
||||
else if (pragma.startsWith("IconTheme ")) pragmas.iconTheme = pragma.sliced(10);
|
||||
else if (pragma.startsWith("Env ")) {
|
||||
auto envPragma = pragma.sliced(4);
|
||||
@@ -104,6 +107,8 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
auto var = envPragma.sliced(0, splitIdx).trimmed();
|
||||
auto val = envPragma.sliced(splitIdx + 1).trimmed();
|
||||
pragmas.envOverrides.insert(var, val);
|
||||
} else if (pragma.startsWith("AppId ")) {
|
||||
pragmas.appId = pragma.sliced(6).trimmed();
|
||||
} else if (pragma.startsWith("ShellId ")) {
|
||||
shellId = pragma.sliced(8).trimmed();
|
||||
} else if (pragma.startsWith("DataDir ")) {
|
||||
@@ -113,8 +118,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
} else if (pragma.startsWith("CacheDir ")) {
|
||||
pragmas.cacheDir = pragma.sliced(9).trimmed();
|
||||
} else {
|
||||
qCritical() << "Unrecognized pragma" << pragma;
|
||||
return -1;
|
||||
qWarning() << "Unrecognized pragma" << pragma;
|
||||
}
|
||||
} else if (line.startsWith("import")) break;
|
||||
}
|
||||
@@ -128,10 +132,13 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
qInfo() << "Shell ID:" << shellId << "Path ID" << pathId;
|
||||
|
||||
auto launchTime = qs::Common::LAUNCH_TIME.toSecsSinceEpoch();
|
||||
auto appId = pragmas.appId.isEmpty() ? QStringLiteral("org.quickshell") : pragmas.appId;
|
||||
|
||||
InstanceInfo::CURRENT = InstanceInfo {
|
||||
.instanceId = base36Encode(getpid()) + base36Encode(launchTime),
|
||||
.configPath = args.configPath,
|
||||
.shellId = shellId,
|
||||
.appId = appId,
|
||||
.launchTime = qs::Common::LAUNCH_TIME,
|
||||
.pid = getpid(),
|
||||
.display = getDisplayConnection(),
|
||||
@@ -171,6 +178,48 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
qputenv(var.toUtf8(), val.toUtf8());
|
||||
}
|
||||
|
||||
pragmas.dropExpensiveFonts |= qEnvironmentVariableIntValue("QS_DROP_EXPENSIVE_FONTS") == 1;
|
||||
|
||||
if (pragmas.dropExpensiveFonts) {
|
||||
if (auto* runDir = QsPaths::instance()->instanceRunDir()) {
|
||||
auto baseConfigPath = qEnvironmentVariable("FONTCONFIG_FILE");
|
||||
if (baseConfigPath.isEmpty()) baseConfigPath = "/etc/fonts/fonts.conf";
|
||||
|
||||
auto filterPath = runDir->filePath("fonts-override.conf");
|
||||
auto filterFile = QFile(filterPath);
|
||||
if (filterFile.open(QFile::WriteOnly | QFile::Truncate | QFile::Text)) {
|
||||
auto filterTemplate = QStringLiteral(R"(<?xml version="1.0"?>
|
||||
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
|
||||
<fontconfig>
|
||||
<include ignore_missing="no">%1</include>
|
||||
<selectfont>
|
||||
<rejectfont>
|
||||
<pattern>
|
||||
<patelt name="fontwrapper">
|
||||
<string>woff</string>
|
||||
</patelt>
|
||||
</pattern>
|
||||
<pattern>
|
||||
<patelt name="fontwrapper">
|
||||
<string>woff2</string>
|
||||
</patelt>
|
||||
</pattern>
|
||||
</rejectfont>
|
||||
</selectfont>
|
||||
</fontconfig>
|
||||
)");
|
||||
|
||||
QTextStream(&filterFile) << filterTemplate.arg(baseConfigPath);
|
||||
filterFile.close();
|
||||
qputenv("FONTCONFIG_FILE", filterPath.toUtf8());
|
||||
} else {
|
||||
qCritical() << "Could not write fontconfig filter to" << filterPath;
|
||||
}
|
||||
} else {
|
||||
qCritical() << "Could not create fontconfig filter: instance run directory unavailable";
|
||||
}
|
||||
}
|
||||
|
||||
// The qml engine currently refuses to cache non file (qsintercept) paths.
|
||||
|
||||
// if (auto* cacheDir = QsPaths::instance()->cacheDir()) {
|
||||
@@ -231,7 +280,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
||||
app = new QGuiApplication(qArgC, argv);
|
||||
}
|
||||
|
||||
QGuiApplication::setDesktopFileName("org.quickshell");
|
||||
QGuiApplication::setDesktopFileName(appId);
|
||||
|
||||
if (args.debugPort != -1) {
|
||||
QQmlDebuggingEnabler::enableDebugging(true);
|
||||
|
||||
@@ -4,6 +4,7 @@ qt_add_library(quickshell-network STATIC
|
||||
network.cpp
|
||||
device.cpp
|
||||
wifi.cpp
|
||||
enums.cpp
|
||||
)
|
||||
|
||||
target_include_directories(quickshell-network PRIVATE
|
||||
|
||||
+9
-43
@@ -8,6 +8,7 @@
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "../core/logcat.hpp"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
@@ -15,49 +16,9 @@ namespace {
|
||||
QS_LOGGING_CATEGORY(logNetworkDevice, "quickshell.network.device", QtWarningMsg);
|
||||
} // namespace
|
||||
|
||||
QString DeviceConnectionState::toString(DeviceConnectionState::Enum state) {
|
||||
switch (state) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case Connecting: return QStringLiteral("Connecting");
|
||||
case Connected: return QStringLiteral("Connected");
|
||||
case Disconnecting: return QStringLiteral("Disconnecting");
|
||||
case Disconnected: return QStringLiteral("Disconnected");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString DeviceType::toString(DeviceType::Enum type) {
|
||||
switch (type) {
|
||||
case None: return QStringLiteral("None");
|
||||
case Wifi: return QStringLiteral("Wifi");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString NMDeviceState::toString(NMDeviceState::Enum state) {
|
||||
switch (state) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case Unmanaged: return QStringLiteral("Not managed by NetworkManager");
|
||||
case Unavailable: return QStringLiteral("Unavailable");
|
||||
case Disconnected: return QStringLiteral("Disconnected");
|
||||
case Prepare: return QStringLiteral("Preparing to connect");
|
||||
case Config: return QStringLiteral("Connecting to a network");
|
||||
case NeedAuth: return QStringLiteral("Waiting for authentication");
|
||||
case IPConfig: return QStringLiteral("Requesting IPv4 and/or IPv6 addresses from the network");
|
||||
case IPCheck:
|
||||
return QStringLiteral("Checking if further action is required for the requested connection");
|
||||
case Secondaries:
|
||||
return QStringLiteral("Waiting for a required secondary connection to activate");
|
||||
case Activated: return QStringLiteral("Connected");
|
||||
case Deactivating: return QStringLiteral("Disconnecting");
|
||||
case Failed: return QStringLiteral("Failed to connect");
|
||||
default: return QStringLiteral("Unknown");
|
||||
};
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkDevice(DeviceType::Enum type, QObject* parent): QObject(parent), mType(type) {
|
||||
this->bindableConnected().setBinding([this]() {
|
||||
return this->bState == DeviceConnectionState::Connected;
|
||||
return this->bState == ConnectionState::Connected;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -66,12 +27,17 @@ void NetworkDevice::setAutoconnect(bool autoconnect) {
|
||||
emit this->requestSetAutoconnect(autoconnect);
|
||||
}
|
||||
|
||||
void NetworkDevice::setNmManaged(bool managed) {
|
||||
if (this->bNmManaged == managed) return;
|
||||
emit this->requestSetNmManaged(managed);
|
||||
}
|
||||
|
||||
void NetworkDevice::disconnect() {
|
||||
if (this->bState == DeviceConnectionState::Disconnected) {
|
||||
if (this->bState == ConnectionState::Disconnected) {
|
||||
qCCritical(logNetworkDevice) << "Device" << this << "is already disconnected";
|
||||
return;
|
||||
}
|
||||
if (this->bState == DeviceConnectionState::Disconnecting) {
|
||||
if (this->bState == ConnectionState::Disconnecting) {
|
||||
qCCritical(logNetworkDevice) << "Device" << this << "is already disconnecting";
|
||||
return;
|
||||
}
|
||||
|
||||
+30
-79
@@ -6,76 +6,22 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../core/doc.hpp"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
///! Connection state of a NetworkDevice.
|
||||
class DeviceConnectionState: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
Connecting = 1,
|
||||
Connected = 2,
|
||||
Disconnecting = 3,
|
||||
Disconnected = 4,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(DeviceConnectionState::Enum state);
|
||||
};
|
||||
|
||||
///! Type of network device.
|
||||
class DeviceType: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
None = 0,
|
||||
Wifi = 1,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(DeviceType::Enum type);
|
||||
};
|
||||
|
||||
///! NetworkManager-specific device state.
|
||||
/// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMDeviceState.
|
||||
class NMDeviceState: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
Unmanaged = 10,
|
||||
Unavailable = 20,
|
||||
Disconnected = 30,
|
||||
Prepare = 40,
|
||||
Config = 50,
|
||||
NeedAuth = 60,
|
||||
IPConfig = 70,
|
||||
IPCheck = 80,
|
||||
Secondaries = 90,
|
||||
Activated = 100,
|
||||
Deactivating = 110,
|
||||
Failed = 120,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(NMDeviceState::Enum state);
|
||||
};
|
||||
|
||||
///! A network device.
|
||||
/// When @@type is `Wifi`, the device is a @@WifiDevice, which can be used to scan for and connect to access points.
|
||||
/// The @@type property may be used to determine if this device is a @@WifiDevice.
|
||||
class NetworkDevice: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("Devices can only be acquired through Network");
|
||||
// clang-format off
|
||||
/// The device type.
|
||||
///
|
||||
/// When the device type is `Wifi`, the device object is a @@WifiDevice which exposes wifi network
|
||||
/// connection and scanning.
|
||||
Q_PROPERTY(DeviceType::Enum type READ type CONSTANT);
|
||||
/// The name of the device's control interface.
|
||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged BINDABLE bindableName);
|
||||
@@ -84,10 +30,12 @@ class NetworkDevice: public QObject {
|
||||
/// True if the device is connected.
|
||||
Q_PROPERTY(bool connected READ default NOTIFY connectedChanged BINDABLE bindableConnected);
|
||||
/// Connection state of the device.
|
||||
Q_PROPERTY(qs::network::DeviceConnectionState::Enum state READ default NOTIFY stateChanged BINDABLE bindableState);
|
||||
/// A more specific device state when the backend is NetworkManager.
|
||||
Q_PROPERTY(qs::network::NMDeviceState::Enum nmState READ default NOTIFY nmStateChanged BINDABLE bindableNmState);
|
||||
/// True if the device is allowed to autoconnect.
|
||||
Q_PROPERTY(qs::network::ConnectionState::Enum state READ default NOTIFY stateChanged BINDABLE bindableState);
|
||||
/// True if the device is managed by NetworkManager.
|
||||
///
|
||||
/// > [!WARNING] Only valid for the NetworkManager backend.
|
||||
Q_PROPERTY(bool nmManaged READ nmManaged WRITE setNmManaged NOTIFY nmManagedChanged)
|
||||
/// True if the device is allowed to autoconnect to a network.
|
||||
Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect NOTIFY autoconnectChanged);
|
||||
// clang-format on
|
||||
|
||||
@@ -97,25 +45,28 @@ public:
|
||||
/// Disconnects the device and prevents it from automatically activating further connections.
|
||||
Q_INVOKABLE void disconnect();
|
||||
|
||||
[[nodiscard]] DeviceType::Enum type() const { return this->mType; };
|
||||
QBindable<QString> bindableName() { return &this->bName; };
|
||||
[[nodiscard]] QString name() const { return this->bName; };
|
||||
QBindable<QString> bindableAddress() { return &this->bAddress; };
|
||||
QBindable<bool> bindableConnected() { return &this->bConnected; };
|
||||
QBindable<DeviceConnectionState::Enum> bindableState() { return &this->bState; };
|
||||
QBindable<NMDeviceState::Enum> bindableNmState() { return &this->bNmState; };
|
||||
[[nodiscard]] bool autoconnect() const { return this->bAutoconnect; };
|
||||
QBindable<bool> bindableAutoconnect() { return &this->bAutoconnect; };
|
||||
[[nodiscard]] DeviceType::Enum type() const { return this->mType; }
|
||||
QBindable<QString> bindableName() { return &this->bName; }
|
||||
[[nodiscard]] QString name() const { return this->bName; }
|
||||
QBindable<QString> bindableAddress() { return &this->bAddress; }
|
||||
QBindable<bool> bindableConnected() { return &this->bConnected; }
|
||||
QBindable<ConnectionState::Enum> bindableState() { return &this->bState; }
|
||||
QBindable<bool> bindableNmManaged() { return &this->bNmManaged; }
|
||||
[[nodiscard]] bool nmManaged() { return this->bNmManaged; }
|
||||
void setNmManaged(bool managed);
|
||||
QBindable<bool> bindableAutoconnect() { return &this->bAutoconnect; }
|
||||
[[nodiscard]] bool autoconnect() { return this->bAutoconnect; }
|
||||
void setAutoconnect(bool autoconnect);
|
||||
|
||||
signals:
|
||||
void requestDisconnect();
|
||||
void requestSetAutoconnect(bool autoconnect);
|
||||
QSDOC_HIDE void requestDisconnect();
|
||||
QSDOC_HIDE void requestSetAutoconnect(bool autoconnect);
|
||||
QSDOC_HIDE void requestSetNmManaged(bool managed);
|
||||
void nameChanged();
|
||||
void addressChanged();
|
||||
void connectedChanged();
|
||||
void stateChanged();
|
||||
void nmStateChanged();
|
||||
void nmManagedChanged();
|
||||
void autoconnectChanged();
|
||||
|
||||
private:
|
||||
@@ -124,8 +75,8 @@ private:
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, QString, bName, &NetworkDevice::nameChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, QString, bAddress, &NetworkDevice::addressChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, bool, bConnected, &NetworkDevice::connectedChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, DeviceConnectionState::Enum, bState, &NetworkDevice::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, NMDeviceState::Enum, bNmState, &NetworkDevice::nmStateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, ConnectionState::Enum, bState, &NetworkDevice::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, bool, bNmManaged, &NetworkDevice::nmManagedChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, bool, bAutoconnect, &NetworkDevice::autoconnectChanged);
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "enums.hpp"
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
QString NetworkConnectivity::toString(NetworkConnectivity::Enum conn) {
|
||||
switch (conn) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case None: return QStringLiteral("Not connected to a network");
|
||||
case Portal: return QStringLiteral("Connection intercepted by a captive portal");
|
||||
case Limited: return QStringLiteral("Partial internet connectivity");
|
||||
case Full: return QStringLiteral("Full internet connectivity");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString NetworkBackendType::toString(NetworkBackendType::Enum type) {
|
||||
switch (type) {
|
||||
case NetworkBackendType::None: return "None";
|
||||
case NetworkBackendType::NetworkManager: return "NetworkManager";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionState::toString(ConnectionState::Enum state) {
|
||||
switch (state) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case Connecting: return QStringLiteral("Connecting");
|
||||
case Connected: return QStringLiteral("Connected");
|
||||
case Disconnecting: return QStringLiteral("Disconnecting");
|
||||
case Disconnected: return QStringLiteral("Disconnected");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionFailReason::toString(ConnectionFailReason::Enum reason) {
|
||||
switch (reason) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case NoSecrets: return QStringLiteral("Secrets were required but not provided");
|
||||
case WifiClientDisconnected: return QStringLiteral("Wi-Fi supplicant diconnected");
|
||||
case WifiClientFailed: return QStringLiteral("Wi-Fi supplicant failed");
|
||||
case WifiAuthTimeout: return QStringLiteral("Wi-Fi connection took too long to authenticate");
|
||||
case WifiNetworkLost: return QStringLiteral("Wi-Fi network could not be found");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString DeviceType::toString(DeviceType::Enum type) {
|
||||
switch (type) {
|
||||
case None: return QStringLiteral("None");
|
||||
case Wifi: return QStringLiteral("Wifi");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString WifiSecurityType::toString(WifiSecurityType::Enum type) {
|
||||
switch (type) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case Wpa3SuiteB192: return QStringLiteral("WPA3 Suite B 192-bit");
|
||||
case Sae: return QStringLiteral("WPA3");
|
||||
case Wpa2Eap: return QStringLiteral("WPA2 Enterprise");
|
||||
case Wpa2Psk: return QStringLiteral("WPA2");
|
||||
case WpaEap: return QStringLiteral("WPA Enterprise");
|
||||
case WpaPsk: return QStringLiteral("WPA");
|
||||
case StaticWep: return QStringLiteral("WEP");
|
||||
case DynamicWep: return QStringLiteral("Dynamic WEP");
|
||||
case Leap: return QStringLiteral("LEAP");
|
||||
case Owe: return QStringLiteral("OWE");
|
||||
case Open: return QStringLiteral("Open");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
QString WifiDeviceMode::toString(WifiDeviceMode::Enum mode) {
|
||||
switch (mode) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case AdHoc: return QStringLiteral("Ad-Hoc");
|
||||
case Station: return QStringLiteral("Station");
|
||||
case AccessPoint: return QStringLiteral("Access Point");
|
||||
case Mesh: return QStringLiteral("Mesh");
|
||||
default: return QStringLiteral("Unknown");
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace qs::network
|
||||
@@ -0,0 +1,154 @@
|
||||
#pragma once
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
///! The degree to which the host can reach the internet.
|
||||
class NetworkConnectivity: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
/// Network connectivity is unknown. This means the connectivity checks are disabled or have not run yet.
|
||||
Unknown = 0,
|
||||
/// The host is not connected to any network.
|
||||
None = 1,
|
||||
/// The internet connection is hijacked by a captive portal gateway.
|
||||
/// This indicates the shell should open a sandboxed web browser window for the purpose of authenticating to a gateway.
|
||||
Portal = 2,
|
||||
/// The host is connected to a network but does not appear to be able to reach the full internet.
|
||||
Limited = 3,
|
||||
/// The host is connected to a network and appears to be able to reach the full internet.
|
||||
Full = 4,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(NetworkConnectivity::Enum conn);
|
||||
};
|
||||
|
||||
///! The backend supplying the Network service.
|
||||
class NetworkBackendType: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
None = 0,
|
||||
NetworkManager = 1,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(NetworkBackendType::Enum type);
|
||||
};
|
||||
|
||||
///! The connection state of a device or network.
|
||||
class ConnectionState: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
Connecting = 1,
|
||||
Connected = 2,
|
||||
Disconnecting = 3,
|
||||
Disconnected = 4,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(ConnectionState::Enum state);
|
||||
};
|
||||
|
||||
///! The reason a connection failed.
|
||||
class ConnectionFailReason: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
/// The connection failed for an unknown reason.
|
||||
Unknown = 0,
|
||||
/// Secrets were required, but not provided.
|
||||
NoSecrets = 1,
|
||||
/// The Wi-Fi supplicant disconnected.
|
||||
WifiClientDisconnected = 2,
|
||||
/// The Wi-Fi supplicant failed.
|
||||
WifiClientFailed = 3,
|
||||
/// The Wi-Fi connection took too long to authenticate.
|
||||
WifiAuthTimeout = 4,
|
||||
/// The Wi-Fi network could not be found.
|
||||
WifiNetworkLost = 5,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(ConnectionFailReason::Enum reason);
|
||||
};
|
||||
|
||||
///! Type of a @@NetworkDevice.
|
||||
class DeviceType: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
None = 0,
|
||||
Wifi = 1,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(DeviceType::Enum type);
|
||||
};
|
||||
|
||||
///! The security type of a @@WifiNetwork.
|
||||
class WifiSecurityType: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Wpa3SuiteB192 = 0,
|
||||
Sae = 1,
|
||||
Wpa2Eap = 2,
|
||||
Wpa2Psk = 3,
|
||||
WpaEap = 4,
|
||||
WpaPsk = 5,
|
||||
StaticWep = 6,
|
||||
DynamicWep = 7,
|
||||
Leap = 8,
|
||||
Owe = 9,
|
||||
Open = 10,
|
||||
Unknown = 11,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(WifiSecurityType::Enum type);
|
||||
};
|
||||
|
||||
///! The 802.11 mode of a @@WifiDevice.
|
||||
class WifiDeviceMode: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
/// The device is part of an Ad-Hoc network without a central access point.
|
||||
AdHoc = 0,
|
||||
/// The device is a station that can connect to networks.
|
||||
Station = 1,
|
||||
/// The device is a local hotspot/access point.
|
||||
AccessPoint = 2,
|
||||
/// The device is an 802.11s mesh point.
|
||||
Mesh = 3,
|
||||
/// The device mode is unknown.
|
||||
Unknown = 4,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(WifiDeviceMode::Enum mode);
|
||||
};
|
||||
|
||||
} // namespace qs::network
|
||||
@@ -4,6 +4,8 @@ headers = [
|
||||
"network.hpp",
|
||||
"device.hpp",
|
||||
"wifi.hpp",
|
||||
"enums.hpp",
|
||||
"nm/settings.hpp",
|
||||
]
|
||||
-----
|
||||
This module exposes Network management APIs provided by a supported network backend.
|
||||
|
||||
+78
-12
@@ -1,6 +1,7 @@
|
||||
#include "network.hpp"
|
||||
#include <utility>
|
||||
|
||||
#include <qdebug.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qobject.h>
|
||||
@@ -9,7 +10,9 @@
|
||||
|
||||
#include "../core/logcat.hpp"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "nm/backend.hpp"
|
||||
#include "nm/settings.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
@@ -17,25 +20,22 @@ namespace {
|
||||
QS_LOGGING_CATEGORY(logNetwork, "quickshell.network", QtWarningMsg);
|
||||
} // namespace
|
||||
|
||||
QString NetworkState::toString(NetworkState::Enum state) {
|
||||
switch (state) {
|
||||
case NetworkState::Connecting: return QStringLiteral("Connecting");
|
||||
case NetworkState::Connected: return QStringLiteral("Connected");
|
||||
case NetworkState::Disconnecting: return QStringLiteral("Disconnecting");
|
||||
case NetworkState::Disconnected: return QStringLiteral("Disconnected");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
Networking::Networking(QObject* parent): QObject(parent) {
|
||||
// Try to create the NetworkManager backend and bind to it.
|
||||
auto* nm = new NetworkManager(this);
|
||||
if (nm->isAvailable()) {
|
||||
// clang-format off
|
||||
QObject::connect(nm, &NetworkManager::deviceAdded, this, &Networking::deviceAdded);
|
||||
QObject::connect(nm, &NetworkManager::deviceRemoved, this, &Networking::deviceRemoved);
|
||||
QObject::connect(this, &Networking::requestSetWifiEnabled, nm, &NetworkManager::setWifiEnabled);
|
||||
QObject::connect(this, &Networking::requestSetConnectivityCheckEnabled, nm, &NetworkManager::setConnectivityCheckEnabled);
|
||||
QObject::connect(this, &Networking::requestCheckConnectivity, nm, &NetworkManager::checkConnectivity);
|
||||
this->bindableWifiEnabled().setBinding([nm]() { return nm->wifiEnabled(); });
|
||||
this->bindableWifiHardwareEnabled().setBinding([nm]() { return nm->wifiHardwareEnabled(); });
|
||||
this->bindableCanCheckConnectivity().setBinding([nm]() { return nm->connectivityCheckAvailable(); });
|
||||
this->bindableConnectivityCheckEnabled().setBinding([nm]() { return nm->connectivityCheckEnabled(); });
|
||||
this->bindableConnectivity().setBinding([nm]() { return static_cast<NetworkConnectivity::Enum>(nm->connectivity()); });
|
||||
// clang-format on
|
||||
|
||||
this->mBackend = nm;
|
||||
this->mBackendType = NetworkBackendType::NetworkManager;
|
||||
@@ -43,23 +43,89 @@ Networking::Networking(QObject* parent): QObject(parent) {
|
||||
} else {
|
||||
delete nm;
|
||||
}
|
||||
|
||||
qCCritical(logNetwork) << "Network will not work. Could not find an available backend.";
|
||||
}
|
||||
|
||||
Networking* Networking::instance() {
|
||||
static Networking* instance = new Networking(); // NOLINT
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Networking::deviceAdded(NetworkDevice* dev) { this->mDevices.insertObject(dev); }
|
||||
void Networking::deviceRemoved(NetworkDevice* dev) { this->mDevices.removeObject(dev); }
|
||||
|
||||
void Networking::checkConnectivity() {
|
||||
if (!this->bConnectivityCheckEnabled || !this->bCanCheckConnectivity) return;
|
||||
emit this->requestCheckConnectivity();
|
||||
}
|
||||
|
||||
void Networking::setWifiEnabled(bool enabled) {
|
||||
if (this->bWifiEnabled == enabled) return;
|
||||
emit this->requestSetWifiEnabled(enabled);
|
||||
}
|
||||
|
||||
void Networking::setConnectivityCheckEnabled(bool enabled) {
|
||||
if (this->bConnectivityCheckEnabled == enabled) return;
|
||||
emit this->requestSetConnectivityCheckEnabled(enabled);
|
||||
}
|
||||
|
||||
NetworkingQml::NetworkingQml(QObject* parent): QObject(parent) {
|
||||
// clang-format off
|
||||
QObject::connect(Networking::instance(), &Networking::wifiEnabledChanged, this, &NetworkingQml::wifiEnabledChanged);
|
||||
QObject::connect(Networking::instance(), &Networking::wifiHardwareEnabledChanged, this, &NetworkingQml::wifiHardwareEnabledChanged);
|
||||
QObject::connect(Networking::instance(), &Networking::canCheckConnectivityChanged, this, &NetworkingQml::canCheckConnectivityChanged);
|
||||
QObject::connect(Networking::instance(), &Networking::connectivityCheckEnabledChanged, this, &NetworkingQml::connectivityCheckEnabledChanged);
|
||||
QObject::connect(Networking::instance(), &Networking::connectivityChanged, this, &NetworkingQml::connectivityChanged);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void NetworkingQml::checkConnectivity() { Networking::instance()->checkConnectivity(); }
|
||||
|
||||
Network::Network(QString name, QObject* parent): QObject(parent), mName(std::move(name)) {
|
||||
this->bStateChanging.setBinding([this] {
|
||||
auto state = this->bState.value();
|
||||
return state == NetworkState::Connecting || state == NetworkState::Disconnecting;
|
||||
return state == ConnectionState::Connecting || state == ConnectionState::Disconnecting;
|
||||
});
|
||||
};
|
||||
|
||||
void Network::connect() {
|
||||
if (this->bConnected) {
|
||||
qCCritical(logNetwork) << this << "is already connected.";
|
||||
return;
|
||||
}
|
||||
this->requestConnect();
|
||||
}
|
||||
|
||||
void Network::connectWithSettings(NMSettings* settings) {
|
||||
if (this->bConnected) {
|
||||
qCCritical(logNetwork) << this << "is already connected.";
|
||||
return;
|
||||
}
|
||||
if (this->bNmSettings.value().indexOf(settings) == -1) return;
|
||||
this->requestConnectWithSettings(settings);
|
||||
}
|
||||
|
||||
void Network::disconnect() {
|
||||
if (!this->bConnected) {
|
||||
qCCritical(logNetwork) << this << "is not currently connected";
|
||||
return;
|
||||
}
|
||||
this->requestDisconnect();
|
||||
}
|
||||
|
||||
void Network::forget() { this->requestForget(); }
|
||||
|
||||
void Network::settingsAdded(NMSettings* settings) {
|
||||
auto list = this->bNmSettings.value();
|
||||
if (list.contains(settings)) return;
|
||||
list.append(settings);
|
||||
this->bNmSettings = list;
|
||||
}
|
||||
|
||||
void Network::settingsRemoved(NMSettings* settings) {
|
||||
auto list = this->bNmSettings.value();
|
||||
list.removeOne(settings);
|
||||
this->bNmSettings = list;
|
||||
}
|
||||
|
||||
} // namespace qs::network
|
||||
+152
-61
@@ -6,43 +6,14 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../core/doc.hpp"
|
||||
#include "../core/model.hpp"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "nm/settings.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
///! The connection state of a Network.
|
||||
class NetworkState: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
Connecting = 1,
|
||||
Connected = 2,
|
||||
Disconnecting = 3,
|
||||
Disconnected = 4,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(NetworkState::Enum state);
|
||||
};
|
||||
|
||||
///! The backend supplying the Network service.
|
||||
class NetworkBackendType: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
None = 0,
|
||||
NetworkManager = 1,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
};
|
||||
|
||||
class NetworkBackend: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
@@ -53,15 +24,65 @@ protected:
|
||||
explicit NetworkBackend(QObject* parent = nullptr): QObject(parent) {};
|
||||
};
|
||||
|
||||
class Networking: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
static Networking* instance();
|
||||
|
||||
void checkConnectivity();
|
||||
|
||||
[[nodiscard]] ObjectModel<NetworkDevice>* devices() { return &this->mDevices; }
|
||||
[[nodiscard]] NetworkBackendType::Enum backend() const { return this->mBackendType; }
|
||||
QBindable<bool> bindableWifiEnabled() { return &this->bWifiEnabled; }
|
||||
[[nodiscard]] bool wifiEnabled() const { return this->bWifiEnabled; }
|
||||
void setWifiEnabled(bool enabled);
|
||||
QBindable<bool> bindableWifiHardwareEnabled() { return &this->bWifiHardwareEnabled; }
|
||||
QBindable<bool> bindableCanCheckConnectivity() { return &this->bCanCheckConnectivity; }
|
||||
QBindable<bool> bindableConnectivityCheckEnabled() { return &this->bConnectivityCheckEnabled; }
|
||||
[[nodiscard]] bool connectivityCheckEnabled() const { return this->bConnectivityCheckEnabled; }
|
||||
void setConnectivityCheckEnabled(bool enabled);
|
||||
QBindable<NetworkConnectivity::Enum> bindableConnectivity() { return &this->bConnectivity; }
|
||||
|
||||
signals:
|
||||
void requestSetWifiEnabled(bool enabled);
|
||||
void requestSetConnectivityCheckEnabled(bool enabled);
|
||||
void requestCheckConnectivity();
|
||||
|
||||
void wifiEnabledChanged();
|
||||
void wifiHardwareEnabledChanged();
|
||||
void canCheckConnectivityChanged();
|
||||
void connectivityCheckEnabledChanged();
|
||||
void connectivityChanged();
|
||||
|
||||
private slots:
|
||||
void deviceAdded(NetworkDevice* dev);
|
||||
void deviceRemoved(NetworkDevice* dev);
|
||||
|
||||
private:
|
||||
explicit Networking(QObject* parent = nullptr);
|
||||
|
||||
ObjectModel<NetworkDevice> mDevices {this};
|
||||
NetworkBackend* mBackend = nullptr;
|
||||
NetworkBackendType::Enum mBackendType = NetworkBackendType::None;
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, bool, bWifiEnabled, &Networking::wifiEnabledChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, bool, bWifiHardwareEnabled, &Networking::wifiHardwareEnabledChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, bool, bCanCheckConnectivity, &Networking::canCheckConnectivityChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, bool, bConnectivityCheckEnabled, &Networking::connectivityCheckEnabledChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, NetworkConnectivity::Enum, bConnectivity, &Networking::connectivityChanged);
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
///! The Network service.
|
||||
/// An interface to a network backend (currently only NetworkManager),
|
||||
/// which can be used to view, configure, and connect to various networks.
|
||||
class Networking: public QObject {
|
||||
class NetworkingQml: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_NAMED_ELEMENT(Networking);
|
||||
QML_SINGLETON;
|
||||
QML_ELEMENT;
|
||||
// clang-format off
|
||||
/// A list of all network devices.
|
||||
/// A list of all network devices. Networks are exposed through their respective devices.
|
||||
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::network::NetworkDevice>*);
|
||||
Q_PROPERTY(UntypedObjectModel* devices READ devices CONSTANT);
|
||||
/// The backend being used to power the Network service.
|
||||
@@ -70,73 +91,143 @@ class Networking: public QObject {
|
||||
Q_PROPERTY(bool wifiEnabled READ wifiEnabled WRITE setWifiEnabled NOTIFY wifiEnabledChanged);
|
||||
/// State of the rfkill hardware block of all wireless devices.
|
||||
Q_PROPERTY(bool wifiHardwareEnabled READ default NOTIFY wifiHardwareEnabledChanged BINDABLE bindableWifiHardwareEnabled);
|
||||
/// True if the @@backend supports connectivity checks.
|
||||
Q_PROPERTY(bool canCheckConnectivity READ default NOTIFY canCheckConnectivityChanged BINDABLE bindableCanCheckConnectivity);
|
||||
/// True if connectivity checking is enabled.
|
||||
Q_PROPERTY(bool connectivityCheckEnabled READ connectivityCheckEnabled WRITE setConnectivityCheckEnabled NOTIFY connectivityCheckEnabledChanged);
|
||||
/// The result of the last connectivity check.
|
||||
///
|
||||
/// Connectivity checks may require additional configuration depending on your distro.
|
||||
///
|
||||
/// > [!NOTE] This property can be used to determine if network access is restricted
|
||||
/// > or gated behind a captive portal.
|
||||
/// >
|
||||
/// > If checking for captive portals, @@checkConnectivity() should be called after
|
||||
/// > the portal is dismissed to update this property.
|
||||
Q_PROPERTY(qs::network::NetworkConnectivity::Enum connectivity READ default NOTIFY connectivityChanged BINDABLE bindableConnectivity);
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
explicit Networking(QObject* parent = nullptr);
|
||||
explicit NetworkingQml(QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] ObjectModel<NetworkDevice>* devices() { return &this->mDevices; };
|
||||
[[nodiscard]] NetworkBackendType::Enum backend() const { return this->mBackendType; };
|
||||
QBindable<bool> bindableWifiEnabled() { return &this->bWifiEnabled; };
|
||||
[[nodiscard]] bool wifiEnabled() const { return this->bWifiEnabled; };
|
||||
void setWifiEnabled(bool enabled);
|
||||
QBindable<bool> bindableWifiHardwareEnabled() { return &this->bWifiHardwareEnabled; };
|
||||
/// Re-check the network connectivity state immediately.
|
||||
/// > [!NOTE] This should be invoked after a user dismisses a web browser that was opened to authenticate via a captive portal.
|
||||
Q_INVOKABLE static void checkConnectivity();
|
||||
|
||||
[[nodiscard]] static ObjectModel<NetworkDevice>* devices() {
|
||||
return Networking::instance()->devices();
|
||||
}
|
||||
[[nodiscard]] static NetworkBackendType::Enum backend() {
|
||||
return Networking::instance()->backend();
|
||||
}
|
||||
[[nodiscard]] static bool wifiEnabled() { return Networking::instance()->wifiEnabled(); }
|
||||
static void setWifiEnabled(bool enabled) { Networking::instance()->setWifiEnabled(enabled); }
|
||||
[[nodiscard]] static QBindable<bool> bindableWifiHardwareEnabled() {
|
||||
return Networking::instance()->bindableWifiHardwareEnabled();
|
||||
}
|
||||
[[nodiscard]] static QBindable<bool> bindableWifiEnabled() {
|
||||
return Networking::instance()->bindableWifiEnabled();
|
||||
}
|
||||
[[nodiscard]] static QBindable<bool> bindableCanCheckConnectivity() {
|
||||
return Networking::instance()->bindableCanCheckConnectivity();
|
||||
}
|
||||
[[nodiscard]] static bool connectivityCheckEnabled() {
|
||||
return Networking::instance()->connectivityCheckEnabled();
|
||||
}
|
||||
static void setConnectivityCheckEnabled(bool enabled) {
|
||||
Networking::instance()->setConnectivityCheckEnabled(enabled);
|
||||
}
|
||||
[[nodiscard]] static QBindable<NetworkConnectivity::Enum> bindableConnectivity() {
|
||||
return Networking::instance()->bindableConnectivity();
|
||||
}
|
||||
|
||||
signals:
|
||||
void requestSetWifiEnabled(bool enabled);
|
||||
void wifiEnabledChanged();
|
||||
void wifiHardwareEnabledChanged();
|
||||
|
||||
private slots:
|
||||
void deviceAdded(NetworkDevice* dev);
|
||||
void deviceRemoved(NetworkDevice* dev);
|
||||
|
||||
private:
|
||||
ObjectModel<NetworkDevice> mDevices {this};
|
||||
NetworkBackend* mBackend = nullptr;
|
||||
NetworkBackendType::Enum mBackendType = NetworkBackendType::None;
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, bool, bWifiEnabled, &Networking::wifiEnabledChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Networking, bool, bWifiHardwareEnabled, &Networking::wifiHardwareEnabledChanged);
|
||||
// clang-format on
|
||||
void canCheckConnectivityChanged();
|
||||
void connectivityCheckEnabledChanged();
|
||||
void connectivityChanged();
|
||||
};
|
||||
|
||||
///! A network.
|
||||
/// A network. Networks derived from a @@WifiDevice are @@WifiNetwork instances.
|
||||
class Network: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("BaseNetwork can only be aqcuired through network devices");
|
||||
QML_UNCREATABLE("Network can only be aqcuired through networking devices");
|
||||
|
||||
// clang-format off
|
||||
/// The name of the network.
|
||||
Q_PROPERTY(QString name READ name CONSTANT);
|
||||
/// A list of NetworkManager connnection settings profiles for this network.
|
||||
///
|
||||
/// > [!WARNING] Only valid for the NetworkManager backend.
|
||||
Q_PROPERTY(QList<NMSettings*> nmSettings READ nmSettings NOTIFY nmSettingsChanged BINDABLE bindableNmSettings);
|
||||
/// True if the network is connected.
|
||||
Q_PROPERTY(bool connected READ default NOTIFY connectedChanged BINDABLE bindableConnected);
|
||||
/// True if the wifi network has known connection settings saved.
|
||||
Q_PROPERTY(bool known READ default NOTIFY knownChanged BINDABLE bindableKnown);
|
||||
/// The connectivity state of the network.
|
||||
Q_PROPERTY(NetworkState::Enum state READ default NOTIFY stateChanged BINDABLE bindableState);
|
||||
Q_PROPERTY(ConnectionState::Enum state READ default NOTIFY stateChanged BINDABLE bindableState);
|
||||
/// If the network is currently connecting or disconnecting. Shorthand for checking @@state.
|
||||
Q_PROPERTY(bool stateChanging READ default NOTIFY stateChangingChanged BINDABLE bindableStateChanging);
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
explicit Network(QString name, QObject* parent = nullptr);
|
||||
/// Attempt to connect to the network.
|
||||
///
|
||||
/// > [!NOTE] If the network is a @@WifiNetwork and requires secrets, a @@connectionFailed(s)
|
||||
/// > signal will be emitted with `NoSecrets`.
|
||||
/// > @@WifiNetwork.connectWithPsk() can be used to provide secrets.
|
||||
Q_INVOKABLE void connect();
|
||||
/// Attempt to connect to the network with a specific @@nmSettings entry.
|
||||
///
|
||||
/// > [!WARNING] Only valid for the NetworkManager backend.
|
||||
Q_INVOKABLE void connectWithSettings(NMSettings* settings);
|
||||
/// Disconnect from the network.
|
||||
Q_INVOKABLE void disconnect();
|
||||
/// Forget all connection settings for this network.
|
||||
Q_INVOKABLE void forget();
|
||||
|
||||
[[nodiscard]] QString name() const { return this->mName; };
|
||||
void settingsAdded(NMSettings* settings);
|
||||
void settingsRemoved(NMSettings* settings);
|
||||
|
||||
// clang-format off
|
||||
[[nodiscard]] QString name() const { return this->mName; }
|
||||
[[nodiscard]] const QList<NMSettings*>& nmSettings() const { return this->bNmSettings; }
|
||||
QBindable<QList<NMSettings*>> bindableNmSettings() const { return &this->bNmSettings; }
|
||||
QBindable<bool> bindableConnected() { return &this->bConnected; }
|
||||
QBindable<NetworkState::Enum> bindableState() { return &this->bState; }
|
||||
QBindable<bool> bindableKnown() { return &this->bKnown; }
|
||||
[[nodiscard]] ConnectionState::Enum state() const { return this->bState; }
|
||||
QBindable<ConnectionState::Enum> bindableState() { return &this->bState; }
|
||||
QBindable<bool> bindableStateChanging() { return &this->bStateChanging; }
|
||||
// clang-format on
|
||||
|
||||
signals:
|
||||
/// Signals that a connection to the network has failed because of the given @@ConnectionFailReason.
|
||||
void connectionFailed(ConnectionFailReason::Enum reason);
|
||||
|
||||
void connectedChanged();
|
||||
void knownChanged();
|
||||
void stateChanged();
|
||||
void stateChangingChanged();
|
||||
void nmSettingsChanged();
|
||||
QSDOC_HIDE void requestConnect();
|
||||
QSDOC_HIDE void requestConnectWithSettings(NMSettings* settings);
|
||||
QSDOC_HIDE void requestDisconnect();
|
||||
QSDOC_HIDE void requestForget();
|
||||
|
||||
protected:
|
||||
QString mName;
|
||||
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Network, bool, bConnected, &Network::connectedChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Network, NetworkState::Enum, bState, &Network::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Network, bool, bKnown, &Network::knownChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Network, ConnectionState::Enum, bState, &Network::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Network, bool, bStateChanging, &Network::stateChangingChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Network, QList<NMSettings*>, bNmSettings, &Network::nmSettingsChanged);
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
} // namespace qs::network
|
||||
@@ -63,10 +63,12 @@ qt_add_dbus_interface(NM_DBUS_INTERFACES
|
||||
qt_add_library(quickshell-network-nm STATIC
|
||||
backend.cpp
|
||||
device.cpp
|
||||
connection.cpp
|
||||
active_connection.cpp
|
||||
settings.cpp
|
||||
accesspoint.cpp
|
||||
wireless.cpp
|
||||
utils.cpp
|
||||
dbus_types.cpp
|
||||
enums.hpp
|
||||
${NM_DBUS_INTERFACES}
|
||||
)
|
||||
|
||||
@@ -48,14 +48,14 @@ public:
|
||||
[[nodiscard]] bool isValid() const;
|
||||
[[nodiscard]] QString path() const;
|
||||
[[nodiscard]] QString address() const;
|
||||
[[nodiscard]] QByteArray ssid() const { return this->bSsid; };
|
||||
[[nodiscard]] quint8 signalStrength() const { return this->bSignalStrength; };
|
||||
[[nodiscard]] NM80211ApFlags::Enum flags() const { return this->bFlags; };
|
||||
[[nodiscard]] NM80211ApSecurityFlags::Enum wpaFlags() const { return this->bWpaFlags; };
|
||||
[[nodiscard]] NM80211ApSecurityFlags::Enum rsnFlags() const { return this->bRsnFlags; };
|
||||
[[nodiscard]] NM80211Mode::Enum mode() const { return this->bMode; };
|
||||
[[nodiscard]] QBindable<WifiSecurityType::Enum> bindableSecurity() { return &this->bSecurity; };
|
||||
[[nodiscard]] WifiSecurityType::Enum security() const { return this->bSecurity; };
|
||||
[[nodiscard]] QByteArray ssid() const { return this->bSsid; }
|
||||
[[nodiscard]] quint8 signalStrength() const { return this->bSignalStrength; }
|
||||
[[nodiscard]] NM80211ApFlags::Enum flags() const { return this->bFlags; }
|
||||
[[nodiscard]] NM80211ApSecurityFlags::Enum wpaFlags() const { return this->bWpaFlags; }
|
||||
[[nodiscard]] NM80211ApSecurityFlags::Enum rsnFlags() const { return this->bRsnFlags; }
|
||||
[[nodiscard]] NM80211Mode::Enum mode() const { return this->bMode; }
|
||||
[[nodiscard]] QBindable<WifiSecurityType::Enum> bindableSecurity() { return &this->bSecurity; }
|
||||
[[nodiscard]] WifiSecurityType::Enum security() const { return this->bSecurity; }
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "active_connection.hpp"
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdbusconnection.h>
|
||||
#include <qdbuspendingcall.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_nm_active_connection.h"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
using namespace qs::dbus;
|
||||
|
||||
namespace {
|
||||
QS_LOGGING_CATEGORY(logNetworkManager, "quickshell.network.networkmanager", QtWarningMsg);
|
||||
}
|
||||
|
||||
NMActiveConnection::NMActiveConnection(const QString& path, QObject* parent): QObject(parent) {
|
||||
this->proxy = new DBusNMActiveConnectionProxy(
|
||||
"org.freedesktop.NetworkManager",
|
||||
path,
|
||||
QDBusConnection::systemBus(),
|
||||
this
|
||||
);
|
||||
|
||||
if (!this->proxy->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Cannot create DBus interface for connection at" << path;
|
||||
return;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(&this->activeConnectionProperties, &DBusPropertyGroup::getAllFinished, this, &NMActiveConnection::loaded, Qt::SingleShotConnection);
|
||||
QObject::connect(this->proxy, &DBusNMActiveConnectionProxy::StateChanged, this, &NMActiveConnection::onStateChanged);
|
||||
// clang-format on
|
||||
|
||||
this->activeConnectionProperties.setInterface(this->proxy);
|
||||
this->activeConnectionProperties.updateAllViaGetAll();
|
||||
}
|
||||
|
||||
void NMActiveConnection::onStateChanged(quint32 /*state*/, quint32 reason) {
|
||||
auto enumReason = static_cast<NMConnectionStateReason::Enum>(reason);
|
||||
if (this->bStateReason == enumReason) return;
|
||||
this->bStateReason = enumReason;
|
||||
}
|
||||
|
||||
bool NMActiveConnection::isValid() const { return this->proxy && this->proxy->isValid(); }
|
||||
QString NMActiveConnection::address() const {
|
||||
return this->proxy ? this->proxy->service() : QString();
|
||||
}
|
||||
QString NMActiveConnection::path() const { return this->proxy ? this->proxy->path() : QString(); }
|
||||
|
||||
} // namespace qs::network
|
||||
|
||||
namespace qs::dbus {
|
||||
|
||||
DBusResult<qs::network::NMConnectionState::Enum>
|
||||
DBusDataTransform<qs::network::NMConnectionState::Enum>::fromWire(quint32 wire) {
|
||||
return DBusResult(static_cast<qs::network::NMConnectionState::Enum>(wire));
|
||||
}
|
||||
|
||||
} // namespace qs::dbus
|
||||
@@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qdbusextratypes.h>
|
||||
#include <qdbuspendingcall.h>
|
||||
#include <qdbuspendingreply.h>
|
||||
#include <qobject.h>
|
||||
#include <qproperty.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../wifi.hpp"
|
||||
#include "dbus_nm_active_connection.h"
|
||||
#include "dbus_nm_connection_settings.h"
|
||||
#include "dbus_types.hpp"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::dbus {
|
||||
@@ -28,40 +26,6 @@ struct DBusDataTransform<qs::network::NMConnectionState::Enum> {
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
// Proxy of a /org/freedesktop/NetworkManager/Settings/Connection/* object.
|
||||
class NMConnectionSettings: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit NMConnectionSettings(const QString& path, QObject* parent = nullptr);
|
||||
|
||||
void forget();
|
||||
|
||||
[[nodiscard]] bool isValid() const;
|
||||
[[nodiscard]] QString path() const;
|
||||
[[nodiscard]] QString address() const;
|
||||
[[nodiscard]] ConnectionSettingsMap settings() const { return this->bSettings; };
|
||||
[[nodiscard]] WifiSecurityType::Enum security() const { return this->bSecurity; };
|
||||
[[nodiscard]] QBindable<WifiSecurityType::Enum> bindableSecurity() { return &this->bSecurity; };
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
void settingsChanged(ConnectionSettingsMap settings);
|
||||
void securityChanged(WifiSecurityType::Enum security);
|
||||
void ssidChanged(QString ssid);
|
||||
|
||||
private:
|
||||
bool mLoaded = false;
|
||||
void updateSettings();
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMConnectionSettings, ConnectionSettingsMap, bSettings, &NMConnectionSettings::settingsChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMConnectionSettings, WifiSecurityType::Enum, bSecurity, &NMConnectionSettings::securityChanged);
|
||||
QS_DBUS_BINDABLE_PROPERTY_GROUP(NMConnectionSettings, connectionSettingsProperties);
|
||||
// clang-format on
|
||||
|
||||
DBusNMConnectionSettingsProxy* proxy = nullptr;
|
||||
};
|
||||
|
||||
// Proxy of a /org/freedesktop/NetworkManager/ActiveConnection/* object.
|
||||
class NMActiveConnection: public QObject {
|
||||
Q_OBJECT;
|
||||
@@ -72,31 +36,27 @@ public:
|
||||
[[nodiscard]] bool isValid() const;
|
||||
[[nodiscard]] QString path() const;
|
||||
[[nodiscard]] QString address() const;
|
||||
[[nodiscard]] QDBusObjectPath connection() const { return this->bConnection; };
|
||||
[[nodiscard]] NMConnectionState::Enum state() const { return this->bState; };
|
||||
[[nodiscard]] NMConnectionStateReason::Enum stateReason() const { return this->mStateReason; };
|
||||
[[nodiscard]] QDBusObjectPath connection() const { return this->bConnection; }
|
||||
[[nodiscard]] NMConnectionState::Enum state() const { return this->bState; }
|
||||
[[nodiscard]] NMConnectionStateReason::Enum stateReason() const { return this->bStateReason; }
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
void connectionChanged(QDBusObjectPath path);
|
||||
void stateChanged(NMConnectionState::Enum state);
|
||||
void stateReasonChanged(NMConnectionStateReason::Enum reason);
|
||||
void uuidChanged(const QString& uuid);
|
||||
|
||||
private slots:
|
||||
void onStateChanged(quint32 state, quint32 reason);
|
||||
|
||||
private:
|
||||
NMConnectionStateReason::Enum mStateReason = NMConnectionStateReason::Unknown;
|
||||
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMActiveConnection, QDBusObjectPath, bConnection, &NMActiveConnection::connectionChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMActiveConnection, QString, bUuid, &NMActiveConnection::uuidChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMActiveConnection, NMConnectionState::Enum, bState, &NMActiveConnection::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMActiveConnection, NMConnectionStateReason::Enum, bStateReason, &NMActiveConnection::stateReasonChanged);
|
||||
|
||||
QS_DBUS_BINDABLE_PROPERTY_GROUP(NMActiveConnection, activeConnectionProperties);
|
||||
QS_DBUS_PROPERTY_BINDING(NMActiveConnection, pConnection, bConnection, activeConnectionProperties, "Connection");
|
||||
QS_DBUS_PROPERTY_BINDING(NMActiveConnection, pUuid, bUuid, activeConnectionProperties, "Uuid");
|
||||
QS_DBUS_PROPERTY_BINDING(NMActiveConnection, pState, bState, activeConnectionProperties, "State");
|
||||
// clang-format on
|
||||
DBusNMActiveConnectionProxy* proxy = nullptr;
|
||||
+49
-14
@@ -1,5 +1,6 @@
|
||||
#include "backend.hpp"
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qdbusconnection.h>
|
||||
#include <qdbusextratypes.h>
|
||||
#include <qdbusmetatype.h>
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../device.hpp"
|
||||
#include "../enums.hpp"
|
||||
#include "../network.hpp"
|
||||
#include "../wifi.hpp"
|
||||
#include "dbus_nm_backend.h"
|
||||
@@ -31,7 +33,8 @@ QS_LOGGING_CATEGORY(logNetworkManager, "quickshell.network.networkmanager", QtWa
|
||||
}
|
||||
|
||||
NetworkManager::NetworkManager(QObject* parent): NetworkBackend(parent) {
|
||||
qDBusRegisterMetaType<ConnectionSettingsMap>();
|
||||
qCDebug(logNetworkManager) << "Connecting to NetworkManager";
|
||||
qDBusRegisterMetaType<NMSettingsMap>();
|
||||
|
||||
auto bus = QDBusConnection::systemBus();
|
||||
if (!bus.isConnected()) {
|
||||
@@ -69,6 +72,23 @@ void NetworkManager::init() {
|
||||
this->registerDevices();
|
||||
}
|
||||
|
||||
void NetworkManager::checkConnectivity() {
|
||||
auto pending = this->proxy->CheckConnectivity();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
auto responseCallback = [](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<quint32> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCInfo(logNetworkManager) << "Failed to check connectivity: " << reply.error().message();
|
||||
}
|
||||
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
void NetworkManager::registerDevices() {
|
||||
auto pending = this->proxy->GetAllDevices();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
@@ -117,23 +137,21 @@ void NetworkManager::registerDevice(const QString& path) {
|
||||
}
|
||||
|
||||
if (dev) {
|
||||
qCDebug(logNetworkManager) << "Device added:" << path;
|
||||
if (!dev->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Ignoring invalid registration of" << path;
|
||||
delete dev;
|
||||
} else {
|
||||
this->mDevices[path] = dev;
|
||||
// Only register a frontend device while it's managed by NM.
|
||||
auto onManagedChanged = [this, dev, type](bool managed) {
|
||||
managed ? this->registerFrontendDevice(type, dev) : this->removeFrontendDevice(dev);
|
||||
};
|
||||
// clang-format off
|
||||
QObject::connect(dev, &NMDevice::addAndActivateConnection, this, &NetworkManager::addAndActivateConnection);
|
||||
QObject::connect(dev, &NMDevice::activateConnection, this, &NetworkManager::activateConnection);
|
||||
QObject::connect(dev, &NMDevice::managedChanged, this, onManagedChanged);
|
||||
// clang-format on
|
||||
|
||||
if (dev->managed()) this->registerFrontendDevice(type, dev);
|
||||
this->registerFrontendDevice(type, dev);
|
||||
}
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Ignoring registration of unsupported device:" << path;
|
||||
}
|
||||
temp->deleteLater();
|
||||
}
|
||||
@@ -173,21 +191,22 @@ void NetworkManager::registerFrontendDevice(NMDeviceType::Enum type, NMDevice* d
|
||||
// Bind generic NetworkDevice properties
|
||||
auto translateState = [dev]() {
|
||||
switch (dev->state()) {
|
||||
case 0 ... 20: return DeviceConnectionState::Unknown;
|
||||
case 30: return DeviceConnectionState::Disconnected;
|
||||
case 40 ... 90: return DeviceConnectionState::Connecting;
|
||||
case 100: return DeviceConnectionState::Connected;
|
||||
case 110 ... 120: return DeviceConnectionState::Disconnecting;
|
||||
case 0 ... 20: return ConnectionState::Unknown;
|
||||
case 30: return ConnectionState::Disconnected;
|
||||
case 40 ... 90: return ConnectionState::Connecting;
|
||||
case 100: return ConnectionState::Connected;
|
||||
case 110 ... 120: return ConnectionState::Disconnecting;
|
||||
}
|
||||
};
|
||||
// clang-format off
|
||||
frontendDev->bindableName().setBinding([dev]() { return dev->interface(); });
|
||||
frontendDev->bindableAddress().setBinding([dev]() { return dev->hwAddress(); });
|
||||
frontendDev->bindableNmState().setBinding([dev]() { return dev->state(); });
|
||||
frontendDev->bindableState().setBinding(translateState);
|
||||
frontendDev->bindableAutoconnect().setBinding([dev]() { return dev->autoconnect(); });
|
||||
frontendDev->bindableNmManaged().setBinding([dev]() { return dev->managed(); });
|
||||
QObject::connect(frontendDev, &WifiDevice::requestDisconnect, dev, &NMDevice::disconnect);
|
||||
QObject::connect(frontendDev, &NetworkDevice::requestSetAutoconnect, dev, &NMDevice::setAutoconnect);
|
||||
QObject::connect(frontendDev, &NetworkDevice::requestSetNmManaged, dev, &NMDevice::setManaged);
|
||||
// clang-format on
|
||||
|
||||
this->mFrontendDevices.insert(dev->path(), frontendDev);
|
||||
@@ -215,6 +234,7 @@ void NetworkManager::onDevicePathRemoved(const QDBusObjectPath& path) {
|
||||
auto* dev = iter.value();
|
||||
this->mDevices.erase(iter);
|
||||
if (dev) {
|
||||
qCDebug(logNetworkManager) << "Device removed:" << path.path();
|
||||
this->removeFrontendDevice(dev);
|
||||
delete dev;
|
||||
}
|
||||
@@ -240,7 +260,7 @@ void NetworkManager::activateConnection(
|
||||
}
|
||||
|
||||
void NetworkManager::addAndActivateConnection(
|
||||
const ConnectionSettingsMap& settings,
|
||||
const NMSettingsMap& settings,
|
||||
const QDBusObjectPath& devPath,
|
||||
const QDBusObjectPath& specificObjectPath
|
||||
) {
|
||||
@@ -259,6 +279,12 @@ void NetworkManager::addAndActivateConnection(
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
void NetworkManager::setConnectivityCheckEnabled(bool enabled) {
|
||||
if (enabled == this->bConnectivityCheckEnabled) return;
|
||||
this->bConnectivityCheckEnabled = enabled;
|
||||
this->pConnectivityCheckEnabled.write();
|
||||
}
|
||||
|
||||
void NetworkManager::setWifiEnabled(bool enabled) {
|
||||
if (enabled == this->bWifiEnabled) return;
|
||||
this->bWifiEnabled = enabled;
|
||||
@@ -268,3 +294,12 @@ void NetworkManager::setWifiEnabled(bool enabled) {
|
||||
bool NetworkManager::isAvailable() const { return this->proxy && this->proxy->isValid(); };
|
||||
|
||||
} // namespace qs::network
|
||||
|
||||
namespace qs::dbus {
|
||||
|
||||
DBusResult<qs::network::NMConnectivityState::Enum>
|
||||
DBusDataTransform<qs::network::NMConnectivityState::Enum>::fromWire(quint32 wire) {
|
||||
return DBusResult(static_cast<qs::network::NMConnectivityState::Enum>(wire));
|
||||
}
|
||||
|
||||
} // namespace qs::dbus
|
||||
@@ -10,7 +10,20 @@
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../network.hpp"
|
||||
#include "dbus_nm_backend.h"
|
||||
#include "dbus_types.hpp"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::dbus {
|
||||
|
||||
template <>
|
||||
struct DBusDataTransform<qs::network::NMConnectivityState::Enum> {
|
||||
using Wire = quint32;
|
||||
using Data = qs::network::NMConnectivityState::Enum;
|
||||
static DBusResult<Data> fromWire(Wire wire);
|
||||
};
|
||||
|
||||
} // namespace qs::dbus
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
@@ -21,24 +34,34 @@ public:
|
||||
explicit NetworkManager(QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] bool isAvailable() const override;
|
||||
[[nodiscard]] bool wifiEnabled() const { return this->bWifiEnabled; };
|
||||
[[nodiscard]] bool wifiHardwareEnabled() const { return this->bWifiHardwareEnabled; };
|
||||
[[nodiscard]] bool wifiEnabled() const { return this->bWifiEnabled; }
|
||||
[[nodiscard]] bool wifiHardwareEnabled() const { return this->bWifiHardwareEnabled; }
|
||||
[[nodiscard]] bool connectivityCheckAvailable() const {
|
||||
return this->bConnectivityCheckAvailable;
|
||||
};
|
||||
[[nodiscard]] bool connectivityCheckEnabled() const { return this->bConnectivityCheckEnabled; }
|
||||
[[nodiscard]] NMConnectivityState::Enum connectivity() const { return this->bConnectivity; }
|
||||
|
||||
signals:
|
||||
void deviceAdded(NetworkDevice* device);
|
||||
void deviceRemoved(NetworkDevice* device);
|
||||
void wifiEnabledChanged(bool enabled);
|
||||
void wifiHardwareEnabledChanged(bool enabled);
|
||||
void connectivityStateChanged(NMConnectivityState::Enum state);
|
||||
void connectivityCheckAvailableChanged(bool available);
|
||||
void connectivityCheckEnabledChanged(bool enabled);
|
||||
|
||||
public slots:
|
||||
void setWifiEnabled(bool enabled);
|
||||
void setConnectivityCheckEnabled(bool enabled);
|
||||
void checkConnectivity();
|
||||
|
||||
private slots:
|
||||
void onDevicePathAdded(const QDBusObjectPath& path);
|
||||
void onDevicePathRemoved(const QDBusObjectPath& path);
|
||||
void activateConnection(const QDBusObjectPath& connPath, const QDBusObjectPath& devPath);
|
||||
void addAndActivateConnection(
|
||||
const ConnectionSettingsMap& settings,
|
||||
const NMSettingsMap& settings,
|
||||
const QDBusObjectPath& devPath,
|
||||
const QDBusObjectPath& specificObjectPath
|
||||
);
|
||||
@@ -56,10 +79,16 @@ private:
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkManager, bool, bWifiEnabled, &NetworkManager::wifiEnabledChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkManager, bool, bWifiHardwareEnabled, &NetworkManager::wifiHardwareEnabledChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkManager, NMConnectivityState::Enum, bConnectivity, &NetworkManager::connectivityStateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkManager, bool, bConnectivityCheckAvailable, &NetworkManager::connectivityCheckAvailableChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NetworkManager, bool, bConnectivityCheckEnabled, &NetworkManager::connectivityCheckEnabledChanged);
|
||||
|
||||
QS_DBUS_BINDABLE_PROPERTY_GROUP(NetworkManager, dbusProperties);
|
||||
QS_DBUS_PROPERTY_BINDING(NetworkManager, pWifiEnabled, bWifiEnabled, dbusProperties, "WirelessEnabled");
|
||||
QS_DBUS_PROPERTY_BINDING(NetworkManager, pWifiHardwareEnabled, bWifiHardwareEnabled, dbusProperties, "WirelessHardwareEnabled");
|
||||
QS_DBUS_PROPERTY_BINDING(NetworkManager, pConnectivity, bConnectivity, dbusProperties, "Connectivity");
|
||||
QS_DBUS_PROPERTY_BINDING(NetworkManager, pConnectivityCheckAvailable, bConnectivityCheckAvailable, dbusProperties, "ConnectivityCheckAvailable");
|
||||
QS_DBUS_PROPERTY_BINDING(NetworkManager, pConnectivityCheckEnabled, bConnectivityCheckEnabled, dbusProperties, "ConnectivityCheckEnabled");
|
||||
// clang-format on
|
||||
DBusNetworkManagerProxy* proxy = nullptr;
|
||||
};
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
#include "connection.hpp"
|
||||
|
||||
#include <qdbusconnection.h>
|
||||
#include <qdbusmetatype.h>
|
||||
#include <qdbuspendingcall.h>
|
||||
#include <qdbuspendingreply.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../wifi.hpp"
|
||||
#include "dbus_nm_active_connection.h"
|
||||
#include "dbus_nm_connection_settings.h"
|
||||
#include "dbus_types.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
using namespace qs::dbus;
|
||||
|
||||
namespace {
|
||||
QS_LOGGING_CATEGORY(logNetworkManager, "quickshell.network.networkmanager", QtWarningMsg);
|
||||
}
|
||||
|
||||
NMConnectionSettings::NMConnectionSettings(const QString& path, QObject* parent): QObject(parent) {
|
||||
qDBusRegisterMetaType<ConnectionSettingsMap>();
|
||||
|
||||
this->proxy = new DBusNMConnectionSettingsProxy(
|
||||
"org.freedesktop.NetworkManager",
|
||||
path,
|
||||
QDBusConnection::systemBus(),
|
||||
this
|
||||
);
|
||||
|
||||
if (!this->proxy->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Cannot create DBus interface for connection at" << path;
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
this->proxy,
|
||||
&DBusNMConnectionSettingsProxy::Updated,
|
||||
this,
|
||||
&NMConnectionSettings::updateSettings
|
||||
);
|
||||
this->bSecurity.setBinding([this]() { return securityFromConnectionSettings(this->bSettings); });
|
||||
|
||||
this->connectionSettingsProperties.setInterface(this->proxy);
|
||||
this->connectionSettingsProperties.updateAllViaGetAll();
|
||||
|
||||
this->updateSettings();
|
||||
}
|
||||
|
||||
void NMConnectionSettings::updateSettings() {
|
||||
auto pending = this->proxy->GetSettings();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
auto responseCallback = [this](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<ConnectionSettingsMap> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCWarning(logNetworkManager)
|
||||
<< "Failed to get" << this->path() << "settings:" << reply.error().message();
|
||||
} else {
|
||||
this->bSettings = reply.value();
|
||||
}
|
||||
|
||||
if (!this->mLoaded) {
|
||||
emit this->loaded();
|
||||
this->mLoaded = true;
|
||||
}
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
void NMConnectionSettings::forget() {
|
||||
auto pending = this->proxy->Delete();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
auto responseCallback = [this](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCWarning(logNetworkManager)
|
||||
<< "Failed to forget" << this->path() << ":" << reply.error().message();
|
||||
}
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
bool NMConnectionSettings::isValid() const { return this->proxy && this->proxy->isValid(); }
|
||||
QString NMConnectionSettings::address() const {
|
||||
return this->proxy ? this->proxy->service() : QString();
|
||||
}
|
||||
QString NMConnectionSettings::path() const { return this->proxy ? this->proxy->path() : QString(); }
|
||||
|
||||
NMActiveConnection::NMActiveConnection(const QString& path, QObject* parent): QObject(parent) {
|
||||
this->proxy = new DBusNMActiveConnectionProxy(
|
||||
"org.freedesktop.NetworkManager",
|
||||
path,
|
||||
QDBusConnection::systemBus(),
|
||||
this
|
||||
);
|
||||
|
||||
if (!this->proxy->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Cannot create DBus interface for connection at" << path;
|
||||
return;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(&this->activeConnectionProperties, &DBusPropertyGroup::getAllFinished, this, &NMActiveConnection::loaded, Qt::SingleShotConnection);
|
||||
QObject::connect(this->proxy, &DBusNMActiveConnectionProxy::StateChanged, this, &NMActiveConnection::onStateChanged);
|
||||
// clang-format on
|
||||
|
||||
this->activeConnectionProperties.setInterface(this->proxy);
|
||||
this->activeConnectionProperties.updateAllViaGetAll();
|
||||
}
|
||||
|
||||
void NMActiveConnection::onStateChanged(quint32 /*state*/, quint32 reason) {
|
||||
auto enumReason = static_cast<NMConnectionStateReason::Enum>(reason);
|
||||
if (this->mStateReason == enumReason) return;
|
||||
this->mStateReason = enumReason;
|
||||
emit this->stateReasonChanged(enumReason);
|
||||
}
|
||||
|
||||
bool NMActiveConnection::isValid() const { return this->proxy && this->proxy->isValid(); }
|
||||
QString NMActiveConnection::address() const {
|
||||
return this->proxy ? this->proxy->service() : QString();
|
||||
}
|
||||
QString NMActiveConnection::path() const { return this->proxy ? this->proxy->path() : QString(); }
|
||||
|
||||
} // namespace qs::network
|
||||
|
||||
namespace qs::dbus {
|
||||
|
||||
DBusResult<qs::network::NMConnectionState::Enum>
|
||||
DBusDataTransform<qs::network::NMConnectionState::Enum>::fromWire(quint32 wire) {
|
||||
return DBusResult(static_cast<qs::network::NMConnectionState::Enum>(wire));
|
||||
}
|
||||
|
||||
} // namespace qs::dbus
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "dbus_types.hpp"
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdbusargument.h>
|
||||
#include <qmap.h>
|
||||
#include <qmetatype.h>
|
||||
#include <qstring.h>
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, NMSettingsMap& map) {
|
||||
argument.beginMap();
|
||||
while (!argument.atEnd()) {
|
||||
argument.beginMapEntry();
|
||||
QString groupName;
|
||||
argument >> groupName;
|
||||
|
||||
QVariantMap group;
|
||||
argument >> group;
|
||||
|
||||
map.insert(groupName, group);
|
||||
argument.endMapEntry();
|
||||
}
|
||||
argument.endMap();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const NMSettingsMap& map) {
|
||||
argument.beginMap(qMetaTypeId<QString>(), qMetaTypeId<QVariantMap>());
|
||||
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
|
||||
argument.beginMapEntry();
|
||||
argument << it.key();
|
||||
argument << it.value();
|
||||
argument.endMapEntry();
|
||||
}
|
||||
argument.endMap();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, NMIPv6Address& addr) {
|
||||
argument.beginStructure();
|
||||
argument >> addr.address >> addr.prefix >> addr.gateway;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const NMIPv6Address& addr) {
|
||||
argument.beginStructure();
|
||||
argument << addr.address << addr.prefix << addr.gateway;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, NMIPv6Route& route) {
|
||||
argument.beginStructure();
|
||||
argument >> route.destination >> route.prefix >> route.nexthop >> route.metric;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const NMIPv6Route& route) {
|
||||
argument.beginStructure();
|
||||
argument << route.destination << route.prefix << route.nexthop << route.metric;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
} // namespace qs::network
|
||||
@@ -1,9 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <qdbusextratypes.h>
|
||||
#include <qbytearray.h>
|
||||
#include <qdbusargument.h>
|
||||
#include <qmap.h>
|
||||
#include <qstring.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
using ConnectionSettingsMap = QMap<QString, QVariantMap>;
|
||||
Q_DECLARE_METATYPE(ConnectionSettingsMap);
|
||||
namespace qs::network {
|
||||
|
||||
using NMSettingsMap = QMap<QString, QVariantMap>;
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, NMSettingsMap& map);
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const NMSettingsMap& map);
|
||||
|
||||
struct NMIPv6Address {
|
||||
QByteArray address;
|
||||
quint32 prefix = 0;
|
||||
QByteArray gateway;
|
||||
};
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, qs::network::NMIPv6Address& addr);
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const qs::network::NMIPv6Address& addr);
|
||||
|
||||
struct NMIPv6Route {
|
||||
QByteArray destination;
|
||||
quint32 prefix = 0;
|
||||
QByteArray nexthop;
|
||||
quint32 metric = 0;
|
||||
};
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, qs::network::NMIPv6Route& route);
|
||||
const QDBusArgument& operator<<(QDBusArgument& argument, const qs::network::NMIPv6Route& route);
|
||||
|
||||
} // namespace qs::network
|
||||
|
||||
Q_DECLARE_METATYPE(qs::network::NMSettingsMap);
|
||||
Q_DECLARE_METATYPE(qs::network::NMIPv6Address);
|
||||
Q_DECLARE_METATYPE(qs::network::NMIPv6Route);
|
||||
+39
-19
@@ -14,9 +14,10 @@
|
||||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../device.hpp"
|
||||
#include "connection.hpp"
|
||||
#include "active_connection.hpp"
|
||||
#include "dbus_nm_device.h"
|
||||
#include "enums.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
using namespace qs::dbus;
|
||||
@@ -39,19 +40,29 @@ NMDevice::NMDevice(const QString& path, QObject* parent): QObject(parent) {
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(this, &NMDevice::availableConnectionPathsChanged, this, &NMDevice::onAvailableConnectionPathsChanged);
|
||||
QObject::connect(this, &NMDevice::availableSettingsPathsChanged, this, &NMDevice::onAvailableSettingsPathsChanged);
|
||||
QObject::connect(this, &NMDevice::activeConnectionPathChanged, this, &NMDevice::onActiveConnectionPathChanged);
|
||||
QObject::connect(this->deviceProxy, &DBusNMDeviceProxy::StateChanged, this, &NMDevice::onStateChanged);
|
||||
// clang-format on
|
||||
|
||||
this->deviceProperties.setInterface(this->deviceProxy);
|
||||
this->deviceProperties.updateAllViaGetAll();
|
||||
}
|
||||
|
||||
void NMDevice::onStateChanged(quint32 newState, quint32 /*oldState*/, quint32 reason) {
|
||||
auto enumReason = static_cast<NMDeviceStateReason::Enum>(reason);
|
||||
auto enumNewState = static_cast<NMDeviceState::Enum>(newState);
|
||||
if (enumNewState == NMDeviceState::Failed) this->bLastFailReason = enumReason;
|
||||
if (this->bStateReason == enumReason) return;
|
||||
this->bStateReason = enumReason;
|
||||
}
|
||||
|
||||
void NMDevice::onActiveConnectionPathChanged(const QDBusObjectPath& path) {
|
||||
const QString stringPath = path.path();
|
||||
|
||||
// Remove old active connection
|
||||
if (this->mActiveConnection) {
|
||||
qCDebug(logNetworkManager) << "Active connection removed:" << this->mActiveConnection->path();
|
||||
QObject::disconnect(this->mActiveConnection, nullptr, this, nullptr);
|
||||
delete this->mActiveConnection;
|
||||
this->mActiveConnection = nullptr;
|
||||
@@ -64,6 +75,7 @@ void NMDevice::onActiveConnectionPathChanged(const QDBusObjectPath& path) {
|
||||
qCWarning(logNetworkManager) << "Ignoring invalid registration of" << stringPath;
|
||||
delete active;
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Active connection added:" << stringPath;
|
||||
this->mActiveConnection = active;
|
||||
QObject::connect(
|
||||
active,
|
||||
@@ -76,42 +88,44 @@ void NMDevice::onActiveConnectionPathChanged(const QDBusObjectPath& path) {
|
||||
}
|
||||
}
|
||||
|
||||
void NMDevice::onAvailableConnectionPathsChanged(const QList<QDBusObjectPath>& paths) {
|
||||
void NMDevice::onAvailableSettingsPathsChanged(const QList<QDBusObjectPath>& paths) {
|
||||
QSet<QString> newPathSet;
|
||||
for (const QDBusObjectPath& path: paths) {
|
||||
newPathSet.insert(path.path());
|
||||
}
|
||||
const auto existingPaths = this->mConnections.keys();
|
||||
const auto existingPaths = this->mSettings.keys();
|
||||
const QSet<QString> existingPathSet(existingPaths.begin(), existingPaths.end());
|
||||
|
||||
const auto addedConnections = newPathSet - existingPathSet;
|
||||
const auto removedConnections = existingPathSet - newPathSet;
|
||||
const auto addedSettings = newPathSet - existingPathSet;
|
||||
const auto removedSettings = existingPathSet - newPathSet;
|
||||
|
||||
for (const QString& path: addedConnections) {
|
||||
this->registerConnection(path);
|
||||
for (const QString& path: addedSettings) {
|
||||
this->registerSettings(path);
|
||||
}
|
||||
for (const QString& path: removedConnections) {
|
||||
auto* connection = this->mConnections.take(path);
|
||||
for (const QString& path: removedSettings) {
|
||||
auto* connection = this->mSettings.take(path);
|
||||
if (!connection) {
|
||||
qCDebug(logNetworkManager) << "Sent removal signal for" << path << "which is not registered.";
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Connection settings removed:" << path;
|
||||
delete connection;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void NMDevice::registerConnection(const QString& path) {
|
||||
auto* connection = new NMConnectionSettings(path, this);
|
||||
if (!connection->isValid()) {
|
||||
void NMDevice::registerSettings(const QString& path) {
|
||||
auto* settings = new NMSettings(path, this);
|
||||
if (!settings->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Ignoring invalid registration of" << path;
|
||||
delete connection;
|
||||
delete settings;
|
||||
} else {
|
||||
this->mConnections.insert(path, connection);
|
||||
qCDebug(logNetworkManager) << "Connection settings added:" << path;
|
||||
this->mSettings.insert(path, settings);
|
||||
QObject::connect(
|
||||
connection,
|
||||
&NMConnectionSettings::loaded,
|
||||
settings,
|
||||
&NMSettings::loaded,
|
||||
this,
|
||||
[this, connection]() { emit this->connectionLoaded(connection); },
|
||||
[this, settings]() { emit this->settingsLoaded(settings); },
|
||||
Qt::SingleShotConnection
|
||||
);
|
||||
}
|
||||
@@ -125,6 +139,12 @@ void NMDevice::setAutoconnect(bool autoconnect) {
|
||||
this->pAutoconnect.write();
|
||||
}
|
||||
|
||||
void NMDevice::setManaged(bool managed) {
|
||||
if (managed == this->bManaged) return;
|
||||
this->bManaged = managed;
|
||||
this->pManaged.write();
|
||||
}
|
||||
|
||||
bool NMDevice::isValid() const { return this->deviceProxy && this->deviceProxy->isValid(); }
|
||||
QString NMDevice::address() const {
|
||||
return this->deviceProxy ? this->deviceProxy->service() : QString();
|
||||
|
||||
+25
-15
@@ -8,8 +8,10 @@
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "connection.hpp"
|
||||
#include "../enums.hpp"
|
||||
#include "active_connection.hpp"
|
||||
#include "dbus_nm_device.h"
|
||||
#include "settings.hpp"
|
||||
|
||||
namespace qs::dbus {
|
||||
|
||||
@@ -36,43 +38,49 @@ public:
|
||||
[[nodiscard]] virtual bool isValid() const;
|
||||
[[nodiscard]] QString path() const;
|
||||
[[nodiscard]] QString address() const;
|
||||
[[nodiscard]] QString interface() const { return this->bInterface; };
|
||||
[[nodiscard]] QString hwAddress() const { return this->bHwAddress; };
|
||||
[[nodiscard]] bool managed() const { return this->bManaged; };
|
||||
[[nodiscard]] NMDeviceState::Enum state() const { return this->bState; };
|
||||
[[nodiscard]] bool autoconnect() const { return this->bAutoconnect; };
|
||||
[[nodiscard]] NMActiveConnection* activeConnection() const { return this->mActiveConnection; };
|
||||
[[nodiscard]] QString interface() const { return this->bInterface; }
|
||||
[[nodiscard]] QString hwAddress() const { return this->bHwAddress; }
|
||||
[[nodiscard]] bool managed() const { return this->bManaged; }
|
||||
[[nodiscard]] NMDeviceState::Enum state() const { return this->bState; }
|
||||
[[nodiscard]] NMDeviceStateReason::Enum stateReason() const { return this->bStateReason; }
|
||||
[[nodiscard]] NMDeviceStateReason::Enum lastFailReason() const { return this->bLastFailReason; }
|
||||
[[nodiscard]] bool autoconnect() const { return this->bAutoconnect; }
|
||||
[[nodiscard]] NMActiveConnection* activeConnection() const { return this->mActiveConnection; }
|
||||
|
||||
signals:
|
||||
void activateConnection(const QDBusObjectPath& connPath, const QDBusObjectPath& devPath);
|
||||
void addAndActivateConnection(
|
||||
const ConnectionSettingsMap& settings,
|
||||
const NMSettingsMap& settings,
|
||||
const QDBusObjectPath& devPath,
|
||||
const QDBusObjectPath& apPath
|
||||
);
|
||||
void connectionLoaded(NMConnectionSettings* connection);
|
||||
void connectionRemoved(NMConnectionSettings* connection);
|
||||
void availableConnectionPathsChanged(QList<QDBusObjectPath> paths);
|
||||
void settingsLoaded(NMSettings* settings);
|
||||
void settingsRemoved(NMSettings* settings);
|
||||
void availableSettingsPathsChanged(QList<QDBusObjectPath> paths);
|
||||
void activeConnectionPathChanged(const QDBusObjectPath& connection);
|
||||
void activeConnectionLoaded(NMActiveConnection* active);
|
||||
void interfaceChanged(const QString& interface);
|
||||
void hwAddressChanged(const QString& hwAddress);
|
||||
void managedChanged(bool managed);
|
||||
void stateChanged(NMDeviceState::Enum state);
|
||||
void stateReasonChanged(NMDeviceStateReason::Enum reason);
|
||||
void lastFailReasonChanged(NMDeviceStateReason::Enum reason);
|
||||
void autoconnectChanged(bool autoconnect);
|
||||
|
||||
public slots:
|
||||
void disconnect();
|
||||
void setAutoconnect(bool autoconnect);
|
||||
void setManaged(bool managed);
|
||||
|
||||
private slots:
|
||||
void onAvailableConnectionPathsChanged(const QList<QDBusObjectPath>& paths);
|
||||
void onStateChanged(quint32 newState, quint32 oldState, quint32 reason);
|
||||
void onAvailableSettingsPathsChanged(const QList<QDBusObjectPath>& paths);
|
||||
void onActiveConnectionPathChanged(const QDBusObjectPath& path);
|
||||
|
||||
private:
|
||||
void registerConnection(const QString& path);
|
||||
void registerSettings(const QString& path);
|
||||
|
||||
QHash<QString, NMConnectionSettings*> mConnections;
|
||||
QHash<QString, NMSettings*> mSettings;
|
||||
NMActiveConnection* mActiveConnection = nullptr;
|
||||
|
||||
// clang-format off
|
||||
@@ -80,8 +88,10 @@ private:
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, QString, bHwAddress, &NMDevice::hwAddressChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, bool, bManaged, &NMDevice::managedChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, NMDeviceState::Enum, bState, &NMDevice::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, NMDeviceStateReason::Enum, bStateReason, &NMDevice::stateReasonChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, NMDeviceStateReason::Enum, bLastFailReason, &NMDevice::lastFailReasonChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, bool, bAutoconnect, &NMDevice::autoconnectChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, QList<QDBusObjectPath>, bAvailableConnections, &NMDevice::availableConnectionPathsChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, QList<QDBusObjectPath>, bAvailableConnections, &NMDevice::availableSettingsPathsChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMDevice, QDBusObjectPath, bActiveConnection, &NMDevice::activeConnectionPathChanged);
|
||||
|
||||
QS_DBUS_BINDABLE_PROPERTY_GROUP(NMDeviceAdapter, deviceProperties);
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMConnectivityState
|
||||
class NMConnectivityState: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
None = 1,
|
||||
Portal = 2,
|
||||
Limited = 3,
|
||||
Full = 4,
|
||||
};
|
||||
};
|
||||
|
||||
// Indicates the type of hardware represented by a device object.
|
||||
class NMDeviceType: public QObject {
|
||||
Q_OBJECT;
|
||||
@@ -52,6 +66,123 @@ public:
|
||||
Q_ENUM(Enum);
|
||||
};
|
||||
|
||||
// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMDeviceState.
|
||||
class NMDeviceState: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
Unmanaged = 10,
|
||||
Unavailable = 20,
|
||||
Disconnected = 30,
|
||||
Prepare = 40,
|
||||
Config = 50,
|
||||
NeedAuth = 60,
|
||||
IPConfig = 70,
|
||||
IPCheck = 80,
|
||||
Secondaries = 90,
|
||||
Activated = 100,
|
||||
Deactivating = 110,
|
||||
Failed = 120,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
};
|
||||
|
||||
// Device state change reason codes.
|
||||
// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMDeviceStateReason.
|
||||
class NMDeviceStateReason: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
None = 0,
|
||||
Unknown = 1,
|
||||
NowManaged = 2,
|
||||
NowUnmanaged = 3,
|
||||
ConfigFailed = 4,
|
||||
IpConfigUnavailable = 5,
|
||||
IpConfigExpired = 6,
|
||||
NoSecrets = 7,
|
||||
SupplicantDisconnect = 8,
|
||||
SupplicantConfigFailed = 9,
|
||||
SupplicantFailed = 10,
|
||||
SupplicantTimeout = 11,
|
||||
PppStartFailed = 12,
|
||||
PppDisconnect = 13,
|
||||
PppFailed = 14,
|
||||
DhcpStartFailed = 15,
|
||||
DhcpError = 16,
|
||||
DhcpFailed = 17,
|
||||
SharedStartFailed = 18,
|
||||
SharedFailed = 19,
|
||||
AutoIpStartFailed = 20,
|
||||
AutoIpError = 21,
|
||||
AutoIpFailed = 22,
|
||||
ModemBusy = 23,
|
||||
ModemNoDialTone = 24,
|
||||
ModemNoCarrier = 25,
|
||||
ModemDialTimeout = 26,
|
||||
ModemDialFailed = 27,
|
||||
ModemInitFailed = 28,
|
||||
GsmApnFailed = 29,
|
||||
GsmRegistrationNotSearching = 30,
|
||||
GsmRegistrationDenied = 31,
|
||||
GsmRegistrationTimeout = 32,
|
||||
GsmRegistrationFailed = 33,
|
||||
GsmPinCheckFailed = 34,
|
||||
FirmwareMissing = 35,
|
||||
Removed = 36,
|
||||
Sleeping = 37,
|
||||
ConnectionRemoved = 38,
|
||||
UserRequested = 39,
|
||||
Carrier = 40,
|
||||
ConnectionAssumed = 41,
|
||||
SupplicantAvailable = 42,
|
||||
ModemNotFound = 43,
|
||||
BtFailed = 44,
|
||||
GsmSimNotInserted = 45,
|
||||
GsmSimPinRequired = 46,
|
||||
GsmSimPukRequired = 47,
|
||||
GsmSimWrong = 48,
|
||||
InfinibandMode = 49,
|
||||
DependencyFailed = 50,
|
||||
Br2684Failed = 51,
|
||||
ModemManagerUnavailable = 52,
|
||||
SsidNotFound = 53,
|
||||
SecondaryConnectionFailed = 54,
|
||||
DcbFcoeFailed = 55,
|
||||
TeamdControlFailed = 56,
|
||||
ModemFailed = 57,
|
||||
ModemAvailable = 58,
|
||||
SimPinIncorrect = 59,
|
||||
NewActivation = 60,
|
||||
ParentChanged = 61,
|
||||
ParentManagedChanged = 62,
|
||||
OvsdbFailed = 63,
|
||||
IpAddressDuplicate = 64,
|
||||
IpMethodUnsupported = 65,
|
||||
SriovConfigurationFailed = 66,
|
||||
PeerNotFound = 67,
|
||||
DeviceHandlerFailed = 68,
|
||||
UnmanagedByDefault = 69,
|
||||
UnmanagedExternalDown = 70,
|
||||
UnmanagedLinkNotInit = 71,
|
||||
UnmanagedQuitting = 72,
|
||||
UnmanagedManagerDisabled = 73,
|
||||
UnmanagedUserConf = 74,
|
||||
UnmanagedUserExplicit = 75,
|
||||
UnmanagedUserSettings = 76,
|
||||
UnmanagedUserUdev = 77,
|
||||
NetworkingOff = 78,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
};
|
||||
|
||||
// 802.11 specific device encryption and authentication capabilities.
|
||||
// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMDeviceWifiCapabilities.
|
||||
class NMWirelessCapabilities: public QObject {
|
||||
@@ -153,4 +284,31 @@ public:
|
||||
Q_ENUM(Enum);
|
||||
};
|
||||
|
||||
/// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMActiveConnectionStateReason.
|
||||
class NMConnectionStateReason: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
None = 1,
|
||||
UserDisconnected = 2,
|
||||
DeviceDisconnected = 3,
|
||||
ServiceStopped = 4,
|
||||
IpConfigInvalid = 5,
|
||||
ConnectTimeout = 6,
|
||||
ServiceStartTimeout = 7,
|
||||
ServiceStartFailed = 8,
|
||||
NoSecrets = 9,
|
||||
LoginFailed = 10,
|
||||
ConnectionRemoved = 11,
|
||||
DependencyFailed = 12,
|
||||
DeviceRealizeFailed = 13,
|
||||
DeviceRemoved = 14
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
};
|
||||
|
||||
} // namespace qs::network
|
||||
@@ -1,5 +1,10 @@
|
||||
<node>
|
||||
<interface name="org.freedesktop.NetworkManager.Device">
|
||||
<method name="Disconnect"/>
|
||||
<signal name="StateChanged">
|
||||
<arg name="new_state" type="u"/>
|
||||
<arg name="old_state" type="u"/>
|
||||
<arg name="reason" type="u"/>
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
||||
@@ -2,8 +2,18 @@
|
||||
<interface name="org.freedesktop.NetworkManager.Settings.Connection">
|
||||
<method name="GetSettings">
|
||||
<arg name="settings" type="a{sa{sv}}" direction="out"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnectionSettingsMap"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="qs::network::NMSettingsMap"/>
|
||||
</method>
|
||||
<method name="GetSecrets">
|
||||
<arg name="setting_name" type="s" direction="in"/>
|
||||
<arg name="secrets" type="a{sa{sv}}" direction="out"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="qs::network::NMSettingsMap"/>
|
||||
</method>
|
||||
<method name="Update">
|
||||
<arg name="properties" type="a{sa{sv}}" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="qs::network::NMSettingsMap"/>
|
||||
</method>
|
||||
<method name="ClearSecrets"/>
|
||||
<method name="Delete"/>
|
||||
<signal name="Updated"/>
|
||||
<signal name="Removed"/>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<node>
|
||||
<interface name="org.freedesktop.NetworkManager">
|
||||
<method name="CheckConnectivity">
|
||||
<arg direction="out" type="u" name="connectivity"/>
|
||||
</method>
|
||||
<method name="GetAllDevices">
|
||||
<arg direction="out" type="ao" name="devices"/>
|
||||
</method>
|
||||
@@ -11,7 +14,7 @@
|
||||
</method>
|
||||
<method name="AddAndActivateConnection">
|
||||
<arg direction="in" type="a{sa{sv}}" name="connection"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnectionSettingsMap"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="qs::network::NMSettingsMap"/>
|
||||
<arg direction="in" type="o" name="device"/>
|
||||
<arg direction="in" type="o" name="specific_object"/>
|
||||
<arg direction="out" type="o" name="path"/>
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdbusconnection.h>
|
||||
#include <qdbusmetatype.h>
|
||||
#include <qdbuspendingcall.h>
|
||||
#include <qdbuspendingreply.h>
|
||||
#include <qdebug.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qmetatype.h>
|
||||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_nm_connection_settings.h"
|
||||
#include "dbus_types.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
using namespace qs::dbus;
|
||||
|
||||
namespace {
|
||||
QS_LOGGING_CATEGORY(logNetworkManager, "quickshell.network", QtWarningMsg);
|
||||
QS_LOGGING_CATEGORY(logNMSettings, "quickshell.network.nm_settings", QtWarningMsg);
|
||||
} // namespace
|
||||
|
||||
NMSettings::NMSettings(const QString& path, QObject* parent): QObject(parent) {
|
||||
qDBusRegisterMetaType<QList<QVariantMap>>();
|
||||
qDBusRegisterMetaType<QList<quint32>>();
|
||||
qDBusRegisterMetaType<QList<QList<quint32>>>();
|
||||
qDBusRegisterMetaType<QList<QByteArray>>();
|
||||
qDBusRegisterMetaType<NMIPv6Address>();
|
||||
qDBusRegisterMetaType<QList<NMIPv6Address>>();
|
||||
qDBusRegisterMetaType<NMIPv6Route>();
|
||||
qDBusRegisterMetaType<QList<NMIPv6Route>>();
|
||||
|
||||
this->proxy = new DBusNMConnectionSettingsProxy(
|
||||
"org.freedesktop.NetworkManager",
|
||||
path,
|
||||
QDBusConnection::systemBus(),
|
||||
this
|
||||
);
|
||||
|
||||
if (!this->proxy->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Cannot create DBus interface for connection settings at"
|
||||
<< path;
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
this->proxy,
|
||||
&DBusNMConnectionSettingsProxy::Updated,
|
||||
this,
|
||||
&NMSettings::getSettings
|
||||
);
|
||||
|
||||
this->bId.setBinding([this]() { return this->bSettings.value()["connection"]["id"].toString(); });
|
||||
this->bUuid.setBinding([this]() {
|
||||
return this->bSettings.value()["connection"]["uuid"].toString();
|
||||
});
|
||||
|
||||
this->settingsProperties.setInterface(this->proxy);
|
||||
this->settingsProperties.updateAllViaGetAll();
|
||||
|
||||
this->getSettings();
|
||||
}
|
||||
|
||||
void NMSettings::getSettings() {
|
||||
auto pending = this->proxy->GetSettings();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
auto responseCallback = [this](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<NMSettingsMap> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCWarning(logNetworkManager)
|
||||
<< "Failed to get settings for" << this->path() << ":" << reply.error().message();
|
||||
} else {
|
||||
auto settings = reply.value();
|
||||
manualSettingDemarshall(settings);
|
||||
this->bSettings = settings;
|
||||
qCDebug(logNetworkManager) << "Settings map updated for" << this->path();
|
||||
|
||||
if (!this->mLoaded) {
|
||||
emit this->loaded();
|
||||
this->mLoaded = true;
|
||||
}
|
||||
};
|
||||
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
QDBusPendingCallWatcher* NMSettings::updateSettings(
|
||||
const NMSettingsMap& settingsToChange,
|
||||
const NMSettingsMap& settingsToRemove
|
||||
) {
|
||||
auto settings = removeSettingsInMap(this->bSettings, settingsToRemove);
|
||||
settings = mergeSettingsMaps(settings, settingsToChange);
|
||||
auto pending = this->proxy->Update(settings);
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
void NMSettings::clearSecrets() {
|
||||
auto pending = this->proxy->ClearSecrets();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
auto responseCallback = [this](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCWarning(logNetworkManager)
|
||||
<< "Failed to clear secrets for" << this->path() << ":" << reply.error().message();
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Cleared secrets for" << this->path();
|
||||
}
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
void NMSettings::forget() {
|
||||
auto pending = this->proxy->Delete();
|
||||
auto* call = new QDBusPendingCallWatcher(pending, this);
|
||||
|
||||
auto responseCallback = [this](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCWarning(logNetworkManager)
|
||||
<< "Failed to forget" << this->path() << ":" << reply.error().message();
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Successfully deletion of" << this->path();
|
||||
}
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
QVariantMap NMSettings::read() {
|
||||
QVariantMap result;
|
||||
const auto& settings = this->bSettings.value();
|
||||
for (auto it = settings.constBegin(); it != settings.constEnd(); ++it) {
|
||||
QVariantMap group;
|
||||
for (auto jt = it.value().constBegin(); jt != it.value().constEnd(); ++jt) {
|
||||
group.insert(jt.key(), settingTypeToQml(jt.value()));
|
||||
}
|
||||
result.insert(it.key(), group);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void NMSettings::write(const QVariantMap& settings) {
|
||||
NMSettingsMap changedSettings;
|
||||
NMSettingsMap removedSettings;
|
||||
QStringList failedSettings;
|
||||
|
||||
for (auto it = settings.constBegin(); it != settings.constEnd(); ++it) {
|
||||
if (!it.value().canConvert<QVariantMap>()) continue;
|
||||
|
||||
auto group = it.value().toMap();
|
||||
QVariantMap toChange;
|
||||
QVariantMap toRemove;
|
||||
for (auto jt = group.constBegin(); jt != group.constEnd(); ++jt) {
|
||||
if (jt.value().isNull()) {
|
||||
toRemove.insert(jt.key(), QVariant());
|
||||
} else {
|
||||
auto converted = settingTypeFromQml(it.key(), jt.key(), jt.value());
|
||||
if (!converted.isValid()) failedSettings.append(it.key() + "." + jt.key());
|
||||
else toChange.insert(jt.key(), converted);
|
||||
}
|
||||
}
|
||||
if (!toChange.isEmpty()) changedSettings.insert(it.key(), toChange);
|
||||
if (!toRemove.isEmpty()) removedSettings.insert(it.key(), toRemove);
|
||||
}
|
||||
|
||||
if (!failedSettings.isEmpty()) {
|
||||
qCWarning(logNMSettings) << "A write to" << this
|
||||
<< "has received bad types for the following settings:"
|
||||
<< failedSettings.join(", ");
|
||||
}
|
||||
|
||||
auto* call = this->updateSettings(changedSettings, removedSettings);
|
||||
|
||||
auto responseCallback = [this](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCWarning(logNetworkManager)
|
||||
<< "Failed to update settings for" << this->path() << ":" << reply.error().message();
|
||||
} else {
|
||||
qCDebug(logNMSettings) << "Successful write to" << this;
|
||||
}
|
||||
delete call;
|
||||
};
|
||||
|
||||
QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
|
||||
}
|
||||
|
||||
bool NMSettings::isValid() const { return this->proxy && this->proxy->isValid(); }
|
||||
QString NMSettings::address() const { return this->proxy ? this->proxy->service() : QString(); }
|
||||
QString NMSettings::path() const { return this->proxy ? this->proxy->path() : QString(); }
|
||||
|
||||
} // namespace qs::network
|
||||
|
||||
QDebug operator<<(QDebug debug, const qs::network::NMSettings* settings) {
|
||||
auto saver = QDebugStateSaver(debug);
|
||||
|
||||
if (settings) {
|
||||
debug.nospace() << "NMSettings(" << static_cast<const void*>(settings)
|
||||
<< ", uuid=" << settings->uuid() << ")";
|
||||
} else {
|
||||
debug << "WifiNetwork(nullptr)";
|
||||
}
|
||||
|
||||
return debug;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qdbusextratypes.h>
|
||||
#include <qdbuspendingcall.h>
|
||||
#include <qdbuspendingreply.h>
|
||||
#include <qobject.h>
|
||||
#include <qproperty.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "dbus_nm_connection_settings.h"
|
||||
#include "dbus_types.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
// Proxy of a /org/freedesktop/NetworkManager/Settings/Connection/* object.
|
||||
///! A NetworkManager connection settings profile.
|
||||
class NMSettings: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("");
|
||||
|
||||
/// The human-readable unique identifier for the connection.
|
||||
Q_PROPERTY(QString id READ default NOTIFY idChanged BINDABLE bindableId);
|
||||
/// A universally unique identifier for the connection.
|
||||
Q_PROPERTY(QString uuid READ uuid NOTIFY uuidChanged BINDABLE bindableUuid);
|
||||
|
||||
public:
|
||||
explicit NMSettings(const QString& path, QObject* parent = nullptr);
|
||||
|
||||
/// Clear all of the secrets belonging to the settings.
|
||||
Q_INVOKABLE void clearSecrets();
|
||||
/// Delete the settings.
|
||||
Q_INVOKABLE void forget();
|
||||
/// Update the connection with new settings and save the connection to disk.
|
||||
/// Only changed fields need to be included.
|
||||
/// Writing a setting to `null` will remove the setting or reset it to its default.
|
||||
///
|
||||
/// > [!NOTE] Secrets may be part of the update request,
|
||||
/// > and will be either stored in persistent storage or sent to a Secret Agent for storage,
|
||||
/// > depending on the flags associated with each secret.
|
||||
Q_INVOKABLE void write(const QVariantMap& settings);
|
||||
/// Get the settings map describing this network configuration.
|
||||
///
|
||||
/// > [!NOTE] This will never include any secrets required for connection to the network, as those are often protected.
|
||||
Q_INVOKABLE QVariantMap read();
|
||||
|
||||
[[nodiscard]] bool isValid() const;
|
||||
[[nodiscard]] QString path() const;
|
||||
[[nodiscard]] QString address() const;
|
||||
[[nodiscard]] NMSettingsMap map() { return this->bSettings; }
|
||||
QDBusPendingCallWatcher*
|
||||
updateSettings(const NMSettingsMap& settingsToChange, const NMSettingsMap& settingsToRemove = {});
|
||||
QBindable<QString> bindableId() { return &this->bId; }
|
||||
[[nodiscard]] QString uuid() const { return this->bUuid; }
|
||||
QBindable<QString> bindableUuid() { return &this->bUuid; }
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
void settingsChanged(NMSettingsMap settings);
|
||||
void idChanged(QString id);
|
||||
void uuidChanged(QString uuid);
|
||||
|
||||
private:
|
||||
bool mLoaded = false;
|
||||
|
||||
void getSettings();
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMSettings, NMSettingsMap, bSettings, &NMSettings::settingsChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMSettings, QString, bId, &NMSettings::idChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMSettings, QString, bUuid, &NMSettings::uuidChanged);
|
||||
QS_DBUS_BINDABLE_PROPERTY_GROUP(NMSettings, settingsProperties);
|
||||
DBusNMConnectionSettingsProxy* proxy = nullptr;
|
||||
};
|
||||
|
||||
} // namespace qs::network
|
||||
|
||||
QDebug operator<<(QDebug debug, const qs::network::NMSettings* settings);
|
||||
+284
-7
@@ -1,27 +1,28 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <cmath>
|
||||
// We depend on non-std Linux extensions that ctime doesn't put in the global namespace
|
||||
// NOLINTNEXTLINE(modernize-deprecated-headers)
|
||||
#include <time.h>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qdbusargument.h>
|
||||
#include <qdbusservicewatcher.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../wifi.hpp"
|
||||
#include "../enums.hpp"
|
||||
#include "dbus_types.hpp"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
WifiSecurityType::Enum securityFromConnectionSettings(const ConnectionSettingsMap& settings) {
|
||||
const QVariantMap& security = settings.value("802-11-wireless-security");
|
||||
if (security.isEmpty()) {
|
||||
return WifiSecurityType::Open;
|
||||
};
|
||||
WifiSecurityType::Enum securityFromSettingsMap(const NMSettingsMap& settings) {
|
||||
const QString mapName = "802-11-wireless-security";
|
||||
if (!settings.contains(mapName)) return WifiSecurityType::Unknown;
|
||||
const QVariantMap& security = settings.value(mapName);
|
||||
if (security.isEmpty()) return WifiSecurityType::Open;
|
||||
|
||||
const QString keyMgmt = security["key-mgmt"].toString();
|
||||
const QString authAlg = security["auth-alg"].toString();
|
||||
@@ -45,6 +46,8 @@ WifiSecurityType::Enum securityFromConnectionSettings(const ConnectionSettingsMa
|
||||
return WifiSecurityType::Sae;
|
||||
} else if (keyMgmt == "wpa-eap-suite-b-192") {
|
||||
return WifiSecurityType::Wpa3SuiteB192;
|
||||
} else if (keyMgmt == "owe") {
|
||||
return WifiSecurityType::Owe;
|
||||
}
|
||||
return WifiSecurityType::Open;
|
||||
}
|
||||
@@ -224,6 +227,280 @@ WifiSecurityType::Enum findBestWirelessSecurity(
|
||||
return WifiSecurityType::Unknown;
|
||||
}
|
||||
|
||||
NMSettingsMap mergeSettingsMaps(const NMSettingsMap& target, const NMSettingsMap& source) {
|
||||
NMSettingsMap result = target;
|
||||
for (auto iter = source.constBegin(); iter != source.constEnd(); ++iter) {
|
||||
result[iter.key()].insert(iter.value());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NMSettingsMap removeSettingsInMap(const NMSettingsMap& target, const NMSettingsMap& toRemove) {
|
||||
NMSettingsMap result = target;
|
||||
for (auto iter = toRemove.constBegin(); iter != toRemove.constEnd(); ++iter) {
|
||||
const QString& group = iter.key();
|
||||
const QVariantMap& keysToRemove = iter.value();
|
||||
|
||||
if (!result.contains(group)) continue;
|
||||
|
||||
for (auto jt = keysToRemove.constBegin(); jt != keysToRemove.constEnd(); ++jt) {
|
||||
result[group].remove(jt.key());
|
||||
}
|
||||
|
||||
// Remove the group entirely if it's now empty
|
||||
if (result[group].isEmpty()) {
|
||||
result.remove(group);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Some NMSettingsMap settings remain QDBusArguments after autodemarshalling.
|
||||
// Manually demarshall these for any complex signature we have registered.
|
||||
void manualSettingDemarshall(NMSettingsMap& map) {
|
||||
auto demarshallValue = [](const QVariant& value) -> QVariant {
|
||||
if (value.userType() != qMetaTypeId<QDBusArgument>()) {
|
||||
return value;
|
||||
}
|
||||
|
||||
auto arg = value.value<QDBusArgument>();
|
||||
auto signature = arg.currentSignature();
|
||||
|
||||
if (signature == "ay") return QVariant::fromValue(qdbus_cast<QByteArray>(arg));
|
||||
if (signature == "aay") return QVariant::fromValue(qdbus_cast<QList<QByteArray>>(arg));
|
||||
if (signature == "au") return QVariant::fromValue(qdbus_cast<QList<quint32>>(arg));
|
||||
if (signature == "aau") return QVariant::fromValue(qdbus_cast<QList<QList<quint32>>>(arg));
|
||||
if (signature == "aa{sv}") return QVariant::fromValue(qdbus_cast<QList<QVariantMap>>(arg));
|
||||
if (signature == "a(ayuay)") return QVariant::fromValue(qdbus_cast<QList<NMIPv6Address>>(arg));
|
||||
if (signature == "a(ayuayu)") return QVariant::fromValue(qdbus_cast<QList<NMIPv6Route>>(arg));
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
for (auto it = map.begin(); it != map.end(); ++it)
|
||||
for (auto jt = it.value().begin(); jt != it.value().end(); ++jt)
|
||||
jt.value() = demarshallValue(jt.value());
|
||||
}
|
||||
|
||||
// Some NMSettingsMap setting types can't be expressed in QML.
|
||||
// Convert these settings to their correct type or return an invalid QVariant.
|
||||
QVariant settingTypeFromQml(const QString& group, const QString& key, const QVariant& value) {
|
||||
auto s = group + "." + key;
|
||||
|
||||
// QString -> QByteArray
|
||||
if (s == "802-1x.ca-cert" || s == "802-1x.client-cert" || s == "802-1x.private-key"
|
||||
|| s == "802-1x.password-raw" || s == "802-1x.phase2-ca-cert"
|
||||
|| s == "802-1x.phase2-client-cert" || s == "802-1x.phase2-private-key"
|
||||
|| s == "802-11-wireless.ssid")
|
||||
{
|
||||
if (value.typeId() == QMetaType::QString) {
|
||||
return value.toString().toUtf8();
|
||||
}
|
||||
if (value.typeId() == QMetaType::QByteArray) {
|
||||
return value;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QList<QByteArray>
|
||||
if (s == "ipv6.dns") {
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QList<QByteArray> r;
|
||||
for (const auto& v: value.toList()) {
|
||||
if (v.typeId() == QMetaType::QString) {
|
||||
r.append(v.toString().toUtf8());
|
||||
} else {
|
||||
r.append(v.toByteArray());
|
||||
}
|
||||
}
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QList<quint32>
|
||||
if (s == "ipv4.dns") {
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QList<quint32> r;
|
||||
for (const auto& v: value.toList()) {
|
||||
r.append(v.value<quint32>());
|
||||
}
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QList<QList<quint32>>
|
||||
if (s == "ipv4.addresses" || s == "ipv4.routes") {
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QList<QList<quint32>> r;
|
||||
for (const auto& v: value.toList()) {
|
||||
if (v.typeId() != QMetaType::QVariantList) {
|
||||
continue;
|
||||
}
|
||||
QList<quint32> inner;
|
||||
for (const auto& u: v.toList()) {
|
||||
inner.append(u.value<quint32>());
|
||||
}
|
||||
r.append(inner);
|
||||
}
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QList<QVariantMap>
|
||||
if (s == "ipv4.address-data" || s == "ipv4.route-data" || s == "ipv4.routing-rules"
|
||||
|| s == "ipv6.address-data" || s == "ipv6.route-data" || s == "ipv6.routing-rules")
|
||||
{
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QList<QVariantMap> r;
|
||||
for (const auto& v: value.toList()) {
|
||||
if (!v.canConvert<QVariantMap>()) {
|
||||
continue;
|
||||
}
|
||||
r.append(v.toMap());
|
||||
}
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QList<NMIPv6Address>
|
||||
if (s == "ipv6.addresses") {
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QList<NMIPv6Address> r;
|
||||
for (const auto& v: value.toList()) {
|
||||
if (v.typeId() != QMetaType::QVariantList) {
|
||||
continue;
|
||||
}
|
||||
auto fields = v.toList();
|
||||
if (fields.size() != 3) {
|
||||
continue;
|
||||
}
|
||||
const QByteArray address = fields[0].typeId() == QMetaType::QString
|
||||
? fields[0].toString().toUtf8()
|
||||
: fields[0].toByteArray();
|
||||
const QByteArray gateway = fields[2].typeId() == QMetaType::QString
|
||||
? fields[2].toString().toUtf8()
|
||||
: fields[2].toByteArray();
|
||||
r.append({.address = address, .prefix = fields[1].value<quint32>(), .gateway = gateway});
|
||||
}
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QList<NMIPv6Route>
|
||||
if (s == "ipv6.routes") {
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QList<NMIPv6Route> r;
|
||||
for (const auto& v: value.toList()) {
|
||||
if (v.typeId() != QMetaType::QVariantList) {
|
||||
continue;
|
||||
}
|
||||
auto fields = v.toList();
|
||||
if (fields.size() != 4) {
|
||||
continue;
|
||||
}
|
||||
const QByteArray destination = fields[0].typeId() == QMetaType::QString
|
||||
? fields[0].toString().toUtf8()
|
||||
: fields[0].toByteArray();
|
||||
const QByteArray nexthop = fields[2].typeId() == QMetaType::QString
|
||||
? fields[2].toString().toUtf8()
|
||||
: fields[2].toByteArray();
|
||||
r.append(
|
||||
{.destination = destination,
|
||||
.prefix = fields[1].value<quint32>(),
|
||||
.nexthop = nexthop,
|
||||
.metric = fields[3].value<quint32>()}
|
||||
);
|
||||
}
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// QVariantList -> QStringList
|
||||
if (s == "connection.permissions" || s == "ipv4.dns-search" || s == "ipv6.dns-search"
|
||||
|| s == "802-11-wireless.seen-bssids")
|
||||
{
|
||||
if (value.typeId() == QMetaType::QVariantList) {
|
||||
QStringList stringList;
|
||||
for (const auto& item: value.toList()) {
|
||||
stringList.append(item.toString());
|
||||
}
|
||||
return stringList;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// double (whole number) -> qint32
|
||||
if (value.typeId() == QMetaType::Double) {
|
||||
auto num = value.toDouble();
|
||||
if (std::isfinite(num) && num == std::trunc(num)) {
|
||||
return QVariant::fromValue(static_cast<qint32>(num));
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Some NMSettingsMap setting types must be converted to a type that is supported by QML.
|
||||
// Although QByteArrays can be represented in QML, we convert them to strings for convenience.
|
||||
QVariant settingTypeToQml(const QVariant& value) {
|
||||
// QByteArray -> QString
|
||||
if (value.typeId() == QMetaType::QByteArray) {
|
||||
return QString::fromUtf8(value.toByteArray());
|
||||
}
|
||||
|
||||
// QList<QByteArray> -> QVariantList
|
||||
if (value.userType() == qMetaTypeId<QList<QByteArray>>()) {
|
||||
QVariantList out;
|
||||
for (const auto& ba: value.value<QList<QByteArray>>()) {
|
||||
out.append(QString::fromUtf8(ba));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// QList<NMIPv6Address> -> QVariantList
|
||||
if (value.userType() == qMetaTypeId<QList<NMIPv6Address>>()) {
|
||||
QVariantList out;
|
||||
for (const auto& addr: value.value<QList<NMIPv6Address>>()) {
|
||||
out.append(
|
||||
QVariant::fromValue(
|
||||
QVariantList {
|
||||
QString::fromUtf8(addr.address),
|
||||
addr.prefix,
|
||||
QString::fromUtf8(addr.gateway),
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// QList<NMIPv6Route> -> QVariantList
|
||||
if (value.userType() == qMetaTypeId<QList<NMIPv6Route>>()) {
|
||||
QVariantList out;
|
||||
for (const auto& route: value.value<QList<NMIPv6Route>>()) {
|
||||
out.append(
|
||||
QVariant::fromValue(
|
||||
QVariantList {
|
||||
QString::fromUtf8(route.destination),
|
||||
route.prefix,
|
||||
QString::fromUtf8(route.nexthop),
|
||||
route.metric,
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// NOLINTBEGIN
|
||||
QDateTime clockBootTimeToDateTime(qint64 clockBootTime) {
|
||||
clockid_t clkId = CLOCK_BOOTTIME;
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdbusservicewatcher.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
#include "../wifi.hpp"
|
||||
#include "../enums.hpp"
|
||||
#include "dbus_types.hpp"
|
||||
#include "enums.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
WifiSecurityType::Enum securityFromConnectionSettings(const ConnectionSettingsMap& settings);
|
||||
WifiSecurityType::Enum securityFromSettingsMap(const NMSettingsMap& settings);
|
||||
|
||||
bool deviceSupportsApCiphers(
|
||||
NMWirelessCapabilities::Enum caps,
|
||||
@@ -40,6 +39,16 @@ WifiSecurityType::Enum findBestWirelessSecurity(
|
||||
NM80211ApSecurityFlags::Enum apRsn
|
||||
);
|
||||
|
||||
NMSettingsMap mergeSettingsMaps(const NMSettingsMap& target, const NMSettingsMap& source);
|
||||
|
||||
NMSettingsMap removeSettingsInMap(const NMSettingsMap& target, const NMSettingsMap& toRemove);
|
||||
|
||||
void manualSettingDemarshall(NMSettingsMap& map);
|
||||
|
||||
QVariant settingTypeFromQml(const QString& group, const QString& key, const QVariant& value);
|
||||
|
||||
QVariant settingTypeToQml(const QVariant& value);
|
||||
|
||||
QDateTime clockBootTimeToDateTime(qint64 clockBootTime);
|
||||
|
||||
} // namespace qs::network
|
||||
+164
-67
@@ -1,6 +1,7 @@
|
||||
#include "wireless.hpp"
|
||||
#include <utility>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qdbusconnection.h>
|
||||
#include <qdbusextratypes.h>
|
||||
@@ -11,20 +12,23 @@
|
||||
#include <qloggingcategory.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qpointer.h>
|
||||
#include <qstring.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../network.hpp"
|
||||
#include "../enums.hpp"
|
||||
#include "../wifi.hpp"
|
||||
#include "accesspoint.hpp"
|
||||
#include "connection.hpp"
|
||||
#include "active_connection.hpp"
|
||||
#include "dbus_nm_wireless.h"
|
||||
#include "dbus_types.hpp"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
@@ -42,38 +46,43 @@ NMWirelessNetwork::NMWirelessNetwork(QString ssid, QObject* parent)
|
||||
, bReason(NMConnectionStateReason::None)
|
||||
, bState(NMConnectionState::Deactivated) {}
|
||||
|
||||
void NMWirelessNetwork::updateReferenceConnection() {
|
||||
void NMWirelessNetwork::updateReferenceSettings() {
|
||||
// If the network has no connections, the reference is nullptr.
|
||||
if (this->mConnections.isEmpty()) {
|
||||
this->mReferenceConn = nullptr;
|
||||
if (this->mSettings.isEmpty()) {
|
||||
this->mReferenceSettings = nullptr;
|
||||
this->bSecurity = WifiSecurityType::Unknown;
|
||||
// Set security back to reference AP.
|
||||
if (this->mReferenceAp) {
|
||||
this->bSecurity.setBinding([this]() { return this->mReferenceAp->security(); });
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
// If the network has an active connection, use it as the reference.
|
||||
// If the network has an active connection, use its settings as the reference.
|
||||
if (this->mActiveConnection) {
|
||||
auto* conn = this->mConnections.value(this->mActiveConnection->connection().path());
|
||||
if (conn && conn != this->mReferenceConn) {
|
||||
this->mReferenceConn = conn;
|
||||
this->bSecurity.setBinding([conn]() { return conn->security(); });
|
||||
auto* settings = this->mSettings.value(this->mActiveConnection->connection().path());
|
||||
if (settings && settings != this->mReferenceSettings) {
|
||||
this->mReferenceSettings = settings;
|
||||
this->bSecurity.setBinding([settings]() { return securityFromSettingsMap(settings->map()); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, choose the connection with the strongest security settings.
|
||||
NMConnectionSettings* selectedConn = nullptr;
|
||||
for (auto* conn: this->mConnections.values()) {
|
||||
if (!selectedConn || conn->security() > selectedConn->security()) {
|
||||
selectedConn = conn;
|
||||
// Otherwise, choose the settings responsible for the last successful connection.
|
||||
NMSettings* selectedSettings = nullptr;
|
||||
quint64 selectedTimestamp = 0;
|
||||
for (auto* settings: this->mSettings.values()) {
|
||||
const quint64 timestamp = settings->map()["connection"]["timestamp"].toULongLong();
|
||||
if (!selectedSettings || timestamp > selectedTimestamp) {
|
||||
selectedSettings = settings;
|
||||
selectedTimestamp = timestamp;
|
||||
}
|
||||
}
|
||||
if (this->mReferenceConn != selectedConn) {
|
||||
this->mReferenceConn = selectedConn;
|
||||
this->bSecurity.setBinding([selectedConn]() { return selectedConn->security(); });
|
||||
|
||||
if (this->mReferenceSettings != selectedSettings) {
|
||||
this->mReferenceSettings = selectedSettings;
|
||||
this->bSecurity.setBinding([selectedSettings]() {
|
||||
return securityFromSettingsMap(selectedSettings->map());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +110,7 @@ void NMWirelessNetwork::updateReferenceAp() {
|
||||
this->mReferenceAp = selectedAp;
|
||||
this->bSignalStrength.setBinding([selectedAp]() { return selectedAp->signalStrength(); });
|
||||
// Reference AP is used for security when there's no connection settings.
|
||||
if (!this->mReferenceConn) {
|
||||
if (!this->mReferenceSettings) {
|
||||
this->bSecurity.setBinding([selectedAp]() { return selectedAp->security(); });
|
||||
}
|
||||
}
|
||||
@@ -113,7 +122,7 @@ void NMWirelessNetwork::addAccessPoint(NMAccessPoint* ap) {
|
||||
auto onDestroyed = [this, ap]() {
|
||||
if (this->mAccessPoints.take(ap->path())) {
|
||||
this->updateReferenceAp();
|
||||
if (this->mAccessPoints.isEmpty() && this->mConnections.isEmpty()) emit this->disappeared();
|
||||
if (this->mAccessPoints.isEmpty() && this->mSettings.isEmpty()) emit this->disappeared();
|
||||
}
|
||||
};
|
||||
// clang-format off
|
||||
@@ -123,44 +132,45 @@ void NMWirelessNetwork::addAccessPoint(NMAccessPoint* ap) {
|
||||
this->updateReferenceAp();
|
||||
};
|
||||
|
||||
void NMWirelessNetwork::addConnection(NMConnectionSettings* conn) {
|
||||
if (this->mConnections.contains(conn->path())) return;
|
||||
this->mConnections.insert(conn->path(), conn);
|
||||
auto onDestroyed = [this, conn]() {
|
||||
if (this->mConnections.take(conn->path())) {
|
||||
this->updateReferenceConnection();
|
||||
if (this->mConnections.isEmpty()) this->bKnown = false;
|
||||
if (this->mAccessPoints.isEmpty() && this->mConnections.isEmpty()) emit this->disappeared();
|
||||
void NMWirelessNetwork::addSettings(NMSettings* settings) {
|
||||
if (this->mSettings.contains(settings->path())) return;
|
||||
this->mSettings.insert(settings->path(), settings);
|
||||
|
||||
auto onDestroyed = [this, settings]() {
|
||||
if (this->mSettings.take(settings->path())) {
|
||||
emit this->settingsRemoved(settings);
|
||||
this->updateReferenceSettings();
|
||||
if (this->mSettings.isEmpty()) this->bKnown = false;
|
||||
if (this->mAccessPoints.isEmpty() && this->mSettings.isEmpty()) emit this->disappeared();
|
||||
}
|
||||
};
|
||||
// clang-format off
|
||||
QObject::connect(conn, &NMConnectionSettings::securityChanged, this, &NMWirelessNetwork::updateReferenceConnection);
|
||||
QObject::connect(conn, &NMConnectionSettings::destroyed, this, onDestroyed);
|
||||
// clang-format on
|
||||
QObject::connect(settings, &NMSettings::destroyed, this, onDestroyed);
|
||||
this->bKnown = true;
|
||||
this->updateReferenceConnection();
|
||||
this->updateReferenceSettings();
|
||||
emit this->settingsAdded(settings);
|
||||
};
|
||||
|
||||
void NMWirelessNetwork::addActiveConnection(NMActiveConnection* active) {
|
||||
if (this->mActiveConnection) return;
|
||||
this->mActiveConnection = active;
|
||||
|
||||
this->bState.setBinding([active]() { return active->state(); });
|
||||
this->bReason.setBinding([active]() { return active->stateReason(); });
|
||||
auto onDestroyed = [this, active]() {
|
||||
if (this->mActiveConnection && this->mActiveConnection == active) {
|
||||
this->mActiveConnection = nullptr;
|
||||
this->updateReferenceConnection();
|
||||
this->updateReferenceSettings();
|
||||
this->bState = NMConnectionState::Deactivated;
|
||||
this->bReason = NMConnectionStateReason::None;
|
||||
}
|
||||
};
|
||||
QObject::connect(active, &NMActiveConnection::destroyed, this, onDestroyed);
|
||||
this->updateReferenceConnection();
|
||||
this->updateReferenceSettings();
|
||||
};
|
||||
|
||||
void NMWirelessNetwork::forget() {
|
||||
if (this->mConnections.isEmpty()) return;
|
||||
for (auto* conn: this->mConnections.values()) {
|
||||
if (this->mSettings.isEmpty()) return;
|
||||
for (auto* conn: this->mSettings.values()) {
|
||||
conn->forget();
|
||||
}
|
||||
}
|
||||
@@ -200,7 +210,7 @@ void NMWirelessDevice::initWireless() {
|
||||
QObject::connect(this->wirelessProxy, &DBusNMWirelessProxy::AccessPointAdded, this, &NMWirelessDevice::onAccessPointAdded);
|
||||
QObject::connect(this->wirelessProxy, &DBusNMWirelessProxy::AccessPointRemoved, this, &NMWirelessDevice::onAccessPointRemoved);
|
||||
QObject::connect(this, &NMWirelessDevice::accessPointLoaded, this, &NMWirelessDevice::onAccessPointLoaded);
|
||||
QObject::connect(this, &NMWirelessDevice::connectionLoaded, this, &NMWirelessDevice::onConnectionLoaded);
|
||||
QObject::connect(this, &NMWirelessDevice::settingsLoaded, this, &NMWirelessDevice::onSettingsLoaded);
|
||||
QObject::connect(this, &NMWirelessDevice::activeConnectionLoaded, this, &NMWirelessDevice::onActiveConnectionLoaded);
|
||||
QObject::connect(this, &NMWirelessDevice::scanningChanged, this, &NMWirelessDevice::onScanningChanged);
|
||||
// clang-format on
|
||||
@@ -218,6 +228,7 @@ void NMWirelessDevice::onAccessPointRemoved(const QDBusObjectPath& path) {
|
||||
<< "which is not registered.";
|
||||
return;
|
||||
}
|
||||
qCDebug(logNetworkManager) << "Access point removed:" << path.path();
|
||||
delete ap;
|
||||
}
|
||||
|
||||
@@ -233,28 +244,26 @@ void NMWirelessDevice::onAccessPointLoaded(NMAccessPoint* ap) {
|
||||
}
|
||||
}
|
||||
|
||||
void NMWirelessDevice::onConnectionLoaded(NMConnectionSettings* conn) {
|
||||
const ConnectionSettingsMap& settings = conn->settings();
|
||||
void NMWirelessDevice::onSettingsLoaded(NMSettings* settings) {
|
||||
const NMSettingsMap& map = settings->map();
|
||||
// Filter connections that aren't wireless or have missing settings
|
||||
if (settings["connection"]["id"].toString().isEmpty()
|
||||
|| settings["connection"]["uuid"].toString().isEmpty()
|
||||
|| !settings.contains("802-11-wireless")
|
||||
|| settings["802-11-wireless"]["ssid"].toString().isEmpty())
|
||||
if (map["connection"]["id"].toString().isEmpty() || map["connection"]["uuid"].toString().isEmpty()
|
||||
|| !map.contains("802-11-wireless") || map["802-11-wireless"]["ssid"].toString().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto ssid = settings["802-11-wireless"]["ssid"].toString();
|
||||
const auto mode = settings["802-11-wireless"]["mode"].toString();
|
||||
const auto ssid = map["802-11-wireless"]["ssid"].toString();
|
||||
const auto mode = map["802-11-wireless"]["mode"].toString();
|
||||
|
||||
if (mode == "infrastructure") {
|
||||
auto* net = this->mNetworks.value(ssid);
|
||||
if (!net) net = this->registerNetwork(ssid);
|
||||
net->addConnection(conn);
|
||||
net->addSettings(settings);
|
||||
|
||||
// Check for active connections that loaded before their respective connection settings
|
||||
auto* active = this->activeConnection();
|
||||
if (active && conn->path() == active->connection().path()) {
|
||||
if (active && settings->path() == active->connection().path()) {
|
||||
net->addActiveConnection(active);
|
||||
}
|
||||
}
|
||||
@@ -265,8 +274,8 @@ void NMWirelessDevice::onActiveConnectionLoaded(NMActiveConnection* active) {
|
||||
// Find an exisiting network with connection settings that matches the active
|
||||
const QString activeConnPath = active->connection().path();
|
||||
for (const auto& net: this->mNetworks.values()) {
|
||||
for (auto* conn: net->connections()) {
|
||||
if (activeConnPath == conn->path()) {
|
||||
for (auto* settings: net->settings()) {
|
||||
if (activeConnPath == settings->path()) {
|
||||
net->addActiveConnection(active);
|
||||
return;
|
||||
}
|
||||
@@ -334,6 +343,7 @@ void NMWirelessDevice::registerAccessPoint(const QString& path) {
|
||||
return;
|
||||
}
|
||||
|
||||
qCDebug(logNetworkManager) << "Access point added:" << path;
|
||||
this->mAccessPoints.insert(path, ap);
|
||||
QObject::connect(
|
||||
ap,
|
||||
@@ -356,22 +366,18 @@ void NMWirelessDevice::registerAccessPoint(const QString& path) {
|
||||
NMWirelessNetwork* NMWirelessDevice::registerNetwork(const QString& ssid) {
|
||||
auto* net = new NMWirelessNetwork(ssid, this);
|
||||
|
||||
// To avoid exposing outdated state to the frontend, filter the backend networks to only show
|
||||
// the known or currently connected networks when the scanner is off.
|
||||
auto visible = [this, net]() {
|
||||
return this->bScanning || net->state() == NMConnectionState::Activated || net->known();
|
||||
};
|
||||
auto onVisibilityChanged = [this, net](bool visible) {
|
||||
visible ? this->registerFrontendNetwork(net) : this->removeFrontendNetwork(net);
|
||||
};
|
||||
|
||||
net->bindableVisible().setBinding(visible);
|
||||
net->bindableActiveApPath().setBinding([this]() { return this->activeApPath().path(); });
|
||||
net->bindableDeviceFailReason().setBinding([this]() { return this->lastFailReason(); });
|
||||
QObject::connect(net, &NMWirelessNetwork::disappeared, this, &NMWirelessDevice::removeNetwork);
|
||||
QObject::connect(net, &NMWirelessNetwork::visibilityChanged, this, onVisibilityChanged);
|
||||
|
||||
qCDebug(logNetworkManager) << "Registered network for SSID" << ssid;
|
||||
this->mNetworks.insert(ssid, net);
|
||||
if (net->visible()) this->registerFrontendNetwork(net);
|
||||
this->registerFrontendNetwork(net);
|
||||
return net;
|
||||
}
|
||||
|
||||
@@ -385,46 +391,137 @@ void NMWirelessDevice::registerFrontendNetwork(NMWirelessNetwork* net) {
|
||||
frontendNet->bindableSignalStrength().setBinding(translateSignal);
|
||||
frontendNet->bindableConnected().setBinding(translateState);
|
||||
frontendNet->bindableKnown().setBinding([net]() { return net->known(); });
|
||||
frontendNet->bindableNmReason().setBinding([net]() { return net->reason(); });
|
||||
frontendNet->bindableSecurity().setBinding([net]() { return net->security(); });
|
||||
frontendNet->bindableState().setBinding([net]() {
|
||||
return static_cast<NetworkState::Enum>(net->state());
|
||||
return static_cast<ConnectionState::Enum>(net->state());
|
||||
});
|
||||
|
||||
QObject::connect(net, &NMWirelessNetwork::reasonChanged, this, [net, frontendNet]() {
|
||||
if (net->reason() == NMConnectionStateReason::DeviceDisconnected) {
|
||||
auto deviceReason = net->deviceFailReason();
|
||||
if (deviceReason == NMDeviceStateReason::NoSecrets)
|
||||
emit frontendNet->connectionFailed(ConnectionFailReason::NoSecrets);
|
||||
if (deviceReason == NMDeviceStateReason::SupplicantDisconnect)
|
||||
emit frontendNet->connectionFailed(ConnectionFailReason::WifiClientDisconnected);
|
||||
if (deviceReason == NMDeviceStateReason::SupplicantFailed)
|
||||
emit frontendNet->connectionFailed(ConnectionFailReason::WifiClientFailed);
|
||||
if (deviceReason == NMDeviceStateReason::SupplicantTimeout)
|
||||
emit frontendNet->connectionFailed(ConnectionFailReason::WifiAuthTimeout);
|
||||
if (deviceReason == NMDeviceStateReason::SsidNotFound)
|
||||
emit frontendNet->connectionFailed(ConnectionFailReason::WifiNetworkLost);
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(frontendNet, &WifiNetwork::requestConnect, this, [this, net]() {
|
||||
if (net->referenceConnection()) {
|
||||
if (net->referenceSettings()) {
|
||||
emit this->activateConnection(
|
||||
QDBusObjectPath(net->referenceConnection()->path()),
|
||||
QDBusObjectPath(net->referenceSettings()->path()),
|
||||
QDBusObjectPath(this->path())
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (net->referenceAp()) {
|
||||
emit this->addAndActivateConnection(
|
||||
ConnectionSettingsMap(),
|
||||
NMSettingsMap(),
|
||||
QDBusObjectPath(this->path()),
|
||||
QDBusObjectPath(net->referenceAp()->path())
|
||||
);
|
||||
return;
|
||||
}
|
||||
qCInfo(logNetworkManager) << "Failed to connect to"
|
||||
<< this->path() + ": The network disappeared.";
|
||||
});
|
||||
|
||||
QObject::connect(
|
||||
frontendNet,
|
||||
&WifiNetwork::requestDisconnect,
|
||||
&WifiNetwork::requestConnectWithPsk,
|
||||
this,
|
||||
&NMWirelessDevice::disconnect
|
||||
[this, net](const QString& psk) {
|
||||
NMSettingsMap settings;
|
||||
settings["802-11-wireless-security"]["psk"] = psk;
|
||||
if (const QPointer<NMSettings> ref = net->referenceSettings()) {
|
||||
auto* call = ref->updateSettings(settings);
|
||||
QObject::connect(
|
||||
call,
|
||||
&QDBusPendingCallWatcher::finished,
|
||||
this,
|
||||
[this, ref](QDBusPendingCallWatcher* call) {
|
||||
const QDBusPendingReply<> reply = *call;
|
||||
|
||||
if (reply.isError()) {
|
||||
qCInfo(logNetworkManager)
|
||||
<< "Failed to write PSK for" << this->path() + ":" << reply.error().message();
|
||||
} else {
|
||||
if (!ref) {
|
||||
qCInfo(logNetworkManager) << "Failed to connectWithPsk to"
|
||||
<< this->path() + ": The settings disappeared.";
|
||||
} else {
|
||||
emit this->activateConnection(
|
||||
QDBusObjectPath(ref->path()),
|
||||
QDBusObjectPath(this->path())
|
||||
);
|
||||
}
|
||||
}
|
||||
delete call;
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (net->referenceAp()) {
|
||||
emit this->addAndActivateConnection(
|
||||
settings,
|
||||
QDBusObjectPath(this->path()),
|
||||
QDBusObjectPath(net->referenceAp()->path())
|
||||
);
|
||||
return;
|
||||
}
|
||||
qCInfo(logNetworkManager) << "Failed to connectWithPsk to"
|
||||
<< this->path() + ": The network disappeared.";
|
||||
}
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
frontendNet,
|
||||
&WifiNetwork::requestConnectWithSettings,
|
||||
this,
|
||||
[this](NMSettings* settings) {
|
||||
if (settings) {
|
||||
emit this->activateConnection(
|
||||
QDBusObjectPath(settings->path()),
|
||||
QDBusObjectPath(this->path())
|
||||
);
|
||||
return;
|
||||
}
|
||||
qCInfo(logNetworkManager) << "Failed to connectWithSettings to"
|
||||
<< this->path() + ": The provided settings no longer exist.";
|
||||
}
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
net,
|
||||
&NMWirelessNetwork::visibilityChanged,
|
||||
this,
|
||||
[this, frontendNet](bool visible) {
|
||||
if (visible) this->networkAdded(frontendNet);
|
||||
else this->networkRemoved(frontendNet);
|
||||
}
|
||||
);
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(frontendNet, &WifiNetwork::requestDisconnect, this, &NMWirelessDevice::disconnect);
|
||||
QObject::connect(frontendNet, &WifiNetwork::requestForget, net, &NMWirelessNetwork::forget);
|
||||
QObject::connect(net, &NMWirelessNetwork::settingsAdded, frontendNet, &WifiNetwork::settingsAdded);
|
||||
QObject::connect(net, &NMWirelessNetwork::settingsRemoved, frontendNet, &WifiNetwork::settingsRemoved);
|
||||
// clang-format on
|
||||
|
||||
this->mFrontendNetworks.insert(ssid, frontendNet);
|
||||
emit this->networkAdded(frontendNet);
|
||||
if (net->visible()) emit this->networkAdded(frontendNet);
|
||||
}
|
||||
|
||||
void NMWirelessDevice::removeFrontendNetwork(NMWirelessNetwork* net) {
|
||||
auto* frontendNet = this->mFrontendNetworks.take(net->ssid());
|
||||
if (frontendNet) {
|
||||
emit this->networkRemoved(frontendNet);
|
||||
if (net->visible()) emit this->networkRemoved(frontendNet);
|
||||
frontendNet->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
+33
-26
@@ -9,10 +9,11 @@
|
||||
|
||||
#include "../wifi.hpp"
|
||||
#include "accesspoint.hpp"
|
||||
#include "connection.hpp"
|
||||
#include "active_connection.hpp"
|
||||
#include "dbus_nm_wireless.h"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
namespace qs::dbus {
|
||||
template <>
|
||||
@@ -32,7 +33,7 @@ struct DBusDataTransform<QDateTime> {
|
||||
} // namespace qs::dbus
|
||||
namespace qs::network {
|
||||
|
||||
// NMWirelessNetwork aggregates all related NMActiveConnection, NMAccessPoint, and NMConnectionSetting objects.
|
||||
// NMWirelessNetwork aggregates all related NMActiveConnection, NMAccessPoint, and NMSettings objects.
|
||||
class NMWirelessNetwork: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
@@ -40,46 +41,51 @@ public:
|
||||
explicit NMWirelessNetwork(QString ssid, QObject* parent = nullptr);
|
||||
|
||||
void addAccessPoint(NMAccessPoint* ap);
|
||||
void addConnection(NMConnectionSettings* conn);
|
||||
void addSettings(NMSettings* settings);
|
||||
void addActiveConnection(NMActiveConnection* active);
|
||||
void forget();
|
||||
|
||||
[[nodiscard]] QString ssid() const { return this->mSsid; };
|
||||
[[nodiscard]] quint8 signalStrength() const { return this->bSignalStrength; };
|
||||
[[nodiscard]] WifiSecurityType::Enum security() const { return this->bSecurity; };
|
||||
[[nodiscard]] NMConnectionState::Enum state() const { return this->bState; };
|
||||
[[nodiscard]] bool known() const { return this->bKnown; };
|
||||
[[nodiscard]] NMConnectionStateReason::Enum reason() const { return this->bReason; };
|
||||
[[nodiscard]] NMAccessPoint* referenceAp() const { return this->mReferenceAp; };
|
||||
[[nodiscard]] NMConnectionSettings* referenceConnection() const { return this->mReferenceConn; };
|
||||
[[nodiscard]] QList<NMAccessPoint*> accessPoints() const { return this->mAccessPoints.values(); };
|
||||
[[nodiscard]] QList<NMConnectionSettings*> connections() const {
|
||||
return this->mConnections.values();
|
||||
}
|
||||
[[nodiscard]] QBindable<QString> bindableActiveApPath() { return &this->bActiveApPath; };
|
||||
[[nodiscard]] QBindable<bool> bindableVisible() { return &this->bVisible; };
|
||||
[[nodiscard]] bool visible() const { return this->bVisible; };
|
||||
// clang-format off
|
||||
[[nodiscard]] QString ssid() const { return this->mSsid; }
|
||||
[[nodiscard]] quint8 signalStrength() const { return this->bSignalStrength; }
|
||||
[[nodiscard]] WifiSecurityType::Enum security() const { return this->bSecurity; }
|
||||
[[nodiscard]] NMConnectionState::Enum state() const { return this->bState; }
|
||||
[[nodiscard]] bool known() const { return this->bKnown; }
|
||||
[[nodiscard]] NMConnectionStateReason::Enum reason() const { return this->bReason; }
|
||||
QBindable<NMDeviceStateReason::Enum> bindableDeviceFailReason() { return &this->bDeviceFailReason; }
|
||||
[[nodiscard]] NMDeviceStateReason::Enum deviceFailReason() const { return this->bDeviceFailReason; }
|
||||
[[nodiscard]] NMAccessPoint* referenceAp() const { return this->mReferenceAp; }
|
||||
[[nodiscard]] QList<NMAccessPoint*> accessPoints() const { return this->mAccessPoints.values(); }
|
||||
[[nodiscard]] QList<NMSettings*> settings() const { return this->mSettings.values(); }
|
||||
[[nodiscard]] NMSettings* referenceSettings() const { return this->mReferenceSettings; }
|
||||
QBindable<QString> bindableActiveApPath() { return &this->bActiveApPath; }
|
||||
QBindable<bool> bindableVisible() { return &this->bVisible; }
|
||||
bool visible() const { return this->bVisible; }
|
||||
// clang-format on
|
||||
|
||||
signals:
|
||||
void disappeared();
|
||||
void settingsAdded(NMSettings* settings);
|
||||
void settingsRemoved(NMSettings* settings);
|
||||
void visibilityChanged(bool visible);
|
||||
void signalStrengthChanged(quint8 signal);
|
||||
void stateChanged(NMConnectionState::Enum state);
|
||||
void knownChanged(bool known);
|
||||
void securityChanged(WifiSecurityType::Enum security);
|
||||
void reasonChanged(NMConnectionStateReason::Enum reason);
|
||||
void deviceFailReasonChanged(NMDeviceStateReason::Enum reason);
|
||||
void capabilitiesChanged(NMWirelessCapabilities::Enum caps);
|
||||
void activeApPathChanged(QString path);
|
||||
|
||||
private:
|
||||
void updateReferenceAp();
|
||||
void updateReferenceConnection();
|
||||
void updateReferenceSettings();
|
||||
|
||||
QString mSsid;
|
||||
QHash<QString, NMAccessPoint*> mAccessPoints;
|
||||
QHash<QString, NMConnectionSettings*> mConnections;
|
||||
QHash<QString, NMSettings*> mSettings;
|
||||
NMAccessPoint* mReferenceAp = nullptr;
|
||||
NMConnectionSettings* mReferenceConn = nullptr;
|
||||
NMSettings* mReferenceSettings = nullptr;
|
||||
NMActiveConnection* mActiveConnection = nullptr;
|
||||
|
||||
// clang-format off
|
||||
@@ -88,6 +94,7 @@ private:
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMWirelessNetwork, WifiSecurityType::Enum, bSecurity, &NMWirelessNetwork::securityChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMWirelessNetwork, NMConnectionStateReason::Enum, bReason, &NMWirelessNetwork::reasonChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMWirelessNetwork, NMConnectionState::Enum, bState, &NMWirelessNetwork::stateChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMWirelessNetwork, NMDeviceStateReason::Enum, bDeviceFailReason, &NMWirelessNetwork::deviceFailReasonChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMWirelessNetwork, quint8, bSignalStrength, &NMWirelessNetwork::signalStrengthChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(NMWirelessNetwork, QString, bActiveApPath, &NMWirelessNetwork::activeApPathChanged);
|
||||
// clang-format on
|
||||
@@ -103,10 +110,10 @@ public:
|
||||
explicit NMWirelessDevice(const QString& path, QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] bool isValid() const override;
|
||||
[[nodiscard]] NMWirelessCapabilities::Enum capabilities() { return this->bCapabilities; };
|
||||
[[nodiscard]] const QDBusObjectPath& activeApPath() { return this->bActiveAccessPoint; };
|
||||
[[nodiscard]] NM80211Mode::Enum mode() { return this->bMode; };
|
||||
[[nodiscard]] QBindable<bool> bindableScanning() { return &this->bScanning; };
|
||||
[[nodiscard]] NMWirelessCapabilities::Enum capabilities() { return this->bCapabilities; }
|
||||
[[nodiscard]] const QDBusObjectPath& activeApPath() { return this->bActiveAccessPoint; }
|
||||
[[nodiscard]] NM80211Mode::Enum mode() { return this->bMode; }
|
||||
[[nodiscard]] QBindable<bool> bindableScanning() { return &this->bScanning; }
|
||||
|
||||
signals:
|
||||
void accessPointLoaded(NMAccessPoint* ap);
|
||||
@@ -123,7 +130,7 @@ private slots:
|
||||
void onAccessPointAdded(const QDBusObjectPath& path);
|
||||
void onAccessPointRemoved(const QDBusObjectPath& path);
|
||||
void onAccessPointLoaded(NMAccessPoint* ap);
|
||||
void onConnectionLoaded(NMConnectionSettings* conn);
|
||||
void onSettingsLoaded(NMSettings* settings);
|
||||
void onActiveConnectionLoaded(NMActiveConnection* active);
|
||||
void onScanTimeout();
|
||||
void onScanningChanged(bool scanning);
|
||||
|
||||
+344
-139
@@ -5,151 +5,356 @@ import Quickshell
|
||||
import Quickshell.Widgets
|
||||
import Quickshell.Networking
|
||||
|
||||
FloatingWindow {
|
||||
color: contentItem.palette.window
|
||||
Scope {
|
||||
Component {
|
||||
id: editorComponent
|
||||
FloatingWindow {
|
||||
id: editorWindow
|
||||
required property var nmSettings
|
||||
color: contentItem.palette.window
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 5
|
||||
Component.onCompleted: editorArea.text = JSON.stringify(nmSettings.read(), null, 2)
|
||||
|
||||
Column {
|
||||
Layout.fillWidth: true
|
||||
RowLayout {
|
||||
Label {
|
||||
text: "WiFi"
|
||||
font.bold: true
|
||||
font.pointSize: 12
|
||||
}
|
||||
CheckBox {
|
||||
text: "Software"
|
||||
checked: Networking.wifiEnabled
|
||||
onClicked: Networking.wifiEnabled = !Networking.wifiEnabled
|
||||
}
|
||||
CheckBox {
|
||||
enabled: false
|
||||
text: "Hardware"
|
||||
checked: Networking.wifiHardwareEnabled
|
||||
}
|
||||
}
|
||||
}
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 10
|
||||
|
||||
ListView {
|
||||
clip: true
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
model: Networking.devices
|
||||
Label {
|
||||
text: "Editing " + nmSettings?.id + " (" + nmSettings?.uuid + ")"
|
||||
font.bold: true
|
||||
font.pointSize: 12
|
||||
}
|
||||
|
||||
delegate: WrapperRectangle {
|
||||
width: parent.width
|
||||
color: "transparent"
|
||||
border.color: palette.button
|
||||
border.width: 1
|
||||
margin: 5
|
||||
ScrollView {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
TextArea {
|
||||
id: editorArea
|
||||
wrapMode: TextEdit.Wrap
|
||||
selectByMouse: true
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
RowLayout {
|
||||
Label { text: modelData.name; font.bold: true }
|
||||
Label { text: modelData.address }
|
||||
Label { text: `(Type: ${DeviceType.toString(modelData.type)})` }
|
||||
}
|
||||
RowLayout {
|
||||
Label {
|
||||
text: DeviceConnectionState.toString(modelData.state)
|
||||
color: modelData.connected ? palette.link : palette.placeholderText
|
||||
}
|
||||
Label {
|
||||
visible: Networking.backend == NetworkBackendType.NetworkManager && (modelData.state == DeviceConnectionState.Connecting || modelData.state == DeviceConnectionState.Disconnecting)
|
||||
text: `(${NMDeviceState.toString(modelData.nmState)})`
|
||||
}
|
||||
Button {
|
||||
visible: modelData.state == DeviceConnectionState.Connected
|
||||
text: "Disconnect"
|
||||
onClicked: modelData.disconnect()
|
||||
}
|
||||
CheckBox {
|
||||
text: "Autoconnect"
|
||||
checked: modelData.autoconnect
|
||||
onClicked: modelData.autoconnect = !modelData.autoconnect
|
||||
}
|
||||
Label {
|
||||
text: `Mode: ${WifiDeviceMode.toString(modelData.mode)}`
|
||||
visible: modelData.type == DeviceType.Wifi
|
||||
}
|
||||
CheckBox {
|
||||
text: "Scanner"
|
||||
checked: modelData.scannerEnabled
|
||||
onClicked: modelData.scannerEnabled = !modelData.scannerEnabled
|
||||
visible: modelData.type === DeviceType.Wifi
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Label {
|
||||
id: statusLabel
|
||||
Layout.fillWidth: true
|
||||
color: palette.placeholderText
|
||||
}
|
||||
Button {
|
||||
text: "Reload"
|
||||
onClicked: {
|
||||
editorArea.text = JSON.stringify(editorWindow.nmSettings.read(), null, 2);
|
||||
statusLabel.text = "Reloaded";
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "Save"
|
||||
onClicked: {
|
||||
try {
|
||||
const parsed = JSON.parse(editorArea.text);
|
||||
nmSettings.write(parsed);
|
||||
statusLabel.text = "Saved";
|
||||
} catch (e) {
|
||||
statusLabel.text = "Parse error: " + e.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "Close"
|
||||
onClicked: {
|
||||
editorArea.focus = false;
|
||||
editorWindow.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
Layout.fillWidth: true
|
||||
model: {
|
||||
if (modelData.type !== DeviceType.Wifi) return []
|
||||
return [...modelData.networks.values].sort((a, b) => {
|
||||
if (a.connected !== b.connected) {
|
||||
return b.connected - a.connected
|
||||
}
|
||||
return b.signalStrength - a.signalStrength
|
||||
})
|
||||
}
|
||||
FloatingWindow {
|
||||
color: contentItem.palette.window
|
||||
|
||||
WrapperRectangle {
|
||||
Layout.fillWidth: true
|
||||
color: modelData.connected ? palette.highlight : palette.button
|
||||
border.color: palette.mid
|
||||
border.width: 1
|
||||
margin: 5
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 5
|
||||
|
||||
RowLayout {
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
RowLayout {
|
||||
Label { text: modelData.name; font.bold: true }
|
||||
Label {
|
||||
text: modelData.known ? "Known" : ""
|
||||
color: palette.placeholderText
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
Label {
|
||||
text: `Security: ${WifiSecurityType.toString(modelData.security)}`
|
||||
color: palette.placeholderText
|
||||
}
|
||||
Label {
|
||||
text: `| Signal strength: ${Math.round(modelData.signalStrength*100)}%`
|
||||
color: palette.placeholderText
|
||||
}
|
||||
}
|
||||
Label {
|
||||
visible: Networking.backend == NetworkBackendType.NetworkManager && (modelData.nmReason != NMConnectionStateReason.Unknown && modelData.nmReason != NMConnectionStateReason.None)
|
||||
text: `Connection change reason: ${NMConnectionStateReason.toString(modelData.nmReason)}`
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Button {
|
||||
text: "Connect"
|
||||
onClicked: modelData.connect()
|
||||
visible: !modelData.connected
|
||||
}
|
||||
Button {
|
||||
text: "Disconnect"
|
||||
onClicked: modelData.disconnect()
|
||||
visible: modelData.connected
|
||||
}
|
||||
Button {
|
||||
text: "Forget"
|
||||
onClicked: modelData.forget()
|
||||
visible: modelData.known
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ColumnLayout {
|
||||
Label {
|
||||
text: `Networking (${NetworkBackendType.toString(Networking.backend)} backend)`
|
||||
font.bold: true
|
||||
font.pointSize: 12
|
||||
}
|
||||
RowLayout {
|
||||
Label {
|
||||
text: `Connectivity`
|
||||
font.bold: true
|
||||
}
|
||||
Label {
|
||||
text: `${NetworkConnectivity.toString(Networking.connectivity)}`
|
||||
visible: Networking.canCheckConnectivity
|
||||
}
|
||||
Button {
|
||||
text: "Re-check"
|
||||
visible: Networking.canCheckConnectivity && Networking.connectivityCheckEnabled
|
||||
onClicked: Networking.checkConnectivity()
|
||||
}
|
||||
CheckBox {
|
||||
text: "Checking enabled"
|
||||
checked: Networking.connectivityCheckEnabled
|
||||
onClicked: Networking.connectivityCheckEnabled = !Networking.connectivityCheckEnabled
|
||||
visible: Networking.canCheckConnectivity
|
||||
}
|
||||
CheckBox {
|
||||
enabled: false
|
||||
text: "Supported"
|
||||
checked: Networking.canCheckConnectivity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
Layout.fillWidth: true
|
||||
RowLayout {
|
||||
Label {
|
||||
text: "WiFi"
|
||||
font.bold: true
|
||||
}
|
||||
CheckBox {
|
||||
text: "Software"
|
||||
checked: Networking.wifiEnabled
|
||||
onClicked: Networking.wifiEnabled = !Networking.wifiEnabled
|
||||
}
|
||||
CheckBox {
|
||||
enabled: false
|
||||
text: "Hardware"
|
||||
checked: Networking.wifiHardwareEnabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
clip: true
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
model: Networking.devices
|
||||
|
||||
delegate: WrapperRectangle {
|
||||
width: parent.width
|
||||
color: "transparent"
|
||||
border.color: palette.button
|
||||
border.width: 1
|
||||
margin: 5
|
||||
|
||||
ColumnLayout {
|
||||
RowLayout {
|
||||
Label {
|
||||
text: modelData.name
|
||||
font.bold: true
|
||||
}
|
||||
Label {
|
||||
text: modelData.address
|
||||
}
|
||||
Label {
|
||||
text: `(Type: ${DeviceType.toString(modelData.type)})`
|
||||
}
|
||||
CheckBox {
|
||||
text: `Managed`
|
||||
checked: modelData.nmManaged
|
||||
onClicked: modelData.nmManaged = !modelData.nmManaged
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
Label {
|
||||
text: ConnectionState.toString(modelData.state)
|
||||
color: modelData.connected ? palette.link : palette.placeholderText
|
||||
}
|
||||
Button {
|
||||
visible: modelData.state == ConnectionState.Connected
|
||||
text: "Disconnect"
|
||||
onClicked: modelData.disconnect()
|
||||
}
|
||||
CheckBox {
|
||||
text: "Autoconnect"
|
||||
checked: modelData.autoconnect
|
||||
onClicked: modelData.autoconnect = !modelData.autoconnect
|
||||
}
|
||||
Label {
|
||||
text: `Mode: ${WifiDeviceMode.toString(modelData.mode)}`
|
||||
visible: modelData.type == DeviceType.Wifi
|
||||
}
|
||||
CheckBox {
|
||||
text: "Scanner"
|
||||
checked: modelData.scannerEnabled
|
||||
onClicked: modelData.scannerEnabled = !modelData.scannerEnabled
|
||||
visible: modelData.type === DeviceType.Wifi
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
Layout.fillWidth: true
|
||||
model: ScriptModel {
|
||||
values: [...modelData.networks.values].sort((a, b) => {
|
||||
if (a.connected !== b.connected) {
|
||||
return b.connected - a.connected;
|
||||
}
|
||||
return b.signalStrength - a.signalStrength;
|
||||
})
|
||||
}
|
||||
|
||||
WrapperRectangle {
|
||||
property var chosenSettings: {
|
||||
const settings = modelData.nmSettings;
|
||||
if (!settings || settings.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (settings.length === 1) {
|
||||
return settings[0];
|
||||
}
|
||||
return settings[settingsComboBox.currentIndex];
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: modelData
|
||||
function onConnectionFailed(reason) {
|
||||
failLoader.sourceComponent = failComponent;
|
||||
failLoader.item.failReason = reason;
|
||||
}
|
||||
function onStateChanged() {
|
||||
if (modelData.state == ConnectionState.Connecting) {
|
||||
failLoader.sourceComponent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: failComponent
|
||||
RowLayout {
|
||||
property var failReason
|
||||
Label {
|
||||
text: ConnectionFailReason.toString(failReason)
|
||||
}
|
||||
RowLayout {
|
||||
TextField {
|
||||
id: pskField
|
||||
placeholderText: "PSK"
|
||||
}
|
||||
Button {
|
||||
text: "Set"
|
||||
visible: pskField.visible
|
||||
onClicked: {
|
||||
modelData.connectWithPsk(pskField.text);
|
||||
failLoader.sourceComponent = null;
|
||||
}
|
||||
}
|
||||
visible: modelData.security === WifiSecurityType.WpaPsk || modelData.security === WifiSecurityType.Wpa2Psk || modelData.security === WifiSecurityType.Sae
|
||||
}
|
||||
Button {
|
||||
text: "Close"
|
||||
onClicked: failLoader.sourceComponent = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
color: modelData.connected ? palette.highlight : palette.button
|
||||
border.color: palette.mid
|
||||
border.width: 1
|
||||
margin: 5
|
||||
|
||||
RowLayout {
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
RowLayout {
|
||||
Label {
|
||||
text: modelData.name
|
||||
font.bold: true
|
||||
}
|
||||
Label {
|
||||
text: modelData.known ? "Known" : ""
|
||||
color: palette.placeholderText
|
||||
}
|
||||
}
|
||||
RowLayout {
|
||||
Label {
|
||||
text: `Security: ${WifiSecurityType.toString(modelData.security)}`
|
||||
color: palette.placeholderText
|
||||
}
|
||||
Label {
|
||||
text: `| Signal strength: ${Math.round(modelData.signalStrength * 100)}%`
|
||||
color: palette.placeholderText
|
||||
}
|
||||
}
|
||||
}
|
||||
ColumnLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
BusyIndicator {
|
||||
implicitHeight: 30
|
||||
implicitWidth: 30
|
||||
running: modelData.stateChanging
|
||||
visible: modelData.stateChanging
|
||||
}
|
||||
Label {
|
||||
text: ConnectionState.toString(modelData.state)
|
||||
color: modelData.connected ? palette.link : palette.placeholderText
|
||||
}
|
||||
RowLayout {
|
||||
Label {
|
||||
text: "Choose settings:"
|
||||
}
|
||||
ComboBox {
|
||||
id: settingsComboBox
|
||||
model: modelData.nmSettings.map(s => s?.read()?.connection?.id)
|
||||
currentIndex: 0
|
||||
}
|
||||
visible: modelData.nmSettings.length > 1
|
||||
}
|
||||
Button {
|
||||
text: "Connect"
|
||||
onClicked: {
|
||||
if (chosenSettings)
|
||||
modelData.connectWithSettings(chosenSettings);
|
||||
else
|
||||
modelData.connect();
|
||||
}
|
||||
visible: !modelData.connected
|
||||
}
|
||||
Button {
|
||||
text: "Disconnect"
|
||||
onClicked: modelData.disconnect()
|
||||
visible: modelData.connected
|
||||
}
|
||||
Button {
|
||||
text: "Forget"
|
||||
onClicked: modelData.forget()
|
||||
visible: modelData.known
|
||||
}
|
||||
Button {
|
||||
text: "Edit"
|
||||
visible: modelData.known
|
||||
onClicked: {
|
||||
if (chosenSettings)
|
||||
editorComponent.createObject(null, {
|
||||
nmSettings: chosenSettings
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loader {
|
||||
id: failLoader
|
||||
Layout.alignment: Qt.AlignRight
|
||||
visible: sourceComponent !== null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-74
@@ -6,99 +6,35 @@
|
||||
#include <qloggingcategory.h>
|
||||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "../core/logcat.hpp"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "network.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
namespace {
|
||||
QS_LOGGING_CATEGORY(logWifi, "quickshell.network.wifi", QtWarningMsg);
|
||||
} // namespace
|
||||
|
||||
QString WifiSecurityType::toString(WifiSecurityType::Enum type) {
|
||||
switch (type) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case Wpa3SuiteB192: return QStringLiteral("WPA3 Suite B 192-bit");
|
||||
case Sae: return QStringLiteral("WPA3");
|
||||
case Wpa2Eap: return QStringLiteral("WPA2 Enterprise");
|
||||
case Wpa2Psk: return QStringLiteral("WPA2");
|
||||
case WpaEap: return QStringLiteral("WPA Enterprise");
|
||||
case WpaPsk: return QStringLiteral("WPA");
|
||||
case StaticWep: return QStringLiteral("WEP");
|
||||
case DynamicWep: return QStringLiteral("Dynamic WEP");
|
||||
case Leap: return QStringLiteral("LEAP");
|
||||
case Owe: return QStringLiteral("OWE");
|
||||
case Open: return QStringLiteral("Open");
|
||||
default: return QStringLiteral("Unknown");
|
||||
}
|
||||
QS_LOGGING_CATEGORY(logWifiNetwork, "quickshell.wifinetwork", QtWarningMsg);
|
||||
}
|
||||
|
||||
QString WifiDeviceMode::toString(WifiDeviceMode::Enum mode) {
|
||||
switch (mode) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case AdHoc: return QStringLiteral("Ad-Hoc");
|
||||
case Station: return QStringLiteral("Station");
|
||||
case AccessPoint: return QStringLiteral("Access Point");
|
||||
case Mesh: return QStringLiteral("Mesh");
|
||||
default: return QStringLiteral("Unknown");
|
||||
};
|
||||
}
|
||||
|
||||
QString NMConnectionStateReason::toString(NMConnectionStateReason::Enum reason) {
|
||||
switch (reason) {
|
||||
case Unknown: return QStringLiteral("Unknown");
|
||||
case None: return QStringLiteral("No reason");
|
||||
case UserDisconnected: return QStringLiteral("User disconnection");
|
||||
case DeviceDisconnected:
|
||||
return QStringLiteral("The device the connection was using was disconnected.");
|
||||
case ServiceStopped:
|
||||
return QStringLiteral("The service providing the VPN connection was stopped.");
|
||||
case IpConfigInvalid:
|
||||
return QStringLiteral("The IP config of the active connection was invalid.");
|
||||
case ConnectTimeout:
|
||||
return QStringLiteral("The connection attempt to the VPN service timed out.");
|
||||
case ServiceStartTimeout:
|
||||
return QStringLiteral(
|
||||
"A timeout occurred while starting the service providing the VPN connection."
|
||||
);
|
||||
case ServiceStartFailed:
|
||||
return QStringLiteral("Starting the service providing the VPN connection failed.");
|
||||
case NoSecrets: return QStringLiteral("Necessary secrets for the connection were not provided.");
|
||||
case LoginFailed: return QStringLiteral("Authentication to the server failed.");
|
||||
case ConnectionRemoved:
|
||||
return QStringLiteral("Necessary secrets for the connection were not provided.");
|
||||
case DependencyFailed:
|
||||
return QStringLiteral("Master connection of this connection failed to activate.");
|
||||
case DeviceRealizeFailed: return QStringLiteral("Could not create the software device link.");
|
||||
case DeviceRemoved: return QStringLiteral("The device this connection depended on disappeared.");
|
||||
default: return QStringLiteral("Unknown");
|
||||
};
|
||||
};
|
||||
|
||||
WifiNetwork::WifiNetwork(QString ssid, QObject* parent): Network(std::move(ssid), parent) {};
|
||||
|
||||
void WifiNetwork::connect() {
|
||||
void WifiNetwork::connectWithPsk(const QString& psk) {
|
||||
if (this->bConnected) {
|
||||
qCCritical(logWifi) << this << "is already connected.";
|
||||
qCCritical(logWifiNetwork) << this << "is already connected.";
|
||||
return;
|
||||
}
|
||||
|
||||
this->requestConnect();
|
||||
}
|
||||
|
||||
void WifiNetwork::disconnect() {
|
||||
if (!this->bConnected) {
|
||||
qCCritical(logWifi) << this << "is not currently connected";
|
||||
if (this->bSecurity != WifiSecurityType::WpaPsk && this->bSecurity != WifiSecurityType::Wpa2Psk
|
||||
&& this->bSecurity != WifiSecurityType::Sae)
|
||||
{
|
||||
qCCritical(logWifiNetwork) << this << "has the wrong security type for a PSK.";
|
||||
return;
|
||||
}
|
||||
|
||||
this->requestDisconnect();
|
||||
emit this->requestConnectWithPsk(psk);
|
||||
}
|
||||
|
||||
void WifiNetwork::forget() { this->requestForget(); }
|
||||
|
||||
WifiDevice::WifiDevice(QObject* parent): NetworkDevice(DeviceType::Wifi, parent) {};
|
||||
|
||||
void WifiDevice::setScannerEnabled(bool enabled) {
|
||||
|
||||
+18
-105
@@ -6,90 +6,15 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../core/doc.hpp"
|
||||
#include "../core/model.hpp"
|
||||
#include "device.hpp"
|
||||
#include "enums.hpp"
|
||||
#include "network.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
|
||||
///! The security type of a wifi network.
|
||||
class WifiSecurityType: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Wpa3SuiteB192 = 0,
|
||||
Sae = 1,
|
||||
Wpa2Eap = 2,
|
||||
Wpa2Psk = 3,
|
||||
WpaEap = 4,
|
||||
WpaPsk = 5,
|
||||
StaticWep = 6,
|
||||
DynamicWep = 7,
|
||||
Leap = 8,
|
||||
Owe = 9,
|
||||
Open = 10,
|
||||
Unknown = 11,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(WifiSecurityType::Enum type);
|
||||
};
|
||||
|
||||
///! The 802.11 mode of a wifi device.
|
||||
class WifiDeviceMode: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
/// The device is part of an Ad-Hoc network without a central access point.
|
||||
AdHoc = 0,
|
||||
/// The device is a station that can connect to networks.
|
||||
Station = 1,
|
||||
/// The device is a local hotspot/access point.
|
||||
AccessPoint = 2,
|
||||
/// The device is an 802.11s mesh point.
|
||||
Mesh = 3,
|
||||
/// The device mode is unknown.
|
||||
Unknown = 4,
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(WifiDeviceMode::Enum mode);
|
||||
};
|
||||
|
||||
///! NetworkManager-specific reason for a WifiNetworks connection state.
|
||||
/// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMActiveConnectionStateReason.
|
||||
class NMConnectionStateReason: public QObject {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_SINGLETON;
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
Unknown = 0,
|
||||
None = 1,
|
||||
UserDisconnected = 2,
|
||||
DeviceDisconnected = 3,
|
||||
ServiceStopped = 4,
|
||||
IpConfigInvalid = 5,
|
||||
ConnectTimeout = 6,
|
||||
ServiceStartTimeout = 7,
|
||||
ServiceStartFailed = 8,
|
||||
NoSecrets = 9,
|
||||
LoginFailed = 10,
|
||||
ConnectionRemoved = 11,
|
||||
DependencyFailed = 12,
|
||||
DeviceRealizeFailed = 13,
|
||||
DeviceRemoved = 14
|
||||
};
|
||||
Q_ENUM(Enum);
|
||||
Q_INVOKABLE static QString toString(NMConnectionStateReason::Enum reason);
|
||||
};
|
||||
|
||||
///! An available wifi network.
|
||||
///! WiFi subtype of @@Network.
|
||||
class WifiNetwork: public Network {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
@@ -97,58 +22,46 @@ class WifiNetwork: public Network {
|
||||
// clang-format off
|
||||
/// The current signal strength of the network, from 0.0 to 1.0.
|
||||
Q_PROPERTY(qreal signalStrength READ default NOTIFY signalStrengthChanged BINDABLE bindableSignalStrength);
|
||||
/// True if the wifi network has known connection settings saved.
|
||||
Q_PROPERTY(bool known READ default NOTIFY knownChanged BINDABLE bindableKnown);
|
||||
/// The security type of the wifi network.
|
||||
Q_PROPERTY(WifiSecurityType::Enum security READ default NOTIFY securityChanged BINDABLE bindableSecurity);
|
||||
/// A specific reason for the connection state when the backend is NetworkManager.
|
||||
Q_PROPERTY(NMConnectionStateReason::Enum nmReason READ default NOTIFY nmReasonChanged BINDABLE bindableNmReason);
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
explicit WifiNetwork(QString ssid, QObject* parent = nullptr);
|
||||
|
||||
/// Attempt to connect to the wifi network.
|
||||
/// Attempt to connect to the network with the given PSK. If the PSK is wrong,
|
||||
/// a @@Network.connectionFailed(s) signal will be emitted with `NoSecrets`.
|
||||
///
|
||||
/// > [!WARNING] Quickshell does not yet provide a NetworkManager authentication agent,
|
||||
/// > meaning another agent will need to be active to enter passwords for unsaved networks.
|
||||
Q_INVOKABLE void connect();
|
||||
/// Disconnect from the wifi network.
|
||||
Q_INVOKABLE void disconnect();
|
||||
/// Forget all connection settings for this wifi network.
|
||||
Q_INVOKABLE void forget();
|
||||
/// The networking backend may store the PSK for future use with @@Network.connect().
|
||||
/// As such, calling that function first is recommended to avoid having to show a
|
||||
/// prompt if not required.
|
||||
///
|
||||
/// > [!NOTE] PSKs should only be provided when the @@security is one of
|
||||
/// > `WpaPsk`, `Wpa2Psk`, or `Sae`.
|
||||
Q_INVOKABLE void connectWithPsk(const QString& psk);
|
||||
|
||||
QBindable<qreal> bindableSignalStrength() { return &this->bSignalStrength; }
|
||||
QBindable<bool> bindableKnown() { return &this->bKnown; }
|
||||
QBindable<NMConnectionStateReason::Enum> bindableNmReason() { return &this->bNmReason; }
|
||||
QBindable<WifiSecurityType::Enum> bindableSecurity() { return &this->bSecurity; }
|
||||
|
||||
signals:
|
||||
void requestConnect();
|
||||
void requestDisconnect();
|
||||
void requestForget();
|
||||
QSDOC_HIDE void requestConnectWithPsk(QString psk);
|
||||
void signalStrengthChanged();
|
||||
void knownChanged();
|
||||
void securityChanged();
|
||||
void nmReasonChanged();
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(WifiNetwork, qreal, bSignalStrength, &WifiNetwork::signalStrengthChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(WifiNetwork, bool, bKnown, &WifiNetwork::knownChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(WifiNetwork, NMConnectionStateReason::Enum, bNmReason, &WifiNetwork::nmReasonChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(WifiNetwork, WifiSecurityType::Enum, bSecurity, &WifiNetwork::securityChanged);
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
///! Wireless variant of a NetworkDevice.
|
||||
///! WiFi variant of a @@NetworkDevice.
|
||||
class WifiDevice: public NetworkDevice {
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("");
|
||||
|
||||
// clang-format off
|
||||
/// A list of this available and connected wifi networks.
|
||||
/// A list of this available or connected wifi networks.
|
||||
QSDOC_TYPE_OVERRIDE(ObjectModel<WifiNetwork>*);
|
||||
Q_PROPERTY(UntypedObjectModel* networks READ networks CONSTANT);
|
||||
/// True when currently scanning for networks.
|
||||
@@ -164,9 +77,9 @@ public:
|
||||
void networkAdded(WifiNetwork* net);
|
||||
void networkRemoved(WifiNetwork* net);
|
||||
|
||||
[[nodiscard]] ObjectModel<WifiNetwork>* networks() { return &this->mNetworks; };
|
||||
QBindable<bool> bindableScannerEnabled() { return &this->bScannerEnabled; };
|
||||
[[nodiscard]] bool scannerEnabled() const { return this->bScannerEnabled; };
|
||||
[[nodiscard]] ObjectModel<WifiNetwork>* networks() { return &this->mNetworks; }
|
||||
QBindable<bool> bindableScannerEnabled() { return &this->bScannerEnabled; }
|
||||
[[nodiscard]] bool scannerEnabled() const { return this->bScannerEnabled; }
|
||||
void setScannerEnabled(bool enabled);
|
||||
QBindable<WifiDeviceMode::Enum> bindableMode() { return &this->bMode; }
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/wait.h>
|
||||
#ifdef __FreeBSD__
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "ipc.hpp"
|
||||
|
||||
@@ -214,13 +214,24 @@ void PwDefaultTracker::setDefaultSink(PwNode* node) {
|
||||
qCInfo(logDefaults) << "Default sink changed to" << node;
|
||||
|
||||
if (this->mDefaultSink != nullptr) {
|
||||
QObject::disconnect(this->mDefaultSink, nullptr, this, nullptr);
|
||||
// Targeted disconnect is used because this can also be the default configured sink.
|
||||
QObject::disconnect(
|
||||
this->mDefaultSink,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultSinkDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
this->mDefaultSink = node;
|
||||
|
||||
if (node != nullptr) {
|
||||
QObject::connect(node, &QObject::destroyed, this, &PwDefaultTracker::onDefaultSinkDestroyed);
|
||||
QObject::connect(
|
||||
node,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultSinkDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
emit this->defaultSinkChanged();
|
||||
@@ -244,13 +255,24 @@ void PwDefaultTracker::setDefaultSource(PwNode* node) {
|
||||
qCInfo(logDefaults) << "Default source changed to" << node;
|
||||
|
||||
if (this->mDefaultSource != nullptr) {
|
||||
QObject::disconnect(this->mDefaultSource, nullptr, this, nullptr);
|
||||
// Targeted disconnect is used because this can also be the default configured source.
|
||||
QObject::disconnect(
|
||||
this->mDefaultSource,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultSourceDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
this->mDefaultSource = node;
|
||||
|
||||
if (node != nullptr) {
|
||||
QObject::connect(node, &QObject::destroyed, this, &PwDefaultTracker::onDefaultSourceDestroyed);
|
||||
QObject::connect(
|
||||
node,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultSourceDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
emit this->defaultSourceChanged();
|
||||
@@ -274,7 +296,13 @@ void PwDefaultTracker::setDefaultConfiguredSink(PwNode* node) {
|
||||
qCInfo(logDefaults) << "Default configured sink changed to" << node;
|
||||
|
||||
if (this->mDefaultConfiguredSink != nullptr) {
|
||||
QObject::disconnect(this->mDefaultConfiguredSink, nullptr, this, nullptr);
|
||||
// Targeted disconnect is used because this can also be the default sink.
|
||||
QObject::disconnect(
|
||||
this->mDefaultConfiguredSink,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultConfiguredSinkDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
this->mDefaultConfiguredSink = node;
|
||||
@@ -282,7 +310,7 @@ void PwDefaultTracker::setDefaultConfiguredSink(PwNode* node) {
|
||||
if (node != nullptr) {
|
||||
QObject::connect(
|
||||
node,
|
||||
&QObject::destroyed,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultConfiguredSinkDestroyed
|
||||
);
|
||||
@@ -309,7 +337,13 @@ void PwDefaultTracker::setDefaultConfiguredSource(PwNode* node) {
|
||||
qCInfo(logDefaults) << "Default configured source changed to" << node;
|
||||
|
||||
if (this->mDefaultConfiguredSource != nullptr) {
|
||||
QObject::disconnect(this->mDefaultConfiguredSource, nullptr, this, nullptr);
|
||||
// Targeted disconnect is used because this can also be the default source.
|
||||
QObject::disconnect(
|
||||
this->mDefaultConfiguredSource,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultConfiguredSourceDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
this->mDefaultConfiguredSource = node;
|
||||
@@ -317,7 +351,7 @@ void PwDefaultTracker::setDefaultConfiguredSource(PwNode* node) {
|
||||
if (node != nullptr) {
|
||||
QObject::connect(
|
||||
node,
|
||||
&QObject::destroyed,
|
||||
&PwBindableObject::destroying,
|
||||
this,
|
||||
&PwDefaultTracker::onDefaultConfiguredSourceDestroyed
|
||||
);
|
||||
|
||||
@@ -68,11 +68,13 @@ function (wl_proto target name dir)
|
||||
target_include_directories(${target} INTERFACE ${PROTO_BUILD_PATH})
|
||||
target_link_libraries(${target} wl-proto-${name}-wl Qt6::WaylandClient Qt6::WaylandClientPrivate)
|
||||
qs_pch(${target} SET wayland-protocol)
|
||||
target_compile_options(wl-proto-${name}-wl PRIVATE ${wayland_CFLAGS})
|
||||
endfunction()
|
||||
|
||||
# -----
|
||||
|
||||
qt_add_library(quickshell-wayland STATIC
|
||||
wl_proxy_safe_deref.cpp
|
||||
platformmenu.cpp
|
||||
popupanchor.cpp
|
||||
xdgshell.cpp
|
||||
@@ -80,6 +82,10 @@ qt_add_library(quickshell-wayland STATIC
|
||||
output_tracking.cpp
|
||||
)
|
||||
|
||||
# required for wl_proxy_safe_deref
|
||||
target_link_libraries(quickshell-wayland PRIVATE ${CMAKE_DL_LIBS})
|
||||
target_link_options(quickshell PRIVATE "LINKER:--export-dynamic-symbol=wl_proxy_get_listener")
|
||||
|
||||
# required to make sure the constructor is linked
|
||||
add_library(quickshell-wayland-init OBJECT init.cpp)
|
||||
|
||||
@@ -114,6 +120,9 @@ if (HYPRLAND)
|
||||
add_subdirectory(hyprland)
|
||||
endif()
|
||||
|
||||
add_subdirectory(background_effect)
|
||||
list(APPEND WAYLAND_MODULES Quickshell.Wayland._BackgroundEffect)
|
||||
|
||||
add_subdirectory(idle_inhibit)
|
||||
list(APPEND WAYLAND_MODULES Quickshell.Wayland._IdleInhibitor)
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
qt_add_library(quickshell-wayland-background-effect STATIC
|
||||
manager.cpp
|
||||
surface.cpp
|
||||
qml.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(quickshell-wayland-background-effect
|
||||
URI Quickshell.Wayland._BackgroundEffect
|
||||
VERSION 0.1
|
||||
DEPENDENCIES QtQml
|
||||
)
|
||||
|
||||
install_qml_module(quickshell-wayland-background-effect)
|
||||
|
||||
wl_proto(wlp-background-effect ext-background-effect-v1 "${WAYLAND_PROTOCOLS}/staging/ext-background-effect")
|
||||
|
||||
target_link_libraries(quickshell-wayland-background-effect PRIVATE
|
||||
Qt::Quick Qt::WaylandClient Qt::WaylandClientPrivate wayland-client
|
||||
wlp-background-effect
|
||||
)
|
||||
|
||||
qs_module_pch(quickshell-wayland-background-effect)
|
||||
|
||||
target_link_libraries(quickshell PRIVATE quickshell-wayland-background-effectplugin)
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "manager.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#include <private/qwaylandwindow_p.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qwayland-ext-background-effect-v1.h>
|
||||
#include <qwaylandclientextension.h>
|
||||
|
||||
#include "surface.hpp"
|
||||
|
||||
namespace qs::wayland::background_effect::impl {
|
||||
|
||||
BackgroundEffectManager::BackgroundEffectManager(): QWaylandClientExtensionTemplate(1) {
|
||||
this->initialize();
|
||||
}
|
||||
|
||||
BackgroundEffectSurface*
|
||||
BackgroundEffectManager::createEffectSurface(QtWaylandClient::QWaylandWindow* window) {
|
||||
return new BackgroundEffectSurface(this->get_background_effect(window->surface()));
|
||||
}
|
||||
|
||||
bool BackgroundEffectManager::blurAvailable() const {
|
||||
return this->isActive() && this->mBlurAvailable;
|
||||
}
|
||||
|
||||
void BackgroundEffectManager::ext_background_effect_manager_v1_capabilities(uint32_t flags) {
|
||||
auto available = static_cast<bool>(flags & capability_blur);
|
||||
if (available == this->mBlurAvailable) return;
|
||||
this->mBlurAvailable = available;
|
||||
emit this->blurAvailableChanged();
|
||||
}
|
||||
|
||||
BackgroundEffectManager* BackgroundEffectManager::instance() {
|
||||
static auto* instance = new BackgroundEffectManager(); // NOLINT
|
||||
return instance->isInitialized() ? instance : nullptr;
|
||||
}
|
||||
|
||||
} // namespace qs::wayland::background_effect::impl
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <private/qwaylandwindow_p.h>
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qwayland-ext-background-effect-v1.h>
|
||||
#include <qwaylandclientextension.h>
|
||||
|
||||
#include "surface.hpp"
|
||||
|
||||
namespace qs::wayland::background_effect::impl {
|
||||
|
||||
class BackgroundEffectManager
|
||||
: public QWaylandClientExtensionTemplate<BackgroundEffectManager>
|
||||
, public QtWayland::ext_background_effect_manager_v1 {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit BackgroundEffectManager();
|
||||
|
||||
BackgroundEffectSurface* createEffectSurface(QtWaylandClient::QWaylandWindow* window);
|
||||
|
||||
[[nodiscard]] bool blurAvailable() const;
|
||||
|
||||
static BackgroundEffectManager* instance();
|
||||
|
||||
signals:
|
||||
void blurAvailableChanged();
|
||||
|
||||
protected:
|
||||
void ext_background_effect_manager_v1_capabilities(uint32_t flags) override;
|
||||
|
||||
private:
|
||||
bool mBlurAvailable = false;
|
||||
};
|
||||
|
||||
} // namespace qs::wayland::background_effect::impl
|
||||
@@ -0,0 +1,246 @@
|
||||
#include "qml.hpp"
|
||||
#include <memory>
|
||||
|
||||
#include <private/qhighdpiscaling_p.h>
|
||||
#include <private/qwaylandwindow_p.h>
|
||||
#include <qcoreevent.h>
|
||||
#include <qevent.h>
|
||||
#include <qlogging.h>
|
||||
#include <qnumeric.h>
|
||||
#include <qobject.h>
|
||||
#include <qregion.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qvariant.h>
|
||||
#include <qwindow.h>
|
||||
|
||||
#include "../../core/region.hpp"
|
||||
#include "../../window/proxywindow.hpp"
|
||||
#include "../../window/windowinterface.hpp"
|
||||
#include "manager.hpp"
|
||||
#include "surface.hpp"
|
||||
|
||||
using QtWaylandClient::QWaylandWindow;
|
||||
|
||||
namespace qs::wayland::background_effect {
|
||||
|
||||
BackgroundEffect* BackgroundEffect::qmlAttachedProperties(QObject* object) {
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(object);
|
||||
|
||||
if (!proxyWindow) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(object)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
if (!proxyWindow) return nullptr;
|
||||
return new BackgroundEffect(proxyWindow);
|
||||
}
|
||||
|
||||
BackgroundEffect::BackgroundEffect(ProxyWindowBase* window): QObject(nullptr), proxyWindow(window) {
|
||||
QObject::connect(
|
||||
window,
|
||||
&ProxyWindowBase::windowConnected,
|
||||
this,
|
||||
&BackgroundEffect::onWindowConnected
|
||||
);
|
||||
|
||||
QObject::connect(window, &ProxyWindowBase::polished, this, &BackgroundEffect::onWindowPolished);
|
||||
|
||||
QObject::connect(
|
||||
window,
|
||||
&ProxyWindowBase::devicePixelRatioChanged,
|
||||
this,
|
||||
&BackgroundEffect::updateBlurRegion
|
||||
);
|
||||
|
||||
QObject::connect(window, &QObject::destroyed, this, &BackgroundEffect::onProxyWindowDestroyed);
|
||||
|
||||
if (window->backingWindow()) {
|
||||
this->onWindowConnected();
|
||||
}
|
||||
}
|
||||
|
||||
PendingRegion* BackgroundEffect::blurRegion() const { return this->mBlurRegion; }
|
||||
|
||||
void BackgroundEffect::setBlurRegion(PendingRegion* region) {
|
||||
if (region == this->mBlurRegion) return;
|
||||
|
||||
if (this->mBlurRegion) {
|
||||
QObject::disconnect(this->mBlurRegion, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mBlurRegion = region;
|
||||
|
||||
if (region) {
|
||||
QObject::connect(region, &QObject::destroyed, this, &BackgroundEffect::onBlurRegionDestroyed);
|
||||
QObject::connect(region, &PendingRegion::changed, this, &BackgroundEffect::updateBlurRegion);
|
||||
}
|
||||
|
||||
this->updateBlurRegion();
|
||||
emit this->blurRegionChanged();
|
||||
}
|
||||
|
||||
void BackgroundEffect::onBlurRegionDestroyed() {
|
||||
this->mBlurRegion = nullptr;
|
||||
this->updateBlurRegion();
|
||||
emit this->blurRegionChanged();
|
||||
}
|
||||
|
||||
void BackgroundEffect::updateBlurRegion() {
|
||||
if (!this->surface || !this->proxyWindow) return;
|
||||
|
||||
this->pendingBlurRegion = true;
|
||||
this->proxyWindow->schedulePolish();
|
||||
}
|
||||
|
||||
void BackgroundEffect::onWindowPolished() {
|
||||
if (!this->surface || !this->pendingBlurRegion) return;
|
||||
if (!this->mWaylandWindow || !this->mWaylandWindow->surface()) {
|
||||
this->pendingBlurRegion = false;
|
||||
return;
|
||||
}
|
||||
|
||||
QRegion region;
|
||||
if (this->mBlurRegion) {
|
||||
region =
|
||||
this->mBlurRegion->applyTo(QRect(0, 0, this->mWindow->width(), this->mWindow->height()));
|
||||
|
||||
auto scale = QHighDpiScaling::factor(this->mWindow);
|
||||
if (!qFuzzyCompare(scale, 1.0)) {
|
||||
region = QHighDpi::scale(region, scale);
|
||||
}
|
||||
|
||||
auto margins = this->mWaylandWindow->clientSideMargins();
|
||||
region.translate(margins.left(), margins.top());
|
||||
}
|
||||
|
||||
this->surface->setBlurRegion(region);
|
||||
this->pendingBlurRegion = false;
|
||||
}
|
||||
|
||||
bool BackgroundEffect::eventFilter(QObject* object, QEvent* event) {
|
||||
if (event->type() == QEvent::PlatformSurface) {
|
||||
auto* surfaceEvent = dynamic_cast<QPlatformSurfaceEvent*>(event);
|
||||
if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
|
||||
this->surface = nullptr;
|
||||
this->pendingBlurRegion = false;
|
||||
}
|
||||
}
|
||||
|
||||
return this->QObject::eventFilter(object, event);
|
||||
}
|
||||
|
||||
void BackgroundEffect::onWindowConnected() {
|
||||
this->mWindow = this->proxyWindow->backingWindow();
|
||||
this->mWindow->installEventFilter(this);
|
||||
|
||||
QObject::connect(
|
||||
this->mWindow,
|
||||
&QWindow::visibleChanged,
|
||||
this,
|
||||
&BackgroundEffect::onWindowVisibleChanged
|
||||
);
|
||||
|
||||
this->onWindowVisibleChanged();
|
||||
}
|
||||
|
||||
void BackgroundEffect::onWindowVisibleChanged() {
|
||||
if (this->mWindow->isVisible()) {
|
||||
if (!this->mWindow->handle()) {
|
||||
this->mWindow->create();
|
||||
}
|
||||
}
|
||||
|
||||
auto* window = dynamic_cast<QWaylandWindow*>(this->mWindow->handle());
|
||||
if (window == this->mWaylandWindow) return;
|
||||
|
||||
if (this->mWaylandWindow) {
|
||||
QObject::disconnect(this->mWaylandWindow, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mWaylandWindow = window;
|
||||
if (!window) return;
|
||||
|
||||
QObject::connect(
|
||||
this->mWaylandWindow,
|
||||
&QObject::destroyed,
|
||||
this,
|
||||
&BackgroundEffect::onWaylandWindowDestroyed
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->mWaylandWindow,
|
||||
&QWaylandWindow::surfaceCreated,
|
||||
this,
|
||||
&BackgroundEffect::onWaylandSurfaceCreated
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->mWaylandWindow,
|
||||
&QWaylandWindow::surfaceDestroyed,
|
||||
this,
|
||||
&BackgroundEffect::onWaylandSurfaceDestroyed
|
||||
);
|
||||
|
||||
if (this->mWaylandWindow->surface()) {
|
||||
this->onWaylandSurfaceCreated();
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundEffect::onWaylandWindowDestroyed() { this->mWaylandWindow = nullptr; }
|
||||
|
||||
void BackgroundEffect::onWaylandSurfaceCreated() {
|
||||
auto* manager = impl::BackgroundEffectManager::instance();
|
||||
|
||||
if (!manager) {
|
||||
qWarning() << "Cannot enable background effect as ext-background-effect-v1 is not supported "
|
||||
"by the current compositor.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Steal protocol surface from previous BackgroundEffect to avoid duplicate-attachment on reload.
|
||||
auto v = this->mWaylandWindow->property("qs_background_effect");
|
||||
if (v.canConvert<BackgroundEffect*>()) {
|
||||
auto* prev = v.value<BackgroundEffect*>();
|
||||
if (prev != this && prev->surface) {
|
||||
this->surface.swap(prev->surface);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->surface) {
|
||||
this->surface = std::unique_ptr<impl::BackgroundEffectSurface>(
|
||||
manager->createEffectSurface(this->mWaylandWindow)
|
||||
);
|
||||
}
|
||||
|
||||
this->mWaylandWindow->setProperty("qs_background_effect", QVariant::fromValue(this));
|
||||
|
||||
this->pendingBlurRegion = this->mBlurRegion != nullptr;
|
||||
if (this->pendingBlurRegion) {
|
||||
this->proxyWindow->schedulePolish();
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundEffect::onWaylandSurfaceDestroyed() {
|
||||
this->surface = nullptr;
|
||||
this->pendingBlurRegion = false;
|
||||
|
||||
if (!this->proxyWindow) {
|
||||
this->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundEffect::onProxyWindowDestroyed() {
|
||||
// Don't delete the BackgroundEffect, and therefore the impl::BackgroundEffectSurface
|
||||
// until the wl_surface is destroyed. Deleting it when the proxy window is deleted would
|
||||
// cause a frame without blur between the destruction of the ext_background_effect_surface_v1
|
||||
// and wl_surface objects.
|
||||
|
||||
this->proxyWindow = nullptr;
|
||||
|
||||
if (this->surface == nullptr) {
|
||||
this->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace qs::wayland::background_effect
|
||||
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <private/qwaylandwindow_p.h>
|
||||
#include <qcoreevent.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qwindow.h>
|
||||
|
||||
#include "../../core/region.hpp"
|
||||
#include "../../window/proxywindow.hpp"
|
||||
#include "surface.hpp"
|
||||
|
||||
namespace qs::wayland::background_effect {
|
||||
|
||||
///! Background blur effect for Wayland surfaces.
|
||||
/// Applies background blur behind a @@Quickshell.QsWindow or subclass,
|
||||
/// as an attached object, using the [ext-background-effect-v1] Wayland protocol.
|
||||
///
|
||||
/// > [!NOTE] Using a background effect requires the compositor support the
|
||||
/// > [ext-background-effect-v1] protocol.
|
||||
///
|
||||
/// [ext-background-effect-v1]: https://wayland.app/protocols/ext-background-effect-v1
|
||||
///
|
||||
/// #### Example
|
||||
/// ```qml
|
||||
/// @@Quickshell.PanelWindow {
|
||||
/// id: root
|
||||
/// color: "#80000000"
|
||||
///
|
||||
/// BackgroundEffect.blurRegion: Region { item: root.contentItem }
|
||||
/// }
|
||||
/// ```
|
||||
class BackgroundEffect: public QObject {
|
||||
Q_OBJECT;
|
||||
// clang-format off
|
||||
/// Region to blur behind the surface. Set to null to remove blur.
|
||||
Q_PROPERTY(PendingRegion* blurRegion READ blurRegion WRITE setBlurRegion NOTIFY blurRegionChanged);
|
||||
// clang-format on
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("BackgroundEffect can only be used as an attached object.");
|
||||
QML_ATTACHED(BackgroundEffect);
|
||||
|
||||
public:
|
||||
explicit BackgroundEffect(ProxyWindowBase* window);
|
||||
|
||||
[[nodiscard]] PendingRegion* blurRegion() const;
|
||||
void setBlurRegion(PendingRegion* region);
|
||||
|
||||
static BackgroundEffect* qmlAttachedProperties(QObject* object);
|
||||
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
|
||||
signals:
|
||||
void blurRegionChanged();
|
||||
|
||||
private slots:
|
||||
void onWindowConnected();
|
||||
void onWindowVisibleChanged();
|
||||
void onWaylandWindowDestroyed();
|
||||
void onWaylandSurfaceCreated();
|
||||
void onWaylandSurfaceDestroyed();
|
||||
void onProxyWindowDestroyed();
|
||||
void onBlurRegionDestroyed();
|
||||
void onWindowPolished();
|
||||
void updateBlurRegion();
|
||||
|
||||
private:
|
||||
ProxyWindowBase* proxyWindow = nullptr;
|
||||
QWindow* mWindow = nullptr;
|
||||
QtWaylandClient::QWaylandWindow* mWaylandWindow = nullptr;
|
||||
|
||||
bool pendingBlurRegion = false;
|
||||
PendingRegion* mBlurRegion = nullptr;
|
||||
std::unique_ptr<impl::BackgroundEffectSurface> surface;
|
||||
};
|
||||
|
||||
} // namespace qs::wayland::background_effect
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "surface.hpp"
|
||||
|
||||
#include <private/qwaylanddisplay_p.h>
|
||||
#include <private/qwaylandintegration_p.h>
|
||||
#include <qregion.h>
|
||||
#include <qwayland-ext-background-effect-v1.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
|
||||
namespace qs::wayland::background_effect::impl {
|
||||
|
||||
BackgroundEffectSurface::BackgroundEffectSurface(
|
||||
::ext_background_effect_surface_v1* surface // NOLINT(misc-include-cleaner)
|
||||
)
|
||||
: QtWayland::ext_background_effect_surface_v1(surface) {}
|
||||
|
||||
BackgroundEffectSurface::~BackgroundEffectSurface() {
|
||||
if (!this->isInitialized()) return;
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
void BackgroundEffectSurface::setBlurRegion(const QRegion& region) {
|
||||
if (!this->isInitialized()) return;
|
||||
|
||||
if (region.isEmpty()) {
|
||||
this->set_blur_region(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
static const auto* waylandIntegration = QtWaylandClient::QWaylandIntegration::instance();
|
||||
auto* display = waylandIntegration->display();
|
||||
|
||||
auto* wlRegion = display->createRegion(region);
|
||||
this->set_blur_region(wlRegion);
|
||||
wl_region_destroy(wlRegion); // NOLINT(misc-include-cleaner)
|
||||
}
|
||||
|
||||
} // namespace qs::wayland::background_effect::impl
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <qregion.h>
|
||||
#include <qtclasshelpermacros.h>
|
||||
#include <qwayland-ext-background-effect-v1.h>
|
||||
|
||||
namespace qs::wayland::background_effect::impl {
|
||||
|
||||
class BackgroundEffectSurface: public QtWayland::ext_background_effect_surface_v1 {
|
||||
public:
|
||||
explicit BackgroundEffectSurface(::ext_background_effect_surface_v1* surface);
|
||||
~BackgroundEffectSurface() override;
|
||||
Q_DISABLE_COPY_MOVE(BackgroundEffectSurface);
|
||||
|
||||
void setBlurRegion(const QRegion& region);
|
||||
};
|
||||
|
||||
} // namespace qs::wayland::background_effect::impl
|
||||
@@ -0,0 +1,62 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
|
||||
FloatingWindow {
|
||||
id: root
|
||||
color: "transparent"
|
||||
contentItem.palette.windowText: "white"
|
||||
|
||||
ColumnLayout {
|
||||
anchors.centerIn: parent
|
||||
|
||||
CheckBox {
|
||||
id: enableBox
|
||||
checked: true
|
||||
text: "Enable Blur"
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Hide->Show"
|
||||
onClicked: {
|
||||
root.visible = false
|
||||
showTimer.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: showTimer
|
||||
interval: 200
|
||||
onTriggered: root.visible = true
|
||||
}
|
||||
|
||||
Slider {
|
||||
id: radiusSlider
|
||||
from: 0
|
||||
to: 1000
|
||||
value: 100
|
||||
}
|
||||
|
||||
component EdgeSlider: Slider {
|
||||
from: -1
|
||||
to: 1000
|
||||
value: -1
|
||||
}
|
||||
|
||||
EdgeSlider { id: topLeftSlider }
|
||||
EdgeSlider { id: topRightSlider }
|
||||
EdgeSlider { id: bottomLeftSlider }
|
||||
EdgeSlider { id: bottomRightSlider }
|
||||
}
|
||||
|
||||
BackgroundEffect.blurRegion: Region {
|
||||
item: enableBox.checked ? root.contentItem : null
|
||||
radius: radiusSlider.value == -1 ? undefined : radiusSlider.value
|
||||
topLeftRadius: topLeftSlider.value == -1 ? undefined : topLeftSlider.value
|
||||
topRightRadius: topRightSlider.value == -1 ? undefined : topRightSlider.value
|
||||
bottomLeftRadius: bottomLeftSlider.value == -1 ? undefined : bottomLeftSlider.value
|
||||
bottomRightRadius: bottomRightSlider.value == -1 ? undefined : bottomRightSlider.value
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GLES3/gl32.h>
|
||||
#include <fcntl.h>
|
||||
#include <gbm.h>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
|
||||
@@ -123,6 +123,10 @@ void WlBufferQSGDisplayNode::setRect(const QRectF& rect) {
|
||||
this->setMatrix(matrix);
|
||||
}
|
||||
|
||||
void WlBufferQSGDisplayNode::setFiltering(QSGTexture::Filtering filtering) {
|
||||
this->imageNode->setFiltering(filtering);
|
||||
}
|
||||
|
||||
void WlBufferQSGDisplayNode::syncSwapchain(const WlBufferSwapchain& swapchain) {
|
||||
auto* buffer = swapchain.frontbuffer();
|
||||
auto& texture = swapchain.presentSecondBuffer ? this->buffer2 : this->buffer1;
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
|
||||
void syncSwapchain(const WlBufferSwapchain& swapchain);
|
||||
void setRect(const QRectF& rect);
|
||||
void setFiltering(QSGTexture::Filtering filtering);
|
||||
|
||||
private:
|
||||
QQuickWindow* window;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <qwindow.h>
|
||||
|
||||
#include "../../../window/proxywindow.hpp"
|
||||
#include "../../../window/windowinterface.hpp"
|
||||
#include "grab.hpp"
|
||||
#include "manager.hpp"
|
||||
|
||||
@@ -38,8 +37,51 @@ QObjectList HyprlandFocusGrab::windows() const { return this->windowObjects; }
|
||||
|
||||
void HyprlandFocusGrab::setWindows(QObjectList windows) {
|
||||
if (windows == this->windowObjects) return;
|
||||
if (this->grab) this->grab->startTransaction();
|
||||
|
||||
for (auto* obj: this->windowObjects) {
|
||||
if (windows.contains(obj)) continue;
|
||||
QObject::disconnect(obj, nullptr, this, nullptr);
|
||||
|
||||
auto* proxy = ProxyWindowBase::forObject(obj);
|
||||
if (!proxy) continue;
|
||||
|
||||
QObject::disconnect(proxy, nullptr, this, nullptr);
|
||||
|
||||
if (this->grab && proxy->backingWindow()) {
|
||||
this->grab->removeWindow(proxy->backingWindow());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = windows.begin(); it != windows.end();) {
|
||||
auto* proxy = ProxyWindowBase::forObject(*it);
|
||||
if (!proxy) {
|
||||
it = windows.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->windowObjects.contains(*it)) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
QObject::connect(*it, &QObject::destroyed, this, &HyprlandFocusGrab::onObjectDestroyed);
|
||||
QObject::connect(
|
||||
proxy,
|
||||
&ProxyWindowBase::windowConnected,
|
||||
this,
|
||||
&HyprlandFocusGrab::onProxyConnected
|
||||
);
|
||||
|
||||
if (this->grab && proxy->backingWindow()) {
|
||||
this->grab->addWindow(proxy->backingWindow());
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
if (this->grab) this->grab->completeTransaction();
|
||||
this->windowObjects = std::move(windows);
|
||||
this->syncWindows();
|
||||
emit this->windowsChanged();
|
||||
}
|
||||
|
||||
@@ -75,59 +117,18 @@ void HyprlandFocusGrab::tryActivate() {
|
||||
QObject::connect(this->grab, &FocusGrab::cleared, this, &HyprlandFocusGrab::onGrabCleared);
|
||||
|
||||
this->grab->startTransaction();
|
||||
for (auto* proxy: this->trackedProxies) {
|
||||
if (proxy->backingWindow() != nullptr) {
|
||||
for (auto* obj: this->windowObjects) {
|
||||
auto* proxy = ProxyWindowBase::forObject(obj);
|
||||
if (proxy && proxy->backingWindow()) {
|
||||
this->grab->addWindow(proxy->backingWindow());
|
||||
}
|
||||
}
|
||||
this->grab->completeTransaction();
|
||||
}
|
||||
|
||||
void HyprlandFocusGrab::syncWindows() {
|
||||
auto newProxy = QList<ProxyWindowBase*>();
|
||||
for (auto* windowObject: this->windowObjects) {
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(windowObject);
|
||||
|
||||
if (proxyWindow == nullptr) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(windowObject)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
if (proxyWindow != nullptr) {
|
||||
newProxy.push_back(proxyWindow);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->grab) this->grab->startTransaction();
|
||||
|
||||
for (auto* oldWindow: this->trackedProxies) {
|
||||
if (!newProxy.contains(oldWindow)) {
|
||||
QObject::disconnect(oldWindow, nullptr, this, nullptr);
|
||||
|
||||
if (this->grab != nullptr && oldWindow->backingWindow() != nullptr) {
|
||||
this->grab->removeWindow(oldWindow->backingWindow());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* newProxy: newProxy) {
|
||||
if (!this->trackedProxies.contains(newProxy)) {
|
||||
QObject::connect(
|
||||
newProxy,
|
||||
&ProxyWindowBase::windowConnected,
|
||||
this,
|
||||
&HyprlandFocusGrab::onProxyConnected
|
||||
);
|
||||
|
||||
if (this->grab != nullptr && newProxy->backingWindow() != nullptr) {
|
||||
this->grab->addWindow(newProxy->backingWindow());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->trackedProxies = newProxy;
|
||||
if (this->grab) this->grab->completeTransaction();
|
||||
void HyprlandFocusGrab::onObjectDestroyed(QObject* object) {
|
||||
this->windowObjects.removeOne(object);
|
||||
emit this->windowsChanged();
|
||||
}
|
||||
|
||||
} // namespace qs::hyprland
|
||||
@@ -96,15 +96,13 @@ private slots:
|
||||
void onGrabActivated();
|
||||
void onGrabCleared();
|
||||
void onProxyConnected();
|
||||
void onObjectDestroyed(QObject* object);
|
||||
|
||||
private:
|
||||
void tryActivate();
|
||||
void syncWindows();
|
||||
|
||||
bool targetActive = false;
|
||||
QObjectList windowObjects;
|
||||
QList<ProxyWindowBase*> trackedProxies;
|
||||
QList<QWindow*> trackedWindows;
|
||||
|
||||
focus_grab::FocusGrab* grab = nullptr;
|
||||
};
|
||||
|
||||
@@ -729,7 +729,7 @@ void HyprlandIpc::refreshToplevels() {
|
||||
}
|
||||
|
||||
auto* workspace = toplevel->bindableWorkspace().value();
|
||||
workspace->insertToplevel(toplevel);
|
||||
if (workspace) workspace->insertToplevel(toplevel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,20 +72,16 @@ void HyprlandToplevel::updateFromObject(const QVariantMap& object) {
|
||||
Qt::beginPropertyUpdateGroup();
|
||||
bool ok = false;
|
||||
auto address = addressStr.toULongLong(&ok, 16);
|
||||
if (!ok || !address) {
|
||||
return;
|
||||
}
|
||||
if (ok && address) this->setAddress(address);
|
||||
|
||||
this->setAddress(address);
|
||||
this->bTitle = title;
|
||||
|
||||
auto workspaceMap = object.value("workspace").toMap();
|
||||
auto workspaceName = workspaceMap.value("name").toString();
|
||||
|
||||
auto* workspace = this->ipc->findWorkspaceByName(workspaceName, false);
|
||||
if (!workspace) return;
|
||||
auto* workspace = this->ipc->findWorkspaceByName(workspaceName, true);
|
||||
if (workspace) this->setWorkspace(workspace);
|
||||
|
||||
this->setWorkspace(workspace);
|
||||
this->bLastIpcObject = object;
|
||||
Qt::endPropertyUpdateGroup();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "../../../core/region.hpp"
|
||||
#include "../../../window/proxywindow.hpp"
|
||||
#include "../../../window/windowinterface.hpp"
|
||||
#include "manager.hpp"
|
||||
#include "surface.hpp"
|
||||
|
||||
@@ -23,13 +22,7 @@ using QtWaylandClient::QWaylandWindow;
|
||||
namespace qs::hyprland::surface {
|
||||
|
||||
HyprlandWindow* HyprlandWindow::qmlAttachedProperties(QObject* object) {
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(object);
|
||||
|
||||
if (!proxyWindow) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(object)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
auto* proxyWindow = ProxyWindowBase::forObject(object);
|
||||
|
||||
if (!proxyWindow) return nullptr;
|
||||
return new HyprlandWindow(proxyWindow);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "../../window/proxywindow.hpp"
|
||||
#include "../../window/windowinterface.hpp"
|
||||
#include "proto.hpp"
|
||||
|
||||
namespace qs::wayland::idle_inhibit {
|
||||
@@ -25,27 +24,13 @@ QObject* IdleInhibitor::window() const { return this->bWindowObject; }
|
||||
void IdleInhibitor::setWindow(QObject* window) {
|
||||
if (window == this->bWindowObject) return;
|
||||
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(window);
|
||||
|
||||
if (proxyWindow == nullptr) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(window)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
auto* proxyWindow = ProxyWindowBase::forObject(window);
|
||||
this->bWindowObject = proxyWindow ? window : nullptr;
|
||||
}
|
||||
|
||||
void IdleInhibitor::boundWindowChanged() {
|
||||
auto* window = this->bBoundWindow.value();
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(window);
|
||||
|
||||
if (proxyWindow == nullptr) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(window)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
auto* proxyWindow = ProxyWindowBase::forObject(window);
|
||||
if (proxyWindow == this->proxyWindow) return;
|
||||
|
||||
if (this->mWaylandWindow) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "wlr_layershell/wlr_layershell.hpp"
|
||||
#endif
|
||||
|
||||
void installWlProxySafeDeref(); // NOLINT(misc-use-internal-linkage)
|
||||
void installPlatformMenuHook(); // NOLINT(misc-use-internal-linkage)
|
||||
void installPopupPositioner(); // NOLINT(misc-use-internal-linkage)
|
||||
|
||||
@@ -32,6 +33,8 @@ class WaylandPlugin: public QsEnginePlugin {
|
||||
return isWayland;
|
||||
}
|
||||
|
||||
void preinit() override { installWlProxySafeDeref(); }
|
||||
|
||||
void init() override {
|
||||
installPlatformMenuHook();
|
||||
installPopupPositioner();
|
||||
|
||||
@@ -8,5 +8,6 @@ headers = [
|
||||
"idle_inhibit/inhibitor.hpp",
|
||||
"idle_notify/monitor.hpp",
|
||||
"shortcuts_inhibit/inhibitor.hpp",
|
||||
"background_effect/qml.hpp",
|
||||
]
|
||||
-----
|
||||
@@ -167,6 +167,7 @@ QSGNode* ScreencopyView::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*
|
||||
auto& swapchain = this->context->swapchain();
|
||||
node->syncSwapchain(swapchain);
|
||||
node->setRect(this->boundingRect());
|
||||
node->setFiltering(QSGTexture::Linear); // NOLINT (misc-include-cleaner)
|
||||
|
||||
if (this->mLive) this->context->captureFrame();
|
||||
return node;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <qwindow.h>
|
||||
|
||||
#include "../../window/proxywindow.hpp"
|
||||
#include "../../window/windowinterface.hpp"
|
||||
#include "proto.hpp"
|
||||
|
||||
namespace qs::wayland::shortcuts_inhibit {
|
||||
@@ -48,14 +47,7 @@ ShortcutInhibitor::~ShortcutInhibitor() {
|
||||
|
||||
void ShortcutInhibitor::onBoundWindowChanged() {
|
||||
auto* window = this->bBoundWindow.value();
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(window);
|
||||
|
||||
if (!proxyWindow) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(window)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
|
||||
auto* proxyWindow = ProxyWindowBase::forObject(window);
|
||||
if (proxyWindow == this->proxyWindow) return;
|
||||
|
||||
if (this->proxyWindow) {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "../../core/qmlscreen.hpp"
|
||||
#include "../../core/util.hpp"
|
||||
#include "../../window/proxywindow.hpp"
|
||||
#include "../../window/windowinterface.hpp"
|
||||
#include "../output_tracking.hpp"
|
||||
#include "handle.hpp"
|
||||
#include "manager.hpp"
|
||||
@@ -73,13 +72,7 @@ void Toplevel::fullscreenOn(QuickshellScreenInfo* screen) {
|
||||
}
|
||||
|
||||
void Toplevel::setRectangle(QObject* window, QRect rect) {
|
||||
auto* proxyWindow = qobject_cast<ProxyWindowBase*>(window);
|
||||
|
||||
if (proxyWindow == nullptr) {
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(window)) {
|
||||
proxyWindow = iface->proxyWindow();
|
||||
}
|
||||
}
|
||||
auto* proxyWindow = ProxyWindowBase::forObject(window);
|
||||
|
||||
if (proxyWindow != this->rectWindow) {
|
||||
if (this->rectWindow != nullptr) {
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include <qobjectdefs.h>
|
||||
#include <qproperty.h>
|
||||
|
||||
#include "../../windowmanager/screenprojection.hpp"
|
||||
#include "../../windowmanager/windowmanager.hpp"
|
||||
#include "../../windowmanager/windowset.hpp"
|
||||
#include "../../windowmanager/screenprojection.hpp"
|
||||
#include "ext_workspace.hpp"
|
||||
|
||||
namespace qs::wm::wayland {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <dlfcn.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <wayland-client-core.h>
|
||||
#include <wayland-util.h>
|
||||
|
||||
#include "../core/logcat.hpp"
|
||||
|
||||
namespace {
|
||||
QS_LOGGING_CATEGORY(logDeref, "quickshell.wayland.safederef", QtWarningMsg);
|
||||
using wl_proxy_get_listener_t = const void* (*) (wl_proxy*);
|
||||
wl_proxy_get_listener_t original_wl_proxy_get_listener = nullptr; // NOLINT
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
WL_EXPORT const void* wl_proxy_get_listener(struct wl_proxy* proxy) {
|
||||
// Avoid null derefs of protocol objects in qtbase.
|
||||
// https://qt-project.atlassian.net/browse/QTBUG-145022
|
||||
if (!proxy) [[unlikely]] {
|
||||
qCCritical(logDeref) << "wl_proxy_get_listener called with a null proxy!";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return original_wl_proxy_get_listener(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTBEGIN (concurrency-mt-unsafe)
|
||||
void installWlProxySafeDeref() {
|
||||
dlerror(); // clear old errors
|
||||
|
||||
original_wl_proxy_get_listener =
|
||||
reinterpret_cast<wl_proxy_get_listener_t>(dlsym(RTLD_NEXT, "wl_proxy_get_listener"));
|
||||
|
||||
if (auto* error = dlerror()) {
|
||||
qCCritical(logDeref) << "Failed to find wl_proxy_get_listener for hooking:" << error;
|
||||
} else {
|
||||
qCInfo(logDeref) << "Installed wl_proxy_get_listener hook.";
|
||||
}
|
||||
}
|
||||
// NOLINTEND
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <qvariant.h>
|
||||
#include <qwayland-wlr-layer-shell-unstable-v1.h>
|
||||
#include <qwindow.h>
|
||||
#include <wayland-xdg-shell-client-protocol.h>
|
||||
|
||||
#include "../../window/panelinterface.hpp"
|
||||
#include "shell_integration.hpp"
|
||||
@@ -247,9 +248,19 @@ void LayerSurface::commit() {
|
||||
}
|
||||
|
||||
void LayerSurface::attachPopup(QtWaylandClient::QWaylandShellSurface* popup) {
|
||||
std::any role = popup->surfaceRole();
|
||||
|
||||
if (auto* popupRole = std::any_cast<::xdg_popup*>(&role)) { // NOLINT
|
||||
#ifdef __FreeBSD__
|
||||
// FreeBSD uses an alternate RTTI matching strategy by default which does
|
||||
// not work across modules, preventing std::any from downcasting. On
|
||||
// FreeBSD, Qt is built with a patch to expose the surface role through a
|
||||
// pointer instead of an any, which does not have this problem.
|
||||
// See https://bugs.kde.org/show_bug.cgi?id=479679
|
||||
if (auto* xdgPopup = static_cast<::xdg_popup*>(popup->nativeResource("xdg_popup"))) {
|
||||
this->get_popup(xdgPopup);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
auto role = popup->surfaceRole(); // NOLINT
|
||||
if (auto* popupRole = std::any_cast<::xdg_popup*>(&role)) {
|
||||
this->get_popup(*popupRole);
|
||||
} else {
|
||||
qWarning() << "Cannot attach popup" << popup << "to shell surface" << this
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qqmlinfo.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qwindow.h>
|
||||
@@ -11,6 +11,27 @@
|
||||
#include "proxywindow.hpp"
|
||||
#include "windowinterface.hpp"
|
||||
|
||||
ProxyFloatingWindow::ProxyFloatingWindow(QObject* parent): ProxyWindowBase(parent) {
|
||||
this->bTargetVisible.setBinding([this] {
|
||||
if (!this->bWantsVisible) return false;
|
||||
auto* parent = this->bParentProxyWindow.value();
|
||||
if (!parent) return true;
|
||||
return parent->bindableBackerVisibility().value();
|
||||
});
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::targetVisibleChanged() {
|
||||
if (this->window && this->bParentProxyWindow) {
|
||||
auto* bw = this->bParentProxyWindow.value()->backingWindow();
|
||||
|
||||
if (bw != this->window->transientParent()) {
|
||||
this->window->setTransientParent(bw);
|
||||
}
|
||||
}
|
||||
|
||||
this->ProxyWindowBase::setVisible(this->bTargetVisible);
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::connectWindow() {
|
||||
this->ProxyWindowBase::connectWindow();
|
||||
|
||||
@@ -19,6 +40,25 @@ void ProxyFloatingWindow::connectWindow() {
|
||||
this->window->setMaximumSize(this->bMaximumSize);
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::completeWindow() {
|
||||
this->ProxyWindowBase::completeWindow();
|
||||
|
||||
auto* parent = this->bParentProxyWindow.value();
|
||||
this->window->setTransientParent(parent ? parent->backingWindow() : nullptr);
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::postCompleteWindow() {
|
||||
this->ProxyWindowBase::setVisible(this->bTargetVisible);
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::onParentDestroyed() {
|
||||
this->mParentWindow = nullptr;
|
||||
this->bParentProxyWindow = nullptr;
|
||||
emit this->parentWindowChanged();
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::setVisible(bool visible) { this->bWantsVisible = visible; }
|
||||
|
||||
void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) {
|
||||
if (!this->window->isVisible()) {
|
||||
this->ProxyWindowBase::trySetWidth(implicitWidth);
|
||||
@@ -46,6 +86,42 @@ void ProxyFloatingWindow::onMaximumSizeChanged() {
|
||||
emit this->maximumSizeChanged();
|
||||
}
|
||||
|
||||
QObject* ProxyFloatingWindow::parentWindow() const { return this->mParentWindow; }
|
||||
|
||||
void ProxyFloatingWindow::setParentWindow(QObject* window) {
|
||||
if (window == this->mParentWindow) return;
|
||||
|
||||
if (this->window && this->window->isVisible()) {
|
||||
qmlWarning(this) << "parentWindow cannot be changed after the window is visible.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->bParentProxyWindow) {
|
||||
QObject::disconnect(this->bParentProxyWindow, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
if (this->mParentWindow) {
|
||||
QObject::disconnect(this->mParentWindow, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mParentWindow = nullptr;
|
||||
this->bParentProxyWindow = nullptr;
|
||||
|
||||
if (auto* proxy = ProxyWindowBase::forObject(window)) {
|
||||
this->mParentWindow = window;
|
||||
this->bParentProxyWindow = proxy;
|
||||
|
||||
QObject::connect(
|
||||
this->mParentWindow,
|
||||
&QObject::destroyed,
|
||||
this,
|
||||
&ProxyFloatingWindow::onParentDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
emit this->parentWindowChanged();
|
||||
}
|
||||
|
||||
// FloatingWindowInterface
|
||||
|
||||
FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
|
||||
@@ -57,6 +133,7 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
|
||||
QObject::connect(this->window, &ProxyFloatingWindow::titleChanged, this, &FloatingWindowInterface::titleChanged);
|
||||
QObject::connect(this->window, &ProxyFloatingWindow::minimumSizeChanged, this, &FloatingWindowInterface::minimumSizeChanged);
|
||||
QObject::connect(this->window, &ProxyFloatingWindow::maximumSizeChanged, this, &FloatingWindowInterface::maximumSizeChanged);
|
||||
QObject::connect(this->window, &ProxyFloatingWindow::parentWindowChanged, this, &FloatingWindowInterface::parentWindowChanged);
|
||||
QObject::connect(this->window, &ProxyWindowBase::windowConnected, this, &FloatingWindowInterface::onWindowConnected);
|
||||
// clang-format on
|
||||
}
|
||||
@@ -169,3 +246,9 @@ bool FloatingWindowInterface::startSystemResize(Qt::Edges edges) const {
|
||||
if (!qw) return false;
|
||||
return qw->startSystemResize(edges);
|
||||
}
|
||||
|
||||
QObject* FloatingWindowInterface::parentWindow() const { return this->window->parentWindow(); }
|
||||
|
||||
void FloatingWindowInterface::setParentWindow(QObject* window) {
|
||||
this->window->setParentWindow(window);
|
||||
}
|
||||
@@ -16,9 +16,15 @@ class ProxyFloatingWindow: public ProxyWindowBase {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit ProxyFloatingWindow(QObject* parent = nullptr): ProxyWindowBase(parent) {}
|
||||
explicit ProxyFloatingWindow(QObject* parent = nullptr);
|
||||
|
||||
void connectWindow() override;
|
||||
void completeWindow() override;
|
||||
void postCompleteWindow() override;
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
[[nodiscard]] QObject* parentWindow() const;
|
||||
void setParentWindow(QObject* window);
|
||||
|
||||
// Setting geometry while the window is visible makes the content item shrink but not the window
|
||||
// which is awful so we disable it for floating windows.
|
||||
@@ -29,11 +35,28 @@ signals:
|
||||
void minimumSizeChanged();
|
||||
void maximumSizeChanged();
|
||||
void titleChanged();
|
||||
void parentWindowChanged();
|
||||
|
||||
private slots:
|
||||
void onParentDestroyed();
|
||||
|
||||
private:
|
||||
void onMinimumSizeChanged();
|
||||
void onMaximumSizeChanged();
|
||||
void onTitleChanged();
|
||||
void targetVisibleChanged();
|
||||
|
||||
QObject* mParentWindow = nullptr;
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(ProxyFloatingWindow, ProxyWindowBase*, bParentProxyWindow);
|
||||
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(ProxyFloatingWindow, bool, bWantsVisible, true);
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(
|
||||
ProxyFloatingWindow,
|
||||
bool,
|
||||
bTargetVisible,
|
||||
&ProxyFloatingWindow::targetVisibleChanged
|
||||
);
|
||||
|
||||
public:
|
||||
Q_OBJECT_BINDABLE_PROPERTY(
|
||||
@@ -75,6 +98,11 @@ class FloatingWindowInterface: public WindowInterface {
|
||||
Q_PROPERTY(bool maximized READ isMaximized WRITE setMaximized NOTIFY maximizedChanged);
|
||||
/// Whether the window is currently fullscreen.
|
||||
Q_PROPERTY(bool fullscreen READ isFullscreen WRITE setFullscreen NOTIFY fullscreenChanged);
|
||||
/// The parent window of this window. Setting this makes the window a child of the parent,
|
||||
/// which affects window stacking behavior.
|
||||
///
|
||||
/// > [!NOTE] This property cannot be changed after the window is visible.
|
||||
Q_PROPERTY(QObject* parentWindow READ parentWindow WRITE setParentWindow NOTIFY parentWindowChanged);
|
||||
// clang-format on
|
||||
QML_NAMED_ELEMENT(FloatingWindow);
|
||||
|
||||
@@ -101,6 +129,9 @@ public:
|
||||
/// Start a system resize operation. Must be called during a pointer press/drag.
|
||||
Q_INVOKABLE [[nodiscard]] bool startSystemResize(Qt::Edges edges) const;
|
||||
|
||||
[[nodiscard]] QObject* parentWindow() const;
|
||||
void setParentWindow(QObject* window);
|
||||
|
||||
signals:
|
||||
void minimumSizeChanged();
|
||||
void maximumSizeChanged();
|
||||
@@ -108,6 +139,7 @@ signals:
|
||||
void minimizedChanged();
|
||||
void maximizedChanged();
|
||||
void fullscreenChanged();
|
||||
void parentWindowChanged();
|
||||
|
||||
private slots:
|
||||
void onWindowConnected();
|
||||
|
||||
@@ -57,6 +57,12 @@ ProxyWindowBase::ProxyWindowBase(QObject* parent)
|
||||
|
||||
ProxyWindowBase::~ProxyWindowBase() { this->deleteWindow(true); }
|
||||
|
||||
ProxyWindowBase* ProxyWindowBase::forObject(QObject* obj) {
|
||||
if (auto* proxy = qobject_cast<ProxyWindowBase*>(obj)) return proxy;
|
||||
if (auto* iface = qobject_cast<WindowInterface*>(obj)) return iface->proxyWindow();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ProxyWindowBase::onReload(QObject* oldInstance) {
|
||||
if (this->mVisible) this->window = this->retrieveWindow(oldInstance);
|
||||
auto wasVisible = this->window != nullptr && this->window->isVisible();
|
||||
|
||||
@@ -66,6 +66,8 @@ public:
|
||||
explicit ProxyWindowBase(QObject* parent = nullptr);
|
||||
~ProxyWindowBase() override;
|
||||
|
||||
static ProxyWindowBase* forObject(QObject* obj);
|
||||
|
||||
ProxyWindowBase(ProxyWindowBase&) = delete;
|
||||
ProxyWindowBase(ProxyWindowBase&&) = delete;
|
||||
void operator=(ProxyWindowBase&) = delete;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls.Fusion
|
||||
import Quickshell
|
||||
|
||||
Scope {
|
||||
FloatingWindow {
|
||||
id: control
|
||||
color: contentItem.palette.window
|
||||
ColumnLayout {
|
||||
CheckBox {
|
||||
id: parentCb
|
||||
text: "Show parent"
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: dialogCb
|
||||
text: "Show dialog"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FloatingWindow {
|
||||
id: parentw
|
||||
Text {
|
||||
text: "parent"
|
||||
}
|
||||
visible: parentCb.checked
|
||||
color: contentItem.palette.window
|
||||
|
||||
FloatingWindow {
|
||||
id: dialog
|
||||
parentWindow: parentw
|
||||
visible: dialogCb.checked
|
||||
color: contentItem.palette.window
|
||||
|
||||
Text {
|
||||
text: "dialog"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ WindowManager* WindowManager::instance() {
|
||||
}
|
||||
|
||||
ScreenProjection* WindowManager::screenProjection(QuickshellScreenInfo* screen) {
|
||||
if (!screen) return nullptr;
|
||||
|
||||
auto* qscreen = screen->screen;
|
||||
auto it = this->mScreenProjections.find(qscreen);
|
||||
if (it != this->mScreenProjections.end()) {
|
||||
|
||||
Reference in new issue
Block a user