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:
parent
64cb4c781c
commit
a7c7cf8159
5 changed files with 93 additions and 50 deletions
|
@ -141,7 +141,8 @@ Settings config = {
|
||||||
/** Separator style: dash/solid */
|
/** Separator style: dash/solid */
|
||||||
.separator_style = "dash",
|
.separator_style = "dash",
|
||||||
/** Hide scrollbar */
|
/** Hide scrollbar */
|
||||||
.hide_scrollbar = FALSE,
|
.hide_scrollbar = FALSE,
|
||||||
.markup_rows = FALSE,
|
.markup_rows = FALSE,
|
||||||
.fullscreen = FALSE,
|
.fullscreen = FALSE,
|
||||||
|
.fake_transparency = FALSE,
|
||||||
};
|
};
|
||||||
|
|
|
@ -246,6 +246,8 @@ typedef struct _Settings
|
||||||
unsigned int markup_rows;
|
unsigned int markup_rows;
|
||||||
/** fullscreen */
|
/** fullscreen */
|
||||||
unsigned int fullscreen;
|
unsigned int fullscreen;
|
||||||
|
/** bg image */
|
||||||
|
unsigned int fake_transparency;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
/** Global Settings structure. */
|
/** Global Settings structure. */
|
||||||
|
|
|
@ -33,14 +33,14 @@ typedef struct
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TB_AUTOHEIGHT = 1 << 0,
|
TB_AUTOHEIGHT = 1 << 0,
|
||||||
TB_AUTOWIDTH = 1 << 1,
|
TB_AUTOWIDTH = 1 << 1,
|
||||||
TB_LEFT = 1 << 16,
|
TB_LEFT = 1 << 16,
|
||||||
TB_RIGHT = 1 << 17,
|
TB_RIGHT = 1 << 17,
|
||||||
TB_CENTER = 1 << 18,
|
TB_CENTER = 1 << 18,
|
||||||
TB_EDITABLE = 1 << 19,
|
TB_EDITABLE = 1 << 19,
|
||||||
TB_MARKUP = 1 << 20,
|
TB_MARKUP = 1 << 20,
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
115
source/rofi.c
115
source/rofi.c
|
@ -176,54 +176,55 @@ static int levenshtein ( char *s1, char *s2 )
|
||||||
|
|
||||||
typedef struct MenuState
|
typedef struct MenuState
|
||||||
{
|
{
|
||||||
Switcher *sw;
|
Switcher *sw;
|
||||||
unsigned int menu_lines;
|
unsigned int menu_lines;
|
||||||
unsigned int max_elements;
|
unsigned int max_elements;
|
||||||
unsigned int max_rows;
|
unsigned int max_rows;
|
||||||
unsigned int columns;
|
unsigned int columns;
|
||||||
|
|
||||||
// window width,height
|
// window width,height
|
||||||
unsigned int w, h;
|
unsigned int w, h;
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int element_width;
|
unsigned int element_width;
|
||||||
int top_offset;
|
int top_offset;
|
||||||
|
|
||||||
// Update/Refilter list.
|
// Update/Refilter list.
|
||||||
int update;
|
int update;
|
||||||
int refilter;
|
int refilter;
|
||||||
int rchanged;
|
int rchanged;
|
||||||
int cur_page;
|
int cur_page;
|
||||||
|
|
||||||
// Entries
|
// Entries
|
||||||
textbox *text;
|
textbox *text;
|
||||||
textbox *prompt_tb;
|
textbox *prompt_tb;
|
||||||
textbox *message_tb;
|
textbox *message_tb;
|
||||||
textbox *case_indicator;
|
textbox *case_indicator;
|
||||||
textbox **boxes;
|
textbox **boxes;
|
||||||
scrollbar *scrollbar;
|
scrollbar *scrollbar;
|
||||||
int *distance;
|
int *distance;
|
||||||
unsigned int *line_map;
|
unsigned int *line_map;
|
||||||
|
|
||||||
unsigned int num_lines;
|
unsigned int num_lines;
|
||||||
|
|
||||||
// Selected element.
|
// Selected element.
|
||||||
unsigned int selected;
|
unsigned int selected;
|
||||||
unsigned int filtered_lines;
|
unsigned int filtered_lines;
|
||||||
// Last offset in paginating.
|
// Last offset in paginating.
|
||||||
unsigned int last_offset;
|
unsigned int last_offset;
|
||||||
|
|
||||||
KeySym prev_key;
|
KeySym prev_key;
|
||||||
Time last_button_press;
|
Time last_button_press;
|
||||||
|
|
||||||
int quit;
|
int quit;
|
||||||
int skip_absorb;
|
int skip_absorb;
|
||||||
// Return state
|
// Return state
|
||||||
unsigned int *selected_line;
|
unsigned int *selected_line;
|
||||||
MenuReturn retv;
|
MenuReturn retv;
|
||||||
char **lines;
|
char **lines;
|
||||||
int *lines_not_ascii;
|
int *lines_not_ascii;
|
||||||
int line_height;
|
int line_height;
|
||||||
unsigned int border;
|
unsigned int border;
|
||||||
|
cairo_surface_t *bg;
|
||||||
}MenuState;
|
}MenuState;
|
||||||
|
|
||||||
static Window create_window ( Display *display )
|
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->prompt_tb );
|
||||||
textbox_free ( state->case_indicator );
|
textbox_free ( state->case_indicator );
|
||||||
scrollbar_free ( state->scrollbar );
|
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++ ) {
|
for ( unsigned int i = 0; i < state->max_elements; i++ ) {
|
||||||
textbox_free ( state->boxes[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_surface_t *surf = cairo_image_surface_create ( get_format (), state->w, state->h );
|
||||||
cairo_t *d = cairo_create ( surf );
|
cairo_t *d = cairo_create ( surf );
|
||||||
cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
|
cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
|
||||||
// Paint the background.
|
if ( config.fake_transparency ) {
|
||||||
color_background ( display, d );
|
if ( state->bg != NULL ) {
|
||||||
cairo_paint ( d );
|
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 );
|
color_border ( display, d );
|
||||||
|
|
||||||
if ( config.menu_bw > 0 ) {
|
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 );
|
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.
|
// Get active monitor size.
|
||||||
monitor_active ( display, &mon );
|
monitor_active ( display, &mon );
|
||||||
|
|
||||||
|
@ -1215,6 +1249,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
|
||||||
else if ( ev.type == ConfigureNotify ) {
|
else if ( ev.type == ConfigureNotify ) {
|
||||||
XConfigureEvent xce = ev.xconfigure;
|
XConfigureEvent xce = ev.xconfigure;
|
||||||
if ( xce.window == main_window ) {
|
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 ) {
|
if ( state.w != (unsigned int) xce.width || state.h != (unsigned int ) xce.height ) {
|
||||||
state.w = xce.width;
|
state.w = xce.width;
|
||||||
state.h = xce.height;
|
state.h = xce.height;
|
||||||
|
|
|
@ -133,7 +133,8 @@ static XrmOption xrmOptions[] = {
|
||||||
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL, "Separator style (none, dash, solid)" },
|
{ 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, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, "Hide the scroll-bar" },
|
||||||
{ xrm_Boolean, "markup-rows", { .num = &config.markup_rows }, NULL, "Show markup" },
|
{ 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.
|
// Dynamic options.
|
||||||
|
|
Loading…
Reference in a new issue