-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
105 lines (92 loc) · 2.76 KB
/
window.cpp
File metadata and controls
105 lines (92 loc) · 2.76 KB
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
#include "window.hpp"
#include "history_manipulator.hpp"
/**
* @brief Construct a new Main Window:: Main Window object
*
* Creates the main window with all the styles
*/
MainWindow::MainWindow() {
set_app_paintable(true);
auto screen1 = get_screen();
auto visual = screen1->get_rgba_visual();
if (visual) {
gtk_widget_set_visual(Gtk::Widget::gobj(), visual->gobj());
} else {
g_warning("RGBA not found");
}
auto css_provider = Gtk::CssProvider::create();
css_provider->load_from_data(R"(
.box-row {
padding: 10px;
}
.list-row {
background-color: #404040;
border-radius: 10px;
color: white;
padding: 10px;
}
.box-container {
border-radius: 20px;
margin: 5px;
padding: 5px;
}
.app-container {
background-color: #2a2a2a;
border-radius: 20px;
padding: 10px;
}
)");
auto screen = Gdk::Display::get_default()->get_default_screen();
Gtk::StyleContext::add_provider_for_screen(
screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_USER);
set_default_size(300, 400);
set_decorated(false);
set_position(Gtk::WIN_POS_CENTER);
app_container.set_orientation(Gtk::ORIENTATION_VERTICAL);
app_container.get_style_context()->add_class("app-container");
scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
scrolled_window.add(box);
box.set_orientation(Gtk::ORIENTATION_VERTICAL);
box.set_spacing(10);
box.get_style_context()->add_class("box-container");
app_container.pack_start(scrolled_window, Gtk::PACK_EXPAND_WIDGET);
add(app_container);
signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::onLostFocus), false);
show_all_children();
hide();
}
/**
* @brief Callback for when the window loses focus (user clicks outside the window)
*
* @param event The focus event
* @return true
*/
bool MainWindow::onLostFocus(GdkEventFocus*) {
hide();
return false;
}
/**
* @brief Toggles the visibility of the window
*
*/
void MainWindow::toggleVisibility() {
if (is_visible()) {
hide();
} else {
show_all();
}
}
/**
* @brief Updates the items in the history
*
* @param history The history to be updated
*/
void MainWindow::updateItems(HistoryManipulator *history) {
box.foreach([&](Gtk::Widget& child) {
box.remove(child);
});
for (auto it = history->getHistory().rbegin(); it != history->getHistory().rend(); ++it) { // reverse loop
box.pack_start(*(*it)->getEventBox(), Gtk::PACK_SHRINK);
}
show_all_children();
}