Add option to view background image instead of screenshot in fake transparency. Issue #390

This commit is contained in:
Dave Davenport 2016-05-06 12:40:28 +02:00
parent ea3b5a39ca
commit 8e05106c87
11 changed files with 223 additions and 97 deletions

View File

@ -125,4 +125,5 @@ Settings config = {
.threads = 1, .threads = 1,
.scrollbar_width = 8, .scrollbar_width = 8,
.scroll_method = 0, .scroll_method = 0,
.fake_background = "screenshot",
}; };

View File

@ -589,6 +589,10 @@ simultaneously. This is useful when running **rofi** from a keybinding daemon.
Enable fake transparency. This only works with transparent background color in the theme, not the opacity setting. Enable fake transparency. This only works with transparent background color in the theme, not the opacity setting.
`-fake-background`
Select what to use as background for fake transparency. This can be 'background' or 'screenshot'
### Debug ### Debug

View File

@ -1,7 +1,7 @@
.\" 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" "" "April 2016" "" "" .TH "ROFI\-MANPAGE" "" "May 2016" "" ""
. .
.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
@ -932,6 +932,12 @@ Make \fBrofi\fR create a pid file and check this on startup\. Avoiding multiple
.P .P
Enable fake transparency\. This only works with transparent background color in the theme, not the opacity setting\. Enable fake transparency\. This only works with transparent background color in the theme, not the opacity setting\.
. .
.P
\fB\-fake\-background\fR
.
.P
Select what to use as background for fake transparency\. This can be \'background\' or \'screenshot\'
.
.SS "Debug" .SS "Debug"
\fB\-no\-config\fR \fB\-no\-config\fR
. .

View File

@ -127,6 +127,8 @@ typedef struct
unsigned int threads; unsigned int threads;
unsigned int scrollbar_width; unsigned int scrollbar_width;
unsigned int scroll_method; unsigned int scroll_method;
/** Background type */
char *fake_background;
} Settings; } Settings;
/** Global Settings structure. */ /** Global Settings structure. */
extern Settings config; extern Settings config;

View File

@ -38,7 +38,9 @@ void window_set_atom_prop ( xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms,
X ( I3_SOCKET_PATH ), \ X ( I3_SOCKET_PATH ), \
X ( UTF8_STRING ), \ X ( UTF8_STRING ), \
X ( STRING ), \ X ( STRING ), \
X ( WM_WINDOW_ROLE ) X ( WM_WINDOW_ROLE ), \
X ( _XROOTPMAP_ID ), \
X ( ESETROOT_PMAP_ID )
enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS }; enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS };
@ -134,5 +136,12 @@ void color_border ( cairo_t *d );
void color_separator ( cairo_t *d ); void color_separator ( cairo_t *d );
void x11_helper_set_cairo_rgba ( cairo_t *d, Color col ); void x11_helper_set_cairo_rgba ( cairo_t *d, Color col );
/**
* Gets a surface containing the background image of the desktop.
*
* @param a cairo surface with the background image of the desktop.
*/
cairo_surface_t * x11_helper_get_bg_surface ( void );
/*@}*/ /*@}*/
#endif #endif

View File

@ -544,7 +544,8 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i
if ( rmpd->config_i3_mode ) { if ( rmpd->config_i3_mode ) {
// Hack for i3. // Hack for i3.
i3_support_focus_window ( rmpd->ids->array[selected_line] ); i3_support_focus_window ( rmpd->ids->array[selected_line] );
} else { }
else {
// Get the current desktop. // Get the current desktop.
unsigned int current_desktop = 0; unsigned int current_desktop = 0;
xcb_get_property_cookie_t c = xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr ); xcb_get_property_cookie_t c = xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr );

View File

