Skip to content

Commit de6c742

Browse files
committed
'testcurs' modified to allow full control over the mouse mask, and to be able to set mouseinterval(0). Largely for testing issue #330 (and related problems noticed while investigating that issue).
1 parent c869587 commit de6c742

1 file changed

Lines changed: 84 additions & 4 deletions

File tree

demos/testcurs.c

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,87 @@ COMMAND command[MAX_OPTIONS] =
108108
};
109109

110110
int width, height;
111-
static bool report_mouse_movement = FALSE;
111+
static mmask_t test_mouse_mask = ALL_MOUSE_EVENTS;
112112
static SCREEN *screen_pointer;
113113

114+
static mmask_t parse_mouse_mask( const char *str)
115+
{
116+
test_mouse_mask = 0;
117+
while( *str)
118+
{
119+
const mmask_t *event_ptr = NULL;
120+
const mmask_t pressed[5] = { BUTTON1_PRESSED, BUTTON2_PRESSED,
121+
BUTTON3_PRESSED, BUTTON4_PRESSED, BUTTON5_PRESSED };
122+
const mmask_t released[5] = { BUTTON1_RELEASED, BUTTON2_RELEASED,
123+
BUTTON3_RELEASED, BUTTON4_RELEASED, BUTTON5_RELEASED };
124+
const mmask_t clicked[5] = { BUTTON1_CLICKED, BUTTON2_CLICKED,
125+
BUTTON3_CLICKED, BUTTON4_CLICKED, BUTTON5_CLICKED };
126+
const mmask_t dblclk[5] = { BUTTON1_DOUBLE_CLICKED, BUTTON2_DOUBLE_CLICKED,
127+
BUTTON3_DOUBLE_CLICKED, BUTTON4_DOUBLE_CLICKED, BUTTON5_DOUBLE_CLICKED };
128+
const mmask_t triclk[5] = { BUTTON1_TRIPLE_CLICKED, BUTTON2_TRIPLE_CLICKED,
129+
BUTTON3_TRIPLE_CLICKED, BUTTON4_TRIPLE_CLICKED, BUTTON5_TRIPLE_CLICKED };
130+
#ifdef BUTTON1_MOVED
131+
const mmask_t moved[5] = { BUTTON1_MOVED, BUTTON2_MOVED,
132+
BUTTON3_MOVED, BUTTON4_MOVED, BUTTON5_MOVED };
133+
#endif
134+
135+
switch( *str)
136+
{
137+
case 'p':
138+
event_ptr = pressed;
139+
break;
140+
case 'r':
141+
event_ptr = released;
142+
break;
143+
case 'c':
144+
event_ptr = clicked;
145+
break;
146+
case 'd':
147+
event_ptr = dblclk;
148+
break;
149+
case 't':
150+
event_ptr = triclk;
151+
break;
152+
#ifdef BUTTON1_MOVED
153+
case 'm':
154+
event_ptr = moved;
155+
break;
156+
#endif
157+
#ifdef MOUSE_WHEEL_SCROLL
158+
case 'w':
159+
test_mouse_mask |= MOUSE_WHEEL_SCROLL;
160+
break;
161+
#endif
162+
#ifdef BUTTON_MODIFIER_SHIFT
163+
case 's':
164+
test_mouse_mask |= BUTTON_MODIFIER_SHIFT;
165+
break;
166+
#endif
167+
#ifdef BUTTON_MODIFIER_CONTROL
168+
case 'x':
169+
test_mouse_mask |= BUTTON_MODIFIER_CONTROL;
170+
break;
171+
#endif
172+
#ifdef BUTTON_MODIFIER_ALT
173+
case 'a':
174+
test_mouse_mask |= BUTTON_MODIFIER_ALT;
175+
break;
176+
#endif
177+
case 'M':
178+
test_mouse_mask |= REPORT_MOUSE_POSITION;
179+
break;
180+
case '0':
181+
mouseinterval( 0);
182+
break;
183+
}
184+
str++;
185+
if( event_ptr)
186+
while( *str >= '1' && *str <= '5')
187+
test_mouse_mask |= event_ptr[*str++ - '1'];
188+
}
189+
return test_mouse_mask;
190+
}
191+
114192
int main(int argc, char *argv[])
115193
{
116194
WINDOW *win;
@@ -161,7 +239,10 @@ int main(int argc, char *argv[])
161239
#endif
162240
#endif
163241
case 'z':
164-
report_mouse_movement = TRUE;
242+
if( !argv[i][2])
243+
test_mouse_mask = ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION;
244+
else
245+
test_mouse_mask = parse_mouse_mask( argv[i] + 2);
165246
break;
166247
default:
167248
break;
@@ -425,8 +506,7 @@ void inputTest(WINDOW *win)
425506
wtimeout(win, 200);
426507

427508
#ifdef PDCURSES
428-
mouse_set( ALL_MOUSE_EVENTS |
429-
(report_mouse_movement ? REPORT_MOUSE_POSITION : 0));
509+
mouse_set( test_mouse_mask);
430510
#endif
431511
curs_set(0); /* turn cursor off */
432512

0 commit comments

Comments
 (0)