Commit Graph

68 Commits (master)

Author SHA1 Message Date
Vlad Zahorodnii 6f153552da Allow calling setFrameGeometry() while the client is being resized
Currently, if some script attempts to resize a window while it's being
interactively resized, the corresponding change won't be propagated to
the X server.

The main reason for that is that we don't want to configure the frame
window, the wrapper window, and the client window twice. However, since
Xcb::Window keeps track of the last configured geometry, we can adjust
X11Client::updateServerGeometry() so it only configures windows that
have mismatching geometry.

By doing so, the setFrameGeometry() function can be called by scripts
even when the associated X11 window is being interactively resized.

Note that this bug doesn't affect Wayland windows.

BUG: 426988
2020-09-29 13:55:41 +00:00
Vlad Zahorodnii a9fd5ac19f Move struts logic to AbstractClient 2020-09-03 18:11:44 +00:00
Adrien Faveraux 788c65d260 Fix Build Warning 2020-08-26 19:24:02 +02:00
Vlad Zahorodnii 90b53f416c Use universal helper for writing toplevels to QDebug streams
Toplevel::debug() is one of annoyances that you need to deal with when
implementing a new client type. It can be tempting to just write "this"
to the stream, but it will result in a crash.

In order to make implementing new client types easier, this change
introduces a debug stream insertion operator overload that works for all
kinds of the Toplevel class.
2020-08-21 11:42:53 +00:00
Vlad Zahorodnii 3e9b722f8c Explicitly indicate support for window rules
This way it's more difficult to overlook the case where a new client
type unexpectedly advertises that it supports window rules.
2020-08-20 16:18:59 +00:00
Vlad Zahorodnii 9e74199e27 Refactor color scheme related code
Currently, we have two functions that update the color scheme for a
client - updateColorScheme(QString) and updateColorScheme(). Even though
they both share the same name, they do different things. The first one
sets the specified color scheme, while the other determines the color
scheme preferred by the client and assigns it.

This change refactors the color scheme initialization code so we no
longer need those two methods. The setColorScheme() method sets the
specified color scheme, and the preferredColorScheme() method returns
the color scheme preferred by the client. Sub-classes of AbstractClient
can override the preferredColorScheme() method in order to add support
for platform-specific color scheme protocols.

The end result: color scheme related code is a bit more comprehensible.
2020-08-19 15:18:50 +00:00
Vlad Zahorodnii 4ce853e8e4 Prettify license headers 2020-08-07 19:57:56 +00:00
Vlad Zahorodnii 1fb9f6f13a Switch to SPDX license markers
The main advantage of SPDX license identifiers over the traditional
license headers is that it's more difficult to overlook inappropriate
licenses for kwin, for example GPL 3. We also don't have to copy a
lot of boilerplate text.

In order to create this change, I ran licensedigger -r -c from the
toplevel source directory.
2020-08-07 19:57:56 +00:00
Vlad Zahorodnii 19ad172584 Survive Xwayland crashes
If the Xwayland process crashes, it will bring down the entire session
together with itself. Obviously, we don't want that. At least, Wayland
clients should survive the crash.

This change refactors relevant X11 parts to handle Xwayland crashes in a
less fatal way.

In order to handle Xwayland crashes better, a pair of start() and stop()
methods had been introduced in the Xwayland class to allow starting and
stopping the Xwayland process at any moment.

If we detect that the Xwayland process has crashed, we will immediately
stop the Xwayland server, which in its turn will deactivate the socket
notifier and destroy all connected X11 clients. Unfortunately, a couple
of subtle changes in X11Client::releaseWindow() and Unmanaged::release()
had to be made to ensure that we are left with a valid state after the
Xwayland server has been stopped.
2020-08-05 08:48:00 +00:00
Vlad Zahorodnii 555885072d Check if we successfully restored input focus
In rare cases, Workspace::restoreFocus() may fail, for example when the
most recently activated client is about to be destroyed or unmapped.

If it happens that we cannot restore the focus, then mark the window in
FocusIn event as active.

CCBUG: 424223
2020-07-22 12:29:41 +00:00
Vlad Zahorodnii 80a31ab4b7 Make setFrameGeometry() re-entrant for X and internal clients
If AbstractClient::setFrameGeometry() is called from a slot connected
directly to the frameGeometryChanged() signal, then is there a good
chance that kwin will fall into an infinite recursion. However, that's
the case with only X11 and internal clients.

