diff options
author | raveit65 <[email protected]> | 2018-03-21 21:03:17 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2018-03-22 21:24:30 +0100 |
commit | 1d90b700c7bf5036e9f1e7ddd0adb09bd39467ce (patch) | |
tree | 564d016e3cae8c41720779814bd6eb78d9c10624 /libview | |
parent | 1b1f2c58617b72efb9aad7ebc98fe390138d733f (diff) | |
download | atril-1d90b700c7bf5036e9f1e7ddd0adb09bd39467ce.tar.bz2 atril-1d90b700c7bf5036e9f1e7ddd0adb09bd39467ce.tar.xz |
libview: use css to draw the background of presentations
With the recent changes in gtk+, widgets have to draw themselves,
causing the current use of gdk_window_set_background_rgba to fail.
https://bugzilla.gnome.org/show_bug.cgi?id=765557
view: Redraw ev-view-presentation when setting normal and black mode.
The black and normal mode are the same from the CSS point of view.
The difference is that in the draw function the page is not drawn
in black mode. Hence, we need to explicitly queue a redraw in these
cases. Since setting the white mode add a CSS class, this queues
the redraw for us.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=772390.
origin commits:
https://git.gnome.org/browse/evince/commit/?id=2b352b3
https://git.gnome.org/browse/evince/commit/?id=b3f49f4
Fixes https://github.com/mate-desktop/atril/issues/232
Diffstat (limited to 'libview')
-rw-r--r-- | libview/ev-view-presentation.c | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/libview/ev-view-presentation.c b/libview/ev-view-presentation.c index 72df922d..997a11b1 100644 --- a/libview/ev-view-presentation.c +++ b/libview/ev-view-presentation.c @@ -116,9 +116,6 @@ static void ev_view_presentation_set_cursor_for_location (EvViewPresentation *pv G_DEFINE_TYPE (EvViewPresentation, ev_view_presentation, GTK_TYPE_WIDGET) -static GdkRGBA black = { 0., 0., 0., 1. }; -static GdkRGBA white = { 1., 1., 1., 1. }; - static void ev_view_presentation_set_normal (EvViewPresentation *pview) { @@ -128,7 +125,8 @@ ev_view_presentation_set_normal (EvViewPresentation *pview) return; pview->state = EV_PRESENTATION_NORMAL; - gdk_window_set_background_rgba (gtk_widget_get_window (widget), &black); + gtk_style_context_remove_class (gtk_widget_get_style_context (widget), + "white-mode"); gtk_widget_queue_draw (widget); } @@ -141,7 +139,8 @@ ev_view_presentation_set_black (EvViewPresentation *pview) return; pview->state = EV_PRESENTATION_BLACK; - gdk_window_set_background_rgba (gtk_widget_get_window (widget), &black); + gtk_style_context_remove_class (gtk_widget_get_style_context (widget), + "white-mode"); gtk_widget_queue_draw (widget); } @@ -154,8 +153,8 @@ ev_view_presentation_set_white (EvViewPresentation *pview) return; pview->state = EV_PRESENTATION_WHITE; - gdk_window_set_background_rgba (gtk_widget_get_window (widget), &white); - gtk_widget_queue_draw (widget); + gtk_style_context_add_class (gtk_widget_get_style_context (widget), + "white-mode"); } static void @@ -1026,6 +1025,13 @@ ev_view_presentation_draw (GtkWidget *widget, cairo_surface_t *surface; cairo_rectangle_int_t clip_rect; GdkRectangle *area = &clip_rect; + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (pview)); + gtk_render_background (context, cr, + 0, 0, + gtk_widget_get_allocated_width (widget), + gtk_widget_get_allocated_height (widget)); if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect)) return FALSE; @@ -1413,6 +1419,8 @@ ev_view_presentation_class_init (EvViewPresentationClass *klass) widget_class->motion_notify_event = ev_view_presentation_motion_notify_event; widget_class->scroll_event = ev_view_presentation_scroll_event; + gtk_widget_class_set_css_name (widget_class, "evpresentationview"); + gobject_class->dispose = ev_view_presentation_dispose; gobject_class->constructor = ev_view_presentation_constructor; @@ -1514,25 +1522,8 @@ ev_view_presentation_class_init (EvViewPresentationClass *klass) static void ev_view_presentation_init (EvViewPresentation *pview) { - static gsize initialization_value = 0; - gtk_widget_set_can_focus (GTK_WIDGET (pview), TRUE); - pview->is_constructing = TRUE; - - if (g_once_init_enter (&initialization_value)) { - GtkCssProvider *provider; - - provider = gtk_css_provider_new (); - gtk_css_provider_load_from_data (provider, - "EvViewPresentation {\n" - " background-color: black; }", - -1, NULL); - gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), - GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - g_object_unref (provider); - g_once_init_leave (&initialization_value, 1); - } + pview->is_constructing = TRUE; } GtkWidget * |