diff --git a/libui/CMakeLists.txt b/libui/CMakeLists.txt index 1a0fa74b..79c0deae 100644 --- a/libui/CMakeLists.txt +++ b/libui/CMakeLists.txt @@ -11,7 +11,7 @@ set(SOURCES ) add_library(ui ${SOURCES}) -target_compile_options(ui PRIVATE ${COMMON_FLAGS}) +target_compile_options(ui PRIVATE ${COMMON_FLAGS} -fno-threadsafe-statics) target_include_directories(ui PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/) target_include_directories(ui PUBLIC ${LUNA_BASE}/usr/include) target_link_libraries(ui PUBLIC os) diff --git a/libui/src/Font.cpp b/libui/src/Font.cpp index 1c99965c..2e99d921 100644 --- a/libui/src/Font.cpp +++ b/libui/src/Font.cpp @@ -2,9 +2,6 @@ #include #include -SharedPtr s_default_font = {}; -SharedPtr s_default_bold_font = {}; - constexpr static int BYTES_PER_PIXEL = (int)sizeof(ui::Color); namespace ui @@ -51,15 +48,15 @@ namespace ui SharedPtr Font::default_font() { - if (s_default_font) return s_default_font; - s_default_font = load("/usr/share/fonts/Tamsyn-Regular.psf").release_value(); + static SharedPtr s_default_font = {}; + if (!s_default_font) s_default_font = load("/usr/share/fonts/Tamsyn-Regular.psf").release_value(); return s_default_font; } SharedPtr Font::default_bold_font() { - if (s_default_bold_font) return s_default_bold_font; - s_default_bold_font = load("/usr/share/fonts/Tamsyn-Bold.psf").release_value(); + static SharedPtr s_default_bold_font = {}; + if (!s_default_bold_font) s_default_bold_font = load("/usr/share/fonts/Tamsyn-Bold.psf").release_value(); return s_default_bold_font; } diff --git a/wind/CMakeLists.txt b/wind/CMakeLists.txt index 8f5db052..0ddb710f 100644 --- a/wind/CMakeLists.txt +++ b/wind/CMakeLists.txt @@ -9,7 +9,7 @@ set(SOURCES ) add_executable(wind ${SOURCES}) -target_compile_options(wind PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings) +target_compile_options(wind PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings -fno-threadsafe-statics) add_dependencies(wind libc) target_include_directories(wind PRIVATE ${LUNA_BASE}/usr/include ${CMAKE_CURRENT_LIST_DIR}) target_link_libraries(wind PRIVATE os ui) diff --git a/wind/Window.cpp b/wind/Window.cpp index 45110ccf..43141247 100644 --- a/wind/Window.cpp +++ b/wind/Window.cpp @@ -6,8 +6,6 @@ LinkedList g_windows; -static SharedPtr g_close_icon; - void Window::draw(ui::Canvas& screen) { auto window = screen.subcanvas(surface); @@ -25,11 +23,12 @@ void Window::draw(ui::Canvas& screen) auto textarea = titlebar_canvas.subcanvas(ui::Rect { 10, 10, titlebar_canvas.width - 10, titlebar_canvas.height }); font->render(buffer, ui::BLACK, textarea); - if (g_close_icon) - { - auto close_area = window.subcanvas(close_button); - close_area.fill(g_close_icon->pixels(), g_close_icon->width()); - } + static SharedPtr g_close_icon; + + if (!g_close_icon) g_close_icon = ui::Image::load("/usr/share/icons/16x16/app-close.tga").release_value(); + + auto close_area = window.subcanvas(close_button); + close_area.fill(g_close_icon->pixels(), g_close_icon->width()); } void Window::focus() @@ -48,6 +47,4 @@ Window::Window(ui::Rect r, ui::Color c, StringView n) : surface(r), color(c), na close_button = ui::Rect { surface.width - 26, 10, 16, 16 }; contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) }; g_windows.append(this); - - if (!g_close_icon) g_close_icon = ui::Image::load("/usr/share/icons/16x16/app-close.tga").value_or({}); }