summaryrefslogtreecommitdiff
path: root/XOrg/InputDevice.pm
blob: 5e4f191bf36e9c53bbe27a36c646728a2211014f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl

# Copyright © 2011 by Red Hat, Inc.
#                                                                            
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
# Authors: Peter Hutterer <peter.hutterer@redhat.com>


# Generic input device class

package InputDevice;

use warnings;
use strict;

# Class methods
sub TYPE_MASTER_POINTER { return 1; }
sub TYPE_MASTER_KEYBOARD { return 2; }
sub TYPE_SLAVE { return 3; }
sub TYPE_FLOATING_SLAVE { return 4; }

# Instance methods
sub new {
	my $class = shift;
	my $self = {@_};
	bless ($self, $class);

	$self->{inputclasses} = [()] if not $self->{inputclasses};
	$self->{options} = {} if not $self->{options};
	$self->{present} = 1 if not defined $self->{present};

	return $self;
}

sub name {
	my $self = shift;
	my $name = shift;
	$self->{name} = $name if defined $name;
	return $self->{name};
}

sub id {
	my $self = shift;
	my $id = shift;
	$self->{id} = $id if defined $id;
	return $self->{id};
}

sub attachment {
	my $self = shift;
	my $attachment = shift;
	$self->{attachment} = $attachment if defined $attachment;
	return $self->{attachment};
}

# Input driver module
sub module {
	my $self = shift;
	my $module = shift;
	$self->{module} = $module if defined $module;
	return $self->{module};
}

# Source is "hal", "udev", "implicit", "internal" or "xorg.conf"
sub source {
	my $self = shift;
	my $source = shift;
	$self->{source} = $source if defined $source;
	return $self->{source};
}

# /dev/input/... device node
sub devicenode {
	my $self = shift;
	my $devicenode = shift;
	$self->{devicenode} = $devicenode if defined $devicenode;
	return $self->{devicenode};
}

# The list of input classes that apply to this device.
# Arguments:
# - ref to list of input classes
# Returns:
# - The list of input classes
sub inputclasses {
	my $self = shift;
	my $inputclasses = shift;

	$self->{inputclasses} = [@{$inputclasses}] if defined $inputclasses;

	return @{$self->{inputclasses}};
}

sub add_inputclass {
	my $self = shift;
	my $cls = shift;
	push @{$self->{inputclasses}}, $cls;
}

# Returns 1 if the device is present, or 0 if it failed to initialize.
sub present {
	my $self = shift;
	my $present = shift;
	$self->{present} = $present if defined $present;
	return $self->{present};
}

# The hash of options the device reported to the log.
# Returns:
# - A hash of the options
sub options {
	my $self = shift;
	return %{$self->{options}};
}

# Add one option to the device
# Arguments:
# - option key
# - option value
sub add_option {
	my $self = shift;
	my $opt = shift;
	my $val = shift;

	if ($opt eq "Device" and not defined $self->{options}->{Device}) {
		$self->devicenode($val);
	}
	$self->{options}->{$opt} = $val;
}

1;

# vim: set noexpandtab shiftwidth=8 tabstop=8: