From 94cfbee2e60e97cda0bbc0ed8afd6a23073bde52 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 26 Mar 2023 22:34:16 +0200 Subject: [PATCH] vnc: double monitor setup --- vnc-client/src/main.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/vnc-client/src/main.c b/vnc-client/src/main.c index 56cf358..270a743 100644 --- a/vnc-client/src/main.c +++ b/vnc-client/src/main.c @@ -239,7 +239,7 @@ static struct monitor *monitor_create(char *server) char *argv[] = { "cgvm_vnc", "-encodings", "raw", server, NULL }; if(!rfbInitClient(client, &argc, argv)) { - fprintf(stderr, "rfbInitClient failed\n"); + fprintf(stderr, "rfbInitClient on server %s failed\n", server); return NULL; } mon->client = client; @@ -268,7 +268,22 @@ static struct monitor *monitor_create(char *server) return mon; } -void monitor_update(struct monitor *mon) +/* Static monitor assignment. If a calculator with the specified serial number + is found, this function determined the only monitor that goes on it. */ +static int monitor_assignment(struct fxlink_device *fdev) +{ + if(!fdev->calc || !fdev->calc->serial); + return -1; + + if(!strcmp(fdev->calc->serial, "IGQcGRe9")) /* Lephe's Graph 90+E */ + return 0; + if(!strcmp(fdev->calc->serial, "hULOJWGL")) /* Lephe's fx-CG 50 */ + return 1; + + return -1; +} + +void monitor_update(struct monitor *mon, int mon_id) { /* Check if the calculator disconnected */ if(mon->calc) { @@ -297,14 +312,23 @@ void monitor_update(struct monitor *mon) log_("ignoring %s: no fxlink interface\n", id); continue; } + + int assigned_id = monitor_assignment(fdev); + if(assigned_id >= 0 && assigned_id != mon_id) { + hlog("cgvm"); + log_("reserving %s for its statically-assigned monitor %d\n", + assigned_id); + } if(!fxlink_device_claim_fxlink(fdev)) continue; hlog("cgvm"); - log_("starting virtual monitor on %s\n", id); + log_("starting virtual monitor #%d on %s (serial: %s)\n", + mon_id, id, fdev->calc->serial); mon->calc = fdev; mon->calc_unique_id = fdev->dp; fxlink_device_start_bulk_IN(fdev); + break; } } @@ -360,8 +384,10 @@ int main(int argc, char **argv) /** Initialize monitors **/ - app.monitors[0] = monitor_create("127.0.0.1"); - if(!app.monitors[0]) + app.monitors[0] = monitor_create("127.0.0.1:5900"); + app.monitors[1] = monitor_create("127.0.0.1:5910"); + + if(!app.monitors[0] && !app.monitors[1]) return 1; while(1) { @@ -402,7 +428,7 @@ int main(int argc, char **argv) for(int i = 0; i < MONITOR_COUNT; i++) { struct monitor *mon = app.monitors[i]; if(mon) - monitor_update(mon); + monitor_update(mon, i); } }