aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-28 13:58:18 (GMT)
committerfluxgen <fluxgen>2003-08-28 13:58:18 (GMT)
commiteb7ff98f6af6feb8ff6f4122b978a3ff1a180e2f (patch)
tree444ed109545361164ca442af0de2d973bb36b721
parentac9b4987cf21d28b9900e3af79906a095d4f9840 (diff)
downloadfluxbox-eb7ff98f6af6feb8ff6f4122b978a3ff1a180e2f.zip
fluxbox-eb7ff98f6af6feb8ff6f4122b978a3ff1a180e2f.tar.bz2
added configurable tools
-rw-r--r--src/Toolbar.cc134
-rw-r--r--src/Toolbar.hh7
2 files changed, 99 insertions, 42 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index ab78f09..624c907 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Toolbar.cc,v 1.117 2003/08/27 19:56:56 fluxgen Exp $ 25// $Id: Toolbar.cc,v 1.118 2003/08/28 13:58:18 fluxgen Exp $
26 26
27#include "Toolbar.hh" 27#include "Toolbar.hh"
28 28
@@ -38,17 +38,19 @@
38#include "I18n.hh" 38#include "I18n.hh"
39#include "fluxbox.hh" 39#include "fluxbox.hh"
40#include "Screen.hh" 40#include "Screen.hh"
41#include "ImageControl.hh"
42
43#include "EventManager.hh"
44#include "SimpleCommand.hh"
45#include "IntResMenuItem.hh" 41#include "IntResMenuItem.hh"
46#include "MacroCommand.hh"
47#include "BoolMenuItem.hh" 42#include "BoolMenuItem.hh"
48#include "Xinerama.hh" 43#include "Xinerama.hh"
49#include "Strut.hh" 44#include "Strut.hh"
50#include "FbCommands.hh" 45#include "FbCommands.hh"
51 46
47#include "FbTk/ImageControl.hh"
48#include "FbTk/MacroCommand.hh"
49#include "FbTk/EventManager.hh"
50#include "FbTk/SimpleCommand.hh"
51#include "FbTk/StringUtil.hh"
52
53
52// use GNU extensions 54// use GNU extensions
53#ifndef _GNU_SOURCE 55#ifndef _GNU_SOURCE
54#define _GNU_SOURCE 56#define _GNU_SOURCE
@@ -65,18 +67,7 @@
65 67
66#include <cstring> 68#include <cstring>
67#include <cstdio> 69#include <cstdio>
68 70#include <iterator>
69#ifdef TIME_WITH_SYS_TIME
70#include <sys/time.h>
71#include <time.h>
72#else // !TIME_WITH_SYS_TIME
73#ifdef HAVE_SYS_TIME_H
74#include <sys/time.h>
75#else // !HAVE_SYS_TIME_H
76#include <time.h>
77#endif // HAVE_SYS_TIME_H
78#endif // TIME_WITH_SYS_TIME
79
80 71
81#include <iostream> 72#include <iostream>
82 73
@@ -259,6 +250,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
259 m_rc_placement(scrn.resourceManager(), Toolbar::BOTTOMCENTER, 250 m_rc_placement(scrn.resourceManager(), Toolbar::BOTTOMCENTER,
260 scrn.name() + ".toolbar.placement", scrn.altName() + ".Toolbar.Placement"), 251 scrn.name() + ".toolbar.placement", scrn.altName() + ".Toolbar.Placement"),
261 m_rc_height(scrn.resourceManager(), 0, scrn.name() + ".toolbar.height", scrn.altName() + ".Toolbar.Height"), 252 m_rc_height(scrn.resourceManager(), 0, scrn.name() + ".toolbar.height", scrn.altName() + ".Toolbar.Height"),
253 m_rc_tools(scrn.resourceManager(), "", scrn.name() + ".toolbar.tools", scrn.altName() + ".Toolbar.Tools"),
262 m_shape(new Shape(frame.window, 0)), 254 m_shape(new Shape(frame.window, 0)),
263 m_resize_lock(false) { 255 m_resize_lock(false) {
264 256
@@ -283,16 +275,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
283 frame.bevel_w = 1; 275 frame.bevel_w = 1;
284 frame.grab_x = frame.grab_y = 0; 276 frame.grab_x = frame.grab_y = 0;
285 277
286 // add toolbar items 278 // set antialias on themes
287 WorkspaceNameTool *item = new WorkspaceNameTool(frame.window, m_workspace_theme, screen());
288 using namespace FbTk;
289 RefCount<Command> showmenu(new ShowMenuAboveToolbar(*this));
290 item->button().setOnClick(showmenu);
291 m_item_list.push_back(item);
292 m_item_list.push_back(new IconbarTool(frame.window, m_iconbar_theme, screen()));
293 m_item_list.push_back(new SystemTray(frame.window));
294 m_item_list.push_back(new ClockTool(frame.window, m_clock_theme, screen()));
295
296 m_clock_theme.setAntialias(screen().antialias()); 279 m_clock_theme.setAntialias(screen().antialias());
297 m_iconbar_theme.setAntialias(screen().antialias()); 280 m_iconbar_theme.setAntialias(screen().antialias());
298 m_workspace_theme.setAntialias(screen().antialias()); 281 m_workspace_theme.setAntialias(screen().antialias());
@@ -317,15 +300,13 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, FbTk::Menu &menu, size_t wi
317} 300}
318 301
319Toolbar::~Toolbar() { 302Toolbar::~Toolbar() {
320 while (!m_item_list.empty()) { 303 FbTk::EventManager::instance()->remove(window());
321 delete m_item_list.back(); 304
322 m_item_list.pop_back(); 305 deleteItems();
323 } 306 clearStrut();
324 307
325 if (m_window_pm) 308 if (m_window_pm)
326 screen().imageControl().removeImage(m_window_pm); 309 screen().imageControl().removeImage(m_window_pm);
327
328 clearStrut();
329} 310}
330 311
331void Toolbar::clearStrut() { 312void Toolbar::clearStrut() {
@@ -398,6 +379,69 @@ void Toolbar::reconfigure() {
398 m_iconbar_theme.setAntialias(screen().antialias()); 379 m_iconbar_theme.setAntialias(screen().antialias());
399 m_workspace_theme.setAntialias(screen().antialias()); 380 m_workspace_theme.setAntialias(screen().antialias());
400 381
382
383
384 // parse resource tools and determine if we need to rebuild toolbar
385
386 bool need_update = false;
387 // parse and transform to lower case
388 std::list<std::string> tools;
389 FbTk::StringUtil::stringtok(tools, *m_rc_tools, ", ");
390 transform(tools.begin(),
391 tools.end(),
392 tools.begin(),
393 FbTk::StringUtil::toLower);
394
395 if (tools.size() == m_tools.size() && tools.size() != 0) {
396 StringList::const_iterator tool_it = tools.begin();
397 StringList::const_iterator current_tool_it = m_tools.begin();
398 StringList::const_iterator tool_it_end = tools.end();
399 for (; tool_it != tool_it_end; ++tool_it, ++current_tool_it) {
400 if (*current_tool_it != *tool_it)
401 break;
402 }
403 // did we find anything that wasn't in the right place or new item?
404 if (tool_it != tool_it_end)
405 need_update = true;
406 } else // sizes does not match so we update
407 need_update = true;
408
409 if (need_update) {
410
411 // destroy tools and rebuild them
412 deleteItems();
413
414 m_tools = tools; // copy values
415
416 if (m_tools.size()) {
417 // make lower case
418 transform(m_tools.begin(), m_tools.end(),
419 m_tools.begin(),
420 FbTk::StringUtil::toLower);
421
422 // create items
423 StringList::const_iterator item_it = m_tools.begin();
424 StringList::const_iterator item_it_end = m_tools.end();
425 for (; item_it != item_it_end; ++item_it) {
426 if (*item_it == "workspacename") {
427 WorkspaceNameTool *item = new WorkspaceNameTool(frame.window, m_workspace_theme, screen());
428 using namespace FbTk;
429 RefCount<Command> showmenu(new ShowMenuAboveToolbar(*this));
430 item->button().setOnClick(showmenu);
431 m_item_list.push_back(item);
432 } else if (*item_it == "iconbar") {
433 m_item_list.push_back(new IconbarTool(frame.window, m_iconbar_theme, screen()));
434 } else if (*item_it == "systemtray") {
435 m_item_list.push_back(new SystemTray(frame.window));
436 } else if (*item_it == "clock") {
437 m_item_list.push_back(new ClockTool(frame.window, m_clock_theme, screen()));
438 }
439 }
440 // show all items
441 frame.window.showSubwindows();
442 }
443 }
444
401 if (doAutoHide()) 445 if (doAutoHide())
402 m_hide_timer.start(); 446 m_hide_timer.start();
403 447
@@ -517,7 +561,9 @@ void Toolbar::leaveNotifyEvent(XCrossingEvent &not_used) {
517 561
518 562
519void Toolbar::exposeEvent(XExposeEvent &ee) { 563void Toolbar::exposeEvent(XExposeEvent &ee) {
520 564 if (ee.window == frame.window)
565 frame.window.clearArea(ee.x, ee.y,
566 ee.width, ee.height);
521} 567}
522 568
523 569
@@ -526,10 +572,9 @@ void Toolbar::keyPressEvent(XKeyEvent &ke) {
526} 572}
527 573
528void Toolbar::handleEvent(XEvent &event) { 574void Toolbar::handleEvent(XEvent &event) {
529 if (event.type == ConfigureNotify && 575 if (event.type == ConfigureNotify &&
530 event.xconfigure.window != window().window()) { 576 event.xconfigure.window != window().window())
531 rearrangeItems(); 577 rearrangeItems();
532 }
533} 578}
534 579
535void Toolbar::update(FbTk::Subject *subj) { 580void Toolbar::update(FbTk::Subject *subj) {
@@ -845,7 +890,8 @@ void Toolbar::saveOnHead(int head) {
845} 890}
846 891
847void Toolbar::rearrangeItems() { 892void Toolbar::rearrangeItems() {
848 if (m_resize_lock || screen().isShuttingdown()) 893 if (m_resize_lock || screen().isShuttingdown() ||
894 m_item_list.size() == 0)
849 return; 895 return;
850 // lock this 896 // lock this
851 m_resize_lock = true; 897 m_resize_lock = true;
@@ -886,3 +932,11 @@ void Toolbar::rearrangeItems() {
886 // unlock 932 // unlock
887 m_resize_lock = false; 933 m_resize_lock = false;
888} 934}
935
936void Toolbar::deleteItems() {
937 while (!m_item_list.empty()) {
938 delete m_item_list.back();
939 m_item_list.pop_back();
940 }
941 m_tools.clear();
942}
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index 3e9878c..981fb1a 100644
--- a/src/Toolbar.hh
+++ b/src/Toolbar.hh
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Toolbar.hh,v 1.44 2003/08/19 21:28:57 fluxgen Exp $ 25// $Id: Toolbar.hh,v 1.45 2003/08/28 13:58:17 fluxgen Exp $
26 26
27#ifndef TOOLBAR_HH 27#ifndef TOOLBAR_HH
28#define TOOLBAR_HH 28#define TOOLBAR_HH
@@ -139,6 +139,7 @@ public:
139 139
140private: 140private:
141 void rearrangeItems(); 141 void rearrangeItems();
142 void deleteItems();
142 143
143 void updateIconbarGraphics(); 144 void updateIconbarGraphics();
144 void setupMenus(); 145 void setupMenus();
@@ -186,8 +187,10 @@ private:
186 FbTk::Resource<int> m_rc_on_head; 187 FbTk::Resource<int> m_rc_on_head;
187 FbTk::Resource<Placement> m_rc_placement; 188 FbTk::Resource<Placement> m_rc_placement;
188 FbTk::Resource<int> m_rc_height; 189 FbTk::Resource<int> m_rc_height;
190 FbTk::Resource<std::string> m_rc_tools;
189 std::auto_ptr<Shape> m_shape; 191 std::auto_ptr<Shape> m_shape;
190 192 typedef std::list<std::string> StringList;
193 StringList m_tools;
191 194
192 bool m_resize_lock; ///< to lock rearrangeItems or not 195 bool m_resize_lock; ///< to lock rearrangeItems or not
193}; 196};