Skip to content

Commit

Permalink
unsigned and const cleanups
Browse files Browse the repository at this point in the history
ScreenInfoList now uses a vector
ScreenInfoList contains objects not pointers, getScreenInfo() returns a pointer
however.  It is either this or support exceptions.
  • Loading branch information
shaleh committed Mar 19, 2002
1 parent cd3db4f commit 91f0fde
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 65 deletions.
21 changes: 8 additions & 13 deletions src/BaseDisplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name) {

XSetErrorHandler((XErrorHandler) handleXErrors);

for (int i = 0; i < number_of_screens; ++i) {
ScreenInfo *screeninfo = new ScreenInfo(this, i);
screenInfoList.reserve(number_of_screens);
for (unsigned int i = 0; i < number_of_screens; ++i) {
ScreenInfo screeninfo(this, i);
screenInfoList.push_back(screeninfo);
}

Expand Down Expand Up @@ -275,9 +276,6 @@ BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name) {


BaseDisplay::~BaseDisplay(void) {
std::for_each(screenInfoList.begin(), screenInfoList.end(),
PointerAssassin());

// we don't create the BTimers, we don't delete them

XCloseDisplay(display);
Expand Down Expand Up @@ -381,17 +379,14 @@ void BaseDisplay::ungrabButton(unsigned int button, unsigned int modifiers,
}


ScreenInfo* BaseDisplay::getScreenInfo(unsigned int s) {
if (s < screenInfoList.size()) {
ScreenInfoList::iterator it = screenInfoList.begin();
for (; s > 0; ++it, --s); // increment interator to index
return *it;
}
return (ScreenInfo*) 0;
const ScreenInfo* BaseDisplay::getScreenInfo(unsigned int s) const {
if (s < screenInfoList.size())
return &screenInfoList[s];
return (const ScreenInfo*) 0;
}


ScreenInfo::ScreenInfo(BaseDisplay *d, int num) {
ScreenInfo::ScreenInfo(BaseDisplay *d, unsigned int num) {
basedisplay = d;
screen_number = num;

Expand Down
27 changes: 13 additions & 14 deletions src/BaseDisplay.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>

#include <list>
#include <vector>

// forward declaration
class BaseDisplay;
Expand All @@ -50,12 +50,12 @@ private:
Bool _startup, _shutdown;
Display *display;

typedef std::list<ScreenInfo*> ScreenInfoList;
typedef std::vector<ScreenInfo> ScreenInfoList;
ScreenInfoList screenInfoList;
TimerQueue timerList;

const char *display_name, *application_name;
int number_of_screens, colors_per_channel;
unsigned int number_of_screens;

// no copying!
BaseDisplay(const BaseDisplay &);
Expand All @@ -73,7 +73,7 @@ public:
BaseDisplay(const char *app_name, const char *dpy_name = 0);
virtual ~BaseDisplay(void);

ScreenInfo* getScreenInfo(unsigned int s);
const ScreenInfo* getScreenInfo(unsigned int s) const;

inline const Bool hasShapeExtensions(void) const
{ return shape.extensions; }
Expand All @@ -82,14 +82,14 @@ public:
inline const Bool isStartup(void) const
{ return _startup; }

inline Display *getXDisplay(void) { return display; }
inline Display *getXDisplay(void) const { return display; }

inline const char *getXDisplayName(void) const
{ return display_name; }
inline const char *getApplicationName(void) const
{ return application_name; }

inline const int getNumberOfScreens(void) const
inline const unsigned int getNumberOfScreens(void) const
{ return number_of_screens; }
inline const int getShapeEventBase(void) const
{ return shape.event_basep; }
Expand Down Expand Up @@ -123,24 +123,23 @@ private:
Window root_window;
Colormap colormap;

int depth, screen_number;
int depth;
unsigned int screen_number;
XRectangle rect;

protected:
const XRectangle& getRect(void) const { return rect; }

public:
ScreenInfo(BaseDisplay *d, int num);
ScreenInfo(BaseDisplay *d, unsigned int num);

inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }

inline Visual *getVisual(void) { return visual; }
inline BaseDisplay *getBaseDisplay(void) const { return basedisplay; }
inline Visual *getVisual(void) const { return visual; }
inline const Window getRootWindow(void) const { return root_window; }
inline const Colormap &getColormap(void) const { return colormap; }

inline const int getDepth(void) const { return depth; }
inline const int getScreenNumber(void) const { return screen_number; }

inline const unsigned int getScreenNumber(void) const
{ return screen_number; }
inline const unsigned short getWidth(void) const { return rect.width; }
inline const unsigned short getHeight(void) const { return rect.height; }
};
Expand Down
2 changes: 1 addition & 1 deletion src/Iconmenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Iconmenu::itemSelected(int button, int index) {
if (button != 1)
return;

if (index >= 0 && index < screen->getIconCount()) {
if (index >= 0 && index < (signed) screen->getIconCount()) {
BlackboxWindow *win = screen->getIcon(index);

if (win) {
Expand Down
11 changes: 6 additions & 5 deletions src/Image.hh
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,17 @@ public:
unsigned long pixel1, pixel2, texture;
};

BImageControl(BaseDisplay *dpy, ScreenInfo *scrn, Bool _dither= False,
int _cpc = 4, unsigned long cache_timeout = 300000l,
BImageControl(BaseDisplay *dpy, const ScreenInfo *scrn,
Bool _dither= False, int _cpc = 4,
unsigned long cache_timeout = 300000l,
unsigned long cmax = 200l);
virtual ~BImageControl(void);

inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
inline BaseDisplay *getBaseDisplay(void) const { return basedisplay; }

inline const Bool doDither(void) { return dither; }

inline ScreenInfo *getScreenInfo(void) { return screeninfo; }
inline const ScreenInfo *getScreenInfo(void) { return screeninfo; }

inline const Window getDrawable(void) const { return window; }

Expand Down Expand Up @@ -221,7 +222,7 @@ public:
private:
Bool dither;
BaseDisplay *basedisplay;
ScreenInfo *screeninfo;
const ScreenInfo *screeninfo;
#ifdef TIMEDCACHE
BTimer *timer;
#endif // TIMEDCACHE
Expand Down
5 changes: 3 additions & 2 deletions src/ImageControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ static unsigned long bsqrt(unsigned long x) {
}


BImageControl::BImageControl(BaseDisplay *dpy, ScreenInfo *scrn, Bool _dither,
int _cpc, unsigned long cache_timeout,
BImageControl::BImageControl(BaseDisplay *dpy, const ScreenInfo *scrn,
Bool _dither, int _cpc,
unsigned long cache_timeout,
unsigned long cmax)
{
basedisplay = dpy;
Expand Down
2 changes: 1 addition & 1 deletion src/Screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static const char *getFontSize(const char *pattern, int *size) {
}


BScreen::BScreen(Blackbox *bb, int scrn) : ScreenInfo(bb, scrn) {
BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
blackbox = bb;

event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
Expand Down
2 changes: 1 addition & 1 deletion src/Screen.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public:
WindowLower, WindowStick, WindowKill, SetStyle };
enum FocusModel { SloppyFocus, ClickToFocus };

BScreen(Blackbox *bb, int scrn);
BScreen(Blackbox *bb, unsigned int scrn);
~BScreen(void);

inline const Bool isToolbarOnTop(void) const
Expand Down
2 changes: 1 addition & 1 deletion src/blackbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Blackbox::Blackbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
cursor.ll_angle = XCreateFontCursor(getXDisplay(), XC_ll_angle);
cursor.lr_angle = XCreateFontCursor(getXDisplay(), XC_lr_angle);

for (int i = 0; i < getNumberOfScreens(); i++) {
for (unsigned int i = 0; i < getNumberOfScreens(); i++) {
BScreen *screen = new BScreen(this, i);

if (! screen->isScreenManaged()) {
Expand Down
59 changes: 32 additions & 27 deletions util/bsetroot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif // HAVE_STDIO_H

#include "../src/i18n.hh"
#include "../src/Util.hh"
#include "bsetroot.hh"


Expand Down Expand Up @@ -80,7 +81,7 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
}

img_ctrl = new BImageControl*[getNumberOfScreens()];
for (int i = 0; i < getNumberOfScreens(); i++)
for (unsigned int i = 0; i < getNumberOfScreens(); i++)
img_ctrl[i] = new BImageControl(this, getScreenInfo(i), True);

if (sol && fore) solid();
Expand All @@ -95,8 +96,7 @@ bsetroot::~bsetroot(void) {

XKillClient(getXDisplay(), AllTemporary);

for (int i = 0; i < getNumberOfScreens(); i++)
delete img_ctrl[i];
std::for_each(img_ctrl, img_ctrl + getNumberOfScreens(), PointerAssassin());

delete [] img_ctrl;
}
Expand All @@ -110,14 +110,15 @@ void bsetroot::setPixmapProperty(int screen, Pixmap pixmap) {
unsigned long length, after;
unsigned char *data;
int mode;

const ScreenInfo *screen_info = getScreenInfo(screen);

if (rootpmap_id == None)
rootpmap_id = XInternAtom(getXDisplay(), "_XROOTPMAP_ID", False);

XGrabServer(getXDisplay());

/* Clear out the old pixmap */
XGetWindowProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
XGetWindowProperty(getXDisplay(), screen_info->getRootWindow(),
rootpmap_id, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data);

Expand All @@ -129,11 +130,11 @@ void bsetroot::setPixmapProperty(int screen, Pixmap pixmap) {
mode = PropModeAppend;
}
if (pixmap) {
XChangeProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
XChangeProperty(getXDisplay(), screen_info->getRootWindow(),
rootpmap_id, XA_PIXMAP, 32, mode,
(unsigned char *) &pixmap, 1);
} else {
XDeleteProperty(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
XDeleteProperty(getXDisplay(), screen_info->getRootWindow(),
rootpmap_id);
}

Expand All @@ -160,18 +161,19 @@ Pixmap bsetroot::duplicatePixmap(int screen, Pixmap pixmap,


void bsetroot::solid(void) {
for (int screen = 0; screen < getNumberOfScreens(); screen++) {
for (unsigned int screen = 0; screen < getNumberOfScreens(); screen++) {
BColor c;
const ScreenInfo *screen_info = getScreenInfo(screen);

img_ctrl[screen]->parseColor(&c, fore);
if (! c.isAllocated()) c.setPixel(BlackPixel(getXDisplay(), screen));

XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
XSetWindowBackground(getXDisplay(), screen_info->getRootWindow(),
c.getPixel());
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XClearWindow(getXDisplay(), screen_info->getRootWindow());

Pixmap pixmap = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
screen_info->getRootWindow(),
8, 8, DefaultDepth(getXDisplay(), screen));
XSetForeground(getXDisplay(), DefaultGC(getXDisplay(), screen),
c.getPixel());
Expand All @@ -189,7 +191,7 @@ void bsetroot::modula(int x, int y) {
char data[32];
long pattern;

int screen, i;
unsigned int screen, i;

for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) {
for (i = 0; i < 16; i++) {
Expand All @@ -212,10 +214,11 @@ void bsetroot::modula(int x, int y) {
GC gc;
Pixmap bitmap;
XGCValues gcv;
const ScreenInfo *screen_info = getScreenInfo(screen);

bitmap =
XCreateBitmapFromData(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), data,
screen_info->getRootWindow(), data,
16, 16);

img_ctrl[screen]->parseColor(&f, fore);
Expand All @@ -227,35 +230,37 @@ void bsetroot::modula(int x, int y) {
gcv.foreground = f.getPixel();
gcv.background = b.getPixel();

gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
gc = XCreateGC(getXDisplay(), screen_info->getRootWindow(),
GCForeground | GCBackground, &gcv);

Pixmap pixmap = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
16, 16, getScreenInfo(screen)->getDepth());
screen_info->getRootWindow(),
16, 16, screen_info->getDepth());

XCopyPlane(getXDisplay(), bitmap, pixmap, gc,
0, 0, 16, 16, 0, 0, 1l);
XSetWindowBackgroundPixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
screen_info->getRootWindow(),
pixmap);
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XClearWindow(getXDisplay(), screen_info->getRootWindow());

setPixmapProperty(screen,
duplicatePixmap(screen, pixmap, 16, 16));

XFreeGC(getXDisplay(), gc);
XFreePixmap(getXDisplay(), bitmap);

if (! (getScreenInfo(screen)->getVisual()->c_class & 1))
if (! (screen_info->getVisual()->c_class & 1))
XFreePixmap(getXDisplay(), pixmap);
}
}


void bsetroot::gradient(void) {
for (int screen = 0; screen < getNumberOfScreens(); screen++) {
for (unsigned int screen = 0; screen < getNumberOfScreens(); screen++) {
BTexture texture;
const ScreenInfo *screen_info = getScreenInfo(screen);

img_ctrl[screen]->parseTexture(&texture, grad);
img_ctrl[screen]->parseColor(texture.getColor(), fore);
img_ctrl[screen]->parseColor(texture.getColorTo(), back);
Expand All @@ -266,21 +271,21 @@ void bsetroot::gradient(void) {
texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen));

Pixmap pixmap =
img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(),
getScreenInfo(screen)->getHeight(),
img_ctrl[screen]->renderImage(screen_info->getWidth(),
screen_info->getHeight(),
&texture);

XSetWindowBackgroundPixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
screen_info->getRootWindow(),
pixmap);
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XClearWindow(getXDisplay(), screen_info->getRootWindow());

setPixmapProperty(screen,
duplicatePixmap(screen, pixmap,
getScreenInfo(screen)->getWidth(),
getScreenInfo(screen)->getHeight()));
screen_info->getWidth(),
screen_info->getHeight()));

if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
if (! (screen_info->getVisual()->c_class & 1)) {
img_ctrl[screen]->removeImage(pixmap);
}
}
Expand Down

0 comments on commit 91f0fde

Please sign in to comment.