Добавление работы с мониторами

This commit is contained in:
Alexander Zhirov 2022-07-11 13:12:29 +03:00
parent 5a6aef9424
commit cb57c8d92a
7 changed files with 2367 additions and 21 deletions

View File

@ -16,14 +16,22 @@ void settingsLoad()
addParameterKey(PARAMETER_SERVER, "/v:", true, true);
addParameterKey(PARAMETER_USERNAME, "/u:", true, true);
addParameterKey(PARAMETER_PASSWORD, "/p:", true, true);
addParameterKey(PARAMETER_MULTIMONITOR, "/multimon", true, true);
addParameterKey(PARAMETER_CERTIGNORE, "/cert-ignore", false, true);
addParameterKey(PARAMETER_THEMES, "-themes", false, true);
addParameterKey(PARAMETER_WALLPAPER, "-wallpaper", false, true);
addParameterKey(PARAMETER_FULLSCREEN, "/f", true, true);
addParameterKey(PARAMETER_MULTIMONITOR, "/multimon", true, true);
addParameterKey(PARAMETER_AUTHENTICATION, "-authentication", true, true);
addParameterKey(PARAMETER_SECURITY, "/sec:", true, true);
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);
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);
}
void settingsFree()

View File

@ -14,10 +14,14 @@ typedef enum
PARAMETER_SERVER,
PARAMETER_USERNAME,
PARAMETER_PASSWORD,
PARAMETER_CERTIGNORE,
PARAMETER_THEMES,
PARAMETER_WALLPAPER,
PARAMETER_MULTIMONITOR,
PARAMETER_FULLSCREEN,
PARAMETER_AUTHENTICATION,
PARAMETER_SECURITY
PARAMETER_SECURITY,
PARAMETER_BITSPERPIXEL,
} Parameter;
#endif /* PARAMETERS_H_ */

View File

