Subversion Repositories shark

Rev

Rev 966 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   Mauro Marinoni      <mauro.marinoni@unipv.it>
13
 *   (see the web pages for full authors list)
14
 *
15
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
16
 *
17
 * http://www.sssup.it
18
 * http://retis.sssup.it
19
 * http://shark.sssup.it
20
 */
21
 
22
/*
23
 *
24
 * Auto Pointer management
25
 *
26
 */
27
 
28
#include <kernel/kern.h>
1034 mauro 29
#include <kernel/int_sem.h>
538 mauro 30
 
31
#include "../include/drivers/shark_input26.h"
32
#include "../include/drivers/shark_mouse26.h"
33
 
34
//#define CURTXT_DEBUG
35
 
36
/* these variables are managed by this module but MUST be declared
37
 * into shark_mouse.c to prevent implicit inclusion of this module
38
 * when a user link the mouse library
39
 */
40
extern MOUSE_HANDLER show_mouse_handler;
41
extern MOUSE_HANDLER user_mouse_handler;
42
 
43
/* a mutex semaphore */
1034 mauro 44
static int mcur_mutex_init = 0;
45
static internal_sem_t mutex;
538 mauro 46
 
47
/* Setup function */
48
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int));
49
 
50
/*
51
 *
52
 * autocursor mouse handler
53
 *
54
 */
55
 
56
/* >=0 hide cursor; <0 show cursor */
57
static int mouse_cursor_state = 0;
58
 
59
/* mouse status */
549 mauro 60
int autocursormode = 0;
538 mauro 61
 
62
/* saved mouse_position */
63
static int  saved_x, saved_y;
64
 
65
static void dummy(int x,int y){}
66
 
67
static void (*show_cursor)(int x, int y) = dummy;
68
static void (*restore_cursor)(int x, int y) = dummy;
69
 
70
/* those are the 4 mouse handlers */
71
/* AUTOOFF    -> call the user handler with no mouse displayed */
72
/* WITHOUTSEM -> does not use a mutex semaphore */
73
 
74
/* with no flags */
75
static void autocursor_mouse_handler_1(MOUSE_EVT *event)
76
{
77
#ifdef CURTXT_DEBUG
78
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_1\n");
79
#endif
80
 
81
        if (user_mouse_handler != NULL)
82
                user_mouse_handler(event);
83
 
1034 mauro 84
        internal_sem_wait(&mutex);
538 mauro 85
        if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) {
86
                restore_cursor(saved_x, saved_y);
87
                saved_x = event->x;
88
                saved_y = event->y;
89
                show_cursor(saved_x, saved_y);
90
        }
1034 mauro 91
        internal_sem_post(&mutex);
538 mauro 92
}
93
 
94
/* with WITHOUTSEM flag*/
95
static void autocursor_mouse_handler_2(MOUSE_EVT *event)
96
{
97
#ifdef CURTXT_DEBUG
98
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_2\n");
99
#endif
100
        if (user_mouse_handler != NULL)
101
                user_mouse_handler(event);
102
 
103
        if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) {
104
                restore_cursor(saved_x, saved_y);
105
                saved_x = event->x;
106
                saved_y = event->y;
107
                show_cursor(saved_x, saved_y);
108
        }
109
}
110
 
111
/* with AUTOOFF flag*/
112
static void autocursor_mouse_handler_3(MOUSE_EVT *event)
113
{
114
#ifdef CURTXT_DEBUG
115
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_3\n");
116
#endif
1034 mauro 117
        internal_sem_wait(&mutex);
538 mauro 118
 
119
        if (mouse_cursor_state < 0) {
120
                restore_cursor(saved_x, saved_y);
121
                saved_x = event->x;
122
                saved_y = event->y;
123
                if (user_mouse_handler != NULL)
124
                        user_mouse_handler(event);      
125
                show_cursor(saved_x, saved_y);
126
        } else if (user_mouse_handler != NULL)
127
                user_mouse_handler(event);
128
 
1034 mauro 129
        internal_sem_post(&mutex);
538 mauro 130
}
131
 
132
/* with WITHOUTSEM & AUTOOFF flags */
133
static void autocursor_mouse_handler_4(MOUSE_EVT *event)
134
{
135
#ifdef CURTXT_DEBUG
136
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_4\n");
137
#endif
138
        if (mouse_cursor_state < 0) {
139
                restore_cursor(saved_x, saved_y);
140
                saved_x = event->x;
141
                saved_y = event->y;
142
                if (user_mouse_handler != NULL)
143
                        user_mouse_handler(event);      
144
                show_cursor(saved_x, saved_y);
145
        } else if (user_mouse_handler != NULL)
146
                user_mouse_handler(event);
147
}
148
 
149
/* --------------
150
 * TXT management
151
 * --------------
152
 */
153
 
154
/* text cursor shape */
155
#define DEFAULTTXTSHAPE 0x7700ffff
156
static DWORD saved_txtshape = DEFAULTTXTSHAPE;
157
static BYTE attr_andmask, attr_xormask;
158
static BYTE c_andmask, c_xormask;
159
 
160
/* saved values */
161
static BYTE saved_attr, saved_c;
162
 
163
/* show txt cursor */
164
void show_txt_cursor(int x, int y)
165
{
166
        int attr,c;
167
 
168
        getc_xy(x, y, &saved_attr, &saved_c);
169
        attr = (saved_attr & attr_andmask) ^ attr_xormask;
170
        c = (saved_c & c_andmask) ^ c_xormask;
171
        putc_xy(x, y, attr, c);
172
}
173
 
