23 :
QObject(parent), _value(action), preProgram(0), relProgram(0), sniperValue(0)
28 :
QObject(parent), _value(
""), preProgram(0), relProgram(0), sniperValue(0)
46 if(key.length() >= 2 && key[0] ==
'g'
47 && ((key.length() == 2 && key[1] >=
'0' && key[1] <=
'9')
48 || (key.length() == 3 && key[1] ==
'1' && key[2] >=
'0' && key[2] <=
'8')))
51 if(key.startsWith(
"thumb"))
87 QStringList parts =
_value.split(
":");
88 QString prefix = parts[0];
89 if(parts.length() < 2){
96 int suffix = parts[1].toInt();
97 if(prefix ==
"$mode"){
101 return "Switch to previous mode";
104 return "Switch to next mode";
106 return tr(
"Switch to mode %1").arg(suffix + 1);
108 }
else if(prefix ==
"$dpi"){
110 int level = parts[1].split(
"+")[0].toInt();
113 return "DPI cycle up";
115 return "DPI cycle down";
125 return tr(
"DPI: %1, %2").arg(xy.x()).arg(xy.y());
128 return tr(
"DPI stage %1").arg(level);
130 }
else if(prefix ==
"$light"){
134 return "Brightness up";
137 return "Brightness down";
139 }
else if(prefix ==
"$lock"){
142 return "Toggle Windows lock";
144 return "Windows lock on";
146 return "Windows lock off";
148 }
else if(prefix ==
"$anim"){
149 return "Start animation";
150 }
else if(prefix ==
"$program"){
151 return "Launch program";
152 }
else if(prefix ==
"$macro"){
153 return "Send G-key macro";
159 return QString(
"$mode:%1").arg(mode);
163 QString action = tr(
"$dpi:%1").arg(level);
165 action += tr(
"+%1+%2").arg(customX).arg(customY);
170 return QString(
"$light:%1").arg(type);
174 return QString(
"$lock:%1").arg(type);
179 return "$program:" + QString::fromUtf8(QUrl::toPercentEncoding(onPress.trimmed())) +
"+" + QString::fromUtf8(QUrl::toPercentEncoding(onRelease.trimmed())) + QString(
"+%1").arg(stop);
186 return "$anim:" + guid.toString() + QString(
"+%1").arg(flags);
190 QStringList list =
_value.split(
":");
191 if(list.length() < 2){
195 parameter = list[1].toInt();
196 return list[0].replace(
"$",
"");
202 QString param =
_value.mid(9);
203 QStringList programs = param.split(
"+");
204 if(programs.length() != 3)
206 onPress = QUrl::fromPercentEncoding(programs[0].toUtf8());
207 onRelease = QUrl::fromPercentEncoding(programs[1].toUtf8());
208 return programs[2].toInt();
214 QString param =
_value.mid(5);
215 QStringList lxy = param.split(
"+");
216 int level = lxy[0].toInt();
218 if(lxy.length() != 3)
220 custom = QPoint(lxy[1].toInt(), lxy[2].toInt());
228 QString param =
_value.mid(6);
229 QStringList split = param.split(
"+");
230 if(split.length() < 2)
233 int flags = split[1].toInt();
249 QStringList parts =
_value.split(
":");
250 if(parts.length() < 2)
252 QString prefix = parts[0];
253 int suffix = parts[1].toInt();
254 if(prefix ==
"$mode"){
261 int modeCount = currentProfile->
modeCount();
266 mode = modeCount - 1;
270 if(mode >= modeCount)
284 if(mode < 0 || mode >= modeCount)
287 }
else if(prefix ==
"$dpi"){
289 int level = parts[1].split(
"+")[0].toInt();
322 if(xy.x() <= 0 || xy.y() <= 0)
339 }
else if(prefix ==
"$light"){
366 }
else if(prefix ==
"$lock"){
381 }
else if(prefix ==
"$anim"){
383 bool onlyOnce =
false, stopOnRelease =
false;
384 QUuid
id =
animInfo(onlyOnce, stopOnRelease);
391 anim->
trigger(QDateTime::currentMSecsSinceEpoch(),
true);
392 }
else if(stopOnRelease){
396 }
else if(prefix ==
"$program"){
398 QString onPress, onRelease;
401 QProcess* process = 0;
418 QString& program = down ? onPress : onRelease;
419 if(program.isEmpty())
424 if(process->state() == QProcess::NotRunning)
437 QProcess::startDetached(
"sh", QStringList() <<
"-c" << program);
439 process =
new QProcess(
this);
440 process->start(
"sh", QStringList() <<
"-c" << program);
446 }
else if (prefix ==
"$macro") {
457 qDebug() <<
"isMacro returns" << (
isMacro() ?
"true" :
"false");
458 qDebug() <<
"isValidMacro returns" << (
isValidMacro() ?
"true" :
"false");
459 QStringList ret =
_value.split(
":");
460 qDebug() <<
"Macro definition conains" << ret.count() <<
"elements";
461 qDebug() <<
"Macro definition is" <<
_value;
467 char* display_name = XDisplayName(NULL);
470 Display* display = XOpenDisplay(display_name);
473 char* display_string = DisplayString(display);
474 if(!display_string || strlen(display_string) == 0){
475 XCloseDisplay(display);
478 size_t envstr_size = strlen(display_string) + 4;
479 char* envstr =
new char[envstr_size];
480 strncpy(envstr, display_string, envstr_size);
481 envstr[envstr_size - 1] = 0;
483 Window root_window = XRootWindow(display, DefaultScreen(display));
484 Window root_window_ret, child_window_ret, window;
485 XWindowAttributes attr;
486 int root_x, root_y, win_x, win_y;
487 unsigned int mask_ret;
490 XQueryPointer(display, root_window, &root_window_ret, &child_window_ret, &root_x, &root_y, &win_x, &win_y, &mask_ret);
491 if(child_window_ret == (Window)NULL)
492 window = root_window_ret;
494 window = child_window_ret;
495 XGetWindowAttributes(display, window, &attr);
497 char* ptr = strchr(envstr,
':');
499 ptr = strchr(ptr,
'.');
503 snprintf(buf,
sizeof(buf),
".%i", XScreenNumberOfScreen(attr.screen));
504 strncat(envstr, buf, envstr_size - 1 - strlen(envstr));
507 setenv(
"DISPLAY", envstr, 1);
511 XCloseDisplay(display);
524 return QString (
"$macro:%1").arg(macroDef);
KbMode * currentMode() const
const ModeList & modes() const
void setCurrentMode(KbProfile *profile, KbMode *mode, bool spontaneous=true)
static const int DPI_CYCLE_DOWN
static QString animAction(const QUuid &guid, bool onlyOnce, bool stopOnRelease)
static QString macroAction(QString macroDef)
well documented in cpp file
static QString friendlyName(const QString &key, Layout layout=US)
static const int DPI_CUSTOM
static const int PROGRAM_PR_MULTI
static const int ANIM_ONCE
static const int PROGRAM_RE_MULTI
static QString dpiAction(int level, int customX=0, int customY=0)
QString specialInfo(int ¶meter) const
bool isValidMacro() const
isValidMacro checks whether a keyAction contains a valid macro. This is done easily: If the macro act...
void trigger(quint64 timestamp, bool ignoreParameter=false)
KbProfile * currentProfile()
static const int ANIM_KRSTOP
static const int MODE_PREV
static QString programAction(const QString &onPress, const QString &onRelease, int stop)
static const int PROGRAM_PR_KPSTOP
QUuid animInfo(bool &onlyOnce, bool &stopOnRelease) const
KeyAction(const QString &action, QObject *parent=0)
void popDpi(quint64 pushIdx)
static const int DPI_SNIPER
quint64 pushDpi(const QPoint &newDpi)
static const int PROGRAM_RE_KPSTOP
static QString lockAction(int type=LOCK_TOGGLE)
static const int MODE_PREV_WRAP
static const int LOCK_TOGGLE
static const int DPI_COUNT
static QString modeAction(int mode)
static const int LIGHT_DOWN
static const int DPI_CYCLE_UP
static const int LOCK_OFF
int dpiInfo(QPoint &custom) const
static const int PROGRAM_PR_KRSTOP
static QString lightAction(int type=LIGHT_UP_WRAP)
QString driverName() const
static const int MODE_NEXT_WRAP
void macroDisplay()
Debug output for invalid macro Definitions.
int programInfo(QString &onPress, QString &onRelease) const
static const int MODE_NEXT
QString friendlyName(const KeyMap &map) const
static const int LIGHT_DOWN_WRAP
static const int DPI_DOWN
int indexOf(KbMode *mode) const
static const int LIGHT_UP_WRAP
KbAnim * findAnim(const QUuid &guid) const
static QString defaultAction(const QString &key, KeyMap::Model model)
void keyEvent(KbBind *bind, bool down)
static const int LIGHT_UP