From: Eleni Maria Stea Date: Sun, 10 Mar 2013 02:35:14 +0000 (+0200) Subject: maximize windows X-Git-Url: https://eleni.mutantstargoat.com/git/?p=winnie;a=commitdiff_plain;h=15e07ead145a859762b48ac9062a07cddf826151 maximize windows --- diff --git a/src/window.cc b/src/window.cc index fb46b38..ca8bdbc 100644 --- a/src/window.cc +++ b/src/window.cc @@ -16,6 +16,7 @@ Window::Window() dirty = true; managed = true; focusable = true; + state = STATE_NORMAL; } Window::~Window() @@ -237,3 +238,13 @@ Window *Window::get_parent() { return parent; } + +void Window::set_state(State state) +{ + this->state = state; +} + +Window::State Window::get_state() const +{ + return state; +} diff --git a/src/window.h b/src/window.h index ee9c7a0..ecbee9e 100644 --- a/src/window.h +++ b/src/window.h @@ -7,9 +7,16 @@ #include "event.h" class Window { +public: + enum State {STATE_NORMAL, STATE_MINIMIZED, STATE_MAXIMIZED, STATE_SHADED}; + private: char *title; + State state; + Rect rect; + Rect normal_rect; // normal state rectangle managed by the wm + Callbacks callbacks; std::vector children; @@ -72,6 +79,9 @@ public: const Window *get_parent() const; Window *get_parent(); + void set_state(State state); + State get_state() const; + // XXX remove if not needed friend class WindowManager; }; diff --git a/src/winnie.cc b/src/winnie.cc index a2c61ee..f79a9e8 100644 --- a/src/winnie.cc +++ b/src/winnie.cc @@ -1,3 +1,5 @@ +#include + #include "keyboard.h" #include "mouse.h" #include "shalloc.h" @@ -42,3 +44,18 @@ void winnie_shutdown() destroy_shared_memory(); } + +long winnie_get_time() +{ + static struct timeval init_tv; + struct timeval tv; + + gettimeofday(&tv, 0); + + if(!tv.tv_sec && !tv.tv_usec) { + init_tv = tv; + return 0; + } + + return (tv.tv_usec - init_tv.tv_usec) / 1000 + (tv.tv_sec - init_tv.tv_sec) * 1000; +} diff --git a/src/winnie.h b/src/winnie.h index 6c495af..bd611e2 100644 --- a/src/winnie.h +++ b/src/winnie.h @@ -11,4 +11,6 @@ bool winnie_init(); void winnie_shutdown(); +long winnie_get_time(); + #endif diff --git a/src/wm.cc b/src/wm.cc index 7c5959e..7791e79 100644 --- a/src/wm.cc +++ b/src/wm.cc @@ -1,4 +1,5 @@ #include +#include #include #include // TODO @@ -8,6 +9,9 @@ #include "text.h" #include "wm.h" #include "window.h" +#include "winnie.h" + +#define DCLICK_INTERVAL 400 WindowManager *wm; @@ -329,6 +333,45 @@ void WindowManager::sink_window(Window *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 { + rect.x = 0; + rect.y = 0; + win->move(rect.x, rect.y); + } + + 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: @@ -356,12 +399,29 @@ static int prev_x, prev_y; static void mouse(Window *win, int bn, bool pressed, int x, int y) { + static long last_click = 0; + if(bn == 0) { if(pressed) { + long time = winnie_get_time(); + if((time - last_click) < DCLICK_INTERVAL) { + Window *child = win->get_children()[0]; + Window::State state = child->get_state(); + if(state == Window::STATE_MAXIMIZED) { + child->set_state(Window::STATE_NORMAL); + wm->unmaximize_window(child); + } + else if(state == Window::STATE_NORMAL) { + wm->maximize_window(child); + } + } + wm->grab_mouse(win); wm->raise_window(win); prev_x = x; prev_y = y; + + last_click = time; } else { wm->release_mouse(); diff --git a/src/wm.h b/src/wm.h index 6b9f13d..140a3b0 100644 --- a/src/wm.h +++ b/src/wm.h @@ -62,6 +62,9 @@ public: void raise_window(Window *win); void sink_window(Window *win); + + void maximize_window(Window *win); + void unmaximize_window(Window *win); }; extern WindowManager *wm;