#include <EventWindowXWin.h>
Inheritance diagram for gadget::EventWindowXWin:


Public Types | |
| enum | lockState { Unlocked, Lock_LockKey, Lock_KeyDown } |
| Enum to keep track of current lock state for state machine. More... | |
Public Methods | |
| EventWindowXWin () | |
| ~EventWindowXWin () | |
| virtual bool | config (jccl::ConfigElementPtr e) |
| Constructor. More... | |
| void | controlLoop (void *nullParam) |
| Main thread of control for this active object. More... | |
| bool | sample () |
| Processes the current x-events. More... | |
| void | updateData () |
| Update the data. More... | |
| int | isKeyPressed (int Key) |
| Returns the number of times the key was pressed during the last frame. More... | |
| void | operator delete (void *p) |
| Invokes the global scope delete operator. More... | |
Pure Virtuals required by Input | |
| bool | startSampling () |
| Start a device sampling. More... | |
| bool | stopSampling () |
| StopSampling. More... | |
Static Public Methods | |
| std::string | getElementType () |
| Returns the string rep of the element type used to config this device. More... | |
Protected Methods | |
| void | destroy () |
| Deletes this object. More... | |
| virtual void | processEvent (XEvent event) |
| Do any extra event processing needed. More... | |
| void | createEmptyCursor (Display *display, Window root) |
Protected Attributes | |
| bool | mWeOwnTheWindow |
| True if this class owns the window (is reposible for opening, closing, and event processing). More... | |
| ::Window | mWindow |
| ::XVisualInfo * | mVisual |
| ::Display * | mDisplay |
| ::XSetWindowAttributes | mSWA |
| int | mScreen |
| int | mX |
| int | mY |
| screen id, x-origin, y-origin. More... | |
| unsigned int | mWidth |
| unsigned int | mHeight |
| Cursor | mEmptyCursor |
| bool | mEmptyCursorSet |
| std::string | mXDisplayString |
| The display string to use from systemDisplay config info. More... | |
| float | mMouseSensitivity |
| int | mSleepTimeMS |
| Amount of time to sleep in milliseconds between updates. More... | |
| int | mPrevX |
| int | mPrevY |
| Previous mouse location. More... | |
EventWindow state holders | |
| |
| int | mKeys [gadget::LAST_KEY] |
| (0,*): The num key presses during an UpdateData (ie. More... | |
| int | mRealkeys [gadget::LAST_KEY] |
| (0,1): The real keyboard state, all events processed (ie. More... | |
| vpr::Mutex | mKeysLock |
| Must hold this lock when accessing m_keys. More... | |
| bool | mExitFlag |
| Should we exit? More... | |
| lockState | mLockState |
| The current state of locking. More... | |
| int | mLockStoredKey |
| The key that was pressed down. More... | |
| int | mLockToggleKey |
| The key that toggles the locking. More... | |
This device is a source of keyboard events. The device should not be used directly, it should be referenced through proxies.
Mouse Locking:
This device recieves input from the XWindows display. As such, the xwindow must have focus to generate events. In order to help users keep the window in focus, there are two cases where the driver will "lock" the mouse to the window, thus preventing loss of focus.
CASE 1: The user holds down any key. (ie. a,b, ctrl, shift, etc)
CASE 2: The user can toggle locking using a special "locking" key defined in the configuration element.
Definition at line 72 of file EventWindowXWin.h.
|
|
Enum to keep track of current lock state for state machine.
Definition at line 76 of file EventWindowXWin.h.
00077 {
00078 Unlocked,
00079 Lock_LockKey,
00080 Lock_KeyDown
00081 };
|
|
|
Definition at line 83 of file EventWindowXWin.h. References mDisplay, mEmptyCursorSet, mExitFlag, mLockState, mPrevX, mPrevY, mVisual, mWeOwnTheWindow, and Unlocked.
00084 : mWeOwnTheWindow(true), mVisual(NULL), mDisplay(NULL), 00085 mEmptyCursorSet(false), mExitFlag(false), 00086 mLockState(Unlocked), mPrevX(0), mPrevY(0) 00087 { 00088 //mThread = NULL; -- Should be done in base constructor 00089 } |
|
|
Definition at line 91 of file EventWindowXWin.h. References stopSampling.
00092 {
00093 stopSampling();
00094 }
|
|
|
Constructor.
Reimplemented from gadget::EventWindow. Definition at line 59 of file EventWindowXWin.cpp. References gadgetDBG_INPUT_MGR, Lock_LockKey, gadget::EventWindow::mCurKeys, mHeight, mKeys, mLockState, mLockToggleKey, mMouseSensitivity, mRealkeys, mSleepTimeMS, mWeOwnTheWindow, mWidth, mX, mXDisplayString, and mY.
00060 {
00061 if ( ! (Input::config(e) && EventWindow::config(e)) )
00062 {
00063 return false;
00064 }
00065
00066 const char neg_one_STRING[] = "-1";
00067
00068 for ( int i = 0; i < gadget::LAST_KEY; ++i )
00069 {
00070 mRealkeys[i] = mKeys[i] = mCurKeys[i];
00071 }
00072
00073 // Get size and position
00074 mWidth = e->getProperty<int>("width");
00075 mHeight = e->getProperty<int>("height");
00076
00077 // Sanity checks.
00078 if (mWidth == 0) mWidth = 400;
00079 if (mHeight == 0) mHeight = 400;
00080
00081 mX = e->getProperty<int>("origin", 0);
00082 mY = e->getProperty<int>("origin", 1);
00083
00084 // Get the X display string
00085 int x_disp_num = e->getProperty<int>("display_number");
00086 jccl::ConfigElementPtr disp_sys_elt =
00087 gadget::InputManager::instance()->getDisplaySystemElement();
00088
00089 if ((x_disp_num >= 0) && (disp_sys_elt.get() != NULL) )
00090 {
00091 mXDisplayString = disp_sys_elt->getProperty<std::string>("x11_pipes",
00092 x_disp_num);
00093 }
00094 else
00095 {
00096 mXDisplayString = std::string("-1");
00097 }
00098
00099 if ((mXDisplayString.empty()) || (strcmp(mXDisplayString.c_str(), neg_one_STRING) == 0)) // Use display env
00100 {
00101 const std::string DISPLAY_str("DISPLAY");
00102 vpr::System::getenv(DISPLAY_str, mXDisplayString);
00103 }
00104
00105 // Get the lock information
00106 mLockToggleKey = e->getProperty<int>("lock_key");
00107 bool start_locked = e->getProperty<bool>("start_locked");
00108
00109 if (start_locked)
00110 {
00111 mLockState = Lock_LockKey; // Initialize to the locked state
00112 }
00113
00114 mMouseSensitivity = e->getProperty<float>("mouse_sensitivity");
00115 if (0.0f == mMouseSensitivity)
00116 {
00117 mMouseSensitivity = 0.5;
00118 }
00119
00120 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00121 << "Mouse Sensititivty: " << mMouseSensitivity << std::endl
00122 << vprDEBUG_FLUSH;
00123
00124 mSleepTimeMS = e->getProperty<int>("sleep_time");
00125
00126 // Sanity check.
00127 if (mSleepTimeMS == 0)
00128 {
00129 mSleepTimeMS = 50;
00130 }
00131
00132 // Default to owning the window
00133 mWeOwnTheWindow = true;
00134
00135 return true;
00136 }
|
|
|
Main thread of control for this active object.
Definition at line 139 of file EventWindowXWin.cpp. References gadgetDBG_INPUT_MGR, Lock_LockKey, mDisplay, mEmptyCursor, mExitFlag, mLockState, mSleepTimeMS, gadget::Input::mThread, mWeOwnTheWindow, mWindow, and sample.
00140 {
00141 boost::ignore_unused_variable_warning(nullParam);
00142
00143 vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00144 << "gadget::EventWindowXWin::controlLoop: Thread started.\n"
00145 << vprDEBUG_FLUSH;
00146
00147 while (NULL == vpr::Thread::self())
00148 {
00149 vpr::System::usleep(50);
00150 vprDEBUG(vprDBG_ALL,vprDBG_VERB_LVL)
00151 << "gadget::EventWindowXWin: Waiting for (thread::self() != NULL)\n"
00152 << vprDEBUG_FLUSH;
00153 }
00154 mThread = (vpr::Thread*) vpr::Thread::self();
00155
00156 vprASSERT(mWeOwnTheWindow && "control loop should not be called if we don't own window. Update in owning thread.");
00157
00158 // Open the x-window
00159 openTheWindow();
00160
00161 // Sync up with window
00162 XSync(mDisplay, 0);
00163
00164 // If we have initial locked, then we need to lock the system
00165 if(mLockState == Lock_LockKey) // Means that we are in the initially locked state
00166 {
00167 vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00168 << "gadget::EventWindowXWin::controlLoop: Mouse set to initial lock. Locking it now.\n"
00169 << vprDEBUG_FLUSH;
00170 lockMouse(); // Lock the mouse
00171 }
00172
00173 // Loop on updating
00174 while(!mExitFlag)
00175 {
00176 sample();
00177 long usleep_time(1); // to be set...
00178
00179 usleep_time = mSleepTimeMS*1000;
00180
00181 vpr::System::usleep(usleep_time);
00182 }
00183
00184 XResizeWindow(mDisplay, mWindow, 1,1); //Dummy event
00185 XFlush(mDisplay);
00186
00187 if ( mEmptyCursorSet )
00188 {
00189 XFreeCursor(mDisplay, mEmptyCursor);
00190 }
00191
00192 // Exit, cleanup code
00193 XDestroyWindow(mDisplay, mWindow);
00194 XCloseDisplay((::Display*) mDisplay);
00195
00196 }
|
|
|
Start a device sampling. Start the device sampling, normally this will spawn a thread which will just repeatedly call Sample(). This function should return true when it sucessfully starts, false otherwise. Implements gadget::Input. Definition at line 199 of file EventWindowXWin.cpp. References mExitFlag, and gadget::Input::mThread.
00200 {
00201 if(mThread != NULL)
00202 {
00203 vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
00204 << clrOutNORM(clrRED,"ERROR:")
00205 << "gadget::EventWindowXWin: startSampling called, when already sampling.\n"
00206 << vprDEBUG_FLUSH;
00207 vprASSERT(false);
00208 }
00209
00210 mExitFlag =false;
00211 // Create a new thread to handle the control
00212 vpr::ThreadMemberFunctor<EventWindowXWin>* memberFunctor =
00213 new vpr::ThreadMemberFunctor<EventWindowXWin>(this, &EventWindowXWin::controlLoop, NULL);
00214
00215 mThread = new vpr::Thread(memberFunctor);
00216
00217 // return success value...
00218 if ( ! mThread->valid() )
00219 {
00220 return 0; // fail
00221 }
00222 else
00223 {
00224 return 1; // success
00225 }
00226 }
|
|
|
StopSampling. Reverse the effects of StartSampling(). Implements gadget::Input. Definition at line 680 of file EventWindowXWin.cpp. References mExitFlag, gadget::Input::mThread, and mWeOwnTheWindow. Referenced by ~EventWindowXWin.
|
|
|
Processes the current x-events. Called repetatively by the controlLoop. Implements gadget::Input. Definition at line 111 of file EventWindowXWin.h. Referenced by controlLoop.
00112 {
00113 HandleEvents();
00114 return 1;
00115 }
|
|
|
Update the data. After this function is called subsequent calls to GetData(d) will return the most recent data at the time of THIS function call. Data is guaranteed to be valid and static until the next call to UpdateData. Implements gadget::Input. Definition at line 246 of file EventWindowXWin.cpp. References gadget::EventWindow::mCurKeys, mKeys, mKeysLock, mMouseSensitivity, mRealkeys, and gadget::EventWindow::updateEventQueue.
00247 {
00248 vpr::Guard<vpr::Mutex> guard(mKeysLock); // Lock access to the mKeys array
00249
00250 // Scale mouse values based on sensitivity
00251 mKeys[gadget::MOUSE_POSX] = int(float(mKeys[gadget::MOUSE_POSX]) * mMouseSensitivity);
00252 mKeys[gadget::MOUSE_NEGX] = int(float(mKeys[gadget::MOUSE_NEGX]) * mMouseSensitivity);
00253 mKeys[gadget::MOUSE_POSY] = int(float(mKeys[gadget::MOUSE_POSY]) * mMouseSensitivity);
00254 mKeys[gadget::MOUSE_NEGY] = int(float(mKeys[gadget::MOUSE_NEGY]) * mMouseSensitivity);
00255
00256 /*
00257 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)
00258 << "gadget::EventWindowXWin::updateData:" << mInstName << " -- "
00259 << "mouse_keys: px:" << mKeys[gadget::MOUSE_POSX]
00260 << " nx:" << mKeys[gadget::MOUSE_NEGX]
00261 << " py:" << mKeys[gadget::MOUSE_POSY]
00262 << " ny:" << mKeys[gadget::MOUSE_NEGY]
00263 << std::endl << vprDEBUG_FLUSH;
00264 */
00265
00266 // Copy over values
00267 for ( unsigned int i = 0; i < gadget::LAST_KEY; ++i )
00268 {
00269 mCurKeys[i] = mKeys[i];
00270 }
00271
00272 // Re-initialize the mKeys based on current key state in realKeys
00273 // Set the initial state of the mKey key counts based on the current state
00274 // of the system this is to ensure that if a key is still down, we get at
00275 // least one event for it.
00276 for ( unsigned int j = 0; j < gadget::LAST_KEY; ++j )
00277 {
00278 mKeys[j] = mRealkeys[j];
00279 }
00280
00281 updateEventQueue();
00282 }
|
|
|
Returns the string rep of the element type used to config this device. This string is used by the device factory to look up device drivers based up the type of element it is trying to load. Reimplemented from gadget::Input. Definition at line 53 of file EventWindowXWin.cpp.
00054 {
00055 return "event_window";
00056 }
|
|
|
Returns the number of times the key was pressed during the last frame. You can put this in an if to check if was pressed at all, or if you are doing processing based on this catch the actual number. Definition at line 126 of file EventWindowXWin.h. References gadget::EventWindow::mCurKeys.
00127 {
00128 return mCurKeys[Key];
00129 }
|
|
|
Invokes the global scope delete operator. This is required for proper releasing of memory in DLLs on Win32. Definition at line 135 of file EventWindowXWin.h.
00136 {
00137 ::operator delete(p);
00138 }
|
|
|
Deletes this object. This is an implementation of the pure virtual gadget::Input::destroy() method. Implements gadget::Input. Definition at line 145 of file EventWindowXWin.h.
00146 {
00147 delete this;
00148 }
|
|
|
Do any extra event processing needed.
Definition at line 151 of file EventWindowXWin.h.
00152 {
00153 boost::ignore_unused_variable_warning(event);
00154 }
|
|
||||||||||||
|
Definition at line 991 of file EventWindowXWin.cpp. References mEmptyCursor, and mEmptyCursorSet.
00992 {
00993 Pixmap cursormask;
00994 XGCValues xgc;
00995 GC gc;
00996 XColor dummycolour;
00997
00998 cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
00999 xgc.function = GXclear;
01000 gc = XCreateGC(display, cursormask, GCFunction, &xgc);
01001 XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
01002 dummycolour.pixel = 0;
01003 dummycolour.red = 0;
01004 dummycolour.flags = 04;
01005 mEmptyCursor = XCreatePixmapCursor(display, cursormask, cursormask,
01006 &dummycolour,&dummycolour, 0,0);
01007 XFreePixmap(display,cursormask);
01008 XFreeGC(display,gc);
01009
01010 mEmptyCursorSet = true;
01011 }
|
|
|
True if this class owns the window (is reposible for opening, closing, and event processing).
Definition at line 244 of file EventWindowXWin.h. Referenced by config, controlLoop, EventWindowXWin, and stopSampling. |
|
|
Definition at line 246 of file EventWindowXWin.h. Referenced by controlLoop. |
|
|
Definition at line 247 of file EventWindowXWin.h. Referenced by EventWindowXWin. |
|
|
Definition at line 248 of file EventWindowXWin.h. Referenced by controlLoop, and EventWindowXWin. |
|
|
Definition at line 249 of file EventWindowXWin.h. |
|
|
Definition at line 250 of file EventWindowXWin.h. |
|
|
Definition at line 250 of file EventWindowXWin.h. Referenced by config. |
|
|
screen id, x-origin, y-origin.
Definition at line 250 of file EventWindowXWin.h. Referenced by config. |
|
|
Definition at line 251 of file EventWindowXWin.h. Referenced by config. |
|
|
Definition at line 251 of file EventWindowXWin.h. Referenced by config. |
|
|
Definition at line 253 of file EventWindowXWin.h. Referenced by controlLoop, and createEmptyCursor. |
|
|
Definition at line 254 of file EventWindowXWin.h. Referenced by createEmptyCursor, and EventWindowXWin. |
|
|
(0,*): The num key presses during an UpdateData (ie. How many keypress events). Definition at line 261 of file EventWindowXWin.h. Referenced by config, and updateData. |
|
|
(0,1): The real keyboard state, all events processed (ie. what is the key now). Definition at line 263 of file EventWindowXWin.h. Referenced by config, and updateData. |
|
|
Must hold this lock when accessing m_keys.
Definition at line 264 of file EventWindowXWin.h. Referenced by updateData. |
|
|
Should we exit?
Definition at line 265 of file EventWindowXWin.h. Referenced by controlLoop, EventWindowXWin, startSampling, and stopSampling. |
|
|
The current state of locking.
Definition at line 267 of file EventWindowXWin.h. Referenced by config, controlLoop, and EventWindowXWin. |
|
|
The key that was pressed down.
Definition at line 268 of file EventWindowXWin.h. |
|
|
The key that toggles the locking.
Definition at line 269 of file EventWindowXWin.h. Referenced by config. |
|
|
The display string to use from systemDisplay config info.
Definition at line 272 of file EventWindowXWin.h. Referenced by config. |
|
|
Definition at line 274 of file EventWindowXWin.h. Referenced by config, and updateData. |
|
|
Amount of time to sleep in milliseconds between updates.
Definition at line 275 of file EventWindowXWin.h. Referenced by config, and controlLoop. |
|
|
Definition at line 276 of file EventWindowXWin.h. Referenced by EventWindowXWin. |
|
|
Previous mouse location.
Definition at line 276 of file EventWindowXWin.h. Referenced by EventWindowXWin. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002