@ -10,6 +10,8 @@
#include <stdlib.h>
#include <stdbool.h>
#include "xrandr.h"
#include "settings.h"
#include "arguments.h"
#include "node_settings.h"
@ -19,7 +21,6 @@ void toggleActive(Ihandle *self, char *name)
IupSetInt(IupGetDialogChild(self, name), "ACTIVE", !IupGetInt(IupGetDialogChild(self, name), "ACTIVE"));
}
static int settingsClose(Ihandle *self)
{
resetChangeSettings();
@ -54,6 +55,24 @@ static int settingsTglAuthentication(Ihandle *self)
return IUP_DEFAULT;
}
static int settingsTglCertIgnore(Ihandle *self)
{
changeParameter(PARAMETER_CERTIGNORE);
return IUP_DEFAULT;
}
static int settingsTglThemes(Ihandle *self)
{
changeParameter(PARAMETER_THEMES);
return IUP_DEFAULT;
}
static int settingsTglWallpaper(Ihandle *self)
{
changeParameter(PARAMETER_WALLPAPER);
return IUP_DEFAULT;
}
static int settingsUseSecurity(Ihandle *self)
{
changeParameter(PARAMETER_SECURITY);
@ -96,29 +115,92 @@ static void settingsChooseSecurity(Ihandle *self, int state)
}
}
static int settingsUseBitsPerPixel(Ihandle *self)
{
changeParameter(PARAMETER_BITSPERPIXEL);
toggleActive(self, "BITSPERPIXEL_8");
toggleActive(self, "BITSPERPIXEL_16");
toggleActive(self, "BITSPERPIXEL_24");
toggleActive(self, "BITSPERPIXEL_32");
return IUP_DEFAULT;
}
static void settingsChooseBitsPerPixel(Ihandle *self, int state)
{
if (state == 1)
{
int tool_index = IupGetInt(self, "TOOLINDEX");
switch (tool_index)
{
case 0:
{
changeValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_8);
break;
}
case 1:
{
changeValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_16);
break;
}
case 2:
{
changeValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_24);
break;
}
case 3:
{
changeValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_32);
break;
}
}
}
}
static int settingsChooseMonitor(Ihandle *self)
{
// printf("%d\n", IupGetInt(IupGetDialogChild(self, "VALUE"), "ACTIVE"));
return IUP_DEFAULT;
}
/*
* Блок настроек
*/
static Ihandle* settingsBoxCheckbox()
{
Ihandle *tglMultimonitor, *tglFullscreen, *tglAuthentication;
Ihandle *tglMultimonitor, *tglFullscreen, *tglAuthentication, *tglCertIgnore, *tglThemes, *tglWallpaper;
tglMultimonitor = IupToggle("Несколько мониторов", NULL);
tglFullscreen = IupToggle("На весь экран", NULL);
tglAuthentication = IupToggle("Аутентификация", NULL);
tglCertIgnore = IupToggle("Игнорировать сертификат", NULL);
tglThemes = IupToggle("Отключить темы", NULL);
tglWallpaper = IupToggle("Отключить обои", NULL);
IupSetInt(tglMultimonitor, "VALUE", getSetParameter(PARAMETER_MULTIMONITOR));
IupSetInt(tglFullscreen, "VALUE", getSetParameter(PARAMETER_FULLSCREEN));
IupSetInt(tglAuthentication, "VALUE", getSetParameter(PARAMETER_AUTHENTICATION));
IupSetInt(tglCertIgnore, "VALUE", getSetParameter(PARAMETER_CERTIGNORE));
IupSetInt(tglThemes, "VALUE", getSetParameter(PARAMETER_THEMES));
IupSetInt(tglWallpaper, "VALUE", getSetParameter(PARAMETER_WALLPAPER));
return IupHbox(IupSetAttributes(IupFrame(IupVbox(
IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR"), "ACTION",
(Icallback) settingsTglMultimonitor, NULL),
IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN"), "ACTION",
(Icallback) settingsTglFullscreen, NULL),
IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
(Icallback) settingsTglAuthentication, NULL),
NULL)), "TITLE=\"Общие\""), NULL);
return IupHbox(
IupSetAttributes(
IupFrame(
IupVbox(
IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR"), "ACTION",
(Icallback) settingsTglMultimonitor, NULL),
IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN"), "ACTION",
(Icallback) settingsTglFullscreen, NULL),
IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
(Icallback) settingsTglAuthentication, NULL),
IupSetCallbacks(IupSetAttributes(tglCertIgnore, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
(Icallback) settingsTglCertIgnore, NULL),
IupSetCallbacks(IupSetAttributes(tglThemes, "NAME=SETTINGS_TGL_THEMES"), "ACTION", (Icallback) settingsTglThemes,
NULL),
IupSetCallbacks(IupSetAttributes(tglWallpaper, "NAME=SETTINGS_TGL_WALLPAPER"), "ACTION",
(Icallback) settingsTglWallpaper, NULL),
NULL)), "TITLE=\"Общие\""), NULL);
}
static Ihandle* settingsBoxSecurity()
@ -129,7 +211,7 @@ static Ihandle* settingsBoxSecurity()
tglSecurity = IupToggle("Использовать", NULL);
IupSetInt(tglSecurity, "VALUE", getSetParameter(PARAMETER_SECURITY));
IupSetCallback(tglSecurity, "ACTION", (Icallback)settingsUseSecurity);
IupSetCallback(tglSecurity, "ACTION", (Icallback) settingsUseSecurity);
tglTLS = IupToggle("TLS", NULL);
IupSetInt(tglTLS, "VALUE", getSetValue(PARAMETER_SECURITY, VALUE_SECURITY_TLS));
@ -144,19 +226,73 @@ static Ihandle* settingsBoxSecurity()
IupSetInt(tglEXT, "VALUE", getSetValue(PARAMETER_SECURITY, VALUE_SECURITY_EXT));
IupSetInt(tglEXT, "ACTIVE", getSetParameter(PARAMETER_SECURITY));
grdSecurity = IupRadio(IupGridBox(
IupSetCallbacks(IupSetAttributes(tglTLS, "NAME=SECURITY_TLS, TOOLINDEX=0"), "ACTION", (Icallback)settingsChooseSecurity, NULL),
IupSetCallbacks(IupSetAttributes(tglRDP, "NAME=SECURITY_RDP, TOOLINDEX=1"), "ACTION", (Icallback)settingsChooseSecurity, NULL),
IupSetCallbacks(IupSetAttributes(tglNLA, "NAME=SECURITY_NLA, TOOLINDEX=2"), "ACTION", (Icallback)settingsChooseSecurity, NULL),
IupSetCallbacks(IupSetAttributes(tglEXT, "NAME=SECURITY_EXT, TOOLINDEX=3"), "ACTION", (Icallback)settingsChooseSecurity, NULL),
NULL));
grdSecurity = IupRadio(
IupGridBox(
IupSetCallbacks(IupSetAttributes(tglTLS, "NAME=SECURITY_TLS, TOOLINDEX=0"), "ACTION", (Icallback) settingsChooseSecurity, NULL),
IupSetCallbacks(IupSetAttributes(tglRDP, "NAME=SECURITY_RDP, TOOLINDEX=1"), "ACTION", (Icallback) settingsChooseSecurity, NULL),
IupSetCallbacks(IupSetAttributes(tglNLA, "NAME=SECURITY_NLA, TOOLINDEX=2"), "ACTION", (Icallback) settingsChooseSecurity, NULL),
IupSetCallbacks(IupSetAttributes(tglEXT, "NAME=SECURITY_EXT, TOOLINDEX=3"), "ACTION", (Icallback) settingsChooseSecurity, NULL),
NULL));
return IupHbox(IupSetAttributes(IupFrame(IupVbox(tglSecurity, grdSecurity, NULL)), "TITLE=\"Протокол безопасности\", MARGIN=15x10"), NULL);
}
static Ihandle* settingsBoxBitsPerPixel()
{
Ihandle *tglBitsPerPixel;
Ihandle *tgl8, *tgl16, *tgl24, *tgl32;
Ihandle *grdBitsPerPixel;
tglBitsPerPixel = IupToggle("Использовать", NULL);
IupSetInt(tglBitsPerPixel, "VALUE", getSetParameter(PARAMETER_BITSPERPIXEL));
IupSetCallback(tglBitsPerPixel, "ACTION", (Icallback) settingsUseBitsPerPixel);
tgl8 = IupToggle("8 бит", NULL);
IupSetInt(tgl8, "VALUE", getSetValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_8));
IupSetInt(tgl8, "ACTIVE", getSetParameter(PARAMETER_BITSPERPIXEL));
tgl16 = IupToggle("16 бит", NULL);
IupSetInt(tgl16, "VALUE", getSetValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_16));
IupSetInt(tgl16, "ACTIVE", getSetParameter(PARAMETER_BITSPERPIXEL));
tgl24 = IupToggle("24 бит", NULL);
IupSetInt(tgl24, "VALUE", getSetValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_24));
IupSetInt(tgl24, "ACTIVE", getSetParameter(PARAMETER_BITSPERPIXEL));
tgl32 = IupToggle("32 бит", NULL);
IupSetInt(tgl32, "VALUE", getSetValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_32));
IupSetInt(tgl32, "ACTIVE", getSetParameter(PARAMETER_BITSPERPIXEL));
grdBitsPerPixel = IupRadio(
IupGridBox(IupSetCallbacks(IupSetAttributes(tgl8, "NAME=BITSPERPIXEL_8, TOOLINDEX=0"), "ACTION", (Icallback) settingsChooseBitsPerPixel,
NULL), IupSetCallbacks(IupSetAttributes(tgl16, "NAME=BITSPERPIXEL_16, TOOLINDEX=1"), "ACTION", (Icallback) settingsChooseBitsPerPixel,
NULL), IupSetCallbacks(IupSetAttributes(tgl24, "NAME=BITSPERPIXEL_24, TOOLINDEX=2"), "ACTION", (Icallback) settingsChooseBitsPerPixel,
NULL), IupSetCallbacks(IupSetAttributes(tgl32, "NAME=BITSPERPIXEL_32, TOOLINDEX=3"), "ACTION", (Icallback) settingsChooseBitsPerPixel,
NULL),
NULL));
return IupHbox(IupSetAttributes(IupFrame(IupVbox(tglBitsPerPixel, grdBitsPerPixel, NULL)), "TITLE=\"Глубина цвета\", MARGIN=15x10"), NULL);
}
static Ihandle* settingsBoxMonitor()
{
Ihandle *ddMonitor;
ddMonitor = IupList(NULL);
x_info *monitors = getXInfo();
for (short i = 0; i < monitors->count; ++i)
{
IupSetAttribute(ddMonitor, monitors->monitor[i].ptrIndex, monitors->monitor[i].ptrName);
}
free(monitors);
return IupSetCallbacks(IupSetAttributes(ddMonitor,
"DROPDOWN=YES, VALUE=1"), "ACTION", (Icallback) settingsChooseMonitor, NULL);
}
static Ihandle* settingsHorizontalBox()
{
return IupSetAttributes(IupHbox(settingsBoxCheckbox(), settingsBoxSecurity(), NULL), "MARGIN=5x5");
return IupSetAttributes(IupHbox(IupVbox(settingsBoxCheckbox(), settingsBoxMonitor(), NULL), settingsBoxSecurity(), settingsBoxBitsPerPixel(), NULL), "MARGIN=5x5");
}
/*

12
value.h
View File

@ -10,7 +10,17 @@
typedef enum
{
VALUE_SERVER, VALUE_USERNAME, VALUE_PASSWORD, VALUE_SECURITY_TLS, VALUE_SECURITY_RDP, VALUE_SECURITY_NLA, VALUE_SECURITY_EXT,
VALUE_SERVER,
VALUE_USERNAME,
VALUE_PASSWORD,
VALUE_SECURITY_TLS,
VALUE_SECURITY_RDP,
VALUE_SECURITY_NLA,
VALUE_SECURITY_EXT,
VALUES_BITSPERPIXEL_8,
VALUES_BITSPERPIXEL_16,
VALUES_BITSPERPIXEL_24,
VALUES_BITSPERPIXEL_32
} Value;
#endif /* VALUE_H_ */

