kwin/client.cpp

2285 lines
75 KiB
C++
Raw Normal View History

/********************************************************************
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>
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/>.
*********************************************************************/
// own
#include "client.h"
// kwin
#ifdef KWIN_BUILD_ACTIVITIES
#include "activities.h"
#endif
#include "atoms.h"
Improved resolving whether a window is on local machine Most windows use the hostname in WM_CLIENT_MACHINE, but there are windows using the FQDN (for example libreoffice). So instead of "foo" it is "foo.local.net" or similar. The logic so far has been unable to properly determine whether windows with FQDN are on the local system. In order to solve this problem the handling is split out into an own class which stores the information of hostname and whether it is a local machine. This is to not query multiple times. To determine whether the Client is on the local system getaddrinfo is used for the own hostname and the FQDN provided in WM_CLIENT_MACHINE. If one of the queried names matches, we know that it is on the local machine. The old logic to compare the hostname is still used and getaddrinfo is only a fallback in case hostname does not match. The problem with getaddrinfo is, that it accesses the network and by that could block. To circumvent this problem the calls are moved into threads by using QtConcurrent::run. Obviously this brings disadvantages. When trying to resolve whether a Client is on the local machine and a FQDN is used, the information is initially wrong. The new ClientMachine class emits a signal when the information that the system is local becomes available, but for some things this is just too late: * window rules are already gathered * Session Management has already taken place In both cases this is an acceptable loss. For window rules it just needs a proper matching of the machine in case of localhost (remote hosts are not affected). And the case of session management is very academic as it is unlikely that a restoring session contains remote windows. BUG: 308391 FIXED-IN: 4.11 REVIEW: 108235
2013-01-07 07:07:27 +00:00
#include "client_machine.h"
#include "composite.h"
#include "cursor.h"
#include "deleted.h"
#include "focuschain.h"
#include "group.h"
#include "shadow.h"
#include "workspace.h"
Screenedge show support for Clients This provides a new protocol intended to be used by auto-hiding panels to make use of the centralized screen edges. To use it a Client can set an X11 property of type _KDE_NET_WM_SCREEN_EDGE_SHOW to KWin. As value it takes: * 0: top edge * 1: right edge * 2: bottom edge * 3: left edge KWin will hide the Client (hide because unmap or minimize would break it) and create an Edge. If that Edge gets triggered the Client is shown again and the property gets deleted. If the Client doesn't border the specified screen edge the Client gets shown immediately so that we never end in a situation that we cannot unhide the auto-hidden panel again. The exact process is described in the documentation of ScreenEdges. The Client can request to be shown again by deleting the property. If KWin gets restarted the state is read from the property and it is tried to create the edge as described. As this is a KWin specific extension we need to discuss what it means for Clients using this feature with other WMs: it does nothing. As the Client gets hidden by KWin and not by the Client, it just doesn't get hidden if the WM doesn't provide the feature. In case of an auto-hiding panel this seems like a good solution given that we don't want to hide it if we cannot unhide it. Of course there's the option for the Client to provide that feature itself and if that's wanted we would need to announce the feature in the _NET_SUPPORTED atom. At the moment that doesn't sound like being needed as Plasma doesn't want to provide an own implementation. The implementation comes with a small test application showing how the feature is intended to be used. REVIEW: 115910
2014-02-20 11:39:23 +00:00
#include "screenedge.h"
#include "decorations/decorationbridge.h"
#include "decorations/decoratedclient.h"
#include <KDecoration2/Decoration>
#include <KDecoration2/DecoratedClient>
// KDE
#include <KWindowSystem>
#include <KColorScheme>
// Qt
#include <QApplication>
#include <QDebug>
2014-12-02 12:50:26 +00:00
#include <QFile>
#include <QMouseEvent>
#include <QProcess>
#include <QStandardPaths>
#include <QScriptEngine>
#include <QScriptProgram>
#include <QWhatsThis>
// XLib
#include <X11/Xutil.h>
#include <fixx11h.h>
// system
#include <unistd.h>
#include <signal.h>
// Put all externs before the namespace statement to allow the linker
// to resolve them properly
namespace KWin
{
bool Client::s_haveResizeEffect = false;
const long ClientWinMask = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE |
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_KEYMAP_STATE |
XCB_EVENT_MASK_BUTTON_MOTION |
XCB_EVENT_MASK_POINTER_MOTION | // need this, too!
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW |
XCB_EVENT_MASK_FOCUS_CHANGE |
XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
// Creating a client:
// - only by calling Workspace::createClient()
// - it creates a new client and calls manage() for it
//
// Destroying a client:
// - destroyClient() - only when the window itself has been destroyed
// - releaseWindow() - the window is kept, only the client itself is destroyed
/**
* \class Client client.h
* \brief The Client class encapsulates a window decoration frame.
*/
/**
* This ctor is "dumb" - it only initializes data. All the real initialization
* is done in manage().
*/
Client::Client()
: AbstractClient()
, m_client()
, m_wrapper()
, m_frame()
, m_decoration(nullptr)
, m_activityUpdatesBlocked(false)
, m_blockedActivityUpdatesRequireTransients(false)
, m_moveResizeGrabWindow()
2011-01-30 14:34:42 +00:00
, move_resize_has_keyboard_grab(false)
, m_managed(false)
2011-01-30 14:34:42 +00:00
, transient_for (NULL)
, m_transientForId(XCB_WINDOW_NONE)
, m_originalTransientForId(XCB_WINDOW_NONE)
, shade_below(NULL)
, m_motif(atoms->motif_wm_hints)
, blocks_compositing(false)
, m_cursor(Qt::ArrowCursor)
2011-01-30 14:34:42 +00:00
, shadeHoverTimer(NULL)
, delayedMoveResizeTimer(NULL)
, m_colormap(XCB_COLORMAP_NONE)
2011-01-30 14:34:42 +00:00
, in_group(NULL)
, tab_group(NULL)
2011-01-30 14:34:42 +00:00
, in_layer(UnknownLayer)
, ping_timer(NULL)
, m_killHelperPID(0)
, m_pingTimestamp(XCB_TIME_CURRENT_TIME)
, m_userTime(XCB_TIME_CURRENT_TIME) // Not known yet
2011-01-30 14:34:42 +00:00
, allowed_actions(0)
, block_geometry_updates(0)
, pending_geometry_update(PendingGeometryNone)
, shade_geometry_change(false)
, sm_stacking_order(-1)
, electricMaximizing(false)
, activitiesDefined(false)
, needsSessionInteract(false)
, needsXWindowMove(false)
, m_decoInputExtent()
, m_focusOutTimer(nullptr)
Add a script to enforce window decorations for GTK windows This is going to be a controversal change. It enforces KWin decorations on all client side decorated windows from GTK+. Unfortunately we are caught between a rock and a hard place. Keeping the status quo means having broken windows and a more or less broken window manager due to GTK+ including the shadow in the windows. This is no solution. Enforcing server side decorations visually breaks the windows. This is also no solution. So why do it? It's our task to provide the best possible user experience and KWin is a window manager which has always done great efforts to fix misbehaving windows. One can think of the focus stealing prevention, the window rules and lately the scripts. The best possible window management experience is our aim. This means we cannot leave the users with the broken windows from GTK. The issues we noticed were reported to GTK+ about 2 months ago and we are working on improving the situation. Unfortunately several issues are not yet addressed and others will only be addressed in the next GTK+ release. We are working on improving the NETWM spec (see [1]) to ensure that the client side decorated windows are not in a broken state. This means the enforcment is a temporary solution and will be re-evaluated with the next GTK release. I would prefer to not have to do such a change, if some of the bugs were fixed or GTK+ would not use client-side-decos on wms not yet supporting those all of this would be a no issue. For a complete list of the problems caused by GTK's decos see bug [2] and the linked bug reports from there. The change is done in a least inversive way in KWin. We just check for the property _GTK_FRAME_EXTENTS and create a Q_PROPERTY in Client for it. If we add support for the frame extents in future we would also need this. So it's not a change just for enforcing the decoration. The actual enforcing is done through a KWin script so users can still disable it. REVIEW: 119062 [1] https://mail.gnome.org/archives/wm-spec-list/2014-June/msg00002.html [2] https://bugzilla.gnome.org/show_bug.cgi?id=729721
2014-07-01 13:44:02 +00:00
, m_clientSideDecorated(false)
2011-01-30 14:34:42 +00:00
{
// TODO: Do all as initialization
2013-07-31 08:11:39 +00:00
syncRequest.counter = syncRequest.alarm = XCB_NONE;
syncRequest.timeout = syncRequest.failsafeTimeout = NULL;
syncRequest.lastTimestamp = xTime();
syncRequest.isPending = false;
// Set the initial mapping state
mapping_state = Withdrawn;
quick_tile_mode = QuickTileNone;
mode = PositionCenter;
buttonDown = false;
moveResizeMode = false;
info = NULL;
shade_mode = ShadeNone;
deleting = false;
fullscreen_mode = FullScreenNone;
hidden = false;
modal = false;
noborder = false;
app_noborder = false;
ignore_focus_stealing = false;
check_active_modal = false;
max_mode = MaximizeRestore;
//Client to workspace connections require that each
//client constructed be connected to the workspace wrapper
2011-01-30 14:34:42 +00:00
geom = QRect(0, 0, 100, 100); // So that decorations don't start with size being (0,0)
client_size = QSize(100, 100);
ready_for_painting = false; // wait for first damage or sync reply
connect(this, &Client::geometryShapeChanged, this, &Client::geometryChanged);
auto signalMaximizeChanged = static_cast<void (Client::*)(KWin::AbstractClient*, MaximizeMode)>(&Client::clientMaximizedStateChanged);
connect(this, signalMaximizeChanged, this, &Client::geometryChanged);
connect(this, &Client::clientStepUserMovedResized, this, &Client::geometryChanged);
connect(this, &Client::clientStartUserMovedResized, this, &Client::moveResizedChanged);
connect(this, &Client::clientFinishUserMovedResized, this, &Client::moveResizedChanged);
connect(this, &Client::clientStartUserMovedResized, this, &Client::removeCheckScreenConnection);
connect(this, &Client::clientFinishUserMovedResized, this, &Client::setupCheckScreenConnection);
connect(this, &Client::paletteChanged, this, &Client::triggerDecorationRepaint);
connect(clientMachine(), &ClientMachine::localhostChanged, this, &Client::updateCaption);
connect(options, &Options::condensedTitleChanged, this, &Client::updateCaption);
Improved resolving whether a window is on local machine Most windows use the hostname in WM_CLIENT_MACHINE, but there are windows using the FQDN (for example libreoffice). So instead of "foo" it is "foo.local.net" or similar. The logic so far has been unable to properly determine whether windows with FQDN are on the local system. In order to solve this problem the handling is split out into an own class which stores the information of hostname and whether it is a local machine. This is to not query multiple times. To determine whether the Client is on the local system getaddrinfo is used for the own hostname and the FQDN provided in WM_CLIENT_MACHINE. If one of the queried names matches, we know that it is on the local machine. The old logic to compare the hostname is still used and getaddrinfo is only a fallback in case hostname does not match. The problem with getaddrinfo is, that it accesses the network and by that could block. To circumvent this problem the calls are moved into threads by using QtConcurrent::run. Obviously this brings disadvantages. When trying to resolve whether a Client is on the local machine and a FQDN is used, the information is initially wrong. The new ClientMachine class emits a signal when the information that the system is local becomes available, but for some things this is just too late: * window rules are already gathered * Session Management has already taken place In both cases this is an acceptable loss. For window rules it just needs a proper matching of the machine in case of localhost (remote hosts are not affected). And the case of session management is very academic as it is unlikely that a restoring session contains remote windows. BUG: 308391 FIXED-IN: 4.11 REVIEW: 108235
2013-01-07 07:07:27 +00:00
// SELI TODO: Initialize xsizehints??
2011-01-30 14:34:42 +00:00
}
/**
* "Dumb" destructor.
*/
Client::~Client()
2011-01-30 14:34:42 +00:00
{
if (m_killHelperPID && !::kill(m_killHelperPID, 0)) { // means the process is alive
::kill(m_killHelperPID, SIGTERM);
m_killHelperPID = 0;
}
//SWrapper::Client::clientRelease(this);
2013-07-31 08:11:39 +00:00
if (syncRequest.alarm != XCB_NONE)
xcb_sync_destroy_alarm(connection(), syncRequest.alarm);
assert(!moveResizeMode);
assert(m_client == XCB_WINDOW_NONE);
assert(m_wrapper == XCB_WINDOW_NONE);
//assert( frameId() == None );
Q_ASSERT(m_decoration == nullptr);
2011-01-30 14:34:42 +00:00
assert(block_geometry_updates == 0);
assert(!check_active_modal);
for (auto it = m_connections.constBegin(); it != m_connections.constEnd(); ++it) {
disconnect(*it);
}
2011-01-30 14:34:42 +00:00
}
// Use destroyClient() or releaseWindow(), Client instances cannot be deleted directly
void Client::deleteClient(Client* c)
2011-01-30 14:34:42 +00:00
{
delete c;
2011-01-30 14:34:42 +00:00
}
/**
* Releases the window. The client has done its job and the window is still existing.
*/
2011-01-30 14:34:42 +00:00
void Client::releaseWindow(bool on_shutdown)
{
assert(!deleting);
deleting = true;
Deleted* del = NULL;
if (!on_shutdown) {
del = Deleted::create(this);
}
if (moveResizeMode)
emit clientFinishUserMovedResized(this);
emit windowClosed(this, del);
finishCompositing();
RuleBook::self()->discardUsed(this, true); // Remove ForceTemporarily rules
2011-01-30 14:34:42 +00:00
StackingUpdatesBlocker blocker(workspace());
if (moveResizeMode)
2011-01-30 14:34:42 +00:00
leaveMoveResize();
finishWindowRules();
++block_geometry_updates;
2011-01-30 14:34:42 +00:00
if (isOnCurrentDesktop() && isShown(true))
addWorkspaceRepaint(visibleRect());
// Grab X during the release to make removing of properties, setting to withdrawn state
// and repareting to root an atomic operation (http://lists.kde.org/?l=kde-devel&m=116448102901184&w=2)
grabXServer();
2011-01-30 14:34:42 +00:00
exportMappingState(WithdrawnState);
setModal(false); // Otherwise its mainwindow wouldn't get focus
hidden = true; // So that it's not considered visible anymore (can't use hideClient(), it would set flags)
2011-01-30 14:34:42 +00:00
if (!on_shutdown)
workspace()->clientHidden(this);
m_frame.unmap(); // Destroying decoration would cause ugly visual effect
destroyDecoration();
cleanGrouping();
2011-01-30 14:34:42 +00:00
if (!on_shutdown) {
workspace()->removeClient(this);
// Only when the window is being unmapped, not when closing down KWin (NETWM sections 5.5,5.7)
2011-01-30 14:34:42 +00:00
info->setDesktop(0);
info->setState(0, info->state()); // Reset all state flags
} else
untab();
xcb_connection_t *c = connection();
m_client.deleteProperty(atoms->kde_net_wm_user_creation_time);
m_client.deleteProperty(atoms->net_frame_extents);
m_client.deleteProperty(atoms->kde_net_wm_frame_strut);
m_client.reparent(rootWindow(), x(), y());
xcb_change_save_set(c, XCB_SET_MODE_DELETE, m_client);
m_client.selectInput(XCB_EVENT_MASK_NO_EVENT);
2011-01-30 14:34:42 +00:00
if (on_shutdown)
// Map the window, so it can be found after another WM is started
m_client.map();
2011-01-30 14:34:42 +00:00
// TODO: Preserve minimized, shaded etc. state?
else // Make sure it's not mapped if the app unmapped it (#65279). The app
2011-01-30 14:34:42 +00:00
// may do map+unmap before we initially map the window by calling rawShow() from manage().
m_client.unmap();
m_client.reset();
m_wrapper.reset();
m_frame.reset();
//frame = None;
--block_geometry_updates; // Don't use GeometryUpdatesBlocker, it would now set the geometry
if (!on_shutdown) {
disownDataPassedToDeleted();
del->unrefWindow();
}
checkNonExistentClients();
deleteClient(this);
ungrabXServer();
2011-01-30 14:34:42 +00:00
}
/**
* Like releaseWindow(), but this one is called when the window has been already destroyed
* (E.g. The application closed it)
*/
void Client::destroyClient()
2011-01-30 14:34:42 +00:00
{
assert(!deleting);
deleting = true;
2011-01-30 14:34:42 +00:00
Deleted* del = Deleted::create(this);
if (moveResizeMode)
emit clientFinishUserMovedResized(this);
emit windowClosed(this, del);
finishCompositing(ReleaseReason::Destroyed);
RuleBook::self()->discardUsed(this, true); // Remove ForceTemporarily rules
2011-01-30 14:34:42 +00:00
StackingUpdatesBlocker blocker(workspace());
if (moveResizeMode)
2011-01-30 14:34:42 +00:00
leaveMoveResize();
finishWindowRules();
++block_geometry_updates;
2011-01-30 14:34:42 +00:00
if (isOnCurrentDesktop() && isShown(true))
addWorkspaceRepaint(visibleRect());
setModal(false);
hidden = true; // So that it's not considered visible anymore
2011-01-30 14:34:42 +00:00
workspace()->clientHidden(this);
destroyDecoration();
cleanGrouping();
workspace()->removeClient(this);
m_client.reset(); // invalidate
m_wrapper.reset();
m_frame.reset();
//frame = None;
--block_geometry_updates; // Don't use GeometryUpdatesBlocker, it would now set the geometry
disownDataPassedToDeleted();
del->unrefWindow();
checkNonExistentClients();
deleteClient(this);
2011-01-30 14:34:42 +00:00
}
void Client::updateInputWindow()
{
if (!Xcb::Extensions::self()->isShapeInputAvailable())
return;
QRegion region;
if (!noBorder() && m_decoration) {
const QMargins &r = m_decoration->resizeOnlyBorders();
const int left = r.left();
const int top = r.top();
const int right = r.right();
const int bottom = r.bottom();
if (left != 0 || top != 0 || right != 0 || bottom != 0) {
region = QRegion(-left,
-top,
m_decoration->size().width() + left + right,
m_decoration->size().height() + top + bottom);
region = region.subtracted(m_decoration->rect());
}
}
if (region.isEmpty()) {
m_decoInputExtent.reset();
return;
}
QRect bounds = region.boundingRect();
input_offset = bounds.topLeft();
// Move the bounding rect to screen coordinates
bounds.translate(geometry().topLeft());
// Move the region to input window coordinates
region.translate(-input_offset);
if (!m_decoInputExtent.isValid()) {
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
const uint32_t values[] = {true,
XCB_EVENT_MASK_ENTER_WINDOW |
XCB_EVENT_MASK_LEAVE_WINDOW |
XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_POINTER_MOTION
};
m_decoInputExtent.create(bounds, XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
if (mapping_state == Mapped)
m_decoInputExtent.map();
} else {
m_decoInputExtent.setGeometry(bounds);
}
const QVector<xcb_rectangle_t> rects = Xcb::regionToRects(region);
xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_CLIP_ORDERING_UNSORTED,
m_decoInputExtent, 0, 0, rects.count(), rects.constData());
}
2011-01-30 14:34:42 +00:00
void Client::updateDecoration(bool check_workspace_pos, bool force)
{
if (!force &&
((m_decoration == NULL && noBorder()) || (m_decoration != NULL && !noBorder())))
return;
QRect oldgeom = geometry();
fix sendToScreen/checkWorkspaceGeometry Prime target is to preserve the in-screen condition of client AND window.i[1] Atm. when the client is fully in sight (but the window is not) - regardless of snapping or screen change - a workspace update (screen change, resolution change, adding/removing a strutting panel) would allow the client to partiall escape screen bounds. This is changed so that if the client is fully in sight, it's kept fully in sight (but not the decoration) If the entire window was fully in sight, it's also kept (as is right now) The code handles inner screen edges (if the client was in sight, the entire window will be if we'd bleed to the other screen) [1] I'd say that handling the client is more relevant, but foresee more complaints if the window wasn't handled anymore ;-) During that, i stumbled across some other issues. - when a window centered on one screen is moved to a screen smaller than the window, the window is shrinked to the dimensions of that screen and now randomly touches eg. left AND right edge. When moved back, the right and bottom edge were preferred (to the window was "moved" into the lower right corner). It's now kept centered. - geom_restore was saved before keeping the window in the new screen area (causing accidental drops on screen changes) BUG: 330968 REVIEW: 122517 FIXED-IN: 5.4 Prime target is to preserve the in-screen condition of client AND window.[1] Atm. when the client is fully in sight (but the window is not) - regardless of snapping or screen change - a workspace update (screen change, resolution change, adding/removing a strutting panel) would allow the client to partiall escape screen bounds. This is changed so that if the client is fully in sight, it's kept fully in sight (but not the decoration) If the entire window was fully in sight, it's also kept (as is right now) The code handles inner screen edges (if the client was in sight, the entire window will be if we'd bleed to the other screen) [1] I'd say that handling the client is more relevant, but foresee more complaints if the window wasn't handled anymore ;-) During that, i stumbled across some other issues. - when a window centered on one screen is moved to a screen smaller than the window, the window is shrinked to the dimensions of that screen and now randomly touches eg. left AND right edge. When moved back, the right and bottom edge were preferred (to the window was "moved" into the lower right corner). It's now kept centered. - geom_restore was saved before keeping the window in the new screen area (causing accidental drops on screen changes) BUG: 330968 REVIEW: 116029 FIXED-IN: 5.3
2015-02-06 21:48:12 +00:00
QRect oldClientGeom = oldgeom.adjusted(borderLeft(), borderTop(), -borderRight(), -borderBottom());
2011-01-30 14:34:42 +00:00
blockGeometryUpdates(true);
if (force)
destroyDecoration();
2011-01-30 14:34:42 +00:00
if (!noBorder()) {
createDecoration(oldgeom);
2011-01-30 14:34:42 +00:00
} else
destroyDecoration();
getShadow();
2011-01-30 14:34:42 +00:00
if (check_workspace_pos)
fix sendToScreen/checkWorkspaceGeometry Prime target is to preserve the in-screen condition of client AND window.i[1] Atm. when the client is fully in sight (but the window is not) - regardless of snapping or screen change - a workspace update (screen change, resolution change, adding/removing a strutting panel) would allow the client to partiall escape screen bounds. This is changed so that if the client is fully in sight, it's kept fully in sight (but not the decoration) If the entire window was fully in sight, it's also kept (as is right now) The code handles inner screen edges (if the client was in sight, the entire window will be if we'd bleed to the other screen) [1] I'd say that handling the client is more relevant, but foresee more complaints if the window wasn't handled anymore ;-) During that, i stumbled across some other issues. - when a window centered on one screen is moved to a screen smaller than the window, the window is shrinked to the dimensions of that screen and now randomly touches eg. left AND right edge. When moved back, the right and bottom edge were preferred (to the window was "moved" into the lower right corner). It's now kept centered. - geom_restore was saved before keeping the window in the new screen area (causing accidental drops on screen changes) BUG: 330968 REVIEW: 122517 FIXED-IN: 5.4 Prime target is to preserve the in-screen condition of client AND window.[1] Atm. when the client is fully in sight (but the window is not) - regardless of snapping or screen change - a workspace update (screen change, resolution change, adding/removing a strutting panel) would allow the client to partiall escape screen bounds. This is changed so that if the client is fully in sight, it's kept fully in sight (but not the decoration) If the entire window was fully in sight, it's also kept (as is right now) The code handles inner screen edges (if the client was in sight, the entire window will be if we'd bleed to the other screen) [1] I'd say that handling the client is more relevant, but foresee more complaints if the window wasn't handled anymore ;-) During that, i stumbled across some other issues. - when a window centered on one screen is moved to a screen smaller than the window, the window is shrinked to the dimensions of that screen and now randomly touches eg. left AND right edge. When moved back, the right and bottom edge were preferred (to the window was "moved" into the lower right corner). It's now kept centered. - geom_restore was saved before keeping the window in the new screen area (causing accidental drops on screen changes) BUG: 330968 REVIEW: 116029 FIXED-IN: 5.3
2015-02-06 21:48:12 +00:00
checkWorkspacePosition(oldgeom, -2, oldClientGeom);
updateInputWindow();
2011-01-30 14:34:42 +00:00
blockGeometryUpdates(false);
updateFrameExtents();
2011-01-30 14:34:42 +00:00
}
void Client::createDecoration(const QRect& oldgeom)
{
m_decoration = Decoration::DecorationBridge::self()->createDecoration(this);
if (m_decoration) {
QMetaObject::invokeMethod(m_decoration, "update", Qt::QueuedConnection);
connect(m_decoration, &KDecoration2::Decoration::shadowChanged, this, &Toplevel::getShadow);
connect(m_decoration, &KDecoration2::Decoration::resizeOnlyBordersChanged, this, &Client::updateInputWindow);
connect(m_decoration, &KDecoration2::Decoration::bordersChanged, this,
[this]() {
GeometryUpdatesBlocker blocker(this);
// TODO: this is obviously idempotent
// calculateGravitation(true) would have to operate on the old border sizes
// move(calculateGravitation(true));
// move(calculateGravitation(false));
QRect oldgeom = geometry();
plainResize(sizeForClientSize(clientSize()), ForceGeometrySet);
if (!isShade())
checkWorkspacePosition(oldgeom);
emit geometryShapeChanged(this, oldgeom);
}
);
}
move(calculateGravitation(false));
plainResize(sizeForClientSize(clientSize()), ForceGeometrySet);
if (Compositor::compositing()) {
discardWindowPixmap();
}
emit geometryShapeChanged(this, oldgeom);
}
void Client::destroyDecoration()
2011-01-30 14:34:42 +00:00
{
QRect oldgeom = geometry();
if (m_decoration) {
QPoint grav = calculateGravitation(true);
delete m_decoration;
m_decoration = nullptr;
2011-01-30 14:34:42 +00:00
plainResize(sizeForClientSize(clientSize()), ForceGeometrySet);
move(grav);
if (compositing())
discardWindowPixmap();
if (!deleting) {
emit geometryShapeChanged(this, oldgeom);
}
}
m_decoInputExtent.reset();
2011-01-30 14:34:42 +00:00
}
void Client::triggerDecorationRepaint()
2011-01-30 14:34:42 +00:00
{
if (m_decoration) {
m_decoration->update();
}
2011-01-30 14:34:42 +00:00
}
void Client::layoutDecorationRects(QRect &left, QRect &top, QRect &right, QRect &bottom) const
2011-01-30 14:34:42 +00:00
{
if (!m_decoration) {
return;
}
QRect r = m_decoration->rect();
NETStrut strut = info->frameOverlap();
// Ignore the overlap strut when compositing is disabled
if (!compositing())
strut.left = strut.top = strut.right = strut.bottom = 0;
2011-01-30 14:34:42 +00:00
else if (strut.left == -1 && strut.top == -1 && strut.right == -1 && strut.bottom == -1) {
top = QRect(r.x(), r.y(), r.width(), r.height() / 3);
left = QRect(r.x(), r.y() + top.height(), width() / 2, r.height() / 3);
right = QRect(r.x() + left.width(), r.y() + top.height(), r.width() - left.width(), left.height());
bottom = QRect(r.x(), r.y() + top.height() + left.height(), r.width(), r.height() - left.height() - top.height());
return;
2011-01-30 14:34:42 +00:00
}
top = QRect(r.x(), r.y(), r.width(), borderTop() + strut.top);
bottom = QRect(r.x(), r.y() + r.height() - borderBottom() - strut.bottom,
r.width(), borderBottom() + strut.bottom);
left = QRect(r.x(), r.y() + top.height(),
borderLeft() + strut.left, r.height() - top.height() - bottom.height());
right = QRect(r.x() + r.width() - borderRight() - strut.right, r.y() + top.height(),
borderRight() + strut.right, r.height() - top.height() - bottom.height());
2011-01-30 14:34:42 +00:00
}
QRect Client::transparentRect() const
2011-01-30 14:34:42 +00:00
{
if (isShade())
return QRect();
NETStrut strut = info->frameOverlap();
// Ignore the strut when compositing is disabled or the decoration doesn't support it
if (!compositing())
strut.left = strut.top = strut.right = strut.bottom = 0;
else if (strut.left == -1 && strut.top == -1 && strut.right == -1 && strut.bottom == -1)
return QRect();
const QRect r = QRect(clientPos(), clientSize())
2011-01-30 14:34:42 +00:00
.adjusted(strut.left, strut.top, -strut.right, -strut.bottom);
if (r.isValid())
return r;
return QRect();
2011-01-30 14:34:42 +00:00
}
void Client::detectNoBorder()
2011-01-30 14:34:42 +00:00
{
if (shape()) {
noborder = true;
app_noborder = true;
return;
2011-01-30 14:34:42 +00:00
}
switch(windowType()) {
case NET::Desktop :
case NET::Dock :
case NET::TopMenu :
case NET::Splash :
case NET::Notification :
case NET::OnScreenDisplay :
2011-01-30 14:34:42 +00:00
noborder = true;
app_noborder = true;
break;
case NET::Unknown :
case NET::Normal :
case NET::Toolbar :
case NET::Menu :
case NET::Dialog :
case NET::Utility :
noborder = false;
break;
default:
abort();
}
// NET::Override is some strange beast without clear definition, usually
// just meaning "noborder", so let's treat it only as such flag, and ignore it as
// a window type otherwise (SUPPORTED_WINDOW_TYPES_MASK doesn't include it)
if (info->windowType(NET::OverrideMask) == NET::Override) {
noborder = true;
app_noborder = true;
}
2011-01-30 14:34:42 +00:00
}
void Client::updateFrameExtents()
2011-01-30 14:34:42 +00:00
{
NETStrut strut;
strut.left = borderLeft();
strut.right = borderRight();
strut.top = borderTop();
strut.bottom = borderBottom();
2011-01-30 14:34:42 +00:00
info->setFrameExtents(strut);
}
Xcb::Property Client::fetchGtkFrameExtents() const
{
return Xcb::Property(false, m_client, atoms->gtk_frame_extents, XCB_ATOM_CARDINAL, 0, 4);
}
void Client::readGtkFrameExtents(Xcb::Property &prop)
Add a script to enforce window decorations for GTK windows This is going to be a controversal change. It enforces KWin decorations on all client side decorated windows from GTK+. Unfortunately we are caught between a rock and a hard place. Keeping the status quo means having broken windows and a more or less broken window manager due to GTK+ including the shadow in the windows. This is no solution. Enforcing server side decorations visually breaks the windows. This is also no solution. So why do it? It's our task to provide the best possible user experience and KWin is a window manager which has always done great efforts to fix misbehaving windows. One can think of the focus stealing prevention, the window rules and lately the scripts. The best possible window management experience is our aim. This means we cannot leave the users with the broken windows from GTK. The issues we noticed were reported to GTK+ about 2 months ago and we are working on improving the situation. Unfortunately several issues are not yet addressed and others will only be addressed in the next GTK+ release. We are working on improving the NETWM spec (see [1]) to ensure that the client side decorated windows are not in a broken state. This means the enforcment is a temporary solution and will be re-evaluated with the next GTK release. I would prefer to not have to do such a change, if some of the bugs were fixed or GTK+ would not use client-side-decos on wms not yet supporting those all of this would be a no issue. For a complete list of the problems caused by GTK's decos see bug [2] and the linked bug reports from there. The change is done in a least inversive way in KWin. We just check for the property _GTK_FRAME_EXTENTS and create a Q_PROPERTY in Client for it. If we add support for the frame extents in future we would also need this. So it's not a change just for enforcing the decoration. The actual enforcing is done through a KWin script so users can still disable it. REVIEW: 119062 [1] https://mail.gnome.org/archives/wm-spec-list/2014-June/msg00002.html [2] https://bugzilla.gnome.org/show_bug.cgi?id=729721
2014-07-01 13:44:02 +00:00
{
m_clientSideDecorated = !prop.isNull() && prop->type != 0;
emit clientSideDecoratedChanged();
}
void Client::detectGtkFrameExtents()
{
Xcb::Property prop = fetchGtkFrameExtents();
readGtkFrameExtents(prop);
}
/**
* Resizes the decoration, and makes sure the decoration widget gets resize event
* even if the size hasn't changed. This is needed to make sure the decoration
* re-layouts (e.g. when maximization state changes,
* the decoration may alter some borders, but the actual size
* of the decoration stays the same).
*/
void Client::resizeDecoration()
2011-01-30 14:34:42 +00:00
{
if (m_decoration) {
m_decoration->update();
}
updateInputWindow();
2011-01-30 14:34:42 +00:00
}
bool Client::noBorder() const
2011-01-30 14:34:42 +00:00
{
return noborder || isFullScreen();
2011-01-30 14:34:42 +00:00
}
bool Client::userCanSetNoBorder() const
2011-01-30 14:34:42 +00:00
{
return !isFullScreen() && !isShade() && !tabGroup();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::setNoBorder(bool set)
{
if (!userCanSetNoBorder())
return;
2011-01-30 14:34:42 +00:00
set = rules()->checkNoBorder(set);
if (noborder == set)
return;
noborder = set;
2011-01-30 14:34:42 +00:00
updateDecoration(true, false);
updateWindowRules(Rules::NoBorder);
2011-01-30 14:34:42 +00:00
}
void Client::checkNoBorder()
2011-01-30 14:34:42 +00:00
{
setNoBorder(app_noborder);
}
bool Client::wantsShadowToBeRendered() const
{
return !isFullScreen() && maximizeMode() != MaximizeFull;
}
void Client::updateShape()
2011-01-30 14:34:42 +00:00
{
if (shape()) {
// Workaround for #19644 - Shaped windows shouldn't have decoration
if (!app_noborder) {
// Only when shape is detected for the first time, still let the user to override
app_noborder = true;
noborder = rules()->checkNoBorder(true);
2011-01-30 14:34:42 +00:00
updateDecoration(true);
}
if (noBorder()) {
xcb_shape_combine(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, XCB_SHAPE_SK_BOUNDING,
frameId(), clientPos().x(), clientPos().y(), window());
}
} else if (app_noborder) {
xcb_shape_mask(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, frameId(), 0, 0, XCB_PIXMAP_NONE);
detectNoBorder();
app_noborder = noborder;
noborder = rules()->checkNoBorder(noborder || m_motif.noBorder());
updateDecoration(true);
}
// Decoration mask (i.e. 'else' here) setting is done in setMask()
// when the decoration calls it or when the decoration is created/destroyed
updateInputShape();
2011-01-30 14:34:42 +00:00
if (compositing()) {
addRepaintFull();
2011-01-30 14:34:42 +00:00
addWorkspaceRepaint(visibleRect()); // In case shape change removes part of this window
}
emit geometryShapeChanged(this, geometry());
2011-01-30 14:34:42 +00:00
}
static Xcb::Window shape_helper_window(XCB_WINDOW_NONE);
void Client::updateInputShape()
2011-01-30 14:34:42 +00:00
{
if (hiddenPreview()) // Sets it to none, don't change
return;
if (Xcb::Extensions::self()->isShapeInputAvailable()) {
2011-01-30 14:34:42 +00:00
// There appears to be no way to find out if a window has input
// shape set or not, so always propagate the input shape
// (it's the same like the bounding shape by default).
// Also, build the shape using a helper window, not directly
// in the frame window, because the sequence set-shape-to-frame,
// remove-shape-of-client, add-input-shape-of-client has the problem
// that after the second step there's a hole in the input shape
// until the real shape of the client is added and that can make
// the window lose focus (which is a problem with mouse focus policies)
// TODO: It seems there is, after all - XShapeGetRectangles() - but maybe this is better
if (!shape_helper_window.isValid())
shape_helper_window.create(QRect(0, 0, 1, 1));
shape_helper_window.resize(width(), height());
xcb_connection_t *c = connection();
xcb_shape_combine(c, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_SHAPE_SK_BOUNDING,
shape_helper_window, 0, 0, frameId());
xcb_shape_combine(c, XCB_SHAPE_SO_SUBTRACT, XCB_SHAPE_SK_INPUT, XCB_SHAPE_SK_BOUNDING,
shape_helper_window, clientPos().x(), clientPos().y(), window());
xcb_shape_combine(c, XCB_SHAPE_SO_UNION, XCB_SHAPE_SK_INPUT, XCB_SHAPE_SK_INPUT,
shape_helper_window, clientPos().x(), clientPos().y(), window());
xcb_shape_combine(c, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_SHAPE_SK_INPUT,
frameId(), 0, 0, shape_helper_window);
}
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::hideClient(bool hide)
{
if (hidden == hide)
return;
hidden = hide;
updateVisibility();
2011-01-30 14:34:42 +00:00
}
/**
* Returns whether the window is minimizable or not
*/
bool Client::isMinimizable() const
2011-01-30 14:34:42 +00:00
{
if (isSpecialWindow() && !isTransient())
return false;
if (!rules()->checkMinimize(true))
return false;
2011-01-30 14:34:42 +00:00
if (isTransient()) {
// #66868 - Let other xmms windows be minimized when the mainwindow is minimized
bool shown_mainwindow = false;
ClientList mainclients = mainClients();
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = mainclients.constBegin();
it != mainclients.constEnd();
++it)
if ((*it)->isShown(true))
shown_mainwindow = true;
2011-01-30 14:34:42 +00:00
if (!shown_mainwindow)
return true;
2011-01-30 14:34:42 +00:00
}
#if 0
// This is here because kicker's taskbar doesn't provide separate entries
// for windows with an explicitly given parent
// TODO: perhaps this should be redone
// Disabled for now, since at least modal dialogs should be minimizable
// (resulting in the mainwindow being minimized too).
2011-01-30 14:34:42 +00:00
if (transientFor() != NULL)
return false;
#endif
2011-01-30 14:34:42 +00:00
if (!wantsTabFocus()) // SELI, TODO: - NET::Utility? why wantsTabFocus() - skiptaskbar? ?
return false;
return true;
2011-01-30 14:34:42 +00:00
}
void Client::doMinimize()
{
updateVisibility();
updateAllowedActions();
2011-01-30 14:34:42 +00:00
workspace()->updateMinimizedOfTransients(this);
// Update states of all other windows in this group
if (tabGroup())
tabGroup()->updateStates(this, TabGroup::Minimized);
2011-01-30 14:34:42 +00:00
}
QRect Client::iconGeometry() const
2011-01-30 14:34:42 +00:00
{
NETRect r = info->iconGeometry();
2011-01-30 14:34:42 +00:00
QRect geom(r.pos.x, r.pos.y, r.size.width, r.size.height);
if (geom.isValid())
return geom;
2011-01-30 14:34:42 +00:00
else {
// Check all mainwindows of this window (recursively)
foreach (Client * mainwin, mainClients()) {
geom = mainwin->iconGeometry();
2011-01-30 14:34:42 +00:00
if (geom.isValid())
return geom;
2011-01-30 14:34:42 +00:00
}
// No mainwindow (or their parents) with icon geometry was found
return QRect();
}
2011-01-30 14:34:42 +00:00
}
bool Client::isShadeable() const
2011-01-30 14:34:42 +00:00
{
return !isSpecialWindow() && !noBorder() && (rules()->checkShade(ShadeNormal) != rules()->checkShade(ShadeNone));
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::setShade(ShadeMode mode)
{
if (mode == ShadeHover && isMove())
return; // causes geometry breaks and is probably nasty
if (isSpecialWindow() || noBorder())
mode = ShadeNone;
2011-01-30 14:34:42 +00:00
mode = rules()->checkShade(mode);
if (shade_mode == mode)
return;
bool was_shade = isShade();
ShadeMode was_shade_mode = shade_mode;
shade_mode = mode;
// Decorations may turn off some borders when shaded
// this has to happen _before_ the tab alignment since it will restrict the minimum geometry
#if 0
if (decoration)
decoration->borders(border_left, border_right, border_top, border_bottom);
#endif
// Update states of all other windows in this group
if (tabGroup())
tabGroup()->updateStates(this, TabGroup::Shaded);
2011-01-30 14:34:42 +00:00
if (was_shade == isShade()) {
// Decoration may want to update after e.g. hover-shade changes
emit shadeChanged();
return; // No real change in shaded state
2011-01-30 14:34:42 +00:00
}
assert(m_decoration != NULL); // noborder windows can't be shaded
2011-01-30 14:34:42 +00:00
GeometryUpdatesBlocker blocker(this);
// TODO: All this unmapping, resizing etc. feels too much duplicated from elsewhere
2011-01-30 14:34:42 +00:00
if (isShade()) {
// shade_mode == ShadeNormal
addWorkspaceRepaint(visibleRect());
// Shade
shade_geometry_change = true;
2011-01-30 14:34:42 +00:00
QSize s(sizeForClientSize(QSize(clientSize())));
s.setHeight(borderTop() + borderBottom());
m_wrapper.selectInput(ClientWinMask); // Avoid getting UnmapNotify
m_wrapper.unmap();
m_client.unmap();
m_wrapper.selectInput(ClientWinMask | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY);
exportMappingState(IconicState);
2011-01-30 14:34:42 +00:00
plainResize(s);
shade_geometry_change = false;
if (was_shade_mode == ShadeHover) {
if (shade_below && workspace()->stackingOrder().indexOf(shade_below) > -1)
workspace()->restack(this, shade_below, true);
if (isActive())
2011-01-30 14:34:42 +00:00
workspace()->activateNextClient(this);
} else if (isActive()) {
workspace()->focusToNull();
}
2011-01-30 14:34:42 +00:00
} else {
shade_geometry_change = true;
2011-01-30 14:34:42 +00:00
QSize s(sizeForClientSize(clientSize()));
shade_geometry_change = false;
2011-01-30 14:34:42 +00:00
plainResize(s);
geom_restore = geometry();
if ((shade_mode == ShadeHover || shade_mode == ShadeActivated) && rules()->checkAcceptFocus(info->input()))
2011-01-30 14:34:42 +00:00
setActive(true);
if (shade_mode == ShadeHover) {
ToplevelList order = workspace()->stackingOrder();
// invalidate, since "this" could be the topmost toplevel and shade_below dangeling
shade_below = NULL;
// this is likely related to the index parameter?!
for (int idx = order.indexOf(this) + 1; idx < order.count(); ++idx) {
shade_below = qobject_cast<Client*>(order.at(idx));
if (shade_below) {
break;
}
}
if (shade_below && shade_below->isNormalWindow())
workspace()->raiseClient(this);
else
shade_below = NULL;
}
m_wrapper.map();
m_client.map();
exportMappingState(NormalState);
2011-01-30 14:34:42 +00:00
if (isActive())
workspace()->requestFocus(this);
}
info->setState(isShade() ? NET::Shaded : NET::States(0), NET::Shaded);
info->setState(isShown(false) ? NET::States(0) : NET::Hidden, NET::Hidden);
discardWindowPixmap();
updateVisibility();
updateAllowedActions();
updateWindowRules(Rules::Shade);
emit shadeChanged();
2011-01-30 14:34:42 +00:00
}
void Client::shadeHover()
2011-01-30 14:34:42 +00:00
{
setShade(ShadeHover);
cancelShadeHoverTimer();
2011-01-30 14:34:42 +00:00
}
void Client::shadeUnhover()
2011-01-30 14:34:42 +00:00
{
if (!tabGroup() || tabGroup()->current() == this ||
tabGroup()->current()->shadeMode() == ShadeNormal)
setShade(ShadeNormal);
cancelShadeHoverTimer();
2011-01-30 14:34:42 +00:00
}
void Client::cancelShadeHoverTimer()
2011-01-30 14:34:42 +00:00
{
delete shadeHoverTimer;
shadeHoverTimer = 0;
2011-01-30 14:34:42 +00:00
}
void Client::toggleShade()
2011-01-30 14:34:42 +00:00
{
// If the mode is ShadeHover or ShadeActive, cancel shade too
setShade(shade_mode == ShadeNone ? ShadeNormal : ShadeNone);
}
void Client::updateVisibility()
2011-01-30 14:34:42 +00:00
{
if (deleting)
return;
if (hidden && isCurrentTab()) {
2011-01-30 14:34:42 +00:00
info->setState(NET::Hidden, NET::Hidden);
setSkipTaskbar(true); // Also hide from taskbar
if (compositing() && options->hiddenPreviews() == HiddenPreviewsAlways)
internalKeep();
else
internalHide();
return;
2011-01-30 14:34:42 +00:00
}
if (isCurrentTab())
setSkipTaskbar(originalSkipTaskbar()); // Reset from 'hidden'
if (isMinimized()) {
2011-01-30 14:34:42 +00:00
info->setState(NET::Hidden, NET::Hidden);
if (compositing() && options->hiddenPreviews() == HiddenPreviewsAlways)
internalKeep();
else
internalHide();
return;
2011-01-30 14:34:42 +00:00
}
info->setState(0, NET::Hidden);
if (!isOnCurrentDesktop()) {
if (compositing() && options->hiddenPreviews() != HiddenPreviewsNever)
internalKeep();
else
internalHide();
return;
2011-01-30 14:34:42 +00:00
}
if (!isOnCurrentActivity()) {
if (compositing() && options->hiddenPreviews() != HiddenPreviewsNever)
internalKeep();
else
internalHide();
return;
2011-01-30 14:34:42 +00:00
}
internalShow();
2011-01-30 14:34:42 +00:00
}
/**
* Sets the client window's mapping state. Possible values are
* WithdrawnState, IconicState, NormalState.
*/
2011-01-30 14:34:42 +00:00
void Client::exportMappingState(int s)
{
assert(m_client != XCB_WINDOW_NONE);
2011-01-30 14:34:42 +00:00
assert(!deleting || s == WithdrawnState);
if (s == WithdrawnState) {
m_client.deleteProperty(atoms->wm_state);
return;
2011-01-30 14:34:42 +00:00
}
assert(s == NormalState || s == IconicState);
int32_t data[2];
data[0] = s;
data[1] = XCB_NONE;
m_client.changeProperty(atoms->wm_state, atoms->wm_state, 32, 2, data);
2011-01-30 14:34:42 +00:00
}
void Client::internalShow()
2011-01-30 14:34:42 +00:00
{
if (mapping_state == Mapped)
return;
MappingState old = mapping_state;
mapping_state = Mapped;
2011-01-30 14:34:42 +00:00
if (old == Unmapped || old == Withdrawn)
map();
if (old == Kept) {
m_decoInputExtent.map();
updateHiddenPreview();
}
if (Compositor::isCreated()) {
Compositor::self()->checkUnredirect();
}
2011-01-30 14:34:42 +00:00
}
void Client::internalHide()
2011-01-30 14:34:42 +00:00
{
if (mapping_state == Unmapped)
return;
MappingState old = mapping_state;
mapping_state = Unmapped;
2011-01-30 14:34:42 +00:00
if (old == Mapped || old == Kept)
unmap();
2011-01-30 14:34:42 +00:00
if (old == Kept)
updateHiddenPreview();
2011-01-30 14:34:42 +00:00
addWorkspaceRepaint(visibleRect());
workspace()->clientHidden(this);
if (Compositor::isCreated()) {
Compositor::self()->checkUnredirect();
}
2011-01-30 14:34:42 +00:00
}
void Client::internalKeep()
2011-01-30 14:34:42 +00:00
{
assert(compositing());
if (mapping_state == Kept)
return;
MappingState old = mapping_state;
mapping_state = Kept;
2011-01-30 14:34:42 +00:00
if (old == Unmapped || old == Withdrawn)
map();
m_decoInputExtent.unmap();
if (isActive())
workspace()->focusToNull(); // get rid of input focus, bug #317484
updateHiddenPreview();
2011-01-30 14:34:42 +00:00
addWorkspaceRepaint(visibleRect());
workspace()->clientHidden(this);
if (Compositor::isCreated()) {
Compositor::self()->checkUnredirect();
}
2011-01-30 14:34:42 +00:00
}
/**
* Maps (shows) the client. Note that it is mapping state of the frame,
* not necessarily the client window itself (i.e. a shaded window is here
* considered mapped, even though it is in IconicState).
*/
void Client::map()
2011-01-30 14:34:42 +00:00
{
// XComposite invalidates backing pixmaps on unmap (minimize, different
// virtual desktop, etc.). We kept the last known good pixmap around
// for use in effects, but now we want to have access to the new pixmap
2011-01-30 14:34:42 +00:00
if (compositing())
discardWindowPixmap();
m_frame.map();
2011-01-30 14:34:42 +00:00
if (!isShade()) {
m_wrapper.map();
m_client.map();
m_decoInputExtent.map();
2011-01-30 14:34:42 +00:00
exportMappingState(NormalState);
} else
exportMappingState(IconicState);
addLayerRepaint(visibleRect());
2011-01-30 14:34:42 +00:00
}
/**
* Unmaps the client. Again, this is about the frame.
*/
void Client::unmap()
2011-01-30 14:34:42 +00:00
{
// Here it may look like a race condition, as some other client might try to unmap
// the window between these two XSelectInput() calls. However, they're supposed to
// use XWithdrawWindow(), which also sends a synthetic event to the root window,
// which won't be missed, so this shouldn't be a problem. The chance the real UnmapNotify
// will be missed is also very minimal, so I don't think it's needed to grab the server
// here.
m_wrapper.selectInput(ClientWinMask); // Avoid getting UnmapNotify
m_frame.unmap();
m_wrapper.unmap();
m_client.unmap();
m_decoInputExtent.unmap();
m_wrapper.selectInput(ClientWinMask | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY);
2011-01-30 14:34:42 +00:00
exportMappingState(IconicState);
}
/**
* XComposite doesn't keep window pixmaps of unmapped windows, which means
* there wouldn't be any previews of windows that are minimized or on another
* virtual desktop. Therefore rawHide() actually keeps such windows mapped.
* However special care needs to be taken so that such windows don't interfere.
* Therefore they're put very low in the stacking order and they have input shape
* set to none, which hopefully is enough. If there's no input shape available,
* then it's hoped that there will be some other desktop above it *shrug*.
* Using normal shape would be better, but that'd affect other things, e.g. painting
* of the actual preview.
*/
void Client::updateHiddenPreview()
2011-01-30 14:34:42 +00:00
{
if (hiddenPreview()) {
workspace()->forceRestacking();
if (Xcb::Extensions::self()->isShapeInputAvailable()) {
xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT,
XCB_CLIP_ORDERING_UNSORTED, frameId(), 0, 0, 0, NULL);
}
2011-01-30 14:34:42 +00:00
} else {
workspace()->forceRestacking();
updateInputShape();
}
2011-01-30 14:34:42 +00:00
}
void Client::sendClientMessage(xcb_window_t w, xcb_atom_t a, xcb_atom_t protocol, uint32_t data1, uint32_t data2, uint32_t data3)
2011-01-30 14:34:42 +00:00
{
2013-05-03 08:55:37 +00:00
xcb_client_message_event_t ev;
2011-01-30 14:34:42 +00:00
memset(&ev, 0, sizeof(ev));
2013-05-03 08:55:37 +00:00
ev.response_type = XCB_CLIENT_MESSAGE;
ev.window = w;
ev.type = a;
ev.format = 32;
ev.data.data32[0] = protocol;
ev.data.data32[1] = xTime();
ev.data.data32[2] = data1;
ev.data.data32[3] = data2;
ev.data.data32[4] = data3;
uint32_t eventMask = 0;
if (w == rootWindow()) {
eventMask = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; // Magic!
}
xcb_send_event(connection(), false, w, eventMask, reinterpret_cast<const char*>(&ev));
xcb_flush(connection());
2011-01-30 14:34:42 +00:00
}
/**
* Returns whether the window may be closed (have a close button)
*/
bool Client::isCloseable() const
2011-01-30 14:34:42 +00:00
{
return rules()->checkCloseable(m_motif.close() && !isSpecialWindow());
2011-01-30 14:34:42 +00:00
}
/**
* Closes the window by either sending a delete_window message or using XKill.
*/
void Client::closeWindow()
2011-01-30 14:34:42 +00:00
{
if (!isCloseable())
return;
// Update user time, because the window may create a confirming dialog.
updateUserTime();
if (info->supportsProtocol(NET::DeleteWindowProtocol)) {
2011-01-30 14:34:42 +00:00
sendClientMessage(window(), atoms->wm_protocols, atoms->wm_delete_window);
pingWindow();
2011-01-30 14:34:42 +00:00
} else // Client will not react on wm_delete_window. We have not choice
// but destroy his connection to the XServer.
killWindow();
2011-01-30 14:34:42 +00:00
}
/**
* Kills the window via XKill
*/
void Client::killWindow()
2011-01-30 14:34:42 +00:00
{
qCDebug(KWIN_CORE) << "Client::killWindow():" << caption();
2011-01-30 14:34:42 +00:00
killProcess(false);
2013-09-10 06:49:41 +00:00
m_client.kill(); // Always kill this client at the server
destroyClient();
2011-01-30 14:34:42 +00:00
}
/**
* Send a ping to the window using _NET_WM_PING if possible if it
* doesn't respond within a reasonable time, it will be killed.
*/
void Client::pingWindow()
2011-01-30 14:34:42 +00:00
{
if (!info->supportsProtocol(NET::PingProtocol))
return; // Can't ping :(
if (options->killPingTimeout() == 0)
return; // Turned off
2011-01-30 14:34:42 +00:00
if (ping_timer != NULL)
return; // Pinging already
2011-01-30 14:34:42 +00:00
ping_timer = new QTimer(this);
connect(ping_timer, &QTimer::timeout, this,
[this]() {
qCDebug(KWIN_CORE) << "Ping timeout:" << caption();
ping_timer->deleteLater();
ping_timer = nullptr;
killProcess(true, m_pingTimestamp);
}
);
2011-01-30 14:34:42 +00:00
ping_timer->setSingleShot(true);
ping_timer->start(options->killPingTimeout());
m_pingTimestamp = xTime();
workspace()->sendPingToWindow(window(), m_pingTimestamp);
2011-01-30 14:34:42 +00:00
}
void Client::gotPing(xcb_timestamp_t timestamp)
2011-01-30 14:34:42 +00:00
{
// Just plain compare is not good enough because of 64bit and truncating and whatnot
if (NET::timestampCompare(timestamp, m_pingTimestamp) != 0)
return;
delete ping_timer;
ping_timer = NULL;
if (m_killHelperPID && !::kill(m_killHelperPID, 0)) { // means the process is alive
::kill(m_killHelperPID, SIGTERM);
m_killHelperPID = 0;
}
2011-01-30 14:34:42 +00:00
}
void Client::killProcess(bool ask, xcb_timestamp_t timestamp)
2011-01-30 14:34:42 +00:00
{
if (m_killHelperPID && !::kill(m_killHelperPID, 0)) // means the process is alive
return;
Q_ASSERT(!ask || timestamp != XCB_TIME_CURRENT_TIME);
pid_t pid = info->pid();
Improved resolving whether a window is on local machine Most windows use the hostname in WM_CLIENT_MACHINE, but there are windows using the FQDN (for example libreoffice). So instead of "foo" it is "foo.local.net" or similar. The logic so far has been unable to properly determine whether windows with FQDN are on the local system. In order to solve this problem the handling is split out into an own class which stores the information of hostname and whether it is a local machine. This is to not query multiple times. To determine whether the Client is on the local system getaddrinfo is used for the own hostname and the FQDN provided in WM_CLIENT_MACHINE. If one of the queried names matches, we know that it is on the local machine. The old logic to compare the hostname is still used and getaddrinfo is only a fallback in case hostname does not match. The problem with getaddrinfo is, that it accesses the network and by that could block. To circumvent this problem the calls are moved into threads by using QtConcurrent::run. Obviously this brings disadvantages. When trying to resolve whether a Client is on the local machine and a FQDN is used, the information is initially wrong. The new ClientMachine class emits a signal when the information that the system is local becomes available, but for some things this is just too late: * window rules are already gathered * Session Management has already taken place In both cases this is an acceptable loss. For window rules it just needs a proper matching of the machine in case of localhost (remote hosts are not affected). And the case of session management is very academic as it is unlikely that a restoring session contains remote windows. BUG: 308391 FIXED-IN: 4.11 REVIEW: 108235
2013-01-07 07:07:27 +00:00
if (pid <= 0 || clientMachine()->hostName().isEmpty()) // Needed properties missing
return;
qCDebug(KWIN_CORE) << "Kill process:" << pid << "(" << clientMachine()->hostName() << ")";
2011-01-30 14:34:42 +00:00
if (!ask) {
Improved resolving whether a window is on local machine Most windows use the hostname in WM_CLIENT_MACHINE, but there are windows using the FQDN (for example libreoffice). So instead of "foo" it is "foo.local.net" or similar. The logic so far has been unable to properly determine whether windows with FQDN are on the local system. In order to solve this problem the handling is split out into an own class which stores the information of hostname and whether it is a local machine. This is to not query multiple times. To determine whether the Client is on the local system getaddrinfo is used for the own hostname and the FQDN provided in WM_CLIENT_MACHINE. If one of the queried names matches, we know that it is on the local machine. The old logic to compare the hostname is still used and getaddrinfo is only a fallback in case hostname does not match. The problem with getaddrinfo is, that it accesses the network and by that could block. To circumvent this problem the calls are moved into threads by using QtConcurrent::run. Obviously this brings disadvantages. When trying to resolve whether a Client is on the local machine and a FQDN is used, the information is initially wrong. The new ClientMachine class emits a signal when the information that the system is local becomes available, but for some things this is just too late: * window rules are already gathered * Session Management has already taken place In both cases this is an acceptable loss. For window rules it just needs a proper matching of the machine in case of localhost (remote hosts are not affected). And the case of session management is very academic as it is unlikely that a restoring session contains remote windows. BUG: 308391 FIXED-IN: 4.11 REVIEW: 108235
2013-01-07 07:07:27 +00:00
if (!clientMachine()->isLocal()) {
QStringList lst;
lst << QString::fromUtf8(clientMachine()->hostName()) << QStringLiteral("kill") << QString::number(pid);
QProcess::startDetached(QStringLiteral("xon"), lst);
2011-01-30 14:34:42 +00:00
} else
::kill(pid, SIGTERM);
} else {
QString hostname = clientMachine()->isLocal() ? QStringLiteral("localhost") : QString::fromUtf8(clientMachine()->hostName());
QProcess::startDetached(QStringLiteral(KWIN_KILLER_BIN),
QStringList() << QStringLiteral("--pid") << QString::number(unsigned(pid)) << QStringLiteral("--hostname") << hostname
<< QStringLiteral("--windowname") << caption()
<< QStringLiteral("--applicationname") << QString::fromUtf8(resourceClass())
<< QStringLiteral("--wid") << QString::number(window())
<< QStringLiteral("--timestamp") << QString::number(timestamp),
QString(), &m_killHelperPID);
}
2011-01-30 14:34:42 +00:00
}
void Client::doSetSkipTaskbar()
2011-01-30 14:34:42 +00:00
{
info->setState(skipTaskbar() ? NET::SkipTaskbar : NET::States(0), NET::SkipTaskbar);
2011-01-30 14:34:42 +00:00
}
void Client::doSetSkipPager()
2011-01-30 14:34:42 +00:00
{
info->setState(skipPager() ? NET::SkipPager : NET::States(0), NET::SkipPager);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::setModal(bool m)
{
// Qt-3.2 can have even modal normal windows :(
if (modal == m)
return;
modal = m;
2011-12-22 16:54:07 +00:00
emit modalChanged();
// Changing modality for a mapped window is weird (?)
// _NET_WM_STATE_MODAL should possibly rather be _NET_WM_WINDOW_TYPE_MODAL_DIALOG
2011-01-30 14:34:42 +00:00
}
void Client::doSetDesktop(int desktop, int was_desk)
2011-01-30 14:34:42 +00:00
{
info->setDesktop(desktop);
if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) {
// onAllDesktops changed
workspace()->updateOnAllDesktopsOfTransients(this);
}
2011-01-30 14:34:42 +00:00
ClientList transients_stacking_order = workspace()->ensureStackingOrder(transients());
for (ClientList::ConstIterator it = transients_stacking_order.constBegin();
it != transients_stacking_order.constEnd();
++it)
(*it)->setDesktop(desktop);
2011-01-30 14:34:42 +00:00
if (isModal()) // if a modal dialog is moved, move the mainwindow with it as otherwise
// the (just moved) modal dialog will confusingly return to the mainwindow with
// the next desktop change
{
foreach (Client * c2, mainClients())
c2->setDesktop(desktop);
}
updateVisibility();
// Update states of all other windows in this group
if (tabGroup())
tabGroup()->updateStates(this, TabGroup::Desktop);
2011-01-30 14:34:42 +00:00
}
/**
* Sets whether the client is on @p activity.
* If you remove it from its last activity, then it's on all activities.
*
* Note: If it was on all activities and you try to remove it from one, nothing will happen;
* I don't think that's an important enough use case to handle here.
*/
2011-01-30 14:34:42 +00:00
void Client::setOnActivity(const QString &activity, bool enable)
{
#ifdef KWIN_BUILD_ACTIVITIES
QStringList newActivitiesList = activities();
2011-01-30 14:34:42 +00:00
if (newActivitiesList.contains(activity) == enable) //nothing to do
return;
2011-01-30 14:34:42 +00:00
if (enable) {
QStringList allActivities = Activities::self()->all();
2011-01-30 14:34:42 +00:00
if (!allActivities.contains(activity)) //bogus ID
return;
newActivitiesList.append(activity);
2011-01-30 14:34:42 +00:00
} else
newActivitiesList.removeOne(activity);
2011-01-30 14:34:42 +00:00
setOnActivities(newActivitiesList);
#else
Q_UNUSED(activity)
Q_UNUSED(enable)
#endif
2011-01-30 14:34:42 +00:00
}
/**
* set exactly which activities this client is on
*/
2011-01-30 14:34:42 +00:00
void Client::setOnActivities(QStringList newActivitiesList)
{
#ifdef KWIN_BUILD_ACTIVITIES
QString joinedActivitiesList = newActivitiesList.join(QStringLiteral(","));
joinedActivitiesList = rules()->checkActivity(joinedActivitiesList, false);
newActivitiesList = joinedActivitiesList.split(QStringLiteral(","), QString::SkipEmptyParts);
QStringList allActivities = Activities::self()->all();
if (// If we got the request to be on all activities explicitly
newActivitiesList.isEmpty() || joinedActivitiesList == Activities::nullUuid() ||
// If we got a list of activities that covers all activities
(newActivitiesList.count() > 1 && newActivitiesList.count() == allActivities.count())) {
activityList.clear();
const QByteArray nullUuid = Activities::nullUuid().toUtf8();
m_client.changeProperty(atoms->activities, XCB_ATOM_STRING, 8, nullUuid.length(), nullUuid.constData());
} else {
QByteArray joined = joinedActivitiesList.toAscii();
activityList = newActivitiesList;
m_client.changeProperty(atoms->activities, XCB_ATOM_STRING, 8, joined.length(), joined.constData());
}
2011-01-30 14:34:42 +00:00
updateActivities(false);
#else
Q_UNUSED(newActivitiesList)
#endif
2011-01-30 14:34:42 +00:00
}
void Client::blockActivityUpdates(bool b)
{
if (b) {
++m_activityUpdatesBlocked;
} else {
Q_ASSERT(m_activityUpdatesBlocked);
--m_activityUpdatesBlocked;
if (!m_activityUpdatesBlocked)
updateActivities(m_blockedActivityUpdatesRequireTransients);
}
}
/**
* update after activities changed
*/
2011-01-30 14:34:42 +00:00
void Client::updateActivities(bool includeTransients)
{
if (m_activityUpdatesBlocked) {
m_blockedActivityUpdatesRequireTransients |= includeTransients;
return;
}
emit activitiesChanged(this);
m_blockedActivityUpdatesRequireTransients = false; // reset
FocusChain::self()->update(this, FocusChain::MakeFirst);
updateVisibility();
updateWindowRules(Rules::Activity);
// Update states of all other windows in this group
if (tabGroup())
tabGroup()->updateStates(this, TabGroup::Activity);
2011-01-30 14:34:42 +00:00
}
/**
* Returns the virtual desktop within the workspace() the client window
* is located in, 0 if it isn't located on any special desktop (not mapped yet),
* or NET::OnAllDesktops. Do not use desktop() directly, use
* isOnDesktop() instead.
*/
int Client::desktop() const
{
if (needsSessionInteract) {
return NET::OnAllDesktops;
}
return AbstractClient::desktop();
}
/**
* Returns the list of activities the client window is on.
* if it's on all activities, the list will be empty.
* Don't use this, use isOnActivity() and friends (from class Toplevel)
*/
QStringList Client::activities() const
2011-01-30 14:34:42 +00:00
{
if (needsSessionInteract) {
return QStringList();
}
return activityList;
2011-01-30 14:34:42 +00:00
}
/**
* if @p on is true, sets on all activities.
* if it's false, sets it to only be on the current activity
*/
2011-01-30 14:34:42 +00:00
void Client::setOnAllActivities(bool on)
{
#ifdef KWIN_BUILD_ACTIVITIES
2011-01-30 14:34:42 +00:00
if (on == isOnAllActivities())
return;
2011-01-30 14:34:42 +00:00
if (on) {
setOnActivities(QStringList());
2011-01-30 14:34:42 +00:00
} else {
setOnActivity(Activities::self()->current(), true);
}
#else
Q_UNUSED(on)
#endif
2011-01-30 14:34:42 +00:00
}
/**
* Performs the actual focusing of the window using XSetInputFocus and WM_TAKE_FOCUS
*/
void Client::takeFocus()
2011-01-30 14:34:42 +00:00
{
#ifndef NDEBUG
static Time previous_focus_timestamp;
static Client* previous_client;
2011-01-30 14:34:42 +00:00
//if ( previous_focus_timestamp == xTime() && previous_client != this )
// {
2013-11-01 11:29:05 +00:00
// qDebug() << "Repeated use of the same X timestamp for focus";
// qDebug() << kBacktrace();
// }
previous_focus_timestamp = xTime();
previous_client = this;
#endif
if (rules()->checkAcceptFocus(info->input()))
2013-09-10 08:59:16 +00:00
m_client.focus();
else
demandAttention(false); // window cannot take input, at least withdraw urgency
if (info->supportsProtocol(NET::TakeFocusProtocol)) {
updateXTime();
2011-01-30 14:34:42 +00:00
sendClientMessage(window(), atoms->wm_protocols, atoms->wm_take_focus);
}
2011-01-30 14:34:42 +00:00
workspace()->setShouldGetFocus(this);
bool breakShowingDesktop = !keepAbove();
if (breakShowingDesktop) {
foreach (const Client *c, group()->members()) {
if (c->isDesktop()) {
breakShowingDesktop = false;
break;
}
}
}
if (breakShowingDesktop)
workspace()->setShowingDesktop(false);
2011-01-30 14:34:42 +00:00
}
/**
* Returns whether the window provides context help or not. If it does,
* you should show a help menu item or a help button like '?' and call
* contextHelp() if this is invoked.
*
* \sa contextHelp()
*/
bool Client::providesContextHelp() const
2011-01-30 14:34:42 +00:00
{
return info->supportsProtocol(NET::ContextHelpProtocol);
2011-01-30 14:34:42 +00:00
}
/**
* Invokes context help on the window. Only works if the window
* actually provides context help.
*
* \sa providesContextHelp()
*/
void Client::showContextHelp()
2011-01-30 14:34:42 +00:00
{
if (info->supportsProtocol(NET::ContextHelpProtocol)) {
2011-01-30 14:34:42 +00:00
sendClientMessage(window(), atoms->wm_protocols, atoms->net_wm_context_help);
QWhatsThis::enterWhatsThisMode(); // SELI TODO: ?
}
2011-01-30 14:34:42 +00:00
}
/**
* Fetches the window's caption (WM_NAME property). It will be
* stored in the client's caption().
*/
void Client::fetchName()
2011-01-30 14:34:42 +00:00
{
setCaption(readName());
}
QString Client::readName() const
2011-01-30 14:34:42 +00:00
{
if (info->name() && info->name()[0] != '\0')
return QString::fromUtf8(info->name());
else
return KWindowSystem::readNameProperty(window(), XCB_ATOM_WM_NAME);
2011-01-30 14:34:42 +00:00
}
// The list is taken from http://www.unicode.org/reports/tr9/ (#154840)
static const QChar LRM(0x200E);
static const QChar RLM(0x200F);
static const QChar LRE(0x202A);
static const QChar RLE(0x202B);
static const QChar LRO(0x202D);
static const QChar RLO(0x202E);
static const QChar PDF(0x202C);
2011-01-30 14:34:42 +00:00
void Client::setCaption(const QString& _s, bool force)
{
if (!force && _s == cap_normal)
return;
QString s(_s);
for (int i = 0; i < s.length(); ++i)
if (!s[i].isPrint())
s[i] = QChar(u' ');
cap_normal = s;
if (options->condensedTitle()) {
static QScriptEngine engine;
static QScriptProgram stripTitle;
static QScriptValue script;
if (stripTitle.isNull()) {
const QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME) + QStringLiteral("/stripTitle.js"));
if (!scriptFile.isEmpty()) {
QFile f(scriptFile);
if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
f.reset();
stripTitle = QScriptProgram(QString::fromLocal8Bit(f.readAll()), QStringLiteral("stripTitle.js"));
f.close();
}
}
if (stripTitle.isNull())
stripTitle = QScriptProgram(QStringLiteral("(function(title, wm_name, wm_class){ return title ; })"), QStringLiteral("stripTitle.js"));
script = engine.evaluate(stripTitle);
}
QScriptValueList args;
args << _s << QString::fromUtf8(resourceName()) << QString::fromUtf8(resourceClass());
s = script.call(QScriptValue(), args).toString();
}
if (!force && s == cap_deco)
return;
cap_deco = s;
bool reset_name = force;
bool was_suffix = (!cap_suffix.isEmpty());
cap_suffix.clear();
QString machine_suffix;
if (!options->condensedTitle()) { // machine doesn't qualify for "clean"
Improved resolving whether a window is on local machine Most windows use the hostname in WM_CLIENT_MACHINE, but there are windows using the FQDN (for example libreoffice). So instead of "foo" it is "foo.local.net" or similar. The logic so far has been unable to properly determine whether windows with FQDN are on the local system. In order to solve this problem the handling is split out into an own class which stores the information of hostname and whether it is a local machine. This is to not query multiple times. To determine whether the Client is on the local system getaddrinfo is used for the own hostname and the FQDN provided in WM_CLIENT_MACHINE. If one of the queried names matches, we know that it is on the local machine. The old logic to compare the hostname is still used and getaddrinfo is only a fallback in case hostname does not match. The problem with getaddrinfo is, that it accesses the network and by that could block. To circumvent this problem the calls are moved into threads by using QtConcurrent::run. Obviously this brings disadvantages. When trying to resolve whether a Client is on the local machine and a FQDN is used, the information is initially wrong. The new ClientMachine class emits a signal when the information that the system is local becomes available, but for some things this is just too late: * window rules are already gathered * Session Management has already taken place In both cases this is an acceptable loss. For window rules it just needs a proper matching of the machine in case of localhost (remote hosts are not affected). And the case of session management is very academic as it is unlikely that a restoring session contains remote windows. BUG: 308391 FIXED-IN: 4.11 REVIEW: 108235
2013-01-07 07:07:27 +00:00
if (clientMachine()->hostName() != ClientMachine::localhost() && !clientMachine()->isLocal())
machine_suffix = QStringLiteral(" <@") + QString::fromUtf8(clientMachine()->hostName()) + QStringLiteral(">") + LRM;
}
QString shortcut_suffix = !shortcut().isEmpty() ? (QStringLiteral(" {") + shortcut().toString() + QStringLiteral("}")) : QString();
cap_suffix = machine_suffix + shortcut_suffix;
auto fetchNameInternalPredicate = [this](const Client *cl) {
return (!cl->isSpecialWindow() || cl->isToolbar()) &&
cl != this && cl->caption() == caption();
};
if ((!isSpecialWindow() || isToolbar()) && workspace()->findClient(fetchNameInternalPredicate)) {
int i = 2;
do {
cap_suffix = machine_suffix + QStringLiteral(" <") + QString::number(i) + QStringLiteral(">") + LRM;
i++;
} while (workspace()->findClient(fetchNameInternalPredicate));
info->setVisibleName(caption().toUtf8().constData());
reset_name = false;
}
if ((was_suffix && cap_suffix.isEmpty()) || reset_name) {
// If it was new window, it may have old value still set, if the window is reused
info->setVisibleName("");
info->setVisibleIconName("");
} else if (!cap_suffix.isEmpty() && !cap_iconic.isEmpty())
// Keep the same suffix in iconic name if it's set
info->setVisibleIconName(QString(cap_iconic + cap_suffix).toUtf8().constData());
emit captionChanged();
2011-01-30 14:34:42 +00:00
}
void Client::updateCaption()
2011-01-30 14:34:42 +00:00
{
setCaption(cap_normal, true);
}
void Client::fetchIconicName()
2011-01-30 14:34:42 +00:00
{
QString s;
2011-01-30 14:34:42 +00:00
if (info->iconName() && info->iconName()[0] != '\0')
s = QString::fromUtf8(info->iconName());
else
s = KWindowSystem::readNameProperty(window(), XCB_ATOM_WM_ICON_NAME);
2011-01-30 14:34:42 +00:00
if (s != cap_iconic) {
bool was_set = !cap_iconic.isEmpty();
cap_iconic = s;
2011-01-30 14:34:42 +00:00
if (!cap_suffix.isEmpty()) {
if (!cap_iconic.isEmpty()) // Keep the same suffix in iconic name if it's set
info->setVisibleIconName(QString(s + cap_suffix).toUtf8().constData());
2011-01-30 14:34:42 +00:00
else if (was_set)
info->setVisibleIconName("");
}
}
2011-01-30 14:34:42 +00:00
}
/**
* \reimp
*/
QString Client::caption(bool full, bool stripped) const
2011-01-30 14:34:42 +00:00
{
QString cap = stripped ? cap_deco : cap_normal;
if (full)
cap += cap_suffix;
return cap;
2011-01-30 14:34:42 +00:00
}
bool Client::tabTo(Client *other, bool behind, bool activate)
{
Q_ASSERT(other && other != this);
if (tab_group && tab_group == other->tabGroup()) { // special case: move inside group
tab_group->move(this, other, behind);
return true;
}
GeometryUpdatesBlocker blocker(this);
const bool wasBlocking = signalsBlocked();
blockSignals(true); // prevent client emitting "retabbed to nowhere" cause it's about to be entabbed the next moment
untab();
blockSignals(wasBlocking);
TabGroup *newGroup = other->tabGroup() ? other->tabGroup() : new TabGroup(other);
if (!newGroup->add(this, other, behind, activate)) {
if (newGroup->count() < 2) { // adding "c" to "to" failed for whatever reason
newGroup->remove(other);
delete newGroup;
}
return false;
}
return true;
}
bool Client::untab(const QRect &toGeometry, bool clientRemoved)
2012-01-15 10:26:38 +00:00
{
TabGroup *group = tab_group;
if (group && group->remove(this)) { // remove sets the tabgroup to "0", therefore the pointer is cached
if (group->isEmpty()) {
delete group;
}
if (clientRemoved)
return true; // there's been a broadcast signal that this client is now removed - don't touch it
setClientShown(!(isMinimized() || isShade()));
bool keepSize = toGeometry.size() == size();
bool changedSize = false;
if (quickTileMode() != QuickTileNone) {
changedSize = true;
setQuickTileMode(QuickTileNone); // if we leave a quicktiled group, assume that the user wants to untile
}
if (toGeometry.isValid()) {
if (maximizeMode() != MaximizeRestore) {
changedSize = true;
maximize(MaximizeRestore); // explicitly calling for a geometry -> unmaximize
}
if (keepSize && changedSize) {
geom_restore = geometry(); // checkWorkspacePosition() invokes it
QPoint cpoint = Cursor::pos();
QPoint point = cpoint;
point.setX((point.x() - toGeometry.x()) * geom_restore.width() / toGeometry.width());
point.setY((point.y() - toGeometry.y()) * geom_restore.height() / toGeometry.height());
geom_restore.moveTo(cpoint-point);
} else {
geom_restore = toGeometry; // checkWorkspacePosition() invokes it
}
setGeometry(geom_restore);
checkWorkspacePosition();
}
2012-01-15 10:26:38 +00:00
return true;
}
return false;
}
void Client::setTabGroup(TabGroup *group)
{
tab_group = group;
if (group) {
unsigned long data[] = {qHash(group)}; //->id();
m_client.changeProperty(atoms->kde_net_wm_tab_group, XCB_ATOM_CARDINAL, 32, 1, data);
}
else
m_client.deleteProperty(atoms->kde_net_wm_tab_group);
emit tabGroupChanged();
}
bool Client::isCurrentTab() const
{
return !tab_group || tab_group->current() == this;
2012-01-15 10:26:38 +00:00
}
void Client::syncTabGroupFor(QString property, bool fromThisClient)
{
if (tab_group)
tab_group->sync(property.toAscii().data(), fromThisClient ? this : tab_group->current());
}
void Client::dontMoveResize()
2011-01-30 14:34:42 +00:00
{
buttonDown = false;
stopDelayedMoveResize();
2011-01-30 14:34:42 +00:00
if (moveResizeMode)
finishMoveResize(false);
}
2011-01-30 14:34:42 +00:00
void Client::setClientShown(bool shown)
{
if (deleting)
return; // Don't change shown status if this client is being deleted
if (shown != hidden)
return; // nothing to change
hidden = !shown;
if (options->isInactiveTabsSkipTaskbar())
setSkipTaskbar(hidden); // TODO: Causes reshuffle of the taskbar
if (shown) {
map();
takeFocus();
autoRaise();
FocusChain::self()->update(this, FocusChain::MakeFirst);
} else {
unmap();
// Don't move tabs to the end of the list when another tab get's activated
if (isCurrentTab())
FocusChain::self()->update(this, FocusChain::MakeLast);
2011-01-30 14:34:42 +00:00
addWorkspaceRepaint(visibleRect());
}
2011-01-30 14:34:42 +00:00
}
void Client::getMotifHints()
2011-01-30 14:34:42 +00:00
{
const bool wasClosable = m_motif.close();
const bool wasNoBorder = m_motif.noBorder();
m_motif.read();
if (m_motif.hasDecoration() && m_motif.noBorder() != wasNoBorder) {
// If we just got a hint telling us to hide decorations, we do so.
if (m_motif.noBorder())
noborder = rules()->checkNoBorder(true);
// If the Motif hint is now telling us to show decorations, we only do so if the app didn't
// instruct us to hide decorations in some other way, though.
else if (!app_noborder)
noborder = rules()->checkNoBorder(false);
2011-01-30 14:34:42 +00:00
}
// mminimize; - Ignore, bogus - E.g. shading or sending to another desktop is "minimizing" too
// mmaximize; - Ignore, bogus - Maximizing is basically just resizing
const bool closabilityChanged = wasClosable != m_motif.close();
2011-01-30 14:34:42 +00:00
if (isManaged())
updateDecoration(true); // Check if noborder state has changed
if (closabilityChanged) {
emit closeableChanged(isCloseable());
}
2011-01-30 14:34:42 +00:00
}
void Client::getIcons()
2011-01-30 14:34:42 +00:00
{
// First read icons from the window itself
QIcon icon;
auto readIcon = [this, &icon](int size, bool scale = true) {
const QPixmap pix = KWindowSystem::icon(window(), size, size, scale, KWindowSystem::NETWM | KWindowSystem::WMHints, info);
if (!pix.isNull()) {
icon.addPixmap(pix);
}
};
readIcon(16);
readIcon(32);
readIcon(48, false);
readIcon(64, false);
readIcon(128, false);
if (icon.isNull()) {
2011-01-30 14:34:42 +00:00
// Then try window group
icon = group()->icon();
2011-01-30 14:34:42 +00:00
}
if (icon.isNull() && isTransient()) {
2011-01-30 14:34:42 +00:00
// Then mainclients
ClientList mainclients = mainClients();
2011-01-30 14:34:42 +00:00
for (ClientList::ConstIterator it = mainclients.constBegin();
it != mainclients.constEnd() && icon.isNull();
2011-01-30 14:34:42 +00:00
++it) {
if (!(*it)->icon().isNull()) {
icon = (*it)->icon();
break;
}
}
}
if (icon.isNull()) {
2011-01-30 14:34:42 +00:00
// And if nothing else, load icon from classhint or xapp icon
icon.addPixmap(KWindowSystem::icon(window(), 32, 32, true, KWindowSystem::ClassHint | KWindowSystem::XApp, info));
icon.addPixmap(KWindowSystem::icon(window(), 16, 16, true, KWindowSystem::ClassHint | KWindowSystem::XApp, info));
icon.addPixmap(KWindowSystem::icon(window(), 64, 64, false, KWindowSystem::ClassHint | KWindowSystem::XApp, info));
icon.addPixmap(KWindowSystem::icon(window(), 128, 128, false, KWindowSystem::ClassHint | KWindowSystem::XApp, info));
2011-01-30 14:34:42 +00:00
}
setIcon(icon);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::getSyncCounter()
{
if (!Xcb::Extensions::self()->isSyncAvailable())
return;
Xcb::Property syncProp(false, window(), atoms->net_wm_sync_request_counter, XCB_ATOM_CARDINAL, 0, 1);
const xcb_sync_counter_t counter = syncProp.value<xcb_sync_counter_t>(XCB_NONE);
if (counter != XCB_NONE) {
syncRequest.counter = counter;
2013-07-31 08:11:39 +00:00
syncRequest.value.hi = 0;
syncRequest.value.lo = 0;
auto *c = connection();
xcb_sync_set_counter(c, syncRequest.counter, syncRequest.value);
2013-07-31 08:11:39 +00:00
if (syncRequest.alarm == XCB_NONE) {
const uint32_t mask = XCB_SYNC_CA_COUNTER | XCB_SYNC_CA_VALUE_TYPE | XCB_SYNC_CA_TEST_TYPE | XCB_SYNC_CA_EVENTS;
2013-07-31 08:11:39 +00:00
const uint32_t values[] = {
syncRequest.counter,
XCB_SYNC_VALUETYPE_RELATIVE,
XCB_SYNC_TESTTYPE_POSITIVE_TRANSITION,
1
};
syncRequest.alarm = xcb_generate_id(c);
auto cookie = xcb_sync_create_alarm_checked(c, syncRequest.alarm, mask, values);
ScopedCPointer<xcb_generic_error_t> error(xcb_request_check(c, cookie));
if (!error.isNull()) {
syncRequest.alarm = XCB_NONE;
} else {
xcb_sync_change_alarm_value_list_t value;
memset(&value, 0, sizeof(value));
value.value.hi = 0;
value.value.lo = 1;
value.delta.hi = 0;
value.delta.lo = 1;
xcb_sync_change_alarm_aux(c, syncRequest.alarm, XCB_SYNC_CA_DELTA | XCB_SYNC_CA_VALUE, &value);
}
}
2011-01-30 14:34:42 +00:00
}
}
/**
* Send the client a _NET_SYNC_REQUEST
*/
void Client::sendSyncRequest()
{
2013-07-31 08:11:39 +00:00
if (syncRequest.counter == XCB_NONE || syncRequest.isPending)
return; // do NOT, NEVER send a sync request when there's one on the stack. the clients will just stop respoding. FOREVER! ...
if (!syncRequest.failsafeTimeout) {
syncRequest.failsafeTimeout = new QTimer(this);
connect(syncRequest.failsafeTimeout, &QTimer::timeout, this,
[this]() {
// client does not respond to XSYNC requests in reasonable time, remove support
if (!ready_for_painting) {
// failed on initial pre-show request
setReadyForPainting();
return;
}
// failed during resize
syncRequest.isPending = false;
syncRequest.counter = syncRequest.alarm = XCB_NONE;
delete syncRequest.timeout; delete syncRequest.failsafeTimeout;
syncRequest.timeout = syncRequest.failsafeTimeout = nullptr;
syncRequest.lastTimestamp = XCB_CURRENT_TIME;
}
);
syncRequest.failsafeTimeout->setSingleShot(true);
}
// if there's no response within 10 seconds, sth. went wrong and we remove XSYNC support from this client.
// see events.cpp Client::syncEvent()
syncRequest.failsafeTimeout->start(ready_for_painting ? 10000 : 1000);
// We increment before the notify so that after the notify
// syncCounterSerial will equal the value we are expecting
// in the acknowledgement
2013-07-31 08:11:39 +00:00
const uint32_t oldLo = syncRequest.value.lo;
syncRequest.value.lo++;;
if (oldLo > syncRequest.value.lo) {
syncRequest.value.hi++;
}
if (syncRequest.lastTimestamp >= xTime()) {
updateXTime();
}
// Send the message to client
sendClientMessage(window(), atoms->wm_protocols, atoms->net_wm_sync_request, syncRequest.value.lo, syncRequest.value.hi);
syncRequest.isPending = true;
syncRequest.lastTimestamp = xTime();
}
bool Client::wantsInput() const
2011-01-30 14:34:42 +00:00
{
return rules()->checkAcceptFocus(info->input() || info->supportsProtocol(NET::TakeFocusProtocol));
2011-01-30 14:34:42 +00:00
}
/**
* Sets an appropriate cursor shape for the logical mouse position \a m
*/
void Client::updateCursor()
2011-01-30 14:34:42 +00:00
{
Position m = mode;
2011-01-30 14:34:42 +00:00
if (!isResizable() || isShade())
m = PositionCenter;
Qt::CursorShape c = Qt::ArrowCursor;
2011-01-30 14:34:42 +00:00
switch(m) {
case PositionTopLeft:
case PositionBottomRight:
c = Qt::SizeFDiagCursor;
break;
case PositionBottomLeft:
case PositionTopRight:
c = Qt::SizeBDiagCursor;
break;
case PositionTop:
case PositionBottom:
c = Qt::SizeVerCursor;
break;
case PositionLeft:
case PositionRight:
c = Qt::SizeHorCursor;
break;
default:
if (moveResizeMode)
c = Qt::SizeAllCursor;
else
c = Qt::ArrowCursor;
break;
}
if (c == m_cursor)
return;
m_cursor = c;
xcb_cursor_t nativeCursor = Cursor::x11Cursor(m_cursor);
m_frame.defineCursor(nativeCursor);
if (m_decoInputExtent.isValid())
m_decoInputExtent.defineCursor(nativeCursor);
if (moveResizeMode) {
// changing window attributes doesn't change cursor if there's pointer grab active
xcb_change_active_pointer_grab(connection(), nativeCursor, xTime(),
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW);
}
2011-01-30 14:34:42 +00:00
}
void Client::setBlockingCompositing(bool block)
{
const bool usedToBlock = blocks_compositing;
blocks_compositing = rules()->checkBlockCompositing(block);
if (usedToBlock != blocks_compositing) {
emit blockingCompositingChanged(blocks_compositing ? this : 0);
}
}
Client::Position Client::mousePosition() const
2011-01-30 14:34:42 +00:00
{
if (m_decoration) {
switch (m_decoration->sectionUnderMouse()) {
case Qt::BottomLeftSection:
return PositionBottomLeft;
case Qt::BottomRightSection:
return PositionBottomRight;
case Qt::BottomSection:
return PositionBottom;
case Qt::LeftSection:
return PositionLeft;
case Qt::RightSection:
return PositionRight;
case Qt::TopSection:
return PositionTop;
case Qt::TopLeftSection:
return PositionTopLeft;
case Qt::TopRightSection:
return PositionTopRight;
default:
return PositionCenter;
}
}
return PositionCenter;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::updateAllowedActions(bool force)
{
if (!isManaged() && !force)
return;
NET::Actions old_allowed_actions = NET::Actions(allowed_actions);
allowed_actions = 0;
2011-01-30 14:34:42 +00:00
if (isMovable())
allowed_actions |= NET::ActionMove;
2011-01-30 14:34:42 +00:00
if (isResizable())
allowed_actions |= NET::ActionResize;
2011-01-30 14:34:42 +00:00
if (isMinimizable())
allowed_actions |= NET::ActionMinimize;
2011-01-30 14:34:42 +00:00
if (isShadeable())
allowed_actions |= NET::ActionShade;
// Sticky state not supported
2011-01-30 14:34:42 +00:00
if (isMaximizable())
allowed_actions |= NET::ActionMax;
2011-01-30 14:34:42 +00:00
if (userCanSetFullScreen())
allowed_actions |= NET::ActionFullScreen;
allowed_actions |= NET::ActionChangeDesktop; // Always (Pagers shouldn't show Docks etc.)
2011-01-30 14:34:42 +00:00
if (isCloseable())
allowed_actions |= NET::ActionClose;
2011-01-30 14:34:42 +00:00
if (old_allowed_actions == allowed_actions)
return;
// TODO: This could be delayed and compressed - It's only for pagers etc. anyway
2011-01-30 14:34:42 +00:00
info->setAllowedActions(allowed_actions);
// ONLY if relevant features have changed (and the window didn't just get/loose moveresize for maximization state changes)
const NET::Actions relevant = ~(NET::ActionMove|NET::ActionResize);
if ((allowed_actions & relevant) != (old_allowed_actions & relevant)) {
if ((allowed_actions & NET::ActionMinimize) != (old_allowed_actions & NET::ActionMinimize)) {
emit minimizeableChanged(allowed_actions & NET::ActionMinimize);
}
if ((allowed_actions & NET::ActionShade) != (old_allowed_actions & NET::ActionShade)) {
emit shadeableChanged(allowed_actions & NET::ActionShade);
}
if ((allowed_actions & NET::ActionMax) != (old_allowed_actions & NET::ActionMax)) {
emit maximizeableChanged(allowed_actions & NET::ActionMax);
}
}
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::debug(QDebug& stream) const
{
print<QDebug>(stream);
2011-01-30 14:34:42 +00:00
}
Xcb::StringProperty Client::fetchActivities() const
{
#ifdef KWIN_BUILD_ACTIVITIES
return Xcb::StringProperty(window(), atoms->activities);
#else
return Xcb::StringProperty();
#endif
}
void Client::readActivities(Xcb::StringProperty &property)
2011-01-30 14:34:42 +00:00
{
#ifdef KWIN_BUILD_ACTIVITIES
QStringList newActivitiesList;
QString prop = QString::fromUtf8(property);
activitiesDefined = !prop.isEmpty();
if (prop == Activities::nullUuid()) {
//copied from setOnAllActivities to avoid a redundant XChangeProperty.
if (!activityList.isEmpty()) {
activityList.clear();
2011-01-30 14:34:42 +00:00
updateActivities(true);
}
return;
}
if (prop.isEmpty()) {
//note: this makes it *act* like it's on all activities but doesn't set the property to 'ALL'
if (!activityList.isEmpty()) {
activityList.clear();
2011-01-30 14:34:42 +00:00
updateActivities(true);
}
return;
}
newActivitiesList = prop.split(QStringLiteral(","));
if (newActivitiesList == activityList)
return; //expected change, it's ok.
//otherwise, somebody else changed it. we need to validate before reacting.
//if the activities are not synced, and there are existing clients with
//activities specified, somebody has restarted kwin. we can not validate
//activities in this case. we need to trust the old values.
if (Activities::self()->serviceStatus() != KActivities::Consumer::Unknown) {
QStringList allActivities = Activities::self()->all();
if (allActivities.isEmpty()) {
qCDebug(KWIN_CORE) << "no activities!?!?";
//don't touch anything, there's probably something bad going on and we don't wanna make it worse
return;
}
for (int i = 0; i < newActivitiesList.size(); ++i) {
if (! allActivities.contains(newActivitiesList.at(i))) {
qCDebug(KWIN_CORE) << "invalid:" << newActivitiesList.at(i);
newActivitiesList.removeAt(i--);
}
}
}
2011-01-30 14:34:42 +00:00
setOnActivities(newActivitiesList);
#else
Q_UNUSED(property)
#endif
}
void Client::checkActivities()
{
#ifdef KWIN_BUILD_ACTIVITIES
Xcb::StringProperty property = fetchActivities();
readActivities(property);
#endif
2011-01-30 14:34:42 +00:00
}
void Client::setSessionInteract(bool needed)
{
needsSessionInteract = needed;
}
QRect Client::decorationRect() const
{
return QRect(0, 0, width(), height());
}
Xcb::Property Client::fetchFirstInTabBox() const
{
return Xcb::Property(false, m_client, atoms->kde_first_in_window_list,
atoms->kde_first_in_window_list, 0, 1);
}
void Client::readFirstInTabBox(Xcb::Property &property)
{
setFirstInTabBox(property.toBool(32, atoms->kde_first_in_window_list));
}
void Client::updateFirstInTabBox()
{
// TODO: move into KWindowInfo
Xcb::Property property = fetchFirstInTabBox();
readFirstInTabBox(property);
}
Xcb::StringProperty Client::fetchColorScheme() const
{
return Xcb::StringProperty(m_client, atoms->kde_color_sheme);
}
void Client::readColorScheme(Xcb::StringProperty &property)
{
AbstractClient::updateColorScheme(rules()->checkDecoColor(QString::fromUtf8(property)));
}
void Client::updateColorScheme()
{
Xcb::StringProperty property = fetchColorScheme();
readColorScheme(property);
}
bool Client::isClient() const
{
return true;
}
NET::WindowType Client::windowType(bool direct, int supportedTypes) const
{
// TODO: does it make sense to cache the returned window type for SUPPORTED_MANAGED_WINDOW_TYPES_MASK?
if (supportedTypes == 0) {
supportedTypes = SUPPORTED_MANAGED_WINDOW_TYPES_MASK;
}
NET::WindowType wt = info->windowType(NET::WindowTypes(supportedTypes));
if (direct) {
return wt;
}
NET::WindowType wt2 = client_rules.checkType(wt);
if (wt != wt2) {
wt = wt2;
info->setWindowType(wt); // force hint change
}
// hacks here
if (wt == NET::Unknown) // this is more or less suggested in NETWM spec
wt = isTransient() ? NET::Dialog : NET::Normal;
return wt;
}
bool Client::decorationHasAlpha() const
{
2014-07-22 12:04:48 +00:00
if (!m_decoration || m_decoration->isOpaque()) {
// either no decoration or decoration has alpha disabled
return false;
}
return true;
}
void Client::cancelFocusOutTimer()
{
if (m_focusOutTimer) {
m_focusOutTimer->stop();
}
}
xcb_window_t Client::frameId() const
{
return m_frame;
}
Xcb::Property Client::fetchShowOnScreenEdge() const
{
return Xcb::Property(false, window(), atoms->kde_screen_edge_show, XCB_ATOM_CARDINAL, 0, 1);
}
void Client::readShowOnScreenEdge(Xcb::Property &property)
Screenedge show support for Clients This provides a new protocol intended to be used by auto-hiding panels to make use of the centralized screen edges. To use it a Client can set an X11 property of type _KDE_NET_WM_SCREEN_EDGE_SHOW to KWin. As value it takes: * 0: top edge * 1: right edge * 2: bottom edge * 3: left edge KWin will hide the Client (hide because unmap or minimize would break it) and create an Edge. If that Edge gets triggered the Client is shown again and the property gets deleted. If the Client doesn't border the specified screen edge the Client gets shown immediately so that we never end in a situation that we cannot unhide the auto-hidden panel again. The exact process is described in the documentation of ScreenEdges. The Client can request to be shown again by deleting the property. If KWin gets restarted the state is read from the property and it is tried to create the edge as described. As this is a KWin specific extension we need to discuss what it means for Clients using this feature with other WMs: it does nothing. As the Client gets hidden by KWin and not by the Client, it just doesn't get hidden if the WM doesn't provide the feature. In case of an auto-hiding panel this seems like a good solution given that we don't want to hide it if we cannot unhide it. Of course there's the option for the Client to provide that feature itself and if that's wanted we would need to announce the feature in the _NET_SUPPORTED atom. At the moment that doesn't sound like being needed as Plasma doesn't want to provide an own implementation. The implementation comes with a small test application showing how the feature is intended to be used. REVIEW: 115910
2014-02-20 11:39:23 +00:00
{
const uint32_t value = property.value<uint32_t>(ElectricNone);
ElectricBorder border = ElectricNone;
switch (value) {
case 0:
border = ElectricTop;
break;
case 1:
border = ElectricRight;
break;
case 2:
border = ElectricBottom;
break;
case 3:
border = ElectricLeft;
break;
}
if (border != ElectricNone) {
hideClient(true);
ScreenEdges::self()->reserve(this, border);
} else if (!property.isNull() && property->type != XCB_ATOM_NONE) {
// property value is incorrect, delete the property
// so that the client knows that it is not hidden
xcb_delete_property(connection(), window(), atoms->kde_screen_edge_show);
} else {
// restore
Screenedge show support for Clients This provides a new protocol intended to be used by auto-hiding panels to make use of the centralized screen edges. To use it a Client can set an X11 property of type _KDE_NET_WM_SCREEN_EDGE_SHOW to KWin. As value it takes: * 0: top edge * 1: right edge * 2: bottom edge * 3: left edge KWin will hide the Client (hide because unmap or minimize would break it) and create an Edge. If that Edge gets triggered the Client is shown again and the property gets deleted. If the Client doesn't border the specified screen edge the Client gets shown immediately so that we never end in a situation that we cannot unhide the auto-hidden panel again. The exact process is described in the documentation of ScreenEdges. The Client can request to be shown again by deleting the property. If KWin gets restarted the state is read from the property and it is tried to create the edge as described. As this is a KWin specific extension we need to discuss what it means for Clients using this feature with other WMs: it does nothing. As the Client gets hidden by KWin and not by the Client, it just doesn't get hidden if the WM doesn't provide the feature. In case of an auto-hiding panel this seems like a good solution given that we don't want to hide it if we cannot unhide it. Of course there's the option for the Client to provide that feature itself and if that's wanted we would need to announce the feature in the _NET_SUPPORTED atom. At the moment that doesn't sound like being needed as Plasma doesn't want to provide an own implementation. The implementation comes with a small test application showing how the feature is intended to be used. REVIEW: 115910
2014-02-20 11:39:23 +00:00
// TODO: add proper unreserve
ScreenEdges::self()->reserve(this, ElectricNone);
hideClient(false);
}
}
void Client::updateShowOnScreenEdge()
{
Xcb::Property property = fetchShowOnScreenEdge();
readShowOnScreenEdge(property);
}
Screenedge show support for Clients This provides a new protocol intended to be used by auto-hiding panels to make use of the centralized screen edges. To use it a Client can set an X11 property of type _KDE_NET_WM_SCREEN_EDGE_SHOW to KWin. As value it takes: * 0: top edge * 1: right edge * 2: bottom edge * 3: left edge KWin will hide the Client (hide because unmap or minimize would break it) and create an Edge. If that Edge gets triggered the Client is shown again and the property gets deleted. If the Client doesn't border the specified screen edge the Client gets shown immediately so that we never end in a situation that we cannot unhide the auto-hidden panel again. The exact process is described in the documentation of ScreenEdges. The Client can request to be shown again by deleting the property. If KWin gets restarted the state is read from the property and it is tried to create the edge as described. As this is a KWin specific extension we need to discuss what it means for Clients using this feature with other WMs: it does nothing. As the Client gets hidden by KWin and not by the Client, it just doesn't get hidden if the WM doesn't provide the feature. In case of an auto-hiding panel this seems like a good solution given that we don't want to hide it if we cannot unhide it. Of course there's the option for the Client to provide that feature itself and if that's wanted we would need to announce the feature in the _NET_SUPPORTED atom. At the moment that doesn't sound like being needed as Plasma doesn't want to provide an own implementation. The implementation comes with a small test application showing how the feature is intended to be used. REVIEW: 115910
2014-02-20 11:39:23 +00:00
void Client::showOnScreenEdge()
{
hideClient(false);
xcb_delete_property(connection(), window(), atoms->kde_screen_edge_show);
}
#define BORDER(which) \
int Client::border##which() const \
{ \
return m_decoration ? m_decoration->border##which() : 0; \
}
BORDER(Bottom)
BORDER(Left)
BORDER(Right)
BORDER(Top)
#undef BORDER
QPointer<Decoration::DecoratedClientImpl> Client::decoratedClient() const
{
return m_decoratedClient;
}
void Client::setDecoratedClient(QPointer< Decoration::DecoratedClientImpl > client)
{
m_decoratedClient = client;
}
void Client::addDamage(const QRegion &damage)
{
if (!ready_for_painting) { // avoid "setReadyForPainting()" function calling overhead
if (syncRequest.counter == XCB_NONE) // cannot detect complete redraw, consider done now
setReadyForPainting();
}
Toplevel::addDamage(damage);
}
bool Client::belongsToSameApplication(const AbstractClient *other, bool active_hack) const
{
const Client *c2 = dynamic_cast<const Client*>(other);
if (!c2) {
return false;
}
return Client::belongToSameApplication(this, c2, active_hack);
}
bool Client::processDecorationButtonPress(QMouseEvent *event)
{
return processDecorationButtonPress(qtToX11Button(event->button()), 0,
event->x(), event->y(),
event->globalX(), event->globalY());
}
void Client::processDecorationButtonRelease(QMouseEvent *event)
{
if (m_decoration) {
if (!event->isAccepted() && m_decoration->titleBar().contains(event->pos()) && event->button() == Qt::LeftButton) {
m_decorationDoubleClickTimer.start();
}
}
if (event->buttons() == Qt::NoButton) {
buttonDown = false;
stopDelayedMoveResize();
if (moveResizeMode) {
finishMoveResize(false);
mode = mousePosition();
}
updateCursor();
}
}
void Client::processDecorationMove()
{
if (buttonDown) {
return;
}
// TODO: handle modifiers
Position newmode = mousePosition();
if (newmode != mode) {
mode = newmode;
updateCursor();
}
}
} // namespace
#include "client.moc"