diff --git a/include/mode.h b/include/mode.h index b140ebce..e3914e29 100644 --- a/include/mode.h +++ b/include/mode.h @@ -7,6 +7,11 @@ * The 'object' that makes a mode in rofi. * @{ */ + +/** + * Type of a mode. + * Access should be done via mode_* functions. + */ typedef struct rofi_mode Mode; /** @@ -152,9 +157,31 @@ void *mode_get_private_data ( const Mode *mode ); */ void mode_set_private_data ( Mode *mode, void *pd ); +/** + * @param mode The mode to query + * + * Get the name of the mode as it should be presented to the user. + * + * @return the user visible name of the mode + */ const char *mode_get_display_name ( const Mode *mode ); +/** + * @param mode The mode to query + * + * Should be called once for each mode. This adds the display-name configuration option for the mode. + */ void mode_set_config ( Mode *mode ); + +/** + * @param mode The mode to query + * @param intput The input to process + * + * This processes the input so it can be used for matching and sorting. + * This includes removing pango markup. + * + * @returns a newly allocated string + */ char * mode_preprocess_input ( Mode *mode, const char *input ); /*@}*/ #endif diff --git a/include/widgets/listview.h b/include/widgets/listview.h index a489a085..e04400d0 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -8,26 +8,84 @@ * @{ */ +/** + * Handle to the listview. + * No internal fields should be accessed directly. + */ typedef struct _listview listview; +/** + * The scrolling type used in the list view + */ typedef enum { + /** Flip through the pages. */ LISTVIEW_SCROLL_PER_PAGE, + /** keep selected item centered */ LISTVIEW_SCROLL_CONTINIOUS } ScrollType; +/** + * @param tb The textbox to set + * @param entry The position of the textbox + * @param udata User data + * @param type The textbox font style to apply to this entry (normal, selected, alternative row) + * @param full If true Set both text and style. + * + * Update callback, this is called to set the value of each (visible) element. + */ typedef void ( *listview_update_callback )( textbox *tb, unsigned int entry, void *udata, TextBoxFontType type, gboolean full ); + +/** + * Callback when a element is activated. + */ typedef void ( *listview_mouse_activated_cb )( listview *, xcb_button_press_event_t *, void * ); +/** + * @param cb The update callback. + * @param udata The user data to pass to the callback + * @param eh The height of one element + * + * @returns a new listview + */ listview *listview_create ( listview_update_callback cb, void *udata, unsigned int eh ); +/** + * @param lv The listview handle + * @param rows Number of elements + * + * Set the maximum number of elements to display. + */ void listview_set_num_elements ( listview *lv, unsigned int rows ); + +/** + * @param lv The listview handle + * @param selected The row index to select + * + * Select the row, if selected > the number of rows, it selects the last one. + */ void listview_set_selected ( listview *lv, unsigned int selected ); + +/** + * @param lv The listview handle + * + * Returns the selected row. + * + * @returns the selected row. + */ unsigned int listview_get_selected ( listview *lv ); + +/** + * @param lv The listview handle + * + * Get the desired height of the listview widget. + * + * @returns the desired height. + */ unsigned int listview_get_desired_height ( listview *lv ); /** - * @param state The listview handle + * @param lv The listview handle * * Move the selection one row up. * - Wrap around. diff --git a/include/x11-helper.h b/include/x11-helper.h index 3dd3491e..bc23e404 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -184,10 +184,7 @@ extern xcb_visualtype_t *visual; * Color map to use for creating window */ extern xcb_colormap_t map; -/** - * Depth of root window. - */ -extern xcb_visualtype_t *root_visual; + /** * This function tries to create a 32bit TrueColor colormap. * If this fails, it falls back to the default for the connected display. @@ -250,6 +247,14 @@ void x11_helper_set_cairo_rgba ( cairo_t *d, Color col ); * @returns a cairo surface with the background image of the desktop. */ cairo_surface_t * x11_helper_get_bg_surface ( void ); +/** + * Gets a surface for the root window of the desktop. + * + * Can be used to take screenshot. + * + * @returns a cairo surface for the root window of the desktop. + */ +cairo_surface_t *x11_helper_get_screenshot_surface ( void ); /** * Creates an internal represenation of the available monitors. diff --git a/source/helper.c b/source/helper.c index e052e01e..f3483515 100644 --- a/source/helper.c +++ b/source/helper.c @@ -56,8 +56,6 @@ const char *const monitor_position_entries[] = { "on monitor with focused window", "on monitor that has mouse pointer" }; -extern xcb_connection_t *xcb_connection; -extern xcb_screen_t *xcb_screen; static int stored_argc = 0; static char **stored_argv = NULL; @@ -192,6 +190,7 @@ static gchar *fuzzy_to_regex ( const char * input ) } static GRegex * create_regex ( const char *input, int case_sensitive ) { +// Macro for quickly generating regex for matching. #define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL ) GRegex * retv = NULL; gchar *r; diff --git a/source/view.c b/source/view.c index 148e8316..24c6ae85 100644 --- a/source/view.c +++ b/source/view.c @@ -65,25 +65,43 @@ static int rofi_view_calculate_height ( RofiViewState *state ); +/** Thread pool used for filtering */ GThreadPool *tpool = NULL; +/** Global pointer to the currently active RofiViewState */ RofiViewState *current_active_menu = NULL; +/** + * Structure holding cached state. + */ struct { + /** main x11 windows */ xcb_window_t main_window; + /** surface containing the fake background. */ cairo_surface_t *fake_bg; + /** Draw context for main window */ xcb_gcontext_t gc; + /** Main X11 side pixmap to draw on. */ xcb_pixmap_t edit_pixmap; + /** Cairo Surface for edit_pixmap */ cairo_surface_t *edit_surf; + /** Drawable context for edit_surf */ cairo_t *edit_draw; + /** Indicate that fake background should be drawn relative to the window */ int fake_bgrel; + /** Main flags */ MenuFlags flags; + /** List of stacked views */ GQueue views; + /** Current work area */ workarea mon; + /** timeout for reloading */ guint idle_timeout; + /** debug counter for redraws */ uint64_t count; - guint repaint_timeout; + /** redraw idle time. */ + guint repaint_source; } CacheState = { .main_window = XCB_WINDOW_NONE, .fake_bg = NULL, @@ -94,7 +112,7 @@ struct .views = G_QUEUE_INIT, .idle_timeout = 0, .count = 0L, - .repaint_timeout = 0, + .repaint_source = 0, }; static char * get_matching_state ( void ) @@ -188,7 +206,7 @@ static gboolean rofi_view_repaint ( G_GNUC_UNUSED void * data ) 0, 0, 0, 0, current_active_menu->width, current_active_menu->height ); xcb_flush ( xcb->connection ); TICK_N ( "flush" ); - CacheState.repaint_timeout = 0; + CacheState.repaint_source = 0; } return G_SOURCE_REMOVE; } @@ -299,10 +317,10 @@ void rofi_view_reload ( void ) } void rofi_view_queue_redraw ( void ) { - if ( current_active_menu && CacheState.repaint_timeout == 0 ) { + if ( current_active_menu && CacheState.repaint_source == 0 ) { CacheState.count++; g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "redraw %lu\n", CacheState.count ); - CacheState.repaint_timeout = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL ); + CacheState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL ); } } @@ -479,11 +497,7 @@ static void rofi_view_setup_fake_transparency ( void ) */ TICK_N ( "Fake start" ); if ( g_strcmp0 ( config.fake_background, "screenshot" ) == 0 ) { - s = cairo_xcb_surface_create ( xcb->connection, - xcb_stuff_get_root_window ( xcb ), - root_visual, - xcb->screen->width_in_pixels, - xcb->screen->height_in_pixels ); + s = x11_helper_get_screenshot_surface (); } else if ( g_strcmp0 ( config.fake_background, "background" ) == 0 ) { s = x11_helper_get_bg_surface (); @@ -1320,8 +1334,8 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *ev, xkb_st } rofi_view_update ( state ); - if ( ( ev->response_type & ~0x80 ) == XCB_EXPOSE && CacheState.repaint_timeout == 0 ) { - CacheState.repaint_timeout = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL ); + if ( ( ev->response_type & ~0x80 ) == XCB_EXPOSE && CacheState.repaint_source == 0 ) { + CacheState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL ); } } @@ -1577,8 +1591,8 @@ void rofi_view_cleanup () g_source_remove ( CacheState.idle_timeout ); CacheState.idle_timeout = 0; } - if ( CacheState.repaint_timeout > 0 ) { - g_source_remove ( CacheState.repaint_timeout ); + if ( CacheState.repaint_source > 0 ) { + g_source_remove ( CacheState.repaint_source ); CacheState.idle_timeout = 0; } if ( CacheState.fake_bg ) { diff --git a/source/x11-helper.c b/source/x11-helper.c index a5c0e581..e850c311 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -51,8 +51,12 @@ #include "x11-helper.h" #include "xkb-internal.h" +/** Log domain for this module */ #define LOG_DOMAIN "X11Helper" +/** + * Structure holding xcb objects needed to function. + */ struct _xcb_stuff xcb_int = { .connection = NULL, .screen = NULL, @@ -63,14 +67,32 @@ struct _xcb_stuff xcb_int = { }; xcb_stuff *xcb = &xcb_int; +/** + * Depth of root window. + */ xcb_depth_t *depth = NULL; xcb_visualtype_t *visual = NULL; xcb_colormap_t map = XCB_COLORMAP_NONE; -xcb_visualtype_t *root_visual = NULL; +/** + * Visual of the root window. + */ +static xcb_visualtype_t *root_visual = NULL; xcb_atom_t netatoms[NUM_NETATOMS]; const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) }; + +/** + * Holds for each supported modifier the possible modifier mask. + * Check x11_mod_masks[MODIFIER]&mask != 0 to see if MODIFIER is activated. + */ static unsigned int x11_mod_masks[NUM_X11MOD]; +cairo_surface_t *x11_helper_get_screenshot_surface ( void ) +{ + return cairo_xcb_surface_create ( xcb->connection, + xcb_stuff_get_root_window ( xcb ), root_visual, + xcb->screen->width_in_pixels, xcb->screen->height_in_pixels ); +} + static xcb_pixmap_t get_root_pixmap ( xcb_connection_t *c, xcb_screen_t *screen, xcb_atom_t atom ) @@ -824,10 +846,9 @@ void x11_helper_set_cairo_rgba ( cairo_t *d, Color col ) { cairo_set_source_rgba ( d, col.red, col.green, col.blue, col.alpha ); } + /** - * Color cache. - * - * This stores the current color until + * Type of colors stored */ enum { @@ -835,9 +856,16 @@ enum BORDER, SEPARATOR }; +/** + * Color cache. + * + * This stores the current color until + */ static struct { + /** The color */ Color color; + /** Flag indicating it is set. */ unsigned int set; } color_cache[3]; @@ -911,8 +939,9 @@ void xcb_stuff_wipe ( xcb_stuff *xcb ) void x11_disable_decoration ( xcb_window_t window ) { -#define MWM_HINTS_FUNCTIONS ( 1 << 0 ) -#define MWM_HINTS_DECORATIONS ( 1 << 1 ) + // Flag used to indicate we are setting the decoration type. + const uint32_t MWM_HINTS_DECORATIONS = ( 1 << 1 ); + // Motif property data structure struct MotifWMHints { uint32_t flags; @@ -923,7 +952,7 @@ void x11_disable_decoration ( xcb_window_t window ) }; struct MotifWMHints hints; - hints.flags = /*MWM_HINTS_FUNCTIONS |*/ MWM_HINTS_DECORATIONS; + hints.flags = MWM_HINTS_DECORATIONS; hints.decorations = 0; hints.functions = 0; hints.inputMode = 0; @@ -931,6 +960,4 @@ void x11_disable_decoration ( xcb_window_t window ) xcb_atom_t ha = netatoms[_MOTIF_WM_HINTS]; xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, window, ha, ha, 32, 5, &hints ); -#undef MWM_HINTS_DECORATIONS -#undef MWM_HINTS_FUNCTIONS }