Subversion Repositories shark

Rev

Rev 1034 | 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
/*
1063 tullio 23
 * This program is free software; you can redistribute it and/or modify
24
 * it under the terms of the GNU General Public License as published by
25
 * the Free Software Foundation; either version 2 of the License, or
26
 * (at your option) any later version.
538 mauro 27
 *
1063 tullio 28
 * This program is distributed in the hope that it will be useful,
29
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 * GNU General Public License for more details.
32
 *
33
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, write to the Free Software
35
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
36
 *
37
 */
38
 
39
/*
40
 *
538 mauro 41
 * Auto Pointer management
42
 *
43
 */
44
 
45
#include <kernel/kern.h>
1034 mauro 46
#include <kernel/int_sem.h>
538 mauro 47
 
48
#include "../include/drivers/shark_input26.h"
49
#include "../include/drivers/shark_mouse26.h"
50
 
51
//#define CURTXT_DEBUG
52
 
53
/* these variables are managed by this module but MUST be declared
54
 * into shark_mouse.c to prevent implicit inclusion of this module
55
 * when a user link the mouse library
56
 */
57
extern MOUSE_HANDLER show_mouse_handler;
58
extern MOUSE_HANDLER user_mouse_handler;
59
 
60
/* a mutex semaphore */
1034 mauro 61
static int mcur_mutex_init = 0;
62
static internal_sem_t mutex;
538 mauro 63
 
64
/* Setup function */
65
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int));
66
 
67
/*
68
 *
69
 * autocursor mouse handler
70
 *
71
 */
72
 
73
/* >=0 hide cursor; <0 show cursor */
74
static int mouse_cursor_state = 0;
75
 
76
/* mouse status */
549 mauro 77
int autocursormode = 0;
538 mauro 78
 
79
/* saved mouse_position */
80
static int  saved_x, saved_y;
81
 
82
static void dummy(int x,int y){}
83
 
84
static void (*show_cursor)(int x, int y) = dummy;
85
static void (*restore_cursor)(int x, int y) = dummy;
86
 
87
/* those are the 4 mouse handlers */
88
/* AUTOOFF    -> call the user handler with no mouse displayed */
89
/* WITHOUTSEM -> does not use a mutex semaphore */
90
 
91
/* with no flags */
92
static void autocursor_mouse_handler_1(MOUSE_EVT *event)
93
{
94
#ifdef CURTXT_DEBUG
95
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_1\n");
96
#endif
97
 
98
        if (user_mouse_handler != NULL)
99
                user_mouse_handler(event);
100
 
1034 mauro 101
        internal_sem_wait(&mutex);
538 mauro 102
        if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) {
103
                restore_cursor(saved_x, saved_y);
104
                saved_x = event->x;
105
                saved_y = event->y;
106
                show_cursor(saved_x, saved_y);
107
        }
1034 mauro 108
        internal_sem_post(&mutex);
538 mauro 109
}
110
 
111
/* with WITHOUTSEM flag*/
112
static void autocursor_mouse_handler_2(MOUSE_EVT *event)
113
{
114
#ifdef CURTXT_DEBUG
115
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_2\n");
116
#endif
117
        if (user_mouse_handler != NULL)
118
                user_mouse_handler(event);
119
 
120
        if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) {
121
                restore_cursor(saved_x, saved_y);
122
                saved_x = event->x;
123
                saved_y = event->y;
124
                show_cursor(saved_x, saved_y);
125
        }
126
}
127
 
128
/* with AUTOOFF flag*/
129
static void autocursor_mouse_handler_3(MOUSE_EVT *event)
130
{
131
#ifdef CURTXT_DEBUG
132
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_3\n");
133
#endif
1034 mauro 134
        internal_sem_wait(&mutex);
538 mauro 135
 
136
        if (mouse_cursor_state < 0) {
137
                restore_cursor(saved_x, saved_y);
138
                saved_x = event->x;
139
                saved_y = event->y;
140
                if (user_mouse_handler != NULL)
141
                        user_mouse_handler(event);      
142
                show_cursor(saved_x, saved_y);
143
        } else if (user_mouse_handler != NULL)
144
                user_mouse_handler(event);
145
 
1034 mauro 146
        internal_sem_post(&mutex);
538 mauro 147
}
148
 
149
/* with WITHOUTSEM & AUTOOFF flags */
150
static void autocursor_mouse_handler_4(MOUSE_EVT *event)
151
{
152
#ifdef CURTXT_DEBUG
153
        printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_4\n");
154
#endif
155
        if (mouse_cursor_state < 0) {
156
                restore_cursor(saved_x, saved_y);
157
                saved_x = event->x;
158
                saved_y = event->y;
159
                if (user_mouse_handler != NULL)
160
                        user_mouse_handler(event);      
161
                show_cursor(saved_x, saved_y);
162
        } else if (user_mouse_handler != NULL)
163
                user_mouse_handler(event);
164
}
165
 
166
/* --------------
167
 * TXT management
168
 * --------------
169
 */
170
 
171
/* text cursor shape */
172
#define DEFAULTTXTSHAPE 0x7700ffff
173
static DWORD saved_txtshape = DEFAULTTXTSHAPE;
174
static BYTE attr_andmask, attr_xormask;
175
static BYTE c_andmask, c_xormask;
176
 
177
/* saved values */
178
static BYTE saved_attr, saved_c;
179
 
180
/* show txt cursor */
181
void show_txt_cursor(int x, int y)
182
{
183
        int attr,c;
184
 
185
        getc_xy(x, y, &saved_attr, &saved_c);
186
        attr = (saved_attr & attr_andmask) ^ attr_xormask;
187
        c = (saved_c & c_andmask) ^ c_xormask;
188
        putc_xy(x, y, attr, c);
189
}
190
 
