misc: Use the OpenURI D-Bus portal for opening URLs
Build (All) / Create test plan (push) Has been cancelled
Build (All) / level1 (push) Has been cancelled
Build (All) / level2 (push) Has been cancelled

This works inside of containers, and supports passing an activation token with the request, which is needed on Wayland to transfer focus to the browser.
This commit is contained in:
Frank Praznik
2026-04-04 22:28:06 -04:00
parent f8feccfa46
commit 682da4ee98
6 changed files with 307 additions and 11 deletions
+41 -11
View File
@@ -25,29 +25,27 @@ static void tryOpenURL(const char *url)
int main(int argc, char **argv)
{
int i;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_Log("SDL_Init failed: %s", SDL_GetError());
return 1;
}
const char *url = NULL;
SDLTest_CommonState *state = SDLTest_CommonCreateState(argv, 0);
bool use_gui = false;
/* Parse commandline */
for (i = 1; i < argc;) {
for (int i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
if (argv[i][0] != '-') {
tryOpenURL(argv[i]);
url = argv[i];
consumed = 1;
} else if (SDL_strcasecmp(argv[i], "--gui") == 0) {
use_gui = true;
consumed = 1;
}
}
if (consumed <= 0) {
static const char *options[] = {
"[--gui]"
"[URL [...]]",
NULL,
};
@@ -57,6 +55,38 @@ int main(int argc, char **argv)
i += consumed;
}
state->flags = SDL_INIT_VIDEO;
if (!SDLTest_CommonInit(state)) {
return SDL_APP_FAILURE;
}
if (!use_gui) {
tryOpenURL(url);
} else {
SDL_Event event;
bool quit = false;
while (!quit) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_KEY_DOWN) {
if (event.key.key == SDLK_SPACE) {
tryOpenURL(url);
} else if (event.key.key == SDLK_ESCAPE) {
quit = true;
}
} else if (event.type == SDL_EVENT_QUIT) {
quit = true;
}
}
SDL_SetRenderDrawColor(state->renderers[0], 0, 0, 0, 255);
SDL_RenderClear(state->renderers[0]);
SDL_SetRenderDrawColor(state->renderers[0], 255, 255, 255, 255);
SDL_RenderDebugTextFormat(state->renderers[0], 8.f, 16.f, "Press space to open %s", url);
SDL_RenderPresent(state->renderers[0]);
}
}
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;