~ubuntu-branches/ubuntu/natty/compiz-fusion-plugins-main/natty

« back to all changes in this revision

Viewing changes to src/mousepoll/mousepoll.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-10-19 12:07:20 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20101019120720-c3wffrxv7khh2ll8
Tags: 0.9.2.1-0ubuntu1
* New upstream release
* debian/control, debian/rules:
  - convert to cmake, remove autoconf, and convert to debhelper7
* debian/control:
  - bump compiz build-dep and deps to 0.9,
  - reintroduce coreabiversion trick to dep on the good package
* debian/install:
  - removed, seems we shipped all files anyway. Now install in the package
    directly
* debian/docs:
  - adapt to latest upstream shipped file
* debian/source:
  - switch to quilt format
* debian/patches/01-animation-defaults.patch,
  debian/patches/03_default_options.patch,
  debian/patches/06_bug326995.patch,
  debian/patches/08_disable_desktop_vpswitch.patch:
  - adapt to latest version
* debian/patches/02_fix_edges.patch:
  - removed for now: the plugin has been rewritten and have a different
    behavior
* debian/control:
  - remove compiz-fusion-bcop as a build-dep, now built in the core itself
* debian/rules:
  - add some switch to build in package mode, not in debug one

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 * Compiz mouse position polling plugin
4
 
 *
5
 
 * mousepoll.c
6
 
 *
7
 
 * Copyright : (C) 2008 by Dennis Kasprzyk
8
 
 * E-mail    : onestone@opencompositing.org
9
 
 *
10
 
 *
11
 
 * This program is free software; you can redistribute it and/or
12
 
 * modify it under the terms of the GNU General Public License
13
 
 * as published by the Free Software Foundation; either version 2
14
 
 * of the License, or (at your option) any later version.
15
 
 *
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU General Public License for more details.
20
 
 *
21
 
 */
22
 
 
23
 
#include <compiz-core.h>
24
 
 
25
 
#include "compiz-mousepoll.h"
26
 
 
27
 
static CompMetadata mousepollMetadata;
28
 
 
29
 
static int displayPrivateIndex;
30
 
static int functionsPrivateIndex;
31
 
 
32
 
typedef struct _MousepollClient MousepollClient;
33
 
 
34
 
struct _MousepollClient {
35
 
    MousepollClient *next;
36
 
    MousepollClient *prev;
37
 
 
38
 
    PositionPollingHandle id;
39
 
    PositionUpdateProc    update;
40
 
};
41
 
 
42
 
typedef enum _MousepollDisplayOptions
43
 
{
44
 
    MP_DISPLAY_OPTION_ABI,
45
 
    MP_DISPLAY_OPTION_INDEX,
46
 
    MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL,
47
 
    MP_DISPLAY_OPTION_NUM
48
 
} MousepollDisplayOptions;
49
 
 
50
 
typedef struct _MousepollDisplay {
51
 
    int screenPrivateIndex;
52
 
 
53
 
    CompOption opt[MP_DISPLAY_OPTION_NUM];
54
 
} MousepollDisplay;
55
 
 
56
 
typedef struct _MousepollScreen {
57
 
 
58
 
    MousepollClient       *clients;
59
 
    PositionPollingHandle freeId;
60
 
 
61
 
    CompTimeoutHandle updateHandle;
62
 
    int posX;
63
 
    int posY;
64
 
 
65
 
} MousepollScreen;
66
 
 
67
 
