From 4936c7492c9223637981a764086b115048989456 Mon Sep 17 00:00:00 2001 From: Tin Date: Fri, 10 Nov 2023 12:31:01 +0100 Subject: [PATCH] Provide a notice when build options get disabled Reformat files and hope it invalidates CI cache :) Signed-off-by: Tin --- .github/workflows/build-and-test-linux.yaml | 1 + CMakeLists.txt | 2 +- cmake/ConkyBuildOptions.cmake | 162 +++++++++----------- cmake/ConkyPlatformChecks.cmake | 16 ++ cmake/DependentOption.cmake | 36 +++++ src/display-wayland.cc | 124 ++++++--------- src/display-x11.cc | 2 +- src/llua.cc | 15 +- src/logging.h | 13 +- src/mouse-events.cc | 40 ++--- src/mouse-events.h | 66 +++++--- src/x11.cc | 139 +++++++++-------- src/x11.h | 22 +-- 13 files changed, 336 insertions(+), 302 deletions(-) create mode 100644 cmake/DependentOption.cmake diff --git a/.github/workflows/build-and-test-linux.yaml b/.github/workflows/build-and-test-linux.yaml index 1a2164e5..92bdc876 100644 --- a/.github/workflows/build-and-test-linux.yaml +++ b/.github/workflows/build-and-test-linux.yaml @@ -140,6 +140,7 @@ jobs: -DBUILD_MYSQL=ON \ -DBUILD_NVIDIA=ON \ -DBUILD_PULSEAUDIO=ON \ + -DBUILD_CURL=ON \ -DBUILD_RSS=ON \ -DBUILD_TESTS=ON \ -DBUILD_WLAN=ON \ diff --git a/CMakeLists.txt b/CMakeLists.txt index bf2b2d94..186a87ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ # along with this program. If not, see . # -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.17) project(conky) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 1a485276..97c6eba8 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -18,6 +18,9 @@ # along with this program. If not, see . # +include(CMakeDependentOption) +include(DependentOption) + if(NOT CMAKE_BUILD_TYPE) if(MAINTAINER_MODE) set( @@ -97,33 +100,26 @@ set(DEFAULT_TEXT_BUFFER_SIZE "256" set(MAX_NET_INTERFACES "256" CACHE STRING "Maximum number of network devices") # Platform specific options Linux only -if(OS_LINUX) - option(BUILD_PORT_MONITORS "Build TCP portmon support" true) - option(BUILD_IBM "Support for IBM/Lenovo notebooks" true) - option(BUILD_HDDTEMP "Support for hddtemp" true) - option(BUILD_IPV6 "Enable if you want IPv6 support" true) - if(BUILD_X11) - # nvidia may also work on FreeBSD, not sure - option(BUILD_NVIDIA "Enable nvidia support" false) - endif(BUILD_X11) -else(OS_LINUX) - set(BUILD_PORT_MONITORS false) - set(BUILD_IBM false) - set(BUILD_HDDTEMP false) - set(BUILD_NVIDIA false) - set(BUILD_IPV6 false) -endif(OS_LINUX) +cmake_dependent_option(BUILD_PORT_MONITORS "Build TCP portmon support" true + "OS_LINUX" false) +cmake_dependent_option(BUILD_IBM "Support for IBM/Lenovo notebooks" true + "OS_LINUX" false) +cmake_dependent_option(BUILD_HDDTEMP "Support for hddtemp" true + "OS_LINUX" false) +cmake_dependent_option(BUILD_IPV6 "Enable if you want IPv6 support" true + "OS_LINUX" false) +# nvidia may also work on FreeBSD, not sure +cmake_dependent_option(BUILD_NVIDIA "Enable nvidia support" false + "OS_LINUX" false) # macOS Only -if(OS_DARWIN) - option( - BUILD_IPGFREQ - "Enable cpu freq calculation based on IntelĀ® Power Gadget; otherwise use constant factory value" - false) -endif(OS_DARWIN) +cmake_dependent_option( + BUILD_IPGFREQ + "Enable cpu freq calculation based on IntelĀ® Power Gadget; otherwise use constant factory value" + false + "OS_DARWIN" false) # Optional features etc -# option(BUILD_WLAN "Enable wireless support" false) @@ -137,55 +133,53 @@ option(BUILD_OLD_CONFIG "Enable support for the old syntax of configurations" option(BUILD_MATH "Enable math support" true) option(BUILD_NCURSES "Enable ncurses support" true) -if(BUILD_NCURSES) - option( - LEAKFREE_NCURSES - "Enable to hide false ncurses-memleaks in valgrind (works only when ncurses is compiled with --disable-leaks)" - false) -else(BUILD_NCURSES) - set( - LEAKFREE_NCURSES false - CACHE - BOOL - "Enable to hide false ncurses-memleaks in valgrind (works only when ncurses is compiled with --disable-leaks)" - FORCE) -endif(BUILD_NCURSES) + +dependent_option(LEAKFREE_NCURSES + "Enable to hide false ncurses-memleaks in valgrind (works only when ncurses is compiled with --disable-leaks)" + false + "BUILD_NCURSES" false + "LEAKFREE_NCURSES requires ncurses") option(BUILD_WAYLAND "Build Wayland support" false) option(BUILD_X11 "Build X11 support" true) -if(BUILD_X11) - option(OWN_WINDOW "Enable own_window support" true) - # Mac Fix - if(OS_DARWIN) - option(BUILD_XDAMAGE "Build Xdamage support" false) - option(BUILD_XFIXES "Build Xfixes support" false) - else(OS_DARWIN) - option(BUILD_XDAMAGE "Build Xdamage support" true) - option(BUILD_XFIXES "Build Xfixes support" true) - endif(OS_DARWIN) +dependent_option(OWN_WINDOW "Enable running conky in a dedicated window" true + "BUILD_X11" false + "Dedicated window mode only works on X11") - option(BUILD_XINERAMA "Build Xinerama support" true) - option(BUILD_XDBE "Build Xdbe (double-buffer) support" true) - option(BUILD_XFT "Build Xft (freetype fonts) support" true) - option(BUILD_IMLIB2 "Enable Imlib2 support" true) - option(BUILD_XSHAPE "Enable Xshape support" true) +# On MacOS these cause issues so they're disabled by default +if(OS_DARWIN) + dependent_option(BUILD_XDAMAGE "Build Xdamage support" false + "BUILD_X11" false + "Xdamage support requires X11") + dependent_option(BUILD_XFIXES "Build Xfixes support" false + "BUILD_X11" false + "Xfixes support requires X11") +else() + dependent_option(BUILD_XDAMAGE "Build Xdamage support" true + "BUILD_X11" false + "Xdamage support requires X11") + dependent_option(BUILD_XFIXES "Build Xfixes support" true + "BUILD_X11" false + "Xfixes support requires X11") +endif(OS_DARWIN) - option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false) -else(BUILD_X11) - set(OWN_WINDOW false CACHE BOOL "Enable own_window support" FORCE) - set(BUILD_XDAMAGE false CACHE BOOL "Build Xdamage support" FORCE) - set(BUILD_XFIXES false CACHE BOOL "Build Xfixes support" FORCE) - set(BUILD_XINERAMA false CACHE BOOL "Build Xinerama support" FORCE) - set(BUILD_XDBE false CACHE BOOL "Build Xdbe (double-buffer) support" FORCE) - set(BUILD_XFT false CACHE BOOL "Build Xft (freetype fonts) support" FORCE) - set(BUILD_IMLIB2 false CACHE BOOL "Enable Imlib2 support" FORCE) - set(BUILD_XSHAPE false CACHE BOOL "Enable Xshape support" FORCE) - - set(BUILD_LUA_IMLIB2 false CACHE BOOL "Build Imlib2 bindings for Lua" FORCE) - set(BUILD_NVIDIA false) -endif(BUILD_X11) +dependent_option(BUILD_XINERAMA "Build Xinerama support" true + "BUILD_X11" false + "Xinerama support requires X11") +dependent_option(BUILD_XDBE "Build Xdbe (double-buffer) support" true + "BUILD_X11" false + "Xdbe based double-buffering requires X11") +dependent_option(BUILD_XFT "Build Xft (freetype fonts) support" true + "BUILD_X11" false + "Xft (freetype font) support requires X11") +dependent_option(BUILD_IMLIB2 "Enable Imlib2 support" true + "BUILD_X11" false + "Imlib2 support requires X11") +dependent_option(BUILD_XSHAPE "Enable Xshape support" true + "BUILD_X11" false + "Xshape support requires X11") # if we build with any GUI support if(BUILD_X11) @@ -195,25 +189,22 @@ if(BUILD_WAYLAND) set(BUILD_GUI true) endif(BUILD_WAYLAND) -if(BUILD_GUI) - option(BUILD_MOUSE_EVENTS "Enable mouse event support" true) -endif(BUILD_GUI) +dependent_option(BUILD_MOUSE_EVENTS "Enable mouse event support" true + "BUILD_WAYLAND OR OWN_WINDOW" false + "Mouse event support requires Wayland or OWN_WINDOW enabled") +dependent_option(BUILD_XINPUT "Build Xinput 2 support" true + "BUILD_X11;BUILD_MOUSE_EVENTS" false + "Xinput 2 support requires X11 and BUILD_MOUSE_EVENTS enabled") -if(BUILD_GUI AND BUILD_MOUSE_EVENTS) - option(BUILD_XINPUT "Build Xinput 2 support" true) -else(BUILD_GUI AND BUILD_MOUSE_EVENTS) - set(BUILD_XINPUT false CACHE BOOL "Build Xinput 2 support" FORCE) -endif(BUILD_GUI AND BUILD_MOUSE_EVENTS) - -if(OWN_WINDOW) - option(BUILD_ARGB "Build ARGB (real transparency) support" true) -else(OWN_WINDOW) - set(BUILD_ARGB false - CACHE BOOL "Build ARGB (real transparency) support" - FORCE) -endif(OWN_WINDOW) +dependent_option(BUILD_ARGB "Build ARGB (real transparency) support" true + "OWN_WINDOW" false + "ARGB support requires OWN_WINDOW enabled") +# Lua library options option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false) +dependent_option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false + "BUILD_X11;BUILD_IMLIB2" false + "Imlib2 Lua bindings require X11 and Imlib2") option(BUILD_LUA_RSVG "Build rsvg bindings for Lua" false) option(BUILD_AUDACIOUS "Build audacious (music player) support" false) @@ -228,12 +219,9 @@ option(BUILD_XMMS2 "Enable if you want XMMS2 (music player) support" false) option(BUILD_CURL "Enable if you want Curl support" false) -option(BUILD_RSS "Enable if you want RSS support" false) - -if(BUILD_RSS) - # if RSS is enabled, curl is required - set(BUILD_CURL true) -endif(BUILD_RSS) +dependent_option(BUILD_RSS "Enable if you want RSS support" false + "BUILD_CURL" false + "RSS depends on Curl support") option(BUILD_APCUPSD "Enable APCUPSD support" true) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 0804afe1..f6dab39e 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -59,6 +59,8 @@ set(INCLUDE_SEARCH_PATH /usr/include /usr/local/include) # Set system vars if(CMAKE_SYSTEM_NAME MATCHES "Linux") set(OS_LINUX true) +else(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(OS_LINUX false) endif(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") @@ -68,33 +70,47 @@ if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(BUILD_IRC) set(conky_libs ${conky_libs} -lssl -lcrypto) endif(BUILD_IRC) +else(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set(OS_FREEBSD false) endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "DragonFly") set(OS_DRAGONFLY true) set(conky_libs ${conky_libs} -ldevstat) +else(CMAKE_SYSTEM_NAME MATCHES "DragonFly") + set(OS_DRAGONFLY false) endif(CMAKE_SYSTEM_NAME MATCHES "DragonFly") if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") set(OS_OPENBSD true) +else(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") + set(OS_OPENBSD false) endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") if(CMAKE_SYSTEM_NAME MATCHES "SunOS") set(OS_SOLARIS true) set(conky_libs ${conky_libs} -lkstat) +else(CMAKE_SYSTEM_NAME MATCHES "SunOS") + set(OS_SOLARIS false) endif(CMAKE_SYSTEM_NAME MATCHES "SunOS") if(CMAKE_SYSTEM_NAME MATCHES "NetBSD") set(OS_NETBSD true) +else(CMAKE_SYSTEM_NAME MATCHES "NetBSD") + set(OS_NETBSD false) endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD") if(CMAKE_SYSTEM_NAME MATCHES "Haiku") set(OS_HAIKU true) set(conky_libs ${conky_libs} -lnetwork -lintl) +else(CMAKE_SYSTEM_NAME MATCHES "Haiku") + set(OS_HAIKU false) endif(CMAKE_SYSTEM_NAME MATCHES "Haiku") if(CMAKE_SYSTEM_NAME MATCHES "Darwin") set(OS_DARWIN true) +else(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(OS_DARWIN false) endif(CMAKE_SYSTEM_NAME MATCHES "Darwin") if(NOT OS_LINUX diff --git a/cmake/DependentOption.cmake b/cmake/DependentOption.cmake new file mode 100644 index 00000000..bd651d04 --- /dev/null +++ b/cmake/DependentOption.cmake @@ -0,0 +1,36 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +DependentOption +-------------------- +Roughly based on CMakeDependentOption: +https://github.com/Kitware/CMake/blob/master/Modules/CMakeDependentOption.cmake + +Modified to so it produces warnings instead of hiding an option completely and +sets a default value. + +Argument meaning and order are the same, and there's an additional (warn) +argument which is the message printed if the end-user enabled a feature which +isn't "possible". +#]=======================================================================] + +macro(DEPENDENT_OPTION option doc default depends else warn) + set(${option}_POSSIBLE 1) + foreach(d ${depends}) + cmake_language(EVAL CODE " + if (${d}) + else() + set(${option}_POSSIBLE 0) + endif()" + ) + endforeach() + option(${option} "${doc}" "${default}") + if(NOT ${option}_POSSIBLE) + if(NOT ${option} MATCHES ${else}) + message(NOTICE "${warn}; setting to '${else}'.") + endif() + set(${option} ${else} CACHE BOOL "${doc}" FORCE) + endif() + unset(${option}_POSSIBLE) +endmacro() diff --git a/src/display-wayland.cc b/src/display-wayland.cc index 137b40e9..764b7d77 100644 --- a/src/display-wayland.cc +++ b/src/display-wayland.cc @@ -24,7 +24,7 @@ * */ -#include +#include <> #ifdef BUILD_WAYLAND #include @@ -62,9 +62,9 @@ #include "fonts.h" #endif #ifdef BUILD_MOUSE_EVENTS -#include "mouse-events.h" -#include #include +#include +#include "mouse-events.h" #endif #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -429,11 +429,11 @@ void window_layer_surface_set_size(struct window *window) { } #ifdef BUILD_MOUSE_EVENTS -static std::map> last_known_positions{}; +static std::map> last_known_positions{}; static void on_pointer_enter(void *data, wl_pointer *pointer, uint32_t serial, - wl_surface *surface, wl_fixed_t surface_x, - wl_fixed_t surface_y) { + wl_surface *surface, wl_fixed_t surface_x, + wl_fixed_t surface_y) { auto w = reinterpret_cast(data); size_t x = static_cast(wl_fixed_to_double(surface_x)); @@ -443,20 +443,12 @@ static void on_pointer_enter(void *data, wl_pointer *pointer, uint32_t serial, size_t abs_x = w->rectangle.x + x; size_t abs_y = w->rectangle.y + y; - mouse_crossing_event event { - mouse_event_t::AREA_ENTER, - x, - y, - abs_x, - abs_y - }; + mouse_crossing_event event{mouse_event_t::AREA_ENTER, x, y, abs_x, abs_y}; llua_mouse_hook(event); } -static void on_pointer_leave(void *data, - struct wl_pointer *pointer, - uint32_t serial, - struct wl_surface *surface) { +static void on_pointer_leave(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface) { auto w = reinterpret_cast(data); std::array last = last_known_positions[pointer]; @@ -465,21 +457,13 @@ static void on_pointer_leave(void *data, size_t abs_x = w->rectangle.x + x; size_t abs_y = w->rectangle.y + y; - mouse_crossing_event event { - mouse_event_t::AREA_LEAVE, - x, - y, - abs_x, - abs_y - }; + mouse_crossing_event event{mouse_event_t::AREA_LEAVE, x, y, abs_x, abs_y}; llua_mouse_hook(event); } -static void on_pointer_motion(void *data, - struct wl_pointer *pointer, - uint32_t _time, - wl_fixed_t surface_x, - wl_fixed_t surface_y) { +static void on_pointer_motion(void *data, struct wl_pointer *pointer, + uint32_t _time, wl_fixed_t surface_x, + wl_fixed_t surface_y) { auto w = reinterpret_cast(data); size_t x = static_cast(wl_fixed_to_double(surface_x)); @@ -489,21 +473,13 @@ static void on_pointer_motion(void *data, size_t abs_x = w->rectangle.x + x; size_t abs_y = w->rectangle.y + y; - mouse_move_event event { - x, - y, - abs_x, - abs_y - }; + mouse_move_event event{x, y, abs_x, abs_y}; llua_mouse_hook(event); } -static void on_pointer_button(void *data, - struct wl_pointer *pointer, - uint32_t serial, - uint32_t time, - uint32_t button, - uint32_t state) { +static void on_pointer_button(void *data, struct wl_pointer *pointer, + uint32_t serial, uint32_t time, uint32_t button, + uint32_t state) { auto w = reinterpret_cast(data); std::array last = last_known_positions[pointer]; @@ -512,13 +488,9 @@ static void on_pointer_button(void *data, size_t abs_x = w->rectangle.x + x; size_t abs_y = w->rectangle.y + y; - mouse_button_event event { - mouse_event_t::MOUSE_RELEASE, - x, - y, - abs_x, - abs_y, - static_cast(button), + mouse_button_event event{ + mouse_event_t::MOUSE_RELEASE, x, y, abs_x, abs_y, + static_cast(button), }; switch (static_cast(state)) { @@ -534,11 +506,8 @@ static void on_pointer_button(void *data, llua_mouse_hook(event); } -void on_pointer_axis(void *data, - struct wl_pointer *pointer, - uint32_t time, - uint32_t axis, - wl_fixed_t value) { +void on_pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, + uint32_t axis, wl_fixed_t value) { if (value == 0) return; auto w = reinterpret_cast(data); @@ -549,20 +518,18 @@ void on_pointer_axis(void *data, size_t abs_x = w->rectangle.x + x; size_t abs_y = w->rectangle.y + y; - mouse_scroll_event event { - x, - y, - abs_x, - abs_y, - scroll_direction_t::SCROLL_UP, + mouse_scroll_event event{ + x, y, abs_x, abs_y, scroll_direction_t::SCROLL_UP, }; switch (static_cast(axis)) { case WL_POINTER_AXIS_VERTICAL_SCROLL: - event.direction = value > 0 ? scroll_direction_t::SCROLL_DOWN : scroll_direction_t::SCROLL_UP; + event.direction = value > 0 ? scroll_direction_t::SCROLL_DOWN + : scroll_direction_t::SCROLL_UP; break; case WL_POINTER_AXIS_HORIZONTAL_SCROLL: - event.direction = value > 0 ? scroll_direction_t::SCROLL_RIGHT : scroll_direction_t::SCROLL_LEFT; + event.direction = value > 0 ? scroll_direction_t::SCROLL_RIGHT + : scroll_direction_t::SCROLL_LEFT; break; default: return; @@ -570,24 +537,27 @@ void on_pointer_axis(void *data, llua_mouse_hook(event); } -static void seat_capability_listener (void *data, wl_seat *seat, uint32_t capability_int) { - wl_seat_capability capabilities = static_cast(capability_int); +static void seat_capability_listener(void *data, wl_seat *seat, + uint32_t capability_int) { + wl_seat_capability capabilities = + static_cast(capability_int); if (wl_globals.seat == seat) { if ((capabilities & WL_SEAT_CAPABILITY_POINTER) > 0) { wl_globals.pointer = wl_seat_get_pointer(seat); - static wl_pointer_listener listener { - .enter = on_pointer_enter, - .leave = on_pointer_leave, - .motion = on_pointer_motion, - .button = on_pointer_button, - .axis = on_pointer_axis, + static wl_pointer_listener listener{ + .enter = on_pointer_enter, + .leave = on_pointer_leave, + .motion = on_pointer_motion, + .button = on_pointer_button, + .axis = on_pointer_axis, }; wl_pointer_add_listener(wl_globals.pointer, &listener, data); } } } -static void seat_name_listener(void *data, struct wl_seat *wl_seat, const char *name) {} +static void seat_name_listener(void *data, struct wl_seat *wl_seat, + const char *name) {} #endif /* BUILD_MOUSE_EVENTS */ bool display_output_wayland::initialize() { @@ -619,13 +589,13 @@ bool display_output_wayland::initialize() { zwlr_layer_surface_v1_add_listener(global_window->layer_surface, &layer_surface_listener, nullptr); - #ifdef BUILD_MOUSE_EVENTS - wl_seat_listener listener { - .capabilities = seat_capability_listener, - .name = seat_name_listener, +#ifdef BUILD_MOUSE_EVENTS + wl_seat_listener listener{ + .capabilities = seat_capability_listener, + .name = seat_name_listener, }; wl_seat_add_listener(wl_globals.seat, &listener, global_window); - #endif /* BUILD_MOUSE_EVENTS */ +#endif /* BUILD_MOUSE_EVENTS */ wl_surface_commit(global_window->surface); wl_display_roundtrip(global_display); @@ -1046,8 +1016,8 @@ void display_output_wayland::load_fonts(bool utf8) { // pango_fc_font_description_from_pattern requires a FAMILY to be set, // so set an empty one if none is present. FcValue dummy; - if (FcPatternGet (fc_pattern, FC_FAMILY, 0, &dummy) != FcResultMatch) { - FcPatternAddString (fc_pattern, FC_FAMILY, (FcChar8 *) ""); + if (FcPatternGet(fc_pattern, FC_FAMILY, 0, &dummy) != FcResultMatch) { + FcPatternAddString(fc_pattern, FC_FAMILY, (FcChar8 *)""); } pango_font_entry.desc = pango_fc_font_description_from_pattern(fc_pattern, true); diff --git a/src/display-x11.cc b/src/display-x11.cc index 2c139f7b..6f7beb21 100644 --- a/src/display-x11.cc +++ b/src/display-x11.cc @@ -382,7 +382,7 @@ bool display_output_x11::main_loop_wait(double t) { XNextEvent(display, &ev); -#if defined(BUILD_MOUSE_EVENTS) && defined(BUILD_XINPUT) +#if defined(OWN_WINDOW) && defined(BUILD_MOUSE_EVENTS) && defined(BUILD_XINPUT) // no need to check whether these events have been consumed because // they're global and shouldn't be propagated if (ev.type == GenericEvent && ev.xcookie.extension == window.xi_opcode) { diff --git a/src/llua.cc b/src/llua.cc index f9d346c5..08b0d9c2 100644 --- a/src/llua.cc +++ b/src/llua.cc @@ -210,9 +210,9 @@ void llua_init() { #endif /* BUILD_X11 */ } -inline bool file_exists (const char *path) { - struct stat buffer; - return (stat (path, &buffer) == 0); +inline bool file_exists(const char *path) { + struct stat buffer; + return (stat(path, &buffer) == 0); } void llua_load(const char *script) { @@ -522,14 +522,17 @@ bool llua_mouse_hook(const EventT &ev) { } else { hook_name = "conky_" + raw_hook_name; } - + int ty = lua_getglobal(lua_L, hook_name.c_str()); if (ty == LUA_TNIL) { int ty_raw = lua_getglobal(lua_L, raw_hook_name.c_str()); if (ty_raw == LUA_TFUNCTION) { - // TODO: (1.22.0) Force conky_ prefix on use_mouse_hook like llua_do_call does + // TODO: (1.22.0) Force conky_ prefix on use_mouse_hook like llua_do_call + // does // - keep only else case, remove ty_raw and make hook_name const. - NORM_ERR("llua_mouse_hook: hook %s declaration is missing 'conky_' prefix", raw_hook_name.c_str()); + NORM_ERR( + "llua_mouse_hook: hook %s declaration is missing 'conky_' prefix", + raw_hook_name.c_str()); hook_name = raw_hook_name; ty = ty_raw; lua_insert(lua_L, -2); diff --git a/src/logging.h b/src/logging.h index 0e529241..c4af5bdf 100644 --- a/src/logging.h +++ b/src/logging.h @@ -30,8 +30,8 @@ #ifndef _LOGGING_H #define _LOGGING_H -#include #include +#include #include #include "config.h" #include "i18n.h" @@ -82,9 +82,10 @@ void NORM_ERR(const char *format, Args &&...args) { /* critical error with additional cleanup */ template -__attribute__((noreturn)) -inline void CRIT_ERR_FREE(void *memtofree1, void *memtofree2, - const char *format, Args &&...args) { +__attribute__((noreturn)) inline void CRIT_ERR_FREE(void *memtofree1, + void *memtofree2, + const char *format, + Args &&...args) { NORM_ERR(format, args...); free(memtofree1); free(memtofree2); @@ -94,8 +95,8 @@ inline void CRIT_ERR_FREE(void *memtofree1, void *memtofree2, /* critical error */ template -__attribute__((noreturn)) -inline void CRIT_ERR(const char *format, Args &&...args) { +__attribute__((noreturn)) inline void CRIT_ERR(const char *format, + Args &&...args) { CRIT_ERR_FREE(nullptr, nullptr, format, args...); } diff --git a/src/mouse-events.cc b/src/mouse-events.cc index f164021d..6a9593bb 100644 --- a/src/mouse-events.cc +++ b/src/mouse-events.cc @@ -20,10 +20,10 @@ #include "mouse-events.h" -#include -#include #include #include +#include +#include #include #include "logging.h" @@ -35,11 +35,11 @@ void push_table_value(lua_State *L, std::string key, std::string value) { } template -typename std::enable_if::value>::type -push_table_value(lua_State *L, std::string key, T value) { - lua_pushstring(L, key.c_str()); - lua_pushinteger(L, value); - lua_settable(L, -3); +typename std::enable_if::value>::type push_table_value( + lua_State *L, std::string key, T value) { + lua_pushstring(L, key.c_str()); + lua_pushinteger(L, value); + lua_settable(L, -3); } template @@ -64,12 +64,12 @@ void push_bitset(lua_State *L, std::bitset it, } const std::array mod_names = {{ - "shift", - "control", - "alt", - "super", - "caps_lock", - "num_lock", + "shift", + "control", + "alt", + "super", + "caps_lock", + "num_lock", }}; void push_mods(lua_State *L, modifier_state_t mods) { @@ -80,9 +80,10 @@ void push_mods(lua_State *L, modifier_state_t mods) { // Returns ms since Epoch. inline size_t current_time_ms() { - struct timespec spec; - clock_gettime(CLOCK_REALTIME, &spec); - return static_cast(static_cast(spec.tv_sec)*1'000 + spec.tv_nsec/1'000'000); + struct timespec spec; + clock_gettime(CLOCK_REALTIME, &spec); + return static_cast(static_cast(spec.tv_sec) * 1'000 + + spec.tv_nsec / 1'000'000); } void push_table_value(lua_State *L, std::string key, mouse_event_t type) { @@ -113,7 +114,8 @@ void push_table_value(lua_State *L, std::string key, mouse_event_t type) { lua_settable(L, -3); } -void push_table_value(lua_State *L, std::string key, scroll_direction_t direction) { +void push_table_value(lua_State *L, std::string key, + scroll_direction_t direction) { lua_pushstring(L, key.c_str()); switch (direction) { case SCROLL_DOWN: @@ -135,7 +137,6 @@ void push_table_value(lua_State *L, std::string key, scroll_direction_t directio lua_settable(L, -3); } - void push_table_value(lua_State *L, std::string key, mouse_button_t button) { lua_pushstring(L, key.c_str()); switch (button) { @@ -162,7 +163,8 @@ void push_table_value(lua_State *L, std::string key, mouse_button_t button) { } /* Class methods */ -mouse_event::mouse_event(mouse_event_t type): type(type), time(current_time_ms()) {}; +mouse_event::mouse_event(mouse_event_t type) + : type(type), time(current_time_ms()){}; void mouse_event::push_lua_table(lua_State *L) const { lua_newtable(L); diff --git a/src/mouse-events.h b/src/mouse-events.h index 341c8c14..e0cd5eb7 100644 --- a/src/mouse-events.h +++ b/src/mouse-events.h @@ -22,8 +22,8 @@ #define MOUSE_EVENTS_H #include -#include #include +#include #include "config.h" #include "logging.h" @@ -57,19 +57,19 @@ enum mouse_event_t { // above list if it has other event codes or a standard file containing them. // Left mouse button event code -#define BTN_LEFT 0x110 +#define BTN_LEFT 0x110 // Right mouse button event code -#define BTN_RIGHT 0x111 +#define BTN_RIGHT 0x111 // Middle mouse button event code -#define BTN_MIDDLE 0x112 +#define BTN_MIDDLE 0x112 // Back mouse button event code -#define BTN_BACK 0x116 +#define BTN_BACK 0x116 // Forward mouse button event code -#define BTN_FORWARD 0x115 +#define BTN_FORWARD 0x115 #endif -enum mouse_button_t: uint32_t { +enum mouse_button_t : uint32_t { BUTTON_LEFT = BTN_LEFT, BUTTON_RIGHT = BTN_RIGHT, BUTTON_MIDDLE = BTN_MIDDLE, @@ -105,8 +105,8 @@ inline mouse_button_t x11_mouse_button_code(unsigned int x11_mouse_button) { #endif /* BUILD_X11 */ struct mouse_event { - mouse_event_t type; // type of event - size_t time; // ms since epoch when the event happened + mouse_event_t type; // type of event + size_t time; // ms since epoch when the event happened explicit mouse_event(mouse_event_t type); @@ -119,13 +119,15 @@ struct mouse_positioned_event : public mouse_event { size_t x = 0, y = 0; // position relative to window size_t x_abs = 0, y_abs = 0; // position relative to root - mouse_positioned_event(mouse_event_t type, size_t x, size_t y, size_t x_abs, size_t y_abs): mouse_event(type), x(x), y(y), x_abs(x_abs), y_abs() {}; - + mouse_positioned_event(mouse_event_t type, size_t x, size_t y, size_t x_abs, + size_t y_abs) + : mouse_event(type), x(x), y(y), x_abs(x_abs), y_abs(){}; + void push_lua_data(lua_State *L) const; }; typedef std::bitset<6> modifier_state_t; -enum modifier_key: uint32_t { +enum modifier_key : uint32_t { MOD_SHIFT = 0, MOD_CONTROL = 1, MOD_ALT = 2, @@ -138,26 +140,29 @@ std::string modifier_name(modifier_key key); #ifdef BUILD_X11 inline modifier_state_t x11_modifier_state(unsigned int mods) { - modifier_state_t result; - result[MOD_SHIFT] = mods & ShiftMask; - result[MOD_CONTROL] = mods & ControlMask; - result[MOD_ALT] = mods & Mod1Mask; - result[MOD_SUPER] = mods & Mod4Mask; - result[MOD_CAPS_LOCK] = mods & LockMask; - result[MOD_NUM_LOCK] = mods & Mod2Mask; - return result; + modifier_state_t result; + result[MOD_SHIFT] = mods & ShiftMask; + result[MOD_CONTROL] = mods & ControlMask; + result[MOD_ALT] = mods & Mod1Mask; + result[MOD_SUPER] = mods & Mod4Mask; + result[MOD_CAPS_LOCK] = mods & LockMask; + result[MOD_NUM_LOCK] = mods & Mod2Mask; + return result; } #endif /* BUILD_X11 */ struct mouse_move_event : public mouse_positioned_event { modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...) - mouse_move_event(size_t x, size_t y, size_t x_abs, size_t y_abs, modifier_state_t mods = 0): mouse_positioned_event{mouse_event_t::MOUSE_MOVE, x, y, x_abs, y_abs}, mods(mods) {}; + mouse_move_event(size_t x, size_t y, size_t x_abs, size_t y_abs, + modifier_state_t mods = 0) + : mouse_positioned_event{mouse_event_t::MOUSE_MOVE, x, y, x_abs, y_abs}, + mods(mods){}; void push_lua_data(lua_State *L) const; }; -enum scroll_direction_t: uint8_t { +enum scroll_direction_t : uint8_t { SCROLL_UNKNOWN = 0, SCROLL_UP, SCROLL_DOWN, @@ -190,7 +195,11 @@ struct mouse_scroll_event : public mouse_positioned_event { modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...) scroll_direction_t direction; - mouse_scroll_event(size_t x, size_t y, size_t x_abs, size_t y_abs, scroll_direction_t direction, modifier_state_t mods = 0): mouse_positioned_event{mouse_event_t::MOUSE_SCROLL, x, y, x_abs, y_abs}, direction(direction), mods(mods) {}; + mouse_scroll_event(size_t x, size_t y, size_t x_abs, size_t y_abs, + scroll_direction_t direction, modifier_state_t mods = 0) + : mouse_positioned_event{mouse_event_t::MOUSE_SCROLL, x, y, x_abs, y_abs}, + direction(direction), + mods(mods){}; void push_lua_data(lua_State *L) const; }; @@ -199,13 +208,20 @@ struct mouse_button_event : public mouse_positioned_event { modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...) mouse_button_t button; - mouse_button_event(mouse_event_t type, size_t x, size_t y, size_t x_abs, size_t y_abs, mouse_button_t button, modifier_state_t mods = 0): mouse_positioned_event{type, x, y, x_abs, y_abs}, button(button), mods(mods) {}; + mouse_button_event(mouse_event_t type, size_t x, size_t y, size_t x_abs, + size_t y_abs, mouse_button_t button, + modifier_state_t mods = 0) + : mouse_positioned_event{type, x, y, x_abs, y_abs}, + button(button), + mods(mods){}; void push_lua_data(lua_State *L) const; }; struct mouse_crossing_event : public mouse_positioned_event { - mouse_crossing_event(mouse_event_t type, size_t x, size_t y, size_t x_abs, size_t y_abs): mouse_positioned_event{type, x, y, x_abs, y_abs} {}; + mouse_crossing_event(mouse_event_t type, size_t x, size_t y, size_t x_abs, + size_t y_abs) + : mouse_positioned_event{type, x, y, x_abs, y_abs} {}; }; #endif /* MOUSE_EVENTS_H */ diff --git a/src/x11.cc b/src/x11.cc index 97fb7e4a..fb48e1a6 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -27,21 +27,22 @@ * */ +#include "x11.h" + #include -#include #include #include "common.h" #include "config.h" #include "conky.h" +#include "gui.h" #include "logging.h" -#include "x11.h" +#include #include #include -#include #include +#include #include -#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvariadic-macros" @@ -52,7 +53,7 @@ #include #include #include -#include "gui.h" + #ifdef BUILD_IMLIB2 #include "imlib2.h" #endif /* BUILD_IMLIB2 */ @@ -72,8 +73,8 @@ #include #endif /* BUILD_XFIXES */ #ifdef BUILD_XINPUT -#include #include +#include #endif /* BUILD_XINPUT */ #ifdef HAVE_XCB_ERRORS #include @@ -83,7 +84,6 @@ /* some basic X11 stuff */ Display *display = nullptr; - #ifdef HAVE_XCB_ERRORS xcb_connection_t *xcb_connection; xcb_errors_context_t *xcb_errors_ctx; @@ -239,79 +239,78 @@ imlib_cache_size_setting imlib_cache_size; /******************** ************************/ /* WARNING, this type not in Xlib spec */ -static int -x11_error_handler(Display *d, XErrorEvent *err) { +static int x11_error_handler(Display *d, XErrorEvent *err) { char *error_name = nullptr; bool name_allocated = false; char *code_description = nullptr; bool code_allocated = false; - #ifdef HAVE_XCB_ERRORS - if (xcb_errors_ctx != nullptr) { - const char *extension; - const char *base_name = xcb_errors_get_name_for_error(xcb_errors_ctx, err->error_code, &extension); - if (extension != nullptr) { - const size_t size = strlen(base_name) + strlen(extension) + 4; - error_name = new char(size); - snprintf(error_name, size, "%s (%s)", base_name, extension); - name_allocated = true; - } else { - error_name = const_cast(base_name); - } - - const char *major = xcb_errors_get_name_for_major_code(xcb_errors_ctx, err->request_code); - const char *minor = xcb_errors_get_name_for_minor_code(xcb_errors_ctx, err->request_code, err->minor_code); - if (minor != nullptr) { - const size_t size = strlen(base_name) + strlen(extension) + 4; - code_description = new char(size); - snprintf(code_description, size, "%s - %s", major, minor); - code_allocated = true; - } else { - code_description = const_cast(major); - } +#ifdef HAVE_XCB_ERRORS + if (xcb_errors_ctx != nullptr) { + const char *extension; + const char *base_name = xcb_errors_get_name_for_error( + xcb_errors_ctx, err->error_code, &extension); + if (extension != nullptr) { + const size_t size = strlen(base_name) + strlen(extension) + 4; + error_name = new char(size); + snprintf(error_name, size, "%s (%s)", base_name, extension); + name_allocated = true; + } else { + error_name = const_cast(base_name); } - #endif + + const char *major = + xcb_errors_get_name_for_major_code(xcb_errors_ctx, err->request_code); + const char *minor = xcb_errors_get_name_for_minor_code( + xcb_errors_ctx, err->request_code, err->minor_code); + if (minor != nullptr) { + const size_t size = strlen(base_name) + strlen(extension) + 4; + code_description = new char(size); + snprintf(code_description, size, "%s - %s", major, minor); + code_allocated = true; + } else { + code_description = const_cast(major); + } + } +#endif if (error_name == nullptr) { if (err->error_code > 0 && err->error_code < 17) { static std::array NAMES = { - "request", "value", "window", "pixmap", "atom", "cursor", "font", "match", - "drawable", "access", "alloc", "colormap", "G context", "ID choice", - "name", "length", "implementation" - }; - error_name = const_cast(NAMES[err->error_code].c_str()); + "request", "value", "window", "pixmap", "atom", + "cursor", "font", "match", "drawable", "access", + "alloc", "colormap", "G context", "ID choice", "name", + "length", "implementation"}; + error_name = const_cast(NAMES[err->error_code].c_str()); } else { static char code_name_buffer[4]; - error_name = reinterpret_cast(&code_name_buffer); + error_name = reinterpret_cast(&code_name_buffer); snprintf(error_name, 3, "%d", err->error_code); } } if (code_description == nullptr) { const size_t size = 37; code_description = new char(size); - snprintf(code_description, size, "error code: [major: %i, minor: %i]", err->request_code, err->minor_code); + snprintf(code_description, size, "error code: [major: %i, minor: %i]", + err->request_code, err->minor_code); code_allocated = true; } DBGP( - "X %s Error:\n" - "Display: %lx, XID: %li, Serial: %lu\n" - "%s", - error_name, - reinterpret_cast(err->display), - static_cast(err->resourceid), err->serial, - code_description - ); + "X %s Error:\n" + "Display: %lx, XID: %li, Serial: %lu\n" + "%s", + error_name, reinterpret_cast(err->display), + static_cast(err->resourceid), err->serial, code_description); if (name_allocated) free(error_name); if (code_allocated) free(code_description); - + return 0; } -__attribute__((noreturn)) -static int x11_ioerror_handler(Display *d) { +__attribute__((noreturn)) static int x11_ioerror_handler(Display *d) { CRIT_ERR("X IO Error: Display %lx\n", reinterpret_cast(d)); } @@ -351,15 +350,15 @@ static void init_x11() { update_workarea(); - #ifdef HAVE_XCB_ERRORS +#ifdef HAVE_XCB_ERRORS auto connection = xcb_connect(NULL, NULL); if (!xcb_connection_has_error(connection)) { if (xcb_errors_context_new(connection, &xcb_errors_ctx) != Success) { xcb_errors_ctx = nullptr; } } - #endif /* HAVE_XCB_ERRORS */ - +#endif /* HAVE_XCB_ERRORS */ + /* WARNING, this type not in Xlib spec */ XSetErrorHandler(&x11_error_handler); XSetIOErrorHandler(&x11_ioerror_handler); @@ -960,9 +959,10 @@ void x11_init_window(lua::state &l, bool own) { } bool xinput_ok = false; #ifdef BUILD_XINPUT - do { // not loop - int _ignored; // segfault if NULL - if (!XQueryExtension(display, "XInputExtension", &window.xi_opcode, &_ignored, &_ignored)) { + do { // not loop + int _ignored; // segfault if NULL + if (!XQueryExtension(display, "XInputExtension", &window.xi_opcode, + &_ignored, &_ignored)) { // events will still ~work but let the user know why they're buggy NORM_ERR("XInput extension is not supported by X11!"); break; @@ -976,7 +976,7 @@ void x11_init_window(lua::state &l, bool own) { } const size_t mask_size = (XI_LASTEVENT + 7) / 8; - unsigned char mask_bytes[mask_size] = {0}; /* must be zeroed! */ + unsigned char mask_bytes[mask_size] = {0}; /* must be zeroed! */ XISetMask(mask_bytes, XI_Motion); XIEventMask ev_masks[1]; @@ -1356,10 +1356,10 @@ void print_mouse_speed(struct text_object *obj, char *p, } InputEvent *xev_as_input_event(XEvent &ev) { - if (ev.type == KeyPress || ev.type == KeyRelease || - ev.type == ButtonPress || ev.type == ButtonRelease || ev.type == MotionNotify || + if (ev.type == KeyPress || ev.type == KeyRelease || ev.type == ButtonPress || + ev.type == ButtonRelease || ev.type == MotionNotify || ev.type == EnterNotify || ev.type == LeaveNotify) { - return reinterpret_cast(&ev); + return reinterpret_cast(&ev); } else { return nullptr; } @@ -1380,9 +1380,7 @@ void propagate_x11_event(XEvent &ev) { XGetInputFocus(display, &focused, &_revert_to); if (focused == window.window) { Time time = CurrentTime; - if (i_ev != nullptr) { - time = i_ev->common.time; - } + if (i_ev != nullptr) { time = i_ev->common.time; } XSetInputFocus(display, window.desktop, RevertToPointerRoot, time); } } @@ -1390,13 +1388,15 @@ void propagate_x11_event(XEvent &ev) { #ifdef BUILD_MOUSE_EVENTS // Assuming parent has a simple linear stack of descendants, this function // returns the last leaf on the graph. -inline Window last_descendant(Display* display, Window parent) { +inline Window last_descendant(Display *display, Window parent) { Window _ignored, *children; uint32_t count; Window current = parent; - while (XQueryTree(display, current, &_ignored, &_ignored, &children, &count) && count != 0) { + while ( + XQueryTree(display, current, &_ignored, &_ignored, &children, &count) && + count != 0) { current = children[count - 1]; XFree(children); } @@ -1404,7 +1404,7 @@ inline Window last_descendant(Display* display, Window parent) { return current; } -Window query_x11_window_at_pos(Display* display, int x, int y) { +Window query_x11_window_at_pos(Display *display, int x, int y) { Window root = DefaultRootWindow(display); // these values are ignored but NULL can't be passed @@ -1413,9 +1413,8 @@ Window query_x11_window_at_pos(Display* display, int x, int y) { unsigned int mask_return; Window last = None; - XQueryPointer(display, window.root, &root_return, &last, - &root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return - ); + XQueryPointer(display, window.root, &root_return, &last, &root_x_return, + &root_y_return, &win_x_return, &win_y_return, &mask_return); // X11 correctly returns a window which covers conky area, but returned window // is not window.window, but instead a parent node in some cases and the diff --git a/src/x11.h b/src/x11.h index 36221951..ed90f59c 100644 --- a/src/x11.h +++ b/src/x11.h @@ -24,20 +24,21 @@ #pragma once +#include "setting.hh" + #include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvariadic-macros" #include #pragma GCC diagnostic pop + #ifdef BUILD_XFT #include #endif - #ifdef BUILD_XDBE #include #endif -#include "setting.hh" #include #ifdef BUILD_ARGB @@ -130,28 +131,29 @@ struct InputEventCommon { }; union InputEvent { - int type; // event type + int type; // event type InputEventCommon common; // Discrete interfaces - XAnyEvent xany; // common event interface - XKeyEvent xkey; // KeyPress & KeyRelease events - XButtonEvent xbutton; // ButtonPress & ButtonRelease events - XMotionEvent xmotion; // MotionNotify event - XCrossingEvent xcrossing; // EnterNotify & LeaveNotify events + XAnyEvent xany; // common event interface + XKeyEvent xkey; // KeyPress & KeyRelease events + XButtonEvent xbutton; // ButtonPress & ButtonRelease events + XMotionEvent xmotion; // MotionNotify event + XCrossingEvent xcrossing; // EnterNotify & LeaveNotify events // Ensures InputEvent matches memory layout of XEvent. // Accessing base variant is as code smell. XEvent base; }; -// Returns InputEvent pointer to provided XEvent is an input event; nullptr otherwise. +// Returns InputEvent pointer to provided XEvent is an input event; nullptr +// otherwise. InputEvent *xev_as_input_event(XEvent &ev); void propagate_x11_event(XEvent &ev); #ifdef BUILD_MOUSE_EVENTS -Window query_x11_window_at_pos(Display* display, int x, int y); +Window query_x11_window_at_pos(Display *display, int x, int y); #endif /* BUILD_MOUSE_EVENTS */ #ifdef BUILD_XDBE