-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrw.hpp
102 lines (78 loc) · 2.27 KB
/
drw.hpp
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
91
92
93
94
95
96
97
98
99
100
101
102
/* See LICENSE file for copyright and license details. */
#pragma once
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <memory>
#include <optional>
#include <string_view>
#include <vector>
class CursorFont {
public:
CursorFont(Display*, int shape);
CursorFont(CursorFont&&);
~CursorFont();
Cursor getXCursor() const;
private:
Display* fDisplay;
std::optional<Cursor> fCursor;
};
struct ColorScheme {
std::string foreground;
std::string background;
std::string border;
};
struct XColorScheme {
XColorScheme(Display*, int screen, const ColorScheme&);
XftColor foreground;
XftColor background;
XftColor border;
};
template <typename Scheme> struct Theme {
Scheme normal;
Scheme selected;
};
class DisplayFont {
public:
DisplayFont(Display*, int screen, const char* fontName);
DisplayFont(Display*, FcPattern*);
DisplayFont(DisplayFont&&);
~DisplayFont();
bool doesCodepointExistInFont(long utf8Codepoint) const;
std::optional<DisplayFont>
generateDerivedFontWithCodepoint(int screen, long utf8Codepoint) const;
uint getHeight() const;
uint getTextExtent(std::string_view) const;
XftFont* getXFont() const;
private:
void dieIfFontIsColored() const;
Display* fDisplay;
XftFont* fXfont;
FcPattern* fPattern;
};
class Drw {
public:
Drw(Display* dpy, int screen, Window win, uint w, uint h);
~Drw();
void resize(uint w, uint h);
const std::vector<DisplayFont>&
createFontSet(const std::vector<std::string>& fontNames);
uint getPrimaryFontHeight() const;
const std::vector<DisplayFont>& getFontset() const;
Theme<XColorScheme> parseTheme(const Theme<ColorScheme>&) const;
void setScheme(const XColorScheme&);
int getTextWidth(std::string_view);
void renderRect(int x, int y, uint w, uint h, bool filled,
bool invert) const;
int renderText(int x, int y, uint w, uint h, uint lpad, std::string_view,
bool invert);
void map(Window win, int x, int y, uint w, uint h) const;
private:
uint fWidth, fHeight;
Display* fDisplay;
int fScreen;
Window fRoot;
Drawable fDrawable;
GC fGC;
std::optional<XColorScheme> fScheme;
std::vector<DisplayFont> fFonts;
};