Skip to content

Commit

Permalink
create the slit and toolbar menus in BScreen and use them in
Browse files Browse the repository at this point in the history
Configmenu, Slit and Toolbar

this saves memory and solves the crash described in bug 896889 where
disabling the toolbar from the toolbarmenu in the toolbar would crash
blackbox.

oddly enough, i couldn't reproduce this, but the bug is obvious when
looking at what the Toolbar destructor does - it deletes the
toolbarmenu, which means the hideAll() from
bt::Menu::buttonReleaseEvent() or ::keyPressEvent() would access freed
memory... hence the crash
  • Loading branch information
bradleyhughes committed Mar 8, 2004
1 parent ee578e7 commit 05294b5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 34 deletions.
8 changes: 2 additions & 6 deletions src/Configmenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ Configmenu::Configmenu(bt::Application &app, unsigned int screen,
new ConfigPlacementmenu(app, screen, bscreen);
ConfigDithermenu *dithermenu =
new ConfigDithermenu(app, screen, bscreen);
Toolbarmenu *toolbarmenu =
new Toolbarmenu(app, screen, _bscreen);
Slitmenu *slitmenu =
new Slitmenu(app, screen, _bscreen);

insertItem("Focus Model", focusmenu, FocusModel);
insertItem("Window Placement", placementmenu, WindowPlacement);
Expand All @@ -121,8 +117,8 @@ Configmenu::Configmenu(bt::Application &app, unsigned int screen,
insertItem("Focus Last Window on Workspace", FocusLastWindowOnWorkspace);
insertItem("Disable Bindings with Scroll Lock", DisableBindings);
insertSeparator();
insertItem("Toolbar Options", toolbarmenu, ToolbarOptions);
insertItem("Slit Options", slitmenu, SlitOptions);
insertItem("Toolbar Options", bscreen->toolbarmenu(), ToolbarOptions);
insertItem("Slit Options", bscreen->slitmenu(), SlitOptions);
}


Expand Down
11 changes: 9 additions & 2 deletions src/Screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include "Iconmenu.hh"
#include "Rootmenu.hh"
#include "Slit.hh"
#include "Slitmenu.hh"
#include "Toolbar.hh"
#include "Toolbarmenu.hh"
#include "Window.hh"
#include "WindowGroup.hh"
#include "Windowmenu.hh"
Expand Down Expand Up @@ -118,13 +120,18 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) :

updateGeomWindow();

configmenu =
new Configmenu(*blackbox, screen_info.screenNumber(), this);
_iconmenu =
new Iconmenu(*blackbox, screen_info.screenNumber(), this);
_slitmenu =
new Slitmenu(*blackbox, screen_info.screenNumber(), this);
_toolbarmenu =
new Toolbarmenu(*blackbox, screen_info.screenNumber(), this);
workspacemenu =
new Workspacemenu(*blackbox, screen_info.screenNumber(), this);

configmenu =
new Configmenu(*blackbox, screen_info.screenNumber(), this);

if (_resource.numberOfWorkspaces() == 0) // there is always 1 workspace
_resource.saveWorkspaces(1);

Expand Down
8 changes: 8 additions & 0 deletions src/Screen.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class Configmenu;
class Iconmenu;
class Rootmenu;
class Slit;
class Slitmenu;
class Toolbar;
class Toolbarmenu;
class Windowmenu;
class Workspace;
class Workspacemenu;
Expand All @@ -65,6 +67,8 @@ private:
Configmenu *configmenu;
Iconmenu *_iconmenu;
Rootmenu *rootmenu;
Slitmenu *_slitmenu;
Toolbarmenu *_toolbarmenu;
Windowmenu *_windowmenu;
Workspacemenu *workspacemenu;

Expand Down Expand Up @@ -136,6 +140,10 @@ public:

inline Iconmenu *iconmenu(void) const
{ return _iconmenu; }
inline Slitmenu *slitmenu(void) const
{ return _slitmenu; }
inline Toolbarmenu *toolbarmenu(void) const
{ return _toolbarmenu; }

Windowmenu *windowmenu(BlackboxWindow *win);

