summaryrefslogtreecommitdiff
path: root/XOrg/XServer.pm
blob: d07526d2b2be6b69d986d0f2011b8d1553d85ed4 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/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>


=head1 NAME

XOrg::XServer - XServer representation

=head1 SYNOPSIS

	use XOrg::xorglog;

	my $xlog = xorglog->new(file => "/var/log/Xorg.0.log");
	my $xserver = $xlog->server;

=head1 DESCRIPTION

This module is not supposed to be created directly, it is a product of
the Xorg.log parser. Use it to query information.

=cut

package XOrg::XServer;

use XOrg::Module;
use XOrg::InputDevice;
use warnings;
use strict;
use Carp;

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

	$self->{modules} = {};
	$self->{devices} = ();

        return $self;
}

=head2 B<$xserver-E<gt>logfile([$logfile])>

Returns the logfile this server writes/wrote to.
=cut
sub logfile {
	my $self = shift;
	my $logfile = shift;

	$self->{logfile} = $logfile if defined $logfile;
	return $self->{logfile};
}

=head2 B<$xserver-E<gt>version([$major, [$minor], [$patchlevel])>

Returns a triple of the major, minor and patchlevel version.

=cut
sub version {
	my $self = shift;
	my $major = shift;
	my $minor = shift;
	my $patchlevel = shift;

	if (defined $major) {
		if (not defined $minor or not defined $patchlevel) {
			croak "Invalid version number. Need 3 components.\n";
			return;
		}
		$self->{version} = [($major, $minor, $patchlevel)];
	}

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

=head2 B<$xserver-E<gt>build_id([$build_id])>

Returns the string that is the build ID.

=cut
sub build_id {
	my $self = shift;
	my $build_id = shift;

	$self->{build_id} = $build_id if defined $build_id;
	return $self->{build_id};
}

=head2 B<$xserver-E<gt>config_backend([$config_backend])>

Returns the string that represents the config backend. Currently known
backends:

=over

=item B<hal>
Device was added by the HAL backend (now deprecated on Linux).

=item B<udev>
Device was added by the udev backend (default for hotplugged devices on
Linux).

=item B<xorg.conf>
Device was listed in the xorg.conf.

=item B<internal>
Device was added internally without external instructions (e.g. Wacom
driver-internal hotplugging).

=back

=cut
sub config_backend {
	my $self = shift;
	my $config_backend = shift;

	$self->{config_backend} = $config_backend if defined $config_backend;
	return $self->{config_backend};
}

=head2 B<$xserver-E<gt>modules()>

Returns a {module name => XOrg::Module} reference of the modules loaded.
=cut

sub modules {
	my $self = shift;
	return $self->{modules};
}

=head2 B<$xserver-E<gt>auto_add_devices([$enabled])>

returns 1/0 if AutoAddDevices is on/off.
=cut
sub auto_add_devices {
	my $self = shift;
	my $auto_add_devices = shift;

	$self->{auto_add_devices} = $auto_add_devices if defined $auto_add_devices;
	return $self->{auto_add_devices};
}

=head2 B<$xserver-E<gt>devices([\@devices])>

Returns a [XOrg::InputDevice] list with all devices found in the log file.

This includes those devices that did not get added (e.g.  because no driver
was selected). On Linux, most mouse devices will appear twice in this list,
once because of /dev/input/eventX, once because of /dev/input/mouseX.

=cut
sub devices {
	my $self = shift;
	return $self->{devices};
}


=head2 B<$xserver-E<gt>add_device([$device])>

Add one XOrg::InputDevice to the list of devices.

=cut
sub add_device {
	my $self = shift;
	my $device = shift;

	push @{$self->{devices}}, $device;
}

1;

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