-
Notifications
You must be signed in to change notification settings - Fork 2
/
simpleOSD.cpp
139 lines (126 loc) · 2.98 KB
/
simpleOSD.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <string>
#include <iostream>
#include <boost/lexical_cast.hpp>
#include "simpleOSD.hpp"
using std::string;
using std::cerr;
using std::endl;
using boost::lexical_cast;
xosd *osd = NULL;
void initialize(int v_offset, int h_offset, int h_align, int v_align, int timeout, string colour, string font)
{
osd = xosd_create(2);
int shadow_offset = 1;
int outline_offset = 0;
xosd_pos pos = XOSD_bottom;
xosd_align align = XOSD_center;
switch(h_align) {
case 0:
align = XOSD_left;
break;
case 1:
align = XOSD_center;
break;
case 2:
align = XOSD_right;
break;
}
switch(v_align) {
case 0:
pos = XOSD_top;
break;
case 1:
pos = XOSD_middle;
break;
case 2:
pos = XOSD_bottom;
break;
}
if (osd) {
if (xosd_set_font(osd, font.c_str()) == -1)
cerr << "invalid font " << font << endl;
xosd_set_colour(osd, colour.c_str());
if(timeout > 0)
xosd_set_timeout(osd, timeout);
xosd_set_shadow_offset(osd, shadow_offset);
xosd_set_outline_offset(osd, outline_offset);
xosd_set_pos(osd, pos);
xosd_set_align(osd, align);
xosd_set_vertical_offset(osd, v_offset);
xosd_set_horizontal_offset(osd, h_offset);
}
}
void printUsage() {
cerr << "Usage: simpleOSD [options] text" << endl;
cerr << "Options:" << endl;
cerr << "\t-v vertical alignment: 0 = top, 1 = middle, 2 = bottom" << endl;
cerr << "\t-h horizontal alignment: 0 = left, 1 = center, 2 = right" << endl;
cerr << "\t-l vertical offset" << endl;
cerr << "\t-b horizontal offset" << endl;
cerr << "\t-t timeout: 0 = forever" << endl;
cerr << "\t-f font string" << endl;
cerr << "\t-c color name" << endl << endl;
}
int main(int argc, char *argv[])
{
int c = 0;
int timeout = 0;
int v_offset = 0;
int h_offset = 50;
int h_align = 1;
int v_align = 2;
string colour = "white";
string font = "-misc-dejavu sans-*-*-*-*-17-*-*-*-*-*-*-*";
string text;
while (optind < argc) {
while ((c = getopt(argc, argv, "v:h:t:f:c:l:b:")) != -1) {
switch (c) {
case 'v':
v_align = lexical_cast<int>(optarg);
break;
case 'h':
h_align = lexical_cast<int>(optarg);
break;
case 't':
timeout = lexical_cast<int>(optarg);
break;
case 'f':
font = optarg;
break;
case 'c':
colour = optarg;
break;
case 'l':
v_offset = lexical_cast<int>(optarg);
break;
case 'b':
h_offset = lexical_cast<int>(optarg);
break;
case ':':
printUsage();
break;
case '?':
printUsage();
return 0;
break;
}
}
if (optind < argc) {
text = argv[optind++];
}
else {
printUsage();
return 0;
}
}
initialize(h_offset, v_offset, h_align,v_align,timeout,colour,font);
if (osd) {
xosd_display(osd, 1, XOSD_string, text.c_str());
xosd_wait_until_no_display (osd);
xosd_destroy(osd);
osd = NULL;
} else {
cerr << "Unable to initialize osd" << endl;
}
return 0;
}