summaryrefslogtreecommitdiffstats
path: root/layout.c
diff options
context:
space:
mode:
authorJames <git@panaceas.org>2014-05-05 17:50:20 +0100
committerJames <git@panaceas.org>2014-05-05 17:50:20 +0100
commit470457e22a1b5537013603d5e367c51e47bb61bf (patch)
tree6b72d32bfd9eaec31c8c520d18782ccaebc01759 /layout.c
downloadkmd_usb-470457e22a1b5537013603d5e367c51e47bb61bf.tar.gz
kmd_usb-470457e22a1b5537013603d5e367c51e47bb61bf.tar.bz2
kmd_usb-470457e22a1b5537013603d5e367c51e47bb61bf.zip
fish
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/layout.c b/layout.c
new file mode 100644
index 0000000..32f1cdf
--- /dev/null
+++ b/layout.c
@@ -0,0 +1,156 @@
+#include "project.h"
+
+static int computer_to_console[N_COMPUTER + 1];
+static int console_to_computer[N_CONSOLE + 1];
+static int console_locked[N_CONSOLE + 1];
+
+static MM *mm;
+
+int
+layout_computer_to_console (int computer)
+{
+ if ((computer < 1) || (computer > N_COMPUTER))
+ return 0;
+ return computer_to_console[computer];
+
+}
+
+int
+layout_console_to_computer (int console)
+{
+ if ((console < 1) || (console > N_CONSOLE))
+ return 0;
+ return console_to_computer[console];
+}
+
+#ifdef LAYOUT_NULL
+int
+layout_possible (int console, int computer)
+{
+ if ((console < 1) || (console > N_CONSOLE))
+ return 0;
+ if ((computer < 1) || (computer > N_COMPUTER))
+ return 0;
+
+ if (console_locked[console])
+ return 0;
+
+return 1;
+}
+#elif defined(LAYOUT_HOME)
+int
+layout_possible (int console, int computer)
+{
+ if ((console < 1) || (console > N_CONSOLE))
+ return 0;
+ if ((computer < 1) || (computer > N_COMPUTER))
+ return 0;
+
+ if (console_locked[console])
+ return 0;
+
+ switch (computer)
+ {
+ case 1:
+ case 2:
+ case 3:
+ if (console != 1)
+ return 0;
+ return 1;
+ }
+
+ switch (console)
+ {
+ case 1:
+ if (computer > 3)
+ return 0;
+ return 1;
+ }
+
+
+ return 1;
+}
+#endif
+
+void
+layout_map (int console, int computer)
+{
+ int oc;
+
+ if ((console < 1) || (console > N_CONSOLE))
+ return;
+ if ((computer < 1) || (computer > N_COMPUTER))
+ return;
+
+ oc = console_to_computer[console];
+
+ if ((oc > 0) && (oc <= N_COMPUTER))
+ {
+ computer_to_console[oc] = 0;
+ }
+ computer_to_console[computer] = console;
+ console_to_computer[console] = computer;
+
+#ifdef LAYOUT_HOME
+ switch (console)
+ {
+ case 1:
+ VS_set (mm, 4 - computer);
+ break;
+ case 2:
+ MM_set (mm, computer - 3, -1);
+ break;
+ case 3:
+ MM_set (mm, -1, computer - 3);
+ break;
+ }
+#endif
+
+}
+
+void
+layout_status (int active_computer)
+{
+ int i;
+ for (i = 1; i <= N_COMPUTER; ++i)
+ {
+ int console = layout_computer_to_console (i);
+ status_draw_computer (i, console_locked[console], console,
+ active_computer == i, 0);
+ }
+
+ for (i = 1; i <= N_CONSOLE; ++i)
+ {
+ int computer = layout_console_to_computer (i);
+ status_draw_console (i, console_locked[i], computer,
+ active_computer == computer, 0);
+ }
+}
+
+
+void
+layout_toggle_lock (int computer)
+{
+ int console = layout_computer_to_console (computer);
+ if ((console < 1) || (console > N_CONSOLE))
+ return;
+
+ console_locked[console] = !console_locked[console];
+ layout_status (computer);
+}
+
+
+int
+layout_init (void)
+{
+ mm = MM_open ();
+
+ layout_map (1, 3);
+ layout_map (2, 4);
+ layout_map (3, 5);
+
+
+ layout_status (3);
+
+ return 3;
+}