Selaa lähdekoodia

Delete X11Keyboard and X11Mouse

Daniele Bartolini 13 vuotta sitten
vanhempi
sitoutus
17b4bc7a0a
4 muutettua tiedostoa jossa 0 lisäystä ja 497 poistoa
  1. 0 169
      src/os/linux/X11Keyboard.cpp
  2. 0 80
      src/os/linux/X11Keyboard.h
  3. 0 167
      src/os/linux/X11Mouse.cpp
  4. 0 81
      src/os/linux/X11Mouse.h

+ 0 - 169
src/os/linux/X11Keyboard.cpp

@@ -1,169 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "X11Keyboard.h"
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysymdef.h>
-#include <X11/XKBlib.h>
-#include "Exceptions.h"
-#include "Log.h"
-#include "OS.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-X11Keyboard::X11Keyboard(InputManager* creator) :
-	Keyboard(creator),
-	mModifierMask(0),
-	mDisplay(NULL),
-	mXWindow(0),
-	mDetectableAutoRepeat(false)
-{
-	for (int i = 0; i < MAX_KEYCODES; i++)
-	{
-		mKeyState[i] = false;
-	}
-
-//	// Connect to the X Server
-//	mDisplay = XOpenDisplay(NULL);
-
-//	if (!mDisplay)
-//	{
-//		throw InvalidOperationException("X11Keyboard::X11Keyboard: Unable to connect to the X Server.");
-//	}
-
-//	if (mCreator)
-//	{
-//		mXWindow = static_cast<X11InputManager*>(mCreator)->GetXWindow();
-//	}
-
-//	// We want to track motion and button pressed/released events
-//	if (XSelectInput(mDisplay, mXWindow, KeyPressMask | KeyReleaseMask) == BadWindow)
-//	{
-//		throw InvalidOperationException("X11Keyboard::X11Keyboard: Unable to select input, bad window.");
-//	}
-
-//	Bool detectable;
-//	if ((mDetectableAutoRepeat = (bool) XkbSetDetectableAutoRepeat(mDisplay, true, &detectable)) == False)
-//	{
-//		Log::I("X11Keyboard::X11Keyboard: Detectable auto-repeat not supported.");
-//	}
-
-//	static_cast<X11InputManager*>(mCreator)->SetKeyboardAvailable(true);
-}
-
-//-----------------------------------------------------------------------------
-X11Keyboard::~X11Keyboard()
-{
-//	if (mCreator)
-//	{
-//		static_cast<X11InputManager*>(mCreator)->SetKeyboardAvailable(false);
-//	}
-
-//	if (mDisplay)
-//	{
-//		XCloseDisplay(mDisplay);
-//	}
-}
-
-//-----------------------------------------------------------------------------
-bool X11Keyboard::IsModifierPressed(ModifierKey modifier) const
-{
-	return (mModifierMask & modifier) == modifier;
-}
-
-//-----------------------------------------------------------------------------
-bool X11Keyboard::IsKeyPressed(KeyCode key) const
-{
-	return mKeyState[key] == true;
-}
-
-//-----------------------------------------------------------------------------
-bool X11Keyboard::IsKeyReleased(KeyCode key) const
-{
-	return mKeyState[key] == false;
-}
-
-//-----------------------------------------------------------------------------
-Key X11Keyboard::TranslateKey(int x11Key)
-{
-	if ((x11Key > 0x40 && x11Key < 0x5B) || (x11Key > 0x60 && x11Key < 0x7B) || (x11Key > 0x2F && x11Key < 0x3A))
-	{
-		return (Key)x11Key;
-	}
-
-	switch (x11Key)
-	{
-		case XK_BackSpace:	return KC_BACKSPACE;
-		case XK_Tab:		return KC_TAB;
-		case XK_space:		return KC_SPACE;
-		case XK_Escape:		return KC_ESCAPE;
-		case XK_Return:		return KC_ENTER;
-		case XK_F1:			return KC_F1;
-		case XK_F2:			return KC_F2;
-		case XK_F3:			return KC_F3;
-		case XK_F4:			return KC_F4;
-		case XK_F5:			return KC_F5;
-		case XK_F6:			return KC_F6;
-		case XK_F7:			return KC_F7;
-		case XK_F8:			return KC_F8;
-		case XK_F9:			return KC_F9;
-		case XK_F10:		return KC_F10;
-		case XK_F11:		return KC_F11;
-		case XK_F12:		return KC_F12;
-		case XK_Home:		return KC_HOME;
-		case XK_Left:		return KC_LEFT;
-		case XK_Up:			return KC_UP;
-		case XK_Right:		return KC_RIGHT;
-		case XK_Down:		return KC_DOWN;
-		case XK_Page_Up:	return KC_PAGE_UP;
-		case XK_Page_Down:	return KC_PAGE_DOWN;
-		case XK_Shift_L:	return KC_LSHIFT;
-		case XK_Shift_R:	return KC_RSHIFT;
-		case XK_Control_L:	return KC_LCONTROL;
-		case XK_Control_R:	return KC_RCONTROL;
-		case XK_Caps_Lock:	return KC_CAPS_LOCK;
-		case XK_Alt_L:		return KC_LALT;
-		case XK_Alt_R:		return KC_RALT;
-		case XK_Super_L:	return KC_LSUPER;
-		case XK_Super_R:	return KC_RSUPER;
-		case XK_KP_0:		return KC_KP_0;
-		case XK_KP_1:		return KC_KP_1;
-		case XK_KP_2:		return KC_KP_2;
-		case XK_KP_3:		return KC_KP_3;
-		case XK_KP_4:		return KC_KP_4;
-		case XK_KP_5:		return KC_KP_5;
-		case XK_KP_6:		return KC_KP_6;
-		case XK_KP_7:		return KC_KP_7;
-		case XK_KP_8:		return KC_KP_8;
-		case XK_KP_9:		return KC_KP_9;
-		default:			return KC_NOKEY;
-	}
-}
-
-} // namespace crown
-

