File indexing completed on 2024-05-05 16:19:53
0001 /* 0002 SPDX-FileCopyrightText: 2001-2003 Lubos Lunak <l.lunak@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KXMESSAGES_H 0008 #define KXMESSAGES_H 0009 0010 #include <QObject> 0011 #include <kwindowsystem_export.h> 0012 0013 #include <config-kwindowsystem.h> // KWINDOWSYSTEM_HAVE_X11 0014 #if KWINDOWSYSTEM_HAVE_X11 0015 #include <xcb/xcb.h> 0016 typedef struct _XDisplay Display; 0017 0018 class QString; 0019 0020 class KXMessagesPrivate; 0021 0022 /** 0023 * Sending string messages to other applications using the X Client Messages. 0024 * 0025 * Used internally by KStartupInfo and kstart. 0026 * You usually don't want to use this, use D-Bus instead. 0027 * 0028 * @internal 0029 * 0030 * @author Lubos Lunak <l.lunak@kde.org> 0031 */ 0032 class KWINDOWSYSTEM_EXPORT KXMessages : public QObject 0033 { 0034 Q_OBJECT 0035 public: 0036 /** 0037 * Creates an instance which will receive X messages. 0038 * 0039 * @param accept_broadcast if non-nullptr, all broadcast messages with 0040 * this message type will be received. 0041 * @param parent the parent of this widget 0042 */ 0043 explicit KXMessages(const char *accept_broadcast = nullptr, QObject *parent = nullptr); 0044 0045 /** 0046 * @overload 0047 * Overload passing in the xcb_connection_t to use instead relying on platform xcb. 0048 * 0049 * @param connection The xcb connection 0050 * @param rootWindow The rootWindow to use 0051 * @param accept_broadcast if non-nullptr, all broadcast messages with 0052 * this message type will be received. 0053 * @param parent the parent of this object 0054 * @since 5.8 0055 **/ 0056 explicit KXMessages(xcb_connection_t *connection, xcb_window_t rootWindow, const char *accept_broadcast = nullptr, QObject *parent = nullptr); 0057 0058 ~KXMessages() override; 0059 /** 0060 * Broadcasts the given message with the given message type. 0061 * @param msg_type the type of the message 0062 * @param message the message itself 0063 * @param screen X11 screen to use, -1 for the default 0064 */ 0065 void broadcastMessage(const char *msg_type, const QString &message, int screen = -1); 0066 // Not 5.0, as KStartupInfo::sendStartupX uses this, and is only deprecated for 5.18 0067 #if KWINDOWSYSTEM_ENABLE_DEPRECATED_SINCE(5, 18) 0068 /** 0069 * Broadcasts the given message with the given message type. 0070 * 0071 * @param disp X11 connection which will be used instead of 0072 * QX11Info::display() 0073 * @param msg_type the type of the message 0074 * @param message the message itself 0075 * @param screen X11 screen to use, -1 for the default 0076 * @return false when an error occurred, true otherwise 0077 * @deprecated since 5.0 use xcb variant 0078 */ 0079 KWINDOWSYSTEM_DEPRECATED_VERSION( 0080 5, 0081 0, 0082 "Use KXMessages::broadcastMessageX(xcb_connection_t *, const char *, const QString &, int)") 0083 static bool broadcastMessageX(Display *disp, const char *msg_type, const QString &message, int screen = -1); 0084 #endif 0085 /** 0086 * Broadcasts the given message with the given message type. 0087 * 0088 * @param c X11 connection which will be used instead of 0089 * QX11Info::connection() 0090 * @param msg_type the type of the message 0091 * @param message the message itself 0092 * @param screenNumber X11 screen to use 0093 * @return false when an error occurred, true otherwise 0094 */ 0095 static bool broadcastMessageX(xcb_connection_t *c, const char *msg_type, const QString &message, int screenNumber); 0096 0097 #if 0 // currently unused 0098 /** 0099 * Sends the given message with the given message type only to given 0100 * window. 0101 * 0102 * @param w X11 handle for the destination window 0103 * @param msg_type the type of the message 0104 * @param message the message itself 0105 */ 0106 void sendMessage(WId w, const char *msg_type, const QString &message); 0107 /** 0108 * Sends the given message with the given message type only to given 0109 * window. 0110 * 0111 * @param disp X11 connection which will be used instead of 0112 * QX11Info::display() 0113 * @param w X11 handle for the destination window 0114 * @param msg_type the type of the message 0115 * @param message the message itself 0116 * @return false when an error occurred, true otherwise 0117 */ 0118 static bool sendMessageX(Display *disp, WId w, const char *msg_type, 0119 const QString &message); 0120 #endif 0121 0122 Q_SIGNALS: 0123 /** 0124 * Emitted when a message was received. 0125 * @param message the message that has been received 0126 */ 0127 void gotMessage(const QString &message); 0128 0129 private: 0130 friend class KXMessagesPrivate; 0131 KXMessagesPrivate *const d; 0132 }; 0133 0134 #endif 0135 #endif