-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.h
More file actions
208 lines (157 loc) · 3.26 KB
/
view.h
File metadata and controls
208 lines (157 loc) · 3.26 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef VIEW_H
#define VIEW_H
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <chrono>
#include <cstdlib>
#include <unordered_set>
class application;
class keyboard_state;
class view;
class view {
public:
view(
application * app,
std::chrono::steady_clock::duration tick_duration = std::chrono::steady_clock::duration::max());
virtual
~view();
void
request_redraw();
void
destroy();
virtual void
redraw();
virtual void
resize(std::size_t width, std::size_t height);
virtual void
handle_button_press(
int button,
int x, int y,
int button_state);
virtual void
handle_button_release(
int button,
int x, int y,
int button_state);
virtual void
handle_pointer_motion(
int x, int y,
int button_state);
virtual void
handle_key_press(
int key_code,
const keyboard_state & state,
const char * chars);
virtual void
handle_key_release(
int key_code,
const keyboard_state & state);
virtual void
timer_tick();
protected:
application * app_;
bool active_;
virtual void notify_activate();
virtual void notify_deactivate();
inline std::size_t width() const noexcept;
inline std::size_t height() const noexcept;
private:
std::chrono::steady_clock::duration tick_duration_;
friend class application;
};
class keyboard_state {
public:
const std::unordered_set<int> & pressed_keys() const noexcept
{
return pressed_keys_;
}
private:
std::unordered_set<int> pressed_keys_;
friend class application;
};
class application {
public:
application();
~application();
void
set_active_view(view * active_view);
void
run();
void
quit();
void
request_redraw();
void
toggle_fullscreen();
inline const keyboard_state &
keyboard() const { return keyboard_state_; }
private:
void
intern_atoms();
void
handle_redraw();
void
handle_client_message(const ::XClientMessageEvent & ev);
void
handle_event(const ::XEvent & ev);
void
handle_button_press(const ::XEvent & ev);
void
handle_button_release(const ::XEvent & ev);
void
handle_pointer_motion(const ::XEvent & ev);
void
handle_key_press(const ::XEvent & ev);
void
handle_key_release(const ::XEvent & ev);
void
handle_focus_in(const ::XFocusChangeEvent & ev);
void
handle_focus_out(const ::XFocusChangeEvent & ev);
void
handle_glx_buffer_swap_complete(const ::XEvent & ev);
::Display * display_;
int glx_error_base_;
int glx_event_base_;
::XIM input_method_;
::XIC input_context_;
::Window root_;
::Window window_;
::GLXWindow glxwindow_;
::GLXContext glxctx_;
view * active_view_ = nullptr;
bool requested_quit_ = false;
bool requested_redraw_ = false;
bool visible_ = false;
bool fullscreen_ = false;
bool buffer_swap_pending_ = false;
std::size_t width_ = 0;
std::size_t height_ = 0;
std::chrono::steady_clock::time_point timer_due_ = std::chrono::steady_clock::time_point::max();
int x11_fd_;
/* FIXME: may not need this
int wake_write_fd_;
int wake_read_fd_;
*/
struct {
Atom wm_protocols;
Atom wm_delete_window;
Atom wm_take_focus;
Atom net_wm_state;
Atom net_wm_state_fullscreen;
} atoms_;
keyboard_state keyboard_state_;
friend class view;
};
inline std::size_t
view::width() const noexcept
{
return app_->width_;
}
inline std::size_t
view::height() const noexcept
{
return app_->height_;
}
#endif