mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-23 11:02:21 +03:00
d2135af0d9
CServer to the primary screen when the configuration changes so it can make necessary adjustments (the win32 primary screen must tell the hook dll about the new jump zones). changed includes of some std c++ library files to go through our own include files. these wrap the include with stuff to keep vc++ quiet when compiling at warning level 4, which is what it does now. it also works around missing <istream> and <ostream> on g++2.96. added missing std:: where necessary. g++ doesn't really support namespaces so it lets references without the namespace slip through. added workaround or fix. not sure if istringstream::str(string) should reset eofbit. it does on g++ but does not on vc++. added clear() after str() so it works either way. added low-level keyboard hook to win32. if available (it's only available on NT SP3 and up) it allows us to catch and handle alt+tab, alt+esc, ctrl+esc, and windows key hot keys. i think that leaves only ctrl+alt+del and accessibility functions uncaught on those systems.
131 lines
3.3 KiB
C++
131 lines
3.3 KiB
C++
#ifndef CCONFIG_H
|
|
#define CCONFIG_H
|
|
|
|
#include "BasicTypes.h"
|
|
#include "CString.h"
|
|
#include "XBase.h"
|
|
#include <iosfwd>
|
|
#include "stdmap.h"
|
|
|
|
class CConfig;
|
|
|
|
namespace std {
|
|
struct iterator_traits<CConfig> {
|
|
typedef CString value_type;
|
|
typedef ptrdiff_t difference_type;
|
|
typedef bidirectional_iterator_tag iterator_category;
|
|
typedef CString* pointer;
|
|
typedef CString& reference;
|
|
};
|
|
};
|
|
|
|
class CConfig {
|
|
public:
|
|
enum EDirection { kLeft, kRight, kTop, kBottom,
|
|
kFirstDirection = kLeft, kLastDirection = kBottom };
|
|
enum EDirectionMask { kLeftMask = 1, kRightMask = 2,
|
|
kTopMask = 4, kBottomMask = 8 };
|
|
private:
|
|
class CCell {
|
|
public:
|
|
CString m_neighbor[kLastDirection - kFirstDirection + 1];
|
|
};
|
|
typedef std::map<CString, CCell> CCellMap;
|
|
|
|
public:
|
|
typedef CCellMap::const_iterator internal_const_iterator;
|
|
class const_iterator : std::iterator_traits<CConfig> {
|
|
public:
|
|
explicit const_iterator() : m_i() { }
|
|
explicit const_iterator(const internal_const_iterator& i) : m_i(i) { }
|
|
|
|
const_iterator& operator=(const const_iterator& i) {
|
|
m_i = i.m_i;
|
|
return *this;
|
|
}
|
|
CString operator*() { return m_i->first; }
|
|
const CString* operator->() { return &(m_i->first); }
|
|
const_iterator& operator++() { ++m_i; return *this; }
|
|
const_iterator operator++(int) { return const_iterator(m_i++); }
|
|
const_iterator& operator--() { --m_i; return *this; }
|
|
const_iterator operator--(int) { return const_iterator(m_i--); }
|
|
bool operator==(const const_iterator& i) const {
|
|
return (m_i == i.m_i);
|
|
}
|
|
bool operator!=(const const_iterator& i) const {
|
|
return (m_i != i.m_i);
|
|
}
|
|
|
|
private:
|
|
internal_const_iterator m_i;
|
|
};
|
|
|
|
CConfig();
|
|
virtual ~CConfig();
|
|
|
|
// manipulators
|
|
|
|
// note that case is preserved in screen names but has no effect
|
|
// FIXME -- make that true
|
|
|
|
// add/remove screens
|
|
void addScreen(const CString& name);
|
|
void removeScreen(const CString& name);
|
|
void removeAllScreens();
|
|
|
|
// connect edges
|
|
void connect(const CString& srcName,
|
|
EDirection srcSide,
|
|
const CString& dstName);
|
|
void disconnect(const CString& srcName,
|
|
EDirection srcSide);
|
|
|
|
// accessors
|
|
|
|
// returns true iff the given name is a valid screen name.
|
|
bool isValidScreenName(const CString&) const;
|
|
|
|
// iterators over screen names
|
|
const_iterator begin() const;
|
|
const_iterator end() const;
|
|
|
|
// returns true iff name names a screen
|
|
bool isScreen(const CString& name) const;
|
|
|
|
// get the neighbor in the given direction. returns the empty string
|
|
// if there is no neighbor in that direction.
|
|
CString getNeighbor(const CString&, EDirection) const;
|
|
|
|
// read/write a configuration. operator>> will throw XConfigRead
|
|
// on error.
|
|
friend std::istream& operator>>(std::istream&, CConfig&);
|
|
friend std::ostream& operator<<(std::ostream&, const CConfig&);
|
|
|
|
// get the name of a direction (for debugging)
|
|
static const char* dirName(EDirection);
|
|
|
|
private:
|
|
static bool readLine(std::istream&, CString&);
|
|
void readSection(std::istream&);
|
|
void readSectionScreens(std::istream&);
|
|
void readSectionLinks(std::istream&);
|
|
|
|
private:
|
|
CCellMap m_map;
|
|
};
|
|
|
|
class XConfigRead : public XBase {
|
|
public:
|
|
XConfigRead(const CString&);
|
|
~XConfigRead();
|
|
|
|
protected:
|
|
// XBase overrides
|
|
virtual CString getWhat() const throw();
|
|
|
|
private:
|
|
CString m_error;
|
|
};
|
|
|
|
#endif
|