diff src/main.rs @ 14:adab13145994

Add support for remote clients.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 02 Nov 2020 00:06:09 +0100
parents 97e543f50f62
children 478cf2a7d577
line wrap: on
line diff
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,16 +14,48 @@
 // You should have received a copy of the GNU Affero General Public License
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+#[cfg(feature = "gui")]
 mod gtk;
+mod server;
 mod uinput;
 mod state;
 
+use std::env::args;
+
 const MAX_X: i32 = 69920;
 const MAX_Y: i32 = 39980;
 
 const DEFAULT_WIDTH: i32 = 320;
 const DEFAULT_HEIGHT: i32 = 180;
 
+#[derive(Debug)]
+enum Ui {
+    Gtk,
+    Server,
+}
+
 fn main() {
-    gtk::main();
+    let mut args: Vec<_> = args().collect();
+    let ui = match if args.len() > 1 {
+        args.remove(1)
+    } else {
+        String::from("gui")
+    }.as_str() {
+        "gui" => Ui::Gtk,
+        "server" => Ui::Server,
+        name => {
+            eprintln!("Wrong UI “{}”, expected gui or server.", name);
+            std::process::exit(2);
+        }
+    };
+
+    match ui {
+        #[cfg(feature = "gui")]
+        Ui::Gtk => gtk::main(&args),
+
+        #[cfg(not(feature = "gui"))]
+        Ui::Gtk => panic!("tablet-emu has been compiled without GUI support."),
+
+        Ui::Server => server::main(&args),
+    }
 }