|
| 1 | +/* |
| 2 | + Simple DirectMedia Layer |
| 3 | + Copyright (C) 1997-2025 Sam Lantinga <[email protected]> |
| 4 | +
|
| 5 | + This software is provided 'as-is', without any express or implied |
| 6 | + warranty. In no event will the authors be held liable for any damages |
| 7 | + arising from the use of this software. |
| 8 | +
|
| 9 | + Permission is granted to anyone to use this software for any purpose, |
| 10 | + including commercial applications, and to alter it and redistribute it |
| 11 | + freely, subject to the following restrictions: |
| 12 | +
|
| 13 | + 1. The origin of this software must not be misrepresented; you must not |
| 14 | + claim that you wrote the original software. If you use this software |
| 15 | + in a product, an acknowledgment in the product documentation would be |
| 16 | + appreciated but is not required. |
| 17 | + 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | + misrepresented as being the original software. |
| 19 | + 3. This notice may not be removed or altered from any source distribution. |
| 20 | +*/ |
| 21 | +#include "SDL_internal.h" |
| 22 | + |
| 23 | +#ifdef SDL_PLATFORM_LINUX |
| 24 | +#include <stdio.h> |
| 25 | +#include <unistd.h> |
| 26 | + |
| 27 | +bool SDL_IsUbuntuTouch(void) |
| 28 | +{ |
| 29 | + return access("/etc/ubuntu-touch-session.d/", F_OK) == 0; |
| 30 | +} |
| 31 | + |
| 32 | +// https://docs.ubports.com/en/latest/porting/configure_test_fix/Display.html#form-factor |
| 33 | +SDL_UTFormFactor SDL_GetUbuntuTouchFormFactor(void) |
| 34 | +{ |
| 35 | + SDL_UTFormFactor form_factor = SDL_UTFORMFACTOR_UNKNOWN; |
| 36 | + FILE *config_file = NULL; |
| 37 | + char *line = NULL; |
| 38 | + size_t line_alloc = 0; |
| 39 | + ssize_t line_size = 0; |
| 40 | + |
| 41 | + config_file = fopen("/etc/ubuntu-touch-session.d/android.conf", "r"); |
| 42 | + if (!config_file) { |
| 43 | + return form_factor; |
| 44 | + } |
| 45 | + |
| 46 | + while ((line_size = getline(&line, &line_alloc, config_file)) != -1) { |
| 47 | + if (SDL_strncmp(line, "FORM_FACTOR=", 12) == 0) { |
| 48 | + if (SDL_strcmp(line, "FORM_FACTOR=handset\n")) { |
| 49 | + form_factor = SDL_UTFORMFACTOR_PHONE; |
| 50 | + } else if (SDL_strcmp(line, "FORM_FACTOR=tablet\n")) { |
| 51 | + form_factor = SDL_UTFORMFACTOR_TABLET; |
| 52 | + } else if (SDL_strcmp(line, "FORM_FACTOR=laptop\n")) { |
| 53 | + form_factor = SDL_UTFORMFACTOR_LAPTOP; |
| 54 | + } else if (SDL_strcmp(line, "FORM_FACTOR=desktop\n")) { |
| 55 | + form_factor = SDL_UTFORMFACTOR_DESKTOP; |
| 56 | + } else { |
| 57 | + form_factor = SDL_UTFORMFACTOR_UNKNOWN; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + free(line); // This should NOT be SDL_free() |
| 62 | + } |
| 63 | + |
| 64 | + fclose(config_file); |
| 65 | + |
| 66 | + return form_factor; |
| 67 | +} |
| 68 | +#endif |
0 commit comments