Compare commits

...

4 Commits

18 changed files with 430 additions and 111 deletions

44
CMakeLists.txt Normal file
View File

@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 2.8)
project(xfree)
#include_directories(/home/alexander/repositories/iup/include)
include_directories(/root/iup/include)
set(SOURCE_EXE
address.c
arguments.c
concat.c
db.c
gui.c
images.c
monitor.c
node_settings.c
rxrandr_broker.c
rxrandr.c
settings.c
xfreerdp.c
xrdp.c
)
add_executable(xfree ${SOURCE_EXE})
#target_link_libraries(xfree iup X11 Xrandr m /home/alexander/programming/c/iup/sqlite3.a)
target_link_libraries(xfree
gtk-3
gdk-3
pangocairo-1.0
pango-1.0
atk-1.0
cairo-gobject
cairo
gdk_pixbuf-2.0
gio-2.0
gobject-2.0
glib-2.0
X11
Xrandr
m
dl
pthread
/root/iup/lib/Linux515/libiup.a
/root/SQLite/sqlite3.a
)
#target_link_libraries(xfree iup X11 Xrandr m sqlite3 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lX11 -lXrandr -lm)

View File

@ -21,8 +21,9 @@ char *getHostIP(char *dnsName)
if (he)
{
char *ip = inet_ntoa(*(struct in_addr*)he->h_addr);
result = (char *)malloc(sizeof(char) * strlen(ip));
strcpy(result, ip);
size_t size = strlen(ip) + 1;
result = (char *)malloc(sizeof(char) * size);
strncpy(result, ip, size);
}
return result;
}

View File

@ -10,51 +10,23 @@
#include "node_settings.h"
#include "concat.h"
#include "xrandr.h"
#include "rxrandr.h"
#include "db.h"
#include "monitor.h"
void settingsLoad()
void settingsLoad(char *pathDB)
{
// dbGetHostsList();
if (!dbLoadData())
getPathDB(pathDB);
dbLoadData();
Monitors *monitors = loadMonitors();
for (size_t i = 0; i < monitors->size; ++i)
{
addParameterKey(PARAMETER_XFREERDP, "xfreerdp", true, true, NULL, NULL);
addParameterKey(PARAMETER_SERVER, "/v:", true, true, NULL, NULL);
addParameterKey(PARAMETER_USERNAME, "/u:", true, true, NULL, NULL);
addParameterKey(PARAMETER_PASSWORD, "/p:", true, true, NULL, NULL);
addParameterKey(PARAMETER_CERTIGNORE, "/cert-ignore", true, true, NULL, NULL);
addParameterKey(PARAMETER_THEMES, "-themes", false, true, NULL, NULL);
addParameterKey(PARAMETER_WALLPAPER, "-wallpaper", false, true, NULL, NULL);
addParameterKey(PARAMETER_ENCRYPTION, "-encryption", false, true, NULL, NULL);
addParameterKey(PARAMETER_FONTS, "-fonts", false, true, NULL, NULL);
addParameterKey(PARAMETER_SOUND, "/sound", false, true, NULL, NULL);
addParameterKey(PARAMETER_COMPRESSION, "+compression", false, true, NULL, NULL);
addParameterKey(PARAMETER_FULLSCREEN, "/f", false, true, NULL, NULL);
addParameterKey(PARAMETER_MULTIMONITOR, "/multimon", false, true, getParameter(PARAMETER_FULLSCREEN), NULL);
addParameterKey(PARAMETER_AUTHENTICATION, "-authentication", true, true, NULL, NULL);
addParameterKey(PARAMETER_SECURITY, "/sec:", true, true, NULL, NULL);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_TLS, "tls", true);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_RDP, "rdp", false);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_NLA, "nla", false);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_EXT, "ext", false);
addParameterKey(PARAMETER_BITSPERPIXEL, "/bpp:", true, true, NULL, NULL);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_8, "8", true);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_16, "16", false);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_24, "24", false);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_32, "32", false);
addParameterKey(PARAMETER_USB, "/a:drive,USB,", true, true, NULL, NULL);
addParameterValue(PARAMETER_USB, VALUES_USB_DRIVE, "/mnt/usbdevice", true);
addParameterKey(PARAMETER_MONITORS, "/monitors:", false, true, getParameter(PARAMETER_FULLSCREEN), getParameter(PARAMETER_MULTIMONITOR));
addParameterValue(PARAMETER_MONITORS, i, monitors->monitor[i]->data[3], !i);
}
x_info *monitors = getXInfo();
for (size_t i = 0; i < monitors->count; ++i)
{
addParameterValue(PARAMETER_MONITORS, i, monitors->monitor[i].ptrIndexMonitor, !i);
}
freeXInfo(monitors);
dbFreeMonitors(monitors);
}
void settingsFree()