+ 0 - 80
src/os/linux/X11Keyboard.h

@@ -1,80 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Keyboard.h"
-
-struct _XDisplay;
-typedef struct _XDisplay Display;
-
-namespace crown
-{
-
-/**
-	Implementation of Keyboard interface for the X11 Windowing System.
-*/
-class X11Keyboard : public Keyboard
-{
-
-public:
-
-	/** @copydoc Keyboard::Keyboard() */
-	X11Keyboard(InputManager* creator);
-
-	/** @copydoc Keyboard::~Keyboard() */
-	~X11Keyboard();
-
-	/** @copydoc Keyboard::IsModifierPressed() */
-	virtual bool IsModifierPressed(ModifierKey modifier) const;
-
-	/** @copydoc Keyboard::IsKeyPressed() */
-	virtual bool IsKeyPressed(KeyCode key) const;
-
-	/** @copydoc Keyboard::IsKeyReleased() */
-	virtual bool IsKeyReleased(KeyCode key) const;
-
-	/**
-		Returns whether DetectableAutoRepeat is set.
-	@return
-		True if set, false otherwise
-	*/
-	inline bool HasDetectableAutoRepeat() { return mDetectableAutoRepeat; }
-
-private:
-
-	Key TranslateKey(int x11Key);
-
-	uint mModifierMask;
-	bool mKeyState[MAX_KEYCODES];
-
-	// X11 related
-	Display* mDisplay;
-	unsigned long mXWindow;
-	bool mDetectableAutoRepeat;
-};
-
-} // namespace crown
-

+ 0 - 167
src/os/linux/X11Mouse.cpp

@@ -1,167 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "X11Mouse.h"
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include "Exceptions.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-X11Mouse::X11Mouse(InputManager* creator) :
-	Mouse(creator),
-	mIsCursorVisible(true),
-	mDisplay(NULL),
-	mXWindow(0),
-	mHiddenCursor(0)
-{
-//	// Connect to the X Server
-//	mDisplay = XOpenDisplay(NULL);
-
-//	if (!mDisplay)
-//	{
-//		throw InvalidOperationException("X11Mouse::X11Mouse: Unable to connect to the X Server.");
-//	}
-
-//	if (mCreator)
-//	{
-//		mXWindow = static_cast<X11InputManager*>(mCreator)->GetXWindow();
-//	}
-
-//	// We want to track motion and button pressed/released events
-//	if (XSelectInput(mDisplay, mXWindow, ButtonPressMask | ButtonReleaseMask | PointerMotionMask) == BadWindow)
-//	{
-//		throw InvalidOperationException("X11Mouse::X11Mouse: Unable to select input, bad window.");
-//	}
-
-//	// Build hidden cursor
-//	Pixmap bm_no;
-//	XColor black, dummy;
-//	Colormap colormap;
-//	static char no_data[] = { 0,0,0,0,0,0,0,0 };
-
-//	colormap = DefaultColormap(mDisplay, DefaultScreen(mDisplay));
-//	XAllocNamedColor(mDisplay, colormap, "black", &black, &dummy);
-//	bm_no = XCreateBitmapFromData(mDisplay, mXWindow, no_data, 8, 8);
-//	mHiddenCursor = XCreatePixmapCursor(mDisplay, bm_no, bm_no, &black, &black, 0, 0);
-
-//	static_cast<X11InputManager*>(mCreator)->SetMouseAvailable(true);
-}
-
-//-----------------------------------------------------------------------------
-X11Mouse::~X11Mouse()
-{
-//	if (mCreator)
-//	{
-//		static_cast<X11InputManager*>(mCreator)->SetMouseAvailable(false);
-//	}
-
-//	if (!IsCursorVisible())
-//	{
-//		SetCursorVisible(true);
-//	}
-
-//	if (mHiddenCursor)
-//	{
-//		XFreeCursor(mDisplay, mHiddenCursor);
-//	}
-
-//	if (mDisplay)
-//	{
-//		XCloseDisplay(mDisplay);
-//	}
-}
-
-//-----------------------------------------------------------------------------
-bool X11Mouse::IsCursorVisible() const
-{
-	return mIsCursorVisible;
-}
-
-//-----------------------------------------------------------------------------
-void X11Mouse::SetCursorVisible(bool visible)
-{
-	if (visible)
-	{
-		XUndefineCursor(mDisplay, mXWindow);
-	}
-	else
-	{
-		XDefineCursor(mDisplay, mXWindow, mHiddenCursor);
-	}
-
-	mIsCursorVisible = visible;
-}
-
-//-----------------------------------------------------------------------------
-Point2 X11Mouse::GetCursorXY() const
-{
-	Window unused;
-	int x, y, dummy;
-	uint dummy2;
-
-	XQueryPointer(mDisplay, mXWindow, &unused, &unused, &dummy, &dummy, &x, &y, &dummy2);
-
-	return Point2(x, y);
-}
-
-//-----------------------------------------------------------------------------
-void X11Mouse::SetCursorXY(const Point2& position)
-{
-	XWindowAttributes attribs;
-	XGetWindowAttributes(mDisplay, mXWindow, &attribs);
-
-	XWarpPointer(mDisplay, None, mXWindow, 0, 0, attribs.width, attribs.height, position.x, position.y);
-
-	XFlush(mDisplay);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 X11Mouse::GetCursorRelativeXY() const
-{
-	XWindowAttributes attribs;
-	XGetWindowAttributes(mDisplay, mXWindow, &attribs);
-
-	Vec2 pos = GetCursorXY().to_vec2();
-
-	pos.x = pos.x / (float) attribs.width;
-	pos.y = pos.y / (float) attribs.height;
-
-	return pos;
-}
-
-//-----------------------------------------------------------------------------
-void X11Mouse::SetCursorRelativeXY(const Vec2& position)
-{
-	XWindowAttributes attribs;
-	XGetWindowAttributes(mDisplay, mXWindow, &attribs);
-
-	SetCursorXY(Point2((int)(position.x * (float) attribs.width), (int)(position.y * (float) attribs.height)));
-}
-
-} // namespace crown
-

+ 0 - 81
src/os/linux/X11Mouse.h

@@ -1,81 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Mouse.h"
-
-struct _XDisplay;
-typedef struct _XDisplay Display;
-typedef unsigned long XID;
-typedef XID Cursor;
-
-namespace crown
-{
-
-/**
-	Implementation of Mouse interface for the X11 Windowing System.
-*/
-class X11Mouse : public Mouse
-{
-
-public:
-
-	/** @copydoc Mouse::Mouse() */
-	X11Mouse(InputManager* creator);
-
-	/** @copydoc Mouse::~Mouse() */
-	~X11Mouse();
-
-	/** @copydoc Mouse::IsVisible() */
-	virtual bool IsCursorVisible() const;
-
-	/** @copydoc Mouse::SetVisible() */
-	virtual void SetCursorVisible(bool visible);
-
-	/** @copydoc Mouse::GetCursorXY() */
-	virtual Point2 GetCursorXY() const;
-
-	/** @copydoc Mouse::SetCursorXY() */
-	virtual void SetCursorXY(const Point2& position);
-
-	/** @copydoc Mouse::GetCursorRelativeXY() */
-	virtual Vec2 GetCursorRelativeXY() const;
-
-	/** @copydoc Mouse::SetCursorRelativeXY() */
-	virtual void SetCursorRelativeXY(const Vec2& position);
-
-private:
-
-	bool mIsCursorVisible;
-
-	// X11 related
-	Display* mDisplay;
-	unsigned long mXWindow;
-	Cursor mHiddenCursor;
-};
-
-} // namespace crown
-