mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-25 12:10:03 +00:00
build, colours, core, gui, wayland, wl, x11: implement wayland display backend
This commit is contained in:
parent
4622c0e336
commit
d11742ae18
@ -177,6 +177,8 @@ else(BUILD_NCURSES)
|
||||
FORCE)
|
||||
endif(BUILD_NCURSES)
|
||||
|
||||
option(BUILD_WAYLAND "Build Wayland support" true)
|
||||
|
||||
option(BUILD_X11 "Build X11 support" true)
|
||||
if(BUILD_X11)
|
||||
option(OWN_WINDOW "Enable own_window support" true)
|
||||
@ -208,6 +210,9 @@ endif(BUILD_X11)
|
||||
if(BUILD_X11)
|
||||
set(BUILD_GUI true)
|
||||
endif(BUILD_X11)
|
||||
if(BUILD_WAYLAND)
|
||||
set(BUILD_GUI true)
|
||||
endif(BUILD_WAYLAND)
|
||||
|
||||
if(OWN_WINDOW)
|
||||
option(BUILD_ARGB "Build ARGB (real transparency) support" true)
|
||||
|
@ -352,6 +352,35 @@ if(BUILD_X11)
|
||||
endif(X11_FOUND)
|
||||
endif(BUILD_X11)
|
||||
|
||||
if(BUILD_WAYLAND)
|
||||
find_package(Wayland REQUIRED)
|
||||
set(conky_libs ${conky_libs} ${WAYLAND_CLIENT_LIBRARY})
|
||||
set(conky_includes ${conky_includes} ${WAYLAND_CLIENT_INCLUDE_DIR})
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
pkg_check_modules(wayland-protocols QUIET wayland-protocols>=1.13)
|
||||
if(WAYLAND_CLIENT_FOUND AND wayland-protocols_FOUND)
|
||||
#target_sources( ${COMPONENT} PRIVATE display-wayland.cxx )
|
||||
|
||||
# find Wayland protocols
|
||||
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
|
||||
|
||||
# find 'wayland-scanner' executable
|
||||
pkg_get_variable(WAYLAND_SCANNER wayland-scanner wayland_scanner)
|
||||
else(WAYLAND_CLIENT_FOUND AND wayland-protocols_FOUND)
|
||||
message(FATAL_ERROR "Unable to find wayland-scanner and xdg-shell protocol")
|
||||
endif(WAYLAND_CLIENT_FOUND AND wayland-protocols_FOUND)
|
||||
|
||||
pkg_check_modules(PANGOCAIRO pangocairo)
|
||||
set(conky_libs ${conky_libs} ${PANGOCAIRO_LIBRARIES})
|
||||
set(conky_includes ${conky_includes} ${PANGOCAIRO_INCLUDE_DIRS})
|
||||
|
||||
pkg_check_modules(PANGOFC pangofc)
|
||||
set(conky_libs ${conky_libs} ${PANGOFC_LIBRARIES})
|
||||
set(conky_includes ${conky_includes} ${PANGOFC_INCLUDE_DIRS})
|
||||
endif(BUILD_WAYLAND)
|
||||
|
||||
# Otherwise, use the most recent Lua version
|
||||
pkg_search_module(LUA
|
||||
REQUIRED
|
||||
@ -454,6 +483,12 @@ if(BUILD_PULSEAUDIO)
|
||||
set(conky_includes ${conky_includes} ${PULSEAUDIO_INCLUDE_DIRS})
|
||||
endif(BUILD_PULSEAUDIO)
|
||||
|
||||
if(WANT_CURL)
|
||||
pkg_check_modules(CURL REQUIRED libcurl)
|
||||
set(conky_libs ${conky_libs} ${CURL_LIBRARIES})
|
||||
set(conky_includes ${conky_includes} ${CURL_INCLUDE_DIRS})
|
||||
endif(WANT_CURL)
|
||||
|
||||
# Common libraries
|
||||
if(WANT_GLIB)
|
||||
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.36)
|
||||
|
59
cmake/FindWayland.cmake
Normal file
59
cmake/FindWayland.cmake
Normal file
@ -0,0 +1,59 @@
|
||||
find_path(
|
||||
WAYLAND_CLIENT_INCLUDE_DIR
|
||||
NAMES wayland-client.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
WAYLAND_CLIENT_LIBRARY
|
||||
NAMES wayland-client libwayland-client
|
||||
)
|
||||
|
||||
if(WAYLAND_CLIENT_INCLUDE_DIR AND WAYLAND_CLIENT_LIBRARY)
|
||||
add_library(wayland::client UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
wayland::client PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WAYLAND_CLIENT_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${WAYLAND_CLIENT_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
find_path(
|
||||
WAYLAND_SERVER_INCLUDE_DIR
|
||||
NAMES wayland-server.h
|
||||
)
|
||||
|
||||
find_library(
|
||||
WAYLAND_SERVER_LIBRARY
|
||||
NAMES wayland-server libwayland-server
|
||||
)
|
||||
|
||||
if(WAYLAND_SERVER_INCLUDE_DIR AND WAYLAND_SERVER_LIBRARY)
|
||||
add_library(wayland::server UNKNOWN IMPORTED)
|
||||
|
||||
set_target_properties(
|
||||
wayland::server PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WAYLAND_SERVER_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${WAYLAND_SERVER_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
WAYLAND_CLIENT
|
||||
REQUIRED_VARS WAYLAND_CLIENT_LIBRARY WAYLAND_CLIENT_INCLUDE_DIR
|
||||
)
|
||||
|
||||
find_package_handle_standard_args(
|
||||
WAYLAND_SERVER
|
||||
REQUIRED_VARS WAYLAND_SERVER_LIBRARY WAYLAND_SERVER_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
WAYLAND_CLIENT_INCLUDE_DIR
|
||||
WAYLAND_CLIENT_LIBRARY
|
||||
WAYLAND_SERVER_INCLUDE_DIR
|
||||
WAYLAND_SERVER_LIBRARY
|
||||
)
|
@ -42,6 +42,8 @@
|
||||
|
||||
#cmakedefine HAVE_CLOCK_GETTIME 1
|
||||
|
||||
#cmakedefine BUILD_WAYLAND 1
|
||||
|
||||
#cmakedefine BUILD_X11 1
|
||||
|
||||
#cmakedefine OWN_WINDOW 1
|
||||
|
@ -120,6 +120,8 @@ set(conky_sources
|
||||
display-http.hh
|
||||
display-x11.cc
|
||||
display-x11.hh
|
||||
display-wayland.cc
|
||||
display-wayland.hh
|
||||
lua-config.cc
|
||||
lua-config.hh
|
||||
setting.cc
|
||||
@ -227,7 +229,7 @@ if(BUILD_PORT_MONITORS)
|
||||
endif(BUILD_PORT_MONITORS)
|
||||
|
||||
if(BUILD_GUI)
|
||||
set(gui fonts.cc fonts.h)
|
||||
set(gui fonts.cc fonts.h gui.cc gui.h)
|
||||
set(optional_sources ${optional_sources} ${gui})
|
||||
endif(BUILD_GUI)
|
||||
|
||||
@ -241,6 +243,23 @@ if(BUILD_X11)
|
||||
endif(BUILD_XINERAMA)
|
||||
endif(BUILD_X11)
|
||||
|
||||
if(BUILD_WAYLAND)
|
||||
set(wl_srcs wl.cc wl.h xdg-shell-protocol.c)
|
||||
set(optional_sources ${optional_sources} ${wl_srcs})
|
||||
# generate protocol implementation
|
||||
set(XDG_PROT_DEF "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml")
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h
|
||||
COMMAND ${WAYLAND_SCANNER} client-header ${XDG_PROT_DEF} xdg-shell-client-protocol.h)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-protocol.c
|
||||
COMMAND ${WAYLAND_SCANNER} private-code ${XDG_PROT_DEF} xdg-shell-protocol.c
|
||||
DEPENDS xdg-shell-client-protocol.h)
|
||||
|
||||
# include output dir in include path
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif(BUILD_WAYLAND)
|
||||
|
||||
if(BUILD_HDDTEMP)
|
||||
set(hddtemp hddtemp.cc hddtemp.h)
|
||||
set(optional_sources ${optional_sources} ${hddtemp})
|
||||
|
@ -83,8 +83,23 @@ unsigned int adjust_colours(unsigned int colour) {
|
||||
return colour;
|
||||
}
|
||||
|
||||
#ifdef BUILD_X11
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
#ifndef BUILD_X11
|
||||
static int hex_nibble_value(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif /* !BUILD_X11 */
|
||||
|
||||
long get_x11_color(const char *name) {
|
||||
#ifdef BUILD_X11
|
||||
XColor color;
|
||||
|
||||
color.pixel = 0;
|
||||
@ -108,9 +123,35 @@ long get_x11_color(const char *name) {
|
||||
}
|
||||
|
||||
return static_cast<long>(color.pixel);
|
||||
#else /*BUILD_X11*/
|
||||
if (name[0] == '#') {
|
||||
name++;
|
||||
}
|
||||
size_t len = strlen(name);
|
||||
if (len == 6 || len == 8)
|
||||
{
|
||||
unsigned char argb[4] = {0xff, 0, 0, 0};
|
||||
for (size_t i = 0; i + 1 < len; i += 2) {
|
||||
int nib1 = hex_nibble_value(name[i]);
|
||||
int nib2 = hex_nibble_value(name[i+1]);
|
||||
if (nib1 < 0 || nib2 < 0) {
|
||||
goto err;
|
||||
}
|
||||
int val = (nib1 << 4) + nib2;
|
||||
|
||||
argb[3 - i / 2] = val;
|
||||
}
|
||||
long out;
|
||||
memcpy(static_cast<void*>(&out), argb, 4);
|
||||
return out;
|
||||
}
|
||||
err:
|
||||
NORM_ERR("can't parse X color '%s'", name);
|
||||
return 0xFF00FF;
|
||||
#endif /*BUILD_X11*/
|
||||
}
|
||||
|
||||
long get_x11_color(const std::string &colour) {
|
||||
return get_x11_color(colour.c_str());
|
||||
}
|
||||
#endif
|
||||
#endif /*BUILD_GUI*/
|
||||
|
14
src/conky.cc
14
src/conky.cc
@ -54,6 +54,9 @@
|
||||
#include <sys/inotify.h>
|
||||
#pragma clang diagnostic pop
|
||||
#endif /* HAVE_SYS_INOTIFY_H */
|
||||
#ifdef BUILD_WAYLAND
|
||||
#include "wl.h"
|
||||
#endif /* BUILD_WAYLAND */
|
||||
#ifdef BUILD_X11
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
||||
@ -90,6 +93,7 @@
|
||||
#include "exec.h"
|
||||
#ifdef BUILD_GUI
|
||||
#include "fonts.h"
|
||||
#include "gui.h"
|
||||
#endif
|
||||
#include "fs.h"
|
||||
#ifdef BUILD_ICONV
|
||||
@ -1930,11 +1934,19 @@ static void set_default_configurations() {
|
||||
info.xmms2.status = nullptr;
|
||||
info.xmms2.playlist = nullptr;
|
||||
#endif /* BUILD_XMMS2 */
|
||||
|
||||
/* Enable a single output by default based on what was enabled at build-time */
|
||||
#ifdef BUILD_WAYLAND
|
||||
state->pushboolean(true);
|
||||
out_to_wayland.lua_set(*state);
|
||||
#else
|
||||
#ifdef BUILD_X11
|
||||
state->pushboolean(true);
|
||||
#ifdef BUILD_GUI
|
||||
out_to_x.lua_set(*state);
|
||||
#else
|
||||
state->pushboolean(true);
|
||||
out_to_stdout.lua_set(*state);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
info.users.number = 1;
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include "irc.h"
|
||||
#endif /* BUILD_IRC */
|
||||
#ifdef BUILD_GUI
|
||||
#include "gui.h"
|
||||
#include "fonts.h"
|
||||
#endif /* BUILD_GUI */
|
||||
#include "fs.h"
|
||||
@ -749,7 +750,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
||||
#endif /* BUILD_GUI */
|
||||
END OBJ(color, nullptr)
|
||||
#ifdef BUILD_GUI
|
||||
if (out_to_x.get(*state)) {
|
||||
if (out_to_gui(*state)) {
|
||||
obj->data.l =
|
||||
arg != nullptr ? get_x11_color(arg) : default_color.get(*state);
|
||||
set_current_text_color(obj->data.l);
|
||||
@ -883,7 +884,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
||||
obj->callbacks.print = &print_cat;
|
||||
obj->callbacks.free = &gen_free_opaque;
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
#ifdef BUILD_X11
|
||||
END OBJ(key_num_lock, 0) obj->callbacks.print = &print_key_num_lock;
|
||||
END OBJ(key_caps_lock, 0) obj->callbacks.print = &print_key_caps_lock;
|
||||
END OBJ(key_scroll_lock, 0) obj->callbacks.print = &print_key_scroll_lock;
|
||||
|
@ -56,6 +56,7 @@ extern void init_ncurses_output();
|
||||
extern void init_file_output();
|
||||
extern void init_http_output();
|
||||
extern void init_x11_output();
|
||||
extern void init_wayland_output();
|
||||
|
||||
/*
|
||||
* The selected and active display output.
|
||||
@ -111,6 +112,7 @@ bool initialize_display_outputs() {
|
||||
init_file_output();
|
||||
init_http_output();
|
||||
init_x11_output();
|
||||
init_wayland_output();
|
||||
|
||||
std::vector<display_output_base *> outputs;
|
||||
outputs.reserve(display_outputs->size());
|
||||
|
1104
src/display-wayland.cc
Normal file
1104
src/display-wayland.cc
Normal file
File diff suppressed because it is too large
Load Diff
89
src/display-wayland.hh
Normal file
89
src/display-wayland.hh
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (C) 2018-2021 François Revol et al.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DISPLAY_WAYLAND_HH
|
||||
#define DISPLAY_WAYLAND_HH
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "display-output.hh"
|
||||
#include "luamm.hh"
|
||||
#include "wl.h"
|
||||
|
||||
namespace conky {
|
||||
|
||||
/*
|
||||
* A base class for Wayland display output.
|
||||
*/
|
||||
class display_output_wayland : public display_output_base {
|
||||
public:
|
||||
explicit display_output_wayland();
|
||||
|
||||
virtual ~display_output_wayland() {}
|
||||
|
||||
// check if available and enabled in settings
|
||||
virtual bool detect();
|
||||
// connect to DISPLAY and other stuff
|
||||
virtual bool initialize();
|
||||
virtual bool shutdown();
|
||||
|
||||
virtual bool main_loop_wait(double);
|
||||
|
||||
virtual void sigterm_cleanup();
|
||||
virtual void cleanup();
|
||||
|
||||
// drawing primitives
|
||||
virtual void set_foreground_color(long);
|
||||
|
||||
virtual int calc_text_width(const char *);
|
||||
|
||||
// GUI interface
|
||||
virtual void draw_string_at(int, int, const char *, int );
|
||||
// X11 lookalikes
|
||||
virtual void set_line_style(int, bool);
|
||||
virtual void set_dashes(char *);
|
||||
virtual void draw_line(int, int, int, int);
|
||||
virtual void draw_rect(int, int, int, int);
|
||||
virtual void fill_rect(int, int, int, int);
|
||||
virtual void draw_arc(int, int, int, int, int, int);
|
||||
virtual void move_win(int, int);
|
||||
virtual int dpi_scale(int);
|
||||
|
||||
virtual void end_draw_stuff();
|
||||
virtual void clear_text(int);
|
||||
|
||||
virtual int font_height(unsigned int);
|
||||
virtual int font_ascent(unsigned int);
|
||||
virtual int font_descent(unsigned int);
|
||||
virtual void setup_fonts(void);
|
||||
virtual void set_font(unsigned int);
|
||||
virtual void free_fonts(bool);
|
||||
virtual void load_fonts(bool);
|
||||
|
||||
// Wayland-specific
|
||||
};
|
||||
|
||||
} // namespace conky
|
||||
|
||||
#endif /* DISPLAY_WAYLAND_HH */
|
11
src/fonts.cc
11
src/fonts.cc
@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "fonts.h"
|
||||
#include "gui.h"
|
||||
#include "display-output.hh"
|
||||
#include "logging.h"
|
||||
|
||||
@ -40,7 +41,7 @@ void font_setting::lua_setter(lua::state &l, bool init) {
|
||||
|
||||
Base::lua_setter(l, init);
|
||||
|
||||
if (init && out_to_x.get(*state)) {
|
||||
if (init) {
|
||||
if (fonts.empty()) { fonts.resize(1); }
|
||||
fonts[0].name = do_convert(l, -1).first;
|
||||
}
|
||||
@ -66,7 +67,7 @@ void setup_fonts() {
|
||||
}
|
||||
|
||||
int add_font(const char *data_in) {
|
||||
if (!out_to_x.get(*state)) { return 0; }
|
||||
if (!out_to_gui(*state)) { return 0; }
|
||||
fonts.emplace_back();
|
||||
fonts.rbegin()->name = data_in;
|
||||
|
||||
@ -85,16 +86,16 @@ void load_fonts(bool utf8) {
|
||||
}
|
||||
|
||||
int font_height() {
|
||||
assert(selected_font < fonts.size());
|
||||
//assert(selected_font < fonts.size());
|
||||
return display_output()->font_height(selected_font);
|
||||
}
|
||||
|
||||
int font_ascent() {
|
||||
assert(selected_font < fonts.size());
|
||||
//assert(selected_font < fonts.size());
|
||||
return display_output()->font_ascent(selected_font);
|
||||
}
|
||||
|
||||
int font_descent() {
|
||||
assert(selected_font < fonts.size());
|
||||
//assert(selected_font < fonts.size());
|
||||
return display_output()->font_descent(selected_font);
|
||||
}
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "conky.h"
|
||||
#include "x11.h"
|
||||
|
||||
/* for fonts */
|
||||
struct font_list {
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#ifdef BUILD_X11
|
||||
#include "x11.h"
|
||||
#include "gui.h"
|
||||
#endif /* BUILD_X11 */
|
||||
|
||||
namespace conky {
|
||||
|
259
src/gui.cc
Normal file
259
src/gui.cc
Normal file
@ -0,0 +1,259 @@
|
||||
/*
|
||||
*
|
||||
* 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-2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
#include "gui.h"
|
||||
#include "wl.h"
|
||||
|
||||
#ifdef BUILD_IMLIB2
|
||||
#include "imlib2.h"
|
||||
#endif /* BUILD_IMLIB2 */
|
||||
#ifndef OWN_WINDOW
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
bool have_argb_visual;
|
||||
#endif /* BUILD_ARGB */
|
||||
|
||||
/* basic display attributes */
|
||||
int display_width;
|
||||
int display_height;
|
||||
int screen;
|
||||
|
||||
/* workarea where window / text is aligned (from _NET_WORKAREA on X11) */
|
||||
int workarea[4];
|
||||
|
||||
/* Window stuff */
|
||||
char window_created = 0;
|
||||
|
||||
/* local prototypes */
|
||||
#ifdef BUILD_X11
|
||||
void x11_init_window(lua::state &l, bool own);
|
||||
#endif /*BUILD_X11*/
|
||||
|
||||
/********************* <SETTINGS> ************************/
|
||||
|
||||
|
||||
priv::colour_setting background_colour("own_window_colour", 0);
|
||||
|
||||
bool out_to_gui(lua::state &l) {
|
||||
bool to_gui = false;
|
||||
#ifdef BUILD_X11
|
||||
to_gui |= out_to_x.get(l);
|
||||
#endif /* BUILD_X11 */
|
||||
#ifdef BUILD_WAYLAND
|
||||
to_gui |= out_to_wayland.get(l);
|
||||
#endif /* BUILD_WAYLAND */
|
||||
return to_gui;
|
||||
}
|
||||
|
||||
namespace priv {
|
||||
void own_window_setting::lua_setter(lua::state &l, bool init) {
|
||||
lua::stack_sentry s(l, -2);
|
||||
|
||||
Base::lua_setter(l, init);
|
||||
|
||||
if (init) {
|
||||
if (do_convert(l, -1).first) {
|
||||
#ifndef OWN_WINDOW
|
||||
std::cerr << "Support for the own_window setting has been "
|
||||
"disabled during compilation\n";
|
||||
l.pop();
|
||||
l.pushboolean(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (out_to_gui(l)) {
|
||||
#ifdef BUILD_X11
|
||||
x11_init_window(l, do_convert(l, -1).first);
|
||||
#endif /*BUILD_X11*/
|
||||
} else {
|
||||
// own_window makes no sense when not drawing to X
|
||||
l.pop();
|
||||
l.pushboolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
void colour_setting::lua_setter(lua::state &l, bool init) {
|
||||
lua::stack_sentry s(l, -2);
|
||||
Base::lua_setter(l, init);
|
||||
++s;
|
||||
}
|
||||
} // namespace priv
|
||||
|
||||
template <>
|
||||
conky::lua_traits<alignment>::Map conky::lua_traits<alignment>::map = {
|
||||
{"top_left", TOP_LEFT},
|
||||
{"top_right", TOP_RIGHT},
|
||||
{"top_middle", TOP_MIDDLE},
|
||||
{"bottom_left", BOTTOM_LEFT},
|
||||
{"bottom_right", BOTTOM_RIGHT},
|
||||
{"bottom_middle", BOTTOM_MIDDLE},
|
||||
{"middle_left", MIDDLE_LEFT},
|
||||
{"middle_middle", MIDDLE_MIDDLE},
|
||||
{"middle_right", MIDDLE_RIGHT},
|
||||
{"tl", TOP_LEFT},
|
||||
{"tr", TOP_RIGHT},
|
||||
{"tm", TOP_MIDDLE},
|
||||
{"bl", BOTTOM_LEFT},
|
||||
{"br", BOTTOM_RIGHT},
|
||||
{"bm", BOTTOM_MIDDLE},
|
||||
{"ml", MIDDLE_LEFT},
|
||||
{"mm", MIDDLE_MIDDLE},
|
||||
{"mr", MIDDLE_RIGHT},
|
||||
{"none", NONE}};
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
template <>
|
||||
conky::lua_traits<window_type>::Map conky::lua_traits<window_type>::map = {
|
||||
{"normal", TYPE_NORMAL},
|
||||
{"dock", TYPE_DOCK},
|
||||
{"panel", TYPE_PANEL},
|
||||
{"desktop", TYPE_DESKTOP},
|
||||
{"override", TYPE_OVERRIDE}};
|
||||
|
||||
template <>
|
||||
conky::lua_traits<window_hints>::Map conky::lua_traits<window_hints>::map = {
|
||||
{"undecorated", HINT_UNDECORATED},
|
||||
{"below", HINT_BELOW},
|
||||
{"above", HINT_ABOVE},
|
||||
{"sticky", HINT_STICKY},
|
||||
{"skip_taskbar", HINT_SKIP_TASKBAR},
|
||||
{"skip_pager", HINT_SKIP_PAGER}};
|
||||
|
||||
std::pair<uint16_t, bool> window_hints_traits::convert(
|
||||
lua::state &l, int index, const std::string &name) {
|
||||
lua::stack_sentry s(l);
|
||||
l.checkstack(1);
|
||||
|
||||
std::string hints = l.tostring(index);
|
||||
// add a sentinel to simplify the following loop
|
||||
hints += ',';
|
||||
size_t pos = 0;
|
||||
size_t newpos;
|
||||
uint16_t ret = 0;
|
||||
while ((newpos = hints.find_first_of(", ", pos)) != std::string::npos) {
|
||||
if (newpos > pos) {
|
||||
l.pushstring(hints.substr(pos, newpos - pos));
|
||||
auto t = conky::lua_traits<window_hints>::convert(l, -1, name);
|
||||
if (!t.second) { return {0, false}; }
|
||||
SET_HINT(ret, t.first);
|
||||
l.pop();
|
||||
}
|
||||
pos = newpos + 1;
|
||||
}
|
||||
return {ret, true};
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
namespace {
|
||||
// used to set the default value for own_window_title
|
||||
std::string gethostnamecxx() {
|
||||
update_uname();
|
||||
return info.uname_s.nodename;
|
||||
}
|
||||
} // namespace
|
||||
#endif /* OWN_WINDOW */
|
||||
|
||||
/*
|
||||
* The order of these settings cannot be completely arbitrary. Some of them
|
||||
* depend on others, and the setters are called in the order in which they are
|
||||
* defined. The order should be: x11_display_name -> out_to_x -> everything colour
|
||||
* related
|
||||
* -> border_*, own_window_*, etc -> own_window ->
|
||||
* double_buffer -> imlib_cache_size
|
||||
*/
|
||||
|
||||
conky::simple_config_setting<alignment> text_alignment("alignment", BOTTOM_LEFT,
|
||||
false);
|
||||
conky::simple_config_setting<int> head_index("xinerama_head", 0, true);
|
||||
|
||||
conky::simple_config_setting<std::string> display_name("display", std::string(),
|
||||
false);
|
||||
|
||||
priv::colour_setting color[10] = {{"color0", 0xffffff}, {"color1", 0xffffff},
|
||||
{"color2", 0xffffff}, {"color3", 0xffffff},
|
||||
{"color4", 0xffffff}, {"color5", 0xffffff},
|
||||
{"color6", 0xffffff}, {"color7", 0xffffff},
|
||||
{"color8", 0xffffff}, {"color9", 0xffffff}};
|
||||
priv::colour_setting default_color("default_color", 0xffffff);
|
||||
priv::colour_setting default_shade_color("default_shade_color", 0x000000);
|
||||
priv::colour_setting default_outline_color("default_outline_color", 0x000000);
|
||||
|
||||
conky::range_config_setting<int> border_inner_margin(
|
||||
"border_inner_margin", 0, std::numeric_limits<int>::max(), 3, true);
|
||||
conky::range_config_setting<int> border_outer_margin(
|
||||
"border_outer_margin", 0, std::numeric_limits<int>::max(), 1, true);
|
||||
conky::range_config_setting<int> border_width("border_width", 0,
|
||||
std::numeric_limits<int>::max(),
|
||||
1, true);
|
||||
|
||||
conky::simple_config_setting<bool> forced_redraw("forced_redraw", false, false);
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
conky::simple_config_setting<bool> set_transparent("own_window_transparent",
|
||||
false, false);
|
||||
conky::simple_config_setting<std::string> own_window_class("own_window_class",
|
||||
PACKAGE_NAME, false);
|
||||
|
||||
conky::simple_config_setting<std::string> own_window_title(
|
||||
"own_window_title", PACKAGE_NAME " (" + gethostnamecxx() + ")", false);
|
||||
|
||||
conky::simple_config_setting<window_type> own_window_type("own_window_type",
|
||||
TYPE_NORMAL, false);
|
||||
conky::simple_config_setting<uint16_t, window_hints_traits> own_window_hints(
|
||||
"own_window_hints", 0, false);
|
||||
|
||||
priv::colour_setting background_colour("own_window_colour", 0);
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
conky::simple_config_setting<bool> use_argb_visual("own_window_argb_visual",
|
||||
false, false);
|
||||
conky::range_config_setting<int> own_window_argb_value("own_window_argb_value",
|
||||
0, 255, 255, false);
|
||||
#endif /* BUILD_ARGB */
|
||||
#endif /* OWN_WINDOW */
|
||||
priv::own_window_setting own_window;
|
||||
|
||||
#ifdef BUILD_IMLIB2
|
||||
/*
|
||||
* the only reason this is not in imlib2.cc is so that we can be sure it's
|
||||
* setter executes after use_xdbe
|
||||
*/
|
||||
imlib_cache_size_setting imlib_cache_size;
|
||||
#endif
|
||||
/******************** </SETTINGS> ************************/
|
181
src/gui.h
Normal file
181
src/gui.h
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
*
|
||||
* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2005-2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
#ifndef GUI_H_
|
||||
#define GUI_H_
|
||||
|
||||
#include "colours.h"
|
||||
#include "setting.hh"
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
enum window_type {
|
||||
TYPE_NORMAL = 0,
|
||||
TYPE_DOCK,
|
||||
TYPE_PANEL,
|
||||
TYPE_DESKTOP,
|
||||
TYPE_OVERRIDE
|
||||
};
|
||||
|
||||
enum window_hints {
|
||||
HINT_UNDECORATED = 0,
|
||||
HINT_BELOW,
|
||||
HINT_ABOVE,
|
||||
HINT_STICKY,
|
||||
HINT_SKIP_TASKBAR,
|
||||
HINT_SKIP_PAGER
|
||||
};
|
||||
#endif /*OWN_WINDOW*/
|
||||
|
||||
#if defined(BUILD_ARGB) && defined(OWN_WINDOW)
|
||||
/* true if use_argb_visual=true and argb visual was found*/
|
||||
extern bool have_argb_visual;
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_X11
|
||||
extern Display *display;
|
||||
#endif
|
||||
extern int display_width;
|
||||
extern int display_height;
|
||||
extern int screen;
|
||||
extern int workarea[4];
|
||||
|
||||
extern char window_created;
|
||||
|
||||
void destroy_window(void);
|
||||
void create_gc(void);
|
||||
void set_struts(int);
|
||||
|
||||
bool out_to_gui(lua::state &l);
|
||||
|
||||
void print_monitor(struct text_object *, char *, unsigned int);
|
||||
void print_monitor_number(struct text_object *, char *, unsigned int);
|
||||
void print_desktop(struct text_object *, char *, unsigned int);
|
||||
void print_desktop_number(struct text_object *, char *, unsigned int);
|
||||
void print_desktop_name(struct text_object *, char *, unsigned int);
|
||||
|
||||
/* Num lock, Scroll lock, Caps Lock */
|
||||
void print_key_num_lock(struct text_object *, char *, unsigned int);
|
||||
void print_key_caps_lock(struct text_object *, char *, unsigned int);
|
||||
void print_key_scroll_lock(struct text_object *, char *, unsigned int);
|
||||
|
||||
/* Keyboard layout and mouse speed in percentage */
|
||||
void print_keyboard_layout(struct text_object *, char *, unsigned int);
|
||||
void print_mouse_speed(struct text_object *, char *, unsigned int);
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
void xdbe_swap_buffers(void);
|
||||
#else
|
||||
void xpmdb_swap_buffers(void);
|
||||
#endif /* BUILD_XDBE */
|
||||
|
||||
/* alignments */
|
||||
enum alignment {
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
TOP_MIDDLE,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT,
|
||||
BOTTOM_MIDDLE,
|
||||
MIDDLE_LEFT,
|
||||
MIDDLE_MIDDLE,
|
||||
MIDDLE_RIGHT,
|
||||
NONE
|
||||
};
|
||||
|
||||
extern conky::simple_config_setting<alignment> text_alignment;
|
||||
|
||||
namespace priv {
|
||||
class own_window_setting : public conky::simple_config_setting<bool> {
|
||||
typedef conky::simple_config_setting<bool> Base;
|
||||
|
||||
protected:
|
||||
virtual void lua_setter(lua::state &l, bool init);
|
||||
|
||||
public:
|
||||
own_window_setting() : Base("own_window", false, false) {}
|
||||
};
|
||||
|
||||
struct colour_traits {
|
||||
static const lua::Type type = lua::TSTRING;
|
||||
typedef unsigned long Type;
|
||||
|
||||
static inline std::pair<Type, bool> convert(lua::state &l, int index,
|
||||
const std::string &) {
|
||||
return {get_x11_color(l.tostring(index)), true};
|
||||
}
|
||||
};
|
||||
|
||||
class colour_setting
|
||||
: public conky::simple_config_setting<unsigned long, colour_traits> {
|
||||
typedef conky::simple_config_setting<unsigned long, colour_traits> Base;
|
||||
|
||||
protected:
|
||||
virtual void lua_setter(lua::state &l, bool init);
|
||||
|
||||
public:
|
||||
colour_setting(const std::string &name_, unsigned long default_value_ = 0)
|
||||
: Base(name_, default_value_, true) {}
|
||||
};
|
||||
} // namespace priv
|
||||
|
||||
extern conky::simple_config_setting<std::string> display_name;
|
||||
extern conky::simple_config_setting<int> head_index;
|
||||
extern priv::colour_setting color[10];
|
||||
extern priv::colour_setting default_color;
|
||||
extern priv::colour_setting default_shade_color;
|
||||
extern priv::colour_setting default_outline_color;
|
||||
|
||||
extern conky::range_config_setting<int> border_inner_margin;
|
||||
extern conky::range_config_setting<int> border_outer_margin;
|
||||
extern conky::range_config_setting<int> border_width;
|
||||
|
||||
extern conky::simple_config_setting<bool> forced_redraw;
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
extern conky::simple_config_setting<bool> set_transparent;
|
||||
extern conky::simple_config_setting<std::string> own_window_class;
|
||||
extern conky::simple_config_setting<std::string> own_window_title;
|
||||
extern conky::simple_config_setting<window_type> own_window_type;
|
||||
|
||||
struct window_hints_traits {
|
||||
static const lua::Type type = lua::TSTRING;
|
||||
typedef uint16_t Type;
|
||||
static std::pair<Type, bool> convert(lua::state &l, int index,
|
||||
const std::string &name);
|
||||
};
|
||||
extern conky::simple_config_setting<uint16_t, window_hints_traits>
|
||||
own_window_hints;
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
extern conky::simple_config_setting<bool> use_argb_visual;
|
||||
|
||||
/* range of 0-255 for alpha */
|
||||
extern conky::range_config_setting<int> own_window_argb_value;
|
||||
#endif /*BUILD_ARGB*/
|
||||
#endif /*OWN_WINDOW*/
|
||||
extern priv::own_window_setting own_window;
|
||||
|
||||
#endif /*GUI_H_*/
|
||||
#endif /* BUILD_GUI */
|
18
src/llua.cc
18
src/llua.cc
@ -27,6 +27,14 @@
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
|
||||
#ifdef BUILD_X11
|
||||
#include "x11.h"
|
||||
#endif /* BUILD_X11 */
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
#include "gui.h"
|
||||
#endif /* BUILD_GUI */
|
||||
|
||||
extern "C" {
|
||||
#include <tolua++.h>
|
||||
}
|
||||
@ -485,13 +493,20 @@ void llua_setup_window_table(int text_start_x, int text_start_y, int text_width,
|
||||
if (lua_L == nullptr) { return; }
|
||||
lua_newtable(lua_L);
|
||||
|
||||
#ifdef BUILD_X11
|
||||
if (out_to_x.get(*state)) {
|
||||
llua_set_userdata("drawable", "Drawable", (void *)&window.drawable);
|
||||
llua_set_userdata("visual", "Visual", window.visual);
|
||||
llua_set_userdata("display", "Display", display);
|
||||
}
|
||||
#endif /*BUILD_X11*/
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
if (out_to_gui(*state)) {
|
||||
#ifdef BUILD_X11
|
||||
llua_set_number("width", window.width);
|
||||
llua_set_number("height", window.height);
|
||||
#endif /*BUILD_X11*/
|
||||
llua_set_number("border_inner_margin", border_inner_margin.get(*state));
|
||||
llua_set_number("border_outer_margin", border_outer_margin.get(*state));
|
||||
llua_set_number("border_width", border_width.get(*state));
|
||||
@ -503,6 +518,7 @@ void llua_setup_window_table(int text_start_x, int text_start_y, int text_width,
|
||||
|
||||
lua_setglobal(lua_L, "conky_window");
|
||||
}
|
||||
#endif /*BUILD_GUI*/
|
||||
}
|
||||
|
||||
void llua_update_window_table(int text_start_x, int text_start_y,
|
||||
@ -516,8 +532,10 @@ void llua_update_window_table(int text_start_x, int text_start_y,
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BUILD_X11
|
||||
llua_set_number("width", window.width);
|
||||
llua_set_number("height", window.height);
|
||||
#endif /*BUILD_X11*/
|
||||
|
||||
llua_set_number("text_start_x", text_start_x);
|
||||
llua_set_number("text_start_y", text_start_y);
|
||||
|
@ -32,10 +32,6 @@ extern "C" {
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef BUILD_X11
|
||||
#include "x11.h"
|
||||
#endif /* BUILD_X11 */
|
||||
|
||||
#define LUAPREFIX "conky_"
|
||||
|
||||
#ifdef HAVE_SYS_INOTIFY_H
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "logging.h"
|
||||
#include "specials.h"
|
||||
#include "text_object.h"
|
||||
#include "x11.h"
|
||||
|
||||
/**
|
||||
* Length of a character in bytes.
|
||||
|
@ -28,6 +28,7 @@
|
||||
*/
|
||||
#include "conky.h"
|
||||
#ifdef BUILD_GUI
|
||||
#include "gui.h"
|
||||
#include "fonts.h"
|
||||
#endif /* BUILD_GUI */
|
||||
#include <cmath>
|
||||
@ -389,7 +390,7 @@ void new_gauge_in_shell(struct text_object *obj, char *p,
|
||||
}
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
void new_gauge_in_x11(struct text_object *obj, char *buf, double usage) {
|
||||
void new_gauge_in_gui(struct text_object *obj, char *buf, double usage) {
|
||||
struct special_t *s = nullptr;
|
||||
auto *g = static_cast<struct gauge *>(obj->special_data);
|
||||
|
||||
@ -420,7 +421,7 @@ void new_gauge(struct text_object *obj, char *p, unsigned int p_max_size,
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
if (display_output() && display_output()->graphical()) {
|
||||
new_gauge_in_x11(obj, p, usage);
|
||||
new_gauge_in_gui(obj, p, usage);
|
||||
}
|
||||
if (out_to_stdout.get(*state)) {
|
||||
new_gauge_in_shell(obj, p, p_max_size, usage);
|
||||
@ -705,7 +706,7 @@ static void new_bar_in_shell(struct text_object *obj, char *buffer,
|
||||
}
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
static void new_bar_in_x11(struct text_object *obj, char *buf, double usage) {
|
||||
static void new_bar_in_gui(struct text_object *obj, char *buf, double usage) {
|
||||
struct special_t *s = nullptr;
|
||||
auto *b = static_cast<struct bar *>(obj->special_data);
|
||||
|
||||
@ -737,7 +738,7 @@ void new_bar(struct text_object *obj, char *p, unsigned int p_max_size,
|
||||
|
||||
#ifdef BUILD_GUI
|
||||
if (display_output() && display_output()->graphical()) {
|
||||
new_bar_in_x11(obj, p, usage);
|
||||
new_bar_in_gui(obj, p, usage);
|
||||
}
|
||||
if (out_to_stdout.get(*state)) {
|
||||
new_bar_in_shell(obj, p, p_max_size, usage);
|
||||
|
118
src/wl.cc
Normal file
118
src/wl.cc
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
*
|
||||
* 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-2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "conky.h"
|
||||
#include "wl.h"
|
||||
|
||||
#ifdef BUILD_WAYLAND
|
||||
|
||||
namespace priv {
|
||||
void out_to_wayland_setting::lua_setter(lua::state &l, bool init) {
|
||||
lua::stack_sentry s(l, -2);
|
||||
|
||||
Base::lua_setter(l, init);
|
||||
|
||||
if (init && do_convert(l, -1).first) {
|
||||
//init
|
||||
}
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
void out_to_wayland_setting::cleanup(lua::state &l) {
|
||||
lua::stack_sentry s(l, -1);
|
||||
|
||||
if (do_convert(l, -1).first) {
|
||||
//deinit
|
||||
}
|
||||
|
||||
l.pop();
|
||||
}
|
||||
} // namespace priv
|
||||
|
||||
priv::out_to_wayland_setting out_to_wayland;
|
||||
|
||||
static const char NOT_IN_WAYLAND[] = "Not running in Wayland";
|
||||
|
||||
void print_monitor(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
|
||||
if (!out_to_wayland.get(*state)) {
|
||||
strncpy(p, NOT_IN_WAYLAND, p_max_size);
|
||||
return;
|
||||
}
|
||||
snprintf(p, p_max_size, "%d", -1);
|
||||
}
|
||||
|
||||
void print_monitor_number(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
|
||||
if (!out_to_wayland.get(*state)) {
|
||||
strncpy(p, NOT_IN_WAYLAND, p_max_size);
|
||||
return;
|
||||
}
|
||||
snprintf(p, p_max_size, "%d", -1);
|
||||
}
|
||||
|
||||
void print_desktop(struct text_object *obj, char *p, unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
|
||||
if (!out_to_wayland.get(*state)) {
|
||||
strncpy(p, NOT_IN_WAYLAND, p_max_size);
|
||||
return;
|
||||
}
|
||||
snprintf(p, p_max_size, "%d", -1);
|
||||
}
|
||||
|
||||
void print_desktop_number(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
|
||||
if (!out_to_wayland.get(*state)) {
|
||||
strncpy(p, NOT_IN_WAYLAND, p_max_size);
|
||||
return;
|
||||
}
|
||||
snprintf(p, p_max_size, "%d", -1);
|
||||
}
|
||||
|
||||
void print_desktop_name(struct text_object *obj, char *p,
|
||||
unsigned int p_max_size) {
|
||||
(void)obj;
|
||||
|
||||
if (!out_to_wayland.get(*state)) {
|
||||
strncpy(p, NOT_IN_WAYLAND, p_max_size);
|
||||
} else {
|
||||
strncpy(p, "NYI", p_max_size);
|
||||
}
|
||||
}
|
||||
#endif
|
52
src/wl.h
Normal file
52
src/wl.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
*
|
||||
* 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-2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(BUILD_WAYLAND) && !defined(CONKY_WL_H)
|
||||
#define CONKY_WL_H
|
||||
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include "setting.hh"
|
||||
|
||||
namespace priv {
|
||||
class out_to_wayland_setting : public conky::simple_config_setting<bool> {
|
||||
typedef conky::simple_config_setting<bool> Base;
|
||||
|
||||
protected:
|
||||
virtual void lua_setter(lua::state &l, bool init);
|
||||
virtual void cleanup(lua::state &l);
|
||||
|
||||
public:
|
||||
out_to_wayland_setting() : Base("out_to_wayland", false, false) {}
|
||||
};
|
||||
} // namespace priv
|
||||
|
||||
extern priv::out_to_wayland_setting out_to_wayland;
|
||||
|
||||
#endif /* CONKY_WL_H */
|
102
src/x11.cc
102
src/x11.cc
@ -58,22 +58,11 @@
|
||||
#include <X11/extensions/shape.h>
|
||||
#endif /* BUILD_XSHAPE */
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
bool have_argb_visual;
|
||||
#endif /* BUILD_ARGB */
|
||||
|
||||
/* some basic X11 stuff */
|
||||
Display *display = nullptr;
|
||||
int display_width;
|
||||
int display_height;
|
||||
int screen;
|
||||
|
||||
/* workarea from _NET_WORKAREA, this is where window / text is aligned */
|
||||
int workarea[4];
|
||||
|
||||
/* Window stuff */
|
||||
struct conky_window window;
|
||||
char window_created = 0;
|
||||
struct conky_x11_window window;
|
||||
|
||||
/* local prototypes */
|
||||
static void update_workarea();
|
||||
@ -81,7 +70,6 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop);
|
||||
static Window find_subwindow(Window win, int w, int h);
|
||||
static void init_X11();
|
||||
static void deinit_X11();
|
||||
static void init_window(lua::state &l, bool own);
|
||||
|
||||
/********************* <SETTINGS> ************************/
|
||||
namespace priv {
|
||||
@ -103,33 +91,6 @@ void out_to_x_setting::cleanup(lua::state &l) {
|
||||
l.pop();
|
||||
}
|
||||
|
||||
void own_window_setting::lua_setter(lua::state &l, bool init) {
|
||||
lua::stack_sentry s(l, -2);
|
||||
|
||||
Base::lua_setter(l, init);
|
||||
|
||||
if (init) {
|
||||
if (do_convert(l, -1).first) {
|
||||
#ifndef OWN_WINDOW
|
||||
std::cerr << "Support for the own_window setting has been "
|
||||
"disabled during compilation\n";
|
||||
l.pop();
|
||||
l.pushboolean(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (out_to_x.get(l)) {
|
||||
init_window(l, do_convert(l, -1).first);
|
||||
} else {
|
||||
// own_window makes no sense when not drawing to X
|
||||
l.pop();
|
||||
l.pushboolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
bool use_xdbe_setting::set_up(lua::state &l) {
|
||||
// double_buffer makes no sense when not drawing to X
|
||||
@ -210,19 +171,6 @@ void use_xpmdb_setting::lua_setter(lua::state &l, bool init) {
|
||||
++s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void colour_setting::lua_setter(lua::state &l, bool init) {
|
||||
lua::stack_sentry s(l, -2);
|
||||
|
||||
if (!out_to_x.get(l)) {
|
||||
// ignore if we're not using X
|
||||
l.replace(-2);
|
||||
} else {
|
||||
Base::lua_setter(l, init);
|
||||
}
|
||||
|
||||
++s;
|
||||
}
|
||||
} // namespace priv
|
||||
|
||||
template <>
|
||||
@ -300,38 +248,9 @@ std::string gethostnamecxx() {
|
||||
} // namespace
|
||||
#endif /* OWN_WINDOW */
|
||||
|
||||
/*
|
||||
* The order of these settings cannot be completely arbitrary. Some of them
|
||||
* depend on others, and the setters are called in the order in which they are
|
||||
* defined. The order should be: display_name -> out_to_x -> everything colour
|
||||
* related
|
||||
* -> border_*, own_window_*, etc -> own_window ->
|
||||
* double_buffer -> imlib_cache_size
|
||||
*/
|
||||
|
||||
conky::simple_config_setting<alignment> text_alignment("alignment", BOTTOM_LEFT,
|
||||
false);
|
||||
conky::simple_config_setting<std::string> display_name("display", std::string(),
|
||||
false);
|
||||
conky::simple_config_setting<int> head_index("xinerama_head", 0, true);
|
||||
priv::out_to_x_setting out_to_x;
|
||||
|
||||
priv::colour_setting color[10] = {{"color0", 0xffffff}, {"color1", 0xffffff},
|
||||
{"color2", 0xffffff}, {"color3", 0xffffff},
|
||||
{"color4", 0xffffff}, {"color5", 0xffffff},
|
||||
{"color6", 0xffffff}, {"color7", 0xffffff},
|
||||
{"color8", 0xffffff}, {"color9", 0xffffff}};
|
||||
priv::colour_setting default_color("default_color", 0xffffff);
|
||||
priv::colour_setting default_shade_color("default_shade_color", 0x000000);
|
||||
priv::colour_setting default_outline_color("default_outline_color", 0x000000);
|
||||
|
||||
conky::range_config_setting<int> border_inner_margin(
|
||||
"border_inner_margin", 0, std::numeric_limits<int>::max(), 3, true);
|
||||
conky::range_config_setting<int> border_outer_margin(
|
||||
"border_outer_margin", 0, std::numeric_limits<int>::max(), 1, true);
|
||||
conky::range_config_setting<int> border_width("border_width", 0,
|
||||
std::numeric_limits<int>::max(),
|
||||
1, true);
|
||||
#ifdef BUILD_XFT
|
||||
conky::simple_config_setting<bool> use_xft("use_xft", false, false);
|
||||
#endif
|
||||
@ -339,21 +258,11 @@ conky::simple_config_setting<bool> use_xft("use_xft", false, false);
|
||||
conky::simple_config_setting<bool> forced_redraw("forced_redraw", false, false);
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
conky::simple_config_setting<bool> set_transparent("own_window_transparent",
|
||||
false, false);
|
||||
conky::simple_config_setting<std::string> own_window_class("own_window_class",
|
||||
PACKAGE_NAME, false);
|
||||
|
||||
conky::simple_config_setting<std::string> own_window_title(
|
||||
"own_window_title", PACKAGE_NAME " (" + gethostnamecxx() + ")", false);
|
||||
|
||||
conky::simple_config_setting<window_type> own_window_type("own_window_type",
|
||||
conky::simple_config_setting<window_type> own_window_x11_type("own_window_type",
|
||||
TYPE_NORMAL, false);
|
||||
conky::simple_config_setting<uint16_t, window_hints_traits> own_window_hints(
|
||||
conky::simple_config_setting<uint16_t, window_hints_traits> own_window_x11_hints(
|
||||
"own_window_hints", 0, false);
|
||||
|
||||
priv::colour_setting background_colour("own_window_colour", 0);
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
conky::simple_config_setting<bool> use_argb_visual("own_window_argb_visual",
|
||||
false, false);
|
||||
@ -361,7 +270,6 @@ conky::range_config_setting<int> own_window_argb_value("own_window_argb_value",
|
||||
0, 255, 255, false);
|
||||
#endif /* BUILD_ARGB */
|
||||
#endif /* OWN_WINDOW */
|
||||
priv::own_window_setting own_window;
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
priv::use_xdbe_setting use_xdbe;
|
||||
@ -636,10 +544,10 @@ void destroy_window() {
|
||||
if (window.xftdraw != nullptr) { XftDrawDestroy(window.xftdraw); }
|
||||
#endif /* BUILD_XFT */
|
||||
if (window.gc != nullptr) { XFreeGC(display, window.gc); }
|
||||
memset(&window, 0, sizeof(struct conky_window));
|
||||
memset(&window, 0, sizeof(struct conky_x11_window));
|
||||
}
|
||||
|
||||
static void init_window(lua::state &l __attribute__((unused)), bool own) {
|
||||
void x11_init_window(lua::state &l __attribute__((unused)), bool own) {
|
||||
DBGP("enter init_window()");
|
||||
// own is unused if OWN_WINDOW is not defined
|
||||
(void)own;
|
||||
|
127
src/x11.h
127
src/x11.h
@ -66,7 +66,9 @@ enum window_hints {
|
||||
#define TEST_HINT(mask, hint) (mask & (1 << (hint)))
|
||||
#endif
|
||||
|
||||
struct conky_window {
|
||||
extern Display *display;
|
||||
|
||||
struct conky_x11_window {
|
||||
Window root, window, desktop;
|
||||
Drawable drawable;
|
||||
Visual *visual;
|
||||
@ -75,12 +77,12 @@ struct conky_window {
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
XdbeBackBuffer back_buffer;
|
||||
#else
|
||||
#else /*BUILD_XDBE*/
|
||||
Pixmap back_buffer;
|
||||
#endif
|
||||
#endif /*BUILD_XDBE*/
|
||||
#ifdef BUILD_XFT
|
||||
XftDraw *xftdraw;
|
||||
#endif
|
||||
#endif /*BUILD_XFT*/
|
||||
|
||||
int width;
|
||||
int height;
|
||||
@ -90,41 +92,14 @@ struct conky_window {
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(BUILD_ARGB) && defined(OWN_WINDOW)
|
||||
/* true if use_argb_visual=true and argb visual was found*/
|
||||
extern bool have_argb_visual;
|
||||
#endif
|
||||
|
||||
extern Display *display;
|
||||
extern int display_width;
|
||||
extern int display_height;
|
||||
extern int screen;
|
||||
|
||||
extern int workarea[4];
|
||||
|
||||
extern struct conky_window window;
|
||||
extern char window_created;
|
||||
extern struct conky_x11_window window;
|
||||
|
||||
void destroy_window(void);
|
||||
void create_gc(void);
|
||||
void set_transparent_background(Window win);
|
||||
void get_x11_desktop_info(Display *current_display, Atom atom);
|
||||
void set_struts(int);
|
||||
|
||||
void print_monitor(struct text_object *, char *, unsigned int);
|
||||
void print_monitor_number(struct text_object *, char *, unsigned int);
|
||||
void print_desktop(struct text_object *, char *, unsigned int);
|
||||
void print_desktop_number(struct text_object *, char *, unsigned int);
|
||||
void print_desktop_name(struct text_object *, char *, unsigned int);
|
||||
|
||||
/* Num lock, Scroll lock, Caps Lock */
|
||||
void print_key_num_lock(struct text_object *, char *, unsigned int);
|
||||
void print_key_caps_lock(struct text_object *, char *, unsigned int);
|
||||
void print_key_scroll_lock(struct text_object *, char *, unsigned int);
|
||||
|
||||
/* Keyboard layout and mouse speed in percentage */
|
||||
void print_keyboard_layout(struct text_object *, char *, unsigned int);
|
||||
void print_mouse_speed(struct text_object *, char *, unsigned int);
|
||||
void x11_init_window(lua::state &l, bool own);
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
void xdbe_swap_buffers(void);
|
||||
@ -132,22 +107,6 @@ void xdbe_swap_buffers(void);
|
||||
void xpmdb_swap_buffers(void);
|
||||
#endif /* BUILD_XDBE */
|
||||
|
||||
/* alignments */
|
||||
enum alignment {
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
TOP_MIDDLE,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT,
|
||||
BOTTOM_MIDDLE,
|
||||
MIDDLE_LEFT,
|
||||
MIDDLE_MIDDLE,
|
||||
MIDDLE_RIGHT,
|
||||
NONE
|
||||
};
|
||||
|
||||
extern conky::simple_config_setting<alignment> text_alignment;
|
||||
|
||||
namespace priv {
|
||||
class out_to_x_setting : public conky::simple_config_setting<bool> {
|
||||
typedef conky::simple_config_setting<bool> Base;
|
||||
@ -160,16 +119,6 @@ class out_to_x_setting : public conky::simple_config_setting<bool> {
|
||||
out_to_x_setting() : Base("out_to_x", true, false) {}
|
||||
};
|
||||
|
||||
class own_window_setting : public conky::simple_config_setting<bool> {
|
||||
typedef conky::simple_config_setting<bool> Base;
|
||||
|
||||
protected:
|
||||
virtual void lua_setter(lua::state &l, bool init);
|
||||
|
||||
public:
|
||||
own_window_setting() : Base("own_window", false, false) {}
|
||||
};
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
class use_xdbe_setting : public conky::simple_config_setting<bool> {
|
||||
typedef conky::simple_config_setting<bool> Base;
|
||||
@ -196,72 +145,14 @@ class use_xpmdb_setting : public conky::simple_config_setting<bool> {
|
||||
use_xpmdb_setting() : Base("double_buffer", false, false) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
struct colour_traits {
|
||||
static const lua::Type type = lua::TSTRING;
|
||||
typedef unsigned long Type;
|
||||
|
||||
static inline std::pair<Type, bool> convert(lua::state &l, int index,
|
||||
const std::string &) {
|
||||
return {get_x11_color(l.tostring(index)), true};
|
||||
}
|
||||
};
|
||||
|
||||
class colour_setting
|
||||
: public conky::simple_config_setting<unsigned long, colour_traits> {
|
||||
typedef conky::simple_config_setting<unsigned long, colour_traits> Base;
|
||||
|
||||
protected:
|
||||
virtual void lua_setter(lua::state &l, bool init);
|
||||
|
||||
public:
|
||||
colour_setting(const std::string &name_, unsigned long default_value_ = 0)
|
||||
: Base(name_, default_value_, true) {}
|
||||
};
|
||||
} // namespace priv
|
||||
} /* namespace priv */
|
||||
|
||||
extern priv::out_to_x_setting out_to_x;
|
||||
extern conky::simple_config_setting<std::string> display_name;
|
||||
extern conky::simple_config_setting<int> head_index;
|
||||
extern priv::colour_setting color[10];
|
||||
extern priv::colour_setting default_color;
|
||||
extern priv::colour_setting default_shade_color;
|
||||
extern priv::colour_setting default_outline_color;
|
||||
|
||||
extern conky::range_config_setting<int> border_inner_margin;
|
||||
extern conky::range_config_setting<int> border_outer_margin;
|
||||
extern conky::range_config_setting<int> border_width;
|
||||
|
||||
extern conky::simple_config_setting<bool> forced_redraw;
|
||||
|
||||
#ifdef BUILD_XFT
|
||||
extern conky::simple_config_setting<bool> use_xft;
|
||||
#endif
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
extern conky::simple_config_setting<bool> set_transparent;
|
||||
extern conky::simple_config_setting<std::string> own_window_class;
|
||||
extern conky::simple_config_setting<std::string> own_window_title;
|
||||
extern conky::simple_config_setting<window_type> own_window_type;
|
||||
|
||||
struct window_hints_traits {
|
||||
static const lua::Type type = lua::TSTRING;
|
||||
typedef uint16_t Type;
|
||||
static std::pair<Type, bool> convert(lua::state &l, int index,
|
||||
const std::string &name);
|
||||
};
|
||||
extern conky::simple_config_setting<uint16_t, window_hints_traits>
|
||||
own_window_hints;
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
extern conky::simple_config_setting<bool> use_argb_visual;
|
||||
|
||||
/* range of 0-255 for alpha */
|
||||
extern conky::range_config_setting<int> own_window_argb_value;
|
||||
#endif
|
||||
#endif /*OWN_WINDOW*/
|
||||
extern priv::own_window_setting own_window;
|
||||
|
||||
#ifdef BUILD_XDBE
|
||||
extern priv::use_xdbe_setting use_xdbe;
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user