fix a few things with new signal code
This commit is contained in:
parent
ab8b21d18c
commit
4c11204716
2 changed files with 25 additions and 5 deletions
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "Slot.hh"
|
#include "Slot.hh"
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace FbTk {
|
namespace FbTk {
|
||||||
|
@ -45,6 +46,8 @@ public:
|
||||||
typedef Iterator SlotID;
|
typedef Iterator SlotID;
|
||||||
typedef SlotList::const_iterator ConstIterator;
|
typedef SlotList::const_iterator ConstIterator;
|
||||||
|
|
||||||
|
virtual ~SignalHolder() { }
|
||||||
|
|
||||||
/// Remove a specific slot \c id from this signal
|
/// Remove a specific slot \c id from this signal
|
||||||
void disconnect(SlotID slotIt) {
|
void disconnect(SlotID slotIt) {
|
||||||
m_slots.erase( slotIt );
|
m_slots.erase( slotIt );
|
||||||
|
@ -78,6 +81,8 @@ class Signal0: public SignalHolder {
|
||||||
public:
|
public:
|
||||||
typedef Slot0<ReturnType> SlotType;
|
typedef Slot0<ReturnType> SlotType;
|
||||||
|
|
||||||
|
virtual ~Signal0() { }
|
||||||
|
|
||||||
void emit() {
|
void emit() {
|
||||||
for ( Iterator it = begin(); it != end(); ++it ) {
|
for ( Iterator it = begin(); it != end(); ++it ) {
|
||||||
static_cast<SlotType&>(*it)();
|
static_cast<SlotType&>(*it)();
|
||||||
|
@ -96,6 +101,8 @@ class Signal1: public SignalHolder {
|
||||||
public:
|
public:
|
||||||
typedef Slot1<ReturnType, Arg1> SlotType;
|
typedef Slot1<ReturnType, Arg1> SlotType;
|
||||||
|
|
||||||
|
virtual ~Signal1() { }
|
||||||
|
|
||||||
void emit(Arg1 arg) {
|
void emit(Arg1 arg) {
|
||||||
for ( Iterator it = begin(); it != end(); ++it ) {
|
for ( Iterator it = begin(); it != end(); ++it ) {
|
||||||
static_cast<SlotType&>(*it)(arg);
|
static_cast<SlotType&>(*it)(arg);
|
||||||
|
@ -114,6 +121,8 @@ class Signal2: public SignalHolder {
|
||||||
public:
|
public:
|
||||||
typedef Slot2<ReturnType, Arg1, Arg2> SlotType;
|
typedef Slot2<ReturnType, Arg1, Arg2> SlotType;
|
||||||
|
|
||||||
|
virtual ~Signal2() { }
|
||||||
|
|
||||||
void emit(Arg1 arg1, Arg2 arg2) {
|
void emit(Arg1 arg1, Arg2 arg2) {
|
||||||
for ( Iterator it = begin(); it != end(); ++it ) {
|
for ( Iterator it = begin(); it != end(); ++it ) {
|
||||||
static_cast<SlotType&>(*it)(arg1, arg2);
|
static_cast<SlotType&>(*it)(arg1, arg2);
|
||||||
|
@ -131,6 +140,8 @@ class Signal3: public SignalHolder {
|
||||||
public:
|
public:
|
||||||
typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
|
typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
|
||||||
|
|
||||||
|
virtual ~Signal3() { }
|
||||||
|
|
||||||
void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
||||||
for ( Iterator it = begin(); it != end(); ++it ) {
|
for ( Iterator it = begin(); it != end(); ++it ) {
|
||||||
static_cast<SlotType&>(*it)(arg1, arg2, arg3);
|
static_cast<SlotType&>(*it)(arg1, arg2, arg3);
|
||||||
|
@ -180,16 +191,15 @@ public:
|
||||||
class SignalTracker {
|
class SignalTracker {
|
||||||
public:
|
public:
|
||||||
/// Internal type, do not use.
|
/// Internal type, do not use.
|
||||||
typedef std::list< std::pair< SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID > > Connections;
|
typedef std::map<SigImpl::SignalHolder*, SigImpl::SignalHolder::SlotID> Connections;
|
||||||
typedef Connections::iterator TrackID; ///< \c ID type for join/leave.
|
typedef Connections::iterator TrackID; ///< \c ID type for join/leave.
|
||||||
|
|
||||||
~SignalTracker() {
|
virtual ~SignalTracker() {
|
||||||
// disconnect all connections
|
// disconnect all connections
|
||||||
for ( Connections::iterator conIt = m_connections.begin();
|
for ( Connections::iterator conIt = m_connections.begin();
|
||||||
conIt != m_connections.end(); ) {
|
conIt != m_connections.end(); ++conIt)
|
||||||
conIt->first->disconnect( conIt->second );
|
conIt->first->disconnect( conIt->second );
|
||||||
conIt = m_connections.erase( conIt );
|
m_connections.clear();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts tracking a signal.
|
/// Starts tracking a signal.
|
||||||
|
@ -207,6 +217,13 @@ public:
|
||||||
m_connections.erase(id);
|
m_connections.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Leave tracking for a signal
|
||||||
|
/// @param sig the signal to leave
|
||||||
|
template <typename Signal>
|
||||||
|
void leave(Signal &sig) {
|
||||||
|
m_connections.erase(&sig);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// holds all connections to different signals and slots.
|
/// holds all connections to different signals and slots.
|
||||||
Connections m_connections;
|
Connections m_connections;
|
||||||
|
|
|
@ -429,6 +429,9 @@ Fluxbox::~Fluxbox() {
|
||||||
|
|
||||||
// destroy screens (after others, as they may do screen things)
|
// destroy screens (after others, as they may do screen things)
|
||||||
while (!m_screen_list.empty()) {
|
while (!m_screen_list.empty()) {
|
||||||
|
// this needs to be done before the signal is destroyed
|
||||||
|
leave( m_screen_list.back()->workspaceCountSig() );
|
||||||
|
|
||||||
delete m_screen_list.back();
|
delete m_screen_list.back();
|
||||||
m_screen_list.pop_back();
|
m_screen_list.pop_back();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue