Commit graph

27306 commits

Author SHA1 Message Date
Vlad Zahorodnii
913a850584 Add missing size check in Placement::placeOnScreenDisplay()
In order to center a window, kwin needs to know the window size.
2024-08-23 09:01:56 +00:00
Vlad Zahorodnii
6379b8b01a Clean up Placement::placeSmart()
Avoid using Window::frameGeometry() because its position is invalid.

In the future, the XdgToplevelWindow would need to run the placement
code before updating the Window::frameGeometry(). In order to prepare
for that, this change also makes placeSmart() pull the window size from
a cached QSizeF() object.
2024-08-23 09:01:56 +00:00
Vlad Zahorodnii
646f071291 Clean up Placement::placeCascaded()
Avoid using Window::frameGeometry() because its position is invalid.

In the future, the XdgToplevelWindow would need to run the placement
code before updating the Window::frameGeometry(). In order to prepare
for that, this change also makes placeCascaded() pull the window size
from a cached QSizeF() object.
2024-08-23 09:01:56 +00:00
Vlad Zahorodnii
3810811730 Stop Placement::cascadeIfCovering() from changing window geometry
The main motivation behind this change is to ensure that every placeXyz()
function issues only one move() or moveResize() function so the placement
code is more refactorable, and in general, it's a good idea to avoid
changing the geometry until the final geometry is finally known.

Note that it changes the behavior of placeOnMainWindow() and
placeUnderMouse(). Those methods will not anymore potentially resize
the window. It was done to avoid a flicker glitch on Wayland. This is
the responsibility of the caller (X11Window) to further inspect whether
the window needs to be resized. However, for now, let's keep things
simple and revisit this if somebody actually complains about it.
2024-08-23 09:01:56 +00:00
Vlad Zahorodnii
4258797402 Port Workspace::cascadeOffset() away from Window::frameGeometry()
Workspace::cascadeOffset() can be called by placement code before the
frame geometry has a valid position. That is wrong. In order to avoid
that, use the placement area that we are given.
2024-08-23 09:01:56 +00:00
l10n daemon script
428c4c4fd1 GIT_SILENT Sync po/docbooks with svn 2024-08-23 01:30:02 +00:00
l10n daemon script
149b49f160 SVN_SILENT made messages (.desktop file) - always resolve ours
In case of conflict in i18n, keep the version of the branch "ours"
To resolve a particular conflict, "git checkout --ours path/to/file.desktop"
2024-08-23 01:22:02 +00:00
Xaver Hugl
d0c4aeeb08 options: enable separate screen focus by default
When the user closes the active window, with separate screen focus disabled, a
window on the other screen might get activated, which also switches the active
screen to the other one. As this is quite unintuitive, and in my testing having
separate screen focus enabled didn't have any other unintuitive side effects,
this commit enables separate screen focus by default
2024-08-23 00:33:01 +02:00
Xaver Hugl
c3c3f56e98 implement a proper tone mapping algorithm
Instead of just clipping when HDR content is brighter than the maximum luminance the
screen can show, when HDR metadata indicates this could happen, KWin now
- converts the rgb colors to ICtCp, to split luminance and color
- applies a tone mapping curve that maps the intensity component from
 - [0, reference] to [0, newReference] linearly
 - [reference, max content luminance] to [newReference, max display luminance] nonlinearly
- converts the resulting ICtCp color back to rgb

The result is that HDR content looks much, much better on SDR displays, at least when decent
HDR metadata is provided.
As wrong metadata could cause this tone mapping to wrongly kick in in games for example, the
environment variable KWIN_DISABLE_TONEMAPPING is provided to disable tone mapping and fall back
to clipping again instead.
2024-08-22 23:04:00 +02:00
Vlad Zahorodnii
e03fb08bcc utils: Validate svg cursor metadata better
Metadata array must contain at least one item.
2024-08-22 16:50:27 +03:00
Vlad Zahorodnii
5cff8cd2d1 utils: Assume that the top object in svg cursor metadata is an array
This adapts the svg cursor loading code to the recent metadata format
changes.
2024-08-22 14:07:56 +03:00
Vlad Zahorodnii
95611189d5 effect: Refuse starting quick effect if keyboard cannot be grabbed
If effects->grabKeyboard() fails and effects->ungrabKeyboard() is called
later, kwin will crash due to an assert in the ungrabKeyboard() function.

