From 5d430824b307fefdd1c784bb407aa28675d0009f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 8 Feb 2016 18:16:16 +0100 Subject: [PATCH] Doxygen updates. --- include/textbox.h | 18 ++++---- include/view-internal.h | 2 +- include/view.h | 99 +++++++++++++++++++++++++++++++++++++---- source/rofi.c | 23 +++++----- source/view.c | 31 ++++++------- 5 files changed, 127 insertions(+), 46 deletions(-) diff --git a/include/textbox.h b/include/textbox.h index 757b1c62..c321eb47 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -42,15 +42,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/include/view-internal.h b/include/view-internal.h index 5c41fd14..9632e810 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -5,7 +5,7 @@ #include "scrollbar.h" /** - * @ingroup View + * @ingroup ViewHandle * * @{ */ diff --git a/include/view.h b/include/view.h index 329102e5..3151a438 100644 --- a/include/view.h +++ b/include/view.h @@ -6,12 +6,17 @@ * * The rofi Menu view. * + * @defgroup ViewHandle ViewHandle + * @ingroup View + * * @{ */ typedef struct RofiViewState RofiViewState; typedef enum { + /** Create a menu for entering text */ MENU_NORMAL = 0, + /** Create a menu for entering passwords */ MENU_PASSWORD = 1 } MenuFlags; @@ -36,26 +41,82 @@ __attribute__ ( ( nonnull ( 1, 2, 3 ) ) ); */ void rofi_view_finalize ( RofiViewState *state ); -RofiViewState * rofi_view_state_create ( void ); - MenuReturn rofi_view_get_return_value ( const RofiViewState *state ); -unsigned int rofi_view_get_selected_line ( const RofiViewState *state ); unsigned int rofi_view_get_next_position ( const RofiViewState *state ); void rofi_view_itterrate ( RofiViewState *state, XEvent *event ); unsigned int rofi_view_get_completed ( const RofiViewState *state ); const char * rofi_view_get_user_input ( const RofiViewState *state ); -void rofi_view_free ( RofiViewState *state ); -void rofi_view_restart ( RofiViewState *state ); + +/** + * @param state The Menu Handle + * @param selected_line The line to select. + * + * Select a line. + */ void rofi_view_set_selected_line ( RofiViewState *state, unsigned int selected_line ); -void rofi_view_queue_redraw ( void ); -void rofi_view_set_active ( RofiViewState *state ); -void rofi_view_call_thread ( gpointer data, gpointer user_data ); +/** + * @param state The Menu Handle + * + * Get the selected line. + * + * @returns the selected line or UINT32_MAX if none selected. + */ +unsigned int rofi_view_get_selected_line ( const RofiViewState *state ); +/** + * @param state The Menu Handle + * + * Restart the menu so it can be displayed again. + * Resets RofiViewState::quit and RofiViewState::retv. + */ +void rofi_view_restart ( RofiViewState *state ); +/** + * @param state The handle to the view + * + * Update the state of the view. This involves filter state. + */ void rofi_view_update ( RofiViewState *state ); + +/** + * @param display Connection to the X server. + * @param state The handle to the view + * + * Enables fake transparancy on this view. + */ void rofi_view_setup_fake_transparency ( Display *display, RofiViewState *state ); -void rofi_view_cleanup ( void ); +/** + * @param state The handle to the view + * + * Free's the memory allocated for this handle. + * After a call to this function, state is invalid and can no longer be used. + */ +void rofi_view_free ( RofiViewState *state ); +/** @} */ +/** + * @defgroup ViewGlobal ViewGlobal + * @ingroup View + * + * Global menu view functions. + * These do not work on the view itself but modifies the global state. + * @{ + */ + +/** + * Get the current active view Handle. + * + * @returns the active view handle or NULL + */ +RofiViewState * rofi_view_get_active ( void ); + +/** + * @param state the new active view handle, NULL to clear. + * + * Set the current active view Handle. + * + */ +void rofi_view_set_active ( RofiViewState *state ); /** * @param msg The error message to show. @@ -64,5 +125,25 @@ void rofi_view_cleanup ( void ); * The error message to show. */ void rofi_view_error_dialog ( const char *msg, int markup ); + +/** + * Queue a redraw. + * This triggers a X11 Expose Event. + */ +void rofi_view_queue_redraw ( void ); + +/** + * Cleanup internal data of the view. + */ +void rofi_view_cleanup ( void ); + +/** + * @param data A thread_state object. + * @param user_data User data to pass to thread_state callback + * + * Small wrapper function that is internally used to pass a job to a worker. + */ +void rofi_view_call_thread ( gpointer data, gpointer user_data ); + /** @} */ #endif diff --git a/source/rofi.c b/source/rofi.c index 5b2e966e..7c6e61fd 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -42,7 +41,6 @@ #include #include #include -#include #include #include @@ -79,11 +77,10 @@ unsigned int num_modi = 0; // Current selected switcher. unsigned int curr_switcher = 0; -GThreadPool *tpool = NULL; -GMainLoop *main_loop = NULL; -GSource *main_loop_source = NULL; -gboolean quiet = FALSE; -RofiViewState *current_active_menu = NULL; +GThreadPool *tpool = NULL; +GMainLoop *main_loop = NULL; +GSource *main_loop_source = NULL; +gboolean quiet = FALSE; static void process_result ( RofiViewState *state ); gboolean main_loop_x11_event_handler ( G_GNUC_UNUSED gpointer data ); @@ -198,12 +195,13 @@ static void run_switcher ( ModeMode mode ) } static void process_result ( RofiViewState *state ) { + Mode *sw = state->sw; unsigned int selected_line = rofi_view_get_selected_line ( state );; MenuReturn mretv = rofi_view_get_return_value ( state ); char *input = g_strdup ( rofi_view_get_user_input ( state ) ); rofi_view_set_active ( NULL ); rofi_view_free ( state ); - ModeMode retv = mode_result ( modi[curr_switcher], mretv, &input, selected_line ); + ModeMode retv = mode_result ( sw, mretv, &input, selected_line ); ModeMode mode = curr_switcher; // Find next enabled @@ -535,16 +533,17 @@ static void reload_configuration () */ gboolean main_loop_x11_event_handler ( G_GNUC_UNUSED gpointer data ) { - if ( current_active_menu != NULL ) { + RofiViewState *state = rofi_view_get_active (); + if ( state != NULL ) { while ( XPending ( display ) ) { XEvent ev; // Read event, we know this won't block as we checked with XPending. XNextEvent ( display, &ev ); - rofi_view_itterrate ( current_active_menu, &ev ); + rofi_view_itterrate ( state, &ev ); } - if ( rofi_view_get_completed ( current_active_menu ) ) { + if ( rofi_view_get_completed ( state ) ) { // This menu is done. - rofi_view_finalize ( current_active_menu ); + rofi_view_finalize ( state ); } return G_SOURCE_CONTINUE; } diff --git a/source/view.c b/source/view.c index c72daa4a..b6e99a5b 100644 --- a/source/view.c +++ b/source/view.c @@ -66,19 +66,18 @@ #include "view.h" #include "view-internal.h" -extern RofiViewState *current_active_menu; extern Display *display; extern unsigned int num_modi; -Window main_window = None; +extern Mode **modi; extern SnDisplay *sndisplay; extern SnLauncheeContext *sncontext; extern GThreadPool *tpool; -extern unsigned int curr_switcher; -extern Mode **modi; -extern unsigned int num_modi; -cairo_surface_t *surface = NULL; -cairo_surface_t *fake_bg = NULL; -cairo_t *draw = NULL; + +RofiViewState *current_active_menu = NULL; +Window main_window = None; +cairo_surface_t *surface = NULL; +cairo_surface_t *fake_bg = NULL; +cairo_t *draw = NULL; XIM xim; XIC xic; Colormap map = None; @@ -225,6 +224,11 @@ void rofi_view_restart ( RofiViewState *state ) state->retv = MENU_CANCEL; } +RofiViewState * rofi_view_get_active ( void ) +{ + return current_active_menu; +} + void rofi_view_set_active ( RofiViewState *state ) { g_assert ( ( current_active_menu == NULL && state != NULL ) || ( current_active_menu != NULL && state == NULL ) ); @@ -324,7 +328,7 @@ const char * rofi_view_get_user_input ( const RofiViewState *state ) * * @returns a new 0 initialized RofiViewState */ -RofiViewState * rofi_view_state_create ( void ) +static RofiViewState * __rofi_view_state_create ( void ) { return g_malloc0 ( sizeof ( RofiViewState ) ); } @@ -448,9 +452,6 @@ static Window __create_window ( Display *display ) return box; } -/** - * Small wrapper function to create easy workers. - */ void rofi_view_call_thread ( gpointer data, gpointer user_data ) { thread_state *t = (thread_state *) data; @@ -1389,7 +1390,7 @@ RofiViewState *rofi_view_create ( Mode *sw, MenuFlags menu_flags ) { TICK (); - RofiViewState *state = rofi_view_state_create (); + RofiViewState *state = __rofi_view_state_create (); state->sw = sw; state->selected_line = UINT32_MAX; state->retv = MENU_CANCEL; @@ -1569,7 +1570,7 @@ RofiViewState *rofi_view_create ( Mode *sw, for ( unsigned int j = 0; j < num_modi; j++ ) { state->modi[j] = textbox_create ( TB_CENTER, state->border + j * ( width + config.line_margin ), state->h - state->line_height - state->border, width, state->line_height, - ( j == curr_switcher ) ? HIGHLIGHT : NORMAL, mode_get_name ( modi[j] ) ); + ( modi[j] == state->sw ) ? HIGHLIGHT : NORMAL, mode_get_name ( modi[j] ) ); } } @@ -1616,7 +1617,7 @@ static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) } void rofi_view_error_dialog ( const char *msg, int markup ) { - RofiViewState *state = rofi_view_state_create (); + RofiViewState *state = __rofi_view_state_create (); state->retv = MENU_CANCEL; state->update = TRUE; state->border = config.padding + config.menu_bw;