Skip to content

Commit

Permalink
Drop dependency on YLocale class and X11 libs
Browse files Browse the repository at this point in the history
Since no glib or X11 stuff is required anymore, can save a bit on
loading time. Moving code (for LC_MESSAGE lang extraction) back to us.
  • Loading branch information
Code7R committed Sep 28, 2024
1 parent 1aa5f24 commit 38552a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,15 @@ if(BUILD_TESTING)
endif()

IF(CONFIG_FDO_MENUS)
ADD_EXECUTABLE(icewm-menu-fdo${EXEEXT} fdomenu.cc ycollections.cc)
target_compile_options(icewm-menu-fdo${EXEEXT} PUBLIC ${gio_CFLAGS_OTHER} ${gio_unix_CFLAGS_OTHER})
target_include_directories(icewm-menu-fdo${EXEEXT} PUBLIC ${gio_INCLUDE_DIRS} ${gio_unix_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(icewm-menu-fdo${EXEEXT} ice ${x11_LDFLAGS}
${gio_LDFLAGS} ${nls_LIBS})
INSTALL(TARGETS icewm-menu-fdo${EXEEXT} DESTINATION ${BINDIR})
set(_tgt icewm-menu-fdo${EXEEXT})
ADD_EXECUTABLE(${_tgt} fdomenu.cc)
TARGET_LINK_LIBRARIES(${_tgt} ice)
# XXX: static linking or LTO make it actually slower
#target_compile_options(${_tgt} PUBLIC -flto)
#target_link_options(${_tgt} PUBLIC -flto)
#target_compile_options(${_tgt} PUBLIC -static)
#target_link_options(${_tgt} PUBLIC -static)
INSTALL(TARGETS ${_tgt} DESTINATION ${BINDIR})
ENDIF()

add_executable(icewm-session${EXEEXT} icesm.cc)
Expand Down
19 changes: 13 additions & 6 deletions src/fdomenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@

#include "base.h"
#include "config.h"
// #include "sysdep.h"
#include "appnames.h"
#include "intl.h"
#include "ylocale.h"

#include <cstring>
#include <stack>
#include <string>
// does not matter, string from C++11 is enough
// #include <string_view>
#include <algorithm>
#include <array>
#include <fstream>
#include <iostream>
#include <locale>
#include <map>
#include <memory>
#include <regex>
#include <set>
#include <unordered_map>
Expand Down Expand Up @@ -270,7 +266,6 @@ struct DesktopFile : public tLintRefcounted {
string &GetTranslatedGenericName() {
if (GenericNameLoc.empty() && !GenericName.empty())
GenericNameLoc = gettext(GenericName.c_str());

return GenericNameLoc;
}

Expand Down Expand Up @@ -555,6 +550,18 @@ struct MenuNode {
unordered_multimap<string, MenuNode *> fixup();
};

const char* getCheckedExplicitLocale(bool lctype)
{
auto loc = setlocale(lctype ? LC_CTYPE : LC_MESSAGES, NULL);
if (loc == NULL)
return NULL;
return (islower(*loc & 0xff)
&& islower(loc[1] & 0xff)
&& !isalpha(loc[2] & 0xff))
? loc
: NULL;
}

int main(int argc, char **argv) {

// basic framework and environment initialization
Expand All @@ -563,7 +570,7 @@ int main(int argc, char **argv) {
#ifdef CONFIG_I18N
setlocale(LC_ALL, "");

auto msglang = YLocale::getCheckedExplicitLocale(false);
auto msglang = getCheckedExplicitLocale(false);
right_to_left =
msglang && std::any_of(rtls, rtls + ACOUNT(rtls), [&](const char *rtl) {
return rtl[0] == msglang[0] && rtl[1] == msglang[1];
Expand Down

0 comments on commit 38552a7

Please sign in to comment.