GUI-FreeRDP/freerdp/client/X11/cli/monitor.c

85 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* monitor.c
*
* Created on: 18 июл. 2022 г.
* Author: alexander
*/
#include <string.h>
#include <stdio.h>
#include "monitor.h"
#include "rxrandr.h"
static bool checkMonitor(Monitors *dbMonitors, x_info *pcMonitors)
{
if (!dbMonitors->size || !pcMonitors->count ||
!(dbMonitors->size == pcMonitors->count))
{
return false;
}
bool compare = false;
for (size_t i = 0; i < dbMonitors->size; ++i)
{
for (size_t j = 0; j < pcMonitors->count; ++j)
{
if (!strcmp(pcMonitors->monitor[j].name, dbMonitors->monitor[i]->data[1]))
{
compare = true;
}
}
if (!compare)
{
return false;
}
compare = false;
}
return true;
}
Monitors *loadMonitors()
{
Monitors *dbMonitors = dbGetMonitorsList();
x_info *pcMonitors = getXInfo();
if (!checkMonitor(dbMonitors, pcMonitors)) // Если строки не равны, произвести перезапись в БД
{
if (dbMonitors)
dbFreeMonitors(dbMonitors);
if (!deleteAllMonitors())
{
fprintf(stderr, "Не удалось удалить записи мониторов из БД\n");
exit(1);
}
for (size_t i = 0; i < pcMonitors->count; ++i)
{
dbAddMonitor(pcMonitors->monitor[i].name, pcMonitors->monitor[i].primary);
}
freeXInfo(pcMonitors);
return dbGetMonitorsList();
}
freeXInfo(pcMonitors);
return dbMonitors;
}
void freeMonitors(Monitors *monitors)
{
for (size_t i = 0; i < monitors->size; ++i)
{
free(monitors->monitor[i]->data[2]);
free(monitors->monitor[i]->data[3]);
free(monitors->monitor[i]->data);
free(monitors->monitor[i]);
}
free(monitors);
}