2129
xrandr.c Normal file

File diff suppressed because it is too large Load Diff

30
xrandr.h Normal file
View File

@ -0,0 +1,30 @@
/*
* xrandr.h
*
* Created on: 11 июл. 2022 г.
* Author: alexander
*/
#ifndef XRANDR_H_
#define XRANDR_H_
typedef struct
{
char name[10];
char *ptrName;
char *ptrIndex;
int width;
int height;
int primary;
} x_monitor;
typedef struct
{
int count;
x_monitor monitor[5];
} x_info;
int XInfo(x_info *info);
x_info *getXInfo();
#endif /* XRANDR_H_ */

29
xrandr_broker.c Normal file
View File

@ -0,0 +1,29 @@
/*
* xrandr_broker.c
*
* Created on: 11 июл. 2022 г.
* Author: alexander
*/
#include "xrandr.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
x_info *getXInfo()
{
x_info *monitors = (x_info *) malloc(sizeof(x_info));
XInfo(monitors);
for (int i = 0; i < monitors->count; ++i)
{
monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * strlen(monitors->monitor[i].name));
monitors->monitor[i].ptrIndex = (char *)malloc(sizeof(char) * 3);
strcpy(monitors->monitor[i].ptrName, monitors->monitor[i].name);
sprintf(monitors->monitor[i].ptrIndex, "%d", i + 1);
}
return monitors;
}