replaced LinkedList with stl container

This commit is contained in:
fluxgen 2002-02-04 22:33:09 +00:00
parent 1207f0cd2e
commit 0c4c33f9f5
4 changed files with 224 additions and 197 deletions

View file

@ -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: Basemenu.cc,v 1.7 2002/01/26 11:22:06 fluxgen Exp $ // $Id: Basemenu.cc,v 1.8 2002/02/04 22:33:09 fluxgen Exp $
// stupid macros needed to access some functions in version 2 of the GNU C // stupid macros needed to access some functions in version 2 of the GNU C
// library // library
@ -155,8 +155,6 @@ Basemenu::Basemenu(BScreen *scrn) {
screen->getVisual(), attrib_mask, &attrib); screen->getVisual(), attrib_mask, &attrib);
fluxbox->saveMenuSearch(menu.frame, this); fluxbox->saveMenuSearch(menu.frame, this);
menuitems = new LinkedList<BasemenuItem>;
// even though this is the end of the constructor the menu is still not // even though this is the end of the constructor the menu is still not
// completely created. items must be inserted and it must be update()'d // completely created. items must be inserted and it must be update()'d
} }
@ -168,12 +166,10 @@ Basemenu::~Basemenu(void) {
if (shown && shown->getWindowID() == getWindowID()) if (shown && shown->getWindowID() == getWindowID())
shown = (Basemenu *) 0; shown = (Basemenu *) 0;
int n = menuitems->count(); int n = menuitems.size() - 1;
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i)
remove(0); remove(0);
delete menuitems;
if (menu.label) if (menu.label)
delete [] menu.label; delete [] menu.label;
@ -207,9 +203,13 @@ int Basemenu::insert(const char *l, int function, const char *e, int pos) {
if (e) exec = StringUtil::strdup(e); if (e) exec = StringUtil::strdup(e);
BasemenuItem *item = new BasemenuItem(label, function, exec); BasemenuItem *item = new BasemenuItem(label, function, exec);
menuitems->insert(item, pos); if (pos == -1) {
menuitems.push_back(item);
} else {
menuitems.insert(menuitems.begin() + pos, item);
}
return menuitems->count(); return menuitems.size();
} }
@ -219,26 +219,35 @@ int Basemenu::insert(const char *l, Basemenu *submenu, int pos) {
if (l) label = StringUtil::strdup(l); if (l) label = StringUtil::strdup(l);
BasemenuItem *item = new BasemenuItem(label, submenu); BasemenuItem *item = new BasemenuItem(label, submenu);
menuitems->insert(item, pos); if (pos == -1) {
menuitems.push_back(item);
} else {
menuitems.insert(menuitems.begin() + pos, item);
}
submenu->parent = this; submenu->parent = this;
return menuitems->count(); return menuitems.size();
} }
int Basemenu::insert(const char **ulabel, int pos, int function) { int Basemenu::insert(const char **ulabel, int pos, int function) {
BasemenuItem *item = new BasemenuItem(ulabel, function); BasemenuItem *item = new BasemenuItem(ulabel, function);
menuitems->insert(item, pos); if (pos == -1) {
menuitems.push_back(item);
} else {
menuitems.insert(menuitems.begin() + pos, item);
}
return menuitems->count(); return menuitems.size();
} }
int Basemenu::remove(int index) { int Basemenu::remove(int index) {
if (index < 0 || index > menuitems->count()) return -1; if (index < 0 || index > menuitems.size()) return -1;
BasemenuItem *item = menuitems->remove(index); Menuitems::iterator it = menuitems.erase(menuitems.begin() + index);
BasemenuItem *item = (*it);
if (item) { if (item) {
if ((! internal_menu) && (item->submenu())) { if ((! internal_menu) && (item->submenu())) {
@ -247,8 +256,7 @@ int Basemenu::remove(int index) {
if (! tmp->internal_menu) { if (! tmp->internal_menu) {
delete tmp; delete tmp;
} else } else
tmp->internal_hide();
tmp->internal_hide();
} }
if (item->label()) if (item->label())
@ -265,7 +273,7 @@ int Basemenu::remove(int index) {
else if (which_sub > index) else if (which_sub > index)
which_sub--; which_sub--;
return menuitems->count(); return menuitems.size();
} }
@ -310,9 +318,10 @@ void Basemenu::update(void) {
menu.item_w = 1; menu.item_w = 1;
int ii = 0; int ii = 0;
LinkedListIterator<BasemenuItem> it(menuitems); Menuitems::iterator it = menuitems.begin();
for (; it.current(); it++) { Menuitems::iterator it_end = menuitems.end();
BasemenuItem *itmp = it.current(); for (; it != it_end; ++it) {
BasemenuItem *itmp = (*it);
const char *s = ((itmp->u && *itmp->u) ? *itmp->u : const char *s = ((itmp->u && *itmp->u) ? *itmp->u :
((itmp->l) ? itmp->l : (const char *) 0)); ((itmp->l) ? itmp->l : (const char *) 0));
@ -330,18 +339,18 @@ void Basemenu::update(void) {
menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w); menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w);
} }
if (menuitems->count()) { if (menuitems.size()) {
menu.sublevels = 1; menu.sublevels = 1;
while (((menu.item_h * (menuitems->count() + 1) / menu.sublevels) while (((menu.item_h * (menuitems.size() + 1) / menu.sublevels)
+ menu.title_h + screen->getBorderWidth()) > + menu.title_h + screen->getBorderWidth()) >
screen->getHeight()) screen->getHeight())
menu.sublevels++; menu.sublevels++;
if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub; if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub;
menu.persub = menuitems->count() / menu.sublevels; menu.persub = menuitems.size() / menu.sublevels;
if (menuitems->count() % menu.sublevels) menu.persub++; if (menuitems.size() % menu.sublevels) menu.persub++;
} else { } else {
menu.sublevels = 0; menu.sublevels = 0;
menu.persub = 0; menu.persub = 0;
@ -423,7 +432,7 @@ void Basemenu::update(void) {
if (title_vis && visible) redrawTitle(); if (title_vis && visible) redrawTitle();
int i = 0; int i = 0;
for (i = 0; visible && i < menuitems->count(); i++) for (i = 0; visible && i < menuitems.size(); i++)
if (i == which_sub) { if (i == which_sub) {
drawItem(i, True, 0); drawItem(i, True, 0);
drawSubmenu(i); drawSubmenu(i);
@ -464,7 +473,7 @@ void Basemenu::hide(void) {
void Basemenu::internal_hide(void) { void Basemenu::internal_hide(void) {
if (which_sub != -1) { if (which_sub != -1) {
BasemenuItem *tmp = menuitems->find(which_sub); BasemenuItem *tmp = menuitems[which_sub];
tmp->submenu()->internal_hide(); tmp->submenu()->internal_hide();
} }
@ -539,14 +548,14 @@ void Basemenu::redrawTitle(void) {
void Basemenu::drawSubmenu(int index) { void Basemenu::drawSubmenu(int index) {
if (which_sub != -1 && which_sub != index) { if (which_sub != -1 && which_sub != index) {
BasemenuItem *itmp = menuitems->find(which_sub); BasemenuItem *itmp = menuitems[which_sub];
if (! itmp->submenu()->isTorn()) if (! itmp->submenu()->isTorn())
itmp->submenu()->internal_hide(); itmp->submenu()->internal_hide();
} }
if (index >= 0 && index < menuitems->count()) { if (index >= 0 && index < menuitems.size()) {
BasemenuItem *item = menuitems->find(index); BasemenuItem *item = menuitems[index];
if (item->submenu() && visible && (! item->submenu()->isTorn()) && if (item->submenu() && visible && (! item->submenu()->isTorn()) &&
item->isEnabled()) { item->isEnabled()) {
@ -607,8 +616,8 @@ void Basemenu::drawSubmenu(int index) {
Bool Basemenu::hasSubmenu(int index) { Bool Basemenu::hasSubmenu(int index) {
if ((index >= 0) && (index < menuitems->count())) if ((index >= 0) && (index < menuitems.size()))
if (menuitems->find(index)->submenu()) if (menuitems[index]->submenu())
return True; return True;
else else
return False; return False;
@ -620,9 +629,9 @@ Bool Basemenu::hasSubmenu(int index) {
void Basemenu::drawItem(int index, Bool highlight, Bool clear, void Basemenu::drawItem(int index, Bool highlight, Bool clear,
int x, int y, unsigned int w, unsigned int h) int x, int y, unsigned int w, unsigned int h)
{ {
if (index < 0 || index > menuitems->count()) return; if (index < 0 || index > menuitems.size()) return;
BasemenuItem *item = menuitems->find(index); BasemenuItem *item = menuitems[index];
if (! item) return; if (! item) return;
Bool dotext = True, dohilite = True, dosel = True; Bool dotext = True, dohilite = True, dosel = True;
@ -802,7 +811,7 @@ void Basemenu::setLabel(const char *l) {
void Basemenu::setItemSelected(int index, Bool sel) { void Basemenu::setItemSelected(int index, Bool sel) {
if (index < 0 || index >= menuitems->count()) return; if (index < 0 || index >= menuitems.size()) return;
BasemenuItem *item = find(index); BasemenuItem *item = find(index);
if (! item) return; if (! item) return;
@ -813,7 +822,7 @@ void Basemenu::setItemSelected(int index, Bool sel) {
Bool Basemenu::isItemSelected(int index) { Bool Basemenu::isItemSelected(int index) {
if (index < 0 || index >= menuitems->count()) return False; if (index < 0 || index >= menuitems.size()) return False;
BasemenuItem *item = find(index); BasemenuItem *item = find(index);
if (! item) return False; if (! item) return False;
@ -823,7 +832,7 @@ Bool Basemenu::isItemSelected(int index) {
void Basemenu::setItemEnabled(int index, Bool enable) { void Basemenu::setItemEnabled(int index, Bool enable) {
if (index < 0 || index >= menuitems->count()) return; if (index < 0 || index >= menuitems.size()) return;
BasemenuItem *item = find(index); BasemenuItem *item = find(index);
if (! item) return; if (! item) return;
@ -834,7 +843,7 @@ void Basemenu::setItemEnabled(int index, Bool enable) {
Bool Basemenu::isItemEnabled(int index) { Bool Basemenu::isItemEnabled(int index) {
if (index < 0 || index >= menuitems->count()) return False; if (index < 0 || index >= menuitems.size()) return False;
BasemenuItem *item = find(index); BasemenuItem *item = find(index);
if (! item) return False; if (! item) return False;
@ -848,11 +857,11 @@ void Basemenu::buttonPressEvent(XButtonEvent *be) {
int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h); int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
int w = (sbl * menu.persub) + i; int w = (sbl * menu.persub) + i;
if (w < menuitems->count() && w >= 0) { if (w < menuitems.size() && w >= 0) {
which_press = i; which_press = i;
which_sbl = sbl; which_sbl = sbl;
BasemenuItem *item = menuitems->find(w); BasemenuItem *item = menuitems[w];
if (item->submenu()) if (item->submenu())
drawSubmenu(w); drawSubmenu(w);
@ -891,7 +900,7 @@ void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
w = (sbl * menu.persub) + i, w = (sbl * menu.persub) + i,
p = (which_sbl * menu.persub) + which_press; p = (which_sbl * menu.persub) + which_press;
if (w < menuitems->count() && w >= 0) { if (w < menuitems.size() && w >= 0) {
drawItem(p, (p == which_sub), True); drawItem(p, (p == which_sub), True);
if (p == w && isItemEnabled(w)) { if (p == w && isItemEnabled(w)) {
@ -937,10 +946,10 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
w = (sbl * menu.persub) + i; w = (sbl * menu.persub) + i;
if ((i != which_press || sbl != which_sbl) && if ((i != which_press || sbl != which_sbl) &&
(w < menuitems->count() && w >= 0)) { (w < menuitems.size() && w >= 0)) {
if (which_press != -1 && which_sbl != -1) { if (which_press != -1 && which_sbl != -1) {
int p = (which_sbl * menu.persub) + which_press; int p = (which_sbl * menu.persub) + which_press;
BasemenuItem *item = menuitems->find(p); BasemenuItem *item = menuitems[p];
drawItem(p, False, True); drawItem(p, False, True);
if (item->submenu()) { if (item->submenu()) {
@ -955,7 +964,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
which_press = i; which_press = i;
which_sbl = sbl; which_sbl = sbl;
BasemenuItem *itmp = menuitems->find(w); BasemenuItem *itmp = menuitems[w];
if (itmp->submenu()) if (itmp->submenu())
drawSubmenu(w); drawSubmenu(w);
@ -970,8 +979,6 @@ void Basemenu::exposeEvent(XExposeEvent *ee) {
if (ee->window == menu.title) { if (ee->window == menu.title) {
redrawTitle(); redrawTitle();
} else if (ee->window == menu.frame) { } else if (ee->window == menu.frame) {
LinkedListIterator<BasemenuItem> it(menuitems);
// this is a compilicated algorithm... lets do it step by step... // this is a compilicated algorithm... lets do it step by step...
// first... we see in which sub level the expose starts... and how many // first... we see in which sub level the expose starts... and how many
// items down in that sublevel // items down in that sublevel
@ -988,12 +995,16 @@ void Basemenu::exposeEvent(XExposeEvent *ee) {
int i, ii; int i, ii;
for (i = sbl; i <= sbl_d; i++) { for (i = sbl; i <= sbl_d; i++) {
// set the iterator to the first item in the sublevel needing redrawing // set the iterator to the first item in the sublevel needing redrawing
it.set(id + (i * menu.persub)); int index = id + i * menu.persub;
for (ii = id; ii <= id_d && it.current(); it++, ii++) { if (index < menuitems.size() && index >= 0) {
int index = ii + (i * menu.persub); Menuitems::iterator it = menuitems.begin() + index;
// redraw the item Menuitems::iterator it_end = menuitems.end();
drawItem(index, (which_sub == index), False, for (ii = id; ii <= id_d && it != it_end; ++it, ii++) {
ee->x, ee->y, ee->width, ee->height); int index = ii + (i * menu.persub);
// redraw the item
drawItem(index, (which_sub == index), False,
ee->x, ee->y, ee->width, ee->height);
}
} }
} }
} }
@ -1025,7 +1036,7 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift); XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift);
if (which_sub != -1) { if (which_sub != -1) {
BasemenuItem *tmp = menuitems->find(which_sub); BasemenuItem *tmp = menuitems[which_sub];
if (tmp->submenu()->isVisible()) { if (tmp->submenu()->isVisible()) {
int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h), int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
w = (sbl * menu.persub) + i; w = (sbl * menu.persub) + i;
@ -1044,7 +1055,7 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) { void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
if (ce->window == menu.frame) { if (ce->window == menu.frame) {
if (which_press != -1 && which_sbl != -1 && menuitems->count() > 0) { if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
int p = (which_sbl * menu.persub) + which_press; int p = (which_sbl * menu.persub) + which_press;
drawItem(p, (p == which_sub), True); drawItem(p, (p == which_sub), True);

View file

@ -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: Basemenu.hh,v 1.4 2002/01/11 09:24:46 fluxgen Exp $ // $Id: Basemenu.hh,v 1.5 2002/02/04 22:33:09 fluxgen Exp $
#ifndef _BASEMENU_HH_ #ifndef _BASEMENU_HH_
#define _BASEMENU_HH_ #define _BASEMENU_HH_
@ -37,12 +37,12 @@ class Fluxbox;
class BImageControl; class BImageControl;
class BScreen; class BScreen;
#include "LinkedList.hh" #include <vector>
class Basemenu { class Basemenu {
private: private:
LinkedList<BasemenuItem> *menuitems; typedef std::vector<BasemenuItem *> Menuitems;
Menuitems menuitems;
Fluxbox *fluxbox; Fluxbox *fluxbox;
Basemenu *parent; Basemenu *parent;
BImageControl *image_ctrl; BImageControl *image_ctrl;
@ -66,7 +66,7 @@ private:
protected: protected:
inline BasemenuItem *find(int index) { return menuitems->find(index); } inline BasemenuItem *find(int index) { return menuitems[index]; }
inline void setTitleVisibility(Bool b) { title_vis = b; } inline void setTitleVisibility(Bool b) { title_vis = b; }
inline void setMovable(Bool b) { movable = b; } inline void setMovable(Bool b) { movable = b; }
inline void setHideTree(Bool h) { hide_tree = h; } inline void setHideTree(Bool h) { hide_tree = h; }
@ -99,7 +99,7 @@ public:
inline const int &getX(void) const { return menu.x; } inline const int &getX(void) const { return menu.x; }
inline const int &getY(void) const { return menu.y; } inline const int &getY(void) const { return menu.y; }
inline int getCount(void) { return menuitems->count(); } inline int getCount(void) { return menuitems.size(); }
inline const int &getCurrentSubmenu(void) const { return which_sub; } inline const int &getCurrentSubmenu(void) const { return which_sub; }
inline const unsigned int &getWidth(void) const { return menu.width; } inline const unsigned int &getWidth(void) const { return menu.width; }

View file

@ -40,6 +40,8 @@
#include "Slit.hh" #include "Slit.hh"
#include "Toolbar.hh" #include "Toolbar.hh"
#include <algorithm>
Slit::Slit(BScreen *scr) { Slit::Slit(BScreen *scr) {
screen = scr; screen = scr;
@ -55,13 +57,11 @@ Slit::Slit(BScreen *scr) {
timer->setTimeout(fluxbox->getAutoRaiseDelay()); timer->setTimeout(fluxbox->getAutoRaiseDelay());
timer->fireOnce(True); timer->fireOnce(True);
clientList = new LinkedList<SlitClient>;
slitmenu = new Slitmenu(this); slitmenu = new Slitmenu(this);
XSetWindowAttributes attrib; XSetWindowAttributes attrib;
unsigned long create_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | unsigned long create_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
CWColormap | CWOverrideRedirect | CWEventMask; CWColormap | CWOverrideRedirect | CWEventMask;
attrib.background_pixmap = None; attrib.background_pixmap = None;
attrib.background_pixel = attrib.border_pixel = attrib.background_pixel = attrib.border_pixel =
screen->getBorderColor()->getPixel(); screen->getBorderColor()->getPixel();
@ -87,10 +87,8 @@ Slit::Slit(BScreen *scr) {
Slit::~Slit() { Slit::~Slit() {
fluxbox->grab(); fluxbox->grab();
if (timer->isTiming()) timer->stop();
delete timer; delete timer;
delete clientList;
delete slitmenu; delete slitmenu;
screen->getImageControl()->removeImage(frame.pixmap); screen->getImageControl()->removeImage(frame.pixmap);
@ -116,9 +114,8 @@ void Slit::addClient(Window w) {
if ((wmhints->flags & IconWindowHint) && if ((wmhints->flags & IconWindowHint) &&
(wmhints->icon_window != None)) { (wmhints->icon_window != None)) {
XMoveWindow(display, client->client_window, screen->getWidth() + 10, XMoveWindow(display, client->client_window, screen->getWidth() + 10,
screen->getHeight() + 10); screen->getHeight() + 10);
XMapWindow(display, client->client_window); XMapWindow(display, client->client_window);
client->icon_window = wmhints->icon_window; client->icon_window = wmhints->icon_window;
client->window = client->icon_window; client->window = client->icon_window;
} else { } else {
@ -150,24 +147,24 @@ void Slit::addClient(Window w) {
// Check if KDE v2.x dock applet // Check if KDE v2.x dock applet
if (XGetWindowProperty(fluxbox->getXDisplay(), w, if (XGetWindowProperty(fluxbox->getXDisplay(), w,
fluxbox->getKWM2DockwindowAtom(), 0l, 1l, False, fluxbox->getKWM2DockwindowAtom(), 0l, 1l, False,
fluxbox->getKWM2DockwindowAtom(), fluxbox->getKWM2DockwindowAtom(),
&ajunk, &ijunk, &uljunk, &uljunk, &ajunk, &ijunk, &uljunk, &uljunk,
(unsigned char **) &data) == Success) { (unsigned char **) &data) == Success) {
iskdedockapp = (data && data[0] != 0); iskdedockapp = (data && data[0] != 0);
XFree((char *) data); XFree((char *) data);
} }
// Check if KDE v1.x dock applet // Check if KDE v1.x dock applet
if (!iskdedockapp) { if (!iskdedockapp) {
if (XGetWindowProperty(fluxbox->getXDisplay(), w, if (XGetWindowProperty(fluxbox->getXDisplay(), w,
fluxbox->getKWM1DockwindowAtom(), 0l, 1l, False, fluxbox->getKWM1DockwindowAtom(), 0l, 1l, False,
fluxbox->getKWM1DockwindowAtom(), fluxbox->getKWM1DockwindowAtom(),
&ajunk, &ijunk, &uljunk, &uljunk, &ajunk, &ijunk, &uljunk, &uljunk,
(unsigned char **) &data) == Success) { (unsigned char **) &data) == Success) {
iskdedockapp = (data && data[0] != 0); iskdedockapp = (data && data[0] != 0);
XFree((char *) data); XFree((char *) data);
} }
} }
if (iskdedockapp) if (iskdedockapp)
@ -187,16 +184,16 @@ void Slit::addClient(Window w) {
XSelectInput(display, client->window, NoEventMask); XSelectInput(display, client->window, NoEventMask);
XReparentWindow(display, client->window, frame.window, 0, 0); XReparentWindow(display, client->window, frame.window, 0, 0);
XMapRaised(display, client->window); //TODO: bbkeys bug here? XMapRaised(display, client->window);
XChangeSaveSet(display, client->window, SetModeInsert); XChangeSaveSet(display, client->window, SetModeInsert);
XSelectInput(display, frame.window, SubstructureRedirectMask | XSelectInput(display, frame.window, SubstructureRedirectMask |
ButtonPressMask | EnterWindowMask | LeaveWindowMask); ButtonPressMask | EnterWindowMask | LeaveWindowMask);
XSelectInput(display, client->window, StructureNotifyMask | XSelectInput(display, client->window, StructureNotifyMask |
SubstructureNotifyMask | EnterWindowMask); SubstructureNotifyMask | EnterWindowMask);
XFlush(display); XFlush(display);
clientList->insert(client); clientList.push_back(client);
fluxbox->saveSlitSearch(client->client_window, this); fluxbox->saveSlitSearch(client->client_window, this);
fluxbox->saveSlitSearch(client->icon_window, this); fluxbox->saveSlitSearch(client->icon_window, this);
@ -207,10 +204,11 @@ void Slit::addClient(Window w) {
} }
void Slit::removeClient(SlitClient *client, Bool remap) { void Slit::removeClient(SlitClient *client, bool remap) {
fluxbox->removeSlitSearch(client->client_window); fluxbox->removeSlitSearch(client->client_window);
fluxbox->removeSlitSearch(client->icon_window); fluxbox->removeSlitSearch(client->icon_window);
clientList->remove(client);
clientList.remove(client);
screen->removeNetizen(client->window); screen->removeNetizen(client->window);
@ -218,10 +216,10 @@ void Slit::removeClient(SlitClient *client, Bool remap) {
XSelectInput(display, frame.window, NoEventMask); XSelectInput(display, frame.window, NoEventMask);
XSelectInput(display, client->window, NoEventMask); XSelectInput(display, client->window, NoEventMask);
XReparentWindow(display, client->window, screen->getRootWindow(), XReparentWindow(display, client->window, screen->getRootWindow(),
client->x, client->y); client->x, client->y);
XChangeSaveSet(display, client->window, SetModeDelete); XChangeSaveSet(display, client->window, SetModeDelete);
XSelectInput(display, frame.window, SubstructureRedirectMask | XSelectInput(display, frame.window, SubstructureRedirectMask |
ButtonPressMask | EnterWindowMask | LeaveWindowMask); ButtonPressMask | EnterWindowMask | LeaveWindowMask);
XFlush(display); XFlush(display);
} }
@ -229,20 +227,21 @@ void Slit::removeClient(SlitClient *client, Bool remap) {
} }
void Slit::removeClient(Window w, Bool remap) { void Slit::removeClient(Window w, bool remap) {
fluxbox->grab(); fluxbox->grab();
Bool reconf = False; bool reconf = false;
LinkedListIterator<SlitClient> it(clientList); SlitClients::iterator it = clientList.begin();
for (; it.current(); it++) SlitClients::iterator it_end = clientList.end();
if (it.current()->window == w) { for (; it != it_end; ++it) {
removeClient(it.current(), remap); if ((*it)->window == w) {
reconf = True; removeClient((*it), remap);
reconf = true;
break; break;
} }
}
if (reconf) reconfigure(); if (reconf) reconfigure();
fluxbox->ungrab(); fluxbox->ungrab();
@ -252,15 +251,18 @@ void Slit::removeClient(Window w, Bool remap) {
void Slit::reconfigure(void) { void Slit::reconfigure(void) {
frame.width = 0; frame.width = 0;
frame.height = 0; frame.height = 0;
LinkedListIterator<SlitClient> it(clientList);
switch (screen->getSlitDirection()) { switch (screen->getSlitDirection()) {
case VERTICAL: case VERTICAL:
for (; it.current(); it++) { {
frame.height += it.current()->height + screen->getBevelWidth(); SlitClients::iterator it = clientList.begin();
SlitClients::iterator it_end = clientList.end();
for (; it != it_end; ++it) {
frame.height += (*it)->height + screen->getBevelWidth();
if (frame.width < it.current()->width) if (frame.width < (*it)->width)
frame.width = it.current()->width; frame.width = (*it)->width;
}
} }
if (frame.width < 1) if (frame.width < 1)
@ -276,11 +278,15 @@ void Slit::reconfigure(void) {
break; break;
case HORIZONTAL: case HORIZONTAL:
for (; it.current(); it++) { {
frame.width += it.current()->width + screen->getBevelWidth(); SlitClients::iterator it = clientList.begin();
SlitClients::iterator it_end = clientList.end();
for (; it != it_end; ++it) {
frame.width += (*it)->width + screen->getBevelWidth();
if (frame.height < it.current()->height) if (frame.height < (*it)->height)
frame.height = it.current()->height; frame.height = (*it)->height;
}
} }
if (frame.width < 1) if (frame.width < 1)
@ -300,9 +306,9 @@ void Slit::reconfigure(void) {
XSetWindowBorderWidth(display ,frame.window, screen->getBorderWidth()); XSetWindowBorderWidth(display ,frame.window, screen->getBorderWidth());
XSetWindowBorder(display, frame.window, XSetWindowBorder(display, frame.window,
screen->getBorderColor()->getPixel()); screen->getBorderColor()->getPixel());
if (! clientList->count()) if (clientList.size()==0)
XUnmapWindow(display, frame.window); XUnmapWindow(display, frame.window);
else else
XMapWindow(display, frame.window); XMapWindow(display, frame.window);
@ -316,49 +322,52 @@ void Slit::reconfigure(void) {
texture->getColor()->getPixel()); texture->getColor()->getPixel());
} else { } else {
frame.pixmap = image_ctrl->renderImage(frame.width, frame.height, frame.pixmap = image_ctrl->renderImage(frame.width, frame.height,
texture); texture);
XSetWindowBackgroundPixmap(display, frame.window, frame.pixmap); XSetWindowBackgroundPixmap(display, frame.window, frame.pixmap);
} }
if (tmp) image_ctrl->removeImage(tmp); if (tmp) image_ctrl->removeImage(tmp);
XClearWindow(display, frame.window); XClearWindow(display, frame.window);
int x, y; int x, y;
it.reset();
switch (screen->getSlitDirection()) { switch (screen->getSlitDirection()) {
case VERTICAL: case VERTICAL:
x = 0; x = 0;
y = screen->getBevelWidth(); y = screen->getBevelWidth();
for (; it.current(); it++) { {
x = (frame.width - it.current()->width) / 2; SlitClients::iterator it = clientList.begin();
SlitClients::iterator it_end = clientList.end();
for (; it != it_end; ++it) {
x = (frame.width - (*it)->width) / 2;
XMoveResizeWindow(display, it.current()->window, x, y, XMoveResizeWindow(display, (*it)->window, x, y,
it.current()->width, it.current()->height); (*it)->width, (*it)->height);
XMapWindow(display, it.current()->window); XMapWindow(display, (*it)->window);
// for ICCCM compliance // for ICCCM compliance
it.current()->x = x; (*it)->x = x;
it.current()->y = y; (*it)->y = y;
XEvent event; XEvent event;
event.type = ConfigureNotify; event.type = ConfigureNotify;
event.xconfigure.display = display; event.xconfigure.display = display;
event.xconfigure.event = it.current()->window; event.xconfigure.event = (*it)->window;
event.xconfigure.window = it.current()->window; event.xconfigure.window = (*it)->window;
event.xconfigure.x = x; event.xconfigure.x = x;
event.xconfigure.y = y; event.xconfigure.y = y;
event.xconfigure.width = it.current()->width; event.xconfigure.width = (*it)->width;
event.xconfigure.height = it.current()->height; event.xconfigure.height = (*it)->height;
event.xconfigure.border_width = 0; event.xconfigure.border_width = 0;
event.xconfigure.above = frame.window; event.xconfigure.above = frame.window;
event.xconfigure.override_redirect = False; event.xconfigure.override_redirect = False;
XSendEvent(display, it.current()->window, False, StructureNotifyMask, XSendEvent(display, (*it)->window, False, StructureNotifyMask,
&event); &event);
y += it.current()->height + screen->getBevelWidth(); y += (*it)->height + screen->getBevelWidth();
}
} }
break; break;
@ -367,35 +376,39 @@ void Slit::reconfigure(void) {
x = screen->getBevelWidth(); x = screen->getBevelWidth();
y = 0; y = 0;
for (; it.current(); it++) { {
y = (frame.height - it.current()->height) / 2; SlitClients::iterator it = clientList.begin();
SlitClients::iterator it_end = clientList.end();
for (; it != it_end; ++it) {
y = (frame.height - (*it)->height) / 2;
XMoveResizeWindow(display, it.current()->window, x, y, XMoveResizeWindow(display, (*it)->window, x, y,
it.current()->width, it.current()->height); (*it)->width, (*it)->height);
XMapWindow(display, it.current()->window); XMapWindow(display, (*it)->window);
// for ICCCM compliance // for ICCCM compliance
it.current()->x = x; (*it)->x = x;
it.current()->y = y; (*it)->y = y;
XEvent event; XEvent event;
event.type = ConfigureNotify; event.type = ConfigureNotify;
event.xconfigure.display = display; event.xconfigure.display = display;
event.xconfigure.event = it.current()->window; event.xconfigure.event = (*it)->window;
event.xconfigure.window = it.current()->window; event.xconfigure.window = (*it)->window;
event.xconfigure.x = frame.x + x + screen->getBorderWidth(); event.xconfigure.x = frame.x + x + screen->getBorderWidth();
event.xconfigure.y = frame.y + y + screen->getBorderWidth(); event.xconfigure.y = frame.y + y + screen->getBorderWidth();
event.xconfigure.width = it.current()->width; event.xconfigure.width = (*it)->width;
event.xconfigure.height = it.current()->height; event.xconfigure.height = (*it)->height;
event.xconfigure.border_width = 0; event.xconfigure.border_width = 0;
event.xconfigure.above = frame.window; event.xconfigure.above = frame.window;
event.xconfigure.override_redirect = False; event.xconfigure.override_redirect = False;
XSendEvent(display, it.current()->window, False, StructureNotifyMask, XSendEvent(display, (*it)->window, False, StructureNotifyMask,
&event); &event);
x += it.current()->width + screen->getBevelWidth(); x += (*it)->width + screen->getBevelWidth();
}
} }
break; break;
@ -412,21 +425,21 @@ void Slit::reposition(void) {
frame.x = 0; frame.x = 0;
frame.y = 0; frame.y = 0;
if (screen->getSlitDirection() == VERTICAL) { if (screen->getSlitDirection() == VERTICAL) {
frame.x_hidden = screen->getBevelWidth() - screen->getBorderWidth() frame.x_hidden = screen->getBevelWidth() -
- frame.width; screen->getBorderWidth() - frame.width;
frame.y_hidden = 0; frame.y_hidden = 0;
} else { } else {
frame.x_hidden = 0; frame.x_hidden = 0;
frame.y_hidden = screen->getBevelWidth() - screen->getBorderWidth() frame.y_hidden = screen->getBevelWidth() -
- frame.height; screen->getBorderWidth() - frame.height;
} }
break; break;
case CENTERLEFT: case CENTERLEFT:
frame.x = 0; frame.x = 0;
frame.y = (screen->getHeight() - frame.height) / 2; frame.y = (screen->getHeight() - frame.height) / 2;
frame.x_hidden = screen->getBevelWidth() - screen->getBorderWidth() frame.x_hidden = screen->getBevelWidth() -
- frame.width; screen->getBorderWidth() - frame.width;
frame.y_hidden = frame.y; frame.y_hidden = frame.y;
break; break;
@ -439,8 +452,8 @@ void Slit::reposition(void) {
frame.y_hidden = frame.y; frame.y_hidden = frame.y;
} else { } else {
frame.x_hidden = 0; frame.x_hidden = 0;
frame.y_hidden = screen->getHeight() - screen->getBevelWidth() frame.y_hidden = screen->getHeight() -
- screen->getBorderWidth(); screen->getBevelWidth() - screen->getBorderWidth();
} }
break; break;
@ -448,29 +461,29 @@ void Slit::reposition(void) {
frame.x = (screen->getWidth() - frame.width) / 2; frame.x = (screen->getWidth() - frame.width) / 2;
frame.y = 0; frame.y = 0;
frame.x_hidden = frame.x; frame.x_hidden = frame.x;
frame.y_hidden = screen->getBevelWidth() - screen->getBorderWidth() frame.y_hidden = screen->getBevelWidth() -
- frame.height; screen->getBorderWidth() - frame.height;
break; break;
case BOTTOMCENTER: case BOTTOMCENTER:
frame.x = (screen->getWidth() - frame.width) / 2; frame.x = (screen->getWidth() - frame.width) / 2;
frame.y = screen->getHeight() - frame.height - screen->getBorderWidth2x(); frame.y = screen->getHeight() - frame.height - screen->getBorderWidth2x();
frame.x_hidden = frame.x; frame.x_hidden = frame.x;
frame.y_hidden = screen->getHeight() - screen->getBevelWidth() frame.y_hidden = screen->getHeight() -
- screen->getBorderWidth(); screen->getBevelWidth() - screen->getBorderWidth();
break; break;
case TOPRIGHT: case TOPRIGHT:
frame.x = screen->getWidth() - frame.width - screen->getBorderWidth2x(); frame.x = screen->getWidth() - frame.width - screen->getBorderWidth2x();
frame.y = 0; frame.y = 0;
if (screen->getSlitDirection() == VERTICAL) { if (screen->getSlitDirection() == VERTICAL) {
frame.x_hidden = screen->getWidth() - screen->getBevelWidth() frame.x_hidden = screen->getWidth() -
- screen->getBorderWidth(); screen->getBevelWidth() - screen->getBorderWidth();
frame.y_hidden = 0; frame.y_hidden = 0;
} else { } else {
frame.x_hidden = frame.x; frame.x_hidden = frame.x;
frame.y_hidden = screen->getBevelWidth() - screen->getBorderWidth() frame.y_hidden = screen->getBevelWidth() -
- frame.height; screen->getBorderWidth() - frame.height;
} }
break; break;
@ -478,8 +491,8 @@ void Slit::reposition(void) {
default: default:
frame.x = screen->getWidth() - frame.width - screen->getBorderWidth2x(); frame.x = screen->getWidth() - frame.width - screen->getBorderWidth2x();
frame.y = (screen->getHeight() - frame.height) / 2; frame.y = (screen->getHeight() - frame.height) / 2;
frame.x_hidden = screen->getWidth() - screen->getBevelWidth() frame.x_hidden = screen->getWidth() -
- screen->getBorderWidth(); screen->getBevelWidth() - screen->getBorderWidth();
frame.y_hidden = frame.y; frame.y_hidden = frame.y;
break; break;
@ -487,22 +500,22 @@ void Slit::reposition(void) {
frame.x = screen->getWidth() - frame.width - screen->getBorderWidth2x(); frame.x = screen->getWidth() - frame.width - screen->getBorderWidth2x();
frame.y = screen->getHeight() - frame.height - screen->getBorderWidth2x(); frame.y = screen->getHeight() - frame.height - screen->getBorderWidth2x();
if (screen->getSlitDirection() == VERTICAL) { if (screen->getSlitDirection() == VERTICAL) {
frame.x_hidden = screen->getWidth() - screen->getBevelWidth() frame.x_hidden = screen->getWidth() -
- screen->getBorderWidth(); screen->getBevelWidth() - screen->getBorderWidth();
frame.y_hidden = frame.y; frame.y_hidden = frame.y;
} else { } else {
frame.x_hidden = frame.x; frame.x_hidden = frame.x;
frame.y_hidden = screen->getHeight() - screen->getBevelWidth() frame.y_hidden = screen->getHeight() -
- screen->getBorderWidth(); screen->getBevelWidth() - screen->getBorderWidth();
} }
break; break;
} }
Toolbar *tbar = screen->getToolbar(); Toolbar *tbar = screen->getToolbar();
int sw = frame.width + screen->getBorderWidth2x(), int sw = frame.width + screen->getBorderWidth2x(),
sh = frame.height + screen->getBorderWidth2x(), sh = frame.height + screen->getBorderWidth2x(),
tw = tbar->getWidth() + screen->getBorderWidth(), tw = tbar->getWidth() + screen->getBorderWidth(),
th = tbar->getHeight() + screen->getBorderWidth(); th = tbar->getHeight() + screen->getBorderWidth();
if (tbar->getX() < frame.x + sw && tbar->getX() + tw > frame.x && if (tbar->getX() < frame.x + sw && tbar->getX() + tw > frame.x &&
tbar->getY() < frame.y + sh && tbar->getY() + th > frame.y) { tbar->getY() < frame.y + sh && tbar->getY() + th > frame.y) {
@ -511,28 +524,28 @@ void Slit::reposition(void) {
if (screen->getSlitDirection() == VERTICAL) if (screen->getSlitDirection() == VERTICAL)
frame.y_hidden += tbar->getExposedHeight(); frame.y_hidden += tbar->getExposedHeight();
else else
frame.y_hidden = frame.y; frame.y_hidden = frame.y;
} else { } else {
frame.y -= tbar->getExposedHeight(); frame.y -= tbar->getExposedHeight();
if (screen->getSlitDirection() == VERTICAL) if (screen->getSlitDirection() == VERTICAL)
frame.y_hidden -= tbar->getExposedHeight(); frame.y_hidden -= tbar->getExposedHeight();
else else
frame.y_hidden = frame.y; frame.y_hidden = frame.y;
} }
} }
if (hidden) if (hidden)
XMoveResizeWindow(display, frame.window, frame.x_hidden, XMoveResizeWindow(display, frame.window, frame.x_hidden,
frame.y_hidden, frame.width, frame.height); frame.y_hidden, frame.width, frame.height);
else else
XMoveResizeWindow(display, frame.window, frame.x, XMoveResizeWindow(display, frame.window, frame.x,
frame.y, frame.width, frame.height); frame.y, frame.width, frame.height);
} }
void Slit::shutdown(void) { void Slit::shutdown(void) {
while (clientList->count()) while (clientList.size() != 0)
removeClient(clientList->first()); removeClient(clientList.front());
} }
@ -597,7 +610,7 @@ void Slit::configureRequestEvent(XConfigureRequestEvent *e) {
fluxbox->grab(); fluxbox->grab();
if (fluxbox->validateWindow(e->window)) { if (fluxbox->validateWindow(e->window)) {
Bool reconf = False; bool reconf = false;
XWindowChanges xwc; XWindowChanges xwc;
xwc.x = e->x; xwc.x = e->x;
@ -610,15 +623,16 @@ void Slit::configureRequestEvent(XConfigureRequestEvent *e) {
XConfigureWindow(display, e->window, e->value_mask, &xwc); XConfigureWindow(display, e->window, e->value_mask, &xwc);
LinkedListIterator<SlitClient> it(clientList); SlitClients::iterator it = clientList.begin();
for (; it.current(); it++) SlitClients::iterator it_end = clientList.end();
if (it.current()->window == e->window) for (; it != it_end; ++it)
if (it.current()->width != ((unsigned) e->width) || if ((*it)->window == e->window)
it.current()->height != ((unsigned) e->height)) { if ((*it)->width != ((unsigned) e->width) ||
it.current()->width = (unsigned) e->width; (*it)->height != ((unsigned) e->height)) {
it.current()->height = (unsigned) e->height; (*it)->width = (unsigned) e->width;
(*it)->height = (unsigned) e->height;
reconf = True; reconf = true;
break; break;
} }

View file

@ -30,8 +30,8 @@ class Slit;
class Slitmenu; class Slitmenu;
#include "Basemenu.hh" #include "Basemenu.hh"
#include "LinkedList.hh"
#include <list>
class Slitmenu : public Basemenu { class Slitmenu : public Basemenu {
private: private:
@ -100,7 +100,9 @@ private:
BScreen *screen; BScreen *screen;
BTimer *timer; BTimer *timer;
LinkedList<SlitClient> *clientList; typedef std::list<SlitClient *> SlitClients;
SlitClients clientList;
Slitmenu *slitmenu; Slitmenu *slitmenu;
struct frame { struct frame {
@ -137,8 +139,8 @@ public:
inline const unsigned int &getHeight(void) const { return frame.height; } inline const unsigned int &getHeight(void) const { return frame.height; }
void addClient(Window); void addClient(Window);
void removeClient(SlitClient *, Bool = True); void removeClient(SlitClient *, bool = true);
void removeClient(Window, Bool = True); void removeClient(Window, bool = true);
void reconfigure(void); void reconfigure(void);
void reposition(void); void reposition(void);
void shutdown(void); void shutdown(void);