src/tests/movetest.cc (raw)
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 |
// movetest.cc a test app for moving windows // Copyright (c) 2004 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) #include <iostream> #include "../FbTk/FbWindow.hh" #include "../FbTk/App.hh" #include "../FbTk/EventManager.hh" #include "../FbTk/EventHandler.hh" #include "../FbTk/Color.hh" using namespace std; using namespace FbTk; class Ev: public EventHandler { public: Ev():m_window(0, 0, 0, 512, 512, ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | SubstructureRedirectMask), m_drag(m_window, 0, 0, 32, 32, ExposureMask) { /* | ButtonPressMask) { ButtonReleaseMask | ButtonMotionMask) { */ m_window.setName("hello"); m_window.show(); m_drag.setBackgroundColor(Color("blue", 0)); m_drag.show(); EventManager::instance()->add(*this, m_window); EventManager::instance()->add(*this, m_drag); drag = false; } void exposeEvent(XExposeEvent &event) { m_drag.clear(); m_window.clear(); } void buttonPressEvent(XButtonEvent &event) { if (m_drag != event.subwindow) return; cerr<<"drag!"<<endl; drag = true; grab_x = event.x - m_drag.x(); grab_y = event.y - m_drag.y(); } void buttonReleaseEvent(XButtonEvent &event) { drag = false; } void motionNotifyEvent(XMotionEvent &event) { if (!drag) return; cerr<<"event.x_root: "<<event.x_root<<endl; cerr<<"event.y_root: "<<event.y_root<<endl; cerr<<"event.x: "<<event.x<<endl; cerr<<"event.y: "<<event.y<<endl; cerr<<"event.window: "<<hex<<event.window<<endl; cerr<<"event.subwindow: "<<event.subwindow<<endl; cerr<<"event.root: "<<event.root<<dec<<endl; cerr<<"event.is_hint: "<<event.is_hint<<endl; cerr<<"event.same_screen: "<<event.same_screen<<endl; cerr<<"event.send_event: "<<event.send_event<<endl; cerr<<"window pos: "<<m_window.x()<<", "<<m_window.y()<<endl; m_drag.move(event.x - grab_x, event.y - grab_y); } int grab_x, grab_y; bool drag; FbWindow m_window, m_drag; }; int main() { App app; Ev ev; cerr<<"Drag the blue rectangle! ...please :D"<<endl; app.eventLoop(); } |