diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..784c8a93
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,107 @@
+---
+Language: Cpp
+# BasedOnStyle: Google
+AccessModifierOffset: -1
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeCategories:
+ - Regex: '^<.*\.h>'
+ Priority: 1
+ - Regex: '^<.*'
+ Priority: 2
+ - Regex: '.*'
+ Priority: 3
+IncludeIsMainRegex: '([-_](test|unittest))?$'
+IndentCaseLabels: true
+IndentWidth: 2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Auto
+TabWidth: 2
+UseTab: Never
+...
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..c401e20b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,7 @@
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+intend_size = 2
diff --git a/.travis.yml b/.travis.yml
index b44b199a..14a911b5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,29 +1,75 @@
language: cpp
-compiler:
- - gcc
-addons:
- apt:
- packages:
- - cmake
- - libxdamage-dev
- - libx11-dev
- - libxft-dev
- - libxext-dev
- - libglib2.0-dev
- - libxml2-dev
- - libcurl4-gnutls-dev
- - liblua5.1-0-dev
- - libtolua++5.1-dev
- - libcairo2-dev
- - libimlib2-dev
- - libxinerama-dev
- - gawk
+dist: trusty
+matrix:
+ include:
+ - os: linux
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-trusty-5.0
+ packages:
+ - g++-7
+ - cmake
+ - libxdamage-dev
+ - libx11-dev
+ - libxft-dev
+ - libxext-dev
+ - libglib2.0-dev
+ - libxml2-dev
+ - libcurl4-gnutls-dev
+ - liblua5.1-0-dev
+ - libtolua++5.1-dev
+ - libcairo2-dev
+ - libimlib2-dev
+ - libxinerama-dev
+ - gawk
+ - clang-5.0
+ - clang-format-5.0
+ env:
+ - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
+ - os: linux
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-trusty-5.0
+ packages:
+ - cmake
+ - libxdamage-dev
+ - libx11-dev
+ - libxft-dev
+ - libxext-dev
+ - libglib2.0-dev
+ - libxml2-dev
+ - libcurl4-gnutls-dev
+ - liblua5.1-0-dev
+ - libtolua++5.1-dev
+ - libcairo2-dev
+ - libimlib2-dev
+ - libxinerama-dev
+ - gawk
+ - clang-5.0
+ - clang-format-5.0
+ env:
+ - MATRIX_EVAL="CC=clang && CXX=clang++"
+before_install:
+ - eval "${MATRIX_EVAL}"
before_script:
- - mkdir build && cd build && cmake .. && cd ..
- - mkdir build-no-x11 && cd build-no-x11 && cmake -DBUILD_X11=OFF .. && cd ..
+ - mkdir build
+ - cd build
+ - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout cmake -DCHECK_CODE_FORMAT=ON ..
+ - travis_wait 30 make format-check
+ - cd ..
+ - mkdir build-no-x11
+ - cd build-no-x11
+ - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout cmake -DCHECK_CODE_FORMAT=ON -DBUILD_X11=OFF ..
+ - cd ..
script:
- - cd build && make -j4 && cd ..
- - cd build-no-x11 && make -j4 && cd ..
+ - cd build
+ - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout make -j4
+ - cd ../build-no-x11
+ - scan-build --use-cc=$CC --use-c++=$CXX -o scanbuildout make -j4
branches:
only:
- master
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b33a112e..3910d33f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
@@ -20,7 +19,7 @@
# along with this program. If not, see .
#
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.5)
project(conky)
@@ -39,10 +38,22 @@ include(ConkyPlatformChecks)
# CPack module for installation tasks
include(ConkyCPackSetup)
+if(CHECK_CODE_FORMAT)
+ # Set up clang-format
+ set(CLANG_FORMAT_BIN_NAME clang-format clang-format-5.0)
+ set(CLANG_FORMAT_EXCLUDE_PATTERNS "build/" ${CMAKE_BINARY_DIR})
+ find_package(ClangFormat)
+endif(CHECK_CODE_FORMAT)
+
# setup our configuration headers
configure_file(${CMAKE_MODULE_PATH}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h)
+set(conky_sources
+ ${CMAKE_BINARY_DIR}/config.h
+ ${CMAKE_BINARY_DIR}/build.h
+)
+
# Finally, add some code
add_subdirectory(lua)
add_subdirectory(data)
@@ -50,7 +61,7 @@ add_subdirectory(doc)
add_subdirectory(src)
IF(NOT DEFINED DOC_PATH)
- set(DOC_PATH "share/doc/${CPACK_PACKAGE_NAME}-${VERSION}")
+ set(DOC_PATH "share/doc/${CPACK_PACKAGE_NAME}-${VERSION}")
ENDIF(NOT DEFINED DOC_PATH)
set(DOC_FILES extras/convert.lua data/conky_no_x11.conf data/conky.conf)
@@ -61,12 +72,12 @@ set(MAN_PATH "share/man/man1")
set(MAN_FILES doc/conky.1)
install(FILES ${DOC_FILES}
- DESTINATION ${DOC_PATH})
+ DESTINATION ${DOC_PATH})
if(MAINTAINER_MODE)
- install(FILES ${HTML_FILES}
- DESTINATION ${HTML_PATH})
+ install(FILES ${HTML_FILES}
+ DESTINATION ${HTML_PATH})
- install(FILES ${MAN_FILES}
- DESTINATION ${MAN_PATH})
+ install(FILES ${MAN_FILES}
+ DESTINATION ${MAN_PATH})
endif(MAINTAINER_MODE)
diff --git a/LICENSE.BSD b/LICENSE.BSD
index 604d79da..91fe6e12 100644
--- a/LICENSE.BSD
+++ b/LICENSE.BSD
@@ -1,5 +1,5 @@
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
-Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
+Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/apply-clang-format.sh b/apply-clang-format.sh
new file mode 100755
index 00000000..566a20f5
--- /dev/null
+++ b/apply-clang-format.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+find . -iname "*.h" -o -iname "*.cc" -o -iname "*.hh" \
+ | xargs clang-format \
+ -style=file -i -fallback-style=google
diff --git a/cmake/Conky.cmake b/cmake/Conky.cmake
index 31a77cb0..65738b7d 100644
--- a/cmake/Conky.cmake
+++ b/cmake/Conky.cmake
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
@@ -24,40 +23,40 @@
# Set system vars
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- set(OS_LINUX true)
+ set(OS_LINUX true)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- set(OS_FREEBSD true)
+ set(OS_FREEBSD true)
endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
- set(OS_DRAGONFLY true)
+ set(OS_DRAGONFLY true)
endif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
- set(OS_OPENBSD true)
+ set(OS_OPENBSD true)
endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
- set(OS_SOLARIS true)
+ set(OS_SOLARIS true)
endif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
- set(OS_NETBSD true)
+ set(OS_NETBSD true)
endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
- set(OS_HAIKU true)
+ set(OS_HAIKU true)
endif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- set(OS_DARWIN true)
+ set(OS_DARWIN true)
endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY
- AND NOT OS_SOLARIS AND NOT OS_HAIKU AND NOT OS_DARWIN)
- message(FATAL_ERROR "Your platform, '${CMAKE_SYSTEM_NAME}', is not currently supported. Patches are welcome.")
+ AND NOT OS_SOLARIS AND NOT OS_HAIKU AND NOT OS_DARWIN)
+ message(FATAL_ERROR "Your platform, '${CMAKE_SYSTEM_NAME}', is not currently supported. Patches are welcome.")
endif(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY
AND NOT OS_SOLARIS AND NOT OS_HAIKU AND NOT OS_DARWIN)
@@ -72,18 +71,18 @@ set(conky_includes ${CMAKE_BINARY_DIR})
# Thus disable this and _LARGEFILE64_SOURCE isnt needed, it is already used on macOS.
#
if(NOT OS_DARWIN)
- add_definitions(-D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L) # Standard definitions
- set(CMAKE_REQUIRED_DEFINITIONS
- "${CMAKE_REQUIRED_DEFINITIONS} -D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L")
+ add_definitions(-D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L) # Standard definitions
+ set(CMAKE_REQUIRED_DEFINITIONS
+ "${CMAKE_REQUIRED_DEFINITIONS} -D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L")
endif(NOT OS_DARWIN)
if(OS_DRAGONFLY)
-set(conky_libs ${conky_libs} -L/usr/pkg/lib)
-set(conky_includes ${conky_includes} -I/usr/pkg/include)
+ set(conky_libs ${conky_libs} -L/usr/pkg/lib)
+ set(conky_includes ${conky_includes} -I/usr/pkg/include)
endif(OS_DRAGONFLY)
if(OS_SOLARIS)
-set(conky_libs ${conky_libs} -L/usr/local/lib)
+ set(conky_libs ${conky_libs} -L/usr/local/lib)
endif(OS_SOLARIS)
# Do version stuff
@@ -93,30 +92,30 @@ set(VERSION_PATCH "9")
find_program(APP_AWK awk)
if(NOT APP_AWK)
- message(FATAL_ERROR "Unable to find program 'awk'")
+ message(FATAL_ERROR "Unable to find program 'awk'")
endif(NOT APP_AWK)
find_program(APP_WC wc)
if(NOT APP_WC)
- message(FATAL_ERROR "Unable to find program 'wc'")
+ message(FATAL_ERROR "Unable to find program 'wc'")
endif(NOT APP_WC)
find_program(APP_DATE date)
if(NOT APP_DATE)
- message(FATAL_ERROR "Unable to find program 'date'")
+ message(FATAL_ERROR "Unable to find program 'date'")
endif(NOT APP_DATE)
find_program(APP_UNAME uname)
if(NOT APP_UNAME)
- message(FATAL_ERROR "Unable to find program 'uname'")
+ message(FATAL_ERROR "Unable to find program 'uname'")
endif(NOT APP_UNAME)
if(NOT RELEASE)
- find_program(APP_GIT git)
- if(NOT APP_GIT)
- message(FATAL_ERROR "Unable to find program 'git'")
- endif(NOT APP_GIT)
- mark_as_advanced(APP_GIT)
+ find_program(APP_GIT git)
+ if(NOT APP_GIT)
+ message(FATAL_ERROR "Unable to find program 'git'")
+ endif(NOT APP_GIT)
+ mark_as_advanced(APP_GIT)
endif(NOT RELEASE)
mark_as_advanced(APP_AWK APP_WC APP_DATE APP_UNAME)
@@ -124,37 +123,37 @@ mark_as_advanced(APP_AWK APP_WC APP_DATE APP_UNAME)
#BUILD_DATE=$(LANG=en_US LC_ALL=en_US LOCALE=en_US date)
#BUILD_ARCH="$(uname -sr) ($(uname -m))"
execute_process(COMMAND ${APP_DATE} RESULT_VARIABLE RETVAL OUTPUT_VARIABLE
- BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
+ BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${APP_UNAME} -srm RESULT_VARIABLE RETVAL
- OUTPUT_VARIABLE BUILD_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
+ OUTPUT_VARIABLE BUILD_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
if(RELEASE)
- set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+ set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
else(RELEASE)
- set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_pre${COMMIT_COUNT}")
+ set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_pre${COMMIT_COUNT}")
endif(RELEASE)
-set(COPYRIGHT "Copyright Brenden Matthews, et al, 2005-2015")
+set(COPYRIGHT "Copyright Brenden Matthews, et al, 2005-2018")
macro(AC_SEARCH_LIBS FUNCTION_NAME INCLUDES TARGET_VAR)
- if("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$")
- unset(AC_SEARCH_LIBS_TMP CACHE)
- check_symbol_exists(${FUNCTION_NAME} ${INCLUDES} AC_SEARCH_LIBS_TMP)
- if(${AC_SEARCH_LIBS_TMP})
- set(${TARGET_VAR} "" CACHE INTERNAL "Library containing ${FUNCTION_NAME}")
- else(${AC_SEARCH_LIBS_TMP})
- foreach(LIB ${ARGN})
- unset(AC_SEARCH_LIBS_TMP CACHE)
- unset(AC_SEARCH_LIBS_FOUND CACHE)
- find_library(AC_SEARCH_LIBS_TMP ${LIB})
- check_library_exists(${LIB} ${FUNCTION_NAME} ${AC_SEARCH_LIBS_TMP}
- AC_SEARCH_LIBS_FOUND)
- if(${AC_SEARCH_LIBS_FOUND})
- set(${TARGET_VAR} ${AC_SEARCH_LIBS_TMP} CACHE INTERNAL
- "Library containing ${FUNCTION_NAME}")
- break()
- endif(${AC_SEARCH_LIBS_FOUND})
- endforeach(LIB)
- endif(${AC_SEARCH_LIBS_TMP})
- endif("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$")
+ if("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$")
+ unset(AC_SEARCH_LIBS_TMP CACHE)
+ check_symbol_exists(${FUNCTION_NAME} ${INCLUDES} AC_SEARCH_LIBS_TMP)
+ if(${AC_SEARCH_LIBS_TMP})
+ set(${TARGET_VAR} "" CACHE INTERNAL "Library containing ${FUNCTION_NAME}")
+ else(${AC_SEARCH_LIBS_TMP})
+ foreach(LIB ${ARGN})
+ unset(AC_SEARCH_LIBS_TMP CACHE)
+ unset(AC_SEARCH_LIBS_FOUND CACHE)
+ find_library(AC_SEARCH_LIBS_TMP ${LIB})
+ check_library_exists(${LIB} ${FUNCTION_NAME} ${AC_SEARCH_LIBS_TMP}
+ AC_SEARCH_LIBS_FOUND)
+ if(${AC_SEARCH_LIBS_FOUND})
+ set(${TARGET_VAR} ${AC_SEARCH_LIBS_TMP} CACHE INTERNAL
+ "Library containing ${FUNCTION_NAME}")
+ break()
+ endif(${AC_SEARCH_LIBS_FOUND})
+ endforeach(LIB)
+ endif(${AC_SEARCH_LIBS_TMP})
+ endif("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$")
endmacro(AC_SEARCH_LIBS)
diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake
index 53b7859e..5f17d966 100644
--- a/cmake/ConkyBuildOptions.cmake
+++ b/cmake/ConkyBuildOptions.cmake
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
@@ -179,3 +178,5 @@ option(BUILD_CMUS "Enable support for cmus music player" false)
option(BUILD_JOURNAL "Enable support for reading from the systemd journal" false)
option(BUILD_PULSEAUDIO "Enable support for Pulseaudio's default sink and source" false)
+
+option(CHECK_CODE_FORMAT "Check code formatting with clang-format" false)
diff --git a/cmake/ConkyCPackSetup.cmake b/cmake/ConkyCPackSetup.cmake
index c1046efa..60f0e9b3 100644
--- a/cmake/ConkyCPackSetup.cmake
+++ b/cmake/ConkyCPackSetup.cmake
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake
index 30dda7e6..c2fe4f85 100644
--- a/cmake/ConkyPlatformChecks.cmake
+++ b/cmake/ConkyPlatformChecks.cmake
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
@@ -38,18 +37,18 @@ check_symbol_exists(pipe2 "unistd.h" HAVE_PIPE2)
check_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- check_symbol_exists(statfs64 "sys/mount.h" HAVE_STATFS64)
+ check_symbol_exists(statfs64 "sys/mount.h" HAVE_STATFS64)
else(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- check_symbol_exists(statfs64 "sys/statfs.h" HAVE_STATFS64)
+ check_symbol_exists(statfs64 "sys/statfs.h" HAVE_STATFS64)
endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
AC_SEARCH_LIBS(clock_gettime "time.h" CLOCK_GETTIME_LIB "rt")
if(NOT DEFINED CLOCK_GETTIME_LIB)
- if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
- message(FATAL_ERROR "clock_gettime not found.")
- endif(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ message(FATAL_ERROR "clock_gettime not found.")
+ endif(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
else(NOT DEFINED CLOCK_GETTIME_LIB)
- set(HAVE_CLOCK_GETTIME 1)
+ set(HAVE_CLOCK_GETTIME 1)
endif(NOT DEFINED CLOCK_GETTIME_LIB)
set(conky_libs ${conky_libs} ${CLOCK_GETTIME_LIB})
@@ -58,258 +57,275 @@ set(INCLUDE_SEARCH_PATH /usr/include /usr/local/include)
# Set system vars
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- set(OS_LINUX true)
+ set(OS_LINUX true)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- set(OS_FREEBSD true)
- set(conky_libs ${conky_libs} -lkvm -ldevstat -lbsd)
+ set(OS_FREEBSD true)
+ set(conky_libs ${conky_libs} -lkvm -ldevstat -lbsd)
endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
- set(OS_DRAGONFLY true)
- set(conky_libs ${conky_libs} -ldevstat)
+ set(OS_DRAGONFLY true)
+ set(conky_libs ${conky_libs} -ldevstat)
endif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
- set(OS_OPENBSD true)
+ set(OS_OPENBSD true)
endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
- set(OS_SOLARIS true)
- set(conky_libs ${conky_libs} -lkstat)
+ set(OS_SOLARIS true)
+ set(conky_libs ${conky_libs} -lkstat)
endif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
- set(OS_NETBSD true)
+ set(OS_NETBSD true)
endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
- set(OS_HAIKU true)
- set(conky_libs ${conky_libs} -lnetwork -lintl)
+ set(OS_HAIKU true)
+ set(conky_libs ${conky_libs} -lnetwork -lintl)
endif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- set(OS_DARWIN true)
+ set(OS_DARWIN true)
endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
-if(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY
- AND NOT OS_SOLARIS AND NOT OS_HAIKU AND NOT OS_DARWIN)
- message(FATAL_ERROR "Your platform, '${CMAKE_SYSTEM_NAME}', is not currently supported. Patches are welcome.")
+if(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY
+ AND NOT OS_SOLARIS AND NOT OS_HAIKU AND NOT OS_DARWIN)
+ message(FATAL_ERROR "Your platform, '${CMAKE_SYSTEM_NAME}', is not currently supported. Patches are welcome.")
endif(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY
AND NOT OS_SOLARIS AND NOT OS_HAIKU AND NOT OS_DARWIN)
# Check for soundcard header
if(OS_LINUX)
- check_include_files("linux/soundcard.h" HAVE_SOME_SOUNDCARD_H)
- check_include_files("linux/soundcard.h" HAVE_LINUX_SOUNDCARD_H)
+ check_include_files("linux/soundcard.h" HAVE_SOME_SOUNDCARD_H)
+ check_include_files("linux/soundcard.h" HAVE_LINUX_SOUNDCARD_H)
elseif(OS_OPENBSD)
- check_include_files("soundcard.h" HAVE_SOME_SOUNDCARD_H)
+ check_include_files("soundcard.h" HAVE_SOME_SOUNDCARD_H)
else(OS_LINUX)
- check_include_files("sys/soundcard.h" HAVE_SOME_SOUNDCARD_H)
+ check_include_files("sys/soundcard.h" HAVE_SOME_SOUNDCARD_H)
endif(OS_LINUX)
if(BUILD_I18N AND OS_DRAGONFLY)
- set(conky_libs ${conky_libs} -lintl)
+ set(conky_libs ${conky_libs} -lintl)
endif(BUILD_I18N AND OS_DRAGONFLY)
if(BUILD_I18N AND OS_DARWIN)
- set(conky_libs ${conky_libs} -lintl)
+ find_path(LIBINTL_H_N libintl.h PATHS
+ /usr/local/opt/gettext/include
+ /usr/include
+ /usr/local/include
+ /usr/local/opt/include
+ )
+ if(LIBINTL_H_N)
+ include_directories(${LIBINTL_H_N})
+ else(LIBINTL_H_N)
+ message(FATAL_ERROR "Unable to find libintl.h (try `brew install gettext`)")
+ endif(LIBINTL_H_N)
+ find_library(INTL_LIB NAMES intl PATHS
+ /usr/local/opt/gettext/lib
+ /usr/lib
+ /usr/local/lib
+ /usr/local/opt/lib
+ )
+ set(conky_libs ${conky_libs} ${INTL_LIB})
endif(BUILD_I18N AND OS_DARWIN)
if(BUILD_NCURSES AND OS_DARWIN)
- set(conky_libs ${conky_libs} -lncurses)
+ set(conky_libs ${conky_libs} -lncurses)
endif(BUILD_NCURSES AND OS_DARWIN)
if(BUILD_MATH)
- set(conky_libs ${conky_libs} -lm)
+ set(conky_libs ${conky_libs} -lm)
endif(BUILD_MATH)
if(BUILD_ICAL)
- check_include_files(libical/ical.h ICAL_H_)
- if(NOT ICAL_H_)
- message(FATAL_ERROR "Unable to find libical")
- endif(NOT ICAL_H_)
- set(conky_libs ${conky_libs} -lical)
+ check_include_files(libical/ical.h ICAL_H_)
+ if(NOT ICAL_H_)
+ message(FATAL_ERROR "Unable to find libical")
+ endif(NOT ICAL_H_)
+ set(conky_libs ${conky_libs} -lical)
endif(BUILD_ICAL)
if(BUILD_IRC)
- find_path(IRC_H_N libircclient.h PATHS /usr/include/libircclient)
- find_path(IRC_H_S libircclient.h PATHS /usr/include)
- if(IRC_H_N)
- include_directories(${IRC_H_N})
- endif(IRC_H_N)
- if(IRC_H_N OR IRC_H_S)
- set(IRC_H_ true)
- else()
- message(FATAL_ERROR "Unable to find libircclient")
- endif(IRC_H_N OR IRC_H_S)
- set(conky_libs ${conky_libs} -lircclient)
+ find_path(IRC_H_N libircclient.h PATHS /usr/include/libircclient)
+ find_path(IRC_H_S libircclient.h PATHS /usr/include)
+ if(IRC_H_N)
+ include_directories(${IRC_H_N})
+ endif(IRC_H_N)
+ if(IRC_H_N OR IRC_H_S)
+ set(IRC_H_ true)
+ else()
+ message(FATAL_ERROR "Unable to find libircclient")
+ endif(IRC_H_N OR IRC_H_S)
+ set(conky_libs ${conky_libs} -lircclient)
endif(BUILD_IRC)
if(BUILD_IPV6)
- find_file(IF_INET6 if_inet6 PATHS /proc/net)
- if(NOT IF_INET6)
- message(WARNING "/proc/net/if_inet6 unavailable")
- endif(NOT IF_INET6)
+ find_file(IF_INET6 if_inet6 PATHS /proc/net)
+ if(NOT IF_INET6)
+ message(WARNING "/proc/net/if_inet6 unavailable")
+ endif(NOT IF_INET6)
endif(BUILD_IPV6)
if(BUILD_HTTP)
- find_file(HTTP_H_ microhttpd.h)
- #I'm not using check_include_files because microhttpd.h seems to need a lot of different headers and i'm not sure which...
- if(NOT HTTP_H_)
- message(FATAL_ERROR "Unable to find libmicrohttpd")
- endif(NOT HTTP_H_)
- set(conky_libs ${conky_libs} -lmicrohttpd)
+ find_file(HTTP_H_ microhttpd.h)
+ #I'm not using check_include_files because microhttpd.h seems to need a lot of different headers and i'm not sure which...
+ if(NOT HTTP_H_)
+ message(FATAL_ERROR "Unable to find libmicrohttpd")
+ endif(NOT HTTP_H_)
+ set(conky_libs ${conky_libs} -lmicrohttpd)
endif(BUILD_HTTP)
if(BUILD_NCURSES)
- include(FindCurses)
- if(NOT CURSES_FOUND)
- message(FATAL_ERROR "Unable to find ncurses library")
- endif(NOT CURSES_FOUND)
- set(conky_libs ${conky_libs} ${CURSES_LIBRARIES})
- set(conky_includes ${conky_includes} ${CURSES_INCLUDE_DIR})
+ include(FindCurses)
+ if(NOT CURSES_FOUND)
+ message(FATAL_ERROR "Unable to find ncurses library")
+ endif(NOT CURSES_FOUND)
+ set(conky_libs ${conky_libs} ${CURSES_LIBRARIES})
+ set(conky_includes ${conky_includes} ${CURSES_INCLUDE_DIR})
endif(BUILD_NCURSES)
if(BUILD_MYSQL)
- find_path(mysql_INCLUDE_PATH mysql.h ${INCLUDE_SEARCH_PATH} /usr/include/mysql /usr/local/include/mysql)
- if(NOT mysql_INCLUDE_PATH)
- message(FATAL_ERROR "Unable to find mysql.h")
- endif(NOT mysql_INCLUDE_PATH)
- set(conky_includes ${conky_includes} ${mysql_INCLUDE_PATH})
- find_library(MYSQLCLIENT_LIB NAMES mysqlclient)
- if(NOT MYSQLCLIENT_LIB)
- message(FATAL_ERROR "Unable to find mysqlclient library")
- endif(NOT MYSQLCLIENT_LIB)
- set(conky_libs ${conky_libs} ${MYSQLCLIENT_LIB})
+ find_path(mysql_INCLUDE_PATH mysql.h ${INCLUDE_SEARCH_PATH} /usr/include/mysql /usr/local/include/mysql)
+ if(NOT mysql_INCLUDE_PATH)
+ message(FATAL_ERROR "Unable to find mysql.h")
+ endif(NOT mysql_INCLUDE_PATH)
+ set(conky_includes ${conky_includes} ${mysql_INCLUDE_PATH})
+ find_library(MYSQLCLIENT_LIB NAMES mysqlclient)
+ if(NOT MYSQLCLIENT_LIB)
+ message(FATAL_ERROR "Unable to find mysqlclient library")
+ endif(NOT MYSQLCLIENT_LIB)
+ set(conky_libs ${conky_libs} ${MYSQLCLIENT_LIB})
endif(BUILD_MYSQL)
if(BUILD_WLAN)
- set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
- check_include_files(iwlib.h IWLIB_H)
- if(NOT IWLIB_H)
- message(FATAL_ERROR "Unable to find iwlib.h")
- endif(NOT IWLIB_H)
- find_library(IWLIB_LIB NAMES iw)
- if(NOT IWLIB_LIB)
- message(FATAL_ERROR "Unable to find libiw.so")
- endif(NOT IWLIB_LIB)
- set(conky_libs ${conky_libs} ${IWLIB_LIB})
- check_function_exists(iw_sockets_open IWLIB_SOCKETS_OPEN_FUNC)
+ set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+ check_include_files(iwlib.h IWLIB_H)
+ if(NOT IWLIB_H)
+ message(FATAL_ERROR "Unable to find iwlib.h")
+ endif(NOT IWLIB_H)
+ find_library(IWLIB_LIB NAMES iw)
+ if(NOT IWLIB_LIB)
+ message(FATAL_ERROR "Unable to find libiw.so")
+ endif(NOT IWLIB_LIB)
+ set(conky_libs ${conky_libs} ${IWLIB_LIB})
+ check_function_exists(iw_sockets_open IWLIB_SOCKETS_OPEN_FUNC)
endif(BUILD_WLAN)
if(BUILD_PORT_MONITORS)
- check_function_exists(getnameinfo HAVE_GETNAMEINFO)
- if(NOT HAVE_GETNAMEINFO)
- message(FATAL_ERROR "could not find getnameinfo()")
- endif(NOT HAVE_GETNAMEINFO)
- check_include_files("netdb.h;netinet/in.h;netinet/tcp.h;sys/socket.h;arpa/inet.h" HAVE_PORTMON_HEADERS)
- if(NOT HAVE_PORTMON_HEADERS)
- message(FATAL_ERROR "missing needed network header(s) for port monitoring")
- endif(NOT HAVE_PORTMON_HEADERS)
+ check_function_exists(getnameinfo HAVE_GETNAMEINFO)
+ if(NOT HAVE_GETNAMEINFO)
+ message(FATAL_ERROR "could not find getnameinfo()")
+ endif(NOT HAVE_GETNAMEINFO)
+ check_include_files("netdb.h;netinet/in.h;netinet/tcp.h;sys/socket.h;arpa/inet.h" HAVE_PORTMON_HEADERS)
+ if(NOT HAVE_PORTMON_HEADERS)
+ message(FATAL_ERROR "missing needed network header(s) for port monitoring")
+ endif(NOT HAVE_PORTMON_HEADERS)
endif(BUILD_PORT_MONITORS)
# Check for iconv
if(BUILD_ICONV)
- check_include_files(iconv.h HAVE_ICONV_H)
- find_library(ICONV_LIBRARY NAMES iconv)
- if(NOT ICONV_LIBRARY)
- # maybe iconv() is provided by libc
- set(ICONV_LIBRARY "" CACHE FILEPATH "Path to the iconv library, if iconv is not provided by libc" FORCE)
- endif(NOT ICONV_LIBRARY)
- set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
- check_function_exists(iconv ICONV_FUNC)
- if(HAVE_ICONV_H AND ICONV_FUNC)
- set(conky_includes ${conky_includes} ${ICONV_INCLUDE_DIR})
- set(conky_libs ${conky_libs} ${ICONV_LIBRARY})
- else(HAVE_ICONV_H AND ICONV_FUNC)
- message(FATAL_ERROR "Unable to find iconv library")
- endif(HAVE_ICONV_H AND ICONV_FUNC)
+ check_include_files(iconv.h HAVE_ICONV_H)
+ find_library(ICONV_LIBRARY NAMES iconv)
+ if(NOT ICONV_LIBRARY)
+ # maybe iconv() is provided by libc
+ set(ICONV_LIBRARY "" CACHE FILEPATH "Path to the iconv library, if iconv is not provided by libc" FORCE)
+ endif(NOT ICONV_LIBRARY)
+ set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
+ check_function_exists(iconv ICONV_FUNC)
+ if(HAVE_ICONV_H AND ICONV_FUNC)
+ set(conky_includes ${conky_includes} ${ICONV_INCLUDE_DIR})
+ set(conky_libs ${conky_libs} ${ICONV_LIBRARY})
+ else(HAVE_ICONV_H AND ICONV_FUNC)
+ message(FATAL_ERROR "Unable to find iconv library")
+ endif(HAVE_ICONV_H AND ICONV_FUNC)
endif(BUILD_ICONV)
# check for Xlib
if(BUILD_X11)
- include(FindX11)
- find_package(X11)
- if(X11_FOUND)
- set(conky_includes ${conky_includes} ${X11_INCLUDE_DIR})
- set(conky_libs ${conky_libs} ${X11_LIBRARIES})
+ include(FindX11)
+ find_package(X11)
+ if(X11_FOUND)
+ set(conky_includes ${conky_includes} ${X11_INCLUDE_DIR})
+ set(conky_libs ${conky_libs} ${X11_LIBRARIES})
- # check for Xdamage
- if(BUILD_XDAMAGE)
- if(NOT X11_Xdamage_FOUND)
- message(FATAL_ERROR "Unable to find Xdamage library")
- endif(NOT X11_Xdamage_FOUND)
- if(NOT X11_Xfixes_FOUND)
- message(FATAL_ERROR "Unable to find Xfixes library")
- endif(NOT X11_Xfixes_FOUND)
- set(conky_libs ${conky_libs} ${X11_Xdamage_LIB} ${X11_Xfixes_LIB})
- endif(BUILD_XDAMAGE)
+ # check for Xdamage
+ if(BUILD_XDAMAGE)
+ if(NOT X11_Xdamage_FOUND)
+ message(FATAL_ERROR "Unable to find Xdamage library")
+ endif(NOT X11_Xdamage_FOUND)
+ if(NOT X11_Xfixes_FOUND)
+ message(FATAL_ERROR "Unable to find Xfixes library")
+ endif(NOT X11_Xfixes_FOUND)
+ set(conky_libs ${conky_libs} ${X11_Xdamage_LIB} ${X11_Xfixes_LIB})
+ endif(BUILD_XDAMAGE)
- if(BUILD_XSHAPE)
- if(NOT X11_Xshape_FOUND)
- message(FATAL_ERROR "Unable to find Xshape library")
- endif(NOT X11_Xshape_FOUND)
- set(conky_libs ${conky_libs} ${X11_Xshape_LIB} )
- endif(BUILD_XSHAPE)
+ if(BUILD_XSHAPE)
+ if(NOT X11_Xshape_FOUND)
+ message(FATAL_ERROR "Unable to find Xshape library")
+ endif(NOT X11_Xshape_FOUND)
+ set(conky_libs ${conky_libs} ${X11_Xshape_LIB} )
+ endif(BUILD_XSHAPE)
- # check for Xft
- if(BUILD_XFT)
- find_path(freetype_INCLUDE_PATH config/ftconfig.h ${INCLUDE_SEARCH_PATH}
- /usr/include/freetype2
- /usr/local/include/freetype2
- /usr/pkg/include/freetype2)
- if(freetype_INCLUDE_PATH)
- set(freetype_FOUND true)
- set(conky_includes ${conky_includes} ${freetype_INCLUDE_PATH})
- else(freetype_INCLUDE_PATH)
- find_path(freetype_INCLUDE_PATH freetype/config/ftconfig.h ${INCLUDE_SEARCH_PATH}
- /usr/include/freetype2
- /usr/local/include/freetype2
- /usr/pkg/include/freetype2)
- if(freetype_INCLUDE_PATH)
- set(freetype_FOUND true)
- set(conky_includes ${conky_includes} ${freetype_INCLUDE_PATH})
- else(freetype_INCLUDE_PATH)
- message(FATAL_ERROR "Unable to find freetype library")
- endif(freetype_INCLUDE_PATH)
- endif(freetype_INCLUDE_PATH)
- if(NOT X11_Xft_FOUND)
- message(FATAL_ERROR "Unable to find Xft library")
- endif(NOT X11_Xft_FOUND)
- set(conky_libs ${conky_libs} ${X11_Xft_LIB})
- endif(BUILD_XFT)
+ # check for Xft
+ if(BUILD_XFT)
+ find_path(freetype_INCLUDE_PATH config/ftconfig.h ${INCLUDE_SEARCH_PATH}
+ /usr/include/freetype2
+ /usr/local/include/freetype2
+ /usr/pkg/include/freetype2)
+ if(freetype_INCLUDE_PATH)
+ set(freetype_FOUND true)
+ set(conky_includes ${conky_includes} ${freetype_INCLUDE_PATH})
+ else(freetype_INCLUDE_PATH)
+ find_path(freetype_INCLUDE_PATH freetype/config/ftconfig.h ${INCLUDE_SEARCH_PATH}
+ /usr/include/freetype2
+ /usr/local/include/freetype2
+ /usr/pkg/include/freetype2)
+ if(freetype_INCLUDE_PATH)
+ set(freetype_FOUND true)
+ set(conky_includes ${conky_includes} ${freetype_INCLUDE_PATH})
+ else(freetype_INCLUDE_PATH)
+ message(FATAL_ERROR "Unable to find freetype library")
+ endif(freetype_INCLUDE_PATH)
+ endif(freetype_INCLUDE_PATH)
+ if(NOT X11_Xft_FOUND)
+ message(FATAL_ERROR "Unable to find Xft library")
+ endif(NOT X11_Xft_FOUND)
+ set(conky_libs ${conky_libs} ${X11_Xft_LIB})
+ endif(BUILD_XFT)
- # check for Xdbe
- if(BUILD_XDBE)
- if(NOT X11_Xext_FOUND)
- message(FATAL_ERROR "Unable to find Xext library (needed for Xdbe)")
- endif(NOT X11_Xext_FOUND)
- set(conky_libs ${conky_libs} ${X11_Xext_LIB})
- endif(BUILD_XDBE)
- else(X11_FOUND)
- message(FATAL_ERROR "Unable to find X11 library")
- endif(X11_FOUND)
+ # check for Xdbe
+ if(BUILD_XDBE)
+ if(NOT X11_Xext_FOUND)
+ message(FATAL_ERROR "Unable to find Xext library (needed for Xdbe)")
+ endif(NOT X11_Xext_FOUND)
+ set(conky_libs ${conky_libs} ${X11_Xext_LIB})
+ endif(BUILD_XDBE)
+ else(X11_FOUND)
+ message(FATAL_ERROR "Unable to find X11 library")
+ endif(X11_FOUND)
endif(BUILD_X11)
# Check whether we want Lua bindings
if(BUILD_LUA_CAIRO OR BUILD_LUA_IMLIB2 OR BUILD_LUA_RSVG)
- set(WANT_TOLUA true)
+ set(WANT_TOLUA true)
endif(BUILD_LUA_CAIRO OR BUILD_LUA_IMLIB2 OR BUILD_LUA_RSVG)
# Check for Lua itself
if(WANT_TOLUA)
- # If we need tolua++, we must compile against Lua 5.1
- pkg_search_module(LUA REQUIRED lua5.1 lua-5.1 lua51 lua)
- if(NOT LUA_VERSION VERSION_LESS 5.2.0)
- message(FATAL_ERROR "Unable to find Lua 5.1.x")
- endif(NOT LUA_VERSION VERSION_LESS 5.2.0)
+ # If we need tolua++, we must compile against Lua 5.1
+ pkg_search_module(LUA REQUIRED lua5.1 lua-5.1 lua51 lua)
+ if(NOT LUA_VERSION VERSION_LESS 5.2.0)
+ message(FATAL_ERROR "Unable to find Lua 5.1.x")
+ endif(NOT LUA_VERSION VERSION_LESS 5.2.0)
else(WANT_TOLUA)
- # Otherwise, use the most recent Lua version
- pkg_search_module(LUA REQUIRED lua>=5.3 lua5.3 lua-5.3 lua53 lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua>=5.1)
+ # Otherwise, use the most recent Lua version
+ pkg_search_module(LUA REQUIRED lua>=5.3 lua5.3 lua-5.3 lua53 lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua>=5.1)
endif(WANT_TOLUA)
set(conky_libs ${conky_libs} ${LUA_LIBRARIES})
set(conky_includes ${conky_includes} ${LUA_INCLUDE_DIRS})
@@ -317,183 +333,183 @@ link_directories(${LUA_LIBRARY_DIRS})
# Check for libraries used by Lua bindings
if(BUILD_LUA_CAIRO)
- pkg_check_modules(CAIRO REQUIRED cairo cairo-xlib)
- set(luacairo_libs ${CAIRO_LIBRARIES} ${LUA_LIBRARIES})
- set(luacairo_includes ${CAIRO_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
- find_program(APP_PATCH patch)
- if(NOT APP_PATCH)
- message(FATAL_ERROR "Unable to find program 'patch'")
- endif(NOT APP_PATCH)
+ pkg_check_modules(CAIRO REQUIRED cairo cairo-xlib)
+ set(luacairo_libs ${CAIRO_LIBRARIES} ${LUA_LIBRARIES})
+ set(luacairo_includes ${CAIRO_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
+ find_program(APP_PATCH patch)
+ if(NOT APP_PATCH)
+ message(FATAL_ERROR "Unable to find program 'patch'")
+ endif(NOT APP_PATCH)
endif(BUILD_LUA_CAIRO)
if(BUILD_LUA_IMLIB2)
- pkg_search_module(IMLIB2 REQUIRED imlib2 Imlib2)
- set(luaimlib2_libs ${IMLIB2_LIB} ${LUA_LIBRARIES})
- set(luaimlib2_includes ${IMLIB2_INCLUDE_PATH} ${LUA_INCLUDE_DIRS})
+ pkg_search_module(IMLIB2 REQUIRED imlib2 Imlib2)
+ set(luaimlib2_libs ${IMLIB2_LIB} ${LUA_LIBRARIES})
+ set(luaimlib2_includes ${IMLIB2_INCLUDE_PATH} ${LUA_INCLUDE_DIRS})
endif(BUILD_LUA_IMLIB2)
if(BUILD_LUA_RSVG)
- pkg_check_modules(RSVG REQUIRED librsvg-2.0)
- set(luarsvg_libs ${RSVG_LIBRARIES} ${LUA_LIBRARIES})
- set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
+ pkg_check_modules(RSVG REQUIRED librsvg-2.0)
+ set(luarsvg_libs ${RSVG_LIBRARIES} ${LUA_LIBRARIES})
+ set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
endif(BUILD_LUA_RSVG)
if(BUILD_AUDACIOUS)
- set(WANT_GLIB true)
- pkg_check_modules(NEW_AUDACIOUS audacious>=1.4.0)
- if(NEW_AUDACIOUS_FOUND)
- pkg_check_modules(AUDACIOUS REQUIRED audclient>=1.4.0)
- pkg_check_modules(DBUS_GLIB REQUIRED dbus-glib-1)
- else(NEW_AUDACIOUS_FOUND)
- pkg_check_modules(AUDACIOUS REQUIRED audacious<1.4.0)
- endif(NEW_AUDACIOUS_FOUND)
- set(conky_libs ${conky_libs} ${AUDACIOUS_LIBRARIES} ${DBUS_GLIB_LIBRARIES})
- set(conky_includes ${conky_includes} ${AUDACIOUS_INCLUDE_DIRS} ${DBUS_GLIB_INCLUDE_DIRS})
+ set(WANT_GLIB true)
+ pkg_check_modules(NEW_AUDACIOUS audacious>=1.4.0)
+ if(NEW_AUDACIOUS_FOUND)
+ pkg_check_modules(AUDACIOUS REQUIRED audclient>=1.4.0)
+ pkg_check_modules(DBUS_GLIB REQUIRED dbus-glib-1)
+ else(NEW_AUDACIOUS_FOUND)
+ pkg_check_modules(AUDACIOUS REQUIRED audacious<1.4.0)
+ endif(NEW_AUDACIOUS_FOUND)
+ set(conky_libs ${conky_libs} ${AUDACIOUS_LIBRARIES} ${DBUS_GLIB_LIBRARIES})
+ set(conky_includes ${conky_includes} ${AUDACIOUS_INCLUDE_DIRS} ${DBUS_GLIB_INCLUDE_DIRS})
endif(BUILD_AUDACIOUS)
if(BUILD_BMPX)
- pkg_check_modules(BMPX REQUIRED bmp-2.0>=0.14.0)
- set(conky_libs ${conky_libs} ${BMPX_LIBRARIES})
- set(conky_includes ${conky_includes} ${BMPX_INCLUDE_DIRS})
+ pkg_check_modules(BMPX REQUIRED bmp-2.0>=0.14.0)
+ set(conky_libs ${conky_libs} ${BMPX_LIBRARIES})
+ set(conky_includes ${conky_includes} ${BMPX_INCLUDE_DIRS})
endif(BUILD_BMPX)
if(BUILD_XMMS2)
- pkg_check_modules(XMMS2 REQUIRED xmms2-client>=0.6)
- set(conky_libs ${conky_libs} ${XMMS2_LIBRARIES})
- set(conky_includes ${conky_includes} ${XMMS2_INCLUDE_DIRS})
+ pkg_check_modules(XMMS2 REQUIRED xmms2-client>=0.6)
+ set(conky_libs ${conky_libs} ${XMMS2_LIBRARIES})
+ set(conky_includes ${conky_includes} ${XMMS2_INCLUDE_DIRS})
endif(BUILD_XMMS2)
if(BUILD_EVE)
- set(WANT_CURL true)
- set(WANT_LIBXML2 true)
+ set(WANT_CURL true)
+ set(WANT_LIBXML2 true)
endif(BUILD_EVE)
if(BUILD_CURL)
- set(WANT_CURL true)
+ set(WANT_CURL true)
endif(BUILD_CURL)
if(BUILD_RSS)
- set(WANT_CURL true)
- set(WANT_LIBXML2 true)
+ set(WANT_CURL true)
+ set(WANT_LIBXML2 true)
endif(BUILD_RSS)
if(BUILD_WEATHER_METAR)
- set(WANT_CURL true)
- set(BUILD_WEATHER true)
+ set(WANT_CURL true)
+ set(BUILD_WEATHER true)
endif(BUILD_WEATHER_METAR)
if(BUILD_WEATHER_XOAP)
- set(WANT_LIBXML2 true)
- set(WANT_CURL true)
- set(BUILD_XOAP true)
- set(BUILD_WEATHER true)
+ set(WANT_LIBXML2 true)
+ set(WANT_CURL true)
+ set(BUILD_XOAP true)
+ set(BUILD_WEATHER true)
endif(BUILD_WEATHER_XOAP)
if(BUILD_NVIDIA)
- find_path(XNVCtrl_INCLUDE_PATH NVCtrl/NVCtrl.h ${INCLUDE_SEARCH_PATH})
- find_library(XNVCtrl_LIB NAMES XNVCtrl)
- if(XNVCtrl_INCLUDE_PATH AND XNVCtrl_LIB)
- set(XNVCtrl_FOUND true)
- set(conky_libs ${conky_libs} ${XNVCtrl_LIB})
- set(conky_includes ${conky_includes} ${XNVCtrl_INCLUDE_PATH})
- else(XNVCtrl_INCLUDE_PATH AND XNVCtrl_LIB)
- message(FATAL_ERROR "Unable to find XNVCtrl library")
- endif(XNVCtrl_INCLUDE_PATH AND XNVCtrl_LIB)
+ find_path(XNVCtrl_INCLUDE_PATH NVCtrl/NVCtrl.h ${INCLUDE_SEARCH_PATH})
+ find_library(XNVCtrl_LIB NAMES XNVCtrl)
+ if(XNVCtrl_INCLUDE_PATH AND XNVCtrl_LIB)
+ set(XNVCtrl_FOUND true)
+ set(conky_libs ${conky_libs} ${XNVCtrl_LIB})
+ set(conky_includes ${conky_includes} ${XNVCtrl_INCLUDE_PATH})
+ else(XNVCtrl_INCLUDE_PATH AND XNVCtrl_LIB)
+ message(FATAL_ERROR "Unable to find XNVCtrl library")
+ endif(XNVCtrl_INCLUDE_PATH AND XNVCtrl_LIB)
endif(BUILD_NVIDIA)
if(BUILD_IMLIB2)
- pkg_search_module(IMLIB2 REQUIRED imlib2 Imlib2)
- set(conky_libs ${conky_libs} ${IMLIB2_LIB} ${IMLIB2_LDFLAGS})
- set(conky_includes ${conky_includes} ${IMLIB2_INCLUDE_PATH})
+ pkg_search_module(IMLIB2 REQUIRED imlib2 Imlib2)
+ set(conky_libs ${conky_libs} ${IMLIB2_LIB} ${IMLIB2_LDFLAGS})
+ set(conky_includes ${conky_includes} ${IMLIB2_INCLUDE_PATH})
endif(BUILD_IMLIB2)
if(BUILD_JOURNAL)
- pkg_search_module(SYSTEMD REQUIRED libsystemd)
- set(conky_libs ${conky_libs} ${SYSTEMD_LIB} ${SYSTEMD_LDFLAGS})
- set(conky_includes ${conky_includes} ${SYSTEMD_INCLUDE_PATH})
+ pkg_search_module(SYSTEMD REQUIRED libsystemd)
+ set(conky_libs ${conky_libs} ${SYSTEMD_LIB} ${SYSTEMD_LDFLAGS})
+ set(conky_includes ${conky_includes} ${SYSTEMD_INCLUDE_PATH})
endif(BUILD_JOURNAL)
if(BUILD_PULSEAUDIO)
- pkg_check_modules(PULSEAUDIO REQUIRED libpulse)
- set(conky_libs ${conky_libs} ${PULSEAUDIO_LIBRARIES})
- set(conky_includes ${conky_includes} ${PULSEAUDIO_INCLUDE_DIRS})
+ pkg_check_modules(PULSEAUDIO REQUIRED libpulse)
+ set(conky_libs ${conky_libs} ${PULSEAUDIO_LIBRARIES})
+ set(conky_includes ${conky_includes} ${PULSEAUDIO_INCLUDE_DIRS})
endif(BUILD_PULSEAUDIO)
# Common libraries
if(WANT_GLIB)
- pkg_check_modules(GLIB REQUIRED glib-2.0)
- set(conky_libs ${conky_libs} ${GLIB_LIBRARIES})
- set(conky_includes ${conky_includes} ${GLIB_INCLUDE_DIRS})
+ pkg_check_modules(GLIB REQUIRED glib-2.0)
+ set(conky_libs ${conky_libs} ${GLIB_LIBRARIES})
+ set(conky_includes ${conky_includes} ${GLIB_INCLUDE_DIRS})
endif(WANT_GLIB)
if(WANT_CURL)
- pkg_check_modules(CURL REQUIRED libcurl)
- set(conky_libs ${conky_libs} ${CURL_LIBRARIES})
- set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
+ pkg_check_modules(CURL REQUIRED libcurl)
+ set(conky_libs ${conky_libs} ${CURL_LIBRARIES})
+ set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
endif(WANT_CURL)
if(WANT_LIBXML2)
- pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
- set(conky_libs ${conky_libs} ${LIBXML2_LIBRARIES})
- set(conky_includes ${conky_includes} ${LIBXML2_INCLUDE_DIRS})
+ pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
+ set(conky_libs ${conky_libs} ${LIBXML2_LIBRARIES})
+ set(conky_includes ${conky_includes} ${LIBXML2_INCLUDE_DIRS})
endif(WANT_LIBXML2)
if(WANT_TOLUA)
- find_program(APP_TOLUA NAMES toluapp tolua++ tolua++5.1 tolua++-5.1)
- if(NOT APP_TOLUA)
- message(FATAL_ERROR "Unable to find program 'tolua++'")
- endif(NOT APP_TOLUA)
- find_library(TOLUA_LIBS NAMES toluapp tolua++ tolua++5.1 tolua++-5.1)
- find_path(TOLUA_INCLUDE_PATH tolua++.h ${INCLUDE_SEARCH_PATH})
- if(TOLUA_INCLUDE_PATH AND TOLUA_LIBS)
- set(TOLUA_FOUND true)
- else(TOLUA_INCLUDE_PATH AND TOLUA_LIBS)
- message(FATAL_ERROR "Unable to find tolua++ library")
- endif(TOLUA_INCLUDE_PATH AND TOLUA_LIBS)
- mark_as_advanced(APP_TOLUA TOLUA_INCLUDE_PATH TOLUA_LIBS)
- set(conky_includes ${conky_includes} ${TOLUA_INCLUDE_PATH})
- set(conky_libs ${conky_libs} ${TOLUA_LIBS})
- set(LUA_EXTRAS true)
+ find_program(APP_TOLUA NAMES toluapp tolua++ tolua++5.1 tolua++-5.1)
+ if(NOT APP_TOLUA)
+ message(FATAL_ERROR "Unable to find program 'tolua++'")
+ endif(NOT APP_TOLUA)
+ find_library(TOLUA_LIBS NAMES toluapp tolua++ tolua++5.1 tolua++-5.1)
+ find_path(TOLUA_INCLUDE_PATH tolua++.h ${INCLUDE_SEARCH_PATH})
+ if(TOLUA_INCLUDE_PATH AND TOLUA_LIBS)
+ set(TOLUA_FOUND true)
+ else(TOLUA_INCLUDE_PATH AND TOLUA_LIBS)
+ message(FATAL_ERROR "Unable to find tolua++ library")
+ endif(TOLUA_INCLUDE_PATH AND TOLUA_LIBS)
+ mark_as_advanced(APP_TOLUA TOLUA_INCLUDE_PATH TOLUA_LIBS)
+ set(conky_includes ${conky_includes} ${TOLUA_INCLUDE_PATH})
+ set(conky_libs ${conky_libs} ${TOLUA_LIBS})
+ set(LUA_EXTRAS true)
endif(WANT_TOLUA)
# Look for doc generation programs
if(MAINTAINER_MODE)
- # Used for doc generation
- find_program(APP_DB2X_XSLTPROC db2x_xsltproc)
- if(NOT APP_DB2X_XSLTPROC)
- message(FATAL_ERROR "Unable to find program 'db2x_xsltproc'")
- endif(NOT APP_DB2X_XSLTPROC)
- find_program(APP_DB2X_MANXML db2x_manxml)
- if(NOT APP_DB2X_MANXML)
- message(FATAL_ERROR "Unable to find program 'db2x_manxml'")
- endif(NOT APP_DB2X_MANXML)
- find_program(APP_XSLTPROC xsltproc)
- if(NOT APP_XSLTPROC)
- message(FATAL_ERROR "Unable to find program 'xsltproc'")
- endif(NOT APP_XSLTPROC)
- find_program(APP_MAN man)
- if(NOT APP_MAN)
- message(FATAL_ERROR "Unable to find program 'man'")
- endif(NOT APP_MAN)
- find_program(APP_LESS less)
- if(NOT APP_LESS)
- message(FATAL_ERROR "Unable to find program 'less'")
- endif(NOT APP_LESS)
- find_program(APP_SED sed)
- if(NOT APP_SED)
- message(FATAL_ERROR "Unable to find program 'sed'")
- endif(NOT APP_SED)
- mark_as_advanced(APP_DB2X_XSLTPROC APP_DB2X_MANXML APP_XSLTPROC APP_MAN APP_SED APP_LESS)
+ # Used for doc generation
+ find_program(APP_DB2X_XSLTPROC db2x_xsltproc)
+ if(NOT APP_DB2X_XSLTPROC)
+ message(FATAL_ERROR "Unable to find program 'db2x_xsltproc'")
+ endif(NOT APP_DB2X_XSLTPROC)
+ find_program(APP_DB2X_MANXML db2x_manxml)
+ if(NOT APP_DB2X_MANXML)
+ message(FATAL_ERROR "Unable to find program 'db2x_manxml'")
+ endif(NOT APP_DB2X_MANXML)
+ find_program(APP_XSLTPROC xsltproc)
+ if(NOT APP_XSLTPROC)
+ message(FATAL_ERROR "Unable to find program 'xsltproc'")
+ endif(NOT APP_XSLTPROC)
+ find_program(APP_MAN man)
+ if(NOT APP_MAN)
+ message(FATAL_ERROR "Unable to find program 'man'")
+ endif(NOT APP_MAN)
+ find_program(APP_LESS less)
+ if(NOT APP_LESS)
+ message(FATAL_ERROR "Unable to find program 'less'")
+ endif(NOT APP_LESS)
+ find_program(APP_SED sed)
+ if(NOT APP_SED)
+ message(FATAL_ERROR "Unable to find program 'sed'")
+ endif(NOT APP_SED)
+ mark_as_advanced(APP_DB2X_XSLTPROC APP_DB2X_MANXML APP_XSLTPROC APP_MAN APP_SED APP_LESS)
endif(MAINTAINER_MODE)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
- set(DEBUG true)
+ set(DEBUG true)
endif(CMAKE_BUILD_TYPE MATCHES "Debug")
# The version numbers are simply derived from the date and number of commits
# since start of month
if(DEBUG)
- execute_process(COMMAND
- ${APP_GIT} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git log
- --since=${VERSION_MAJOR}-${VERSION_MINOR}-01 --pretty=oneline COMMAND
- ${APP_WC} -l COMMAND ${APP_AWK} "{print $1}" RESULT_VARIABLE RETVAL
- OUTPUT_VARIABLE COMMIT_COUNT OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND
+ ${APP_GIT} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git log
+ --since=${VERSION_MAJOR}-${VERSION_MINOR}-01 --pretty=oneline COMMAND
+ ${APP_WC} -l COMMAND ${APP_AWK} "{print $1}" RESULT_VARIABLE RETVAL
+ OUTPUT_VARIABLE COMMIT_COUNT OUTPUT_STRIP_TRAILING_WHITESPACE)
endif(DEBUG)
diff --git a/cmake/Docbook.cmake b/cmake/Docbook.cmake
index 355c6bd2..060b8eb3 100644
--- a/cmake/Docbook.cmake
+++ b/cmake/Docbook.cmake
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
diff --git a/cmake/FindClangFormat.cmake b/cmake/FindClangFormat.cmake
new file mode 100644
index 00000000..036afd7a
--- /dev/null
+++ b/cmake/FindClangFormat.cmake
@@ -0,0 +1,34 @@
+# Find Clang format
+#
+#
+if(NOT CLANG_FORMAT_BIN_NAME)
+ set(CLANG_FORMAT_BIN_NAME clang-format)
+endif()
+
+# if custom path check there first
+if(CLANG_FORMAT_ROOT_DIR)
+ find_program(CLANG_FORMAT_BIN
+ NAMES
+ ${CLANG_FORMAT_BIN_NAME}
+ PATHS
+ "${CLANG_FORMAT_ROOT_DIR}"
+ NO_DEFAULT_PATH)
+endif()
+
+find_program(CLANG_FORMAT_BIN NAMES ${CLANG_FORMAT_BIN_NAME})
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+ CLANG_FORMAT
+ DEFAULT_MSG
+ CLANG_FORMAT_BIN)
+
+mark_as_advanced(
+ CLANG_FORMAT_BIN)
+
+if(CLANG_FORMAT_FOUND)
+ # A CMake script to find all source files and setup clang-format targets for them
+ include(clang-format)
+else()
+ message("clang-format not found. Not setting up format targets")
+endif()
diff --git a/cmake/ToLua.cmake b/cmake/ToLua.cmake
index c8b067c9..00de3f19 100644
--- a/cmake/ToLua.cmake
+++ b/cmake/ToLua.cmake
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2010 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
diff --git a/cmake/clang-format.cmake b/cmake/clang-format.cmake
new file mode 100644
index 00000000..423d1ef6
--- /dev/null
+++ b/cmake/clang-format.cmake
@@ -0,0 +1,62 @@
+# A CMake script to find all source files and setup clang-format targets for them
+
+# Find all source files
+set(CLANG_FORMAT_CXX_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.h *.cxx *.hxx *.hpp *.cc *.ipp)
+file(GLOB_RECURSE ALL_SOURCE_FILES ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
+
+# Don't include some common build folders
+set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake")
+
+# get all project files file
+foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
+ foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
+ string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND)
+ if (NOT ${EXCLUDE_FOUND} EQUAL -1)
+ list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
+ endif ()
+ endforeach ()
+endforeach ()
+
+add_custom_target(format
+ COMMENT "Running clang-format to change files"
+ COMMAND ${CLANG_FORMAT_BIN}
+ -style=file
+ -i
+ ${ALL_SOURCE_FILES}
+)
+
+
+add_custom_target(format-check
+ COMMENT "Checking clang-format changes"
+ # Use ! to negate the result for correct output
+ COMMAND !
+ ${CLANG_FORMAT_BIN}
+ -style=file
+ -output-replacements-xml
+ ${ALL_SOURCE_FILES}
+ | grep -q "replacement offset"
+)
+
+# Get the path to this file
+get_filename_component(_clangcheckpath ${CMAKE_CURRENT_LIST_FILE} PATH)
+# have at least one here by default
+set(CHANGED_FILE_EXTENSIONS ".cpp")
+foreach(EXTENSION ${CLANG_FORMAT_CXX_FILE_EXTENSIONS})
+ set(CHANGED_FILE_EXTENSIONS "${CHANGED_FILE_EXTENSIONS},${EXTENSION}" )
+endforeach()
+
+set(EXCLUDE_PATTERN_ARGS)
+foreach(EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
+ list(APPEND EXCLUDE_PATTERN_ARGS "--exclude=${EXCLUDE_PATTERN}")
+endforeach()
+
+# call the script to chech changed files in git
+add_custom_target(format-check-changed
+ COMMENT "Checking changed files in git"
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ COMMAND ${_clangcheckpath}/../scripts/clang-format-check-changed.py
+ --file-extensions \"${CHANGED_FILE_EXTENSIONS}\"
+ ${EXCLUDE_PATTERN_ARGS}
+ --clang-format-bin ${CLANG_FORMAT_BIN}
+)
+
diff --git a/cmake/scripts/clang-format-check-changed b/cmake/scripts/clang-format-check-changed
new file mode 100755
index 00000000..30da46ec
--- /dev/null
+++ b/cmake/scripts/clang-format-check-changed
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# Required because cmake root isn't git root in this example
+CLANG_FORMAT_BIN=$1
+GIT_ROOT=`git rev-parse --show-toplevel`
+
+pushd ${GIT_ROOT} > /dev/null
+
+git status --porcelain \
+ | egrep '*\.cpp|*\.h|*\.cxx|*\.hxx|*\.hpp|*\.cc' \
+ | awk -F " " '{print $NF}' \
+ | xargs -r ${CLANG_FORMAT_BIN} -style=file -output-replacements-xml \
+ | grep "replacement offset" 2>&1 > /dev/null
+
+RET=$?
+popd > /dev/null
+
+exit ${RET}
diff --git a/cmake/scripts/clang-format-check-changed.py b/cmake/scripts/clang-format-check-changed.py
new file mode 100755
index 00000000..6c91c2ae
--- /dev/null
+++ b/cmake/scripts/clang-format-check-changed.py
@@ -0,0 +1,163 @@
+#!/usr/bin/env python
+
+import argparse
+import os
+import sys
+import subprocess
+
+
+def check_file(filename, excludes, extensions):
+ """
+ Check if a file should be included in our check
+ """
+ name, ext = os.path.splitext(filename)
+
+ if len(ext) > 0 and ext in extensions:
+ if len(excludes) == 0:
+ return True
+
+ for exclude in excludes:
+ if exclude in filename:
+ return False
+
+ return True
+
+ return False
+
+
+def check_directory(directory, excludes, extensions):
+ output = []
+
+ if len(excludes) > 0:
+ for exclude in excludes:
+ if exclude in directory:
+ directory_excluded = False
+ return output
+
+ for root, _, files in os.walk(directory):
+ for file in files:
+ filename = os.path.join(root, file)
+ if check_file(filename, excludes, extensions):
+ print("Will check file [{}]".format(filename))
+ output.append(filename)
+ return output
+
+def get_git_root(git_bin):
+ cmd = [git_bin, "rev-parse", "--show-toplevel"]
+ try:
+ return subprocess.check_output(cmd).strip()
+ except subprocess.CalledProcessError, e:
+ print("Error calling git [{}]".format(e))
+ raise
+
+def clean_git_filename(line):
+ """
+ Takes a line from git status --porcelain and returns the filename
+ """
+ file = None
+ git_status = line[:2]
+ # Not an exhaustive list of git status output but should
+ # be enough for this case
+ # check if this is a delete
+ if 'D' in git_status:
+ return None
+ # ignored file
+ if '!' in git_status:
+ return None
+ # Covers renamed files
+ if '->' in line:
+ file = line[3:].split('->')[-1].strip()
+ else:
+ file = line[3:].strip()
+
+ return file
+
+
+def get_changed_files(git_bin, excludes, file_extensions):
+ """
+ Run git status and return the list of changed files
+ """
+ extensions = file_extensions.split(",")
+ # arguments coming from cmake will be *.xx. We want to remove the *
+ for i, extension in enumerate(extensions):
+ if extension[0] == '*':
+ extensions[i] = extension[1:]
+
+ git_root = get_git_root(git_bin)
+
+ cmd = [git_bin, "status", "--porcelain", "--ignore-submodules"]
+ print("git cmd = {}".format(cmd))
+ output = []
+ returncode = 0
+ try:
+ cmd_output = subprocess.check_output(cmd)
+ for line in cmd_output.split('\n'):
+ if len(line) > 0:
+ file = clean_git_filename(line)
+ if not file:
+ continue
+ file = os.path.join(git_root, file)
+
+ if file[-1] == "/":
+ directory_files = check_directory(
+ file, excludes, file_extensions)
+ output = output + directory_files
+ else:
+ if check_file(file, excludes, file_extensions):
+ print("Will check file [{}]".format(file))
+ output.append(file)
+
+ except subprocess.CalledProcessError, e:
+ print("Error calling git [{}]".format(e))
+ returncode = e.returncode
+
+ return output, returncode
+
+
+def run_clang_format(clang_format_bin, changed_files):
+ """
+ Run clang format on a list of files
+ @return 0 if formatted correctly.
+ """
+ if len(changed_files) == 0:
+ return 0
+ cmd = [clang_format_bin, "-style=file",
+ "-output-replacements-xml"] + changed_files
+ print("clang-format cmd = {}".format(cmd))
+ try:
+ cmd_output = subprocess.check_output(cmd)
+ if "replacement offset" in cmd_output:
+ print("ERROR: Changed files don't match format")
+ return 1
+ except subprocess.CalledProcessError, e:
+ print("Error calling clang-format [{}]".format(e))
+ return e.returncode
+
+ return 0
+
+
+def cli():
+ # global params
+ parser = argparse.ArgumentParser(prog='clang-format-check-changed',
+ description='Checks if files chagned in git match the .clang-format specification')
+ parser.add_argument("--file-extensions", type=str,
+ default=".cpp,.h,.cxx,.hxx,.hpp,.cc,.ipp",
+ help="Comma seperated list of file extensions to check")
+ parser.add_argument('--exclude', action='append', default=[],
+ help='Will not match the files / directories with these in the name')
+ parser.add_argument('--clang-format-bin', type=str, default="clang-format",
+ help="The clang format binary")
+ parser.add_argument('--git-bin', type=str, default="git",
+ help="The git binary")
+ args = parser.parse_args()
+
+ # Run gcovr to get the .gcda files form .gcno
+ changed_files, returncode = get_changed_files(
+ args.git_bin, args.exclude, args.file_extensions)
+ if returncode != 0:
+ return returncode
+
+ return run_clang_format(args.clang_format_bin, changed_files)
+
+if __name__ == '__main__':
+ sys.exit(cli())
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 6c943fea..b611ab3b 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
diff --git a/data/Makefile.am b/data/Makefile.am
deleted file mode 100644
index 126c4f24..00000000
--- a/data/Makefile.am
+++ /dev/null
@@ -1,31 +0,0 @@
-# -*- mode: Makefile; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
-#
-# Conky, a system monitor, based on torsmo
-#
-# Any original torsmo code is licensed under the BSD license
-#
-# All code written since the fork of torsmo is licensed under the GPL
-#
-# Please see COPYING for details
-#
-# Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
-# Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
-# All rights reserved.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-#
-
-configdir = ${sysconfdir}/conky
-dist_config_DATA = conky.conf conky_no_x11.conf
-
-# vi:set ts=4 sw=4 noet ai nocindent syntax=automake:
diff --git a/data/conky-dfly-smp.conf b/data/conky-dfly-smp.conf
index c89313ca..f728fc3d 100644
--- a/data/conky-dfly-smp.conf
+++ b/data/conky-dfly-smp.conf
@@ -1,4 +1,3 @@
--- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[
Conky, a system monitor, based on torsmo
@@ -9,7 +8,7 @@ All code written since the fork of torsmo is licensed under the GPL
Please see COPYING for details
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
-Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
+Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved.
This program is free software: you can redistribute it and/or modify
diff --git a/data/conky.conf b/data/conky.conf
index 3a7b935a..b3709c8d 100644
--- a/data/conky.conf
+++ b/data/conky.conf
@@ -1,4 +1,3 @@
--- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[
Conky, a system monitor, based on torsmo
@@ -9,7 +8,7 @@ All code written since the fork of torsmo is licensed under the GPL
Please see COPYING for details
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
-Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
+Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved.
This program is free software: you can redistribute it and/or modify
diff --git a/data/conky_no_x11.conf b/data/conky_no_x11.conf
index 07f18e7d..40a675da 100644
--- a/data/conky_no_x11.conf
+++ b/data/conky_no_x11.conf
@@ -7,7 +7,7 @@
-- Please see COPYING for details
-- Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
--- Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
+-- Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
-- All rights reserved.
-- This program is free software: you can redistribute it and/or modify
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
index b58e3e0f..74189bfc 100644
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
diff --git a/doc/docs.xml b/doc/docs.xml
index 83e9a320..856f40b2 100644
--- a/doc/docs.xml
+++ b/doc/docs.xml
@@ -303,7 +303,7 @@
Copying
- Copyright (c) 2005-2012 Brenden Matthews, Philip
+ Copyright (c) 2005-2018 Brenden Matthews, Philip
Kovacs, et. al. Any original torsmo code is licensed under
the BSD license (see LICENSE.BSD for a copy). All code
written since the fork of torsmo is licensed under the GPL
diff --git a/lua/CMakeLists.txt b/lua/CMakeLists.txt
index 436dd0c5..947c18ec 100644
--- a/lua/CMakeLists.txt
+++ b/lua/CMakeLists.txt
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
diff --git a/lua/libcairo-helper.h b/lua/libcairo-helper.h
index bec2d6e5..3b8dce37 100644
--- a/lua/libcairo-helper.h
+++ b/lua/libcairo-helper.h
@@ -1,10 +1,10 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -28,15 +28,15 @@
#include
cairo_text_extents_t *create_cairo_text_extents_t(void) {
- return calloc(1, sizeof(cairo_text_extents_t));
+ return calloc(1, sizeof(cairo_text_extents_t));
}
cairo_font_extents_t *create_cairo_font_extents_t(void) {
- return calloc(1, sizeof(cairo_font_extents_t));
+ return calloc(1, sizeof(cairo_font_extents_t));
}
cairo_matrix_t *create_cairo_matrix_t(void) {
- return calloc(1, sizeof(cairo_matrix_t));
+ return calloc(1, sizeof(cairo_matrix_t));
}
#endif /* _LIBCAIRO_HELPER_H_ */
diff --git a/lua/libcairo_imlib2_helper.h b/lua/libcairo_imlib2_helper.h
index 85ff9977..e8fa1ebc 100644
--- a/lua/libcairo_imlib2_helper.h
+++ b/lua/libcairo_imlib2_helper.h
@@ -1,10 +1,10 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -25,22 +25,22 @@
#ifndef _LIBCAIRO_IMAGE_HELPER_H_
#define _LIBCAIRO_IMAGE_HELPER_H_
-#include
#include
+#include
-void
-cairo_draw_image(const char * file, cairo_surface_t * cs, int x, int y,
- double scale_x, double scale_y,
- double * return_scale_w, double * return_scale_h)
-{
- Imlib_Image * image = imlib_load_image(file);
- if (! image) { return; }
+void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y,
+ double scale_x, double scale_y, double *return_scale_w,
+ double *return_scale_h) {
+ Imlib_Image *image = imlib_load_image(file);
+ if (!image) {
+ return;
+ }
imlib_context_set_image(image);
int w = imlib_image_get_width(), h = imlib_image_get_height();
- double scaled_w = *return_scale_w = scale_x * (double)w
- , scaled_h = *return_scale_h = scale_y * (double)h;
+ double scaled_w = *return_scale_w = scale_x * (double)w,
+ scaled_h = *return_scale_h = scale_y * (double)h;
/* create temporary image */
Imlib_Image premul = imlib_create_image(scaled_w, scaled_h);
@@ -59,11 +59,11 @@ cairo_draw_image(const char * file, cairo_surface_t * cs, int x, int y,
imlib_image_copy_alpha_to_image(image, 0, 0);
/* now pass the result to cairo */
- cairo_surface_t * result = cairo_image_surface_create_for_data(
- (void *) imlib_image_get_data_for_reading_only(),
- CAIRO_FORMAT_ARGB32, scaled_w, scaled_h, sizeof(DATA32) * scaled_w);
+ cairo_surface_t *result = cairo_image_surface_create_for_data(
+ (void *)imlib_image_get_data_for_reading_only(), CAIRO_FORMAT_ARGB32,
+ scaled_w, scaled_h, sizeof(DATA32) * scaled_w);
- cairo_t * cr = cairo_create(cs);
+ cairo_t *cr = cairo_create(cs);
cairo_set_source_surface(cr, result, x, y);
cairo_paint(cr);
diff --git a/lua/librsvg-helper.h b/lua/librsvg-helper.h
index 8918f558..2d960f6a 100644
--- a/lua/librsvg-helper.h
+++ b/lua/librsvg-helper.h
@@ -1,10 +1,10 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -26,19 +26,15 @@
#define _LIBRSVG_HELPER_H_
#include
-#include
#include
+#include
-RsvgDimensionData *
-rsvgDimensionDataCreate(void)
-{
+RsvgDimensionData *rsvgDimensionDataCreate(void) {
return (RsvgDimensionData *)calloc(1, sizeof(RsvgDimensionData));
}
-void
-rsvgDimensionDataGet(RsvgDimensionData * dd,
- int * width, int * height, double * em, double * ex)
-{
+void rsvgDimensionDataGet(RsvgDimensionData *dd, int *width, int *height,
+ double *em, double *ex) {
if (dd) {
*width = dd->width;
*height = dd->height;
@@ -47,51 +43,40 @@ rsvgDimensionDataGet(RsvgDimensionData * dd,
}
}
-RsvgPositionData *
-rsvgPositionDataCreate(void)
-{
+RsvgPositionData *rsvgPositionDataCreate(void) {
return (RsvgPositionData *)calloc(1, sizeof(RsvgPositionData));
}
-void
-rsvgPositionDataGet(RsvgPositionData * pd, int * x, int * y)
-{
+void rsvgPositionDataGet(RsvgPositionData *pd, int *x, int *y) {
if (pd) {
*x = pd->x;
*y = pd->y;
}
}
-RsvgHandle *
-rsvg_create_handle_from_file(const char * filename)
-{
- GError * error = NULL;
- RsvgHandle * handle = rsvg_handle_new_from_file(filename, &error);
+RsvgHandle *rsvg_create_handle_from_file(const char *filename) {
+ GError *error = NULL;
+ RsvgHandle *handle = rsvg_handle_new_from_file(filename, &error);
if (error) {
g_object_unref(error);
- if (handle)
- g_object_unref(handle);
+ if (handle) g_object_unref(handle);
handle = NULL;
}
return handle;
}
-int
-rsvg_destroy_handle(RsvgHandle * handle)
-{
+int rsvg_destroy_handle(RsvgHandle *handle) {
int status = 0;
if (handle) {
- GError * error = NULL;
+ GError *error = NULL;
status = rsvg_handle_close(handle, &error);
- if (status)
- g_object_unref(handle);
+ if (status) g_object_unref(handle);
- if (error)
- g_object_unref(error);
+ if (error) g_object_unref(error);
}
return status;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6a5b45df..040d0ead 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,10 +1,9 @@
-# vim: ts=4 sw=4 noet ai cindent syntax=cmake
#
# Conky, a system monitor, based on torsmo
#
# Please see COPYING for details
#
-# Copyright (c) 2005-2012 Brenden Matthews, et. al. (see AUTHORS)
+# Copyright (c) 2005-2018 Brenden Matthews, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
@@ -22,199 +21,310 @@
include_directories(${conky_includes})
if(BUILD_BUILTIN_CONFIG OR BUILD_OLD_CONFIG)
- # include config output dir
- include_directories(${CMAKE_BINARY_DIR}/data)
+ # include config output dir
+ include_directories(${CMAKE_BINARY_DIR}/data)
endif(BUILD_BUILTIN_CONFIG OR BUILD_OLD_CONFIG)
# ensure build.h and config.h aren't in the way
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
- message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/config.h' in order to build with CMake.")
+ message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/config.h' in order to build with CMake.")
endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build.h)
- message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/build.h' in order to build with CMake.")
+ message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/build.h' in order to build with CMake.")
endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build.h)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h)
- message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h' in order to build with CMake.")
+ message(FATAL_ERROR "You must remove the autotools generated file '${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h' in order to build with CMake.")
endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h)
-set(conky_sources c++wrap.cc colours.cc combine.cc common.cc conky.cc core.cc
- diskio.cc entropy.cc exec.cc fs.cc mail.cc net_stat.cc template.cc
- mboxscan.cc read_tcpip.cc scroll.cc specials.cc tailhead.cc temphelper.cc
- text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.cc proc.cc user.cc
- luamm.cc data-source.cc lua-config.cc setting.cc llua.cc update-cb.cc)
+set(conky_sources
+ ${conky_sources}
+ c++wrap.cc c++wrap.hh
+ colours.cc colours.h
+ combine.cc combine.h
+ common.cc common.h
+ conky.cc conky.h
+ core.cc core.h
+ diskio.cc diskio.h
+ entropy.cc entropy.h
+ exec.cc exec.h
+ fs.cc fs.h
+ mail.cc mail.h
+ net_stat.cc net_stat.h
+ template.cc template.h
+ mboxscan.cc mboxscan.h
+ read_tcpip.cc read_tcpip.h
+ scroll.cc scroll.h
+ specials.cc specials.h
+ tailhead.cc tailhead.h
+ temphelper.cc temphelper.h
+ text_object.cc text_object.h
+ timeinfo.cc timeinfo.h
+ top.cc top.h
+ algebra.cc algebra.h
+ prioqueue.cc prioqueue.h
+ proc.cc proc.h
+ user.cc user.h
+ luamm.cc luamm.hh
+ data-source.cc data-source.hh
+ lua-config.cc lua-config.hh
+ setting.cc setting.hh
+ llua.cc llua.h
+ update-cb.cc update-cb.hh
+ logging.h
+ semaphore.hh
+)
# Platform specific sources
if(OS_LINUX)
- set(linux linux.cc users.cc sony.cc i8k.cc)
- set(optional_sources ${optional_sources} ${linux})
+ set(linux
+ linux.cc linux.h
+ users.cc users.h
+ sony.cc sony.h
+ i8k.cc i8k.h
+ )
+ set(optional_sources ${optional_sources} ${linux})
endif(OS_LINUX)
if(OS_FREEBSD)
- set(freebsd freebsd.cc bsdapm.cc)
- set(optional_sources ${optional_sources} ${freebsd})
+ set(freebsd
+ freebsd.cc freebsd.h
+ bsdapm.cc bsdapm.h
+ )
+ set(optional_sources ${optional_sources} ${freebsd})
endif(OS_FREEBSD)
if(OS_DRAGONFLY)
- set(dragonfly dragonfly.cc bsdapm.cc)
- set(optional_sources ${optional_sources} ${dragonfly})
+ set(dragonfly
+ dragonfly.cc dragonfly.h
+ bsdapm.cc bsdapm.h
+ )
+ set(optional_sources ${optional_sources} ${dragonfly})
endif(OS_DRAGONFLY)
if(OS_OPENBSD)
- set(openbsd openbsd.cc bsdapm.cc)
- set(optional_sources ${optional_sources} ${openbsd})
+ set(openbsd
+ openbsd.cc openbsd.h
+ bsdapm.cc bsdapm.h
+ )
+ set(optional_sources ${optional_sources} ${openbsd})
endif(OS_OPENBSD)
# These below are not actually supported. No idea what their status is.
if(OS_SOLARIS)
- set(solaris solaris.cc)
- set(optional_sources ${optional_sources} ${solaris})
+ set(solaris
+ solaris.cc solaris.h
+ )
+ set(optional_sources ${optional_sources} ${solaris})
endif(OS_SOLARIS)
if(OS_NETBSD)
- set(netbsd netbsd.cc)
- set(optional_sources ${optional_sources} ${netbsd})
+ set(netbsd
+ netbsd.cc netbsd.h
+ )
+ set(optional_sources ${optional_sources} ${netbsd})
endif(OS_NETBSD)
if(OS_HAIKU)
- set(haiku haiku.cc)
- set(optional_sources ${optional_sources} ${haiku})
+ set(haiku
+ haiku.cc haiku.h
+ )
+ set(optional_sources ${optional_sources} ${haiku})
endif(OS_HAIKU)
if(OS_DARWIN)
- set(darwin darwin.cc)
- set(optional_sources ${optional_sources} ${darwin})
+ set(darwin
+ darwin.cc darwin.h
+ darwin_sip.h
+ i18n.h
+ )
+ set(optional_sources ${optional_sources} ${darwin})
endif(OS_DARWIN)
# Optional sources
if(HAVE_SOME_SOUNDCARD_H)
- set(mixer mixer.cc)
- set(optional_sources ${optional_sources} ${mixer})
+ set(mixer
+ mixer.cc mixer.h
+ )
+ set(optional_sources ${optional_sources} ${mixer})
endif(HAVE_SOME_SOUNDCARD_H)
if(BUILD_AUDACIOUS)
- set(audacious audacious.cc)
- set(optional_sources ${optional_sources} ${audacious})
+ set(audacious
+ audacious.cc audacious.h
+ )
+ set(optional_sources ${optional_sources} ${audacious})
endif(BUILD_AUDACIOUS)
if(BUILD_BMPX)
- set(bmpx bmpx.cc)
- set(optional_sources ${optional_sources} ${bmpx})
+ set(bmpx
+ bmpx.cc bmpx.h
+ )
+ set(optional_sources ${optional_sources} ${bmpx})
endif(BUILD_BMPX)
if(BUILD_IBM)
- set(ibm ibm.cc smapi.cc)
- set(optional_sources ${optional_sources} ${ibm})
+ set(ibm
+ ibm.cc ibm.h
+ smapi.cc smapi.h
+ )
+ set(optional_sources ${optional_sources} ${ibm})
endif(BUILD_IBM)
if(BUILD_MPD)
- set(mpd mpd.cc libmpdclient.cc)
- set(optional_sources ${optional_sources} ${mpd})
+ set(mpd
+ mpd.cc mpd.h
+ libmpdclient.cc libmpdclient.h
+ )
+ set(optional_sources ${optional_sources} ${mpd})
endif(BUILD_MPD)
if(BUILD_MYSQL)
- set(mysql mysql.cc)
- set(optional_sources ${optional_sources} ${mysql})
+ set(mysql
+ mysql.cc mysql.h
+ )
+ set(optional_sources ${optional_sources} ${mysql})
endif(BUILD_MYSQL)
if(BUILD_MOC)
- set(moc moc.cc)
- set(optional_sources ${optional_sources} ${moc})
+ set(moc
+ moc.cc moc.h
+ )
+ set(optional_sources ${optional_sources} ${moc})
endif(BUILD_MOC)
if(BUILD_CMUS)
- set(cmus cmus.cc)
- set(optional_sources ${optional_sources} ${cmus})
+ set(cmus
+ cmus.cc cmus.h
+ )
+ set(optional_sources ${optional_sources} ${cmus})
endif(BUILD_CMUS)
if(BUILD_JOURNAL)
- set(journal journal.cc)
- set(optional_sources ${optional_sources} ${journal})
+ set(journal
+ journal.cc journal.h
+ )
+ set(optional_sources ${optional_sources} ${journal})
endif(BUILD_JOURNAL)
if(BUILD_XMMS2)
- set(xmms2 xmms2.cc)
- set(optional_sources ${optional_sources} ${xmms2})
+ set(xmms2
+ xmms2.cc xmms2.h
+ )
+ set(optional_sources ${optional_sources} ${xmms2})
endif(BUILD_XMMS2)
if(BUILD_PORT_MONITORS)
- add_library(tcp-portmon libtcp-portmon.cc)
- set(conky_libs ${conky_libs} tcp-portmon)
- set(port_monitors tcp-portmon.cc)
- set(optional_sources ${optional_sources} ${port_monitors})
+ add_library(tcp-portmon libtcp-portmon.cc libtcp-portmon.h)
+ set(conky_libs ${conky_libs} tcp-portmon)
+ set(port_monitors
+ tcp-portmon.cc tcp-portmon.h
+ )
+ set(optional_sources ${optional_sources} ${port_monitors})
endif(BUILD_PORT_MONITORS)
if(BUILD_X11)
- set(x11 x11.cc fonts.cc)
- set(optional_sources ${optional_sources} ${x11})
+ set(x11
+ x11.cc x11.h
+ fonts.cc fonts.h
+ )
+ set(optional_sources ${optional_sources} ${x11})
- if(BUILD_XINERAMA)
- find_package(Xinerama REQUIRED)
- set(conky_libs ${conky_libs} ${Xinerama_LIBRARIES})
- endif(BUILD_XINERAMA)
+ if(BUILD_XINERAMA)
+ find_package(Xinerama REQUIRED)
+ set(conky_libs ${conky_libs} ${Xinerama_LIBRARIES})
+ endif(BUILD_XINERAMA)
endif(BUILD_X11)
if(BUILD_HDDTEMP)
- set(hddtemp hddtemp.cc)
- set(optional_sources ${optional_sources} ${hddtemp})
+ set(hddtemp
+ hddtemp.cc hddtemp.h
+ )
+ set(optional_sources ${optional_sources} ${hddtemp})
endif(BUILD_HDDTEMP)
if(BUILD_EVE)
- set(eve eve.cc)
- set(optional_sources ${optional_sources} ${eve})
+ set(eve
+ eve.cc eve.h
+ )
+ set(optional_sources ${optional_sources} ${eve})
endif(BUILD_EVE)
if(BUILD_CURL)
- set(ccurl_thread ccurl_thread.cc)
- set(optional_sources ${optional_sources} ${ccurl_thread})
+ set(ccurl_thread
+ ccurl_thread.cc ccurl_thread.h
+ )
+ set(optional_sources ${optional_sources} ${ccurl_thread})
endif(BUILD_CURL)
if(BUILD_RSS)
- set(rss rss.cc prss.cc)
- set(optional_sources ${optional_sources} ${rss})
+ set(rss
+ rss.cc rss.h
+ prss.cc prss.h
+ )
+ set(optional_sources ${optional_sources} ${rss})
endif(BUILD_RSS)
if(BUILD_WEATHER)
- set(weather weather.cc)
- set(optional_sources ${optional_sources} ${weather})
+ set(weather
+ weather.cc weather.h
+ )
+ set(optional_sources ${optional_sources} ${weather})
endif(BUILD_WEATHER)
if(BUILD_NVIDIA)
- set(nvidia nvidia.cc)
- set(optional_sources ${optional_sources} ${nvidia})
+ set(nvidia
+ nvidia.cc nvidia.h
+ )
+ set(optional_sources ${optional_sources} ${nvidia})
endif(BUILD_NVIDIA)
if(BUILD_IMLIB2)
- set(imlib2 imlib2.cc)
- set(optional_sources ${optional_sources} ${imlib2})
+ set(imlib2
+ imlib2.cc imlib2.h
+ )
+ set(optional_sources ${optional_sources} ${imlib2})
endif(BUILD_IMLIB2)
if(BUILD_APCUPSD)
- set(apcupsd apcupsd.cc)
- set(optional_sources ${optional_sources} ${apcupsd})
+ set(apcupsd
+ apcupsd.cc apcupsd.h
+ )
+ set(optional_sources ${optional_sources} ${apcupsd})
endif(BUILD_APCUPSD)
if(BUILD_ICAL)
- set(ical ical.cc)
- set(optional_sources ${optional_sources} ${ical})
+ set(ical
+ ical.cc ical.h
+ )
+ set(optional_sources ${optional_sources} ${ical})
endif(BUILD_ICAL)
if(BUILD_IRC)
- set(irc irc.cc)
- set(optional_sources ${optional_sources} ${irc})
+ set(irc
+ irc.cc irc.h
+ )
+ set(optional_sources ${optional_sources} ${irc})
endif(BUILD_IRC)
if(BUILD_ICONV)
- set(iconv iconv_tools.cc)
- set(optional_sources ${optional_sources} ${iconv})
+ set(iconv
+ iconv_tools.cc iconv_tools.h
+ )
+ set(optional_sources ${optional_sources} ${iconv})
endif(BUILD_ICONV)
if(BUILD_NCURSES)
- set(optional_sources ${optional_sources} nc.cc)
+ set(ncurses_srcs
+ nc.cc nc.h
+ )
+ set(optional_sources ${optional_sources} ${ncurses_srcs})
endif(BUILD_NCURSES)
if(BUILD_PULSEAUDIO)
- set(pulseaudio pulseaudio.cc)
- set(optional_sources ${optional_sources} ${pulseaudio})
+ set(pulseaudio
+ pulseaudio.cc pulseaudio.h
+ )
+ set(optional_sources ${optional_sources} ${pulseaudio})
endif(BUILD_PULSEAUDIO)
add_executable(conky ${conky_sources} ${optional_sources})
@@ -223,8 +333,8 @@ target_link_libraries(conky ${conky_libs})
# Install libtcp-portmon too?
install(TARGETS
- conky
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib
- ARCHIVE DESTINATION lib
+ conky
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
)
diff --git a/src/algebra.cc b/src/algebra.cc
index c984558f..0617972f 100644
--- a/src/algebra.cc
+++ b/src/algebra.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -27,250 +26,227 @@
* along with this program. If not, see .
*
*/
-#include "config.h"
-#include "conky.h"
#include "algebra.h"
-#include "logging.h"
#include
#include
#include
#include
#include
+#include "config.h"
+#include "conky.h"
+#include "logging.h"
/* find the operand in the given expression
* returns the index of the first op character or -1 on error
*/
-int find_match_op(const char *expr)
-{
- unsigned int idx;
+int find_match_op(const char *expr) {
+ unsigned int idx;
- for (idx = 0; idx < strlen(expr); idx++) {
- switch (expr[idx]) {
- case '=':
- case '!':
- if (expr[idx + 1] != '=')
- return -1;
- /* fall through */
- case '<':
- case '>':
- return idx;
- break;
- }
- }
- return -1;
+ for (idx = 0; idx < strlen(expr); idx++) {
+ switch (expr[idx]) {
+ case '=':
+ case '!':
+ if (expr[idx + 1] != '=') return -1;
+ /* fall through */
+ case '<':
+ case '>':
+ return idx;
+ break;
+ }
+ }
+ return -1;
}
-int get_match_type(const char *expr)
-{
- int idx;
- const char *str;
+int get_match_type(const char *expr) {
+ int idx;
+ const char *str;
- if ((idx = find_match_op(expr)) == -1)
- return -1;
- str = expr + idx;
+ if ((idx = find_match_op(expr)) == -1) return -1;
+ str = expr + idx;
- if (*str == '=' && *(str + 1) == '=')
- return OP_EQ;
- else if (*str == '!' && *(str + 1) == '=')
- return OP_NEQ;
- else if (*str == '>') {
- if (*(str + 1) == '=')
- return OP_GEQ;
- return OP_GT;
- } else if (*str == '<') {
- if (*(str + 1) == '=')
- return OP_LEQ;
- return OP_LT;
- }
- return -1;
+ if (*str == '=' && *(str + 1) == '=')
+ return OP_EQ;
+ else if (*str == '!' && *(str + 1) == '=')
+ return OP_NEQ;
+ else if (*str == '>') {
+ if (*(str + 1) == '=') return OP_GEQ;
+ return OP_GT;
+ } else if (*str == '<') {
+ if (*(str + 1) == '=') return OP_LEQ;
+ return OP_LT;
+ }
+ return -1;
}
-
-
/* generic compare function
*
* v is actually the difference of the compared values. For strings
* this is equal to the output of str(n)cmp(). Use a macro here, as
* it's type-independent.
*/
-#define COMPARE(v, t) \
- switch (t) { \
- case OP_GT: return (v > 0); \
- case OP_LT: return (v < 0); \
- case OP_EQ: return (v == 0); \
- case OP_GEQ: return (v >= 0); \
- case OP_LEQ: return (v <= 0); \
- case OP_NEQ: return (v != 0); \
- } \
- return 0
+#define COMPARE(v, t) \
+ switch (t) { \
+ case OP_GT: \
+ return (v > 0); \
+ case OP_LT: \
+ return (v < 0); \
+ case OP_EQ: \
+ return (v == 0); \
+ case OP_GEQ: \
+ return (v >= 0); \
+ case OP_LEQ: \
+ return (v <= 0); \
+ case OP_NEQ: \
+ return (v != 0); \
+ } \
+ return 0
-int lcompare(long a, enum match_type mtype, long b)
-{
- DBGP2("comparing longs '%ld' and '%ld'", a, b);
- COMPARE((a - b), mtype);
+int lcompare(long a, enum match_type mtype, long b) {
+ DBGP2("comparing longs '%ld' and '%ld'", a, b);
+ COMPARE((a - b), mtype);
}
-int dcompare(double a, enum match_type mtype, double b)
-{
- DBGP2("comparing doubles '%.lf' and '%.lf'", a, b);
- COMPARE((a - b), mtype);
+int dcompare(double a, enum match_type mtype, double b) {
+ DBGP2("comparing doubles '%.lf' and '%.lf'", a, b);
+ COMPARE((a - b), mtype);
}
-int scompare(const char *a, enum match_type mtype, const char *b)
-{
- DBGP2("comparing strings '%s' and '%s'", a, b);
- COMPARE(strcmp(a, b), mtype);
+int scompare(const char *a, enum match_type mtype, const char *b) {
+ DBGP2("comparing strings '%s' and '%s'", a, b);
+ COMPARE(strcmp(a, b), mtype);
}
-enum arg_type get_arg_type(const char *arg)
-{
- const char *p, *e;
+enum arg_type get_arg_type(const char *arg) {
+ const char *p, *e;
- p = arg;
- e = arg + strlen(arg)-1;
+ p = arg;
+ e = arg + strlen(arg) - 1;
- while (p != e && *e && *e == ' ')
- e--;
- while (p != e && *p == ' ')
- p++;
+ while (p != e && *e && *e == ' ') e--;
+ while (p != e && *p == ' ') p++;
- if (*p == '"' && *e == '"')
- return ARG_STRING;
+ if (*p == '"' && *e == '"') return ARG_STRING;
- if (*p == '-') //allow negative values
- p++;
- while (p <= e) {
- if (!isdigit(*p))
- break;
- p++;
- }
- if (p == e+1)
- return ARG_LONG;
- if (*p == '.') {
- p++;
- while (p <= e) {
- if (!isdigit(*p))
- return ARG_BAD;
- p++;
- }
- return ARG_DOUBLE;
- }
- return ARG_BAD;
+ if (*p == '-') // allow negative values
+ p++;
+ while (p <= e) {
+ if (!isdigit(*p)) break;
+ p++;
+ }
+ if (p == e + 1) return ARG_LONG;
+ if (*p == '.') {
+ p++;
+ while (p <= e) {
+ if (!isdigit(*p)) return ARG_BAD;
+ p++;
+ }
+ return ARG_DOUBLE;
+ }
+ return ARG_BAD;
}
-char *arg_to_string(const char *arg)
-{
- const char *start;
- int len;
+char *arg_to_string(const char *arg) {
+ const char *start;
+ int len;
- start = arg;
- len = 0;
- while (*start && *start == ' ')
- start++;
- if (!(*(start++) == '"'))
- return NULL;
- while (start[len] != '"')
- len++;
- return strndup(start, len);
+ start = arg;
+ len = 0;
+ while (*start && *start == ' ') start++;
+ if (!(*(start++) == '"')) return NULL;
+ while (start[len] != '"') len++;
+ return strndup(start, len);
}
-double arg_to_double(const char *arg)
-{
- double d;
- if (sscanf(arg, "%lf", &d) != 1) {
- NORM_ERR("converting '%s' to double failed", arg);
- return 0.0;
- }
- return d;
+double arg_to_double(const char *arg) {
+ double d;
+ if (sscanf(arg, "%lf", &d) != 1) {
+ NORM_ERR("converting '%s' to double failed", arg);
+ return 0.0;
+ }
+ return d;
}
-long arg_to_long(const char *arg)
-{
- long l;
- if (sscanf(arg, "%ld", &l) != 1) {
- NORM_ERR("converting '%s' to long failed", arg);
- return 0;
- }
- return l;
+long arg_to_long(const char *arg) {
+ long l;
+ if (sscanf(arg, "%ld", &l) != 1) {
+ NORM_ERR("converting '%s' to long failed", arg);
+ return 0;
+ }
+ return l;
}
-int compare(const char *expr)
-{
- char *expr_dup;
- int idx, mtype;
- enum arg_type type1, type2;
- long lng_a, lng_b;
- double dbl_a, dbl_b;
+int compare(const char *expr) {
+ char *expr_dup;
+ int idx, mtype;
+ enum arg_type type1, type2;
+ long lng_a, lng_b;
+ double dbl_a, dbl_b;
- idx = find_match_op(expr);
- mtype = get_match_type(expr);
+ idx = find_match_op(expr);
+ mtype = get_match_type(expr);
- if (!idx || mtype == -1) {
- NORM_ERR("failed to parse compare string '%s'", expr);
- return -2;
- }
+ if (!idx || mtype == -1) {
+ NORM_ERR("failed to parse compare string '%s'", expr);
+ return -2;
+ }
- expr_dup = strdup(expr);
- expr_dup[idx] = '\0';
- if (expr_dup[idx + 1] == '=')
- expr_dup[++idx] = '\0';
+ expr_dup = strdup(expr);
+ expr_dup[idx] = '\0';
+ if (expr_dup[idx + 1] == '=') expr_dup[++idx] = '\0';
- type1 = get_arg_type(expr_dup);
- type2 = get_arg_type(expr_dup + idx + 1);
- if (type1 == ARG_BAD || type2 == ARG_BAD) {
- NORM_ERR("Bad arguments: '%s' and '%s'", expr_dup, (expr_dup + idx + 1));
- free(expr_dup);
- return -2;
- }
- if (type1 == ARG_LONG && type2 == ARG_DOUBLE)
- type1 = ARG_DOUBLE;
- if (type1 == ARG_DOUBLE && type2 == ARG_LONG)
- type2 = ARG_DOUBLE;
- if (type1 != type2) {
- NORM_ERR("trying to compare args '%s' and '%s' of different type",
- expr_dup, (expr_dup + idx + 1));
- free(expr_dup);
- return -2;
- }
- switch (type1) {
- case ARG_STRING:
- {
- char *a, *b;
- a = arg_to_string(expr_dup);
- b = arg_to_string(expr_dup + idx + 1);
- idx = scompare(a, (enum match_type) mtype, b);
- free(a);
- free(b);
- free(expr_dup);
- return idx;
- }
- case ARG_LONG:
- lng_a = arg_to_long(expr_dup);
- lng_b = arg_to_long(expr_dup + idx + 1);
- free(expr_dup);
- return lcompare(lng_a, (enum match_type) mtype, lng_b);
- case ARG_DOUBLE:
- dbl_a = arg_to_double(expr_dup);
- dbl_b = arg_to_double(expr_dup + idx + 1);
- free(expr_dup);
- return dcompare(dbl_a, (enum match_type) mtype, dbl_b);
- case ARG_BAD: /* make_gcc_happy() */;
- }
- /* not reached */
- free(expr_dup);
- return -2;
+ type1 = get_arg_type(expr_dup);
+ type2 = get_arg_type(expr_dup + idx + 1);
+ if (type1 == ARG_BAD || type2 == ARG_BAD) {
+ NORM_ERR("Bad arguments: '%s' and '%s'", expr_dup, (expr_dup + idx + 1));
+ free(expr_dup);
+ return -2;
+ }
+ if (type1 == ARG_LONG && type2 == ARG_DOUBLE) type1 = ARG_DOUBLE;
+ if (type1 == ARG_DOUBLE && type2 == ARG_LONG) type2 = ARG_DOUBLE;
+ if (type1 != type2) {
+ NORM_ERR("trying to compare args '%s' and '%s' of different type", expr_dup,
+ (expr_dup + idx + 1));
+ free(expr_dup);
+ return -2;
+ }
+ switch (type1) {
+ case ARG_STRING: {
+ char *a, *b;
+ a = arg_to_string(expr_dup);
+ b = arg_to_string(expr_dup + idx + 1);
+ idx = scompare(a, (enum match_type)mtype, b);
+ free(a);
+ free(b);
+ free(expr_dup);
+ return idx;
+ }
+ case ARG_LONG:
+ lng_a = arg_to_long(expr_dup);
+ lng_b = arg_to_long(expr_dup + idx + 1);
+ free(expr_dup);
+ return lcompare(lng_a, (enum match_type)mtype, lng_b);
+ case ARG_DOUBLE:
+ dbl_a = arg_to_double(expr_dup);
+ dbl_b = arg_to_double(expr_dup + idx + 1);
+ free(expr_dup);
+ return dcompare(dbl_a, (enum match_type)mtype, dbl_b);
+ case ARG_BAD: /* make_gcc_happy() */;
+ }
+ /* not reached */
+ free(expr_dup);
+ return -2;
}
-int check_if_match(struct text_object *obj)
-{
- std::unique_ptr expression(new char[max_user_text.get(*state)]);
- int val;
- int result = 1;
+int check_if_match(struct text_object *obj) {
+ std::unique_ptr expression(new char[max_user_text.get(*state)]);
+ int val;
+ int result = 1;
- generate_text_internal(expression.get(), max_user_text.get(*state), *obj->sub);
- DBGP("parsed arg into '%s'", expression.get());
+ generate_text_internal(expression.get(), max_user_text.get(*state),
+ *obj->sub);
+ DBGP("parsed arg into '%s'", expression.get());
- val = compare(expression.get());
- if (val == -2) {
- NORM_ERR("compare failed for expression '%s'", expression.get());
- } else if (!val) {
- result = 0;
- }
- return result;
+ val = compare(expression.get());
+ if (val == -2) {
+ NORM_ERR("compare failed for expression '%s'", expression.get());
+ } else if (!val) {
+ result = 0;
+ }
+ return result;
}
diff --git a/src/algebra.h b/src/algebra.h
index a3194ee5..c80b8b17 100644
--- a/src/algebra.h
+++ b/src/algebra.h
@@ -1,5 +1,4 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=c
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -31,19 +30,19 @@
#define _ALGEBRA_H
enum match_type {
- OP_LT = 1, /* < */
- OP_GT = 2, /* > */
- OP_EQ = 3, /* == */
- OP_LEQ = 4, /* <= */
- OP_GEQ = 5, /* >= */
- OP_NEQ = 6 /* != */
+ OP_LT = 1, /* < */
+ OP_GT = 2, /* > */
+ OP_EQ = 3, /* == */
+ OP_LEQ = 4, /* <= */
+ OP_GEQ = 5, /* >= */
+ OP_NEQ = 6 /* != */
};
enum arg_type {
- ARG_BAD = 0, /* something strange */
- ARG_STRING = 1, /* "asdf" */
- ARG_LONG = 2, /* 123456 */
- ARG_DOUBLE = 3 /* 12.456 */
+ ARG_BAD = 0, /* something strange */
+ ARG_STRING = 1, /* "asdf" */
+ ARG_LONG = 2, /* 123456 */
+ ARG_DOUBLE = 3 /* 12.456 */
};
int compare(const char *);
diff --git a/src/apcupsd.cc b/src/apcupsd.cc
index 8f088ff6..7e2c7de8 100644
--- a/src/apcupsd.cc
+++ b/src/apcupsd.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* apcupsd.c: conky module for APC UPS daemon monitoring
*
@@ -22,260 +21,254 @@
*
*/
-#include "conky.h"
#include "apcupsd.h"
+#include "conky.h"
#include "logging.h"
#include "text_object.h"
#include
-#include
#include
+#include
#include
#include
enum _apcupsd_items {
- APCUPSD_NAME,
- APCUPSD_MODEL,
- APCUPSD_UPSMODE,
- APCUPSD_CABLE,
- APCUPSD_STATUS,
- APCUPSD_LINEV,
- APCUPSD_LOAD,
- APCUPSD_CHARGE,
- APCUPSD_TIMELEFT,
- APCUPSD_TEMP,
- APCUPSD_LASTXFER,
- _APCUPSD_COUNT
+ APCUPSD_NAME,
+ APCUPSD_MODEL,
+ APCUPSD_UPSMODE,
+ APCUPSD_CABLE,
+ APCUPSD_STATUS,
+ APCUPSD_LINEV,
+ APCUPSD_LOAD,
+ APCUPSD_CHARGE,
+ APCUPSD_TIMELEFT,
+ APCUPSD_TEMP,
+ APCUPSD_LASTXFER,
+ _APCUPSD_COUNT
};
/* type for data exchange with main thread */
#define APCUPSD_MAXSTR 32
typedef struct apcupsd_s {
- char items[_APCUPSD_COUNT][APCUPSD_MAXSTR+1]; /* e.g. items[APCUPSD_STATUS] */
- char host[64];
- int port;
+ char items[_APCUPSD_COUNT]
+ [APCUPSD_MAXSTR + 1]; /* e.g. items[APCUPSD_STATUS] */
+ char host[64];
+ int port;
} APCUPSD_S, *PAPCUPSD_S;
static APCUPSD_S apcupsd;
-
//
// encapsulated recv()
//
-static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv)
-{
- fd_set fds;
- int res;
+static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv) {
+ fd_set fds;
+ int res;
- // wait for some data to be read
- do {
- errno = 0;
- FD_ZERO(&fds);
- FD_SET(sock, &fds);
- res = select(sock + 1, &fds, NULL, NULL, tv);
- } while (res < 0 && errno == EINTR);
- if (res < 0) return 0;
- if (res == 0) {
- // timeout
- errno = ETIMEDOUT; // select was succesfull, errno is now 0
- return 0;
- }
+ // wait for some data to be read
+ do {
+ errno = 0;
+ FD_ZERO(&fds);
+ FD_SET(sock, &fds);
+ res = select(sock + 1, &fds, NULL, NULL, tv);
+ } while (res < 0 && errno == EINTR);
+ if (res < 0) return 0;
+ if (res == 0) {
+ // timeout
+ errno = ETIMEDOUT; // select was succesfull, errno is now 0
+ return 0;
+ }
- // socket ready, read the data
- do {
- errno = 0;
- res = recv(sock, (char*)buf, size, 0);
- } while (res < 0 && errno == EINTR);
- if (res < 0) return 0;
- if (res == 0) {
- // orderly shutdown
- errno = ENOTCONN;
- return 0;
- }
+ // socket ready, read the data
+ do {
+ errno = 0;
+ res = recv(sock, (char *)buf, size, 0);
+ } while (res < 0 && errno == EINTR);
+ if (res < 0) return 0;
+ if (res == 0) {
+ // orderly shutdown
+ errno = ENOTCONN;
+ return 0;
+ }
- return res;
+ return res;
}
//
// read whole buffer or fail
//
-static int net_recv(int sock, void* buf, int size)
-{
- int todo = size;
- int off = 0;
- int len;
- struct timeval tv = { 0, 250000 };
+static int net_recv(int sock, void *buf, int size) {
+ int todo = size;
+ int off = 0;
+ int len;
+ struct timeval tv = {0, 250000};
- while (todo) {
- len = net_recv_ex(sock, (char*)buf + off, todo, &tv);
- if (!len) return 0;
- todo -= len;
- off += len;
- }
- return 1;
+ while (todo) {
+ len = net_recv_ex(sock, (char *)buf + off, todo, &tv);
+ if (!len) return 0;
+ todo -= len;
+ off += len;
+ }
+ return 1;
}
//
// get one response line
//
-static int get_line(int sock, char line[], short linesize)
-{
- // get the line length
- short sz;
- if (!net_recv(sock, &sz, sizeof(sz))) return -1;
- sz = ntohs(sz);
- if (!sz) return 0;
+static int get_line(int sock, char line[], short linesize) {
+ // get the line length
+ short sz;
+ if (!net_recv(sock, &sz, sizeof(sz))) return -1;
+ sz = ntohs(sz);
+ if (!sz) return 0;
- // get the line
- while (sz >= linesize) {
- // this is just a hack (being lazy), this should not happen anyway
- net_recv(sock, line, linesize);
- sz -= linesize;
- }
- if (!net_recv(sock, line, sz)) return 0;
- line[sz] = 0;
- return sz;
+ // get the line
+ while (sz >= linesize) {
+ // this is just a hack (being lazy), this should not happen anyway
+ net_recv(sock, line, linesize);
+ sz -= linesize;
+ }
+ if (!net_recv(sock, line, sz)) return 0;
+ line[sz] = 0;
+ return sz;
}
-#define FILL(NAME,FIELD,FIRST) \
- if (!strncmp(NAME, line, sizeof(NAME)-1)) { \
- strncpy(apc->items[FIELD], line+11, APCUPSD_MAXSTR); \
- /* remove trailing newline and assure termination */ \
- apc->items[FIELD][len-11 > APCUPSD_MAXSTR ? APCUPSD_MAXSTR : len-12] = 0; \
- if (FIRST) { \
- char* c; \
- for (c = apc->items[FIELD]; *c; ++c) \
- if (*c == ' ' && c > apc->items[FIELD]+2) { \
- *c = 0; \
- break; \
- } \
- } \
- }
+#define FILL(NAME, FIELD, FIRST) \
+ if (!strncmp(NAME, line, sizeof(NAME) - 1)) { \
+ strncpy(apc->items[FIELD], line + 11, APCUPSD_MAXSTR); \
+ /* remove trailing newline and assure termination */ \
+ apc->items[FIELD][len - 11 > APCUPSD_MAXSTR ? APCUPSD_MAXSTR : len - 12] = \
+ 0; \
+ if (FIRST) { \
+ char *c; \
+ for (c = apc->items[FIELD]; *c; ++c) \
+ if (*c == ' ' && c > apc->items[FIELD] + 2) { \
+ *c = 0; \
+ break; \
+ } \
+ } \
+ }
//
// fills in the data received from a socket
//
-static int fill_items(int sock, PAPCUPSD_S apc)
-{
- char line[512];
- int len;
- while ((len = get_line(sock, line, sizeof(line)))) {
- // fill the right types in
- FILL("UPSNAME", APCUPSD_NAME, FALSE);
- FILL("MODEL", APCUPSD_MODEL, FALSE);
- FILL("UPSMODE", APCUPSD_UPSMODE, FALSE);
- FILL("CABLE", APCUPSD_CABLE, FALSE);
- FILL("STATUS", APCUPSD_STATUS, FALSE);
- FILL("LINEV", APCUPSD_LINEV, TRUE);
- FILL("LOADPCT", APCUPSD_LOAD, TRUE);
- FILL("BCHARGE", APCUPSD_CHARGE, TRUE);
- FILL("TIMELEFT", APCUPSD_TIMELEFT, TRUE);
- FILL("ITEMP", APCUPSD_TEMP, TRUE);
- FILL("LASTXFER", APCUPSD_LASTXFER, FALSE);
- }
+static int fill_items(int sock, PAPCUPSD_S apc) {
+ char line[512];
+ int len;
+ while ((len = get_line(sock, line, sizeof(line)))) {
+ // fill the right types in
+ FILL("UPSNAME", APCUPSD_NAME, FALSE);
+ FILL("MODEL", APCUPSD_MODEL, FALSE);
+ FILL("UPSMODE", APCUPSD_UPSMODE, FALSE);
+ FILL("CABLE", APCUPSD_CABLE, FALSE);
+ FILL("STATUS", APCUPSD_STATUS, FALSE);
+ FILL("LINEV", APCUPSD_LINEV, TRUE);
+ FILL("LOADPCT", APCUPSD_LOAD, TRUE);
+ FILL("BCHARGE", APCUPSD_CHARGE, TRUE);
+ FILL("TIMELEFT", APCUPSD_TIMELEFT, TRUE);
+ FILL("ITEMP", APCUPSD_TEMP, TRUE);
+ FILL("LASTXFER", APCUPSD_LASTXFER, FALSE);
+ }
- return len == 0;
+ return len == 0;
}
//
// Conky update function for apcupsd data
//
-int update_apcupsd(void)
-{
- int i;
- APCUPSD_S apc;
- int sock;
+int update_apcupsd(void) {
+ int i;
+ APCUPSD_S apc;
+ int sock;
- for (i = 0; i < _APCUPSD_COUNT; ++i)
- memcpy(apc.items[i], "N/A", 4); // including \0
+ for (i = 0; i < _APCUPSD_COUNT; ++i)
+ memcpy(apc.items[i], "N/A", 4); // including \0
- do {
- struct addrinfo hints;
- struct addrinfo *ai, *rp;
- int res;
- short sz = 0;
- char portbuf[8];
- //
- // connect to apcupsd daemon
- //
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = 0;
- hints.ai_protocol = 0;
- snprintf(portbuf, 8, "%d", apcupsd.port);
- res = getaddrinfo(apcupsd.host, portbuf, &hints, &ai);
- if (res != 0) {
- NORM_ERR("APCUPSD getaddrinfo: %s", gai_strerror(res));
- break;
- }
- for (rp = ai; rp != NULL; rp = rp->ai_next) {
- sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
- if (sock == -1) {
- continue;
- }
- if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) {
- break;
- }
- close(sock);
- }
- freeaddrinfo(ai);
- if (rp == NULL) {
- // no error reporting, the daemon is probably not running
- break;
- }
+ do {
+ struct addrinfo hints;
+ struct addrinfo *ai, *rp;
+ int res;
+ short sz = 0;
+ char portbuf[8];
+ //
+ // connect to apcupsd daemon
+ //
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = 0;
+ hints.ai_protocol = 0;
+ snprintf(portbuf, 8, "%d", apcupsd.port);
+ res = getaddrinfo(apcupsd.host, portbuf, &hints, &ai);
+ if (res != 0) {
+ NORM_ERR("APCUPSD getaddrinfo: %s", gai_strerror(res));
+ break;
+ }
+ for (rp = ai; rp != NULL; rp = rp->ai_next) {
+ sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (sock == -1) {
+ continue;
+ }
+ if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) {
+ break;
+ }
+ close(sock);
+ }
+ freeaddrinfo(ai);
+ if (rp == NULL) {
+ // no error reporting, the daemon is probably not running
+ break;
+ }
- //
- // send status request - "status" - 6B
- //
- sz = htons(6);
- // no waiting to become writeable is really needed
- if (send(sock, &sz, sizeof(sz), 0) != sizeof(sz) || send(sock, "status", 6, 0) != 6) {
- perror("send");
- break;
- }
+ //
+ // send status request - "status" - 6B
+ //
+ sz = htons(6);
+ // no waiting to become writeable is really needed
+ if (send(sock, &sz, sizeof(sz), 0) != sizeof(sz) ||
+ send(sock, "status", 6, 0) != 6) {
+ perror("send");
+ break;
+ }
- //
- // read the lines of output and put them into the info structure
- //
- if (!fill_items(sock, &apc)) break;
+ //
+ // read the lines of output and put them into the info structure
+ //
+ if (!fill_items(sock, &apc)) break;
- } while (0);
+ } while (0);
- close(sock);
+ close(sock);
- //
- // "atomically" copy the data into working set
- //
- memcpy(apcupsd.items, apc.items, sizeof(apcupsd.items));
- return 0;
+ //
+ // "atomically" copy the data into working set
+ //
+ memcpy(apcupsd.items, apc.items, sizeof(apcupsd.items));
+ return 0;
}
-int apcupsd_scan_arg(const char *arg)
-{
- char host[64];
- int port;
- if (sscanf(arg, "%63s %d", host, &port) != 2)
- return 1;
+int apcupsd_scan_arg(const char *arg) {
+ char host[64];
+ int port;
+ if (sscanf(arg, "%63s %d", host, &port) != 2) return 1;
- apcupsd.port = port;
- strncpy(apcupsd.host, host, sizeof(apcupsd.host));
- return 0;
+ apcupsd.port = port;
+ strncpy(apcupsd.host, host, sizeof(apcupsd.host));
+ return 0;
}
-double apcupsd_loadbarval(struct text_object *obj)
-{
- (void)obj;
+double apcupsd_loadbarval(struct text_object *obj) {
+ (void)obj;
- return atof(apcupsd.items[APCUPSD_LOAD]);
+ return atof(apcupsd.items[APCUPSD_LOAD]);
}
-#define APCUPSD_PRINT_GENERATOR(name, idx) \
-void print_apcupsd_##name(struct text_object *obj, char *p, int p_max_size) \
-{ \
- (void)obj; \
- snprintf(p, p_max_size, "%s", apcupsd.items[APCUPSD_##idx]); \
-}
+#define APCUPSD_PRINT_GENERATOR(name, idx) \
+ void print_apcupsd_##name(struct text_object *obj, char *p, \
+ int p_max_size) { \
+ (void)obj; \
+ snprintf(p, p_max_size, "%s", apcupsd.items[APCUPSD_##idx]); \
+ }
APCUPSD_PRINT_GENERATOR(name, NAME)
APCUPSD_PRINT_GENERATOR(model, MODEL)
diff --git a/src/apcupsd.h b/src/apcupsd.h
index 67862b44..2c4cf835 100644
--- a/src/apcupsd.h
+++ b/src/apcupsd.h
@@ -1,5 +1,4 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=c
+/*
*
* apcupsd.h: conky module for APC UPS daemon monitoring
*
diff --git a/src/audacious.cc b/src/audacious.cc
index b39775eb..4c38ebea 100644
--- a/src/audacious.cc
+++ b/src/audacious.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* audacious.c: conky support for audacious music player
*
@@ -26,219 +25,213 @@
#include
+#include
+#include "audacious.h"
#include "conky.h"
#include "logging.h"
-#include "audacious.h"
-#include
#include "update-cb.hh"
#include
#ifdef NEW_AUDACIOUS_FOUND
-#include
#include
#include
+#include
#else /* NEW_AUDACIOUS_FOUND */
#include
-#define audacious_remote_is_running(x) \
- xmms_remote_is_running(x)
-#define audacious_remote_is_paused(x) \
- xmms_remote_is_paused(x)
-#define audacious_remote_is_playing(x) \
- xmms_remote_is_playing(x)
-#define audacious_remote_get_playlist_pos(x) \
- xmms_remote_get_playlist_pos(x)
-#define audacious_remote_get_playlist_title(x, y) \
- xmms_remote_get_playlist_title(x, y)
-#define audacious_remote_get_playlist_time(x, y) \
- xmms_remote_get_playlist_time(x, y)
-#define audacious_remote_get_output_time(x) \
- xmms_remote_get_output_time(x)
-#define audacious_remote_get_info(w, x, y, z) \
- xmms_remote_get_info(w, x, y, z)
-#define audacious_remote_get_playlist_file(x, y) \
- xmms_remote_get_playlist_file(x, y)
-#define audacious_remote_get_playlist_length(x) \
- xmms_remote_get_playlist_length(x)
+#define audacious_remote_is_running(x) xmms_remote_is_running(x)
+#define audacious_remote_is_paused(x) xmms_remote_is_paused(x)
+#define audacious_remote_is_playing(x) xmms_remote_is_playing(x)
+#define audacious_remote_get_playlist_pos(x) xmms_remote_get_playlist_pos(x)
+#define audacious_remote_get_playlist_title(x, y) \
+ xmms_remote_get_playlist_title(x, y)
+#define audacious_remote_get_playlist_time(x, y) \
+ xmms_remote_get_playlist_time(x, y)
+#define audacious_remote_get_output_time(x) xmms_remote_get_output_time(x)
+#define audacious_remote_get_info(w, x, y, z) xmms_remote_get_info(w, x, y, z)
+#define audacious_remote_get_playlist_file(x, y) \
+ xmms_remote_get_playlist_file(x, y)
+#define audacious_remote_get_playlist_length(x) \
+ xmms_remote_get_playlist_length(x)
#endif /* NEW_AUDACIOUS_FOUND */
namespace {
- enum aud_status { AS_NOT_RUNNING, AS_PAUSED, AS_PLAYING, AS_STOPPED };
- const char * const as_message[] = { "Not running", "Paused", "Playing", "Stopped" };
+enum aud_status { AS_NOT_RUNNING, AS_PAUSED, AS_PLAYING, AS_STOPPED };
+const char *const as_message[] = {"Not running", "Paused", "Playing",
+ "Stopped"};
- struct aud_result {
- std::string title;
- std::string filename;
- int length; // in ms
- int position; // in ms
- int bitrate;
- int frequency;
- int channels;
- int playlist_length;
- int playlist_position;
- int main_volume;
- aud_status status;
+struct aud_result {
+ std::string title;
+ std::string filename;
+ int length; // in ms
+ int position; // in ms
+ int bitrate;
+ int frequency;
+ int channels;
+ int playlist_length;
+ int playlist_position;
+ int main_volume;
+ aud_status status;
- aud_result()
- : length(0), position(0), bitrate(0), frequency(0), channels(0), playlist_length(0),
- playlist_position(0), main_volume(0), status(AS_NOT_RUNNING)
- {}
- };
+ aud_result()
+ : length(0),
+ position(0),
+ bitrate(0),
+ frequency(0),
+ channels(0),
+ playlist_length(0),
+ playlist_position(0),
+ main_volume(0),
+ status(AS_NOT_RUNNING) {}
+};
- class audacious_cb: public conky::callback {
- typedef conky::callback Base;
+class audacious_cb : public conky::callback {
+ typedef conky::callback Base;
#ifdef NEW_AUDACIOUS_FOUND
- DBusGProxy *session;
+ DBusGProxy *session;
#else
- gint session;
+ gint session;
#endif
- protected:
- virtual void work();
+ protected:
+ virtual void work();
- public:
- audacious_cb(uint32_t period)
- : Base(period, false, Tuple())
- {
+ public:
+ audacious_cb(uint32_t period) : Base(period, false, Tuple()) {
#ifdef NEW_AUDACIOUS_FOUND
- g_type_init();
- DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- if (!connection)
- throw std::runtime_error("unable to establish dbus connection");
+ g_type_init();
+ DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ if (!connection)
+ throw std::runtime_error("unable to establish dbus connection");
- session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE,
- AUDACIOUS_DBUS_PATH, AUDACIOUS_DBUS_INTERFACE);
- if (!session)
- throw std::runtime_error("unable to create dbus proxy");
+ session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE,
+ AUDACIOUS_DBUS_PATH,
+ AUDACIOUS_DBUS_INTERFACE);
+ if (!session) throw std::runtime_error("unable to create dbus proxy");
#else
- session = 0;
+ session = 0;
#endif /* NEW_AUDACIOUS_FOUND */
- }
+ }
#ifdef NEW_AUDACIOUS_FOUND
- ~audacious_cb()
- {
- /* release reference to dbus proxy */
- g_object_unref(session);
- }
+ ~audacious_cb() {
+ /* release reference to dbus proxy */
+ g_object_unref(session);
+ }
#endif
- };
+};
- /* ---------------------------------------------------
- * Worker thread function for audacious data sampling.
- * --------------------------------------------------- */
- void audacious_cb::work()
- {
- aud_result tmp;
- gchar *psong, *pfilename;
- psong = NULL;
- pfilename = NULL;
+/* ---------------------------------------------------
+ * Worker thread function for audacious data sampling.
+ * --------------------------------------------------- */
+void audacious_cb::work() {
+ aud_result tmp;
+ gchar *psong, *pfilename;
+ psong = NULL;
+ pfilename = NULL;
- do {
- if (!audacious_remote_is_running(session)) {
- tmp.status = AS_NOT_RUNNING;
- break;
- }
+ do {
+ if (!audacious_remote_is_running(session)) {
+ tmp.status = AS_NOT_RUNNING;
+ break;
+ }
- /* Player status */
- if (audacious_remote_is_paused(session)) {
- tmp.status = AS_PAUSED;
- } else if (audacious_remote_is_playing(session)) {
- tmp.status = AS_PLAYING;
- } else {
- tmp.status = AS_STOPPED;
- }
+ /* Player status */
+ if (audacious_remote_is_paused(session)) {
+ tmp.status = AS_PAUSED;
+ } else if (audacious_remote_is_playing(session)) {
+ tmp.status = AS_PLAYING;
+ } else {
+ tmp.status = AS_STOPPED;
+ }
- /* Current song title */
- tmp.playlist_position = audacious_remote_get_playlist_pos(session);
- psong = audacious_remote_get_playlist_title(session, tmp.playlist_position);
- if (psong) {
- tmp.title = psong;
- g_free(psong);
- }
+ /* Current song title */
+ tmp.playlist_position = audacious_remote_get_playlist_pos(session);
+ psong = audacious_remote_get_playlist_title(session, tmp.playlist_position);
+ if (psong) {
+ tmp.title = psong;
+ g_free(psong);
+ }
- /* Current song length */
- tmp.length = audacious_remote_get_playlist_time(session, tmp.playlist_position);
+ /* Current song length */
+ tmp.length =
+ audacious_remote_get_playlist_time(session, tmp.playlist_position);
- /* Current song position */
- tmp.position = audacious_remote_get_output_time(session);
+ /* Current song position */
+ tmp.position = audacious_remote_get_output_time(session);
- /* Current song bitrate, frequency, channels */
- audacious_remote_get_info(session, &tmp.bitrate, &tmp.frequency, &tmp.channels);
+ /* Current song bitrate, frequency, channels */
+ audacious_remote_get_info(session, &tmp.bitrate, &tmp.frequency,
+ &tmp.channels);
- /* Current song filename */
- pfilename = audacious_remote_get_playlist_file(session, tmp.playlist_position);
- if (pfilename) {
- tmp.filename = pfilename;
- g_free(pfilename);
- }
+ /* Current song filename */
+ pfilename =
+ audacious_remote_get_playlist_file(session, tmp.playlist_position);
+ if (pfilename) {
+ tmp.filename = pfilename;
+ g_free(pfilename);
+ }
- /* Length of the Playlist (number of songs) */
- tmp.playlist_length = audacious_remote_get_playlist_length(session);
+ /* Length of the Playlist (number of songs) */
+ tmp.playlist_length = audacious_remote_get_playlist_length(session);
- /* Main volume */
- tmp.main_volume = audacious_remote_get_main_volume(session);
- } while (0);
- {
- /* Deliver the refreshed items array to audacious_items. */
- std::lock_guard lock(result_mutex);
- result = tmp;
- }
- }
-
- aud_result get_res()
- {
- uint32_t period = std::max(
- lround(music_player_interval.get(*state)/active_update_interval()), 1l
- );
- return conky::register_cb(period)->get_result_copy();
- }
+ /* Main volume */
+ tmp.main_volume = audacious_remote_get_main_volume(session);
+ } while (0);
+ {
+ /* Deliver the refreshed items array to audacious_items. */
+ std::lock_guard lock(result_mutex);
+ result = tmp;
+ }
}
-void print_audacious_status(struct text_object *, char *p, int p_max_size)
-{
- const aud_result &res = get_res();
- snprintf(p, p_max_size, "%s", as_message[res.status]);
+aud_result get_res() {
+ uint32_t period = std::max(
+ lround(music_player_interval.get(*state) / active_update_interval()), 1l);
+ return conky::register_cb(period)->get_result_copy();
+}
+} // namespace
+
+void print_audacious_status(struct text_object *, char *p, int p_max_size) {
+ const aud_result &res = get_res();
+ snprintf(p, p_max_size, "%s", as_message[res.status]);
}
-void print_audacious_title(struct text_object *obj, char *p, int p_max_size)
-{
- snprintf(p, std::min(obj->data.i, p_max_size), "%s", get_res().title.c_str());
+void print_audacious_title(struct text_object *obj, char *p, int p_max_size) {
+ snprintf(p, std::min(obj->data.i, p_max_size), "%s", get_res().title.c_str());
}
-void print_audacious_filename(struct text_object *obj, char *p, int p_max_size)
-{
- snprintf(p, std::min(obj->data.i, p_max_size), "%s", get_res().filename.c_str());
+void print_audacious_filename(struct text_object *obj, char *p,
+ int p_max_size) {
+ snprintf(p, std::min(obj->data.i, p_max_size), "%s",
+ get_res().filename.c_str());
}
-double audacious_barval(struct text_object *)
-{
- const aud_result &res = get_res();
- return (double)res.position / res.length;
+double audacious_barval(struct text_object *) {
+ const aud_result &res = get_res();
+ return (double)res.position / res.length;
}
-#define AUDACIOUS_TIME_GENERATOR(name) \
-void print_audacious_##name(struct text_object *, char *p, int p_max_size) \
-{ \
- const aud_result &res = get_res(); \
- int sec = res.name / 1000; \
- snprintf(p, p_max_size, "%d:%.2d", sec/60, sec%60); \
-} \
- \
-void print_audacious_##name##_seconds(struct text_object *, char *p, int p_max_size) \
-{ \
- snprintf(p, p_max_size, "%d", get_res().name); \
-}
+#define AUDACIOUS_TIME_GENERATOR(name) \
+ void print_audacious_##name(struct text_object *, char *p, int p_max_size) { \
+ const aud_result &res = get_res(); \
+ int sec = res.name / 1000; \
+ snprintf(p, p_max_size, "%d:%.2d", sec / 60, sec % 60); \
+ } \
+ \
+ void print_audacious_##name##_seconds(struct text_object *, char *p, \
+ int p_max_size) { \
+ snprintf(p, p_max_size, "%d", get_res().name); \
+ }
AUDACIOUS_TIME_GENERATOR(length)
AUDACIOUS_TIME_GENERATOR(position)
-#define AUDACIOUS_INT_GENERATOR(name, offset) \
-void print_audacious_##name(struct text_object *, char *p, int p_max_size) \
-{ \
- snprintf(p, p_max_size, "%d", get_res().name + offset); \
-}
+#define AUDACIOUS_INT_GENERATOR(name, offset) \
+ void print_audacious_##name(struct text_object *, char *p, int p_max_size) { \
+ snprintf(p, p_max_size, "%d", get_res().name + offset); \
+ }
AUDACIOUS_INT_GENERATOR(bitrate, 0)
AUDACIOUS_INT_GENERATOR(frequency, 0)
diff --git a/src/audacious.h b/src/audacious.h
index c66e9e04..e8e70412 100644
--- a/src/audacious.h
+++ b/src/audacious.h
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* audacious.h: conky support for audacious music player
*
diff --git a/src/bmpx.cc b/src/bmpx.cc
index cbe5b4e5..b23f3d81 100644
--- a/src/bmpx.cc
+++ b/src/bmpx.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -9,7 +8,7 @@
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -31,11 +30,11 @@
#include "conky.h"
#include "logging.h"
-#include
#include
+#include
#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
- (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
+ (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
static DBusGConnection *bus;
static DBusGProxy *remote_object;
@@ -44,105 +43,103 @@ static char *unknown = "unknown";
void fail(GError *error, struct information *);
-void update_bmpx()
-{
- GError *error = NULL;
- struct information *current_info = &info;
- gint current_track;
- GHashTable *metadata;
+void update_bmpx() {
+ GError *error = NULL;
+ struct information *current_info = &info;
+ gint current_track;
+ GHashTable *metadata;
- if (connected == 0) {
- g_type_init();
- dbus_g_type_specialized_init();
+ if (connected == 0) {
+ g_type_init();
+ dbus_g_type_specialized_init();
- bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (bus == NULL) {
- NORM_ERR("BMPx error 1: %s\n", error->message);
- fail(error, current_info);
- return;
- }
+ bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (bus == NULL) {
+ NORM_ERR("BMPx error 1: %s\n", error->message);
+ fail(error, current_info);
+ return;
+ }
- remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
- BMP_DBUS_PATH__BMP, BMP_DBUS_INTERFACE__BMP);
- if (!remote_object) {
- NORM_ERR("BMPx error 2: %s\n", error->message);
- fail(error, current_info);
- return;
- }
+ remote_object = dbus_g_proxy_new_for_name(
+ bus, BMP_DBUS_SERVICE, BMP_DBUS_PATH__BMP, BMP_DBUS_INTERFACE__BMP);
+ if (!remote_object) {
+ NORM_ERR("BMPx error 2: %s\n", error->message);
+ fail(error, current_info);
+ return;
+ }
- connected = 1;
- }
+ connected = 1;
+ }
- if (connected == 1) {
- if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
- G_TYPE_INVALID, G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
- } else {
- NORM_ERR("BMPx error 3: %s\n", error->message);
- fail(error, current_info);
- return;
- }
+ if (connected == 1) {
+ if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
+ G_TYPE_INVALID, G_TYPE_INT, ¤t_track,
+ G_TYPE_INVALID)) {
+ } else {
+ NORM_ERR("BMPx error 3: %s\n", error->message);
+ fail(error, current_info);
+ return;
+ }
- if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
- G_TYPE_INT, current_track, G_TYPE_INVALID,
- DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
- G_TYPE_INVALID)) {
- free_and_zero(current_info->bmpx.title);
- free_and_zero(current_info->bmpx.artist);
- free_and_zero(current_info->bmpx.album);
- current_info->bmpx.title =
- g_value_dup_string(g_hash_table_lookup(metadata, "title"));
- current_info->bmpx.artist =
- g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
- current_info->bmpx.album =
- g_value_dup_string(g_hash_table_lookup(metadata, "album"));
- current_info->bmpx.bitrate =
- g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
- current_info->bmpx.track =
- g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
- current_info->bmpx.uri =
- g_value_get_string(g_hash_table_lookup(metadata, "location"));
- } else {
- NORM_ERR("BMPx error 4: %s\n", error->message);
- fail(error, current_info);
- return;
- }
+ if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
+ G_TYPE_INT, current_track, G_TYPE_INVALID,
+ DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
+ G_TYPE_INVALID)) {
+ free_and_zero(current_info->bmpx.title);
+ free_and_zero(current_info->bmpx.artist);
+ free_and_zero(current_info->bmpx.album);
+ current_info->bmpx.title =
+ g_value_dup_string(g_hash_table_lookup(metadata, "title"));
+ current_info->bmpx.artist =
+ g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
+ current_info->bmpx.album =
+ g_value_dup_string(g_hash_table_lookup(metadata, "album"));
+ current_info->bmpx.bitrate =
+ g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
+ current_info->bmpx.track =
+ g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
+ current_info->bmpx.uri =
+ g_value_get_string(g_hash_table_lookup(metadata, "location"));
+ } else {
+ NORM_ERR("BMPx error 4: %s\n", error->message);
+ fail(error, current_info);
+ return;
+ }
- g_hash_table_destroy(metadata);
- } else {
- fail(error, current_info);
- }
+ g_hash_table_destroy(metadata);
+ } else {
+ fail(error, current_info);
+ }
}
-void fail(GError *error, struct information *current_info)
-{
- if (error) {
- g_error_free(error);
- }
- if (current_info->bmpx.title) {
- g_free(current_info->bmpx.title);
- current_info->bmpx.title = 0;
- }
- if (current_info->bmpx.artist) {
- g_free(current_info->bmpx.artist);
- current_info->bmpx.artist = 0;
- }
- if (current_info->bmpx.album) {
- g_free(current_info->bmpx.album);
- current_info->bmpx.album = 0;
- }
- current_info->bmpx.title = unknown;
- current_info->bmpx.artist = unknown;
- current_info->bmpx.album = unknown;
- current_info->bmpx.bitrate = 0;
- current_info->bmpx.track = 0;
+void fail(GError *error, struct information *current_info) {
+ if (error) {
+ g_error_free(error);
+ }
+ if (current_info->bmpx.title) {
+ g_free(current_info->bmpx.title);
+ current_info->bmpx.title = 0;
+ }
+ if (current_info->bmpx.artist) {
+ g_free(current_info->bmpx.artist);
+ current_info->bmpx.artist = 0;
+ }
+ if (current_info->bmpx.album) {
+ g_free(current_info->bmpx.album);
+ current_info->bmpx.album = 0;
+ }
+ current_info->bmpx.title = unknown;
+ current_info->bmpx.artist = unknown;
+ current_info->bmpx.album = unknown;
+ current_info->bmpx.bitrate = 0;
+ current_info->bmpx.track = 0;
}
-#define BMPX_PRINT_GENERATOR(name, fmt) \
-void print_bmpx_##name(struct text_object *obj, char *p, int p_max_size) \
-{ \
- (void)obj; \
- snprintf(p, p_max_size, fmt, info.bmpx.name); \
-}
+#define BMPX_PRINT_GENERATOR(name, fmt) \
+ void print_bmpx_##name(struct text_object *obj, char *p, int p_max_size) { \
+ (void)obj; \
+ snprintf(p, p_max_size, fmt, info.bmpx.name); \
+ }
BMPX_PRINT_GENERATOR(title, "%s")
BMPX_PRINT_GENERATOR(artist, "%s")
@@ -152,4 +149,3 @@ BMPX_PRINT_GENERATOR(track, "%i")
BMPX_PRINT_GENERATOR(bitrate, "%i")
#undef BMPX_PRINT_GENERATOR
-
diff --git a/src/bmpx.h b/src/bmpx.h
index 6891557b..b40b3011 100644
--- a/src/bmpx.h
+++ b/src/bmpx.h
@@ -1,11 +1,10 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=c
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -28,12 +27,12 @@
void update_bmpx(void);
struct bmpx_s {
- char *title;
- char *artist;
- char *album;
- char *uri;
- int bitrate;
- int track;
+ char *title;
+ char *artist;
+ char *album;
+ char *uri;
+ int bitrate;
+ int track;
};
void print_bmpx_title(struct text_object *, char *, int);
diff --git a/src/bsdapm.cc b/src/bsdapm.cc
index 357c4156..74dfee3f 100644
--- a/src/bsdapm.cc
+++ b/src/bsdapm.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -27,184 +26,178 @@
* along with this program. If not, see .
*
*/
+#include
+#include
+#include
+#include
#include "config.h"
#include "conky.h"
#include "text_object.h"
-#include
-#include
-#include
-#include
-#define APMDEV "/dev/apm"
-#define APM_UNKNOWN 255
+#define APMDEV "/dev/apm"
+#define APM_UNKNOWN 255
#ifndef APM_AC_OFF
-# define APM_AC_OFF 0
+#define APM_AC_OFF 0
#endif
#ifndef APM_AC_ON
-# define APM_AC_ON 1
+#define APM_AC_ON 1
#endif
#ifndef APM_BATT_CHARGING
-# define APM_BATT_CHARGING 3
+#define APM_BATT_CHARGING 3
#endif
-static int apm_getinfo(int fd, apm_info_t aip)
-{
+static int apm_getinfo(int fd, apm_info_t aip) {
#ifdef __OpenBSD__
- if (ioctl(fd, APM_IOC_GETPOWER, aip) == -1) {
+ if (ioctl(fd, APM_IOC_GETPOWER, aip) == -1) {
#else
- if (ioctl(fd, APMIO_GETINFO, aip) == -1) {
+ if (ioctl(fd, APMIO_GETINFO, aip) == -1) {
#endif
- return -1;
- }
+ return -1;
+ }
- return 0;
+ return 0;
}
-void print_apm_adapter(struct text_object *obj, char *p, int p_max_size)
-{
- int fd;
- const char *out;
+void print_apm_adapter(struct text_object *obj, char *p, int p_max_size) {
+ int fd;
+ const char *out;
#ifdef __OpenBSD__
- struct apm_power_info a_info;
+ struct apm_power_info a_info;
#else
- struct apm_info a_info;
+ struct apm_info a_info;
#endif
- (void)obj;
+ (void)obj;
- fd = open(APMDEV, O_RDONLY);
- if (fd < 0) {
- snprintf(p, p_max_size, "ERR");
- return;
- }
+ fd = open(APMDEV, O_RDONLY);
+ if (fd < 0) {
+ snprintf(p, p_max_size, "ERR");
+ return;
+ }
- if (apm_getinfo(fd, &a_info) != 0) {
- close(fd);
- snprintf(p, p_max_size, "ERR");
- return;
- }
- close(fd);
+ if (apm_getinfo(fd, &a_info) != 0) {
+ close(fd);
+ snprintf(p, p_max_size, "ERR");
+ return;
+ }
+ close(fd);
#ifdef __OpenBSD__
-# define ai_acline ac_state
+#define ai_acline ac_state
#endif
- switch (a_info.ai_acline) {
- case APM_AC_OFF:
- out = "off-line";
- break;
- case APM_AC_ON:
+ switch (a_info.ai_acline) {
+ case APM_AC_OFF:
+ out = "off-line";
+ break;
+ case APM_AC_ON:
#ifdef __OpenBSD__
-# define ai_batt_stat battery_state
+#define ai_batt_stat battery_state
#endif
- if (a_info.ai_batt_stat
- == APM_BATT_CHARGING) {
- out = "charging";
- } else {
- out = "on-line";
- }
- break;
- default:
- out = "unknown";
- break;
- }
- snprintf(p, p_max_size, "%s", out);
+ if (a_info.ai_batt_stat == APM_BATT_CHARGING) {
+ out = "charging";
+ } else {
+ out = "on-line";
+ }
+ break;
+ default:
+ out = "unknown";
+ break;
+ }
+ snprintf(p, p_max_size, "%s", out);
}
-void print_apm_battery_life(struct text_object *obj, char *p, int p_max_size)
-{
- int fd;
- u_int batt_life;
- const char *out;
+void print_apm_battery_life(struct text_object *obj, char *p, int p_max_size) {
+ int fd;
+ u_int batt_life;
+ const char *out;
#ifdef __OpenBSD__
- struct apm_power_info a_info;
+ struct apm_power_info a_info;
#else
- struct apm_info a_info;
+ struct apm_info a_info;
#endif
- (void)obj;
+ (void)obj;
- fd = open(APMDEV, O_RDONLY);
- if (fd < 0) {
- snprintf(p, p_max_size, "ERR");
- return;
- }
+ fd = open(APMDEV, O_RDONLY);
+ if (fd < 0) {
+ snprintf(p, p_max_size, "ERR");
+ return;
+ }
- if (apm_getinfo(fd, &a_info) != 0) {
- close(fd);
- snprintf(p, p_max_size, "ERR");
- return;
- }
- close(fd);
+ if (apm_getinfo(fd, &a_info) != 0) {
+ close(fd);
+ snprintf(p, p_max_size, "ERR");
+ return;
+ }
+ close(fd);
#ifdef __OpenBSD__
-# define ai_batt_life battery_life
+#define ai_batt_life battery_life
#endif
- batt_life = a_info.ai_batt_life;
- if (batt_life == APM_UNKNOWN) {
- out = "unknown";
- } else if (batt_life <= 100) {
- snprintf(p, p_max_size, "%d%%", batt_life);
- return;
- } else {
- out = "ERR";
- }
+ batt_life = a_info.ai_batt_life;
+ if (batt_life == APM_UNKNOWN) {
+ out = "unknown";
+ } else if (batt_life <= 100) {
+ snprintf(p, p_max_size, "%d%%", batt_life);
+ return;
+ } else {
+ out = "ERR";
+ }
- snprintf(p, p_max_size, "%s", out);
+ snprintf(p, p_max_size, "%s", out);
}
-void print_apm_battery_time(struct text_object *obj, char *p, int p_max_size)
-{
- int fd;
- int batt_time;
+void print_apm_battery_time(struct text_object *obj, char *p, int p_max_size) {
+ int fd;
+ int batt_time;
#ifdef __OpenBSD__
- int h, m;
- struct apm_power_info a_info;
+ int h, m;
+ struct apm_power_info a_info;
#else
- int h, m, s;
- struct apm_info a_info;
+ int h, m, s;
+ struct apm_info a_info;
#endif
- (void)obj;
+ (void)obj;
- fd = open(APMDEV, O_RDONLY);
- if (fd < 0) {
- snprintf(p, p_max_size, "ERR");
- return;
- }
+ fd = open(APMDEV, O_RDONLY);
+ if (fd < 0) {
+ snprintf(p, p_max_size, "ERR");
+ return;
+ }
- if (apm_getinfo(fd, &a_info) != 0) {
- close(fd);
- snprintf(p, p_max_size, "ERR");
- return;
- }
- close(fd);
+ if (apm_getinfo(fd, &a_info) != 0) {
+ close(fd);
+ snprintf(p, p_max_size, "ERR");
+ return;
+ }
+ close(fd);
#ifdef __OpenBSD__
-# define ai_batt_time minutes_left
+#define ai_batt_time minutes_left
#endif
- batt_time = a_info.ai_batt_time;
-
- if (batt_time == -1) {
- snprintf(p, p_max_size, "unknown");
- } else
+ batt_time = a_info.ai_batt_time;
+ if (batt_time == -1) {
+ snprintf(p, p_max_size, "unknown");
+ } else
#ifdef __OpenBSD__
- {
- h = batt_time / 60;
- m = batt_time % 60;
- snprintf(p, p_max_size, "%2d:%02d", h, m);
- }
+ {
+ h = batt_time / 60;
+ m = batt_time % 60;
+ snprintf(p, p_max_size, "%2d:%02d", h, m);
+ }
#else
- {
- h = batt_time;
- s = h % 60;
- h /= 60;
- m = h % 60;
- h /= 60;
- snprintf(p, p_max_size, "%2d:%02d:%02d", h, m, s);
- }
+ {
+ h = batt_time;
+ s = h % 60;
+ h /= 60;
+ m = h % 60;
+ h /= 60;
+ snprintf(p, p_max_size, "%2d:%02d:%02d", h, m, s);
+ }
#endif
}
diff --git a/src/bsdapm.h b/src/bsdapm.h
index 3dac2ddb..59061d87 100644
--- a/src/bsdapm.h
+++ b/src/bsdapm.h
@@ -1,5 +1,4 @@
-/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=c
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
diff --git a/src/c++wrap.cc b/src/c++wrap.cc
index fcb2713f..14f9788e 100644
--- a/src/c++wrap.cc
+++ b/src/c++wrap.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -25,8 +24,8 @@
#include "c++wrap.hh"
-#include
#include
+#include
/* force use of POSIX strerror_r instead of non-portable GNU specific */
#ifdef _GNU_SOURCE
@@ -42,47 +41,41 @@
#include
namespace {
- int pipe2_emulate(int pipefd[2], int flags)
- {
- if(pipe(pipefd) == -1)
- return -1;
+int pipe2_emulate(int pipefd[2], int flags) {
+ if (pipe(pipefd) == -1) return -1;
- if(flags & O_CLOEXEC) {
- // we emulate O_CLOEXEC if the system does not have it
- // not very thread-safe, but at least it works
+ if (flags & O_CLOEXEC) {
+ // we emulate O_CLOEXEC if the system does not have it
+ // not very thread-safe, but at least it works
- for(int i = 0; i < 2; ++i) {
- int r = fcntl(pipefd[i], F_GETFD);
- if(r == -1)
- return -1;
+ for (int i = 0; i < 2; ++i) {
+ int r = fcntl(pipefd[i], F_GETFD);
+ if (r == -1) return -1;
- if(fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1)
- return -1;
- }
- }
+ if (fcntl(pipefd[i], F_SETFD, r | FD_CLOEXEC) == -1) return -1;
+ }
+ }
- return 0;
- }
-
- int (* const pipe2_ptr)(int[2], int) = &pipe2_emulate;
+ return 0;
}
+
+int (*const pipe2_ptr)(int[2], int) = &pipe2_emulate;
+} // namespace
#else
- int (* const pipe2_ptr)(int[2], int) = &pipe2;
+int (*const pipe2_ptr)(int[2], int) = &pipe2;
#endif
-std::string strerror_r(int errnum)
-{
- static thread_local char buf[100];
- if (strerror_r(errnum, buf, sizeof buf) != 0)
- snprintf(buf, sizeof buf, "Unknown error %i", errnum);
- return buf;
+std::string strerror_r(int errnum) {
+ static thread_local char buf[100];
+ if (strerror_r(errnum, buf, sizeof buf) != 0)
+ snprintf(buf, sizeof buf, "Unknown error %i", errnum);
+ return buf;
}
-std::pair pipe2(int flags)
-{
- int fd[2];
- if(pipe2_ptr(fd, flags) == -1)
- throw errno_error("pipe2");
- else
- return std::pair(fd[0], fd[1]);
+std::pair pipe2(int flags) {
+ int fd[2];
+ if (pipe2_ptr(fd, flags) == -1)
+ throw errno_error("pipe2");
+ else
+ return std::pair(fd[0], fd[1]);
}
diff --git a/src/c++wrap.hh b/src/c++wrap.hh
index fc4c9e76..69abca82 100644
--- a/src/c++wrap.hh
+++ b/src/c++wrap.hh
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -38,15 +37,14 @@ enum { O_CLOEXEC = 02000000 };
std::string strerror_r(int errnum);
std::pair pipe2(int flags);
-class errno_error: public std::runtime_error {
- typedef std::runtime_error Base;
+class errno_error : public std::runtime_error {
+ typedef std::runtime_error Base;
-public:
- errno_error(const std::string &prefix, int err_ = errno)
- : Base(prefix + ": " + strerror_r(err_)), err(err_)
- {}
+ public:
+ errno_error(const std::string &prefix, int err_ = errno)
+ : Base(prefix + ": " + strerror_r(err_)), err(err_) {}
- const int err;
+ const int err;
};
#endif /* CPPWRAP_HH */
diff --git a/src/ccurl_thread.cc b/src/ccurl_thread.cc
index 02cee57b..8c771568 100644
--- a/src/ccurl_thread.cc
+++ b/src/ccurl_thread.cc
@@ -1,11 +1,10 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -23,12 +22,12 @@
*
*/
-#include "conky.h"
-#include "logging.h"
#include "ccurl_thread.h"
-#include "text_object.h"
#include
#include
+#include "conky.h"
+#include "logging.h"
+#include "text_object.h"
#ifdef DEBUG
#include
@@ -44,178 +43,169 @@
*/
namespace priv {
- /* callback used by curl for parsing the header data */
- size_t curl_internal::parse_header_cb(void *ptr, size_t size, size_t nmemb, void *data)
- {
- curl_internal *obj = static_cast(data);
- const char *value = static_cast(ptr);
- size_t realsize = size * nmemb;
+/* callback used by curl for parsing the header data */
+size_t curl_internal::parse_header_cb(void *ptr, size_t size, size_t nmemb,
+ void *data) {
+ curl_internal *obj = static_cast(data);
+ const char *value = static_cast(ptr);
+ size_t realsize = size * nmemb;
- if(realsize > 0 && (value[realsize-1] == '\r' || value[realsize-1] == 0))
- --realsize;
+ if (realsize > 0 && (value[realsize - 1] == '\r' || value[realsize - 1] == 0))
+ --realsize;
- if (strncmp(value, "Last-Modified: ", 15) == EQUAL) {
- obj->last_modified = std::string(value + 15, realsize - 15);
- } else if (strncmp(value,"ETag: ", 6) == EQUAL) {
- obj->etag = std::string(value + 6, realsize - 6);
- }
+ if (strncmp(value, "Last-Modified: ", 15) == EQUAL) {
+ obj->last_modified = std::string(value + 15, realsize - 15);
+ } else if (strncmp(value, "ETag: ", 6) == EQUAL) {
+ obj->etag = std::string(value + 6, realsize - 6);
+ }
- return size*nmemb;
- }
-
- /* callback used by curl for writing the received data */
- size_t curl_internal::write_cb(void *ptr, size_t size, size_t nmemb, void *data)
- {
- curl_internal *obj = static_cast(data);
- const char *value = static_cast(ptr);
- size_t realsize = size * nmemb;
-
- obj->data += std::string(value, realsize);
-
- return realsize;
- }
-
- curl_internal::curl_internal(const std::string &url)
- : curl(curl_easy_init())
- {
- if(not curl)
- throw std::runtime_error("curl_easy_init() failed");
-
- curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
- curl_easy_setopt(curl, CURLOPT_HEADERDATA, this);
- curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, parse_header_cb);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.1");
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
- curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1000);
- curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60);
-
- // curl's usage of alarm()+longjmp() is a really bad idea for multi-threaded applications
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-
- }
-
-
- /* fetch our datums */
- void curl_internal::do_work()
- {
- CURLcode res;
- struct headers_ {
- struct curl_slist *h;
-
- headers_() : h(NULL) {}
- ~headers_() { curl_slist_free_all(h); }
- } headers;
-
- data.clear();
-
- if (not last_modified.empty()) {
- headers.h = curl_slist_append(headers.h, ("If-Modified-Since: " + last_modified).c_str());
- last_modified.clear();
- }
- if (not etag.empty()) {
- headers.h = curl_slist_append(headers.h, ("If-None-Match: " + etag).c_str());
- etag.clear();
- }
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.h);
-
- res = curl_easy_perform(curl);
- if (res == CURLE_OK) {
- long http_status_code;
-
- if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK) {
- switch (http_status_code) {
- case 200:
- process_data();
- break;
- case 304:
- break;
- default:
- NORM_ERR("curl: no data from server, got HTTP status %ld",
- http_status_code);
- break;
- }
- } else {
- NORM_ERR("curl: no HTTP status from server");
- }
- } else {
- NORM_ERR("curl: could not retrieve data from server");
- }
- }
+ return size * nmemb;
}
+/* callback used by curl for writing the received data */
+size_t curl_internal::write_cb(void *ptr, size_t size, size_t nmemb,
+ void *data) {
+ curl_internal *obj = static_cast(data);
+ const char *value = static_cast(ptr);
+ size_t realsize = size * nmemb;
+
+ obj->data += std::string(value, realsize);
+
+ return realsize;
+}
+
+curl_internal::curl_internal(const std::string &url) : curl(curl_easy_init()) {
+ if (not curl) throw std::runtime_error("curl_easy_init() failed");
+
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
+ curl_easy_setopt(curl, CURLOPT_HEADERDATA, this);
+ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, parse_header_cb);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
+ curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.1");
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1000);
+ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60);
+
+ // curl's usage of alarm()+longjmp() is a really bad idea for multi-threaded
+ // applications
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+}
+
+/* fetch our datums */
+void curl_internal::do_work() {
+ CURLcode res;
+ struct headers_ {
+ struct curl_slist *h;
+
+ headers_() : h(NULL) {}
+ ~headers_() { curl_slist_free_all(h); }
+ } headers;
+
+ data.clear();
+
+ if (not last_modified.empty()) {
+ headers.h = curl_slist_append(
+ headers.h, ("If-Modified-Since: " + last_modified).c_str());
+ last_modified.clear();
+ }
+ if (not etag.empty()) {
+ headers.h =
+ curl_slist_append(headers.h, ("If-None-Match: " + etag).c_str());
+ etag.clear();
+ }
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.h);
+
+ res = curl_easy_perform(curl);
+ if (res == CURLE_OK) {
+ long http_status_code;
+
+ if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) ==
+ CURLE_OK) {
+ switch (http_status_code) {
+ case 200:
+ process_data();
+ break;
+ case 304:
+ break;
+ default:
+ NORM_ERR("curl: no data from server, got HTTP status %ld",
+ http_status_code);
+ break;
+ }
+ } else {
+ NORM_ERR("curl: no HTTP status from server");
+ }
+ } else {
+ NORM_ERR("curl: could not retrieve data from server");
+ }
+}
+} // namespace priv
+
namespace {
- class simple_curl_cb: public curl_callback {
- typedef curl_callback Base;
+class simple_curl_cb : public curl_callback {
+ typedef curl_callback Base;
- protected:
- virtual void process_data()
- {
- std::lock_guard lock(result_mutex);
- result = data;
- }
-
- public:
- simple_curl_cb(uint32_t period, const std::string &uri)
- : Base(period, Tuple(uri))
- {}
- };
-}
+ protected:
+ virtual void process_data() {
+ std::lock_guard lock(result_mutex);
+ result = data;
+ }
+
+ public:
+ simple_curl_cb(uint32_t period, const std::string &uri)
+ : Base(period, Tuple(uri)) {}
+};
+} // namespace
/*
* This is where the $curl section begins.
*/
struct curl_data {
- char uri[128];
- float interval;
+ char uri[128];
+ float interval;
};
/* prints result data to text buffer, used by $curl */
-void ccurl_process_info(char *p, int p_max_size, const std::string &uri, int interval)
-{
- uint32_t period = std::max(lround(interval/active_update_interval()), 1l);
- auto cb = conky::register_cb(period, uri);
+void ccurl_process_info(char *p, int p_max_size, const std::string &uri,
+ int interval) {
+ uint32_t period = std::max(lround(interval / active_update_interval()), 1l);
+ auto cb = conky::register_cb(period, uri);
- strncpy(p, cb->get_result_copy().c_str(), p_max_size);
+ strncpy(p, cb->get_result_copy().c_str(), p_max_size);
}
-void curl_parse_arg(struct text_object *obj, const char *arg)
-{
- int argc;
- struct curl_data *cd;
- float interval = 0;
+void curl_parse_arg(struct text_object *obj, const char *arg) {
+ int argc;
+ struct curl_data *cd;
+ float interval = 0;
- cd = (struct curl_data*)malloc(sizeof(struct curl_data));
- memset(cd, 0, sizeof(struct curl_data));
+ cd = (struct curl_data *)malloc(sizeof(struct curl_data));
+ memset(cd, 0, sizeof(struct curl_data));
- argc = sscanf(arg, "%127s %f", cd->uri, &interval);
- if (argc < 1) {
- free(cd);
- NORM_ERR("wrong number of arguments for $curl");
- return;
- }
- if (argc == 1)
- cd->interval = 15*60;
- else
- cd->interval = interval > 0 ? interval * 60 : active_update_interval();
- obj->data.opaque = cd;
+ argc = sscanf(arg, "%127s %f", cd->uri, &interval);
+ if (argc < 1) {
+ free(cd);
+ NORM_ERR("wrong number of arguments for $curl");
+ return;
+ }
+ if (argc == 1)
+ cd->interval = 15 * 60;
+ else
+ cd->interval = interval > 0 ? interval * 60 : active_update_interval();
+ obj->data.opaque = cd;
}
-void curl_print(struct text_object *obj, char *p, int p_max_size)
-{
- struct curl_data *cd = (struct curl_data *)obj->data.opaque;
+void curl_print(struct text_object *obj, char *p, int p_max_size) {
+ struct curl_data *cd = (struct curl_data *)obj->data.opaque;
- if (!cd || !cd->uri) {
- NORM_ERR("error processing Curl data");
- return;
- }
- ccurl_process_info(p, p_max_size, cd->uri, cd->interval);
+ if (!cd || !cd->uri) {
+ NORM_ERR("error processing Curl data");
+ return;
+ }
+ ccurl_process_info(p, p_max_size, cd->uri, cd->interval);
}
-void curl_obj_free(struct text_object *obj)
-{
- free_and_zero(obj->data.opaque);
-}
+void curl_obj_free(struct text_object *obj) { free_and_zero(obj->data.opaque); }
diff --git a/src/ccurl_thread.h b/src/ccurl_thread.h
index 5520168b..f7827717 100644
--- a/src/ccurl_thread.h
+++ b/src/ccurl_thread.h
@@ -1,11 +1,10 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -31,55 +30,56 @@
#include "update-cb.hh"
namespace priv {
- // factored out stuff that does not depend on the template parameters
- struct curl_internal {
- std::string last_modified;
- std::string etag;
- std::string data;
- CURL *curl;
+// factored out stuff that does not depend on the template parameters
+struct curl_internal {
+ std::string last_modified;
+ std::string etag;
+ std::string data;
+ CURL *curl;
- static size_t parse_header_cb(void *ptr, size_t size, size_t nmemb, void *data);
- static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data);
+ static size_t parse_header_cb(void *ptr, size_t size, size_t nmemb,
+ void *data);
+ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data);
- void do_work();
+ void do_work();
- // called by do_work() after downloading data from the uri
- // it should populate the result variable
- virtual void process_data() = 0;
+ // called by do_work() after downloading data from the uri
+ // it should populate the result variable
+ virtual void process_data() = 0;
- curl_internal(const std::string &url);
- virtual ~curl_internal() { if(curl) curl_easy_cleanup(curl); }
- };
-}
+ curl_internal(const std::string &url);
+ virtual ~curl_internal() {
+ if (curl) curl_easy_cleanup(curl);
+ }
+};
+} // namespace priv
/*
* Curl callback class template
* the key is an url
*/
-template
-class curl_callback: public conky::callback,
- protected priv::curl_internal {
- typedef conky::callback Base1;
- typedef priv::curl_internal Base2;
+template
+class curl_callback : public conky::callback,
+ protected priv::curl_internal {
+ typedef conky::callback Base1;
+ typedef priv::curl_internal Base2;
-protected:
- virtual void work()
- {
- DBGP("reading curl data from '%s'", std::get<0>(Base1::tuple).c_str());
- do_work();
- }
+ protected:
+ virtual void work() {
+ DBGP("reading curl data from '%s'", std::get<0>(Base1::tuple).c_str());
+ do_work();
+ }
-public:
- curl_callback(uint32_t period, const typename Base1::Tuple &tuple)
- : Base1(period, false, tuple), Base2(std::get<0>(tuple))
- {}
+ public:
+ curl_callback(uint32_t period, const typename Base1::Tuple &tuple)
+ : Base1(period, false, tuple), Base2(std::get<0>(tuple)) {}
};
-
/* $curl exports begin */
/* runs instance of $curl */
-void ccurl_process_info(char *p, int p_max_size, const std::string &uri, int interval);
+void ccurl_process_info(char *p, int p_max_size, const std::string &uri,
+ int interval);
void curl_parse_arg(struct text_object *, const char *);
void curl_print(struct text_object *, char *, int);
@@ -88,4 +88,3 @@ void curl_obj_free(struct text_object *);
/* $curl exports end */
#endif /* _CURL_THREAD_H_ */
-
diff --git a/src/cmus.cc b/src/cmus.cc
index 547efff9..4b6bb849 100644
--- a/src/cmus.cc
+++ b/src/cmus.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* CMUS Conky integration
*
@@ -25,134 +24,129 @@
#include "logging.h"
#include "text_object.h"
+#include
#include
#include
#include
#include
#include
-#include
#include "update-cb.hh"
namespace {
- struct cmus_result {
- std::string state;
- std::string file;
- std::string title;
- std::string artist;
- std::string album;
- std::string totaltime;
- std::string curtime;
- std::string random;
- std::string repeat;
- std::string aaa;
- std::string track;
- std::string genre;
- std::string date;
- float progress;
- float timeleft;
- };
+struct cmus_result {
+ std::string state;
+ std::string file;
+ std::string title;
+ std::string artist;
+ std::string album;
+ std::string totaltime;
+ std::string curtime;
+ std::string random;
+ std::string repeat;
+ std::string aaa;
+ std::string track;
+ std::string genre;
+ std::string date;
+ float progress;
+ float timeleft;
+};
- class cmus_cb: public conky::callback {
- typedef conky::callback Base;
+class cmus_cb : public conky::callback {
+ typedef conky::callback Base;
- protected:
- virtual void work();
+ protected:
+ virtual void work();
- public:
- cmus_cb(uint32_t period)
- : Base(period, false, Tuple())
- {}
- };
+ public:
+ cmus_cb(uint32_t period) : Base(period, false, Tuple()) {}
+};
- void cmus_cb::work()
- {
- cmus_result cmus;
- FILE *fp;
+void cmus_cb::work() {
+ cmus_result cmus;
+ FILE *fp;
- fp = popen("cmus-remote -Q 2>/dev/null", "r");
- if (!fp) {
- cmus.state = "Can't run 'cmus-remote -Q'";
- } else {
- while (1) {
- char line[255];
- char *p;
+ fp = popen("cmus-remote -Q 2>/dev/null", "r");
+ if (!fp) {
+ cmus.state = "Can't run 'cmus-remote -Q'";
+ } else {
+ while (1) {
+ char line[255];
+ char *p;
- /* Read a line from the pipe and strip the possible '\n'. */
- if (!fgets(line, 255, fp))
- break;
- if ((p = strrchr(line, '\n')))
- *p = '\0';
+ /* Read a line from the pipe and strip the possible '\n'. */
+ if (!fgets(line, 255, fp)) break;
+ if ((p = strrchr(line, '\n'))) *p = '\0';
- /* Parse infos. */
- if (strncmp(line, "status ", 7) == 0)
- cmus.state = line + 7;
+ /* Parse infos. */
+ if (strncmp(line, "status ", 7) == 0)
+ cmus.state = line + 7;
- else if (strncmp(line, "file ", 5) == 0)
- cmus.file = line + 5;
+ else if (strncmp(line, "file ", 5) == 0)
+ cmus.file = line + 5;
- else if (strncmp(line, "tag artist ", 11) == 0)
- cmus.artist = line + 11;
+ else if (strncmp(line, "tag artist ", 11) == 0)
+ cmus.artist = line + 11;
- else if (strncmp(line, "tag title ", 10) == 0)
- cmus.title = line + 10;
+ else if (strncmp(line, "tag title ", 10) == 0)
+ cmus.title = line + 10;
- else if (strncmp(line, "tag album ", 10) == 0)
- cmus.album = line + 10;
+ else if (strncmp(line, "tag album ", 10) == 0)
+ cmus.album = line + 10;
- else if (strncmp(line, "duration ", 9) == 0)
- cmus.totaltime = line + 9;
+ else if (strncmp(line, "duration ", 9) == 0)
+ cmus.totaltime = line + 9;
- else if (strncmp(line, "position ", 9) == 0)
- {
- cmus.curtime = line + 9;
- cmus.timeleft = atoi(cmus.totaltime.c_str()) - atoi(cmus.curtime.c_str());
- if (cmus.curtime.size() > 0)
- cmus.progress = (float) atoi(cmus.curtime.c_str()) / atoi(cmus.totaltime.c_str());
- else
- cmus.progress = 0;
- }
+ else if (strncmp(line, "position ", 9) == 0) {
+ cmus.curtime = line + 9;
+ cmus.timeleft =
+ atoi(cmus.totaltime.c_str()) - atoi(cmus.curtime.c_str());
+ if (cmus.curtime.size() > 0)
+ cmus.progress =
+ (float)atoi(cmus.curtime.c_str()) / atoi(cmus.totaltime.c_str());
+ else
+ cmus.progress = 0;
+ }
- else if (strncmp(line, "set shuffle ", 12) == 0)
- cmus.random = (strncmp(line+12, "true", 4) == 0 ?
- "on" : "off" );
+ else if (strncmp(line, "set shuffle ", 12) == 0)
+ cmus.random = (strncmp(line + 12, "true", 4) == 0 ? "on" : "off");
- else if (strncmp(line, "set repeat ", 11) == 0)
- cmus.repeat = (strncmp((line+11), "true", 4) == 0 ?
- "all" : "off" );
+ else if (strncmp(line, "set repeat ", 11) == 0)
+ cmus.repeat = (strncmp((line + 11), "true", 4) == 0 ? "all" : "off");
- else if (strncmp(line, "set repeat_current ", 19) == 0)
- cmus.repeat = (strncmp((line + 19), "true", 4) == 0 ?
- "song" : cmus.repeat );
- else if (strncmp(line, "set aaa_mode ", 13) == 0)
- cmus.aaa = line + 13;
+ else if (strncmp(line, "set repeat_current ", 19) == 0)
+ cmus.repeat =
+ (strncmp((line + 19), "true", 4) == 0 ? "song" : cmus.repeat);
+ else if (strncmp(line, "set aaa_mode ", 13) == 0)
+ cmus.aaa = line + 13;
- else if (strncmp(line, "tag tracknumber ", 16) == 0)
- cmus.track = line + 16;
- else if (strncmp(line, "tag genre ", 10) == 0)
- cmus.genre = line + 10;
- else if (strncmp(line, "tag date ", 9) == 0)
- cmus.date = line + 9;
- }
- }
+ else if (strncmp(line, "tag tracknumber ", 16) == 0)
+ cmus.track = line + 16;
+ else if (strncmp(line, "tag genre ", 10) == 0)
+ cmus.genre = line + 10;
+ else if (strncmp(line, "tag date ", 9) == 0)
+ cmus.date = line + 9;
+ }
+ }
- pclose(fp);
+ pclose(fp);
- std::lock_guard l(result_mutex);
- result = cmus;
- }
+ std::lock_guard l(result_mutex);
+ result = cmus;
}
+} // namespace
-#define CMUS_PRINT_GENERATOR(type, alt) \
-void print_cmus_##type(struct text_object *obj, char *p, int p_max_size) \
-{ \
- (void)obj; \
- uint32_t period = std::max( \
- lround(music_player_interval.get(*state)/active_update_interval()), 1l \
- ); \
- const cmus_result &cmus = conky::register_cb(period)->get_result_copy(); \
- snprintf(p, p_max_size, "%s", (cmus.type.length() ? cmus.type.c_str() : alt)); \
-}
+#define CMUS_PRINT_GENERATOR(type, alt) \
+ void print_cmus_##type(struct text_object *obj, char *p, int p_max_size) { \
+ (void)obj; \
+ uint32_t period = std::max( \
+ lround(music_player_interval.get(*state) / active_update_interval()), \
+ 1l); \
+ const cmus_result &cmus = \
+ conky::register_cb(period)->get_result_copy(); \
+ snprintf(p, p_max_size, "%s", \
+ (cmus.type.length() ? cmus.type.c_str() : alt)); \
+ }
CMUS_PRINT_GENERATOR(state, "Off")
CMUS_PRINT_GENERATOR(file, "no file")
@@ -166,50 +160,50 @@ CMUS_PRINT_GENERATOR(track, "no track")
CMUS_PRINT_GENERATOR(genre, "")
CMUS_PRINT_GENERATOR(date, "")
-uint8_t cmus_percent(struct text_object *obj)
-{
- (void)obj;
- uint32_t period = std::max(
- lround(music_player_interval.get(*state)/active_update_interval()), 1l);
- const cmus_result &cmus = conky::register_cb(period)->get_result_copy();
- return (uint8_t) round(cmus.progress * 100.0f);
+uint8_t cmus_percent(struct text_object *obj) {
+ (void)obj;
+ uint32_t period = std::max(
+ lround(music_player_interval.get(*state) / active_update_interval()), 1l);
+ const cmus_result &cmus =
+ conky::register_cb(period)->get_result_copy();
+ return (uint8_t)round(cmus.progress * 100.0f);
}
-double cmus_progress(struct text_object *obj)
-{
- (void)obj;
- uint32_t period = std::max(
- lround(music_player_interval.get(*state)/active_update_interval()), 1l);
- const cmus_result &cmus = conky::register_cb(period)->get_result_copy();
- return (double) cmus.progress;
+double cmus_progress(struct text_object *obj) {
+ (void)obj;
+ uint32_t period = std::max(
+ lround(music_player_interval.get(*state) / active_update_interval()), 1l);
+ const cmus_result &cmus =
+ conky::register_cb(period)->get_result_copy();
+ return (double)cmus.progress;
}
-void print_cmus_totaltime(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- uint32_t period = std::max(
- lround(music_player_interval.get(*state)/active_update_interval()), 1l);
- const cmus_result &cmus = conky::register_cb(period)->get_result_copy();
- format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str()));
+void print_cmus_totaltime(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ uint32_t period = std::max(
+ lround(music_player_interval.get(*state) / active_update_interval()), 1l);
+ const cmus_result &cmus =
+ conky::register_cb(period)->get_result_copy();
+ format_seconds_short(p, p_max_size, atol(cmus.totaltime.c_str()));
}
-void print_cmus_timeleft(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- uint32_t period = std::max(
- lround(music_player_interval.get(*state)/active_update_interval()), 1l);
- const cmus_result &cmus = conky::register_cb(period)->get_result_copy();
- //format_seconds_short(p, p_max_size, atol(cmus.timeleft.c_str()));
- format_seconds_short(p, p_max_size, (long)cmus.timeleft);
+void print_cmus_timeleft(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ uint32_t period = std::max(
+ lround(music_player_interval.get(*state) / active_update_interval()), 1l);
+ const cmus_result &cmus =
+ conky::register_cb(period)->get_result_copy();
+ // format_seconds_short(p, p_max_size, atol(cmus.timeleft.c_str()));
+ format_seconds_short(p, p_max_size, (long)cmus.timeleft);
}
-void print_cmus_curtime(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- uint32_t period = std::max(
- lround(music_player_interval.get(*state)/active_update_interval()), 1l);
- const cmus_result &cmus = conky::register_cb(period)->get_result_copy();
- format_seconds_short(p, p_max_size, atol(cmus.curtime.c_str()));
+void print_cmus_curtime(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ uint32_t period = std::max(
+ lround(music_player_interval.get(*state) / active_update_interval()), 1l);
+ const cmus_result &cmus =
+ conky::register_cb(period)->get_result_copy();
+ format_seconds_short(p, p_max_size, atol(cmus.curtime.c_str()));
}
#undef CMUS_PRINT_GENERATOR
diff --git a/src/cmus.h b/src/cmus.h
index 7c518f99..5dfa0470 100644
--- a/src/cmus.h
+++ b/src/cmus.h
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* CMUS Conky integration
*
@@ -43,4 +42,3 @@ double cmus_progress(struct text_object *obj);
uint8_t cmus_percent(struct text_object *obj);
#endif /* CMUS_H_ */
-
diff --git a/src/colours.cc b/src/colours.cc
index 7fcab034..a8fa4e22 100644
--- a/src/colours.cc
+++ b/src/colours.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -40,156 +39,156 @@
static short colour_depth = 0;
static long redmask, greenmask, bluemask;
-static void set_up_gradient(void)
-{
- int i;
+static void set_up_gradient(void) {
+ int i;
#ifdef BUILD_X11
- if (out_to_x.get(*state)) {
- colour_depth = DisplayPlanes(display, screen);
- } else
+ if (out_to_x.get(*state)) {
+ colour_depth = DisplayPlanes(display, screen);
+ } else
#endif /* BUILD_X11 */
- {
- colour_depth = 16;
- }
- if (colour_depth != 24 && colour_depth != 16) {
- NORM_ERR("using non-standard colour depth, gradients may look like a "
- "lolly-pop");
- }
+ {
+ colour_depth = 16;
+ }
+ if (colour_depth != 24 && colour_depth != 16) {
+ NORM_ERR(
+ "using non-standard colour depth, gradients may look like a "
+ "lolly-pop");
+ }
- redmask = 0;
- greenmask = 0;
- bluemask = 0;
- for (i = (colour_depth / 3) - 1; i >= 0; i--) {
- redmask |= 1 << i;
- greenmask |= 1 << i;
- bluemask |= 1 << i;
- }
- if (colour_depth % 3 == 1) {
- greenmask |= 1 << (colour_depth / 3);
- }
- redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
- greenmask = greenmask << (colour_depth / 3);
+ redmask = 0;
+ greenmask = 0;
+ bluemask = 0;
+ for (i = (colour_depth / 3) - 1; i >= 0; i--) {
+ redmask |= 1 << i;
+ greenmask |= 1 << i;
+ bluemask |= 1 << i;
+ }
+ if (colour_depth % 3 == 1) {
+ greenmask |= 1 << (colour_depth / 3);
+ }
+ redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
+ greenmask = greenmask << (colour_depth / 3);
}
/* adjust colour values depending on colour depth */
-unsigned int adjust_colours(unsigned int colour)
-{
- double r, g, b;
+unsigned int adjust_colours(unsigned int colour) {
+ double r, g, b;
- if (colour_depth == 0) {
- set_up_gradient();
- }
- if (colour_depth == 16) {
- r = (colour & 0xff0000) >> 16;
- g = (colour & 0xff00) >> 8;
- b = colour & 0xff;
- colour = (int) (r * CONST_8_TO_5_BITS) << 11;
- colour |= (int) (g * CONST_8_TO_6_BITS) << 5;
- colour |= (int) (b * CONST_8_TO_5_BITS);
- }
- return colour;
+ if (colour_depth == 0) {
+ set_up_gradient();
+ }
+ if (colour_depth == 16) {
+ r = (colour & 0xff0000) >> 16;
+ g = (colour & 0xff00) >> 8;
+ b = colour & 0xff;
+ colour = (int)(r * CONST_8_TO_5_BITS) << 11;
+ colour |= (int)(g * CONST_8_TO_6_BITS) << 5;
+ colour |= (int)(b * CONST_8_TO_5_BITS);
+ }
+ return colour;
}
/* this function returns the next colour between two colours for a gradient */
-unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long last_colour)
-{
- int red1, green1, blue1; // first colour
- int red2, green2, blue2; // last colour
- int reddiff, greendiff, bluediff; // difference
- short redshift = (2 * colour_depth / 3 + colour_depth % 3);
- short greenshift = (colour_depth / 3);
- unsigned long *colours = (unsigned long*)malloc(width * sizeof(unsigned long));
- int i;
+unsigned long *do_gradient(int width, unsigned long first_colour,
+ unsigned long last_colour) {
+ int red1, green1, blue1; // first colour
+ int red2, green2, blue2; // last colour
+ int reddiff, greendiff, bluediff; // difference
+ short redshift = (2 * colour_depth / 3 + colour_depth % 3);
+ short greenshift = (colour_depth / 3);
+ unsigned long *colours =
+ (unsigned long *)malloc(width * sizeof(unsigned long));
+ int i;
- if (colour_depth == 0) {
- set_up_gradient();
- }
- red1 = (first_colour & redmask) >> redshift;
- green1 = (first_colour & greenmask) >> greenshift;
- blue1 = first_colour & bluemask;
- red2 = (last_colour & redmask) >> redshift;
- green2 = (last_colour & greenmask) >> greenshift;
- blue2 = last_colour & bluemask;
- reddiff = abs(red1 - red2);
- greendiff = abs(green1 - green2);
- bluediff = abs(blue1 - blue2);
+ if (colour_depth == 0) {
+ set_up_gradient();
+ }
+ red1 = (first_colour & redmask) >> redshift;
+ green1 = (first_colour & greenmask) >> greenshift;
+ blue1 = first_colour & bluemask;
+ red2 = (last_colour & redmask) >> redshift;
+ green2 = (last_colour & greenmask) >> greenshift;
+ blue2 = last_colour & bluemask;
+ reddiff = abs(red1 - red2);
+ greendiff = abs(green1 - green2);
+ bluediff = abs(blue1 - blue2);
#ifdef HAVE_OPENMP
-#pragma omp parallel for schedule(dynamic,10) shared(colours)
+#pragma omp parallel for schedule(dynamic, 10) shared(colours)
#endif /* HAVE_OPENMP */
- for (i = 0; i < width; i++) {
- int red3 = 0, green3 = 0, blue3 = 0; // colour components
+ for (i = 0; i < width; i++) {
+ int red3 = 0, green3 = 0, blue3 = 0; // colour components
- float factor = ((float) i / (width - 1));
+ float factor = ((float)i / (width - 1));
- /* the '+ 0.5' bit rounds our floats to ints properly */
- if (red1 >= red2) {
- red3 = -(factor * reddiff) - 0.5;
- } else if (red1 < red2) {
- red3 = factor * reddiff + 0.5;
- }
- if (green1 >= green2) {
- green3 = -(factor * greendiff) - 0.5;
- } else if (green1 < green2) {
- green3 = factor * greendiff + 0.5;
- }
- if (blue1 >= blue2) {
- blue3 = -(factor * bluediff) - 0.5;
- } else if (blue1 < blue2) {
- blue3 = factor * bluediff + 0.5;
- }
- red3 += red1;
- green3 += green1;
- blue3 += blue1;
- if (red3 < 0) {
- red3 = 0;
- }
- if (green3 < 0) {
- green3 = 0;
- }
- if (blue3 < 0) {
- blue3 = 0;
- }
- if (red3 > bluemask) {
- red3 = bluemask;
- }
- if (green3 > bluemask) {
- green3 = bluemask;
- }
- if (blue3 > bluemask) {
- blue3 = bluemask;
- }
- colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
- }
- return colours;
+ /* the '+ 0.5' bit rounds our floats to ints properly */
+ if (red1 >= red2) {
+ red3 = -(factor * reddiff) - 0.5;
+ } else if (red1 < red2) {
+ red3 = factor * reddiff + 0.5;
+ }
+ if (green1 >= green2) {
+ green3 = -(factor * greendiff) - 0.5;
+ } else if (green1 < green2) {
+ green3 = factor * greendiff + 0.5;
+ }
+ if (blue1 >= blue2) {
+ blue3 = -(factor * bluediff) - 0.5;
+ } else if (blue1 < blue2) {
+ blue3 = factor * bluediff + 0.5;
+ }
+ red3 += red1;
+ green3 += green1;
+ blue3 += blue1;
+ if (red3 < 0) {
+ red3 = 0;
+ }
+ if (green3 < 0) {
+ green3 = 0;
+ }
+ if (blue3 < 0) {
+ blue3 = 0;
+ }
+ if (red3 > bluemask) {
+ red3 = bluemask;
+ }
+ if (green3 > bluemask) {
+ green3 = bluemask;
+ }
+ if (blue3 > bluemask) {
+ blue3 = bluemask;
+ }
+ colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
+ }
+ return colours;
}
#ifdef BUILD_X11
-long get_x11_color(const char *name)
-{
- XColor color;
+long get_x11_color(const char *name) {
+ XColor color;
- color.pixel = 0;
- if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) {
- /* lets check if it's a hex colour with the # missing in front
- * if yes, then do something about it */
- char newname[DEFAULT_TEXT_BUFFER_SIZE];
+ color.pixel = 0;
+ if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) {
+ /* lets check if it's a hex colour with the # missing in front
+ * if yes, then do something about it */
+ char newname[DEFAULT_TEXT_BUFFER_SIZE];
- newname[0] = '#';
- strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
- /* now lets try again */
- if (!XParseColor(display, DefaultColormap(display, screen), &newname[0],
- &color)) {
- NORM_ERR("can't parse X color '%s'", name);
- return 0xFF00FF;
- }
- }
- if (!XAllocColor(display, DefaultColormap(display, screen), &color)) {
- NORM_ERR("can't allocate X color '%s'", name);
- }
+ newname[0] = '#';
+ strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
+ /* now lets try again */
+ if (!XParseColor(display, DefaultColormap(display, screen), &newname[0],
+ &color)) {
+ NORM_ERR("can't parse X color '%s'", name);
+ return 0xFF00FF;
+ }
+ }
+ if (!XAllocColor(display, DefaultColormap(display, screen), &color)) {
+ NORM_ERR("can't allocate X color '%s'", name);
+ }
- return (long) color.pixel;
+ return (long)color.pixel;
}
-long get_x11_color(const std::string &colour)
-{ return get_x11_color(colour.c_str()); }
+long get_x11_color(const std::string &colour) {
+ return get_x11_color(colour.c_str());
+}
#endif
diff --git a/src/colours.h b/src/colours.h
index 1ebefff1..ec34d775 100644
--- a/src/colours.h
+++ b/src/colours.h
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -30,6 +29,8 @@
#ifndef _COLOURS_H
#define _COLOURS_H
+#include
+
unsigned int adjust_colours(unsigned int);
unsigned long *do_gradient(int, unsigned long, unsigned long);
diff --git a/src/combine.cc b/src/combine.cc
index dad2e5df..9edff96d 100644
--- a/src/combine.cc
+++ b/src/combine.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -35,155 +34,159 @@
#include "text_object.h"
struct combine_data {
- char *left;
- char *seperation;
- char *right;
+ char *left;
+ char *seperation;
+ char *right;
};
-void parse_combine_arg(struct text_object *obj, const char *arg)
-{
- struct combine_data *cd;
- unsigned int i,j;
- unsigned int indenting = 0; //vars can be used as args for other vars
- int startvar[2];
- int endvar[2];
- startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
- j=0;
- for (i=0; arg[i] != 0 && j < 2; i++) {
- if(startvar[j] == -1) {
- if(arg[i] == '$') {
- startvar[j] = i;
- }
- }else if(endvar[j] == -1) {
- if(arg[i] == '{') {
- indenting++;
- }else if(arg[i] == '}') {
- indenting--;
- }
- if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
- endvar[j]=i+1;
- j++;
- }
- }
- }
- if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
- cd = (struct combine_data*)malloc(sizeof(struct combine_data));
- memset(cd, 0, sizeof(struct combine_data));
+void parse_combine_arg(struct text_object *obj, const char *arg) {
+ struct combine_data *cd;
+ unsigned int i, j;
+ unsigned int indenting = 0; // vars can be used as args for other vars
+ int startvar[2];
+ int endvar[2];
+ startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
+ j = 0;
+ for (i = 0; arg[i] != 0 && j < 2; i++) {
+ if (startvar[j] == -1) {
+ if (arg[i] == '$') {
+ startvar[j] = i;
+ }
+ } else if (endvar[j] == -1) {
+ if (arg[i] == '{') {
+ indenting++;
+ } else if (arg[i] == '}') {
+ indenting--;
+ }
+ if (indenting == 0 &&
+ arg[i + 1] < 48) { //<48 has 0, $, and the most used chars not used
+ // in varnames but not { or }
+ endvar[j] = i + 1;
+ j++;
+ }
+ }
+ }
+ if (startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 &&
+ endvar[1] >= 0) {
+ cd = (struct combine_data *)malloc(sizeof(struct combine_data));
+ memset(cd, 0, sizeof(struct combine_data));
- cd->left = (char*)malloc(endvar[0]-startvar[0] + 1);
- cd->seperation = (char*)malloc(startvar[1] - endvar[0] + 1);
- cd->right= (char*)malloc(endvar[1]-startvar[1] + 1);
+ cd->left = (char *)malloc(endvar[0] - startvar[0] + 1);
+ cd->seperation = (char *)malloc(startvar[1] - endvar[0] + 1);
+ cd->right = (char *)malloc(endvar[1] - startvar[1] + 1);
- strncpy(cd->left, arg + startvar[0], endvar[0] - startvar[0]);
- cd->left[endvar[0] - startvar[0]] = 0;
+ strncpy(cd->left, arg + startvar[0], endvar[0] - startvar[0]);
+ cd->left[endvar[0] - startvar[0]] = 0;
- strncpy(cd->seperation, arg + endvar[0], startvar[1] - endvar[0]);
- cd->seperation[startvar[1] - endvar[0]] = 0;
+ strncpy(cd->seperation, arg + endvar[0], startvar[1] - endvar[0]);
+ cd->seperation[startvar[1] - endvar[0]] = 0;
- strncpy(cd->right, arg + startvar[1], endvar[1] - startvar[1]);
- cd->right[endvar[1] - startvar[1]] = 0;
+ strncpy(cd->right, arg + startvar[1], endvar[1] - startvar[1]);
+ cd->right[endvar[1] - startvar[1]] = 0;
- obj->sub = (struct text_object*)malloc(sizeof(struct text_object));
- extract_variable_text_internal(obj->sub, cd->left);
- obj->sub->sub = (struct text_object*)malloc(sizeof(struct text_object));
- extract_variable_text_internal(obj->sub->sub, cd->right);
- obj->data.opaque = cd;
- } else {
- throw combine_needs_2_args_error();
- }
+ obj->sub = (struct text_object *)malloc(sizeof(struct text_object));
+ extract_variable_text_internal(obj->sub, cd->left);
+ obj->sub->sub = (struct text_object *)malloc(sizeof(struct text_object));
+ extract_variable_text_internal(obj->sub->sub, cd->right);
+ obj->data.opaque = cd;
+ } else {
+ throw combine_needs_2_args_error();
+ }
}
-void print_combine(struct text_object *obj, char *p, int p_max_size)
-{
- struct combine_data *cd = (struct combine_data *)obj->data.opaque;
- std::vector> buf;
- buf.resize(2);
- buf[0].resize(max_user_text.get(*state));
- buf[1].resize(max_user_text.get(*state));
- int i, j;
- long longest=0;
- int nextstart;
- int nr_rows[2];
- struct llrows {
- char* row;
- struct llrows* next;
- };
- struct llrows *ll_rows[2], *current[2];
- struct text_object * objsub = obj->sub;
+void print_combine(struct text_object *obj, char *p, int p_max_size) {
+ struct combine_data *cd = (struct combine_data *)obj->data.opaque;
+ std::vector> buf;
+ buf.resize(2);
+ buf[0].resize(max_user_text.get(*state));
+ buf[1].resize(max_user_text.get(*state));
+ int i, j;
+ long longest = 0;
+ int nextstart;
+ int nr_rows[2];
+ struct llrows {
+ char *row;
+ struct llrows *next;
+ };
+ struct llrows *ll_rows[2], *current[2];
+ struct text_object *objsub = obj->sub;
- if (!cd || !p_max_size)
- return;
+ if (!cd || !p_max_size) return;
- p[0]=0;
- for(i=0; i<2; i++) {
- nr_rows[i] = 1;
- nextstart = 0;
- ll_rows[i] = (struct llrows*)malloc(sizeof(struct llrows));
- current[i] = ll_rows[i];
- for(j=0; jsub;
- generate_text_internal(&(buf[i][0]), max_user_text.get(*state), *objsub);
- for(j=0; buf[i][j] != 0; j++) {
- if(buf[i][j] == '\t') buf[i][j] = ' ';
- if(buf[i][j] == '\n') buf[i][j] = 0; //the vars inside combine may not have a \n at the end
- if(buf[i][j] == 2) { // \002 is used instead of \n to separate lines inside a var
- buf[i][j] = 0;
- current[i]->row = strdup(&(buf[i][0])+nextstart);
- if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
- current[i]->next = (struct llrows*)malloc(sizeof(struct llrows));
- current[i] = current[i]->next;
- nextstart = j + 1;
- nr_rows[i]++;
- }
- }
- current[i]->row = strdup(&(buf[i][0])+nextstart);
- if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
- current[i]->next = NULL;
- current[i] = ll_rows[i];
- }
- for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
- if(current[0]) {
- strcat(p, current[0]->row);
- i=strlen(current[0]->row);
- }else i = 0;
- while(i < longest) {
- strcat(p, " ");
- i++;
- }
- if(current[1]) {
- strcat(p, cd->seperation);
- strcat(p, current[1]->row);
- }
- strcat(p, "\n");
+ p[0] = 0;
+ for (i = 0; i < 2; i++) {
+ nr_rows[i] = 1;
+ nextstart = 0;
+ ll_rows[i] = (struct llrows *)malloc(sizeof(struct llrows));
+ current[i] = ll_rows[i];
+ for (j = 0; j < i; j++) objsub = objsub->sub;
+ generate_text_internal(&(buf[i][0]), max_user_text.get(*state), *objsub);
+ for (j = 0; buf[i][j] != 0; j++) {
+ if (buf[i][j] == '\t') buf[i][j] = ' ';
+ if (buf[i][j] == '\n')
+ buf[i][j] = 0; // the vars inside combine may not have a \n at the end
+ if (buf[i][j] ==
+ 2) { // \002 is used instead of \n to separate lines inside a var
+ buf[i][j] = 0;
+ current[i]->row = strdup(&(buf[i][0]) + nextstart);
+ if (i == 0 && (long)strlen(current[i]->row) > longest)
+ longest = (long)strlen(current[i]->row);
+ current[i]->next = (struct llrows *)malloc(sizeof(struct llrows));
+ current[i] = current[i]->next;
+ nextstart = j + 1;
+ nr_rows[i]++;
+ }
+ }
+ current[i]->row = strdup(&(buf[i][0]) + nextstart);
+ if (i == 0 && (long)strlen(current[i]->row) > longest)
+ longest = (long)strlen(current[i]->row);
+ current[i]->next = NULL;
+ current[i] = ll_rows[i];
+ }
+ for (j = 0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1]); j++) {
+ if (current[0]) {
+ strcat(p, current[0]->row);
+ i = strlen(current[0]->row);
+ } else
+ i = 0;
+ while (i < longest) {
+ strcat(p, " ");
+ i++;
+ }
+ if (current[1]) {
+ strcat(p, cd->seperation);
+ strcat(p, current[1]->row);
+ }
+ strcat(p, "\n");
#ifdef HAVE_OPENMP
-#pragma omp parallel for schedule(dynamic,10)
+#pragma omp parallel for schedule(dynamic, 10)
#endif /* HAVE_OPENMP */
- for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
- }
+ for (i = 0; i < 2; i++)
+ if (current[i]) current[i] = current[i]->next;
+ }
#ifdef HAVE_OPENMP
-#pragma omp parallel for schedule(dynamic,10)
+#pragma omp parallel for schedule(dynamic, 10)
#endif /* HAVE_OPENMP */
- for(i=0; i<2; i++) {
- while(ll_rows[i] != NULL) {
- current[i]=ll_rows[i];
- free(current[i]->row);
- ll_rows[i]=current[i]->next;
- free(current[i]);
- }
- }
+ for (i = 0; i < 2; i++) {
+ while (ll_rows[i] != NULL) {
+ current[i] = ll_rows[i];
+ free(current[i]->row);
+ ll_rows[i] = current[i]->next;
+ free(current[i]);
+ }
+ }
}
-void free_combine(struct text_object *obj)
-{
- struct combine_data *cd = (struct combine_data *)obj->data.opaque;
+void free_combine(struct text_object *obj) {
+ struct combine_data *cd = (struct combine_data *)obj->data.opaque;
- if (!cd)
- return;
- free(cd->left);
- free(cd->seperation);
- free(cd->right);
- free_text_objects(obj->sub->sub);
- free_and_zero(obj->sub->sub);
- free_text_objects(obj->sub);
- free_and_zero(obj->sub);
- free_and_zero(obj->data.opaque);
+ if (!cd) return;
+ free(cd->left);
+ free(cd->seperation);
+ free(cd->right);
+ free_text_objects(obj->sub->sub);
+ free_and_zero(obj->sub->sub);
+ free_text_objects(obj->sub);
+ free_and_zero(obj->sub);
+ free_and_zero(obj->data.opaque);
}
diff --git a/src/combine.h b/src/combine.h
index cacba209..146ec236 100644
--- a/src/combine.h
+++ b/src/combine.h
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
diff --git a/src/common.cc b/src/common.cc
index 37fddf3e..4f1db15f 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -28,6 +27,17 @@
*
*/
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include "config.h"
#include "conky.h"
#include "core.h"
@@ -38,17 +48,6 @@
#include "temphelper.h"
#include "timeinfo.h"
#include "top.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
/* check for OS and include appropriate headers */
#if defined(__linux__)
@@ -60,7 +59,7 @@
#elif defined(__OpenBSD__)
#include "openbsd.h"
#elif defined(__APPLE__) && defined(__MACH__)
-#include "darwin.h" // strings.h
+#include "darwin.h" // strings.h
#endif
#include "update-cb.hh"
@@ -73,352 +72,324 @@
*
* if start is "blah", and you call it with count = 1, the result will be "lah"
*/
-void strfold(char *start, int count)
-{
- char *curplace;
- for (curplace = start + count; *curplace != 0; curplace++) {
- *(curplace - count) = *curplace;
- }
- *(curplace - count) = 0;
+void strfold(char *start, int count) {
+ char *curplace;
+ for (curplace = start + count; *curplace != 0; curplace++) {
+ *(curplace - count) = *curplace;
+ }
+ *(curplace - count) = 0;
}
#ifndef HAVE_STRNDUP
// use our own strndup() if it's not available
-char *strndup(const char *s, size_t n)
-{
- if (strlen(s) > n) {
- char *ret = malloc(n + 1);
- strncpy(ret, s, n);
- ret[n] = 0;
- return ret;
- } else {
- return strdup(s);
- }
+char *strndup(const char *s, size_t n) {
+ if (strlen(s) > n) {
+ char *ret = malloc(n + 1);
+ strncpy(ret, s, n);
+ ret[n] = 0;
+ return ret;
+ } else {
+ return strdup(s);
+ }
}
#endif /* HAVE_STRNDUP */
-int update_uname(void)
-{
- uname(&info.uname_s);
+int update_uname(void) {
+ uname(&info.uname_s);
#if defined(__DragonFly__)
- {
- size_t desc_n; char desc[256];
+ {
+ size_t desc_n;
+ char desc[256];
- if (sysctlbyname("kern.version", NULL, &desc_n, NULL, 0) == -1 ||
- sysctlbyname("kern.version", desc, &desc_n, NULL, 0) == -1)
- perror("kern.version");
- else {
- char *start = desc;
- strsep(&start, " ");
- strcpy(info.uname_v, strsep(&start, " "));
- }
+ if (sysctlbyname("kern.version", NULL, &desc_n, NULL, 0) == -1 ||
+ sysctlbyname("kern.version", desc, &desc_n, NULL, 0) == -1)
+ perror("kern.version");
+ else {
+ char *start = desc;
+ strsep(&start, " ");
+ strcpy(info.uname_v, strsep(&start, " "));
+ }
- if (errno == ENOMEM) printf("desc_n %zu\n", desc_n);
- }
+ if (errno == ENOMEM) printf("desc_n %zu\n", desc_n);
+ }
#endif
- return 0;
+ return 0;
}
-double get_time(void)
-{
- struct timespec tv;
+double get_time(void) {
+ struct timespec tv;
#ifdef _POSIX_MONOTONIC_CLOCK
- clock_gettime(CLOCK_MONOTONIC, &tv);
+ clock_gettime(CLOCK_MONOTONIC, &tv);
#else
- clock_gettime(CLOCK_REALTIME, &tv);
+ clock_gettime(CLOCK_REALTIME, &tv);
#endif
- return tv.tv_sec + (tv.tv_nsec * 1e-9);
+ return tv.tv_sec + (tv.tv_nsec * 1e-9);
}
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
* variable_substitute, except only cheques for $HOME and ~/ in
* path. If HOME is unset it uses an empty string for substitution */
-std::string to_real_path(const std::string &source)
-{
- const char *homedir = getenv("HOME") ? : "";
- if(source.find("~/") == 0)
- return homedir + source.substr(1);
- else if(source.find("$HOME/") == 0)
- return homedir + source.substr(5);
- else
- return source;
+std::string to_real_path(const std::string &source) {
+ const char *homedir = getenv("HOME") ?: "";
+ if (source.find("~/") == 0)
+ return homedir + source.substr(1);
+ else if (source.find("$HOME/") == 0)
+ return homedir + source.substr(5);
+ else
+ return source;
}
-int open_fifo(const char *file, int *reported)
-{
- int fd = 0;
+int open_fifo(const char *file, int *reported) {
+ int fd = 0;
- fd = open(file, O_RDONLY | O_NONBLOCK);
+ fd = open(file, O_RDONLY | O_NONBLOCK);
- if (fd == -1) {
- if (!reported || *reported == 0) {
- NORM_ERR("can't open %s: %s", file, strerror(errno));
- if (reported) {
- *reported = 1;
- }
- }
- return -1;
- }
+ if (fd == -1) {
+ if (!reported || *reported == 0) {
+ NORM_ERR("can't open %s: %s", file, strerror(errno));
+ if (reported) {
+ *reported = 1;
+ }
+ }
+ return -1;
+ }
- return fd;
+ return fd;
}
-FILE *open_file(const char *file, int *reported)
-{
- FILE *fp = 0;
+FILE *open_file(const char *file, int *reported) {
+ FILE *fp = 0;
- fp = fopen(file, "r");
+ fp = fopen(file, "r");
- if (!fp) {
- if (!reported || *reported == 0) {
- NORM_ERR("can't open %s: %s", file, strerror(errno));
- if (reported) {
- *reported = 1;
- }
- }
- return NULL;
- }
+ if (!fp) {
+ if (!reported || *reported == 0) {
+ NORM_ERR("can't open %s: %s", file, strerror(errno));
+ if (reported) {
+ *reported = 1;
+ }
+ }
+ return NULL;
+ }
- return fp;
+ return fp;
}
-std::string variable_substitute(std::string s)
-{
- std::string::size_type pos = 0;
- while((pos = s.find('$', pos)) != std::string::npos) {
- if(pos + 1 >= s.size())
- break;
+std::string variable_substitute(std::string s) {
+ std::string::size_type pos = 0;
+ while ((pos = s.find('$', pos)) != std::string::npos) {
+ if (pos + 1 >= s.size()) break;
- if(s[pos+1] == '$') {
- s.erase(pos, 1);
- ++pos;
- } else {
- std::string var;
- std::string::size_type l = 0;
+ if (s[pos + 1] == '$') {
+ s.erase(pos, 1);
+ ++pos;
+ } else {
+ std::string var;
+ std::string::size_type l = 0;
- if(isalpha(s[pos+1])) {
- l = 1;
- while(pos+l < s.size() && isalnum(s[pos+l]))
- ++l;
- var = s.substr(pos+1, l-1);
- } else if(s[pos+1] == '{') {
- l = s.find('}', pos);
- if(l == std::string::npos)
- break;
- l -= pos - 1;
- var = s.substr(pos+2, l-3);
- } else
- ++pos;
+ if (isalpha(s[pos + 1])) {
+ l = 1;
+ while (pos + l < s.size() && isalnum(s[pos + l])) ++l;
+ var = s.substr(pos + 1, l - 1);
+ } else if (s[pos + 1] == '{') {
+ l = s.find('}', pos);
+ if (l == std::string::npos) break;
+ l -= pos - 1;
+ var = s.substr(pos + 2, l - 3);
+ } else
+ ++pos;
- if(l) {
- s.erase(pos, l);
- const char *val = getenv(var.c_str());
- if(val) {
- s.insert(pos, val);
- pos += strlen(val);
- }
+ if (l) {
+ s.erase(pos, l);
+ const char *val = getenv(var.c_str());
+ if (val) {
+ s.insert(pos, val);
+ pos += strlen(val);
+ }
+ }
+ }
+ }
- }
- }
- }
-
- return s;
+ return s;
}
-void format_seconds(char *buf, unsigned int n, long seconds)
-{
- long days;
- int hours, minutes;
+void format_seconds(char *buf, unsigned int n, long seconds) {
+ long days;
+ int hours, minutes;
- if (times_in_seconds.get(*state)) {
- snprintf(buf, n, "%ld", seconds);
- return;
- }
+ if (times_in_seconds.get(*state)) {
+ snprintf(buf, n, "%ld", seconds);
+ return;
+ }
- days = seconds / 86400;
- seconds %= 86400;
- hours = seconds / 3600;
- seconds %= 3600;
- minutes = seconds / 60;
- seconds %= 60;
+ days = seconds / 86400;
+ seconds %= 86400;
+ hours = seconds / 3600;
+ seconds %= 3600;
+ minutes = seconds / 60;
+ seconds %= 60;
- if (days > 0) {
- snprintf(buf, n, "%ldd %dh %dm", days, hours, minutes);
- } else {
- snprintf(buf, n, "%dh %dm %lds", hours, minutes, seconds);
- }
+ if (days > 0) {
+ snprintf(buf, n, "%ldd %dh %dm", days, hours, minutes);
+ } else {
+ snprintf(buf, n, "%dh %dm %lds", hours, minutes, seconds);
+ }
}
-void format_seconds_short(char *buf, unsigned int n, long seconds)
-{
- long days;
- int hours, minutes;
+void format_seconds_short(char *buf, unsigned int n, long seconds) {
+ long days;
+ int hours, minutes;
- if (times_in_seconds.get(*state)) {
- snprintf(buf, n, "%ld", seconds);
- return;
- }
+ if (times_in_seconds.get(*state)) {
+ snprintf(buf, n, "%ld", seconds);
+ return;
+ }
- days = seconds / 86400;
- seconds %= 86400;
- hours = seconds / 3600;
- seconds %= 3600;
- minutes = seconds / 60;
- seconds %= 60;
+ days = seconds / 86400;
+ seconds %= 86400;
+ hours = seconds / 3600;
+ seconds %= 3600;
+ minutes = seconds / 60;
+ seconds %= 60;
- if (days > 0) {
- snprintf(buf, n, "%ldd %dh", days, hours);
- } else if (hours > 0) {
- snprintf(buf, n, "%dh %dm", hours, minutes);
- } else {
- snprintf(buf, n, "%dm %lds", minutes, seconds);
- }
+ if (days > 0) {
+ snprintf(buf, n, "%ldd %dh", days, hours);
+ } else if (hours > 0) {
+ snprintf(buf, n, "%dh %dm", hours, minutes);
+ } else {
+ snprintf(buf, n, "%dm %lds", minutes, seconds);
+ }
}
conky::simple_config_setting no_buffers("no_buffers", true, true);
-void update_stuff(void)
-{
- /* clear speeds, addresses and up status in case device was removed and
- * doesn't get updated */
+void update_stuff(void) {
+ /* clear speeds, addresses and up status in case device was removed and
+ * doesn't get updated */
- #ifdef HAVE_OPENMP
- #pragma omp parallel for schedule(dynamic,10)
- #endif /* HAVE_OPENMP */
- for (int i = 0; i < MAX_NET_INTERFACES; ++i) {
- if (netstats[i].dev) {
- netstats[i].up = 0;
- netstats[i].recv_speed = 0.0;
- netstats[i].trans_speed = 0.0;
- netstats[i].addr.sa_data[2] = 0;
- netstats[i].addr.sa_data[3] = 0;
- netstats[i].addr.sa_data[4] = 0;
- netstats[i].addr.sa_data[5] = 0;
- }
- }
+#ifdef HAVE_OPENMP
+#pragma omp parallel for schedule(dynamic, 10)
+#endif /* HAVE_OPENMP */
+ for (int i = 0; i < MAX_NET_INTERFACES; ++i) {
+ if (netstats[i].dev) {
+ netstats[i].up = 0;
+ netstats[i].recv_speed = 0.0;
+ netstats[i].trans_speed = 0.0;
+ netstats[i].addr.sa_data[2] = 0;
+ netstats[i].addr.sa_data[3] = 0;
+ netstats[i].addr.sa_data[4] = 0;
+ netstats[i].addr.sa_data[5] = 0;
+ }
+ }
- /* this is a stub on all platforms except solaris */
- prepare_update();
+ /* this is a stub on all platforms except solaris */
+ prepare_update();
- /* if you registered a callback with conky::register_cb, this will run it */
- conky::run_all_callbacks();
+ /* if you registered a callback with conky::register_cb, this will run it */
+ conky::run_all_callbacks();
- /* XXX: move the following into the update_meminfo() functions? */
- if (no_buffers.get(*state)) {
- info.mem -= info.bufmem;
- info.memeasyfree += info.bufmem;
- }
+ /* XXX: move the following into the update_meminfo() functions? */
+ if (no_buffers.get(*state)) {
+ info.mem -= info.bufmem;
+ info.memeasyfree += info.bufmem;
+ }
}
/* Ohkie to return negative values for temperatures */
-int round_to_int_temp(float f)
-{
- if (f >= 0.0) {
- return (int) (f + 0.5);
- } else {
- return (int) (f - 0.5);
- }
+int round_to_int_temp(float f) {
+ if (f >= 0.0) {
+ return (int)(f + 0.5);
+ } else {
+ return (int)(f - 0.5);
+ }
}
/* Don't return negative values for cpugraph, bar, gauge, percentage.
* Causes unreasonable numbers to show */
-unsigned int round_to_int(float f)
-{
- if (f >= 0.0) {
- return (int) (f + 0.5);
- } else {
- return 0;
- }
+unsigned int round_to_int(float f) {
+ if (f >= 0.0) {
+ return (int)(f + 0.5);
+ } else {
+ return 0;
+ }
}
-void scan_loadavg_arg(struct text_object *obj, const char *arg)
-{
- obj->data.i = 0;
- if (arg && !arg[1] && isdigit(arg[0])) {
- obj->data.i = atoi(arg);
- if (obj->data.i > 3 || obj->data.i < 1) {
- NORM_ERR("loadavg arg needs to be in range (1,3)");
- obj->data.i = 0;
- }
- }
- /* convert to array index (or the default (-1)) */
- obj->data.i--;
+void scan_loadavg_arg(struct text_object *obj, const char *arg) {
+ obj->data.i = 0;
+ if (arg && !arg[1] && isdigit(arg[0])) {
+ obj->data.i = atoi(arg);
+ if (obj->data.i > 3 || obj->data.i < 1) {
+ NORM_ERR("loadavg arg needs to be in range (1,3)");
+ obj->data.i = 0;
+ }
+ }
+ /* convert to array index (or the default (-1)) */
+ obj->data.i--;
}
-void print_loadavg(struct text_object *obj, char *p, int p_max_size)
-{
- float *v = info.loadavg;
+void print_loadavg(struct text_object *obj, char *p, int p_max_size) {
+ float *v = info.loadavg;
- if (obj->data.i < 0) {
- snprintf(p, p_max_size, "%.2f %.2f %.2f", v[0], v[1], v[2]);
- } else {
- snprintf(p, p_max_size, "%.2f", v[obj->data.i]);
- }
+ if (obj->data.i < 0) {
+ snprintf(p, p_max_size, "%.2f %.2f %.2f", v[0], v[1], v[2]);
+ } else {
+ snprintf(p, p_max_size, "%.2f", v[obj->data.i]);
+ }
}
-void scan_no_update(struct text_object *obj, const char *arg)
-{
- obj->data.s = (char*) malloc(text_buffer_size.get(*state));
- evaluate(arg, obj->data.s, text_buffer_size.get(*state));
- obj->data.s = (char*) realloc(obj->data.s, strlen(obj->data.s) + 1);
+void scan_no_update(struct text_object *obj, const char *arg) {
+ obj->data.s = (char *)malloc(text_buffer_size.get(*state));
+ evaluate(arg, obj->data.s, text_buffer_size.get(*state));
+ obj->data.s = (char *)realloc(obj->data.s, strlen(obj->data.s) + 1);
}
-void free_no_update(struct text_object *obj) {
- free(obj->data.s);
-}
+void free_no_update(struct text_object *obj) { free(obj->data.s); }
-void print_no_update(struct text_object *obj, char *p, int p_max_size)
-{
- snprintf(p, p_max_size, "%s", obj->data.s);
+void print_no_update(struct text_object *obj, char *p, int p_max_size) {
+ snprintf(p, p_max_size, "%s", obj->data.s);
}
#ifdef BUILD_X11
-void scan_loadgraph_arg(struct text_object *obj, const char *arg)
-{
- char *buf = 0;
+void scan_loadgraph_arg(struct text_object *obj, const char *arg) {
+ char *buf = 0;
- buf = scan_graph(obj, arg, 0);
- free_and_zero(buf);
+ buf = scan_graph(obj, arg, 0);
+ free_and_zero(buf);
}
-double loadgraphval(struct text_object *obj)
-{
- (void)obj;
+double loadgraphval(struct text_object *obj) {
+ (void)obj;
- return info.loadavg[0];
+ return info.loadavg[0];
}
#endif /* BUILD_X11 */
-uint8_t cpu_percentage(struct text_object *obj)
-{
- if (obj->data.i > info.cpu_count) {
- NORM_ERR("obj->data.i %i info.cpu_count %i",
- obj->data.i, info.cpu_count);
- CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
- }
- if (info.cpu_usage) {
- return round_to_int(info.cpu_usage[obj->data.i] * 100.0);
- } else {
- return 0;
- }
+uint8_t cpu_percentage(struct text_object *obj) {
+ if (obj->data.i > info.cpu_count) {
+ NORM_ERR("obj->data.i %i info.cpu_count %i", obj->data.i, info.cpu_count);
+ CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
+ }
+ if (info.cpu_usage) {
+ return round_to_int(info.cpu_usage[obj->data.i] * 100.0);
+ } else {
+ return 0;
+ }
}
-double cpu_barval(struct text_object *obj)
-{
- if (info.cpu_usage) {
- return info.cpu_usage[obj->data.i];
- } else {
- return 0.;
- }
+double cpu_barval(struct text_object *obj) {
+ if (info.cpu_usage) {
+ return info.cpu_usage[obj->data.i];
+ } else {
+ return 0.;
+ }
}
-#define PRINT_HR_GENERATOR(name) \
-void print_##name(struct text_object *obj, char *p, int p_max_size) \
-{ \
- (void)obj; \
- human_readable(info.name * 1024, p, p_max_size); \
-}
+#define PRINT_HR_GENERATOR(name) \
+ void print_##name(struct text_object *obj, char *p, int p_max_size) { \
+ (void)obj; \
+ human_readable(info.name * 1024, p, p_max_size); \
+ }
PRINT_HR_GENERATOR(mem)
PRINT_HR_GENERATOR(memwithbuffers)
@@ -430,341 +401,300 @@ PRINT_HR_GENERATOR(swap)
PRINT_HR_GENERATOR(swapfree)
PRINT_HR_GENERATOR(swapmax)
-uint8_t mem_percentage(struct text_object *obj)
-{
- (void)obj;
+uint8_t mem_percentage(struct text_object *obj) {
+ (void)obj;
- return (info.memmax ? round_to_int(info.mem * 100 / info.memmax) : 0);
+ return (info.memmax ? round_to_int(info.mem * 100 / info.memmax) : 0);
}
-double mem_barval(struct text_object *obj)
-{
- (void)obj;
+double mem_barval(struct text_object *obj) {
+ (void)obj;
- return info.memmax ? ((double)info.mem / info.memmax) : 0;
+ return info.memmax ? ((double)info.mem / info.memmax) : 0;
}
-double mem_with_buffers_barval(struct text_object *obj)
-{
- (void)obj;
+double mem_with_buffers_barval(struct text_object *obj) {
+ (void)obj;
- return info.memmax ? ((double)info.memwithbuffers / info.memmax) : 0;
+ return info.memmax ? ((double)info.memwithbuffers / info.memmax) : 0;
}
-uint8_t swap_percentage(struct text_object *obj)
-{
- (void)obj;
+uint8_t swap_percentage(struct text_object *obj) {
+ (void)obj;
- return (info.swapmax ? round_to_int(info.swap * 100 / info.swapmax) : 0);
+ return (info.swapmax ? round_to_int(info.swap * 100 / info.swapmax) : 0);
}
-double swap_barval(struct text_object *obj)
-{
- (void)obj;
+double swap_barval(struct text_object *obj) {
+ (void)obj;
- return info.swapmax ? ((double)info.swap / info.swapmax) : 0;
+ return info.swapmax ? ((double)info.swap / info.swapmax) : 0;
}
-void print_kernel(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%s", info.uname_s.release);
+void print_kernel(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%s", info.uname_s.release);
}
-void print_machine(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%s", info.uname_s.machine);
+void print_machine(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%s", info.uname_s.machine);
}
-void print_nodename(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%s", info.uname_s.nodename);
+void print_nodename(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%s", info.uname_s.nodename);
}
-void print_nodename_short(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%s", info.uname_s.nodename);
- for(int i=0; p[i] != 0; i++) {
- if(p[i] == '.') {
- p[i] = 0;
- break;
- }
- }
+void print_nodename_short(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%s", info.uname_s.nodename);
+ for (int i = 0; p[i] != 0; i++) {
+ if (p[i] == '.') {
+ p[i] = 0;
+ break;
+ }
+ }
}
-void print_sysname(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%s", info.uname_s.sysname);
+void print_sysname(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%s", info.uname_s.sysname);
}
#if defined(__DragonFly__)
-void print_version(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%s", info.uname_v);
+void print_version(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%s", info.uname_v);
}
#endif
-void print_uptime(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- format_seconds(p, p_max_size, (int)info.uptime);
+void print_uptime(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ format_seconds(p, p_max_size, (int)info.uptime);
}
-void print_uptime_short(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- format_seconds_short(p, p_max_size, (int)info.uptime);
+void print_uptime_short(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ format_seconds_short(p, p_max_size, (int)info.uptime);
}
-void print_processes(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- spaced_print(p, p_max_size, "%hu", 4, info.procs);
+void print_processes(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ spaced_print(p, p_max_size, "%hu", 4, info.procs);
}
-void print_running_processes(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- spaced_print(p, p_max_size, "%hu", 4, info.run_procs);
+void print_running_processes(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ spaced_print(p, p_max_size, "%hu", 4, info.run_procs);
}
-void print_running_threads(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- spaced_print(p, p_max_size, "%hu", 4, info.run_threads);
+void print_running_threads(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ spaced_print(p, p_max_size, "%hu", 4, info.run_threads);
}
-void print_threads(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- spaced_print(p, p_max_size, "%hu", 4, info.threads);
+void print_threads(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ spaced_print(p, p_max_size, "%hu", 4, info.threads);
}
-void print_buffers(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- human_readable(info.buffers * 1024, p, p_max_size);
+void print_buffers(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ human_readable(info.buffers * 1024, p, p_max_size);
}
-void print_cached(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- human_readable(info.cached * 1024, p, p_max_size);
+void print_cached(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ human_readable(info.cached * 1024, p, p_max_size);
}
-void print_evaluate(struct text_object *obj, char *p, int p_max_size)
-{
- std::vector buf(text_buffer_size.get(*state));
- evaluate(obj->data.s, &buf[0], buf.size());
- evaluate(&buf[0], p, p_max_size);
+void print_evaluate(struct text_object *obj, char *p, int p_max_size) {
+ std::vector buf(text_buffer_size.get(*state));
+ evaluate(obj->data.s, &buf[0], buf.size());
+ evaluate(&buf[0], p, p_max_size);
}
-int if_empty_iftest(struct text_object *obj)
-{
- std::vector buf(max_user_text.get(*state));
- int result = 1;
+int if_empty_iftest(struct text_object *obj) {
+ std::vector buf(max_user_text.get(*state));
+ int result = 1;
- generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
+ generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
- if (strlen(&(buf[0])) != 0) {
- result = 0;
- }
- return result;
+ if (strlen(&(buf[0])) != 0) {
+ result = 0;
+ }
+ return result;
}
-static int check_contains(char *f, char *s)
-{
- int ret = 0;
- FILE *where = open_file(f, 0);
+static int check_contains(char *f, char *s) {
+ int ret = 0;
+ FILE *where = open_file(f, 0);
- if (where) {
- char buf1[256];
+ if (where) {
+ char buf1[256];
- while (fgets(buf1, 256, where)) {
- if (strstr(buf1, s)) {
- ret = 1;
- break;
- }
- }
- fclose(where);
- } else {
- NORM_ERR("Could not open the file");
- }
- return ret;
+ while (fgets(buf1, 256, where)) {
+ if (strstr(buf1, s)) {
+ ret = 1;
+ break;
+ }
+ }
+ fclose(where);
+ } else {
+ NORM_ERR("Could not open the file");
+ }
+ return ret;
}
-int if_existing_iftest(struct text_object *obj)
-{
- char *spc;
- int result = 0;
+int if_existing_iftest(struct text_object *obj) {
+ char *spc;
+ int result = 0;
- spc = strchr(obj->data.s, ' ');
- if(spc != NULL) *spc = 0;
- if (access(obj->data.s, F_OK) == 0) {
- if(spc == NULL || check_contains(obj->data.s, spc + 1)) result = 1;
- }
- if(spc != NULL) *spc = ' ';
- return result;
+ spc = strchr(obj->data.s, ' ');
+ if (spc != NULL) *spc = 0;
+ if (access(obj->data.s, F_OK) == 0) {
+ if (spc == NULL || check_contains(obj->data.s, spc + 1)) result = 1;
+ }
+ if (spc != NULL) *spc = ' ';
+ return result;
}
-int if_running_iftest(struct text_object *obj)
-{
+int if_running_iftest(struct text_object *obj) {
#ifdef __linux__
- if (!get_process_by_name(obj->data.s)) {
+ if (!get_process_by_name(obj->data.s)) {
#else
- if ((obj->data.s) && system(obj->data.s)) {
+ if ((obj->data.s) && system(obj->data.s)) {
#endif
- return 0;
- }
- return 1;
+ return 0;
+ }
+ return 1;
}
#ifndef __OpenBSD__
-void print_acpitemp(struct text_object *obj, char *p, int p_max_size)
-{
- temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
+void print_acpitemp(struct text_object *obj, char *p, int p_max_size) {
+ temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
}
-void free_acpitemp(struct text_object *obj)
-{
- close(obj->data.i);
-}
+void free_acpitemp(struct text_object *obj) { close(obj->data.i); }
#endif /* !__OpenBSD__ */
-void print_freq(struct text_object *obj, char *p, int p_max_size)
-{
- static int ok = 1;
- if (ok) {
- ok = get_freq(p, p_max_size, "%.0f", 1, obj->data.i);
- }
+void print_freq(struct text_object *obj, char *p, int p_max_size) {
+ static int ok = 1;
+ if (ok) {
+ ok = get_freq(p, p_max_size, "%.0f", 1, obj->data.i);
+ }
}
-void print_freq_g(struct text_object *obj, char *p, int p_max_size)
-{
- static int ok = 1;
- if (ok) {
+void print_freq_g(struct text_object *obj, char *p, int p_max_size) {
+ static int ok = 1;
+ if (ok) {
#ifndef __OpenBSD__
- ok = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.i);
+ ok = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.i);
#else
- /* OpenBSD has no such flag (SUSv2) */
- ok = get_freq(p, p_max_size, "%.2f", 1000, obj->data.i);
+ /* OpenBSD has no such flag (SUSv2) */
+ ok = get_freq(p, p_max_size, "%.2f", 1000, obj->data.i);
#endif /* __OpenBSD */
- }
+ }
}
#ifndef __OpenBSD__
-void print_acpifan(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- get_acpi_fan(p, p_max_size);
+void print_acpifan(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ get_acpi_fan(p, p_max_size);
}
-void print_acpiacadapter(struct text_object *obj, char *p, int p_max_size)
-{
- get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
+void print_acpiacadapter(struct text_object *obj, char *p, int p_max_size) {
+ get_acpi_ac_adapter(p, p_max_size, (const char *)obj->data.opaque);
}
-void print_battery(struct text_object *obj, char *p, int p_max_size)
-{
- get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
+void print_battery(struct text_object *obj, char *p, int p_max_size) {
+ get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
}
-void print_battery_time(struct text_object *obj, char *p, int p_max_size)
-{
- get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
+void print_battery_time(struct text_object *obj, char *p, int p_max_size) {
+ get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
}
-uint8_t battery_percentage(struct text_object *obj)
-{
- return get_battery_perct(obj->data.s);
+uint8_t battery_percentage(struct text_object *obj) {
+ return get_battery_perct(obj->data.s);
}
-void print_battery_short(struct text_object *obj, char *p, int p_max_size)
-{
- get_battery_short_status(p, p_max_size, obj->data.s);
+void print_battery_short(struct text_object *obj, char *p, int p_max_size) {
+ get_battery_short_status(p, p_max_size, obj->data.s);
}
#endif /* !__OpenBSD__ */
+void print_blink(struct text_object *obj, char *p, int p_max_size) {
+ // blinking like this can look a bit ugly if the chars in the font don't have
+ // the same width
+ std::vector buf(max_user_text.get(*state));
+ static int visible = 1;
+ static int last_len = 0;
+ int i;
-void print_blink(struct text_object *obj, char *p, int p_max_size)
-{
- //blinking like this can look a bit ugly if the chars in the font don't have the same width
- std::vector buf(max_user_text.get(*state));
- static int visible = 1;
- static int last_len = 0;
- int i;
+ if (visible) {
+ generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
+ last_len = strlen(&(buf[0]));
+ } else {
+ for (i = 0; i < last_len; i++) buf[i] = ' ';
+ }
- if (visible) {
- generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
- last_len = strlen(&(buf[0]));
- } else {
- for (i = 0; i < last_len; i++)
- buf[i] = ' ';
- }
-
- snprintf(p, p_max_size, "%s", &(buf[0]));
- visible = !visible;
+ snprintf(p, p_max_size, "%s", &(buf[0]));
+ visible = !visible;
}
-void print_include(struct text_object *obj, char *p, int p_max_size)
-{
- std::vector buf(max_user_text.get(*state));
+void print_include(struct text_object *obj, char *p, int p_max_size) {
+ std::vector buf(max_user_text.get(*state));
- if (!obj->sub)
- return;
+ if (!obj->sub) return;
- generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
- snprintf(p, p_max_size, "%s", &(buf[0]));
+ generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
+ snprintf(p, p_max_size, "%s", &(buf[0]));
}
#ifdef BUILD_CURL
-void print_stock(struct text_object *obj, char *p, int p_max_size)
-{
- if( ! obj->data.s) {
- p[0] = 0;
- return;
- }
- ccurl_process_info(p, p_max_size, obj->data.s, 1);
+void print_stock(struct text_object *obj, char *p, int p_max_size) {
+ if (!obj->data.s) {
+ p[0] = 0;
+ return;
+ }
+ ccurl_process_info(p, p_max_size, obj->data.s, 1);
}
-void free_stock(struct text_object *obj)
-{
- free(obj->data.s);
-}
+void free_stock(struct text_object *obj) { free(obj->data.s); }
#endif /* BUILD_CURL */
-void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
-{
- std::vector buf(max_user_text.get(*state));
- long double bytes;
- char unit[16]; // 16 because we can also have long names (like mega-bytes)
+void print_to_bytes(struct text_object *obj, char *p, int p_max_size) {
+ std::vector buf(max_user_text.get(*state));
+ long double bytes;
+ char unit[16]; // 16 because we can also have long names (like mega-bytes)
- generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
- if(sscanf(&(buf[0]), "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16){
- if(strncasecmp("b", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes);
- else if(strncasecmp("k", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024);
- else if(strncasecmp("m", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024);
- else if(strncasecmp("g", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024 * 1024);
- else if(strncasecmp("t", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024 * 1024 * 1024);
- }
- snprintf(p, p_max_size, "%s", &(buf[0]));
+ generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
+ if (sscanf(&(buf[0]), "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16) {
+ if (strncasecmp("b", unit, 1) == 0)
+ snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes);
+ else if (strncasecmp("k", unit, 1) == 0)
+ snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024);
+ else if (strncasecmp("m", unit, 1) == 0)
+ snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
+ bytes * 1024 * 1024);
+ else if (strncasecmp("g", unit, 1) == 0)
+ snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
+ bytes * 1024 * 1024 * 1024);
+ else if (strncasecmp("t", unit, 1) == 0)
+ snprintf(&(buf[0]), max_user_text.get(*state), "%Lf",
+ bytes * 1024 * 1024 * 1024 * 1024);
+ }
+ snprintf(p, p_max_size, "%s", &(buf[0]));
}
-
-void print_updates(struct text_object *obj, char *p, int p_max_size)
-{
- (void)obj;
- snprintf(p, p_max_size, "%d", get_total_updates());
+void print_updates(struct text_object *obj, char *p, int p_max_size) {
+ (void)obj;
+ snprintf(p, p_max_size, "%d", get_total_updates());
}
-int updatenr_iftest(struct text_object *obj)
-{
- if (get_total_updates() % get_updatereset() != obj->data.i - 1)
- return 0;
- return 1;
+int updatenr_iftest(struct text_object *obj) {
+ if (get_total_updates() % get_updatereset() != obj->data.i - 1) return 0;
+ return 1;
}
diff --git a/src/common.h b/src/common.h
index 217100f2..3f4f6511 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,11 +1,10 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -28,13 +27,13 @@
#include
#include
-#include
#include
#include
-#include "text_object.h"
+#include
#include "setting.hh"
+#include "text_object.h"
-char* readfile(const char* filename, int* total_read, char showerror);
+char *readfile(const char *filename, int *total_read, char showerror);
void print_to_bytes(struct text_object *, char *, int);
@@ -60,7 +59,8 @@ void get_cpu_count(void);
double get_time(void);
/* Converts '~/...' paths to '/home/blah/...'
- * It's similar to variable_substitute, except only cheques for $HOME and ~/ in path */
+ * It's similar to variable_substitute, except only cheques for $HOME and ~/ in
+ * path */
std::string to_real_path(const std::string &source);
FILE *open_file(const char *file, int *reported);
int open_fifo(const char *file, int *reported);
@@ -77,7 +77,8 @@ extern conky::simple_config_setting no_buffers;
int open_acpi_temperature(const char *name);
double get_acpi_temperature(int fd);
-void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter);
+void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
+ const char *adapter);
void get_acpi_fan(char *, size_t);
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
int get_battery_perct(const char *bat);
@@ -123,7 +124,6 @@ void print_sysname(struct text_object *, char *, int);
void print_version(struct text_object *obj, char *p, int p_max_size);
#endif
-
void print_uptime(struct text_object *, char *, int);
void print_uptime_short(struct text_object *, char *, int);
diff --git a/src/conky.cc b/src/conky.cc
index 9b2c55ca..2e3d6df8 100644
--- a/src/conky.cc
+++ b/src/conky.cc
@@ -1,5 +1,4 @@
-/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
- * vim: ts=4 sw=4 noet ai cindent syntax=cpp
+/*
*
* Conky, a system monitor, based on torsmo
*
@@ -10,7 +9,7 @@
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
@@ -28,32 +27,32 @@
*
*/
-#include "config.h"
-#include "text_object.h"
#include "conky.h"
-#include "common.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "common.h"
+#include "config.h"
+#include "text_object.h"
#ifdef HAVE_DIRENT_H
#include
#endif /* HAVE_DIRENT_H */
-#include
#include
+#include
#ifdef HAVE_SYS_INOTIFY_H
#include
#endif /* HAVE_SYS_INOTIFY_H */
#ifdef BUILD_X11
-#include "x11.h"
#include
+#include "x11.h"
#ifdef BUILD_XDAMAGE
#include
#endif
@@ -67,12 +66,12 @@
#ifdef BUILD_NCURSES
#include
#endif
-#include
-#include
-#include
-#include
#include
#include
+#include
+#include
+#include
+#include
#if defined BUILD_WEATHER_XOAP || defined BUILD_RSS
#include
#endif
@@ -81,9 +80,9 @@
#endif
/* local headers */
-#include "core.h"
#include "build.h"
#include "colours.h"
+#include "core.h"
#include "diskio.h"
#include "exec.h"
#ifdef BUILD_X11
@@ -139,7 +138,9 @@
#ifdef BUILD_BUILTIN_CONFIG
#include "defconfig.h"
-namespace { const char builtin_config_magic[] = "==builtin=="; }
+namespace {
+const char builtin_config_magic[] = "==builtin==";
+}
#endif
#ifdef BUILD_OLD_CONFIG
@@ -147,7 +148,7 @@ namespace { const char builtin_config_magic[] = "==builtin=="; }
#endif
#ifndef S_ISSOCK
-#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
+#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
#endif
#define MAX_IF_BLOCK_DEPTH 5
@@ -159,286 +160,287 @@ namespace { const char builtin_config_magic[] = "==builtin=="; }
int global_debug_level = 0;
/* disable inotify auto reload feature if desired */
-static conky::simple_config_setting disable_auto_reload("disable_auto_reload", false, false);
+static conky::simple_config_setting disable_auto_reload(
+ "disable_auto_reload", false, false);
/* two strings for internal use */
static char *tmpstring1, *tmpstring2;
#ifdef BUILD_NCURSES
-extern WINDOW* ncurses_window;
+extern WINDOW *ncurses_window;
#endif
-enum spacer_state {
- NO_SPACER = 0,
- LEFT_SPACER,
- RIGHT_SPACER
-};
-template<>
+enum spacer_state { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
+template <>
conky::lua_traits::Map conky::lua_traits::map = {
- { "none", NO_SPACER },
- { "left", LEFT_SPACER },
- { "right", RIGHT_SPACER }
-};
-static conky::simple_config_setting use_spacer("use_spacer", NO_SPACER, false);
+ {"none", NO_SPACER}, {"left", LEFT_SPACER}, {"right", RIGHT_SPACER}};
+static conky::simple_config_setting use_spacer("use_spacer",
+ NO_SPACER, false);
/* variables holding various config settings */
-static conky::simple_config_setting short_units("short_units", false, true);
-static conky::simple_config_setting format_human_readable("format_human_readable",
- true, true);
+static conky::simple_config_setting short_units("short_units", false,
+ true);
+static conky::simple_config_setting format_human_readable(
+ "format_human_readable", true, true);
static conky::simple_config_setting out_to_stdout("out_to_console",
// Default value is false, unless we are building without X
#ifdef BUILD_X11
- false,
+ false,
#else
- true,
+ true,
#endif
- false);
-static conky::simple_config_setting out_to_stderr("out_to_stderr", false, false);
-
+ false);
+static conky::simple_config_setting out_to_stderr("out_to_stderr", false,
+ false);
int top_cpu, top_mem, top_time;
#ifdef BUILD_IOSTATS
int top_io;
#endif
int top_running;
-static conky::simple_config_setting extra_newline("extra_newline", false, false);
-static volatile sig_atomic_t g_sigterm_pending, g_sighup_pending,g_sigusr2_pending;
+static conky::simple_config_setting extra_newline("extra_newline", false,
+ false);
+static volatile sig_atomic_t g_sigterm_pending, g_sighup_pending,
+ g_sigusr2_pending;
/* Update interval */
-conky::range_config_setting update_interval("update_interval", 0.0,
- std::numeric_limits::infinity(), 3.0, true);
-conky::range_config_setting update_interval_on_battery("update_interval_on_battery", 0.0,
- std::numeric_limits::infinity(), NOBATTERY, true);
+conky::range_config_setting update_interval(
+ "update_interval", 0.0, std::numeric_limits::infinity(), 3.0, true);
+conky::range_config_setting update_interval_on_battery(
+ "update_interval_on_battery", 0.0, std::numeric_limits::infinity(),
+ NOBATTERY, true);
conky::simple_config_setting detect_battery("detect_battery",
- std::string("BAT0"), false);
+ std::string("BAT0"),
+ false);
static bool on_battery = false;
-double active_update_interval()
-{ return (on_battery?update_interval_on_battery:update_interval).get(*state); }
+double active_update_interval() {
+ return (on_battery ? update_interval_on_battery : update_interval)
+ .get(*state);
+}
-void music_player_interval_setting::lua_setter(lua::state &l, bool init)
-{
- lua::stack_sentry s(l, -2);
+void music_player_interval_setting::lua_setter(lua::state &l, bool init) {
+ lua::stack_sentry s(l, -2);
- if(l.isnil(-2)) {
- l.checkstack(1);
- l.pushnumber(update_interval.get(l));
- l.replace(-3);
- }
+ if (l.isnil(-2)) {
+ l.checkstack(1);
+ l.pushnumber(update_interval.get(l));
+ l.replace(-3);
+ }
- Base::lua_setter(l, init);
+ Base::lua_setter(l, init);
- ++s;
+ ++s;
}
music_player_interval_setting music_player_interval;
void *global_cpu = NULL;
-static conky::range_config_setting max_text_width("max_text_width", 0,
- std::numeric_limits::max(), 0, true);
+static conky::range_config_setting max_text_width(
+ "max_text_width", 0, std::numeric_limits::max(), 0, true);
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
extern kvm_t *kd;
#endif
int argc_copy;
-char** argv_copy;
+char **argv_copy;
/* prototypes for internally used functions */
static void signal_handler(int);
static void reload_config(void);
-static void print_version(void)
-{
- std::cout << _(PACKAGE_NAME" " VERSION" compiled " BUILD_DATE" for " BUILD_ARCH"\n"
- "\nCompiled in features:\n\n"
- "System config file: " SYSTEM_CONFIG_FILE"\n"
- "Package library path: " PACKAGE_LIBDIR"\n\n")
- << _("\n General:\n")
+static void print_version(void) {
+ std::cout << _(PACKAGE_NAME " " VERSION " compiled " BUILD_DATE
+ " for " BUILD_ARCH
+ "\n"
+ "\nCompiled in features:\n\n"
+ "System config file: " SYSTEM_CONFIG_FILE
+ "\n"
+ "Package library path: " PACKAGE_LIBDIR "\n\n")
+ << _("\n General:\n")
#ifdef HAVE_OPENMP
- << _(" * OpenMP\n")
+ << _(" * OpenMP\n")
#endif /* HAVE_OPENMP */
#ifdef BUILD_MATH
- << _(" * math\n")
+ << _(" * math\n")
#endif /* BUILD_MATH */
#ifdef BUILD_HDDTEMP
- << _(" * hddtemp\n")
+ << _(" * hddtemp\n")
#endif /* BUILD_HDDTEMP */
#ifdef BUILD_PORT_MONITORS
- << _(" * portmon\n")
+ << _(" * portmon\n")
#endif /* BUILD_PORT_MONITORS */
#ifdef BUILD_HTTP
- << _(" * HTTP\n")
+ << _(" * HTTP\n")
#endif
#ifdef BUILD_IPV6
- << _(" * IPv6\n")
+ << _(" * IPv6\n")
#endif /* BUILD_IPV6 */
#ifdef BUILD_IRC
- << _(" * IRC\n")
+ << _(" * IRC\n")
#endif
#ifdef BUILD_CURL
- << _(" * Curl\n")
+ << _(" * Curl\n")
#endif /* BUILD_CURL */
#ifdef BUILD_RSS
- << _(" * RSS\n")
+ << _(" * RSS\n")
#endif /* BUILD_RSS */
#ifdef BUILD_ICAL
- << _(" * ICal\n")
+ << _(" * ICal\n")
#endif /* BUILD_ICAL */
#ifdef BUILD_ICONV
- << _(" * iconv\n")
+ << _(" * iconv\n")
#endif /* BUILD_ICONV */
#ifdef BUILD_MYSQL
- << _(" * MySQL\n")
+ << _(" * MySQL\n")
#endif /* BUILD_MYSQL */
#ifdef BUILD_WEATHER_METAR
- << _(" * Weather (METAR)\n")
+ << _(" * Weather (METAR)\n")
#endif /* BUILD_WEATHER_METAR */
#ifdef BUILD_WEATHER_XOAP
- << _(" * Weather (XOAP)\n")
+ << _(" * Weather (XOAP)\n")
#endif /* BUILD_WEATHER_XOAP */
#ifdef BUILD_WLAN
- << _(" * wireless\n")
+ << _(" * wireless\n")
#endif /* BUILD_WLAN */
#ifdef BUILD_IBM
- << _(" * support for IBM/Lenovo notebooks\n")
+ << _(" * support for IBM/Lenovo notebooks\n")
#endif /* BUILD_IBM */
#ifdef BUILD_NVIDIA
- << _(" * nvidia\n")
+ << _(" * nvidia\n")
#endif /* BUILD_NVIDIA */
#ifdef BUILD_EVE
- << _(" * eve-online\n")
+ << _(" * eve-online\n")
#endif /* BUILD_EVE */
#ifdef BUILD_BUILTIN_CONFIG
- << _(" * builtin default configuration\n")
+ << _(" * builtin default configuration\n")
#endif /* BUILD_BUILTIN_CONFIG */
#ifdef BUILD_OLD_CONFIG
- << _(" * old configuration syntax\n")
+ << _(" * old configuration syntax\n")
#endif /* BUILD_OLD_CONFIG */
#ifdef BUILD_IMLIB2
- << _(" * Imlib2\n")
+ << _(" * Imlib2\n")
#endif /* BUILD_IMLIB2 */
#ifdef HAVE_SOME_SOUNDCARD_H
- << _(" * OSS mixer support\n")
+ << _(" * OSS mixer support\n")
#endif /* HAVE_SOME_SOUNDCARD_H */
#ifdef BUILD_MIXER_ALSA
- << _(" * ALSA mixer support\n")
+ << _(" * ALSA mixer support\n")
#endif /* BUILD_MIXER_ALSA */
#ifdef BUILD_APCUPSD
- << _(" * apcupsd\n")
+ << _(" * apcupsd\n")
#endif /* BUILD_APCUPSD */
#ifdef BUILD_IOSTATS
- << _(" * iostats\n")
+ << _(" * iostats\n")
#endif /* BUILD_IOSTATS */
#ifdef BUILD_NCURSES
- << _(" * ncurses\n")
+ << _(" * ncurses\n")
#endif /* BUILD_NCURSES */
#ifdef BUILD_I18N
- << _(" * Internationalization support\n")
+ << _(" * Internationalization support\n")
#endif
#ifdef BUILD_PULSEAUDIO
- << _(" * PulseAudio\n")
+ << _(" * PulseAudio\n")
#endif /* BUIL_PULSEAUDIO */
#ifdef DEBUG
- << _(" * Debugging extensions\n")
+ << _(" * Debugging extensions\n")
#endif
#if defined BUILD_LUA_CAIRO || defined BUILD_LUA_IMLIB2 || BUILD_LUA_RSVG
- << _("\n Lua bindings:\n")
+ << _("\n Lua bindings:\n")
#endif
#ifdef BUILD_LUA_CAIRO
- << _(" * Cairo\n")
+ << _(" * Cairo\n")
#endif /* BUILD_LUA_CAIRO */
#ifdef BUILD_LUA_IMLIB2
- << _(" * Imlib2\n")
+ << _(" * Imlib2\n")
#endif /* BUILD_LUA_IMLIB2 */
#ifdef BUILD_LUA_RSVG
- << _(" * RSVG\n")
+ << _(" * RSVG\n")
#endif /* BUILD_LUA_RSVG */
#ifdef BUILD_X11
- << _(" X11:\n")
-# ifdef BUILD_XDAMAGE
- << _(" * Xdamage extension\n")
-# endif /* BUILD_XDAMAGE */
-# ifdef BUILD_XINERAMA
- << _(" * Xinerama extension (virtual display)\n")
-# endif /* BUILD_XINERAMA */
-# ifdef BUILD_XSHAPE
- << _(" * Xshape extension (click through)\n")
-# endif /* BUILD_XSHAPE */
-# ifdef BUILD_XDBE
- << _(" * XDBE (double buffer extension)\n")
-# endif /* BUILD_XDBE */
-# ifdef BUILD_XFT
- << _(" * Xft\n")
-# endif /* BUILD_XFT */
-# ifdef BUILD_ARGB
- << _(" * ARGB visual\n")
-# endif /* BUILD_ARGB */
+ << _(" X11:\n")
+#ifdef BUILD_XDAMAGE
+ << _(" * Xdamage extension\n")
+#endif /* BUILD_XDAMAGE */
+#ifdef BUILD_XINERAMA
+ << _(" * Xinerama extension (virtual display)\n")
+#endif /* BUILD_XINERAMA */
+#ifdef BUILD_XSHAPE
+ << _(" * Xshape extension (click through)\n")
+#endif /* BUILD_XSHAPE */
+#ifdef BUILD_XDBE
+ << _(" * XDBE (double buffer extension)\n")
+#endif /* BUILD_XDBE */
+#ifdef BUILD_XFT
+ << _(" * Xft\n")
+#endif /* BUILD_XFT */
+#ifdef BUILD_ARGB
+ << _(" * ARGB visual\n")
+#endif /* BUILD_ARGB */
#ifdef OWN_WINDOW
- << _(" * Own window\n")
+ << _(" * Own window\n")
#endif
#endif /* BUILD_X11 */
-#if defined BUILD_AUDACIOUS || defined BUILD_BMPX || defined BUILD_CMUS || defined BUILD_MPD || defined BUILD_MOC || defined BUILD_XMMS2
- << _("\n Music detection:\n")
+#if defined BUILD_AUDACIOUS || defined BUILD_BMPX || defined BUILD_CMUS || \
+ defined BUILD_MPD || defined BUILD_MOC || defined BUILD_XMMS2
+ << _("\n Music detection:\n")
#endif
#ifdef BUILD_AUDACIOUS
- << _(" * Audacious\n")
+ << _(" * Audacious\n")
#endif /* BUILD_AUDACIOUS */
#ifdef BUILD_BMPX
- << _(" * BMPx\n")
+ << _(" * BMPx\n")
#endif /* BUILD_BMPX */
#ifdef BUILD_CMUS
- << _(" * CMUS\n")
+ << _(" * CMUS\n")
#endif /* BUILD_CMUS */
#ifdef BUILD_MPD
- << _(" * MPD\n")
+ << _(" * MPD\n")
#endif /* BUILD_MPD */
#ifdef BUILD_MOC
- << _(" * MOC\n")
+ << _(" * MOC\n")
#endif /* BUILD_MOC */
#ifdef BUILD_XMMS2
- << _(" * XMMS2\n")
+ << _(" * XMMS2\n")
#endif /* BUILD_XMMS2 */
- << _("\n Default values:\n")
- << " * Netdevice: " DEFAULTNETDEV"\n"
- << " * Local configfile: " CONFIG_FILE"\n"
+ << _("\n Default values:\n") << " * Netdevice: " DEFAULTNETDEV "\n"
+ << " * Local configfile: " CONFIG_FILE "\n"
#ifdef BUILD_I18N
- << " * Localedir: " LOCALE_DIR"\n"
+ << " * Localedir: " LOCALE_DIR "\n"
#endif
#ifdef BUILD_HTTP
- << " * HTTP-port: " << HTTPPORT << "\n"
+ << " * HTTP-port: " << HTTPPORT << "\n"
#endif
- << " * Maximum netdevices: " << MAX_NET_INTERFACES << "\n"
- << " * Maximum text size: " << MAX_USER_TEXT_DEFAULT << "\n"
- << " * Size text buffer: " << DEFAULT_TEXT_BUFFER_SIZE << "\n"
- ;
+ << " * Maximum netdevices: " << MAX_NET_INTERFACES << "\n"
+ << " * Maximum text size: " << MAX_USER_TEXT_DEFAULT << "\n"
+ << " * Size text buffer: " << DEFAULT_TEXT_BUFFER_SIZE << "\n";
}
-
-static const char *suffixes[] = {
- _nop("B"), _nop("KiB"), _nop("MiB"), _nop("GiB"), _nop("TiB"), _nop("PiB"), ""
-};
-
+static const char *suffixes[] = {_nop("B"), _nop("KiB"), _nop("MiB"),
+ _nop("GiB"), _nop("TiB"), _nop("PiB"),
+ ""};
#ifdef BUILD_X11
static void X11_create_window(void);
struct _x11_stuff_s {
- Region region;
+ Region region;
#ifdef BUILD_XDAMAGE
- Damage damage;
- XserverRegion region2, part;
- int event_base, error_base;
+ Damage damage;
+ XserverRegion region2, part;
+ int event_base, error_base;
#endif
} x11_stuff;
/* text size */
-static int text_start_x, text_start_y; /* text start position in window */
+static int text_start_x, text_start_y; /* text start position in window */
static int text_offset_x, text_offset_y; /* offset for start position */
-static int text_width = 1, text_height = 1; /* initially 1 so no zero-sized window is created */
+static int text_width = 1,
+ text_height = 1; /* initially 1 so no zero-sized window is created */
#endif /* BUILD_X11 */
@@ -450,149 +452,165 @@ struct information info;
std::string current_config;
/* set to 1 if you want all text to be in uppercase */
-static conky::simple_config_setting stuff_in_uppercase("uppercase", false, true);
+static conky::simple_config_setting stuff_in_uppercase("uppercase", false,
+ true);
/* Run how many times? */
-static conky::range_config_setting total_run_times("total_run_times", 0,
- std::numeric_limits::max(), 0, true);
+static conky::range_config_setting total_run_times(
+ "total_run_times", 0, std::numeric_limits::max(), 0, true);
/* fork? */
-static conky::simple_config_setting fork_to_background("background", false, false);
+static conky::simple_config_setting fork_to_background("background",
+ false, false);
/* set to 0 after the first time conky is run, so we don't fork again after the
* first forking */
static int first_pass = 1;
-conky::range_config_setting cpu_avg_samples("cpu_avg_samples", 1, 14, 2, true);
-conky::range_config_setting net_avg_samples("net_avg_samples", 1, 14, 2, true);
-conky::range_config_setting diskio_avg_samples("diskio_avg_samples", 1, 14, 2, true);
+conky::range_config_setting cpu_avg_samples("cpu_avg_samples", 1, 14, 2,
+ true);
+conky::range_config_setting net_avg_samples("net_avg_samples", 1, 14, 2,
+ true);
+conky::range_config_setting diskio_avg_samples("diskio_avg_samples", 1, 14,
+ 2, true);
/* filenames for output */
-static conky::simple_config_setting overwrite_file("overwrite_file",
- std::string(), true);
+static conky::simple_config_setting overwrite_file(
+ "overwrite_file", std::string(), true);
static FILE *overwrite_fpointer = NULL;
static conky::simple_config_setting append_file("append_file",
- std::string(), true);
+ std::string(),
+ true);
static FILE *append_fpointer = NULL;
#ifdef BUILD_HTTP
std::string webpage;
struct MHD_Daemon *httpd;
-static conky::simple_config_setting http_refresh("http_refresh", false, true);
+static conky::simple_config_setting http_refresh("http_refresh", false,
+ true);
-int sendanswer(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) {
- struct MHD_Response *response = MHD_create_response_from_data(webpage.length(), (void*) webpage.c_str(), MHD_NO, MHD_NO);
- int ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
- MHD_destroy_response(response);
- if(cls || url || method || version || upload_data || upload_data_size || con_cls) {} //make compiler happy
- return ret;
+int sendanswer(void *cls, struct MHD_Connection *connection, const char *url,
+ const char *method, const char *version, const char *upload_data,
+ size_t *upload_data_size, void **con_cls) {
+ struct MHD_Response *response = MHD_create_response_from_data(
+ webpage.length(), (void *)webpage.c_str(), MHD_NO, MHD_NO);
+ int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
+ MHD_destroy_response(response);
+ if (cls || url || method || version || upload_data || upload_data_size ||
+ con_cls) {
+ } // make compiler happy
+ return ret;
}
-class out_to_http_setting: public conky::simple_config_setting {
- typedef conky::simple_config_setting Base;
+class out_to_http_setting : public conky::simple_config_setting {
+ typedef conky::simple_config_setting Base;
-protected:
- virtual void lua_setter(lua::state &l, bool init)
- {
- lua::stack_sentry s(l, -2);
+ protected:
+ virtual void lua_setter(lua::state &l, bool init) {
+ lua::stack_sentry s(l, -2);
- Base::lua_setter(l, init);
+ Base::lua_setter(l, init);
- if(init && do_convert(l, -1).first) {
- httpd = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, HTTPPORT,
- NULL, NULL, &sendanswer, NULL, MHD_OPTION_END);
- }
-
- ++s;
+ if (init && do_convert(l, -1).first) {
+ httpd = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, HTTPPORT, NULL, NULL,
+ &sendanswer, NULL, MHD_OPTION_END);
}
- virtual void cleanup(lua::state &l)
- {
- lua::stack_sentry s(l, -1);
+ ++s;
+ }
- if(do_convert(l, -1).first) {
- MHD_stop_daemon(httpd);
- httpd = NULL;
- }
+ virtual void cleanup(lua::state &l) {
+ lua::stack_sentry s(l, -1);
- l.pop();
- }
+ if (do_convert(l, -1).first) {
+ MHD_stop_daemon(httpd);
+ httpd = NULL;
+ }
-public:
- out_to_http_setting()
- : Base("out_to_http", false, false)
- {}
+ l.pop();
+ }
+
+ public:
+ out_to_http_setting() : Base("out_to_http", false, false) {}
};
static out_to_http_setting out_to_http;
#endif
#ifdef BUILD_X11
-static conky::simple_config_setting show_graph_scale("show_graph_scale", false, false);
-static conky::simple_config_setting show_graph_range("show_graph_range", false, false);
+static conky::simple_config_setting show_graph_scale("show_graph_scale",
+ false, false);
+static conky::simple_config_setting show_graph_range("show_graph_range",
+ false, false);
/* Position on the screen */
static conky::simple_config_setting gap_x("gap_x", 5, true);
static conky::simple_config_setting gap_y("gap_y", 60, true);
/* border */
-static conky::simple_config_setting draw_borders("draw_borders", false, false);
-static conky::simple_config_setting draw_graph_borders("draw_graph_borders", true, false);
+static conky::simple_config_setting draw_borders("draw_borders", false,
+ false);
+static conky::simple_config_setting