This matters only on X11.
2024-08-22 07:25:21 +00:00
l10n daemon script
d474a6795b GIT_SILENT Sync po/docbooks with svn 2024-08-22 01:35:59 +00:00
l10n daemon script
f781d48d86 SVN_SILENT made messages (.desktop file) - always resolve ours
In case of conflict in i18n, keep the version of the branch "ours"
To resolve a particular conflict, "git checkout --ours path/to/file.desktop"
2024-08-22 01:22:58 +00:00
Xaver Hugl
e7780f1ab3 backends/drm: implement damage tracking for the color management shadow buffer
This significantly reduces the amount of pixels that have to be repainted in most frames
while an ICC profile is set.

BUG: 477223
2024-08-21 23:01:00 +02:00
Vlad Zahorodnii
d56dbb04e6 Use for range based loop in X11Window::restackWindow() when traversing through stack
It's more readable and it also makes code more refactorable. For example,
if somebody makes Workspace::stackingOrder() return a normal QList, KWin
won't crash at this code.
2024-08-21 20:39:25 +03:00
Vlad Zahorodnii
0622526e8f Drop "send_event" boolean trap in X11Window::restackWindow()
The synthetic ConfigureNotify event is not sent when the stack mode is
TopIf and BottomIf, i.e. the way the restackWindow() function handles
the "send_event" argument is inconsistent.

And the window manager doesn't have to send a synthetic configure event
when processing a _NET_RESTACK_WINDOW client message. It must do it only
after handling a ConfigureRequest request, which
the X11Window::configureRequestEvent() function already does.

So rather than fixing the handling of the "send_event" argument, this
change removes that boolean trap instead.
2024-08-21 17:14:02 +00:00
Vlad Zahorodnii
eff06e4109 Drop Workspace::lowerWindowRequest(Window *window)
It's unused.
2024-08-21 16:59:37 +00:00
Vlad Zahorodnii
4a14644885 Guard Workspace::raiseWindowRequest() with a KWIN_BUILD_X11 ifdef
raiseWindowRequest() is an X11 specific detail.
2024-08-21 16:59:37 +00:00
Vlad Zahorodnii
ef9d3a1cd0 Add safety guards in FocusChain::move{After,Before}Window()
If the `window` is the same as the `reference`, the `window` will be
inserted at index "-1", which is wrong.
2024-08-21 16:28:37 +00:00
Vlad Zahorodnii
22e10f6efb Correct traversal order in FocusChain::moveAfterWindowInChain()
The first item in the `chain` list corresponds to the last item in
the focus chain. The last item in the `chain` list corresponds to
the first item in the focus chain.

Given that, we need to traverse the list from the start to the end in
order to find the first window owned by the same app as `reference`.
2024-08-21 16:17:18 +00:00
Xaver Hugl
1c7c16f28b core/renderloop: add a debug print for presentation mode changes
It can be useful for debugging and these changes don't happen too often
2024-08-21 16:02:19 +00:00
Xaver Hugl
5316cf8d50 rules: add window rule to force tearing on or off
This allows the user to override which presentation mode individual apps request
2024-08-21 16:02:19 +00:00
Xaver Hugl
1dab5fb328 backends/drm: support tearing with atomic modesetting
Whenever tearing is desired, this does an atomic test to figure out if the current
configuration can do tearing - if not, the backend just transparently falls back to
synchronous commits.
As the kernel (as of Linux 6.9) rejects all commits that are both async and modify
more than the primary plane FB_ID property, this disables the cursor plane and
IN_FENCE_FD usage, to make it more likely for the atomic commit to succeed.
Once these restrictions are loosened, these checks can be removed as well.
2024-08-21 16:02:19 +00:00
Vlad Zahorodnii
43ab00a337 Port X11Window::restackWindow() to Workspace::stackAbove() 2024-08-21 12:33:02 +00:00
Vlad Zahorodnii
bca341c70b Introduce Workspace::stackAbove()
The main purpose is to simplify X11 Above stack mode implementation.
2024-08-21 12:33:02 +00:00
Vlad Zahorodnii
1ff2846579 Remove boolean trap in Workspace::stackBelow()
Boolean traps are a code smell that makes code harder to read and it
also usually makes the api more difficult.

The force == false is used by two places:

 - in Workspace::restackWindowUnderActive()
 - and in X11Window::restackWindow()

Technically, the restackWindow() function doesn't need the force == false
behavior because the stackBelow() function is used in code paths where an
explicit sibling is provided.

The restackWindowUnderActive() function is trickier, it is used in the case
when kwin rejects to raise a newly mapped window, so for that purpose, I
changed the function so it picks the lowest window that belongs to the same
application as m_activeWindow.

The result of this change is that the stackBelow() is simpler and its
behavior is much more predictable, which is important when analyzing the
code that updates the stack.
2024-08-21 12:32:51 +00:00
Vlad Zahorodnii
b6c1f7fb51 Re-arrange code in X11Window::restackWindow()
Above and Below modes should be handled as follows:

   if (sibling) {
       workspace_stack_below/above(window, sibling);
   } else {
       workspace_lower/raise(window);
   }

