Выбор монитора при подключении

This commit is contained in:
Alexander Zhirov 2022-07-11 20:06:05 +03:00
parent cb57c8d92a
commit 719f159b9a
7 changed files with 165 additions and 63 deletions

View File

@ -10,28 +10,38 @@
#include "node_settings.h" #include "node_settings.h"
#include "concat.h" #include "concat.h"
#include "xrandr.h"
void settingsLoad() void settingsLoad()
{ {
addParameterKey(PARAMETER_XFREERDP, "xfreerdp", true, true); addParameterKey(PARAMETER_XFREERDP, "xfreerdp", true, true, NULL, NULL);
addParameterKey(PARAMETER_SERVER, "/v:", true, true); addParameterKey(PARAMETER_SERVER, "/v:", true, true, NULL, NULL);
addParameterKey(PARAMETER_USERNAME, "/u:", true, true); addParameterKey(PARAMETER_USERNAME, "/u:", true, true, NULL, NULL);
addParameterKey(PARAMETER_PASSWORD, "/p:", true, true); addParameterKey(PARAMETER_PASSWORD, "/p:", true, true, NULL, NULL);
addParameterKey(PARAMETER_CERTIGNORE, "/cert-ignore", false, true); addParameterKey(PARAMETER_CERTIGNORE, "/cert-ignore", false, true, NULL, NULL);
addParameterKey(PARAMETER_THEMES, "-themes", false, true); addParameterKey(PARAMETER_THEMES, "-themes", false, true, NULL, NULL);
addParameterKey(PARAMETER_WALLPAPER, "-wallpaper", false, true); addParameterKey(PARAMETER_WALLPAPER, "-wallpaper", false, true, NULL, NULL);
addParameterKey(PARAMETER_FULLSCREEN, "/f", true, true); addParameterKey(PARAMETER_FULLSCREEN, "/f", false, true, NULL, NULL);
addParameterKey(PARAMETER_MULTIMONITOR, "/multimon", true, true); addParameterKey(PARAMETER_MULTIMONITOR, "/multimon", false, true, getParameter(PARAMETER_FULLSCREEN), NULL);
addParameterKey(PARAMETER_AUTHENTICATION, "-authentication", true, true); addParameterKey(PARAMETER_AUTHENTICATION, "-authentication", true, true, NULL, NULL);
addParameterKey(PARAMETER_SECURITY, "/sec:", true, true); addParameterKey(PARAMETER_SECURITY, "/sec:", true, true, NULL, NULL);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_TLS, "tls", true); addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_TLS, "tls", true);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_RDP, "rdp", false); addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_RDP, "rdp", false);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_NLA, "nla", false); addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_NLA, "nla", false);
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_EXT, "ext", false); addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_EXT, "ext", false);
addParameterKey(PARAMETER_BITSPERPIXEL, "/bpp:", true, true); addParameterKey(PARAMETER_BITSPERPIXEL, "/bpp:", true, true, NULL, NULL);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_8, "8", true); addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_8, "8", true);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_16, "16", false); addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_16, "16", false);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_24, "24", false); addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_24, "24", false);
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_32, "32", false); addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_32, "32", false);
addParameterKey(PARAMETER_MONITORS, "/monitors:", false, true, getParameter(PARAMETER_FULLSCREEN), getParameter(PARAMETER_MULTIMONITOR));
x_info *monitors = getXInfo();
for (size_t i = 0; i < monitors->count; ++i)
{
addParameterValue(PARAMETER_MONITORS, i, monitors->monitor[i].ptrIndexMonitor, !i);
}
freeXInfo(monitors);
} }
void settingsFree() void settingsFree()

View File

