36
36
namespace ca = compiz::actions;
42
{ "<Shift>", ShiftMask },
43
{ "<Control>", ControlMask },
44
{ "<Mod1>", Mod1Mask },
45
{ "<Mod2>", Mod2Mask },
46
{ "<Mod3>", Mod3Mask },
47
{ "<Mod4>", Mod4Mask },
48
{ "<Mod5>", Mod5Mask },
49
{ "<Alt>", CompAltMask },
50
{ "<Meta>", CompMetaMask },
44
{ "<Shift>", ShiftMask },
45
{ "<Control>", ControlMask },
46
{ "<Mod1>", Mod1Mask },
47
{ "<Mod2>", Mod2Mask },
48
{ "<Mod3>", Mod3Mask },
49
{ "<Mod4>", Mod4Mask },
50
{ "<Mod5>", Mod5Mask },
51
{ "<Alt>", CompAltMask },
52
{ "<Meta>", CompMetaMask },
51
53
{ "<Super>", CompSuperMask },
52
{ "<Hyper>", CompHyperMask },
54
{ "<Hyper>", CompHyperMask },
53
55
{ "<ModeSwitch>", CompModeSwitchMask }
56
58
#define N_MODIFIERS (sizeof (modifiers) / sizeof (struct _Modifier))
60
63
const char *modifierName;
62
{ "Left", "<LeftEdge>" },
63
{ "Right", "<RightEdge>" },
64
{ "Top", "<TopEdge>" },
65
{ "Bottom", "<BottomEdge>" },
66
{ "TopLeft", "<TopLeftEdge>" },
67
{ "TopRight", "<TopRightEdge>" },
68
{ "BottomLeft", "<BottomLeftEdge>" },
66
{ "Left", "<LeftEdge>" },
67
{ "Right", "<RightEdge>" },
68
{ "Top", "<TopEdge>" },
69
{ "Bottom", "<BottomEdge>" },
70
{ "TopLeft", "<TopLeftEdge>" },
71
{ "TopRight", "<TopRightEdge>" },
72
{ "BottomLeft", "<BottomLeftEdge>" },
69
73
{ "BottomRight", "<BottomRightEdge>" }
86
90
static unsigned int
87
stringToModifiers (CompString str)
91
stringToModifiers (const CompString &str)
89
93
unsigned int mods = 0;
91
for (unsigned int i = 0; i < N_MODIFIERS; i++)
95
for (unsigned int i = 0; i < N_MODIFIERS; ++i)
93
96
if (str.find (modifiers[i].name) != std::string::npos)
94
97
mods |= modifiers[i].modifier;
100
102
static unsigned int
101
bindingStringToEdgeMask (CompString str)
103
bindingStringToEdgeMask (CompString str)
103
105
unsigned int edgeMask = 0;
105
for (int i = 0; i < SCREEN_EDGE_NUM; i++)
107
for (int i = 0; i < SCREEN_EDGE_NUM; ++i)
106
108
if (str.find (edges[i].modifierName) != std::string::npos)
107
109
edgeMask |= 1 << i;
155
158
CompAction::KeyBinding::fromString (const CompString &str)
159
size_t pos, start = 0;
162
160
/* This assertion is a regression test for LP: #930412 */
167
mods = stringToModifiers (str);
169
pos = str.rfind ('>');
166
unsigned int mods = stringToModifiers (str);
169
size_t pos = str.rfind ('>');
170
171
if (pos != std::string::npos)
173
174
while (start < str.size () && !isalnum (str[start]))
176
177
if (start == str.size ())
218
220
CompAction::KeyBinding::toString () const
225
binding = modifiersToString (mModifiers);
225
CompString binding = modifiersToString (mModifiers);
227
227
if (mKeycode != 0)
232
keysym = XKeycodeToKeysym (screen->dpy (), mKeycode, 0);
233
keyname = XKeysymToString (keysym);
229
KeySym keysym = XKeycodeToKeysym (screen->dpy (), mKeycode, 0);
230
char *keyname = XKeysymToString (keysym);
236
233
binding += keyname;
275
272
CompAction::ButtonBinding::fromString (const CompString &str)
278
size_t pos, start = 0;
280
mods = stringToModifiers (str);
282
pos = str.rfind ('>');
274
unsigned int mods = stringToModifiers (str);
277
size_t pos = str.rfind ('>');
283
279
if (pos != std::string::npos)
286
282
while (start < str.size () && !isalnum (str[start]))
289
285
if (start != str.size () && str.compare (start, 6, "Button") == 0)
306
302
CompAction::ButtonBinding::toString () const
310
304
if (!mModifiers && !mButton)
313
binding = modifiersToString (mModifiers);
314
binding += compPrintf ("Button%d", mButton);
307
CompString binding = modifiersToString (mModifiers);
308
binding += compPrintf ("Button%d", mButton);
461
453
CompAction::operator== (const CompAction& val) const
463
if (priv->state != val.priv->state)
465
if (priv->type != val.priv->type)
467
if (priv->key.modifiers () != val.priv->key.modifiers ())
469
if (priv->key.keycode () != val.priv->key.keycode ())
471
if (priv->button.modifiers () != val.priv->button.modifiers ())
473
if (priv->button.button () != val.priv->button.button ())
475
if (priv->bell != val.priv->bell)
477
if (priv->edgeMask != val.priv->edgeMask)
479
if (memcmp (&priv->priv, &val.priv->priv, sizeof (CompPrivate)) != 0)
455
if (priv->state != val.priv->state ||
456
priv->type != val.priv->type ||
457
priv->key.modifiers () != val.priv->key.modifiers () ||
458
priv->key.keycode () != val.priv->key.keycode () ||
459
priv->button.modifiers () != val.priv->button.modifiers () ||
460
priv->button.button () != val.priv->button.button () ||
461
priv->bell != val.priv->bell ||
462
priv->edgeMask != val.priv->edgeMask ||
463
memcmp (&priv->priv, &val.priv->priv, sizeof (CompPrivate)) != 0)
583
568
CompAction::buttonToString ()
585
CompString binding, edge;
587
binding = modifiersToString (priv->button.modifiers ());
588
binding += edgeMaskToBindingString (priv->edgeMask);
590
binding += compPrintf ("Button%d", priv->button.button ());
572
CompString binding = modifiersToString (priv->button.modifiers ());
573
binding += edgeMaskToBindingString (priv->edgeMask);
574
binding += compPrintf ("Button%d", priv->button.button ());
592
576
if (!priv->button.button ())
593
577
return "Disabled";
637
620
ca::setActionActiveState (const CompAction &action,
640
623
action.priv->setActive (active);
643
626
PrivateAction::PrivateAction () :
654
637
memset (&priv, 0, sizeof (CompPrivate));
657
PrivateAction::PrivateAction (const PrivateAction& a) :
658
initiate (a.initiate),
640
PrivateAction::PrivateAction (const PrivateAction &a) :
641
initiate (a.initiate),
659
642
terminate (a.terminate),
665
edgeMask (a.edgeMask),
648
edgeMask (a.edgeMask),
668
651
memcpy (&priv, &a.priv, sizeof (CompPrivate));