Add SpacerTool

This allows to add random spacers, fixed size or stretching, to the toolbar.

CCBUG: 1141
This commit is contained in:
Thomas Lübking 2016-07-24 10:18:07 +02:00
parent 50b6102bbf
commit f6e1f555f9
4 changed files with 104 additions and 0 deletions

View file

@ -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 \

39
src/SpacerTool.cc Normal file
View file

@ -0,0 +1,39 @@
// SpacerTool.cc for Fluxbox
// Copyright (c) 2016 Thomas Lübking <thomas.luebking@gmail.com>
//
// 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;
}

52
src/SpacerTool.hh Normal file
View file

@ -0,0 +1,52 @@
// SpacerTool.hh for Fluxbox
// Copyright (c) 2016 Thomas Lübking <thomas.luebking@gmail.com>
//
// 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

View file

@ -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;