Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add di option #123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/ddcctl.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ int main(int argc, const char * argv[])
// Defaults
NSString *screenName = @"";
NSUInteger displayId = -1;
const char *displayUid = NULL;
NSUInteger command_interval = 100000;
BOOL dump_values = NO;

NSString *HelpString = @"Usage:\n"
@"ddcctl \t-d <1-..> [display#]\n"
@"\t-di <0-..> [display id (overrides -d if specified)]\n"
@"\t-w <0-..> [delay in usecs between settings]\n"
@"\t-W <0-..> [timeout in nanosecs for replies]\n"
@"\n"
Expand Down Expand Up @@ -261,6 +263,12 @@ int main(int argc, const char * argv[])
displayId = atoi(argv[i]);
}

else if (!strcmp(argv[i], "-di")) {
i++;
if (i >= argc) break;
displayUid = argv[i];
}

else if (!strcmp(argv[i], "-b")) {
i++;
if (i >= argc) break;
Expand Down Expand Up @@ -400,6 +408,30 @@ int main(int argc, const char * argv[])
}
}

if (displayUid != NULL) {
char *endptr;
uint uid = strtol(displayUid, &endptr, 10);
if (endptr == displayUid) {
Copy link
Owner

@kfix kfix Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather should be checking that uid == 0.

NSLog(@"Display ID needs to be numeric");
exit(1);
}
int i = 1;
bool found = false;
for (NSNumber *dispId in _displayIDs)
{
if (uid == dispId.unsignedIntegerValue) {
displayId = i;
found = true;
break;
}
++i;
}
if (!found) {
NSLog(@"Display ID %d not found", uid);
exit(1);
}
}

if (0 >= displayId || displayId > [_displayIDs count]) {
// no display id given, nothing left to do!
NSLog(@"%@", HelpString);
Expand Down