+ root_win->remove_child(win);
+ root_win->add_child(win);
+}
+
+void WindowManager::sink_window(Window *win)
+{
+ if(!win) {
+ return;
+ }
+
+ std::list<Window*>::iterator it;
+ it = std::find(windows.begin(), windows.end(), win);
+ if(it != windows.end()) {
+ windows.erase(it);
+ windows.push_front(win);
+ }
+}
+
+void WindowManager::maximize_window(Window *win)
+{
+ win->normal_rect = win->rect;
+
+ Rect rect = get_screen_size();
+
+ Window *frame;
+ if((frame = win->get_parent())) {
+ frame->normal_rect = frame->rect;
+ frame->resize(rect.width, rect.height);
+ frame->move(rect.x, rect.y);
+
+ rect.width -= frame_thickness * 2;
+ rect.height -= frame_thickness * 2 + titlebar_thickness;
+ }
+ else {
+ win->move(0, 0);
+ }
+
+ win->resize(rect.width, rect.height);
+ win->set_state(Window::STATE_MAXIMIZED);
+}
+
+void WindowManager::unmaximize_window(Window *win)
+{
+ win->resize(win->normal_rect.width, win->normal_rect.height);
+ win->move(win->normal_rect.x, win->normal_rect.y);
+
+ Window *frame;
+ if((frame = win->get_parent())) {
+ frame->resize(frame->normal_rect.width, frame->normal_rect.height);
+ frame->move(frame->normal_rect.x, frame->normal_rect.y);
+ }
+
+ win->set_state(Window::STATE_NORMAL);
+}
+
+static void display(Window *win)
+{
+ //frame display:
+ Window *child = win->get_children()[0];
+ int r, g, b;
+ Rect abs_rect = win->get_absolute_rect();
+
+ //TODO 5 not hardcoded
+ set_text_position(abs_rect.x + 5, abs_rect.y + 15);
+ set_text_color(255, 255, 255);
+
+ if(child == wm->get_focused_window()) {
+ wm->get_focused_frame_color(&r, &g, &b);
+ fill_rect(abs_rect, r, g, b);
+ }
+ else {
+ wm->get_unfocused_frame_color(&r, &g, &b);
+ fill_rect(win->get_absolute_rect(), r, g, b);
+ }
+
+ draw_text(child->get_title());