src/SpacenavWrapper.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 07 Mar 2019 16:20:51 +0100
branchv_0
changeset 6 49560660d230
parent 4 1383ad1c4f57
child 9 d3716f03efcd
permissions -rw-r--r--
emit MotionEvent and ButtonEvent + display button status
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
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * 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
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 */
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#pragma once
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <iostream>
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
/**
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
 * 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
    24
 * 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
    25
 * 
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
 * 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
    27
 */
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
class SpacenavWrapper {
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
public:
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	class Event {
6
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    32
	public:
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    33
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    34
		enum class Type {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    35
			MOTION,
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    36
			BUTTON
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
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    39
		class MotionEvent {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    40
		public:
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    41
			int x;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    42
			int y;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    43
			int z;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    44
			int rx;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    45
			int ry;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    46
			int rz;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    47
			int type;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    48
			unsigned int period;
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
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    51
		class ButtonEvent {
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    52
		public:
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    53
			int number;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    54
			bool pressed;
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
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    57
		Type type;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    58
		MotionEvent motion;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    59
		ButtonEvent button;
49560660d230 emit MotionEvent and ButtonEvent + display button status
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    60
4
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	};
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	SpacenavWrapper();
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
	virtual ~SpacenavWrapper();
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
	Event waitEvent();
1383ad1c4f57 SpacenavWrapper
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
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
};