#define GET_MOUSEPOLL_DISPLAY(d)                                      \
68
 
    ((MousepollDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
69
 
 
70
 
#define MOUSEPOLL_DISPLAY(d)                       \
71
 
    MousepollDisplay *md = GET_MOUSEPOLL_DISPLAY (d)
72
 
 
73
 
#define GET_MOUSEPOLL_SCREEN(s, md)                                      \
74
 
    ((MousepollScreen *) (s)->base.privates[(md)->screenPrivateIndex].ptr)
75
 
 
76
 
#define MOUSEPOLL_SCREEN(s)                                                     \
77
 
    MousepollScreen *ms = GET_MOUSEPOLL_SCREEN (s, GET_MOUSEPOLL_DISPLAY (s->display))
78
 
 
79
 
#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
80
 
 
81
 
static Bool
82
 
getMousePosition (CompScreen *s)
83
 
{
84
 
    Window       root_return;
85
 
    Window       child_return;
86
 
    int          rootX, rootY;
87
 
    int          winX, winY;
88
 
    unsigned int maskReturn;
89
 
    Bool         status;
90
 
 
91
 
    MOUSEPOLL_SCREEN (s);
92
 
 
93
 
    status = XQueryPointer (s->display->display, s->root,
94
 
                            &root_return, &child_return,
95
 
                            &rootX, &rootY, &winX, &winY, &maskReturn);
96
 
 
97
 
    if (!status || rootX > s->width || rootY > s->height ||
98
 
        s->root != root_return)
99
 
        return FALSE;
100
 
 
101
 
    if ((rootX != ms->posX || rootY != ms->posY))
102
 
    {
103
 
        ms->posX = rootX;
104
 
        ms->posY = rootY;
105
 
        return TRUE;
106
 
    }
107
 
    return FALSE;
108
 
}
109
 
 
110
 
static Bool
111
 
updatePosition (void *c)
112
 
{
113
 
    CompScreen      *s = (CompScreen *)c;
114
 
    MousepollClient *mc;
115
 
 
116
 
    MOUSEPOLL_SCREEN (s);
117
 
 
118
 
    if (!ms->clients)
119
 
        return FALSE;
120
 
 
121
 
    if (getMousePosition (s))
122
 
    {
123
 
        MousepollClient *next;
124
 
        for (mc = ms->clients; mc; mc = next)
125
 
        {
126
 
            next = mc->next;
127
 
            if (mc->update)
128
 
                (*mc->update) (s, ms->posX, ms->posY);
129
 
        }
130
 
    }
131
 
 
132
 
    return TRUE;
133
 
}
134
 
 
135
 
static PositionPollingHandle
136
 
mousepollAddPositionPolling (CompScreen         *s,
137
 
                             PositionUpdateProc update)
138
 
{
139
 
    MOUSEPOLL_SCREEN  (s);
140
 
    MOUSEPOLL_DISPLAY (s->display);
141
 
 
142
 
    Bool start = FALSE;
143
 
 
144
 
    MousepollClient *mc = malloc (sizeof (MousepollClient));
145
 
 
146
 
    if (!mc)
147
 
        return -1;
148
 
 
149
 
    if (!ms->clients)
150
 
        start = TRUE;
151
 
 
152
 
    mc->update = update;
153
 
    mc->id     = ms->freeId;
154
 
    ms->freeId++;
155
 
 
156
 
    mc->prev = NULL;
157
 
    mc->next = ms->clients;
158
 
 
159
 
    if (ms->clients)
160
 
        ms->clients->prev = mc;
161
 
 
162
 
    ms->clients = mc;
163
 
 
164
 
    if (start)
165
 
    {
166
 
        getMousePosition (s);
167
 
        ms->updateHandle =
168
 
            compAddTimeout (
169
 
                md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i / 2,
170
 
                md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i,
171
 
                updatePosition, s);
172
 
    }
173
 
 
174
 
    return mc->id;
175
 
}
176
 
 
177
 
static void
178
 
mousepollRemovePositionPolling (CompScreen            *s,
179
 
                                PositionPollingHandle id)
180
 
{
181
 
    MOUSEPOLL_SCREEN (s);
182
 
 
183
 
    MousepollClient *mc = ms->clients;
184
 
 
185
 
    if (ms->clients && ms->clients->id == id)
186
 
    {
187
 
        ms->clients = ms->clients->next;
188
 
        if (ms->clients)
189
 
            ms->clients->prev = NULL;
190
 
 
191
 
        free (mc);
192
 
        return;
193
 
    }
194
 
 
195
 
    for (mc = ms->clients; mc; mc = mc->next)
196
 
        if (mc->id == id)
197
 
        {
198
 
            if (mc->next)
199
 
                mc->next->prev = mc->prev;
200
 
            if (mc->prev)
201
 
                mc->prev->next = mc->next;
202
 
            free (mc);
203
 
            return;
204
 
        }
205
 
 
206
 
    if (!ms->clients && ms->updateHandle)
207
 
    {
208
 
        compRemoveTimeout (ms->updateHandle);
209
 
        ms->updateHandle = 0;
210
 
    }
211
 
}
212
 
 
213
 
static void
214
 
mousepollGetCurrentPosition (CompScreen *s,
215
 
                             int        *x,
216
 
                             int        *y)
217
 
{
218
 
    MOUSEPOLL_SCREEN (s);
219
 
 
220
 
    if (!ms->clients)
221
 
        getMousePosition (s);
222
 
 
223
 
    if (x)
224
 
        *x = ms->posX;
225
 
    if (y)
226
 
        *y = ms->posY;
227
 
}
228
 
 
229
 
static const CompMetadataOptionInfo mousepollDisplayOptionInfo[] = {
230
 
    { "abi", "int", 0, 0, 0 },
231
 
    { "index", "int", 0, 0, 0 },
232
 
    { "mouse_poll_interval", "int", "<min>1</min><max>500</max><default>10</default>", 0, 0 }
233
 
};
234
 
 
235
 
static CompOption *
236
 
mousepollGetDisplayOptions (CompPlugin  *plugin,
237
 
                            CompDisplay *display,
238
 
                            int         *count)
239
 
{
240
 
    MOUSEPOLL_DISPLAY (display);
241
 
    *count = NUM_OPTIONS (md);
242
 
    return md->opt;
243
 
}
244
 
 
245
 
static Bool
246
 
mousepollSetDisplayOption (CompPlugin      *plugin,
247
 
                           CompDisplay     *display,
248
 
                           const char      *name,
249
 
                           CompOptionValue *value)
250
 
{
251
 
    CompOption      *o;
252
 
    CompScreen      *s;
253
 
    MousepollScreen *ms;
254
 
    int             index;
255
 
    Bool            status = FALSE;
256
 
    MOUSEPOLL_DISPLAY (display);
257
 
    o = compFindOption (md->opt, NUM_OPTIONS (md), name, &index);
258
 
    if (!o)
259
 
        return FALSE;
260
 
 
261
 
    switch (index) {
262
 
    case MP_DISPLAY_OPTION_ABI:
263
 
    case MP_DISPLAY_OPTION_INDEX:
264
 
        break;
265
 
    case MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL:
266
 
        status = compSetDisplayOption (display, o, value);
267
 
        for (s = display->screens; s; s = s->next)
268
 
        {
269
 
            ms = GET_MOUSEPOLL_SCREEN (s, md);
270
 
            if (ms->updateHandle)
271
 
            {
272
 
                compRemoveTimeout (ms->updateHandle);
273
 
                ms->updateHandle =
274
 
                    compAddTimeout (
275
 
                        md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i
276
 
                        / 2,
277
 
                        md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i,
278
 
                        updatePosition, s);
279
 
            }
280
 
        }
281
 
        return status;
282
 
        break;
283
 
    default:
284
 
        return compSetDisplayOption (display, o, value);
285
 
    }
286
 
 
287
 
    return FALSE;
288
 
}
289
 
 
290
 
static MousePollFunc mousepollFunctions =
291
 
{
292
 
    .addPositionPolling    = mousepollAddPositionPolling,
293
 
    .removePositionPolling = mousepollRemovePositionPolling,
294
 
    .getCurrentPosition    = mousepollGetCurrentPosition,
295
 
};
296
 
 
297
 
static Bool
298
 
mousepollInitDisplay (CompPlugin  *p,
299
 
                      CompDisplay *d)
300
 
{
301
 
    MousepollDisplay *md;
302
 
 
303
 
    if (!checkPluginABI ("core", CORE_ABIVERSION))
304
 
        return FALSE;
305
 
 
306
 
    md = malloc (sizeof (MousepollDisplay));
307
 
    if (!md)
308
 
        return FALSE;
309
 
    if (!compInitDisplayOptionsFromMetadata (d,
310
 
                                             &mousepollMetadata,
311
 
                                             mousepollDisplayOptionInfo,
312
 
                                             md->opt,
313
 
                                             MP_DISPLAY_OPTION_NUM))
314
 
    {
315
 
        free (md);
316
 
        return FALSE;
317
 
    }
318
 
 
319
 
    md->screenPrivateIndex = allocateScreenPrivateIndex (d);
320
 
    if (md->screenPrivateIndex < 0)
321
 
    {
322
 
        compFiniDisplayOptions (d, md->opt, MP_DISPLAY_OPTION_NUM);
323
 
        free (md);
324
 
        return FALSE;
325
 
    }
326
 
 
327
 
    md->opt[MP_DISPLAY_OPTION_ABI].value.i   = MOUSEPOLL_ABIVERSION;
328
 
    md->opt[MP_DISPLAY_OPTION_INDEX].value.i = functionsPrivateIndex;
329
 
 
330
 
    d->base.privates[displayPrivateIndex].ptr   = md;
331
 
    d->base.privates[functionsPrivateIndex].ptr = &mousepollFunctions;
332
 
    return TRUE;
333
 
}
334
 
 
335
 
static void
336
 
mousepollFiniDisplay (CompPlugin  *p,
337
 
                 CompDisplay *d)
338
 
{
339
 
    MOUSEPOLL_DISPLAY (d);
340
 
 
341
 
    compFiniDisplayOptions (d, md->opt, MP_DISPLAY_OPTION_NUM);
342
 
    free (md);
343
 
}
344
 
 
345
 
static Bool
346
 
mousepollInitScreen (CompPlugin *p,
347
 
                     CompScreen *s)
348
 
{
349
 
    MousepollScreen *ms;
350
 
 
351
 
    MOUSEPOLL_DISPLAY (s->display);
352
 
 
353
 
    ms = malloc (sizeof (MousepollScreen));
354
 
    if (!ms)
355
 
        return FALSE;
356
 
 
357
 
    ms->posX = 0;
358
 
    ms->posY = 0;
359
 
 
360
 
    ms->clients = NULL;
361
 
    ms->freeId  = 1;
362
 
    
363
 
    ms->updateHandle = 0;
364
 
 
365
 
    s->base.privates[md->screenPrivateIndex].ptr = ms;
366
 
    return TRUE;
367
 
}
368
 
 
369
 
static void
370
 
mousepollFiniScreen (CompPlugin *p,
371
 
                     CompScreen *s)
372
 
{
373
 
    MOUSEPOLL_SCREEN (s);
374
 
 
375
 
    if (ms->updateHandle)
376
 
        compRemoveTimeout (ms->updateHandle);
377
 
 
378
 
    free (ms);
379
 
}
380
 
 
381
 
static CompBool
382
 
mousepollInitObject (CompPlugin *p,
383
 
                     CompObject *o)
384
 
{
385
 
    static InitPluginObjectProc dispTab[] = {
386
 
        (InitPluginObjectProc) 0, /* InitCore */
387
 
        (InitPluginObjectProc) mousepollInitDisplay,
388
 
        (InitPluginObjectProc) mousepollInitScreen
389
 
    };
390
 
 
391
 
    RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
392
 
}
393
 
 
394
 
static void
395
 
mousepollFiniObject (CompPlugin *p,
396
 
                     CompObject *o)
397
 
{
398
 
    static FiniPluginObjectProc dispTab[] = {
399
 
        (FiniPluginObjectProc) 0, /* FiniCore */
400
 
        (FiniPluginObjectProc) mousepollFiniDisplay,
401
 
        (FiniPluginObjectProc) mousepollFiniScreen
402
 
    };
403
 
 
404
 
    DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
405
 
}
406
 
 
407
 
static Bool
408
 
mousepollInit (CompPlugin *p)
409
 
{
410
 
    if (!compInitPluginMetadataFromInfo (&mousepollMetadata,
411
 
                                         p->vTable->name,
412
 
                                         mousepollDisplayOptionInfo,
413
 
                                         MP_DISPLAY_OPTION_NUM,
414
 
                                         NULL, 0))
415
 
        return FALSE;
416
 
 
417
 
    displayPrivateIndex = allocateDisplayPrivateIndex ();
418
 
    if (displayPrivateIndex < 0)
419
 
    {
420
 
        compFiniMetadata (&mousepollMetadata);
421
 
        return FALSE;
422
 
    }
423
 
 
424
 
    functionsPrivateIndex = allocateDisplayPrivateIndex ();
425
 
    if (functionsPrivateIndex < 0)
426
 
    {
427
 
        freeDisplayPrivateIndex (displayPrivateIndex);
428
 
        compFiniMetadata (&mousepollMetadata);
429
 
        return FALSE;
430
 
    }
431
 
    
432
 
    compAddMetadataFromFile (&mousepollMetadata, p->vTable->name);
433
 
    return TRUE;
434
 
}
435
 
 
436
 
static CompOption *
437
 
mousepollGetObjectOptions (CompPlugin *plugin,
438
 
                           CompObject *object,
439
 
                           int        *count)
440
 
{
441
 
    static GetPluginObjectOptionsProc dispTab[] = {
442
 
        (GetPluginObjectOptionsProc) 0, /* GetCoreOptions */
443
 
        (GetPluginObjectOptionsProc) mousepollGetDisplayOptions
444
 
    };
445
 
 
446
 
    *count = 0;
447
 
    RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab),
448
 
                     NULL, (plugin, object, count));
449
 
}
450
 
 
451
 
