From 7fe3301e7ea905a8a76d54c22751f3d8a346e28b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 14 Feb 2003 23:05:59 +0000 Subject: [PATCH] Add the "obsetroot" tool. Use it to set the root background. --- Makefile.am | 2 +- configure.ac | 1 + otk/.cvsignore | 1 + otk/Makefile.am | 3 ++- otk/application.cc | 25 +++++++----------- otk/application.hh | 2 -- otk/appwidget.cc | 1 + otk/otk.cc | 25 ++++++++++++++++++ otk/otk.hh | 5 ++++ otk/property.cc | 3 +++ otk/property.hh | 3 +++ otk/pseudorendercontrol.cc | 6 ++--- otk/rendercontrol.cc | 22 +++++++++------- otk/rendercontrol.hh | 3 --- otk/renderstyle.cc | 13 ++++----- otk/renderstyle.hh | 7 ++--- otk/truerendercontrol.cc | 6 ++--- src/actions.cc | 2 ++ src/openbox.cc | 31 +++++++--------------- src/openbox.hh | 5 ---- src/screen.cc | 6 +++-- tools/.cvsignore | 5 ++++ tools/Makefile.am | 10 +++++++ tools/obsetroot.cc | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 24 files changed, 173 insertions(+), 80 deletions(-) create mode 100644 otk/otk.cc create mode 100644 tools/.cvsignore create mode 100644 tools/Makefile.am create mode 100644 tools/obsetroot.cc diff --git a/Makefile.am b/Makefile.am index 4c82fef..2491616 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = po data doc otk wrap src scripts +SUBDIRS = po data doc otk wrap src scripts tools MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in stamp-h.in .PHONY: doc diff --git a/configure.ac b/configure.ac index c5302aa..b83776f 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,7 @@ X11_EXT_XINERAMA AC_CONFIG_FILES([Makefile po/Makefile.in otk/Makefile src/Makefile + tools/Makefile wrap/Makefile scripts/Makefile doc/Makefile diff --git a/otk/.cvsignore b/otk/.cvsignore index 0497be4..7dab6bb 100644 --- a/otk/.cvsignore +++ b/otk/.cvsignore @@ -41,3 +41,4 @@ rendercontrol.lo rendercolor.lo otk.py otk.pc +otk.lo diff --git a/otk/Makefile.am b/otk/Makefile.am index f0c2e80..dc53291 100644 --- a/otk/Makefile.am +++ b/otk/Makefile.am @@ -10,7 +10,8 @@ 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 \ eventdispatcher.cc eventhandler.cc ustring.cc \ - widget.cc application.cc label.cc appwidget.cc button.cc + widget.cc application.cc label.cc appwidget.cc button.cc \ + otk.cc #focuswidget.cc focuslabel.cc diff --git a/otk/application.cc b/otk/application.cc index 94842ca..afe06f8 100644 --- a/otk/application.cc +++ b/otk/application.cc @@ -8,41 +8,34 @@ #include "property.hh" #include "rendercolor.hh" #include "renderstyle.hh" +#include "display.hh" -extern "C" { -#ifdef HAVE_STDLIB_H -# include -#endif -} - +#include #include namespace otk { +extern void initialize(); +extern void destroy(); + Application::Application(int argc, char **argv) : EventDispatcher(), - _display(), _dockable(false), _appwidget_count(0) { (void)argc; (void)argv; - _screen = DefaultScreen(*_display); + otk::initialize(); + + _screen = DefaultScreen(**display); - Timer::initialize(); - RenderColor::initialize(); - RenderStyle::initialize(); - Property::initialize(); - loadStyle(); } Application::~Application() { - RenderStyle::destroy(); - RenderColor::destroy(); - Timer::destroy(); + otk::destroy(); } void Application::loadStyle(void) diff --git a/otk/application.hh b/otk/application.hh index 848b798..6da36d2 100644 --- a/otk/application.hh +++ b/otk/application.hh @@ -3,7 +3,6 @@ #define __application_hh #include "eventdispatcher.hh" -#include "display.hh" namespace otk { @@ -27,7 +26,6 @@ public: private: void loadStyle(void); - Display _display; int _screen; bool _dockable; diff --git a/otk/appwidget.cc b/otk/appwidget.cc index 8b15722..5dcad7a 100644 --- a/otk/appwidget.cc +++ b/otk/appwidget.cc @@ -6,6 +6,7 @@ #include "application.hh" #include "property.hh" #include "renderstyle.hh" +#include "display.hh" extern "C" { #include diff --git a/otk/otk.cc b/otk/otk.cc new file mode 100644 index 0000000..130e3b7 --- /dev/null +++ b/otk/otk.cc @@ -0,0 +1,25 @@ +#include "display.hh" +#include "timer.hh" +#include "renderstyle.hh" +#include "property.hh" + +namespace otk { + +void initialize() +{ + new Display(); + Timer::initialize(); + RenderColor::initialize(); + RenderStyle::initialize(); + Property::initialize(); +} + +void destroy() +{ + RenderStyle::destroy(); + RenderColor::destroy(); + Timer::destroy(); + delete display; +} + +} diff --git a/otk/otk.hh b/otk/otk.hh index 62788cb..74187f0 100644 --- a/otk/otk.hh +++ b/otk/otk.hh @@ -30,4 +30,9 @@ #include "ustring.hh" #include "widget.hh" +namespace otk { +void initialize(); +void destroy(); +} + #endif // __otk_hh diff --git a/otk/property.cc b/otk/property.cc index 75f9a7c..16b507f 100644 --- a/otk/property.cc +++ b/otk/property.cc @@ -134,6 +134,9 @@ void Property::initialize() atoms.kde_net_wm_window_type_override = create("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE"); + atoms.rootpmapid = create("_XROOTPMAP_ID"); + atoms.esetrootid = create("ESETROOT_PMAP_ID"); + atoms.openbox_premax = create("_OPENBOX_PREMAX"); atoms.openbox_active_window = create("_OPENBOX_ACTIVE_WINDOW"); } diff --git a/otk/property.hh b/otk/property.hh index f773c64..e6677a6 100644 --- a/otk/property.hh +++ b/otk/property.hh @@ -125,6 +125,9 @@ struct Atoms { Atom kde_net_wm_system_tray_window_for; Atom kde_net_wm_window_type_override; + Atom rootpmapid; + Atom esetrootid; + Atom openbox_premax; Atom openbox_active_window; }; diff --git a/otk/pseudorendercontrol.cc b/otk/pseudorendercontrol.cc index 7af5719..cf99292 100644 --- a/otk/pseudorendercontrol.cc +++ b/otk/pseudorendercontrol.cc @@ -9,14 +9,12 @@ #include "rendertexture.hh" extern "C" { -#ifdef HAVE_STDLIB_H -# include -#endif // HAVE_STDLIB_H - #include "../src/gettext.h" #define _(str) gettext(str) } +#include + namespace otk { PseudoRenderControl::PseudoRenderControl(int screen) diff --git a/otk/rendercontrol.cc b/otk/rendercontrol.cc index a4de270..8f93296 100644 --- a/otk/rendercontrol.cc +++ b/otk/rendercontrol.cc @@ -13,16 +13,23 @@ #include "surface.hh" #include "font.hh" #include "ustring.hh" +#include "property.hh" extern "C" { -#ifdef HAVE_STDLIB_H -# include -#endif // HAVE_STDLIB_H +#ifdef HAVE_SYS_WAIT_H +# include +#endif // HAVE_SYS_WAIT_H + +#ifdef HAVE_UNISTD_H +# include +#endif // HAVE_UNISTD_H #include "../src/gettext.h" #define _(str) gettext(str) } +#include + namespace otk { RenderControl *RenderControl::getRenderControl(int screen) @@ -47,8 +54,10 @@ RenderControl *RenderControl::getRenderControl(int screen) RenderControl::RenderControl(int screen) : _screen(screen) + { printf("Initializing RenderControl\n"); + } RenderControl::~RenderControl() @@ -56,13 +65,6 @@ RenderControl::~RenderControl() printf("Destroying RenderControl\n"); } -void RenderControl::drawRoot(const RenderColor &color) const -{ - Window root = display->screenInfo(_screen)->rootWindow(); - XSetWindowBackground(**display, root, color.pixel()); - XClearWindow(**display, root); -} - void RenderControl::drawString(Surface& sf, const Font &font, int x, int y, const RenderColor &color, const ustring &string) const diff --git a/otk/rendercontrol.hh b/otk/rendercontrol.hh index 56f45c8..5e21da2 100644 --- a/otk/rendercontrol.hh +++ b/otk/rendercontrol.hh @@ -48,9 +48,6 @@ public: static RenderControl *getRenderControl(int screen); - //! Draws onto the root window - virtual void drawRoot(const RenderColor &color) const; - //! Draws a background onto a Surface, as specified by a RenderTexture /*! This function will overwrite the entire surface. diff --git a/otk/renderstyle.cc b/otk/renderstyle.cc index d9e106a..88c8d78 100644 --- a/otk/renderstyle.cc +++ b/otk/renderstyle.cc @@ -73,11 +73,11 @@ bool RenderStyle::loadStyle(RenderStyle *s, int screen, s->_screen = screen; s->_file = stylefile; // pick one.. -//#define FIERON -#define MERRY +#define FIERON +//#define MERRY #ifdef FIERON - s->_root_color = new RenderColor(screen, 0x272a2f); + s->_root_args = "#272a2f"; s->_text_color_focus = new RenderColor(screen, 0x272a2f); s->_text_color_unfocus = new RenderColor(screen, 0x676869); @@ -281,7 +281,7 @@ bool RenderStyle::loadStyle(RenderStyle *s, int screen, s->_handle_width = 4; #else # ifdef MERRY - s->_root_color = new RenderColor(screen, 0x7b756a); + s->_root_args = "#7b756a"; s->_text_color_focus = new RenderColor(screen, 0xffffff); s->_text_color_unfocus = new RenderColor(screen, 0xffffff); @@ -497,7 +497,7 @@ void RenderStyle::defaultStyle(RenderStyle *s, int screen) s->_screen = screen; s->_file = ""; - s->_root_color = new RenderColor(screen, 0); + s->_root_args = "#000000"; s->_text_color_focus = new RenderColor(screen, 0xffffff); s->_text_color_unfocus = new RenderColor(screen, 0xffffff); s->_button_color_focus = new RenderColor(screen, 0); @@ -634,9 +634,6 @@ void RenderStyle::defaultStyle(RenderStyle *s, int screen) RenderStyle::~RenderStyle() { - assert(_root_color); - delete _root_color; - assert(_text_color_focus); delete _text_color_focus; assert(_text_color_unfocus); diff --git a/otk/renderstyle.hh b/otk/renderstyle.hh index 69c26a7..0f51214 100644 --- a/otk/renderstyle.hh +++ b/otk/renderstyle.hh @@ -8,6 +8,7 @@ #include "ustring.hh" #include +#include namespace otk { @@ -49,7 +50,7 @@ private: int _screen; ustring _file; - RenderColor *_root_color; + std::string _root_args; RenderColor *_text_color_focus; RenderColor *_text_color_unfocus; @@ -97,7 +98,7 @@ public: inline int screen() const { return _screen; } - inline RenderColor *rootColor() const { return _root_color; } + inline const std::string& rootArgs() const { return _root_args; } inline RenderColor *textFocusColor() const { return _text_color_focus; } inline RenderColor *textUnfocusColor() const { return _text_color_unfocus; } @@ -153,4 +154,4 @@ public: } -#endif // __rendertexture_hh +#endif // __renderstyle_hh diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc index 2ce771e..42589dd 100644 --- a/otk/truerendercontrol.cc +++ b/otk/truerendercontrol.cc @@ -9,14 +9,12 @@ #include "rendertexture.hh" extern "C" { -#ifdef HAVE_STDLIB_H -# include -#endif // HAVE_STDLIB_H - #include "../src/gettext.h" #define _(str) gettext(str) } +#include + namespace otk { TrueRenderControl::TrueRenderControl(int screen) diff --git a/src/actions.cc b/src/actions.cc index cefa577..1213f21 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -72,6 +72,8 @@ void Actions::buttonPressHandler(const XButtonEvent &e) otk::EventHandler::buttonPressHandler(e); insertPress(e); + printf("press queue %u pressed %u\n", _button, e.button); + MouseContext::MC context; EventHandler *h = openbox->findHandler(e.window); Frame *f = dynamic_cast(h); diff --git a/src/openbox.cc b/src/openbox.cc index 89e541a..d068880 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -38,6 +38,11 @@ extern "C" { #include #include +namespace otk { +extern void initialize(); +extern void destroy(); +} + namespace ob { Openbox *openbox = (Openbox *) 0; @@ -73,8 +78,7 @@ void Openbox::signalHandler(int signal) Openbox::Openbox(int argc, char **argv) : otk::EventDispatcher(), - otk::EventHandler(), - _display() + otk::EventHandler() { struct sigaction action; @@ -82,7 +86,6 @@ Openbox::Openbox(int argc, char **argv) openbox = this; - _displayreq = (char*) 0; _argv = argv; _shutdown = false; _restart = false; @@ -94,6 +97,8 @@ Openbox::Openbox(int argc, char **argv) parseCommandLine(argc, argv); + otk::initialize(); + XSynchronize(**otk::display, _sync); // set up the signal handler @@ -112,10 +117,6 @@ Openbox::Openbox(int argc, char **argv) // anything that died while we were restarting won't give us a SIGCHLD while (waitpid(-1, NULL, WNOHANG) > 0); - otk::RenderColor::initialize(); - otk::RenderStyle::initialize(); - otk::Timer::initialize(); - otk::Property::initialize(); _actions = new Actions(); _bindings = new Bindings(); @@ -200,14 +201,7 @@ Openbox::~Openbox() CurrentTime); XSync(**otk::display, false); - // this tends to block.. i honestly am not sure why. causing an x error in - // the shutdown process unblocks it. blackbox simply did a ::exit(0), so - // all im gunna do is the same. - //delete _display; - - otk::Timer::destroy(); - otk::RenderStyle::destroy(); - otk::RenderColor::destroy(); + otk::destroy(); } @@ -218,12 +212,7 @@ void Openbox::parseCommandLine(int argc, char **argv) for (int i = 1; i < argc; ++i) { std::string arg(argv[i]); - if (arg == "-display") { - if (++i >= argc) - err = true; - else - _displayreq = argv[i]; - } else if (arg == "-rc") { + if (arg == "-rc") { if (++i >= argc) err = true; else diff --git a/src/openbox.hh b/src/openbox.hh index 8145531..e718dd2 100644 --- a/src/openbox.hh +++ b/src/openbox.hh @@ -72,9 +72,6 @@ public: typedef std::vector ScreenList; private: - //! The display on which Openbox is running - otk::Display _display; - // stuff that can be passed on the command line //! Path to the config file to use/in use /*! @@ -91,8 +88,6 @@ private: Defaults to $(HOME)/.openbox/user.py */ std::string _scriptfilepath; - //! The display requested by the user, or null to use the DISPLAY env var - char *_displayreq; //! The value of argv, i.e. how this application was executed char **_argv; //! Run the application in synchronous mode? (for debugging) diff --git a/src/screen.cc b/src/screen.cc index 3f507af..6eaa5cc 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -10,6 +10,7 @@ #include "python.hh" #include "otk/display.hh" #include "otk/property.hh" +#include "otk/util.hh" extern "C" { #ifdef HAVE_UNISTD_H @@ -68,8 +69,9 @@ Screen::Screen(int screen) // initialize the screen's style otk::RenderStyle::setStyle(_number, _config.theme); - otk::display->renderControl(_number)-> - drawRoot(*otk::RenderStyle::style(_number)->rootColor()); + // draw the root window + otk::bexec("obsetroot " + otk::RenderStyle::style(_number)->rootArgs(), + _info->displayString()); // set up notification of netwm support changeSupportedAtoms(); diff --git a/tools/.cvsignore b/tools/.cvsignore new file mode 100644 index 0000000..b0f0d99 --- /dev/null +++ b/tools/.cvsignore @@ -0,0 +1,5 @@ +.libs +.deps +obsetroot +Makefile.in +Makefile diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..1785c00 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,10 @@ +bin_PROGRAMS=obsetroot + +obsetroot_LDADD=$(XFT_LIBS) -L../otk -lotk @LIBINTL@ +obsetroot_CPPFLAGS=$(XFT_CFLAGS) -I.. +obsetroot_SOURCES=obsetroot.cc + +MAINTAINERCLEANFILES=Makefile.in + +distclean-local: + $(RM) *\~ *.orig *.rej .\#* diff --git a/tools/obsetroot.cc b/tools/obsetroot.cc new file mode 100644 index 0000000..286a61e --- /dev/null +++ b/tools/obsetroot.cc @@ -0,0 +1,66 @@ +#include + +int main(int argc, char **argv) +{ + otk::initialize(); + + int screen = DefaultScreen(**otk::display); + + Pixmap old; + Window root = otk::display->screenInfo(screen)->rootWindow(); + + otk::Surface *s = new otk::Surface(screen, + otk::display->screenInfo(screen)->size()); + otk::RenderTexture *tx = new otk::RenderTexture(screen, false, + otk::RenderTexture::Flat, + otk::RenderTexture::Bevel1, + false, + otk::RenderTexture::Solid, + false, 0x202020, 0x0000ff, + 0, 0); + otk::display->renderControl(screen)->drawBackground(*s, *tx); + + otk::display->grab(); + + otk::display->setIgnoreErrors(true); + // get the current pixmap and free it + if (otk::Property::get(root, otk::Property::atoms.rootpmapid, + otk::Property::atoms.pixmap, &old) && old) { + XKillClient(**otk::display, old); + XSync(**otk::display, false); + XFreePixmap(**otk::display, old); + } + if (otk::Property::get(root, otk::Property::atoms.esetrootid, + otk::Property::atoms.pixmap, &old) && old) + XFreePixmap(**otk::display, old); + otk::display->setIgnoreErrors(false); + + // XSetWindowBackground(**display, root, color.pixel()); + + // don't kill us when someone wants to change the background!! + Pixmap pixmap = XCreatePixmap(**otk::display, root, s->size().width(), + s->size().height(), + otk::display->screenInfo(screen)->depth()); + XCopyArea(**otk::display, s->pixmap(), pixmap, + DefaultGC(**otk::display, screen), 0, 0, + s->size().width(), s->size().height(), 0, 0); + + // set the new pixmap + XSetWindowBackgroundPixmap(**otk::display, root, pixmap); + XClearWindow(**otk::display, root); + + otk::Property::set(root, otk::Property::atoms.rootpmapid, + otk::Property::atoms.pixmap, pixmap); + otk::Property::set(root, otk::Property::atoms.esetrootid, + otk::Property::atoms.pixmap, pixmap); + + otk::display->ungrab(); + + delete tx; + delete s; + + XSetCloseDownMode(**otk::display, RetainPermanent); + XKillClient(**otk::display, AllTemporary); + + otk::destroy(); +} -- 1.9.1