@ -517,18 +517,29 @@ static void check_is_ascii ( thread_state *t, G_GNUC_UNUSED gpointer user_data )
static void rofi_view_setup_fake_transparency ( void ) static void rofi_view_setup_fake_transparency ( void )
{ {
if ( CacheState.fake_bg == NULL ) { if ( CacheState.fake_bg == NULL ) {
cairo_surface_t *s = cairo_xcb_surface_create ( xcb->connection, cairo_surface_t *s = NULL;
/**
* Select Background to use for fake transparency.
* Current options: 'screenshot','background'
*/
if ( g_strcmp0 ( config.fake_background, "screenshot" ) == 0 ) {
s = cairo_xcb_surface_create ( xcb->connection,
xcb_stuff_get_root_window ( xcb ), xcb_stuff_get_root_window ( xcb ),
root_visual, root_visual,
xcb->screen->width_in_pixels, xcb->screen->width_in_pixels,
xcb->screen->height_in_pixels ); xcb->screen->height_in_pixels );
}
else if ( g_strcmp0 ( config.fake_background, "background" ) == 0 ) {
s = x11_helper_get_bg_surface ();
}
if ( s != NULL ) {
CacheState.fake_bg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, CacheState.mon.w, CacheState.mon.h ); CacheState.fake_bg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, CacheState.mon.w, CacheState.mon.h );
cairo_t *dr = cairo_create ( CacheState.fake_bg ); cairo_t *dr = cairo_create ( CacheState.fake_bg );
cairo_set_source_surface ( dr, s, -CacheState.mon.x, -CacheState.mon.y ); cairo_set_source_surface ( dr, s, -CacheState.mon.x, -CacheState.mon.y );
cairo_paint ( dr ); cairo_paint ( dr );
cairo_destroy ( dr ); cairo_destroy ( dr );
cairo_surface_destroy ( s ); cairo_surface_destroy ( s );
}
TICK_N ( "Fake transparency" ); TICK_N ( "Fake transparency" );
} }
} }
@ -612,7 +623,6 @@ void __create_window ( MenuFlags menu_flags )
} }
} }
/** /**
* @param state Internal state of the menu. * @param state Internal state of the menu.
* *

View File

@ -33,6 +33,7 @@
#include <stdint.h> #include <stdint.h>
#include <glib.h> #include <glib.h>
#include <cairo.h> #include <cairo.h>
#include <cairo-xcb.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xinerama.h> #include <xcb/xinerama.h>
@ -83,6 +84,47 @@ xcb_atom_t netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) }; const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
static unsigned int x11_mod_masks[NUM_X11MOD]; static unsigned int x11_mod_masks[NUM_X11MOD];
static xcb_pixmap_t get_root_pixmap ( xcb_connection_t *c,
xcb_screen_t *screen,
xcb_atom_t atom )
{
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply;
xcb_pixmap_t *rootpixmap = NULL;
cookie = xcb_get_property ( c,
0,
screen->root,
atom,
XCB_ATOM_PIXMAP,
0,
1 );
reply = xcb_get_property_reply ( c, cookie, NULL );
if ( reply &&
( xcb_get_property_value_length ( reply ) == sizeof ( xcb_pixmap_t ) ) ) {
rootpixmap = (xcb_pixmap_t *) xcb_get_property_value ( reply );
}
else {
*rootpixmap = XCB_NONE;
}
free ( reply );
return *rootpixmap;
}
cairo_surface_t * x11_helper_get_bg_surface ( void )
{
xcb_pixmap_t pm = get_root_pixmap ( xcb->connection, xcb->screen, netatoms[ESETROOT_PMAP_ID] );
if ( pm == XCB_NONE ) {
return NULL;
}
return cairo_xcb_surface_create ( xcb->connection, pm, root_visual,
xcb->screen->width_in_pixels, xcb->screen->height_in_pixels );
}
// retrieve a text property from a window // retrieve a text property from a window
// technically we could use window_get_prop(), but this is better for character set support // technically we could use window_get_prop(), but this is better for character set support
char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom ) char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom )
@ -300,12 +342,12 @@ void monitor_active ( workarea *mon )
free ( r ); free ( r );
free ( t ); free ( t );
return; return;
} else if ( config.monitor == -4 ){ }
else if ( config.monitor == -4 ) {
monitor_dimensions ( t->dst_x, t->dst_y, mon ); monitor_dimensions ( t->dst_x, t->dst_y, mon );
free ( r ); free ( r );
free ( t ); free ( t );
return; return;
} }
} }
free ( r ); free ( r );

View File

@ -63,62 +63,113 @@ typedef struct
* Currently supports string, boolean and number (signed and unsigned). * Currently supports string, boolean and number (signed and unsigned).
*/ */
static XrmOption xrmOptions[] = { static XrmOption xrmOptions[] = {
{ xrm_String, "switchers", { .str = &config.modi }, NULL, "" }, { xrm_String, "switchers", { .str = &config.modi }, NULL,
{ xrm_String, "modi", { .str = &config.modi }, NULL, "Enabled modi" }, "" },
{ xrm_Number, "opacity", { .num = &config.window_opacity }, NULL, "Window opacity" }, { xrm_String, "modi", { .str = &config.modi }, NULL,
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL, "Window width" }, "Enabled modi" },
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL, "Number of lines" }, { xrm_Number, "opacity", { .num = &config.window_opacity }, NULL,
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL, "Number of columns" }, "Window opacity" },
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL,
"Window width" },
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL,
"Number of lines" },
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL,
"Number of columns" },
{ xrm_String, "font", { .str = &config.menu_font }, NULL, "Font to use" }, { xrm_String, "font", { .str = &config.menu_font }, NULL,
{ xrm_String, "color-normal", { .str = &config.color_normal }, NULL, "Color scheme for normal row" }, "Font to use" },
{ xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL, "Color scheme for urgent row" }, { xrm_String, "color-normal", { .str = &config.color_normal }, NULL,
{ xrm_String, "color-active", { .str = &config.color_active }, NULL, "Color scheme for active row" }, "Color scheme for normal row" },
{ xrm_String, "color-window", { .str = &config.color_window }, NULL, "Color scheme window" }, { xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL,
"Color scheme for urgent row" },
{ xrm_String, "color-active", { .str = &config.color_active }, NULL,
"Color scheme for active row" },
{ xrm_String, "color-window", { .str = &config.color_window }, NULL,
"Color scheme window" },
{ xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL, "" }, { xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL,
{ xrm_Number, "bw", { .num = &config.menu_bw }, NULL, "Border width" }, "" },
{ xrm_Number, "bw", { .num = &config.menu_bw }, NULL,
"Border width" },
{ xrm_Number, "location", { .num = &config.location }, NULL, "Location on screen" }, { xrm_Number, "location", { .num = &config.location }, NULL,
"Location on screen" },
{ xrm_Number, "padding", { .num = &config.padding }, NULL, "Padding" }, { xrm_Number, "padding", { .num = &config.padding }, NULL,
{ xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL, "Y-offset relative to location" }, "Padding" },
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL, "X-offset relative to location" }, { xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL,
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL, "Always show number of lines" }, "Y-offset relative to location" },
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL,
"X-offset relative to location" },
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL,
"Always show number of lines" },
{ xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL, "Terminal to use" }, { xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL,
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL, "Ssh client to use" }, "Terminal to use" },
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL, "Ssh command to execute" }, { xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL,
{ xrm_String, "run-command", { .str = &config.run_command }, NULL, "Run command to execute" }, "Ssh client to use" },
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL, "Command to get extra run targets" }, { xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL,
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL, "Run command to execute that runs in shell" }, "Ssh command to execute" },
{ xrm_String, "run-command", { .str = &config.run_command }, NULL,
"Run command to execute" },
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL,
"Command to get extra run targets" },
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
"Run command to execute that runs in shell" },
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL, "Disable history in run/ssh" }, { xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL, "Use levenshtein sorting" }, "Disable history in run/ssh" },
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, "Set case-sensitivity" }, { xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL,
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL, "Enable sidebar-mode" }, "Use levenshtein sorting" },
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL, "Row height (in chars)" }, { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL,
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL, "Enable auto select mode" }, "Set case-sensitivity" },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL, "Parse hosts file for ssh mode" }, { xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL,
{ xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL, "Parse known_hosts file for ssh mode" }, "Enable sidebar-mode" },
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL, "Set the modi to combine in combi mode" }, { xrm_SNumber, "eh", { .snum = &config.element_height }, NULL,
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL, "Do a more fuzzy matching" }, "Row height (in chars)" },
{ xrm_Boolean, "glob", { .num = &config.glob }, NULL, "Use glob matching" }, { xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL,
{ xrm_Boolean, "regex", { .num = &config.regex }, NULL, "Use regex matching" }, "Enable auto select mode" },
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL, "Tokenize input string" }, { xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL,
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL, "" }, "Parse hosts file for ssh mode" },
{ xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL,
"Parse known_hosts file for ssh mode" },
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL,
"Set the modi to combine in combi mode" },
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL,
"Do a more fuzzy matching" },
{ xrm_Boolean, "glob", { .num = &config.glob }, NULL,
"Use glob matching" },
{ xrm_Boolean, "regex", { .num = &config.regex }, NULL,
"Use regex matching" },
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL,
"Tokenize input string" },
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL,
"" },
/* Alias for dmenu compatibility. */ /* Alias for dmenu compatibility. */
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL, "Monitor id to show on" }, { xrm_SNumber, "m", { .snum = &config.monitor }, NULL,
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL, "Margin between rows" }, "Monitor id to show on" },
{ xrm_String, "filter", { .str = &config.filter }, NULL, "Pre-set filter" }, { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL, "Separator style (none, dash, solid)" }, "Margin between rows" },
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, "Hide scroll-bar" }, { xrm_String, "filter", { .str = &config.filter }, NULL,
{ xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, "Fullscreen" }, "Pre-set filter" },
{ xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, "Fake transparency" }, { xrm_String, "separator-style", { .str = &config.separator_style }, NULL,
{ xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL, "DPI" }, "Separator style (none, dash, solid)" },
{ xrm_Number, "threads", { .num = &config.threads }, NULL, "Threads to use for string matching" }, { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL,
{ xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, "Scrollbar width" }, "Hide scroll-bar" },
{ xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL, "Scrolling method. (0: Page, 1: Centered)" } { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL,
"Fullscreen" },
{ xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL,
"Fake transparency" },
{ xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL,
"DPI" },
{ xrm_Number, "threads", { .num = &config.threads }, NULL,
"Threads to use for string matching" },
{ xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL,
"Scrollbar width" },
{ xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL,
"Scrolling method. (0: Page, 1: Centered)" },
{ xrm_String, "fake-background", { .str = &config.fake_background }, NULL,
"Background to use for fake transparency. (background or screenshot)" },
}; };
// Dynamic options. // Dynamic options.