Application::Application(int argc, char **argv)
: EventDispatcher(),
+ _display(),
_dockable(false),
_appwidget_count(0)
{
(void)argc;
(void)argv;
- Display::initialize(0);
- const ScreenInfo *s_info =
- Display::screenInfo(DefaultScreen(Display::display));
+ const ScreenInfo *s_info = _display.screenInfo(DefaultScreen(*_display));
_timer_manager = new TimerQueueManager();
_img_ctrl = new ImageControl(_timer_manager, s_info, True, 4, 5, 200);
delete _img_ctrl;
delete _timer_manager;
delete _style;
-
- Display::destroy();
}
void Application::loadStyle(void)
private:
void loadStyle(void);
+ Display _display;
TimerQueueManager *_timer_manager;
ImageControl *_img_ctrl;
Configuration *_style_conf;
{
assert(app);
- _wm_protocols = XInternAtom(Display::display, "WM_PROTOCOLS", false);
- _wm_delete = XInternAtom(Display::display, "WM_DELETE_WINDOW", false);
+ _wm_protocols = XInternAtom(**display, "WM_PROTOCOLS", false);
+ _wm_delete = XInternAtom(**display, "WM_DELETE_WINDOW", false);
// set WM Protocols on the window
Atom protocols[2];
protocols[0] = _wm_protocols;
protocols[1] = _wm_delete;
- XSetWMProtocols(Display::display, window(), protocols, 2);
+ XSetWMProtocols(**display, window(), protocols, 2);
}
AppWidget::~AppWidget()
}
if (scrn == ~(0u))
- scrn = DefaultScreen(Display::display);
- Colormap colormap = Display::screenInfo(scrn)->colormap();
+ scrn = DefaultScreen(**display);
+ Colormap colormap = display->screenInfo(scrn)->colormap();
// get rgb values from colorname
XColor xcol;
xcol.blue = 0;
xcol.pixel = 0;
- if (! XParseColor(Display::display, colormap,
+ if (! XParseColor(**display, colormap,
colorname.c_str(), &xcol)) {
fprintf(stderr, "Color::allocate: color parse error: \"%s\"\n",
colorname.c_str());
void Color::allocate(void) {
- if (scrn == ~(0u)) scrn = DefaultScreen(Display::display);
- Colormap colormap = Display::screenInfo(scrn)->colormap();
+ if (scrn == ~(0u)) scrn = DefaultScreen(**display);
+ Colormap colormap = display->screenInfo(scrn)->colormap();
if (! isValid()) {
if (colorname.empty()) {
xcol.blue = b | b << 8;
xcol.pixel = 0;
- if (! XAllocColor(Display::display, colormap, &xcol)) {
+ if (! XAllocColor(**display, colormap, &xcol)) {
fprintf(stderr, "Color::allocate: color alloc error: rgb:%x/%x/%x\n",
r, g, b);
xcol.pixel = 0;
int i;
unsigned count;
- for (i = 0; i < ScreenCount(Display::display); i++) {
+ for (i = 0; i < ScreenCount(**display); i++) {
count = 0;
it = colorcache.begin();
}
if (count > 0)
- XFreeColors(Display::display,
- Display::screenInfo(i)->colormap(),
+ XFreeColors(**display, display->screenInfo(i)->colormap(),
pixels, count, 0);
}
namespace otk {
-::Display *Display::display = (::Display*) 0;
-bool Display::_xkb = false;
-int Display::_xkb_event_basep = 0;
-bool Display::_shape = false;
-int Display::_shape_event_basep = 0;
-bool Display::_xinerama = false;
-int Display::_xinerama_event_basep = 0;
-unsigned int Display::_mask_list[8];
-unsigned int Display::_scrollLockMask = 0;
-unsigned int Display::_numLockMask = 0;
-Display::ScreenInfoList Display::_screenInfoList;
-GCCache *Display::_gccache = (GCCache*) 0;
-int Display::_grab_count = 0;
-
+Display *display = (Display*) 0;
static int xerrorHandler(::Display *d, XErrorEvent *e)
{
}
-void Display::initialize(char *name)
+Display::Display()
+ : _display(0),
+ _xkb(false),
+ _xkb_event_basep(0),
+ _shape(false),
+ _shape_event_basep(0),
+ _xinerama(false),
+ _xinerama_event_basep(0),
+ _mask_list(),
+ _num_lock_mask(0),
+ _scroll_lock_mask(0),
+ _grab_count(0),
+ _screenInfoList(),
+ _gccache((GCCache*) 0)
{
int junk;
(void)junk;
// Open the X display
- if (!(display = XOpenDisplay(name))) {
+ if (!(_display = XOpenDisplay(NULL))) {
printf(_("Unable to open connection to the X server. Please set the \n\
-DISPLAY environment variable approriately, or use the '-display' command \n\
-line argument.\n\n"));
+DISPLAY environment variable approriately.\n\n"));
::exit(1);
}
- if (fcntl(ConnectionNumber(display), F_SETFD, 1) == -1) {
+ if (fcntl(ConnectionNumber(_display), F_SETFD, 1) == -1) {
printf(_("Couldn't mark display connection as close-on-exec.\n\n"));
::exit(1);
}
// set the DISPLAY environment variable for any lauched children, to the
// display we're using, so they open in the right place.
- putenv(std::string("DISPLAY=") + DisplayString(display));
+ putenv(std::string("DISPLAY=") + DisplayString(_display));
// find the availability of X extensions we like to use
#ifdef XKB
- _xkb = XkbQueryExtension(display, &junk, &_xkb_event_basep, &junk, NULL,
+ _xkb = XkbQueryExtension(_display, &junk, &_xkb_event_basep, &junk, NULL,
NULL);
#endif
#ifdef SHAPE
- _shape = XShapeQueryExtension(display, &_shape_event_basep, &junk);
+ _shape = XShapeQueryExtension(_display, &_shape_event_basep, &junk);
#endif
#ifdef XINERAMA
- _xinerama = XineramaQueryExtension(display, &_xinerama_event_basep, &junk);
+ _xinerama = XineramaQueryExtension(_display, &_xinerama_event_basep, &junk);
#endif // XINERAMA
// get lock masks that are defined by the display (not constant)
XModifierKeymap *modmap;
- modmap = XGetModifierMapping(display);
+ modmap = XGetModifierMapping(_display);
if (modmap && modmap->max_keypermod > 0) {
const int mask_table[] = {
ShiftMask, LockMask, ControlMask, Mod1Mask,
// get the values of the keyboard lock modifiers
// Note: Caps lock is not retrieved the same way as Scroll and Num lock
// since it doesn't need to be.
- const KeyCode num_lock = XKeysymToKeycode(display, XK_Num_Lock);
- const KeyCode scroll_lock = XKeysymToKeycode(display, XK_Scroll_Lock);
+ const KeyCode num_lock = XKeysymToKeycode(_display, XK_Num_Lock);
+ const KeyCode scroll_lock = XKeysymToKeycode(_display, XK_Scroll_Lock);
for (size_t cnt = 0; cnt < size; ++cnt) {
if (! modmap->modifiermap[cnt]) continue;
if (num_lock == modmap->modifiermap[cnt])
- _numLockMask = mask_table[cnt / modmap->max_keypermod];
+ _num_lock_mask = mask_table[cnt / modmap->max_keypermod];
if (scroll_lock == modmap->modifiermap[cnt])
- _scrollLockMask = mask_table[cnt / modmap->max_keypermod];
+ _scroll_lock_mask = mask_table[cnt / modmap->max_keypermod];
}
}
_mask_list[0] = 0;
_mask_list[1] = LockMask;
- _mask_list[2] = _numLockMask;
- _mask_list[3] = LockMask | _numLockMask;
- _mask_list[4] = _scrollLockMask;
- _mask_list[5] = _scrollLockMask | LockMask;
- _mask_list[6] = _scrollLockMask | _numLockMask;
- _mask_list[7] = _scrollLockMask | LockMask | _numLockMask;
+ _mask_list[2] = _num_lock_mask;
+ _mask_list[3] = LockMask | _num_lock_mask;
+ _mask_list[4] = _scroll_lock_mask;
+ _mask_list[5] = _scroll_lock_mask | LockMask;
+ _mask_list[6] = _scroll_lock_mask | _num_lock_mask;
+ _mask_list[7] = _scroll_lock_mask | LockMask | _num_lock_mask;
// Get information on all the screens which are available.
- _screenInfoList.reserve(ScreenCount(display));
- for (int i = 0; i < ScreenCount(display); ++i)
+ _screenInfoList.reserve(ScreenCount(_display));
+ for (int i = 0; i < ScreenCount(_display); ++i)
_screenInfoList.push_back(ScreenInfo(i));
_gccache = new GCCache(_screenInfoList.size());
}
-void Display::destroy()
+Display::~Display()
{
delete _gccache;
while (_grab_count > 0)
ungrab();
- XCloseDisplay(display);
+ XCloseDisplay(_display);
}
-const ScreenInfo* Display::screenInfo(int snum) {
+const ScreenInfo* Display::screenInfo(int snum)
+{
assert(snum >= 0);
assert(snum < static_cast<int>(_screenInfoList.size()));
return &_screenInfoList[snum];
void Display::grab()
{
if (_grab_count == 0)
- XGrabServer(display);
+ XGrabServer(_display);
_grab_count++;
}
if (_grab_count == 0) return;
_grab_count--;
if (_grab_count == 0)
- XUngrabServer(display);
+ XUngrabServer(_display);
}
Window grab_window, bool owner_events,
unsigned int event_mask, int pointer_mode,
int keyboard_mode, Window confine_to,
- Cursor cursor, bool allow_scroll_lock) {
+ Cursor cursor, bool allow_scroll_lock) const
+{
unsigned int length = (allow_scroll_lock) ? 8 / 2:
8;
for (size_t cnt = 0; cnt < length; ++cnt)
- XGrabButton(Display::display, button, modifiers | _mask_list[cnt],
+ XGrabButton(_display, button, modifiers | _mask_list[cnt],
grab_window, owner_events, event_mask, pointer_mode,
keyboard_mode, confine_to, cursor);
}
* keyboard lock keys.
*/
void Display::ungrabButton(unsigned int button, unsigned int modifiers,
- Window grab_window) {
+ Window grab_window) const
+{
for (size_t cnt = 0; cnt < 8; ++cnt)
- XUngrabButton(Display::display, button, modifiers | _mask_list[cnt],
+ XUngrabButton(_display, button, modifiers | _mask_list[cnt],
grab_window);
}
void Display::grabKey(unsigned int keycode, unsigned int modifiers,
Window grab_window, bool owner_events,
int pointer_mode, int keyboard_mode,
- bool allow_scroll_lock)
+ bool allow_scroll_lock) const
{
unsigned int length = (allow_scroll_lock) ? 8 / 2:
8;
for (size_t cnt = 0; cnt < length; ++cnt)
- XGrabKey(Display::display, keycode, modifiers | _mask_list[cnt],
+ XGrabKey(_display, keycode, modifiers | _mask_list[cnt],
grab_window, owner_events, pointer_mode, keyboard_mode);
}
void Display::ungrabKey(unsigned int keycode, unsigned int modifiers,
- Window grab_window)
+ Window grab_window) const
{
for (size_t cnt = 0; cnt < 8; ++cnt)
- XUngrabKey(Display::display, keycode, modifiers | _mask_list[cnt],
+ XUngrabKey(_display, keycode, modifiers | _mask_list[cnt],
grab_window);
}
class ScreenInfo;
class GCCache;
+class Display;
+
+//! The display instance for the library
+extern Display *display;
+
//! Manages a single X11 display.
/*!
This class is static, and cannot be instantiated.
class Display
{
public:
- //! The X display
- static ::Display *display;
-
//! A List of ScreenInfo instances
typedef std::vector<ScreenInfo> ScreenInfoList;
private:
+ //! The X display
+ ::Display *_display;
+
//! Does the display have the XKB extension?
- static bool _xkb;
+ bool _xkb;
//! Base for events for the XKB extension
- static int _xkb_event_basep;
+ int _xkb_event_basep;
//! Does the display have the Shape extension?
- static bool _shape;
+ bool _shape;
//! Base for events for the Shape extension
- static int _shape_event_basep;
+ int _shape_event_basep;
//! Does the display have the Xinerama extension?
- static bool _xinerama;
+ bool _xinerama;
//! Base for events for the Xinerama extension
- static int _xinerama_event_basep;
+ int _xinerama_event_basep;
//! A list of all possible combinations of keyboard lock masks
- static unsigned int _mask_list[8];
+ unsigned int _mask_list[8];
//! The value of the mask for the NumLock modifier
- static unsigned int _numLockMask;
+ unsigned int _num_lock_mask;
//! The value of the mask for the ScrollLock modifier
- static unsigned int _scrollLockMask;
+ unsigned int _scroll_lock_mask;
//! The number of requested grabs on the display
- static int _grab_count;
+ int _grab_count;
//! A list of information for all screens on the display
- static ScreenInfoList _screenInfoList;
+ ScreenInfoList _screenInfoList;
//! A cache for re-using GCs, used by the drawing objects
/*!
@see ImageControl
@see Texture
*/
- static GCCache *_gccache;
+ GCCache *_gccache;
// Handles X errors on the display
/*
Displays the error if compiled for debugging.
*/
- //static int xerrorHandler(::Display *d, XErrorEvent *e);
-
- //! Prevents instantiation of the class
- Display();
+ //int xerrorHandler(::Display *d, XErrorEvent *e);
public:
//! Initializes the class, opens the X display
/*!
+ The DISPLAY environment variable is used to choose the display.
@see Display::display
- @param name The name of the X display to open. If it is null, the DISPLAY
- environment variable is used instead.
*/
- static void initialize(char *name);
+ Display();
//! Destroys the class, closes the X display
- static void destroy();
+ ~Display();
//! Returns the GC cache for the application
- inline static GCCache *gcCache() { return _gccache; }
+ inline GCCache *gcCache() const { return _gccache; }
//! Gets information on a specific screen
/*!
@param snum The screen number of the screen to retrieve info on
@return Info on the requested screen, in a ScreenInfo class
*/
- static const ScreenInfo* screenInfo(int snum);
+ const ScreenInfo* screenInfo(int snum);
//! Find a ScreenInfo based on a root window
- static const ScreenInfo* findScreen(Window root);
+ const ScreenInfo* findScreen(Window root);
//! Returns if the display has the xkb extension available
- inline static bool xkb() { return _xkb; }
+ inline bool xkb() const { return _xkb; }
//! Returns the xkb extension's event base
- inline static int xkbEventBase() { return _xkb_event_basep; }
+ inline int xkbEventBase() const { return _xkb_event_basep; }
//! Returns if the display has the shape extension available
- inline static bool shape() { return _shape; }
+ inline bool shape() const { return _shape; }
//! Returns the shape extension's event base
- inline static int shapeEventBase() { return _shape_event_basep; }
+ inline int shapeEventBase() const { return _shape_event_basep; }
//! Returns if the display has the xinerama extension available
- inline static bool xinerama() { return _xinerama; }
+ inline bool xinerama() const { return _xinerama; }
- inline static unsigned int numLockMask() { return _numLockMask; }
- inline static unsigned int scrollLockMask() { return _scrollLockMask; }
+ inline unsigned int numLockMask() const { return _num_lock_mask; }
+ inline unsigned int scrollLockMask() const { return _scroll_lock_mask; }
+
+ inline ::Display* operator*() const { return _display; }
//! Grabs the display
- static void grab();
+ void grab();
//! Ungrabs the display
- static void ungrab();
+ void ungrab();
/* TEMPORARY */
- static void grabButton(unsigned int button, unsigned int modifiers,
+ void grabButton(unsigned int button, unsigned int modifiers,
Window grab_window, bool owner_events,
unsigned int event_mask, int pointer_mode,
int keyboard_mode, Window confine_to, Cursor cursor,
- bool allow_scroll_lock);
- static void ungrabButton(unsigned int button, unsigned int modifiers,
- Window grab_window);
- static void grabKey(unsigned int keycode, unsigned int modifiers,
- Window grab_window, bool owner_events,
- int pointer_mode, int keyboard_mode, bool allow_scroll_lock);
- static void ungrabKey(unsigned int keycode, unsigned int modifiers,
- Window grab_window);
+ bool allow_scroll_lock) const;
+ void ungrabButton(unsigned int button, unsigned int modifiers,
+ Window grab_window) const;
+ void grabKey(unsigned int keycode, unsigned int modifiers,
+ Window grab_window, bool owner_events,
+ int pointer_mode, int keyboard_mode,
+ bool allow_scroll_lock) const;
+ void ungrabKey(unsigned int keycode, unsigned int modifiers,
+ Window grab_window) const;
};
}
{
XEvent e;
- while (XPending(Display::display)) {
- XNextEvent(Display::display, &e);
+ while (XPending(**display)) {
+ XNextEvent(**display, &e);
#if 0//defined(DEBUG)
printf("Event %d window %lx\n", e.type, e.xany.window);
case ButtonPress:
case ButtonRelease:
_lasttime = e.xbutton.time;
- e.xbutton.state &= ~(LockMask | Display::numLockMask() |
- Display::scrollLockMask());
+ e.xbutton.state &= ~(LockMask | display->numLockMask() |
+ display->scrollLockMask());
break;
case KeyPress:
- e.xkey.state &= ~(LockMask | Display::numLockMask() |
- Display::scrollLockMask());
+ e.xkey.state &= ~(LockMask | display->numLockMask() |
+ display->scrollLockMask());
break;
case MotionNotify:
_lasttime = e.xmotion.time;
- e.xmotion.state &= ~(LockMask | Display::numLockMask() |
- Display::scrollLockMask());
+ e.xmotion.state &= ~(LockMask | display->numLockMask() |
+ display->scrollLockMask());
break;
case PropertyNotify:
_lasttime = e.xproperty.time;
// FocusOut events just make us look for FocusIn events. They are ignored
// otherwise.
XEvent fi;
- if (XCheckTypedEvent(Display::display, FocusIn, &fi)) {
+ if (XCheckTypedEvent(**display, FocusIn, &fi)) {
//printf("Found FocusIn\n");
dispatchFocus(fi);
// dont unfocus the window we just focused!
xwc.sibling = e.xconfigurerequest.above;
xwc.stack_mode = e.xconfigurerequest.detail;
- XConfigureWindow(otk::Display::display, e.xconfigurerequest.window,
+ XConfigureWindow(**display, e.xconfigurerequest.window,
e.xconfigurerequest.value_mask, &xwc);
} else {
// grab a falback if it exists
return selectionRequestHandler(e.xselectionrequest);
default:
#ifdef SHAPE
- if (e.type == Display::shapeEventBase())
+ if (e.type == display->shapeEventBase())
return shapeHandler((*(XShapeEvent*)&e));
#endif // SHAPE
#ifdef XKB
- if (e.type == Display::xkbEventBase())
+ if (e.type == display->xkbEventBase())
return xkbHandler((*(XkbEvent*)&e));
#endif // XKB
;
FocusLabel::FocusLabel(Widget *parent)
: FocusWidget(parent), _text("")
{
- const ScreenInfo *info = Display::screenInfo(screen());
- _xftdraw = XftDrawCreate(Display::display, window(), info->visual(),
+ const ScreenInfo *info = display->screenInfo(screen());
+ _xftdraw = XftDrawCreate(**display, window(), info->visual(),
info->colormap());
}
_xft_init = true;
}
- if ((_xftfont = XftFontOpenName(Display::display, _screen_num,
+ if ((_xftfont = XftFontOpenName(**display, _screen_num,
_fontstring.c_str())))
return;
printf(_("Unable to load font: %s\n"), _fontstring.c_str());
printf(_("Trying fallback font: %s\n"), _fallback_font.c_str());
- if ((_xftfont = XftFontOpenName(Display::display, _screen_num,
+ if ((_xftfont = XftFontOpenName(**display, _screen_num,
_fallback_font.c_str())))
return;
Font::~Font(void)
{
if (_xftfont)
- XftFontClose(Display::display, _xftfont);
+ XftFontClose(**display, _xftfont);
}
c.color.green = 0;
c.color.blue = 0;
c.color.alpha = _tint | _tint << 8; // transparent shadow
- c.pixel = BlackPixel(Display::display, _screen_num);
+ c.pixel = BlackPixel(**display, _screen_num);
if (string.utf8())
XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
XGlyphInfo info;
if (string.utf8())
- XftTextExtentsUtf8(Display::display, _xftfont,
+ XftTextExtentsUtf8(**display, _xftfont,
(FcChar8*)string.c_str(), string.size(), &info);
else
- XftTextExtents8(Display::display, _xftfont,
+ XftTextExtents8(**display, _xftfont,
(FcChar8*)string.c_str(), string.size(), &info);
return info.xOff + (_shadow ? _offset : 0);
GCCacheContext::~GCCacheContext(void) {
if (gc)
- XFreeGC(Display::display, gc);
+ XFreeGC(**display, gc);
}
fontid = 0;
}
- XChangeGC(Display::display, gc, mask, &gcv);
+ XChangeGC(**display, gc, mask, &gcv);
}
XGCValues gcv;
fontid = gcv.font = _font->fid;
- XChangeGC(Display::display, gc, GCFont, &gcv);
+ XChangeGC(**display, gc, GCFont, &gcv);
}
GCCacheContext *GCCache::nextContext(unsigned int scr) {
- Window hd = Display::screenInfo(scr)->rootWindow();
+ Window hd = display->screenInfo(scr)->rootWindow();
GCCacheContext *c;
c = contexts[i];
if (! c->gc) {
- c->gc = XCreateGC(Display::display, hd, 0, 0);
+ c->gc = XCreateGC(**display, hd, 0, 0);
c->used = false;
c->screen = scr;
}
int _linewidth = 0, int _function = GXcopy,
int _subwindow = ClipByChildren)
: color(_color), font(_font), linewidth(_linewidth), function(_function),
- subwindow(_subwindow), cache(Display::gcCache()), item(0) { }
+ subwindow(_subwindow), cache(display->gcCache()), item(0) { }
inline ~Pen(void) { if (item) cache->release(item); }
Pixmap Image::render_solid(const Texture &texture) {
- Pixmap pixmap = XCreatePixmap(Display::display,
- control->getDrawable(), width,
+ Pixmap pixmap = XCreatePixmap(**display, control->getDrawable(), width,
height, control->getDepth());
if (pixmap == None) {
fprintf(stderr, "Image::render_solid: error creating pixmap\n");
Pen penlight(texture.lightColor());
Pen penshadow(texture.shadowColor());
- XFillRectangle(Display::display, pixmap, pen.gc(), 0, 0, width, height);
+ XFillRectangle(**display, pixmap, pen.gc(), 0, 0, width, height);
if (texture.texture() & Texture::Interlaced) {
Pen peninterlace(texture.colorTo());
for (unsigned int i = 0; i < height; i += 2)
- XDrawLine(Display::display, pixmap, peninterlace.gc(), 0, i, width, i);
+ XDrawLine(**display, pixmap, peninterlace.gc(), 0, i, width, i);
}
int left = 0, top = 0, right = width - 1, bottom = height - 1;
if (texture.texture() & Texture::Border) {
Pen penborder(texture.borderColor());
- XDrawRectangle(Display::display, pixmap, penborder.gc(),
+ XDrawRectangle(**display, pixmap, penborder.gc(),
left, top, right, bottom);
}
if (texture.texture() & Texture::Bevel1) {
if (texture.texture() & Texture::Raised) {
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
left, bottom, right, bottom);
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
right, bottom, right, top);
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
left, top, right, top);
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
left, bottom, left, top);
} else if (texture.texture() & Texture::Sunken) {
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
left, bottom, right, bottom);
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
right, bottom, right, top);
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
left, top, right, top);
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
left, bottom, left, top);
}
} else if (texture.texture() & Texture::Bevel2) {
if (texture.texture() & Texture::Raised) {
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
left + 1, bottom - 2, right - 2, bottom - 2);
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
right - 2, bottom - 2, right - 2, top + 1);
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
left + 1, top + 1, right - 2, top + 1);
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
left + 1, bottom - 2, left + 1, top + 1);
} else if (texture.texture() & Texture::Sunken) {
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
left + 1, bottom - 2, right - 2, bottom - 2);
- XDrawLine(Display::display, pixmap, penlight.gc(),
+ XDrawLine(**display, pixmap, penlight.gc(),
right - 2, bottom - 2, right - 2, top + 1);
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
left + 1, top + 1, right - 2, top + 1);
- XDrawLine(Display::display, pixmap, penshadow.gc(),
+ XDrawLine(**display, pixmap, penshadow.gc(),
left + 1, bottom - 2, left + 1, top + 1);
}
}
XImage *Image::renderXImage(void) {
XImage *image =
- XCreateImage(Display::display,
- control->getVisual(), control->getDepth(), ZPixmap, 0, 0,
- width, height, 32, 0);
+ XCreateImage(**display, control->getVisual(), control->getDepth(),
+ ZPixmap, 0, 0,width, height, 32, 0);
if (! image) {
fprintf(stderr, "Image::renderXImage: error creating XImage\n");
Pixmap Image::renderPixmap(void) {
Pixmap pixmap =
- XCreatePixmap(Display::display,
- control->getDrawable(), width, height, control->getDepth());
+ XCreatePixmap(**display, control->getDrawable(), width, height,
+ control->getDepth());
if (pixmap == None) {
fprintf(stderr, "Image::renderPixmap: error creating pixmap\n");
XImage *image = renderXImage();
if (! image) {
- XFreePixmap(Display::display, pixmap);
+ XFreePixmap(**display, pixmap);
return None;
}
if (! image->data) {
XDestroyImage(image);
- XFreePixmap(Display::display, pixmap);
+ XFreePixmap(**display, pixmap);
return None;
}
- XPutImage(Display::display, pixmap,
- DefaultGC(Display::display,
- control->getScreenInfo()->screen()),
+ XPutImage(**display, pixmap,
+ DefaultGC(**display, control->getScreenInfo()->screen()),
image, 0, 0, 0, 0, width, height);
if (image->data) {
colormap = screeninfo->colormap();
int count;
- XPixmapFormatValues *pmv = XListPixmapFormats(Display::display,
+ XPixmapFormatValues *pmv = XListPixmapFormats(**display,
&count);
if (pmv) {
bits_per_pixel = 0;
}
for (i = 0; i < ncolors; i++) {
- if (! XAllocColor(Display::display, colormap, &colors[i])) {
+ if (! XAllocColor(**display, colormap, &colors[i])) {
fprintf(stderr, "couldn't alloc color %i %i %i\n",
colors[i].red, colors[i].green, colors[i].blue);
colors[i].flags = 0;
for (i = 0; i < incolors; i++)
icolors[i].pixel = i;
- XQueryColors(Display::display, colormap, icolors, incolors);
+ XQueryColors(**display, colormap, icolors, incolors);
for (i = 0; i < ncolors; i++) {
if (! colors[i].flags) {
unsigned long chk = 0xffffffff, pixel, close = 0;
colors[i].green = icolors[close].green;
colors[i].blue = icolors[close].blue;
- if (XAllocColor(Display::display, colormap,
+ if (XAllocColor(**display, colormap,
&colors[i])) {
colors[i].flags = DoRed|DoGreen|DoBlue;
break;
colors[i].blue = (i * 0xffff) / (colors_per_channel - 1);;
colors[i].flags = DoRed|DoGreen|DoBlue;
- if (! XAllocColor(Display::display, colormap,
+ if (! XAllocColor(**display, colormap,
&colors[i])) {
fprintf(stderr, "couldn't alloc color %i %i %i\n",
colors[i].red, colors[i].green, colors[i].blue);
for (i = 0; i < incolors; i++)
icolors[i].pixel = i;
- XQueryColors(Display::display, colormap, icolors, incolors);
+ XQueryColors(**display, colormap, icolors, incolors);
for (i = 0; i < ncolors; i++) {
if (! colors[i].flags) {
unsigned long chk = 0xffffffff, pixel, close = 0;
colors[i].green = icolors[close].green;
colors[i].blue = icolors[close].blue;
- if (XAllocColor(Display::display, colormap,
+ if (XAllocColor(**display, colormap,
&colors[i])) {
colors[i].flags = DoRed|DoGreen|DoBlue;
break;
for (int i = 0; i < ncolors; i++)
*(pixels + i) = (*(colors + i)).pixel;
- XFreeColors(Display::display, colormap, pixels, ncolors, 0);
+ XFreeColors(**display, colormap, pixels, ncolors, 0);
delete [] colors;
}
CacheContainer::iterator it = cache.begin();
const CacheContainer::iterator end = cache.end();
for (; it != end; ++it)
- XFreePixmap(Display::display, it->pixmap);
+ XFreePixmap(**display, it->pixmap);
}
if (timer) {
timer->stop();
void ImageControl::installRootColormap(void) {
int ncmap = 0;
Colormap *cmaps =
- XListInstalledColormaps(Display::display, window, &ncmap);
+ XListInstalledColormaps(**display, window, &ncmap);
if (cmaps) {
bool install = True;
install = False;
if (install)
- XInstallColormap(Display::display, colormap);
+ XInstallColormap(**display, colormap);
XFree(cmaps);
}
CacheCleaner() {}
inline void operator()(const ImageControl::CachedImage& image) const {
if (ref_check(image))
- XFreePixmap(Display::display, image.pixmap);
+ XFreePixmap(**display, image.pixmap);
}
};
Label::Label(Widget *parent)
: Widget(parent), _text("")
{
- const ScreenInfo *info = Display::screenInfo(screen());
- _xftdraw = XftDrawCreate(Display::display, window(), info->visual(),
+ const ScreenInfo *info = display->screenInfo(screen());
+ _xftdraw = XftDrawCreate(**display, window(), info->visual(),
info->colormap());
}
Property::Property()
{
- assert(Display::display);
+ assert(**display);
// make sure asserts fire if there is a problem
memset(_atoms, 0, sizeof(_atoms));
*/
Atom Property::create(const char *name) const
{
- Atom a = XInternAtom(Display::display, name, False);
+ Atom a = XInternAtom(**display, name, False);
assert(a);
return a;
}
assert(win != None); assert(atom != None); assert(type != None);
assert(nelements == 0 || (nelements > 0 && data != (unsigned char *) 0));
assert(size == 8 || size == 16 || size == 32);
- XChangeProperty(Display::display, win, atom, type, size,
+ XChangeProperty(**display, win, atom, type, size,
(append ? PropModeAppend : PropModeReplace),
data, nelements);
}
bool ret = False;
// try get the first element
- result = XGetWindowProperty(Display::display, win, atom, 0l, 1l,
+ result = XGetWindowProperty(**display, win, atom, 0l, 1l,
False, AnyPropertyType, &ret_type, &ret_size,
nelements, &ret_bytes, &c_val);
ret = (result == Success && ret_type == type && ret_size == size &&
int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
if (remain > size/8 * (signed)maxread) // dont get more than the max
remain = size/8 * (signed)maxread;
- result = XGetWindowProperty(Display::display, win, atom, 0l,
+ result = XGetWindowProperty(**display, win, atom, 0l,
remain, False, type, &ret_type, &ret_size,
nelements, &ret_bytes, &c_val);
ret = (result == Success && ret_type == type && ret_size == size &&
void Property::erase(Window win, Atoms atom) const
{
assert(atom >= 0 && atom < NUM_ATOMS);
- XDeleteProperty(Display::display, win, _atoms[atom]);
+ XDeleteProperty(**display, win, _atoms[atom]);
}
}
ScreenInfo::ScreenInfo(unsigned int num) {
_screen = num;
- _root_window = RootWindow(Display::display, _screen);
+ _root_window = RootWindow(**display, _screen);
- _rect.setSize(WidthOfScreen(ScreenOfDisplay(Display::display,
+ _rect.setSize(WidthOfScreen(ScreenOfDisplay(**display,
_screen)),
- HeightOfScreen(ScreenOfDisplay(Display::display,
+ HeightOfScreen(ScreenOfDisplay(**display,
_screen)));
/*
If the default depth is at least 8 we will use that,
Preference is given to 24 bit over larger depths if 24 bit is an option.
*/
- _depth = DefaultDepth(Display::display, _screen);
- _visual = DefaultVisual(Display::display, _screen);
- _colormap = DefaultColormap(Display::display, _screen);
+ _depth = DefaultDepth(**display, _screen);
+ _visual = DefaultVisual(**display, _screen);
+ _colormap = DefaultColormap(**display, _screen);
if (_depth < 8) {
// search for a TrueColor Visual... if we can't find one...
vinfo_template.screen = _screen;
vinfo_template.c_class = TrueColor;
- vinfo_return = XGetVisualInfo(Display::display,
+ vinfo_return = XGetVisualInfo(**display,
VisualScreenMask | VisualClassMask,
&vinfo_template, &vinfo_nitems);
if (vinfo_return) {
if (best != -1) {
_depth = vinfo_return[best].depth;
_visual = vinfo_return[best].visual;
- _colormap = XCreateColormap(Display::display, _root_window, _visual,
+ _colormap = XCreateColormap(**display, _root_window, _visual,
AllocNone);
}
}
// get the default display string and strip the screen number
- string default_string = DisplayString(Display::display);
+ string default_string = DisplayString(**display);
const string::size_type pos = default_string.rfind(".");
if (pos != string::npos)
default_string.resize(pos);
in future versions we should be able, so the 'activeness' is checked
on a pre-screen basis anyways.
*/
- if (XineramaIsActive(Display::display)) {
+ if (XineramaIsActive(**display)) {
/*
If Xinerama is being used, there there is only going to be one screen
present. We still, of course, want to use the screen class, but that
never be more than one screen present with Xinerama active.
*/
int num;
- XineramaScreenInfo *info = XineramaQueryScreens(Display::display,
- &num);
+ XineramaScreenInfo *info = XineramaQueryScreens(**display, &num);
if (num > 0 && info) {
_xinerama_areas.reserve(num);
for (int i = 0; i < num; ++i) {
delete font;
if (close_button.mask != None)
- XFreePixmap(Display::display, close_button.mask);
+ XFreePixmap(**display, close_button.mask);
if (max_button.mask != None)
- XFreePixmap(Display::display, max_button.mask);
+ XFreePixmap(**display, max_button.mask);
if (icon_button.mask != None)
- XFreePixmap(Display::display, icon_button.mask);
+ XFreePixmap(**display, icon_button.mask);
if (stick_button.mask != None)
- XFreePixmap(Display::display, stick_button.mask);
+ XFreePixmap(**display, stick_button.mask);
max_button.mask = None;
close_button.mask = None;
}
if (close_button.mask != None)
- XFreePixmap(Display::display, close_button.mask);
+ XFreePixmap(**display, close_button.mask);
if (max_button.mask != None)
- XFreePixmap(Display::display, max_button.mask);
+ XFreePixmap(**display, max_button.mask);
if (icon_button.mask != None)
- XFreePixmap(Display::display, icon_button.mask);
+ XFreePixmap(**display, icon_button.mask);
if (stick_button.mask != None)
- XFreePixmap(Display::display, stick_button.mask);
+ XFreePixmap(**display, stick_button.mask);
close_button.mask = max_button.mask = icon_button.mask
= icon_button.mask = None;
// load bevel, border and handle widths
- const ScreenInfo *s_info = Display::screenInfo(screen_number);
+ const ScreenInfo *s_info = display->screenInfo(screen_number);
unsigned int width = s_info->rect().width();
if (! style.getValue("handleWidth", handle_width) ||
void Style::readDatabaseMask(const std::string &rname, PixmapMask &pixmapMask,
const Configuration &style) {
- Window root_window = Display::screenInfo(screen_number)->rootWindow();
+ Window root_window = display->screenInfo(screen_number)->rootWindow();
std::string s;
int hx, hy; //ignored
int ret = BitmapOpenFailed; //default to failure.
if (style.getValue(rname, s)) {
if (s[0] != '/' && s[0] != '~') {
std::string xbmFile = std::string("~/.openbox/buttons/") + s;
- ret = XReadBitmapFile(Display::display, root_window,
+ ret = XReadBitmapFile(**display, root_window,
expandTilde(xbmFile).c_str(), &pixmapMask.w,
&pixmapMask.h, &pixmapMask.mask, &hx, &hy);
if (ret != BitmapSuccess) {
xbmFile = std::string(BUTTONSDIR) + "/" + s;
- ret = XReadBitmapFile(Display::display, root_window,
+ ret = XReadBitmapFile(**display, root_window,
xbmFile.c_str(), &pixmapMask.w,
&pixmapMask.h, &pixmapMask.mask, &hx, &hy);
}
} else
- ret = XReadBitmapFile(Display::display, root_window,
+ ret = XReadBitmapFile(**display, root_window,
expandTilde(s).c_str(), &pixmapMask.w,
&pixmapMask.h, &pixmapMask.mask, &hx, &hy);
return ParentRelative;
if (screen() == ~(0u))
- scrn = DefaultScreen(Display::display);
+ scrn = DefaultScreen(**display);
assert(ctrl != 0);
Pixmap ret = ctrl->renderImage(width, height, *this);
fd_set rfds;
timeval now, tm, *timeout = (timeval *) 0;
- const int xfd = ConnectionNumber(Display::display);
+ const int xfd = ConnectionNumber(**display);
FD_ZERO(&rfds);
FD_SET(xfd, &rfds); // break on any x events
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
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);
void Widget::move(int x, int y)
{
_rect.setPos(x, y);
- XMoveWindow(Display::display, _window, x, y);
+ XMoveWindow(**display, _window, x, y);
_ignore_config++;
}
_rect = Rect(x, y, width, height);
_dirty = true;
- XMoveResizeWindow(Display::display, _window, x, y, width, height);
+ XMoveResizeWindow(**display, _window, x, y, width, height);
_ignore_config++;
}
(*it)->show();
}
- XMapWindow(Display::display, _window);
+ XMapWindow(**display, _window);
_visible = true;
}
(*it)->hide();
}
- XUnmapWindow(Display::display, _window);
+ XUnmapWindow(**display, _window);
_visible = false;
}
bool Widget::grabMouse(void)
{
- Status ret = XGrabPointer(Display::display, _window, True,
+ Status ret = XGrabPointer(**display, _window, True,
(ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask | EnterWindowMask |
LeaveWindowMask | PointerMotionMask),
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;
if (! _grabbed_keyboard)
return;
- XUngrabKeyboard(Display::display, CurrentTime);
+ XUngrabKeyboard(**display, CurrentTime);
_grabbed_keyboard = false;
}
_bg_pixmap = _texture->render(_rect.width(), _rect.height(), _bg_pixmap);
if (_bg_pixmap) {
- XSetWindowBackgroundPixmap(Display::display, _window, _bg_pixmap);
+ XSetWindowBackgroundPixmap(**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);
+ XSetWindowBackground(**display, _window, pix);
}
}
}
if (_dirty) {
adjust();
render();
- XClearWindow(Display::display, _window);
+ XClearWindow(**display, _window);
}
WidgetList::iterator it = _children.begin(), end = _children.end();
inline const Color *borderColor(void) const { return _bcolor; }
virtual void setBorderColor(const Color *color) {
assert(color); _bcolor = color;
- XSetWindowBorder(Display::display, _window, color->pixel());
+ XSetWindowBorder(**display, _window, color->pixel());
}
inline int borderWidth(void) const { return _bwidth; }
void setBorderWidth(int width) {
_bwidth = width;
- XSetWindowBorderWidth(Display::display, _window, width);
+ XSetWindowBorderWidth(**display, _window, width);
}
virtual void addChild(Widget *child, bool front = false);
inline Cursor cursor(void) const { return _cursor; }
void setCursor(Cursor cursor) {
_cursor = cursor;
- XDefineCursor(Display::display, _window, _cursor);
+ XDefineCursor(**display, _window, _cursor);
}
inline int bevelWidth(void) const { return _bevel_width; }