The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
heimdall.c File Reference

libheimdall: the client side of the heimdalld protocol. More...

#include "heimdall.h"
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

Macros

#define MSG_SIZE   ((int)sizeof(heim_msg_t))
#define IN_BUFFER   (MSG_SIZE * 32)
#define FD_QUEUE   8

Functions

bool heim_pending (const heim_conn_t *conn)
 true if a whole message is already read from the socket: the next heim_next_event returns at once.
int heim_next_event (heim_conn_t *conn, heim_event_t *event, int timeout_ms)
 the next event.
heim_conn_t * heim_connect (void)
 connect to the window server.
void heim_disconnect (heim_conn_t *conn)
 close the connection.
int heim_fd (const heim_conn_t *conn)
 the connection's socket, to wait for events with poll() together with other files.
void heim_screen_size (const heim_conn_t *conn, int32_t *width, int32_t *height)
bool heim_window_resize (heim_window_t *win, int32_t width, int32_t height)
 a new buffer of another size (its pixels are transparent).
heim_window_t * heim_window_new (heim_conn_t *conn, int32_t width, int32_t height, const char *title, uint32_t flags)
 make a window with a buffer of that size (its content, without the title bar).
heim_window_t * heim_popup_new (heim_window_t *parent, int32_t width, int32_t height, uint32_t flags)
 make a popup of parent (a menu, a popover; with HEIM_WINDOW_TOOLTIP a tooltip).
void heim_window_place (heim_window_t *popup, gfx_rect_t r, uint32_t side, int32_t margin)
 where a popup goes: next to the rect r of its parent's content, on a side (HEIM_SIDE_).
void heim_window_free (heim_window_t *win)
gfx_buffer_t * heim_window_buffer (heim_window_t *win)
 the buffer to draw into.
void heim_window_commit (heim_window_t *win, gfx_rect_t damage)
 show a changed part of the buffer.
bool heim_window_busy (const heim_window_t *win)
 true from a commit until its HEIM_EV_FRAME: drawing then can be seen half done.
void heim_window_set_title (heim_window_t *win, const char *title)
void heim_window_set_cursor (heim_window_t *win, uint32_t shape)
 the pointer shape over the window's content (HEIM_CURSOR_).
void heim_window_set_data (heim_window_t *win, void *data)
 a pointer of the program's own for the window (NULL at first).
void * heim_window_data (const heim_window_t *win)
void heim_clipboard_set (heim_conn_t *conn, const char *text, size_t length)
 put text on the clipboard (length 0 empties it).
void heim_clipboard_request (heim_conn_t *conn)
 ask for the clipboard's text: it comes as a HEIM_EV_CLIPBOARD event.
void heim_settings_changed (heim_conn_t *conn, const char *name)
 tell all clients that the settings file name changed (after conf_save): each gets a HEIM_EV_SETTINGS event with the name, also this one.
void heim_window_set_app (heim_window_t *win, const char *app)
 name the program of a window, so the shell can show its icon (the id of its .app file: "idunn-gallery").
