+
+ focused_win = 0;
+}
+
+const Window *WindowManager::get_focused_window() const
+{
+ return focused_win;
+}
+
+Window *WindowManager::get_focused_window()
+{
+ return focused_win;
+}
+
+Window *WindowManager::get_window_at_pos(int pointer_x, int pointer_y)
+{
+ std::list<Window*>::reverse_iterator rit = windows.rbegin();
+ while(rit != windows.rend()) {
+ Window *w = *rit++;
+ Window *parent = w->get_parent();
+
+ if(parent == root_win && w->contains_point(pointer_x, pointer_y)) {
+ return w;
+ }
+ }
+
+ return 0;
+}
+
+static void display(Window *win)
+{
+ if(win->get_managed()) {
+ fill_rect(win->get_rect(), 255, 211, 5);
+ win->draw(win->get_parent()->get_rect());
+ }
+}
+
+static int prev_x = -1, prev_y;
+
+static void mouse(Window *win, int bn, bool pressed)
+{
+ printf("mouse callback (%d, %s)\n", bn, pressed ? "pressed" : "released");
+ if(bn == 0) {
+ if(pressed) {
+ get_pointer_pos(&prev_x, &prev_y);
+ } else {
+ prev_x = -1;
+ }
+ }
+}
+
+static void motion(Window *win, int x, int y)
+{
+ int left_bn = get_button(0);
+ if(left_bn && prev_x != -1) {
+ int dx = x - prev_x;
+ int dy = y - prev_y;
+ prev_x = x;
+ prev_y = y;
+
+ Rect rect = win->get_rect();
+ win->move(rect.x + dx, rect.y + dy);
+ }