The root cause of the infinite recursion is that both X11Client and
InternalClient compare the new geometry against the geometry before
update blocking. In order to fix the bug, we simply need to ensure that
updateGeometryBeforeUpdateBlocking() has been called before we start
emitting the frameGeometryChanged() signal.

Furthermore, a couple of tests were added to ensure that we won't hit
this subtle bug again.
2020-07-22 05:51:23 +00:00
Vlad Zahorodnii 2717252861 Partially revert a0c4a8e766
Unfortunately, a0c4a8e766 has a major bug
where clients that track focus events may get confused by focusToNull().

One such a notable example is Dota 2. It tracks the focus events to
minimize itself after the keyboard focus has been lost as well stop
playing music while it's in background. So, when we call focusToNull(),
Dota 2 will receive a corresponding FocusOut event and ask the window
manager to minimize it. It doesn't really matter that the FocusOut
event is going to be followed by a FocusIn event because when a window
is minimized, kwin will activate the next one in the focus chain.

Since those issues can't be fixed from the window manager's side, this
patch partially reverts a0c4a leaving only the autotest.

BUG: 424223
FIXED-IN: 5.19.4
2020-07-21 12:56:21 +03:00
Vlad Zahorodnii 9c55c01767 Introduce a signal that notifies about new buffer geometry
The new signal can be useful if one wants to watch a toplevel for buffer
geometry updates. This can be especially useful for input related code
because the position of the upper left corner of the main surface is used
to compute the input transformation matrix.
2020-07-17 11:56:22 +00:00
Vlad Zahorodnii 4a6badc22c Ignore setActive() for windows that are being deleted
We may call setActive() on a window that is being deleted. We cannot
guarantee that at that moment the X11 window or the Wayland surface is
still valid. So, the best course of actions is to do nothing.

BUG: 424255
2020-07-16 17:04:09 +03:00
Vlad Zahorodnii fa7fe79825 Merge branch 'Plasma/5.19' 2020-06-25 16:14:12 +03:00
Vlad Zahorodnii 578ede2dd7 Merge branch 'Plasma/5.18' into Plasma/5.19 2020-06-25 16:13:57 +03:00
Vlad Zahorodnii a0c4a8e766 [x11] Force FocusIn events for already focused windows
Depending on the current focus stealing prevention level, it's possible
for kwin to call XSetInputFocus() on a window that already has the input
focus. In which case, we won't receive the corresponding FocusIn event
and the client will remain inactive from kwin's perspective even though
it isn't.

In order to work around this issue, we can move the input focus to the
null window. By doing so, it's guaranteed that we're going to receive
the matching FocusIn event for the client.

This commit indirectly fixes a bug where fullscreen games are displayed
below panels.
2020-06-25 13:12:44 +00:00
Vlad Zahorodnii c03b4879f0 Merge branch 'Plasma/5.19' 2020-06-24 17:26:19 +03:00
Vlad Zahorodnii ec5a0249e2 [x11] Hold a passive grab on buttons only when needed
Due to a bug in the XI2 protocol, clients have to reset scroll valuators
on XI_Enter because the scroll valuators might have changed while the
pointer was elsewhere. The XI_Enter event is usually sent when an input
device enters the window, but it can also be generated by a passive grab.

If an XI_Enter event has been generated by a passive grab, the client
should not reset scroll valuators. Unfortunately, there is no any
reliable way for the client to determine if an XI_Enter event has been
sent in response to a deactivated passive grab. A correct fix for the
scroll issues in GTK apps would involve changes in the XI2 protocol.

As a work around, we can hold a passive grab only if the current mouse
wheel action is either "Activate and scroll" or "Activate, raise, and
scroll."

BUG: 394772
FIXED-IN: 5.19.3
2020-06-24 13:48:54 +00:00
Vlad Zahorodnii cc3eb54b32 Introduce the client geometry in Toplevel
In most cases, we don't need to react to client geometry changes, but in
code that deals with server-side window decorations, we need to react to
client geometry changes. The problem is that frame and client geometry
updates are not correlated even though there is a connection between the
frame geometry and the client geometry.

