-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
85 lines (59 loc) · 2.47 KB
/
main.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
#include <iostream>
#include <unistd.h>
#include <gtk/gtk.h>
#include <string>
// Modules
#include "modules/CssManager.h"
#include "modules/MixerManager.h"
// Images
#include "images/images.h"
#include "style.hex"
const char *homeDir = getenv("HOME");
using namespace std;
GtkWidget *volume_bar;
MixerManager mixerManager;
void on_window_closed() {
gtk_main_quit();
}
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
// Установка временной локали "C" для использования точки в качестве разделителя
setlocale(LC_NUMERIC, "C");
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Volume");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
g_signal_connect(window, "destroy", G_CALLBACK(on_window_closed), NULL);
GtkWidget *box1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
GdkPixbuf *image_pixbuf = gdk_pixbuf_new_from_data(*imageData_volume, GDK_COLORSPACE_RGB, TRUE, 8, IMAGE_WIDTH - 50, IMAGE_HEIGHT, 3 * IMAGE_HEIGHT, NULL, NULL);
GdkPixbuf *resized_pixbuf = gdk_pixbuf_scale_simple(image_pixbuf, 90, 90, GDK_INTERP_BILINEAR);
GtkWidget *image = gtk_image_new_from_pixbuf(resized_pixbuf);
volume_bar = gtk_level_bar_new_for_interval(0.0, 1.0);
if (argc >= 3) {
string option1 = argv[1];
string option2 = argv[2];
if (option1 == "increase") {
mixerManager.increase_volume(stof(option2));
gtk_level_bar_set_value(GTK_LEVEL_BAR(volume_bar), mixerManager.get_volume());
} else if (option1 == "decrease") {
mixerManager.decrease_volume(stof(option2));
gtk_level_bar_set_value(GTK_LEVEL_BAR(volume_bar), mixerManager.get_volume());
} else {
}
} else {
cerr << "2 arguments are required" << endl;
return 1;
}
gtk_box_pack_start(GTK_BOX(box1), image, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box1), volume_bar, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), box1);
//CSS
CssManager cssManager;
string path = string(homeDir) + "/.config/mixerdialog/style.css";
cssManager.loadFromHex(style_css, style_css_len);
cssManager.loadFromFile(path.c_str());
gtk_widget_show_all(window);
g_timeout_add(500, GSourceFunc(on_window_closed), NULL);
gtk_main();
return 0;
}