1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-07-31 21:59:25 -04:00

Merge remote-tracking branch 'origin/Transparency'

This commit is contained in:
QC 2015-10-21 20:42:40 +02:00
commit de1f7a11aa
7 changed files with 127 additions and 74 deletions

View file

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

View file

@ -54,6 +54,7 @@
[ -parse-hosts ] [ -parse-hosts ]
[ -combi-modi *mode1,mode2* ] [ -combi-modi *mode1,mode2* ]
[ -normal-window ] [ -normal-window ]
[ -fake-transparency ]
[ -quiet ] [ -quiet ]
## DESCRIPTION ## DESCRIPTION
@ -577,6 +578,11 @@ For more information on supported markup see [here](https://developer.gnome.org/
Make **rofi** reacts like a normal application window. Useful for scripts like Clerk that are basically an application. Make **rofi** reacts like a normal application window. Useful for scripts like Clerk that are basically an application.
`-fake-transparency`
Enable fake transparency. This only works with transparent background color in the theme, not the opacity setting.
### Message dialog ### Message dialog
`-e` *message* `-e` *message*

View file

@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "ROFI\-MANPAGE" "" "September 2015" "" "" .TH "ROFI\-MANPAGE" "" "October 2015" "" ""
. .
.SH "NAME" .SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
. .
.SH "SYNOPSIS" .SH "SYNOPSIS"
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-fg \fIcolor\fR ] [ \-fg\-urgent \fIcolor\fR ] [ \-fg\-active \fIcolor\fR ] [ \-bg\-urgent \fIcolor\fR ] [ \-bg\-active \fIcolor\fR ] [ \-bg \fIcolor\fR ] [ \-bgalt \fIcolor\fR ] [ \-hlfg \fIcolor\fR ] [ \-hlbg \fIcolor\fR ] [ \-key\-\fBmode\fR \fIcombo\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bc \fIcolor\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-quiet ] \fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-fg \fIcolor\fR ] [ \-fg\-urgent \fIcolor\fR ] [ \-fg\-active \fIcolor\fR ] [ \-bg\-urgent \fIcolor\fR ] [ \-bg\-active \fIcolor\fR ] [ \-bg \fIcolor\fR ] [ \-bgalt \fIcolor\fR ] [ \-hlfg \fIcolor\fR ] [ \-hlbg \fIcolor\fR ] [ \-key\-\fBmode\fR \fIcombo\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bc \fIcolor\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-quiet ]
. .
.SH "DESCRIPTION" .SH "DESCRIPTION"
\fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\. \fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\.
@ -969,6 +969,12 @@ Add a message line below the filter entry box\. Supports pango markup\. For more
.P .P
Make \fBrofi\fR reacts like a normal application window\. Useful for scripts like Clerk that are basically an application\. Make \fBrofi\fR reacts like a normal application window\. Useful for scripts like Clerk that are basically an application\.
. .
.P
\fB\-fake\-transparency\fR
.
.P
Enable fake transparency\. This only works with transparent background color in the theme, not the opacity setting\.
.
.SS "Message dialog" .SS "Message dialog"
\fB\-e\fR \fImessage\fR \fB\-e\fR \fImessage\fR
. .

View file

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

View file

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

View file

