16
16
#include " on_event.h"
17
17
#include " bar.h"
18
18
19
- RGBA background = {0.0 , 0.0 , 0.0 , 0.9 };
20
19
std::string wm {" " }; // detected or forced window manager name
21
20
const char * const HELP_MESSAGE =
22
21
" GTK button bar: nwgbar " VERSION_STR " (c) Piotr Miller & Contributors 2020\n\n \
@@ -88,24 +87,7 @@ int main(int argc, char *argv[]) {
88
87
wm = wm_name;
89
88
}
90
89
91
- auto opa = input.getCmdOption (" -o" );
92
- if (!opa.empty ()){
93
- try {
94
- auto o = std::stod (std::string{opa});
95
- if (o >= 0.0 && o <= 1.0 ) {
96
- background.alpha = o;
97
- } else {
98
- std::cerr << " \n ERROR: Opacity must be in range 0.0 to 1.0\n\n " ;
99
- }
100
- } catch (...) {
101
- std::cerr << " \n ERROR: Invalid opacity value\n\n " ;
102
- }
103
- }
104
-
105
- std::string_view bcg = input.getCmdOption (" -b" );
106
- if (!bcg.empty ()) {
107
- set_background (bcg);
108
- }
90
+ auto background_color = input.get_background_color (0.9 );
109
91
110
92
auto i_size = input.getCmdOption (" -s" );
111
93
if (!i_size.empty ()) {
@@ -124,16 +106,16 @@ int main(int argc, char *argv[]) {
124
106
}
125
107
}
126
108
127
- std::string config_dir = get_config_dir (" nwgbar" );
109
+ auto config_dir = get_config_dir (" nwgbar" );
128
110
if (!fs::is_directory (config_dir)) {
129
111
std::cout << " Config dir not found, creating...\n " ;
130
112
fs::create_directories (config_dir);
131
113
}
132
114
133
115
// default and custom style sheet
134
- std::string default_css_file = config_dir + " / style.css" ;
116
+ auto default_css_file = config_dir / " style.css" ;
135
117
// css file to be used
136
- std::string css_file = config_dir + " / " + custom_css_file;
118
+ auto css_file = config_dir / custom_css_file;
137
119
// copy default file if not found
138
120
if (!fs::exists (default_css_file)) {
139
121
try {
@@ -144,8 +126,8 @@ int main(int argc, char *argv[]) {
144
126
}
145
127
146
128
// default or custom template
147
- std::string default_bar_file = config_dir + " / bar.json" ;
148
- std::string custom_bar_file = config_dir + " / " + definition_file;
129
+ auto default_bar_file = config_dir / " bar.json" ;
130
+ auto custom_bar_file = config_dir / definition_file;
149
131
// copy default anyway if not found
150
132
if (!fs::exists (default_bar_file)) {
151
133
try {
@@ -155,12 +137,12 @@ int main(int argc, char *argv[]) {
155
137
}
156
138
}
157
139
158
- ns::json bar_json {} ;
140
+ ns::json bar_json;
159
141
try {
160
- bar_json = get_bar_json ( std::move ( custom_bar_file) );
142
+ bar_json = json_from_file ( custom_bar_file);
161
143
} catch (...) {
162
- std::cerr << " \n ERROR : Template file not found, using default\n " ;
163
- bar_json = get_bar_json (default_bar_file);
144
+ std::cerr << " ERROR : Template file not found, using default\n " ;
145
+ bar_json = json_from_file (default_bar_file);
164
146
}
165
147
std::cout << bar_json.size () << " bar entries loaded\n " ;
166
148
@@ -210,6 +192,7 @@ int main(int argc, char *argv[]) {
210
192
}
211
193
212
194
MainWindow window;
195
+ window.set_background_color (background_color);
213
196
window.show ();
214
197
215
198
window.signal_button_press_event ().connect (sigc::ptr_fun (&on_window_clicked));
0 commit comments