-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWbar.cc
125 lines (105 loc) · 3.23 KB
/
Wbar.cc
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
#include <iostream>
#include <unistd.h>
#include <signal.h>
#include "OptionParser.h"
#include "ConfigReader.h"
#include "CanvasEngine.h"
#include "LayoutStrategy.h"
class Wbar : public XEventHandler {
private:
Wbar(const Wbar &);
Wbar &operator=(const Wbar &);
ConfigReader cfgreader;
Xwindow window;
WaveLayout *layout;
XButtonEvent mouse_position;
public:
Wbar(const OptionParser &optparser)
: cfgreader(optparser.getString("config")), window(Size(10, 10)),
layout(new WaveLayout(
optparser.getInt("size"), optparser.getInt("nanim"),
optparser.getFloat("zoomf"), optparser.getFloat("jumpf"))) {
CanvasEngine::init(window);
// if (cfgreader.get("Dock").get("layout") == "Wave") {
// layout = new WaveLayout();
//}
CanvasWidget &dock = CanvasEngine::get().addWidget(
cfgreader.get("Dock").get("face"), RectLayout(layout->dockLayout()));
dock.setFrame(Border(5, 5, 5, 5));
for (const auto &elem : cfgreader) {
if (elem.get("type") == "LauncherWidget") {
CanvasEngine::get().addWidget(elem.get("face"),
RectLayout(layout->addWidget()));
}
}
window.resize(layout->frameSize());
CanvasEngine::get().resize(layout->frameSize());
window.setSkipPager();
window.setSkipTaskbar();
window.setSticky();
window.setType(wtype_dock);
window.setLayer(wlayer_above);
window.decorationsOff();
window.map();
window.move(Point((Xwindow::screenSize().x - layout->frameSize().x) / 2,
Xwindow::screenSize().y - layout->frameSize().y));
eventLoop(window);
}
~Wbar() { delete layout; }
void onExposure(const XExposeEvent &) override {
CanvasEngine::get().render();
}
void onMouseMove(const XMotionEvent &e) override {
const Point p(e.x, e.y);
if (layout->atHoverZone(p)) {
layout->focus(p);
} else {
layout->unfocus();
}
CanvasEngine::get().render();
}
void onMouseDown(const XButtonEvent &e) override { mouse_position = e; }
void onMouseUp(const XButtonEvent &e) override {
if (mouse_position.x == e.x && mouse_position.y == e.y) {
int idx = layout->widgetAt(Point(e.x, e.y));
for (const auto &elem : cfgreader) {
if (elem.get("type") == "LauncherWidget" && idx-- == 0) {
if (!fork()) {
execl("/bin/sh", "/bin/sh", "-c", elem.get("command").c_str(),
NULL);
_exit(1);
} else
break;
}
}
}
}
void onMouseEnter(const XCrossingEvent &e) override {
layout->focus(Point(e.x, e.y));
CanvasEngine::get().render();
}
void onMouseLeave(const XCrossingEvent &) override {
layout->unfocus();
CanvasEngine::get().render();
}
};
void showHelp() { std::cout << "wbar 2.0" << std::endl; }
int main(int argc, char *argv[]) {
try {
OptionParser optparser(argc, argv);
if (optparser.isset("help")) {
showHelp();
} else {
struct sigaction sa;
sa.sa_flags = SA_NOCLDSTOP;
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, nullptr);
Wbar wbar(optparser);
}
}
catch (const char *e) {
std::cout << e << std::endl;
}
return 0;
}
/* vim: set sw=2 sts=2 : */