aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathias <mathias>2005-07-25 23:17:41 (GMT)
committermathias <mathias>2005-07-25 23:17:41 (GMT)
commit7b21abc421380f10fa76823702eb99a8cf13297b (patch)
treee17b9d47070ad5ebbff2161ff0bd37cbfae420b9 /src
parent460dffdcc1f2de5463225feedd7d02f6f27958c2 (diff)
downloadfluxbox-7b21abc421380f10fa76823702eb99a8cf13297b.zip
fluxbox-7b21abc421380f10fa76823702eb99a8cf13297b.tar.bz2
Fix for #1240248, Segfaults for :MoveTabLeft/Right
wrong code in Container.cc
Diffstat (limited to 'src')
-rw-r--r--src/Container.cc32
-rw-r--r--src/FbWinFrame.cc4
-rw-r--r--src/Window.cc24
3 files changed, 27 insertions, 33 deletions
diff --git a/src/Container.cc b/src/Container.cc
index 3a53a4b..0c2ddd5 100644
--- a/src/Container.cc
+++ b/src/Container.cc
@@ -28,6 +28,8 @@
28#include "FbTk/EventManager.hh" 28#include "FbTk/EventManager.hh"
29#include "CompareWindow.hh" 29#include "CompareWindow.hh"
30 30
31#include <algorithm>
32
31Container::Container(const FbTk::FbWindow &parent): 33Container::Container(const FbTk::FbWindow &parent):
32 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), 34 FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask),
33 m_align(RELATIVE), 35 m_align(RELATIVE),
@@ -113,35 +115,31 @@ void Container::insertItem(Item item, int pos) {
113} 115}
114 116
115void Container::moveItem(Item item, int movement) { 117void Container::moveItem(Item item, int movement) {
118
116 int index = find(item); 119 int index = find(item);
117 if (index < 0) 120 const int size = m_item_list.size();
121
122 if (index < 0 || (movement % size) == 0) {
118 return; 123 return;
124 }
119 125
120 int size = m_item_list.size();
121 int newindex = (index + movement) % size; 126 int newindex = (index + movement) % size;
122 if (newindex < 0) // neg wrap 127 if (newindex < 0) // neg wrap
123 newindex += size; 128 newindex += size;
124 129
125 if (newindex > index) // one smaller now 130 ItemList::iterator it = std::find(m_item_list.begin(),
126 --newindex; 131 m_item_list.end(),
127 132 item);
128 ItemList::iterator it = m_item_list.begin(); 133 m_item_list.erase(it);
129 for (; newindex > 0 && index > 0; ++it, --newindex, --index) { 134
135 for (it = m_item_list.begin(); newindex >= 0; ++it, --newindex) {
130 if (newindex == 0) { 136 if (newindex == 0) {
131 m_item_list.insert(it, item); 137 break;
132 ++newindex;
133 }
134
135 if (index == 0) {
136 m_item_list.erase(it);
137 --index;
138 } 138 }
139 } 139 }
140 140
141 m_item_list.insert(it, item); 141 m_item_list.insert(it, item);
142 insertItem(item, newindex);
143 repositionItems(); 142 repositionItems();
144
145} 143}
146 144
147// returns true if something was done 145// returns true if something was done
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index 9ac2935..53d1d2c 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -372,7 +372,7 @@ void FbWinFrame::moveLabelButtonLeft(FbTk::TextButton &btn) {
372} 372}
373 373
374void FbWinFrame::moveLabelButtonRight(FbTk::TextButton &btn) { 374void FbWinFrame::moveLabelButtonRight(FbTk::TextButton &btn) {
375 m_tab_container.moveItem(&btn, -1); 375 m_tab_container.moveItem(&btn, +1);
376} 376}
377 377
378void FbWinFrame::moveLabelButtonTo(FbTk::TextButton &btn, int x, int y) { 378void FbWinFrame::moveLabelButtonTo(FbTk::TextButton &btn, int x, int y) {
@@ -394,7 +394,7 @@ void FbWinFrame::moveLabelButtonRightOf(FbTk::TextButton &btn, const FbTk::TextB
394 if (pos < 0) 394 if (pos < 0)
395 return; 395 return;
396 396
397 m_tab_container.moveItem(&btn, pos-1); 397 m_tab_container.moveItem(&btn, pos+1);
398} 398}
399 399
400void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn) { 400void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn) {
diff --git a/src/Window.cc b/src/Window.cc
index 88690ce..db430f9 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -864,14 +864,12 @@ void FluxboxWindow::moveClientLeft() {
864 if (m_clientlist.size() == 1 || 864 if (m_clientlist.size() == 1 ||
865 *m_clientlist.begin() == &winClient()) 865 *m_clientlist.begin() == &winClient())
866 return; 866 return;
867 // move label button to the left 867
868 frame().moveLabelButtonLeft(*m_labelbuttons[&winClient()]);
869 // move client in clientlist to the left 868 // move client in clientlist to the left
870 ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), &winClient()); 869 ClientList::iterator oldpos = find(m_clientlist.begin(), m_clientlist.end(), &winClient());
871 ClientList::iterator new_pos = it; 870 ClientList::iterator newpos = oldpos; newpos--;
872 new_pos--; 871 std::swap(*newpos, *oldpos);
873 m_clientlist.erase(it); 872 frame().moveLabelButtonLeft(*m_labelbuttons[&winClient()]);
874 m_clientlist.insert(new_pos, &winClient());
875 873
876 updateClientLeftWindow(); 874 updateClientLeftWindow();
877 875
@@ -879,15 +877,13 @@ void FluxboxWindow::moveClientLeft() {
879 877
880void FluxboxWindow::moveClientRight() { 878void FluxboxWindow::moveClientRight() {
881 if (m_clientlist.size() == 1 || 879 if (m_clientlist.size() == 1 ||
882 *m_clientlist.rbegin() == &winClient()) 880 *m_clientlist.rbegin() == &winClient())
883 return; 881 return;
884 // move label button to the right 882
883 ClientList::iterator oldpos = find(m_clientlist.begin(), m_clientlist.end(), &winClient());
884 ClientList::iterator newpos = oldpos; newpos++;
885 std::swap(*newpos, *oldpos);
885 frame().moveLabelButtonRight(*m_labelbuttons[&winClient()]); 886 frame().moveLabelButtonRight(*m_labelbuttons[&winClient()]);
886 // move client in clientlist to the right
887 ClientList::iterator it = find(m_clientlist.begin(), m_clientlist.end(), &winClient());
888 ClientList::iterator new_pos = m_clientlist.erase(it);
889 new_pos++;
890 m_clientlist.insert(new_pos, &winClient());
891 887
892 updateClientLeftWindow(); 888 updateClientLeftWindow();
893} 889}