Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BUILD_COLOUR_NAME_MAP build flag #1880

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions cmake/Conky.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ if(NOT APP_UNAME)
message(FATAL_ERROR "Unable to find program 'uname'")
endif(NOT APP_UNAME)

find_program(APP_GPERF gperf)

if(NOT APP_GPERF)
message(FATAL_ERROR "Unable to find program 'gperf' (required at build-time as of Conky v1.20.2)")
endif(NOT APP_GPERF)

if(NOT RELEASE)
find_program(APP_GIT git)

Expand All @@ -169,7 +163,7 @@ if(NOT RELEASE)
mark_as_advanced(APP_GIT)
endif(NOT RELEASE)

mark_as_advanced(APP_AWK APP_WC APP_UNAME APP_GPERF)
mark_as_advanced(APP_AWK APP_WC APP_UNAME)

execute_process(COMMAND ${APP_UNAME} -sm
RESULT_VARIABLE RETVAL
Expand Down
2 changes: 2 additions & 0 deletions cmake/ConkyBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ option(BUILD_EXTRAS "Build extras (includes syntax files for editors)" false)

option(BUILD_I18N "Enable if you want internationalization support" true)

option(BUILD_COLOUR_NAME_MAP "Include mappings of colour name -> RGB (i.e., red -> ff0000)" true)

if(BUILD_I18N)
set(LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale"
CACHE STRING "Directory containing the locales")
Expand Down
12 changes: 11 additions & 1 deletion cmake/ConkyPlatformChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ if(BUILD_LUA_CAIRO)
set(luacairo_libs ${CAIROXLIB_LIBRARIES} ${luacairo_libs})
set(luacairo_includes ${CAIROXLIB_INCLUDE_DIRS} ${luacairo_includes})
endif(BUILD_LUA_CAIRO_XLIB)

find_program(APP_PATCH patch)

if(NOT APP_PATCH)
Expand Down Expand Up @@ -669,6 +669,16 @@ if(BUILD_DOCS OR BUILD_EXTRAS)
endif()
endif(BUILD_DOCS OR BUILD_EXTRAS)

if(BUILD_COLOUR_NAME_MAP)
find_program(APP_GPERF gperf)

if(NOT APP_GPERF)
message(FATAL_ERROR "Unable to find program 'gperf' (required at build-time as of Conky v1.20.2)")
endif(NOT APP_GPERF)

mark_as_advanced(APP_GPERF)
endif(BUILD_COLOUR_NAME_MAP)

if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG true)
endif(CMAKE_BUILD_TYPE MATCHES "Debug")
Expand Down
2 changes: 2 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@

#cmakedefine BUILD_HSV_GRADIENT 1

#cmakedefine BUILD_COLOUR_NAME_MAP 1

#cmakedefine HAVE_STATFS64 1
#ifndef HAVE_STATFS64
#define statfs64 statfs
Expand Down
28 changes: 28 additions & 0 deletions src/colour-names-stub.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* To generate colour-names.hh, you must have gperf installed during build.
* This is a dummy implementation for builds without gperf.
* Color name matching will always return null (i.e. no match).
*/

#pragma once

#include <cstdint>

#include "logging.h"

struct rgb {
const char *name;
uint8_t red;
uint8_t green;
uint8_t blue;
};

class color_name_hash {
public:
static const struct rgb *in_word_set(const char *str, size_t len);
};

const struct rgb *color_name_hash::in_word_set(const char *str, size_t len) {
DBGP("color parsing not supported");
Caellian marked this conversation as resolved.
Show resolved Hide resolved
return nullptr;
}
4 changes: 4 additions & 0 deletions src/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ Colour Colour::from_argb32(uint32_t argb) {
return out;
}

#ifdef BUILD_COLOUR_NAME_MAP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wregister"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wregister"
#include <colour-names.hh>
#pragma clang diagnostic pop
#pragma GCC diagnostic pop
#else /* BUILD_COLOUR_NAME_MAP */
#include "colour-names-stub.hh"
#endif /* BUILD_COLOUR_NAME_MAP */

std::optional<Colour> parse_color_name(const std::string &name) {
const rgb *value = color_name_hash::in_word_set(name.c_str(), name.length());
Expand Down