191
/* restore txt cursor */
192
static void restore_txt_cursor(int x, int y)
193
{
194
        putc_xy(x, y, saved_attr, saved_c);
195
}
196
 
197
/* define text shape */
198
int mouse_txtshape(DWORD img)
199
{
200
        int cond;
201
 
202
        if (img == DEFAULT)
203
                img = DEFAULTTXTSHAPE;
204
 
205
        cond = ( (autocursormode & STATUSMASK) == ENABLE && (autocursormode & TXTCURSOR) == TXTCURSOR );
206
 
207
        if (cond)
208
                restore_txt_cursor(saved_x, saved_y);
209
 
210
        saved_txtshape = img;
211
        c_andmask = img & 0xff;
212
        attr_andmask = (img & 0xff00) >> 8;
213
        c_xormask = (img & 0xff0000) >> 16;
214
        attr_xormask = (img & 0xff000000) >> 24;
215
 
216
#ifdef CURTXT_DEBUG
217
        printk(KERN_DEBUG "MouseTxt_Shape: %x %x %x %x\n", c_andmask, attr_andmask, c_xormask, attr_xormask);
218
#endif
219
        if (cond)
220
                show_txt_cursor(saved_x, saved_y);
221
 
222
        return 0;
223
}
224
 
225
/*
226
 * User interface to autocursor functions
227
 */
228
 
229
/* display the cursor */
230
#define MOUSE_ON() { \
231
        int unused; \
232
        unsigned long lunused; \
233
        mouse_cursor_state--; \
234
        if (mouse_cursor_state == -1) { \
549 mauro 235
                mouse_getposition(&saved_x, &saved_y, &unused, &lunused); \
538 mauro 236
                show_cursor(saved_x, saved_y); \
237
        } \
238
}
239
 
240
static void mouse_on_sem(void)
241
{
1034 mauro 242
        internal_sem_wait(&mutex);
538 mauro 243
        MOUSE_ON();
1034 mauro 244
        internal_sem_post(&mutex);
538 mauro 245
}
246
 
247
static void mouse_on_nosem(void)
248
{
249
        MOUSE_ON();
250
}
251
 
252
void (*mouse_on)(void)=mouse_on_nosem;
253
 
254
/* hide the cursor */
255
#define MOUSE_OFF() { \
256
        mouse_cursor_state++; \
257
        if (mouse_cursor_state == 0) \
258
                restore_cursor(saved_x, saved_y); \
259
}
260
 
261
void mouse_off_sem(void)
262
{
1034 mauro 263
        internal_sem_wait(&mutex);
538 mauro 264
        MOUSE_OFF();
1034 mauro 265
        internal_sem_post(&mutex);
538 mauro 266
}
267
 
268
void mouse_off_nosem(void)
269
{
270
        MOUSE_OFF();
271
}
272
 
273
void (*mouse_off)(void) = mouse_off_nosem;
274
 
275
static MOUSE_HANDLER wich_handler(int cmd)
276
{
277
        if ( ((cmd & WITHOUTSEM) == WITHOUTSEM) && ((cmd & AUTOOFF) == AUTOOFF) )
278
                return autocursor_mouse_handler_4;
279
        if ((cmd & WITHOUTSEM) == WITHOUTSEM)
280
                return autocursor_mouse_handler_2;
281
        if ((cmd & AUTOOFF) == AUTOOFF)
282
                return autocursor_mouse_handler_3;
283
        return autocursor_mouse_handler_1;
284
}
285
 
286
int mouse_txtcursor(int cmd)
287
{
288
        mouse_txtshape(saved_txtshape);  
289
        return _mouse_cursor_init(cmd|TXTCURSOR, show_txt_cursor, restore_txt_cursor);
290
}
291
 
292
/* Generic functions, both for text & graphics mode */
293
 
294
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int))
295
{
1034 mauro 296
        if (mcur_mutex_init == 0) {
297
                internal_sem_init(&mutex, 1);
298
                mcur_mutex_init = 1;
538 mauro 299
        }
300
 
301
#ifdef CURTXT_DEBUG
302
        printk(KERN_DEBUG "mouse_cursor_init: command %x\n", cmd);
303
#endif
304
 
305
        switch (cmd & STATUSMASK) {
306
                case DISABLE:
307
                        //show_mouse_handler = user_mouse_handler;
308
                        show_mouse_handler = NULL;
309
                        restore_cursor(saved_x, saved_y);
310
                        show_cursor = dummy;
311
                        restore_cursor = dummy;
312
                        mouse_cursor_state = 0;
313
                        break;
314
                case ENABLE:
315
                        restore_cursor(saved_x, saved_y);
316
                        restore_cursor = my_restore_cursor;
317
                        show_cursor = my_show_cursor;      
318
                        if ((autocursormode & STATUSMASK) == DISABLE) {
319
                                //user_mouse_handler = show_mouse_handler;
320
                                show_mouse_handler = wich_handler(cmd);
321
                        }
322
                        mouse_cursor_state = -1;
323
                        break;
324
                default:
325
                        return -1;
326
        }  
327
 
328
        autocursormode = cmd;
329
 
330
        if ((autocursormode & STATUSMASK) == ENABLE) {
331
                if ((cmd & WITHOUTSEM) == WITHOUTSEM) {
332
                        mouse_on = mouse_on_nosem;
333
                        mouse_off = mouse_off_nosem;
334
                } else {
335
                        mouse_on = mouse_on_sem;
336
                        mouse_off = mouse_off_sem;
337
                }
338
        }
339
 
340
        return 0;
341
}
342
 
343
void _mouse_cursor_getposition(int *xptr, int *yptr)
344
{
345
        *xptr = saved_x;
346
        *yptr = saved_y;
347
}