Add private modules build and add Applcation ref to MainWindow

This commit is contained in:
sha512sum 2024-08-26 14:22:15 +00:00
parent 2b4d8804ce
commit 1bb458198c
5 changed files with 39 additions and 25 deletions

View file

@ -19,8 +19,12 @@ set(CXX_EXTENSIONS NO)
set(BOOST_INCLUDE_LIBRARIES "pfr") set(BOOST_INCLUDE_LIBRARIES "pfr")
option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON) option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON)
file(GLOB_RECURSE LIB_SOURCES "lib/src/*.cpp") file(GLOB_RECURSE LIB_SOURCES "src/lib/*.cpp")
file(GLOB_RECURSE SOURCES "src/*.cpp") file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE IMPL_SOURCES "src/*_impl.cpp")
file(GLOB_RECURSE LIB_IMPL_SOURCES "src/lib/*_impl.cpp")
list(REMOVE_ITEM LIB_SOURCES ${LIB_IMPL_SOURCES})
list(REMOVE_ITEM SOURCES ${IMPL_SOURCES} ${LIB_SOURCES})
set(CMAKE_CXX_MODULE_STD 1) set(CMAKE_CXX_MODULE_STD 1)
set_target_properties(__cmake_cxx23 PROPERTIES CXX_EXTENSIONS OFF) set_target_properties(__cmake_cxx23 PROPERTIES CXX_EXTENSIONS OFF)
@ -85,6 +89,8 @@ target_compile_features(larra_xmpp INTERFACE cxx_std_23)
target_sources(larra_xmpp PUBLIC FILE_SET larraXMPPSet TYPE CXX_MODULES target_sources(larra_xmpp PUBLIC FILE_SET larraXMPPSet TYPE CXX_MODULES
FILES ${LIB_SOURCES}) FILES ${LIB_SOURCES})
target_sources(larra_xmpp PUBLIC ${LIB_IMPL_SOURCES})
install(TARGETS larra_xmpp install(TARGETS larra_xmpp
EXPORT larraXMPPTargets EXPORT larraXMPPTargets
@ -115,6 +121,7 @@ target_link_libraries(larra larra_xmpp)
target_sources(larra PUBLIC FILE_SET larraSet TYPE CXX_MODULES target_sources(larra PUBLIC FILE_SET larraSet TYPE CXX_MODULES
FILES ${SOURCES}) FILES ${SOURCES})
target_sources(larra PUBLIC ${IMPL_SOURCES})
install(TARGETS larra install(TARGETS larra
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}

View file

@ -3,17 +3,16 @@ module;
#include <print> #include <print>
export module larra.application; export module larra.application;
import larra.main_window;
namespace larra { namespace larra {
export struct Application : Gtk::Application { export struct Application : Gtk::Application {
Application() : Gtk::Application("org.larra.larra") { Application() : Gtk::Application("org.larra.larra") {
Glib::set_application_name("Larra"); Glib::set_application_name("Larra");
}; }
static auto create() -> Glib::RefPtr<Application> { static auto create() -> Glib::RefPtr<Application> {
return Glib::make_refptr_for_instance<Application>(new Application{}); // NOLINT return Glib::make_refptr_for_instance<Application>(new Application{}); // NOLINT
}; }
auto on_startup() -> void final { auto on_startup() -> void final {
this->Gtk::Application::on_startup(); this->Gtk::Application::on_startup();
this->add_action("preferences", sigc::mem_fun(*this, &Application::OnClickPreferences)); this->add_action("preferences", sigc::mem_fun(*this, &Application::OnClickPreferences));
@ -32,25 +31,15 @@ export struct Application : Gtk::Application {
gmenu->append_submenu("Accounts", accountsMenu); gmenu->append_submenu("Accounts", accountsMenu);
gmenu->append_submenu("Help", helpMenu); gmenu->append_submenu("Help", helpMenu);
this->set_menubar(gmenu); this->set_menubar(gmenu);
}; }
auto on_activate() -> void final { auto on_activate() -> void final;
auto win = new MainWindow{}; // NOLINT
this->add_window(*win);
win->signal_hide().connect([win] {
delete win; // NOLINT
});
win->set_show_menubar();
win->set_visible(true);
};
auto OnClickPreferences() -> void { auto OnClickPreferences() -> void {
}
};
auto OnClickManageAccounts() -> void { auto OnClickManageAccounts() -> void {
}
};
auto OnClickAbout() -> void {}; auto OnClickAbout() -> void {};
}; };

16
src/application_impl.cpp Normal file
View file

@ -0,0 +1,16 @@
module larra.application;
import larra.main_window;
namespace larra {
auto Application::on_activate() -> void {
auto win = new MainWindow{*this}; // NOLINT
this->add_window(*win);
win->signal_hide().connect([win] {
delete win; // NOLINT
});
win->set_show_menubar();
win->set_visible(true);
}
} // namespace larra

View file

@ -1,19 +1,21 @@
module; module;
#include <gtkmm.h> #include <gtkmm.h>
export module larra.main_window; export module larra.main_window;
import larra.application;
namespace larra { namespace larra {
export struct MainWindow : Gtk::ApplicationWindow { export struct MainWindow : Gtk::ApplicationWindow {
Gtk::Box main; Gtk::Box main;
Application& app;
Gtk::Box leftPanel{Gtk::Orientation::VERTICAL}; MainWindow(Application& app) : app(app) {
Gtk::Box accounts{Gtk::Orientation::VERTICAL};
MainWindow() {
this->set_title("Larra"); this->set_title("Larra");
auto settings = Gtk::Settings::get_default(); Gtk::Box leftPanel{Gtk::Orientation::VERTICAL};
this->main.append(this->leftPanel); leftPanel.set_halign(Gtk::Align::START);
leftPanel.set_expand(true);
Gtk::Box accounts{Gtk::Orientation::VERTICAL};
leftPanel.append(accounts);
this->main.append(leftPanel);
this->set_child(this->main); this->set_child(this->main);
} }
}; };