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

Allow pixelnuke to be fullscreened on startup by commandline argument #22

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Server written in C, based on libevent2, OpenGL, GLFW and pthreads. It won't get
make
./pixelnuke

Commandline Arguments:

* `H`: Show help for commandline arguments
* `F[screen_id]`: Start fullscreened. You can additionally specify the fullscreen monitor by adding a screen id from 0 to 9 after the F

Keyboard controls:

* `F11`: Toggle between fullscreen and windowed mode
Expand Down
26 changes: 25 additions & 1 deletion pixelnuke/pixelnuke.c
Copy link

Choose a reason for hiding this comment

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

while the function contains a for-loop you return / exit the function inside a case. so multiple options are not processed.

furthermore you can use curly brackets to start a new block where you introduce new variables instead of using an empty statement. this is cleaner and it shows clearly the lifetime of that variable.

Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,37 @@ void px_on_window_close() {
net_stop();
}

uint8_t args_parse_and_act(int argc, char **argv) {
for (int arg = 1; arg < argc; ++arg) {
switch (argv[arg][0]) { //compare first char of argument
case 'H':
printf("==pixelnuke commandline arguments==\nH\t\tshows this help\nF[screen_id]\tStart fullscreened. You can additionally specify the fullscreen monitor\n\t\tby adding a screen id from 0 to 9 after the F, the default is 0.\n");
return 1; //1 means please quit
case 'F':
; //funny C quirk not allowing lables before declarations
int target_fs_disp = 0;
if (argv[arg][1] != 0) { //if not null
int possible_num = argv[arg][1] - '0'; //convert to number if in range 0-9
if (possible_num >= 0 && possible_num <= 9) { //check if range fits
target_fs_disp = possible_num;
}
}
printf("Fullscreening on display %d due to cmdline arg\n", target_fs_disp);
canvas_fullscreen(target_fs_disp); //fullscreen pxnuke on the target screen
return 0;
}
}
return 0;
}

int main(int argc, char **argv) {
canvas_setcb_key(&px_on_key);
canvas_setcb_resize(&px_on_resize);

canvas_start(1024, &px_on_window_close);

if (args_parse_and_act(argc, argv)) return 0; //handle args and quit if needed

net_start(1337, &px_on_connect, &px_on_read, &px_on_close);
return 0;
}