Compare commits
255 Commits
4574977287
...
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df4c6a3d9b | ||
|
|
3b9e2c5812 | ||
|
|
b99c7db73e | ||
|
|
7c15a1438a | ||
|
|
2b52edd9e3 | ||
|
|
9175489f65 | ||
|
|
45ffdf9849 | ||
|
|
96de4f07ca | ||
|
|
a93bbc30e5 | ||
|
|
6315faed20 | ||
|
|
580aef939f | ||
|
|
071b77c49f | ||
|
|
0dcca2228e | ||
|
|
bb097730c7 | ||
|
|
8d0284da1b | ||
|
|
9b6b6855d7 | ||
|
|
2d98518b7d | ||
|
|
7f3f8b37b5 | ||
|
|
42782689e8 | ||
|
|
216bfefd9f | ||
|
|
bef1240b41 | ||
|
|
7e7c2b0cef | ||
|
|
f509008cb9 | ||
|
|
8c96fbebc4 | ||
|
|
05b1fbff9e | ||
|
|
613d179f2d | ||
|
|
84b9ff3148 | ||
|
|
7da8b7afeb | ||
|
|
5b81ea2c58 | ||
|
|
2238cf1e54 | ||
|
|
85bb56e8a6 | ||
|
|
241d7f1d03 | ||
|
|
e8d42885fa | ||
|
|
e948b74363 | ||
|
|
64f6c4885a | ||
|
|
23b0c5a1d5 | ||
|
|
c7591982b6 | ||
|
|
1aa90f6466 | ||
|
|
b0dfcf4a32 | ||
|
|
28cb220b5b | ||
|
|
c6db632d9d | ||
|
|
f28905b62d | ||
|
|
53dd8a4e66 | ||
|
|
f179119d84 | ||
|
|
466fb4c9e0 | ||
|
|
4f792243c1 | ||
|
|
9392829d84 | ||
|
|
a4ec70982c | ||
|
|
0ab3e0740e | ||
|
|
7ada6db4a3 | ||
|
|
75d0b7ba1e | ||
|
|
a5826b6fb0 | ||
|
|
bdc0943399 | ||
|
|
baeafb3a3b | ||
|
|
037be5cca2 | ||
|
|
0e1628e031 | ||
|
|
642a43acbb | ||
|
|
755996a42c | ||
|
|
eb723eee29 | ||
|
|
fcd51e7373 | ||
|
|
dff77aae27 | ||
|
|
709f0168d9 | ||
|
|
726b8d0e28 | ||
|
|
023103c620 | ||
|
|
39534b98f0 | ||
|
|
0f22b70705 | ||
|
|
f265e049a8 | ||
|
|
a39cd94e1f | ||
|
|
7fad0d51d7 | ||
|
|
9204426caf | ||
|
|
0d3d18cd88 | ||
|
|
c738400058 | ||
|
|
eb39426b08 | ||
|
|
77c4ebaafc | ||
|
|
e8ca1912cd | ||
|
|
0ed8d0cadf | ||
|
|
bbc657e4bc | ||
|
|
839a101527 | ||
|
|
5c640ac452 | ||
|
|
4a79e7b777 | ||
|
|
a655730e49 | ||
|
|
4401666cfb | ||
|
|
90f5f4ca29 | ||
|
|
c1b4ede06e | ||
|
|
238c3cc833 | ||
|
|
0638de5c56 | ||
|
|
fdbcd15975 | ||
|
|
bacdb919c7 | ||
|
|
733113c691 | ||
|
|
14a345a817 | ||
|
|
5fba210ad6 | ||
|
|
1bfb129985 | ||
|
|
8ca66f8a00 | ||
|
|
f3bdd01dc8 | ||
|
|
71e29c4128 | ||
|
|
606844c4bb | ||
|
|
39de1e49cf | ||
|
|
fffc7ce535 | ||
|
|
fe5b416ed6 | ||
|
|
2417084628 | ||
|
|
4299336146 | ||
|
|
702e30df4a | ||
|
|
d87dd41f4c | ||
|
|
ce205d1591 | ||
|
|
4c4df9b918 | ||
|
|
56da153f1c | ||
|
|
81d137a3cc | ||
|
|
6e3c86226b | ||
|
|
197b4bd396 | ||
|
|
a3f50e8a3b | ||
|
|
4c34944d76 | ||
|
|
a73ca2dc8d | ||
|
|
1b8d321c45 | ||
|
|
30e37dbf09 | ||
|
|
dc2d7b2876 | ||
|
|
5e119123a7 | ||
|
|
6d4eaec811 | ||
|
|
eb3a58a6b0 | ||
|
|
3390494bfe | ||
|
|
148e61a0b2 | ||
|
|
d8f303761b | ||
|
|
217284642a | ||
|
|
496452cfce | ||
|
|
cacb45fbcd | ||
|
|
7336e4142b | ||
|
|
b368072e12 | ||
|
|
359d004b99 | ||
|
|
6e0bad0034 | ||
|
|
a28e221b83 | ||
|
|
b582d2989e | ||
|
|
db9b808bfb | ||
|
|
db6ed75b60 | ||
|
|
dd83f550e1 | ||
|
|
c42e6cef0a | ||
|
|
25d16b0352 | ||
|
|
3838b45e2c | ||
|
|
4b57e3aa4c | ||
|
|
1430d28116 | ||
|
|
147561a313 | ||
|
|
23eb3d5f52 | ||
|
|
2e1c4e51b3 | ||
|
|
827380e1e3 | ||
|
|
8d98b7d639 | ||
|
|
e76cf43f02 | ||
|
|
c178be2874 | ||
|
|
7da885e6c0 | ||
|
|
70ea36bedd | ||
|
|
fd9c52d0ee | ||
|
|
5a8c61daed | ||
|
|
b1fce63a26 | ||
|
|
b73e6a0c45 | ||
|
|
98e842e83b | ||
|
|
2241c7d87a | ||
|
|
21c2da549a | ||
|
|
2b74392ec7 | ||
|
|
367643e98a | ||
|
|
a5c4095082 | ||
|
|
15aa5014a6 | ||
|
|
4d624bbee5 | ||
|
|
dc9d1fe248 | ||
|
|
1c7466c07c | ||
|
|
44cfa0b0ef | ||
|
|
bb2b4801f7 | ||
|
|
36e6b73cde | ||
|
|
90f57e9b1a | ||
|
|
157ecd2077 | ||
|
|
3a791ab559 | ||
|
|
f5e8351507 | ||
|
|
9f14c43989 | ||
|
|
97d9c960e0 | ||
|
|
d41a291fd6 | ||
|
|
c3a7cf29ab | ||
|
|
3b1930d2c6 | ||
|
|
92a32808ae | ||
|
|
d3c467f4c0 | ||
|
|
4be96a92c7 | ||
|
|
ab766b6386 | ||
|
|
7e975cdc5d | ||
|
|
349f2f37db | ||
|
|
7846b17c54 | ||
|
|
a667886959 | ||
|
|
6c08650f3c | ||
|
|
7f533c0b23 | ||
|
|
efa3d9c227 | ||
|
|
0b965b2e5a | ||
|
|
ba2e24af3e | ||
|
|
0278a1fb0b | ||
|
|
931c1b8bf6 | ||
|
|
6906e6694a | ||
|
|
f1bff49b1c | ||
|
|
fe3f53f3a4 | ||
|
|
57956fb219 | ||
|
|
c51020aef7 | ||
|
|
eec8bf79d2 | ||
|
|
227cb55ca5 | ||
|
|
e9ff18e1bd | ||
|
|
43d8d3ed5d | ||
|
|
bf0832cd4c | ||
|
|
9c3204cc72 | ||
|
|
bc1f99f2ae | ||
|
|
d21fb34e55 | ||
|
|
7f18e74b8f | ||
|
|
2173654fbd | ||
|
|
123ef51210 | ||
|
|
4ecc3e65a9 | ||
|
|
4a7a9e8079 | ||
|
|
dacadb9fc3 | ||
|
|
144e78fd5d | ||
|
|
d647ccca16 | ||
|
|
9fe7e65e3e | ||
|
|
ad5a042803 | ||
|
|
0a82f460e0 | ||
|
|
49490ab99f | ||
|
|
9bf39b8d1d | ||
|
|
11a195747a | ||
|
|
89690c9843 | ||
|
|
935885d396 | ||
|
|
611f8b80c2 | ||
|
|
8f848c2b1d | ||
|
|
a10a64f984 | ||
|
|
1434881567 | ||
|
|
fa21c44ee7 | ||
|
|
dbb81b5116 | ||
|
|
f7596fd43a | ||
|
|
f7a950a638 | ||
|
|
fbe7ed5699 | ||
|
|
0004173ecd | ||
|
|
1e5de4067b | ||
|
|
04b80760d8 | ||
|
|
a88393a7df | ||
|
|
8e8a62ae29 | ||
|
|
223533acec | ||
|
|
bcc7d37546 | ||
|
|
332501aef7 | ||
|
|
c9aee893d2 | ||
|
|
a1dcadf81b | ||
|
|
c86652a5c4 | ||
|
|
157cb57ea7 | ||
|
|
ad8feaad12 | ||
|
|
f54315b51c | ||
|
|
fd18476f4b | ||
|
|
8e3ff3d63b | ||
|
|
04b027d495 | ||
|
|
b93ad16e5a | ||
|
|
68b48617c7 | ||
|
|
59d5b95483 | ||
|
|
0a49da1b91 | ||
|
|
260adcdc15 | ||
|
|
4fbc9b33ad | ||
|
|
9e397ef4e9 | ||
|
|
70c729d389 | ||
|
|
23c151c8dc | ||
|
|
b7434c7b76 | ||
|
|
5a8da46952 | ||
|
|
f6b0b04f5b |
@@ -12,6 +12,7 @@ packages:
|
||||
- uthash
|
||||
- libconfig
|
||||
- libglvnd
|
||||
- libepoxy
|
||||
- dbus
|
||||
- pcre
|
||||
sources:
|
||||
@@ -19,7 +20,7 @@ sources:
|
||||
tasks:
|
||||
- setup: |
|
||||
cd picom
|
||||
CPPFLAGS="-I/usr/local/include" meson -Dunittest=true build
|
||||
CPPFLAGS="-I/usr/local/include" meson setup -Dunittest=true --werror build
|
||||
- build: |
|
||||
cd picom
|
||||
ninja -C build
|
||||
|
||||
23
.builds/openbsd.yml
Normal file
23
.builds/openbsd.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
image: openbsd/latest
|
||||
packages:
|
||||
- libev
|
||||
- xcb
|
||||
- meson
|
||||
- pkgconf
|
||||
- cmake
|
||||
- uthash
|
||||
- libconfig
|
||||
- dbus
|
||||
- pcre2
|
||||
sources:
|
||||
- https://github.com/yshui/picom
|
||||
tasks:
|
||||
- setup: |
|
||||
cd picom
|
||||
CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" meson setup -Dunittest=true --werror build
|
||||
- build: |
|
||||
cd picom
|
||||
ninja -C build
|
||||
- unittest: |
|
||||
cd picom
|
||||
ninja -C build test
|
||||
@@ -29,7 +29,7 @@ commands:
|
||||
- ".git"
|
||||
- run:
|
||||
name: config
|
||||
command: CC=<< parameters.cc >> meson << parameters.build-config >> -Dunittest=true --werror . build
|
||||
command: CC=<< parameters.cc >> meson setup << parameters.build-config >> -Dunittest=true --werror . build
|
||||
- run:
|
||||
name: build
|
||||
command: ninja -vC build
|
||||
|
||||
@@ -23,5 +23,9 @@ CheckOptions:
|
||||
value: 255.0;1.0;
|
||||
- key: readability-function-cognitive-complexity.IgnoreMacros
|
||||
value: true
|
||||
- key: readability-function-cognitive-complexity.Threshold
|
||||
value: 50
|
||||
- key: readability-function-cognitive-complexity.DescribeBasicIncrements
|
||||
value: true
|
||||
- key: bugprone-signed-char-misuse.CharTypdefsToIgnore
|
||||
value: int8_t
|
||||
|
||||
@@ -3,3 +3,6 @@ root = true
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
max_line_length = 90
|
||||
[*.nix]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
@@ -18,11 +18,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
|
||||
# Autobuild
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
||||
4
.github/workflows/coding-style-pr.yml
vendored
4
.github/workflows/coding-style-pr.yml
vendored
@@ -6,8 +6,8 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }}
|
||||
- uses: yshui/git-clang-format-lint@v1.14
|
||||
- uses: yshui/git-clang-format-lint@v1.15
|
||||
with:
|
||||
base: ${{ github.event.pull_request.base.sha }}
|
||||
|
||||
4
.github/workflows/coding-style.yml
vendored
4
.github/workflows/coding-style.yml
vendored
@@ -6,9 +6,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 2
|
||||
- uses: yshui/git-clang-format-lint@v1.14
|
||||
- uses: yshui/git-clang-format-lint@v1.15
|
||||
with:
|
||||
base: ${{ github.event.ref }}~1
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
# Build files
|
||||
.deps
|
||||
.direnv
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
config.log
|
||||
@@ -15,6 +16,7 @@ compton
|
||||
build/
|
||||
compile_commands.json
|
||||
build.ninja
|
||||
make.sh
|
||||
|
||||
# language servers
|
||||
.ccls-cache
|
||||
|
||||
74
CHANGELOG.md
Normal file
74
CHANGELOG.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Unreleased
|
||||
|
||||
## New features
|
||||
|
||||
* Allow `corner-radius-rules` to override `corner-radius = 0`. Previously setting corner radius to 0 globally disables rounded corners. (#1170)
|
||||
|
||||
## Notable changes
|
||||
|
||||
* Marginally improve performance when resizing/opening/closing windows. (#1190)
|
||||
|
||||
# v11.2 (2024-Feb-13)
|
||||
|
||||
## Build changes
|
||||
|
||||
* `picom` now depends on `libepoxy` for OpenGL symbol management.
|
||||
|
||||
## Bug fixes
|
||||
|
||||
* Workaround a NVIDIA problem that causes high CPU usage after suspend/resume (#1172, #1168)
|
||||
* Fix building on OpenBSD (#1189, #1188)
|
||||
* Fix occasional freezes (#1040, #1145, #1166)
|
||||
* Fix `corner-radius-rules` not applying sometimes (#1177)
|
||||
* Fix window shader not having an effect when frame opacity is enabled (#1174)
|
||||
* Fix binding root pixmap in case of depth mismatch (#984)
|
||||
|
||||
# v11.1 (2024-Jan-28)
|
||||
|
||||
## Bug fixes
|
||||
|
||||
* Fix missing fading on window close for some window managers. (#704)
|
||||
|
||||
# v11 (2024-Jan-20)
|
||||
|
||||
## Build changes
|
||||
|
||||
* Due to some caveats discovered related to setting the `CAP_SYS_NICE` capability, it is now recommended to **NOT** set this capability for picom.
|
||||
|
||||
## Deprecations
|
||||
|
||||
* Uses of `--sw-opti`, and `--respect-prop-shadow` are now hard errors.
|
||||
* `-F` has been removed completely. It was deprecated before the picom fork.
|
||||
|
||||
# v11-rc1 (2024-Jan-14)
|
||||
|
||||
## Notable features
|
||||
|
||||
* picom now uses dithering to prevent banding. Banding is most notable when using a strong background blur. (#952)
|
||||
* Frame pacing. picom uses present feedback information to schedule new frames when it makes sense to do so. This improves latency, and replaces the `glFlush` and `GL_MaxFramesAllowed=1` hacks we used to do for NVIDIA. (#968 #1156)
|
||||
* Some missing features have been implemented for the EGL backend (#1004 #1007)
|
||||
|
||||
## Bug fixes
|
||||
|
||||
* Many memory/resource leak fixes thanks to @absolutelynothelix . (#977 #978 #979 #980 #982 #985 #992 #1009 #1022)
|
||||
* Fix tiling of wallpaper. (#1002)
|
||||
* Fix some blur artifacts (#1095)
|
||||
* Fix shadow color for transparent shadows (#1124)
|
||||
* Don't spam logs when another compositor is running (#1104)
|
||||
* Fix rounded corners showing as black with the xrender backend (#1003)
|
||||
* Fix blur with rounded windows (#950)
|
||||
|
||||
## Build changes
|
||||
|
||||
* Dependency `pcre` has been replaced by `pcre2`.
|
||||
* New dependency `xcb-util`.
|
||||
* `xinerama` is no longer used.
|
||||
* `picom` now tries to give itself a real-time scheduling priority. ~~Please consider giving `picom` the `CAP_SYS_NICE` capability when packaging it.~~
|
||||
|
||||
## Deprecations
|
||||
|
||||
* The `kawase` blur method is removed. Note this is just an alias to the `dual_kawase` method, which is still available. (#1102)
|
||||
|
||||
# Earlier versions
|
||||
|
||||
Please see the GitHub releases page.
|
||||
@@ -34,6 +34,7 @@ hasufell <julian.ospald at googlemail.com>
|
||||
i-c-u-p
|
||||
Ignacio Taranto <ignacio.taranto at eclypsium.com>
|
||||
Istvan Petres
|
||||
Ivan Malison <ivanmalison at gmail.com>
|
||||
Jake <jakeroggenbuck2 at gmail.com>
|
||||
James Cloos <cloos at jhcloos.com>
|
||||
Jamey Sharp <jamey at minilop.net>
|
||||
@@ -43,6 +44,7 @@ Javeed Shaikh <syscrash2k at gmail.com>
|
||||
Jerónimo Navarro <jnavarro at ancasrl.com.ar>
|
||||
jialeens <jialeadmin at 163.com>
|
||||
Johnny Pribyl <pribylsnbits at gmail.com>
|
||||
Jose Maldonado aka Yukiteru <josemald89 at gmail.com>
|
||||
Keith Packard <keithp at keithp.com>
|
||||
Kevin Kelley <kelleyk at kelleyk.net>
|
||||
ktprograms <ktprograms at gmail.com>
|
||||
@@ -68,6 +70,7 @@ Peter Mattern <matternp at arcor.de>
|
||||
Phil Blundell <pb at reciva.com>
|
||||
Que Quotion <quequotion at bugmenot.com>
|
||||
Rafael Kitover <rkitover at gmail.com>
|
||||
Reith
|
||||
Richard Grenville <pyxlcy at gmail.com>
|
||||
Rytis Karpuska <rytis.karpuska at gmail.com>
|
||||
Samuel Hand <samuel.d.hand at gmail.com>
|
||||
|
||||
17
README.md
17
README.md
@@ -41,7 +41,7 @@ Assuming you already have all the usual building tools installed (e.g. gcc, pyth
|
||||
* pixman
|
||||
* libdbus (optional, disable with the `-Ddbus=false` meson configure flag)
|
||||
* libconfig (optional, disable with the `-Dconfig_file=false` meson configure flag)
|
||||
* libGL, libEGL (optional, disable with the `-Dopengl=false` meson configure flag)
|
||||
* libGL, libEGL, libepoxy (optional, disable with the `-Dopengl=false` meson configure flag)
|
||||
* libpcre2 (optional, disable with the `-Dregex=false` meson configure flag)
|
||||
* libev
|
||||
* uthash
|
||||
@@ -49,13 +49,13 @@ Assuming you already have all the usual building tools installed (e.g. gcc, pyth
|
||||
On Debian based distributions (e.g. Ubuntu), the needed packages are
|
||||
|
||||
```
|
||||
libconfig-dev libdbus-1-dev libegl-dev libev-dev libgl-dev libpcre2-dev libpixman-1-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libxcb-damage0-dev libxcb-dpms0-dev libxcb-glx0-dev libxcb-image0-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-util-dev libxcb-xfixes0-dev libxext-dev meson ninja-build uthash-dev
|
||||
libconfig-dev libdbus-1-dev libegl-dev libev-dev libgl-dev libepoxy-dev libpcre2-dev libpixman-1-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libxcb-damage0-dev libxcb-dpms0-dev libxcb-glx0-dev libxcb-image0-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-util-dev libxcb-xfixes0-dev libxext-dev meson ninja-build uthash-dev
|
||||
```
|
||||
|
||||
On Fedora, the needed packages are
|
||||
|
||||
```
|
||||
dbus-devel gcc git libconfig-devel libdrm-devel libev-devel libX11-devel libX11-xcb libXext-devel libxcb-devel libGL-devel libEGL-devel meson pcre2-devel pixman-devel uthash-devel xcb-util-image-devel xcb-util-renderutil-devel xorg-x11-proto-devel
|
||||
dbus-devel gcc git libconfig-devel libdrm-devel libev-devel libX11-devel libX11-xcb libXext-devel libxcb-devel libGL-devel libEGL-devel libepoxy-devel meson pcre2-devel pixman-devel uthash-devel xcb-util-image-devel xcb-util-renderutil-devel xorg-x11-proto-devel xcb-util-devel
|
||||
```
|
||||
|
||||
To build the documents, you need `asciidoc`
|
||||
@@ -85,12 +85,23 @@ $ ninja -C build
|
||||
|
||||
### To install
|
||||
|
||||
#### AUR (arch)
|
||||
- picom-ftlabs-git
|
||||
Thanks to @Fxzzi for maintaining the package.
|
||||
|
||||
|
||||
``` bash
|
||||
$ ninja -C build install
|
||||
```
|
||||
|
||||
Default install prefix is `/usr/local`, you can change it with `meson configure -Dprefix=<path> build`
|
||||
|
||||
## Running
|
||||
To launch with all animations as a background process you can use:
|
||||
`picom --animations -b`
|
||||
|
||||
To only have specific animations, enable them with cli flags (see `picom --help`) or add them to your picom config.
|
||||
|
||||
## How to Contribute
|
||||
|
||||
All contributions are welcome!
|
||||
|
||||
23
flake.lock
generated
23
flake.lock
generated
@@ -5,11 +5,11 @@
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1689068808,
|
||||
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
|
||||
"lastModified": 1705309234,
|
||||
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
|
||||
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -25,11 +25,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1660459072,
|
||||
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
|
||||
"lastModified": 1703887061,
|
||||
"narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
|
||||
"rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -41,11 +41,12 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1691186842,
|
||||
"narHash": "sha256-wxBVCvZUwq+XS4N4t9NqsHV4E64cPVqQ2fdDISpjcw0=",
|
||||
"path": "/nix/store/d42v5grfq77vr10r336kks0qjp0wij8d-source",
|
||||
"rev": "18036c0be90f4e308ae3ebcab0e14aae0336fe42",
|
||||
"type": "path"
|
||||
"lastModified": 1705856552,
|
||||
"narHash": "sha256-JXfnuEf5Yd6bhMs/uvM67/joxYKoysyE3M2k6T3eWbg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "612f97239e2cc474c13c9dafa0df378058c5ad8d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
|
||||
75
flake.nix
75
flake.nix
@@ -7,28 +7,55 @@
|
||||
};
|
||||
};
|
||||
outputs = {
|
||||
self, flake-utils, nixpkgs, git-ignore-nix, ...
|
||||
}: flake-utils.lib.eachDefaultSystem (system: let
|
||||
overlay = self: super: {
|
||||
picom = super.picom.overrideAttrs (oldAttrs: rec {
|
||||
pname = "picom";
|
||||
buildInputs = [
|
||||
self.pcre2 self.xorg.xcbutil
|
||||
] ++ self.lib.remove self.xorg.libXinerama (
|
||||
self.lib.remove self.pcre oldAttrs.buildInputs
|
||||
);
|
||||
src = git-ignore-nix.lib.gitignoreSource ./.;
|
||||
});
|
||||
};
|
||||
pkgs = import nixpkgs { inherit system overlays; config.allowBroken = true; };
|
||||
overlays = [ overlay ];
|
||||
in rec {
|
||||
inherit overlay overlays;
|
||||
defaultPackage = pkgs.picom;
|
||||
devShell = defaultPackage.overrideAttrs {
|
||||
buildInputs = defaultPackage.buildInputs ++ [
|
||||
pkgs.clang-tools
|
||||
];
|
||||
};
|
||||
});
|
||||
self,
|
||||
flake-utils,
|
||||
nixpkgs,
|
||||
git-ignore-nix,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
overlay = self: super: {
|
||||
picom = super.picom.overrideAttrs (oldAttrs: rec {
|
||||
version = "11";
|
||||
pname = "picom";
|
||||
buildInputs =
|
||||
[
|
||||
self.pcre2
|
||||
self.xorg.xcbutil
|
||||
self.libepoxy
|
||||
]
|
||||
++ self.lib.remove self.xorg.libXinerama (
|
||||
self.lib.remove self.pcre oldAttrs.buildInputs
|
||||
);
|
||||
src = git-ignore-nix.lib.gitignoreSource ./.;
|
||||
});
|
||||
};
|
||||
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
config.allowBroken = true;
|
||||
};
|
||||
|
||||
overlays = [overlay];
|
||||
in rec {
|
||||
inherit
|
||||
overlay
|
||||
overlays
|
||||
;
|
||||
defaultPackage = pkgs.picom;
|
||||
devShell = defaultPackage.overrideAttrs {
|
||||
buildInputs =
|
||||
defaultPackage.buildInputs
|
||||
++ (with pkgs; [
|
||||
clang-tools_17
|
||||
llvmPackages_17.clang-unwrapped.python
|
||||
]);
|
||||
hardeningDisable = ["fortify"];
|
||||
shellHook = ''
|
||||
# Workaround a NixOS limitation on sanitizers:
|
||||
# See: https://github.com/NixOS/nixpkgs/issues/287763
|
||||
export LD_LIBRARY_PATH+=":/run/opengl-driver/lib"
|
||||
'';
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,9 +49,6 @@ OPTIONS
|
||||
*-f*, *--fading*::
|
||||
Fade windows in/out when opening/closing and when opacity changes, unless *--no-fading-openclose* is used.
|
||||
|
||||
*-F*::
|
||||
Equals to *-f*. Deprecated.
|
||||
|
||||
*-i*, *--inactive-opacity*='OPACITY'::
|
||||
Opacity of inactive windows. (0.1 - 1.0, defaults to 1.0)
|
||||
|
||||
@@ -393,6 +390,7 @@ uniform float corner_radius; // corner radius of the window (pixels)
|
||||
uniform float border_width; // estimated border width of the window (pixels)
|
||||
uniform bool invert_color; // whether to invert the color of the window
|
||||
uniform sampler2D tex; // texture of the window
|
||||
uniform vec2 effective_size; // effective dimensions of the texture (repeats pixels if larger than tex)
|
||||
uniform sampler2D brightness; // estimated brightness of the window, 1x1 texture
|
||||
uniform float max_brightness; // configured maximum brightness of the window (0.0 - 1.0)
|
||||
uniform float time; // time in milliseconds, counting from an unspecified starting point
|
||||
@@ -418,7 +416,8 @@ vec4 default_post_processing(vec4 c);
|
||||
// 1) fetch the specified pixel
|
||||
// 2) apply default post-processing
|
||||
vec4 window_shader() {
|
||||
vec4 c = texelFetch(tex, ivec2(texcoord), 0);
|
||||
vec2 texsize = textureSize(tex, 0);
|
||||
vec4 c = texture2D(tex, texcoord / texsize, 0);
|
||||
return default_post_processing(c);
|
||||
}
|
||||
----
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
project('picom', 'c', version: '10',
|
||||
project('picom', 'c', version: '11',
|
||||
default_options: ['c_std=c11', 'warning_level=1'])
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
@@ -1,29 +1,76 @@
|
||||
#################################
|
||||
# Animations #
|
||||
|
||||
# !These animations WILL NOT work correctly for any other wm other than phyOS-dwm fork!
|
||||
|
||||
# fly-in: Windows fly in from random directions to the screen
|
||||
# maximize: Windows pop from center of the screen to their respective positions
|
||||
# minimize: Windows minimize from their position to the center of the screen
|
||||
# slide-in-center: Windows move from upper-center of the screen to their respective positions
|
||||
# slide-out-center: Windows move to the upper-center of the screen
|
||||
# slide-left: Windows are created from the right-most window position and slide leftwards
|
||||
# slide right: Windows are created from the left-most window position and slide rightwards
|
||||
# slide-down: Windows are moved from the top of the screen and slide downward
|
||||
# slide-up: Windows are moved from their position to top of the screen
|
||||
# squeeze: Windows are either closed or created to/from their center y-position (the animation is similar to a blinking eye)
|
||||
# squeeze-bottom: Similar to squeeze, but the animation starts from bottom-most y-position
|
||||
# zoom: Windows are either created or destroyed from/to their center (not the screen center)
|
||||
|
||||
#################################
|
||||
|
||||
#enable or disable animations
|
||||
animations = true;
|
||||
#change animation speed of windows in current tag e.g open window in current tag
|
||||
animation-stiffness-in-tag = 125;
|
||||
#change animation speed of windows when tag changes
|
||||
animation-stiffness-tag-change = 90.0;
|
||||
|
||||
animation-window-mass = 0.4;
|
||||
animation-dampening = 15;
|
||||
animation-clamping = true;
|
||||
|
||||
#open windows
|
||||
animation-for-open-window = "zoom";
|
||||
#minimize or close windows
|
||||
animation-for-unmap-window = "squeeze";
|
||||
#popup windows
|
||||
animation-for-transient-window = "slide-up"; #available options: slide-up, slide-down, slide-left, slide-right, squeeze, squeeze-bottom, zoom
|
||||
|
||||
#set animation for windows being transitioned out while changings tags
|
||||
animation-for-prev-tag = "minimize";
|
||||
#enables fading for windows being transitioned out while changings tags
|
||||
enable-fading-prev-tag = true;
|
||||
|
||||
#set animation for windows being transitioned in while changings tags
|
||||
animation-for-next-tag = "slide-in-center";
|
||||
#enables fading for windows being transitioned in while changings tags
|
||||
enable-fading-next-tag = true;
|
||||
|
||||
#################################
|
||||
# Shadows #
|
||||
#################################
|
||||
|
||||
|
||||
# Enabled client-side shadows on windows. Note desktop windows
|
||||
# (windows with '_NET_WM_WINDOW_TYPE_DESKTOP') never get shadow,
|
||||
# unless explicitly requested using the wintypes option.
|
||||
#
|
||||
# shadow = false
|
||||
shadow = true;
|
||||
shadow = false;
|
||||
|
||||
# The blur radius for shadows, in pixels. (defaults to 12)
|
||||
# shadow-radius = 12
|
||||
shadow-radius = 7;
|
||||
shadow-radius = 60;
|
||||
|
||||
# The opacity of shadows. (0.0 - 1.0, defaults to 0.75)
|
||||
# shadow-opacity = .75
|
||||
|
||||
# The left offset for shadows, in pixels. (defaults to -15)
|
||||
# shadow-offset-x = -15
|
||||
shadow-offset-x = -7;
|
||||
shadow-offset-x = -20;
|
||||
|
||||
# The top offset for shadows, in pixels. (defaults to -15)
|
||||
# shadow-offset-y = -15
|
||||
shadow-offset-y = -7;
|
||||
shadow-offset-y = -20;
|
||||
|
||||
# Red color value of shadow (0.0 - 1.0, defaults to 0).
|
||||
# shadow-red = 0
|
||||
@@ -48,6 +95,9 @@ shadow-exclude = [
|
||||
"class_g = 'Conky'",
|
||||
"class_g ?= 'Notify-osd'",
|
||||
"class_g = 'Cairo-clock'",
|
||||
"class_g = 'dwm'",
|
||||
"class_g = 'chromium'",
|
||||
"class_g *?= 'slop'",
|
||||
"_GTK_FRAME_EXTENTS@:c"
|
||||
];
|
||||
|
||||
@@ -73,19 +123,18 @@ shadow-exclude = [
|
||||
|
||||
# Fade windows in/out when opening/closing and when opacity changes,
|
||||
# unless no-fading-openclose is used.
|
||||
# fading = false
|
||||
fading = true;
|
||||
|
||||
# Opacity change between steps while fading in. (0.01 - 1.0, defaults to 0.028)
|
||||
# fade-in-step = 0.028
|
||||
fade-in-step = 0.03;
|
||||
fade-in-step = 0.023;
|
||||
|
||||
# Opacity change between steps while fading out. (0.01 - 1.0, defaults to 0.03)
|
||||
# fade-out-step = 0.03
|
||||
fade-out-step = 0.03;
|
||||
fade-out-step = 0.035;
|
||||
|
||||
# The time between steps in fade step, in milliseconds. (> 0, defaults to 10)
|
||||
# fade-delta = 10
|
||||
fade-delta = 10
|
||||
|
||||
# Specify a list of conditions of windows that should not be faded.
|
||||
# fade-exclude = []
|
||||
@@ -104,15 +153,13 @@ fade-out-step = 0.03;
|
||||
|
||||
# Opacity of inactive windows. (0.1 - 1.0, defaults to 1.0)
|
||||
# inactive-opacity = 1
|
||||
inactive-opacity = 0.8;
|
||||
|
||||
# Opacity of window titlebars and borders. (0.1 - 1.0, disabled by default)
|
||||
# frame-opacity = 1.0
|
||||
frame-opacity = 0.7;
|
||||
|
||||
# Let inactive opacity set by -i override the '_NET_WM_WINDOW_OPACITY' values of windows.
|
||||
# inactive-opacity-override = true
|
||||
inactive-opacity-override = false;
|
||||
inactive-opacity-override = true;
|
||||
|
||||
# Default opacity for active windows. (0.0 - 1.0, defaults to 1.0)
|
||||
# active-opacity = 1.0
|
||||
@@ -122,21 +169,13 @@ inactive-opacity-override = false;
|
||||
|
||||
# Specify a list of conditions of windows that should never be considered focused.
|
||||
# focus-exclude = []
|
||||
focus-exclude = [ "class_g = 'Cairo-clock'" ];
|
||||
focus-exclude = [
|
||||
"class_g = 'Cairo-clock'" ,
|
||||
];
|
||||
|
||||
# Use fixed inactive dim value, instead of adjusting according to window opacity.
|
||||
# inactive-dim-fixed = 1.0
|
||||
|
||||
# Specify a list of opacity rules, in the format `PERCENT:PATTERN`,
|
||||
# like `50:name *= "Firefox"`. picom-trans is recommended over this.
|
||||
# Note we don't make any guarantee about possible conflicts with other
|
||||
# programs that set '_NET_WM_WINDOW_OPACITY' on frame or client windows.
|
||||
# example:
|
||||
# opacity-rule = [ "80:class_g = 'URxvt'" ];
|
||||
#
|
||||
# opacity-rule = []
|
||||
|
||||
|
||||
#################################
|
||||
# Corners #
|
||||
#################################
|
||||
@@ -144,52 +183,21 @@ focus-exclude = [ "class_g = 'Cairo-clock'" ];
|
||||
# Sets the radius of rounded window corners. When > 0, the compositor will
|
||||
# round the corners of windows. Does not interact well with
|
||||
# `transparent-clipping`.
|
||||
corner-radius = 0
|
||||
corner-radius = 11;
|
||||
|
||||
# Exclude conditions for rounded corners.
|
||||
rounded-corners-exclude = [
|
||||
"window_type = 'dock'",
|
||||
"window_type = 'desktop'"
|
||||
];
|
||||
#rounded-corners-exclude = [
|
||||
# "window_type = 'dock'",
|
||||
# "window_type = 'desktop'"
|
||||
#];
|
||||
|
||||
|
||||
#################################
|
||||
# Background-Blurring #
|
||||
#################################
|
||||
|
||||
|
||||
# Parameters for background blurring, see the *BLUR* section for more information.
|
||||
# blur-method =
|
||||
# blur-size = 12
|
||||
#
|
||||
# blur-deviation = false
|
||||
#
|
||||
# blur-strength = 5
|
||||
|
||||
# Blur background of semi-transparent / ARGB windows.
|
||||
# Bad in performance, with driver-dependent behavior.
|
||||
# The name of the switch may change without prior notifications.
|
||||
#
|
||||
# blur-background = false
|
||||
|
||||
# Blur background of windows when the window frame is not opaque.
|
||||
# Implies:
|
||||
# blur-background
|
||||
# Bad in performance, with driver-dependent behavior. The name may change.
|
||||
#
|
||||
# blur-background-frame = false
|
||||
|
||||
|
||||
# Use fixed blur strength rather than adjusting according to window opacity.
|
||||
# blur-background-fixed = false
|
||||
|
||||
|
||||
# Specify the blur convolution kernel, with the following format:
|
||||
# example:
|
||||
# blur-kern = "5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1";
|
||||
#
|
||||
# blur-kern = ""
|
||||
blur-kern = "3x3box";
|
||||
blur: {
|
||||
method = "dual_kawase";
|
||||
strength = 9;
|
||||
background = true;
|
||||
background-frame = false;
|
||||
background-fixed = false;
|
||||
}
|
||||
|
||||
|
||||
# Exclude conditions for background blur.
|
||||
@@ -197,24 +205,25 @@ blur-kern = "3x3box";
|
||||
blur-background-exclude = [
|
||||
"window_type = 'dock'",
|
||||
"window_type = 'desktop'",
|
||||
"_GTK_FRAME_EXTENTS@:c"
|
||||
"_GTK_FRAME_EXTENTS@:c",
|
||||
"class_g = 'Chromium'",
|
||||
"class_g = 'Discord'",
|
||||
"class_g = 'Dunst'",
|
||||
"class_g = 'Peek'",
|
||||
"class_g *?= 'slop'",
|
||||
];
|
||||
|
||||
#################################
|
||||
# General Settings #
|
||||
#################################
|
||||
|
||||
# Enable remote control via D-Bus. See the man page for more details.
|
||||
# dbus = true
|
||||
|
||||
# Daemonize process. Fork to background after initialization. Causes issues with certain (badly-written) drivers.
|
||||
# daemon = false
|
||||
|
||||
# Specify the backend to use: `xrender`, `glx`, `egl` or `xr_glx_hybrid`.
|
||||
# `xrender` is the default one.
|
||||
#
|
||||
# backend = "glx"
|
||||
backend = "xrender";
|
||||
backend = "glx"
|
||||
|
||||
# Use higher precision during rendering, and apply dither when presenting the
|
||||
# rendered screen. Reduces banding artifacts, but might cause performance
|
||||
@@ -222,8 +231,7 @@ backend = "xrender";
|
||||
dithered-present = false;
|
||||
|
||||
# Enable/disable VSync.
|
||||
# vsync = false
|
||||
vsync = true;
|
||||
# vsync = true
|
||||
|
||||
# Try to detect WM windows (a non-override-redirect window with no
|
||||
# child that has 'WM_STATE') and mark them as active.
|
||||
@@ -239,25 +247,25 @@ mark-ovredir-focused = true;
|
||||
# shaped windows. The accuracy is not very high, unfortunately.
|
||||
#
|
||||
# detect-rounded-corners = false
|
||||
detect-rounded-corners = true;
|
||||
detect-rounded-corners = false;
|
||||
|
||||
# Detect '_NET_WM_WINDOW_OPACITY' on client windows, useful for window managers
|
||||
# not passing '_NET_WM_WINDOW_OPACITY' of client windows to frame windows.
|
||||
#
|
||||
# detect-client-opacity = false
|
||||
detect-client-opacity = true;
|
||||
detect-client-opacity = false;
|
||||
|
||||
# Use EWMH '_NET_ACTIVE_WINDOW' to determine currently focused window,
|
||||
# rather than listening to 'FocusIn'/'FocusOut' event. Might have more accuracy,
|
||||
# provided that the WM supports it.
|
||||
#
|
||||
# use-ewmh-active-win = false
|
||||
use-ewmh-active-win = true;
|
||||
|
||||
# Unredirect all windows if a full-screen opaque window is detected,
|
||||
# to maximize performance for full-screen windows. Known to cause flickering
|
||||
# when redirecting/unredirecting windows.
|
||||
#
|
||||
# unredir-if-possible = false
|
||||
unredir-if-possible = false;
|
||||
|
||||
# Delay before unredirecting the window, in milliseconds. Defaults to 0.
|
||||
# unredir-if-possible-delay = 0
|
||||
@@ -301,7 +309,7 @@ detect-transient = true;
|
||||
# practically happened) and may not work with blur-background.
|
||||
# My tests show a 15% performance boost. Recommended.
|
||||
#
|
||||
# glx-no-stencil = false
|
||||
glx-no-stencil = true;
|
||||
|
||||
# GLX backend: Avoid rebinding pixmap on window damage.
|
||||
# Probably could improve performance on rapid window content changes,
|
||||
@@ -322,24 +330,18 @@ use-damage = true;
|
||||
# calls are finished before picom starts drawing. Needed on nvidia-drivers
|
||||
# with GLX backend for some users.
|
||||
#
|
||||
# xrender-sync-fence = false
|
||||
xrender-sync-fence = true;
|
||||
|
||||
# GLX backend: Use specified GLSL fragment shader for rendering window
|
||||
# contents. Read the man page for a detailed explanation of the interface.
|
||||
# GLX backend: Use specified GLSL fragment shader for rendering window contents.
|
||||
# See `compton-default-fshader-win.glsl` and `compton-fake-transparency-fshader-win.glsl`
|
||||
# in the source tree for examples.
|
||||
#
|
||||
# window-shader-fg = "default"
|
||||
|
||||
# Use rules to set per-window shaders. Syntax is SHADER_PATH:PATTERN, similar
|
||||
# to opacity-rule. SHADER_PATH can be "default". This overrides window-shader-fg.
|
||||
#
|
||||
# window-shader-fg-rule = [
|
||||
# "my_shader.frag:window_type != 'dock'"
|
||||
# ]
|
||||
window-shader-fg = "default";
|
||||
|
||||
# Force all windows to be painted with blending. Useful if you
|
||||
# have a glx-fshader-win that could turn opaque pixels transparent.
|
||||
#
|
||||
# force-win-blend = false
|
||||
# force-win-blend = true;
|
||||
|
||||
# Do not use EWMH to detect fullscreen windows.
|
||||
# Reverts to checking if a window is fullscreen based only on its size and coordinates.
|
||||
@@ -356,7 +358,7 @@ use-damage = true;
|
||||
# Make transparent windows clip other windows like non-transparent windows do,
|
||||
# instead of blending on top of them.
|
||||
#
|
||||
# transparent-clipping = false
|
||||
transparent-clipping = false;
|
||||
|
||||
# Specify a list of conditions of windows that should never have transparent
|
||||
# clipping applied. Useful for screenshot tools, where you need to be able to
|
||||
@@ -429,3 +431,9 @@ wintypes:
|
||||
popup_menu = { opacity = 0.8; }
|
||||
dropdown_menu = { opacity = 0.8; }
|
||||
};
|
||||
|
||||
opacity-rule = [
|
||||
"100:class_g = 'St' && focused",
|
||||
"50:class_g = 'St' && !focused",
|
||||
"100:fullscreen",
|
||||
];
|
||||
|
||||
50
src/atom.c
50
src/atom.c
@@ -2,12 +2,20 @@
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "atom.h"
|
||||
#include "cache.h"
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
#include "compiler.h"
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
|
||||
static inline void *atom_getter(void *ud, const char *atom_name, int *err) {
|
||||
xcb_connection_t *c = ud;
|
||||
struct atom_entry {
|
||||
struct cache_handle entry;
|
||||
xcb_atom_t atom;
|
||||
};
|
||||
|
||||
static inline int atom_getter(struct cache *cache attr_unused, const char *atom_name,
|
||||
struct cache_handle **value, void *user_data) {
|
||||
xcb_connection_t *c = user_data;
|
||||
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(
|
||||
c, xcb_intern_atom(c, 0, to_u16_checked(strlen(atom_name)), atom_name), NULL);
|
||||
|
||||
@@ -18,9 +26,32 @@ static inline void *atom_getter(void *ud, const char *atom_name, int *err) {
|
||||
free(reply);
|
||||
} else {
|
||||
log_error("Failed to intern atoms");
|
||||
*err = 1;
|
||||
return -1;
|
||||
}
|
||||
return (void *)(intptr_t)atom;
|
||||
|
||||
struct atom_entry *entry = ccalloc(1, struct atom_entry);
|
||||
entry->atom = atom;
|
||||
*value = &entry->entry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
atom_entry_free(struct cache *cache attr_unused, struct cache_handle *handle) {
|
||||
struct atom_entry *entry = cache_entry(handle, struct atom_entry, entry);
|
||||
free(entry);
|
||||
}
|
||||
|
||||
xcb_atom_t get_atom(struct atom *a, const char *key, xcb_connection_t *c) {
|
||||
struct cache_handle *entry = NULL;
|
||||
if (cache_get_or_fetch(&a->c, key, &entry, c, atom_getter) < 0) {
|
||||
log_error("Failed to get atom %s", key);
|
||||
return XCB_NONE;
|
||||
}
|
||||
return cache_entry(entry, struct atom_entry, entry)->atom;
|
||||
}
|
||||
|
||||
xcb_atom_t get_atom_cached(struct atom *a, const char *key) {
|
||||
return cache_entry(cache_get(&a->c, key), struct atom_entry, entry)->atom;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,10 +59,15 @@ static inline void *atom_getter(void *ud, const char *atom_name, int *err) {
|
||||
*/
|
||||
struct atom *init_atoms(xcb_connection_t *c) {
|
||||
auto atoms = ccalloc(1, struct atom);
|
||||
atoms->c = new_cache((void *)c, atom_getter, NULL);
|
||||
#define ATOM_GET(x) atoms->a##x = (xcb_atom_t)(intptr_t)cache_get(atoms->c, #x, NULL)
|
||||
atoms->c = CACHE_INIT;
|
||||
#define ATOM_GET(x) atoms->a##x = get_atom(atoms, #x, c)
|
||||
LIST_APPLY(ATOM_GET, SEP_COLON, ATOM_LIST1);
|
||||
LIST_APPLY(ATOM_GET, SEP_COLON, ATOM_LIST2);
|
||||
#undef ATOM_GET
|
||||
return atoms;
|
||||
}
|
||||
|
||||
void destroy_atoms(struct atom *a) {
|
||||
cache_invalidate_all(&a->c, atom_entry_free);
|
||||
free(a);
|
||||
}
|
||||
|
||||
20
src/atom.h
20
src/atom.h
@@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "cache.h"
|
||||
@@ -23,6 +21,7 @@
|
||||
WM_CLIENT_MACHINE, \
|
||||
_NET_ACTIVE_WINDOW, \
|
||||
_COMPTON_SHADOW, \
|
||||
COMPTON_VERSION, \
|
||||
_NET_WM_WINDOW_TYPE, \
|
||||
_XROOTPMAP_ID, \
|
||||
ESETROOT_PMAP_ID, \
|
||||
@@ -52,19 +51,18 @@
|
||||
|
||||
#define ATOM_DEF(x) xcb_atom_t a##x
|
||||
|
||||
struct atom_entry;
|
||||
struct atom {
|
||||
struct cache *c;
|
||||
struct cache c;
|
||||
LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST1);
|
||||
LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST2);
|
||||
};
|
||||
|
||||
struct atom *init_atoms(xcb_connection_t *);
|
||||
/// Create a new atom object with a xcb connection. `struct atom` does not hold
|
||||
/// a reference to the connection.
|
||||
struct atom *init_atoms(xcb_connection_t *c);
|
||||
|
||||
static inline xcb_atom_t get_atom(struct atom *a, const char *key) {
|
||||
return (xcb_atom_t)(intptr_t)cache_get(a->c, key, NULL);
|
||||
}
|
||||
xcb_atom_t get_atom(struct atom *a, const char *key, xcb_connection_t *c);
|
||||
xcb_atom_t get_atom_cached(struct atom *a, const char *key);
|
||||
|
||||
static inline void destroy_atoms(struct atom *a) {
|
||||
cache_free(a->c);
|
||||
free(a);
|
||||
}
|
||||
void destroy_atoms(struct atom *a);
|
||||
|
||||
@@ -56,6 +56,58 @@ region_t get_damage(session_t *ps, bool all_damage) {
|
||||
return region;
|
||||
}
|
||||
|
||||
static void process_window_for_painting(session_t *ps, struct managed_win *w,
|
||||
void *win_image, double additional_alpha,
|
||||
region_t *reg_bound, region_t *reg_visible,
|
||||
region_t *reg_paint, region_t *reg_paint_in_bound) {
|
||||
// For window image processing, we don't have to limit the process
|
||||
// region to damage for correctness. (see <damager-note> for
|
||||
// details)
|
||||
|
||||
// The visible region, in window local coordinates Although we
|
||||
// don't limit process region to damage, we provide that info in
|
||||
// reg_visible as a hint. Since window image data outside of the
|
||||
// damage region won't be painted onto target
|
||||
coord_t window_coord = {.x = w->g.x, .y = w->g.y};
|
||||
coord_t dest_coord = {.x = w->g.x + w->widthb, .y = w->g.y + w->heightb};
|
||||
|
||||
region_t reg_visible_local;
|
||||
region_t reg_bound_local;
|
||||
{
|
||||
// The bounding shape, in window local coordinates
|
||||
pixman_region32_init(®_bound_local);
|
||||
pixman_region32_copy(®_bound_local, reg_bound);
|
||||
pixman_region32_translate(®_bound_local, -w->g.x, -w->g.y);
|
||||
|
||||
pixman_region32_init(®_visible_local);
|
||||
pixman_region32_intersect(®_visible_local, reg_visible, reg_paint);
|
||||
pixman_region32_translate(®_visible_local, -w->g.x, -w->g.y);
|
||||
// Data outside of the bounding shape won't be visible,
|
||||
// but it is not necessary to limit the image operations
|
||||
// to the bounding shape yet. So pass that as the visible
|
||||
// region, not the clip region.
|
||||
pixman_region32_intersect(®_visible_local, ®_visible_local,
|
||||
®_bound_local);
|
||||
}
|
||||
|
||||
auto new_img = ps->backend_data->ops->clone_image(ps->backend_data, win_image,
|
||||
®_visible_local);
|
||||
auto reg_frame = win_get_region_frame_local_by_val(w);
|
||||
double alpha = additional_alpha * w->opacity;
|
||||
ps->backend_data->ops->set_image_property(
|
||||
ps->backend_data, IMAGE_PROPERTY_OPACITY, new_img, &alpha);
|
||||
ps->backend_data->ops->image_op(ps->backend_data, IMAGE_OP_APPLY_ALPHA, new_img,
|
||||
®_frame, ®_visible_local,
|
||||
(double[]){w->frame_opacity});
|
||||
pixman_region32_fini(®_frame);
|
||||
ps->backend_data->ops->compose(ps->backend_data, new_img,
|
||||
window_coord, NULL, dest_coord,
|
||||
reg_paint_in_bound, reg_visible, true);
|
||||
ps->backend_data->ops->release_image(ps->backend_data, new_img);
|
||||
pixman_region32_fini(®_visible_local);
|
||||
pixman_region32_fini(®_bound_local);
|
||||
}
|
||||
|
||||
void handle_device_reset(session_t *ps) {
|
||||
log_error("Device reset detected");
|
||||
// Wait for reset to complete
|
||||
@@ -82,13 +134,17 @@ void handle_device_reset(session_t *ps) {
|
||||
}
|
||||
|
||||
/// paint all windows
|
||||
void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
///
|
||||
/// Returns if any render command is issued. IOW if nothing on the screen has changed,
|
||||
/// this function will return false.
|
||||
bool paint_all_new(session_t *ps, struct managed_win *const t) {
|
||||
struct timespec now = get_time_timespec();
|
||||
auto paint_all_start_us =
|
||||
(uint64_t)now.tv_sec * 1000000UL + (uint64_t)now.tv_nsec / 1000;
|
||||
if (ps->backend_data->ops->device_status &&
|
||||
ps->backend_data->ops->device_status(ps->backend_data) != DEVICE_STATUS_NORMAL) {
|
||||
return handle_device_reset(ps);
|
||||
handle_device_reset(ps);
|
||||
return false;
|
||||
}
|
||||
if (ps->o.xrender_sync_fence) {
|
||||
if (ps->xsync_exists && !x_fence_sync(&ps->c, ps->sync_fence)) {
|
||||
@@ -114,7 +170,7 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
|
||||
if (!pixman_region32_not_empty(®_damage)) {
|
||||
pixman_region32_fini(®_damage);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_REPAINT
|
||||
@@ -190,16 +246,15 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
auto after_damage_us = (uint64_t)now.tv_sec * 1000000UL + (uint64_t)now.tv_nsec / 1000;
|
||||
log_trace("Getting damage took %" PRIu64 " us", after_damage_us - after_sync_fence_us);
|
||||
if (ps->next_render > 0) {
|
||||
log_trace("Render schedule deviation: %ld us (%s) %" PRIu64 " %ld",
|
||||
labs((long)after_damage_us - (long)ps->next_render),
|
||||
after_damage_us < ps->next_render ? "early" : "late",
|
||||
after_damage_us, ps->next_render);
|
||||
log_verbose("Render schedule deviation: %ld us (%s) %" PRIu64 " %" PRIu64,
|
||||
labs((long)after_damage_us - (long)ps->next_render),
|
||||
after_damage_us < ps->next_render ? "early" : "late",
|
||||
after_damage_us, ps->next_render);
|
||||
ps->last_schedule_delay = 0;
|
||||
if (after_damage_us > ps->next_render) {
|
||||
ps->last_schedule_delay = after_damage_us - ps->next_render;
|
||||
}
|
||||
}
|
||||
ps->did_render = true;
|
||||
|
||||
if (ps->backend_data->ops->prepare) {
|
||||
ps->backend_data->ops->prepare(ps->backend_data, ®_paint);
|
||||
@@ -207,8 +262,8 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
|
||||
if (ps->root_image) {
|
||||
ps->backend_data->ops->compose(ps->backend_data, ps->root_image,
|
||||
(coord_t){0}, NULL, (coord_t){0},
|
||||
®_paint, ®_visible);
|
||||
(coord_t){0}, NULL, (coord_t){.x = ps->root_width, .y = ps->root_height},
|
||||
®_paint, ®_visible, true);
|
||||
} else {
|
||||
ps->backend_data->ops->fill(ps->backend_data, (struct color){0, 0, 0, 1},
|
||||
®_paint);
|
||||
@@ -219,7 +274,7 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
// on top of that window. This is used to reduce the number of pixels painted.
|
||||
//
|
||||
// Whether this is beneficial is to be determined XXX
|
||||
for (auto w = t; w; w = w->prev_trans) {
|
||||
for (struct managed_win *w = t; w; w = w->prev_trans) {
|
||||
pixman_region32_subtract(®_visible, &ps->screen_reg, w->reg_ignore);
|
||||
assert(!(w->flags & WIN_FLAGS_IMAGE_ERROR));
|
||||
assert(!(w->flags & WIN_FLAGS_PIXMAP_STALE));
|
||||
@@ -259,6 +314,7 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
* option */
|
||||
auto real_win_mode = w->mode;
|
||||
coord_t window_coord = {.x = w->g.x, .y = w->g.y};
|
||||
coord_t dest_coord = {.x = w->g.x + w->widthb, .y = w->g.y + w->heightb};
|
||||
|
||||
if (w->blur_background &&
|
||||
(ps->o.force_win_blend || real_win_mode == WMODE_TRANS ||
|
||||
@@ -387,7 +443,7 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
}
|
||||
ps->backend_data->ops->compose(
|
||||
ps->backend_data, w->shadow_image, shadow_coord,
|
||||
inverted_mask, window_coord, ®_shadow, ®_visible);
|
||||
inverted_mask, window_coord, ®_shadow, ®_visible, false);
|
||||
if (inverted_mask) {
|
||||
ps->backend_data->ops->set_image_property(
|
||||
ps->backend_data, IMAGE_PROPERTY_INVERTED,
|
||||
@@ -431,6 +487,17 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
ps->backend_data->ops->set_image_property(
|
||||
ps->backend_data, IMAGE_PROPERTY_BORDER_WIDTH,
|
||||
w->win_image, &border_width);
|
||||
if (w->old_win_image) {
|
||||
// TODO(dccsillag): explain why the following is
|
||||
// "necessary"
|
||||
double zero = 0.0;
|
||||
ps->backend_data->ops->set_image_property(
|
||||
ps->backend_data, IMAGE_PROPERTY_BORDER_WIDTH,
|
||||
w->old_win_image, &zero);
|
||||
ps->backend_data->ops->set_image_property(
|
||||
ps->backend_data, IMAGE_PROPERTY_CORNER_RADIUS,
|
||||
w->old_win_image, &zero);
|
||||
}
|
||||
}
|
||||
|
||||
ps->backend_data->ops->set_image_property(
|
||||
@@ -453,53 +520,43 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
}
|
||||
|
||||
// Draw window on target
|
||||
if (w->frame_opacity == 1) {
|
||||
bool is_animating = 0 <= w->animation_progress && w->animation_progress < 1.0;
|
||||
if (w->frame_opacity == 1 && !is_animating) {
|
||||
ps->backend_data->ops->compose(ps->backend_data, w->win_image,
|
||||
window_coord, NULL, window_coord,
|
||||
®_paint_in_bound, ®_visible);
|
||||
window_coord, NULL, dest_coord,
|
||||
®_paint_in_bound, ®_visible, true);
|
||||
} else {
|
||||
// For window image processing, we don't have to limit the process
|
||||
// region to damage for correctness. (see <damager-note> for
|
||||
// details)
|
||||
if (is_animating && w->old_win_image) {
|
||||
bool is_focused = win_is_focused_raw(w);
|
||||
if (!is_focused && w->focused && w->opacity_is_set)
|
||||
is_focused = true;
|
||||
assert(w->old_win_image);
|
||||
|
||||
// The visible region, in window local coordinates Although we
|
||||
// don't limit process region to damage, we provide that info in
|
||||
// reg_visible as a hint. Since window image data outside of the
|
||||
// damage region won't be painted onto target
|
||||
region_t reg_visible_local;
|
||||
region_t reg_bound_local;
|
||||
{
|
||||
// The bounding shape, in window local coordinates
|
||||
pixman_region32_init(®_bound_local);
|
||||
pixman_region32_copy(®_bound_local, ®_bound);
|
||||
pixman_region32_translate(®_bound_local, -w->g.x, -w->g.y);
|
||||
bool resizing =
|
||||
w->g.width != w->pending_g.width ||
|
||||
w->g.height != w->pending_g.height;
|
||||
|
||||
pixman_region32_init(®_visible_local);
|
||||
pixman_region32_intersect(®_visible_local,
|
||||
®_visible, ®_paint);
|
||||
pixman_region32_translate(®_visible_local, -w->g.x,
|
||||
-w->g.y);
|
||||
// Data outside of the bounding shape won't be visible,
|
||||
// but it is not necessary to limit the image operations
|
||||
// to the bounding shape yet. So pass that as the visible
|
||||
// region, not the clip region.
|
||||
pixman_region32_intersect(
|
||||
®_visible_local, ®_visible_local, ®_bound_local);
|
||||
// Only animate opacity here if we are resizing
|
||||
// a transparent window
|
||||
process_window_for_painting(ps, w, w->win_image,
|
||||
is_focused ? 1.0 : w->opacity >= 1 ? 1.0 : w->animation_progress,
|
||||
®_bound, ®_visible,
|
||||
®_paint, ®_paint_in_bound);
|
||||
|
||||
// Only do this if size changes as otherwise moving
|
||||
// transparent windows will flicker and if you just
|
||||
// move so slightly they will keep flickering
|
||||
if (resizing && (!is_focused || !w->opacity_is_set)) {
|
||||
process_window_for_painting(ps, w, w->old_win_image,
|
||||
1.0 - w->animation_progress,
|
||||
®_bound, ®_visible,
|
||||
®_paint, ®_paint_in_bound);
|
||||
}
|
||||
} else {
|
||||
process_window_for_painting(
|
||||
ps, w, w->win_image, 1.0, ®_bound, ®_visible,
|
||||
®_paint, ®_paint_in_bound);
|
||||
}
|
||||
|
||||
auto new_img = ps->backend_data->ops->clone_image(
|
||||
ps->backend_data, w->win_image, ®_visible_local);
|
||||
auto reg_frame = win_get_region_frame_local_by_val(w);
|
||||
ps->backend_data->ops->image_op(
|
||||
ps->backend_data, IMAGE_OP_APPLY_ALPHA, new_img, ®_frame,
|
||||
®_visible_local, (double[]){w->frame_opacity});
|
||||
pixman_region32_fini(®_frame);
|
||||
ps->backend_data->ops->compose(ps->backend_data, new_img,
|
||||
window_coord, NULL, window_coord,
|
||||
®_paint_in_bound, ®_visible);
|
||||
ps->backend_data->ops->release_image(ps->backend_data, new_img);
|
||||
pixman_region32_fini(®_visible_local);
|
||||
pixman_region32_fini(®_bound_local);
|
||||
}
|
||||
skip:
|
||||
pixman_region32_fini(®_bound);
|
||||
@@ -541,6 +598,7 @@ void paint_all_new(session_t *ps, struct managed_win *t) {
|
||||
for (win *w = t; w; w = w->prev_trans)
|
||||
log_trace(" %#010lx", w->id);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// vim: set noet sw=8 ts=8 :
|
||||
|
||||
@@ -115,6 +115,10 @@ struct dual_kawase_blur_args {
|
||||
int strength;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
// Intentionally left blank
|
||||
} *image_handle;
|
||||
|
||||
struct backend_operations {
|
||||
// =========== Initialization ===========
|
||||
|
||||
@@ -167,26 +171,27 @@ struct backend_operations {
|
||||
* Paint the content of an image onto the rendering buffer.
|
||||
*
|
||||
* @param backend_data the backend data
|
||||
* @param image_data the image to paint
|
||||
* @param image the image to paint, cannot be NULL
|
||||
* @param dst_x, dst_y the top left corner of the image in the target
|
||||
* @param mask the mask image, the top left of the mask is aligned with
|
||||
* the top left of the image
|
||||
* the top left of the image. Optional, can be
|
||||
* NULL.
|
||||
* @param reg_paint the clip region, in target coordinates
|
||||
* @param reg_visible the visible region, in target coordinates
|
||||
*/
|
||||
void (*compose)(backend_t *backend_data, void *image_data, coord_t image_dst,
|
||||
void *mask, coord_t mask_dst, const region_t *reg_paint,
|
||||
const region_t *reg_visible);
|
||||
void (*compose)(backend_t *backend_data, image_handle image, coord_t image_dst,
|
||||
image_handle mask, coord_t mask_dst, const region_t *reg_paint,
|
||||
const region_t *reg_visible, bool lerp) attr_nonnull(1, 2, 6, 7);
|
||||
|
||||
/// Fill rectangle of the rendering buffer, mostly for debug purposes, optional.
|
||||
void (*fill)(backend_t *backend_data, struct color, const region_t *clip);
|
||||
|
||||
/// Blur a given region of the rendering buffer.
|
||||
///
|
||||
/// The blur is limited by `mask`. `mask_dst` specifies the top left corner of the
|
||||
/// mask is.
|
||||
bool (*blur)(backend_t *backend_data, double opacity, void *blur_ctx, void *mask,
|
||||
coord_t mask_dst, const region_t *reg_blur,
|
||||
/// The blur can be limited by `mask`. `mask_dst` specifies the top left corner of
|
||||
/// the mask. `mask` can be NULL.
|
||||
bool (*blur)(backend_t *backend_data, double opacity, void *blur_ctx,
|
||||
image_handle mask, coord_t mask_dst, const region_t *reg_blur,
|
||||
const region_t *reg_visible) attr_nonnull(1, 3, 6, 7);
|
||||
|
||||
/// Update part of the back buffer with the rendering buffer, then present the
|
||||
@@ -202,13 +207,15 @@ struct backend_operations {
|
||||
* Bind a X pixmap to the backend's internal image data structure.
|
||||
*
|
||||
* @param backend_data backend data
|
||||
* @param pixmap X pixmap to bind
|
||||
* @param fmt information of the pixmap's visual
|
||||
* @param owned whether the ownership of the pixmap is transfered to the backend
|
||||
* @return backend internal data structure bound with this pixmap
|
||||
* @param pixmap X pixmap to bind
|
||||
* @param fmt information of the pixmap's visual
|
||||
* @param owned whether the ownership of the pixmap is transferred to the
|
||||
* backend.
|
||||
* @return backend specific image handle for the pixmap. May be
|
||||
* NULL.
|
||||
*/
|
||||
void *(*bind_pixmap)(backend_t *backend_data, xcb_pixmap_t pixmap,
|
||||
struct xvisual_info fmt, bool owned);
|
||||
image_handle (*bind_pixmap)(backend_t *backend_data, xcb_pixmap_t pixmap,
|
||||
struct xvisual_info fmt, bool owned);
|
||||
|
||||
/// Create a shadow context for rendering shadows with radius `radius`.
|
||||
/// Default implementation: default_create_shadow_context
|
||||
@@ -220,21 +227,27 @@ struct backend_operations {
|
||||
struct backend_shadow_context *ctx);
|
||||
|
||||
/// Create a shadow image based on the parameters. Resulting image should have a
|
||||
/// size of `width + radisu * 2` x `height + radius * 2`. Radius is set when the
|
||||
/// size of `width + radius * 2` x `height + radius * 2`. Radius is set when the
|
||||
/// shadow context is created.
|
||||
/// Default implementation: default_render_shadow
|
||||
///
|
||||
/// @return the shadow image, may be NULL.
|
||||
///
|
||||
/// Required.
|
||||
void *(*render_shadow)(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *ctx, struct color color);
|
||||
image_handle (*render_shadow)(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *ctx, struct color color);
|
||||
|
||||
/// Create a shadow by blurring a mask. `size` is the size of the blur. The
|
||||
/// backend can use whichever blur method is the fastest. The shadow produced
|
||||
/// shoule be consistent with `render_shadow`.
|
||||
///
|
||||
/// @param mask the input mask, must not be NULL.
|
||||
/// @return the shadow image, may be NULL.
|
||||
///
|
||||
/// Optional.
|
||||
void *(*shadow_from_mask)(backend_t *backend_data, void *mask,
|
||||
struct backend_shadow_context *ctx, struct color color);
|
||||
image_handle (*shadow_from_mask)(backend_t *backend_data, image_handle mask,
|
||||
struct backend_shadow_context *ctx,
|
||||
struct color color);
|
||||
|
||||
/// Create a mask image from region `reg`. This region can be used to create
|
||||
/// shadow, or used as a mask for composing. When used as a mask, it should mask
|
||||
@@ -245,13 +258,18 @@ struct backend_operations {
|
||||
/// and outside of the mask. Corner radius should exclude the corners from the
|
||||
/// mask. Corner radius should be applied before the inversion.
|
||||
///
|
||||
/// @return the mask image, may be NULL.
|
||||
///
|
||||
/// Required.
|
||||
void *(*make_mask)(backend_t *backend_data, geometry_t size, const region_t *reg);
|
||||
image_handle (*make_mask)(backend_t *backend_data, geometry_t size,
|
||||
const region_t *reg);
|
||||
|
||||
// ============ Resource management ===========
|
||||
|
||||
/// Free resources associated with an image data structure
|
||||
void (*release_image)(backend_t *backend_data, void *img_data) attr_nonnull(1, 2);
|
||||
///
|
||||
/// @param image the image to be released, cannot be NULL.
|
||||
void (*release_image)(backend_t *backend_data, image_handle image) attr_nonnull(1, 2);
|
||||
|
||||
/// Create a shader object from a shader source.
|
||||
///
|
||||
@@ -276,12 +294,14 @@ struct backend_operations {
|
||||
/// This function is needed because some backend might change the content of the
|
||||
/// window (e.g. when using a custom shader with the glx backend), so only the
|
||||
/// backend knows if an image is transparent.
|
||||
bool (*is_image_transparent)(backend_t *backend_data, void *image_data)
|
||||
///
|
||||
/// @param image the image to be checked, must not be NULL.
|
||||
bool (*is_image_transparent)(backend_t *backend_data, image_handle image)
|
||||
attr_nonnull(1, 2);
|
||||
|
||||
/// Get the age of the buffer content we are currently rendering ontop
|
||||
/// Get the age of the buffer content we are currently rendering on top
|
||||
/// of. The buffer that has just been `present`ed has a buffer age of 1.
|
||||
/// Everytime `present` is called, buffers get older. Return -1 if the
|
||||
/// Every time `present` is called, buffers get older. Return -1 if the
|
||||
/// buffer is empty.
|
||||
///
|
||||
/// Optional
|
||||
@@ -290,7 +310,7 @@ struct backend_operations {
|
||||
/// Get the render time of the last frame. If the render is still in progress,
|
||||
/// returns false. The time is returned in `ts`. Frames are delimited by the
|
||||
/// present() calls. i.e. after a present() call, last_render_time() should start
|
||||
/// reporting the time of the just presen1ted frame.
|
||||
/// reporting the time of the just presented frame.
|
||||
///
|
||||
/// Optional, if not available, the most conservative estimation will be used.
|
||||
bool (*last_render_time)(backend_t *backend_data, struct timespec *ts);
|
||||
@@ -311,35 +331,39 @@ struct backend_operations {
|
||||
*
|
||||
* @param backend_data backend data
|
||||
* @param prop the property to change
|
||||
* @param image_data an image data structure returned by the backend
|
||||
* @param image an image handle, cannot be NULL.
|
||||
* @param args property value
|
||||
* @return whether the operation is successful
|
||||
* @return whether the operation is successful
|
||||
*/
|
||||
bool (*set_image_property)(backend_t *backend_data, enum image_properties prop,
|
||||
void *image_data, void *args);
|
||||
image_handle image, void *args) attr_nonnull(1, 3);
|
||||
|
||||
/**
|
||||
* Manipulate an image. Image properties are untouched.
|
||||
*
|
||||
* @param backend_data backend data
|
||||
* @param op the operation to perform
|
||||
* @param image_data an image data structure returned by the backend
|
||||
* @param image an image handle, cannot be NULL.
|
||||
* @param reg_op the clip region, define the part of the image to be
|
||||
* operated on.
|
||||
* @param reg_visible define the part of the image that will eventually
|
||||
* be visible on target. this is a hint to the backend
|
||||
* for optimization purposes.
|
||||
* @param args extra arguments, operation specific
|
||||
* @return whether the operation is successful
|
||||
* @return whether the operation is successful
|
||||
*/
|
||||
bool (*image_op)(backend_t *backend_data, enum image_operations op, void *image_data,
|
||||
const region_t *reg_op, const region_t *reg_visible, void *args);
|
||||
bool (*image_op)(backend_t *backend_data, enum image_operations op,
|
||||
image_handle image, const region_t *reg_op,
|
||||
const region_t *reg_visible, void *args) attr_nonnull(1, 3, 4, 5);
|
||||
|
||||
/// Create another instance of the `image_data`. All `image_op` and
|
||||
/// `set_image_property` calls on the returned image should not affect the
|
||||
/// original image
|
||||
void *(*clone_image)(backend_t *base, const void *image_data,
|
||||
const region_t *reg_visible);
|
||||
/// Create another instance of the `image`. The newly created image
|
||||
/// inherits its content and all image properties from the image being
|
||||
/// cloned. All `image_op` and `set_image_property` calls on the
|
||||
/// returned image should not affect the original image.
|
||||
///
|
||||
/// @param image the image to be cloned, must not be NULL.
|
||||
image_handle (*clone_image)(backend_t *base, image_handle image,
|
||||
const region_t *reg_visible) attr_nonnull_all;
|
||||
|
||||
/// Create a blur context that can be used to call `blur`
|
||||
void *(*create_blur_context)(backend_t *base, enum blur_method, void *args);
|
||||
@@ -366,4 +390,8 @@ struct backend_operations {
|
||||
|
||||
extern struct backend_operations *backend_list[];
|
||||
|
||||
void paint_all_new(session_t *ps, struct managed_win *const t) attr_nonnull(1);
|
||||
/// paint all windows
|
||||
///
|
||||
/// Returns if any render command is issued. IOW if nothing on the screen has changed,
|
||||
/// this function will return false.
|
||||
bool paint_all_new(session_t *ps, struct managed_win *t) attr_nonnull(1);
|
||||
|
||||
@@ -293,8 +293,8 @@ shadow_picture_err:
|
||||
return false;
|
||||
}
|
||||
|
||||
void *default_render_shadow(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *sctx, struct color color) {
|
||||
image_handle default_render_shadow(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *sctx, struct color color) {
|
||||
const conv *kernel = (void *)sctx;
|
||||
xcb_render_picture_t shadow_pixel =
|
||||
solid_picture(backend_data->c, true, 1, color.red, color.green, color.blue);
|
||||
@@ -308,7 +308,7 @@ void *default_render_shadow(backend_t *backend_data, int width, int height,
|
||||
}
|
||||
|
||||
auto visual = x_get_visual_for_standard(backend_data->c, XCB_PICT_STANDARD_ARGB_32);
|
||||
void *ret = backend_data->ops->bind_pixmap(
|
||||
auto ret = backend_data->ops->bind_pixmap(
|
||||
backend_data, shadow, x_get_visual_info(backend_data->c, visual), true);
|
||||
x_free_picture(backend_data->c, pict);
|
||||
x_free_picture(backend_data->c, shadow_pixel);
|
||||
@@ -316,16 +316,16 @@ void *default_render_shadow(backend_t *backend_data, int width, int height,
|
||||
}
|
||||
|
||||
/// Implement render_shadow with shadow_from_mask
|
||||
void *
|
||||
image_handle
|
||||
backend_render_shadow_from_mask(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *sctx, struct color color) {
|
||||
region_t reg;
|
||||
pixman_region32_init_rect(®, 0, 0, (unsigned int)width, (unsigned int)height);
|
||||
void *mask = backend_data->ops->make_mask(
|
||||
auto mask = backend_data->ops->make_mask(
|
||||
backend_data, (geometry_t){.width = width, .height = height}, ®);
|
||||
pixman_region32_fini(®);
|
||||
|
||||
void *shadow = backend_data->ops->shadow_from_mask(backend_data, mask, sctx, color);
|
||||
auto shadow = backend_data->ops->shadow_from_mask(backend_data, mask, sctx, color);
|
||||
backend_data->ops->release_image(backend_data, mask);
|
||||
return shadow;
|
||||
}
|
||||
@@ -458,17 +458,17 @@ struct dual_kawase_params *generate_dual_kawase_params(void *args) {
|
||||
return params;
|
||||
}
|
||||
|
||||
void *default_clone_image(backend_t *base attr_unused, const void *image_data,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
image_handle default_clone_image(backend_t *base attr_unused, image_handle image,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
auto new_img = ccalloc(1, struct backend_image);
|
||||
*new_img = *(struct backend_image *)image_data;
|
||||
*new_img = *(struct backend_image *)image;
|
||||
new_img->inner->refcount++;
|
||||
return new_img;
|
||||
return (image_handle)new_img;
|
||||
}
|
||||
|
||||
bool default_set_image_property(backend_t *base attr_unused, enum image_properties op,
|
||||
void *image_data, void *arg) {
|
||||
struct backend_image *tex = image_data;
|
||||
image_handle image, void *arg) {
|
||||
auto tex = (struct backend_image *)image;
|
||||
int *iargs = arg;
|
||||
bool *bargs = arg;
|
||||
double *dargs = arg;
|
||||
@@ -490,8 +490,8 @@ bool default_set_image_property(backend_t *base attr_unused, enum image_properti
|
||||
return true;
|
||||
}
|
||||
|
||||
bool default_is_image_transparent(backend_t *base attr_unused, void *image_data) {
|
||||
struct backend_image *img = image_data;
|
||||
bool default_is_image_transparent(backend_t *base attr_unused, image_handle image) {
|
||||
auto img = (struct backend_image *)image;
|
||||
return img->opacity < 1 || img->inner->has_alpha;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,11 +54,11 @@ solid_picture(struct x_connection *, bool argb, double a, double r, double g, do
|
||||
xcb_image_t *make_shadow(struct x_connection *c, const conv *kernel, double opacity,
|
||||
int width, int height);
|
||||
|
||||
void *default_render_shadow(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *sctx, struct color color);
|
||||
image_handle default_render_shadow(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *sctx, struct color color);
|
||||
|
||||
/// Implement `render_shadow` with `shadow_from_mask`.
|
||||
void *
|
||||
image_handle
|
||||
backend_render_shadow_from_mask(backend_t *backend_data, int width, int height,
|
||||
struct backend_shadow_context *sctx, struct color color);
|
||||
struct backend_shadow_context *
|
||||
@@ -72,8 +72,8 @@ void init_backend_base(struct backend_base *base, session_t *ps);
|
||||
struct conv **generate_blur_kernel(enum blur_method method, void *args, int *kernel_count);
|
||||
struct dual_kawase_params *generate_dual_kawase_params(void *args);
|
||||
|
||||
void *default_clone_image(backend_t *base, const void *image_data, const region_t *reg);
|
||||
bool default_is_image_transparent(backend_t *base attr_unused, void *image_data);
|
||||
image_handle default_clone_image(backend_t *base, image_handle image, const region_t *reg);
|
||||
bool default_is_image_transparent(backend_t *base attr_unused, image_handle image);
|
||||
bool default_set_image_property(backend_t *base attr_unused, enum image_properties op,
|
||||
void *image_data, void *arg);
|
||||
image_handle image, void *arg);
|
||||
struct backend_image *default_new_backend_image(int w, int h);
|
||||
|
||||
@@ -19,6 +19,16 @@ void apply_driver_workarounds(struct session *ps, enum driver driver) {
|
||||
}
|
||||
}
|
||||
|
||||
enum vblank_scheduler_type choose_vblank_scheduler(enum driver driver attr_unused) {
|
||||
enum vblank_scheduler_type type = VBLANK_SCHEDULER_PRESENT;
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (driver & DRIVER_NVIDIA) {
|
||||
type = VBLANK_SCHEDULER_SGI_VIDEO_SYNC;
|
||||
}
|
||||
#endif
|
||||
return type;
|
||||
}
|
||||
|
||||
enum driver detect_driver(xcb_connection_t *c, backend_t *backend_data, xcb_window_t window) {
|
||||
enum driver ret = 0;
|
||||
// First we try doing backend agnostic detection using RANDR
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
|
||||
struct session;
|
||||
@@ -41,6 +42,8 @@ enum driver detect_driver(xcb_connection_t *, struct backend_base *, xcb_window_
|
||||
|
||||
/// Apply driver specified global workarounds. It's safe to call this multiple times.
|
||||
void apply_driver_workarounds(struct session *ps, enum driver);
|
||||
/// Choose a vblank scheduler based on the driver.
|
||||
enum vblank_scheduler_type choose_vblank_scheduler(enum driver driver);
|
||||
|
||||
// Print driver names to stdout, for diagnostics
|
||||
static inline void print_drivers(enum driver drivers) {
|
||||
|
||||
@@ -50,8 +50,9 @@ void dummy_deinit(struct backend_base *data) {
|
||||
free(dummy);
|
||||
}
|
||||
|
||||
static void dummy_check_image(struct backend_base *base, const struct dummy_image *img) {
|
||||
static void dummy_check_image(struct backend_base *base, image_handle image) {
|
||||
auto dummy = (struct dummy_data *)base;
|
||||
auto img = (struct dummy_image *)image;
|
||||
if (img == (struct dummy_image *)&dummy->mask) {
|
||||
return;
|
||||
}
|
||||
@@ -64,13 +65,13 @@ static void dummy_check_image(struct backend_base *base, const struct dummy_imag
|
||||
assert(*tmp->refcount > 0);
|
||||
}
|
||||
|
||||
void dummy_compose(struct backend_base *base, void *image, coord_t dst attr_unused,
|
||||
void *mask attr_unused, coord_t mask_dst attr_unused,
|
||||
void dummy_compose(struct backend_base *base, image_handle image, coord_t dst attr_unused,
|
||||
image_handle mask attr_unused, coord_t mask_dst attr_unused,
|
||||
const region_t *reg_paint attr_unused,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
const region_t *reg_visible attr_unused, bool lerp attr_unused) {
|
||||
auto dummy attr_unused = (struct dummy_data *)base;
|
||||
dummy_check_image(base, image);
|
||||
assert(mask == NULL || mask == &dummy->mask);
|
||||
assert(mask == NULL || (struct backend_image *)mask == &dummy->mask);
|
||||
}
|
||||
|
||||
void dummy_fill(struct backend_base *backend_data attr_unused, struct color c attr_unused,
|
||||
@@ -78,20 +79,20 @@ void dummy_fill(struct backend_base *backend_data attr_unused, struct color c at
|
||||
}
|
||||
|
||||
bool dummy_blur(struct backend_base *backend_data attr_unused, double opacity attr_unused,
|
||||
void *blur_ctx attr_unused, void *mask attr_unused,
|
||||
void *blur_ctx attr_unused, image_handle mask attr_unused,
|
||||
coord_t mask_dst attr_unused, const region_t *reg_blur attr_unused,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void *dummy_bind_pixmap(struct backend_base *base, xcb_pixmap_t pixmap,
|
||||
struct xvisual_info fmt, bool owned) {
|
||||
image_handle dummy_bind_pixmap(struct backend_base *base, xcb_pixmap_t pixmap,
|
||||
struct xvisual_info fmt, bool owned) {
|
||||
auto dummy = (struct dummy_data *)base;
|
||||
struct dummy_image *img = NULL;
|
||||
HASH_FIND_INT(dummy->images, &pixmap, img);
|
||||
if (img) {
|
||||
(*img->refcount)++;
|
||||
return img;
|
||||
return (image_handle)img;
|
||||
}
|
||||
|
||||
img = ccalloc(1, struct dummy_image);
|
||||
@@ -102,12 +103,12 @@ void *dummy_bind_pixmap(struct backend_base *base, xcb_pixmap_t pixmap,
|
||||
img->owned = owned;
|
||||
|
||||
HASH_ADD_INT(dummy->images, pixmap, img);
|
||||
return (void *)img;
|
||||
return (image_handle)img;
|
||||
}
|
||||
|
||||
void dummy_release_image(backend_t *base, void *image) {
|
||||
void dummy_release_image(backend_t *base, image_handle image) {
|
||||
auto dummy = (struct dummy_data *)base;
|
||||
if (image == &dummy->mask) {
|
||||
if ((struct backend_image *)image == &dummy->mask) {
|
||||
return;
|
||||
}
|
||||
auto img = (struct dummy_image *)image;
|
||||
@@ -123,10 +124,9 @@ void dummy_release_image(backend_t *base, void *image) {
|
||||
}
|
||||
}
|
||||
|
||||
bool dummy_is_image_transparent(struct backend_base *base, void *image) {
|
||||
auto img = (struct dummy_image *)image;
|
||||
dummy_check_image(base, img);
|
||||
return img->transparent;
|
||||
bool dummy_is_image_transparent(struct backend_base *base, image_handle image) {
|
||||
dummy_check_image(base, image);
|
||||
return ((struct dummy_image *)image)->transparent;
|
||||
}
|
||||
|
||||
int dummy_buffer_age(struct backend_base *base attr_unused) {
|
||||
@@ -134,29 +134,31 @@ int dummy_buffer_age(struct backend_base *base attr_unused) {
|
||||
}
|
||||
|
||||
bool dummy_image_op(struct backend_base *base, enum image_operations op attr_unused,
|
||||
void *image, const region_t *reg_op attr_unused,
|
||||
image_handle image, const region_t *reg_op attr_unused,
|
||||
const region_t *reg_visible attr_unused, void *args attr_unused) {
|
||||
dummy_check_image(base, image);
|
||||
return true;
|
||||
}
|
||||
|
||||
void *dummy_make_mask(struct backend_base *base, geometry_t size attr_unused,
|
||||
const region_t *reg attr_unused) {
|
||||
return &(((struct dummy_data *)base)->mask);
|
||||
image_handle dummy_make_mask(struct backend_base *base, geometry_t size attr_unused,
|
||||
const region_t *reg attr_unused) {
|
||||
auto dummy = (struct dummy_data *)base;
|
||||
auto mask = &dummy->mask;
|
||||
return (image_handle)mask;
|
||||
}
|
||||
|
||||
bool dummy_set_image_property(struct backend_base *base, enum image_properties prop attr_unused,
|
||||
void *image, void *arg attr_unused) {
|
||||
image_handle image, void *arg attr_unused) {
|
||||
dummy_check_image(base, image);
|
||||
return true;
|
||||
}
|
||||
|
||||
void *dummy_clone_image(struct backend_base *base, const void *image,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
auto img = (const struct dummy_image *)image;
|
||||
dummy_check_image(base, img);
|
||||
(*img->refcount)++;
|
||||
return (void *)img;
|
||||
image_handle dummy_clone_image(struct backend_base *base, image_handle image,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
dummy_check_image(base, image);
|
||||
auto image_impl = (struct dummy_image *)image;
|
||||
(*image_impl->refcount)++;
|
||||
return image;
|
||||
}
|
||||
|
||||
void *dummy_create_blur_context(struct backend_base *base attr_unused,
|
||||
|
||||
@@ -256,10 +256,11 @@ bool gl_dual_kawase_blur(double opacity, struct gl_blur_context *bctx, const rec
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gl_blur_impl(double opacity, struct gl_blur_context *bctx, void *mask, coord_t mask_dst,
|
||||
const region_t *reg_blur, const region_t *reg_visible attr_unused,
|
||||
GLuint source_texture, geometry_t source_size, GLuint target_fbo,
|
||||
GLuint default_mask, bool high_precision) {
|
||||
bool gl_blur_impl(double opacity, struct gl_blur_context *bctx,
|
||||
struct backend_image *mask, coord_t mask_dst, const region_t *reg_blur,
|
||||
const region_t *reg_visible attr_unused, GLuint source_texture,
|
||||
geometry_t source_size, GLuint target_fbo, GLuint default_mask,
|
||||
bool high_precision) {
|
||||
bool ret = false;
|
||||
|
||||
if (source_size.width != bctx->fb_width || source_size.height != bctx->fb_height) {
|
||||
@@ -400,12 +401,12 @@ bool gl_blur_impl(double opacity, struct gl_blur_context *bctx, void *mask, coor
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool gl_blur(backend_t *base, double opacity, void *ctx, void *mask, coord_t mask_dst,
|
||||
bool gl_blur(backend_t *base, double opacity, void *ctx, image_handle mask, coord_t mask_dst,
|
||||
const region_t *reg_blur, const region_t *reg_visible attr_unused) {
|
||||
auto gd = (struct gl_data *)base;
|
||||
auto bctx = (struct gl_blur_context *)ctx;
|
||||
return gl_blur_impl(opacity, bctx, mask, mask_dst, reg_blur, reg_visible,
|
||||
gd->back_texture,
|
||||
return gl_blur_impl(opacity, bctx, (struct backend_image *)mask, mask_dst,
|
||||
reg_blur, reg_visible, gd->back_texture,
|
||||
(geometry_t){.width = gd->width, .height = gd->height},
|
||||
gd->back_fbo, gd->default_mask_texture, gd->dithered_present);
|
||||
}
|
||||
@@ -604,9 +605,9 @@ bool gl_create_kernel_blur_context(void *blur_context, GLfloat *projection,
|
||||
bind_uniform(pass, mask_offset);
|
||||
bind_uniform(pass, mask_inverted);
|
||||
bind_uniform(pass, mask_corner_radius);
|
||||
log_info("Uniform locations: %d %d %d %d %d", pass->uniform_mask_tex,
|
||||
pass->uniform_mask_offset, pass->uniform_mask_inverted,
|
||||
pass->uniform_mask_corner_radius, pass->uniform_opacity);
|
||||
log_debug("Uniform locations: %d %d %d %d %d", pass->uniform_mask_tex,
|
||||
pass->uniform_mask_offset, pass->uniform_mask_inverted,
|
||||
pass->uniform_mask_corner_radius, pass->uniform_opacity);
|
||||
pass->texorig_loc = glGetUniformLocationChecked(pass->prog, "texorig");
|
||||
|
||||
// Setup projection matrix
|
||||
|
||||
@@ -36,12 +36,6 @@ struct egl_data {
|
||||
EGLContext ctx;
|
||||
};
|
||||
|
||||
static PFNGLEGLIMAGETARGETTEXSTORAGEEXTPROC glEGLImageTargetTexStorage = NULL;
|
||||
static PFNEGLCREATEIMAGEKHRPROC eglCreateImageProc = NULL;
|
||||
static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageProc = NULL;
|
||||
static PFNEGLGETPLATFORMDISPLAYPROC eglGetPlatformDisplayProc = NULL;
|
||||
static PFNEGLCREATEPLATFORMWINDOWSURFACEPROC eglCreatePlatformWindowSurfaceProc = NULL;
|
||||
|
||||
const char *eglGetErrorString(EGLint error) {
|
||||
#define CASE_STR(value) \
|
||||
case value: return #value;
|
||||
@@ -74,7 +68,7 @@ static void egl_release_image(backend_t *base, struct gl_texture *tex) {
|
||||
struct egl_pixmap *p = tex->user_data;
|
||||
// Release binding
|
||||
if (p->image != EGL_NO_IMAGE) {
|
||||
eglDestroyImageProc(gd->display, p->image);
|
||||
eglDestroyImage(gd->display, p->image);
|
||||
p->image = EGL_NO_IMAGE;
|
||||
}
|
||||
|
||||
@@ -134,18 +128,6 @@ static backend_t *egl_init(session_t *ps, xcb_window_t target) {
|
||||
bool success = false;
|
||||
struct egl_data *gd = NULL;
|
||||
|
||||
#define get_proc(name, type) \
|
||||
name##Proc = (type)eglGetProcAddress(#name); \
|
||||
if (!name##Proc) { \
|
||||
log_error("Failed to get EGL function " #name); \
|
||||
goto end; \
|
||||
}
|
||||
get_proc(eglCreateImage, PFNEGLCREATEIMAGEKHRPROC);
|
||||
get_proc(eglDestroyImage, PFNEGLDESTROYIMAGEKHRPROC);
|
||||
get_proc(eglGetPlatformDisplay, PFNEGLGETPLATFORMDISPLAYPROC);
|
||||
get_proc(eglCreatePlatformWindowSurface, PFNEGLCREATEPLATFORMWINDOWSURFACEPROC);
|
||||
#undef get_proc
|
||||
|
||||
// Check if we have the X11 platform
|
||||
const char *exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
||||
if (strstr(exts, "EGL_EXT_platform_x11") == NULL) {
|
||||
@@ -154,12 +136,12 @@ static backend_t *egl_init(session_t *ps, xcb_window_t target) {
|
||||
}
|
||||
|
||||
gd = ccalloc(1, struct egl_data);
|
||||
gd->display = eglGetPlatformDisplayProc(EGL_PLATFORM_X11_EXT, ps->c.dpy,
|
||||
(EGLAttrib[]){
|
||||
EGL_PLATFORM_X11_SCREEN_EXT,
|
||||
ps->c.screen,
|
||||
EGL_NONE,
|
||||
});
|
||||
gd->display = eglGetPlatformDisplayEXT(EGL_PLATFORM_X11_EXT, ps->c.dpy,
|
||||
(EGLint[]){
|
||||
EGL_PLATFORM_X11_SCREEN_EXT,
|
||||
ps->c.screen,
|
||||
EGL_NONE,
|
||||
});
|
||||
if (gd->display == EGL_NO_DISPLAY) {
|
||||
log_error("Failed to get EGL display.");
|
||||
goto end;
|
||||
@@ -212,7 +194,7 @@ static backend_t *egl_init(session_t *ps, xcb_window_t target) {
|
||||
// clang-format on
|
||||
|
||||
gd->target_win =
|
||||
eglCreatePlatformWindowSurfaceProc(gd->display, config, &target, NULL);
|
||||
eglCreatePlatformWindowSurfaceEXT(gd->display, config, &target, NULL);
|
||||
if (gd->target_win == EGL_NO_SURFACE) {
|
||||
log_error("Failed to create EGL surface.");
|
||||
goto end;
|
||||
@@ -243,14 +225,6 @@ static backend_t *egl_init(session_t *ps, xcb_window_t target) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
glEGLImageTargetTexStorage =
|
||||
(PFNGLEGLIMAGETARGETTEXSTORAGEEXTPROC)eglGetProcAddress("glEGLImageTargetTexS"
|
||||
"torageEXT");
|
||||
if (glEGLImageTargetTexStorage == NULL) {
|
||||
log_error("Failed to get glEGLImageTargetTexStorageEXT.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
gd->gl.decouple_texture_user_data = egl_decouple_user_data;
|
||||
gd->gl.release_user_data = egl_release_image;
|
||||
|
||||
@@ -275,7 +249,7 @@ end:
|
||||
return &gd->gl.base;
|
||||
}
|
||||
|
||||
static void *
|
||||
static image_handle
|
||||
egl_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, bool owned) {
|
||||
struct egl_data *gd = (void *)base;
|
||||
struct egl_pixmap *eglpixmap = NULL;
|
||||
@@ -302,9 +276,8 @@ egl_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
|
||||
|
||||
eglpixmap = cmalloc(struct egl_pixmap);
|
||||
eglpixmap->pixmap = pixmap;
|
||||
eglpixmap->image =
|
||||
eglCreateImageProc(gd->display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR,
|
||||
(EGLClientBuffer)(uintptr_t)pixmap, NULL);
|
||||
eglpixmap->image = eglCreateImage(gd->display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR,
|
||||
(EGLClientBuffer)(uintptr_t)pixmap, NULL);
|
||||
eglpixmap->owned = owned;
|
||||
|
||||
if (eglpixmap->image == EGL_NO_IMAGE) {
|
||||
@@ -324,14 +297,14 @@ egl_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
|
||||
wd->dim = 0;
|
||||
wd->inner->refcount = 1;
|
||||
glBindTexture(GL_TEXTURE_2D, inner->texture);
|
||||
glEGLImageTargetTexStorage(GL_TEXTURE_2D, eglpixmap->image, NULL);
|
||||
glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D, eglpixmap->image, NULL);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
gl_check_err();
|
||||
return wd;
|
||||
return (image_handle)wd;
|
||||
err:
|
||||
if (eglpixmap && eglpixmap->image) {
|
||||
eglDestroyImageProc(gd->display, eglpixmap->image);
|
||||
eglDestroyImage(gd->display, eglpixmap->image);
|
||||
}
|
||||
free(eglpixmap);
|
||||
|
||||
@@ -422,41 +395,6 @@ struct backend_operations egl_ops = {
|
||||
.max_buffer_age = 5, // Why?
|
||||
};
|
||||
|
||||
PFNEGLGETDISPLAYDRIVERNAMEPROC eglGetDisplayDriverName;
|
||||
/**
|
||||
* Check if a EGL extension exists.
|
||||
*/
|
||||
static inline bool egl_has_extension(EGLDisplay dpy, const char *ext) {
|
||||
const char *egl_exts = eglQueryString(dpy, EGL_EXTENSIONS);
|
||||
if (!egl_exts) {
|
||||
log_error("Failed get EGL extension list.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto inlen = strlen(ext);
|
||||
const char *curr = egl_exts;
|
||||
bool match = false;
|
||||
while (curr && !match) {
|
||||
const char *end = strchr(curr, ' ');
|
||||
if (!end) {
|
||||
// Last extension string
|
||||
match = strcmp(ext, curr) == 0;
|
||||
} else if (curr + inlen == end) {
|
||||
// Length match, do match string
|
||||
match = strncmp(ext, curr, (unsigned long)(end - curr)) == 0;
|
||||
}
|
||||
curr = end ? end + 1 : NULL;
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
log_info("Missing EGL extension %s.", ext);
|
||||
} else {
|
||||
log_info("Found EGL extension %s.", ext);
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
struct eglext_info eglext = {0};
|
||||
|
||||
void eglext_init(EGLDisplay dpy) {
|
||||
@@ -464,7 +402,10 @@ void eglext_init(EGLDisplay dpy) {
|
||||
return;
|
||||
}
|
||||
eglext.initialized = true;
|
||||
#define check_ext(name) eglext.has_##name = egl_has_extension(dpy, #name)
|
||||
#define check_ext(name) \
|
||||
eglext.has_##name = epoxy_has_egl_extension(dpy, #name); \
|
||||
log_info("Extension " #name " - %s", eglext.has_##name ? "present" : "absent")
|
||||
|
||||
check_ext(EGL_EXT_buffer_age);
|
||||
check_ext(EGL_EXT_create_context_robustness);
|
||||
check_ext(EGL_KHR_image_pixmap);
|
||||
@@ -472,16 +413,4 @@ void eglext_init(EGLDisplay dpy) {
|
||||
check_ext(EGL_MESA_query_driver);
|
||||
#endif
|
||||
#undef check_ext
|
||||
|
||||
// Checking if the returned function pointer is NULL is not really necessary,
|
||||
// or maybe not even useful, since eglGetProcAddress might always return
|
||||
// something. We are doing it just for completeness' sake.
|
||||
|
||||
#ifdef EGL_MESA_query_driver
|
||||
eglGetDisplayDriverName =
|
||||
(PFNEGLGETDISPLAYDRIVERNAMEPROC)eglGetProcAddress("eglGetDisplayDriverName");
|
||||
if (!eglGetDisplayDriverName) {
|
||||
eglext.has_EGL_MESA_query_driver = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
||||
#pragma once
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#include <epoxy/egl.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <stdbool.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/xcb.h>
|
||||
@@ -24,8 +22,4 @@ struct eglext_info {
|
||||
|
||||
extern struct eglext_info eglext;
|
||||
|
||||
#ifdef EGL_MESA_query_driver
|
||||
extern PFNEGLGETDISPLAYDRIVERNAMEPROC eglGetDisplayDriverName;
|
||||
#endif
|
||||
|
||||
void eglext_init(EGLDisplay);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -185,7 +184,7 @@ void gl_destroy_window_shader(backend_t *backend_data attr_unused, void *shader)
|
||||
* @note In order to reduce number of textures which needs to be
|
||||
* allocated and deleted during this recursive render
|
||||
* we reuse the same two textures for render source and
|
||||
* destination simply by alterating between them.
|
||||
* destination simply by alternating between them.
|
||||
* Unfortunately on first iteration source_texture might
|
||||
* be read-only. In this case we will select auxiliary_texture as
|
||||
* destination_texture in order not to touch that read-only source
|
||||
@@ -253,7 +252,7 @@ _gl_average_texture_color(backend_t *base, GLuint source_texture, GLuint destina
|
||||
|
||||
/*
|
||||
* @brief Builds a 1x1 texture which has color corresponding to the average of all
|
||||
* pixels of img by recursively rendering into texture of quorter the size (half
|
||||
* pixels of img by recursively rendering into texture of quarter the size (half
|
||||
* width and half height).
|
||||
* Returned texture must not be deleted, since it's owned by the gl_image. It will be
|
||||
* deleted when the gl_image is released.
|
||||
@@ -390,6 +389,10 @@ static void _gl_compose(backend_t *base, struct backend_image *img, GLuint targe
|
||||
if (win_shader->uniform_tex >= 0) {
|
||||
glUniform1i(win_shader->uniform_tex, 0);
|
||||
}
|
||||
if (win_shader->uniform_effective_size >= 0) {
|
||||
glUniform2f(win_shader->uniform_effective_size, (float)img->ewidth,
|
||||
(float)img->eheight);
|
||||
}
|
||||
if (win_shader->uniform_dim >= 0) {
|
||||
glUniform1f(win_shader->uniform_dim, (float)img->dim);
|
||||
}
|
||||
@@ -417,7 +420,7 @@ static void _gl_compose(backend_t *base, struct backend_image *img, GLuint targe
|
||||
}
|
||||
|
||||
glUniform1i(win_shader->uniform_mask_tex, 2);
|
||||
glUniform2f(win_shader->uniform_mask_offset, (float)mask_offset.x,
|
||||
glUniform2f(win_shader->uniform_mask_offset, (float)mask_offset.x ,
|
||||
(float)mask_offset.y);
|
||||
if (mask != NULL) {
|
||||
glUniform1i(win_shader->uniform_mask_inverted, mask->color_inverted);
|
||||
@@ -499,6 +502,7 @@ void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst,
|
||||
image_dst.y = root_height - image_dst.y;
|
||||
image_dst.y -= extent_height;
|
||||
|
||||
|
||||
for (int i = 0; i < nrects; i++) {
|
||||
// Y-flip. Note after this, crect.y1 > crect.y2
|
||||
rect_t crect = rects[i];
|
||||
@@ -548,11 +552,12 @@ void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst,
|
||||
}
|
||||
|
||||
// TODO(yshui) make use of reg_visible
|
||||
void gl_compose(backend_t *base, void *image_data, coord_t image_dst, void *mask,
|
||||
void gl_compose(backend_t *base, image_handle image_data, coord_t image_dst, image_handle mask_,
|
||||
coord_t mask_dst, const region_t *reg_tgt,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
const region_t *reg_visible attr_unused, bool lerp) {
|
||||
auto gd = (struct gl_data *)base;
|
||||
struct backend_image *img = image_data;
|
||||
auto img = (struct backend_image *)image_data;
|
||||
auto mask = (struct backend_image *)mask_;
|
||||
auto inner = (struct gl_texture *)img->inner;
|
||||
|
||||
// Painting
|
||||
@@ -576,6 +581,14 @@ void gl_compose(backend_t *base, void *image_data, coord_t image_dst, void *mask
|
||||
coord_t mask_offset = {.x = mask_dst.x - image_dst.x, .y = mask_dst.y - image_dst.y};
|
||||
x_rect_to_coords(nrects, rects, image_dst, inner->height, inner->height,
|
||||
gd->height, inner->y_inverted, coord, indices);
|
||||
|
||||
if (lerp) {
|
||||
for (unsigned int i = 2; i < 16; i+=4) {
|
||||
coord[i+0] = lerp_range(0, mask_offset.x, 0, inner->width, coord[i+0]);
|
||||
coord[i+1] = lerp_range(0, mask_offset.y, 0, inner->height, coord[i+1]);
|
||||
}
|
||||
}
|
||||
|
||||
_gl_compose(base, img, gd->back_fbo, mask, mask_offset, coord, indices, nrects);
|
||||
|
||||
free(indices);
|
||||
@@ -599,6 +612,7 @@ static bool gl_win_shader_from_stringv(const char **vshader_strv,
|
||||
bind_uniform(ret, opacity);
|
||||
bind_uniform(ret, invert_color);
|
||||
bind_uniform(ret, tex);
|
||||
bind_uniform(ret, effective_size);
|
||||
bind_uniform(ret, dim);
|
||||
bind_uniform(ret, brightness);
|
||||
bind_uniform(ret, max_brightness);
|
||||
@@ -705,7 +719,7 @@ void gl_fill(backend_t *base, struct color c, const region_t *clip) {
|
||||
return _gl_fill(base, c, clip, gd->back_fbo, gd->height, true);
|
||||
}
|
||||
|
||||
void *gl_make_mask(backend_t *base, geometry_t size, const region_t *reg) {
|
||||
image_handle gl_make_mask(backend_t *base, geometry_t size, const region_t *reg) {
|
||||
auto tex = ccalloc(1, struct gl_texture);
|
||||
auto img = default_new_backend_image(size.width, size.height);
|
||||
tex->width = size.width;
|
||||
@@ -736,7 +750,7 @@ void *gl_make_mask(backend_t *base, geometry_t size, const region_t *reg) {
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
return img;
|
||||
return (image_handle)img;
|
||||
}
|
||||
|
||||
static void gl_release_image_inner(backend_t *base, struct gl_texture *inner) {
|
||||
@@ -752,8 +766,8 @@ static void gl_release_image_inner(backend_t *base, struct gl_texture *inner) {
|
||||
gl_check_err();
|
||||
}
|
||||
|
||||
void gl_release_image(backend_t *base, void *image_data) {
|
||||
struct backend_image *wd = image_data;
|
||||
void gl_release_image(backend_t *base, image_handle image) {
|
||||
auto wd = (struct backend_image *)image;
|
||||
auto inner = (struct gl_texture *)wd->inner;
|
||||
inner->refcount--;
|
||||
assert(inner->refcount >= 0);
|
||||
@@ -880,24 +894,35 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
|
||||
glUseProgram(0);
|
||||
|
||||
gd->dithered_present = ps->o.dithered_present;
|
||||
gd->dummy_prog =
|
||||
gl_create_program_from_strv((const char *[]){present_vertex_shader, NULL},
|
||||
(const char *[]){dummy_frag, NULL});
|
||||
if (!gd->dummy_prog) {
|
||||
log_error("Failed to create the dummy shader");
|
||||
return false;
|
||||
}
|
||||
if (gd->dithered_present) {
|
||||
gd->present_prog = gl_create_program_from_strv(
|
||||
(const char *[]){present_vertex_shader, NULL},
|
||||
(const char *[]){present_frag, dither_glsl, NULL});
|
||||
} else {
|
||||
gd->present_prog = gl_create_program_from_strv(
|
||||
(const char *[]){present_vertex_shader, NULL},
|
||||
(const char *[]){dummy_frag, NULL});
|
||||
gd->present_prog = gd->dummy_prog;
|
||||
}
|
||||
if (!gd->present_prog) {
|
||||
log_error("Failed to create the present shader");
|
||||
return false;
|
||||
}
|
||||
pml = glGetUniformLocationChecked(gd->present_prog, "projection");
|
||||
glUseProgram(gd->present_prog);
|
||||
glUniform1i(glGetUniformLocationChecked(gd->present_prog, "tex"), 0);
|
||||
|
||||
pml = glGetUniformLocationChecked(gd->dummy_prog, "projection");
|
||||
glUseProgram(gd->dummy_prog);
|
||||
glUniform1i(glGetUniformLocationChecked(gd->dummy_prog, "tex"), 0);
|
||||
glUniformMatrix4fv(pml, 1, false, projection_matrix[0]);
|
||||
glUseProgram(0);
|
||||
if (gd->present_prog != gd->dummy_prog) {
|
||||
pml = glGetUniformLocationChecked(gd->present_prog, "projection");
|
||||
glUseProgram(gd->present_prog);
|
||||
glUniform1i(glGetUniformLocationChecked(gd->present_prog, "tex"), 0);
|
||||
glUniformMatrix4fv(pml, 1, false, projection_matrix[0]);
|
||||
}
|
||||
|
||||
gd->shadow_shader.prog =
|
||||
gl_create_program_from_str(present_vertex_shader, shadow_colorization_frag);
|
||||
@@ -907,7 +932,6 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
|
||||
glUseProgram(gd->shadow_shader.prog);
|
||||
glUniform1i(glGetUniformLocationChecked(gd->shadow_shader.prog, "tex"), 0);
|
||||
glUniformMatrix4fv(pml, 1, false, projection_matrix[0]);
|
||||
glUseProgram(0);
|
||||
glBindFragDataLocation(gd->shadow_shader.prog, 0, "out_color");
|
||||
|
||||
gd->brightness_shader.prog =
|
||||
@@ -920,6 +944,7 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
|
||||
glUseProgram(gd->brightness_shader.prog);
|
||||
glUniform1i(glGetUniformLocationChecked(gd->brightness_shader.prog, "tex"), 0);
|
||||
glUniformMatrix4fv(pml, 1, false, projection_matrix[0]);
|
||||
|
||||
glUseProgram(0);
|
||||
|
||||
// Set up the size and format of the back texture
|
||||
@@ -956,8 +981,8 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
|
||||
} else {
|
||||
gd->is_nvidia = false;
|
||||
}
|
||||
gd->has_robustness = gl_has_extension("GL_ARB_robustness");
|
||||
gd->has_egl_image_storage = gl_has_extension("GL_EXT_EGL_image_storage");
|
||||
gd->has_robustness = epoxy_has_gl_extension("GL_ARB_robustness");
|
||||
gd->has_egl_image_storage = epoxy_has_gl_extension("GL_EXT_EGL_image_storage");
|
||||
gl_check_err();
|
||||
|
||||
return true;
|
||||
@@ -973,10 +998,25 @@ void gl_deinit(struct gl_data *gd) {
|
||||
gl_destroy_window_shader(&gd->base, gd->default_shader);
|
||||
gd->default_shader = NULL;
|
||||
}
|
||||
glDeleteProgram(gd->dummy_prog);
|
||||
if (gd->present_prog != gd->dummy_prog) {
|
||||
glDeleteProgram(gd->present_prog);
|
||||
}
|
||||
gd->dummy_prog = 0;
|
||||
gd->present_prog = 0;
|
||||
|
||||
glDeleteProgram(gd->fill_shader.prog);
|
||||
glDeleteProgram(gd->brightness_shader.prog);
|
||||
glDeleteProgram(gd->shadow_shader.prog);
|
||||
gd->fill_shader.prog = 0;
|
||||
gd->brightness_shader.prog = 0;
|
||||
gd->shadow_shader.prog = 0;
|
||||
|
||||
glDeleteTextures(1, &gd->default_mask_texture);
|
||||
glDeleteTextures(1, &gd->back_texture);
|
||||
|
||||
glDeleteQueries(2, gd->frame_timing);
|
||||
|
||||
gl_check_err();
|
||||
}
|
||||
|
||||
@@ -1008,9 +1048,11 @@ static inline void gl_image_decouple(backend_t *base, struct backend_image *img)
|
||||
auto new_tex = ccalloc(1, struct gl_texture);
|
||||
|
||||
new_tex->texture = gl_new_texture(GL_TEXTURE_2D);
|
||||
new_tex->y_inverted = true;
|
||||
new_tex->y_inverted = inner->y_inverted;
|
||||
new_tex->has_alpha = inner->has_alpha;
|
||||
new_tex->height = inner->height;
|
||||
new_tex->width = inner->width;
|
||||
new_tex->shader = inner->shader;
|
||||
new_tex->refcount = 1;
|
||||
new_tex->user_data = gd->decouple_texture_user_data(base, inner->user_data);
|
||||
|
||||
@@ -1019,8 +1061,7 @@ static inline void gl_image_decouple(backend_t *base, struct backend_image *img)
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
assert(gd->present_prog);
|
||||
glUseProgram(gd->present_prog);
|
||||
glUseProgram(gd->dummy_prog);
|
||||
glBindTexture(GL_TEXTURE_2D, inner->texture);
|
||||
|
||||
GLuint fbo;
|
||||
@@ -1190,9 +1231,9 @@ bool gl_last_render_time(backend_t *base, struct timespec *ts) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gl_image_op(backend_t *base, enum image_operations op, void *image_data,
|
||||
bool gl_image_op(backend_t *base, enum image_operations op, image_handle image,
|
||||
const region_t *reg_op, const region_t *reg_visible attr_unused, void *arg) {
|
||||
struct backend_image *tex = image_data;
|
||||
auto tex = (struct backend_image *)image;
|
||||
switch (op) {
|
||||
case IMAGE_OP_APPLY_ALPHA:
|
||||
gl_image_decouple(base, tex);
|
||||
@@ -1205,12 +1246,12 @@ bool gl_image_op(backend_t *base, enum image_operations op, void *image_data,
|
||||
}
|
||||
|
||||
bool gl_set_image_property(backend_t *backend_data, enum image_properties prop,
|
||||
void *image_data, void *args) {
|
||||
image_handle image, void *args) {
|
||||
if (prop != IMAGE_PROPERTY_CUSTOM_SHADER) {
|
||||
return default_set_image_property(backend_data, prop, image_data, args);
|
||||
return default_set_image_property(backend_data, prop, image, args);
|
||||
}
|
||||
|
||||
struct backend_image *img = image_data;
|
||||
auto img = (struct backend_image *)image;
|
||||
auto inner = (struct gl_texture *)img->inner;
|
||||
inner->shader = args;
|
||||
return true;
|
||||
@@ -1249,12 +1290,12 @@ void gl_destroy_shadow_context(backend_t *base attr_unused, struct backend_shado
|
||||
free(ctx_);
|
||||
}
|
||||
|
||||
void *gl_shadow_from_mask(backend_t *base, void *mask,
|
||||
struct backend_shadow_context *sctx, struct color color) {
|
||||
image_handle gl_shadow_from_mask(backend_t *base, image_handle mask_,
|
||||
struct backend_shadow_context *sctx, struct color color) {
|
||||
log_debug("Create shadow from mask");
|
||||
auto gd = (struct gl_data *)base;
|
||||
auto img = (struct backend_image *)mask;
|
||||
auto inner = (struct gl_texture *)img->inner;
|
||||
auto mask = (struct backend_image *)mask_;
|
||||
auto inner = (struct gl_texture *)mask->inner;
|
||||
auto gsctx = (struct gl_shadow_context *)sctx;
|
||||
int radius = (int)gsctx->radius;
|
||||
|
||||
@@ -1284,7 +1325,7 @@ void *gl_shadow_from_mask(backend_t *base, void *mask,
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
source_texture, 0);
|
||||
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
||||
if (img->color_inverted) {
|
||||
if (mask->color_inverted) {
|
||||
// If the mask is inverted, clear the source_texture to white, so the
|
||||
// "outside" of the mask would be correct
|
||||
glClearColor(1, 1, 1, 1);
|
||||
@@ -1393,7 +1434,7 @@ void *gl_shadow_from_mask(backend_t *base, void *mask,
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
gl_check_err();
|
||||
return new_img;
|
||||
return (image_handle)new_img;
|
||||
}
|
||||
|
||||
enum device_status gl_device_status(backend_t *base) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
||||
#pragma once
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "backend/backend.h"
|
||||
#include "backend/backend_common.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
|
||||
@@ -29,12 +29,11 @@ static inline GLint glGetUniformLocationChecked(GLuint p, const char *name) {
|
||||
|
||||
// Program and uniforms for window shader
|
||||
typedef struct {
|
||||
UT_hash_handle hh;
|
||||
uint32_t id;
|
||||
GLuint prog;
|
||||
GLint uniform_opacity;
|
||||
GLint uniform_invert_color;
|
||||
GLint uniform_tex;
|
||||
GLint uniform_effective_size;
|
||||
GLint uniform_dim;
|
||||
GLint uniform_brightness;
|
||||
GLint uniform_max_brightness;
|
||||
@@ -77,7 +76,7 @@ typedef struct {
|
||||
GLint color_loc;
|
||||
} gl_fill_shader_t;
|
||||
|
||||
/// @brief Wrapper of a binded GL texture.
|
||||
/// @brief Wrapper of a bound GL texture.
|
||||
struct gl_texture {
|
||||
int refcount;
|
||||
bool has_alpha;
|
||||
@@ -111,6 +110,7 @@ struct gl_data {
|
||||
GLuint frame_timing[2];
|
||||
int current_frame_timing;
|
||||
GLuint present_prog;
|
||||
GLuint dummy_prog;
|
||||
|
||||
bool dithered_present;
|
||||
|
||||
@@ -144,14 +144,14 @@ void *gl_create_window_shader(backend_t *backend_data, const char *source);
|
||||
void gl_destroy_window_shader(backend_t *backend_data, void *shader);
|
||||
uint64_t gl_get_shader_attributes(backend_t *backend_data, void *shader);
|
||||
bool gl_set_image_property(backend_t *backend_data, enum image_properties prop,
|
||||
void *image_data, void *args);
|
||||
image_handle image, void *args);
|
||||
bool gl_last_render_time(backend_t *backend_data, struct timespec *time);
|
||||
|
||||
/**
|
||||
* @brief Render a region with texture data.
|
||||
*/
|
||||
void gl_compose(backend_t *, void *image_data, coord_t image_dst, void *mask,
|
||||
coord_t mask_dst, const region_t *reg_tgt, const region_t *reg_visible);
|
||||
void gl_compose(backend_t *, image_handle image_data, coord_t image_dst, image_handle mask_,
|
||||
coord_t mask_dst, const region_t *reg_tgt, const region_t *reg_visible, bool lerp);
|
||||
|
||||
void gl_resize(struct gl_data *, int width, int height);
|
||||
|
||||
@@ -160,32 +160,32 @@ void gl_deinit(struct gl_data *gd);
|
||||
|
||||
GLuint gl_new_texture(GLenum target);
|
||||
|
||||
bool gl_image_op(backend_t *base, enum image_operations op, void *image_data,
|
||||
bool gl_image_op(backend_t *base, enum image_operations op, image_handle image,
|
||||
const region_t *reg_op, const region_t *reg_visible, void *arg);
|
||||
|
||||
void gl_release_image(backend_t *base, void *image_data);
|
||||
void *gl_make_mask(backend_t *base, geometry_t size, const region_t *reg);
|
||||
void gl_release_image(backend_t *base, image_handle image);
|
||||
image_handle gl_make_mask(backend_t *base, geometry_t size, const region_t *reg);
|
||||
|
||||
void *gl_clone(backend_t *base, const void *image_data, const region_t *reg_visible);
|
||||
image_handle gl_clone(backend_t *base, image_handle image, const region_t *reg_visible);
|
||||
|
||||
bool gl_blur(backend_t *base, double opacity, void *ctx, void *mask, coord_t mask_dst,
|
||||
const region_t *reg_blur, const region_t *reg_visible);
|
||||
bool gl_blur_impl(double opacity, struct gl_blur_context *bctx, void *mask, coord_t mask_dst,
|
||||
const region_t *reg_blur, const region_t *reg_visible attr_unused,
|
||||
GLuint source_texture, geometry_t source_size, GLuint target_fbo,
|
||||
GLuint default_mask, bool high_precision);
|
||||
bool gl_blur(backend_t *base, double opacity, void *ctx, image_handle mask,
|
||||
coord_t mask_dst, const region_t *reg_blur, const region_t *reg_visible);
|
||||
bool gl_blur_impl(double opacity, struct gl_blur_context *bctx,
|
||||
struct backend_image *mask, coord_t mask_dst, const region_t *reg_blur,
|
||||
const region_t *reg_visible attr_unused, GLuint source_texture,
|
||||
geometry_t source_size, GLuint target_fbo, GLuint default_mask,
|
||||
bool high_precision);
|
||||
void *gl_create_blur_context(backend_t *base, enum blur_method, void *args);
|
||||
void gl_destroy_blur_context(backend_t *base, void *ctx);
|
||||
struct backend_shadow_context *gl_create_shadow_context(backend_t *base, double radius);
|
||||
void gl_destroy_shadow_context(backend_t *base attr_unused, struct backend_shadow_context *ctx);
|
||||
void *gl_shadow_from_mask(backend_t *base, void *mask,
|
||||
struct backend_shadow_context *sctx, struct color color);
|
||||
image_handle gl_shadow_from_mask(backend_t *base, image_handle mask,
|
||||
struct backend_shadow_context *sctx, struct color color);
|
||||
void gl_get_blur_size(void *blur_context, int *width, int *height);
|
||||
|
||||
void gl_fill(backend_t *base, struct color, const region_t *clip);
|
||||
|
||||
void gl_present(backend_t *base, const region_t *);
|
||||
bool gl_read_pixel(backend_t *base, void *image_data, int x, int y, struct color *output);
|
||||
enum device_status gl_device_status(backend_t *base);
|
||||
|
||||
/**
|
||||
@@ -264,26 +264,6 @@ static inline bool gl_check_fb_complete_(const char *func, int line, GLenum fb)
|
||||
|
||||
#define gl_check_fb_complete(fb) gl_check_fb_complete_(__func__, __LINE__, (fb))
|
||||
|
||||
/**
|
||||
* Check if a GL extension exists.
|
||||
*/
|
||||
static inline bool gl_has_extension(const char *ext) {
|
||||
int nexts = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &nexts);
|
||||
for (int i = 0; i < nexts || !nexts; i++) {
|
||||
const char *exti = (const char *)glGetStringi(GL_EXTENSIONS, (GLuint)i);
|
||||
if (exti == NULL) {
|
||||
break;
|
||||
}
|
||||
if (strcmp(ext, exti) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
gl_clear_err();
|
||||
log_info("Missing GL extension %s.", ext);
|
||||
return false;
|
||||
}
|
||||
|
||||
static const GLuint vert_coord_loc = 0;
|
||||
static const GLuint vert_in_texcoord_loc = 1;
|
||||
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <uthash.h>
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "backend/backend.h"
|
||||
#include "backend/backend_common.h"
|
||||
@@ -44,6 +46,13 @@ struct _glx_data {
|
||||
struct gl_data gl;
|
||||
xcb_window_t target_win;
|
||||
GLXContext ctx;
|
||||
struct glx_fbconfig_cache *cached_fbconfigs;
|
||||
};
|
||||
|
||||
struct glx_fbconfig_cache {
|
||||
UT_hash_handle hh;
|
||||
struct xvisual_info visual_info;
|
||||
struct glx_fbconfig_info info;
|
||||
};
|
||||
|
||||
#define glXGetFBConfigAttribChecked(a, b, attr, c) \
|
||||
@@ -54,9 +63,12 @@ struct _glx_data {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *c, struct xvisual_info m) {
|
||||
log_debug("Looking for FBConfig for RGBA%d%d%d%d, depth %d", m.red_size,
|
||||
m.blue_size, m.green_size, m.alpha_size, m.visual_depth);
|
||||
bool glx_find_fbconfig(struct x_connection *c, struct xvisual_info m,
|
||||
struct glx_fbconfig_info *info) {
|
||||
log_debug("Looking for FBConfig for RGBA%d%d%d%d, depth: %d, visual id: %#x", m.red_size,
|
||||
m.blue_size, m.green_size, m.alpha_size, m.visual_depth, m.visual);
|
||||
|
||||
info->cfg = NULL;
|
||||
|
||||
int ncfg;
|
||||
// clang-format off
|
||||
@@ -114,7 +126,8 @@ struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *c, struct xvisu
|
||||
int visual;
|
||||
glXGetFBConfigAttribChecked(c->dpy, cfg[i], GLX_VISUAL_ID, &visual);
|
||||
if (m.visual_depth != -1 &&
|
||||
x_get_visual_depth(c, (xcb_visualid_t)visual) != m.visual_depth) {
|
||||
xcb_aux_get_depth_of_visual(c->screen_info, (xcb_visualid_t)visual) !=
|
||||
m.visual_depth) {
|
||||
// FBConfig and the correspondent X Visual might not have the same
|
||||
// depth. (e.g. 32 bit FBConfig with a 24 bit Visual). This is
|
||||
// quite common, seen in both open source and proprietary drivers.
|
||||
@@ -143,16 +156,13 @@ struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *c, struct xvisu
|
||||
min_cost = depthbuf + stencil + bufsize * (doublebuf + 1);
|
||||
}
|
||||
free(cfg);
|
||||
if (!found) {
|
||||
return NULL;
|
||||
if (found) {
|
||||
info->cfg = ret;
|
||||
info->texture_tgts = texture_tgts;
|
||||
info->texture_fmt = texture_fmt;
|
||||
info->y_inverted = y_inverted;
|
||||
}
|
||||
|
||||
auto info = cmalloc(struct glx_fbconfig_info);
|
||||
info->cfg = ret;
|
||||
info->texture_tgts = texture_tgts;
|
||||
info->texture_fmt = texture_fmt;
|
||||
info->y_inverted = y_inverted;
|
||||
return info;
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,6 +207,12 @@ void glx_deinit(backend_t *base) {
|
||||
gd->ctx = 0;
|
||||
}
|
||||
|
||||
struct glx_fbconfig_cache *cached_fbconfig = NULL, *tmp = NULL;
|
||||
HASH_ITER(hh, gd->cached_fbconfigs, cached_fbconfig, tmp) {
|
||||
HASH_DEL(gd->cached_fbconfigs, cached_fbconfig);
|
||||
free(cached_fbconfig);
|
||||
}
|
||||
|
||||
free(gd);
|
||||
}
|
||||
|
||||
@@ -364,9 +380,10 @@ end:
|
||||
return &gd->gl.base;
|
||||
}
|
||||
|
||||
static void *
|
||||
static image_handle
|
||||
glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, bool owned) {
|
||||
struct _glx_pixmap *glxpixmap = NULL;
|
||||
auto gd = (struct _glx_data *)base;
|
||||
// Retrieve pixmap parameters, if they aren't provided
|
||||
if (fmt.visual_depth > OPENGL_MAX_DEPTH) {
|
||||
log_error("Requested depth %d higher than max possible depth %d.",
|
||||
@@ -394,38 +411,52 @@ glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
|
||||
wd->inner = (struct backend_image_inner_base *)inner;
|
||||
free(r);
|
||||
|
||||
auto fbcfg = glx_find_fbconfig(base->c, fmt);
|
||||
if (!fbcfg) {
|
||||
log_error("Couldn't find FBConfig with requested visual %x", fmt.visual);
|
||||
goto err;
|
||||
struct glx_fbconfig_cache *cached_fbconfig = NULL;
|
||||
HASH_FIND(hh, gd->cached_fbconfigs, &fmt, sizeof(fmt), cached_fbconfig);
|
||||
if (!cached_fbconfig) {
|
||||
struct glx_fbconfig_info fbconfig;
|
||||
if (!glx_find_fbconfig(base->c, fmt, &fbconfig)) {
|
||||
log_error("Couldn't find FBConfig with requested visual %#x",
|
||||
fmt.visual);
|
||||
goto err;
|
||||
}
|
||||
cached_fbconfig = cmalloc(struct glx_fbconfig_cache);
|
||||
cached_fbconfig->visual_info = fmt;
|
||||
cached_fbconfig->info = fbconfig;
|
||||
HASH_ADD(hh, gd->cached_fbconfigs, visual_info, sizeof(fmt), cached_fbconfig);
|
||||
} else {
|
||||
log_debug("Found cached FBConfig for RGBA%d%d%d%d, depth: %d, visual id: "
|
||||
"%#x",
|
||||
fmt.red_size, fmt.blue_size, fmt.green_size, fmt.alpha_size,
|
||||
fmt.visual_depth, fmt.visual);
|
||||
}
|
||||
struct glx_fbconfig_info *fbconfig = &cached_fbconfig->info;
|
||||
|
||||
// Choose a suitable texture target for our pixmap.
|
||||
// Refer to GLX_EXT_texture_om_pixmap spec to see what are the mean
|
||||
// of the bits in texture_tgts
|
||||
if (!(fbcfg->texture_tgts & GLX_TEXTURE_2D_BIT_EXT)) {
|
||||
if (!(fbconfig->texture_tgts & GLX_TEXTURE_2D_BIT_EXT)) {
|
||||
log_error("Cannot bind pixmap to GL_TEXTURE_2D, giving up");
|
||||
goto err;
|
||||
}
|
||||
|
||||
log_debug("depth %d, rgba %d", fmt.visual_depth,
|
||||
(fbcfg->texture_fmt == GLX_TEXTURE_FORMAT_RGBA_EXT));
|
||||
(fbconfig->texture_fmt == GLX_TEXTURE_FORMAT_RGBA_EXT));
|
||||
|
||||
GLint attrs[] = {
|
||||
GLX_TEXTURE_FORMAT_EXT,
|
||||
fbcfg->texture_fmt,
|
||||
fbconfig->texture_fmt,
|
||||
GLX_TEXTURE_TARGET_EXT,
|
||||
GLX_TEXTURE_2D_EXT,
|
||||
0,
|
||||
};
|
||||
|
||||
inner->y_inverted = fbcfg->y_inverted;
|
||||
inner->y_inverted = fbconfig->y_inverted;
|
||||
|
||||
glxpixmap = cmalloc(struct _glx_pixmap);
|
||||
glxpixmap->pixmap = pixmap;
|
||||
glxpixmap->glpixmap = glXCreatePixmap(base->c->dpy, fbcfg->cfg, pixmap, attrs);
|
||||
glxpixmap->glpixmap = glXCreatePixmap(base->c->dpy, fbconfig->cfg, pixmap, attrs);
|
||||
glxpixmap->owned = owned;
|
||||
free(fbcfg);
|
||||
|
||||
if (!glxpixmap->glpixmap) {
|
||||
log_error("Failed to create glpixmap for pixmap %#010x", pixmap);
|
||||
@@ -444,7 +475,7 @@ glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, b
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
gl_check_err();
|
||||
return wd;
|
||||
return (image_handle)wd;
|
||||
err:
|
||||
if (glxpixmap && glxpixmap->glpixmap) {
|
||||
glXDestroyPixmap(base->c->dpy, glxpixmap->glpixmap);
|
||||
@@ -545,62 +576,17 @@ struct backend_operations glx_ops = {
|
||||
.max_buffer_age = 5, // Why?
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a GLX extension exists.
|
||||
*/
|
||||
static inline bool glx_has_extension(Display *dpy, int screen, const char *ext) {
|
||||
const char *glx_exts = glXQueryExtensionsString(dpy, screen);
|
||||
if (!glx_exts) {
|
||||
log_error("Failed get GLX extension list.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto inlen = strlen(ext);
|
||||
const char *curr = glx_exts;
|
||||
bool match = false;
|
||||
while (curr && !match) {
|
||||
const char *end = strchr(curr, ' ');
|
||||
if (!end) {
|
||||
// Last extension string
|
||||
match = strcmp(ext, curr) == 0;
|
||||
} else if (curr + inlen == end) {
|
||||
// Length match, do match string
|
||||
match = strncmp(ext, curr, (unsigned long)(end - curr)) == 0;
|
||||
}
|
||||
curr = end ? end + 1 : NULL;
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
log_info("Missing GLX extension %s.", ext);
|
||||
} else {
|
||||
log_info("Found GLX extension %s.", ext);
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
struct glxext_info glxext = {0};
|
||||
PFNGLXGETVIDEOSYNCSGIPROC glXGetVideoSyncSGI;
|
||||
PFNGLXWAITVIDEOSYNCSGIPROC glXWaitVideoSyncSGI;
|
||||
PFNGLXGETSYNCVALUESOMLPROC glXGetSyncValuesOML;
|
||||
PFNGLXWAITFORMSCOMLPROC glXWaitForMscOML;
|
||||
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
|
||||
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
|
||||
PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA;
|
||||
PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT;
|
||||
PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT;
|
||||
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
|
||||
|
||||
#ifdef GLX_MESA_query_renderer
|
||||
PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC glXQueryCurrentRendererIntegerMESA;
|
||||
#endif
|
||||
|
||||
void glxext_init(Display *dpy, int screen) {
|
||||
if (glxext.initialized) {
|
||||
return;
|
||||
}
|
||||
glxext.initialized = true;
|
||||
#define check_ext(name) glxext.has_##name = glx_has_extension(dpy, screen, #name)
|
||||
#define check_ext(name) \
|
||||
glxext.has_##name = epoxy_has_glx_extension(dpy, screen, #name); \
|
||||
log_info("Extension " #name " - %s", glxext.has_##name ? "present" : "absent")
|
||||
|
||||
check_ext(GLX_SGI_video_sync);
|
||||
check_ext(GLX_SGI_swap_control);
|
||||
check_ext(GLX_OML_sync_control);
|
||||
@@ -614,36 +600,4 @@ void glxext_init(Display *dpy, int screen) {
|
||||
check_ext(GLX_MESA_query_renderer);
|
||||
#endif
|
||||
#undef check_ext
|
||||
|
||||
#define lookup(name) ((name) = (__typeof__(name))glXGetProcAddress((GLubyte *)#name))
|
||||
// Checking if the returned function pointer is NULL is not really necessary,
|
||||
// or maybe not even useful, since glXGetProcAddress might always return
|
||||
// something. We are doing it just for completeness' sake.
|
||||
if (!lookup(glXGetVideoSyncSGI) || !lookup(glXWaitVideoSyncSGI)) {
|
||||
glxext.has_GLX_SGI_video_sync = false;
|
||||
}
|
||||
if (!lookup(glXSwapIntervalEXT)) {
|
||||
glxext.has_GLX_EXT_swap_control = false;
|
||||
}
|
||||
if (!lookup(glXSwapIntervalMESA)) {
|
||||
glxext.has_GLX_MESA_swap_control = false;
|
||||
}
|
||||
if (!lookup(glXSwapIntervalSGI)) {
|
||||
glxext.has_GLX_SGI_swap_control = false;
|
||||
}
|
||||
if (!lookup(glXWaitForMscOML) || !lookup(glXGetSyncValuesOML)) {
|
||||
glxext.has_GLX_OML_sync_control = false;
|
||||
}
|
||||
if (!lookup(glXBindTexImageEXT) || !lookup(glXReleaseTexImageEXT)) {
|
||||
glxext.has_GLX_EXT_texture_from_pixmap = false;
|
||||
}
|
||||
if (!lookup(glXCreateContextAttribsARB)) {
|
||||
glxext.has_GLX_ARB_create_context = false;
|
||||
}
|
||||
#ifdef GLX_MESA_query_renderer
|
||||
if (!lookup(glXQueryCurrentRendererIntegerMESA)) {
|
||||
glxext.has_GLX_MESA_query_renderer = false;
|
||||
}
|
||||
#endif
|
||||
#undef lookup
|
||||
}
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
// Older version of glx.h defines function prototypes for these extensions...
|
||||
// Rename them to avoid conflicts
|
||||
#define glXSwapIntervalMESA glXSwapIntervalMESA_
|
||||
#define glXBindTexImageEXT glXBindTexImageEXT_
|
||||
#define glXReleaseTexImageEXT glXReleaseTexImageEXT
|
||||
#include <GL/glx.h>
|
||||
#undef glXSwapIntervalMESA
|
||||
#undef glXBindTexImageEXT
|
||||
#undef glXReleaseTexImageEXT
|
||||
#include <X11/Xlib.h>
|
||||
#include <epoxy/glx.h>
|
||||
#include <stdbool.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
@@ -27,21 +19,8 @@ struct glx_fbconfig_info {
|
||||
int y_inverted;
|
||||
};
|
||||
|
||||
/// The search criteria for glx_find_fbconfig
|
||||
struct glx_fbconfig_criteria {
|
||||
/// Bit width of the red component
|
||||
int red_size;
|
||||
/// Bit width of the green component
|
||||
int green_size;
|
||||
/// Bit width of the blue component
|
||||
int blue_size;
|
||||
/// Bit width of the alpha component
|
||||
int alpha_size;
|
||||
/// The depth of X visual
|
||||
int visual_depth;
|
||||
};
|
||||
|
||||
struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *, struct xvisual_info);
|
||||
bool glx_find_fbconfig(struct x_connection *c, struct xvisual_info m,
|
||||
struct glx_fbconfig_info *info);
|
||||
|
||||
struct glxext_info {
|
||||
bool initialized;
|
||||
@@ -59,19 +38,4 @@ struct glxext_info {
|
||||
|
||||
extern struct glxext_info glxext;
|
||||
|
||||
extern PFNGLXGETVIDEOSYNCSGIPROC glXGetVideoSyncSGI;
|
||||
extern PFNGLXWAITVIDEOSYNCSGIPROC glXWaitVideoSyncSGI;
|
||||
extern PFNGLXGETSYNCVALUESOMLPROC glXGetSyncValuesOML;
|
||||
extern PFNGLXWAITFORMSCOMLPROC glXWaitForMscOML;
|
||||
extern PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
|
||||
extern PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
|
||||
extern PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA;
|
||||
extern PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT;
|
||||
extern PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT;
|
||||
extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
|
||||
|
||||
#ifdef GLX_MESA_query_renderer
|
||||
extern PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC glXQueryCurrentRendererIntegerMESA;
|
||||
#endif
|
||||
|
||||
void glxext_init(Display *, int screen);
|
||||
|
||||
@@ -97,6 +97,7 @@ const char win_shader_glsl[] = GLSL(330,
|
||||
uniform bool invert_color;
|
||||
in vec2 texcoord;
|
||||
uniform sampler2D tex;
|
||||
uniform vec2 effective_size;
|
||||
uniform sampler2D brightness;
|
||||
uniform float max_brightness;
|
||||
// Signed distance field for rectangle center at (0, 0), with size of
|
||||
@@ -130,7 +131,7 @@ const char win_shader_glsl[] = GLSL(330,
|
||||
// Using mix() to avoid a branch here.
|
||||
vec4 rim_color = mix(c, border_color, clamp(border_width, 0.0f, 1.0f));
|
||||
|
||||
vec2 outer_size = vec2(textureSize(tex, 0));
|
||||
vec2 outer_size = effective_size;
|
||||
vec2 inner_size = outer_size - vec2(corner_radius) * 2.0f;
|
||||
float rect_distance = rectangle_sdf(texcoord - outer_size / 2.0f,
|
||||
inner_size / 2.0f) - corner_radius;
|
||||
@@ -157,7 +158,8 @@ const char win_shader_default[] = GLSL(330,
|
||||
uniform sampler2D tex;
|
||||
vec4 default_post_processing(vec4 c);
|
||||
vec4 window_shader() {
|
||||
vec4 c = texelFetch(tex, ivec2(texcoord), 0);
|
||||
vec2 texsize = textureSize(tex, 0);
|
||||
vec4 c = texture2D(tex, texcoord / texsize, 0);
|
||||
return default_post_processing(c);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "backend/backend.h"
|
||||
#include "backend/backend_common.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "config.h"
|
||||
#include "kernel.h"
|
||||
#include "log.h"
|
||||
@@ -56,6 +57,10 @@ typedef struct _xrender_data {
|
||||
int target_width, target_height;
|
||||
|
||||
xcb_special_event_t *present_event;
|
||||
|
||||
/// Cache an X region to avoid creating and destroying it every frame. A
|
||||
/// workaround for yshui/picom#1166.
|
||||
xcb_xfixes_region_t present_region;
|
||||
} xrender_data;
|
||||
|
||||
struct _xrender_blur_context {
|
||||
@@ -250,10 +255,16 @@ compose_impl(struct _xrender_data *xd, struct xrender_image *xrimg, coord_t dst,
|
||||
}
|
||||
if (((img->color_inverted || img->dim != 0) && has_alpha) || img->corner_radius != 0) {
|
||||
// Apply image properties using a temporary image, because the source
|
||||
// image is transparent. Otherwise the properties can be applied directly
|
||||
// on the target image.
|
||||
// image is transparent or will get transparent corners. Otherwise the
|
||||
// properties can be applied directly on the target image.
|
||||
// Also force a 32-bit ARGB visual for transparent corners, otherwise the
|
||||
// corners become black.
|
||||
auto visual =
|
||||
(img->corner_radius != 0 && inner->depth != 32)
|
||||
? x_get_visual_for_standard(xd->base.c, XCB_PICT_STANDARD_ARGB_32)
|
||||
: inner->visual;
|
||||
auto tmp_pict = x_create_picture_with_visual(
|
||||
xd->base.c, inner->width, inner->height, inner->visual, 0, NULL);
|
||||
xd->base.c, inner->width, inner->height, visual, 0, NULL);
|
||||
|
||||
// Set clip region translated to source coordinate
|
||||
x_set_picture_clip_region(xd->base.c, tmp_pict, to_i16_checked(-dst.x),
|
||||
@@ -349,10 +360,12 @@ compose_impl(struct _xrender_data *xd, struct xrender_image *xrimg, coord_t dst,
|
||||
pixman_region32_fini(®);
|
||||
}
|
||||
|
||||
static void compose(backend_t *base, void *img_data, coord_t dst, void *mask, coord_t mask_dst,
|
||||
const region_t *reg_paint, const region_t *reg_visible) {
|
||||
static void compose(backend_t *base, image_handle image_, coord_t dst, image_handle mask_,
|
||||
coord_t mask_dst, const region_t *reg_paint, const region_t *reg_visible, attr_unused bool lerp) {
|
||||
struct _xrender_data *xd = (void *)base;
|
||||
return compose_impl(xd, img_data, dst, mask, mask_dst, reg_paint, reg_visible,
|
||||
auto image = (struct xrender_image *)image_;
|
||||
auto mask = (struct xrender_image *)mask_;
|
||||
return compose_impl(xd, image, dst, mask, mask_dst, reg_paint, reg_visible,
|
||||
xd->back[2]);
|
||||
}
|
||||
|
||||
@@ -374,9 +387,10 @@ static void fill(backend_t *base, struct color c, const region_t *clip) {
|
||||
.height = to_u16_checked(extent->y2 - extent->y1)}});
|
||||
}
|
||||
|
||||
static bool blur(backend_t *backend_data, double opacity, void *ctx_, void *mask,
|
||||
static bool blur(backend_t *backend_data, double opacity, void *ctx_, image_handle mask_,
|
||||
coord_t mask_dst, const region_t *reg_blur, const region_t *reg_visible) {
|
||||
struct _xrender_blur_context *bctx = ctx_;
|
||||
auto bctx = (struct _xrender_blur_context *)ctx_;
|
||||
auto mask = (struct xrender_image *)mask_;
|
||||
if (bctx->method == BLUR_METHOD_NONE) {
|
||||
return true;
|
||||
}
|
||||
@@ -507,7 +521,7 @@ static bool blur(backend_t *backend_data, double opacity, void *ctx_, void *mask
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *
|
||||
static image_handle
|
||||
bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, bool owned) {
|
||||
xcb_generic_error_t *e;
|
||||
auto r = xcb_get_geometry_reply(base->c->c, xcb_get_geometry(base->c->c, pixmap), &e);
|
||||
@@ -542,7 +556,7 @@ bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, bool
|
||||
free(img);
|
||||
return NULL;
|
||||
}
|
||||
return img;
|
||||
return (image_handle)img;
|
||||
}
|
||||
static void release_image_inner(backend_t *base, struct _xrender_image_data_inner *inner) {
|
||||
x_free_picture(base->c, inner->pict);
|
||||
@@ -566,13 +580,13 @@ release_rounded_corner_cache(backend_t *base, struct xrender_rounded_rectangle_c
|
||||
}
|
||||
}
|
||||
|
||||
static void release_image(backend_t *base, void *image) {
|
||||
struct xrender_image *img = image;
|
||||
static void release_image(backend_t *base, image_handle image) {
|
||||
auto img = (struct xrender_image *)image;
|
||||
release_rounded_corner_cache(base, img->rounded_rectangle);
|
||||
img->rounded_rectangle = NULL;
|
||||
img->base.inner->refcount -= 1;
|
||||
if (img->base.inner->refcount == 0) {
|
||||
release_image_inner(base, (void *)img->base.inner);
|
||||
release_image_inner(base, (struct _xrender_image_data_inner *)img->base.inner);
|
||||
}
|
||||
free(img);
|
||||
}
|
||||
@@ -591,6 +605,7 @@ static void deinit(backend_t *backend_data) {
|
||||
xcb_free_pixmap(xd->base.c->c, xd->back_pixmap[i]);
|
||||
}
|
||||
}
|
||||
x_destroy_region(xd->base.c, xd->present_region);
|
||||
if (xd->present_event) {
|
||||
xcb_unregister_for_special_event(xd->base.c->c, xd->present_event);
|
||||
}
|
||||
@@ -618,16 +633,15 @@ static void present(backend_t *base, const region_t *region) {
|
||||
XCB_NONE, xd->back[xd->curr_back], orig_x, orig_y, 0,
|
||||
0, orig_x, orig_y, region_width, region_height);
|
||||
|
||||
auto xregion = x_create_region(base->c, region);
|
||||
|
||||
// Make sure we got reply from PresentPixmap before waiting for events,
|
||||
// to avoid deadlock
|
||||
auto e = xcb_request_check(
|
||||
base->c->c, xcb_present_pixmap_checked(
|
||||
xd->base.c->c, xd->target_win,
|
||||
xd->back_pixmap[xd->curr_back], 0, XCB_NONE, xregion, 0,
|
||||
0, XCB_NONE, XCB_NONE, XCB_NONE, 0, 0, 0, 0, 0, NULL));
|
||||
x_destroy_region(base->c, xregion);
|
||||
base->c->c,
|
||||
xcb_present_pixmap_checked(
|
||||
base->c->c, xd->target_win, xd->back_pixmap[xd->curr_back], 0, XCB_NONE,
|
||||
x_set_region(base->c, xd->present_region, region) ? xd->present_region
|
||||
: XCB_NONE,
|
||||
0, 0, XCB_NONE, XCB_NONE, XCB_NONE, 0, 0, 0, 0, 0, NULL));
|
||||
if (e) {
|
||||
log_error("Failed to present pixmap");
|
||||
free(e);
|
||||
@@ -701,7 +715,7 @@ new_inner(backend_t *base, int w, int h, xcb_visualid_t visual, uint8_t depth) {
|
||||
return new_inner;
|
||||
}
|
||||
|
||||
static void *make_mask(backend_t *base, geometry_t size, const region_t *reg) {
|
||||
static image_handle make_mask(backend_t *base, geometry_t size, const region_t *reg) {
|
||||
struct _xrender_data *xd = (void *)base;
|
||||
// Give the mask a 1 pixel wide border to emulate the clamp to border behavior of
|
||||
// OpenGL textures.
|
||||
@@ -744,7 +758,7 @@ static void *make_mask(backend_t *base, geometry_t size, const region_t *reg) {
|
||||
img->base.dim = 0;
|
||||
img->base.inner = (struct backend_image_inner_base *)inner;
|
||||
img->rounded_rectangle = NULL;
|
||||
return img;
|
||||
return (image_handle)img;
|
||||
}
|
||||
|
||||
static bool decouple_image(backend_t *base, struct backend_image *img, const region_t *reg) {
|
||||
@@ -772,10 +786,10 @@ static bool decouple_image(backend_t *base, struct backend_image *img, const reg
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool image_op(backend_t *base, enum image_operations op, void *image,
|
||||
static bool image_op(backend_t *base, enum image_operations op, image_handle image,
|
||||
const region_t *reg_op, const region_t *reg_visible, void *arg) {
|
||||
struct _xrender_data *xd = (void *)base;
|
||||
struct backend_image *img = image;
|
||||
auto img = (struct backend_image *)image;
|
||||
region_t reg;
|
||||
double *dargs = arg;
|
||||
|
||||
@@ -923,6 +937,10 @@ static backend_t *backend_xrender_init(session_t *ps, xcb_window_t target) {
|
||||
xd->vsync = false;
|
||||
}
|
||||
|
||||
if (xd->vsync) {
|
||||
xd->present_region = x_create_region(&ps->c, &ps->screen_reg);
|
||||
}
|
||||
|
||||
// We might need to do double buffering for vsync, and buffer 0 and 1 are for
|
||||
// double buffering.
|
||||
int first_buffer_index = xd->vsync ? 0 : 2;
|
||||
@@ -950,19 +968,19 @@ err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *clone_image(backend_t *base attr_unused, const void *image_data,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
image_handle clone_image(backend_t *base attr_unused, image_handle image,
|
||||
const region_t *reg_visible attr_unused) {
|
||||
auto new_img = ccalloc(1, struct xrender_image);
|
||||
*new_img = *(struct xrender_image *)image_data;
|
||||
*new_img = *(struct xrender_image *)image;
|
||||
new_img->base.inner->refcount++;
|
||||
if (new_img->rounded_rectangle) {
|
||||
new_img->rounded_rectangle->refcount++;
|
||||
}
|
||||
return new_img;
|
||||
return (image_handle)new_img;
|
||||
}
|
||||
|
||||
static bool
|
||||
set_image_property(backend_t *base, enum image_properties op, void *image, void *args) {
|
||||
static bool set_image_property(backend_t *base, enum image_properties op,
|
||||
image_handle image, void *args) {
|
||||
auto xrimg = (struct xrender_image *)image;
|
||||
if (op == IMAGE_PROPERTY_CORNER_RADIUS &&
|
||||
((double *)args)[0] != xrimg->base.corner_radius) {
|
||||
|
||||
13
src/c2.c
13
src/c2.c
@@ -1047,7 +1047,7 @@ static bool c2_l_postprocess(session_t *ps, c2_l_t *pleaf) {
|
||||
|
||||
// Get target atom if it's not a predefined one
|
||||
if (pleaf->predef == C2_L_PUNDEFINED) {
|
||||
pleaf->tgtatom = get_atom(ps->atoms, pleaf->tgt);
|
||||
pleaf->tgtatom = get_atom(ps->atoms, pleaf->tgt, ps->c.c);
|
||||
if (!pleaf->tgtatom) {
|
||||
log_error("Failed to get atom for target \"%s\".", pleaf->tgt);
|
||||
return false;
|
||||
@@ -1380,14 +1380,10 @@ static inline void c2_match_once_leaf(session_t *ps, const struct managed_win *w
|
||||
case C2_L_PWIDTHB: predef_target = w->widthb; break;
|
||||
case C2_L_PHEIGHTB: predef_target = w->heightb; break;
|
||||
case C2_L_PBDW: predef_target = w->g.border_width; break;
|
||||
case C2_L_PFULLSCREEN:
|
||||
predef_target = win_is_fullscreen(ps, w);
|
||||
break;
|
||||
case C2_L_PFULLSCREEN: predef_target = w->is_fullscreen; break;
|
||||
case C2_L_POVREDIR: predef_target = w->a.override_redirect; break;
|
||||
case C2_L_PARGB: predef_target = win_has_alpha(w); break;
|
||||
case C2_L_PFOCUSED:
|
||||
predef_target = win_is_focused_raw(ps, w);
|
||||
break;
|
||||
case C2_L_PFOCUSED: predef_target = win_is_focused_raw(w); break;
|
||||
case C2_L_PWMWIN: predef_target = w->wmwin; break;
|
||||
case C2_L_PBSHAPED: predef_target = w->bounding_shaped; break;
|
||||
case C2_L_PROUNDED: predef_target = w->rounded_corners; break;
|
||||
@@ -1513,7 +1509,8 @@ static inline void c2_match_once_leaf(session_t *ps, const struct managed_win *w
|
||||
else {
|
||||
char **strlst = NULL;
|
||||
int nstr = 0;
|
||||
if (wid_get_text_prop(ps, wid, pleaf->tgtatom, &strlst, &nstr)) {
|
||||
if (wid_get_text_prop(&ps->c, ps->atoms, wid, pleaf->tgtatom,
|
||||
&strlst, &nstr)) {
|
||||
if (pleaf->index < 0 && nstr > 0 && strlen(strlst[0]) > 0) {
|
||||
ntargets = to_u32_checked(nstr);
|
||||
targets = (const char **)strlst;
|
||||
|
||||
96
src/cache.c
96
src/cache.c
@@ -1,95 +1,43 @@
|
||||
#include <uthash.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "utils.h"
|
||||
#include "cache.h"
|
||||
|
||||
struct cache_entry {
|
||||
char *key;
|
||||
void *value;
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
|
||||
struct cache {
|
||||
cache_getter_t getter;
|
||||
cache_free_t free;
|
||||
void *user_data;
|
||||
struct cache_entry *entries;
|
||||
};
|
||||
|
||||
void cache_set(struct cache *c, const char *key, void *data) {
|
||||
struct cache_entry *e = NULL;
|
||||
struct cache_handle *cache_get(struct cache *c, const char *key) {
|
||||
struct cache_handle *e;
|
||||
HASH_FIND_STR(c->entries, key, e);
|
||||
CHECK(!e);
|
||||
|
||||
e = ccalloc(1, struct cache_entry);
|
||||
e->key = strdup(key);
|
||||
e->value = data;
|
||||
HASH_ADD_STR(c->entries, key, e);
|
||||
return e;
|
||||
}
|
||||
|
||||
void *cache_get(struct cache *c, const char *key, int *err) {
|
||||
struct cache_entry *e;
|
||||
HASH_FIND_STR(c->entries, key, e);
|
||||
if (e) {
|
||||
return e->value;
|
||||
int cache_get_or_fetch(struct cache *c, const char *key, struct cache_handle **value,
|
||||
void *user_data, cache_getter_t getter) {
|
||||
*value = cache_get(c, key);
|
||||
if (*value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tmperr;
|
||||
if (!err) {
|
||||
err = &tmperr;
|
||||
int err = getter(c, key, value, user_data);
|
||||
assert(err <= 0);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
(*value)->key = strdup(key);
|
||||
|
||||
*err = 0;
|
||||
e = ccalloc(1, struct cache_entry);
|
||||
e->key = strdup(key);
|
||||
e->value = c->getter(c->user_data, key, err);
|
||||
if (*err) {
|
||||
free(e->key);
|
||||
free(e);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HASH_ADD_STR(c->entries, key, e);
|
||||
return e->value;
|
||||
HASH_ADD_STR(c->entries, key, *value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline void _cache_invalidate(struct cache *c, struct cache_entry *e) {
|
||||
if (c->free) {
|
||||
c->free(c->user_data, e->value);
|
||||
}
|
||||
static inline void
|
||||
cache_invalidate_impl(struct cache *c, struct cache_handle *e, cache_free_t free_fn) {
|
||||
free(e->key);
|
||||
HASH_DEL(c->entries, e);
|
||||
free(e);
|
||||
}
|
||||
|
||||
void cache_invalidate(struct cache *c, const char *key) {
|
||||
struct cache_entry *e;
|
||||
HASH_FIND_STR(c->entries, key, e);
|
||||
|
||||
if (e) {
|
||||
_cache_invalidate(c, e);
|
||||
if (free_fn) {
|
||||
free_fn(c, e);
|
||||
}
|
||||
}
|
||||
|
||||
void cache_invalidate_all(struct cache *c) {
|
||||
struct cache_entry *e, *tmpe;
|
||||
void cache_invalidate_all(struct cache *c, cache_free_t free_fn) {
|
||||
struct cache_handle *e, *tmpe;
|
||||
HASH_ITER(hh, c->entries, e, tmpe) {
|
||||
_cache_invalidate(c, e);
|
||||
cache_invalidate_impl(c, e, free_fn);
|
||||
}
|
||||
}
|
||||
|
||||
void *cache_free(struct cache *c) {
|
||||
void *ret = c->user_data;
|
||||
cache_invalidate_all(c);
|
||||
free(c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct cache *new_cache(void *ud, cache_getter_t getter, cache_free_t f) {
|
||||
auto c = ccalloc(1, struct cache);
|
||||
c->user_data = ud;
|
||||
c->getter = getter;
|
||||
c->free = f;
|
||||
return c;
|
||||
}
|
||||
|
||||
57
src/cache.h
57
src/cache.h
@@ -1,32 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <uthash.h>
|
||||
#include "utils.h"
|
||||
|
||||
#define cache_entry(ptr, type, member) container_of(ptr, type, member)
|
||||
|
||||
struct cache;
|
||||
struct cache_handle;
|
||||
|
||||
typedef void *(*cache_getter_t)(void *user_data, const char *key, int *err);
|
||||
typedef void (*cache_free_t)(void *user_data, void *data);
|
||||
/// User-provided function to fetch a value for the cache, when it's not present.
|
||||
/// Should return 0 if the value is fetched successfully, and a negative number if the
|
||||
/// value cannot be fetched. Getter doesn't need to initialize fields of `struct
|
||||
/// cache_handle`.
|
||||
typedef int (*cache_getter_t)(struct cache *, const char *key,
|
||||
struct cache_handle **value, void *user_data);
|
||||
typedef void (*cache_free_t)(struct cache *, struct cache_handle *value);
|
||||
|
||||
/// Create a cache with `getter`, and a free function `f` which is used to free the cache
|
||||
/// value when they are invalidated.
|
||||
///
|
||||
/// `user_data` will be passed to `getter` and `f` when they are called.
|
||||
struct cache *new_cache(void *user_data, cache_getter_t getter, cache_free_t f);
|
||||
struct cache {
|
||||
struct cache_handle *entries;
|
||||
};
|
||||
|
||||
/// Fetch a value from the cache. If the value doesn't present in the cache yet, the
|
||||
static const struct cache CACHE_INIT = {NULL};
|
||||
|
||||
struct cache_handle {
|
||||
char *key;
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
|
||||
/// Get a value from the cache. If the value doesn't present in the cache yet, the
|
||||
/// getter will be called, and the returned value will be stored into the cache.
|
||||
void *cache_get(struct cache *, const char *key, int *err);
|
||||
/// Returns 0 if the value is already present in the cache, 1 if the value is fetched
|
||||
/// successfully, and a negative number if the value cannot be fetched.
|
||||
int cache_get_or_fetch(struct cache *, const char *key, struct cache_handle **value,
|
||||
void *user_data, cache_getter_t getter);
|
||||
|
||||
/// Invalidate a value in the cache.
|
||||
void cache_invalidate(struct cache *, const char *key);
|
||||
/// Get a value from the cache. If the value doesn't present in the cache, NULL will be
|
||||
/// returned.
|
||||
struct cache_handle *cache_get(struct cache *, const char *key);
|
||||
|
||||
/// Invalidate all values in the cache.
|
||||
void cache_invalidate_all(struct cache *);
|
||||
|
||||
/// Invalidate all values in the cache and free it. Returns the user data passed to
|
||||
/// `new_cache`
|
||||
void *cache_free(struct cache *);
|
||||
|
||||
/// Insert a key-value pair into the cache. Only used for internal testing. Takes
|
||||
/// ownership of `data`
|
||||
///
|
||||
/// If `key` already exists in the cache, this function will abort the program.
|
||||
void cache_set(struct cache *c, const char *key, void *data);
|
||||
/// Invalidate all values in the cache. After this call, `struct cache` holds no allocated
|
||||
/// memory, and can be discarded.
|
||||
void cache_invalidate_all(struct cache *, cache_free_t free_fn);
|
||||
|
||||
46
src/common.h
46
src/common.h
@@ -139,12 +139,15 @@ typedef struct session {
|
||||
// === Event handlers ===
|
||||
/// ev_io for X connection
|
||||
ev_io xiow;
|
||||
/// Timer for checking DPMS power level
|
||||
ev_timer dpms_check_timer;
|
||||
/// Timeout for delayed unredirection.
|
||||
ev_timer unredir_timer;
|
||||
/// Timer for fading
|
||||
ev_timer fade_timer;
|
||||
/// Timer for animations
|
||||
ev_timer animation_timer;
|
||||
/// Use an ev_idle callback for drawing
|
||||
/// So we only start drawing when events are processed
|
||||
ev_idle draw_idle;
|
||||
/// Use an ev_timer callback for drawing
|
||||
ev_timer draw_timer;
|
||||
/// Called every time we have timeouts or new data on socket,
|
||||
@@ -177,7 +180,6 @@ typedef struct session {
|
||||
bool server_grabbed;
|
||||
/// Width of root window.
|
||||
int root_width;
|
||||
/// Height of root window.
|
||||
int root_height;
|
||||
/// X Composite overlay window.
|
||||
xcb_window_t overlay;
|
||||
@@ -188,7 +190,7 @@ typedef struct session {
|
||||
/// Picture of the root window background.
|
||||
paint_t root_tile_paint;
|
||||
/// The backend data the root pixmap bound to
|
||||
void *root_image;
|
||||
image_handle root_image;
|
||||
/// A region of the size of the screen.
|
||||
region_t screen_reg;
|
||||
/// Picture of root window. Destination of painting in no-DBE painting
|
||||
@@ -206,7 +208,7 @@ typedef struct session {
|
||||
/// Custom GLX program used for painting window.
|
||||
// XXX should be in struct glx_session
|
||||
glx_prog_main_t glx_prog_win;
|
||||
struct glx_fbconfig_info *argb_fbconfig;
|
||||
struct glx_fbconfig_info argb_fbconfig;
|
||||
#endif
|
||||
/// Sync fence to sync draw operations
|
||||
xcb_sync_fence_t sync_fence;
|
||||
@@ -214,26 +216,19 @@ typedef struct session {
|
||||
bool first_frame;
|
||||
/// Whether screen has been turned off
|
||||
bool screen_is_off;
|
||||
/// Event context for X Present extension.
|
||||
uint32_t present_event_id;
|
||||
xcb_special_event_t *present_event;
|
||||
/// When last MSC event happened, in useconds.
|
||||
uint64_t last_msc_instant;
|
||||
/// The last MSC number
|
||||
uint64_t last_msc;
|
||||
/// When the currently rendered frame will be displayed.
|
||||
/// 0 means there is no pending frame.
|
||||
uint64_t target_msc;
|
||||
/// The delay between when the last frame was scheduled to be rendered, and when
|
||||
/// the render actually started.
|
||||
uint64_t last_schedule_delay;
|
||||
/// When do we want our next frame to start rendering.
|
||||
uint64_t next_render;
|
||||
/// Did we actually render the last frame. Sometimes redraw will be scheduled only
|
||||
/// to find out nothing has changed. In which case this will be set to false.
|
||||
bool did_render;
|
||||
/// Whether we can perform frame pacing.
|
||||
bool frame_pacing;
|
||||
/// Vblank event scheduler
|
||||
struct vblank_scheduler *vblank_scheduler;
|
||||
|
||||
/// Render statistics
|
||||
struct render_statistics render_stats;
|
||||
@@ -245,8 +240,18 @@ typedef struct session {
|
||||
options_t o;
|
||||
/// Whether we have hit unredirection timeout.
|
||||
bool tmout_unredir_hit;
|
||||
/// Whether we need to redraw the screen
|
||||
bool redraw_needed;
|
||||
/// If the backend is busy. This means two things:
|
||||
/// Either the backend is currently rendering a frame, or a frame has been
|
||||
/// rendered but has yet to be presented. In either case, we should not start
|
||||
/// another render right now. As if we start issuing rendering commands now, we
|
||||
/// will have to wait for either the current render to finish, or the current
|
||||
/// back buffer to become available again. In either case, we will be wasting
|
||||
/// time.
|
||||
bool backend_busy;
|
||||
/// Whether a render is queued. This generally means there are pending updates
|
||||
/// to the screen that's neither included in the current render, nor on the
|
||||
/// screen.
|
||||
bool render_queued;
|
||||
|
||||
/// Cache a xfixes region so we don't need to allocate it every time.
|
||||
/// A workaround for yshui/picom#301
|
||||
@@ -263,11 +268,18 @@ typedef struct session {
|
||||
xcb_render_picture_t *alpha_picts;
|
||||
/// Time of last fading. In milliseconds.
|
||||
long long fade_time;
|
||||
/// Time of last window animation step. In milliseconds.
|
||||
long animation_time; // TODO(dccsillag) turn into `long long`, like fade_time
|
||||
/// Head pointer of the error ignore linked list.
|
||||
pending_reply_t *pending_reply_head;
|
||||
/// Pointer to the <code>next</code> member of tail element of the error
|
||||
/// ignore linked list.
|
||||
pending_reply_t **pending_reply_tail;
|
||||
// Cached blur convolution kernels.
|
||||
struct x_convolution_kernel **blur_kerns_cache;
|
||||
/// If we should quit
|
||||
bool quit : 1;
|
||||
// TODO(yshui) use separate flags for dfferent kinds of updates so we don't
|
||||
// TODO(yshui) use separate flags for different kinds of updates so we don't
|
||||
// waste our time.
|
||||
/// Whether there are pending updates, like window creation, etc.
|
||||
bool pending_updates : 1;
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
#else
|
||||
# define attr_warn_unused_result
|
||||
#endif
|
||||
// An alias for conveninence
|
||||
// An alias for convenience
|
||||
#define must_use attr_warn_unused_result
|
||||
|
||||
#if __has_attribute(nonnull)
|
||||
@@ -105,9 +105,9 @@
|
||||
|
||||
#ifndef unreachable
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define unreachable() __builtin_unreachable()
|
||||
# define unreachable() assert(false); __builtin_unreachable()
|
||||
# else
|
||||
# define unreachable() do {} while(0)
|
||||
# define unreachable() assert(false); do {} while(0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
151
src/config.c
151
src/config.c
@@ -8,6 +8,8 @@
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -41,10 +43,7 @@ const char *xdg_config_home(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xdgh = cvalloc(strlen(home) + strlen(default_dir) + 1);
|
||||
|
||||
strcpy(xdgh, home);
|
||||
strcat(xdgh, default_dir);
|
||||
xdgh = mstrjoin(home, default_dir);
|
||||
} else {
|
||||
xdgh = strdup(xdgh);
|
||||
}
|
||||
@@ -561,7 +560,7 @@ static char *locate_auxiliary_file_at(const char *base, const char *scope, const
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a path of an auxiliary file to read, could be a shader file, or any supplimenrary
|
||||
* Get a path of an auxiliary file to read, could be a shader file, or any supplementary
|
||||
* file.
|
||||
*
|
||||
* Follows the XDG specification to search for the shader file in configuration locations.
|
||||
@@ -596,15 +595,17 @@ char *locate_auxiliary_file(const char *scope, const char *path, const char *inc
|
||||
// Fall back to searching in user config directory
|
||||
scoped_charp picom_scope = mstrjoin("/picom/", scope);
|
||||
scoped_charp config_home = (char *)xdg_config_home();
|
||||
char *ret = locate_auxiliary_file_at(config_home, picom_scope, path);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (config_home) {
|
||||
char *ret = locate_auxiliary_file_at(config_home, picom_scope, path);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to searching in system config directory
|
||||
auto config_dirs = xdg_config_dirs();
|
||||
for (int i = 0; config_dirs[i]; i++) {
|
||||
ret = locate_auxiliary_file_at(config_dirs[i], picom_scope, path);
|
||||
char *ret = locate_auxiliary_file_at(config_dirs[i], picom_scope, path);
|
||||
if (ret) {
|
||||
free(config_dirs);
|
||||
return ret;
|
||||
@@ -612,7 +613,83 @@ char *locate_auxiliary_file(const char *scope, const char *path, const char *inc
|
||||
}
|
||||
free(config_dirs);
|
||||
|
||||
return ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct debug_options_entry {
|
||||
const char *name;
|
||||
const char **choices;
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
const char *vblank_scheduler_str[] = {
|
||||
[VBLANK_SCHEDULER_PRESENT] = "present",
|
||||
[VBLANK_SCHEDULER_SGI_VIDEO_SYNC] = "sgi_video_sync",
|
||||
[LAST_VBLANK_SCHEDULER] = NULL
|
||||
};
|
||||
static const struct debug_options_entry debug_options_entries[] = {
|
||||
{"smart_frame_pacing", NULL, offsetof(struct debug_options, smart_frame_pacing)},
|
||||
{"force_vblank_sched", vblank_scheduler_str, offsetof(struct debug_options, force_vblank_scheduler)},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
void parse_debug_option_single(char *setting, struct debug_options *debug_options) {
|
||||
char *equal = strchr(setting, '=');
|
||||
size_t name_len = equal ? (size_t)(equal - setting) : strlen(setting);
|
||||
for (size_t i = 0; i < ARR_SIZE(debug_options_entries); i++) {
|
||||
if (strncmp(setting, debug_options_entries[i].name, name_len) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (debug_options_entries[i].name[name_len] != '\0') {
|
||||
continue;
|
||||
}
|
||||
auto value = (int *)((void *)debug_options + debug_options_entries[i].offset);
|
||||
if (equal) {
|
||||
const char *const arg = equal + 1;
|
||||
if (debug_options_entries[i].choices != NULL) {
|
||||
for (size_t j = 0; debug_options_entries[i].choices[j]; j++) {
|
||||
if (strcmp(arg, debug_options_entries[i].choices[j]) ==
|
||||
0) {
|
||||
*value = (int)j;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!parse_int(arg, value)) {
|
||||
log_error("Invalid value for debug option %s: %s, it "
|
||||
"will be ignored.",
|
||||
debug_options_entries[i].name, arg);
|
||||
}
|
||||
} else if (debug_options_entries[i].choices == NULL) {
|
||||
*value = 1;
|
||||
} else {
|
||||
log_error(
|
||||
"Missing value for debug option %s, it will be ignored.", setting);
|
||||
}
|
||||
return;
|
||||
}
|
||||
log_error("Invalid debug option: %s", setting);
|
||||
}
|
||||
|
||||
/// Parse debug options from environment variable `PICOM_DEBUG`.
|
||||
void parse_debug_options(struct debug_options *debug_options) {
|
||||
const char *debug = getenv("PICOM_DEBUG");
|
||||
const struct debug_options default_debug_options = {
|
||||
.force_vblank_scheduler = LAST_VBLANK_SCHEDULER,
|
||||
};
|
||||
|
||||
*debug_options = default_debug_options;
|
||||
if (!debug) {
|
||||
return;
|
||||
}
|
||||
|
||||
scoped_charp debug_copy = strdup(debug);
|
||||
char *tmp, *needle = strtok_r(debug_copy, ";", &tmp);
|
||||
while (needle) {
|
||||
parse_debug_option_single(needle, debug_options);
|
||||
needle = strtok_r(NULL, ";", &tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -719,6 +796,10 @@ void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_en
|
||||
// opacity logic is complicated, and needs an "unset" state
|
||||
opt->wintype_option[i].opacity = NAN;
|
||||
}
|
||||
if (!mask[i].animation) {
|
||||
mask[i].animation = OPEN_WINDOW_ANIMATION_INVALID;
|
||||
opt->wintype_option[i].animation = OPEN_WINDOW_ANIMATION_INVALID;
|
||||
}
|
||||
if (!mask[i].clip_shadow_above) {
|
||||
mask[i].clip_shadow_above = true;
|
||||
opt->wintype_option[i].clip_shadow_above = false;
|
||||
@@ -726,6 +807,40 @@ void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_en
|
||||
}
|
||||
}
|
||||
|
||||
enum open_window_animation parse_open_window_animation(const char *src) {
|
||||
if (strcmp(src, "none") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_NONE;
|
||||
} else if (strcmp(src, "fly-in") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_FLYIN;
|
||||
} else if (strcmp(src, "zoom") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_ZOOM;
|
||||
} else if (strcmp(src, "slide-up") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_UP;
|
||||
} else if (strcmp(src, "slide-down") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_DOWN;
|
||||
} else if (strcmp(src, "slide-left") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_LEFT;
|
||||
} else if (strcmp(src, "slide-right") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_RIGHT;
|
||||
} else if (strcmp(src, "slide-out") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_OUT;
|
||||
} else if (strcmp(src, "slide-in") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_IN;
|
||||
} else if (strcmp(src, "slide-out-center") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_OUT_CENTER;
|
||||
} else if (strcmp(src, "slide-in-center") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SLIDE_IN_CENTER;
|
||||
} else if (strcmp(src, "minimize") == 0 || strcmp(src, "maximize") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_MINIMIZE;
|
||||
} else if (strcmp(src, "squeeze") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SQUEEZE;
|
||||
} else if (strcmp(src, "squeeze-bottom") == 0) {
|
||||
return OPEN_WINDOW_ANIMATION_SQUEEZE_BOTTOM;
|
||||
}
|
||||
|
||||
return OPEN_WINDOW_ANIMATION_INVALID;
|
||||
}
|
||||
|
||||
char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
|
||||
bool *fading_enable, bool *hasneg, win_option_mask_t *winopt_mask) {
|
||||
// clang-format off
|
||||
@@ -771,6 +886,18 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
|
||||
.no_fading_destroyed_argb = false,
|
||||
.fade_blacklist = NULL,
|
||||
|
||||
.animations = false,
|
||||
.animation_for_open_window = OPEN_WINDOW_ANIMATION_NONE,
|
||||
.animation_for_transient_window = OPEN_WINDOW_ANIMATION_NONE,
|
||||
.animation_for_unmap_window = OPEN_WINDOW_ANIMATION_NONE,
|
||||
.animation_for_next_tag = OPEN_WINDOW_ANIMATION_NONE,
|
||||
.animation_for_prev_tag = OPEN_WINDOW_ANIMATION_NONE,
|
||||
.animation_stiffness = 200.0,
|
||||
.animation_stiffness_tag_change = 200.0,
|
||||
.animation_window_mass = 1.0,
|
||||
.animation_dampening = 25,
|
||||
.animation_clamping = true,
|
||||
|
||||
.inactive_opacity = 1.0,
|
||||
.inactive_opacity_override = false,
|
||||
.active_opacity = 1.0,
|
||||
@@ -802,7 +929,8 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
|
||||
|
||||
.track_leader = false,
|
||||
|
||||
.rounded_corners_blacklist = NULL
|
||||
.rounded_corners_blacklist = NULL,
|
||||
.animation_blacklist = NULL
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
@@ -817,5 +945,6 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
|
||||
(void)hasneg;
|
||||
(void)winopt_mask;
|
||||
#endif
|
||||
parse_debug_options(&opt->debug_options);
|
||||
return ret;
|
||||
}
|
||||
|
||||
80
src/config.h
80
src/config.h
@@ -40,6 +40,24 @@ enum backend {
|
||||
NUM_BKEND,
|
||||
};
|
||||
|
||||
enum open_window_animation {
|
||||
OPEN_WINDOW_ANIMATION_NONE = 0,
|
||||
OPEN_WINDOW_ANIMATION_FLYIN,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_UP,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_DOWN,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_LEFT,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_RIGHT,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_IN,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_OUT,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_IN_CENTER,
|
||||
OPEN_WINDOW_ANIMATION_SLIDE_OUT_CENTER,
|
||||
OPEN_WINDOW_ANIMATION_ZOOM,
|
||||
OPEN_WINDOW_ANIMATION_MINIMIZE,
|
||||
OPEN_WINDOW_ANIMATION_SQUEEZE,
|
||||
OPEN_WINDOW_ANIMATION_SQUEEZE_BOTTOM,
|
||||
OPEN_WINDOW_ANIMATION_INVALID,
|
||||
};
|
||||
|
||||
typedef struct win_option_mask {
|
||||
bool shadow : 1;
|
||||
bool fade : 1;
|
||||
@@ -49,6 +67,7 @@ typedef struct win_option_mask {
|
||||
bool redir_ignore : 1;
|
||||
bool opacity : 1;
|
||||
bool clip_shadow_above : 1;
|
||||
enum open_window_animation animation;
|
||||
} win_option_mask_t;
|
||||
|
||||
typedef struct win_option {
|
||||
@@ -60,6 +79,7 @@ typedef struct win_option {
|
||||
bool redir_ignore;
|
||||
double opacity;
|
||||
bool clip_shadow_above;
|
||||
enum open_window_animation animation;
|
||||
} win_option_t;
|
||||
|
||||
enum blur_method {
|
||||
@@ -73,6 +93,27 @@ enum blur_method {
|
||||
|
||||
typedef struct _c2_lptr c2_lptr_t;
|
||||
|
||||
enum vblank_scheduler_type {
|
||||
/// X Present extension based vblank events
|
||||
VBLANK_SCHEDULER_PRESENT,
|
||||
/// GLX_SGI_video_sync based vblank events
|
||||
VBLANK_SCHEDULER_SGI_VIDEO_SYNC,
|
||||
/// An invalid scheduler, served as a scheduler count, and
|
||||
/// as a sentinel value.
|
||||
LAST_VBLANK_SCHEDULER,
|
||||
};
|
||||
|
||||
extern const char *vblank_scheduler_str[];
|
||||
|
||||
/// Internal, private options for debugging and development use.
|
||||
struct debug_options {
|
||||
/// Try to reduce frame latency by using vblank interval and render time
|
||||
/// estimates. Right now it's not working well across drivers.
|
||||
int smart_frame_pacing;
|
||||
/// Override the vblank scheduler chosen by the compositor.
|
||||
int force_vblank_scheduler;
|
||||
};
|
||||
|
||||
/// Structure representing all options.
|
||||
typedef struct options {
|
||||
// === Debugging ===
|
||||
@@ -174,6 +215,33 @@ typedef struct options {
|
||||
/// Fading blacklist. A linked list of conditions.
|
||||
c2_lptr_t *fade_blacklist;
|
||||
|
||||
// === Animations ===
|
||||
/// Whether to do window animations
|
||||
bool animations;
|
||||
/// Which animation to run when opening a window
|
||||
enum open_window_animation animation_for_open_window;
|
||||
/// Which animation to run when opening a transient window
|
||||
enum open_window_animation animation_for_transient_window;
|
||||
/// Which animation to run when unmapping a window
|
||||
enum open_window_animation animation_for_unmap_window;
|
||||
/// Which animation to run when swapping to new tag
|
||||
enum open_window_animation animation_for_next_tag;
|
||||
/// Which animation to run for old tag
|
||||
enum open_window_animation animation_for_prev_tag;
|
||||
/// Spring stiffness for animation
|
||||
double animation_stiffness;
|
||||
/// Spring stiffness for current tag animation
|
||||
double animation_stiffness_tag_change;
|
||||
/// Window mass for animation
|
||||
double animation_window_mass;
|
||||
/// Animation dampening
|
||||
double animation_dampening;
|
||||
/// Whether to clamp animations
|
||||
bool animation_clamping;
|
||||
/// Animation blacklist. A linked list of conditions.
|
||||
c2_lptr_t *animation_blacklist;
|
||||
/// TODO: open/close animations
|
||||
|
||||
// === Opacity ===
|
||||
/// Default opacity for inactive windows.
|
||||
/// 32-bit integer with the format of _NET_WM_WINDOW_OPACITY.
|
||||
@@ -257,11 +325,20 @@ typedef struct options {
|
||||
// Make transparent windows clip other windows, instead of blending on top of
|
||||
// them
|
||||
bool transparent_clipping;
|
||||
|
||||
// Enable fading for next tag
|
||||
bool enable_fading_next_tag;
|
||||
|
||||
// Enable fading for prev tag
|
||||
bool enable_fading_prev_tag;
|
||||
|
||||
/// A list of conditions of windows to which transparent clipping
|
||||
/// should not apply
|
||||
c2_lptr_t *transparent_clipping_blacklist;
|
||||
|
||||
bool dithered_present;
|
||||
|
||||
struct debug_options debug_options;
|
||||
} options_t;
|
||||
|
||||
extern const char *const BACKEND_STRS[NUM_BKEND + 1];
|
||||
@@ -275,6 +352,7 @@ bool must_use parse_rule_window_shader(c2_lptr_t **, const char *, const char *)
|
||||
char *must_use locate_auxiliary_file(const char *scope, const char *path,
|
||||
const char *include_dir);
|
||||
enum blur_method must_use parse_blur_method(const char *src);
|
||||
enum open_window_animation must_use parse_open_window_animation(const char *src);
|
||||
|
||||
/**
|
||||
* Add a pattern to a condition linked list.
|
||||
@@ -288,7 +366,7 @@ char **xdg_config_dirs(void);
|
||||
/// Parse a configuration file
|
||||
/// Returns the actually config_file name used, allocated on heap
|
||||
/// Outputs:
|
||||
/// shadow_enable = whether shaodw is enabled globally
|
||||
/// shadow_enable = whether shadow is enabled globally
|
||||
/// fading_enable = whether fading is enabled globally
|
||||
/// win_option_mask = whether option overrides for specific window type is set for given
|
||||
/// options
|
||||
|
||||
@@ -81,17 +81,19 @@ FILE *open_config_file(const char *cpath, char **ppath) {
|
||||
|
||||
// First search for config file in user config directory
|
||||
auto config_home = xdg_config_home();
|
||||
auto ret = open_config_file_at(config_home, ppath);
|
||||
free((void *)config_home);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (config_home) {
|
||||
auto ret = open_config_file_at(config_home, ppath);
|
||||
free((void *)config_home);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to legacy config file in user home directory
|
||||
const char *home = getenv("HOME");
|
||||
if (home && strlen(home)) {
|
||||
auto path = mstrjoin(home, config_filename_legacy);
|
||||
ret = fopen(path, "r");
|
||||
auto ret = fopen(path, "r");
|
||||
if (ret && ppath) {
|
||||
*ppath = path;
|
||||
} else {
|
||||
@@ -105,7 +107,7 @@ FILE *open_config_file(const char *cpath, char **ppath) {
|
||||
// Fall back to config file in system config directory
|
||||
auto config_dirs = xdg_config_dirs();
|
||||
for (int i = 0; config_dirs[i]; i++) {
|
||||
ret = open_config_file_at(config_dirs[i], ppath);
|
||||
auto ret = open_config_file_at(config_dirs[i], ppath);
|
||||
if (ret) {
|
||||
free(config_dirs);
|
||||
return ret;
|
||||
@@ -262,6 +264,15 @@ static inline void parse_wintype_config(const config_t *cfg, const char *member_
|
||||
o->clip_shadow_above = ival;
|
||||
mask->clip_shadow_above = true;
|
||||
}
|
||||
const char *sval = NULL;
|
||||
if (config_setting_lookup_string(setting, "animation", &sval)) {
|
||||
enum open_window_animation animation = parse_open_window_animation(sval);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID)
|
||||
animation = OPEN_WINDOW_ANIMATION_NONE;
|
||||
|
||||
o->animation = animation;
|
||||
mask->animation = animation;
|
||||
}
|
||||
|
||||
double fval;
|
||||
if (config_setting_lookup_float(setting, "opacity", &fval)) {
|
||||
@@ -476,7 +487,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
||||
}
|
||||
// --sw-opti
|
||||
if (lcfg_lookup_bool(&cfg, "sw-opti", &bval)) {
|
||||
log_warn("The sw-opti %s", deprecation_message);
|
||||
log_error("The sw-opti %s", deprecation_message);
|
||||
goto err;
|
||||
}
|
||||
// --use-ewmh-active-win
|
||||
lcfg_lookup_bool(&cfg, "use-ewmh-active-win", &opt->use_ewmh_active_win);
|
||||
@@ -511,6 +523,70 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
||||
parse_cfg_condlst(&cfg, &opt->shadow_clip_list, "clip-shadow-above");
|
||||
// --fade-exclude
|
||||
parse_cfg_condlst(&cfg, &opt->fade_blacklist, "fade-exclude");
|
||||
// --animations
|
||||
lcfg_lookup_bool(&cfg, "animations", &opt->animations);
|
||||
// --animation-for-open-window
|
||||
if (config_lookup_string(&cfg, "animation-for-open-window", &sval)) {
|
||||
enum open_window_animation animation = parse_open_window_animation(sval);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_fatal("Invalid open-window animation %s", sval);
|
||||
goto err;
|
||||
}
|
||||
opt->animation_for_open_window = animation;
|
||||
}
|
||||
// --animation-for-transient-window
|
||||
if (config_lookup_string(&cfg, "animation-for-transient-window", &sval)) {
|
||||
enum open_window_animation animation = parse_open_window_animation(sval);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_fatal("Invalid open-window animation %s", sval);
|
||||
goto err;
|
||||
}
|
||||
opt->animation_for_transient_window = animation;
|
||||
}
|
||||
// --animation-for-unmap-window
|
||||
if (config_lookup_string(&cfg, "animation-for-unmap-window", &sval)) {
|
||||
enum open_window_animation animation = parse_open_window_animation(sval);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_fatal("Invalid unmap-window animation %s", sval);
|
||||
goto err;
|
||||
}
|
||||
opt->animation_for_unmap_window = animation;
|
||||
}
|
||||
// --animation-for-next-tag
|
||||
if (config_lookup_string(&cfg, "animation-for-next-tag", &sval)) {
|
||||
enum open_window_animation animation = parse_open_window_animation(sval);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_fatal("Invalid next-tag animation %s", sval);
|
||||
goto err;
|
||||
}
|
||||
opt->animation_for_next_tag = animation;
|
||||
}
|
||||
// --animation-for-prev-tag
|
||||
if (config_lookup_string(&cfg, "animation-for-prev-tag", &sval)) {
|
||||
enum open_window_animation animation = parse_open_window_animation(sval);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_fatal("Invalid prev-tag animation %s", sval);
|
||||
goto err;
|
||||
}
|
||||
opt->animation_for_prev_tag = animation;
|
||||
}
|
||||
// --animations-exclude
|
||||
parse_cfg_condlst(&cfg, &opt->animation_blacklist, "animation-exclude");
|
||||
|
||||
// --animation-stiffness
|
||||
config_lookup_float(&cfg, "animation-stiffness-in-tag", &opt->animation_stiffness);
|
||||
// --animation-stiffness-tag-change
|
||||
config_lookup_float(&cfg, "animation-stiffness-tag-change", &opt->animation_stiffness_tag_change);
|
||||
// --enable-fading-next-tag
|
||||
lcfg_lookup_bool(&cfg, "enable-fading-next-tag", &opt->enable_fading_next_tag);
|
||||
// --enable-fading-next-tag
|
||||
lcfg_lookup_bool(&cfg, "enable-fading-prev-tag", &opt->enable_fading_prev_tag);
|
||||
// --animation-window-mass
|
||||
config_lookup_float(&cfg, "animation-window-mass", &opt->animation_window_mass);
|
||||
// --animation-dampening
|
||||
config_lookup_float(&cfg, "animation-dampening", &opt->animation_dampening);
|
||||
// --animation-clamping
|
||||
lcfg_lookup_bool(&cfg, "animation-clamping", &opt->animation_clamping);
|
||||
// --focus-exclude
|
||||
parse_cfg_condlst(&cfg, &opt->focus_blacklist, "focus-exclude");
|
||||
// --invert-color-include
|
||||
|
||||
@@ -906,7 +906,7 @@ cdbus_process_window_property_get(session_t *ps, DBusMessage *msg, cdbus_window_
|
||||
}
|
||||
if (!strcmp("RawFocused", target)) {
|
||||
cdbus_reply(ps, msg, cdbus_append_bool_variant,
|
||||
(bool[]){win_is_focused_raw(ps, w)});
|
||||
(bool[]){win_is_focused_raw(w)});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -976,7 +976,7 @@ static bool cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
|
||||
cdbus_m_win_get_do(wmwin, cdbus_reply_bool);
|
||||
cdbus_m_win_get_do(leader, cdbus_reply_wid);
|
||||
if (!strcmp("focused_raw", target)) {
|
||||
cdbus_reply_bool(ps, msg, win_is_focused_raw(ps, w));
|
||||
cdbus_reply_bool(ps, msg, win_is_focused_raw(w));
|
||||
return true;
|
||||
}
|
||||
cdbus_m_win_get_do(fade_force, cdbus_reply_enum);
|
||||
|
||||
73
src/event.c
73
src/event.c
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2019, Yuxuan Shui <yshuiv7@gmail.com>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <X11/Xlibint.h>
|
||||
@@ -29,7 +30,7 @@
|
||||
/// made the query when those events were already in the queue. so the reply you got is
|
||||
/// more up-to-date than the events). Also, handling events when other client are making
|
||||
/// concurrent requests is not good. Because the server states are changing without you
|
||||
/// knowning them. This is super racy, and can cause lots of potential problems.
|
||||
/// knowing them. This is super racy, and can cause lots of potential problems.
|
||||
///
|
||||
/// All of above mandates we do these things:
|
||||
/// 1. Grab server when handling events
|
||||
@@ -47,8 +48,14 @@
|
||||
/// When top half finished, we enter the render stage, where no server state should be
|
||||
/// queried. All rendering should be done with our internal knowledge of the server state.
|
||||
///
|
||||
/// P.S. There is another reason to avoid sending any request to the server as much as
|
||||
/// possible. To make sure requests are sent, flushes are needed. And `xcb_flush`/`XFlush`
|
||||
/// functions may read more events from the server into their queues. This is
|
||||
/// undesirable, see the comments on `handle_queued_x_events` in picom.c for more details.
|
||||
|
||||
// TODO(yshui) the things described above
|
||||
// TODO(yshui) the things described above. This is mostly done, maybe some of
|
||||
// the functions here is still making unnecessary queries, we need
|
||||
// to do some auditing to be sure.
|
||||
|
||||
/**
|
||||
* Get a window's name from window ID.
|
||||
@@ -324,7 +331,7 @@ static inline void ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t
|
||||
}
|
||||
|
||||
if (ev->parent == ps->c.screen_info->root) {
|
||||
// X will generate reparent notifiy even if the parent didn't actually
|
||||
// X will generate reparent notify even if the parent didn't actually
|
||||
// change (i.e. reparent again to current parent). So we check if that's
|
||||
// the case
|
||||
auto w = find_win(ps, ev->window);
|
||||
@@ -350,19 +357,14 @@ static inline void ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t
|
||||
}
|
||||
|
||||
// Reset event mask in case something wrong happens
|
||||
xcb_change_window_attributes(
|
||||
ps->c.c, ev->window, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]){determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN)});
|
||||
uint32_t evmask = determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN);
|
||||
|
||||
if (!wid_has_prop(ps, ev->window, ps->atoms->aWM_STATE)) {
|
||||
log_debug("Window %#010x doesn't have WM_STATE property, it is "
|
||||
"probably not a client window. But we will listen for "
|
||||
"property change in case it gains one.",
|
||||
ev->window);
|
||||
xcb_change_window_attributes(
|
||||
ps->c.c, ev->window, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]){determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) |
|
||||
XCB_EVENT_MASK_PROPERTY_CHANGE});
|
||||
evmask |= XCB_EVENT_MASK_PROPERTY_CHANGE;
|
||||
} else {
|
||||
auto w_real_top = find_managed_window_or_parent(ps, ev->parent);
|
||||
if (w_real_top && w_real_top->state != WSTATE_UNMAPPED &&
|
||||
@@ -386,6 +388,8 @@ static inline void ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t
|
||||
}
|
||||
}
|
||||
}
|
||||
XCB_AWAIT_VOID(xcb_change_window_attributes, ps->c.c, ev->window,
|
||||
XCB_CW_EVENT_MASK, (const uint32_t[]){evmask});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,7 +469,7 @@ static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t
|
||||
}
|
||||
}
|
||||
|
||||
// Unconcerned about any other proprties on root window
|
||||
// Unconcerned about any other properties on root window
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -475,9 +479,10 @@ static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t
|
||||
// Check whether it could be a client window
|
||||
if (!find_toplevel(ps, ev->window)) {
|
||||
// Reset event mask anyway
|
||||
xcb_change_window_attributes(ps->c.c, ev->window, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]){determine_evmask(
|
||||
ps, ev->window, WIN_EVMODE_UNKNOWN)});
|
||||
const uint32_t evmask =
|
||||
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN);
|
||||
XCB_AWAIT_VOID(xcb_change_window_attributes, ps->c.c, ev->window,
|
||||
XCB_CW_EVENT_MASK, (const uint32_t[]){evmask});
|
||||
|
||||
auto w_top = find_managed_window_or_parent(ps, ev->window);
|
||||
// ev->window might have not been managed yet, in that case w_top
|
||||
@@ -492,14 +497,14 @@ static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t
|
||||
// If _NET_WM_WINDOW_TYPE changes... God knows why this would happen, but
|
||||
// there are always some stupid applications. (#144)
|
||||
if (ev->atom == ps->atoms->a_NET_WM_WINDOW_TYPE) {
|
||||
struct managed_win *w = NULL;
|
||||
if ((w = find_toplevel(ps, ev->window))) {
|
||||
struct managed_win *w = find_toplevel(ps, ev->window);
|
||||
if (w) {
|
||||
win_set_property_stale(w, ev->atom);
|
||||
}
|
||||
}
|
||||
|
||||
if (ev->atom == ps->atoms->a_NET_WM_BYPASS_COMPOSITOR) {
|
||||
// Unnecessay until we remove the queue_redraw in ev_handle
|
||||
// Unnecessary until we remove the queue_redraw in ev_handle
|
||||
queue_redraw(ps);
|
||||
}
|
||||
|
||||
@@ -560,6 +565,13 @@ static inline void ev_property_notify(session_t *ps, xcb_property_notify_event_t
|
||||
}
|
||||
}
|
||||
|
||||
if (!ps->o.no_ewmh_fullscreen && ev->atom == ps->atoms->a_NET_WM_STATE) {
|
||||
auto w = find_toplevel(ps, ev->window);
|
||||
if (w) {
|
||||
win_set_property_stale(w, ev->atom);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for other atoms we are tracking
|
||||
for (latom_t *platom = ps->track_atom_lst; platom; platom = platom->next) {
|
||||
if (platom->atom == ev->atom) {
|
||||
@@ -586,16 +598,28 @@ static inline void repair_win(session_t *ps, struct managed_win *w) {
|
||||
region_t parts;
|
||||
pixman_region32_init(&parts);
|
||||
|
||||
// If this is the first time this window is damaged, we would redraw the
|
||||
// whole window, so we don't need to fetch the damage region. But we still need
|
||||
// to make sure the X server receives the DamageSubtract request, hence the
|
||||
// `xcb_request_check` here.
|
||||
// Otherwise, we fetch the damage regions. That means we will receive a reply
|
||||
// from the X server, which implies it has received our DamageSubtract request.
|
||||
if (!w->ever_damaged) {
|
||||
win_extents(w, &parts);
|
||||
if (!ps->o.show_all_xerrors) {
|
||||
set_ignore_cookie(&ps->c, xcb_damage_subtract(ps->c.c, w->damage,
|
||||
XCB_NONE, XCB_NONE));
|
||||
auto e = xcb_request_check(
|
||||
ps->c.c, xcb_damage_subtract(ps->c.c, w->damage, XCB_NONE, XCB_NONE));
|
||||
if (e) {
|
||||
if (ps->o.show_all_xerrors) {
|
||||
x_print_error(e->sequence, e->major_code, e->minor_code,
|
||||
e->error_code);
|
||||
}
|
||||
free(e);
|
||||
}
|
||||
win_extents(w, &parts);
|
||||
} else {
|
||||
auto cookie =
|
||||
xcb_damage_subtract(ps->c.c, w->damage, XCB_NONE, ps->damaged_region);
|
||||
if (!ps->o.show_all_xerrors) {
|
||||
set_ignore_cookie(&ps->c, xcb_damage_subtract(ps->c.c, w->damage, XCB_NONE,
|
||||
ps->damaged_region));
|
||||
set_ignore_cookie(&ps->c, cookie);
|
||||
}
|
||||
x_fetch_region(&ps->c, ps->damaged_region, &parts);
|
||||
pixman_region32_translate(&parts, w->g.x + w->g.border_width,
|
||||
@@ -716,7 +740,8 @@ void ev_handle(session_t *ps, xcb_generic_event_t *ev) {
|
||||
// XXX redraw needs to be more fine grained
|
||||
queue_redraw(ps);
|
||||
|
||||
// the events sent from SendEvent will be ignored
|
||||
// We intentionally ignore events sent via SendEvent. Those events has the 8th bit
|
||||
// of response_type set, meaning they will match none of the cases below.
|
||||
switch (ev->response_type) {
|
||||
case FocusIn: ev_focus_in(ps, (xcb_focus_in_event_t *)ev); break;
|
||||
case FocusOut: ev_focus_out(ps, (xcb_focus_out_event_t *)ev); break;
|
||||
|
||||
@@ -158,7 +158,7 @@ bool file_watch_add(void *_fwr, const char *filename, file_watch_cb_t cb, void *
|
||||
fflags |= NOTE_CLOSE_WRITE;
|
||||
#else
|
||||
// NOTE_WRITE will receive notification more frequent than necessary, so is less
|
||||
// preferrable
|
||||
// preferable
|
||||
fflags |= NOTE_WRITE;
|
||||
#endif
|
||||
struct kevent ev = {
|
||||
|
||||
@@ -96,7 +96,7 @@ static inline double estimate_first_row_sum(double size, double r) {
|
||||
// `a` is gaussian at (size, 0)
|
||||
double a = exp(-0.5 * size * size / (r * r)) / sqrt(2 * M_PI) / r;
|
||||
// The sum of the whole kernel is normalized to 1, i.e. each element is divided by
|
||||
// factor sqaured. So the sum of the first row is a * factor / factor^2 = a /
|
||||
// factor squared. So the sum of the first row is a * factor / factor^2 = a /
|
||||
// factor
|
||||
return a / factor;
|
||||
}
|
||||
|
||||
13
src/list.h
13
src/list.h
@@ -2,18 +2,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const __typeof__(((type *)0)->member) *__mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
#include "utils.h"
|
||||
|
||||
struct list_node {
|
||||
struct list_node *next, *prev;
|
||||
|
||||
31
src/log.c
31
src/log.c
@@ -9,7 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
#include <GL/gl.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include "backend/gl/gl_common.h"
|
||||
#include "backend/gl/glx.h"
|
||||
#endif
|
||||
@@ -338,21 +338,14 @@ struct log_target *stderr_logger_new(void) {
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
/// An opengl logger that can be used for logging into opengl debugging tools,
|
||||
/// such as apitrace
|
||||
struct gl_string_marker_logger {
|
||||
struct log_target tgt;
|
||||
PFNGLSTRINGMARKERGREMEDYPROC gl_string_marker;
|
||||
};
|
||||
|
||||
static void
|
||||
gl_string_marker_logger_write(struct log_target *tgt, const char *str, size_t len) {
|
||||
auto g = (struct gl_string_marker_logger *)tgt;
|
||||
static void gl_string_marker_logger_write(struct log_target *tgt attr_unused,
|
||||
const char *str, size_t len) {
|
||||
// strip newlines at the end of the string
|
||||
while (len > 0 && str[len - 1] == '\n') {
|
||||
len--;
|
||||
}
|
||||
g->gl_string_marker((GLsizei)len, str);
|
||||
glStringMarkerGREMEDY((GLsizei)len, str);
|
||||
}
|
||||
|
||||
static const struct log_ops gl_string_marker_logger_ops = {
|
||||
@@ -361,20 +354,16 @@ static const struct log_ops gl_string_marker_logger_ops = {
|
||||
.destroy = logger_trivial_destroy,
|
||||
};
|
||||
|
||||
/// Create an opengl logger that can be used for logging into opengl debugging tools,
|
||||
/// such as apitrace
|
||||
struct log_target *gl_string_marker_logger_new(void) {
|
||||
if (!gl_has_extension("GL_GREMEDY_string_marker")) {
|
||||
if (!epoxy_has_gl_extension("GL_GREMEDY_string_marker")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *fnptr = glXGetProcAddress((GLubyte *)"glStringMarkerGREMEDY");
|
||||
if (!fnptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
auto ret = cmalloc(struct gl_string_marker_logger);
|
||||
ret->tgt.ops = &gl_string_marker_logger_ops;
|
||||
ret->gl_string_marker = fnptr;
|
||||
return &ret->tgt;
|
||||
auto ret = cmalloc(struct log_target);
|
||||
ret->ops = &gl_string_marker_logger_ops;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -9,7 +9,8 @@ base_deps = [
|
||||
|
||||
srcs = [ files('picom.c', 'win.c', 'c2.c', 'x.c', 'config.c', 'vsync.c', 'utils.c',
|
||||
'diagnostic.c', 'string_utils.c', 'render.c', 'kernel.c', 'log.c',
|
||||
'options.c', 'event.c', 'cache.c', 'atom.c', 'file_watch.c', 'statistics.c') ]
|
||||
'options.c', 'event.c', 'cache.c', 'atom.c', 'file_watch.c', 'statistics.c',
|
||||
'vblank.c') ]
|
||||
picom_inc = include_directories('.')
|
||||
|
||||
cflags = []
|
||||
@@ -22,7 +23,7 @@ required_xcb_packages = [
|
||||
# Some XCB packages are here because their versioning differs (see check below).
|
||||
required_packages = [
|
||||
'pixman-1', 'x11', 'x11-xcb', 'xcb-image', 'xcb-renderutil', 'xcb-util',
|
||||
'xext'
|
||||
'xext', 'threads',
|
||||
]
|
||||
|
||||
foreach i : required_packages
|
||||
@@ -57,8 +58,8 @@ if get_option('vsync_drm')
|
||||
endif
|
||||
|
||||
if get_option('opengl')
|
||||
cflags += ['-DCONFIG_OPENGL', '-DGL_GLEXT_PROTOTYPES']
|
||||
deps += [dependency('gl', required: true), dependency('egl', required: true)]
|
||||
cflags += ['-DCONFIG_OPENGL']
|
||||
deps += [dependency('epoxy', required: true)]
|
||||
srcs += [ 'opengl.c' ]
|
||||
endif
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ bool glx_init(session_t *ps, bool need_render) {
|
||||
// must precede FBConfig fetching
|
||||
if (need_render) {
|
||||
psglx->has_texture_non_power_of_two =
|
||||
gl_has_extension("GL_ARB_texture_non_power_of_two");
|
||||
epoxy_has_gl_extension("GL_ARB_texture_non_power_of_two");
|
||||
}
|
||||
|
||||
// Render preparations
|
||||
@@ -279,7 +279,7 @@ void glx_destroy(session_t *ps) {
|
||||
|
||||
free(ps->psglx);
|
||||
ps->psglx = NULL;
|
||||
ps->argb_fbconfig = NULL;
|
||||
ps->argb_fbconfig = (struct glx_fbconfig_info){0};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1129,7 +1129,7 @@ glx_blur_dst_end:
|
||||
// TODO(bhagwan) this is a mess and needs a more consistent way of getting the border
|
||||
// pixel I tried looking for a notify event for XCB_CW_BORDER_PIXEL (in
|
||||
// xcb_create_window()) or a way to get the pixels from xcb_render_picture_t but the
|
||||
// documentation for the xcb_xrender extension is literaly non existent...
|
||||
// documentation for the xcb_xrender extension is literally non existent...
|
||||
//
|
||||
// NOTE(yshui) There is no consistent way to get the "border" color of a X window. From
|
||||
// the WM's perspective there are multiple ways to implement window borders. Using
|
||||
|
||||
15
src/opengl.h
15
src/opengl.h
@@ -18,9 +18,9 @@
|
||||
#include "render.h"
|
||||
#include "win.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include <ctype.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <epoxy/glx.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -75,7 +75,7 @@ typedef struct glx_session {
|
||||
glx_round_pass_t *round_passes;
|
||||
} glx_session_t;
|
||||
|
||||
/// @brief Wrapper of a binded GLX texture.
|
||||
/// @brief Wrapper of a bound GLX texture.
|
||||
typedef struct _glx_texture {
|
||||
GLuint texture;
|
||||
GLXPixmap glpixmap;
|
||||
@@ -121,9 +121,9 @@ bool glx_bind_texture(session_t *ps, glx_texture_t **pptex, int x, int y, int wi
|
||||
void glx_paint_pre(session_t *ps, region_t *preg) attr_nonnull(1, 2);
|
||||
|
||||
/**
|
||||
* Check if a texture is binded, or is binded to the given pixmap.
|
||||
* Check if a texture is bound, or is bound to the given pixmap.
|
||||
*/
|
||||
static inline bool glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
||||
static inline bool glx_tex_bound(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
||||
return ptex && ptex->glpixmap && ptex->texture && (!pixmap || pixmap == ptex->pixmap);
|
||||
}
|
||||
|
||||
@@ -228,10 +228,7 @@ static inline void free_texture(session_t *ps, glx_texture_t **pptex) {
|
||||
*/
|
||||
static inline void free_paint_glx(session_t *ps, paint_t *ppaint) {
|
||||
free_texture(ps, &ppaint->ptex);
|
||||
#ifdef CONFIG_OPENGL
|
||||
free(ppaint->fbcfg);
|
||||
#endif
|
||||
ppaint->fbcfg = NULL;
|
||||
ppaint->fbcfg = (struct glx_fbconfig_info){0};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,6 +184,15 @@ static const struct picom_option picom_options[] = {
|
||||
"you want to attach a debugger to picom"},
|
||||
{"no-ewmh-fullscreen" , no_argument , 803, NULL , "Do not use EWMH to detect fullscreen windows. Reverts to checking if a "
|
||||
"window is fullscreen based only on its size and coordinates."},
|
||||
{"animations" ,no_argument , 804, NULL , "Enable/disable animations."},
|
||||
{"animation-stiffness-in-tag" , required_argument, 805, NULL , "Animation speed in current tag (float)."},
|
||||
{"animation-stiffness-tag-change", required_argument, 806, NULL , "Animation speed when tag changes (change to a new desktop)."},
|
||||
{"animation-dampening" , required_argument, 807, NULL , "Animation dampening ratio (spring dampening as an example)."},
|
||||
{"animation-window-mass" , required_argument, 808, NULL , "Animation window mass (lower mass makes animations bumpy)."},
|
||||
{"animation-clamping" , no_argument , 809, NULL , "Enable/disable animation clamping. Disabling increases performance"},
|
||||
{"animation-for-open-window" , required_argument, 810, NULL , "Set animation for opening window (Check sample.conf for options)."},
|
||||
{"animation-for-transient-window", required_argument, 811, NULL , "Set animation for transient (child) windows."},
|
||||
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
@@ -306,7 +315,7 @@ static void usage(const char *argv0, int ret) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char *shortopts = "D:I:O:r:o:m:l:t:i:e:hscnfFCazGb";
|
||||
static const char *shortopts = "D:I:O:r:o:m:l:t:i:e:hscnfCazGb";
|
||||
|
||||
/// Get config options that are needed to parse the rest of the options
|
||||
/// Return true if we should quit
|
||||
@@ -316,9 +325,9 @@ bool get_early_config(int argc, char *const *argv, char **config_file, bool *all
|
||||
|
||||
int o = 0, longopt_idx = -1;
|
||||
|
||||
// Pre-parse the commandline arguments to check for --config and invalid
|
||||
// Pre-parse the command line arguments to check for --config and invalid
|
||||
// switches
|
||||
// Must reset optind to 0 here in case we reread the commandline
|
||||
// Must reset optind to 0 here in case we reread the command line
|
||||
// arguments
|
||||
optind = 1;
|
||||
*config_file = NULL;
|
||||
@@ -370,7 +379,7 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||
// instead of commas in atof().
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
// Parse commandline arguments. Range checking will be done later.
|
||||
// Parse command line arguments. Range checking will be done later.
|
||||
|
||||
bool failed = false;
|
||||
const char *deprecation_message attr_unused =
|
||||
@@ -426,7 +435,6 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||
opt->wintype_option[WINTYPE_DROPDOWN_MENU].opacity = tmp;
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
fading_enable = true;
|
||||
break;
|
||||
P_CASEINT('r', shadow_radius);
|
||||
@@ -511,8 +519,9 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||
"--crop-shadow-to-monitor instead.");
|
||||
break;
|
||||
case 274:
|
||||
log_warn("--sw-opti has been deprecated, please remove it from the "
|
||||
log_error("--sw-opti has been deprecated, please remove it from the "
|
||||
"command line options");
|
||||
failed = true;
|
||||
break;
|
||||
case 275:
|
||||
// --vsync-aggressive
|
||||
@@ -523,9 +532,10 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||
P_CASEBOOL(276, use_ewmh_active_win);
|
||||
case 277:
|
||||
// --respect-prop-shadow
|
||||
log_warn("--respect-prop-shadow option has been deprecated, its "
|
||||
log_error("--respect-prop-shadow option has been deprecated, its "
|
||||
"functionality will always be enabled. Please remove it "
|
||||
"from the command line options");
|
||||
failed = true;
|
||||
break;
|
||||
P_CASEBOOL(278, unredir_if_possible);
|
||||
case 279:
|
||||
@@ -721,7 +731,7 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||
opt->blur_strength = atoi(optarg);
|
||||
break;
|
||||
case 333:
|
||||
// --cornor-radius
|
||||
// --corner-radius
|
||||
opt->corner_radius = atoi(optarg);
|
||||
break;
|
||||
case 334:
|
||||
@@ -750,6 +760,52 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
|
||||
break;
|
||||
P_CASEBOOL(802, debug_mode);
|
||||
P_CASEBOOL(803, no_ewmh_fullscreen);
|
||||
P_CASEBOOL(804, animations);
|
||||
case 805:
|
||||
// --animation-stiffness
|
||||
opt->animation_stiffness = atof(optarg);
|
||||
break;
|
||||
case 806:
|
||||
// --animation-stiffness-for-tags
|
||||
opt->animation_stiffness_tag_change = atof(optarg);
|
||||
break;
|
||||
case 807:
|
||||
// --animation-dampening
|
||||
opt->animation_dampening = atof(optarg);
|
||||
break;
|
||||
case 808:
|
||||
// --animation-window-masss
|
||||
opt->animation_window_mass = atof(optarg);
|
||||
break;
|
||||
case 809:
|
||||
// --animation-clamping
|
||||
opt->animation_clamping = true;
|
||||
break;
|
||||
case 810: {
|
||||
// --animation-for-open-window
|
||||
enum open_window_animation animation = parse_open_window_animation(optarg);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_warn("Invalid open-window animation %s, ignoring.", optarg);
|
||||
} else {
|
||||
opt->animation_for_open_window = animation;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 811: {
|
||||
// --animation-for-transient-window
|
||||
enum open_window_animation animation = parse_open_window_animation(optarg);
|
||||
if (animation >= OPEN_WINDOW_ANIMATION_INVALID) {
|
||||
log_warn("Invalid transient-window animation %s, ignoring.", optarg);
|
||||
} else {
|
||||
opt->animation_for_transient_window = animation;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 812: {
|
||||
// --animation-exclude
|
||||
condlst_add(&opt->animation_blacklist, optarg);
|
||||
break;
|
||||
}
|
||||
default: usage(argv[0], 1); break;
|
||||
#undef P_CASEBOOL
|
||||
}
|
||||
|
||||
1022
src/picom.c
1022
src/picom.c
File diff suppressed because it is too large
Load Diff
60
src/render.c
60
src/render.c
@@ -6,6 +6,7 @@
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/sync.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_image.h>
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
|
||||
@@ -55,19 +56,20 @@ static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, int wid, int h
|
||||
struct glx_fbconfig_info *fbcfg;
|
||||
if (!visual) {
|
||||
assert(depth == 32);
|
||||
if (!ps->argb_fbconfig) {
|
||||
ps->argb_fbconfig = glx_find_fbconfig(
|
||||
&ps->c, (struct xvisual_info){.red_size = 8,
|
||||
.green_size = 8,
|
||||
.blue_size = 8,
|
||||
.alpha_size = 8,
|
||||
.visual_depth = 32});
|
||||
if (!ps->argb_fbconfig.cfg) {
|
||||
glx_find_fbconfig(&ps->c,
|
||||
(struct xvisual_info){.red_size = 8,
|
||||
.green_size = 8,
|
||||
.blue_size = 8,
|
||||
.alpha_size = 8,
|
||||
.visual_depth = 32},
|
||||
&ps->argb_fbconfig);
|
||||
}
|
||||
if (!ps->argb_fbconfig) {
|
||||
if (!ps->argb_fbconfig.cfg) {
|
||||
log_error("Failed to find appropriate FBConfig for 32 bit depth");
|
||||
return false;
|
||||
}
|
||||
fbcfg = ps->argb_fbconfig;
|
||||
fbcfg = &ps->argb_fbconfig;
|
||||
} else {
|
||||
auto m = x_get_visual_info(&ps->c, visual);
|
||||
if (m.visual_depth < 0) {
|
||||
@@ -79,17 +81,17 @@ static inline bool paint_bind_tex(session_t *ps, paint_t *ppaint, int wid, int h
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ppaint->fbcfg) {
|
||||
ppaint->fbcfg = glx_find_fbconfig(&ps->c, m);
|
||||
if (!ppaint->fbcfg.cfg) {
|
||||
glx_find_fbconfig(&ps->c, m, &ppaint->fbcfg);
|
||||
}
|
||||
if (!ppaint->fbcfg) {
|
||||
if (!ppaint->fbcfg.cfg) {
|
||||
log_error("Failed to find appropriate FBConfig for X pixmap");
|
||||
return false;
|
||||
}
|
||||
fbcfg = ppaint->fbcfg;
|
||||
fbcfg = &ppaint->fbcfg;
|
||||
}
|
||||
|
||||
if (force || !glx_tex_binded(ppaint->ptex, ppaint->pixmap)) {
|
||||
if (force || !glx_tex_bound(ppaint->ptex, ppaint->pixmap)) {
|
||||
return glx_bind_pixmap(ps, &ppaint->ptex, ppaint->pixmap, wid, hei,
|
||||
repeat, fbcfg);
|
||||
}
|
||||
@@ -378,7 +380,7 @@ static inline bool paint_isvalid(session_t *ps, const paint_t *ppaint) {
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (BKEND_GLX == ps->o.backend && !glx_tex_binded(ppaint->ptex, XCB_NONE)) {
|
||||
if (BKEND_GLX == ps->o.backend && !glx_tex_bound(ppaint->ptex, XCB_NONE)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@@ -604,20 +606,27 @@ static bool get_root_tile(session_t *ps) {
|
||||
bool fill = false;
|
||||
xcb_pixmap_t pixmap = x_get_root_back_pixmap(&ps->c, ps->atoms);
|
||||
|
||||
// Make sure the pixmap we got is valid
|
||||
if (pixmap && !x_validate_pixmap(&ps->c, pixmap)) {
|
||||
pixmap = XCB_NONE;
|
||||
xcb_get_geometry_reply_t *r;
|
||||
if (pixmap) {
|
||||
r = xcb_get_geometry_reply(ps->c.c, xcb_get_geometry(ps->c.c, pixmap), NULL);
|
||||
}
|
||||
|
||||
// Create a pixmap if there isn't any
|
||||
if (!pixmap) {
|
||||
xcb_visualid_t visual;
|
||||
if (!pixmap || !r) {
|
||||
pixmap =
|
||||
x_create_pixmap(&ps->c, (uint8_t)ps->c.screen_info->root_depth, 1, 1);
|
||||
if (pixmap == XCB_NONE) {
|
||||
log_error("Failed to create pixmaps for root tile.");
|
||||
return false;
|
||||
}
|
||||
visual = ps->c.screen_info->root_visual;
|
||||
fill = true;
|
||||
} else {
|
||||
visual = r->depth == ps->c.screen_info->root_depth
|
||||
? ps->c.screen_info->root_visual
|
||||
: x_get_visual_for_depth(ps->c.screen_info, r->depth);
|
||||
free(r);
|
||||
}
|
||||
|
||||
// Create Picture
|
||||
@@ -625,7 +634,7 @@ static bool get_root_tile(session_t *ps) {
|
||||
.repeat = true,
|
||||
};
|
||||
ps->root_tile_paint.pict = x_create_picture_with_visual_and_pixmap(
|
||||
&ps->c, ps->c.screen_info->root_visual, pixmap, XCB_RENDER_CP_REPEAT, &pa);
|
||||
&ps->c, visual, pixmap, XCB_RENDER_CP_REPEAT, &pa);
|
||||
|
||||
// Fill pixmap if needed
|
||||
if (fill) {
|
||||
@@ -646,8 +655,7 @@ static bool get_root_tile(session_t *ps) {
|
||||
ps->root_tile_paint.pixmap = pixmap;
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (BKEND_GLX == ps->o.backend) {
|
||||
return paint_bind_tex(ps, &ps->root_tile_paint, 0, 0, true, 0,
|
||||
ps->c.screen_info->root_visual, false);
|
||||
return paint_bind_tex(ps, &ps->root_tile_paint, 0, 0, true, 0, visual, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1223,7 +1231,7 @@ void paint_all(session_t *ps, struct managed_win *t) {
|
||||
if (ps->o.vsync) {
|
||||
// Make sure all previous requests are processed to achieve best
|
||||
// effect
|
||||
x_sync(&ps->c);
|
||||
xcb_aux_sync(ps->c.c);
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (glx_has_context(ps)) {
|
||||
if (ps->o.vsync_use_glfinish) {
|
||||
@@ -1282,7 +1290,7 @@ void paint_all(session_t *ps, struct managed_win *t) {
|
||||
break;
|
||||
#ifdef CONFIG_OPENGL
|
||||
case BKEND_XR_GLX_HYBRID:
|
||||
x_sync(&ps->c);
|
||||
xcb_aux_sync(ps->c.c);
|
||||
if (ps->o.vsync_use_glfinish) {
|
||||
glFinish();
|
||||
} else {
|
||||
@@ -1307,7 +1315,7 @@ void paint_all(session_t *ps, struct managed_win *t) {
|
||||
default: assert(0);
|
||||
}
|
||||
|
||||
x_sync(&ps->c);
|
||||
xcb_aux_sync(ps->c.c);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (glx_has_context(ps)) {
|
||||
@@ -1522,7 +1530,7 @@ void deinit_render(session_t *ps) {
|
||||
free_root_tile(ps);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
free(ps->root_tile_paint.fbcfg);
|
||||
ps->root_tile_paint.fbcfg = (struct glx_fbconfig_info){0};
|
||||
if (bkend_use_glx(ps)) {
|
||||
glx_destroy(ps);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ typedef struct paint {
|
||||
xcb_render_picture_t pict;
|
||||
glx_texture_t *ptex;
|
||||
#ifdef CONFIG_OPENGL
|
||||
struct glx_fbconfig_info *fbcfg;
|
||||
struct glx_fbconfig_info fbcfg;
|
||||
#endif
|
||||
} paint_t;
|
||||
|
||||
|
||||
@@ -51,30 +51,15 @@ void render_statistics_add_render_time_sample(struct render_statistics *rs, int
|
||||
}
|
||||
|
||||
/// How much time budget we should give to the backend for rendering, in microseconds.
|
||||
///
|
||||
/// A `divisor` is also returned, indicating the target framerate. The divisor is
|
||||
/// the number of vblanks we should wait between each frame. A divisor of 1 means
|
||||
/// full framerate, 2 means half framerate, etc.
|
||||
unsigned int
|
||||
render_statistics_get_budget(struct render_statistics *rs, unsigned int *divisor) {
|
||||
unsigned int render_statistics_get_budget(struct render_statistics *rs) {
|
||||
if (rs->render_times.nelem < rs->render_times.window_size) {
|
||||
// No valid render time estimates yet. Assume maximum budget.
|
||||
*divisor = 1;
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
// N-th percentile of render times, see render_statistics_init for N.
|
||||
auto render_time_percentile =
|
||||
rolling_quantile_estimate(&rs->render_time_quantile, &rs->render_times);
|
||||
auto vblank_time_us = render_statistics_get_vblank_time(rs);
|
||||
if (vblank_time_us == 0) {
|
||||
// We don't have a good estimate of the vblank time yet, so we
|
||||
// assume we can finish in one vblank.
|
||||
*divisor = 1;
|
||||
} else {
|
||||
*divisor =
|
||||
(unsigned int)(render_time_percentile / rs->vblank_time_us.mean + 1);
|
||||
}
|
||||
return (unsigned int)render_time_percentile;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,8 @@ void render_statistics_add_vblank_time_sample(struct render_statistics *rs, int
|
||||
void render_statistics_add_render_time_sample(struct render_statistics *rs, int time_us);
|
||||
|
||||
/// How much time budget we should give to the backend for rendering, in microseconds.
|
||||
///
|
||||
/// A `divisor` is also returned, indicating the target framerate. The divisor is
|
||||
/// the number of vblanks we should wait between each frame. A divisor of 1 means
|
||||
/// full framerate, 2 means half framerate, etc.
|
||||
unsigned int
|
||||
render_statistics_get_budget(struct render_statistics *rs, unsigned int *divisor);
|
||||
unsigned int render_statistics_get_budget(struct render_statistics *rs);
|
||||
|
||||
/// Return the measured vblank interval in microseconds. Returns 0 if not enough
|
||||
/// samples have been collected yet.
|
||||
unsigned int render_statistics_get_vblank_time(struct render_statistics *rs);
|
||||
|
||||
@@ -141,10 +141,10 @@ void rolling_max_pop_front(struct rolling_max *rm, int front) {
|
||||
}
|
||||
|
||||
void rolling_max_push_back(struct rolling_max *rm, int val) {
|
||||
// Update the prority queue.
|
||||
// Update the priority queue.
|
||||
// Remove all elements smaller than the new element from the queue. Because
|
||||
// the new element will become the maximum element before them, and since they
|
||||
// come b1efore the new element, they will have been popped before the new
|
||||
// come before the new element, they will have been popped before the new
|
||||
// element, so they will never become the maximum element.
|
||||
while (rm->np) {
|
||||
int p_tail = IDX(rm->p_head + rm->np - 1);
|
||||
|
||||
65
src/utils.h
65
src/utils.h
@@ -21,6 +21,7 @@
|
||||
#include "types.h"
|
||||
|
||||
#define ARR_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#define CLEAR_MASK(x) x = 0;
|
||||
|
||||
#ifdef __FAST_MATH__
|
||||
#warning Use of -ffast-math can cause rendering error or artifacts, \
|
||||
@@ -58,11 +59,11 @@ safe_isnan(double a) {
|
||||
/// being always true or false.
|
||||
#define ASSERT_IN_RANGE(var, lower, upper) \
|
||||
do { \
|
||||
auto __tmp attr_unused = (var); \
|
||||
auto __assert_in_range_tmp attr_unused = (var); \
|
||||
_Pragma("GCC diagnostic push"); \
|
||||
_Pragma("GCC diagnostic ignored \"-Wtype-limits\""); \
|
||||
assert(__tmp >= lower); \
|
||||
assert(__tmp <= upper); \
|
||||
assert(__assert_in_range_tmp >= lower); \
|
||||
assert(__assert_in_range_tmp <= upper); \
|
||||
_Pragma("GCC diagnostic pop"); \
|
||||
} while (0)
|
||||
|
||||
@@ -112,11 +113,26 @@ safe_isnan(double a) {
|
||||
#define to_u32_checked(val) \
|
||||
({ \
|
||||
auto __to_tmp = (val); \
|
||||
int64_t max attr_unused = UINT32_MAX; /* silence clang tautological \
|
||||
comparison warning*/ \
|
||||
ASSERT_IN_RANGE(__to_tmp, 0, max); \
|
||||
int64_t __to_u32_max attr_unused = UINT32_MAX; /* silence clang \
|
||||
tautological \
|
||||
comparison warning */ \
|
||||
ASSERT_IN_RANGE(__to_tmp, 0, __to_u32_max); \
|
||||
(uint32_t) __to_tmp; \
|
||||
})
|
||||
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const __typeof__(((type *)0)->member) *__mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
|
||||
/**
|
||||
* Normalize an int value to a specific range.
|
||||
*
|
||||
@@ -125,14 +141,35 @@ safe_isnan(double a) {
|
||||
* @param max maximum value
|
||||
* @return normalized value
|
||||
*/
|
||||
static inline int attr_const normalize_i_range(int i, int min, int max) {
|
||||
if (i > max)
|
||||
static inline int attr_const attr_unused normalize_i_range(int i, int min, int max) {
|
||||
if (i > max) {
|
||||
return max;
|
||||
if (i < min)
|
||||
}
|
||||
if (i < min) {
|
||||
return min;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linearly interpolate from a range into another.
|
||||
*
|
||||
* @param a,b first range
|
||||
* @param c,d second range
|
||||
* @param value value to interpolate, should be in range [a,b]
|
||||
* @return interpolated value in range [c,d]
|
||||
*/
|
||||
static inline int attr_const lerp_range(int a, int b, int c, int d, int value) {
|
||||
ASSERT_IN_RANGE(value, a, b);
|
||||
return (d-c)*(value-a)/(b-a) + c;
|
||||
}
|
||||
|
||||
/// Generic integer abs()
|
||||
#define iabs(val) \
|
||||
({ \
|
||||
__auto_type __tmp = (val); \
|
||||
__tmp > 0 ? __tmp : -__tmp; \
|
||||
})
|
||||
#define min2(a, b) ((a) > (b) ? (b) : (a))
|
||||
#define max2(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define min3(a, b, c) min2(a, min2(b, c))
|
||||
@@ -149,10 +186,12 @@ static inline int attr_const normalize_i_range(int i, int min, int max) {
|
||||
* @return normalized value
|
||||
*/
|
||||
static inline double attr_const normalize_d_range(double d, double min, double max) {
|
||||
if (d > max)
|
||||
if (d > max) {
|
||||
return max;
|
||||
if (d < min)
|
||||
}
|
||||
if (d < min) {
|
||||
return min;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -162,7 +201,7 @@ static inline double attr_const normalize_d_range(double d, double min, double m
|
||||
* @param d double value to normalize
|
||||
* @return normalized value
|
||||
*/
|
||||
static inline double attr_const normalize_d(double d) {
|
||||
static inline double attr_const attr_unused normalize_d(double d) {
|
||||
return normalize_d_range(d, 0.0, 1.0);
|
||||
}
|
||||
|
||||
@@ -212,7 +251,7 @@ allocchk_(const char *func_name, const char *file, unsigned int line, void *ptr)
|
||||
((type *)allocchk(calloc((size_t)tmp, sizeof(type)))); \
|
||||
})
|
||||
|
||||
/// @brief Wrapper of ealloc().
|
||||
/// @brief Wrapper of realloc().
|
||||
#define crealloc(ptr, nmemb) \
|
||||
({ \
|
||||
auto tmp = (nmemb); \
|
||||
|
||||
569
src/vblank.c
Normal file
569
src/vblank.c
Normal file
@@ -0,0 +1,569 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <ev.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdatomic.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xproto.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
// Enable sgi_video_sync_vblank_scheduler
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <epoxy/glx.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "compiler.h"
|
||||
#include "list.h" // for container_of
|
||||
#include "log.h"
|
||||
#include "vblank.h"
|
||||
#include "x.h"
|
||||
|
||||
struct vblank_closure {
|
||||
vblank_callback_t fn;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
#define VBLANK_WIND_DOWN 4
|
||||
|
||||
struct vblank_scheduler {
|
||||
struct x_connection *c;
|
||||
size_t callback_capacity, callback_count;
|
||||
struct vblank_closure *callbacks;
|
||||
struct ev_loop *loop;
|
||||
/// Request extra vblank events even when no callbacks are scheduled.
|
||||
/// This is because when callbacks are scheduled too close to a vblank,
|
||||
/// we might send PresentNotifyMsc request too late and miss the vblank event.
|
||||
/// So we request extra vblank events right after the last vblank event
|
||||
/// to make sure this doesn't happen.
|
||||
unsigned int wind_down;
|
||||
xcb_window_t target_window;
|
||||
enum vblank_scheduler_type type;
|
||||
bool vblank_event_requested;
|
||||
};
|
||||
|
||||
struct present_vblank_scheduler {
|
||||
struct vblank_scheduler base;
|
||||
|
||||
uint64_t last_msc;
|
||||
/// The timestamp for the end of last vblank.
|
||||
uint64_t last_ust;
|
||||
ev_timer callback_timer;
|
||||
xcb_present_event_t event_id;
|
||||
xcb_special_event_t *event;
|
||||
};
|
||||
|
||||
struct vblank_scheduler_ops {
|
||||
size_t size;
|
||||
bool (*init)(struct vblank_scheduler *self);
|
||||
void (*deinit)(struct vblank_scheduler *self);
|
||||
bool (*schedule)(struct vblank_scheduler *self);
|
||||
bool (*handle_x_events)(struct vblank_scheduler *self);
|
||||
};
|
||||
|
||||
static void
|
||||
vblank_scheduler_invoke_callbacks(struct vblank_scheduler *self, struct vblank_event *event);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
struct sgi_video_sync_vblank_scheduler {
|
||||
struct vblank_scheduler base;
|
||||
|
||||
// Since glXWaitVideoSyncSGI blocks, we need to run it in a separate thread.
|
||||
// ... and all the thread shenanigans that come with it.
|
||||
_Atomic unsigned int current_msc;
|
||||
_Atomic uint64_t current_ust;
|
||||
ev_async notify;
|
||||
pthread_t sync_thread;
|
||||
bool running, error;
|
||||
unsigned int last_msc;
|
||||
|
||||
/// Protects `running`, and `base.vblank_event_requested`
|
||||
pthread_mutex_t vblank_requested_mtx;
|
||||
pthread_cond_t vblank_requested_cnd;
|
||||
};
|
||||
|
||||
struct sgi_video_sync_thread_args {
|
||||
struct sgi_video_sync_vblank_scheduler *self;
|
||||
int start_status;
|
||||
pthread_mutex_t start_mtx;
|
||||
pthread_cond_t start_cnd;
|
||||
};
|
||||
|
||||
static bool check_sgi_video_sync_extension(Display *dpy, int screen) {
|
||||
const char *glx_ext = glXQueryExtensionsString(dpy, screen);
|
||||
const char *needle = "GLX_SGI_video_sync";
|
||||
char *found = strstr(glx_ext, needle);
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
if (found != glx_ext && found[-1] != ' ') {
|
||||
return false;
|
||||
}
|
||||
if (found[strlen(needle)] != ' ' && found[strlen(needle)] != '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *sgi_video_sync_thread(void *data) {
|
||||
auto args = (struct sgi_video_sync_thread_args *)data;
|
||||
auto self = args->self;
|
||||
Display *dpy = XOpenDisplay(NULL);
|
||||
int error_code = 0;
|
||||
if (!dpy) {
|
||||
error_code = 1;
|
||||
goto start_failed;
|
||||
}
|
||||
Window root = DefaultRootWindow(dpy), dummy = None;
|
||||
int screen = DefaultScreen(dpy);
|
||||
int ncfg = 0;
|
||||
GLXFBConfig *cfg_ = glXChooseFBConfig(
|
||||
dpy, screen,
|
||||
(int[]){GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0},
|
||||
&ncfg);
|
||||
GLXContext ctx = NULL;
|
||||
GLXDrawable drawable = None;
|
||||
|
||||
if (!cfg_) {
|
||||
error_code = 2;
|
||||
goto start_failed;
|
||||
}
|
||||
GLXFBConfig cfg = cfg_[0];
|
||||
XFree(cfg_);
|
||||
|
||||
XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, cfg);
|
||||
if (!vi) {
|
||||
error_code = 3;
|
||||
goto start_failed;
|
||||
}
|
||||
|
||||
Visual *visual = vi->visual;
|
||||
const int depth = vi->depth;
|
||||
XFree(vi);
|
||||
|
||||
Colormap colormap = XCreateColormap(dpy, root, visual, AllocNone);
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.colormap = colormap;
|
||||
|
||||
dummy = XCreateWindow(dpy, root, 0, 0, 1, 1, 0, depth, InputOutput, visual,
|
||||
CWColormap, &attributes);
|
||||
XFreeColormap(dpy, colormap);
|
||||
if (dummy == None) {
|
||||
error_code = 4;
|
||||
goto start_failed;
|
||||
}
|
||||
|
||||
drawable = glXCreateWindow(dpy, cfg, dummy, NULL);
|
||||
if (drawable == None) {
|
||||
error_code = 5;
|
||||
goto start_failed;
|
||||
}
|
||||
|
||||
ctx = glXCreateNewContext(dpy, cfg, GLX_RGBA_TYPE, 0, true);
|
||||
if (ctx == NULL) {
|
||||
error_code = 6;
|
||||
goto start_failed;
|
||||
}
|
||||
|
||||
if (!glXMakeContextCurrent(dpy, drawable, drawable, ctx)) {
|
||||
error_code = 7;
|
||||
goto start_failed;
|
||||
}
|
||||
|
||||
if (!check_sgi_video_sync_extension(dpy, screen)) {
|
||||
error_code = 8;
|
||||
goto start_failed;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&args->start_mtx);
|
||||
args->start_status = 0;
|
||||
pthread_cond_signal(&args->start_cnd);
|
||||
pthread_mutex_unlock(&args->start_mtx);
|
||||
|
||||
pthread_mutex_lock(&self->vblank_requested_mtx);
|
||||
while (self->running) {
|
||||
if (!self->base.vblank_event_requested) {
|
||||
pthread_cond_wait(&self->vblank_requested_cnd,
|
||||
&self->vblank_requested_mtx);
|
||||
continue;
|
||||
}
|
||||
pthread_mutex_unlock(&self->vblank_requested_mtx);
|
||||
|
||||
unsigned int last_msc;
|
||||
glXWaitVideoSyncSGI(1, 0, &last_msc);
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
atomic_store(&self->current_msc, last_msc);
|
||||
atomic_store(&self->current_ust,
|
||||
(uint64_t)(now.tv_sec * 1000000 + now.tv_nsec / 1000));
|
||||
ev_async_send(self->base.loop, &self->notify);
|
||||
pthread_mutex_lock(&self->vblank_requested_mtx);
|
||||
}
|
||||
pthread_mutex_unlock(&self->vblank_requested_mtx);
|
||||
goto cleanup;
|
||||
|
||||
start_failed:
|
||||
pthread_mutex_lock(&args->start_mtx);
|
||||
args->start_status = error_code;
|
||||
pthread_cond_signal(&args->start_cnd);
|
||||
pthread_mutex_unlock(&args->start_mtx);
|
||||
|
||||
cleanup:
|
||||
if (dpy) {
|
||||
glXMakeCurrent(dpy, None, NULL);
|
||||
if (ctx) {
|
||||
glXDestroyContext(dpy, ctx);
|
||||
}
|
||||
if (drawable) {
|
||||
glXDestroyWindow(dpy, drawable);
|
||||
}
|
||||
if (dummy) {
|
||||
XDestroyWindow(dpy, dummy);
|
||||
}
|
||||
XCloseDisplay(dpy);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool sgi_video_sync_scheduler_schedule(struct vblank_scheduler *base) {
|
||||
auto self = (struct sgi_video_sync_vblank_scheduler *)base;
|
||||
if (self->error) {
|
||||
return false;
|
||||
}
|
||||
log_verbose("Requesting vblank event for msc %d", self->current_msc + 1);
|
||||
pthread_mutex_lock(&self->vblank_requested_mtx);
|
||||
assert(!base->vblank_event_requested);
|
||||
base->vblank_event_requested = true;
|
||||
pthread_cond_signal(&self->vblank_requested_cnd);
|
||||
pthread_mutex_unlock(&self->vblank_requested_mtx);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
sgi_video_sync_scheduler_callback(EV_P attr_unused, ev_async *w, int attr_unused revents);
|
||||
|
||||
static bool sgi_video_sync_scheduler_init(struct vblank_scheduler *base) {
|
||||
auto self = (struct sgi_video_sync_vblank_scheduler *)base;
|
||||
auto args = (struct sgi_video_sync_thread_args){
|
||||
.self = self,
|
||||
.start_status = -1,
|
||||
};
|
||||
bool succeeded = true;
|
||||
pthread_mutex_init(&args.start_mtx, NULL);
|
||||
pthread_cond_init(&args.start_cnd, NULL);
|
||||
|
||||
base->type = VBLANK_SCHEDULER_SGI_VIDEO_SYNC;
|
||||
ev_async_init(&self->notify, sgi_video_sync_scheduler_callback);
|
||||
ev_async_start(base->loop, &self->notify);
|
||||
pthread_mutex_init(&self->vblank_requested_mtx, NULL);
|
||||
pthread_cond_init(&self->vblank_requested_cnd, NULL);
|
||||
|
||||
self->running = true;
|
||||
pthread_create(&self->sync_thread, NULL, sgi_video_sync_thread, &args);
|
||||
|
||||
pthread_mutex_lock(&args.start_mtx);
|
||||
while (args.start_status == -1) {
|
||||
pthread_cond_wait(&args.start_cnd, &args.start_mtx);
|
||||
}
|
||||
if (args.start_status != 0) {
|
||||
log_fatal("Failed to start sgi_video_sync_thread, error code: %d",
|
||||
args.start_status);
|
||||
succeeded = false;
|
||||
} else {
|
||||
log_info("Started sgi_video_sync_thread");
|
||||
}
|
||||
self->error = !succeeded;
|
||||
self->last_msc = 0;
|
||||
pthread_mutex_destroy(&args.start_mtx);
|
||||
pthread_cond_destroy(&args.start_cnd);
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
static void sgi_video_sync_scheduler_deinit(struct vblank_scheduler *base) {
|
||||
auto self = (struct sgi_video_sync_vblank_scheduler *)base;
|
||||
ev_async_stop(base->loop, &self->notify);
|
||||
pthread_mutex_lock(&self->vblank_requested_mtx);
|
||||
self->running = false;
|
||||
pthread_cond_signal(&self->vblank_requested_cnd);
|
||||
pthread_mutex_unlock(&self->vblank_requested_mtx);
|
||||
|
||||
pthread_join(self->sync_thread, NULL);
|
||||
|
||||
pthread_mutex_destroy(&self->vblank_requested_mtx);
|
||||
pthread_cond_destroy(&self->vblank_requested_cnd);
|
||||
}
|
||||
|
||||
static void
|
||||
sgi_video_sync_scheduler_callback(EV_P attr_unused, ev_async *w, int attr_unused revents) {
|
||||
auto sched = container_of(w, struct sgi_video_sync_vblank_scheduler, notify);
|
||||
auto msc = atomic_load(&sched->current_msc);
|
||||
if (sched->last_msc == msc) {
|
||||
// NVIDIA spams us with duplicate vblank events after a suspend/resume
|
||||
// cycle. Recreating the X connection and GLX context seems to fix this.
|
||||
// Oh NVIDIA.
|
||||
log_warn("Duplicate vblank event found with msc %d. Possible NVIDIA bug?", msc);
|
||||
log_warn("Resetting the vblank scheduler");
|
||||
sgi_video_sync_scheduler_deinit(&sched->base);
|
||||
sched->base.vblank_event_requested = false;
|
||||
if (!sgi_video_sync_scheduler_init(&sched->base)) {
|
||||
log_error("Failed to reset the vblank scheduler");
|
||||
} else {
|
||||
sgi_video_sync_scheduler_schedule(&sched->base);
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto event = (struct vblank_event){
|
||||
.msc = msc,
|
||||
.ust = atomic_load(&sched->current_ust),
|
||||
};
|
||||
sched->base.vblank_event_requested = false;
|
||||
sched->last_msc = msc;
|
||||
log_verbose("Received vblank event for msc %" PRIu64, event.msc);
|
||||
vblank_scheduler_invoke_callbacks(&sched->base, &event);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool present_vblank_scheduler_schedule(struct vblank_scheduler *base) {
|
||||
auto self = (struct present_vblank_scheduler *)base;
|
||||
log_verbose("Requesting vblank event for window 0x%08x, msc %" PRIu64,
|
||||
base->target_window, self->last_msc + 1);
|
||||
assert(!base->vblank_event_requested);
|
||||
x_request_vblank_event(base->c, base->target_window, self->last_msc + 1);
|
||||
base->vblank_event_requested = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void present_vblank_callback(EV_P attr_unused, ev_timer *w, int attr_unused revents) {
|
||||
auto sched = container_of(w, struct present_vblank_scheduler, callback_timer);
|
||||
auto event = (struct vblank_event){
|
||||
.msc = sched->last_msc,
|
||||
.ust = sched->last_ust,
|
||||
};
|
||||
sched->base.vblank_event_requested = false;
|
||||
vblank_scheduler_invoke_callbacks(&sched->base, &event);
|
||||
}
|
||||
|
||||
static bool present_vblank_scheduler_init(struct vblank_scheduler *base) {
|
||||
auto self = (struct present_vblank_scheduler *)base;
|
||||
base->type = VBLANK_SCHEDULER_PRESENT;
|
||||
ev_timer_init(&self->callback_timer, present_vblank_callback, 0, 0);
|
||||
|
||||
self->event_id = x_new_id(base->c);
|
||||
auto select_input =
|
||||
xcb_present_select_input(base->c->c, self->event_id, base->target_window,
|
||||
XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY);
|
||||
set_cant_fail_cookie(base->c, select_input);
|
||||
self->event =
|
||||
xcb_register_for_special_xge(base->c->c, &xcb_present_id, self->event_id, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void present_vblank_scheduler_deinit(struct vblank_scheduler *base) {
|
||||
auto self = (struct present_vblank_scheduler *)base;
|
||||
ev_timer_stop(base->loop, &self->callback_timer);
|
||||
auto select_input =
|
||||
xcb_present_select_input(base->c->c, self->event_id, base->target_window, 0);
|
||||
set_cant_fail_cookie(base->c, select_input);
|
||||
xcb_unregister_for_special_event(base->c->c, self->event);
|
||||
}
|
||||
|
||||
/// Handle PresentCompleteNotify events
|
||||
///
|
||||
/// Schedule the registered callback to be called when the current vblank ends.
|
||||
static void handle_present_complete_notify(struct present_vblank_scheduler *self,
|
||||
xcb_present_complete_notify_event_t *cne) {
|
||||
assert(self->base.type == VBLANK_SCHEDULER_PRESENT);
|
||||
|
||||
if (cne->kind != XCB_PRESENT_COMPLETE_KIND_NOTIFY_MSC) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(self->base.vblank_event_requested);
|
||||
|
||||
// X sometimes sends duplicate/bogus MSC events, when screen has just been turned
|
||||
// off. Don't use the msc value in these events. We treat this as not receiving a
|
||||
// vblank event at all, and try to get a new one.
|
||||
//
|
||||
// See:
|
||||
// https://gitlab.freedesktop.org/xorg/xserver/-/issues/1418
|
||||
bool event_is_invalid = cne->msc <= self->last_msc || cne->ust == 0;
|
||||
if (event_is_invalid) {
|
||||
log_debug("Invalid PresentCompleteNotify event, %" PRIu64 " %" PRIu64,
|
||||
cne->msc, cne->ust);
|
||||
x_request_vblank_event(self->base.c, cne->window, self->last_msc + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
self->last_ust = cne->ust;
|
||||
self->last_msc = cne->msc;
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
auto now_us = (unsigned long)(now.tv_sec * 1000000L + now.tv_nsec / 1000);
|
||||
double delay_sec = 0.0;
|
||||
if (now_us < cne->ust) {
|
||||
log_trace("The end of this vblank is %" PRIu64 " us into the "
|
||||
"future",
|
||||
cne->ust - now_us);
|
||||
delay_sec = (double)(cne->ust - now_us) / 1000000.0;
|
||||
}
|
||||
// Wait until the end of the current vblank to invoke callbacks. If we
|
||||
// call it too early, it can mistakenly think the render missed the
|
||||
// vblank, and doesn't schedule render for the next vblank, causing frame
|
||||
// drops.
|
||||
assert(!ev_is_active(&self->callback_timer));
|
||||
ev_timer_set(&self->callback_timer, delay_sec, 0);
|
||||
ev_timer_start(self->base.loop, &self->callback_timer);
|
||||
}
|
||||
|
||||
static bool handle_present_events(struct vblank_scheduler *base) {
|
||||
auto self = (struct present_vblank_scheduler *)base;
|
||||
xcb_present_generic_event_t *ev;
|
||||
while ((ev = (void *)xcb_poll_for_special_event(base->c->c, self->event))) {
|
||||
if (ev->event != self->event_id) {
|
||||
// This event doesn't have the right event context, it's not meant
|
||||
// for us.
|
||||
goto next;
|
||||
}
|
||||
|
||||
// We only subscribed to the complete notify event.
|
||||
assert(ev->evtype == XCB_PRESENT_EVENT_COMPLETE_NOTIFY);
|
||||
handle_present_complete_notify(self, (void *)ev);
|
||||
next:
|
||||
free(ev);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const struct vblank_scheduler_ops vblank_scheduler_ops[LAST_VBLANK_SCHEDULER] = {
|
||||
[VBLANK_SCHEDULER_PRESENT] =
|
||||
{
|
||||
.size = sizeof(struct present_vblank_scheduler),
|
||||
.init = present_vblank_scheduler_init,
|
||||
.deinit = present_vblank_scheduler_deinit,
|
||||
.schedule = present_vblank_scheduler_schedule,
|
||||
.handle_x_events = handle_present_events,
|
||||
},
|
||||
#ifdef CONFIG_OPENGL
|
||||
[VBLANK_SCHEDULER_SGI_VIDEO_SYNC] =
|
||||
{
|
||||
.size = sizeof(struct sgi_video_sync_vblank_scheduler),
|
||||
.init = sgi_video_sync_scheduler_init,
|
||||
.deinit = sgi_video_sync_scheduler_deinit,
|
||||
.schedule = sgi_video_sync_scheduler_schedule,
|
||||
.handle_x_events = NULL,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static bool vblank_scheduler_schedule_internal(struct vblank_scheduler *self) {
|
||||
assert(self->type < LAST_VBLANK_SCHEDULER);
|
||||
auto fn = vblank_scheduler_ops[self->type].schedule;
|
||||
assert(fn != NULL);
|
||||
return fn(self);
|
||||
}
|
||||
|
||||
bool vblank_scheduler_schedule(struct vblank_scheduler *self,
|
||||
vblank_callback_t vblank_callback, void *user_data) {
|
||||
if (self->callback_count == 0 && self->wind_down == 0) {
|
||||
if (!vblank_scheduler_schedule_internal(self)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (self->callback_count == self->callback_capacity) {
|
||||
size_t new_capacity =
|
||||
self->callback_capacity ? self->callback_capacity * 2 : 1;
|
||||
void *new_buffer =
|
||||
realloc(self->callbacks, new_capacity * sizeof(*self->callbacks));
|
||||
if (!new_buffer) {
|
||||
return false;
|
||||
}
|
||||
self->callbacks = new_buffer;
|
||||
self->callback_capacity = new_capacity;
|
||||
}
|
||||
self->callbacks[self->callback_count++] = (struct vblank_closure){
|
||||
.fn = vblank_callback,
|
||||
.user_data = user_data,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
vblank_scheduler_invoke_callbacks(struct vblank_scheduler *self, struct vblank_event *event) {
|
||||
// callbacks might be added during callback invocation, so we need to
|
||||
// copy the callback_count.
|
||||
size_t count = self->callback_count, write_head = 0;
|
||||
if (count == 0) {
|
||||
self->wind_down--;
|
||||
} else {
|
||||
self->wind_down = VBLANK_WIND_DOWN;
|
||||
}
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
auto action = self->callbacks[i].fn(event, self->callbacks[i].user_data);
|
||||
switch (action) {
|
||||
case VBLANK_CALLBACK_AGAIN:
|
||||
if (i != write_head) {
|
||||
self->callbacks[write_head] = self->callbacks[i];
|
||||
}
|
||||
write_head++;
|
||||
case VBLANK_CALLBACK_DONE:
|
||||
default: // nothing to do
|
||||
break;
|
||||
}
|
||||
}
|
||||
memset(self->callbacks + write_head, 0,
|
||||
(count - write_head) * sizeof(*self->callbacks));
|
||||
assert(count == self->callback_count && "callbacks should not be added when "
|
||||
"callbacks are being invoked.");
|
||||
self->callback_count = write_head;
|
||||
if (self->callback_count || self->wind_down) {
|
||||
vblank_scheduler_schedule_internal(self);
|
||||
}
|
||||
}
|
||||
|
||||
void vblank_scheduler_free(struct vblank_scheduler *self) {
|
||||
assert(self->type < LAST_VBLANK_SCHEDULER);
|
||||
auto fn = vblank_scheduler_ops[self->type].deinit;
|
||||
if (fn != NULL) {
|
||||
fn(self);
|
||||
}
|
||||
free(self->callbacks);
|
||||
free(self);
|
||||
}
|
||||
|
||||
struct vblank_scheduler *
|
||||
vblank_scheduler_new(struct ev_loop *loop, struct x_connection *c,
|
||||
xcb_window_t target_window, enum vblank_scheduler_type type) {
|
||||
size_t object_size = vblank_scheduler_ops[type].size;
|
||||
auto init_fn = vblank_scheduler_ops[type].init;
|
||||
if (!object_size || !init_fn) {
|
||||
log_error("Unsupported or invalid vblank scheduler type: %d", type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(object_size >= sizeof(struct vblank_scheduler));
|
||||
struct vblank_scheduler *self = calloc(1, object_size);
|
||||
self->target_window = target_window;
|
||||
self->c = c;
|
||||
self->loop = loop;
|
||||
init_fn(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
bool vblank_handle_x_events(struct vblank_scheduler *self) {
|
||||
assert(self->type < LAST_VBLANK_SCHEDULER);
|
||||
auto fn = vblank_scheduler_ops[self->type].handle_x_events;
|
||||
if (fn != NULL) {
|
||||
return fn(self);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
47
src/vblank.h
Normal file
47
src/vblank.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <xcb/present.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include <ev.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "x.h"
|
||||
|
||||
/// An object that schedule vblank events.
|
||||
struct vblank_scheduler;
|
||||
|
||||
struct vblank_event {
|
||||
uint64_t msc;
|
||||
uint64_t ust;
|
||||
};
|
||||
|
||||
enum vblank_callback_action {
|
||||
/// The callback should be called again in the next vblank.
|
||||
VBLANK_CALLBACK_AGAIN,
|
||||
/// The callback is done and should not be called again.
|
||||
VBLANK_CALLBACK_DONE,
|
||||
};
|
||||
|
||||
typedef enum vblank_callback_action (*vblank_callback_t)(struct vblank_event *event,
|
||||
void *user_data);
|
||||
|
||||
/// Schedule a vblank event.
|
||||
///
|
||||
/// Schedule for `cb` to be called when the current vblank ends. If this is called
|
||||
/// from a callback function for the current vblank, the newly scheduled callback
|
||||
/// will be called in the next vblank.
|
||||
///
|
||||
/// Returns whether the scheduling is successful. Scheduling can fail if there
|
||||
/// is not enough memory.
|
||||
bool vblank_scheduler_schedule(struct vblank_scheduler *self, vblank_callback_t cb,
|
||||
void *user_data);
|
||||
struct vblank_scheduler *
|
||||
vblank_scheduler_new(struct ev_loop *loop, struct x_connection *c,
|
||||
xcb_window_t target_window, enum vblank_scheduler_type type);
|
||||
void vblank_scheduler_free(struct vblank_scheduler *);
|
||||
|
||||
bool vblank_handle_x_events(struct vblank_scheduler *self);
|
||||
522
src/win.c
522
src/win.c
@@ -73,6 +73,11 @@ static void
|
||||
win_update_frame_extents(session_t *ps, struct managed_win *w, xcb_window_t client);
|
||||
static void win_update_prop_shadow_raw(session_t *ps, struct managed_win *w);
|
||||
static void win_update_prop_shadow(session_t *ps, struct managed_win *w);
|
||||
/**
|
||||
* Update window EWMH fullscreen state.
|
||||
*/
|
||||
bool win_update_prop_fullscreen(struct x_connection *c, const struct atom *atoms,
|
||||
struct managed_win *w);
|
||||
/**
|
||||
* Update leader of a window.
|
||||
*/
|
||||
@@ -134,10 +139,10 @@ static inline bool attr_pure win_is_real_visible(const struct managed_win *w) {
|
||||
* Update focused state of a window.
|
||||
*/
|
||||
static void win_update_focused(session_t *ps, struct managed_win *w) {
|
||||
if (UNSET != w->focused_force) {
|
||||
if (w->focused_force != UNSET) {
|
||||
w->focused = w->focused_force;
|
||||
} else {
|
||||
w->focused = win_is_focused_raw(ps, w);
|
||||
w->focused = win_is_focused_raw(w);
|
||||
|
||||
// Use wintype_focus, and treat WM windows and override-redirected
|
||||
// windows specially
|
||||
@@ -205,7 +210,7 @@ static inline bool group_is_focused(session_t *ps, xcb_window_t leader) {
|
||||
continue;
|
||||
}
|
||||
auto mw = (struct managed_win *)w;
|
||||
if (win_get_leader(ps, mw) == leader && win_is_focused_raw(ps, mw)) {
|
||||
if (win_get_leader(ps, mw) == leader && win_is_focused_raw(mw)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -302,6 +307,13 @@ static inline void win_release_pixmap(backend_t *base, struct managed_win *w) {
|
||||
w->flags |= WIN_FLAGS_PIXMAP_NONE;
|
||||
}
|
||||
}
|
||||
static inline void win_release_oldpixmap(backend_t *base, struct managed_win *w) {
|
||||
log_debug("Releasing old_pixmap of window %#010x (%s)", w->base.id, w->name);
|
||||
if (w->old_win_image) {
|
||||
base->ops->release_image(base, w->old_win_image);
|
||||
w->old_win_image = NULL;
|
||||
}
|
||||
}
|
||||
static inline void win_release_shadow(backend_t *base, struct managed_win *w) {
|
||||
log_debug("Releasing shadow of window %#010x (%s)", w->base.id, w->name);
|
||||
assert(w->shadow_image);
|
||||
@@ -398,6 +410,7 @@ void win_release_images(struct backend_base *backend, struct managed_win *w) {
|
||||
if (!win_check_flags_all(w, WIN_FLAGS_PIXMAP_NONE)) {
|
||||
assert(!win_check_flags_all(w, WIN_FLAGS_PIXMAP_STALE));
|
||||
win_release_pixmap(backend, w);
|
||||
win_release_oldpixmap(backend, w);
|
||||
}
|
||||
|
||||
if (!win_check_flags_all(w, WIN_FLAGS_SHADOW_NONE)) {
|
||||
@@ -457,6 +470,12 @@ static void win_update_properties(session_t *ps, struct managed_win *w) {
|
||||
win_update_prop_shadow(ps, w);
|
||||
}
|
||||
|
||||
if (win_fetch_and_unset_property_stale(w, ps->atoms->a_NET_WM_STATE)) {
|
||||
if (win_update_prop_fullscreen(&ps->c, ps->atoms, w)) {
|
||||
win_set_flags(w, WIN_FLAGS_FACTOR_CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
if (win_fetch_and_unset_property_stale(w, ps->atoms->aWM_CLIENT_LEADER) ||
|
||||
win_fetch_and_unset_property_stale(w, ps->atoms->aWM_TRANSIENT_FOR)) {
|
||||
win_update_leader(ps, w);
|
||||
@@ -465,13 +484,181 @@ static void win_update_properties(session_t *ps, struct managed_win *w) {
|
||||
win_clear_all_properties_stale(w);
|
||||
}
|
||||
|
||||
static void init_animation(session_t *ps, struct managed_win *w) {
|
||||
CLEAR_MASK(w->animation_is_tag)
|
||||
static int32_t randr_mon_center_x, randr_mon_center_y;
|
||||
if (w->randr_monitor != -1) {
|
||||
auto e = pixman_region32_extents(&ps->monitors.regions[w->randr_monitor]);
|
||||
randr_mon_center_x = (e->x2 + e->x1) / 2, randr_mon_center_y = (e->y2 + e->y1) / 2;
|
||||
} else {
|
||||
randr_mon_center_x = ps->root_width / 2, randr_mon_center_y = ps->root_height / 2;
|
||||
}
|
||||
static double *anim_x, *anim_y, *anim_w, *anim_h;
|
||||
enum open_window_animation animation;
|
||||
|
||||
|
||||
animation = ps->o.animation_for_open_window;
|
||||
|
||||
if (w->window_type != WINTYPE_TOOLTIP &&
|
||||
wid_has_prop(ps, w->client_win, ps->atoms->aWM_TRANSIENT_FOR)) {
|
||||
animation = ps->o.animation_for_transient_window;
|
||||
}
|
||||
|
||||
if (ps->o.wintype_option[w->window_type].animation != OPEN_WINDOW_ANIMATION_INVALID
|
||||
&& !w->dwm_mask) {
|
||||
animation = ps->o.wintype_option[w->window_type].animation;
|
||||
}
|
||||
|
||||
anim_x = &w->animation_center_x, anim_y = &w->animation_center_y;
|
||||
anim_w = &w->animation_w, anim_h = &w->animation_h;
|
||||
|
||||
if (w->dwm_mask & ANIM_PREV_TAG) {
|
||||
animation = ps->o.animation_for_prev_tag;
|
||||
|
||||
if (ps->o.enable_fading_prev_tag) {
|
||||
w->opacity_target_old = fmax(w->opacity_target, w->opacity_target_old);
|
||||
w->state = WSTATE_FADING;
|
||||
w->animation_is_tag |= ANIM_FADE;
|
||||
}
|
||||
if (ps->o.animation_for_prev_tag >= OPEN_WINDOW_ANIMATION_ZOOM) {
|
||||
w->animation_is_tag |= ANIM_FAST;
|
||||
w->dwm_mask |= ANIM_SPECIAL_MINIMIZE;
|
||||
goto revert;
|
||||
}
|
||||
w->animation_is_tag |= ANIM_SLOW;
|
||||
} else if (w->dwm_mask & ANIM_NEXT_TAG) {
|
||||
animation = ps->o.animation_for_next_tag;
|
||||
w->animation_is_tag |= animation >= OPEN_WINDOW_ANIMATION_ZOOM ? ANIM_FAST : ANIM_SLOW;
|
||||
if (ps->o.enable_fading_next_tag) {
|
||||
w->opacity = 0.0;
|
||||
w->state = WSTATE_FADING;
|
||||
}
|
||||
} else if (w->dwm_mask & ANIM_UNMAP) {
|
||||
animation = ps->o.animation_for_unmap_window;
|
||||
revert:
|
||||
anim_x = &w->animation_dest_center_x, anim_y = &w->animation_dest_center_y;
|
||||
anim_w = &w->animation_dest_w, anim_h = &w->animation_dest_h;
|
||||
}
|
||||
|
||||
double angle;
|
||||
switch (animation) {
|
||||
case OPEN_WINDOW_ANIMATION_NONE: // No animation
|
||||
w->animation_center_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
w->animation_center_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
w->animation_w = w->pending_g.width;
|
||||
w->animation_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_FLYIN: // Fly-in from a random point outside the screen
|
||||
// Compute random point off screen
|
||||
angle = 2 * M_PI * ((double)rand() / RAND_MAX);
|
||||
const double radius =
|
||||
sqrt(ps->root_width * ps->root_width + ps->root_height * ps->root_height);
|
||||
|
||||
// Set animation
|
||||
*anim_x = randr_mon_center_x + radius * cos(angle);
|
||||
*anim_y = randr_mon_center_y + radius * sin(angle);
|
||||
*anim_w = 0;
|
||||
*anim_h = 0;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_UP: // Slide up the image, without changing its location
|
||||
*anim_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height;
|
||||
*anim_w = w->pending_g.width;
|
||||
*anim_h = 0;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_DOWN: // Slide down the image, without changing its location
|
||||
*anim_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
*anim_y = w->pending_g.y;
|
||||
*anim_w = w->pending_g.width;
|
||||
*anim_h = 0;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_LEFT: // Slide left the image, without changing its location
|
||||
*anim_x = w->pending_g.x + w->pending_g.width;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
*anim_w = 0;
|
||||
*anim_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_RIGHT: // Slide right the image, without changing its location
|
||||
*anim_x = w->pending_g.x;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
*anim_w = 0;
|
||||
*anim_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_IN:
|
||||
*anim_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
*anim_w = w->pending_g.width;
|
||||
*anim_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_IN_CENTER:
|
||||
*anim_x = randr_mon_center_x;
|
||||
*anim_y = w->g.y + w->pending_g.height * 0.5;
|
||||
*anim_w = w->pending_g.width;
|
||||
*anim_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_OUT:
|
||||
w->animation_dest_center_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
w->animation_dest_center_y = w->pending_g.y;
|
||||
w->animation_dest_w = w->pending_g.width;
|
||||
w->animation_dest_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SLIDE_OUT_CENTER:
|
||||
w->animation_dest_center_x = randr_mon_center_x;
|
||||
w->animation_dest_center_y = w->pending_g.y;
|
||||
w->animation_dest_w = w->pending_g.width;
|
||||
w->animation_dest_h = w->pending_g.height;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_ZOOM: // Zoom-in the image, without changing its location
|
||||
if (w->dwm_mask & ANIM_SPECIAL_MINIMIZE) {
|
||||
*anim_x = w->g.x + w->g.width * 0.5;
|
||||
*anim_y = w->g.y + w->g.height * 0.5;
|
||||
} else {
|
||||
*anim_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
}
|
||||
*anim_w = 0;
|
||||
*anim_h = 0;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_MINIMIZE:
|
||||
*anim_x = randr_mon_center_x;
|
||||
*anim_y = randr_mon_center_y;
|
||||
*anim_w = 0;
|
||||
*anim_h = 0;
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SQUEEZE:
|
||||
if (w->dwm_mask & ANIM_PREV_TAG) {
|
||||
*anim_h = 0;
|
||||
} else {
|
||||
*anim_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
*anim_w = w->pending_g.width;
|
||||
*anim_h = 0;
|
||||
}
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_SQUEEZE_BOTTOM:
|
||||
if (w->dwm_mask & ANIM_PREV_TAG) {
|
||||
*anim_y = w->g.y + w->g.height;
|
||||
*anim_h = 0;
|
||||
} else {
|
||||
w->animation_center_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
w->animation_center_y = w->pending_g.y + w->pending_g.height;
|
||||
w->animation_w = w->pending_g.width;
|
||||
*anim_h = 0;
|
||||
*anim_y = w->pending_g.y + w->pending_g.height;
|
||||
}
|
||||
break;
|
||||
case OPEN_WINDOW_ANIMATION_INVALID: assert(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle non-image flags. This phase might set IMAGES_STALE flags
|
||||
void win_process_update_flags(session_t *ps, struct managed_win *w) {
|
||||
// Whether the window was visible before we process the mapped flag. i.e.
|
||||
// is the window just mapped.
|
||||
bool was_visible = win_is_real_visible(w);
|
||||
log_trace("Processing flags for window %#010x (%s), was visible: %d", w->base.id,
|
||||
w->name, was_visible);
|
||||
log_trace("Processing flags for window %#010x (%s), was visible: %d, flags: "
|
||||
"%#" PRIx64,
|
||||
w->base.id, w->name, was_visible, w->flags);
|
||||
|
||||
if (win_check_flags_all(w, WIN_FLAGS_MAPPED)) {
|
||||
map_win_start(ps, w);
|
||||
@@ -505,8 +692,82 @@ void win_process_update_flags(session_t *ps, struct managed_win *w) {
|
||||
add_damage_from_win(ps, w);
|
||||
}
|
||||
|
||||
// Update window geometry
|
||||
w->g = w->pending_g;
|
||||
|
||||
|
||||
// Determine if a window should animate
|
||||
if (win_should_animate(ps, w)) {
|
||||
if (w->pending_g.y < 0 && w->g.y > 0 && abs(w->pending_g.y - w->g.y) >= w->pending_g.height)
|
||||
w->dwm_mask = ANIM_PREV_TAG;
|
||||
else if (w->pending_g.y > 0 && w->g.y < 0 && abs(w->pending_g.y - w->g.y) >= w->pending_g.height)
|
||||
w->dwm_mask = ANIM_NEXT_TAG;
|
||||
|
||||
if (!was_visible || w->dwm_mask) {
|
||||
|
||||
// Set window-open animation
|
||||
init_animation(ps, w);
|
||||
if (!(w->dwm_mask & ANIM_SPECIAL_MINIMIZE)) {
|
||||
w->animation_dest_center_x = w->pending_g.x + w->pending_g.width * 0.5;
|
||||
w->animation_dest_center_y = w->pending_g.y + w->pending_g.height * 0.5;
|
||||
w->animation_dest_w = w->pending_g.width;
|
||||
w->animation_dest_h = w->pending_g.height;
|
||||
w->g.x = (int16_t)round(w->animation_center_x -
|
||||
w->animation_w * 0.5);
|
||||
w->g.y = (int16_t)round(w->animation_center_y -
|
||||
w->animation_h * 0.5);
|
||||
w->g.width = (uint16_t)round(w->animation_w);
|
||||
w->g.height = (uint16_t)round(w->animation_h);
|
||||
}
|
||||
|
||||
} else {
|
||||
w->animation_is_tag = ANIM_IN_TAG;
|
||||
w->animation_dest_center_x =
|
||||
w->pending_g.x + w->pending_g.width * 0.5;
|
||||
w->animation_dest_center_y =
|
||||
w->pending_g.y + w->pending_g.height * 0.5;
|
||||
w->animation_dest_w = w->pending_g.width;
|
||||
w->animation_dest_h = w->pending_g.height;
|
||||
}
|
||||
|
||||
CLEAR_MASK(w->dwm_mask)
|
||||
w->g.border_width = w->pending_g.border_width;
|
||||
double x_dist = w->animation_dest_center_x - w->animation_center_x;
|
||||
double y_dist = w->animation_dest_center_y - w->animation_center_y;
|
||||
double w_dist = w->animation_dest_w - w->animation_w;
|
||||
double h_dist = w->animation_dest_h - w->animation_h;
|
||||
w->animation_inv_og_distance =
|
||||
1.0 / sqrt(x_dist * x_dist + y_dist * y_dist +
|
||||
w_dist * w_dist + h_dist * h_dist);
|
||||
|
||||
if (isinf(w->animation_inv_og_distance))
|
||||
w->animation_inv_og_distance = 0;
|
||||
|
||||
// We only grab images if w->reg_ignore_valid is true as
|
||||
// there's an ev_shape_notify() event fired quickly on new windows
|
||||
// for e.g. in case of Firefox main menu and ev_shape_notify()
|
||||
// sets the win_set_flags(w, WIN_FLAGS_SIZE_STALE); which
|
||||
// brakes the new image captured and because this same event
|
||||
// also sets w->reg_ignore_valid = false; too we check for it
|
||||
if (w->reg_ignore_valid) {
|
||||
if (w->old_win_image) {
|
||||
ps->backend_data->ops->release_image(ps->backend_data,
|
||||
w->old_win_image);
|
||||
w->old_win_image = NULL;
|
||||
}
|
||||
|
||||
// We only grab
|
||||
if (w->win_image) {
|
||||
w->old_win_image = ps->backend_data->ops->clone_image(
|
||||
ps->backend_data, w->win_image, &w->bounding_shape);
|
||||
}
|
||||
}
|
||||
|
||||
w->animation_progress = 0.0;
|
||||
} else {
|
||||
w->g = w->pending_g;
|
||||
}
|
||||
|
||||
// Whether a window is fullscreen changes based on its geometry
|
||||
win_update_is_fullscreen(ps, w);
|
||||
|
||||
if (win_check_flags_all(w, WIN_FLAGS_SIZE_STALE)) {
|
||||
win_on_win_size_change(ps, w);
|
||||
@@ -643,12 +904,14 @@ int win_update_name(session_t *ps, struct managed_win *w) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(wid_get_text_prop(ps, w->client_win, ps->atoms->a_NET_WM_NAME, &strlst, &nstr))) {
|
||||
if (!(wid_get_text_prop(&ps->c, ps->atoms, w->client_win,
|
||||
ps->atoms->a_NET_WM_NAME, &strlst, &nstr))) {
|
||||
log_debug("(%#010x): _NET_WM_NAME unset, falling back to "
|
||||
"WM_NAME.",
|
||||
w->client_win);
|
||||
|
||||
if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_NAME, &strlst, &nstr)) {
|
||||
if (!wid_get_text_prop(&ps->c, ps->atoms, w->client_win,
|
||||
ps->atoms->aWM_NAME, &strlst, &nstr)) {
|
||||
log_debug("Unsetting window name for %#010x", w->client_win);
|
||||
free(w->name);
|
||||
w->name = NULL;
|
||||
@@ -675,7 +938,8 @@ static int win_update_role(session_t *ps, struct managed_win *w) {
|
||||
char **strlst = NULL;
|
||||
int nstr = 0;
|
||||
|
||||
if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_WINDOW_ROLE, &strlst, &nstr)) {
|
||||
if (!wid_get_text_prop(&ps->c, ps->atoms, w->client_win,
|
||||
ps->atoms->aWM_WINDOW_ROLE, &strlst, &nstr)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -818,6 +1082,10 @@ double win_calc_opacity_target(session_t *ps, const struct managed_win *w) {
|
||||
if (w->state == WSTATE_UNMAPPING || w->state == WSTATE_DESTROYING) {
|
||||
return 0;
|
||||
}
|
||||
if ((w->state == WSTATE_FADING && (w->animation_is_tag & ANIM_FADE))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Try obeying opacity property and window type opacity firstly
|
||||
if (w->has_opacity_prop) {
|
||||
opacity = ((double)w->opacity_prop) / OPAQUE;
|
||||
@@ -828,7 +1096,7 @@ double win_calc_opacity_target(session_t *ps, const struct managed_win *w) {
|
||||
} else {
|
||||
// Respect active_opacity only when the window is physically
|
||||
// focused
|
||||
if (win_is_focused_raw(ps, w)) {
|
||||
if (win_is_focused_raw(w)) {
|
||||
opacity = ps->o.active_opacity;
|
||||
} else if (!w->focused) {
|
||||
// Respect inactive_opacity in some cases
|
||||
@@ -882,6 +1150,24 @@ bool win_should_fade(session_t *ps, const struct managed_win *w) {
|
||||
return ps->o.wintype_option[w->window_type].fade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a window should animate.
|
||||
*/
|
||||
bool win_should_animate(session_t *ps, const struct managed_win *w) {
|
||||
if (!ps->o.animations) {
|
||||
return false;
|
||||
}
|
||||
if (ps->o.wintype_option[w->window_type].animation == 0) {
|
||||
log_debug("Animation disabled by window_type");
|
||||
return false;
|
||||
}
|
||||
if (c2_match(ps, w, ps->o.animation_blacklist, NULL)) {
|
||||
log_debug("Animation disabled by animation_exclude");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reread _COMPTON_SHADOW property from a window.
|
||||
*
|
||||
@@ -954,7 +1240,7 @@ static void win_set_shadow(session_t *ps, struct managed_win *w, bool shadow_new
|
||||
|
||||
// Delayed update of shadow image
|
||||
// By setting WIN_FLAGS_SHADOW_STALE, we ask win_process_flags to
|
||||
// re-create or release the shaodw in based on whether w->shadow
|
||||
// re-create or release the shadow in based on whether w->shadow
|
||||
// is set.
|
||||
win_set_flags(w, WIN_FLAGS_SHADOW_STALE);
|
||||
|
||||
@@ -1011,6 +1297,30 @@ void win_update_prop_shadow(session_t *ps, struct managed_win *w) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update window EWMH fullscreen state.
|
||||
*/
|
||||
bool win_update_prop_fullscreen(struct x_connection *c, const struct atom *atoms,
|
||||
struct managed_win *w) {
|
||||
auto prop = x_get_prop(c, w->client_win, atoms->a_NET_WM_STATE, 12, XCB_ATOM_ATOM, 0);
|
||||
if (!prop.nitems) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_fullscreen = false;
|
||||
for (uint32_t i = 0; i < prop.nitems; i++) {
|
||||
if (prop.atom[i] == atoms->a_NET_WM_STATE_FULLSCREEN) {
|
||||
is_fullscreen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free_winprop(&prop);
|
||||
|
||||
bool changed = w->is_ewmh_fullscreen != is_fullscreen;
|
||||
w->is_ewmh_fullscreen = is_fullscreen;
|
||||
return changed;
|
||||
}
|
||||
|
||||
static void win_determine_clip_shadow_above(session_t *ps, struct managed_win *w) {
|
||||
bool should_crop = (ps->o.wintype_option[w->window_type].clip_shadow_above ||
|
||||
c2_match(ps, w, ps->o.shadow_clip_list, NULL));
|
||||
@@ -1139,19 +1449,19 @@ static void win_determine_blur_background(session_t *ps, struct managed_win *w)
|
||||
* Determine if a window should have rounded corners.
|
||||
*/
|
||||
static void win_determine_rounded_corners(session_t *ps, struct managed_win *w) {
|
||||
if (ps->o.corner_radius == 0) {
|
||||
w->corner_radius = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void *radius_override = NULL;
|
||||
if (c2_match(ps, w, ps->o.corner_radius_rules, &radius_override)) {
|
||||
log_debug("Matched corner rule! %d", w->corner_radius);
|
||||
}
|
||||
|
||||
if (ps->o.corner_radius == 0 && !radius_override) {
|
||||
w->corner_radius = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't round full screen windows & excluded windows,
|
||||
// unless we find a corner override in corner_radius_rules
|
||||
if (!radius_override && ((w && win_is_fullscreen(ps, w)) ||
|
||||
if (!radius_override && ((w && w->is_fullscreen) ||
|
||||
c2_match(ps, w, ps->o.rounded_corners_blacklist, NULL))) {
|
||||
w->corner_radius = 0;
|
||||
log_debug("Not rounding corners for window %#010x", w->base.id);
|
||||
@@ -1218,9 +1528,10 @@ void win_update_opacity_rule(session_t *ps, struct managed_win *w) {
|
||||
*/
|
||||
void win_on_factor_change(session_t *ps, struct managed_win *w) {
|
||||
log_debug("Window %#010x (%s) factor change", w->base.id, w->name);
|
||||
// Focus needs to be updated first, as other rules might depend on the
|
||||
// focused state of the window
|
||||
// Focus and is_fullscreen needs to be updated first, as other rules might depend
|
||||
// on the focused state of the window
|
||||
win_update_focused(ps, w);
|
||||
win_update_is_fullscreen(ps, w);
|
||||
|
||||
win_determine_shadow(ps, w);
|
||||
win_determine_clip_shadow_above(ps, w);
|
||||
@@ -1253,6 +1564,10 @@ void win_on_factor_change(session_t *ps, struct managed_win *w) {
|
||||
* Update cache data in struct _win that depends on window size.
|
||||
*/
|
||||
void win_on_win_size_change(session_t *ps, struct managed_win *w) {
|
||||
log_trace("Window %#010x (%s) size changed, was %dx%d, now %dx%d", w->base.id,
|
||||
w->name, w->widthb, w->heightb, w->g.width + w->g.border_width * 2,
|
||||
w->g.height + w->g.border_width * 2);
|
||||
|
||||
w->widthb = w->g.width + w->g.border_width * 2;
|
||||
w->heightb = w->g.height + w->g.border_width * 2;
|
||||
w->shadow_dx = ps->o.shadow_offset_x;
|
||||
@@ -1266,8 +1581,12 @@ void win_on_win_size_change(session_t *ps, struct managed_win *w) {
|
||||
w->state != WSTATE_UNMAPPING);
|
||||
|
||||
// Invalidate the shadow we built
|
||||
win_set_flags(w, WIN_FLAGS_IMAGES_STALE);
|
||||
win_release_mask(ps->backend_data, w);
|
||||
// Do not set flags if window is unmapping and animation is running
|
||||
if (w->state != WSTATE_UNMAPPED && w->state != WSTATE_DESTROYING &&
|
||||
w->state != WSTATE_UNMAPPING) {
|
||||
win_set_flags(w, WIN_FLAGS_IMAGES_STALE);
|
||||
win_release_mask(ps->backend_data, w);
|
||||
}
|
||||
ps->pending_updates = true;
|
||||
free_paint(ps, &w->shadow_paint);
|
||||
}
|
||||
@@ -1526,14 +1845,19 @@ struct win *fill_win(session_t *ps, struct win *w) {
|
||||
.blur_background = false,
|
||||
.reg_ignore = NULL,
|
||||
// The following ones are updated for other reasons
|
||||
.pixmap_damaged = false, // updated by damage events
|
||||
.state = WSTATE_UNMAPPED, // updated by window state changes
|
||||
.in_openclose = true, // set to false after first map is done,
|
||||
// true here because window is just created
|
||||
.reg_ignore_valid = false, // set to true when damaged
|
||||
.flags = WIN_FLAGS_IMAGES_NONE, // updated by
|
||||
// property/attributes/etc
|
||||
// change
|
||||
.pixmap_damaged = false, // updated by damage events
|
||||
.state = WSTATE_UNMAPPED, // updated by window state changes
|
||||
.in_openclose = true, // set to false after first map is done,
|
||||
// true here because window is just created
|
||||
.animation_velocity_x = 0.0, // updated by window geometry changes
|
||||
.animation_velocity_y = 0.0, // updated by window geometry changes
|
||||
.animation_velocity_w = 0.0, // updated by window geometry changes
|
||||
.animation_velocity_h = 0.0, // updated by window geometry changes
|
||||
.animation_progress = 1.0, // updated by window geometry changes
|
||||
.animation_inv_og_distance = NAN, // updated by window geometry changes
|
||||
.reg_ignore_valid = false, // set to true when damaged
|
||||
.flags = WIN_FLAGS_IMAGES_NONE, // updated by property/attributes/etc
|
||||
// change
|
||||
.stale_props = NULL,
|
||||
.stale_props_capacity = 0,
|
||||
|
||||
@@ -1559,6 +1883,7 @@ struct win *fill_win(session_t *ps, struct win *w) {
|
||||
// have no meaning or have no use until the window
|
||||
// is mapped
|
||||
.win_image = NULL,
|
||||
.old_win_image = NULL,
|
||||
.shadow_image = NULL,
|
||||
.mask_image = NULL,
|
||||
.prev_trans = NULL,
|
||||
@@ -1718,6 +2043,7 @@ struct win *fill_win(session_t *ps, struct win *w) {
|
||||
ps->atoms->a_NET_WM_NAME, ps->atoms->aWM_CLASS,
|
||||
ps->atoms->aWM_WINDOW_ROLE, ps->atoms->a_COMPTON_SHADOW,
|
||||
ps->atoms->aWM_CLIENT_LEADER, ps->atoms->aWM_TRANSIENT_FOR,
|
||||
ps->atoms->a_NET_WM_STATE,
|
||||
};
|
||||
win_set_properties_stale(new, init_stale_props, ARR_SIZE(init_stale_props));
|
||||
|
||||
@@ -1747,7 +2073,7 @@ static inline void win_set_leader(session_t *ps, struct managed_win *w, xcb_wind
|
||||
// Update the old and new window group and active_leader if the
|
||||
// window could affect their state.
|
||||
xcb_window_t cache_leader = win_get_leader(ps, w);
|
||||
if (win_is_focused_raw(ps, w) && cache_leader_old != cache_leader) {
|
||||
if (win_is_focused_raw(w) && cache_leader_old != cache_leader) {
|
||||
ps->active_leader = cache_leader;
|
||||
|
||||
group_on_factor_change(ps, cache_leader_old);
|
||||
@@ -1831,7 +2157,8 @@ bool win_update_class(session_t *ps, struct managed_win *w) {
|
||||
w->class_general = NULL;
|
||||
|
||||
// Retrieve the property string list
|
||||
if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_CLASS, &strlst, &nstr)) {
|
||||
if (!wid_get_text_prop(&ps->c, ps->atoms, w->client_win, ps->atoms->aWM_CLASS,
|
||||
&strlst, &nstr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1860,7 +2187,7 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
|
||||
xcb_window_t leader = win_get_leader(ps, w);
|
||||
|
||||
// If the window gets focused, replace the old active_leader
|
||||
if (win_is_focused_raw(ps, w) && leader != ps->active_leader) {
|
||||
if (win_is_focused_raw(w) && leader != ps->active_leader) {
|
||||
xcb_window_t active_leader_old = ps->active_leader;
|
||||
|
||||
ps->active_leader = leader;
|
||||
@@ -1869,7 +2196,7 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
|
||||
group_on_factor_change(ps, leader);
|
||||
}
|
||||
// If the group get unfocused, remove it from active_leader
|
||||
else if (!win_is_focused_raw(ps, w) && leader &&
|
||||
else if (!win_is_focused_raw(w) && leader &&
|
||||
leader == ps->active_leader && !group_is_focused(ps, leader)) {
|
||||
ps->active_leader = XCB_NONE;
|
||||
group_on_factor_change(ps, leader);
|
||||
@@ -1882,7 +2209,7 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
|
||||
#ifdef CONFIG_DBUS
|
||||
// Send D-Bus signal
|
||||
if (ps->o.dbus) {
|
||||
if (win_is_focused_raw(ps, w)) {
|
||||
if (win_is_focused_raw(w)) {
|
||||
cdbus_ev_win_focusin(ps, &w->base);
|
||||
} else {
|
||||
cdbus_ev_win_focusout(ps, &w->base);
|
||||
@@ -1900,15 +2227,18 @@ void win_set_focused(session_t *ps, struct managed_win *w) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (win_is_focused_raw(ps, w)) {
|
||||
if (w->is_ewmh_focused) {
|
||||
assert(ps->active_win == w);
|
||||
return;
|
||||
}
|
||||
|
||||
auto old_active_win = ps->active_win;
|
||||
ps->active_win = w;
|
||||
assert(win_is_focused_raw(ps, w));
|
||||
w->is_ewmh_focused = true;
|
||||
|
||||
if (old_active_win) {
|
||||
assert(old_active_win->is_ewmh_focused);
|
||||
old_active_win->is_ewmh_focused = false;
|
||||
win_on_focus_change(ps, old_active_win);
|
||||
}
|
||||
win_on_focus_change(ps, w);
|
||||
@@ -1981,7 +2311,7 @@ void win_update_bounding_shape(session_t *ps, struct managed_win *w) {
|
||||
|
||||
// Add border width because we are using a different origin.
|
||||
// X thinks the top left of the inner window is the origin
|
||||
// (for the bounding shape, althought xcb_get_geometry thinks
|
||||
// (for the bounding shape, although xcb_get_geometry thinks
|
||||
// the outer top left (outer means outside of the window
|
||||
// border) is the origin),
|
||||
// We think the top left of the border is the origin
|
||||
@@ -2001,14 +2331,12 @@ void win_update_bounding_shape(session_t *ps, struct managed_win *w) {
|
||||
|
||||
// Window shape changed, we should free old wpaint and shadow pict
|
||||
// log_trace("free out dated pict");
|
||||
win_set_flags(w, WIN_FLAGS_IMAGES_STALE);
|
||||
win_set_flags(w, WIN_FLAGS_IMAGES_STALE | WIN_FLAGS_FACTOR_CHANGED);
|
||||
win_release_mask(ps->backend_data, w);
|
||||
ps->pending_updates = true;
|
||||
|
||||
free_paint(ps, &w->paint);
|
||||
free_paint(ps, &w->shadow_paint);
|
||||
|
||||
win_on_factor_change(ps, w);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2121,17 +2449,31 @@ static void unmap_win_finish(session_t *ps, struct managed_win *w) {
|
||||
// Shadow image can be preserved.
|
||||
if (!win_check_flags_all(w, WIN_FLAGS_PIXMAP_NONE)) {
|
||||
win_release_pixmap(ps->backend_data, w);
|
||||
win_release_oldpixmap(ps->backend_data, w);
|
||||
}
|
||||
} else {
|
||||
assert(!w->win_image);
|
||||
assert(!w->old_win_image);
|
||||
assert(!w->shadow_image);
|
||||
}
|
||||
|
||||
// Force animation to completed position
|
||||
w->animation_velocity_x = 0;
|
||||
w->animation_velocity_y = 0;
|
||||
w->animation_velocity_w = 0;
|
||||
w->animation_velocity_h = 0;
|
||||
w->animation_progress = 1.0;
|
||||
|
||||
free_paint(ps, &w->paint);
|
||||
free_paint(ps, &w->shadow_paint);
|
||||
|
||||
// Try again at binding images when the window is mapped next time
|
||||
win_clear_flags(w, WIN_FLAGS_IMAGE_ERROR);
|
||||
|
||||
// Flag window so that it gets animated when it reapears
|
||||
// in case it wasn't destroyed
|
||||
win_set_flags(w, WIN_FLAGS_POSITION_STALE);
|
||||
win_set_flags(w, WIN_FLAGS_SIZE_STALE);
|
||||
}
|
||||
|
||||
/// Finish the destruction of a window (e.g. after fading has finished).
|
||||
@@ -2310,7 +2652,7 @@ bool destroy_win_start(session_t *ps, struct win *w) {
|
||||
HASH_DEL(ps->windows, w);
|
||||
|
||||
if (!w->managed || mw->state == WSTATE_UNMAPPED) {
|
||||
// Window is already unmapped, or is an unmanged window, just
|
||||
// Window is already unmapped, or is an unmanaged window, just
|
||||
// destroy it
|
||||
destroy_win_finish(ps, w);
|
||||
return true;
|
||||
@@ -2335,6 +2677,13 @@ bool destroy_win_start(session_t *ps, struct win *w) {
|
||||
add_damage_from_win(ps, mw);
|
||||
}
|
||||
|
||||
if (win_check_flags_all(mw, WIN_FLAGS_CLIENT_STALE)) {
|
||||
mw->client_win = mw->base.id;
|
||||
mw->wmwin = !mw->a.override_redirect;
|
||||
log_debug("(%#010x): client self (%s)", mw->base.id,
|
||||
(mw->wmwin ? "wmwin" : "override-redirected"));
|
||||
}
|
||||
|
||||
// Clear some flags about stale window information. Because now
|
||||
// the window is destroyed, we can't update them anyway.
|
||||
win_clear_flags(mw, WIN_FLAGS_SIZE_STALE | WIN_FLAGS_POSITION_STALE |
|
||||
@@ -2400,6 +2749,30 @@ void unmap_win_start(session_t *ps, struct managed_win *w) {
|
||||
w->opacity_target_old = fmax(w->opacity_target, w->opacity_target_old);
|
||||
w->opacity_target = win_calc_opacity_target(ps, w);
|
||||
|
||||
if (ps->o.animations && ps->o.animation_for_unmap_window != OPEN_WINDOW_ANIMATION_NONE && ps->o.wintype_option[w->window_type].animation) {
|
||||
w->dwm_mask = ANIM_UNMAP;
|
||||
init_animation(ps, w);
|
||||
|
||||
double x_dist = w->animation_dest_center_x - w->animation_center_x;
|
||||
double y_dist = w->animation_dest_center_y - w->animation_center_y;
|
||||
double w_dist = w->animation_dest_w - w->animation_w;
|
||||
double h_dist = w->animation_dest_h - w->animation_h;
|
||||
w->animation_inv_og_distance =
|
||||
1.0 / sqrt(x_dist * x_dist + y_dist * y_dist +
|
||||
w_dist * w_dist + h_dist * h_dist);
|
||||
|
||||
if (isinf(w->animation_inv_og_distance))
|
||||
w->animation_inv_og_distance = 0;
|
||||
|
||||
w->animation_progress = 0.0;
|
||||
|
||||
if (w->old_win_image) {
|
||||
ps->backend_data->ops->release_image(ps->backend_data,
|
||||
w->old_win_image);
|
||||
w->old_win_image = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DBUS
|
||||
// Send D-Bus signal
|
||||
if (ps->o.dbus) {
|
||||
@@ -2445,7 +2818,7 @@ bool win_check_fade_finished(session_t *ps, struct managed_win *w) {
|
||||
///
|
||||
/// @return whether the window is destroyed and freed
|
||||
bool win_skip_fading(session_t *ps, struct managed_win *w) {
|
||||
if (w->state == WSTATE_MAPPED || w->state == WSTATE_UNMAPPED) {
|
||||
if ((w->state == WSTATE_MAPPED || w->state == WSTATE_UNMAPPED)) {
|
||||
assert(w->opacity_target == w->opacity);
|
||||
return false;
|
||||
}
|
||||
@@ -2457,11 +2830,12 @@ bool win_skip_fading(session_t *ps, struct managed_win *w) {
|
||||
// TODO(absolutelynothelix): rename to x_update_win_(randr_?)monitor and move to
|
||||
// the x.c.
|
||||
void win_update_monitor(struct x_monitors *monitors, struct managed_win *mw) {
|
||||
mw->randr_monitor = -1;
|
||||
for (int i = 0; i < monitors->count; i++) {
|
||||
auto e = pixman_region32_extents(&monitors->regions[i]);
|
||||
if (e->x1 <= mw->g.x && e->y1 <= mw->g.y &&
|
||||
e->x2 >= mw->g.x + mw->widthb && e->y2 >= mw->g.y + mw->heightb) {
|
||||
if (((e->x1 <= mw->g.x || e->x1 <= mw->pending_g.x) &&
|
||||
(e->x2 >= mw->g.x + mw->widthb || e->x2 >= mw->pending_g.x + mw->widthb)) &&
|
||||
(e->y1 <= mw->g.y || e->y1 <= mw->pending_g.y) &&
|
||||
(e->y2 >= mw->g.y + mw->heightb || e->y2 >= mw->pending_g.y + mw->heightb)) {
|
||||
mw->randr_monitor = i;
|
||||
log_debug("Window %#010x (%s), %dx%d+%dx%d, is entirely on the "
|
||||
"monitor %d (%dx%d+%dx%d)",
|
||||
@@ -2470,6 +2844,7 @@ void win_update_monitor(struct x_monitors *monitors, struct managed_win *mw) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
mw->randr_monitor = -1;
|
||||
log_debug("Window %#010x (%s), %dx%d+%dx%d, is not entirely on any monitor",
|
||||
mw->base.id, mw->name, mw->g.x, mw->g.y, mw->widthb, mw->heightb);
|
||||
}
|
||||
@@ -2698,41 +3073,6 @@ struct managed_win *find_managed_window_or_parent(session_t *ps, xcb_window_t wi
|
||||
return (struct managed_win *)w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a rectangle includes the whole screen.
|
||||
*/
|
||||
static inline bool rect_is_fullscreen(const session_t *ps, int x, int y, int wid, int hei) {
|
||||
return (x <= 0 && y <= 0 && (x + wid) >= ps->root_width && (y + hei) >= ps->root_height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a window is fulscreen using EWMH
|
||||
*
|
||||
* TODO(yshui) cache this property
|
||||
*/
|
||||
static inline bool
|
||||
win_is_fullscreen_xcb(xcb_connection_t *c, const struct atom *a, const xcb_window_t w) {
|
||||
xcb_get_property_cookie_t prop =
|
||||
xcb_get_property(c, 0, w, a->a_NET_WM_STATE, XCB_ATOM_ATOM, 0, 12);
|
||||
xcb_get_property_reply_t *reply = xcb_get_property_reply(c, prop, NULL);
|
||||
if (!reply) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reply->length) {
|
||||
xcb_atom_t *val = xcb_get_property_value(reply);
|
||||
for (uint32_t i = 0; i < reply->length; i++) {
|
||||
if (val[i] != a->a_NET_WM_STATE_FULLSCREEN) {
|
||||
continue;
|
||||
}
|
||||
free(reply);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
free(reply);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Set flags on a window. Some sanity checks are performed
|
||||
void win_set_flags(struct managed_win *w, uint64_t flags) {
|
||||
log_debug("Set flags %" PRIu64 " to window %#010x (%s)", flags, w->base.id, w->name);
|
||||
@@ -2817,13 +3157,15 @@ bool win_check_flags_all(struct managed_win *w, uint64_t flags) {
|
||||
*
|
||||
* It's not using w->border_size for performance measures.
|
||||
*/
|
||||
bool win_is_fullscreen(const session_t *ps, const struct managed_win *w) {
|
||||
if (!ps->o.no_ewmh_fullscreen &&
|
||||
win_is_fullscreen_xcb(ps->c.c, ps->atoms, w->client_win)) {
|
||||
return true;
|
||||
void win_update_is_fullscreen(const session_t *ps, struct managed_win *w) {
|
||||
if (!ps->o.no_ewmh_fullscreen && w->is_ewmh_fullscreen) {
|
||||
w->is_fullscreen = true;
|
||||
return;
|
||||
}
|
||||
return rect_is_fullscreen(ps, w->g.x, w->g.y, w->widthb, w->heightb) &&
|
||||
(!w->bounding_shaped || w->rounded_corners);
|
||||
w->is_fullscreen = w->g.x <= 0 && w->g.y <= 0 &&
|
||||
(w->g.x + w->widthb) >= ps->root_width &&
|
||||
(w->g.y + w->heightb) >= ps->root_height &&
|
||||
(!w->bounding_shaped || w->rounded_corners);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2849,8 +3191,8 @@ bool win_is_bypassing_compositor(const session_t *ps, const struct managed_win *
|
||||
* Check if a window is focused, without using any focus rules or forced focus
|
||||
* settings
|
||||
*/
|
||||
bool win_is_focused_raw(const session_t *ps, const struct managed_win *w) {
|
||||
return w->a.map_state == XCB_MAP_STATE_VIEWABLE && ps->active_win == w;
|
||||
bool win_is_focused_raw(const struct managed_win *w) {
|
||||
return w->a.map_state == XCB_MAP_STATE_VIEWABLE && w->is_ewmh_focused;
|
||||
}
|
||||
|
||||
// Find the managed window immediately below `i` in the window stack
|
||||
@@ -2869,5 +3211,5 @@ win_stack_find_next_managed(const session_t *ps, const struct list_node *w) {
|
||||
/// Return whether this window is mapped on the X server side
|
||||
bool win_is_mapped_in_x(const struct managed_win *w) {
|
||||
return w->state == WSTATE_MAPPING || w->state == WSTATE_FADING ||
|
||||
w->state == WSTATE_MAPPED || (w->flags & WIN_FLAGS_MAPPED);
|
||||
w->state == WSTATE_MAPPED || w->state == WSTATE_DESTROYING || (w->flags & WIN_FLAGS_MAPPED);
|
||||
}
|
||||
|
||||
70
src/win.h
70
src/win.h
@@ -96,13 +96,27 @@ struct win_geometry {
|
||||
uint16_t border_width;
|
||||
};
|
||||
|
||||
enum {
|
||||
// dwm_mask
|
||||
ANIM_PREV_TAG = 1,
|
||||
ANIM_NEXT_TAG = (1 << 1),
|
||||
ANIM_UNMAP = (1 << 2),
|
||||
ANIM_SPECIAL_MINIMIZE = (1 << 3),
|
||||
// animation_is_tag
|
||||
ANIM_IN_TAG = 1,
|
||||
ANIM_SLOW = (1 << 1),
|
||||
ANIM_FAST = (1 << 2),
|
||||
ANIM_FADE = (1 << 3),
|
||||
};
|
||||
|
||||
struct managed_win {
|
||||
struct win base;
|
||||
/// backend data attached to this window. Only available when
|
||||
/// `state` is not UNMAPPED
|
||||
void *win_image;
|
||||
void *shadow_image;
|
||||
void *mask_image;
|
||||
image_handle win_image;
|
||||
image_handle old_win_image; // Old window image for interpolating window contents during animations
|
||||
image_handle shadow_image;
|
||||
image_handle mask_image;
|
||||
/// Pointer to the next higher window to paint.
|
||||
struct managed_win *prev_trans;
|
||||
/// Number of windows above this window
|
||||
@@ -152,6 +166,8 @@ struct managed_win {
|
||||
/// opacity state, window geometry, window mapped/unmapped state,
|
||||
/// window mode of the windows above. DOES NOT INCLUDE the body of THIS WINDOW.
|
||||
/// NULL means reg_ignore has not been calculated for this window.
|
||||
/// 1 = tag prev , 2 = tag next, 4 = unmap
|
||||
uint32_t dwm_mask;
|
||||
rc_region_t *reg_ignore;
|
||||
/// Whether the reg_ignore of all windows beneath this window are valid
|
||||
bool reg_ignore_valid;
|
||||
@@ -169,6 +185,24 @@ struct managed_win {
|
||||
bool unredir_if_possible_excluded;
|
||||
/// Whether this window is in open/close state.
|
||||
bool in_openclose;
|
||||
/// Current position and destination, for animation
|
||||
double animation_center_x, animation_center_y;
|
||||
double animation_dest_center_x, animation_dest_center_y;
|
||||
double animation_w, animation_h;
|
||||
double animation_dest_w, animation_dest_h;
|
||||
/// Spring animation velocity
|
||||
double animation_velocity_x, animation_velocity_y;
|
||||
double animation_velocity_w, animation_velocity_h;
|
||||
/// Track animation progress; goes from 0 to 1
|
||||
double animation_progress;
|
||||
/// Inverse of the window distance at the start of animation, for
|
||||
/// tracking animation progress
|
||||
double animation_inv_og_distance;
|
||||
/// Animation info if it is a tag change & check if its changing window sizes
|
||||
/// 0: no tag change
|
||||
/// 1: normal tag change animation
|
||||
/// 2: tag change animation that effects window size
|
||||
uint16_t animation_is_tag;
|
||||
|
||||
// Client window related members
|
||||
/// ID of the top-level client window of the window.
|
||||
@@ -199,6 +233,14 @@ struct managed_win {
|
||||
char *class_general;
|
||||
/// <code>WM_WINDOW_ROLE</code> value of the window.
|
||||
char *role;
|
||||
/// Whether the window sets the EWMH fullscreen property.
|
||||
bool is_ewmh_fullscreen;
|
||||
/// Whether the window should be considered fullscreen. Based on
|
||||
/// `is_ewmh_fullscreen`, or the windows spatial relation with the
|
||||
/// root window. Which one is used is determined by user configuration.
|
||||
bool is_fullscreen;
|
||||
/// Whether the window is the EWMH active window.
|
||||
bool is_ewmh_focused;
|
||||
|
||||
// Opacity-related members
|
||||
/// Current window opacity.
|
||||
@@ -244,13 +286,13 @@ struct managed_win {
|
||||
switch_t shadow_force;
|
||||
/// Opacity of the shadow. Affected by window opacity and frame opacity.
|
||||
double shadow_opacity;
|
||||
/// X offset of shadow. Affected by commandline argument.
|
||||
/// X offset of shadow. Affected by command line argument.
|
||||
int shadow_dx;
|
||||
/// Y offset of shadow. Affected by commandline argument.
|
||||
/// Y offset of shadow. Affected by command line argument.
|
||||
int shadow_dy;
|
||||
/// Width of shadow. Affected by window size and commandline argument.
|
||||
/// Width of shadow. Affected by window size and command line argument.
|
||||
int shadow_width;
|
||||
/// Height of shadow. Affected by window size and commandline argument.
|
||||
/// Height of shadow. Affected by window size and command line argument.
|
||||
int shadow_height;
|
||||
/// Picture to render shadow. Affected by window size.
|
||||
paint_t shadow_paint;
|
||||
@@ -349,6 +391,8 @@ void win_update_monitor(struct x_monitors *monitors, struct managed_win *mw);
|
||||
*/
|
||||
// XXX was win_border_size
|
||||
void win_update_bounding_shape(session_t *ps, struct managed_win *w);
|
||||
/// Recheck if a window is fullscreen
|
||||
void win_update_is_fullscreen(const session_t *ps, struct managed_win *w);
|
||||
/**
|
||||
* Check if a window has BYPASS_COMPOSITOR property set
|
||||
*/
|
||||
@@ -424,17 +468,10 @@ struct managed_win *find_toplevel(session_t *ps, xcb_window_t id);
|
||||
*/
|
||||
struct managed_win *find_managed_window_or_parent(session_t *ps, xcb_window_t wid);
|
||||
|
||||
/**
|
||||
* Check if a window is a fullscreen window.
|
||||
*
|
||||
* It's not using w->border_size for performance measures.
|
||||
*/
|
||||
bool attr_pure win_is_fullscreen(const session_t *ps, const struct managed_win *w);
|
||||
|
||||
/**
|
||||
* Check if a window is focused, without using any focus rules or forced focus settings
|
||||
*/
|
||||
bool attr_pure win_is_focused_raw(const session_t *ps, const struct managed_win *w);
|
||||
bool attr_pure win_is_focused_raw(const struct managed_win *w);
|
||||
|
||||
/// check if window has ARGB visual
|
||||
bool attr_pure win_has_alpha(const struct managed_win *w);
|
||||
@@ -459,6 +496,9 @@ bool win_check_flags_all(struct managed_win *w, uint64_t flags);
|
||||
/// Mark properties as stale for a window
|
||||
void win_set_properties_stale(struct managed_win *w, const xcb_atom_t *prop, int nprops);
|
||||
|
||||
/// Determine if a window should animate
|
||||
bool attr_pure win_should_animate(session_t *ps, const struct managed_win *w);
|
||||
|
||||
static inline attr_unused void win_set_property_stale(struct managed_win *w, xcb_atom_t prop) {
|
||||
return win_set_properties_stale(w, (xcb_atom_t[]){prop}, 1);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ typedef enum {
|
||||
} winstate_t;
|
||||
|
||||
enum win_flags {
|
||||
// Note: *_NONE flags are mostly redudant and meant for detecting logical errors
|
||||
// Note: *_NONE flags are mostly redundant and meant for detecting logical errors
|
||||
// in the code
|
||||
|
||||
/// pixmap is out of date, will be update in win_process_flags
|
||||
|
||||
141
src/x.c
141
src/x.c
@@ -9,11 +9,14 @@
|
||||
#include <pixman.h>
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/damage.h>
|
||||
#include <xcb/dpms.h>
|
||||
#include <xcb/glx.h>
|
||||
#include <xcb/present.h>
|
||||
#include <xcb/randr.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/sync.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
#include <xcb/xfixes.h>
|
||||
|
||||
@@ -92,7 +95,7 @@ void x_connection_init(struct x_connection *c, Display *dpy) {
|
||||
c->previous_xerror_handler = XSetErrorHandler(xerror);
|
||||
|
||||
c->screen = DefaultScreen(dpy);
|
||||
c->screen_info = x_screen_of_display(c, c->screen);
|
||||
c->screen_info = xcb_aux_get_screen(c->c, c->screen);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,10 +182,9 @@ xcb_window_t wid_get_prop_window(struct x_connection *c, xcb_window_t wid, xcb_a
|
||||
/**
|
||||
* Get the value of a text property of a window.
|
||||
*/
|
||||
bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst,
|
||||
int *pnstr) {
|
||||
assert(ps->server_grabbed);
|
||||
auto prop_info = x_get_prop_info(&ps->c, wid, prop);
|
||||
bool wid_get_text_prop(struct x_connection *c, struct atom *atoms, xcb_window_t wid,
|
||||
xcb_atom_t prop, char ***pstrlst, int *pnstr) {
|
||||
auto prop_info = x_get_prop_info(c, wid, prop);
|
||||
auto type = prop_info.type;
|
||||
auto format = prop_info.format;
|
||||
auto length = prop_info.length;
|
||||
@@ -191,8 +193,7 @@ bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char **
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type != XCB_ATOM_STRING && type != ps->atoms->aUTF8_STRING &&
|
||||
type != ps->atoms->aC_STRING) {
|
||||
if (type != XCB_ATOM_STRING && type != atoms->aUTF8_STRING && type != atoms->aC_STRING) {
|
||||
log_warn("Text property %d of window %#010x has unsupported type: %d",
|
||||
prop, wid, type);
|
||||
return false;
|
||||
@@ -207,7 +208,7 @@ bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char **
|
||||
xcb_generic_error_t *e = NULL;
|
||||
auto word_count = (length + 4 - 1) / 4;
|
||||
auto r = xcb_get_property_reply(
|
||||
ps->c.c, xcb_get_property(ps->c.c, 0, wid, prop, type, 0, word_count), &e);
|
||||
c->c, xcb_get_property(c->c, 0, wid, prop, type, 0, word_count), &e);
|
||||
if (!r) {
|
||||
log_debug_x_error(e, "Failed to get window property for %#010x", wid);
|
||||
free(e);
|
||||
@@ -319,6 +320,17 @@ xcb_visualid_t x_get_visual_for_standard(struct x_connection *c, xcb_pict_standa
|
||||
return x_get_visual_for_pictfmt(g_pictfmts, pictfmt->id);
|
||||
}
|
||||
|
||||
xcb_visualid_t x_get_visual_for_depth(xcb_screen_t *screen, uint8_t depth) {
|
||||
xcb_depth_iterator_t depth_it = xcb_screen_allowed_depths_iterator(screen);
|
||||
for (; depth_it.rem; xcb_depth_next(&depth_it)) {
|
||||
if (depth_it.data->depth == depth) {
|
||||
return xcb_depth_visuals_iterator(depth_it.data).data->visual_id;
|
||||
}
|
||||
}
|
||||
|
||||
return XCB_NONE;
|
||||
}
|
||||
|
||||
xcb_render_pictformat_t
|
||||
x_get_pictfmt_for_standard(struct x_connection *c, xcb_pict_standard_t std) {
|
||||
x_get_server_pictfmts(c);
|
||||
@@ -328,24 +340,6 @@ x_get_pictfmt_for_standard(struct x_connection *c, xcb_pict_standard_t std) {
|
||||
return pictfmt->id;
|
||||
}
|
||||
|
||||
int x_get_visual_depth(struct x_connection *c, xcb_visualid_t visual) {
|
||||
auto setup = xcb_get_setup(c->c);
|
||||
for (auto screen = xcb_setup_roots_iterator(setup); screen.rem;
|
||||
xcb_screen_next(&screen)) {
|
||||
for (auto depth = xcb_screen_allowed_depths_iterator(screen.data);
|
||||
depth.rem; xcb_depth_next(&depth)) {
|
||||
const int len = xcb_depth_visuals_length(depth.data);
|
||||
const xcb_visualtype_t *visuals = xcb_depth_visuals(depth.data);
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (visual == visuals[i].visual_id) {
|
||||
return depth.data->depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt_and_pixmap(struct x_connection *c,
|
||||
const xcb_render_pictforminfo_t *pictfmt,
|
||||
@@ -457,6 +451,34 @@ bool x_fetch_region(struct x_connection *c, xcb_xfixes_region_t r, pixman_region
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool x_set_region(struct x_connection *c, xcb_xfixes_region_t dst, const region_t *src) {
|
||||
if (!src || dst == XCB_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t nrects = 0;
|
||||
const rect_t *rects = pixman_region32_rectangles((region_t *)src, &nrects);
|
||||
if (!rects || nrects < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
xcb_rectangle_t *xrects = ccalloc(nrects, xcb_rectangle_t);
|
||||
for (int32_t i = 0; i < nrects; i++) {
|
||||
xrects[i] =
|
||||
(xcb_rectangle_t){.x = to_i16_checked(rects[i].x1),
|
||||
.y = to_i16_checked(rects[i].y1),
|
||||
.width = to_u16_checked(rects[i].x2 - rects[i].x1),
|
||||
.height = to_u16_checked(rects[i].y2 - rects[i].y1)};
|
||||
}
|
||||
|
||||
bool success =
|
||||
XCB_AWAIT_VOID(xcb_xfixes_set_region, c->c, dst, to_u32_checked(nrects), xrects);
|
||||
|
||||
free(xrects);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
uint32_t x_create_region(struct x_connection *c, const region_t *reg) {
|
||||
if (!reg) {
|
||||
return XCB_NONE;
|
||||
@@ -560,9 +582,7 @@ _x_strerror(unsigned long serial, uint8_t major, uint16_t minor, uint8_t error_c
|
||||
const char *name = "Unknown";
|
||||
|
||||
#define CASESTRRET(s) \
|
||||
case s: \
|
||||
name = #s; \
|
||||
break
|
||||
case s: name = #s; break
|
||||
|
||||
#define CASESTRRET2(s) \
|
||||
case XCB_##s: name = #s; break
|
||||
@@ -687,27 +707,6 @@ xcb_pixmap_t x_create_pixmap(struct x_connection *c, uint8_t depth, int width, i
|
||||
return XCB_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a pixmap.
|
||||
*
|
||||
* Detect whether the pixmap is valid with XGetGeometry. Well, maybe there
|
||||
* are better ways.
|
||||
*/
|
||||
bool x_validate_pixmap(struct x_connection *c, xcb_pixmap_t pixmap) {
|
||||
if (pixmap == XCB_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto r = xcb_get_geometry_reply(c->c, xcb_get_geometry(c->c, pixmap), NULL);
|
||||
if (!r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = r->width && r->height;
|
||||
free(r);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// We don't use the _XSETROOT_ID root window property as a source of the background
|
||||
/// pixmap because it most likely points to a dummy pixmap used to keep the colormap
|
||||
/// associated with the background pixmap alive but we listen for it's changes and update
|
||||
@@ -777,6 +776,31 @@ err:
|
||||
return false;
|
||||
}
|
||||
|
||||
void x_request_vblank_event(struct x_connection *c, xcb_window_t window, uint64_t msc) {
|
||||
auto cookie = xcb_present_notify_msc(c->c, window, 0, msc, 1, 0);
|
||||
set_cant_fail_cookie(c, cookie);
|
||||
}
|
||||
|
||||
static inline bool dpms_screen_is_off(xcb_dpms_info_reply_t *info) {
|
||||
// state is a bool indicating whether dpms is enabled
|
||||
return info->state && (info->power_level != XCB_DPMS_DPMS_MODE_ON);
|
||||
}
|
||||
|
||||
bool x_check_dpms_status(struct x_connection *c, bool *screen_is_off) {
|
||||
auto r = xcb_dpms_info_reply(c->c, xcb_dpms_info(c->c), NULL);
|
||||
if (!r) {
|
||||
log_error("Failed to query DPMS status.");
|
||||
return false;
|
||||
}
|
||||
auto now_screen_is_off = dpms_screen_is_off(r);
|
||||
if (*screen_is_off != now_screen_is_off) {
|
||||
log_debug("Screen is now %s", now_screen_is_off ? "off" : "on");
|
||||
*screen_is_off = now_screen_is_off;
|
||||
}
|
||||
free(r);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a struct conv to a X picture convolution filter, normalizing the kernel
|
||||
* in the process. Allow the caller to specify the element at the center of the kernel,
|
||||
@@ -829,8 +853,8 @@ void x_create_convolution_kernel(const conv *kernel, double center,
|
||||
/// Returns {-1, -1, -1, -1, -1, 0} on failure
|
||||
struct xvisual_info x_get_visual_info(struct x_connection *c, xcb_visualid_t visual) {
|
||||
auto pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
auto depth = x_get_visual_depth(c, visual);
|
||||
if (!pictfmt || depth == -1) {
|
||||
auto depth = xcb_aux_get_depth_of_visual(c->screen_info, visual);
|
||||
if (!pictfmt || depth == 0) {
|
||||
log_error("Invalid visual %#03x", visual);
|
||||
return (struct xvisual_info){-1, -1, -1, -1, -1, 0};
|
||||
}
|
||||
@@ -855,19 +879,6 @@ struct xvisual_info x_get_visual_info(struct x_connection *c, xcb_visualid_t vis
|
||||
};
|
||||
}
|
||||
|
||||
xcb_screen_t *x_screen_of_display(struct x_connection *c, int screen) {
|
||||
xcb_screen_iterator_t iter;
|
||||
|
||||
iter = xcb_setup_roots_iterator(xcb_get_setup(c->c));
|
||||
for (; iter.rem; --screen, xcb_screen_next(&iter)) {
|
||||
if (screen == 0) {
|
||||
return iter.data;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void x_update_monitors(struct x_connection *c, struct x_monitors *m) {
|
||||
x_free_monitor_info(m);
|
||||
|
||||
|
||||
34
src/x.h
34
src/x.h
@@ -27,6 +27,7 @@ typedef struct winprop {
|
||||
int16_t *p16;
|
||||
int32_t *p32;
|
||||
uint32_t *c32; // 32bit cardinal
|
||||
xcb_atom_t *atom;
|
||||
};
|
||||
unsigned long nitems;
|
||||
xcb_atom_t type;
|
||||
@@ -207,17 +208,6 @@ void x_discard_pending(struct x_connection *c, uint32_t sequence);
|
||||
/// This function logs X errors, or aborts the program based on severity of the error.
|
||||
void x_handle_error(struct x_connection *c, xcb_generic_error_t *ev);
|
||||
|
||||
/**
|
||||
* Send a request to X server and get the reply to make sure all previous
|
||||
* requests are processed, and their replies received
|
||||
*
|
||||
* xcb_get_input_focus is used here because it is the same request used by
|
||||
* libX11
|
||||
*/
|
||||
static inline void x_sync(struct x_connection *c) {
|
||||
free(xcb_get_input_focus_reply(c->c, xcb_get_input_focus(c->c), NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific attribute of a window.
|
||||
*
|
||||
@@ -271,12 +261,11 @@ xcb_window_t wid_get_prop_window(struct x_connection *c, xcb_window_t wid, xcb_a
|
||||
* array
|
||||
* @param[out] pnstr Number of strings in the array
|
||||
*/
|
||||
bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst,
|
||||
int *pnstr);
|
||||
bool wid_get_text_prop(struct x_connection *c, struct atom *atoms, xcb_window_t wid,
|
||||
xcb_atom_t prop, char ***pstrlst, int *pnstr);
|
||||
|
||||
const xcb_render_pictforminfo_t *
|
||||
x_get_pictform_for_visual(struct x_connection *, xcb_visualid_t);
|
||||
int x_get_visual_depth(struct x_connection *, xcb_visualid_t);
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt_and_pixmap(struct x_connection *,
|
||||
@@ -321,6 +310,9 @@ x_create_picture_with_visual(struct x_connection *, int w, int h, xcb_visualid_t
|
||||
/// Fetch a X region and store it in a pixman region
|
||||
bool x_fetch_region(struct x_connection *, xcb_xfixes_region_t r, region_t *res);
|
||||
|
||||
/// Set an X region to a pixman region
|
||||
bool x_set_region(struct x_connection *c, xcb_xfixes_region_t dst, const region_t *src);
|
||||
|
||||
/// Create a X region from a pixman region
|
||||
uint32_t x_create_region(struct x_connection *c, const region_t *reg);
|
||||
|
||||
@@ -356,8 +348,6 @@ const char *x_strerror(xcb_generic_error_t *e);
|
||||
|
||||
xcb_pixmap_t x_create_pixmap(struct x_connection *, uint8_t depth, int width, int height);
|
||||
|
||||
bool x_validate_pixmap(struct x_connection *, xcb_pixmap_t pxmap);
|
||||
|
||||
/**
|
||||
* Free a <code>winprop_t</code>.
|
||||
*
|
||||
@@ -408,14 +398,22 @@ struct xvisual_info x_get_visual_info(struct x_connection *c, xcb_visualid_t vis
|
||||
|
||||
xcb_visualid_t x_get_visual_for_standard(struct x_connection *c, xcb_pict_standard_t std);
|
||||
|
||||
xcb_visualid_t x_get_visual_for_depth(xcb_screen_t *screen, uint8_t depth);
|
||||
|
||||
xcb_render_pictformat_t
|
||||
x_get_pictfmt_for_standard(struct x_connection *c, xcb_pict_standard_t std);
|
||||
|
||||
xcb_screen_t *x_screen_of_display(struct x_connection *c, int screen);
|
||||
|
||||
/// Populates a `struct x_monitors` with the current monitor configuration.
|
||||
void x_update_monitors(struct x_connection *, struct x_monitors *);
|
||||
/// Free memory allocated for a `struct x_monitors`.
|
||||
void x_free_monitor_info(struct x_monitors *);
|
||||
|
||||
uint32_t attr_deprecated xcb_generate_id(xcb_connection_t *c);
|
||||
|
||||
/// Ask X server to send us a notification for the next end of vblank.
|
||||
void x_request_vblank_event(struct x_connection *c, xcb_window_t window, uint64_t msc);
|
||||
|
||||
/// Update screen_is_off to reflect the current DPMS state.
|
||||
///
|
||||
/// Returns true if the DPMS state was successfully queried, false otherwise.
|
||||
bool x_check_dpms_status(struct x_connection *c, bool *screen_is_off);
|
||||
|
||||
@@ -58,6 +58,14 @@ struct test_file_metadata __attribute__((weak)) * test_file_head;
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TEST_NOTEQUAL(a, b) \
|
||||
do { \
|
||||
if ((a) == (b)) { \
|
||||
SET_FAILURE(#a " == " #b, false); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TEST_TRUE(a) \
|
||||
do { \
|
||||
if (!(a)) { \
|
||||
@@ -69,11 +77,13 @@ struct test_file_metadata __attribute__((weak)) * test_file_head;
|
||||
#define TEST_STREQUAL(a, b) \
|
||||
do { \
|
||||
if (strcmp(a, b) != 0) { \
|
||||
const char *part2 = " != " #b; \
|
||||
size_t len = strlen(a) + strlen(part2) + 3; \
|
||||
char *buf = malloc(len); \
|
||||
snprintf(buf, len, "\"%s\"%s", a, part2); \
|
||||
SET_FAILURE(buf, true); \
|
||||
const char *test_strequal__part2 = " != " #b; \
|
||||
size_t test_strequal__len = \
|
||||
strlen(a) + strlen(test_strequal__part2) + 3; \
|
||||
char *test_strequal__buf = malloc(test_strequal__len); \
|
||||
snprintf(test_strequal__buf, test_strequal__len, "\"%s\"%s", a, \
|
||||
test_strequal__part2); \
|
||||
SET_FAILURE(test_strequal__buf, true); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -81,11 +91,27 @@ struct test_file_metadata __attribute__((weak)) * test_file_head;
|
||||
#define TEST_STRNEQUAL(a, b, len) \
|
||||
do { \
|
||||
if (strncmp(a, b, len) != 0) { \
|
||||
const char *part2 = " != " #b; \
|
||||
size_t len2 = len + strlen(part2) + 3; \
|
||||
char *buf = malloc(len2); \
|
||||
snprintf(buf, len2, "\"%.*s\"%s", (int)len, a, part2); \
|
||||
SET_FAILURE(buf, true); \
|
||||
const char *test_strnequal__part2 = " != " #b; \
|
||||
size_t test_strnequal__len2 = \
|
||||
len + strlen(test_strnequal__part2) + 3; \
|
||||
char *test_strnequal__buf = malloc(test_strnequal__len2); \
|
||||
snprintf(test_strnequal__buf, test_strnequal__len2, \
|
||||
"\"%.*s\"%s", (int)len, a, test_strnequal__part2); \
|
||||
SET_FAILURE(test_strnequal__buf, true); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TEST_STREQUAL3(str, expected, len) \
|
||||
do { \
|
||||
if (len != strlen(expected) || strncmp(str, expected, len) != 0) { \
|
||||
const char *test_strequal3__part2 = " != " #expected; \
|
||||
size_t test_strequal3__len2 = \
|
||||
len + strlen(test_strequal3__part2) + 3; \
|
||||
char *test_strequal3__buf = malloc(test_strequal3__len2); \
|
||||
snprintf(test_strequal3__buf, test_strequal3__len2, \
|
||||
"\"%.*s\"%s", (int)len, str, test_strequal3__part2); \
|
||||
SET_FAILURE(test_strequal3__buf, true); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -199,6 +225,9 @@ static inline void __attribute__((constructor(102))) run_tests(void) {
|
||||
#define TEST_EQUAL(a, b) \
|
||||
(void)(a); \
|
||||
(void)(b)
|
||||
#define TEST_NOTEQUAL(a, b) \
|
||||
(void)(a); \
|
||||
(void)(b)
|
||||
#define TEST_TRUE(a) (void)(a)
|
||||
#define TEST_STREQUAL(a, b) \
|
||||
(void)(a); \
|
||||
@@ -207,5 +236,8 @@ static inline void __attribute__((constructor(102))) run_tests(void) {
|
||||
(void)(a); \
|
||||
(void)(b); \
|
||||
(void)(len)
|
||||
|
||||
#define TEST_STREQUAL3(str, expected, len) \
|
||||
(void)(str); \
|
||||
(void)(expected); \
|
||||
(void)(len)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user