Class EventQueue
public abstract class EventQueue
Platform-level input event queue (singleton).
The concrete implementation is selected at startup by initInstance():
WinEventQueue on Windows, MacosEventQueue on macOS, and
LinuxEventQueue on all other Unix platforms.
org.viktor44.jtvision.platform.EventQueue
Summary
Constructors
| Visibility | Signature |
|---|---|
| protected | EventQueue() |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| private static | INSTANCE | org.viktor44.jtvision.platform.EventQueue |
| private final | eventQueue | concurrent.LinkedBlockingQueue<org.viktor44.jtvision.core.JtvEvent> |
| protected | inputThread | Thread |
| protected | readerThread | Thread |
| protected volatile | running | boolean |
| protected | rawTerminalEnabled | boolean |
| protected | lastMouse | org.viktor44.jtvision.core.MouseEvent |
| protected | lastClickTime | long |
| protected | clickCount | int |
| public | doubleDelay | int |
Methods
| Modifiers | Method signature | Return type |
|---|---|---|
| public static | initInstance() | void |
| static | initInstance(EventQueue instance) | void |
| public static | getInstance() | org.viktor44.jtvision.platform.EventQueue |
| protected abstract | init() | void |
| protected abstract | enableRawTerminalMode() | void |
| protected abstract | disableRawTerminalMode() | void |
| protected | beforeStopThreads(boolean forceClose) | void |
| protected | afterStopThreads() | void |
| public | shutdown() | void |
| public | waitForEvents(int timeoutMs) | void |
| public | getMouseEvent(JtvEvent event) | void |
| public | getKeyEvent(JtvEvent event) | org.viktor44.jtvision.core.JtvEvent |
| public | wakeUp() | void |
| public | suspend() | void |
| public | resume() | void |
| protected | stopInputThreads(boolean forceCloseInputStream) | void |
| private | joinThread(Thread thread) | void |
| private | peekEvent(int mask) | org.viktor44.jtvision.core.JtvEvent |
| protected | pushKeyEvent(int keyCode, int modifiers, char keyChar) | void |
| protected | pushPasteEvent(String text) | void |
| protected | offerEvent(JtvEvent event) | void |
| protected | toButtonMask(int sgrButton) | int |
Constructors
EventQueue()
No method description provided
Fields
org.viktor44.jtvision.platform.EventQueue INSTANCE
No description provided
concurrent.LinkedBlockingQueue<org.viktor44.jtvision.core.JtvEvent> eventQueue
No description provided
Thread inputThread
Event-decoding thread.
Thread readerThread
Raw-byte reader thread (Unix) or combined reader+decoder (Windows).
boolean running
true while the input threads are running.
boolean rawTerminalEnabled
true after raw terminal mode has been successfully enabled.
org.viktor44.jtvision.core.MouseEvent lastMouse
Mouse tracking state, shared by Unix SGR and Windows mouse handlers.
long lastClickTime
No description provided
int clickCount
No description provided
int doubleDelay
Maximum time between two mouse-down events (milliseconds) to qualify as a double-click. Defaults to 400 ms.
Methods
initInstance()
Initialises the singleton with the correct platform implementation. Must be called before getInstance().
initInstance(EventQueue instance)
Initialises the singleton with a custom instance, allowing tests to substitute alternative implementations.
Parameters
instance- the instance to use; must not benull
getInstance()
Returns the singleton EventQueue instance.
init()
Initialises the event queue and starts the input thread(s).
enableRawTerminalMode()
Enables raw terminal input mode so that keystrokes arrive immediately.
Unix: saves terminal settings and applies stty raw -echo.
Windows: saves and changes console mode flags via SetConsoleMode.
disableRawTerminalMode()
Restores the terminal to its pre-raw-mode state.
beforeStopThreads(boolean forceClose)
Called by stopInputThreads before threads are interrupted. Subclasses should close streams or signal conditions that unblock blocked reads.
Parameters
forceClose- whether to force-close any open stream
afterStopThreads()
Called by stopInputThreads after all threads have been joined. Subclasses should clear any intermediate byte queues here.
shutdown()
Shuts down the event queue and restores the terminal to its original state.
waitForEvents(int timeoutMs)
Waits for at least one event to become available, up to timeoutMs
milliseconds. Always flushes pending screen updates first.
Parameters
timeoutMs- maximum wait time in milliseconds
getMouseEvent(JtvEvent event)
Dequeues the next mouse event into event, or sets
event.what to evNothing if no mouse event is queued.
Coalesces consecutive evMouseMove events.
Parameters
event- the target event object to fill in
getKeyEvent(JtvEvent event)
Dequeues the next keyboard event into event, or sets
event.what to evNothing if no keyboard event is queued.
Parameters
event- the target event object to fill in
Returns
event for convenience
wakeUp()
No-op wake-up hint. Input threads run continuously.
suspend()
Suspends event processing and restores the terminal to cooked mode. Call resume() to re-initialise afterwards.
resume()
Re-initialises the event queue after a previous suspend().
stopInputThreads(boolean forceCloseInputStream)
Signals all input threads to stop, waits for them to finish, and clears thread references.
Parameters
forceCloseInputStream- passed to#beforeStopThreads
joinThread(Thread thread)
No method description provided
Parameters
thread
peekEvent(int mask)
No method description provided
Parameters
mask
pushKeyEvent(int keyCode, int modifiers, char keyChar)
Constructs an evKeyDown event and places it in the queue.
Parameters
keyCode- AWT virtual-key codemodifiers- AWT modifier maskkeyChar- Unicode character, orjava.awt.event.KeyEvent#CHAR_UNDEFINED
pushPasteEvent(String text)
Constructs an evPaste event carrying the pasted text and
places it in the queue. Used by the bracketed-paste handler.
Parameters
text- the clipboard text delivered by the terminal
offerEvent(JtvEvent event)
Places a pre-constructed event in the event queue.
Parameters
event- the event to enqueue
toButtonMask(int sgrButton)
Converts an SGR mouse button index to the JT Vision button-mask constant.
Parameters
sgrButton- SGR button index (0=left, 1=middle, 2=right)
Returns
mbLeftButton, mbMiddleButton, mbRightButton, or 0