But with the current code, it's difficult to see. This change rearranges
the code in the restackWindow() so it's more clear how the Above and the
Below modes are implemented.

It also moves workspace()->findClient(Predicate::WindowMatch, above); to
the top because all branches have it.
2024-08-21 11:37:57 +03:00
Vlad Zahorodnii
e022bd7141 Rename Workspace::restack() function
There are several ways how a window can be restacked relative to another:
either by placing it below the reference window or above the reference
window.

Currently, the restack() function places the given window below the
refererence window. But it's hard to decipher from the name, one needs
to take a look at the argument names to understand what's going on.

Another reason to rename is that it could be useful to have a stackAbove()
function to make X11Window::restackWindow() implementation simpler and
more straightforward.
2024-08-21 10:59:40 +03:00
Vlad Zahorodnii
4bc74d6831 scene: Ignore xwayland window shape
The shape region is used to clip the window contents. But, in practice,
it's used by a few applications. The most notable is xeyes.

The APIs that the shape region requires are manageable, but it would be
much preferred if we had a much simpler design.

In terms of the shape region support on Wayland, it's not widely
supported across all wayland compositors, to my knowledge, only two
support it, some compositors even want to disable XSHAPE extension at all.

This change makes the Xwayland windows ignore the shape region to see if
any real world applications are affected by it. If not, then we could
safely simplify the scene bits later.

The Xorg session is unaffected by this change.
2024-08-21 07:10:42 +00:00
l10n daemon script
ec04284518 GIT_SILENT Sync po/docbooks with svn 2024-08-21 01:40:19 +00:00
Vlad Zahorodnii
f1eb095a0c opengl: Drop GLTexture::clear()
It's used only by the decoration renderer, but even it doesn't need it
because the atlas parts are padded.

From the API point of view, it's worth looking for alternative solutions,
like integrating the render target clear step in the render passes. And
texture uploading code usually doesn't need to clear the texture because
it is going to overwrite its contents anyway.
2024-08-20 22:38:13 +00:00
Xaver Hugl
874189f11b scene/workspacescene: also check for occlusion of the parent item
Somehow this was dropped in a rebase of def0bde5e9
2024-08-20 21:52:55 +00:00
David Redondo
aa88904b53 decorations: Show tooltip at current cursor position
instead of at the mouse position. Fixes tooltips showing
up in wrong places when using tablets.
BUG: 491143
FIXED-IN: 6.1.5
2024-08-20 20:54:53 +00:00
Vlad Zahorodnii
76eb1d20b9 wayland: Allow mapping more than one shm buffer at the same time
The shared memory buffer may need to install a SIGBUS handler if the
compositor _may_ access the data outside of the buffer.

However, signal handling requires great care. For the simplicity sake,
only one shared memory buffer is allowed to be accessed at the time.
But such a restricted access policy is inconvenient and requires us
making client buffer contents copies.

This change eases the restrictions on map() and unmap() functions so
several buffers can be accessed simulatenously.

Note that atomic pointers are used because a signal handler can be
invoked at any point in the main thread's execution. Even though
"a = b" is a single operation from the developer's pov, it can take
several steps for the CPU to store a new value to the variable. The
atomic pointers ensure that assignments to the next and s_accessedBuffers
happen atomically.

Also keep in mind that we cannot start removing copy() calls yet
because the ShmClientBuffer life time management requires further
changes, which I believe, are out of the scope of this patch.
2024-08-20 22:32:38 +03:00
Vlad Zahorodnii
0162aea100 wayland: Store shm pool mapping in a shared pointer
ShmClientBuffer needs to hold a reference to the old memory
map while the buffer is mapped. Currently, it's not a problem
because unmap() must be called soon after map(). But in case
we relax that constraint, shm_pool.resize() can change the
memory map in the ShmPool with a new one, which can cause issues
for the SIGBUS handler because it won't be able to find the
right mapping object.
2024-08-20 22:32:38 +03:00
Xaver Hugl
b8b900891b scene/workspacescene: don't iterate through all child items twice
Instead, use an iterator for the second loop to pick up where the first loop stopped
2024-08-20 14:52:40 +00:00
Gabriel Souza Franco
60e3964322 opengl/gltexture: Fix format for 565 textures
> GL_INVALID_OPERATION is generated if type is one of [...]
> GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, [...]
> and format is not GL_RGB.
2024-08-20 14:28:09 +00:00
Vlad Zahorodnii
6a1db91191 wayland: Check that wl_shm buffer stride is multiple of bytes per pixel
This is needed to ensure that the values passed to GL_UNPACK_ROW_LENGTH
are reasonable. It's not described in the spec but wlroots already does
the same.
2024-08-20 14:05:59 +00:00
Vlad Zahorodnii
49b2b0d001 scene: Drop ItemRendererOpenGL::RenderNode::coordinateType
All render nodes have unnormalized texture coordinates now, so this
field is not needed anymore.
2024-08-20 13:26:37 +00:00
Vlad Zahorodnii
d12112b7a5 scene: Make ImageItem provide device texture coordinates
The main motivation behind this change is to make the ItemRendererOpenGL
use a homogeneous coordinate space for texture coordinates in order to
simplify rendering code.

