-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (55 loc) · 1.92 KB
/
main.cpp
File metadata and controls
70 lines (55 loc) · 1.92 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
/* SPDX-License-Identifier: CC0-1.0 */
#include <peel/Adw/Adw.h>
#include <peel/GLib/MainContext.h>
#include <peel/Gtk/WindowHandle.h>
#include <peel/Adw/ToolbarView.h>
#include <peel/Adw/HeaderBar.h>
#include <peel/Gtk/Label.h>
#include <peel/GLib/DateTime.h>
#include <peel/GLib/functions.h>
#include <peel/GLib/Source.h>
using namespace peel;
static void on_waking_up(Gtk::Label *label, unsigned *source_id) {
auto time = GLib::DateTime::create_now_local();
char buffer[10];
snprintf(buffer, sizeof(buffer), "%02d\n%02d", time->get_hour(), time->get_minute());
label->set_label(buffer);
int time_span = (60 - time->get_second()) * 1000 - time->get_microsecond() / 1000 + 1; // in milliseconds
*source_id = GLib::timeout_add_once(
time_span,
[label, source_id]() {
on_waking_up(label, source_id);
}
);
}
int main() {
Adw::init();
GLib::MainContext *main_context = GLib::MainContext::default_();
auto label = Gtk::Label::create("00\n00");
label->add_css_class("numeric");
label->set_margin_bottom(30);
auto attr_list = Pango::AttrList::from_string("0 -1 font-desc \"100\", 0 -1 weight 100");
label->set_attributes(attr_list);
unsigned source_id;
on_waking_up(label, &source_id);
auto handle = Gtk::WindowHandle::create();
handle->set_child(std::move(label));
auto view = Adw::ToolbarView::create();
view->set_content(std::move(handle));
auto top_bar = Adw::HeaderBar::create();
view->add_top_bar(std::move(top_bar));
bool should_stop = false;
Adw::Window *window = Adw::Window::create();
window->connect_destroy (
[&should_stop, &source_id] (Gtk::Widget *)
{
should_stop = true;
GLib::Source::remove(source_id);
}
);
window->set_content(std::move(view));
window->present();
while (!should_stop) {
main_context->iteration(true);
}
}