Skip to content
Permalink
Browse files

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 #232
  • Loading branch information...
raveit65 committed Mar 21, 2018
1 parent 1e531cb commit 02970c6cc1a6752ddc41325cc629c29cafe556c7
Showing with 32 additions and 25 deletions.
  1. +16 −25 libview/ev-view-presentation.c
  2. +16 −0 shell/atril.css
@@ -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 *
@@ -1,3 +1,19 @@
#ev-fullscreen-toolbar {

}

#ev-loading-message {
background-color: @theme_selected_bg_color;
color: @theme_selected_fg_color;
border-radius: 3px;
padding: 8px;
}

evpresentationview {
background-color: black;
}

evpresentationview.white-mode {
background-color: white;
}

0 comments on commit 02970c6

Please sign in to comment.
You can’t perform that action at this time.