mirror of
https://github.com/quickshell-mirror/quickshell.git
synced 2026-10-28 02:55:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a4716cde7 | ||
|
|
069e33a93e | ||
|
|
532a0606ca | ||
|
|
78672a8405 | ||
|
|
990a8badab | ||
|
|
7e6c7ae3fb | ||
|
|
8f1316d0c2 | ||
|
|
63eb2ba6ef | ||
|
|
b1fc3e0740 | ||
|
|
21fec77de7 | ||
|
|
d9cbc90a8c | ||
|
|
28771c7c74 | ||
|
|
43d4fa9e88 | ||
|
|
10b439fc6e | ||
|
|
e649d24749 | ||
|
|
025c709e94 | ||
|
|
4df562dfb2 | ||
|
|
98b6d0b7e7 | ||
|
|
25eb04fb06 | ||
|
|
ead3b00afd | ||
|
|
a611932352 | ||
|
|
1661ef100a | ||
|
|
68c2c85c33 | ||
|
|
897fcdaa99 | ||
|
|
d99d87d5e5 | ||
|
|
b66495fcc5 | ||
|
|
eaba6c8b62 | ||
|
|
4b4fca3224 | ||
|
|
7d1c9a9c67 | ||
|
|
d1760ed1f3 | ||
|
|
b93d61385f | ||
|
|
59e9c47b0e | ||
|
|
ffe95f06ac | ||
|
|
8db8ca1fec | ||
|
|
0baa81aa03 | ||
|
|
01834e9c8f | ||
|
|
2ba2ae48b4 | ||
|
|
055e384668 | ||
|
|
11a71d233a | ||
|
|
e162429b6f | ||
|
|
783c953987 | ||
|
|
b850b8a1a9 | ||
|
|
d60498adc0 | ||
|
|
9a54119893 | ||
|
|
18075d1218 | ||
|
|
fb08eced44 | ||
|
|
d4c92973b5 | ||
|
|
7f7ab6bc8a | ||
|
|
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 | ||
|
|
6705e2da77 | ||
|
|
9e8eecf2b8 | ||
|
|
1b2519d9f3 | ||
|
|
1123d5ab4f | ||
|
|
4b77936c80 | ||
|
|
e32b909354 | ||
|
|
178c04b59c | ||
|
|
706d6de7b0 | ||
|
|
9a9c605250 | ||
|
|
bd62179277 | ||
|
|
cf1a2aeb2d | ||
|
|
15a8409765 | ||
|
|
6bcd3d9bbf | ||
|
|
c030300191 | ||
|
|
5721955686 | ||
|
|
a849a88893 | ||
|
|
cdde4c63f4 | ||
|
|
cddb4f061b | ||
|
|
6e17efab83 | ||
|
|
36517a2c10 | ||
|
|
c3c3e2ca25 | ||
|
|
2cf57f43d5 | ||
|
|
a99519c3ad | ||
|
|
158db16b93 | ||
|
|
e7cd1e9982 | ||
|
|
afbc5ffd4e | ||
|
|
dacfa9de82 | ||
|
|
4429c03837 | ||
|
|
395a1301a8 | ||
|
|
1e4d804e7f | ||
|
|
191085a882 | ||
|
|
8fd0de4580 | ||
|
|
7a427ce197 | ||
|
|
5eb6f51f4a | ||
|
|
d03c59768c | ||
|
|
783b97152a | ||
|
|
dca652366a | ||
|
|
de1bfe028d | ||
|
|
db37dc580a | ||
|
|
bcc3d4265e | ||
|
|
eecc2f88b3 | ||
|
|
11d6d67961 | ||
|
|
5d8354a88b | ||
|
|
8d19beb69e | ||
|
|
6742148cf4 | ||
|
|
341a07d05b | ||
|
|
41828c4180 | ||
|
|
3918290c1b | ||
|
|
26531fc46e | ||
|
|
667bd38489 | ||
|
|
9cdda21974 | ||
|
|
d24e8e9736 | ||
|
|
e9bad67619 | ||
|
|
ed036d514b | ||
|
|
1ddb355121 | ||
|
|
ab494dd982 | ||
|
|
fdbb86a06a | ||
|
|
0a7dcf30ea | ||
|
|
1552aca3df | ||
|
|
0a36e3ed40 | ||
|
|
a00ff03944 | ||
|
|
fc704e6b5d | ||
|
|
db1777c20b | ||
|
|
1b147a2c78 | ||
|
|
3e2ce40b18 | ||
|
|
00858812f2 | ||
|
|
1e8cc2e78d | ||
|
|
ea79eaceb0 | ||
|
|
c9d3ffb604 | ||
|
|
f12f0e7c7d | ||
|
|
3e32ae595f | ||
|
|
2eacb713b9 | ||
|
|
c5c438f1cd | ||
|
|
9bb2c043ae | ||
|
|
3bcc1993f4 | ||
|
|
9662234759 | ||
|
|
475856b767 | ||
|
|
482744cfa9 | ||
|
|
6092b37c56 | ||
|
|
1d94144976 | ||
|
|
f78078dfaf | ||
|
|
eeb8181cb1 | ||
|
|
a922694a7d | ||
|
|
afada1eb6c | ||
|
|
b9905ef824 | ||
|
|
2119eb2205 | ||
|
|
e9a574d919 | ||
|
|
59f5744f30 | ||
|
|
49646e4407 | ||
|
|
6eb12551ba | ||
|
|
b8fa424f85 | ||
|
|
2c2983462c | ||
|
|
f592793873 | ||
|
|
f7597cdae2 | ||
|
|
42420ea26d | ||
|
|
b8625aa098 |
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
AlignArrayOfStructures: None
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
|
||||
@@ -20,6 +20,8 @@ Checks: >
|
||||
-cppcoreguidelines-avoid-do-while,
|
||||
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||
-cppcoreguidelines-pro-type-vararg,
|
||||
-cppcoreguidelines-pro-type-union-access,
|
||||
-cppcoreguidelines-use-enum-class,
|
||||
google-global-names-in-headers,
|
||||
google-readability-casting,
|
||||
google-runtime-int,
|
||||
@@ -63,6 +65,8 @@ CheckOptions:
|
||||
readability-identifier-naming.ParameterCase: camelBack
|
||||
readability-identifier-naming.VariableCase: camelBack
|
||||
|
||||
misc-const-correctness.WarnPointersAsPointers: false
|
||||
|
||||
# does not appear to work
|
||||
readability-operators-representation.BinaryOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='
|
||||
readability-operators-representation.OverloadedOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='
|
||||
@@ -1,82 +1,17 @@
|
||||
name: Crash Report
|
||||
description: Quickshell has crashed
|
||||
labels: ["bug", "crash"]
|
||||
name: Crash Report (v1)
|
||||
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
|
||||
@@ -0,0 +1,43 @@
|
||||
name: Crash Report (v2)
|
||||
description: Quickshell has crashed
|
||||
labels: ["bug", "crash"]
|
||||
body:
|
||||
- type: textarea
|
||||
id: userinfo
|
||||
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: upload
|
||||
id: report
|
||||
attributes:
|
||||
label: Report file
|
||||
description: |
|
||||
Attach `report.txt` here.
|
||||
|
||||
Please ensure the report does not contain personal information,
|
||||
as reports may contain detailed logs leading up to the crash.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: config
|
||||
attributes:
|
||||
label: Configuration
|
||||
description: |
|
||||
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.
|
||||
- type: textarea
|
||||
id: bt
|
||||
attributes:
|
||||
label: Backtrace
|
||||
description: |
|
||||
GDB usually produces better stacktraces than quickshell can. Consider attaching a gdb backtrace
|
||||
following the instructions below.
|
||||
|
||||
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.
|
||||
@@ -6,17 +6,23 @@ jobs:
|
||||
name: Nix
|
||||
strategy:
|
||||
matrix:
|
||||
qtver: [qt6.9.0, qt6.8.3, qt6.8.2, qt6.8.1, qt6.8.0, qt6.7.3, qt6.7.2, qt6.7.1, qt6.7.0, qt6.6.3, qt6.6.2, qt6.6.1, qt6.6.0]
|
||||
qtver: [qt6.10.1, qt6.10.0, qt6.9.2, qt6.9.1, qt6.9.0, qt6.8.3, qt6.8.2, qt6.8.1, qt6.8.0, qt6.7.3, qt6.7.2, qt6.7.1, qt6.7.0, qt6.6.3, qt6.6.2, qt6.6.1, qt6.6.0]
|
||||
compiler: [clang, gcc]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
# Use cachix action over detsys for testing with act.
|
||||
# - uses: cachix/install-nix-action@v27
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
with:
|
||||
use-flakehub: false
|
||||
|
||||
- name: Download Dependencies
|
||||
run: nix-build --no-out-link --expr '((import ./ci/matrix.nix) { qtver = "${{ matrix.qtver }}"; compiler = "${{ matrix.compiler }}"; }).inputDerivation'
|
||||
run: nix-build --no-out-link --expr '((import ./ci/matrix.nix) { qtver = "${{ matrix.qtver }}"; compiler = "${{ matrix.compiler }}"; }).unwrapped.inputDerivation'
|
||||
|
||||
- name: Build
|
||||
run: nix-build --no-out-link --expr '(import ./ci/matrix.nix) { qtver = "${{ matrix.qtver }}"; compiler = "${{ matrix.compiler }}"; }'
|
||||
@@ -44,13 +50,16 @@ jobs:
|
||||
wayland-protocols \
|
||||
wayland \
|
||||
libdrm \
|
||||
vulkan-headers \
|
||||
libxcb \
|
||||
libpipewire \
|
||||
cli11 \
|
||||
jemalloc
|
||||
polkit \
|
||||
jemalloc \
|
||||
libunwind \
|
||||
git # for cpptrace clone
|
||||
|
||||
- name: Build
|
||||
# breakpad is annoying to build in ci due to makepkg not running as root
|
||||
run: |
|
||||
cmake -GNinja -B build -DCRASH_REPORTER=OFF
|
||||
cmake -GNinja -B build -DVENDOR_CPPTRACE=ON
|
||||
cmake --build build
|
||||
@@ -5,11 +5,17 @@ jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
# Use cachix action over detsys for testing with act.
|
||||
# - uses: cachix/install-nix-action@v27
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
with:
|
||||
use-flakehub: false
|
||||
- uses: nicknovitski/nix-develop@v1
|
||||
|
||||
- name: Check formatting
|
||||
|
||||
@@ -15,15 +15,7 @@ Please make this descriptive enough to identify your specific package, for examp
|
||||
- `Nixpkgs`
|
||||
- `Fedora COPR (errornointernet/quickshell)`
|
||||
|
||||
`-DDISTRIBUTOR_DEBUGINFO_AVAILABLE=YES/NO`
|
||||
|
||||
If we can retrieve binaries and debug information for the package without actually running your
|
||||
distribution (e.g. from an website), and you would like to strip the binary, please set this to `YES`.
|
||||
|
||||
If we cannot retrieve debug information, please set this to `NO` and
|
||||
**ensure you aren't distributing stripped (non debuggable) binaries**.
|
||||
|
||||
In both cases you should build with `-DCMAKE_BUILD_TYPE=RelWithDebInfo` (then split or keep the debuginfo).
|
||||
If you are forking quickshell, please change `CRASHREPORT_URL` to your own issue tracker.
|
||||
|
||||
### QML Module dir
|
||||
Currently all QML modules are statically linked to quickshell, but this is where
|
||||
@@ -41,11 +33,15 @@ Quickshell has a set of base dependencies you will always need, names vary by di
|
||||
- `cmake`
|
||||
- `qt6base`
|
||||
- `qt6declarative`
|
||||
- `libdrm`
|
||||
- `qtshadertools` (build-time)
|
||||
- `spirv-tools` (build-time)
|
||||
- `pkg-config` (build-time)
|
||||
- `cli11` (static library)
|
||||
|
||||
Quickshell relies on private Qt APIs and **MUST** be rebuilt against the each Qt release
|
||||
or crashes via ABI mismatches will occur.
|
||||
|
||||
Build time dependencies and static libraries don't have to exist at runtime,
|
||||
however build time dependencies must be compiled for the architecture of
|
||||
the builder, while static libraries must be compiled for the architecture
|
||||
@@ -55,7 +51,7 @@ On some distros, private Qt headers are in separate packages which you may have
|
||||
We currently require private headers for the following libraries:
|
||||
|
||||
- `qt6declarative`
|
||||
- `qt6wayland`
|
||||
- `qt6wayland` (for Qt versions prior to 6.10)
|
||||
|
||||
We recommend an implicit dependency on `qt6svg`. If it is not installed, svg images and
|
||||
svg icons will not work, including system ones.
|
||||
@@ -64,14 +60,24 @@ At least Qt 6.6 is required.
|
||||
|
||||
All features are enabled by default and some have their own dependencies.
|
||||
|
||||
### Crash Reporter
|
||||
The crash reporter catches crashes, restarts quickshell when it crashes,
|
||||
### Crash Handler
|
||||
The crash reporter catches crashes, restarts Quickshell when it crashes,
|
||||
and collects useful crash information in one place. Leaving this enabled will
|
||||
enable us to fix bugs far more easily.
|
||||
|
||||
To disable: `-DCRASH_REPORTER=OFF`
|
||||
To disable: `-DCRASH_HANDLER=OFF`
|
||||
|
||||
Dependencies: `google-breakpad` (static library)
|
||||
Dependencies: `cpptrace`
|
||||
|
||||
Note: `-DVENDOR_CPPTRACE=ON` can be set to vendor cpptrace using FetchContent.
|
||||
|
||||
When using FetchContent, `libunwind` is required, and `libdwarf` can be provided by the
|
||||
package manager or fetched with FetchContent.
|
||||
|
||||
*Please ensure binaries have usable symbols.* We do not necessarily need full debuginfo, but
|
||||
leaving symbols in the binary is extremely helpful. You can check if symbols are useful
|
||||
by sending a SIGSEGV to the process and ensuring symbols for the quickshell binary are present
|
||||
in the trace.
|
||||
|
||||
### Jemalloc
|
||||
We recommend leaving Jemalloc enabled as it will mask memory fragmentation caused
|
||||
@@ -94,17 +100,10 @@ To disable: `-DSOCKETS=OFF`
|
||||
### Wayland
|
||||
This feature enables wayland support. Subfeatures exist for each particular wayland integration.
|
||||
|
||||
WARNING: Wayland integration relies on features that are not part of the public Qt API and which
|
||||
may break in minor releases. Updating quickshell's dependencies without ensuring without ensuring
|
||||
that the current Qt version is supported WILL result in quickshell failing to build or misbehaving
|
||||
at runtime.
|
||||
|
||||
Currently supported Qt versions: `6.6`, `6.7`.
|
||||
|
||||
To disable: `-DWAYLAND=OFF`
|
||||
|
||||
Dependencies:
|
||||
- `qt6wayland`
|
||||
- `qt6wayland` (for Qt versions prior to 6.10)
|
||||
- `wayland` (libwayland-client)
|
||||
- `wayland-scanner` (build time)
|
||||
- `wayland-protocols` (static library)
|
||||
@@ -144,8 +143,8 @@ Enables streaming video from monitors and toplevel windows through various proto
|
||||
To disable: `-DSCREENCOPY=OFF`
|
||||
|
||||
Dependencies:
|
||||
- `libdrm`
|
||||
- `libgbm`
|
||||
- `vulkan-headers` (build-time)
|
||||
|
||||
Specific protocols can also be disabled:
|
||||
- `DSCREENCOPY_ICC=OFF` - Disable screencopy via [ext-image-copy-capture-v1]
|
||||
@@ -192,6 +191,13 @@ To disable: `-DSERVICE_PAM=OFF`
|
||||
|
||||
Dependencies: `pam`
|
||||
|
||||
### Polkit
|
||||
This feature enables creating Polkit agents that can prompt user for authentication.
|
||||
|
||||
To disable: `-DSERVICE_POLKIT=OFF`
|
||||
|
||||
Dependencies: `polkit`, `glib`
|
||||
|
||||
### Hyprland
|
||||
This feature enables hyprland specific integrations. It requires wayland support
|
||||
but has no extra dependencies.
|
||||
@@ -232,7 +238,7 @@ Only `ninja` builds are tested, but makefiles may work.
|
||||
|
||||
#### Configuring the build
|
||||
```sh
|
||||
$ cmake -GNinja -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo [additional disable flags from above here]
|
||||
$ cmake -GNinja -B build -DCMAKE_BUILD_TYPE=Release [additional disable flags from above here]
|
||||
```
|
||||
|
||||
Note that features you do not supply dependencies for MUST be disabled with their associated flags
|
||||
|
||||
+26
-6
@@ -1,5 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(quickshell VERSION "0.2.0" LANGUAGES CXX C)
|
||||
project(quickshell VERSION "0.3.1" LANGUAGES CXX C)
|
||||
|
||||
set(UNRELEASED_FEATURES)
|
||||
|
||||
set(QT_MIN_VERSION "6.6.0")
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
@@ -7,6 +9,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(QS_BUILD_OPTIONS "")
|
||||
|
||||
# should be changed for forks
|
||||
set(CRASHREPORT_URL "https://github.com/outfoxxed/quickshell/issues/new?template=crash2.yml" CACHE STRING "Bugreport URL")
|
||||
|
||||
function(boption VAR NAME DEFAULT)
|
||||
cmake_parse_arguments(PARSE_ARGV 3 arg "" "REQUIRES" "")
|
||||
|
||||
@@ -38,14 +43,17 @@ string(APPEND QS_BUILD_OPTIONS " Distributor: ${DISTRIBUTOR}")
|
||||
|
||||
message(STATUS "Quickshell configuration")
|
||||
message(STATUS " Distributor: ${DISTRIBUTOR}")
|
||||
boption(DISTRIBUTOR_DEBUGINFO_AVAILABLE "Distributor provided debuginfo" NO)
|
||||
boption(NO_PCH "Disable precompild headers (dev)" OFF)
|
||||
boption(BUILD_TESTING "Build tests (dev)" OFF)
|
||||
boption(ASAN "ASAN (dev)" OFF) # note: better output with gcc than clang
|
||||
boption(FRAME_POINTERS "Keep Frame Pointers (dev)" ${ASAN})
|
||||
|
||||
boption(CRASH_REPORTER "Crash Handling" ON)
|
||||
boption(USE_JEMALLOC "Use jemalloc" ON)
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||
boption(USE_JEMALLOC "Use jemalloc" OFF)
|
||||
else()
|
||||
boption(USE_JEMALLOC "Use jemalloc" ON)
|
||||
endif()
|
||||
boption(CRASH_HANDLER "Crash Handling" ON)
|
||||
boption(SOCKETS "Unix Sockets" ON)
|
||||
boption(WAYLAND "Wayland" ON)
|
||||
boption(WAYLAND_WLR_LAYERSHELL " Wlroots Layer-Shell" ON REQUIRES WAYLAND)
|
||||
@@ -67,18 +75,21 @@ boption(SERVICE_STATUS_NOTIFIER "System Tray" ON)
|
||||
boption(SERVICE_PIPEWIRE "PipeWire" ON)
|
||||
boption(SERVICE_MPRIS "Mpris" ON)
|
||||
boption(SERVICE_PAM "Pam" ON)
|
||||
boption(SERVICE_POLKIT "Polkit" ON)
|
||||
boption(SERVICE_GREETD "Greetd" ON)
|
||||
boption(SERVICE_UPOWER "UPower" ON)
|
||||
boption(SERVICE_NOTIFICATIONS "Notifications" ON)
|
||||
boption(BLUETOOTH "Bluetooth" ON)
|
||||
boption(NETWORK "Network" ON)
|
||||
|
||||
include(cmake/install-qml-module.cmake)
|
||||
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)
|
||||
@@ -100,6 +111,7 @@ if (NOT CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
|
||||
set(QT_FPDEPS Gui Qml Quick QuickControls2 Widgets ShaderTools)
|
||||
set(QT_PRIVDEPS QuickPrivate)
|
||||
|
||||
include(cmake/pch.cmake)
|
||||
|
||||
@@ -115,9 +127,10 @@ endif()
|
||||
|
||||
if (WAYLAND)
|
||||
list(APPEND QT_FPDEPS WaylandClient)
|
||||
list(APPEND QT_PRIVDEPS WaylandClientPrivate)
|
||||
endif()
|
||||
|
||||
if (SERVICE_STATUS_NOTIFIER OR SERVICE_MPRIS OR SERVICE_UPOWER OR SERVICE_NOTIFICATIONS OR BLUETOOTH)
|
||||
if (SERVICE_STATUS_NOTIFIER OR SERVICE_MPRIS OR SERVICE_UPOWER OR SERVICE_NOTIFICATIONS OR BLUETOOTH OR NETWORK)
|
||||
set(DBUS ON)
|
||||
endif()
|
||||
|
||||
@@ -127,6 +140,13 @@ endif()
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS ${QT_FPDEPS})
|
||||
|
||||
# In Qt 6.10, private dependencies are required to be explicit,
|
||||
# but they could not be explicitly depended on prior to 6.9.
|
||||
if (Qt6_VERSION VERSION_GREATER_EQUAL "6.9.0")
|
||||
set(QT_NO_PRIVATE_MODULE_WARNING ON)
|
||||
find_package(Qt6 REQUIRED COMPONENTS ${QT_PRIVDEPS})
|
||||
endif()
|
||||
|
||||
set(CMAKE_AUTOUIC OFF)
|
||||
qt_standard_project_setup(REQUIRES 6.6)
|
||||
set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml_modules)
|
||||
|
||||
+26
-221
@@ -1,235 +1,40 @@
|
||||
# Contributing / Development
|
||||
Instructions for development setup and upstreaming patches.
|
||||
# Contributing
|
||||
|
||||
If you just want to build or package quickshell see [BUILD.md](BUILD.md).
|
||||
Thank you for taking the time to contribute.
|
||||
To ensure nobody's time is wasted, please follow the rules below.
|
||||
|
||||
## Development
|
||||
## Acceptable Code Contributions
|
||||
|
||||
Install the dependencies listed in [BUILD.md](BUILD.md).
|
||||
You probably want all of them even if you don't use all of them
|
||||
to ensure tests work correctly and avoid passing a bunch of configure
|
||||
flags when you need to wipe the build directory.
|
||||
- All changes submitted MUST be **fully understood by the submitter**. If you do not know why or how
|
||||
your change works, do not submit it to be merged. You must be able to explain your reasoning
|
||||
for every change.
|
||||
|
||||
Quickshell also uses `just` for common development command aliases.
|
||||
- Changes MUST be submitted by a human who will be responsible for them. Changes submitted without
|
||||
a human in the loop such as automated tooling and AI Agents are **strictly disallowed**. Accounts
|
||||
responsible for such contribution attempts **will be banned**.
|
||||
|
||||
The dependencies are also available as a nix shell or nix flake which we recommend
|
||||
using with nix-direnv.
|
||||
- Changes MUST respect Quickshell's license and the license of any source works. Changes including
|
||||
code from any other works must disclose the source of the code, explain why it was used, and
|
||||
ensure the license is compatible.
|
||||
|
||||
Common aliases:
|
||||
- `just configure [<debug|release> [extra cmake args]]` (note that you must specify debug/release to specify extra args)
|
||||
- `just build` - runs the build, configuring if not configured already.
|
||||
- `just run [args]` - runs quickshell with the given arguments
|
||||
- `just clean` - clean up build artifacts. `just clean build` is somewhat common.
|
||||
- Changes must follow the guidelines outlined in [HACKING.md](HACKING.md) for style and substance.
|
||||
|
||||
### Formatting
|
||||
All contributions should be formatted similarly to what already exists.
|
||||
Group related functionality together.
|
||||
- Changes must stand on their own as a unit. Do not make multiple unrelated changes in one PR.
|
||||
Changes depending on prior merges should be marked as a draft.
|
||||
|
||||
Run the formatter using `just fmt`.
|
||||
If the results look stupid, fix the clang-format file if possible,
|
||||
or disable clang-format in the affected area
|
||||
using `// clang-format off` and `// clang-format on`.
|
||||
## Acceptable Non-code Contributions
|
||||
|
||||
#### Style preferences not caught by clang-format
|
||||
These are flexible. You can ignore them if it looks or works better to
|
||||
for one reason or another.
|
||||
- Bug and crash reports. You must follow the instructions in the issue templates and provide the
|
||||
information requested.
|
||||
|
||||
Use `auto` if the type of a variable can be deduced automatically, instead of
|
||||
redeclaring the returned value's type. Additionally, auto should be used when a
|
||||
constructor takes arguments.
|
||||
- Feature requests can be made via Issues. Please check to ensure nobody else has requested the same feature.
|
||||
|
||||
```cpp
|
||||
auto x = <expr>; // ok
|
||||
auto x = QString::number(3); // ok
|
||||
QString x; // ok
|
||||
QString x = "foo"; // ok
|
||||
auto x = QString("foo"); // ok
|
||||
- Do not make insubstantial or pointless changes.
|
||||
|
||||
auto x = QString(); // avoid
|
||||
QString x(); // avoid
|
||||
QString x("foo"); // avoid
|
||||
```
|
||||
- Changes to project rules / policy / governance will not be entertained, except from significant
|
||||
long-term contributors. These changes should not be addressed through contribution channels.
|
||||
|
||||
Put newlines around logical units of code, and after closing braces. If the
|
||||
most reasonable logical unit of code takes only a single line, it should be
|
||||
merged into the next single line logical unit if applicable.
|
||||
```cpp
|
||||
// multiple units
|
||||
auto x = <expr>; // unit 1
|
||||
auto y = <expr>; // unit 2
|
||||
## Merge timelines
|
||||
|
||||
auto x = <expr>; // unit 1
|
||||
emit this->y(); // unit 2
|
||||
|
||||
auto x1 = <expr>; // unit 1
|
||||
auto x2 = <expr>; // unit 1
|
||||
auto x3 = <expr>; // unit 1
|
||||
|
||||
auto y1 = <expr>; // unit 2
|
||||
auto y2 = <expr>; // unit 2
|
||||
auto y3 = <expr>; // unit 2
|
||||
|
||||
// one unit
|
||||
auto x = <expr>;
|
||||
if (x...) {
|
||||
// ...
|
||||
}
|
||||
|
||||
// if more than one variable needs to be used then add a newline
|
||||
auto x = <expr>;
|
||||
auto y = <expr>;
|
||||
|
||||
if (x && y) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Class formatting:
|
||||
```cpp
|
||||
//! Doc comment summary
|
||||
/// Doc comment body
|
||||
class Foo: public QObject {
|
||||
// The Q_OBJECT macro comes first. Macros are ; terminated.
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_CLASSINFO(...);
|
||||
// Properties must stay on a single line or the doc generator won't be able to pick them up
|
||||
Q_PROPERTY(...);
|
||||
/// Doc comment
|
||||
Q_PROPERTY(...);
|
||||
/// Doc comment
|
||||
Q_PROPERTY(...);
|
||||
|
||||
public:
|
||||
// Classes should have explicit constructors if they aren't intended to
|
||||
// implicitly cast. The constructor can be inline in the header if it has no body.
|
||||
explicit Foo(QObject* parent = nullptr): QObject(parent) {}
|
||||
|
||||
// Instance functions if applicable.
|
||||
static Foo* instance();
|
||||
|
||||
// Member functions unrelated to properties come next
|
||||
void function();
|
||||
void function();
|
||||
void function();
|
||||
|
||||
// Then Q_INVOKABLEs
|
||||
Q_INVOKABLE function();
|
||||
/// Doc comment
|
||||
Q_INVOKABLE function();
|
||||
/// Doc comment
|
||||
Q_INVOKABLE function();
|
||||
|
||||
// Then property related functions, in the order (bindable, getter, setter).
|
||||
// Related functions may be included here as well. Function bodies may be inline
|
||||
// if they are a single expression. There should be a newline between each
|
||||
// property's methods.
|
||||
[[nodiscard]] QBindable<T> bindableFoo() { return &this->bFoo; }
|
||||
[[nodiscard]] T foo() const { return this->foo; }
|
||||
void setFoo();
|
||||
|
||||
[[nodiscard]] T bar() const { return this->foo; }
|
||||
void setBar();
|
||||
|
||||
signals:
|
||||
// Signals that are not property change related go first.
|
||||
// Property change signals go in property definition order.
|
||||
void asd();
|
||||
void asd2();
|
||||
void fooChanged();
|
||||
void barChanged();
|
||||
|
||||
public slots:
|
||||
// generally Q_INVOKABLEs are preferred to public slots.
|
||||
void slot();
|
||||
|
||||
private slots:
|
||||
// ...
|
||||
|
||||
private:
|
||||
// statics, then functions, then fields
|
||||
static const foo BAR;
|
||||
static void foo();
|
||||
|
||||
void foo();
|
||||
void bar();
|
||||
|
||||
// property related members are prefixed with `m`.
|
||||
QString mFoo;
|
||||
QString bar;
|
||||
|
||||
// Bindables go last and should be prefixed with `b`.
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Foo, QString, bFoo, &Foo::fooChanged);
|
||||
};
|
||||
```
|
||||
|
||||
### Linter
|
||||
All contributions should pass the linter.
|
||||
|
||||
Note that running the linter requires disabling precompiled
|
||||
headers and including the test codepaths:
|
||||
```sh
|
||||
$ just configure debug -DNO_PCH=ON -DBUILD_TESTING=ON
|
||||
$ just lint-changed
|
||||
```
|
||||
|
||||
If the linter is complaining about something that you think it should not,
|
||||
please disable the lint in your MR and explain your reasoning if it isn't obvious.
|
||||
|
||||
### Tests
|
||||
If you feel like the feature you are working on is very complex or likely to break,
|
||||
please write some tests. We will ask you to directly if you send in an MR for an
|
||||
overly complex or breakable feature.
|
||||
|
||||
At least all tests that passed before your changes should still be passing
|
||||
by the time your contribution is ready.
|
||||
|
||||
You can run the tests using `just test` but you must enable them first
|
||||
using `-DBUILD_TESTING=ON`.
|
||||
|
||||
### Documentation
|
||||
Most of quickshell's documentation is automatically generated from the source code.
|
||||
You should annotate `Q_PROPERTY`s and `Q_INVOKABLE`s with doc comments. Note that the parser
|
||||
cannot handle random line breaks and will usually require you to disable clang-format if the
|
||||
lines are too long.
|
||||
|
||||
Before submitting an MR, if adding new features please make sure the documentation is generated
|
||||
reasonably using the `quickshell-docs` repo. We recommend checking it out at `/docs` in this repo.
|
||||
|
||||
Doc comments take the form `///` or `///!` (summary) and work with markdown.
|
||||
You can reference other types using the `@@[Module.][Type.][member]` shorthand
|
||||
where all parts are optional. If module or type are not specified they will
|
||||
be inferred as the current module. Member can be a `property`, `function()` or `signal(s)`.
|
||||
Look at existing code for how it works.
|
||||
|
||||
Quickshell modules additionally have a `module.md` file which contains a summary, description,
|
||||
and list of headers to scan for documentation.
|
||||
|
||||
## Contributing
|
||||
|
||||
### Commits
|
||||
Please structure your commit messages as `scope[!]: commit` where
|
||||
the scope is something like `core` or `service/mpris`. (pick what has been
|
||||
used historically or what makes sense if new). Add `!` for changes that break
|
||||
existing APIs or functionality.
|
||||
|
||||
Commit descriptions should contain a summary of the changes if they are not
|
||||
sufficiently addressed in the commit message.
|
||||
|
||||
Please squash/rebase additions or edits to previous changes and follow the
|
||||
commit style to keep the history easily searchable at a glance.
|
||||
Depending on the change, it is often reasonable to squash it into just
|
||||
a single commit. (If you do not follow this we will squash your changes
|
||||
for you.)
|
||||
|
||||
### Sending patches
|
||||
You may contribute by submitting a pull request on github, asking for
|
||||
an account on our git server, or emailing patches / git bundles
|
||||
directly to `[email protected]`.
|
||||
|
||||
### Getting help
|
||||
If you're getting stuck, you can come talk to us in the
|
||||
[quickshell-development matrix room](https://matrix.to/#/#quickshell-development:outfoxxed.me)
|
||||
for help on implementation, conventions, etc.
|
||||
Feel free to ask for advice early in your implementation if you are
|
||||
unsure.
|
||||
We handle work for the most part on a push basis. If your PR has been ignored for a while
|
||||
and is still relevant please bump it.
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
## Development
|
||||
|
||||
Install the dependencies listed in [BUILD.md](BUILD.md).
|
||||
You probably want all of them even if you don't use all of them
|
||||
to ensure tests work correctly and avoid passing a bunch of configure
|
||||
flags when you need to wipe the build directory.
|
||||
|
||||
The dependencies are also available as a nix shell or nix flake which we recommend
|
||||
using with nix-direnv.
|
||||
|
||||
Quickshell uses `just` for common development command aliases.
|
||||
|
||||
Common aliases:
|
||||
- `just configure [<debug|release> [extra cmake args]]` (note that you must specify debug/release to specify extra args)
|
||||
- `just build` - runs the build, configuring if not configured already.
|
||||
- `just run [args]` - runs quickshell with the given arguments
|
||||
- `just clean` - clean up build artifacts. `just clean build` is somewhat common.
|
||||
|
||||
### Formatting
|
||||
All contributions should be formatted similarly to what already exists.
|
||||
Group related functionality together.
|
||||
|
||||
Run the formatter using `just fmt`.
|
||||
If the results look stupid, fix the clang-format file if possible,
|
||||
or disable clang-format in the affected area
|
||||
using `// clang-format off` and `// clang-format on`.
|
||||
|
||||
#### Style preferences not caught by clang-format
|
||||
These are flexible. You can ignore them if it looks or works better to
|
||||
for one reason or another.
|
||||
|
||||
Use `auto` if the type of a variable can be deduced automatically, instead of
|
||||
redeclaring the returned value's type. Additionally, auto should be used when a
|
||||
constructor takes arguments.
|
||||
|
||||
```cpp
|
||||
auto x = <expr>; // ok
|
||||
auto x = QString::number(3); // ok
|
||||
QString x; // ok
|
||||
QString x = "foo"; // ok
|
||||
auto x = QString("foo"); // ok
|
||||
|
||||
auto x = QString(); // avoid
|
||||
QString x(); // avoid
|
||||
QString x("foo"); // avoid
|
||||
```
|
||||
|
||||
Put newlines around logical units of code, and after closing braces. If the
|
||||
most reasonable logical unit of code takes only a single line, it should be
|
||||
merged into the next single line logical unit if applicable.
|
||||
```cpp
|
||||
// multiple units
|
||||
auto x = <expr>; // unit 1
|
||||
auto y = <expr>; // unit 2
|
||||
|
||||
auto x = <expr>; // unit 1
|
||||
emit this->y(); // unit 2
|
||||
|
||||
auto x1 = <expr>; // unit 1
|
||||
auto x2 = <expr>; // unit 1
|
||||
auto x3 = <expr>; // unit 1
|
||||
|
||||
auto y1 = <expr>; // unit 2
|
||||
auto y2 = <expr>; // unit 2
|
||||
auto y3 = <expr>; // unit 2
|
||||
|
||||
// one unit
|
||||
auto x = <expr>;
|
||||
if (x...) {
|
||||
// ...
|
||||
}
|
||||
|
||||
// if more than one variable needs to be used then add a newline
|
||||
auto x = <expr>;
|
||||
auto y = <expr>;
|
||||
|
||||
if (x && y) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Class formatting:
|
||||
```cpp
|
||||
//! Doc comment summary
|
||||
/// Doc comment body
|
||||
class Foo: public QObject {
|
||||
// The Q_OBJECT macro comes first. Macros are ; terminated.
|
||||
Q_OBJECT;
|
||||
QML_ELEMENT;
|
||||
QML_CLASSINFO(...);
|
||||
// Properties must stay on a single line or the doc generator won't be able to pick them up
|
||||
Q_PROPERTY(...);
|
||||
/// Doc comment
|
||||
Q_PROPERTY(...);
|
||||
/// Doc comment
|
||||
Q_PROPERTY(...);
|
||||
|
||||
public:
|
||||
// Classes should have explicit constructors if they aren't intended to
|
||||
// implicitly cast. The constructor can be inline in the header if it has no body.
|
||||
explicit Foo(QObject* parent = nullptr): QObject(parent) {}
|
||||
|
||||
// Instance functions if applicable.
|
||||
static Foo* instance();
|
||||
|
||||
// Member functions unrelated to properties come next
|
||||
void function();
|
||||
void function();
|
||||
void function();
|
||||
|
||||
// Then Q_INVOKABLEs
|
||||
Q_INVOKABLE function();
|
||||
/// Doc comment
|
||||
Q_INVOKABLE function();
|
||||
/// Doc comment
|
||||
Q_INVOKABLE function();
|
||||
|
||||
// Then property related functions, in the order (bindable, getter, setter).
|
||||
// Related functions may be included here as well. Function bodies may be inline
|
||||
// if they are a single expression. There should be a newline between each
|
||||
// property's methods.
|
||||
[[nodiscard]] QBindable<T> bindableFoo() { return &this->bFoo; }
|
||||
[[nodiscard]] T foo() const { return this->foo; }
|
||||
void setFoo();
|
||||
|
||||
[[nodiscard]] T bar() const { return this->foo; }
|
||||
void setBar();
|
||||
|
||||
signals:
|
||||
// Signals that are not property change related go first.
|
||||
// Property change signals go in property definition order.
|
||||
void asd();
|
||||
void asd2();
|
||||
void fooChanged();
|
||||
void barChanged();
|
||||
|
||||
public slots:
|
||||
// generally Q_INVOKABLEs are preferred to public slots.
|
||||
void slot();
|
||||
|
||||
private slots:
|
||||
// ...
|
||||
|
||||
private:
|
||||
// statics, then functions, then fields
|
||||
static const foo BAR;
|
||||
static void foo();
|
||||
|
||||
void foo();
|
||||
void bar();
|
||||
|
||||
// property related members are prefixed with `m`.
|
||||
QString mFoo;
|
||||
QString bar;
|
||||
|
||||
// Bindables go last and should be prefixed with `b`.
|
||||
Q_OBJECT_BINDABLE_PROPERTY(Foo, QString, bFoo, &Foo::fooChanged);
|
||||
};
|
||||
```
|
||||
|
||||
Use lowercase .h suffixed Qt headers, e.g. `<qwindow.h>` over `<QWindow>`.
|
||||
|
||||
### Linter
|
||||
All contributions should pass the linter.
|
||||
|
||||
Note that running the linter requires disabling precompiled
|
||||
headers and including the test codepaths:
|
||||
```sh
|
||||
$ just configure debug -DNO_PCH=ON -DBUILD_TESTING=ON
|
||||
$ just lint-changed
|
||||
```
|
||||
|
||||
If the linter is complaining about something that you think it should not,
|
||||
please disable the lint in your MR and explain your reasoning if it isn't obvious.
|
||||
|
||||
### Tests
|
||||
If you feel like the feature you are working on is very complex or likely to break,
|
||||
please write some tests. We will ask you to directly if you send in an MR for an
|
||||
overly complex or breakable feature.
|
||||
|
||||
At least all tests that passed before your changes should still be passing
|
||||
by the time your contribution is ready.
|
||||
|
||||
You can run the tests using `just test` but you must enable them first
|
||||
using `-DBUILD_TESTING=ON`.
|
||||
|
||||
### Documentation
|
||||
Most of quickshell's documentation is automatically generated from the source code.
|
||||
You should annotate `Q_PROPERTY`s and `Q_INVOKABLE`s with doc comments. Note that the parser
|
||||
cannot handle random line breaks and will usually require you to disable clang-format if the
|
||||
lines are too long.
|
||||
|
||||
Make sure new files containing doc comments are added to a `module.md` file.
|
||||
See existing module files for reference.
|
||||
|
||||
Doc comments take the form `///` or `///!` (summary) and work with markdown.
|
||||
You can reference other types using the `@@[Module.][Type.][member]` shorthand
|
||||
where all parts are optional. If module or type are not specified they will
|
||||
be inferred as the current module. Member can be a `property`, `function()` or `signal(s)`.
|
||||
Look at existing code for how it works.
|
||||
|
||||
If you have made a user visible change since the last tagged release, describe it in
|
||||
[changelog/next.md](changelog/next.md).
|
||||
|
||||
## Contributing
|
||||
|
||||
### Commits
|
||||
Please structure your commit messages as `scope: commit` where
|
||||
the scope is something like `core` or `service/mpris`. (pick what has been
|
||||
used historically or what makes sense if new).
|
||||
|
||||
Commit descriptions should contain a summary of the changes if they are not
|
||||
sufficiently addressed in the commit message.
|
||||
|
||||
Please squash/rebase additions or edits to previous changes and follow the
|
||||
commit style to keep the history easily searchable at a glance.
|
||||
Depending on the change, it is often reasonable to squash it into just
|
||||
a single commit. (If you do not follow this we will squash your changes
|
||||
for you.)
|
||||
|
||||
### Getting help
|
||||
If you're getting stuck, you can come talk to us in the
|
||||
[quickshell-development matrix room](https://matrix.to/#/#quickshell-development:outfoxxed.me)
|
||||
for help on implementation, conventions, etc. There is also a bridged [discord server](https://discord.gg/UtZeT3xNyT).
|
||||
Feel free to ask for advice early in your implementation if you are
|
||||
unsure.
|
||||
@@ -12,6 +12,9 @@ lint-ci:
|
||||
lint-changed:
|
||||
git diff --name-only HEAD | grep "^.*\.cpp\$" | parallel -j$(nproc) --no-notice --will-cite --tty --bar clang-tidy --load={{ env_var("TIDYFOX") }}
|
||||
|
||||
lint-staged:
|
||||
git diff --staged --name-only --diff-filter=d HEAD | grep "^.*\.cpp\$" | parallel -j$(nproc) --no-notice --will-cite --tty --bar clang-tidy --load={{ env_var("TIDYFOX") }}
|
||||
|
||||
configure target='debug' *FLAGS='':
|
||||
cmake -GNinja -B {{builddir}} \
|
||||
-DCMAKE_BUILD_TYPE={{ if target == "debug" { "Debug" } else { "RelWithDebInfo" } }} \
|
||||
|
||||
@@ -7,7 +7,9 @@ This repo is hosted at:
|
||||
- https://github.com/quickshell-mirror/quickshell
|
||||
|
||||
# Contributing / Development
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
||||
- [HACKING.md](HACKING.md) - Development instructions and policy.
|
||||
- [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution policy.
|
||||
- [BUILD.md](BUILD.md) - Packaging and build instructions.
|
||||
|
||||
#### License
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
## New Features
|
||||
|
||||
- Changes to desktop entries are now tracked in real time.
|
||||
|
||||
## Other Changes
|
||||
|
||||
- Added support for Qt 6.10
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Fixed volumes getting stuck on change for pipewire devices with few volume steps.
|
||||
- Fixed a crash when running out of disk space to write log files.
|
||||
- Fixed a rare crash when disconnecting a monitor.
|
||||
- Fixed build issues preventing cross compilation from working.
|
||||
- Fixed dekstop entries with lower priority than a hidden entry not being hidden.
|
||||
- Fixed desktop entry keys with mismatched modifier or country not being discarded.
|
||||
- Fixed greetd hanging when authenticating with a fingerprint.
|
||||
@@ -0,0 +1,89 @@
|
||||
## Breaking Changes
|
||||
|
||||
### Config paths are no longer canonicalized
|
||||
|
||||
This fixes nix configs changing shell-ids on rebuild as the shell id is now derived from
|
||||
the symlink path. Configs with a symlink in their path will have a different shell id.
|
||||
|
||||
Shell ids are used to derive the default config / state / cache folders, so those files
|
||||
will need to be manually moved if using a config behind a symlinked path without an explicitly
|
||||
set shell id.
|
||||
|
||||
## New Features
|
||||
|
||||
- Added support for creating Polkit agents.
|
||||
- Added support for creating wayland idle inhibitors.
|
||||
- Added support for wayland idle timeouts.
|
||||
- Added support for inhibiting wayland compositor shortcuts for focused windows.
|
||||
- Added the ability to override Quickshell.cacheDir with a custom path.
|
||||
- Added minimized, maximized, and fullscreen properties to FloatingWindow.
|
||||
- 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 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.
|
||||
- Added lua config support to Hyprland module.
|
||||
|
||||
## Other Changes
|
||||
|
||||
- IPC operations filter available instances to the current display connection by default.
|
||||
- PwNodeLinkTracker ignores sound level monitoring programs.
|
||||
- Replaced breakpad with cpptrace.
|
||||
- Reloads are prevented if no file content has changed.
|
||||
- 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.
|
||||
- Added `DefaultEnv` pragma which sets an environment variable if not already set.
|
||||
- Unrecognized pragmas are no longer a hard error for future backward compatibility.
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Fixed volume control breaking with pipewire pro audio mode.
|
||||
- Fixed volume control breaking with bluez streams and potentially others.
|
||||
- Fixed volume control breaking for devices without route definitions.
|
||||
- Fixed escape sequence handling in desktop entries.
|
||||
- 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.
|
||||
- Fixed memory leak in IPC handlers.
|
||||
- Fixed ClippingRectangle related crashes.
|
||||
- Fixed crashes when monitors are unplugged.
|
||||
- Fixed crashes when default pipewire devices are lost.
|
||||
- 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.
|
||||
- Fixed launches failing for `--daemonize` on some systems.
|
||||
- Fixed screencopy crashing when used across GPUs.
|
||||
- Fixed pipewire volumes not working for some pw-pulse clients.
|
||||
- Fixed nulls in Toplevel.screens after unplugging a monitor.
|
||||
- Fixed some DbusMenu updates being dropped from apps.
|
||||
|
||||
## Packaging Changes
|
||||
|
||||
- `glib` and `polkit` have been added as dependencies when compiling with polkit agent support.
|
||||
- `vulkan-headers` has been added as a build-time dependency for screencopy (Vulkan backend support).
|
||||
- `breakpad` has been replaced by `cpptrace`, which is far easier to package, and the `CRASH_REPORTER` cmake variable has been replaced with `CRASH_HANDLER` to stop this from being easy to ignore.
|
||||
- `DISTRIBUTOR_DEBUGINFO_AVAILABLE` was removed as it is no longer important without breakpad.
|
||||
- `libdrm` is now unconditionally required as a direct dependency.
|
||||
@@ -0,0 +1,23 @@
|
||||
## Bug Fixes
|
||||
|
||||
- Fixed `ScreencopyView` not displaying when only lock surfaces are shown.
|
||||
- Fixed `WlSessionLockSurface.visible` crashing if accessed before backing surface creation.
|
||||
- Fixed `MprisPlayer` returning `rate` for `minRate` and `maxRate`.
|
||||
- Fixed missing/wrong change signals on various properties.
|
||||
- Fixed session lock crashes on sleep, wake, DPMS, and unlocking.
|
||||
- `QsWindow.updatesEnabled` makes sure windows are redrawn when set to true.
|
||||
- Fixed potential crashes from usage of `WindowsetProjection.screens` during monitor unplug.
|
||||
- Fixed crashes from accessing freed objects laundered through a `ScriptModel`.
|
||||
- Fixed crashes when a wifi network disappear.
|
||||
- Fixed unhandled notifications sending `NotificationClosed` out of order.
|
||||
- Fixed `qs kill` not waiting for the process to exit.
|
||||
- Fixed IPC calls from children of a crashed and relaunched process crashing.
|
||||
- Fixed `JsonAdapter` crashing when deserializing new objects into an array.
|
||||
- Fixed `Toplevel.unsetRectangle` crashing when calle.
|
||||
- Fixed intermittent `FileView` crashes when updating watched files.
|
||||
- Fixed `ColorQuantizer` deletion crashing if an operation was live.
|
||||
- Fixed crashes when failing to create a `ScreencopyView`.
|
||||
- Fixed `PwNodePeakMonitor` crashing when sampling a stream with mismatched channels from the node.
|
||||
- Fixed unsetting `PopupAnchor.item` causing a crash.
|
||||
- Fixed hiding the last `PanelWindow` on screen causing a crash under X11.
|
||||
- Fixed crashes when `ScriptModel.values` is set while processing previously set values.
|
||||
+5
-2
@@ -2,7 +2,10 @@
|
||||
qtver,
|
||||
compiler,
|
||||
}: let
|
||||
nixpkgs = (import ./nix-checkouts.nix).${builtins.replaceStrings ["."] ["_"] qtver};
|
||||
checkouts = import ./nix-checkouts.nix;
|
||||
nixpkgs = checkouts.${builtins.replaceStrings ["."] ["_"] qtver};
|
||||
compilerOverride = (nixpkgs.callPackage ./variations.nix {}).${compiler};
|
||||
pkg = (nixpkgs.callPackage ../default.nix {}).override compilerOverride;
|
||||
pkg = (nixpkgs.callPackage ../default.nix {}).override (compilerOverride // {
|
||||
wayland-protocols = checkouts.latest.wayland-protocols;
|
||||
});
|
||||
in pkg
|
||||
+22
-3
@@ -7,9 +7,28 @@ let
|
||||
url = "https://github.com/nixos/nixpkgs/archive/${commit}.tar.gz";
|
||||
inherit sha256;
|
||||
}) {};
|
||||
in {
|
||||
# For old qt versions, grab the commit before the version bump that has all the patches
|
||||
# instead of the bumped version.
|
||||
in rec {
|
||||
latest = qt6_10_0;
|
||||
|
||||
qt6_10_1 = byCommit {
|
||||
commit = "ffbc9f8cbaacfb331b6017d5a5abb21a492c9a38";
|
||||
sha256 = "0fvbizl7j5rv2rf8j76yw0xb3d9l06hahkjys2a7k1yraznvnafm";
|
||||
};
|
||||
|
||||
qt6_10_0 = byCommit {
|
||||
commit = "c5ae371f1a6a7fd27823bc500d9390b38c05fa55";
|
||||
sha256 = "18g0f8cb9m8mxnz9cf48sks0hib79b282iajl2nysyszph993yp0";
|
||||
};
|
||||
|
||||
qt6_9_2 = byCommit {
|
||||
commit = "e9f00bd893984bc8ce46c895c3bf7cac95331127";
|
||||
sha256 = "0s2mhbrgzxlgkg2yxb0q0hpk8lby1a7w67dxvfmaz4gsmc0bnvfj";
|
||||
};
|
||||
|
||||
qt6_9_1 = byCommit {
|
||||
commit = "4c202d26483c5ccf3cb95e0053163facde9f047e";
|
||||
sha256 = "06l2w4bcgfw7dfanpzpjcf25ydf84in240yplqsss82qx405y9di";
|
||||
};
|
||||
|
||||
qt6_9_0 = byCommit {
|
||||
commit = "546c545bd0594809a28ab7e869b5f80dd7243ef6";
|
||||
|
||||
+2
-2
@@ -2,6 +2,6 @@
|
||||
clangStdenv,
|
||||
gccStdenv,
|
||||
}: {
|
||||
clang = { buildStdenv = clangStdenv; };
|
||||
gcc = { buildStdenv = gccStdenv; };
|
||||
clang = { stdenv = clangStdenv; };
|
||||
gcc = { stdenv = gccStdenv; };
|
||||
}
|
||||
+35
-12
@@ -2,25 +2,31 @@
|
||||
lib,
|
||||
nix-gitignore,
|
||||
pkgs,
|
||||
stdenv,
|
||||
keepDebugInfo,
|
||||
buildStdenv ? pkgs.clangStdenv,
|
||||
|
||||
pkg-config,
|
||||
cmake,
|
||||
ninja,
|
||||
spirv-tools,
|
||||
qt6,
|
||||
breakpad,
|
||||
cpptrace ? null,
|
||||
libunwind,
|
||||
libdwarf,
|
||||
jemalloc,
|
||||
cli11,
|
||||
wayland,
|
||||
wayland-protocols,
|
||||
wayland-scanner,
|
||||
xorg,
|
||||
libxcb ? xorg.libxcb,
|
||||
libdrm,
|
||||
libgbm ? null,
|
||||
vulkan-headers,
|
||||
pipewire,
|
||||
pam,
|
||||
polkit,
|
||||
glib,
|
||||
|
||||
gitRev ? (let
|
||||
headExists = builtins.pathExists ./.git/HEAD;
|
||||
@@ -43,10 +49,14 @@
|
||||
withPam ? true,
|
||||
withHyprland ? true,
|
||||
withI3 ? true,
|
||||
withPolkit ? true,
|
||||
withNetworkManager ? true,
|
||||
}: let
|
||||
unwrapped = buildStdenv.mkDerivation {
|
||||
withCrashHandler = withCrashReporter && cpptrace != null && lib.strings.compareVersions cpptrace.version "0.7.2" >= 0;
|
||||
|
||||
unwrapped = stdenv.mkDerivation {
|
||||
pname = "quickshell${lib.optionalString debug "-debug"}";
|
||||
version = "0.2.0";
|
||||
version = "0.3.1";
|
||||
src = nix-gitignore.gitignoreSource "/default.nix\n" ./.;
|
||||
|
||||
dontWrapQtApps = true; # see wrappers
|
||||
@@ -54,25 +64,36 @@
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
ninja
|
||||
qt6.qtshadertools
|
||||
spirv-tools
|
||||
pkg-config
|
||||
]
|
||||
++ lib.optional withWayland wayland-scanner;
|
||||
++ lib.optional (withWayland && lib.strings.compareVersions qt6.qtbase.version "6.10.0" == -1) qt6.qtwayland
|
||||
++ lib.optionals withWayland [
|
||||
qt6.qtwayland # qtwaylandscanner required at build time
|
||||
wayland-scanner
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
qt6.qtbase
|
||||
qt6.qtdeclarative
|
||||
libdrm
|
||||
cli11
|
||||
]
|
||||
++ lib.optional withQtSvg qt6.qtsvg
|
||||
++ lib.optional withCrashReporter breakpad
|
||||
++ lib.optional withCrashHandler (cpptrace.overrideAttrs (prev: {
|
||||
cmakeFlags = prev.cmakeFlags ++ [
|
||||
"-DCPPTRACE_UNWIND_WITH_LIBUNWIND=TRUE"
|
||||
];
|
||||
buildInputs = prev.buildInputs ++ [ libunwind ];
|
||||
}))
|
||||
++ lib.optional withJemalloc jemalloc
|
||||
++ lib.optionals withWayland [ qt6.qtwayland wayland wayland-protocols ]
|
||||
++ lib.optionals (withWayland && libgbm != null) [ libdrm libgbm ]
|
||||
++ lib.optional withX11 xorg.libxcb
|
||||
++ lib.optional (withWayland && lib.strings.compareVersions qt6.qtbase.version "6.10.0" == -1) qt6.qtwayland
|
||||
++ lib.optionals withWayland [ wayland wayland-protocols ]
|
||||
++ lib.optionals (withWayland && libgbm != null) [ libgbm vulkan-headers ]
|
||||
++ lib.optional withX11 libxcb
|
||||
++ lib.optional withPam pam
|
||||
++ lib.optional withPipewire pipewire;
|
||||
++ lib.optional withPipewire pipewire
|
||||
++ lib.optionals withPolkit [ polkit glib ];
|
||||
|
||||
cmakeBuildType = if debug then "Debug" else "RelWithDebInfo";
|
||||
|
||||
@@ -81,12 +102,14 @@
|
||||
(lib.cmakeFeature "INSTALL_QML_PREFIX" qt6.qtbase.qtQmlPrefix)
|
||||
(lib.cmakeBool "DISTRIBUTOR_DEBUGINFO_AVAILABLE" true)
|
||||
(lib.cmakeFeature "GIT_REVISION" gitRev)
|
||||
(lib.cmakeBool "CRASH_REPORTER" withCrashReporter)
|
||||
(lib.cmakeBool "CRASH_HANDLER" withCrashHandler)
|
||||
(lib.cmakeBool "USE_JEMALLOC" withJemalloc)
|
||||
(lib.cmakeBool "WAYLAND" withWayland)
|
||||
(lib.cmakeBool "SCREENCOPY" (libgbm != null))
|
||||
(lib.cmakeBool "SERVICE_PIPEWIRE" withPipewire)
|
||||
(lib.cmakeBool "SERVICE_PAM" withPam)
|
||||
(lib.cmakeBool "SERVICE_NETWORKMANAGER" withNetworkManager)
|
||||
(lib.cmakeBool "SERVICE_POLKIT" withPolkit)
|
||||
(lib.cmakeBool "HYPRLAND" withHyprland)
|
||||
(lib.cmakeBool "I3" withI3)
|
||||
];
|
||||
|
||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1749285348,
|
||||
"narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=",
|
||||
"lastModified": 1768127708,
|
||||
"narHash": "sha256-1Sm77VfZh3mU0F5OqKABNLWxOuDeHIlcFjsXeeiPazs=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "3e3afe5174c561dee0df6f2c2b2236990146329f",
|
||||
"rev": "ffbc9f8cbaacfb331b6017d5a5abb21a492c9a38",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -4,23 +4,28 @@
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }: let
|
||||
overlayPkgs = p: p.appendOverlays [ self.overlays.default ];
|
||||
|
||||
forEachSystem = fn:
|
||||
nixpkgs.lib.genAttrs
|
||||
nixpkgs.lib.platforms.linux
|
||||
(system: fn system nixpkgs.legacyPackages.${system});
|
||||
(system: fn system (overlayPkgs nixpkgs.legacyPackages.${system}));
|
||||
in {
|
||||
packages = forEachSystem (system: pkgs: rec {
|
||||
quickshell = pkgs.callPackage ./default.nix {
|
||||
gitRev = self.rev or self.dirtyRev;
|
||||
};
|
||||
overlays.default = import ./overlay.nix {
|
||||
rev = self.rev or self.dirtyRev;
|
||||
};
|
||||
|
||||
packages = forEachSystem (system: pkgs: rec {
|
||||
quickshell = pkgs.quickshell;
|
||||
default = quickshell;
|
||||
});
|
||||
|
||||
devShells = forEachSystem (system: pkgs: rec {
|
||||
default = import ./shell.nix {
|
||||
inherit pkgs;
|
||||
inherit (self.packages.${system}) quickshell;
|
||||
quickshell = self.packages.${system}.quickshell.override {
|
||||
stdenv = pkgs.clangStdenv;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{ rev ? null }: (final: prev: {
|
||||
quickshell = final.callPackage ./default.nix {
|
||||
gitRev = rev;
|
||||
};
|
||||
})
|
||||
@@ -1,77 +0,0 @@
|
||||
(define-module (quickshell)
|
||||
#:use-module ((guix licenses) #:prefix license:)
|
||||
#:use-module (gnu packages cpp)
|
||||
#:use-module (gnu packages freedesktop)
|
||||
#:use-module (gnu packages gcc)
|
||||
#:use-module (gnu packages gl)
|
||||
#:use-module (gnu packages jemalloc)
|
||||
#:use-module (gnu packages linux)
|
||||
#:use-module (gnu packages ninja)
|
||||
#:use-module (gnu packages pkg-config)
|
||||
#:use-module (gnu packages qt)
|
||||
#:use-module (gnu packages vulkan)
|
||||
#:use-module (gnu packages xdisorg)
|
||||
#:use-module (gnu packages xorg)
|
||||
#:use-module (guix build-system cmake)
|
||||
#:use-module (guix download)
|
||||
#:use-module (guix gexp)
|
||||
#:use-module (guix git-download)
|
||||
#:use-module (guix packages)
|
||||
#:use-module (guix packages)
|
||||
#:use-module (guix utils))
|
||||
|
||||
(define-public quickshell-git
|
||||
(package
|
||||
(name "quickshell")
|
||||
(version "git")
|
||||
(source (local-file "." "quickshell-checkout"
|
||||
#:recursive? #t
|
||||
#:select? (or (git-predicate (current-source-directory))
|
||||
(const #t))))
|
||||
(build-system cmake-build-system)
|
||||
(propagated-inputs (list qtbase qtdeclarative qtsvg))
|
||||
(native-inputs (list ninja
|
||||
gcc-14
|
||||
pkg-config
|
||||
qtshadertools
|
||||
spirv-tools
|
||||
wayland-protocols
|
||||
cli11))
|
||||
(inputs (list jemalloc
|
||||
libdrm
|
||||
libxcb
|
||||
libxkbcommon
|
||||
linux-pam
|
||||
mesa
|
||||
pipewire
|
||||
qtbase
|
||||
qtdeclarative
|
||||
qtwayland
|
||||
vulkan-headers
|
||||
wayland))
|
||||
(arguments
|
||||
(list #:tests? #f
|
||||
#:configure-flags
|
||||
#~(list "-GNinja"
|
||||
"-DDISTRIBUTOR=\"In-tree Guix channel\""
|
||||
"-DDISTRIBUTOR_DEBUGINFO_AVAILABLE=NO"
|
||||
;; Breakpad is not currently packaged for Guix.
|
||||
"-DCRASH_REPORTER=OFF")
|
||||
#:phases
|
||||
#~(modify-phases %standard-phases
|
||||
(replace 'build (lambda _ (invoke "cmake" "--build" ".")))
|
||||
(replace 'install (lambda _ (invoke "cmake" "--install" ".")))
|
||||
(add-after 'install 'wrap-program
|
||||
(lambda* (#:key inputs #:allow-other-keys)
|
||||
(wrap-program (string-append #$output "/bin/quickshell")
|
||||
`("QML_IMPORT_PATH" ":"
|
||||
= (,(getenv "QML_IMPORT_PATH")))))))))
|
||||
(home-page "https://quickshell.outfoxxed.me")
|
||||
(synopsis "QtQuick-based desktop shell toolkit")
|
||||
(description
|
||||
"Quickshell is a flexible QtQuick-based toolkit for creating and
|
||||
customizing toolbars, notification centers, and other desktop
|
||||
environment tools in a live programming environment.")
|
||||
(license license:lgpl3)))
|
||||
|
||||
quickshell-git
|
||||
@@ -1,14 +1,15 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
quickshell ? pkgs.callPackage ./default.nix {},
|
||||
stdenv ? pkgs.clangStdenv, # faster compiles than gcc
|
||||
quickshell ? pkgs.callPackage ./default.nix { inherit stdenv; },
|
||||
...
|
||||
}: let
|
||||
tidyfox = import (pkgs.fetchFromGitea {
|
||||
domain = "git.outfoxxed.me";
|
||||
owner = "outfoxxed";
|
||||
repo = "tidyfox";
|
||||
rev = "1f062cc198d1112d13e5128fa1f2ee3dbffe613b";
|
||||
sha256 = "kbt0Zc1qHE5fhqBkKz8iue+B+ZANjF1AR/RdgmX1r0I=";
|
||||
rev = "9d85d7e7dea2602aa74ec3168955fee69967e92f";
|
||||
hash = "sha256-77ERiweF6lumonp2c/124rAoVG6/o9J+Aajhttwtu0w=";
|
||||
}) { inherit pkgs; };
|
||||
in pkgs.mkShell.override { stdenv = quickshell.stdenv; } {
|
||||
inputsFrom = [ quickshell ];
|
||||
|
||||
+6
-1
@@ -11,8 +11,9 @@ add_subdirectory(window)
|
||||
add_subdirectory(io)
|
||||
add_subdirectory(widgets)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(windowmanager)
|
||||
|
||||
if (CRASH_REPORTER)
|
||||
if (CRASH_HANDLER)
|
||||
add_subdirectory(crash)
|
||||
endif()
|
||||
|
||||
@@ -33,3 +34,7 @@ add_subdirectory(services)
|
||||
if (BLUETOOTH)
|
||||
add_subdirectory(bluetooth)
|
||||
endif()
|
||||
|
||||
if (NETWORK)
|
||||
add_subdirectory(network)
|
||||
endif()
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qstring.h>
|
||||
#include <qstringliteral.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../core/logcat.hpp"
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qstring.h>
|
||||
#include <qstringliteral.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
|
||||
@@ -9,16 +9,10 @@ if (NOT DEFINED GIT_REVISION)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CRASH_REPORTER)
|
||||
set(CRASH_REPORTER_DEF 1)
|
||||
if (CRASH_HANDLER)
|
||||
set(CRASH_HANDLER_DEF 1)
|
||||
else()
|
||||
set(CRASH_REPORTER_DEF 0)
|
||||
endif()
|
||||
|
||||
if (DISTRIBUTOR_DEBUGINFO_AVAILABLE)
|
||||
set(DEBUGINFO_AVAILABLE 1)
|
||||
else()
|
||||
set(DEBUGINFO_AVAILABLE 0)
|
||||
set(CRASH_HANDLER_DEF 0)
|
||||
endif()
|
||||
|
||||
configure_file(build.hpp.in build.hpp @ONLY ESCAPE_QUOTES)
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
// NOLINTBEGIN
|
||||
#define QS_VERSION "@quickshell_VERSION@"
|
||||
#define QS_VERSION_MAJOR @quickshell_VERSION_MAJOR@
|
||||
#define QS_VERSION_MINOR @quickshell_VERSION_MINOR@
|
||||
#define QS_VERSION_PATCH @quickshell_VERSION_PATCH@
|
||||
#define QS_UNRELEASED_FEATURES "@UNRELEASED_FEATURES@"
|
||||
#define GIT_REVISION "@GIT_REVISION@"
|
||||
#define DISTRIBUTOR "@DISTRIBUTOR@"
|
||||
#define DISTRIBUTOR_DEBUGINFO_AVAILABLE @DEBUGINFO_AVAILABLE@
|
||||
#define CRASH_REPORTER @CRASH_REPORTER_DEF@
|
||||
#define CRASH_HANDLER @CRASH_HANDLER_DEF@
|
||||
#define BUILD_TYPE "@CMAKE_BUILD_TYPE@"
|
||||
#define COMPILER "@CMAKE_CXX_COMPILER_ID@ (@CMAKE_CXX_COMPILER_VERSION@)"
|
||||
#define COMPILE_FLAGS "@CMAKE_CXX_FLAGS@"
|
||||
#define BUILD_CONFIGURATION "@QS_BUILD_OPTIONS@"
|
||||
#define CRASHREPORT_URL "@CRASHREPORT_URL@"
|
||||
// NOLINTEND
|
||||
@@ -1,3 +1,4 @@
|
||||
pkg_check_modules(libdrm REQUIRED IMPORTED_TARGET libdrm)
|
||||
qt_add_library(quickshell-core STATIC
|
||||
plugin.cpp
|
||||
shell.cpp
|
||||
@@ -12,6 +13,7 @@ qt_add_library(quickshell-core STATIC
|
||||
singleton.cpp
|
||||
generation.cpp
|
||||
scan.cpp
|
||||
scanenv.cpp
|
||||
qsintercept.cpp
|
||||
incubator.cpp
|
||||
lazyloader.cpp
|
||||
@@ -23,7 +25,7 @@ qt_add_library(quickshell-core STATIC
|
||||
model.cpp
|
||||
elapsedtimer.cpp
|
||||
desktopentry.cpp
|
||||
objectrepeater.cpp
|
||||
desktopentrymonitor.cpp
|
||||
platformmenu.cpp
|
||||
qsmenu.cpp
|
||||
retainable.cpp
|
||||
@@ -39,6 +41,8 @@ qt_add_library(quickshell-core STATIC
|
||||
scriptmodel.cpp
|
||||
colorquantizer.cpp
|
||||
toolsupport.cpp
|
||||
streamreader.cpp
|
||||
debuginfo.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(quickshell-core
|
||||
@@ -51,7 +55,7 @@ qt_add_qml_module(quickshell-core
|
||||
|
||||
install_qml_module(quickshell-core)
|
||||
|
||||
target_link_libraries(quickshell-core PRIVATE Qt::Quick Qt::Widgets)
|
||||
target_link_libraries(quickshell-core PRIVATE Qt::Quick Qt::QuickPrivate Qt::Widgets quickshell-build PkgConfig::libdrm)
|
||||
|
||||
qs_module_pch(quickshell-core SET large)
|
||||
|
||||
|
||||
+62
-28
@@ -1,5 +1,6 @@
|
||||
#include "colorquantizer.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <qatomic.h>
|
||||
#include <qcolor.h>
|
||||
@@ -13,6 +14,7 @@
|
||||
#include <qnumeric.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qrect.h>
|
||||
#include <qrgb.h>
|
||||
#include <qthreadpool.h>
|
||||
#include <qtmetamacros.h>
|
||||
@@ -24,30 +26,43 @@ namespace {
|
||||
QS_LOGGING_CATEGORY(logColorQuantizer, "quickshell.colorquantizer", QtWarningMsg);
|
||||
}
|
||||
|
||||
ColorQuantizerOperation::ColorQuantizerOperation(QUrl* source, qreal depth, qreal rescaleSize)
|
||||
: source(source)
|
||||
ColorQuantizerOperation::ColorQuantizerOperation(
|
||||
QUrl source,
|
||||
qreal depth,
|
||||
QRect imageRect,
|
||||
qreal rescaleSize
|
||||
)
|
||||
: source(std::move(source))
|
||||
, maxDepth(depth)
|
||||
, imageRect(imageRect)
|
||||
, rescaleSize(rescaleSize) {
|
||||
setAutoDelete(false);
|
||||
this->setAutoDelete(false);
|
||||
}
|
||||
|
||||
void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCancel) {
|
||||
if (shouldCancel.loadAcquire() || source->isEmpty()) return;
|
||||
if (shouldCancel.loadAcquire() || this->source.isEmpty()) return;
|
||||
|
||||
colors.clear();
|
||||
this->colors.clear();
|
||||
|
||||
auto image = QImage(source->toLocalFile());
|
||||
if ((image.width() > rescaleSize || image.height() > rescaleSize) && rescaleSize > 0) {
|
||||
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)
|
||||
{
|
||||
image = image.scaled(
|
||||
static_cast<int>(rescaleSize),
|
||||
static_cast<int>(rescaleSize),
|
||||
static_cast<int>(this->rescaleSize),
|
||||
static_cast<int>(this->rescaleSize),
|
||||
Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation
|
||||
);
|
||||
}
|
||||
|
||||
if (image.isNull()) {
|
||||
qCWarning(logColorQuantizer) << "Failed to load image from" << source->toString();
|
||||
qCWarning(logColorQuantizer) << "Failed to load image from" << this->source.toString();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,7 +78,7 @@ void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCa
|
||||
|
||||
auto startTime = QDateTime::currentDateTime();
|
||||
|
||||
colors = quantization(pixels, 0);
|
||||
this->colors = this->quantization(pixels, 0);
|
||||
|
||||
auto endTime = QDateTime::currentDateTime();
|
||||
auto milliseconds = startTime.msecsTo(endTime);
|
||||
@@ -77,7 +92,7 @@ QList<QColor> ColorQuantizerOperation::quantization(
|
||||
) {
|
||||
if (shouldCancel.loadAcquire()) return QList<QColor>();
|
||||
|
||||
if (depth >= maxDepth || rgbValues.isEmpty()) {
|
||||
if (depth >= this->maxDepth || rgbValues.isEmpty()) {
|
||||
if (rgbValues.isEmpty()) return QList<QColor>();
|
||||
|
||||
auto totalR = 0;
|
||||
@@ -114,8 +129,8 @@ QList<QColor> ColorQuantizerOperation::quantization(
|
||||
auto rightHalf = rgbValues.mid(mid);
|
||||
|
||||
QList<QColor> result;
|
||||
result.append(quantization(leftHalf, depth + 1));
|
||||
result.append(quantization(rightHalf, depth + 1));
|
||||
result.append(this->quantization(leftHalf, depth + 1));
|
||||
result.append(this->quantization(rightHalf, depth + 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -159,7 +174,7 @@ void ColorQuantizerOperation::finishRun() {
|
||||
}
|
||||
|
||||
void ColorQuantizerOperation::finished() {
|
||||
emit this->done(colors);
|
||||
emit this->done(this->colors);
|
||||
delete this;
|
||||
}
|
||||
|
||||
@@ -177,40 +192,53 @@ void ColorQuantizerOperation::run() {
|
||||
|
||||
void ColorQuantizerOperation::tryCancel() { this->shouldCancel.storeRelease(true); }
|
||||
|
||||
ColorQuantizer::~ColorQuantizer() { this->cancelAsync(); }
|
||||
|
||||
void ColorQuantizer::componentComplete() {
|
||||
componentCompleted = true;
|
||||
if (!mSource.isEmpty()) quantizeAsync();
|
||||
this->componentCompleted = true;
|
||||
if (!this->mSource.isEmpty()) this->quantizeAsync();
|
||||
}
|
||||
|
||||
void ColorQuantizer::setSource(const QUrl& source) {
|
||||
if (mSource != source) {
|
||||
mSource = source;
|
||||
if (this->mSource != source) {
|
||||
this->mSource = source;
|
||||
emit this->sourceChanged();
|
||||
|
||||
if (this->componentCompleted && !mSource.isEmpty()) quantizeAsync();
|
||||
if (this->componentCompleted && !this->mSource.isEmpty()) this->quantizeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void ColorQuantizer::setDepth(qreal depth) {
|
||||
if (mDepth != depth) {
|
||||
mDepth = depth;
|
||||
if (this->mDepth != depth) {
|
||||
this->mDepth = depth;
|
||||
emit this->depthChanged();
|
||||
|
||||
if (this->componentCompleted) 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 (mRescaleSize != rescaleSize) {
|
||||
mRescaleSize = rescaleSize;
|
||||
if (this->mRescaleSize != rescaleSize) {
|
||||
this->mRescaleSize = rescaleSize;
|
||||
emit this->rescaleSizeChanged();
|
||||
|
||||
if (this->componentCompleted) quantizeAsync();
|
||||
if (this->componentCompleted && !this->mSource.isEmpty()) this->quantizeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void ColorQuantizer::operationFinished(const QList<QColor>& result) {
|
||||
bColors = result;
|
||||
this->bColors = result;
|
||||
this->liveOperation = nullptr;
|
||||
emit this->colorsChanged();
|
||||
}
|
||||
@@ -219,7 +247,13 @@ void ColorQuantizer::quantizeAsync() {
|
||||
if (this->liveOperation) this->cancelAsync();
|
||||
|
||||
qCDebug(logColorQuantizer) << "Starting color quantization asynchronously";
|
||||
this->liveOperation = new ColorQuantizerOperation(&mSource, mDepth, mRescaleSize);
|
||||
|
||||
this->liveOperation = new ColorQuantizerOperation(
|
||||
this->mSource,
|
||||
this->mDepth,
|
||||
this->mImageRect,
|
||||
this->mRescaleSize
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->liveOperation,
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <qproperty.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qqmlparserstatus.h>
|
||||
#include <qrect.h>
|
||||
#include <qrunnable.h>
|
||||
#include <qtclasshelpermacros.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qurl.h>
|
||||
@@ -16,7 +18,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();
|
||||
@@ -42,8 +44,9 @@ private:
|
||||
|
||||
QAtomicInteger<bool> shouldCancel = false;
|
||||
QList<QColor> colors;
|
||||
QUrl* source;
|
||||
QUrl source;
|
||||
qreal maxDepth;
|
||||
QRect imageRect;
|
||||
qreal rescaleSize;
|
||||
};
|
||||
|
||||
@@ -78,32 +81,46 @@ 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.
|
||||
/// > recommended to rescale, otherwise the quantization process will take much longer.
|
||||
Q_PROPERTY(qreal rescaleSize READ rescaleSize WRITE setRescaleSize NOTIFY rescaleSizeChanged);
|
||||
|
||||
public:
|
||||
explicit ColorQuantizer(QObject* parent = nullptr): QObject(parent) {}
|
||||
~ColorQuantizer() override;
|
||||
Q_DISABLE_COPY_MOVE(ColorQuantizer);
|
||||
|
||||
void componentComplete() override;
|
||||
void classBegin() override {}
|
||||
|
||||
[[nodiscard]] QBindable<QList<QColor>> bindableColors() { return &this->bColors; }
|
||||
|
||||
[[nodiscard]] QUrl source() const { return mSource; }
|
||||
[[nodiscard]] QUrl source() const { return this->mSource; }
|
||||
void setSource(const QUrl& source);
|
||||
|
||||
[[nodiscard]] qreal depth() const { return mDepth; }
|
||||
[[nodiscard]] qreal depth() const { return this->mDepth; }
|
||||
void setDepth(qreal depth);
|
||||
|
||||
[[nodiscard]] qreal rescaleSize() const { return mRescaleSize; }
|
||||
[[nodiscard]] QRect imageRect() const { return this->mImageRect; }
|
||||
void setImageRect(QRect imageRect);
|
||||
void resetImageRect();
|
||||
|
||||
[[nodiscard]] qreal rescaleSize() const { return this->mRescaleSize; }
|
||||
void setRescaleSize(int rescaleSize);
|
||||
|
||||
signals:
|
||||
void colorsChanged();
|
||||
void sourceChanged();
|
||||
void depthChanged();
|
||||
void imageRectChanged();
|
||||
void rescaleSizeChanged();
|
||||
|
||||
public slots:
|
||||
@@ -117,6 +134,7 @@ private:
|
||||
ColorQuantizerOperation* liveOperation = nullptr;
|
||||
QUrl mSource;
|
||||
qreal mDepth = 0;
|
||||
QRect mImageRect;
|
||||
qreal mRescaleSize = 0;
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
#include "debuginfo.hpp"
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <string_view>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <qconfig.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdebug.h>
|
||||
#include <qfile.h>
|
||||
#include <qfloat16.h>
|
||||
#include <qhashfunctions.h>
|
||||
#include <qscopeguard.h>
|
||||
#include <qtversion.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
|
||||
#include "build.hpp"
|
||||
|
||||
extern char** environ; // NOLINT
|
||||
|
||||
namespace qs::debuginfo {
|
||||
|
||||
QString qsVersion() {
|
||||
return QS_VERSION " (revision " GIT_REVISION ", distributed by " DISTRIBUTOR ")";
|
||||
}
|
||||
|
||||
QString qtVersion() { return qVersion() % QStringLiteral(" (built against " QT_VERSION_STR ")"); }
|
||||
|
||||
QString gpuInfo() {
|
||||
auto deviceCount = drmGetDevices2(0, nullptr, 0);
|
||||
if (deviceCount < 0) return "Failed to get DRM device count: " % QString::number(deviceCount);
|
||||
auto* devices = new drmDevicePtr[deviceCount];
|
||||
auto devicesArrayGuard = qScopeGuard([&] { delete[] devices; });
|
||||
auto r = drmGetDevices2(0, devices, deviceCount);
|
||||
if (deviceCount < 0) return "Failed to get DRM devices: " % QString::number(r);
|
||||
auto devicesGuard = qScopeGuard([&] {
|
||||
for (auto i = 0; i != deviceCount; ++i) drmFreeDevice(&devices[i]); // NOLINT
|
||||
});
|
||||
|
||||
QString info;
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
for (auto i = 0; i != deviceCount; ++i) {
|
||||
auto* device = devices[i]; // NOLINT
|
||||
|
||||
int deviceNodeType = -1;
|
||||
if (device->available_nodes & (1 << DRM_NODE_RENDER)) deviceNodeType = DRM_NODE_RENDER;
|
||||
else if (device->available_nodes & (1 << DRM_NODE_PRIMARY)) deviceNodeType = DRM_NODE_PRIMARY;
|
||||
|
||||
if (deviceNodeType == -1) continue;
|
||||
|
||||
auto* deviceNode = device->nodes[DRM_NODE_RENDER]; // NOLINT
|
||||
|
||||
auto driver = [&]() -> QString {
|
||||
auto fd = open(deviceNode, O_RDWR | O_CLOEXEC);
|
||||
if (fd == -1) return "<failed to open device node>";
|
||||
auto fdGuard = qScopeGuard([&] { close(fd); });
|
||||
auto* ver = drmGetVersion(fd);
|
||||
if (!ver) return "<drmGetVersion failed>";
|
||||
auto verGuard = qScopeGuard([&] { drmFreeVersion(ver); });
|
||||
|
||||
// clang-format off
|
||||
return QString(ver->name)
|
||||
% ' ' % QString::number(ver->version_major)
|
||||
% '.' % QString::number(ver->version_minor)
|
||||
% '.' % QString::number(ver->version_patchlevel)
|
||||
% " (" % ver->desc % ')';
|
||||
// clang-format on
|
||||
}();
|
||||
|
||||
QString product = "unknown";
|
||||
QString address = "unknown";
|
||||
|
||||
auto hex = [](int num, int pad) { return QString::number(num, 16).rightJustified(pad, '0'); };
|
||||
|
||||
switch (device->bustype) {
|
||||
case DRM_BUS_PCI: {
|
||||
auto* b = device->businfo.pci;
|
||||
auto* d = device->deviceinfo.pci;
|
||||
address = "PCI " % hex(b->bus, 2) % ':' % hex(b->dev, 2) % '.' % hex(b->func, 1);
|
||||
product = hex(d->vendor_id, 4) % ':' % hex(d->device_id, 4);
|
||||
} break;
|
||||
case DRM_BUS_USB: {
|
||||
auto* b = device->businfo.usb;
|
||||
auto* d = device->deviceinfo.usb;
|
||||
address = "USB " % QString::number(b->bus) % ':' % QString::number(b->dev);
|
||||
product = hex(d->vendor, 4) % ':' % hex(d->product, 4);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
stream << "GPU " << deviceNode << "\n Driver: " << driver << "\n Model: " << product
|
||||
<< "\n Address: " << address << '\n';
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
QString systemInfo() {
|
||||
QString info;
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
stream << gpuInfo() << '\n';
|
||||
|
||||
stream << "/etc/os-release:";
|
||||
auto osReleaseFile = QFile("/etc/os-release");
|
||||
if (osReleaseFile.open(QFile::ReadOnly)) {
|
||||
stream << '\n' << osReleaseFile.readAll() << '\n';
|
||||
osReleaseFile.close();
|
||||
} else {
|
||||
stream << "FAILED TO OPEN\n";
|
||||
}
|
||||
|
||||
stream << "/etc/lsb-release:";
|
||||
auto lsbReleaseFile = QFile("/etc/lsb-release");
|
||||
if (lsbReleaseFile.open(QFile::ReadOnly)) {
|
||||
stream << '\n' << lsbReleaseFile.readAll();
|
||||
lsbReleaseFile.close();
|
||||
} else {
|
||||
stream << "FAILED TO OPEN\n";
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
QString envInfo() {
|
||||
QString info;
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
for (auto** envp = environ; *envp != nullptr; ++envp) { // NOLINT
|
||||
auto prefixes = std::array<std::string_view, 6> {
|
||||
"QS_",
|
||||
"QT_",
|
||||
"QML_",
|
||||
"QML2_",
|
||||
"QSG_",
|
||||
"XDG_CURRENT_DESKTOP=",
|
||||
};
|
||||
|
||||
for (const auto& prefix: prefixes) {
|
||||
if (strncmp(prefix.data(), *envp, prefix.length()) == 0) goto print;
|
||||
}
|
||||
continue;
|
||||
|
||||
print:
|
||||
stream << *envp << '\n';
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
QString combinedInfo() {
|
||||
QString info;
|
||||
auto stream = QTextStream(&info);
|
||||
|
||||
stream << "===== Version Information =====\n";
|
||||
stream << "Quickshell: " << qsVersion() << '\n';
|
||||
stream << "Qt: " << qtVersion() << '\n';
|
||||
|
||||
stream << "\n===== Build Information =====\n";
|
||||
stream << "Build Type: " << BUILD_TYPE << '\n';
|
||||
stream << "Compiler: " << COMPILER << '\n';
|
||||
stream << "Compile Flags: " << COMPILE_FLAGS << '\n';
|
||||
stream << "Configuration:\n" << BUILD_CONFIGURATION << '\n';
|
||||
|
||||
stream << "\n===== System Information =====\n";
|
||||
stream << systemInfo();
|
||||
|
||||
stream << "\n===== Environment (trimmed) =====\n";
|
||||
stream << envInfo();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace qs::debuginfo
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
|
||||
namespace qs::debuginfo {
|
||||
|
||||
QString qsVersion();
|
||||
QString qtVersion();
|
||||
QString gpuInfo();
|
||||
QString systemInfo();
|
||||
QString envInfo();
|
||||
QString combinedInfo();
|
||||
|
||||
} // namespace qs::debuginfo
|
||||
+314
-126
@@ -1,22 +1,27 @@
|
||||
#include "desktopentry.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdebug.h>
|
||||
#include <qdir.h>
|
||||
#include <qfile.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qhash.h>
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qpair.h>
|
||||
#include <qstringview.h>
|
||||
#include <qproperty.h>
|
||||
#include <qscopeguard.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qthreadpool.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <ranges>
|
||||
|
||||
#include "../io/processcore.hpp"
|
||||
#include "desktopentrymonitor.hpp"
|
||||
#include "logcat.hpp"
|
||||
#include "model.hpp"
|
||||
#include "qmlglobal.hpp"
|
||||
@@ -56,12 +61,14 @@ struct Locale {
|
||||
|
||||
[[nodiscard]] int matchScore(const Locale& other) const {
|
||||
if (this->language != other.language) return 0;
|
||||
auto territoryMatches = !this->territory.isEmpty() && this->territory == other.territory;
|
||||
auto modifierMatches = !this->modifier.isEmpty() && this->modifier == other.modifier;
|
||||
|
||||
if (!other.modifier.isEmpty() && this->modifier != other.modifier) return 0;
|
||||
if (!other.territory.isEmpty() && this->territory != other.territory) return 0;
|
||||
|
||||
auto score = 1;
|
||||
if (territoryMatches) score += 2;
|
||||
if (modifierMatches) score += 1;
|
||||
|
||||
if (!other.territory.isEmpty()) score += 2;
|
||||
if (!other.modifier.isEmpty()) score += 1;
|
||||
|
||||
return score;
|
||||
}
|
||||
@@ -87,57 +94,64 @@ struct Locale {
|
||||
QDebug operator<<(QDebug debug, const Locale& locale) {
|
||||
auto saver = QDebugStateSaver(debug);
|
||||
debug.nospace() << "Locale(language=" << locale.language << ", territory=" << locale.territory
|
||||
<< ", modifier" << locale.modifier << ')';
|
||||
<< ", modifier=" << locale.modifier << ')';
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
void DesktopEntry::parseEntry(const QString& text) {
|
||||
ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString& text) {
|
||||
ParsedDesktopEntryData data;
|
||||
data.id = id;
|
||||
const auto& system = Locale::system();
|
||||
|
||||
auto groupName = QString();
|
||||
auto entries = QHash<QString, QPair<Locale, QString>>();
|
||||
|
||||
auto finishCategory = [this, &groupName, &entries]() {
|
||||
auto actionOrder = QStringList();
|
||||
auto pendingActions = QHash<QString, DesktopActionData>();
|
||||
|
||||
auto finishCategory = [&data, &groupName, &entries, &actionOrder, &pendingActions]() {
|
||||
if (groupName == "Desktop Entry") {
|
||||
if (entries["Type"].second != "Application") return;
|
||||
if (entries.contains("Hidden") && entries["Hidden"].second == "true") return;
|
||||
if (entries.value("Type").second != "Application") return;
|
||||
|
||||
for (const auto& [key, pair]: entries.asKeyValueRange()) {
|
||||
auto& [_, value] = pair;
|
||||
this->mEntries.insert(key, value);
|
||||
data.entries.insert(key, value);
|
||||
|
||||
if (key == "Name") this->mName = value;
|
||||
else if (key == "GenericName") this->mGenericName = value;
|
||||
else if (key == "StartupWMClass") this->mStartupClass = value;
|
||||
else if (key == "NoDisplay") this->mNoDisplay = value == "true";
|
||||
else if (key == "Comment") this->mComment = value;
|
||||
else if (key == "Icon") this->mIcon = value;
|
||||
if (key == "Name") data.name = value;
|
||||
else if (key == "GenericName") data.genericName = value;
|
||||
else if (key == "StartupWMClass") data.startupClass = value;
|
||||
else if (key == "NoDisplay") data.noDisplay = value == "true";
|
||||
else if (key == "Hidden") data.hidden = value == "true";
|
||||
else if (key == "Comment") data.comment = value;
|
||||
else if (key == "Icon") data.icon = value;
|
||||
else if (key == "Exec") {
|
||||
this->mExecString = value;
|
||||
this->mCommand = DesktopEntry::parseExecString(value);
|
||||
} else if (key == "Path") this->mWorkingDirectory = value;
|
||||
else if (key == "Terminal") this->mTerminal = value == "true";
|
||||
else if (key == "Categories") this->mCategories = value.split(u';', Qt::SkipEmptyParts);
|
||||
else if (key == "Keywords") this->mKeywords = value.split(u';', Qt::SkipEmptyParts);
|
||||
data.execString = value;
|
||||
data.command = DesktopEntry::parseExecString(value);
|
||||
} else if (key == "Path") data.workingDirectory = value;
|
||||
else if (key == "Terminal") data.terminal = value == "true";
|
||||
else if (key == "Categories") data.categories = value.split(u';', Qt::SkipEmptyParts);
|
||||
else if (key == "Keywords") data.keywords = value.split(u';', Qt::SkipEmptyParts);
|
||||
else if (key == "Actions") actionOrder = value.split(u';', Qt::SkipEmptyParts);
|
||||
}
|
||||
} else if (groupName.startsWith("Desktop Action ")) {
|
||||
auto actionName = groupName.sliced(16);
|
||||
auto* action = new DesktopAction(actionName, this);
|
||||
auto actionName = groupName.sliced(15);
|
||||
DesktopActionData action;
|
||||
action.id = actionName;
|
||||
|
||||
for (const auto& [key, pair]: entries.asKeyValueRange()) {
|
||||
const auto& [_, value] = pair;
|
||||
action->mEntries.insert(key, value);
|
||||
action.entries.insert(key, value);
|
||||
|
||||
if (key == "Name") action->mName = value;
|
||||
else if (key == "Icon") action->mIcon = value;
|
||||
if (key == "Name") action.name = value;
|
||||
else if (key == "Icon") action.icon = value;
|
||||
else if (key == "Exec") {
|
||||
action->mExecString = value;
|
||||
action->mCommand = DesktopEntry::parseExecString(value);
|
||||
action.execString = value;
|
||||
action.command = DesktopEntry::parseExecString(value);
|
||||
}
|
||||
}
|
||||
|
||||
this->mActions.insert(actionName, action);
|
||||
pendingActions.insert(actionName, action);
|
||||
}
|
||||
|
||||
entries.clear();
|
||||
@@ -183,16 +197,73 @@ void DesktopEntry::parseEntry(const QString& text) {
|
||||
}
|
||||
|
||||
finishCategory();
|
||||
|
||||
for (const auto& actionId: actionOrder) {
|
||||
if (pendingActions.contains(actionId)) {
|
||||
data.actions.append(pendingActions.value(actionId));
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void DesktopEntry::updateState(const ParsedDesktopEntryData& newState) {
|
||||
Qt::beginPropertyUpdateGroup();
|
||||
this->bName = newState.name;
|
||||
this->bGenericName = newState.genericName;
|
||||
this->bStartupClass = newState.startupClass;
|
||||
this->bNoDisplay = newState.noDisplay;
|
||||
this->bComment = newState.comment;
|
||||
this->bIcon = newState.icon;
|
||||
this->bExecString = newState.execString;
|
||||
this->bCommand = newState.command;
|
||||
this->bWorkingDirectory = newState.workingDirectory;
|
||||
this->bRunInTerminal = newState.terminal;
|
||||
this->bCategories = newState.categories;
|
||||
this->bKeywords = newState.keywords;
|
||||
Qt::endPropertyUpdateGroup();
|
||||
|
||||
this->state = newState;
|
||||
this->updateActions(newState.actions);
|
||||
}
|
||||
|
||||
void DesktopEntry::updateActions(const QVector<DesktopActionData>& newActions) {
|
||||
auto old = this->mActions;
|
||||
this->mActions.clear();
|
||||
|
||||
for (const auto& d: newActions) {
|
||||
DesktopAction* act = nullptr;
|
||||
auto found = std::ranges::find(old, d.id, &DesktopAction::mId);
|
||||
if (found != old.end()) {
|
||||
act = *found;
|
||||
old.erase(found);
|
||||
} else {
|
||||
act = new DesktopAction(d.id, this);
|
||||
}
|
||||
|
||||
Qt::beginPropertyUpdateGroup();
|
||||
act->bName = d.name;
|
||||
act->bIcon = d.icon;
|
||||
act->bExecString = d.execString;
|
||||
act->bCommand = d.command;
|
||||
Qt::endPropertyUpdateGroup();
|
||||
|
||||
act->mEntries = d.entries;
|
||||
this->mActions.append(act);
|
||||
}
|
||||
|
||||
for (auto* leftover: old) {
|
||||
leftover->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void DesktopEntry::execute() const {
|
||||
DesktopEntry::doExec(this->mCommand, this->mWorkingDirectory);
|
||||
DesktopEntry::doExec(this->bCommand.value(), this->bWorkingDirectory.value());
|
||||
}
|
||||
|
||||
bool DesktopEntry::isValid() const { return !this->mName.isEmpty(); }
|
||||
bool DesktopEntry::noDisplay() const { return this->mNoDisplay; }
|
||||
bool DesktopEntry::isValid() const { return !this->bName.value().isEmpty(); }
|
||||
|
||||
QVector<DesktopAction*> DesktopEntry::actions() const { return this->mActions.values(); }
|
||||
QVector<DesktopAction*> DesktopEntry::actions() const { return this->mActions; }
|
||||
|
||||
QVector<QString> DesktopEntry::parseExecString(const QString& execString) {
|
||||
QVector<QString> arguments;
|
||||
@@ -211,16 +282,22 @@ QVector<QString> DesktopEntry::parseExecString(const QString& execString) {
|
||||
currentArgument += '\\';
|
||||
escape = 0;
|
||||
}
|
||||
} else if (escape == 2) {
|
||||
currentArgument += c;
|
||||
escape = 0;
|
||||
} else if (escape != 0) {
|
||||
if (escape != 2) {
|
||||
// Technically this is an illegal state, but the spec has a terrible double escape
|
||||
// rule in strings for no discernable reason. Assuming someone might understandably
|
||||
// misunderstand it, treat it as a normal escape and log it.
|
||||
switch (c.unicode()) {
|
||||
case 's': currentArgument += u' '; break;
|
||||
case 'n': currentArgument += u'\n'; break;
|
||||
case 't': currentArgument += u'\t'; break;
|
||||
case 'r': currentArgument += u'\r'; break;
|
||||
case '\\': currentArgument += u'\\'; break;
|
||||
default:
|
||||
qCWarning(logDesktopEntry).noquote()
|
||||
<< "Illegal escape sequence in desktop entry exec string:" << execString;
|
||||
currentArgument += c;
|
||||
break;
|
||||
}
|
||||
|
||||
currentArgument += c;
|
||||
escape = 0;
|
||||
} else if (c == u'"' || c == u'\'') {
|
||||
parsingString = false;
|
||||
@@ -266,59 +343,44 @@ void DesktopEntry::doExec(const QList<QString>& execString, const QString& worki
|
||||
}
|
||||
|
||||
void DesktopAction::execute() const {
|
||||
DesktopEntry::doExec(this->mCommand, this->entry->mWorkingDirectory);
|
||||
DesktopEntry::doExec(this->bCommand.value(), this->entry->bWorkingDirectory.value());
|
||||
}
|
||||
|
||||
DesktopEntryManager::DesktopEntryManager() {
|
||||
this->scanDesktopEntries();
|
||||
this->populateApplications();
|
||||
DesktopEntryScanner::DesktopEntryScanner(DesktopEntryManager* manager): manager(manager) {
|
||||
this->setAutoDelete(true);
|
||||
}
|
||||
|
||||
void DesktopEntryManager::scanDesktopEntries() {
|
||||
QList<QString> dataPaths;
|
||||
void DesktopEntryScanner::run() {
|
||||
const auto& desktopPaths = DesktopEntryManager::desktopPaths();
|
||||
auto scanResults = QList<ParsedDesktopEntryData>();
|
||||
|
||||
if (qEnvironmentVariableIsSet("XDG_DATA_HOME")) {
|
||||
dataPaths.push_back(qEnvironmentVariable("XDG_DATA_HOME"));
|
||||
} else if (qEnvironmentVariableIsSet("HOME")) {
|
||||
dataPaths.push_back(qEnvironmentVariable("HOME") + "/.local/share");
|
||||
for (const auto& path: desktopPaths | std::views::reverse) {
|
||||
auto file = QFileInfo(path);
|
||||
if (!file.isDir()) continue;
|
||||
|
||||
this->scanDirectory(QDir(path), QString(), scanResults);
|
||||
}
|
||||
|
||||
if (qEnvironmentVariableIsSet("XDG_DATA_DIRS")) {
|
||||
auto var = qEnvironmentVariable("XDG_DATA_DIRS");
|
||||
dataPaths += var.split(u':', Qt::SkipEmptyParts);
|
||||
} else {
|
||||
dataPaths.push_back("/usr/local/share");
|
||||
dataPaths.push_back("/usr/share");
|
||||
}
|
||||
|
||||
qCDebug(logDesktopEntry) << "Creating desktop entry scanners";
|
||||
|
||||
for (auto& path: std::ranges::reverse_view(dataPaths)) {
|
||||
auto p = QDir(path).filePath("applications");
|
||||
auto file = QFileInfo(p);
|
||||
|
||||
if (!file.isDir()) {
|
||||
qCDebug(logDesktopEntry) << "Not scanning path" << p << "as it is not a directory";
|
||||
continue;
|
||||
}
|
||||
|
||||
qCDebug(logDesktopEntry) << "Scanning path" << p;
|
||||
this->scanPath(p);
|
||||
}
|
||||
QMetaObject::invokeMethod(
|
||||
this->manager,
|
||||
"onScanCompleted",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(QList<ParsedDesktopEntryData>, scanResults)
|
||||
);
|
||||
}
|
||||
|
||||
void DesktopEntryManager::populateApplications() {
|
||||
for (auto& entry: this->desktopEntries.values()) {
|
||||
if (!entry->noDisplay()) this->mApplications.insertObject(entry);
|
||||
}
|
||||
}
|
||||
void DesktopEntryScanner::scanDirectory(
|
||||
const QDir& dir,
|
||||
const QString& idPrefix,
|
||||
QList<ParsedDesktopEntryData>& entries
|
||||
) {
|
||||
auto dirEntries = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
|
||||
void DesktopEntryManager::scanPath(const QDir& dir, const QString& prefix) {
|
||||
auto entries = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
|
||||
for (auto& entry: entries) {
|
||||
if (entry.isDir()) this->scanPath(entry.absoluteFilePath(), prefix + dir.dirName() + "-");
|
||||
else if (entry.isFile()) {
|
||||
for (auto& entry: dirEntries) {
|
||||
if (entry.isDir()) {
|
||||
auto subdirPrefix = idPrefix.isEmpty() ? entry.fileName() : idPrefix + '-' + entry.fileName();
|
||||
this->scanDirectory(QDir(entry.absoluteFilePath()), subdirPrefix, entries);
|
||||
} else if (entry.isFile()) {
|
||||
auto path = entry.filePath();
|
||||
if (!path.endsWith(".desktop")) {
|
||||
qCDebug(logDesktopEntry) << "Skipping file" << path << "as it has no .desktop extension";
|
||||
@@ -331,46 +393,42 @@ void DesktopEntryManager::scanPath(const QDir& dir, const QString& prefix) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto id = prefix + entry.fileName().sliced(0, entry.fileName().length() - 8);
|
||||
auto lowerId = id.toLower();
|
||||
auto basename = QFileInfo(entry.fileName()).completeBaseName();
|
||||
auto id = idPrefix.isEmpty() ? basename : idPrefix + '-' + basename;
|
||||
auto content = QString::fromUtf8(file.readAll());
|
||||
|
||||
auto text = QString::fromUtf8(file.readAll());
|
||||
auto* dentry = new DesktopEntry(id, this);
|
||||
dentry->parseEntry(text);
|
||||
|
||||
if (!dentry->isValid()) {
|
||||
qCDebug(logDesktopEntry) << "Skipping desktop entry" << path;
|
||||
delete dentry;
|
||||
continue;
|
||||
}
|
||||
|
||||
qCDebug(logDesktopEntry) << "Found desktop entry" << id << "at" << path;
|
||||
|
||||
auto conflictingId = this->desktopEntries.contains(id);
|
||||
|
||||
if (conflictingId) {
|
||||
qCDebug(logDesktopEntry) << "Replacing old entry for" << id;
|
||||
delete this->desktopEntries.value(id);
|
||||
this->desktopEntries.remove(id);
|
||||
this->lowercaseDesktopEntries.remove(lowerId);
|
||||
}
|
||||
|
||||
this->desktopEntries.insert(id, dentry);
|
||||
|
||||
if (this->lowercaseDesktopEntries.contains(lowerId)) {
|
||||
qCInfo(logDesktopEntry).nospace()
|
||||
<< "Multiple desktop entries have the same lowercased id " << lowerId
|
||||
<< ". This can cause ambiguity when byId requests are not made with the correct case "
|
||||
"already.";
|
||||
|
||||
this->lowercaseDesktopEntries.remove(lowerId);
|
||||
}
|
||||
|
||||
this->lowercaseDesktopEntries.insert(lowerId, dentry);
|
||||
auto data = DesktopEntry::parseText(id, content);
|
||||
entries.append(std::move(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DesktopEntryManager::DesktopEntryManager(): monitor(new DesktopEntryMonitor(this)) {
|
||||
QObject::connect(
|
||||
this->monitor,
|
||||
&DesktopEntryMonitor::desktopEntriesChanged,
|
||||
this,
|
||||
&DesktopEntryManager::handleFileChanges
|
||||
);
|
||||
|
||||
DesktopEntryScanner(this).run();
|
||||
}
|
||||
|
||||
void DesktopEntryManager::scanDesktopEntries() {
|
||||
qCDebug(logDesktopEntry) << "Starting desktop entry scan";
|
||||
|
||||
if (this->scanInProgress) {
|
||||
qCDebug(logDesktopEntry) << "Scan already in progress, queuing another scan";
|
||||
this->scanQueued = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this->scanInProgress = true;
|
||||
this->scanQueued = false;
|
||||
auto* scanner = new DesktopEntryScanner(this);
|
||||
QThreadPool::globalInstance()->start(scanner);
|
||||
}
|
||||
|
||||
DesktopEntryManager* DesktopEntryManager::instance() {
|
||||
static auto* instance = new DesktopEntryManager(); // NOLINT
|
||||
return instance;
|
||||
@@ -391,14 +449,14 @@ DesktopEntry* DesktopEntryManager::heuristicLookup(const QString& name) {
|
||||
|
||||
auto list = this->desktopEntries.values();
|
||||
|
||||
auto iter = std::ranges::find_if(list, [&](const DesktopEntry* entry) {
|
||||
return name == entry->mStartupClass;
|
||||
auto iter = std::ranges::find_if(list, [&](DesktopEntry* entry) {
|
||||
return name == entry->bStartupClass.value();
|
||||
});
|
||||
|
||||
if (iter != list.end()) return *iter;
|
||||
|
||||
iter = std::ranges::find_if(list, [&](const DesktopEntry* entry) {
|
||||
return name.toLower() == entry->mStartupClass.toLower();
|
||||
iter = std::ranges::find_if(list, [&](DesktopEntry* entry) {
|
||||
return name.toLower() == entry->bStartupClass.value().toLower();
|
||||
});
|
||||
|
||||
if (iter != list.end()) return *iter;
|
||||
@@ -407,7 +465,137 @@ DesktopEntry* DesktopEntryManager::heuristicLookup(const QString& name) {
|
||||
|
||||
ObjectModel<DesktopEntry>* DesktopEntryManager::applications() { return &this->mApplications; }
|
||||
|
||||
DesktopEntries::DesktopEntries() { DesktopEntryManager::instance(); }
|
||||
void DesktopEntryManager::handleFileChanges() {
|
||||
qCDebug(logDesktopEntry) << "Directory change detected, performing full rescan";
|
||||
|
||||
if (this->scanInProgress) {
|
||||
qCDebug(logDesktopEntry) << "Scan already in progress, queuing another scan";
|
||||
this->scanQueued = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this->scanInProgress = true;
|
||||
this->scanQueued = false;
|
||||
auto* scanner = new DesktopEntryScanner(this);
|
||||
QThreadPool::globalInstance()->start(scanner);
|
||||
}
|
||||
|
||||
const QStringList& DesktopEntryManager::desktopPaths() {
|
||||
static const auto paths = []() {
|
||||
auto dataPaths = QStringList();
|
||||
|
||||
auto dataHome = qEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (dataHome.isEmpty() && qEnvironmentVariableIsSet("HOME"))
|
||||
dataHome = qEnvironmentVariable("HOME") + "/.local/share";
|
||||
if (!dataHome.isEmpty()) dataPaths.append(dataHome + "/applications");
|
||||
|
||||
auto dataDirs = qEnvironmentVariable("XDG_DATA_DIRS");
|
||||
if (dataDirs.isEmpty()) dataDirs = "/usr/local/share:/usr/share";
|
||||
|
||||
for (const auto& dir: dataDirs.split(':', Qt::SkipEmptyParts)) {
|
||||
dataPaths.append(dir + "/applications");
|
||||
}
|
||||
|
||||
return dataPaths;
|
||||
}();
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& scanResults) {
|
||||
auto guard = qScopeGuard([this] {
|
||||
this->scanInProgress = false;
|
||||
if (this->scanQueued) {
|
||||
this->scanQueued = false;
|
||||
this->scanDesktopEntries();
|
||||
}
|
||||
});
|
||||
|
||||
auto oldEntries = this->desktopEntries;
|
||||
auto newEntries = QHash<QString, DesktopEntry*>();
|
||||
auto newLowercaseEntries = QHash<QString, DesktopEntry*>();
|
||||
|
||||
for (const auto& data: scanResults) {
|
||||
auto lowerId = data.id.toLower();
|
||||
|
||||
if (data.hidden) {
|
||||
if (auto* victim = newEntries.take(data.id)) victim->deleteLater();
|
||||
newLowercaseEntries.remove(lowerId);
|
||||
|
||||
if (auto it = oldEntries.find(data.id); it != oldEntries.end()) {
|
||||
it.value()->deleteLater();
|
||||
oldEntries.erase(it);
|
||||
}
|
||||
|
||||
qCDebug(logDesktopEntry) << "Masking hidden desktop entry" << data.id;
|
||||
continue;
|
||||
}
|
||||
|
||||
DesktopEntry* dentry = nullptr;
|
||||
|
||||
if (auto it = oldEntries.find(data.id); it != oldEntries.end()) {
|
||||
dentry = it.value();
|
||||
oldEntries.erase(it);
|
||||
dentry->updateState(data);
|
||||
} else {
|
||||
dentry = new DesktopEntry(data.id, this);
|
||||
dentry->updateState(data);
|
||||
}
|
||||
|
||||
if (!dentry->isValid()) {
|
||||
qCDebug(logDesktopEntry) << "Skipping desktop entry" << data.id;
|
||||
if (!oldEntries.contains(data.id)) {
|
||||
dentry->deleteLater();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
qCDebug(logDesktopEntry) << "Found desktop entry" << data.id;
|
||||
|
||||
auto conflictingId = newEntries.contains(data.id);
|
||||
|
||||
if (conflictingId) {
|
||||
qCDebug(logDesktopEntry) << "Replacing old entry for" << data.id;
|
||||
if (auto* victim = newEntries.take(data.id)) victim->deleteLater();
|
||||
newLowercaseEntries.remove(lowerId);
|
||||
}
|
||||
|
||||
newEntries.insert(data.id, dentry);
|
||||
|
||||
if (newLowercaseEntries.contains(lowerId)) {
|
||||
qCInfo(logDesktopEntry).nospace()
|
||||
<< "Multiple desktop entries have the same lowercased id " << lowerId
|
||||
<< ". This can cause ambiguity when byId requests are not made with the correct case "
|
||||
"already.";
|
||||
|
||||
newLowercaseEntries.remove(lowerId);
|
||||
}
|
||||
|
||||
newLowercaseEntries.insert(lowerId, dentry);
|
||||
}
|
||||
|
||||
this->desktopEntries = newEntries;
|
||||
this->lowercaseDesktopEntries = newLowercaseEntries;
|
||||
|
||||
auto newApplications = QVector<DesktopEntry*>();
|
||||
for (auto* entry: this->desktopEntries.values())
|
||||
if (!entry->bNoDisplay) newApplications.append(entry);
|
||||
|
||||
this->mApplications.diffUpdate(newApplications);
|
||||
|
||||
emit this->applicationsChanged();
|
||||
|
||||
for (auto* e: oldEntries) e->deleteLater();
|
||||
}
|
||||
|
||||
DesktopEntries::DesktopEntries() {
|
||||
QObject::connect(
|
||||
DesktopEntryManager::instance(),
|
||||
&DesktopEntryManager::applicationsChanged,
|
||||
this,
|
||||
&DesktopEntries::applicationsChanged
|
||||
);
|
||||
}
|
||||
|
||||
DesktopEntry* DesktopEntries::byId(const QString& id) {
|
||||
return DesktopEntryManager::instance()->byId(id);
|
||||
|
||||
+154
-39
@@ -6,35 +6,68 @@
|
||||
#include <qdir.h>
|
||||
#include <qhash.h>
|
||||
#include <qobject.h>
|
||||
#include <qproperty.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qrunnable.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "desktopentrymonitor.hpp"
|
||||
#include "doc.hpp"
|
||||
#include "model.hpp"
|
||||
|
||||
class DesktopAction;
|
||||
class DesktopEntryMonitor;
|
||||
|
||||
struct DesktopActionData {
|
||||
QString id;
|
||||
QString name;
|
||||
QString icon;
|
||||
QString execString;
|
||||
QVector<QString> command;
|
||||
QHash<QString, QString> entries;
|
||||
};
|
||||
|
||||
struct ParsedDesktopEntryData {
|
||||
QString id;
|
||||
QString name;
|
||||
QString genericName;
|
||||
QString startupClass;
|
||||
bool noDisplay = false;
|
||||
bool hidden = false;
|
||||
QString comment;
|
||||
QString icon;
|
||||
QString execString;
|
||||
QVector<QString> command;
|
||||
QString workingDirectory;
|
||||
bool terminal = false;
|
||||
QVector<QString> categories;
|
||||
QVector<QString> keywords;
|
||||
QHash<QString, QString> entries;
|
||||
QVector<DesktopActionData> actions;
|
||||
};
|
||||
|
||||
/// A desktop entry. See @@DesktopEntries for details.
|
||||
class DesktopEntry: public QObject {
|
||||
Q_OBJECT;
|
||||
Q_PROPERTY(QString id MEMBER mId CONSTANT);
|
||||
/// Name of the specific application, such as "Firefox".
|
||||
Q_PROPERTY(QString name MEMBER mName CONSTANT);
|
||||
// clang-format off
|
||||
Q_PROPERTY(QString name READ default WRITE default NOTIFY nameChanged BINDABLE bindableName);
|
||||
/// Short description of the application, such as "Web Browser". May be empty.
|
||||
Q_PROPERTY(QString genericName MEMBER mGenericName CONSTANT);
|
||||
Q_PROPERTY(QString genericName READ default WRITE default NOTIFY genericNameChanged BINDABLE bindableGenericName);
|
||||
/// Initial class or app id the app intends to use. May be useful for matching running apps
|
||||
/// to desktop entries.
|
||||
Q_PROPERTY(QString startupClass MEMBER mStartupClass CONSTANT);
|
||||
Q_PROPERTY(QString startupClass READ default WRITE default NOTIFY startupClassChanged BINDABLE bindableStartupClass);
|
||||
/// If true, this application should not be displayed in menus and launchers.
|
||||
Q_PROPERTY(bool noDisplay MEMBER mNoDisplay CONSTANT);
|
||||
Q_PROPERTY(bool noDisplay READ default WRITE default NOTIFY noDisplayChanged BINDABLE bindableNoDisplay);
|
||||
/// Long description of the application, such as "View websites on the internet". May be empty.
|
||||
Q_PROPERTY(QString comment MEMBER mComment CONSTANT);
|
||||
Q_PROPERTY(QString comment READ default WRITE default NOTIFY commentChanged BINDABLE bindableComment);
|
||||
/// Name of the icon associated with this application. May be empty.
|
||||
Q_PROPERTY(QString icon MEMBER mIcon CONSTANT);
|
||||
Q_PROPERTY(QString icon READ default WRITE default NOTIFY iconChanged BINDABLE bindableIcon);
|
||||
/// The raw `Exec` string from the desktop entry.
|
||||
///
|
||||
/// > [!WARNING] This cannot be reliably run as a command. See @@command for one you can run.
|
||||
Q_PROPERTY(QString execString MEMBER mExecString CONSTANT);
|
||||
Q_PROPERTY(QString execString READ default WRITE default NOTIFY execStringChanged BINDABLE bindableExecString);
|
||||
/// The parsed `Exec` command in the desktop entry.
|
||||
///
|
||||
/// The entry can be run with @@execute(), or by using this command in
|
||||
@@ -43,13 +76,14 @@ class DesktopEntry: public QObject {
|
||||
/// the invoked process. See @@execute() for details.
|
||||
///
|
||||
/// > [!NOTE] The provided command does not invoke a terminal even if @@runInTerminal is true.
|
||||
Q_PROPERTY(QVector<QString> command MEMBER mCommand CONSTANT);
|
||||
Q_PROPERTY(QVector<QString> command READ default WRITE default NOTIFY commandChanged BINDABLE bindableCommand);
|
||||
/// The working directory to execute from.
|
||||
Q_PROPERTY(QString workingDirectory MEMBER mWorkingDirectory CONSTANT);
|
||||
Q_PROPERTY(QString workingDirectory READ default WRITE default NOTIFY workingDirectoryChanged BINDABLE bindableWorkingDirectory);
|
||||
/// If the application should run in a terminal.
|
||||
Q_PROPERTY(bool runInTerminal MEMBER mTerminal CONSTANT);
|
||||
Q_PROPERTY(QVector<QString> categories MEMBER mCategories CONSTANT);
|
||||
Q_PROPERTY(QVector<QString> keywords MEMBER mKeywords CONSTANT);
|
||||
Q_PROPERTY(bool runInTerminal READ default WRITE default NOTIFY runInTerminalChanged BINDABLE bindableRunInTerminal);
|
||||
Q_PROPERTY(QVector<QString> categories READ default WRITE default NOTIFY categoriesChanged BINDABLE bindableCategories);
|
||||
Q_PROPERTY(QVector<QString> keywords READ default WRITE default NOTIFY keywordsChanged BINDABLE bindableKeywords);
|
||||
// clang-format on
|
||||
Q_PROPERTY(QVector<DesktopAction*> actions READ actions CONSTANT);
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("DesktopEntry instances must be retrieved from DesktopEntries");
|
||||
@@ -57,7 +91,8 @@ class DesktopEntry: public QObject {
|
||||
public:
|
||||
explicit DesktopEntry(QString id, QObject* parent): QObject(parent), mId(std::move(id)) {}
|
||||
|
||||
void parseEntry(const QString& text);
|
||||
static ParsedDesktopEntryData parseText(const QString& id, const QString& text);
|
||||
void updateState(const ParsedDesktopEntryData& newState);
|
||||
|
||||
/// Run the application. Currently ignores @@runInTerminal and field codes.
|
||||
///
|
||||
@@ -73,31 +108,66 @@ public:
|
||||
Q_INVOKABLE void execute() const;
|
||||
|
||||
[[nodiscard]] bool isValid() const;
|
||||
[[nodiscard]] bool noDisplay() const;
|
||||
[[nodiscard]] QVector<DesktopAction*> actions() const;
|
||||
|
||||
[[nodiscard]] QBindable<QString> bindableName() const { return &this->bName; }
|
||||
[[nodiscard]] QBindable<QString> bindableGenericName() const { return &this->bGenericName; }
|
||||
[[nodiscard]] QBindable<QString> bindableStartupClass() const { return &this->bStartupClass; }
|
||||
[[nodiscard]] QBindable<bool> bindableNoDisplay() const { return &this->bNoDisplay; }
|
||||
[[nodiscard]] QBindable<QString> bindableComment() const { return &this->bComment; }
|
||||
[[nodiscard]] QBindable<QString> bindableIcon() const { return &this->bIcon; }
|
||||
[[nodiscard]] QBindable<QString> bindableExecString() const { return &this->bExecString; }
|
||||
[[nodiscard]] QBindable<QVector<QString>> bindableCommand() const { return &this->bCommand; }
|
||||
[[nodiscard]] QBindable<QString> bindableWorkingDirectory() const {
|
||||
return &this->bWorkingDirectory;
|
||||
}
|
||||
[[nodiscard]] QBindable<bool> bindableRunInTerminal() const { return &this->bRunInTerminal; }
|
||||
[[nodiscard]] QBindable<QVector<QString>> bindableCategories() const {
|
||||
return &this->bCategories;
|
||||
}
|
||||
[[nodiscard]] QBindable<QVector<QString>> bindableKeywords() const { return &this->bKeywords; }
|
||||
|
||||
// currently ignores all field codes.
|
||||
static QVector<QString> parseExecString(const QString& execString);
|
||||
static void doExec(const QList<QString>& execString, const QString& workingDirectory);
|
||||
|
||||
signals:
|
||||
void nameChanged();
|
||||
void genericNameChanged();
|
||||
void startupClassChanged();
|
||||
void noDisplayChanged();
|
||||
void commentChanged();
|
||||
void iconChanged();
|
||||
void execStringChanged();
|
||||
void commandChanged();
|
||||
void workingDirectoryChanged();
|
||||
void runInTerminalChanged();
|
||||
void categoriesChanged();
|
||||
void keywordsChanged();
|
||||
|
||||
public:
|
||||
QString mId;
|
||||
QString mName;
|
||||
QString mGenericName;
|
||||
QString mStartupClass;
|
||||
bool mNoDisplay = false;
|
||||
QString mComment;
|
||||
QString mIcon;
|
||||
QString mExecString;
|
||||
QVector<QString> mCommand;
|
||||
QString mWorkingDirectory;
|
||||
bool mTerminal = false;
|
||||
QVector<QString> mCategories;
|
||||
QVector<QString> mKeywords;
|
||||
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bName, &DesktopEntry::nameChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bGenericName, &DesktopEntry::genericNameChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bStartupClass, &DesktopEntry::startupClassChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, bool, bNoDisplay, &DesktopEntry::noDisplayChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bComment, &DesktopEntry::commentChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bIcon, &DesktopEntry::iconChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bExecString, &DesktopEntry::execStringChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QVector<QString>, bCommand, &DesktopEntry::commandChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QString, bWorkingDirectory, &DesktopEntry::workingDirectoryChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, bool, bRunInTerminal, &DesktopEntry::runInTerminalChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QVector<QString>, bCategories, &DesktopEntry::categoriesChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopEntry, QVector<QString>, bKeywords, &DesktopEntry::keywordsChanged);
|
||||
// clang-format on
|
||||
|
||||
private:
|
||||
QHash<QString, QString> mEntries;
|
||||
QHash<QString, DesktopAction*> mActions;
|
||||
void updateActions(const QVector<DesktopActionData>& newActions);
|
||||
|
||||
ParsedDesktopEntryData state;
|
||||
QVector<DesktopAction*> mActions;
|
||||
|
||||
friend class DesktopAction;
|
||||
};
|
||||
@@ -106,12 +176,13 @@ private:
|
||||
class DesktopAction: public QObject {
|
||||
Q_OBJECT;
|
||||
Q_PROPERTY(QString id MEMBER mId CONSTANT);
|
||||
Q_PROPERTY(QString name MEMBER mName CONSTANT);
|
||||
Q_PROPERTY(QString icon MEMBER mIcon CONSTANT);
|
||||
// clang-format off
|
||||
Q_PROPERTY(QString name READ default WRITE default NOTIFY nameChanged BINDABLE bindableName);
|
||||
Q_PROPERTY(QString icon READ default WRITE default NOTIFY iconChanged BINDABLE bindableIcon);
|
||||
/// The raw `Exec` string from the action.
|
||||
///
|
||||
/// > [!WARNING] This cannot be reliably run as a command. See @@command for one you can run.
|
||||
Q_PROPERTY(QString execString MEMBER mExecString CONSTANT);
|
||||
Q_PROPERTY(QString execString READ default WRITE default NOTIFY execStringChanged BINDABLE bindableExecString);
|
||||
/// The parsed `Exec` command in the action.
|
||||
///
|
||||
/// The entry can be run with @@execute(), or by using this command in
|
||||
@@ -120,7 +191,8 @@ class DesktopAction: public QObject {
|
||||
/// the invoked process.
|
||||
///
|
||||
/// > [!NOTE] The provided command does not invoke a terminal even if @@runInTerminal is true.
|
||||
Q_PROPERTY(QVector<QString> command MEMBER mCommand CONSTANT);
|
||||
Q_PROPERTY(QVector<QString> command READ default WRITE default NOTIFY commandChanged BINDABLE bindableCommand);
|
||||
// clang-format on
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("DesktopAction instances must be retrieved from a DesktopEntry");
|
||||
|
||||
@@ -136,18 +208,47 @@ public:
|
||||
/// and @@DesktopEntry.workingDirectory.
|
||||
Q_INVOKABLE void execute() const;
|
||||
|
||||
[[nodiscard]] QBindable<QString> bindableName() const { return &this->bName; }
|
||||
[[nodiscard]] QBindable<QString> bindableIcon() const { return &this->bIcon; }
|
||||
[[nodiscard]] QBindable<QString> bindableExecString() const { return &this->bExecString; }
|
||||
[[nodiscard]] QBindable<QVector<QString>> bindableCommand() const { return &this->bCommand; }
|
||||
|
||||
signals:
|
||||
void nameChanged();
|
||||
void iconChanged();
|
||||
void execStringChanged();
|
||||
void commandChanged();
|
||||
|
||||
private:
|
||||
DesktopEntry* entry;
|
||||
QString mId;
|
||||
QString mName;
|
||||
QString mIcon;
|
||||
QString mExecString;
|
||||
QVector<QString> mCommand;
|
||||
QHash<QString, QString> mEntries;
|
||||
|
||||
// clang-format off
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopAction, QString, bName, &DesktopAction::nameChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopAction, QString, bIcon, &DesktopAction::iconChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopAction, QString, bExecString, &DesktopAction::execStringChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(DesktopAction, QVector<QString>, bCommand, &DesktopAction::commandChanged);
|
||||
// clang-format on
|
||||
|
||||
friend class DesktopEntry;
|
||||
};
|
||||
|
||||
class DesktopEntryManager;
|
||||
|
||||
class DesktopEntryScanner: public QRunnable {
|
||||
public:
|
||||
explicit DesktopEntryScanner(DesktopEntryManager* manager);
|
||||
|
||||
void run() override;
|
||||
// clang-format off
|
||||
void scanDirectory(const QDir& dir, const QString& idPrefix, QList<ParsedDesktopEntryData>& entries);
|
||||
// clang-format on
|
||||
|
||||
private:
|
||||
DesktopEntryManager* manager;
|
||||
};
|
||||
|
||||
class DesktopEntryManager: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
@@ -161,15 +262,26 @@ public:
|
||||
|
||||
static DesktopEntryManager* instance();
|
||||
|
||||
static const QStringList& desktopPaths();
|
||||
|
||||
signals:
|
||||
void applicationsChanged();
|
||||
|
||||
private slots:
|
||||
void handleFileChanges();
|
||||
void onScanCompleted(const QList<ParsedDesktopEntryData>& scanResults);
|
||||
|
||||
private:
|
||||
explicit DesktopEntryManager();
|
||||
|
||||
void populateApplications();
|
||||
void scanPath(const QDir& dir, const QString& prefix = QString());
|
||||
|
||||
QHash<QString, DesktopEntry*> desktopEntries;
|
||||
QHash<QString, DesktopEntry*> lowercaseDesktopEntries;
|
||||
ObjectModel<DesktopEntry> mApplications {this};
|
||||
DesktopEntryMonitor* monitor = nullptr;
|
||||
bool scanInProgress = false;
|
||||
bool scanQueued = false;
|
||||
|
||||
friend class DesktopEntryScanner;
|
||||
};
|
||||
|
||||
///! Desktop entry index.
|
||||
@@ -201,4 +313,7 @@ public:
|
||||
Q_INVOKABLE [[nodiscard]] static DesktopEntry* heuristicLookup(const QString& name);
|
||||
|
||||
[[nodiscard]] static ObjectModel<DesktopEntry>* applications();
|
||||
|
||||
signals:
|
||||
void applicationsChanged();
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "desktopentrymonitor.hpp"
|
||||
|
||||
#include <qdir.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qfilesystemwatcher.h>
|
||||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "desktopentry.hpp"
|
||||
|
||||
namespace {
|
||||
void addPathAndParents(QFileSystemWatcher& watcher, const QString& path) {
|
||||
watcher.addPath(path);
|
||||
|
||||
auto p = QFileInfo(path).absolutePath();
|
||||
while (!p.isEmpty()) {
|
||||
watcher.addPath(p);
|
||||
const auto parent = QFileInfo(p).dir().absolutePath();
|
||||
if (parent == p) break;
|
||||
p = parent;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DesktopEntryMonitor::DesktopEntryMonitor(QObject* parent): QObject(parent) {
|
||||
this->debounceTimer.setSingleShot(true);
|
||||
this->debounceTimer.setInterval(100);
|
||||
|
||||
QObject::connect(
|
||||
&this->watcher,
|
||||
&QFileSystemWatcher::directoryChanged,
|
||||
this,
|
||||
&DesktopEntryMonitor::onDirectoryChanged
|
||||
);
|
||||
QObject::connect(
|
||||
&this->debounceTimer,
|
||||
&QTimer::timeout,
|
||||
this,
|
||||
&DesktopEntryMonitor::processChanges
|
||||
);
|
||||
|
||||
this->startMonitoring();
|
||||
}
|
||||
|
||||
void DesktopEntryMonitor::startMonitoring() {
|
||||
for (const auto& path: DesktopEntryManager::desktopPaths()) {
|
||||
if (!QDir(path).exists()) continue;
|
||||
addPathAndParents(this->watcher, path);
|
||||
this->scanAndWatch(path);
|
||||
}
|
||||
}
|
||||
|
||||
void DesktopEntryMonitor::scanAndWatch(const QString& dirPath) {
|
||||
auto dir = QDir(dirPath);
|
||||
if (!dir.exists()) return;
|
||||
|
||||
this->watcher.addPath(dirPath);
|
||||
|
||||
auto subdirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||
for (const auto& subdir: subdirs) this->watcher.addPath(subdir.absoluteFilePath());
|
||||
}
|
||||
|
||||
void DesktopEntryMonitor::onDirectoryChanged(const QString& /*path*/) {
|
||||
this->debounceTimer.start();
|
||||
}
|
||||
|
||||
void DesktopEntryMonitor::processChanges() { emit this->desktopEntriesChanged(); }
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <qfilesystemwatcher.h>
|
||||
#include <qobject.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
class DesktopEntryMonitor: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DesktopEntryMonitor(QObject* parent = nullptr);
|
||||
~DesktopEntryMonitor() override = default;
|
||||
DesktopEntryMonitor(const DesktopEntryMonitor&) = delete;
|
||||
DesktopEntryMonitor& operator=(const DesktopEntryMonitor&) = delete;
|
||||
DesktopEntryMonitor(DesktopEntryMonitor&&) = delete;
|
||||
DesktopEntryMonitor& operator=(DesktopEntryMonitor&&) = delete;
|
||||
|
||||
signals:
|
||||
void desktopEntriesChanged();
|
||||
|
||||
private slots:
|
||||
void onDirectoryChanged(const QString& path);
|
||||
void processChanges();
|
||||
|
||||
private:
|
||||
void startMonitoring();
|
||||
void scanAndWatch(const QString& dirPath);
|
||||
|
||||
QFileSystemWatcher watcher;
|
||||
QTimer debounceTimer;
|
||||
};
|
||||
+30
-98
@@ -11,12 +11,12 @@
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlcontext.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmlerror.h>
|
||||
#include <qqmlincubator.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "iconimageprovider.hpp"
|
||||
@@ -49,7 +49,8 @@ EngineGeneration::EngineGeneration(const QDir& rootPath, QmlScanner scanner)
|
||||
this->engine->addImportPath("qs:@/");
|
||||
|
||||
this->engine->setNetworkAccessManagerFactory(&this->interceptNetFactory);
|
||||
this->engine->setIncubationController(&this->delayedIncubationController);
|
||||
this->incubationController.initLoop();
|
||||
this->engine->setIncubationController(&this->incubationController);
|
||||
|
||||
this->engine->addImageProvider("icon", new IconImageProvider());
|
||||
this->engine->addImageProvider("qsimage", new QsImageProvider());
|
||||
@@ -134,7 +135,7 @@ void EngineGeneration::onReload(EngineGeneration* old) {
|
||||
// new generation acquires it then incubators will hang intermittently
|
||||
qCDebug(logIncubator) << "Locking incubation controllers of old generation" << old;
|
||||
old->incubationControllersLocked = true;
|
||||
old->assignIncubationController();
|
||||
old->updateIncubationMode();
|
||||
}
|
||||
|
||||
QObject::connect(this->engine, &QQmlEngine::quit, this, &EngineGeneration::quit);
|
||||
@@ -208,6 +209,8 @@ bool EngineGeneration::setExtraWatchedFiles(const QVector<QString>& files) {
|
||||
for (const auto& file: files) {
|
||||
if (!this->scanner.scannedFiles.contains(file)) {
|
||||
this->extraWatchedFiles.append(file);
|
||||
QByteArray data;
|
||||
this->scanner.readAndHashFile(file, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +231,11 @@ void EngineGeneration::onFileChanged(const QString& name) {
|
||||
auto fileInfo = QFileInfo(name);
|
||||
if (fileInfo.isFile() && fileInfo.size() == 0) return;
|
||||
|
||||
if (!this->scanner.hasFileContentChanged(name)) {
|
||||
qCDebug(logQmlScanner) << "Ignoring file change with unchanged content:" << name;
|
||||
return;
|
||||
}
|
||||
|
||||
emit this->filesChanged();
|
||||
}
|
||||
}
|
||||
@@ -236,96 +244,17 @@ void EngineGeneration::onDirectoryChanged() {
|
||||
// try to find any files that were just deleted from a replace operation
|
||||
for (auto& file: this->deletedWatchedFiles) {
|
||||
if (QFileInfo(file).exists()) {
|
||||
if (!this->scanner.hasFileContentChanged(file)) {
|
||||
qCDebug(logQmlScanner) << "Ignoring restored file with unchanged content:" << file;
|
||||
continue;
|
||||
}
|
||||
|
||||
emit this->filesChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EngineGeneration::registerIncubationController(QQmlIncubationController* controller) {
|
||||
// We only want controllers that we can swap out if destroyed.
|
||||
// This happens if the window owning the active controller dies.
|
||||
auto* obj = dynamic_cast<QObject*>(controller);
|
||||
if (!obj) {
|
||||
qCWarning(logIncubator) << "Could not register incubation controller as it is not a QObject"
|
||||
<< controller;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
obj,
|
||||
&QObject::destroyed,
|
||||
this,
|
||||
&EngineGeneration::incubationControllerDestroyed,
|
||||
Qt::UniqueConnection
|
||||
);
|
||||
|
||||
this->incubationControllers.push_back(obj);
|
||||
qCDebug(logIncubator) << "Registered incubation controller" << obj << "to generation" << this;
|
||||
|
||||
// This function can run during destruction.
|
||||
if (this->engine == nullptr) return;
|
||||
|
||||
if (this->engine->incubationController() == &this->delayedIncubationController) {
|
||||
this->assignIncubationController();
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple controllers may be destroyed at once. Dynamic casts must be performed before working
|
||||
// with any controllers. The QQmlIncubationController destructor will already have run by the
|
||||
// point QObject::destroyed is called, so we can't cast to that.
|
||||
void EngineGeneration::deregisterIncubationController(QQmlIncubationController* controller) {
|
||||
auto* obj = dynamic_cast<QObject*>(controller);
|
||||
if (!obj) {
|
||||
qCCritical(logIncubator) << "Deregistering incubation controller which is not a QObject, "
|
||||
"however only QObject controllers should be registered.";
|
||||
}
|
||||
|
||||
QObject::disconnect(obj, nullptr, this, nullptr);
|
||||
|
||||
if (this->incubationControllers.removeOne(obj)) {
|
||||
qCDebug(logIncubator) << "Deregistered incubation controller" << obj << "from" << this;
|
||||
} else {
|
||||
qCCritical(logIncubator) << "Failed to deregister incubation controller" << obj << "from"
|
||||
<< this << "as it was not registered to begin with";
|
||||
qCCritical(logIncubator) << "Current registered incuabation controllers"
|
||||
<< this->incubationControllers;
|
||||
}
|
||||
|
||||
// This function can run during destruction.
|
||||
if (this->engine == nullptr) return;
|
||||
|
||||
if (this->engine->incubationController() == controller) {
|
||||
qCDebug(logIncubator
|
||||
) << "Destroyed incubation controller was currently active, reassigning from pool";
|
||||
this->assignIncubationController();
|
||||
}
|
||||
}
|
||||
|
||||
void EngineGeneration::incubationControllerDestroyed() {
|
||||
auto* sender = this->sender();
|
||||
|
||||
if (this->incubationControllers.removeAll(sender) != 0) {
|
||||
qCDebug(logIncubator) << "Destroyed incubation controller" << sender << "deregistered from"
|
||||
<< this;
|
||||
} else {
|
||||
qCCritical(logIncubator) << "Destroyed incubation controller" << sender
|
||||
<< "was not registered, but its destruction was observed by" << this;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// This function can run during destruction.
|
||||
if (this->engine == nullptr) return;
|
||||
|
||||
if (dynamic_cast<QObject*>(this->engine->incubationController()) == sender) {
|
||||
qCDebug(logIncubator
|
||||
) << "Destroyed incubation controller was currently active, reassigning from pool";
|
||||
this->assignIncubationController();
|
||||
}
|
||||
}
|
||||
|
||||
void EngineGeneration::onEngineWarnings(const QList<QQmlError>& warnings) {
|
||||
for (const auto& error: warnings) {
|
||||
const auto& url = error.url();
|
||||
@@ -367,20 +296,23 @@ void EngineGeneration::exit(int code) {
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
void EngineGeneration::assignIncubationController() {
|
||||
QQmlIncubationController* controller = nullptr;
|
||||
void EngineGeneration::trackWindowIncubationController(QQuickWindow* window) {
|
||||
if (this->trackedWindows.contains(window)) return;
|
||||
|
||||
if (this->incubationControllersLocked || this->incubationControllers.isEmpty()) {
|
||||
controller = &this->delayedIncubationController;
|
||||
} else {
|
||||
controller = dynamic_cast<QQmlIncubationController*>(this->incubationControllers.first());
|
||||
}
|
||||
QObject::connect(window, &QObject::destroyed, this, &EngineGeneration::onTrackedWindowDestroyed);
|
||||
this->trackedWindows.append(window);
|
||||
this->updateIncubationMode();
|
||||
}
|
||||
|
||||
qCDebug(logIncubator) << "Assigning incubation controller" << controller << "to generation"
|
||||
<< this
|
||||
<< "fallback:" << (controller == &this->delayedIncubationController);
|
||||
void EngineGeneration::onTrackedWindowDestroyed(QObject* object) {
|
||||
this->trackedWindows.removeAll(static_cast<QQuickWindow*>(object)); // NOLINT
|
||||
this->updateIncubationMode();
|
||||
}
|
||||
|
||||
this->engine->setIncubationController(controller);
|
||||
void EngineGeneration::updateIncubationMode() {
|
||||
// If we're in a situation with only hidden but tracked windows this might be wrong,
|
||||
// but it seems to at least work.
|
||||
this->incubationController.setIncubationMode(!this->trackedWindows.empty());
|
||||
}
|
||||
|
||||
EngineGeneration* EngineGeneration::currentGeneration() {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmlerror.h>
|
||||
#include <qqmlincubator.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qtclasshelpermacros.h>
|
||||
|
||||
#include "incubator.hpp"
|
||||
@@ -40,8 +41,7 @@ public:
|
||||
void setWatchingFiles(bool watching);
|
||||
bool setExtraWatchedFiles(const QVector<QString>& files);
|
||||
|
||||
void registerIncubationController(QQmlIncubationController* controller);
|
||||
void deregisterIncubationController(QQmlIncubationController* controller);
|
||||
void trackWindowIncubationController(QQuickWindow* window);
|
||||
|
||||
// takes ownership
|
||||
void registerExtension(const void* key, EngineGenerationExt* extension);
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
QFileSystemWatcher* watcher = nullptr;
|
||||
QVector<QString> deletedWatchedFiles;
|
||||
QVector<QString> extraWatchedFiles;
|
||||
DelayedQmlIncubationController delayedIncubationController;
|
||||
QsIncubationController incubationController;
|
||||
bool reloadComplete = false;
|
||||
QuickshellGlobal* qsgInstance = nullptr;
|
||||
|
||||
@@ -84,13 +84,13 @@ public slots:
|
||||
private slots:
|
||||
void onFileChanged(const QString& name);
|
||||
void onDirectoryChanged();
|
||||
void incubationControllerDestroyed();
|
||||
void onTrackedWindowDestroyed(QObject* object);
|
||||
static void onEngineWarnings(const QList<QQmlError>& warnings);
|
||||
|
||||
private:
|
||||
void postReload();
|
||||
void assignIncubationController();
|
||||
QVector<QObject*> incubationControllers;
|
||||
void updateIncubationMode();
|
||||
QVector<QQuickWindow*> trackedWindows;
|
||||
bool incubationControllersLocked = false;
|
||||
QHash<const void*, EngineGenerationExt*> extensions;
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& re
|
||||
if (splitIdx != -1) {
|
||||
iconName = id.sliced(0, splitIdx);
|
||||
path = id.sliced(splitIdx + 6);
|
||||
qWarning() << "Searching custom icon paths is not yet supported. Icon path will be ignored for"
|
||||
<< id;
|
||||
path = QString("/%1/%2").arg(path, iconName.sliced(iconName.lastIndexOf('/') + 1));
|
||||
} else {
|
||||
splitIdx = id.indexOf("?fallback=");
|
||||
if (splitIdx != -1) {
|
||||
@@ -32,7 +31,8 @@ IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& re
|
||||
}
|
||||
|
||||
auto icon = QIcon::fromTheme(iconName);
|
||||
if (icon.isNull()) icon = QIcon::fromTheme(fallbackName);
|
||||
if (icon.isNull() && !fallbackName.isEmpty()) icon = QIcon::fromTheme(fallbackName);
|
||||
if (icon.isNull() && !path.isEmpty()) icon = QPixmap(path);
|
||||
|
||||
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
|
||||
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "generation.hpp"
|
||||
|
||||
// QMenu re-calls pixmap() every time the mouse moves so its important to cache it.
|
||||
// QMenu re-calls pixmap() every time the mouse moves so it's important to cache it.
|
||||
class PixmapCacheIconEngine: public QIconEngine {
|
||||
void paint(
|
||||
QPainter* /*unused*/,
|
||||
@@ -22,8 +22,8 @@ class PixmapCacheIconEngine: public QIconEngine {
|
||||
QIcon::Mode /*unused*/,
|
||||
QIcon::State /*unused*/
|
||||
) override {
|
||||
qFatal(
|
||||
) << "Unexpected icon paint request bypassed pixmap method. Please report this as a bug.";
|
||||
qFatal()
|
||||
<< "Unexpected icon paint request bypassed pixmap method. Please report this as a bug.";
|
||||
}
|
||||
|
||||
QPixmap pixmap(const QSize& size, QIcon::Mode /*unused*/, QIcon::State /*unused*/) override {
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
#include "incubator.hpp"
|
||||
|
||||
#include <private/qsgrenderloop_p.h>
|
||||
#include <qabstractanimation.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qminmax.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qqmlincubator.h>
|
||||
#include <qscreen.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
#include "logcat.hpp"
|
||||
@@ -15,3 +24,112 @@ void QsQmlIncubator::statusChanged(QQmlIncubator::Status status) {
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void QsIncubationController::initLoop() {
|
||||
auto* app = static_cast<QGuiApplication*>(QGuiApplication::instance()); // NOLINT
|
||||
this->renderLoop = QSGRenderLoop::instance();
|
||||
|
||||
QObject::connect(
|
||||
app,
|
||||
&QGuiApplication::screenAdded,
|
||||
this,
|
||||
&QsIncubationController::updateIncubationTime
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
app,
|
||||
&QGuiApplication::screenRemoved,
|
||||
this,
|
||||
&QsIncubationController::updateIncubationTime
|
||||
);
|
||||
|
||||
this->updateIncubationTime();
|
||||
|
||||
QObject::connect(
|
||||
this->renderLoop,
|
||||
&QSGRenderLoop::timeToIncubate,
|
||||
this,
|
||||
&QsIncubationController::incubate
|
||||
);
|
||||
|
||||
QAnimationDriver* animationDriver = this->renderLoop->animationDriver();
|
||||
if (animationDriver) {
|
||||
QObject::connect(
|
||||
animationDriver,
|
||||
&QAnimationDriver::stopped,
|
||||
this,
|
||||
&QsIncubationController::animationStopped
|
||||
);
|
||||
} else {
|
||||
qCInfo(logIncubator) << "Render loop does not have animation driver, animationStopped cannot "
|
||||
"be used to trigger incubation.";
|
||||
}
|
||||
}
|
||||
|
||||
void QsIncubationController::setIncubationMode(bool render) {
|
||||
if (render == this->followRenderloop) return;
|
||||
this->followRenderloop = render;
|
||||
|
||||
if (render) {
|
||||
qCDebug(logIncubator) << "Incubation mode changed: render loop driven";
|
||||
} else {
|
||||
qCDebug(logIncubator) << "Incubation mode changed: event loop driven";
|
||||
}
|
||||
|
||||
if (!render && this->incubatingObjectCount()) this->incubateLater();
|
||||
}
|
||||
|
||||
void QsIncubationController::timerEvent(QTimerEvent* /*event*/) {
|
||||
this->killTimer(this->timerId);
|
||||
this->timerId = 0;
|
||||
this->incubate();
|
||||
}
|
||||
|
||||
void QsIncubationController::incubateLater() {
|
||||
if (this->followRenderloop) {
|
||||
if (this->timerId != 0) {
|
||||
this->killTimer(this->timerId);
|
||||
this->timerId = 0;
|
||||
}
|
||||
|
||||
// Incubate again at the end of the event processing queue
|
||||
QMetaObject::invokeMethod(this, &QsIncubationController::incubate, Qt::QueuedConnection);
|
||||
} else if (this->timerId == 0) {
|
||||
// Wait for a while before processing the next batch. Using a
|
||||
// timer to avoid starvation of system events.
|
||||
this->timerId = this->startTimer(this->incubationTime);
|
||||
}
|
||||
}
|
||||
|
||||
void QsIncubationController::incubate() {
|
||||
if ((!this->followRenderloop || this->renderLoop) && this->incubatingObjectCount()) {
|
||||
if (!this->followRenderloop) {
|
||||
this->incubateFor(10);
|
||||
if (this->incubatingObjectCount()) this->incubateLater();
|
||||
} else if (this->renderLoop->interleaveIncubation()) {
|
||||
this->incubateFor(this->incubationTime);
|
||||
} else {
|
||||
this->incubateFor(this->incubationTime * 2);
|
||||
if (this->incubatingObjectCount()) this->incubateLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QsIncubationController::animationStopped() { this->incubate(); }
|
||||
|
||||
void QsIncubationController::incubatingObjectCountChanged(int count) {
|
||||
if (count
|
||||
&& (!this->followRenderloop
|
||||
|| (this->renderLoop && !this->renderLoop->interleaveIncubation())))
|
||||
{
|
||||
this->incubateLater();
|
||||
}
|
||||
}
|
||||
|
||||
void QsIncubationController::updateIncubationTime() {
|
||||
auto* screen = QGuiApplication::primaryScreen();
|
||||
if (!screen) return;
|
||||
|
||||
// 1/3 frame on primary screen
|
||||
this->incubationTime = qMax(1, static_cast<int>(1000 / screen->refreshRate() / 3));
|
||||
}
|
||||
+34
-3
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qpointer.h>
|
||||
#include <qqmlincubator.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
@@ -25,7 +26,37 @@ signals:
|
||||
void failed();
|
||||
};
|
||||
|
||||
class DelayedQmlIncubationController: public QQmlIncubationController {
|
||||
// Do nothing.
|
||||
// This ensures lazy loaders don't start blocking before onReload creates windows.
|
||||
class QSGRenderLoop;
|
||||
|
||||
class QsIncubationController
|
||||
: public QObject
|
||||
, public QQmlIncubationController {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void initLoop();
|
||||
void setIncubationMode(bool render);
|
||||
void incubateLater();
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent* event) override;
|
||||
|
||||
public slots:
|
||||
void incubate();
|
||||
void animationStopped();
|
||||
void updateIncubationTime();
|
||||
|
||||
protected:
|
||||
void incubatingObjectCountChanged(int count) override;
|
||||
|
||||
private:
|
||||
// QPointer did not work with forward declarations prior to 6.7
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
QPointer<QSGRenderLoop> renderLoop = nullptr;
|
||||
#else
|
||||
QSGRenderLoop* renderLoop = nullptr;
|
||||
#endif
|
||||
int incubationTime = 0;
|
||||
int timerId = 0;
|
||||
bool followRenderloop = false;
|
||||
};
|
||||
@@ -3,12 +3,14 @@
|
||||
#include <qdatastream.h>
|
||||
|
||||
QDataStream& operator<<(QDataStream& stream, const InstanceInfo& info) {
|
||||
stream << info.instanceId << info.configPath << info.shellId << info.launchTime << info.pid;
|
||||
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;
|
||||
stream >> info.instanceId >> info.configPath >> info.shellId >> info.appId >> info.launchTime
|
||||
>> info.pid >> info.display;
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,10 @@ struct InstanceInfo {
|
||||
QString instanceId;
|
||||
QString configPath;
|
||||
QString shellId;
|
||||
QString appId;
|
||||
QDateTime launchTime;
|
||||
pid_t pid = -1;
|
||||
QString display;
|
||||
|
||||
static InstanceInfo CURRENT; // NOLINT
|
||||
};
|
||||
@@ -34,6 +36,8 @@ namespace qs::crash {
|
||||
|
||||
struct CrashInfo {
|
||||
int logFd = -1;
|
||||
int traceFd = -1;
|
||||
int infoFd = -1;
|
||||
|
||||
static CrashInfo INSTANCE; // NOLINT
|
||||
};
|
||||
|
||||
@@ -82,9 +82,6 @@
|
||||
/// > Notably, @@Variants does not corrently support asynchronous
|
||||
/// > loading, meaning using it inside a LazyLoader will block similarly to not
|
||||
/// > having a loader to start with.
|
||||
///
|
||||
/// > [!WARNING] LazyLoaders do not start loading before the first window is created,
|
||||
/// > meaning if you create all windows inside of lazy loaders, none of them will ever load.
|
||||
class LazyLoader: public Reloadable {
|
||||
Q_OBJECT;
|
||||
/// The fully loaded item if the loader is @@loading or @@active, or `null`
|
||||
|
||||
+127
-28
@@ -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>
|
||||
@@ -27,7 +28,13 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <sys/mman.h>
|
||||
#ifdef __linux__
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "instanceinfo.hpp"
|
||||
#include "logcat.hpp"
|
||||
@@ -43,6 +50,57 @@ using namespace qt_logging_registry;
|
||||
|
||||
QS_LOGGING_CATEGORY(logLogging, "quickshell.logging", QtWarningMsg);
|
||||
|
||||
namespace {
|
||||
bool copyFileData(int sourceFd, int destFd, qint64 size) {
|
||||
auto usize = static_cast<size_t>(size);
|
||||
|
||||
#ifdef __linux__
|
||||
off_t offset = 0;
|
||||
auto remaining = usize;
|
||||
|
||||
while (remaining > 0) {
|
||||
auto r = sendfile(destFd, sourceFd, &offset, remaining);
|
||||
if (r == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
if (r == 0) break;
|
||||
remaining -= static_cast<size_t>(r);
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
std::array<char, 64 * 1024> buffer = {};
|
||||
auto remaining = usize;
|
||||
|
||||
while (remaining > 0) {
|
||||
auto chunk = std::min(remaining, buffer.size());
|
||||
auto r = ::read(sourceFd, buffer.data(), chunk);
|
||||
if (r == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
if (r == 0) break;
|
||||
|
||||
auto readBytes = static_cast<size_t>(r);
|
||||
size_t written = 0;
|
||||
while (written < readBytes) {
|
||||
auto w = ::write(destFd, buffer.data() + written, readBytes - written);
|
||||
if (w == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
written += static_cast<size_t>(w);
|
||||
}
|
||||
|
||||
remaining -= readBytes;
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool LogMessage::operator==(const LogMessage& other) const {
|
||||
// note: not including time
|
||||
return this->type == other.type && this->category == other.category && this->body == other.body;
|
||||
@@ -163,6 +221,7 @@ void LogManager::messageHandler(
|
||||
}
|
||||
|
||||
if (display) {
|
||||
auto locker = QMutexLocker(&self->stdoutMutex);
|
||||
LogMessage::formatMessage(
|
||||
self->stdoutStream,
|
||||
message,
|
||||
@@ -198,9 +257,21 @@ void LogManager::filterCategory(QLoggingCategory* category) {
|
||||
filter.warn = filter.info || instance->mDefaultLevel == QtWarningMsg || defaultLevel == QtWarningMsg;
|
||||
filter.critical = filter.warn || instance->mDefaultLevel == QtCriticalMsg || defaultLevel == QtCriticalMsg;
|
||||
// clang-format on
|
||||
} else if (instance->lastCategoryFilter) {
|
||||
instance->lastCategoryFilter(category);
|
||||
filter = CategoryFilter(category);
|
||||
} else {
|
||||
if (instance->lastCategoryFilter) {
|
||||
instance->lastCategoryFilter(category);
|
||||
filter = CategoryFilter(category);
|
||||
}
|
||||
|
||||
// Hides virtual/override property warnings.
|
||||
// Getting rid of this is blocked by https://qt-project.atlassian.net/browse/QTBUG-145977
|
||||
// for internal Quickshell types, and may still be desired for shells that want to maintain
|
||||
// compatibility with Qt versions prior to 6.11.
|
||||
if (categoryName == QLatin1StringView("qt.qml.propertyCache.append")
|
||||
&& !qEnvironmentVariableIsSet("QS_NO_FILTER_QT_LOGS"))
|
||||
{
|
||||
filter.warn = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& rule: *instance->rules) {
|
||||
@@ -233,6 +304,10 @@ void LogManager::init(
|
||||
const QString& rules,
|
||||
const QString& prefix
|
||||
) {
|
||||
static bool alreadyInitialized = false;
|
||||
if (alreadyInitialized) return;
|
||||
alreadyInitialized = true;
|
||||
|
||||
auto* instance = LogManager::instance();
|
||||
instance->colorLogs = color;
|
||||
instance->timestampLogs = timestamp;
|
||||
@@ -251,10 +326,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);
|
||||
@@ -313,8 +393,12 @@ void ThreadLogging::init() {
|
||||
|
||||
if (logMfd != -1) {
|
||||
this->file = new QFile();
|
||||
this->file->open(logMfd, QFile::ReadWrite, QFile::AutoCloseHandle);
|
||||
this->fileStream.setDevice(this->file);
|
||||
|
||||
if (this->file->open(logMfd, QFile::ReadWrite, QFile::AutoCloseHandle)) {
|
||||
this->fileStream.setDevice(this->file);
|
||||
} else {
|
||||
qCCritical(logLogging) << "Failed to open early logging memfd.";
|
||||
}
|
||||
}
|
||||
|
||||
if (dlogMfd != -1) {
|
||||
@@ -322,14 +406,19 @@ void ThreadLogging::init() {
|
||||
|
||||
this->detailedFile = new QFile();
|
||||
// buffered by WriteBuffer
|
||||
this->detailedFile->open(dlogMfd, QFile::ReadWrite | QFile::Unbuffered, QFile::AutoCloseHandle);
|
||||
this->detailedWriter.setDevice(this->detailedFile);
|
||||
if (this->detailedFile
|
||||
->open(dlogMfd, QFile::ReadWrite | QFile::Unbuffered, QFile::AutoCloseHandle))
|
||||
{
|
||||
this->detailedWriter.setDevice(this->detailedFile);
|
||||
|
||||
if (!this->detailedWriter.writeHeader()) {
|
||||
qCCritical(logLogging) << "Could not write header for detailed logs.";
|
||||
this->detailedWriter.setDevice(nullptr);
|
||||
delete this->detailedFile;
|
||||
this->detailedFile = nullptr;
|
||||
if (!this->detailedWriter.writeHeader()) {
|
||||
qCCritical(logLogging) << "Could not write header for detailed logs.";
|
||||
this->detailedWriter.setDevice(nullptr);
|
||||
delete this->detailedFile;
|
||||
this->detailedFile = nullptr;
|
||||
}
|
||||
} else {
|
||||
qCCritical(logLogging) << "Failed to open early detailed logging memfd.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +441,8 @@ void ThreadLogging::initFs() {
|
||||
auto* runDir = QsPaths::instance()->instanceRunDir();
|
||||
|
||||
if (!runDir) {
|
||||
qCCritical(logLogging
|
||||
qCCritical(
|
||||
logLogging
|
||||
) << "Could not start filesystem logging as the runtime directory could not be created.";
|
||||
return;
|
||||
}
|
||||
@@ -363,7 +453,8 @@ void ThreadLogging::initFs() {
|
||||
auto* detailedFile = new QFile(detailedPath);
|
||||
|
||||
if (!file->open(QFile::ReadWrite | QFile::Truncate)) {
|
||||
qCCritical(logLogging
|
||||
qCCritical(
|
||||
logLogging
|
||||
) << "Could not start filesystem logger as the log file could not be created:"
|
||||
<< path;
|
||||
delete file;
|
||||
@@ -374,13 +465,14 @@ void ThreadLogging::initFs() {
|
||||
|
||||
// buffered by WriteBuffer
|
||||
if (!detailedFile->open(QFile::ReadWrite | QFile::Truncate | QFile::Unbuffered)) {
|
||||
qCCritical(logLogging
|
||||
qCCritical(
|
||||
logLogging
|
||||
) << "Could not start detailed filesystem logger as the log file could not be created:"
|
||||
<< detailedPath;
|
||||
delete detailedFile;
|
||||
detailedFile = nullptr;
|
||||
} else {
|
||||
auto lock = flock {
|
||||
struct flock lock = {
|
||||
.l_type = F_WRLCK,
|
||||
.l_whence = SEEK_SET,
|
||||
.l_start = 0,
|
||||
@@ -402,7 +494,11 @@ void ThreadLogging::initFs() {
|
||||
auto* oldFile = this->file;
|
||||
if (oldFile) {
|
||||
oldFile->seek(0);
|
||||
sendfile(file->handle(), oldFile->handle(), nullptr, oldFile->size());
|
||||
|
||||
if (!copyFileData(oldFile->handle(), file->handle(), oldFile->size())) {
|
||||
qCritical(logLogging) << "Failed to copy log from memfd with error code " << errno
|
||||
<< qt_error_string(errno);
|
||||
}
|
||||
}
|
||||
|
||||
this->file = file;
|
||||
@@ -414,7 +510,10 @@ void ThreadLogging::initFs() {
|
||||
auto* oldFile = this->detailedFile;
|
||||
if (oldFile) {
|
||||
oldFile->seek(0);
|
||||
sendfile(detailedFile->handle(), oldFile->handle(), nullptr, oldFile->size());
|
||||
if (!copyFileData(oldFile->handle(), detailedFile->handle(), oldFile->size())) {
|
||||
qCritical(logLogging) << "Failed to copy detailed log from memfd with error code " << errno
|
||||
<< qt_error_string(errno);
|
||||
}
|
||||
}
|
||||
|
||||
crash::CrashInfo::INSTANCE.logFd = detailedFile->handle();
|
||||
@@ -447,7 +546,7 @@ void ThreadLogging::initFs() {
|
||||
Qt::QueuedConnection
|
||||
);
|
||||
|
||||
qCDebug(logLogging) << "Switched threaded logger to queued eventloop connection.";
|
||||
qCDebug(logLogging) << "Switched threaded logger to queued event loop connection.";
|
||||
}
|
||||
|
||||
void ThreadLogging::onMessage(const LogMessage& msg, bool showInSparse) {
|
||||
@@ -458,13 +557,13 @@ void ThreadLogging::onMessage(const LogMessage& msg, bool showInSparse) {
|
||||
}
|
||||
|
||||
if (!this->detailedWriter.write(msg) || (this->detailedFile && !this->detailedFile->flush())) {
|
||||
this->detailedWriter.setDevice(nullptr);
|
||||
|
||||
if (this->detailedFile) {
|
||||
this->detailedFile->close();
|
||||
this->detailedFile = nullptr;
|
||||
qCCritical(logLogging) << "Detailed logger failed to write. Ending detailed logs.";
|
||||
}
|
||||
|
||||
this->detailedWriter.setDevice(nullptr);
|
||||
this->detailedFile->close();
|
||||
this->detailedFile = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,11 +836,11 @@ bool EncodedLogReader::readVarInt(quint32* slot) {
|
||||
if (!this->reader.skip(1)) return false;
|
||||
*slot = qFromLittleEndian(n);
|
||||
} else if ((bytes[1] != 0xff || bytes[2] != 0xff) && readLength >= 3) {
|
||||
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1);
|
||||
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1); // NOLINT
|
||||
if (!this->reader.skip(3)) return false;
|
||||
*slot = qFromLittleEndian(n);
|
||||
} else if (readLength == 7) {
|
||||
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3);
|
||||
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3); // NOLINT
|
||||
if (!this->reader.skip(7)) return false;
|
||||
*slot = qFromLittleEndian(n);
|
||||
} else return false;
|
||||
@@ -877,7 +976,7 @@ bool LogReader::continueReading() {
|
||||
}
|
||||
|
||||
void LogFollower::FcntlWaitThread::run() {
|
||||
auto lock = flock {
|
||||
struct flock lock = {
|
||||
.l_type = F_RDLCK, // won't block other read locks when we take it
|
||||
.l_whence = SEEK_SET,
|
||||
.l_start = 0,
|
||||
|
||||
@@ -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);
|
||||
|
||||
+2
-69
@@ -1,81 +1,14 @@
|
||||
#include "model.hpp"
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qbytearray.h>
|
||||
#include <qhash.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
qint32 UntypedObjectModel::rowCount(const QModelIndex& parent) const {
|
||||
if (parent != QModelIndex()) return 0;
|
||||
return static_cast<qint32>(this->valuesList.length());
|
||||
}
|
||||
|
||||
QVariant UntypedObjectModel::data(const QModelIndex& index, qint32 role) const {
|
||||
if (role != Qt::UserRole) return QVariant();
|
||||
return QVariant::fromValue(this->valuesList.at(index.row()));
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> UntypedObjectModel::roleNames() const {
|
||||
return {{Qt::UserRole, "modelData"}};
|
||||
}
|
||||
|
||||
void UntypedObjectModel::insertObject(QObject* object, qsizetype index) {
|
||||
auto iindex = index == -1 ? this->valuesList.length() : index;
|
||||
emit this->objectInsertedPre(object, iindex);
|
||||
|
||||
auto intIndex = static_cast<qint32>(iindex);
|
||||
this->beginInsertRows(QModelIndex(), intIndex, intIndex);
|
||||
this->valuesList.insert(iindex, object);
|
||||
this->endInsertRows();
|
||||
|
||||
emit this->valuesChanged();
|
||||
emit this->objectInsertedPost(object, iindex);
|
||||
}
|
||||
|
||||
void UntypedObjectModel::removeAt(qsizetype index) {
|
||||
auto* object = this->valuesList.at(index);
|
||||
emit this->objectRemovedPre(object, index);
|
||||
|
||||
auto intIndex = static_cast<qint32>(index);
|
||||
this->beginRemoveRows(QModelIndex(), intIndex, intIndex);
|
||||
this->valuesList.removeAt(index);
|
||||
this->endRemoveRows();
|
||||
|
||||
emit this->valuesChanged();
|
||||
emit this->objectRemovedPost(object, index);
|
||||
}
|
||||
|
||||
bool UntypedObjectModel::removeObject(const QObject* object) {
|
||||
auto index = this->valuesList.indexOf(object);
|
||||
if (index == -1) return false;
|
||||
|
||||
this->removeAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UntypedObjectModel::diffUpdate(const QVector<QObject*>& newValues) {
|
||||
for (qsizetype i = 0; i < this->valuesList.length();) {
|
||||
if (newValues.contains(this->valuesList.at(i))) i++;
|
||||
else this->removeAt(i);
|
||||
}
|
||||
|
||||
qsizetype oi = 0;
|
||||
for (auto* object: newValues) {
|
||||
if (this->valuesList.length() == oi || this->valuesList.at(oi) != object) {
|
||||
this->insertObject(object, oi);
|
||||
}
|
||||
|
||||
oi++;
|
||||
}
|
||||
}
|
||||
|
||||
qsizetype UntypedObjectModel::indexOf(QObject* object) { return this->valuesList.indexOf(object); }
|
||||
|
||||
UntypedObjectModel* UntypedObjectModel::emptyInstance() {
|
||||
static auto* instance = new UntypedObjectModel(nullptr); // NOLINT
|
||||
static auto* instance = new ObjectModel<void>(nullptr);
|
||||
return instance;
|
||||
}
|
||||
+77
-25
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <bit>
|
||||
#include <QtCore/qtmetamacros.h>
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qobject.h>
|
||||
@@ -49,14 +49,11 @@ class UntypedObjectModel: public QAbstractListModel {
|
||||
public:
|
||||
explicit UntypedObjectModel(QObject* parent): QAbstractListModel(parent) {}
|
||||
|
||||
[[nodiscard]] qint32 rowCount(const QModelIndex& parent) const override;
|
||||
[[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override;
|
||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
[[nodiscard]] QList<QObject*> values() const { return this->valuesList; }
|
||||
void removeAt(qsizetype index);
|
||||
[[nodiscard]] virtual QList<QObject*> values() = 0;
|
||||
|
||||
Q_INVOKABLE qsizetype indexOf(QObject* object);
|
||||
Q_INVOKABLE virtual qsizetype indexOf(QObject* object) const = 0;
|
||||
|
||||
static UntypedObjectModel* emptyInstance();
|
||||
|
||||
@@ -71,15 +68,6 @@ signals:
|
||||
/// Sent immediately after an object is removed from the list.
|
||||
void objectRemovedPost(QObject* object, qsizetype index);
|
||||
|
||||
protected:
|
||||
void insertObject(QObject* object, qsizetype index = -1);
|
||||
bool removeObject(const QObject* object);
|
||||
|
||||
// Assumes only one instance of a specific value
|
||||
void diffUpdate(const QVector<QObject*>& newValues);
|
||||
|
||||
QVector<QObject*> valuesList;
|
||||
|
||||
private:
|
||||
static qsizetype valuesCount(QQmlListProperty<QObject>* property);
|
||||
static QObject* valueAt(QQmlListProperty<QObject>* property, qsizetype index);
|
||||
@@ -90,14 +78,20 @@ class ObjectModel: public UntypedObjectModel {
|
||||
public:
|
||||
explicit ObjectModel(QObject* parent): UntypedObjectModel(parent) {}
|
||||
|
||||
[[nodiscard]] QVector<T*>& valueList() { return *std::bit_cast<QVector<T*>*>(&this->valuesList); }
|
||||
|
||||
[[nodiscard]] const QVector<T*>& valueList() const {
|
||||
return *std::bit_cast<const QVector<T*>*>(&this->valuesList);
|
||||
}
|
||||
[[nodiscard]] const QList<T*>& valueList() const { return this->mValuesList; }
|
||||
[[nodiscard]] QList<T*>& valueList() { return this->mValuesList; }
|
||||
|
||||
void insertObject(T* object, qsizetype index = -1) {
|
||||
this->UntypedObjectModel::insertObject(object, index);
|
||||
auto iindex = index == -1 ? this->mValuesList.length() : index;
|
||||
emit this->objectInsertedPre(object, iindex);
|
||||
|
||||
auto intIndex = static_cast<qint32>(iindex);
|
||||
this->beginInsertRows(QModelIndex(), intIndex, intIndex);
|
||||
this->mValuesList.insert(iindex, object);
|
||||
this->endInsertRows();
|
||||
|
||||
emit this->valuesChanged();
|
||||
emit this->objectInsertedPost(object, iindex);
|
||||
}
|
||||
|
||||
void insertObjectSorted(T* object, const std::function<bool(T*, T*)>& compare) {
|
||||
@@ -110,17 +104,75 @@ public:
|
||||
}
|
||||
|
||||
auto idx = iter - list.begin();
|
||||
this->UntypedObjectModel::insertObject(object, idx);
|
||||
this->insertObject(object, idx);
|
||||
}
|
||||
|
||||
void removeObject(const T* object) { this->UntypedObjectModel::removeObject(object); }
|
||||
bool removeObject(const T* object) {
|
||||
auto index = this->mValuesList.indexOf(object);
|
||||
if (index == -1) return false;
|
||||
|
||||
this->removeAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
void removeAt(qsizetype index) {
|
||||
auto* object = this->mValuesList.at(index);
|
||||
emit this->objectRemovedPre(object, index);
|
||||
|
||||
auto intIndex = static_cast<qint32>(index);
|
||||
this->beginRemoveRows(QModelIndex(), intIndex, intIndex);
|
||||
this->mValuesList.removeAt(index);
|
||||
this->endRemoveRows();
|
||||
|
||||
emit this->valuesChanged();
|
||||
emit this->objectRemovedPost(object, index);
|
||||
}
|
||||
|
||||
// Assumes only one instance of a specific value
|
||||
void diffUpdate(const QVector<T*>& newValues) {
|
||||
this->UntypedObjectModel::diffUpdate(*std::bit_cast<const QVector<QObject*>*>(&newValues));
|
||||
void diffUpdate(const QList<T*>& newValues) {
|
||||
for (qsizetype i = 0; i < this->mValuesList.length();) {
|
||||
if (newValues.contains(this->mValuesList.at(i))) i++;
|
||||
else this->removeAt(i);
|
||||
}
|
||||
|
||||
qsizetype oi = 0;
|
||||
for (auto* object: newValues) {
|
||||
if (this->mValuesList.length() == oi || this->mValuesList.at(oi) != object) {
|
||||
// object may already be present further down (reorder case);
|
||||
// drop the old row first so the same pointer is not inserted twice.
|
||||
auto old = this->mValuesList.indexOf(object, oi);
|
||||
if (old != -1) this->removeAt(old);
|
||||
this->insertObject(object, oi);
|
||||
}
|
||||
|
||||
oi++;
|
||||
}
|
||||
}
|
||||
|
||||
static ObjectModel<T>* emptyInstance() {
|
||||
return static_cast<ObjectModel<T>*>(UntypedObjectModel::emptyInstance());
|
||||
}
|
||||
|
||||
[[nodiscard]] qint32 rowCount(const QModelIndex& parent) const override {
|
||||
if (parent != QModelIndex()) return 0;
|
||||
return static_cast<qint32>(this->mValuesList.length());
|
||||
}
|
||||
|
||||
[[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override {
|
||||
if (role != Qt::UserRole) return QVariant();
|
||||
// Values must be QObject derived, but we can't assert that here without breaking forward decls,
|
||||
// so no static_cast.
|
||||
return QVariant::fromValue(reinterpret_cast<QObject*>(this->mValuesList.at(index.row())));
|
||||
}
|
||||
|
||||
qsizetype indexOf(QObject* object) const override {
|
||||
return this->mValuesList.indexOf(reinterpret_cast<T*>(object));
|
||||
}
|
||||
|
||||
[[nodiscard]] QList<QObject*> values() override {
|
||||
return *reinterpret_cast<QList<QObject*>*>(&this->mValuesList);
|
||||
}
|
||||
|
||||
private:
|
||||
QList<T*> mValuesList;
|
||||
};
|
||||
@@ -21,7 +21,6 @@ headers = [
|
||||
"model.hpp",
|
||||
"elapsedtimer.hpp",
|
||||
"desktopentry.hpp",
|
||||
"objectrepeater.hpp",
|
||||
"qsmenu.hpp",
|
||||
"retainable.hpp",
|
||||
"popupanchor.hpp",
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
#include "objectrepeater.hpp"
|
||||
#include <utility>
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qhash.h>
|
||||
#include <qlogging.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlcomponent.h>
|
||||
#include <qqmlcontext.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmllist.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
QVariant ObjectRepeater::model() const { return this->mModel; }
|
||||
|
||||
void ObjectRepeater::setModel(QVariant model) {
|
||||
if (model == this->mModel) return;
|
||||
|
||||
if (this->itemModel != nullptr) {
|
||||
QObject::disconnect(this->itemModel, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mModel = std::move(model);
|
||||
emit this->modelChanged();
|
||||
this->reloadElements();
|
||||
}
|
||||
|
||||
void ObjectRepeater::onModelDestroyed() {
|
||||
this->mModel.clear();
|
||||
this->itemModel = nullptr;
|
||||
emit this->modelChanged();
|
||||
this->reloadElements();
|
||||
}
|
||||
|
||||
QQmlComponent* ObjectRepeater::delegate() const { return this->mDelegate; }
|
||||
|
||||
void ObjectRepeater::setDelegate(QQmlComponent* delegate) {
|
||||
if (delegate == this->mDelegate) return;
|
||||
|
||||
if (this->mDelegate != nullptr) {
|
||||
QObject::disconnect(this->mDelegate, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mDelegate = delegate;
|
||||
|
||||
if (delegate != nullptr) {
|
||||
QObject::connect(
|
||||
this->mDelegate,
|
||||
&QObject::destroyed,
|
||||
this,
|
||||
&ObjectRepeater::onDelegateDestroyed
|
||||
);
|
||||
}
|
||||
|
||||
emit this->delegateChanged();
|
||||
this->reloadElements();
|
||||
}
|
||||
|
||||
void ObjectRepeater::onDelegateDestroyed() {
|
||||
this->mDelegate = nullptr;
|
||||
emit this->delegateChanged();
|
||||
this->reloadElements();
|
||||
}
|
||||
|
||||
void ObjectRepeater::reloadElements() {
|
||||
for (auto i = this->valuesList.length() - 1; i >= 0; i--) {
|
||||
this->removeComponent(i);
|
||||
}
|
||||
|
||||
if (this->mDelegate == nullptr || !this->mModel.isValid()) return;
|
||||
|
||||
if (this->mModel.canConvert<QAbstractItemModel*>()) {
|
||||
auto* model = this->mModel.value<QAbstractItemModel*>();
|
||||
this->itemModel = model;
|
||||
|
||||
this->insertModelElements(model, 0, model->rowCount() - 1); // -1 is fine
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(model, &QObject::destroyed, this, &ObjectRepeater::onModelDestroyed);
|
||||
QObject::connect(model, &QAbstractItemModel::rowsInserted, this, &ObjectRepeater::onModelRowsInserted);
|
||||
QObject::connect(model, &QAbstractItemModel::rowsRemoved, this, &ObjectRepeater::onModelRowsRemoved);
|
||||
QObject::connect(model, &QAbstractItemModel::rowsMoved, this, &ObjectRepeater::onModelRowsMoved);
|
||||
QObject::connect(model, &QAbstractItemModel::modelAboutToBeReset, this, &ObjectRepeater::onModelAboutToBeReset);
|
||||
// clang-format on
|
||||
} else if (this->mModel.canConvert<QQmlListReference>()) {
|
||||
auto values = this->mModel.value<QQmlListReference>();
|
||||
auto len = values.count();
|
||||
|
||||
for (auto i = 0; i != len; i++) {
|
||||
this->insertComponent(i, {{"modelData", QVariant::fromValue(values.at(i))}});
|
||||
}
|
||||
} else if (this->mModel.canConvert<QVector<QVariant>>()) {
|
||||
auto values = this->mModel.value<QVector<QVariant>>();
|
||||
|
||||
for (auto& value: values) {
|
||||
this->insertComponent(this->valuesList.length(), {{"modelData", value}});
|
||||
}
|
||||
} else {
|
||||
qCritical() << this
|
||||
<< "Cannot create components as the model is not compatible:" << this->mModel;
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectRepeater::insertModelElements(QAbstractItemModel* model, int first, int last) {
|
||||
auto roles = model->roleNames();
|
||||
auto roleDataVec = QVector<QModelRoleData>();
|
||||
for (auto id: roles.keys()) {
|
||||
roleDataVec.push_back(QModelRoleData(id));
|
||||
}
|
||||
|
||||
auto values = QModelRoleDataSpan(roleDataVec);
|
||||
auto props = QVariantMap();
|
||||
|
||||
for (auto i = first; i != last + 1; i++) {
|
||||
auto index = model->index(i, 0);
|
||||
model->multiData(index, values);
|
||||
|
||||
for (auto [id, name]: roles.asKeyValueRange()) {
|
||||
props.insert(name, *values.dataForRole(id));
|
||||
}
|
||||
|
||||
this->insertComponent(i, props);
|
||||
|
||||
props.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectRepeater::onModelRowsInserted(const QModelIndex& parent, int first, int last) {
|
||||
if (parent != QModelIndex()) return;
|
||||
|
||||
this->insertModelElements(this->itemModel, first, last);
|
||||
}
|
||||
|
||||
void ObjectRepeater::onModelRowsRemoved(const QModelIndex& parent, int first, int last) {
|
||||
if (parent != QModelIndex()) return;
|
||||
|
||||
for (auto i = last; i != first - 1; i--) {
|
||||
this->removeComponent(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectRepeater::onModelRowsMoved(
|
||||
const QModelIndex& sourceParent,
|
||||
int sourceStart,
|
||||
int sourceEnd,
|
||||
const QModelIndex& destParent,
|
||||
int destStart
|
||||
) {
|
||||
auto hasSource = sourceParent != QModelIndex();
|
||||
auto hasDest = destParent != QModelIndex();
|
||||
|
||||
if (!hasSource && !hasDest) return;
|
||||
|
||||
if (hasSource) {
|
||||
this->onModelRowsRemoved(sourceParent, sourceStart, sourceEnd);
|
||||
}
|
||||
|
||||
if (hasDest) {
|
||||
this->onModelRowsInserted(destParent, destStart, destStart + (sourceEnd - sourceStart));
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectRepeater::onModelAboutToBeReset() {
|
||||
auto last = static_cast<int>(this->valuesList.length() - 1);
|
||||
this->onModelRowsRemoved(QModelIndex(), 0, last); // -1 is fine
|
||||
}
|
||||
|
||||
void ObjectRepeater::insertComponent(qsizetype index, const QVariantMap& properties) {
|
||||
auto* context = QQmlEngine::contextForObject(this);
|
||||
auto* instance = this->mDelegate->createWithInitialProperties(properties, context);
|
||||
|
||||
if (instance == nullptr) {
|
||||
qWarning().noquote() << this->mDelegate->errorString();
|
||||
qWarning() << this << "failed to create object for model data" << properties;
|
||||
} else {
|
||||
QQmlEngine::setObjectOwnership(instance, QQmlEngine::CppOwnership);
|
||||
instance->setParent(this);
|
||||
}
|
||||
|
||||
this->insertObject(instance, index);
|
||||
}
|
||||
|
||||
void ObjectRepeater::removeComponent(qsizetype index) {
|
||||
auto* instance = this->valuesList.at(index);
|
||||
this->removeAt(index);
|
||||
delete instance;
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlcomponent.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
#include "model.hpp"
|
||||
|
||||
///! A Repeater / for loop / map for non Item derived objects.
|
||||
/// > [!ERROR] Removed in favor of @@QtQml.Models.Instantiator
|
||||
///
|
||||
/// The ObjectRepeater creates instances of the provided delegate for every entry in the
|
||||
/// given model, similarly to a @@QtQuick.Repeater but for non visual types.
|
||||
class ObjectRepeater: public ObjectModel<QObject> {
|
||||
Q_OBJECT;
|
||||
/// The model providing data to the ObjectRepeater.
|
||||
///
|
||||
/// Currently accepted model types are `list<T>` lists, javascript arrays,
|
||||
/// and [QAbstractListModel] derived models, though only one column will be repeated
|
||||
/// from the latter.
|
||||
///
|
||||
/// Note: @@ObjectModel is a [QAbstractListModel] with a single column.
|
||||
///
|
||||
/// [QAbstractListModel]: https://doc.qt.io/qt-6/qabstractlistmodel.html
|
||||
Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged);
|
||||
/// The delegate component to repeat.
|
||||
///
|
||||
/// The delegate is given the same properties as in a Repeater, except `index` which
|
||||
/// is not currently implemented.
|
||||
///
|
||||
/// If the model is a `list<T>` or javascript array, a `modelData` property will be
|
||||
/// exposed containing the entry from the model. If the model is a [QAbstractListModel],
|
||||
/// the roles from the model will be exposed.
|
||||
///
|
||||
/// Note: @@ObjectModel has a single role named `modelData` for compatibility with normal lists.
|
||||
///
|
||||
/// [QAbstractListModel]: https://doc.qt.io/qt-6/qabstractlistmodel.html
|
||||
Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged);
|
||||
Q_CLASSINFO("DefaultProperty", "delegate");
|
||||
QML_ELEMENT;
|
||||
QML_UNCREATABLE("ObjectRepeater has been removed in favor of QtQml.Models.Instantiator.");
|
||||
|
||||
public:
|
||||
explicit ObjectRepeater(QObject* parent = nullptr): ObjectModel(parent) {}
|
||||
|
||||
[[nodiscard]] QVariant model() const;
|
||||
void setModel(QVariant model);
|
||||
|
||||
[[nodiscard]] QQmlComponent* delegate() const;
|
||||
void setDelegate(QQmlComponent* delegate);
|
||||
|
||||
signals:
|
||||
void modelChanged();
|
||||
void delegateChanged();
|
||||
|
||||
private slots:
|
||||
void onDelegateDestroyed();
|
||||
void onModelDestroyed();
|
||||
void onModelRowsInserted(const QModelIndex& parent, int first, int last);
|
||||
void onModelRowsRemoved(const QModelIndex& parent, int first, int last);
|
||||
|
||||
void onModelRowsMoved(
|
||||
const QModelIndex& sourceParent,
|
||||
int sourceStart,
|
||||
int sourceEnd,
|
||||
const QModelIndex& destParent,
|
||||
int destStart
|
||||
);
|
||||
|
||||
void onModelAboutToBeReset();
|
||||
|
||||
private:
|
||||
void reloadElements();
|
||||
void insertModelElements(QAbstractItemModel* model, int first, int last);
|
||||
void insertComponent(qsizetype index, const QVariantMap& properties);
|
||||
void removeComponent(qsizetype index);
|
||||
|
||||
QVariant mModel;
|
||||
QAbstractItemModel* itemModel = nullptr;
|
||||
QQmlComponent* mDelegate = nullptr;
|
||||
};
|
||||
+39
-15
@@ -1,6 +1,7 @@
|
||||
#include "paths.hpp"
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include <fcntl.h>
|
||||
@@ -9,7 +10,6 @@
|
||||
#include <qdir.h>
|
||||
#include <qlogging.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qpair.h>
|
||||
#include <qstandardpaths.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qtversionchecks.h>
|
||||
@@ -27,12 +27,19 @@ QsPaths* QsPaths::instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
void QsPaths::init(QString shellId, QString pathId, QString dataOverride, QString stateOverride) {
|
||||
void QsPaths::init(
|
||||
QString shellId,
|
||||
QString pathId,
|
||||
QString dataOverride,
|
||||
QString stateOverride,
|
||||
QString cacheOverride
|
||||
) {
|
||||
auto* instance = QsPaths::instance();
|
||||
instance->shellId = std::move(shellId);
|
||||
instance->pathId = std::move(pathId);
|
||||
instance->shellDataOverride = std::move(dataOverride);
|
||||
instance->shellStateOverride = std::move(stateOverride);
|
||||
instance->shellCacheOverride = std::move(cacheOverride);
|
||||
}
|
||||
|
||||
QDir QsPaths::crashDir(const QString& id) {
|
||||
@@ -57,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;
|
||||
}
|
||||
|
||||
@@ -168,7 +175,8 @@ void QsPaths::linkRunDir() {
|
||||
auto* shellDir = this->shellRunDir();
|
||||
|
||||
if (!shellDir) {
|
||||
qCCritical(logPaths
|
||||
qCCritical(
|
||||
logPaths
|
||||
) << "Could not create by-id symlink as the shell runtime path could not be created.";
|
||||
} else {
|
||||
auto shellPath = shellDir->filePath(runDir->dirName());
|
||||
@@ -316,9 +324,16 @@ QDir QsPaths::shellStateDir() {
|
||||
|
||||
QDir QsPaths::shellCacheDir() {
|
||||
if (this->shellCacheState == DirState::Unknown) {
|
||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
dir = QDir(dir.filePath("by-shell"));
|
||||
dir = QDir(dir.filePath(this->shellId));
|
||||
QDir dir;
|
||||
if (this->shellCacheOverride.isEmpty()) {
|
||||
dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
dir = QDir(dir.filePath("by-shell"));
|
||||
dir = QDir(dir.filePath(this->shellId));
|
||||
} else {
|
||||
auto basedir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
|
||||
dir = QDir(this->shellCacheOverride.replace("$BASE", basedir));
|
||||
}
|
||||
|
||||
this->mShellCacheDir = dir;
|
||||
|
||||
qCDebug(logPaths) << "Initialized cache path:" << dir.path();
|
||||
@@ -346,7 +361,7 @@ void QsPaths::createLock() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = flock {
|
||||
struct flock lock = {
|
||||
.l_type = F_WRLCK,
|
||||
.l_whence = SEEK_SET,
|
||||
.l_start = 0,
|
||||
@@ -364,7 +379,8 @@ void QsPaths::createLock() {
|
||||
qCDebug(logPaths) << "Created instance lock at" << path;
|
||||
}
|
||||
} else {
|
||||
qCCritical(logPaths
|
||||
qCCritical(
|
||||
logPaths
|
||||
) << "Could not create instance lock, as the instance runtime directory could not be created.";
|
||||
}
|
||||
}
|
||||
@@ -373,7 +389,7 @@ bool QsPaths::checkLock(const QString& path, InstanceLockInfo* info, bool allowD
|
||||
auto file = QFile(QDir(path).filePath("instance.lock"));
|
||||
if (!file.open(QFile::ReadOnly)) return false;
|
||||
|
||||
auto lock = flock {
|
||||
struct flock lock = {
|
||||
.l_type = F_WRLCK,
|
||||
.l_whence = SEEK_SET,
|
||||
.l_start = 0,
|
||||
@@ -396,10 +412,11 @@ bool QsPaths::checkLock(const QString& path, InstanceLockInfo* info, bool allowD
|
||||
return true;
|
||||
}
|
||||
|
||||
QPair<QVector<InstanceLockInfo>, QVector<InstanceLockInfo>>
|
||||
QsPaths::collectInstances(const QString& path) {
|
||||
std::tuple<QVector<InstanceLockInfo>, QVector<InstanceLockInfo>, QVector<InstanceLockInfo>>
|
||||
QsPaths::collectInstances(const QString& path, const QString& display) {
|
||||
qCDebug(logPaths) << "Collecting instances from" << path;
|
||||
auto liveInstances = QVector<InstanceLockInfo>();
|
||||
auto mismatchedInstances = QVector<InstanceLockInfo>();
|
||||
auto deadInstances = QVector<InstanceLockInfo>();
|
||||
auto dir = QDir(path);
|
||||
|
||||
@@ -413,13 +430,20 @@ QsPaths::collectInstances(const QString& path) {
|
||||
|
||||
if (info.pid == -1) {
|
||||
deadInstances.push_back(info);
|
||||
} else {
|
||||
liveInstances.push_back(info);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!display.isEmpty() && info.instance.display != display) {
|
||||
qCDebug(logPaths) << "Skipped instance with mismatched display at" << path;
|
||||
mismatchedInstances.push_back(info);
|
||||
continue;
|
||||
}
|
||||
|
||||
liveInstances.push_back(info);
|
||||
} else {
|
||||
qCDebug(logPaths) << "Skipped potential instance at" << path;
|
||||
}
|
||||
}
|
||||
|
||||
return qMakePair(liveInstances, deadInstances);
|
||||
return {liveInstances, mismatchedInstances, deadInstances};
|
||||
}
|
||||
+13
-3
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qdir.h>
|
||||
#include <qpair.h>
|
||||
@@ -17,14 +20,20 @@ QDataStream& operator>>(QDataStream& stream, InstanceLockInfo& info);
|
||||
class QsPaths {
|
||||
public:
|
||||
static QsPaths* instance();
|
||||
static void init(QString shellId, QString pathId, QString dataOverride, QString stateOverride);
|
||||
static void init(
|
||||
QString shellId,
|
||||
QString pathId,
|
||||
QString dataOverride,
|
||||
QString stateOverride,
|
||||
QString cacheOverride
|
||||
);
|
||||
static QDir crashDir(const QString& id);
|
||||
static QString basePath(const QString& id);
|
||||
static QString ipcPath(const QString& id);
|
||||
static bool
|
||||
checkLock(const QString& path, InstanceLockInfo* info = nullptr, bool allowDead = false);
|
||||
static QPair<QVector<InstanceLockInfo>, QVector<InstanceLockInfo>>
|
||||
collectInstances(const QString& path);
|
||||
static std::tuple<QVector<InstanceLockInfo>, QVector<InstanceLockInfo>, QVector<InstanceLockInfo>>
|
||||
collectInstances(const QString& path, const QString& display);
|
||||
|
||||
QDir* baseRunDir();
|
||||
QDir* shellRunDir();
|
||||
@@ -65,4 +74,5 @@ private:
|
||||
|
||||
QString shellDataOverride;
|
||||
QString shellStateOverride;
|
||||
QString shellCacheOverride;
|
||||
};
|
||||
@@ -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();
|
||||
|
||||
+12
-13
@@ -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 {
|
||||
@@ -28,7 +27,7 @@ void PopupAnchor::markClean() { this->lastState = this->state; }
|
||||
void PopupAnchor::markDirty() { this->lastState.reset(); }
|
||||
|
||||
QWindow* PopupAnchor::backingWindow() const {
|
||||
return this->mProxyWindow ? this->mProxyWindow->backingWindow() : nullptr;
|
||||
return this->bProxyWindow ? this->bProxyWindow->backingWindow() : nullptr;
|
||||
}
|
||||
|
||||
void PopupAnchor::setWindowInternal(QObject* window) {
|
||||
@@ -36,14 +35,12 @@ void PopupAnchor::setWindowInternal(QObject* window) {
|
||||
|
||||
if (this->mWindow) {
|
||||
QObject::disconnect(this->mWindow, nullptr, this, nullptr);
|
||||
QObject::disconnect(this->mProxyWindow, nullptr, this, nullptr);
|
||||
QObject::disconnect(this->bProxyWindow, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
if (window) {
|
||||
if (auto* proxy = qobject_cast<ProxyWindowBase*>(window)) {
|
||||
this->mProxyWindow = proxy;
|
||||
} else if (auto* interface = qobject_cast<WindowInterface*>(window)) {
|
||||
this->mProxyWindow = interface->proxyWindow();
|
||||
if (auto* proxy = ProxyWindowBase::forObject(window)) {
|
||||
this->bProxyWindow = proxy;
|
||||
} else {
|
||||
qWarning() << "Tried to set popup anchor window to" << window
|
||||
<< "which is not a quickshell window.";
|
||||
@@ -55,7 +52,7 @@ void PopupAnchor::setWindowInternal(QObject* window) {
|
||||
QObject::connect(this->mWindow, &QObject::destroyed, this, &PopupAnchor::onWindowDestroyed);
|
||||
|
||||
QObject::connect(
|
||||
this->mProxyWindow,
|
||||
this->bProxyWindow,
|
||||
&ProxyWindowBase::backerVisibilityChanged,
|
||||
this,
|
||||
&PopupAnchor::backingWindowVisibilityChanged
|
||||
@@ -70,7 +67,7 @@ void PopupAnchor::setWindowInternal(QObject* window) {
|
||||
setnull:
|
||||
if (this->mWindow) {
|
||||
this->mWindow = nullptr;
|
||||
this->mProxyWindow = nullptr;
|
||||
this->bProxyWindow = nullptr;
|
||||
|
||||
emit this->windowChanged();
|
||||
emit this->backingWindowVisibilityChanged();
|
||||
@@ -96,11 +93,13 @@ void PopupAnchor::setItem(QQuickItem* item) {
|
||||
QObject::connect(item, &QObject::destroyed, this, &PopupAnchor::onItemDestroyed);
|
||||
QObject::connect(item, &QQuickItem::windowChanged, this, &PopupAnchor::onItemWindowChanged);
|
||||
}
|
||||
|
||||
emit this->itemChanged();
|
||||
}
|
||||
|
||||
void PopupAnchor::onWindowDestroyed() {
|
||||
this->mWindow = nullptr;
|
||||
this->mProxyWindow = nullptr;
|
||||
this->bProxyWindow = nullptr;
|
||||
emit this->windowChanged();
|
||||
emit this->backingWindowVisibilityChanged();
|
||||
}
|
||||
@@ -112,7 +111,7 @@ void PopupAnchor::onItemDestroyed() {
|
||||
}
|
||||
|
||||
void PopupAnchor::onItemWindowChanged() {
|
||||
if (auto* window = qobject_cast<ProxiedWindow*>(this->mItem->window())) {
|
||||
if (auto* window = qobject_cast<ProxiedWindow*>(this->mItem ? this->mItem->window() : nullptr)) {
|
||||
this->setWindowInternal(window->proxy());
|
||||
} else {
|
||||
this->setWindowInternal(nullptr);
|
||||
@@ -186,11 +185,11 @@ void PopupAnchor::updatePlacement(const QPoint& anchorpoint, const QSize& size)
|
||||
}
|
||||
|
||||
void PopupAnchor::updateAnchor() {
|
||||
if (this->mItem && this->mProxyWindow) {
|
||||
if (this->mItem && this->bProxyWindow) {
|
||||
auto baseRect =
|
||||
this->mUserRect.isEmpty() ? this->mItem->boundingRect() : this->mUserRect.qrect();
|
||||
|
||||
auto rect = this->mProxyWindow->contentItem()->mapFromItem(
|
||||
auto rect = this->bProxyWindow->contentItem()->mapFromItem(
|
||||
this->mItem,
|
||||
baseRect.marginsRemoved(this->mMargins.qmargins())
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qpoint.h>
|
||||
#include <qproperty.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qquickitem.h>
|
||||
#include <qsize.h>
|
||||
@@ -139,7 +140,9 @@ public:
|
||||
void markDirty();
|
||||
|
||||
[[nodiscard]] QObject* window() const { return this->mWindow; }
|
||||
[[nodiscard]] ProxyWindowBase* proxyWindow() const { return this->mProxyWindow; }
|
||||
[[nodiscard]] QBindable<ProxyWindowBase*> bindableProxyWindow() const {
|
||||
return &this->bProxyWindow;
|
||||
}
|
||||
[[nodiscard]] QWindow* backingWindow() const;
|
||||
void setWindowInternal(QObject* window);
|
||||
void setWindow(QObject* window);
|
||||
@@ -193,11 +196,12 @@ private slots:
|
||||
private:
|
||||
QObject* mWindow = nullptr;
|
||||
QQuickItem* mItem = nullptr;
|
||||
ProxyWindowBase* mProxyWindow = nullptr;
|
||||
PopupAnchorState state;
|
||||
Box mUserRect;
|
||||
Margins mMargins;
|
||||
std::optional<PopupAnchorState> lastState;
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(PopupAnchor, ProxyWindowBase*, bProxyWindow);
|
||||
};
|
||||
|
||||
class PopupPositioner {
|
||||
|
||||
+39
-1
@@ -18,17 +18,21 @@
|
||||
#include <qscreen.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtversion.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
#include <qversionnumber.h>
|
||||
#include <qwindowdefs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../io/processcore.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "iconimageprovider.hpp"
|
||||
#include "instanceinfo.hpp"
|
||||
#include "paths.hpp"
|
||||
#include "qmlscreen.hpp"
|
||||
#include "rootwrapper.hpp"
|
||||
#include "scanenv.hpp"
|
||||
|
||||
QuickshellSettings::QuickshellSettings() {
|
||||
QObject::connect(
|
||||
@@ -59,7 +63,9 @@ void QuickshellSettings::setWorkingDirectory(QString workingDirectory) { // NOLI
|
||||
emit this->workingDirectoryChanged();
|
||||
}
|
||||
|
||||
bool QuickshellSettings::watchFiles() const { return this->mWatchFiles; }
|
||||
bool QuickshellSettings::watchFiles() const {
|
||||
return this->mWatchFiles && qEnvironmentVariableIsEmpty("QS_DISABLE_FILE_WATCHER");
|
||||
}
|
||||
|
||||
void QuickshellSettings::setWatchFiles(bool watchFiles) {
|
||||
if (watchFiles == this->mWatchFiles) return;
|
||||
@@ -150,6 +156,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();
|
||||
}
|
||||
@@ -313,6 +335,22 @@ QString QuickshellGlobal::iconPath(const QString& icon, const QString& fallback)
|
||||
return IconImageProvider::requestString(icon, "", fallback);
|
||||
}
|
||||
|
||||
bool QuickshellGlobal::hasThemeIcon(const QString& icon) { return QIcon::hasThemeIcon(icon); }
|
||||
|
||||
bool QuickshellGlobal::hasVersion(qint32 major, qint32 minor, const QStringList& features) {
|
||||
return qs::scan::env::PreprocEnv::hasVersion(major, minor, features);
|
||||
}
|
||||
|
||||
bool QuickshellGlobal::hasVersion(qint32 major, qint32 minor) {
|
||||
return QuickshellGlobal::hasVersion(major, minor, QStringList());
|
||||
}
|
||||
|
||||
bool QuickshellGlobal::hasQtVersion(int major, int minor) {
|
||||
auto qtVersion = QVersionNumber::fromString(qVersion());
|
||||
auto requiredVersion = QVersionNumber(major, minor);
|
||||
return qtVersion >= requiredVersion;
|
||||
}
|
||||
|
||||
QuickshellGlobal* QuickshellGlobal::create(QQmlEngine* engine, QJSEngine* /*unused*/) {
|
||||
auto* qsg = new QuickshellGlobal();
|
||||
auto* generation = EngineGeneration::findEngineGeneration(engine);
|
||||
|
||||
+53
-2
@@ -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.
|
||||
@@ -127,18 +143,21 @@ class QuickshellGlobal: public QObject {
|
||||
/// Usually `~/.local/share/quickshell/by-shell/<shell-id>`
|
||||
///
|
||||
/// Can be overridden using `//@ pragma DataDir $BASE/path` in the root qml file, where `$BASE`
|
||||
/// corrosponds to `$XDG_DATA_HOME` (usually `~/.local/share`).
|
||||
/// corresponds to `$XDG_DATA_HOME` (usually `~/.local/share`).
|
||||
Q_PROPERTY(QString dataDir READ dataDir CONSTANT);
|
||||
/// The per-shell state directory.
|
||||
///
|
||||
/// Usually `~/.local/state/quickshell/by-shell/<shell-id>`
|
||||
///
|
||||
/// Can be overridden using `//@ pragma StateDir $BASE/path` in the root qml file, where `$BASE`
|
||||
/// corrosponds to `$XDG_STATE_HOME` (usually `~/.local/state`).
|
||||
/// corresponds to `$XDG_STATE_HOME` (usually `~/.local/state`).
|
||||
Q_PROPERTY(QString stateDir READ stateDir CONSTANT);
|
||||
/// The per-shell cache directory.
|
||||
///
|
||||
/// Usually `~/.cache/quickshell/by-shell/<shell-id>`
|
||||
///
|
||||
/// Can be overridden using `//@ pragma CacheDir $BASE/path` in the root qml file, where `$BASE`
|
||||
/// corresponds to `$XDG_CACHE_HOME` (usually `~/.cache`).
|
||||
Q_PROPERTY(QString cacheDir READ cacheDir CONSTANT);
|
||||
// clang-format on
|
||||
QML_SINGLETON;
|
||||
@@ -146,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();
|
||||
|
||||
@@ -199,6 +222,8 @@ public:
|
||||
/// Setting the `fallback` parameter of `iconPath` will attempt to load the fallback
|
||||
/// icon if the requested one could not be loaded.
|
||||
Q_INVOKABLE static QString iconPath(const QString& icon, const QString& fallback);
|
||||
/// Check if specified icon has an available icon in your icon theme
|
||||
Q_INVOKABLE static bool hasThemeIcon(const QString& icon);
|
||||
/// Equivalent to `${Quickshell.configDir}/${path}`
|
||||
Q_INVOKABLE [[nodiscard]] QString shellPath(const QString& path) const;
|
||||
/// > [!WARNING] Deprecated: Renamed to @@shellPath() for clarity.
|
||||
@@ -214,6 +239,32 @@ public:
|
||||
///
|
||||
/// The popup can also be blocked by setting `QS_NO_RELOAD_POPUP=1`.
|
||||
Q_INVOKABLE void inhibitReloadPopup() { this->mInhibitReloadPopup = true; }
|
||||
/// Check if Quickshell's version is at least `major.minor` and the listed
|
||||
/// unreleased features are available. If Quickshell is newer than the given version
|
||||
/// it is assumed that all unreleased features are present. The unreleased feature list
|
||||
/// may be omitted.
|
||||
///
|
||||
/// > [!NOTE] You can version gate code blocks using Quickshell's preprocessor which
|
||||
/// > has the same function available.
|
||||
/// >
|
||||
/// > ```qml
|
||||
/// > //@ if hasVersion(0, 3, ["feature"])
|
||||
/// > ...
|
||||
/// > //@ endif
|
||||
/// > ```
|
||||
Q_INVOKABLE static bool hasVersion(qint32 major, qint32 minor, const QStringList& features);
|
||||
Q_INVOKABLE static bool hasVersion(qint32 major, qint32 minor);
|
||||
/// Check if Qt's version is at least `major.minor`.
|
||||
///
|
||||
/// > [!NOTE] You can version gate code blocks using Quickshell's preprocessor which
|
||||
/// > has the same function available.
|
||||
/// >
|
||||
/// > ```qml
|
||||
/// > //@ if hasVersion(6, 10)
|
||||
/// > ...
|
||||
/// > //@ endif
|
||||
/// > ```
|
||||
Q_INVOKABLE static bool hasQtVersion(qint32 major, qint32 minor);
|
||||
|
||||
void clearReloadPopupInhibit() { this->mInhibitReloadPopup = false; }
|
||||
[[nodiscard]] bool isReloadPopupInhibited() const { return this->mInhibitReloadPopup; }
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
/// Monitor object useful for setting the monitor for a @@QsWindow
|
||||
/// or querying information about the monitor.
|
||||
///
|
||||
/// > [!WARNING] If the monitor is disconnected than any stored copies of its ShellMonitor will
|
||||
/// > [!WARNING] If the monitor is disconnected, then any stored copies of its ShellMonitor will
|
||||
/// > be marked as dangling and all properties will return default values.
|
||||
/// > Reconnecting the monitor will not reconnect it to the ShellMonitor object.
|
||||
///
|
||||
|
||||
+134
-1
@@ -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);
|
||||
}
|
||||
@@ -109,7 +242,7 @@ QRegion PendingRegion::applyTo(QRegion& region) const {
|
||||
}
|
||||
|
||||
QRegion PendingRegion::applyTo(const QRect& rect) const {
|
||||
// if left as the default, dont combine it with the whole rect area, leave it as is.
|
||||
// if left as the default, don't combine it with the whole rect area, leave it as is.
|
||||
if (this->mIntersection == Intersection::Combine) {
|
||||
return this->build();
|
||||
} else {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
+1
-1
@@ -116,7 +116,7 @@ QObject* Reloadable::getChildByReloadId(QObject* parent, const QString& reloadId
|
||||
auto* reloadable = qobject_cast<Reloadable*>(child);
|
||||
if (reloadable != nullptr) {
|
||||
if (reloadable->mReloadableId == reloadId) return reloadable;
|
||||
// if not then don't check its children as thats a seperate reload scope.
|
||||
// if not then don't check its children as that's a separate reload scope.
|
||||
} else {
|
||||
auto* reloadable = Reloadable::getChildByReloadId(child, reloadId);
|
||||
if (reloadable != nullptr) return reloadable;
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ class Reloadable
|
||||
/// previous state.
|
||||
///
|
||||
/// Simply keeping a stable identifier across config versions (saves) is
|
||||
/// enough to help the reloader figure out which object in the old revision corrosponds to
|
||||
/// enough to help the reloader figure out which object in the old revision corresponds to
|
||||
/// this object in the current revision, and facilitate smoother reloading.
|
||||
///
|
||||
/// Note that identifiers are scoped, and will try to do the right thing in context.
|
||||
|
||||
@@ -63,9 +63,6 @@ void RootWrapper::reloadGraph(bool hard) {
|
||||
qs::core::QmlToolingSupport::updateTooling(rootPath, scanner);
|
||||
this->configDirWatcher.addPath(rootPath.path());
|
||||
|
||||
auto* generation = new EngineGeneration(rootPath, std::move(scanner));
|
||||
generation->wrapper = this;
|
||||
|
||||
// todo: move into EngineGeneration
|
||||
if (this->generation != nullptr) {
|
||||
qInfo() << "Reloading configuration...";
|
||||
@@ -74,6 +71,33 @@ void RootWrapper::reloadGraph(bool hard) {
|
||||
|
||||
QDir::setCurrent(this->originalWorkingDirectory);
|
||||
|
||||
if (!scanner.scanErrors.isEmpty()) {
|
||||
qCritical() << "Failed to load configuration";
|
||||
QString errorString = "Failed to load configuration";
|
||||
for (auto& error: scanner.scanErrors) {
|
||||
const auto& file = error.file;
|
||||
QString rel;
|
||||
if (file.startsWith(rootPath.path() % '/')) {
|
||||
rel = '@' % file.sliced(rootPath.path().length() + 1);
|
||||
} else {
|
||||
rel = file;
|
||||
}
|
||||
|
||||
auto msg = " error in " % rel % '[' % QString::number(error.line) % ":0]: " % error.message;
|
||||
errorString += '\n' % msg;
|
||||
qCritical().noquote() << msg;
|
||||
}
|
||||
|
||||
if (this->generation != nullptr && this->generation->qsgInstance != nullptr) {
|
||||
emit this->generation->qsgInstance->reloadFailed(errorString);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto* generation = new EngineGeneration(rootPath, std::move(scanner));
|
||||
generation->wrapper = this;
|
||||
|
||||
QUrl url;
|
||||
url.setScheme("qs");
|
||||
url.setPath("@/qs/" % rootFile.fileName());
|
||||
|
||||
+147
-55
@@ -1,9 +1,12 @@
|
||||
#include "scan.hpp"
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qcryptographichash.h>
|
||||
#include <qdir.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qjsonarray.h>
|
||||
#include <qjsondocument.h>
|
||||
#include <qjsonobject.h>
|
||||
@@ -12,19 +15,39 @@
|
||||
#include <qloggingcategory.h>
|
||||
#include <qpair.h>
|
||||
#include <qstring.h>
|
||||
#include <qstringliteral.h>
|
||||
#include <qtextstream.h>
|
||||
|
||||
#include "logcat.hpp"
|
||||
#include "scanenv.hpp"
|
||||
|
||||
QS_LOGGING_CATEGORY(logQmlScanner, "quickshell.qmlscanner", QtWarningMsg);
|
||||
|
||||
void QmlScanner::scanDir(const QString& path) {
|
||||
if (this->scannedDirs.contains(path)) return;
|
||||
this->scannedDirs.push_back(path);
|
||||
bool QmlScanner::readAndHashFile(const QString& path, QByteArray& data) {
|
||||
auto file = QFile(path);
|
||||
if (!file.open(QFile::ReadOnly)) return false;
|
||||
data = file.readAll();
|
||||
this->fileHashes.insert(path, QCryptographicHash::hash(data, QCryptographicHash::Md5));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QmlScanner::hasFileContentChanged(const QString& path) const {
|
||||
auto it = this->fileHashes.constFind(path);
|
||||
if (it == this->fileHashes.constEnd()) return true;
|
||||
|
||||
auto file = QFile(path);
|
||||
if (!file.open(QFile::ReadOnly)) return true;
|
||||
|
||||
auto newHash = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md5);
|
||||
return newHash != it.value();
|
||||
}
|
||||
|
||||
void QmlScanner::scanDir(const QDir& dir) {
|
||||
if (this->scannedDirs.contains(dir)) return;
|
||||
this->scannedDirs.push_back(dir);
|
||||
|
||||
const auto& path = dir.path();
|
||||
|
||||
qCDebug(logQmlScanner) << "Scanning directory" << path;
|
||||
auto dir = QDir(path);
|
||||
|
||||
struct Entry {
|
||||
QString name;
|
||||
@@ -37,7 +60,8 @@ void QmlScanner::scanDir(const QString& path) {
|
||||
|
||||
for (auto& name: dir.entryList(QDir::Files | QDir::NoDotAndDotDot)) {
|
||||
if (name == "qmldir") {
|
||||
qCDebug(logQmlScanner
|
||||
qCDebug(
|
||||
logQmlScanner
|
||||
) << "Found qmldir file, qmldir synthesization will be disabled for directory"
|
||||
<< path;
|
||||
seenQmldir = true;
|
||||
@@ -65,7 +89,7 @@ void QmlScanner::scanDir(const QString& path) {
|
||||
QString qmldir;
|
||||
auto stream = QTextStream(&qmldir);
|
||||
|
||||
// cant derive a module name if not in shell path
|
||||
// can't derive a module name if not in shell path
|
||||
if (path.startsWith(this->rootPath.path())) {
|
||||
auto end = path.sliced(this->rootPath.path().length());
|
||||
|
||||
@@ -105,68 +129,125 @@ bool QmlScanner::scanQmlFile(const QString& path, bool& singleton, bool& interna
|
||||
|
||||
qCDebug(logQmlScanner) << "Scanning qml file" << path;
|
||||
|
||||
auto file = QFile(path);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
QByteArray fileData;
|
||||
if (!this->readAndHashFile(path, fileData)) {
|
||||
qCWarning(logQmlScanner) << "Failed to open file" << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto stream = QTextStream(&file);
|
||||
auto stream = QTextStream(&fileData);
|
||||
auto imports = QVector<QString>();
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
auto line = stream.readLine().trimmed();
|
||||
if (!singleton && line == "pragma Singleton") {
|
||||
singleton = true;
|
||||
} else if (!internal && line == "//@ pragma Internal") {
|
||||
internal = true;
|
||||
} else if (line.startsWith("import")) {
|
||||
// we dont care about "import qs" as we always load the root folder
|
||||
if (auto importCursor = line.indexOf(" qs."); importCursor != -1) {
|
||||
importCursor += 4;
|
||||
QString path;
|
||||
bool inHeader = true;
|
||||
auto ifScopes = QVector<bool>();
|
||||
bool sourceMasked = false;
|
||||
int lineNum = 0;
|
||||
QString overrideText;
|
||||
bool isOverridden = false;
|
||||
|
||||
while (importCursor != line.length()) {
|
||||
auto c = line.at(importCursor);
|
||||
if (c == '.') c = '/';
|
||||
else if (c == ' ') break;
|
||||
else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
|
||||
|| c == '_')
|
||||
{
|
||||
} else {
|
||||
qCWarning(logQmlScanner) << "Import line contains invalid characters: " << line;
|
||||
goto next;
|
||||
auto& pragmaEngine = *QmlScanner::preprocEngine();
|
||||
|
||||
auto postError = [&, this](QString error) {
|
||||
this->scanErrors.append({.file = path, .message = std::move(error), .line = lineNum});
|
||||
};
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
++lineNum;
|
||||
bool hideMask = false;
|
||||
auto rawLine = stream.readLine();
|
||||
auto line = rawLine.trimmed();
|
||||
if (!sourceMasked && inHeader) {
|
||||
if (!singleton && line == "pragma Singleton") {
|
||||
singleton = true;
|
||||
} else if (line.startsWith("import")) {
|
||||
// we don't care about "import qs" as we always load the root folder
|
||||
if (auto importCursor = line.indexOf(" qs."); importCursor != -1) {
|
||||
importCursor += 4;
|
||||
QString path;
|
||||
|
||||
while (importCursor != line.length()) {
|
||||
auto c = line.at(importCursor);
|
||||
if (c == '.') c = '/';
|
||||
else if (c == ' ') break;
|
||||
else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
|
||||
|| c == '_')
|
||||
{
|
||||
} else {
|
||||
qCWarning(logQmlScanner) << "Import line contains invalid characters: " << line;
|
||||
goto next;
|
||||
}
|
||||
|
||||
path.append(c);
|
||||
importCursor += 1;
|
||||
}
|
||||
|
||||
path.append(c);
|
||||
importCursor += 1;
|
||||
imports.append(this->rootPath.filePath(path));
|
||||
} else if (auto startQuot = line.indexOf('"');
|
||||
startQuot != -1 && line.length() >= startQuot + 3)
|
||||
{
|
||||
auto endQuot = line.indexOf('"', startQuot + 1);
|
||||
if (endQuot == -1) continue;
|
||||
|
||||
auto name = line.sliced(startQuot + 1, endQuot - startQuot - 1);
|
||||
imports.push_back(name);
|
||||
}
|
||||
|
||||
imports.append(this->rootPath.filePath(path));
|
||||
} else if (auto startQuot = line.indexOf('"');
|
||||
startQuot != -1 && line.length() >= startQuot + 3)
|
||||
{
|
||||
auto endQuot = line.indexOf('"', startQuot + 1);
|
||||
if (endQuot == -1) continue;
|
||||
|
||||
auto name = line.sliced(startQuot + 1, endQuot - startQuot - 1);
|
||||
imports.push_back(name);
|
||||
} else if (!internal && line == "//@ pragma Internal") {
|
||||
internal = true;
|
||||
} else if (line.contains('{')) {
|
||||
inHeader = false;
|
||||
}
|
||||
} else if (line.contains('{')) break;
|
||||
}
|
||||
|
||||
if (line.startsWith("//@ if ")) {
|
||||
auto code = line.sliced(7);
|
||||
auto value = pragmaEngine.evaluate(code, path, 1234);
|
||||
bool mask = true;
|
||||
|
||||
if (value.isError()) {
|
||||
postError(QString("Evaluating if: %0").arg(value.toString()));
|
||||
} else if (!value.isBool()) {
|
||||
postError(QString("If expression \"%0\" is not a boolean").arg(value.toString()));
|
||||
} else if (value.toBool()) {
|
||||
mask = false;
|
||||
}
|
||||
if (!sourceMasked && mask) hideMask = true;
|
||||
mask = sourceMasked || mask; // can't unmask if a nested if passes
|
||||
ifScopes.append(mask);
|
||||
if (mask) isOverridden = true;
|
||||
sourceMasked = mask;
|
||||
} else if (line.startsWith("//@ endif")) {
|
||||
if (ifScopes.isEmpty()) {
|
||||
postError("endif without matching if");
|
||||
} else {
|
||||
ifScopes.pop_back();
|
||||
|
||||
if (ifScopes.isEmpty()) sourceMasked = false;
|
||||
else sourceMasked = ifScopes.last();
|
||||
}
|
||||
}
|
||||
|
||||
if (!hideMask && sourceMasked) overrideText.append("// MASKED: " % rawLine % '\n');
|
||||
else overrideText.append(rawLine % '\n');
|
||||
|
||||
next:;
|
||||
}
|
||||
|
||||
file.close();
|
||||
if (!ifScopes.isEmpty()) {
|
||||
postError("unclosed preprocessor if block");
|
||||
}
|
||||
|
||||
if (isOverridden) {
|
||||
this->fileIntercepts.insert(path, overrideText);
|
||||
}
|
||||
|
||||
if (logQmlScanner().isDebugEnabled() && !imports.isEmpty()) {
|
||||
qCDebug(logQmlScanner) << "Found imports" << imports;
|
||||
}
|
||||
|
||||
auto currentdir = QDir(QFileInfo(path).canonicalPath());
|
||||
auto currentdir = QDir(QFileInfo(path).absolutePath());
|
||||
|
||||
// the root can never be a singleton so it dosent matter if we skip it
|
||||
this->scanDir(currentdir.path());
|
||||
this->scanDir(currentdir);
|
||||
|
||||
for (auto& import: imports) {
|
||||
QString ipath;
|
||||
@@ -179,9 +260,9 @@ bool QmlScanner::scanQmlFile(const QString& path, bool& singleton, bool& interna
|
||||
}
|
||||
|
||||
auto pathInfo = QFileInfo(ipath);
|
||||
auto cpath = pathInfo.canonicalFilePath();
|
||||
auto cpath = pathInfo.absoluteFilePath();
|
||||
|
||||
if (cpath.isEmpty()) {
|
||||
if (!pathInfo.exists()) {
|
||||
qCWarning(logQmlScanner) << "Ignoring unresolvable import" << ipath << "from" << path;
|
||||
continue;
|
||||
}
|
||||
@@ -191,8 +272,11 @@ bool QmlScanner::scanQmlFile(const QString& path, bool& singleton, bool& interna
|
||||
continue;
|
||||
}
|
||||
|
||||
if (import.endsWith(".js")) this->scannedFiles.push_back(cpath);
|
||||
else this->scanDir(cpath);
|
||||
if (import.endsWith(".js")) {
|
||||
this->scannedFiles.push_back(cpath);
|
||||
QByteArray jsData;
|
||||
this->readAndHashFile(cpath, jsData);
|
||||
} else this->scanDir(cpath);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -207,14 +291,12 @@ void QmlScanner::scanQmlRoot(const QString& path) {
|
||||
bool QmlScanner::scanQmlJson(const QString& path) {
|
||||
qCDebug(logQmlScanner) << "Scanning qml.json file" << path;
|
||||
|
||||
auto file = QFile(path);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
QByteArray data;
|
||||
if (!this->readAndHashFile(path, data)) {
|
||||
qCWarning(logQmlScanner) << "Failed to open file" << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
// Importing this makes CI builds fail for some reason.
|
||||
QJsonParseError error; // NOLINT (misc-include-cleaner)
|
||||
auto json = QJsonDocument::fromJson(data, &error);
|
||||
@@ -285,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;
|
||||
}
|
||||
+18
-4
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdir.h>
|
||||
#include <qhash.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qvector.h>
|
||||
|
||||
@@ -16,19 +18,31 @@ public:
|
||||
QmlScanner() = default;
|
||||
QmlScanner(const QDir& rootPath): rootPath(rootPath) {}
|
||||
|
||||
// path must be canonical
|
||||
void scanDir(const QString& path);
|
||||
|
||||
void scanDir(const QDir& dir);
|
||||
void scanQmlRoot(const QString& path);
|
||||
|
||||
QVector<QString> scannedDirs;
|
||||
QVector<QDir> scannedDirs;
|
||||
QVector<QString> scannedFiles;
|
||||
QHash<QString, QByteArray> fileHashes;
|
||||
QHash<QString, QString> fileIntercepts;
|
||||
|
||||
struct ScanError {
|
||||
QString file;
|
||||
QString message;
|
||||
int line;
|
||||
};
|
||||
|
||||
QVector<ScanError> scanErrors;
|
||||
|
||||
bool readAndHashFile(const QString& path, QByteArray& data);
|
||||
[[nodiscard]] bool hasFileContentChanged(const QString& path) const;
|
||||
|
||||
private:
|
||||
QDir rootPath;
|
||||
|
||||
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();
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "scanenv.hpp"
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qtversion.h>
|
||||
#include <qversionnumber.h>
|
||||
|
||||
#include "build.hpp"
|
||||
|
||||
namespace qs::scan::env {
|
||||
|
||||
bool PreprocEnv::hasVersion(int major, int minor, const QStringList& features) {
|
||||
if (QS_VERSION_MAJOR > major) return true;
|
||||
if (QS_VERSION_MAJOR == major && QS_VERSION_MINOR > minor) return true;
|
||||
|
||||
auto availFeatures = QString(QS_UNRELEASED_FEATURES).split(';');
|
||||
|
||||
for (const auto& feature: features) {
|
||||
if (!availFeatures.contains(feature)) return false;
|
||||
}
|
||||
|
||||
return QS_VERSION_MAJOR == major && QS_VERSION_MINOR == minor;
|
||||
}
|
||||
|
||||
bool PreprocEnv::hasQtVersion(int major, int minor) {
|
||||
auto qtVersion = QVersionNumber::fromString(qVersion());
|
||||
auto requiredVersion = QVersionNumber(major, minor);
|
||||
return qtVersion >= requiredVersion;
|
||||
}
|
||||
|
||||
QString PreprocEnv::env(const QString& variable) {
|
||||
return qEnvironmentVariable(variable.toStdString().c_str());
|
||||
}
|
||||
|
||||
bool PreprocEnv::isEnvSet(const QString& variable) {
|
||||
return qEnvironmentVariableIsSet(variable.toStdString().c_str());
|
||||
}
|
||||
|
||||
} // namespace qs::scan::env
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
namespace qs::scan::env {
|
||||
|
||||
class PreprocEnv: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
Q_INVOKABLE static bool
|
||||
hasVersion(int major, int minor, const QStringList& features = QStringList());
|
||||
Q_INVOKABLE static bool hasQtVersion(int major, int minor);
|
||||
|
||||
Q_INVOKABLE static QString env(const QString& variable);
|
||||
Q_INVOKABLE static bool isEnvSet(const QString& variable);
|
||||
};
|
||||
|
||||
} // namespace qs::scan::env
|
||||
+113
-30
@@ -4,39 +4,95 @@
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qjsvalue.h>
|
||||
#include <qjsvalueiterator.h>
|
||||
#include <qlist.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtversionchecks.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
this->hasActiveIterators = true;
|
||||
namespace {
|
||||
struct RecursionPair {
|
||||
const QJSValue* a;
|
||||
const QJSValue* b;
|
||||
const RecursionPair* previous;
|
||||
};
|
||||
|
||||
bool qjsValueStructuralEq(
|
||||
const QJSValue& a,
|
||||
const QJSValue& b,
|
||||
const RecursionPair* activePair = nullptr
|
||||
) {
|
||||
if (a.strictlyEquals(b)) return true;
|
||||
if (!a.isObject() || !b.isObject() || a.isArray() != b.isArray()) return false;
|
||||
|
||||
for (const auto* pair = activePair; pair != nullptr; pair = pair->previous) {
|
||||
if (a.strictlyEquals(*pair->a) || b.strictlyEquals(*pair->b)) return false;
|
||||
}
|
||||
|
||||
const auto nextActivePair = RecursionPair {.a = &a, .b = &b, .previous = activePair};
|
||||
|
||||
auto aIter = QJSValueIterator(a);
|
||||
auto bIter = QJSValueIterator(b);
|
||||
|
||||
while (aIter.hasNext()) {
|
||||
if (!bIter.hasNext()) return false;
|
||||
|
||||
aIter.next();
|
||||
bIter.next();
|
||||
|
||||
const auto aName = aIter.name();
|
||||
const auto bName = bIter.name();
|
||||
const auto aValue = aIter.value();
|
||||
|
||||
if (aName == bName) {
|
||||
const auto bValue = bIter.value();
|
||||
if (!qjsValueStructuralEq(aValue, bValue, &nextActivePair)) return false;
|
||||
} else {
|
||||
if (!b.hasOwnProperty(aName)) return false;
|
||||
|
||||
const auto bValue = b.property(aName);
|
||||
if (!qjsValueStructuralEq(aValue, bValue, &nextActivePair)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !bIter.hasNext();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool ScriptModel::updateValuesUnique(const QList<QJSValue>& newValues) {
|
||||
auto anyChanges = false;
|
||||
|
||||
this->isModifying = true;
|
||||
this->mValues.reserve(newValues.size());
|
||||
|
||||
auto iter = this->mValues.begin();
|
||||
auto newIter = newValues.begin();
|
||||
|
||||
// TODO: cache this
|
||||
auto getCmpKey = [&](const QVariant& v) {
|
||||
if (v.canConvert<QVariantMap>()) {
|
||||
auto vMap = v.value<QVariantMap>();
|
||||
if (vMap.contains(this->cmpKey)) {
|
||||
return vMap.value(this->cmpKey);
|
||||
}
|
||||
auto comparisonValue = [this](const QJSValue& value) {
|
||||
if (value.hasProperty(this->cmpKey)) return value.property(this->cmpKey);
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
auto valueCmp = [&, this](const QJSValue& a, const QJSValue& b) {
|
||||
if (a.strictlyEquals(b)) return true;
|
||||
|
||||
const auto aValue = this->cmpKey.isEmpty() ? a : comparisonValue(a);
|
||||
const auto bValue = this->cmpKey.isEmpty() ? b : comparisonValue(b);
|
||||
|
||||
if (this->mComparisonMode == ObjectComparison::Identity) {
|
||||
return aValue.strictlyEquals(bValue);
|
||||
} else {
|
||||
return qjsValueStructuralEq(aValue, bValue);
|
||||
}
|
||||
|
||||
return v;
|
||||
};
|
||||
|
||||
auto variantCmp = [&](const QVariant& a, const QVariant& b) {
|
||||
if (!this->cmpKey.isEmpty()) return getCmpKey(a) == getCmpKey(b);
|
||||
else return a == b;
|
||||
};
|
||||
|
||||
auto eqPredicate = [&](const QVariant& b) {
|
||||
return [&](const QVariant& a) { return variantCmp(a, b); };
|
||||
auto eqPredicate = [&](const QJSValue& b) {
|
||||
return [&](const QJSValue& a) { return valueCmp(a, b); };
|
||||
};
|
||||
|
||||
while (true) {
|
||||
@@ -49,6 +105,7 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
this->beginRemoveRows(QModelIndex(), startIndex, endIndex);
|
||||
this->mValues.erase(iter, this->mValues.end());
|
||||
this->endRemoveRows();
|
||||
anyChanges = true;
|
||||
|
||||
break;
|
||||
} else if (iter == this->mValues.end()) {
|
||||
@@ -59,9 +116,10 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
this->beginInsertRows(QModelIndex(), startIndex, endIndex);
|
||||
this->mValues.append(newValues.sliced(startIndex));
|
||||
this->endInsertRows();
|
||||
anyChanges = true;
|
||||
|
||||
break;
|
||||
} else if (!variantCmp(*newIter, *iter)) {
|
||||
} else if (!valueCmp(*newIter, *iter)) {
|
||||
auto oldIter = std::find_if(iter, this->mValues.end(), eqPredicate(*newIter));
|
||||
|
||||
if (oldIter != this->mValues.end()) {
|
||||
@@ -72,8 +130,8 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
do {
|
||||
++iter;
|
||||
} while (iter != this->mValues.end()
|
||||
&& std::find_if(newIter, newValues.end(), eqPredicate(*iter)) == newValues.end()
|
||||
);
|
||||
&& std::find_if(newIter, newValues.end(), eqPredicate(*iter))
|
||||
== newValues.end());
|
||||
|
||||
auto index = static_cast<qint32>(std::distance(this->mValues.begin(), iter));
|
||||
auto startIndex = static_cast<qint32>(std::distance(this->mValues.begin(), startIter));
|
||||
@@ -81,6 +139,7 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
this->beginRemoveRows(QModelIndex(), startIndex, index - 1);
|
||||
iter = this->mValues.erase(startIter, iter);
|
||||
this->endRemoveRows();
|
||||
anyChanges = true;
|
||||
} else {
|
||||
// Advance iters to capture a whole move sequence as a single operation if possible.
|
||||
auto oldStartIter = oldIter;
|
||||
@@ -88,7 +147,7 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
++oldIter;
|
||||
++newIter;
|
||||
} while (oldIter != this->mValues.end() && newIter != newValues.end()
|
||||
&& variantCmp(*oldIter, *newIter));
|
||||
&& valueCmp(*oldIter, *newIter));
|
||||
|
||||
auto index = static_cast<qint32>(std::distance(this->mValues.begin(), iter));
|
||||
auto oldStartIndex =
|
||||
@@ -105,6 +164,7 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
|
||||
iter = this->mValues.begin() + (index + len);
|
||||
this->endMoveRows();
|
||||
anyChanges = true;
|
||||
}
|
||||
} else {
|
||||
auto startNewIter = newIter;
|
||||
@@ -130,8 +190,9 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
std::move_backward(iter, this->mValues.end() - len, this->mValues.end());
|
||||
iter = std::copy(startNewIter, newIter, iter);
|
||||
this->endInsertRows();
|
||||
anyChanges = true;
|
||||
}
|
||||
} else if (*newIter != *iter) {
|
||||
} else if (!newIter->strictlyEquals(*iter)) {
|
||||
auto first = static_cast<qint32>(std::distance(this->mValues.begin(), iter));
|
||||
auto index = first;
|
||||
|
||||
@@ -140,26 +201,42 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
++iter;
|
||||
++newIter;
|
||||
++index;
|
||||
} while (iter != this->mValues.end() && newIter != newValues.end() && *newIter != *iter);
|
||||
} while (iter != this->mValues.end() && newIter != newValues.end()
|
||||
&& !newIter->strictlyEquals(*iter));
|
||||
|
||||
this->dataChanged(
|
||||
this->index(first, 0, QModelIndex()),
|
||||
this->index(index - 1, 0, QModelIndex()),
|
||||
{Qt::UserRole}
|
||||
);
|
||||
|
||||
anyChanges = true;
|
||||
} else {
|
||||
++iter;
|
||||
++newIter;
|
||||
}
|
||||
}
|
||||
|
||||
this->hasActiveIterators = false;
|
||||
this->isModifying = false;
|
||||
|
||||
if (this->stagedValues.has_value()) {
|
||||
auto values = *this->stagedValues;
|
||||
this->stagedValues.reset();
|
||||
anyChanges |= this->updateValuesUnique(values);
|
||||
}
|
||||
|
||||
return anyChanges;
|
||||
}
|
||||
|
||||
void ScriptModel::setValues(const QVariantList& newValues) {
|
||||
if (newValues == this->mValues) return;
|
||||
this->updateValuesUnique(newValues);
|
||||
emit this->valuesChanged();
|
||||
void ScriptModel::setValues(const QList<QJSValue>& newValues) {
|
||||
// Re-entrant modification waits for the original modification to complete to avoid mishandled duplicates.
|
||||
if (this->isModifying) {
|
||||
this->stagedValues = newValues;
|
||||
return;
|
||||
}
|
||||
|
||||
auto changed = this->updateValuesUnique(newValues);
|
||||
if (changed) emit this->valuesChanged();
|
||||
}
|
||||
|
||||
void ScriptModel::setObjectProp(const QString& objectProp) {
|
||||
@@ -169,6 +246,12 @@ void ScriptModel::setObjectProp(const QString& objectProp) {
|
||||
emit this->objectPropChanged();
|
||||
}
|
||||
|
||||
void ScriptModel::setComparisonMode(ObjectComparison::Enum comparisonMode) {
|
||||
if (comparisonMode == this->mComparisonMode) return;
|
||||
this->mComparisonMode = comparisonMode;
|
||||
emit this->comparisonModeChanged();
|
||||
}
|
||||
|
||||
qint32 ScriptModel::rowCount(const QModelIndex& parent) const {
|
||||
if (parent != QModelIndex()) return 0;
|
||||
return static_cast<qint32>(this->mValues.length());
|
||||
@@ -176,7 +259,7 @@ qint32 ScriptModel::rowCount(const QModelIndex& parent) const {
|
||||
|
||||
QVariant ScriptModel::data(const QModelIndex& index, qint32 role) const {
|
||||
if (role != Qt::UserRole) return QVariant();
|
||||
return this->mValues.at(index.row());
|
||||
return this->mValues.at(index.row()).toVariant(QJSValue::RetainJSObjects);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ScriptModel::roleNames() const { return {{Qt::UserRole, "modelData"}}; }
|
||||
@@ -1,10 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qjsvalue.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qproperty.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
///! @@ScriptModel value comparison mode.
|
||||
namespace ObjectComparison { // NOLINT
|
||||
Q_NAMESPACE;
|
||||
QML_ELEMENT;
|
||||
|
||||
enum Enum : quint8 {
|
||||
/// Compare values using strict JavaScript equality.
|
||||
Identity = 0,
|
||||
/// Compare records and arrays structurally.
|
||||
Structure = 1,
|
||||
};
|
||||
Q_ENUM_NS(Enum);
|
||||
|
||||
} // namespace ObjectComparison
|
||||
|
||||
///! QML model reflecting a javascript expression
|
||||
/// ScriptModel is a QML [Data Model] that generates model operations based on changes
|
||||
@@ -40,6 +61,7 @@
|
||||
/// [Data Model]: https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html#qml-data-models
|
||||
class ScriptModel: public QAbstractListModel {
|
||||
Q_OBJECT;
|
||||
// clang-format off
|
||||
/// The list of values to reflect in the model.
|
||||
/// > [!WARNING] ScriptModel currently only works with lists of *unique* values.
|
||||
/// > There must not be any duplicates in the given list, or behavior of the model is undefined.
|
||||
@@ -66,7 +88,8 @@ class ScriptModel: public QAbstractListModel {
|
||||
/// > values: [...DesktopEntries.applications.values].sort(...)
|
||||
/// > }
|
||||
/// > ```
|
||||
Q_PROPERTY(QVariantList values READ values WRITE setValues NOTIFY valuesChanged);
|
||||
// TODO: use qjsobject for gc/free checks?
|
||||
Q_PROPERTY(QList<QJSValue> values READ values WRITE setValues NOTIFY valuesChanged);
|
||||
/// The property that javascript objects passed into the model will be compared with.
|
||||
///
|
||||
/// For example, if `objectProp` is `"myprop"` then `{ myprop: "a", other: "y" }` and
|
||||
@@ -74,21 +97,30 @@ class ScriptModel: public QAbstractListModel {
|
||||
///
|
||||
/// Defaults to `""`, meaning no key.
|
||||
Q_PROPERTY(QString objectProp READ objectProp WRITE setObjectProp NOTIFY objectPropChanged);
|
||||
/// How values should be compared. Defaults to `ObjectComparison.Structure`.
|
||||
///
|
||||
/// Identity based comparison is faster if usable for a given model, and often
|
||||
/// achievable with @@objectProp.
|
||||
Q_PROPERTY(ObjectComparison::Enum comparisonMode READ comparisonMode WRITE setComparisonMode NOTIFY comparisonModeChanged);
|
||||
// clang-format on
|
||||
QML_ELEMENT;
|
||||
|
||||
public:
|
||||
[[nodiscard]] QVariantList values() const {
|
||||
[[nodiscard]] QList<QJSValue> values() const {
|
||||
auto values = this->mValues;
|
||||
// If not detached, the QML engine will invalidate iterators in updateValuesUnique.
|
||||
if (this->hasActiveIterators) values.detach();
|
||||
if (this->isModifying) values.detach();
|
||||
return values;
|
||||
}
|
||||
|
||||
void setValues(const QVariantList& newValues);
|
||||
void setValues(const QList<QJSValue>& newValues);
|
||||
|
||||
[[nodiscard]] QString objectProp() const { return this->cmpKey; }
|
||||
void setObjectProp(const QString& objectProp);
|
||||
|
||||
[[nodiscard]] ObjectComparison::Enum comparisonMode() const { return this->mComparisonMode; }
|
||||
void setComparisonMode(ObjectComparison::Enum comparisonMode);
|
||||
|
||||
[[nodiscard]] qint32 rowCount(const QModelIndex& parent) const override;
|
||||
[[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override;
|
||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||
@@ -96,11 +128,14 @@ public:
|
||||
signals:
|
||||
void valuesChanged();
|
||||
void objectPropChanged();
|
||||
void comparisonModeChanged();
|
||||
|
||||
private:
|
||||
QVariantList mValues;
|
||||
QList<QJSValue> mValues;
|
||||
QString cmpKey;
|
||||
bool hasActiveIterators = false;
|
||||
ObjectComparison::Enum mComparisonMode = ObjectComparison::Structure;
|
||||
bool isModifying = false;
|
||||
std::optional<QList<QJSValue>> stagedValues;
|
||||
|
||||
void updateValuesUnique(const QVariantList& newValues);
|
||||
bool updateValuesUnique(const QList<QJSValue>& newValues);
|
||||
};
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "streamreader.hpp"
|
||||
#include <cstring>
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qiodevice.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
void StreamReader::setDevice(QIODevice* device) {
|
||||
this->reset();
|
||||
this->device = device;
|
||||
}
|
||||
|
||||
void StreamReader::startTransaction() {
|
||||
this->cursor = 0;
|
||||
this->failed = false;
|
||||
}
|
||||
|
||||
bool StreamReader::fill() {
|
||||
auto available = this->device->bytesAvailable();
|
||||
if (available <= 0) return false;
|
||||
auto oldSize = this->buffer.size();
|
||||
this->buffer.resize(oldSize + available);
|
||||
auto bytesRead = this->device->read(this->buffer.data() + oldSize, available); // NOLINT
|
||||
|
||||
if (bytesRead <= 0) {
|
||||
this->buffer.resize(oldSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->buffer.resize(oldSize + bytesRead);
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray StreamReader::readBytes(qsizetype count) {
|
||||
if (this->failed) return {};
|
||||
|
||||
auto needed = this->cursor + count;
|
||||
|
||||
while (this->buffer.size() < needed) {
|
||||
if (!this->fill()) {
|
||||
this->failed = true;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
auto result = this->buffer.mid(this->cursor, count);
|
||||
this->cursor += count;
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray StreamReader::readUntil(char terminator) {
|
||||
if (this->failed) return {};
|
||||
|
||||
auto searchFrom = this->cursor;
|
||||
auto idx = this->buffer.indexOf(terminator, searchFrom);
|
||||
|
||||
while (idx == -1) {
|
||||
searchFrom = this->buffer.size();
|
||||
if (!this->fill()) {
|
||||
this->failed = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
idx = this->buffer.indexOf(terminator, searchFrom);
|
||||
}
|
||||
|
||||
auto length = idx - this->cursor + 1;
|
||||
auto result = this->buffer.mid(this->cursor, length);
|
||||
this->cursor += length;
|
||||
return result;
|
||||
}
|
||||
|
||||
void StreamReader::readInto(char* ptr, qsizetype count) {
|
||||
auto data = this->readBytes(count);
|
||||
if (!data.isEmpty()) memcpy(ptr, data.data(), count);
|
||||
}
|
||||
|
||||
qint32 StreamReader::readI32() {
|
||||
qint32 value = 0;
|
||||
this->readInto(reinterpret_cast<char*>(&value), sizeof(qint32));
|
||||
return value;
|
||||
}
|
||||
|
||||
bool StreamReader::commitTransaction() {
|
||||
if (this->failed) {
|
||||
this->cursor = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
this->buffer.remove(0, this->cursor);
|
||||
this->cursor = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void StreamReader::reset() {
|
||||
this->buffer.clear();
|
||||
this->cursor = 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <qbytearray.h>
|
||||
#include <qiodevice.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
class StreamReader {
|
||||
public:
|
||||
void setDevice(QIODevice* device);
|
||||
|
||||
void startTransaction();
|
||||
QByteArray readBytes(qsizetype count);
|
||||
QByteArray readUntil(char terminator);
|
||||
void readInto(char* ptr, qsizetype count);
|
||||
qint32 readI32();
|
||||
bool commitTransaction();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
bool fill();
|
||||
|
||||
QIODevice* device = nullptr;
|
||||
QByteArray buffer;
|
||||
qsizetype cursor = 0;
|
||||
bool failed = false;
|
||||
};
|
||||
@@ -8,3 +8,4 @@ qs_test(transformwatcher transformwatcher.cpp)
|
||||
qs_test(ringbuffer ringbuf.cpp)
|
||||
qs_test(scriptmodel scriptmodel.cpp)
|
||||
qs_test(stacklist stacklist.cpp)
|
||||
qs_test(objectmodel objectmodel.cpp)
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "objectmodel.hpp"
|
||||
|
||||
#include <qlist.h>
|
||||
#include <qobject.h>
|
||||
#include <qtest.h>
|
||||
#include <qtestcase.h>
|
||||
|
||||
#include "../model.hpp"
|
||||
|
||||
void TestObjectModel::diffUpdateInsertRemove() {
|
||||
QObject a;
|
||||
QObject b;
|
||||
QObject c;
|
||||
QObject d;
|
||||
|
||||
auto model = ObjectModel<QObject>(nullptr);
|
||||
model.insertObject(&a);
|
||||
model.insertObject(&b);
|
||||
model.insertObject(&c);
|
||||
QCOMPARE(model.valueList(), (QList<QObject*> {&a, &b, &c}));
|
||||
|
||||
// drop b, append d — relative order of survivors unchanged
|
||||
model.diffUpdate({&a, &c, &d});
|
||||
QCOMPARE(model.valueList(), (QList<QObject*> {&a, &c, &d}));
|
||||
}
|
||||
|
||||
void TestObjectModel::diffUpdateReorder() {
|
||||
QObject a;
|
||||
QObject b;
|
||||
QObject c;
|
||||
QObject d;
|
||||
|
||||
auto model = ObjectModel<QObject>(nullptr);
|
||||
model.insertObject(&d);
|
||||
model.insertObject(&a);
|
||||
model.insertObject(&b);
|
||||
model.insertObject(&c);
|
||||
QCOMPARE(model.valueList(), (QList<QObject*> {&d, &a, &b, &c}));
|
||||
|
||||
// pure permutation: same elements, different order. Previously turned
|
||||
// [d,a,b,c] into [a,b,c,d,a,b,c] because the old row was never removed
|
||||
// before inserting at the new index.
|
||||
model.diffUpdate({&a, &b, &c, &d});
|
||||
QCOMPARE(model.valueList(), (QList<QObject*> {&a, &b, &c, &d}));
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestObjectModel);
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class TestObjectModel: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
private slots:
|
||||
static void diffUpdateInsertRemove();
|
||||
static void diffUpdateReorder();
|
||||
};
|
||||
+156
-54
@@ -4,10 +4,11 @@
|
||||
#include <qabstractitemmodeltester.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdebug.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qjsvalue.h>
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qobject.h>
|
||||
#include <qsignalspy.h>
|
||||
#include <qstring.h>
|
||||
#include <qtest.h>
|
||||
#include <qtestcase.h>
|
||||
@@ -15,8 +16,6 @@
|
||||
|
||||
#include "../scriptmodel.hpp"
|
||||
|
||||
using OpList = QList<ModelOperation>;
|
||||
|
||||
bool ModelOperation::operator==(const ModelOperation& other) const {
|
||||
return other.operation == this->operation && other.index == this->index
|
||||
&& other.length == this->length && other.destIndex == this->destIndex;
|
||||
@@ -44,15 +43,44 @@ QDebug& operator<<(QDebug& debug, const ModelOperation& op) {
|
||||
return debug;
|
||||
}
|
||||
|
||||
ChangeObserver::ChangeObserver(QAbstractItemModel* model) {
|
||||
QObject::connect(model, &QAbstractItemModel::rowsInserted, this, &ChangeObserver::onInsert);
|
||||
QObject::connect(model, &QAbstractItemModel::rowsRemoved, this, &ChangeObserver::onRemove);
|
||||
QObject::connect(model, &QAbstractItemModel::rowsMoved, this, &ChangeObserver::onMove);
|
||||
}
|
||||
|
||||
void ChangeObserver::onInsert(const QModelIndex& parent, int first, int last) {
|
||||
QCOMPARE(parent, QModelIndex());
|
||||
this->mOperations.emplaceBack(ModelOperation::Insert, first, last - first + 1);
|
||||
}
|
||||
|
||||
void ChangeObserver::onRemove(const QModelIndex& parent, int first, int last) {
|
||||
QCOMPARE(parent, QModelIndex());
|
||||
this->mOperations.emplaceBack(ModelOperation::Remove, first, last - first + 1);
|
||||
}
|
||||
|
||||
void ChangeObserver::onMove(
|
||||
const QModelIndex& sourceParent,
|
||||
int sourceStart,
|
||||
int sourceEnd,
|
||||
const QModelIndex& destParent,
|
||||
int destStart
|
||||
) {
|
||||
QCOMPARE(sourceParent, QModelIndex());
|
||||
QCOMPARE(destParent, QModelIndex());
|
||||
this->mOperations
|
||||
.emplaceBack(ModelOperation::Move, sourceStart, sourceEnd - sourceStart + 1, destStart);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-use-internal-linkage)
|
||||
QDebug& operator<<(QDebug& debug, const QVariantList& list) {
|
||||
auto str = QString();
|
||||
QDebug& operator<<(QDebug& debug, const QJSValueList& list) {
|
||||
QString str;
|
||||
|
||||
for (const auto& var: list) {
|
||||
if (var.canConvert<QChar>()) {
|
||||
str += var.value<QChar>();
|
||||
if (var.isString()) {
|
||||
str += var.toString();
|
||||
} else {
|
||||
qFatal() << "QVariantList debug overridden in test";
|
||||
qFatal() << "QJSValueList debug overridden in test";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +88,18 @@ QDebug& operator<<(QDebug& debug, const QVariantList& list) {
|
||||
return debug;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool qjsValueListsEqual(const QJSValueList& a, const QJSValueList& b) {
|
||||
if (a.length() != b.length()) return false;
|
||||
|
||||
for (auto i = 0; i != a.length(); i++) {
|
||||
if (!a.at(i).strictlyEquals(b.at(i))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void TestScriptModel::unique_data() {
|
||||
QTest::addColumn<QString>("oldstr");
|
||||
QTest::addColumn<QString>("newstr");
|
||||
@@ -90,7 +130,7 @@ void TestScriptModel::unique_data() {
|
||||
QTest::addRow("move_overlapping")
|
||||
<< "ABCDEFG" << "ABDEFCG" << OpList({{ModelOperation::Move, 3, 3, 2}});
|
||||
|
||||
// Ensure iterators arent skipping anything at the end of operations by performing
|
||||
// Ensure iterators aren't skipping anything at the end of operations by performing
|
||||
// multiple back to back.
|
||||
|
||||
QTest::addRow("insert_state_ok") << "ABCDEFG" << "ABXXEFG"
|
||||
@@ -117,65 +157,127 @@ void TestScriptModel::unique() {
|
||||
QFETCH(const QString, newstr);
|
||||
QFETCH(const OpList, operations);
|
||||
|
||||
auto strToVariantList = [](const QString& str) -> QVariantList {
|
||||
QVariantList list;
|
||||
auto strToJsValueList = [](const QString& str) -> QJSValueList {
|
||||
QJSValueList list;
|
||||
|
||||
for (auto c: str) {
|
||||
list.emplace_back(c);
|
||||
list.emplace_back(QString(c));
|
||||
}
|
||||
|
||||
return list;
|
||||
};
|
||||
|
||||
auto oldlist = strToVariantList(oldstr);
|
||||
auto newlist = strToVariantList(newstr);
|
||||
auto oldList = strToJsValueList(oldstr);
|
||||
auto newList = strToJsValueList(newstr);
|
||||
|
||||
auto model = ScriptModel();
|
||||
ScriptModel model;
|
||||
auto modelTester = QAbstractItemModelTester(&model);
|
||||
auto observer = ChangeObserver(&model);
|
||||
|
||||
OpList actualOperations;
|
||||
|
||||
auto onInsert = [&](const QModelIndex& parent, int first, int last) {
|
||||
QCOMPARE(parent, QModelIndex());
|
||||
actualOperations << ModelOperation(ModelOperation::Insert, first, last - first + 1);
|
||||
};
|
||||
|
||||
auto onRemove = [&](const QModelIndex& parent, int first, int last) {
|
||||
QCOMPARE(parent, QModelIndex());
|
||||
actualOperations << ModelOperation(ModelOperation::Remove, first, last - first + 1);
|
||||
};
|
||||
|
||||
auto onMove = [&](const QModelIndex& sourceParent,
|
||||
int sourceStart,
|
||||
int sourceEnd,
|
||||
const QModelIndex& destParent,
|
||||
int destStart) {
|
||||
QCOMPARE(sourceParent, QModelIndex());
|
||||
QCOMPARE(destParent, QModelIndex());
|
||||
actualOperations << ModelOperation(
|
||||
ModelOperation::Move,
|
||||
sourceStart,
|
||||
sourceEnd - sourceStart + 1,
|
||||
destStart
|
||||
);
|
||||
};
|
||||
|
||||
QObject::connect(&model, &QAbstractItemModel::rowsInserted, &model, onInsert);
|
||||
QObject::connect(&model, &QAbstractItemModel::rowsRemoved, &model, onRemove);
|
||||
QObject::connect(&model, &QAbstractItemModel::rowsMoved, &model, onMove);
|
||||
|
||||
model.setValues(oldlist);
|
||||
QCOMPARE_EQ(model.values(), oldlist);
|
||||
model.setValues(oldList);
|
||||
QVERIFY(qjsValueListsEqual(model.values(), oldList));
|
||||
QCOMPARE_EQ(
|
||||
actualOperations,
|
||||
OpList({{ModelOperation::Insert, 0, static_cast<qint32>(oldlist.length())}})
|
||||
observer.operations(),
|
||||
OpList({{ModelOperation::Insert, 0, static_cast<qint32>(oldList.length())}})
|
||||
);
|
||||
|
||||
actualOperations.clear();
|
||||
observer.clear();
|
||||
|
||||
model.setValues(newlist);
|
||||
QCOMPARE_EQ(model.values(), newlist);
|
||||
QCOMPARE_EQ(actualOperations, operations);
|
||||
model.setValues(newList);
|
||||
QVERIFY(qjsValueListsEqual(model.values(), newList));
|
||||
QCOMPARE_EQ(observer.operations(), operations);
|
||||
}
|
||||
|
||||
void TestScriptModel::structuralEquality() {
|
||||
ScriptModel model;
|
||||
QJSEngine engine;
|
||||
|
||||
auto object = engine.newObject();
|
||||
object.setProperty("foo", "bar");
|
||||
object.setProperty("bar", "baz");
|
||||
object.setProperty("subobject", engine.newObject());
|
||||
|
||||
auto replacement = engine.newObject();
|
||||
replacement.setProperty("subobject", engine.newObject());
|
||||
replacement.setProperty("bar", "baz");
|
||||
replacement.setProperty("foo", "bar");
|
||||
|
||||
auto oldList = QList<QJSValue> {object};
|
||||
|
||||
auto newList = QList<QJSValue> {replacement};
|
||||
|
||||
auto modelTester = QAbstractItemModelTester(&model);
|
||||
auto observer = ChangeObserver(&model);
|
||||
|
||||
model.setValues(oldList);
|
||||
QVERIFY(qjsValueListsEqual(model.values(), oldList));
|
||||
QCOMPARE_EQ(
|
||||
observer.operations(),
|
||||
OpList({{ModelOperation::Insert, 0, static_cast<qint32>(oldList.length())}})
|
||||
);
|
||||
|
||||
observer.clear();
|
||||
|
||||
model.setValues(newList);
|
||||
QVERIFY(qjsValueListsEqual(model.values(), newList));
|
||||
QCOMPARE_EQ(observer.operations(), OpList());
|
||||
|
||||
auto structurallyEquals = [](const QJSValue& a, const QJSValue& b) {
|
||||
ScriptModel model;
|
||||
model.setValues({a});
|
||||
|
||||
auto observer = ChangeObserver(&model);
|
||||
model.setValues({b});
|
||||
return observer.operations().isEmpty();
|
||||
};
|
||||
|
||||
auto different = engine.newObject();
|
||||
different.setProperty("foo", "bar");
|
||||
different.setProperty("bar", "baz");
|
||||
auto differentSubobject = engine.newObject();
|
||||
differentSubobject.setProperty("value", 1);
|
||||
different.setProperty("subobject", differentSubobject);
|
||||
QVERIFY(!structurallyEquals(object, different));
|
||||
|
||||
auto cycleA = engine.newObject();
|
||||
cycleA.setProperty("self", cycleA);
|
||||
auto cycleB = engine.newObject();
|
||||
cycleB.setProperty("self", cycleB);
|
||||
QVERIFY(!structurallyEquals(cycleA, cycleB));
|
||||
|
||||
const auto arrayA = engine.evaluate("[1, { value: 'x' }]");
|
||||
const auto arrayB = engine.evaluate("[1, { value: 'x' }]");
|
||||
QVERIFY(structurallyEquals(arrayA, arrayB));
|
||||
|
||||
auto sparseArrayA = engine.newArray(1);
|
||||
auto sparseArrayB = engine.newArray(2);
|
||||
QVERIFY(!structurallyEquals(sparseArrayA, sparseArrayB));
|
||||
}
|
||||
|
||||
void TestScriptModel::comparisonModes() {
|
||||
QJSEngine engine;
|
||||
auto makeValue = [&engine]() {
|
||||
auto value = engine.newObject();
|
||||
value.setProperty("nested", engine.newObject());
|
||||
return value;
|
||||
};
|
||||
|
||||
ScriptModel model;
|
||||
QCOMPARE_EQ(model.comparisonMode(), ObjectComparison::Structure);
|
||||
|
||||
model.setValues({makeValue()});
|
||||
model.setComparisonMode(ObjectComparison::Identity);
|
||||
QCOMPARE_EQ(model.comparisonMode(), ObjectComparison::Identity);
|
||||
|
||||
auto observer = ChangeObserver(&model);
|
||||
model.setValues({makeValue()});
|
||||
QVERIFY(!observer.operations().isEmpty());
|
||||
|
||||
model.setComparisonMode(ObjectComparison::Structure);
|
||||
|
||||
observer.clear();
|
||||
model.setValues({makeValue()});
|
||||
QCOMPARE_EQ(observer.operations(), OpList());
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestScriptModel);
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <qdebug.h>
|
||||
#include <qlist.h>
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
@@ -26,6 +28,29 @@ struct ModelOperation {
|
||||
[[nodiscard]] bool operator==(const ModelOperation& other) const;
|
||||
};
|
||||
|
||||
using OpList = QList<ModelOperation>;
|
||||
|
||||
class ChangeObserver: public QObject {
|
||||
public:
|
||||
explicit ChangeObserver(QAbstractItemModel* model);
|
||||
|
||||
[[nodiscard]] const OpList& operations() const { return this->mOperations; }
|
||||
void clear() { this->mOperations.clear(); }
|
||||
|
||||
private:
|
||||
void onInsert(const QModelIndex& parent, int first, int last);
|
||||
void onRemove(const QModelIndex& parent, int first, int last);
|
||||
void onMove(
|
||||
const QModelIndex& sourceParent,
|
||||
int sourceStart,
|
||||
int sourceEnd,
|
||||
const QModelIndex& destParent,
|
||||
int destStart
|
||||
);
|
||||
|
||||
OpList mOperations;
|
||||
};
|
||||
|
||||
QDebug& operator<<(QDebug& debug, const ModelOperation& op);
|
||||
|
||||
class TestScriptModel: public QObject {
|
||||
@@ -34,4 +59,6 @@ class TestScriptModel: public QObject {
|
||||
private slots:
|
||||
static void unique_data(); // NOLINT
|
||||
static void unique();
|
||||
static void structuralEquality();
|
||||
static void comparisonModes();
|
||||
};
|
||||
@@ -54,7 +54,7 @@ bool QmlToolingSupport::lockTooling() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lock = flock {
|
||||
struct flock lock = {
|
||||
.l_type = F_WRLCK,
|
||||
.l_whence = SEEK_SET, // NOLINT (fcntl.h??)
|
||||
.l_start = 0,
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-32
@@ -29,7 +29,7 @@ struct StringLiteral16 {
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const QChar* qCharPtr() const noexcept {
|
||||
return std::bit_cast<const QChar*>(&this->value);
|
||||
return std::bit_cast<const QChar*>(&this->value); // NOLINT
|
||||
}
|
||||
|
||||
[[nodiscard]] Q_ALWAYS_INLINE operator QString() const noexcept {
|
||||
@@ -251,37 +251,6 @@ public:
|
||||
GuardedEmitBlocker block() { return GuardedEmitBlocker(&this->blocked); }
|
||||
};
|
||||
|
||||
template <auto member, auto destroyedSlot, auto changedSignal>
|
||||
class SimpleObjectHandleOps {
|
||||
using Traits = MemberPointerTraits<decltype(member)>;
|
||||
|
||||
public:
|
||||
static bool setObject(Traits::Class* parent, Traits::Type value) {
|
||||
if (value == parent->*member) return false;
|
||||
|
||||
if (parent->*member != nullptr) {
|
||||
QObject::disconnect(parent->*member, &QObject::destroyed, parent, destroyedSlot);
|
||||
}
|
||||
|
||||
parent->*member = value;
|
||||
|
||||
if (value != nullptr) {
|
||||
QObject::connect(parent->*member, &QObject::destroyed, parent, destroyedSlot);
|
||||
}
|
||||
|
||||
if constexpr (changedSignal != nullptr) {
|
||||
emit(parent->*changedSignal)();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <auto member, auto destroyedSlot, auto changedSignal = nullptr>
|
||||
bool setSimpleObjectHandle(auto* parent, auto* value) {
|
||||
return SimpleObjectHandleOps<member, destroyedSlot, changedSignal>::setObject(parent, value);
|
||||
}
|
||||
|
||||
template <auto methodPtr>
|
||||
class MethodFunctor {
|
||||
using PtrMeta = MemberPointerTraits<decltype(methodPtr)>;
|
||||
|
||||
@@ -145,7 +145,7 @@ void Variants::updateVariants() {
|
||||
|
||||
{
|
||||
if (this->mInstances.contains(variant)) {
|
||||
continue; // we dont need to recreate this one
|
||||
continue; // we don't need to recreate this one
|
||||
}
|
||||
|
||||
auto variantMap = QVariantMap();
|
||||
|
||||
@@ -43,7 +43,7 @@ class Variants: public Reloadable {
|
||||
Q_OBJECT;
|
||||
/// The component to create instances of.
|
||||
///
|
||||
/// The delegate should define a `modelData` property that will be popuplated with a value
|
||||
/// The delegate should define a `modelData` property that will be populated with a value
|
||||
/// from the @@model.
|
||||
Q_PROPERTY(QQmlComponent* delegate MEMBER mDelegate);
|
||||
/// The list of sets of properties to create instances with.
|
||||
|
||||
@@ -6,12 +6,51 @@ qt_add_library(quickshell-crash STATIC
|
||||
|
||||
qs_pch(quickshell-crash SET large)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(breakpad REQUIRED IMPORTED_TARGET breakpad)
|
||||
# only need client?? take only includes from pkg config todo
|
||||
target_link_libraries(quickshell-crash PRIVATE PkgConfig::breakpad -lbreakpad_client)
|
||||
if (VENDOR_CPPTRACE)
|
||||
message(STATUS "Vendoring cpptrace...")
|
||||
include(FetchContent)
|
||||
|
||||
# For use without internet access see: https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_SOURCE_DIR_%3CuppercaseName%3E
|
||||
FetchContent_Declare(
|
||||
cpptrace
|
||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
|
||||
GIT_TAG v1.0.4
|
||||
)
|
||||
|
||||
set(CPPTRACE_UNWIND_WITH_LIBUNWIND TRUE)
|
||||
FetchContent_MakeAvailable(cpptrace)
|
||||
else ()
|
||||
find_package(cpptrace REQUIRED)
|
||||
|
||||
# useful for cross after you have already checked cpptrace is built correctly
|
||||
if (NOT DO_NOT_CHECK_CPPTRACE_USABILITY)
|
||||
try_run(CPPTRACE_SIGNAL_SAFE_UNWIND CPPTRACE_SIGNAL_SAFE_UNWIND_COMP
|
||||
SOURCE_FROM_CONTENT check.cxx "
|
||||
#include <cpptrace/basic.hpp>
|
||||
int main() {
|
||||
return cpptrace::can_signal_safe_unwind() ? 0 : 1;
|
||||
}
|
||||
"
|
||||
LOG_DESCRIPTION "Checking ${CPPTRACE_SIGNAL_SAFE_UNWIND}"
|
||||
LINK_LIBRARIES cpptrace::cpptrace
|
||||
COMPILE_OUTPUT_VARIABLE CPPTRACE_SIGNAL_SAFE_UNWIND_LOG
|
||||
CXX_STANDARD 20
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
|
||||
if (NOT CPPTRACE_SIGNAL_SAFE_UNWIND_COMP)
|
||||
message(STATUS "${CPPTRACE_SIGNAL_SAFE_UNWIND_LOG}")
|
||||
message(FATAL_ERROR "Failed to compile cpptrace signal safe unwind tester.")
|
||||
endif()
|
||||
|
||||
if (NOT CPPTRACE_SIGNAL_SAFE_UNWIND EQUAL 0)
|
||||
message(STATUS "Cpptrace signal safe unwind test exited with: ${CPPTRACE_SIGNAL_SAFE_UNWIND}")
|
||||
message(FATAL_ERROR "Cpptrace was built without CPPTRACE_UNWIND_WITH_LIBUNWIND set to true. Enable libunwind support in the package or set VENDOR_CPPTRACE to true when building Quickshell.")
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# quick linked for pch compat
|
||||
target_link_libraries(quickshell-crash PRIVATE quickshell-build Qt::Quick Qt::Widgets)
|
||||
target_link_libraries(quickshell-crash PRIVATE quickshell-build Qt::Quick Qt::Widgets cpptrace::cpptrace)
|
||||
|
||||
target_link_libraries(quickshell PRIVATE quickshell-crash)
|
||||
+171
-102
@@ -1,12 +1,15 @@
|
||||
#include "handler.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cerrno>
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
|
||||
#include <bits/types/sigset_t.h>
|
||||
#include <breakpad/client/linux/handler/exception_handler.h>
|
||||
#include <breakpad/client/linux/handler/minidump_descriptor.h>
|
||||
#include <breakpad/common/linux/linux_libc_support.h>
|
||||
#include <cpptrace/basic.hpp>
|
||||
#include <cpptrace/forward.hpp>
|
||||
#include <cpptrace/utils.hpp>
|
||||
#include <qdatastream.h>
|
||||
#include <qfile.h>
|
||||
#include <qlogging.h>
|
||||
@@ -19,91 +22,77 @@
|
||||
|
||||
extern char** environ; // NOLINT
|
||||
|
||||
using namespace google_breakpad;
|
||||
|
||||
namespace qs::crash {
|
||||
|
||||
namespace {
|
||||
|
||||
QS_LOGGING_CATEGORY(logCrashHandler, "quickshell.crashhandler", QtWarningMsg);
|
||||
}
|
||||
|
||||
struct CrashHandlerPrivate {
|
||||
ExceptionHandler* exceptionHandler = nullptr;
|
||||
int minidumpFd = -1;
|
||||
int infoFd = -1;
|
||||
void writeEnvInt(char* buf, const char* name, int value) {
|
||||
// NOLINTBEGIN (cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
while (*name != '\0') *buf++ = *name++;
|
||||
*buf++ = '=';
|
||||
|
||||
static bool minidumpCallback(const MinidumpDescriptor& descriptor, void* context, bool succeeded);
|
||||
};
|
||||
|
||||
CrashHandler::CrashHandler(): d(new CrashHandlerPrivate()) {}
|
||||
|
||||
void CrashHandler::init() {
|
||||
// MinidumpDescriptor has no move constructor and the copy constructor breaks fds.
|
||||
auto createHandler = [this](const MinidumpDescriptor& desc) {
|
||||
this->d->exceptionHandler = new ExceptionHandler(
|
||||
desc,
|
||||
nullptr,
|
||||
&CrashHandlerPrivate::minidumpCallback,
|
||||
this->d,
|
||||
true,
|
||||
-1
|
||||
);
|
||||
};
|
||||
|
||||
qCDebug(logCrashHandler) << "Starting crash handler...";
|
||||
|
||||
this->d->minidumpFd = memfd_create("quickshell:minidump", MFD_CLOEXEC);
|
||||
|
||||
if (this->d->minidumpFd == -1) {
|
||||
qCCritical(logCrashHandler
|
||||
) << "Failed to allocate minidump memfd, minidumps will be saved in the working directory.";
|
||||
createHandler(MinidumpDescriptor("."));
|
||||
} else {
|
||||
qCDebug(logCrashHandler) << "Created memfd" << this->d->minidumpFd
|
||||
<< "for holding possible minidumps.";
|
||||
createHandler(MinidumpDescriptor(this->d->minidumpFd));
|
||||
if (value < 0) {
|
||||
*buf++ = '-';
|
||||
value = -value;
|
||||
}
|
||||
|
||||
qCInfo(logCrashHandler) << "Crash handler initialized.";
|
||||
}
|
||||
|
||||
void CrashHandler::setRelaunchInfo(const RelaunchInfo& info) {
|
||||
this->d->infoFd = memfd_create("quickshell:instance_info", MFD_CLOEXEC);
|
||||
|
||||
if (this->d->infoFd == -1) {
|
||||
qCCritical(logCrashHandler
|
||||
) << "Failed to allocate instance info memfd, crash recovery will not work.";
|
||||
if (value == 0) {
|
||||
*buf++ = '0';
|
||||
*buf = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file;
|
||||
file.open(this->d->infoFd, QFile::ReadWrite);
|
||||
|
||||
QDataStream ds(&file);
|
||||
ds << info;
|
||||
file.flush();
|
||||
|
||||
qCDebug(logCrashHandler) << "Stored instance info in memfd" << this->d->infoFd;
|
||||
}
|
||||
|
||||
CrashHandler::~CrashHandler() {
|
||||
delete this->d->exceptionHandler;
|
||||
delete this->d;
|
||||
}
|
||||
|
||||
bool CrashHandlerPrivate::minidumpCallback(
|
||||
const MinidumpDescriptor& /*descriptor*/,
|
||||
void* context,
|
||||
bool /*success*/
|
||||
) {
|
||||
// A fork that just dies to ensure the coredump is caught by the system.
|
||||
auto coredumpPid = fork();
|
||||
|
||||
if (coredumpPid == 0) {
|
||||
return false;
|
||||
auto* start = buf;
|
||||
while (value > 0) {
|
||||
*buf++ = static_cast<char>('0' + (value % 10));
|
||||
value /= 10;
|
||||
}
|
||||
|
||||
auto* self = static_cast<CrashHandlerPrivate*>(context);
|
||||
*buf = '\0';
|
||||
std::reverse(start, buf);
|
||||
// NOLINTEND
|
||||
}
|
||||
|
||||
void signalHandler(
|
||||
int sig,
|
||||
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);
|
||||
|
||||
for (size_t i = 0; i < static_cast<size_t>(frameCount); i++) {
|
||||
auto frame = cpptrace::safe_object_frame();
|
||||
cpptrace::get_safe_object_frame(traceBuffer[i], &frame);
|
||||
|
||||
auto* wptr = reinterpret_cast<char*>(&frame);
|
||||
auto* end = wptr + sizeof(cpptrace::safe_object_frame); // NOLINT
|
||||
while (wptr != end) {
|
||||
auto r = write(CrashInfo::INSTANCE.traceFd, &frame, sizeof(cpptrace::safe_object_frame));
|
||||
if (r < 0 && errno == EINTR) continue;
|
||||
if (r <= 0) goto fail;
|
||||
wptr += r; // NOLINT
|
||||
}
|
||||
}
|
||||
|
||||
fail:;
|
||||
}
|
||||
|
||||
// TODO: coredump fork and crash reporter remain as zombies, fix
|
||||
auto coredumpPid = fork();
|
||||
if (coredumpPid == 0) {
|
||||
raise(sig);
|
||||
_exit(-1);
|
||||
}
|
||||
|
||||
auto exe = std::array<char, 4096>();
|
||||
if (readlink("/proc/self/exe", exe.data(), exe.size() - 1) == -1) {
|
||||
@@ -116,17 +105,19 @@ bool CrashHandlerPrivate::minidumpCallback(
|
||||
auto env = std::array<char*, 4096>();
|
||||
auto envi = 0;
|
||||
|
||||
auto infoFd = dup(self->infoFd);
|
||||
auto infoFdStr = std::array<char, 38>();
|
||||
memcpy(infoFdStr.data(), "__QUICKSHELL_CRASH_INFO_FD=-1" /*\0*/, 30);
|
||||
if (infoFd != -1) my_uitos(&infoFdStr[27], infoFd, 10);
|
||||
// dup to remove CLOEXEC
|
||||
auto infoFdStr = std::array<char, 48>();
|
||||
writeEnvInt(infoFdStr.data(), "__QUICKSHELL_CRASH_INFO_FD", dup(CrashInfo::INSTANCE.infoFd));
|
||||
env[envi++] = infoFdStr.data();
|
||||
|
||||
auto corePidStr = std::array<char, 39>();
|
||||
memcpy(corePidStr.data(), "__QUICKSHELL_CRASH_DUMP_PID=-1" /*\0*/, 31);
|
||||
if (coredumpPid != -1) my_uitos(&corePidStr[28], coredumpPid, 10);
|
||||
auto corePidStr = std::array<char, 48>();
|
||||
writeEnvInt(corePidStr.data(), "__QUICKSHELL_CRASH_DUMP_PID", coredumpPid);
|
||||
env[envi++] = corePidStr.data();
|
||||
|
||||
auto sigStr = std::array<char, 48>();
|
||||
writeEnvInt(sigStr.data(), "__QUICKSHELL_CRASH_SIGNAL", sig);
|
||||
env[envi++] = sigStr.data();
|
||||
|
||||
auto populateEnv = [&]() {
|
||||
auto senvi = 0;
|
||||
while (envi != 4095) {
|
||||
@@ -138,30 +129,17 @@ bool CrashHandlerPrivate::minidumpCallback(
|
||||
env[envi] = nullptr;
|
||||
};
|
||||
|
||||
sigset_t sigset;
|
||||
sigemptyset(&sigset); // NOLINT (include)
|
||||
sigprocmask(SIG_SETMASK, &sigset, nullptr); // NOLINT
|
||||
|
||||
auto pid = fork();
|
||||
|
||||
if (pid == -1) {
|
||||
perror("Failed to fork and launch crash reporter.\n");
|
||||
return false;
|
||||
_exit(-1);
|
||||
} else if (pid == 0) {
|
||||
// dup to remove CLOEXEC
|
||||
// if already -1 will return -1
|
||||
auto dumpFd = dup(self->minidumpFd);
|
||||
auto logFd = dup(CrashInfo::INSTANCE.logFd);
|
||||
|
||||
// allow up to 10 digits, which should never happen
|
||||
auto dumpFdStr = std::array<char, 38>();
|
||||
auto logFdStr = std::array<char, 37>();
|
||||
|
||||
memcpy(dumpFdStr.data(), "__QUICKSHELL_CRASH_DUMP_FD=-1" /*\0*/, 30);
|
||||
memcpy(logFdStr.data(), "__QUICKSHELL_CRASH_LOG_FD=-1" /*\0*/, 29);
|
||||
|
||||
if (dumpFd != -1) my_uitos(&dumpFdStr[27], dumpFd, 10);
|
||||
if (logFd != -1) my_uitos(&logFdStr[26], logFd, 10);
|
||||
auto dumpFdStr = std::array<char, 48>();
|
||||
auto logFdStr = std::array<char, 48>();
|
||||
writeEnvInt(dumpFdStr.data(), "__QUICKSHELL_CRASH_DUMP_FD", dup(CrashInfo::INSTANCE.traceFd));
|
||||
writeEnvInt(logFdStr.data(), "__QUICKSHELL_CRASH_LOG_FD", dup(CrashInfo::INSTANCE.logFd));
|
||||
|
||||
env[envi++] = dumpFdStr.data();
|
||||
env[envi++] = logFdStr.data();
|
||||
@@ -178,8 +156,99 @@ bool CrashHandlerPrivate::minidumpCallback(
|
||||
perror("Failed to relaunch quickshell.\n");
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
return false; // should make sure it hits the system coredump handler
|
||||
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() {
|
||||
qCDebug(logCrashHandler) << "Starting crash handler...";
|
||||
|
||||
CrashInfo::INSTANCE.traceFd = memfd_create("quickshell:trace", MFD_CLOEXEC);
|
||||
|
||||
if (CrashInfo::INSTANCE.traceFd == -1) {
|
||||
qCCritical(logCrashHandler) << "Failed to allocate trace memfd, stack traces will not be "
|
||||
"available in crash reports.";
|
||||
} else {
|
||||
qCDebug(logCrashHandler) << "Created memfd" << CrashInfo::INSTANCE.traceFd
|
||||
<< "for holding possible stack traces.";
|
||||
}
|
||||
|
||||
{
|
||||
// Preload anything dynamically linked to avoid malloc etc in the dynamic loader.
|
||||
// See cpptrace documentation for more information.
|
||||
auto buffer = std::array<cpptrace::frame_ptr, 10>();
|
||||
cpptrace::safe_generate_raw_trace(buffer.data(), buffer.size());
|
||||
auto frame = cpptrace::safe_object_frame();
|
||||
cpptrace::get_safe_object_frame(buffer[0], &frame);
|
||||
}
|
||||
|
||||
// NOLINTBEGIN (misc-include-cleaner)
|
||||
|
||||
// Set up alternate signal stack for stack overflow handling
|
||||
auto ss = stack_t();
|
||||
ss.ss_sp = new char[SIGSTKSZ];
|
||||
ss.ss_size = SIGSTKSZ;
|
||||
ss.ss_flags = 0;
|
||||
sigaltstack(&ss, nullptr);
|
||||
|
||||
// Install signal handlers
|
||||
struct sigaction sa {};
|
||||
sa.sa_sigaction = &signalHandler;
|
||||
sa.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESETHAND;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
||||
sigaction(SIGSEGV, &sa, nullptr);
|
||||
sigaction(SIGABRT, &sa, nullptr);
|
||||
sigaction(SIGFPE, &sa, nullptr);
|
||||
sigaction(SIGILL, &sa, nullptr);
|
||||
sigaction(SIGBUS, &sa, nullptr);
|
||||
sigaction(SIGTRAP, &sa, nullptr);
|
||||
|
||||
// NOLINTEND (misc-include-cleaner)
|
||||
|
||||
std::set_terminate(&handleCppTerminate);
|
||||
|
||||
qCInfo(logCrashHandler) << "Crash handler initialized.";
|
||||
}
|
||||
|
||||
void CrashHandler::setRelaunchInfo(const RelaunchInfo& info) {
|
||||
CrashInfo::INSTANCE.infoFd = memfd_create("quickshell:instance_info", MFD_CLOEXEC);
|
||||
|
||||
if (CrashInfo::INSTANCE.infoFd == -1) {
|
||||
qCCritical(
|
||||
logCrashHandler
|
||||
) << "Failed to allocate instance info memfd, crash recovery will not work.";
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file;
|
||||
|
||||
if (!file.open(CrashInfo::INSTANCE.infoFd, QFile::ReadWrite)) {
|
||||
qCCritical(
|
||||
logCrashHandler
|
||||
) << "Failed to open instance info memfd, crash recovery will not work.";
|
||||
}
|
||||
|
||||
QDataStream ds(&file);
|
||||
ds << info;
|
||||
file.flush();
|
||||
|
||||
qCDebug(logCrashHandler) << "Stored instance info in memfd" << CrashInfo::INSTANCE.infoFd;
|
||||
}
|
||||
|
||||
} // namespace qs::crash
|
||||
+2
-11
@@ -5,19 +5,10 @@
|
||||
#include "../core/instanceinfo.hpp"
|
||||
namespace qs::crash {
|
||||
|
||||
struct CrashHandlerPrivate;
|
||||
|
||||
class CrashHandler {
|
||||
public:
|
||||
explicit CrashHandler();
|
||||
~CrashHandler();
|
||||
Q_DISABLE_COPY_MOVE(CrashHandler);
|
||||
|
||||
void init();
|
||||
void setRelaunchInfo(const RelaunchInfo& info);
|
||||
|
||||
private:
|
||||
CrashHandlerPrivate* d;
|
||||
static void init();
|
||||
static void setRelaunchInfo(const RelaunchInfo& info);
|
||||
};
|
||||
|
||||
} // namespace qs::crash
|
||||
+17
-15
@@ -5,6 +5,7 @@
|
||||
#include <qapplication.h>
|
||||
#include <qboxlayout.h>
|
||||
#include <qconfig.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdesktopservices.h>
|
||||
#include <qfont.h>
|
||||
#include <qfontinfo.h>
|
||||
@@ -12,11 +13,22 @@
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qtversion.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
#include "build.hpp"
|
||||
|
||||
namespace {
|
||||
QString crashreportUrl() {
|
||||
if (auto url = qEnvironmentVariable("QS_CRASHREPORT_URL"); !url.isEmpty()) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return CRASHREPORT_URL;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class ReportLabel: public QWidget {
|
||||
public:
|
||||
ReportLabel(const QString& label, const QString& content, QWidget* parent): QWidget(parent) {
|
||||
@@ -66,22 +78,17 @@ CrashReporterGui::CrashReporterGui(QString reportFolder, int pid)
|
||||
mainLayout->addSpacing(textHeight);
|
||||
|
||||
if (qtVersionMatches) {
|
||||
mainLayout->addWidget(new QLabel("Please open a bug report for this issue via github or email.")
|
||||
mainLayout->addWidget(
|
||||
new QLabel("Please open a bug report for this issue on the issue tracker.")
|
||||
);
|
||||
} else {
|
||||
mainLayout->addWidget(new QLabel(
|
||||
"Please rebuild Quickshell against the current Qt version.\n"
|
||||
"If this does not solve the problem, please open a bug report via github or email."
|
||||
"If this does not solve the problem, please open a bug report on the issue tracker."
|
||||
));
|
||||
}
|
||||
|
||||
mainLayout->addWidget(new ReportLabel(
|
||||
"Github:",
|
||||
"https://github.com/quickshell-mirror/quickshell/issues/new?template=crash.yml",
|
||||
this
|
||||
));
|
||||
|
||||
mainLayout->addWidget(new ReportLabel("Email:", "[email protected]", this));
|
||||
mainLayout->addWidget(new ReportLabel("Tracker:", crashreportUrl(), this));
|
||||
|
||||
auto* buttons = new QWidget(this);
|
||||
buttons->setMinimumWidth(900);
|
||||
@@ -111,10 +118,5 @@ void CrashReporterGui::openFolder() {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(this->reportFolder));
|
||||
}
|
||||
|
||||
void CrashReporterGui::openReportUrl() {
|
||||
QDesktopServices::openUrl(
|
||||
QUrl("https://github.com/outfoxxed/quickshell/issues/new?template=crash.yml")
|
||||
);
|
||||
}
|
||||
|
||||
void CrashReporterGui::openReportUrl() { QDesktopServices::openUrl(QUrl(crashreportUrl())); }
|
||||
void CrashReporterGui::cancel() { QApplication::quit(); }
|
||||
+110
-51
@@ -1,9 +1,11 @@
|
||||
#include "main.hpp"
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <cpptrace/basic.hpp>
|
||||
#include <cpptrace/formatting.hpp>
|
||||
#include <qapplication.h>
|
||||
#include <qconfig.h>
|
||||
#include <qcoreapplication.h>
|
||||
#include <qdatastream.h>
|
||||
#include <qdir.h>
|
||||
@@ -12,15 +14,19 @@
|
||||
#include <qloggingcategory.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qtextstream.h>
|
||||
#include <qtversion.h>
|
||||
#include <qtypes.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../core/debuginfo.hpp"
|
||||
#include "../core/instanceinfo.hpp"
|
||||
#include "../core/logcat.hpp"
|
||||
#include "../core/logging.hpp"
|
||||
#include "../core/logging_p.hpp"
|
||||
#include "../core/paths.hpp"
|
||||
#include "build.hpp"
|
||||
#include "../core/plugin.hpp"
|
||||
#include "../core/ringbuf.hpp"
|
||||
#include "interface.hpp"
|
||||
|
||||
namespace {
|
||||
@@ -61,6 +67,76 @@ int tryDup(int fd, const QString& path) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString readRecentLogs(int logFd, int maxLines, qint64 maxAgeSecs) {
|
||||
QFile file;
|
||||
if (!file.open(logFd, QFile::ReadOnly, QFile::AutoCloseHandle)) {
|
||||
return QStringLiteral("(failed to open log fd)\n");
|
||||
}
|
||||
|
||||
file.seek(0);
|
||||
|
||||
qs::log::EncodedLogReader reader;
|
||||
reader.setDevice(&file);
|
||||
|
||||
bool readable = false;
|
||||
quint8 logVersion = 0;
|
||||
quint8 readerVersion = 0;
|
||||
if (!reader.readHeader(&readable, &logVersion, &readerVersion) || !readable) {
|
||||
return QStringLiteral("(failed to read log header)\n");
|
||||
}
|
||||
|
||||
// Read all messages, keeping last maxLines in a ring buffer
|
||||
auto tail = RingBuffer<qs::log::LogMessage>(maxLines);
|
||||
qs::log::LogMessage message;
|
||||
while (reader.read(&message)) {
|
||||
tail.emplace(message);
|
||||
}
|
||||
|
||||
if (tail.size() == 0) {
|
||||
return QStringLiteral("(no logs)\n");
|
||||
}
|
||||
|
||||
// Filter to only messages within maxAgeSecs of the newest message
|
||||
auto cutoff = tail.at(0).time.addSecs(-maxAgeSecs);
|
||||
|
||||
QString result;
|
||||
auto stream = QTextStream(&result);
|
||||
for (auto i = tail.size() - 1; i != -1; i--) {
|
||||
if (tail.at(i).time < cutoff) continue;
|
||||
qs::log::LogMessage::formatMessage(stream, tail.at(i), false, true);
|
||||
stream << '\n';
|
||||
}
|
||||
|
||||
if (result.isEmpty()) {
|
||||
return QStringLiteral("(no recent logs)\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
cpptrace::stacktrace resolveStacktrace(int dumpFd) {
|
||||
QFile sourceFile;
|
||||
if (!sourceFile.open(dumpFd, QFile::ReadOnly, QFile::AutoCloseHandle)) {
|
||||
qCCritical(logCrashReporter) << "Failed to open trace memfd.";
|
||||
return {};
|
||||
}
|
||||
|
||||
sourceFile.seek(0);
|
||||
auto data = sourceFile.readAll();
|
||||
|
||||
auto frameCount = static_cast<size_t>(data.size()) / sizeof(cpptrace::safe_object_frame);
|
||||
if (frameCount == 0) return {};
|
||||
|
||||
const auto* frames = reinterpret_cast<const cpptrace::safe_object_frame*>(data.constData());
|
||||
|
||||
cpptrace::object_trace objectTrace;
|
||||
for (size_t i = 0; i < frameCount; i++) {
|
||||
objectTrace.frames.push_back(frames[i].resolve()); // NOLINT
|
||||
}
|
||||
|
||||
return objectTrace.resolve();
|
||||
}
|
||||
|
||||
void recordCrashInfo(const QDir& crashDir, const InstanceInfo& instance) {
|
||||
qCDebug(logCrashReporter) << "Recording crash information at" << crashDir.path();
|
||||
|
||||
@@ -71,74 +147,49 @@ void recordCrashInfo(const QDir& crashDir, const InstanceInfo& instance) {
|
||||
}
|
||||
|
||||
auto crashProc = qEnvironmentVariable("__QUICKSHELL_CRASH_DUMP_PID").toInt();
|
||||
auto crashSignal = qEnvironmentVariable("__QUICKSHELL_CRASH_SIGNAL").toInt();
|
||||
auto dumpFd = qEnvironmentVariable("__QUICKSHELL_CRASH_DUMP_FD").toInt();
|
||||
auto logFd = qEnvironmentVariable("__QUICKSHELL_CRASH_LOG_FD").toInt();
|
||||
|
||||
qCDebug(logCrashReporter) << "Saving minidump from fd" << dumpFd;
|
||||
auto dumpDupStatus = tryDup(dumpFd, crashDir.filePath("minidump.dmp.log"));
|
||||
if (dumpDupStatus != 0) {
|
||||
qCCritical(logCrashReporter) << "Failed to write minidump:" << dumpDupStatus;
|
||||
}
|
||||
qCDebug(logCrashReporter) << "Resolving stacktrace from fd" << dumpFd;
|
||||
auto stacktrace = resolveStacktrace(dumpFd);
|
||||
|
||||
qCDebug(logCrashReporter) << "Saving log from fd" << logFd;
|
||||
auto logDupStatus = tryDup(logFd, crashDir.filePath("log.qslog.log"));
|
||||
qCDebug(logCrashReporter) << "Reading recent log lines from fd" << logFd;
|
||||
auto logDupFd = dup(logFd);
|
||||
auto recentLogs = readRecentLogs(logFd, 100, 10);
|
||||
|
||||
qCDebug(logCrashReporter) << "Saving log from fd" << logDupFd;
|
||||
auto logDupStatus = tryDup(logDupFd, crashDir.filePath("log.qslog.log"));
|
||||
if (logDupStatus != 0) {
|
||||
qCCritical(logCrashReporter) << "Failed to save log:" << logDupStatus;
|
||||
}
|
||||
|
||||
auto copyBinStatus = 0;
|
||||
if (!DISTRIBUTOR_DEBUGINFO_AVAILABLE) {
|
||||
qCDebug(logCrashReporter) << "Copying binary to crash folder";
|
||||
if (!QFile(QCoreApplication::applicationFilePath()).copy(crashDir.filePath("executable.txt"))) {
|
||||
copyBinStatus = 1;
|
||||
qCCritical(logCrashReporter) << "Failed to copy binary.";
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto extraInfoFile = QFile(crashDir.filePath("info.txt"));
|
||||
auto extraInfoFile = QFile(crashDir.filePath("report.txt"));
|
||||
if (!extraInfoFile.open(QFile::WriteOnly)) {
|
||||
qCCritical(logCrashReporter) << "Failed to open crash info file for writing.";
|
||||
} else {
|
||||
auto stream = QTextStream(&extraInfoFile);
|
||||
stream << "===== Build Information =====\n";
|
||||
stream << "Git Revision: " << GIT_REVISION << '\n';
|
||||
stream << "Buildtime Qt Version: " << QT_VERSION_STR << "\n";
|
||||
stream << "Build Type: " << BUILD_TYPE << '\n';
|
||||
stream << "Compiler: " << COMPILER << '\n';
|
||||
stream << "Complie Flags: " << COMPILE_FLAGS << "\n\n";
|
||||
stream << "Build configuration:\n" << BUILD_CONFIGURATION << "\n";
|
||||
stream << qs::debuginfo::combinedInfo();
|
||||
|
||||
stream << "\n===== Runtime Information =====\n";
|
||||
stream << "Runtime Qt Version: " << qVersion() << '\n';
|
||||
stream << "\n===== Instance Information =====\n";
|
||||
stream << "Signal: " << strsignal(crashSignal) << " (" << crashSignal << ")\n"; // NOLINT
|
||||
stream << "Crashed process ID: " << crashProc << '\n';
|
||||
stream << "Run ID: " << instance.instanceId << '\n';
|
||||
stream << "Shell ID: " << instance.shellId << '\n';
|
||||
stream << "Config Path: " << instance.configPath << '\n';
|
||||
|
||||
stream << "\n===== Report Integrity =====\n";
|
||||
stream << "Minidump save status: " << dumpDupStatus << '\n';
|
||||
stream << "Log save status: " << logDupStatus << '\n';
|
||||
stream << "Binary copy status: " << copyBinStatus << '\n';
|
||||
|
||||
stream << "\n===== System Information =====\n\n";
|
||||
stream << "/etc/os-release:";
|
||||
auto osReleaseFile = QFile("/etc/os-release");
|
||||
if (osReleaseFile.open(QFile::ReadOnly)) {
|
||||
stream << '\n' << osReleaseFile.readAll() << '\n';
|
||||
osReleaseFile.close();
|
||||
stream << "\n===== Stacktrace =====\n";
|
||||
if (stacktrace.empty()) {
|
||||
stream << "(no trace available)\n";
|
||||
} else {
|
||||
stream << "FAILED TO OPEN\n";
|
||||
auto formatter = cpptrace::formatter().header(std::string());
|
||||
auto traceStr = formatter.format(stacktrace);
|
||||
stream << QString::fromStdString(traceStr) << '\n';
|
||||
}
|
||||
|
||||
stream << "/etc/lsb-release:";
|
||||
auto lsbReleaseFile = QFile("/etc/lsb-release");
|
||||
if (lsbReleaseFile.open(QFile::ReadOnly)) {
|
||||
stream << '\n' << lsbReleaseFile.readAll();
|
||||
lsbReleaseFile.close();
|
||||
} else {
|
||||
stream << "FAILED TO OPEN\n";
|
||||
}
|
||||
stream << "\n===== Log Tail =====\n";
|
||||
stream << recentLogs;
|
||||
|
||||
extraInfoFile.close();
|
||||
}
|
||||
@@ -161,7 +212,10 @@ void qsCheckCrash(int argc, char** argv) {
|
||||
auto infoFd = qEnvironmentVariable("__QUICKSHELL_CRASH_INFO_FD").toInt();
|
||||
|
||||
QFile file;
|
||||
file.open(infoFd, QFile::ReadOnly, QFile::AutoCloseHandle);
|
||||
if (!file.open(infoFd, QFile::ReadOnly, QFile::AutoCloseHandle)) {
|
||||
qFatal() << "Failed to open instance info fd.";
|
||||
}
|
||||
|
||||
file.seek(0);
|
||||
|
||||
auto ds = QDataStream(&file);
|
||||
@@ -177,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);
|
||||
|
||||
@@ -183,7 +183,7 @@ void DBusMenuItem::updateProperties(const QVariantMap& properties, const QString
|
||||
}
|
||||
} else if (removed.isEmpty() || removed.contains("icon-data")) {
|
||||
imageChanged = this->image.hasData();
|
||||
image.data.clear();
|
||||
this->image.data.clear();
|
||||
}
|
||||
|
||||
auto type = properties.value("type");
|
||||
@@ -301,6 +301,13 @@ DBusMenu::DBusMenu(const QString& service, const QString& path, QObject* parent)
|
||||
&DBusMenu::onLayoutUpdated
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
this->interface,
|
||||
&DBusMenuInterface::ItemsPropertiesUpdated,
|
||||
this,
|
||||
&DBusMenu::onItemPropertiesUpdated
|
||||
);
|
||||
|
||||
this->properties.setInterface(this->interface);
|
||||
this->properties.updateAllViaGetAll();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class DBusMenuPngImage: public QsIndexedImageHandle {
|
||||
public:
|
||||
explicit DBusMenuPngImage(): QsIndexedImageHandle(QQuickImageProvider::Image) {}
|
||||
|
||||
[[nodiscard]] bool hasData() const { return !data.isEmpty(); }
|
||||
[[nodiscard]] bool hasData() const { return !this->data.isEmpty(); }
|
||||
QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
|
||||
QByteArray data;
|
||||
|
||||
@@ -214,8 +214,10 @@ void DBusPropertyGroup::updatePropertySet(const QVariantMap& properties, bool co
|
||||
}
|
||||
}
|
||||
|
||||
void DBusPropertyGroup::tryUpdateProperty(DBusPropertyCore* property, const QVariant& variant)
|
||||
const {
|
||||
void DBusPropertyGroup::tryUpdateProperty(
|
||||
DBusPropertyCore* property,
|
||||
const QVariant& variant
|
||||
) const {
|
||||
property->mExists = true;
|
||||
|
||||
auto error = property->store(variant);
|
||||
|
||||
@@ -217,7 +217,7 @@ protected:
|
||||
|
||||
private:
|
||||
[[nodiscard]] constexpr Owner* owner() const {
|
||||
auto* self = std::bit_cast<char*>(this);
|
||||
auto* self = std::bit_cast<char*>(this); // NOLINT
|
||||
return std::bit_cast<Owner*>(self - offset()); // NOLINT
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
#include <qqmlinfo.h>
|
||||
#include <qquickitem.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qstringliteral.h>
|
||||
#include <qstring.h>
|
||||
|
||||
#include "../core/logcat.hpp"
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ qt_add_qml_module(quickshell-io
|
||||
qs_add_module_deps_light(quickshell-io Quickshell)
|
||||
install_qml_module(quickshell-io)
|
||||
|
||||
target_link_libraries(quickshell-io PRIVATE Qt::Quick)
|
||||
target_link_libraries(quickshell-io PRIVATE Qt::Quick quickshell-ipc)
|
||||
target_link_libraries(quickshell PRIVATE quickshell-ioplugin)
|
||||
|
||||
qs_module_pch(quickshell-io)
|
||||
|
||||
@@ -51,7 +51,7 @@ void SplitParser::parseBytes(QByteArray& incoming, QByteArray& buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure we dont miss any delimiters in the buffer if the delimiter changes
|
||||
// make sure we don't miss any delimiters in the buffer if the delimiter changes
|
||||
if (this->mSplitMarkerChanged) {
|
||||
this->mSplitMarkerChanged = false;
|
||||
this->parseBytes(buffer, buffer);
|
||||
|
||||
+4
-2
@@ -93,7 +93,8 @@ void FileViewReader::run() {
|
||||
FileViewReader::read(this->owner, this->state, this->doStringConversion, this->shouldCancel);
|
||||
|
||||
if (this->shouldCancel.loadAcquire()) {
|
||||
qCDebug(logFileView) << "Read" << this << "of" << state.path << "canceled for" << this->owner;
|
||||
qCDebug(logFileView) << "Read" << this << "of" << this->state.path << "canceled for"
|
||||
<< this->owner;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ void FileViewWriter::run() {
|
||||
FileViewWriter::write(this->owner, this->state, this->doAtomicWrite, this->shouldCancel);
|
||||
|
||||
if (this->shouldCancel.loadAcquire()) {
|
||||
qCDebug(logFileView) << "Write" << this << "of" << state.path << "canceled for"
|
||||
qCDebug(logFileView) << "Write" << this << "of" << this->state.path << "canceled for"
|
||||
<< this->owner;
|
||||
}
|
||||
}
|
||||
@@ -494,6 +495,7 @@ void FileView::updateWatchedFiles() {
|
||||
// If inotify events are sent to the watcher after deletion and deleteLater
|
||||
// isn't used, a use after free in the QML engine will occur.
|
||||
if (this->watcher) {
|
||||
QObject::disconnect(this->watcher, nullptr, this, nullptr);
|
||||
this->watcher->deleteLater();
|
||||
this->watcher = nullptr;
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,9 +29,9 @@ class FileViewError: public QObject {
|
||||
|
||||
public:
|
||||
enum Enum : quint8 {
|
||||
/// No error occured.
|
||||
/// No error occurred.
|
||||
Success = 0,
|
||||
/// An unknown error occured. Check the logs for details.
|
||||
/// An unknown error occurred. Check the logs for details.
|
||||
Unknown = 1,
|
||||
/// The file to read does not exist.
|
||||
FileNotFound = 2,
|
||||
@@ -204,7 +204,7 @@ class FileView: public QObject {
|
||||
///
|
||||
/// > [!NOTE] This works by creating another file with the desired content, and renaming
|
||||
/// > it over the existing file if successful.
|
||||
Q_PROPERTY(bool atomicWrites READ default WRITE default NOTIFY blockWritesChanged BINDABLE bindableAtomicWrites);
|
||||
Q_PROPERTY(bool atomicWrites READ default WRITE default NOTIFY atomicWritesChanged BINDABLE bindableAtomicWrites);
|
||||
/// If true (default), read or write errors will be printed to the quickshell logs.
|
||||
/// If false, all known errors will not be printed.
|
||||
QSDOC_PROPERTY_OVERRIDE(bool printErrors READ default WRITE default NOTIFY printErrorsChanged);
|
||||
|
||||
Loaded 100 of 339 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user