174
/* restore txt cursor */
175
static void restore_txt_cursor(int x, int y)
176
{
177
        putc_xy(x, y, saved_attr, saved_c);
178
}
179
 
180
/* define text shape */
181
int mouse_txtshape(DWORD img)
182
{
183
        int cond;
184
 
185
        if (img == DEFAULT)
186
                img = DEFAULTTXTSHAPE;
187
 
188
        cond = ( (autocursormode & STATUSMASK) == ENABLE && (autocursormode & TXTCURSOR) == TXTCURSOR );
189
 
190
        if (cond)
191
                restore_txt_cursor(saved_x, saved_y);
192
 
193
        saved_txtshape = img;
194
        c_andmask = img & 0xff;
195
        attr_andmask = (img & 0xff00) >> 8;
196
        c_xormask = (img & 0xff0000) >> 16;
197
        attr_xormask = (img & 0xff000000) >> 24;
198
 
199
#ifdef CURTXT_DEBUG
200
        printk(KERN_DEBUG "MouseTxt_Shape: %x %x %x %x\n", c_andmask, attr_andmask, c_xormask, attr_xormask);
201
#endif
202
        if (cond)
203
                show_txt_cursor(saved_x, saved_y);
204
 
205
        return 0;
206
}
207
 
208
/*
209
 * User interface to autocursor functions
210
 */
211
 
212
/* display the cursor */
213
#define MOUSE_ON() { \
214
        int unused; \
215
        unsigned long lunused; \
216
        mouse_cursor_state--; \
217
        if (mouse_cursor_state == -1) { \
549 mauro 218
                mouse_getposition(&saved_x, &saved_y, &unused, &lunused); \
538 mauro 219
                show_cursor(saved_x, saved_y); \
220
        } \
221
}
222
 
223
static void mouse_on_sem(void)
224
{
1034 mauro 225
        internal_sem_wait(&mutex);
538 mauro 226
        MOUSE_ON();
1034 mauro 227
        internal_sem_post(&mutex);
538 mauro 228
}
229
 
230
static void mouse_on_nosem(void)
231
{
232
        MOUSE_ON();
233
}
234
 
235
void (*mouse_on)(void)=mouse_on_nosem;
236
 
237
/* hide the cursor */
238
#define MOUSE_OFF() { \
239
        mouse_cursor_state++; \
240
        if (mouse_cursor_state == 0) \
241
                restore_cursor(saved_x, saved_y); \
242
}
243
 
244
void mouse_off_sem(void)
245
{
1034 mauro 246
        internal_sem_wait(&mutex);
538 mauro 247
        MOUSE_OFF();
1034 mauro 248
        internal_sem_post(&mutex);
538 mauro 249
}
250
 
251
void mouse_off_nosem(void)
252
{
253
        MOUSE_OFF();
254
}
255
 
256
void (*mouse_off)(void) = mouse_off_nosem;
257
 
258
static MOUSE_HANDLER wich_handler(int cmd)
259
{
260
        if ( ((cmd & WITHOUTSEM) == WITHOUTSEM) && ((cmd & AUTOOFF) == AUTOOFF) )
261
                return autocursor_mouse_handler_4;
262
        if ((cmd & WITHOUTSEM) == WITHOUTSEM)
263
                return autocursor_mouse_handler_2;
264
        if ((cmd & AUTOOFF) == AUTOOFF)
265
                return autocursor_mouse_handler_3;
266
        return autocursor_mouse_handler_1;
267
}
268
 
269
int mouse_txtcursor(int cmd)
270
{
271
        mouse_txtshape(saved_txtshape);  
272
        return _mouse_cursor_init(cmd|TXTCURSOR, show_txt_cursor, restore_txt_cursor);
273
}
274
 
275
/* Generic functions, both for text & graphics mode */
276
 
277
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int))
278
{
1034 mauro 279
        if (mcur_mutex_init == 0) {
280
                internal_sem_init(&mutex, 1);
281
                mcur_mutex_init = 1;
538 mauro 282
        }
283
 
284
#ifdef CURTXT_DEBUG
285
        printk(KERN_DEBUG "mouse_cursor_init: command %x\n", cmd);
286
#endif
287
 
288
        switch (cmd & STATUSMASK) {
289
                case DISABLE:
290
                        //show_mouse_handler = user_mouse_handler;
291
                        show_mouse_handler = NULL;
292
                        restore_cursor(saved_x, saved_y);
293
                        show_cursor = dummy;
294
                        restore_cursor = dummy;
295
                        mouse_cursor_state = 0;
296
                        break;
297
                case ENABLE:
298
                        restore_cursor(saved_x, saved_y);
299
                        restore_cursor = my_restore_cursor;
300
                        show_cursor = my_show_cursor;      
301
                        if ((autocursormode & STATUSMASK) == DISABLE) {
302
                                //user_mouse_handler = show_mouse_handler;
303
                                show_mouse_handler = wich_handler(cmd);
304
                        }
305
                        mouse_cursor_state = -1;
306
                        break;
307
                default:
308
                        return -1;
309
        }  
310
 
311
        autocursormode = cmd;
312
 
313
        if ((autocursormode & STATUSMASK) == ENABLE) {
314
                if ((cmd & WITHOUTSEM) == WITHOUTSEM) {
315
                        mouse_on = mouse_on_nosem;
316
                        mouse_off = mouse_off_nosem;
317
                } else {
318
                        mouse_on = mouse_on_sem;
319
                        mouse_off = mouse_off_sem;
320
                }
321
        }
322
 
323
        return 0;
324
}
325
 
326
void _mouse_cursor_getposition(int *xptr, int *yptr)
327
{
328
        *xptr = saved_x;
329
        *yptr = saved_y;
330
}