1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-06-10 03:02:20 +00:00

Provide a notice when build options get disabled

Reformat files and hope it invalidates CI cache :)

Signed-off-by: Tin <tin.svagelj@live.com>
This commit is contained in:
Tin 2023-11-10 12:31:01 +01:00 committed by Brenden Matthews
parent 484e667450
commit 4936c7492c
No known key found for this signature in database
GPG Key ID: 137B7AC2BDFD8DF0
13 changed files with 336 additions and 302 deletions

View File

@ -140,6 +140,7 @@ jobs:
-DBUILD_MYSQL=ON \ -DBUILD_MYSQL=ON \
-DBUILD_NVIDIA=ON \ -DBUILD_NVIDIA=ON \
-DBUILD_PULSEAUDIO=ON \ -DBUILD_PULSEAUDIO=ON \
-DBUILD_CURL=ON \
-DBUILD_RSS=ON \ -DBUILD_RSS=ON \
-DBUILD_TESTS=ON \ -DBUILD_TESTS=ON \
-DBUILD_WLAN=ON \ -DBUILD_WLAN=ON \

View File

@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.17)
project(conky) project(conky)

View File

@ -18,6 +18,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
include(CMakeDependentOption)
include(DependentOption)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
if(MAINTAINER_MODE) if(MAINTAINER_MODE)
set( set(
@ -97,33 +100,26 @@ set(DEFAULT_TEXT_BUFFER_SIZE "256"
set(MAX_NET_INTERFACES "256" CACHE STRING "Maximum number of network devices") set(MAX_NET_INTERFACES "256" CACHE STRING "Maximum number of network devices")
# Platform specific options Linux only # Platform specific options Linux only
if(OS_LINUX) cmake_dependent_option(BUILD_PORT_MONITORS "Build TCP portmon support" true
option(BUILD_PORT_MONITORS "Build TCP portmon support" true) "OS_LINUX" false)
option(BUILD_IBM "Support for IBM/Lenovo notebooks" true) cmake_dependent_option(BUILD_IBM "Support for IBM/Lenovo notebooks" true
option(BUILD_HDDTEMP "Support for hddtemp" true) "OS_LINUX" false)
option(BUILD_IPV6 "Enable if you want IPv6 support" true) cmake_dependent_option(BUILD_HDDTEMP "Support for hddtemp" true
if(BUILD_X11) "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 # nvidia may also work on FreeBSD, not sure
option(BUILD_NVIDIA "Enable nvidia support" false) cmake_dependent_option(BUILD_NVIDIA "Enable nvidia support" false
endif(BUILD_X11) "OS_LINUX" false)
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)
# macOS Only # macOS Only
if(OS_DARWIN) cmake_dependent_option(
option(
BUILD_IPGFREQ BUILD_IPGFREQ
"Enable cpu freq calculation based on Intel® Power Gadget; otherwise use constant factory value" "Enable cpu freq calculation based on Intel® Power Gadget; otherwise use constant factory value"
false) false
endif(OS_DARWIN) "OS_DARWIN" false)
# Optional features etc # Optional features etc
#
option(BUILD_WLAN "Enable wireless support" false) 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_MATH "Enable math support" true)
option(BUILD_NCURSES "Enable ncurses support" true) option(BUILD_NCURSES "Enable ncurses support" true)
if(BUILD_NCURSES)
option( dependent_option(LEAKFREE_NCURSES
LEAKFREE_NCURSES
"Enable to hide false ncurses-memleaks in valgrind (works only when ncurses is compiled with --disable-leaks)" "Enable to hide false ncurses-memleaks in valgrind (works only when ncurses is compiled with --disable-leaks)"
false) false
else(BUILD_NCURSES) "BUILD_NCURSES" false
set( "LEAKFREE_NCURSES requires ncurses")
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)
option(BUILD_WAYLAND "Build Wayland support" false) option(BUILD_WAYLAND "Build Wayland support" false)
option(BUILD_X11 "Build X11 support" true) option(BUILD_X11 "Build X11 support" true)
if(BUILD_X11)
option(OWN_WINDOW "Enable own_window support" true)
# Mac Fix dependent_option(OWN_WINDOW "Enable running conky in a dedicated window" true
"BUILD_X11" false
"Dedicated window mode only works on X11")
# On MacOS these cause issues so they're disabled by default
if(OS_DARWIN) if(OS_DARWIN)
option(BUILD_XDAMAGE "Build Xdamage support" false) dependent_option(BUILD_XDAMAGE "Build Xdamage support" false
option(BUILD_XFIXES "Build Xfixes support" false) "BUILD_X11" false
else(OS_DARWIN) "Xdamage support requires X11")
option(BUILD_XDAMAGE "Build Xdamage support" true) dependent_option(BUILD_XFIXES "Build Xfixes support" false
option(BUILD_XFIXES "Build Xfixes support" true) "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) endif(OS_DARWIN)
option(BUILD_XINERAMA "Build Xinerama support" true) dependent_option(BUILD_XINERAMA "Build Xinerama support" true
option(BUILD_XDBE "Build Xdbe (double-buffer) support" true) "BUILD_X11" false
option(BUILD_XFT "Build Xft (freetype fonts) support" true) "Xinerama support requires X11")
option(BUILD_IMLIB2 "Enable Imlib2 support" true) dependent_option(BUILD_XDBE "Build Xdbe (double-buffer) support" true
option(BUILD_XSHAPE "Enable Xshape support" true) "BUILD_X11" false
"Xdbe based double-buffering requires X11")
option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false) dependent_option(BUILD_XFT "Build Xft (freetype fonts) support" true
else(BUILD_X11) "BUILD_X11" false
set(OWN_WINDOW false CACHE BOOL "Enable own_window support" FORCE) "Xft (freetype font) support requires X11")
set(BUILD_XDAMAGE false CACHE BOOL "Build Xdamage support" FORCE) dependent_option(BUILD_IMLIB2 "Enable Imlib2 support" true
set(BUILD_XFIXES false CACHE BOOL "Build Xfixes support" FORCE) "BUILD_X11" false
set(BUILD_XINERAMA false CACHE BOOL "Build Xinerama support" FORCE) "Imlib2 support requires X11")
set(BUILD_XDBE false CACHE BOOL "Build Xdbe (double-buffer) support" FORCE) dependent_option(BUILD_XSHAPE "Enable Xshape support" true
set(BUILD_XFT false CACHE BOOL "Build Xft (freetype fonts) support" FORCE) "BUILD_X11" false
set(BUILD_IMLIB2 false CACHE BOOL "Enable Imlib2 support" FORCE) "Xshape support requires X11")
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)
# if we build with any GUI support # if we build with any GUI support
if(BUILD_X11) if(BUILD_X11)
@ -195,25 +189,22 @@ if(BUILD_WAYLAND)
set(BUILD_GUI true) set(BUILD_GUI true)
endif(BUILD_WAYLAND) endif(BUILD_WAYLAND)
if(BUILD_GUI) dependent_option(BUILD_MOUSE_EVENTS "Enable mouse event support" true
option(BUILD_MOUSE_EVENTS "Enable mouse event support" true) "BUILD_WAYLAND OR OWN_WINDOW" false
endif(BUILD_GUI) "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) dependent_option(BUILD_ARGB "Build ARGB (real transparency) support" true
option(BUILD_XINPUT "Build Xinput 2 support" true) "OWN_WINDOW" false
else(BUILD_GUI AND BUILD_MOUSE_EVENTS) "ARGB support requires OWN_WINDOW enabled")
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)
# Lua library options
option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false) 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_LUA_RSVG "Build rsvg bindings for Lua" false)
option(BUILD_AUDACIOUS "Build audacious (music player) support" 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_CURL "Enable if you want Curl support" false)
option(BUILD_RSS "Enable if you want RSS support" false) dependent_option(BUILD_RSS "Enable if you want RSS support" false
"BUILD_CURL" false
if(BUILD_RSS) "RSS depends on Curl support")
# if RSS is enabled, curl is required
set(BUILD_CURL true)
endif(BUILD_RSS)
option(BUILD_APCUPSD "Enable APCUPSD support" true) option(BUILD_APCUPSD "Enable APCUPSD support" true)