This change introduces the client geometry in the Toplevel class in order
to allow monitoring client geometry updates from DecoratedClientImpl.
2020-06-18 07:40:58 +00:00
Alain Knaff e9c68f36bd [x11] Send a valid timestamp in TakeFocus messages
Kwin sends out undated WM_TAKE_FOCUS client messages. Gtk based
applications such as Firefox react to these by handing focus to one of
their subwindows using XSetInputFocus(), and pass on the null time field
that they received in the client message to XSetInputFocus().

If for whatever reason the application (firefox) is slow to process the
event, it might issue that XSetInputFocus() message at a time when it
has already lost focus to the next application. This results in Firefox
stealing back the focus from the next application. Normally, such an
occurrence would not happen, as the server could tell by the time field
that the message is stale.

Until 2016 (e73e331f35) kwin *used* to
send a valid timestamp, but this got deliberately broken to appease some
Java Applications which were "extremely picky" and would refuse focus.

This was based on the assumption that no other toolkit used the
timestamp from take focus events which is now proven to be false.

ICCCM document states:

Windows with the atom WM_TAKE_FOCUS in their WM_PROTOCOLS property may
receive  a ClientMessage event from the window manager (as described in
section 4.2.8) with WM_TAKE_FOCUS in its data[0] field and a valid
timestamp (i.e. not CurrentTime ) in its data[1] field."

BUG: 421068
2020-06-10 11:11:08 +01:00
Vlad Zahorodnii 44143ef7ae Move core shade code to AbstractClient
Summary:
In order to allow shading wayland clients, this change moves core shade
code from X11Client to AbstractClient.

Test Plan: Shading still works on X11.

Reviewers: #kwin, cblack

Reviewed By: cblack

Subscribers: cblack, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29512
2020-05-07 22:03:31 +03:00
Vlad Zahorodnii 325b85f8ca Drop Workspace::sendPingToWindow()
Summary:
This change drops Workspace::sendPingToWindow() in order to better
separate X11-specific and more generic code.

Test Plan: Still able to close X11 windows.

Reviewers: #kwin, apol

Reviewed By: apol

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29472
2020-05-06 15:05:51 +03:00
Vlad Zahorodnii 76af96bcc9 [x11] Disable synchronized resizing for Xwayland < 1.21
In case Xwayland does not use multiple buffers, the currently attached
buffer is going to be destroyed if the frame window is resized. It may
render the previous and the current window pixmap invalid and thus result
in visual artifacts when an X11 client is being interactively resized.

In order to avoid the visual artifacts, this change disables support for
synchronized resizing for X11 clients if the version of Xwayland is less
than the version in which Xwayland started using multiple buffers, i.e.
1.21.

Differential Revision: https://phabricator.kde.org/D29250
2020-04-29 16:37:31 +03:00
Vlad Zahorodnii a9d2bad007 [x11] Enable synchronized resizing for Xwayland clients
Given that we now query the current X11 time stamp on Wayland, we can
enable synchronized resizing for Xwayland clients.

Differential Revision: https://phabricator.kde.org/D29250
2020-04-29 16:37:23 +03:00
Aleix Pol 6abd23ed02 Make it possible to have a separate cursor for the tablet
Summary:
As is KWin only had 1 Cursor which was a singleton. This made it impossible for
us to properly implement the tablet (as in drawing tablets) support and show where
we're drawing.
This patch makes it possible to have different Cursors in KWin, it makes all the
current code still follow the mouse but the tablet can still render a cursor.

Test Plan: Tests pass, been using it and works as well as before but with beautiful tablet cursors.

Reviewers: #kwin, cblack, davidedmundson

Reviewed By: #kwin, cblack, davidedmundson

