1 | /* |
2 | SPDX-FileCopyrightText: 2001-2003 Lubos Lunak <l.lunak@kde.org> |
3 | |
4 | SPDX-License-Identifier: MIT |
5 | */ |
6 | |
7 | #ifndef KXMESSAGES_H |
8 | #define KXMESSAGES_H |
9 | |
10 | #include <QObject> |
11 | #include <kwindowsystem_export.h> |
12 | |
13 | #include <config-kwindowsystem.h> // KWINDOWSYSTEM_HAVE_X11 |
14 | #if KWINDOWSYSTEM_HAVE_X11 |
15 | #include <xcb/xcb.h> |
16 | typedef struct _XDisplay Display; |
17 | |
18 | class QString; |
19 | |
20 | class KXMessagesPrivate; |
21 | |
22 | /*! |
23 | * Sending string messages to other applications using the X Client Messages. |
24 | * |
25 | * Used internally by KStartupInfo and kstart. |
26 | * You usually don't want to use this, use D-Bus instead. |
27 | * |
28 | * \internal |
29 | */ |
30 | class KWINDOWSYSTEM_EXPORT KXMessages : public QObject |
31 | { |
32 | Q_OBJECT |
33 | public: |
34 | /*! |
35 | * Creates an instance which will receive X messages. |
36 | * |
37 | * \a accept_broadcast if non-nullptr, all broadcast messages with |
38 | * this message type will be received. |
39 | * |
40 | * \a parent the parent of this widget |
41 | */ |
42 | explicit KXMessages(const char *accept_broadcast = nullptr, QObject *parent = nullptr); |
43 | |
44 | /*! |
45 | * \overload |
46 | * Overload passing in the xcb_connection_t to use instead relying on platform xcb. |
47 | * |
48 | * \a connection The xcb connection |
49 | * |
50 | * \a rootWindow The rootWindow to use |
51 | * |
52 | * \a accept_broadcast if non-nullptr, all broadcast messages with |
53 | * this message type will be received. |
54 | * \a parent the parent of this object |
55 | * |
56 | * \since 5.8 |
57 | **/ |
58 | explicit KXMessages(xcb_connection_t *connection, xcb_window_t rootWindow, const char *accept_broadcast = nullptr, QObject *parent = nullptr); |
59 | |
60 | ~KXMessages() override; |
61 | /*! |
62 | * Broadcasts the given message with the given message type. |
63 | * |
64 | * \a msg_type the type of the message |
65 | * |
66 | * \a message the message itself |
67 | * |
68 | * \a screen X11 screen to use, -1 for the default |
69 | */ |
70 | void broadcastMessage(const char *msg_type, const QString &message, int screen = -1); |
71 | |
72 | /*! |
73 | * Broadcasts the given message with the given message type. |
74 | * |
75 | * \a c X11 connection which will be used instead of |
76 | * QX11Info::connection() |
77 | * |
78 | * \a msg_type the type of the message |
79 | * |
80 | * \a message the message itself |
81 | * |
82 | * \a screenNumber X11 screen to use |
83 | * |
84 | * Returns false when an error occurred, true otherwise |
85 | */ |
86 | static bool broadcastMessageX(xcb_connection_t *c, const char *msg_type, const QString &message, int screenNumber); |
87 | |
88 | Q_SIGNALS: |
89 | /*! |
90 | * Emitted when a message was received. |
91 | * |
92 | * \a message the message that has been received |
93 | */ |
94 | void gotMessage(const QString &message); |
95 | |
96 | private: |
97 | friend class KXMessagesPrivate; |
98 | KXMessagesPrivate *const d; |
99 | }; |
100 | |
101 | #endif |
102 | #endif |
103 | |