Fix transparent popover backgrounds

Some GTK themes (and newer GTK versions) leave popover surfaces
transparent. Add the canonical 'menu' class to both popovers and a
theme-aware CSS override so the difficulty/leaderboard menus always
draw an opaque background.
This commit is contained in:
2026-08-01 16:00:33 +01:00
parent 97565e415d
commit 49651fd42d
+11
View File
@@ -21,6 +21,15 @@ MainWindow::MainWindow() {
setup_header_bar();
setup_board();
// Popovers: some GTK themes (and newer GTK versions) leave the popover
// surface transparent unless the content opts in. Guarantee an opaque,
// theme-aware background.
auto popover_css = Gtk::CssProvider::create();
popover_css->load_from_data(
"popover.background > contents { background-color: @theme_bg_color; }");
Gtk::StyleContext::add_provider_for_display(
get_display(), popover_css, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
// Keyboard shortcuts
auto key_controller = Gtk::EventControllerKey::create();
key_controller->signal_key_pressed().connect([this](guint keyval, guint /*keycode*/, Gdk::ModifierType mods) {
@@ -116,6 +125,7 @@ void MainWindow::setup_header_bar() {
btn_difficulty_.set_popover(menu_difficulty_);
menu_difficulty_.set_child(box_difficulty_);
menu_difficulty_.add_css_class("menu");
header_bar_.pack_start(btn_difficulty_);
// Leaderboard
@@ -125,6 +135,7 @@ void MainWindow::setup_header_bar() {
box_leaderboard_.set_spacing(4);
btn_leaderboard_.set_popover(menu_leaderboard_);
menu_leaderboard_.set_child(box_leaderboard_);
menu_leaderboard_.add_css_class("menu");
menu_leaderboard_.signal_show().connect(sigc::mem_fun(*this, &MainWindow::refresh_leaderboard));
header_bar_.pack_start(btn_leaderboard_);