View File

@ -17,7 +17,7 @@ typedef struct
void buildArguments(Arguments *args);
void freeArguments(Arguments *args);
void settingsLoad();
void settingsLoad(char *pathDB);
void settingsFree();
#endif /* ARGUMENTS_H_ */

View File

@ -26,11 +26,11 @@ char* concat(char *s1, char *s2)
if (s1)
{
strcpy(result, s1);
strncpy(result, s1, (len1 + 1));
}
if (s2)
{
strcpy(result + len1, s2);
strncpy(result + len1, s2, (len2 + 1));
}
return result;

251
db.c
View File

@ -5,16 +5,26 @@
* Author: alexander
*/
#include <stdbool.h>
#include "sqlite3.h"
#include <stdlib.h>
//#include <sqlite3.h>
#include <stdio.h>
#include <string.h>
#include "db.h"
#include "node_settings.h"
static sqlite3 *dbGetBase(char *path)
char* getPathDB(char *path)
{
static char *current = NULL;
if (path && !current)
{
current = path;
}
return current;
}
static sqlite3* dbGetBase(char *path)
{
sqlite3 *db = NULL;
@ -42,35 +52,24 @@ static sqlite3 *dbGetBase(char *path)
*/
static int dbLoad(void *NotUsed, int argc, char **argv, char **azColName)
{
NotUsed = 0;
char **parameters = (char **) malloc(sizeof(char*) * argc);
for (int i = 0; i < argc; i++)
if (!getParameter(atoi(argv[0])))
{
parameters[i] = argv[i];
addParameterKey(atoi(argv[0]), argv[1], atoi(argv[2]), atoi(argv[3]),
(argv[7] ? getParameter(atoi(argv[7])) : NULL),
(argv[8] ? getParameter(atoi(argv[8])) : NULL));
}
if (!getParameter(atoi(parameters[0])))
if (argv[4] && argv[5])
{
addParameterKey(atoi(parameters[0]), parameters[1], atoi(parameters[2]), atoi(parameters[3]),
parameters[7] ? getParameter(atoi(parameters[7])) : NULL,
parameters[8] ? getParameter(atoi(parameters[8])) : NULL);
addParameterValue(atoi(argv[0]), atoi(argv[4]), argv[5], atoi(argv[6]));
}
if (parameters[4] && parameters[5])
{
addParameterValue(atoi(parameters[0]), atoi(parameters[4]), parameters[5], atoi(parameters[6]));
}
free(parameters);
return 0;
}
bool dbLoadData()
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -100,15 +99,16 @@ bool dbLoadData()
static int dbCreateHostsList(void *answer, int argc, char **argv, char **azColName)
{
Hosts *hosts = *(Hosts **)answer;
Hosts *hosts = *(Hosts**) answer;
Host *host = (Host*) malloc(sizeof(Host));
host->data = (char **) malloc(sizeof(char*) * argc);
host->data = (char**) malloc(sizeof(char*) * argc);
host->size = argc;
for (int i = 0; i < argc; i++)
{
host->data[i] = (char *) malloc(sizeof(char) * strlen(argv[i]));
strcpy(host->data[i], argv[i]);
size_t size = strlen(argv[i]) + 1;
host->data[i] = (char*) malloc(sizeof(char) * size);
strncpy(host->data[i], argv[i], size);
}
Host **tmp = hosts->host;
@ -126,9 +126,9 @@ static int dbCreateHostsList(void *answer, int argc, char **argv, char **azColNa
return 0;
}
Hosts *dbGetHostsList()
Hosts* dbGetHostsList()
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -136,8 +136,7 @@ Hosts *dbGetHostsList()
char *err_msg = 0;
char *sql = "SELECT ROW_NUMBER () OVER (ORDER BY `hosts`.`ip`) `item`, `hosts`.`dns` as `dns`, `hosts`.`set` as `set` FROM `hosts` as `hosts`";
Hosts *hosts = (Hosts *) malloc(sizeof(Hosts));
Hosts *hosts = (Hosts*) malloc(sizeof(Hosts));
hosts->size = 0;
hosts->host = NULL;
@ -148,9 +147,7 @@ Hosts *dbGetHostsList()
sqlite3_close(db);
exit(-1);
}
sqlite3_close(db);
return hosts;
}
@ -162,6 +159,7 @@ void dbFreeHosts(Hosts *hosts)
{
free(hosts->host[i]->data[j]);
}
free(hosts->host[i]->data);
free(hosts->host[i]);
}
free(hosts);
@ -169,7 +167,7 @@ void dbFreeHosts(Hosts *hosts)
bool dbWriteParameter(Parameter name, bool set)
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -184,7 +182,6 @@ bool dbWriteParameter(Parameter name, bool set)
sqlite3_bind_int(res, 2, name);
}
if (sqlite3_step(res) == SQLITE_BUSY)
{
fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", set ? "включено" : "выключено", getParameter(name)->key);
@ -206,7 +203,7 @@ bool dbWriteParameter(Parameter name, bool set)
bool dbWriteValue(Value name, bool set)
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -247,7 +244,7 @@ int dbAddServer(char *ip, char *dns)
if (!(ip && strlen(ip) && dns && strlen(dns)))
return -1;
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;
@ -268,7 +265,7 @@ int dbAddServer(char *ip, char *dns)
if (sqlite3_step(res) == SQLITE_ROW)
{
int id = atoi((const char *)sqlite3_column_text(res, 0));
int id = atoi((const char*) sqlite3_column_text(res, 0));
sqlite3_finalize(res);
sql = "UPDATE `hosts` set `set` = 0";
@ -303,7 +300,7 @@ int dbAddServer(char *ip, char *dns)
result = -5;
}
}
else if(sqlite3_step(res) == SQLITE_DONE)
else if (sqlite3_step(res) == SQLITE_DONE)
{
sqlite3_finalize(res);
@ -351,7 +348,7 @@ int dbAddServer(char *ip, char *dns)
bool dbSetUserNameCurrent(char *current)
{
sqlite3 *db = dbGetBase("freerdp.db");
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
@ -386,3 +383,181 @@ bool dbSetUserNameCurrent(char *current)
return true;
}
static int dbCreateMonitorsList(void *answer, int argc, char **argv, char **azColName)
{
Monitors *monitors = *(Monitors**) answer;
Monitor *monitor = (Monitor*) malloc(sizeof(Monitor));
monitor->data = (char**) malloc(sizeof(char*) * argc);
monitor->size = argc;
for (int i = 0; i < argc; i++)
{
size_t size = strlen(argv[i]) + 1;
monitor->data[i] = (char*) malloc(sizeof(char) * size);
strncpy(monitor->data[i], argv[i], size);
}
Monitor **tmp = monitors->monitor;
monitors->monitor = (Monitor**) malloc(sizeof(Monitor*) * ++monitors->size);
for (size_t i = 0; i < monitors->size - 1; ++i)
{
monitors->monitor[i] = tmp[i];
}
if (tmp)
{
free(tmp);
}
monitors->monitor[monitors->size - 1] = monitor;
return 0;
}
Monitors* dbGetMonitorsList()
{
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
exit(-1);
}
char *err_msg = 0;
char *sql =
"SELECT ROW_NUMBER () OVER (ORDER BY `monitors`.`set` DESC) `item`, `monitors`.`name` as `name`, `monitors`.`set` as `set`, (ROW_NUMBER () OVER (ORDER BY `monitors`.`id`)) - 1 `item` FROM `monitors` as `monitors`";
Monitors *monitors = (Monitors*) malloc(sizeof(Monitors));
monitors->size = 0;
monitors->monitor = NULL;
if (sqlite3_exec(db, sql, dbCreateMonitorsList, &monitors, &err_msg) != SQLITE_OK)
{
fprintf(stderr, "Получение списка мониторов. Ошибка выполнения запроса: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
exit(-2);
}
sqlite3_close(db);
return monitors;
}
void dbFreeMonitors(Monitors *monitors)
{
for (size_t i = 0; i < monitors->size; ++i)
{
for (size_t j = 0; j < monitors->monitor[i]->size; ++j)
{
free(monitors->monitor[i]->data[j]);
}
free(monitors->monitor[i]->data);
free(monitors->monitor[i]);
}
free(monitors);
}
bool deleteAllMonitors()
{
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return false;
}
bool result = false;
char *sql = "DELETE FROM `monitors`";
if (sqlite3_exec(db, sql, NULL, NULL, NULL) == SQLITE_OK)
{
result = true;
}
sqlite3_close(db);
return result;
}
int dbAddMonitor(char *monitor, bool set)
{
if (!(monitor && strlen(monitor)))
return -1;
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;
}
sqlite3_stmt *res;
char *sql = "INSERT INTO `monitors` (`name`, `set`) VALUES (?, ?)";
if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK)
{
sqlite3_bind_text(res, 1, monitor, -1, 0);
sqlite3_bind_int(res, 2, set);
}
// if (sqlite3_step(res) == SQLITE_BUSY)
// {
// fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", text ? "установлено" : "очищено", text ? getValue(VALUE_USERNAME)->current : "");
// }
// if (sqlite3_step(res) == SQLITE_ERROR)
// {
// fprintf(stderr, "[ОШИБКА] %s - \"%s\"\n", text ? "установлено" : "очищено", text ? getValue(VALUE_USERNAME)->current : "");
// }
if (sqlite3_step(res) == SQLITE_DONE)
{
fprintf(stdout, "[УСПЕШНО] %s - \"%s\"\n", monitor ? "установлено" : "очищено", monitor ? monitor : "");
return 0;
}
sqlite3_finalize(res);
sqlite3_close(db);
return -3;
}
int dbSaveMonitors(char *name)
{
int result = 0;
if (!(name && strlen(name)))
return -1;
sqlite3 *db = dbGetBase(getPathDB(NULL));
if (!db)
{
return -2;
}
char *sql = "UPDATE `monitors` set `set` = 0";
if (sqlite3_exec(db, sql, NULL, NULL, NULL) == SQLITE_OK)
{
sqlite3_stmt *res;
sql = "UPDATE `monitors` SET `set` = 1 WHERE `name` = ?";
if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK)
{
sqlite3_bind_text(res, 1, name, -1, 0);
}
if (sqlite3_step(res) == SQLITE_BUSY)
{
fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", name ? "установлено" : "очищено", name);
result = 2;
}
if (sqlite3_step(res) == SQLITE_ERROR)
{
fprintf(stderr, "[ОШИБКА] %s - \"%s\"\n", name ? "установлено" : "очищено", name);
result = 1;
}
if (sqlite3_step(res) == SQLITE_DONE)
{
fprintf(stdout, "[УСПЕШНО] %s - \"%s\"\n", name ? "установлено" : "очищено", name);
result = 0;
}
sqlite3_finalize(res);
}
sqlite3_close(db);
return result;
}

