summaryrefslogtreecommitdiff
path: root/otk
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-03-16 21:11:39 +0000
committerDana Jansens <danakj@orodu.net>2003-03-16 21:11:39 +0000
commitf8a47de5ec444c452093371e3db16857eb39a490 (patch)
tree31db2567842d98232775f9980f7a8d2586c0ac71 /otk
parent8ba0586bcbdc7fe9648f1063812126d71a041670 (diff)
merge the C branch into HEAD
Diffstat (limited to 'otk')
-rw-r--r--otk/Makefile.am4
-rw-r--r--otk/display.cc102
-rw-r--r--otk/display.hh35
-rw-r--r--otk/screeninfo.cc46
-rw-r--r--otk/screeninfo.hh5
5 files changed, 62 insertions, 130 deletions
diff --git a/otk/Makefile.am b/otk/Makefile.am
index 566fafcf..58fe305d 100644
--- a/otk/Makefile.am
+++ b/otk/Makefile.am
@@ -8,7 +8,7 @@ lib_LTLIBRARIES=libotk.la
libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc util.cc \
renderstyle.cc rendercolor.cc pseudorendercontrol.cc \
- display.cc font.cc screeninfo.cc property.cc timer.cc \
+ display.cc font.cc property.cc timer.cc \
eventdispatcher.cc eventhandler.cc ustring.cc \
widget.cc application.cc label.cc appwidget.cc button.cc \
otk.cc messagedialog.cc
@@ -19,7 +19,7 @@ includeotk_HEADERS=application.hh appwidget.hh assassin.hh button.hh \
display.hh eventdispatcher.hh eventhandler.hh font.hh \
label.hh otk.hh point.hh property.hh pseudorendercontrol.hh\
rect.hh rendercolor.hh rendercontrol.hh renderstyle.hh \
- rendertexture.hh screeninfo.hh size.hh strut.hh surface.hh \
+ rendertexture.hh size.hh strut.hh surface.hh \
timer.hh truerendercontrol.hh ustring.hh util.hh widget.hh \
messagedialog.hh ../config.h
diff --git a/otk/display.cc b/otk/display.cc
index 9817b81b..d4580a0e 100644
--- a/otk/display.cc
+++ b/otk/display.cc
@@ -3,8 +3,6 @@
#include "config.h"
#include "display.hh"
-#include "screeninfo.hh"
-#include "rendercontrol.hh"
#include "util.hh"
extern "C" {
@@ -68,8 +66,8 @@ static int xerrorHandler(::Display *d, XErrorEvent *e)
}
-Display::Display()
- : _display(0),
+Display::Display(::Display *d)
+ : _display(d),
_xkb(false),
_xkb_event_basep(0),
_shape(false),
@@ -79,21 +77,15 @@ Display::Display()
_mask_list(),
_num_lock_mask(0),
_scroll_lock_mask(0),
- _grab_count(0),
- _screeninfo_list(0),
- _rendercontrol_list(0)
+ _grab_count(0)
{
int junk;
(void)junk;
+ assert(_display);
+
display = this;
- // Open the X display
- if (!(_display = XOpenDisplay(NULL))) {
- printf(_("Unable to open connection to the X server. Please set the \n\
-DISPLAY environment variable approriately.\n\n"));
- ::exit(1);
- }
if (fcntl(ConnectionNumber(_display), F_SETFD, 1) == -1) {
printf(_("Couldn't mark display connection as close-on-exec.\n\n"));
::exit(1);
@@ -159,13 +151,51 @@ DISPLAY environment variable approriately.\n\n"));
_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, and create their
- // RenderControl
- _screeninfo_list = new ScreenInfo*[ScreenCount(_display)];
- _rendercontrol_list = new RenderControl*[ScreenCount(_display)];
- for (int i = 0; i < ScreenCount(_display); ++i) {
- _screeninfo_list[i] = new ScreenInfo(i);
- _rendercontrol_list[i] = RenderControl::createRenderControl(i);
+ /*
+ If the default depth is at least 8 we will use that,
+ otherwise we try to find the largest TrueColor visual.
+ Preference is given to 24 bit over larger depths if 24 bit is an option.
+ */
+
+ int screen = DefaultScreen(_display);
+ _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...
+ // we will use the default visual for the screen
+ XVisualInfo vinfo_template, *vinfo_return;
+ int vinfo_nitems;
+ int best = -1;
+
+ vinfo_template.screen = screen;
+ vinfo_template.c_class = TrueColor;
+
+ vinfo_return = XGetVisualInfo(_display,
+ VisualScreenMask | VisualClassMask,
+ &vinfo_template, &vinfo_nitems);
+ if (vinfo_return) {
+ int max_depth = 1;
+ for (int i = 0; i < vinfo_nitems; ++i) {
+ if (vinfo_return[i].depth > max_depth) {
+ if (max_depth == 24 && vinfo_return[i].depth > 24)
+ break; // prefer 24 bit over 32
+ max_depth = vinfo_return[i].depth;
+ best = i;
+ }
+ }
+ if (max_depth < _depth) best = -1;
+ }
+
+ if (best != -1) {
+ _depth = vinfo_return[best].depth;
+ _visual = vinfo_return[best].visual;
+ _colormap = XCreateColormap(_display, RootWindow(_display, screen),
+ _visual, AllocNone);
+ }
+
+ XFree(vinfo_return);
}
}
@@ -177,42 +207,10 @@ Display::~Display()
XFreeModifiermap(_modmap);
- for (int i = 0; i < ScreenCount(_display); ++i) {
- delete _rendercontrol_list[i];
- delete _screeninfo_list[i];
- }
- delete [] _rendercontrol_list;
- delete [] _screeninfo_list;
-
XCloseDisplay(_display);
}
-const ScreenInfo* Display::screenInfo(int snum) const
-{
- assert(snum >= 0);
- assert(snum < (signed) ScreenCount(_display));
- return _screeninfo_list[snum];
-}
-
-
-const ScreenInfo* Display::findScreen(Window root) const
-{
- for (int i = 0; i < ScreenCount(_display); ++i)
- if (_screeninfo_list[i]->rootWindow() == root)
- return _screeninfo_list[i];
- return 0;
-}
-
-
-const RenderControl *Display::renderControl(int snum) const
-{
- assert(snum >= 0);
- assert(snum < (signed) ScreenCount(_display));
- return _rendercontrol_list[snum];
-}
-
-
void Display::setIgnoreErrors(bool t)
{
// sync up so that anything already sent is/isn't ignored!
diff --git a/otk/display.hh b/otk/display.hh
index 81dd27c5..25c1b45a 100644
--- a/otk/display.hh
+++ b/otk/display.hh
@@ -8,7 +8,6 @@ extern "C" {
namespace otk {
-class ScreenInfo;
class RenderControl;
class Display;
@@ -56,38 +55,24 @@ private:
//! When true, X errors will be ignored. Use with care.
bool _ignore_errors;
- //! A list of information for all screens on the display
- ScreenInfo** _screeninfo_list;
+ //! The optimal visual for the display
+ Visual *_visual;
- //! A list of RenderControl objects, which are used for all graphics on a
- //! screen
- RenderControl** _rendercontrol_list;
+ //! Our colormap built for the optimal visual
+ Colormap _colormap;
+ //! The depth of our optimal visual
+ int _depth;
+
public:
- //! Initializes the class, opens the X display
+ //! Wraps an open Display connection
/*!
- The DISPLAY environment variable is used to choose the display.
- @see Display::display
+ @param d An open Display connection.
*/
- Display();
+ Display(::Display *d);
//! Destroys the class, closes the X display
~Display();
- //! Gets information on a specific screen
- /*!
- Returns a ScreenInfo class, which contains information for a screen on the
- display.
- @param snum The screen number of the screen to retrieve info on
- @return Info on the requested screen, in a ScreenInfo class
- */
- const ScreenInfo* screenInfo(int snum) const;
-
- //! Find a ScreenInfo based on a root window
- const ScreenInfo* findScreen(Window root) const;
-
- //! Gets the RenderControl for a screen
- const RenderControl *renderControl(int snum) const;
-
//! Returns if the display has the xkb extension available
inline bool xkb() const { return _xkb; }
//! Returns the xkb extension's event base
diff --git a/otk/screeninfo.cc b/otk/screeninfo.cc
index 689837d0..368ae982 100644
--- a/otk/screeninfo.cc
+++ b/otk/screeninfo.cc
@@ -26,52 +26,6 @@ ScreenInfo::ScreenInfo(int num) {
_screen)),
HeightOfScreen(ScreenOfDisplay(**display,
_screen)));
- /*
- If the default depth is at least 8 we will use that,
- otherwise we try to find the largest TrueColor visual.
- Preference is given to 24 bit over larger depths if 24 bit is an option.
- */
-
- _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...
- // we will use the default visual for the screen
- XVisualInfo vinfo_template, *vinfo_return;
- int vinfo_nitems;
- int best = -1;
-
- vinfo_template.screen = _screen;
- vinfo_template.c_class = TrueColor;
-
- vinfo_return = XGetVisualInfo(**display,
- VisualScreenMask | VisualClassMask,
- &vinfo_template, &vinfo_nitems);
- if (vinfo_return) {
- int max_depth = 1;
- for (int i = 0; i < vinfo_nitems; ++i) {
- if (vinfo_return[i].depth > max_depth) {
- if (max_depth == 24 && vinfo_return[i].depth > 24)
- break; // prefer 24 bit over 32
- max_depth = vinfo_return[i].depth;
- best = i;
- }
- }
- if (max_depth < _depth) best = -1;
- }
-
- if (best != -1) {
- _depth = vinfo_return[best].depth;
- _visual = vinfo_return[best].visual;
- _colormap = XCreateColormap(**display, _root_window, _visual,
- AllocNone);
- }
-
- XFree(vinfo_return);
- }
-
// get the default display string and strip the screen number
string default_string = DisplayString(**display);
const string::size_type pos = default_string.rfind(".");
diff --git a/otk/screeninfo.hh b/otk/screeninfo.hh
index 17063e37..93e835fa 100644
--- a/otk/screeninfo.hh
+++ b/otk/screeninfo.hh
@@ -16,11 +16,6 @@ namespace otk {
class ScreenInfo {
private:
- Visual *_visual;
- Window _root_window;
- Colormap _colormap;
-
- int _depth;
int _screen;
std::string _display_string;
Size _size;