diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/rofi.h | 49 | ||||
-rw-r--r-- | include/textbox.h | 2 | ||||
-rw-r--r-- | include/view-internal.h | 73 | ||||
-rw-r--r-- | include/view.h | 149 | ||||
-rw-r--r-- | include/x11-event-source.h | 6 |
5 files changed, 237 insertions, 42 deletions
diff --git a/include/rofi.h b/include/rofi.h index 95fd06c6..75713df7 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -8,6 +8,7 @@ #include "timings.h" #include "keyb.h" #include "mode.h" +#include "view.h" /** * @defgroup Main Main @@ -17,43 +18,17 @@ * Pointer to xdg cache directory. */ extern const char *cache_dir; -typedef struct MenuState MenuState; /** - * @param msg The error message to show. - * @param markup The error message uses pango markup. + * @param key the Key to match + * @param modstate the modifier state to match * - * The error message to show. - */ -void error_dialog ( const char *msg, int markup ); - -typedef enum -{ - MENU_NORMAL = 0, - MENU_PASSWORD = 1 -} MenuFlags; - -/** - * @param sw the Mode to show. - * @param lines An array of strings to display. - * @param num_lines Length of the array with strings to display. - * @param input A pointer to a string where the inputted data is placed. - * @param prompt The prompt to show. - * @param shift pointer to integer that is set to the state of the shift key. - * @param mmc Menu menu match callback, used for matching user input. - * @param mmc_data data to pass to mmc. - * @param selected_line pointer to integer holding the selected line. - * @param message Extra message to display. - * @param flags Flags indicating state of the menu. - * - * Main menu callback. + * Match key and modifier state against modi. * - * @returns The command issued (see MenuReturn) + * @return the index of the switcher that matches the key combination + * specified by key and modstate. Returns -1 if none was found */ -MenuState *menu ( Mode *sw, - char *input, char *prompt, - const char *message, MenuFlags flags ) -__attribute__ ( ( nonnull ( 1, 2, 3 ) ) ); +int locate_switcher ( KeySym key, unsigned int modstate ); /** Reset terminal */ #define color_reset "\033[0m" @@ -83,15 +58,5 @@ int show_error_message ( const char *msg, int markup ); " * The version of rofi you are running\n\n" \ " <i>https://github.com/DaveDavenport/rofi/</i>" #define ERROR_MSG_MARKUP TRUE - -MenuReturn menu_state_get_return_value ( const MenuState *state ); -unsigned int menu_state_get_selected_line ( const MenuState *state ); -unsigned int menu_state_get_next_position ( const MenuState *state ); -void menu_state_itterrate ( MenuState *state, XEvent *event ); -unsigned int menu_state_get_completed ( const MenuState *state ); -const char * menu_state_get_user_input ( const MenuState *state ); -void menu_state_free ( MenuState *state ); -void menu_state_restart ( MenuState *state ); -void menu_state_set_selected_line ( MenuState *state, unsigned int selected_line ); /*@}*/ #endif diff --git a/include/textbox.h b/include/textbox.h index ecc52784..c321eb47 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -36,6 +36,8 @@ typedef struct cairo_t *main_draw; int update; + int blink; + guint blink_timeout; } textbox; typedef enum diff --git a/include/view-internal.h b/include/view-internal.h new file mode 100644 index 00000000..9632e810 --- /dev/null +++ b/include/view-internal.h @@ -0,0 +1,73 @@ +#ifndef ROFI_VIEW_INTERNAL_H +#define ROFI_VIEW_INTERNAL_H +#include "widget.h" +#include "textbox.h" +#include "scrollbar.h" + +/** + * @ingroup ViewHandle + * + * @{ + */ +// State of the menu. + +typedef struct RofiViewState +{ + Mode *sw; + unsigned int menu_lines; + unsigned int max_elements; + unsigned int max_rows; + unsigned int columns; + + // window width,height + unsigned int w, h; + int x, y; + unsigned int element_width; + int top_offset; + + // Update/Refilter list. + int update; + int refilter; + int rchanged; + int cur_page; + + // Entries + textbox *text; + textbox *prompt_tb; + textbox *message_tb; + textbox *case_indicator; + textbox **boxes; + scrollbar *scrollbar; + int *distance; + unsigned int *line_map; + + unsigned int num_lines; + + // Selected element. + unsigned int selected; + unsigned int filtered_lines; + // Last offset in paginating. + unsigned int last_offset; + + KeySym prev_key; + Time last_button_press; + + int quit; + int skip_absorb; + // Return state + unsigned int selected_line; + MenuReturn retv; + int *lines_not_ascii; + int line_height; + unsigned int border; + workarea mon; + + // Sidebar view + ssize_t num_modi; + textbox **modi; + // Handlers. + void ( *x11_event_loop )( struct RofiViewState *state, XEvent *ev ); + void ( *finalize )( struct RofiViewState *state ); +}RofiViewState; +/** @} */ +#endif diff --git a/include/view.h b/include/view.h new file mode 100644 index 00000000..3151a438 --- /dev/null +++ b/include/view.h @@ -0,0 +1,149 @@ +#ifndef ROFI_VIEW_H +#define ROFI_VIEW_H + +/** + * @defgroup View View + * + * 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; + +/** + * @param sw the Mode to show. + * @param input A pointer to a string where the inputted data is placed. + * @param prompt The prompt to show. + * @param message Extra message to display. + * @param flags Flags indicating state of the menu. + * + * Main menu callback. + * + * @returns The command issued (see MenuReturn) + */ +RofiViewState *rofi_view_create ( Mode *sw, const char *input, char *prompt, const char *message, MenuFlags flags ) +__attribute__ ( ( nonnull ( 1, 2, 3 ) ) ); + +/** + * @param state The Menu Handle + * + * Check if a finalize function is set, and if sets executes it. + */ +void rofi_view_finalize ( RofiViewState *state ); + +MenuReturn rofi_view_get_return_value ( 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 ); + +/** + * @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 ); + +/** + * @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 ); + +/** + * @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. + * @param markup The error message uses pango markup. + * + * 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/include/x11-event-source.h b/include/x11-event-source.h new file mode 100644 index 00000000..2c129eb0 --- /dev/null +++ b/include/x11-event-source.h @@ -0,0 +1,6 @@ +#ifndef ROFI_X11_EVENT_SOURCE_H +#define ROFI_X11_EVENT_SOURCE_H + +GSource * x11_event_source_new ( Display *display ); +void x11_event_source_set_callback ( GSource *source, GSourceFunc callback ); +#endif // ROFI_X11_EVENT_SOURCE_H |