View File

@ -59,6 +59,8 @@ set(INCLUDE_SEARCH_PATH /usr/include /usr/local/include)
# Set system vars # Set system vars
if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(OS_LINUX true) set(OS_LINUX true)
else(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(OS_LINUX false)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux") endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
@ -68,33 +70,47 @@ if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if(BUILD_IRC) if(BUILD_IRC)
set(conky_libs ${conky_libs} -lssl -lcrypto) set(conky_libs ${conky_libs} -lssl -lcrypto)
endif(BUILD_IRC) endif(BUILD_IRC)
else(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(OS_FREEBSD false)
endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if(CMAKE_SYSTEM_NAME MATCHES "DragonFly") if(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
set(OS_DRAGONFLY true) set(OS_DRAGONFLY true)
set(conky_libs ${conky_libs} -ldevstat) set(conky_libs ${conky_libs} -ldevstat)
else(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
set(OS_DRAGONFLY false)
endif(CMAKE_SYSTEM_NAME MATCHES "DragonFly") endif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
set(OS_OPENBSD true) set(OS_OPENBSD true)
else(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
set(OS_OPENBSD false)
endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") endif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
if(CMAKE_SYSTEM_NAME MATCHES "SunOS") if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(OS_SOLARIS true) set(OS_SOLARIS true)
set(conky_libs ${conky_libs} -lkstat) set(conky_libs ${conky_libs} -lkstat)
else(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(OS_SOLARIS false)
endif(CMAKE_SYSTEM_NAME MATCHES "SunOS") endif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD") if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(OS_NETBSD true) set(OS_NETBSD true)
else(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(OS_NETBSD false)
endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD") endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
if(CMAKE_SYSTEM_NAME MATCHES "Haiku") if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
set(OS_HAIKU true) set(OS_HAIKU true)
set(conky_libs ${conky_libs} -lnetwork -lintl) set(conky_libs ${conky_libs} -lnetwork -lintl)
else(CMAKE_SYSTEM_NAME MATCHES "Haiku")
set(OS_HAIKU false)
endif(CMAKE_SYSTEM_NAME MATCHES "Haiku") endif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin") if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(OS_DARWIN true) set(OS_DARWIN true)
else(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(OS_DARWIN false)
endif(CMAKE_SYSTEM_NAME MATCHES "Darwin") endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(NOT OS_LINUX if(NOT OS_LINUX

View File

@ -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()

View File

@ -24,7 +24,7 @@
* *
*/ */
#include <config.h> #include <>
#ifdef BUILD_WAYLAND #ifdef BUILD_WAYLAND
#include <wayland-client.h> #include <wayland-client.h>
@ -62,9 +62,9 @@
#include "fonts.h" #include "fonts.h"
#endif #endif
#ifdef BUILD_MOUSE_EVENTS #ifdef BUILD_MOUSE_EVENTS
#include "mouse-events.h"
#include <map>
#include <array> #include <array>
#include <map>
#include "mouse-events.h"
#endif #endif
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
@ -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_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y; size_t abs_y = w->rectangle.y + y;
mouse_crossing_event event { mouse_crossing_event event{mouse_event_t::AREA_ENTER, x, y, abs_x, abs_y};
mouse_event_t::AREA_ENTER,
x,
y,
abs_x,
abs_y
};
llua_mouse_hook(event); llua_mouse_hook(event);
} }
static void on_pointer_leave(void *data, static void on_pointer_leave(void *data, struct wl_pointer *pointer,
struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) {
uint32_t serial,
struct wl_surface *surface) {
auto w = reinterpret_cast<struct window *>(data); auto w = reinterpret_cast<struct window *>(data);
std::array<size_t, 2> last = last_known_positions[pointer]; std::array<size_t, 2> last = last_known_positions[pointer];
@ -465,20 +457,12 @@ static void on_pointer_leave(void *data,
size_t abs_x = w->rectangle.x + x; size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y; size_t abs_y = w->rectangle.y + y;
mouse_crossing_event event { mouse_crossing_event event{mouse_event_t::AREA_LEAVE, x, y, abs_x, abs_y};
mouse_event_t::AREA_LEAVE,
x,
y,
abs_x,
abs_y
};
llua_mouse_hook(event); llua_mouse_hook(event);
} }
static void on_pointer_motion(void *data, static void on_pointer_motion(void *data, struct wl_pointer *pointer,
struct wl_pointer *pointer, uint32_t _time, wl_fixed_t surface_x,
uint32_t _time,
wl_fixed_t surface_x,
wl_fixed_t surface_y) { wl_fixed_t surface_y) {
auto w = reinterpret_cast<struct window *>(data); auto w = reinterpret_cast<struct window *>(data);
@ -489,20 +473,12 @@ static void on_pointer_motion(void *data,
size_t abs_x = w->rectangle.x + x; size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y; size_t abs_y = w->rectangle.y + y;
mouse_move_event event { mouse_move_event event{x, y, abs_x, abs_y};
x,
y,
abs_x,
abs_y
};
llua_mouse_hook(event); llua_mouse_hook(event);
} }
static void on_pointer_button(void *data, static void on_pointer_button(void *data, struct wl_pointer *pointer,
struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state) { uint32_t state) {
auto w = reinterpret_cast<struct window *>(data); auto w = reinterpret_cast<struct window *>(data);
@ -513,11 +489,7 @@ static void on_pointer_button(void *data,
size_t abs_y = w->rectangle.y + y; size_t abs_y = w->rectangle.y + y;
mouse_button_event event{ mouse_button_event event{
mouse_event_t::MOUSE_RELEASE, mouse_event_t::MOUSE_RELEASE, x, y, abs_x, abs_y,
x,
y,
abs_x,
abs_y,
static_cast<mouse_button_t>(button), static_cast<mouse_button_t>(button),
}; };
@ -534,11 +506,8 @@ static void on_pointer_button(void *data,
llua_mouse_hook(event); llua_mouse_hook(event);
} }
void on_pointer_axis(void *data, void on_pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time,
struct wl_pointer *pointer, uint32_t axis, wl_fixed_t value) {
uint32_t time,
uint32_t axis,
wl_fixed_t value) {
if (value == 0) return; if (value == 0) return;
auto w = reinterpret_cast<struct window *>(data); auto w = reinterpret_cast<struct window *>(data);
@ -550,19 +519,17 @@ void on_pointer_axis(void *data,
size_t abs_y = w->rectangle.y + y; size_t abs_y = w->rectangle.y + y;
mouse_scroll_event event{ mouse_scroll_event event{
x, x, y, abs_x, abs_y, scroll_direction_t::SCROLL_UP,
y,
abs_x,
abs_y,
scroll_direction_t::SCROLL_UP,
}; };
switch (static_cast<wl_pointer_axis>(axis)) { switch (static_cast<wl_pointer_axis>(axis)) {
case WL_POINTER_AXIS_VERTICAL_SCROLL: 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; break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL: 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; break;
default: default:
return; return;
@ -570,8 +537,10 @@ void on_pointer_axis(void *data,
llua_mouse_hook(event); llua_mouse_hook(event);
} }
static void seat_capability_listener (void *data, wl_seat *seat, uint32_t capability_int) { static void seat_capability_listener(void *data, wl_seat *seat,
wl_seat_capability capabilities = static_cast<wl_seat_capability>(capability_int); uint32_t capability_int) {
wl_seat_capability capabilities =
static_cast<wl_seat_capability>(capability_int);
if (wl_globals.seat == seat) { if (wl_globals.seat == seat) {
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) > 0) { if ((capabilities & WL_SEAT_CAPABILITY_POINTER) > 0) {
wl_globals.pointer = wl_seat_get_pointer(seat); wl_globals.pointer = wl_seat_get_pointer(seat);
@ -587,7 +556,8 @@ static void seat_capability_listener (void *data, wl_seat *seat, uint32_t capabi
} }
} }
} }
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 */ #endif /* BUILD_MOUSE_EVENTS */
bool display_output_wayland::initialize() { bool display_output_wayland::initialize() {

View File

@ -382,7 +382,7 @@ bool display_output_x11::main_loop_wait(double t) {
XNextEvent(display, &ev); 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 // no need to check whether these events have been consumed because
// they're global and shouldn't be propagated // they're global and shouldn't be propagated
if (ev.type == GenericEvent && ev.xcookie.extension == window.xi_opcode) { if (ev.type == GenericEvent && ev.xcookie.extension == window.xi_opcode) {

View File

@ -527,9 +527,12 @@ bool llua_mouse_hook(const EventT &ev) {
if (ty == LUA_TNIL) { if (ty == LUA_TNIL) {
int ty_raw = lua_getglobal(lua_L, raw_hook_name.c_str()); int ty_raw = lua_getglobal(lua_L, raw_hook_name.c_str());
if (ty_raw == LUA_TFUNCTION) { 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. // - 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; hook_name = raw_hook_name;
ty = ty_raw; ty = ty_raw;
lua_insert(lua_L, -2); lua_insert(lua_L, -2);

View File

@ -30,8 +30,8 @@
#ifndef _LOGGING_H #ifndef _LOGGING_H
#define _LOGGING_H #define _LOGGING_H
#include <cstdio>
#include <cinttypes> #include <cinttypes>
#include <cstdio>
#include <stdexcept> #include <stdexcept>
#include "config.h" #include "config.h"
#include "i18n.h" #include "i18n.h"
@ -82,9 +82,10 @@ void NORM_ERR(const char *format, Args &&...args) {
/* critical error with additional cleanup */ /* critical error with additional cleanup */
template <typename... Args> template <typename... Args>
__attribute__((noreturn)) __attribute__((noreturn)) inline void CRIT_ERR_FREE(void *memtofree1,
inline void CRIT_ERR_FREE(void *memtofree1, void *memtofree2, void *memtofree2,
const char *format, Args &&...args) { const char *format,
Args &&...args) {
NORM_ERR(format, args...); NORM_ERR(format, args...);
free(memtofree1); free(memtofree1);
free(memtofree2); free(memtofree2);
@ -94,8 +95,8 @@ inline void CRIT_ERR_FREE(void *memtofree1, void *memtofree2,
/* critical error */ /* critical error */
template <typename... Args> template <typename... Args>
__attribute__((noreturn)) __attribute__((noreturn)) inline void CRIT_ERR(const char *format,
inline void CRIT_ERR(const char *format, Args &&...args) { Args &&...args) {
CRIT_ERR_FREE(nullptr, nullptr, format, args...); CRIT_ERR_FREE(nullptr, nullptr, format, args...);
} }

View File

@ -20,10 +20,10 @@
#include "mouse-events.h" #include "mouse-events.h"
#include <array>
#include <string>
#include <lua.h> #include <lua.h>
#include <time.h> #include <time.h>
#include <array>
#include <string>
#include <type_traits> #include <type_traits>
#include "logging.h" #include "logging.h"
@ -35,8 +35,8 @@ void push_table_value(lua_State *L, std::string key, std::string value) {
} }
template <typename T> template <typename T>
typename std::enable_if<std::is_integral<T>::value>::type typename std::enable_if<std::is_integral<T>::value>::type push_table_value(
push_table_value(lua_State *L, std::string key, T value) { lua_State *L, std::string key, T value) {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushinteger(L, value); lua_pushinteger(L, value);
lua_settable(L, -3); lua_settable(L, -3);
@ -82,7 +82,8 @@ void push_mods(lua_State *L, modifier_state_t mods) {
inline size_t current_time_ms() { inline size_t current_time_ms() {
struct timespec spec; struct timespec spec;
clock_gettime(CLOCK_REALTIME, &spec); clock_gettime(CLOCK_REALTIME, &spec);
return static_cast<size_t>(static_cast<uint64_t>(spec.tv_sec)*1'000 + spec.tv_nsec/1'000'000); return static_cast<size_t>(static_cast<uint64_t>(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) { 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); 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()); lua_pushstring(L, key.c_str());
switch (direction) { switch (direction) {
case SCROLL_DOWN: 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); lua_settable(L, -3);
} }
void push_table_value(lua_State *L, std::string key, mouse_button_t button) { void push_table_value(lua_State *L, std::string key, mouse_button_t button) {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
switch (button) { switch (button) {
@ -162,7 +163,8 @@ void push_table_value(lua_State *L, std::string key, mouse_button_t button) {
} }
/* Class methods */ /* 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 { void mouse_event::push_lua_table(lua_State *L) const {
lua_newtable(L); lua_newtable(L);

View File

@ -22,8 +22,8 @@
#define MOUSE_EVENTS_H #define MOUSE_EVENTS_H
#include <bitset> #include <bitset>
#include <string>
#include <cstdint> #include <cstdint>
#include <string>
#include "config.h" #include "config.h"
#include "logging.h" #include "logging.h"
@ -119,7 +119,9 @@ struct mouse_positioned_event : public mouse_event {
size_t x = 0, y = 0; // position relative to window size_t x = 0, y = 0; // position relative to window
size_t x_abs = 0, y_abs = 0; // position relative to root 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; void push_lua_data(lua_State *L) const;
}; };
@ -152,7 +154,10 @@ inline modifier_state_t x11_modifier_state(unsigned int mods) {
struct mouse_move_event : public mouse_positioned_event { struct mouse_move_event : public mouse_positioned_event {
modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...) 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; void push_lua_data(lua_State *L) const;
}; };
@ -190,7 +195,11 @@ struct mouse_scroll_event : public mouse_positioned_event {
modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...) modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...)
scroll_direction_t direction; 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; 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, ...) modifier_state_t mods; // held buttons and modifiers (ctrl, shift, ...)
mouse_button_t button; 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; void push_lua_data(lua_State *L) const;
}; };
struct mouse_crossing_event : public mouse_positioned_event { 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 */ #endif /* MOUSE_EVENTS_H */

View File

@ -27,21 +27,22 @@
* *
*/ */
#include "x11.h"
#include <X11/X.h> #include <X11/X.h>
#include <X11/extensions/XI2.h>
#include <sys/types.h> #include <sys/types.h>
#include "common.h" #include "common.h"
#include "config.h" #include "config.h"
#include "conky.h" #include "conky.h"
#include "gui.h"
#include "logging.h" #include "logging.h"
#include "x11.h"
#include <array>
#include <cstddef> #include <cstddef>
#include <cstdio> #include <cstdio>
#include <cstring>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <string> #include <string>
#include <array>
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros" #pragma GCC diagnostic ignored "-Wvariadic-macros"
@ -52,7 +53,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "gui.h"
#ifdef BUILD_IMLIB2 #ifdef BUILD_IMLIB2
#include "imlib2.h" #include "imlib2.h"
#endif /* BUILD_IMLIB2 */ #endif /* BUILD_IMLIB2 */
@ -72,8 +73,8 @@
#include <X11/extensions/Xfixes.h> #include <X11/extensions/Xfixes.h>
#endif /* BUILD_XFIXES */ #endif /* BUILD_XFIXES */
#ifdef BUILD_XINPUT #ifdef BUILD_XINPUT
#include <vector>
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
#include <vector>
#endif /* BUILD_XINPUT */ #endif /* BUILD_XINPUT */
#ifdef HAVE_XCB_ERRORS #ifdef HAVE_XCB_ERRORS
#include <xcb/xcb.h> #include <xcb/xcb.h>
@ -83,7 +84,6 @@
/* some basic X11 stuff */ /* some basic X11 stuff */
Display *display = nullptr; Display *display = nullptr;
#ifdef HAVE_XCB_ERRORS #ifdef HAVE_XCB_ERRORS
xcb_connection_t *xcb_connection; xcb_connection_t *xcb_connection;
xcb_errors_context_t *xcb_errors_ctx; xcb_errors_context_t *xcb_errors_ctx;
@ -239,8 +239,7 @@ imlib_cache_size_setting imlib_cache_size;
/******************** </SETTINGS> ************************/ /******************** </SETTINGS> ************************/
/* WARNING, this type not in Xlib spec */ /* WARNING, this type not in Xlib spec */
static int static int x11_error_handler(Display *d, XErrorEvent *err) {
x11_error_handler(Display *d, XErrorEvent *err) {
char *error_name = nullptr; char *error_name = nullptr;
bool name_allocated = false; bool name_allocated = false;
@ -250,7 +249,8 @@ x11_error_handler(Display *d, XErrorEvent *err) {
#ifdef HAVE_XCB_ERRORS #ifdef HAVE_XCB_ERRORS
if (xcb_errors_ctx != nullptr) { if (xcb_errors_ctx != nullptr) {
const char *extension; const char *extension;
const char *base_name = xcb_errors_get_name_for_error(xcb_errors_ctx, err->error_code, &extension); const char *base_name = xcb_errors_get_name_for_error(
xcb_errors_ctx, err->error_code, &extension);
if (extension != nullptr) { if (extension != nullptr) {
const size_t size = strlen(base_name) + strlen(extension) + 4; const size_t size = strlen(base_name) + strlen(extension) + 4;
error_name = new char(size); error_name = new char(size);
@ -260,8 +260,10 @@ x11_error_handler(Display *d, XErrorEvent *err) {
error_name = const_cast<char *>(base_name); error_name = const_cast<char *>(base_name);
} }
const char *major = xcb_errors_get_name_for_major_code(xcb_errors_ctx, err->request_code); const char *major =
const char *minor = xcb_errors_get_name_for_minor_code(xcb_errors_ctx, err->request_code, err->minor_code); 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) { if (minor != nullptr) {
const size_t size = strlen(base_name) + strlen(extension) + 4; const size_t size = strlen(base_name) + strlen(extension) + 4;
code_description = new char(size); code_description = new char(size);
@ -276,10 +278,10 @@ x11_error_handler(Display *d, XErrorEvent *err) {
if (error_name == nullptr) { if (error_name == nullptr) {
if (err->error_code > 0 && err->error_code < 17) { if (err->error_code > 0 && err->error_code < 17) {
static std::array<std::string, 17> NAMES = { static std::array<std::string, 17> NAMES = {
"request", "value", "window", "pixmap", "atom", "cursor", "font", "match", "request", "value", "window", "pixmap", "atom",
"drawable", "access", "alloc", "colormap", "G context", "ID choice", "cursor", "font", "match", "drawable", "access",
"name", "length", "implementation" "alloc", "colormap", "G context", "ID choice", "name",
}; "length", "implementation"};
error_name = const_cast<char *>(NAMES[err->error_code].c_str()); error_name = const_cast<char *>(NAMES[err->error_code].c_str());
} else { } else {
static char code_name_buffer[4]; static char code_name_buffer[4];
@ -290,7 +292,8 @@ x11_error_handler(Display *d, XErrorEvent *err) {
if (code_description == nullptr) { if (code_description == nullptr) {
const size_t size = 37; const size_t size = 37;
code_description = new char(size); 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; code_allocated = true;
} }
@ -298,11 +301,8 @@ x11_error_handler(Display *d, XErrorEvent *err) {
"X %s Error:\n" "X %s Error:\n"
"Display: %lx, XID: %li, Serial: %lu\n" "Display: %lx, XID: %li, Serial: %lu\n"
"%s", "%s",
error_name, error_name, reinterpret_cast<uint64_t>(err->display),
reinterpret_cast<uint64_t>(err->display), static_cast<int64_t>(err->resourceid), err->serial, code_description);
static_cast<int64_t>(err->resourceid), err->serial,
code_description
);
if (name_allocated) free(error_name); if (name_allocated) free(error_name);
if (code_allocated) free(code_description); if (code_allocated) free(code_description);
@ -310,8 +310,7 @@ x11_error_handler(Display *d, XErrorEvent *err) {
return 0; return 0;
} }
__attribute__((noreturn)) __attribute__((noreturn)) static int x11_ioerror_handler(Display *d) {
static int x11_ioerror_handler(Display *d) {
CRIT_ERR("X IO Error: Display %lx\n", reinterpret_cast<uint64_t>(d)); CRIT_ERR("X IO Error: Display %lx\n", reinterpret_cast<uint64_t>(d));
} }
@ -962,7 +961,8 @@ void x11_init_window(lua::state &l, bool own) {
#ifdef BUILD_XINPUT #ifdef BUILD_XINPUT
do { // not loop do { // not loop
int _ignored; // segfault if NULL int _ignored; // segfault if NULL
if (!XQueryExtension(display, "XInputExtension", &window.xi_opcode, &_ignored, &_ignored)) { if (!XQueryExtension(display, "XInputExtension", &window.xi_opcode,
&_ignored, &_ignored)) {
// events will still ~work but let the user know why they're buggy // events will still ~work but let the user know why they're buggy
NORM_ERR("XInput extension is not supported by X11!"); NORM_ERR("XInput extension is not supported by X11!");
break; break;
@ -1356,8 +1356,8 @@ void print_mouse_speed(struct text_object *obj, char *p,
} }
InputEvent *xev_as_input_event(XEvent &ev) { InputEvent *xev_as_input_event(XEvent &ev) {
if (ev.type == KeyPress || ev.type == KeyRelease || if (ev.type == KeyPress || ev.type == KeyRelease || ev.type == ButtonPress ||
ev.type == ButtonPress || ev.type == ButtonRelease || ev.type == MotionNotify || ev.type == ButtonRelease || ev.type == MotionNotify ||
ev.type == EnterNotify || ev.type == LeaveNotify) { ev.type == EnterNotify || ev.type == LeaveNotify) {
return reinterpret_cast<InputEvent *>(&ev); return reinterpret_cast<InputEvent *>(&ev);
} else { } else {
@ -1380,9 +1380,7 @@ void propagate_x11_event(XEvent &ev) {
XGetInputFocus(display, &focused, &_revert_to); XGetInputFocus(display, &focused, &_revert_to);
if (focused == window.window) { if (focused == window.window) {
Time time = CurrentTime; Time time = CurrentTime;
if (i_ev != nullptr) { if (i_ev != nullptr) { time = i_ev->common.time; }
time = i_ev->common.time;
}
XSetInputFocus(display, window.desktop, RevertToPointerRoot, time); XSetInputFocus(display, window.desktop, RevertToPointerRoot, time);
} }
} }
@ -1396,7 +1394,9 @@ inline Window last_descendant(Display* display, Window parent) {
Window current = parent; 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]; current = children[count - 1];
XFree(children); XFree(children);
} }
@ -1413,9 +1413,8 @@ Window query_x11_window_at_pos(Display* display, int x, int y) {
unsigned int mask_return; unsigned int mask_return;
Window last = None; Window last = None;
XQueryPointer(display, window.root, &root_return, &last, XQueryPointer(display, window.root, &root_return, &last, &root_x_return,
&root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return &root_y_return, &win_x_return, &win_y_return, &mask_return);
);
// X11 correctly returns a window which covers conky area, but returned window // 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 // is not window.window, but instead a parent node in some cases and the

View File

@ -24,20 +24,21 @@
#pragma once #pragma once
#include "setting.hh"
#include <X11/Xatom.h> #include <X11/Xatom.h>
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros" #pragma GCC diagnostic ignored "-Wvariadic-macros"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#ifdef BUILD_XFT #ifdef BUILD_XFT
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#endif #endif
#ifdef BUILD_XDBE #ifdef BUILD_XDBE
#include <X11/extensions/Xdbe.h> #include <X11/extensions/Xdbe.h>
#endif #endif
#include "setting.hh"
#include <cstdint> #include <cstdint>
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
@ -146,7 +147,8 @@ union InputEvent {
XEvent base; 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); InputEvent *xev_as_input_event(XEvent &ev);
void propagate_x11_event(XEvent &ev); void propagate_x11_event(XEvent &ev);