The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
apps.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file apps.h
5 * @brief the programs of the desktop: the .app files.
6 *
7 * each program the launcher shows has a file /usr/share/applications/
8 * <id>.app in the settings format of libconf:
9 *
10 * [app]
11 * name = Window demo
12 * comment = A test of the window server
13 * exec = heimdemo 2
14 * icon = application-x-executable
15 * category = Development
16 *
17 * name and exec must be there. icon is a Tela icon name (the icon library
18 * gives "unknown" for a name it does not have). category is one of
19 * APP_CATEGORIES; another or no category is "Other". hidden = true keeps
20 * the program out of the launcher (it can still be found by its id).
21 *
22 * exec is split into words at spaces. a word in double quotes can have
23 * spaces in it. the first word is the program: a path, or a name in /bin.
24 */
25
26#include <stdbool.h>
27
28#define APPS_DIR "/usr/share/applications"
29
30// the categories, in the order the launcher shows them
31#define APP_CATEGORIES "Accessories", "Development", "Games", "Graphics", "Sound", "System", "Other"
32
33#define APP_ARGS_MAX 16
34
35typedef struct
36{
37 char *id; // the file name without .app
38 char *name; // "Window demo"
39 char *comment; // may be ""
40 char *exec; // "heimdemo 2"
41 char *icon; // "application-x-executable", may be ""
42 char *category; // one of APP_CATEGORIES
43 bool hidden;
44} app_t;
45
46typedef struct
47{
48 app_t *apps; // sorted by name (letter case is not looked at)
49 int count;
51
52/**
53 * read the .app files of a directory (APPS_DIR for the system ones). a
54 * file without a name or exec is skipped, with a warning on stderr.
55 * @return the list (empty if there is no directory), or NULL (no memory).
56 */
57app_list_t *apps_load(const char *dir);
58
59void apps_free(app_list_t *list);
60
61/**
62 * the program with this id.
63 * @return it, or NULL.
64 */
65const app_t *apps_find(const app_list_t *list, const char *id);
66
67/**
68 * split exec into words.
69 * @param buffer receives the words (it must hold strlen(exec) + 1 bytes).
70 * @param argv receives up to APP_ARGS_MAX words and a NULL.
71 * @return the number of words, or -1 (none, too many, or a quote that is
72 * not closed).
73 */
74int app_split_exec(const char *exec, char *buffer, char *argv[APP_ARGS_MAX + 1]);
int app_split_exec(const char *exec, char *buffer, char *argv[APP_ARGS_MAX+1])
split exec into words.
Definition apps.c:174
void apps_free(app_list_t *list)
Definition apps.c:35
app_list_t * apps_load(const char *dir)
read the .app files of a directory (APPS_DIR for the system ones).
Definition apps.c:111
const app_t * apps_find(const app_list_t *list, const char *id)
the program with this id.
Definition apps.c:162
#define APP_ARGS_MAX
Definition apps.h:33
bool, true and false.
Definition apps.h:47
int count
Definition apps.h:49
app_t * apps
Definition apps.h:48
Definition apps.h:36
char * category
Definition apps.h:42
bool hidden
Definition apps.h:43
char * exec
Definition apps.h:40
char * comment
Definition apps.h:39
char * name
Definition apps.h:38
char * icon
Definition apps.h:41
char * id
Definition apps.h:37
pid_t exec(const char *path, const char **argv)
execute a program, spawning a child process.