Skip to content

Commit 55b5163

Browse files
committed
vdisp/vulkan_sdl3: opt to set SDL hints
1 parent 7392718 commit 55b5163

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/video_display/vulkan/vulkan_sdl3.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Martin Bela <492789@mail.muni.cz>
77
*/
88
/*
9-
* Copyright (c) 2018-2025 CESNET
9+
* Copyright (c) 2018-2026 CESNET, zájmové sdružení právnických osob
1010
* All rights reserved.
1111
*
1212
* Redistribution and use in source and binary forms, with or without
@@ -49,6 +49,7 @@
4949
#include <cstdio> // for sscanf
5050
#include <cstdlib> // for calloc
5151
#include <cstring> // for strchr, strcmp
52+
#include <map> // for map
5253

5354
#include "debug.h"
5455
#include "host.h"
@@ -486,6 +487,7 @@ void show_help() {
486487
col() << SBOLD("\t pos=<x>,<y>") << " - set window position\n";
487488
col() << SBOLD("\t size=<W>x<H>") << " - set window size\n";
488489
col() << SBOLD("\twindow_flags=<f>") << " - flags to be passed to SDL_CreateWindow (use prefix 0x for hex)\n";
490+
col() << SBOLD("\thint=<key>=<val>") << " - set SDL hint (eg. SDL_VIDEO_WAYLAND_PREFER_LIBDECOR=0): hint can be used repeatedly\n";
489491

490492
print_gpus();
491493

@@ -607,6 +609,7 @@ struct command_line_arguments {
607609
uint32_t window_flags = 0 ; ///< user requested flags
608610
uint32_t gpu_idx = vkd::no_gpu_selected;
609611
std::string driver{};
612+
std::map<std::string, std::string> hints;
610613
};
611614

612615
bool parse_command_line_arguments(command_line_arguments& args, state_vulkan_sdl3& s, char *fmt) {
@@ -687,6 +690,12 @@ bool parse_command_line_arguments(command_line_arguments& args, state_vulkan_sdl
687690
} else if (IS_KEY_PREFIX(token, "window_flags")) {
688691
token = strchr(token, '=') + 1;
689692
args.window_flags |= cstoi(strchr(token, '=') + 1);
693+
} else if (IS_KEY_PREFIX(token, "hint") && strchr(token, '=') != strrchr(token, '=')) {
694+
char *key = strchr(token, '=') + 1;
695+
char *val = strchr(key, '=');
696+
*val = '\0';
697+
val++;
698+
args.hints[key] = val;
690699
} else {
691700
LOG(LOG_LEVEL_ERROR) << wrong_option_msg << token << '\n';
692701
return false;
@@ -793,6 +802,11 @@ void* display_vulkan_init(module* parent, const char* fmt, unsigned int flags) {
793802
if (!args.driver.empty()) {
794803
SDL_CHECK(SDL_SetHint(SDL_HINT_VIDEO_DRIVER, args.driver.c_str()));
795804
}
805+
for (auto &it : args.hints) {
806+
SDL_CHECK(SDL_SetHint(it.first.c_str(), it.second.c_str()));
807+
MSG(INFO, "Setting %s to %s\n", it.first.c_str(), it.second.c_str());
808+
}
809+
796810
bool ret = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
797811
if (!ret) {
798812
log_msg(LOG_LEVEL_ERROR, "Unable to initialize SDL3: %s\n", SDL_GetError());

0 commit comments

Comments
 (0)