@ -48,7 +48,7 @@ static void freeAllNodeValue(NodeValue *node)
} }
} }
static NodeParameter* newNodeParameter(Parameter name, char *key, bool set, bool singleValue) static NodeParameter* newNodeParameter(Parameter name, char *key, bool set, bool singleValue, NodeParameter *dependence, NodeParameter *conflict)
{ {
NodeParameter *node = (NodeParameter*) malloc(sizeof(NodeParameter)); NodeParameter *node = (NodeParameter*) malloc(sizeof(NodeParameter));
node->name = name; node->name = name;
@ -56,7 +56,10 @@ static NodeParameter* newNodeParameter(Parameter name, char *key, bool set, bool
node->change = false; node->change = false;
node->value = NULL; node->value = NULL;
node->countValue = 0; node->countValue = 0;
node->countValueSet = 0;
node->singleValue = singleValue; node->singleValue = singleValue;
node->dependence = dependence;
node->conflict = conflict;
node->next = NULL; node->next = NULL;
node->key = (char*) malloc(sizeof(char) * strlen(key)); node->key = (char*) malloc(sizeof(char) * strlen(key));
@ -116,11 +119,25 @@ static NodeParameter* getNodeParameter(Parameter name)
return NULL; return NULL;
} }
void addParameterKey(Parameter name, char *key, bool set, bool singleValue) NodeParameter* getParameter(Parameter name)
{
for (NodeParameter *head = settings.parameter; head; head = head->next)
{
if (head->name == name)
{
return head;
}
}
return NULL;
}
void addParameterKey(Parameter name, char *key, bool set, bool singleValue, NodeParameter *dependence, NodeParameter *conflict)
{ {
if (!settings.parameter) if (!settings.parameter)
{ {
settings.parameter = newNodeParameter(name, key, set, singleValue); settings.parameter = newNodeParameter(name, key, set, singleValue, dependence, conflict);
++settings.countParameter; ++settings.countParameter;
if (set) if (set)
{ {
@ -138,7 +155,7 @@ void addParameterKey(Parameter name, char *key, bool set, bool singleValue)
else else
{ {
node = getLastNodeParameter(); node = getLastNodeParameter();
node->next = newNodeParameter(name, key, set, singleValue); node->next = newNodeParameter(name, key, set, singleValue, dependence, conflict);
++settings.countParameter; ++settings.countParameter;
if (set) if (set)
{ {
@ -306,6 +323,12 @@ void changeParameter(Parameter name)
} }
void setParameter(Parameter name, bool set)
{
NodeParameter *node = getNodeParameter(name);
node->set = set;
}
void changeValue(Parameter pName, Value vName) void changeValue(Parameter pName, Value vName)
{ {
NodeParameter *pNode = getNodeParameter(pName); NodeParameter *pNode = getNodeParameter(pName);
@ -344,7 +367,10 @@ static void saveChangeSingleValueSettings(NodeParameter *node)
{ {
nChange->change = false; nChange->change = false;
nChange->set = true; nChange->set = true;
nSet->set = false; if (nSet)
{
nSet->set = false;
}
++node->countValueSet; ++node->countValueSet;
} }
} }
@ -376,6 +402,14 @@ void saveChangeSettings()
pHead->change = false; pHead->change = false;
pHead->set = !pHead->set; pHead->set = !pHead->set;
} }
if (pHead->dependence && !pHead->dependence->set)
{
pHead->set = false;
}
if (pHead->conflict && pHead->conflict->set)
{
pHead->set = false;
}
if (pHead->set) if (pHead->set)
{ {
++settings.countParameterSet; ++settings.countParameterSet;
@ -431,3 +465,13 @@ bool getSetValue(Parameter pName, Value vName)
return false; return false;
} }
int getCountValue(Parameter name)
{
NodeParameter *node = getNodeParameter(name);
if (!node)
{
return -1;
}
return node->countValue;
}

View File

@ -32,6 +32,8 @@ typedef struct NodeParameter
bool singleValue; bool singleValue;
size_t countValue; size_t countValue;
size_t countValueSet; size_t countValueSet;
struct NodeParameter *dependence;
struct NodeParameter *conflict;
struct NodeParameter *next; struct NodeParameter *next;
} NodeParameter; } NodeParameter;
@ -44,18 +46,20 @@ typedef struct NodeHead
extern NodeHead settings; extern NodeHead settings;
void addParameterKey(Parameter name, char *key, bool set, bool singleValue); NodeParameter* getParameter(Parameter name);
void addParameterKey(Parameter name, char *key, bool set, bool singleValue, NodeParameter *dependence, NodeParameter *conflict);
void addParameterValue(Parameter pName, Value vName, char *current, bool set); void addParameterValue(Parameter pName, Value vName, char *current, bool set);
void freeSettings(); void freeSettings();
NodeValue *getSetNodeValue(NodeParameter *node); NodeValue *getSetNodeValue(NodeParameter *node);
bool getSetParameter(Parameter name); bool getSetParameter(Parameter name);
bool getSetValue(Parameter pName, Value vName); bool getSetValue(Parameter pName, Value vName);
int getCountValue(Parameter name);
void changeParameter(Parameter name); void changeParameter(Parameter name);
void changeValue(Parameter pName, Value vName); void changeValue(Parameter pName, Value vName);
void saveChangeSettings(); void saveChangeSettings();
void resetChangeSettings(); void resetChangeSettings();
void setParameter(Parameter name, bool set);
void setParameterValue(Parameter pName, Value vName, char *current); void setParameterValue(Parameter pName, Value vName, char *current);
#endif /* SETTINGS_H_ */ #endif /* SETTINGS_H_ */

View File

@ -17,6 +17,7 @@ typedef enum
PARAMETER_CERTIGNORE, PARAMETER_CERTIGNORE,
PARAMETER_THEMES, PARAMETER_THEMES,
PARAMETER_WALLPAPER, PARAMETER_WALLPAPER,
PARAMETER_MONITORS,
PARAMETER_MULTIMONITOR, PARAMETER_MULTIMONITOR,
PARAMETER_FULLSCREEN, PARAMETER_FULLSCREEN,
PARAMETER_AUTHENTICATION, PARAMETER_AUTHENTICATION,

View File

@ -11,6 +11,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "xrandr.h" #include "xrandr.h"
#include <stdio.h>
#include "settings.h" #include "settings.h"
#include "arguments.h" #include "arguments.h"
@ -37,18 +38,6 @@ static int settingsSave(Ihandle *self)
return IUP_DEFAULT; return IUP_DEFAULT;
} }
static int settingsTglMultimonitor(Ihandle *self)
{
changeParameter(PARAMETER_MULTIMONITOR);
return IUP_DEFAULT;
}
static int settingsTglFullscreen(Ihandle *self)
{
changeParameter(PARAMETER_FULLSCREEN);
return IUP_DEFAULT;
}
static int settingsTglAuthentication(Ihandle *self) static int settingsTglAuthentication(Ihandle *self)
{ {
changeParameter(PARAMETER_AUTHENTICATION); changeParameter(PARAMETER_AUTHENTICATION);
@ -157,9 +146,31 @@ static void settingsChooseBitsPerPixel(Ihandle *self, int state)
} }
} }
static int settingsChooseMonitor(Ihandle *self) static int settingsChooseMonitor(Ihandle *ih, char *text, int item, int state)
{ {
// printf("%d\n", IupGetInt(IupGetDialogChild(self, "VALUE"), "ACTIVE")); if (state == 1)
{
changeValue(PARAMETER_MONITORS, item - 1);
}
return IUP_DEFAULT;
}
static int settingsTglMultimonitor(Ihandle *self)
{
changeParameter(PARAMETER_MULTIMONITOR);
IupSetInt(IupGetDialogChild(self, "MONITORS"), "ACTIVE", !IupGetInt(IupGetDialogChild(self, "SETTINGS_TGL_MULTIMONITOR"), "VALUE"));
setParameter(PARAMETER_MONITORS, !IupGetInt(IupGetDialogChild(self, "SETTINGS_TGL_MULTIMONITOR"), "VALUE"));
return IUP_DEFAULT;
}
static int settingsTglFullscreen(Ihandle *self)
{
changeParameter(PARAMETER_FULLSCREEN);
toggleActive(self, "SETTINGS_TGL_MULTIMONITOR");
IupSetInt(IupGetDialogChild(self, "MONITORS"), "ACTIVE", !IupGetInt(IupGetDialogChild(self, "SETTINGS_TGL_MULTIMONITOR"), "VALUE"));
setParameter(PARAMETER_MONITORS, !IupGetInt(IupGetDialogChild(self, "SETTINGS_TGL_MULTIMONITOR"), "VALUE"));
return IUP_DEFAULT; return IUP_DEFAULT;
} }
@ -168,39 +179,30 @@ static int settingsChooseMonitor(Ihandle *self)
*/ */
static Ihandle* settingsBoxCheckbox() static Ihandle* settingsBoxCheckbox()
{ {
Ihandle *tglMultimonitor, *tglFullscreen, *tglAuthentication, *tglCertIgnore, *tglThemes, *tglWallpaper; Ihandle *tglAuthentication, *tglCertIgnore, *tglThemes, *tglWallpaper;
tglMultimonitor = IupToggle("Несколько мониторов", NULL);
tglFullscreen = IupToggle("На весь экран", NULL);
tglAuthentication = IupToggle("Аутентификация", NULL); tglAuthentication = IupToggle("Аутентификация", NULL);
tglCertIgnore = IupToggle("Игнорировать сертификат", NULL); tglCertIgnore = IupToggle("Игнорировать сертификат", NULL);
tglThemes = IupToggle("Отключить темы", NULL); tglThemes = IupToggle("Отключить темы", NULL);
tglWallpaper = IupToggle("Отключить обои", NULL); tglWallpaper = IupToggle("Отключить обои", NULL);
IupSetInt(tglMultimonitor, "VALUE", getSetParameter(PARAMETER_MULTIMONITOR));
IupSetInt(tglFullscreen, "VALUE", getSetParameter(PARAMETER_FULLSCREEN));
IupSetInt(tglAuthentication, "VALUE", getSetParameter(PARAMETER_AUTHENTICATION)); IupSetInt(tglAuthentication, "VALUE", getSetParameter(PARAMETER_AUTHENTICATION));
IupSetInt(tglCertIgnore, "VALUE", getSetParameter(PARAMETER_CERTIGNORE)); IupSetInt(tglCertIgnore, "VALUE", getSetParameter(PARAMETER_CERTIGNORE));
IupSetInt(tglThemes, "VALUE", getSetParameter(PARAMETER_THEMES)); IupSetInt(tglThemes, "VALUE", getSetParameter(PARAMETER_THEMES));
IupSetInt(tglWallpaper, "VALUE", getSetParameter(PARAMETER_WALLPAPER)); IupSetInt(tglWallpaper, "VALUE", getSetParameter(PARAMETER_WALLPAPER));
return IupHbox( return IupSetAttributes(
IupSetAttributes( IupFrame(
IupFrame( IupVbox(
IupVbox( IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR"), "ACTION", (Icallback) settingsTglAuthentication, NULL),
(Icallback) settingsTglMultimonitor, NULL), IupSetCallbacks(IupSetAttributes(tglCertIgnore, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN"), "ACTION", (Icallback) settingsTglCertIgnore, NULL),
(Icallback) settingsTglFullscreen, NULL), IupSetCallbacks(IupSetAttributes(tglThemes, "NAME=SETTINGS_TGL_THEMES"), "ACTION", (Icallback) settingsTglThemes,
IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION", NULL),
(Icallback) settingsTglAuthentication, NULL), IupSetCallbacks(IupSetAttributes(tglWallpaper, "NAME=SETTINGS_TGL_WALLPAPER"), "ACTION", (Icallback) settingsTglWallpaper,
IupSetCallbacks(IupSetAttributes(tglCertIgnore, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION", NULL),
(Icallback) settingsTglCertIgnore, NULL), NULL)), "TITLE=\"Общие\", MARGIN=10x10");
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() static Ihandle* settingsBoxSecurity()
@ -273,26 +275,49 @@ static Ihandle* settingsBoxBitsPerPixel()
static Ihandle* settingsBoxMonitor() static Ihandle* settingsBoxMonitor()
{ {
Ihandle *ddMonitor; Ihandle *tglFullscreen, *tglMultimonitor, *ddMonitor;
tglMultimonitor = IupToggle("Все мониторы", NULL);
tglFullscreen = IupToggle("На весь экран", NULL);
ddMonitor = IupList(NULL); ddMonitor = IupList(NULL);
x_info *monitors = getXInfo(); 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) for (short i = 0; i < monitors->count; ++i)
{ {
IupSetAttribute(ddMonitor, monitors->monitor[i].ptrIndex, monitors->monitor[i].ptrName); IupSetAttribute(ddMonitor, monitors->monitor[i].ptrIndexItem, monitors->monitor[i].ptrName);
if (getSetValue(PARAMETER_MONITORS, i))
setValueIndex = i + 1;
} }
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); free(monitors);
return IupSetCallbacks(IupSetAttributes(ddMonitor, return IupSetAttributes(
"DROPDOWN=YES, VALUE=1"), "ACTION", (Icallback) settingsChooseMonitor, NULL); IupFrame(
IupVbox(
IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN, EXPAND=YES"), "ACTION",
(Icallback) settingsTglFullscreen, NULL),
IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR"), "ACTION",
(Icallback) settingsTglMultimonitor, NULL),
IupSetCallbacks(IupSetAttributes(ddMonitor, "NAME=MONITORS, DROPDOWN=YES, EXPAND=YES"), "ACTION",
(Icallback) settingsChooseMonitor, NULL),
NULL)), "TITLE=\"Монитор\", MARGIN=10x10, CGAP=5");
} }
static Ihandle* settingsHorizontalBox() static Ihandle* settingsHorizontalBox()
{ {
return IupSetAttributes(IupHbox(IupVbox(settingsBoxCheckbox(), settingsBoxMonitor(), NULL), settingsBoxSecurity(), settingsBoxBitsPerPixel(), NULL), "MARGIN=5x5"); return IupSetAttributes(
IupHbox(IupVbox(settingsBoxCheckbox(), settingsBoxMonitor(), NULL), settingsBoxSecurity(), settingsBoxBitsPerPixel(), NULL), "MARGIN=5x5");
} }
/* /*

View File

@ -12,7 +12,8 @@ typedef struct
{ {
char name[10]; char name[10];
char *ptrName; char *ptrName;
char *ptrIndex; char *ptrIndexItem;
char *ptrIndexMonitor;
int width; int width;
int height; int height;
int primary; int primary;
@ -26,5 +27,6 @@ typedef struct
int XInfo(x_info *info); int XInfo(x_info *info);
x_info *getXInfo(); x_info *getXInfo();
void freeXInfo(x_info *info);
#endif /* XRANDR_H_ */ #endif /* XRANDR_H_ */

View File

@ -19,11 +19,27 @@ x_info *getXInfo()
for (int i = 0; i < monitors->count; ++i) for (int i = 0; i < monitors->count; ++i)
{ {
monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * strlen(monitors->monitor[i].name)); monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * strlen(monitors->monitor[i].name));
monitors->monitor[i].ptrIndex = (char *)malloc(sizeof(char) * 3); 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); strcpy(monitors->monitor[i].ptrName, monitors->monitor[i].name);
sprintf(monitors->monitor[i].ptrIndex, "%d", i + 1); sprintf(monitors->monitor[i].ptrIndexItem, "%d", i + 1);
sprintf(monitors->monitor[i].ptrIndexMonitor, "%d", i);
} }
return monitors; return monitors;
} }
void freeXInfo(x_info *info)
{
for (int i = 0; i < info->count; ++i)
{
if (info->monitor[i].ptrName)
free(info->monitor[i].ptrName);
if (info->monitor[i].ptrIndexItem)
free(info->monitor[i].ptrIndexItem);
if (info->monitor[i].ptrIndexMonitor)
free(info->monitor[i].ptrIndexMonitor);
}
free(info);
}