KSelectionOwner Class

ICCCM manager selection owner. More...

Header: #include <KSelectionOwner>
CMake: find_package(KF6 REQUIRED COMPONENTS KWindowSystem)
target_link_libraries(mytarget PRIVATE KF6::KWindowSystem)
Inherits: QObject

Public Functions

KSelectionOwner(xcb_atom_t selection, int screen = -1, QObject *parent = nullptr)
KSelectionOwner(const char *selection, int screen = -1, QObject *parent = nullptr)
(since 5.8) KSelectionOwner(const char *selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr)
(since 5.8) KSelectionOwner(xcb_atom_t selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr)
virtual ~KSelectionOwner() override
void claim(bool force, bool force_kill = true)
xcb_window_t ownerWindow() const
void release()

Signals

Protected Functions

virtual bool genericReply(xcb_atom_t target, xcb_atom_t property, xcb_window_t requestor)
virtual void getAtoms()
virtual void replyTargets(xcb_atom_t property, xcb_window_t requestor)
void setData(uint32_t extra1, uint32_t extra2)

Detailed Description

This class implements claiming and owning manager selections, as described in the ICCCM, section 2.8. The selection atom is passed to the constructor, claim() attempts to claim ownership of the selection, release() gives up the selection ownership. Signal lostOwnership() is emitted when the selection is claimed by another owner.

This class is only useful on the xcb platform. On other platforms the code is only functional if the constructor overloads taking an xcb_connection_t are used. In case you inherit from this class ensure that you don't use xcb and/or XLib without verifying the platform.

Member Function Documentation

[explicit] KSelectionOwner::KSelectionOwner(xcb_atom_t selection, int screen = -1, QObject *parent = nullptr)

This constructor initializes the object, but doesn't perform any operation on the selection.

selection atom representing the manager selection

screen X screen, or -1 for default

parent parent object, or nullptr if there is none

[explicit] KSelectionOwner::KSelectionOwner(const char *selection, int screen = -1, QObject *parent = nullptr)

This is an overloaded function.

This constructor accepts the selection name and creates the appropriate atom for it automatically.

selection name of the manager selection

screen X screen, or -1 for default

parent parent object, or nullptr if there is none

[explicit, since 5.8] KSelectionOwner::KSelectionOwner(const char *selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr)

This is an overloaded function.

This constructor accepts the xcb_connection_t and root window and doesn't depend on running on the xcb platform. Otherwise this constructor behaves like the similar one without the xcb_connection_t.

selection name of the manager selection

c the xcb connection this KSelectionWatcher should use

root the root window this KSelectionWatcher should use

parent parent object, or nullptr if there is none

This function was introduced in 5.8.

[explicit, since 5.8] KSelectionOwner::KSelectionOwner(xcb_atom_t selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr)

This is an overloaded function.

This constructor accepts the xcb_connection_t and root window and doesn't depend on running on the xcb platform. Otherwise this constructor behaves like the similar one without the xcb_connection_t.

selection atom representing the manager selection

c the xcb connection this KSelectionWatcher should use

root the root window this KSelectionWatcher should use

parent parent object, or nullptr if there is none

This function was introduced in 5.8.

[override virtual noexcept] KSelectionOwner::~KSelectionOwner()

Destructor. Calls release().

void KSelectionOwner::claim(bool force, bool force_kill = true)

Try to claim ownership of the manager selection using the current X timestamp.

This function returns immediately, but it may take up to one second for the claim to succeed or fail, at which point either the claimedOwnership() or failedToClaimOwnership() signal is emitted. The claim will not be completed until the caller has returned to the event loop.

If force is false, and the selection is already owned, the selection is not claimed, and failedToClaimOwnership() is emitted. If force is true and the selection is owned by another client, the client will be given one second to relinquish ownership of the selection. If force_kill is true, and the previous owner fails to disown the selection in time, it will be forcibly killed.

[signal] void KSelectionOwner::claimedOwnership()

This signal is emitted when claim() was successful in claiming ownership of the selection.

[signal] void KSelectionOwner::failedToClaimOwnership()

This signal is emitted when claim() failed to claim ownership of the selection.

[virtual protected] bool KSelectionOwner::genericReply(xcb_atom_t target, xcb_atom_t property, xcb_window_t requestor)

Called when a SelectionRequest event is received. A reply should be sent using the selection handling mechanism described in the ICCCM section 2.

target requested target type

property property to use for the reply data

requestor requestor window

[virtual protected] void KSelectionOwner::getAtoms()

Called to create atoms needed for claiming the selection and communication using the selection handling mechanism. The default implementation must be called if reimplemented. This method may be called repeatedly.

[signal] void KSelectionOwner::lostOwnership()

This signal is emitted if the selection was owned and the ownership has been lost due to another client claiming it, this signal is emitted. IMPORTANT: It's not safe to delete the instance in a slot connected to this signal.

xcb_window_t KSelectionOwner::ownerWindow() const

If the selection is owned, returns the window used internally for owning the selection.

void KSelectionOwner::release()

If the selection is owned, the ownership is given up.

[virtual protected] void KSelectionOwner::replyTargets(xcb_atom_t property, xcb_window_t requestor)

Called to announce the supported targets, as described in the ICCCM section 2.6. The default implementation announces the required targets MULTIPLE, TIMESTAMP and TARGETS.

[protected] void KSelectionOwner::setData(uint32_t extra1, uint32_t extra2)

Sets extra data to be sent in the message sent to root window after successfully claiming a selection. These extra data are in data.l[3] and data.l[4] fields of the XClientMessage.