Subscribers: davidedmundson, cblack, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D28155
2020-04-03 01:16:45 +02:00
Aleix Pol 5eb84af469 Remove overloads on virtual methods
Summary:
Prefer virtual methods that take QRect and QSize rather than multi-int versions.
Makes for clearer API and reduces the amount of code that was taking all of the
components and turn it into a class.

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D28283
2020-03-26 16:10:10 +01:00
Vlad Zahorodnii fb114dfba3 Return early if we ignore resize increments and aspect ratio constraints
Summary:
If we know that we are going to disobey resize increment and aspect ratio
geometry hints, then there is no point for trying to constrain the client
size according to those hints. Just return early.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27031
2020-02-28 17:13:01 +02:00
Vlad Zahorodnii a75fb7f84e Refactor geometry constraints code
Summary:
Currently, there are a couple of issues with sizeForClientSize(). First
of all, we have a method called clientSizeToFrameSize() which does similar
thing except applying geometry constraints and checking window rules. The
other issue is that sizeForClientSize() is doing a bit too much, it checks
window rules, it applies a bunch of geometry constrains. Sometimes it
does not perform conversion between client sizes and frame sizes!

This change attempts to address those issues by replacing sizeForClientSize
with two similar methods and changing semantics of some methods of the
X11Client class.

The most significant difference between sizeForClientSize() and the new
methods is that neither constrainClientSize() nor constrainFrameSize()
check window rules. This is up to users of those methods. In many places,
we don't have to check window rules because we check isResizable(),
which returns false if the frame size is enforced by a window rule.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, romangg, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26828
2020-02-28 17:13:01 +02:00
David Edmundson 41b02f2356 [x11client] Make activity handling more consistent across windows
Summary:
Typically by default newly added toplevel windows are added only to the
current activity.

Initially windows with no borders were added to all activities. This
causes problems particularly now with the newer frame extents support
leaving window behaviour quite inconsistent.

Since the time of the original code the taskbar gained control for
controlling activities allowing at least one method of changing them.
This means we can use this as the new filter.

BUG: 274931

Test Plan:
Opened gtk3-demo
Switched activities, it wasn't on the new one
Went back, altered it through the taskmanager, it worked

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27690
2020-02-28 11:41:59 +00:00
Nicolas Fella 7159684ced Revert "[kcm/effects] Clip ListView"
Bad merge

This reverts commit b713044216.
2020-02-22 11:53:59 +01:00
Nicolas Fella b713044216 [kcm/effects] Clip ListView
Summary:
Otherwise the content overflows the frame when scrolling.

QQC2 scrollview docs say "ScrollView does not automatically clip its contents. If it is not used as a full-screen item, you should consider setting the clip property to true"

Test Plan:
Before:
{F8121150}

After:
{F8121152}

Reviewers: #kwin, #plasma, ngraham

Reviewed By: ngraham

Subscribers: ngraham, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27558
2020-02-22 11:52:49 +01:00
Nicolas Fella cdc5ea19ab Revert "[kcm/effects] Clip ListView"
Bad merge

This reverts commit 5babf52df4.
2020-02-22 11:50:30 +01:00
Nicolas Fella 5babf52df4 [kcm/effects] Clip ListView
Summary:
Otherwise the content overflows the frame when scrolling.

QQC2 scrollview docs say "ScrollView does not automatically clip its contents. If it is not used as a full-screen item, you should consider setting the clip property to true"

Test Plan:
Before:
{F8121150}

After:
{F8121152}

Reviewers: #kwin, #plasma, ngraham

Reviewed By: ngraham

Subscribers: ngraham, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27558
2020-02-22 11:48:51 +01:00
Vlad Zahorodnii 63fa013334 Merge branch 'Plasma/5.18' 2020-02-18 11:16:56 +02:00
Vlad Zahorodnii cfa5daaad1 Fix misplaced client windows
Summary:
This regression was introduced by me, sorry. The client window may be at
location other than (0, 0), in which case we have to move it to (0, 0)
to ensure that the client contents is not covered by window frame.

BUG: 417584
FIXED-IN: 5.18.1

Reviewers: #kwin, broulik

Reviewed By: broulik

Subscribers: broulik, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27456
2020-02-18 11:16:44 +02:00
Vlad Zahorodnii 6a2fc3d8ce Merge branch 'Plasma/5.18' 2020-02-14 01:50:48 +02:00
Vlad Zahorodnii 1181af2cd1 Provide input geometry and input transformation matrix for Xwayland clients
Summary:
We need to provide the input geometry and the input transformation
matrix for Xwayland clients in order to make sure that input events
are correctly mapped from the global screen coordinates to the
screen-local coordinates.