static CompBool
452
 
mousepollSetObjectOption (CompPlugin      *plugin,
453
 
                          CompObject      *object,
454
 
                          const char      *name,
455
 
                          CompOptionValue *value)
456
 
{
457
 
    static SetPluginObjectOptionProc dispTab[] = {
458
 
        (SetPluginObjectOptionProc) 0, /* SetCoreOption */
459
 
        (SetPluginObjectOptionProc) mousepollSetDisplayOption
460
 
    };
461
 
 
462
 
    RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), FALSE,
463
 
                     (plugin, object, name, value));
464
 
}
465
 
 
466
 
static void
467
 
mousepollFini (CompPlugin *p)
468
 
{
469
 
    freeDisplayPrivateIndex (displayPrivateIndex);
470
 
    freeDisplayPrivateIndex (functionsPrivateIndex);
471
 
    compFiniMetadata (&mousepollMetadata);
472
 
}
473
 
 
474
 
static CompMetadata *
475
 
mousepollGetMetadata (CompPlugin *plugin)
476
 
{
477
 
    return &mousepollMetadata;
478
 
}
479
 
 
480
 
CompPluginVTable mousepollVTable = {
481
 
    "mousepoll",
482
 
    mousepollGetMetadata,
483
 
    mousepollInit,
484
 
    mousepollFini,
485
 
    mousepollInitObject,
486
 
    mousepollFiniObject,
487
 
    mousepollGetObjectOptions,
488
 
    mousepollSetObjectOption
489
 
};
490
 
 
491
 
CompPluginVTable *
492
 
getCompPluginInfo20070830 (void)
493
 
{
494
 
    return &mousepollVTable;
495
 
}