Virtual desktop names are user defined strings so they can exceed the maximum size of a wayland message size. BUG: 480614wilder/Plasma/6.2
parent
92f4a95bb5
commit
e58451fc01
4 changed files with 32 additions and 15 deletions
@ -0,0 +1,27 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2024 David Edmundson <kde@davidedmundson.co.uk> |
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
||||
*/ |
||||
#pragma once |
||||
|
||||
#include <QString> |
||||
|
||||
namespace KWin |
||||
{ |
||||
|
||||
/**
|
||||
* Any strings that come from user-defined sources that could exceed the maximum wayland length (e.g. xwayland clients) |
||||
* need to be truncated to the maximumWaylandBufferSize. |
||||
*/ |
||||
static inline QString truncate(const QString &stringIn) |
||||
{ |
||||
const int libwaylandMaxBufferSize = 4096; |
||||
// Some parts of the buffer is used for metadata, so subtract 100 to be on the safe side.
|
||||
// Also, QString is in utf-16, which means that in the worst case each character will be
|
||||
// three bytes when converted to utf-8 (which is what libwayland uses), so divide by three.
|
||||
const int maxLength = libwaylandMaxBufferSize / 3 - 100; |
||||
return stringIn.left(maxLength); |
||||
} |
||||
|
||||
} // namespace KWin
|
||||
Loading…
Reference in new issue