2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999 Alexander König
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Description: This implements the mouse AND keyboard Input handling in
26 #include "tX_mastergui.h"
27 #include "tX_global.h"
28 #include "tX_engine.h"
31 tx_mouse :: tx_mouse()
33 mask=PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask;
34 xmot=(XMotionEvent *) &xev;
35 xkey=(XKeyEvent *) &xev;
36 xbut=(XButtonEvent *) &xev;
40 int tx_mouse :: grab()
42 if (grabbed) return(0);
44 dpy=XOpenDisplay(NULL); // FIXME: use correct display
47 return(ENG_ERR_XOPEN);
50 if (globals.xinput_enable)
55 return(ENG_ERR_XINPUT);
59 XSelectInput(dpy, xwindow, mask);
61 XSetInputFocus(dpy, xwindow, None, CurrentTime);
63 if (GrabSuccess != XGrabPointer(dpy, xwindow, False, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync,GrabModeAsync,None,None,CurrentTime))
67 return(ENG_ERR_GRABMOUSE);
70 if (GrabSuccess != XGrabKeyboard(dpy, xwindow, False, GrabModeAsync,GrabModeAsync,CurrentTime))
72 XUngrabPointer (dpy, CurrentTime);
76 return(ENG_ERR_GRABKEY);
80 if (!XF86DGADirectVideo(dpy,DefaultScreen(dpy),XF86DGADirectMouse))
82 XUngrabKeyboard(dpy, CurrentTime);
83 XUngrabPointer (dpy, CurrentTime);
93 vtt_class::focus_no(0);
98 void tx_mouse :: ungrab()
100 if (!grabbed) return;
102 XF86DGADirectVideo(dpy,DefaultScreen(dpy),0);
104 XUngrabKeyboard(dpy, CurrentTime);
105 XUngrabPointer (dpy, CurrentTime);
112 vtt_class::unfocus();
119 int tx_mouse :: set_xinput()
121 XDeviceInfo *devlist;
125 if (globals.xinput_enable)
127 devlist=XListInputDevices(dpy, &listmax);
129 for (i=0; i<listmax; i++)
131 if(!strcmp(globals.xinput_device,devlist[i].name))
136 if(devlist[i].use == IsXPointer)
138 OrgXPointer=devlist[i].id;
145 input_device=XOpenDevice(dpy,devlist[match].id);
146 /* if (XChangePointerDevice(dpy,input_device, 0, 1)!=Success)
150 XCloseDevice(dpy, input_device);
153 XFreeDeviceList(devlist);
155 if (match>=0) return(0);
162 #define vtt vtt_class::focused_vtt
164 int tx_mouse :: check_event()
166 if (XCheckWindowEvent(dpy, xwindow, mask, &xev))
173 dtime=(f_prec) ntime-otime;
174 if (dtime<=0) dtime=1.0;
177 vtt->xy_input(((f_prec) xmot->x_root)/dtime,((f_prec) xmot->y_root)/dtime);
183 case 1: if (vtt->is_playing)
188 case 2: vtt->set_mute(1); break;
189 case 3: vtt_class::focus_next(); break;
194 switch (xbut->button)
196 case 1: vtt->set_scratch(0); break;
197 case 2: vtt->set_mute(0); break;
203 key=XKeycodeToKeysym(dpy, xkey->keycode, 0);
207 case XK_space: vtt->set_scratch(1); break;
208 case XK_Escape: return(1);
210 case XK_Return: vtt->trigger(); break;
211 case XK_BackSpace : vtt->stop(); break;
213 case XK_Tab: vtt_class::focus_next(); break;
215 case XK_s: vtt->set_sync_client(!vtt->is_sync_client, vtt->sync_cycles); break;
228 case XK_F1: vtt_class::focus_no(0); break;
229 case XK_F2: vtt_class::focus_no(1); break;
230 case XK_F3: vtt_class::focus_no(2); break;
231 case XK_F4: vtt_class::focus_no(3); break;
232 case XK_F5: vtt_class::focus_no(4); break;
233 case XK_F6: vtt_class::focus_no(5); break;
234 case XK_F7: vtt_class::focus_no(6); break;
235 case XK_F8: vtt_class::focus_no(7); break;
236 case XK_F9: vtt_class::focus_no(8); break;
237 case XK_F10: vtt_class::focus_no(9); break;
238 case XK_F11: vtt_class::focus_no(10); break;
239 case XK_F12: vtt_class::focus_no(11); break;
242 warp=((float) globals.scratch_size)/50000.0;
249 key=XKeycodeToKeysym (dpy, xkey->keycode, 0);
253 case XK_space: vtt->set_scratch(0); break;
268 else { puts("no vtt"); return(1); }
273 void tx_mouse :: reset_xinput()
276 /* if (globals.xinput_enable)
278 input_device=XOpenDevice(dpy, OrgXPointer);
279 XChangePointerDevice(dpy, input_device, 0, 1);
280 XCloseDevice(dpy,input_device);