-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathio_interface.c
More file actions
153 lines (134 loc) · 5.82 KB
/
io_interface.c
File metadata and controls
153 lines (134 loc) · 5.82 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* launcher-mobile: a multiplatform flexVDI/SPICE client
*
* Copyright (C) 2016 flexVDI (Flexible Software Solutions S.L.)
*
* This file is part of launcher-mobile.
*
* launcher-mobile 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.
*
* launcher-mobile 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 launcher-mobile. If not, see <http://www.gnu.org/licenses/>.
*/
#include <time.h>
#include <unistd.h>
#include "globals.h"
#include "io_interface.h"
#include "native.h"
#include "spice.h"
static int check_keyboard_widget(io_event_t* event_in)
{
float k_start_x;
float k_start_y;
int keyb_start_x;
int keyb_end_x;
int keyb_start_y;
int keyb_end_y;
if (global_state.content_scale == 2) {
k_start_x = (95 - (((48 * 100) / global_state.width) * 4.0)) / 100.0;
k_start_y = (((48 * 100) / global_state.height) / 40.0) + global_state.keyboard_offset;
} else {
k_start_x = (95 - (((48 * 100) / global_state.width) * 2.0)) / 100.0;
k_start_y = (((48 * 100) / global_state.height) / 80.0) + global_state.keyboard_offset;
}
keyb_start_x = (global_state.width / 2) + (global_state.width / 2 * k_start_x);
keyb_end_x = (global_state.width / 2) + (global_state.width / 2 * 0.95);
keyb_start_y = (global_state.height / 2) - (global_state.height / 2 * k_start_y);
keyb_end_y = (global_state.height / 2) + (global_state.height / 2 * k_start_y);
if (event_in->position[0] > keyb_start_x &&
event_in->position[0] < keyb_end_x &&
event_in->position[1] > keyb_start_y &&
event_in->position[1] < keyb_end_y) {
return 1;
}
return 0;
}
void IO_PushEvent(io_event_t* event_in){
struct timespec sleeptime;
double mouse_fix[2];
if (check_keyboard_widget(event_in)) {
if (event_in->button == 11) {
if (event_in->type == IO_EVENT_BEGAN) {
native_show_menu();
}
} else if (event_in->type == IO_EVENT_ENDED) {
native_show_keyboard();
}
return;
} else if (event_in->button == 11) {
event_in->button = 1;
}
if (global_state.zoom != 0.0) {
//double zoom_width = (global_state.width * (1 - global_state.zoom));
//double zoom_height = (global_state.height * (1 - global_state.zoom));
//double offset_x = global_state.width - zoom_width;
//double offset_y = global_state.height - zoom_height;
double offset_x = (global_state.width * global_state.zoom) +
(global_state.zoom_offset_x * global_state.width);
double offset_y = (global_state.height * global_state.zoom) -
(global_state.zoom_offset_y * global_state.height);
double ratio_x = (global_state.width - (global_state.width * global_state.zoom * 2)) / global_state.width;
double ratio_y = (global_state.height - (global_state.height * global_state.zoom * 2)) /global_state.height;
// mouse_fix[0] = (offset_x + (global_state.zoom_offset_x * zoom_width) + (event_in->position[0] * zoom_ratio_x));
// mouse_fix[1] = (offset_y - (global_state.zoom_offset_y * zoom_height) + (event_in->position[1] * zoom_ratio_y));
mouse_fix[0] = (event_in->position[0] * ratio_x) + offset_x;
mouse_fix[1] = (event_in->position[1] * ratio_y) + offset_y;
#if 0
printf("ratio_x=%f\n", ratio_x);
printf("ratio_y=%f\n", ratio_y);
printf("offset_x=%f\n", offset_x);
printf("offset_y=%f\n", offset_y);
printf("mouse_fix_x=%f\n", mouse_fix[0]);
printf("mouse_fix_y=%f\n", mouse_fix[1]);
#endif
// printf("zoom_max_ratio_x=%f\n", zoom_max_ratio_x);
// printf("zoom_max_ratio_y=%f\n", zoom_max_ratio_y);
} else if (global_state.main_offset != 0) {
float offset_y = global_state.height * (global_state.main_offset / 2);
mouse_fix[0] = event_in->position[0] * global_state.mouse_fix[0];
mouse_fix[1] = (event_in->position[1] * global_state.mouse_fix[1]) + offset_y;
} else {
mouse_fix[0] = event_in->position[0] * global_state.mouse_fix[0];
mouse_fix[1] = event_in->position[1] * global_state.mouse_fix[1];
}
#if 0
printf("global_state.width=%d\n", global_state.width);
printf("global_state.height=%d\n", global_state.height);
printf("global_state.guest_width=%d\n", global_state.guest_width);
printf("global_state.guest_height=%d\n", global_state.guest_height);
printf("event_in_x=%f\n", event_in->position[0]);
printf("event_in_y=%f\n", event_in->position[1]);
printf("mouse_fix_x=%f\n", mouse_fix[0]);
printf("mouse_fix_y=%f\n", mouse_fix[1]);
#endif
sleeptime.tv_sec = 0;
//sleeptime.tv_nsec = 500 * 1000;
sleeptime.tv_nsec = 50 * 1000 * 1000;
switch(event_in->type) {
case IO_EVENT_MOVED:
engine_spice_motion_event(mouse_fix[0], mouse_fix[1]);
break;
case IO_EVENT_BEGAN:
engine_spice_button_event(mouse_fix[0], mouse_fix[1], event_in->button, 1);
if (event_in->button == 1) {
nanosleep(&sleeptime, NULL);
}
//sleep(1);
break;
case IO_EVENT_ENDED:
engine_spice_button_event(mouse_fix[0], mouse_fix[1], event_in->button, 0);
if (event_in->button == 1) {
nanosleep(&sleeptime, NULL);
}
//sleep(1);
break;
}
}