From 1c511e30f540bcc7a79aa9ab96f9552097c1c6ec Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 28 Mar 2014 21:34:38 +0200 Subject: Remove custom output directory paths. --- client/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) (limited to 'client/CMakeLists.txt') diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 70ecd4b..91c4ea5 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,5 +1,3 @@ -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) - # Sources SET(CLIENT_SOURCE client.c) SET(CLIENT_INCLUDE) -- cgit v1.2.3-70-g09d2 From 908749cfdfa037b6f5fd0f5f7b2fa66080329156 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 28 Mar 2014 21:33:20 +0200 Subject: Add basic API code. => bmMenu instancing. => "Rendering" => bmMenu releasing. --- client/CMakeLists.txt | 2 +- client/client.c | 12 +++++++++--- lib/bemenu.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- lib/bemenu.h | 38 ++++++++++++++++++++++++++++++++++++++ lib/internal.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 lib/bemenu.h create mode 100644 lib/internal.h (limited to 'client/CMakeLists.txt') diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 91c4ea5..aceaaf5 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,6 +1,6 @@ # Sources SET(CLIENT_SOURCE client.c) -SET(CLIENT_INCLUDE) +SET(CLIENT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../lib") SET(CLIENT_LIBRARIES bemenu) # Warnings diff --git a/client/client.c b/client/client.c index de5468e..559651f 100644 --- a/client/client.c +++ b/client/client.c @@ -6,6 +6,7 @@ */ #include +#include /** * Main method @@ -20,9 +21,14 @@ int main(int argc, char **argv) { (void)argc, (void)argv; - /* - * code goes here - */ + bmMenu *menu = bmMenuNew(BM_DRAW_MODE_NONE); + + if (!menu) + return EXIT_FAILURE; + + bmMenuRender(menu); + + bmMenuFree(menu); return EXIT_SUCCESS; } diff --git a/lib/bemenu.c b/lib/bemenu.c index 2f92f27..a2caa13 100644 --- a/lib/bemenu.c +++ b/lib/bemenu.c @@ -2,8 +2,55 @@ * @file bemenu.c */ -/* - * code goes here +#include "internal.h" +#include +#include + +/** + * Create new bmMenu instance. + * + * @param drawMode Render method to be used for this menu instance. + * @return bmMenu for new menu instance, NULL if creation failed. */ +bmMenu* bmMenuNew(bmDrawMode drawMode) +{ + bmMenu *menu = calloc(1, sizeof(bmMenu)); + + menu->drawMode = drawMode; + + if (!menu) + return NULL; + + switch (menu->drawMode) { + default:break; + } + + return menu; +} + +/** + * Release bmMenu instance. + * + * @param menu bmMenu instance to be freed from memory. + */ +void bmMenuFree(bmMenu *menu) +{ + assert(menu != NULL); + free(menu); +} + +/** + * Create new bmMenu instance. + * + * @param drawMode Render method to be used for this menu instance. + * @return bmMenu for new menu instance, NULL if creation failed. + */ +void bmMenuRender(bmMenu *menu) +{ + assert(menu != NULL); + + if (menu->renderApi.render) + menu->renderApi.render(menu->items, menu->itemsCount); +} /* vim: set ts=8 sw=4 tw=0 :*/ diff --git a/lib/bemenu.h b/lib/bemenu.h new file mode 100644 index 0000000..f4823b4 --- /dev/null +++ b/lib/bemenu.h @@ -0,0 +1,38 @@ +/** + * @file bemenu.h + * + * Public header + */ + +/** + * Draw mode constants for setting bmMenu instance draw mode. + */ +typedef enum bmDrawMode { + BM_DRAW_MODE_NONE +} bmDrawMode; + +typedef struct _bmMenu bmMenu; + +/** + * Create new bmMenu instance. + * + * @param drawMode Render method to be used for this menu instance. + * @return bmMenu for new menu instance, NULL if creation failed. + */ +bmMenu* bmMenuNew(bmDrawMode drawMode); + +/** + * Release bmMenu instance. + * + * @param menu bmMenu instance to be freed from memory. + */ +void bmMenuFree(bmMenu *menu); + +/** + * Render bmMenu instance using chosen draw method. + * + * @param menu bmMenu instance to be rendered. + */ +void bmMenuRender(bmMenu *menu); + +/* vim: set ts=8 sw=4 tw=0 :*/ diff --git a/lib/internal.h b/lib/internal.h new file mode 100644 index 0000000..d11ebe2 --- /dev/null +++ b/lib/internal.h @@ -0,0 +1,37 @@ +/** + * @file internal.h + */ + +#include "bemenu.h" + +/** + * Internal bmItem struct that is not exposed to public. + * Represents a single item in menu. + */ +struct _bmItem { + char *text; +} _bmItem; + +/** + * Internal bmRenderApi struct. + * Renderers should be able to fill this one as they see fit. + */ +struct _bmRenderApi { + void (*render)(struct _bmItem **items, unsigned int nmemb); + void (*free)(void); +} _bmRenderApi; + +/** + * Internal bmMenu struct that is not exposed to public. + */ +struct _bmMenu { + bmDrawMode drawMode; + struct _bmRenderApi renderApi; + struct _bmItem **items; + unsigned int itemsCount; +} _bmMenu; + + +void bmRenderNullInit(struct _bmRenderApi *api); + +/* vim: set ts=8 sw=4 tw=0 :*/ -- cgit v1.2.3-70-g09d2 From 3f0f507e4f3bea6c5936be62aeff507ed6c4ae25 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 12 Apr 2014 22:42:37 +0300 Subject: Improve CMakeLists and make stuff installable. --- client/CMakeLists.txt | 8 ++++++-- lib/CMakeLists.txt | 28 ++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'client/CMakeLists.txt') diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index aceaaf5..6af4e3e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,7 +1,7 @@ # Sources SET(CLIENT_SOURCE client.c) -SET(CLIENT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../lib") -SET(CLIENT_LIBRARIES bemenu) +SET(CLIENT_INCLUDE ${BEMENU_INCLUDE_DIRS}) +SET(CLIENT_LIBRARIES ${BEMENU_LIBRARIES}) # Warnings IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) @@ -20,5 +20,9 @@ ENDIF () INCLUDE_DIRECTORIES(${CLIENT_INCLUDE}) ADD_EXECUTABLE(client ${CLIENT_SOURCE}) TARGET_LINK_LIBRARIES(client ${CLIENT_LIBRARIES}) +SET_TARGET_PROPERTIES(client PROPERTIES OUTPUT_NAME bemenu) + +# Install +INSTALL(TARGETS client DESTINATION bin) # vim: set ts=8 sw=4 tw=0 : diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index bfdb843..a52bc7b 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -8,9 +8,8 @@ SET(BEMENU_SOURCE library.c draw/curses.c ) -SET(BEMENU_INCLUDE) -SET(BEMENU_LIBRARIES) +# Configure CONFIGURE_FILE(version.h.in version.h @ONLY) # Warnings @@ -26,9 +25,30 @@ IF (UNIX AND CMAKE_COMPILER_IS_GNUCC) ENDIF () ENDIF () +# Parse soversion version +STRING(REGEX MATCHALL "[0-9]+" VERSION_COMPONENTS ${BEMENU_VERSION}) +LIST(GET VERSION_COMPONENTS 0 SOVERSION) + # Compile INCLUDE_DIRECTORIES(${BEMENU_INCLUDE} ${CMAKE_CURRENT_BINARY_DIR}) -ADD_LIBRARY(bemenu ${BEMENU_SOURCE}) -TARGET_LINK_LIBRARIES(bemenu ${BEMENU_LIBRARIES} dl) +ADD_LIBRARY(bemenu SHARED ${BEMENU_SOURCE}) +SET_TARGET_PROPERTIES(bemenu PROPERTIES + VERSION ${BEMENU_VERSION} + SOVERSION ${SOVERSION}) +TARGET_LINK_LIBRARIES(bemenu dl) + +# Install +INSTALL(TARGETS bemenu DESTINATION lib) +INSTALL(FILES bemenu.h DESTINATION include) + +# Unexport +SET(BEMENU_INCLUDES) +SET(BEMENU_INCLUDE_DIRS) +SET(BEMENU_LIBRARIES) + +# Export +SET(BEMENU_INCLUDES "bemenu.h" CACHE STRING "bemenu includes exported from CMake") +SET(BEMENU_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "bemenu public header include path exported from CMake") +SET(BEMENU_LIBRARIES "bemenu" "dl" CACHE STRING "bemenu libraries exported from CMake") # vim: set ts=8 sw=4 tw=0 : -- cgit v1.2.3-70-g09d2