Termux:GUI C/C++ Bindings
Loading...
Searching...
No Matches
connection.h File Reference

This file contains all functions related to the connection object, as well as global methods requiring no Activities. More...

#include "types.h"

Go to the source code of this file.

Functions

tgui_err tgui_to_termux ()
 Brings Termux to the foreground. More...
 
tgui_err tgui_connection_create (tgui_connection *c)
 Creates a connection to the Termux:GUI plugin. Waits up to 6 seconds for the plugin to connect. More...
 
tgui_err tgui_get_version (tgui_connection c, int *v)
 Gets the version code of the plugin app. Can be used to disable features not supported by the plugin version. More...
 
tgui_err tgui_set_log_level (tgui_connection c, int level)
 Sets the log level of the plugin. Can be used for debugging. More...
 
tgui_err tgui_get_log (tgui_connection c, bool clear, char **log)
 Gets the log of the plugin. Can be used for debugging. More...
 
tgui_err tgui_toast (tgui_connection c, const char *text, bool l)
 Sends a toast using the connection. More...
 
tgui_err tgui_turn_screen_on (tgui_connection c)
 Turns the screen on. More...
 
tgui_err tgui_is_locked (tgui_connection c, bool *locked)
 Checks whether the screen is locked. More...
 
tgui_err tgui_request_unlock (tgui_connection c, tgui_activity a)
 Requests a lockscreen unlock. When the lockscreen isn't protected, unlocks it. When the lockscreen is protected, brings up the UI for the user to unlock it. More...
 
tgui_err tgui_wait_event (tgui_connection c, tgui_event *event)
 Waits for an event from the plugin and returns it. Events have to be destroyed with tgui_event_destroy. More...
 
tgui_err tgui_poll_event (tgui_connection c, tgui_event *event, bool *available)
 Returns an event from the plugin if one is available without blocking. Events have to be destroyed with tgui_event_destroy. More...
 
void tgui_event_destroy (tgui_event *event)
 Frees the memory of an event. Some events fill the union with pointers to dynamic memory, which have to be freed. More...
 
void tgui_connection_destroy (tgui_connection c)
 Closes a connection and frees the resources (all objects created with the connection still have to be destroyed). All open Activities will be closed by the plugin automatically. More...
 

Detailed Description

This file contains all functions related to the connection object, as well as global methods requiring no Activities.

Function Documentation

◆ tgui_to_termux()

tgui_err tgui_to_termux ( )

Brings Termux to the foreground.

Errors

  • TGUI_ERR_SYSTEM: am executable not found.
  • TGUI_ERR_CONNECTION_LOST: The timeout was exceeded.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Returns
The error code.

◆ tgui_connection_create()

tgui_err tgui_connection_create ( tgui_connection c)

Creates a connection to the Termux:GUI plugin. Waits up to 6 seconds for the plugin to connect.

Errors

  • TGUI_ERR_SYSTEM: The socket creation failed.
  • TGUI_ERR_CONNECTION_LOST: The timeout was exceeded.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
[out]cThe newly created connection, if no error occurred.
Returns
The error code.

◆ tgui_get_version()

tgui_err tgui_get_version ( tgui_connection  c,
int *  v 
)

Gets the version code of the plugin app. Can be used to disable features not supported by the plugin version.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
[out]vThe version code
Returns
The error code.

◆ tgui_set_log_level()

tgui_err tgui_set_log_level ( tgui_connection  c,
int  level 
)

Sets the log level of the plugin. Can be used for debugging.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
levelThe requested log level, from 0 to 10 (inclusive).
Returns
The error code.

◆ tgui_get_log()

tgui_err tgui_get_log ( tgui_connection  c,
bool  clear,
char **  log 
)

Gets the log of the plugin. Can be used for debugging.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
clearSet to true if you want to clear the log after getting it.
[out]logGets set to a pointer to the retrieved log buffer if successful. Has to be freed with free().
Returns
The error code.

◆ tgui_toast()

tgui_err tgui_toast ( tgui_connection  c,
const char *  text,
bool  l 
)

Sends a toast using the connection.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
[in]textThe text to display.
ltrue if the toast should be displayed for a long time, false for a short time.
Returns
The error code.

◆ tgui_turn_screen_on()

tgui_err tgui_turn_screen_on ( tgui_connection  c)

Turns the screen on.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
Returns
The error code.

◆ tgui_is_locked()

tgui_err tgui_is_locked ( tgui_connection  c,
bool *  locked 
)

Checks whether the screen is locked.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
[out]lockedA pointer where the status should be put.
Returns
The error code.

◆ tgui_request_unlock()

tgui_err tgui_request_unlock ( tgui_connection  c,
tgui_activity  a 
)

Requests a lockscreen unlock. When the lockscreen isn't protected, unlocks it. When the lockscreen is protected, brings up the UI for the user to unlock it.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
aThe Activity that wants to unlock the screen.
Returns
The error code.

◆ tgui_wait_event()

tgui_err tgui_wait_event ( tgui_connection  c,
tgui_event event 
)

Waits for an event from the plugin and returns it. Events have to be destroyed with tgui_event_destroy.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
[out]eventThe event from the plugin.
Returns
The error code.

◆ tgui_poll_event()

tgui_err tgui_poll_event ( tgui_connection  c,
tgui_event event,
bool *  available 
)

Returns an event from the plugin if one is available without blocking. Events have to be destroyed with tgui_event_destroy.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to use.
[out]eventThe event from the plugin.
[out]availableSet to true if an event was available. If false, event is invalid and doesn't need to be destroyed.
Returns
The error code.

◆ tgui_event_destroy()

void tgui_event_destroy ( tgui_event event)

Frees the memory of an event. Some events fill the union with pointers to dynamic memory, which have to be freed.

Parameters
eventThe event to free.

◆ tgui_connection_destroy()

void tgui_connection_destroy ( tgui_connection  c)

Closes a connection and frees the resources (all objects created with the connection still have to be destroyed). All open Activities will be closed by the plugin automatically.

Errors

  • TGUI_ERR_MESSAGE: Protobuf I/O error.
  • TGUI_ERR_NOMEM: Not enough memory.
  • TGUI_ERR_EXCEPTION: Generic exception triggered.
Parameters
cThe connection to close.