summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-14 02:07:35 +0100
committerwm4 <wm4@nowhere>2020-03-14 02:23:38 +0100
commitc78482045444c488bb7948305d583a55d17cd236 (patch)
tree32f9142ac9cd79f6a59220a623d390ef9e269da6 /player/command.c
parent7c4a550c0ed9690e441d2bd0b212d42fffbec70c (diff)
downloadmpv-c78482045444c488bb7948305d583a55d17cd236.tar.bz2
mpv-c78482045444c488bb7948305d583a55d17cd236.tar.xz
options: introduce bool option type, use it for --fullscreen
The option code is very old and was added to MPlayer in the early 2000s, when C99 was still new. MPlayer did not use the "bool" type anywhere,l and the logical option equivalent to bool, the "flag" option type, used int, with the convention that only the values 0 and 1 are allowed. mpv may have hammered many, many additional tentacles to the option code, but some of the basics never changed, and m_option_type_flag still uses int. This seems a bit weird, since mpv uses bool for booleans. So finally introduce an m_option_type_bool. To avoid duplicating too much code, change the flag code to bool, and "reimplement" m_option_type_flag on top of m_option_type_bool. As a "demonstration", change the --fullscreen option to this new type. Ideally, all options would be changed too bool, and m_option_type_flag would be removed. But that is a lot of monotonous thankless work, so I'm not doing it, and making it a painful years long transition. At the same time, I'm introducing a new concept for option declarations. Instead of OPT_BOOL(), which define the full m_option struct contents, there's OPTF_BOOL(), which only takes the option field name itself. The name is provided via a normal struct field initializer. Other fields (such as flags) can be provided via designated initializers. The advantage of this is that we don't need tons of nested vararg macros. We also don't need to deal with 0-sized varargs being a pain (and in fact they are not a thing in standard C99 and probably C11). There is no need to provide a mandatory flags argument either, which is the reason why so many OPT_ macros are used with a "0" argument. (The flag argument seems to confuse other developers; they either don't immediately recognize what it is, and sometimes it's supposed to be the option's default value.) Not having to mess with the flag argument in such option macros is also a reason for the removal of M_OPT_RANGE etc., for the better or worse. The only place that special-cased the _flag option type was in command.c; change it to use something effectively very similar that automatically includes the new _bool option type. Everything else should be transparent to the change. The fullscreen option change should be transparent too, as C99 bool is basically an integer type that is clamped to 0/1 (except in Swift, Swift sucks).
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/player/command.c b/player/command.c
index 393966bb77..2c86a0ecb7 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4143,7 +4143,7 @@ static bool check_property_autorepeat(char *property, struct MPContext *mpctx)
return true;
// This is a heuristic at best.
- if (prop.type == &m_option_type_flag || prop.type == &m_option_type_choice)
+ if (prop.type->flags & M_OPT_TYPE_CHOICE)
return false;
return true;