From b657435aab99e69d0e8c0c672ff1484deee53546 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Mon, 21 Dec 2020 19:54:56 +1100 Subject: [PATCH] target-bsnes: Do not set the window background colour. The bsnes window is mostly covered by the viewport, which is supposed to be black. When the window is resized, the hiro Viewport widget repaints itself, according to whatever hiro backend is in use. However, on some platforms that's not enough. Specifically on X11, when the user resizes a window the window manager, the X server, and the application can all have different ideas about the exact window size. The X11 protocol gives each window a "default background colour", to be used by the X server to fill the blanks after the window manager has resized the window, but before the application has been able to repaint it. Because the bsnes window is *mostly* black, bsnes sets its window background colour to black, so the flickering of X-server-drawn and application-drawn content will be less obvious. Unfortunately, it gets more complex. GTK+2 was designed around the X11 model, and so it works basically the way bsnes expects. GTK+3 was designed around the more modern compositing model, which doesn't need that "default background colour" hack, and as a result when you set the window background colour on GTK+3. that background colour is used for *everything*. Even the menu-bar, which by default draws text in a very dark grey, so you can hardly read what it says. To fix this problem, we stop setting the background of the entire window to black, and instead only set the background of the widgets in the middle of the window. Specifically, the viewport widget is always black anyway, but when no game is loaded bsnes has a Canvas widget that displays the bsnes icon. Previously, a Canvas widget would show a background colour *or* an icon, but now that an icon can have a padding color, we can use that to make sure the icon background is black, regardless of the canvas size. Fixes #108. --- bsnes/target-bsnes/presentation/presentation.cpp | 5 ++--- bsnes/target-bsnes/presentation/presentation.hpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bsnes/target-bsnes/presentation/presentation.cpp b/bsnes/target-bsnes/presentation/presentation.cpp index dd524dbf..6b9dc4eb 100644 --- a/bsnes/target-bsnes/presentation/presentation.cpp +++ b/bsnes/target-bsnes/presentation/presentation.cpp @@ -213,8 +213,8 @@ auto Presentation::create() -> void { iconLayout.setAlignment(0.0).setCollapsible(); image icon{Resource::Icon}; - icon.alphaBlend(0x000000); - iconCanvas.setIcon(icon); + iconCanvas.setIcon(icon, {0, 0, 0}); + iconCanvas.setAlignment({0.0, 0.0}); iconCanvas.setDroppable(); iconCanvas.onDrop([&](auto locations) { onDrop(locations); }); @@ -250,7 +250,6 @@ auto Presentation::create() -> void { }); setTitle({"bsnes v", Emulator::Version}); - setBackgroundColor({0, 0, 0}); resizeWindow(); setAlignment(Alignment::Center); diff --git a/bsnes/target-bsnes/presentation/presentation.hpp b/bsnes/target-bsnes/presentation/presentation.hpp index ce5e324c..a685bd49 100644 --- a/bsnes/target-bsnes/presentation/presentation.hpp +++ b/bsnes/target-bsnes/presentation/presentation.hpp @@ -126,7 +126,7 @@ struct Presentation : Window { Viewport viewport{&viewportLayout, Size{~0, ~0}, 0}; VerticalLayout iconLayout{&viewportLayout, Size{0, ~0}, 0}; Canvas iconSpacer{&iconLayout, Size{144, ~0}, 0}; - Canvas iconCanvas{&iconLayout, Size{128, 128}, 0}; + Canvas iconCanvas{&iconLayout, Size{144, 128}, 0}; HorizontalLayout statusLayout{&layout, Size{~0, StatusHeight}, 0}; Label spacerIcon{&statusLayout, Size{8, ~0}, 0}; Canvas statusIcon{&statusLayout, Size{16, ~0}, 0};