added configurable tools
This commit is contained in:
parent
ac9b4987cf
commit
eb7ff98f6a
2 changed files with 99 additions and 42 deletions
134
src/Toolbar.cc
134
src/Toolbar.cc
|
@ -22,7 +22,7 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: Toolbar.cc,v 1.117 2003/08/27 19:56:56 fluxgen Exp $
|
// $Id: Toolbar.cc,v 1.118 2003/08/28 13:58:18 fluxgen Exp $
|
||||||
|
|
||||||
#include "Toolbar.hh"
|
#include "Toolbar.hh"
|
||||||
|
|
||||||
|
@ -38,17 +38,19 @@
|
||||||
#include "I18n.hh"
|
#include "I18n.hh"
|
||||||
#include "fluxbox.hh"
|
#include "fluxbox.hh"
|
||||||
#include "Screen.hh"
|
#include "Screen.hh"
|
||||||
#include "ImageControl.hh"
|
|
||||||
|
|
||||||
#include "EventManager.hh"
|
|
||||||
#include "SimpleCommand.hh"
|
|
||||||
#include "IntResMenuItem.hh"
|
#include "IntResMenuItem.hh"
|
||||||
#include "MacroCommand.hh"
|
|
||||||
#include "BoolMenuItem.hh"
|
#include "BoolMenuItem.hh"
|
||||||
#include "Xinerama.hh"
|
#include "Xinerama.hh"
|
||||||
#include "Strut.hh"
|
#include "Strut.hh"
|
||||||
#include "FbCommands.hh"
|
#include "FbCommands.hh"
|
||||||
|
|
||||||
|
#include "FbTk/ImageControl.hh"
|
||||||
|
#include "FbTk/MacroCommand.hh"
|
||||||
|
#include "FbTk/EventManager.hh"
|
||||||
|
#include "FbTk/SimpleCommand.hh"
|
||||||
|
#include "FbTk/StringUtil.hh"
|
||||||
|
|
||||||
|
|
||||||
// use GNU extensions
|
// use GNU extensions
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
@ -65,18 +67,7 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <iterator>
|
||||||
#ifdef TIME_WITH_SYS_TIME
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#else // !TIME_WITH_SYS_TIME
|
|
||||||
#ifdef HAVE_SYS_TIME_H
|
|
||||||
#include <sys/time.h>
|
|
||||||
#else // !HAVE_SYS_TIME_H
|
|
||||||
#include <time.h>
|
|
||||||
#endif // HAVE_SYS_TIME_H
|
|
||||||
#endif // TIME_WITH_SYS_TIME
|
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -259,6 +250,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
|
||||||
m_rc_placement(scrn.resourceManager(), Toolbar::BOTTOMCENTER,
|
m_rc_placement(scrn.resourceManager(), Toolbar::BOTTOMCENTER,
|
||||||
scrn.name() + ".toolbar.placement", scrn.altName() + ".Toolbar.Placement"),
|
scrn.name() + ".toolbar.placement", scrn.altName() + ".Toolbar.Placement"),
|
||||||
m_rc_height(scrn.resourceManager(), 0, scrn.name() + ".toolbar.height", scrn.altName() + ".Toolbar.Height"),
|
m_rc_height(scrn.resourceManager(), 0, scrn.name() + ".toolbar.height", scrn.altName() + ".Toolbar.Height"),
|
||||||
|
m_rc_tools(scrn.resourceManager(), "", scrn.name() + ".toolbar.tools", scrn.altName() + ".Toolbar.Tools"),
|
||||||
m_shape(new Shape(frame.window, 0)),
|
m_shape(new Shape(frame.window, 0)),
|
||||||
m_resize_lock(false) {
|
m_resize_lock(false) {
|
||||||
|
|
||||||
|
@ -283,16 +275,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
|
||||||
frame.bevel_w = 1;
|
frame.bevel_w = 1;
|
||||||
frame.grab_x = frame.grab_y = 0;
|
frame.grab_x = frame.grab_y = 0;
|
||||||
|
|
||||||
// add toolbar items
|
// set antialias on themes
|
||||||
WorkspaceNameTool *item = new WorkspaceNameTool(frame.window, m_workspace_theme, screen());
|
|
||||||
using namespace FbTk;
|
|
||||||
RefCount<Command> showmenu(new ShowMenuAboveToolbar(*this));
|
|
||||||
item->button().setOnClick(showmenu);
|
|
||||||
m_item_list.push_back(item);
|
|
||||||
m_item_list.push_back(new IconbarTool(frame.window, m_iconbar_theme, screen()));
|
|
||||||
m_item_list.push_back(new SystemTray(frame.window));
|
|
||||||
m_item_list.push_back(new ClockTool(frame.window, m_clock_theme, screen()));
|
|
||||||
|
|
||||||
m_clock_theme.setAntialias(screen().antialias());
|
m_clock_theme.setAntialias(screen().antialias());
|
||||||
m_iconbar_theme.setAntialias(screen().antialias());
|
m_iconbar_theme.setAntialias(screen().antialias());
|
||||||
m_workspace_theme.setAntialias(screen().antialias());
|
m_workspace_theme.setAntialias(screen().antialias());
|
||||||
|
@ -317,15 +300,13 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
|
||||||
}
|
}
|
||||||
|
|
||||||
Toolbar::~Toolbar() {
|
Toolbar::~Toolbar() {
|
||||||
while (!m_item_list.empty()) {
|
FbTk::EventManager::instance()->remove(window());
|
||||||
delete m_item_list.back();
|
|
||||||
m_item_list.pop_back();
|
deleteItems();
|
||||||
}
|
clearStrut();
|
||||||
|
|
||||||
if (m_window_pm)
|
if (m_window_pm)
|
||||||
screen().imageControl().removeImage(m_window_pm);
|
screen().imageControl().removeImage(m_window_pm);
|
||||||
|
|
||||||
clearStrut();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toolbar::clearStrut() {
|
void Toolbar::clearStrut() {
|
||||||
|
@ -398,6 +379,69 @@ void Toolbar::reconfigure() {
|
||||||
m_iconbar_theme.setAntialias(screen().antialias());
|
m_iconbar_theme.setAntialias(screen().antialias());
|
||||||
m_workspace_theme.setAntialias(screen().antialias());
|
m_workspace_theme.setAntialias(screen().antialias());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// parse resource tools and determine if we need to rebuild toolbar
|
||||||
|
|
||||||
|
bool need_update = false;
|
||||||
|
// parse and transform to lower case
|
||||||
|
std::list<std::string> tools;
|
||||||
|
FbTk::StringUtil::stringtok(tools, *m_rc_tools, ", ");
|
||||||
|
transform(tools.begin(),
|
||||||
|
tools.end(),
|
||||||
|
tools.begin(),
|
||||||
|
FbTk::StringUtil::toLower);
|
||||||
|
|
||||||
|
if (tools.size() == m_tools.size() && tools.size() != 0) {
|
||||||
|
StringList::const_iterator tool_it = tools.begin();
|
||||||
|
StringList::const_iterator current_tool_it = m_tools.begin();
|
||||||
|
StringList::const_iterator tool_it_end = tools.end();
|
||||||
|
for (; tool_it != tool_it_end; ++tool_it, ++current_tool_it) {
|
||||||
|
if (*current_tool_it != *tool_it)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// did we find anything that wasn't in the right place or new item?
|
||||||
|
if (tool_it != tool_it_end)
|
||||||
|
need_update = true;
|
||||||
|
} else // sizes does not match so we update
|
||||||
|
need_update = true;
|
||||||
|
|
||||||
|
if (need_update) {
|
||||||
|
|
||||||
|
// destroy tools and rebuild them
|
||||||
|
deleteItems();
|
||||||
|
|
||||||
|
m_tools = tools; // copy values
|
||||||
|
|
||||||
|
if (m_tools.size()) {
|
||||||
|
// make lower case
|
||||||
|
transform(m_tools.begin(), m_tools.end(),
|
||||||
|
m_tools.begin(),
|
||||||
|
FbTk::StringUtil::toLower);
|
||||||
|
|
||||||
|
// create items
|
||||||
|
StringList::const_iterator item_it = m_tools.begin();
|
||||||
|
StringList::const_iterator item_it_end = m_tools.end();
|
||||||
|
for (; item_it != item_it_end; ++item_it) {
|
||||||
|
if (*item_it == "workspacename") {
|
||||||
|
WorkspaceNameTool *item = new WorkspaceNameTool(frame.window, m_workspace_theme, screen());
|
||||||
|
using namespace FbTk;
|
||||||
|
RefCount<Command> showmenu(new ShowMenuAboveToolbar(*this));
|
||||||
|
item->button().setOnClick(showmenu);
|
||||||
|
m_item_list.push_back(item);
|
||||||
|
} else if (*item_it == "iconbar") {
|
||||||
|
m_item_list.push_back(new IconbarTool(frame.window, m_iconbar_theme, screen()));
|
||||||
|
} else if (*item_it == "systemtray") {
|
||||||
|
m_item_list.push_back(new SystemTray(frame.window));
|
||||||
|
} else if (*item_it == "clock") {
|
||||||
|
m_item_list.push_back(new ClockTool(frame.window, m_clock_theme, screen()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// show all items
|
||||||
|
frame.window.showSubwindows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (doAutoHide())
|
if (doAutoHide())
|
||||||
m_hide_timer.start();
|
m_hide_timer.start();
|
||||||
|
|
||||||
|
@ -517,7 +561,9 @@ void Toolbar::leaveNotifyEvent(XCrossingEvent ¬_used) {
|
||||||
|
|
||||||
|
|
||||||
void Toolbar::exposeEvent(XExposeEvent &ee) {
|
void Toolbar::exposeEvent(XExposeEvent &ee) {
|
||||||
|
if (ee.window == frame.window)
|
||||||
|
frame.window.clearArea(ee.x, ee.y,
|
||||||
|
ee.width, ee.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -526,10 +572,9 @@ void Toolbar::keyPressEvent(XKeyEvent &ke) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toolbar::handleEvent(XEvent &event) {
|
void Toolbar::handleEvent(XEvent &event) {
|
||||||
if (event.type == ConfigureNotify &&
|
if (event.type == ConfigureNotify &&
|
||||||
event.xconfigure.window != window().window()) {
|
event.xconfigure.window != window().window())
|
||||||
rearrangeItems();
|
rearrangeItems();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toolbar::update(FbTk::Subject *subj) {
|
void Toolbar::update(FbTk::Subject *subj) {
|
||||||
|
@ -845,7 +890,8 @@ void Toolbar::saveOnHead(int head) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toolbar::rearrangeItems() {
|
void Toolbar::rearrangeItems() {
|
||||||
if (m_resize_lock || screen().isShuttingdown())
|
if (m_resize_lock || screen().isShuttingdown() ||
|
||||||
|
m_item_list.size() == 0)
|
||||||
return;
|
return;
|
||||||
// lock this
|
// lock this
|
||||||
m_resize_lock = true;
|
m_resize_lock = true;
|
||||||
|
@ -886,3 +932,11 @@ void Toolbar::rearrangeItems() {
|
||||||
// unlock
|
// unlock
|
||||||
m_resize_lock = false;
|
m_resize_lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Toolbar::deleteItems() {
|
||||||
|
while (!m_item_list.empty()) {
|
||||||
|
delete m_item_list.back();
|
||||||
|
m_item_list.pop_back();
|
||||||
|
}
|
||||||
|
m_tools.clear();
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: Toolbar.hh,v 1.44 2003/08/19 21:28:57 fluxgen Exp $
|
// $Id: Toolbar.hh,v 1.45 2003/08/28 13:58:17 fluxgen Exp $
|
||||||
|
|
||||||
#ifndef TOOLBAR_HH
|
#ifndef TOOLBAR_HH
|
||||||
#define TOOLBAR_HH
|
#define TOOLBAR_HH
|
||||||
|
@ -139,6 +139,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rearrangeItems();
|
void rearrangeItems();
|
||||||
|
void deleteItems();
|
||||||
|
|
||||||
void updateIconbarGraphics();
|
void updateIconbarGraphics();
|
||||||
void setupMenus();
|
void setupMenus();
|
||||||
|
@ -186,8 +187,10 @@ private:
|
||||||
FbTk::Resource<int> m_rc_on_head;
|
FbTk::Resource<int> m_rc_on_head;
|
||||||
FbTk::Resource<Placement> m_rc_placement;
|
FbTk::Resource<Placement> m_rc_placement;
|
||||||
FbTk::Resource<int> m_rc_height;
|
FbTk::Resource<int> m_rc_height;
|
||||||
|
FbTk::Resource<std::string> m_rc_tools;
|
||||||
std::auto_ptr<Shape> m_shape;
|
std::auto_ptr<Shape> m_shape;
|
||||||
|
typedef std::list<std::string> StringList;
|
||||||
|
StringList m_tools;
|
||||||
|
|
||||||
bool m_resize_lock; ///< to lock rearrangeItems or not
|
bool m_resize_lock; ///< to lock rearrangeItems or not
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue