summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexei Sorokin <[email protected]>2017-01-15 18:24:34 +0300
committerAlexei Sorokin <[email protected]>2017-01-15 18:24:34 +0300
commit78e6e31dbde35a3f3dd4e95f2d8af90de2c17b1f (patch)
treebe328fdaee82db6fe18a0544a6434c337a4607a5 /src
parent15d98b9835333ba174687b4ec58eae7bcc7d94e2 (diff)
downloadmate-screensaver-78e6e31dbde35a3f3dd4e95f2d8af90de2c17b1f.tar.bz2
mate-screensaver-78e6e31dbde35a3f3dd4e95f2d8af90de2c17b1f.tar.xz
avoid deprecated gdk_window_set_background functions
Which are completely broken in GTK+ 3.22. Also remove some redundant separate Gtk2 code.
Diffstat (limited to 'src')
-rw-r--r--src/gs-manager.c22
-rw-r--r--src/gs-window-x11.c277
-rw-r--r--src/gs-window.h7
-rw-r--r--src/mate-screensaver-preferences.c70
4 files changed, 145 insertions, 231 deletions
diff --git a/src/gs-manager.c b/src/gs-manager.c
index c5ce240..a2ad590 100644
--- a/src/gs-manager.c
+++ b/src/gs-manager.c
@@ -1277,9 +1277,9 @@ static void
apply_background_to_window (GSManager *manager,
GSWindow *window)
{
-#if GTK_CHECK_VERSION (3, 0, 0)
cairo_surface_t *surface;
-#else
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr;
GdkPixmap *pixmap;
#endif
GdkScreen *screen;
@@ -1289,11 +1289,7 @@ apply_background_to_window (GSManager *manager,
if (manager->priv->bg == NULL)
{
gs_debug ("No background available");
-#if GTK_CHECK_VERSION (3, 0, 0)
gs_window_set_background_surface (window, NULL);
-#else
- gs_window_set_background_pixmap (window, NULL);
-#endif
}
screen = gs_window_get_screen (window);
@@ -1306,17 +1302,25 @@ apply_background_to_window (GSManager *manager,
width,
height,
FALSE);
- gs_window_set_background_surface (window, surface);
- cairo_surface_destroy (surface);
#else
+ surface = gdk_window_create_similar_surface (gs_window_get_gdk_window (window),
+ CAIRO_CONTENT_COLOR,
+ width,
+ height);
+ cr = cairo_create (surface);
+
pixmap = mate_bg_create_pixmap (manager->priv->bg,
gs_window_get_gdk_window (window),
width,
height,
FALSE);
- gs_window_set_background_pixmap (window, pixmap);
+ gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+ cairo_paint (cr);
+ cairo_destroy (cr);
g_object_unref (pixmap);
#endif
+ gs_window_set_background_surface (window, surface);
+ cairo_surface_destroy (surface);
}
static void
diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c
index 41adbb6..6a11d5a 100644
--- a/src/gs-window-x11.c
+++ b/src/gs-window-x11.c
@@ -88,11 +88,7 @@ struct GSWindowPrivate
GtkWidget *info_bar;
GtkWidget *info_content;
-#if GTK_CHECK_VERSION (3, 0, 0)
cairo_surface_t *background_surface;
-#else
- GdkPixmap *background_pixmap;
-#endif
guint popup_dialog_idle_id;
@@ -266,18 +262,7 @@ widget_clear_all_children (GtkWidget *widget)
#endif
}
-#if GTK_CHECK_VERSION (3, 0, 0)
-static void
-gs_window_reset_background_surface (GSWindow *window)
-{
- cairo_pattern_t *pattern;
- pattern = cairo_pattern_create_for_surface (window->priv->background_surface);
- gdk_window_set_background_pattern (gtk_widget_get_window (GTK_WIDGET (window)),
- pattern);
- cairo_pattern_destroy (pattern);
- gtk_widget_queue_draw (GTK_WIDGET (window));
-}
-#else
+#if !GTK_CHECK_VERSION (3, 0, 0)
static void
force_no_pixmap_background (GtkWidget *widget)
{
@@ -307,186 +292,47 @@ force_no_pixmap_background (GtkWidget *widget)
#endif
void
-#if GTK_CHECK_VERSION (3, 0, 0)
gs_window_set_background_surface (GSWindow *window,
cairo_surface_t *surface)
-#else
-gs_window_set_background_pixmap (GSWindow *window,
- GdkPixmap *pixmap)
-#endif
{
g_return_if_fail (GS_IS_WINDOW (window));
-#if GTK_CHECK_VERSION (3, 0, 0)
if (window->priv->background_surface != NULL)
{
cairo_surface_destroy (window->priv->background_surface);
}
+ window->priv->background_surface = NULL;
if (surface != NULL)
{
window->priv->background_surface = cairo_surface_reference (surface);
- gs_window_reset_background_surface (window);
- }
-#else
- if (window->priv->background_pixmap != NULL)
- {
- g_object_unref (window->priv->background_pixmap);
}
- if (pixmap != NULL)
- {
- window->priv->background_pixmap = g_object_ref (pixmap);
- gdk_window_set_back_pixmap (gtk_widget_get_window (GTK_WIDGET (window)),
- pixmap,
- FALSE);
- }
-#endif
+ gtk_widget_queue_draw (GTK_WIDGET (window));
}
-static void
-#if GTK_CHECK_VERSION (3, 0, 0)
-gs_window_clear_to_background_surface (GSWindow *window)
-#else
-gs_window_clear_to_background_pixmap (GSWindow *window)
-#endif
+void
+gs_window_clear (GSWindow *window)
{
-#if !GTK_CHECK_VERSION (3, 0, 0)
- GtkStateType state;
- GtkStyle *style;
-#endif
-
g_return_if_fail (GS_IS_WINDOW (window));
- if (! gtk_widget_get_visible (GTK_WIDGET (window)))
- {
- return;
- }
+ gs_debug ("Clearing widgets");
-#if GTK_CHECK_VERSION (3, 0, 0)
- if (window->priv->background_surface == NULL)
-#else
- if (window->priv->background_pixmap == NULL)
-#endif
+ if (gtk_widget_get_realized (GTK_WIDGET (window)))
{
- /* don't allow null pixmaps */
- return;
+ gtk_widget_queue_draw (GTK_WIDGET (window));
+ /* If a screensaver theme adds child windows
+ we need to clear them too */
+ widget_clear_all_children (GTK_WIDGET (window));
}
- gs_debug ("Clearing window to background pixmap");
-
-#if GTK_CHECK_VERSION (3, 0, 0)
- gs_window_reset_background_surface (window);
-#else
- style = gtk_style_copy (gtk_widget_get_style (GTK_WIDGET (window)));
-
- state = (GtkStateType) 0;
- while (state < (GtkStateType) G_N_ELEMENTS (gtk_widget_get_style (GTK_WIDGET (window))->bg_pixmap))
+ if (gtk_widget_get_realized (window->priv->drawing_area))
{
-
- if (style->bg_pixmap[state] != NULL)
- {
- g_object_unref (style->bg_pixmap[state]);
- }
-
- style->bg_pixmap[state] = g_object_ref (window->priv->background_pixmap);
- state++;
+ gtk_widget_queue_draw (window->priv->drawing_area);
+ widget_clear_all_children (window->priv->drawing_area);
}
- gtk_widget_set_style (GTK_WIDGET (window), style);
- g_object_unref (style);
-
- if (window->priv->background_pixmap != NULL)
- {
- gdk_window_set_back_pixmap (gtk_widget_get_window (GTK_WIDGET (window)),
- window->priv->background_pixmap,
- FALSE);
- }
-
- gdk_window_clear (gtk_widget_get_window (GTK_WIDGET (window)));
-
gdk_flush ();
-#endif
-}
-
-static void
-clear_widget (GtkWidget *widget)
-{
-#if GTK_CHECK_VERSION (3, 0, 0)
- GdkRGBA rgba = { 0.0, 0.0, 0.0, 1.0 };
- GtkStateFlags state;
-#else
- GdkColormap *colormap;
- GdkColor color = { 0, 0x0000, 0x0000, 0x0000 };
- GtkStateType state;
- GtkStyle *style;
-#endif
-
-#if GTK_CHECK_VERSION (3, 0, 0)
- if (!gtk_widget_get_realized (widget))
- {
- return;
- }
-
- gs_debug ("Clearing widget");
-
- state = gtk_widget_get_state_flags (widget);
- gtk_widget_override_background_color (widget, state, &rgba);
- gdk_window_set_background_rgba (gtk_widget_get_window (widget), &rgba);
- gtk_widget_queue_draw (GTK_WIDGET (widget));
-#else
- if (!gtk_widget_get_visible (widget))
- {
- return;
- }
-
- gs_debug ("Clearing widget");
-
- state = (GtkStateType) 0;
- while (state < (GtkStateType) G_N_ELEMENTS (gtk_widget_get_style (widget)->bg))
- {
- gtk_widget_modify_bg (widget, state, &color);
- state++;
- }
-
- style = gtk_style_copy (gtk_widget_get_style (widget));
-
- state = (GtkStateType) 0;
- while (state < (GtkStateType) G_N_ELEMENTS (gtk_widget_get_style (widget)->bg_pixmap))
- {
-
- if (style->bg_pixmap[state] != NULL)
- {
- g_object_unref (style->bg_pixmap[state]);
- }
-
- style->bg_pixmap[state] = NULL;
- state++;
- }
-
- colormap = gdk_drawable_get_colormap (gtk_widget_get_window (widget));
- gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE);
- gdk_window_set_background (gtk_widget_get_window (widget), &color);
-
- gtk_widget_set_style (widget, style);
- g_object_unref (style);
-
- gdk_window_clear (gtk_widget_get_window (widget));
-#endif
-
- /* If a screensaver theme adds child windows we need to clear them too */
- widget_clear_all_children (widget);
-
- gdk_flush ();
-}
-
-void
-gs_window_clear (GSWindow *window)
-{
- g_return_if_fail (GS_IS_WINDOW (window));
-
- clear_widget (GTK_WIDGET (window));
- clear_widget (window->priv->drawing_area);
}
#if GTK_CHECK_VERSION (3, 0, 0)
@@ -1071,6 +917,39 @@ window_select_shape_events (GSWindow *window)
#endif
}
+static gboolean
+#if GTK_CHECK_VERSION (3, 0, 0)
+gs_window_real_draw (GtkWidget *widget,
+ cairo_t *cr)
+#else
+gs_window_real_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
+#endif
+{
+ GSWindow *window = GS_WINDOW (widget);
+ cairo_surface_t *bg_surface = window->priv->background_surface;
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ GdkWindow *gdk_window = gtk_widget_get_window (widget);
+ cairo_t *cr = gdk_cairo_create (gdk_window);
+#endif
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ if (bg_surface != NULL)
+ {
+ cairo_set_source_surface (cr, bg_surface, 0, 0);
+ }
+ else
+ {
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ }
+ cairo_paint (cr);
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_destroy (cr);
+#endif
+ return FALSE;
+}
+
static void
gs_window_real_show (GtkWidget *widget)
{
@@ -2027,11 +1906,7 @@ popup_dialog (GSWindow *window)
gtk_widget_hide (window->priv->drawing_area);
-#if GTK_CHECK_VERSION (3, 0, 0)
- gs_window_clear_to_background_surface (window);
-#else
- gs_window_clear_to_background_pixmap (window);
-#endif
+ gtk_widget_queue_draw (GTK_WIDGET (window));
set_invisible_cursor (gtk_widget_get_window (GTK_WIDGET (window)), FALSE);
window->priv->dialog_quit_requested = FALSE;
@@ -2633,6 +2508,11 @@ gs_window_class_init (GSWindowClass *klass)
widget_class->show = gs_window_real_show;
widget_class->hide = gs_window_real_hide;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ widget_class->draw = gs_window_real_draw;
+#else
+ widget_class->expose_event = gs_window_real_expose_event;
+#endif
widget_class->realize = gs_window_real_realize;
widget_class->unrealize = gs_window_real_unrealize;
widget_class->key_press_event = gs_window_real_key_press_event;
@@ -2757,16 +2637,29 @@ create_info_bar (GSWindow *window)
gtk_box_pack_end (GTK_BOX (window->priv->vbox), window->priv->info_bar, FALSE, FALSE, 0);
}
+static gboolean
#if GTK_CHECK_VERSION (3, 0, 0)
-static void
-on_drawing_area_realized (GtkWidget *drawing_area)
+on_drawing_area_draw (GtkWidget *widget,
+ cairo_t *cr)
+#else
+on_drawing_area_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
+#endif
{
- GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ GdkWindow *window = gtk_widget_get_window (widget);
+ cairo_t *cr = gdk_cairo_create (window);
- gdk_window_set_background_rgba (gtk_widget_get_window (drawing_area),
- &black);
-}
#endif
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_paint (cr);
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_destroy (cr);
+#endif
+ return FALSE;
+}
static void
gs_window_init (GSWindow *window)
@@ -2812,21 +2705,22 @@ gs_window_init (GSWindow *window)
window->priv->drawing_area = gtk_drawing_area_new ();
gtk_widget_show (window->priv->drawing_area);
-#if GTK_CHECK_VERSION (3, 0, 0)
gtk_widget_set_app_paintable (window->priv->drawing_area, TRUE);
-#endif
- gtk_box_pack_start (GTK_BOX (window->priv->vbox), window->priv->drawing_area, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (window->priv->vbox),
+ window->priv->drawing_area, TRUE, TRUE, 0);
#if GTK_CHECK_VERSION (3, 0, 0)
g_signal_connect (window->priv->drawing_area,
- "realize",
- G_CALLBACK (on_drawing_area_realized),
+ "draw",
+ G_CALLBACK (on_drawing_area_draw),
+ NULL);
+#else
+ g_signal_connect (window->priv->drawing_area,
+ "expose-event",
+ G_CALLBACK (on_drawing_area_expose_event),
NULL);
-#endif
- create_info_bar (window);
-
-#if !GTK_CHECK_VERSION (3, 0, 0)
force_no_pixmap_background (window->priv->drawing_area);
#endif
+ create_info_bar (window);
}
static void
@@ -2879,17 +2773,10 @@ gs_window_finalize (GObject *object)
gs_window_dialog_finish (window);
-#if GTK_CHECK_VERSION (3, 0, 0)
if (window->priv->background_surface)
{
cairo_surface_destroy (window->priv->background_surface);
}
-#else
- if (window->priv->background_pixmap)
- {
- g_object_unref (window->priv->background_pixmap);
- }
-#endif
G_OBJECT_CLASS (gs_window_parent_class)->finalize (object);
}
diff --git a/src/gs-window.h b/src/gs-window.h
index 22f9274..67d5055 100644
--- a/src/gs-window.h
+++ b/src/gs-window.h
@@ -66,13 +66,8 @@ void gs_window_set_monitor (GSWindow *window,
int monitor);
int gs_window_get_monitor (GSWindow *window);
-#if GTK_CHECK_VERSION (3, 0, 0)
void gs_window_set_background_surface (GSWindow *window,
- cairo_surface_t *surface);
-#else
-void gs_window_set_background_pixmap (GSWindow *window,
- GdkPixmap *pixmap);
-#endif
+ cairo_surface_t *surface);
void gs_window_set_lock_enabled (GSWindow *window,
gboolean lock_enabled);
void gs_window_set_logout_enabled (GSWindow *window,
diff --git a/src/mate-screensaver-preferences.c b/src/mate-screensaver-preferences.c
index 5dd0757..e1d167f 100644
--- a/src/mate-screensaver-preferences.c
+++ b/src/mate-screensaver-preferences.c
@@ -299,22 +299,6 @@ config_set_lock (gboolean lock)
}
static void
-preview_clear (GtkWidget *widget)
-{
-#if GTK_CHECK_VERSION (3, 0, 0)
- GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
-
- gdk_window_set_background_rgba (gtk_widget_get_window (widget), &black);
- gtk_widget_queue_draw (widget);
-#else
- GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
-
- gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &black);
- gdk_window_clear (gtk_widget_get_window (widget));
-#endif
-}
-
-static void
job_set_theme (GSJob *job,
const char *theme)
{
@@ -337,6 +321,33 @@ job_set_theme (GSJob *job,
}
}
+static gboolean
+#if GTK_CHECK_VERSION (3, 0, 0)
+preview_on_draw (GtkWidget *widget,
+ cairo_t *cr)
+#else
+preview_on_expose_event (GtkWidget *widget,
+ GdkEventExpose *event)
+#endif
+{
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ GdkWindow *window = gtk_widget_get_window (widget);
+ cairo_t *cr = gdk_cairo_create (window);
+
+#endif
+ if (job == NULL || !gs_job_is_running (job))
+ {
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_paint (cr);
+ }
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_destroy (cr);
+#endif
+ return FALSE;
+}
+
static void
preview_set_theme (GtkWidget *widget,
const char *theme,
@@ -350,7 +361,7 @@ preview_set_theme (GtkWidget *widget,
gs_job_stop (job);
}
- preview_clear (widget);
+ gtk_widget_queue_draw (widget);
label = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_theme_label"));
markup = g_markup_printf_escaped ("<i>%s</i>", name);
@@ -1170,7 +1181,7 @@ fullscreen_preview_cancelled_cb (GtkWidget *button,
gs_job_set_widget (job, preview_area);
fullscreen_preview_area = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_area"));
- preview_clear (fullscreen_preview_area);
+ gtk_widget_queue_draw (fullscreen_preview_area);
fullscreen_preview_window = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_window"));
gtk_widget_hide (fullscreen_preview_window);
@@ -1200,7 +1211,7 @@ fullscreen_preview_start_cb (GtkWidget *widget,
gtk_widget_grab_focus (fullscreen_preview_window);
fullscreen_preview_area = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_area"));
- preview_clear (fullscreen_preview_area);
+ gtk_widget_queue_draw (fullscreen_preview_area);
gs_job_set_widget (job, fullscreen_preview_area);
}
@@ -1553,6 +1564,7 @@ init_capplet (void)
GtkWidget *preview_button;
GtkWidget *gpm_button;
GtkWidget *fullscreen_preview_window;
+ GtkWidget *fullscreen_preview_area;
GtkWidget *fullscreen_preview_previous;
GtkWidget *fullscreen_preview_next;
GtkWidget *fullscreen_preview_close;
@@ -1601,7 +1613,7 @@ init_capplet (void)
preview_button = GTK_WIDGET (gtk_builder_get_object (builder, "preview_button"));
gpm_button = GTK_WIDGET (gtk_builder_get_object (builder, "gpm_button"));
fullscreen_preview_window = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_window"));
- GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_area"));
+ fullscreen_preview_area = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_area"));
fullscreen_preview_close = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_close"));
fullscreen_preview_previous = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_previous_button"));
fullscreen_preview_next = GTK_WIDGET (gtk_builder_get_object (builder, "fullscreen_preview_next_button"));
@@ -1673,6 +1685,16 @@ init_capplet (void)
gtk_window_set_icon_name (GTK_WINDOW (dialog), "preferences-desktop-screensaver");
gtk_window_set_icon_name (GTK_WINDOW (fullscreen_preview_window), "screensaver");
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect (fullscreen_preview_area,
+ "draw", G_CALLBACK (preview_on_draw),
+ NULL);
+#else
+ g_signal_connect (fullscreen_preview_area,
+ "expose-event", G_CALLBACK (preview_on_expose_event),
+ NULL);
+#endif
+
gtk_drag_dest_set (dialog, GTK_DEST_DEFAULT_ALL,
drop_types, G_N_ELEMENTS (drop_types),
GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_MOVE);
@@ -1695,7 +1717,13 @@ init_capplet (void)
g_strfreev (list);
}
- preview_clear (preview);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect (preview, "draw", G_CALLBACK (preview_on_draw), NULL);
+#else
+ g_signal_connect (preview,
+ "expose-event", G_CALLBACK (preview_on_expose_event),
+ NULL);
+#endif
gs_job_set_widget (job, preview);
if (check_is_root_user ())