forked from tom-wa/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktop.c
91 lines (78 loc) · 2.71 KB
/
desktop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @file
*
* @brief Source for desktop plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include "desktop.h"
#include <ctype.h> // for tolower
#include <stdlib.h> // for getenv
#include <strings.h> // for strcasecmp
#include <kdberrors.h>
#include <kdbhelper.h>
#include <kdblogger.h>
#include <kdbmacros.h>
int elektraDesktopGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
{
ELEKTRA_LOG ("get desktop %s from %s\n", keyName (parentKey), keyString (parentKey));
if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/desktop"))
{
KeySet * contract =
ksNew (30, keyNew ("system/elektra/modules/desktop", KEY_VALUE, "desktop plugin waits for your orders", KEY_END),
keyNew ("system/elektra/modules/desktop/exports", KEY_END),
keyNew ("system/elektra/modules/desktop/exports/get", KEY_FUNC, elektraDesktopGet, KEY_END),
keyNew ("system/elektra/modules/desktop/exports/set", KEY_FUNC, elektraDesktopSet, KEY_END),
#include ELEKTRA_README (desktop)
keyNew ("system/elektra/modules/desktop/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
ksAppend (returned, contract);
ksDel (contract);
return 1; // success
}
const char * desktop;
// get key
if (getenv ("GNOME_DESKTOP_SESSION_ID"))
{
ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "gnome", KEY_END));
}
else if (getenv ("KDE_FULL_SESSION"))
{
ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "kde", KEY_END));
}
else if (getenv ("TDE_FULL_SESSION"))
{
ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "tde", KEY_END));
}
else if ((desktop = getenv ("DESKTOP_SESSION")) && !strcasecmp (desktop, "unity"))
{
ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "unity", KEY_END));
}
else if ((desktop = getenv ("XDG_CURRENT_DESKTOP")))
{
char * str = elektraStrDup (desktop);
for (int i = 0; str[i]; i++)
{
str[i] = tolower (str[i]);
}
ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, str, KEY_END));
elektraFree (str);
}
return 1; // success
}
int elektraDesktopSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
{
ELEKTRA_LOG ("set desktop %s from %s\n", keyName (parentKey), keyString (parentKey));
KeySet * info = ksNew (0, KS_END);
elektraDesktopGet (handle, info, parentKey);
ELEKTRA_SET_ERROR_READ_ONLY (info, returned, parentKey);
return 0;
}
Plugin * ELEKTRA_PLUGIN_EXPORT (desktop)
{
// clang-format off
return elektraPluginExport ("desktop",
ELEKTRA_PLUGIN_GET, &elektraDesktopGet,
ELEKTRA_PLUGIN_SET, &elektraDesktopSet,
ELEKTRA_PLUGIN_END);
}