The device pixels have been chosen because they are more agnostic about
the graphics api.
2024-08-20 13:26:37 +00:00
Vlad Zahorodnii
f002e20354 scene: Make SurfaceItem provide device texture coordinates
The main motivation behind this change is to make the ItemRendererOpenGL
use a homogeneous coordinate space for texture coordinates in order to
simplify rendering code.

The device pixels have been chosen because they are more agnostic about
the graphics api.
2024-08-20 13:26:37 +00:00
Xaver Hugl
8a5f469f95 backends/drm: implement damage tracking for multi gpu transfers
Doesn't seem to help on my system, but maybe it helps with different drivers
2024-08-20 13:04:18 +00:00
Vlad Zahorodnii
36c447a35a autotests: Add X11 stack tests 2024-08-20 12:42:49 +00:00
Vlad Zahorodnii
9c611ddaea Fix a crash in computeLayer()
On X11, the stack order of a window can be changed in multiple ways:

- Opposite
- TopIf
- BottomIf
- Above
- Below

You would pass either of those modes plus maybe the above window id. For
this crash, the relevant mode is Above.

Since the Workspace only has one restack function that places the given
window right under the reference window, the Above stack mode
implementation performs a quirk: it walks through the stack in order to
find a window right above the reference window and pass it to the
restack() function.

However, it could be that the window that wants to be restacked is already
above the reference window, so that same window would be passed as the
"under" window to the restack() function.

It's nothing but a miracle that we have not received major complaints
about this issue until now.

The restack() function doesn't like `window` and `under` to be the same
because of code like

    unconstrained_stacking_order.removeAll(window);
    unconstrained_stacking_order.insert(unconstrained_stacking_order.indexOf(under), window);

The removeAll() function would effectively remove both `window` and `under`
from the unconstrained stack, which breaks the next line because the
indexOf() would return -1, i.e.

    unconstrained_stacking_order.insert(-1, window);

This is the reason why the unconstrained_stacking_order contains strange
values such as `0xe`.

In order to fix the crash, this change adds some code to short-circuit
the restack() function if the passed in window and the reference window
are the same. It would be great to clean up X11Window::restackWindow()
and also add ergonomic restack functions in the Workspace, but this can
be done later. The major blocker is lack of proper test coverage of
X11 bits at the moment.

Last but not least, I would like to express my profound gratitude to
Peter Strick for filing the crash report AND providing a VM image that
helped massively with reproducing the crash and finally fixing it.

BUG: 491618
2024-08-20 12:27:41 +00:00
Vlad Zahorodnii
d028e3b1e9 Make Workspace::removeUnmanaged() keep the window in the stack
It's leftover after the Deleted type. The unmanaged window will be
removed from the stack when all its references are dropped and
Workspace::removeDeleted() is called.

CCBUG: 491618
2024-08-20 12:09:40 +00:00
Vlad Zahorodnii
315fff68e9 opengl: Drop unnecessary 16 bit texture support checks
16 bit textures are supported universally in OpenGL.
2024-08-20 11:57:19 +00:00
Vlad Zahorodnii
f3406a033c opengl: Set GL_UNPACK_ROW_LENGTH in GLTexture::upload()
The image stride can be other than "width * bpp". In order to properly
handle such a case, we need to set GL_UNPACK_ROW_LENGTH to skip the right
amount of pixels between consecutive rows.

Co-authored-by: Gabriel Souza Franco <gabrielfrancosouza@gmail.com>
2024-08-20 11:57:19 +00:00
Vlad Zahorodnii
31adedba3a opengl: Re-arrange code in GLTexture::upload()
Re-arrange the code so it's easier to set GL_UNPACK_ROW_LENGTH.
2024-08-20 11:57:19 +00:00
Xaver Hugl
def0bde5e9 scene/workspacescene: do occlusion testing for direct scanout
Some clients have two or more completely opaque surfaces stacked on top of each other,
optimizing the lower ones out makes direct scanout happen more often and more efficiently
when multiple planes are involved
2024-08-20 13:05:02 +02:00