BUG: 417444
FIXED-IN: 5.18.1

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27375
2020-02-14 01:49:27 +02:00
Vlad Zahorodnii 5af81c1cd7 Make support for the maximized mode partially optional
Summary:
Not all Client classes have support for the maximized mode. Therefore,
it can be made opt-in to reduce the amount of plumbed methods.

Unfortunately, there a few places, which don't have any connection with
the maximized mode, where AbstractClient::geometryRestore() is used, so
it cannot be made 100% optional at the moment.

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27169
2020-02-12 11:28:15 +02:00
Vlad Zahorodnii 624317a78d Don't pass any arguments to AbstractClient::doSetDesktop()
Summary: We don't use them anywhere.

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27121
2020-02-12 11:00:25 +02:00
Vlad Zahorodnii f9e9f93d5b Move X11-specific bits of keep above and keep below state to X11Client
Summary:
Nothing special about this patch except of the removal of code that forces
_NET_WM_STATE_BELOW and _NET_WM_STATE_ABOVE. If the client window is
compliant with the EWMH spec, then _NET_WM_STATE_BELOW and _NET_WM_STATE_ABOVE
will be in sync with keepBelow() and keepAbove(), respectively.

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27120
2020-02-12 11:00:25 +02:00
Vlad Zahorodnii a281bece6a Introduce AbstractClient::doSetDemandsAttention()
Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27119
2020-02-12 11:00:25 +02:00
Vlad Zahorodnii f90c65f431 Move X11-specific minimize code to X11Client
Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27118
2020-02-12 11:00:25 +02:00
Vlad Zahorodnii 15af09c70a Introduce Toplevel::frameGeometryChanged signal
Summary:
Currently we have two signals that are emitted when the Toplevel's geometry
changes - geometryShapeChanged() and geometryChanged(). The former signal
is used primarily to invalidate cached window quads and the latter is
sort of emitted when the frame geometry changes. But it's not that easy. We
have a bunch of connects that link those signals together...

The worst part about all of this is that the window quads cache gets
invalidated every time a geometry update occurs, for example when user
moves a window around on the screen.

This change introduces a new signal and deprecates the existing geometryChanged
signal. frameGeometryChanged is similar to geometryChanged except that it is
emitted when an _actual_ geometry change has occurred.

We do still emit geometryShapeChanged signal. However, in long term, we
need to get rid of this signal or come up with something that makes sense
and doesn't require us to waste computational resources.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, romangg, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26863
2020-02-12 10:52:26 +02:00
Vlad Zahorodnii 98634e0193 Merge branch 'Plasma/5.18' 2020-02-03 14:01:53 +02:00
Vlad Zahorodnii 56d5f3a4f6 [x11] Fix visual artifacts during interactive resize
Summary:
When a window is being interactively resized, its contents may jump. The
reason why that happens is because KWin renders partially resized client
window. Composite extension spec says that a window will get a new pixmap
each time it is resized or mapped. This applies to the frame window, but
not to the client window itself. If the client window is resized,
off-screen storage for the frame window won't be reallocated. Therefore,
KWin may render partially resized client window if the client doesn't
attempt to be in sync with our rendering loop. Currently, the only way
to do that is to use extended frame counters, which are not supported by
KWin.

So, in order to fix visual artifacts during interactive resize, we need
somehow forcefully re-allocate off-screen storage for the frame window.
Unfortunately, Composite extension doesn't provide any request to do
that, so the only option we have is to resize the frame window.

BUG: 415839
FIXED-IN: 5.18.0

Reviewers: #kwin

Subscribers: davidedmundson, ngraham, alexde, fredrik, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26914
2020-02-03 13:56:35 +02:00
Vlad Zahorodnii 74e04949d7 Merge branch 'Plasma/5.18' 2020-01-29 13:11:32 +02:00
Vlad Zahorodnii 35fe3cb6c5 Drop Toplevel::decorationRect()
Summary: It's identical to Toplevel::rect().

Test Plan: Compiles.

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26971
2020-01-29 12:58:54 +02:00
Vlad Zahorodnii c36a5bf423 Merge branch 'Plasma/5.18' 2020-01-28 22:01:03 +02:00
Vlad Zahorodnii 34fc962ff1 Move definition of X11Client::damageNotifyEvent() to x11client.cpp
One step closer to the bright future where one can disable X11 support
at build time.
2020-01-28 21:58:00 +02:00