summaryrefslogtreecommitdiff
path: root/reschange/reschange.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'reschange/reschange.cpp')
-rw-r--r--reschange/reschange.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/reschange/reschange.cpp b/reschange/reschange.cpp
new file mode 100644
index 0000000..991071c
--- /dev/null
+++ b/reschange/reschange.cpp
@@ -0,0 +1,107 @@
+// reschange.cpp : Defines the entry point for the application.
+//
+
+#include "stdafx.h"
+#include <stdio.h>
+#include "reschange.h"
+#include "DisplayUtils.h"
+#include "getopt.h"
+#include "stdio.h"
+
+//Default video mode values
+#define DEFAULT_VIDEO_WIDTH 800
+#define DEFAULT_VIDEO_HEIGHT 600
+#define DEFAULT_VIDEO_BITS 32
+#define DEFAULT_VIDEO_ATTACH FALSE
+
+#define MAX_MONS 4
+
+//Usage: reschange [-all] [-attach] [-devid=prefix] [-mon=width,height,depth,xpos,ypos (1-4 mons)]
+//Options:
+//-all set all monitors to the first mon setting.
+//-attach attach given monitors and detach the rest, otherwise ignore attachment state.
+//-devid prefix of the relevant devices.
+//-mon monitor display settings. can appear up to 4 times, one for each monitor.
+// the rest of the monitors are ignored/detached according to [-attach].
+//-pos use given monitors positions.
+
+//------------------------------------------------------------------------------
+//
+// PNP ID of the device is passed though command line
+// 1. In case of compatible PNP ID (partial PNP ID) the mode will be set for all
+// the devices matched
+// 2. In case of an empty command line (or using "all" as PNP ID) - the mode for
+// all the devices will be changed
+//------------------------------------------------------------------------------
+
+int main(int argc, char **argv)
+{
+ struct option longopts[] = {
+ {"all", no_argument, 0, 0},
+ {"attach", no_argument, 0, 0},
+ {"devid", required_argument, 0, 0},
+ {"mon", required_argument, 0, 0},
+ {"install", no_argument, 0, 0},
+ {"pos", no_argument, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ MonitorConfig mons[MAX_MONS];
+ BOOL all = FALSE;
+ BOOL attach = FALSE;
+ BOOL install = FALSE;
+ BOOL position = FALSE;
+ char ignored, *devid = NULL;
+ int opt, longind = 0;
+ int nmons = 0;
+ int nRetValue = 0;
+
+ printf("reschange\n");
+ while ((opt = my_getopt_long_only(argc, argv, "", longopts, &longind)) != -1) {
+ switch (longind) {
+ case 0: /* -all */
+ all = TRUE;
+ break;
+ case 1: /* -attach */
+ attach = TRUE;
+ break;
+ case 2: /* -devid */
+ devid = optarg;
+ break;
+ case 3: /* -mon */
+ if (nmons == MAX_MONS) {
+ return -1;
+ }
+ if (optarg) {
+ if (sscanf_s(optarg, "%d,%d,%d,%d,%d,%c", &mons[nmons].dwWidth,
+ &mons[nmons].dwHeight, &mons[nmons].dwDepth,
+ &mons[nmons].dwPosX, &mons[nmons].dwPosY,
+ &ignored) == 5) {
+ nmons++;
+ } else {
+ return -2;
+ }
+ }
+ break;
+ case 4: /* -install */
+ install = TRUE;
+ break;
+ case 5: /* -pos */
+ position = TRUE;
+ break;
+ }
+ }
+ if (nmons == 0) {
+ mons[0].dwWidth = DEFAULT_VIDEO_WIDTH;
+ mons[0].dwHeight = DEFAULT_VIDEO_HEIGHT;
+ mons[0].dwDepth = DEFAULT_VIDEO_BITS;
+ mons[0].dwPosX = 0;
+ mons[0].dwPosY = 0;
+ nmons = 1;
+ all = TRUE;
+ }
+
+
+ nRetValue = ChangeResolution(devid ? devid : "", all, attach, position, nmons, mons);
+ return (install) ? 0 : nRetValue;
+}