diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-05-08 11:14:34 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-05-08 11:14:34 +0200 |
commit | b8ecbdcef5784463f95db73a7310e73936379524 (patch) | |
tree | 2238925b54a201df0b06457d85e2557914c96ec5 /source/view.c | |
parent | 8f6c9ee070b60af7f93ca3a44fc0a58df4623272 (diff) |
Add option to set background for rofi window
Diffstat (limited to 'source/view.c')
-rw-r--r-- | source/view.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/source/view.c b/source/view.c index 18e98704..cd77bdf4 100644 --- a/source/view.c +++ b/source/view.c @@ -76,6 +76,7 @@ struct xcb_window_t main_window; cairo_surface_t *surface; cairo_surface_t *fake_bg; + int fake_bgrel; cairo_t *draw; MenuFlags flags; GQueue views; @@ -86,6 +87,7 @@ struct .main_window = XCB_WINDOW_NONE, .surface = NULL, .fake_bg = NULL, + .fake_bgrel = FALSE, .draw = NULL, .flags = MENU_NORMAL, .views = G_QUEUE_INIT, @@ -532,13 +534,30 @@ static void rofi_view_setup_fake_transparency ( void ) else if ( g_strcmp0 ( config.fake_background, "background" ) == 0 ) { s = x11_helper_get_bg_surface (); } + else { + char *fpath = rofi_expand_path ( config.fake_background ); + s = cairo_image_surface_create_from_png ( fpath ); + CacheState.fake_bgrel = TRUE; + g_free ( fpath ); + } if ( s != NULL ) { - 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_set_source_surface ( dr, s, -CacheState.mon.x, -CacheState.mon.y ); - cairo_paint ( dr ); - cairo_destroy ( dr ); - cairo_surface_destroy ( s ); + if ( cairo_surface_status ( s ) != CAIRO_STATUS_SUCCESS ) { + cairo_surface_destroy ( s ); + s = NULL; + } + else { + CacheState.fake_bg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, CacheState.mon.w, CacheState.mon.h ); + cairo_t *dr = cairo_create ( CacheState.fake_bg ); + if ( CacheState.fake_bgrel ) { + cairo_set_source_surface ( dr, s, 0, 0 ); + } + else { + cairo_set_source_surface ( dr, s, -CacheState.mon.x, -CacheState.mon.y ); + } + cairo_paint ( dr ); + cairo_destroy ( dr ); + cairo_surface_destroy ( s ); + } } TICK_N ( "Fake transparency" ); } @@ -954,9 +973,14 @@ void rofi_view_update ( RofiViewState *state ) cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE ); if ( config.fake_transparency ) { if ( CacheState.fake_bg != NULL ) { - cairo_set_source_surface ( d, CacheState.fake_bg, - -(double) ( CacheState.x - CacheState.mon.x ), - -(double) ( CacheState.y - CacheState.mon.y ) ); + if ( CacheState.fake_bgrel ) { + cairo_set_source_surface ( d, CacheState.fake_bg, 0.0, 0.0 ); + } + else { + cairo_set_source_surface ( d, CacheState.fake_bg, + -(double) ( CacheState.x - CacheState.mon.x ), + -(double) ( CacheState.y - CacheState.mon.y ) ); + } cairo_paint ( d ); cairo_set_operator ( d, CAIRO_OPERATOR_OVER ); color_background ( d ); |