mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
WindowServer: In HighDPI mode, load high-res window buttons and high-res cursors
Bitmap::load_from_file("foo.png", 2) will now look for "foo-2x.png" and try load that as a bitmap with scale factor 2 if it exists. If it doesn't, it falls back to the 1x bitmap as normal. Only places that know that they'll draw the bitmap to a 2x painter should pass "2" for the second argument. Use this new API in WindowServer for loading window buttons and cursors. As a testing aid, ctrl-shift-super-i can force HighDPI icons off in HighDPI mode. Toggling between low-res and high-res icons makes it easy to see if the high-res version of an icon looks right: It should look like the low-res version, just less jaggy. We'll likely have to grow a better API for loading scaled resources, but for now this suffices. Things to check: - `chres 640 480` followed by `chres 640 480 2` followed by `chres 640 480` - window buttons in window context menu (in task bar and on title bar) still have low-res icons - ctrl-shift-super-i in high-res mode toggles sharpness of window buttons and of arrow cursorf - arrow cursor hotspot is still where you'd expect
This commit is contained in:
parent
5ad2cbe9ad
commit
98637bd549
8 changed files with 86 additions and 18 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <AK/LogStream.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/CharacterBitmap.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
|
@ -84,7 +85,7 @@ NonnullRefPtr<Cursor> WindowManager::get_cursor(const String& name)
|
|||
{
|
||||
static const auto s_default_cursor_path = "/res/cursors/arrow.x2y2.png";
|
||||
auto path = m_config->read_entry("Cursor", name, s_default_cursor_path);
|
||||
auto gb = Gfx::Bitmap::load_from_file(path);
|
||||
auto gb = Gfx::Bitmap::load_from_file(path, compositor_icon_scale());
|
||||
if (gb)
|
||||
return Cursor::create(*gb, path);
|
||||
return Cursor::create(*Gfx::Bitmap::load_from_file(s_default_cursor_path), s_default_cursor_path);
|
||||
|
@ -1092,6 +1093,12 @@ void WindowManager::event(Core::Event& event)
|
|||
return;
|
||||
}
|
||||
|
||||
if (key_event.type() == Event::KeyDown && (key_event.modifiers() == (Mod_Ctrl | Mod_Logo | Mod_Shift) && key_event.key() == Key_I)) {
|
||||
reload_icon_bitmaps_after_scale_change(!m_allow_hidpi_icons);
|
||||
Compositor::the().invalidate_screen();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MenuManager::the().current_menu()) {
|
||||
MenuManager::the().dispatch_event(event);
|
||||
return;
|
||||
|
@ -1486,4 +1493,21 @@ Gfx::IntPoint WindowManager::get_recommended_window_position(const Gfx::IntPoint
|
|||
|
||||
return point;
|
||||
}
|
||||
|
||||
int WindowManager::compositor_icon_scale() const
|
||||
{
|
||||
if (!m_allow_hidpi_icons)
|
||||
return 1;
|
||||
return scale_factor();
|
||||
}
|
||||
|
||||
void WindowManager::reload_icon_bitmaps_after_scale_change(bool allow_hidpi_icons)
|
||||
{
|
||||
m_allow_hidpi_icons = allow_hidpi_icons;
|
||||
reload_config();
|
||||
for_each_window([&](Window& window) {
|
||||
window.frame().set_button_icons();
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue