src/SpacenavWrapper.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:49:24 +0200
branchv_0
changeset 11 aaa89fe98b63
parent 9 d3716f03efcd
permissions -rw-r--r--
fix license version: GNU GPLv3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Spacenav Demo Qt
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
11
aaa89fe98b63 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <iostream>
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
/**
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
 * This wrapper separates spnav.h and X headers from the rest of the application.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
 * Some definitions like Status would collide with Qt if mixed in a single file with QObjects and processed by MOC.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
 * 
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
 * This wrapper also abstracts from the connection type – tries AF_UNIX socket first and then X11.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
 */
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
class SpacenavWrapper {
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
public:
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
	class Event {
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    31
	public:
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    32
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    33
		enum class Type {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    34
			MOTION,
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    35
			BUTTON
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    36
		};
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    37
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    38
		class MotionEvent {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    39
		public:
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    40
			int x;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    41
			int y;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    42
			int z;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    43
			int rx;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    44
			int ry;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    45
			int rz;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    46
			int type;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    47
			unsigned int period;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    48
		};
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    49
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    50
		class ButtonEvent {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    51
		public:
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    52
			int number;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    53
			bool pressed;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    54
		};
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    55
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    56
		Type type;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    57
		MotionEvent motion;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    58
		ButtonEvent button;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    59
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	};
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    62
	enum class ConnectionStatus {
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    63
		NONE,
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    64
		DOMAIN_SOCKET,
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    65
		X11
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    66
	};
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    67
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
	SpacenavWrapper();
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
	virtual ~SpacenavWrapper();
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    72
	ConnectionStatus getConnectionStatus();
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	Event waitEvent();
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
9
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    75
private:
d3716f03efcd display status – connection type (domain socket or X11)
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    76
	ConnectionStatus connectionStatus;
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
};