]> Dogcows Code - chaz/openbox/blobdiff - otk/widget.cc
linear focus cycling
[chaz/openbox] / otk / widget.cc
index 604992fd1f1fbaf48de13a7651e8b56a5b1fef12..69a86237ec407cdccf8ceb412a12204c7e54d61a 100644 (file)
@@ -8,7 +8,7 @@
 #include "display.hh"
 #include "assassin.hh"
 #include "screeninfo.hh"
-
+#include "focuslabel.hh"
 #include <algorithm>
 #include <iostream>
 
@@ -23,8 +23,10 @@ Widget::Widget(Widget *parent, Direction direction)
     _visible(false), _grabbed_mouse(false),
     _grabbed_keyboard(false), _stretchable_vert(false),
     _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0),
-    _bcolor(0), _bwidth(0), _screen(parent->screen()), _fixed_width(false),
-    _fixed_height(false), _event_dispatcher(parent->eventDispatcher())
+    _bcolor(0), _bwidth(0), _rect(0, 0, 1, 1), _screen(parent->screen()),
+    _fixed_width(false), _fixed_height(false),
+    _surface(0),
+    _event_dispatcher(parent->eventDispatcher())
 {
   assert(parent);
   parent->addChild(this);
@@ -33,17 +35,18 @@ Widget::Widget(Widget *parent, Direction direction)
   setStyle(_style); // let the widget initialize stuff
 }
 
-Widget::Widget(EventDispatcher *event_dispatcher, Style *style,
-                     Direction direction, Cursor cursor, int bevel_width,
-                     bool override_redirect)
+Widget::Widget(EventDispatcher *event_dispatcher, RenderStyle *style,
+               Direction direction, Cursor cursor, int bevel_width,
+               bool override_redirect)
   : EventHandler(),
     _dirty(false),_focused(false),
     _parent(0), _style(style), _direction(direction), _cursor(cursor),
     _bevel_width(bevel_width), _ignore_config(0), _visible(false),
     _grabbed_mouse(false), _grabbed_keyboard(false),
     _stretchable_vert(false), _stretchable_horz(false), _texture(0),
-    _bg_pixmap(0), _bg_pixel(0), _bcolor(0), _bwidth(0),
-    _screen(style->getScreen()), _fixed_width(false), _fixed_height(false),
+    _bg_pixmap(0), _bg_pixel(0), _bcolor(0), _bwidth(0), _rect(0, 0, 1, 1),
+    _screen(style->screen()), _fixed_width(false), _fixed_height(false),
+    _surface(0),
     _event_dispatcher(event_dispatcher)
 {
   assert(event_dispatcher);
@@ -65,12 +68,12 @@ Widget::~Widget()
   if (_parent)
     _parent->removeChild(this);
 
-  XDestroyWindow(Display::display, _window);
+  XDestroyWindow(**display, _window);
 }
 
 void Widget::create(bool override_redirect)
 {
-  const ScreenInfo *scr_info = Display::screenInfo(_screen);
+  const ScreenInfo *scr_info = display->screenInfo(_screen);
   Window p_window = _parent ? _parent->window() : scr_info->rootWindow();
 
   _rect.setRect(0, 0, 1, 1); // just some initial values
@@ -93,7 +96,7 @@ void Widget::create(bool override_redirect)
     attrib_create.cursor = _cursor;
   }
 
-  _window = XCreateWindow(Display::display, p_window, _rect.x(),
+  _window = XCreateWindow(**display, p_window, _rect.x(),
                           _rect.y(), _rect.width(), _rect.height(), 0,
                           scr_info->depth(), InputOutput,
                           scr_info->visual(), create_mask, &attrib_create);
@@ -122,7 +125,7 @@ void Widget::move(const Point &to)
 void Widget::move(int x, int y)
 {
   _rect.setPos(x, y);
-  XMoveWindow(Display::display, _window, x, y);
+  XMoveWindow(**display, _window, x, y);
   _ignore_config++;
 }
 
@@ -153,8 +156,11 @@ void Widget::setGeometry(int x, int y, int width, int height)
   _rect = Rect(x, y, width, height);
   _dirty = true;
 
-  XMoveResizeWindow(Display::display, _window, x, y, width, height);
-  _ignore_config++;
+  // don't use an XMoveResizeWindow here, because it doesn't seem to move
+  // windows with StaticGravity? This works, that didn't.
+  XResizeWindow(**display, _window, width, height);
+  XMoveWindow(**display, _window, x, y);
+  _ignore_config+=2;
 }
 
 void Widget::show(bool recursive)
