deskflow/src/lib/base/IEventQueue.h

225 lines
6.9 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
2012-06-10 16:50:54 +00:00
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "base/Event.h"
#include "common/IInterface.h"
#include <string>
2012-06-10 16:50:54 +00:00
class IEventJob;
class IEventQueueBuffer;
// Opaque type for timer info. This is defined by subclasses of
// IEventQueueBuffer.
2014-11-11 13:51:47 +00:00
class EventQueueTimer;
2012-06-10 16:50:54 +00:00
// Event type registration classes.
2014-11-11 13:51:47 +00:00
class ClientEvents;
class IStreamEvents;
class IDataSocketEvents;
class IListenSocketEvents;
class ISocketEvents;
2014-11-11 13:51:47 +00:00
class OSXScreenEvents;
class ClientListenerEvents;
class ClientProxyEvents;
class ClientProxyUnknownEvents;
class ServerEvents;
class ServerAppEvents;
class IKeyStateEvents;
class IPrimaryScreenEvents;
class IScreenEvents;
class ClipboardEvents;
2015-06-05 20:33:24 +00:00
class FileEvents;
Wayland support (port Red Hat `libei` and `libportal` impl) (#7449) * Add libei and libportal * Port libei and libportal code by Peter Hutterer and Olivier Fourdan * Add Peter Hutterer and Olivier Fourdan to important devs list * Improve error handling for libei and libportal builds * Checkout libportal tags/0.7.1 * Hack out the gi-docgen clone * Remove new submodules in favor of using ExternalProject_Add * Remove submodule dirs * Use ExternalProject_Add instead of submodules * Fixed namespace * Hack to work around type libportal causing type conflicts * Add log helper functions * Use original log functions * Switch to FetchContent, use libportal a1530a9 (unreleased) and use camelCase member names for consistency * Restore a few events (much more work required) * Add TODOs for supporting multiple lib versions * Revert "Switch to FetchContent, use libportal a1530a9 (unreleased) and use camelCase member names for consistency" This reverts commit 610cebb5b6a08282eee68f4424fcdbe9eaab4bf9. * Simplify cmake config by removing builds for libei and libportal (will do this in `install_deps.py` instead) * Remove submodules * Remove .gitmodules * Use meson to build subprojects * Update copyright with Peter Hutterer's guidance * Use meson for installing deps * Fixed typo in tag name * Remove submodules * Remove old submodules * Fixed libei name * Defaults for pugixml and gtest depending on whether source exists in subprojects * Ignore some subproject dirs * Make deps OS-specific * Move python deps to pyproject * Only compile and install on Linux with Meson * Revert "Move python deps to pyproject" This reverts commit 92c8a287b8376a4d166058c85f1d6081f6fdb423. * Add ninja to brewfile * Add python3-attr * Restore original coverage config * Add ninja for meson * Include meson in same try-except * Fixed ninja dep name * Move libs to correct oS * Fixed include for wintoast * Disable docs for libportal * More options for libei and libportal * Fixed option for libei * Use ninja directly to install * Revert "Use ninja directly to install" This reverts commit c926d78ba483406a55acd10fb157c39e13f90b71. * Meson install verbose * Prints stdout/stderr * Remove `from None` * Remove submodules that somehow crept back in?! * Prepend sudo if exists * Add libei deps for all distros * Fixed Fedora package name * Add more deps for other distros * Add more libs (including pugixml) * Fix lib name * Drop -u from pacman * Add vala to rhel * Make libportal optional * Make portal link optional * Remove example code * Always use system pugixml * Disable interactive apt through install_deps.py * Revert "Disable interactive apt through install_deps.py" This reverts commit 5bbc8fd689182447c79b81db16c961b98361a292. * Set DEBIAN_FRONTEND in workflows * Set DEBIAN_FRONTEND in CodeQL workflow * Add gtest dep * Add bundled libei dep * Add libei dep to Arch * Use `googletest` on openSUSE * Add gmock dep * Remove gtest dep from openSUSE * Add libei on Fedora * Bundle libei for older Linux distros * Disable libei dep for RPM * Also bundle symlink to .so * Use ${CMAKE_INSTALL_LIBDIR} * Rename libei to fix openSUSE * List installed files * Add libei-devel to openSUSE * Add googletest-devel to openSUSE * Remove manual deps (probably resolved automatically) * Remove googletest from openSUSE (doesn't provide google mock) * Only add Portal* if libportal found * WIP - Partial work on using old events system :'( * Add deps install commands for subprojects * Solved more compile issues related to events system, threads, etc * Fixed bad config for adding x, ei, portal sources * Remove redundant deps * Remove (another) redundant dep * Fixed pacman command * Add Ubuntu and Linux Mint libei deps * Fixed Ubuntu and Linux Mint libei deps aliases * Only iterate subprojects if not None * Add rhel, rocky, and alma for libei * Make rhel-like deps same as fedora again * Build libportal on rhel-like * Re-enable meson rhel-like for libportal * Remove dbus-python * Make libportal optional (for rhel-like) * Handle ei event queue results * Re-introduce libportal * Print libei and libportal versions * Add ei/portal args and client screen * Switch --use args to --no * Don't build libei/libportal on older distros as it's pointless * Make libei and libportal optional * Add Debian 13 runner * Make some packages optional * Remove subprojects * Improve comment * Add comment for libportal * Improve comment * Add Debian 13 runner * Make optional... optional * Change continuation stripper to remove newline and continuation char * Make command strip more uniform * Fixed help var syntax * Fixed libei linking * Ensure `kHelpNoWayland` is always defined * Improve help message * Fixed Debian 13 runner name * Include sstream and use const var * Update ChangeLog * Remove Wayland block * Return new timer * Make tray icon logging verbose * Fixed arg parser for wayland args * Fixed init of EI screen * Fixed lint issues * Update README to indicate Wayland support in GNOME 46 * Add missing word * Fixed comment positions * Automate CI env * Tone down debug log messages * Add missing comma * Remove redundant log line
2024-08-30 14:53:25 +00:00
class EiEvents;
2012-06-10 16:50:54 +00:00
//! Event queue interface
/*!
2014-11-11 13:51:47 +00:00
An event queue provides a queue of Events. Clients can block waiting
2012-06-10 16:50:54 +00:00
on any event becoming available at the head of the queue and can place
new events at the end of the queue. Clients can also add and remove
timers which generate events periodically.
*/
class IEventQueue : public IInterface
{
2012-06-10 16:50:54 +00:00
public:
class TimerEvent
{
public:
EventQueueTimer *m_timer; //!< The timer
2025-01-11 02:13:19 +00:00
uint32_t m_count; //!< Number of repeats
};
//! @name manipulators
//@{
//! Loop the event queue until quit
/*!
Dequeues and dispatches events until the kQuit event is found.
*/
virtual void loop() = 0;
//! Set the buffer
/*!
Replace the current event queue buffer. Any queued events are
discarded. The queue takes ownership of the buffer.
*/
virtual void adoptBuffer(IEventQueueBuffer *) = 0;
//! Remove event from queue
/*!
Returns the next event on the queue into \p event. If no event is
available then blocks for up to \p timeout seconds, or forever if
\p timeout is negative. Returns true iff an event was available.
*/
virtual bool getEvent(Event &event, double timeout = -1.0) = 0;
//! Dispatch an event
/*!
Looks up the dispatcher for the event's target and invokes it.
Returns true iff a dispatcher exists for the target.
*/
virtual bool dispatchEvent(const Event &event) = 0;
//! Add event to queue
/*!
Adds \p event to the end of the queue.
*/
virtual void addEvent(const Event &event) = 0;
//! Create a recurring timer
/*!
Creates and returns a timer. An event is returned after \p duration
seconds and the timer is reset to countdown again. When a timer event
is returned the data points to a \c TimerEvent. The client must pass
the returned timer to \c deleteTimer() (whether or not the timer has
expired) to release the timer. The returned timer event uses the
given \p target. If \p target is nullptr it uses the returned timer as
the target.
Events for a single timer don't accumulate in the queue, even if the
client reading events can't keep up. Instead, the \c m_count member
of the \c TimerEvent indicates how many events for the timer would
have been put on the queue since the last event for the timer was
removed (or since the timer was added).
*/
virtual EventQueueTimer *newTimer(double duration, void *target) = 0;
//! Create a one-shot timer
/*!
Creates and returns a one-shot timer. An event is returned when
the timer expires and the timer is removed from further handling.
When a timer event is returned the data points to a \c TimerEvent.
The c_count member of the \c TimerEvent is always 1. The client
must pass the returned timer to \c deleteTimer() (whether or not the
timer has expired) to release the timer. The returned timer event
uses the given \p target. If \p target is nullptr it uses the returned
timer as the target.
*/
virtual EventQueueTimer *newOneShotTimer(double duration, void *target) = 0;
//! Destroy a timer
/*!
Destroys a previously created timer. The timer is removed from the
queue and will not generate event, even if the timer has expired.
*/
virtual void deleteTimer(EventQueueTimer *) = 0;
//! Register an event handler for an event type
/*!
Registers an event handler for \p type and \p target. The \p handler
is adopted. Any existing handler for the type,target pair is deleted.
\c dispatchEvent() will invoke \p handler for any event for \p target
of type \p type. If no such handler exists it will use the handler
for \p target and type \p kUnknown if it exists.
*/
virtual void adoptHandler(Event::Type type, void *target, IEventJob *handler) = 0;
//! Unregister an event handler for an event type
/*!
Unregisters an event handler for the \p type, \p target pair and
deletes it.
*/
virtual void removeHandler(Event::Type type, void *target) = 0;
//! Unregister all event handlers for an event target
/*!
Unregisters all event handlers for the \p target and deletes them.
*/
virtual void removeHandlers(void *target) = 0;
//! Creates a new event type
/*!
If \p type contains \c kUnknown then it is set to a unique event
type id otherwise it is left alone. The final value of \p type
is returned.
*/
virtual Event::Type registerTypeOnce(Event::Type &type, const char *name) = 0;
//! Wait for event queue to become ready
/*!
Blocks on the current thread until the event queue is ready for events to
be added.
*/
virtual void waitForReady() const = 0;
//@}
//! @name accessors
//@{
//! Test if queue is empty
/*!
Returns true iff the queue has no events in it, including timer
events.
*/
virtual bool isEmpty() const = 0;
//! Get an event handler
/*!
Finds and returns the event handler for the \p type, \p target pair
if it exists, otherwise it returns nullptr.
*/
virtual IEventJob *getHandler(Event::Type type, void *target) const = 0;
//! Get name for event
/*!
Returns the name for the event \p type. This is primarily for
debugging.
*/
virtual const char *getTypeName(Event::Type type) = 0;
//! Get the system event type target
/*!
Returns the target to use for dispatching \c Event::kSystem events.
*/
virtual void *getSystemTarget() = 0;
//@}
//
// Event type providers.
//
virtual ClientEvents &forClient() = 0;
virtual IStreamEvents &forIStream() = 0;
virtual IDataSocketEvents &forIDataSocket() = 0;
virtual IListenSocketEvents &forIListenSocket() = 0;
virtual ISocketEvents &forISocket() = 0;
virtual OSXScreenEvents &forOSXScreen() = 0;
virtual ClientListenerEvents &forClientListener() = 0;
virtual ClientProxyEvents &forClientProxy() = 0;
virtual ClientProxyUnknownEvents &forClientProxyUnknown() = 0;
virtual ServerEvents &forServer() = 0;
virtual ServerAppEvents &forServerApp() = 0;
virtual IKeyStateEvents &forIKeyState() = 0;
virtual IPrimaryScreenEvents &forIPrimaryScreen() = 0;
virtual IScreenEvents &forIScreen() = 0;
virtual ClipboardEvents &forClipboard() = 0;
virtual FileEvents &forFile() = 0;
Wayland support (port Red Hat `libei` and `libportal` impl) (#7449) * Add libei and libportal * Port libei and libportal code by Peter Hutterer and Olivier Fourdan * Add Peter Hutterer and Olivier Fourdan to important devs list * Improve error handling for libei and libportal builds * Checkout libportal tags/0.7.1 * Hack out the gi-docgen clone * Remove new submodules in favor of using ExternalProject_Add * Remove submodule dirs * Use ExternalProject_Add instead of submodules * Fixed namespace * Hack to work around type libportal causing type conflicts * Add log helper functions * Use original log functions * Switch to FetchContent, use libportal a1530a9 (unreleased) and use camelCase member names for consistency * Restore a few events (much more work required) * Add TODOs for supporting multiple lib versions * Revert "Switch to FetchContent, use libportal a1530a9 (unreleased) and use camelCase member names for consistency" This reverts commit 610cebb5b6a08282eee68f4424fcdbe9eaab4bf9. * Simplify cmake config by removing builds for libei and libportal (will do this in `install_deps.py` instead) * Remove submodules * Remove .gitmodules * Use meson to build subprojects * Update copyright with Peter Hutterer's guidance * Use meson for installing deps * Fixed typo in tag name * Remove submodules * Remove old submodules * Fixed libei name * Defaults for pugixml and gtest depending on whether source exists in subprojects * Ignore some subproject dirs * Make deps OS-specific * Move python deps to pyproject * Only compile and install on Linux with Meson * Revert "Move python deps to pyproject" This reverts commit 92c8a287b8376a4d166058c85f1d6081f6fdb423. * Add ninja to brewfile * Add python3-attr * Restore original coverage config * Add ninja for meson * Include meson in same try-except * Fixed ninja dep name * Move libs to correct oS * Fixed include for wintoast * Disable docs for libportal * More options for libei and libportal * Fixed option for libei * Use ninja directly to install * Revert "Use ninja directly to install" This reverts commit c926d78ba483406a55acd10fb157c39e13f90b71. * Meson install verbose * Prints stdout/stderr * Remove `from None` * Remove submodules that somehow crept back in?! * Prepend sudo if exists * Add libei deps for all distros * Fixed Fedora package name * Add more deps for other distros * Add more libs (including pugixml) * Fix lib name * Drop -u from pacman * Add vala to rhel * Make libportal optional * Make portal link optional * Remove example code * Always use system pugixml * Disable interactive apt through install_deps.py * Revert "Disable interactive apt through install_deps.py" This reverts commit 5bbc8fd689182447c79b81db16c961b98361a292. * Set DEBIAN_FRONTEND in workflows * Set DEBIAN_FRONTEND in CodeQL workflow * Add gtest dep * Add bundled libei dep * Add libei dep to Arch * Use `googletest` on openSUSE * Add gmock dep * Remove gtest dep from openSUSE * Add libei on Fedora * Bundle libei for older Linux distros * Disable libei dep for RPM * Also bundle symlink to .so * Use ${CMAKE_INSTALL_LIBDIR} * Rename libei to fix openSUSE * List installed files * Add libei-devel to openSUSE * Add googletest-devel to openSUSE * Remove manual deps (probably resolved automatically) * Remove googletest from openSUSE (doesn't provide google mock) * Only add Portal* if libportal found * WIP - Partial work on using old events system :'( * Add deps install commands for subprojects * Solved more compile issues related to events system, threads, etc * Fixed bad config for adding x, ei, portal sources * Remove redundant deps * Remove (another) redundant dep * Fixed pacman command * Add Ubuntu and Linux Mint libei deps * Fixed Ubuntu and Linux Mint libei deps aliases * Only iterate subprojects if not None * Add rhel, rocky, and alma for libei * Make rhel-like deps same as fedora again * Build libportal on rhel-like * Re-enable meson rhel-like for libportal * Remove dbus-python * Make libportal optional (for rhel-like) * Handle ei event queue results * Re-introduce libportal * Print libei and libportal versions * Add ei/portal args and client screen * Switch --use args to --no * Don't build libei/libportal on older distros as it's pointless * Make libei and libportal optional * Add Debian 13 runner * Make some packages optional * Remove subprojects * Improve comment * Add comment for libportal * Improve comment * Add Debian 13 runner * Make optional... optional * Change continuation stripper to remove newline and continuation char * Make command strip more uniform * Fixed help var syntax * Fixed libei linking * Ensure `kHelpNoWayland` is always defined * Improve help message * Fixed Debian 13 runner name * Include sstream and use const var * Update ChangeLog * Remove Wayland block * Return new timer * Make tray icon logging verbose * Fixed arg parser for wayland args * Fixed init of EI screen * Fixed lint issues * Update README to indicate Wayland support in GNOME 46 * Add missing word * Fixed comment positions * Automate CI env * Tone down debug log messages * Add missing comma * Remove redundant log line
2024-08-30 14:53:25 +00:00
virtual EiEvents &forEi() = 0;
2012-06-10 16:50:54 +00:00
};