1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Add fake transparency

This commit is contained in:
Qball Cow 2015-10-20 18:41:45 +02:00
parent 64cb4c781c
commit a7c7cf8159
5 changed files with 93 additions and 50 deletions

View file

@ -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,
};

View file

@ -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. */

View file

@ -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

View file

@ -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;

View file

@ -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.