-
Notifications
You must be signed in to change notification settings - Fork 93
/
wallpaper_config.cpp
59 lines (53 loc) · 2.1 KB
/
wallpaper_config.cpp
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
/*
* Copyright © 2016-2020 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Alan Griffiths <alan@octopull.co.uk>
*/
#include "wallpaper_config.h"
#include <unistd.h>
#include <mutex>
namespace
{
auto default_font() -> std::string
{
for (std::string const file : { "Ubuntu-B.ttf", "FreeSansBold.ttf", "LiberationSans-Bold.ttf" })
{
for (auto const path : { "/usr/share/fonts/truetype/ubuntu-font-family/", // Ubuntu < 18.04 Ubuntu-B.ttf
"/usr/share/fonts/truetype/ubuntu/", // Ubuntu >= 18.04 Ubuntu-B.ttf
"/usr/share/fonts/truetype/freefont/", // Debian FreeSansBold.ttf
"/usr/share/fonts/gnu-free/", // Fedora FreeSansBold.ttf
"/usr/share/fonts/liberation-sans/", // Fedora LiberationSans-Bold.ttf
"/usr/share/fonts/TTF/"}) // Arch Ubuntu-B.ttf
{
auto const full_path = path + file;
if (access(full_path.c_str(), R_OK) == 0)
return full_path;
}
}
return "/usr/share/fonts/truetype/freefont/FreeSansBold.ttf";
}
std::mutex mutex;
std::string font_file{default_font()};
}
void wallpaper::font_file(std::string const& font_file)
{
std::lock_guard<decltype(mutex)> lock{mutex};
::font_file = font_file;
}
auto wallpaper::font_file() -> std::string
{
std::lock_guard<decltype(mutex)> lock{mutex};
return ::font_file;
}