22
db.h
View File

@ -8,6 +8,9 @@
#ifndef DB_H_
#define DB_H_
#include <stdlib.h>
#include <stdbool.h>
#include "parameter.h"
#include "value.h"
@ -23,9 +26,28 @@ typedef struct Hosts
size_t size;
} Hosts;
typedef struct Monitor
{
char **data;
size_t size;
} Monitor;
typedef struct Monitors
{
Monitor **monitor;
size_t size;
} Monitors;
char *getPathDB(char *path);
bool dbLoadData();
Hosts *dbGetHostsList();
void dbFreeHosts(Hosts *hosts);
Monitors *dbGetMonitorsList();
void dbFreeMonitors(Monitors *monitors);
bool deleteAllMonitors();
int dbAddMonitor(char *monitor, bool set);
int dbSaveMonitors(char *name);
bool dbWriteParameter(Parameter name, bool set);
bool dbWriteValue(Value name, bool set);
bool dbSetUserNameCurrent(char *current);

Binary file not shown.

10
gui.c
View File

@ -65,10 +65,12 @@ static void createHostsList(Ihandle *iupList)
for (size_t i = 0; i < hosts->size; ++i)
{
Host *host = hosts->host[i];
indexItem = (char *)malloc(sizeof(char) * strlen(host->data[0]));
strcpy(indexItem, host->data[0]);
serverName = (char *)malloc(sizeof(char) * strlen(host->data[1]));
strcpy(serverName, host->data[1]);
size_t size = strlen(host->data[0]) + 1;
indexItem = (char *)malloc(sizeof(char) * size);
strncpy(indexItem, host->data[0], size);
size = strlen(host->data[1]) + 1;
serverName = (char *)malloc(sizeof(char) * size);
strncpy(serverName, host->data[1], size);
IupSetAttribute(iupList, indexItem, serverName);
if (atoi(host->data[2]))

84
monitor.c Normal file
View File

@ -0,0 +1,84 @@
/*
* 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);
}

16
monitor.h Normal file
View File

@ -0,0 +1,16 @@
/*
* monitor.h
*
* Created on: 18 июл. 2022 г.
* Author: alexander
*/
#ifndef MONITOR_H_
#define MONITOR_H_
#include "db.h"
Monitors *loadMonitors();
void freeMonitors(Monitors *monitors);
#endif /* MONITOR_H_ */

View File

@ -24,8 +24,9 @@ static NodeValue* newNodeValue(Value name, char *current, bool set)
node->change = false;
node->next = NULL;
node->current = (char*) malloc(sizeof(char) * strlen(current));
strcpy(node->current, current);
size_t size = strlen(current) + 1;
node->current = (char*) malloc(sizeof(char) * size);
strncpy(node->current, current, size);
return node;
}
@ -63,8 +64,9 @@ static NodeParameter* newNodeParameter(Parameter name, char *key, bool set, bool
node->conflict = conflict;
node->next = NULL;
node->key = (char*) malloc(sizeof(char) * strlen(key));
strcpy(node->key, key);
size_t size = strlen(key) + 1;
node->key = (char*) malloc(sizeof(char) * size);
strncpy(node->key, key, size);
return node;
}
@ -304,7 +306,7 @@ void setParameterValue(Parameter pName, Value vName, char *current)
return;
}
size_t length = strlen(current);
size_t length = strlen(current) + 1;
if (!length)
{
@ -338,7 +340,7 @@ void setParameterValue(Parameter pName, Value vName, char *current)
{
free(nodeValue->current);
nodeValue->current = (char*) malloc(sizeof(char) * length);
strcpy(nodeValue->current, current);
strncpy(nodeValue->current, current, length);
}
else
{

View File

@ -22,8 +22,8 @@ typedef enum
PARAMETER_SOUND,
PARAMETER_COMPRESSION,
PARAMETER_FULLSCREEN,
PARAMETER_MONITORS,
PARAMETER_MULTIMONITOR,
PARAMETER_MONITORS,
PARAMETER_AUTHENTICATION,
PARAMETER_SECURITY,
PARAMETER_BITSPERPIXEL,

View File

@ -15,7 +15,7 @@
#include <unistd.h>
#include "xrandr.h"
#include "rxrandr.h"
static char *program_name;
static Display *dpy;

View File

View File

@ -5,7 +5,7 @@
* Author: alexander
*/
#include "xrandr.h"
#include "rxrandr.h"
#include <stdlib.h>
#include <stdio.h>
@ -14,15 +14,18 @@
x_info *getXInfo()
{
x_info *monitors = (x_info *) malloc(sizeof(x_info));
monitors->count = 0;
XInfo(monitors);
for (int i = 0; i < monitors->count; ++i)
{
monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * strlen(monitors->monitor[i].name));
size_t size = strlen(monitors->monitor[i].name) + 1;
monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * size);
monitors->monitor[i].ptrIndexItem = (char *)malloc(sizeof(char) * 3);
monitors->monitor[i].ptrIndexMonitor = (char *)malloc(sizeof(char) * 3);
strcpy(monitors->monitor[i].ptrName, monitors->monitor[i].name);
strncpy(monitors->monitor[i].ptrName, monitors->monitor[i].name, size);
sprintf(monitors->monitor[i].ptrIndexItem, "%d", i + 1);
sprintf(monitors->monitor[i].ptrIndexMonitor, "%d", i);
}

View File

@ -10,7 +10,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include "xrandr.h"
#include "monitor.h"
#include <stdio.h>
#include "settings.h"
@ -33,6 +33,7 @@ static int settingsClose(Ihandle *self)
static int settingsSave(Ihandle *self)
{
saveChangeSettings();
dbSaveMonitors(IupGetAttribute(IupGetDialogChild(self, "MONITORS"), "VALUESTRING"));
IupSetAttribute(IupGetDialog(self), "SIMULATEMODAL", "OFF");
IupHide(IupGetDialog(self));
return IUP_DEFAULT;
@ -324,27 +325,21 @@ static Ihandle* settingsBoxMonitor()
tglFullscreen = IupToggle("На весь экран", NULL);
ddMonitor = IupList(NULL);
x_info *monitors = getXInfo();
char *allMonitorIndex = (char*) malloc(sizeof(char) * 3);
sprintf(allMonitorIndex, "%hu", monitors->count + 1);
size_t setValueIndex = 0;
for (short i = 0; i < monitors->count; ++i)
Monitors *monitors = loadMonitors();
for (size_t i = 0; i < monitors->size; ++i)
{
IupSetAttribute(ddMonitor, monitors->monitor[i].ptrIndexItem, monitors->monitor[i].ptrName);
if (getSetValue(PARAMETER_MONITORS, i))
setValueIndex = i + 1;
IupSetAttribute(ddMonitor, monitors->monitor[i]->data[0], monitors->monitor[i]->data[1]);
if (monitors->monitor[i]->data[2][0] == '1')
IupSetAttribute(ddMonitor, "VALUE", monitors->monitor[i]->data[0]);
}
freeMonitors(monitors);
IupSetInt(ddMonitor, "VALUE", setValueIndex ? setValueIndex : 1);
IupSetInt(tglMultimonitor, "VALUE", getSetParameter(PARAMETER_MULTIMONITOR));
IupSetInt(tglFullscreen, "VALUE", getSetParameter(PARAMETER_FULLSCREEN));
IupSetInt(tglMultimonitor, "ACTIVE", getSetParameter(PARAMETER_FULLSCREEN));
IupSetInt(ddMonitor, "ACTIVE", getSetParameter(PARAMETER_FULLSCREEN) && !getSetParameter(PARAMETER_MULTIMONITOR));
free(monitors);
return IupSetAttributes(
IupFrame(
IupVbox(

View File

@ -6,7 +6,10 @@
int main(int argc, char **argv)
{
settingsLoad();
if (argc > 1)
settingsLoad(argv[1]);
else
settingsLoad("/etc/freerdp/freerdp.db");
IupOpen(&argc, &argv);