From db4ec8cf20b4e72cd32d0632a5ab6a8584d2515a Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Sat, 19 Jan 2008 04:00:46 -0800 Subject: move position and geometry windows into their own class --- src/Makefile.am | 1 + src/OSDWindow.cc | 94 +++++++++++++++++++++++++++++ src/OSDWindow.hh | 59 ++++++++++++++++++ src/Screen.cc | 180 ++++--------------------------------------------------- src/Screen.hh | 8 +-- 5 files changed, 169 insertions(+), 173 deletions(-) create mode 100644 src/OSDWindow.cc create mode 100644 src/OSDWindow.hh diff --git a/src/Makefile.am b/src/Makefile.am index 683179d..f41a30a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -101,6 +101,7 @@ fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \ Keys.cc Keys.hh main.cc \ RootTheme.hh RootTheme.cc \ FbRootWindow.hh FbRootWindow.cc \ + OSDWindow.hh OSDWindow.cc \ Screen.cc Screen.hh ScreenResources.cc \ Slit.cc Slit.hh SlitTheme.hh SlitTheme.cc SlitClient.hh SlitClient.cc \ WinButton.hh WinButton.cc \ diff --git a/src/OSDWindow.cc b/src/OSDWindow.cc new file mode 100644 index 0000000..005e07b --- /dev/null +++ b/src/OSDWindow.cc @@ -0,0 +1,94 @@ +// OSDWindow.cc +// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// 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 +// DEALINGS IN THE SOFTWARE. + +#include "OSDWindow.hh" + +#include "Screen.hh" +#include "FbWinFrameTheme.hh" + +#include "FbTk/ImageControl.hh" + +void OSDWindow::reconfigTheme() { + + setBorderWidth(m_theme->border().width()); + setBorderColor(m_theme->border().color()); + + if (m_pixmap) + m_screen.imageControl().removeImage(m_pixmap); + + if (m_theme->iconbarTheme().texture().type() & + FbTk::Texture::PARENTRELATIVE) { + if (!m_theme->titleTexture().usePixmap()) { + m_pixmap = None; + setBackgroundColor(m_theme->titleTexture().color()); + } else { + m_pixmap = m_screen.imageControl().renderImage(width(), height(), + m_theme->titleTexture()); + setBackgroundPixmap(m_pixmap); + } + } else { + if (!m_theme->iconbarTheme().texture().usePixmap()) { + m_pixmap = None; + setBackgroundColor(m_theme->iconbarTheme().texture().color()); + } else { + m_pixmap = m_screen.imageControl().renderImage(width(), height(), + m_theme->iconbarTheme().texture()); + setBackgroundPixmap(m_pixmap); + } + } + +} + +void OSDWindow::resize(const std::string &text) { + + int h = m_theme->font().height() + m_theme->bevelWidth()*2; + int w = m_theme->font().textWidth(text, text.size()) + + m_theme->bevelWidth()*2; + FbTk::FbWindow::resize(w, h); +} + +void OSDWindow::showText(const std::string &text) { + show(); + clear(); + m_theme->font().drawText(*this, m_screen.screenNumber(), + m_theme->iconbarTheme().text().textGC(), text, text.size(), + m_theme->bevelWidth(), + m_theme->bevelWidth() + m_theme->font().ascent()); +} + +void OSDWindow::show() { + if (m_visible) + return; + + m_visible = true; + unsigned int head = m_screen.getCurrHead(); + move(m_screen.getHeadX(head) + (m_screen.getHeadWidth(head) - width()) / 2, + m_screen.getHeadY(head) + (m_screen.getHeadHeight(head) - height()) / 2); + raise(); + FbTk::FbWindow::show(); +} + +void OSDWindow::hide() { + if (!m_visible) + return; + m_visible = false; + FbTk::FbWindow::hide(); +} diff --git a/src/OSDWindow.hh b/src/OSDWindow.hh new file mode 100644 index 0000000..3fd5c42 --- /dev/null +++ b/src/OSDWindow.hh @@ -0,0 +1,59 @@ +// OSDWindow.hh +// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// 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 +// DEALINGS IN THE SOFTWARE. + +#ifndef OSDWINDOW_HH +#define OSDWINDOW_HH + +#include "FbTk/FbWindow.hh" +#include + +class BScreen; +class FbWinFrameTheme; + +namespace FbTk { +template class ThemeProxy; +} + +class OSDWindow: public FbTk::FbWindow { +public: + OSDWindow(const FbTk::FbWindow &parent, BScreen &screen, + FbTk::ThemeProxy &theme): + FbTk::FbWindow(parent, 0, 0, 10, 10, 0, false, true), + m_screen(screen), m_theme(theme), + m_pixmap(None), m_visible(false) { } + + void reconfigTheme(); + void resize(const std::string &text); + void showText(const std::string &text); + void hide(); + + bool isVisible() const { return m_visible; } + +private: + void show(); + + BScreen &m_screen; + FbTk::ThemeProxy &m_theme; + Pixmap m_pixmap; + bool m_visible; +}; + +#endif // OSDWINDOW_HH diff --git a/src/Screen.cc b/src/Screen.cc index 6af65a9..9002ad2 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -341,14 +341,8 @@ BScreen::BScreen(FbTk::ResourceManager &rm, m_pressed_winbutton_theme(new WinButtonTheme(scrn, ".pressed", ".Pressed", *m_focused_windowtheme)), m_menutheme(new FbTk::MenuTheme(scrn)), m_root_window(scrn), - m_geom_window(m_root_window, - 0, 0, 10, 10, - false, // override redirect - true), // save under - m_pos_window(m_root_window, - 0, 0, 10, 10, - false, // override redirect - true), // save under + m_geom_window(m_root_window, *this, *m_focused_windowtheme), + m_pos_window(m_root_window, *this, *m_focused_windowtheme), m_dummy_window(scrn, -1, -1, 1, 1, 0, true, false, CopyFromParent, InputOnly), resource(rm, screenname, altscreenname), @@ -483,11 +477,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm, focusedWinFrameTheme()->reconfigSig().attach(this);// for geom window - geom_visible = false; - geom_pixmap = 0; - pos_visible = false; - pos_pixmap = 0; - renderGeomWindow(); renderPosWindow(); @@ -585,12 +574,6 @@ BScreen::~BScreen() { } } - if (geom_pixmap != None) - imageControl().removeImage(geom_pixmap); - - if (pos_pixmap != None) - imageControl().removeImage(pos_pixmap); - removeWorkspaceNames(); using namespace FbTk::STLUtil; destroyAndClear(m_workspaces_list); @@ -938,9 +921,6 @@ void BScreen::reconfigure() { m_menutheme->setDelayOpen(*resource.menu_delay); m_menutheme->setDelayClose(*resource.menu_delay_close); - renderGeomWindow(); - renderPosWindow(); - // realize the number of workspaces from the init-file const unsigned int nr_ws = *resource.workspaces; if (nr_ws > m_workspaces_list.size()) { @@ -1812,47 +1792,17 @@ void BScreen::shutdown() { void BScreen::showPosition(int x, int y) { - if (!doShowWindowPos()) + if (!doShowWindowPos()) return; - if (! pos_visible) { - if (hasXinerama()) { - unsigned int head = getCurrHead(); - - m_pos_window.move(getHeadX(head) + (getHeadWidth(head) - m_pos_window.width()) / 2, - getHeadY(head) + (getHeadHeight(head) - m_pos_window.height()) / 2); - - } else { - m_pos_window.move((width() - m_pos_window.width()) / 2, - (height() - m_pos_window.height()) / 2); - } - - m_pos_window.show(); - m_pos_window.raise(); - - pos_visible = true; - } - char label[256]; sprintf(label, "X:%5d x Y:%5d", x, y); - - m_pos_window.clear(); - - focusedWinFrameTheme()->font().drawText(m_pos_window, screenNumber(), - focusedWinFrameTheme()->iconbarTheme().text().textGC(), - label, strlen(label), - focusedWinFrameTheme()->bevelWidth(), - focusedWinFrameTheme()->bevelWidth() + - focusedWinFrameTheme()->font().ascent()); - + m_pos_window.showText(label); } void BScreen::hidePosition() { - if (pos_visible) { - m_pos_window.hide(); - pos_visible = false; - } + m_pos_window.hide(); } // can be negative when base_width/height > min_width/height @@ -1860,23 +1810,6 @@ void BScreen::showGeometry(int gx, int gy) { if (!doShowWindowPos()) return; - if (! geom_visible) { - if (hasXinerama()) { - unsigned int head = getCurrHead(); - - m_geom_window.move(getHeadX(head) + (getHeadWidth(head) - m_geom_window.width()) / 2, - getHeadY(head) + (getHeadHeight(head) - m_geom_window.height()) / 2); - } else { - m_geom_window.move((width() - m_geom_window.width()) / 2, - (height() - m_geom_window.height()) / 2); - - } - m_geom_window.show(); - m_geom_window.raise(); - - geom_visible = true; - } - char label[256]; _FB_USES_NLS; @@ -1885,24 +1818,12 @@ void BScreen::showGeometry(int gx, int gy) { "W: %4d x H: %4d", "Format for width and height window, %4d for width, and %4d for height").c_str(), gx, gy); - - m_geom_window.clear(); - - //!! TODO: geom window again?! repeated - focusedWinFrameTheme()->font().drawText(m_geom_window, screenNumber(), - focusedWinFrameTheme()->iconbarTheme().text().textGC(), - label, strlen(label), - focusedWinFrameTheme()->bevelWidth(), - focusedWinFrameTheme()->bevelWidth() + - focusedWinFrameTheme()->font().ascent()); + m_geom_window.showText(label); } void BScreen::hideGeometry() { - if (geom_visible) { - m_geom_window.hide(); - geom_visible = false; - } + m_geom_window.hide(); } void BScreen::setLayer(FbTk::XLayerItem &item, int layernum) { @@ -1950,93 +1871,14 @@ void BScreen::renderGeomWindow() { _FB_XTEXT(Screen, GeometrySpacing, "W: %04d x H: %04d", "Representative maximum sized text for width and height dialog").c_str(), 0, 0); - - int geom_h = focusedWinFrameTheme()->font().height() + - focusedWinFrameTheme()->bevelWidth()*2; - int geom_w = focusedWinFrameTheme()->font().textWidth(label, strlen(label)) - + focusedWinFrameTheme()->bevelWidth()*2; - m_geom_window.resize(geom_w, geom_h); - - m_geom_window.setBorderWidth(focusedWinFrameTheme()->border().width()); - m_geom_window.setBorderColor(focusedWinFrameTheme()->border().color()); - - - Pixmap tmp = geom_pixmap; - - if (focusedWinFrameTheme()->iconbarTheme().texture().type() & - FbTk::Texture::PARENTRELATIVE) { - if (!focusedWinFrameTheme()->titleTexture().usePixmap()) { - geom_pixmap = None; - m_geom_window.setBackgroundColor( - focusedWinFrameTheme()->titleTexture().color()); - } else { - geom_pixmap = imageControl().renderImage(m_geom_window.width(), - m_geom_window.height(), - focusedWinFrameTheme()->titleTexture()); - m_geom_window.setBackgroundPixmap(geom_pixmap); - } - } else { - if (!focusedWinFrameTheme()->iconbarTheme().texture().usePixmap()) { - geom_pixmap = None; - m_geom_window.setBackgroundColor( - focusedWinFrameTheme()->iconbarTheme().texture().color()); - } else { - geom_pixmap = imageControl().renderImage(m_geom_window.width(), - m_geom_window.height(), - focusedWinFrameTheme()->iconbarTheme().texture()); - m_geom_window.setBackgroundPixmap(geom_pixmap); - } - } - - if (tmp) - imageControl().removeImage(tmp); - + m_geom_window.resize(label); + m_geom_window.reconfigTheme(); } void BScreen::renderPosWindow() { - - int pos_h = focusedWinFrameTheme()->font().height() + - focusedWinFrameTheme()->bevelWidth()*2; - int pos_w = focusedWinFrameTheme()->font().textWidth("0:00000 x 0:00000", - 17) + - focusedWinFrameTheme()->bevelWidth()*2; - m_pos_window.resize(pos_w, pos_h); - - m_pos_window.setBorderWidth(focusedWinFrameTheme()->border().width()); - m_pos_window.setBorderColor(focusedWinFrameTheme()->border().color()); - - - Pixmap tmp = pos_pixmap; - - if (focusedWinFrameTheme()->iconbarTheme().texture().type() & - FbTk::Texture::PARENTRELATIVE) { - if (!focusedWinFrameTheme()->titleTexture().usePixmap()) { - pos_pixmap = None; - m_pos_window.setBackgroundColor( - focusedWinFrameTheme()->titleTexture().color()); - } else { - pos_pixmap = imageControl().renderImage(m_pos_window.width(), - m_pos_window.height(), - focusedWinFrameTheme()->titleTexture()); - m_pos_window.setBackgroundPixmap(pos_pixmap); - } - } else { - if (!focusedWinFrameTheme()->iconbarTheme().texture().usePixmap()) { - pos_pixmap = None; - m_pos_window.setBackgroundColor( - focusedWinFrameTheme()->iconbarTheme().texture().color()); - } else { - pos_pixmap = imageControl().renderImage(m_pos_window.width(), - m_pos_window.height(), - focusedWinFrameTheme()->iconbarTheme().texture()); - m_pos_window.setBackgroundPixmap(pos_pixmap); - } - } - - if (tmp) - imageControl().removeImage(tmp); - + m_pos_window.resize("0:00000 x 0:00000"); + m_pos_window.reconfigTheme(); } void BScreen::updateSize() { diff --git a/src/Screen.hh b/src/Screen.hh index 99c23ff..a503285 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -30,6 +30,7 @@ #include "RootTheme.hh" #include "WinButtonTheme.hh" #include "FbWinFrameTheme.hh" +#include "OSDWindow.hh" #include "FbTk/MenuTheme.hh" #include "FbTk/EventHandler.hh" @@ -496,11 +497,9 @@ private: FbTk::MultLayers m_layermanager; - bool root_colormap_installed, managed, geom_visible, pos_visible; + bool root_colormap_installed, managed; GC opGC; - Pixmap geom_pixmap, pos_pixmap; - std::auto_ptr m_image_control; @@ -532,7 +531,8 @@ private: std::auto_ptr m_root_theme; FbRootWindow m_root_window; - FbTk::FbWindow m_geom_window, m_pos_window, m_dummy_window; + OSDWindow m_geom_window, m_pos_window; + FbTk::FbWindow m_dummy_window; struct ScreenResource { ScreenResource(FbTk::ResourceManager &rm, const std::string &scrname, -- cgit v0.11.2