2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file contains things relevant to window activation and focus
|
|
|
|
stealing prevention.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.h"
|
2013-02-26 07:45:44 +00:00
|
|
|
#include "cursor.h"
|
2012-11-20 16:26:50 +00:00
|
|
|
#include "focuschain.h"
|
2013-04-26 08:41:24 +00:00
|
|
|
#include "netinfo.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "workspace.h"
|
2013-04-04 14:14:12 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
|
|
|
#include "activities.h"
|
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <kstartupinfo.h>
|
|
|
|
#include <kstringhandler.h>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KLocalizedString>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "atoms.h"
|
|
|
|
#include "group.h"
|
|
|
|
#include "rules.h"
|
2013-04-03 10:19:27 +00:00
|
|
|
#include "screens.h"
|
2012-08-19 10:00:53 +00:00
|
|
|
#include "useractions.h"
|
2013-09-02 11:14:39 +00:00
|
|
|
#include <QDebug>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
Prevention of focus stealing:
|
|
|
|
|
|
|
|
KWin tries to prevent unwanted changes of focus, that would result
|
|
|
|
from mapping a new window. Also, some nasty applications may try
|
|
|
|
to force focus change even in cases when ICCCM 4.2.7 doesn't allow it
|
|
|
|
(e.g. they may try to activate their main window because the user
|
|
|
|
definitely "needs" to see something happened - misusing
|
|
|
|
of QWidget::setActiveWindow() may be such case).
|
|
|
|
|
|
|
|
There are 4 ways how a window may become active:
|
|
|
|
- the user changes the active window (e.g. focus follows mouse, clicking
|
|
|
|
on some window's titlebar) - the change of focus will
|
|
|
|
be done by KWin, so there's nothing to solve in this case
|
|
|
|
- the change of active window will be requested using the _NET_ACTIVE_WINDOW
|
|
|
|
message (handled in RootInfo::changeActiveWindow()) - such requests
|
|
|
|
will be obeyed, because this request is meant mainly for e.g. taskbar
|
|
|
|
asking the WM to change the active window as a result of some user action.
|
|
|
|
Normal applications should use this request only rarely in special cases.
|
|
|
|
See also below the discussion of _NET_ACTIVE_WINDOW_TRANSFER.
|
|
|
|
- the change of active window will be done by performing XSetInputFocus()
|
|
|
|
on a window that's not currently active. ICCCM 4.2.7 describes when
|
|
|
|
the application may perform change of input focus. In order to handle
|
|
|
|
misbehaving applications, KWin will try to detect focus changes to
|
|
|
|
windows that don't belong to currently active application, and restore
|
|
|
|
focus back to the currently active window, instead of activating the window
|
|
|
|
that got focus (unfortunately there's no way to FocusChangeRedirect similar
|
|
|
|
to e.g. SubstructureRedirect, so there will be short time when the focus
|
|
|
|
will be changed). The check itself that's done is
|
|
|
|
Workspace::allowClientActivation() (see below).
|
|
|
|
- a new window will be mapped - this is the most complicated case. If
|
|
|
|
the new window belongs to the currently active application, it may be safely
|
|
|
|
mapped on top and activated. The same if there's no active window,
|
|
|
|
or the active window is the desktop. These checks are done by
|
|
|
|
Workspace::allowClientActivation().
|
|
|
|
Following checks need to compare times. One time is the timestamp
|
|
|
|
of last user action in the currently active window, the other time is
|
|
|
|
the timestamp of the action that originally caused mapping of the new window
|
|
|
|
(e.g. when the application was started). If the first time is newer than
|
|
|
|
the second one, the window will not be activated, as that indicates
|
|
|
|
futher user actions took place after the action leading to this new
|
|
|
|
mapped window. This check is done by Workspace::allowClientActivation().
|
|
|
|
There are several ways how to get the timestamp of action that caused
|
2019-09-24 08:48:08 +00:00
|
|
|
the new mapped window (done in X11Client::readUserTimeMapTimestamp()) :
|
2007-04-29 17:35:43 +00:00
|
|
|
- the window may have the _NET_WM_USER_TIME property. This way
|
|
|
|
the application may either explicitly request that the window is not
|
|
|
|
activated (by using 0 timestamp), or the property contains the time
|
|
|
|
of last user action in the application.
|
|
|
|
- KWin itself tries to detect time of last user action in every window,
|
|
|
|
by watching KeyPress and ButtonPress events on windows. This way some
|
|
|
|
events may be missed (if they don't propagate to the toplevel window),
|
|
|
|
but it's good as a fallback for applications that don't provide
|
|
|
|
_NET_WM_USER_TIME, and missing some events may at most lead
|
|
|
|
to unwanted focus stealing.
|
|
|
|
- the timestamp may come from application startup notification.
|
|
|
|
Application startup notification, if it exists for the new mapped window,
|
|
|
|
should include time of the user action that caused it.
|
|
|
|
- if there's no timestamp available, it's checked whether the new window
|
|
|
|
belongs to some already running application - if yes, the timestamp
|
|
|
|
will be 0 (i.e. refuse activation)
|
|
|
|
- if the window is from session restored window, the timestamp will
|
|
|
|
be 0 too, unless this application was the active one at the time
|
|
|
|
when the session was saved, in which case the window will be
|
|
|
|
activated if there wasn't any user interaction since the time
|
|
|
|
KWin was started.
|
|
|
|
- as the last resort, the _KDE_NET_USER_CREATION_TIME timestamp
|
|
|
|
is used. For every toplevel window that is created (see CreateNotify
|
|
|
|
handling), this property is set to the at that time current time.
|
|
|
|
Since at this time it's known that the new window doesn't belong
|
|
|
|
to any existing application (better said, the application doesn't
|
|
|
|
have any other window mapped), it is either the very first window
|
2009-02-07 01:12:28 +00:00
|
|
|
of the application, or it is the only window of the application
|
2007-04-29 17:35:43 +00:00
|
|
|
that was hidden before. The latter case is handled by removing
|
|
|
|
the property from windows before withdrawing them, making
|
|
|
|
the timestamp empty for next mapping of the window. In the sooner
|
|
|
|
case, the timestamp will be used. This helps in case when
|
|
|
|
an application is launched without application startup notification,
|
|
|
|
it creates its mainwindow, and starts its initialization (that
|
|
|
|
may possibly take long time). The timestamp used will be older
|
|
|
|
than any user action done after launching this application.
|
|
|
|
- if no timestamp is found at all, the window is activated.
|
|
|
|
The check whether two windows belong to the same application (same
|
2019-09-24 08:48:08 +00:00
|
|
|
process) is done in X11Client::belongToSameApplication(). Not 100% reliable,
|
2007-04-29 17:35:43 +00:00
|
|
|
but hopefully 99,99% reliable.
|
|
|
|
|
|
|
|
As a somewhat special case, window activation is always enabled when
|
|
|
|
session saving is in progress. When session saving, the session
|
|
|
|
manager allows only one application to interact with the user.
|
|
|
|
Not allowing window activation in such case would result in e.g. dialogs
|
|
|
|
not becoming active, so focus stealing prevention would cause here
|
|
|
|
more harm than good.
|
|
|
|
|
|
|
|
Windows that attempted to become active but KWin prevented this will
|
|
|
|
be marked as demanding user attention. They'll get
|
|
|
|
the _NET_WM_STATE_DEMANDS_ATTENTION state, and the taskbar should mark
|
|
|
|
them specially (blink, etc.). The state will be reset when the window
|
|
|
|
eventually really becomes active.
|
|
|
|
|
2015-06-12 15:41:49 +00:00
|
|
|
There are two more ways how a window can become obtrusive, window stealing
|
2007-04-29 17:35:43 +00:00
|
|
|
focus: By showing above the active window, by either raising itself,
|
|
|
|
or by moving itself on the active desktop.
|
|
|
|
- KWin will refuse raising non-active window above the active one,
|
|
|
|
unless they belong to the same application. Applications shouldn't
|
|
|
|
raise their windows anyway (unless the app wants to raise one
|
|
|
|
of its windows above another of its windows).
|
|
|
|
- KWin activates windows moved to the current desktop (as that seems
|
|
|
|
logical from the user's point of view, after sending the window
|
|
|
|
there directly from KWin, or e.g. using pager). This means
|
|
|
|
applications shouldn't send their windows to another desktop
|
|
|
|
(SELI TODO - but what if they do?)
|
|
|
|
|
|
|
|
Special cases I can think of:
|
|
|
|
- konqueror reusing, i.e. kfmclient tells running Konqueror instance
|
|
|
|
to open new window
|
|
|
|
- without focus stealing prevention - no problem
|
|
|
|
- with ASN (application startup notification) - ASN is forwarded,
|
|
|
|
and because it's newer than the instance's user timestamp,
|
|
|
|
it takes precedence
|
|
|
|
- without ASN - user timestamp needs to be reset, otherwise it would
|
|
|
|
be used, and it's old; moreover this new window mustn't be detected
|
|
|
|
as window belonging to already running application, or it wouldn't
|
2019-09-24 08:48:08 +00:00
|
|
|
be activated - see X11Client::sameAppWindowRoleMatch() for the (rather ugly)
|
2007-04-29 17:35:43 +00:00
|
|
|
hack
|
|
|
|
- konqueror preloading, i.e. window is created in advance, and kfmclient
|
|
|
|
tells this Konqueror instance to show it later
|
|
|
|
- without focus stealing prevention - no problem
|
|
|
|
- with ASN - ASN is forwarded, and because it's newer than the instance's
|
|
|
|
user timestamp, it takes precedence
|
|
|
|
- without ASN - user timestamp needs to be reset, otherwise it would
|
|
|
|
be used, and it's old; also, creation timestamp is changed to
|
|
|
|
the time the instance starts (re-)initializing the window,
|
|
|
|
this ensures creation timestamp will still work somewhat even in this case
|
|
|
|
- KUniqueApplication - when the window is already visible, and the new instance
|
|
|
|
wants it to activate
|
|
|
|
- without focus stealing prevention - _NET_ACTIVE_WINDOW - no problem
|
|
|
|
- with ASN - ASN is forwarded, and set on the already visible window, KWin
|
|
|
|
treats the window as new with that ASN
|
|
|
|
- without ASN - _NET_ACTIVE_WINDOW as application request is used,
|
|
|
|
and there's no really usable timestamp, only timestamp
|
|
|
|
from the time the (new) application instance was started,
|
|
|
|
so KWin will activate the window *sigh*
|
|
|
|
- the bad thing here is that there's absolutely no chance to recognize
|
|
|
|
the case of starting this KUniqueApp from Konsole (and thus wanting
|
|
|
|
the already visible window to become active) from the case
|
|
|
|
when something started this KUniqueApp without ASN (in which case
|
|
|
|
the already visible window shouldn't become active)
|
|
|
|
- the only solution is using ASN for starting applications, at least silent
|
|
|
|
(i.e. without feedback)
|
|
|
|
- when one application wants to activate another application's window (e.g. KMail
|
|
|
|
activating already running KAddressBook window ?)
|
|
|
|
- without focus stealing prevention - _NET_ACTIVE_WINDOW - no problem
|
|
|
|
- with ASN - can't be here, it's the KUniqueApp case then
|
|
|
|
- without ASN - _NET_ACTIVE_WINDOW as application request should be used,
|
|
|
|
KWin will activate the new window depending on the timestamp and
|
|
|
|
whether it belongs to the currently active application
|
|
|
|
|
|
|
|
_NET_ACTIVE_WINDOW usage:
|
|
|
|
data.l[0]= 1 ->app request
|
|
|
|
= 2 ->pager request
|
|
|
|
= 0 - backwards compatibility
|
|
|
|
data.l[1]= timestamp
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Workspace
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Informs the workspace about the active client, i.e. the client that
|
|
|
|
* has the focus (or None if no client has the focus). This functions
|
|
|
|
* is called by the client itself that gets focus. It has no other
|
|
|
|
* effect than fixing the focus chain and the return value of
|
|
|
|
* activeClient(). And of course, to propagate the active client to the
|
|
|
|
* world.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-03-12 11:08:54 +00:00
|
|
|
void Workspace::setActiveClient(AbstractClient* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (active_client == c)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
if (active_popup && active_popup_client != c && set_active_client_recursion == 0)
|
2007-04-29 17:35:43 +00:00
|
|
|
closeActivePopup();
|
2012-08-19 10:00:53 +00:00
|
|
|
if (m_userActionsMenu->hasClient() && !m_userActionsMenu->isMenuClient(c) && set_active_client_recursion == 0) {
|
|
|
|
m_userActionsMenu->close();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
StackingUpdatesBlocker blocker(this);
|
2007-04-29 17:35:43 +00:00
|
|
|
++set_active_client_recursion;
|
2014-03-19 13:45:27 +00:00
|
|
|
updateFocusMousePosition(Cursor::pos());
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (active_client != nullptr) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// note that this may call setActiveClient( NULL ), therefore the recursion counter
|
|
|
|
active_client->setActive(false);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
active_client = c;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
Q_ASSERT(c == nullptr || c->isActive());
|
2013-06-17 23:57:49 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (active_client) {
|
2013-06-17 23:57:49 +00:00
|
|
|
last_active_client = active_client;
|
2012-11-20 16:26:50 +00:00
|
|
|
FocusChain::self()->update(active_client, FocusChain::MakeFirst);
|
2011-01-30 14:34:42 +00:00
|
|
|
active_client->demandAttention(false);
|
2013-06-17 23:57:49 +00:00
|
|
|
|
|
|
|
// activating a client can cause a non active fullscreen window to loose the ActiveLayer status on > 1 screens
|
|
|
|
if (screens()->count() > 1) {
|
2017-07-25 05:15:37 +00:00
|
|
|
for (auto it = m_allClients.begin(); it != m_allClients.end(); ++it) {
|
2013-06-17 23:57:49 +00:00
|
|
|
if (*it != active_client && (*it)->layer() == ActiveLayer && (*it)->screen() == active_client->screen()) {
|
|
|
|
updateClientLayer(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
updateToolWindows(false);
|
|
|
|
if (c)
|
|
|
|
disableGlobalShortcutsForClient(c->rules()->checkDisableGlobalShortcuts(false));
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
disableGlobalShortcutsForClient(false);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
updateStackingOrder(); // e.g. fullscreens have different layer when active/not-active
|
|
|
|
|
2017-07-26 05:09:49 +00:00
|
|
|
if (rootInfo()) {
|
2017-08-03 14:31:20 +00:00
|
|
|
rootInfo()->setActiveClient(active_client);
|
2017-07-26 05:09:49 +00:00
|
|
|
}
|
2011-02-27 09:05:04 +00:00
|
|
|
|
|
|
|
emit clientActivated(active_client);
|
2007-04-29 17:35:43 +00:00
|
|
|
--set_active_client_recursion;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Tries to activate the client \a c. This function performs what you
|
|
|
|
* expect when clicking the respective entry in a taskbar: showing and
|
|
|
|
* raising the client (this may imply switching to the another virtual
|
|
|
|
* desktop) and putting the focus onto it. Once X really gave focus to
|
|
|
|
* the client window as requested, the client itself will call
|
|
|
|
* setActiveClient() and the operation is complete. This may not happen
|
|
|
|
* with certain focus policies, though.
|
|
|
|
*
|
|
|
|
* @see setActiveClient
|
|
|
|
* @see requestFocus
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-03-06 13:45:58 +00:00
|
|
|
void Workspace::activateClient(AbstractClient* c, bool force)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (c == nullptr) {
|
2007-04-30 11:46:54 +00:00
|
|
|
focusToNull();
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
setActiveClient(nullptr);
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
raiseClient(c);
|
|
|
|
if (!c->isOnCurrentDesktop()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
++block_focus;
|
2012-11-16 07:23:47 +00:00
|
|
|
VirtualDesktopManager::self()->setCurrent(c->desktop());
|
2007-04-29 17:35:43 +00:00
|
|
|
--block_focus;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-02-26 10:38:16 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!c->isOnCurrentActivity()) {
|
2010-05-13 18:53:08 +00:00
|
|
|
++block_focus;
|
|
|
|
//DBUS!
|
2013-04-04 14:14:12 +00:00
|
|
|
Activities::self()->setCurrent(c->activities().first()); //first isn't necessarily best, but it's easiest
|
2010-05-13 18:53:08 +00:00
|
|
|
--block_focus;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-02-26 10:38:16 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isMinimized())
|
2007-04-29 17:35:43 +00:00
|
|
|
c->unminimize();
|
|
|
|
|
2015-05-23 07:02:11 +00:00
|
|
|
// ensure the window is really visible - could eg. be a hidden utility window, see bug #348083
|
|
|
|
c->hideClient(false);
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// TODO force should perhaps allow this only if the window already contains the mouse
|
2011-01-30 14:34:42 +00:00
|
|
|
if (options->focusPolicyIsReasonable() || force)
|
|
|
|
requestFocus(c, force);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Don't update user time for clients that have focus stealing workaround.
|
|
|
|
// As they usually belong to the current active window but fail to provide
|
|
|
|
// this information, updating their user time would make the user time
|
|
|
|
// of the currently active window old, and reject further activation for it.
|
|
|
|
// E.g. typing URL in minicli which will show kio_uiserver dialog (with workaround),
|
|
|
|
// and then kdesktop shows dialog about SSL certificate.
|
2019-09-24 08:48:08 +00:00
|
|
|
// This needs also avoiding user creation time in X11Client::readUserTimeMapTimestamp().
|
|
|
|
if (X11Client *client = dynamic_cast<X11Client *>(c)) {
|
2015-03-06 13:45:58 +00:00
|
|
|
// updateUserTime is X11 specific
|
|
|
|
client->updateUserTime();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Tries to activate the client by asking X for the input focus. This
|
|
|
|
* function does not perform any show, raise or desktop switching. See
|
|
|
|
* Workspace::activateClient() instead.
|
|
|
|
*
|
|
|
|
* @see activateClient
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-03-06 13:45:58 +00:00
|
|
|
void Workspace::requestFocus(AbstractClient* c, bool force)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-03-06 14:04:59 +00:00
|
|
|
takeActivity(c, force ? ActivityFocusForce : ActivityFocus);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 14:04:59 +00:00
|
|
|
void Workspace::takeActivity(AbstractClient* c, ActivityFlags flags)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
// the 'if ( c == active_client ) return;' optimization mustn't be done here
|
|
|
|
if (!focusChangeEnabled() && (c != active_client))
|
2007-04-29 17:35:43 +00:00
|
|
|
flags &= ~ActivityFocus;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!c) {
|
2007-04-29 17:35:43 +00:00
|
|
|
focusToNull();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (flags & ActivityFocus) {
|
2015-03-06 14:04:59 +00:00
|
|
|
AbstractClient* modal = c->findModal();
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (modal != nullptr && modal != c) {
|
2015-05-23 07:02:11 +00:00
|
|
|
if (!modal->isOnDesktop(c->desktop()))
|
2011-01-30 14:34:42 +00:00
|
|
|
modal->setDesktop(c->desktop());
|
2015-05-23 07:02:11 +00:00
|
|
|
if (!modal->isShown(true) && !modal->isMinimized()) // forced desktop or utility window
|
|
|
|
activateClient(modal); // activating a minimized blocked window will unminimize its modal implicitly
|
2007-04-29 17:35:43 +00:00
|
|
|
// if the click was inside the window (i.e. handled is set),
|
|
|
|
// but it has a modal, there's no need to use handled mode, because
|
|
|
|
// the modal doesn't get the click anyway
|
|
|
|
// raising of the original window needs to be still done
|
2011-01-30 14:34:42 +00:00
|
|
|
if (flags & ActivityRaise)
|
|
|
|
raiseClient(c);
|
2007-04-29 17:35:43 +00:00
|
|
|
c = modal;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
cancelDelayFocus();
|
|
|
|
}
|
2016-10-12 13:09:52 +00:00
|
|
|
if (!flags.testFlag(ActivityFocusForce) && (c->isDock() || c->isSplash())) {
|
|
|
|
// toplevel menus and dock windows don't take focus if not forced
|
|
|
|
// and don't have a flag that they take focus
|
|
|
|
if (!c->dockWantsInput()) {
|
|
|
|
flags &= ~ActivityFocus;
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isShade()) {
|
|
|
|
if (c->wantsInput() && (flags & ActivityFocus)) {
|
|
|
|
// client cannot accept focus, but at least the window should be active (window menu, et. al. )
|
|
|
|
c->setActive(true);
|
2007-04-29 17:35:43 +00:00
|
|
|
focusToNull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
flags &= ~ActivityFocus;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (!c->isShown(true)) { // shouldn't happen, call activateClient() if needed
|
2014-12-05 10:42:15 +00:00
|
|
|
qCWarning(KWIN_CORE) << "takeActivity: not shown" ;
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-20 12:39:00 +00:00
|
|
|
if (flags & ActivityFocus)
|
2013-04-26 07:47:45 +00:00
|
|
|
c->takeFocus();
|
2014-03-20 12:39:00 +00:00
|
|
|
if (flags & ActivityRaise)
|
|
|
|
workspace()->raiseClient(c);
|
|
|
|
|
|
|
|
if (!c->isOnActiveScreen())
|
|
|
|
screens()->setCurrent(c->screen());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Informs the workspace that the client \a c has been hidden. If it
|
|
|
|
* was the active client (or to-become the active client),
|
|
|
|
* the workspace activates another one.
|
|
|
|
*
|
|
|
|
* @note @p c may already be destroyed.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-04-30 11:47:44 +00:00
|
|
|
void Workspace::clientHidden(AbstractClient* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-08-31 14:28:37 +00:00
|
|
|
Q_ASSERT(!c->isShown(true) || !c->isOnCurrentDesktop() || !c->isOnCurrentActivity());
|
2011-01-30 14:34:42 +00:00
|
|
|
activateNextClient(c);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2016-02-18 09:28:00 +00:00
|
|
|
AbstractClient *Workspace::clientUnderMouse(int screen) const
|
2012-02-13 22:50:49 +00:00
|
|
|
{
|
2012-04-08 08:07:35 +00:00
|
|
|
ToplevelList::const_iterator it = stackingOrder().constEnd();
|
2012-02-13 22:50:49 +00:00
|
|
|
while (it != stackingOrder().constBegin()) {
|
2016-02-18 09:28:00 +00:00
|
|
|
AbstractClient *client = qobject_cast<AbstractClient*>(*(--it));
|
2012-04-08 08:07:35 +00:00
|
|
|
if (!client) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-13 22:50:49 +00:00
|
|
|
|
|
|
|
// rule out clients which are not really visible.
|
2012-08-16 06:03:07 +00:00
|
|
|
// the screen test is rather superfluous for xrandr & twinview since the geometry would differ -> TODO: might be dropped
|
2012-02-13 22:50:49 +00:00
|
|
|
if (!(client->isShown(false) && client->isOnCurrentDesktop() &&
|
|
|
|
client->isOnCurrentActivity() && client->isOnScreen(screen)))
|
|
|
|
continue;
|
|
|
|
|
2019-09-27 10:01:10 +00:00
|
|
|
if (client->frameGeometry().contains(Cursor::pos())) {
|
2012-02-13 22:50:49 +00:00
|
|
|
return client;
|
|
|
|
}
|
|
|
|
}
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2012-02-13 22:50:49 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// deactivates 'c' and activates next client
|
2015-04-30 11:47:44 +00:00
|
|
|
bool Workspace::activateNextClient(AbstractClient* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// if 'c' is not the active or the to-become active one, do nothing
|
2011-08-22 11:53:03 +00:00
|
|
|
if (!(c == active_client || (should_get_focus.count() > 0 && c == should_get_focus.last())))
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-08-22 11:53:03 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
closeActivePopup();
|
2011-08-22 11:53:03 +00:00
|
|
|
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (c != nullptr) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c == active_client)
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
setActiveClient(nullptr);
|
2011-01-30 14:34:42 +00:00
|
|
|
should_get_focus.removeAll(c);
|
|
|
|
}
|
2011-08-22 11:53:03 +00:00
|
|
|
|
|
|
|
// if blocking focus, move focus to the desktop later if needed
|
|
|
|
// in order to avoid flickering
|
|
|
|
if (!focusChangeEnabled()) {
|
|
|
|
focusToNull();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options->focusPolicyIsReasonable())
|
|
|
|
return false;
|
|
|
|
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
AbstractClient* get_focus = nullptr;
|
2011-08-22 11:53:03 +00:00
|
|
|
|
2015-05-13 21:35:37 +00:00
|
|
|
const int desktop = VirtualDesktopManager::self()->current();
|
|
|
|
|
|
|
|
if (!get_focus && showingDesktop())
|
|
|
|
get_focus = findDesktop(true, desktop); // to not break the state
|
|
|
|
|
2012-11-08 21:26:09 +00:00
|
|
|
if (!get_focus && options->isNextFocusPrefersMouse()) {
|
2013-04-03 10:19:27 +00:00
|
|
|
get_focus = clientUnderMouse(c ? c->screen() : screens()->current());
|
2012-02-13 22:50:49 +00:00
|
|
|
if (get_focus && (get_focus == c || get_focus->isDesktop())) {
|
|
|
|
// should rather not happen, but it cannot get the focus. rest of usability is tested above
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
get_focus = nullptr;
|
2011-08-22 11:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_focus) { // no suitable window under the mouse -> find sth. else
|
|
|
|
// first try to pass the focus to the (former) active clients leader
|
2015-09-17 14:15:26 +00:00
|
|
|
if (c && c->isTransient()) {
|
2015-09-11 13:55:23 +00:00
|
|
|
auto leaders = c->mainClients();
|
|
|
|
if (leaders.count() == 1 && FocusChain::self()->isUsableFocusCandidate(leaders.at(0), c)) {
|
|
|
|
get_focus = leaders.at(0);
|
|
|
|
raiseClient(get_focus); // also raise - we don't know where it came from
|
2015-05-08 20:49:20 +00:00
|
|
|
}
|
2015-04-30 11:47:44 +00:00
|
|
|
}
|
2015-05-08 20:49:20 +00:00
|
|
|
if (!get_focus) {
|
2011-08-22 11:53:03 +00:00
|
|
|
// nope, ask the focus chain for the next candidate
|
2012-11-20 16:26:50 +00:00
|
|
|
get_focus = FocusChain::self()->nextForDesktop(c, desktop);
|
2011-08-22 11:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (get_focus == nullptr) // last chance: focus the desktop
|
2012-11-16 07:23:47 +00:00
|
|
|
get_focus = findDesktop(true, desktop);
|
2010-12-20 18:21:46 +00:00
|
|
|
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (get_focus != nullptr)
|
2011-08-22 11:53:03 +00:00
|
|
|
requestFocus(get_focus);
|
|
|
|
else
|
2007-04-29 17:35:43 +00:00
|
|
|
focusToNull();
|
2011-08-22 11:53:03 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-08-22 11:53:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::setCurrentScreen(int new_screen)
|
|
|
|
{
|
2013-04-03 10:19:27 +00:00
|
|
|
if (new_screen < 0 || new_screen >= screens()->count())
|
2007-05-07 13:13:48 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!options->focusPolicyIsReasonable())
|
2007-05-07 13:13:48 +00:00
|
|
|
return;
|
|
|
|
closeActivePopup();
|
2012-11-16 07:23:47 +00:00
|
|
|
const int desktop = VirtualDesktopManager::self()->current();
|
2015-03-12 12:43:39 +00:00
|
|
|
AbstractClient *get_focus = FocusChain::self()->getForActivation(desktop, new_screen);
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (get_focus == nullptr)
|
2012-11-16 07:23:47 +00:00
|
|
|
get_focus = findDesktop(true, desktop);
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (get_focus != nullptr && get_focus != mostRecentlyActivatedClient())
|
2011-01-30 14:34:42 +00:00
|
|
|
requestFocus(get_focus);
|
2013-04-03 10:19:27 +00:00
|
|
|
screens()->setCurrent(new_screen);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2015-07-09 11:16:19 +00:00
|
|
|
void Workspace::gotFocusIn(const AbstractClient* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-07-09 11:16:19 +00:00
|
|
|
if (should_get_focus.contains(const_cast< AbstractClient* >(c))) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// remove also all sooner elements that should have got FocusIn,
|
|
|
|
// but didn't for some reason (and also won't anymore, because they were sooner)
|
|
|
|
while (should_get_focus.first() != c)
|
2007-04-29 17:35:43 +00:00
|
|
|
should_get_focus.pop_front();
|
|
|
|
should_get_focus.pop_front(); // remove 'c'
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2015-07-09 11:16:19 +00:00
|
|
|
void Workspace::setShouldGetFocus(AbstractClient* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
should_get_focus.append(c);
|
2007-04-29 17:35:43 +00:00
|
|
|
updateStackingOrder(); // e.g. fullscreens have different layer when active/not-active
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2015-11-12 23:37:01 +00:00
|
|
|
|
|
|
|
namespace FSP {
|
|
|
|
enum Level { None = 0, Low, Medium, High, Extreme };
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// focus_in -> the window got FocusIn event
|
2007-11-29 15:01:30 +00:00
|
|
|
// ignore_desktop - call comes from _NET_ACTIVE_WINDOW message, don't refuse just because of window
|
|
|
|
// is on a different desktop
|
2015-03-12 10:35:31 +00:00
|
|
|
bool Workspace::allowClientActivation(const KWin::AbstractClient *c, xcb_timestamp_t time, bool focus_in, bool ignore_desktop)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// options->focusStealingPreventionLevel :
|
|
|
|
// 0 - none - old KWin behaviour, new windows always get focus
|
|
|
|
// 1 - low - focus stealing prevention is applied normally, when unsure, activation is allowed
|
|
|
|
// 2 - normal - focus stealing prevention is applied normally, when unsure, activation is not allowed,
|
|
|
|
// this is the default
|
|
|
|
// 3 - high - new window gets focus only if it belongs to the active application,
|
|
|
|
// or when no window is currently active
|
|
|
|
// 4 - extreme - no window gets focus without user intervention
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time == -1U)
|
2007-04-29 17:35:43 +00:00
|
|
|
time = c->userTime();
|
2012-02-20 09:25:13 +00:00
|
|
|
int level = c->rules()->checkFSP(options->focusStealingPreventionLevel());
|
2019-10-31 16:16:53 +00:00
|
|
|
if (sessionManager()->state() == SessionState::Saving && level <= FSP::Medium) { // <= normal
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-03-12 10:35:31 +00:00
|
|
|
AbstractClient* ac = mostRecentlyActivatedClient();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (focus_in) {
|
2015-03-12 11:13:46 +00:00
|
|
|
if (should_get_focus.contains(const_cast< AbstractClient* >(c)))
|
|
|
|
return true; // FocusIn was result of KWin's action
|
2007-04-29 17:35:43 +00:00
|
|
|
// Before getting FocusIn, the active Client already
|
|
|
|
// got FocusOut, and therefore got deactivated.
|
|
|
|
ac = last_active_client;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-01-22 00:11:54 +00:00
|
|
|
if (time == 0) { // explicitly asked not to get focus
|
|
|
|
if (!c->rules()->checkAcceptFocus(false))
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-12 23:37:01 +00:00
|
|
|
const int protection = ac ? ac->rules()->checkFPP(2) : 0;
|
|
|
|
|
|
|
|
// stealing is unconditionally allowed (NETWM behavior)
|
|
|
|
if (level == FSP::None || protection == FSP::None)
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2015-11-12 23:37:01 +00:00
|
|
|
|
|
|
|
// The active client "grabs" the focus or stealing is generally forbidden
|
|
|
|
if (level == FSP::Extreme || protection == FSP::Extreme)
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2015-11-12 23:37:01 +00:00
|
|
|
|
|
|
|
// Desktop switching is only allowed in the "no protection" case
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!ignore_desktop && !c->isOnCurrentDesktop())
|
2007-04-29 17:35:43 +00:00
|
|
|
return false; // allow only with level == 0
|
2015-11-12 23:37:01 +00:00
|
|
|
|
|
|
|
// No active client, it's ok to pass focus
|
|
|
|
// NOTICE that extreme protection needs to be handled before to allow protection on unmanged windows
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (ac == nullptr || ac->isDesktop()) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Activation: No client active, allowing";
|
2007-04-29 17:35:43 +00:00
|
|
|
return true; // no active client -> always allow
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-11-12 23:37:01 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// TODO window urgency -> return true?
|
2015-11-12 23:37:01 +00:00
|
|
|
|
|
|
|
// Unconditionally allow intra-client passing around for lower stealing protections
|
|
|
|
// unless the active client has High interest
|
2017-11-05 09:10:17 +00:00
|
|
|
if (AbstractClient::belongToSameApplication(c, ac, AbstractClient::SameApplicationCheck::RelaxedForActive) && protection < FSP::High) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Activation: Belongs to active application";
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-11-12 23:37:01 +00:00
|
|
|
|
2016-02-22 22:00:43 +00:00
|
|
|
if (!c->isOnCurrentDesktop()) // we allowed explicit self-activation across virtual desktops
|
|
|
|
return false; // inside a client or if no client was active, but not otherwise
|
|
|
|
|
2015-11-12 23:37:01 +00:00
|
|
|
// High FPS, not intr-client change. Only allow if the active client has only minor interest
|
|
|
|
if (level > FSP::Medium && protection > FSP::Low)
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2015-11-12 23:37:01 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time == -1U) { // no time known
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Activation: No timestamp at all";
|
2015-11-12 23:37:01 +00:00
|
|
|
// Only allow for Low protection unless active client has High interest in focus
|
|
|
|
if (level < FSP::Medium && protection < FSP::High)
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
|
|
|
// no timestamp at all, don't activate - because there's also creation timestamp
|
|
|
|
// done on CreateNotify, this case should happen only in case application
|
|
|
|
// maps again already used window, i.e. this won't happen after app startup
|
2011-01-30 14:34:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-12 23:37:01 +00:00
|
|
|
|
|
|
|
// Low or medium FSP, usertime comparism is possible
|
2019-09-06 14:30:26 +00:00
|
|
|
const xcb_timestamp_t user_time = ac->userTime();
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Activation, compared:" << c << ":" << time << ":" << user_time
|
2015-07-20 11:35:45 +00:00
|
|
|
<< ":" << (NET::timestampCompare(time, user_time) >= 0);
|
2014-03-20 08:51:20 +00:00
|
|
|
return NET::timestampCompare(time, user_time) >= 0; // time >= user_time
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// basically the same like allowClientActivation(), this time allowing
|
|
|
|
// a window to be fully raised upon its own request (XRaiseWindow),
|
|
|
|
// if refused, it will be raised only on top of windows belonging
|
|
|
|
// to the same application
|
2015-03-12 10:46:08 +00:00
|
|
|
bool Workspace::allowFullClientRaising(const KWin::AbstractClient *c, xcb_timestamp_t time)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-02-20 09:25:13 +00:00
|
|
|
int level = c->rules()->checkFSP(options->focusStealingPreventionLevel());
|
2019-10-31 16:16:53 +00:00
|
|
|
if (sessionManager()->state() == SessionState::Saving && level <= 2) { // <= normal
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2015-03-12 10:46:08 +00:00
|
|
|
AbstractClient* ac = mostRecentlyActivatedClient();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (level == 0) // none
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (level == 4) // extreme
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (ac == nullptr || ac->isDesktop()) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Raising: No client active, allowing";
|
2007-04-29 17:35:43 +00:00
|
|
|
return true; // no active client -> always allow
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// TODO window urgency -> return true?
|
2017-11-05 09:10:17 +00:00
|
|
|
if (AbstractClient::belongToSameApplication(c, ac, AbstractClient::SameApplicationCheck::RelaxedForActive)) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Raising: Belongs to active application";
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (level == 3) // high
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2013-04-30 14:01:25 +00:00
|
|
|
xcb_timestamp_t user_time = ac->userTime();
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Raising, compared:" << time << ":" << user_time
|
2015-07-20 11:35:45 +00:00
|
|
|
<< ":" << (NET::timestampCompare(time, user_time) >= 0);
|
2014-03-20 08:51:20 +00:00
|
|
|
return NET::timestampCompare(time, user_time) >= 0; // time >= user_time
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// called from Client after FocusIn that wasn't initiated by KWin and the client
|
|
|
|
// wasn't allowed to activate
|
|
|
|
void Workspace::restoreFocus()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// this updateXTime() is necessary - as FocusIn events don't have
|
|
|
|
// a timestamp *sigh*, kwin's timestamp would be older than the timestamp
|
|
|
|
// that was used by whoever caused the focus change, and therefore
|
|
|
|
// the attempt to restore the focus would fail due to old timestamp
|
|
|
|
updateXTime();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (should_get_focus.count() > 0)
|
|
|
|
requestFocus(should_get_focus.last());
|
|
|
|
else if (last_active_client)
|
|
|
|
requestFocus(last_active_client);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2015-03-13 10:13:29 +00:00
|
|
|
void Workspace::clientAttentionChanged(AbstractClient* c, bool set)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (set) {
|
|
|
|
attention_chain.removeAll(c);
|
|
|
|
attention_chain.prepend(c);
|
|
|
|
} else
|
|
|
|
attention_chain.removeAll(c);
|
2012-03-09 09:17:19 +00:00
|
|
|
emit clientDemandsAttentionChanged(c, set);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
//********************************************
|
|
|
|
// Client
|
|
|
|
//********************************************
|
|
|
|
|
2019-02-02 18:17:44 +00:00
|
|
|
/**
|
|
|
|
* Updates the user time (time of last action in the active window).
|
|
|
|
* This is called inside kwin for every action with the window
|
|
|
|
* that qualifies for user interaction (clicking on it, activate it
|
|
|
|
* externally, etc.).
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2019-09-24 08:48:08 +00:00
|
|
|
void X11Client::updateUserTime(xcb_timestamp_t time)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
// copied in Group::updateUserTime
|
2014-06-01 15:57:51 +00:00
|
|
|
if (time == XCB_TIME_CURRENT_TIME) {
|
|
|
|
updateXTime();
|
2007-04-29 17:35:43 +00:00
|
|
|
time = xTime();
|
2014-06-01 15:57:51 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time != -1U
|
2013-05-03 09:29:50 +00:00
|
|
|
&& (m_userTime == XCB_TIME_CURRENT_TIME
|
2014-03-20 08:51:20 +00:00
|
|
|
|| NET::timestampCompare(time, m_userTime) > 0)) { // time > user_time
|
2013-05-03 09:29:50 +00:00
|
|
|
m_userTime = time;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
shade_below = nullptr; // do not hover re-shade a window after it got interaction
|
2012-03-14 08:59:41 +00:00
|
|
|
}
|
2013-05-03 09:29:50 +00:00
|
|
|
group()->updateUserTime(m_userTime);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
xcb_timestamp_t X11Client::readUserCreationTime() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-04-15 08:09:25 +00:00
|
|
|
Xcb::Property prop(false, window(), atoms->kde_net_wm_user_creation_time, XCB_ATOM_CARDINAL, 0, 1);
|
|
|
|
return prop.value<xcb_timestamp_t>(-1);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
xcb_timestamp_t X11Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id, const KStartupInfoData *asn_data,
|
2013-05-03 09:29:50 +00:00
|
|
|
bool session) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-05-03 09:29:50 +00:00
|
|
|
xcb_timestamp_t time = info->userTime();
|
2013-11-01 11:29:05 +00:00
|
|
|
//qDebug() << "User timestamp, initial:" << time;
|
2010-05-13 18:53:08 +00:00
|
|
|
//^^ this deadlocks kwin --replace sometimes.
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// newer ASN timestamp always replaces user timestamp, unless user timestamp is 0
|
|
|
|
// helps e.g. with konqy reusing
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (asn_data != nullptr && time != 0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (asn_id->timestamp() != 0
|
2014-03-20 08:51:20 +00:00
|
|
|
&& (time == -1U || NET::timestampCompare(asn_id->timestamp(), time) > 0)) {
|
2007-04-29 17:35:43 +00:00
|
|
|
time = asn_id->timestamp();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "User timestamp, ASN:" << time;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time == -1U) {
|
|
|
|
// The window doesn't have any timestamp.
|
|
|
|
// If it's the first window for its application
|
|
|
|
// (i.e. there's no other window from the same app),
|
|
|
|
// use the _KDE_NET_WM_USER_CREATION_TIME trick.
|
|
|
|
// Otherwise, refuse activation of a window
|
|
|
|
// from already running application if this application
|
|
|
|
// is not the active one (unless focus stealing prevention is turned off).
|
2019-09-24 08:48:08 +00:00
|
|
|
X11Client *act = dynamic_cast<X11Client *>(workspace()->mostRecentlyActivatedClient());
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (act != nullptr && !belongToSameApplication(act, this, SameApplicationCheck::RelaxedForActive)) {
|
2007-04-29 17:35:43 +00:00
|
|
|
bool first_window = true;
|
2019-09-24 08:48:08 +00:00
|
|
|
auto sameApplicationActiveHackPredicate = [this](const X11Client *cl) {
|
2014-03-20 08:19:53 +00:00
|
|
|
// ignore already existing splashes, toolbars, utilities and menus,
|
|
|
|
// as the app may show those before the main window
|
|
|
|
return !cl->isSplash() && !cl->isToolbar() && !cl->isUtility() && !cl->isMenu()
|
2019-09-24 08:48:08 +00:00
|
|
|
&& cl != this && X11Client::belongToSameApplication(cl, this, SameApplicationCheck::RelaxedForActive);
|
2014-03-20 08:19:53 +00:00
|
|
|
};
|
2011-01-30 14:34:42 +00:00
|
|
|
if (isTransient()) {
|
2015-09-11 13:55:23 +00:00
|
|
|
auto clientMainClients = [this] () -> ClientList {
|
|
|
|
ClientList ret;
|
|
|
|
const auto mcs = mainClients();
|
|
|
|
for (auto mc: mcs) {
|
2019-09-24 08:48:08 +00:00
|
|
|
if (X11Client *c = dynamic_cast<X11Client *>(mc)) {
|
2015-09-11 13:55:23 +00:00
|
|
|
ret << c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
2011-01-30 14:34:42 +00:00
|
|
|
if (act->hasTransient(this, true))
|
2007-04-29 17:35:43 +00:00
|
|
|
; // is transient for currently active window, even though it's not
|
2011-01-30 14:34:42 +00:00
|
|
|
// the same app (e.g. kcookiejar dialog) -> allow activation
|
|
|
|
else if (groupTransient() &&
|
2019-09-24 08:48:08 +00:00
|
|
|
findInList<X11Client, X11Client>(clientMainClients(), sameApplicationActiveHackPredicate) == nullptr)
|
2007-04-29 17:35:43 +00:00
|
|
|
; // standalone transient
|
|
|
|
else
|
|
|
|
first_window = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2014-03-20 08:19:53 +00:00
|
|
|
if (workspace()->findClient(sameApplicationActiveHackPredicate))
|
2007-04-29 17:35:43 +00:00
|
|
|
first_window = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// don't refuse if focus stealing prevention is turned off
|
2012-02-20 09:25:13 +00:00
|
|
|
if (!first_window && rules()->checkFSP(options->focusStealingPreventionLevel()) > 0) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "User timestamp, already exists:" << 0;
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0; // refuse activation
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// Creation time would just mess things up during session startup,
|
|
|
|
// as possibly many apps are started up at the same time.
|
|
|
|
// If there's no active window yet, no timestamp will be needed,
|
|
|
|
// as plain Workspace::allowClientActivation() will return true
|
|
|
|
// in such case. And if there's already active window,
|
|
|
|
// it's better not to activate the new one.
|
|
|
|
// Unless it was the active window at the time
|
|
|
|
// of session saving and there was no user interaction yet,
|
|
|
|
// this check will be done in manage().
|
2011-01-30 14:34:42 +00:00
|
|
|
if (session)
|
2007-04-29 17:35:43 +00:00
|
|
|
return -1U;
|
2012-03-14 07:03:42 +00:00
|
|
|
time = readUserCreationTime();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "User timestamp, final:" << this << ":" << time;
|
2011-01-30 14:34:42 +00:00
|
|
|
return time;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
xcb_timestamp_t X11Client::userTime() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-05-03 09:29:50 +00:00
|
|
|
xcb_timestamp_t time = m_userTime;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time == 0) // doesn't want focus after showing
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
Q_ASSERT(group() != nullptr);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time == -1U
|
|
|
|
|| (group()->userTime() != -1U
|
2014-03-20 08:51:20 +00:00
|
|
|
&& NET::timestampCompare(group()->userTime(), time) > 0))
|
2007-04-29 17:35:43 +00:00
|
|
|
time = group()->userTime();
|
|
|
|
return time;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void X11Client::doSetActive()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
updateUrgency(); // demand attention again if it's still urgent
|
Support NET_WM_STATE_FOCUSED
Summary:
This is used by GTK clients to know whether to draw as though they have
focus or not. Whilst it's most visible for CSDs headers, use of the
active/inactive palette (or backdrop class in GTK terms) applies
everywhere.
Rationale of the flag is to allow the WM to hint visual states without
giving input, i.e so you can hint that the parent of a modal dialog
should be shown as active. Though kwin only sets it on the truly active
window to match the behaviour our other windows follow.
BUG: 398832
I expect this to be potentially controversial as it's new code in X11,
so in advance:
* Unlike GTK_FRAME_EXTENTS, it is part of the specificiation (albeit
1.4) even i3 supports it.
* It does fix a real world issue
* It's only 2 lines (plus trivial boiler plate in kwindowsystem)
* It's in code path that we rely on for our existing code
* If there's a situation where this does break, the worst that will
happen is a client gets a visual hint to have focus incorrectly, which
ultimately is the same as the current state
Test Plan:
Used my CSS for breeze-gtk
moved between windows
Reviewers: #kwin, rooty, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, ognarb, ngraham, rooty, graesslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19613
2019-05-10 14:32:55 +00:00
|
|
|
info->setState(isActive() ? NET::Focused : NET::States(), NET::Focused);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void X11Client::startupIdChanged()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
KStartupInfoId asn_id;
|
|
|
|
KStartupInfoData asn_data;
|
2011-01-30 14:34:42 +00:00
|
|
|
bool asn_valid = workspace()->checkStartupNotification(window(), asn_id, asn_data);
|
|
|
|
if (!asn_valid)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
// If the ASN contains desktop, move it to the desktop, otherwise move it to the current
|
|
|
|
// desktop (since the new ASN should make the window act like if it's a new application
|
|
|
|
// launched). However don't affect the window's desktop if it's set to be on all desktops.
|
2012-11-16 07:23:47 +00:00
|
|
|
int desktop = VirtualDesktopManager::self()->current();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (asn_data.desktop() != 0)
|
2007-04-29 17:35:43 +00:00
|
|
|
desktop = asn_data.desktop();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!isOnAllDesktops())
|
|
|
|
workspace()->sendClientToDesktop(this, desktop, true);
|
|
|
|
if (asn_data.xinerama() != -1)
|
|
|
|
workspace()->sendClientToScreen(this, asn_data.xinerama());
|
2019-09-06 14:30:26 +00:00
|
|
|
const xcb_timestamp_t timestamp = asn_id.timestamp();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (timestamp != 0) {
|
|
|
|
bool activate = workspace()->allowClientActivation(this, timestamp);
|
|
|
|
if (asn_data.desktop() != 0 && !isOnCurrentDesktop())
|
2007-04-29 17:35:43 +00:00
|
|
|
activate = false; // it was started on different desktop than current one
|
2011-01-30 14:34:42 +00:00
|
|
|
if (activate)
|
|
|
|
workspace()->activateClient(this);
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
|
|
|
demandAttention();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void X11Client::updateUrgency()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-09-12 11:56:34 +00:00
|
|
|
if (info->urgency())
|
2007-04-29 17:35:43 +00:00
|
|
|
demandAttention();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Group
|
|
|
|
//****************************************
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void Group::startupIdChanged()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
KStartupInfoId asn_id;
|
|
|
|
KStartupInfoData asn_data;
|
2011-01-30 14:34:42 +00:00
|
|
|
bool asn_valid = workspace()->checkStartupNotification(leader_wid, asn_id, asn_data);
|
|
|
|
if (!asn_valid)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (asn_id.timestamp() != 0 && user_time != -1U
|
2014-03-20 08:51:20 +00:00
|
|
|
&& NET::timestampCompare(asn_id.timestamp(), user_time) > 0) {
|
2007-04-29 17:35:43 +00:00
|
|
|
user_time = asn_id.timestamp();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2014-06-01 15:57:51 +00:00
|
|
|
void Group::updateUserTime(xcb_timestamp_t time)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-09-24 08:48:08 +00:00
|
|
|
// copy of X11Client::updateUserTime
|
2014-06-01 15:57:51 +00:00
|
|
|
if (time == XCB_CURRENT_TIME) {
|
|
|
|
updateXTime();
|
2007-04-29 17:35:43 +00:00
|
|
|
time = xTime();
|
2014-06-01 15:57:51 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (time != -1U
|
2014-06-01 15:57:51 +00:00
|
|
|
&& (user_time == XCB_CURRENT_TIME
|
2014-03-20 08:51:20 +00:00
|
|
|
|| NET::timestampCompare(time, user_time) > 0)) // time > user_time
|
2007-04-29 17:35:43 +00:00
|
|
|
user_time = time;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|