Skip to content

Commit

Permalink
Separate cairo-xlib.h Lua bindings from cairo.h
Browse files Browse the repository at this point in the history
This allows cairo.h to be used from Lua on Wayland without X11 as
requirement.

A way of creating surfaces in Lua that uses Shm allocated buffers should
be added in future. This commit only cleans up build options to avoid weird
errors.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Apr 19, 2024
1 parent d815f9a commit c1e6432
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 89 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ CMakeCache.txt
CMakeFiles
data/convertconf.h
data/defconfig.h
lua/libcairo-orig.c
lua/libcairo.c
lua/libimlib2.c
*.so
*.a
/config.h
Expand Down
3 changes: 3 additions & 0 deletions cmake/ConkyBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ dependent_option(BUILD_MOUSE_EVENTS "Enable mouse event support" true

# Lua library options
option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false)
dependent_option(BUILD_LUA_CAIRO_XLIB "Build Imlib2 bindings for Lua" true
"BUILD_X11;BUILD_LUA_CAIRO" false
"Lua support for Cairo Xlib requires Cairo and X11")
dependent_option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false
"BUILD_X11;BUILD_IMLIB2" false
"Imlib2 Lua bindings require X11 and Imlib2")
Expand Down
19 changes: 15 additions & 4 deletions cmake/ConkyPlatformChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,19 @@ if(BUILD_WAYLAND)
set(conky_includes ${conky_includes} ${EPOLL_INCLUDE_DIRS})
endif(OS_DARWIN OR OS_DRAGONFLY OR OS_FREEBSD OR OS_NETBSD OR OS_OPENBSD)

pkg_check_modules(PANGOCAIRO pangocairo)
pkg_check_modules(CAIRO REQUIRED cairo)
set(conky_libs ${conky_libs} ${CAIRO_LIBRARIES})
set(conky_includes ${conky_includes} ${CAIRO_INCLUDE_DIR})

pkg_check_modules(PANGOCAIRO REQUIRED pangocairo)
set(conky_libs ${conky_libs} ${PANGOCAIRO_LIBRARIES})
set(conky_includes ${conky_includes} ${PANGOCAIRO_INCLUDE_DIRS})

pkg_check_modules(PANGOFC pangofc)
pkg_check_modules(PANGOFC REQUIRED pangofc)
set(conky_libs ${conky_libs} ${PANGOFC_LIBRARIES})
set(conky_includes ${conky_includes} ${PANGOFC_INCLUDE_DIRS})

pkg_check_modules(PANGOFT2 pangoft2)
pkg_check_modules(PANGOFT2 REQUIRED pangoft2)
set(conky_libs ${conky_libs} ${PANGOFT2_LIBRARIES})
set(conky_includes ${conky_includes} ${PANGOFT2_INCLUDE_DIRS})
endif(BUILD_WAYLAND)
Expand All @@ -494,9 +498,16 @@ include_directories(3rdparty/toluapp/include)
if(BUILD_GUI)
# Check for libraries used by Lua bindings
if(BUILD_LUA_CAIRO)
pkg_check_modules(CAIRO REQUIRED cairo>=1.14 cairo-xlib)
pkg_check_modules(CAIRO REQUIRED cairo>=1.14)
set(luacairo_libs ${CAIRO_LIBRARIES} ${LUA_LIBRARIES})
set(luacairo_includes ${CAIRO_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})

if(BUILD_LUA_CAIRO_XLIB)
pkg_check_modules(CAIROXLIB REQUIRED cairo-xlib)
set(luacairo_libs ${CAIROXLIB_LIBRARIES} ${luacairo_libs})
set(luacairo_includes ${CAIROXLIB_INCLUDE_DIRS} ${luacairo_includes})
endif(BUILD_LUA_CAIRO_XLIB)

find_program(APP_PATCH patch)

if(NOT APP_PATCH)
Expand Down
2 changes: 2 additions & 0 deletions lua/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.cc
cmake_install.cmake
119 changes: 68 additions & 51 deletions lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,74 +22,91 @@ include(ToLua)

add_definitions(-DTOLUA_RELEASE)

if(BUILD_X11)
if(BUILD_LUA_CAIRO)
include_directories(${luacairo_includes} ${CMAKE_CURRENT_SOURCE_DIR})
# NOTE: Don't chain options in IFs here, their dependency is already handled by
# ConkyBuildOptions.cmake