@ -176,54 +176,56 @@ 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;
workarea mon;
}MenuState; }MenuState;
static Window create_window ( Display *display ) static Window create_window ( Display *display )
@ -285,6 +287,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] );
@ -302,33 +308,33 @@ static void menu_free_state ( MenuState *state )
* *
* Calculates the window poslition * Calculates the window poslition
*/ */
static void calculate_window_position ( MenuState *state, const workarea *mon ) static void calculate_window_position ( MenuState *state )
{ {
// Default location is center. // Default location is center.
state->y = mon->y + ( mon->h - state->h ) / 2; state->y = state->mon.y + ( state->mon.h - state->h ) / 2;
state->x = mon->x + ( mon->w - state->w ) / 2; state->x = state->mon.x + ( state->mon.w - state->w ) / 2;
// Determine window location // Determine window location
switch ( config.location ) switch ( config.location )
{ {
case WL_NORTH_WEST: case WL_NORTH_WEST:
state->x = mon->x; state->x = state->mon.x;
case WL_NORTH: case WL_NORTH:
state->y = mon->y; state->y = state->mon.y;
break; break;
case WL_NORTH_EAST: case WL_NORTH_EAST:
state->y = mon->y; state->y = state->mon.y;
case WL_EAST: case WL_EAST:
state->x = mon->x + mon->w - state->w; state->x = state->mon.x + state->mon.w - state->w;
break; break;
case WL_EAST_SOUTH: case WL_EAST_SOUTH:
state->x = mon->x + mon->w - state->w; state->x = state->mon.x + state->mon.w - state->w;
case WL_SOUTH: case WL_SOUTH:
state->y = mon->y + mon->h - state->h; state->y = state->mon.y + state->mon.h - state->h;
break; break;
case WL_SOUTH_WEST: case WL_SOUTH_WEST:
state->y = mon->y + mon->h - state->h; state->y = state->mon.y + state->mon.h - state->h;
case WL_WEST: case WL_WEST:
state->x = mon->x; state->x = state->mon.x;
break; break;
case WL_CENTER: case WL_CENTER:
default: default:
@ -829,9 +835,22 @@ 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 - state->mon.x ),
-(double) ( state->y - state->mon.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 ) {
@ -1022,8 +1041,6 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
if ( next_pos ) { if ( next_pos ) {
*next_pos = *selected_line; *next_pos = *selected_line;
} }
workarea mon;
// Try to grab the keyboard as early as possible. // Try to grab the keyboard as early as possible.
// We grab this using the rootwindow (as dmenu does it). // We grab this using the rootwindow (as dmenu does it).
// this seems to result in the smallest delay for most people. // this seems to result in the smallest delay for most people.
@ -1043,7 +1060,23 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
} }
} }
// Get active monitor size. // Get active monitor size.
monitor_active ( display, &mon ); monitor_active ( display, &( state.mon ) );
if ( config.fake_transparency ) {
Window root = DefaultRootWindow ( display );
int screen = DefaultScreen ( display );
cairo_surface_t *s = cairo_xlib_surface_create ( display,
root,
DefaultVisual ( display, screen ),
DisplayWidth ( display, screen ),
DisplayHeight ( display, screen ) );
state.bg = cairo_image_surface_create ( get_format (), state.mon.w, state.mon.h );
cairo_t *dr = cairo_create ( state.bg );
cairo_set_source_surface ( dr, s, -state.mon.x, -state.mon.y );
cairo_paint ( dr );
cairo_destroy ( dr );
cairo_surface_destroy ( s );
}
// we need this at this point so we can get height. // we need this at this point so we can get height.
state.line_height = textbox_get_estimated_char_height (); state.line_height = textbox_get_estimated_char_height ();
@ -1052,7 +1085,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
// Height of a row. // Height of a row.
if ( config.menu_lines == 0 ) { if ( config.menu_lines == 0 ) {
// Autosize it. // Autosize it.
int h = mon.h - state.border * 2 - config.line_margin; int h = state.mon.h - state.border * 2 - config.line_margin;
int r = ( h ) / ( state.line_height * config.element_height ) - 1 - config.sidebar_mode; int r = ( h ) / ( state.line_height * config.element_height ) - 1 - config.sidebar_mode;
state.menu_lines = r; state.menu_lines = r;
} }
@ -1060,7 +1093,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
state.menu_lines = config.menu_lines; state.menu_lines = config.menu_lines;
} }
menu_calculate_rows_columns ( &state ); menu_calculate_rows_columns ( &state );
menu_calculate_window_and_element_width ( &state, &mon ); menu_calculate_window_and_element_width ( &state, &( state.mon ) );
// Prompt box. // Prompt box.
state.prompt_tb = textbox_create ( TB_AUTOWIDTH, ( state.border ), ( state.border ), state.prompt_tb = textbox_create ( TB_AUTOWIDTH, ( state.border ), ( state.border ),
@ -1132,11 +1165,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
// Sidebar mode. // Sidebar mode.
if ( config.menu_lines == 0 ) { if ( config.menu_lines == 0 ) {
state.h = mon.h; state.h = state.mon.h;
} }
// Move the window to the correct x,y position. // Move the window to the correct x,y position.
calculate_window_position ( &state, &mon ); calculate_window_position ( &state );
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
int width = ( state.w - ( 2 * ( state.border ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; int width = ( state.w - ( 2 * ( state.border ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
@ -1215,6 +1248,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;
@ -1418,7 +1456,6 @@ void error_dialog ( const char *msg, int markup )
.columns = 0, .columns = 0,
.update = TRUE, .update = TRUE,
}; };
workarea mon;
// Try to grab the keyboard as early as possible. // Try to grab the keyboard as early as possible.
// We grab this using the rootwindow (as dmenu does it). // We grab this using the rootwindow (as dmenu does it).
@ -1430,14 +1467,14 @@ void error_dialog ( const char *msg, int markup )
return; return;
} }
// Get active monitor size. // Get active monitor size.
monitor_active ( display, &mon ); monitor_active ( display, &( state.mon ) );
// main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker // main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker
XWindowAttributes attr; XWindowAttributes attr;
if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) { if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) {
main_window = create_window ( display ); main_window = create_window ( display );
} }
menu_calculate_window_and_element_width ( &state, &mon ); menu_calculate_window_and_element_width ( &state, &( state.mon ) );
state.max_elements = 0; state.max_elements = 0;
state.text = textbox_create ( ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), state.text = textbox_create ( ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
@ -1449,7 +1486,7 @@ void error_dialog ( const char *msg, int markup )
state.h = state.line_height + ( state.border ) * 2; state.h = state.line_height + ( state.border ) * 2;
// Move the window to the correct x,y position. // Move the window to the correct x,y position.
calculate_window_position ( &state, &mon ); calculate_window_position ( &state );
XMoveResizeWindow ( display, main_window, state.x, state.y, state.w, state.h ); XMoveResizeWindow ( display, main_window, state.x, state.y, state.w, state.h );
cairo_xlib_surface_set_size ( surface, state.w, state.h ); cairo_xlib_surface_set_size ( surface, state.w, state.h );
// Display it. // Display it.

View file

@ -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 scroll-bar" }, { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, "Hide 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.