wayland: QTWAYLAND_CONTENT_ORIENTATION can support multiple values as bitmasks

This commit is contained in:
Ethan Lee 2021-11-11 13:16:34 -05:00
parent ebed961cb2
commit 63ae103cd1
1 changed files with 26 additions and 8 deletions

View File

@ -954,6 +954,17 @@ QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
const char *oldValue, const char *newValue) const char *oldValue, const char *newValue)
{ {
struct qt_extended_surface *qt_extended_surface = userdata; struct qt_extended_surface *qt_extended_surface = userdata;
int i;
static struct {
const char *name;
int32_t value;
} orientations[] = {
{ "portrait", QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION },
{ "landscape", QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION },
{ "inverted-portrait", QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION },
{ "inverted-landscape", QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION }
};
if (name == NULL) { if (name == NULL) {
return; return;
@ -963,14 +974,21 @@ QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION; int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
if (newValue != NULL) { if (newValue != NULL) {
if (SDL_strcmp(newValue, "portrait") == 0) { const char *value_attempt = newValue;
orientation = QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION; while (value_attempt != NULL && *value_attempt != 0) {
} else if (SDL_strcmp(newValue, "landscape") == 0) { const char *value_attempt_end = SDL_strchr(value_attempt, ',');
orientation = QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION; size_t value_attempt_len = (value_attempt_end != NULL) ? (value_attempt_end - value_attempt)
} else if (SDL_strcmp(newValue, "inverted-portrait") == 0) { : SDL_strlen(value_attempt);
orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
} else if (SDL_strcmp(newValue, "inverted-landscape") == 0) { for (i = 0; i < SDL_arraysize(orientations); i += 1) {
orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION; if ((value_attempt_len == SDL_strlen(orientations[i].name)) &&
(SDL_strncasecmp(orientations[i].name, value_attempt, value_attempt_len) == 0)) {
orientation |= orientations[i].value;
break;
}
}
value_attempt = (value_attempt_end != NULL) ? (value_attempt_end + 1) : NULL;
} }
} }