Add long options

This will allow us to introduce new long options which don't have
any short option equivalent.
This commit is contained in:
Simon Ser 2021-09-01 14:51:23 +02:00
parent f36d436a71
commit 13f792ab15
3 changed files with 44 additions and 3 deletions

View file

@ -7,6 +7,7 @@
#include <sys/capability.h> #include <sys/capability.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <getopt.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <float.h> #include <float.h>
@ -23,6 +24,41 @@
#include "pipewire.hpp" #include "pipewire.hpp"
#endif #endif
const char *gamescope_optstring = "R:T:C:w:h:W:H:m:r:o:NFSvVecsdLinbfxO:";
const struct option *gamescope_options = (struct option[]){
{ "nested-width", required_argument, nullptr, 'w' },
{ "nested-height", required_argument, nullptr, 'h' },
{ "nested-refresh", required_argument, nullptr, 'r' },
{ "nested-unfocused-refresh", required_argument, nullptr, 'o' },
{ "max-scale", required_argument, nullptr, 'm' },
{ "integer-scale", no_argument, nullptr, 'i' },
{ "sleep-at-startup", no_argument, nullptr, 's' },
{ "output-width", required_argument, nullptr, 'W' },
{ "output-height", required_argument, nullptr, 'H' },
{ "disable-layers", no_argument, nullptr, 'L' },
{ "debug-layers", no_argument, nullptr, 'd' },
{ "nearest-neighbor-filter", no_argument, nullptr, 'n' },
{ "borderless", no_argument, nullptr, 'b' },
{ "fullscreen", no_argument, nullptr, 'f' },
{ "prefer-output", no_argument, nullptr, 'O' },
// steamcompmgr options
{ "ready-fd", required_argument, nullptr, 'R' },
{ "stats-path", required_argument, nullptr, 'T' },
{ "hide-cursor-delay", required_argument, nullptr, 'C' },
{ "disable-rendering", no_argument, nullptr, 'N' },
{ "debug-focus", no_argument, nullptr, 'F' },
{ "sync-x11-at-startup", no_argument, nullptr, 'S' },
{ "debug-hud", no_argument, nullptr, 'v' },
{ "debug-events", no_argument, nullptr, 'V' },
{ "steam", no_argument, nullptr, 'e' },
{ "force-composition", no_argument, nullptr, 'c' },
{ "disable-xres", no_argument, nullptr, 'x' },
{} // keep last
};
std::atomic< bool > g_bRun{true}; std::atomic< bool > g_bRun{true};
int g_nNestedWidth = 0; int g_nNestedWidth = 0;
@ -63,7 +99,8 @@ int main(int argc, char **argv)
{ {
int o; int o;
bool bSleepAtStartup = false; bool bSleepAtStartup = false;
while ((o = getopt(argc, argv, GAMESCOPE_OPTIONS)) != -1) int opt_index = -1;
while ((o = getopt_long(argc, argv, gamescope_optstring, gamescope_options, &opt_index)) != -1)
{ {
switch (o) { switch (o) {
case 'w': case 'w':

View file

@ -1,8 +1,11 @@
#pragma once #pragma once
#include <getopt.h>
#include <atomic> #include <atomic>
#define GAMESCOPE_OPTIONS "R:T:C:w:h:W:H:m:r:o:NFSvVecsdLinbfxO:" extern const char *gamescope_optstring;
extern const struct option *gamescope_options;
void wayland_commit(struct wlr_surface *surf, struct wlr_buffer *buf); void wayland_commit(struct wlr_surface *surf, struct wlr_buffer *buf);

View file

@ -3355,7 +3355,8 @@ steamcompmgr_main (int argc, char **argv)
// Reset getopt() state // Reset getopt() state
optind = 1; optind = 1;
while ((o = getopt (argc, argv, GAMESCOPE_OPTIONS)) != -1) int opt_index = -1;
while ((o = getopt_long(argc, argv, gamescope_optstring, gamescope_options, &opt_index)) != -1)
{ {
switch (o) { switch (o) {
case 'R': case 'R':