Mercurial > tablet-emu
annotate src/main.rs @ 16:478cf2a7d577
Reformat with rustfmt.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Aug 2021 19:45:30 +0200 |
parents | adab13145994 |
children | 0bce7fe96937 |
rev | line source |
---|---|
6
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
1 // Tablet emulator, for people who don’t own one |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
2 // Copyright © 2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
3 // |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
4 // This program is free software: you can redistribute it and/or modify |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
5 // it under the terms of the GNU Affero General Public License as published by |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
6 // the Free Software Foundation, either version 3 of the License, or |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
7 // (at your option) any later version. |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
8 // |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
9 // This program is distributed in the hope that it will be useful, |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
12 // GNU Affero General Public License for more details. |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
13 // |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
14 // You should have received a copy of the GNU Affero General Public License |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
15 // along with this program. If not, see <https://www.gnu.org/licenses/>. |
dd10331549c6
Add a license file.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
16 |
14
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
17 #[cfg(feature = "gui")] |
13
97e543f50f62
Split GTK UI into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
18 mod gtk; |
14
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
19 mod server; |
16
478cf2a7d577
Reformat with rustfmt.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
14
diff
changeset
|
20 mod state; |
12
d43c31aff57c
Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
21 mod uinput; |
0 | 22 |
14
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
23 use std::env::args; |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
24 |
0 | 25 const MAX_X: i32 = 69920; |
26 const MAX_Y: i32 = 39980; | |
27 | |
13
97e543f50f62
Split GTK UI into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
28 const DEFAULT_WIDTH: i32 = 320; |
97e543f50f62
Split GTK UI into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
29 const DEFAULT_HEIGHT: i32 = 180; |
0 | 30 |
14
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
31 #[derive(Debug)] |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
32 enum Ui { |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
33 Gtk, |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
34 Server, |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
35 } |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
36 |
0 | 37 fn main() { |
14
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
38 let mut args: Vec<_> = args().collect(); |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
39 let ui = match if args.len() > 1 { |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
40 args.remove(1) |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
41 } else { |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
42 String::from("gui") |
16
478cf2a7d577
Reformat with rustfmt.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
14
diff
changeset
|
43 } |
478cf2a7d577
Reformat with rustfmt.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
14
diff
changeset
|
44 .as_str() |
478cf2a7d577
Reformat with rustfmt.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
14
diff
changeset
|
45 { |
14
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
46 "gui" => Ui::Gtk, |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
47 "server" => Ui::Server, |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
48 name => { |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
49 eprintln!("Wrong UI “{}”, expected gui or server.", name); |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
50 std::process::exit(2); |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
51 } |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
52 }; |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
53 |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
54 match ui { |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
55 #[cfg(feature = "gui")] |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
56 Ui::Gtk => gtk::main(&args), |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
57 |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
58 #[cfg(not(feature = "gui"))] |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
59 Ui::Gtk => panic!("tablet-emu has been compiled without GUI support."), |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
60 |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
61 Ui::Server => server::main(&args), |
adab13145994
Add support for remote clients.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
13
diff
changeset
|
62 } |
0 | 63 } |