vnc: double monitor setup

This commit is contained in:
Lephenixnoir 2023-03-26 22:34:16 +02:00
parent 9319f162bc
commit 94cfbee2e6
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 32 additions and 6 deletions

View File

@ -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);
}
}