summaryrefslogtreecommitdiff
path: root/client/cursor.h
blob: cc64c7205146381a28af168ae896d75cb80ada1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
   Copyright (C) 2009 Red Hat, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This program 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.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _H_CURSOR_
#define _H_CURSOR_

#include "threads.h"
#include "red.h"
#include "red_window_p.h"

class CursorOpaque {
public:
    CursorOpaque() {}
    virtual ~CursorOpaque() {}
};

class LocalCursor;

class CursorData {
public:
    CursorData(SpiceCursor& cursor, int data_size);

    CursorData *ref() { ++_atomic; return this;}
    void unref() {if (--_atomic == 0) delete this;}
    void set_opaque(CursorOpaque* opaque) { delete _opaque; _opaque = opaque;}
    CursorOpaque* get_opaque() { return _opaque;}
    void set_local(LocalCursor* local_cursor);
    LocalCursor* get_local() { return _local_cursor;}
    const SpiceCursorHeader& header() const { return _header;}
    const uint8_t* data() const { return _data;}

private:
    ~CursorData();

private:
    AtomicCount _atomic;
    SpiceCursorHeader _header;
    uint8_t* _data;
    CursorOpaque* _opaque;
    LocalCursor* _local_cursor;
};

class LocalCursor {
public:
    LocalCursor(): _atomic (1) {}
    virtual ~LocalCursor() {}
    virtual void set(Window window) {}
    LocalCursor* ref() { ++_atomic; return this;}
    void unref() { if (--_atomic == 0) delete this;}

protected:
    static int get_size_bits(const SpiceCursorHeader& header, int &size);

private:
    AtomicCount _atomic;
};

#endif