removed BaseDisplay

This commit is contained in:
fluxgen 2003-05-10 15:44:15 +00:00
parent 980060a509
commit 4ccdb5ebb9
3 changed files with 306 additions and 308 deletions

View file

@ -4,7 +4,7 @@ INCLUDES=-I../src/FbTk/
bin_SCRIPTS = fbsetbg fluxbox-generate_menu
bin_PROGRAMS = bsetroot
bsetroot_SOURCES = bsetroot.cc bsetroot.hh
bsetroot_LDADD = ../src/BaseDisplay.o ../src/i18n.o ../src/FbAtoms.o \
bsetroot_LDADD = ../src/ScreenInfo.o ../src/i18n.o ../src/FbAtoms.o \
../src/FbTk/libFbTk.a
MAINTAINERCLEANFILES = Makefile.in
@ -13,5 +13,5 @@ EXTRA_DIST=fbsetbg fluxbox-generate_menu
distclean-local:
rm -f *\~ Makefile.in
bsetroot.o: bsetroot.cc ../config.h bsetroot.hh ../src/BaseDisplay.hh ../src/FbAtoms.hh
bsetroot.o: bsetroot.cc ../config.h bsetroot.hh ../src/ScreenInfo.hh ../src/FbAtoms.hh

View file

@ -18,12 +18,13 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// $Id: bsetroot.cc,v 1.15 2003/02/17 13:33:36 fluxgen Exp $
// $Id: bsetroot.cc,v 1.16 2003/05/10 15:44:15 fluxgen Exp $
#include "bsetroot.hh"
#include "../src/i18n.hh"
#include "../src/FbTk/ImageControl.hh"
#include "../src/ScreenInfo.hh"
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -39,7 +40,7 @@
using namespace std;
bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
: BaseDisplay(argv[0], dpy_name) {
: FbTk::App(dpy_name), m_app_name(argv[0]) {
pixmaps = (Pixmap *) 0;
grad = fore = back = (char *) 0;
@ -47,8 +48,8 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
bool mod = false, sol = false, grd = false;
int mod_x = 0, mod_y = 0, i = 0;
img_ctrl = new FbTk::ImageControl*[getNumberOfScreens()];
for (; i < getNumberOfScreens(); i++) {
img_ctrl = new FbTk::ImageControl*[ScreenCount(display())];
for (; i < ScreenCount(display()); i++) {
img_ctrl[i] = new FbTk::ImageControl(i, true);
}
@ -110,13 +111,12 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
getMessage(
FBNLS::bsetrootSet, FBNLS::bsetrootMustSpecify,
"%s: error: must specify on of: -solid, -mod, -gradient\n"),
getApplicationName());
m_app_name);
usage(2);
}
display = getXDisplay();
num_screens = getNumberOfScreens();
num_screens = ScreenCount(display());
if (sol && fore)
solid();
@ -131,10 +131,10 @@ bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
bsetroot::~bsetroot() {
XKillClient(display, AllTemporary);
XKillClient(display(), AllTemporary);
if (pixmaps) { // should always be true
XSetCloseDownMode(display, RetainTemporary);
XSetCloseDownMode(display(), RetainTemporary);
delete [] pixmaps;
}
@ -159,30 +159,30 @@ void bsetroot::setRootAtoms(Pixmap pixmap, int screen) {
int format;
unsigned long length, after;
atom_root = XInternAtom(display, "_XROOTMAP_ID", true);
atom_eroot = XInternAtom(display, "ESETROOT_PMAP_ID", true);
atom_root = XInternAtom(display(), "_XROOTMAP_ID", true);
atom_eroot = XInternAtom(display(), "ESETROOT_PMAP_ID", true);
ScreenInfo screen_info(screen);
// doing this to clean up after old background
if (atom_root != None && atom_eroot != None) {
XGetWindowProperty(display, getScreenInfo(screen)->getRootWindow(),
XGetWindowProperty(display(), screen_info.getRootWindow(),
atom_root, 0L, 1L, false, AnyPropertyType,
&type, &format, &length, &after, &data_root);
if (type == XA_PIXMAP) {
XGetWindowProperty(display, getScreenInfo(screen)->getRootWindow(),
XGetWindowProperty(display(), screen_info.getRootWindow(),
atom_eroot, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data_eroot);
if (data_root && data_eroot && type == XA_PIXMAP &&
*((Pixmap *) data_root) == *((Pixmap *) data_eroot)) {
XKillClient(display, *((Pixmap *) data_root));
XKillClient(display(), *((Pixmap *) data_root));
}
}
}
atom_root = XInternAtom(display, "_XROOTPMAP_ID", false);
atom_eroot = XInternAtom(display, "ESETROOT_PMAP_ID", false);
atom_root = XInternAtom(display(), "_XROOTPMAP_ID", false);
atom_eroot = XInternAtom(display(), "ESETROOT_PMAP_ID", false);
if (atom_root == None || atom_eroot == None) {
cerr<<"couldn't create pixmap atoms, giving up!"<<endl;
@ -190,22 +190,24 @@ void bsetroot::setRootAtoms(Pixmap pixmap, int screen) {
}
// setting new background atoms
XChangeProperty(display, getScreenInfo(screen)->getRootWindow(),
XChangeProperty(display(), screen_info.getRootWindow(),
atom_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pixmap, 1);
XChangeProperty(display, getScreenInfo(screen)->getRootWindow(),
XChangeProperty(display(), screen_info.getRootWindow(),
atom_eroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pixmap, 1);
}
//-------------- solid --------------------
// draws pixmaps with a single color
//-----------------------------------------
/**
Draws pixmaps with a single color
*/
void bsetroot::solid() {
register int screen = 0;
pixmaps = new Pixmap[getNumberOfScreens()];
pixmaps = new Pixmap[ScreenCount(display())];
for (; screen < ScreenCount(display()); screen++) {
ScreenInfo screen_info(screen);
for (; screen < getNumberOfScreens(); screen++) {
FbTk::Color c;
GC gc;
XGCValues gcv;
@ -213,28 +215,28 @@ void bsetroot::solid() {
c.setFromString(fore, screen);
if (! c.isAllocated())
c.setPixel(BlackPixel(getXDisplay(), screen));
c.setPixel(BlackPixel(display(), screen));
gcv.foreground = c.pixel();
gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
gc = XCreateGC(display(), screen_info.getRootWindow(),
GCForeground , &gcv);
pixmaps[screen] = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(),
getScreenInfo(screen)->getDepth());
pixmaps[screen] = XCreatePixmap(display(),
screen_info.getRootWindow(),
screen_info.getWidth(), screen_info.getHeight(),
screen_info.getDepth());
XFillRectangle(getXDisplay(), pixmaps[screen], gc, 0, 0,
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight());
XFillRectangle(display(), pixmaps[screen], gc, 0, 0,
screen_info.getWidth(), screen_info.getHeight());
setRootAtoms(pixmaps[screen], screen);
XSetWindowBackgroundPixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), pixmaps[screen]);
XSetWindowBackgroundPixmap(display(),
screen_info.getRootWindow(), pixmaps[screen]);
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XClearWindow(display(), screen_info.getRootWindow());
XFreeGC(getXDisplay(), gc);
XFreeGC(display(), gc);
}
}
@ -248,9 +250,10 @@ void bsetroot::modula(int x, int y) {
register int screen, i;
pixmaps = new Pixmap[getNumberOfScreens()];
pixmaps = new Pixmap[ScreenCount(display())];
for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) {
for (pattern = 0, screen = 0; screen < ScreenCount(display()); screen++) {
ScreenInfo screen_info(screen);
for (i = 0; i < 16; i++) {
pattern <<= 1;
@ -273,68 +276,68 @@ void bsetroot::modula(int x, int y) {
Pixmap bitmap, r_bitmap;
XGCValues gcv;
bitmap = XCreateBitmapFromData(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), data, 16, 16);
bitmap = XCreateBitmapFromData(display(),
screen_info.getRootWindow(), data, 16, 16);
// bitmap used as tile, needs to have the same depth as background pixmap
r_bitmap = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), 16, 16,
getScreenInfo(screen)->getDepth());
r_bitmap = XCreatePixmap(display(),
screen_info.getRootWindow(), 16, 16,
screen_info.getDepth());
f.setFromString(fore, screen);
b.setFromString(back, screen);
if (! f.isAllocated())
f.setPixel(WhitePixel(getXDisplay(), screen));
f.setPixel(WhitePixel(display(), screen));
if (! b.isAllocated())
b.setPixel(BlackPixel(getXDisplay(), screen));
b.setPixel(BlackPixel(display(), screen));
gcv.foreground = f.pixel();
gcv.background = b.pixel();
gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
gc = XCreateGC(display(), screen_info.getRootWindow(),
GCForeground | GCBackground, &gcv);
// copying bitmap to the one going to be used as tile
XCopyPlane(getXDisplay(), bitmap, r_bitmap, gc,
XCopyPlane(display(), bitmap, r_bitmap, gc,
0, 0, 16, 16, 0, 0, 1l);
XSetTile(getXDisplay(), gc, r_bitmap);
XSetFillStyle(getXDisplay(), gc, FillTiled);
XSetTile(display(), gc, r_bitmap);
XSetFillStyle(display(), gc, FillTiled);
pixmaps[screen] = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(),
getScreenInfo(screen)->getDepth());
pixmaps[screen] = XCreatePixmap(display(),
screen_info.getRootWindow(),
screen_info.getWidth(), screen_info.getHeight(),
screen_info.getDepth());
XFillRectangle(getXDisplay(), pixmaps[screen], gc, 0, 0,
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight());
XFillRectangle(display(), pixmaps[screen], gc, 0, 0,
screen_info.getWidth(), screen_info.getHeight());
setRootAtoms(pixmaps[screen], screen);
XSetWindowBackgroundPixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), pixmaps[screen]);
XSetWindowBackgroundPixmap(display(),
screen_info.getRootWindow(), pixmaps[screen]);
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XClearWindow(display(), screen_info.getRootWindow());
XFreeGC(getXDisplay(), gc);
XFreePixmap(getXDisplay(), bitmap);
XFreePixmap(getXDisplay(), r_bitmap);
XFreeGC(display(), gc);
XFreePixmap(display(), bitmap);
XFreePixmap(display(), r_bitmap);
}
}
//-------------- gradient -----------------
// draws pixmaps with a fluxbox texure
//-----------------------------------------
/**
draws pixmaps with a fluxbox texure
*/
void bsetroot::gradient(void) {
register int screen;
// using temporaray pixmap and then copying it to background pixmap, as it'll
// get crashed somewhere on the way causing apps like XChat chrashing
// as the pixmap has been destroyed
Pixmap tmp;
pixmaps = new Pixmap[getNumberOfScreens()];
pixmaps = new Pixmap[ScreenCount(display())];
for (screen = 0; screen < getNumberOfScreens(); screen++) {
for (int screen = 0; screen < ScreenCount(display()); screen++) {
ScreenInfo screen_info(screen);
FbTk::Texture texture;
GC gc;
XGCValues gcv;
@ -344,48 +347,49 @@ void bsetroot::gradient(void) {
texture.colorTo().setFromString(back, screen);
if (! texture.color().isAllocated())
texture.color().setPixel(WhitePixel(getXDisplay(), screen));
texture.color().setPixel(WhitePixel(display(), screen));
if (! texture.colorTo().isAllocated())
texture.colorTo().setPixel(BlackPixel(getXDisplay(), screen));
texture.colorTo().setPixel(BlackPixel(display(), screen));
tmp = img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(),
getScreenInfo(screen)->getHeight(), texture);
tmp = img_ctrl[screen]->renderImage(screen_info.getWidth(),
screen_info.getHeight(), texture);
pixmaps[screen] = XCreatePixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(),
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(),
getScreenInfo(screen)->getDepth());
pixmaps[screen] = XCreatePixmap(display(),
screen_info.getRootWindow(),
screen_info.getWidth(), screen_info.getHeight(),
screen_info.getDepth());
gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
gc = XCreateGC(display(), screen_info.getRootWindow(),
GCForeground , &gcv);
XCopyArea(getXDisplay(), tmp, pixmaps[screen], gc, 0, 0,
getScreenInfo(screen)->getWidth(), getScreenInfo(screen)->getHeight(),
XCopyArea(display(), tmp, pixmaps[screen], gc, 0, 0,
screen_info.getWidth(), screen_info.getHeight(),
0, 0);
setRootAtoms(pixmaps[screen], screen);
XSetWindowBackgroundPixmap(getXDisplay(),
getScreenInfo(screen)->getRootWindow(), pixmaps[screen]);
XSetWindowBackgroundPixmap(display(),
screen_info.getRootWindow(), pixmaps[screen]);
XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
XClearWindow(display(), screen_info.getRootWindow());
if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
if (! (screen_info.getVisual()->c_class & 1)) {
img_ctrl[screen]->removeImage(tmp);
img_ctrl[screen]->timeout();
}
XFreeGC(getXDisplay(), gc);
XFreeGC(display(), gc);
}
}
//-------------- usage --------------------
// shows information about usage
//-----------------------------------------
/**
Shows information about usage
*/
void bsetroot::usage(int exit_code) {
fprintf(stderr,
I18n::instance()->getMessage(
FBNLS::bsetrootSet, FBNLS::bsetrootUsage,
"%s 2.2 : (c) 2003 Fluxbox Development Team\n"
"%s 2.1 : (c) 2002 Claes Nasten\n"
"%s 2.0 : (c) 1997-2000 Brad Hughes\n\n"
" -display <string> display connection\n"
@ -397,7 +401,7 @@ void bsetroot::usage(int exit_code) {
" -to <color> gradient end color\n\n"
" -solid <color> solid color\n\n"
" -help print this help text and exit\n"),
getApplicationName(), getApplicationName());
m_app_name, m_app_name);
exit(exit_code);
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
// Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen(at)linuxmail.org)
// Copyright (c) 1997 - 2000 Brad Hughes <bhughes at trolltech.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a
@ -18,12 +18,12 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// $Id: bsetroot.hh,v 1.5 2003/02/17 13:33:07 fluxgen Exp $
// $Id: bsetroot.hh,v 1.6 2003/05/10 15:44:15 fluxgen Exp $
#ifndef BSETROOT_HH
#define BSETROOT_HH
#include "../src/BaseDisplay.hh"
#include "../src/FbTk/App.hh"
namespace FbTk {
@ -31,30 +31,24 @@ class ImageControl;
};
class bsetroot : public BaseDisplay {
class bsetroot : public FbTk::App {
public:
bsetroot(int argc, char **argv, char * dpy_name= 0);
~bsetroot();
inline virtual bool handleSignal(int num) { return False; }
void gradient();
void modula(int, int);
void solid();
void usage(int = 0);
void setRootAtoms(Pixmap pixmap, int screen);
protected:
void handleEvent(XEvent *xe) { }
private:
FbTk::ImageControl **img_ctrl;
Pixmap *pixmaps;
char *fore, *back, *grad;
Display *display;
int num_screens;
char *m_app_name;
};