void heim_shell_start (heim_conn_t *conn)
 be the desktop shell: from now on HEIM_EV_WINDOW, HEIM_EV_WINDOW_APP and HEIM_EV_WINDOW_GONE tell about every normal window (the event's window is NULL; msg.info.id names the window).
void heim_shell_act (heim_conn_t *conn, uint32_t id, uint32_t action)
 the shell does something to a window.
void heim_shell_quit (heim_conn_t *conn)
 the shell ends the session: heimdalld stops and the text console comes back.

Detailed Description

libheimdall: the client side of the heimdalld protocol.

the socket is blocking for sends (64-byte messages, which the server reads quickly) and polled for receives. files that come with messages are kept in a queue until the message that uses them is read.

Macro Definition Documentation

◆ MSG_SIZE

#define MSG_SIZE   ((int)sizeof(heim_msg_t))

◆ IN_BUFFER

#define IN_BUFFER   (MSG_SIZE * 32)

◆ FD_QUEUE

#define FD_QUEUE   8

Function Documentation

◆ heim_pending()

bool heim_pending ( const heim_conn_t * conn)

true if a whole message is already read from the socket: the next heim_next_event returns at once.

a loop that polls heim_fd with other fds checks this first.

◆ heim_next_event()

int heim_next_event ( heim_conn_t * conn,
heim_event_t * event,
int timeout_ms )

the next event.

Parameters
timeout_mshow long to wait: -1 for as long as it takes, 0 not at all.
Returns
1 with an event, 0 when the time ran out, -1 when the server is gone.

◆ heim_connect()

heim_conn_t * heim_connect ( void )

connect to the window server.

Returns
the connection, or NULL (no server: errno is set).

◆ heim_disconnect()

void heim_disconnect ( heim_conn_t * conn)

close the connection.

its windows go away (free them first, or not).

◆ heim_fd()

int heim_fd ( const heim_conn_t * conn)

the connection's socket, to wait for events with poll() together with other files.

POLLIN on it: call heim_next_event.

◆ heim_screen_size()

void heim_screen_size ( const heim_conn_t * conn,
int32_t * width,
int32_t * height )

◆ heim_window_resize()

bool heim_window_resize ( heim_window_t * win,
int32_t width,
int32_t height )

a new buffer of another size (its pixels are transparent).

the old content stays on the screen until the next commit. for HEIM_EV_CONFIGURE, or when the program wants another size.

Returns
false when out of memory (the old buffer stays).

◆ heim_window_new()

heim_window_t * heim_window_new ( heim_conn_t * conn,
int32_t width,
int32_t height,
const char * title,
uint32_t flags )

make a window with a buffer of that size (its content, without the title bar).

it shows after the first heim_window_commit.

Parameters
flagsHEIM_WINDOW_RESIZABLE, HEIM_WINDOW_ALPHA, HEIM_WINDOW_UNDECORATED.

◆ heim_popup_new()

heim_window_t * heim_popup_new ( heim_window_t * parent,
int32_t width,
int32_t height,
uint32_t flags )

make a popup of parent (a menu, a popover; with HEIM_WINDOW_TOOLTIP a tooltip).

place it with heim_window_place before its first commit.

◆ heim_window_place()

void heim_window_place ( heim_window_t * popup,
gfx_rect_t r,
uint32_t side,
int32_t margin )

where a popup goes: next to the rect r of its parent's content, on a side (HEIM_SIDE_).

margin: the shadow around its card in its buffer.

◆ heim_window_free()

void heim_window_free ( heim_window_t * win)

◆ heim_window_buffer()

gfx_buffer_t * heim_window_buffer ( heim_window_t * win)

the buffer to draw into.

after heim_window_resize it is another one.

◆ heim_window_commit()

void heim_window_commit ( heim_window_t * win,
gfx_rect_t damage )

show a changed part of the buffer.

◆ heim_window_busy()

bool heim_window_busy ( const heim_window_t * win)

true from a commit until its HEIM_EV_FRAME: drawing then can be seen half done.

an animation draws its next frame when this is false.

◆ heim_window_set_title()

void heim_window_set_title ( heim_window_t * win,
const char * title )

◆ heim_window_set_cursor()

void heim_window_set_cursor ( heim_window_t * win,
uint32_t shape )

the pointer shape over the window's content (HEIM_CURSOR_).

◆ heim_window_set_data()

void heim_window_set_data ( heim_window_t * win,
void * data )

a pointer of the program's own for the window (NULL at first).

◆ heim_window_data()

void * heim_window_data ( const heim_window_t * win)

◆ heim_clipboard_set()

void heim_clipboard_set ( heim_conn_t * conn,
const char * text,
size_t length )

put text on the clipboard (length 0 empties it).

◆ heim_clipboard_request()

void heim_clipboard_request ( heim_conn_t * conn)

ask for the clipboard's text: it comes as a HEIM_EV_CLIPBOARD event.

◆ heim_settings_changed()

void heim_settings_changed ( heim_conn_t * conn,
const char * name )

tell all clients that the settings file name changed (after conf_save): each gets a HEIM_EV_SETTINGS event with the name, also this one.

Parameters
namethe libconf name, "theme".

◆ heim_window_set_app()

void heim_window_set_app ( heim_window_t * win,
const char * app )

name the program of a window, so the shell can show its icon (the id of its .app file: "idunn-gallery").

◆ heim_shell_start()

void heim_shell_start ( heim_conn_t * conn)

be the desktop shell: from now on HEIM_EV_WINDOW, HEIM_EV_WINDOW_APP and HEIM_EV_WINDOW_GONE tell about every normal window (the event's window is NULL; msg.info.id names the window).

only the first client that asks is the shell.

◆ heim_shell_act()

void heim_shell_act ( heim_conn_t * conn,
uint32_t id,
uint32_t action )

the shell does something to a window.

Parameters
idmsg.info.id of the window.
actionHEIM_ACT_ACTIVATE, HEIM_ACT_MINIMIZE or HEIM_ACT_CLOSE.

◆ heim_shell_quit()

void heim_shell_quit ( heim_conn_t * conn)

the shell ends the session: heimdalld stops and the text console comes back.