The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
heimdall.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file heimdall.h
5 * @brief libheimdall: windows on the ginnOS desktop (the heimdalld client).
6 *
7 * a program connects, makes windows, draws into their buffers with libgfx,
8 * commits what changed, and gets events:
9 *
10 * heim_conn_t *conn = heim_connect();
11 * heim_window_t *win = heim_window_new(conn, 400, 300, "Hello", 0);
12 * gfx_fill_rect(heim_window_buffer(win), gfx_rect(0, 0, 400, 300), color);
13 * heim_window_commit(win, gfx_rect(0, 0, 400, 300));
14 * heim_event_t ev;
15 * while (heim_next_event(conn, &ev, -1) > 0)
16 * if (ev.type == HEIM_EV_CLOSE)
17 * break;
18 *
19 * the protocol is in heimdall_proto.h.
20 */
21
22#include <gfx.h>
23#include <heimdall_proto.h>
24#include <stdbool.h>
25#include <stddef.h>
26#include <stdint.h>
27
28typedef struct heim_conn heim_conn_t;
29typedef struct heim_window heim_window_t;
30
31typedef struct
32{
33 uint16_t type; // HEIM_EV_
34 heim_window_t *window; // the window it is about, or NULL
35 heim_msg_t msg; // the fields (msg.key, msg.pointer, ...)
36 char *clipboard; // HEIM_EV_CLIPBOARD: the text, zero-terminated (or NULL);
37 // valid until the next heim_next_event
40
41/**
42 * connect to the window server.
43 * @return the connection, or NULL (no server: errno is set).
44 */
46
47/**
48 * close the connection. its windows go away (free them first, or not).
49 */
51
52/**
53 * the connection's socket, to wait for events with poll() together with
54 * other files. POLLIN on it: call heim_next_event.
55 */
56int heim_fd(const heim_conn_t *conn);
57
58/**
59 * true if a whole message is already read from the socket: the next
60 * heim_next_event returns at once. a loop that polls heim_fd with other
61 * fds checks this first.
62 */
63bool heim_pending(const heim_conn_t *conn);
64
65void heim_screen_size(const heim_conn_t *conn, int32_t *width, int32_t *height);
66
67/**
68 * the next event.
69 * @param timeout_ms how long to wait: -1 for as long as it takes, 0 not at all.
70 * @return 1 with an event, 0 when the time ran out, -1 when the server is
71 * gone.
72 */
73int heim_next_event(heim_conn_t *conn, heim_event_t *event, int timeout_ms);
74
75/**
76 * make a window with a buffer of that size (its content, without the
77 * title bar). it shows after the first heim_window_commit.
78 * @param flags HEIM_WINDOW_RESIZABLE, HEIM_WINDOW_ALPHA, HEIM_WINDOW_UNDECORATED.
79 */
81 const char *title, uint32_t flags);
82
83/**
84 * make a popup of parent (a menu, a popover; with HEIM_WINDOW_TOOLTIP a
85 * tooltip). place it with heim_window_place before its first commit.
86 */
89
90/**
91 * where a popup goes: next to the rect r of its parent's content, on a
92 * side (HEIM_SIDE_). margin: the shadow around its card in its buffer.
93 */
94void heim_window_place(heim_window_t *popup, gfx_rect_t r, uint32_t side, int32_t margin);
95
97
98/**
99 * the buffer to draw into. after heim_window_resize it is another one.
100 */
102
103/**
104 * a new buffer of another size (its pixels are transparent). the old
105 * content stays on the screen until the next commit. for HEIM_EV_CONFIGURE,
106 * or when the program wants another size.
107 * @return false when out of memory (the old buffer stays).
108 */
109bool heim_window_resize(heim_window_t *win, int32_t width, int32_t height);
110
111/**
112 * show a changed part of the buffer.
113 */
115
116/**
117 * true from a commit until its HEIM_EV_FRAME: drawing then can be seen
118 * half done. an animation draws its next frame when this is false.
119 */
120bool heim_window_busy(const heim_window_t *win);
121
122void heim_window_set_title(heim_window_t *win, const char *title);
123
124/**
125 * the pointer shape over the window's content (HEIM_CURSOR_).
126 */
128
129/**
130 * a pointer of the program's own for the window (NULL at first).
131 */
132void heim_window_set_data(heim_window_t *win, void *data);
133void *heim_window_data(const heim_window_t *win);
134
135/**
136 * put text on the clipboard (length 0 empties it).
137 */
138void heim_clipboard_set(heim_conn_t *conn, const char *text, size_t length);
139
140/**
141 * ask for the clipboard's text: it comes as a HEIM_EV_CLIPBOARD event.
142 */
144
145/**
146 * tell all clients that the settings file name changed (after conf_save):
147 * each gets a HEIM_EV_SETTINGS event with the name, also this one.
148 * @param name the libconf name, "theme".
149 */
150void heim_settings_changed(heim_conn_t *conn, const char *name);
151
152/**
153 * name the program of a window, so the shell can show its icon (the id of
154 * its .app file: "idunn-gallery").
155 */
156void heim_window_set_app(heim_window_t *win, const char *app);
157
158/**
159 * be the desktop shell: from now on HEIM_EV_WINDOW, HEIM_EV_WINDOW_APP
160 * and HEIM_EV_WINDOW_GONE tell about every normal window (the event's
161 * window is NULL; msg.info.id names the window). only the first client
162 * that asks is the shell.
163 */
164void heim_shell_start(heim_conn_t *conn);
165
166/**
167 * the shell does something to a window.
168 * @param id msg.info.id of the window.
169 * @param action HEIM_ACT_ACTIVATE, HEIM_ACT_MINIMIZE or HEIM_ACT_CLOSE.
170 */
171void heim_shell_act(heim_conn_t *conn, uint32_t id, uint32_t action);
172
173/**
174 * the shell ends the session: heimdalld stops and the text console comes
175 * back.
176 */
177void heim_shell_quit(heim_conn_t *conn);
libgfx: drawing into pixel buffers in memory.
void heim_window_set_cursor(heim_window_t *win, uint32_t shape)
the pointer shape over the window's content (HEIM_CURSOR_).
Definition heimdall.c:479
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.
Definition heimdall.c:464
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.
Definition heimdall.c:227
gfx_buffer_t * heim_window_buffer(heim_window_t *win)
the buffer to draw into.
Definition heimdall.c:444
void heim_window_free(heim_window_t *win)
Definition heimdall.c:423
void heim_screen_size(const heim_conn_t *conn, int32_t *width, int32_t *height)
Definition heimdall.c:322
void heim_disconnect(heim_conn_t *conn)
close the connection.
Definition heimdall.c:298
void heim_window_set_title(heim_window_t *win, const char *title)
Definition heimdall.c:469
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 ...
Definition heimdall.c:533
int heim_fd(const heim_conn_t *conn)
the connection's socket, to wait for events with poll() together with other files.
Definition heimdall.c:317
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...
Definition heimdall.c:542
void heim_window_set_data(heim_window_t *win, void *data)
a pointer of the program's own for the window (NULL at first).
Definition heimdall.c:489
void heim_shell_quit(heim_conn_t *conn)
the shell ends the session: heimdalld stops and the text console comes back.
Definition heimdall.c:570
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).
Definition heimdall.c:401
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).
Definition heimdall.c:395
void heim_clipboard_request(heim_conn_t *conn)
ask for the clipboard's text: it comes as a HEIM_EV_CLIPBOARD event.
Definition heimdall.c:525
void * heim_window_data(const heim_window_t *win)
Definition heimdall.c:494
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_).
Definition heimdall.c:408
heim_conn_t * heim_connect(void)
connect to the window server.
Definition heimdall.c:255
bool heim_window_resize(heim_window_t *win, int32_t width, int32_t height)
a new buffer of another size (its pixels are transparent).
Definition heimdall.c:328
void heim_clipboard_set(heim_conn_t *conn, const char *text, size_t length)
put text on the clipboard (length 0 empties it).
Definition heimdall.c:499
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 abo...
Definition heimdall.c:552
void heim_shell_act(heim_conn_t *conn, uint32_t id, uint32_t action)
the shell does something to a window.
Definition heimdall.c:560
void heim_window_commit(heim_window_t *win, gfx_rect_t damage)
show a changed part of the buffer.
Definition heimdall.c:449
int heim_next_event(heim_conn_t *conn, heim_event_t *event, int timeout_ms)
the next event.
Definition heimdall.c:232
struct heim_window heim_window_t
Definition heimdall.h:29
struct heim_conn heim_conn_t
Definition heimdall.h:28
the messages between heimdalld (the window server) and its clients.
uint8_t flags
Definition idt.c:3
unsigned int uint32_t
Definition fb.h:17
NULL, size_t, ptrdiff_t, offsetof.
integer types of fixed width.
unsigned short uint16_t
Definition stdint.h:13
int int32_t
Definition stdint.h:14
bool, true and false.
Definition gfx.h:41
Definition gfx.h:33
Definition heimdall.h:32
char * clipboard
Definition heimdall.h:36
heim_msg_t msg
Definition heimdall.h:35
size_t clipboard_length
Definition heimdall.h:38
heim_window_t * window
Definition heimdall.h:34
uint16_t type
Definition heimdall.h:33
Definition heimdall_proto.h:149