Skip to content

Commit

Permalink
libview: use css to draw the background of presentations
Browse files Browse the repository at this point in the history
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 22, 2018
1 parent 1e531cb commit 02970c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
41 changes: 16 additions & 25 deletions libview/ev-view-presentation.c
Expand Up @@ -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) 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 static void
ev_view_presentation_set_normal (EvViewPresentation *pview) ev_view_presentation_set_normal (EvViewPresentation *pview)
{ {
Expand All @@ -128,7 +125,8 @@ ev_view_presentation_set_normal (EvViewPresentation *pview)
return; return;


pview->state = EV_PRESENTATION_NORMAL; 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); gtk_widget_queue_draw (widget);
} }


Expand All @@ -141,7 +139,8 @@ ev_view_presentation_set_black (EvViewPresentation *pview)
return; return;


pview->state = EV_PRESENTATION_BLACK; 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); gtk_widget_queue_draw (widget);
} }


Expand All @@ -154,8 +153,8 @@ ev_view_presentation_set_white (EvViewPresentation *pview)
return; return;


pview->state = EV_PRESENTATION_WHITE; pview->state = EV_PRESENTATION_WHITE;
gdk_window_set_background_rgba (gtk_widget_get_window (widget), &white); gtk_style_context_add_class (gtk_widget_get_style_context (widget),
gtk_widget_queue_draw (widget); "white-mode");
} }


static void static void
Expand Down Expand Up @@ -1026,6 +1025,13 @@ ev_view_presentation_draw (GtkWidget *widget,
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_rectangle_int_t clip_rect; cairo_rectangle_int_t clip_rect;
GdkRectangle *area = &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)) if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
return FALSE; return FALSE;
Expand Down Expand Up @@ -1413,6 +1419,8 @@ ev_view_presentation_class_init (EvViewPresentationClass *klass)
widget_class->motion_notify_event = ev_view_presentation_motion_notify_event; widget_class->motion_notify_event = ev_view_presentation_motion_notify_event;
widget_class->scroll_event = ev_view_presentation_scroll_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->dispose = ev_view_presentation_dispose;


gobject_class->constructor = ev_view_presentation_constructor; gobject_class->constructor = ev_view_presentation_constructor;
Expand Down Expand Up @@ -1514,25 +1522,8 @@ ev_view_presentation_class_init (EvViewPresentationClass *klass)
static void static void
ev_view_presentation_init (EvViewPresentation *pview) ev_view_presentation_init (EvViewPresentation *pview)
{ {
static gsize initialization_value = 0;

gtk_widget_set_can_focus (GTK_WIDGET (pview), TRUE); gtk_widget_set_can_focus (GTK_WIDGET (pview), TRUE);
pview->is_constructing = 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);
}
} }


GtkWidget * GtkWidget *
Expand Down
16 changes: 16 additions & 0 deletions shell/atril.css
@@ -1,3 +1,19 @@
#ev-fullscreen-toolbar { #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.