From 0e38878528c68563eb8a82287eb9df69588eb649 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Thu, 7 Dec 2006 12:56:22 +0000 Subject: [PATCH] We can be sure that if the low level window is going to be created, it will already have been created so we need only set the event masks here and they will be preserved across window recreations. --- .../arch/InputHandler/InputHandler_X11.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/stepmania/src/arch/InputHandler/InputHandler_X11.cpp b/stepmania/src/arch/InputHandler/InputHandler_X11.cpp index 70eb854072..be13d97fb4 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_X11.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_X11.cpp @@ -9,6 +9,8 @@ #include #include +using namespace X11Helper; + REGISTER_INPUT_HANDLER_CLASS( X11 ); static DeviceButton XSymToDeviceButton( int key ) @@ -126,27 +128,35 @@ static DeviceButton XSymToDeviceButton( int key ) InputHandler_X11::InputHandler_X11() { - X11Helper::Go(); - X11Helper::OpenMask( KeyPressMask | KeyReleaseMask ); + if( Dpy == NULL || Win == None ) + return; + XWindowAttributes winAttrib; + + XGetWindowAttributes( Dpy, Win, &winAttrib ); + XSelectInput( Dpy, Win, winAttrib.your_event_mask | KeyPressMask | KeyReleaseMask ); } InputHandler_X11::~InputHandler_X11() { - X11Helper::CloseMask( KeyPressMask | KeyReleaseMask ); - X11Helper::Stop(); + if( Dpy == NULL || Win == None ) + return; + XWindowAttributes winAttrib; + + XGetWindowAttributes( Dpy, Win, &winAttrib ); + XSelectInput( Dpy, Win, winAttrib.your_event_mask & ~(KeyPressMask|KeyReleaseMask) ); } void InputHandler_X11::Update() { XEvent event; - if( !X11Helper::Win ) + if( Dpy == NULL || Win == None ) { InputHandler::UpdateTimer(); return; } - while( XCheckWindowEvent(X11Helper::Dpy, X11Helper::Win, KeyPressMask | KeyReleaseMask, &event) ) + while( XCheckWindowEvent(Dpy, Win, KeyPressMask | KeyReleaseMask, &event) ) { // Why only the zero index? DeviceButton db = XSymToDeviceButton( XLookupKeysym(&event.xkey, 0) ); @@ -163,11 +173,12 @@ void InputHandler_X11::Update() void InputHandler_X11::GetDevicesAndDescriptions( vector& vDevicesOut ) { - vDevicesOut.push_back( InputDeviceInfo(DEVICE_KEYBOARD,"Keyboard") ); + if( Dpy && Win ) + vDevicesOut.push_back( InputDeviceInfo(DEVICE_KEYBOARD,"Keyboard") ); } /* - * (c) 2005 Sean Burke, Ben Anderson + * (c) 2005, 2006 Sean Burke, Ben Anderson, Steve Checkoway * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a