Commit f0e1e318 authored by Martin Flöser's avatar Martin Flöser
Browse files

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

parent 8bdbe4dc
......@@ -56,6 +56,7 @@ Atoms::Atoms()
, kde_color_sheme(QByteArrayLiteral("_KDE_NET_WM_COLOR_SCHEME"))
, kde_skip_close_animation(QByteArrayLiteral("_KDE_NET_WM_SKIP_CLOSE_ANIMATION"))
, kde_screen_edge_show(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"))
, gtk_frame_extents(QByteArrayLiteral("_GTK_FRAME_EXTENTS"))
, m_dtSmWindowInfo(QByteArrayLiteral("_DT_SM_WINDOW_INFO"))
, m_motifSupport(QByteArrayLiteral("_MOTIF_WM_INFO"))
, m_helpersRetrieved(false)
......@@ -65,6 +65,7 @@ public:
Xcb::Atom kde_color_sheme;
Xcb::Atom kde_skip_close_animation;
Xcb::Atom kde_screen_edge_show;
Xcb::Atom gtk_frame_extents;
* @internal
......@@ -232,6 +232,7 @@ Client::Client()
, m_decoInputExtent()
, m_focusOutTimer(nullptr)
, m_palette(QApplication::palette())
, m_clientSideDecorated(false)
// TODO: Do all as initialization
syncRequest.counter = syncRequest.alarm = XCB_NONE;
......@@ -739,6 +740,13 @@ void Client::updateFrameExtents()
void Client::detectGtkFrameExtents()
Xcb::Property prop(false, m_client, atoms->gtk_frame_extents, XCB_ATOM_CARDINAL, 0, 4);
m_clientSideDecorated = !prop.isNull() && prop->type != 0;
emit clientSideDecoratedChanged();
* 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
......@@ -278,6 +278,11 @@ class Client
* Whether the decoration is currently using an alpha channel.
Q_PROPERTY(bool decorationHasAlpha READ decorationHasAlpha)
* Whether the Client uses client side window decorations.
* Only GTK+ are detected.
Q_PROPERTY(bool clientSideDecorated READ isClientSideDecorated NOTIFY clientSideDecoratedChanged)
explicit Client();
xcb_window_t wrapperId() const;
......@@ -608,6 +613,7 @@ public:
QRegion decorationPendingRegion() const;
bool decorationHasAlpha() const;
bool isClientSideDecorated() const;
Position titlebarPosition() const;
......@@ -780,6 +786,7 @@ Q_SIGNALS:
* Emitted whenever the Client's block compositing state changes.
void blockingCompositingChanged(KWin::Client *client);
void clientSideDecoratedChanged();
void exportMappingState(int s); // ICCCM, 4.1.4, NETWM 2.5.1
......@@ -827,6 +834,7 @@ private:
void embedClient(xcb_window_t w, xcb_visualid_t visualid, xcb_colormap_t colormap, uint8_t depth);
void detectNoBorder();
void detectGtkFrameExtents();
void destroyDecoration();
void updateFrameExtents();
......@@ -1016,6 +1024,7 @@ private:
QPalette m_palette;
QList<QMetaObject::Connection> m_connections;
bool m_clientSideDecorated;
......@@ -1049,6 +1058,11 @@ inline xcb_window_t Client::decorationId() const
inline bool Client::isClientSideDecorated() const
return m_clientSideDecorated;
inline const Client* Client::transientFor() const
return transient_for;
......@@ -869,6 +869,8 @@ void Client::propertyNotifyEvent(xcb_property_notify_event_t *e)
else if (e->atom == atoms->kde_screen_edge_show)
else if (e->atom == atoms->gtk_frame_extents)
......@@ -120,6 +120,7 @@ bool Client::manage(xcb_window_t w, bool isMapped)
if (Xcb::Extensions::self()->isShapeAvailable())
xcb_shape_select_input(connection(), window(), true);
getWMHints(); // Needs to be done before readTransient() because of reading the group
......@@ -2,8 +2,10 @@
install( DIRECTORY synchronizeskipswitcher DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts )
install( DIRECTORY desktopchangeosd DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts )
install( DIRECTORY enforcedeco DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts )
# service files
install( FILES videowall/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-videowall.desktop )
install( FILES synchronizeskipswitcher/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-synchronizeskipswitcher.desktop )
install( FILES desktopchangeosd/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-desktopchangeosd.desktop )
install( FILES enforcedeco/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-enforcedeco.desktop )
* Copyright 2014 Martin Gräßlin <>
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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 <>.
function enforceDeco(client) {
if (client.noBorder && client.clientSideDecorated) {
client.noBorder = false
function setupConnection(client) {
client.clientSideDecoratedChanged.connect(client, function () {
// connect all existing clients
var clients = workspace.clientList();
for (var i=0; i<clients.length; i++) {
[Desktop Entry]
Name=Enforces Window Decorations on GTK+ window
Comment=Fixes functional deficits for client side decorated windows.
X-KDE-PluginInfo-Author=Martin Gräßlin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment