fixed bugs, got otkapp to select on a fd, modded widget to make use of otkapp, press/release events on buttons
This commit is contained in:
parent
0680daeef5
commit
6f5e60f033
10 changed files with 131 additions and 84 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "application.hh"
|
#include "application.hh"
|
||||||
#include "eventhandler.hh"
|
#include "eventhandler.hh"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
OtkApplication::OtkApplication(int argc, char **argv)
|
OtkApplication::OtkApplication(int argc, char **argv)
|
||||||
|
@ -35,12 +37,23 @@ void OtkApplication::loadStyle(void)
|
||||||
// find the style name as a property
|
// find the style name as a property
|
||||||
_style_conf->setFile("/usr/local/share/openbox/styles/artwiz");
|
_style_conf->setFile("/usr/local/share/openbox/styles/artwiz");
|
||||||
_style_conf->load();
|
_style_conf->load();
|
||||||
_style->load(_style_conf);
|
_style->load(*_style_conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtkApplication::exec(void)
|
void OtkApplication::exec(void)
|
||||||
{
|
{
|
||||||
dispatchEvents();
|
const int xfd = ConnectionNumber(OBDisplay::display);
|
||||||
|
fd_set rfds;
|
||||||
|
timeval *timeout = 0;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
dispatchEvents();
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(xfd, &rfds);
|
||||||
|
|
||||||
|
select(xfd + 1, &rfds, 0, 0, timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <iostream>
|
||||||
#include "button.hh"
|
#include "button.hh"
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
@ -66,6 +67,22 @@ void OtkButton::update(void)
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int OtkButton::buttonPressHandler(const XButtonEvent &e)
|
||||||
|
{
|
||||||
|
press();
|
||||||
|
_dirty = true;
|
||||||
|
update();
|
||||||
|
return OtkFocusWidget::buttonPressHandler(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
int OtkButton::buttonReleaseHandler(const XButtonEvent &e)
|
||||||
|
{
|
||||||
|
release();
|
||||||
|
_dirty = true;
|
||||||
|
update();
|
||||||
|
return OtkFocusWidget::buttonReleaseHandler(e);
|
||||||
|
}
|
||||||
|
|
||||||
int OtkButton::exposeHandler(const XExposeEvent &e)
|
int OtkButton::exposeHandler(const XExposeEvent &e)
|
||||||
{
|
{
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
void update(void);
|
void update(void);
|
||||||
int exposeHandler(const XExposeEvent &e);
|
int exposeHandler(const XExposeEvent &e);
|
||||||
int configureHandler(const XConfigureEvent &e);
|
int configureHandler(const XConfigureEvent &e);
|
||||||
|
int buttonPressHandler(const XButtonEvent &e);
|
||||||
|
int buttonReleaseHandler(const XButtonEvent &e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#include "eventdispatcher.hh"
|
#include "eventdispatcher.hh"
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
OtkEventDispatcher::OtkEventDispatcher()
|
OtkEventDispatcher::OtkEventDispatcher()
|
||||||
|
: _fallback(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "eventhandler.hh"
|
#include "eventhandler.hh"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
@ -14,71 +15,71 @@ OtkEventHandler::~OtkEventHandler()
|
||||||
|
|
||||||
int OtkEventHandler::handle(const XEvent &e)
|
int OtkEventHandler::handle(const XEvent &e)
|
||||||
{
|
{
|
||||||
switch(e.type){
|
switch(e.type){
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
return keyPressHandler(e.xkey);
|
return keyPressHandler(e.xkey);
|
||||||
case KeyRelease:
|
case KeyRelease:
|
||||||
return keyReleaseHandler(e.xkey);
|
return keyReleaseHandler(e.xkey);
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
return buttonPressHandler(e.xbutton);
|
return buttonPressHandler(e.xbutton);
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
return buttonReleaseHandler(e.xbutton);
|
return buttonReleaseHandler(e.xbutton);
|
||||||
case EnterNotify:
|
case EnterNotify:
|
||||||
return enterHandler(e.xcrossing);
|
return enterHandler(e.xcrossing);
|
||||||
case LeaveNotify:
|
case LeaveNotify:
|
||||||
return leaveHandler(e.xcrossing);
|
return leaveHandler(e.xcrossing);
|
||||||
case FocusIn:
|
case FocusIn:
|
||||||
return focusHandler(e.xfocus);
|
return focusHandler(e.xfocus);
|
||||||
case FocusOut:
|
case FocusOut:
|
||||||
return unfocusHandler(e.xfocus);
|
return unfocusHandler(e.xfocus);
|
||||||
case Expose:
|
case Expose:
|
||||||
return exposeHandler(e.xexpose);
|
return exposeHandler(e.xexpose);
|
||||||
case GraphicsExpose:
|
case GraphicsExpose:
|
||||||
return graphicsExposeHandler(e.xgraphicsexpose);
|
return graphicsExposeHandler(e.xgraphicsexpose);
|
||||||
case NoExpose:
|
case NoExpose:
|
||||||
return noExposeEventHandler(e.xnoexpose);
|
return noExposeEventHandler(e.xnoexpose);
|
||||||
case CirculateRequest:
|
case CirculateRequest:
|
||||||
return circulateRequestHandler(e.xcirculaterequest);
|
return circulateRequestHandler(e.xcirculaterequest);
|
||||||
case ConfigureRequest:
|
case ConfigureRequest:
|
||||||
return configureRequestHandler(e.xconfigurerequest);
|
return configureRequestHandler(e.xconfigurerequest);
|
||||||
case MapRequest:
|
case MapRequest:
|
||||||
return mapRequestHandler(e.xmaprequest);
|
return mapRequestHandler(e.xmaprequest);
|
||||||
case ResizeRequest:
|
case ResizeRequest:
|
||||||
return resizeRequestHandler(e.xresizerequest);
|
return resizeRequestHandler(e.xresizerequest);
|
||||||
case CirculateNotify:
|
case CirculateNotify:
|
||||||
return circulateHandler(e.xcirculate);
|
return circulateHandler(e.xcirculate);
|
||||||
case ConfigureNotify:
|
case ConfigureNotify:
|
||||||
return configureHandler(e.xconfigure);
|
return configureHandler(e.xconfigure);
|
||||||
case CreateNotify:
|
case CreateNotify:
|
||||||
return createHandler(e.xcreatewindow);
|
return createHandler(e.xcreatewindow);
|
||||||
case DestroyNotify:
|
case DestroyNotify:
|
||||||
return destroyHandler(e.xdestroywindow);
|
return destroyHandler(e.xdestroywindow);
|
||||||
case GravityNotify:
|
case GravityNotify:
|
||||||
return gravityHandler(e.xgravity);
|
return gravityHandler(e.xgravity);
|
||||||
case MapNotify:
|
case MapNotify:
|
||||||
return mapHandler(e.xmap);
|
return mapHandler(e.xmap);
|
||||||
case MappingNotify:
|
case MappingNotify:
|
||||||
return mappingHandler(e.xmapping);
|
return mappingHandler(e.xmapping);
|
||||||
case ReparentNotify:
|
case ReparentNotify:
|
||||||
return reparentHandler(e.xreparent);
|
return reparentHandler(e.xreparent);
|
||||||
case UnmapNotify:
|
case UnmapNotify:
|
||||||
return unmapHandler(e.xunmap);
|
return unmapHandler(e.xunmap);
|
||||||
case VisibilityNotify:
|
case VisibilityNotify:
|
||||||
return visibilityHandler(e.xvisibility);
|
return visibilityHandler(e.xvisibility);
|
||||||
case ColormapNotify:
|
case ColormapNotify:
|
||||||
return colorMapHandler(e.xcolormap);
|
return colorMapHandler(e.xcolormap);
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
return clientMessageHandler(e.xclient);
|
return clientMessageHandler(e.xclient);
|
||||||
case PropertyNotify:
|
case PropertyNotify:
|
||||||
return propertyHandler(e.xproperty);
|
return propertyHandler(e.xproperty);
|
||||||
case SelectionClear:
|
case SelectionClear:
|
||||||
return selectionClearHandler(e.xselectionclear);
|
return selectionClearHandler(e.xselectionclear);
|
||||||
case SelectionNotify:
|
case SelectionNotify:
|
||||||
return selectionHandler(e.xselection);
|
return selectionHandler(e.xselection);
|
||||||
case SelectionRequest:
|
case SelectionRequest:
|
||||||
return selectionRequestHandler(e.xselectionrequest);
|
return selectionRequestHandler(e.xselectionrequest);
|
||||||
};
|
};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace otk {
|
||||||
class OtkEventHandler{
|
class OtkEventHandler{
|
||||||
public:
|
public:
|
||||||
//! Dispatches events to one of the other handlers based on their type.
|
//! Dispatches events to one of the other handlers based on their type.
|
||||||
int handle(const XEvent &e);
|
virtual int handle(const XEvent &e);
|
||||||
|
|
||||||
//! Called whenever any key is pressed.
|
//! Called whenever any key is pressed.
|
||||||
virtual int keyPressHandler(const XKeyEvent &) {return 1;}
|
virtual int keyPressHandler(const XKeyEvent &) {return 1;}
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
#endif // HAVE_CONFIG_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "display.hh"
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "display.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "style.hh"
|
#include "style.hh"
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ BColor Style::readDatabaseColor(const std::string &rname,
|
||||||
|
|
||||||
|
|
||||||
BFont *Style::readDatabaseFont(const std::string &rbasename,
|
BFont *Style::readDatabaseFont(const std::string &rbasename,
|
||||||
const Configuration &style) {
|
const Configuration &style) {
|
||||||
std::string fontname;
|
std::string fontname;
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
|
@ -123,6 +123,11 @@ public:
|
||||||
inline unsigned int getBorderWidth(void) const { return border_width; }
|
inline unsigned int getBorderWidth(void) const { return border_width; }
|
||||||
|
|
||||||
inline const BFont &getFont() const { return *font; }
|
inline const BFont &getFont() const { return *font; }
|
||||||
|
|
||||||
|
inline void setShadowFonts(bool fonts) { shadow_fonts = fonts; }
|
||||||
|
inline bool hasShadowFonts(void) const { return shadow_fonts; }
|
||||||
|
|
||||||
|
inline void setAAFonts(bool fonts) { aa_fonts = fonts; }
|
||||||
inline bool hasAAFonts(void) const { return aa_fonts; }
|
inline bool hasAAFonts(void) const { return aa_fonts; }
|
||||||
|
|
||||||
inline TextJustify textJustify(void) { return justify; }
|
inline TextJustify textJustify(void) { return justify; }
|
||||||
|
|
|
@ -17,10 +17,11 @@ OtkWidget::OtkWidget(OtkWidget *parent, Direction direction)
|
||||||
_grabbed_keyboard(false), _stretchable_vert(false),
|
_grabbed_keyboard(false), _stretchable_vert(false),
|
||||||
_stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0),
|
_stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0),
|
||||||
_screen(parent->getScreen()), _fixed_width(false), _fixed_height(false),
|
_screen(parent->getScreen()), _fixed_width(false), _fixed_height(false),
|
||||||
_dirty(false)
|
_dirty(false), _event_dispatcher(parent->getEventDispatcher())
|
||||||
{
|
{
|
||||||
parent->addChild(this);
|
parent->addChild(this);
|
||||||
create();
|
create();
|
||||||
|
_event_dispatcher->registerHandler(_window, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
OtkWidget::OtkWidget(OtkApplication *app, Direction direction,
|
OtkWidget::OtkWidget(OtkApplication *app, Direction direction,
|
||||||
|
@ -31,11 +32,12 @@ OtkWidget::OtkWidget(OtkApplication *app, Direction direction,
|
||||||
_focused(false), _grabbed_mouse(false), _grabbed_keyboard(false),
|
_focused(false), _grabbed_mouse(false), _grabbed_keyboard(false),
|
||||||
_stretchable_vert(false), _stretchable_horz(false), _texture(0),
|
_stretchable_vert(false), _stretchable_horz(false), _texture(0),
|
||||||
_bg_pixmap(0), _bg_pixel(0), _screen(app->getStyle()->getScreen()),
|
_bg_pixmap(0), _bg_pixel(0), _screen(app->getStyle()->getScreen()),
|
||||||
_fixed_width(false), _fixed_height(false), _dirty(false)
|
_fixed_width(false), _fixed_height(false), _dirty(false),
|
||||||
|
_event_dispatcher(app)
|
||||||
{
|
{
|
||||||
assert(app);
|
assert(app);
|
||||||
create();
|
create();
|
||||||
app->registerHandler(_window, this);
|
_event_dispatcher->registerHandler(_window, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
OtkWidget::OtkWidget(Style *style, Direction direction,
|
OtkWidget::OtkWidget(Style *style, Direction direction,
|
||||||
|
@ -413,6 +415,14 @@ void OtkWidget::removeChild(OtkWidget *child)
|
||||||
_children.erase(it);
|
_children.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OtkWidget::setEventDispatcher(OtkEventDispatcher *disp)
|
||||||
|
{
|
||||||
|
if (_event_dispatcher)
|
||||||
|
_event_dispatcher->clearHandler(_window);
|
||||||
|
_event_dispatcher = disp;
|
||||||
|
_event_dispatcher->registerHandler(_window, this);
|
||||||
|
}
|
||||||
|
|
||||||
int OtkWidget::exposeHandler(const XExposeEvent &e)
|
int OtkWidget::exposeHandler(const XExposeEvent &e)
|
||||||
{
|
{
|
||||||
OtkEventHandler::exposeHandler(e);
|
OtkEventHandler::exposeHandler(e);
|
||||||
|
@ -420,11 +430,6 @@ int OtkWidget::exposeHandler(const XExposeEvent &e)
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
update();
|
update();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
OtkWidgetList::iterator it = _children.begin(), end = _children.end();
|
|
||||||
for (; it != end; ++it)
|
|
||||||
if ((*it)->exposeHandler(e))
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +441,6 @@ int OtkWidget::configureHandler(const XConfigureEvent &e)
|
||||||
if (_ignore_config) {
|
if (_ignore_config) {
|
||||||
_ignore_config--;
|
_ignore_config--;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "configure\n";
|
|
||||||
if (!(e.width == _rect.width() && e.height == _rect.height())) {
|
if (!(e.width == _rect.width() && e.height == _rect.height())) {
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
_rect.setSize(e.width, e.height);
|
_rect.setSize(e.width, e.height);
|
||||||
|
@ -444,12 +448,8 @@ int OtkWidget::configureHandler(const XConfigureEvent &e)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
OtkWidgetList::iterator it = _children.begin(), end = _children.end();
|
|
||||||
for (; it != end; ++it)
|
|
||||||
if ((*it)->configureHandler(e))
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,10 @@ public:
|
||||||
inline Style *getStyle(void) const { return _style; }
|
inline Style *getStyle(void) const { return _style; }
|
||||||
void setStyle(Style *style) { _style = style; }
|
void setStyle(Style *style) { _style = style; }
|
||||||
|
|
||||||
|
inline OtkEventDispatcher *getEventDispatcher(void)
|
||||||
|
{ return _event_dispatcher; }
|
||||||
|
void setEventDispatcher(OtkEventDispatcher *disp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void create(void);
|
void create(void);
|
||||||
|
@ -136,6 +140,8 @@ private:
|
||||||
bool _fixed_height;
|
bool _fixed_height;
|
||||||
|
|
||||||
bool _dirty;
|
bool _dirty;
|
||||||
|
|
||||||
|
OtkEventDispatcher *_event_dispatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue