From a7c7cf8159c6fed2c40ee45f25f508b3f1467c9a Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Tue, 20 Oct 2015 18:41:45 +0200 Subject: [PATCH] Add fake transparency --- config/config.def.c | 7 +-- include/rofi.h | 2 + include/textbox.h | 16 +++--- source/rofi.c | 115 +++++++++++++++++++++++++++++--------------- source/xrmoptions.c | 3 +- 5 files changed, 93 insertions(+), 50 deletions(-) diff --git a/config/config.def.c b/config/config.def.c index fcf2f4cb..701d6cce 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -141,7 +141,8 @@ Settings config = { /** Separator style: dash/solid */ .separator_style = "dash", /** Hide scrollbar */ - .hide_scrollbar = FALSE, - .markup_rows = FALSE, - .fullscreen = FALSE, + .hide_scrollbar = FALSE, + .markup_rows = FALSE, + .fullscreen = FALSE, + .fake_transparency = FALSE, }; diff --git a/include/rofi.h b/include/rofi.h index 871a676c..ff52b71d 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -246,6 +246,8 @@ typedef struct _Settings unsigned int markup_rows; /** fullscreen */ unsigned int fullscreen; + /** bg image */ + unsigned int fake_transparency; } Settings; /** Global Settings structure. */ diff --git a/include/textbox.h b/include/textbox.h index 7fb53305..2b2f2e57 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -33,14 +33,14 @@ 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_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, } TextboxFlags; typedef enum diff --git a/source/rofi.c b/source/rofi.c index f5b26aec..73b78abf 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -176,54 +176,55 @@ static int levenshtein ( char *s1, char *s2 ) typedef struct MenuState { - Switcher *sw; - unsigned int menu_lines; - unsigned int max_elements; - unsigned int max_rows; - unsigned int columns; + Switcher *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; + 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; + 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; + 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; + unsigned int num_lines; // Selected element. - unsigned int selected; - unsigned int filtered_lines; + unsigned int selected; + unsigned int filtered_lines; // Last offset in paginating. - unsigned int last_offset; + unsigned int last_offset; - KeySym prev_key; - Time last_button_press; + KeySym prev_key; + Time last_button_press; - int quit; - int skip_absorb; + int quit; + int skip_absorb; // Return state - unsigned int *selected_line; - MenuReturn retv; - char **lines; - int *lines_not_ascii; - int line_height; - unsigned int border; + unsigned int *selected_line; + MenuReturn retv; + char **lines; + int *lines_not_ascii; + int line_height; + unsigned int border; + cairo_surface_t *bg; }MenuState; static Window create_window ( Display *display ) @@ -285,6 +286,10 @@ static void menu_free_state ( MenuState *state ) textbox_free ( state->prompt_tb ); textbox_free ( state->case_indicator ); scrollbar_free ( state->scrollbar ); + if ( state->bg ) { + cairo_surface_destroy ( state->bg ); + state->bg = NULL; + } for ( unsigned int i = 0; i < state->max_elements; i++ ) { textbox_free ( state->boxes[i] ); @@ -829,9 +834,20 @@ static void menu_update ( MenuState *state ) cairo_surface_t *surf = cairo_image_surface_create ( get_format (), state->w, state->h ); cairo_t *d = cairo_create ( surf ); cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE ); - // Paint the background. - color_background ( display, d ); - cairo_paint ( d ); + if ( config.fake_transparency ) { + if ( state->bg != NULL ) { + cairo_set_source_surface ( d, state->bg, -(double) ( state->x ), -(double) ( state->y ) ); + cairo_paint ( d ); + cairo_set_operator ( d, CAIRO_OPERATOR_OVER ); + color_background ( display, d ); + cairo_paint ( d ); + } + } + else { + // Paint the background. + color_background ( display, d ); + cairo_paint ( d ); + } color_border ( display, d ); if ( config.menu_bw > 0 ) { @@ -1042,6 +1058,24 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select sn_launchee_context_setup_window ( sncontext, main_window ); } } + Window root = DefaultRootWindow ( display ); + if ( config.fake_transparency ) { + cairo_surface_t *s = cairo_xlib_surface_create ( display, + root, + DefaultVisual ( display, DefaultScreen ( display ) ), + DisplayWidth ( display, DefaultScreen ( display ) ), + DisplayHeight ( display, DefaultScreen ( display ) ) ); + + state.bg = cairo_image_surface_create ( get_format (), + DisplayWidth ( display, DefaultScreen ( display ) ), + DisplayHeight ( display, DefaultScreen ( display ) ) ); + cairo_t *dr = cairo_create ( state.bg ); + cairo_set_source_surface ( dr, s, 0, 0 ); + cairo_paint ( dr ); + cairo_destroy ( dr ); + cairo_surface_destroy ( s ); + } + // Get active monitor size. monitor_active ( display, &mon ); @@ -1215,6 +1249,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select else if ( ev.type == ConfigureNotify ) { XConfigureEvent xce = ev.xconfigure; if ( xce.window == main_window ) { + if ( state.x != (int ) xce.x || state.y != (int) xce.y ) { + state.x = xce.x; + state.y = xce.y; + state.update = TRUE; + } if ( state.w != (unsigned int) xce.width || state.h != (unsigned int ) xce.height ) { state.w = xce.width; state.h = xce.height; diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 2e090215..ac211585 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -133,7 +133,8 @@ static XrmOption xrmOptions[] = { { xrm_String, "separator-style", { .str = &config.separator_style }, NULL, "Separator style (none, dash, solid)" }, { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, "Hide the scroll-bar" }, { xrm_Boolean, "markup-rows", { .num = &config.markup_rows }, NULL, "Show markup" }, - { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, "Fullscreen" } + { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, "Fullscreen" }, + { xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, "Fake transparency" } }; // Dynamic options.