cursor.js
3.84 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"use strict";
/*
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
This file is part of spice-html5.
spice-html5 is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
spice-html5 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
*/
/*----------------------------------------------------------------------------
** SpiceCursorConn
** Drive the Spice Cursor Channel
**--------------------------------------------------------------------------*/
function SpiceCursorConn()
{
SpiceConn.apply(this, arguments);
}
SpiceCursorConn.prototype = Object.create(SpiceConn.prototype);
SpiceCursorConn.prototype.process_channel_message = function(msg)
{
if (msg.type == SPICE_MSG_CURSOR_INIT)
{
var cursor_init = new SpiceMsgCursorInit(msg.data);
DEBUG > 1 && console.log("SpiceMsgCursorInit");
if (this.parent && this.parent.inputs &&
this.parent.inputs.mouse_mode == SPICE_MOUSE_MODE_SERVER)
{
// FIXME - this imagines that the server actually
// provides the current cursor position,
// instead of 0,0. As of May 11, 2012,
// that assumption was false :-(.
this.parent.inputs.mousex = cursor_init.position.x;
this.parent.inputs.mousey = cursor_init.position.y;
}
// FIXME - We don't handle most of the parameters here...
return true;
}
if (msg.type == SPICE_MSG_CURSOR_SET)
{
var cursor_set = new SpiceMsgCursorSet(msg.data);
DEBUG > 1 && console.log("SpiceMsgCursorSet");
if (cursor_set.flags & SPICE_CURSOR_FLAGS_NONE)
{
document.getElementById(this.parent.screen_id).style.cursor = "none";
return true;
}
if (cursor_set.flags > 0)
this.log_warn("FIXME: No support for cursor flags " + cursor_set.flags);
if (cursor_set.cursor.header.type != SPICE_CURSOR_TYPE_ALPHA)
{
this.log_warn("FIXME: No support for cursor type " + cursor_set.cursor.header.type);
return false;
}
this.set_cursor(cursor_set.cursor);
return true;
}
if (msg.type == SPICE_MSG_CURSOR_HIDE)
{
DEBUG > 1 && console.log("SpiceMsgCursorHide");
document.getElementById(this.parent.screen_id).style.cursor = "none";
return true;
}
if (msg.type == SPICE_MSG_CURSOR_RESET)
{
DEBUG > 1 && console.log("SpiceMsgCursorReset");
document.getElementById(this.parent.screen_id).style.cursor = "auto";
return true;
}
if (msg.type == SPICE_MSG_CURSOR_INVAL_ALL)
{
DEBUG > 1 && console.log("SpiceMsgCursorInvalAll");
// FIXME - There may be something useful to do here...
return true;
}
return false;
}
SpiceCursorConn.prototype.set_cursor = function(cursor)
{
var pngstr = create_rgba_png(cursor.header.height, cursor.header.width, cursor.data);
var curstr = 'url(data:image/png,' + pngstr + ') ' +
cursor.header.hot_spot_x + ' ' + cursor.header.hot_spot_y + ", default";
var screen = document.getElementById(this.parent.screen_id);
screen.style.cursor = 'auto';
screen.style.cursor = curstr;
if (window.getComputedStyle(screen, null).cursor == 'auto')
SpiceSimulateCursor.simulate_cursor(this, cursor, screen, pngstr);
}