@@ -169,10 +175,10 @@ void Widget::show(bool recursive)
   if (recursive) {
     WidgetList::iterator it = _children.begin(), end = _children.end();
     for (; it != end; ++it)
-      (*it)->show();
+      (*it)->show(recursive);
   }
 
-  XMapWindow(Display::display, _window);
+  XMapWindow(**display, _window);
   _visible = true;
 }
 
@@ -187,7 +193,7 @@ void Widget::hide(bool recursive)
       (*it)->hide();
   }
   
-  XUnmapWindow(Display::display, _window);
+  XUnmapWindow(**display, _window);
   _visible = false;
 }
 
@@ -213,7 +219,7 @@ void Widget::unfocus(void)
 
 bool Widget::grabMouse(void)
 {
-  Status ret = XGrabPointer(Display::display, _window, True,
+  Status ret = XGrabPointer(**display, _window, True,
                             (ButtonPressMask | ButtonReleaseMask |
                              ButtonMotionMask | EnterWindowMask |
                              LeaveWindowMask | PointerMotionMask),
@@ -228,13 +234,13 @@ void Widget::ungrabMouse(void)
   if (! _grabbed_mouse)
     return;
 
-  XUngrabPointer(Display::display, CurrentTime);
+  XUngrabPointer(**display, CurrentTime);
   _grabbed_mouse = false;
 }
 
 bool Widget::grabKeyboard(void)
 {
-  Status ret = XGrabKeyboard(Display::display, _window, True,
+  Status ret = XGrabKeyboard(**display, _window, True,
                              GrabModeSync, GrabModeAsync, CurrentTime);
   _grabbed_keyboard = (ret == GrabSuccess);
   return _grabbed_keyboard;
@@ -246,7 +252,7 @@ void Widget::ungrabKeyboard(void)
   if (! _grabbed_keyboard)
     return;
 
-  XUngrabKeyboard(Display::display, CurrentTime);
+  XUngrabKeyboard(**display, CurrentTime);
   _grabbed_keyboard = false;
 }
 
@@ -254,18 +260,16 @@ void Widget::render(void)
 {
   if (!_texture) return;
 
-  _bg_pixmap = _texture->render(_rect.width(), _rect.height(), _bg_pixmap);
+  Surface *s = _surface; // save the current surface
+  
+  _surface = new Surface(_screen, _rect.size());
+  display->renderControl(_screen)->drawBackground(*_surface, *_texture);
 
-  if (_bg_pixmap) {
-    XSetWindowBackgroundPixmap(Display::display, _window, _bg_pixmap);
-    _bg_pixel = None;
-  } else {
-    unsigned int pix = _texture->color().pixel();
-    if (pix != _bg_pixel) {
-      _bg_pixel = pix;
-      XSetWindowBackground(Display::display, _window, pix);
-    }
-  }
+  renderForeground(); // for inherited types to render onto the _surface
+
+  XSetWindowBackgroundPixmap(**display, _window, _surface->pixmap());
+
+  delete s; // delete the old surface *after* its pixmap isn't in use anymore
 }
 
 void Widget::adjust(void)
@@ -395,7 +399,7 @@ void Widget::update(void)
   if (_dirty) {
     adjust();
     render();
-    XClearWindow(Display::display, _window);
+    XClearWindow(**display, _window);
   }
 
   WidgetList::iterator it = _children.begin(), end = _children.end();
@@ -439,7 +443,7 @@ void Widget::removeChild(Widget *child)
     _children.erase(it);
 }
 
-void Widget::setStyle(Style *style)
+void Widget::setStyle(RenderStyle *style)
 {
   assert(style);
   _style = style;
@@ -462,19 +466,28 @@ void Widget::setEventDispatcher(EventDispatcher *disp)
 void Widget::exposeHandler(const XExposeEvent &e)
 {
   EventHandler::exposeHandler(e);
-  _dirty = true;
-  update();
+//  XClearArea(**display, _window, e.x, e.y, e.width, e.height, false);
 }
 
 void Widget::configureHandler(const XConfigureEvent &e)
 {
   EventHandler::configureHandler(e);
+
   if (_ignore_config) {
     _ignore_config--;
   } else {
-    if (!(e.width == _rect.width() && e.height == _rect.height())) {
+    int width = e.width;
+    int height = e.height;
+
+    XEvent ev;
+    while (XCheckTypedWindowEvent(**display, _window, ConfigureNotify, &ev)) {
+      width = ev.xconfigure.width;
+      height = ev.xconfigure.height;
+    }
+
+    if (!(width == _rect.width() && height == _rect.height())) {
       _dirty = true;
-      _rect.setSize(e.width, e.height);
+      _rect.setSize(width, height);
     }
     update();
   }
This page took 0.026107 seconds and 4 git commands to generate.