# Need the directory for -lSM
get_filename_component(X11_SM_LIB_PATH ${X11_SM_LIB} DIRECTORY)
link_directories(${X11_SM_LIB_PATH})
if(BUILD_LUA_CAIRO)
include_directories(${luacairo_includes} ${CMAKE_CURRENT_SOURCE_DIR})

# cairo_set_dash() needs this special hack to work properly if you have a
# better solution, please let me know
wrap_tolua(luacairo_src cairo.pkg libcairo.patch)
# cairo_set_dash() needs this special hack to work properly if you have a
# better solution, please let me know
wrap_tolua(luacairo_src cairo.pkg libcairo.patch)

add_library(conky-cairo SHARED ${luacairo_src})
set_target_properties(conky-cairo PROPERTIES OUTPUT_NAME "cairo")
add_library(conky-cairo SHARED ${luacairo_src})
set_target_properties(conky-cairo PROPERTIES OUTPUT_NAME "cairo")

target_link_libraries(conky-cairo ${luacairo_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo)
target_link_libraries(conky-cairo ${luacairo_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo)

print_target_properties(conky-cairo)
endif(BUILD_LUA_CAIRO)
print_target_properties(conky-cairo)
endif(BUILD_LUA_CAIRO)

if(BUILD_LUA_IMLIB2)
include_directories(${luaimlib2_includes} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src)
if(BUILD_LUA_CAIRO_XLIB)
include_directories(${luacairoxlib_includes} ${CMAKE_CURRENT_SOURCE_DIR})

if(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")
wrap_tolua(luaimlib2_src imlib2.pkg)
else(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")
wrap_tolua(luaimlib2_src imlib2_old.pkg)
endif(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")
# Need the directory for -lSM
get_filename_component(X11_SM_LIB_PATH ${X11_SM_LIB} DIRECTORY)
link_directories(${X11_SM_LIB_PATH})
wrap_tolua(luacairoxlib_src cairo_xlib.pkg)

add_library(conky-imlib2 SHARED ${luaimlib2_src})
set_target_properties(conky-imlib2 PROPERTIES OUTPUT_NAME "imlib2")
add_library(conky-cairo_xlib SHARED ${luacairoxlib_src})
set_target_properties(conky-cairo_xlib PROPERTIES OUTPUT_NAME "cairo")

target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-imlib2)
target_link_libraries(conky-cairo_xlib
${luacairoxlib_libs}
${luacairo_libs}
toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo_xlib)

print_target_properties(conky-imlib2)
endif(BUILD_LUA_IMLIB2)
print_target_properties(conky-cairo_xlib)
endif(BUILD_LUA_CAIRO_XLIB)

if(BUILD_LUA_RSVG)
include_directories(${luarsvg_includes} ${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luarsvg_src rsvg.pkg)
if(BUILD_LUA_IMLIB2)
include_directories(${luaimlib2_includes} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src)

add_library(conky-rsvg SHARED ${luarsvg_src})
set_target_properties(conky-rsvg PROPERTIES OUTPUT_NAME "rsvg")
if(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")
wrap_tolua(luaimlib2_src imlib2.pkg)
else(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")
wrap_tolua(luaimlib2_src imlib2_old.pkg)
endif(IMLIB2_VERSION VERSION_GREATER_EQUAL "1.10.0")

target_link_libraries(conky-rsvg ${luarsvg_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-rsvg)
add_library(conky-imlib2 SHARED ${luaimlib2_src})
set_target_properties(conky-imlib2 PROPERTIES OUTPUT_NAME "imlib2")

print_target_properties(conky-rsvg)
endif(BUILD_LUA_RSVG)
target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-imlib2)

if(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2)
include_directories(${luacairo_includes} ${luaimlib2_includes}
${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luacairo_imlib2_helper_src cairo_imlib2_helper.pkg)
print_target_properties(conky-imlib2)
endif(BUILD_LUA_IMLIB2)

add_library(conky-cairo_imlib2_helper SHARED ${luacairo_imlib2_helper_src})
set_target_properties(conky-cairo_imlib2_helper
PROPERTIES OUTPUT_NAME "cairo_imlib2_helper")
if(BUILD_LUA_IMLIB2)
include_directories(${luacairo_includes} ${luaimlib2_includes}
${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luacairo_imlib2_helper_src cairo_imlib2_helper.pkg)

target_link_libraries(conky-cairo_imlib2_helper
${luacairo_libs}
${luaimlib2_libs}
toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo_imlib2_helper)
endif(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2)
endif(BUILD_X11)
add_library(conky-cairo_imlib2_helper SHARED ${luacairo_imlib2_helper_src})
set_target_properties(conky-cairo_imlib2_helper
PROPERTIES OUTPUT_NAME "cairo_imlib2_helper")

target_link_libraries(conky-cairo_imlib2_helper
${luacairo_libs}
${luaimlib2_libs}
toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo_imlib2_helper)
endif(BUILD_LUA_IMLIB2)

if(BUILD_LUA_RSVG)
include_directories(${luarsvg_includes} ${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luarsvg_src rsvg.pkg)

add_library(conky-rsvg SHARED ${luarsvg_src})
set_target_properties(conky-rsvg PROPERTIES OUTPUT_NAME "rsvg")

target_link_libraries(conky-rsvg ${luarsvg_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-rsvg)

print_target_properties(conky-rsvg)
endif(BUILD_LUA_RSVG)

install(TARGETS ${lua_libs}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}/conky
Expand Down
33 changes: 2 additions & 31 deletions lua/cairo.pkg
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
$#include <cairo-features.h>
$#include <cairo-deprecated.h>
$#include <cairo.h>
$#include <cairo-xlib.h>
$#include <X11/Xlib.h>
$#include <libcairo-helper.h>
/*
* This code was mostly copied from cairo.h and cairo-xlib.h with comments
* removed. The licence noticed below is present for the sake of clarity.
* This code was mostly copied from cairo.h with comments removed. The
* license notice below is present for the sake of clarity.
*/

/* cairo - a vector graphics library with display and print output
Expand Down Expand Up @@ -191,33 +189,6 @@ typedef enum _cairo_filter {
CAIRO_FILTER_GAUSSIAN
} cairo_filter_t;

cairo_surface_t *cairo_xlib_surface_create(Display * dpy,
Drawable drawable,
Visual * visual, int width, int height);

cairo_surface_t *cairo_xlib_surface_create_for_bitmap(Display * dpy,
Pixmap bitmap,
Screen * screen, int width, int height);

void cairo_xlib_surface_set_size(cairo_surface_t * surface, int width, int height);

void cairo_xlib_surface_set_drawable(cairo_surface_t * surface, Drawable
drawable, int width, int height);

Display *cairo_xlib_surface_get_display(cairo_surface_t * surface);

Drawable cairo_xlib_surface_get_drawable(cairo_surface_t * surface);

Screen *cairo_xlib_surface_get_screen(cairo_surface_t * surface);

Visual *cairo_xlib_surface_get_visual(cairo_surface_t * surface);

int cairo_xlib_surface_get_depth(cairo_surface_t * surface);

int cairo_xlib_surface_get_width(cairo_surface_t * surface);

int cairo_xlib_surface_get_height(cairo_surface_t * surface);

int cairo_version(void);

const char *cairo_version_string(void);
Expand Down
71 changes: 71 additions & 0 deletions lua/cairo_xlib.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
$#include <cairo.h>
$#include <cairo-xlib.h>
$#include <X11/Xlib.h>
/*
* This code was mostly copied from cairo-xlib.h with comments removed. The
* license notice below is present for the sake of clarity.
*/

/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
* Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is University of Southern
* California.
*
* Contributor(s):
* Carl D. Worth <cworth@cworth.org>
*/

cairo_surface_t *cairo_xlib_surface_create(Display * dpy,
Drawable drawable,
Visual * visual, int width, int height);

cairo_surface_t *cairo_xlib_surface_create_for_bitmap(Display * dpy,
Pixmap bitmap,
Screen * screen, int width, int height);

void cairo_xlib_surface_set_size(cairo_surface_t * surface, int width, int height);

void cairo_xlib_surface_set_drawable(cairo_surface_t * surface, Drawable
drawable, int width, int height);

Display *cairo_xlib_surface_get_display(cairo_surface_t * surface);

Drawable cairo_xlib_surface_get_drawable(cairo_surface_t * surface);

Screen *cairo_xlib_surface_get_screen(cairo_surface_t * surface);

Visual *cairo_xlib_surface_get_visual(cairo_surface_t * surface);

int cairo_xlib_surface_get_depth(cairo_surface_t * surface);

int cairo_xlib_surface_get_width(cairo_surface_t * surface);

int cairo_xlib_surface_get_height(cairo_surface_t * surface);

0 comments on commit c1e6432

Please sign in to comment.