File indexing completed on 2024-05-12 05:32:26
0001 /* 0002 SPDX-FileCopyrightText: 2024 David Edmundson <kde@davidedmundson.co.uk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #pragma once 0007 0008 #include <QString> 0009 0010 namespace KWin 0011 { 0012 0013 /** 0014 * Any strings that come from user-defined sources that could exceed the maximum wayland length (e.g. xwayland clients) 0015 * need to be truncated to the maximumWaylandBufferSize. 0016 */ 0017 static inline QString truncate(const QString &stringIn) 0018 { 0019 const int libwaylandMaxBufferSize = 4096; 0020 // Some parts of the buffer is used for metadata, so subtract 100 to be on the safe side. 0021 // Also, QString is in utf-16, which means that in the worst case each character will be 0022 // three bytes when converted to utf-8 (which is what libwayland uses), so divide by three. 0023 const int maxLength = libwaylandMaxBufferSize / 3 - 100; 0024 return stringIn.left(maxLength); 0025 } 0026 0027 } // namespace KWin