aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathias <mathias>2005-04-27 09:52:30 (GMT)
committermathias <mathias>2005-04-27 09:52:30 (GMT)
commitb97c3db25193c3b549e46910604d27e5ff92baa2 (patch)
treee0625ab80a5dd1f814e58d3d680cc78d9f5cc53b /src
parent6df9d6ed54a299c0897cdd2d8aa380dc02b15a41 (diff)
downloadfluxbox_pavel-b97c3db25193c3b549e46910604d27e5ff92baa2.zip
fluxbox_pavel-b97c3db25193c3b549e46910604d27e5ff92baa2.tar.bz2
close #1182770
if someone changed the session.screen0.workspaces:<int> value and fired a "reload config"/reconfigure-Command fluxbox crashed. changes: - cleaner way of reading in the workspacenames - cleaner way of initialize the workspaces in BScreen() - on BScreen::reconfigure we add/delete Workspaces to the current screen until init-file and fluxbox are in sync -> the user changed the initfile and pressed reload, so imho he wants to have the changes in the init-file realized.
Diffstat (limited to 'src')
-rw-r--r--src/Screen.cc42
-rw-r--r--src/Workspace.cc4
-rw-r--r--src/WorkspaceNameTool.cc17
-rw-r--r--src/fluxbox.cc30
4 files changed, 49 insertions, 44 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index fae0aff..45f9693 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -328,22 +328,12 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
328 renderPosWindow(); 328 renderPosWindow();
329 329
330 // setup workspaces and workspace menu 330 // setup workspaces and workspace menu
331 331 int nr_ws = *resource.workspaces;
332 if (*resource.workspaces != 0) { 332 addWorkspace(); // at least one
333 for (int i = 0; i < *resource.workspaces; ++i) { 333 for (int i = 1; i < nr_ws; ++i) {
334 Workspace *wkspc = new Workspace(*this, m_layermanager, 334 addWorkspace();
335 getNameOfWorkspace(m_workspaces_list.size()),
336 m_workspaces_list.size());
337 m_workspaces_list.push_back(wkspc);
338 }
339 } else { // create at least one workspace
340 Workspace *wkspc = new Workspace(*this, m_layermanager,
341 getNameOfWorkspace(m_workspaces_list.size()),
342 m_workspaces_list.size());
343 m_workspaces_list.push_back(wkspc);
344 } 335 }
345 336
346
347 m_current_workspace = m_workspaces_list.front(); 337 m_current_workspace = m_workspaces_list.front();
348 338
349 339
@@ -656,6 +646,7 @@ void BScreen::hideWindowMenus(const FluxboxWindow* except) {
656 646
657 647
658void BScreen::reconfigure() { 648void BScreen::reconfigure() {
649
659 m_windowtheme->setFocusedAlpha(*resource.focused_alpha); 650 m_windowtheme->setFocusedAlpha(*resource.focused_alpha);
660 m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha); 651 m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha);
661 m_menutheme->setAlpha(*resource.menu_alpha); 652 m_menutheme->setAlpha(*resource.menu_alpha);
@@ -688,6 +679,18 @@ void BScreen::reconfigure() {
688 renderGeomWindow(); 679 renderGeomWindow();
689 renderPosWindow(); 680 renderPosWindow();
690 681
682 // realize the number of workspaces from the init-file
683 const int nr_ws = *resource.workspaces;
684 if (nr_ws > m_workspaces_list.size()) {
685 while(nr_ws != m_workspaces_list.size()) {
686 addWorkspace();
687 }
688 } else if (nr_ws < m_workspaces_list.size()) {
689 while(nr_ws != m_workspaces_list.size()) {
690 removeLastWorkspace();
691 }
692 }
693
691 //reconfigure menus 694 //reconfigure menus
692 m_workspacemenu->reconfigure(); 695 m_workspacemenu->reconfigure();
693 m_configmenu->reconfigure(); 696 m_configmenu->reconfigure();
@@ -851,11 +854,16 @@ void BScreen::setAntialias(bool value) {
851} 854}
852 855
853int BScreen::addWorkspace() { 856int BScreen::addWorkspace() {
857
858 bool save_name = getNameOfWorkspace(m_workspaces_list.size()) != "" ? false : true;
854 Workspace *wkspc = new Workspace(*this, m_layermanager, 859 Workspace *wkspc = new Workspace(*this, m_layermanager,
855 "", 860 getNameOfWorkspace(m_workspaces_list.size()),
856 m_workspaces_list.size()); 861 m_workspaces_list.size());
857 m_workspaces_list.push_back(wkspc); 862 m_workspaces_list.push_back(wkspc);
858 addWorkspaceName(wkspc->name().c_str()); // update names 863
864 if (save_name)
865 addWorkspaceName(wkspc->name().c_str()); //update names
866
859 saveWorkspaces(m_workspaces_list.size()); 867 saveWorkspaces(m_workspaces_list.size());
860 868
861 updateNetizenWorkspaceCount(); 869 updateNetizenWorkspaceCount();
@@ -879,8 +887,6 @@ int BScreen::removeLastWorkspace() {
879 //remove last workspace 887 //remove last workspace
880 m_workspaces_list.pop_back(); 888 m_workspaces_list.pop_back();
881 889
882
883
884 updateNetizenWorkspaceCount(); 890 updateNetizenWorkspaceCount();
885 saveWorkspaces(m_workspaces_list.size()); 891 saveWorkspaces(m_workspaces_list.size());
886 // must be deleted after we send notify!! 892 // must be deleted after we send notify!!
diff --git a/src/Workspace.cc b/src/Workspace.cc
index 4985c39..8a6bdbb 100644
--- a/src/Workspace.cc
+++ b/src/Workspace.cc
@@ -364,7 +364,7 @@ void Workspace::update(FbTk::Subject *subj) {
364 364
365 365
366void Workspace::setName(const std::string &name) { 366void Workspace::setName(const std::string &name) {
367 if (!name.empty()) { 367 if (!name.empty() && name != "") {
368 m_name = name; 368 m_name = name;
369 } else { //if name == 0 then set default name from nls 369 } else { //if name == 0 then set default name from nls
370 _FB_USES_NLS; 370 _FB_USES_NLS;
@@ -375,7 +375,7 @@ void Workspace::setName(const std::string &name) {
375 m_id + 1); //m_id starts at 0 375 m_id + 1); //m_id starts at 0
376 m_name = tname; 376 m_name = tname;
377 } 377 }
378 378
379 screen().updateWorkspaceNamesAtom(); 379 screen().updateWorkspaceNamesAtom();
380 380
381 menu().setLabel(m_name.c_str()); 381 menu().setLabel(m_name.c_str());
diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc
index dbbc571..fdc4ffe 100644
--- a/src/WorkspaceNameTool.cc
+++ b/src/WorkspaceNameTool.cc
@@ -30,6 +30,8 @@
30 30
31#include "FbTk/ImageControl.hh" 31#include "FbTk/ImageControl.hh"
32 32
33#include <algorithm>
34
33WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent, 35WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent,
34 ToolTheme &theme, BScreen &screen): 36 ToolTheme &theme, BScreen &screen):
35 ToolbarItem(ToolbarItem::FIXED), 37 ToolbarItem(ToolbarItem::FIXED),
@@ -68,6 +70,7 @@ void WorkspaceNameTool::moveResize(int x, int y,
68} 70}
69 71
70void WorkspaceNameTool::update(FbTk::Subject *subj) { 72void WorkspaceNameTool::update(FbTk::Subject *subj) {
73
71 m_button.setText(m_screen.currentWorkspace()->name()); 74 m_button.setText(m_screen.currentWorkspace()->name());
72 if (m_button.width() != width()) { 75 if (m_button.width() != width()) {
73 resize(width(), height()); 76 resize(width(), height());
@@ -79,13 +82,13 @@ void WorkspaceNameTool::update(FbTk::Subject *subj) {
79 82
80unsigned int WorkspaceNameTool::width() const { 83unsigned int WorkspaceNameTool::width() const {
81 // calculate largest size 84 // calculate largest size
82 int max_size = 0; 85 unsigned int max_size = 0;
83 const int num_workspaces = m_screen.getNumberOfWorkspaces(); 86 const BScreen::Workspaces& workspaces = m_screen.getWorkspacesList();
84 for (int workspace = 0; workspace < num_workspaces; ++workspace) { 87 BScreen::Workspaces::const_iterator it;
85 const std::string &name = m_screen.getWorkspace(workspace)->name().c_str(); 88 for (it = workspaces.begin(); it != workspaces.end(); it++) {
86 int size = m_theme.font().textWidth(name.c_str(), name.size()); 89 const std::string &name = (*it)->name();
87 if (size > max_size) 90 max_size = std::max(m_theme.font().textWidth(name.c_str(), name.size()),
88 max_size = size; 91 max_size);
89 } 92 }
90 // so align text dont cut the last character 93 // so align text dont cut the last character
91 max_size += 2; 94 max_size += 2;
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 0865bc2..299207e 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -374,7 +374,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile
374 } 374 }
375 375
376 m_keyscreen = m_mousescreen = m_screen_list.front(); 376 m_keyscreen = m_mousescreen = m_screen_list.front();
377 377
378 // setup theme manager to have our style file ready to be scanned 378 // setup theme manager to have our style file ready to be scanned
379 FbTk::ThemeManager::instance().load(FbTk::StringUtil::expandFilename(getStyleFilename())); 379 FbTk::ThemeManager::instance().load(FbTk::StringUtil::expandFilename(getStyleFilename()));
380 380
@@ -388,7 +388,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile
388 388
389 m_resourcemanager.unlock(); 389 m_resourcemanager.unlock();
390 ungrab(); 390 ungrab();
391 391
392#ifdef DEBUG 392#ifdef DEBUG
393 if (m_resourcemanager.lockDepth() != 0) 393 if (m_resourcemanager.lockDepth() != 0)
394 cerr<<"--- resource manager lockdepth = "<<m_resourcemanager.lockDepth()<<endl; 394 cerr<<"--- resource manager lockdepth = "<<m_resourcemanager.lockDepth()<<endl;
@@ -1568,22 +1568,18 @@ void Fluxbox::load_rc(BScreen &screen) {
1568 cerr<<__FILE__<<"("<<__FUNCTION__<<"): Workspaces="<< 1568 cerr<<__FILE__<<"("<<__FUNCTION__<<"): Workspaces="<<
1569 screen.getNumberOfWorkspaces()<<endl; 1569 screen.getNumberOfWorkspaces()<<endl;
1570#endif // DEBUG 1570#endif // DEBUG
1571 char *search = StringUtil::strdup(value.addr); 1571 string values(value.addr);
1572 1572 BScreen::WorkspaceNames names;
1573 int i; 1573
1574 for (i = 0; i < screen.getNumberOfWorkspaces(); i++) { 1574 StringUtil::removeTrailingWhitespace(values);
1575 char *nn; 1575 StringUtil::removeFirstWhitespace(values);
1576 1576 StringUtil::stringtok<BScreen::WorkspaceNames>(names, values, ",");
1577 if (! i) nn = strtok(search, ","); 1577 BScreen::WorkspaceNames::iterator it;
1578 else nn = strtok(0, ","); 1578 for(it = names.begin(); it != names.end(); it++) {
1579 1579 if (!(*it).empty() && (*it) != "")
1580 if (nn) 1580 screen.addWorkspaceName((*it).c_str());
1581 screen.addWorkspaceName(nn);
1582 else break;
1583
1584 } 1581 }
1585 1582
1586 delete [] search;
1587 } 1583 }
1588 1584
1589 FbTk::Image::removeAllSearchPaths(); 1585 FbTk::Image::removeAllSearchPaths();