Expand Down
16 changes: 7 additions & 9 deletions src/Slit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ Slit::Slit(BScreen *scr) {
timer = new bt::Timer(blackbox, this);
timer->setTimeout(blackbox->resource().autoRaiseDelay());

slitmenu = new Slitmenu(*blackbox, screen->screenNumber(), screen);

XSetWindowAttributes attrib;
unsigned long create_mask = CWColormap | CWEventMask;
attrib.colormap = screen->screenInfo().colormap();
Expand Down Expand Up @@ -86,7 +84,6 @@ Slit::~Slit(void) {
XDestroyWindow(display, frame.window);

delete timer;
delete slitmenu;
}


Expand Down Expand Up @@ -316,8 +313,6 @@ void Slit::reconfigure(void) {
}
break;
}

slitmenu->reconfigure();
}


Expand Down Expand Up @@ -478,7 +473,8 @@ void Slit::buttonPressEvent(const XButtonEvent * const event) {
screen->lowerWindow(this);
break;
case Button3:
slitmenu->popup(event->x_root, event->y_root, screen->availableArea());
screen->slitmenu()->popup(event->x_root, event->y_root,
screen->availableArea());
break;
}
}
Expand All @@ -501,9 +497,11 @@ void Slit::leaveNotifyEvent(const XCrossingEvent * const /*unused*/) {
return;

if (hidden) {
if (timer->isTiming()) timer->stop();
} else if (! slitmenu->isVisible()) {
if (! timer->isTiming()) timer->start();
if (timer->isTiming())
timer->stop();
} else if (! screen->slitmenu()->isVisible()) {
if (! timer->isTiming())
timer->start();
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/Slit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#include "BlackboxResource.hh"
#include "Screen.hh"

// forward declarations
class Slitmenu;

class Slit : public StackEntity, public bt::TimeoutHandler,
public bt::EventHandler, public bt::NoCopy
{
Expand All @@ -56,7 +53,6 @@ private:
bt::Netwm::Strut strut;

SlitClientList clientList;
Slitmenu *slitmenu;

struct SlitFrame {
Pixmap pixmap;
Expand All @@ -68,8 +64,6 @@ private:

void updateStrut(void);

friend class Slitmenu;

public:
Slit(BScreen *scr);
virtual ~Slit(void);
Expand Down
9 changes: 2 additions & 7 deletions src/Toolbar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ Toolbar::Toolbar(BScreen *scrn) {
editing = False;
new_name_pos = 0;

toolbarmenu = new Toolbarmenu(*blackbox, _screen->screenNumber(), _screen);

display = blackbox->XDisplay();
XSetWindowAttributes attrib;
unsigned long create_mask = CWColormap | CWOverrideRedirect | CWEventMask;
Expand Down Expand Up @@ -178,7 +176,6 @@ Toolbar::~Toolbar(void) {

delete hide_timer;
delete clock_timer;
delete toolbarmenu;
}


Expand Down Expand Up @@ -384,8 +381,6 @@ void Toolbar::reconfigure(void) {
style->button_width, style->button_width, True);
XClearArea(display, frame.nwbutton, 0, 0,
style->button_width, style->button_width, True);

toolbarmenu->reconfigure();
}


Expand Down Expand Up @@ -637,8 +632,8 @@ void Toolbar::buttonPressEvent(const XButtonEvent * const event) {
windowmenu->popup(event->x_root, event->y_root,
_screen->availableArea());
} else {
toolbarmenu->popup(event->x_root, event->y_root,
_screen->availableArea());
_screen->toolbarmenu()->popup(event->x_root, event->y_root,
_screen->availableArea());
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/Toolbar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@

#include "Screen.hh"

// forward declarations
class Toolbarmenu;

class Toolbar : public StackEntity, public bt::TimeoutHandler,
public bt::EventHandler, public bt::NoCopy
{
Expand All @@ -54,7 +51,6 @@ private:
Blackbox *blackbox;
BScreen *_screen;
bt::Timer *clock_timer, *hide_timer;
Toolbarmenu *toolbarmenu;
bt::Netwm::Strut strut;

std::string new_workspace_name;
Expand Down

0 comments on commit 05294b5

Please sign in to comment.