2
* Compiz configuration system library plugin
4
* Copyright (C) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
COMPIZ_PLUGIN_20090315 (ccp, CcpPluginVTable)
25
#define CCP_UPDATE_MIN_TIMEOUT 250
26
#define CCP_UPDATE_MAX_TIMEOUT 4000
27
#define CORE_VTABLE_NAME "core"
32
ccpSetValueToValue (CCSSettingValue *sv,
39
v->set ((int) sv->value.asInt);
42
v->set ((float) sv->value.asFloat);
45
v->set ((bool) sv->value.asBool);
48
v->set ((unsigned short *) sv->value.asColor.array.array);
51
v->set (CompString (sv->value.asString));
54
v->set (CompMatch (sv->value.asMatch));
61
(sv->value.asKey.keysym == NoSymbol) ? 0 :
62
XKeysymToKeycode (screen->dpy (), sv->value.asKey.keysym);
64
action.setKey (CompAction::KeyBinding (keycode,
65
sv->value.asKey.keyModMask));
73
action.setEdgeMask (sv->value.asButton.edgeMask);
75
action.setButton (CompAction::ButtonBinding (
76
sv->value.asButton.button,
77
sv->value.asButton.buttonModMask));
85
action.setEdgeMask (sv->value.asEdge);
93
action.setBell (sv->value.asBell);
104
ccpCCSTypeToCompizType (CCSSettingType st, CompOption::Type *ct)
108
*ct = CompOption::TypeBool;
111
*ct = CompOption::TypeInt;
114
*ct = CompOption::TypeFloat;
117
*ct = CompOption::TypeColor;
120
*ct = CompOption::TypeString;
123
*ct = CompOption::TypeMatch;
126
*ct = CompOption::TypeKey;
129
*ct = CompOption::TypeButton;
132
*ct = CompOption::TypeEdge;
135
*ct = CompOption::TypeBell;
138
*ct = CompOption::TypeList;
148
ccpConvertPluginList (CCSSetting *s,
149
CCSSettingValueList list,
150
CompOption::Value *v)
155
sl = ccsGetStringListFromValueList (list);
157
while (ccsStringListFind(sl, (char *) "ccp"))
158
sl = ccsStringListRemove (sl, (char *) "ccp", TRUE);
160
while (ccsStringListFind(sl, (char *)"core"))
161
sl = ccsStringListRemove (sl, (char *) "core", TRUE);
163
sl = ccsStringListPrepend (sl, strdup ("ccp"));
164
sl = ccsStringListPrepend (sl, strdup ("core"));
166
CompOption::Value::Vector val (ccsStringListLength (sl));
168
for (l = sl, i = 0; l; l = l->next)
171
val[i].set (CompString (l->data));
175
v->set (CompOption::TypeString, val);
177
ccsStringListFree (sl, TRUE);
181
ccpSettingToValue (CCSSetting *s,
182
CompOption::Value *v)
184
if (s->type != TypeList)
185
ccpSetValueToValue (s->value, v, s->type);
188
CCSSettingValueList list;
190
CompOption::Type type;
192
ccsGetList (s, &list);
194
if (!ccpCCSTypeToCompizType (s->info.forList.listType, &type))
195
type = CompOption::TypeBool;
197
if ((strcmp (s->name, "active_plugins") == 0) &&
198
(strcmp (s->parent->name, CORE_VTABLE_NAME) == 0))
200
ccpConvertPluginList (s, list, v);
204
CompOption::Value::Vector val (ccsSettingValueListLength (list));
208
ccpSetValueToValue (list->data,
210
s->info.forList.listType);
221
ccpInitValue (CCSSettingValue *value,
222
CompOption::Value *from,
228
value->value.asInt = from->i ();
231
value->value.asFloat = from->f ();
234
value->value.asBool = from->b ();
238
for (unsigned int i = 0; i < 4; i++)
239
value->value.asColor.array.array[i] = from->c ()[i];
243
value->value.asString = strdup (from->s ().c_str ());
246
value->value.asMatch = strdup (from->match ().toString ().c_str ());
249
if (from->action ().type () & CompAction::BindingTypeKey)
251
value->value.asKey.keysym =
252
XKeycodeToKeysym (screen->dpy (),
253
from->action ().key ().keycode (), 0);
254
value->value.asKey.keyModMask =
255
from->action ().key ().modifiers ();
259
value->value.asKey.keysym = 0;
260
value->value.asKey.keyModMask = 0;
263
if (from->action ().type () & CompAction::BindingTypeButton)
265
value->value.asButton.button =
266
from->action ().button ().button ();
267
value->value.asButton.buttonModMask =
268
from->action ().button ().modifiers ();
269
value->value.asButton.edgeMask = 0;
271
else if (from->action ().type () & CompAction::BindingTypeEdgeButton)
273
value->value.asButton.button =
274
from->action ().button ().button ();
275
value->value.asButton.buttonModMask =
276
from->action ().button ().modifiers ();
277
value->value.asButton.edgeMask = from->action ().edgeMask ();
281
value->value.asButton.button = 0;
282
value->value.asButton.buttonModMask = 0;
283
value->value.asButton.edgeMask = 0;
287
value->value.asEdge = from->action ().edgeMask ();
290
value->value.asBell = from->action ().bell ();
298
ccpValueToSetting (CCSSetting *s,
299
CompOption::Value *v)
301
CCSSettingValue *value;
303
value = (CCSSettingValue *) calloc (1, sizeof (CCSSettingValue));
309
if (s->type == TypeList)
311
foreach (CompOption::Value &lv, v->list ())
313
CCSSettingValue *val;
315
val = (CCSSettingValue *) calloc (1, sizeof (CCSSettingValue));
319
val->isListChild = TRUE;
320
ccpInitValue (val, &lv,
321
s->info.forList.listType);
322
value->value.asList =
323
ccsSettingValueListAppend (value->value.asList, val);
328
ccpInitValue (value, v, s->type);
330
ccsSetValue (s, value);
331
ccsFreeSettingValue (value);
335
ccpTypeCheck (CCSSetting *s, CompOption *o)
342
return ccpCCSTypeToCompizType (s->type, &ot) && (ot == o->type ()) &&
343
ccpCCSTypeToCompizType (s->info.forList.listType, &ot) &&
344
(ot == o->value ().listType ());
347
return ccpCCSTypeToCompizType (s->type, &ot) && (ot == o->type ());
355
CcpScreen::setOptionFromContext (CompOption *o,
360
CompOption::Value value;
362
bsp = ccsFindPlugin (mContext, (plugin) ? plugin : CORE_VTABLE_NAME);
366
setting = ccsFindSetting (bsp, o->name ().c_str ());
370
if (!ccpTypeCheck (setting, o))
373
ccpSettingToValue (setting, &value);
375
mApplyingSettings = true;
376
screen->setOptionForPlugin (plugin, o->name ().c_str (), value);
377
mApplyingSettings = false;
381
CcpScreen::setContextFromOption (CompOption *o, const char *plugin)
386
bsp = ccsFindPlugin (mContext, (plugin) ? plugin : CORE_VTABLE_NAME);
390
setting = ccsFindSetting (bsp, o->name ().c_str ());
394
if (!ccpTypeCheck (setting, o))
397
ccpValueToSetting (setting, &o->value ());
398
ccsWriteChangedSettings (mContext);
404
foreach (CompPlugin *p, CompPlugin::getPlugins ())
406
foreach (CompOption &o, p->vTable->getOptions ())
407
setOptionFromContext (&o, p->vTable->name ().c_str ());
414
CcpScreen::timeout ()
416
unsigned int flags = 0;
418
if (CompPlugin::find ("glib"))
419
flags |= ProcessEventsNoGlibMainLoopMask;
421
ccsProcessEvents (mContext, flags);
423
if (ccsSettingListLength (mContext->changedSettings))
425
CCSSettingList list = mContext->changedSettings;
426
CCSSettingList l = list;
431
mContext->changedSettings = NULL;
433
fprintf (stderr, "looping list\n");
440
p = CompPlugin::find (s->parent->name);
445
o = CompOption::findOption (p->vTable->getOptions (), s->name);
447
setOptionFromContext (o, s->parent->name);
448
D (D_FULL, "Setting Update \"%s\"\n", s->name);
451
ccsSettingListFree (list, FALSE);
452
mContext->changedSettings =
453
ccsSettingListFree (mContext->changedSettings, FALSE);
460
CcpScreen::setOptionForPlugin (const char *plugin,
462
CompOption::Value &v)
466
status = screen->setOptionForPlugin (plugin, name, v);
468
if (status && !mApplyingSettings && !mReloadTimer.active ())
472
p = CompPlugin::find (plugin);
477
o = CompOption::findOption (p->vTable->getOptions (), name);
478
if (o && (o->value () != v))
479
setContextFromOption (o, p->vTable->name ().c_str ());
487
CcpScreen::initPluginForScreen (CompPlugin *p)
491
status = screen->initPluginForScreen (p);
495
foreach (CompOption &opt, p->vTable->getOptions ())
496
setOptionFromContext (&opt, p->vTable->name ().c_str ());
503
CcpScreen::CcpScreen (CompScreen *screen) :
504
PluginClassHandler<CcpScreen,CompScreen> (screen),
505
mApplyingSettings (false)
507
ccsSetBasicMetadata (TRUE);
509
mContext = ccsContextNew (screen->screenNum ());
510
ccsReadSettings (mContext);
512
mContext->changedSettings =
513
ccsSettingListFree (mContext->changedSettings, FALSE);
515
mReloadTimer.start (boost::bind (&CcpScreen::reload, this), 0);
516
mTimeoutTimer.start (boost::bind (&CcpScreen::timeout, this),
517
CCP_UPDATE_MIN_TIMEOUT, CCP_UPDATE_MAX_TIMEOUT);
519
ScreenInterface::setHandler (screen);
522
CcpScreen::~CcpScreen ()
524
ccsContextDestroy (mContext);
528
CcpPluginVTable::init ()
530
fprintf (stderr, "plugin init\n");
532
if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))