2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2002-05-31 14:34:16 +00:00
|
|
|
#include "CConfig.h"
|
2007-06-17 11:19:18 +00:00
|
|
|
#include "CServer.h"
|
|
|
|
#include "CKeyMap.h"
|
2003-02-22 15:03:31 +00:00
|
|
|
#include "KeyTypes.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "XSocket.h"
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdistream.h"
|
|
|
|
#include "stdostream.h"
|
2003-02-22 16:20:23 +00:00
|
|
|
#include <stdlib.h>
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
//
|
2002-05-31 14:43:23 +00:00
|
|
|
// CConfig
|
2001-10-06 14:13:28 +00:00
|
|
|
//
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::CConfig() : m_hasLockToScreenAction(false)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-05-31 14:43:23 +00:00
|
|
|
CConfig::~CConfig()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::addScreen(const CString& name)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-06-08 23:24:40 +00:00
|
|
|
// alias name must not exist
|
|
|
|
if (m_nameToCanonicalName.find(name) != m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
// add cell
|
2001-10-06 14:13:28 +00:00
|
|
|
m_map.insert(std::make_pair(name, CCell()));
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
// add name
|
|
|
|
m_nameToCanonicalName.insert(std::make_pair(name, name));
|
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
bool
|
|
|
|
CConfig::renameScreen(const CString& oldName,
|
|
|
|
const CString& newName)
|
|
|
|
{
|
|
|
|
// get canonical name and find cell
|
|
|
|
CString oldCanonical = getCanonicalName(oldName);
|
|
|
|
CCellMap::iterator index = m_map.find(oldCanonical);
|
|
|
|
if (index == m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accept if names are equal but replace with new name to maintain
|
|
|
|
// case. otherwise, the new name must not exist.
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(oldName, newName) &&
|
|
|
|
m_nameToCanonicalName.find(newName) != m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update cell
|
|
|
|
CCell tmpCell = index->second;
|
|
|
|
m_map.erase(index);
|
|
|
|
m_map.insert(std::make_pair(newName, tmpCell));
|
|
|
|
|
|
|
|
// update name
|
|
|
|
m_nameToCanonicalName.erase(oldCanonical);
|
|
|
|
m_nameToCanonicalName.insert(std::make_pair(newName, newName));
|
|
|
|
|
|
|
|
// update connections
|
2007-06-17 11:19:18 +00:00
|
|
|
CName oldNameObj(this, oldName);
|
2002-08-11 11:49:36 +00:00
|
|
|
for (index = m_map.begin(); index != m_map.end(); ++index) {
|
2007-06-17 11:19:18 +00:00
|
|
|
index->second.rename(oldNameObj, newName);
|
2002-08-11 11:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update alias targets
|
|
|
|
if (CStringUtil::CaselessCmp::equal(oldName, oldCanonical)) {
|
|
|
|
for (CNameMap::iterator index = m_nameToCanonicalName.begin();
|
|
|
|
index != m_nameToCanonicalName.end(); ++index) {
|
|
|
|
if (CStringUtil::CaselessCmp::equal(
|
|
|
|
index->second, oldCanonical)) {
|
|
|
|
index->second = newName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::removeScreen(const CString& name)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-06-08 23:24:40 +00:00
|
|
|
// get canonical name and find cell
|
|
|
|
CString canonical = getCanonicalName(name);
|
|
|
|
CCellMap::iterator index = m_map.find(canonical);
|
2001-10-06 14:13:28 +00:00
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove from map
|
|
|
|
m_map.erase(index);
|
|
|
|
|
|
|
|
// disconnect
|
2007-06-17 11:19:18 +00:00
|
|
|
CName nameObj(this, name);
|
2001-10-06 14:13:28 +00:00
|
|
|
for (index = m_map.begin(); index != m_map.end(); ++index) {
|
2007-06-17 11:19:18 +00:00
|
|
|
index->second.remove(nameObj);
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
// remove aliases (and canonical name)
|
|
|
|
for (CNameMap::iterator index = m_nameToCanonicalName.begin();
|
|
|
|
index != m_nameToCanonicalName.end(); ) {
|
|
|
|
if (index->second == canonical) {
|
|
|
|
m_nameToCanonicalName.erase(index++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CConfig::removeAllScreens()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
m_map.clear();
|
2002-06-08 23:24:40 +00:00
|
|
|
m_nameToCanonicalName.clear();
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::addAlias(const CString& canonical, const CString& alias)
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
// alias name must not exist
|
|
|
|
if (m_nameToCanonicalName.find(alias) != m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// canonical name must be known
|
2002-08-11 11:49:36 +00:00
|
|
|
if (m_map.find(canonical) == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert alias
|
|
|
|
m_nameToCanonicalName.insert(std::make_pair(alias, canonical));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::removeAlias(const CString& alias)
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
// must not be a canonical name
|
|
|
|
if (m_map.find(alias) != m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find alias
|
|
|
|
CNameMap::iterator index = m_nameToCanonicalName.find(alias);
|
|
|
|
if (index == m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove alias
|
|
|
|
m_nameToCanonicalName.erase(index);
|
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
bool
|
|
|
|
CConfig::removeAliases(const CString& canonical)
|
|
|
|
{
|
|
|
|
// must be a canonical name
|
|
|
|
if (m_map.find(canonical) == m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find and removing matching aliases
|
|
|
|
for (CNameMap::iterator index = m_nameToCanonicalName.begin();
|
|
|
|
index != m_nameToCanonicalName.end(); ) {
|
|
|
|
if (index->second == canonical && index->first != canonical) {
|
|
|
|
m_nameToCanonicalName.erase(index++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CConfig::removeAllAliases()
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
// remove all names
|
|
|
|
m_nameToCanonicalName.clear();
|
|
|
|
|
|
|
|
// put the canonical names back in
|
|
|
|
for (CCellMap::iterator index = m_map.begin();
|
|
|
|
index != m_map.end(); ++index) {
|
|
|
|
m_nameToCanonicalName.insert(
|
|
|
|
std::make_pair(index->first, index->first));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::connect(const CString& srcName,
|
2007-06-17 11:19:18 +00:00
|
|
|
EDirection srcSide,
|
|
|
|
float srcStart, float srcEnd,
|
|
|
|
const CString& dstName,
|
|
|
|
float dstStart, float dstEnd)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2003-02-23 19:29:08 +00:00
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// find source cell
|
2002-06-08 23:24:40 +00:00
|
|
|
CCellMap::iterator index = m_map.find(getCanonicalName(srcName));
|
2001-10-06 14:13:28 +00:00
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return false;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// add link
|
|
|
|
CCellEdge srcEdge(srcSide, CInterval(srcStart, srcEnd));
|
|
|
|
CCellEdge dstEdge(dstName, srcSide, CInterval(dstStart, dstEnd));
|
|
|
|
return index->second.add(srcEdge, dstEdge);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::disconnect(const CString& srcName, EDirection srcSide)
|
|
|
|
{
|
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
|
|
|
// find source cell
|
|
|
|
CCellMap::iterator index = m_map.find(srcName);
|
|
|
|
if (index == m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// disconnect side
|
|
|
|
index->second.remove(srcSide);
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::disconnect(const CString& srcName, EDirection srcSide, float position)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2003-02-23 19:29:08 +00:00
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// find source cell
|
|
|
|
CCellMap::iterator index = m_map.find(srcName);
|
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return false;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// disconnect side
|
2007-06-17 11:19:18 +00:00
|
|
|
index->second.remove(srcSide, position);
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::setSynergyAddress(const CNetworkAddress& addr)
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
m_synergyAddress = addr;
|
|
|
|
}
|
|
|
|
|
2002-12-23 13:55:21 +00:00
|
|
|
bool
|
2003-01-25 13:34:51 +00:00
|
|
|
CConfig::addOption(const CString& name, OptionID option, OptionValue value)
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options == NULL) {
|
2002-12-23 13:55:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add option
|
2003-02-22 16:41:03 +00:00
|
|
|
options->insert(std::make_pair(option, value));
|
2002-12-23 13:55:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2003-01-25 13:34:51 +00:00
|
|
|
CConfig::removeOption(const CString& name, OptionID option)
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options == NULL) {
|
2002-12-23 13:55:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove option
|
2003-02-22 16:41:03 +00:00
|
|
|
options->erase(option);
|
2002-12-23 13:55:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-01-25 13:34:51 +00:00
|
|
|
bool
|
|
|
|
CConfig::removeOptions(const CString& name)
|
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options == NULL) {
|
2003-01-25 13:34:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:41:03 +00:00
|
|
|
// remove options
|
|
|
|
options->clear();
|
2003-01-25 13:34:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::isValidScreenName(const CString& name) const
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
// name is valid if matches validname
|
2003-04-16 20:05:00 +00:00
|
|
|
// name ::= [_A-Za-z0-9] | [_A-Za-z0-9][-_A-Za-z0-9]*[_A-Za-z0-9]
|
2002-05-31 17:32:26 +00:00
|
|
|
// domain ::= . name
|
|
|
|
// validname ::= name domain*
|
2004-09-28 22:25:35 +00:00
|
|
|
// we also accept names ending in . because many OS X users have
|
|
|
|
// so misconfigured their systems.
|
|
|
|
|
|
|
|
// empty name is invalid
|
|
|
|
if (name.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
// check each dot separated part
|
|
|
|
CString::size_type b = 0;
|
|
|
|
for (;;) {
|
2004-09-28 22:25:35 +00:00
|
|
|
// accept trailing .
|
|
|
|
if (b == name.size()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
// find end of part
|
|
|
|
CString::size_type e = name.find('.', b);
|
|
|
|
if (e == CString::npos) {
|
|
|
|
e = name.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// part may not be empty
|
|
|
|
if (e - b < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check first and last characters
|
2003-04-16 20:05:00 +00:00
|
|
|
if (!(isalnum(name[b]) || name[b] == '_') ||
|
|
|
|
!(isalnum(name[e - 1]) || name[e - 1] == '_')) {
|
2002-05-31 17:32:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check interior characters
|
|
|
|
for (CString::size_type i = b; i < e; ++i) {
|
2003-04-16 20:05:00 +00:00
|
|
|
if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-') {
|
2002-05-31 17:32:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// next part
|
|
|
|
if (e == name.size()) {
|
|
|
|
// no more parts
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
b = e + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CConfig::const_iterator
|
|
|
|
CConfig::begin() const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
return const_iterator(m_map.begin());
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CConfig::const_iterator
|
|
|
|
CConfig::end() const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
return const_iterator(m_map.end());
|
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
CConfig::all_const_iterator
|
|
|
|
CConfig::beginAll() const
|
|
|
|
{
|
|
|
|
return m_nameToCanonicalName.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::all_const_iterator
|
|
|
|
CConfig::endAll() const
|
|
|
|
{
|
|
|
|
return m_nameToCanonicalName.end();
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::isScreen(const CString& name) const
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2002-06-08 23:24:40 +00:00
|
|
|
return (m_nameToCanonicalName.count(name) > 0);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::isCanonicalName(const CString& name) const
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
return (!name.empty() &&
|
|
|
|
CStringUtil::CaselessCmp::equal(getCanonicalName(name), name));
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::getCanonicalName(const CString& name) const
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
CNameMap::const_iterator index = m_nameToCanonicalName.find(name);
|
|
|
|
if (index == m_nameToCanonicalName.end()) {
|
|
|
|
return CString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return index->second;
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::getNeighbor(const CString& srcName, EDirection srcSide,
|
|
|
|
float position, float* positionOut) const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2003-02-23 19:29:08 +00:00
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// find source cell
|
2002-06-08 23:24:40 +00:00
|
|
|
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
2001-10-06 14:13:28 +00:00
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return CString();
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// find edge
|
|
|
|
const CCellEdge* srcEdge, *dstEdge;
|
|
|
|
if (!index->second.getLink(srcSide, position, srcEdge, dstEdge)) {
|
|
|
|
// no neighbor
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// compute position on neighbor
|
|
|
|
if (positionOut != NULL) {
|
|
|
|
*positionOut =
|
|
|
|
dstEdge->inverseTransform(srcEdge->transform(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
// return neighbor's name
|
|
|
|
return getCanonicalName(dstEdge->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::hasNeighbor(const CString& srcName, EDirection srcSide) const
|
|
|
|
{
|
|
|
|
return hasNeighbor(srcName, srcSide, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::hasNeighbor(const CString& srcName, EDirection srcSide,
|
|
|
|
float start, float end) const
|
|
|
|
{
|
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
|
|
|
// find source cell
|
|
|
|
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
|
|
|
if (index == m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index->second.overlaps(CCellEdge(srcSide, CInterval(start, end)));
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::link_const_iterator
|
|
|
|
CConfig::beginNeighbor(const CString& srcName) const
|
|
|
|
{
|
|
|
|
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
|
|
|
assert(index != m_map.end());
|
|
|
|
return index->second.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::link_const_iterator
|
|
|
|
CConfig::endNeighbor(const CString& srcName) const
|
|
|
|
{
|
|
|
|
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
|
|
|
assert(index != m_map.end());
|
|
|
|
return index->second.end();
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
2001-10-14 14:37:41 +00:00
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
const CNetworkAddress&
|
|
|
|
CConfig::getSynergyAddress() const
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
return m_synergyAddress;
|
|
|
|
}
|
|
|
|
|
2002-12-23 13:55:21 +00:00
|
|
|
const CConfig::CScreenOptions*
|
|
|
|
CConfig::getOptions(const CString& name) const
|
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
const CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::const_iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return options
|
2003-02-22 16:41:03 +00:00
|
|
|
return options;
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
bool
|
|
|
|
CConfig::hasLockToScreenAction() const
|
|
|
|
{
|
|
|
|
return m_hasLockToScreenAction;
|
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
bool
|
|
|
|
CConfig::operator==(const CConfig& x) const
|
|
|
|
{
|
|
|
|
if (m_synergyAddress != x.m_synergyAddress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_map.size() != x.m_map.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_nameToCanonicalName.size() != x.m_nameToCanonicalName.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:41:03 +00:00
|
|
|
// compare global options
|
|
|
|
if (m_globalOptions != x.m_globalOptions) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
for (CCellMap::const_iterator index1 = m_map.begin(),
|
|
|
|
index2 = x.m_map.begin();
|
|
|
|
index1 != m_map.end(); ++index1, ++index2) {
|
2003-01-25 13:34:51 +00:00
|
|
|
// compare names
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(index1->first, index2->first)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// compare cells
|
|
|
|
if (index1->second != index2->second) {
|
2003-01-25 13:34:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-08-11 11:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (CNameMap::const_iterator index1 = m_nameToCanonicalName.begin(),
|
|
|
|
index2 = x.m_nameToCanonicalName.begin();
|
|
|
|
index1 != m_nameToCanonicalName.end();
|
|
|
|
++index1, ++index2) {
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(index1->first, index2->first) ||
|
|
|
|
!CStringUtil::CaselessCmp::equal(index1->second, index2->second)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// compare input filters
|
|
|
|
if (m_inputFilter != x.m_inputFilter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::operator!=(const CConfig& x) const
|
|
|
|
{
|
|
|
|
return !operator==(x);
|
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
void
|
|
|
|
CConfig::read(CConfigReadContext& context)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig tmp;
|
|
|
|
while (context) {
|
|
|
|
tmp.readSection(context);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
*this = tmp;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
const char*
|
|
|
|
CConfig::dirName(EDirection dir)
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
static const char* s_name[] = { "left", "right", "up", "down" };
|
2002-12-23 13:55:21 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
assert(dir >= kFirstDirection && dir <= kLastDirection);
|
2003-02-22 16:20:23 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
return s_name[dir - kFirstDirection];
|
2003-02-22 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
CInputFilter*
|
|
|
|
CConfig::getInputFilter()
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
return &m_inputFilter;
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 16:20:23 +00:00
|
|
|
CString
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::formatInterval(const CInterval& x)
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
if (x.first == 0.0f && x.second == 1.0f) {
|
|
|
|
return "";
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
return CStringUtil::print("(%d,%d)", (int)(x.first * 100.0f + 0.5f),
|
|
|
|
(int)(x.second * 100.0f + 0.5f));
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::readSection(CConfigReadContext& s)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
static const char s_section[] = "section:";
|
2003-02-22 16:20:23 +00:00
|
|
|
static const char s_options[] = "options";
|
2002-05-31 17:32:26 +00:00
|
|
|
static const char s_screens[] = "screens";
|
|
|
|
static const char s_links[] = "links";
|
2002-06-08 23:24:40 +00:00
|
|
|
static const char s_aliases[] = "aliases";
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
CString line;
|
2007-06-17 11:19:18 +00:00
|
|
|
if (!s.readLine(line)) {
|
2002-05-31 17:32:26 +00:00
|
|
|
// no more sections
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// should be a section header
|
|
|
|
if (line.find(s_section) != 0) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "found data outside section");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get section name
|
|
|
|
CString::size_type i = line.find_first_not_of(" \t", sizeof(s_section) - 1);
|
|
|
|
if (i == CString::npos) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "section name is missing");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
CString name = line.substr(i);
|
|
|
|
i = name.find_first_of(" \t");
|
|
|
|
if (i != CString::npos) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unexpected data after section name");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// read section
|
2003-02-22 16:20:23 +00:00
|
|
|
if (name == s_options) {
|
|
|
|
readSectionOptions(s);
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
|
|
|
else if (name == s_screens) {
|
2002-05-31 17:32:26 +00:00
|
|
|
readSectionScreens(s);
|
|
|
|
}
|
|
|
|
else if (name == s_links) {
|
|
|
|
readSectionLinks(s);
|
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
else if (name == s_aliases) {
|
|
|
|
readSectionAliases(s);
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
else {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unknown section name \"%{1}\"", name);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::readSectionOptions(CConfigReadContext& s)
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
CString line;
|
2007-06-17 11:19:18 +00:00
|
|
|
while (s.readLine(line)) {
|
2002-06-09 16:53:25 +00:00
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// parse argument: `nameAndArgs = [values][;[values]]'
|
|
|
|
// nameAndArgs := <name>[(arg[,...])]
|
|
|
|
// values := valueAndArgs[,valueAndArgs]...
|
|
|
|
// valueAndArgs := <value>[(arg[,...])]
|
|
|
|
CString::size_type i = 0;
|
|
|
|
CString name, value;
|
|
|
|
CConfigReadContext::ArgList nameArgs, valueArgs;
|
|
|
|
s.parseNameWithArgs("name", line, "=", i, name, nameArgs);
|
|
|
|
++i;
|
|
|
|
s.parseNameWithArgs("value", line, ",;\n", i, value, valueArgs);
|
|
|
|
|
|
|
|
bool handled = true;
|
2002-06-09 16:53:25 +00:00
|
|
|
if (name == "address") {
|
|
|
|
try {
|
|
|
|
m_synergyAddress = CNetworkAddress(value, kDefaultPort);
|
2004-12-30 13:28:51 +00:00
|
|
|
m_synergyAddress.resolve();
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
2004-02-15 17:32:11 +00:00
|
|
|
catch (XSocketAddress& e) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s,
|
|
|
|
CString("invalid address argument ") + e.what());
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-22 16:20:23 +00:00
|
|
|
else if (name == "heartbeat") {
|
2007-06-17 11:19:18 +00:00
|
|
|
addOption("", kOptionHeartbeat, s.parseInt(value));
|
|
|
|
}
|
|
|
|
else if (name == "switchCorners") {
|
|
|
|
addOption("", kOptionScreenSwitchCorners, s.parseCorners(value));
|
|
|
|
}
|
|
|
|
else if (name == "switchCornerSize") {
|
|
|
|
addOption("", kOptionScreenSwitchCornerSize, s.parseInt(value));
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
2003-02-22 21:53:25 +00:00
|
|
|
else if (name == "switchDelay") {
|
2007-06-17 11:19:18 +00:00
|
|
|
addOption("", kOptionScreenSwitchDelay, s.parseInt(value));
|
2003-02-22 21:53:25 +00:00
|
|
|
}
|
2003-02-23 19:29:08 +00:00
|
|
|
else if (name == "switchDoubleTap") {
|
2007-06-17 11:19:18 +00:00
|
|
|
addOption("", kOptionScreenSwitchTwoTap, s.parseInt(value));
|
2003-02-23 19:29:08 +00:00
|
|
|
}
|
2003-05-03 14:38:36 +00:00
|
|
|
else if (name == "screenSaverSync") {
|
2007-06-17 11:19:18 +00:00
|
|
|
addOption("", kOptionScreenSaverSync, s.parseBoolean(value));
|
2003-05-03 14:38:36 +00:00
|
|
|
}
|
2004-05-01 15:18:59 +00:00
|
|
|
else if (name == "relativeMouseMoves") {
|
2007-06-17 11:19:18 +00:00
|
|
|
addOption("", kOptionRelativeMouseMoves, s.parseBoolean(value));
|
|
|
|
}
|
|
|
|
else if (name == "win32KeepForeground") {
|
|
|
|
addOption("", kOptionWin32KeepForeground, s.parseBoolean(value));
|
2004-05-01 15:18:59 +00:00
|
|
|
}
|
2002-06-09 16:53:25 +00:00
|
|
|
else {
|
2007-06-17 11:19:18 +00:00
|
|
|
handled = false;
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
if (handled) {
|
|
|
|
// make sure handled options aren't followed by more values
|
|
|
|
if (i < line.size() && (line[i] == ',' || line[i] == ';')) {
|
|
|
|
throw XConfigRead(s, "to many arguments to %s", name.c_str());
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
else {
|
|
|
|
// make filter rule
|
|
|
|
CInputFilter::CRule rule(parseCondition(s, name, nameArgs));
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// save first action (if any)
|
|
|
|
if (!value.empty() || line[i] != ';') {
|
|
|
|
parseAction(s, value, valueArgs, rule, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get remaining activate actions
|
|
|
|
while (i < line.length() && line[i] != ';') {
|
|
|
|
++i;
|
|
|
|
s.parseNameWithArgs("value", line, ",;\n", i, value, valueArgs);
|
|
|
|
parseAction(s, value, valueArgs, rule, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get deactivate actions
|
|
|
|
if (i < line.length() && line[i] == ';') {
|
|
|
|
// allow trailing ';'
|
|
|
|
i = line.find_first_not_of(" \t", i + 1);
|
|
|
|
if (i == CString::npos) {
|
|
|
|
i = line.length();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get actions
|
|
|
|
while (i < line.length()) {
|
|
|
|
++i;
|
|
|
|
s.parseNameWithArgs("value", line, ",\n",
|
|
|
|
i, value, valueArgs);
|
|
|
|
parseAction(s, value, valueArgs, rule, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add rule
|
|
|
|
m_inputFilter.addFilterRule(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw XConfigRead(s, "unexpected end of options section");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfig::readSectionScreens(CConfigReadContext& s)
|
|
|
|
{
|
|
|
|
CString line;
|
|
|
|
CString screen;
|
|
|
|
while (s.readLine(line)) {
|
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if it's the next screen
|
|
|
|
if (line[line.size() - 1] == ':') {
|
2002-05-31 17:32:26 +00:00
|
|
|
// strip :
|
2002-12-23 13:55:21 +00:00
|
|
|
screen = line.substr(0, line.size() - 1);
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
// verify validity of screen name
|
2002-12-23 13:55:21 +00:00
|
|
|
if (!isValidScreenName(screen)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "invalid screen name \"%{1}\"", screen);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add the screen to the configuration
|
2002-12-23 13:55:21 +00:00
|
|
|
if (!addScreen(screen)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "duplicate screen name \"%{1}\"", screen);
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
else if (screen.empty()) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "argument before first screen");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-12-23 13:55:21 +00:00
|
|
|
// parse argument: `<name>=<value>'
|
|
|
|
CString::size_type i = line.find_first_of(" \t=");
|
|
|
|
if (i == 0) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "missing argument name");
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
if (i == CString::npos) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "missing =");
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
CString name = line.substr(0, i);
|
|
|
|
i = line.find_first_not_of(" \t", i);
|
|
|
|
if (i == CString::npos || line[i] != '=') {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "missing =");
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
i = line.find_first_not_of(" \t", i + 1);
|
|
|
|
CString value;
|
|
|
|
if (i != CString::npos) {
|
|
|
|
value = line.substr(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle argument
|
|
|
|
if (name == "halfDuplexCapsLock") {
|
|
|
|
addOption(screen, kOptionHalfDuplexCapsLock,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseBoolean(value));
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
else if (name == "halfDuplexNumLock") {
|
|
|
|
addOption(screen, kOptionHalfDuplexNumLock,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseBoolean(value));
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
2004-09-28 22:19:11 +00:00
|
|
|
else if (name == "halfDuplexScrollLock") {
|
|
|
|
addOption(screen, kOptionHalfDuplexScrollLock,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseBoolean(value));
|
2004-09-28 22:19:11 +00:00
|
|
|
}
|
2003-02-22 15:03:31 +00:00
|
|
|
else if (name == "shift") {
|
|
|
|
addOption(screen, kOptionModifierMapForShift,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseModifierKey(value));
|
2003-02-22 15:03:31 +00:00
|
|
|
}
|
|
|
|
else if (name == "ctrl") {
|
|
|
|
addOption(screen, kOptionModifierMapForControl,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseModifierKey(value));
|
2003-02-22 15:03:31 +00:00
|
|
|
}
|
|
|
|
else if (name == "alt") {
|
|
|
|
addOption(screen, kOptionModifierMapForAlt,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseModifierKey(value));
|
2003-02-22 15:03:31 +00:00
|
|
|
}
|
|
|
|
else if (name == "meta") {
|
|
|
|
addOption(screen, kOptionModifierMapForMeta,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseModifierKey(value));
|
2003-02-22 15:03:31 +00:00
|
|
|
}
|
|
|
|
else if (name == "super") {
|
|
|
|
addOption(screen, kOptionModifierMapForSuper,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseModifierKey(value));
|
2003-02-22 15:03:31 +00:00
|
|
|
}
|
2003-05-17 13:44:24 +00:00
|
|
|
else if (name == "xtestIsXineramaUnaware") {
|
|
|
|
addOption(screen, kOptionXTestXineramaUnaware,
|
2007-06-17 11:19:18 +00:00
|
|
|
s.parseBoolean(value));
|
|
|
|
}
|
|
|
|
else if (name == "switchCorners") {
|
|
|
|
addOption(screen, kOptionScreenSwitchCorners,
|
|
|
|
s.parseCorners(value));
|
|
|
|
}
|
|
|
|
else if (name == "switchCornerSize") {
|
|
|
|
addOption(screen, kOptionScreenSwitchCornerSize,
|
|
|
|
s.parseInt(value));
|
2003-05-17 13:44:24 +00:00
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
else {
|
|
|
|
// unknown argument
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unknown argument \"%{1}\"", name);
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unexpected end of screens section");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::readSectionLinks(CConfigReadContext& s)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
CString line;
|
|
|
|
CString screen;
|
2007-06-17 11:19:18 +00:00
|
|
|
while (s.readLine(line)) {
|
2002-05-31 17:32:26 +00:00
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if it's the next screen
|
|
|
|
if (line[line.size() - 1] == ':') {
|
|
|
|
// strip :
|
|
|
|
screen = line.substr(0, line.size() - 1);
|
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// verify we know about the screen
|
2002-05-31 17:32:26 +00:00
|
|
|
if (!isScreen(screen)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unknown screen name \"%{1}\"", screen);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
if (!isCanonicalName(screen)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "cannot use screen name alias here");
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
else if (screen.empty()) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "argument before first screen");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-06-17 11:19:18 +00:00
|
|
|
// parse argument: `<name>[(<s0>,<e0>)]=<value>[(<s1>,<e1>)]'
|
|
|
|
// the stuff in brackets is optional. interval values must be
|
|
|
|
// in the range [0,100] and start < end. if not given the
|
|
|
|
// interval is taken to be (0,100).
|
|
|
|
CString::size_type i = 0;
|
|
|
|
CString side, dstScreen, srcArgString, dstArgString;
|
|
|
|
CConfigReadContext::ArgList srcArgs, dstArgs;
|
|
|
|
s.parseNameWithArgs("link", line, "=", i, side, srcArgs);
|
|
|
|
++i;
|
|
|
|
s.parseNameWithArgs("screen", line, "", i, dstScreen, dstArgs);
|
|
|
|
CInterval srcInterval(s.parseInterval(srcArgs));
|
|
|
|
CInterval dstInterval(s.parseInterval(dstArgs));
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
// handle argument
|
2007-06-17 11:19:18 +00:00
|
|
|
EDirection dir;
|
|
|
|
if (side == "left") {
|
|
|
|
dir = kLeft;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (side == "right") {
|
|
|
|
dir = kRight;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (side == "up") {
|
|
|
|
dir = kTop;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (side == "down") {
|
|
|
|
dir = kBottom;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// unknown argument
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unknown side \"%{1}\" in link", side);
|
|
|
|
}
|
|
|
|
if (!isScreen(dstScreen)) {
|
|
|
|
throw XConfigRead(s, "unknown screen name \"%{1}\"", dstScreen);
|
|
|
|
}
|
|
|
|
if (!connect(screen, dir,
|
|
|
|
srcInterval.first, srcInterval.second,
|
|
|
|
dstScreen,
|
|
|
|
dstInterval.first, dstInterval.second)) {
|
|
|
|
throw XConfigRead(s, "overlapping range");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unexpected end of links section");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2007-06-17 11:19:18 +00:00
|
|
|
CConfig::readSectionAliases(CConfigReadContext& s)
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
CString line;
|
|
|
|
CString screen;
|
2007-06-17 11:19:18 +00:00
|
|
|
while (s.readLine(line)) {
|
2002-06-08 23:24:40 +00:00
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if it's the next screen
|
|
|
|
if (line[line.size() - 1] == ':') {
|
|
|
|
// strip :
|
|
|
|
screen = line.substr(0, line.size() - 1);
|
|
|
|
|
|
|
|
// verify we know about the screen
|
|
|
|
if (!isScreen(screen)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unknown screen name \"%{1}\"", screen);
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
if (!isCanonicalName(screen)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "cannot use screen name alias here");
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (screen.empty()) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "argument before first screen");
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// verify validity of screen name
|
|
|
|
if (!isValidScreenName(line)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "invalid screen alias \"%{1}\"", line);
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add alias
|
|
|
|
if (!addAlias(screen, line)) {
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "alias \"%{1}\" is already used", line);
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
throw XConfigRead(s, "unexpected end of aliases section");
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
CInputFilter::CCondition*
|
|
|
|
CConfig::parseCondition(CConfigReadContext& s,
|
|
|
|
const CString& name, const std::vector<CString>& args)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
if (name == "keystroke") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for condition: keystroke(modifiers+key)");
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
IPlatformScreen::CKeyInfo* keyInfo = s.parseKeystroke(args[0]);
|
|
|
|
|
|
|
|
return new CInputFilter::CKeystrokeCondition(keyInfo);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
|
|
|
|
if (name == "mousebutton") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for condition: mousebutton(modifiers+button)");
|
|
|
|
}
|
|
|
|
|
|
|
|
IPlatformScreen::CButtonInfo* mouseInfo = s.parseMouse(args[0]);
|
|
|
|
|
|
|
|
return new CInputFilter::CMouseButtonCondition(mouseInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "connect") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for condition: connect([screen])");
|
|
|
|
}
|
|
|
|
|
|
|
|
CString screen = args[0];
|
|
|
|
if (isScreen(screen)) {
|
|
|
|
screen = getCanonicalName(screen);
|
|
|
|
}
|
|
|
|
else if (!screen.empty()) {
|
|
|
|
throw XConfigRead(s, "unknown screen name \"%{1}\" in connect", screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CInputFilter::CScreenConnectedCondition(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw XConfigRead(s, "unknown argument \"%{1}\"", name);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
void
|
|
|
|
CConfig::parseAction(CConfigReadContext& s,
|
|
|
|
const CString& name, const std::vector<CString>& args,
|
|
|
|
CInputFilter::CRule& rule, bool activate)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2007-06-17 11:19:18 +00:00
|
|
|
CInputFilter::CAction* action;
|
|
|
|
|
|
|
|
if (name == "keystroke" || name == "keyDown" || name == "keyUp") {
|
|
|
|
if (args.size() < 1 || args.size() > 2) {
|
|
|
|
throw XConfigRead(s, "syntax for action: keystroke(modifiers+key[,screens])");
|
|
|
|
}
|
|
|
|
|
|
|
|
IPlatformScreen::CKeyInfo* keyInfo;
|
|
|
|
if (args.size() == 1) {
|
|
|
|
keyInfo = s.parseKeystroke(args[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::set<CString> screens;
|
|
|
|
parseScreens(s, args[1], screens);
|
|
|
|
keyInfo = s.parseKeystroke(args[0], screens);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "keystroke") {
|
|
|
|
IPlatformScreen::CKeyInfo* keyInfo2 =
|
|
|
|
IKeyState::CKeyInfo::alloc(*keyInfo);
|
|
|
|
action = new CInputFilter::CKeystrokeAction(keyInfo2, true);
|
|
|
|
rule.adoptAction(action, true);
|
|
|
|
action = new CInputFilter::CKeystrokeAction(keyInfo, false);
|
|
|
|
activate = false;
|
|
|
|
}
|
|
|
|
else if (name == "keyDown") {
|
|
|
|
action = new CInputFilter::CKeystrokeAction(keyInfo, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
action = new CInputFilter::CKeystrokeAction(keyInfo, false);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-09 16:53:25 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (name == "mousebutton" ||
|
|
|
|
name == "mouseDown" || name == "mouseUp") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for action: mousebutton(modifiers+button)");
|
|
|
|
}
|
|
|
|
|
|
|
|
IPlatformScreen::CButtonInfo* mouseInfo = s.parseMouse(args[0]);
|
|
|
|
|
|
|
|
if (name == "mousebutton") {
|
|
|
|
IPlatformScreen::CButtonInfo* mouseInfo2 =
|
|
|
|
IPlatformScreen::CButtonInfo::alloc(*mouseInfo);
|
|
|
|
action = new CInputFilter::CMouseButtonAction(mouseInfo2, true);
|
|
|
|
rule.adoptAction(action, true);
|
|
|
|
action = new CInputFilter::CMouseButtonAction(mouseInfo, false);
|
|
|
|
activate = false;
|
|
|
|
}
|
|
|
|
else if (name == "mouseDown") {
|
|
|
|
action = new CInputFilter::CMouseButtonAction(mouseInfo, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
action = new CInputFilter::CMouseButtonAction(mouseInfo, false);
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
/* XXX -- not supported
|
|
|
|
else if (name == "modifier") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for action: modifier(modifiers)");
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyModifierMask mask = s.parseModifier(args[0]);
|
|
|
|
|
|
|
|
action = new CInputFilter::CModifierAction(mask, ~mask);
|
|
|
|
}
|
|
|
|
*/
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (name == "switchToScreen") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for action: switchToScreen(name)");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
CString screen = args[0];
|
|
|
|
if (isScreen(screen)) {
|
|
|
|
screen = getCanonicalName(screen);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (!screen.empty()) {
|
|
|
|
throw XConfigRead(s, "unknown screen name in switchToScreen");
|
|
|
|
}
|
|
|
|
|
|
|
|
action = new CInputFilter::CSwitchToScreenAction(screen);
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (name == "switchInDirection") {
|
|
|
|
if (args.size() != 1) {
|
|
|
|
throw XConfigRead(s, "syntax for action: switchInDirection(<left|right|up|down>)");
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
EDirection direction;
|
|
|
|
if (args[0] == "left") {
|
|
|
|
direction = kLeft;
|
|
|
|
}
|
|
|
|
else if (args[0] == "right") {
|
|
|
|
direction = kRight;
|
|
|
|
}
|
|
|
|
else if (args[0] == "up") {
|
|
|
|
direction = kTop;
|
|
|
|
}
|
|
|
|
else if (args[0] == "down") {
|
|
|
|
direction = kBottom;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw XConfigRead(s, "unknown direction \"%{1}\" in switchToScreen", args[0]);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
|
|
|
|
action = new CInputFilter::CSwitchInDirectionAction(direction);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
else if (name == "lockCursorToScreen") {
|
|
|
|
if (args.size() > 1) {
|
|
|
|
throw XConfigRead(s, "syntax for action: lockCursorToScreen([{off|on|toggle}])");
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
CInputFilter::CLockCursorToScreenAction::Mode mode =
|
|
|
|
CInputFilter::CLockCursorToScreenAction::kToggle;
|
|
|
|
if (args.size() == 1) {
|
|
|
|
if (args[0] == "off") {
|
|
|
|
mode = CInputFilter::CLockCursorToScreenAction::kOff;
|
|
|
|
}
|
|
|
|
else if (args[0] == "on") {
|
|
|
|
mode = CInputFilter::CLockCursorToScreenAction::kOn;
|
|
|
|
}
|
|
|
|
else if (args[0] == "toggle") {
|
|
|
|
mode = CInputFilter::CLockCursorToScreenAction::kToggle;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw XConfigRead(s, "syntax for action: lockCursorToScreen([{off|on|toggle}])");
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-17 11:19:18 +00:00
|
|
|
|
|
|
|
if (mode != CInputFilter::CLockCursorToScreenAction::kOff) {
|
|
|
|
m_hasLockToScreenAction = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
action = new CInputFilter::CLockCursorToScreenAction(mode);
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
2007-09-10 00:59:51 +00:00
|
|
|
else if (name == "keyboardBroadcast") {
|
|
|
|
if (args.size() > 2) {
|
|
|
|
throw XConfigRead(s, "syntax for action: keyboardBroadcast([{off|on|toggle}[,screens]])");
|
|
|
|
}
|
|
|
|
|
|
|
|
CInputFilter::CKeyboardBroadcastAction::Mode mode =
|
|
|
|
CInputFilter::CKeyboardBroadcastAction::kToggle;
|
|
|
|
if (args.size() >= 1) {
|
|
|
|
if (args[0] == "off") {
|
|
|
|
mode = CInputFilter::CKeyboardBroadcastAction::kOff;
|
|
|
|
}
|
|
|
|
else if (args[0] == "on") {
|
|
|
|
mode = CInputFilter::CKeyboardBroadcastAction::kOn;
|
|
|
|
}
|
|
|
|
else if (args[0] == "toggle") {
|
|
|
|
mode = CInputFilter::CKeyboardBroadcastAction::kToggle;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw XConfigRead(s, "syntax for action: keyboardBroadcast([{off|on|toggle}[,screens]])");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<CString> screens;
|
|
|
|
if (args.size() >= 2) {
|
|
|
|
parseScreens(s, args[1], screens);
|
|
|
|
}
|
|
|
|
|
|
|
|
action = new CInputFilter::CKeyboardBroadcastAction(mode, screens);
|
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
else {
|
|
|
|
throw XConfigRead(s, "unknown action argument \"%{1}\"", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
rule.adoptAction(action, activate);
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
void
|
|
|
|
CConfig::parseScreens(CConfigReadContext& c,
|
|
|
|
const CString& s, std::set<CString>& screens) const
|
|
|
|
{
|
|
|
|
screens.clear();
|
|
|
|
|
|
|
|
CString::size_type i = 0;
|
|
|
|
while (i < s.size()) {
|
|
|
|
// find end of next screen name
|
|
|
|
CString::size_type j = s.find(':', i);
|
|
|
|
if (j == CString::npos) {
|
|
|
|
j = s.size();
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
// extract name
|
|
|
|
CString rawName;
|
|
|
|
i = s.find_first_not_of(" \t", i);
|
|
|
|
if (i < j) {
|
|
|
|
rawName = s.substr(i, s.find_last_not_of(" \t", j - 1) - i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add name
|
|
|
|
if (rawName == "*") {
|
|
|
|
screens.insert("*");
|
|
|
|
}
|
|
|
|
else if (!rawName.empty()) {
|
|
|
|
CString name = getCanonicalName(rawName);
|
|
|
|
if (name.empty()) {
|
|
|
|
throw XConfigRead(c, "unknown screen name \"%{1}\"", rawName);
|
|
|
|
}
|
|
|
|
screens.insert(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// next
|
|
|
|
i = j + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
CConfig::getOptionName(OptionID id)
|
|
|
|
{
|
|
|
|
if (id == kOptionHalfDuplexCapsLock) {
|
|
|
|
return "halfDuplexCapsLock";
|
|
|
|
}
|
|
|
|
if (id == kOptionHalfDuplexNumLock) {
|
|
|
|
return "halfDuplexNumLock";
|
|
|
|
}
|
|
|
|
if (id == kOptionHalfDuplexScrollLock) {
|
|
|
|
return "halfDuplexScrollLock";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForShift) {
|
|
|
|
return "shift";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForControl) {
|
|
|
|
return "ctrl";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForAlt) {
|
|
|
|
return "alt";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForMeta) {
|
|
|
|
return "meta";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForSuper) {
|
|
|
|
return "super";
|
|
|
|
}
|
|
|
|
if (id == kOptionHeartbeat) {
|
|
|
|
return "heartbeat";
|
|
|
|
}
|
|
|
|
if (id == kOptionScreenSwitchCorners) {
|
|
|
|
return "switchCorners";
|
|
|
|
}
|
|
|
|
if (id == kOptionScreenSwitchCornerSize) {
|
|
|
|
return "switchCornerSize";
|
|
|
|
}
|
|
|
|
if (id == kOptionScreenSwitchDelay) {
|
|
|
|
return "switchDelay";
|
|
|
|
}
|
|
|
|
if (id == kOptionScreenSwitchTwoTap) {
|
|
|
|
return "switchDoubleTap";
|
|
|
|
}
|
|
|
|
if (id == kOptionScreenSaverSync) {
|
|
|
|
return "screenSaverSync";
|
|
|
|
}
|
|
|
|
if (id == kOptionXTestXineramaUnaware) {
|
|
|
|
return "xtestIsXineramaUnaware";
|
|
|
|
}
|
|
|
|
if (id == kOptionRelativeMouseMoves) {
|
|
|
|
return "relativeMouseMoves";
|
|
|
|
}
|
|
|
|
if (id == kOptionWin32KeepForeground) {
|
|
|
|
return "win32KeepForeground";
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CString
|
|
|
|
CConfig::getOptionValue(OptionID id, OptionValue value)
|
|
|
|
{
|
|
|
|
if (id == kOptionHalfDuplexCapsLock ||
|
|
|
|
id == kOptionHalfDuplexNumLock ||
|
|
|
|
id == kOptionHalfDuplexScrollLock ||
|
|
|
|
id == kOptionScreenSaverSync ||
|
|
|
|
id == kOptionXTestXineramaUnaware ||
|
|
|
|
id == kOptionRelativeMouseMoves ||
|
|
|
|
id == kOptionWin32KeepForeground) {
|
|
|
|
return (value != 0) ? "true" : "false";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForShift ||
|
|
|
|
id == kOptionModifierMapForControl ||
|
|
|
|
id == kOptionModifierMapForAlt ||
|
|
|
|
id == kOptionModifierMapForMeta ||
|
|
|
|
id == kOptionModifierMapForSuper) {
|
|
|
|
switch (value) {
|
|
|
|
case kKeyModifierIDShift:
|
|
|
|
return "shift";
|
|
|
|
|
|
|
|
case kKeyModifierIDControl:
|
|
|
|
return "ctrl";
|
|
|
|
|
|
|
|
case kKeyModifierIDAlt:
|
|
|
|
return "alt";
|
|
|
|
|
|
|
|
case kKeyModifierIDMeta:
|
|
|
|
return "meta";
|
|
|
|
|
|
|
|
case kKeyModifierIDSuper:
|
|
|
|
return "super";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id == kOptionHeartbeat ||
|
|
|
|
id == kOptionScreenSwitchCornerSize ||
|
|
|
|
id == kOptionScreenSwitchDelay ||
|
|
|
|
id == kOptionScreenSwitchTwoTap) {
|
|
|
|
return CStringUtil::print("%d", value);
|
|
|
|
}
|
|
|
|
if (id == kOptionScreenSwitchCorners) {
|
|
|
|
std::string result("none");
|
|
|
|
if ((value & kTopLeftMask) != 0) {
|
|
|
|
result += " +top-left";
|
|
|
|
}
|
|
|
|
if ((value & kTopRightMask) != 0) {
|
|
|
|
result += " +top-right";
|
|
|
|
}
|
|
|
|
if ((value & kBottomLeftMask) != 0) {
|
|
|
|
result += " +bottom-left";
|
|
|
|
}
|
|
|
|
if ((value & kBottomRightMask) != 0) {
|
|
|
|
result += " +bottom-right";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig::CName
|
|
|
|
//
|
|
|
|
|
|
|
|
CConfig::CName::CName(CConfig* config, const CString& name) :
|
|
|
|
m_config(config),
|
|
|
|
m_name(config->getCanonicalName(name))
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CName::operator==(const CString& name) const
|
|
|
|
{
|
|
|
|
CString canonical = m_config->getCanonicalName(name);
|
|
|
|
return CStringUtil::CaselessCmp::equal(canonical, m_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig::CCellEdge
|
|
|
|
//
|
|
|
|
|
|
|
|
CConfig::CCellEdge::CCellEdge(EDirection side, float position)
|
|
|
|
{
|
|
|
|
init("", side, CInterval(position, position));
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CCellEdge::CCellEdge(EDirection side, const CInterval& interval)
|
|
|
|
{
|
|
|
|
assert(interval.first >= 0.0f);
|
|
|
|
assert(interval.second <= 1.0f);
|
|
|
|
assert(interval.first < interval.second);
|
|
|
|
|
|
|
|
init("", side, interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CCellEdge::CCellEdge(const CString& name,
|
|
|
|
EDirection side, const CInterval& interval)
|
|
|
|
{
|
|
|
|
assert(interval.first >= 0.0f);
|
|
|
|
assert(interval.second <= 1.0f);
|
|
|
|
assert(interval.first < interval.second);
|
|
|
|
|
|
|
|
init(name, side, interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CCellEdge::~CCellEdge()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfig::CCellEdge::init(const CString& name, EDirection side,
|
|
|
|
const CInterval& interval)
|
|
|
|
{
|
|
|
|
assert(side != kNoDirection);
|
|
|
|
|
|
|
|
m_name = name;
|
|
|
|
m_side = side;
|
|
|
|
m_interval = interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CInterval
|
|
|
|
CConfig::CCellEdge::getInterval() const
|
|
|
|
{
|
|
|
|
return m_interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfig::CCellEdge::setName(const CString& newName)
|
|
|
|
{
|
|
|
|
m_name = newName;
|
|
|
|
}
|
|
|
|
|
|
|
|
CString
|
|
|
|
CConfig::CCellEdge::getName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
EDirection
|
|
|
|
CConfig::CCellEdge::getSide() const
|
|
|
|
{
|
|
|
|
return m_side;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCellEdge::overlaps(const CCellEdge& edge) const
|
|
|
|
{
|
|
|
|
const CInterval& x = m_interval;
|
|
|
|
const CInterval& y = edge.m_interval;
|
|
|
|
if (m_side != edge.m_side) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (x.first >= y.first && x.first < y.second) ||
|
|
|
|
(x.second > y.first && x.second <= y.second) ||
|
|
|
|
(y.first >= x.first && y.first < x.second) ||
|
|
|
|
(y.second > x.first && y.second <= x.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCellEdge::isInside(float x) const
|
|
|
|
{
|
|
|
|
return (x >= m_interval.first && x < m_interval.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
CConfig::CCellEdge::transform(float x) const
|
|
|
|
{
|
|
|
|
return (x - m_interval.first) / (m_interval.second - m_interval.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
CConfig::CCellEdge::inverseTransform(float x) const
|
|
|
|
{
|
|
|
|
return x * (m_interval.second - m_interval.first) + m_interval.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCellEdge::operator<(const CCellEdge& o) const
|
|
|
|
{
|
|
|
|
if (static_cast<int>(m_side) < static_cast<int>(o.m_side)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (static_cast<int>(m_side) > static_cast<int>(o.m_side)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (m_interval.first < o.m_interval.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCellEdge::operator==(const CCellEdge& x) const
|
|
|
|
{
|
|
|
|
return (m_side == x.m_side && m_interval == x.m_interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCellEdge::operator!=(const CCellEdge& x) const
|
|
|
|
{
|
|
|
|
return !operator==(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig::CCell
|
|
|
|
//
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCell::add(const CCellEdge& src, const CCellEdge& dst)
|
|
|
|
{
|
|
|
|
// cannot add an edge that overlaps other existing edges but we
|
|
|
|
// can exactly replace an edge.
|
|
|
|
if (!hasEdge(src) && overlaps(src)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_neighbors.erase(src);
|
|
|
|
m_neighbors.insert(std::make_pair(src, dst));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfig::CCell::remove(EDirection side)
|
|
|
|
{
|
|
|
|
for (CEdgeLinks::iterator j = m_neighbors.begin();
|
|
|
|
j != m_neighbors.end(); ) {
|
|
|
|
if (j->first.getSide() == side) {
|
|
|
|
m_neighbors.erase(j++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfig::CCell::remove(EDirection side, float position)
|
|
|
|
{
|
|
|
|
for (CEdgeLinks::iterator j = m_neighbors.begin();
|
|
|
|
j != m_neighbors.end(); ++j) {
|
|
|
|
if (j->first.getSide() == side && j->first.isInside(position)) {
|
|
|
|
m_neighbors.erase(j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
|
|
|
CConfig::CCell::remove(const CName& name)
|
|
|
|
{
|
|
|
|
for (CEdgeLinks::iterator j = m_neighbors.begin();
|
|
|
|
j != m_neighbors.end(); ) {
|
|
|
|
if (name == j->second.getName()) {
|
|
|
|
m_neighbors.erase(j++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfig::CCell::rename(const CName& oldName, const CString& newName)
|
|
|
|
{
|
|
|
|
for (CEdgeLinks::iterator j = m_neighbors.begin();
|
|
|
|
j != m_neighbors.end(); ++j) {
|
|
|
|
if (oldName == j->second.getName()) {
|
|
|
|
j->second.setName(newName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCell::hasEdge(const CCellEdge& edge) const
|
|
|
|
{
|
|
|
|
CEdgeLinks::const_iterator i = m_neighbors.find(edge);
|
|
|
|
return (i != m_neighbors.end() && i->first == edge);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCell::overlaps(const CCellEdge& edge) const
|
|
|
|
{
|
|
|
|
CEdgeLinks::const_iterator i = m_neighbors.upper_bound(edge);
|
|
|
|
if (i != m_neighbors.end() && i->first.overlaps(edge)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (i != m_neighbors.begin() && (--i)->first.overlaps(edge)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCell::getLink(EDirection side, float position,
|
|
|
|
const CCellEdge*& src, const CCellEdge*& dst) const
|
|
|
|
{
|
|
|
|
CCellEdge edge(side, position);
|
|
|
|
CEdgeLinks::const_iterator i = m_neighbors.upper_bound(edge);
|
|
|
|
if (i == m_neighbors.begin()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
--i;
|
|
|
|
if (i->first.getSide() == side && i->first.isInside(position)) {
|
|
|
|
src = &i->first;
|
|
|
|
dst = &i->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCell::operator==(const CCell& x) const
|
|
|
|
{
|
|
|
|
// compare options
|
|
|
|
if (m_options != x.m_options) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare links
|
|
|
|
if (m_neighbors.size() != x.m_neighbors.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (CEdgeLinks::const_iterator index1 = m_neighbors.begin(),
|
|
|
|
index2 = x.m_neighbors.begin();
|
|
|
|
index1 != m_neighbors.end();
|
|
|
|
++index1, ++index2) {
|
|
|
|
if (index1->first != index2->first) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (index1->second != index2->second) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator== doesn't compare names. only compare destination
|
|
|
|
// names.
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(index1->second.getName(),
|
|
|
|
index2->second.getName())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::CCell::operator!=(const CCell& x) const
|
|
|
|
{
|
|
|
|
return !operator==(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CCell::const_iterator
|
|
|
|
CConfig::CCell::begin() const
|
|
|
|
{
|
|
|
|
return m_neighbors.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CCell::const_iterator
|
|
|
|
CConfig::CCell::end() const
|
|
|
|
{
|
|
|
|
return m_neighbors.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig I/O
|
|
|
|
//
|
|
|
|
|
|
|
|
std::istream&
|
|
|
|
operator>>(std::istream& s, CConfig& config)
|
|
|
|
{
|
|
|
|
CConfigReadContext context(s);
|
|
|
|
config.read(context);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& s, const CConfig& config)
|
|
|
|
{
|
|
|
|
// screens section
|
|
|
|
s << "section: screens" << std::endl;
|
|
|
|
for (CConfig::const_iterator screen = config.begin();
|
|
|
|
screen != config.end(); ++screen) {
|
|
|
|
s << "\t" << screen->c_str() << ":" << std::endl;
|
|
|
|
const CConfig::CScreenOptions* options = config.getOptions(*screen);
|
|
|
|
if (options != NULL && options->size() > 0) {
|
|
|
|
for (CConfig::CScreenOptions::const_iterator
|
|
|
|
option = options->begin();
|
|
|
|
option != options->end(); ++option) {
|
|
|
|
const char* name = CConfig::getOptionName(option->first);
|
|
|
|
CString value = CConfig::getOptionValue(option->first,
|
|
|
|
option->second);
|
|
|
|
if (name != NULL && !value.empty()) {
|
|
|
|
s << "\t\t" << name << " = " << value << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s << "end" << std::endl;
|
|
|
|
|
|
|
|
// links section
|
|
|
|
CString neighbor;
|
|
|
|
s << "section: links" << std::endl;
|
|
|
|
for (CConfig::const_iterator screen = config.begin();
|
|
|
|
screen != config.end(); ++screen) {
|
|
|
|
s << "\t" << screen->c_str() << ":" << std::endl;
|
|
|
|
|
|
|
|
for (CConfig::link_const_iterator
|
|
|
|
link = config.beginNeighbor(*screen),
|
|
|
|
nend = config.endNeighbor(*screen); link != nend; ++link) {
|
|
|
|
s << "\t\t" << CConfig::dirName(link->first.getSide()) <<
|
|
|
|
CConfig::formatInterval(link->first.getInterval()) <<
|
|
|
|
" = " << link->second.getName().c_str() <<
|
|
|
|
CConfig::formatInterval(link->second.getInterval()) <<
|
|
|
|
std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s << "end" << std::endl;
|
|
|
|
|
|
|
|
// aliases section (if there are any)
|
|
|
|
if (config.m_map.size() != config.m_nameToCanonicalName.size()) {
|
|
|
|
// map canonical to alias
|
|
|
|
typedef std::multimap<CString, CString,
|
|
|
|
CStringUtil::CaselessCmp> CMNameMap;
|
|
|
|
CMNameMap aliases;
|
|
|
|
for (CConfig::CNameMap::const_iterator
|
|
|
|
index = config.m_nameToCanonicalName.begin();
|
|
|
|
index != config.m_nameToCanonicalName.end();
|
|
|
|
++index) {
|
|
|
|
if (index->first != index->second) {
|
|
|
|
aliases.insert(std::make_pair(index->second, index->first));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dump it
|
|
|
|
CString screen;
|
|
|
|
s << "section: aliases" << std::endl;
|
|
|
|
for (CMNameMap::const_iterator index = aliases.begin();
|
|
|
|
index != aliases.end(); ++index) {
|
|
|
|
if (index->first != screen) {
|
|
|
|
screen = index->first;
|
|
|
|
s << "\t" << screen.c_str() << ":" << std::endl;
|
|
|
|
}
|
|
|
|
s << "\t\t" << index->second.c_str() << std::endl;
|
|
|
|
}
|
|
|
|
s << "end" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// options section
|
|
|
|
s << "section: options" << std::endl;
|
|
|
|
const CConfig::CScreenOptions* options = config.getOptions("");
|
|
|
|
if (options != NULL && options->size() > 0) {
|
|
|
|
for (CConfig::CScreenOptions::const_iterator
|
|
|
|
option = options->begin();
|
|
|
|
option != options->end(); ++option) {
|
|
|
|
const char* name = CConfig::getOptionName(option->first);
|
|
|
|
CString value = CConfig::getOptionValue(option->first,
|
|
|
|
option->second);
|
|
|
|
if (name != NULL && !value.empty()) {
|
|
|
|
s << "\t" << name << " = " << value << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (config.m_synergyAddress.isValid()) {
|
|
|
|
s << "\taddress = " <<
|
|
|
|
config.m_synergyAddress.getHostname().c_str() << std::endl;
|
|
|
|
}
|
|
|
|
s << config.m_inputFilter.format("\t");
|
|
|
|
s << "end" << std::endl;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfigReadContext
|
|
|
|
//
|
|
|
|
|
|
|
|
CConfigReadContext::CConfigReadContext(std::istream& s, SInt32 firstLine) :
|
|
|
|
m_stream(s),
|
|
|
|
m_line(firstLine - 1)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfigReadContext::~CConfigReadContext()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfigReadContext::readLine(CString& line)
|
|
|
|
{
|
|
|
|
++m_line;
|
|
|
|
while (std::getline(m_stream, line)) {
|
|
|
|
// strip leading whitespace
|
|
|
|
CString::size_type i = line.find_first_not_of(" \t");
|
|
|
|
if (i != CString::npos) {
|
|
|
|
line.erase(0, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// strip comments and then trailing whitespace
|
|
|
|
i = line.find('#');
|
|
|
|
if (i != CString::npos) {
|
|
|
|
line.erase(i);
|
|
|
|
}
|
|
|
|
i = line.find_last_not_of(" \r\t");
|
|
|
|
if (i != CString::npos) {
|
|
|
|
line.erase(i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return non empty line
|
|
|
|
if (!line.empty()) {
|
|
|
|
// make sure there are no invalid characters
|
|
|
|
for (i = 0; i < line.length(); ++i) {
|
|
|
|
if (!isgraph(line[i]) && line[i] != ' ' && line[i] != '\t') {
|
|
|
|
throw XConfigRead(*this,
|
|
|
|
"invalid character %{1}",
|
|
|
|
CStringUtil::print("%#2x", line[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// next line
|
|
|
|
++m_line;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
UInt32
|
|
|
|
CConfigReadContext::getLineNumber() const
|
|
|
|
{
|
|
|
|
return m_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfigReadContext::operator void*() const
|
|
|
|
{
|
|
|
|
return m_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfigReadContext::operator!() const
|
|
|
|
{
|
|
|
|
return !m_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionValue
|
|
|
|
CConfigReadContext::parseBoolean(const CString& arg) const
|
|
|
|
{
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "true")) {
|
|
|
|
return static_cast<OptionValue>(true);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "false")) {
|
|
|
|
return static_cast<OptionValue>(false);
|
|
|
|
}
|
|
|
|
throw XConfigRead(*this, "invalid boolean argument \"%{1}\"", arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionValue
|
|
|
|
CConfigReadContext::parseInt(const CString& arg) const
|
|
|
|
{
|
|
|
|
const char* s = arg.c_str();
|
|
|
|
char* end;
|
|
|
|
long tmp = strtol(s, &end, 10);
|
|
|
|
if (*end != '\0') {
|
|
|
|
// invalid characters
|
|
|
|
throw XConfigRead(*this, "invalid integer argument \"%{1}\"", arg);
|
|
|
|
}
|
|
|
|
OptionValue value = static_cast<OptionValue>(tmp);
|
|
|
|
if (value != tmp) {
|
|
|
|
// out of range
|
|
|
|
throw XConfigRead(*this, "integer argument \"%{1}\" out of range", arg);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionValue
|
|
|
|
CConfigReadContext::parseModifierKey(const CString& arg) const
|
|
|
|
{
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "shift")) {
|
|
|
|
return static_cast<OptionValue>(kKeyModifierIDShift);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "ctrl")) {
|
|
|
|
return static_cast<OptionValue>(kKeyModifierIDControl);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "alt")) {
|
|
|
|
return static_cast<OptionValue>(kKeyModifierIDAlt);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "meta")) {
|
|
|
|
return static_cast<OptionValue>(kKeyModifierIDMeta);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "super")) {
|
|
|
|
return static_cast<OptionValue>(kKeyModifierIDSuper);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "none")) {
|
|
|
|
return static_cast<OptionValue>(kKeyModifierIDNull);
|
|
|
|
}
|
|
|
|
throw XConfigRead(*this, "invalid argument \"%{1}\"", arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionValue
|
|
|
|
CConfigReadContext::parseCorner(const CString& arg) const
|
|
|
|
{
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "left")) {
|
|
|
|
return kTopLeftMask | kBottomLeftMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "right")) {
|
|
|
|
return kTopRightMask | kBottomRightMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "top")) {
|
|
|
|
return kTopLeftMask | kTopRightMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "bottom")) {
|
|
|
|
return kBottomLeftMask | kBottomRightMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "top-left")) {
|
|
|
|
return kTopLeftMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "top-right")) {
|
|
|
|
return kTopRightMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "bottom-left")) {
|
|
|
|
return kBottomLeftMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "bottom-right")) {
|
|
|
|
return kBottomRightMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "none")) {
|
|
|
|
return kNoCornerMask;
|
|
|
|
}
|
|
|
|
else if (CStringUtil::CaselessCmp::equal(arg, "all")) {
|
|
|
|
return kAllCornersMask;
|
|
|
|
}
|
|
|
|
throw XConfigRead(*this, "invalid argument \"%{1}\"", arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionValue
|
|
|
|
CConfigReadContext::parseCorners(const CString& args) const
|
|
|
|
{
|
|
|
|
// find first token
|
|
|
|
CString::size_type i = args.find_first_not_of(" \t", 0);
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead(*this, "missing corner argument");
|
|
|
|
}
|
|
|
|
CString::size_type j = args.find_first_of(" \t", i);
|
|
|
|
|
|
|
|
// parse first corner token
|
|
|
|
OptionValue corners = parseCorner(args.substr(i, j - i));
|
|
|
|
|
|
|
|
// get +/-
|
|
|
|
i = args.find_first_not_of(" \t", j);
|
|
|
|
while (i != CString::npos) {
|
|
|
|
// parse +/-
|
|
|
|
bool add;
|
|
|
|
if (args[i] == '-') {
|
|
|
|
add = false;
|
|
|
|
}
|
|
|
|
else if (args[i] == '+') {
|
|
|
|
add = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw XConfigRead(*this,
|
|
|
|
"invalid corner operator \"%{1}\"",
|
|
|
|
CString(args.c_str() + i, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
// get next corner token
|
|
|
|
i = args.find_first_not_of(" \t", i + 1);
|
|
|
|
j = args.find_first_of(" \t", i);
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead(*this, "missing corner argument");
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse next corner token
|
|
|
|
if (add) {
|
|
|
|
corners |= parseCorner(args.substr(i, j - i));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
corners &= ~parseCorner(args.substr(i, j - i));
|
|
|
|
}
|
|
|
|
i = args.find_first_not_of(" \t", j);
|
|
|
|
}
|
|
|
|
|
|
|
|
return corners;
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::CInterval
|
|
|
|
CConfigReadContext::parseInterval(const ArgList& args) const
|
|
|
|
{
|
|
|
|
if (args.size() == 0) {
|
|
|
|
return CConfig::CInterval(0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
if (args.size() != 2 || args[0].empty() || args[1].empty()) {
|
|
|
|
throw XConfigRead(*this, "invalid interval \"%{1}\"", concatArgs(args));
|
|
|
|
}
|
|
|
|
|
|
|
|
char* end;
|
|
|
|
long startValue = strtol(args[0].c_str(), &end, 10);
|
|
|
|
if (end[0] != '\0') {
|
|
|
|
throw XConfigRead(*this, "invalid interval \"%{1}\"", concatArgs(args));
|
|
|
|
}
|
|
|
|
long endValue = strtol(args[1].c_str(), &end, 10);
|
|
|
|
if (end[0] != '\0') {
|
|
|
|
throw XConfigRead(*this, "invalid interval \"%{1}\"", concatArgs(args));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startValue < 0 || startValue > 100 ||
|
|
|
|
endValue < 0 || endValue > 100 ||
|
|
|
|
startValue >= endValue) {
|
|
|
|
throw XConfigRead(*this, "invalid interval \"%{1}\"", concatArgs(args));
|
|
|
|
}
|
|
|
|
|
|
|
|
return CConfig::CInterval(startValue / 100.0f, endValue / 100.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CConfigReadContext::parseNameWithArgs(
|
|
|
|
const CString& type, const CString& line,
|
|
|
|
const CString& delim, CString::size_type& index,
|
|
|
|
CString& name, ArgList& args) const
|
|
|
|
{
|
|
|
|
// skip leading whitespace
|
|
|
|
CString::size_type i = line.find_first_not_of(" \t", index);
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead(*this, CString("missing ") + type);
|
|
|
|
}
|
|
|
|
|
|
|
|
// find end of name
|
|
|
|
CString::size_type j = line.find_first_of(" \t(" + delim, i);
|
|
|
|
if (j == CString::npos) {
|
|
|
|
j = line.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
// save name
|
|
|
|
name = line.substr(i, j - i);
|
|
|
|
args.clear();
|
|
|
|
|
|
|
|
// is it okay to not find a delimiter?
|
|
|
|
bool needDelim = (!delim.empty() && delim.find('\n') == CString::npos);
|
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
i = line.find_first_not_of(" \t", j);
|
|
|
|
if (i == CString::npos && needDelim) {
|
|
|
|
// expected delimiter but didn't find it
|
|
|
|
throw XConfigRead(*this, CString("missing ") + delim[0]);
|
|
|
|
}
|
|
|
|
if (i == CString::npos) {
|
|
|
|
// no arguments
|
|
|
|
index = line.length();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (line[i] != '(') {
|
|
|
|
// no arguments
|
|
|
|
index = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eat '('
|
|
|
|
++i;
|
|
|
|
|
|
|
|
// parse arguments
|
|
|
|
j = line.find_first_of(",)", i);
|
|
|
|
while (j != CString::npos) {
|
|
|
|
// extract arg
|
|
|
|
CString arg(line.substr(i, j - i));
|
|
|
|
i = j;
|
|
|
|
|
|
|
|
// trim whitespace
|
|
|
|
j = arg.find_first_not_of(" \t");
|
|
|
|
if (j != CString::npos) {
|
|
|
|
arg.erase(0, j);
|
|
|
|
}
|
|
|
|
j = arg.find_last_not_of(" \t");
|
|
|
|
if (j != CString::npos) {
|
|
|
|
arg.erase(j + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// save arg
|
|
|
|
args.push_back(arg);
|
|
|
|
|
|
|
|
// exit loop at end of arguments
|
|
|
|
if (line[i] == ')') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eat ','
|
|
|
|
++i;
|
|
|
|
|
|
|
|
// next
|
|
|
|
j = line.find_first_of(",)", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify ')'
|
|
|
|
if (j == CString::npos) {
|
|
|
|
// expected )
|
|
|
|
throw XConfigRead(*this, "missing )");
|
|
|
|
}
|
|
|
|
|
|
|
|
// eat ')'
|
|
|
|
++i;
|
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
j = line.find_first_not_of(" \t", i);
|
|
|
|
if (j == CString::npos && needDelim) {
|
|
|
|
// expected delimiter but didn't find it
|
|
|
|
throw XConfigRead(*this, CString("missing ") + delim[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify delimiter
|
|
|
|
if (needDelim && delim.find(line[j]) == CString::npos) {
|
|
|
|
throw XConfigRead(*this, CString("expected ") + delim[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == CString::npos) {
|
|
|
|
j = line.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
index = j;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPlatformScreen::CKeyInfo*
|
|
|
|
CConfigReadContext::parseKeystroke(const CString& keystroke) const
|
|
|
|
{
|
|
|
|
return parseKeystroke(keystroke, std::set<CString>());
|
|
|
|
}
|
|
|
|
|
|
|
|
IPlatformScreen::CKeyInfo*
|
|
|
|
CConfigReadContext::parseKeystroke(const CString& keystroke,
|
|
|
|
const std::set<CString>& screens) const
|
|
|
|
{
|
|
|
|
CString s = keystroke;
|
|
|
|
|
|
|
|
KeyModifierMask mask;
|
|
|
|
if (!CKeyMap::parseModifiers(s, mask)) {
|
|
|
|
throw XConfigRead(*this, "unable to parse key modifiers");
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyID key;
|
|
|
|
if (!CKeyMap::parseKey(s, key)) {
|
|
|
|
throw XConfigRead(*this, "unable to parse key");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key == kKeyNone && mask == 0) {
|
|
|
|
throw XConfigRead(*this, "missing key and/or modifiers in keystroke");
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPlatformScreen::CKeyInfo::alloc(key, mask, 0, 0, screens);
|
|
|
|
}
|
|
|
|
|
|
|
|
IPlatformScreen::CButtonInfo*
|
|
|
|
CConfigReadContext::parseMouse(const CString& mouse) const
|
|
|
|
{
|
|
|
|
CString s = mouse;
|
|
|
|
|
|
|
|
KeyModifierMask mask;
|
|
|
|
if (!CKeyMap::parseModifiers(s, mask)) {
|
|
|
|
throw XConfigRead(*this, "unable to parse button modifiers");
|
|
|
|
}
|
|
|
|
|
|
|
|
char* end;
|
|
|
|
ButtonID button = (ButtonID)strtol(s.c_str(), &end, 10);
|
|
|
|
if (*end != '\0') {
|
|
|
|
throw XConfigRead(*this, "unable to parse button");
|
|
|
|
}
|
|
|
|
if (s.empty() || button <= 0) {
|
|
|
|
throw XConfigRead(*this, "invalid button");
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPlatformScreen::CButtonInfo::alloc(button, mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyModifierMask
|
|
|
|
CConfigReadContext::parseModifier(const CString& modifiers) const
|
|
|
|
{
|
|
|
|
CString s = modifiers;
|
|
|
|
|
|
|
|
KeyModifierMask mask;
|
|
|
|
if (!CKeyMap::parseModifiers(s, mask)) {
|
|
|
|
throw XConfigRead(*this, "unable to parse modifiers");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask == 0) {
|
|
|
|
throw XConfigRead(*this, "no modifiers specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
CString
|
|
|
|
CConfigReadContext::concatArgs(const ArgList& args)
|
|
|
|
{
|
|
|
|
CString s("(");
|
|
|
|
for (size_t i = 0; i < args.size(); ++i) {
|
|
|
|
if (i != 0) {
|
|
|
|
s += ",";
|
|
|
|
}
|
|
|
|
s += args[i];
|
|
|
|
}
|
|
|
|
s += ")";
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig I/O exceptions
|
|
|
|
//
|
|
|
|
|
|
|
|
XConfigRead::XConfigRead(const CConfigReadContext& context,
|
|
|
|
const CString& error) :
|
|
|
|
m_error(CStringUtil::print("line %d: %s",
|
|
|
|
context.getLineNumber(), error.c_str()))
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2007-06-17 11:19:18 +00:00
|
|
|
XConfigRead::XConfigRead(const CConfigReadContext& context,
|
|
|
|
const char* errorFmt, const CString& arg) :
|
|
|
|
m_error(CStringUtil::print("line %d: ", context.getLineNumber()) +
|
|
|
|
CStringUtil::format(errorFmt, arg.c_str()))
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
XConfigRead::~XConfigRead()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
|
|
|
XConfigRead::getWhat() const throw()
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2002-10-15 22:08:10 +00:00
|
|
|
return format("XConfigRead", "read error: %{1}", m_error.c_str());
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|