From f6e1f555f91059a0462db7d60b3a0923fed25652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sun, 24 Jul 2016 10:18:07 +0200 Subject: Add SpacerTool This allows to add random spacers, fixed size or stretching, to the toolbar. CCBUG: 1141 --- src/Makemodule.am | 2 ++ src/SpacerTool.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/SpacerTool.hh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ToolFactory.cc | 11 +++++++++++ 4 files changed, 104 insertions(+) create mode 100644 src/SpacerTool.cc create mode 100644 src/SpacerTool.hh diff --git a/src/Makemodule.am b/src/Makemodule.am index fedddb2..0156c90 100644 --- a/src/Makemodule.am +++ b/src/Makemodule.am @@ -102,6 +102,8 @@ TOOLBAR_SOURCE = \ src/GenericTool.hh \ src/IconbarTool.cc \ src/IconbarTool.hh \ + src/SpacerTool.cc \ + src/SpacerTool.hh \ src/ToolFactory.cc \ src/ToolFactory.hh \ src/ToolTheme.cc \ diff --git a/src/SpacerTool.cc b/src/SpacerTool.cc new file mode 100644 index 0000000..a6b42a3 --- /dev/null +++ b/src/SpacerTool.cc @@ -0,0 +1,39 @@ +// SpacerTool.cc for Fluxbox +// Copyright (c) 2016 Thomas Lübking +// +// 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 "SpacerTool.hh" + +SpacerTool::SpacerTool(int size): + ToolbarItem(size < 0 ? RELATIVE : FIXED), m_size(size) { +} + +SpacerTool::~SpacerTool() { + +} + +unsigned int SpacerTool::width() const { + return ((orientation() & 1) || m_size < 0) ? 0 : m_size; +} + +unsigned int SpacerTool::height() const { + return ((orientation() & 1) && m_size > -1) ? m_size : 0; +} + diff --git a/src/SpacerTool.hh b/src/SpacerTool.hh new file mode 100644 index 0000000..1e29b45 --- /dev/null +++ b/src/SpacerTool.hh @@ -0,0 +1,52 @@ +// SpacerTool.hh for Fluxbox +// Copyright (c) 2016 Thomas Lübking +// +// 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 SPACERTOOL_HH +#define SPACERTOOL_HH + +#include "ToolbarItem.hh" + + +class SpacerTool: public ToolbarItem { +public: + SpacerTool(int size = -1); + virtual ~SpacerTool(); + void move(int x, int y) {} + void resize(unsigned int x, unsigned int y) {} + void moveResize(int x, int y, + unsigned int width, unsigned int height) {} + void show() {} + void hide() {} + + unsigned int width() const; + unsigned int height() const; + unsigned int borderWidth() const {return 0;} + + void parentMoved() {} + void updateSizing() {} + + virtual void renderTheme(int alpha) {} + +private: + int m_size; +}; + +#endif // SPACERTOOL_HH diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc index 60b283c..a033656 100644 --- a/src/ToolFactory.cc +++ b/src/ToolFactory.cc @@ -29,6 +29,7 @@ #endif #include "IconbarTool.hh" #include "WorkspaceNameTool.hh" +#include "SpacerTool.hh" #include "ArrowButton.hh" // Themes @@ -98,6 +99,16 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow & #endif } else if (name == "clock") { item = new ClockTool(parent, m_clock_theme, screen(), tbar.menu()); + } else if (name.find("spacer") == 0) { + int size = -1; + if (name.size() > 6) { // spacer_20 creates a 20px spacer + if (name.at(6) != '_') + return 0; + size = atoi(name.substr(7, std::string::npos).c_str()); + if (size < 1) + return 0; + } + item = new SpacerTool(size); } else { std::string cmd_str = name; -- cgit v0.11.2